Skip to content

Commit 544786d

Browse files
authored
IGNITE-22971 Reduce log pollution by RaftGroupServiceImpl (#4214)
1 parent 513d54d commit 544786d

File tree

4 files changed

+45
-12
lines changed

4 files changed

+45
-12
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.internal.raft;
19+
20+
/**
21+
* Special type of exception used when a target peer is not present in the physical topology.
22+
*
23+
* <p>The stacktrace is omitted on purpose as to reduce log pollution (this exception is thrown and logged nearly immediately).
24+
*/
25+
public class PeerUnavailableException extends RuntimeException {
26+
public PeerUnavailableException(String consistentId) {
27+
super("Peer " + consistentId + " is unavailable", null, true, false);
28+
}
29+
}

modules/raft/src/main/java/org/apache/ignite/internal/raft/RaftGroupServiceImpl.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static java.util.concurrent.ThreadLocalRandom.current;
2222
import static java.util.stream.Collectors.toList;
2323
import static org.apache.ignite.internal.tostring.IgniteToStringBuilder.includeSensitive;
24+
import static org.apache.ignite.internal.util.ExceptionUtils.unwrapCause;
2425
import static org.apache.ignite.lang.ErrorGroups.Common.INTERNAL_ERR;
2526
import static org.apache.ignite.raft.jraft.rpc.CliRequests.AddLearnersRequest;
2627
import static org.apache.ignite.raft.jraft.rpc.CliRequests.AddPeerRequest;
@@ -41,13 +42,11 @@
4142
import static org.apache.ignite.raft.jraft.rpc.CliRequests.TransferLeaderRequest;
4243

4344
import java.io.IOException;
44-
import java.net.ConnectException;
4545
import java.util.ArrayList;
4646
import java.util.Collection;
4747
import java.util.List;
4848
import java.util.concurrent.CompletableFuture;
4949
import java.util.concurrent.CompletionException;
50-
import java.util.concurrent.ExecutionException;
5150
import java.util.concurrent.ScheduledExecutorService;
5251
import java.util.concurrent.ThreadLocalRandom;
5352
import java.util.concurrent.TimeUnit;
@@ -598,6 +597,8 @@ private void handleThrowable(
598597
long stopTime,
599598
CompletableFuture<? extends NetworkMessage> fut
600599
) {
600+
err = unwrapCause(err);
601+
601602
if (recoverable(err)) {
602603
Peer randomPeer = randomNode(peer);
603604

@@ -707,17 +708,18 @@ private void scheduleRetry(Runnable runnable) {
707708
}
708709

709710
/**
710-
* Checks if an error is recoverable, for example, {@link java.net.ConnectException}.
711+
* Checks if an error is recoverable.
712+
*
713+
* <p>An error is considered recoverable if it's an instance of {@link TimeoutException}, {@link IOException}
714+
* or {@link PeerUnavailableException}.
711715
*
712716
* @param t The throwable.
713717
* @return {@code True} if this is a recoverable exception.
714718
*/
715719
private static boolean recoverable(Throwable t) {
716-
if (t instanceof ExecutionException || t instanceof CompletionException) {
717-
t = t.getCause();
718-
}
720+
t = unwrapCause(t);
719721

720-
return t instanceof TimeoutException || t instanceof IOException;
722+
return t instanceof TimeoutException || t instanceof IOException || t instanceof PeerUnavailableException;
721723
}
722724

723725
private Peer randomNode() {
@@ -811,7 +813,7 @@ private CompletableFuture<ClusterNode> resolvePeer(Peer peer) {
811813
ClusterNode node = cluster.topologyService().getByConsistentId(peer.consistentId());
812814

813815
if (node == null) {
814-
return CompletableFuture.failedFuture(new ConnectException("Peer " + peer.consistentId() + " is unavailable"));
816+
return CompletableFuture.failedFuture(new PeerUnavailableException(peer.consistentId()));
815817
}
816818

817819
return CompletableFuture.completedFuture(node);

modules/raft/src/main/java/org/apache/ignite/raft/jraft/rpc/impl/AbstractClientService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.concurrent.ExecutorService;
2727
import org.apache.ignite.internal.logger.IgniteLogger;
2828
import org.apache.ignite.internal.logger.Loggers;
29+
import org.apache.ignite.internal.raft.PeerUnavailableException;
2930
import org.apache.ignite.network.ClusterNode;
3031
import org.apache.ignite.internal.network.TopologyEventHandler;
3132
import org.apache.ignite.raft.jraft.Status;
@@ -59,7 +60,7 @@ public abstract class AbstractClientService implements ClientService, TopologyEv
5960
/**
6061
* The set of pinged consistent IDs.
6162
*/
62-
protected Set<String> readyConsistentIds = new ConcurrentHashSet<>();
63+
private final Set<String> readyConsistentIds = new ConcurrentHashSet<>();
6364

6465
public RpcClient getRpcClient() {
6566
return this.rpcClient;
@@ -224,7 +225,7 @@ public void complete(final Object result, final Throwable err) {
224225
}
225226
}
226227
else {
227-
if (ThrowUtil.hasCause(err, null, ConnectException.class))
228+
if (ThrowUtil.hasCause(err, null, PeerUnavailableException.class, ConnectException.class))
228229
readyConsistentIds.remove(peerId.getConsistentId()); // Force logical reconnect.
229230

230231
if (done != null) {

modules/raft/src/main/java/org/apache/ignite/raft/jraft/rpc/impl/IgniteRpcClient.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.function.BiPredicate;
2828
import org.apache.ignite.internal.logger.IgniteLogger;
2929
import org.apache.ignite.internal.logger.Loggers;
30+
import org.apache.ignite.internal.raft.PeerUnavailableException;
3031
import org.apache.ignite.internal.tostring.S;
3132
import org.apache.ignite.network.ClusterNode;
3233
import org.apache.ignite.internal.network.ClusterService;
@@ -135,8 +136,8 @@ public void send(PeerId peerId, Object request, CompletableFuture<Message> fut,
135136
ClusterNode targetNode = service.topologyService().getByConsistentId(peerId.getConsistentId());
136137

137138
if (targetNode == null) {
138-
// ConnectException will force a retry by the enclosing components.
139-
fut.completeExceptionally(new ConnectException());
139+
// PeerUnavailableException will force a retry by the enclosing components.
140+
fut.completeExceptionally(new PeerUnavailableException(peerId.getConsistentId()));
140141

141142
return;
142143
}

0 commit comments

Comments
 (0)