From 758a17e199b520ede735af2c82b30fc01073b399 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Mon, 6 Dec 2021 11:47:52 -0500 Subject: [PATCH 1/6] feat: Create a build-time-optimized release build profile Fixes #3316. --- Cargo.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 445233ffbb..c32a5c7ac1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -85,3 +85,8 @@ lto = "thin" [profile.bench] debug = true + +[profile.quick-release] +inherits = "release" +codegen-units = 16 +lto = false From 361745803eb8ce08f181d7fa6485bea55b79a471 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Mon, 6 Dec 2021 13:16:26 -0500 Subject: [PATCH 2/6] feat: Use a PROFILE arg/env var in the Dockerfile --- Dockerfile | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index c8b800b6f5..10f2576826 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,14 +14,12 @@ COPY . /influxdb_iox WORKDIR /influxdb_iox ARG CARGO_INCREMENTAL=yes -ARG CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1 -ARG CARGO_PROFILE_RELEASE_LTO=thin +ARG PROFILE=release ARG FEATURES=aws,gcp,azure,jemalloc_replacing_malloc ARG ROARING_ARCH="haswell" ARG RUSTFLAGS="" ENV CARGO_INCREMENTAL=$CARGO_INCREMENTAL \ - CARGO_PROFILE_RELEASE_CODEGEN_UNITS=$CARGO_PROFILE_RELEASE_CODEGEN_UNITS \ - CARGO_PROFILE_RELEASE_LTO=$CARGO_PROFILE_RELEASE_LTO \ + PROFILE=$PROFILE \ FEATURES=$FEATURES \ ROARING_ARCH=$ROARING_ARCH \ RUSTFLAGS=$RUSTFLAGS @@ -31,7 +29,7 @@ RUN \ --mount=type=cache,id=influxdb_iox_git,sharing=locked,target=/usr/local/cargo/git \ --mount=type=cache,id=influxdb_iox_target,sharing=locked,target=/influxdb_iox/target \ du -cshx /usr/local/cargo/registry /usr/local/cargo/git /influxdb_iox/target && \ - cargo build --target-dir /influxdb_iox/target --release --no-default-features --features="$FEATURES" && \ + cargo build --target-dir /influxdb_iox/target --profile="$PROFILE" --no-default-features --features="$FEATURES" && \ objcopy --compress-debug-sections target/release/influxdb_iox && \ cp /influxdb_iox/target/release/influxdb_iox /root/influxdb_iox && \ du -cshx /usr/local/cargo/registry /usr/local/cargo/git /influxdb_iox/target From 255cf79104fb148d6ccb06425575cd7d00105b5e Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Mon, 6 Dec 2021 16:08:41 -0500 Subject: [PATCH 3/6] docs: Explain tradeoffs and use cases of the different release profiles --- Cargo.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index c32a5c7ac1..740f4a84ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -78,6 +78,8 @@ exclude = [ "tools/", ] +# This profile optimizes for runtime performance and small binary size at the expense of longer +# build times. It's most suitable for final release builds. [profile.release] codegen-units = 1 debug = true @@ -86,6 +88,8 @@ lto = "thin" [profile.bench] debug = true +# This profile optimizes for short build times at the expense of larger binary size and slower +# runtime performance. It's most suitable for development iterations. [profile.quick-release] inherits = "release" codegen-units = 16 From 2561af666ec86aaec8ffbbba97d9d742dfcf8088 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" <193874+carols10cents@users.noreply.github.com> Date: Wed, 8 Dec 2021 09:52:56 -0500 Subject: [PATCH 4/6] fix: Use profile name variable in build artifact paths Co-authored-by: Marco Neumann --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 10f2576826..24a47f82cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,8 +30,8 @@ RUN \ --mount=type=cache,id=influxdb_iox_target,sharing=locked,target=/influxdb_iox/target \ du -cshx /usr/local/cargo/registry /usr/local/cargo/git /influxdb_iox/target && \ cargo build --target-dir /influxdb_iox/target --profile="$PROFILE" --no-default-features --features="$FEATURES" && \ - objcopy --compress-debug-sections target/release/influxdb_iox && \ - cp /influxdb_iox/target/release/influxdb_iox /root/influxdb_iox && \ + objcopy --compress-debug-sections "target/$PROFILE/influxdb_iox" && \ + cp "/influxdb_iox/target/$PROFILE/influxdb_iox" /root/influxdb_iox && \ du -cshx /usr/local/cargo/registry /usr/local/cargo/git /influxdb_iox/target From 183de4519fa02f18cd253b7e5f842dc1dc893217 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Wed, 8 Dec 2021 09:51:27 -0500 Subject: [PATCH 5/6] feat: Add incremental = true to the quick-release profile --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 740f4a84ba..c6de01cf64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -94,3 +94,4 @@ debug = true inherits = "release" codegen-units = 16 lto = false +incremental = true From a8bc5b3b6d4d01e320e22a0a9decca80a7320960 Mon Sep 17 00:00:00 2001 From: Marco Neumann Date: Wed, 8 Dec 2021 19:01:45 +0100 Subject: [PATCH 6/6] fix: allow setting the same server ID twice This is important for idempotence and simplifies clients and helper scripts a lot. --- .../tests/end_to_end_cases/deployment_api.rs | 11 +++++++- server/src/lib.rs | 25 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/influxdb_iox/tests/end_to_end_cases/deployment_api.rs b/influxdb_iox/tests/end_to_end_cases/deployment_api.rs index 4bf225d035..894ba05b4d 100644 --- a/influxdb_iox/tests/end_to_end_cases/deployment_api.rs +++ b/influxdb_iox/tests/end_to_end_cases/deployment_api.rs @@ -129,7 +129,16 @@ async fn assert_set_get_server_id(server_fixture: ServerFixture) { let got = client.get_server_id().await.expect("get ID failed"); assert_eq!(got, Some(test_id)); - // setting server ID a second time should fail + // setting server ID to same ID should be OK + client + .update_server_id(test_id) + .await + .expect("set ID again failed"); + + let got = client.get_server_id().await.expect("get ID failed"); + assert_eq!(got, Some(test_id)); + + // setting server ID to a different ID should fail let result = client .update_server_id(NonZeroU32::try_from(13).unwrap()) .await; diff --git a/server/src/lib.rs b/server/src/lib.rs index 95c4ce8c51..b513f85985 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -470,6 +470,15 @@ impl Server { let mut state = self.shared.state.write(); let startup = match &**state { ServerState::Startup(startup) => startup.clone(), + state + if state + .server_id() + .map(|existing| existing == server_id) + .unwrap_or_default() => + { + // already set to same ID + return Ok(()); + } _ => return Err(Error::IdAlreadySet), }; @@ -2459,4 +2468,20 @@ mod tests { ]) .unwrap(); } + + #[tokio::test] + async fn set_server_id_twice() { + test_helpers::maybe_start_logging(); + let server = make_server(make_application()); + + server.set_id(ServerId::try_from(1).unwrap()).unwrap(); + server.wait_for_init().await.unwrap(); + + server.set_id(ServerId::try_from(1).unwrap()).unwrap(); + + assert_error!( + server.set_id(ServerId::try_from(2).unwrap()), + Error::IdAlreadySet + ); + } }