2020-07-24 13:54:03 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
2024-10-21 07:22:54 +00:00
|
|
|
"context"
|
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-05-26 10:24:41 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors"
|
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"
|
|
|
|
)
|
|
|
|
|
2024-10-21 09:21:01 +00:00
|
|
|
func (np *Processor) HandleNewEpochTick(ctx context.Context, ev event.Event) {
|
2020-09-08 09:09:08 +00:00
|
|
|
_ = ev.(timerEvent.NewEpochTick)
|
2024-10-21 07:22:54 +00:00
|
|
|
np.log.Info(context.Background(), 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
|
|
|
|
2024-10-21 09:21:01 +00:00
|
|
|
err := processors.SubmitEvent(np.pool, np.metrics, "netmap_new_epoch_tick", func() bool { return np.processNewEpochTick(ctx) })
|
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
|
2024-10-21 07:22:54 +00:00
|
|
|
np.log.Warn(context.Background(), logs.NetmapNetmapWorkerPoolDrained,
|
2020-07-24 13:54:03 +00:00
|
|
|
zap.Int("capacity", np.pool.Cap()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-21 09:21:01 +00:00
|
|
|
func (np *Processor) handleNewEpoch(ctx context.Context, ev event.Event) {
|
2020-09-08 09:09:08 +00:00
|
|
|
epochEvent := ev.(netmapEvent.NewEpoch)
|
2024-10-21 09:21:01 +00:00
|
|
|
np.log.Info(ctx, 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
|
|
|
|
2023-05-26 10:24:41 +00:00
|
|
|
err := processors.SubmitEvent(np.pool, np.metrics, "netmap_new_epoch", func() bool {
|
2024-10-21 09:21:01 +00:00
|
|
|
return np.processNewEpoch(ctx, 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
|
2024-10-21 09:21:01 +00:00
|
|
|
np.log.Warn(ctx, logs.NetmapNetmapWorkerPoolDrained,
|
2020-07-24 13:54:03 +00:00
|
|
|
zap.Int("capacity", np.pool.Cap()))
|
|
|
|
}
|
|
|
|
}
|
2020-09-03 14:55:11 +00:00
|
|
|
|
2024-10-21 09:21:01 +00:00
|
|
|
func (np *Processor) handleAddPeer(ctx context.Context, ev event.Event) {
|
2020-09-08 09:09:08 +00:00
|
|
|
newPeer := ev.(netmapEvent.AddPeer)
|
2020-09-03 14:55:11 +00:00
|
|
|
|
2024-10-21 09:21:01 +00:00
|
|
|
np.log.Info(ctx, 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
|
|
|
|
2023-05-26 10:24:41 +00:00
|
|
|
err := processors.SubmitEvent(np.pool, np.metrics, "netmap_add_peer", func() bool {
|
|
|
|
return 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
|
2024-10-21 09:21:01 +00:00
|
|
|
np.log.Warn(ctx, logs.NetmapNetmapWorkerPoolDrained,
|
2020-09-03 14:55:11 +00:00
|
|
|
zap.Int("capacity", np.pool.Cap()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-21 09:21:01 +00:00
|
|
|
func (np *Processor) handleUpdateState(ctx context.Context, ev event.Event) {
|
2020-09-08 09:09:08 +00:00
|
|
|
updPeer := ev.(netmapEvent.UpdatePeer)
|
2024-10-21 09:21:01 +00:00
|
|
|
np.log.Info(ctx, 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
|
|
|
|
|
2023-05-26 10:24:41 +00:00
|
|
|
err := processors.SubmitEvent(np.pool, np.metrics, "netmap_update_peer", func() bool {
|
|
|
|
return np.processUpdatePeer(updPeer)
|
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
|
2024-10-21 09:21:01 +00:00
|
|
|
np.log.Warn(ctx, logs.NetmapNetmapWorkerPoolDrained,
|
2020-09-03 14:55:11 +00:00
|
|
|
zap.Int("capacity", np.pool.Cap()))
|
|
|
|
}
|
|
|
|
}
|
2020-10-29 16:08:36 +00:00
|
|
|
|
2024-10-21 09:21:01 +00:00
|
|
|
func (np *Processor) handleCleanupTick(ctx context.Context, ev event.Event) {
|
2020-10-29 16:08:36 +00:00
|
|
|
if !np.netmapSnapshot.enabled {
|
2024-10-21 09:21:01 +00:00
|
|
|
np.log.Debug(ctx, logs.NetmapNetmapCleanUpRoutineIsDisabled518)
|
2020-10-29 16:08:36 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup := ev.(netmapCleanupTick)
|
|
|
|
|
2024-10-21 09:21:01 +00:00
|
|
|
np.log.Info(ctx, logs.NetmapTick, zap.String("type", "netmap cleaner"))
|
2020-10-29 16:08:36 +00:00
|
|
|
|
|
|
|
// send event to the worker pool
|
2023-05-26 10:24:41 +00:00
|
|
|
err := processors.SubmitEvent(np.pool, np.metrics, "netmap_cleanup_tick", func() bool {
|
|
|
|
return np.processNetmapCleanupTick(cleanup)
|
2020-10-29 16:08:36 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
// there system can be moved into controlled degradation stage
|
2024-10-21 09:21:01 +00:00
|
|
|
np.log.Warn(ctx, logs.NetmapNetmapWorkerPoolDrained,
|
2020-10-29 16:08:36 +00:00
|
|
|
zap.Int("capacity", np.pool.Cap()))
|
|
|
|
}
|
|
|
|
}
|