-
Notifications
You must be signed in to change notification settings - Fork 48
Aggregate Cleanup #446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
allenss-amazon
merged 7 commits into
valkey-io:main
from
allenss-amazon:aggregate-testing
Nov 7, 2025
Merged
Aggregate Cleanup #446
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5a2ba0b
Re-enable unit testing
allenss-amazon 97776a9
respond to review comments
allenss-amazon 5d27e1f
Combine command processing between FT.SEARCH and FT.AGGREGATE
allenss-amazon cb0cd1c
more unification between FT.SEARCH and FT.AGGREGATE
allenss-amazon 868c74f
spellings
allenss-amazon 7cff905
Merge branch 'main' into aggregate-testing
allenss-amazon 58bc9c7
Merge branch 'main' into aggregate-testing
allenss-amazon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| CompileFlags: | ||
| Add: | ||
| - "-ferror-limit=0" | ||
| - "-DRunningClangd" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| /* | ||
| * Copyright (c) 2025, valkey-search contributors | ||
| * All rights reserved. | ||
| * SPDX-License-Identifier: BSD 3-Clause | ||
| * | ||
| */ | ||
|
|
||
| #include "src/commands/commands.h" | ||
|
|
||
| #include "fanout.h" | ||
| #include "ft_create_parser.h" | ||
| #include "src/acl.h" | ||
| #include "src/commands/ft_search.h" | ||
| #include "src/query/search.h" | ||
| #include "src/schema_manager.h" | ||
| #include "src/valkey_search.h" | ||
| #include "valkey_search_options.h" | ||
| #include "vmsdk/src/debug.h" | ||
|
|
||
| namespace valkey_search { | ||
| namespace async { | ||
|
|
||
| struct Result { | ||
| cancel::Token cancellation_token; | ||
| absl::StatusOr<std::deque<indexes::Neighbor>> neighbors; | ||
| std::unique_ptr<QueryCommand> parameters; | ||
| }; | ||
|
|
||
| int Timeout(ValkeyModuleCtx *ctx, [[maybe_unused]] ValkeyModuleString **argv, | ||
| [[maybe_unused]] int argc) { | ||
| return ValkeyModule_ReplyWithError( | ||
| ctx, "Search operation cancelled due to timeout"); | ||
| } | ||
|
|
||
| int Reply(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) { | ||
| auto *res = | ||
| static_cast<Result *>(ValkeyModule_GetBlockedClientPrivateData(ctx)); | ||
| CHECK(res != nullptr); | ||
| if (!res->neighbors.ok()) { | ||
| ++Metrics::GetStats().query_failed_requests_cnt; | ||
| return ValkeyModule_ReplyWithError( | ||
| ctx, res->neighbors.status().message().data()); | ||
| } | ||
| res->parameters->SendReply(ctx, res->neighbors.value()); | ||
| return VALKEYMODULE_OK; | ||
| } | ||
|
|
||
| void Free([[maybe_unused]] ValkeyModuleCtx *ctx, void *privdata) { | ||
| auto *result = static_cast<Result *>(privdata); | ||
| delete result; | ||
| } | ||
|
|
||
| } // namespace async | ||
|
|
||
| CONTROLLED_BOOLEAN(ForceReplicasOnly, false); | ||
|
|
||
| // | ||
| // Common Class for FT.SEARCH and FT.AGGREGATE command | ||
| // | ||
| absl::Status QueryCommand::Execute(ValkeyModuleCtx *ctx, | ||
| ValkeyModuleString **argv, int argc, | ||
| std::unique_ptr<QueryCommand> parameters) { | ||
| auto status = [&]() -> absl::Status { | ||
| auto &schema_manager = SchemaManager::Instance(); | ||
| vmsdk::ArgsIterator itr{argv + 1, argc - 1}; | ||
| parameters->timeout_ms = options::GetDefaultTimeoutMs().GetValue(); | ||
| VMSDK_RETURN_IF_ERROR( | ||
| vmsdk::ParseParamValue(itr, parameters->index_schema_name)); | ||
| VMSDK_ASSIGN_OR_RETURN( | ||
| parameters->index_schema, | ||
| SchemaManager::Instance().GetIndexSchema( | ||
| ValkeyModule_GetSelectedDb(ctx), parameters->index_schema_name)); | ||
| VMSDK_RETURN_IF_ERROR( | ||
| vmsdk::ParseParamValue(itr, parameters->parse_vars.query_string)); | ||
| VMSDK_RETURN_IF_ERROR(parameters->ParseCommand(itr)); | ||
| parameters->parse_vars.ClearAtEndOfParse(); | ||
| parameters->cancellation_token = | ||
| cancel::Make(parameters->timeout_ms, nullptr); | ||
| static const auto permissions = | ||
| PrefixACLPermissions(kSearchCmdPermissions, kSearchCommand); | ||
| VMSDK_RETURN_IF_ERROR(AclPrefixCheck( | ||
| ctx, permissions, parameters->index_schema->GetKeyPrefixes())); | ||
|
|
||
| parameters->index_schema->ProcessMultiQueue(); | ||
|
|
||
| const bool inside_multi_exec = vmsdk::MultiOrLua(ctx); | ||
| if (ABSL_PREDICT_FALSE(!ValkeySearch::Instance().SupportParallelQueries() || | ||
| inside_multi_exec)) { | ||
| VMSDK_ASSIGN_OR_RETURN( | ||
| auto neighbors, | ||
| query::Search(*parameters, query::SearchMode::kLocal)); | ||
| if (!options::GetEnablePartialResults().GetValue() && | ||
| parameters->cancellation_token->IsCancelled()) { | ||
| ValkeyModule_ReplyWithError( | ||
| ctx, "Search operation cancelled due to timeout"); | ||
| ++Metrics::GetStats().query_failed_requests_cnt; | ||
| return absl::OkStatus(); | ||
| } | ||
| parameters->SendReply(ctx, neighbors); | ||
| return absl::OkStatus(); | ||
| } | ||
|
|
||
| vmsdk::BlockedClient blocked_client(ctx, async::Reply, async::Timeout, | ||
| async::Free, parameters->timeout_ms); | ||
| blocked_client.MeasureTimeStart(); | ||
| auto on_done_callback = [blocked_client = std::move(blocked_client)]( | ||
| auto &neighbors, auto parameters) mutable { | ||
| std::unique_ptr<QueryCommand> upcast_parameters( | ||
| dynamic_cast<QueryCommand *>(parameters.release())); | ||
| CHECK(upcast_parameters != nullptr); | ||
| auto result = std::make_unique<async::Result>(async::Result{ | ||
| .neighbors = std::move(neighbors), | ||
| .parameters = std::move(upcast_parameters), | ||
| }); | ||
| blocked_client.SetReplyPrivateData(result.release()); | ||
| }; | ||
|
|
||
| if (ValkeySearch::Instance().UsingCoordinator() && | ||
| ValkeySearch::Instance().IsCluster() && !parameters->local_only) { | ||
| auto mode = /* !vmsdk::IsReadOnly(ctx) ? query::fanout::kPrimaries ? */ | ||
| ForceReplicasOnly.GetValue() | ||
| ? query::fanout::FanoutTargetMode::kReplicasOnly | ||
| : query::fanout::FanoutTargetMode::kRandom; | ||
| auto search_targets = query::fanout::GetSearchTargetsForFanout(ctx, mode); | ||
| return query::fanout::PerformSearchFanoutAsync( | ||
| ctx, search_targets, | ||
| ValkeySearch::Instance().GetCoordinatorClientPool(), | ||
| std::move(parameters), ValkeySearch::Instance().GetReaderThreadPool(), | ||
| std::move(on_done_callback)); | ||
| } | ||
| return query::SearchAsync( | ||
| std::move(parameters), ValkeySearch::Instance().GetReaderThreadPool(), | ||
| std::move(on_done_callback), query::SearchMode::kLocal); | ||
| }(); | ||
| if (!status.ok()) { | ||
| ++Metrics::GetStats().query_failed_requests_cnt; | ||
| } | ||
| return status; | ||
| } | ||
|
|
||
| } // namespace valkey_search | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is using the old code in fanout_template.h. With the new cluster map, this can be replaced by ValkeySearch()::Instance().GetClusterMap()->GetRandomTargets()/GetReplicaTargets(). A switch clause might be needed here to determine the get target mode.
If the ctx is valid here (which I think should be the case), we should use ValkeySearch()::Instance().GetOrRefreshClusterMap()