[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 // starting the cluster http server
clusterHttpServer := v.startClusterHttpService(volumeMux) clusterHttpServer := v.startClusterHttpService(volumeMux)
grace.OnReload(volumeServer.LoadNewVolumes)
stopChan := make(chan bool) stopChan := make(chan bool)
grace.OnInterrupt(func() { grace.OnInterrupt(func() {
fmt.Println("volume server has been killed") fmt.Println("volume server has been killed")

View file

@ -137,6 +137,11 @@ func (vs *VolumeServer) SetStopping() {
vs.store.SetStopping() vs.store.SetStopping()
} }
func (vs *VolumeServer) LoadNewVolumes() {
glog.V(0).Infoln(" Loading new volume ids ...")
vs.store.LoadNewVolumes()
}
func (vs *VolumeServer) Shutdown() { func (vs *VolumeServer) Shutdown() {
glog.V(0).Infoln("Shutting down volume server...") glog.V(0).Infoln("Shutting down volume server...")
vs.store.Close() 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() { func (s *Store) Close() {
for _, location := range s.Locations { for _, location := range s.Locations {
location.Close() location.Close()

View file

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