hachikuji commented on a change in pull request #10909:
URL: https://github.com/apache/kafka/pull/10909#discussion_r680147135



##########
File path: raft/src/main/java/org/apache/kafka/raft/KafkaRaftClient.java
##########
@@ -2248,24 +2250,23 @@ public void poll() {
     }
 
     @Override
-    public Long scheduleAppend(int epoch, List<T> records) {
+    public long scheduleAppend(int epoch, List<T> records) {
         return append(epoch, records, false);
     }
 
     @Override
-    public Long scheduleAtomicAppend(int epoch, List<T> records) {
+    public long scheduleAtomicAppend(int epoch, List<T> records) {
         return append(epoch, records, true);
     }
 
-    private Long append(int epoch, List<T> records, boolean isAtomic) {
-        Optional<LeaderState<T>> leaderStateOpt = quorum.maybeLeaderState();
-        if (!leaderStateOpt.isPresent()) {
-            return Long.MAX_VALUE;
-        }
+    private long append(int epoch, List<T> records, boolean isAtomic) {
+        LeaderState<T> leaderState = quorum.<T>maybeLeaderState().orElseThrow(
+            () -> new NotLeaderException("Append failed because the 
replication is not the current leader")

Review comment:
       I think it would be nice if we could consolidate `NotLeaderException` 
and `FencedEpochException`. In the context of `scheduleAppend`, they mean the 
same thing to the caller. They both say that the raft state has transitioned 
and the operation is no longer possible. I'm inclined to keep 
`NotLeaderException` and document that it covers both cases. What do you think?
   

##########
File path: core/src/main/scala/kafka/tools/TestRaftServer.scala
##########
@@ -193,10 +193,13 @@ class TestRaftServer(
       currentTimeMs: Long
     ): Unit = {
       recordCount.incrementAndGet()
-
-      raftManager.scheduleAppend(leaderEpoch, Seq(payload)) match {
-        case Some(offset) => pendingAppends.offer(PendingAppend(offset, 
currentTimeMs))
-        case None => time.sleep(10)
+      try {
+        val offset = raftManager.client.scheduleAppend(leaderEpoch, 
List(payload).asJava)
+        pendingAppends.offer(PendingAppend(offset, currentTimeMs))
+      } catch {
+        case e: Exception =>
+          logger.warn("Appending failed, transition to resigned", e)

Review comment:
       How about this instead?
   ```scala
   case e: FencedEpochException =>
     logger.debug(s"Append failed because of the node is no longer leader in 
epoch $leaderEpoch", e)
     time.sleep(10)
   ```
   For every other exception type, we can let it propagate.




-- 
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: jira-unsubscr...@kafka.apache.org

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


Reply via email to