forked from TrueCloudLab/frostfs-node
[#109] services: Implement Replicator service
Implement Replicator service that performs background work to replicate local object to remote nodes in the container. Replicator is going to be used by Policer. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
53efa18e14
commit
2d46baa4a5
3 changed files with 228 additions and 0 deletions
53
pkg/services/replicator/task.go
Normal file
53
pkg/services/replicator/task.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
package replicator
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
)
|
||||
|
||||
// Task represents group of Replicator task parameters.
|
||||
type Task struct {
|
||||
quantity uint32
|
||||
|
||||
addr *object.Address
|
||||
|
||||
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.
|
||||
func (t *Task) WithObjectAddress(v *object.Address) *Task {
|
||||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue