Dmitrii Stepanov
692749dba1
Some checks failed
DCO action / DCO (pull_request) Failing after 1m30s
Tests and linters / Run gofumpt (pull_request) Successful in 1m26s
Vulncheck / Vulncheck (pull_request) Successful in 2m11s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m25s
Build / Build Components (pull_request) Successful in 2m29s
Tests and linters / Lint (pull_request) Failing after 2m26s
Tests and linters / gopls check (pull_request) Successful in 2m43s
Tests and linters / Staticcheck (pull_request) Successful in 2m56s
Tests and linters / Tests (pull_request) Successful in 4m22s
Tests and linters / Tests with -race (pull_request) Successful in 5m58s
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
83 lines
2.2 KiB
Go
83 lines
2.2 KiB
Go
package shard
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// ErrReadOnlyMode is returned when it is impossible to apply operation
|
|
// that changes shard's memory due to the "read-only" shard's mode.
|
|
var ErrReadOnlyMode = logicerr.New("shard is in read-only mode")
|
|
|
|
// ErrDegradedMode is returned when operation requiring metabase is executed in degraded mode.
|
|
var ErrDegradedMode = logicerr.New("shard is in degraded mode")
|
|
|
|
// SetMode sets mode of the shard.
|
|
//
|
|
// Returns any error encountered that did not allow
|
|
// setting shard mode.
|
|
func (s *Shard) SetMode(m mode.Mode) error {
|
|
unlock := s.lockExclusive()
|
|
defer unlock()
|
|
|
|
return s.setMode(m)
|
|
}
|
|
|
|
func (s *Shard) setMode(m mode.Mode) error {
|
|
s.log.Info(context.Background(), logs.ShardSettingShardMode,
|
|
zap.Stringer("old_mode", s.info.Mode),
|
|
zap.Stringer("new_mode", m))
|
|
|
|
components := []interface{ SetMode(mode.Mode) error }{
|
|
s.metaBase, s.blobStor,
|
|
}
|
|
|
|
if s.hasWriteCache() {
|
|
components = append(components, s.writeCache)
|
|
}
|
|
|
|
if s.pilorama != nil {
|
|
components = append(components, s.pilorama)
|
|
}
|
|
|
|
// The usual flow of the requests (pilorama is independent):
|
|
// writecache -> blobstor -> metabase
|
|
// For mode.ReadOnly and mode.Degraded the order is:
|
|
// writecache -> blobstor -> metabase
|
|
// For mode.ReadWrite it is the opposite:
|
|
// metabase -> blobstor -> writecache
|
|
if m != mode.ReadWrite {
|
|
if s.hasWriteCache() {
|
|
components[0], components[2] = components[2], components[0]
|
|
} else {
|
|
components[0], components[1] = components[1], components[0]
|
|
}
|
|
}
|
|
|
|
if !m.Disabled() {
|
|
for i := range components {
|
|
if err := components[i].SetMode(m); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
s.info.Mode = m
|
|
s.metricsWriter.SetMode(s.info.Mode)
|
|
|
|
s.log.Info(context.Background(), logs.ShardShardModeSetSuccessfully,
|
|
zap.Stringer("mode", s.info.Mode))
|
|
return nil
|
|
}
|
|
|
|
// GetMode returns mode of the shard.
|
|
func (s *Shard) GetMode() mode.Mode {
|
|
s.m.RLock()
|
|
defer s.m.RUnlock()
|
|
|
|
return s.info.Mode
|
|
}
|