2022-07-05 04:55:46 +00:00
|
|
|
package blobstor
|
|
|
|
|
|
|
|
import (
|
2023-08-31 16:26:47 +00:00
|
|
|
"context"
|
2022-07-05 04:55:46 +00:00
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
2022-07-05 04:55:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// SetMode sets the blobstor mode of operation.
|
2024-10-21 08:56:38 +00:00
|
|
|
func (b *BlobStor) SetMode(ctx context.Context, m mode.Mode) error {
|
2022-07-05 04:55:46 +00:00
|
|
|
b.modeMtx.Lock()
|
|
|
|
defer b.modeMtx.Unlock()
|
|
|
|
|
|
|
|
if b.mode == m {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if b.mode.ReadOnly() == m.ReadOnly() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
err := b.Close()
|
|
|
|
if err == nil {
|
2024-10-21 08:56:38 +00:00
|
|
|
if err = b.openBlobStor(ctx, m); err == nil {
|
2022-07-05 04:55:46 +00:00
|
|
|
err = b.Init()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("can't set blobstor mode (old=%s, new=%s): %w", b.mode, m, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
b.mode = m
|
2024-03-28 13:12:33 +00:00
|
|
|
b.metrics.SetMode(m.ReadOnly())
|
2022-07-05 04:55:46 +00:00
|
|
|
return nil
|
|
|
|
}
|