mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 11:07:31 +01:00
shell: fs.verify treats a cut-short restore index as unreadable
A partial trailing record was skipped, so its key read as absent and -pruneEntries could delete an entry the source still held. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4cc4180aa6
commit
fd045baa4c
2 files changed
+32
No files matched your search
@@ -129,6 +129,12 @@ func loadRestoreIndex(idxPath string) (map[types.NeedleId]restoreNeedleLocation,
|
||||
return nil, err
|
||||
}
|
||||
defer idxFile.Close()
|
||||
// a cut-short last record would read as a key the volume never held
|
||||
if info, err := idxFile.Stat(); err != nil {
|
||||
return nil, err
|
||||
} else if info.Size()%types.NeedleMapEntrySize != 0 {
|
||||
return nil, fmt.Errorf("read %s: size %d is not a multiple of %d", idxPath, info.Size(), types.NeedleMapEntrySize)
|
||||
}
|
||||
needles := make(map[types.NeedleId]restoreNeedleLocation)
|
||||
err = idx.WalkIndexFile(idxFile, 0, func(key types.NeedleId, offset types.Offset, size types.Size) error {
|
||||
if !offset.IsZero() && size.IsValid() {
|
||||
|
||||
@@ -210,3 +210,29 @@ func TestRestoreSourceOpen(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestRestoreSourceKeepsKeysOfACutShortIndex(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
v := newTestRestoreVolume(t, filepath.Join(dir, "pics_7"))
|
||||
v.write(1, 0x11, []byte("first"), false)
|
||||
v.write(2, 0x22, []byte("second"), false)
|
||||
v.close()
|
||||
idxPath := filepath.Join(dir, "pics_7.idx")
|
||||
info, err := os.Stat(idxPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Truncate(idxPath, info.Size()-3); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
source, err := openRestoreSource(dir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer source.Close()
|
||||
_, err = source.readNeedle(7, 2, 0x22)
|
||||
if !restoreSourceMayHold(err) {
|
||||
t.Fatalf("readNeedle = %v, want a may-hold error for a key the cut record held", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user