2020-12-10 12:26:40 +00:00
|
|
|
package searchsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2020-12-10 12:26:40 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Search serves a request to select the objects.
|
|
|
|
func (s *Service) Search(ctx context.Context, prm Prm) error {
|
|
|
|
exec := &execCtx{
|
|
|
|
svc: s,
|
|
|
|
prm: prm,
|
|
|
|
}
|
|
|
|
|
|
|
|
exec.prepare()
|
|
|
|
|
|
|
|
exec.setLogger(s.log)
|
|
|
|
|
2023-04-04 09:54:21 +00:00
|
|
|
exec.execute(ctx)
|
2020-12-10 12:26:40 +00:00
|
|
|
|
|
|
|
return exec.statusError.err
|
|
|
|
}
|
|
|
|
|
2023-04-04 09:54:21 +00:00
|
|
|
func (exec *execCtx) execute(ctx context.Context) {
|
2023-04-13 12:51:36 +00:00
|
|
|
exec.log.Debug(logs.ServingRequest)
|
2020-12-10 12:26:40 +00:00
|
|
|
|
|
|
|
// perform local operation
|
2023-04-12 14:01:29 +00:00
|
|
|
exec.executeLocal(ctx)
|
2020-12-10 12:26:40 +00:00
|
|
|
|
2023-04-04 09:54:21 +00:00
|
|
|
exec.analyzeStatus(ctx, true)
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
|
2023-04-04 09:54:21 +00:00
|
|
|
func (exec *execCtx) analyzeStatus(ctx context.Context, execCnr bool) {
|
2020-12-10 12:26:40 +00:00
|
|
|
// analyze local result
|
|
|
|
switch exec.status {
|
|
|
|
default:
|
2023-04-13 12:51:36 +00:00
|
|
|
exec.log.Debug(logs.OperationFinishedWithError,
|
2020-12-10 12:26:40 +00:00
|
|
|
zap.String("error", exec.err.Error()),
|
|
|
|
)
|
|
|
|
case statusOK:
|
2023-04-13 12:51:36 +00:00
|
|
|
exec.log.Debug(logs.OperationFinishedSuccessfully)
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if execCnr {
|
2023-04-04 09:54:21 +00:00
|
|
|
exec.executeOnContainer(ctx)
|
|
|
|
exec.analyzeStatus(ctx, false)
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
}
|