fix/use latest doc on persist & correct queueing#27
Merged
Conversation
galaxian85
approved these changes
Feb 11, 2025
Yukaii
approved these changes
Feb 11, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes two potential issues:
debouncedPersistDocMap, which could lead to data missing ifdebouncedPersistis called when persisting. (Detail explained below)The current flow looks like this:

If the stream is scheduled for persistence, another call to
debouncedPersistwill do nothing but update the doc for persistence.But the updated doc would be dropped if the call to

debouncedPersistis during the persistence stage:This is because the doc to persist is retrieved at the start of the persistence stage, but the stream key is still in the queue. Calling
debouncedPersistnow would only updatedebouncedPersistDocMapwithout scheduling a new persistence operation. The newly updated doc will be cleared after the previous persistence without being saved.In this PR, I restructured the queueing and persisting algorithm to the following:

Where when persisting, we always use the latest doc in the cache. Once the doc to persist is retrieved, we dequeue the current stream key immediately to allow the queueing of new persistence operations.