fix(spanstats): set SkipMvccStats when node is designated for zero spans - #173205
Open
waterWang wants to merge 1 commit into
Open
fix(spanstats): set SkipMvccStats when node is designated for zero spans#173205waterWang wants to merge 1 commit into
waterWang wants to merge 1 commit into
Conversation
When SkipApproxTotalStats is set and a node is the designated MVCC node for none of its spans, `spansRequiringMvcc` is empty. An empty list is indistinguishable from the proto3 zero-value "not participating" case, so the node falls through and computes MVCC stats for all its spans. Fix by setting `SkipMvccStats: true` on the per-node request when the node's computed MVCC set is empty. This stays compatible with `verifySpanStatsRequest` (SkipMvccStats is only set when SpansRequiringMvcc is empty, so they remain mutually exclusive). Fixes cockroachdb#173200
|
It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR? Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
|
|
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.
Description
When
SkipApproxTotalStatsis set and a node is the designated MVCC node for none of its spans,spansRequiringMvccis computed as an empty list. An empty list is indistinguishable from the proto3 zero-value "not participating" case, so the receiving node'sgetLocalStatsfalls through and computes MVCC stats for all its spans — the opposite of the intended behavior.Root cause
In
getLocalStats, the skip decision is gated onlen(req.SpansRequiringMvcc) > 0. When the list is empty (because this node is designated for zero spans), the guard fails silently andskipMvccstaysfalse, computing full MVCC for every span.Fix
In
nodeFn, whenSkipApproxTotalStatsis set and the computedspansRequiringMvccis empty, setSkipMvccStats: trueon the per-node request. This disambiguates the empty-list case: the receiving node seesSkipMvccStats == trueand skips MVCC collection entirely.Compatibility
SkipMvccStatsis only set whenSpansRequiringMvccis empty, soverifySpanStatsRequest's mutual exclusivity check (len(SpansRequiringMvcc) > 0 && SkipMvccStats) is satisfied. ThegetLocalStatshandler already checksreq.SkipMvccStatsbeforelen(req.SpansRequiringMvcc), so this is backward compatible with older nodes.Impact
When
spansPerNode < nodes(e.g. a single large span whose ranges are spread across many nodes), the bug causes ~M nodes each to do a full-span meta scan and returnTotalStatsthat gets summed intoApproximateTotalStats, violating the documented invariant:Fixes #173200
Related: #161819, #138792