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

raftstore: cache term #1154

Merged
merged 2 commits into from
Oct 11, 2016
Merged

raftstore: cache term #1154

merged 2 commits into from
Oct 11, 2016

Conversation

BusyJay
Copy link
Member

@BusyJay BusyJay commented Oct 9, 2016

Currently almost every call to term will invoke rocksdb::get. This pr reduce the call times by caching the term of last_index. If truncated_term is equal to last_term, then every entry between truncated_index and last_index should have the same term.

@@ -160,6 +163,16 @@ impl PeerStorage {
raft_state
}
};
let last_term = match raft_state.get_last_index() {
0 => 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

any test to cover 0 and RAFT_INIT_LOG_INDEX ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Existing cases cover it already.

@@ -279,6 +293,9 @@ impl PeerStorage {
return Ok(self.truncated_term());
}
try!(self.check_range(idx, idx + 1));
if self.truncated_term() == self.last_term || idx == self.last_index() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why check truncated_term() here?

@hhkbp2
Copy link
Contributor

hhkbp2 commented Oct 11, 2016

LGTM

@BusyJay
Copy link
Member Author

BusyJay commented Oct 11, 2016

PTAL

@hhkbp2
Copy link
Contributor

hhkbp2 commented Oct 11, 2016

LGTM

1 similar comment
@siddontang
Copy link
Contributor

LGTM

@BusyJay BusyJay merged commit f9c2c93 into master Oct 11, 2016
@BusyJay BusyJay deleted the busyjay/cache-term branch October 11, 2016 11:30
zhangjinpeng87 pushed a commit that referenced this pull request Oct 17, 2016
mittalrishabh pushed a commit to mittalrishabh/tikv that referenced this pull request Nov 22, 2024
* Configurable lowres tso update interval

Signed-off-by: Ari Ekmekji <aekmekji@gmail.com>

* Review comments

Signed-off-by: Ari Ekmekji <aekmekji@gmail.com>

* Comment for exported function

Signed-off-by: Ari Ekmekji <aekmekji@gmail.com>

---------

Signed-off-by: Ari Ekmekji <aekmekji@gmail.com>
Co-authored-by: Ari Ekmekji <ari.ekmekji@airbnb.com>
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.

3 participants