Repository navigation
Conversation
Signed-off-by: PerryLink <255665900+PerryLink@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
FileStorage.obtainLock()refuses to work when the lock file exists but cannot be JSON-decoded —and that refusal happens before the stale-lock check:
A lock file left truncated or zero-filled by a crash during refresh therefore becomes permanent: every
node fails to acquire the lock for that key forever, and only a manual delete recovers it.
Measured on local NTFS with a hand-written corrupt file and the public API:
Three consecutive
Lock()attempts fail with identical errors and the file keeps the same size andmtime, so no amount of retrying helps.
The change
Treat an undecodable lock file the same way the code already treats an empty one (the policy merged
in #232): retry a few times, then consider it stale and remove it.
io.EOFkeeps the existing"Empty lockfile" log; other decode errors get "Unreadable lockfile"; the partially decoded metadata is
zeroed so a corrupt file cannot look fresh.
This follows the file's own design note (
filestorage.go:56-64): imperfect mutual exclusion ispreferable to a permanent loop.
Verification
New table test with three corrupt variants, run in parallel:
-count=3passes too;go test -count=1 ./...passes;gofmt/go vetclean;git apply --checkon a pristinemaster.Open PR #337 changes how lock files are written (write+rename) and is orthogonal — this patch is about
recovering from a file that is already corrupt on disk.
Commits are signed off, as
CONTRIBUTING.mdasks.