Browse Source

Support concurrenct volume.configure.replication

pull/5632/head
Misty 8 months ago
parent
commit
f524d0801e
  1. 20
      weed/shell/command_volume_configure_replication.go

20
weed/shell/command_volume_configure_replication.go

@ -6,6 +6,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"github.com/seaweedfs/seaweedfs/weed/pb" "github.com/seaweedfs/seaweedfs/weed/pb"
"golang.org/x/sync/errgroup"
"io" "io"
"path/filepath" "path/filepath"
@ -35,7 +36,7 @@ func (c *commandVolumeConfigureReplication) Help() string {
` `
} }
func (c *commandVolumeConfigureReplication) Do(args []string, commandEnv *CommandEnv, _ io.Writer) (err error) {
func (c *commandVolumeConfigureReplication) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
configureReplicationCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError) configureReplicationCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
volumeIdInt := configureReplicationCommand.Int("volumeId", 0, "the volume id") volumeIdInt := configureReplicationCommand.Int("volumeId", 0, "the volume id")
@ -67,8 +68,11 @@ func (c *commandVolumeConfigureReplication) Do(args []string, commandEnv *Comman
vid := needle.VolumeId(*volumeIdInt) vid := needle.VolumeId(*volumeIdInt)
volumeFilter := getVolumeFilter(replicaPlacement, uint32(vid), *collectionPattern) volumeFilter := getVolumeFilter(replicaPlacement, uint32(vid), *collectionPattern)
eg, gCtx := errgroup.WithContext(context.Background())
_ = gCtx
// find all data nodes with volumes that needs replication change // find all data nodes with volumes that needs replication change
eachDataNode(topologyInfo, func(dc string, rack RackId, dn *master_pb.DataNodeInfo) { eachDataNode(topologyInfo, func(dc string, rack RackId, dn *master_pb.DataNodeInfo) {
eg.Go(func() error {
var targetVolumeIds []uint32 var targetVolumeIds []uint32
for _, diskInfo := range dn.DiskInfos { for _, diskInfo := range dn.DiskInfos {
for _, v := range diskInfo.VolumeInfos { for _, v := range diskInfo.VolumeInfos {
@ -78,10 +82,14 @@ func (c *commandVolumeConfigureReplication) Do(args []string, commandEnv *Comman
} }
} }
if len(targetVolumeIds) == 0 { if len(targetVolumeIds) == 0 {
return
return nil
} }
fmt.Fprintf(writer, "volume server %s has %d volumes\n", dn.Id, len(targetVolumeIds))
err = operation.WithVolumeServerClient(false, pb.NewServerAddressFromDataNode(dn), commandEnv.option.GrpcDialOption, func(volumeServerClient volume_server_pb.VolumeServerClient) error { err = operation.WithVolumeServerClient(false, pb.NewServerAddressFromDataNode(dn), commandEnv.option.GrpcDialOption, func(volumeServerClient volume_server_pb.VolumeServerClient) error {
for _, targetVolumeId := range targetVolumeIds {
for i, targetVolumeId := range targetVolumeIds {
if i%100 == 0 {
fmt.Fprintf(writer, "volume marking progress on %s: %.2f (%d/%d)\n", dn.Id, float32(i)/float32(len(targetVolumeIds))*100, i, len(targetVolumeIds))
}
resp, configureErr := volumeServerClient.VolumeConfigure(context.Background(), &volume_server_pb.VolumeConfigureRequest{ resp, configureErr := volumeServerClient.VolumeConfigure(context.Background(), &volume_server_pb.VolumeConfigureRequest{
VolumeId: targetVolumeId, VolumeId: targetVolumeId,
Replication: replicaPlacement.String(), Replication: replicaPlacement.String(),
@ -96,9 +104,13 @@ func (c *commandVolumeConfigureReplication) Do(args []string, commandEnv *Comman
return nil return nil
}) })
if err != nil { if err != nil {
return
return err
} }
return nil
}) })
})
err = eg.Wait()
return err return err
} }

Loading…
Cancel
Save