mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-23 06:20:48 +02:00
* shell: bound the initial master connection wait behind -connectTimeout weed shell waited on WaitUntilConnected with a background context, so an unreachable master hung the command forever. The wait now runs on a 30s (configurable) timeout and reports the failure instead. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * shell: stop the master reconnect loop when RunShell returns KeepConnectedToMaster ran on context.Background(), so once RunShell returned — including the new connect-timeout early return — the reconnect goroutine kept dialing forever, and repeated RunShell calls accumulated one each. Give it its own cancellable context, separate from connectCtx whose deadline must not cut reconnects under a live shell. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * shell: bound filer discovery by -connectTimeout too The discovery WithClient and ListClusterNodes ran on the unbounded background context, so a master disconnect after the initial connect — or a persistently failing ListClusterNodes — could block startup past the deadline. Reusing connectCtx bounds the whole startup phase. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * shell: report filer discovery failures instead of silently losing the filer target * shell: give filer discovery its own budget after master connects Discovery shared connectCtx, so a connection that landed near the -connectTimeout deadline left ListClusterNodes almost no time and no room for WithClient to retry. A fresh timeout keeps discovery bounded without starving it. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * shell: cover the -connectTimeout master wait with a test Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * shell: note filer discovery in the -connectTimeout help text Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
84 lines
2.5 KiB
Go
84 lines
2.5 KiB
Go
package command
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/security"
|
|
"github.com/seaweedfs/seaweedfs/weed/shell"
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
)
|
|
|
|
var (
|
|
shellOptions shell.ShellOptions
|
|
shellInitialFiler *string
|
|
shellCluster *string
|
|
shellDebug *bool
|
|
shellConnectTimeout *time.Duration
|
|
)
|
|
|
|
func init() {
|
|
cmdShell.Run = runShell // break init cycle
|
|
shellOptions.Masters = cmdShell.Flag.String("master", "", "comma-separated master servers, e.g. localhost:9333")
|
|
shellOptions.FilerGroup = cmdShell.Flag.String("filerGroup", "", "filerGroup for the filers")
|
|
shellInitialFiler = cmdShell.Flag.String("filer", "", "filer host and port for initial connection, e.g. localhost:8888")
|
|
shellCluster = cmdShell.Flag.String("cluster", "", "cluster defined in shell.toml")
|
|
shellDebug = cmdShell.Flag.Bool("debug", false, "print informational logs to stderr")
|
|
shellConnectTimeout = cmdShell.Flag.Duration("connectTimeout", 30*time.Second, "timeout for the initial master connection and filer discovery")
|
|
}
|
|
|
|
var cmdShell = &Command{
|
|
UsageLine: "shell",
|
|
Short: "run interactive administrative commands",
|
|
Long: `run interactive administrative commands.
|
|
|
|
Generate shell.toml via "weed scaffold -config=shell"
|
|
|
|
`,
|
|
}
|
|
|
|
func runShell(command *Command, args []string) bool {
|
|
|
|
util.LoadSecurityConfiguration()
|
|
shellOptions.GrpcDialOption = security.LoadClientTLS(util.GetViper(), "grpc.client")
|
|
shellOptions.Directory = "/"
|
|
|
|
util.LoadConfiguration("shell", false)
|
|
viper := util.GetViper()
|
|
cluster := viper.GetString("cluster.default")
|
|
if *shellCluster != "" {
|
|
cluster = *shellCluster
|
|
}
|
|
|
|
if *shellOptions.Masters == "" {
|
|
if cluster == "" {
|
|
*shellOptions.Masters = "localhost:9333"
|
|
} else {
|
|
*shellOptions.Masters = viper.GetString("cluster." + cluster + ".master")
|
|
}
|
|
}
|
|
|
|
filerAddress := *shellInitialFiler
|
|
if filerAddress == "" && cluster != "" {
|
|
filerAddress = viper.GetString("cluster." + cluster + ".filer")
|
|
}
|
|
shellOptions.FilerAddress = pb.ServerAddress(filerAddress)
|
|
shellOptions.Debug = *shellDebug
|
|
shellOptions.ConnectTimeout = *shellConnectTimeout
|
|
if shellOptions.Debug {
|
|
fmt.Fprintf(os.Stderr, "master: %s filer: %s\n", *shellOptions.Masters, shellOptions.FilerAddress)
|
|
}
|
|
|
|
if err := shell.RunShell(shellOptions); err != nil {
|
|
// The command already printed the error; a piped run has to fail the
|
|
// script wrapping it too.
|
|
SetCommandExitStatus(1)
|
|
}
|
|
|
|
return true
|
|
|
|
}
|