SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
[volume] Add new volumes to HUP(reload) signal (#3755)
Konstantin Lebedev301b678147c4
diff --git a/weed/command/volume.go b/weed/command/volume.goindex 24945d0e31..4c6bb20c25 100644--- a/weed/command/volume.go+++ b/weed/command/volume.go@@ -265,6 +265,8 @@ func (v VolumeServerOptions) startVolumeServer(volumeFolders, maxVolumeCounts, v// starting the cluster http serverclusterHttpServer := v.startClusterHttpService(volumeMux)+ grace.OnReload(volumeServer.LoadNewVolumes)+stopChan := make(chan bool)grace.OnInterrupt(func() {fmt.Println("volume server has been killed")diff --git a/weed/server/volume_server.go b/weed/server/volume_server.goindex 8e20b0846d..8c6c63c567 100644--- a/weed/server/volume_server.go+++ b/weed/server/volume_server.go@@ -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()diff --git a/weed/storage/store.go b/weed/storage/store.goindex 76be2fa9cb..8dea7496d8 100644--- a/weed/storage/store.go+++ b/weed/storage/store.go@@ -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()diff --git a/weed/util/grace/signal_handling.go b/weed/util/grace/signal_handling.goindex 8146668be5..14b9987965 100644--- a/weed/util/grace/signal_handling.go+++ b/weed/util/grace/signal_handling.go@@ -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.RWMutexfunc 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 {- hook()+ for s := range signalChan {+ if s.String() == syscall.SIGHUP.String() {+ reloadHookLock.RLock()+ for _, hook := range reloadHooks {+ hook()+ }+ reloadHookLock.RUnlock()+ } else {+ interruptHookLock.RLock()+ for _, hook := range interruptHooks {+ hook()+ }+ interruptHookLock.RUnlock()+ os.Exit(0)}- hookLock.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)}