Adjust cli option (#7418)

* adjust "weed benchmark" CLI to use readOnly/writeOnly

* consistently use "-master" CLI option

* If both -readOnly and -writeOnly are specified, the current logic silently allows it with -writeOnly taking precedence. This is confusing and could lead to unexpected behavior.
This commit is contained in:
Chris Lu
2025-10-31 17:08:00 -07:00
committed by GitHub
parent 58acc14d2c
commit 5ab49e2971
7 changed files with 91 additions and 34 deletions

View File

@@ -21,6 +21,7 @@ var (
type BackupOptions struct {
master *string
server *string // deprecated, for backward compatibility
collection *string
dir *string
volumeId *int
@@ -30,7 +31,8 @@ type BackupOptions struct {
func init() {
cmdBackup.Run = runBackup // break init cycle
s.master = cmdBackup.Flag.String("server", "localhost:9333", "SeaweedFS master location")
s.master = cmdBackup.Flag.String("master", "localhost:9333", "SeaweedFS master location")
s.server = cmdBackup.Flag.String("server", "", "SeaweedFS master location (deprecated, use -master instead)")
s.collection = cmdBackup.Flag.String("collection", "", "collection name")
s.dir = cmdBackup.Flag.String("dir", ".", "directory to store volume data files")
s.volumeId = cmdBackup.Flag.Int("volumeId", -1, "a volume id. The volume .dat and .idx files should already exist in the dir.")
@@ -46,7 +48,7 @@ func init() {
}
var cmdBackup = &Command{
UsageLine: "backup -dir=. -volumeId=234 -server=localhost:9333",
UsageLine: "backup -dir=. -volumeId=234 -master=localhost:9333",
Short: "incrementally backup a volume to local folder",
Long: `Incrementally backup volume data.
@@ -69,13 +71,19 @@ func runBackup(cmd *Command, args []string) bool {
util.LoadSecurityConfiguration()
grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client")
// Backward compatibility: if -server is provided, use it
masterServer := *s.master
if *s.server != "" {
masterServer = *s.server
}
if *s.volumeId == -1 {
return false
}
vid := needle.VolumeId(*s.volumeId)
// find volume location, replication, ttl info
lookup, err := operation.LookupVolumeId(func(_ context.Context) pb.ServerAddress { return pb.ServerAddress(*s.master) }, grpcDialOption, vid.String())
lookup, err := operation.LookupVolumeId(func(_ context.Context) pb.ServerAddress { return pb.ServerAddress(masterServer) }, grpcDialOption, vid.String())
if err != nil {
fmt.Printf("Error looking up volume %d: %v\n", vid, err)
return true