2020-10-21 11:49:02 +00:00
|
|
|
package replicator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/engine"
|
|
|
|
putsvc "github.com/TrueCloudLab/frostfs-node/pkg/services/object/put"
|
|
|
|
"github.com/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() {
|
2021-12-22 16:19:31 +00:00
|
|
|
p.log.Debug("finish work",
|
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
|
|
|
|
task.obj, err = engine.Get(p.localStorage, task.addr)
|
|
|
|
if err != nil {
|
|
|
|
p.log.Error("could not get object from local storage",
|
|
|
|
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 {
|
|
|
|
log.Error("could not replicate object",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
} else {
|
2021-12-22 16:19:31 +00:00
|
|
|
log.Debug("object successfully replicated")
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|