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

Commit 02f74f3

Browse files
authored
Combine AbstractStreamIdTracker and AbstractStreamIdGenerator. (#15192)
AbstractStreamIdTracker (now) has only a single sub-class: AbstractStreamIdGenerator, combine them to simplify some code and remove any direct references to AbstractStreamIdTracker.
1 parent 848f7e3 commit 02f74f3

File tree

7 files changed

+15
-27
lines changed

7 files changed

+15
-27
lines changed

changelog.d/15192.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Combine `AbstractStreamIdTracker` and `AbstractStreamIdGenerator`.

synapse/storage/databases/main/devices.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
from synapse.storage.types import Cursor
5353
from synapse.storage.util.id_generators import (
5454
AbstractStreamIdGenerator,
55-
AbstractStreamIdTracker,
5655
StreamIdGenerator,
5756
)
5857
from synapse.types import JsonDict, StrCollection, get_verify_key_from_cross_signing_key
@@ -91,7 +90,7 @@ def __init__(
9190

9291
# In the worker store this is an ID tracker which we overwrite in the non-worker
9392
# class below that is used on the main process.
94-
self._device_list_id_gen: AbstractStreamIdTracker = StreamIdGenerator(
93+
self._device_list_id_gen = StreamIdGenerator(
9594
db_conn,
9695
hs.get_replication_notifier(),
9796
"device_lists_stream",
@@ -712,9 +711,7 @@ async def add_user_signature_change_to_streams(
712711
The new stream ID.
713712
"""
714713

715-
# TODO: this looks like it's _writing_. Should this be on DeviceStore rather
716-
# than DeviceWorkerStore?
717-
async with self._device_list_id_gen.get_next() as stream_id: # type: ignore[attr-defined]
714+
async with self._device_list_id_gen.get_next() as stream_id:
718715
await self.db_pool.runInteraction(
719716
"add_user_sig_change_to_streams",
720717
self._add_user_signature_change_txn,

synapse/storage/databases/main/events_worker.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
from synapse.storage.types import Cursor
7373
from synapse.storage.util.id_generators import (
7474
AbstractStreamIdGenerator,
75-
AbstractStreamIdTracker,
7675
MultiWriterIdGenerator,
7776
StreamIdGenerator,
7877
)
@@ -187,8 +186,8 @@ def __init__(
187186
):
188187
super().__init__(database, db_conn, hs)
189188

190-
self._stream_id_gen: AbstractStreamIdTracker
191-
self._backfill_id_gen: AbstractStreamIdTracker
189+
self._stream_id_gen: AbstractStreamIdGenerator
190+
self._backfill_id_gen: AbstractStreamIdGenerator
192191
if isinstance(database.engine, PostgresEngine):
193192
# If we're using Postgres than we can use `MultiWriterIdGenerator`
194193
# regardless of whether this process writes to the streams or not.

synapse/storage/databases/main/push_rule.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
from synapse.storage.push_rule import InconsistentRuleException, RuleNotFoundException
4747
from synapse.storage.util.id_generators import (
4848
AbstractStreamIdGenerator,
49-
AbstractStreamIdTracker,
5049
IdGenerator,
5150
StreamIdGenerator,
5251
)
@@ -118,7 +117,7 @@ def __init__(
118117

119118
# In the worker store this is an ID tracker which we overwrite in the non-worker
120119
# class below that is used on the main process.
121-
self._push_rules_stream_id_gen: AbstractStreamIdTracker = StreamIdGenerator(
120+
self._push_rules_stream_id_gen = StreamIdGenerator(
122121
db_conn,
123122
hs.get_replication_notifier(),
124123
"push_rules_stream",

synapse/storage/databases/main/pusher.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
)
3737
from synapse.storage.util.id_generators import (
3838
AbstractStreamIdGenerator,
39-
AbstractStreamIdTracker,
4039
StreamIdGenerator,
4140
)
4241
from synapse.types import JsonDict
@@ -60,7 +59,7 @@ def __init__(
6059

6160
# In the worker store this is an ID tracker which we overwrite in the non-worker
6261
# class below that is used on the main process.
63-
self._pushers_id_gen: AbstractStreamIdTracker = StreamIdGenerator(
62+
self._pushers_id_gen = StreamIdGenerator(
6463
db_conn,
6564
hs.get_replication_notifier(),
6665
"pushers",

synapse/storage/databases/main/receipts.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from synapse.storage.engines import PostgresEngine
4040
from synapse.storage.engines._base import IsolationLevel
4141
from synapse.storage.util.id_generators import (
42-
AbstractStreamIdTracker,
42+
AbstractStreamIdGenerator,
4343
MultiWriterIdGenerator,
4444
StreamIdGenerator,
4545
)
@@ -65,7 +65,7 @@ def __init__(
6565

6666
# In the worker store this is an ID tracker which we overwrite in the non-worker
6767
# class below that is used on the main process.
68-
self._receipts_id_gen: AbstractStreamIdTracker
68+
self._receipts_id_gen: AbstractStreamIdGenerator
6969

7070
if isinstance(database.engine, PostgresEngine):
7171
self._can_write_to_receipts = (
@@ -768,7 +768,7 @@ async def insert_receipt(
768768
"insert_receipt_conv", self._graph_to_linear, room_id, event_ids
769769
)
770770

771-
async with self._receipts_id_gen.get_next() as stream_id: # type: ignore[attr-defined]
771+
async with self._receipts_id_gen.get_next() as stream_id:
772772
event_ts = await self.db_pool.runInteraction(
773773
"insert_linearized_receipt",
774774
self._insert_linearized_receipt_txn,

synapse/storage/util/id_generators.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,11 @@ def _load_current_id(
9393
return res
9494

9595

96-
class AbstractStreamIdTracker(metaclass=abc.ABCMeta):
97-
"""Tracks the "current" stream ID of a stream that may have multiple writers.
96+
class AbstractStreamIdGenerator(metaclass=abc.ABCMeta):
97+
"""Generates or tracks stream IDs for a stream that may have multiple writers.
98+
99+
Each stream ID represents a write transaction, whose completion is tracked
100+
so that the "current" stream ID of the stream can be determined.
98101
99102
Stream IDs are monotonically increasing or decreasing integers representing write
100103
transactions. The "current" stream ID is the stream ID such that all transactions
@@ -130,16 +133,6 @@ def get_current_token_for_writer(self, instance_name: str) -> int:
130133
"""
131134
raise NotImplementedError()
132135

133-
134-
class AbstractStreamIdGenerator(AbstractStreamIdTracker):
135-
"""Generates stream IDs for a stream that may have multiple writers.
136-
137-
Each stream ID represents a write transaction, whose completion is tracked
138-
so that the "current" stream ID of the stream can be determined.
139-
140-
See `AbstractStreamIdTracker` for more details.
141-
"""
142-
143136
@abc.abstractmethod
144137
def get_next(self) -> AsyncContextManager[int]:
145138
"""

0 commit comments

Comments
 (0)