elek commented on a change in pull request #185:
URL: https://github.com/apache/incubator-ratis/pull/185#discussion_r482866266



##########
File path: 
ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcLogAppender.java
##########
@@ -101,41 +101,44 @@ private synchronized void 
resetClient(AppendEntriesRequest request) {
 
   @Override
   protected void runAppenderImpl() throws IOException {
-    boolean shouldAppendLog;
+    boolean installSnapshotRequired;
     for(; isAppenderRunning(); mayWait()) {
-      shouldAppendLog = true;
-      if (shouldSendRequest()) {
+      installSnapshotRequired = false;
+
+      //HB period is expired OR we have messages OR follower is behind with 
commit index
+      if (haveLogEntriesToSendOut() || heartbeatTimeout() || 
isFollowerCommitBehindLastCommitIndex()) {
+
         if (installSnapshotEnabled) {
           SnapshotInfo snapshot = shouldInstallSnapshot();
           if (snapshot != null) {
             installSnapshot(snapshot);
-            shouldAppendLog = false;
+            installSnapshotRequired = true;
           }
         } else {
           TermIndex installSnapshotNotificationTermIndex = 
shouldNotifyToInstallSnapshot();
           if (installSnapshotNotificationTermIndex != null) {
             installSnapshot(installSnapshotNotificationTermIndex);
-            shouldAppendLog = false;
+            installSnapshotRequired = true;
           }
         }
-        if (shouldHeartbeat() || (shouldAppendLog && !shouldWait())) {
-          // keep appending log entries or sending heartbeats
-          appendLog();
-        }
+
+        appendLog(installSnapshotRequired || haveTooManyPendingRequests());
+
       }
       checkSlowness();
+
     }
 
     
Optional.ofNullable(appendLogRequestObserver).ifPresent(StreamObserver::onCompleted);
   }
 
   private long getWaitTimeMs() {
-    if (!shouldSendRequest()) {
-      return getHeartbeatRemainingTime(); // No requests, wait until heartbeat
-    } else if (shouldWait()) {
-      return getHalfMinTimeoutMs(); // Should wait for a short time
+    if (haveTooManyPendingRequests()) {
+      return getHeartbeatRemainingTime(); // Should wait for a short time
+    } else if (haveLogEntriesToSendOut() || heartbeatTimeout()) {
+      return 0L;
     }
-    return 0L;
+    return Math.min(10L, getHeartbeatRemainingTime());

Review comment:
       `getHeartbeatRemainingTime()` can be a longer time, for example in Ozone 
it's 2.5 seconds. With using 10L (or less) the thread itself will check the 
other conditions in the `runAppenderImpl` loop. 
   
   As there is no easy way to notify the waiting thread in case of watch for 
commit requests, the thread is waking up at every 10ms and checks if the HB 
should be sent out or not.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to