[#1770] node: Do not lock on shard's Close
call
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
ab3ef7110e
commit
8ebe95747e
3 changed files with 21 additions and 15 deletions
|
@ -263,10 +263,7 @@ func (e *StorageEngine) Reload(rcfg ReConfiguration) error {
|
||||||
|
|
||||||
e.mtx.RUnlock()
|
e.mtx.RUnlock()
|
||||||
|
|
||||||
err := e.removeShards(shardsToRemove...)
|
e.removeShards(shardsToRemove...)
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("could not remove shards: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, newPath := range shardsToAdd {
|
for _, newPath := range shardsToAdd {
|
||||||
sh, err := e.createShard(rcfg.shards[newPath])
|
sh, err := e.createShard(rcfg.shards[newPath])
|
||||||
|
|
|
@ -115,22 +115,22 @@ func (e *StorageEngine) addShard(sh *shard.Shard) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// removeShards removes specified shards. Skips non-existent shards.
|
// removeShards removes specified shards. Skips non-existent shards.
|
||||||
// Returns any error encountered that did not allow remove the shards.
|
// Logs errors about shards that it could not Close after the removal.
|
||||||
func (e *StorageEngine) removeShards(ids ...string) error {
|
func (e *StorageEngine) removeShards(ids ...string) {
|
||||||
e.mtx.Lock()
|
if len(ids) == 0 {
|
||||||
defer e.mtx.Unlock()
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ss := make([]shardWrapper, 0, len(ids))
|
||||||
|
|
||||||
|
e.mtx.Lock()
|
||||||
for _, id := range ids {
|
for _, id := range ids {
|
||||||
sh, found := e.shards[id]
|
sh, found := e.shards[id]
|
||||||
if !found {
|
if !found {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
err := sh.Close()
|
ss = append(ss, sh)
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("could not close removed shard: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
delete(e.shards, id)
|
delete(e.shards, id)
|
||||||
|
|
||||||
pool, ok := e.shardPools[id]
|
pool, ok := e.shardPools[id]
|
||||||
|
@ -142,8 +142,17 @@ func (e *StorageEngine) removeShards(ids ...string) error {
|
||||||
e.log.Info("shard has been removed",
|
e.log.Info("shard has been removed",
|
||||||
zap.String("id", id))
|
zap.String("id", id))
|
||||||
}
|
}
|
||||||
|
e.mtx.Unlock()
|
||||||
|
|
||||||
return nil
|
for _, sh := range ss {
|
||||||
|
err := sh.Close()
|
||||||
|
if err != nil {
|
||||||
|
e.log.Error("could not close removed shard",
|
||||||
|
zap.Stringer("id", sh.ID()),
|
||||||
|
zap.Error(err),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateShardID() (*shard.ID, error) {
|
func generateShardID() (*shard.ID, error) {
|
||||||
|
|
|
@ -32,7 +32,7 @@ func TestRemoveShard(t *testing.T) {
|
||||||
|
|
||||||
for id, remove := range mSh {
|
for id, remove := range mSh {
|
||||||
if remove {
|
if remove {
|
||||||
require.NoError(t, e.removeShards(id))
|
e.removeShards(id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue