1
0
Fork 0
mirror of https://github.com/chrislusf/seaweedfs synced 2024-05-24 04:10:40 +02:00

clone volume locations in case they are changed

fix https://github.com/seaweedfs/seaweedfs/issues/4642
This commit is contained in:
chrislu 2023-07-06 00:32:58 -07:00
parent a315490f7d
commit 31b2751aff
5 changed files with 18 additions and 5 deletions

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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()