From 9a5d3e7b315b8f3b0c7355d411952f260684cebd Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.com> Date: Wed, 6 Nov 2024 08:09:22 +0500 Subject: [PATCH] [shell] add admin noLock for balance (#6209) add admin noLock for balance --- weed/shell/command_volume_balance.go | 9 +++++++-- weed/shell/commands.go | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/weed/shell/command_volume_balance.go b/weed/shell/command_volume_balance.go index 42b4ea13c..8351415e2 100644 --- a/weed/shell/command_volume_balance.go +++ b/weed/shell/command_volume_balance.go @@ -76,14 +76,19 @@ func (c *commandVolumeBalance) Do(args []string, commandEnv *CommandEnv, writer dc := balanceCommand.String("dataCenter", "", "only apply the balancing for this dataCenter") racks := balanceCommand.String("racks", "", "only apply the balancing for this racks") nodes := balanceCommand.String("nodes", "", "only apply the balancing for this nodes") + noLock := balanceCommand.Bool("noLock", false, "do not lock the admin shell at one's own risk") applyBalancing := balanceCommand.Bool("force", false, "apply the balancing plan.") if err = balanceCommand.Parse(args); err != nil { return nil } infoAboutSimulationMode(writer, *applyBalancing, "-force") - if err = commandEnv.confirmIsLocked(args); err != nil { - return + if *noLock { + commandEnv.noLock = true + } else { + if err = commandEnv.confirmIsLocked(args); err != nil { + return + } } // collect topology information diff --git a/weed/shell/commands.go b/weed/shell/commands.go index 582ee560d..dbbd86f0e 100644 --- a/weed/shell/commands.go +++ b/weed/shell/commands.go @@ -35,6 +35,7 @@ type CommandEnv struct { MasterClient *wdclient.MasterClient option *ShellOptions locker *exclusive_locks.ExclusiveLocker + noLock bool } func NewCommandEnv(options *ShellOptions) *CommandEnv { @@ -42,6 +43,7 @@ func NewCommandEnv(options *ShellOptions) *CommandEnv { env: make(map[string]string), MasterClient: wdclient.NewMasterClient(options.GrpcDialOption, *options.FilerGroup, pb.AdminShellClient, "", "", "", *pb.ServerAddresses(*options.Masters).ToServiceDiscovery()), option: options, + noLock: false, } ce.locker = exclusive_locks.NewExclusiveLocker(ce.MasterClient, "shell") return ce @@ -79,6 +81,9 @@ func (ce *CommandEnv) isLocked() bool { if ce == nil { return true } + if ce.noLock { + return false + } return ce.locker.IsLocked() }