Skip to content

Commit

Permalink
IGNITE-18719 Deprecate SqlFieldsQuery#lazy and set default to true. (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
nizhikov authored Feb 13, 2023
1 parent 7ea9539 commit 9a82419
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ public void testJdbcV2InitiatorId() throws Exception {
final UUID grid0NodeId = grid(0).cluster().localNode().id();

GridTestUtils.runAsync(() -> {
try (Connection conn = DriverManager.getConnection(
CFG_URL_PREFIX + "nodeId=" + grid0NodeId + "@modules/clients/src/test/config/jdbc-security-config.xml")) {
try (Connection conn = DriverManager.getConnection(CFG_URL_PREFIX + "lazy=false:nodeId="
+ grid0NodeId + "@modules/clients/src/test/config/jdbc-security-config.xml")) {
try (Statement stmt = conn.createStatement()) {
stmt.execute(sql);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.junit.Test;

import static org.apache.ignite.IgniteJdbcDriver.CFG_URL_PREFIX;
import static org.apache.ignite.cache.query.SqlFieldsQuery.DFLT_LAZY;

/**
* Connection test.
Expand Down Expand Up @@ -269,7 +270,7 @@ public void testSqlHints() throws Exception {
assertTrue(((JdbcConnection)conn).isEnforceJoinOrder());
assertFalse(((JdbcConnection)conn).isDistributedJoins());
assertFalse(((JdbcConnection)conn).isCollocatedQuery());
assertFalse(((JdbcConnection)conn).isLazy());
assertEquals(DFLT_LAZY, ((JdbcConnection)conn).isLazy());
assertFalse(((JdbcConnection)conn).skipReducerOnUpdate());
}

Expand All @@ -278,7 +279,7 @@ public void testSqlHints() throws Exception {
assertFalse(((JdbcConnection)conn).isEnforceJoinOrder());
assertTrue(((JdbcConnection)conn).isDistributedJoins());
assertFalse(((JdbcConnection)conn).isCollocatedQuery());
assertFalse(((JdbcConnection)conn).isLazy());
assertEquals(DFLT_LAZY, ((JdbcConnection)conn).isLazy());
assertFalse(((JdbcConnection)conn).skipReducerOnUpdate());
}

Expand All @@ -287,23 +288,23 @@ public void testSqlHints() throws Exception {
assertFalse(((JdbcConnection)conn).isEnforceJoinOrder());
assertFalse(((JdbcConnection)conn).isDistributedJoins());
assertTrue(((JdbcConnection)conn).isCollocatedQuery());
assertFalse(((JdbcConnection)conn).isLazy());
assertEquals(DFLT_LAZY, ((JdbcConnection)conn).isLazy());
assertFalse(((JdbcConnection)conn).skipReducerOnUpdate());
}

try (final Connection conn = DriverManager.getConnection(CFG_URL_PREFIX + "lazy=true@" + configURL())) {
try (final Connection conn = DriverManager.getConnection(CFG_URL_PREFIX + "lazy=" + (!DFLT_LAZY) + "@" + configURL())) {
assertFalse(((JdbcConnection)conn).isEnforceJoinOrder());
assertFalse(((JdbcConnection)conn).isDistributedJoins());
assertFalse(((JdbcConnection)conn).isCollocatedQuery());
assertTrue(((JdbcConnection)conn).isLazy());
assertEquals(!DFLT_LAZY, ((JdbcConnection)conn).isLazy());
assertFalse(((JdbcConnection)conn).skipReducerOnUpdate());
}
try (final Connection conn = DriverManager.getConnection(CFG_URL_PREFIX + "skipReducerOnUpdate=true@"
+ configURL())) {
assertFalse(((JdbcConnection)conn).isEnforceJoinOrder());
assertFalse(((JdbcConnection)conn).isDistributedJoins());
assertFalse(((JdbcConnection)conn).isCollocatedQuery());
assertFalse(((JdbcConnection)conn).isLazy());
assertEquals(DFLT_LAZY, ((JdbcConnection)conn).isLazy());
assertTrue(((JdbcConnection)conn).skipReducerOnUpdate());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import static java.sql.ResultSet.TYPE_FORWARD_ONLY;
import static java.sql.Statement.NO_GENERATED_KEYS;
import static java.sql.Statement.RETURN_GENERATED_KEYS;
import static org.apache.ignite.cache.query.SqlFieldsQuery.DFLT_LAZY;
import static org.apache.ignite.configuration.ClientConnectorConfiguration.DFLT_PORT;
import static org.apache.ignite.internal.processors.odbc.SqlStateCode.TRANSACTION_STATE_EXCEPTION;
import static org.apache.ignite.testframework.GridTestUtils.assertThrows;
Expand Down Expand Up @@ -386,43 +387,43 @@ public void testPartitionAwarenessPartitionDistributionsCacheSizePropertySemicol
@Test
public void testSqlHints() throws Exception {
try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
assertHints(conn, false, false, false, false, false,
assertHints(conn, false, false, false, false, DFLT_LAZY,
false, partitionAwareness);
}

try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp + "&distributedJoins=true")) {
assertHints(conn, true, false, false, false, false,
assertHints(conn, true, false, false, false, DFLT_LAZY,
false, partitionAwareness);
}

try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp + "&enforceJoinOrder=true")) {
assertHints(conn, false, true, false, false, false,
assertHints(conn, false, true, false, false, DFLT_LAZY,
false, partitionAwareness);
}

try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp + "&collocated=true")) {
assertHints(conn, false, false, true, false, false,
assertHints(conn, false, false, true, false, DFLT_LAZY,
false, partitionAwareness);
}

try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp + "&replicatedOnly=true")) {
assertHints(conn, false, false, false, true, false,
assertHints(conn, false, false, false, true, DFLT_LAZY,
false, partitionAwareness);
}

try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp + "&lazy=true")) {
assertHints(conn, false, false, false, false, true,
try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp + "&lazy=" + (!DFLT_LAZY))) {
assertHints(conn, false, false, false, false, !DFLT_LAZY,
false, partitionAwareness);
}

try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp + "&skipReducerOnUpdate=true")) {
assertHints(conn, false, false, false, false, false,
assertHints(conn, false, false, false, false, DFLT_LAZY,
true, partitionAwareness);
}

try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp + "&distributedJoins=true&" +
"enforceJoinOrder=true&collocated=true&replicatedOnly=true&lazy=true&skipReducerOnUpdate=true")) {
assertHints(conn, true, true, true, true, true,
"enforceJoinOrder=true&collocated=true&replicatedOnly=true&lazy=" + (!DFLT_LAZY) + "&skipReducerOnUpdate=true")) {
assertHints(conn, true, true, true, true, !DFLT_LAZY,
true, partitionAwareness);
}
}
Expand All @@ -435,38 +436,38 @@ public void testSqlHints() throws Exception {
@Test
public void testSqlHintsSemicolon() throws Exception {
try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessPropSemicolon + ";distributedJoins=true")) {
assertHints(conn, true, false, false, false, false,
assertHints(conn, true, false, false, false, DFLT_LAZY,
false, partitionAwareness);
}

try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessPropSemicolon + ";enforceJoinOrder=true")) {
assertHints(conn, false, true, false, false, false,
assertHints(conn, false, true, false, false, DFLT_LAZY,
false, partitionAwareness);
}

try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessPropSemicolon + ";collocated=true")) {
assertHints(conn, false, false, true, false, false,
assertHints(conn, false, false, true, false, DFLT_LAZY,
false, partitionAwareness);
}

try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessPropSemicolon + ";replicatedOnly=true")) {
assertHints(conn, false, false, false, true, false,
assertHints(conn, false, false, false, true, DFLT_LAZY,
false, partitionAwareness);
}

try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessPropSemicolon + ";lazy=true")) {
assertHints(conn, false, false, false, false, true,
try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessPropSemicolon + ";lazy=" + (!DFLT_LAZY))) {
assertHints(conn, false, false, false, false, !DFLT_LAZY,
false, partitionAwareness);
}

try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessPropSemicolon + ";skipReducerOnUpdate=true")) {
assertHints(conn, false, false, false, false, false,
assertHints(conn, false, false, false, false, DFLT_LAZY,
true, partitionAwareness);
}

try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessPropSemicolon + ";distributedJoins=true;" +
"enforceJoinOrder=true;collocated=true;replicatedOnly=true;lazy=true;skipReducerOnUpdate=true")) {
assertHints(conn, true, true, true, true, true,
"enforceJoinOrder=true;collocated=true;replicatedOnly=true;lazy=" + (!DFLT_LAZY) + ";skipReducerOnUpdate=true")) {
assertHints(conn, true, true, true, true, !DFLT_LAZY,
true, partitionAwareness);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo;
import org.apache.ignite.testframework.GridTestUtils;
import org.junit.Test;
import static org.apache.ignite.cache.query.SqlFieldsQuery.DFLT_LAZY;

/**
* DataSource test.
Expand Down Expand Up @@ -132,15 +133,15 @@ public void testUrlCompose() throws Exception {
public void testResetUrl() throws Exception {
IgniteJdbcThinDataSource ids = new IgniteJdbcThinDataSource();

ids.setUrl("jdbc:ignite:thin://127.0.0.1:10800/test?lazy=true");
ids.setUrl("jdbc:ignite:thin://127.0.0.1:10800/test?lazy=" + (!DFLT_LAZY));

assertEquals("test", ids.getSchema());
assertTrue(ids.isLazy());
assertEquals(!DFLT_LAZY, ids.isLazy());

ids.setUrl("jdbc:ignite:thin://mydomain.org,localhost?collocated=true");

assertNull(ids.getSchema());
assertFalse(ids.isLazy());
assertEquals(DFLT_LAZY, ids.isLazy());
assertTrue(ids.isCollocated());
}

Expand All @@ -159,7 +160,7 @@ public void testSqlHints() throws Exception {
assertFalse(io.connectionProperties().isAutoCloseServerCursor());
assertFalse(io.connectionProperties().isCollocated());
assertFalse(io.connectionProperties().isEnforceJoinOrder());
assertFalse(io.connectionProperties().isLazy());
assertEquals(DFLT_LAZY, io.connectionProperties().isLazy());
assertFalse(io.connectionProperties().isDistributedJoins());
assertFalse(io.connectionProperties().isReplicatedOnly());
}
Expand All @@ -168,7 +169,7 @@ public void testSqlHints() throws Exception {
ids.setAutoCloseServerCursor(true);
ids.setCollocated(true);
ids.setEnforceJoinOrder(true);
ids.setLazy(true);
ids.setLazy(!DFLT_LAZY);
ids.setDistributedJoins(true);
ids.setReplicatedOnly(true);

Expand All @@ -178,7 +179,7 @@ public void testSqlHints() throws Exception {
assertTrue(io.connectionProperties().isAutoCloseServerCursor());
assertTrue(io.connectionProperties().isCollocated());
assertTrue(io.connectionProperties().isEnforceJoinOrder());
assertTrue(io.connectionProperties().isLazy());
assertEquals(!DFLT_LAZY, io.connectionProperties().isLazy());
assertTrue(io.connectionProperties().isDistributedJoins());
assertTrue(io.connectionProperties().isReplicatedOnly());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ private void checkStateAfterQuery0(String schema) {
assertFalse(listener(grid(0)).distributedJoin);
assertFalse(listener(grid(1)).distributedJoin);

assertFalse(listener(grid(0)).lazy);
assertFalse(listener(grid(1)).lazy);
assertTrue(listener(grid(0)).lazy);
assertTrue(listener(grid(1)).lazy);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class SqlFieldsQuery extends Query<List<?>> {

/** Do not remove. For tests only. */
@SuppressWarnings("NonConstantFieldWithUpperCaseName")
private static boolean DFLT_LAZY;
public static boolean DFLT_LAZY = true;

/** SQL Query. */
private String sql;
Expand All @@ -83,7 +83,10 @@ public class SqlFieldsQuery extends Query<List<?>> {
/** */
private boolean replicatedOnly;

/** Lazy mode is default since Ignite v.2.8. */
/**
* Lazy mode is default since Ignite v.2.8.
* @deprecated Use {@link #setPageSize(int)} instead.
*/
private boolean lazy = DFLT_LAZY;

/** Partitions for query */
Expand Down Expand Up @@ -322,18 +325,19 @@ public boolean isReplicatedOnly() {
/**
* Sets lazy query execution flag.
* <p>
* By default Ignite attempts to fetch the whole query result set to memory and send it to the client. For small
* If {@code lazy=false} Ignite will attempt to fetch the whole query result set to memory and send it to the client. For small
* and medium result sets this provides optimal performance and minimize duration of internal database locks, thus
* increasing concurrency.
* <p>
* If result set is too big to fit in available memory this could lead to excessive GC pauses and even
* OutOfMemoryError. Use this flag as a hint for Ignite to fetch result set lazily, thus minimizing memory
* {@link OutOfMemoryError}. Use this flag as a hint for Ignite to fetch result set lazily, thus minimizing memory
* consumption at the cost of moderate performance hit.
* <p>
* Defaults to {@code false}, meaning that the whole result set is fetched to memory eagerly.
* Defaults to {@code true}, meaning that the only first page of result set is fetched to memory.
*
* @param lazy Lazy query execution flag.
* @return {@code this} For chaining.
* @deprecated Use {@link #setPageSize(int)} instead.
*/
public SqlFieldsQuery setLazy(boolean lazy) {
this.lazy = lazy;
Expand All @@ -347,6 +351,7 @@ public SqlFieldsQuery setLazy(boolean lazy) {
* See {@link #setLazy(boolean)} for more information.
*
* @return Lazy flag.
* @deprecated Use {@link #getPageSize()} instead.
*/
public boolean isLazy() {
return lazy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.ignite.internal.util.HostAndPortRange;
import org.apache.ignite.internal.util.typedef.F;
import org.jetbrains.annotations.Nullable;
import static org.apache.ignite.cache.query.SqlFieldsQuery.DFLT_LAZY;

/**
* Holds JDBC connection properties.
Expand Down Expand Up @@ -86,7 +87,7 @@ public class ConnectionPropertiesImpl implements ConnectionProperties, Serializa

/** Lazy query execution property. */
private BooleanProperty lazy = new BooleanProperty(
"lazy", "Enable lazy query execution", false, false);
"lazy", "Enable lazy query execution", DFLT_LAZY, false);

/** Socket send buffer size property. */
private IntegerProperty socketSendBuffer = new IntegerProperty(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
import static org.apache.ignite.IgniteJdbcDriver.PROP_STREAMING_PER_NODE_BUF_SIZE;
import static org.apache.ignite.IgniteJdbcDriver.PROP_STREAMING_PER_NODE_PAR_OPS;
import static org.apache.ignite.IgniteJdbcDriver.PROP_TX_ALLOWED;
import static org.apache.ignite.cache.query.SqlFieldsQuery.DFLT_LAZY;
import static org.apache.ignite.internal.jdbc2.JdbcUtils.convertToSqlException;
import static org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode.createJdbcSqlException;

Expand Down Expand Up @@ -223,7 +224,7 @@ public JdbcConnection(String url, Properties props) throws SQLException {
collocatedQry = Boolean.parseBoolean(props.getProperty(PROP_COLLOCATED));
distributedJoins = Boolean.parseBoolean(props.getProperty(PROP_DISTRIBUTED_JOINS));
enforceJoinOrder = Boolean.parseBoolean(props.getProperty(PROP_ENFORCE_JOIN_ORDER));
lazy = Boolean.parseBoolean(props.getProperty(PROP_LAZY));
lazy = Boolean.parseBoolean(props.getProperty(PROP_LAZY, String.valueOf(DFLT_LAZY)));
txAllowed = Boolean.parseBoolean(props.getProperty(PROP_TX_ALLOWED));

stream = Boolean.parseBoolean(props.getProperty(PROP_STREAMING));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.ignite.testsuites;

import org.apache.ignite.cache.query.SqlFieldsQuery;
import org.apache.ignite.internal.processors.cache.AffinityAliasKeyTest;
import org.apache.ignite.internal.processors.cache.AffinityKeyNameAndValueFieldNameConflictTest;
import org.apache.ignite.internal.processors.cache.CacheOffheapBatchIndexingMultiTypeTest;
Expand Down Expand Up @@ -154,6 +155,8 @@
import org.apache.ignite.sqltests.PartitionedSqlTest;
import org.apache.ignite.sqltests.ReplicatedSqlCustomPartitionsTest;
import org.apache.ignite.sqltests.ReplicatedSqlTest;
import org.apache.ignite.testframework.GridTestUtils;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

Expand Down Expand Up @@ -338,4 +341,9 @@

})
public class IgniteBinaryCacheQueryTestSuite {
/** Setup lazy mode default. */
@BeforeClass
public static void setupLazy() {
GridTestUtils.setFieldValue(SqlFieldsQuery.class, "DFLT_LAZY", false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.ignite.testsuites;

import org.apache.ignite.cache.query.SqlFieldsQuery;
import org.apache.ignite.internal.processors.cache.CacheScanPartitionQueryFallbackSelfTest;
import org.apache.ignite.internal.processors.cache.IgniteCacheCrossCacheJoinRandomTest;
import org.apache.ignite.internal.processors.cache.IgniteCacheObjectKeyIndexingSelfTest;
Expand Down Expand Up @@ -62,6 +63,8 @@
import org.apache.ignite.internal.processors.query.SqlTwoCachesInGroupWithSameEntryTest;
import org.apache.ignite.internal.processors.query.WrongQueryEntityFieldTypeTest;
import org.apache.ignite.internal.processors.query.timeout.DefaultQueryTimeoutTestSuite;
import org.apache.ignite.testframework.GridTestUtils;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

Expand Down Expand Up @@ -137,4 +140,9 @@

})
public class IgniteBinaryCacheQueryTestSuite2 {
/** Setup lazy mode default. */
@BeforeClass
public static void setupLazy() {
GridTestUtils.setFieldValue(SqlFieldsQuery.class, "DFLT_LAZY", false);
}
}
Loading

0 comments on commit 9a82419

Please sign in to comment.