Repository navigation
feat: let a standalone cluster run push-staged #2669
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
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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,159 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| mod common; | ||
|
|
||
| /// End-to-end tests of a standalone cluster running push-staged, selected with | ||
| /// `ballista.standalone.task_scheduling_policy`. Each query's results are | ||
| /// compared with the same query run on a pull-staged standalone cluster. | ||
| #[cfg(test)] | ||
| #[cfg(feature = "standalone")] | ||
| mod standalone_push_staged { | ||
| use crate::common::setup_test_cluster_with_executors; | ||
| use ballista::prelude::SessionContextExt; | ||
| use ballista_core::config::{ | ||
| BALLISTA_STANDALONE_PARALLELISM, BALLISTA_STANDALONE_TASK_SCHEDULING_POLICY, | ||
| }; | ||
| use ballista_core::extension::SessionConfigExt; | ||
| use ballista_core::serde::protobuf::PollWorkParams; | ||
| use ballista_core::serde::protobuf::scheduler_grpc_client::SchedulerGrpcClient; | ||
| use datafusion::arrow::util::pretty::pretty_format_batches; | ||
| use datafusion::execution::{SessionState, SessionStateBuilder}; | ||
| use datafusion::prelude::{CsvReadOptions, SessionConfig, SessionContext}; | ||
| use std::io::Write; | ||
| use std::path::Path; | ||
| use tempfile::TempDir; | ||
|
|
||
| /// Writes an `orders` table split over four files, so its scan has four | ||
| /// partitions, and a small `customers` table. | ||
| fn write_tables(dir: &Path) { | ||
| let orders = dir.join("orders"); | ||
| std::fs::create_dir(&orders).unwrap(); | ||
| for file in 0..4 { | ||
| let mut out = | ||
| std::fs::File::create(orders.join(format!("part-{file}.csv"))).unwrap(); | ||
| writeln!(out, "o_id,o_cust,o_amount").unwrap(); | ||
| for i in 0..250 { | ||
| let id = file * 250 + i; | ||
| writeln!(out, "{id},{},{}", id % 97, (id * 7) % 1000).unwrap(); | ||
| } | ||
| } | ||
| let mut out = std::fs::File::create(dir.join("customers.csv")).unwrap(); | ||
| writeln!(out, "c_id,c_name,c_region").unwrap(); | ||
| for id in 0..100 { | ||
| writeln!(out, "{id},customer-{id},region-{}", id % 5).unwrap(); | ||
| } | ||
| } | ||
|
|
||
| fn state(policy: &str) -> SessionState { | ||
| let config = SessionConfig::new_with_ballista() | ||
| .with_target_partitions(4) | ||
| .set_str(BALLISTA_STANDALONE_PARALLELISM, "4") | ||
| .set_str(BALLISTA_STANDALONE_TASK_SCHEDULING_POLICY, policy); | ||
| SessionStateBuilder::new() | ||
| .with_config(config) | ||
| .with_default_features() | ||
| .build() | ||
| } | ||
|
|
||
| async fn register_tables(ctx: &SessionContext, dir: &Path) { | ||
| ctx.register_csv( | ||
| "orders", | ||
| dir.join("orders").to_str().unwrap(), | ||
| CsvReadOptions::new(), | ||
| ) | ||
| .await | ||
| .unwrap(); | ||
| ctx.register_csv( | ||
| "customers", | ||
| dir.join("customers.csv").to_str().unwrap(), | ||
| CsvReadOptions::new(), | ||
| ) | ||
| .await | ||
| .unwrap(); | ||
| } | ||
|
|
||
| async fn rows(ctx: &SessionContext, sql: &str) -> String { | ||
| let batches = ctx.sql(sql).await.unwrap().collect().await.unwrap(); | ||
| pretty_format_batches(&batches).unwrap().to_string() | ||
| } | ||
|
|
||
| const QUERIES: &[&str] = &[ | ||
| "SELECT count(*), sum(o_amount) FROM orders", | ||
| "SELECT o_cust, count(*) AS n, sum(o_amount) AS total \ | ||
| FROM orders GROUP BY o_cust ORDER BY o_cust", | ||
| "SELECT c_region, count(*) AS n, sum(o_amount) AS total \ | ||
| FROM orders JOIN customers ON o_cust = c_id \ | ||
| GROUP BY c_region ORDER BY c_region", | ||
| ]; | ||
|
|
||
| async fn expected(dir: &Path) -> Vec<String> { | ||
| let ctx = SessionContext::standalone_with_state(state("pull-staged")) | ||
| .await | ||
| .unwrap(); | ||
| register_tables(&ctx, dir).await; | ||
| let mut out = Vec::new(); | ||
| for sql in QUERIES { | ||
| out.push(rows(&ctx, sql).await); | ||
| } | ||
| out | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn push_staged_standalone_matches_pull_staged() { | ||
| let dir = TempDir::new().unwrap(); | ||
| write_tables(dir.path()); | ||
| let expected = expected(dir.path()).await; | ||
|
|
||
| let ctx = SessionContext::standalone_with_state(state("push-staged")) | ||
| .await | ||
| .unwrap(); | ||
| register_tables(&ctx, dir.path()).await; | ||
| for (sql, expected) in QUERIES.iter().zip(&expected) { | ||
| assert_eq!(&rows(&ctx, sql).await, expected, "{sql}"); | ||
| } | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn push_staged_cluster_of_two_executors_matches_pull_staged() { | ||
| let dir = TempDir::new().unwrap(); | ||
| write_tables(dir.path()); | ||
| let expected = expected(dir.path()).await; | ||
|
|
||
| let state = state("push-staged"); | ||
| let (host, port) = setup_test_cluster_with_executors(&state, 2, 2).await; | ||
|
|
||
| // The results match pull-staged by design, so check the scheduler | ||
| // really is push-staged: one of those rejects polling for work. | ||
| let mut scheduler = SchedulerGrpcClient::connect(format!("http://{host}:{port}")) | ||
| .await | ||
| .unwrap(); | ||
| let status = scheduler | ||
| .poll_work(PollWorkParams::default()) | ||
| .await | ||
| .unwrap_err(); | ||
| assert_eq!(status.code(), tonic::Code::FailedPrecondition); | ||
|
|
||
| let ctx = | ||
| SessionContext::remote_with_state(&format!("df://{host}:{port}"), state) | ||
| .await | ||
| .unwrap(); | ||
| register_tables(&ctx, dir.path()).await; | ||
| for (sql, expected) in QUERIES.iter().zip(&expected) { | ||
| assert_eq!(&rows(&ctx, sql).await, expected, "{sql}"); | ||
| } | ||
| } | ||
| } | ||
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
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.
Should these tests check that the cluster really runs push-staged? Their results match pull-staged by design, so they would also pass if the setting were ignored. I tried that locally on the head commit. I hard-coded
PullStagedinnew_standalone_scheduler_with_builder, forcedpush_stagedtofalsein the executor, and both tests still passed. A push-staged scheduler rejectspoll_workwithFailedPrecondition(grpc.rs), so the two-executor test could assert that after the cluster starts: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.
Nice find. The two-executor test now asserts
poll_workgetsFailedPrecondition. I checked it against a pull-staged cluster and it fails there withInvalidArgument, so it catches the setting being ignored.