forked from TrueCloudLab/frostfs-node
[#381] *: Move to sync/atomic
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
ff570847a4
commit
4b768fd115
21 changed files with 77 additions and 64 deletions
|
@ -11,7 +11,7 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
atomicstd "sync/atomic"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
|
@ -68,7 +68,6 @@ import (
|
|||
neogoutil "github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/panjf2000/ants/v2"
|
||||
"go.etcd.io/bbolt"
|
||||
"go.uber.org/atomic"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
@ -374,7 +373,7 @@ type shared struct {
|
|||
ownerIDFromKey user.ID // user ID calculated from key
|
||||
|
||||
// current network map
|
||||
netMap atomicstd.Value // type netmap.NetMap
|
||||
netMap atomic.Value // type netmap.NetMap
|
||||
netMapSource netmapCore.Source
|
||||
|
||||
cnrClient *containerClient.Client
|
||||
|
@ -582,6 +581,9 @@ func initCfg(appCfg *config.Config) *cfg {
|
|||
}
|
||||
|
||||
func initInternals(appCfg *config.Config, log *logger.Logger) internals {
|
||||
var healthStatus atomic.Int32
|
||||
healthStatus.Store(int32(control.HealthStatus_HEALTH_STATUS_UNDEFINED))
|
||||
|
||||
return internals{
|
||||
done: make(chan struct{}),
|
||||
appCfg: appCfg,
|
||||
|
@ -589,7 +591,7 @@ func initInternals(appCfg *config.Config, log *logger.Logger) internals {
|
|||
log: log,
|
||||
wg: new(sync.WaitGroup),
|
||||
apiVersion: version.Current(),
|
||||
healthStatus: atomic.NewInt32(int32(control.HealthStatus_HEALTH_STATUS_UNDEFINED)),
|
||||
healthStatus: &healthStatus,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -627,12 +629,14 @@ func initNetmap(appCfg *config.Config, netState *networkState, relayOnly bool) c
|
|||
netmapWorkerPool, err := ants.NewPool(notificationHandlerPoolSize)
|
||||
fatalOnErr(err)
|
||||
|
||||
var reBootstrapTurnedOff atomic.Bool
|
||||
reBootstrapTurnedOff.Store(relayOnly)
|
||||
return cfgNetmap{
|
||||
scriptHash: contractsconfig.Netmap(appCfg),
|
||||
state: netState,
|
||||
workerPool: netmapWorkerPool,
|
||||
needBootstrap: !relayOnly,
|
||||
reBoostrapTurnedOff: atomic.NewBool(relayOnly),
|
||||
reBoostrapTurnedOff: &reBootstrapTurnedOff,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync/atomic"
|
||||
|
||||
netmapGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
||||
|
@ -19,7 +20,6 @@ import (
|
|||
netmapService "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/netmap"
|
||||
netmapSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/version"
|
||||
"go.uber.org/atomic"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
@ -27,7 +27,7 @@ import (
|
|||
type networkState struct {
|
||||
epoch *atomic.Uint64
|
||||
|
||||
controlNetStatus atomic.Value // control.NetmapStatus
|
||||
controlNetStatus atomic.Int32 // control.NetmapStatus
|
||||
|
||||
nodeInfo atomic.Value // *netmapSDK.NodeInfo
|
||||
|
||||
|
@ -35,13 +35,11 @@ type networkState struct {
|
|||
}
|
||||
|
||||
func newNetworkState() *networkState {
|
||||
var nmStatus atomic.Value
|
||||
nmStatus.Store(control.NetmapStatus_STATUS_UNDEFINED)
|
||||
|
||||
return &networkState{
|
||||
epoch: atomic.NewUint64(0),
|
||||
controlNetStatus: nmStatus,
|
||||
ns := &networkState{
|
||||
epoch: new(atomic.Uint64),
|
||||
}
|
||||
ns.controlNetStatus.Store(int32(control.NetmapStatus_STATUS_UNDEFINED))
|
||||
return ns
|
||||
}
|
||||
|
||||
func (s *networkState) CurrentEpoch() uint64 {
|
||||
|
@ -91,11 +89,11 @@ func (s *networkState) setNodeInfo(ni *netmapSDK.NodeInfo) {
|
|||
// calls will process this value to decide what status node should set in the
|
||||
// network.
|
||||
func (s *networkState) setControlNetmapStatus(st control.NetmapStatus) {
|
||||
s.controlNetStatus.Store(st)
|
||||
s.controlNetStatus.Store(int32(st))
|
||||
}
|
||||
|
||||
func (s *networkState) controlNetmapStatus() (res control.NetmapStatus) {
|
||||
return s.controlNetStatus.Load().(control.NetmapStatus)
|
||||
return control.NetmapStatus(s.controlNetStatus.Load())
|
||||
}
|
||||
|
||||
func (s *networkState) getNodeInfo() (res netmapSDK.NodeInfo, ok bool) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue