Skip to content

fix/use latest doc on persist & correct queueing #27

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

Merged
merged 1 commit into from
Feb 11, 2025

Conversation

stanley2058
Copy link
Collaborator

@stanley2058 stanley2058 commented Feb 10, 2025

This PR fixes two potential issues:

  1. Remove the need for debouncedPersistDocMap, which could lead to data missing if debouncedPersist is called when persisting. (Detail explained below)
  2. Allow queueing the next persist operation immediately after the current persist request fires. This ensures that every persistent call eventually results in a persist.

The current flow looks like this:

If the stream is scheduled for persistence, another call to debouncedPersist will do nothing but update the doc for persistence.

But the updated doc would be dropped if the call to debouncedPersist is 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 debouncedPersist now would only update debouncedPersistDocMap without 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.

@Yukaii Yukaii merged commit d57c8de into main Feb 11, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants