perf: hash a precomputed segment ID digest in result-level cache ETags #20950
All Vouch review confidence checks passed
Residual risk 0.27 = Change Risk (0.47) × (1 − Review Confidence (0.43)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.47 · 480 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.369
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #20950"
general
weight: 0.35
agali-09
Description
When the result-level cache is on, the Broker computes an ETag for every query before it can serve a cached result. The ETag hashes every segment in the query's interval, so even a cache hit costs time in proportion to the number of segments. On a datasource with 160,983 segments, a cache hit over the whole datasource spent about 1 s in the Broker (
query/time1,013 ms). The cost grew linearly from 20 ms at 519 segments, about 6.3 µs per segment, and Broker CPU time matched wall time.A sampling profile of the Broker serving those hits put about 69% of the query thread in
computeResultLevelCachingEtag. Most of that was string formatting:Interval.toString()(21%) andSegmentId.toString()(18%), which format two dates each per segment, plus SHA-1 over the resulting strings (12%). The profile had about 110 samples on the query thread, so the shares are approximate.Hash a precomputed digest of each segment ID
Each
ServerSelectornow computes a 128-bit digest of its segment ID once, when it's created: the first 128 bits of a SHA-1 over the ID's fields. Those fields are the datasource, the interval start and end in milliseconds, the version and the partition number, with both strings length-prefixed so different IDs never produce the same input. A selector's segment ID never changes, becauseBrokerServerViewkeys selectors by segment ID.ServerSelector.putSegmentIdDigest(Hasher)adds the digest to a hasher.computeResultLevelCachingEtagnow hashes each segment's digest and the query interval's start and end in milliseconds, in place of the two formatted strings. The ETag still covers the same information, so it still changes whenever the set of segments or their query intervals changes. It just no longer formats anything per segment.Alternatives considered:
SegmentIdand its strings.SegmentId.toString(). That costs around 100 bytes of Broker heap per segment, against 16 for the digest.Release note
The Broker spends less CPU computing result-level cache ETags, which it does for every query when the result-level cache is enabled, and the savings are largest for queries over many segments. ETag values change with this release, so existing result-level cache entries miss once after upgrading, and clients that send a stored ETag in
If-None-Matchget a full response once.<hr>
##### Key changed/added classes in this PR
ServerSelectorCachingClusteredClient(CacheKeyManager.computeResultLevelCachingEtag)<hr>
This PR has:
- [x] using the concurrency checklist (the digest fields are final and set in the constructor)
-
ServerSelectorTest: the digest matches for equal IDs and changes with each ID field.-
CachingClusteredClientCacheKeyManagerTest: the mocked selector adds a real digest.-
CachingClusteredClientTest.testIfNoneMatch: the pinned ETag value changes.