mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
fix: skip the end-of-file check for a volume on a remote tier
The scan reads the remote object when the .vif lists one, so a retained local .dat is the wrong length to check records against. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c57f58959d
commit
8bc6044232
2 files changed
+34
-3
No files matched your search
+13
-3
@@ -229,6 +229,18 @@ func SaveToIdx(scaner *VolumeFileScanner4Fix, idxName string) (ret error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// localDatSize is the length of the .dat the scan reads, or 0 when the volume
|
||||
// is read from a remote tier.
|
||||
func localDatSize(basepath, baseFileName string) int64 {
|
||||
if _, hasRemoteFile, _, _ := volume_info.MaybeLoadVolumeInfo(path.Join(basepath, baseFileName+".vif")); hasRemoteFile {
|
||||
return 0
|
||||
}
|
||||
if info, err := os.Stat(path.Join(basepath, baseFileName+".dat")); err == nil {
|
||||
return info.Size()
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func doFixOneVolume(basepath string, baseFileName string, collection string, volumeId int64, fixIncludeDeleted bool) {
|
||||
indexFileName := path.Join(basepath, baseFileName+".idx")
|
||||
|
||||
@@ -256,9 +268,7 @@ func doFixOneVolume(basepath string, baseFileName string, collection string, vol
|
||||
nmDeleted: nmDeleted,
|
||||
includeDeleted: fixIncludeDeleted,
|
||||
}
|
||||
if info, err := os.Stat(path.Join(basepath, baseFileName+".dat")); err == nil {
|
||||
scanner.datSize = info.Size()
|
||||
}
|
||||
scanner.datSize = localDatSize(basepath, baseFileName)
|
||||
|
||||
if err := storage.ScanVolumeFile(basepath, collection, vid, storage.NeedleMapInMemory, scanner); err != nil {
|
||||
err := fmt.Errorf("scan .dat File: %w", err)
|
||||
|
||||
@@ -7,12 +7,14 @@ import (
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/storage/backend"
|
||||
"github.com/seaweedfs/seaweedfs/weed/storage/idx"
|
||||
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
||||
"github.com/seaweedfs/seaweedfs/weed/storage/needle_map"
|
||||
"github.com/seaweedfs/seaweedfs/weed/storage/super_block"
|
||||
"github.com/seaweedfs/seaweedfs/weed/storage/types"
|
||||
"github.com/seaweedfs/seaweedfs/weed/storage/volume_info"
|
||||
)
|
||||
|
||||
// TestSaveToIdxWritesOffsetOrder guards that weed fix rebuilds the .idx as an
|
||||
@@ -200,3 +202,22 @@ func TestFixIgnoreErrorReportsIncompleteScan(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestLocalDatSizeIgnoresRemoteTier(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
base, _ := writeFixTestVolume(t, dir, 2)
|
||||
info, err := os.Stat(base + ".dat")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := localDatSize(dir, "fix_7"); got != info.Size() {
|
||||
t.Fatalf("localDatSize = %d, want %d", got, info.Size())
|
||||
}
|
||||
vi := &volume_server_pb.VolumeInfo{Files: []*volume_server_pb.RemoteFile{{BackendType: "s3", Key: "fix_7.dat", FileSize: uint64(info.Size()) * 2}}}
|
||||
if err := volume_info.SaveVolumeInfo(base+".vif", vi); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := localDatSize(dir, "fix_7"); got != 0 {
|
||||
t.Errorf("localDatSize with a remote .dat = %d, want 0", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user