[#176] localstore: Change multiple access sync

In previous implementation each operation on local storage
locked engine mutex. This was done under the assumption that
the weights of the shards change as a result of write operations.
With the transition to static weights of shards, it is no longer
necessary to lock the global mutex during the execution of operations.
However, since the set of engine shards is dynamic, there is still a
need to control multiple access to this set. The same mutex is used
for synchronization.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-18 15:06:47 +03:00 committed by Alex Vanin
parent df558cbe6b
commit 6f8c45d61b
6 changed files with 3 additions and 15 deletions

View file

@ -30,9 +30,6 @@ func (p *DeletePrm) WithAddress(addr *objectSDK.Address) *DeletePrm {
// Returns any error encountered that did not allow to completely
// mark the object to delete.
func (e *StorageEngine) Delete(prm *DeletePrm) (*DeleteRes, error) {
e.mtx.RLock()
defer e.mtx.RUnlock()
shPrm := new(shard.DeletePrm)
e.iterateOverSortedShards(prm.addr, func(sh *shard.Shard) (stop bool) {

View file

@ -61,9 +61,6 @@ func (r *GetRes) Object() *object.Object {
//
// Returns ErrObjectNotFound if requested object is missing in local storage.
func (e *StorageEngine) Get(prm *GetPrm) (*GetRes, error) {
e.mtx.RLock()
defer e.mtx.RUnlock()
var obj *object.Object
shPrm := new(shard.GetPrm).

View file

@ -43,9 +43,6 @@ func (r *HeadRes) Header() *object.Object {
//
// Returns ErrObjectNotFound if requested object is missing in local storage.
func (e *StorageEngine) Head(prm *HeadPrm) (*HeadRes, error) {
e.mtx.RLock()
defer e.mtx.RUnlock()
var head *object.Object
shPrm := new(shard.GetPrm).

View file

@ -34,9 +34,6 @@ func (p *PutPrm) WithObject(obj *object.Object) *PutPrm {
// Returns any error encountered that
// did not allow to completely save the object.
func (e *StorageEngine) Put(prm *PutPrm) (*PutRes, error) {
e.mtx.Lock()
defer e.mtx.Unlock()
// choose shards through sorting by weight
sortedShards := e.sortShardsByWeight(prm.obj.Address())

View file

@ -35,9 +35,6 @@ func (r *SelectRes) AddressList() []*objectSDK.Address {
//
// Returns any error encountered that did not allow to completely select the objects.
func (e *StorageEngine) Select(prm *SelectPrm) (*SelectRes, error) {
e.mtx.RLock()
defer e.mtx.RUnlock()
addrList := make([]*object.Address, 0)
shPrm := new(shard.SelectPrm).

View file

@ -49,6 +49,9 @@ func (e *StorageEngine) shardWeight(sh *shard.Shard) float64 {
}
func (e *StorageEngine) sortShardsByWeight(objAddr fmt.Stringer) []*shard.Shard {
e.mtx.RLock()
defer e.mtx.RUnlock()
shards := make([]*shard.Shard, 0, len(e.shards))
weights := make([]float64, 0, len(e.shards))