forked from TrueCloudLab/frostfs-node
Evgenii Stratonikov
9098d0eec0
All operations must ensure the shard is not in a degraded mode. Write operations must also ensure the shard is not in a read-only mode. Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
204 lines
5.1 KiB
Go
204 lines
5.1 KiB
Go
package shard
|
|
|
|
import (
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/pilorama"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
|
|
cidSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
)
|
|
|
|
var _ pilorama.Forest = (*Shard)(nil)
|
|
|
|
// ErrPiloramaDisabled is returned when pilorama was disabled in the configuration.
|
|
var ErrPiloramaDisabled = logicerr.New("pilorama is disabled")
|
|
|
|
// TreeMove implements the pilorama.Forest interface.
|
|
func (s *Shard) TreeMove(d pilorama.CIDDescriptor, treeID string, m *pilorama.Move) (*pilorama.Move, error) {
|
|
if s.pilorama == nil {
|
|
return nil, ErrPiloramaDisabled
|
|
}
|
|
|
|
s.m.RLock()
|
|
defer s.m.RUnlock()
|
|
|
|
if s.info.Mode.ReadOnly() {
|
|
return nil, ErrReadOnlyMode
|
|
}
|
|
if s.info.Mode.NoMetabase() {
|
|
return nil, ErrDegradedMode
|
|
}
|
|
return s.pilorama.TreeMove(d, treeID, m)
|
|
}
|
|
|
|
// TreeAddByPath implements the pilorama.Forest interface.
|
|
func (s *Shard) TreeAddByPath(d pilorama.CIDDescriptor, treeID string, attr string, path []string, meta []pilorama.KeyValue) ([]pilorama.Move, error) {
|
|
if s.pilorama == nil {
|
|
return nil, ErrPiloramaDisabled
|
|
}
|
|
|
|
s.m.RLock()
|
|
defer s.m.RUnlock()
|
|
|
|
if s.info.Mode.ReadOnly() {
|
|
return nil, ErrReadOnlyMode
|
|
}
|
|
if s.info.Mode.NoMetabase() {
|
|
return nil, ErrDegradedMode
|
|
}
|
|
return s.pilorama.TreeAddByPath(d, treeID, attr, path, meta)
|
|
}
|
|
|
|
// TreeApply implements the pilorama.Forest interface.
|
|
func (s *Shard) TreeApply(cnr cidSDK.ID, treeID string, m *pilorama.Move, backgroundSync bool) error {
|
|
if s.pilorama == nil {
|
|
return ErrPiloramaDisabled
|
|
}
|
|
|
|
s.m.RLock()
|
|
defer s.m.RUnlock()
|
|
|
|
if s.info.Mode.ReadOnly() {
|
|
return ErrReadOnlyMode
|
|
}
|
|
if s.info.Mode.NoMetabase() {
|
|
return ErrDegradedMode
|
|
}
|
|
return s.pilorama.TreeApply(cnr, treeID, m, backgroundSync)
|
|
}
|
|
|
|
// TreeGetByPath implements the pilorama.Forest interface.
|
|
func (s *Shard) TreeGetByPath(cid cidSDK.ID, treeID string, attr string, path []string, latest bool) ([]pilorama.Node, error) {
|
|
if s.pilorama == nil {
|
|
return nil, ErrPiloramaDisabled
|
|
}
|
|
|
|
s.m.RLock()
|
|
defer s.m.RUnlock()
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
return nil, ErrDegradedMode
|
|
}
|
|
return s.pilorama.TreeGetByPath(cid, treeID, attr, path, latest)
|
|
}
|
|
|
|
// TreeGetMeta implements the pilorama.Forest interface.
|
|
func (s *Shard) TreeGetMeta(cid cidSDK.ID, treeID string, nodeID pilorama.Node) (pilorama.Meta, uint64, error) {
|
|
if s.pilorama == nil {
|
|
return pilorama.Meta{}, 0, ErrPiloramaDisabled
|
|
}
|
|
|
|
s.m.RLock()
|
|
defer s.m.RUnlock()
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
return pilorama.Meta{}, 0, ErrDegradedMode
|
|
}
|
|
return s.pilorama.TreeGetMeta(cid, treeID, nodeID)
|
|
}
|
|
|
|
// TreeGetChildren implements the pilorama.Forest interface.
|
|
func (s *Shard) TreeGetChildren(cid cidSDK.ID, treeID string, nodeID pilorama.Node) ([]uint64, error) {
|
|
if s.pilorama == nil {
|
|
return nil, ErrPiloramaDisabled
|
|
}
|
|
|
|
s.m.RLock()
|
|
defer s.m.RUnlock()
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
return nil, ErrDegradedMode
|
|
}
|
|
return s.pilorama.TreeGetChildren(cid, treeID, nodeID)
|
|
}
|
|
|
|
// TreeGetOpLog implements the pilorama.Forest interface.
|
|
func (s *Shard) TreeGetOpLog(cid cidSDK.ID, treeID string, height uint64) (pilorama.Move, error) {
|
|
if s.pilorama == nil {
|
|
return pilorama.Move{}, ErrPiloramaDisabled
|
|
}
|
|
|
|
s.m.RLock()
|
|
defer s.m.RUnlock()
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
return pilorama.Move{}, ErrDegradedMode
|
|
}
|
|
return s.pilorama.TreeGetOpLog(cid, treeID, height)
|
|
}
|
|
|
|
// TreeDrop implements the pilorama.Forest interface.
|
|
func (s *Shard) TreeDrop(cid cidSDK.ID, treeID string) error {
|
|
if s.pilorama == nil {
|
|
return ErrPiloramaDisabled
|
|
}
|
|
|
|
s.m.RLock()
|
|
defer s.m.RUnlock()
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
return ErrDegradedMode
|
|
}
|
|
return s.pilorama.TreeDrop(cid, treeID)
|
|
}
|
|
|
|
// TreeList implements the pilorama.Forest interface.
|
|
func (s *Shard) TreeList(cid cidSDK.ID) ([]string, error) {
|
|
if s.pilorama == nil {
|
|
return nil, ErrPiloramaDisabled
|
|
}
|
|
|
|
s.m.RLock()
|
|
defer s.m.RUnlock()
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
return nil, ErrDegradedMode
|
|
}
|
|
return s.pilorama.TreeList(cid)
|
|
}
|
|
|
|
// TreeExists implements the pilorama.Forest interface.
|
|
func (s *Shard) TreeExists(cid cidSDK.ID, treeID string) (bool, error) {
|
|
if s.pilorama == nil {
|
|
return false, ErrPiloramaDisabled
|
|
}
|
|
|
|
s.m.RLock()
|
|
defer s.m.RUnlock()
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
return false, ErrDegradedMode
|
|
}
|
|
return s.pilorama.TreeExists(cid, treeID)
|
|
}
|
|
|
|
// TreeUpdateLastSyncHeight implements the pilorama.Forest interface.
|
|
func (s *Shard) TreeUpdateLastSyncHeight(cid cidSDK.ID, treeID string, height uint64) error {
|
|
if s.pilorama == nil {
|
|
return ErrPiloramaDisabled
|
|
}
|
|
|
|
s.m.RLock()
|
|
defer s.m.RUnlock()
|
|
|
|
if s.info.Mode.ReadOnly() {
|
|
return ErrReadOnlyMode
|
|
}
|
|
if s.info.Mode.NoMetabase() {
|
|
return ErrDegradedMode
|
|
}
|
|
return s.pilorama.TreeUpdateLastSyncHeight(cid, treeID, height)
|
|
}
|
|
|
|
// TreeLastSyncHeight implements the pilorama.Forest interface.
|
|
func (s *Shard) TreeLastSyncHeight(cid cidSDK.ID, treeID string) (uint64, error) {
|
|
if s.pilorama == nil {
|
|
return 0, ErrPiloramaDisabled
|
|
}
|
|
|
|
s.m.RLock()
|
|
defer s.m.RUnlock()
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
return 0, ErrDegradedMode
|
|
}
|
|
return s.pilorama.TreeLastSyncHeight(cid, treeID)
|
|
}
|