-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor: remvoe Copy
bound from NodeId
#1255
base: main
Are you sure you want to change the base?
Conversation
c1e5faf
to
740010d
Compare
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
740010d
to
ed3b446
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for reviewing this PR on GitHub, reviewable does not show line numbers, which makes me impossible to locate the code and do a check in my IDE, left some comments.
BTW, there are multiple "unused" warnings reported by GitHub Actions on the review page, are they false-positive? If not, perhaps we can do a clean-up:)
let cmd = sm::Command::apply(first, last); | ||
self.sm_handle.send(cmd).map_err(|e| StorageError::apply(last, AnyError::error(e)))?; | ||
let cmd = sm::Command::apply(first, last.clone()); | ||
self.sm_handle.send(cmd).map_err(|e| StorageError::apply(last.clone(), AnyError::error(e)))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This clone can be avoided:
self.sm_handle.send(cmd).map_err(|e| StorageError::apply(last.clone(), AnyError::error(e)))?; | |
self.sm_handle.send(cmd).map_err(|e| StorageError::apply(last, AnyError::error(e)))?; |
if Some(accepted.clone()) > curr_accepted { | ||
self.io_state.io_progress.accept(accepted.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do this:
if Some(accepted.clone()) > curr_accepted { | |
self.io_state.io_progress.accept(accepted.clone()); | |
if Some(&accepted) > curr_accepted.as_ref() { | |
self.io_state.io_progress.accept(accepted); |
(vec![], r) | ||
} else { | ||
// limited_get_log_entries will return logs smaller than the range [start, end). | ||
let logs = self.log_reader.limited_get_log_entries(start, end).await?; | ||
|
||
let first = *logs.first().map(|x| x.get_log_id()).unwrap(); | ||
let last = *logs.last().map(|x| x.get_log_id()).unwrap(); | ||
let first = logs.first().map(|x| x.get_log_id().clone()).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be avoided:
let first = logs.first().map(|x| x.get_log_id().clone()).unwrap(); | |
let first = logs.first().map(|x| x.get_log_id()).unwrap(); |
@@ -496,7 +496,7 @@ where | |||
})) | |||
} | |||
AppendEntriesResponse::Conflict => { | |||
let conflict = sending_range.prev; | |||
let conflict = sending_range.prev.clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we can move sending_range.prev
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SteveLauC (no review from my side, just a tip)
reviewable does not show line numbers, which makes me impossible to locate the code and do a check in my IDE, left some comments
Actually, it does. It is just a bit cumbersome, since you have to set it up, see here. Similarly, for locating the code in the IDE, you can directly jump into the IDE from Reviewable from any comment (also from a new draft). It is documented here. With that, you don't even strictly need line numbers (BTW, those are shown in the draft of the new comment as well), but I personally did configure them for myself :-).
Reviewable status: 0 of 57 files reviewed, 4 unresolved discussions (waiting on @drmingdrmer and @SteveLauC)
Amazing! TIL! Will set them up. 😄 |
I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/
Summary
Refactor: remvoe
Copy
bound fromNodeId
The
NodeId
type is currently defined as:This commit removes the
Copy
bound fromNodeId
.This modification will allow the use of non-
Copy
types asNodeId
,providing greater flexibility for applications that prefer
variable-length strings or other non-
Copy
types for nodeidentification.
This change maintain compatibility by updating derived
Copy
implementations with manual implementations:
Copy
Bound fromNodeId
#1250This change is