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 {
|
|
|
|
loop:
|
2020-10-01 11:42:17 +00:00
|
|
|
for obj := meta.Head(); obj != nil; obj = obj.GetParent() {
|
2020-10-01 11:49:10 +00:00
|
|
|
if !f.cid.Equal(obj.GetContainerID()) || !f.query.Match(obj) {
|
2020-09-28 15:11:11 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
break loop
|
|
|
|
case f.ch <- []*objectSDK.ID{obj.GetID()}:
|
|
|
|
}
|
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
|
|
|
}
|