Skip to content

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.

master: remove hard coded filer settings in master.toml

chrislu826a7b307e37
diff --git a/weed/command/scaffold/master.toml b/weed/command/scaffold/master.toml
index 78a5a6b7c6..ff0d90d1db 100644
--- a/weed/command/scaffold/master.toml
+++ b/weed/command/scaffold/master.toml
@@ -19,9 +19,6 @@ scripts = """
"""
sleep_minutes = 17 # sleep minutes between each script execution
-[master.filer]
-default = "localhost:8888" # used by maintenance scripts if the scripts needs to use fs related commands
-
[master.sequencer]
type = "raft" # Choose [raft|snowflake] type for storing the file id sequence
diff --git a/weed/server/master_grpc_server_cluster.go b/weed/server/master_grpc_server_cluster.go
index 4a61d2e294..a5c82627ad 100644
--- a/weed/server/master_grpc_server_cluster.go
+++ b/weed/server/master_grpc_server_cluster.go
@@ -2,7 +2,10 @@ package weed_server
import (
"context"
+ "github.com/chrislusf/seaweedfs/weed/cluster"
+ "github.com/chrislusf/seaweedfs/weed/pb"
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
+ "math/rand"
)
func (ms *MasterServer) ListClusterNodes(ctx context.Context, req *master_pb.ListClusterNodesRequest) (*master_pb.ListClusterNodesResponse, error) {
@@ -12,10 +15,26 @@ func (ms *MasterServer) ListClusterNodes(ctx context.Context, req *master_pb.Lis
for _, node := range clusterNodes {
resp.ClusterNodes = append(resp.ClusterNodes, &master_pb.ListClusterNodesResponse_ClusterNode{
- Address: string(node.Address),
- Version: node.Version,
+ Address: string(node.Address),
+ Version: node.Version,
IsLeader: ms.Cluster.IsOneLeader(node.Address),
})
}
return resp, nil
}
+
+func (ms *MasterServer) GetOneFiler() pb.ServerAddress {
+
+ clusterNodes := ms.Cluster.ListClusterNode(cluster.FilerType)
+
+ var filers []pb.ServerAddress
+ for _, node := range clusterNodes {
+ if ms.Cluster.IsOneLeader(node.Address) {
+ filers = append(filers, node.Address)
+ }
+ }
+ if len(filers) > 0 {
+ return filers[rand.Intn(len(filers))]
+ }
+ return "localhost:8888"
+}
diff --git a/weed/server/master_server.go b/weed/server/master_server.go
index cbc0aa3379..3851c4d2a9 100644
--- a/weed/server/master_server.go
+++ b/weed/server/master_server.go
@@ -208,7 +208,6 @@ func (ms *MasterServer) proxyToLeader(f http.HandlerFunc) http.HandlerFunc {
}
func (ms *MasterServer) startAdminScripts() {
- var err error
v := util.GetViper()
adminScripts := v.GetString("master.maintenance.scripts")
@@ -220,9 +219,6 @@ func (ms *MasterServer) startAdminScripts() {
v.SetDefault("master.maintenance.sleep_minutes", 17)
sleepMinutes := v.GetInt("master.maintenance.sleep_minutes")
- v.SetDefault("master.filer.default", "localhost:8888")
- filerHostPort := v.GetString("master.filer.default")
-
scriptLines := strings.Split(adminScripts, "\n")
if !strings.Contains(adminScripts, "lock") {
scriptLines = append(append([]string{}, "lock"), scriptLines...)
@@ -235,14 +231,9 @@ func (ms *MasterServer) startAdminScripts() {
shellOptions.GrpcDialOption = security.LoadClientTLS(v, "grpc.master")
shellOptions.Masters = &masterAddress
- shellOptions.FilerAddress = pb.ServerAddress(filerHostPort)
shellOptions.Directory = "/"
- if err != nil {
- glog.V(0).Infof("failed to parse master.filer.default = %s : %v\n", filerHostPort, err)
- return
- }
- commandEnv := shell.NewCommandEnv(shellOptions)
+ commandEnv := shell.NewCommandEnv(&shellOptions)
reg, _ := regexp.Compile(`'.*?'|".*?"|\S+`)
@@ -254,6 +245,10 @@ func (ms *MasterServer) startAdminScripts() {
for {
time.Sleep(time.Duration(sleepMinutes) * time.Minute)
if ms.Topo.IsLeader() {
+ shellOptions.FilerAddress = ms.GetOneFiler()
+ if shellOptions.FilerAddress == "" {
+ continue
+ }
for _, line := range scriptLines {
for _, c := range strings.Split(line, ";") {
processEachCmd(reg, c, commandEnv)
diff --git a/weed/shell/commands.go b/weed/shell/commands.go
index 985f6423bc..ec71edee02 100644
--- a/weed/shell/commands.go
+++ b/weed/shell/commands.go
@@ -29,7 +29,7 @@ type ShellOptions struct {
type CommandEnv struct {
env map[string]string
MasterClient *wdclient.MasterClient
- option ShellOptions
+ option *ShellOptions
locker *exclusive_locks.ExclusiveLocker
}
@@ -43,7 +43,7 @@ var (
Commands = []command{}
)
-func NewCommandEnv(options ShellOptions) *CommandEnv {
+func NewCommandEnv(options *ShellOptions) *CommandEnv {
ce := &CommandEnv{
env: make(map[string]string),
MasterClient: wdclient.NewMasterClient(options.GrpcDialOption, pb.AdminShellClient, "", "", pb.ServerAddresses(*options.Masters).ToAddresses()),