server/span_stats: fix SkipApproxTotalStats empty-ambiguity opt-out [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT] - #173207
Open
waterWang wants to merge 1 commit into
Conversation
waterWang
requested review from
alyshanjahani-crl
and removed request for
a team
August 8, 2026 01:34
|
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.
Fixes #173200
Problem
SkipApproxTotalStats(added in #161819, fixing #138792) is meant to ensure that during aSpanStatsfan-out, only one node per span collects logical MVCC stats. The coordinator picks a designated MVCC node per span and populatesSpansRequiringMvccon that node's per-node request.The mechanism relies on a non-empty
SpansRequiringMvcclist to signal "restrict MVCC collection to this subset." But a replica-holding node that is designated for none of its spans receives an emptySpansRequiringMvcc, which is indistinguishable from "field not set" in proto3. Such a node falls through and computes MVCC stats for all of its spans — the opposite of the intended behavior.In
getLocalStats, the skip decision is gated on the list being non-empty:Because the coordinator sets only
SpansRequiringMvcc(neverSkipMvccStats), a node with an empty computed list seesSkipMvccStats == falseandlen(SpansRequiringMvcc) == 0, and computes MVCC for every span it holds.Fix
When
SkipApproxTotalStatsis set and the computedspansRequiringMvccfor a node is empty (the node is the designated MVCC collector for none of its spans), setSkipMvccStats: trueon the per-node request so the receiving node skips MVCC collection entirely and reports physical bytes only.This makes the per-node request unambiguous:
SkipApproxTotalStatsnow guarantees exactly one node per span computes MVCC stats, andApproximateTotalStatsequalsTotalStatsregardless of the spans-to-nodes ratio — restoring the invariant documented inroachpb/span_stats.proto.Test plan
nodeFn).