mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 19:17:28 +01:00
fix: exit non-zero when a record is cut off by the end of the .dat
A record past EOF ends the scan like a bad header does, so report it the same way while keeping the index of the records before it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8ca0c781c0
commit
13a68d93a2
2 files changed
+11
-2
No files matched your search
+3
-2
@@ -33,7 +33,7 @@ var cmdFix = &Command{
|
||||
Long: `Fix runs the SeaweedFS fix command on local dat files ( or remote files) or whole folders to re-create the index .idx file. If fixing remote files, you need to synchronize master.toml to the same directory on the current node as on the master node.
|
||||
You Need to stop the volume server when running this command.
|
||||
Use -ecx to rebuild a lost EC index (.ecx) — and the .vif when missing — from the local .ec## shards.
|
||||
On a damaged .dat, fix indexes only the needles before the first unreadable header; repair from a replica, or run fix on a copy, before compacting or loading the volume.
|
||||
On a damaged .dat, fix indexes only the needles before the first unreadable header or a record cut off by the end of the file, and exits non-zero; repair from a replica, or run fix on a copy, before compacting or loading the volume.
|
||||
With -ignoreError, fix keeps going and writes what it could index, but still exits non-zero if any volume failed.
|
||||
`,
|
||||
}
|
||||
@@ -70,7 +70,8 @@ func (scanner *VolumeFileScanner4Fix) ReadNeedleBody() bool {
|
||||
func (scanner *VolumeFileScanner4Fix) VisitNeedle(n *needle.Needle, offset int64, needleHeader, needleBody []byte) error {
|
||||
glog.V(2).Infof("key %v offset %d size %d disk_size %d compressed %v", n.Id, offset, n.Size, n.DiskSize(scanner.version), n.IsCompressed())
|
||||
if scanner.datSize > 0 && offset+n.DiskSize(scanner.version) > scanner.datSize {
|
||||
glog.Warningf("needle %v at offset %d needs %d bytes but the .dat ends at %d; not indexing it", n.Id, offset, n.DiskSize(scanner.version), scanner.datSize)
|
||||
glog.Errorf("needle %v at offset %d needs %d bytes but the .dat ends at %d; not indexing it", n.Id, offset, n.DiskSize(scanner.version), scanner.datSize)
|
||||
SetCommandExitStatus(1)
|
||||
// The key was rewritten or deleted here, so an older record must not become current again.
|
||||
if pe := scanner.nm.Delete(n.Id); pe != nil {
|
||||
return fmt.Errorf("delete %v with error %v", n.Id, pe)
|
||||
|
||||
@@ -140,6 +140,8 @@ func overwriteAt(t *testing.T, path string, offset int64, b []byte) {
|
||||
}
|
||||
|
||||
func TestFixSkipsRecordPastEndOfDat(t *testing.T) {
|
||||
savedStatus := commandExitStatus
|
||||
defer func() { commandExitStatus = savedStatus }()
|
||||
sizeAt := types.NeedleIdSize + types.CookieSize
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
@@ -158,7 +160,11 @@ func TestFixSkipsRecordPastEndOfDat(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
base, offsets := writeFixTestVolume(t, dir, 5)
|
||||
tc.corrupt(t, base+".dat", offsets[4])
|
||||
commandExitStatus = 0
|
||||
doFixOneVolume(dir, "fix_7", "fix", 7, true)
|
||||
if CommandExitStatus() == 0 {
|
||||
t.Error("expected a non-zero exit status")
|
||||
}
|
||||
if got := indexedKeys(t, base+".idx"); !slices.Equal(got, []uint64{1, 2, 3, 4}) {
|
||||
t.Errorf("indexed keys %v, want [1 2 3 4]", got)
|
||||
}
|
||||
@@ -223,6 +229,8 @@ func TestLocalDatSizeIgnoresRemoteTier(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFixTruncatedDeleteKeepsKeyDeleted(t *testing.T) {
|
||||
savedStatus := commandExitStatus
|
||||
defer func() { commandExitStatus = savedStatus }()
|
||||
dir := t.TempDir()
|
||||
base, _ := writeFixTestVolume(t, dir, 3)
|
||||
f, err := os.OpenFile(base+".dat", os.O_RDWR, 0644)
|
||||
|
||||
Reference in new issue
Block a user