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

Clean up ShardedWorkerHandlingConfig #9466

Merged
merged 5 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions synapse/config/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,4 +876,20 @@ def get_instance(self, key: str) -> str:
return self.instances[remainder]


@attr.s
class RoutableShardedWorkerHandlingConfig(ShardedWorkerHandlingConfig):
"""A version of `ShardedWorkerHandlingConfig` that is used for config
options where all instances know which instances are responsible for the
sharded work.
"""

def __attrs_post_init__(self):
# We require that `self.instances` is non-empty.
assert self.instances
clokep marked this conversation as resolved.
Show resolved Hide resolved

def get_instance(self, key: str) -> str:
"""Get the instance responsible for handling the given key."""
return self._get_instance(key)
clokep marked this conversation as resolved.
Show resolved Hide resolved


__all__ = ["Config", "RootConfig", "ShardedWorkerHandlingConfig"]
2 changes: 2 additions & 0 deletions synapse/config/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,6 @@ class ShardedWorkerHandlingConfig:
instances: List[str]
def __init__(self, instances: List[str]) -> None: ...
def should_handle(self, instance_name: str, key: str) -> bool: ...

class RoutableShardedWorkerHandlingConfig(ShardedWorkerHandlingConfig):
def get_instance(self, key: str) -> str: ...
clokep marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 9 additions & 2 deletions synapse/config/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@

import attr

from ._base import Config, ConfigError, ShardedWorkerHandlingConfig
from ._base import (
Config,
ConfigError,
RoutableShardedWorkerHandlingConfig,
ShardedWorkerHandlingConfig,
)
from .server import ListenerConfig, parse_listener_def


Expand Down Expand Up @@ -164,7 +169,9 @@ def read_config(self, config, **kwargs):
"Must only specify one instance to handle `receipts` messages."
)

self.events_shard_config = ShardedWorkerHandlingConfig(self.writers.events)
self.events_shard_config = RoutableShardedWorkerHandlingConfig(
self.writers.events
)

# Whether this worker should run background tasks or not.
#
Expand Down