forked from TrueCloudLab/frostfs-node
[#1731] services/replicator: Unify Task interface with other parameters
Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
parent
4e043a801c
commit
898689ec14
4 changed files with 24 additions and 40 deletions
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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 {
|
||||
t.quantity = v
|
||||
}
|
||||
|
||||
return t
|
||||
// SetCopiesNumber sets number of copies to replicate.
|
||||
func (t *Task) SetCopiesNumber(v uint32) {
|
||||
t.quantity = v
|
||||
}
|
||||
|
||||
// WithObjectAddress sets address of local object.
|
||||
func (t *Task) WithObjectAddress(v oid.Address) *Task {
|
||||
if t != nil {
|
||||
t.addr = v
|
||||
}
|
||||
|
||||
return t
|
||||
// SetObjectAddress sets address of local object.
|
||||
func (t *Task) SetObjectAddress(v oid.Address) {
|
||||
t.addr = v
|
||||
}
|
||||
|
||||
// WithObject sets object to avoid fetching it from the local storage.
|
||||
func (t *Task) WithObject(obj *objectSDK.Object) *Task {
|
||||
if t != nil {
|
||||
t.obj = obj
|
||||
}
|
||||
|
||||
return t
|
||||
// SetObject sets object to avoid fetching it from the local storage.
|
||||
func (t *Task) SetObject(obj *objectSDK.Object) {
|
||||
t.obj = obj
|
||||
}
|
||||
|
||||
// WithNodes sets a list of potential object holders.
|
||||
func (t *Task) WithNodes(v []netmap.NodeInfo) *Task {
|
||||
if t != nil {
|
||||
t.nodes = v
|
||||
}
|
||||
|
||||
return t
|
||||
// SetNodes sets a list of potential object holders.
|
||||
func (t *Task) SetNodes(v []netmap.NodeInfo) {
|
||||
t.nodes = v
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue