frostfs-node/pkg/innerring/processors/frostfs/handlers.go

92 lines
2.9 KiB
Go
Raw Normal View History

package frostfs
2020-07-24 13:54:03 +00:00
import (
"bytes"
"context"
2020-07-24 13:54:03 +00:00
"encoding/hex"
"slices"
2020-07-24 13:54:03 +00:00
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
frostfsEvent "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event/frostfs"
2020-07-24 13:54:03 +00:00
"go.uber.org/zap"
)
func (np *Processor) handleDeposit(ctx context.Context, ev event.Event) {
deposit := ev.(frostfsEvent.Deposit)
depositIDBin := bytes.Clone(deposit.ID())
slices.Reverse(depositIDBin)
np.log.Info(ctx, logs.Notification,
2020-07-24 13:54:03 +00:00
zap.String("type", "deposit"),
zap.String("id", hex.EncodeToString(depositIDBin)))
2020-07-24 13:54:03 +00:00
// send event to the worker pool
err := processors.SubmitEvent(np.pool, np.metrics, "frostfs_deposit", func() bool {
return np.processDeposit(ctx, deposit)
})
2020-07-24 13:54:03 +00:00
if err != nil {
// there system can be moved into controlled degradation stage
np.log.Warn(ctx, logs.FrostFSFrostfsProcessorWorkerPoolDrained,
2020-07-24 13:54:03 +00:00
zap.Int("capacity", np.pool.Cap()))
}
}
func (np *Processor) handleWithdraw(ctx context.Context, ev event.Event) {
withdraw := ev.(frostfsEvent.Withdraw)
withdrawBin := bytes.Clone(withdraw.ID())
slices.Reverse(withdrawBin)
np.log.Info(ctx, logs.Notification,
2020-07-24 13:54:03 +00:00
zap.String("type", "withdraw"),
zap.String("id", hex.EncodeToString(withdrawBin)))
2020-07-24 13:54:03 +00:00
// send event to the worker pool
err := processors.SubmitEvent(np.pool, np.metrics, "frostfs_withdraw", func() bool {
return np.processWithdraw(ctx, withdraw)
})
2020-07-24 13:54:03 +00:00
if err != nil {
// there system can be moved into controlled degradation stage
np.log.Warn(ctx, logs.FrostFSFrostfsProcessorWorkerPoolDrained,
2020-07-24 13:54:03 +00:00
zap.Int("capacity", np.pool.Cap()))
}
}
func (np *Processor) handleCheque(ctx context.Context, ev event.Event) {
cheque := ev.(frostfsEvent.Cheque)
np.log.Info(ctx, logs.Notification,
2020-07-24 13:54:03 +00:00
zap.String("type", "cheque"),
zap.String("id", hex.EncodeToString(cheque.ID())))
// send event to the worker pool
err := processors.SubmitEvent(np.pool, np.metrics, "frostfs_cheque", func() bool {
return np.processCheque(ctx, cheque)
})
2020-07-24 13:54:03 +00:00
if err != nil {
// there system can be moved into controlled degradation stage
np.log.Warn(ctx, logs.FrostFSFrostfsProcessorWorkerPoolDrained,
2020-07-24 13:54:03 +00:00
zap.Int("capacity", np.pool.Cap()))
}
}
func (np *Processor) handleConfig(ctx context.Context, ev event.Event) {
cfg := ev.(frostfsEvent.Config)
np.log.Info(ctx, logs.Notification,
zap.String("type", "set config"),
zap.String("key", hex.EncodeToString(cfg.Key())),
zap.String("value", hex.EncodeToString(cfg.Value())))
// send event to the worker pool
err := processors.SubmitEvent(np.pool, np.metrics, "frostfs_config", func() bool {
return np.processConfig(ctx, cfg)
})
if err != nil {
// there system can be moved into controlled degradation stage
np.log.Warn(ctx, logs.FrostFSFrostfsProcessorWorkerPoolDrained,
zap.Int("capacity", np.pool.Cap()))
}
}