Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Commit 7ccacfe

Browse files
feat: now compatible with non-local postgres (#110)
**Summary**: Modified code so that it can work with a non-local (meaning on a different machine or in a Docker container) Postgres instance by removing all uses of `pg_ctl` and `psql`. **Demo**: The demo shows that the codebase has no instances of "pg_ctl" or "psql" (except for one appearance of "psql" in a comment). Despite this, `cargo run ... cardtest` still works correctly. https://github.com/cmu-db/optd/assets/20631215/453a341a-8141-4ac4-95f1-e09b7bb690a5 **Details**: * Removing `pg_ctl` required significant changes. Instead of having one `pgdata/` per TPC-H config's data, we now have one global `pgdata/` and one _Postgres database_ per TPC-H config's data. * Removing `psql` involved using SQL queries to load the database instead of `psql` invocations. * Since each TPC-H config corresponds to a Postgres database instead of a file, the string representing each TPC-H config now has additional restrictions described in `get_dbname()`.
1 parent b6f1768 commit 7ccacfe

File tree

7 files changed

+199
-275
lines changed

7 files changed

+199
-275
lines changed

optd-perftest/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ clap = { version = "4.5", features = [
2424
"derive",
2525
] }
2626
log = "0.4"
27-
env_logger = "0.11"
27+
env_logger = "0.11"

optd-perftest/src/benchmark.rs

+25-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,32 @@ pub enum Benchmark {
77
}
88

99
impl Benchmark {
10-
pub fn get_stringid(&self) -> String {
11-
match self {
10+
/// Get a unique string that deterministically describes the "data" of this benchmark.
11+
/// Note that benchmarks consist of "data" and "queries". This name is only for the data
12+
/// For instance, if you have two TPC-H benchmarks with the same scale factor and seed
13+
/// but different queries, they could both share the same database and would thus
14+
/// have the same dbname.
15+
/// This name must be compatible with the rules all databases have for their names, which
16+
/// are described below:
17+
///
18+
/// Postgres' rules:
19+
/// - The name can only contain A-Z a-z 0-9 _ and cannot start with 0-9.
20+
/// - There is a weird behavior where if you use CREATE DATABASE to create a database,
21+
/// Postgres will convert uppercase letters to lowercase. However, if you use psql to
22+
/// then connect to the database, Postgres will *not* convert capital letters to
23+
/// lowercase. To resolve the inconsistency, the names output by this function will
24+
/// *not* contain uppercase letters.
25+
pub fn get_dbname(&self) -> String {
26+
let dbname = match self {
1227
Self::Test => String::from("test"),
13-
Self::Tpch(tpch_config) => format!("tpch_{}", tpch_config.get_stringid()),
14-
}
28+
Self::Tpch(tpch_config) => {
29+
format!("tpch_sf{}_sd{}", tpch_config.scale_factor, tpch_config.seed)
30+
}
31+
};
32+
// since Postgres names cannot contain periods
33+
let dbname = dbname.replace('.', "point");
34+
// due to the weird inconsistency with Postgres (see function comment)
35+
dbname.to_lowercase()
1536
}
1637

1738
pub fn is_readonly(&self) -> bool {

optd-perftest/src/cardtest.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,6 @@ pub trait CardtestRunnerDBHelper {
7777
fn get_name(&self) -> &str;
7878

7979
// The order of queries has to be the same between these two functions.
80-
// They take mutable references because evaluation sometimes involves mutating self.
81-
// One example of this is in PostgresDb where we may need to reconnect to the database,
82-
// which requires modifying the PostgresDb object.
83-
async fn eval_benchmark_estcards(
84-
&mut self,
85-
benchmark: &Benchmark,
86-
) -> anyhow::Result<Vec<usize>>;
87-
async fn eval_benchmark_truecards(
88-
&mut self,
89-
benchmark: &Benchmark,
90-
) -> anyhow::Result<Vec<usize>>;
80+
async fn eval_benchmark_estcards(&self, benchmark: &Benchmark) -> anyhow::Result<Vec<usize>>;
81+
async fn eval_benchmark_truecards(&self, benchmark: &Benchmark) -> anyhow::Result<Vec<usize>>;
9182
}

optd-perftest/src/datafusion_db_cardtest.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,11 @@ impl CardtestRunnerDBHelper for DatafusionDb {
88
"DataFusion"
99
}
1010

11-
async fn eval_benchmark_truecards(
12-
&mut self,
13-
_benchmark: &Benchmark,
14-
) -> anyhow::Result<Vec<usize>> {
11+
async fn eval_benchmark_truecards(&self, _benchmark: &Benchmark) -> anyhow::Result<Vec<usize>> {
1512
Ok(vec![])
1613
}
1714

18-
async fn eval_benchmark_estcards(
19-
&mut self,
20-
_benchmark: &Benchmark,
21-
) -> anyhow::Result<Vec<usize>> {
15+
async fn eval_benchmark_estcards(&self, _benchmark: &Benchmark) -> anyhow::Result<Vec<usize>> {
2216
Ok(vec![])
2317
}
2418
}

optd-perftest/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async fn cardtest<P: AsRef<Path>>(
6666
workspace_dpath: P,
6767
tpch_config: TpchConfig,
6868
) -> anyhow::Result<()> {
69-
let pg_db = PostgresDb::build(workspace_dpath).await?;
69+
let pg_db = PostgresDb::new(workspace_dpath);
7070
let databases: Vec<Box<dyn CardtestRunnerDBHelper>> = vec![Box::new(pg_db)];
7171

7272
let tpch_benchmark = Benchmark::Tpch(tpch_config.clone());

0 commit comments

Comments
 (0)