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

Add a sanity-check in the StreamChangeCache #7299

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/7299.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a sanity-check in the StreamChangeCache to check that important data is not being overwritten.
15 changes: 15 additions & 0 deletions synapse/util/caches/stream_change_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,21 @@ def entity_has_changed(self, entity, stream_pos):
"""
assert type(stream_pos) is int

# sanity-check that we are not going to overwrite existing data.
current = self._cache.get(stream_pos)
if current is not None:
if current != entity:
logger.error(
"Stream %s: %s has already changed at %s",
self.name,
current,
stream_pos,
)
raise NotImplementedError(
"more than one entity changing at a stream position"
)
return

if stream_pos > self._earliest_known_stream_pos:
old_pos = self._entity_to_key.get(entity, None)
if old_pos is not None:
Expand Down