[TrueCloudLab/hrw#2] node: Optimize shard hash
Compute shard hash only once Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
a1ab25b33e
commit
c3a7039801
3 changed files with 21 additions and 13 deletions
|
@ -19,7 +19,7 @@ type StorageEngine struct {
|
|||
|
||||
mtx *sync.RWMutex
|
||||
|
||||
shards map[string]shardWrapper
|
||||
shards map[string]hashedShard
|
||||
|
||||
shardPools map[string]util.WorkerPool
|
||||
|
||||
|
@ -223,7 +223,7 @@ func New(opts ...Option) *StorageEngine {
|
|||
return &StorageEngine{
|
||||
cfg: c,
|
||||
mtx: new(sync.RWMutex),
|
||||
shards: make(map[string]shardWrapper),
|
||||
shards: make(map[string]hashedShard),
|
||||
shardPools: make(map[string]util.WorkerPool),
|
||||
closeCh: make(chan struct{}),
|
||||
setModeCh: make(chan setModeRequest),
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
oidtest "github.com/TrueCloudLab/frostfs-sdk-go/object/id/test"
|
||||
usertest "github.com/TrueCloudLab/frostfs-sdk-go/user/test"
|
||||
"github.com/TrueCloudLab/frostfs-sdk-go/version"
|
||||
"github.com/TrueCloudLab/hrw"
|
||||
"github.com/TrueCloudLab/tzhash/tz"
|
||||
"github.com/panjf2000/ants/v2"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -86,9 +87,12 @@ func testNewEngineWithShards(shards ...*shard.Shard) *StorageEngine {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
engine.shards[s.ID().String()] = shardWrapper{
|
||||
errorCount: atomic.NewUint32(0),
|
||||
Shard: s,
|
||||
engine.shards[s.ID().String()] = hashedShard{
|
||||
shardWrapper: shardWrapper{
|
||||
errorCount: atomic.NewUint32(0),
|
||||
Shard: s,
|
||||
},
|
||||
hash: hrw.Hash([]byte(s.ID().String())),
|
||||
}
|
||||
engine.shardPools[s.ID().String()] = pool
|
||||
}
|
||||
|
|
|
@ -16,7 +16,10 @@ import (
|
|||
|
||||
var errShardNotFound = logicerr.New("shard not found")
|
||||
|
||||
type hashedShard shardWrapper
|
||||
type hashedShard struct {
|
||||
shardWrapper
|
||||
hash uint64
|
||||
}
|
||||
|
||||
type metricsWithID struct {
|
||||
id string
|
||||
|
@ -127,9 +130,12 @@ func (e *StorageEngine) addShard(sh *shard.Shard) error {
|
|||
return fmt.Errorf("shard with id %s was already added", strID)
|
||||
}
|
||||
|
||||
e.shards[strID] = shardWrapper{
|
||||
errorCount: atomic.NewUint32(0),
|
||||
Shard: sh,
|
||||
e.shards[strID] = hashedShard{
|
||||
shardWrapper: shardWrapper{
|
||||
errorCount: atomic.NewUint32(0),
|
||||
Shard: sh,
|
||||
},
|
||||
hash: hrw.Hash([]byte(strID)),
|
||||
}
|
||||
|
||||
e.shardPools[strID] = pool
|
||||
|
@ -144,7 +150,7 @@ func (e *StorageEngine) removeShards(ids ...string) {
|
|||
return
|
||||
}
|
||||
|
||||
ss := make([]shardWrapper, 0, len(ids))
|
||||
ss := make([]hashedShard, 0, len(ids))
|
||||
|
||||
e.mtx.Lock()
|
||||
for _, id := range ids {
|
||||
|
@ -276,7 +282,5 @@ func (e *StorageEngine) HandleNewEpoch(epoch uint64) {
|
|||
}
|
||||
|
||||
func (s hashedShard) Hash() uint64 {
|
||||
return hrw.Hash(
|
||||
[]byte(s.Shard.ID().String()),
|
||||
)
|
||||
return s.hash
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue