2020-09-22 06:51:47 +00:00
|
|
|
package searchsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-10-01 11:49:10 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
2020-09-28 15:11:11 +00:00
|
|
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
2020-09-22 06:51:47 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/bucket"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/localstore"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/search/query"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type localStream struct {
|
|
|
|
query query.Query
|
|
|
|
|
|
|
|
storage *localstore.Storage
|
2020-10-01 11:49:10 +00:00
|
|
|
|
|
|
|
cid *container.ID
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 15:11:11 +00:00
|
|
|
type searchQueryFilter struct {
|
|
|
|
localstore.FilterPipeline
|
2020-09-22 06:51:47 +00:00
|
|
|
|
2020-09-28 15:11:11 +00:00
|
|
|
query query.Query
|
|
|
|
|
|
|
|
ch chan<- []*objectSDK.ID
|
2020-10-01 11:49:10 +00:00
|
|
|
|
|
|
|
cid *container.ID
|
2020-09-28 15:11:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *localStream) stream(ctx context.Context, ch chan<- []*objectSDK.ID) error {
|
|
|
|
filter := &searchQueryFilter{
|
|
|
|
query: s.query,
|
|
|
|
ch: ch,
|
2020-10-01 11:49:10 +00:00
|
|
|
cid: s.cid,
|
2020-09-28 15:11:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := s.storage.Iterate(filter, func(meta *localstore.ObjectMeta) bool {
|
2020-09-22 06:51:47 +00:00
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}); err != nil && !errors.Is(errors.Cause(err), bucket.ErrIteratingAborted) {
|
|
|
|
return errors.Wrapf(err, "(%T) could not iterate over local storage", s)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-28 15:11:11 +00:00
|
|
|
func (f *searchQueryFilter) Pass(ctx context.Context, meta *localstore.ObjectMeta) *localstore.FilterResult {
|
2020-10-01 12:12:39 +00:00
|
|
|
if obj := meta.Head(); f.cid.Equal(obj.GetContainerID()) {
|
|
|
|
f.query.Match(meta.Head(), func(id *objectSDK.ID) {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return
|
|
|
|
case f.ch <- []*objectSDK.ID{id}:
|
|
|
|
}
|
|
|
|
})
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 15:11:11 +00:00
|
|
|
return localstore.ResultPass()
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|