mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
clone volume locations in case they are changed
fix https://github.com/seaweedfs/seaweedfs/issues/4642
This commit is contained in:
parent
a315490f7d
commit
31b2751aff
|
@ -98,7 +98,7 @@ func doEcEncode(commandEnv *CommandEnv, collection string, vid needle.VolumeId,
|
||||||
}
|
}
|
||||||
|
|
||||||
// find volume location
|
// find volume location
|
||||||
locations, found := commandEnv.MasterClient.GetLocations(uint32(vid))
|
locations, found := commandEnv.MasterClient.GetLocationsClone(uint32(vid))
|
||||||
if !found {
|
if !found {
|
||||||
return fmt.Errorf("volume %d not found", vid)
|
return fmt.Errorf("volume %d not found", vid)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
func doVolumeTierDownload(commandEnv *CommandEnv, writer io.Writer, collection string, vid needle.VolumeId) (err error) {
|
||||||
// find volume location
|
// find volume location
|
||||||
locations, found := commandEnv.MasterClient.GetLocations(uint32(vid))
|
locations, found := commandEnv.MasterClient.GetLocationsClone(uint32(vid))
|
||||||
if !found {
|
if !found {
|
||||||
return fmt.Errorf("volume %d not found", vid)
|
return fmt.Errorf("volume %d not found", vid)
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,7 @@ func (c *commandVolumeTierMove) Do(args []string, commandEnv *CommandEnv, writer
|
||||||
for job := range jobs {
|
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())
|
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 {
|
if !found {
|
||||||
fmt.Printf("volume %d not found", job.vid)
|
fmt.Printf("volume %d not found", job.vid)
|
||||||
continue
|
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) {
|
func (c *commandVolumeTierMove) doVolumeTierMove(commandEnv *CommandEnv, writer io.Writer, vid needle.VolumeId, toDiskType types.DiskType, allLocations []location) (err error) {
|
||||||
// find volume location
|
// find volume location
|
||||||
locations, found := commandEnv.MasterClient.GetLocations(uint32(vid))
|
locations, found := commandEnv.MasterClient.GetLocationsClone(uint32(vid))
|
||||||
if !found {
|
if !found {
|
||||||
return fmt.Errorf("volume %d not found", vid)
|
return fmt.Errorf("volume %d not found", vid)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
func doVolumeTierUpload(commandEnv *CommandEnv, writer io.Writer, collection string, vid needle.VolumeId, dest string, keepLocalDatFile bool) (err error) {
|
||||||
// find volume location
|
// find volume location
|
||||||
existingLocations, found := commandEnv.MasterClient.GetLocations(uint32(vid))
|
existingLocations, found := commandEnv.MasterClient.GetLocationsClone(uint32(vid))
|
||||||
if !found {
|
if !found {
|
||||||
return fmt.Errorf("volume %d not found", vid)
|
return fmt.Errorf("volume %d not found", vid)
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,6 +141,19 @@ func (vc *vidMap) GetLocations(vid uint32) (locations []Location, found bool) {
|
||||||
return nil, false
|
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) {
|
func (vc *vidMap) getLocations(vid uint32) (locations []Location, found bool) {
|
||||||
vc.RLock()
|
vc.RLock()
|
||||||
defer vc.RUnlock()
|
defer vc.RUnlock()
|
||||||
|
|
Loading…
Reference in a new issue