Skip to content

Commit 4093c19

Browse files
committed
chore: remove unused log
1 parent f7992cf commit 4093c19

File tree

3 files changed

+50
-57
lines changed

3 files changed

+50
-57
lines changed

src/main/java/io/lettuce/core/ContextualChannel.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.lettuce.core;
22

3+
import java.net.SocketAddress;
4+
35
import io.lettuce.core.context.ConnectionContext;
46
import io.netty.buffer.ByteBufAllocator;
57
import io.netty.channel.Channel;
@@ -15,8 +17,6 @@
1517
import io.netty.util.AttributeKey;
1618
import org.jetbrains.annotations.NotNull;
1719

18-
import java.net.SocketAddress;
19-
2020
/**
2121
* @author chenxiaofan
2222
*/
@@ -30,6 +30,10 @@ public ConnectionContext getContext() {
3030
return context;
3131
}
3232

33+
public ConnectionContext.State getInitialState() {
34+
return context.getInitialState();
35+
}
36+
3337
public Channel getDelegate() {
3438
return delegate;
3539
}

src/main/java/io/lettuce/core/context/BatchFlushEndPointContext.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public boolean tryEnterSafeGetVolatile() {
4545
return safe.get() == 0 && /* rare case if QPS is high */ safe.compareAndSet(0, 1);
4646
}
4747

48+
public void exitSafe() {
49+
safe.set(0);
50+
}
51+
4852
/**
4953
* This method is not thread safe, can only be used from single thread.
5054
*
@@ -58,10 +62,6 @@ public boolean tryEnterUnsafe() {
5862
return true;
5963
}
6064

61-
public void exitSafe() {
62-
safe.set(0);
63-
}
64-
6565
public void exitUnsafe() {
6666
unsafe = false;
6767
}

src/main/java/io/lettuce/core/protocol/DefaultBatchFlushEndpoint.java

Lines changed: 40 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ protected static void cancelCommandOnEndpointClose(RedisCommand<?, ?, ?> cmd) {
112112
cmd.cancel();
113113
}
114114

115-
protected volatile @Nonnull ContextualChannel channel = DummyContextualChannelInstances.CHANNEL_CONNECTING;
116-
117115
private final Reliability reliability;
118116

119117
private final ClientOptions clientOptions;
@@ -123,12 +121,13 @@ protected static void cancelCommandOnEndpointClose(RedisCommand<?, ?, ?> cmd) {
123121
private final boolean boundedQueues;
124122

125123
// access via QUEUE_SIZE
126-
@SuppressWarnings("unused")
127124
private volatile int queueSize = 0;
128125

129126
// access via STATUS
130-
@SuppressWarnings("unused")
131127
private volatile int status = ST_OPEN;
128+
// access via CHANNEL
129+
130+
protected volatile @Nonnull ContextualChannel channel = DummyContextualChannelInstances.CHANNEL_CONNECTING;
132131

133132
private final Consumer<RedisCommand<?, ?, ?>> callbackOnClose;
134133

@@ -152,10 +151,6 @@ protected static void cancelCommandOnEndpointClose(RedisCommand<?, ?, ?> cmd) {
152151

153152
private volatile Throwable connectionError;
154153

155-
// // access via QUEUE_SIZE
156-
// @SuppressWarnings("unused")
157-
// private volatile int queueSize = 0;
158-
159154
private final String cachedEndpointId;
160155

161156
protected final UnboundedMpscOfferFirstQueue<RedisCommand<?, ?, ?>> taskQueue;
@@ -308,11 +303,8 @@ public void notifyChannelActive(Channel channel) {
308303
this.connectionError = null;
309304

310305
if (!CHANNEL.compareAndSet(this, DummyContextualChannelInstances.CHANNEL_CONNECTING, contextualChannel)) {
311-
logger.error("[unexpected] {} failed to set to CHANNEL_CONNECTING because current state is '{}'", logPrefix(),
312-
CHANNEL.get(this));
313306
channel.close();
314-
onUnexpectedState("notifyChannelActive", ConnectionContext.State.CONNECTING,
315-
this.channel.getContext().getInitialState());
307+
onUnexpectedState("notifyChannelActive", ConnectionContext.State.CONNECTING);
316308
return;
317309
}
318310

@@ -357,21 +349,13 @@ public void notifyChannelActive(Channel channel) {
357349
}
358350
}
359351

360-
private void onUnexpectedState(String caller, ConnectionContext.State exp, ConnectionContext.State actual) {
361-
logger.error("[{}][unexpected] {}: unexpected state: exp '{}' got '{}'", caller, logPrefix(), exp, actual);
362-
cancelCommands(String.format("%s: state not match: expect '%s', got '%s'", caller, exp, actual));
363-
}
364-
365352
@Override
366353
public void notifyReconnectFailed(Throwable t) {
367354
this.failedToReconnectReason = t;
368355

369356
if (!CHANNEL.compareAndSet(this, DummyContextualChannelInstances.CHANNEL_CONNECTING,
370357
DummyContextualChannelInstances.CHANNEL_RECONNECT_FAILED)) {
371-
logger.error("[unexpected] {} failed to set to CHANNEL_CONNECTING because current state is '{}'", logPrefix(),
372-
CHANNEL.get(this));
373-
onUnexpectedState("notifyReconnectFailed", ConnectionContext.State.CONNECTING,
374-
this.channel.getContext().getInitialState());
358+
onUnexpectedState("notifyReconnectFailed", ConnectionContext.State.CONNECTING);
375359
return;
376360
}
377361

@@ -396,13 +380,13 @@ public void notifyChannelInactive(Channel channel) {
396380
@Override
397381
public void notifyChannelInactiveAfterWatchdogDecision(Channel channel,
398382
Deque<RedisCommand<?, ?, ?>> retryableQueuedCommands) {
399-
final ContextualChannel prevChan = this.channel;
400-
if (!prevChan.getContext().getInitialState().isConnected() || prevChan.getDelegate() != channel) {
383+
final ContextualChannel inactiveChan = this.channel;
384+
if (!inactiveChan.getInitialState().isConnected() || inactiveChan.getDelegate() != channel) {
401385
logger.error("[unexpected][{}] notifyChannelInactive: channel not match", logPrefix());
402386
return;
403387
}
404388

405-
if (prevChan.getContext().isChannelInactiveEventFired()) {
389+
if (inactiveChan.getContext().isChannelInactiveEventFired()) {
406390
logger.error("[unexpected][{}] notifyChannelInactive: already fired", logPrefix());
407391
return;
408392
}
@@ -431,9 +415,9 @@ public void notifyChannelInactiveAfterWatchdogDecision(Channel channel,
431415
if (!willReconnect) {
432416
CHANNEL.set(this, DummyContextualChannelInstances.CHANNEL_ENDPOINT_CLOSED);
433417
}
434-
prevChan.getContext()
418+
inactiveChan.getContext()
435419
.setCloseStatus(new ConnectionContext.CloseStatus(willReconnect, retryableQueuedCommands, exception));
436-
trySetEndpointQuiescence(prevChan);
420+
trySetEndpointQuiescence(inactiveChan);
437421
}
438422

439423
@Override
@@ -444,7 +428,7 @@ public void notifyException(Throwable t) {
444428
}
445429

446430
final ContextualChannel curr = this.channel;
447-
if (!curr.getContext().getInitialState().isConnected() || !curr.isActive()) {
431+
if (!curr.getInitialState().isConnected() || !curr.isActive()) {
448432
connectionError = t;
449433
}
450434
}
@@ -457,7 +441,7 @@ public void registerConnectionWatchdog(ConnectionWatchdog connectionWatchdog) {
457441
@Override
458442
public void flushCommands() {
459443
final ContextualChannel chan = this.channel;
460-
switch (chan.getContext().getInitialState()) {
444+
switch (chan.getInitialState()) {
461445
case ENDPOINT_CLOSED:
462446
syncAfterTerminated(() -> {
463447
if (isClosed()) {
@@ -486,7 +470,7 @@ public void flushCommands() {
486470
scheduleSendJobIfNeeded(chan);
487471
return;
488472
default:
489-
throw new IllegalStateException("unexpected state: " + chan.getContext().getInitialState());
473+
throw new IllegalStateException("unexpected state: " + chan.getInitialState());
490474
}
491475
}
492476

@@ -519,8 +503,8 @@ public CompletableFuture<Void> closeAsync() {
519503
connectionWatchdog.prepareClose();
520504
}
521505

522-
final Channel chan = channel;
523-
if (channel.getContext().getInitialState().isConnected()) {
506+
final ContextualChannel chan = channel;
507+
if (chan.getInitialState().isConnected()) {
524508
// 1. STATUS.compareAndSet(this, ST_OPEN, ST_CLOSED) synchronize-before channel == CONNECTED
525509
// 2. channel == CONNECTED synchronize-before setting channel to WILL_RECONNECT/ENDPOINT_CLOSED
526510
// 3. setting channel to WILL_RECONNECT synchronize-before `isClosed()`, which will cancel all the commands.
@@ -545,7 +529,7 @@ public void disconnect() {
545529

546530
ContextualChannel chan = this.channel;
547531

548-
if (chan.getContext().getInitialState().isConnected() && chan.isOpen()) {
532+
if (chan.getInitialState().isConnected() && chan.isOpen()) {
549533
chan.disconnect();
550534
}
551535
}
@@ -561,9 +545,9 @@ public void reset() {
561545
logger.debug("{} reset()", logPrefix());
562546
}
563547

564-
final ContextualChannel curr = channel;
565-
if (curr.getContext().getInitialState().isConnected()) {
566-
curr.pipeline().fireUserEventTriggered(new ConnectionEvents.Reset());
548+
final ContextualChannel chan = channel;
549+
if (chan.getInitialState().isConnected()) {
550+
chan.pipeline().fireUserEventTriggered(new ConnectionEvents.Reset());
567551
}
568552
// Unsafe to call cancelBufferedCommands() here.
569553
// cancelBufferedCommands("Reset");
@@ -575,9 +559,9 @@ private void resetInternal() {
575559
logger.debug("{} reset()", logPrefix());
576560
}
577561

578-
ContextualChannel curr = channel;
579-
if (curr.getContext().getInitialState().isConnected()) {
580-
curr.pipeline().fireUserEventTriggered(new ConnectionEvents.Reset());
562+
ContextualChannel chan = channel;
563+
if (chan.getInitialState().isConnected()) {
564+
chan.pipeline().fireUserEventTriggered(new ConnectionEvents.Reset());
581565
}
582566
// Unsafe to call cancelBufferedCommands() here.
583567
cancelCommands("Reset");
@@ -593,7 +577,7 @@ public void initialState() {
593577
cancelCommands("initialState");
594578

595579
ContextualChannel currentChannel = this.channel;
596-
if (currentChannel.getContext().getInitialState().isConnected()) {
580+
if (currentChannel.getInitialState().isConnected()) {
597581
ChannelFuture close = currentChannel.close();
598582
if (currentChannel.isOpen()) {
599583
close.syncUninterruptibly();
@@ -602,7 +586,7 @@ public void initialState() {
602586
}
603587

604588
private boolean isClosed() {
605-
return STATUS.get(this) == ST_CLOSED;
589+
return status == ST_CLOSED;
606590
}
607591

608592
protected String logPrefix() {
@@ -799,16 +783,14 @@ private void trySetEndpointQuiescence(ContextualChannel chan) {
799783
}
800784

801785
private void onEndpointQuiescence() {
802-
if (channel.getContext().getInitialState() == ConnectionContext.State.ENDPOINT_CLOSED) {
786+
if (channel.getInitialState() == ConnectionContext.State.ENDPOINT_CLOSED) {
803787
return;
804788
}
805789

806790
// Create happens-before with channelActive()
807791
if (!CHANNEL.compareAndSet(this, DummyContextualChannelInstances.CHANNEL_WILL_RECONNECT,
808792
DummyContextualChannelInstances.CHANNEL_CONNECTING)) {
809-
810-
onUnexpectedState("onEndpointQuiescence", ConnectionContext.State.WILL_RECONNECT,
811-
this.channel.getContext().getInitialState());
793+
onUnexpectedState("onEndpointQuiescence", ConnectionContext.State.WILL_RECONNECT);
812794
return;
813795
}
814796

@@ -824,17 +806,18 @@ private void onWillReconnect(@Nonnull final ConnectionContext.CloseStatus closeS
824806
// Save retryable failed tasks
825807
logger.info(
826808
"[onWillReconnect][{}] compensate {} retryableFailedToSendTasks (write failure) for retrying on reconnecting, first write error: {}",
827-
retryableFailedToSendTasks.size(), batchFlushEndPointContext.getFirstDiscontinueReason().getMessage(),
828-
logPrefix());
809+
logPrefix(), retryableFailedToSendTasks.size(),
810+
batchFlushEndPointContext.getFirstDiscontinueReason().getMessage());
829811
offerFirstAll(retryableFailedToSendTasks);
830812
}
831813

832814
LettuceAssert.assertState(reliability != Reliability.AT_MOST_ONCE, "unexpected: reliability is AT_MOST_ONCE");
833815
final Deque<RedisCommand<?, ?, ?>> retryablePendingCommands = closeStatus.getAndClearRetryablePendingCommands();
834816
if (retryablePendingCommands != null) {
835817
// Save uncompletedTasks for later retry.
836-
logger.info("[onWillReconnect][{}] compensate {} pendingCommands (write success) for retrying on reconnecting",
837-
retryablePendingCommands.size(), logPrefix());
818+
logger.info(
819+
"[onWillReconnect][{}] compensate {} retryable pending commands (write success) for retrying on reconnecting",
820+
logPrefix(), retryablePendingCommands.size());
838821
offerFirstAll(retryablePendingCommands);
839822
}
840823

@@ -961,13 +944,13 @@ private Throwable validateWrite(@SuppressWarnings("unused") int commands) {
961944
return localConnectionErr;
962945
}
963946

964-
if (boundedQueues && QUEUE_SIZE.get(this) + commands > clientOptions.getRequestQueueSize()) {
947+
if (boundedQueues && queueSize + commands > clientOptions.getRequestQueueSize()) {
965948
return new RedisException("Request queue size exceeded: " + clientOptions.getRequestQueueSize()
966949
+ ". Commands are not accepted until the queue size drops.");
967950
}
968951

969952
final ContextualChannel chan = this.channel;
970-
switch (chan.getContext().getInitialState()) {
953+
switch (chan.getInitialState()) {
971954
case ENDPOINT_CLOSED:
972955
return new RedisException("Connection is closed");
973956
case RECONNECT_FAILED:
@@ -979,10 +962,16 @@ private Throwable validateWrite(@SuppressWarnings("unused") int commands) {
979962
case CONNECTED:
980963
return !chan.isActive() && rejectCommandsWhileDisconnected ? new RedisException("Connection is closed") : null;
981964
default:
982-
throw new IllegalStateException("unexpected state: " + chan.getContext().getInitialState());
965+
throw new IllegalStateException("unexpected state: " + chan.getInitialState());
983966
}
984967
}
985968

969+
private void onUnexpectedState(String caller, ConnectionContext.State exp) {
970+
final ConnectionContext.State actual = this.channel.getInitialState();
971+
logger.error("[{}][unexpected] {}: unexpected state: exp '{}' got '{}'", caller, logPrefix(), exp, actual);
972+
cancelCommands(String.format("%s: state not match: expect '%s', got '%s'", caller, exp, actual));
973+
}
974+
986975
private void channelFlush(Channel channel) {
987976
if (debugEnabled) {
988977
logger.debug("{} write() channelFlush", logPrefix());

0 commit comments

Comments
 (0)