This is an automated email from the ASF dual-hosted git repository.
nizhikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 99b88b98fb4 IGNITE-27379 Fix tx support init in partitionAwareness
mode (#12587)
99b88b98fb4 is described below
commit 99b88b98fb475ddebd7b43b91514710905982837
Author: Nikolay <[email protected]>
AuthorDate: Thu Dec 18 12:12:00 2025 +0300
IGNITE-27379 Fix tx support init in partitionAwareness mode (#12587)
---
.../jdbc/JdbcThinTransactionalSelfTest.java | 66 +++++++++----
.../internal/jdbc/thin/JdbcThinConnection.java | 102 +++++++++++----------
2 files changed, 103 insertions(+), 65 deletions(-)
diff --git
a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/jdbc/JdbcThinTransactionalSelfTest.java
b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/jdbc/JdbcThinTransactionalSelfTest.java
index 1a583c760db..7120f15e2e0 100644
---
a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/jdbc/JdbcThinTransactionalSelfTest.java
+++
b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/jdbc/JdbcThinTransactionalSelfTest.java
@@ -34,6 +34,8 @@ import
org.apache.ignite.testframework.junits.IgniteConfigVariationsAbstractTest
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.apache.ignite.transactions.TransactionConcurrency;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
import static java.sql.Connection.TRANSACTION_NONE;
import static java.sql.Connection.TRANSACTION_READ_COMMITTED;
@@ -47,9 +49,20 @@ import static java.sql.ResultSet.TYPE_FORWARD_ONLY;
import static org.apache.ignite.testframework.GridTestUtils.assertThrows;
/** */
+@RunWith(Parameterized.class)
public class JdbcThinTransactionalSelfTest extends GridCommonAbstractTest {
+ /** */
+ @Parameterized.Parameter
+ public boolean partitionAwareness;
+
+ /** */
+ @Parameterized.Parameters(name = "partitionAwareness={0}")
+ public static Object[] parameters() {
+ return new Object[] {false, true};
+ }
+
/** URL. */
- public static final String URL = "jdbc:ignite:thin://127.0.0.1";
+ public static final String URL = "jdbc:ignite:thin://127.0.0.1?";
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String
igniteInstanceName) throws Exception {
@@ -71,7 +84,7 @@ public class JdbcThinTransactionalSelfTest extends
GridCommonAbstractTest {
/** */
@Test
public void testDatabaseMetadata() throws Exception {
- try (Connection conn = DriverManager.getConnection(URL)) {
+ try (Connection conn = DriverManager.getConnection(url())) {
DatabaseMetaData meta = conn.getMetaData();
assertTrue(meta.supportsTransactions());
@@ -89,7 +102,7 @@ public class JdbcThinTransactionalSelfTest extends
GridCommonAbstractTest {
/** */
@Test
public void testInvalidHoldability() throws Exception {
- try (Connection conn = DriverManager.getConnection(URL)) {
+ try (Connection conn = DriverManager.getConnection(url())) {
List<TestRunnable> checks = Arrays.asList(
() -> conn.setHoldability(HOLD_CURSORS_OVER_COMMIT),
() -> conn.createStatement(TYPE_FORWARD_ONLY,
CONCUR_READ_ONLY, HOLD_CURSORS_OVER_COMMIT),
@@ -116,7 +129,7 @@ public class JdbcThinTransactionalSelfTest extends
GridCommonAbstractTest {
@Test
public void testTransactionConcurrencyProperty() throws Exception {
for (TransactionConcurrency txConcurrency :
TransactionConcurrency.values()) {
- String url = URL + "?transactionConcurrency=" + txConcurrency;
+ String url = url("transactionConcurrency=" + txConcurrency);
try (Connection conn = DriverManager.getConnection(url)) {
conn.setAutoCommit(false);
@@ -132,7 +145,7 @@ public class JdbcThinTransactionalSelfTest extends
GridCommonAbstractTest {
/** */
@Test
public void testTransactionIsolation() throws Exception {
- try (Connection conn = DriverManager.getConnection(URL)) {
+ try (Connection conn = DriverManager.getConnection(url())) {
assertEquals(TRANSACTION_READ_COMMITTED,
conn.getTransactionIsolation());
conn.setTransactionIsolation(TRANSACTION_NONE);
@@ -156,7 +169,7 @@ public class JdbcThinTransactionalSelfTest extends
GridCommonAbstractTest {
/** */
@Test
public void testChangeStreamInsideTransactionThrows() throws Exception {
- try (Connection conn = DriverManager.getConnection(URL)) {
+ try (Connection conn = DriverManager.getConnection(url())) {
conn.setAutoCommit(false);
conn.prepareStatement("SELECT 1").executeQuery();
@@ -176,7 +189,7 @@ public class JdbcThinTransactionalSelfTest extends
GridCommonAbstractTest {
/** */
@Test
public void testNoTxInNoTxIsolation() throws Exception {
- try (Connection conn = DriverManager.getConnection(URL)) {
+ try (Connection conn = DriverManager.getConnection(url())) {
conn.setTransactionIsolation(TRANSACTION_NONE);
conn.prepareStatement("SELECT 1").executeQuery();
@@ -188,9 +201,7 @@ public class JdbcThinTransactionalSelfTest extends
GridCommonAbstractTest {
/** */
@Test
public void testTransactionLabel() throws Exception {
- String url = URL + "?transactionLabel=mylabel";
-
- try (Connection conn = DriverManager.getConnection(url)) {
+ try (Connection conn =
DriverManager.getConnection(url("transactionLabel=mylabel"))) {
conn.setAutoCommit(false);
try (ResultSet rs = conn.prepareStatement("SELECT
1").executeQuery()) {
@@ -205,9 +216,7 @@ public class JdbcThinTransactionalSelfTest extends
GridCommonAbstractTest {
public void testTransactionTimeout() throws Exception {
int timeout = 1000;
- String url = URL + "?transactionTimeout=" + timeout;
-
- try (Connection conn = DriverManager.getConnection(url)) {
+ try (Connection conn =
DriverManager.getConnection(url("transactionTimeout=" + timeout))) {
conn.setAutoCommit(false);
ResultSet rs = conn.prepareStatement("SELECT 1").executeQuery();
@@ -232,7 +241,7 @@ public class JdbcThinTransactionalSelfTest extends
GridCommonAbstractTest {
public void testStatementsClosedOnTxEnd() throws Exception {
for (boolean commit : new boolean[]{true, false}) {
- try (Connection conn = DriverManager.getConnection(URL)) {
+ try (Connection conn = DriverManager.getConnection(url())) {
conn.setAutoCommit(false);
PreparedStatement stmt0 = conn.prepareStatement("SELECT 1");
@@ -273,7 +282,7 @@ public class JdbcThinTransactionalSelfTest extends
GridCommonAbstractTest {
ResultSet rs0;
ResultSet rs1;
- try (Connection conn = DriverManager.getConnection(URL)) {
+ try (Connection conn = DriverManager.getConnection(url())) {
conn.setAutoCommit(false);
stmt0 = conn.prepareStatement("SELECT 1");
@@ -297,7 +306,7 @@ public class JdbcThinTransactionalSelfTest extends
GridCommonAbstractTest {
/** */
@Test
public void testCreateStatementOnDefaults() throws Exception {
- try (Connection conn = DriverManager.getConnection(URL)) {
+ try (Connection conn = DriverManager.getConnection(url())) {
conn.setAutoCommit(false);
try (Statement stmt = conn.createStatement()) {
@@ -314,4 +323,29 @@ public class JdbcThinTransactionalSelfTest extends
GridCommonAbstractTest {
}
}
+
+ /** */
+ private String url(String...params) {
+ String url = URL;
+
+ boolean first = true;
+
+ if (partitionAwareness) {
+ url += "partitionAwareness=true";
+ first = false;
+ }
+
+ if (!F.isEmpty(params)) {
+ for (String param : params) {
+ if (first) {
+ url += param;
+ first = false;
+ }
+ else
+ url += "&" + param;
+ }
+ }
+
+ return url;
+ }
}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinConnection.java
b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinConnection.java
index ac5314a9772..be6b1eb5fb5 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinConnection.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinConnection.java
@@ -1985,74 +1985,78 @@ public class JdbcThinConnection implements Connection {
*/
private IgniteProductVersion connectInBestEffortAffinityMode(
IgniteProductVersion baseEndpointVer) throws SQLException {
- List<Exception> exceptions = null;
+ try {
+ List<Exception> exceptions = null;
- for (int i = 0; i < connProps.getAddresses().length; i++) {
- HostAndPortRange srv = connProps.getAddresses()[i];
+ for (int i = 0; i < connProps.getAddresses().length; i++) {
+ HostAndPortRange srv = connProps.getAddresses()[i];
- try {
- InetAddress[] addrs = InetAddress.getAllByName(srv.host());
+ try {
+ InetAddress[] addrs = InetAddress.getAllByName(srv.host());
- for (InetAddress addr : addrs) {
- for (int port = srv.portFrom(); port <= srv.portTo();
++port) {
- try {
- JdbcThinTcpIo cliIo =
- new JdbcThinTcpIo(connProps, new
InetSocketAddress(addr, port), ctx, 0);
+ for (InetAddress addr : addrs) {
+ for (int port = srv.portFrom(); port <= srv.portTo();
++port) {
+ try {
+ JdbcThinTcpIo cliIo =
+ new JdbcThinTcpIo(connProps, new
InetSocketAddress(addr, port), ctx, 0);
- if (!cliIo.isPartitionAwarenessSupported()) {
- cliIo.close();
+ if (!cliIo.isPartitionAwarenessSupported()) {
+ cliIo.close();
- throw new SQLException("Failed to connect to
Ignite node [url=" +
- connProps.getUrl() + "]. address = [" +
addr + ':' + port + "]." +
- "Node doesn't support partition awareness
mode.",
- INTERNAL_ERROR);
- }
+ throw new SQLException("Failed to connect
to Ignite node [url=" +
+ connProps.getUrl() + "]. address = ["
+ addr + ':' + port + "]." +
+ "Node doesn't support partition
awareness mode.",
+ INTERNAL_ERROR);
+ }
- IgniteProductVersion endpointVer =
cliIo.igniteVersion();
+ IgniteProductVersion endpointVer =
cliIo.igniteVersion();
- if (baseEndpointVer != null &&
baseEndpointVer.compareTo(endpointVer) > 0) {
- cliIo.close();
+ if (baseEndpointVer != null &&
baseEndpointVer.compareTo(endpointVer) > 0) {
+ cliIo.close();
- throw new SQLException("Failed to connect to
Ignite node [url=" +
- connProps.getUrl() + "], address = [" +
addr + ':' + port + "]," +
- "the node version [" + endpointVer + "] " +
- "is smaller than the base one [" +
baseEndpointVer + "].",
- INTERNAL_ERROR);
- }
+ throw new SQLException("Failed to connect
to Ignite node [url=" +
+ connProps.getUrl() + "], address = ["
+ addr + ':' + port + "]," +
+ "the node version [" + endpointVer +
"] " +
+ "is smaller than the base one [" +
baseEndpointVer + "].",
+ INTERNAL_ERROR);
+ }
- cliIo.timeout(netTimeout);
+ cliIo.timeout(netTimeout);
- JdbcThinTcpIo ioToSameNode =
ios.putIfAbsent(cliIo.nodeId(), cliIo);
+ JdbcThinTcpIo ioToSameNode =
ios.putIfAbsent(cliIo.nodeId(), cliIo);
- // This can happen if the same node has several
IPs or if connection manager background
- // timer task runs concurrently.
- if (ioToSameNode != null)
- cliIo.close();
- else
- connCnt.incrementAndGet();
+ // This can happen if the same node has
several IPs or if connection manager background
+ // timer task runs concurrently.
+ if (ioToSameNode != null)
+ cliIo.close();
+ else
+ connCnt.incrementAndGet();
- return cliIo.igniteVersion();
- }
- catch (Exception exception) {
- if (exceptions == null)
- exceptions = new ArrayList<>();
+ return cliIo.igniteVersion();
+ }
+ catch (Exception exception) {
+ if (exceptions == null)
+ exceptions = new ArrayList<>();
- exceptions.add(exception);
+ exceptions.add(exception);
+ }
}
}
}
- }
- catch (Exception exception) {
- if (exceptions == null)
- exceptions = new ArrayList<>();
+ catch (Exception exception) {
+ if (exceptions == null)
+ exceptions = new ArrayList<>();
- exceptions.add(exception);
+ exceptions.add(exception);
+ }
}
- }
-
- handleConnectExceptions(exceptions);
- isTxAwareQueriesSupported = defaultIo().isTxAwareQueriesSupported();
+ handleConnectExceptions(exceptions);
+ }
+ finally {
+ if (!ios.isEmpty())
+ isTxAwareQueriesSupported =
defaultIo().isTxAwareQueriesSupported();
+ }
return null;
}