mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-10-21 11:07:45 +08:00
shell: add volumeServer.leave command
This commit is contained in:
@@ -196,6 +196,16 @@ func (vs *VolumeServer) VolumeServerStatus(ctx context.Context, req *volume_serv
|
||||
|
||||
}
|
||||
|
||||
func (vs *VolumeServer) VolumeServerLeave(ctx context.Context, req *volume_server_pb.VolumeServerLeaveRequest) (*volume_server_pb.VolumeServerLeaveResponse, error) {
|
||||
|
||||
resp := &volume_server_pb.VolumeServerLeaveResponse{}
|
||||
|
||||
vs.StopHeartbeat()
|
||||
|
||||
return resp, nil
|
||||
|
||||
}
|
||||
|
||||
func (vs *VolumeServer) VolumeNeedleStatus(ctx context.Context, req *volume_server_pb.VolumeNeedleStatusRequest) (*volume_server_pb.VolumeNeedleStatusResponse, error) {
|
||||
|
||||
resp := &volume_server_pb.VolumeNeedleStatusResponse{}
|
||||
|
@@ -31,7 +31,7 @@ func (vs *VolumeServer) heartbeat() {
|
||||
|
||||
var err error
|
||||
var newLeader string
|
||||
for {
|
||||
for vs.isHeartbeating {
|
||||
for _, master := range vs.SeedMasterNodes {
|
||||
if newLeader != "" {
|
||||
// the new leader may actually is the same master
|
||||
@@ -52,10 +52,22 @@ func (vs *VolumeServer) heartbeat() {
|
||||
newLeader = ""
|
||||
vs.store.MasterAddress = ""
|
||||
}
|
||||
if !vs.isHeartbeating {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (vs *VolumeServer) StopHeartbeat() (isAlreadyStopping bool) {
|
||||
if !vs.isHeartbeating {
|
||||
return true
|
||||
}
|
||||
vs.isHeartbeating = false
|
||||
vs.stopChan <- true
|
||||
return false
|
||||
}
|
||||
|
||||
func (vs *VolumeServer) doHeartbeat(masterNode, masterGrpcAddress string, grpcDialOption grpc.DialOption, sleepInterval time.Duration) (newLeader string, err error) {
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
@@ -171,14 +183,10 @@ func (vs *VolumeServer) doHeartbeat(masterNode, masterGrpcAddress string, grpcDi
|
||||
return "", err
|
||||
}
|
||||
case <-volumeTickChan:
|
||||
if vs.SendHeartbeat {
|
||||
glog.V(4).Infof("volume server %s:%d heartbeat", vs.store.Ip, vs.store.Port)
|
||||
if err = stream.Send(vs.store.CollectHeartbeat()); err != nil {
|
||||
glog.V(0).Infof("Volume Server Failed to talk with master %s: %v", masterNode, err)
|
||||
return "", err
|
||||
}
|
||||
} else {
|
||||
glog.V(4).Infof("volume server %s:%d skip send heartbeat", vs.store.Ip, vs.store.Port)
|
||||
glog.V(4).Infof("volume server %s:%d heartbeat", vs.store.Ip, vs.store.Port)
|
||||
if err = stream.Send(vs.store.CollectHeartbeat()); err != nil {
|
||||
glog.V(0).Infof("Volume Server Failed to talk with master %s: %v", masterNode, err)
|
||||
return "", err
|
||||
}
|
||||
case <-ecShardTickChan:
|
||||
glog.V(4).Infof("volume server %s:%d ec heartbeat", vs.store.Ip, vs.store.Port)
|
||||
@@ -188,6 +196,8 @@ func (vs *VolumeServer) doHeartbeat(masterNode, masterGrpcAddress string, grpcDi
|
||||
}
|
||||
case err = <-doneChan:
|
||||
return
|
||||
case <-vs.stopChan:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -31,7 +31,8 @@ type VolumeServer struct {
|
||||
MetricsAddress string
|
||||
MetricsIntervalSec int
|
||||
fileSizeLimitBytes int64
|
||||
SendHeartbeat bool
|
||||
isHeartbeating bool
|
||||
stopChan chan bool
|
||||
}
|
||||
|
||||
func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
|
||||
@@ -67,7 +68,8 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
|
||||
grpcDialOption: security.LoadClientTLS(util.GetViper(), "grpc.volume"),
|
||||
compactionBytePerSecond: int64(compactionMBPerSecond) * 1024 * 1024,
|
||||
fileSizeLimitBytes: int64(fileSizeLimitMB) * 1024 * 1024,
|
||||
SendHeartbeat: true,
|
||||
isHeartbeating: true,
|
||||
stopChan: make(chan bool),
|
||||
}
|
||||
vs.SeedMasterNodes = masterNodes
|
||||
vs.store = storage.NewStore(vs.grpcDialOption, port, ip, publicUrl, folders, maxCounts, minFreeSpacePercents, vs.needleMapKind)
|
||||
|
Reference in New Issue
Block a user