-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add TTL values for client caches of key locations and auto remove expired entries #12514
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
cf3480c
bc933ea
2967d31
18b1b4a
78ca1a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -972,15 +972,45 @@ void updateLocationCacheWithCaches(DatabaseContext* self, | |
| } | ||
| } | ||
|
|
||
| Reference<LocationInfo> addCaches(const Reference<LocationInfo>& loc, | ||
| const std::vector<Reference<ReferencedInterface<StorageServerInterface>>>& other) { | ||
| std::vector<Reference<ReferencedInterface<StorageServerInterface>>> interfaces; | ||
| interfaces.reserve(loc->size() + other.size()); | ||
| for (int i = 0; i < loc->size(); ++i) { | ||
| interfaces.emplace_back((*loc)[i]); | ||
| ACTOR static Future<Void> cleanupLocationCache(DatabaseContext* cx) { | ||
| // Only run cleanup if TTL is enabled | ||
| if (CLIENT_KNOBS->LOCATION_CACHE_ENTRY_TTL == 0.0) { | ||
| return Void(); | ||
| } | ||
|
|
||
| loop { | ||
| wait(delay(CLIENT_KNOBS->LOCATION_CACHE_EVICTION_INTERVAL)); | ||
|
|
||
| double currentTime = now(); | ||
| std::vector<KeyRangeRef> toRemove; | ||
| int totalCount = 0; | ||
|
|
||
| // Scan locationCache for expired entries | ||
| auto iter = cx->locationCache.randomRange(); | ||
| for (; iter != cx->locationCache.lastItem(); ++iter) { | ||
| if (iter->value() && iter->value()->hasCaches) { | ||
| // Check the expireTime of the first cache entry as a representative | ||
| // All entries in a range typically have similar expiration times | ||
| if (iter->value()->expireTime > 0.0 && iter->value()->expireTime <= currentTime) { | ||
| toRemove.push_back(iter->range()); | ||
| } | ||
| } | ||
| totalCount++; | ||
| if (totalCount > 1000 || toRemove.size() > 100) { | ||
| break; // Avoid long blocking scans | ||
| } | ||
| } | ||
|
|
||
| // Remove expired entries | ||
| for (const auto& range : toRemove) { | ||
| cx->locationCache.insert(range, Reference<LocationInfo>()); | ||
| } | ||
|
|
||
| if (!toRemove.empty()) { | ||
| CODE_PROBE(true, "LocationCacheCleanup removed some entries"); | ||
| TraceEvent("LocationCacheCleanup").detail("RemovedRanges", toRemove.size()); | ||
| } | ||
| } | ||
| interfaces.insert(interfaces.end(), other.begin(), other.end()); | ||
| return makeReference<LocationInfo>(interfaces, true); | ||
| } | ||
|
|
||
| ACTOR static Future<Void> handleTssMismatches(DatabaseContext* cx) { | ||
|
|
@@ -1266,6 +1296,7 @@ DatabaseContext::DatabaseContext(Reference<AsyncVar<Reference<IClusterConnection | |
|
|
||
| clientDBInfoMonitor = monitorClientDBInfoChange(this, clientInfo, &proxiesChangeTrigger); | ||
| tssMismatchHandler = handleTssMismatches(this); | ||
| locationCacheCleanup = cleanupLocationCache(this); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to explicitly call |
||
| clientStatusUpdater.actor = clientStatusUpdateActor(this); | ||
|
|
||
| smoothMidShardSize.reset(CLIENT_KNOBS->INIT_MID_SHARD_BYTES); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,15 +64,22 @@ class StorageServerInfo : public ReferencedInterface<StorageServerInterface> { | |
| struct LocationInfo : MultiInterface<ReferencedInterface<StorageServerInterface>>, FastAllocated<LocationInfo> { | ||
| using Locations = MultiInterface<ReferencedInterface<StorageServerInterface>>; | ||
| explicit LocationInfo(const std::vector<Reference<ReferencedInterface<StorageServerInterface>>>& v) | ||
| : Locations(v) {} | ||
| : Locations(v), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please correct me if I'm wrong, but do I understand the code correctly that the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's correct. Each shard is stored on multiple storage servers, so |
||
| expireTime(CLIENT_KNOBS->LOCATION_CACHE_ENTRY_TTL > 0.0 ? now() + CLIENT_KNOBS->LOCATION_CACHE_ENTRY_TTL | ||
| : 0.0) {} | ||
| LocationInfo(const std::vector<Reference<ReferencedInterface<StorageServerInterface>>>& v, bool hasCaches) | ||
| : Locations(v), hasCaches(hasCaches) {} | ||
| : Locations(v), hasCaches(hasCaches), | ||
| expireTime(CLIENT_KNOBS->LOCATION_CACHE_ENTRY_TTL > 0.0 ? now() + CLIENT_KNOBS->LOCATION_CACHE_ENTRY_TTL | ||
| : 0.0) {} | ||
| LocationInfo(const LocationInfo&) = delete; | ||
| LocationInfo(LocationInfo&&) = delete; | ||
| LocationInfo& operator=(const LocationInfo&) = delete; | ||
| LocationInfo& operator=(LocationInfo&&) = delete; | ||
| bool hasCaches = false; | ||
| Reference<Locations> locations() { return Reference<Locations>::addRef(this); } | ||
|
|
||
| bool hasCaches = false; | ||
| // Absolute expiration time for this cache entry. 0 means no expiration (TTL disabled). | ||
| double expireTime = 0.0; | ||
| }; | ||
|
|
||
| using CommitProxyInfo = ModelInterface<CommitProxyInterface>; | ||
|
|
@@ -376,6 +383,7 @@ class DatabaseContext : public ReferenceCounted<DatabaseContext>, public FastAll | |
| Future<Void> tssMismatchHandler; | ||
| PromiseStream<std::pair<UID, std::vector<DetailedTSSMismatch>>> tssMismatchStream; | ||
| Future<Void> grvUpdateHandler; | ||
| Future<Void> locationCacheCleanup; | ||
| Reference<CommitProxyInfo> commitProxies; | ||
| Reference<GrvProxyInfo> grvProxies; | ||
| bool proxyProvisional; // Provisional commit proxy and grv proxy are used at the same time. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.