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.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 {
|
2024-10-21 07:22:54 +00:00
|
|
|
exec.log.Debug(ctx, 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() {
|
2024-10-21 07:22:54 +00:00
|
|
|
exec.log.Debug(ctx, logs.SearchReturnResultDirectly)
|
2023-08-24 18:44:55 +00:00
|
|
|
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:
|
2024-10-21 07:22:54 +00:00
|
|
|
exec.log.Debug(context.Background(), logs.OperationFinishedWithError, zap.String("error", err.Error()))
|
2023-08-24 18:44:55 +00:00
|
|
|
case err == nil:
|
2024-10-21 07:22:54 +00:00
|
|
|
exec.log.Debug(context.Background(), logs.OperationFinishedSuccessfully)
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
}
|