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"
|
2023-09-27 08:02:06 +00:00
|
|
|
tracingPkg "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/tracing"
|
2023-07-13 11:58:15 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
2023-07-13 11:58:15 +00:00
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
|
|
"go.opentelemetry.io/otel/trace"
|
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
|
|
|
}
|
|
|
|
|
2024-05-13 13:50:21 +00:00
|
|
|
// HandleReplicationTask 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.
|
2024-05-13 13:50:21 +00:00
|
|
|
func (p *Replicator) HandleReplicationTask(ctx context.Context, task Task, res TaskResult) {
|
2023-05-12 08:44:21 +00:00
|
|
|
p.metrics.IncInFlightRequest()
|
|
|
|
defer p.metrics.DecInFlightRequest()
|
2020-10-21 11:49:02 +00:00
|
|
|
defer func() {
|
2023-04-12 14:35:10 +00:00
|
|
|
p.log.Debug(logs.ReplicatorFinishWork,
|
2023-06-29 09:13:01 +00:00
|
|
|
zap.Uint32("amount of unfinished replicas", task.NumCopies),
|
2020-10-21 11:49:02 +00:00
|
|
|
)
|
|
|
|
}()
|
|
|
|
|
2024-05-14 11:43:21 +00:00
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Replicator.HandleReplicateTask",
|
2023-07-13 11:58:15 +00:00
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.Stringer("address", task.Addr),
|
|
|
|
attribute.Int64("number_of_copies", int64(task.NumCopies)),
|
|
|
|
))
|
|
|
|
defer span.End()
|
|
|
|
|
2023-06-29 09:13:01 +00:00
|
|
|
if task.Obj == nil {
|
2022-09-19 10:57:59 +00:00
|
|
|
var err error
|
2023-06-29 09:13:01 +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,
|
2023-06-29 09:13:01 +00:00
|
|
|
zap.Stringer("object", task.Addr),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.Error(err),
|
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
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).
|
2023-06-29 09:13:01 +00:00
|
|
|
WithObject(task.Obj)
|
2020-10-21 11:49:02 +00:00
|
|
|
|
2023-06-29 09:13:01 +00:00
|
|
|
for i := 0; task.NumCopies > 0 && i < len(task.Nodes); i++ {
|
2020-10-21 11:49:02 +00:00
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
2021-12-22 16:19:31 +00:00
|
|
|
log := p.log.With(
|
2023-06-29 09:13:01 +00:00
|
|
|
zap.String("node", netmap.StringifyPublicKey(task.Nodes[i])),
|
|
|
|
zap.Stringer("object", task.Addr),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)),
|
2021-12-22 16:19:31 +00:00
|
|
|
)
|
2020-10-21 11:49:02 +00:00
|
|
|
|
|
|
|
callCtx, cancel := context.WithTimeout(ctx, p.putTimeout)
|
|
|
|
|
2023-06-29 09:13:01 +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
|
|
|
|
2023-06-29 09:13:01 +00:00
|
|
|
task.NumCopies--
|
2022-06-09 19:11:35 +00:00
|
|
|
|
2023-06-29 09:13:01 +00:00
|
|
|
res.SubmitSuccessfulReplication(task.Nodes[i])
|
2023-05-12 08:44:21 +00:00
|
|
|
|
|
|
|
p.metrics.IncProcessedObjects()
|
2023-06-29 09:13:01 +00:00
|
|
|
p.metrics.AddPayloadSize(int64(task.Obj.PayloadSize()))
|
2020-10-21 11:49:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|