[volume] Add new volumes to HUP(reload) signal (#3755)

Add new volumes to HUP(reload) signal
This commit is contained in:
Konstantin Lebedev 2022-09-29 00:44:13 +05:00 committed by GitHub
parent 47fd5d3fa1
commit 301b678147
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 13 deletions

View file

@ -265,6 +265,8 @@ func (v VolumeServerOptions) startVolumeServer(volumeFolders, maxVolumeCounts, v
// starting the cluster http server
clusterHttpServer := v.startClusterHttpService(volumeMux)
grace.OnReload(volumeServer.LoadNewVolumes)
stopChan := make(chan bool)
grace.OnInterrupt(func() {
fmt.Println("volume server has been killed")

View file

@ -137,6 +137,11 @@ func (vs *VolumeServer) SetStopping() {
vs.store.SetStopping()
}
func (vs *VolumeServer) LoadNewVolumes() {
glog.V(0).Infoln(" Loading new volume ids ...")
vs.store.LoadNewVolumes()
}
func (vs *VolumeServer) Shutdown() {
glog.V(0).Infoln("Shutting down volume server...")
vs.store.Close()

View file

@ -361,6 +361,12 @@ func (s *Store) SetStopping() {
}
}
func (s *Store) LoadNewVolumes() {
for _, location := range s.Locations {
location.loadExistingVolumes(s.NeedleMapKind)
}
}
func (s *Store) Close() {
for _, location := range s.Locations {
location.Close()

View file

@ -11,39 +11,55 @@ import (
)
var signalChan chan os.Signal
var hooks = make([]func(), 0)
var hookLock sync.RWMutex
var interruptHooks = make([]func(), 0)
var interruptHookLock sync.RWMutex
var reloadHooks = make([]func(), 0)
var reloadHookLock sync.RWMutex
func init() {
signalChan = make(chan os.Signal, 1)
signal.Ignore(syscall.SIGHUP)
signal.Notify(signalChan,
os.Interrupt,
os.Kill,
syscall.SIGALRM,
// syscall.SIGHUP,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
// syscall.SIGQUIT,
)
go func() {
for range signalChan {
hookLock.RLock()
for _, hook := range hooks {
for s := range signalChan {
if s.String() == syscall.SIGHUP.String() {
reloadHookLock.RLock()
for _, hook := range reloadHooks {
hook()
}
hookLock.RUnlock()
reloadHookLock.RUnlock()
} else {
interruptHookLock.RLock()
for _, hook := range interruptHooks {
hook()
}
interruptHookLock.RUnlock()
os.Exit(0)
}
}
}()
}
func OnReload(fn func()) {
// prevent reentry
reloadHookLock.Lock()
defer reloadHookLock.Unlock()
reloadHooks = append(reloadHooks, fn)
}
func OnInterrupt(fn func()) {
// prevent reentry
hookLock.Lock()
defer hookLock.Unlock()
interruptHookLock.Lock()
defer interruptHookLock.Unlock()
// deal with control+c,etc
// controlling terminal close, daemon not exit
hooks = append(hooks, fn)
interruptHooks = append(interruptHooks, fn)
}