-
Notifications
You must be signed in to change notification settings - Fork 92
feat(query-coordinator): Implement Spider query graph submission. #2521
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
Open
Bill-hbrhbr
wants to merge
50
commits into
y-scope:main
Choose a base branch
from
Bill-hbrhbr:query-coordinator/graph-submission
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
0b03851
Init
Bill-hbrhbr dbc1986
Change search to query; Add msgpack tests
Bill-hbrhbr d8f992e
Merge branch 'main' into query-coordinator-tdl
Bill-hbrhbr 4b2acb6
Create and submitter skeleton
Bill-hbrhbr d13c6e6
docs(clp-tdl-package): Clarify package task scope
Bill-hbrhbr 0ba6fe5
docs(clp-tdl-package): Clarify package task scope
Bill-hbrhbr 1198719
Merge branch 'main' into query-coordinator-tdl
Bill-hbrhbr 6298f54
polish
Bill-hbrhbr ff5bc49
Update components/clp-rust-utils/src/task_io/query.rs
Bill-hbrhbr 37396cd
Update components/clp-rust-utils/src/task_io/query.rs
Bill-hbrhbr da02988
Change to milliseconds
Bill-hbrhbr bf2ebc0
Update components/clp-tdl-package/src/task/query/mod.rs
Bill-hbrhbr ba425f5
Merge branch 'main' into query-coordinator-tdl
Bill-hbrhbr 0296f0c
Remove task redundant description
Bill-hbrhbr 2096e9b
Add query job ID type
Bill-hbrhbr cb87c6e
Make query task dataset optional
Bill-hbrhbr f8a68a6
Require non-empty query task strings
Bill-hbrhbr d5c0450
Use shared default for query result limit
Bill-hbrhbr ca2ebe2
Lint fix remove unused
Bill-hbrhbr 9429396
Remove unused query task output
Bill-hbrhbr 323acfc
Rename task
Bill-hbrhbr 8f509ef
Add query task output handle
Bill-hbrhbr b67cb70
Fix todo uppercase
Bill-hbrhbr 61fd27e
Merge branch 'main' into query-coordinator-tdl
Bill-hbrhbr 3bee52b
Document Python mirror for query result limit default
Bill-hbrhbr c39b086
Name query task output handle parameter after its type
Bill-hbrhbr 3cee914
Fix symbol ordering
Bill-hbrhbr 789f671
Use clp-s default query result limit
Bill-hbrhbr 184d940
Apply batched suggestions from code review
Bill-hbrhbr c479fad
Propagate rename
Bill-hbrhbr cfa0a97
lint fix
Bill-hbrhbr c592252
Merge branch 'main' into query-coordinator/crate
Bill-hbrhbr e5937b7
Merge branch 'query-coordinator-tdl' into query-coordinator/crate
Bill-hbrhbr 89ca7b5
Fix inconsistencies
Bill-hbrhbr 4e063fb
Add missing output handle arg
Bill-hbrhbr 842c93c
Address review comments
Bill-hbrhbr 2e689fe
Add trailing comma
Bill-hbrhbr b2fed1f
Apply batched suggestions from code review
Bill-hbrhbr e5f0501
Apply suggestion from @LinZhihao-723
Bill-hbrhbr e0566a7
docs(query-coordinator): Fix deferred API documentation
Bill-hbrhbr 4891cf8
fix(query-coordinator): Return errors from staging paths
Bill-hbrhbr 4a45d04
Change back to todo
Bill-hbrhbr ce692e8
Merge branch 'main' into query-coordinator/crate
Bill-hbrhbr c2208f4
feat(query-coordinator): Implement Spider query graph submission.
Bill-hbrhbr ae0ccc0
Add docstrings
Bill-hbrhbr 4a1df55
Remove empty task input check
Bill-hbrhbr c12a79f
Remove single use variables
Bill-hbrhbr d64afcb
style(query-coordinator): Align submitter spacing and simplify comments.
Bill-hbrhbr ddbe7f5
Lint fix
Bill-hbrhbr 4d23f5d
Address review comments
Bill-hbrhbr 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| pub mod compression; | ||
| pub mod query; |
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,31 @@ | ||
| //! Protocol types exchanged with the Spider (Huntsman) tasks that run CLP query jobs. | ||
|
|
||
| use std::num::NonZeroU32; | ||
|
|
||
| use non_empty_string::NonEmptyString; | ||
| use serde::Deserialize; | ||
| use serde::Serialize; | ||
|
|
||
| /// `clp-s` options for a query job. | ||
| #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] | ||
| pub struct ClpSQueryOption { | ||
| /// The query string passed positionally to `clp-s`. | ||
| pub query_string: NonEmptyString, | ||
|
|
||
| /// The per-archive result limit. When absent, the task omits `--max-num-results` and uses the | ||
| /// `clp-s` default. | ||
| pub max_num_results: Option<NonZeroU32>, | ||
|
|
||
| /// Inclusive `--tge` bound in Unix epoch milliseconds. | ||
| pub begin_timestamp_millisecs: Option<i64>, | ||
|
|
||
| /// Inclusive `--tle` bound in Unix epoch milliseconds. | ||
| pub end_timestamp_millisecs: Option<i64>, | ||
|
|
||
| /// Whether `clp-s` performs a case-insensitive search. | ||
| pub ignore_case: bool, | ||
| } | ||
|
|
||
| /// The output handler that `clp-s` writes a query task's results to. | ||
| #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] | ||
| pub enum OutputHandle {} | ||
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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| //! The task implementations this package registers with Spider. | ||
|
|
||
| pub mod compression; | ||
| pub mod query; |
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,21 @@ | ||
| //! The query-task signatures registered with Spider. | ||
|
|
||
| use clp_rust_utils::job_config::ArchiveId; | ||
| use clp_rust_utils::job_config::QueryJobId; | ||
| use clp_rust_utils::task_io::query::ClpSQueryOption; | ||
| use clp_rust_utils::task_io::query::OutputHandle; | ||
| use non_empty_string::NonEmptyString; | ||
| use spider_tdl::TaskContext; | ||
| use spider_tdl::task; | ||
|
|
||
| #[task(name = "query::clp_s_search")] | ||
| pub(crate) fn clp_s_search_task( | ||
| _ctx: TaskContext, | ||
| _query_job_id: QueryJobId, | ||
| _clp_s_query_option: ClpSQueryOption, | ||
| _dataset: Option<NonEmptyString>, | ||
| _archive_id: ArchiveId, | ||
| _output_handle: OutputHandle, | ||
| ) -> Result<(), spider_tdl::TdlError> { | ||
| todo!("clp-s search task is not implemented") | ||
|
Bill-hbrhbr marked this conversation as resolved.
|
||
| } | ||
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,14 @@ | ||
| [package] | ||
| name = "query-coordinator" | ||
| version = { workspace = true } | ||
| edition = { workspace = true } | ||
|
|
||
| [dependencies] | ||
| async-trait = { workspace = true } | ||
| clp-rust-utils = { workspace = true } | ||
| non-empty-string = { workspace = true } | ||
| rmp-serde = { workspace = true } | ||
| spider-client = { workspace = true } | ||
| spider-core = { workspace = true } | ||
| thiserror = { workspace = true } | ||
| tracing = { workspace = true } |
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,14 @@ | ||
| //! The crate-level error type for the query coordinator. | ||
|
|
||
| /// Errors returned by the query coordinator. | ||
| #[derive(Debug, thiserror::Error)] | ||
| pub enum Error { | ||
| #[error("spider request failure: {0}")] | ||
| SpiderClient(#[from] spider_client::error::ClientError), | ||
|
|
||
| #[error("failed to build the query task graph: {0}")] | ||
| TaskGraph(#[from] spider_core::task::Error), | ||
|
|
||
| #[error("failed to serialize a task input: {0}")] | ||
| TaskInputSerialization(#[from] rmp_serde::encode::Error), | ||
| } |
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,6 @@ | ||
| //! Coordination for CLP query jobs. | ||
|
|
||
| mod error; | ||
| pub mod query_job_submitter; | ||
|
|
||
| pub use error::Error; |
60 changes: 60 additions & 0 deletions
60
components/query-coordinator/src/query_job_submitter/mod.rs
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,60 @@ | ||
| //! The query-job submission interface. | ||
|
|
||
| mod spider; | ||
|
|
||
| use async_trait::async_trait; | ||
| use clp_rust_utils::job_config::ArchiveId; | ||
| use clp_rust_utils::job_config::QueryJobId; | ||
| use clp_rust_utils::task_io::query::ClpSQueryOption; | ||
| use clp_rust_utils::task_io::query::OutputHandle; | ||
| use non_empty_string::NonEmptyString; | ||
| use spider_core::task::ExecutionPolicy; | ||
| use spider_core::types::id::JobId; | ||
| use spider_core::types::id::ResourceGroupId; | ||
|
|
||
| use crate::Error; | ||
|
|
||
| /// Identifies an archive handled by query tasks. | ||
| #[derive(Clone, Debug, Eq, PartialEq)] | ||
| pub struct ArchiveMetadata { | ||
| /// The archive's ID. | ||
| pub id: ArchiveId, | ||
|
|
||
| /// The archive's dataset, or `None` for the default dataset. | ||
| pub dataset: Option<NonEmptyString>, | ||
|
|
||
| /// The archive's compressed size in bytes. | ||
| pub size: u64, | ||
| } | ||
|
|
||
| /// Drives CLP query jobs on a Spider (Huntsman) cluster. | ||
| #[async_trait] | ||
| pub trait QueryJobSubmitter: Clone + Send + Sync { | ||
| /// Builds the query task graph for the given archives and registers it with Spider, without | ||
| /// starting it. | ||
| /// | ||
| /// # Parameters | ||
| /// | ||
| /// * `query_job_id` - The unique ID of the CLP query job. | ||
| /// * `resource_group_id` - The Spider resource group to register the job under. | ||
| /// * `clp_s_query_option` - `clp-s` query options shared by every task in the job. | ||
| /// * `output_handle` - The output handle selecting how the query outputs are returned. | ||
| /// * `archives_to_search` - The archives to search, each represents a query task paired with | ||
| /// the task execution policy. | ||
| /// | ||
| /// # Returns | ||
| /// | ||
| /// The job ID issued by Spider on success. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Implementations must document their error conditions. | ||
| async fn submit_query_job( | ||
| &self, | ||
| query_job_id: QueryJobId, | ||
| resource_group_id: ResourceGroupId, | ||
| clp_s_query_option: ClpSQueryOption, | ||
| output_handle: OutputHandle, | ||
| archives_to_search: Vec<(ArchiveMetadata, ExecutionPolicy)>, | ||
| ) -> Result<JobId, Error>; | ||
| } |
120 changes: 120 additions & 0 deletions
120
components/query-coordinator/src/query_job_submitter/spider.rs
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,120 @@ | ||
| //! [`QueryJobSubmitter`] implementation for [`spider_client::SpiderClient`]. | ||
|
|
||
| use async_trait::async_trait; | ||
| use clp_rust_utils::job_config::QueryJobId; | ||
| use clp_rust_utils::task_io::query::ClpSQueryOption; | ||
| use clp_rust_utils::task_io::query::OutputHandle; | ||
| use spider_client::SpiderClient; | ||
| use spider_core::task::DataTypeDescriptor; | ||
| use spider_core::task::ExecutionPolicy; | ||
| use spider_core::task::TaskDescriptor; | ||
| use spider_core::task::TaskGraph; | ||
| use spider_core::task::TdlContext; | ||
| use spider_core::task::ValueTypeDescriptor; | ||
| use spider_core::types::id::JobId; | ||
| use spider_core::types::id::ResourceGroupId; | ||
| use spider_core::types::io::TaskInput; | ||
|
|
||
| use crate::Error; | ||
| use crate::query_job_submitter::ArchiveMetadata; | ||
| use crate::query_job_submitter::QueryJobSubmitter; | ||
|
|
||
| #[async_trait] | ||
| impl QueryJobSubmitter for SpiderClient { | ||
| /// # Errors | ||
| /// | ||
| /// Returns an error if: | ||
| /// | ||
| /// * Forwards [`build_query_task_graph`]'s return values on failure. | ||
| /// * Forwards [`SpiderClient::submit_job`]'s return values on failure. | ||
| async fn submit_query_job( | ||
| &self, | ||
| query_job_id: QueryJobId, | ||
| resource_group_id: ResourceGroupId, | ||
| clp_s_query_option: ClpSQueryOption, | ||
| output_handle: OutputHandle, | ||
| archives_to_search: Vec<(ArchiveMetadata, ExecutionPolicy)>, | ||
| ) -> Result<JobId, Error> { | ||
| let (graph, inputs) = build_query_task_graph( | ||
| query_job_id, | ||
| &clp_s_query_option, | ||
| &output_handle, | ||
| archives_to_search, | ||
| )?; | ||
| let spider_job_id = self.submit_job(resource_group_id, &graph, inputs).await?; | ||
|
|
||
| tracing::info!( | ||
| query_job_id = % query_job_id, | ||
| spider_job_id = % spider_job_id, | ||
| num_tasks = graph.get_num_tasks(), | ||
| "Submitted query job to Spider.", | ||
| ); | ||
|
|
||
| Ok(spider_job_id) | ||
| } | ||
| } | ||
|
|
||
| /// Builds independent archive-search tasks and their positionally ordered external inputs. | ||
| /// | ||
| /// # Returns | ||
| /// | ||
| /// A tuple on success, containing: | ||
| /// | ||
| /// * The constructed task graph. | ||
| /// * The positionally ordered external inputs. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns an error if: | ||
| /// | ||
| /// * Forwards [`TaskGraph::new`]'s return values on failure. | ||
| /// * Forwards [`ValueTypeDescriptor::struct_from_name`]'s return values on failure. | ||
| /// * Forwards [`TaskGraph::insert_task`]'s return values on failure. | ||
| /// * Forwards [`rmp_serde::to_vec`]'s return values on failure. | ||
| fn build_query_task_graph( | ||
| query_job_id: QueryJobId, | ||
| clp_s_query_option: &ClpSQueryOption, | ||
| output_handle: &OutputHandle, | ||
| archives_to_search: Vec<(ArchiveMetadata, ExecutionPolicy)>, | ||
| ) -> Result<(TaskGraph, Vec<TaskInput>), Error> { | ||
| // NOTE: Keep these names and the input order in sync with the TDL package definitions. | ||
| const CLP_TDL_PACKAGE_NAME: &str = "clp"; | ||
| const QUERY_TASK_FUNC: &str = "query::clp_s_search"; | ||
|
|
||
| let mut graph = TaskGraph::new(None, None)?; | ||
|
|
||
| let mut inputs = Vec::new(); | ||
| for (archive, execution_policy) in archives_to_search { | ||
| graph.insert_task(TaskDescriptor { | ||
| tdl_context: TdlContext { | ||
| package: CLP_TDL_PACKAGE_NAME.to_owned(), | ||
| task_func: QUERY_TASK_FUNC.to_owned(), | ||
| }, | ||
| execution_policy: Some(execution_policy), | ||
| inputs: vec![ | ||
| DataTypeDescriptor::Value(ValueTypeDescriptor::int32()), | ||
| DataTypeDescriptor::Value(ValueTypeDescriptor::struct_from_name( | ||
| "ClpSQueryOption", | ||
| )?), | ||
| DataTypeDescriptor::Value(ValueTypeDescriptor::struct_from_name( | ||
| "Option<NonEmptyString>", | ||
| )?), | ||
| DataTypeDescriptor::Value(ValueTypeDescriptor::struct_from_name("NonEmptyString")?), | ||
| DataTypeDescriptor::Value(ValueTypeDescriptor::struct_from_name("OutputHandle")?), | ||
| ], | ||
| outputs: vec![], | ||
| input_sources: None, | ||
| })?; | ||
| inputs.push(TaskInput::ValuePayload(rmp_serde::to_vec(&query_job_id)?)); | ||
| inputs.push(TaskInput::ValuePayload(rmp_serde::to_vec( | ||
| clp_s_query_option, | ||
| )?)); | ||
| inputs.push(TaskInput::ValuePayload(rmp_serde::to_vec( | ||
| &archive.dataset, | ||
| )?)); | ||
| inputs.push(TaskInput::ValuePayload(rmp_serde::to_vec(&archive.id)?)); | ||
| inputs.push(TaskInput::ValuePayload(rmp_serde::to_vec(output_handle)?)); | ||
| } | ||
|
|
||
| Ok((graph, inputs)) | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.