@@ -77,16 +77,16 @@ type Peer struct { //nolint:govet // not fieldalignment relevant
77
77
waitGroup * sync.WaitGroup // wait group used to wait on shutdowns
78
78
ConfigTool * string
79
79
ThrukExtras * string
80
- lock * deadlock.RWMutex // must be used for Peer.* access
81
- data * DataStoreSet // the cached remote data tables
82
- lmd * Daemon // reference to main lmd instance
83
- Config * Connection // reference to the peer configuration from the config file
84
- SubPeerStatus map [string ]interface {} // cached /sites result for sub peer
85
- shutdownChannel chan bool // channel used to wait to finish shutdown
86
- Name string // Name of this peer, aka peer_name
87
- ID string // ID for this peer, aka peer_key
88
- PeerAddr string // Address of the peer
89
- ParentID string // ID of parent Peer
80
+ lock * deadlock.RWMutex // must be used for Peer.* access
81
+ data atomic. Pointer [ DataStoreSet ] // the cached remote data tables
82
+ lmd * Daemon // reference to main lmd instance
83
+ Config * Connection // reference to the peer configuration from the config file
84
+ SubPeerStatus map [string ]interface {} // cached /sites result for sub peer
85
+ shutdownChannel chan bool // channel used to wait to finish shutdown
86
+ Name string // Name of this peer, aka peer_name
87
+ ID string // ID for this peer, aka peer_key
88
+ PeerAddr string // Address of the peer
89
+ ParentID string // ID of parent Peer
90
90
PeerParent string
91
91
LastError string
92
92
Section string
@@ -397,9 +397,7 @@ func (p *Peer) periodicUpdate(ctx context.Context) (ok bool, err error) {
397
397
lastUpdate := interface2float64 (p .LastUpdate .Load ())
398
398
lastFullUpdate := interface2float64 (p .LastFullUpdate .Load ())
399
399
lastTimeperiodUpdateMinute := p .LastTimeperiodUpdateMinute .Load ()
400
- p .lock .RLock ()
401
- data := p .data
402
- p .lock .RUnlock ()
400
+ data := p .data .Load ()
403
401
404
402
lastStatus := PeerStatus (p .PeerState .Load ())
405
403
@@ -767,8 +765,8 @@ func (p *Peer) InitAllTables(ctx context.Context) (err error) {
767
765
768
766
duration := time .Since (time1 )
769
767
peerStatus := PeerStatus (p .PeerState .Load ())
768
+ p .data .Store (data )
770
769
p .lock .Lock ()
771
- p .SetDataStoreSet (data , false )
772
770
p .ResponseTime = duration .Seconds ()
773
771
p .lock .Unlock ()
774
772
logWith (p ).Infof ("objects created in: %s" , duration .String ())
@@ -2760,39 +2758,26 @@ func (p *Peer) setQueryOptions(req *Request) {
2760
2758
}
2761
2759
2762
2760
// GetDataStoreSet returns table data or error.
2763
- func (p * Peer ) GetDataStoreSet () (data * DataStoreSet , err error ) {
2764
- p .lock .RLock ()
2765
- data = p .data
2766
- p .lock .RUnlock ()
2767
- if data == nil {
2761
+ func (p * Peer ) GetDataStoreSet () (store * DataStoreSet , err error ) {
2762
+ store = p .data .Load ()
2763
+ if store == nil {
2768
2764
err = fmt .Errorf ("peer is down: %s" , p .getError ())
2769
2765
}
2770
2766
2771
2767
return
2772
2768
}
2773
2769
2774
- // SetDataStoreSet resets the data table.
2775
- func (p * Peer ) SetDataStoreSet (data * DataStoreSet , lock bool ) {
2776
- if lock {
2777
- p .lock .Lock ()
2778
- defer p .lock .Unlock ()
2779
- }
2780
- p .data = data
2781
- }
2782
-
2783
2770
// ClearData resets the data table.
2784
2771
func (p * Peer ) ClearData (lock bool ) {
2785
2772
if lock {
2786
2773
p .lock .Lock ()
2787
2774
defer p .lock .Unlock ()
2788
2775
}
2789
- p .data = nil
2776
+ p .data . Store ( nil )
2790
2777
}
2791
2778
2792
2779
func (p * Peer ) ResumeFromIdle (ctx context.Context ) (err error ) {
2793
- p .lock .RLock ()
2794
- data := p .data
2795
- p .lock .RUnlock ()
2780
+ data := p .data .Load ()
2796
2781
state := PeerStatus (p .PeerState .Load ())
2797
2782
p .statusSetLocked (Idling , false )
2798
2783
logWith (p ).Infof ("switched back to normal update interval" )
0 commit comments