forked from TrueCloudLab/frostfs-node
[#1437] ir: Fix contextcheck linter
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
ea190dd425
commit
22b26ea14e
5 changed files with 39 additions and 38 deletions
|
@ -47,7 +47,7 @@ func reloadConfig() error {
|
|||
return logPrm.Reload()
|
||||
}
|
||||
|
||||
func watchForSignal(cancel func()) {
|
||||
func watchForSignal(ctx context.Context, cancel func()) {
|
||||
ch := make(chan os.Signal, 1)
|
||||
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
|
@ -59,49 +59,49 @@ func watchForSignal(cancel func()) {
|
|||
// signals causing application to shut down should have priority over
|
||||
// reconfiguration signal
|
||||
case <-ch:
|
||||
log.Info(context.Background(), logs.FrostFSNodeTerminationSignalHasBeenReceivedStopping)
|
||||
log.Info(ctx, logs.FrostFSNodeTerminationSignalHasBeenReceivedStopping)
|
||||
cancel()
|
||||
shutdown()
|
||||
log.Info(context.Background(), logs.FrostFSNodeTerminationSignalProcessingIsComplete)
|
||||
shutdown(ctx)
|
||||
log.Info(ctx, logs.FrostFSNodeTerminationSignalProcessingIsComplete)
|
||||
return
|
||||
case err := <-intErr: // internal application error
|
||||
log.Info(context.Background(), logs.FrostFSIRInternalError, zap.String("msg", err.Error()))
|
||||
log.Info(ctx, logs.FrostFSIRInternalError, zap.String("msg", err.Error()))
|
||||
cancel()
|
||||
shutdown()
|
||||
shutdown(ctx)
|
||||
return
|
||||
default:
|
||||
// block until any signal is receieved
|
||||
select {
|
||||
case <-ch:
|
||||
log.Info(context.Background(), logs.FrostFSNodeTerminationSignalHasBeenReceivedStopping)
|
||||
log.Info(ctx, logs.FrostFSNodeTerminationSignalHasBeenReceivedStopping)
|
||||
cancel()
|
||||
shutdown()
|
||||
log.Info(context.Background(), logs.FrostFSNodeTerminationSignalProcessingIsComplete)
|
||||
shutdown(ctx)
|
||||
log.Info(ctx, logs.FrostFSNodeTerminationSignalProcessingIsComplete)
|
||||
return
|
||||
case err := <-intErr: // internal application error
|
||||
log.Info(context.Background(), logs.FrostFSIRInternalError, zap.String("msg", err.Error()))
|
||||
log.Info(ctx, logs.FrostFSIRInternalError, zap.String("msg", err.Error()))
|
||||
cancel()
|
||||
shutdown()
|
||||
shutdown(ctx)
|
||||
return
|
||||
case <-sighupCh:
|
||||
log.Info(context.Background(), logs.FrostFSNodeSIGHUPHasBeenReceivedRereadingConfiguration)
|
||||
if !innerRing.CompareAndSwapHealthStatus(control.HealthStatus_READY, control.HealthStatus_RECONFIGURING) {
|
||||
log.Info(context.Background(), logs.FrostFSNodeSIGHUPSkip)
|
||||
log.Info(ctx, logs.FrostFSNodeSIGHUPHasBeenReceivedRereadingConfiguration)
|
||||
if !innerRing.CompareAndSwapHealthStatus(ctx, control.HealthStatus_READY, control.HealthStatus_RECONFIGURING) {
|
||||
log.Info(ctx, logs.FrostFSNodeSIGHUPSkip)
|
||||
break
|
||||
}
|
||||
err := reloadConfig()
|
||||
if err != nil {
|
||||
log.Error(context.Background(), logs.FrostFSNodeConfigurationReading, zap.Error(err))
|
||||
log.Error(ctx, logs.FrostFSNodeConfigurationReading, zap.Error(err))
|
||||
}
|
||||
pprofCmp.reload()
|
||||
metricsCmp.reload()
|
||||
log.Info(context.Background(), logs.FrostFSIRReloadExtraWallets)
|
||||
log.Info(ctx, logs.FrostFSIRReloadExtraWallets)
|
||||
err = innerRing.SetExtraWallets(cfg)
|
||||
if err != nil {
|
||||
log.Error(context.Background(), logs.FrostFSNodeConfigurationReading, zap.Error(err))
|
||||
log.Error(ctx, logs.FrostFSNodeConfigurationReading, zap.Error(err))
|
||||
}
|
||||
innerRing.CompareAndSwapHealthStatus(control.HealthStatus_RECONFIGURING, control.HealthStatus_READY)
|
||||
log.Info(context.Background(), logs.FrostFSNodeConfigurationHasBeenReloadedSuccessfully)
|
||||
innerRing.CompareAndSwapHealthStatus(ctx, control.HealthStatus_RECONFIGURING, control.HealthStatus_READY)
|
||||
log.Info(ctx, logs.FrostFSNodeConfigurationHasBeenReloadedSuccessfully)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ func main() {
|
|||
log.Info(ctx, logs.CommonApplicationStarted,
|
||||
zap.String("version", misc.Version))
|
||||
|
||||
watchForSignal(cancel)
|
||||
watchForSignal(ctx, cancel)
|
||||
|
||||
<-ctx.Done() // graceful shutdown
|
||||
log.Debug(ctx, logs.FrostFSNodeWaitingForAllProcessesToStop)
|
||||
|
@ -115,20 +115,20 @@ func main() {
|
|||
log.Info(ctx, logs.FrostFSIRApplicationStopped)
|
||||
}
|
||||
|
||||
func shutdown() {
|
||||
innerRing.Stop()
|
||||
func shutdown(ctx context.Context) {
|
||||
innerRing.Stop(ctx)
|
||||
if err := metricsCmp.shutdown(); err != nil {
|
||||
log.Debug(context.Background(), logs.FrostFSIRCouldNotShutdownHTTPServer,
|
||||
log.Debug(ctx, logs.FrostFSIRCouldNotShutdownHTTPServer,
|
||||
zap.String("error", err.Error()),
|
||||
)
|
||||
}
|
||||
if err := pprofCmp.shutdown(); err != nil {
|
||||
log.Debug(context.Background(), logs.FrostFSIRCouldNotShutdownHTTPServer,
|
||||
log.Debug(ctx, logs.FrostFSIRCouldNotShutdownHTTPServer,
|
||||
zap.String("error", err.Error()),
|
||||
)
|
||||
}
|
||||
|
||||
if err := sdnotify.ClearStatus(); err != nil {
|
||||
log.Error(context.Background(), logs.FailedToReportStatusToSystemd, zap.Error(err))
|
||||
log.Error(ctx, logs.FailedToReportStatusToSystemd, zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -140,10 +140,10 @@ var (
|
|||
|
||||
// Start runs all event providers.
|
||||
func (s *Server) Start(ctx context.Context, intError chan<- error) (err error) {
|
||||
s.setHealthStatus(control.HealthStatus_STARTING)
|
||||
s.setHealthStatus(ctx, control.HealthStatus_STARTING)
|
||||
defer func() {
|
||||
if err == nil {
|
||||
s.setHealthStatus(control.HealthStatus_READY)
|
||||
s.setHealthStatus(ctx, control.HealthStatus_READY)
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -299,15 +299,15 @@ func (s *Server) startWorkers(ctx context.Context) {
|
|||
}
|
||||
|
||||
// Stop closes all subscription channels.
|
||||
func (s *Server) Stop() {
|
||||
s.setHealthStatus(control.HealthStatus_SHUTTING_DOWN)
|
||||
func (s *Server) Stop(ctx context.Context) {
|
||||
s.setHealthStatus(ctx, control.HealthStatus_SHUTTING_DOWN)
|
||||
|
||||
go s.morphListener.Stop()
|
||||
go s.mainnetListener.Stop()
|
||||
|
||||
for _, c := range s.closers {
|
||||
if err := c(); err != nil {
|
||||
s.log.Warn(context.Background(), logs.InnerringCloserError,
|
||||
s.log.Warn(ctx, logs.InnerringCloserError,
|
||||
zap.String("error", err.Error()),
|
||||
)
|
||||
}
|
||||
|
@ -349,7 +349,7 @@ func New(ctx context.Context, log *logger.Logger, cfg *viper.Viper, errChan chan
|
|||
return nil, err
|
||||
}
|
||||
|
||||
server.setHealthStatus(control.HealthStatus_HEALTH_STATUS_UNDEFINED)
|
||||
server.setHealthStatus(ctx, control.HealthStatus_HEALTH_STATUS_UNDEFINED)
|
||||
|
||||
// parse notary support
|
||||
server.feeConfig = config.NewFeeConfig(cfg)
|
||||
|
|
|
@ -154,17 +154,17 @@ func (s *Server) ResetEpochTimer(h uint32) error {
|
|||
return s.epochTimer.Reset()
|
||||
}
|
||||
|
||||
func (s *Server) setHealthStatus(hs control.HealthStatus) {
|
||||
func (s *Server) setHealthStatus(ctx context.Context, hs control.HealthStatus) {
|
||||
s.healthStatus.Store(int32(hs))
|
||||
s.notifySystemd(hs)
|
||||
s.notifySystemd(ctx, hs)
|
||||
if s.irMetrics != nil {
|
||||
s.irMetrics.SetHealth(int32(hs))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) CompareAndSwapHealthStatus(oldSt, newSt control.HealthStatus) (swapped bool) {
|
||||
func (s *Server) CompareAndSwapHealthStatus(ctx context.Context, oldSt, newSt control.HealthStatus) (swapped bool) {
|
||||
if swapped = s.healthStatus.CompareAndSwap(int32(oldSt), int32(newSt)); swapped {
|
||||
s.notifySystemd(newSt)
|
||||
s.notifySystemd(ctx, newSt)
|
||||
if s.irMetrics != nil {
|
||||
s.irMetrics.SetHealth(int32(newSt))
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ func initPersistentStateStorage(cfg *viper.Viper) (*state.PersistentStorage, err
|
|||
return persistStorage, nil
|
||||
}
|
||||
|
||||
func (s *Server) notifySystemd(st control.HealthStatus) {
|
||||
func (s *Server) notifySystemd(ctx context.Context, st control.HealthStatus) {
|
||||
if !s.sdNotify {
|
||||
return
|
||||
}
|
||||
|
@ -203,6 +203,6 @@ func (s *Server) notifySystemd(st control.HealthStatus) {
|
|||
err = sdnotify.Status(fmt.Sprintf("%v", st))
|
||||
}
|
||||
if err != nil {
|
||||
s.log.Error(context.Background(), logs.FailedToReportStatusToSystemd, zap.Error(err))
|
||||
s.log.Error(ctx, logs.FailedToReportStatusToSystemd, zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package innerring
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -42,7 +43,7 @@ func TestServerState(t *testing.T) {
|
|||
require.Equal(t, epochDuration, srv.EpochDuration(), "invalid epoch duration")
|
||||
|
||||
var healthStatus control.HealthStatus = control.HealthStatus_READY
|
||||
srv.setHealthStatus(healthStatus)
|
||||
srv.setHealthStatus(context.Background(), healthStatus)
|
||||
require.Equal(t, healthStatus, srv.HealthStatus(), "invalid health status")
|
||||
|
||||
require.True(t, srv.IsActive(), "invalid IsActive result")
|
||||
|
|
Loading…
Reference in a new issue