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

Commit

Permalink
Remove HomeServer.get_datastore() (#12031)
Browse files Browse the repository at this point in the history
The presence of this method was confusing, and mostly present for backwards
compatibility. Let's get rid of it.

Part of #11733
  • Loading branch information
richvdh authored Feb 23, 2022
1 parent c1ac2a8 commit e24ff8e
Show file tree
Hide file tree
Showing 230 changed files with 526 additions and 500 deletions.
1 change: 1 addition & 0 deletions changelog.d/12031.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove legacy `HomeServer.get_datastore()`.
2 changes: 1 addition & 1 deletion docs/manhole.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ As a simple example, retrieving an event from the database:

```pycon
>>> from twisted.internet import defer
>>> defer.ensureDeferred(hs.get_datastore().get_event('$1416420717069yeQaw:matrix.org'))
>>> defer.ensureDeferred(hs.get_datastores().main.get_event('$1416420717069yeQaw:matrix.org'))
<Deferred at 0x7ff253fc6998 current result: <FrozenEvent event_id='$1416420717069yeQaw:matrix.org', type='m.room.create', state_key=''>>
```
2 changes: 1 addition & 1 deletion scripts/update_synapse_database
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MockHomeserver(HomeServer):


def run_background_updates(hs):
store = hs.get_datastore()
store = hs.get_datastores().main

async def run_background_updates():
await store.db_pool.updates.run_background_updates(sleep=False)
Expand Down
2 changes: 1 addition & 1 deletion synapse/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Auth:
def __init__(self, hs: "HomeServer"):
self.hs = hs
self.clock = hs.get_clock()
self.store = hs.get_datastore()
self.store = hs.get_datastores().main
self.state = hs.get_state_handler()
self._account_validity_handler = hs.get_account_validity_handler()

Expand Down
2 changes: 1 addition & 1 deletion synapse/api/auth_blocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

class AuthBlocking:
def __init__(self, hs: "HomeServer"):
self.store = hs.get_datastore()
self.store = hs.get_datastores().main

self._server_notices_mxid = hs.config.servernotices.server_notices_mxid
self._hs_disabled = hs.config.server.hs_disabled
Expand Down
4 changes: 2 additions & 2 deletions synapse/api/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def matrix_user_id_validator(user_id_str: str) -> UserID:
class Filtering:
def __init__(self, hs: "HomeServer"):
self._hs = hs
self.store = hs.get_datastore()
self.store = hs.get_datastores().main

self.DEFAULT_FILTER_COLLECTION = FilterCollection(hs, {})

Expand Down Expand Up @@ -294,7 +294,7 @@ def blocks_all_room_timeline(self) -> bool:
class Filter:
def __init__(self, hs: "HomeServer", filter_json: JsonDict):
self._hs = hs
self._store = hs.get_datastore()
self._store = hs.get_datastores().main
self.filter_json = filter_json

self.limit = filter_json.get("limit", 10)
Expand Down
2 changes: 1 addition & 1 deletion synapse/app/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def run_sighup(*args: Any, **kwargs: Any) -> None:

# It is now safe to start your Synapse.
hs.start_listening()
hs.get_datastore().db_pool.start_profiling()
hs.get_datastores().main.db_pool.start_profiling()
hs.get_pusherpool().start()

# Log when we start the shut down process.
Expand Down
2 changes: 1 addition & 1 deletion synapse/app/generic_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def __init__(self, hs: HomeServer):
"""
super().__init__()
self.auth = hs.get_auth()
self.store = hs.get_datastore()
self.store = hs.get_datastores().main
self.http_client = hs.get_simple_http_client()
self.main_uri = hs.config.worker.worker_main_http_uri

Expand Down
2 changes: 1 addition & 1 deletion synapse/app/homeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ async def start() -> None:

await _base.start(hs)

hs.get_datastore().db_pool.updates.start_doing_background_updates()
hs.get_datastores().main.db_pool.updates.start_doing_background_updates()

register_start(start)

Expand Down
14 changes: 9 additions & 5 deletions synapse/app/phone_stats_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async def phone_stats_home(
# General statistics
#

store = hs.get_datastore()
store = hs.get_datastores().main

stats["homeserver"] = hs.config.server.server_name
stats["server_context"] = hs.config.server.server_context
Expand Down Expand Up @@ -170,18 +170,22 @@ def performance_stats_init() -> None:
# Rather than update on per session basis, batch up the requests.
# If you increase the loop period, the accuracy of user_daily_visits
# table will decrease
clock.looping_call(hs.get_datastore().generate_user_daily_visits, 5 * 60 * 1000)
clock.looping_call(
hs.get_datastores().main.generate_user_daily_visits, 5 * 60 * 1000
)

# monthly active user limiting functionality
clock.looping_call(hs.get_datastore().reap_monthly_active_users, 1000 * 60 * 60)
hs.get_datastore().reap_monthly_active_users()
clock.looping_call(
hs.get_datastores().main.reap_monthly_active_users, 1000 * 60 * 60
)
hs.get_datastores().main.reap_monthly_active_users()

@wrap_as_background_process("generate_monthly_active_users")
async def generate_monthly_active_users() -> None:
current_mau_count = 0
current_mau_count_by_service = {}
reserved_users: Sized = ()
store = hs.get_datastore()
store = hs.get_datastores().main
if hs.config.server.limit_usage_by_mau or hs.config.server.mau_stats_only:
current_mau_count = await store.get_monthly_active_count()
current_mau_count_by_service = (
Expand Down
2 changes: 1 addition & 1 deletion synapse/appservice/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class ApplicationServiceScheduler:

def __init__(self, hs: "HomeServer"):
self.clock = hs.get_clock()
self.store = hs.get_datastore()
self.store = hs.get_datastores().main
self.as_api = hs.get_application_service_api()

self.txn_ctrl = _TransactionController(self.clock, self.store, self.as_api)
Expand Down
4 changes: 2 additions & 2 deletions synapse/crypto/keyring.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ class StoreKeyFetcher(KeyFetcher):
def __init__(self, hs: "HomeServer"):
super().__init__(hs)

self.store = hs.get_datastore()
self.store = hs.get_datastores().main

async def _fetch_keys(
self, keys_to_fetch: List[_FetchKeyRequest]
Expand All @@ -498,7 +498,7 @@ class BaseV2KeyFetcher(KeyFetcher):
def __init__(self, hs: "HomeServer"):
super().__init__(hs)

self.store = hs.get_datastore()
self.store = hs.get_datastores().main
self.config = hs.config

async def process_v2_response(
Expand Down
2 changes: 1 addition & 1 deletion synapse/events/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def __init__(self, hs: "HomeServer"):
self.hostname = hs.hostname
self.signing_key = hs.signing_key

self.store = hs.get_datastore()
self.store = hs.get_datastores().main
self.state = hs.get_state_handler()
self._event_auth_handler = hs.get_event_auth_handler()

Expand Down
2 changes: 1 addition & 1 deletion synapse/events/third_party_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class ThirdPartyEventRules:
def __init__(self, hs: "HomeServer"):
self.third_party_rules = None

self.store = hs.get_datastore()
self.store = hs.get_datastores().main

self._check_event_allowed_callbacks: List[CHECK_EVENT_ALLOWED_CALLBACK] = []
self._on_create_room_callbacks: List[ON_CREATE_ROOM_CALLBACK] = []
Expand Down
2 changes: 1 addition & 1 deletion synapse/federation/federation_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, hs: "HomeServer"):
self.server_name = hs.hostname
self.keyring = hs.get_keyring()
self.spam_checker = hs.get_spam_checker()
self.store = hs.get_datastore()
self.store = hs.get_datastores().main
self._clock = hs.get_clock()

async def _check_sigs_and_hash(
Expand Down
2 changes: 1 addition & 1 deletion synapse/federation/sender/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def __init__(self, hs: "HomeServer"):
self.hs = hs
self.server_name = hs.hostname

self.store = hs.get_datastore()
self.store = hs.get_datastores().main
self.state = hs.get_state_handler()

self.clock = hs.get_clock()
Expand Down
9 changes: 5 additions & 4 deletions synapse/federation/sender/per_destination_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(
):
self._server_name = hs.hostname
self._clock = hs.get_clock()
self._store = hs.get_datastore()
self._store = hs.get_datastores().main
self._transaction_manager = transaction_manager
self._instance_name = hs.get_instance_name()
self._federation_shard_config = hs.config.worker.federation_shard_config
Expand Down Expand Up @@ -381,9 +381,8 @@ async def _catch_up_transmission_loop(self) -> None:
)
)

last_successful_stream_ordering = self._last_successful_stream_ordering

if last_successful_stream_ordering is None:
_tmp_last_successful_stream_ordering = self._last_successful_stream_ordering
if _tmp_last_successful_stream_ordering is None:
# if it's still None, then this means we don't have the information
# in our database ­ we haven't successfully sent a PDU to this server
# (at least since the introduction of the feature tracking
Expand All @@ -393,6 +392,8 @@ async def _catch_up_transmission_loop(self) -> None:
self._catching_up = False
return

last_successful_stream_ordering: int = _tmp_last_successful_stream_ordering

# get at most 50 catchup room/PDUs
while True:
event_ids = await self._store.get_catch_up_room_event_ids(
Expand Down
2 changes: 1 addition & 1 deletion synapse/federation/sender/transaction_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class TransactionManager:
def __init__(self, hs: "synapse.server.HomeServer"):
self._server_name = hs.hostname
self.clock = hs.get_clock() # nb must be called this for @measure_func
self._store = hs.get_datastore()
self._store = hs.get_datastores().main
self._transaction_actions = TransactionActions(self._store)
self._transport_layer = hs.get_federation_transport_client()

Expand Down
2 changes: 1 addition & 1 deletion synapse/federation/transport/server/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, hs: "HomeServer"):
self._clock = hs.get_clock()
self.keyring = hs.get_keyring()
self.server_name = hs.hostname
self.store = hs.get_datastore()
self.store = hs.get_datastores().main
self.federation_domain_whitelist = (
hs.config.federation.federation_domain_whitelist
)
Expand Down
2 changes: 1 addition & 1 deletion synapse/federation/transport/server/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ def __init__(
server_name: str,
):
super().__init__(hs, authenticator, ratelimiter, server_name)
self._store = self.hs.get_datastore()
self._store = self.hs.get_datastores().main

async def on_GET(
self,
Expand Down
2 changes: 1 addition & 1 deletion synapse/groups/attestations.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class GroupAttestionRenewer:

def __init__(self, hs: "HomeServer"):
self.clock = hs.get_clock()
self.store = hs.get_datastore()
self.store = hs.get_datastores().main
self.assestations = hs.get_groups_attestation_signing()
self.transport_client = hs.get_federation_transport_client()
self.is_mine_id = hs.is_mine_id
Expand Down
2 changes: 1 addition & 1 deletion synapse/groups/groups_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
class GroupsServerWorkerHandler:
def __init__(self, hs: "HomeServer"):
self.hs = hs
self.store = hs.get_datastore()
self.store = hs.get_datastores().main
self.room_list_handler = hs.get_room_list_handler()
self.auth = hs.get_auth()
self.clock = hs.get_clock()
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

class AccountDataHandler:
def __init__(self, hs: "HomeServer"):
self._store = hs.get_datastore()
self._store = hs.get_datastores().main
self._instance_name = hs.get_instance_name()
self._notifier = hs.get_notifier()

Expand Down Expand Up @@ -166,7 +166,7 @@ async def remove_tag_from_room(self, user_id: str, room_id: str, tag: str) -> in

class AccountDataEventSource(EventSource[int, JsonDict]):
def __init__(self, hs: "HomeServer"):
self.store = hs.get_datastore()
self.store = hs.get_datastores().main

def get_current_key(self, direction: str = "f") -> int:
return self.store.get_max_account_data_stream_id()
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/account_validity.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AccountValidityHandler:
def __init__(self, hs: "HomeServer"):
self.hs = hs
self.config = hs.config
self.store = self.hs.get_datastore()
self.store = self.hs.get_datastores().main
self.send_email_handler = self.hs.get_send_email_handler()
self.clock = self.hs.get_clock()

Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

class AdminHandler:
def __init__(self, hs: "HomeServer"):
self.store = hs.get_datastore()
self.store = hs.get_datastores().main
self.storage = hs.get_storage()
self.state_store = self.storage.state

Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

class ApplicationServicesHandler:
def __init__(self, hs: "HomeServer"):
self.store = hs.get_datastore()
self.store = hs.get_datastores().main
self.is_mine_id = hs.is_mine_id
self.appservice_api = hs.get_application_service_api()
self.scheduler = hs.get_application_service_scheduler()
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class AuthHandler:
SESSION_EXPIRE_MS = 48 * 60 * 60 * 1000

def __init__(self, hs: "HomeServer"):
self.store = hs.get_datastore()
self.store = hs.get_datastores().main
self.auth = hs.get_auth()
self.clock = hs.get_clock()
self.checkers: Dict[str, UserInteractiveAuthChecker] = {}
Expand Down Expand Up @@ -1183,7 +1183,7 @@ async def validate_login(

# No password providers were able to handle this 3pid
# Check local store
user_id = await self.hs.get_datastore().get_user_id_by_threepid(
user_id = await self.hs.get_datastores().main.get_user_id_by_threepid(
medium, address
)
if not user_id:
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/cas.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class CasHandler:
def __init__(self, hs: "HomeServer"):
self.hs = hs
self._hostname = hs.hostname
self._store = hs.get_datastore()
self._store = hs.get_datastores().main
self._auth_handler = hs.get_auth_handler()
self._registration_handler = hs.get_registration_handler()

Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/deactivate_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DeactivateAccountHandler:
"""Handler which deals with deactivating user accounts."""

def __init__(self, hs: "HomeServer"):
self.store = hs.get_datastore()
self.store = hs.get_datastores().main
self.hs = hs
self._auth_handler = hs.get_auth_handler()
self._device_handler = hs.get_device_handler()
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class DeviceWorkerHandler:
def __init__(self, hs: "HomeServer"):
self.clock = hs.get_clock()
self.hs = hs
self.store = hs.get_datastore()
self.store = hs.get_datastores().main
self.notifier = hs.get_notifier()
self.state = hs.get_state_handler()
self.state_store = hs.get_storage().state
Expand Down Expand Up @@ -628,7 +628,7 @@ class DeviceListUpdater:
"Handles incoming device list updates from federation and updates the DB"

def __init__(self, hs: "HomeServer", device_handler: DeviceHandler):
self.store = hs.get_datastore()
self.store = hs.get_datastores().main
self.federation = hs.get_federation_client()
self.clock = hs.get_clock()
self.device_handler = device_handler
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/devicemessage.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, hs: "HomeServer"):
Args:
hs: server
"""
self.store = hs.get_datastore()
self.store = hs.get_datastores().main
self.notifier = hs.get_notifier()
self.is_mine = hs.is_mine

Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, hs: "HomeServer"):
self.state = hs.get_state_handler()
self.appservice_handler = hs.get_application_service_handler()
self.event_creation_handler = hs.get_event_creation_handler()
self.store = hs.get_datastore()
self.store = hs.get_datastores().main
self.config = hs.config
self.enable_room_list_search = hs.config.roomdirectory.enable_room_list_search
self.require_membership = hs.config.server.require_membership_for_aliases
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/e2e_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

class E2eKeysHandler:
def __init__(self, hs: "HomeServer"):
self.store = hs.get_datastore()
self.store = hs.get_datastores().main
self.federation = hs.get_federation_client()
self.device_handler = hs.get_device_handler()
self.is_mine = hs.is_mine
Expand Down Expand Up @@ -1335,7 +1335,7 @@ class SigningKeyEduUpdater:
"""Handles incoming signing key updates from federation and updates the DB"""

def __init__(self, hs: "HomeServer", e2e_keys_handler: E2eKeysHandler):
self.store = hs.get_datastore()
self.store = hs.get_datastores().main
self.federation = hs.get_federation_client()
self.clock = hs.get_clock()
self.e2e_keys_handler = e2e_keys_handler
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/e2e_room_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class E2eRoomKeysHandler:
"""

def __init__(self, hs: "HomeServer"):
self.store = hs.get_datastore()
self.store = hs.get_datastores().main

# Used to lock whenever a client is uploading key data. This prevents collisions
# between clients trying to upload the details of a new session, given all
Expand Down
Loading

0 comments on commit e24ff8e

Please sign in to comment.