2020-10-21 11:49:02 +00:00
|
|
|
package replicator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/engine"
|
|
|
|
putsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/put"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
2020-10-21 11:49:02 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2022-06-09 19:11:35 +00:00
|
|
|
// TaskResult is a replication result interface.
|
|
|
|
type TaskResult interface {
|
2022-10-07 09:26:08 +00:00
|
|
|
// SubmitSuccessfulReplication submits the successful object replication
|
|
|
|
// to the given node.
|
|
|
|
SubmitSuccessfulReplication(netmap.NodeInfo)
|
2022-06-09 19:11:35 +00:00
|
|
|
}
|
|
|
|
|
2021-11-10 11:47:52 +00:00
|
|
|
// HandleTask executes replication task inside invoking goroutine.
|
2022-06-09 19:11:35 +00:00
|
|
|
// Passes all the nodes that accepted the replication to the TaskResult.
|
2022-09-19 11:01:19 +00:00
|
|
|
func (p *Replicator) HandleTask(ctx context.Context, task Task, res TaskResult) {
|
2020-10-21 11:49:02 +00:00
|
|
|
defer func() {
|
2023-04-12 14:35:10 +00:00
|
|
|
p.log.Debug(logs.ReplicatorFinishWork,
|
2020-10-21 11:49:02 +00:00
|
|
|
zap.Uint32("amount of unfinished replicas", task.quantity),
|
|
|
|
)
|
|
|
|
}()
|
|
|
|
|
2022-09-19 10:57:59 +00:00
|
|
|
if task.obj == nil {
|
|
|
|
var err error
|
2023-03-13 11:37:35 +00:00
|
|
|
task.obj, err = engine.Get(ctx, p.localStorage, task.addr)
|
2022-09-19 10:57:59 +00:00
|
|
|
if err != nil {
|
2023-04-12 14:35:10 +00:00
|
|
|
p.log.Error(logs.ReplicatorCouldNotGetObjectFromLocalStorage,
|
2022-09-19 10:57:59 +00:00
|
|
|
zap.Stringer("object", task.addr),
|
|
|
|
zap.Error(err))
|
2020-10-21 11:49:02 +00:00
|
|
|
|
2022-09-19 10:57:59 +00:00
|
|
|
return
|
|
|
|
}
|
2020-10-21 11:49:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
prm := new(putsvc.RemotePutPrm).
|
2022-09-19 10:57:59 +00:00
|
|
|
WithObject(task.obj)
|
2020-10-21 11:49:02 +00:00
|
|
|
|
|
|
|
for i := 0; task.quantity > 0 && i < len(task.nodes); i++ {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
2021-12-22 16:19:31 +00:00
|
|
|
log := p.log.With(
|
2022-10-11 12:49:34 +00:00
|
|
|
zap.String("node", netmap.StringifyPublicKey(task.nodes[i])),
|
2021-12-22 16:19:31 +00:00
|
|
|
zap.Stringer("object", task.addr),
|
|
|
|
)
|
2020-10-21 11:49:02 +00:00
|
|
|
|
|
|
|
callCtx, cancel := context.WithTimeout(ctx, p.putTimeout)
|
|
|
|
|
2022-09-19 10:57:59 +00:00
|
|
|
err := p.remoteSender.PutObject(callCtx, prm.WithNodeInfo(task.nodes[i]))
|
2020-10-21 11:49:02 +00:00
|
|
|
|
|
|
|
cancel()
|
|
|
|
|
|
|
|
if err != nil {
|
2023-04-12 14:35:10 +00:00
|
|
|
log.Error(logs.ReplicatorCouldNotReplicateObject,
|
2020-10-21 11:49:02 +00:00
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
} else {
|
2023-04-12 14:35:10 +00:00
|
|
|
log.Debug(logs.ReplicatorObjectSuccessfullyReplicated)
|
2020-10-21 11:49:02 +00:00
|
|
|
|
|
|
|
task.quantity--
|
2022-06-09 19:11:35 +00:00
|
|
|
|
2022-10-07 09:26:08 +00:00
|
|
|
res.SubmitSuccessfulReplication(task.nodes[i])
|
2020-10-21 11:49:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|