Repository navigation
feat: cache: read through &self, and without waiting - #8
Merged
drmingdrmer merged 1 commit intoNov 18, 2026
Merged
Conversation
# Summary `Cache` reads take `&self`, and the data is behind a tokio `RwLock` instead of a `Mutex`, so concurrent readers share a cache, by reference or `Arc`, without an outer lock. The new `try_access_now`, `try_get_now` and `try_list_dir_now` never wait: they return `None` while the watcher holds the data, as while it initializes or reconnects. # Details The watcher holds the lock exclusively, briefly to apply each change, and for the whole reset-and-refetch of an initialization. The waiting reads, `try_get`, `try_list_dir`, `try_last_seq` and `try_access`, wait for it as before. The non-waiting reads use `RwLock::try_read`, which is not a future: a lock polled once with `now_or_never()` returned `None` whenever the task's tokio coop budget was spent, even with the lock free, and its caller read the remote store for no reason. `Some(Err(_))` still reports a source that cannot be subscribed. Upgrade tip: `cache_data()` takes `&self` and returns a `RwLockReadGuard` instead of a `MutexGuard`. A caller that kept a cache behind a mutex only to read it can drop the mutex. Fixes: databendlabs#4
xp-trumpet
reviewed
Nov 18, 2026
xp-trumpet
left a comment
There was a problem hiding this comment.
@xp-trumpet reviewed 9 files and all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on drmingdrmer).
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.
Changelog
feat: cache: read through
&self, and without waitingSummary
Cachereads take&self, and the data is behind a tokioRwLockinstead of a
Mutex, so concurrent readers share a cache, by referenceor
Arc, without an outer lock. The newtry_access_now,try_get_nowandtry_list_dir_nownever wait: they returnNonewhile the watcher holds the data, as while it initializes or
reconnects.
Details
The watcher holds the lock exclusively, briefly to apply each change,
and for the whole reset-and-refetch of an initialization. The waiting
reads,
try_get,try_list_dir,try_last_seqandtry_access, waitfor it as before. The non-waiting reads use
RwLock::try_read, which isnot a future: a lock polled once with
now_or_never()returnedNonewhenever the task's tokio coop budget was spent, even with the lock
free, and its caller read the remote store for no reason.
Some(Err(_))still reports a source that cannot be subscribed.Upgrade tip:
cache_data()takes&selfand returns aRwLockReadGuardinstead ofa
MutexGuard. A caller that kept a cache behind a mutex only to readit can drop the mutex.
Fixes: #4