From c387fe957b1be5342e2188bf258c440815fb98d0 Mon Sep 17 00:00:00 2001 From: user Date: Thu, 11 Nov 2021 16:08:41 +0900 Subject: [PATCH 1/4] Unused parameter removed. --- weed/shell/command_volume_configure_replication.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weed/shell/command_volume_configure_replication.go b/weed/shell/command_volume_configure_replication.go index 5640e58bb..00eab2c85 100644 --- a/weed/shell/command_volume_configure_replication.go +++ b/weed/shell/command_volume_configure_replication.go @@ -34,7 +34,7 @@ func (c *commandVolumeConfigureReplication) Help() string { ` } -func (c *commandVolumeConfigureReplication) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { +func (c *commandVolumeConfigureReplication) Do(args []string, commandEnv *CommandEnv, _ io.Writer) (err error) { configureReplicationCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError) volumeIdInt := configureReplicationCommand.Int("volumeId", 0, "the volume id") From dbb8003ce3cb0891eb78c117ad1e7d64dc7f5e4d Mon Sep 17 00:00:00 2001 From: user Date: Thu, 11 Nov 2021 17:36:26 +0900 Subject: [PATCH 2/4] Volume filter function added. --- weed/shell/command_volume_configure_replication.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/weed/shell/command_volume_configure_replication.go b/weed/shell/command_volume_configure_replication.go index 00eab2c85..591e88b45 100644 --- a/weed/shell/command_volume_configure_replication.go +++ b/weed/shell/command_volume_configure_replication.go @@ -55,7 +55,6 @@ func (c *commandVolumeConfigureReplication) Do(args []string, commandEnv *Comman if err != nil { return fmt.Errorf("replication format: %v", err) } - replicaPlacementInt32 := uint32(replicaPlacement.Byte()) // collect topology information topologyInfo, _, err := collectTopologyInfo(commandEnv) @@ -64,6 +63,7 @@ func (c *commandVolumeConfigureReplication) Do(args []string, commandEnv *Comman } vid := needle.VolumeId(*volumeIdInt) + volumeFilter := getVolumeFilter(replicaPlacement, uint32(vid)) // find all data nodes with volumes that needs replication change var allLocations []location @@ -71,7 +71,7 @@ func (c *commandVolumeConfigureReplication) Do(args []string, commandEnv *Comman loc := newLocation(dc, string(rack), dn) for _, diskInfo := range dn.DiskInfos { for _, v := range diskInfo.VolumeInfos { - if v.Id == uint32(vid) && v.ReplicaPlacement != replicaPlacementInt32 { + if volumeFilter(v) { allLocations = append(allLocations, loc) continue } @@ -106,3 +106,10 @@ func (c *commandVolumeConfigureReplication) Do(args []string, commandEnv *Comman return nil } + +func getVolumeFilter(replicaPlacement *super_block.ReplicaPlacement, volumeId uint32) func(message *master_pb.VolumeInformationMessage) bool { + replicaPlacementInt32 := uint32(replicaPlacement.Byte()) + return func(v *master_pb.VolumeInformationMessage) bool { + return v.Id == volumeId && v.ReplicaPlacement != replicaPlacementInt32 + } +} From 563a74a9eb050730ee16e3510ca95d0c36d13fdb Mon Sep 17 00:00:00 2001 From: user Date: Thu, 11 Nov 2021 18:01:47 +0900 Subject: [PATCH 3/4] Volume filter by collection pattern added. --- .../shell/command_volume_configure_replication.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/weed/shell/command_volume_configure_replication.go b/weed/shell/command_volume_configure_replication.go index 591e88b45..fe4eab22a 100644 --- a/weed/shell/command_volume_configure_replication.go +++ b/weed/shell/command_volume_configure_replication.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/chrislusf/seaweedfs/weed/pb" "io" + "path/filepath" "github.com/chrislusf/seaweedfs/weed/operation" "github.com/chrislusf/seaweedfs/weed/pb/master_pb" @@ -39,6 +40,7 @@ func (c *commandVolumeConfigureReplication) Do(args []string, commandEnv *Comman configureReplicationCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError) volumeIdInt := configureReplicationCommand.Int("volumeId", 0, "the volume id") replicationString := configureReplicationCommand.String("replication", "", "the intended replication value") + collectionPattern := configureReplicationCommand.String("collectionPattern", "", "match with wildcard characters '*' and '?'") if err = configureReplicationCommand.Parse(args); err != nil { return nil } @@ -63,7 +65,7 @@ func (c *commandVolumeConfigureReplication) Do(args []string, commandEnv *Comman } vid := needle.VolumeId(*volumeIdInt) - volumeFilter := getVolumeFilter(replicaPlacement, uint32(vid)) + volumeFilter := getVolumeFilter(replicaPlacement, uint32(vid), *collectionPattern) // find all data nodes with volumes that needs replication change var allLocations []location @@ -107,8 +109,17 @@ func (c *commandVolumeConfigureReplication) Do(args []string, commandEnv *Comman return nil } -func getVolumeFilter(replicaPlacement *super_block.ReplicaPlacement, volumeId uint32) func(message *master_pb.VolumeInformationMessage) bool { +func getVolumeFilter(replicaPlacement *super_block.ReplicaPlacement, volumeId uint32, collectionPattern string) func(message *master_pb.VolumeInformationMessage) bool { replicaPlacementInt32 := uint32(replicaPlacement.Byte()) + if collectionPattern != "" { + return func(v *master_pb.VolumeInformationMessage) bool { + matched, err := filepath.Match(collectionPattern, v.Collection) + if err != nil { + return false + } + return matched + } + } return func(v *master_pb.VolumeInformationMessage) bool { return v.Id == volumeId && v.ReplicaPlacement != replicaPlacementInt32 } From 9668b15f3868b5084961a27fb79588b01ae9a91e Mon Sep 17 00:00:00 2001 From: user Date: Thu, 11 Nov 2021 18:18:56 +0900 Subject: [PATCH 4/4] Filtering by volume id is prioritized. --- weed/shell/command_volume_configure_replication.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/weed/shell/command_volume_configure_replication.go b/weed/shell/command_volume_configure_replication.go index fe4eab22a..7e9627b40 100644 --- a/weed/shell/command_volume_configure_replication.go +++ b/weed/shell/command_volume_configure_replication.go @@ -111,16 +111,16 @@ func (c *commandVolumeConfigureReplication) Do(args []string, commandEnv *Comman func getVolumeFilter(replicaPlacement *super_block.ReplicaPlacement, volumeId uint32, collectionPattern string) func(message *master_pb.VolumeInformationMessage) bool { replicaPlacementInt32 := uint32(replicaPlacement.Byte()) - if collectionPattern != "" { + if volumeId > 0 { return func(v *master_pb.VolumeInformationMessage) bool { - matched, err := filepath.Match(collectionPattern, v.Collection) - if err != nil { - return false - } - return matched + return v.Id == volumeId && v.ReplicaPlacement != replicaPlacementInt32 } } return func(v *master_pb.VolumeInformationMessage) bool { - return v.Id == volumeId && v.ReplicaPlacement != replicaPlacementInt32 + matched, err := filepath.Match(collectionPattern, v.Collection) + if err != nil { + return false + } + return matched } }