Skip to content

Commit

Permalink
Switching to the new version of the prost and related libraries.
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-huba committed Apr 11, 2024
1 parent 93c40a2 commit 9cb1d0a
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 17 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ jobs:
- name: check clippy
if: ${{ matrix.rust == 'stable' && matrix.os == 'ubuntu-latest' }}
run: cargo clippy --all --all-targets -- -D clippy::all && cargo clippy --no-default-features --features prost-codec --features std -- -D clippy::all
- name: check no_std compatibility
run: cargo build --no-default-features --features prost-codec --target x86_64-unknown-none
- name: install targets
run: rustup target add x86_64-unknown-none
- name: run tests with no-std enabled
# No-std implementation uses feature that can only be compiled by nightly version
if: ${{ matrix.rust == 'nightly' }}
run: cargo build --no-default-features --features prost-codec --target x86_64-unknown-none
run: cargo test --all --no-default-features --features=prost-codec --features=default-logger --no-fail-fast -- --nocapture
- run: cargo test --all --no-fail-fast -- --nocapture
# Validate benches still work.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ahash = { version = "0.8.3", default-features = false }
fail = { version = "0.4", optional = true }
getset = "0.1.1"
protobuf = { version = "2", optional = true }
prost = { version = "0.11", optional = true, default-features = false, features = ["prost-derive"] }
prost = { version = "0.12.4", optional = true, default-features = false, features = ["prost-derive"] }
thiserror = { version = "1.0", optional = true }
raft-proto = { path = "proto", version = "0.7.0", default-features = false }
rand = { version = "0.8", default-features = false, features = ["alloc", "small_rng", "getrandom"] }
Expand Down
19 changes: 15 additions & 4 deletions harness/tests/integration_cases/test_raw_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ fn test_raw_node_read_index_to_old_leader() {
);
}

fn sort_conf_state_collections(cs: &mut ConfState) {
cs.voters.sort();
cs.learners.sort();
}

/// Tests the configuration change mechanism. Each test case sends a configuration
/// change which is either simple or joint, verifies that it applies and that the
/// resulting ConfState matches expectations, and for joint configurations makes
Expand Down Expand Up @@ -251,7 +256,7 @@ fn test_raw_node_propose_and_conf_change() {
let cs = conf_state_v2(vec![2], vec![3], vec![1], vec![1], true);
test_cases.push((Box::new(cc), cs, Some(conf_state(vec![2], vec![1, 3]))));

for (cc, exp, exp2) in test_cases {
for (cc, mut exp, exp2) in test_cases {
let s = new_storage();
let mut raw_node = new_raw_node(1, vec![1], 10, 1, s.clone(), &l);
raw_node.campaign().unwrap();
Expand Down Expand Up @@ -321,7 +326,10 @@ fn test_raw_node_propose_and_conf_change() {
assert_eq!(entries[1].get_entry_type(), EntryType::EntryConfChangeV2);
}
assert_eq!(ccdata, entries[1].get_data());
assert_eq!(exp, cs.unwrap());
let mut cs = cs.unwrap();
sort_conf_state_collections(&mut cs);
sort_conf_state_collections(&mut exp);
assert_eq!(exp, cs);

let conf_index = if cc.as_v2().enter_joint() == Some(true) {
// If this is an auto-leaving joint conf change, it will have
Expand Down Expand Up @@ -366,8 +374,11 @@ fn test_raw_node_propose_and_conf_change() {
assert_eq!(context, leave_cc.get_context(), "{:?}", cc.as_v2());
// Lie and pretend the ConfChange applied. It won't do so because now
// we require the joint quorum and we're only running one node.
let cs = raw_node.apply_conf_change(&leave_cc).unwrap();
assert_eq!(cs, exp2.unwrap());
let mut cs = raw_node.apply_conf_change(&leave_cc).unwrap();
let mut exp2 = exp2.unwrap();
sort_conf_state_collections(&mut cs);
sort_conf_state_collections(&mut exp2);
assert_eq!(cs, exp2);
}
}

Expand Down
2 changes: 1 addition & 1 deletion proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ protobuf-build = { version = "0.15.1", default-features = false }
[dependencies]
bytes = { version = "1", optional = true, default-features = false }
lazy_static = { version = "1", optional = true, default-features = false, features = ["spin_no_std"] }
prost = { version = "0.11", optional = true, default-features = false, features = ["prost-derive"] }
prost = { version = "0.12.4", optional = true, default-features = false, features = ["prost-derive"] }
protobuf = { version = "2", optional = true }
5 changes: 5 additions & 0 deletions proto/src/wrappers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Generated file, modified and added to support no_std

#[allow(deprecated)]
impl Entry {
#[inline]
pub fn default_ref() -> &'static Self {
Expand Down Expand Up @@ -220,6 +221,7 @@ impl Snapshot {
.unwrap_or_else(SnapshotMetadata::default)
}
}
#[allow(deprecated)]
impl Message {
pub fn new() -> Self {
Self::default()
Expand Down Expand Up @@ -604,6 +606,7 @@ impl ConfState {
self.auto_leave
}
}
#[allow(deprecated)]
impl ConfChange {
pub fn write_to_bytes(
&self,
Expand Down Expand Up @@ -683,6 +686,7 @@ impl ConfChange {
self.id
}
}
#[allow(deprecated)]
impl ConfChangeSingle {
#[inline]
pub fn default_ref() -> &'static Self {
Expand Down Expand Up @@ -715,6 +719,7 @@ impl ConfChangeSingle {
self.node_id
}
}
#[allow(deprecated)]
impl ConfChangeV2 {
pub fn write_to_bytes(
&self,
Expand Down
42 changes: 42 additions & 0 deletions scripts/ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2024 The Google raft-rs authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#!/usr/bin/env bash

# Exit when any command fails
#set -e

printf "\n// cargo fmt --all -- --check\n\n"
env cargo fmt --all -- --check

printf "\n// cargo clippy --all --all-targets -- -D clippy::all && cargo clippy --no-default-features --features prost-codec --features std -- -D clippy::all\n\n"
env cargo clippy --all --all-targets -- -D clippy::all && cargo clippy --no-default-features --features prost-codec --features std -- -D clippy::all

printf "\n// cargo build --no-default-features --features prost-codec --target x86_64-unknown-none\n\n"
env cargo build --no-default-features --features prost-codec --target x86_64-unknown-none

printf "\n// cargo test --all --no-default-features --features=prost-codec --features=default-logger --no-fail-fast -- --nocapture\n\n"
env cargo test --all --no-default-features --features=prost-codec --features=default-logger --no-fail-fast -- --nocapture

printf "\n// cargo test --all --no-fail-fast -- --nocapture\n\n"
env cargo test --all --no-fail-fast -- --nocapture

printf "\n// cargo bench --all -- --test\n\n"
env cargo bench --all -- --test

printf "\n// cargo test --tests --features failpoints --package harness -- --nocapture\n\n"
env cargo test --tests --features failpoints --package harness -- --nocapture

printf "\n// cargo test --no-default-features --features prost-codec --features std -- --nocapture\n\n"
env cargo test --no-default-features --features prost-codec --features std -- --nocapture
16 changes: 7 additions & 9 deletions src/quorum/majority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ pub struct Configuration {

impl core::fmt::Display for Configuration {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(
f,
"({})",
self.voters
.iter()
.map(|x| x.to_string())
.collect::<Vec<String>>()
.join(" ")
)
let mut voters = self
.voters
.iter()
.map(|x| x.to_string())
.collect::<Vec<String>>();
voters.sort();
write!(f, "({})", voters.join(" "))
}
}

Expand Down

0 comments on commit 9cb1d0a

Please sign in to comment.