2022-12-23 17:35:35 +00:00
|
|
|
package frostfs
|
2020-07-24 13:54:03 +00:00
|
|
|
|
|
|
|
import (
|
2023-11-17 07:58:04 +00:00
|
|
|
"bytes"
|
2020-07-24 13:54:03 +00:00
|
|
|
"encoding/hex"
|
2024-02-14 07:52:52 +00:00
|
|
|
"slices"
|
2020-07-24 13:54:03 +00:00
|
|
|
|
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
|
|
|
"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(ev event.Event) {
|
2022-12-23 17:35:35 +00:00
|
|
|
deposit := ev.(frostfsEvent.Deposit)
|
2023-11-17 07:58:04 +00:00
|
|
|
depositIDBin := bytes.Clone(deposit.ID())
|
|
|
|
slices.Reverse(depositIDBin)
|
2023-04-13 12:51:36 +00:00
|
|
|
np.log.Info(logs.Notification,
|
2020-07-24 13:54:03 +00:00
|
|
|
zap.String("type", "deposit"),
|
2023-11-17 07:58:04 +00:00
|
|
|
zap.String("id", hex.EncodeToString(depositIDBin)))
|
2020-07-24 13:54:03 +00:00
|
|
|
|
|
|
|
// send event to the worker pool
|
|
|
|
|
2023-05-26 10:24:41 +00:00
|
|
|
err := processors.SubmitEvent(np.pool, np.metrics, "frostfs_deposit", func() bool {
|
|
|
|
return np.processDeposit(deposit)
|
|
|
|
})
|
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.FrostFSFrostfsProcessorWorkerPoolDrained,
|
2020-07-24 13:54:03 +00:00
|
|
|
zap.Int("capacity", np.pool.Cap()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (np *Processor) handleWithdraw(ev event.Event) {
|
2022-12-23 17:35:35 +00:00
|
|
|
withdraw := ev.(frostfsEvent.Withdraw)
|
2023-11-17 07:58:04 +00:00
|
|
|
withdrawBin := bytes.Clone(withdraw.ID())
|
|
|
|
slices.Reverse(withdrawBin)
|
2023-04-13 12:51:36 +00:00
|
|
|
np.log.Info(logs.Notification,
|
2020-07-24 13:54:03 +00:00
|
|
|
zap.String("type", "withdraw"),
|
2023-11-17 07:58:04 +00:00
|
|
|
zap.String("id", hex.EncodeToString(withdrawBin)))
|
2020-07-24 13:54:03 +00:00
|
|
|
|
|
|
|
// send event to the worker pool
|
|
|
|
|
2023-05-26 10:24:41 +00:00
|
|
|
err := processors.SubmitEvent(np.pool, np.metrics, "frostfs_withdraw", func() bool {
|
|
|
|
return np.processWithdraw(withdraw)
|
|
|
|
})
|
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.FrostFSFrostfsProcessorWorkerPoolDrained,
|
2020-07-24 13:54:03 +00:00
|
|
|
zap.Int("capacity", np.pool.Cap()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (np *Processor) handleCheque(ev event.Event) {
|
2022-12-23 17:35:35 +00:00
|
|
|
cheque := ev.(frostfsEvent.Cheque)
|
2023-04-13 12:51:36 +00:00
|
|
|
np.log.Info(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
|
|
|
|
|
2023-05-26 10:24:41 +00:00
|
|
|
err := processors.SubmitEvent(np.pool, np.metrics, "frostfs_cheque", func() bool {
|
|
|
|
return np.processCheque(cheque)
|
|
|
|
})
|
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.FrostFSFrostfsProcessorWorkerPoolDrained,
|
2020-07-24 13:54:03 +00:00
|
|
|
zap.Int("capacity", np.pool.Cap()))
|
|
|
|
}
|
|
|
|
}
|
2020-09-08 09:01:38 +00:00
|
|
|
|
|
|
|
func (np *Processor) handleConfig(ev event.Event) {
|
2022-12-23 17:35:35 +00:00
|
|
|
cfg := ev.(frostfsEvent.Config)
|
2023-04-13 12:51:36 +00:00
|
|
|
np.log.Info(logs.Notification,
|
2020-09-08 09:01:38 +00:00
|
|
|
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
|
|
|
|
|
2023-05-26 10:24:41 +00:00
|
|
|
err := processors.SubmitEvent(np.pool, np.metrics, "frostfs_config", func() bool {
|
|
|
|
return np.processConfig(cfg)
|
|
|
|
})
|
2020-09-08 09:01:38 +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.FrostFSFrostfsProcessorWorkerPoolDrained,
|
2020-09-08 09:01:38 +00:00
|
|
|
zap.Int("capacity", np.pool.Cap()))
|
|
|
|
}
|
|
|
|
}
|