From 921be5299ba912f0f0fe4c85f37489971ff8e8e2 Mon Sep 17 00:00:00 2001 From: sd Date: Tue, 9 Apr 2024 12:11:27 +0200 Subject: [PATCH 01/10] allow clippy::mixed_attributes_style for auto-generated proto files --- src/rpc/cache.rs | 5 +++-- src/rpc/mod.rs | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rpc/cache.rs b/src/rpc/cache.rs index e8d20e8..1a88d8e 100644 --- a/src/rpc/cache.rs +++ b/src/rpc/cache.rs @@ -1,3 +1,4 @@ +// This file is @generated by prost-build. #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct Ack { @@ -521,7 +522,7 @@ pub mod cache_server { #[async_trait] pub trait Cache: Send + Sync + 'static { /// Server streaming response type for the StreamValues method. - type StreamValuesStream: futures_core::Stream< + type StreamValuesStream: tonic::codegen::tokio_stream::Stream< Item = std::result::Result, > + Send @@ -634,7 +635,7 @@ pub mod cache_server { ) -> Self::Future { let inner = Arc::clone(&self.0); let fut = async move { - (*inner).stream_values(request).await + ::stream_values(&inner, request).await }; Box::pin(fut) } diff --git a/src/rpc/mod.rs b/src/rpc/mod.rs index a5c08fd..32f90b3 100644 --- a/src/rpc/mod.rs +++ b/src/rpc/mod.rs @@ -1 +1,2 @@ +#[allow(clippy::mixed_attributes_style)] pub mod cache; From 03e62286497847a3bbceddc026767d30c5f6f78d Mon Sep 17 00:00:00 2001 From: sd Date: Tue, 9 Apr 2024 12:11:49 +0200 Subject: [PATCH 02/10] rust 1.77 clippy lints --- src/lib.rs | 2 +- src/quorum.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 44df03d..9b40c16 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1438,7 +1438,7 @@ pub async fn start_cluster( if !h.contains(&hostname) { ha_clients.push(h.trim().to_owned()) } else { - host_srv_addr = h.trim().to_owned(); + h.trim().clone_into(&mut host_srv_addr); } }); info!( diff --git a/src/quorum.rs b/src/quorum.rs index 914391b..7e9725d 100644 --- a/src/quorum.rs +++ b/src/quorum.rs @@ -270,7 +270,7 @@ pub(crate) async fn quorum_handler( state = QuorumState::Follower; health_state.state = QuorumState::Follower; - health_state.tx_leader = server.tx.clone(); + health_state.tx_leader.clone_from(&server.tx); } } @@ -294,7 +294,7 @@ pub(crate) async fn quorum_handler( state = QuorumState::Follower; health_state.state = QuorumState::Follower; - health_state.tx_leader = server.tx.clone(); + health_state.tx_leader.clone_from(&server.tx); tx_remote .send_async(RpcRequest::LeaderReqAck { From 3ff313c7f919bf71f6fe1768ceaf2bd319c707ef Mon Sep 17 00:00:00 2001 From: sd Date: Tue, 9 Apr 2024 12:12:04 +0200 Subject: [PATCH 03/10] add protoc flag to build protos with `optional` --- build.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/build.rs b/build.rs index b6c5599..7f77243 100644 --- a/build.rs +++ b/build.rs @@ -6,6 +6,7 @@ fn main() { // .build_client(true) // .build_server(true) // .out_dir("src/rpc/") + // .protoc_arg("--experimental_allow_proto3_optional") // .compile(&["proto/cache.proto"], &["proto"]) // .expect("Failed to compile proto/cache.proto"); } From 796f301a5440bbaa120956f6ad5be1a7e931b83b Mon Sep 17 00:00:00 2001 From: sd Date: Tue, 9 Apr 2024 12:12:15 +0200 Subject: [PATCH 04/10] bump version + update deps --- Cargo.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e5dbb56..1e51900 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "redhac" -version = "0.9.1" +version = "0.10.0" edition = "2021" rust-version = "1.65.0" license = "Apache-2.0 OR MIT" @@ -15,7 +15,7 @@ repository = "https://github.com/sebadob/redhac" anyhow = "1.0" async-stream = "0.3" bincode = "1" -cached = { version = "0.46", features = ["async", "async_tokio_rt_multi_thread"] } +cached = { version = "0.49.3", features = ["async", "async_tokio_rt_multi_thread"] } chrono = { version = "0.4.31", default-features = false, features = ["clock", "serde", "std"] } ctrlc = { version = "3", features = ["termination"] } dotenvy = "0.15" @@ -30,7 +30,7 @@ rand = "0.8" serde = { version = "1", features = ["derive"] } tokio = { version = "1.21.2", features = ["full"] } tokio-stream = "0.1.5" -tonic = { version = "0.10.2", features = ["gzip", "tls", "tls-webpki-roots"] } +tonic = { version = "0.11.0", features = ["gzip", "tls", "tls-webpki-roots"] } tower = "0.4" tracing = "0.1" @@ -46,4 +46,4 @@ tokio-test = "0.4" tracing-subscriber = { version = "0.3", features = ["env-filter", "tracing"] } [build-dependencies] -tonic-build = "0.10" +tonic-build = "0.11.0" From 9aab6e76d1496332f9fdc1d74a4d035fda9b27b8 Mon Sep 17 00:00:00 2001 From: sd Date: Tue, 9 Apr 2024 12:39:11 +0200 Subject: [PATCH 05/10] fix possible channel send panic --- examples/conflict_resolution_tests/Cargo.toml | 6 ++++++ src/client.rs | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/examples/conflict_resolution_tests/Cargo.toml b/examples/conflict_resolution_tests/Cargo.toml index 516f24d..413cbdc 100644 --- a/examples/conflict_resolution_tests/Cargo.toml +++ b/examples/conflict_resolution_tests/Cargo.toml @@ -5,6 +5,12 @@ edition = "2021" license = "Apache-2.0 OR MIT" authors = ["Sebastian Dobe Date: Tue, 9 Apr 2024 12:39:20 +0200 Subject: [PATCH 06/10] update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48b5548..d0b6293 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v0.10.0 + +- core dependencies have been updated +- latest rust nightly clippy lints have been applied +- a very unlikely but possible channel panic in case of a conflict resolution has been fixed + ## 0.9.1 Typo corrections in documentation and removed now obsolete minimal-versions dependencies. From c303a3a677b27d82a8e41066a6061fe085ad210b Mon Sep 17 00:00:00 2001 From: sd Date: Tue, 9 Apr 2024 12:40:33 +0200 Subject: [PATCH 07/10] add `publish-dry` just recipe --- justfile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/justfile b/justfile index 3ae0a2e..1fe586c 100644 --- a/justfile +++ b/justfile @@ -73,6 +73,13 @@ release: verfiy-is-clean git push origin "v$TAG" +# dry-run publishing the latest version +publish-dry: verfiy-is-clean + #!/usr/bin/env bash + set -euxo pipefail + cargo publish --dry-run + + # publishes the current version to cargo.io publish: verfiy-is-clean #!/usr/bin/env bash From b6d3649fd20a295b542dec1160b495c78edebcd4 Mon Sep 17 00:00:00 2001 From: sd Date: Tue, 9 Apr 2024 12:41:54 +0200 Subject: [PATCH 08/10] don't build musl by default --- justfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/justfile b/justfile index 1fe586c..ef3de2d 100644 --- a/justfile +++ b/justfile @@ -33,7 +33,8 @@ build: #!/usr/bin/env bash set -euxo pipefail # build as musl to make sure this works - cargo build --release --target x86_64-unknown-linux-musl + #cargo build --release --target x86_64-unknown-linux-musl + cargo build --release # verifies the MSRV From 1745fa960ff7cea48198c5595f30d526d65ee1ff Mon Sep 17 00:00:00 2001 From: sd Date: Tue, 9 Apr 2024 13:07:42 +0200 Subject: [PATCH 09/10] speed up doc tests and fix comment typos --- examples/ha_setup/src/main.rs | 2 +- src/lib.rs | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/examples/ha_setup/src/main.rs b/examples/ha_setup/src/main.rs index 8817113..2c72ab1 100644 --- a/examples/ha_setup/src/main.rs +++ b/examples/ha_setup/src/main.rs @@ -66,7 +66,7 @@ async fn main() -> anyhow::Result<()> { .await?; info!("First cache node started"); - // Now just sleep until we ctrl + c so we can start the other members and observe the behavior + // Now just sleep until we ctrl + c, so we can start the other members and observe the behavior time::sleep(Duration::from_secs(6000)).await; // Let's simulate a graceful shutdown diff --git a/src/lib.rs b/src/lib.rs index 9b40c16..21732ea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -277,11 +277,12 @@ //! &mut cache_config_1, //! // optional notification channel: `Option>` //! None, -//! // We need to overwrite the hostname so we can start all nodes on the same host for this +//! // We need to overwrite the hostname, so we can start all nodes on the same host for this //! // example. Usually, this will be set to `None` //! Some("127.0.0.1:7001".to_string()), //! ) //! .await?; +//! time::sleep(Duration::from_millis(100)).await; //! println!("First cache node started"); //! //! // Mimic the other 2 cache members. This should usually not be done in the same code - only @@ -295,6 +296,7 @@ //! Some("127.0.0.1:7002".to_string()), //! ) //! .await?; +//! time::sleep(Duration::from_millis(100)).await; //! println!("2nd cache node started"); //! // Now after the 2nd cache member has been started, we would already have quorum and a //! // working cache layer. As long as there is no leader and / or quorum, the cache will not @@ -309,6 +311,7 @@ //! Some("127.0.0.1:7003".to_string()), //! ) //! .await?; +//! time::sleep(Duration::from_millis(100)).await; //! println!("3rd cache node started"); //! //! // For the sake of this example again, we need to wait until the cache is in a healthy @@ -1004,12 +1007,12 @@ pub(crate) async fn insert_from_leader( }; // double check, that we are really the leader - // this might get removed after enough testing, if it provides a performance benefit if health_state.state != QuorumState::Leader && health_state.state != QuorumState::LeaderSwitch { - let error = "Execution of 'insert_from_leader' is not allowed on a non-leader".to_string(); - warn!("is_leader state: {:?}", health_state.state); - // TODO remove this panic after testing + let error = format!("Execution of 'insert_from_leader' is not allowed on a non-leader: {:?}", health_state.state); + error!("{}", error); + // TODO we once ended up here during conflict resolution -> try to reproduce + // rather panic than have an inconsistent state panic!("{}", error); } From c291478f063c5981f2fbb5122307a817bf4c16a9 Mon Sep 17 00:00:00 2001 From: sd Date: Tue, 9 Apr 2024 13:11:06 +0200 Subject: [PATCH 10/10] bump msrv to 1.70.0 --- CHANGELOG.md | 1 + Cargo.toml | 2 +- justfile | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0b6293..55dc5f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - core dependencies have been updated - latest rust nightly clippy lints have been applied - a very unlikely but possible channel panic in case of a conflict resolution has been fixed +- bump MSRV to 1.70.0 ## 0.9.1 diff --git a/Cargo.toml b/Cargo.toml index 1e51900..82c7ec4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "redhac" version = "0.10.0" edition = "2021" -rust-version = "1.65.0" +rust-version = "1.70.0" license = "Apache-2.0 OR MIT" authors = ["Sebastian Dobe