[#1731] services/replicator: Unify Task interface with other parameters

Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
Evgenii Stratonikov 2022-09-19 14:01:19 +03:00 committed by fyrchik
parent 4e043a801c
commit 898689ec14
4 changed files with 24 additions and 40 deletions

View file

@ -86,11 +86,11 @@ func (s *Server) replicate(addr oid.Address, obj *objectSDK.Object) error {
}
var res replicatorResult
task := new(replicator.Task).
WithObject(obj).
WithObjectAddress(addr).
WithCopiesNumber(1).
WithNodes(nodes)
var task replicator.Task
task.SetObject(obj)
task.SetObjectAddress(addr)
task.SetCopiesNumber(1)
task.SetNodes(nodes)
s.replicator.HandleTask(context.TODO(), task, &res)
if res.count == 0 {

View file

@ -154,11 +154,11 @@ func (p *Policer) processNodes(ctx *processPlacementContext, addr oid.Address,
zap.Uint32("shortage", shortage),
)
p.replicator.HandleTask(ctx, new(replicator.Task).
WithObjectAddress(addr).
WithNodes(nodes).
WithCopiesNumber(shortage),
checkedNodes,
)
var task replicator.Task
task.SetObjectAddress(addr)
task.SetNodes(nodes)
task.SetCopiesNumber(shortage)
p.replicator.HandleTask(ctx, task, checkedNodes)
}
}

View file

@ -19,7 +19,7 @@ type TaskResult interface {
// HandleTask executes replication task inside invoking goroutine.
// Passes all the nodes that accepted the replication to the TaskResult.
func (p *Replicator) HandleTask(ctx context.Context, task *Task, res TaskResult) {
func (p *Replicator) HandleTask(ctx context.Context, task Task, res TaskResult) {
defer func() {
p.log.Debug("finish work",
zap.Uint32("amount of unfinished replicas", task.quantity),

View file

@ -17,38 +17,22 @@ type Task struct {
nodes []netmap.NodeInfo
}
// WithCopiesNumber sets number of copies to replicate.
func (t *Task) WithCopiesNumber(v uint32) *Task {
if t != nil {
// SetCopiesNumber sets number of copies to replicate.
func (t *Task) SetCopiesNumber(v uint32) {
t.quantity = v
}
return t
}
// WithObjectAddress sets address of local object.
func (t *Task) WithObjectAddress(v oid.Address) *Task {
if t != nil {
// SetObjectAddress sets address of local object.
func (t *Task) SetObjectAddress(v oid.Address) {
t.addr = v
}
return t
}
// WithObject sets object to avoid fetching it from the local storage.
func (t *Task) WithObject(obj *objectSDK.Object) *Task {
if t != nil {
// SetObject sets object to avoid fetching it from the local storage.
func (t *Task) SetObject(obj *objectSDK.Object) {
t.obj = obj
}
return t
}
// WithNodes sets a list of potential object holders.
func (t *Task) WithNodes(v []netmap.NodeInfo) *Task {
if t != nil {
// SetNodes sets a list of potential object holders.
func (t *Task) SetNodes(v []netmap.NodeInfo) {
t.nodes = v
}
return t
}