-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bust _membership_stream_cache
cache when current state changes
#17732
base: develop
Are you sure you want to change the base?
Changes from 2 commits
2bd0e63
d327c62
64eb71f
dd87620
7c53716
bceb4e0
944d1e0
20ff239
f40e649
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix membership caches not updating in state reset scenarios. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -314,6 +314,17 @@ def entity_has_changed(self, entity: EntityType, stream_pos: int) -> None: | |
self._entity_to_key[entity] = stream_pos | ||
self._evict() | ||
|
||
def all_entities_changed(self, stream_pos: int) -> None: | ||
""" | ||
Mark all entities as changed. This is useful when the cache is invalidated and | ||
there may be some potential change for all of the entities. | ||
""" | ||
Comment on lines
+317
to
+321
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re: I don't think it makes sense to drop all of the keys as we're essentially not sure if something has changed so we have to update them to say "something might have changed but we don't know for sure". I think this is the way and is just "unfortunate for the membership caches" |
||
# All entities are at the same stream position now. | ||
self._cache = SortedDict({stream_pos: set(self._entity_to_key.keys())}) | ||
self._entity_to_key = { | ||
entity: stream_pos for entity in self._entity_to_key.keys() | ||
} | ||
|
||
def _evict(self) -> None: | ||
""" | ||
Ensure the cache has not exceeded the maximum size. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -251,3 +251,19 @@ def test_max_pos(self) -> None: | |
|
||
# Unknown entities will return None | ||
self.assertEqual(cache.get_max_pos_of_last_change("[email protected]"), None) | ||
|
||
def test_all_entities_changed(self) -> None: | ||
""" | ||
`StreamChangeCache.all_entities_changed(...)` will mark all entites as changed. | ||
""" | ||
cache = StreamChangeCache("#test", 1, max_size=10) | ||
|
||
cache.entity_has_changed("[email protected]", 2) | ||
cache.entity_has_changed("[email protected]", 3) | ||
cache.entity_has_changed("[email protected]", 4) | ||
|
||
cache.all_entities_changed(5) | ||
|
||
self.assertEqual(cache.get_max_pos_of_last_change("[email protected]"), 5) | ||
self.assertEqual(cache.get_max_pos_of_last_change("[email protected]"), 5) | ||
self.assertEqual(cache.get_max_pos_of_last_change("[email protected]"), 5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kinda weird to just stick this here (same with the others in
process_replication_rows
). Better way to organize this?