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.
|
|
|
|
func (b *BlobStor) SetMode(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()
|
|
|
|
if err == nil {
|
2024-02-09 06:17:17 +00:00
|
|
|
if err = b.openBlobStor(context.TODO(), 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
|
|
|
|
}
|