Repository navigation
[release-7.3] Process ranges in chunks when evicting stale peers - #13643
Conversation
| wait(yield()); | ||
| } | ||
|
|
||
| // Phase 2: invalidate the cache based on invalid ranges computed in Phase 1 |
There was a problem hiding this comment.
FYI: phase 2 may not need chunking assuming rangesToInvalidate.size() is not too high e.g. O(1K). But given we already have a way to chunk, does not hurt to have an option on hand in case we discover too many invalid ranges for some problematics workload.
Result of foundationdb-pr-macos-m1 on macOS 14.x
|
Result of foundationdb-pr-clang on Linux RHEL 9
|
Result of foundationdb-pr-macos on macOS 14.x
|
Result of foundationdb-pr-clang-73 on Linux CentOS 7
|
Result of foundationdb-pr-73 on Linux CentOS 7
|
Result of foundationdb-pr-macos-m1 on macOS 14.x
|
Result of foundationdb-pr-cluster-tests-73 on Linux CentOS 7
|
Result of foundationdb-pr-73 on Linux CentOS 7
|
Result of foundationdb-pr on Linux RHEL 9
|
Result of foundationdb-pr-clang-73 on Linux CentOS 7
|
Result of foundationdb-pr-clang on Linux RHEL 9
|
Result of foundationdb-pr on Linux RHEL 9
|
Result of foundationdb-pr-cluster-tests-73 on Linux CentOS 7
|
Result of foundationdb-pr-macos on macOS 14.x
|
alecgrieser
left a comment
There was a problem hiding this comment.
LGTM. There are a few places where, theoretically, the extra yields could lead to some unnecessary cache invalidations, I think, which theoretically, we could think about tightening up, but nothing that I think is too likely to happen in practice
| auto& loc = iter->value(); | ||
| for (int i = 0; i < loc->size(); ++i) { | ||
| if (addresses.contains(loc->getInterface(i).address())) { | ||
| rangesToInvalidate.push_back(KeyRange(KeyRangeRef(iter->begin(), iter->end()))); |
There was a problem hiding this comment.
Does this need to be converted from a KeyRangeRef to ensure correctness somehow, or would it be possible to keep it as just a reference?
There was a problem hiding this comment.
converted from a KeyRangeRef
You mean not have a reference and rather a deep copy? If so, that was my intent with KeyRange(KeyRangeRef(iter->begin().... KeyRange is Standalone<KeyRangeRef>, so it deep copies the underlying bytes.
would it be possible to keep it as just a reference
Between yields, the key range reference obtained via the iterator points into location cache tree nodes, which may be freed, leaving it dangling. So to be safe, I did the deep copy above.
| // Evicts cached ranges mapping to any server address in the input addresses set | ||
| // Yields every LOCATION_CACHE_PEER_EVICTOR_SCAN_CHUNK ranges | ||
| ACTOR static Future<Void> invalidateCacheByAddresses(DatabaseContext* self, | ||
| std::unordered_set<NetworkAddress> addresses) { |
There was a problem hiding this comment.
Do we need to worry about the case that one of the addresses comes back to life in the middle of a sweep? If that were to happen, then it seems like we may evict its ranges right after inserting it, which could lead to unnecessary cache refetches. Which probably isn't the end of the world
There was a problem hiding this comment.
Yes, that is a valid tradeoff. In practice, I don't expect it to matter, but let me add a comment for completeness.
| state int phase2Yields = 0; | ||
| state double phase2StartT = now(); | ||
| for (; phase2Idx < rangesToInvalidate.size(); phase2Idx++) { | ||
| self->locationCache.insert(rangesToInvalidate[phase2Idx], Reference<LocationInfo>()); |
There was a problem hiding this comment.
Similar to the case that there's an address that comes back to life, it is possible that we have already reloaded a range into the location cache during a yield (I think), which could mean that we invalidate it here unnecessarily. Like with above, I think the worst case is we end up re-loading something into the cache that never needed to be invalidated
There was a problem hiding this comment.
Same as earlier comment: yes, that is a valid tradeoff. In practice, I don't expect it to matter, but let me add a comment for completeness.
| // Value must be >= 1 (evictor will assert otherwise). | ||
| // If this value is > LOCATION_CACHE_EVICTION_SIZE, then this will boil down to blocking | ||
| // invalidation without any yields in between. | ||
| int LOCATION_CACHE_PEER_EVICTOR_SCAN_CHUNK; |
There was a problem hiding this comment.
Do you think we could get away with 1 less knob by making the loop time itself (sample the clock every say 1000 entries) and doing say 10ms of work per turn? Essentially this has the code calculate a reasonable value for this parameter at runtime.
There was a problem hiding this comment.
Yeah, that should be possible. Assuming 1000 or 10ms above are hard coded and not knobs?
There was a problem hiding this comment.
Given we've done fair amount of testing on the current commit hash, let me tackle this suggestion in a small follow-up PR.
There was a problem hiding this comment.
Yeah, that should be possible. Assuming 1000 or 10ms above are hard coded and not knobs?
Right. 1000 is just to avoid sampling the clock too frequently in this loop which I think does not need a knob (it's specific to the rest of the code in the loop more than anything else). the 10ms is generic in nature and may not benefit by being a named constant or knob with semantics like "how much CPU intensive background maintenance work to do before yielding". Even then I don't see why we'd need to change the 10ms. The main thing about it is that it has a reasonable bound altogether (alternatives may not).
There was a problem hiding this comment.
Hm, 10 ms also seems like quite a bit of time to be paused in the middle of trying to, say, read an FDB key, though not the end of the world if it's not chronic. Maybe more to the point, I think it gets hard to simulation test because of when the simulated clock gets updated
There was a problem hiding this comment.
(thinking more)
I think the first question is whether we need size (process N entries before yielding) based chunking or time based (do >= 10ms amount of work before yielding). In the past, for different use-case, I've done both. I think here, either would work. Honestly, one can be derived from another anyway (although requires observability from prod).
Time based chunking sounds more like what we'd want since the whole point is to give time to other critical tasks. So let's say we converge on that.
Then the question is: can it be fixed to 10ms or does it have to be a knob for various reasons? Perhaps we can have a knob and have it be default to 10ms (and potentially some other value for simulation). We don't expect to change the 10ms so hopefully no one (other than us right now) has to even know that chunking is happening.
@gxglass @alecgrieser does that sound good? Basically my proposal is:
- switch to time based chunking
- have a knob (10ms for prod, maybe some other value for sim). Expect no one to have to tune the knob but it's there in case we need it (prod shows behavior where it needs tuning, reduce simulation noise, etc.).
There was a problem hiding this comment.
Maybe see if there is a general solution lurking here for code paths that just want to do a bunch of background maintenance and yield periodically. Anyway fine to pick this up later or main-only.
| init( LOCATION_CACHE_PEER_EVICTOR_ENABLED, false ); if( randomize && isSimulated ) LOCATION_CACHE_PEER_EVICTOR_ENABLED = deterministicRandom()->coinflip(); | ||
| init( LOCATION_CACHE_PEER_EVICTOR_DELAY, 60.0 ); | ||
| init( LOCATION_CACHE_PEER_EVICTOR_FAILED_THRESHOLD, 0 ); | ||
| init( LOCATION_CACHE_PEER_EVICTOR_SCAN_CHUNK, 1000000 ); if( randomize && BUGGIFY ) LOCATION_CACHE_PEER_EVICTOR_SCAN_CHUNK = deterministicRandom()->randomInt(1, 11); |
There was a problem hiding this comment.
Is there a reason we choose 1000000 and not 600000 similar to LOCATION_CACHE_EVICTION_SIZE?
There was a problem hiding this comment.
Just so that by default, we don't do chunking. But now that we've done some more at-scale testing, I can verify the results and do chunking by default. Having said that, I'm thinking to delete this knob as part of #13643 (comment).
Result of foundationdb-pr-macos-m1 on macOS 14.x
|
Result of foundationdb-pr-clang on Linux RHEL 9
|
Result of foundationdb-pr-clang-73 on Linux CentOS 7
|
Result of foundationdb-pr-73 on Linux CentOS 7
|
Result of foundationdb-pr on Linux RHEL 9
|
Result of foundationdb-pr-cluster-tests-73 on Linux CentOS 7
|
Result of foundationdb-pr-macos on macOS 14.x
|
8b5700d to
a2085a9
Compare
Result of foundationdb-pr-macos-m1 on macOS 14.x
|
Result of foundationdb-pr-73 on Linux CentOS 7
|
Result of foundationdb-pr-clang-73 on Linux CentOS 7
|
Result of foundationdb-pr-clang on Linux RHEL 9
|
Result of foundationdb-pr on Linux RHEL 9
|
Result of foundationdb-pr-macos on macOS 14.x
|
Result of foundationdb-pr-cluster-tests-73 on Linux CentOS 7
|
Result of foundationdb-pr-cluster-tests-73 on Linux CentOS 7
|
Result of foundationdb-pr-clang-73 on Linux CentOS 7
|
Result of foundationdb-pr-macos-m1 on macOS 14.x
|
Result of foundationdb-pr-73 on Linux CentOS 7
|
Result of foundationdb-pr-clang on Linux RHEL 9
|
Result of foundationdb-pr on Linux RHEL 9
|
Result of foundationdb-pr-73 on Linux CentOS 7
|
Result of foundationdb-pr-macos-m1 on macOS 14.x
|
Result of foundationdb-pr-macos on macOS 14.x
|
Result of foundationdb-pr-clang-73 on Linux CentOS 7
|
Result of foundationdb-pr on Linux RHEL 9
|
Result of foundationdb-pr-cluster-tests-73 on Linux CentOS 7
|
Result of foundationdb-pr-macos on macOS 14.x
|
Result of foundationdb-pr-cluster-tests-73 on Linux CentOS 7
summary / time infofor f in fdb-kubernetes-/logs/.log); do check all fail typesfail_test=false Check for test failures where one or more tests have failed for a test suite.if grep -q -- "--- FAIL:" fdb-kubernetes-/logs/.log ; then Check for all tests that have not finished e.g. because they timed out or they paniced during the execution.for f in $(grep -L -- "SUCCESS! --" fdb-kubernetes-/logs/.log); do
|
…, grv proxy) Client processes can keep stale RequestStream references to dead storage-server/proxy peers (via DatabaseContext::locationCache and MonitorLeader::shrinkProxyList's sampled subset), causing connection-timeout churn. Adds opt-in draining of dead-peer connections: a per-DatabaseContext peer evictor driven by a persistent per-address connect-failed counter, a shrinkProxyList cache clear below the connection cap, eager proxy rebuild on clientInfo change, and an InterfaceTracker observability layer (all gated by knobs, default off in production). invalidateCacheByAddress(es) processes ranges in chunks and yields between chunks to avoid hogging the event loop on large caches. Includes StalePeerTest, a deterministic repro workload. Ported from upstream/release-7.3 PR apple#13367 (51e1c42) and PR apple#13643 (805c271). Conflicts resolved in: tests/CMakeLists.txt, fdbclient/NativeAPI.actor.cpp, fdbclient/include/fdbclient/CommitProxyInterface.h, fdbclient/include/fdbclient/StorageServerInterface.h, fdbrpc/include/fdbrpc/FlowTransport.h, fdbserver/SimulatedCluster.actor.cpp.
…, grv proxy) (#13912) Client processes can keep stale RequestStream references to dead storage-server/proxy peers (via DatabaseContext::locationCache and MonitorLeader::shrinkProxyList's sampled subset), causing connection-timeout churn. Adds opt-in draining of dead-peer connections: a per-DatabaseContext peer evictor driven by a persistent per-address connect-failed counter, a shrinkProxyList cache clear below the connection cap, eager proxy rebuild on clientInfo change, and an InterfaceTracker observability layer (all gated by knobs, default off in production). invalidateCacheByAddress(es) processes ranges in chunks and yields between chunks to avoid hogging the event loop on large caches. Includes StalePeerTest, a deterministic repro workload. Ported from upstream/release-7.3 PR #13367 (51e1c42) and PR #13643 (805c271). Conflicts resolved in: tests/CMakeLists.txt, fdbclient/NativeAPI.actor.cpp, fdbclient/include/fdbclient/CommitProxyInterface.h, fdbclient/include/fdbclient/StorageServerInterface.h, fdbrpc/include/fdbrpc/FlowTransport.h, fdbserver/SimulatedCluster.actor.cpp.
* Fix stale peers for client facing roles (storage server, commit proxy, grv proxy) (#13912) Client processes can keep stale RequestStream references to dead storage-server/proxy peers (via DatabaseContext::locationCache and MonitorLeader::shrinkProxyList's sampled subset), causing connection-timeout churn. Adds opt-in draining of dead-peer connections: a per-DatabaseContext peer evictor driven by a persistent per-address connect-failed counter, a shrinkProxyList cache clear below the connection cap, eager proxy rebuild on clientInfo change, and an InterfaceTracker observability layer (all gated by knobs, default off in production). invalidateCacheByAddress(es) processes ranges in chunks and yields between chunks to avoid hogging the event loop on large caches. Includes StalePeerTest, a deterministic repro workload. Ported from upstream/release-7.3 PR #13367 (51e1c42) and PR #13643 (805c271). Conflicts resolved in: tests/CMakeLists.txt, fdbclient/NativeAPI.actor.cpp, fdbclient/include/fdbclient/CommitProxyInterface.h, fdbclient/include/fdbclient/StorageServerInterface.h, fdbrpc/include/fdbrpc/FlowTransport.h, fdbserver/SimulatedCluster.actor.cpp. (cherry picked from commit 2963ee8) * Enable stale peer fixes by default on main/8.0 Flip the three stale-peer client-facing mitigation knobs from off to on by default now that they have had bake time on 7.3/7.4: - location_cache_peer_evictor_enabled - shrink_proxy_list_clear_cache_below_threshold - dbcontext_eager_proxy_update The forward-port landed these off by default (opt-in). By the 8.0 cut they will have had sufficient production bake time, so main should ship with them on. The simulation randomization (coinflip under randomize && isSimulated) is left unchanged, so simulation still exercises both on and off states; only the production default changes. The stale_peer_observability tracing knob is intentionally left off (it is a debug aid, not a mitigation, and carries overhead). * fix clang-format * fix clang-tidy
Problem: On every sweep of the eviction actor, invalidateCacheByAddresses is called, which invalidates all cached ranges mapping to stale servers. However, invalidateCacheByAddresses was a blocking call with runtime complexity O(|cached ranges|), which can be as high as 600K (based on the LOCATION_CACHE_EVICTION_SIZE knob default). It is unclear whether this is actually a problem in practice e.g., hogging the main event loop for too long could prevent other critical tasks from making progress. This change is a preemptive fix in case invalidateCacheByAddresses turns out to be too expensive for realistic workloads.
Solution: Introduce a chunk-size knob. invalidateCacheByAddresses now processes ranges in chunks of up to this knob value, yielding before processing the next chunk.
Testing: Simulation testing was done to ensure correctness i.e., that this does not break general DB functionality, and that we continue to fix the stale peer issue. See results below.
Ran 250K general test suite: 20260702-221148-praza-stalepeer-chunkRanges-v2-on7.3.77-25f8 compressed=True data_size=34949681 duration=5923005 ended=250000 fail=2 fail_fast=10 max_runs=250000 pass=249998 priority=100 remaining=0 runtime=1:13:55 sanity=False started=250000 stopped=20260702-232543 submitted=20260702-221148 timeout=5400 username=praza-stalepeer-chunkRanges-v2-on7.3.77-25f80264e08efbc72f892955dd2604ef87d3c46f. Both failures are not related.
Ran StalePeerTest specifically 10K times: 20260702-221157-praza-stalepeer-chunkRanges-v2-on7.3.77-25f8 compressed=True data_size=34984822 duration=340545 ended=10000 fail_fast=100 max_runs=10000 pass=10000 priority=100 remaining=0 runtime=0:10:22 sanity=False started=10000 stopped=20260702-222219 submitted=20260702-221157 timeout=5400 username=praza-stalepeer-chunkRanges-v2-on7.3.77-25f80264e08efbc72f892955dd2604ef87d3c46f