diff --git a/synapse/federation/federation_server.py b/synapse/federation/federation_server.py index 58def6bdf526..4a8f996cb87b 100644 --- a/synapse/federation/federation_server.py +++ b/synapse/federation/federation_server.py @@ -109,7 +109,6 @@ def __init__(self, hs: "HomeServer"): super().__init__(hs) self.handler = hs.get_federation_handler() - self.storage_controllers = hs.get_storage_controllers() self._spam_checker = hs.get_spam_checker() self._federation_event_handler = hs.get_federation_event_handler() self.state = hs.get_state_handler() diff --git a/synapse/handlers/admin.py b/synapse/handlers/admin.py index 31f2e60c320e..d4fe7df533a1 100644 --- a/synapse/handlers/admin.py +++ b/synapse/handlers/admin.py @@ -30,8 +30,8 @@ class AdminHandler: def __init__(self, hs: "HomeServer"): self.store = hs.get_datastores().main - self.storage_controllers = hs.get_storage_controllers() - self.state_storage_controller = self.storage_controllers.state + self._storage_controllers = hs.get_storage_controllers() + self._state_storage_controller = self._storage_controllers.state async def get_whois(self, user: UserID) -> JsonDict: connections = [] @@ -198,7 +198,7 @@ async def export_user_data(self, user_id: str, writer: "ExfiltrationWriter") -> from_key = events[-1].internal_metadata.after events = await filter_events_for_client( - self.storage_controllers, user_id, events + self._storage_controllers, user_id, events ) writer.write_events(room_id, events) @@ -235,7 +235,7 @@ async def export_user_data(self, user_id: str, writer: "ExfiltrationWriter") -> for event_id in extremities: if not event_to_unseen_prevs[event_id]: continue - state = await self.state_storage_controller.get_state_for_event( + state = await self._state_storage_controller.get_state_for_event( event_id ) writer.write_state(room_id, event_id, state) diff --git a/synapse/handlers/device.py b/synapse/handlers/device.py index fe73978bebd8..3b002c6072eb 100644 --- a/synapse/handlers/device.py +++ b/synapse/handlers/device.py @@ -70,7 +70,7 @@ def __init__(self, hs: "HomeServer"): self.store = hs.get_datastores().main self.notifier = hs.get_notifier() self.state = hs.get_state_handler() - self.state_storage = hs.get_storage_controllers().state + self._state_storage = hs.get_storage_controllers().state self._auth_handler = hs.get_auth_handler() self.server_name = hs.hostname @@ -203,7 +203,7 @@ async def get_user_ids_changed( continue # mapping from event_id -> state_dict - prev_state_ids = await self.state_storage.get_state_ids_for_events( + prev_state_ids = await self._state_storage.get_state_ids_for_events( event_ids ) diff --git a/synapse/handlers/events.py b/synapse/handlers/events.py index fa729bf4e617..e5410caf992e 100644 --- a/synapse/handlers/events.py +++ b/synapse/handlers/events.py @@ -139,7 +139,7 @@ async def get_stream( class EventHandler: def __init__(self, hs: "HomeServer"): self.store = hs.get_datastores().main - self.storage_controllers = hs.get_storage_controllers() + self._storage_controllers = hs.get_storage_controllers() async def get_event( self, @@ -177,7 +177,7 @@ async def get_event( is_peeking = user.to_string() not in users filtered = await filter_events_for_client( - self.storage_controllers, user.to_string(), [event], is_peeking=is_peeking + self._storage_controllers, user.to_string(), [event], is_peeking=is_peeking ) if not filtered: diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py index 42bec7e12740..80ee7e7b4e7c 100644 --- a/synapse/handlers/federation.py +++ b/synapse/handlers/federation.py @@ -125,8 +125,8 @@ def __init__(self, hs: "HomeServer"): self.hs = hs self.store = hs.get_datastores().main - self.storage_controllers = hs.get_storage_controllers() - self.state_storage_controller = self.storage_controllers.state + self._storage_controllers = hs.get_storage_controllers() + self._state_storage_controller = self._storage_controllers.state self.federation_client = hs.get_federation_client() self.state_handler = hs.get_state_handler() self.server_name = hs.hostname @@ -324,7 +324,7 @@ async def _maybe_backfill_inner( # We set `check_history_visibility_only` as we might otherwise get false # positives from users having been erased. filtered_extremities = await filter_events_for_server( - self.storage_controllers, + self._storage_controllers, self.server_name, events_to_check, redact=False, @@ -660,7 +660,7 @@ async def do_knock( # in the invitee's sync stream. It is stripped out for all other local users. event.unsigned["knock_room_state"] = stripped_room_state["knock_state_events"] - context = EventContext.for_outlier(self.storage_controllers) + context = EventContext.for_outlier(self._storage_controllers) stream_id = await self._federation_event_handler.persist_events_and_notify( event.room_id, [(event, context)] ) @@ -849,7 +849,7 @@ async def on_invite_request( ) ) - context = EventContext.for_outlier(self.storage_controllers) + context = EventContext.for_outlier(self._storage_controllers) await self._federation_event_handler.persist_events_and_notify( event.room_id, [(event, context)] ) @@ -878,7 +878,7 @@ async def do_remotely_reject_invite( await self.federation_client.send_leave(host_list, event) - context = EventContext.for_outlier(self.storage_controllers) + context = EventContext.for_outlier(self._storage_controllers) stream_id = await self._federation_event_handler.persist_events_and_notify( event.room_id, [(event, context)] ) @@ -1027,7 +1027,7 @@ async def get_state_ids_for_pdu(self, room_id: str, event_id: str) -> List[str]: if event.internal_metadata.outlier: raise NotFoundError("State not known at event %s" % (event_id,)) - state_groups = await self.state_storage_controller.get_state_groups_ids( + state_groups = await self._state_storage_controller.get_state_groups_ids( room_id, [event_id] ) @@ -1079,7 +1079,7 @@ async def on_backfill_request( ) events = await filter_events_for_server( - self.storage_controllers, origin, events + self._storage_controllers, origin, events ) return events @@ -1112,7 +1112,7 @@ async def get_persisted_pdu( raise AuthError(403, "Host not in room.") events = await filter_events_for_server( - self.storage_controllers, origin, [event] + self._storage_controllers, origin, [event] ) event = events[0] return event @@ -1142,7 +1142,7 @@ async def on_get_missing_events( ) missing_events = await filter_events_for_server( - self.storage_controllers, origin, missing_events + self._storage_controllers, origin, missing_events ) return missing_events @@ -1484,9 +1484,11 @@ async def _sync_partial_state_room( # clear the lazy-loading flag. logger.info("Updating current state for %s", room_id) assert ( - self.storage_controllers.persistence is not None + self._storage_controllers.persistence is not None ), "TODO(faster_joins): support for workers" - await self.storage_controllers.persistence.update_current_state(room_id) + await self._storage_controllers.persistence.update_current_state( + room_id + ) logger.info("Clearing partial-state flag for %s", room_id) success = await self.store.clear_partial_state_room(room_id) diff --git a/synapse/handlers/initial_sync.py b/synapse/handlers/initial_sync.py index 876bdfc7ae39..d78802b34d69 100644 --- a/synapse/handlers/initial_sync.py +++ b/synapse/handlers/initial_sync.py @@ -67,8 +67,8 @@ def __init__(self, hs: "HomeServer"): ] ] = ResponseCache(hs.get_clock(), "initial_sync_cache") self._event_serializer = hs.get_event_client_serializer() - self.storage_controllers = hs.get_storage_controllers() - self.state_storage_controller = self.storage_controllers.state + self._storage_controllers = hs.get_storage_controllers() + self._state_storage_controller = self._storage_controllers.state async def snapshot_all_rooms( self, @@ -198,7 +198,7 @@ async def handle_room(event: RoomsForUser) -> None: event.stream_ordering, ) deferred_room_state = run_in_background( - self.state_storage_controller.get_state_for_events, + self._state_storage_controller.get_state_for_events, [event.event_id], ).addCallback( lambda states: cast(StateMap[EventBase], states[event.event_id]) @@ -219,7 +219,7 @@ async def handle_room(event: RoomsForUser) -> None: ).addErrback(unwrapFirstError) messages = await filter_events_for_client( - self.storage_controllers, user_id, messages + self._storage_controllers, user_id, messages ) start_token = now_token.copy_and_replace(StreamKeyType.ROOM, token) @@ -356,7 +356,7 @@ async def _room_initial_sync_parted( member_event_id: str, is_peeking: bool, ) -> JsonDict: - room_state = await self.state_storage_controller.get_state_for_event( + room_state = await self._state_storage_controller.get_state_for_event( member_event_id ) @@ -372,7 +372,7 @@ async def _room_initial_sync_parted( ) messages = await filter_events_for_client( - self.storage_controllers, user_id, messages, is_peeking=is_peeking + self._storage_controllers, user_id, messages, is_peeking=is_peeking ) start_token = StreamToken.START.copy_and_replace(StreamKeyType.ROOM, token) @@ -477,7 +477,7 @@ async def get_receipts() -> List[JsonDict]: ) messages = await filter_events_for_client( - self.storage_controllers, user_id, messages, is_peeking=is_peeking + self._storage_controllers, user_id, messages, is_peeking=is_peeking ) start_token = now_token.copy_and_replace(StreamKeyType.ROOM, token) diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index a78f6cd3d995..bdcd1818774c 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -84,8 +84,8 @@ def __init__(self, hs: "HomeServer"): self.clock = hs.get_clock() self.state = hs.get_state_handler() self.store = hs.get_datastores().main - self.storage_controllers = hs.get_storage_controllers() - self.state_storage_controller = self.storage_controllers.state + self._storage_controllers = hs.get_storage_controllers() + self._state_storage_controller = self._storage_controllers.state self._event_serializer = hs.get_event_client_serializer() self._ephemeral_events_enabled = hs.config.server.enable_ephemeral_messages @@ -132,7 +132,7 @@ async def get_room_data( assert ( membership_event_id is not None ), "check_user_in_room_or_world_readable returned invalid data" - room_state = await self.state_storage_controller.get_state_for_events( + room_state = await self._state_storage_controller.get_state_for_events( [membership_event_id], StateFilter.from_types([key]) ) data = room_state[membership_event_id].get(key) @@ -193,7 +193,7 @@ async def get_state_events( # check whether the user is in the room at that time to determine # whether they should be treated as peeking. - state_map = await self.state_storage_controller.get_state_for_event( + state_map = await self._state_storage_controller.get_state_for_event( last_event.event_id, StateFilter.from_types([(EventTypes.Member, user_id)]), ) @@ -206,7 +206,7 @@ async def get_state_events( is_peeking = not joined visible_events = await filter_events_for_client( - self.storage_controllers, + self._storage_controllers, user_id, [last_event], filter_send_to_client=False, @@ -215,7 +215,7 @@ async def get_state_events( if visible_events: room_state_events = ( - await self.state_storage_controller.get_state_for_events( + await self._state_storage_controller.get_state_for_events( [last_event.event_id], state_filter=state_filter ) ) @@ -247,7 +247,7 @@ async def get_state_events( membership_event_id is not None ), "check_user_in_room_or_world_readable returned invalid data" room_state_events = ( - await self.state_storage_controller.get_state_for_events( + await self._state_storage_controller.get_state_for_events( [membership_event_id], state_filter=state_filter ) ) @@ -406,7 +406,7 @@ def __init__(self, hs: "HomeServer"): self.auth = hs.get_auth() self._event_auth_handler = hs.get_event_auth_handler() self.store = hs.get_datastores().main - self.storage_controllers = hs.get_storage_controllers() + self._storage_controllers = hs.get_storage_controllers() self.state = hs.get_state_handler() self.clock = hs.get_clock() self.validator = EventValidator() @@ -1021,7 +1021,7 @@ async def create_new_client_event( # after it is created if builder.internal_metadata.outlier: event.internal_metadata.outlier = True - context = EventContext.for_outlier(self.storage_controllers) + context = EventContext.for_outlier(self._storage_controllers) elif ( event.type == EventTypes.MSC2716_INSERTION and state_event_ids @@ -1434,7 +1434,7 @@ async def persist_and_notify_client_event( """ extra_users = extra_users or [] - assert self.storage_controllers.persistence is not None + assert self._storage_controllers.persistence is not None assert self._events_shard_config.should_handle( self._instance_name, event.room_id ) @@ -1668,7 +1668,7 @@ async def persist_and_notify_client_event( event, event_pos, max_stream_token, - ) = await self.storage_controllers.persistence.persist_event( + ) = await self._storage_controllers.persistence.persist_event( event, context=context, backfilled=backfilled ) diff --git a/synapse/handlers/pagination.py b/synapse/handlers/pagination.py index c4d0b2d3e237..acabee62ec38 100644 --- a/synapse/handlers/pagination.py +++ b/synapse/handlers/pagination.py @@ -129,8 +129,8 @@ def __init__(self, hs: "HomeServer"): self.hs = hs self.auth = hs.get_auth() self.store = hs.get_datastores().main - self.storage_controllers = hs.get_storage_controllers() - self.state_storage_controller = self.storage_controllers.state + self._storage_controllers = hs.get_storage_controllers() + self._state_storage_controller = self._storage_controllers.state self.clock = hs.get_clock() self._server_name = hs.hostname self._room_shutdown_handler = hs.get_room_shutdown_handler() @@ -352,7 +352,7 @@ async def _purge_history( self._purges_in_progress_by_room.add(room_id) try: async with self.pagination_lock.write(room_id): - await self.storage_controllers.purge_events.purge_history( + await self._storage_controllers.purge_events.purge_history( room_id, token, delete_local_events ) logger.info("[purge] complete") @@ -414,7 +414,7 @@ async def purge_room(self, room_id: str, force: bool = False) -> None: if joined: raise SynapseError(400, "Users are still joined to this room") - await self.storage_controllers.purge_events.purge_room(room_id) + await self._storage_controllers.purge_events.purge_room(room_id) async def get_messages( self, @@ -520,7 +520,7 @@ async def get_messages( events = await event_filter.filter(events) events = await filter_events_for_client( - self.storage_controllers, + self._storage_controllers, user_id, events, is_peeking=(member_event_id is None), @@ -542,7 +542,7 @@ async def get_messages( (EventTypes.Member, event.sender) for event in events ) - state_ids = await self.state_storage_controller.get_state_ids_for_event( + state_ids = await self._state_storage_controller.get_state_ids_for_event( events[0].event_id, state_filter=state_filter ) @@ -656,7 +656,7 @@ async def _shutdown_and_purge_room( 400, "Users are still joined to this room" ) - await self.storage_controllers.purge_events.purge_room(room_id) + await self._storage_controllers.purge_events.purge_room(room_id) logger.info("complete") self._delete_by_id[delete_id].status = DeleteStatus.STATUS_COMPLETE diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index 6fd4af932a0b..5c91d33f583f 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -1192,8 +1192,8 @@ def __init__(self, hs: "HomeServer"): self.hs = hs self.auth = hs.get_auth() self.store = hs.get_datastores().main - self.storage_controllers = hs.get_storage_controllers() - self.state_storage_controller = self.storage_controllers.state + self._storage_controllers = hs.get_storage_controllers() + self._state_storage_controller = self._storage_controllers.state self._relations_handler = hs.get_relations_handler() async def get_event_context( @@ -1236,7 +1236,7 @@ async def filter_evts(events: List[EventBase]) -> List[EventBase]: if use_admin_priviledge: return events return await filter_events_for_client( - self.storage_controllers, + self._storage_controllers, user.to_string(), events, is_peeking=is_peeking, @@ -1296,7 +1296,7 @@ async def filter_evts(events: List[EventBase]) -> List[EventBase]: # first? Shouldn't we be consistent with /sync? # https://github.com/matrix-org/matrix-doc/issues/687 - state = await self.state_storage_controller.get_state_for_events( + state = await self._state_storage_controller.get_state_for_events( [last_event_id], state_filter=state_filter ) diff --git a/synapse/handlers/room_batch.py b/synapse/handlers/room_batch.py index d65126248e0c..1414e575d6fc 100644 --- a/synapse/handlers/room_batch.py +++ b/synapse/handlers/room_batch.py @@ -17,7 +17,7 @@ class RoomBatchHandler: def __init__(self, hs: "HomeServer"): self.hs = hs self.store = hs.get_datastores().main - self.state_storage_controller = hs.get_storage_controllers().state + self._state_storage_controller = hs.get_storage_controllers().state self.event_creation_handler = hs.get_event_creation_handler() self.room_member_handler = hs.get_room_member_handler() self.auth = hs.get_auth() @@ -141,7 +141,7 @@ async def get_most_recent_full_state_ids_from_event_id_list( ) = await self.store.get_max_depth_of(event_ids) # mapping from (type, state_key) -> state_event_id assert most_recent_event_id is not None - prev_state_map = await self.state_storage_controller.get_state_ids_for_event( + prev_state_map = await self._state_storage_controller.get_state_ids_for_event( most_recent_event_id ) # List of state event ID's diff --git a/synapse/handlers/search.py b/synapse/handlers/search.py index 40a7e18586fe..659f99f7e2a2 100644 --- a/synapse/handlers/search.py +++ b/synapse/handlers/search.py @@ -55,8 +55,8 @@ def __init__(self, hs: "HomeServer"): self.hs = hs self._event_serializer = hs.get_event_client_serializer() self._relations_handler = hs.get_relations_handler() - self.storage_controllers = hs.get_storage_controllers() - self.state_storage_controller = self.storage_controllers.state + self._storage_controllers = hs.get_storage_controllers() + self._state_storage_controller = self._storage_controllers.state self.auth = hs.get_auth() async def get_old_rooms_from_upgraded_room(self, room_id: str) -> Iterable[str]: @@ -460,7 +460,7 @@ async def _search_by_rank( filtered_events = await search_filter.filter([r["event"] for r in results]) events = await filter_events_for_client( - self.storage_controllers, user.to_string(), filtered_events + self._storage_controllers, user.to_string(), filtered_events ) events.sort(key=lambda e: -rank_map[e.event_id]) @@ -559,7 +559,7 @@ async def _search_by_recent( filtered_events = await search_filter.filter([r["event"] for r in results]) events = await filter_events_for_client( - self.storage_controllers, user.to_string(), filtered_events + self._storage_controllers, user.to_string(), filtered_events ) room_events.extend(events) @@ -644,11 +644,11 @@ async def _calculate_event_contexts( ) events_before = await filter_events_for_client( - self.storage_controllers, user.to_string(), res.events_before + self._storage_controllers, user.to_string(), res.events_before ) events_after = await filter_events_for_client( - self.storage_controllers, user.to_string(), res.events_after + self._storage_controllers, user.to_string(), res.events_after ) context: JsonDict = { @@ -677,7 +677,7 @@ async def _calculate_event_contexts( [(EventTypes.Member, sender) for sender in senders] ) - state = await self.state_storage_controller.get_state_for_event( + state = await self._state_storage_controller.get_state_for_event( last_event_id, state_filter ) diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py index 048b3d06bf36..b5859dcb28ca 100644 --- a/synapse/handlers/sync.py +++ b/synapse/handlers/sync.py @@ -238,8 +238,8 @@ def __init__(self, hs: "HomeServer"): self.clock = hs.get_clock() self.state = hs.get_state_handler() self.auth = hs.get_auth() - self.storage_controllers = hs.get_storage_controllers() - self.state_storage_controller = self.storage_controllers.state + self._storage_controllers = hs.get_storage_controllers() + self._state_storage_controller = self._storage_controllers.state # TODO: flush cache entries on subsequent sync request. # Once we get the next /sync request (ie, one with the same access token @@ -512,7 +512,7 @@ async def _load_filtered_recents( current_state_ids = frozenset(current_state_ids_map.values()) recents = await filter_events_for_client( - self.storage_controllers, + self._storage_controllers, sync_config.user.to_string(), recents, always_include_ids=current_state_ids, @@ -580,7 +580,7 @@ async def _load_filtered_recents( current_state_ids = frozenset(current_state_ids_map.values()) loaded_recents = await filter_events_for_client( - self.storage_controllers, + self._storage_controllers, sync_config.user.to_string(), loaded_recents, always_include_ids=current_state_ids, @@ -630,7 +630,7 @@ async def get_state_after_event( event: event of interest state_filter: The state filter used to fetch state from the database. """ - state_ids = await self.state_storage_controller.get_state_ids_for_event( + state_ids = await self._state_storage_controller.get_state_ids_for_event( event.event_id, state_filter=state_filter or StateFilter.all() ) if event.is_state(): @@ -710,7 +710,7 @@ async def compute_summary( return None last_event = last_events[-1] - state_ids = await self.state_storage_controller.get_state_ids_for_event( + state_ids = await self._state_storage_controller.get_state_ids_for_event( last_event.event_id, state_filter=StateFilter.from_types( [(EventTypes.Name, ""), (EventTypes.CanonicalAlias, "")] @@ -889,13 +889,13 @@ async def compute_state_delta( if full_state: if batch: current_state_ids = ( - await self.state_storage_controller.get_state_ids_for_event( + await self._state_storage_controller.get_state_ids_for_event( batch.events[-1].event_id, state_filter=state_filter ) ) state_ids = ( - await self.state_storage_controller.get_state_ids_for_event( + await self._state_storage_controller.get_state_ids_for_event( batch.events[0].event_id, state_filter=state_filter ) ) @@ -917,7 +917,7 @@ async def compute_state_delta( elif batch.limited: if batch: state_at_timeline_start = ( - await self.state_storage_controller.get_state_ids_for_event( + await self._state_storage_controller.get_state_ids_for_event( batch.events[0].event_id, state_filter=state_filter ) ) @@ -952,7 +952,7 @@ async def compute_state_delta( if batch: current_state_ids = ( - await self.state_storage_controller.get_state_ids_for_event( + await self._state_storage_controller.get_state_ids_for_event( batch.events[-1].event_id, state_filter=state_filter ) ) @@ -984,7 +984,7 @@ async def compute_state_delta( # So we fish out all the member events corresponding to the # timeline here, and then dedupe any redundant ones below. - state_ids = await self.state_storage_controller.get_state_ids_for_event( + state_ids = await self._state_storage_controller.get_state_ids_for_event( batch.events[0].event_id, # we only want members! state_filter=StateFilter.from_types( diff --git a/synapse/notifier.py b/synapse/notifier.py index ed3a4d58fa86..25c70802e17f 100644 --- a/synapse/notifier.py +++ b/synapse/notifier.py @@ -221,7 +221,7 @@ def __init__(self, hs: "HomeServer"): self.room_to_user_streams: Dict[str, Set[_NotifierUserStream]] = {} self.hs = hs - self.storage_controllers = hs.get_storage_controllers() + self._storage_controllers = hs.get_storage_controllers() self.event_sources = hs.get_event_sources() self.store = hs.get_datastores().main self.pending_new_room_events: List[_PendingRoomEventEntry] = [] @@ -623,7 +623,7 @@ async def check_for_updates( if name == "room": new_events = await filter_events_for_client( - self.storage_controllers, + self._storage_controllers, user.to_string(), new_events, is_peeking=is_peeking, diff --git a/synapse/push/httppusher.py b/synapse/push/httppusher.py index c437bd808fa9..e96fb45e9f55 100644 --- a/synapse/push/httppusher.py +++ b/synapse/push/httppusher.py @@ -65,7 +65,7 @@ class HttpPusher(Pusher): def __init__(self, hs: "HomeServer", pusher_config: PusherConfig): super().__init__(hs, pusher_config) - self.storage_controllers = self.hs.get_storage_controllers() + self._storage_controllers = self.hs.get_storage_controllers() self.app_display_name = pusher_config.app_display_name self.device_display_name = pusher_config.device_display_name self.pushkey_ts = pusher_config.ts @@ -344,7 +344,7 @@ async def _build_notification_dict( return d ctx = await push_tools.get_context_for_event( - self.storage_controllers, event, self.user_id + self._storage_controllers, event, self.user_id ) d = { diff --git a/synapse/push/mailer.py b/synapse/push/mailer.py index cb9a8f2c1337..63aefd07f55c 100644 --- a/synapse/push/mailer.py +++ b/synapse/push/mailer.py @@ -114,10 +114,10 @@ def __init__( self.send_email_handler = hs.get_send_email_handler() self.store = self.hs.get_datastores().main - self.state_storage_controller = self.hs.get_storage_controllers().state + self._state_storage_controller = self.hs.get_storage_controllers().state self.macaroon_gen = self.hs.get_macaroon_generator() self.state_handler = self.hs.get_state_handler() - self.storage_controllers = hs.get_storage_controllers() + self._storage_controllers = hs.get_storage_controllers() self.app_name = app_name self.email_subjects: EmailSubjectConfig = hs.config.email.email_subjects @@ -456,7 +456,7 @@ async def _get_notif_vars( } the_events = await filter_events_for_client( - self.storage_controllers, user_id, results.events_before + self._storage_controllers, user_id, results.events_before ) the_events.append(notif_event) @@ -494,7 +494,7 @@ async def _get_message_vars( ) else: # Attempt to check the historical state for the room. - historical_state = await self.state_storage_controller.get_state_for_event( + historical_state = await self._state_storage_controller.get_state_for_event( event.event_id, StateFilter.from_types((type_state_key,)) ) sender_state_event = historical_state.get(type_state_key) @@ -768,7 +768,7 @@ async def _make_summary_text_from_member_events( else: # Attempt to check the historical state for the room. historical_state = ( - await self.state_storage_controller.get_state_for_event( + await self._state_storage_controller.get_state_for_event( event_id, StateFilter.from_types((type_state_key,)) ) ) diff --git a/synapse/replication/http/federation.py b/synapse/replication/http/federation.py index 2d2d06bcf7d6..eed29cd59739 100644 --- a/synapse/replication/http/federation.py +++ b/synapse/replication/http/federation.py @@ -69,7 +69,7 @@ def __init__(self, hs: "HomeServer"): super().__init__(hs) self.store = hs.get_datastores().main - self.storage_controllers = hs.get_storage_controllers() + self._storage_controllers = hs.get_storage_controllers() self.clock = hs.get_clock() self.federation_event_handler = hs.get_federation_event_handler() @@ -133,7 +133,7 @@ async def _handle_request(self, request: Request) -> Tuple[int, JsonDict]: # ty event.internal_metadata.outlier = event_payload["outlier"] context = EventContext.deserialize( - self.storage_controllers, event_payload["context"] + self._storage_controllers, event_payload["context"] ) event_and_contexts.append((event, context)) diff --git a/synapse/replication/http/send_event.py b/synapse/replication/http/send_event.py index aacabfac4a7e..c2b2588ea548 100644 --- a/synapse/replication/http/send_event.py +++ b/synapse/replication/http/send_event.py @@ -70,7 +70,7 @@ def __init__(self, hs: "HomeServer"): self.event_creation_handler = hs.get_event_creation_handler() self.store = hs.get_datastores().main - self.storage_controllers = hs.get_storage_controllers() + self._storage_controllers = hs.get_storage_controllers() self.clock = hs.get_clock() @staticmethod @@ -128,7 +128,7 @@ async def _handle_request( # type: ignore[override] requester = Requester.deserialize(self.store, content["requester"]) context = EventContext.deserialize( - self.storage_controllers, content["context"] + self._storage_controllers, content["context"] ) ratelimit = content["ratelimit"] diff --git a/tests/events/test_snapshot.py b/tests/events/test_snapshot.py index 2cf3f1a4c9c3..8ddce83b830d 100644 --- a/tests/events/test_snapshot.py +++ b/tests/events/test_snapshot.py @@ -29,7 +29,7 @@ class TestEventContext(unittest.HomeserverTestCase): def prepare(self, reactor, clock, hs): self.store = hs.get_datastores().main - self.storage = hs.get_storage_controllers() + self._storage_controllers = hs.get_storage_controllers() self.user_id = self.register_user("u1", "pass") self.user_tok = self.login("u1", "pass") @@ -87,7 +87,7 @@ def test_serialize_deserialize_state_prev(self): def _check_serialize_deserialize(self, event, context): serialized = self.get_success(context.serialize(event, self.store)) - d_context = EventContext.deserialize(self.storage, serialized) + d_context = EventContext.deserialize(self._storage_controllers, serialized) self.assertEqual(context.state_group, d_context.state_group) self.assertEqual(context.rejected, d_context.rejected) diff --git a/tests/handlers/test_message.py b/tests/handlers/test_message.py index b5779c485f83..44da96c792fe 100644 --- a/tests/handlers/test_message.py +++ b/tests/handlers/test_message.py @@ -37,7 +37,7 @@ class EventCreationTestCase(unittest.HomeserverTestCase): def prepare(self, reactor, clock, hs): self.handler = self.hs.get_event_creation_handler() - self.persist_event_storage_controller = ( + self._persist_event_storage_controller = ( self.hs.get_storage_controllers().persistence ) @@ -67,7 +67,7 @@ def _create_and_persist_member_event(self) -> Tuple[EventBase, EventContext]: ) ) self.get_success( - self.persist_event_storage_controller.persist_event( + self._persist_event_storage_controller.persist_event( memberEvent, memberEventContext ) ) @@ -133,7 +133,7 @@ def test_duplicated_txn_id(self): self.assertNotEqual(event1.event_id, event3.event_id) ret_event3, event_pos3, _ = self.get_success( - self.persist_event_storage_controller.persist_event(event3, context) + self._persist_event_storage_controller.persist_event(event3, context) ) # Assert that the returned values match those from the initial event @@ -147,7 +147,7 @@ def test_duplicated_txn_id(self): self.assertNotEqual(event1.event_id, event3.event_id) events, _ = self.get_success( - self.persist_event_storage_controller.persist_events([(event3, context)]) + self._persist_event_storage_controller.persist_events([(event3, context)]) ) ret_event4 = events[0] @@ -170,7 +170,7 @@ def test_duplicated_txn_id_one_call(self): self.assertNotEqual(event1.event_id, event2.event_id) events, _ = self.get_success( - self.persist_event_storage_controller.persist_events( + self._persist_event_storage_controller.persist_events( [(event1, context1), (event2, context2)] ) ) diff --git a/tests/replication/slave/storage/_base.py b/tests/replication/slave/storage/_base.py index 9b41d9309122..c5705256e6fa 100644 --- a/tests/replication/slave/storage/_base.py +++ b/tests/replication/slave/storage/_base.py @@ -32,7 +32,7 @@ def prepare(self, reactor, clock, hs): self.master_store = hs.get_datastores().main self.slaved_store = self.worker_hs.get_datastores().main - self.storage = hs.get_storage_controllers() + self._storage_controllers = hs.get_storage_controllers() def replicate(self): """Tell the master side of replication that something has happened, and then diff --git a/tests/replication/slave/storage/test_events.py b/tests/replication/slave/storage/test_events.py index 297a9e77f8c3..6d3d4afe52c7 100644 --- a/tests/replication/slave/storage/test_events.py +++ b/tests/replication/slave/storage/test_events.py @@ -262,7 +262,9 @@ def test_get_rooms_for_user_with_stream_ordering_with_multi_event_persist(self): ) msg, msgctx = self.build_event() self.get_success( - self.storage.persistence.persist_events([(j2, j2ctx), (msg, msgctx)]) + self._storage_controllers.persistence.persist_events( + [(j2, j2ctx), (msg, msgctx)] + ) ) self.replicate() @@ -323,12 +325,14 @@ def persist(self, backfill=False, **kwargs): if backfill: self.get_success( - self.storage.persistence.persist_events( + self._storage_controllers.persistence.persist_events( [(event, context)], backfilled=True ) ) else: - self.get_success(self.storage.persistence.persist_event(event, context)) + self.get_success( + self._storage_controllers.persistence.persist_event(event, context) + ) return event diff --git a/tests/rest/client/test_room_batch.py b/tests/rest/client/test_room_batch.py index 20010e028350..1b7ee08ab2c0 100644 --- a/tests/rest/client/test_room_batch.py +++ b/tests/rest/client/test_room_batch.py @@ -88,7 +88,7 @@ def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer: def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None: self.clock = clock - self.storage_controllers = hs.get_storage_controllers() + self._storage_controllers = hs.get_storage_controllers() self.virtual_user_id, _ = self.register_appservice_user( "as_user_potato", self.appservice.token @@ -168,7 +168,7 @@ def test_same_state_groups_for_whole_historical_batch(self) -> None: # Fetch the state_groups state_group_map = self.get_success( - self.storage_controllers.state.get_state_groups_ids( + self._storage_controllers.state.get_state_groups_ids( room_id, historical_event_ids ) ) diff --git a/tests/storage/test_events.py b/tests/storage/test_events.py index 27b20b6b048e..a76718e8f995 100644 --- a/tests/storage/test_events.py +++ b/tests/storage/test_events.py @@ -31,7 +31,7 @@ class ExtremPruneTestCase(HomeserverTestCase): def prepare(self, reactor, clock, homeserver): self.state = self.hs.get_state_handler() - self.persistence = self.hs.get_storage_controllers().persistence + self._persistence = self.hs.get_storage_controllers().persistence self.store = self.hs.get_datastores().main self.register_user("user", "pass") @@ -71,7 +71,7 @@ def persist_event(self, event, state=None): context = self.get_success( self.state.compute_event_context(event, state_ids_before_event=state) ) - self.get_success(self.persistence.persist_event(event, context)) + self.get_success(self._persistence.persist_event(event, context)) def assert_extremities(self, expected_extremities): """Assert the current extremities for the room""" @@ -148,7 +148,7 @@ def test_do_not_prune_gap_if_state_different(self): ) ) - self.get_success(self.persistence.persist_event(remote_event_2, context)) + self.get_success(self._persistence.persist_event(remote_event_2, context)) # Check that we haven't dropped the old extremity. self.assert_extremities([self.remote_event_1.event_id, remote_event_2.event_id]) @@ -353,7 +353,7 @@ class InvalideUsersInRoomCacheTestCase(HomeserverTestCase): def prepare(self, reactor, clock, homeserver): self.state = self.hs.get_state_handler() - self.persistence = self.hs.get_storage_controllers().persistence + self._persistence = self.hs.get_storage_controllers().persistence self.store = self.hs.get_datastores().main def test_remote_user_rooms_cache_invalidated(self): @@ -390,7 +390,7 @@ def test_remote_user_rooms_cache_invalidated(self): ) context = self.get_success(self.state.compute_event_context(remote_event_1)) - self.get_success(self.persistence.persist_event(remote_event_1, context)) + self.get_success(self._persistence.persist_event(remote_event_1, context)) # Call `get_rooms_for_user` to add the remote user to the cache rooms = self.get_success(self.store.get_rooms_for_user(remote_user)) @@ -437,7 +437,7 @@ def test_room_remote_user_cache_invalidated(self): ) context = self.get_success(self.state.compute_event_context(remote_event_1)) - self.get_success(self.persistence.persist_event(remote_event_1, context)) + self.get_success(self._persistence.persist_event(remote_event_1, context)) # Call `get_users_in_room` to add the remote user to the cache users = self.get_success(self.store.get_users_in_room(room_id)) diff --git a/tests/storage/test_purge.py b/tests/storage/test_purge.py index 78c8744e3b0f..92cd0dfc0557 100644 --- a/tests/storage/test_purge.py +++ b/tests/storage/test_purge.py @@ -31,7 +31,7 @@ def prepare(self, reactor, clock, hs): self.room_id = self.helper.create_room_as(self.user_id) self.store = hs.get_datastores().main - self.storage_controllers = self.hs.get_storage_controllers() + self._storage_controllers = self.hs.get_storage_controllers() def test_purge_history(self): """ @@ -51,7 +51,7 @@ def test_purge_history(self): # Purge everything before this topological token self.get_success( - self.storage_controllers.purge_events.purge_history( + self._storage_controllers.purge_events.purge_history( self.room_id, token_str, True ) ) @@ -81,7 +81,7 @@ def test_purge_history_wont_delete_extrems(self): # Purge everything before this topological token f = self.get_failure( - self.storage_controllers.purge_events.purge_history( + self._storage_controllers.purge_events.purge_history( self.room_id, event, True ), SynapseError, @@ -109,7 +109,9 @@ def test_purge_room(self): self.assertIsNotNone(create_event) # Purge everything before this topological token - self.get_success(self.storage_controllers.purge_events.purge_room(self.room_id)) + self.get_success( + self._storage_controllers.purge_events.purge_room(self.room_id) + ) # The events aren't found. self.store._invalidate_get_event_cache(create_event.event_id) diff --git a/tests/storage/test_redaction.py b/tests/storage/test_redaction.py index 8e737332fc06..6c4e63b77cac 100644 --- a/tests/storage/test_redaction.py +++ b/tests/storage/test_redaction.py @@ -31,7 +31,7 @@ def default_config(self): def prepare(self, reactor, clock, hs): self.store = hs.get_datastores().main - self.storage = hs.get_storage_controllers() + self._storage = hs.get_storage_controllers() self.event_builder_factory = hs.get_event_builder_factory() self.event_creation_handler = hs.get_event_creation_handler() @@ -71,7 +71,7 @@ def inject_room_member( self.event_creation_handler.create_new_client_event(builder) ) - self.get_success(self.storage.persistence.persist_event(event, context)) + self.get_success(self._storage.persistence.persist_event(event, context)) return event @@ -93,7 +93,7 @@ def inject_message(self, room, user, body): self.event_creation_handler.create_new_client_event(builder) ) - self.get_success(self.storage.persistence.persist_event(event, context)) + self.get_success(self._storage.persistence.persist_event(event, context)) return event @@ -114,7 +114,7 @@ def inject_redaction(self, room, event_id, user, reason): self.event_creation_handler.create_new_client_event(builder) ) - self.get_success(self.storage.persistence.persist_event(event, context)) + self.get_success(self._storage.persistence.persist_event(event, context)) return event @@ -268,7 +268,7 @@ def internal_metadata(self): ) ) - self.get_success(self.storage.persistence.persist_event(event_1, context_1)) + self.get_success(self._storage.persistence.persist_event(event_1, context_1)) event_2, context_2 = self.get_success( self.event_creation_handler.create_new_client_event( @@ -287,7 +287,7 @@ def internal_metadata(self): ) ) ) - self.get_success(self.storage.persistence.persist_event(event_2, context_2)) + self.get_success(self._storage.persistence.persist_event(event_2, context_2)) # fetch one of the redactions fetched = self.get_success(self.store.get_event(redaction_event_id1)) @@ -411,7 +411,7 @@ def test_store_redacted_redaction(self): ) self.get_success( - self.storage.persistence.persist_event(redaction_event, context) + self._storage.persistence.persist_event(redaction_event, context) ) # Now lets jump to the future where we have censored the redaction event diff --git a/tests/storage/test_room.py b/tests/storage/test_room.py index fec81a9f712b..d497a19f6336 100644 --- a/tests/storage/test_room.py +++ b/tests/storage/test_room.py @@ -72,7 +72,7 @@ def prepare(self, reactor, clock, hs): # Room events need the full datastore, for persist_event() and # get_room_state() self.store = hs.get_datastores().main - self.storage = hs.get_storage_controllers() + self._storage = hs.get_storage_controllers() self.event_factory = hs.get_event_factory() self.room = RoomID.from_string("!abcde:test") @@ -88,7 +88,7 @@ def prepare(self, reactor, clock, hs): def inject_room_event(self, **kwargs): self.get_success( - self.storage.persistence.persist_event( + self._storage.persistence.persist_event( self.event_factory.create_event(room_id=self.room.to_string(), **kwargs) ) ) diff --git a/tests/test_visibility.py b/tests/test_visibility.py index 380a1839a11b..f338af6c36d0 100644 --- a/tests/test_visibility.py +++ b/tests/test_visibility.py @@ -34,7 +34,7 @@ def setUp(self) -> None: super(FilterEventsForServerTestCase, self).setUp() self.event_creation_handler = self.hs.get_event_creation_handler() self.event_builder_factory = self.hs.get_event_builder_factory() - self.storage_controllers = self.hs.get_storage_controllers() + self._storage_controllers = self.hs.get_storage_controllers() self.get_success(create_room(self.hs, TEST_ROOM_ID, "@someone:ROOM")) @@ -61,7 +61,7 @@ def test_filtering(self) -> None: filtered = self.get_success( filter_events_for_server( - self.storage_controllers, "test_server", events_to_filter + self._storage_controllers, "test_server", events_to_filter ) ) @@ -83,7 +83,7 @@ def test_filter_outlier(self) -> None: self.assertEqual( self.get_success( filter_events_for_server( - self.storage_controllers, "remote_hs", [outlier] + self._storage_controllers, "remote_hs", [outlier] ) ), [outlier], @@ -94,7 +94,7 @@ def test_filter_outlier(self) -> None: filtered = self.get_success( filter_events_for_server( - self.storage_controllers, "remote_hs", [outlier, evt] + self._storage_controllers, "remote_hs", [outlier, evt] ) ) self.assertEqual(len(filtered), 2, f"expected 2 results, got: {filtered}") @@ -106,7 +106,7 @@ def test_filter_outlier(self) -> None: # be redacted) filtered = self.get_success( filter_events_for_server( - self.storage_controllers, "other_server", [outlier, evt] + self._storage_controllers, "other_server", [outlier, evt] ) ) self.assertEqual(filtered[0], outlier) @@ -141,7 +141,7 @@ def test_erased_user(self) -> None: # ... and the filtering happens. filtered = self.get_success( filter_events_for_server( - self.storage_controllers, "test_server", events_to_filter + self._storage_controllers, "test_server", events_to_filter ) ) @@ -179,7 +179,7 @@ def _inject_visibility(self, user_id: str, visibility: str) -> EventBase: self.event_creation_handler.create_new_client_event(builder) ) self.get_success( - self.storage_controllers.persistence.persist_event(event, context) + self._storage_controllers.persistence.persist_event(event, context) ) return event @@ -207,7 +207,7 @@ def _inject_room_member( ) self.get_success( - self.storage_controllers.persistence.persist_event(event, context) + self._storage_controllers.persistence.persist_event(event, context) ) return event @@ -231,7 +231,7 @@ def _inject_message( ) self.get_success( - self.storage_controllers.persistence.persist_event(event, context) + self._storage_controllers.persistence.persist_event(event, context) ) return event @@ -250,8 +250,8 @@ def _inject_outlier(self) -> EventBase: event = self.get_success(builder.build(prev_event_ids=[], auth_event_ids=[])) event.internal_metadata.outlier = True self.get_success( - self.storage_controllers.persistence.persist_event( - event, EventContext.for_outlier(self.storage_controllers) + self._storage_controllers.persistence.persist_event( + event, EventContext.for_outlier(self._storage_controllers) ) ) return event