Skip to content

Comments

Add memory tracking and cap to query consolidator#804

Draft
tanjinx wants to merge 1 commit intoslack-22.0from
tanjin-consolidator-memcap
Draft

Add memory tracking and cap to query consolidator#804
tanjinx wants to merge 1 commit intoslack-22.0from
tanjin-consolidator-memcap

Conversation

@tanjinx
Copy link

@tanjinx tanjinx commented Feb 24, 2026

Track memory usage of pending results in the consolidator using atomic int64, and add a --consolidator-memory-cap flag to bypass consolidation when memory exceeds the configured threshold (default 0 = unlimited). Exposes a ConsolidatorMemoryUsage gauge metric for observability.

Description

What's this?

Adds memory tracking to the query consolidator so we can observe and bound how much memory is held in pending results. When many distinct queries are in-flight with large results, the consolidator can cause unbounded memory growth -- this gives us a cap to gracefully degrade by bypassing consolidation.

How it works

  • Tracks memory atomically in the consolidator: SetResult adds the result's CachedSize, Broadcast subtracts it
  • New --consolidator-memory-cap flag (default 0 = unlimited). When exceeded, new queries skip consolidation and execute independently (fallthrough, never rejects)
  • Exposes a ConsolidatorMemoryUsage gauge metric for observability
  • Follows the same patterns as the existing stream consolidator memory tracking

Files changed

  • go/sync2/consolidator.go -- core memory tracking (memory field, Memory() interface method)
  • go/sync2/fake_consolidator.go -- updated fake to satisfy interface
  • go/sync2/consolidator_test.go -- three new tests (basic, nil result, concurrent)
  • go/vt/vttablet/tabletserver/tabletenv/config.go -- new config field + flag
  • go/vt/vttablet/tabletserver/query_engine.go -- gauge metric registration
  • go/vt/vttablet/tabletserver/query_executor.go -- memory cap check in execSelect()

Most of this was written by Claude Code - I just provided direction.

Related Issue(s)

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Deployment Notes

AI Disclosure

Track memory usage of pending results in the consolidator using atomic
int64, and add a --consolidator-memory-cap flag to bypass consolidation
when memory exceeds the configured threshold (default 0 = unlimited).
Exposes a ConsolidatorMemoryUsage gauge metric for observability.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Signed-off-by: Tanjin Xu <tanjin.xu@slack-corp.com>
@github-actions github-actions bot added this to the v22.0.3 milestone Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant