szetszwo commented on PR #1296:
URL: https://github.com/apache/ratis/pull/1296#issuecomment-3416501339
> ... The usage on OzoneManager side is as follows:
>
> ```
> if (ozoneManager.isFollowerReadLocalLeaseEnabled() &&
> omRatisServer.getServerDivision().okForLocalReadBounded(
> ozoneManager.getFollowerReadLocalLeaseLagLimit(),
> ozoneManager.getFollowerReadLocalLeaseTimeMs())) {
> return handler.handleReadRequest(request);
> } else if (omRatisServer.isLinearizableRead()) {
> return
> ```
@symious , The current code already supports it. We may add the following
method to Ozone:
```java
boolean allowFollowerReadLocalLease(RaftServer.Division ratisDivision,
long leaseTimeMsLimit, long leaseLogLimit) {
final DivisionInfo divisionInfo = ratisDivision.getInfo();
final FollowerInfoProto followerInfo =
divisionInfo.getRoleInfoProto().getFollowerInfo();
if (followerInfo == null) {
return false; // not follower
}
final ServerRpcProto leaderInfo = followerInfo.getLeaderInfo();
if (leaderInfo == null) {
return false; // no leader
}
if (Time.monotonicNow() - leaderInfo.getLastRpcElapsedTimeMs() >
leaseTimeMsLimit) {
return false; // lease time expired
}
final RaftPeerId leaderId = divisionInfo.getLeaderId();
Long leaderCommit = null;
if (leaderId != null) {
for (CommitInfoProto i : ratisDivision.getCommitInfos()) {
if (i.getServer().getId().equals(leaderId.toByteString())) {
leaderCommit = i.getCommitIndex();
}
}
}
if (leaderCommit == null) {
return false;
}
return divisionInfo.getLastAppliedIndex() + leaseLogLimit >=
leaderCommit;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]