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

Update events stream cache before ID generator #14648

Closed

Conversation

Fizzadar
Copy link
Contributor

@Fizzadar Fizzadar commented Dec 9, 2022

Part of #14158

Essentially this just moves all the handling logic for the events stream change cache and ID generator under the EventsWorkerStore and ensures that the cache is updated before the token position. This prevents other threads seeing tokens ahead of the cache (full description at #14158 (comment)).

This now also includes an assertion in flagging changes in the stream change cache, as described in this comment: #14158 (comment).

Signed off by Nick @ Beeper (@Fizzadar).

Pull Request Checklist

This means during replication the changes will be flagged twice, but this
isn't a problem aside from pointless work. To avoid this requires bringing
the function out of the `CacheInvalidationWorkerStore` which is much more
involved due to class dependencies.
This will assert that any changes being flagged have tokens ahead of
the current known position. If the change is at or behind the current
token there is a race condition during which changes may be incorrectly
missed, this guards against that.
@Fizzadar Fizzadar force-pushed the update-events-stream-cache-before-id branch from 5ee0425 to 3a86f75 Compare December 9, 2022 11:25
This has to be here to account for applying changes on workers that
acually increment the stream ID - they have to increment the token before
they know about it to flag the change.

This does leave open a potential hole in the check for replicated changes
which should be addressed in the future.
@Fizzadar Fizzadar marked this pull request as ready for review December 9, 2022 17:20
@Fizzadar Fizzadar requested a review from a team as a code owner December 9, 2022 17:20
@Fizzadar Fizzadar changed the title Update events stream cache before Update events stream cache before ID generator Dec 10, 2022
@@ -271,6 +277,13 @@ def entity_has_changed(self, entity: EntityType, stream_pos: int) -> None:
if stream_pos <= self._earliest_known_stream_pos:
return

# Any change being flagged must be ahead of any current token, otherwise
# we have a race condition between token position and stream change cache.
# NOTE: this checks for equal to allow for a process persisting an event to
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not super pleased with this perhaps a better way would be to add a flag to explicitly enable exact matches for writer instances?

@Fizzadar Fizzadar marked this pull request as draft January 1, 2023 09:02
@Fizzadar
Copy link
Contributor Author

Fizzadar commented Jan 1, 2023

I have reverted to draft because #14723 presents a cleaner (IMO) solution (but not the assertion - perhaps worth splitting into a separate PR?).

@erikjohnston erikjohnston removed the request for review from a team January 3, 2023 11:12
@richvdh
Copy link
Member

richvdh commented Jan 9, 2023

looks like this is largely superceded by #14723?

The assertion seems like a worthwhile addition, via a separate PR.

@Fizzadar
Copy link
Contributor Author

looks like this is largely superceded by #14723?

The assertion seems like a worthwhile addition, via a separate PR.

Yes and agreed, will make a separate PR for that when I have a moment, closing this one!

@Fizzadar Fizzadar closed this Jan 11, 2023
@Fizzadar Fizzadar deleted the update-events-stream-cache-before-id branch January 24, 2023 10:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants