[#1956] node: Lock shard's mode on its methods switch

Signed-off-by: Pavel Karpy <p.karpy@yadro.com>
This commit is contained in:
Pavel Karpy 2022-12-07 20:42:35 +03:00 committed by Anton Nikiforov
parent 33d279a3f2
commit eea2892109
13 changed files with 94 additions and 22 deletions

View file

@ -16,7 +16,11 @@ func (s *Shard) TreeMove(d pilorama.CIDDescriptor, treeID string, m *pilorama.Mo
if s.pilorama == nil {
return nil, ErrPiloramaDisabled
}
if s.GetMode().ReadOnly() {
s.m.RLock()
defer s.m.RUnlock()
if s.info.Mode.ReadOnly() {
return nil, ErrReadOnlyMode
}
return s.pilorama.TreeMove(d, treeID, m)
@ -27,7 +31,11 @@ func (s *Shard) TreeAddByPath(d pilorama.CIDDescriptor, treeID string, attr stri
if s.pilorama == nil {
return nil, ErrPiloramaDisabled
}
if s.GetMode().ReadOnly() {
s.m.RLock()
defer s.m.RUnlock()
if s.info.Mode.ReadOnly() {
return nil, ErrReadOnlyMode
}
return s.pilorama.TreeAddByPath(d, treeID, attr, path, meta)
@ -38,7 +46,11 @@ func (s *Shard) TreeApply(d pilorama.CIDDescriptor, treeID string, m *pilorama.M
if s.pilorama == nil {
return ErrPiloramaDisabled
}
if s.GetMode().ReadOnly() {
s.m.RLock()
defer s.m.RUnlock()
if s.info.Mode.ReadOnly() {
return ErrReadOnlyMode
}
return s.pilorama.TreeApply(d, treeID, m)