Commit Graph

408 Commits

Author SHA1 Message Date
Stefan Ceriu
487640fa1f feat(client): expose a client pause/resume mechanism throughout the SDK
This patch exposes the pause/resume mechanism for SDK stores all the way up to
the FFI `Client`, so apps can temporarily release SQLite resources when moving
to the background and re-acquire them on resume.

The main use case is iOS backgrounding, where keeping SQLite file descriptors and
locks open can contribute to `0xdead10cc` terminations by the operating system.
2026-04-23 18:52:41 +03:00
Stefan Ceriu
0ea0c94bd0 chore(tests): add pause/resume mechanism tests for all the stores 2026-04-23 18:18:58 +03:00
Stefan Ceriu
30875cac1f feat(stores): implement pause/resume support in the crypto, event cache, state and media SQLite stores
This patch implements the main pause/resume logic in the underlying SDK stores.
The in memory stores no-op trough the default trait implementations.

The main change are limited to the sqlite crate:
- a new type called `SqliteConnections` has been introduced which now holds a
store's read connection pools as well as the always on write connection. This
lives as an optional on each store's level and gets set to None whenever the
store is paused
- during the pausing phase `SqliteConnections` (through its `pause_connections`
method) does the following:
    - closes the read pool, directly dropping idle connections
    - waits for in flight writes to finish
    - tries a best effort WAL checkpoint
    - drops the write connection on a blocking thread
    - and waits for in-flight read connections to drain
    - this is all best effort with an eventual timeout
- resuming connections is also shared between the stores through
`SqliteConnections` and consists in building a new pool with the previous
configuration and creating a new write connection
2026-04-23 18:18:58 +03:00
Stefan Ceriu
f89ae339b2 feat(stores): add pause and resume trait definitions and default implementations for all the stores 2026-04-23 13:13:17 +03:00
Hubert Chathi
c1274cea14 Add support for pushing secrets and receiving secret pushes (#6164)
see MSC4385

Pushing secrets allow devices to send secrets to other devices without waiting for a secret request.
2026-04-07 12:26:17 +01:00
Michael Goldenberg
ee9a05defe refactor(sqlite): remove old crypto store generation key-value
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
2026-03-31 17:34:11 +02:00
Jorge Martín
5d2eab119d feat: Improve getting homeserver capabilities
This extracts the `/capabilities` logic to its own `HomeserverCapabilities` component in the SDK that can be manually asked to fetch, cache locally and return these capabilities.
2026-03-31 15:25:37 +02:00
Benjamin Bouvier
816530c89c feat(event cache): make EventCacheError cloneable
This makes it possible to share futures which output is a result that
has the error type set to `EventCacheError`. See also
https://github.com/matrix-org/matrix-rust-sdk/pull/6304 for usage.
2026-03-17 15:47:39 +01:00
mgoldenberg
4ec9124ce1 Allow storing the same Event in multiple LinkedChunks of the same Room (#6200)
# Overview

There are scenarios in which it is sensible to have an event exist in
the same room more than once. Notably, this is true in the context of a
thread, where an event exists in the main timeline of a room, as well as
in a thread of that same room.

Support for this behavior has been implemented in the
`SQLiteEventCacheStore` in #6065; however, this was never implemented
for the `IndexeddbEventCacheStore` or the `MemoryStore`. This pull
request extends this behavior to both of those stores.

# Changes

## Integration Tests
First, `test_event_chunks_allows_same_event_in_room_and_thread` was
moved from `matrix_sdk_sqlite::event_cache_store` to
`matrix_sdk_base::event_cache::store::integration_tests`. Then, a few
additional integration tests were added to ensure that behavior is
consistent across implementations of `EventCacheStore`.

## `IndexeddbEventCacheStore`
In order to accommodate the behavioral changes specified by the
integration tests, it was necessary to modify the schema in the
IndexedDB implementation of `EventCacheStore`. Namely, the events object
store was cleared and removed and then replaced with a nearly identical
one, the only difference being the removal of a uniqueness constraint on
one of the indices.

The remaining changes mostly involved updating the behavior of top-level
`EventCacheStore` functions - e.g., filtering out events where they were
duplicated or removing positioning information where it was not
relevant.

## `MemoryStore`
The changes to `MemoryStore` mostly involved updating the behavior of
top-level `EventCacheStore` function - e.g., filtering out events where
they were duplicated or removing positioning information where it was
not relevant.

That being said, it also involved some breaking changes to
`RelationalLinkedChunk`.

1. `RelationalLinkedChunk::items` - this function returned an `Iterator`
that did not contain information about the `LinkedChunkId`, so this
information was added to the items in the `Iterator`.
2. `RelationalLinkedChunk::save_item` - this function did not update the
item in all linked chunks of the provided `Room`. It now does this, but
requires that the provided `Item` be `Clone`.

(1) could probably have been a new function, but I thought a nicer
interface was worth the breaking change. (2) could probably be prevented
by re-organizing `RelationalLinkedChunk`'s internal data structures to
remove the `Clone` requirement, but that seemed like it could turn into
a large refactoring project, so I opted for something simpler albeit
somewhat crude.

In both cases, I'm open to suggestions and would be happy to revisit if
something else is preferred.

---
Closes #6094.

- [x] I've documented the public API Changes in the appropriate
`CHANGELOG.md` files.
- [x] I've read [the `CONTRIBUTING.md`
file](https://github.com/matrix-org/matrix-rust-sdk/blob/main/CONTRIBUTING.md),
notably the sections about Pull requests, Commit message format, and AI
policy.
- [ ] This PR was made with the help of AI.

Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>

---------

Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
2026-03-10 14:55:02 +01:00
Benjamin Bouvier
8dbb6e5c1d refactor(event cache): rename Gap::prev_token to token
As it is now used for both a previous batch token (backwards pagination)
or a next batch token (forwards pagination).
2026-03-04 12:13:22 +01:00
Kévin Commaille
81286ad1e7 Upgrade Ruma after breaking change about EventId constructors
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2026-03-04 10:30:25 +00:00
Kévin Commaille
029148ef6e refactor(sqlite): Get rid of the DATABASE_VERSION constants
They are error prone because they need to be bumped for every migration
otherwise the new migration will not happen because we exit early.

So instead we get rid of the early returns and log each individual
upgrade separately. It makes more noise when creating a new database,
but since it is logged at the DEBUG level it is not much of a problem.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2026-03-03 15:26:42 +01:00
Skye Elliot
fadfd98bee feat(crypto): Add get_all_rooms_pending_key_bundle to store trait
Signed-off-by: Skye Elliot <actuallyori@gmail.com>
2026-02-25 16:02:41 +00:00
Skye Elliot
640fa4854f feat(sqlite): Add query_many helper trait method
Signed-off-by: Skye Elliot <actuallyori@gmail.com>
2026-02-25 16:02:35 +00:00
Richard van der Hoff
8ac5d42fbe crypto: add rooms_pending_key_bundles interface to crypto store
Add a place to store details about rooms where we are waiting for a key bundle
2026-02-25 14:23:14 +00:00
Ivan Enderlin
a8e4630f56 chore(sqlite): Update deadpool to 0.13 and deadpool-sync to 0.2.
These releases include our patch to fix a panic (see
https://github.com/deadpool-rs/deadpool/pull/461).
2026-02-24 16:26:45 +01:00
Ivan Enderlin
c017ce0928 feat(sqlite): SqliteCryptoStore has 1 write connection.
Similarly to #5382 and #5744, this patch introduces a write-only
connection in `SqliteCryptoStore`. The idea is to get many read-only
connections, and a single write-only connection behind a lock, so that
there is a single writer at a time.

This patch renames the `acquire` method to `read`, and it introduces a
new `write` connection.
2026-02-23 14:31:13 +01:00
Kévin Commaille
fd5c1d847e Remove once_cell dependency
Use the types that were stabilized in the standard library instead.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2026-02-23 10:10:14 +00:00
Michael Goldenberg
d6293c75a9 test(event-cache): move test_linked_chunk_exists_before_referenced to integration tests
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
2026-02-03 11:47:05 -05:00
Michael Goldenberg
78d681f24f style(event-cache): fmt
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
2026-01-31 15:42:56 -05:00
Michael Goldenberg
709d4cb80d Merge branch 'main' into test-merge-consolidate-event-cache-store-tests
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
2026-01-31 15:07:52 -05:00
Michael Goldenberg
1b4e6aa0e7 feat(event-cache): ensure chunks exist before referenced in sqlite store
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
2026-01-30 22:36:22 -05:00
Ivan Enderlin
09a1bf8ec2 fix(sqlite): Replace unwrap when using interact.
This patch replaces the `interact(…).unwrap()` by a proper error.

So far, `interact()` was only returning `InteractError::Panic`
despites `InteractError::Aborted` exists. With
https://github.com/deadpool-rs/deadpool/pull/461, we now get
`InteractError::Aborted` when the SDK is shutdown, sometimes. This
results in hitting the `unwrap` and having a panic again. This patch
solves the problem by changing the `unwrap` to a proper error. Note: in
case of `InteractError::Panic`, we continue to panic.

This patch makes sense with or without the merge of the PR on
`deadpool`.
2026-01-30 15:08:39 +01:00
Benjamin Bouvier
e601c1d9b4 test: test that one can store the same event in multiple linked chunks 2026-01-27 16:02:20 +01:00
Benjamin Bouvier
2a968661e7 feat(sqlite): allow storing the same events in multiple linked chunks 2026-01-27 16:02:20 +01:00
Skye Elliot
3924463c6d fix: Correctly store rooms with downloaded keys in SQLite and IndexedDB. (#6044)
While https://github.com/matrix-org/matrix-rust-sdk/pull/6017 is mostly
functional, there are two issues:

- I did not process `changes.room_key_bundles_fully_downloaded` in
`matrix-sdk-sqlite`, meaning any updates made via `Changes` would not be
persisted;
- I used a non-encrypting `JsValue` serialisation for the same field in
`matrix-sdk-indexeddb`, which causes errors when passed to the
decryption-enabled deserializer.

Solutions:

- Process the aforementioned changes such that keys are added to SQLite;
- Use a non-encrypting deserialiser, since this is effectively a
hash-set, and the contents aren't sensitive.

Signed-off-by: Skye Elliot <actuallyori@gmail.com>
2026-01-26 14:12:54 +00:00
Michael Goldenberg
3c42e1b4b9 test(event-cache): move test_load_previous_chunk to integration tests
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
2026-01-25 18:57:43 -05:00
Michael Goldenberg
12af5c4444 test(event-cache): move test_load_last_chunk_with_cycle to integration tests
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
2026-01-25 18:48:11 -05:00
Michael Goldenberg
3738091689 test(event-cache): move test_load_last_chunk to integration tests
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
2026-01-25 18:44:46 -05:00
Michael Goldenberg
750f59e4ea test(event-cache): move test_filter_duplicate_events_no_events to integration tests
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
2026-01-25 18:41:52 -05:00
Michael Goldenberg
e60b204cda test(event-cache): move test_linked_chunk_multiple_rooms to integration tests
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
2026-01-25 18:38:19 -05:00
Michael Goldenberg
0443615683 test(event-cache): copy test_linked_chunk_clear to integration tests
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
2026-01-25 17:54:18 -05:00
Michael Goldenberg
d93238d086 test(event-cache): move test_linked_chunk_start_end_reattach_items to integration tests
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
2026-01-25 17:51:44 -05:00
Michael Goldenberg
fe1ab18474 test(event-cache): move test_linked_chunk_detach_last_items to integration tests
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
2026-01-25 17:49:17 -05:00
Michael Goldenberg
2c8a915018 test(event-cache): copy test_linked_chunk_remove_item to integration tests
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
2026-01-25 17:46:19 -05:00
Michael Goldenberg
4f34b51bda test(event-cache): move test_linked_chunk_push_items to integration tests
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
2026-01-25 17:43:12 -05:00
Michael Goldenberg
cd1fbef0ea test(event-cache): copy test_linked_chunk_remove_chunk to integration tests
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
2026-01-25 17:39:33 -05:00
Michael Goldenberg
ca9c74d2c4 test(event-cache): move test_linked_chunk_new_gap_chunk to integration tests
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
2026-01-25 17:34:56 -05:00
Michael Goldenberg
a7ab53838e test(event-cache): move test_linked_chunk_new_items_chunk to integration tests
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
2026-01-25 17:29:00 -05:00
Michael Goldenberg
680bc74543 test(event-cache): move test_linked_chunk_replace_item to integration tests
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
2026-01-25 17:26:00 -05:00
Skye Elliot
90390d7488 Merge pull request #6017 from matrix-org/kaylendog/history-sharing/backup-download
feat: Download room keys from backup before building key bundle.
2026-01-16 17:03:46 +00:00
Benjamin Bouvier
5b8ff8a76d refactor(state store): remove StateStore::upsert_thread_subscription
There is `StateStore::upsert_thread_subscriptions` as a proper
replacement these days.
2026-01-16 17:01:03 +01:00
Skye Elliot
e156d8e00c refactor: Use Try operator over Into::into, fixup comment. 2026-01-13 17:46:54 +00:00
Skye Elliot
3baaef5109 feat: Download room keys from backup before building key bundle.
Signed-off-by: Skye Elliot <actuallyori@gmail.com>
2026-01-13 15:19:28 +00:00
Jorge Martín
6b0c1e2992 doc: Add doc and inline comments 2026-01-07 16:11:40 +01:00
Jorge Martín
b5a0042e14 fix(sqlite): Add WAL checkpoints to the DBs when they're opened too 2026-01-07 16:11:40 +01:00
Jorge Martín
3be6fb1a80 fix(sqlite): Add WAL checkpoints when vacuuming
For some reason, the automatic WAL checkpoints don't seem to be working as expected. Since we should periodically run VACUUM operations, we might as well add checkpoints before vacuuming (so the WAL size is reset and can grow to fit the whole DB) and after (so we clean up after that).
2026-01-07 16:11:40 +01:00
razvp
67b1de613c feat(state-stores): Add StateStore::upsert_thread_subscriptions() method for bulk upsert 2025-12-17 11:03:50 +01:00
Jonas Platte
ad58607013 Fix new clippy lints 2025-12-11 16:18:42 +01:00
Jonas Platte
eae3006f8d Reformat matrix-sdk-sqlite 2025-12-11 16:18:42 +01:00