From d9d37d31728e64c5673afa4d46170d6a05a085db Mon Sep 17 00:00:00 2001 From: sanpwc Date: Fri, 29 Mar 2019 12:29:46 +0300 Subject: [PATCH 1/8] ignite-11309 added ability to enable/disable best effort affinity --- .../jdbc/thin/ConnectionProperties.java | 13 +++++++++++++ .../jdbc/thin/ConnectionPropertiesImpl.java | 19 ++++++++++++++++++- .../jdbc/thin/JdbcThinConnection.java | 6 +++--- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionProperties.java b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionProperties.java index d59e9793ebc7e..a4f7eb7da5218 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionProperties.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionProperties.java @@ -405,4 +405,17 @@ public interface ConnectionProperties { * if {@code false} then it's disabled, if {@code null} then server should use its default settings. */ public void setDataPageScanEnabled(@Nullable Boolean dataPageScanEnabled); + + /** + * @return {@code True} if jdbc thin best effort affinity is enabled for this connection, + * {@code false} if it's disabled. + */ + @Nullable public Boolean isJdbcThinBestEffortAffinityEnabled(); + + /** + * @param jdbcThinBestEffortAffinityEnabled {@code True} if jdbc thin best effort affinity is enabled + * for this connection, if {@code false} then it's disabled, if {@code null} then server should use + * its default settings. + */ + public void setJdbcThinBestEffortAffinityEnabled(@Nullable Boolean jdbcThinBestEffortAffinityEnabled); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionPropertiesImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionPropertiesImpl.java index 0a0ff8a4b01dc..3642a257fffa8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionPropertiesImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionPropertiesImpl.java @@ -189,6 +189,12 @@ false, new PropertyValidator() { "Whether data page scan for queries is allowed. If not specified, server defines the default behaviour.", null, false); + /** Best effort affinity flag. */ + private BooleanProperty jdbcThinBestEffortAffinityEnabled = new BooleanProperty( + "jdbcThinBestEffortAffinityEnabled", + "Whether jdbc thin best effort affinity is enabled.", + false, false); + /** Properties array. */ private final ConnectionProperty [] propsArray = { distributedJoins, enforceJoinOrder, collocated, replicatedOnly, autoCloseServerCursor, @@ -198,7 +204,8 @@ false, new PropertyValidator() { sslTrustCertificateKeyStoreUrl, sslTrustCertificateKeyStorePassword, sslTrustCertificateKeyStoreType, sslTrustAll, sslFactory, user, passwd, - dataPageScanEnabled + dataPageScanEnabled, + jdbcThinBestEffortAffinityEnabled }; /** {@inheritDoc} */ @@ -504,6 +511,16 @@ false, new PropertyValidator() { this.dataPageScanEnabled.setValue(dataPageScanEnabled); } + /** {@inheritDoc} */ + @Override public @Nullable Boolean isJdbcThinBestEffortAffinityEnabled() { + return jdbcThinBestEffortAffinityEnabled.value(); + } + + /** {@inheritDoc} */ + @Override public void setJdbcThinBestEffortAffinityEnabled(@Nullable Boolean jdbcThinBestEffortAffinityEnabled) { + this.jdbcThinBestEffortAffinityEnabled.setValue(jdbcThinBestEffortAffinityEnabled); + } + /** * @param url URL connection. * @param props Environment properties. 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 c37c76eebc9c0..06bab833b00c9 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 @@ -120,9 +120,7 @@ public class JdbcThinConnection implements Connection { private static final AtomicLong IDX_GEN = new AtomicLong(); /** Best effort affinity enabled flag. */ - // TODO: 13.02.19 IGNITE-11309 JDBC Thin: add flag or property to disable best effort affinity - @SuppressWarnings("unused") - private static boolean bestEffortAffinity = true; + private final boolean bestEffortAffinity; /** Statements modification mutex. */ private final Object stmtsMux = new Object(); @@ -210,6 +208,8 @@ public JdbcThinConnection(ConnectionProperties connProps) throws SQLException { timer = new Timer("query-timeout-timer"); + bestEffortAffinity = connProps.isJdbcThinBestEffortAffinityEnabled(); + ensureConnected(); } From b55079eb441ca1098637d18e5160e04d1b92db7d Mon Sep 17 00:00:00 2001 From: sanpwc Date: Mon, 1 Apr 2019 10:57:51 +0300 Subject: [PATCH 2/8] ignite-11309 Tests for best effort affinity flag and cleanup. --- ...hinDriverBestEffordAffinityTestSuite.java} | 4 +- .../jdbc/thin/JdbcThinConnectionSelfTest.java | 241 ++++++++++-------- .../jdbc/thin/JdbcThinStatementSelfTest.java | 4 +- .../jdbc/thin/ConnectionProperties.java | 9 +- .../jdbc/thin/ConnectionPropertiesImpl.java | 14 +- .../jdbc/thin/JdbcThinConnection.java | 2 +- 6 files changed, 150 insertions(+), 124 deletions(-) rename modules/clients/src/test/java/org/apache/ignite/jdbc/suite/{IgniteJdbcThinDriverBestEffordAffinitySuite.java => IgniteJdbcThinDriverBestEffordAffinityTestSuite.java} (88%) diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcThinDriverBestEffordAffinitySuite.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcThinDriverBestEffordAffinityTestSuite.java similarity index 88% rename from modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcThinDriverBestEffordAffinitySuite.java rename to modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcThinDriverBestEffordAffinityTestSuite.java index 924dc11bcdafd..ed191f512b8e7 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcThinDriverBestEffordAffinitySuite.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcThinDriverBestEffordAffinityTestSuite.java @@ -17,7 +17,6 @@ package org.apache.ignite.jdbc.suite; -import org.apache.ignite.internal.jdbc.thin.JdbcThinConnection; import org.apache.ignite.jdbc.thin.JdbcThinAbstractSelfTest; import org.apache.ignite.jdbc.thin.JdbcThinConnectionSelfTest; import org.apache.ignite.jdbc.thin.JdbcThinStatementSelfTest; @@ -36,14 +35,13 @@ JdbcThinTcpIoTest.class, JdbcThinStatementSelfTest.class, }) -public class IgniteJdbcThinDriverBestEffordAffinitySuite { +public class IgniteJdbcThinDriverBestEffordAffinityTestSuite { /** * Setup best effort affinity mode. */ @BeforeClass public static void setupBestEffortAffinity() { - GridTestUtils.setFieldValue(JdbcThinConnection.class, "bestEffortAffinity", true); GridTestUtils.setFieldValue(JdbcThinAbstractSelfTest.class, "bestEffortAffinity", true); } } \ No newline at end of file diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinConnectionSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinConnectionSelfTest.java index 3a97223256acf..fb2430585fc3b 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinConnectionSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinConnectionSelfTest.java @@ -89,6 +89,18 @@ public class JdbcThinConnectionSelfTest extends JdbcThinAbstractSelfTest { "jdbc:ignite:thin://127.0.0.1:10800..10802" : "jdbc:ignite:thin://127.0.0.1"; + /** URL with best effort affinity flag. */ + private String urlWithBestEffortAffinityFlag = url + + (bestEffortAffinity ? + "?bestEffortAffinityEnabled=true" : + "?bestEffortAffinityEnabled=false"); + + /** URL with best effort affinity flag and semicolon as delimeter. */ + private String urlWithBestEffortAffinityFlagSemicolon = url + + (bestEffortAffinity ? + ";bestEffortAffinityEnabled=true" : + ";bestEffortAffinityEnabled=false"); + /** Nodes count. */ private int nodesCnt = bestEffortAffinity ? 4 : 2; @@ -165,13 +177,13 @@ public void testInvalidEndpoint() { public void testSocketBuffers() throws Exception { final int dfltDufSize = 64 * 1024; - assertInvalid(url + "?socketSendBuffer=-1", + assertInvalid(urlWithBestEffortAffinityFlag + "&socketSendBuffer=-1", "Property cannot be lower than 0 [name=socketSendBuffer, value=-1]"); - assertInvalid(url + "?socketReceiveBuffer=-1", + assertInvalid(urlWithBestEffortAffinityFlag + "&socketReceiveBuffer=-1", "Property cannot be lower than 0 [name=socketReceiveBuffer, value=-1]"); - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { for (JdbcThinTcpIo io: ios(conn)) { assertEquals(dfltDufSize, io.connectionProperties().getSocketSendBuffer()); assertEquals(dfltDufSize, io.connectionProperties().getSocketReceiveBuffer()); @@ -179,21 +191,21 @@ public void testSocketBuffers() throws Exception { } // Note that SO_* options are hints, so we check that value is equals to either what we set or to default. - try (Connection conn = DriverManager.getConnection(url + "?socketSendBuffer=1024")) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag + "&socketSendBuffer=1024")) { for (JdbcThinTcpIo io: ios(conn)) { assertEquals(1024, io.connectionProperties().getSocketSendBuffer()); assertEquals(dfltDufSize, io.connectionProperties().getSocketReceiveBuffer()); } } - try (Connection conn = DriverManager.getConnection(url + "?socketReceiveBuffer=1024")) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag + "&socketReceiveBuffer=1024")) { for (JdbcThinTcpIo io: ios(conn)) { assertEquals(dfltDufSize, io.connectionProperties().getSocketSendBuffer()); assertEquals(1024, io.connectionProperties().getSocketReceiveBuffer()); } } - try (Connection conn = DriverManager.getConnection(url+ "?" + + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag + "&" + "socketSendBuffer=1024&socketReceiveBuffer=2048")) { for (JdbcThinTcpIo io: ios(conn)) { assertEquals(1024, io.connectionProperties().getSocketSendBuffer()); @@ -211,28 +223,28 @@ public void testSocketBuffers() throws Exception { public void testSocketBuffersSemicolon() throws Exception { final int dfltDufSize = 64 * 1024; - assertInvalid(url + ";socketSendBuffer=-1", + assertInvalid(urlWithBestEffortAffinityFlagSemicolon + ";socketSendBuffer=-1", "Property cannot be lower than 0 [name=socketSendBuffer, value=-1]"); - assertInvalid(url + ";socketReceiveBuffer=-1", + assertInvalid(urlWithBestEffortAffinityFlagSemicolon + ";socketReceiveBuffer=-1", "Property cannot be lower than 0 [name=socketReceiveBuffer, value=-1]"); // Note that SO_* options are hints, so we check that value is equals to either what we set or to default. - try (Connection conn = DriverManager.getConnection(url + ";socketSendBuffer=1024")) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlagSemicolon + ";socketSendBuffer=1024")) { for (JdbcThinTcpIo io: ios(conn)) { assertEquals(1024, io.connectionProperties().getSocketSendBuffer()); assertEquals(dfltDufSize, io.connectionProperties().getSocketReceiveBuffer()); } } - try (Connection conn = DriverManager.getConnection(url + ";socketReceiveBuffer=1024")) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlagSemicolon + ";socketReceiveBuffer=1024")) { for (JdbcThinTcpIo io: ios(conn)) { assertEquals(dfltDufSize, io.connectionProperties().getSocketSendBuffer()); assertEquals(1024, io.connectionProperties().getSocketReceiveBuffer()); } } - try (Connection conn = DriverManager.getConnection(url + ";" + + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlagSemicolon + ";" + "socketSendBuffer=1024;socketReceiveBuffer=2048")) { for (JdbcThinTcpIo io: ios(conn)) { assertEquals(1024, io.connectionProperties().getSocketSendBuffer()); @@ -248,37 +260,44 @@ public void testSocketBuffersSemicolon() throws Exception { */ @Test public void testSqlHints() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { - assertHints(conn, false, false, false, false, false, false); + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { + assertHints(conn, false, false, false, false, false, false, bestEffortAffinity); } - try (Connection conn = DriverManager.getConnection(url + "?distributedJoins=true")) { - assertHints(conn, true, false, false, false, false, false); + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag + "&distributedJoins=true")) { + assertHints(conn, true, false, false, false, false, + false, bestEffortAffinity); } - try (Connection conn = DriverManager.getConnection(url + "?enforceJoinOrder=true")) { - assertHints(conn, false, true, false, false, false, false); + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag + "&enforceJoinOrder=true")) { + assertHints(conn, false, true, false, false, false, + false, bestEffortAffinity); } - try (Connection conn = DriverManager.getConnection(url + "?collocated=true")) { - assertHints(conn, false, false, true, false, false, false); + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag + "&collocated=true")) { + assertHints(conn, false, false, true, false, false, + false, bestEffortAffinity); } - try (Connection conn = DriverManager.getConnection(url + "?replicatedOnly=true")) { - assertHints(conn, false, false, false, true, false, false); + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag + "&replicatedOnly=true")) { + assertHints(conn, false, false, false, true, false, + false, bestEffortAffinity); } - try (Connection conn = DriverManager.getConnection(url + "?lazy=true")) { - assertHints(conn, false, false, false, false, true, false); + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag + "&lazy=true")) { + assertHints(conn, false, false, false, false, true, + false, bestEffortAffinity); } - try (Connection conn = DriverManager.getConnection(url + "?skipReducerOnUpdate=true")) { - assertHints(conn, false, false, false, false, false, true); + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag + "&skipReducerOnUpdate=true")) { + assertHints(conn, false, false, false, false, false, + true, bestEffortAffinity); } - try (Connection conn = DriverManager.getConnection(url + "?distributedJoins=true&" + + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag + "&distributedJoins=true&" + "enforceJoinOrder=true&collocated=true&replicatedOnly=true&lazy=true&skipReducerOnUpdate=true")) { - assertHints(conn, true, true, true, true, true, true); + assertHints(conn, true, true, true, true, true, + true, bestEffortAffinity); } } @@ -289,33 +308,40 @@ public void testSqlHints() throws Exception { */ @Test public void testSqlHintsSemicolon() throws Exception { - try (Connection conn = DriverManager.getConnection(url + ";distributedJoins=true")) { - assertHints(conn, true, false, false, false, false, false); + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlagSemicolon + ";distributedJoins=true")) { + assertHints(conn, true, false, false, false, false, + false, bestEffortAffinity); } - try (Connection conn = DriverManager.getConnection(url + ";enforceJoinOrder=true")) { - assertHints(conn, false, true, false, false, false, false); + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlagSemicolon + ";enforceJoinOrder=true")) { + assertHints(conn, false, true, false, false, false, + false, bestEffortAffinity); } - try (Connection conn = DriverManager.getConnection(url + ";collocated=true")) { - assertHints(conn, false, false, true, false, false, false); + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlagSemicolon + ";collocated=true")) { + assertHints(conn, false, false, true, false, false, + false, bestEffortAffinity); } - try (Connection conn = DriverManager.getConnection(url + ";replicatedOnly=true")) { - assertHints(conn, false, false, false, true, false, false); + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlagSemicolon + ";replicatedOnly=true")) { + assertHints(conn, false, false, false, true, false, + false, bestEffortAffinity); } - try (Connection conn = DriverManager.getConnection(url + ";lazy=true")) { - assertHints(conn, false, false, false, false, true, false); + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlagSemicolon + ";lazy=true")) { + assertHints(conn, false, false, false, false, true, + false, bestEffortAffinity); } - try (Connection conn = DriverManager.getConnection(url + ";skipReducerOnUpdate=true")) { - assertHints(conn, false, false, false, false, false, true); + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlagSemicolon + ";skipReducerOnUpdate=true")) { + assertHints(conn, false, false, false, false, false, + true, bestEffortAffinity); } - try (Connection conn = DriverManager.getConnection(url + ";distributedJoins=true;" + + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlagSemicolon + ";distributedJoins=true;" + "enforceJoinOrder=true;collocated=true;replicatedOnly=true;lazy=true;skipReducerOnUpdate=true")) { - assertHints(conn, true, true, true, true, true, true); + assertHints(conn, true, true, true, true, true, + true, bestEffortAffinity); } } @@ -332,7 +358,7 @@ public void testSqlHintsSemicolon() throws Exception { * @throws Exception If failed. */ private void assertHints(Connection conn, boolean distributedJoins, boolean enforceJoinOrder, boolean collocated, - boolean replicatedOnly, boolean lazy, boolean skipReducerOnUpdate)throws Exception { + boolean replicatedOnly, boolean lazy, boolean skipReducerOnUpdate, boolean bestEffortAffinityEnabled)throws Exception { for (JdbcThinTcpIo io: ios(conn)) { assertEquals(distributedJoins, io.connectionProperties().isDistributedJoins()); assertEquals(enforceJoinOrder, io.connectionProperties().isEnforceJoinOrder()); @@ -340,6 +366,7 @@ private void assertHints(Connection conn, boolean distributedJoins, boolean enfo assertEquals(replicatedOnly, io.connectionProperties().isReplicatedOnly()); assertEquals(lazy, io.connectionProperties().isLazy()); assertEquals(skipReducerOnUpdate, io.connectionProperties().isSkipReducerOnUpdate()); + assertEquals(bestEffortAffinityEnabled, io.connectionProperties().isBestEffortAffinityEnabled()); } } @@ -350,39 +377,39 @@ private void assertHints(Connection conn, boolean distributedJoins, boolean enfo */ @Test public void testTcpNoDelay() throws Exception { - assertInvalid(url + "?tcpNoDelay=0", + assertInvalid(urlWithBestEffortAffinityFlag + "&tcpNoDelay=0", "Invalid property value. [name=tcpNoDelay, val=0, choices=[true, false]]"); - assertInvalid(url + "?tcpNoDelay=1", + assertInvalid(urlWithBestEffortAffinityFlag + "&tcpNoDelay=1", "Invalid property value. [name=tcpNoDelay, val=1, choices=[true, false]]"); - assertInvalid(url + "?tcpNoDelay=false1", + assertInvalid(urlWithBestEffortAffinityFlag + "&tcpNoDelay=false1", "Invalid property value. [name=tcpNoDelay, val=false1, choices=[true, false]]"); - assertInvalid(url + "?tcpNoDelay=true1", + assertInvalid(urlWithBestEffortAffinityFlag + "&tcpNoDelay=true1", "Invalid property value. [name=tcpNoDelay, val=true1, choices=[true, false]]"); - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { for (JdbcThinTcpIo io: ios(conn)) assertTrue(io.connectionProperties().isTcpNoDelay()); } - try (Connection conn = DriverManager.getConnection(url + "?tcpNoDelay=true")) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag + "&tcpNoDelay=true")) { for (JdbcThinTcpIo io: ios(conn)) assertTrue(io.connectionProperties().isTcpNoDelay()); } - try (Connection conn = DriverManager.getConnection(url + "?tcpNoDelay=True")) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag + "&tcpNoDelay=True")) { for (JdbcThinTcpIo io: ios(conn)) assertTrue(io.connectionProperties().isTcpNoDelay()); } - try (Connection conn = DriverManager.getConnection(url + "?tcpNoDelay=false")) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag + "&tcpNoDelay=false")) { for (JdbcThinTcpIo io: ios(conn)) assertFalse(io.connectionProperties().isTcpNoDelay()); } - try (Connection conn = DriverManager.getConnection(url + "?tcpNoDelay=False")) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag + "&tcpNoDelay=False")) { for (JdbcThinTcpIo io: ios(conn)) assertFalse(io.connectionProperties().isTcpNoDelay()); } @@ -395,34 +422,34 @@ public void testTcpNoDelay() throws Exception { */ @Test public void testTcpNoDelaySemicolon() throws Exception { - assertInvalid(url + ";tcpNoDelay=0", + assertInvalid(urlWithBestEffortAffinityFlagSemicolon + ";tcpNoDelay=0", "Invalid property value. [name=tcpNoDelay, val=0, choices=[true, false]]"); - assertInvalid(url + ";tcpNoDelay=1", + assertInvalid(urlWithBestEffortAffinityFlagSemicolon + ";tcpNoDelay=1", "Invalid property value. [name=tcpNoDelay, val=1, choices=[true, false]]"); - assertInvalid(url + ";tcpNoDelay=false1", + assertInvalid(urlWithBestEffortAffinityFlagSemicolon + ";tcpNoDelay=false1", "Invalid property value. [name=tcpNoDelay, val=false1, choices=[true, false]]"); - assertInvalid(url + ";tcpNoDelay=true1", + assertInvalid(urlWithBestEffortAffinityFlagSemicolon + ";tcpNoDelay=true1", "Invalid property value. [name=tcpNoDelay, val=true1, choices=[true, false]]"); - try (Connection conn = DriverManager.getConnection(url + ";tcpNoDelay=true")) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlagSemicolon + ";tcpNoDelay=true")) { for (JdbcThinTcpIo io: ios(conn)) assertTrue(io.connectionProperties().isTcpNoDelay()); } - try (Connection conn = DriverManager.getConnection(url + ";tcpNoDelay=True")) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlagSemicolon + ";tcpNoDelay=True")) { for (JdbcThinTcpIo io: ios(conn)) assertTrue(io.connectionProperties().isTcpNoDelay()); } - try (Connection conn = DriverManager.getConnection(url + ";tcpNoDelay=false")) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlagSemicolon + ";tcpNoDelay=false")) { for (JdbcThinTcpIo io: ios(conn)) assertFalse(io.connectionProperties().isTcpNoDelay()); } - try (Connection conn = DriverManager.getConnection(url + ";tcpNoDelay=False")) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlagSemicolon + ";tcpNoDelay=False")) { for (JdbcThinTcpIo io: ios(conn)) assertFalse(io.connectionProperties().isTcpNoDelay()); } @@ -435,7 +462,7 @@ public void testTcpNoDelaySemicolon() throws Exception { */ @Test public void testAutoCloseServerCursorProperty() throws Exception { - String url = this.url + "?autoCloseServerCursor"; + String url = urlWithBestEffortAffinityFlag + "&autoCloseServerCursor"; String err = "Invalid property value. [name=autoCloseServerCursor"; @@ -444,7 +471,7 @@ public void testAutoCloseServerCursorProperty() throws Exception { assertInvalid(url + "=false1", err); assertInvalid(url + "=true1", err); - try (Connection conn = DriverManager.getConnection(this.url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { for (JdbcThinTcpIo io: ios(conn)) assertFalse(io.connectionProperties().isAutoCloseServerCursor()); } @@ -477,7 +504,7 @@ public void testAutoCloseServerCursorProperty() throws Exception { */ @Test public void testAutoCloseServerCursorPropertySemicolon() throws Exception { - String url = this.url + ";autoCloseServerCursor"; + String url = urlWithBestEffortAffinityFlagSemicolon + ";autoCloseServerCursor"; String err = "Invalid property value. [name=autoCloseServerCursor"; @@ -537,15 +564,15 @@ public void testSchema() throws Exception { */ @Test public void testSchemaSemicolon() throws Exception { - try (Connection conn = DriverManager.getConnection(url + ";schema=public")) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlagSemicolon + ";schema=public")) { assertEquals("Invalid schema", "PUBLIC", conn.getSchema()); } - try (Connection conn = DriverManager.getConnection(url + ";schema=\"" + DEFAULT_CACHE_NAME + '"')) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlagSemicolon + ";schema=\"" + DEFAULT_CACHE_NAME + '"')) { assertEquals("Invalid schema", DEFAULT_CACHE_NAME, conn.getSchema()); } - try (Connection conn = DriverManager.getConnection(url + ";schema=_not_exist_schema_")) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlagSemicolon + ";schema=_not_exist_schema_")) { assertEquals("Invalid schema", "_NOT_EXIST_SCHEMA_", conn.getSchema()); } } @@ -594,7 +621,7 @@ private void assertInvalid(final String url, String errMsg) { public void testClose() throws Exception { final Connection conn; - try (Connection conn0 = DriverManager.getConnection(url)) { + try (Connection conn0 = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { conn = conn0; assert conn != null; @@ -619,7 +646,7 @@ public void testClose() throws Exception { */ @Test public void testCreateStatement() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { try (Statement stmt = conn.createStatement()) { assertNotNull(stmt); @@ -642,7 +669,7 @@ public void testCreateStatement() throws Exception { */ @Test public void testCreateStatement2() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { int [] rsTypes = new int[] {TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.TYPE_SCROLL_SENSITIVE}; @@ -696,7 +723,7 @@ public void testCreateStatement2() throws Exception { */ @Test public void testCreateStatement3() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { int [] rsTypes = new int[] {TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.TYPE_SCROLL_SENSITIVE}; @@ -756,7 +783,7 @@ public void testCreateStatement3() throws Exception { */ @Test public void testPrepareStatement() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { // null query text GridTestUtils.assertThrows(log, new Callable() { @@ -790,7 +817,7 @@ public void testPrepareStatement() throws Exception { */ @Test public void testPrepareStatement3() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { final String sqlText = "select * from test where param = ?"; int [] rsTypes = new int[] @@ -851,7 +878,7 @@ public void testPrepareStatement3() throws Exception { */ @Test public void testPrepareStatement4() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { final String sqlText = "select * from test where param = ?"; int [] rsTypes = new int[] @@ -917,7 +944,7 @@ public void testPrepareStatement4() throws Exception { */ @Test public void testPrepareStatementAutoGeneratedKeysUnsupported() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { final String sqlText = "insert into test (val) values (?)"; GridTestUtils.assertThrows(log, @@ -967,7 +994,7 @@ public void testPrepareStatementAutoGeneratedKeysUnsupported() throws Exception */ @Test public void testPrepareCallUnsupported() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { final String sqlText = "exec test()"; GridTestUtils.assertThrows(log, @@ -1008,7 +1035,7 @@ public void testPrepareCallUnsupported() throws Exception { */ @Test public void testNativeSql() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { // null query text GridTestUtils.assertThrows(log, new Callable() { @@ -1040,7 +1067,7 @@ public void testNativeSql() throws Exception { */ @Test public void testGetSetAutoCommit() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { boolean ac0 = conn.getAutoCommit(); conn.setAutoCommit(!ac0); @@ -1065,7 +1092,7 @@ public void testGetSetAutoCommit() throws Exception { */ @Test public void testCommit() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { // Should not be called in auto-commit mode GridTestUtils.assertThrows(log, new Callable() { @@ -1110,7 +1137,7 @@ public void testCommit() throws Exception { */ @Test public void testRollback() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { // Should not be called in auto-commit mode GridTestUtils.assertThrows(log, new Callable() { @@ -1140,7 +1167,7 @@ public void testRollback() throws Exception { */ @Test public void testBeginFailsWhenMvccIsDisabled() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { conn.createStatement().execute("BEGIN"); fail("Exception is expected"); @@ -1155,7 +1182,7 @@ public void testBeginFailsWhenMvccIsDisabled() throws Exception { */ @Test public void testCommitIgnoredWhenMvccIsDisabled() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { conn.setAutoCommit(false); conn.createStatement().execute("COMMIT"); @@ -1169,7 +1196,7 @@ public void testCommitIgnoredWhenMvccIsDisabled() throws Exception { */ @Test public void testRollbackIgnoredWhenMvccIsDisabled() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { conn.setAutoCommit(false); conn.createStatement().execute("ROLLBACK"); @@ -1184,7 +1211,7 @@ public void testRollbackIgnoredWhenMvccIsDisabled() throws Exception { */ @Test public void testGetMetaData() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { DatabaseMetaData meta = conn.getMetaData(); assertNotNull(meta); @@ -1205,7 +1232,7 @@ public void testGetMetaData() throws Exception { */ @Test public void testGetSetReadOnly() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { conn.close(); // Exception when called on closed connection @@ -1229,7 +1256,7 @@ public void testGetSetReadOnly() throws Exception { */ @Test public void testGetSetCatalog() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { assert !conn.getMetaData().supportsCatalogsInDataManipulation(); assertNull(conn.getCatalog()); @@ -1261,7 +1288,7 @@ public void testGetSetCatalog() throws Exception { */ @Test public void testGetSetTransactionIsolation() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { // Invalid parameter value GridTestUtils.assertThrows(log, new Callable() { @@ -1312,7 +1339,7 @@ public void testGetSetTransactionIsolation() throws Exception { */ @Test public void testClearGetWarnings() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { SQLWarning warn = conn.getWarnings(); assertNull(warn); @@ -1346,7 +1373,7 @@ public void testClearGetWarnings() throws Exception { */ @Test public void testGetSetTypeMap() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { GridTestUtils.assertThrows(log, new Callable() { @Override public Object call() throws Exception { @@ -1402,7 +1429,7 @@ public void testGetSetTypeMap() throws Exception { */ @Test public void testGetSetHoldability() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { // default value assertEquals(conn.getMetaData().getResultSetHoldability(), conn.getHoldability()); @@ -1456,7 +1483,7 @@ public void testGetSetHoldability() throws Exception { */ @Test public void testSetSavepoint() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { assert !conn.getMetaData().supportsSavepoints(); // Disallowed in auto-commit mode @@ -1487,7 +1514,7 @@ public void testSetSavepoint() throws Exception { */ @Test public void testSetSavepointName() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { assert !conn.getMetaData().supportsSavepoints(); // Invalid arg @@ -1533,7 +1560,7 @@ public void testSetSavepointName() throws Exception { */ @Test public void testRollbackSavePoint() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { assert !conn.getMetaData().supportsSavepoints(); // Invalid arg @@ -1579,7 +1606,7 @@ public void testRollbackSavePoint() throws Exception { */ @Test public void testReleaseSavepoint() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { assert !conn.getMetaData().supportsSavepoints(); // Invalid arg @@ -1618,7 +1645,7 @@ public void testReleaseSavepoint() throws Exception { */ @Test public void testCreateClob() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { // Unsupported GridTestUtils.assertThrows(log, new Callable() { @@ -1649,7 +1676,7 @@ public void testCreateClob() throws Exception { */ @Test public void testCreateBlob() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { // Unsupported GridTestUtils.assertThrows(log, new Callable() { @@ -1680,7 +1707,7 @@ public void testCreateBlob() throws Exception { */ @Test public void testCreateNClob() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { // Unsupported GridTestUtils.assertThrows(log, new Callable() { @@ -1711,7 +1738,7 @@ public void testCreateNClob() throws Exception { */ @Test public void testCreateSQLXML() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { // Unsupported GridTestUtils.assertThrows(log, new Callable() { @@ -1744,7 +1771,7 @@ public void testCreateSQLXML() throws Exception { public void testGetSetClientInfoPair() throws Exception { // fail("https://issues.apache.org/jira/browse/IGNITE-5425"); - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { final String name = "ApplicationName"; final String val = "SelfTest"; @@ -1778,7 +1805,7 @@ public void testGetSetClientInfoPair() throws Exception { */ @Test public void testGetSetClientInfoProperties() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { final String name = "ApplicationName"; final String val = "SelfTest"; @@ -1817,7 +1844,7 @@ public void testGetSetClientInfoProperties() throws Exception { */ @Test public void testCreateArrayOf() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { final String typeName = "varchar"; final String[] elements = new String[] {"apple", "pear"}; @@ -1858,7 +1885,7 @@ public void testCreateArrayOf() throws Exception { */ @Test public void testCreateStruct() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { // Invalid typename GridTestUtils.assertThrows(log, new Callable() { @@ -1895,7 +1922,7 @@ public void testCreateStruct() throws Exception { */ @Test public void testGetSetSchema() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { assertEquals("PUBLIC", conn.getSchema()); final String schema = "test"; @@ -1929,7 +1956,7 @@ public void testGetSetSchema() throws Exception { */ @Test public void testAbort() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { //Invalid executor GridTestUtils.assertThrows(log, new Callable() { @@ -1956,7 +1983,7 @@ public void testAbort() throws Exception { */ @Test public void testGetSetNetworkTimeout() throws Exception { - try (Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { // default assertEquals(0, conn.getNetworkTimeout()); @@ -2004,7 +2031,7 @@ public void testGetSetNetworkTimeout() throws Exception { public void testInvalidNestedTxMode() { GridTestUtils.assertThrows(null, new Callable() { @Override public Object call() throws Exception { - DriverManager.getConnection(url + "/?nestedTransactionsMode=invalid"); + DriverManager.getConnection(urlWithBestEffortAffinityFlag + "&nestedTransactionsMode=invalid"); return null; } @@ -2024,6 +2051,8 @@ public void testInvalidNestedTxModeOnServerSide() { connProps.nestedTxMode("invalid"); + connProps.setBestEffortAffinityEnabled(bestEffortAffinity); + GridTestUtils.assertThrows(null, new Callable() { @SuppressWarnings("ResultOfObjectAllocationIgnored") @Override public Object call() throws Exception { @@ -2040,7 +2069,7 @@ public void testInvalidNestedTxModeOnServerSide() { public void testSslClientAndPlainServer() { Throwable e = GridTestUtils.assertThrows(log, new Callable() { @Override public Object call() throws Exception { - DriverManager.getConnection(url + "/?sslMode=require" + + DriverManager.getConnection(urlWithBestEffortAffinityFlag + "&sslMode=require" + "&sslClientCertificateKeyStoreUrl=" + CLI_KEY_STORE_PATH + "&sslClientCertificateKeyStorePassword=123456" + "&sslTrustCertificateKeyStoreUrl=" + SRV_KEY_STORE_PATH + @@ -2071,7 +2100,7 @@ public void testMultithreadingException() throws Exception { final AtomicInteger exCnt = new AtomicInteger(0); - try (final Connection conn = DriverManager.getConnection(url)) { + try (final Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { final IgniteInternalFuture f = GridTestUtils.runMultiThreadedAsync(new Runnable() { @Override public void run() { try { diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinStatementSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinStatementSelfTest.java index 93a120cd0f0ae..c321361207e4a 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinStatementSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinStatementSelfTest.java @@ -44,8 +44,8 @@ public class JdbcThinStatementSelfTest extends JdbcThinAbstractSelfTest { /** URL. */ private String url = bestEffortAffinity ? - "jdbc:ignite:thin://127.0.0.1:10800..10802" : - "jdbc:ignite:thin://127.0.0.1"; + "jdbc:ignite:thin://127.0.0.1:10800..10802?bestEffortAffinityEnabled=true" : + "jdbc:ignite:thin://127.0.0.1?bestEffortAffinityEnabled=false"; /** Nodes count. */ private int nodesCnt = bestEffortAffinity ? 4 : 3; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionProperties.java b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionProperties.java index a4f7eb7da5218..58e538f439e57 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionProperties.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionProperties.java @@ -410,12 +410,11 @@ public interface ConnectionProperties { * @return {@code True} if jdbc thin best effort affinity is enabled for this connection, * {@code false} if it's disabled. */ - @Nullable public Boolean isJdbcThinBestEffortAffinityEnabled(); + public boolean isBestEffortAffinityEnabled(); /** - * @param jdbcThinBestEffortAffinityEnabled {@code True} if jdbc thin best effort affinity is enabled - * for this connection, if {@code false} then it's disabled, if {@code null} then server should use - * its default settings. + * @param bestEffortAffinityEnabled {@code True} if jdbc thin best effort affinity is enabled + * for this connection, if {@code false} then it's disabled. */ - public void setJdbcThinBestEffortAffinityEnabled(@Nullable Boolean jdbcThinBestEffortAffinityEnabled); + public void setBestEffortAffinityEnabled(boolean bestEffortAffinityEnabled); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionPropertiesImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionPropertiesImpl.java index 3642a257fffa8..bc3cf31a65f23 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionPropertiesImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionPropertiesImpl.java @@ -190,8 +190,8 @@ false, new PropertyValidator() { null, false); /** Best effort affinity flag. */ - private BooleanProperty jdbcThinBestEffortAffinityEnabled = new BooleanProperty( - "jdbcThinBestEffortAffinityEnabled", + private BooleanProperty bestEffortAffinityEnabled = new BooleanProperty( + "bestEffortAffinityEnabled", "Whether jdbc thin best effort affinity is enabled.", false, false); @@ -205,7 +205,7 @@ false, new PropertyValidator() { sslTrustAll, sslFactory, user, passwd, dataPageScanEnabled, - jdbcThinBestEffortAffinityEnabled + bestEffortAffinityEnabled }; /** {@inheritDoc} */ @@ -512,13 +512,13 @@ false, new PropertyValidator() { } /** {@inheritDoc} */ - @Override public @Nullable Boolean isJdbcThinBestEffortAffinityEnabled() { - return jdbcThinBestEffortAffinityEnabled.value(); + @Override public boolean isBestEffortAffinityEnabled() { + return bestEffortAffinityEnabled.value(); } /** {@inheritDoc} */ - @Override public void setJdbcThinBestEffortAffinityEnabled(@Nullable Boolean jdbcThinBestEffortAffinityEnabled) { - this.jdbcThinBestEffortAffinityEnabled.setValue(jdbcThinBestEffortAffinityEnabled); + @Override public void setBestEffortAffinityEnabled(boolean bestEffortAffinityEnabled) { + this.bestEffortAffinityEnabled.setValue(bestEffortAffinityEnabled); } /** 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 06bab833b00c9..9a8cf341be61b 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 @@ -208,7 +208,7 @@ public JdbcThinConnection(ConnectionProperties connProps) throws SQLException { timer = new Timer("query-timeout-timer"); - bestEffortAffinity = connProps.isJdbcThinBestEffortAffinityEnabled(); + bestEffortAffinity = connProps.isBestEffortAffinityEnabled(); ensureConnected(); } From cfd9d1ecf7fe893e564d15c58c72686a3902fd8a Mon Sep 17 00:00:00 2001 From: sanpwc Date: Wed, 10 Apr 2019 15:14:22 +0300 Subject: [PATCH 3/8] ignite-11309 tests for best effort affinity added. --- ...ThinDriverBestEffordAffinityTestSuite.java | 2 + .../JdbcThinBestEffortAffinitySelfTest.java | 811 ++++++++++++++++++ ...estEffortAffinityTransactionsSelfTest.java | 4 +- 3 files changed, 815 insertions(+), 2 deletions(-) create mode 100644 modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcThinDriverBestEffordAffinityTestSuite.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcThinDriverBestEffordAffinityTestSuite.java index b2add266e9d47..dbc9c4e54fd4f 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcThinDriverBestEffordAffinityTestSuite.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcThinDriverBestEffordAffinityTestSuite.java @@ -18,6 +18,7 @@ package org.apache.ignite.jdbc.suite; import org.apache.ignite.jdbc.thin.JdbcThinAbstractSelfTest; +import org.apache.ignite.jdbc.thin.JdbcThinBestEffortAffinitySelfTest; import org.apache.ignite.jdbc.thin.JdbcThinBestEffortAffinityTransactionsSelfTest; import org.apache.ignite.jdbc.thin.JdbcThinConnectionSelfTest; import org.apache.ignite.jdbc.thin.JdbcThinStatementSelfTest; @@ -35,6 +36,7 @@ JdbcThinConnectionSelfTest.class, JdbcThinTcpIoTest.class, JdbcThinStatementSelfTest.class, + JdbcThinBestEffortAffinitySelfTest.class, JdbcThinBestEffortAffinityTransactionsSelfTest.class, }) public class IgniteJdbcThinDriverBestEffordAffinityTestSuite { diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java new file mode 100644 index 0000000000000..ea3735a230026 --- /dev/null +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java @@ -0,0 +1,811 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.jdbc.thin; + +import java.io.Serializable; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.Callable; +import java.util.stream.Collectors; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.affinity.AffinityFunction; +import org.apache.ignite.cache.affinity.AffinityFunctionContext; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.jdbc.thin.AffinityCache; +import org.apache.ignite.internal.jdbc.thin.JdbcThinPartitionResultDescriptor; +import org.apache.ignite.internal.jdbc.thin.QualifiedSQLQuery; +import org.apache.ignite.internal.processors.query.QueryHistoryMetrics; +import org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing; +import org.apache.ignite.internal.sql.optimizer.affinity.PartitionResult; +import org.apache.ignite.internal.util.GridBoundedLinkedHashMap; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.lang.IgnitePredicate; +import org.apache.ignite.testframework.GridTestUtils; + +import static org.apache.ignite.cache.CacheMode.PARTITIONED; + +/** + * Jdbc thin best effort affinity test. + */ +@SuppressWarnings({"ThrowableNotThrown"}) +public class JdbcThinBestEffortAffinitySelfTest extends JdbcThinAbstractSelfTest { + /** URL. */ + private static final String URL = "jdbc:ignite:thin://127.0.0.1:10800..10802?bestEffortAffinityEnabled=true"; + + /** Nodes count. */ + private static final int NODES_CNT = 3; + + /** Query execution multiplier. */ + private static final int QUERY_EXECUTION_MULTIPLIER = 5; + + /** Rows count. */ + private static final int ROWS_COUNT = 100; + + /** Connection. */ + private Connection conn; + + /** Statement. */ + private Statement stmt; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + CacheConfiguration cache = defaultCacheConfiguration(); + + cache.setCacheMode(PARTITIONED); + cache.setBackups(1); + cache.setIndexedTypes( + Integer.class, Person.class, + Integer.class, Test.class + ); + + cfg.setCacheConfiguration(cache); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + startGridsMultiThreaded(NODES_CNT); + + fillCache(DEFAULT_CACHE_NAME); + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + conn = DriverManager.getConnection(URL); + + conn.setSchema('"' + DEFAULT_CACHE_NAME + '"'); + + stmt = conn.createStatement(); + + assert stmt != null; + assert !stmt.isClosed(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + if (stmt != null && !stmt.isClosed()) { + stmt.close(); + + assert stmt.isClosed(); + } + + conn.close(); + + assert stmt.isClosed(); + assert conn.isClosed(); + } + + /** + * Check that queries goes to expected number of nodes. + * + * @throws Exception If failed. + */ + @org.junit.Test + public void testExecuteQueries() throws Exception { + checkNodesUsage(null, "select * from Person where _key = 1", 1, 1, + false); + + checkNodesUsage(null, "select * from Person where _key = 1 or _key = 2", 2, + 2, false); + + checkNodesUsage(null, "select * from Person where _key in (1, 2)", 2, 2, + false); + } + + /** + * Check that parameterised queries goes to expected number of nodes. + * + * @throws Exception If failed. + */ + @org.junit.Test + public void testExecuteParametrizedQueries() throws Exception { + PreparedStatement ps = conn.prepareStatement("select * from Person where _key = ?"); + ps.setInt(1, 2); + checkNodesUsage(ps, null, 1, 1, false); + + ps = conn.prepareStatement("select * from Person where _key = ? or _key = ?"); + ps.setInt(1, 1); + ps.setInt(2, 2); + checkNodesUsage(ps, null, 2, 2, false); + + ps = conn.prepareStatement("select * from Person where _key in (?, ?)"); + ps.setInt(1, 1); + ps.setInt(2, 2); + checkNodesUsage(ps, null, 2, 2, false); + } + + /** + * Check that dml queries(updates) goes to expected number of nodes. + * + * @throws Exception If failed. + */ + @org.junit.Test + public void testUpdateQueries() throws Exception { + checkNodesUsage(null, "update Person set firstName = 'TestFirstName' where _key = 1", + 1, 1, true); + + checkNodesUsage(null, "update Person set firstName = 'TestFirstName' where _key = 1 or _key = 2", + 2, 2, true); + + checkNodesUsage(null, "update Person set firstName = 'TestFirstName' where _key in (1, 2)", + 2, 2, true); + } + + /** + * Check that parameterised dml queries(updates) goes to expected number of nodes. + * + * @throws Exception If failed. + */ + @org.junit.Test + public void testUpdateParametrizedQueries() throws Exception { + PreparedStatement ps = conn.prepareStatement( + "update Person set firstName = 'TestFirstName' where _key = ?"); + ps.setInt(1, 2); + checkNodesUsage(ps, null, + 1, 1, true); + + ps = conn.prepareStatement("update Person set firstName = 'TestFirstName' where _key = ? or _key = ?"); + ps.setInt(1, 1); + ps.setInt(2, 2); + checkNodesUsage(ps, null, + 2, 2, true); + + ps = conn.prepareStatement("update Person set firstName = 'TestFirstName' where _key in (?, ?)"); + ps.setInt(1, 1); + ps.setInt(2, 2); + checkNodesUsage(ps, null, + 2, 2, true); + } + + /** + * Check that dml queries(delete) goes to expected number of nodes. + * + * @throws Exception If failed. + */ + @org.junit.Test + public void testDeleteQueries() throws Exception { + // In case of simple query like "delete from Person where _key = 1" fast update logic is used, + // so parition result is not calculated on the server side - nothing to check. + + checkNodesUsage(null, "delete from Person where _key = 10000 or _key = 20000", + 2, 0, true); + + checkNodesUsage(null, "delete from Person where _key in (10000, 20000)", + 2, 0, true); + } + + /** + * Check that parameterised dml queries(delete) goes to expected number of nodes. + * + * @throws Exception If failed. + */ + @org.junit.Test + public void testDeleteParametrizedQueries() throws Exception { + // In case of simple query like "delete from Person where _key = ?" fast update logic is used, + // so parition result is not calculated on the server side - nothing to check. + + PreparedStatement ps = conn.prepareStatement( + "delete from Person where _key = ? or _key = ?"); + ps.setInt(1, 1000); + ps.setInt(2, 2000); + checkNodesUsage(ps, null, + 2, 0, true); + + ps = conn.prepareStatement("delete from Person where _key in (?, ?)"); + ps.setInt(1, 1000); + ps.setInt(2, 2000); + checkNodesUsage(ps, null, + 2, 0, true); + } + + /** + * Check that request/response functionality works fine if server response lacks partition result, + * i.e. partitionResult is null. AllNode tes. + * + * @throws Exception If failed. + */ + @org.junit.Test + public void testQueryWithNullPartitionResponseBasedOnAllNode() throws Exception { + verifyPartitionResultIsNull("select * from Person where age > 15", 85); + } + + /** + * Check that request/response functionality works fine if server response lacks partition result, + * i.e. partitionResult is null. NoneNode tes. + * + * @throws Exception If failed. + */ + @org.junit.Test + public void testQueryWithNullPartitionResponseBasedOnNondeNode() throws Exception { + verifyPartitionResultIsNull("select * from Person where _key = 1 and _key = 2", 0); + } + + + /** + * Check that in case of non-rendezvous affinity function, client side best effort affinity is skipped. + * + * @throws Exception If failed. + */ + @org.junit.Test + public void testCacheWithNonRendezvousAffinityFunction() throws Exception { + final String cacheName = "cacheWithCustomAffinityFunction"; + + CacheConfiguration cache = prepareCacheConfig(cacheName); + cache.setAffinity(new DummyAffinity()); + + ignite(0).createCache(cache); + + fillCache(cacheName); + + verifyPartitionResultIsNull("select * from \"" + cacheName + "\".Person where _key = 1", + 1); + } + + /** + * Check that in case of custom filters, client side best effort affinity is skipped. + * + * @throws Exception If failed. + */ + @org.junit.Test + public void testCacheWithCustomNodeFilter() throws Exception { + final String cacheName = "cacheWithCustomNodeFilter"; + + CacheConfiguration cache = prepareCacheConfig(cacheName); + cache.setNodeFilter(new CustomNodeFilter()); + + ignite(0).createCache(cache); + + fillCache(cacheName); + + verifyPartitionResultIsNull("select * from \"" + cacheName + "\".Person where _key = 1", + 1); + } + + /** + * Check that best effort functionality works fine for custom partitions count. + * + * @throws Exception If failed. + */ + @org.junit.Test + public void testCacheWithRendezvousCustomPartitionsCount() throws Exception { + final String cacheName = "cacheWithRendezvousCustomPartitionsCount"; + + CacheConfiguration cache = prepareCacheConfig(cacheName); + cache.setAffinity(new RendezvousAffinityFunction(false, 10)); + + ignite(0).createCache(cache); + + fillCache(cacheName); + + checkNodesUsage(null, + "select * from \"" + cacheName + "\".Person where _key = 1", + 1, 1, false); + } + + /** + * Check that affinity cache is invalidated in case of changing topology, + * detected during partions destribution retrieval. + * + * @throws Exception If failed. + */ + @org.junit.Test + public void testChangeTopologyDetectionWithinPartitionDistributionResponse() throws Exception { + final String sqlQry = "select * from Person where _key = 1"; + + stmt.executeQuery(sqlQry); + + AffinityCache affinityCache = GridTestUtils.getFieldValue(conn, "affinityCache"); + + startGrid(3); + + stmt.executeQuery(sqlQry); + + AffinityCache recreatedAffinityCache = GridTestUtils.getFieldValue(conn, "affinityCache"); + + assertTrue(recreatedAffinityCache.version().compareTo(affinityCache.version()) > 0); + } + + /** + * Check that affinity cache is invalidated in case of changing topology, + * detected during query response retrieval. + * + * @throws Exception If failed. + */ + @org.junit.Test + public void testChangeTopologyDetectionWithinQueryExecutionResponse() throws Exception { + final String sqlQry = "select * from Person where _key = 1"; + + stmt.executeQuery(sqlQry); + stmt.executeQuery(sqlQry); + + AffinityCache affinityCache = GridTestUtils.getFieldValue(conn, "affinityCache"); + + startGrid(4); + + stmt.executeQuery("select * from Person where _key = 2"); + + AffinityCache recreatedAffinityCache = GridTestUtils.getFieldValue(conn, "affinityCache"); + + assertTrue(recreatedAffinityCache.version().compareTo(affinityCache.version()) > 0); + } + + /** + * Check that affinity cache is invalidated in case of changing topology, + * detected during best-effort-affinity-unrelated-query response retrieval. + * + * @throws Exception If failed. + */ + @org.junit.Test + public void testChangeTopologyDetectionWithinBestEffortAffinityUnrelatedQuery() throws Exception { + final String sqlQry = "select * from Person where _key = 1"; + + ResultSet rs = stmt.executeQuery(sqlQry); + + AffinityCache affinityCache = GridTestUtils.getFieldValue(conn, "affinityCache"); + + startGrid(5); + + rs.getMetaData(); + + AffinityCache recreatedAffinityCache = GridTestUtils.getFieldValue(conn, "affinityCache"); + + assertTrue(recreatedAffinityCache.version().compareTo(affinityCache.version()) > 0); + } + + /** + * Check that client side best effort affinity optimizations are skipped if bestEffortAffinity is switched off. + * + * @throws Exception If failed. + */ + @org.junit.Test + public void testBestEffortAffinityIsSkippedIfItIsSwitchedOff() throws Exception { + Connection conn = DriverManager.getConnection( + "jdbc:ignite:thin://127.0.0.1:10800..10802?bestEffortAffinityEnabled=false"); + + Statement stmt = conn.createStatement(); + + final String cacheName = "yac"; + + CacheConfiguration cache = prepareCacheConfig(cacheName); + + ignite(0).createCache(cache); + + stmt.executeQuery("select * from \"" + cacheName + "\".Person where _key = 1"); + + AffinityCache affinityCache = GridTestUtils.getFieldValue(conn, "affinityCache"); + + assertNull("Affinity cache is not null.", affinityCache); + } + + /** + * Check that affinity cache stores sql queries with their schemas. + * + * @throws Exception If failed. + */ + @org.junit.Test + public void testAffinityCacheStoresSchemaBindedQuries() throws Exception { + final String cacheName = "yacc"; + + CacheConfiguration cache = prepareCacheConfig(cacheName); + cache.setSqlSchema(cacheName); + + ignite(0).createCache(cache); + + fillCache(cacheName); + + stmt.execute("select * from \"" + cacheName.toUpperCase() + "\".Person where _key = 1"); + + conn.setSchema(cacheName.toUpperCase()); + + stmt = conn.createStatement(); + + stmt.execute("select * from \"" + cacheName.toUpperCase() + "\".Person where _key = 1"); + + AffinityCache affinityCache = GridTestUtils.getFieldValue(conn, "affinityCache"); + + GridBoundedLinkedHashMap sqlCache = + GridTestUtils.getFieldValue(affinityCache, "sqlCache"); + + Set schemas = sqlCache.keySet().stream().map(QualifiedSQLQuery::schemaName).collect(Collectors.toSet()); + + assertTrue("Affinity cache doesn't contain query sent to 'default' schema.", + schemas.contains("default")); + assertTrue("Affinity cache doesn't contain query sent to '" + cacheName.toUpperCase() + "' schema.", + schemas.contains(cacheName.toUpperCase())); + } + + /** + * Check that affinity cache stores compacted version of partitoins destributions. + * + * @throws Exception If failed. + */ + @org.junit.Test + public void testAffinityCacheCompactsPartitonDestributions() throws Exception { + final String cacheName = "yaccc"; + + CacheConfiguration cache = prepareCacheConfig(cacheName); + + ignite(0).createCache(cache); + + fillCache(cacheName); + + stmt.execute("select * from Person where _key = 2"); + stmt.execute("select * from Person where _key = 2"); + + stmt.execute("select * from \"" + cacheName + "\".Person where _key = 2"); + stmt.execute("select * from \"" + cacheName + "\".Person where _key = 2"); + + AffinityCache affinityCache = GridTestUtils.getFieldValue(conn, "affinityCache"); + + GridBoundedLinkedHashMap sqlCache = + GridTestUtils.getFieldValue(affinityCache, "sqlCache"); + + GridBoundedLinkedHashMap cachePartitionsDistribution = + GridTestUtils.getFieldValue(affinityCache, "cachePartitionsDistribution"); + + assertEquals("Sql sub-cache of affinity cache has unexpected number of elements.", + 2, sqlCache.size()); + + assertEquals("Partitions destribution sub-cache of affinity cache has unexpected number of elements.", + 2, cachePartitionsDistribution.size()); + + // Main assertition of the test: we are checking that partitions destributions for different caches + // are equal in therms of (==) + assertTrue("Partitions distributions are not the same.", + cachePartitionsDistribution.get(0) == cachePartitionsDistribution.get(1)); + } + + /** + * Check that best effort affinity works fine after reconnection. + * + * @throws Exception If failed. + */ + @org.junit.Test + public void testReconnect() throws Exception { + checkNodesUsage(null, "select * from Person where _key = 3", 1, 1, + false); + + startGrid(7); + + for(int i = 0; i < NODES_CNT; i++) + stopGrid(i); + + GridTestUtils.assertThrows(log, new Callable() { + @Override public Object call() throws Exception { + stmt.execute("select * from Person where _key = 3"); + + return null; + } + }, SQLException.class, "Failed to communicate with Ignite cluster."); + + for(int i = 0; i < NODES_CNT; i++) + startGrid(i); + + // TODO: 09.04.19 proper way to do this? + stopGrid(4); + stopGrid(5); + stopGrid(6); + stopGrid(7); + + stmt = conn.createStatement(); + + // We need this extra query to invalidate obsolete affinity cache + stmt.execute("select * from Person where _key = 3"); + + checkNodesUsage(null, "select * from Person where _key = 3", 1, 1, + false); + } + + /** + * Prepares default cache configuration with given name. + * + * @param cacheName Cache name. + * @return Cache configuration. + */ + @SuppressWarnings("unchecked") + protected CacheConfiguration prepareCacheConfig(String cacheName) { + CacheConfiguration cache = defaultCacheConfiguration(); + + cache.setName(cacheName); + cache.setCacheMode(PARTITIONED); + cache.setIndexedTypes( + Integer.class, Person.class + ); + + return cache; + } + + /** + * Utitlity method that executes given query and verifies that expeted number of records was returned. + * Besides that given method verified that partitoin result for corresponding query is null. + * + * @param sqlQry Sql query. + * @param expRowsCnt Expected rows count. + * @throws SQLException If failed. + */ + protected void verifyPartitionResultIsNull(String sqlQry, int expRowsCnt) throws SQLException { + ResultSet rs = stmt.executeQuery(sqlQry); + + assert rs != null; + + int rowCntr = 0; + + while (rs.next()) + rowCntr++; + + assertEquals("Rows counter doesn't match expected value.", expRowsCnt, rowCntr); + + AffinityCache affinityCache = GridTestUtils.getFieldValue(conn, "affinityCache"); + + PartitionResult gotPartRes = affinityCache.partitionResult( + new QualifiedSQLQuery("default", sqlQry)).partitionResult(); + + assertNull("Partition result descriptor is not null.", gotPartRes); + } + + /** + * Utility method that: + * 1. warms up an affinity cache; + * 2. resets query history; + * 3. executes given query multiple times; + * 4. checks query history metrics in order to verify that not more than expected nodes were used. + * + * @param ps Prepared statement, either prepared statement or sql query should be used. + * @param sql Sql query, either prepared statement or sql query should be used. + * @param maxNodesUsedCnt Expected maximum number of used nodes. + * @param expRowsCnt Expected rows count within result. + * @param dml Flag that signals whether we execute dml or not. + * @throws Exception If failed. + */ + private void checkNodesUsage(PreparedStatement ps, String sql, int maxNodesUsedCnt, int expRowsCnt, boolean dml) + throws Exception { + // Warm up an affinity cache. + if (ps != null) + if (dml) + ps.executeUpdate(); + else + ps.executeQuery(); + else { + if (dml) + stmt.executeUpdate(sql); + else + stmt.executeQuery(sql); + } + + // Reset query history. + for (int i = 0; i < NODES_CNT; i++) { + ((IgniteH2Indexing)grid(i).context().query().getIndexing()) + .runningQueryManager().resetQueryHistoryMetrics(); + } + + // Execute query multiple times + for (int i = 0; i < NODES_CNT * QUERY_EXECUTION_MULTIPLIER; i++) { + ResultSet rs = null; + + int updatedRowsCnt = 0; + + if (ps != null) + if (dml) + updatedRowsCnt = ps.executeUpdate(); + else + rs = ps.executeQuery(); + else { + if (dml) + updatedRowsCnt = stmt.executeUpdate(sql); + else + rs = stmt.executeQuery(sql); + } + + if (dml) { + assertEquals("Unexpected updated rows count: expected [" + expRowsCnt + "]," + + " got [" + updatedRowsCnt + "]", expRowsCnt, updatedRowsCnt); + } + else { + assert rs != null; + + int gotRowsCnt = 0; + + while (rs.next()) + gotRowsCnt++; + + assertEquals("Unexpected rows count: expected [" + expRowsCnt + "], got [" + gotRowsCnt + "]", + expRowsCnt, gotRowsCnt); + } + } + + // Check query history metrics in order to verify that not more than expected nodes were used. + int nonEmptyMetricsCntr = 0; + int qryExecutionsCntr = 0; + for (int i = 0; i < NODES_CNT; i++) { + Collection metrics = ((IgniteH2Indexing)grid(i).context().query().getIndexing()) + .runningQueryManager().queryHistoryMetrics().values(); + + if (!metrics.isEmpty()) { + nonEmptyMetricsCntr++; + qryExecutionsCntr += new ArrayList<>(metrics).get(0).executions(); + } + } + + assertTrue("Unexpected amount of used nodes: expected [0 < nodesCnt <= " + maxNodesUsedCnt + + "], got [" + nonEmptyMetricsCntr + "]", + nonEmptyMetricsCntr > 0 && nonEmptyMetricsCntr <= maxNodesUsedCnt); + + assertEquals("Executions count doesn't match expeted value: expected [" + + NODES_CNT * QUERY_EXECUTION_MULTIPLIER + "], got [" + qryExecutionsCntr + "]", + NODES_CNT * QUERY_EXECUTION_MULTIPLIER, qryExecutionsCntr); + } + + /** + * Fills cache with test data. + * + * @param cacheName Cache name. + */ + private void fillCache(String cacheName) { + IgniteCache cachePerson = grid(0).cache(cacheName); + + assert cachePerson != null; + + for (int i = 0; i < ROWS_COUNT; i++) + cachePerson.put(i, new Person(i, "John" + i, "White" + i, i + 1)); + } + + /** + * Person. + */ + @SuppressWarnings("unused") + private static class Person implements Serializable { + /** ID. */ + @QuerySqlField + private final int id; + + /** First name. */ + @QuerySqlField + private final String firstName; + + /** Last name. */ + @QuerySqlField + private final String lastName; + + /** Age. */ + @QuerySqlField + private final int age; + + /** + * @param id ID. + * @param firstName First name. + * @param lastName Last name. + * @param age Age. + */ + private Person(int id, String firstName, String lastName, int age) { + assert !F.isEmpty(firstName); + assert !F.isEmpty(lastName); + assert age > 0; + + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + this.age = age; + } + } + + /** + * Dummy affinity function. + */ + private static class DummyAffinity implements AffinityFunction { + /** {@inheritDoc} */ + @Override public void reset() { + // No-op. + } + + /** {@inheritDoc} */ + @Override public int partitions() { + return 1; + } + + /** {@inheritDoc} */ + @Override public int partition(Object key) { + return 0; + } + + /** + * Default constructor. + */ + public DummyAffinity() { + // No-op. + } + + /** {@inheritDoc} */ + @Override public List> assignPartitions(AffinityFunctionContext affCtx) { + List nodes = affCtx.currentTopologySnapshot(); + + List> assign = new ArrayList<>(partitions()); + + for (int i = 0; i < partitions(); ++i) + assign.add(Collections.singletonList(nodes.get(0))); + + return assign; + } + + /** {@inheritDoc} */ + @Override public void removeNode(UUID nodeId) { + // No-op. + } + } + + /** + * Filter that accepts all nodes. + */ + public static class CustomNodeFilter implements IgnitePredicate { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public boolean apply(ClusterNode node) { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object obj) { + return false; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return "CustomNodeFilter"; + } + } +} diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinityTransactionsSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinityTransactionsSelfTest.java index 6aa348b99e972..81da17c5f240e 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinityTransactionsSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinityTransactionsSelfTest.java @@ -39,7 +39,7 @@ */ public class JdbcThinBestEffortAffinityTransactionsSelfTest extends JdbcThinAbstractSelfTest { /** */ - private static final String URL = "jdbc:ignite:thin://127.0.0.1:10800..10802"; + private static final String URL = "jdbc:ignite:thin://127.0.0.1:10800..10802?bestEffortAffinityEnabled=true"; /** Nodes count. */ private static final int NODES_CNT = 3; @@ -129,7 +129,7 @@ private CacheConfiguration cacheConfiguration(@NotNull String name) { * @throws SQLException if failed. */ private static Connection prepareConnection(boolean autoCommit, NestedTxMode nestedTxMode) throws SQLException { - Connection res = DriverManager.getConnection(URL + "?nestedTransactionsMode=" + nestedTxMode.name()); + Connection res = DriverManager.getConnection(URL + "&nestedTransactionsMode=" + nestedTxMode.name()); res.setAutoCommit(autoCommit); From f96c9159ffdbe33b754b9ff3cea09f1903240180 Mon Sep 17 00:00:00 2001 From: sanpwc Date: Wed, 10 Apr 2019 18:15:59 +0300 Subject: [PATCH 4/8] ignite-11309 bestEffortAffinityEnabled -> affinityAwareness. --- ...ThinDriverBestEffordAffinityTestSuite.java | 2 +- .../jdbc/thin/JdbcThinAbstractSelfTest.java | 2 +- .../JdbcThinBestEffortAffinitySelfTest.java | 6 +- ...estEffortAffinityTransactionsSelfTest.java | 2 +- ...bcThinConnectionMultipleAddressesTest.java | 2 +- .../jdbc/thin/JdbcThinConnectionSelfTest.java | 57 ++++++++++--------- .../jdbc/thin/JdbcThinDataSourceSelfTest.java | 2 +- .../jdbc/thin/JdbcThinStatementSelfTest.java | 8 +-- .../jdbc/thin/ConnectionProperties.java | 8 +-- .../jdbc/thin/ConnectionPropertiesImpl.java | 18 +++--- .../jdbc/thin/JdbcThinConnection.java | 20 +++---- 11 files changed, 64 insertions(+), 63 deletions(-) diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcThinDriverBestEffordAffinityTestSuite.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcThinDriverBestEffordAffinityTestSuite.java index dbc9c4e54fd4f..0706386f6ad46 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcThinDriverBestEffordAffinityTestSuite.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcThinDriverBestEffordAffinityTestSuite.java @@ -46,6 +46,6 @@ public class IgniteJdbcThinDriverBestEffordAffinityTestSuite { */ @BeforeClass public static void setupBestEffortAffinity() { - GridTestUtils.setFieldValue(JdbcThinAbstractSelfTest.class, "bestEffortAffinity", true); + GridTestUtils.setFieldValue(JdbcThinAbstractSelfTest.class, "affinityAwareness", true); } } \ No newline at end of file diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinAbstractSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinAbstractSelfTest.java index cdfbb3fe31adb..4450be2b7d5f5 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinAbstractSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinAbstractSelfTest.java @@ -43,7 +43,7 @@ public class JdbcThinAbstractSelfTest extends GridCommonAbstractTest { /** Signals that tests should start in best effort affinity mode. */ - public static boolean bestEffortAffinity; + public static boolean affinityAwareness; /** * @param r Runnable to check support. diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java index ea3735a230026..a2b7a3a98abaa 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java @@ -59,7 +59,7 @@ @SuppressWarnings({"ThrowableNotThrown"}) public class JdbcThinBestEffortAffinitySelfTest extends JdbcThinAbstractSelfTest { /** URL. */ - private static final String URL = "jdbc:ignite:thin://127.0.0.1:10800..10802?bestEffortAffinityEnabled=true"; + private static final String URL = "jdbc:ignite:thin://127.0.0.1:10800..10802?affinityAwareness=true"; /** Nodes count. */ private static final int NODES_CNT = 3; @@ -407,14 +407,14 @@ public void testChangeTopologyDetectionWithinBestEffortAffinityUnrelatedQuery() } /** - * Check that client side best effort affinity optimizations are skipped if bestEffortAffinity is switched off. + * Check that client side best effort affinity optimizations are skipped if affinityAwareness is switched off. * * @throws Exception If failed. */ @org.junit.Test public void testBestEffortAffinityIsSkippedIfItIsSwitchedOff() throws Exception { Connection conn = DriverManager.getConnection( - "jdbc:ignite:thin://127.0.0.1:10800..10802?bestEffortAffinityEnabled=false"); + "jdbc:ignite:thin://127.0.0.1:10800..10802?affinityAwareness=false"); Statement stmt = conn.createStatement(); diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinityTransactionsSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinityTransactionsSelfTest.java index 81da17c5f240e..ab65675c74bb3 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinityTransactionsSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinityTransactionsSelfTest.java @@ -39,7 +39,7 @@ */ public class JdbcThinBestEffortAffinityTransactionsSelfTest extends JdbcThinAbstractSelfTest { /** */ - private static final String URL = "jdbc:ignite:thin://127.0.0.1:10800..10802?bestEffortAffinityEnabled=true"; + private static final String URL = "jdbc:ignite:thin://127.0.0.1:10800..10802?affinityAwareness=true"; /** Nodes count. */ private static final int NODES_CNT = 3; diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinConnectionMultipleAddressesTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinConnectionMultipleAddressesTest.java index 6aa08e8713bf6..1edae3a328f69 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinConnectionMultipleAddressesTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinConnectionMultipleAddressesTest.java @@ -535,7 +535,7 @@ private void stop(Connection conn, boolean all) { stopAllGrids(); else { - if (bestEffortAffinity) { + if (affinityAwareness) { for (int i = 0; i < NODES_CNT - 1; i++) stopGrid(i); } diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinConnectionSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinConnectionSelfTest.java index cfae903f60d74..d3c32473cad1e 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinConnectionSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinConnectionSelfTest.java @@ -85,24 +85,24 @@ public class JdbcThinConnectionSelfTest extends JdbcThinAbstractSelfTest { private static final String LOCALHOST = "127.0.0.1"; /** URL. */ - private String url = bestEffortAffinity ? + private String url = affinityAwareness ? "jdbc:ignite:thin://127.0.0.1:10800..10802" : "jdbc:ignite:thin://127.0.0.1"; /** URL with best effort affinity flag. */ private String urlWithBestEffortAffinityFlag = url + - (bestEffortAffinity ? - "?bestEffortAffinityEnabled=true" : - "?bestEffortAffinityEnabled=false"); + (affinityAwareness ? + "?affinityAwareness=true" : + "?affinityAwareness=false"); /** URL with best effort affinity flag and semicolon as delimeter. */ private String urlWithBestEffortAffinityFlagSemicolon = url + - (bestEffortAffinity ? - ";bestEffortAffinityEnabled=true" : - ";bestEffortAffinityEnabled=false"); + (affinityAwareness ? + ";affinityAwareness=true" : + ";affinityAwareness=false"); /** Nodes count. */ - private int nodesCnt = bestEffortAffinity ? 4 : 2; + private int nodesCnt = affinityAwareness ? 4 : 2; /** {@inheritDoc} */ @SuppressWarnings("deprecation") @@ -261,43 +261,44 @@ public void testSocketBuffersSemicolon() throws Exception { @Test public void testSqlHints() throws Exception { try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag)) { - assertHints(conn, false, false, false, false, false, false, bestEffortAffinity); + assertHints(conn, false, false, false, false, false, + false, affinityAwareness); } try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag + "&distributedJoins=true")) { assertHints(conn, true, false, false, false, false, - false, bestEffortAffinity); + false, affinityAwareness); } try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag + "&enforceJoinOrder=true")) { assertHints(conn, false, true, false, false, false, - false, bestEffortAffinity); + false, affinityAwareness); } try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag + "&collocated=true")) { assertHints(conn, false, false, true, false, false, - false, bestEffortAffinity); + false, affinityAwareness); } try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag + "&replicatedOnly=true")) { assertHints(conn, false, false, false, true, false, - false, bestEffortAffinity); + false, affinityAwareness); } try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag + "&lazy=true")) { assertHints(conn, false, false, false, false, true, - false, bestEffortAffinity); + false, affinityAwareness); } try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag + "&skipReducerOnUpdate=true")) { assertHints(conn, false, false, false, false, false, - true, bestEffortAffinity); + true, affinityAwareness); } try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlag + "&distributedJoins=true&" + "enforceJoinOrder=true&collocated=true&replicatedOnly=true&lazy=true&skipReducerOnUpdate=true")) { assertHints(conn, true, true, true, true, true, - true, bestEffortAffinity); + true, affinityAwareness); } } @@ -310,38 +311,38 @@ public void testSqlHints() throws Exception { public void testSqlHintsSemicolon() throws Exception { try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlagSemicolon + ";distributedJoins=true")) { assertHints(conn, true, false, false, false, false, - false, bestEffortAffinity); + false, affinityAwareness); } try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlagSemicolon + ";enforceJoinOrder=true")) { assertHints(conn, false, true, false, false, false, - false, bestEffortAffinity); + false, affinityAwareness); } try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlagSemicolon + ";collocated=true")) { assertHints(conn, false, false, true, false, false, - false, bestEffortAffinity); + false, affinityAwareness); } try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlagSemicolon + ";replicatedOnly=true")) { assertHints(conn, false, false, false, true, false, - false, bestEffortAffinity); + false, affinityAwareness); } try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlagSemicolon + ";lazy=true")) { assertHints(conn, false, false, false, false, true, - false, bestEffortAffinity); + false, affinityAwareness); } try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlagSemicolon + ";skipReducerOnUpdate=true")) { assertHints(conn, false, false, false, false, false, - true, bestEffortAffinity); + true, affinityAwareness); } try (Connection conn = DriverManager.getConnection(urlWithBestEffortAffinityFlagSemicolon + ";distributedJoins=true;" + "enforceJoinOrder=true;collocated=true;replicatedOnly=true;lazy=true;skipReducerOnUpdate=true")) { assertHints(conn, true, true, true, true, true, - true, bestEffortAffinity); + true, affinityAwareness); } } @@ -366,7 +367,7 @@ private void assertHints(Connection conn, boolean distributedJoins, boolean enfo assertEquals(replicatedOnly, io.connectionProperties().isReplicatedOnly()); assertEquals(lazy, io.connectionProperties().isLazy()); assertEquals(skipReducerOnUpdate, io.connectionProperties().isSkipReducerOnUpdate()); - assertEquals(bestEffortAffinityEnabled, io.connectionProperties().isBestEffortAffinityEnabled()); + assertEquals(bestEffortAffinityEnabled, io.connectionProperties().isAffinityAwareness()); } } @@ -587,7 +588,7 @@ public void testSchemaSemicolon() throws Exception { private static Collection ios(Connection conn) throws Exception { JdbcThinConnection conn0 = conn.unwrap(JdbcThinConnection.class); - Collection ios = bestEffortAffinity ? ((Map) + Collection ios = affinityAwareness ? ((Map) GridTestUtils.getFieldValue(conn0, JdbcThinConnection.class, "ios")).values() : Collections.singleton(GridTestUtils.getFieldValue(conn0, JdbcThinConnection.class, "singleIo")); @@ -2051,7 +2052,7 @@ public void testInvalidNestedTxModeOnServerSide() { connProps.nestedTxMode("invalid"); - connProps.setBestEffortAffinityEnabled(bestEffortAffinity); + connProps.setAffinityAwareness(affinityAwareness); GridTestUtils.assertThrows(null, new Callable() { @SuppressWarnings("ResultOfObjectAllocationIgnored") @@ -2077,9 +2078,9 @@ public void testSslClientAndPlainServer() { return null; } - }, SQLException.class, bestEffortAffinity ? "Failed to connect to server" : "Failed to SSL connect to server"); + }, SQLException.class, affinityAwareness ? "Failed to connect to server" : "Failed to SSL connect to server"); - if (bestEffortAffinity) { + if (affinityAwareness) { for (Throwable t: e.getSuppressed()) { assertEquals(SQLException.class, t.getClass()); assertTrue(t.getMessage().contains("Failed to SSL connect to server")); diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinDataSourceSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinDataSourceSelfTest.java index 86ec178c6f2a5..b2de045536435 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinDataSourceSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinDataSourceSelfTest.java @@ -283,7 +283,7 @@ public static class JndiContextMockFactory implements InitialContextFactory { private static Collection ios(Connection conn) throws Exception { JdbcThinConnection conn0 = conn.unwrap(JdbcThinConnection.class); - Collection ios = bestEffortAffinity ? ((Map) + Collection ios = affinityAwareness ? ((Map) GridTestUtils.getFieldValue(conn0, JdbcThinConnection.class, "ios")).values() : Collections.singleton(GridTestUtils.getFieldValue(conn0, JdbcThinConnection.class, "singleIo")); diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinStatementSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinStatementSelfTest.java index c321361207e4a..c319907169ea8 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinStatementSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinStatementSelfTest.java @@ -43,12 +43,12 @@ @SuppressWarnings({"ThrowableNotThrown"}) public class JdbcThinStatementSelfTest extends JdbcThinAbstractSelfTest { /** URL. */ - private String url = bestEffortAffinity ? - "jdbc:ignite:thin://127.0.0.1:10800..10802?bestEffortAffinityEnabled=true" : - "jdbc:ignite:thin://127.0.0.1?bestEffortAffinityEnabled=false"; + private String url = affinityAwareness ? + "jdbc:ignite:thin://127.0.0.1:10800..10802?affinityAwareness=true" : + "jdbc:ignite:thin://127.0.0.1?affinityAwareness=false"; /** Nodes count. */ - private int nodesCnt = bestEffortAffinity ? 4 : 3; + private int nodesCnt = affinityAwareness ? 4 : 3; /** SQL query. */ private static final String SQL = "select * from Person where age > 30"; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionProperties.java b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionProperties.java index 58e538f439e57..19fc1cd53221e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionProperties.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionProperties.java @@ -407,14 +407,14 @@ public interface ConnectionProperties { public void setDataPageScanEnabled(@Nullable Boolean dataPageScanEnabled); /** - * @return {@code True} if jdbc thin best effort affinity is enabled for this connection, + * @return {@code True} if jdbc thin affinity awareness is enabled for this connection, * {@code false} if it's disabled. */ - public boolean isBestEffortAffinityEnabled(); + public boolean isAffinityAwareness(); /** - * @param bestEffortAffinityEnabled {@code True} if jdbc thin best effort affinity is enabled + * @param affinityAwareness {@code True} if jdbc thin affinity awareness is enabled * for this connection, if {@code false} then it's disabled. */ - public void setBestEffortAffinityEnabled(boolean bestEffortAffinityEnabled); + public void setAffinityAwareness(boolean affinityAwareness); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionPropertiesImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionPropertiesImpl.java index bc3cf31a65f23..ac65b2078acab 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionPropertiesImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionPropertiesImpl.java @@ -189,10 +189,10 @@ false, new PropertyValidator() { "Whether data page scan for queries is allowed. If not specified, server defines the default behaviour.", null, false); - /** Best effort affinity flag. */ - private BooleanProperty bestEffortAffinityEnabled = new BooleanProperty( - "bestEffortAffinityEnabled", - "Whether jdbc thin best effort affinity is enabled.", + /** affinity awareness flag. */ + private BooleanProperty affinityAwareness = new BooleanProperty( + "affinityAwareness", + "Whether jdbc thin affinity awareness is enabled.", false, false); /** Properties array. */ @@ -205,7 +205,7 @@ false, new PropertyValidator() { sslTrustAll, sslFactory, user, passwd, dataPageScanEnabled, - bestEffortAffinityEnabled + affinityAwareness }; /** {@inheritDoc} */ @@ -512,13 +512,13 @@ false, new PropertyValidator() { } /** {@inheritDoc} */ - @Override public boolean isBestEffortAffinityEnabled() { - return bestEffortAffinityEnabled.value(); + @Override public boolean isAffinityAwareness() { + return affinityAwareness.value(); } /** {@inheritDoc} */ - @Override public void setBestEffortAffinityEnabled(boolean bestEffortAffinityEnabled) { - this.bestEffortAffinityEnabled.setValue(bestEffortAffinityEnabled); + @Override public void setAffinityAwareness(boolean affinityAwareness) { + this.affinityAwareness.setValue(affinityAwareness); } /** 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 4e3e07b1b845f..a841b814b7519 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 @@ -116,8 +116,8 @@ public class JdbcThinConnection implements Connection { /** Index generator. */ private static final AtomicLong IDX_GEN = new AtomicLong(); - /** Best effort affinity enabled flag. */ - private final boolean bestEffortAffinity; + /** Affinity awareness enabled flag. */ + private final boolean affinityAwareness; /** Statements modification mutex. */ private final Object stmtsMux = new Object(); @@ -205,7 +205,7 @@ public JdbcThinConnection(ConnectionProperties connProps) throws SQLException { timer = new Timer("query-timeout-timer"); - bestEffortAffinity = connProps.isBestEffortAffinityEnabled(); + affinityAwareness = connProps.isAffinityAwareness(); ensureConnected(); } @@ -225,7 +225,7 @@ private void ensureConnected() throws SQLException { HostAndPortRange[] srvs = connProps.getAddresses(); - if (bestEffortAffinity) + if (affinityAwareness) connectInBestEffortAffinityMode(srvs); else connectInCommonMode(srvs); @@ -459,7 +459,7 @@ private void doCommit() throws SQLException { closed = true; - if (bestEffortAffinity) { + if (affinityAwareness) { for (JdbcThinTcpIo clioIo : ios.values()) clioIo.close(); @@ -794,7 +794,7 @@ private void doCommit() throws SQLException { netTimeout = ms; - if (bestEffortAffinity) { + if (affinityAwareness) { for (JdbcThinTcpIo clioIo : ios.values()) clioIo.timeout(ms); } @@ -936,7 +936,7 @@ else if (res.status() != ClientListenerResponse.STATUS_SUCCESS) * @throws SQLException If Failed to calculate derived partitions. */ @Nullable private List calculateNodeIds(JdbcRequest req) throws IOException, SQLException { - if (!bestEffortAffinity || !(req instanceof JdbcQueryExecuteRequest)) + if (!affinityAwareness || !(req instanceof JdbcQueryExecuteRequest)) return null; JdbcQueryExecuteRequest qry = (JdbcQueryExecuteRequest)req; @@ -1130,7 +1130,7 @@ private void onDisconnect() { if (!connected) return; - if (bestEffortAffinity) { + if (affinityAwareness) { for (JdbcThinTcpIo clioIo : ios.values()) clioIo.close(); @@ -1397,7 +1397,7 @@ boolean isQueryCancellationSupported() { */ @SuppressWarnings("ZeroLengthArrayAllocation") private JdbcThinTcpIo cliIo(List nodeIds) { - if (!bestEffortAffinity) + if (!affinityAwareness) return singleIo; if (txIo != null) @@ -1672,7 +1672,7 @@ private class RequestTimeoutTimerTask extends TimerTask { * @param res Jdbc Response. */ private void updateAffinityCache(JdbcQueryExecuteRequest qryReq, JdbcResponse res) { - if (bestEffortAffinity) { + if (affinityAwareness) { AffinityTopologyVersion resAffVer = res.affinityVersion(); if (resAffVer != null && (affinityCache == null || affinityCache.version().compareTo(resAffVer) < 0)) From d77e99c407186e16096101ee78a6e9cd6293814f Mon Sep 17 00:00:00 2001 From: sanpwc Date: Thu, 11 Apr 2019 10:56:59 +0300 Subject: [PATCH 5/8] ignite-11309 cleanup. --- .../ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java index a2b7a3a98abaa..d30ac2732910c 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java @@ -85,8 +85,7 @@ public class JdbcThinBestEffortAffinitySelfTest extends JdbcThinAbstractSelfTest cache.setCacheMode(PARTITIONED); cache.setBackups(1); cache.setIndexedTypes( - Integer.class, Person.class, - Integer.class, Test.class + Integer.class, Person.class ); cfg.setCacheConfiguration(cache); From dd8c0db80b98cfac7450d9f753e1ec86d8b16212 Mon Sep 17 00:00:00 2001 From: sanpwc Date: Fri, 12 Apr 2019 11:35:23 +0300 Subject: [PATCH 6/8] ignite-11314 typo fixed. --- .../JdbcThinBestEffortAffinitySelfTest.java | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java index d30ac2732910c..44eca4b5727a1 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java @@ -269,7 +269,7 @@ public void testQueryWithNullPartitionResponseBasedOnAllNode() throws Exception * @throws Exception If failed. */ @org.junit.Test - public void testQueryWithNullPartitionResponseBasedOnNondeNode() throws Exception { + public void testQueryWithNullPartitionResponseBasedOnNoneNode() throws Exception { verifyPartitionResultIsNull("select * from Person where _key = 1 and _key = 2", 0); } @@ -549,6 +549,48 @@ public void testReconnect() throws Exception { false); } + /** + * Check that + * + * @throws Exception If failed. + */ + @org.junit.Test + public void test1() throws Exception { + // Reset query history. + for (int i = 0; i < NODES_CNT; i++) { + ((IgniteH2Indexing)grid(i).context().query().getIndexing()) + .runningQueryManager().resetQueryHistoryMetrics(); + } + + stmt.setFetchSize(1); + + ResultSet rs = stmt.executeQuery("select * from Person where _key = 1"); +// ResultSet rs = stmt.executeQuery("select 1 union all select 1 union all select 1 union all select 1 union all select 1;"); +// +// while (rs.next()); + + // Check query history metrics in order to verify that not more than expected nodes were used. + int nonEmptyMetricsCntr = 0; + int qryExecutionsCntr = 0; + for (int i = 0; i < NODES_CNT; i++) { + Collection metrics = ((IgniteH2Indexing)grid(i).context().query().getIndexing()) + .runningQueryManager().queryHistoryMetrics().values(); + + if (!metrics.isEmpty()) { + nonEmptyMetricsCntr++; + qryExecutionsCntr += new ArrayList<>(metrics).get(0).executions(); + } + } + + assertTrue("Unexpected amount of used nodes: expected [0 < nodesCnt <= " + 1 + + "], got [" + nonEmptyMetricsCntr + "]", + nonEmptyMetricsCntr > 0 && nonEmptyMetricsCntr <= 1); + +// assertEquals("Executions count doesn't match expeted value: expected [" + +// NODES_CNT * QUERY_EXECUTION_MULTIPLIER + "], got [" + qryExecutionsCntr + "]", +// NODES_CNT * QUERY_EXECUTION_MULTIPLIER, qryExecutionsCntr); + } + /** * Prepares default cache configuration with given name. * From ef93be32353ef0ee866745e7cb33c7d99b41cfd0 Mon Sep 17 00:00:00 2001 From: sanpwc Date: Fri, 12 Apr 2019 11:58:09 +0300 Subject: [PATCH 7/8] ignite-11314 test checking default behaviour of affinity awareness added. --- .../JdbcThinBestEffortAffinitySelfTest.java | 67 +++++++------------ 1 file changed, 25 insertions(+), 42 deletions(-) diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java index 44eca4b5727a1..fd2218a2a50bd 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java @@ -430,6 +430,31 @@ public void testBestEffortAffinityIsSkippedIfItIsSwitchedOff() throws Exception assertNull("Affinity cache is not null.", affinityCache); } + /** + * Check that client side best effort affinity optimizations are skipped by default. + * + * @throws Exception If failed. + */ + @org.junit.Test + public void testBestEffortAffinityIsSkippedByDefault() throws Exception { + Connection conn = DriverManager.getConnection( + "jdbc:ignite:thin://127.0.0.1:10800..10802"); + + Statement stmt = conn.createStatement(); + + final String cacheName = "yacccc"; + + CacheConfiguration cache = prepareCacheConfig(cacheName); + + ignite(0).createCache(cache); + + stmt.executeQuery("select * from \"" + cacheName + "\".Person where _key = 1"); + + AffinityCache affinityCache = GridTestUtils.getFieldValue(conn, "affinityCache"); + + assertNull("Affinity cache is not null.", affinityCache); + } + /** * Check that affinity cache stores sql queries with their schemas. * @@ -549,48 +574,6 @@ public void testReconnect() throws Exception { false); } - /** - * Check that - * - * @throws Exception If failed. - */ - @org.junit.Test - public void test1() throws Exception { - // Reset query history. - for (int i = 0; i < NODES_CNT; i++) { - ((IgniteH2Indexing)grid(i).context().query().getIndexing()) - .runningQueryManager().resetQueryHistoryMetrics(); - } - - stmt.setFetchSize(1); - - ResultSet rs = stmt.executeQuery("select * from Person where _key = 1"); -// ResultSet rs = stmt.executeQuery("select 1 union all select 1 union all select 1 union all select 1 union all select 1;"); -// -// while (rs.next()); - - // Check query history metrics in order to verify that not more than expected nodes were used. - int nonEmptyMetricsCntr = 0; - int qryExecutionsCntr = 0; - for (int i = 0; i < NODES_CNT; i++) { - Collection metrics = ((IgniteH2Indexing)grid(i).context().query().getIndexing()) - .runningQueryManager().queryHistoryMetrics().values(); - - if (!metrics.isEmpty()) { - nonEmptyMetricsCntr++; - qryExecutionsCntr += new ArrayList<>(metrics).get(0).executions(); - } - } - - assertTrue("Unexpected amount of used nodes: expected [0 < nodesCnt <= " + 1 + - "], got [" + nonEmptyMetricsCntr + "]", - nonEmptyMetricsCntr > 0 && nonEmptyMetricsCntr <= 1); - -// assertEquals("Executions count doesn't match expeted value: expected [" + -// NODES_CNT * QUERY_EXECUTION_MULTIPLIER + "], got [" + qryExecutionsCntr + "]", -// NODES_CNT * QUERY_EXECUTION_MULTIPLIER, qryExecutionsCntr); - } - /** * Prepares default cache configuration with given name. * From 09e6b7c3fe97145bdf218d4e498340d697f7e74a Mon Sep 17 00:00:00 2001 From: sanpwc Date: Wed, 17 Apr 2019 18:48:14 +0300 Subject: [PATCH 8/8] ignite-11309 changes based on code review; --- .../JdbcThinBestEffortAffinitySelfTest.java | 95 +++++++++++-------- ...estEffortAffinityTransactionsSelfTest.java | 7 +- .../jdbc/thin/JdbcThinConnectionSelfTest.java | 10 +- .../jdbc/thin/ConnectionProperties.java | 8 +- 4 files changed, 66 insertions(+), 54 deletions(-) diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java index fd2218a2a50bd..5916d0da4b9ea 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinitySelfTest.java @@ -48,8 +48,10 @@ import org.apache.ignite.internal.sql.optimizer.affinity.PartitionResult; import org.apache.ignite.internal.util.GridBoundedLinkedHashMap; import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgnitePredicate; import org.apache.ignite.testframework.GridTestUtils; +import org.junit.Test; import static org.apache.ignite.cache.CacheMode.PARTITIONED; @@ -116,11 +118,7 @@ public class JdbcThinBestEffortAffinitySelfTest extends JdbcThinAbstractSelfTest /** {@inheritDoc} */ @Override protected void afterTest() throws Exception { - if (stmt != null && !stmt.isClosed()) { - stmt.close(); - - assert stmt.isClosed(); - } + U.closeQuiet(stmt); conn.close(); @@ -133,7 +131,7 @@ public class JdbcThinBestEffortAffinitySelfTest extends JdbcThinAbstractSelfTest * * @throws Exception If failed. */ - @org.junit.Test + @Test public void testExecuteQueries() throws Exception { checkNodesUsage(null, "select * from Person where _key = 1", 1, 1, false); @@ -150,20 +148,31 @@ public void testExecuteQueries() throws Exception { * * @throws Exception If failed. */ - @org.junit.Test + @Test public void testExecuteParametrizedQueries() throws Exception { + // Use case 1. PreparedStatement ps = conn.prepareStatement("select * from Person where _key = ?"); + ps.setInt(1, 2); + checkNodesUsage(ps, null, 1, 1, false); + // Use case 2. ps = conn.prepareStatement("select * from Person where _key = ? or _key = ?"); + ps.setInt(1, 1); + ps.setInt(2, 2); + checkNodesUsage(ps, null, 2, 2, false); + // Use case 3. ps = conn.prepareStatement("select * from Person where _key in (?, ?)"); + ps.setInt(1, 1); + ps.setInt(2, 2); + checkNodesUsage(ps, null, 2, 2, false); } @@ -172,7 +181,7 @@ public void testExecuteParametrizedQueries() throws Exception { * * @throws Exception If failed. */ - @org.junit.Test + @Test public void testUpdateQueries() throws Exception { checkNodesUsage(null, "update Person set firstName = 'TestFirstName' where _key = 1", 1, 1, true); @@ -189,25 +198,33 @@ public void testUpdateQueries() throws Exception { * * @throws Exception If failed. */ - @org.junit.Test + @Test public void testUpdateParametrizedQueries() throws Exception { + // Use case 1. PreparedStatement ps = conn.prepareStatement( "update Person set firstName = 'TestFirstName' where _key = ?"); + ps.setInt(1, 2); - checkNodesUsage(ps, null, - 1, 1, true); + checkNodesUsage(ps, null, 1, 1, true); + + // Use case 2. ps = conn.prepareStatement("update Person set firstName = 'TestFirstName' where _key = ? or _key = ?"); + ps.setInt(1, 1); + ps.setInt(2, 2); - checkNodesUsage(ps, null, - 2, 2, true); + checkNodesUsage(ps, null, 2, 2, true); + + // Use case 3. ps = conn.prepareStatement("update Person set firstName = 'TestFirstName' where _key in (?, ?)"); + ps.setInt(1, 1); + ps.setInt(2, 2); - checkNodesUsage(ps, null, - 2, 2, true); + + checkNodesUsage(ps, null, 2, 2, true); } /** @@ -215,7 +232,7 @@ public void testUpdateParametrizedQueries() throws Exception { * * @throws Exception If failed. */ - @org.junit.Test + @Test public void testDeleteQueries() throws Exception { // In case of simple query like "delete from Person where _key = 1" fast update logic is used, // so parition result is not calculated on the server side - nothing to check. @@ -232,23 +249,28 @@ public void testDeleteQueries() throws Exception { * * @throws Exception If failed. */ - @org.junit.Test + @Test public void testDeleteParametrizedQueries() throws Exception { // In case of simple query like "delete from Person where _key = ?" fast update logic is used, // so parition result is not calculated on the server side - nothing to check. - PreparedStatement ps = conn.prepareStatement( - "delete from Person where _key = ? or _key = ?"); + // Use case 1. + PreparedStatement ps = conn.prepareStatement("delete from Person where _key = ? or _key = ?"); + ps.setInt(1, 1000); + ps.setInt(2, 2000); - checkNodesUsage(ps, null, - 2, 0, true); + checkNodesUsage(ps, null, 2, 0, true); + + // Use case 2. ps = conn.prepareStatement("delete from Person where _key in (?, ?)"); + ps.setInt(1, 1000); + ps.setInt(2, 2000); - checkNodesUsage(ps, null, - 2, 0, true); + + checkNodesUsage(ps, null, 2, 0, true); } /** @@ -257,7 +279,7 @@ public void testDeleteParametrizedQueries() throws Exception { * * @throws Exception If failed. */ - @org.junit.Test + @Test public void testQueryWithNullPartitionResponseBasedOnAllNode() throws Exception { verifyPartitionResultIsNull("select * from Person where age > 15", 85); } @@ -268,7 +290,7 @@ public void testQueryWithNullPartitionResponseBasedOnAllNode() throws Exception * * @throws Exception If failed. */ - @org.junit.Test + @Test public void testQueryWithNullPartitionResponseBasedOnNoneNode() throws Exception { verifyPartitionResultIsNull("select * from Person where _key = 1 and _key = 2", 0); } @@ -279,7 +301,7 @@ public void testQueryWithNullPartitionResponseBasedOnNoneNode() throws Exception * * @throws Exception If failed. */ - @org.junit.Test + @Test public void testCacheWithNonRendezvousAffinityFunction() throws Exception { final String cacheName = "cacheWithCustomAffinityFunction"; @@ -299,7 +321,7 @@ public void testCacheWithNonRendezvousAffinityFunction() throws Exception { * * @throws Exception If failed. */ - @org.junit.Test + @Test public void testCacheWithCustomNodeFilter() throws Exception { final String cacheName = "cacheWithCustomNodeFilter"; @@ -319,7 +341,7 @@ public void testCacheWithCustomNodeFilter() throws Exception { * * @throws Exception If failed. */ - @org.junit.Test + @Test public void testCacheWithRendezvousCustomPartitionsCount() throws Exception { final String cacheName = "cacheWithRendezvousCustomPartitionsCount"; @@ -341,7 +363,7 @@ public void testCacheWithRendezvousCustomPartitionsCount() throws Exception { * * @throws Exception If failed. */ - @org.junit.Test + @Test public void testChangeTopologyDetectionWithinPartitionDistributionResponse() throws Exception { final String sqlQry = "select * from Person where _key = 1"; @@ -364,7 +386,7 @@ public void testChangeTopologyDetectionWithinPartitionDistributionResponse() thr * * @throws Exception If failed. */ - @org.junit.Test + @Test public void testChangeTopologyDetectionWithinQueryExecutionResponse() throws Exception { final String sqlQry = "select * from Person where _key = 1"; @@ -388,7 +410,7 @@ public void testChangeTopologyDetectionWithinQueryExecutionResponse() throws Exc * * @throws Exception If failed. */ - @org.junit.Test + @Test public void testChangeTopologyDetectionWithinBestEffortAffinityUnrelatedQuery() throws Exception { final String sqlQry = "select * from Person where _key = 1"; @@ -410,7 +432,7 @@ public void testChangeTopologyDetectionWithinBestEffortAffinityUnrelatedQuery() * * @throws Exception If failed. */ - @org.junit.Test + @Test public void testBestEffortAffinityIsSkippedIfItIsSwitchedOff() throws Exception { Connection conn = DriverManager.getConnection( "jdbc:ignite:thin://127.0.0.1:10800..10802?affinityAwareness=false"); @@ -435,7 +457,7 @@ public void testBestEffortAffinityIsSkippedIfItIsSwitchedOff() throws Exception * * @throws Exception If failed. */ - @org.junit.Test + @Test public void testBestEffortAffinityIsSkippedByDefault() throws Exception { Connection conn = DriverManager.getConnection( "jdbc:ignite:thin://127.0.0.1:10800..10802"); @@ -460,7 +482,7 @@ public void testBestEffortAffinityIsSkippedByDefault() throws Exception { * * @throws Exception If failed. */ - @org.junit.Test + @Test public void testAffinityCacheStoresSchemaBindedQuries() throws Exception { final String cacheName = "yacc"; @@ -497,7 +519,7 @@ public void testAffinityCacheStoresSchemaBindedQuries() throws Exception { * * @throws Exception If failed. */ - @org.junit.Test + @Test public void testAffinityCacheCompactsPartitonDestributions() throws Exception { final String cacheName = "yaccc"; @@ -538,7 +560,7 @@ public void testAffinityCacheCompactsPartitonDestributions() throws Exception { * * @throws Exception If failed. */ - @org.junit.Test + @Test public void testReconnect() throws Exception { checkNodesUsage(null, "select * from Person where _key = 3", 1, 1, false); @@ -559,7 +581,6 @@ public void testReconnect() throws Exception { for(int i = 0; i < NODES_CNT; i++) startGrid(i); - // TODO: 09.04.19 proper way to do this? stopGrid(4); stopGrid(5); stopGrid(6); diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinityTransactionsSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinityTransactionsSelfTest.java index 71b78e506206b..85290f3c6ce72 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinityTransactionsSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinBestEffortAffinityTransactionsSelfTest.java @@ -31,6 +31,7 @@ import org.apache.ignite.internal.processors.query.NestedTxMode; import org.apache.ignite.internal.processors.query.QueryHistoryMetrics; import org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing; +import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.testframework.GridStringLogger; import org.jetbrains.annotations.NotNull; import org.junit.Test; @@ -103,11 +104,7 @@ private CacheConfiguration cacheConfiguration(@NotNull String name) { /** {@inheritDoc} */ @Override protected void afterTest() throws Exception { - if (stmt != null && !stmt.isClosed()) { - stmt.close(); - - assert stmt.isClosed(); - } + U.closeQuiet(stmt); conn.close(); diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinConnectionSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinConnectionSelfTest.java index d3c32473cad1e..bcae0b4243749 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinConnectionSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinConnectionSelfTest.java @@ -90,16 +90,10 @@ public class JdbcThinConnectionSelfTest extends JdbcThinAbstractSelfTest { "jdbc:ignite:thin://127.0.0.1"; /** URL with best effort affinity flag. */ - private String urlWithBestEffortAffinityFlag = url + - (affinityAwareness ? - "?affinityAwareness=true" : - "?affinityAwareness=false"); + private String urlWithBestEffortAffinityFlag = url + "?affinityAwareness=" + affinityAwareness; /** URL with best effort affinity flag and semicolon as delimeter. */ - private String urlWithBestEffortAffinityFlagSemicolon = url + - (affinityAwareness ? - ";affinityAwareness=true" : - ";affinityAwareness=false"); + private String urlWithBestEffortAffinityFlagSemicolon = url + ";affinityAwareness=" + affinityAwareness; /** Nodes count. */ private int nodesCnt = affinityAwareness ? 4 : 2; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionProperties.java b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionProperties.java index 19fc1cd53221e..400bf8e2db7e0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionProperties.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/ConnectionProperties.java @@ -395,25 +395,25 @@ public interface ConnectionProperties { public String getPassword(); /** - * @return {@code True} if data page scan support is enabled for this connection, {@code false} if it's disabled + * @return {@code true} if data page scan support is enabled for this connection, {@code false} if it's disabled * and {@code null} for server default. */ @Nullable public Boolean isDataPageScanEnabled(); /** - * @param dataPageScanEnabled {@code True} if data page scan support is enabled for this connection, + * @param dataPageScanEnabled {@code true} if data page scan support is enabled for this connection, * if {@code false} then it's disabled, if {@code null} then server should use its default settings. */ public void setDataPageScanEnabled(@Nullable Boolean dataPageScanEnabled); /** - * @return {@code True} if jdbc thin affinity awareness is enabled for this connection, + * @return {@code true} if jdbc thin affinity awareness is enabled for this connection, * {@code false} if it's disabled. */ public boolean isAffinityAwareness(); /** - * @param affinityAwareness {@code True} if jdbc thin affinity awareness is enabled + * @param affinityAwareness {@code true} if jdbc thin affinity awareness is enabled * for this connection, if {@code false} then it's disabled. */ public void setAffinityAwareness(boolean affinityAwareness);