mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 11:07:31 +01:00
shell: fs.verify -restoreFrom loads a volume's index on its first lookup
Pointed at a data directory, the restore source read every .idx into memory before verification began, though missing chunks usually name few of those volumes, and one unreadable .idx stopped the whole run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cec02fbf0e
commit
9d0c5ffe6a
2 files changed
+41
-7
No files matched your search
@@ -25,12 +25,16 @@ type restoreSource struct {
|
||||
volumes map[needle.VolumeId]*restoreVolume
|
||||
}
|
||||
|
||||
// restoreVolume loads its .idx on the first lookup: a directory of many
|
||||
// volumes usually holds few that missing chunks name.
|
||||
type restoreVolume struct {
|
||||
collection string
|
||||
idxPath string
|
||||
datPath string
|
||||
dat backend.BackendStorageFile
|
||||
version needle.Version
|
||||
needles map[types.NeedleId]restoreNeedleLocation
|
||||
indexErr error
|
||||
}
|
||||
|
||||
type restoreNeedleLocation struct {
|
||||
@@ -88,10 +92,6 @@ func openRestoreVolume(base string) (*restoreVolume, error) {
|
||||
if info.BytesOffset != 0 && info.BytesOffset != types.OffsetSize {
|
||||
return nil, fmt.Errorf("%s.vif records %d-byte offsets, this binary reads %d-byte offsets", base, info.BytesOffset, types.OffsetSize)
|
||||
}
|
||||
needles, err := loadRestoreIndex(base + ".idx")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
datFile, err := os.Open(base + ".dat")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -106,7 +106,7 @@ func openRestoreVolume(base string) (*restoreVolume, error) {
|
||||
dat.Close()
|
||||
return nil, fmt.Errorf("%s.dat has unsupported needle version %d", base, superBlock.Version)
|
||||
}
|
||||
return &restoreVolume{datPath: base + ".dat", dat: dat, version: superBlock.Version, needles: needles}, nil
|
||||
return &restoreVolume{idxPath: base + ".idx", datPath: base + ".dat", dat: dat, version: superBlock.Version}, nil
|
||||
}
|
||||
|
||||
// loadRestoreIndex maps each key to its last live record. A later tombstone
|
||||
@@ -144,6 +144,12 @@ func (s *restoreSource) readNeedle(vid needle.VolumeId, key types.NeedleId, cook
|
||||
if !found {
|
||||
return nil, errNotInRestoreSource
|
||||
}
|
||||
if v.needles == nil && v.indexErr == nil {
|
||||
v.needles, v.indexErr = loadRestoreIndex(v.idxPath)
|
||||
}
|
||||
if v.indexErr != nil {
|
||||
return nil, v.indexErr
|
||||
}
|
||||
loc, found := v.needles[key]
|
||||
if !found {
|
||||
return nil, errNotInRestoreSource
|
||||
|
||||
@@ -91,8 +91,8 @@ func TestRestoreSourceReadsLastLiveRecord(t *testing.T) {
|
||||
if volume == nil || volume.collection != "pics" {
|
||||
t.Fatalf("volume 7 = %+v, want collection pics", volume)
|
||||
}
|
||||
if len(volume.needles) != 4 {
|
||||
t.Errorf("indexed %d needles, want 4", len(volume.needles))
|
||||
if volume.needles != nil {
|
||||
t.Errorf("index loaded before the first lookup")
|
||||
}
|
||||
|
||||
for _, c := range []struct {
|
||||
@@ -115,6 +115,10 @@ func TestRestoreSourceReadsLastLiveRecord(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
if len(volume.needles) != 4 {
|
||||
t.Errorf("indexed %d needles, want 4", len(volume.needles))
|
||||
}
|
||||
|
||||
// the earlier record of key 2 carried another cookie
|
||||
if _, err := source.readNeedle(7, 2, 0x22); err == nil || !strings.Contains(err.Error(), "cookie") {
|
||||
t.Errorf("stale cookie: got %v, want a cookie mismatch", err)
|
||||
@@ -171,6 +175,30 @@ func TestRestoreSourceOpen(t *testing.T) {
|
||||
t.Fatalf("got %v, want a duplicate volume error", err)
|
||||
}
|
||||
})
|
||||
t.Run("unreadable idx fails only its own lookups", func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
v := newTestRestoreVolume(t, filepath.Join(dir, "7"))
|
||||
v.write(1, 0x11, []byte("kept"), false)
|
||||
v.close()
|
||||
newTestRestoreVolume(t, filepath.Join(dir, "8")).close()
|
||||
if err := os.Remove(filepath.Join(dir, "8.idx")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Mkdir(filepath.Join(dir, "8.idx"), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
source, err := openRestoreSource(dir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer source.Close()
|
||||
if _, err := source.readNeedle(7, 1, 0x11); err != nil {
|
||||
t.Errorf("volume 7: %v", err)
|
||||
}
|
||||
if _, err := source.readNeedle(8, 1, 0x11); err == nil || errors.Is(err, errNotInRestoreSource) {
|
||||
t.Errorf("volume 8: got %v, want the index read error", err)
|
||||
}
|
||||
})
|
||||
t.Run("idx without dat", func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
newTestRestoreVolume(t, filepath.Join(dir, "7")).close()
|
||||
|
||||
Reference in new issue
Block a user