Skip to content

Commit

Permalink
Refactor: remvoe Copy bound from NodeId
Browse files Browse the repository at this point in the history
The `NodeId` type is currently defined as:

```rust
type NodeId: .. + Copy + .. + 'static;
```

This commit removes the `Copy` bound from `NodeId`.
This modification will allow the use of non-`Copy` types as `NodeId`,
providing greater flexibility for applications that prefer
variable-length strings or other non-`Copy` types for node
identification.

This change maintain compatibility by updating derived `Copy`
implementations with manual implementations:

```rust
// Before
#[derive(Copy...)]
pub struct LogId<NID: NodeId> {}

// After
impl<NID: Copy> Copy for LogId<NID> {}
```

- Fix: databendlabs#1250
  • Loading branch information
drmingdrmer committed Oct 12, 2024
1 parent 3fe7d9a commit b0c3dee
Show file tree
Hide file tree
Showing 54 changed files with 491 additions and 415 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ bytes = "1.0"
chrono = { version = "0.4" }
clap = { version = "4.1.11", features = ["derive", "env"] }
derive_more = { version = "1.0", features = ["std", "from", "try_into", "display"] }
dupit = { version = "0.2.0" }
futures = "0.3"
lazy_static = "1.4.0"
maplit = "1.0.2"
Expand Down
1 change: 1 addition & 0 deletions openraft/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ byte-unit = { workspace = true }
chrono = { workspace = true }
clap = { workspace = true }
derive_more = { workspace = true }
dupit = { workspace = true }
futures = { workspace = true }
openraft-macros = { path = "../macros", version = "0.10.0" }
maplit = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/core/heartbeat/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::LogId;
use crate::RaftTypeConfig;

/// The information for broadcasting a heartbeat.
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone)]
#[derive(PartialEq, Eq)]
pub struct HeartbeatEvent<C>
where C: RaftTypeConfig
Expand Down
8 changes: 4 additions & 4 deletions openraft/src/core/heartbeat/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,19 @@ where C: RaftTypeConfig
{
for (target, node) in targets {
tracing::debug!("id={} spawn HeartbeatWorker target={}", self.id, target);
let network = network_factory.new_client(target, &node).await;
let network = network_factory.new_client(target.clone(), &node).await;

let worker = HeartbeatWorker {
id: self.id,
id: self.id.clone(),
rx: self.rx.clone(),
network,
target,
target: target.clone(),
node,
config: self.config.clone(),
tx_notification: tx_notification.clone(),
};

let span = tracing::span!(parent: &Span::current(), Level::DEBUG, "heartbeat", id=display(self.id), target=display(target));
let span = tracing::span!(parent: &Span::current(), Level::DEBUG, "heartbeat", id=display(&self.id), target=display(&target));

let (tx_shutdown, rx_shutdown) = C::oneshot();

Expand Down
10 changes: 5 additions & 5 deletions openraft/src/core/heartbeat/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ where
_ = self.rx.changed().fuse() => {},
}

let heartbeat: Option<HeartbeatEvent<C>> = *self.rx.borrow_watched();
let heartbeat: Option<HeartbeatEvent<C>> = self.rx.borrow_watched().clone();

// None is the initial value of the WatchReceiver, ignore it.
let Some(heartbeat) = heartbeat else {
Expand All @@ -82,9 +82,9 @@ where
let option = RPCOption::new(timeout);

let payload = AppendEntriesRequest {
vote: heartbeat.session_id.leader_vote.into_vote(),
vote: heartbeat.session_id.leader_vote.clone().into_vote(),
prev_log_id: None,
leader_commit: heartbeat.committed,
leader_commit: heartbeat.committed.clone(),
entries: vec![],
};

Expand All @@ -94,9 +94,9 @@ where
match res {
Ok(Ok(_)) => {
let res = self.tx_notification.send(Notification::HeartbeatProgress {
session_id: heartbeat.session_id,
session_id: heartbeat.session_id.clone(),
sending_time: heartbeat.time,
target: self.target,
target: self.target.clone(),
});

if res.is_err() {
Expand Down
Loading

0 comments on commit b0c3dee

Please sign in to comment.