mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-07 14:57:48 +02:00
* volume: return error instead of panicking when .dat open fails When backend.OpenVolumeFile returns an error (e.g. disk below -minFreeSpace), dataFile is nil. Calling backend.NewDiskFile(nil) immediately after caused a nil-pointer panic in f.Stat()/f.Name(). Move the existing error check to run right after OpenVolumeFile, before NewDiskFile is called, so the error is returned cleanly. Fixes seaweedfs/seaweedfs#11615 * volume: share .dat load error handling Extract datFileLoadError helper so open and create paths share one check. * volume: trim dat-open-fail test comments * volume(rust): cover unopenable .dat load path --------- Co-authored-by: Chris Lu <chris.lu@gmail.com>
36 lines
1.0 KiB
Go
36 lines
1.0 KiB
Go
package storage
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/super_block"
|
|
)
|
|
|
|
// A directory occupying the .dat path fails open even as root; load must
|
|
// return the error rather than crash inside backend.NewDiskFile.
|
|
func TestLoad_DatOpenFail_NoNilPanic(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
v, err := NewVolume(dir, dir, "", 1, NeedleMapInMemory, &super_block.ReplicaPlacement{}, &needle.TTL{}, 0, needle.GetCurrentVersion(), 0, 0)
|
|
if err != nil {
|
|
t.Fatalf("create volume: %v", err)
|
|
}
|
|
v.Close()
|
|
|
|
datPath := VolumeFileName(dir, "", 1) + ".dat"
|
|
if err := os.Remove(datPath); err != nil {
|
|
t.Fatalf("remove .dat: %v", err)
|
|
}
|
|
if err := os.Mkdir(datPath, 0755); err != nil {
|
|
t.Fatalf("mkdir .dat: %v", err)
|
|
}
|
|
|
|
v2, err := NewVolume(dir, dir, "", 1, NeedleMapInMemory, &super_block.ReplicaPlacement{}, &needle.TTL{}, 0, needle.GetCurrentVersion(), 0, 0)
|
|
if err == nil {
|
|
v2.Close()
|
|
t.Fatal("expected error when .dat cannot be opened, got nil")
|
|
}
|
|
}
|