amaliujia commented on code in PR #1679:
URL: https://github.com/apache/ratis/pull/1679#discussion_r4468607984


##########
ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcLogAppender.java:
##########
@@ -357,7 +360,13 @@ private void sleepForErrors() throws InterruptedException {
   @Override
   public CompletableFuture<LifeCycle.State> stopAsync() {
     grpcServerMetrics.unregister();
-    return super.stopAsync();
+    return super.stopAsync().whenComplete((state, e) -> {
+      // when CLOSED, no more appendEntries for this group to the follower; 
otherwise, a restarted appender takes over
+      final GrpcServerProtocolClient client = appendEntriesClient;
+      if (state == LifeCycle.State.CLOSED && client != null) {
+        
client.releaseAppendEntriesIndex(getServer().getMemberId().getGroupId());

Review Comment:
   When I thought about round-bin style assignment, I didn't think about this 
far to have a channel usage counter stuff and introduce this much of code. I 
was only expecting simple changes which could have improvements with least 
cost. 
   
   If we introduce the count and releaseAppendEntriesIndex, I find there could 
be other places involved as well. For example, a failed appender would be 
restarted, then for a complete solution we might need to call 
releaseAppendEntriesIndex there as well. Then the complexity starts to grow.\
   Can we just use a simple index to indicate the next slot:
   
   `final int i = Math.floorMod(nextAppendEntriesIndex.getAndIncrement(), 
appendEntriesStubs.size());`
   
   Then we can drop the map, the counts, releaseAppendEntriesIndex and the 
stopAsync hook. The spread isn't perfect after groups come and go, but it's no 
worse than hashing, and it keeps the change small.
   
   if you find the simple next slot index does not help, we can also go back to 
the simple hashing solution.  
   
   



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