diff options
| author | Chris Lu <chris.lu@gmail.com> | 2019-07-28 03:58:13 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2019-07-28 03:58:13 -0700 |
| commit | 8afd8d35b3230f6fc286967e8aa9641bd8c1460c (patch) | |
| tree | 8c134e958969a7aec6337c8c7bab120009006941 /weed/server/master_server.go | |
| parent | 2c6cf72e73861f3bdefaba28189fa2b15fa26d9e (diff) | |
| download | seaweedfs-8afd8d35b3230f6fc286967e8aa9641bd8c1460c.tar.xz seaweedfs-8afd8d35b3230f6fc286967e8aa9641bd8c1460c.zip | |
master: followers can also lookup and redirect
improve scalability
Diffstat (limited to 'weed/server/master_server.go')
| -rw-r--r-- | weed/server/master_server.go | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/weed/server/master_server.go b/weed/server/master_server.go index 3689b5495..e9eb32cca 100644 --- a/weed/server/master_server.go +++ b/weed/server/master_server.go @@ -1,8 +1,10 @@ package weed_server import ( + "context" "fmt" "github.com/chrislusf/seaweedfs/weed/shell" + "github.com/chrislusf/seaweedfs/weed/wdclient" "google.golang.org/grpc" "net/http" "net/http/httputil" @@ -56,9 +58,11 @@ type MasterServer struct { clientChans map[string]chan *master_pb.VolumeLocation grpcDialOpiton grpc.DialOption + + MasterClient *wdclient.MasterClient } -func NewMasterServer(r *mux.Router, option *MasterOption) *MasterServer { +func NewMasterServer(r *mux.Router, option *MasterOption, peers []string) *MasterServer { v := viper.GetViper() signingKey := v.GetString("jwt.signing.key") @@ -73,11 +77,14 @@ func NewMasterServer(r *mux.Router, option *MasterOption) *MasterServer { if option.VolumePreallocate { preallocateSize = int64(option.VolumeSizeLimitMB) * (1 << 20) } + + grpcDialOption := security.LoadClientTLS(v.Sub("grpc"), "master") ms := &MasterServer{ option: option, preallocateSize: preallocateSize, clientChans: make(map[string]chan *master_pb.VolumeLocation), - grpcDialOpiton: security.LoadClientTLS(v.Sub("grpc"), "master"), + grpcDialOpiton: grpcDialOption, + MasterClient: wdclient.NewMasterClient(context.Background(), grpcDialOption, "master", peers), } ms.bounedLeaderChan = make(chan int, 16) seq := sequence.NewMemorySequencer() @@ -92,7 +99,7 @@ func NewMasterServer(r *mux.Router, option *MasterOption) *MasterServer { r.HandleFunc("/", ms.proxyToLeader(ms.uiStatusHandler)) r.HandleFunc("/ui/index.html", ms.uiStatusHandler) r.HandleFunc("/dir/assign", ms.proxyToLeader(ms.guard.WhiteList(ms.dirAssignHandler))) - r.HandleFunc("/dir/lookup", ms.proxyToLeader(ms.guard.WhiteList(ms.dirLookupHandler))) + r.HandleFunc("/dir/lookup", ms.guard.WhiteList(ms.dirLookupHandler)) r.HandleFunc("/dir/status", ms.proxyToLeader(ms.guard.WhiteList(ms.dirStatusHandler))) r.HandleFunc("/col/delete", ms.proxyToLeader(ms.guard.WhiteList(ms.collectionDeleteHandler))) r.HandleFunc("/vol/grow", ms.proxyToLeader(ms.guard.WhiteList(ms.volumeGrowHandler))) @@ -102,7 +109,7 @@ func NewMasterServer(r *mux.Router, option *MasterOption) *MasterServer { r.HandleFunc("/stats/health", ms.guard.WhiteList(statsHealthHandler)) r.HandleFunc("/stats/counter", ms.guard.WhiteList(statsCounterHandler)) r.HandleFunc("/stats/memory", ms.guard.WhiteList(statsMemoryHandler)) - r.HandleFunc("/{fileId}", ms.proxyToLeader(ms.redirectHandler)) + r.HandleFunc("/{fileId}", ms.redirectHandler) } ms.Topo.StartRefreshWritableVolumes(ms.grpcDialOpiton, ms.option.GarbageThreshold, ms.preallocateSize) |
