diff options
| author | guol-fnst <goul-fnst@fujitsu.com> | 2022-05-16 10:41:18 +0800 |
|---|---|---|
| committer | guol-fnst <goul-fnst@fujitsu.com> | 2022-05-16 19:33:51 +0800 |
| commit | de6aa9cce81cb2214e7b7f3dd1a3c9383d054779 (patch) | |
| tree | 0451da338c468cc8565c5ec433070a6879e99efe /weed/storage/disk_location.go | |
| parent | 8f103ae613fb4752e7ec41394e155e8ad4c06826 (diff) | |
| download | seaweedfs-de6aa9cce81cb2214e7b7f3dd1a3c9383d054779.tar.xz seaweedfs-de6aa9cce81cb2214e7b7f3dd1a3c9383d054779.zip | |
avoid duplicated volume directory
Diffstat (limited to 'weed/storage/disk_location.go')
| -rw-r--r-- | weed/storage/disk_location.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/weed/storage/disk_location.go b/weed/storage/disk_location.go index e92810022..ae2a36296 100644 --- a/weed/storage/disk_location.go +++ b/weed/storage/disk_location.go @@ -14,6 +14,7 @@ import ( "github.com/chrislusf/seaweedfs/weed/storage/needle" "github.com/chrislusf/seaweedfs/weed/storage/types" "github.com/chrislusf/seaweedfs/weed/util" + "github.com/google/uuid" ) type DiskLocation struct { @@ -33,6 +34,29 @@ type DiskLocation struct { isDiskSpaceLow bool } +func GenerateDirUUID(dir string) (dirUUIDString string, err error) { + glog.V(1).Infof("Getting UUID of volume directory:%s", dir) + dirUUIDString = "" + fileName := dir + "/volume.uuid" + if !util.FileExists(fileName) { + dirUUID, _ := uuid.NewRandom() + dirUUIDString = dirUUID.String() + writeErr := util.WriteFile(fileName, []byte(dirUUIDString), 0644) + if writeErr != nil { + glog.Warningf("failed to write UUID to %s : %v", fileName, writeErr) + return "", fmt.Errorf("failed to write UUID to %s : %v", fileName, writeErr) + } + } else { + uuidData, readErr := os.ReadFile(fileName) + if readErr != nil { + glog.Warningf("failed to read UUID from %s : %v", fileName, readErr) + return "", fmt.Errorf("failed to read UUID from %s : %v", fileName, readErr) + } + dirUUIDString = string(uuidData) + } + return dirUUIDString, nil +} + func NewDiskLocation(dir string, maxVolumeCount int, minFreeSpace util.MinFreeSpace, idxDir string, diskType types.DiskType) *DiskLocation { dir = util.ResolvePath(dir) if idxDir == "" { |
