Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

clone volume locations in case they are changed

chrislu31b2751affd2
diff --git a/weed/shell/command_ec_encode.go b/weed/shell/command_ec_encode.go
index d5a344e3ae..9fe7ad8e49 100644
--- a/weed/shell/command_ec_encode.go
+++ b/weed/shell/command_ec_encode.go
@@ -98,7 +98,7 @@ func doEcEncode(commandEnv *CommandEnv, collection string, vid needle.VolumeId,
}
// find volume location
- locations, found := commandEnv.MasterClient.GetLocations(uint32(vid))
+ locations, found := commandEnv.MasterClient.GetLocationsClone(uint32(vid))
if !found {
return fmt.Errorf("volume %d not found", vid)
}
diff --git a/weed/shell/command_volume_tier_download.go b/weed/shell/command_volume_tier_download.go
index bccbe8ccd7..0dc34c071c 100644
--- a/weed/shell/command_volume_tier_download.go
+++ b/weed/shell/command_volume_tier_download.go
@@ -105,7 +105,7 @@ func collectRemoteVolumes(topoInfo *master_pb.TopologyInfo, selectedCollection s
func doVolumeTierDownload(commandEnv *CommandEnv, writer io.Writer, collection string, vid needle.VolumeId) (err error) {
// find volume location
- locations, found := commandEnv.MasterClient.GetLocations(uint32(vid))
+ locations, found := commandEnv.MasterClient.GetLocationsClone(uint32(vid))
if !found {
return fmt.Errorf("volume %d not found", vid)
}
diff --git a/weed/shell/command_volume_tier_move.go b/weed/shell/command_volume_tier_move.go
index 90fef27c03..bf41c2ea07 100644
--- a/weed/shell/command_volume_tier_move.go
+++ b/weed/shell/command_volume_tier_move.go
@@ -116,7 +116,7 @@ func (c *commandVolumeTierMove) Do(args []string, commandEnv *CommandEnv, writer
for job := range jobs {
fmt.Fprintf(writer, "moving volume %d from %s to %s with disk type %s ...\n", job.vid, job.src, dst.dataNode.Id, toDiskType.ReadableString())
- locations, found := commandEnv.MasterClient.GetLocations(uint32(job.vid))
+ locations, found := commandEnv.MasterClient.GetLocationsClone(uint32(job.vid))
if !found {
fmt.Printf("volume %d not found", job.vid)
continue
@@ -186,7 +186,7 @@ func isOneOf(server string, locations []wdclient.Location) bool {
func (c *commandVolumeTierMove) doVolumeTierMove(commandEnv *CommandEnv, writer io.Writer, vid needle.VolumeId, toDiskType types.DiskType, allLocations []location) (err error) {
// find volume location
- locations, found := commandEnv.MasterClient.GetLocations(uint32(vid))
+ locations, found := commandEnv.MasterClient.GetLocationsClone(uint32(vid))
if !found {
return fmt.Errorf("volume %d not found", vid)
}
diff --git a/weed/shell/command_volume_tier_upload.go b/weed/shell/command_volume_tier_upload.go
index a8221bbe94..c109d59d8e 100644
--- a/weed/shell/command_volume_tier_upload.go
+++ b/weed/shell/command_volume_tier_upload.go
@@ -97,7 +97,7 @@ func (c *commandVolumeTierUpload) Do(args []string, commandEnv *CommandEnv, writ
func doVolumeTierUpload(commandEnv *CommandEnv, writer io.Writer, collection string, vid needle.VolumeId, dest string, keepLocalDatFile bool) (err error) {
// find volume location
- existingLocations, found := commandEnv.MasterClient.GetLocations(uint32(vid))
+ existingLocations, found := commandEnv.MasterClient.GetLocationsClone(uint32(vid))
if !found {
return fmt.Errorf("volume %d not found", vid)
}
diff --git a/weed/wdclient/vid_map.go b/weed/wdclient/vid_map.go
index 5c3d167db7..7a2a5bb923 100644
--- a/weed/wdclient/vid_map.go
+++ b/weed/wdclient/vid_map.go
@@ -141,6 +141,19 @@ func (vc *vidMap) GetLocations(vid uint32) (locations []Location, found bool) {
return nil, false
}
+func (vc *vidMap) GetLocationsClone(vid uint32) (locations []Location, found bool) {
+ locations, found = vc.GetLocations(vid)
+
+ if found {
+ // clone the locations in case the volume locations are changed below
+ existingLocations := make([]Location, len(locations))
+ copy(existingLocations, locations)
+ return existingLocations, found
+ }
+
+ return nil, false
+}
+
func (vc *vidMap) getLocations(vid uint32) (locations []Location, found bool) {
vc.RLock()
defer vc.RUnlock()