Skip to content

Commit

Permalink
fix sonar lint complains
Browse files Browse the repository at this point in the history
  • Loading branch information
SzyWilliam committed Oct 14, 2023
1 parent 4c8ef9d commit 44600c4
Show file tree
Hide file tree
Showing 18 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ CompletableFuture<DataStreamReply> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ RaftClientReply handleNotLeaderException(RaftClientRequest request, NotLeaderExc
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ private void detectPause() {
try {
extraSleep = sleepTime.sleep();
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class MetricServerCallListener<R> extends ForwardingServerCallListener<R>

MetricServerCallListener(
ServerCall.Listener<R> delegate,
String metricNamePrefix,
MessageMetrics metrics
){
this.delegate = delegate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public <R, S> ServerCall.Listener<R> interceptCall(
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ private ManagedChannel buildChannel(RaftPeer target, int flowControlWindow,
@Override
public void close() {
LOG.info("{} Close channels", raftPeerId);
CompletableFuture<Void> future1;
if (useSeparateHBChannel) {
GrpcUtil.shutdownManagedChannel(hbChannel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}",
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public UncheckedAutoCloseable startPurgeTimer() {
return Timekeeper.start(purgeTimer);
}

@Override
public void onStateMachineDataWriteTimeout() {
numStateMachineDataWriteTimeout.inc();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ public List<LogSegment> 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<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--) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ public String getDescription() {
return description();
}

@Override
public Options getOptions() {
return super.getOptions();
}

/**
* @return command's description
*/
Expand Down

0 comments on commit 44600c4

Please sign in to comment.