From 41ab4d070e6b700491ae741cf4d9ffbb0845105f Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 2 Jun 2023 15:39:16 +0300 Subject: [PATCH] [#423] *: Use hrw.StringHash() where possible Signed-off-by: Evgenii Stratonikov --- .../blobstor/blobovniczatree/blobovnicza.go | 2 +- pkg/local_object_storage/engine/engine_test.go | 2 +- pkg/local_object_storage/engine/evacuate.go | 2 +- pkg/local_object_storage/engine/remove_copies.go | 2 +- pkg/local_object_storage/engine/shards.go | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza.go b/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza.go index af976f9774..d99e9aa894 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza.go @@ -216,7 +216,7 @@ func addressHash(addr *oid.Address, path string) uint64 { a = addr.EncodeToString() } - return hrw.Hash([]byte(a + path)) + return hrw.StringHash(a + path) } // converts uint64 to hex string. diff --git a/pkg/local_object_storage/engine/engine_test.go b/pkg/local_object_storage/engine/engine_test.go index 9c239739f3..11c0848feb 100644 --- a/pkg/local_object_storage/engine/engine_test.go +++ b/pkg/local_object_storage/engine/engine_test.go @@ -101,7 +101,7 @@ func (te *testEngineWrapper) setInitializedShards(t testing.TB, shards ...*shard errorCount: new(atomic.Uint32), Shard: s, }, - hash: hrw.Hash([]byte(s.ID().String())), + hash: hrw.StringHash(s.ID().String()), } te.engine.shardPools[s.ID().String()] = pool te.shardIDs = append(te.shardIDs, s.ID()) diff --git a/pkg/local_object_storage/engine/evacuate.go b/pkg/local_object_storage/engine/evacuate.go index c103ede73a..73b7a78309 100644 --- a/pkg/local_object_storage/engine/evacuate.go +++ b/pkg/local_object_storage/engine/evacuate.go @@ -373,7 +373,7 @@ func (e *StorageEngine) evacuateObjects(ctx context.Context, sh *shard.Shard, to func (e *StorageEngine) tryEvacuateObjectLocal(ctx context.Context, addr oid.Address, object *objectSDK.Object, sh *shard.Shard, shards []pooledShard, weights []float64, shardsToEvacuate map[string]*shard.Shard, res *EvacuateShardRes) (bool, error) { - hrw.SortHasherSliceByWeightValue(shards, weights, hrw.Hash([]byte(addr.EncodeToString()))) + hrw.SortHasherSliceByWeightValue(shards, weights, hrw.StringHash(addr.EncodeToString())) for j := range shards { select { case <-ctx.Done(): diff --git a/pkg/local_object_storage/engine/remove_copies.go b/pkg/local_object_storage/engine/remove_copies.go index 1ea569928c..7681e0e50d 100644 --- a/pkg/local_object_storage/engine/remove_copies.go +++ b/pkg/local_object_storage/engine/remove_copies.go @@ -110,7 +110,7 @@ func (e *StorageEngine) removeObjects(ctx context.Context, ch <-chan oid.Address } for addr := range ch { - h := hrw.Hash([]byte(addr.EncodeToString())) + h := hrw.StringHash(addr.EncodeToString()) shards := sortShardsByWeight(shards, h) found := false for i := range shards { diff --git a/pkg/local_object_storage/engine/shards.go b/pkg/local_object_storage/engine/shards.go index c4c356a75e..fd9605e9ba 100644 --- a/pkg/local_object_storage/engine/shards.go +++ b/pkg/local_object_storage/engine/shards.go @@ -162,7 +162,7 @@ func (e *StorageEngine) addShard(sh *shard.Shard) error { errorCount: new(atomic.Uint32), Shard: sh, }, - hash: hrw.Hash([]byte(strID)), + hash: hrw.StringHash(strID), } e.shardPools[strID] = pool @@ -237,7 +237,7 @@ func (e *StorageEngine) sortShardsByWeight(objAddr interface{ EncodeToString() s e.mtx.RLock() defer e.mtx.RUnlock() - h := hrw.Hash([]byte(objAddr.EncodeToString())) + h := hrw.StringHash(objAddr.EncodeToString()) shards := make([]hashedShard, 0, len(e.shards)) for _, sh := range e.shards { shards = append(shards, hashedShard(sh))