diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/ProxyDatabaseConnectionManager.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/ProxyDatabaseConnectionManager.java index 9ff69eb0ccd18..c82dd4c01abc2 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/ProxyDatabaseConnectionManager.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/ProxyDatabaseConnectionManager.java @@ -28,7 +28,7 @@ import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader; import org.apache.shardingsphere.proxy.backend.connector.jdbc.connection.ConnectionPostProcessor; -import org.apache.shardingsphere.proxy.backend.connector.jdbc.connection.ResourceLock; +import org.apache.shardingsphere.proxy.backend.connector.jdbc.connection.ConnectionResourceLock; import org.apache.shardingsphere.proxy.backend.connector.jdbc.transaction.BackendTransactionManager; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.exception.BackendConnectionException; @@ -67,7 +67,7 @@ public final class ProxyDatabaseConnectionManager implements DatabaseConnectionM private final Collection connectionPostProcessors = new LinkedList<>(); - private final ResourceLock resourceLock = new ResourceLock(); + private final ConnectionResourceLock connectionResourceLock = new ConnectionResourceLock(); private final AtomicBoolean closed = new AtomicBoolean(false); diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/connection/ResourceLock.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/connection/ConnectionResourceLock.java similarity index 96% rename from proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/connection/ResourceLock.java rename to proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/connection/ConnectionResourceLock.java index 2eaf8c17ffb25..6a8a04312e014 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/connection/ResourceLock.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/connection/ConnectionResourceLock.java @@ -26,9 +26,9 @@ import java.util.concurrent.locks.ReentrantLock; /** - * Resource lock. + * Connection resource lock. */ -public final class ResourceLock { +public final class ConnectionResourceLock { private static final long DEFAULT_TIMEOUT_MILLISECONDS = 200L; diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/connection/ResourceLockTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/connection/ConnectionResourceLockTest.java similarity index 84% rename from proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/connection/ResourceLockTest.java rename to proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/connection/ConnectionResourceLockTest.java index 7d3ac0719146e..fae1d2924ae04 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/connection/ResourceLockTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/connection/ConnectionResourceLockTest.java @@ -40,7 +40,7 @@ @ExtendWith(AutoMockExtension.class) @MockitoSettings(strictness = Strictness.LENIENT) -class ResourceLockTest { +class ConnectionResourceLockTest { @Mock private ChannelHandlerContext channelHandlerContext; @@ -49,7 +49,7 @@ class ResourceLockTest { private Channel channel; @Mock - private ResourceLock resourceLock; + private ConnectionResourceLock connectionResourceLock; @Test void assertDoAwait() throws NoSuchFieldException, IllegalAccessException { @@ -57,10 +57,10 @@ void assertDoAwait() throws NoSuchFieldException, IllegalAccessException { when(channel.isActive()).thenReturn(true); when(channelHandlerContext.channel()).thenReturn(channel); ExecutorService executorService = Executors.newFixedThreadPool(1); - executorService.submit(() -> resourceLock.doAwait(channelHandlerContext)); + executorService.submit(() -> connectionResourceLock.doAwait(channelHandlerContext)); Awaitility.await().pollDelay(200L, TimeUnit.MILLISECONDS).until(() -> true); - Plugins.getMemberAccessor().set(ResourceLock.class.getDeclaredField("condition"), resourceLock, new ReentrantLock().newCondition()); - verify(resourceLock, times(1)).doAwait(channelHandlerContext); + Plugins.getMemberAccessor().set(ConnectionResourceLock.class.getDeclaredField("condition"), connectionResourceLock, new ReentrantLock().newCondition()); + verify(connectionResourceLock, times(1)).doAwait(channelHandlerContext); } @Test @@ -72,9 +72,9 @@ void assertDoNotify() { ExecutorService executorService = Executors.newFixedThreadPool(1); executorService.submit(() -> { Awaitility.await().pollDelay(50L, TimeUnit.MILLISECONDS).until(() -> true); - resourceLock.doNotify(); + connectionResourceLock.doNotify(); }); - resourceLock.doAwait(channelHandlerContext); + connectionResourceLock.doAwait(channelHandlerContext); assertTrue(System.currentTimeMillis() >= startTime); } } diff --git a/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java b/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java index fcfb4300252dd..d3ea1b3a4b0d5 100644 --- a/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java +++ b/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java @@ -113,7 +113,7 @@ private void closeAllResources() { @Override public void channelWritabilityChanged(final ChannelHandlerContext context) { if (context.channel().isWritable()) { - connectionSession.getDatabaseConnectionManager().getResourceLock().doNotify(); + connectionSession.getDatabaseConnectionManager().getConnectionResourceLock().doNotify(); } } } diff --git a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecuteEngine.java b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecuteEngine.java index 2782618fb8199..6d508b7447791 100644 --- a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecuteEngine.java +++ b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecuteEngine.java @@ -74,7 +74,7 @@ public void writeQueryData(final ChannelHandlerContext context, int flushThreshold = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getProps().getValue(ConfigurationPropertyKey.PROXY_FRONTEND_FLUSH_THRESHOLD); while (queryCommandExecutor.next()) { count++; - databaseConnectionManager.getResourceLock().doAwait(context); + databaseConnectionManager.getConnectionResourceLock().doAwait(context); DatabasePacket dataValue = queryCommandExecutor.getQueryRowPacket(); context.write(dataValue); if (flushThreshold == count) { diff --git a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngine.java b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngine.java index 3ac5579faee7a..bb086836d66e7 100644 --- a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngine.java +++ b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngine.java @@ -108,7 +108,7 @@ private long writeDataPackets(final ChannelHandlerContext context, final ProxyDa .getContextManager().getMetaDataContexts().getMetaData().getProps().getValue(ConfigurationPropertyKey.PROXY_FRONTEND_FLUSH_THRESHOLD); while (queryCommandExecutor.next()) { flushCount++; - databaseConnectionManager.getResourceLock().doAwait(context); + databaseConnectionManager.getConnectionResourceLock().doAwait(context); DatabasePacket resultValue = queryCommandExecutor.getQueryRowPacket(); context.write(resultValue); if (proxyFrontendFlushThreshold == flushCount) { diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngineTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngineTest.java index 0d7481105e735..7171cbedbca94 100644 --- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngineTest.java +++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngineTest.java @@ -30,7 +30,7 @@ import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; import org.apache.shardingsphere.mode.spi.PersistRepository; import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager; -import org.apache.shardingsphere.proxy.backend.connector.jdbc.connection.ResourceLock; +import org.apache.shardingsphere.proxy.backend.connector.jdbc.connection.ConnectionResourceLock; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.session.ConnectionSession; import org.apache.shardingsphere.proxy.backend.session.transaction.TransactionStatus; @@ -114,9 +114,9 @@ void assertWriteQueryDataWithHasNextResult() throws SQLException { when(channel.isActive()).thenReturn(true); when(queryCommandExecutor.next()).thenReturn(true, false); when(channel.isWritable()).thenReturn(false, true); - ResourceLock resourceLock = mock(ResourceLock.class); + ConnectionResourceLock connectionResourceLock = mock(ConnectionResourceLock.class); ProxyDatabaseConnectionManager databaseConnectionManager = mock(ProxyDatabaseConnectionManager.class); - when(databaseConnectionManager.getResourceLock()).thenReturn(resourceLock); + when(databaseConnectionManager.getConnectionResourceLock()).thenReturn(connectionResourceLock); when(databaseConnectionManager.getConnectionSession()).thenReturn(connectionSession); PostgreSQLPacket packet = mock(PostgreSQLPacket.class); when(queryCommandExecutor.getQueryRowPacket()).thenReturn(packet); @@ -127,7 +127,7 @@ void assertWriteQueryDataWithHasNextResult() throws SQLException { new ShardingSphereMetaData()), computeNodeInstanceContext, mock(PersistRepository.class)); when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager); commandExecuteEngine.writeQueryData(channelHandlerContext, databaseConnectionManager, queryCommandExecutor, 0); - verify(resourceLock).doAwait(channelHandlerContext); + verify(connectionResourceLock).doAwait(channelHandlerContext); verify(channelHandlerContext).write(packet); verify(channelHandlerContext).write(isA(PostgreSQLCommandCompletePacket.class)); verify(channelHandlerContext).write(isA(PostgreSQLReadyForQueryPacket.class));