[#965] policer: Implement continuous replication
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
20f0b29a6e
commit
a74a402a7d
5 changed files with 145 additions and 159 deletions
|
@ -1,8 +1,9 @@
|
|||
package policer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/rand"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||
)
|
||||
|
||||
|
@ -10,23 +11,15 @@ type jobQueue struct {
|
|||
localStorage *engine.StorageEngine
|
||||
}
|
||||
|
||||
func (q *jobQueue) Select(limit int) ([]*object.Address, error) {
|
||||
// TODO: optimize the logic for selecting objects
|
||||
// We can prioritize objects for migration, newly arrived objects, etc.
|
||||
// It is recommended to make changes after updating the metabase
|
||||
func (q *jobQueue) Select(cursor *engine.Cursor, count uint32) ([]*object.Address, *engine.Cursor, error) {
|
||||
prm := new(engine.ListWithCursorPrm)
|
||||
prm.WithCursor(cursor)
|
||||
prm.WithCount(count)
|
||||
|
||||
res, err := engine.List(q.localStorage, 0) // consider some limit
|
||||
res, err := q.localStorage.ListWithCursor(prm)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, fmt.Errorf("cannot list objects in engine: %w", err)
|
||||
}
|
||||
|
||||
rand.New().Shuffle(len(res), func(i, j int) {
|
||||
res[i], res[j] = res[j], res[i]
|
||||
})
|
||||
|
||||
if len(res) < limit {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
return res[:limit], nil
|
||||
return res.AddressList(), res.Cursor(), nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue