summary refs log tree commit diff
path: root/synapse/storage (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Convert DeviceLastConnectionInfo to attrs. (#16507)Patrick Cloke2023-10-171-20/+26
| | | To improve type safety & memory usage.
* Convert state delta processing from a dict to attrs. (#16469)Patrick Cloke2023-10-162-30/+36
| | | For improved type checking & memory usage.
* Remove useless async job to delete device messages on sync (#16491)Mathieu Velten2023-10-161-2/+3
|
* Revert "Drop unused tables & unneeded access token ID for events. (#16268)" ↵Patrick Cloke2023-10-122-26/+2
| | | | | | | | (#16465) This reverts commit cabd57746004fe2dacc11aa8d373854a3d25e306. There are additional usages of these tables which need to be removed first.
* Convert user_get_threepids response to attrs. (#16468)Patrick Cloke2023-10-111-5/+14
| | | This improves type annotations by not having a dictionary of Any values.
* Convert simple_select_many_batch, simple_select_many_txn to tuples. (#16444)Patrick Cloke2023-10-1121-416/+601
|
* Inline simple_search_list/simple_search_list_txn. (#16434)Patrick Cloke2023-10-102-72/+36
| | | | This only has a single use and is over abstracted. Inline it so that we can improve type hints.
* Add DB indices to speed up purging rooms (#16457)David Robertson2023-10-103-0/+34
|
* Disable statement timeout whilst purging rooms (#16455)reivilibre2023-10-091-0/+5
| | | | | | | | | | | | | * Disable statement timeout whilst purging rooms * Newsfile Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org> * Note the introduction version --------- Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org>
* Convert simple_select_list_paginate_txn to return tuples. (#16433)Patrick Cloke2023-10-063-33/+58
|
* Return ThumbnailInfo in more places (#16438)Patrick Cloke2023-10-061-5/+25
| | | | Improves type hints by using concrete types instead of dictionaries.
* Drop unused tables & unneeded access token ID for events. (#16268)Patrick Cloke2023-10-062-2/+26
| | | | Drop the event_txn_id table and the tables related to MSC2716, which is no longer supported in Synapse.
* Remove unused method. (#16435)Patrick Cloke2023-10-051-20/+0
|
* Remove manys calls to cursor_to_dict (#16431)Patrick Cloke2023-10-0513-226/+317
| | | | | | | | | | This avoids calling cursor_to_dict and then immediately unpacking the values in the dict for other users. By not creating the intermediate dictionary we can avoid allocating the dictionary and strings for the keys, which should generally be more performant. Additionally this improves type hints by avoid Dict[str, Any] dictionaries coming out of the database layer.
* Factor out `MultiWriter` token from `RoomStreamToken` (#16427)Erik Johnston2023-10-051-9/+13
|
* Some refactors around receipts stream (#16426)Erik Johnston2023-10-042-5/+3
|
* mypy plugin to check `@cached` return types (#14911)David Robertson2023-10-024-10/+15
| | | | | | | | Co-authored-by: David Robertson <davidr@element.io> Co-authored-by: Patrick Cloke <patrickc@matrix.org> Co-authored-by: Erik Johnston <erik@matrix.org> Assert that the return type of callables wrapped in @cached and @cachedList are cachable (aka immutable).
* Add a cache around server ACL checking (#16360)Patrick Cloke2023-09-261-0/+59
| | | | | * Pre-compiles the server ACLs onto an object per room and invalidates them when new events come in. * Converts the server ACL checking into Rust.
* Implement MSC4028: push all encrypted events. (#16361)Patrick Cloke2023-09-261-0/+1
| | | | This unstable push rule is implemented behind an experimental configuration flag.
* Improve comments in StateGroupBackgroundUpdateStore. (#16383)Patrick Cloke2023-09-251-2/+16
|
* Bump types-psycopg2 from 2.9.21.11 to 2.9.21.14 (#16381)dependabot[bot]2023-09-252-29/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Bump types-psycopg2 from 2.9.21.11 to 2.9.21.14 Bumps [types-psycopg2](https://github.com/python/typeshed) from 2.9.21.11 to 2.9.21.14. - [Commits](https://github.com/python/typeshed/commits) --- updated-dependencies: - dependency-name: types-psycopg2 dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * Relax the annotation of Cursor.description See https://github.com/matrix-org/synapse/pull/16343#issuecomment-1726083384 for rationale. * Changelog * Changelog --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: David Robertson <davidr@element.io>
* Add support for pydantic v2 via pydantic.v1 compat module (#16332)Maxwell G2023-09-251-1/+6
| | | While maintaining support with pydantic v1.
* Convert more cached return values to immutable types (#16356)Patrick Cloke2023-09-204-9/+11
|
* Return immutable objects for cachedList decorators (#16350)Patrick Cloke2023-09-1913-51/+80
|
* Bump ruff from 0.0.286 to 0.0.290 (#16342)dependabot[bot]2023-09-182-13/+2
| | | | | Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Patrick Cloke <patrickc@matrix.org>
* Filter locked users in the admin API (#16328)Hanadi2023-09-182-1/+7
| | | | Co-authored-by: Hanadi Tamimi <hanadi.tamimi@sdui.de>
* Make cached account data/tags/admin types immutable (#16325)Patrick Cloke2023-09-183-14/+13
|
* Return an immutable value from get_latest_event_ids_in_room. (#16326)Patrick Cloke2023-09-183-9/+10
|
* Convert `_insert_graph_receipts_txn` to `simple_upsert` (#16299)Jason Little2023-09-152-14/+12
|
* Some minor performance fixes for task schedular (#16313)Erik Johnston2023-09-142-0/+22
|
* Refactor `get_user_by_id` (#16316)Erik Johnston2023-09-142-54/+33
|
* Fix using dehydrated devices (MSC2697) & refresh tokens (#16288)Hanadi2023-09-131-0/+20
| | | | | Refresh tokens were not correctly moved to the rehydrated device (similar to how the access token is currently handled). This resulted in invalid refresh tokens after rehydration.
* Use StrCollection in additional places. (#16301)Patrick Cloke2023-09-131-2/+2
|
* Stop purging tables which are slated for removal. (#16273)Patrick Cloke2023-09-122-5/+5
|
* Refactor storing of server keys (#16261)Erik Johnston2023-09-121-147/+72
|
* Improve type hints for attrs classes (#16276)David Robertson2023-09-081-5/+3
|
* Update ruff config (#16283)Patrick Cloke2023-09-081-2/+0
| | | Enable additional checks & clean-up unneeded configuration.
* Log values at DEBUG level with execute_values (#16281)David Robertson2023-09-081-2/+3
|
* Recheck if remote device is cached before requesting it (#16252)Erik Johnston2023-09-071-9/+17
| | | | This fixes a bug where we could get stuck re-requesting the device over replication again and again.
* Add `/notifications` endpoint to workers (#16265)Erik Johnston2023-09-071-36/+36
|
* Merge remote-tracking branch 'origin/release-v1.92' into developPatrick Cloke2023-09-062-22/+0
|\
| * Merge remote-tracking branch 'origin/release-v1.91' into release-v1.92Patrick Cloke2023-09-062-22/+0
| |\
| | * Revert MSC3861 introspection cache, admin impersonation and account lock ↵Quentin Gliech2023-09-062-22/+0
| | | | | | | | | | | | (#16258)
* | | Delete device messages asynchronously and in staged batches (#16240)Mathieu Velten2023-09-067-21/+37
| | |
* | | Fix appservices being unable to handle to_device messages for multiple users ↵Will Hunt2023-09-051-1/+1
| | | | | | | | | | | | (#16251)
* | | Fix bug where we kept re-requesting a remote server's key repeatedly. (#16257)Erik Johnston2023-09-051-6/+11
|/ / | | | | | | | | * Correctly handle multiple rows per server/key * Newsfile
* | Don't wake up destination transaction queue if they're not due for retry. ↵Erik Johnston2023-09-041-3/+23
| | | | | | | | (#16223)
* | Add last_seen_ts to the admin users API (#16218)Mathieu Velten2023-09-043-2/+12
| |
* | Log the details of background update failures (#16212)David Robertson2023-09-011-2/+2
| |
* | Fix rare bug that broke looping calls (#16210)Erik Johnston2023-08-301-14/+22
| | | | | | | | | | | | | | | | | | | | * Fix rare bug that broke looping calls We can't interact with the reactor from the main thread via looping call. Introduced in v1.90.0 / #15791. * Newsfile
* | Stop writing to the event_txn_id table (#16175)Patrick Cloke2023-08-303-71/+21
| |
* | Bump mypy-zope & mypy. (#16188)Patrick Cloke2023-08-291-1/+16
| |
* | Bump ruff from 0.0.277 to 0.0.286 (#16198)dependabot[bot]2023-08-291-3/+3
| | | | | | | | Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* | Stabilize support for MSC3958 (suppress notifications from edits). (#16113)Patrick Cloke2023-08-231-1/+0
|/
* Fix rare deadlock when using read/write locks (#16169) github/release-v1.91.0 release-v1.91.0Erik Johnston2023-08-232-37/+71
|
* Filter out unwanted user_agents from udv. (#16124)Neil Johnson2023-08-231-0/+5
|
* Fix rare deadlock when using read/write locks (#16133)Erik Johnston2023-08-231-0/+37
|
* Reduce DB contention on worker locks (#16160)Erik Johnston2023-08-231-0/+37
|
* Always update `retry_last_ts` (#16164)Erik Johnston2023-08-231-3/+3
|
* Task scheduler: mark task as active if we are scheduling ASAP (#16165)Mathieu Velten2023-08-231-1/+1
|
* Properly update retry_last_ts when hitting the maximum retry interval (#16156)DeepBlueV7.X2023-08-231-1/+3
| | | | | | | | | | | | | | | | | | | | | * Properly update retry_last_ts when hitting the maximum retry interval This was broken in 1.87 when the maximum retry interval got changed from almost infinite to a week (and made configurable). fixes #16101 Signed-off-by: Nicolas Werner <nicolas.werner@hotmail.de> * Add changelog * Change fix + add test * Add comment --------- Signed-off-by: Nicolas Werner <nicolas.werner@hotmail.de> Co-authored-by: Mathieu Velten <mathieuv@matrix.org>
* Increase perf of read/write locks (#16149)Erik Johnston2023-08-231-0/+30
| | | We do this by marking the tables as `UNLOGGED` in PostgreSQL.
* Add an admin endpoint to allow authorizing server to signal token ↵Shay2023-08-222-0/+22
| | | | revocations (#16125)
* Implements a task scheduler for resumable potentially long running tasks ↵Mathieu Velten2023-08-214-0/+233
| | | | (#15891)
* Speed up state res in rare case we don't have all events (#16116)Erik Johnston2023-08-181-23/+161
| | | | | | | If we don't have all the auth events in a room then not all state events will have a chain cover index. Even so, we can still use the chain cover index on the events that do have it, rather than bailing and using the slower functions. This situation should not arise for newly persisted rooms, as we check we have the full auth chain for each event, but can happen for existing rooms. c.f. #15245
* Allow filtering for admins in the list accounts admin API (#16114)Alexander Fechler2023-08-181-0/+10
|
* Add cache to `get_server_keys_json_for_remote` (#16123)Erik Johnston2023-08-182-44/+95
|
* Fix database performance of read/write worker locks (#16061)Erik Johnston2023-08-171-52/+35
| | | | | | | We were seeing serialization errors when taking out multiple read locks. The transactions were retried, so isn't causing any failures. Introduced in #15782.
* Override global statement timeout when creating indexes in Postgres (#16085)Shay2023-08-171-0/+12
|
* Rename pagination&purge locks and add comments explaining them (#16112)Mathieu Velten2023-08-161-2/+2
|
* Run pyupgrade for python 3.7 & 3.8. (#16110)Patrick Cloke2023-08-155-8/+14
|
* Implements admin API to lock an user (MSC3939) (#15870)Mathieu Velten2023-08-103-5/+84
|
* Support MSC3814: Dehydrated Devices Part 2 (#16010)Shay2023-08-082-59/+162
|
* Remove old rows from the `cache_invalidation_stream_by_instance` table ↵reivilibre2023-08-081-0/+130
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | automatically. (This table is not used when Synapse is configured to use SQLite.) (#15868) * Add a cache invalidation clean-up task * Run the cache invalidation stream clean-up on the background worker * Tune down * call_later is in millis! * Newsfile Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org> * fixup! Add a cache invalidation clean-up task * Update synapse/storage/databases/main/cache.py Co-authored-by: Eric Eastwood <erice@element.io> * Update synapse/storage/databases/main/cache.py Co-authored-by: Eric Eastwood <erice@element.io> * MILLISEC -> MS * Expand on comment * Move and tweak comment about Postgres * Use `wrap_as_background_process` --------- Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org> Co-authored-by: Eric Eastwood <erice@element.io>
* Stabilize support for MSC3970: updated transaction semantics (scope to ↵Patrick Cloke2023-08-042-10/+10
| | | | | | | `device_id`) (#15629) For now this maintains compatible with old Synapses by falling back to using transaction semantics on a per-access token. A future version of Synapse will drop support for this.
* Add ability to wait for locks and add locks to purge history / room deletion ↵Erik Johnston2023-07-312-75/+142
| | | | | (#15791) c.f. #13476
* Inline SQL queries using boolean parameters (#15525)Anshul Madnawat2023-07-267-25/+23
| | | | SQLite now supports TRUE and FALSE constants, simplify some queries by inlining those instead of passing them as arguments.
* Bump DB version to 79 since synapse v1.88 was already there (#15998)Mathieu Velten2023-07-266-16/+21
|
* Actually stop reading from column `user_id` of tables `profiles` (#15955)Shay2023-07-233-11/+10
|
* Speed up updating state in large rooms (#15971)Erik Johnston2023-07-202-124/+135
| | | This should speed up updating state in rooms with lots of state.
* Fix bad merge of #15933 (#15958)Erik Johnston2023-07-192-0/+0
| | | This was because we reverted the bump of the schema version, so we were not applying the new deltas.
* Fix race in triggers for read/write locks. (#15933)Erik Johnston2023-07-194-98/+134
|
* Fix background schema updates failing over a large upgrade gap (#15887)Shay2023-07-181-0/+70
|
* Merge branch 'master' into developOlivier Wilkinson (reivilibre)2023-07-187-122/+16
|\
| * Revert "Stop writing to column `user_id` of tables `profiles` and ↵Shay2023-07-187-122/+16
| | | | | | | | | | | | | | | | | | `user_filters`. (#15953) * Revert "Stop writing to column `user_id` of tables `profiles` and `user_filters` (#15787)" This reverts commit f25b0f88081bb436bef914983cff7087b54eba5f. * newsfragement
* | Support room version 11 (#15912)Patrick Cloke2023-07-181-1/+1
| | | | | | | | | | And fix a bug in the implementation of the updated redaction format (MSC2174) where the top-level redacts field was not properly added for backwards-compatibility.
* | Mark get_user_in_directory private since only used in tests (#15884)Mathieu Velten2023-07-121-8/+1
|/
* Fix downgrading to previous version of Synapse (#15907)Erik Johnston2023-07-103-4/+17
| | | We do this by marking the constraint as deferrable.
* Stop writing to column `user_id` of tables `profiles` and `user_filters` ↵Shay2023-07-077-16/+122
| | | | (#15787)
* Add basic read/write lock (#15782)Erik Johnston2023-07-053-56/+439
|
* Add tracing to media `/upload` endpoint (#15850)Eric Eastwood2023-07-051-0/+5
| | | Add tracing instrumentation to media `/upload` code paths to investigate https://github.com/matrix-org/synapse/issues/15841
* Fix could not serialize access due to concurrent `DELETE` from ↵Jason Little2023-07-051-1/+6
| | | | | | | presence_stream (#15826) * Change update_presence to have a isolation level of READ_COMMITTED * changelog
* Add foreign key constraint to `event_forward_extremities`. (#15751)Erik Johnston2023-07-055-7/+438
|
* Add not_user_type param to the list accounts admin API (#15844)Michael Weimann2023-07-041-0/+37
| | | Signed-off-by: Michael Weimann <michaelw@element.io>
* devices: use combined ANY clause for faster cleanup (#15861)pacien2023-07-031-5/+9
| | | | | | | | | | | | | | | | | | | | | | | | | Old device entries for the same user were being removed in individual SQL commands, making the batch take way longer than necessary. This combines the commands into a single one with a IN/ANY clause. Example of log entry before the change, regularly observed with "log_min_duration_statement = 10000" in PostgreSQL's config: LOG: duration: 42538.282 ms statement: DELETE FROM device_lists_stream WHERE user_id = '@someone' AND device_id = 'someid1' AND stream_id < 123456789 ; DELETE FROM device_lists_stream WHERE user_id = '@someone' AND device_id = 'someid2' AND stream_id < 123456789 ; [repeated for each device ID of that user, potentially a lot...] With the patch applied on my instance for the past couple of days, I no longer notice overly long statements of that particular kind. Signed-off-by: pacien <pacien.trangirard@pacien.net>
* Add a timeout that aborts any Postgres statement taking more than 1 hour. ↵reivilibre2023-07-031-0/+13
| | | | | | | | | | | | | (#15853) * Add a timeout to Postgres statements * Newsfile Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org> --------- Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org>
* Fix sqlite `user_filters` upgrade (#15817)Shay2023-06-273-3/+91
|
* Fix forgotten rooms missing in initial sync (#15815)Nicolas Werner2023-06-211-0/+13
| | | | | | | | If you leave a room and forget it, then rejoin it, the room would be missing from the next initial sync. fixes #13262 Signed-off-by: Nicolas Werner <n.werner@famedly.com>
* Remove experimental MSC2716 implementation to incrementally import history ↵Eric Eastwood2023-06-164-384/+1
| | | | | | | | | | | | into existing rooms (#15748) Context for why we're removing the implementation: - https://github.com/matrix-org/matrix-spec-proposals/pull/2716#issuecomment-1487441010 - https://github.com/matrix-org/matrix-spec-proposals/pull/2716#issuecomment-1504262734 Anyone wanting to continue MSC2716, should also address these leftover tasks: https://github.com/matrix-org/synapse/issues/10737 Closes https://github.com/matrix-org/synapse/issues/10737 in the fact that it is not longer necessary to track those things.
* Don't always lock "user_ips" table when performing non-native upsert (#15788)Andrew Morgan2023-06-161-1/+1
|
* Prefill events after invalidate not before when persisting events (#15758)Jason Little2023-06-142-4/+13
| | | | | Fixes #15757
* Replace `EventContext` fields `prev_group` and `delta_ids` with field ↵Shay2023-06-131-3/+2
| | | | `state_group_deltas` (#15233)
* Clear event caches when we purge history (#15609)Erik Johnston2023-06-084-5/+177
| | | | | | | This should help a little with #13476 --------- Co-authored-by: Patrick Cloke <patrickc@matrix.org>
* Quick & dirty metric for background update status (#15740)David Robertson2023-06-072-1/+37
| | | | | | | | | | | | | | | * Quick & dirty metric for background update status * Changelog * Remove debug Co-authored-by: Mathieu Velten <mathieuv@matrix.org> * Actually write to _aborted --------- Co-authored-by: Mathieu Velten <mathieuv@matrix.org>
* Remove superfluous `room_memberships` join from background update (#15733)Eric Eastwood2023-06-071-1/+0
| | | Spawning from https://github.com/matrix-org/synapse/pull/15731
* Merge branch 'master' into developErik Johnston2023-06-071-1/+21
|\
| * Fix schema delta error in 1.85 (#15739)Erik Johnston2023-06-071-2/+14
| | | | | | | | Some users seem to have multiple rows per user / room with a null thread ID, which we need to handle.
| * Fix schema delta error in 1.85 (#15738)Erik Johnston2023-06-071-0/+8
| | | | | | | | | | | | | | | | There appears to be a race where you can end up with entries in `event_push_summary` with both a `NULL` and `main` thread ID. Fixes #15736 Introduced in #15597
* | No need for the extra join since `membership` is built-in to ↵Eric Eastwood2023-06-061-4/+3
| | | | | | | | | | | | | | `current_state_events` (#15731) This helps with the upstream `is_host_joined()` and `is_host_invited()` functions. `membership` was added to `current_state_events` in https://github.com/matrix-org/synapse/pull/5706 and forced in https://github.com/matrix-org/synapse/pull/13745
* | Improve performance of user directory search (#15729)Shay2023-06-061-4/+8
| |
* | Stabilize support for MSC3952: Intentional mentions. (#15520)Patrick Cloke2023-06-061-1/+0
| |
* | `N + 3`: Read from column `full_user_id` rather than `user_id` of tables ↵Shay2023-06-025-13/+203
| | | | | | | | `profiles` and `user_filters` (#15649)
* | Add a catch-all * to the supported relation types when redacting (#15705)Mathieu Velten2023-06-021-0/+30
| | | | | | This is an update to MSC3912 implementation
* | Merge branch 'release-v1.85' into developH. Shay2023-06-014-2/+53
|\|
| * Speed up background jobs populate_full_user_id_user_filters and ↵Shay2023-05-312-2/+2
| | | | | | | | populate_full_user_id_profiles (#15700)
| * Fix a performance issue introduced in Synapse v1.83.0 which meant that ↵reivilibre2023-05-312-0/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | purging rooms was very slow and database-intensive. (#15693) * Add indices required to efficiently validate new foreign key constraints on stream_ordering * Newsfile Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org> --------- Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org>
* | Cache requests for user's devices from federation (#15675)Erik Johnston2023-06-012-2/+69
| | | | | | | | This should mitigate the issue where lots of different servers requests the same user's devices all at once.
* | Add get_canonical_room_alias to module API (#15450)Gabriel Féron2023-05-311-1/+1
|/ | | Co-authored-by: Boxdot <d@zerovolt.org>
* Set thread_id column to non-null for ↵Patrick Cloke2023-05-268-223/+291
| | | | | | | | | | | | | | | | event_push_{actions,actions_staging,summary} (#15597) Updates the database schema to require a thread_id (by adding a constraint that the column is non-null) for event_push_actions, event_push_actions_staging, and event_push_actions_summary. For PostgreSQL we add the constraint as NOT VALID, then VALIDATE the constraint a background job to avoid locking the table during an upgrade. Each table is updated as a separate schema delta to avoid deadlocks between them. For SQLite we simply rebuild the table & copy the data.
* Process previously failed backfill events in the background (#15585)Eric Eastwood2023-05-241-1/+30
| | | | | | | | | Process previously failed backfill events in the background because they are bound to fail again and we don't need to waste time holding up the request for something that is bound to fail again. Fix https://github.com/matrix-org/synapse/issues/13623 Follow-up to https://github.com/matrix-org/synapse/issues/13621 and https://github.com/matrix-org/synapse/issues/13622 Part of making `/messages` faster: https://github.com/matrix-org/synapse/issues/13356
* Speed up user directory rebuild for users some more... (#15665)Erik Johnston2023-05-241-76/+114
|
* Improve type hints for cached decorator. (#15658)Patrick Cloke2023-05-241-1/+1
| | | | | The cached decorators always return a Deferred, which was not properly propagated. It was close enough when wrapping coroutines, but failed if a bare function was wrapped.
* Fix `@trace` not wrapping some state methods that return coroutines ↵Eric Eastwood2023-05-231-7/+8
| | | | | | | | | | | correctly (#15647) ``` 2023-05-21 09:30:09,288 - synapse.logging.opentracing - 940 - ERROR - POST-1 - @trace may not have wrapped StateStorageController.get_state_for_groups correctly! The function is not async but returned a coroutine ``` Tracing instrumentation for these functions originally introduced in https://github.com/matrix-org/synapse/pull/15610
* Instrument `state` and `state_group` storage related things (tracing) (#15610)Eric Eastwood2023-05-193-0/+53
| | | | | Instrument `state` and `state_group` storage related things (tracing) so it's a little more clear where these database transactions are coming from as there is a lot of wires crossing in these functions. Part of `/messages` performance investigation: https://github.com/matrix-org/synapse/issues/13356
* Remove old R30 because R30v2 supercedes it (#10428)reivilibre2023-05-191-83/+0
| | | | | R30v2 has been out since 2021-07-19 (https://github.com/matrix-org/synapse/pull/10332) and we started collecting stats on 2021-08-16. Since it's been over a year now (almost 2 years), this is enough grace period for us to now rip it out.
* Rename blacklist/whitelist internally. (#15620)Patrick Cloke2023-05-191-3/+2
| | | | Avoid renaming configuration settings for now and rename internal code to use blocklist and allowlist instead.
* Handle missing previous read marker event. (#15464)Nick Mills-Barrett2023-05-181-6/+0
| | | | | If the previous read marker is pointing to an event that no longer exists (e.g. due to retention) then assume that the newly given read marker is newer.
* Update code to refer to "workers". (#15606)Patrick Cloke2023-05-166-25/+14
| | | | A bunch of comments and variables are out of date and use obsolete terms.
* Add not null constraint to column `full_user_id` of tables `profiles` and ↵Shay2023-05-167-4/+267
| | | | `user_filters` (#15537)
* Fix subscriptable type usage in Python <3.9 (#15604)Eric Eastwood2023-05-161-2/+1
| | | | | | | | | | | | Fix the following `mypy` errors when running `mypy` with Python 3.7: ``` synapse/storage/controllers/stats.py:58: error: "Counter" is not subscriptable, use "typing.Counter" instead [misc] tests/test_state.py:267: error: "dict" is not subscriptable, use "typing.Dict" instead [misc] ``` Part of https://github.com/matrix-org/synapse/issues/15603 In Python 3.9, `typing` is deprecated and the types are subscriptable (generics) by default, https://peps.python.org/pep-0585/#implementation
* Revert "Set thread_id column to non-null for ↵Erik Johnston2023-05-126-224/+234
| | | | | event_push_{actions,actions_staging,summary} (#15437)" (#15580) This reverts commit a7b3e9ce65335e452de216cb42b9e724e8f3ad1d.
* Clean up and clarify "Create or modify Account" Admin API documentation (#15544)Andrew Morgan2023-05-051-0/+16
|
* Factor out an `is_mine_server_name` method (#15542)Sean Quah2023-05-051-1/+1
| | | | | | | | | | | | Add an `is_mine_server_name` method, similar to `is_mine_id`. Ideally we would use this consistently, instead of sometimes comparing against `hs.hostname` and other times reaching into `hs.config.server.server_name`. Also fix a bug in the tests where `hs.hostname` would sometimes differ from `hs.config.server.server_name`. Signed-off-by: Sean Quah <seanq@matrix.org>
* Speed up deleting of old rows in `event_push_actions` (#15531)Erik Johnston2023-05-031-0/+9
| | | Enforce that we use index scans (rather than seq scans), which we also do for state queries. The reason to enforce this is that we can't correctly get PostgreSQL to understand the distribution of `stream_ordering` depends on `highlight`, and so it always defaults (on matrix.org) to sequential scans.
* Speed up rebuilding of the user directory for local users (#15529)Erik Johnston2023-05-032-77/+171
| | | The idea here is to batch up the work.
* Set thread_id column to non-null for ↵Patrick Cloke2023-05-036-234/+224
| | | | | | | | | | | | | event_push_{actions,actions_staging,summary} (#15437) Updates the database schema to require a thread_id (by adding a constraint that the column is non-null) for event_push_actions, event_push_actions_staging, and event_push_actions_summary. For PostgreSQL we add the constraint as NOT VALID, then VALIDATE the constraint a background job to avoid locking the table during an upgrade. For SQLite we simply rebuild the table & copy the data.
* Add config option to forget rooms automatically when users leave them (#15224)Sean Quah2023-05-032-24/+69
| | | | | This is largely based off the stats and user directory updater code. Signed-off-by: Sean Quah <seanq@matrix.org>
* Initial implementation of MSC3981: recursive relations API (#15315)Patrick Cloke2023-05-021-17/+48
| | | | | | | | | | | Adds an optional keyword argument to the /relations API which will recurse a limited number of event relationships. This will cause the API to return not just the events related to the parent event, but also events related to those related to the parent event, etc. This is disabled by default behind an experimental configuration flag and is currently implemented using prefixed parameters.
* Add an admin API endpoint to support per-user feature flags (#15344)Shay2023-04-283-0/+104
|
* Add support for claiming multiple OTKs at once. (#15468)Patrick Cloke2023-04-271-30/+47
| | | | | | | MSC3983 provides a way to request multiple OTKs at once from appservices, this extends this concept to the Client-Server API. Note that this will likely be spit out into a separate MSC, but is currently part of MSC3983.
* Add type hints to schema deltas (#15497)Patrick Cloke2023-04-2728-134/+131
| | | | | | | | | | Cleans-up the schema delta files: * Removes no-op functions. * Adds missing type hints to function parameters. * Fixes any issues with type hints. This also renames one (very old) schema delta to avoid a conflict that mypy complains about.
* Check databases/__init__ and main/cache with mypy. (#15496)Patrick Cloke2023-04-272-9/+11
|
* Add column `full_user_id` to tables `profiles` and `user_filters`. (#15458)Shay2023-04-266-18/+120
|
* Add admin endpoint to query room sizes (#15482)Erik Johnston2023-04-262-0/+115
|
* Add unstable /keys/claim endpoint which always returns fallback keys. (#15462)Patrick Cloke2023-04-251-4/+5
| | | | | | | | | | | | | It can be useful to always return the fallback key when attempting to claim keys. This adds an unstable endpoint for `/keys/claim` which always returns fallback keys in addition to one-time-keys. The fallback key(s) are not marked as "used" unless there are no corresponding OTKs. This is currently defined in MSC3983 (although likely to be split out to a separate MSC). The endpoint shape may change or be requested differently (i.e. a keyword parameter on the current endpoint), but the core logic should be reasonable.
* Re re introduce membership tables event stream ordering (#15356)Nick Mills-Barrett2023-04-256-12/+162
|
* Experimental support for MSC3970: per-device transaction IDs (#15318)Quentin Gliech2023-04-253-18/+136
|
* Modify StoreKeyFetcher to read from server_keys_json. (#15417)Patrick Cloke2023-04-201-12/+87
| | | | | | | | | | | | | | | | | | | | | | | | | | | Before this change: * `PerspectivesKeyFetcher` and `ServerKeyFetcher` write to `server_keys_json`. * `PerspectivesKeyFetcher` also writes to `server_signature_keys`. * `StoreKeyFetcher` reads from `server_signature_keys`. After this change: * `PerspectivesKeyFetcher` and `ServerKeyFetcher` write to `server_keys_json`. * `PerspectivesKeyFetcher` also writes to `server_signature_keys`. * `StoreKeyFetcher` reads from `server_keys_json`. This results in `StoreKeyFetcher` now using the results from `ServerKeyFetcher` in addition to those from `PerspectivesKeyFetcher`, i.e. keys which are directly fetched from a server will now be pulled from the database instead of refetched. An additional minor change is included to avoid creating a `PerspectivesKeyFetcher` (and checking it) if no `trusted_key_servers` are configured. The overall impact of this should be better usage of cached results: * If a server has no trusted key servers configured then it should reduce how often keys are fetched. * if a server's trusted key server does not have a requested server's keys cached then it should reduce how often keys are directly fetched.
* More precise type for LoggingTransaction.execute (#15432)David Robertson2023-04-143-14/+31
| | | | | | * More precise type for LoggingTransaction.execute * Add an annotation for stream_ordering_month_ago This would have spotted the error that was fixed in "Add comma missing from #15382. (#15429)"
* User directory background update speedup (#15435)Erik Johnston2023-04-141-45/+44
| | | | | | | c.f. #15264 The two changes are: 1. Add indexes so that the select / deletes don't do sequential scans 2. Don't repeatedly call `SELECT count(*)` each iteration, as that's slow
* Load `/directory/room/{roomAlias}` endpoint on workers (#15333)Dirk Klimpel2023-04-141-2/+4
| | | | | | | | | * Enable `directory` * move to worker store * newsfile * disable `ClientDirectoryListServer` and `ClientAppserviceDirectoryListServer` for workers
* Improve robustness when handling a perspective key response by deduplicating ↵reivilibre2023-04-131-3/+3
| | | | | | | | | | | | | | | received server keys. (#15423) * Change `store_server_verify_keys` to take a `Mapping[(str, str), FKR]` This is because we already can't handle duplicate keys — leads to cardinality violation * Newsfile Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org> --------- Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org>
* Add comma missing from #15382. (#15429)reivilibre2023-04-131-1/+1
| | | | | | | | | | | * Add missing comma * Newsfile Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org> --------- Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org>
* Implement MSC2175: remove the creator field from create events. (#15394)Patrick Cloke2023-04-061-5/+12
|
* Don't keep old stream_ordering_to_exterm around (#15382)Erik Johnston2023-04-061-10/+42
|
* Merge remote-tracking branch 'origin/release-v1.81' into developPatrick Cloke2023-04-061-1/+1
|\
| * Fix the 'set_device_id_for_pushers_txn' background update. (#15391)Quentin Gliech2023-04-051-1/+1
| | | | | | | | Refer to the correct field from the response when updating the background update progress.
* | Delete server-side backup keys when deactivating an account. (#15181)Shay2023-04-042-3/+128
|/
* Speed up membership queries for users with forgotten rooms (#15385)Erik Johnston2023-04-042-1/+30
|
* Revert pruning of old devices (#15360)Erik Johnston2023-03-311-82/+1
| | | | | | | | | * Revert "Fix registering a device on an account with lots of devices (#15348)" This reverts commit f0d8f66eaaacfa75bed65bc5d0c602fbc5339c85. * Revert "Delete stale non-e2e devices for users, take 3 (#15183)" This reverts commit 78cdb72cd6b0e007c314d9fed9f629dfc5b937a6.
* Revert "Set thread_id column to non-null for ↵Olivier Wilkinson (reivilibre)2023-03-315-153/+243
| | | | | | | | event_push_{actions,actions_staging,summary} (#15350)" This reverts commit 2a234b788e2b5706ee83cf8eb86dfd004bc7c166. See #15359 for context.
* Set thread_id column to non-null for ↵Patrick Cloke2023-03-305-243/+153
| | | | | | | | | | | event_push_{actions,actions_staging,summary} (#15350) Clean-up from adding the thread_id column, which was initially null but backfilled with values. It is desirable to require it to now be non-null. In addition to altering this column to be non-null, we clean up obsolete background jobs, indexes, and just-in-time updating code.
* to_device updates could be dropped when consuming the replication stream ↵Mathieu Velten2023-03-301-10/+4
| | | | | (#15349) Co-authored-by: reivilibre <oliverw@matrix.org>
* Speed up SQLite unit test CI (#15334)Erik Johnston2023-03-301-1/+16
| | | Tests now take 40% of the time.
* Fix spinloop during partial state sync when a prev event is in backoff (#15351)Sean Quah2023-03-301-14/+21
| | | | | | | | Previously, we would spin in a tight loop until `update_state_for_partial_state_event` stopped raising `FederationPullAttemptBackoffError`s. Replace the spinloop with a wait until the backoff period has expired. Signed-off-by: Sean Quah <seanq@matrix.org>
* Fix registering a device on an account with lots of devices (#15348)Erik Johnston2023-03-291-3/+6
| | | Fixes up #15183
* Revert "Reintroduce membership tables event stream ordering (#15128)" (#15347)Erik Johnston2023-03-295-130/+12
| | | This reverts commit e6af49fbea939d9e69ed05e0a0ced5948c722ea4.
* Delete stale non-e2e devices for users, take 3 (#15183)Erik Johnston2023-03-291-1/+79
| | | | | This should help reduce the number of devices e.g. simple bots the repeatedly login rack up. We only delete non-e2e devices as they should be safe to delete, whereas if we delete e2e devices for a user we may accidentally break their ability to receive e2e keys for a message.
* Implement MSC3983 to proxy /keys/claim queries to appservices. (#15314)Patrick Cloke2023-03-281-9/+27
| | | | | | Experimental support for MSC3983 is behind a configuration flag. If enabled, for users which are exclusively owned by an application service then the appservice will be queried for one-time keys *if* there are none uploaded to Synapse.
* Bump ruff from 0.0.252 to 0.0.259 (#15328)dependabot[bot]2023-03-285-9/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Bump ruff from 0.0.252 to 0.0.259 Bumps [ruff](https://github.com/charliermarsh/ruff) from 0.0.252 to 0.0.259. - [Release notes](https://github.com/charliermarsh/ruff/releases) - [Changelog](https://github.com/charliermarsh/ruff/blob/main/BREAKING_CHANGES.md) - [Commits](https://github.com/charliermarsh/ruff/compare/v0.0.252...v0.0.259) --- updated-dependencies: - dependency-name: ruff dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * Fix new warnings * Mypy * Newsfile --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Erik Johnston <erik@matrix.org>
* As an optimisation, use `TRUNCATE` on Postgres when clearing the user ↵reivilibre2023-03-241-4/+11
| | | | directory tables. (#15316)
* Make cleaning up pushers depend on the device_id instead of the token_id ↵Quentin Gliech2023-03-242-9/+50
| | | | | | | | | | | | | | (#15280) This makes it so that we rely on the `device_id` to delete pushers on logout, instead of relying on the `access_token_id`. This ensures we're not removing pushers on token refresh, and prepares for a world without access token IDs (also known as the OIDC). This actually runs the `set_device_id_for_pushers` background update, which was forgotten in #13831. Note that for backwards compatibility it still deletes pushers based on the `access_token` until the background update finishes.
* Reintroduce membership tables event stream ordering (#15128)Nick Mills-Barrett2023-03-245-12/+130
| | | | | | | | | | | | | | | | | | * Add `event_stream_ordering` column to membership state tables Specifically this adds the column to `current_state_events`, `local_current_membership` and `room_memberships`. Each of these tables is regularly joined with the `events` table to get the stream ordering and denormalising this into each table will yield significant query performance improvements once used. * Make denormalised `event_stream_ordering` columns foreign keys * Add comment in schema file explaining new denormalised columns * Add triggers to enforce consistency of `event_stream_ordering` columns * Re-order purge room tables to account for foreign keys * Bump schema version to 75 Co-authored-by: David Robertson <david.m.robertson1@gmail.com> Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
* Use immutabledict instead of frozendict (#15113)David Robertson2023-03-221-2/+2
| | | | | | | | | | Additionally: * Consistently use `freeze()` in test --------- Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
* Apply & bundle edits for non-message events. (#15295)Patrick Cloke2023-03-211-7/+4
|
* Make `POST /_matrix/client/v3/rooms/{roomId}/report/{eventId}` endpoint ↵Andrew Morgan2023-03-211-1/+0
| | | | return 404 if event exists, but the user lacks access (#15300)
* Refresh remote profiles that have been marked as stale, in order to fill the ↵reivilibre2023-03-161-0/+74
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | user directory. [rei:userdirpriv] (#14756) * Scaffolding for background process to refresh profiles * Add scaffolding for background process to refresh profiles for a given server * Implement the code to select servers to refresh from * Ensure we don't build up multiple looping calls * Make `get_profile` able to respect backoffs * Add logic for refreshing users * When backing off, schedule a refresh when the backoff is over * Wake up the background processes when we receive an interesting state event * Add tests * Newsfile Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org> * Add comment about 1<<62 --------- Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org>
* Preparatory work to fix the user directory assuming that any remote ↵reivilibre2023-03-162-0/+79
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | membership state events represent a profile change. [rei:userdirpriv] (#14755) * Remove special-case method for new memberships only, use more generic method * Only collect profiles from state events in public rooms * Add a table to track stale remote user profiles * Add store methods to set and delete rows in this new table * Mark remote profiles as stale when a member state event comes in to a private room * Newsfile Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org> * Simplify by removing Optionality of `event_id` * Replace names and avatars with None if they're set to dodgy things I think this makes more sense anyway. * Move schema delta to 74 (I missed the boat?) * Turns out these can be None after all --------- Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org>
* Add schema comments about the `destinations` and `destination_rooms` tables. ↵reivilibre2023-03-151-0/+52
| | | | (#15247)
* Remove unused store method `_set_destination_retry_timings_emulated`. (#15266)reivilibre2023-03-141-54/+2
|
* Add missing type hints to `synapse.storage.database`. (#15230)Patrick Cloke2023-03-091-5/+16
|
* Include the room ID in more purge room log lines. (#15222)Patrick Cloke2023-03-083-14/+21
|
* Split up txn for fetching device keys (#15215)Erik Johnston2023-03-072-9/+25
| | | | We look up keys in batches, but we should do that outside of the transaction to avoid starving the database pool.
* Combine AbstractStreamIdTracker and AbstractStreamIdGenerator. (#15192)Patrick Cloke2023-03-036-27/+14
| | | | | AbstractStreamIdTracker (now) has only a single sub-class: AbstractStreamIdGenerator, combine them to simplify some code and remove any direct references to AbstractStreamIdTracker.
* Experimental MSC3890 Implementation: Fix deleting account data when using an ↵Andrew Morgan2023-03-031-19/+15
| | | | account data writer worker (#14869)
* Add a `get_next_txn` method to `StreamIdGenerator` to match ↵Andrew Morgan2023-03-023-11/+47
| | | | `MultiWriterIdGenerator` (#15191
* Move event_reports to `RoomWorkerStore` (#15165)Dirk Klimpel2023-03-021-177/+177
|
* Remove support for aggregating reactions (#15172)Richard van der Hoff2023-02-284-147/+0
| | | | | | | | | | It turns out that no clients rely on server-side aggregation of `m.annotation` relationships: it's just not very useful as currently implemented. It's also non-trivial to calculate. I want to remove it from MSC2677, so to keep the implementation in line, let's remove it here.
* Fix a long-standing bug where an initial sync would not respond to changes ↵reivilibre2023-02-281-0/+31
| | | | to the list of ignored users if there was an initial sync cached. (#15163)
* Allow use of the `/filter` Client-Server APIs on workers. (#15134)reivilibre2023-02-282-6/+23
|
* Admin API endpoint to delete a reported event (#15116)Dirk Klimpel2023-02-281-1/+35
| | | | | | | | | | | | | | | | | | | | | * Admin api to delete event report * lint + tests * newsfile * Apply suggestions from code review Co-authored-by: David Robertson <david.m.robertson1@gmail.com> * revert changes - move to WorkerStore * update unit test * Note that timestamp is in millseconds --------- Co-authored-by: David Robertson <david.m.robertson1@gmail.com>
* Add module API callbacks for adding and deleting local 3PID associations (#15044Andrew Morgan2023-02-271-13/+0
|
* Batch up storing state groups when creating new room (#14918)Shay2023-02-241-0/+119
|
* Improve handling of non-ASCII characters in user directory search (#15143)Sean Quah2023-02-241-2/+50
| | | | | | | | | | | | | | | * Fix a long-standing bug where non-ASCII characters in search terms, including accented letters, would not match characters in a different case. * Fix a long-standing bug where search terms using combining accents would not match display names using precomposed accents and vice versa. To fully take effect, the user directory must be rebuilt after this change. Fixes #14630. Signed-off-by: Sean Quah <seanq@matrix.org>
* Bump black from 22.12.0 to 23.1.0 (#15103)dependabot[bot]2023-02-2221-35/+18
|
* Fix a bug introduced in Synapse v1.74.0 where searching with colons when ↵reivilibre2023-02-201-4/+20
| | | | | | using ICU for search term tokenisation would fail with an error. (#15079) Co-authored-by: David Robertson <davidr@element.io>
* Use mypy 1.0 (#15052)David Robertson2023-02-162-14/+64
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Update mypy and mypy-zope * Remove unused ignores These used to suppress ``` synapse/storage/engines/__init__.py:28: error: "__new__" must return a class instance (got "NoReturn") [misc] ``` and ``` synapse/http/matrixfederationclient.py:1270: error: "BaseException" has no attribute "reasons" [attr-defined] ``` (note that we check `hasattr(e, "reasons")` above) * Avoid empty body warnings, sometimes by marking methods as abstract E.g. ``` tests/handlers/test_register.py:58: error: Missing return statement [empty-body] tests/handlers/test_register.py:108: error: Missing return statement [empty-body] ``` * Suppress false positive about `JaegerConfig` Complaint was ``` synapse/logging/opentracing.py:450: error: Function "Type[Config]" could always be true in boolean context [truthy-function] ``` * Fix not calling `is_state()` Oops! ``` tests/rest/client/test_third_party_rules.py:428: error: Function "Callable[[], bool]" could always be true in boolean context [truthy-function] ``` * Suppress false positives from ParamSpecs ```` synapse/logging/opentracing.py:971: error: Argument 2 to "_custom_sync_async_decorator" has incompatible type "Callable[[Arg(Callable[P, R], 'func'), **P], _GeneratorContextManager[None]]"; expected "Callable[[Callable[P, R], **P], _GeneratorContextManager[None]]" [arg-type] synapse/logging/opentracing.py:1017: error: Argument 2 to "_custom_sync_async_decorator" has incompatible type "Callable[[Arg(Callable[P, R], 'func'), **P], _GeneratorContextManager[None]]"; expected "Callable[[Callable[P, R], **P], _GeneratorContextManager[None]]" [arg-type] ```` * Drive-by improvement to `wrapping_logic` annotation * Workaround false "unreachable" positives See https://github.com/Shoobx/mypy-zope/issues/91 ``` tests/http/test_proxyagent.py:626: error: Statement is unreachable [unreachable] tests/http/test_proxyagent.py:762: error: Statement is unreachable [unreachable] tests/http/test_proxyagent.py:826: error: Statement is unreachable [unreachable] tests/http/test_proxyagent.py:838: error: Statement is unreachable [unreachable] tests/http/test_proxyagent.py:845: error: Statement is unreachable [unreachable] tests/http/federation/test_matrix_federation_agent.py:151: error: Statement is unreachable [unreachable] tests/http/federation/test_matrix_federation_agent.py:452: error: Statement is unreachable [unreachable] tests/logging/test_remote_handler.py:60: error: Statement is unreachable [unreachable] tests/logging/test_remote_handler.py:93: error: Statement is unreachable [unreachable] tests/logging/test_remote_handler.py:127: error: Statement is unreachable [unreachable] tests/logging/test_remote_handler.py:152: error: Statement is unreachable [unreachable] ``` * Changelog * Tweak DBAPI2 Protocol to be accepted by mypy 1.0 Some extra context in: - https://github.com/matrix-org/python-canonicaljson/pull/57 - https://github.com/python/mypy/issues/6002 - https://mypy.readthedocs.io/en/latest/common_issues.html#covariant-subtyping-of-mutable-protocol-members-is-rejected * Pull in updated canonicaljson lib so the protocol check just works * Improve comments in opentracing I tried to workaround the ignores but found it too much trouble. I think the corresponding issue is https://github.com/python/mypy/issues/12909. The mypy repo has a PR claiming to fix this (https://github.com/python/mypy/pull/14677) which might mean this gets resolved soon? * Better annotation for INTERACTIVE_AUTH_CHECKERS * Drive-by AUTH_TYPE annotation, to remove an ignore
* Fix order of partial state tables when purging (#15068)David Robertson2023-02-141-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Fix order of partial state tables when purging `partial_state_rooms` has an FK on `events` pointing to the join event we get from `/send_join`, so we must delete from that table before deleting from `events`. **NB:** It would be nice to cancel any resync processes for the room being purged. We do not do this at present. To do so reliably we'd need an internal HTTP "replication" endpoint, because the worker doing the resync process may be different to that handling the purge request. The first time the resync process tries to write data after the deletion it will fail because we have deleted necessary data e.g. auth events. AFAICS it will not retry the resync, so the only downside to not cancelling the resync is a scary-looking traceback. (This is presumably extremely race-sensitive.) * Changelog * admist(?) -> between * Warn about a race * Fix typo, thanks Sean Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com> --------- Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com>
* Fix clashing DB txn name (#15070)Erik Johnston2023-02-141-1/+1
| | | | | * Fix clashing DB txn name * Newsfile
* Skip calculating unread push actions in `/sync` when `enable_push` is false. ↵Erik Johnston2023-02-141-0/+7
| | | | (#14980)
* Change collection[str] to StrCollection in event_auth code (#14929)Harishankar Kumar2023-02-142-7/+6
| | | Signed-off-by: Harishankar Kumar <hari01584@gmail.com>
* Faster joins: don't stall when a user joins during a fast join (#14606)Mathieu Velten2023-02-101-20/+1
| | | | | | | | | | | | | | | | Fixes #12801. Complement tests are at https://github.com/matrix-org/complement/pull/567. Avoid blocking on full state when handling a subsequent join into a partial state room. Also always perform a remote join into partial state rooms, since we do not know whether the joining user has been banned and want to avoid leaking history to banned users. Signed-off-by: Mathieu Velten <mathieuv@matrix.org> Co-authored-by: Sean Quah <seanq@matrix.org> Co-authored-by: David Robertson <davidr@element.io>
* Return read-only collections from `@cached` methods (#13755)Sean Quah2023-02-1015-55/+74
| | | | | | | | | | | | | It's important that collections returned from `@cached` methods are not modified, otherwise future retrievals from the cache will return the modified collection. This applies to the return values from `@cached` methods and the values inside the dictionaries returned by `@cachedList` methods. It's not necessary for the dictionaries returned by `@cachedList` methods themselves to be read-only. Signed-off-by: Sean Quah <seanq@matrix.org> Co-authored-by: David Robertson <davidr@element.io>
* Avoid fetching unused account data in sync. (#14973)Patrick Cloke2023-02-101-36/+91
| | | | | | | The per-room account data is no longer unconditionally fetched, even if all rooms will be filtered out. Global account data will not be fetched if it will all be filtered out.
* Merge branch 'release-v1.77' into developDavid Robertson2023-02-101-2/+7
|\
| * Bump schema version (#15036)David Robertson2023-02-091-2/+7
| | | | | | | | | | | | | | | | * Bump schema version This should have been included in f10caa73eee0caa91cf373966104d1ededae2aee (and #14979). * Changelog
* | Refactor get_user_devices_from_cache to avoid mutating cached values. (#15040)Patrick Cloke2023-02-101-14/+17
| | | | | | | | | | | | | | | | The previous version of the code could mutate a cached value, but only if the input requested all devices of a user *and* a specific device. To avoid this nonsensical situation we no longer fetch a specific device ID if all of a user's devices are returned.
* | Fix exception on start up about device lists (#15041)Erik Johnston2023-02-101-0/+1
| | | | | | Fixes #15010.
* | Do not always start a db txn on Postgres (#14840)Andrew Morgan2023-02-091-4/+9
| |
* | Add final type hint to synapse.server. (#15035)Patrick Cloke2023-02-093-1/+4
|/
* Disambiguate `get_ex_outlier_stream_rows` queryDavid Robertson2023-02-071-4/+4
| | | | A backwards-compatible piece of #14979 that's safe to land now.
* Revert "Add `event_stream_ordering` column to membership state tables (#14979)"David Robertson2023-02-074-145/+11
| | | | This reverts commit 5fdc12f482c68e2cdbb78d7db5de2cfe621720d4.
* Add `event_stream_ordering` column to membership state tables (#14979)Nick Mills-Barrett2023-02-074-11/+145
| | | | | | | | | | | | This adds an `event_stream_ordering` column to `current_state_events`, `local_current_membership` and `room_memberships`. Each of these tables is regularly joined with the `events` table to get the stream ordering and denormalising this into each table will yield significant query performance improvements once used. Includes a background job to populate these values from the `events` table. Same idea as https://github.com/matrix-org/synapse/pull/13703. Signed off by Nick @ Beeper (@fizzadar).
* Type hints for tests.appservice (#14990)David Robertson2023-02-061-2/+12
| | | | | | | | | | | | | | | | | | | | * Accept a Sequence of events in synapse.appservice This avoids some casts/ignores in the tests I'm about to fixup. It seems that `List[Mock]` is not a subtype of `List[EventBase]`, but `Sequence[Mock]` is a subtype of `Sequence[EventBase]`. So presumably `Mock` is considered a subtype of anything, much like `Any`. * make tests.appservice.test_scheduler pass mypy * Extra hints in tests.appservice.test_scheduler * Extra hints in tests.appservice.test_api * Extra hints in tests.appservice.test_appservice * Disallow untyped defs * Changelog
* Implement MSC3958: suppress notifications from edits (#14960)Patrick Cloke2023-02-031-0/+1
| | | | | | | | Co-authored-by: Brad Murray <brad@beeper.com> Co-authored-by: Nick Barrett <nick@beeper.com> Copy the suppress_edits push rule from Beeper to implement MSC3958. https://github.com/beeper/synapse/blame/9415a1284b1bfb558bd66f28c24ca1611e6c6fa2/rust/src/push/base_rules.rs#L98-L114
* Faster joins: Refactor handling of servers in room (#14954)Sean Quah2023-02-032-18/+35
| | | | | | | | | | | | | | Ensure that the list of servers in a partial state room always contains the server we joined off. Also refactor `get_partial_state_servers_at_join` to return `None` when the given room is no longer partial stated, to explicitly indicate when the room has partial state. Otherwise it's not clear whether an empty list means that the room has full state, or the room is partial stated, but the server we joined off told us that there are no servers in the room. Signed-off-by: Sean Quah <seanq@matrix.org>
* Fetch fewer events when getting hosts in room (#14962)David Robertson2023-02-021-2/+44
|
* Add helper to parse an enum from query args & use it. (#14956)Patrick Cloke2023-02-016-22/+27
| | | | | | | | The `parse_enum` helper pulls an enum value from the query string (by delegating down to the parse_string helper with values generated from the enum). This is used to pull out "f" and "b" in most places and then we thread the resulting Direction enum throughout more code.
* Attempt to delete more duplicate rows in receipts_linearized table. (#14915)Patrick Cloke2023-02-011-8/+26
| | | | | | | | | The previous assumption was that the stream_id column was unique (for a room ID, receipt type, user ID tuple), but this turned out to be incorrect. Now find the max stream ID, then map this back to a database-specific row identifier and delete other rows which match the (room ID, receipt type, user ID) tuple, but *not* the row ID.
* Make sqlite database migrations transactional again, part two (#14926)Sean Quah2023-01-313-5/+12
| | | | | | | | | | | | | | | | #14910 fixed the regression introduced by #13873 where sqlite database migrations would no longer run inside a transaction. However, it committed the transaction before Synapse updated its bookkeeping of which migrations have been run, which means that migrations may be run again after they have completed successfully. Leave the transaction open at the end of `executescript`, to restore the old, correct behaviour. Also make the PostgreSQL behaviour consistent with SQLite. Fixes #14909. Signed-off-by: Sean Quah <seanq@matrix.org>
* Prefer `type(x) is int` to `isinstance(x, int)` (#14945)David Robertson2023-01-311-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Perfer `type(x) is int` to `isinstance(x, int)` This covered all additional instances I could see where `x` was user-controlled. The remaining cases are ``` $ rg -s 'isinstance.*[^_]int' tests/replication/_base.py 576: if isinstance(obj, int): synapse/util/caches/stream_change_cache.py 136: assert isinstance(stream_pos, int) 214: assert isinstance(stream_pos, int) 246: assert isinstance(stream_pos, int) 267: assert isinstance(stream_pos, int) synapse/replication/tcp/external_cache.py 133: if isinstance(result, int): synapse/metrics/__init__.py 100: if isinstance(calls, (int, float)): synapse/handlers/appservice.py 262: assert isinstance(new_token, int) synapse/config/_util.py 62: if isinstance(p, int): ``` which cover metrics, logic related to `jsonschema`, and replication and data streams. AFAICS these are all internal to Synapse * Changelog
* Implement MSC3952: Intentional mentions (#14823)Patrick Cloke2023-01-271-0/+1
| | | | | | | | MSC3952 defines push rules which searches for mentions in a list of Matrix IDs in the event body, instead of searching the entire event body for display name / local part. This is implemented behind an experimental configuration flag and does not yet implement the backwards compatibility pieces of the MSC.
* Merge branch 'release-v1.76' into developDavid Robertson2023-01-273-4/+26
|\
| * Batch look-ups to see if rooms are partial stated. (#14917)Patrick Cloke2023-01-262-4/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Batch look-ups to see if rooms are partial stated. * Fix issues found in linting. * Fix typo. * Apply suggestions from code review Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com> * Clarify comments. Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com> * Also improve the cache size while we're at it * is_partial_state_rooms -> is_partial_state_room_batched * Run `black` * Improve annotation for `simple_select_many_batch` * Fix is_partial_state_room_batched impl * Okay, _actually_ fix impl * Update description. * Update synapse/storage/databases/main/room.py Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com> * Run black. Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com> Co-authored-by: David Robertson <davidr@element.io>
| * Fix initialization of `_device_list_id_gen` (#14914)Sean Quah2023-01-261-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On startup, the `_device_list_id_gen` stream id generator is initialized using the maximum stream id seen in a list of tables. When we started populating the `device_list_remote_pending` table in #13913, we forgot to add it to the aforementioned list of tables, so the stream id generator can hand out old stream ids after a restart. The end result is that Synapse can fail to handle device list update EDUs after a restart when a partial state join is in progress. Add the `device_list_remote_pending` table to the list of tables to consider when initializing the `_device_list_id_gen` stream id generator. Signed-off-by: Sean Quah <seanq@matrix.org>
* | Use an enum for direction. (#14927)Patrick Cloke2023-01-272-32/+35
| | | | | | | | For better type safety we use an enum instead of strings to configure direction (backwards or forwards).
* | Fix paginating /relations with a live token (#14866)Patrick Cloke2023-01-262-70/+122
|/ | | | | The `/relations` endpoint was not properly handle "live tokens" (i.e sync tokens), to do this properly we abstract the code that `/messages` has and re-use it.
* Make sqlite database migrations transactional again (#14910)Sean Quah2023-01-252-2/+6
| | | | | | | | | | #13873 introduced a regression which causes sqlite database migrations to no longer run inside a transaction. Wrap them in a transaction again, to avoid database corruption when migrations are interrupted. Fixes #14909. Signed-off-by: Sean Quah <seanq@matrix.org>
* Request partial joins by default (#14905)David Robertson2023-01-241-6/+34
| | | | | | | | | | | | | | | | | | | | | | | | | * Request partial joins by default This is a little sloppy, but we are trying to gain confidence in faster joins in the upcoming RC. Admins can still opt out by adding the following to their Synapse config: ```yaml experimental: faster_joins: false ``` We may revert this change before the release proper, depending on how testing in the wild goes. * Changelog * Try to fix the backfill test failures * Upgrade notes * Postgres compat?
* Faster joins: omit partial rooms from eager syncs until the resync completes ↵David Robertson2023-01-233-11/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (#14870) * Allow `AbstractSet` in `StrCollection` Or else frozensets are excluded. This will be useful in an upcoming commit where I plan to change a function that accepts `List[str]` to accept `StrCollection` instead. * `rooms_to_exclude` -> `rooms_to_exclude_globally` I am about to make use of this exclusion mechanism to exclude rooms for a specific user and a specific sync. This rename helps to clarify the distinction between the global config and the rooms to exclude for a specific sync. * Better function names for internal sync methods * Track a list of excluded rooms on SyncResultBuilder I plan to feed a list of partially stated rooms for this sync to ignore * Exclude partial state rooms during eager sync using the mechanism established in the previous commit * Track un-partial-state stream in sync tokens So that we can work out which rooms have become fully-stated during a given sync period. * Fix mutation of `@cached` return value This was fouling up a complement test added alongside this PR. Excluding a room would mean the set of forgotten rooms in the cache would be extended. This means that room could be erroneously considered forgotten in the future. Introduced in #12310, Synapse 1.57.0. I don't think this had any user-visible side effects (until now). * SyncResultBuilder: track rooms to force as newly joined Similar plan as before. We've omitted rooms from certain sync responses; now we establish the mechanism to reintroduce them into future syncs. * Read new field, to present rooms as newly joined * Force un-partial-stated rooms to be newly-joined for eager incremental syncs only, provided they're still fully stated * Notify user stream listeners to wake up long polling syncs * Changelog * Typo fix Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com> * Unnecessary list cast Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com> * Rephrase comment Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com> * Another comment Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com> * Fixup merge(?) * Poke notifier when receiving un-partial-stated msg over replication * Fixup merge whoops Thanks MV :) Co-authored-by: Mathieu Velen <mathieuv@matrix.org> Co-authored-by: Mathieu Velten <mathieuv@matrix.org> Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com>
* Skip processing stats for broken rooms. (#14873)Patrick Cloke2023-01-232-2/+17
| | | | | | | * Skip processing stats for broken rooms. * Newsfragment * Use a custom exception.
* Faster joins: Update room stats and the user directory on workers when ↵Sean Quah2023-01-231-2/+0
| | | | | | | | | | | | | | | | | | | | | | | finishing join (#14874) * Faster joins: Update room stats and user directory on workers when done When finishing a partial state join to a room, we update the current state of the room without persisting additional events. Workers receive notice of the current state update over replication, but neglect to wake the room stats and user directory updaters, which then get incidentally triggered the next time an event is persisted or an unrelated event persister sends out a stream position update. We wake the room stats and user directory updaters at the appropriate time in this commit. Part of #12814 and #12815. Signed-off-by: Sean Quah <seanq@matrix.org> * fixup comment Signed-off-by: Sean Quah <seanq@matrix.org>
* Enable Faster Remote Room Joins against worker-mode Synapse. (#14752)reivilibre2023-01-223-12/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Enable Complement tests for Faster Remote Room Joins on worker-mode * (dangerous) Add an override to allow Complement to use FRRJ under workers * Newsfile Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org> * Fix race where we didn't send out replication notification * MORE HACKS * Fix get_un_partial_stated_rooms_token to take instance_name * Fix bad merge * Remove warning * Correctly advance un_partial_stated_room_stream * Fix merge * Add another notify_replication * Fixups * Create a separate ReplicationNotifier * Fix test * Fix portdb * Create a separate ReplicationNotifier * Fix test * Fix portdb * Fix presence test * Newsfile * Apply suggestions from code review * Update changelog.d/14752.misc Co-authored-by: Erik Johnston <erik@matrix.org> * lint Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org> Co-authored-by: Erik Johnston <erik@matrix.org>
* Always notify replication when a stream advances (#14877)Erik Johnston2023-01-2012-7/+54
| | | This ensures that all other workers are told about stream updates in a timely manner, without having to remember to manually poke replication.
* Implement MSC3930: polls push rules (#14787)Andrew Morgan2023-01-191-1/+2
|
* Wait for streams to catch up when processing HTTP replication. (#14820)Erik Johnston2023-01-181-15/+19
| | | | This should hopefully mitigate a class of races where data gets out of sync due a HTTP replication request racing with the replication streams.
* Merge device list replication streams (#14833)Erik Johnston2023-01-171-6/+7
|
* Merge account data streams (#14826)Erik Johnston2023-01-132-45/+15
|
* Drop unused table `presence` (#14825)Dirk Klimpel2023-01-131-0/+17
|
* Merge remote-tracking branch 'origin/release-v1.75' into developRichard van der Hoff2023-01-121-6/+59
|\
| * Fix race calling `/members?at=` (#14817)Erik Johnston2023-01-121-6/+59
| | | | | | Fixes #14814
* | Add index to improve performance of the `/timestamp_to_event` endpoint used ↵reivilibre2023-01-112-0/+29
|/ | | | for jumping to a specific date in the timeline of a room. (#14799)
* Batch up replication requests to request the resyncing of remote users's ↵reivilibre2023-01-101-8/+22
| | | | devices. (#14716)
* Update all stream IDs after processing replication rows (#14723)Nick Mills-Barrett2023-01-0411-20/+91
| | | | | | | | | | | | | | This creates a new store method, `process_replication_position` that is called after `process_replication_rows`. By moving stream ID advances here this guarantees any relevant cache invalidations will have been applied before the stream is advanced. This avoids race conditions where Python switches between threads mid way through processing the `process_replication_rows` method where stream IDs may be advanced before caches are invalidated due to class resolution ordering. See this comment/issue for further discussion: https://github.com/matrix-org/synapse/issues/14158#issuecomment-1344048703
* Add experimental support for MSC3391: deleting account data (#14714)Andrew Morgan2023-01-012-14/+238
|
* Faster remote room joins: invalidate caches and unblock requests when ↵reivilibre2022-12-192-13/+32
| | | | receiving un-partial-stated event notifications over replication. [rei:frrj/streams/unpsr] (#14546)
* Faster remote room joins: stream the un-partial-stating of events over ↵reivilibre2022-12-144-9/+167
| | | | replication. [rei:frrj/streams/unpsr] (#14545)
* Delete event_push_summary_unique_index again. (#14669)Patrick Cloke2022-12-142-9/+33
| | | | | | | | | | | | | | | | | | if a Synapse deployment upgraded (from < 1.62.0 to >= 1.70.0) then it is possible for schema deltas to run before background updates causing drift in the database schema due to: 1. A delta registered a background update to create an index. 2. A delta dropped the above index if it exists (but it yet exist won't since the background job hasn't run). 3. The code assumed the index was dropped. To fix this we: 1. Cancel the background update which could create the index. 2. Drop the index again. 3. Drop a related index which is dropped by the background update.
* Allow selecting "prejoin" events by state keys (#14642)David Robertson2022-12-131-14/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Declare new config * Parse new config * Read new config * Don't use trial/our TestCase where it's not needed Before: ``` $ time trial tests/events/test_utils.py > /dev/null real 0m2.277s user 0m2.186s sys 0m0.083s ``` After: ``` $ time trial tests/events/test_utils.py > /dev/null real 0m0.566s user 0m0.508s sys 0m0.056s ``` * Helper to upsert to event fields without exceeding size limits. * Use helper when adding invite/knock state Now that we allow admins to include events in prejoin room state with arbitrary state keys, be a good Matrix citizen and ensure they don't accidentally create an oversized event. * Changelog * Move StateFilter tests should have done this in #14668 * Add extra methods to StateFilter * Use StateFilter * Ensure test file enforces typed defs; alphabetise * Workaround surprising get_current_state_ids * Whoops, fix mypy
* Enable `--warn-redundant-casts` option in mypy (#14671)David Robertson2022-12-122-2/+3
| | | | | | | | | | | | | | | | | | | * Enable `--warn-redundant-casts` option in mypy Doesn't do much but helps me sleep better at night. * Changelog * Fix name of the ignore * Fix one more missed cast Not sure why I didn't see this one locally, maybe I needed a poetry update * Remove old comment Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com> Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>