Skip to content

fix: validate exported snapshot images without panicking - #22

Merged
volgariver6 merged 1 commit into
matrixorigin:masterfrom
jiangxinmeng1:codex/safe-exported-snapshot-validation
Nov 17, 2026
Merged

volgariver6 merged 1 commit into
matrixorigin:masterfrom
jiangxinmeng1:codex/safe-exported-snapshot-validation

Conversation

@jiangxinmeng1

Copy link
Copy Markdown

Summary

Return tools.ErrIncompleteSnapshot for malformed exported snapshot metadata and V2 image headers, instead of panicking while a caller checks an exported snapshot. Preserve filesystem I/O errors so callers can retry them. Internal flag-file readers retain their existing fail-stop behavior.

This supports the recovery path in matrixorigin/matrixone#32853 for matrixorigin/matrixone#32842: when the newest exported candidate is permanently damaged, LogService can discard it and import an older valid candidate. The earlier export-worker error fix is in #21.

Validation

  • go test -count=1 -timeout=180s ./internal/fileutil ./internal/rsm ./tools
  • go test -race -count=10 -timeout=120s -run '^Test(GetSnapshotRecordRejectsDamagedMetadataWithoutPanic|IncompleteSnapshotImageReportsCorruptionWithoutPanic|V2PayloadChecksumRejectsMalformedHeaderWithoutLeaking)$' ./tools ./internal/rsm
  • NodeHost export/import regressions, including the commit EIO retry test
  • go vet ./internal/fileutil ./internal/rsm ./tools

Read exported metadata through a non-panicking flag parser and validate V2 image headers before calculating their checksum. Report corrupt exports as incomplete while preserving ordinary I/O errors for retry; keep internal flag-file readers fail-stop.
@volgariver6
volgariver6 merged commit 03ee395 into matrixorigin:master Nov 17, 2026
XuPeng-SH pushed a commit to matrixorigin/matrixone that referenced this pull request Nov 20, 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:

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](matrixorigin/dragonboat#21) and
[#22](matrixorigin/dragonboat#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](matrixorigin/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 #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.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
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.

2 participants