Check if metabase file exists before read shard ID #1178

Merged
fyrchik merged 1 commit from dstepanov-yadro/frostfs-node:fix/update_shard_id into master 2024-06-17 07:44:57 +00:00

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) {
Review

The error happens on shard ID update, but we change ReadShardID, which should function in RO mode. Why so?

The error happens on shard ID update, but we change `ReadShardID`, which should function in RO mode. Why so?
Review

See next line: db.openDB(mode) creates DB file if DB doesn't exist.

See next line: `db.openDB(mode)` creates DB file if DB doesn't exist.
return nil, nil
}
if err := db.openDB(mode); err != nil {
return nil, fmt.Errorf("failed to open metabase: %w", err)
}