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(Ready): add pub getters and make fields private #120

Merged
merged 5 commits into from
Nov 2, 2018

Conversation

Ryan-Git
Copy link
Contributor

@Ryan-Git Ryan-Git commented Sep 9, 2018

Fixes #90

siddontang
siddontang previously approved these changes Sep 10, 2018
Copy link
Contributor

@siddontang siddontang left a comment

Choose a reason for hiding this comment

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

LGTM

Seem we need to upgrade the version too. It breaks the compatibility.

/cc @Hoverbear @BusyJay

Copy link
Member

@BusyJay BusyJay left a comment

Choose a reason for hiding this comment

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

It looks very expensive to maintain a read-only ready. And what if users want to advance ready partially?

src/raw_node.rs Outdated
/// store/state-machine. These have previously been committed to stable
/// store.
#[inline]
pub fn committed_entries(&self) -> Option<&[Entry]> {
Copy link
Member

Choose a reason for hiding this comment

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

So users have to clone the memory to handle committed entries in other thread now?

src/raw_node.rs Outdated
/// If it contains a MsgSnap message, the application MUST report back to raft
/// when the snapshot has been received or has failed by calling ReportSnapshot.
#[inline]
pub fn messages(&self) -> &[Message] {
Copy link
Member

Choose a reason for hiding this comment

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

Channel usually move the message. So a clone seems unavoidable.

@Ryan-Git
Copy link
Contributor Author

@siddontang
shall I bump the version? I saw separate pr to release new versions, thought it should be left for you guys.

@BusyJay
Thanks for the comments. I searched for examples in TiKV and found two
mutable ref:
self.pending_messages = mem::replace(&mut ready.messages, vec![]);
move:
self.send(trans, ready.messages.drain(..), &mut metrics.message)
both of which seem to take and clear the origin message.

I don't have a clear enough understanding of this scenario, @Hoverbear, as the issue owner, what do you think about this?

@Hoverbear
Copy link
Contributor

Thanks for taking up the flag on this @Ryan-Git. :)

We will definitely need to include this in a non-patch version since it's an API break.

I think @BusyJay has a very interesting point:

And what if users want to advance ready partially?

@BusyJay, could you expand more on this? I was unaware of this use.

@BusyJay
Copy link
Member

BusyJay commented Sep 11, 2018

For example, we may handle committed entries and entries differently so may not advance them all together. Maybe we need a more clear Ready mechanism for this. For example, Use Ready to represent readiness, and use HandleProgress, which is just an example name, to represent the handle progress. So Ready is free to be moved and modify, raft is only required to check the progress.

@Hoverbear
Copy link
Contributor

@BusyJay Maybe we should revert the change on these particular fields, and merge this PR, then investigate how to move forward with this solution in another issue?

@Hoverbear Hoverbear added this to the 0.5.0 milestone Sep 11, 2018
@Ryan-Git
Copy link
Contributor Author

I could revert changes on messages and committed_entries mentioned above.

@Hoverbear
Copy link
Contributor

@Ryan-Git Yeah, let's revert them for now. Thanks so much!

@Ryan-Git
Copy link
Contributor Author

updated

@siddontang
Copy link
Contributor

PTAL @BusyJay

@Hoverbear Hoverbear added the Enhancement An improvement to existing code. label Sep 17, 2018
@@ -59,21 +59,22 @@ fn conf_change(t: ConfChangeType, node_id: u64) -> ConfChange {
cc
}

fn new_ready(
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can #[derive(PartialEq)] instead?

Copy link
Contributor Author

@Ryan-Git Ryan-Git Sep 23, 2018

Choose a reason for hiding this comment

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

Does it mean to add a pub constructor? Otherwise we can't make a Ready from the private fields.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, nevermind. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

emm.. do you mean to add the constructor or just keep it as it is?

@hicqu
Copy link
Contributor

hicqu commented Oct 9, 2018

LGTM. Please resolves conflicts.

@Ryan-Git
Copy link
Contributor Author

LGTM. Please resolves conflicts.

resolved

@Hoverbear
Copy link
Contributor

bors r+

bors bot added a commit that referenced this pull request Nov 1, 2018
120: refactor(Ready): add pub getters and make fields private r=Hoverbear a=Ryan-Git

Fixes #90 

Co-authored-by: renhongdi <renhongdi@mobike.com>
Co-authored-by: Ryan-Git <ryan.hd.ren@gmail.com>
@Hoverbear
Copy link
Contributor

@Ryan-Git Thanks, I'm going to drive this to merge. :) I decided to use your PR to test our bors and I have a small hiccup. If you get some notifications you can just ignore them. Sorry about that!

@bors

This comment has been minimized.

@Hoverbear

This comment has been minimized.

@bors

This comment has been minimized.

@Hoverbear

This comment has been minimized.

bors bot added a commit that referenced this pull request Nov 2, 2018
120: refactor(Ready): add pub getters and make fields private r=Hoverbear a=Ryan-Git

Fixes #90 

Co-authored-by: renhongdi <renhongdi@mobike.com>
Co-authored-by: Ryan-Git <ryan.hd.ren@gmail.com>
Co-authored-by: A. Hobden <operator@hoverbear.org>
@bors

This comment has been minimized.

@Hoverbear

This comment has been minimized.

@bors

This comment has been minimized.

@tikv tikv deleted a comment from bors bot Nov 2, 2018
@Hoverbear
Copy link
Contributor

bors r+

@tikv tikv deleted a comment from bors bot Nov 2, 2018
bors bot added a commit that referenced this pull request Nov 2, 2018
120: refactor(Ready): add pub getters and make fields private r=Hoverbear a=Ryan-Git

Fixes #90 

Co-authored-by: renhongdi <renhongdi@mobike.com>
Co-authored-by: Ryan-Git <ryan.hd.ren@gmail.com>
Co-authored-by: A. Hobden <operator@hoverbear.org>
@tikv tikv deleted a comment from bors bot Nov 2, 2018
@bors
Copy link
Contributor

bors bot commented Nov 2, 2018

@bors bors bot merged commit 41e3783 into tikv:master Nov 2, 2018
@Hoverbear
Copy link
Contributor

🎉 Thank you @Ryan-Git for your patience and hard work, and @bors[bot] for the merge. 😉

@Ryan-Git
Copy link
Contributor Author

Ryan-Git commented Nov 3, 2018

@Hoverbear My pleasure :-)

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

Successfully merging this pull request may close these issues.

5 participants