Skip to content

[Bug] Recover from invalid and failed exported log snapshots - #32853

Merged
XuPeng-SH merged 22 commits into
matrixorigin:mainfrom
jiangxinmeng1:codex/fix-32842-32836
Nov 20, 2026
Merged

XuPeng-SH merged 22 commits into
matrixorigin:mainfrom
jiangxinmeng1:codex/fix-32842-32836

Conversation

@jiangxinmeng1

@jiangxinmeng1 jiangxinmeng1 commented Nov 17, 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:

Fixes #32842
Fixes #32836

What this PR does / why we need it:

  • Validate exported snapshots before import. Remove a definitively invalid candidate and try an older export while preserving the TN replay watermark check. Keep transient read and removal errors retryable without compacting the Raft log.
  • Upgrade to the merged Dragonboat fixes in #21 and #22. Export worker failures return an error instead of terminating LogService, and malformed exported metadata or image headers return an incomplete-snapshot result instead of panicking.
  • Retain an admitted export request across a caller timeout, then reconcile its final worker result before retrying. After a same-process replica restart, use Dragonboat's successful restart as confirmation that the previous worker stopped, clean its abandoned export, and release the old export fence.
  • Rename incomplete final directories to durable .removing tombstones before deletion. Sync the parent directory on both initial cleanup and retries, so a partial deletion or crash remains recoverable.
  • Apply the same tombstone cleanup to invalid-candidate eviction and post-import cleanup, and return snapshot inventory errors from voting and nonvoting replica startup.
  • Upgrade the pinned upstream Dragonboat module to the merged Dragonboat #23 commit. Export-abort temporary-directory cleanup now reports filesystem errors to the worker.
  • Retry cleanup of already imported snapshots on the next ordinary truncation tick if the first rename fails, freeing export quota without re-importing or deleting newer candidates.
  • Treat a confirmed missing canonical export directory as already evicted, so an older valid candidate remains reachable; retain the inventory item when rename fails but its source still exists.

Validation

  • The published Dragonboat module passes go mod verify and matches the source used for earlier full-package validation.
  • Focused corruption, TN replay watermark, failed export commit, timeout, replica restart, transient read, partial removal, and parent-sync retry regressions pass.
  • The new restart and tombstone-sync regressions each pass 100 race-enabled repetitions. Full pkg/logservice tests pass (142.162s), full package race tests pass (152.021s), and CGo-configured go vet ./pkg/logservice passes after merging upstream main.
  • After the Dragonboat upgrade, go mod verify and full pkg/logservice tests passed (127.735s). Dragonboat Add top #23 passed focused ordinary and race tests.
  • After the post-import cleanup retry fix and upstream main merge, full pkg/logservice tests pass (132.535s), the import/corrupt-export/rename-failure regressions pass 10 race-enabled repetitions, and CGo-configured go vet ./pkg/logservice passes.
  • After the missing-directory fallback fix, full pkg/logservice tests pass (128.629s), the new fallback and rename controls pass 10 race-enabled repetitions, and go vet ./pkg/logservice passes. Focused regressions also pass after merging the latest upstream main; CI is pending on this head.

Validate export candidates before import so a damaged newer image can be removed and an older safe image used. Reconcile completed worker failures and retry exports after transient filesystem errors. Update to the merged Dragonboat export error release.
@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 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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

Treat missing and malformed exported metadata or image headers as invalid candidates so truncation can fall back to an older valid export. Cover the regular tick and TN replay watermark across five corruption types.
@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 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 1242496003eef1e29c96ced8513a1935fb3c69b1

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: 1242496003eef1e29c96ced8513a1935fb3c69b1

Assessment: request_changes

The patch reuses Dragonboat’s export worker and preserves the TN replay check when falling back to an older snapshot. The previously reported restart fence and tombstone sync regressions pass. Invalid-candidate eviction can still strand files, and two snapshot filesystem error paths still panic.

Model: gpt-6.2-sol / xhigh

Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3

  • P2 pkg/logservice/snapshot.go:223: Deleting a confirmed invalid export removes its metadata and then returns an I/O error. The service restarts before cleanup completes.
    Impact: Startup drops the directory from its inventory and leaves the corrupt image on disk indefinitely. The image still consumes disk space and its directory can block another export at the same index.
    Evidence: The restart probe imported snapshot 14 and confirmed that the image for snapshot 24 remained with zero tracked exports. DropInvalid uses recursive deletion, while startup skips unflagged directories with missing metadata. Reuse the existing durable tombstone cleanup for invalid-candidate eviction and the analogous post-import cleanup reported in #32842. See invalid-eviction-confirmed.jsonl.

  • P2 go.mod:303: An export finds an existing final directory at its Raft index, then hits an I/O error while removing the rejected export’s temporary directory.
    Impact: The Dragonboat worker panics and terminates LogService before the truncation loop can receive an error or retry.
    Evidence: The ordinary truncation tick reproduced the panic in the pinned dependency’s MustRemoveTempDir call from node.doSave. The worker’s new error handler only sees returned errors. Use an export cleanup path in Dragonboat that returns the filesystem error to the worker. See export-abort.jsonl.

  • P2 pkg/logservice/store.go:696: During retained-replica startup, the reconciliation directory scan succeeds and the subsequent snapshot inventory scan returns EIO.
    Impact: LogService exits through a panic instead of returning the startup error. This is the retained-replica failure documented in #32836, which the PR marks fixed.
    Evidence: The startup probe reproduced the panic on the second directory listing. Both voting and nonvoting start paths still panic on snapshotMgr.Init errors, as they did in the base revision. Return the error through the existing startup paths, or narrow the issue closure and track this case separately. See startup-list.jsonl.

Validation:

  • Verified the frozen patch, whitespace, runtime preflight, retained native build inputs, and both pinned Dragonboat checksums. The V2 snapshot writer and format match.

  • Twenty-four focused LogService test functions passed through the supplied executor, covering corrupt export fallback, TN replay safety, export retry, replica restart, and parent-directory sync.

  • Three isolated fault-injection probes reproduced the findings. Commands, terminal receipts, and logs are indexed in validation-evidence.json. All 11 discussion entries are recorded in discussion-assessment.json.

Limitations:

  • The fault probes used a single local replica and injected filesystem errors.

  • Full-package race results were author-reported. The independent run was focused, and the frozen upgrade CI jobs were skipped.

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

Request changes: a transient cleanup rename error after a successful import can leave the live shard unable to compact its WAL again.

P2 — Retry canonical snapshots left behind when post-import rename fails (pkg/logservice/truncation.go:399, pkg/logservice/snapshot.go:181)

importSnapshot now advances truncatedLsn immediately after the Raft import and before snapshotMgr.Remove. If the first rename to .removing returns an I/O error, removeAt leaves the canonical snapshot in the inventory, but it does not mark any cleanup pending. On subsequent normal ticks, shouldDoImport declines that same snapshot because its index is already at the forwarded watermark, and nothing retries Remove for it. If the inventory has reached MaxExportedSnapshot, shouldDoExport also declines new exports, so later WAL cannot be compacted even after the filesystem recovers. This applies to the supported limit of 1 and also to the default limit when the inventory is full. The comment claiming a watermark-based residue purge is unreachable no longer holds for this error path.

I reproduced this against d438e90136fd using a real single-replica Raft store and a filesystem wrapper that returns EIO exactly once for the post-import rename. With MaxExportedSnapshot=1, the import advanced to index 14, then cleanup failed. After restoring the filesystem, appending more records, and running three ordinary truncation ticks, the inventory still held index 14 and the rename-attempt count was still 1. A restart is outside that observation; the demonstrated stall is in the running process.

Please make cleanup of entries at or below the successfully imported watermark retry through the ordinary tick (or record an equivalent durable/pending cleanup obligation), without re-importing an already compacted snapshot. Include a regression that injects failure before the rename, recovers storage, and verifies that subsequent ticks free the slot and can resume forward progress. Also update the stale assumption in the truncation-loop comment.

The latest revision addresses the three findings in the preceding review: invalid/post-import deletion now uses tombstones, the pinned Dragonboat returns temporary-directory removal errors, and both replica startup paths return inventory errors. I ran the corrupt-export fallback cases and the existing failed-export cleanup retry test successfully on this head, as well as the fault-injection probe above. The prior reviews' broader race evidence and current successful CI were considered; this is a focused independent run, not a full rerun of the package race suite.

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

Request changes on the latest head. The previous post-import rename failure is fixed by retrying entries at or below the import watermark; the new TestTruncationRetriesPostImportRenameFailure passes on this revision. The earlier payload-corruption, tombstone cleanup, restart, and startup error findings also remain addressed in the code I inspected. One invalid-export path still prevents the promised fallback: when the entire tracked export directory is missing, candidate validation classifies it as invalid, but eviction tries to rename that already-missing path and returns ENOENT on every tick. See the inline P2 finding and exact-head probe below.

Validation: the author's post-import rename retry test, the existing corrupt-export fallback cases, and my isolated restart probe passed on this head. A temporary exact-head probe based on the existing fallback fixture removed the whole newer snapshot directory and ran three ordinary truncation ticks; each returned ENOENT, retained both inventory entries, kept the truncation watermark at 0, and never reached the older export. The local probe is outside the PR tree. Required Ubuntu UT and other CI jobs are still pending at review time, so CI is not yet fully green.

Comment thread pkg/logservice/truncation.go Resolved

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

Reviewed the latest recovery change and the earlier snapshot export/import handling. The missing-directory case now removes an invalid candidate only after a second check confirms that its source is absent; other removal failures retain the candidate for retry. The repeated-tick regression exercises fallback to the older snapshot, and the ENOENT-while-source-exists case checks that a transient failure does not discard the candidate. I found no remaining blocker in the reviewed changes. Required CI is green on this head; for broader package and race coverage I relied on the author's reported runs and CI rather than rerunning the full suite locally.

@mergify

mergify Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request dequeued

2 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Fri 20 Nov, 17:46 · rule main · triggered by rule Automatic queue on approval for main
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 17:48 · dc777c6

Reason

Pull request #32853 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

To get back in the queue

  • Push a change if one is needed: the pull request is queued again once its queue conditions match.
  • If no change is needed, tick the box below to queue it again as it is.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

Times in UTC · dashboard · how the merge queue works

This branch was successfully deployed

No deployments
ci — dc777c66 Deployed Nov 20, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dequeued kind/bug Something isn't working size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

3 participants