add admin script worker (#8491)
* admin: add plugin lock coordination * shell: allow bypassing lock checks * plugin worker: add admin script handler * mini: include admin_script in plugin defaults * admin script UI: drop name and enlarge text * admin script: add default script * admin_script: make run interval configurable * plugin: gate other jobs during admin_script runs * plugin: use last completed admin_script run * admin: backfill plugin config defaults * templ Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * comparable to default version Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * default to run Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * format Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * shell: respect pre-set noLock for fix.replication * shell: add force no-lock mode for admin scripts * volume balance worker already exists Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * admin: expose scheduler status JSON * shell: add sleep command * shell: restrict sleep syntax * Revert "shell: respect pre-set noLock for fix.replication" This reverts commit 2b14e8b82602a740d3a473c085e3b3a14f1ddbb3. * templ Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * fix import Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * less logs Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * Reduce master client logs on canceled contexts * Update mini default job type count --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -2,9 +2,9 @@ package shell
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||
"github.com/seaweedfs/seaweedfs/weed/storage/types"
|
||||
)
|
||||
|
||||
@@ -66,7 +66,7 @@ func (c *commandEcBalance) Do(args []string, commandEnv *CommandEnv, writer io.W
|
||||
} else {
|
||||
collections = append(collections, *collection)
|
||||
}
|
||||
fmt.Printf("balanceEcVolumes collections %+v\n", len(collections))
|
||||
glog.V(1).Infof("balanceEcVolumes collections %+v\n", len(collections))
|
||||
|
||||
rp, err := parseReplicaPlacementArg(commandEnv, *shardReplicaPlacement)
|
||||
if err != nil {
|
||||
|
||||
@@ -150,14 +150,14 @@ func parseReplicaPlacementArg(commandEnv *CommandEnv, replicaStr string) (*super
|
||||
if err != nil {
|
||||
return rp, err
|
||||
}
|
||||
fmt.Printf("using replica placement %q for EC volumes\n", rp.String())
|
||||
glog.V(1).Infof("using replica placement %q for EC volumes\n", rp.String())
|
||||
} else {
|
||||
// No replica placement argument provided, resolve from master default settings.
|
||||
rp, err = getDefaultReplicaPlacement(commandEnv)
|
||||
if err != nil {
|
||||
return rp, err
|
||||
}
|
||||
fmt.Printf("using master default replica placement %q for EC volumes\n", rp.String())
|
||||
glog.V(1).Infof("using master default replica placement %q for EC volumes\n", rp.String())
|
||||
}
|
||||
|
||||
return rp, nil
|
||||
@@ -1628,7 +1628,7 @@ func EcBalance(commandEnv *CommandEnv, collections []string, dc string, ecReplic
|
||||
}
|
||||
|
||||
if len(collections) == 0 {
|
||||
fmt.Printf("WARNING: No collections to balance EC volumes across.\n")
|
||||
glog.V(1).Infof("WARNING: No collections to balance EC volumes across.\n")
|
||||
}
|
||||
for _, c := range collections {
|
||||
if err = ecb.balanceEcVolumes(c); err != nil {
|
||||
|
||||
43
weed/shell/command_sleep.go
Normal file
43
weed/shell/command_sleep.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package shell
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Commands = append(Commands, &commandSleep{})
|
||||
}
|
||||
|
||||
// =========== Sleep ==============
|
||||
type commandSleep struct {
|
||||
}
|
||||
|
||||
func (c *commandSleep) Name() string {
|
||||
return "sleep"
|
||||
}
|
||||
|
||||
func (c *commandSleep) Help() string {
|
||||
return `sleep for N seconds (useful to simulate long running jobs)
|
||||
|
||||
sleep 5
|
||||
`
|
||||
}
|
||||
|
||||
func (c *commandSleep) HasTag(CommandTag) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *commandSleep) Do(args []string, _ *CommandEnv, _ io.Writer) error {
|
||||
if len(args) == 0 {
|
||||
return fmt.Errorf("sleep requires a seconds argument")
|
||||
}
|
||||
seconds, err := strconv.Atoi(args[0])
|
||||
if err != nil || seconds <= 0 {
|
||||
return fmt.Errorf("sleep duration must be a positive integer, got %q", args[0])
|
||||
}
|
||||
time.Sleep(time.Duration(seconds) * time.Second)
|
||||
return nil
|
||||
}
|
||||
@@ -38,6 +38,7 @@ type CommandEnv struct {
|
||||
option *ShellOptions
|
||||
locker *exclusive_locks.ExclusiveLocker
|
||||
noLock bool
|
||||
forceNoLock bool
|
||||
verbose bool
|
||||
}
|
||||
|
||||
@@ -71,6 +72,9 @@ func (ce *CommandEnv) isDirectory(path string) bool {
|
||||
|
||||
func (ce *CommandEnv) confirmIsLocked(args []string) error {
|
||||
|
||||
if ce.noLock || ce.forceNoLock {
|
||||
return nil
|
||||
}
|
||||
if ce.locker.IsLocked() {
|
||||
return nil
|
||||
}
|
||||
@@ -80,11 +84,25 @@ func (ce *CommandEnv) confirmIsLocked(args []string) error {
|
||||
|
||||
}
|
||||
|
||||
func (ce *CommandEnv) SetNoLock(noLock bool) {
|
||||
if ce == nil {
|
||||
return
|
||||
}
|
||||
ce.noLock = noLock
|
||||
}
|
||||
|
||||
func (ce *CommandEnv) ForceNoLock() {
|
||||
if ce == nil {
|
||||
return
|
||||
}
|
||||
ce.forceNoLock = true
|
||||
}
|
||||
|
||||
func (ce *CommandEnv) isLocked() bool {
|
||||
if ce == nil {
|
||||
return true
|
||||
}
|
||||
if ce.noLock {
|
||||
if ce.noLock || ce.forceNoLock {
|
||||
return true
|
||||
}
|
||||
return ce.locker.IsLocked()
|
||||
|
||||
Reference in New Issue
Block a user