2020-10-21 11:49:02 +00:00
|
|
|
package replicator
|
|
|
|
|
|
|
|
import (
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
2022-01-26 12:11:13 +00:00
|
|
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
2020-10-21 11:49:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Task represents group of Replicator task parameters.
|
|
|
|
type Task struct {
|
|
|
|
quantity uint32
|
|
|
|
|
2022-01-26 12:11:13 +00:00
|
|
|
addr *addressSDK.Address
|
2020-10-21 11:49:02 +00:00
|
|
|
|
|
|
|
nodes netmap.Nodes
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddTask pushes replication task to Replicator queue.
|
|
|
|
//
|
|
|
|
// If task queue is full, log message is written.
|
|
|
|
func (p *Replicator) AddTask(t *Task) {
|
|
|
|
select {
|
|
|
|
case p.ch <- t:
|
|
|
|
default:
|
|
|
|
p.log.Warn("task queue is full")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithCopiesNumber sets number of copies to replicate.
|
|
|
|
func (t *Task) WithCopiesNumber(v uint32) *Task {
|
|
|
|
if t != nil {
|
|
|
|
t.quantity = v
|
|
|
|
}
|
|
|
|
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithObjectAddress sets address of local object.
|
2022-01-26 12:11:13 +00:00
|
|
|
func (t *Task) WithObjectAddress(v *addressSDK.Address) *Task {
|
2020-10-21 11:49:02 +00:00
|
|
|
if t != nil {
|
|
|
|
t.addr = v
|
|
|
|
}
|
|
|
|
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithNodes sets list of potential object holders.
|
|
|
|
func (t *Task) WithNodes(v netmap.Nodes) *Task {
|
|
|
|
if t != nil {
|
|
|
|
t.nodes = v
|
|
|
|
}
|
|
|
|
|
|
|
|
return t
|
|
|
|
}
|