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)
|
2024-10-21 13:27:28 +00:00
|
|
|
exec.logResult(ctx, err)
|
2023-08-24 18:44:55 +00:00
|
|
|
|
|
|
|
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)
|
2024-10-21 13:27:28 +00:00
|
|
|
exec.logResult(ctx, err)
|
2023-08-24 18:44:55 +00:00
|
|
|
return err
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
func (exec *execCtx) logResult(ctx context.Context, err error) {
|
2023-08-24 18:44:55 +00:00
|
|
|
switch {
|
2020-12-10 12:26:40 +00:00
|
|
|
default:
|
2024-12-13 08:44:56 +00:00
|
|
|
exec.log.Debug(ctx, logs.OperationFinishedWithError, zap.Error(err))
|
2023-08-24 18:44:55 +00:00
|
|
|
case err == nil:
|
2024-10-21 13:27:28 +00:00
|
|
|
exec.log.Debug(ctx, logs.OperationFinishedSuccessfully)
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
}
|