fix command_volume_tier_upload bug (#7041)
* fix command_volume_tier_upload bug: Avoid deleting volumes under the same collection * simplify a bit --------- Co-authored-by: hzxialei <hzxialei@corp.netease.com> Co-authored-by: chrislu <chris.lu@gmail.com>
This commit is contained in:
@@ -4,17 +4,21 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/storage/types"
|
|
||||||
"io"
|
"io"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/storage/types"
|
||||||
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/pb"
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/operation"
|
"github.com/seaweedfs/seaweedfs/weed/operation"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
||||||
|
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/wdclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -110,9 +114,33 @@ 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.GetLocationsClone(uint32(vid))
|
topoInfo, _, err := collectTopologyInfo(commandEnv, 0)
|
||||||
if !found {
|
if err != nil {
|
||||||
return fmt.Errorf("volume %d not found", vid)
|
return fmt.Errorf("collect topology info: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var existingLocations []wdclient.Location
|
||||||
|
eachDataNode(topoInfo, func(dc DataCenterId, rack RackId, dn *master_pb.DataNodeInfo) {
|
||||||
|
for _, disk := range dn.DiskInfos {
|
||||||
|
for _, vi := range disk.VolumeInfos {
|
||||||
|
if needle.VolumeId(vi.Id) == vid && (collection == "" || vi.Collection == collection) {
|
||||||
|
fmt.Printf("find volume %d from Url:%s, GrpcPort:%d, DC:%s\n", vid, dn.Id, dn.GrpcPort, string(dc))
|
||||||
|
existingLocations = append(existingLocations, wdclient.Location{
|
||||||
|
Url: dn.Id,
|
||||||
|
PublicUrl: dn.Id,
|
||||||
|
GrpcPort: int(dn.GrpcPort),
|
||||||
|
DataCenter: string(dc),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if len(existingLocations) == 0 {
|
||||||
|
if collection == "" {
|
||||||
|
return fmt.Errorf("volume %d not found", vid)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("volume %d not found in collection %s", vid, collection)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = markVolumeReplicasWritable(commandEnv.option.GrpcDialOption, vid, existingLocations, false, false)
|
err = markVolumeReplicasWritable(commandEnv.option.GrpcDialOption, vid, existingLocations, false, false)
|
||||||
@@ -135,7 +163,7 @@ func doVolumeTierUpload(commandEnv *CommandEnv, writer io.Writer, collection str
|
|||||||
if i == 0 {
|
if i == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Printf("delete volume %d from %s\n", vid, location.Url)
|
fmt.Printf("delete volume %d from Url:%s\n", vid, location.Url)
|
||||||
err = deleteVolume(commandEnv.option.GrpcDialOption, vid, location.ServerAddress(), false)
|
err = deleteVolume(commandEnv.option.GrpcDialOption, vid, location.ServerAddress(), false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("deleteVolume %s volume %d: %v", location.Url, vid, err)
|
return fmt.Errorf("deleteVolume %s volume %d: %v", location.Url, vid, err)
|
||||||
|
|||||||
Reference in New Issue
Block a user