This is an automated email from the ASF dual-hosted git repository.

rpuch pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new c71e0536fc4 IGNITE-25087 Do not log 'Not leader' as ERROR on leader 
miss (#5601)
c71e0536fc4 is described below

commit c71e0536fc49710b94861ebca0dd14a326ed4b66
Author: Roman Puchkovskiy <roman.puchkovs...@gmail.com>
AuthorDate: Fri Jun 13 14:23:32 2025 +0400

    IGNITE-25087 Do not log 'Not leader' as ERROR on leader miss (#5601)
---
 .../apache/ignite/raft/jraft/core/NodeImpl.java    |  8 +++----
 .../ignite/raft/jraft/core/NotLeaderException.java | 28 ++++++++++++++++++++++
 .../ignite/raft/jraft/rpc/RpcRequestProcessor.java | 12 +++++++++-
 3 files changed, 43 insertions(+), 5 deletions(-)

diff --git 
a/modules/raft/src/main/java/org/apache/ignite/raft/jraft/core/NodeImpl.java 
b/modules/raft/src/main/java/org/apache/ignite/raft/jraft/core/NodeImpl.java
index 5668cac6cbc..819c6840e4d 100644
--- a/modules/raft/src/main/java/org/apache/ignite/raft/jraft/core/NodeImpl.java
+++ b/modules/raft/src/main/java/org/apache/ignite/raft/jraft/core/NodeImpl.java
@@ -3377,7 +3377,7 @@ public class NodeImpl implements Node, RaftServerService {
         this.readLock.lock();
         try {
             if (this.state != State.STATE_LEADER) {
-                throw new IllegalStateException("Not leader");
+                throw new NotLeaderException();
             }
             return this.conf.getConf().listPeers();
         }
@@ -3391,7 +3391,7 @@ public class NodeImpl implements Node, RaftServerService {
         this.readLock.lock();
         try {
             if (this.state != State.STATE_LEADER) {
-                throw new IllegalStateException("Not leader");
+                throw new NotLeaderException();
             }
             return getAliveNodes(this.conf.getConf().getPeers(), 
Utils.monotonicMs());
         }
@@ -3405,7 +3405,7 @@ public class NodeImpl implements Node, RaftServerService {
         this.readLock.lock();
         try {
             if (this.state != State.STATE_LEADER) {
-                throw new IllegalStateException("Not leader");
+                throw new NotLeaderException();
             }
             return this.conf.getConf().listLearners();
         }
@@ -3419,7 +3419,7 @@ public class NodeImpl implements Node, RaftServerService {
         this.readLock.lock();
         try {
             if (this.state != State.STATE_LEADER) {
-                throw new IllegalStateException("Not leader");
+                throw new NotLeaderException();
             }
             return getAliveNodes(this.conf.getConf().getLearners(), 
Utils.monotonicMs());
         }
diff --git 
a/modules/raft/src/main/java/org/apache/ignite/raft/jraft/core/NotLeaderException.java
 
b/modules/raft/src/main/java/org/apache/ignite/raft/jraft/core/NotLeaderException.java
new file mode 100644
index 00000000000..86db9818d31
--- /dev/null
+++ 
b/modules/raft/src/main/java/org/apache/ignite/raft/jraft/core/NotLeaderException.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.raft.jraft.core;
+
+/**
+ * Thrown when a Raft node is asked to perform an action that is only allowed 
for a leader, when the node is not a leader.
+ */
+public class NotLeaderException extends IllegalStateException {
+    private static final long serialVersionUID = 0L;
+
+    public NotLeaderException() {
+        super("Not leader");
+    }
+}
diff --git 
a/modules/raft/src/main/java/org/apache/ignite/raft/jraft/rpc/RpcRequestProcessor.java
 
b/modules/raft/src/main/java/org/apache/ignite/raft/jraft/rpc/RpcRequestProcessor.java
index 70e83b07cb2..0b91b4d8f9b 100644
--- 
a/modules/raft/src/main/java/org/apache/ignite/raft/jraft/rpc/RpcRequestProcessor.java
+++ 
b/modules/raft/src/main/java/org/apache/ignite/raft/jraft/rpc/RpcRequestProcessor.java
@@ -20,6 +20,7 @@ import java.util.concurrent.Executor;
 import org.apache.ignite.internal.logger.IgniteLogger;
 import org.apache.ignite.internal.logger.Loggers;
 import org.apache.ignite.raft.jraft.RaftMessagesFactory;
+import org.apache.ignite.raft.jraft.core.NotLeaderException;
 
 /**
  * Abstract AsyncUserProcessor for RPC processors.
@@ -53,12 +54,21 @@ public abstract class RpcRequestProcessor<T extends 
Message> implements RpcProce
             }
         }
         catch (final Throwable t) {
-            LOG.error("handleRequest {} failed", t, request);
+            if (isIgnorable(t)) {
+                LOG.debug("handleRequest {} failed", t, request);
+            } else {
+                LOG.error("handleRequest {} failed", t, request);
+            }
             rpcCtx.sendResponse(RaftRpcFactory.DEFAULT //
                 .newResponse(msgFactory, -1, "handleRequest internal error"));
         }
     }
 
+    private static boolean isIgnorable(Throwable t) {
+        // It is ok if we lost leadership while a request to us was in flight, 
there is no need to clutter up the log.
+        return t instanceof NotLeaderException;
+    }
+
     @Override
     public Executor executor() {
         return this.executor;

Reply via email to