|
27 | 27 | )
|
28 | 28 |
|
29 | 29 | import attr
|
| 30 | +from typing_extensions import Protocol |
30 | 31 |
|
31 | 32 | from synapse.api.constants import AccountDataTypes
|
32 | 33 | from synapse.replication.http.streams import ReplicationGetStreamUpdates
|
|
78 | 79 | UpdateFunction = Callable[[str, Token, Token, int], Awaitable[StreamUpdateResult]]
|
79 | 80 |
|
80 | 81 |
|
| 82 | +class CurrentTokenFunction(Protocol): |
| 83 | + def __call__(self, instance_name: str, minimum: bool = False) -> Token: |
| 84 | + ... |
| 85 | + |
| 86 | + |
81 | 87 | class Stream:
|
82 | 88 | """Base class for the streams.
|
83 | 89 |
|
@@ -107,7 +113,7 @@ def parse_row(cls, row: StreamRow) -> Any:
|
107 | 113 | def __init__(
|
108 | 114 | self,
|
109 | 115 | local_instance_name: str,
|
110 |
| - current_token_function: Callable[[str], Token], |
| 116 | + current_token_function: CurrentTokenFunction, |
111 | 117 | update_function: UpdateFunction,
|
112 | 118 | ):
|
113 | 119 | """Instantiate a Stream
|
@@ -192,12 +198,16 @@ async def get_updates_since(
|
192 | 198 |
|
193 | 199 | def current_token_without_instance(
|
194 | 200 | current_token: Callable[[], int]
|
195 |
| -) -> Callable[[str], int]: |
| 201 | +) -> CurrentTokenFunction: |
196 | 202 | """Takes a current token callback function for a single writer stream
|
197 | 203 | that doesn't take an instance name parameter and wraps it in a function that
|
198 | 204 | does accept an instance name parameter but ignores it.
|
199 | 205 | """
|
200 |
| - return lambda instance_name: current_token() |
| 206 | + |
| 207 | + def expanded_current_token(instance_name: str, minimum: bool = False) -> int: |
| 208 | + return current_token() |
| 209 | + |
| 210 | + return expanded_current_token |
201 | 211 |
|
202 | 212 |
|
203 | 213 | def make_http_update_function(hs: "HomeServer", stream_name: str) -> UpdateFunction:
|
@@ -246,10 +256,12 @@ def __init__(self, hs: "HomeServer"):
|
246 | 256 | self.store.get_all_new_backfill_event_rows,
|
247 | 257 | )
|
248 | 258 |
|
249 |
| - def _current_token(self, instance_name: str) -> int: |
| 259 | + def _current_token(self, instance_name: str, minimum: bool = False) -> int: |
250 | 260 | # The backfill stream over replication operates on *positive* numbers,
|
251 | 261 | # which means we need to negate it.
|
252 |
| - return -self.store._backfill_id_gen.get_current_token_for_writer(instance_name) |
| 262 | + return -self.store._backfill_id_gen.get_current_token_for_writer( |
| 263 | + instance_name, minimum |
| 264 | + ) |
253 | 265 |
|
254 | 266 |
|
255 | 267 | class PresenceStream(Stream):
|
@@ -395,7 +407,7 @@ def __init__(self, hs: "HomeServer"):
|
395 | 407 | self.store.get_all_push_rule_updates,
|
396 | 408 | )
|
397 | 409 |
|
398 |
| - def _current_token(self, instance_name: str) -> int: |
| 410 | + def _current_token(self, instance_name: str, minimum: bool = False) -> int: |
399 | 411 | push_rules_token = self.store.get_max_push_rules_stream_id()
|
400 | 412 | return push_rules_token
|
401 | 413 |
|
|
0 commit comments