2020-12-10 12:26:40 +00:00
|
|
|
package searchsvc
|
|
|
|
|
|
|
|
import (
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
2023-07-06 12:36:41 +00:00
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2023-03-07 13:38:26 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2020-12-10 12:26:40 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
type execCtx struct {
|
|
|
|
svc *Service
|
|
|
|
|
|
|
|
prm Prm
|
|
|
|
|
|
|
|
log *logger.Logger
|
2021-01-12 14:55:02 +00:00
|
|
|
|
|
|
|
curProcEpoch uint64
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (exec *execCtx) setLogger(l *logger.Logger) {
|
2024-10-21 07:22:54 +00:00
|
|
|
exec.log = l.With(
|
2020-12-10 12:26:40 +00:00
|
|
|
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),
|
2024-10-21 07:22:54 +00:00
|
|
|
)
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
|
2024-05-27 13:05:20 +00:00
|
|
|
func (exec *execCtx) isLocal() bool {
|
2020-12-10 12:26:40 +00:00
|
|
|
return exec.prm.common.LocalOnly()
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (exec *execCtx) containerID() cid.ID {
|
|
|
|
return exec.prm.cnr
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
func (exec *execCtx) searchFilters() objectSDK.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()
|
|
|
|
}
|
|
|
|
|
2023-08-24 18:44:55 +00:00
|
|
|
func (exec *execCtx) initEpoch() error {
|
2021-01-12 14:55:02 +00:00
|
|
|
exec.curProcEpoch = exec.netmapEpoch()
|
|
|
|
if exec.curProcEpoch > 0 {
|
2023-08-24 18:44:55 +00:00
|
|
|
return nil
|
2021-01-12 14:55:02 +00:00
|
|
|
}
|
|
|
|
|
2023-08-24 17:54:29 +00:00
|
|
|
e, err := exec.svc.currentEpochReceiver.Epoch()
|
2023-08-24 18:44:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-01-12 14:55:02 +00:00
|
|
|
}
|
2020-12-10 12:26:40 +00:00
|
|
|
|
2023-08-24 18:44:55 +00:00
|
|
|
exec.curProcEpoch = e
|
|
|
|
return nil
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
|
2023-08-24 18:44:55 +00:00
|
|
|
func (exec *execCtx) writeIDList(ids []oid.ID) error {
|
2023-03-21 12:41:58 +00:00
|
|
|
ids = exec.filterAllowedObjectIDs(ids)
|
2023-08-24 18:44:55 +00:00
|
|
|
return exec.prm.writer.WriteIDs(ids)
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
2023-03-21 12:41:58 +00:00
|
|
|
|
|
|
|
func (exec *execCtx) filterAllowedObjectIDs(objIDs []oid.ID) []oid.ID {
|
|
|
|
sessionToken := exec.prm.common.SessionToken()
|
|
|
|
if sessionToken == nil {
|
|
|
|
return objIDs
|
|
|
|
}
|
|
|
|
result := make([]oid.ID, 0, len(objIDs))
|
|
|
|
for _, objID := range objIDs {
|
|
|
|
if sessionToken.AssertObject(objID) {
|
|
|
|
result = append(result, objID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|