frostfs-node/pkg/local_object_storage/blobstor/mode.go
Evgenii Stratonikov 58668e6bc3
storage: Remove "could not/can't/failed to" from error messages
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-12-18 09:38:14 +03:00

36 lines
657 B
Go

package blobstor
import (
"context"
"fmt"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
)
// SetMode sets the blobstor mode of operation.
func (b *BlobStor) SetMode(ctx context.Context, m mode.Mode) error {
b.modeMtx.Lock()
defer b.modeMtx.Unlock()
if b.mode == m {
return nil
}
if b.mode.ReadOnly() == m.ReadOnly() {
return nil
}
err := b.Close(ctx)
if err == nil {
if err = b.openBlobStor(ctx, m); err == nil {
err = b.Init(ctx)
}
}
if err != nil {
return fmt.Errorf("set blobstor mode (old=%s, new=%s): %w", b.mode, m, err)
}
b.mode = m
b.metrics.SetMode(m.ReadOnly())
return nil
}