Redis Router graceful stop (#116)
* prestop and hasparticipants in interface * add prestop function to existing routers * fakerouter prestop * update protocol version * read lock * redis router graceful stop * test fix * force stop
This commit is contained in:
@@ -62,6 +62,7 @@ type Router interface {
|
||||
OnRTCMessage(callback RTCMessageCallback)
|
||||
|
||||
Start() error
|
||||
PreStop()
|
||||
Stop()
|
||||
}
|
||||
|
||||
|
||||
@@ -132,6 +132,10 @@ func (r *LocalRouter) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *LocalRouter) PreStop() {
|
||||
r.currentNode.State = livekit.NodeState_SHUTTING_DOWN
|
||||
}
|
||||
|
||||
func (r *LocalRouter) Stop() {
|
||||
r.rtcMessageChan.Close()
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ func NewLocalNode(conf *config.Config) (LocalNode, error) {
|
||||
Id: fmt.Sprintf("%s%s", utils.NodePrefix, HashedID(hostname)[:8]),
|
||||
Ip: conf.RTC.NodeIP,
|
||||
NumCpus: uint32(runtime.NumCPU()),
|
||||
State: livekit.NodeState_SERVING,
|
||||
Stats: &livekit.NodeStats{
|
||||
StartedAt: time.Now().Unix(),
|
||||
UpdatedAt: time.Now().Unix(),
|
||||
|
||||
@@ -258,6 +258,11 @@ func (r *RedisRouter) Start() error {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RedisRouter) PreStop() {
|
||||
r.currentNode.State = livekit.NodeState_SHUTTING_DOWN
|
||||
r.RegisterNode()
|
||||
}
|
||||
|
||||
func (r *RedisRouter) Stop() {
|
||||
if !r.isStarted.TrySet(false) {
|
||||
return
|
||||
|
||||
@@ -782,6 +782,8 @@ func (fake *FakeRouter) Stop() {
|
||||
}
|
||||
}
|
||||
|
||||
func (fake *FakeRouter) PreStop() {}
|
||||
|
||||
func (fake *FakeRouter) StopCallCount() int {
|
||||
fake.stopMutex.RLock()
|
||||
defer fake.stopMutex.RUnlock()
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
var (
|
||||
nodeLoadLow = &livekit.Node{
|
||||
State: livekit.NodeState_SERVING,
|
||||
Stats: &livekit.NodeStats{
|
||||
UpdatedAt: time.Now().Unix(),
|
||||
NumCpus: 1,
|
||||
@@ -20,6 +21,7 @@ var (
|
||||
}
|
||||
|
||||
nodeLoadHigh = &livekit.Node{
|
||||
State: livekit.NodeState_SERVING,
|
||||
Stats: &livekit.NodeStats{
|
||||
UpdatedAt: time.Now().Unix(),
|
||||
NumCpus: 1,
|
||||
|
||||
@@ -18,7 +18,7 @@ func IsAvailable(node *livekit.Node) bool {
|
||||
|
||||
func GetAvailableNodes(nodes []*livekit.Node) []*livekit.Node {
|
||||
return funk.Filter(nodes, func(node *livekit.Node) bool {
|
||||
return IsAvailable(node)
|
||||
return IsAvailable(node) && node.State == livekit.NodeState_SERVING
|
||||
}).([]*livekit.Node)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user