2020-12-10 12:26:40 +00:00
|
|
|
package searchsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2021-09-28 04:46:10 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/client"
|
2020-12-10 12:26:40 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
2021-11-10 07:08:33 +00:00
|
|
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
2022-03-03 14:19:05 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
2022-01-26 12:11:13 +00:00
|
|
|
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2020-12-10 12:26:40 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
type statusError struct {
|
|
|
|
status int
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
|
|
|
type execCtx struct {
|
|
|
|
svc *Service
|
|
|
|
|
|
|
|
ctx context.Context
|
|
|
|
|
|
|
|
prm Prm
|
|
|
|
|
|
|
|
statusError
|
|
|
|
|
|
|
|
log *logger.Logger
|
2021-01-12 14:55:02 +00:00
|
|
|
|
|
|
|
curProcEpoch uint64
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
statusUndefined int = iota
|
|
|
|
statusOK
|
|
|
|
)
|
|
|
|
|
|
|
|
func (exec *execCtx) prepare() {
|
|
|
|
if _, ok := exec.prm.writer.(*uniqueIDWriter); !ok {
|
|
|
|
exec.prm.writer = newUniqueAddressWriter(exec.prm.writer)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (exec *execCtx) setLogger(l *logger.Logger) {
|
|
|
|
exec.log = l.With(
|
|
|
|
zap.String("request", "SEARCH"),
|
|
|
|
zap.Stringer("container", exec.containerID()),
|
|
|
|
zap.Bool("local", exec.isLocal()),
|
|
|
|
zap.Bool("with session", exec.prm.common.SessionToken() != nil),
|
|
|
|
zap.Bool("with bearer", exec.prm.common.BearerToken() != nil),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (exec execCtx) context() context.Context {
|
|
|
|
return exec.ctx
|
|
|
|
}
|
|
|
|
|
|
|
|
func (exec execCtx) isLocal() bool {
|
|
|
|
return exec.prm.common.LocalOnly()
|
|
|
|
}
|
|
|
|
|
2021-05-31 11:03:17 +00:00
|
|
|
func (exec *execCtx) containerID() *cid.ID {
|
2021-11-01 08:35:33 +00:00
|
|
|
return exec.prm.cid
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
func (exec *execCtx) searchFilters() object.SearchFilters {
|
2021-11-01 08:35:33 +00:00
|
|
|
return exec.prm.filters
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
|
2021-01-12 14:55:02 +00:00
|
|
|
func (exec *execCtx) netmapEpoch() uint64 {
|
|
|
|
return exec.prm.common.NetmapEpoch()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (exec *execCtx) netmapLookupDepth() uint64 {
|
|
|
|
return exec.prm.common.NetmapLookupDepth()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (exec *execCtx) initEpoch() bool {
|
|
|
|
exec.curProcEpoch = exec.netmapEpoch()
|
|
|
|
if exec.curProcEpoch > 0 {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
e, err := exec.svc.currentEpochReceiver.currentEpoch()
|
|
|
|
|
|
|
|
switch {
|
|
|
|
default:
|
|
|
|
exec.status = statusUndefined
|
|
|
|
exec.err = err
|
|
|
|
|
|
|
|
exec.log.Debug("could not get current epoch number",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return false
|
|
|
|
case err == nil:
|
|
|
|
exec.curProcEpoch = e
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-31 11:03:17 +00:00
|
|
|
func (exec *execCtx) generateTraverser(cid *cid.ID) (*placement.Traverser, bool) {
|
2021-01-12 14:55:02 +00:00
|
|
|
t, err := exec.svc.traverserGenerator.generateTraverser(cid, exec.curProcEpoch)
|
2020-12-10 12:26:40 +00:00
|
|
|
|
|
|
|
switch {
|
|
|
|
default:
|
|
|
|
exec.status = statusUndefined
|
|
|
|
exec.err = err
|
|
|
|
|
|
|
|
exec.log.Debug("could not generate container traverser",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return nil, false
|
|
|
|
case err == nil:
|
|
|
|
return t, true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-28 04:46:10 +00:00
|
|
|
func (exec execCtx) remoteClient(info client.NodeInfo) (searchClient, bool) {
|
|
|
|
c, err := exec.svc.clientConstructor.get(info)
|
2020-12-10 12:26:40 +00:00
|
|
|
switch {
|
|
|
|
default:
|
|
|
|
exec.status = statusUndefined
|
|
|
|
exec.err = err
|
|
|
|
|
2021-06-22 12:19:30 +00:00
|
|
|
exec.log.Debug("could not construct remote node client")
|
2020-12-10 12:26:40 +00:00
|
|
|
case err == nil:
|
2021-05-20 15:17:16 +00:00
|
|
|
return c, true
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil, false
|
|
|
|
}
|
|
|
|
|
2022-03-15 12:11:35 +00:00
|
|
|
func (exec *execCtx) writeIDList(ids []oidSDK.ID) {
|
2020-12-10 12:26:40 +00:00
|
|
|
err := exec.prm.writer.WriteIDs(ids)
|
|
|
|
|
|
|
|
switch {
|
|
|
|
default:
|
|
|
|
exec.status = statusUndefined
|
|
|
|
exec.err = err
|
|
|
|
|
|
|
|
exec.log.Debug("could not write object identifiers",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
case err == nil:
|
|
|
|
exec.status = statusOK
|
|
|
|
exec.err = nil
|
|
|
|
}
|
|
|
|
}
|