master server graceful stop (#3797)

This commit is contained in:
Konstantin Lebedev
2022-10-06 21:30:30 +05:00
committed by GitHub
parent 36daa7709d
commit b9933d5589
3 changed files with 37 additions and 14 deletions

View File

@@ -2,6 +2,7 @@ package command
import (
"fmt"
hashicorpRaft "github.com/hashicorp/raft"
"net/http"
"os"
"path"
@@ -253,6 +254,13 @@ func startMaster(masterOption MasterOptions, masterWhiteList []string) {
go httpS.Serve(masterListener)
}
grace.OnInterrupt(ms.Shutdown)
grace.OnInterrupt(grpcS.GracefulStop)
grace.OnReload(func() {
if ms.Topo.HashicorpRaft != nil && ms.Topo.HashicorpRaft.State() == hashicorpRaft.Leader {
ms.Topo.HashicorpRaft.LeadershipTransfer()
}
})
select {}
}