mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
master: remove hard coded filer settings in master.toml
fix https://github.com/chrislusf/seaweedfs/issues/2529
This commit is contained in:
parent
cd1ad88f30
commit
826a7b307e
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
@ -19,3 +22,19 @@ func (ms *MasterServer) ListClusterNodes(ctx context.Context, req *master_pb.Lis
|
|||
}
|
||||
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"
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()),
|
||||
|
|
Loading…
Reference in a new issue