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

Require documentation on public interfaces #87

Merged
merged 2 commits into from
Jul 13, 2018

Conversation

choubacha
Copy link
Contributor

Previously, compiling would not warn or error for lack of documentation.
Now the compiler will fail if public interfaces are left without
documentation. To prevent the library from failing, all public
interfaces have been documented.

resolves #72

Critique welcome: I tried to document the functions as I understood them but there
may be places where I have typos or misunderstood.

I also noticed that some of these functions should probably be scoped to the crate instead of
making them public. I did not change them, however, as that would potentially break the interface.
Could you let me know if any of these functions can be converted to pub(crate)?

@choubacha choubacha force-pushed the choubacha/deny-missing-docs branch from 622325c to 3dea091 Compare July 9, 2018 22:15
@@ -224,6 +225,8 @@ extern crate protobuf;
extern crate quick_error;
extern crate rand;

/// This module supplies the needed message types. However, it is autogenerated and thus cannot be
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could examine having the generated code use comments from the proto files as well. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would be really cool!

@@ -148,6 +166,8 @@ impl Unstable {
&self.entries[l - off..h - off]
}

/// Asserts the hi and lo values against each other and against the
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you throw hi and lo in ticks so they're formatted distinctly?

pub fn iter_mut(&mut self) -> Chain<IterMut<u64, Progress>, IterMut<u64, Progress>> {
self.voters.iter_mut().chain(&mut self.learners)
}

/// Adds a voter node
///
/// # Panics
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be avoided. :) Thanks: #88

pub fn remove(&mut self, id: u64) -> Option<Progress> {
match self.voters.remove(&id) {
None => self.learners.remove(&id),
some => some,
}
}

/// Promote a learner to a peer.
///
/// # Panics
Copy link
Contributor

Choose a reason for hiding this comment

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

#89

src/raft.rs Outdated
Leader,
/// The node could become a candidate.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a note that this only happens if prevote is enabled.

src/raft.rs Outdated
@@ -753,6 +794,8 @@ impl<T: Storage> Raft<T> {
}
}

/// Appends an slice of entries to the log. The entries are updated to match
Copy link
Contributor

Choose a reason for hiding this comment

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

Appends a slice

// All fields in Ready are read-only.
/// Ready encapsulates the entries and messages that are ready to read,
/// be saved to stable storage, committed or sent to other peers.
/// All fields in Ready are read-only.
Copy link
Contributor

Choose a reason for hiding this comment

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

#90

src/status.rs Outdated
pub hs: HardState,
/// The softstate of the raft, representing prosposed state.
Copy link
Contributor

Choose a reason for hiding this comment

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

proposed

Copy link
Contributor

@Hoverbear Hoverbear left a comment

Choose a reason for hiding this comment

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

I notice that there is consistency issues between some comments (no capital at the start.) and the new ones (Capital at the start.).

Would you be willing to fix them to all be one style at least for this diff? (`Capital at the front works for me.) If not I can follow up.

@siddontang
Copy link
Contributor

PTAL @queenypingcap

@choubacha choubacha force-pushed the choubacha/deny-missing-docs branch from 3dea091 to 6804476 Compare July 11, 2018 03:03
@choubacha
Copy link
Contributor Author

@Hoverbear PTAL

@choubacha choubacha force-pushed the choubacha/deny-missing-docs branch from 6804476 to a20eff4 Compare July 11, 2018 03:06
@Hoverbear Hoverbear added this to the 0.4.0 milestone Jul 11, 2018
@Hoverbear Hoverbear added the Enhancement An improvement to existing code. label Jul 11, 2018
@@ -6,6 +6,16 @@ enum EntryType {
EntryConfChange = 1;
}

// The entry is a type of change that needs to be applied. It contains two data fields.
// Which field is used and how can be determined by the entry type.

Choose a reason for hiding this comment

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

-> Which field is used and how it can be determined by the entry type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it should be:

Which field is used, and how, is determined by the entry type.

The usage and how it's used is determined by the type. I'm rewording it completely though to see if I can make it more obvious.

While the fields are built into the model; their usage is determined by the entry_type.

src/progress.rs Outdated
/// an optimized state for fast replicating log entries to the follower.
///
/// When in ProgressStateSnapshot, leader should have sent out snapshot
/// before and stops sending any replication message.

Choose a reason for hiding this comment

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

stops -> stop

src/progress.rs Outdated
@@ -200,28 +233,31 @@ impl Progress {
}
}

/// Changes the progress to a a Replicate.

Choose a reason for hiding this comment

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

Changes the progress to a Replicate.

src/progress.rs Outdated
pub fn optimistic_update(&mut self, n: u64) {
self.next_idx = n + 1;
}

// maybe_decr_to returns false if the given to index comes from an out of order message.
// Otherwise it decreases the progress next index to min(rejected, last) and returns true.
/// Returns false if the given to index comes from an out of order message.

Choose a reason for hiding this comment

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

-> Returns false if the given index comes from an out of order message. ?

src/raft.rs Outdated
@@ -444,38 +472,45 @@ impl<T: Storage> Raft<T> {
r
}

/// Grabs a immutable reference to the store.

Choose a reason for hiding this comment

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

a -> an

src/raft.rs Outdated
@@ -2060,6 +2132,7 @@ impl<T: Storage> Raft<T> {
self.election_elapsed >= self.randomized_election_timeout
}

/// Regenerates and stroes the election timeout.

Choose a reason for hiding this comment

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

stroes -> stores

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good eye!

src/raft_log.rs Outdated
/// It returns the first index of conflicting entries between the existing
/// entries and the given entries, if there are any.
///
/// If there is no conflicting entries, and the existing entries contain

Choose a reason for hiding this comment

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

-> If there are no conflicting entries, and the existing entries contain...

src/raft_log.rs Outdated
/// If there is no conflicting entries, and the existing entries contain
/// all the given entries, zero will be returned.
///
/// If there is no conflicting entries, but the given entries contains new

Choose a reason for hiding this comment

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

-> If there are no conflicting entries, but the given entries contain new...

src/raw_node.rs Outdated
// Returns true to indicate that there will probably be some readiness need to be handled.
/// Tick advances the internal logical clock by a single tick.
///
/// Returns true to indicate that there will probably be some readiness need to be handled.

Choose a reason for hiding this comment

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

Returns true to indicate that there will probably be some readiness which need to be handled.

src/raw_node.rs Outdated
/// ReadIndex requests a read state. The read state will be set in ready.
/// Read State has a read index. Once the application advances further than the read
/// index, any linearizable read requests issued before the read request can be
/// processed safely. The read state will have the same rctx attched.

Choose a reason for hiding this comment

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

attched -> attached

@choubacha choubacha force-pushed the choubacha/deny-missing-docs branch from a20eff4 to f26ba85 Compare July 11, 2018 15:39
@choubacha
Copy link
Contributor Author

@CaitinChen Thank you for the thorough review! PTAL

Previously, compiling would not warn or error for lack of documentation.
Now the compiler will fail if public interfaces are left without
documentation. To prevent the library from failing, all public
interfaces have been documented.

resolves tikv#72
@choubacha choubacha force-pushed the choubacha/deny-missing-docs branch from f26ba85 to 8772e69 Compare July 11, 2018 15:41
Copy link
Contributor

@Hoverbear Hoverbear left a comment

Choose a reason for hiding this comment

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

Thank you for this valuable contribution. 🙇‍♀️ :

Copy link

@CaitinChen CaitinChen left a comment

Choose a reason for hiding this comment

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

LGTM

@Hoverbear Hoverbear merged commit 18f1cd8 into tikv:master Jul 13, 2018
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.

deny missing docs
4 participants