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
refactor: change masters from a slice to a map
chrislu21e089863179
diff --git a/weed/command/benchmark.go b/weed/command/benchmark.goindex af5919adf8..7091463ccb 100644--- a/weed/command/benchmark.go+++ b/weed/command/benchmark.go@@ -129,7 +129,7 @@ func runBenchmark(cmd *Command, args []string) bool {defer pprof.StopCPUProfile()}- b.masterClient = wdclient.NewMasterClient(b.grpcDialOption, "client", "", "", pb.ServerAddresses(*b.masters).ToAddresses())+ b.masterClient = wdclient.NewMasterClient(b.grpcDialOption, "client", "", "", pb.ServerAddresses(*b.masters).ToAddressMap())go b.masterClient.KeepConnectedToMaster()b.masterClient.WaitUntilConnected()diff --git a/weed/command/filer.go b/weed/command/filer.goindex 4f8fd947af..0a768944b7 100644--- a/weed/command/filer.go+++ b/weed/command/filer.go@@ -29,7 +29,7 @@ var ()type FilerOptions struct {- masters []pb.ServerAddress+ masters map[string]pb.ServerAddressmastersString *stringip *stringbindIp *string@@ -171,7 +171,7 @@ func runFiler(cmd *Command, args []string) bool {}()}- f.masters = pb.ServerAddresses(*f.mastersString).ToAddresses()+ f.masters = pb.ServerAddresses(*f.mastersString).ToAddressMap()f.startFiler()diff --git a/weed/command/iam.go b/weed/command/iam.goindex 88b17b1a2a..968d230955 100644--- a/weed/command/iam.go+++ b/weed/command/iam.go@@ -67,7 +67,7 @@ func (iamopt *IamOptions) startIamServer() bool {}}- masters := pb.ServerAddresses(*iamopt.masters).ToAddresses()+ masters := pb.ServerAddresses(*iamopt.masters).ToAddressMap()router := mux.NewRouter().SkipClean(true)_, iamApiServer_err := iamapi.NewIamApiServer(router, &iamapi.IamServerOption{Masters: masters,diff --git a/weed/command/master.go b/weed/command/master.goindex 9792ce0ba0..e56ee19fef 100644--- a/weed/command/master.go+++ b/weed/command/master.go@@ -132,8 +132,13 @@ func startMaster(masterOption MasterOptions, masterWhiteList []string) {myMasterAddress, peers := checkPeers(*masterOption.ip, *masterOption.port, *masterOption.portGrpc, *masterOption.peers)+ masterPeers := make(map[string]pb.ServerAddress)+ for _, peer := range peers {+ masterPeers[peer.String()] = peer+ }+r := mux.NewRouter()- ms := weed_server.NewMasterServer(r, masterOption.toMasterOption(masterWhiteList), peers)+ ms := weed_server.NewMasterServer(r, masterOption.toMasterOption(masterWhiteList), masterPeers)listeningAddress := util.JoinHostPort(*masterOption.ipBind, *masterOption.port)glog.V(0).Infof("Start Seaweed Master %s at %s", util.Version(), listeningAddress)masterListener, masterLocalListner, e := util.NewIpAndLocalListeners(*masterOption.ipBind, *masterOption.port, 0)@@ -141,11 +146,6 @@ func startMaster(masterOption MasterOptions, masterWhiteList []string) {glog.Fatalf("Master startup error: %v", e)}- masterPeers := make(map[string]pb.ServerAddress)- for _, peer := range peers {- masterPeers[peer.String()] = peer- }-// start raftServerraftServerOption := &weed_server.RaftServerOption{GrpcDialOption: security.LoadClientTLS(util.GetViper(), "grpc.master"),diff --git a/weed/command/master_follower.go b/weed/command/master_follower.goindex f182d7ce45..ec7d2758f3 100644--- a/weed/command/master_follower.go+++ b/weed/command/master_follower.go@@ -83,7 +83,7 @@ func runMasterFollower(cmd *Command, args []string) bool {func startMasterFollower(masterOptions MasterOptions) {// collect settings from main masters- masters := pb.ServerAddresses(*mf.peers).ToAddresses()+ masters := pb.ServerAddresses(*mf.peers).ToAddressMap()var err errorgrpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.master")diff --git a/weed/command/server.go b/weed/command/server.goindex a1b495c5fa..0cc60fd30a 100644--- a/weed/command/server.go+++ b/weed/command/server.go@@ -191,7 +191,7 @@ func runServer(cmd *Command, args []string) bool {// ip addressmasterOptions.ip = serverIpmasterOptions.ipBind = serverBindIp- filerOptions.masters = pb.ServerAddresses(*masterOptions.peers).ToAddresses()+ filerOptions.masters = pb.ServerAddresses(*masterOptions.peers).ToAddressMap()filerOptions.ip = serverIpfilerOptions.bindIp = serverBindIps3Options.bindIp = serverBindIpdiff --git a/weed/filer/filer.go b/weed/filer/filer.goindex 7b6f1342cd..836a0e4478 100644--- a/weed/filer/filer.go+++ b/weed/filer/filer.go@@ -49,7 +49,7 @@ type Filer struct {UniqueFileId uint32}-func NewFiler(masters []pb.ServerAddress, grpcDialOption grpc.DialOption,+func NewFiler(masters map[string]pb.ServerAddress, grpcDialOption grpc.DialOption,filerHost pb.ServerAddress, collection string, replication string, dataCenter string, notifyFn func()) *Filer {f := &Filer{MasterClient: wdclient.NewMasterClient(grpcDialOption, cluster.FilerType, filerHost, dataCenter, masters),diff --git a/weed/iamapi/iamapi_server.go b/weed/iamapi/iamapi_server.goindex fc0e6b7008..6f6cc7533c 100644--- a/weed/iamapi/iamapi_server.go+++ b/weed/iamapi/iamapi_server.go@@ -33,7 +33,7 @@ type IamS3ApiConfigure struct {}type IamServerOption struct {- Masters []pb.ServerAddress+ Masters map[string]pb.ServerAddressFiler pb.ServerAddressPort intGrpcDialOption grpc.DialOptiondiff --git a/weed/pb/grpc_client_server.go b/weed/pb/grpc_client_server.goindex cedcc28138..50feb2e235 100644--- a/weed/pb/grpc_client_server.go+++ b/weed/pb/grpc_client_server.go@@ -206,7 +206,7 @@ func WithMasterClient(streamingMode bool, master ServerAddress, grpcDialOption g}-func WithOneOfGrpcMasterClients(streamingMode bool, masterGrpcAddresses []ServerAddress, grpcDialOption grpc.DialOption, fn func(client master_pb.SeaweedClient) error) (err error) {+func WithOneOfGrpcMasterClients(streamingMode bool, masterGrpcAddresses map[string]ServerAddress, grpcDialOption grpc.DialOption, fn func(client master_pb.SeaweedClient) error) (err error) {for _, masterGrpcAddress := range masterGrpcAddresses {err = WithGrpcClient(streamingMode, func(grpcConnection *grpc.ClientConn) error {diff --git a/weed/pb/server_address.go b/weed/pb/server_address.goindex b60551c715..c7faea4bd7 100644--- a/weed/pb/server_address.go+++ b/weed/pb/server_address.go@@ -86,6 +86,14 @@ func (sa ServerAddresses) ToAddresses() (addresses []ServerAddress) {return}+func (sa ServerAddresses) ToAddressMap() (addresses map[string]ServerAddress) {+ addresses = make(map[string]ServerAddress)+ for _, address := range sa.ToAddresses() {+ addresses[address.String()] = address+ }+ return+}+func (sa ServerAddresses) ToAddressStrings() (addresses []string) {parts := strings.Split(string(sa), ",")for _, address := range parts {@@ -101,6 +109,13 @@ func ToAddressStrings(addresses []ServerAddress) []string {}return strings}+func ToAddressStringsFromMap(addresses map[string]ServerAddress) []string {+ var strings []string+ for _, addr := range addresses {+ strings = append(strings, string(addr))+ }+ return strings+}func FromAddressStrings(strings []string) []ServerAddress {var addresses []ServerAddressfor _, addr := range strings {diff --git a/weed/server/filer_grpc_server.go b/weed/server/filer_grpc_server.goindex 3f65660ee3..5a57141563 100644--- a/weed/server/filer_grpc_server.go+++ b/weed/server/filer_grpc_server.go@@ -393,7 +393,7 @@ func (fs *FilerServer) GetFilerConfiguration(ctx context.Context, req *filer_pb.clusterId, _ := fs.filer.Store.KvGet(context.Background(), []byte("clusterId"))t := &filer_pb.GetFilerConfigurationResponse{- Masters: pb.ToAddressStrings(fs.option.Masters),+ Masters: pb.ToAddressStringsFromMap(fs.option.Masters),Collection: fs.option.Collection,Replication: fs.option.DefaultReplication,MaxMb: uint32(fs.option.MaxMB),diff --git a/weed/server/filer_server.go b/weed/server/filer_server.goindex 497f595688..7edd5870fc 100644--- a/weed/server/filer_server.go+++ b/weed/server/filer_server.go@@ -48,7 +48,7 @@ import ()type FilerOption struct {- Masters []pb.ServerAddress+ Masters map[string]pb.ServerAddressCollection stringDefaultReplication stringDisableDirListing booldiff --git a/weed/server/master_server.go b/weed/server/master_server.goindex 671432d5c6..b63e3a418a 100644--- a/weed/server/master_server.go+++ b/weed/server/master_server.go@@ -75,7 +75,7 @@ type MasterServer struct {Cluster *cluster.Cluster}-func NewMasterServer(r *mux.Router, option *MasterOption, peers []pb.ServerAddress) *MasterServer {+func NewMasterServer(r *mux.Router, option *MasterOption, peers map[string]pb.ServerAddress) *MasterServer {v := util.GetViper()signingKey := v.GetString("jwt.signing.key")diff --git a/weed/shell/commands.go b/weed/shell/commands.goindex ec71edee02..3ff49f1d2b 100644--- a/weed/shell/commands.go+++ b/weed/shell/commands.go@@ -46,7 +46,7 @@ var (func NewCommandEnv(options *ShellOptions) *CommandEnv {ce := &CommandEnv{env: make(map[string]string),- MasterClient: wdclient.NewMasterClient(options.GrpcDialOption, pb.AdminShellClient, "", "", pb.ServerAddresses(*options.Masters).ToAddresses()),+ MasterClient: wdclient.NewMasterClient(options.GrpcDialOption, pb.AdminShellClient, "", "", pb.ServerAddresses(*options.Masters).ToAddressMap()),option: options,}ce.locker = exclusive_locks.NewExclusiveLocker(ce.MasterClient, "admin")diff --git a/weed/wdclient/masterclient.go b/weed/wdclient/masterclient.goindex 5280305e2b..daf74c1bee 100644--- a/weed/wdclient/masterclient.go+++ b/weed/wdclient/masterclient.go@@ -18,7 +18,7 @@ type MasterClient struct {clientType stringclientHost pb.ServerAddresscurrentMaster pb.ServerAddress- masters []pb.ServerAddress+ masters map[string]pb.ServerAddressgrpcDialOption grpc.DialOptionvidMap@@ -26,7 +26,7 @@ type MasterClient struct {OnPeerUpdate func(update *master_pb.ClusterNodeUpdate)}-func NewMasterClient(grpcDialOption grpc.DialOption, clientType string, clientHost pb.ServerAddress, clientDataCenter string, masters []pb.ServerAddress) *MasterClient {+func NewMasterClient(grpcDialOption grpc.DialOption, clientType string, clientHost pb.ServerAddress, clientDataCenter string, masters map[string]pb.ServerAddress) *MasterClient {return &MasterClient{clientType: clientType,clientHost: clientHost,