frostfs-node/pkg/local_object_storage/blobstor/mode.go
Ekaterina Lebedeva ef55443cf8
All checks were successful
DCO action / DCO (pull_request) Successful in 1m53s
Build / Build Components (1.21) (pull_request) Successful in 2m52s
Vulncheck / Vulncheck (pull_request) Successful in 3m26s
Build / Build Components (1.20) (pull_request) Successful in 4m26s
Tests and linters / Staticcheck (pull_request) Successful in 6m54s
Tests and linters / Lint (pull_request) Successful in 8m48s
Tests and linters / gopls check (pull_request) Successful in 8m31s
Tests and linters / Tests (1.20) (pull_request) Successful in 12m13s
Tests and linters / Tests (1.21) (pull_request) Successful in 12m46s
Tests and linters / Tests with -race (pull_request) Successful in 13m26s
[#1055] blobstor: fix mode metric
It used to always show CLOSED after setting shard mode
to read-only regardless of actual mode.
Now metric represents actual blobstor mode of operations.

Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
2024-03-28 16:12:33 +03:00

36 lines
647 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.openBlobStor(context.TODO(), m); 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
b.metrics.SetMode(m.ReadOnly())
return nil
}