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

Commit 2359ee3

Browse files
authored
Remove redundant get_current_events_token (#11643)
* Push `get_room_{min,max_stream_ordering}` into StreamStore Both implementations of this are identical, so we may as well push it down and get rid of the abstract base class nonsense. * Remove redundant `StreamStore` class This is empty now * Remove redundant `get_current_events_token` This was an exact duplicate of `get_room_max_stream_ordering`, so let's get rid of it. * newsfile
1 parent bd9821f commit 2359ee3

File tree

7 files changed

+20
-36
lines changed

7 files changed

+20
-36
lines changed

changelog.d/11643.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove redundant `get_current_events_token` method.

synapse/handlers/federation_event.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1838,7 +1838,7 @@ async def persist_events_and_notify(
18381838
The stream ID after which all events have been persisted.
18391839
"""
18401840
if not event_and_contexts:
1841-
return self._store.get_current_events_token()
1841+
return self._store.get_room_max_stream_ordering()
18421842

18431843
instance = self._config.worker.events_shard_config.get_instance(room_id)
18441844
if instance != self._instance_name:

synapse/handlers/presence.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ def run_persister() -> Awaitable[None]:
729729

730730
# Presence is best effort and quickly heals itself, so lets just always
731731
# stream from the current state when we restart.
732-
self._event_pos = self.store.get_current_events_token()
732+
self._event_pos = self.store.get_room_max_stream_ordering()
733733
self._event_processing = False
734734

735735
async def _on_shutdown(self) -> None:

synapse/replication/slave/storage/events.py

-9
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,3 @@ def __init__(
8080
min_curr_state_delta_id,
8181
prefilled_cache=curr_state_delta_prefill,
8282
)
83-
84-
# Cached functions can't be accessed through a class instance so we need
85-
# to reach inside the __dict__ to extract them.
86-
87-
def get_room_max_stream_ordering(self):
88-
return self._stream_id_gen.get_current_token()
89-
90-
def get_room_min_stream_ordering(self):
91-
return self._backfill_id_gen.get_current_token()

synapse/storage/databases/main/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
from .signatures import SignatureStore
6969
from .state import StateStore
7070
from .stats import StatsStore
71-
from .stream import StreamStore
71+
from .stream import StreamWorkerStore
7272
from .tags import TagsStore
7373
from .transactions import TransactionWorkerStore
7474
from .ui_auth import UIAuthStore
@@ -87,7 +87,7 @@ class DataStore(
8787
RoomStore,
8888
RoomBatchStore,
8989
RegistrationStore,
90-
StreamStore,
90+
StreamWorkerStore,
9191
ProfileStore,
9292
PresenceStore,
9393
TransactionWorkerStore,

synapse/storage/databases/main/events_worker.py

-4
Original file line numberDiff line numberDiff line change
@@ -1383,10 +1383,6 @@ async def get_room_complexity(self, room_id: str) -> Dict[str, float]:
13831383

13841384
return {"v1": complexity_v1}
13851385

1386-
def get_current_events_token(self) -> int:
1387-
"""The current maximum token that events have reached"""
1388-
return self._stream_id_gen.get_current_token()
1389-
13901386
async def get_all_new_forward_event_rows(
13911387
self, instance_name: str, last_id: int, current_id: int, limit: int
13921388
) -> List[Tuple[int, str, str, str, str, str, str, str, str]]:

synapse/storage/databases/main/stream.py

+15-19
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
- topological tokems: "t%d-%d", where the integers map to the topological
3535
and stream ordering columns respectively.
3636
"""
37-
import abc
37+
3838
import logging
3939
from typing import TYPE_CHECKING, Collection, Dict, List, Optional, Set, Tuple
4040

@@ -336,12 +336,7 @@ def filter_to_clause(event_filter: Optional[Filter]) -> Tuple[str, List[str]]:
336336
return " AND ".join(clauses), args
337337

338338

339-
class StreamWorkerStore(EventsWorkerStore, SQLBaseStore, metaclass=abc.ABCMeta):
340-
"""This is an abstract base class where subclasses must implement
341-
`get_room_max_stream_ordering` and `get_room_min_stream_ordering`
342-
which can be called in the initializer.
343-
"""
344-
339+
class StreamWorkerStore(EventsWorkerStore, SQLBaseStore):
345340
def __init__(
346341
self,
347342
database: DatabasePool,
@@ -379,13 +374,22 @@ def __init__(
379374

380375
self._stream_order_on_start = self.get_room_max_stream_ordering()
381376

382-
@abc.abstractmethod
383377
def get_room_max_stream_ordering(self) -> int:
384-
raise NotImplementedError()
378+
"""Get the stream_ordering of regular events that we have committed up to
379+
380+
Returns the maximum stream id such that all stream ids less than or
381+
equal to it have been successfully persisted.
382+
"""
383+
return self._stream_id_gen.get_current_token()
385384

386-
@abc.abstractmethod
387385
def get_room_min_stream_ordering(self) -> int:
388-
raise NotImplementedError()
386+
"""Get the stream_ordering of backfilled events that we have committed up to
387+
388+
Backfilled events use *negative* stream orderings, so this returns the
389+
minimum negative stream id such that all stream ids greater than or
390+
equal to it have been successfully persisted.
391+
"""
392+
return self._backfill_id_gen.get_current_token()
389393

390394
def get_room_max_token(self) -> RoomStreamToken:
391395
"""Get a `RoomStreamToken` that marks the current maximum persisted
@@ -1351,11 +1355,3 @@ async def get_name_from_instance_id(self, instance_id: int) -> str:
13511355
retcol="instance_name",
13521356
desc="get_name_from_instance_id",
13531357
)
1354-
1355-
1356-
class StreamStore(StreamWorkerStore):
1357-
def get_room_max_stream_ordering(self) -> int:
1358-
return self._stream_id_gen.get_current_token()
1359-
1360-
def get_room_min_stream_ordering(self) -> int:
1361-
return self._backfill_id_gen.get_current_token()

0 commit comments

Comments
 (0)