You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "vldpyatkov (via GitHub)" <gi...@apache.org> on 2023/06/28 08:20:24 UTC

[GitHub] [ignite-3] vldpyatkov commented on a diff in pull request #2255: IGNITE-19120 Raft client should get leader metadata along while getting leader itself

vldpyatkov commented on code in PR #2255:
URL: https://github.com/apache/ignite-3/pull/2255#discussion_r1244861785


##########
modules/raft/src/main/java/org/apache/ignite/raft/jraft/core/NodeImpl.java:
##########
@@ -1739,6 +1742,53 @@ public void handleReadIndexRequest(final ReadIndexRequest request,
         }
     }
 
+    @Override
+    public void handleReadLeaderIndexRequest(
+            ReadLeaderMetadataRequest request,
+            RpcResponseClosure<ReadLeaderMetadataResponse> done
+    ) {
+        long startMs = Utils.monotonicMs();
+
+        this.readLock.lock();
+
+        try {
+            switch (this.state) {
+                case STATE_LEADER:
+                    readLeader(
+                            null,
+                            new RpcResponseClosureAdapter<>() {
+                                @Override
+                                public void run(Status status) {
+                                    if (getResponse() != null) {
+                                        done.setResponse(raftOptions.getRaftMessagesFactory().readLeaderMetadataResponse()
+                                                .leaderId(leaderId.toString())
+                                                .currentTerm(currTerm)
+                                                .index(getResponse().index())
+                                                .build());
+                                    }
+
+                                    done.run(status);
+                                }
+                            }
+                    );
+                    break;
+
+                case STATE_TRANSFERRING:
+                    done.run(new Status(RaftError.EBUSY, "Is transferring leadership."));
+                    break;
+
+                default:
+                    done.run(new Status(RaftError.EPERM, "Invalid state for readIndex: %s.", this.state));
+                    break;
+            }
+        }
+        finally {
+            this.readLock.unlock();
+            this.metrics.recordLatency("handle-read-index", Utils.monotonicMs() - startMs);

Review Comment:
   What's your proposal?



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org