diff --git a/ratis-client/src/main/java/org/apache/ratis/client/api/AdminApi.java b/ratis-client/src/main/java/org/apache/ratis/client/api/AdminApi.java index e27c8ae867..8ce6a5eb1b 100644 --- a/ratis-client/src/main/java/org/apache/ratis/client/api/AdminApi.java +++ b/ratis-client/src/main/java/org/apache/ratis/client/api/AdminApi.java @@ -68,7 +68,7 @@ default RaftClientReply setConfiguration(RaftPeer[] serversInNewConf, RaftPeer[] /** Transfer leadership to the given server.*/ default RaftClientReply transferLeadership(RaftPeerId newLeader, long timeoutMs) throws IOException { return transferLeadership(newLeader, null, timeoutMs); - }; + } RaftClientReply transferLeadership(RaftPeerId newLeader, RaftPeerId leaderId, long timeoutMs) throws IOException; } \ No newline at end of file diff --git a/ratis-client/src/main/java/org/apache/ratis/client/impl/OrderedStreamAsync.java b/ratis-client/src/main/java/org/apache/ratis/client/impl/OrderedStreamAsync.java index 3847adf03b..989c00cbbc 100644 --- a/ratis-client/src/main/java/org/apache/ratis/client/impl/OrderedStreamAsync.java +++ b/ratis-client/src/main/java/org/apache/ratis/client/impl/OrderedStreamAsync.java @@ -112,6 +112,7 @@ CompletableFuture sendRequest(DataStreamRequestHeader header, O try { requestSemaphore.acquire(); } catch (InterruptedException e){ + Thread.currentThread().interrupt(); return JavaUtils.completeExceptionally(IOUtils.toInterruptedIOException( "Interrupted when sending " + JavaUtils.getClassSimpleName(data.getClass()) + ", header= " + header, e)); } diff --git a/ratis-client/src/main/java/org/apache/ratis/client/impl/RaftClientImpl.java b/ratis-client/src/main/java/org/apache/ratis/client/impl/RaftClientImpl.java index 579c2f56bf..e85e0ded9d 100644 --- a/ratis-client/src/main/java/org/apache/ratis/client/impl/RaftClientImpl.java +++ b/ratis-client/src/main/java/org/apache/ratis/client/impl/RaftClientImpl.java @@ -350,7 +350,7 @@ RaftClientReply handleNotLeaderException(RaftClientRequest request, NotLeaderExc } private void refreshPeers(Collection newPeers) { - if (newPeers != null && newPeers.size() > 0) { + if (newPeers != null && !newPeers.isEmpty()) { peers.set(newPeers); // also refresh the rpc proxies for these peers clientRpc.addRaftPeers(newPeers); diff --git a/ratis-common/src/main/java/org/apache/ratis/conf/ReconfigurationBase.java b/ratis-common/src/main/java/org/apache/ratis/conf/ReconfigurationBase.java index ea6ba225e4..6d4930e676 100644 --- a/ratis-common/src/main/java/org/apache/ratis/conf/ReconfigurationBase.java +++ b/ratis-common/src/main/java/org/apache/ratis/conf/ReconfigurationBase.java @@ -114,7 +114,7 @@ synchronized Daemon stop() { * Construct a ReconfigurableBase with the {@link RaftProperties} * @param properties raft properties. */ - public ReconfigurationBase(String name, RaftProperties properties) { + protected ReconfigurationBase(String name, RaftProperties properties) { this.name = name; this.properties = properties; this.context = new Context(); diff --git a/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamPacketImpl.java b/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamPacketImpl.java index 6be0300645..41e3a5e12b 100644 --- a/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamPacketImpl.java +++ b/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamPacketImpl.java @@ -33,7 +33,7 @@ public abstract class DataStreamPacketImpl implements DataStreamPacket { private final long streamId; private final long streamOffset; - public DataStreamPacketImpl(ClientId clientId, Type type, long streamId, long streamOffset) { + protected DataStreamPacketImpl(ClientId clientId, Type type, long streamId, long streamOffset) { this.clientId = clientId; this.type = type; this.streamId = streamId; diff --git a/ratis-common/src/main/java/org/apache/ratis/util/JvmPauseMonitor.java b/ratis-common/src/main/java/org/apache/ratis/util/JvmPauseMonitor.java index 2e84c11227..86038e697c 100644 --- a/ratis-common/src/main/java/org/apache/ratis/util/JvmPauseMonitor.java +++ b/ratis-common/src/main/java/org/apache/ratis/util/JvmPauseMonitor.java @@ -159,6 +159,7 @@ private void detectPause() { try { extraSleep = sleepTime.sleep(); } catch (InterruptedException ie) { + Thread.currentThread().interrupt(); return; } diff --git a/ratis-grpc/src/main/java/org/apache/ratis/grpc/metrics/intercept/server/MetricServerCallListener.java b/ratis-grpc/src/main/java/org/apache/ratis/grpc/metrics/intercept/server/MetricServerCallListener.java index 104f9883a0..77ae4c8f35 100644 --- a/ratis-grpc/src/main/java/org/apache/ratis/grpc/metrics/intercept/server/MetricServerCallListener.java +++ b/ratis-grpc/src/main/java/org/apache/ratis/grpc/metrics/intercept/server/MetricServerCallListener.java @@ -30,7 +30,6 @@ public class MetricServerCallListener extends ForwardingServerCallListener MetricServerCallListener( ServerCall.Listener delegate, - String metricNamePrefix, MessageMetrics metrics ){ this.delegate = delegate; diff --git a/ratis-grpc/src/main/java/org/apache/ratis/grpc/metrics/intercept/server/MetricServerInterceptor.java b/ratis-grpc/src/main/java/org/apache/ratis/grpc/metrics/intercept/server/MetricServerInterceptor.java index a11d5ca160..7e20946add 100644 --- a/ratis-grpc/src/main/java/org/apache/ratis/grpc/metrics/intercept/server/MetricServerInterceptor.java +++ b/ratis-grpc/src/main/java/org/apache/ratis/grpc/metrics/intercept/server/MetricServerInterceptor.java @@ -76,7 +76,7 @@ public ServerCall.Listener interceptCall( String metricNamePrefix = getMethodMetricPrefix(method); ServerCall monitoringCall = new MetricServerCall<>(call, metricNamePrefix, metrics); return new MetricServerCallListener<>( - next.startCall(monitoringCall, requestHeaders), metricNamePrefix, metrics); + next.startCall(monitoringCall, requestHeaders), metrics); } @Override diff --git a/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolClient.java b/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolClient.java index 2eb73f6aa0..e4a8549d39 100644 --- a/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolClient.java +++ b/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolClient.java @@ -102,7 +102,6 @@ private ManagedChannel buildChannel(RaftPeer target, int flowControlWindow, @Override public void close() { LOG.info("{} Close channels", raftPeerId); - CompletableFuture future1; if (useSeparateHBChannel) { GrpcUtil.shutdownManagedChannel(hbChannel); } diff --git a/ratis-netty/src/main/java/org/apache/ratis/netty/server/NettyServerStreamRpc.java b/ratis-netty/src/main/java/org/apache/ratis/netty/server/NettyServerStreamRpc.java index 2c53560535..b0acf2580e 100644 --- a/ratis-netty/src/main/java/org/apache/ratis/netty/server/NettyServerStreamRpc.java +++ b/ratis-netty/src/main/java/org/apache/ratis/netty/server/NettyServerStreamRpc.java @@ -310,6 +310,7 @@ public void close() { ConcurrentUtils.shutdownAndWait(TimeDuration.ONE_SECOND, workerGroup, timeout -> LOG.warn("{}: workerGroup shutdown timeout in " + timeout, this)); } catch (InterruptedException e) { + Thread.currentThread().interrupt(); LOG.error(this + ": Interrupted close()", e); } diff --git a/ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderElection.java b/ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderElection.java index dedc56cfc3..302f848719 100644 --- a/ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderElection.java +++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderElection.java @@ -249,6 +249,9 @@ public void run() { } } } catch(Exception e) { + if (e instanceof InterruptedException) { + Thread.currentThread().interrupt(); + } final LifeCycle.State state = lifeCycle.getCurrentState(); if (state.isClosingOrClosed()) { LOG.info("{}: {} is safely ignored since this is already {}", @@ -426,7 +429,7 @@ private ResultAndTerm waitForResults(Phase phase, long electionTerm, int submitt if (r.getServerReply().getSuccess()) { votedPeers.add(replierId); // If majority and all peers with higher priority have voted, candidate pass vote - if (higherPriorityPeers.size() == 0 && conf.hasMajority(votedPeers, server.getId())) { + if (higherPriorityPeers.isEmpty() && conf.hasMajority(votedPeers, server.getId())) { return logAndReturn(phase, Result.PASSED, responses, exceptions); } } else { diff --git a/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java b/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java index 315d610551..07c0e6c4a2 100644 --- a/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java +++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java @@ -415,6 +415,9 @@ void close() { getStateMachineUpdater().stopAndJoin(); } } catch (Throwable e) { + if (e instanceof InterruptedException) { + Thread.currentThread().interrupt(); + } LOG.warn(getMemberId() + ": Failed to join " + getStateMachineUpdater(), e); } LOG.info("{}: applyIndex: {}", getMemberId(), getLastAppliedIndex()); diff --git a/ratis-server/src/main/java/org/apache/ratis/server/impl/SnapshotManagementRequestHandler.java b/ratis-server/src/main/java/org/apache/ratis/server/impl/SnapshotManagementRequestHandler.java index b899752e07..8632242b18 100644 --- a/ratis-server/src/main/java/org/apache/ratis/server/impl/SnapshotManagementRequestHandler.java +++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/SnapshotManagementRequestHandler.java @@ -35,7 +35,7 @@ import java.util.function.Supplier; class SnapshotManagementRequestHandler { - public static final Logger LOG = LoggerFactory.getLogger(TransferLeadership.class); + public static final Logger LOG = LoggerFactory.getLogger(SnapshotManagementRequestHandler.class); class PendingRequest { private final SnapshotManagementRequest request; diff --git a/ratis-server/src/main/java/org/apache/ratis/server/metrics/SegmentedRaftLogMetrics.java b/ratis-server/src/main/java/org/apache/ratis/server/metrics/SegmentedRaftLogMetrics.java index e591473e8a..228258f300 100644 --- a/ratis-server/src/main/java/org/apache/ratis/server/metrics/SegmentedRaftLogMetrics.java +++ b/ratis-server/src/main/java/org/apache/ratis/server/metrics/SegmentedRaftLogMetrics.java @@ -187,6 +187,7 @@ public UncheckedAutoCloseable startPurgeTimer() { return Timekeeper.start(purgeTimer); } + @Override public void onStateMachineDataWriteTimeout() { numStateMachineDataWriteTimeout.inc(); } diff --git a/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/CacheInvalidationPolicy.java b/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/CacheInvalidationPolicy.java index b8e57092fb..baae8e2ee6 100644 --- a/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/CacheInvalidationPolicy.java +++ b/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/CacheInvalidationPolicy.java @@ -50,13 +50,13 @@ public List evict(long[] followerNextIndices, long safeEvictIndex, long lastAppliedIndex, LogSegmentList segments, final int maxCachedSegments) { try(AutoCloseableLock readLock = segments.readLock()) { - return evictImpl(followerNextIndices, safeEvictIndex, lastAppliedIndex, segments, maxCachedSegments); + return evictImpl(followerNextIndices, safeEvictIndex, lastAppliedIndex, segments); } } private List evictImpl(long[] followerNextIndices, long safeEvictIndex, long lastAppliedIndex, - LogSegmentList segments, final int maxCachedSegments) { + LogSegmentList segments) { List result = new ArrayList<>(); int safeIndex = segments.size() - 1; for (; safeIndex >= 0; safeIndex--) { diff --git a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/AbstractShell.java b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/AbstractShell.java index 139dd26e10..e2679045e5 100644 --- a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/AbstractShell.java +++ b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/AbstractShell.java @@ -43,7 +43,7 @@ public abstract class AbstractShell implements Closeable { /** * Creates a new instance of {@link AbstractShell}. */ - public AbstractShell(Context context) { + protected AbstractShell(Context context) { closer = Closer.create(); mCommands = loadCommands(context); // Register all loaded commands under closer. diff --git a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/AbstractParentCommand.java b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/AbstractParentCommand.java index ec8401f4f7..7293c5bf1e 100644 --- a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/AbstractParentCommand.java +++ b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/AbstractParentCommand.java @@ -29,7 +29,7 @@ public abstract class AbstractParentCommand implements Command { private final Map subs; - public AbstractParentCommand(Context context, List> subCommandConstructors) { + protected AbstractParentCommand(Context context, List> subCommandConstructors) { this.subs = Collections.unmodifiableMap(subCommandConstructors.stream() .map(constructor -> constructor.apply(context)) .collect(Collectors.toMap(Command::getCommandName, Function.identity(), diff --git a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/election/StepDownCommand.java b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/election/StepDownCommand.java index 50abfe37cd..02976ed347 100644 --- a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/election/StepDownCommand.java +++ b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/election/StepDownCommand.java @@ -73,11 +73,6 @@ public String getDescription() { return description(); } - @Override - public Options getOptions() { - return super.getOptions(); - } - /** * @return command's description */