2022-07-05 04:55:46 +00:00
|
|
|
package blobstor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/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 {
|
|
|
|
if err = b.Open(m.ReadOnly()); err == nil {
|
|
|
|
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
|
|
|
|
return nil
|
|
|
|
}
|