ChenSammi commented on code in PR #561:
URL: https://github.com/apache/ratis/pull/561#discussion_r922933983


##########
ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcLogAppender.java:
##########
@@ -212,33 +225,50 @@ private void appendLog(boolean excludeLogEntries) throws 
IOException {
       pendingRequests.put(request);
       increaseNextIndex(pending);
       if (appendLogRequestObserver == null) {
-        appendLogRequestObserver = getClient().appendEntries(new 
AppendLogResponseHandler());
+        appendLogRequestObserver =
+            getClient().appendEntries(appendLogResponseHandler, false);
+      }
+
+      if (heartbeatRequestObserver == null && useSeparateHBChannel) {
+        heartbeatRequestObserver =
+            getClient().appendEntries(appendLogResponseHandler, true);
       }
-      s = appendLogRequestObserver;
     }
 
     if (isRunning()) {
-      sendRequest(request, pending, s);
+      sendRequest(request, pending);
     }
   }
 
-  private void sendRequest(AppendEntriesRequest request, 
AppendEntriesRequestProto proto,
-        StreamObserver<AppendEntriesRequestProto> s) {
+  private void sendRequest(AppendEntriesRequest request, 
AppendEntriesRequestProto proto) {
     CodeInjectionForTesting.execute(GrpcService.GRPC_SEND_SERVER_REQUEST,
         getServer().getId(), null, proto);
     request.startRequestTimer();
-    s.onNext(proto);
-    scheduler.onTimeout(requestTimeoutDuration,
-        () -> timeoutAppendRequest(request.getCallId(), request.isHeartbeat()),
-        LOG, () -> "Timeout check failed for append entry request: " + 
request);
-    getFollower().updateLastRpcSendTime(request.isHeartbeat());
+    boolean sent = false;
+    if (request.isHeartbeat() && useSeparateHBChannel) {
+      // NPE throw out when observer is closed in resetClient
+      Optional.ofNullable(heartbeatRequestObserver).ifPresent(observer -> 
observer.onNext(proto));
+      sent = true;
+    } else {
+      Optional.ofNullable(appendLogRequestObserver).ifPresent(observer -> 
observer.onNext(proto));
+      sent = true;
+    }
+    if (sent) {

Review Comment:
   Good catch. This logic is not as expected. 



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

Reply via email to