Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 56722c6

Browse files
committed
Merge commit '0d4f614fd' into anoa/dinsic_release_1_21_x
* commit '0d4f614fd': Refactor `_get_e2e_device_keys_for_federation_query_txn` (#8225) Add experimental support for sharding event persister. (#8170) Add /user/{user_id}/shared_rooms/ api (#7785) Do not try to store invalid data in the stats table (#8226) Convert the main methods run by the reactor to async. (#8213)
2 parents 2bd022e + 0d4f614 commit 56722c6

34 files changed

+531
-121
lines changed

UPGRADE.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
Upgrading to v1.20.0
2+
====================
3+
4+
Shared rooms endpoint (MSC2666)
5+
-------------------------------
6+
7+
This release contains a new unstable endpoint `/_matrix/client/unstable/uk.half-shot.msc2666/user/shared_rooms/.*`
8+
for fetching rooms one user has in common with another. This feature requires the
9+
`update_user_directory` config flag to be `True`. If you are you are using a `synapse.app.user_dir`
10+
worker, requests to this endpoint must be handled by that worker.
11+
See `docs/workers.md <docs/workers.md>`_ for more details.
12+
13+
114
Upgrading Synapse
215
=================
316

changelog.d/7785.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add an endpoint to query your shared rooms with another user as an implementation of [MSC2666](https://github.com/matrix-org/matrix-doc/pull/2666).

changelog.d/8170.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add experimental support for sharding event persister.

changelog.d/8213.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Convert various parts of the codebase to async/await.

changelog.d/8225.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Refactor queries for device keys and cross-signatures.

changelog.d/8226.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a longstanding bug where stats updates could break when unexpected profile data was included in events.

docs/workers.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ Handles searches in the user directory. It can handle REST endpoints matching
380380
the following regular expressions:
381381

382382
^/_matrix/client/(api/v1|r0|unstable)/user_directory/search$
383+
^/_matrix/client/unstable/uk.half-shot.msc2666/user/shared_rooms/.*$
383384

384385
When using this worker you must also set `update_user_directory: False` in the
385386
shared configuration file to stop the main synapse running background

synapse/app/admin_cmd.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ def start_listening(self, listeners):
7979
pass
8080

8181

82-
@defer.inlineCallbacks
83-
def export_data_command(hs, args):
82+
async def export_data_command(hs, args):
8483
"""Export data for a user.
8584
8685
Args:
@@ -91,10 +90,8 @@ def export_data_command(hs, args):
9190
user_id = args.user_id
9291
directory = args.output_directory
9392

94-
res = yield defer.ensureDeferred(
95-
hs.get_handlers().admin_handler.export_user_data(
96-
user_id, FileExfiltrationWriter(user_id, directory=directory)
97-
)
93+
res = await hs.get_handlers().admin_handler.export_user_data(
94+
user_id, FileExfiltrationWriter(user_id, directory=directory)
9895
)
9996
print(res)
10097

@@ -232,14 +229,15 @@ def start(config_options):
232229
# We also make sure that `_base.start` gets run before we actually run the
233230
# command.
234231

235-
@defer.inlineCallbacks
236-
def run(_reactor):
232+
async def run():
237233
with LoggingContext("command"):
238-
yield _base.start(ss, [])
239-
yield args.func(ss, args)
234+
_base.start(ss, [])
235+
await args.func(ss, args)
240236

241237
_base.start_worker_reactor(
242-
"synapse-admin-cmd", config, run_command=lambda: task.react(run)
238+
"synapse-admin-cmd",
239+
config,
240+
run_command=lambda: task.react(lambda _reactor: defer.ensureDeferred(run())),
243241
)
244242

245243

synapse/app/homeserver.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -411,26 +411,24 @@ async def do_acme() -> bool:
411411

412412
return provision
413413

414-
@defer.inlineCallbacks
415-
def reprovision_acme():
414+
async def reprovision_acme():
416415
"""
417416
Provision a certificate from ACME, if required, and reload the TLS
418417
certificate if it's renewed.
419418
"""
420-
reprovisioned = yield defer.ensureDeferred(do_acme())
419+
reprovisioned = await do_acme()
421420
if reprovisioned:
422421
_base.refresh_certificate(hs)
423422

424-
@defer.inlineCallbacks
425-
def start():
423+
async def start():
426424
try:
427425
# Run the ACME provisioning code, if it's enabled.
428426
if hs.config.acme_enabled:
429427
acme = hs.get_acme_handler()
430428
# Start up the webservices which we will respond to ACME
431429
# challenges with, and then provision.
432-
yield defer.ensureDeferred(acme.start_listening())
433-
yield defer.ensureDeferred(do_acme())
430+
await acme.start_listening()
431+
await do_acme()
434432

435433
# Check if it needs to be reprovisioned every day.
436434
hs.get_clock().looping_call(reprovision_acme, 24 * 60 * 60 * 1000)
@@ -439,8 +437,8 @@ def start():
439437
if hs.config.oidc_enabled:
440438
oidc = hs.get_oidc_handler()
441439
# Loading the provider metadata also ensures the provider config is valid.
442-
yield defer.ensureDeferred(oidc.load_metadata())
443-
yield defer.ensureDeferred(oidc.load_jwks())
440+
await oidc.load_metadata()
441+
await oidc.load_jwks()
444442

445443
_base.start(hs, config.listeners)
446444

@@ -456,7 +454,7 @@ def start():
456454
reactor.stop()
457455
sys.exit(1)
458456

459-
reactor.callWhenRunning(start)
457+
reactor.callWhenRunning(lambda: defer.ensureDeferred(start()))
460458

461459
return hs
462460

synapse/config/_base.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -833,11 +833,26 @@ class ShardedWorkerHandlingConfig:
833833
def should_handle(self, instance_name: str, key: str) -> bool:
834834
"""Whether this instance is responsible for handling the given key.
835835
"""
836-
837-
# If multiple instances are not defined we always return true.
836+
# If multiple instances are not defined we always return true
838837
if not self.instances or len(self.instances) == 1:
839838
return True
840839

840+
return self.get_instance(key) == instance_name
841+
842+
def get_instance(self, key: str) -> str:
843+
"""Get the instance responsible for handling the given key.
844+
845+
Note: For things like federation sending the config for which instance
846+
is sending is known only to the sender instance if there is only one.
847+
Therefore `should_handle` should be used where possible.
848+
"""
849+
850+
if not self.instances:
851+
return "master"
852+
853+
if len(self.instances) == 1:
854+
return self.instances[0]
855+
841856
# We shard by taking the hash, modulo it by the number of instances and
842857
# then checking whether this instance matches the instance at that
843858
# index.
@@ -847,7 +862,7 @@ def should_handle(self, instance_name: str, key: str) -> bool:
847862
dest_hash = sha256(key.encode("utf8")).digest()
848863
dest_int = int.from_bytes(dest_hash, byteorder="little")
849864
remainder = dest_int % (len(self.instances))
850-
return self.instances[remainder] == instance_name
865+
return self.instances[remainder]
851866

852867

853868
__all__ = ["Config", "RootConfig", "ShardedWorkerHandlingConfig"]

0 commit comments

Comments
 (0)