-
Notifications
You must be signed in to change notification settings - Fork 38
/
handlers.go
101 lines (81 loc) · 2.59 KB
/
handlers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package netmap
import (
"encoding/hex"
timerEvent "github.com/nspcc-dev/neofs-node/pkg/innerring/timers"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
"go.uber.org/zap"
)
func (np *Processor) handleNewEpochTick(ev event.Event) {
_ = ev.(timerEvent.NewEpochTick)
np.log.Info("tick", zap.String("type", "epoch"))
// send event to the worker pool
err := np.pool.Submit(func() { np.processNewEpochTick() })
if err != nil {
// there system can be moved into controlled degradation stage
np.log.Warn("netmap worker pool drained",
zap.Int("capacity", np.pool.Cap()))
}
}
func (np *Processor) handleNewEpoch(ev event.Event) {
epochEvent := ev.(netmapEvent.NewEpoch)
np.log.Info("notification",
zap.String("type", "new epoch"),
zap.Uint64("value", epochEvent.EpochNumber()))
// send event to the worker pool
err := np.pool.Submit(func() {
np.processNewEpoch(epochEvent.EpochNumber())
})
if err != nil {
// there system can be moved into controlled degradation stage
np.log.Warn("netmap worker pool drained",
zap.Int("capacity", np.pool.Cap()))
}
}
func (np *Processor) handleAddPeer(ev event.Event) {
newPeer := ev.(netmapEvent.AddPeer)
np.log.Info("notification",
zap.String("type", "add peer"),
)
// send event to the worker pool
err := np.pool.Submit(func() {
np.processAddPeer(newPeer.Node())
})
if err != nil {
// there system can be moved into controlled degradation stage
np.log.Warn("netmap worker pool drained",
zap.Int("capacity", np.pool.Cap()))
}
}
func (np *Processor) handleUpdateState(ev event.Event) {
updPeer := ev.(netmapEvent.UpdatePeer)
np.log.Info("notification",
zap.String("type", "update peer state"),
zap.String("key", hex.EncodeToString(updPeer.PublicKey().Bytes())))
// send event to the worker pool
err := np.pool.Submit(func() {
np.processUpdatePeer(updPeer)
})
if err != nil {
// there system can be moved into controlled degradation stage
np.log.Warn("netmap worker pool drained",
zap.Int("capacity", np.pool.Cap()))
}
}
func (np *Processor) handleCleanupTick(ev event.Event) {
if !np.netmapSnapshot.enabled {
np.log.Debug("netmap clean up routine is disabled")
return
}
cleanup := ev.(netmapCleanupTick)
np.log.Info("tick", zap.String("type", "netmap cleaner"))
// send event to the worker pool
err := np.pool.Submit(func() {
np.processNetmapCleanupTick(cleanup.epoch)
})
if err != nil {
// there system can be moved into controlled degradation stage
np.log.Warn("netmap worker pool drained",
zap.Int("capacity", np.pool.Cap()))
}
}