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

Commit 39c5fd5

Browse files
committed
Process received rows by invalidating caches and notifying
1 parent 4f4d690 commit 39c5fd5

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

synapse/replication/tcp/client.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,18 @@
3636
TagAccountDataStream,
3737
ToDeviceStream,
3838
TypingStream,
39+
UnPartialStatedEventStream,
3940
UnPartialStatedRoomStream,
4041
)
4142
from synapse.replication.tcp.streams.events import (
4243
EventsStream,
4344
EventsStreamEventRow,
4445
EventsStreamRow,
4546
)
46-
from synapse.replication.tcp.streams.partial_state import UnPartialStatedRoomStreamRow
47+
from synapse.replication.tcp.streams.partial_state import (
48+
UnPartialStatedEventStreamRow,
49+
UnPartialStatedRoomStreamRow,
50+
)
4751
from synapse.types import PersistedEventPosition, ReadReceipt, StreamKeyType, UserID
4852
from synapse.util.async_helpers import Linearizer, timeout_deferred
4953
from synapse.util.metrics import Measure
@@ -247,6 +251,14 @@ async def on_rdata(
247251
self._state_storage_controller.notify_room_un_partial_stated(
248252
row.room_id
249253
)
254+
elif stream_name == UnPartialStatedEventStream.NAME:
255+
for row in rows:
256+
assert isinstance(row, UnPartialStatedEventStreamRow)
257+
258+
# Wake up any tasks waiting for the event to be un-partial-stated.
259+
self._state_storage_controller.notify_event_un_partial_stated(
260+
row.event_id
261+
)
250262

251263
await self._presence_handler.process_replication_rows(
252264
stream_name, instance_name, token, rows

synapse/storage/databases/main/events_worker.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@
5959
run_as_background_process,
6060
wrap_as_background_process,
6161
)
62-
from synapse.replication.tcp.streams import BackfillStream
62+
from synapse.replication.tcp.streams import BackfillStream, UnPartialStatedEventStream
6363
from synapse.replication.tcp.streams.events import EventsStream
64+
from synapse.replication.tcp.streams.partial_state import UnPartialStatedEventStreamRow
6465
from synapse.storage._base import SQLBaseStore, db_to_json, make_in_list_sql_clause
6566
from synapse.storage.database import (
6667
DatabasePool,
@@ -391,6 +392,16 @@ def process_replication_rows(
391392
self._stream_id_gen.advance(instance_name, token)
392393
elif stream_name == BackfillStream.NAME:
393394
self._backfill_id_gen.advance(instance_name, -token)
395+
elif stream_name == UnPartialStatedEventStream.NAME:
396+
for row in rows:
397+
assert isinstance(row, UnPartialStatedEventStreamRow)
398+
399+
self.is_partial_state_event.invalidate(row.event_id)
400+
401+
if row.rejection_status_changed:
402+
# If the partial-stated event became rejected or unrejected
403+
# when it wasn't before, we need to invalidate this cache.
404+
self._invalidate_local_get_event_cache(row.event_id)
394405

395406
super().process_replication_rows(stream_name, instance_name, token, rows)
396407

synapse/storage/databases/main/state.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# limitations under the License.
1515
import collections.abc
1616
import logging
17-
from typing import TYPE_CHECKING, Collection, Dict, Iterable, Optional, Set, Tuple
17+
from typing import TYPE_CHECKING, Any, Collection, Dict, Iterable, Optional, Set, Tuple
1818

1919
import attr
2020

@@ -24,6 +24,8 @@
2424
from synapse.events import EventBase
2525
from synapse.events.snapshot import EventContext
2626
from synapse.logging.opentracing import trace
27+
from synapse.replication.tcp.streams import UnPartialStatedEventStream
28+
from synapse.replication.tcp.streams.partial_state import UnPartialStatedEventStreamRow
2729
from synapse.storage._base import SQLBaseStore
2830
from synapse.storage.database import (
2931
DatabasePool,
@@ -82,6 +84,20 @@ def __init__(
8284
super().__init__(database, db_conn, hs)
8385
self._instance_name: str = hs.get_instance_name()
8486

87+
def process_replication_rows(
88+
self,
89+
stream_name: str,
90+
instance_name: str,
91+
token: int,
92+
rows: Iterable[Any],
93+
) -> None:
94+
if stream_name == UnPartialStatedEventStream.NAME:
95+
for row in rows:
96+
assert isinstance(row, UnPartialStatedEventStreamRow)
97+
self._get_state_group_for_event.invalidate((row.event_id,))
98+
99+
super().process_replication_rows(stream_name, instance_name, token, rows)
100+
85101
async def get_room_version(self, room_id: str) -> RoomVersion:
86102
"""Get the room_version of a given room
87103
Raises:

0 commit comments

Comments
 (0)