Skip to content

fix(disttae): handle empty TN response in table stats - #26782

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
aptend:fix/26779-table-stats-empty-tn
Aug 7, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
aptend:fix/26779-table-stats-empty-tn

Conversation

@aptend

@aptend aptend commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #26779

What this PR does / why we need it:

Adds a shared ctl.GetFirstTNResponse boundary for callers that require a TN response. When no TN is available, table statistics, SHOW ACCOUNTS storage usage, and mo_ctl(..., INSPECT, ...) now return ErrNoAvailableBackend instead of indexing an empty result and panicking the CN. Commands where an empty target set is valid continue to consume Result.Data directly.

Adds regression coverage for the shared boundary, table statistics, and SHOW ACCOUNTS.

@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

Choose a reason for hiding this comment

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

Deep review of head 1f9d848. No code was changed.

P1 — The empty-TN success contract still leaves sibling process-panic paths

The new length check protects only getChangedTableList, but the source of the invalid state is still in ctl.GetTNHandlerFunc: when cluster.GetTNService discovers no target, it returns a nil error with Data set to an empty []any. Other callers still treat nil error as proof that a response exists. A concrete public path is frontend.requestStorageUsage, which calls the same helper and then unconditionally returns result.Data.([]any)[0]. With an empty or expired storage-usage cache, SHOW ACCOUNTS during the same TN-restart window still reaches an index-out-of-range panic. ctl.MoCtl has the same unchecked [0] access for INSPECT.

This means the PR fixes one table-stats symptom while the shared no-backend contract can still crash a CN from sibling consumers. The no-target condition should be owned at GetTNHandlerFunc, with any intentionally empty-result command made explicit, or every consumer must be audited and guarded. The regression should cover the common handler boundary and at least the SHOW ACCOUNTS fallback, not only the local table-stats indexing site.

Validation on this head: the new focused regression passed, the full pkg/vm/engine/disttae test package passed, go build and go vet passed, and git diff --check is clean.

@aptend
aptend requested a review from aunjgr as a code owner August 7, 2026 08:13
@aptend

aptend commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the empty-response review in dd124d5:

  • added ctl.GetFirstTNResponse as the shared boundary for strict TN-response consumers;
  • migrated table stats, SHOW ACCOUNTS storage usage, and INSPECT;
  • kept commands such as PING, where an empty target set is valid, on the existing raw result contract;
  • added shared-boundary and SHOW ACCOUNTS regressions, while retaining the table-stats regression.

Focused regressions, full owning-package tests, build, and vet pass for ctl, disttae, and frontend.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Deep review of head dd124d5.

The previous P1 is resolved systematically: strict single-response consumers now share GetFirstTNResponse and return ErrNoAvailableBackend for an empty TN target set. The affected table-stats, SHOW ACCOUNTS/storage-usage, and mo_ctl INSPECT paths are all guarded; the remaining snapshot-read consumer explicitly treats an empty set as a valid unsuccessful response.

I also traced TN disappearance after target enumeration through txnOperator.Debug and rpc.sender.Send. Send/build-stream/receive failures return an error, while successful sends preserve response cardinality, including cached-write response trimming, so this change does not leave the same failure mode behind a short-response panic.

No correctness, compatibility, resource-lifecycle, hang, or performance blocker found. The hot-path cost is only a type assertion and length check, with no extra RPC, retry, allocation growth, lock, or scan.

Validation:

  • focused empty-TN regressions for ctl, frontend, and disttae passed
  • full tests for all three changed packages passed
  • go vet for all three changed packages passed
  • git diff --check passed

@XuPeng-SH
XuPeng-SH merged commit c72224b into matrixorigin:main Aug 7, 2026
15 of 18 checks passed
XuPeng-SH added a commit that referenced this pull request Aug 14, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue #26779

## What this PR does / why we need it:

Backports #26782 (`c72224bea6`) to `4.2-dev`.

Adds a shared `ctl.GetFirstTNResponse` boundary for callers that require
a TN response. When no TN is available, table statistics, `SHOW
ACCOUNTS` storage usage, and `mo_ctl(..., INSPECT, ...)` now return
`ErrNoAvailableBackend` instead of indexing an empty result and
panicking the CN. Commands where an empty target set is valid continue
to consume `Result.Data` directly.

The original regression tests are included unchanged.

## Testing

- `go test -mod=readonly -count=1 -timeout 180s
./pkg/sql/plan/function/ctl ./pkg/frontend ./pkg/vm/engine/disttae`

Co-authored-by: aptend <[email protected]>
Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…6782)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#26779

## What this PR does / why we need it:

Adds a shared `ctl.GetFirstTNResponse` boundary for callers that require
a TN response. When no TN is available, table statistics, `SHOW
ACCOUNTS` storage usage, and `mo_ctl(..., INSPECT, ...)` now return
`ErrNoAvailableBackend` instead of indexing an empty result and
panicking the CN. Commands where an empty target set is valid continue
to consume `Result.Data` directly.

Adds regression coverage for the shared boundary, table statistics, and
`SHOW ACCOUNTS`.

---------

Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…6782)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#26779

## What this PR does / why we need it:

Adds a shared `ctl.GetFirstTNResponse` boundary for callers that require
a TN response. When no TN is available, table statistics, `SHOW
ACCOUNTS` storage usage, and `mo_ctl(..., INSPECT, ...)` now return
`ErrNoAvailableBackend` instead of indexing an empty result and
panicking the CN. Commands where an empty target set is valid continue
to consume `Result.Data` directly.

Adds regression coverage for the shared boundary, table statistics, and
`SHOW ACCOUNTS`.

---------

Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…6782)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#26779

## What this PR does / why we need it:

Adds a shared `ctl.GetFirstTNResponse` boundary for callers that require
a TN response. When no TN is available, table statistics, `SHOW
ACCOUNTS` storage usage, and `mo_ctl(..., INSPECT, ...)` now return
`ErrNoAvailableBackend` instead of indexing an empty result and
panicking the CN. Commands where an empty target set is valid continue
to consume `Result.Data` directly.

Adds regression coverage for the shared boundary, table statistics, and
`SHOW ACCOUNTS`.

---------

Co-authored-by: XuPeng-SH <[email protected]>

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

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants