[#1770] engine: Do not lock on shard init

Init can take a lot of time. Because the mutex is taken, all new operations
are blocked.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-09-28 00:43:38 +03:00 committed by fyrchik
parent fbd5bc8c38
commit 887afeaddb
2 changed files with 39 additions and 22 deletions

View file

@ -268,30 +268,29 @@ func (e *StorageEngine) Reload(rcfg ReConfiguration) error {
return fmt.Errorf("could not remove shards: %w", err)
}
e.mtx.Lock()
defer e.mtx.Unlock()
for _, newPath := range shardsToAdd {
id, err := e.addShard(rcfg.shards[newPath]...)
sh, err := e.createShard(rcfg.shards[newPath])
if err != nil {
return fmt.Errorf("could not add new shard: %w", err)
return fmt.Errorf("could not add new shard with '%s' metabase path: %w", newPath, err)
}
idStr := id.String()
sh := e.shards[idStr]
idStr := sh.ID().String()
err = sh.Open()
if err == nil {
err = sh.Init()
}
if err != nil {
delete(e.shards, idStr)
e.shardPools[idStr].Release()
delete(e.shardPools, idStr)
_ = sh.Close()
return fmt.Errorf("could not init %s shard: %w", idStr, err)
}
err = e.addShard(sh)
if err != nil {
_ = sh.Close()
return fmt.Errorf("could not add %s shard: %w", idStr, err)
}
e.log.Info("added new shard", zap.String("id", idStr))
}