We get more precise tracking and also fewer conversions on the fast
path.
Change-Id: Iea9700bce0b2c75ff26447f2b65022dbfb8dda37
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
/**
* Returns the time since the last activity occurred for the follower.
*
/**
* Returns the time since the last activity occurred for the follower.
*
- * @return time in milliseconds since the last activity from the follower.
+ * @return time in nanoseconds since the last activity from the follower.
- public long timeSinceLastActivity() {
- return stopwatch.elapsed(TimeUnit.MILLISECONDS);
+ public long nanosSinceLastActivity() {
+ return stopwatch.elapsed(TimeUnit.NANOSECONDS);
for (String id: followerIds) {
final FollowerLogInformation info = leader.getFollower(id);
followerInfoList.add(new FollowerInfo(id, info.getNextIndex(), info.getMatchIndex(),
for (String id: followerIds) {
final FollowerLogInformation info = leader.getFollower(id);
followerInfoList.add(new FollowerInfo(id, info.getNextIndex(), info.getMatchIndex(),
- info.isFollowerActive(), DurationFormatUtils.formatDurationHMS(info.timeSinceLastActivity()),
+ info.isFollowerActive(), DurationFormatUtils.formatDurationHMS(
+ TimeUnit.NANOSECONDS.toMillis(info.nanosSinceLastActivity())),
context.getPeerInfo(info.getId()).isVoting()));
}
context.getPeerInfo(info.getId()).isVoting()));
}
- if (followerLogInformation.timeSinceLastActivity()
- > context.getConfigParams().getElectionTimeOutInterval().toMillis()) {
+ final long lastActivityNanos = followerLogInformation.nanosSinceLastActivity();
+ if (lastActivityNanos > context.getConfigParams().getElectionTimeOutInterval().toNanos()) {
log.warn("{} : handleAppendEntriesReply delayed beyond election timeout, "
+ "appendEntriesReply : {}, timeSinceLastActivity : {}, lastApplied : {}, commitIndex : {}",
log.warn("{} : handleAppendEntriesReply delayed beyond election timeout, "
+ "appendEntriesReply : {}, timeSinceLastActivity : {}, lastApplied : {}, commitIndex : {}",
- logName(), appendEntriesReply, followerLogInformation.timeSinceLastActivity(),
+ logName(), appendEntriesReply, TimeUnit.NANOSECONDS.toMillis(lastActivityNanos),
context.getLastApplied(), context.getCommitIndex());
}
context.getLastApplied(), context.getCommitIndex());
}
- protected void sendAppendEntries(final long timeSinceLastActivityInterval, final boolean isHeartbeat) {
+ protected void sendAppendEntries(final long timeSinceLastActivityIntervalNanos, final boolean isHeartbeat) {
// Send an AppendEntries to all followers
for (Entry<String, FollowerLogInformation> e : followerToLog.entrySet()) {
final String followerId = e.getKey();
final FollowerLogInformation followerLogInformation = e.getValue();
// This checks helps not to send a repeat message to the follower
if (!followerLogInformation.isFollowerActive()
// Send an AppendEntries to all followers
for (Entry<String, FollowerLogInformation> e : followerToLog.entrySet()) {
final String followerId = e.getKey();
final FollowerLogInformation followerLogInformation = e.getValue();
// This checks helps not to send a repeat message to the follower
if (!followerLogInformation.isFollowerActive()
- || followerLogInformation.timeSinceLastActivity() >= timeSinceLastActivityInterval) {
+ || followerLogInformation.nanosSinceLastActivity() >= timeSinceLastActivityIntervalNanos) {
sendUpdatesToFollower(followerId, followerLogInformation, true, isHeartbeat);
}
}
sendUpdatesToFollower(followerId, followerLogInformation, true, isHeartbeat);
}
}
private void sendHeartBeat() {
if (!followerToLog.isEmpty()) {
log.trace("{}: Sending heartbeat", logName());
private void sendHeartBeat() {
if (!followerToLog.isEmpty()) {
log.trace("{}: Sending heartbeat", logName());
- sendAppendEntries(context.getConfigParams().getHeartBeatInterval().toMillis(), true);
+ sendAppendEntries(context.getConfigParams().getHeartBeatInterval().toNanos(), true);
appendEntriesMessageSlicer.checkExpiredSlicedMessageState();
}
appendEntriesMessageSlicer.checkExpiredSlicedMessageState();
}