Skip to content

fix(frontend): prevent stale global sysvar refresh - #26271

Merged
XuPeng-SH merged 4 commits into
mainfrom
fix/global-sysvar-cache-generation-26270
Jul 29, 2026
Merged

XuPeng-SH merged 4 commits into
mainfrom
fix/global-sysvar-cache-generation-26270

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

Summary

Prevent a catalog snapshot captured before SET GLOBAL from replacing the committing CN's newer in-memory global-system-variable value.

  • Record the account cache's local mutation generation before a refresh reads the catalog.
  • Publish the full snapshot only if no local mutation advanced that generation while the read was in flight.
  • Preserve the existing cache object when an entry was created or replaced during the read.
  • Keep the generation specific to successful local mutations; refreshes do not invalidate each other.

Root cause

GlobalSysVarsMgr.Get read the catalog outside the cache lock, then replaced the whole cache map. A concurrent SET GLOBAL could commit and update one cache entry in the gap, after which the older full snapshot restored the old value.

Scope

This is Option A for the same-CN lost-update race described in #26270. It deliberately does not claim cross-CN cache propagation; that needs a durable revision plus invalidation/reconciliation design.

Validation

  • go test -count=1 -timeout=10m ./pkg/frontend
  • go test -race -count=1 -timeout=15m ./pkg/frontend
  • Each new exact regression test: go test -race -count=100 -run '^Test…$' ./pkg/frontend
  • go vet ./pkg/frontend
  • go build ./pkg/frontend

Regression coverage

  • Deterministically blocks a stale refresh, commits SET GLOBAL password_history = 0, releases the refresh, and verifies the cache remains 0.
  • Ensures refresh publication does not advance the local mutation generation.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve-equivalent deep review on exact head bdb3f83: no merge-blocking correctness, performance, compatibility, or lifecycle issue found.

The same-CN publication invariant closes correctly. A refresh captures the current account object and its local mutation generation before catalog I/O. Final publication rechecks object identity under the manager lock and generation under the account-entry lock. Therefore a concurrent successful SET GLOBAL either publishes after the refresh or advances the generation and makes the older snapshot ineligible; the stale snapshot cannot be the final cache state.

I also traced entry creation/replacement, concurrent refreshes, catalog-error paths, session initialization, SHOW GLOBAL VARIABLES refresh, and SET GLOBAL commit-before-cache ordering. The lock graph is one-way from GlobalSysVarsMgr to SystemVariables with no reverse edge, no lock is held across catalog I/O, and the change adds no goroutine, resource owner, wait cycle, or unbounded container. The stated cross-CN invalidation gap remains intentionally outside Option A and is not obscured by this patch.

Local validation on this exact head passed:

  • both exact generation regressions were enumerated and passed with race, count 100;
  • full pkg/frontend tests passed in normal and race modes;
  • pkg/frontend build and vet passed;
  • diff check is clean.

GitHub does not allow the PR author to approve their own pull request, so this COMMENT is the strongest available review action. On code, this is an approve.

@XuPeng-SH
XuPeng-SH marked this pull request as ready for review July 28, 2026 07:14
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep re-review on unchanged exact head bdb3f83, prospectively merged with latest main 3653b5e: no merge-blocking correctness, performance, compatibility, or lifecycle issue found.

The target invariant is sound across the relevant interleavings. A refresh snapshots both the current account object identity and its local mutation generation before catalog I/O. Publication then rechecks identity under the manager lock and generation under the account lock. A successful same-CN SET GLOBAL either publishes after an older refresh or advances the generation and makes that refresh ineligible, so the older catalog snapshot cannot become the final local cache state.

This pass independently checked:

  • SET commit-before-cache ordering, catalog failures, equal-value mutations, first cache creation, object replacement, and overlapping refreshes;
  • lock ordering and contention: manager -> account is one-way, no account -> manager edge exists, and no lock is held across catalog I/O;
  • allocation/lifecycle effects: no new goroutine, resource owner, retry loop, or unbounded state; the extra uint64 and uncontended lock operations are not material beside the catalog refresh;
  • scope boundaries: cross-CN convergence and the pre-existing broader SET-vs-SET durable/cache ordering are not solved here, but neither is worsened or hidden by this focused Option A fix.

Fresh validation:

  • both exact generation regressions passed under race for 100 repetitions;
  • full pkg/frontend passed in normal and race modes;
  • pkg/frontend build, vet, and diff checks passed;
  • the prospective latest-main merge is clean, builds, and both regressions again passed under race for 100 repetitions;
  • the latest CI attempt is green (the rollup still lists superseded cancelled/failed jobs from the earlier run).

GitHub does not permit an author to approve their own PR, so this COMMENT is the strongest available action. On code, this remains an approve.

@XuPeng-SH
XuPeng-SH merged commit e371ea4 into main Jul 29, 2026
30 checks passed
@XuPeng-SH
XuPeng-SH deleted the fix/global-sysvar-cache-generation-26270 branch July 29, 2026 00:14
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## Summary

Prevent a catalog snapshot captured before `SET GLOBAL` from replacing
the committing CN's newer in-memory global-system-variable value.

- Record the account cache's local mutation generation before a refresh
reads the catalog.
- Publish the full snapshot only if no local mutation advanced that
generation while the read was in flight.
- Preserve the existing cache object when an entry was created or
replaced during the read.
- Keep the generation specific to successful local mutations; refreshes
do not invalidate each other.

## Root cause

`GlobalSysVarsMgr.Get` read the catalog outside the cache lock, then
replaced the whole cache map. A concurrent `SET GLOBAL` could commit and
update one cache entry in the gap, after which the older full snapshot
restored the old value.

## Scope

This is Option A for the same-CN lost-update race described in matrixorigin#26270.
It deliberately does not claim cross-CN cache propagation; that needs a
durable revision plus invalidation/reconciliation design.

## Validation

- `go test -count=1 -timeout=10m ./pkg/frontend`
- `go test -race -count=1 -timeout=15m ./pkg/frontend`
- Each new exact regression test: `go test -race -count=100 -run
'^Test…$' ./pkg/frontend`
- `go vet ./pkg/frontend`
- `go build ./pkg/frontend`

## Regression coverage

- Deterministically blocks a stale refresh, commits `SET GLOBAL
password_history = 0`, releases the refresh, and verifies the cache
remains `0`.
- Ensures refresh publication does not advance the local mutation
generation.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## Summary

Prevent a catalog snapshot captured before `SET GLOBAL` from replacing
the committing CN's newer in-memory global-system-variable value.

- Record the account cache's local mutation generation before a refresh
reads the catalog.
- Publish the full snapshot only if no local mutation advanced that
generation while the read was in flight.
- Preserve the existing cache object when an entry was created or
replaced during the read.
- Keep the generation specific to successful local mutations; refreshes
do not invalidate each other.

## Root cause

`GlobalSysVarsMgr.Get` read the catalog outside the cache lock, then
replaced the whole cache map. A concurrent `SET GLOBAL` could commit and
update one cache entry in the gap, after which the older full snapshot
restored the old value.

## Scope

This is Option A for the same-CN lost-update race described in matrixorigin#26270.
It deliberately does not claim cross-CN cache propagation; that needs a
durable revision plus invalidation/reconciliation design.

## Validation

- `go test -count=1 -timeout=10m ./pkg/frontend`
- `go test -race -count=1 -timeout=15m ./pkg/frontend`
- Each new exact regression test: `go test -race -count=100 -run
'^Test…$' ./pkg/frontend`
- `go vet ./pkg/frontend`
- `go build ./pkg/frontend`

## Regression coverage

- Deterministically blocks a stale refresh, commits `SET GLOBAL
password_history = 0`, releases the refresh, and verifies the cache
remains `0`.
- Ensures refresh publication does not advance the local mutation
generation.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## Summary

Prevent a catalog snapshot captured before `SET GLOBAL` from replacing
the committing CN's newer in-memory global-system-variable value.

- Record the account cache's local mutation generation before a refresh
reads the catalog.
- Publish the full snapshot only if no local mutation advanced that
generation while the read was in flight.
- Preserve the existing cache object when an entry was created or
replaced during the read.
- Keep the generation specific to successful local mutations; refreshes
do not invalidate each other.

## Root cause

`GlobalSysVarsMgr.Get` read the catalog outside the cache lock, then
replaced the whole cache map. A concurrent `SET GLOBAL` could commit and
update one cache entry in the gap, after which the older full snapshot
restored the old value.

## Scope

This is Option A for the same-CN lost-update race described in matrixorigin#26270.
It deliberately does not claim cross-CN cache propagation; that needs a
durable revision plus invalidation/reconciliation design.

## Validation

- `go test -count=1 -timeout=10m ./pkg/frontend`
- `go test -race -count=1 -timeout=15m ./pkg/frontend`
- Each new exact regression test: `go test -race -count=100 -run
'^Test…$' ./pkg/frontend`
- `go vet ./pkg/frontend`
- `go build ./pkg/frontend`

## Regression coverage

- Deterministically blocks a stale refresh, commits `SET GLOBAL
password_history = 0`, releases the refresh, and verifies the cache
remains `0`.
- Ensures refresh publication does not advance the local mutation
generation.

This branch was previously deployed

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

Labels

size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants