diff --git a/Cargo.toml b/Cargo.toml index 445233ffbb..c6de01cf64 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 @@ -85,3 +87,11 @@ 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 +lto = false +incremental = true diff --git a/Dockerfile b/Dockerfile index c8b800b6f5..24a47f82cc 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,9 +29,9 @@ 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" && \ - objcopy --compress-debug-sections target/release/influxdb_iox && \ - cp /influxdb_iox/target/release/influxdb_iox /root/influxdb_iox && \ + cargo build --target-dir /influxdb_iox/target --profile="$PROFILE" --no-default-features --features="$FEATURES" && \ + 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 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 + ); + } }