Skip to content

fix(spanstats): set SkipMvccStats when node is designated for zero spans - #173205

Open
waterWang wants to merge 1 commit into
cockroachdb:masterfrom
waterWang:fix/skip-approx-total-stats-empty-list-173200
Open

fix(spanstats): set SkipMvccStats when node is designated for zero spans#173205
waterWang wants to merge 1 commit into
cockroachdb:masterfrom
waterWang:fix/skip-approx-total-stats-empty-list-173200

Conversation

@waterWang

Copy link
Copy Markdown

Description

When SkipApproxTotalStats is set and a node is the designated MVCC node for none of its spans, spansRequiringMvcc is computed as an empty list. An empty list is indistinguishable from the proto3 zero-value "not participating" case, so the receiving node's getLocalStats falls through and computes MVCC stats for all its spans — the opposite of the intended behavior.

Root cause

In getLocalStats, the skip decision is gated on len(req.SpansRequiringMvcc) > 0. When the list is empty (because this node is designated for zero spans), the guard fails silently and skipMvcc stays false, computing full MVCC for every span.

Fix

In nodeFn, when SkipApproxTotalStats is set and the computed spansRequiringMvcc is empty, set SkipMvccStats: true on the per-node request. This disambiguates the empty-list case: the receiving node sees SkipMvccStats == true and skips MVCC collection entirely.

Compatibility

SkipMvccStats is only set when SpansRequiringMvcc is empty, so verifySpanStatsRequest's mutual exclusivity check (len(SpansRequiringMvcc) > 0 && SkipMvccStats) is satisfied. The getLocalStats handler already checks req.SkipMvccStats before len(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 return TotalStats that gets summed into ApproximateTotalStats, violating the documented invariant:

When set ApproximateTotalStats will equal TotalStats since MVCC stats are collected from only one node rather than accumulated across all replicas.

Fixes #173200

Related: #161819, #138792

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
@waterWang
waterWang requested a review from a team as a code owner August 7, 2026 21:26
@waterWang
waterWang requested review from parkerswy and removed request for a team August 7, 2026 21:26
@blathers-crl

blathers-crl Bot commented Aug 7, 2026

Copy link
Copy Markdown

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:

  • Please ensure your git commit message contains a release note.
  • When CI has completed, please ensure no errors have appeared.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@blathers-crl blathers-crl Bot added the O-community Originated from the community label Aug 7, 2026
@cockroachlabs-cla-agent

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-community Originated from the community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

server: SkipApproxTotalStats fails to skip MVCC collection on nodes designated for zero spans

1 participant