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-08-24 18:44:55 +00:00
|
|
|
return exec.execute(ctx)
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
|
2023-08-24 18:44:55 +00:00
|
|
|
func (exec *execCtx) execute(ctx context.Context) error {
|
2023-04-13 12:51:36 +00:00
|
|
|
exec.log.Debug(logs.ServingRequest)
|
2020-12-10 12:26:40 +00:00
|
|
|
|
2023-08-24 18:44:55 +00:00
|
|
|
err := exec.executeLocal(ctx)
|
|
|
|
exec.logResult(err)
|
|
|
|
|
|
|
|
if exec.isLocal() {
|
|
|
|
exec.log.Debug(logs.SearchReturnResultDirectly)
|
|
|
|
return err
|
|
|
|
}
|
2020-12-10 12:26:40 +00:00
|
|
|
|
2023-08-24 18:44:55 +00:00
|
|
|
err = exec.executeOnContainer(ctx)
|
|
|
|
exec.logResult(err)
|
|
|
|
return err
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
|
2023-08-24 18:44:55 +00:00
|
|
|
func (exec *execCtx) logResult(err error) {
|
|
|
|
switch {
|
2020-12-10 12:26:40 +00:00
|
|
|
default:
|
2023-08-24 18:44:55 +00:00
|
|
|
exec.log.Debug(logs.OperationFinishedWithError, zap.String("error", err.Error()))
|
|
|
|
case err == nil:
|
2023-04-13 12:51:36 +00:00
|
|
|
exec.log.Debug(logs.OperationFinishedSuccessfully)
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
}
|