2020-11-19 12:41:10 +00:00
|
|
|
package shard
|
|
|
|
|
2022-01-18 12:47:16 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2022-06-28 14:05:08 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
|
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.
|
|
|
|
var ErrReadOnlyMode = errors.New("shard is in read-only mode")
|
|
|
|
|
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-01-18 12:47:16 +00:00
|
|
|
if s.hasWriteCache() {
|
2022-06-28 14:05:08 +00:00
|
|
|
s.writeCache.SetMode(m)
|
2022-01-18 12:47:16 +00:00
|
|
|
}
|
|
|
|
|
2021-12-27 18:07:02 +00:00
|
|
|
s.info.Mode = m
|
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
|
|
|
}
|