Skip to content

[4.2-dev] fix(tae): cancel snapshot writes when a table-tail flush fails - #33493

Merged
mergify[bot] merged 3 commits into
matrixorigin:4.2-devfrom
iamlinjunhong:fix/33490-cancel-snapshot-writes
Dec 1, 2026
Merged

mergify[bot] merged 3 commits into
matrixorigin:4.2-devfrom
iamlinjunhong:fix/33490-cancel-snapshot-writes

Conversation

@iamlinjunhong

@iamlinjunhong iamlinjunhong commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG

Which issue(s) this PR fixes:

Fixes #33490.

What this PR does / why we need it:

A table-tail flush can time out waiting for a snapshot while an already-running child keeps writing on the I/O worker's context. In one QA incident a child logged a successful object write more than 18 minutes after its parent reported failure.

The child now registers a cancel function and claims its batch under the same lock. On parent failure, the parent first retires pending batches and cancels running writes across both data and tombstone groups, including any partially scheduled group. It then waits for the local writers and their resource cleanup before returning control to the scheduler. The existing snapshot wait budget is unchanged. A phase log records the failure before waiting for cleanup.

If the parent panics while snapshot writes are outstanding, the same cancellation and drain run before the panic propagates. The parent retains each child as it is scheduled, including children in a partially scheduled group. Review finding

If the storage backend ignores cancellation, the parent must still wait for the local writer to finish. Canceling a client request cannot guarantee rollback of a PUT already received by a remote server.

Validation

  • Both new ownership and cancellation regression tests passed 100 repetitions each under the race detector. The owning package also passed build, vet, normal tests and a full-package race run.

  • Engine integration tests passed for table-tail flush, both flush error-handling paths and tombstone rollback.

  • In the QA-version A/B experiment with the real MinIO SDK and a delayed loopback HTTP endpoint, median time from timeout to the next successful flush fell from 361.119 ms to 0.645 ms (20 runs per version). Normal two-write medians were 0.168 and 0.172 ms. Experiment and controls

  • Panic follow-up at 415e77f443bb (Darwin/arm64, Go 1.27.1). mo-cgo-test reproduced one late queued write on the reviewed code and zero after the fix, with the injected panic reaching the caller. The panic regression and both snapshot ownership tests each passed 100 race repetitions. The jobs package passed normal and race tests, and the targeted TAE flush and tombstone rollback tests passed. The jobs package built successfully. Vet and incremental lint passed for both touched packages. The loopback figures above are from the original QA-version experiment.

@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 →

@mergify mergify Bot added the kind/bug Something isn't working label Nov 30, 2026
@mergify

mergify Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Nov 30, 2026
XuPeng-SH pushed a commit that referenced this pull request Nov 30, 2026
## What type of PR is this?

- [x] BUG

## Which issue(s) this PR fixes:

Fixes #33490. The corresponding 4.2-dev change is #33493.

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

When a table-tail flush times out waiting for an appendable-object
snapshot, a child that already owns its batch can continue writing on
the I/O worker. That write occupies the worker even though its parent
can no longer commit the flush.

Register the child's cancel function while transferring ownership of the
batch. On failure, retire pending batches and cancel running writes
across both the data and tombstone groups, including partially scheduled
groups. Wait for the local writers to release their resources before
returning the parent's object scopes to the scheduler. Log the failing
phase before draining so it is visible even if storage is slow to
respond. The six-minute snapshot wait budget is unchanged.

### Validation on main

Compared the baseline at `d4a41b466c` and this patch on the same Linux
host. Two three-row flushes shared one I/O worker. The loopback HTTP
endpoint delayed the first PUT response by 400 ms, and the parent had a
40 ms wait budget after the write reached storage.

| Scenario | Runs per version | Baseline P50 / P95 | Patched P50 / P95 |
|---|---:|---:|---:|
| S3FS + MinIO SDK, time from timeout to next successful flush | 20 |
361.196 / 361.526 ms | 0.679 / 0.872 ms |
| Backend ignores cancellation, same recovery metric | 20 | 360.722 /
360.904 ms | 360.642 / 360.778 ms |
| Two successful writes, warmed up, total elapsed | 1,800 | 53 / 205 µs
| 57 / 205 µs |

The HTTP endpoint observed cancellation in all 20 patched runs, and the
next object write succeeded each time. A backend that ignores
cancellation can still delay parent cleanup. These tests measure local
worker recovery; production checkpoint latency and OOM frequency were
outside the experiment.

The jobs package passed build, vet, normal tests and the race detector.
Both new regression tests passed 100 race repetitions each. The engine
regressions passed for table-tail flush, error handling, tombstone
rollback, stopping checkpoints on flush failure, and preserving snapshot
row IDs across an aborted append.

### Branch update validation

Rebased onto official `main` at `98b20975b7` after GitHub rejected
Mergify's automated branch update for a workflow permission. The patch
at `54b5814dcb` matches the patch at `8286e8d586` in `git range-diff`.
`git diff --check` and the Loom artifact check passed. On Darwin/arm64
at `54b5814dcb`, `mo-cgo-test -race -short` passed both snapshot
cancellation tests and four engine tests covering normal table-tail
flush, flush errors, and tombstone rollback. These checks cover the
rebase across the upstream appendable-object merge changes. The
benchmark numbers above are from `8286e8d586`.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
@XuPeng-SH

XuPeng-SH commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 10c9a8b52e2784da2a73cf211dfe4e205902040e

Review completed. Read the assessment.

@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.

mo-bot review · mo-bot-local · review

Commit: 10c9a8b52e2784da2a73cf211dfe4e205902040e

Assessment: request_changes

The cancellation design handles ordinary error returns, but the new cleanup condition skips a recoverable panic path. This allows snapshot writes that were previously retired while queued to start after the parent releases its object scopes.

Model: gpt-6.1-terra / max

Session: 01a22af4-cf2a-7f70-88e4-931bbf57d739 · slot 2 · generation 14

  • P2 pkg/vm/engine/tae/tables/jobs/flushTableTail.go:322: The synchronous merge panics after snapshot tasks have been scheduled, for example when S3FS.Write encounters an io.EOF error.
    Impact: The named error remains nil during unwinding, so abortSnapshotWrites is skipped. The scheduler recovers the panic and releases the object scopes, after which queued snapshot tasks can start writes that may leave orphan files or overlap a retry. The baseline already allowed an active writer to continue on this path; allowing queued writers to start is the regression.
    Evidence: A real-scheduler probe with one I/O worker and an injected merge-write panic observed a queued snapshot write after scope release on the candidate; the same probe with the two implementation files overlaid from the merge-base observed none. Those baseline files match the pinned target base and the linked issue's v4.2.9 incident commit. Ensure outstanding children are canceled and drained on panic as well as on an error return, while preserving panic propagation.

Validation:

  • Private /tmp and loopback preflight passed; retained native inputs and library hashes matched the frozen checkout.

  • Both focused cancellation tests passed. The jobs package passed 30 repetitions under the race detector.

  • TestFlushTableErrorHandle, TestFlushTableErrorHandle2, TestFlushTabletail, and TestFlushTransferTombstonesRollback passed.

  • The controlled scheduler panic probe and merge-base control completed with the observations described in the finding; receipts and logs are retained in the diagnostic directory.

Limitations:

  • The panic probe injected a FileService panic; it did not exercise a real S3 endpoint or a real network failure.

  • The first race build did not load the assigned shell environment and failed to find native headers. The corrected run used the assigned environment and passed.

  • The full test suite was not run. A remote PUT already accepted by an object store may still complete after local cancellation.

@XuPeng-SH

XuPeng-SH commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 415e77f443bbfa3705f45a174c38b675cb2f7d5a

Review completed. Read the assessment.

@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.

mo-bot review · mo-bot-local · review

Commit: 415e77f443bbfa3705f45a174c38b675cb2f7d5a

Assessment: approve

The earlier panic finding is resolved: the parent records children before scheduling and cancels and drains outstanding snapshot writes on both errors and panics. The change reuses the existing scheduler and adds per-child synchronization to preserve batch ownership and object scopes. No actionable findings remain.

Model: gpt-6.1-terra / max

Session: 01a22aff-bb68-7e31-ae71-ee4ab48ad9d0 · slot 0 · generation 45

Validation:

  • Private /tmp and loopback preflight and native-input provenance checks passed.

  • The focused cancellation tests and the complete jobs package passed. Each focused child test passed 100 race-enabled repetitions, and the complete jobs package passed once under race.

  • The engine panic regression and selected flush, error-handling, and tombstone-rollback tests passed. The panic regression also passed 100 race-enabled repetitions.

  • The same panic regression failed against the earlier reviewed parent implementation, observing one queued snapshot write after the panic, and passed on the assigned head.

  • Vet and git diff --check passed. The corrected evidence audit passed with receipt checks/1796097353872575714-4.json; its initial receipt selector had matched multiple valid test runs.

Limitations:

  • The author-reported MinIO latency experiment and full integration suite were not independently rerun.

  • A backend that ignores cancellation can delay scope release until its local write returns; cancellation cannot guarantee rollback of a PUT already accepted remotely.

@mergify mergify Bot added the queued label Dec 1, 2026
@mergify

mergify Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into 4.2-dev as 39f0aa3 at 05:03 UTC

1 h 6 min in the queue, 1 h 5 min of it CI.

So far

  • ✅ Entered the queue Tue 1 Dec, 03:57 · rule release-4.2 · triggered by rule Automatic queue on approval for release-4.2
  • ✅ Passed · in place
  • ✅ Merged 05:03 · 39f0aa3 · squash
3 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection
  • any of · required by GitHub branch protection:
    • check-success = CI Required
    • check-neutral = CI Required
    • check-skipped = CI Required

Times in UTC · dashboard · how the merge queue works

@mergify
mergify Bot merged commit 39f0aa3 into matrixorigin:4.2-dev Dec 1, 2026
31 of 32 checks passed
@mergify mergify Bot removed the queued label Dec 1, 2026

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