forked from TrueCloudLab/frostfs-node
[#1599] engine: Parallelize shard initialization
Shard is intended to be used as a separate failure domain, which usually resides on a separate disk. Thus, sequential initialization is bound by IO and this change speeds up thing a bit. Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
6eb5260562
commit
72c044e2eb
1 changed files with 36 additions and 4 deletions
|
@ -3,7 +3,9 @@ package engine
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -16,9 +18,24 @@ func (e *StorageEngine) open() error {
|
||||||
e.mtx.RLock()
|
e.mtx.RLock()
|
||||||
defer e.mtx.RUnlock()
|
defer e.mtx.RUnlock()
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
var errCh = make(chan error, len(e.shards))
|
||||||
|
|
||||||
for id, sh := range e.shards {
|
for id, sh := range e.shards {
|
||||||
|
wg.Add(1)
|
||||||
|
go func(id string, sh *shard.Shard) {
|
||||||
|
defer wg.Done()
|
||||||
if err := sh.Open(); err != nil {
|
if err := sh.Open(); err != nil {
|
||||||
return fmt.Errorf("could not open shard %s: %w", id, err)
|
errCh <- fmt.Errorf("could not open shard %s: %w", id, err)
|
||||||
|
}
|
||||||
|
}(id, sh.Shard)
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
close(errCh)
|
||||||
|
|
||||||
|
for err := range errCh {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,9 +47,24 @@ func (e *StorageEngine) Init() error {
|
||||||
e.mtx.RLock()
|
e.mtx.RLock()
|
||||||
defer e.mtx.RUnlock()
|
defer e.mtx.RUnlock()
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
var errCh = make(chan error, len(e.shards))
|
||||||
|
|
||||||
for id, sh := range e.shards {
|
for id, sh := range e.shards {
|
||||||
|
wg.Add(1)
|
||||||
|
go func(id string, sh *shard.Shard) {
|
||||||
|
defer wg.Done()
|
||||||
if err := sh.Init(); err != nil {
|
if err := sh.Init(); err != nil {
|
||||||
return fmt.Errorf("could not initialize shard %s: %w", id, err)
|
errCh <- fmt.Errorf("could not initialize shard %s: %w", id, err)
|
||||||
|
}
|
||||||
|
}(id, sh.Shard)
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
close(errCh)
|
||||||
|
|
||||||
|
for err := range errCh {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue