[#188] localstorage: Implement SetShardMode method

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-19 16:04:04 +03:00 committed by Alex Vanin
parent 3fa3661cad
commit cba87a1300

View file

@ -10,6 +10,8 @@ import (
"github.com/pkg/errors"
)
var errShardNotFound = errors.New("shard not found")
// AddShard adds a new shard to the storage engine.
//
// Returns any error encountered that did not allow adding a shard.
@ -72,3 +74,19 @@ func (e *StorageEngine) iterateOverSortedShards(addr *object.Address, handler fu
}
}
}
// SetShardMode sets mode of the shard with provided identifier.
//
// Returns an error if shard mode was not set, or shard was not found in storage engine.
func (e *StorageEngine) SetShardMode(id *shard.ID, m shard.Mode) error {
e.mtx.RLock()
defer e.mtx.RUnlock()
for shID, sh := range e.shards {
if id.String() == shID {
return sh.SetMode(m)
}
}
return errShardNotFound
}