2020-07-24 13:54:03 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
2020-09-03 14:55:11 +00:00
|
|
|
"encoding/hex"
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2021-01-22 15:01:44 +00:00
|
|
|
func (np *Processor) HandleNewEpochTick(ev event.Event) {
|
2020-09-08 09:09:08 +00:00
|
|
|
_ = ev.(timerEvent.NewEpochTick)
|
2020-07-24 13:54:03 +00:00
|
|
|
np.log.Info("tick", zap.String("type", "epoch"))
|
|
|
|
|
|
|
|
// send event to the worker pool
|
|
|
|
|
|
|
|
err := np.pool.Submit(func() { np.processNewEpochTick() })
|
|
|
|
if err != nil {
|
2020-09-08 09:09:08 +00:00
|
|
|
// there system can be moved into controlled degradation stage
|
2020-07-24 13:54:03 +00:00
|
|
|
np.log.Warn("netmap worker pool drained",
|
|
|
|
zap.Int("capacity", np.pool.Cap()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (np *Processor) handleNewEpoch(ev event.Event) {
|
2020-09-08 09:09:08 +00:00
|
|
|
epochEvent := ev.(netmapEvent.NewEpoch)
|
2020-07-24 13:54:03 +00:00
|
|
|
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 {
|
2020-09-08 09:09:08 +00:00
|
|
|
// there system can be moved into controlled degradation stage
|
2020-07-24 13:54:03 +00:00
|
|
|
np.log.Warn("netmap worker pool drained",
|
|
|
|
zap.Int("capacity", np.pool.Cap()))
|
|
|
|
}
|
|
|
|
}
|
2020-09-03 14:55:11 +00:00
|
|
|
|
|
|
|
func (np *Processor) handleAddPeer(ev event.Event) {
|
2020-09-08 09:09:08 +00:00
|
|
|
newPeer := ev.(netmapEvent.AddPeer)
|
2020-09-03 14:55:11 +00:00
|
|
|
|
|
|
|
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 {
|
2020-09-08 09:09:08 +00:00
|
|
|
// there system can be moved into controlled degradation stage
|
2020-09-03 14:55:11 +00:00
|
|
|
np.log.Warn("netmap worker pool drained",
|
|
|
|
zap.Int("capacity", np.pool.Cap()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (np *Processor) handleUpdateState(ev event.Event) {
|
2020-09-08 09:09:08 +00:00
|
|
|
updPeer := ev.(netmapEvent.UpdatePeer)
|
2020-09-03 14:55:11 +00:00
|
|
|
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 {
|
2020-09-08 09:09:08 +00:00
|
|
|
// there system can be moved into controlled degradation stage
|
2020-09-03 14:55:11 +00:00
|
|
|
np.log.Warn("netmap worker pool drained",
|
|
|
|
zap.Int("capacity", np.pool.Cap()))
|
|
|
|
}
|
|
|
|
}
|
2020-10-29 16:08:36 +00:00
|
|
|
|
|
|
|
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()))
|
|
|
|
}
|
|
|
|
}
|