Skip to content

Commit

Permalink
fix: fix clippy (#553)
Browse files Browse the repository at this point in the history
Signed-off-by: Dat Tien Nguyen <[email protected]>
  • Loading branch information
datbeohbbh authored Oct 20, 2024
1 parent 2aefbf6 commit dfe2239
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 37 deletions.
5 changes: 2 additions & 3 deletions datadriven/src/datadriven.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,9 @@ where
if has_blank_line(&actual) {
r.emit("----");

r.rewrite_buffer.as_mut().map(|rb| {
if let Some(rb) = r.rewrite_buffer.as_mut() {
rb.push_str(&actual);
rb
});
}

r.emit("----");
r.emit("----");
Expand Down
5 changes: 2 additions & 3 deletions datadriven/src/test_data_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,9 @@ impl<'a> TestDataReader<'a> {
}

pub fn emit(&mut self, str: &str) {
self.rewrite_buffer.as_mut().map(|rb| {
if let Some(rb) = self.rewrite_buffer.as_mut() {
let str = str.to_string() + "\n";
rb.push_str(&str);
rb
});
}
}
}
4 changes: 3 additions & 1 deletion src/confchange/changer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ impl IncrChangeMap<'_> {
}
}

/// Changer facilitates configuration changes. It exposes methods to handle
/// Changer facilitates configuration changes.
///
/// It exposes methods to handle
/// simple and joint consensus while performing the proper validation that allows
/// refusing invalid configuration changes before they affect the active
/// configuration.
Expand Down
50 changes: 23 additions & 27 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ The `Ready` state contains quite a bit of information, and you need to check and
by one:
1. Check whether `messages` is empty or not. If not, it means that the node will send messages to
other nodes:
other nodes:
```rust
# use slog::{Drain, o};
Expand All @@ -226,7 +226,7 @@ other nodes:
```
2. Check whether `snapshot` is empty or not. If not empty, it means that the Raft node has received
a Raft snapshot from the leader and we must apply the snapshot:
a Raft snapshot from the leader and we must apply the snapshot:
```rust
# use slog::{Drain, o};
Expand Down Expand Up @@ -254,8 +254,8 @@ a Raft snapshot from the leader and we must apply the snapshot:
```
3. Check whether `committed_entries` is empty or not. If not, it means that there are some newly
committed log entries which you must apply to the state machine. Of course, after applying, you
need to update the applied index and resume `apply` later:
committed log entries which you must apply to the state machine. Of course, after applying, you
need to update the applied index and resume `apply` later:
```rust
# use slog::{Drain, o};
Expand Down Expand Up @@ -310,7 +310,7 @@ need to update the applied index and resume `apply` later:
after restarting, *it may work but potential log loss may also be ignored silently*.
4. Check whether `entries` is empty or not. If not empty, it means that there are newly added
entries but have not been committed yet, we must append the entries to the Raft log:
entries but have not been committed yet, we must append the entries to the Raft log:
```rust
# use slog::{Drain, o};
Expand All @@ -335,8 +335,8 @@ entries but have not been committed yet, we must append the entries to the Raft
```
5. Check whether `hs` is empty or not. If not empty, it means that the `HardState` of the node has
changed. For example, the node may vote for a new leader, or the commit index has been increased.
We must persist the changed `HardState`:
changed. For example, the node may vote for a new leader, or the commit index has been increased.
We must persist the changed `HardState`:
```rust
# use slog::{Drain, o};
Expand All @@ -360,7 +360,7 @@ We must persist the changed `HardState`:
```
6. Check whether `persisted_messages` is empty or not. If not, it means that the node will send messages to
other nodes after persisting hardstate, entries and snapshot:
other nodes after persisting hardstate, entries and snapshot:
```rust
# use slog::{Drain, o};
Expand All @@ -385,8 +385,8 @@ other nodes after persisting hardstate, entries and snapshot:
```
7. Call `advance` to notify that the previous work is completed. Get the return value `LightReady`
and handle its `messages` and `committed_entries` like step 1 and step 3 does. Then call `advance_apply`
to advance the applied index inside.
and handle its `messages` and `committed_entries` like step 1 and step 3 does. Then call `advance_apply`
to advance the applied index inside.
```rust
# use slog::{Drain, o};
Expand Down Expand Up @@ -470,8 +470,8 @@ This process is a two-phase process, during the midst of it the peer group's lea
**two independent, possibly overlapping peer sets**.
> **Note:** In order to maintain resiliency guarantees (progress while a majority of both peer sets is
active), it is recommended to wait until the entire peer group has exited the transition phase
before taking old, removed peers offline.
> active), it is recommended to wait until the entire peer group has exited the transition phase
> before taking old, removed peers offline.
*/

Expand Down Expand Up @@ -569,24 +569,20 @@ pub mod prelude {

/// The default logger we fall back to when passed `None` in external facing constructors.
///
/// Currently, this is a `log` adaptor behind a `Once` to ensure there is no clobbering.
/// Currently, this is a `log` adaptor behind a `OnceLock` to ensure there is no clobbering.
#[cfg(any(test, feature = "default-logger"))]
pub fn default_logger() -> slog::Logger {
use slog::{o, Drain};
use std::sync::{Mutex, Once};

static LOGGER_INITIALIZED: Once = Once::new();
static mut LOGGER: Option<slog::Logger> = None;

let logger = unsafe {
LOGGER_INITIALIZED.call_once(|| {
let decorator = slog_term::TermDecorator::new().build();
let drain = slog_term::CompactFormat::new(decorator).build();
let drain = slog_envlogger::new(drain);
LOGGER = Some(slog::Logger::root(Mutex::new(drain).fuse(), o!()));
});
LOGGER.as_ref().unwrap()
};
use std::sync::{Mutex, OnceLock};

static LOGGER_INITIALIZED: OnceLock<slog::Logger> = OnceLock::new();
let logger = LOGGER_INITIALIZED.get_or_init(|| {
let decorator = slog_term::TermDecorator::new().build();
let drain = slog_term::CompactFormat::new(decorator).build();
let drain = slog_envlogger::new(drain);
slog::Logger::root(Mutex::new(drain).fuse(), o!())
});

if let Some(case) = std::thread::current()
.name()
.and_then(|v| v.split(':').last())
Expand Down
3 changes: 3 additions & 0 deletions src/log_unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ use crate::eraftpb::{Entry, Snapshot};
use crate::util::entry_approximate_size;
use slog::Logger;

/// Unstable contains "unstable" log entries and snapshot state that has
/// not yet been written to Storage.
///
/// The `unstable.entries[i]` has raft log position `i+unstable.offset`.
/// Note that `unstable.offset` may be less than the highest log
/// position in storage; this means that the next write to storage
Expand Down
2 changes: 1 addition & 1 deletion src/quorum/majority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::collections::hash_set::Iter;
use std::fmt::Formatter;
use std::mem::MaybeUninit;
use std::ops::{Deref, DerefMut};
use std::{cmp, slice, u64};
use std::{cmp, slice};

/// A set of IDs that uses majority quorums to make decisions.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
Expand Down
1 change: 1 addition & 0 deletions src/raw_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ impl Ready {
/// MustSync is false if and only if
/// 1. no HardState or only its commit is different from before
/// 2. no Entries and Snapshot
///
/// If it's false, an asynchronous write of HardState is permissible before calling
/// [`RawNode::on_persist_ready`] or [`RawNode::advance`] or its families.
#[inline]
Expand Down
1 change: 1 addition & 0 deletions src/read_only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub enum ReadOnlyOption {
}

/// ReadState provides state for read only query.
///
/// It's caller's responsibility to send MsgReadIndex first before getting
/// this state from ready. It's also caller's duty to differentiate if this
/// state is what it requests through request_ctx, e.g. given a unique id as
Expand Down
2 changes: 1 addition & 1 deletion src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ mod test {
new_entry(5, 5),
new_entry(6, 6),
];
let max_u64 = u64::max_value();
let max_u64 = u64::MAX;
let mut tests = vec![
(
2,
Expand Down
1 change: 0 additions & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

use std::fmt;
use std::fmt::Write;
use std::u64;

use slog::{OwnedKVList, Record, KV};

Expand Down

0 comments on commit dfe2239

Please sign in to comment.