diff --git a/pkg/local_object_storage/engine/put.go b/pkg/local_object_storage/engine/put.go index 062b11a013..97c7d33070 100644 --- a/pkg/local_object_storage/engine/put.go +++ b/pkg/local_object_storage/engine/put.go @@ -46,14 +46,14 @@ func (e *StorageEngine) Put(prm *PutPrm) (*PutRes, error) { // save the object into the "largest" possible shard for _, sh := range sortedShards { - _, err := sh.Put( + _, err := sh.sh.Put( shPrm.WithObject(prm.obj), ) if err != nil { // TODO: smth wrong with shard, need to be processed e.log.Warn("could not save object in shard", - zap.Stringer("shard", sh.ID()), + zap.Stringer("shard", sh.sh.ID()), zap.String("error", err.Error()), ) } else { @@ -64,11 +64,11 @@ func (e *StorageEngine) Put(prm *PutPrm) (*PutRes, error) { return nil, errPutShard } -func (e *StorageEngine) objectExists(obj *object.Object, shards []*shard.Shard) bool { +func (e *StorageEngine) objectExists(obj *object.Object, shards []hashedShard) bool { exists := false for _, sh := range shards { - res, err := sh.Exists( + res, err := sh.sh.Exists( new(shard.ExistsPrm). WithAddress(obj.Address()), ) diff --git a/pkg/local_object_storage/engine/shards.go b/pkg/local_object_storage/engine/shards.go index a6cf3db305..5bde2759e3 100644 --- a/pkg/local_object_storage/engine/shards.go +++ b/pkg/local_object_storage/engine/shards.go @@ -12,6 +12,10 @@ import ( var errShardNotFound = errors.New("shard not found") +type hashedShard struct { + sh *shard.Shard +} + // AddShard adds a new shard to the storage engine. // // Returns any error encountered that did not allow adding a shard. @@ -50,15 +54,15 @@ func (e *StorageEngine) shardWeight(sh *shard.Shard) float64 { return float64(weightValues.FreeSpace) } -func (e *StorageEngine) sortShardsByWeight(objAddr fmt.Stringer) []*shard.Shard { +func (e *StorageEngine) sortShardsByWeight(objAddr fmt.Stringer) []hashedShard { e.mtx.RLock() defer e.mtx.RUnlock() - shards := make([]*shard.Shard, 0, len(e.shards)) + shards := make([]hashedShard, 0, len(e.shards)) weights := make([]float64, 0, len(e.shards)) for _, sh := range e.shards { - shards = append(shards, sh) + shards = append(shards, hashedShard{sh}) weights = append(weights, e.shardWeight(sh)) } @@ -69,7 +73,7 @@ func (e *StorageEngine) sortShardsByWeight(objAddr fmt.Stringer) []*shard.Shard func (e *StorageEngine) iterateOverSortedShards(addr *object.Address, handler func(*shard.Shard) (stop bool)) { for _, sh := range e.sortShardsByWeight(addr) { - if handler(sh) { + if handler(sh.sh) { break } } @@ -90,3 +94,9 @@ func (e *StorageEngine) SetShardMode(id *shard.ID, m shard.Mode) error { return errShardNotFound } + +func (s hashedShard) Hash() uint64 { + return hrw.Hash( + []byte(s.sh.ID().String()), + ) +}