SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
master: add cluster wide lock/unlock operation in weed shell
Chris Lu73564e6a0177
diff --git a/weed/server/master_server.go b/weed/server/master_server.goindex a7bea89053..ba17748bde 100644--- a/weed/server/master_server.go+++ b/weed/server/master_server.go@@ -205,6 +205,10 @@ func (ms *MasterServer) startAdminScripts() {filerHostPort := v.GetString("master.filer.default")scriptLines := strings.Split(adminScripts, "\n")+ if !strings.Contains(adminScripts, "lock") {+ scriptLines = append(append([]string{}, "lock"), scriptLines...)+ scriptLines = append(scriptLines, "unlock")+ }masterAddress := "localhost:" + strconv.Itoa(ms.option.Port)diff --git a/weed/server/master_server_handlers_ui.go b/weed/server/master_server_handlers_ui.goindex f241df87f6..994f0ffb3b 100644--- a/weed/server/master_server_handlers_ui.go+++ b/weed/server/master_server_handlers_ui.go@@ -2,6 +2,7 @@ package weed_serverimport ("net/http"+ "time""github.com/chrislusf/raft"ui "github.com/chrislusf/seaweedfs/weed/server/master_ui"@@ -11,7 +12,7 @@ import (func (ms *MasterServer) uiStatusHandler(w http.ResponseWriter, r *http.Request) {infos := make(map[string]interface{})- infos["Version"] = util.VERSION+ infos["Up Time"] = time.Now().Sub(startTime).String()args := struct {Version stringTopology interface{}diff --git a/weed/shell/command_ec_balance.go b/weed/shell/command_ec_balance.goindex 299d44fed1..1ddb6a4901 100644--- a/weed/shell/command_ec_balance.go+++ b/weed/shell/command_ec_balance.go@@ -98,6 +98,10 @@ func (c *commandEcBalance) Help() string {func (c *commandEcBalance) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {+ if err = commandEnv.confirmIsLocked(); err != nil {+ return+ }+balanceCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)collection := balanceCommand.String("collection", "EACH_COLLECTION", "collection name, or \"EACH_COLLECTION\" for each collection")dc := balanceCommand.String("dataCenter", "", "only apply the balancing for this dataCenter")diff --git a/weed/shell/command_ec_decode.go b/weed/shell/command_ec_decode.goindex b69e403cbd..5f03df58ce 100644--- a/weed/shell/command_ec_decode.go+++ b/weed/shell/command_ec_decode.go@@ -36,6 +36,10 @@ func (c *commandEcDecode) Help() string {func (c *commandEcDecode) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {+ if err = commandEnv.confirmIsLocked(); err != nil {+ return+ }+encodeCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)volumeId := encodeCommand.Int("volumeId", 0, "the volume id")collection := encodeCommand.String("collection", "", "the collection name")diff --git a/weed/shell/command_ec_encode.go b/weed/shell/command_ec_encode.goindex 6efb054884..8f11f84803 100644--- a/weed/shell/command_ec_encode.go+++ b/weed/shell/command_ec_encode.go@@ -54,6 +54,10 @@ func (c *commandEcEncode) Help() string {func (c *commandEcEncode) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {+ if err = commandEnv.confirmIsLocked(); err != nil {+ return+ }+encodeCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)volumeId := encodeCommand.Int("volumeId", 0, "the volume id")collection := encodeCommand.String("collection", "", "the collection name")diff --git a/weed/shell/command_ec_rebuild.go b/weed/shell/command_ec_rebuild.goindex d9d943e6d6..df28681fef 100644--- a/weed/shell/command_ec_rebuild.go+++ b/weed/shell/command_ec_rebuild.go@@ -56,6 +56,10 @@ func (c *commandEcRebuild) Help() string {func (c *commandEcRebuild) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {+ if err = commandEnv.confirmIsLocked(); err != nil {+ return+ }+fixCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)collection := fixCommand.String("collection", "EACH_COLLECTION", "collection name, or \"EACH_COLLECTION\" for each collection")applyChanges := fixCommand.Bool("force", false, "apply the changes")diff --git a/weed/shell/command_volume_balance.go b/weed/shell/command_volume_balance.goindex 349f52f1c5..69e3c7fd9d 100644--- a/weed/shell/command_volume_balance.go+++ b/weed/shell/command_volume_balance.go@@ -60,6 +60,10 @@ func (c *commandVolumeBalance) Help() string {func (c *commandVolumeBalance) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {+ if err = commandEnv.confirmIsLocked(); err != nil {+ return+ }+balanceCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)collection := balanceCommand.String("collection", "EACH_COLLECTION", "collection name, or use \"ALL_COLLECTIONS\" across collections, \"EACH_COLLECTION\" for each collection")dc := balanceCommand.String("dataCenter", "", "only apply the balancing for this dataCenter")diff --git a/weed/shell/command_volume_configure_replication.go b/weed/shell/command_volume_configure_replication.goindex 133ec62c66..ff976c3456 100644--- a/weed/shell/command_volume_configure_replication.go+++ b/weed/shell/command_volume_configure_replication.go@@ -35,6 +35,10 @@ func (c *commandVolumeConfigureReplication) Help() string {func (c *commandVolumeConfigureReplication) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {+ if err = commandEnv.confirmIsLocked(); err != nil {+ return+ }+configureReplicationCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)volumeIdInt := configureReplicationCommand.Int("volumeId", 0, "the volume id")replicationString := configureReplicationCommand.String("replication", "", "the intended replication value")diff --git a/weed/shell/command_volume_copy.go b/weed/shell/command_volume_copy.goindex aecc071ad3..cdd10863ff 100644--- a/weed/shell/command_volume_copy.go+++ b/weed/shell/command_volume_copy.go@@ -31,6 +31,10 @@ func (c *commandVolumeCopy) Help() string {func (c *commandVolumeCopy) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {+ if err = commandEnv.confirmIsLocked(); err != nil {+ return+ }+if len(args) != 3 {fmt.Fprintf(writer, "received args: %+v\n", args)return fmt.Errorf("need 3 args of <source volume server host:port> <target volume server host:port> <volume id>")diff --git a/weed/shell/command_volume_delete.go b/weed/shell/command_volume_delete.goindex 5869b1621c..c5cc9e2778 100644--- a/weed/shell/command_volume_delete.go+++ b/weed/shell/command_volume_delete.go@@ -30,6 +30,10 @@ func (c *commandVolumeDelete) Help() string {func (c *commandVolumeDelete) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {+ if err = commandEnv.confirmIsLocked(); err != nil {+ return+ }+if len(args) != 2 {fmt.Fprintf(writer, "received args: %+v\n", args)return fmt.Errorf("need 2 args of <volume server host:port> <volume id>")diff --git a/weed/shell/command_volume_fix_replication.go b/weed/shell/command_volume_fix_replication.goindex 5bfe1edc99..d16a89434b 100644--- a/weed/shell/command_volume_fix_replication.go+++ b/weed/shell/command_volume_fix_replication.go@@ -44,6 +44,10 @@ func (c *commandVolumeFixReplication) Help() string {func (c *commandVolumeFixReplication) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {+ if err = commandEnv.confirmIsLocked(); err != nil {+ return+ }+takeAction := trueif len(args) > 0 && args[0] == "-n" {takeAction = falsediff --git a/weed/shell/command_volume_fsck.go b/weed/shell/command_volume_fsck.goindex 07e2bee5be..69a1a63b47 100644--- a/weed/shell/command_volume_fsck.go+++ b/weed/shell/command_volume_fsck.go@@ -48,6 +48,10 @@ func (c *commandVolumeFsck) Help() string {func (c *commandVolumeFsck) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {+ if err = commandEnv.confirmIsLocked(); err != nil {+ return+ }+fsckCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)verbose := fsckCommand.Bool("v", false, "verbose mode")applyPurging := fsckCommand.Bool("reallyDeleteFromVolume", false, "<expert only> delete data not referenced by the filer")diff --git a/weed/shell/command_volume_mount.go b/weed/shell/command_volume_mount.goindex cffc7136bf..ded7b7e666 100644--- a/weed/shell/command_volume_mount.go+++ b/weed/shell/command_volume_mount.go@@ -34,6 +34,10 @@ func (c *commandVolumeMount) Help() string {func (c *commandVolumeMount) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {+ if err = commandEnv.confirmIsLocked(); err != nil {+ return+ }+if len(args) != 2 {fmt.Fprintf(writer, "received args: %+v\n", args)return fmt.Errorf("need 2 args of <volume server host:port> <volume id>")diff --git a/weed/shell/command_volume_move.go b/weed/shell/command_volume_move.goindex c25b953a54..392b947e75 100644--- a/weed/shell/command_volume_move.go+++ b/weed/shell/command_volume_move.go@@ -44,6 +44,10 @@ func (c *commandVolumeMove) Help() string {func (c *commandVolumeMove) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {+ if err = commandEnv.confirmIsLocked(); err != nil {+ return+ }+if len(args) != 3 {fmt.Fprintf(writer, "received args: %+v\n", args)return fmt.Errorf("need 3 args of <source volume server host:port> <target volume server host:port> <volume id>")diff --git a/weed/shell/command_volume_tier_download.go b/weed/shell/command_volume_tier_download.goindex 756dc4686b..d31c8c0319 100644--- a/weed/shell/command_volume_tier_download.go+++ b/weed/shell/command_volume_tier_download.go@@ -42,6 +42,10 @@ func (c *commandVolumeTierDownload) Help() string {func (c *commandVolumeTierDownload) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {+ if err = commandEnv.confirmIsLocked(); err != nil {+ return+ }+tierCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)volumeId := tierCommand.Int("volumeId", 0, "the volume id")collection := tierCommand.String("collection", "", "the collection name")diff --git a/weed/shell/command_volume_tier_upload.go b/weed/shell/command_volume_tier_upload.goindex 5131e8f85c..f92cdc3e4d 100644--- a/weed/shell/command_volume_tier_upload.go+++ b/weed/shell/command_volume_tier_upload.go@@ -56,6 +56,10 @@ func (c *commandVolumeTierUpload) Help() string {func (c *commandVolumeTierUpload) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {+ if err = commandEnv.confirmIsLocked(); err != nil {+ return+ }+tierCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)volumeId := tierCommand.Int("volumeId", 0, "the volume id")collection := tierCommand.String("collection", "", "the collection name")diff --git a/weed/shell/command_volume_unmount.go b/weed/shell/command_volume_unmount.goindex 6e5bef4853..7596bb4c8e 100644--- a/weed/shell/command_volume_unmount.go+++ b/weed/shell/command_volume_unmount.go@@ -34,6 +34,10 @@ func (c *commandVolumeUnmount) Help() string {func (c *commandVolumeUnmount) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {+ if err = commandEnv.confirmIsLocked(); err != nil {+ return+ }+if len(args) != 2 {fmt.Fprintf(writer, "received args: %+v\n", args)return fmt.Errorf("need 2 args of <volume server host:port> <volume id>")diff --git a/weed/shell/commands.go b/weed/shell/commands.goindex 2faba4280c..a43196b625 100644--- a/weed/shell/commands.go+++ b/weed/shell/commands.go@@ -68,6 +68,16 @@ func (ce *CommandEnv) isDirectory(path string) bool {}+func (ce *CommandEnv) confirmIsLocked() error {++ if ce.locker.isLocking {+ return nil+ }++ return fmt.Errorf("need to lock to continue")++}+func (ce *CommandEnv) checkDirectory(path string) error {dir, name := util.FullPath(path).DirAndName()