2020-07-24 13:54:03 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
2020-09-03 14:55:11 +00:00
|
|
|
"encoding/hex"
|
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2023-03-07 13:38:26 +00:00
|
|
|
timerEvent "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/timers"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
|
|
|
|
netmapEvent "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event/netmap"
|
2020-07-24 13:54:03 +00:00
|
|
|
"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)
|
2023-04-12 14:35:10 +00:00
|
|
|
np.log.Info(logs.NetmapTick, zap.String("type", "epoch"))
|
2020-07-24 13:54:03 +00:00
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// send an event to the worker pool
|
2020-07-24 13:54:03 +00:00
|
|
|
|
|
|
|
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
|
2023-04-12 14:35:10 +00:00
|
|
|
np.log.Warn(logs.NetmapNetmapWorkerPoolDrained,
|
2020-07-24 13:54:03 +00:00
|
|
|
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)
|
2023-04-13 12:51:36 +00:00
|
|
|
np.log.Info(logs.Notification,
|
2020-07-24 13:54:03 +00:00
|
|
|
zap.String("type", "new epoch"),
|
|
|
|
zap.Uint64("value", epochEvent.EpochNumber()))
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// send an event to the worker pool
|
2020-07-24 13:54:03 +00:00
|
|
|
|
|
|
|
err := np.pool.Submit(func() {
|
2021-11-01 15:55:25 +00:00
|
|
|
np.processNewEpoch(epochEvent)
|
2020-07-24 13:54:03 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
2020-09-08 09:09:08 +00:00
|
|
|
// there system can be moved into controlled degradation stage
|
2023-04-12 14:35:10 +00:00
|
|
|
np.log.Warn(logs.NetmapNetmapWorkerPoolDrained,
|
2020-07-24 13:54:03 +00:00
|
|
|
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
|
|
|
|
2023-04-13 12:51:36 +00:00
|
|
|
np.log.Info(logs.Notification,
|
2020-09-03 14:55:11 +00:00
|
|
|
zap.String("type", "add peer"),
|
|
|
|
)
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// send an event to the worker pool
|
2020-09-03 14:55:11 +00:00
|
|
|
|
|
|
|
err := np.pool.Submit(func() {
|
2021-09-23 17:13:59 +00:00
|
|
|
np.processAddPeer(newPeer)
|
2020-09-03 14:55:11 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
2020-09-08 09:09:08 +00:00
|
|
|
// there system can be moved into controlled degradation stage
|
2023-04-12 14:35:10 +00:00
|
|
|
np.log.Warn(logs.NetmapNetmapWorkerPoolDrained,
|
2020-09-03 14:55:11 +00:00
|
|
|
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)
|
2023-04-13 12:51:36 +00:00
|
|
|
np.log.Info(logs.Notification,
|
2020-09-03 14:55:11 +00:00
|
|
|
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
|
2023-04-12 14:35:10 +00:00
|
|
|
np.log.Warn(logs.NetmapNetmapWorkerPoolDrained,
|
2020-09-03 14:55:11 +00:00
|
|
|
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 {
|
2023-04-12 14:35:10 +00:00
|
|
|
np.log.Debug(logs.NetmapNetmapCleanUpRoutineIsDisabled518)
|
2020-10-29 16:08:36 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup := ev.(netmapCleanupTick)
|
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
np.log.Info(logs.NetmapTick, zap.String("type", "netmap cleaner"))
|
2020-10-29 16:08:36 +00:00
|
|
|
|
|
|
|
// send event to the worker pool
|
|
|
|
err := np.pool.Submit(func() {
|
2021-09-23 17:13:59 +00:00
|
|
|
np.processNetmapCleanupTick(cleanup)
|
2020-10-29 16:08:36 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
// there system can be moved into controlled degradation stage
|
2023-04-12 14:35:10 +00:00
|
|
|
np.log.Warn(logs.NetmapNetmapWorkerPoolDrained,
|
2020-10-29 16:08:36 +00:00
|
|
|
zap.Int("capacity", np.pool.Cap()))
|
|
|
|
}
|
|
|
|
}
|