[#1412] searchSvc: Check container is indexed
For non S3 containers it is expected to use attributes index for some attributes. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
1efa64ee72
commit
4572fa4874
9 changed files with 41 additions and 16 deletions
|
@ -174,7 +174,7 @@ func initObjectService(c *cfg) {
|
|||
|
||||
sPutV2 := createPutSvcV2(sPut, keyStorage)
|
||||
|
||||
sSearch := createSearchSvc(c, keyStorage, traverseGen, c.clientCache)
|
||||
sSearch := createSearchSvc(c, keyStorage, traverseGen, c.clientCache, c.cfgObject.cnrSource)
|
||||
|
||||
sSearchV2 := createSearchSvcV2(sSearch, keyStorage)
|
||||
|
||||
|
@ -366,7 +366,7 @@ func createPatchSvc(sGet *getsvc.Service, sPut *putsvc.Service) *patchsvc.Servic
|
|||
return patchsvc.NewService(sPut.Config, sGet)
|
||||
}
|
||||
|
||||
func createSearchSvc(c *cfg, keyStorage *util.KeyStorage, traverseGen *util.TraverserGenerator, coreConstructor *cache.ClientCache) *searchsvc.Service {
|
||||
func createSearchSvc(c *cfg, keyStorage *util.KeyStorage, traverseGen *util.TraverserGenerator, coreConstructor *cache.ClientCache, containerSource containercore.Source) *searchsvc.Service {
|
||||
ls := c.cfgObject.cfgLocalStorage.localStorage
|
||||
|
||||
return searchsvc.New(
|
||||
|
@ -377,6 +377,7 @@ func createSearchSvc(c *cfg, keyStorage *util.KeyStorage, traverseGen *util.Trav
|
|||
),
|
||||
c.netMapSource,
|
||||
keyStorage,
|
||||
containerSource,
|
||||
searchsvc.WithLogger(c.log),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ func (e *StorageEngine) deleteChildren(ctx context.Context, addr oid.Address, fo
|
|||
|
||||
var selectPrm shard.SelectPrm
|
||||
selectPrm.SetFilters(fs)
|
||||
selectPrm.SetContainerID(addr.Container())
|
||||
selectPrm.SetContainerID(addr.Container(), false) // doesn't matter for search by splitID
|
||||
|
||||
var inhumePrm shard.InhumePrm
|
||||
if force {
|
||||
|
|
|
@ -49,7 +49,7 @@ func TestStorageEngine_Inhume(t *testing.T) {
|
|||
_, err = e.Inhume(context.Background(), inhumePrm)
|
||||
require.NoError(t, err)
|
||||
|
||||
addrs, err := Select(context.Background(), e, cnr, fs)
|
||||
addrs, err := Select(context.Background(), e, cnr, false, fs)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, addrs)
|
||||
})
|
||||
|
@ -78,7 +78,7 @@ func TestStorageEngine_Inhume(t *testing.T) {
|
|||
_, err = e.Inhume(context.Background(), inhumePrm)
|
||||
require.NoError(t, err)
|
||||
|
||||
addrs, err := Select(context.Background(), e, cnr, fs)
|
||||
addrs, err := Select(context.Background(), e, cnr, false, fs)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, addrs)
|
||||
})
|
||||
|
|
|
@ -16,6 +16,7 @@ import (
|
|||
type SelectPrm struct {
|
||||
cnr cid.ID
|
||||
filters objectSDK.SearchFilters
|
||||
indexedContainer bool
|
||||
}
|
||||
|
||||
// SelectRes groups the resulting values of Select operation.
|
||||
|
@ -24,8 +25,9 @@ type SelectRes struct {
|
|||
}
|
||||
|
||||
// WithContainerID is a Select option to set the container id to search in.
|
||||
func (p *SelectPrm) WithContainerID(cnr cid.ID) {
|
||||
func (p *SelectPrm) WithContainerID(cnr cid.ID, indexedContainer bool) {
|
||||
p.cnr = cnr
|
||||
p.indexedContainer = indexedContainer
|
||||
}
|
||||
|
||||
// WithFilters is a Select option to set the object filters.
|
||||
|
@ -67,7 +69,7 @@ func (e *StorageEngine) _select(ctx context.Context, prm SelectPrm) (SelectRes,
|
|||
var outError error
|
||||
|
||||
var shPrm shard.SelectPrm
|
||||
shPrm.SetContainerID(prm.cnr)
|
||||
shPrm.SetContainerID(prm.cnr, prm.indexedContainer)
|
||||
shPrm.SetFilters(prm.filters)
|
||||
|
||||
e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
|
||||
|
@ -140,9 +142,9 @@ func (e *StorageEngine) list(ctx context.Context, limit uint64) (SelectRes, erro
|
|||
}
|
||||
|
||||
// Select selects objects from local storage using provided filters.
|
||||
func Select(ctx context.Context, storage *StorageEngine, cnr cid.ID, fs objectSDK.SearchFilters) ([]oid.Address, error) {
|
||||
func Select(ctx context.Context, storage *StorageEngine, cnr cid.ID, isIndexedContainer bool, fs objectSDK.SearchFilters) ([]oid.Address, error) {
|
||||
var selectPrm SelectPrm
|
||||
selectPrm.WithContainerID(cnr)
|
||||
selectPrm.WithContainerID(cnr, isIndexedContainer)
|
||||
selectPrm.WithFilters(fs)
|
||||
|
||||
res, err := storage.Select(ctx, selectPrm)
|
||||
|
|
|
@ -50,7 +50,7 @@ func benchmarkTreeVsSearch(b *testing.B, objCount int) {
|
|||
|
||||
b.Run("search", func(b *testing.B) {
|
||||
var prm SelectPrm
|
||||
prm.WithContainerID(cid)
|
||||
prm.WithContainerID(cid, true)
|
||||
|
||||
var fs objectSDK.SearchFilters
|
||||
fs.AddFilter(pilorama.AttributeFilename, strconv.Itoa(objCount/2), objectSDK.MatchStringEqual)
|
||||
|
|
|
@ -17,6 +17,7 @@ import (
|
|||
type SelectPrm struct {
|
||||
cnr cid.ID
|
||||
filters objectSDK.SearchFilters
|
||||
isIndexedContainer bool
|
||||
}
|
||||
|
||||
// SelectRes groups the resulting values of Select operation.
|
||||
|
@ -25,8 +26,9 @@ type SelectRes struct {
|
|||
}
|
||||
|
||||
// SetContainerID is a Select option to set the container id to search in.
|
||||
func (p *SelectPrm) SetContainerID(cnr cid.ID) {
|
||||
func (p *SelectPrm) SetContainerID(cnr cid.ID, isIndexedContainer bool) {
|
||||
p.cnr = cnr
|
||||
p.isIndexedContainer = isIndexedContainer
|
||||
}
|
||||
|
||||
// SetFilters is a Select option to set the object filters.
|
||||
|
@ -61,6 +63,7 @@ func (s *Shard) Select(ctx context.Context, prm SelectPrm) (SelectRes, error) {
|
|||
var selectPrm meta.SelectPrm
|
||||
selectPrm.SetFilters(prm.filters)
|
||||
selectPrm.SetContainerID(prm.cnr)
|
||||
selectPrm.SetUseAttributeIndex(prm.isIndexedContainer)
|
||||
|
||||
mRes, err := s.metaBase.Select(ctx, selectPrm)
|
||||
if err != nil {
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/client"
|
||||
containerSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
@ -112,3 +113,12 @@ func (exec *execCtx) processCurrentEpoch(ctx context.Context) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (exec *execCtx) getContainer() (containerSDK.Container, error) {
|
||||
cnrID := exec.containerID()
|
||||
cnr, err := exec.svc.containerSource.Get(cnrID)
|
||||
if err != nil {
|
||||
return containerSDK.Container{}, err
|
||||
}
|
||||
return cnr.Value, nil
|
||||
}
|
||||
|
|
|
@ -54,6 +54,8 @@ type cfg struct {
|
|||
}
|
||||
|
||||
keyStore *util.KeyStorage
|
||||
|
||||
containerSource container.Source
|
||||
}
|
||||
|
||||
// New creates, initializes and returns utility serving
|
||||
|
@ -63,6 +65,7 @@ func New(e *engine.StorageEngine,
|
|||
tg *util.TraverserGenerator,
|
||||
ns netmap.Source,
|
||||
ks *util.KeyStorage,
|
||||
cs container.Source,
|
||||
opts ...Option,
|
||||
) *Service {
|
||||
c := &cfg{
|
||||
|
@ -76,6 +79,7 @@ func New(e *engine.StorageEngine,
|
|||
traverserGenerator: tg,
|
||||
currentEpochReceiver: ns,
|
||||
keyStore: ks,
|
||||
containerSource: cs,
|
||||
}
|
||||
|
||||
for i := range opts {
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"sync"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/client"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/container"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/engine"
|
||||
internalclient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/internal/client"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util"
|
||||
|
@ -112,9 +113,13 @@ func (c *clientWrapper) searchObjects(ctx context.Context, exec *execCtx, info c
|
|||
}
|
||||
|
||||
func (e *storageEngineWrapper) search(ctx context.Context, exec *execCtx) ([]oid.ID, error) {
|
||||
cnr, err := exec.getContainer()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var selectPrm engine.SelectPrm
|
||||
selectPrm.WithFilters(exec.searchFilters())
|
||||
selectPrm.WithContainerID(exec.containerID())
|
||||
selectPrm.WithContainerID(exec.containerID(), container.IsIndexedContainer(cnr))
|
||||
|
||||
r, err := e.storage.Select(ctx, selectPrm)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue