Ekaterina Lebedeva
8a81af5a3b
All checks were successful
DCO action / DCO (pull_request) Successful in 1m38s
Build / Build Components (1.20) (pull_request) Successful in 4m22s
Build / Build Components (1.21) (pull_request) Successful in 4m25s
Vulncheck / Vulncheck (pull_request) Successful in 4m56s
Tests and linters / Lint (pull_request) Successful in 6m1s
Tests and linters / Tests (1.20) (pull_request) Successful in 7m43s
Tests and linters / Staticcheck (pull_request) Successful in 8m1s
Tests and linters / Tests (1.21) (pull_request) Successful in 8m14s
Tests and linters / Tests with -race (pull_request) Successful in 8m32s
Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
35 lines
617 B
Go
35 lines
617 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(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(context.TODO(), 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
|
|
}
|