Skip to content

Commit 6bfd868

Browse files
committed
Revert "Optimize CockroachDB setup for tests (96% reduction) (#493)"
This reverts commit ab8872a.
1 parent a5713c6 commit 6bfd868

File tree

9 files changed

+29
-171
lines changed

9 files changed

+29
-171
lines changed

.github/buildomat/jobs/build-and-test.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,6 @@ set -o xtrace
1414
cargo --version
1515
rustc --version
1616

17-
banner clickhouse
18-
ptime -m ./tools/ci_download_clickhouse
19-
20-
banner cockroach
21-
ptime -m bash ./tools/ci_download_cockroachdb
22-
23-
#
24-
# Put "./cockroachdb/bin" and "./clickhouse" on the PATH for the test
25-
# suite.
26-
#
27-
export PATH="$PATH:$PWD/cockroachdb/bin:$PWD/clickhouse"
28-
2917
#
3018
# We build with:
3119
#
@@ -51,6 +39,18 @@ ptime -m cargo +'nightly-2021-11-24' build --locked --all-targets --verbose
5139
banner deploy-check
5240
ptime -m cargo run --bin omicron-package -- check
5341

42+
banner clickhouse
43+
ptime -m ./tools/ci_download_clickhouse
44+
45+
banner cockroach
46+
ptime -m bash ./tools/ci_download_cockroachdb
47+
48+
#
49+
# Put "./cockroachdb/bin" and "./clickhouse" on the PATH for the test
50+
# suite.
51+
#
52+
export PATH="$PATH:$PWD/cockroachdb/bin:$PWD/clickhouse"
53+
5454
#
5555
# NOTE: We're using using the same RUSTFLAGS and RUSTDOCFLAGS as above to avoid
5656
# having to rebuild here.

.github/workflows/rust.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,6 @@ jobs:
108108
with:
109109
key: ${{ runner.os }}-clickhouse-binary-${{ hashFiles('tools/clickhouse_checksums') }}
110110
path: "clickhouse"
111-
- name: Download ClickHouse
112-
if: steps.cache-clickhouse.outputs.cache-hit != 'true'
113-
run: ./tools/ci_download_clickhouse
114-
- name: Download CockroachDB binary
115-
if: steps.cache-cockroachdb.outputs.cache-hit != 'true'
116-
run: bash ./tools/ci_download_cockroachdb
117111
- name: Build
118112
# We build with:
119113
# - RUSTFLAGS="-D warnings" RUSTDOCFLAGS="-D warnings": disallow warnings
@@ -125,7 +119,13 @@ jobs:
125119
# also gives us a record of which dependencies were used for each CI
126120
# run. Building with `--locked` ensures that the checked-in Cargo.lock
127121
# is up to date.
128-
run: PATH="$PATH:$PWD/cockroachdb/bin:$PWD/clickhouse" RUSTFLAGS="-D warnings" RUSTDOCFLAGS="-D warnings" cargo build --locked --all-targets --verbose
122+
run: RUSTFLAGS="-D warnings" RUSTDOCFLAGS="-D warnings" cargo build --locked --all-targets --verbose
123+
- name: Download ClickHouse
124+
if: steps.cache-clickhouse.outputs.cache-hit != 'true'
125+
run: ./tools/ci_download_clickhouse
126+
- name: Download CockroachDB binary
127+
if: steps.cache-cockroachdb.outputs.cache-hit != 'true'
128+
run: bash ./tools/ci_download_cockroachdb
129129
- name: Run tests
130130
# Use the same RUSTFLAGS and RUSTDOCFLAGS as above to avoid having to
131131
# rebuild here.

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ default-members = [
2424
"common",
2525
"nexus",
2626
"nexus/src/db/db-macros",
27+
"nexus/test-utils",
2728
"package",
2829
"rpaths",
2930
"sled-agent",

README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ example, on Helios, you'd want `/usr/bin` on your PATH.
8383
--
8484
. CockroachDB v21.1.10.
8585
+
86-
The build and test suite expects to be able to start a single-node CockroachDB cluster using the `cockroach` executable on your PATH.
86+
The test suite expects to be able to start a single-node CockroachDB cluster using the `cockroach` executable on your PATH.
8787
On illumos, MacOS, and Linux, you should be able to use the `tools/ci_download_cockroachdb` script to fetch the official CockroachDB binary. It will be put into `./cockroachdb/bin/cockroach`.
8888
Alternatively, you can follow the https://www.cockroachlabs.com/docs/stable/install-cockroachdb.html[official CockroachDB installation instructions for your platform].
8989

nexus/test-utils/Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,3 @@ serde = { version = "1.0", features = [ "derive" ] }
2424
serde_json = "1.0"
2525
slog = { version = "2.7", features = [ "max_level_trace", "release_max_level_debug" ] }
2626
uuid = { version = "0.8", features = [ "serde", "v4" ] }
27-
28-
[build-dependencies]
29-
dropshot = { git = "https://github.com/oxidecomputer/dropshot", branch = "main", features = [ "usdt-probes" ] }
30-
omicron-test-utils = { path = "../../test-utils" }
31-
tokio = { version = "1.14" }

nexus/test-utils/build.rs

Lines changed: 0 additions & 32 deletions
This file was deleted.

test-utils/src/dev/db.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl CockroachStarterBuilder {
204204
CockroachStarterBuilder::temp_path(&temp_dir, "listen-url");
205205
let listen_arg = format!("127.0.0.1:{}", self.listen_port);
206206
self.arg("--store")
207-
.arg(&store_dir)
207+
.arg(store_dir)
208208
.arg("--listen-addr")
209209
.arg(&listen_arg)
210210
.arg("--listening-url-file")
@@ -222,7 +222,6 @@ impl CockroachStarterBuilder {
222222

223223
Ok(CockroachStarter {
224224
temp_dir,
225-
store_dir: store_dir.into(),
226225
listen_url_file,
227226
args: self.args,
228227
cmd_builder: self.cmd_builder,
@@ -261,8 +260,6 @@ impl CockroachStarterBuilder {
261260
pub struct CockroachStarter {
262261
/// temporary directory used for URL file and potentially data storage
263262
temp_dir: TempDir,
264-
/// path to storage directory
265-
store_dir: PathBuf,
266263
/// path to listen URL file (inside temp_dir)
267264
listen_url_file: PathBuf,
268265
/// command-line arguments, mirrored here for reporting to the user
@@ -286,11 +283,6 @@ impl CockroachStarter {
286283
self.temp_dir.path()
287284
}
288285

289-
/// Returns the path to the storage directory created for this execution.
290-
pub fn store_dir(&self) -> &Path {
291-
self.store_dir.as_path()
292-
}
293-
294286
/**
295287
* Spawns a new process to run the configured command
296288
*

test-utils/src/dev/mod.rs

Lines changed: 7 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -12,63 +12,11 @@ pub mod db;
1212
pub mod poll;
1313
pub mod test_cmds;
1414

15-
use anyhow::Context;
1615
use dropshot::test_util::LogContext;
1716
use dropshot::ConfigLogging;
1817
use dropshot::ConfigLoggingIfExists;
1918
use dropshot::ConfigLoggingLevel;
2019
use slog::Logger;
21-
use std::path::{Path, PathBuf};
22-
23-
/// Path to the "seed" CockroachDB directory.
24-
///
25-
/// Populating CockroachDB unfortunately isn't free - creation of
26-
/// tables, indices, and users takes several seconds to complete.
27-
///
28-
/// By creating a "seed" version of the database, we can cut down
29-
/// on the time spent performing this operation. Instead, we opt
30-
/// to copy the database from this seed location.
31-
fn seed_dir() -> PathBuf {
32-
std::env::temp_dir().join("crdb-base")
33-
}
34-
35-
// Helper for copying all the files in one directory to another.
36-
fn copy_dir(
37-
src: impl AsRef<Path>,
38-
dst: impl AsRef<Path>,
39-
) -> Result<(), anyhow::Error> {
40-
let src = src.as_ref();
41-
let dst = dst.as_ref();
42-
std::fs::create_dir_all(&dst)
43-
.with_context(|| format!("Failed to create dst {}", dst.display()))?;
44-
for entry in std::fs::read_dir(src)
45-
.with_context(|| format!("Failed to read_dir {}", src.display()))?
46-
{
47-
let entry = entry.with_context(|| {
48-
format!("Failed to read entry in {}", src.display())
49-
})?;
50-
let ty = entry.file_type().context("Failed to access file type")?;
51-
let target = dst.join(entry.file_name());
52-
if ty.is_dir() {
53-
copy_dir(entry.path(), &target).with_context(|| {
54-
format!(
55-
"Failed to copy subdirectory {} to {}",
56-
entry.path().display(),
57-
target.display()
58-
)
59-
})?;
60-
} else {
61-
std::fs::copy(entry.path(), &target).with_context(|| {
62-
format!(
63-
"Failed to copy file at {} to {}",
64-
entry.path().display(),
65-
target.display()
66-
)
67-
})?;
68-
}
69-
}
70-
Ok(())
71-
}
7220

7321
/**
7422
* Set up a [`dropshot::test_util::LogContext`] appropriate for a test named
@@ -87,71 +35,26 @@ pub fn test_setup_log(test_name: &str) -> LogContext {
8735
LogContext::new(test_name, &log_config)
8836
}
8937

90-
enum StorageSource {
91-
Populate,
92-
CopyFromSeed,
93-
}
94-
95-
/// Creates a [`db::CockroachInstance`] with a populated storage directory.
96-
///
97-
/// This is intended to optimize subsequent calls to [`test_setup_database`]
98-
/// by reducing the latency of populating the storage directory.
99-
pub async fn test_setup_database_seed(log: &Logger) {
100-
let dir = seed_dir();
101-
let _ = std::fs::remove_dir_all(&dir);
102-
std::fs::create_dir_all(&dir).unwrap();
103-
let mut db = setup_database(log, Some(&dir), StorageSource::Populate).await;
104-
db.cleanup().await.unwrap();
105-
}
106-
107-
/// Set up a [`db::CockroachInstance`] for running tests.
38+
/**
39+
* Set up a [`db::CockroachInstance`] for running tests against.
40+
*/
10841
pub async fn test_setup_database(log: &Logger) -> db::CockroachInstance {
109-
setup_database(log, None, StorageSource::CopyFromSeed).await
110-
}
111-
112-
async fn setup_database(
113-
log: &Logger,
114-
store_dir: Option<&Path>,
115-
storage_source: StorageSource,
116-
) -> db::CockroachInstance {
117-
let builder = db::CockroachStarterBuilder::new();
118-
let mut builder = if let Some(store_dir) = store_dir {
119-
builder.store_dir(store_dir)
120-
} else {
121-
builder
122-
};
42+
let mut builder = db::CockroachStarterBuilder::new();
12343
builder.redirect_stdio_to_files();
12444
let starter = builder.build().unwrap();
12545
info!(
12646
&log,
12747
"cockroach temporary directory: {}",
12848
starter.temp_dir().display()
12949
);
130-
131-
// If we're going to copy the storage directory from the seed,
132-
// it is critical we do so before starting the DB.
133-
if matches!(storage_source, StorageSource::CopyFromSeed) {
134-
info!(&log,
135-
"cockroach: copying from seed directory ({}) to storage directory ({})",
136-
seed_dir().to_string_lossy(), starter.store_dir().to_string_lossy(),
137-
);
138-
copy_dir(seed_dir(), starter.store_dir())
139-
.expect("Cannot copy storage from seed directory");
140-
}
141-
14250
info!(&log, "cockroach command line: {}", starter.cmdline());
14351
let database = starter.start().await.unwrap();
14452
info!(&log, "cockroach pid: {}", database.pid());
14553
let db_url = database.pg_config();
14654
info!(&log, "cockroach listen URL: {}", db_url);
147-
148-
// If we populate the storage directory by importing the '.sql'
149-
// file, we must do so after the DB has started.
150-
if matches!(storage_source, StorageSource::Populate) {
151-
info!(&log, "cockroach: populating");
152-
database.populate().await.expect("failed to populate database");
153-
info!(&log, "cockroach: populated");
154-
}
55+
info!(&log, "cockroach: populating");
56+
database.populate().await.expect("failed to populate database");
57+
info!(&log, "cockroach: populated");
15558
database
15659
}
15760

0 commit comments

Comments
 (0)