2020-11-19 12:41:10 +00:00
|
|
|
package shard
|
|
|
|
|
2022-01-18 12:47:16 +00:00
|
|
|
import (
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
|
2022-01-18 12:47:16 +00:00
|
|
|
)
|
2021-12-27 11:03:15 +00:00
|
|
|
|
|
|
|
// ErrReadOnlyMode is returned when it is impossible to apply operation
|
|
|
|
// that changes shard's memory due to the "read-only" shard's mode.
|
2022-10-31 07:02:30 +00:00
|
|
|
var ErrReadOnlyMode = logicerr.New("shard is in read-only mode")
|
2021-12-27 11:03:15 +00:00
|
|
|
|
2022-06-29 11:27:36 +00:00
|
|
|
// ErrDegradedMode is returned when operation requiring metabase is executed in degraded mode.
|
2022-10-31 07:02:30 +00:00
|
|
|
var ErrDegradedMode = logicerr.New("shard is in degraded mode")
|
2022-06-29 11:27:36 +00:00
|
|
|
|
2020-11-19 12:56:10 +00:00
|
|
|
// SetMode sets mode of the shard.
|
|
|
|
//
|
|
|
|
// Returns any error encountered that did not allow
|
2021-12-27 11:03:15 +00:00
|
|
|
// setting shard mode.
|
2022-06-28 14:05:08 +00:00
|
|
|
func (s *Shard) SetMode(m mode.Mode) error {
|
2021-12-27 18:07:02 +00:00
|
|
|
s.m.Lock()
|
|
|
|
defer s.m.Unlock()
|
|
|
|
|
2022-10-16 11:39:47 +00:00
|
|
|
return s.setMode(m)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Shard) setMode(m mode.Mode) error {
|
2022-07-05 04:55:46 +00:00
|
|
|
components := []interface{ SetMode(mode.Mode) error }{
|
|
|
|
s.metaBase, s.blobStor,
|
|
|
|
}
|
|
|
|
|
2022-01-18 12:47:16 +00:00
|
|
|
if s.hasWriteCache() {
|
2022-07-05 04:55:46 +00:00
|
|
|
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]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range components {
|
|
|
|
if err := components[i].SetMode(m); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-01-18 12:47:16 +00:00
|
|
|
}
|
|
|
|
|
2021-12-27 18:07:02 +00:00
|
|
|
s.info.Mode = m
|
2022-12-09 13:52:13 +00:00
|
|
|
if s.metricsWriter != nil {
|
|
|
|
s.metricsWriter.SetReadonly(s.info.Mode != mode.ReadWrite)
|
|
|
|
}
|
2020-11-19 13:51:58 +00:00
|
|
|
|
|
|
|
return nil
|
2020-11-19 12:56:10 +00:00
|
|
|
}
|
|
|
|
|
2021-12-27 18:07:02 +00:00
|
|
|
// GetMode returns mode of the shard.
|
2022-06-28 14:05:08 +00:00
|
|
|
func (s *Shard) GetMode() mode.Mode {
|
2021-12-27 18:07:02 +00:00
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
return s.info.Mode
|
2020-11-19 12:56:10 +00:00
|
|
|
}
|