Skip to content

Commit

Permalink
engine: Do not use zero weights for sorting shards
Browse files Browse the repository at this point in the history
Every shard has a zero weight. It is useless and worked only because of the
falling back to the simple sorting in the HRW library.

Signed-off-by: Pavel Karpy <[email protected]>
  • Loading branch information
carpawell committed Nov 15, 2023
1 parent b67a268 commit a1cbaac
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 30 deletions.
7 changes: 1 addition & 6 deletions pkg/local_object_storage/engine/evacuate.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ func (e *StorageEngine) Evacuate(prm EvacuateShardPrm) (EvacuateShardRes, error)
}
e.mtx.RUnlock()

weights := make([]float64, 0, len(shards))
for i := range shards {
weights = append(weights, e.shardWeight(shards[i].Shard))
}

shardMap := make(map[string]*shard.Shard)
for i := range sidList {
for j := range shards {
Expand Down Expand Up @@ -152,7 +147,7 @@ mainLoop:
return res, err
}

hrw.SortWeighted(shards, weights, addrHash)
hrw.Sort(shards, addrHash)
for j := range shards {
if _, ok := shardMap[shards[j].ID().String()]; ok {
continue
Expand Down
9 changes: 0 additions & 9 deletions pkg/local_object_storage/engine/shards.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,22 +192,13 @@ func generateShardID() (*shard.ID, error) {
return shard.NewIDFromBytes(bin), nil
}

func (e *StorageEngine) shardWeight(sh *shard.Shard) float64 {
weightValues := sh.WeightValues()

return float64(weightValues.FreeSpace)
}

func (e *StorageEngine) sortShardsByWeight(objAddr interface{ EncodeToString() string }) []hashedShard {
e.mtx.RLock()
defer e.mtx.RUnlock()

shards := make([]hashedShard, 0, len(e.shards))
weights := make([]float64, 0, len(e.shards))

for _, sh := range e.shards {
shards = append(shards, hashedShard(sh))
weights = append(weights, e.shardWeight(sh.Shard))
}

hrw.Sort(shards, hrw.WrapBytes([]byte(objAddr.EncodeToString())))
Expand Down
3 changes: 0 additions & 3 deletions pkg/local_object_storage/shard/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ type Info struct {
// Information about the Write Cache.
WriteCacheInfo writecache.Info

// Weight parameters of the shard.
WeightValues WeightValues

// ErrorCount contains amount of errors occurred in shard operations.
ErrorCount uint32

Expand Down
12 changes: 0 additions & 12 deletions pkg/local_object_storage/shard/weight.go

This file was deleted.

0 comments on commit a1cbaac

Please sign in to comment.