This is an automated email from the ASF dual-hosted git repository.
szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git
The following commit(s) were added to refs/heads/master by this push:
new 121a081fb RATIS-1905. Fix some sonar lint complains (#936)
121a081fb is described below
commit 121a081fb506748acc6244ee83e128cc6cad2ad9
Author: William Song <[email protected]>
AuthorDate: Tue Oct 17 10:29:18 2023 -0500
RATIS-1905. Fix some sonar lint complains (#936)
---
.../src/main/java/org/apache/ratis/client/api/AdminApi.java | 2 +-
.../main/java/org/apache/ratis/client/impl/OrderedStreamAsync.java | 1 +
.../src/main/java/org/apache/ratis/client/impl/RaftClientImpl.java | 2 +-
.../src/main/java/org/apache/ratis/conf/ReconfigurationBase.java | 2 +-
.../java/org/apache/ratis/datastream/impl/DataStreamPacketImpl.java | 2 +-
.../src/main/java/org/apache/ratis/util/JvmPauseMonitor.java | 1 +
.../grpc/metrics/intercept/server/MetricServerCallListener.java | 1 -
.../grpc/metrics/intercept/server/MetricServerInterceptor.java | 2 +-
.../java/org/apache/ratis/grpc/server/GrpcServerProtocolClient.java | 2 --
.../java/org/apache/ratis/netty/server/NettyServerStreamRpc.java | 1 +
.../src/main/java/org/apache/ratis/server/impl/LeaderElection.java | 5 ++++-
.../src/main/java/org/apache/ratis/server/impl/ServerState.java | 3 +++
.../apache/ratis/server/impl/SnapshotManagementRequestHandler.java | 2 +-
.../org/apache/ratis/server/metrics/SegmentedRaftLogMetrics.java | 1 +
.../ratis/server/raftlog/segmented/CacheInvalidationPolicy.java | 4 ++--
.../src/main/java/org/apache/ratis/shell/cli/AbstractShell.java | 2 +-
.../apache/ratis/shell/cli/sh/command/AbstractParentCommand.java | 2 +-
.../org/apache/ratis/shell/cli/sh/election/StepDownCommand.java | 6 ------
18 files changed, 21 insertions(+), 20 deletions(-)
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 e27c8ae86..8ce6a5eb1 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 @@ public interface AdminApi {
/** 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 3847adf03..989c00cbb 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 @@ public class OrderedStreamAsync {
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 e11490570..9847beed7 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 @@ public final class RaftClientImpl implements RaftClient {
}
private void refreshPeers(Collection<RaftPeer> 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 ea6ba225e..6d4930e67 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 @@ public abstract class ReconfigurationBase implements
Reconfigurable {
* 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 6be030064..41e3a5e12 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 2e84c1122..86038e697 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 @@ public final class JvmPauseMonitor {
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 104f9883a..77ae4c8f3 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<R> extends
ForwardingServerCallListener<R>
MetricServerCallListener(
ServerCall.Listener<R> 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 a11d5ca16..7e20946ad 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 class MetricServerInterceptor implements
ServerInterceptor, Closeable {
String metricNamePrefix = getMethodMetricPrefix(method);
ServerCall<R,S> 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 2eb73f6aa..392864535 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
@@ -39,7 +39,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.Closeable;
-import java.util.concurrent.CompletableFuture;
/**
* This is a RaftClient implementation that supports streaming data to the raft
@@ -102,7 +101,6 @@ public class GrpcServerProtocolClient implements Closeable {
@Override
public void close() {
LOG.info("{} Close channels", raftPeerId);
- CompletableFuture<Void> 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 2c5356053..b0acf2580 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 class NettyServerStreamRpc implements
DataStreamServerRpc {
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 dedc56cfc..302f84871 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 @@ class LeaderElection implements Runnable {
}
}
} 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 @@ class LeaderElection implements Runnable {
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 315d61055..07c0e6c4a 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 @@ class ServerState {
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 b899752e0..8632242b1 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.concurrent.atomic.AtomicReference;
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 e591473e8..228258f30 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 class SegmentedRaftLogMetrics extends
RaftLogMetricsBase {
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 b8e57092f..baae8e2ee 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 interface CacheInvalidationPolicy {
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<LogSegment> evictImpl(long[] followerNextIndices,
long safeEvictIndex, long lastAppliedIndex,
- LogSegmentList segments, final int maxCachedSegments) {
+ LogSegmentList segments) {
List<LogSegment> 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 139dd26e1..e2679045e 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 ec8401f4f..7293c5bf1 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 @@ import java.util.stream.Collectors;
public abstract class AbstractParentCommand implements Command {
private final Map<String, Command> subs;
- public AbstractParentCommand(Context context, List<Function<Context,
Command>> subCommandConstructors) {
+ protected AbstractParentCommand(Context context, List<Function<Context,
Command>> 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 50abfe37c..911a2bb26 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
@@ -18,7 +18,6 @@
package org.apache.ratis.shell.cli.sh.election;
import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.Options;
import org.apache.ratis.client.RaftClient;
import org.apache.ratis.protocol.RaftClientReply;
import org.apache.ratis.protocol.RaftPeerId;
@@ -73,11 +72,6 @@ public class StepDownCommand extends AbstractRatisCommand {
return description();
}
- @Override
- public Options getOptions() {
- return super.getOptions();
- }
-
/**
* @return command's description
*/