[#1178] shard: Check metabase existence before read shard ID

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2024-06-17 09:47:53 +03:00
parent b9d6c9d10c
commit 76cf7a051b

View file

@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"fmt"
"os"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/metaerr"
metamode "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
@ -25,6 +26,10 @@ func (db *DB) GetShardID(mode metamode.Mode) ([]byte, error) {
defer db.modeMtx.Unlock()
db.mode = mode
if _, err := os.Stat(db.info.Path); errors.Is(err, os.ErrNotExist) {
return nil, nil
}
if err := db.openDB(mode); err != nil {
return nil, fmt.Errorf("failed to open metabase: %w", err)
}