forked from TrueCloudLab/frostfs-node
[#428] engine: Add low_mem config parameter
Concurrent initialization in case of the metabase resync leads to high memory consumption and potential OOM. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
71a63b8e9c
commit
cac4ed93d6
7 changed files with 44 additions and 10 deletions
|
@ -12,6 +12,7 @@ import (
|
|||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
||||
"go.uber.org/zap"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
type shardInitError struct {
|
||||
|
@ -74,23 +75,30 @@ func (e *StorageEngine) Init(ctx context.Context) error {
|
|||
e.mtx.Lock()
|
||||
defer e.mtx.Unlock()
|
||||
|
||||
var wg sync.WaitGroup
|
||||
var errCh = make(chan shardInitError, len(e.shards))
|
||||
var eg errgroup.Group
|
||||
if e.cfg.lowMem && e.anyShardRequiresRefill() {
|
||||
eg.SetLimit(1)
|
||||
}
|
||||
|
||||
for id, sh := range e.shards {
|
||||
wg.Add(1)
|
||||
go func(id string, sh *shard.Shard) {
|
||||
defer wg.Done()
|
||||
id := id
|
||||
sh := sh
|
||||
eg.Go(func() error {
|
||||
if err := sh.Init(ctx); err != nil {
|
||||
errCh <- shardInitError{
|
||||
err: err,
|
||||
id: id,
|
||||
}
|
||||
}
|
||||
}(id, sh.Shard)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
wg.Wait()
|
||||
err := eg.Wait()
|
||||
close(errCh)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to initialize shards: %w", err)
|
||||
}
|
||||
|
||||
for res := range errCh {
|
||||
if res.err != nil {
|
||||
|
@ -125,6 +133,15 @@ func (e *StorageEngine) Init(ctx context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (e *StorageEngine) anyShardRequiresRefill() bool {
|
||||
for _, sh := range e.shards {
|
||||
if sh.NeedRefillMetabase() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var errClosed = errors.New("storage engine is closed")
|
||||
|
||||
// Close releases all StorageEngine's components. Waits for all data-related operations to complete.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue