[#186] localstorage: Implement utility functions over StorageEngine

Implement Put/Get/GetRange/Select/SelectAll functions over storage
engine. These functions are going to be used by Object service.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-19 11:15:49 +03:00 committed by Alex Vanin
parent 70a65c5aff
commit 9a4cd01eb8
4 changed files with 63 additions and 0 deletions

View file

@ -97,3 +97,28 @@ func (e *StorageEngine) Get(prm *GetPrm) (*GetRes, error) {
obj: obj, obj: obj,
}, nil }, nil
} }
// Get reads object from local storage by provided address.
func Get(storage *StorageEngine, addr *objectSDK.Address) (*object.Object, error) {
res, err := storage.Get(new(GetPrm).
WithAddress(addr),
)
if err != nil {
return nil, err
}
return res.Object(), nil
}
// GetRange reads object payload range from local storage by provided address.
func GetRange(storage *StorageEngine, addr *objectSDK.Address, rng *objectSDK.Range) ([]byte, error) {
res, err := storage.Get(new(GetPrm).
WithAddress(addr).
WithPayloadRange(rng.GetOffset(), rng.GetLength()),
)
if err != nil {
return nil, err
}
return res.Object().Payload(), nil
}

View file

@ -73,3 +73,15 @@ func (e *StorageEngine) Head(prm *HeadPrm) (*HeadRes, error) {
head: head, head: head,
}, nil }, nil
} }
// Head reads object header from local storage by provided address.
func Head(storage *StorageEngine, addr *objectSDK.Address) (*object.Object, error) {
res, err := storage.Head(new(HeadPrm).
WithAddress(addr),
)
if err != nil {
return nil, err
}
return res.Header(), nil
}

View file

@ -89,3 +89,12 @@ func (e *StorageEngine) objectExists(obj *object.Object, shards []*shard.Shard)
return exists return exists
} }
// Put writes provided object to local storage.
func Put(storage *StorageEngine, obj *object.Object) error {
_, err := storage.Put(new(PutPrm).
WithObject(obj),
)
return err
}

View file

@ -58,3 +58,20 @@ func (e *StorageEngine) Select(prm *SelectPrm) (*SelectRes, error) {
addrList: addrList, addrList: addrList,
}, nil }, nil
} }
// Select selects objects from local storage using provided filters.
func Select(storage *StorageEngine, fs object.SearchFilters) ([]*object.Address, error) {
res, err := storage.Select(new(SelectPrm).
WithFilters(fs),
)
if err != nil {
return nil, err
}
return res.AddressList(), nil
}
// SelectAll selects all objects from local storage.
func SelectAll(storage *StorageEngine) ([]*object.Address, error) {
return Select(storage, object.SearchFilters{})
}