Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

drmingdrmer
Copy link
Member

@drmingdrmer drmingdrmer commented Oct 12, 2024

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

Refactor: remvoe Copy bound from NodeId

The NodeId type is currently defined as:

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:

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

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

This change is Reviewable

@drmingdrmer drmingdrmer force-pushed the 159-nid-no-copy branch 3 times, most recently from c1e5faf to 740010d Compare October 13, 2024 01:59
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
@drmingdrmer drmingdrmer marked this pull request as ready for review October 13, 2024 02:52
Copy link
Collaborator

@SteveLauC SteveLauC left a 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)))?;
Copy link
Collaborator

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:

Suggested change
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)))?;

Comment on lines +245 to +246
if Some(accepted.clone()) > curr_accepted {
self.io_state.io_progress.accept(accepted.clone());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do this:

Suggested change
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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be avoided:

Suggested change
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();
Copy link
Collaborator

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

Copy link
Collaborator

@schreter schreter left a 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)

@SteveLauC
Copy link
Collaborator

@SteveLauC (no review from my side, just a tip)

Amazing! TIL! Will set them up. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove Copy Bound from NodeId
3 participants