Skip to content

fix: cache: never serve a part of a failed initial flush - #9

Merged
drmingdrmer merged 1 commit into
databendlabs:mainfrom
drmingdrmer:eventwatcher-a-failed-initial-flush
Nov 18, 2026
Merged

drmingdrmer merged 1 commit into
databendlabs:mainfrom
drmingdrmer:eventwatcher-a-failed-initial-flush

Conversation

@drmingdrmer

Copy link
Copy Markdown
Member

Changelog

fix: cache: never serve a part of a failed initial flush

Summary

The watcher collects each initial flush in a fresh CacheData and
replaces the shared data with it only when the flush completes. A
flush that fails part way is dropped, so no reader gets it as a ready
cache, on the first initialization or after a reconnect.

Details

EventWatcher::main used to reset the shared data to empty and apply
the flush to it in place. When the flush broke, the continue that
retries released the lock with the partial data in place, and the
readers queued during the initialization got it as an Ok answer:
keys not delivered yet looked absent.

The watcher still holds the write lock for the whole attempt, so
readers wait for its data. Between failed attempts, a reader gets the
data from before the attempt: after a reconnect, the previous copy,
complete but missing the changes since the stream broke; on the first
initialization, the Unsupported error of a cache not initialized.
While a reconnect fetches its flush, the previous copy and the new
one are both in memory.

Fixes: #3


  • Bug Fix

# Summary

The watcher collects each initial flush in a fresh `CacheData` and
replaces the shared data with it only when the flush completes. A
flush that fails part way is dropped, so no reader gets it as a ready
cache, on the first initialization or after a reconnect.

# Details

`EventWatcher::main` used to reset the shared data to empty and apply
the flush to it in place. When the flush broke, the `continue` that
retries released the lock with the partial data in place, and the
readers queued during the initialization got it as an `Ok` answer:
keys not delivered yet looked absent.

The watcher still holds the write lock for the whole attempt, so
readers wait for its data. Between failed attempts, a reader gets the
data from before the attempt: after a reconnect, the previous copy,
complete but missing the changes since the stream broke; on the first
initialization, the `Unsupported` error of a cache not initialized.
While a reconnect fetches its flush, the previous copy and the new
one are both in memory.

Fixes: databendlabs#3

@xp-trumpet xp-trumpet left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@xp-trumpet reviewed 5 files and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on drmingdrmer).

@drmingdrmer
drmingdrmer merged commit a3ebd13 into databendlabs:main Nov 18, 2026
6 checks passed
@drmingdrmer
drmingdrmer deleted the eventwatcher-a-failed-initial-flush branch November 18, 2026 11:27
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.

EventWatcher: a failed initial flush is served to readers as a ready cache

2 participants