-
Notifications
You must be signed in to change notification settings - Fork 440
RATIS-1894. Implement ReadOnly based on leader lease #925
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
Changes from all commits
786f519
45e227e
b1d12ec
4202af8
6d82680
9f91f77
9ce652b
f730931
85dc009
07b796e
505ce9f
8055787
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -438,6 +438,7 @@ void stop() { | |
| messageStreamRequests.clear(); | ||
| // TODO client should retry on NotLeaderException | ||
| readIndexHeartbeats.failListeners(nle); | ||
| lease.getAndSetEnabled(false); | ||
| server.getServerRpc().notifyNotLeader(server.getMemberId().getGroupId()); | ||
| logAppenderMetrics.unregister(); | ||
| raftServerMetrics.unregister(); | ||
|
|
@@ -675,6 +676,7 @@ void submitStepDownEvent(long term, StepDownReason reason) { | |
|
|
||
| private void stepDown(long term, StepDownReason reason) { | ||
| try { | ||
| lease.getAndSetEnabled(false); | ||
| server.changeToFollowerAndPersistMetadata(term, false, reason); | ||
| pendingStepDown.complete(server::newSuccessReply); | ||
| } catch(IOException e) { | ||
|
|
@@ -953,6 +955,7 @@ private void checkAndUpdateConfiguration() { | |
| pendingRequests.replySetConfiguration(server::newSuccessReply); | ||
| // if the leader is not included in the current configuration, step down | ||
| if (!conf.containsInConf(server.getId(), RaftPeerRole.FOLLOWER, RaftPeerRole.LISTENER)) { | ||
| lease.getAndSetEnabled(false); | ||
| LOG.info("{} is not included in the new configuration {}. Will shutdown server...", this, conf); | ||
| try { | ||
| // leave some time for all RPC senders to send out new conf entry | ||
|
|
@@ -1113,6 +1116,12 @@ CompletableFuture<Long> getReadIndex(Long readAfterWriteConsistentIndex) { | |
| new LeaderNotReadyException(server.getMemberId()))); | ||
| } | ||
|
|
||
| // if lease is enabled, check lease first | ||
| if (hasLease()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that even though lease read is not enabled, we are still calling
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right! Fixed, PTAL. |
||
| return CompletableFuture.completedFuture(readIndex); | ||
| } | ||
|
|
||
| // send heartbeats and wait for majority acknowledgments | ||
| final AppendEntriesListener listener = readIndexHeartbeats.addAppendEntriesListener( | ||
| readIndex, i -> new AppendEntriesListener(i, senders)); | ||
|
|
||
|
|
@@ -1129,7 +1138,15 @@ public void onAppendEntriesReply(LogAppender appender, RaftProtos.AppendEntriesR | |
| readIndexHeartbeats.onAppendEntriesReply(appender, reply, this::hasMajority); | ||
| } | ||
|
|
||
| boolean getAndSetLeaseEnabled(boolean newValue) { | ||
| return lease.getAndSetEnabled(newValue); | ||
| } | ||
|
|
||
| boolean hasLease() { | ||
| if (!lease.isEnabled()) { | ||
| return false; | ||
| } | ||
|
|
||
| if (checkLeaderLease()) { | ||
| return true; | ||
| } | ||
|
|
@@ -1143,7 +1160,8 @@ boolean hasLease() { | |
| } | ||
|
|
||
| private boolean checkLeaderLease() { | ||
| return isReady() && (server.getRaftConf().isSingleton() || lease.isValid()); | ||
| return isRunning() && isReady() | ||
| && (server.getRaftConf().isSingleton() || lease.isValid()); | ||
| } | ||
|
|
||
| void replyPendingRequest(long logIndex, RaftClientReply reply) { | ||
|
|
||
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.
do we need to check this when lease read is disabled?