From 6c19e393d1abbaf3d22a4f20c544148dd40d35bc Mon Sep 17 00:00:00 2001 From: Vladimir Steshin Date: Tue, 14 Jan 2025 02:18:11 +0300 Subject: [PATCH 01/15] fails --- .../index/CreateTableIfNotExistsSelfTest.java | 176 ++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/CreateTableIfNotExistsSelfTest.java diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/CreateTableIfNotExistsSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/CreateTableIfNotExistsSelfTest.java new file mode 100644 index 0000000000000..dc985a0b76029 --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/CreateTableIfNotExistsSelfTest.java @@ -0,0 +1,176 @@ +package org.apache.ignite.internal.processors.cache.index; + +import java.util.Arrays; +import java.util.List; +import org.apache.ignite.Ignition; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.DataRegionConfiguration; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.junit.Test; + +import static org.apache.ignite.configuration.DataPageEvictionMode.RANDOM_2_LRU; + +/** Tests for CREATE TABLE IF NOT EXISTS */ +public class CreateTableIfNotExistsSelfTest extends AbstractSchemaSelfTest { + /** Node to restart id. */ + private static final int NODE_TO_RESTART_ID = 2; + + /** Client node index. */ + private static final int CLIENT_ID = 3; + + /** */ + private static final String TEST_CACHE_NAME = "SQL_PUBLIC_DMSOPERATIONAMOUNTATTRIBUTE"; + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + for (IgniteConfiguration cfg : configurations()) + Ignition.start(cfg); + + client().addCacheConfiguration(cacheConfiguration()); + client().getOrCreateCache(cacheConfiguration()); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + execute("DROP TABLE IF EXISTS PUBLIC.SQL_PUBLIC_DMSOPERATIONAMOUNTATTRIBUTE"); + + super.afterTest(); + } + + /** + * Test that attempting to {@code CREATE TABLE} that already exists does not yield an error if the statement + * contains {@code IF NOT EXISTS} clause. + */ + @Test + public void testCreateTableIfNotExists() throws Exception { + execute( + "CREATE TABLE IF NOT EXISTS DmsOperationAmountAttribute " + + "(objectId VARCHAR PRIMARY KEY, version BIGINT, dateTime TIMESTAMP, amount DECIMAL, " + + "currencyAmount DECIMAL, currency VARCHAR, decision INT, serviceCode VARCHAR, channel VARCHAR, " + + "payerId VARCHAR, payerTin VARCHAR, receiverId VARCHAR, receiverTin VARCHAR, receiverAccount VARCHAR, " + + "payerAccount VARCHAR) " + + "WITH \"VALUE_TYPE=ru.sbrf.pprb.compliance.database.entities.cumulative.DmsOperationAmountAttribute, " + + "CACHE_NAME=SQL_PUBLIC_DMSOPERATIONAMOUNTATTRIBUTE, " + + "BACKUPS=1, " + + "WRITE_SYNCHRONIZATION_MODE=PRIMARY_SYNC\"" + ); + + execute("SELECT * FROM PUBLIC.DMSOPERATIONAMOUNTATTRIBUTE"); + + restartNode(NODE_TO_RESTART_ID); + +// execute( +// "CREATE TABLE IF NOT EXISTS DmsOperationAmountAttribute " + +// "(objectId VARCHAR PRIMARY KEY, version BIGINT, dateTime TIMESTAMP, amount DECIMAL, " + +// "currencyAmount DECIMAL, currency VARCHAR, decision INT, serviceCode VARCHAR, channel VARCHAR, " + +// "payerId VARCHAR, payerTin VARCHAR, receiverId VARCHAR, receiverTin VARCHAR, receiverAccount VARCHAR, " + +// "payerAccount VARCHAR) " + +// "WITH \"VALUE_TYPE=ru.sbrf.pprb.compliance.database.entities.cumulative.DmsOperationAmountAttribute, " + +// "CACHE_NAME=SQL_PUBLIC_DMSOPERATIONAMOUNTATTRIBUTE, " + +// "BACKUPS=1, " + +// "WRITE_SYNCHRONIZATION_MODE=PRIMARY_SYNC\"" +// ); + + Thread.sleep(1000); + + execute("SELECT * FROM PUBLIC.DMSOPERATIONAMOUNTATTRIBUTE"); + } + + /** + * Execute DDL statement on client node. + * + * @param sql Statement. + */ + private void execute(String sql) { + execute(client(), sql); + } + + /** + * @return Client node. + */ + private IgniteEx client() { + return grid(CLIENT_ID); + } + + /** + * @param idx Index. + */ + private void restartNode(int idx) throws Exception { + grid(idx).close(); + + Ignition.start(serverConfiguration(idx)); + } + + /** + * Get configurations to be used in test. + * + * @return Configurations. + * @throws Exception If failed. + */ + private List configurations() throws Exception { + return Arrays.asList( + serverConfiguration(0), + serverConfiguration(1), + serverConfiguration(2), + clientConfiguration(3) + ); + } + + /** + * Create server configuration. + * + * @param idx Index. + * @return Configuration. + * @throws Exception If failed. + */ + private IgniteConfiguration serverConfiguration(int idx) throws Exception { + IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(idx)); + + DataRegionConfiguration dataRegionConfiguration = new DataRegionConfiguration() + .setName("default") + .setPersistenceEnabled(false) + .setMetricsEnabled(true) + .setCdcEnabled(true) + .setPageEvictionMode(RANDOM_2_LRU); + + cfg.setDataStorageConfiguration(new DataStorageConfiguration() + .setDefaultDataRegionConfiguration(dataRegionConfiguration)); + + cfg.setCacheConfiguration(cacheConfiguration()); + + return cfg; + } + + /** + * Create client configuration. + * + * @param idx Index. + * @return Configuration. + * @throws Exception If failed. + */ + private IgniteConfiguration clientConfiguration(int idx) throws Exception { + return commonConfiguration(idx).setClientMode(true); + } + + /** + * @return Cache configuration. + */ + private CacheConfiguration cacheConfiguration() { + CacheConfiguration ccfg = new CacheConfiguration<>(TEST_CACHE_NAME); + + ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); + ccfg.setBackups(1); + ccfg.setCacheMode(CacheMode.PARTITIONED); + ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.PRIMARY_SYNC); + ccfg.setStatisticsEnabled(true); + + return ccfg; + } +} \ No newline at end of file From 2d174d75145bfea24d8f7381b9a378ce97349fcf Mon Sep 17 00:00:00 2001 From: Vladimir Steshin Date: Tue, 14 Jan 2025 02:24:03 +0300 Subject: [PATCH 02/15] fails2 --- .../cache/index/CreateTableIfNotExistsSelfTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/CreateTableIfNotExistsSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/CreateTableIfNotExistsSelfTest.java index dc985a0b76029..407ff26931ab2 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/CreateTableIfNotExistsSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/CreateTableIfNotExistsSelfTest.java @@ -21,7 +21,7 @@ public class CreateTableIfNotExistsSelfTest extends AbstractSchemaSelfTest { private static final int NODE_TO_RESTART_ID = 2; /** Client node index. */ - private static final int CLIENT_ID = 3; + private static final int CLIENT_ID = 1; /** */ private static final String TEST_CACHE_NAME = "SQL_PUBLIC_DMSOPERATIONAMOUNTATTRIBUTE"; @@ -33,8 +33,8 @@ public class CreateTableIfNotExistsSelfTest extends AbstractSchemaSelfTest { for (IgniteConfiguration cfg : configurations()) Ignition.start(cfg); - client().addCacheConfiguration(cacheConfiguration()); - client().getOrCreateCache(cacheConfiguration()); + //client().addCacheConfiguration(cacheConfiguration()); + //client().getOrCreateCache(cacheConfiguration()); } /** {@inheritDoc} */ From 40f0d930b8116ac875fcc474ae9d39be156e23c1 Mon Sep 17 00:00:00 2001 From: Vladimir Steshin Date: Tue, 14 Jan 2025 14:46:51 +0300 Subject: [PATCH 03/15] research --- .../index/CreateTableIfNotExistsSelfTest.java | 45 ++++++++++++------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/CreateTableIfNotExistsSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/CreateTableIfNotExistsSelfTest.java index 407ff26931ab2..f18655315bc69 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/CreateTableIfNotExistsSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/CreateTableIfNotExistsSelfTest.java @@ -6,6 +6,7 @@ import org.apache.ignite.cache.CacheAtomicityMode; import org.apache.ignite.cache.CacheMode; import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.cluster.ClusterState; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.DataRegionConfiguration; import org.apache.ignite.configuration.DataStorageConfiguration; @@ -26,10 +27,14 @@ public class CreateTableIfNotExistsSelfTest extends AbstractSchemaSelfTest { /** */ private static final String TEST_CACHE_NAME = "SQL_PUBLIC_DMSOPERATIONAMOUNTATTRIBUTE"; + public static volatile boolean TEST; + /** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { super.beforeTest(); + cleanPersistenceDir(); + for (IgniteConfiguration cfg : configurations()) Ignition.start(cfg); @@ -39,7 +44,7 @@ public class CreateTableIfNotExistsSelfTest extends AbstractSchemaSelfTest { /** {@inheritDoc} */ @Override protected void afterTest() throws Exception { - execute("DROP TABLE IF EXISTS PUBLIC.SQL_PUBLIC_DMSOPERATIONAMOUNTATTRIBUTE"); + execute("DROP TABLE IF EXISTS PUBLIC." + TEST_CACHE_NAME); super.afterTest(); } @@ -50,6 +55,8 @@ public class CreateTableIfNotExistsSelfTest extends AbstractSchemaSelfTest { */ @Test public void testCreateTableIfNotExists() throws Exception { + grid(0).cluster().state(ClusterState.ACTIVE); + execute( "CREATE TABLE IF NOT EXISTS DmsOperationAmountAttribute " + "(objectId VARCHAR PRIMARY KEY, version BIGINT, dateTime TIMESTAMP, amount DECIMAL, " + @@ -57,14 +64,16 @@ public void testCreateTableIfNotExists() throws Exception { "payerId VARCHAR, payerTin VARCHAR, receiverId VARCHAR, receiverTin VARCHAR, receiverAccount VARCHAR, " + "payerAccount VARCHAR) " + "WITH \"VALUE_TYPE=ru.sbrf.pprb.compliance.database.entities.cumulative.DmsOperationAmountAttribute, " + - "CACHE_NAME=SQL_PUBLIC_DMSOPERATIONAMOUNTATTRIBUTE, " + + "CACHE_NAME=" + TEST_CACHE_NAME + ", " + "BACKUPS=1, " + "WRITE_SYNCHRONIZATION_MODE=PRIMARY_SYNC\"" ); execute("SELECT * FROM PUBLIC.DMSOPERATIONAMOUNTATTRIBUTE"); - restartNode(NODE_TO_RESTART_ID); + TEST = true; + + restartNode(NODE_TO_RESTART_ID, false); // execute( // "CREATE TABLE IF NOT EXISTS DmsOperationAmountAttribute " + @@ -78,9 +87,14 @@ public void testCreateTableIfNotExists() throws Exception { // "WRITE_SYNCHRONIZATION_MODE=PRIMARY_SYNC\"" // ); - Thread.sleep(1000); + //Thread.sleep(1000); - execute("SELECT * FROM PUBLIC.DMSOPERATIONAMOUNTATTRIBUTE"); + for (int i = 0; i < 10; ++i) { + execute("INSERT INTO DMSOPERATIONAMOUNTATTRIBUTE VALUES('" + i + "', 1, null, null, null, null, null, null, null, null, " + + "null, null, null, null, null)"); + } + + execute("SELECT * FROM DMSOPERATIONAMOUNTATTRIBUTE"); } /** @@ -102,10 +116,10 @@ private IgniteEx client() { /** * @param idx Index. */ - private void restartNode(int idx) throws Exception { + private void restartNode(int idx, boolean includeCaches) throws Exception { grid(idx).close(); - Ignition.start(serverConfiguration(idx)); + Ignition.start(serverConfiguration(idx, includeCaches)); } /** @@ -116,10 +130,10 @@ private void restartNode(int idx) throws Exception { */ private List configurations() throws Exception { return Arrays.asList( - serverConfiguration(0), - serverConfiguration(1), - serverConfiguration(2), - clientConfiguration(3) + serverConfiguration(0, true), + serverConfiguration(1, true), + serverConfiguration(2, true) + //clientConfiguration(3) ); } @@ -130,7 +144,7 @@ private List configurations() throws Exception { * @return Configuration. * @throws Exception If failed. */ - private IgniteConfiguration serverConfiguration(int idx) throws Exception { + private IgniteConfiguration serverConfiguration(int idx, boolean includeCaches) throws Exception { IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(idx)); DataRegionConfiguration dataRegionConfiguration = new DataRegionConfiguration() @@ -143,7 +157,8 @@ private IgniteConfiguration serverConfiguration(int idx) throws Exception { cfg.setDataStorageConfiguration(new DataStorageConfiguration() .setDefaultDataRegionConfiguration(dataRegionConfiguration)); - cfg.setCacheConfiguration(cacheConfiguration()); +// if(includeCaches) +// cfg.setCacheConfiguration(cacheConfiguration()); return cfg; } @@ -166,10 +181,10 @@ private IgniteConfiguration clientConfiguration(int idx) throws Exception { CacheConfiguration ccfg = new CacheConfiguration<>(TEST_CACHE_NAME); ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); - ccfg.setBackups(1); + ccfg.setBackups(2); ccfg.setCacheMode(CacheMode.PARTITIONED); ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.PRIMARY_SYNC); - ccfg.setStatisticsEnabled(true); + //ccfg.setStatisticsEnabled(true); return ccfg; } From e3cdb3dafd374362354fc7c5ae27d0246dfd338f Mon Sep 17 00:00:00 2001 From: Vladimir Steshin Date: Thu, 16 Jan 2025 14:18:50 +0300 Subject: [PATCH 04/15] raw --- ...istentNodeRestartsWithDynamicSQLTable.java | 179 ++++++++++++++++ .../processors/cache/ClusterCachesInfo.java | 2 +- .../processors/query/QuerySchema.java | 1 + .../index/CreateTableIfNotExistsSelfTest.java | 191 ------------------ 4 files changed, 181 insertions(+), 192 deletions(-) create mode 100644 modules/calcite/src/test/java/org/apache/ignite/internal/processors/TestNonPersistentNodeRestartsWithDynamicSQLTable.java delete mode 100644 modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/CreateTableIfNotExistsSelfTest.java diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/TestNonPersistentNodeRestartsWithDynamicSQLTable.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/TestNonPersistentNodeRestartsWithDynamicSQLTable.java new file mode 100644 index 0000000000000..f94507c57a41e --- /dev/null +++ b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/TestNonPersistentNodeRestartsWithDynamicSQLTable.java @@ -0,0 +1,179 @@ +package org.apache.ignite.internal.processors; + +import java.util.List; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cluster.ClusterState; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.DataRegionConfiguration; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.util.typedef.G; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.Test; + +/** */ +public class TestNonPersistentNodeRestartsWithDynamicSQLTable extends GridCommonAbstractTest { + /** */ + private static final int NODES_CNT = 3; + + /** */ + private static final int NODE_TO_RESTART_ID = 1; + + /** */ + private static final int EXEC_NODE_ID = 2; + + /** */ + private static final String TEST_CACHE_NAME = "TEST_CACHE"; + + /** */ + private static volatile boolean TEST; + + /** */ + private boolean persistence; + + /** */ + private int backups = 2; + + /** */ + private boolean predefineCaches = true; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + // Enable persistence, make the cluster ACTIVe at the start and the test will work. + DataRegionConfiguration dataRegionConfiguration = new DataRegionConfiguration() + .setName("default") + .setPersistenceEnabled(persistence); + + cfg.setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(dataRegionConfiguration)); + + // Or comment this ant the test will also work. + if (predefineCaches) + cfg.setCacheConfiguration(cacheConfiguration()); + + return cfg; + } + + /** */ + private CacheConfiguration cacheConfiguration() { + CacheConfiguration ccfg = new CacheConfiguration<>(TEST_CACHE_NAME); + + ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); + ccfg.setBackups(backups); + ccfg.setCacheMode(CacheMode.PARTITIONED); + ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.PRIMARY_SYNC); + + return ccfg; + } + + /** */ + @Test + public void testChangeCacheConfig() throws Exception { + startGrid(0); + startGrid(1); + startGrid(2); + + backups = 1; + + stopGrid(2); + + awaitPartitionMapExchange(); + + TEST = true; + + startGrid(2); + } + + /** */ + @Test + public void testChangeSchema() throws Exception { + persistence = true; + predefineCaches = false; + + startGrids(NODES_CNT); + + grid(0).cluster().state(ClusterState.ACTIVE); + + query("CREATE TABLE IF NOT EXISTS TEST_TBL(ID INTEGER PRIMARY KEY, VAL VARCHAR) WITH \"CACHE_NAME=" + TEST_CACHE_NAME + '"'); + + assertEquals(0, query("SELECT * FROM TEST_TBL").size()); + + stopGrid(0); + stopGrid(1); + + //grid(2).destroyCache(TEST_CACHE_NAME); + query("DROP TABLE TEST_TBL"); + assertNull(grid(2).cache(TEST_CACHE_NAME)); + + query("CREATE TABLE IF NOT EXISTS TEST_TBL(ID INTEGER PRIMARY KEY, VAL VARCHAR, VAL2 DOUBLE) WITH \"CACHE_NAME=" + TEST_CACHE_NAME + '"'); + + assertEquals(0, query("SELECT * FROM TEST_TBL").size()); + + stopGrid(2); + + startGrid(0); + startGrid(1); + grid(0).cluster().state(ClusterState.ACTIVE); + + assertEquals(0, query("SELECT * FROM TEST_TBL", 1).size()); + } + + /** */ + @Test + public void testNodeRejoinsAndUsesTheTable() throws Exception { + startGrids(NODES_CNT); + + query("CREATE TABLE IF NOT EXISTS TEST_TBL(ID INTEGER PRIMARY KEY, VAL VARCHAR) WITH \"CACHE_NAME=" + TEST_CACHE_NAME + '"'); + + assertEquals(0, query("SELECT * FROM TEST_TBL").size()); + + TEST = true; + + stopGrid(NODE_TO_RESTART_ID); + startGrid(NODE_TO_RESTART_ID); + + // Btw, comment `awaitPartitionMapExchange()` and the inserts to prevent failure with 'table not found'. + awaitPartitionMapExchange(); + + // Inserts works. + for (int i = 0; i < 100; ++i) + assertEquals(1, query("INSERT INTO TEST_TBL VALUES(" + (i + 1) + ", '" + (i + 1000) + "')").size()); + + assertEquals(100, grid(EXEC_NODE_ID).cache(TEST_CACHE_NAME).size()); + + //Thread.sleep(1000); + + // Failes with 'table not found'. + assertEquals(100, query("SELECT * FROM TEST_TBL").size()); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + G.stopAll(false); + + cleanPersistenceDir(); + + super.afterTest(); + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + cleanPersistenceDir(); + } + + /** */ + private List> query(String sql, int nodeIdx) { + return grid(nodeIdx).context().query().querySqlFields(new SqlFieldsQuery(sql).setSchema("PUBLIC"), true).getAll(); + } + + /** */ + private List> query(String sql) { + return query(sql, EXEC_NODE_ID); + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java index a2c04e8e5cab8..940825ea0b026 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java @@ -1840,7 +1840,7 @@ private void initStartCachesForLocalJoin(boolean firstNode, boolean reconnect) { nearCfg = locCfg.cacheData().config().getNearConfiguration(); DynamicCacheDescriptor desc0 = new DynamicCacheDescriptor(ctx, - locCfg.cacheData().config(), + desc.cacheConfiguration(), desc.cacheType(), desc.groupDescriptor(), desc.template(), diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java index adc92e019a77d..9878e7755a002 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java @@ -41,6 +41,7 @@ import org.apache.ignite.internal.processors.query.schema.operation.SchemaIndexDropOperation; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.internal.S; +import org.jetbrains.annotations.Nullable; /** * Dynamic cache schema. diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/CreateTableIfNotExistsSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/CreateTableIfNotExistsSelfTest.java deleted file mode 100644 index f18655315bc69..0000000000000 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/CreateTableIfNotExistsSelfTest.java +++ /dev/null @@ -1,191 +0,0 @@ -package org.apache.ignite.internal.processors.cache.index; - -import java.util.Arrays; -import java.util.List; -import org.apache.ignite.Ignition; -import org.apache.ignite.cache.CacheAtomicityMode; -import org.apache.ignite.cache.CacheMode; -import org.apache.ignite.cache.CacheWriteSynchronizationMode; -import org.apache.ignite.cluster.ClusterState; -import org.apache.ignite.configuration.CacheConfiguration; -import org.apache.ignite.configuration.DataRegionConfiguration; -import org.apache.ignite.configuration.DataStorageConfiguration; -import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.internal.IgniteEx; -import org.junit.Test; - -import static org.apache.ignite.configuration.DataPageEvictionMode.RANDOM_2_LRU; - -/** Tests for CREATE TABLE IF NOT EXISTS */ -public class CreateTableIfNotExistsSelfTest extends AbstractSchemaSelfTest { - /** Node to restart id. */ - private static final int NODE_TO_RESTART_ID = 2; - - /** Client node index. */ - private static final int CLIENT_ID = 1; - - /** */ - private static final String TEST_CACHE_NAME = "SQL_PUBLIC_DMSOPERATIONAMOUNTATTRIBUTE"; - - public static volatile boolean TEST; - - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - super.beforeTest(); - - cleanPersistenceDir(); - - for (IgniteConfiguration cfg : configurations()) - Ignition.start(cfg); - - //client().addCacheConfiguration(cacheConfiguration()); - //client().getOrCreateCache(cacheConfiguration()); - } - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - execute("DROP TABLE IF EXISTS PUBLIC." + TEST_CACHE_NAME); - - super.afterTest(); - } - - /** - * Test that attempting to {@code CREATE TABLE} that already exists does not yield an error if the statement - * contains {@code IF NOT EXISTS} clause. - */ - @Test - public void testCreateTableIfNotExists() throws Exception { - grid(0).cluster().state(ClusterState.ACTIVE); - - execute( - "CREATE TABLE IF NOT EXISTS DmsOperationAmountAttribute " + - "(objectId VARCHAR PRIMARY KEY, version BIGINT, dateTime TIMESTAMP, amount DECIMAL, " + - "currencyAmount DECIMAL, currency VARCHAR, decision INT, serviceCode VARCHAR, channel VARCHAR, " + - "payerId VARCHAR, payerTin VARCHAR, receiverId VARCHAR, receiverTin VARCHAR, receiverAccount VARCHAR, " + - "payerAccount VARCHAR) " + - "WITH \"VALUE_TYPE=ru.sbrf.pprb.compliance.database.entities.cumulative.DmsOperationAmountAttribute, " + - "CACHE_NAME=" + TEST_CACHE_NAME + ", " + - "BACKUPS=1, " + - "WRITE_SYNCHRONIZATION_MODE=PRIMARY_SYNC\"" - ); - - execute("SELECT * FROM PUBLIC.DMSOPERATIONAMOUNTATTRIBUTE"); - - TEST = true; - - restartNode(NODE_TO_RESTART_ID, false); - -// execute( -// "CREATE TABLE IF NOT EXISTS DmsOperationAmountAttribute " + -// "(objectId VARCHAR PRIMARY KEY, version BIGINT, dateTime TIMESTAMP, amount DECIMAL, " + -// "currencyAmount DECIMAL, currency VARCHAR, decision INT, serviceCode VARCHAR, channel VARCHAR, " + -// "payerId VARCHAR, payerTin VARCHAR, receiverId VARCHAR, receiverTin VARCHAR, receiverAccount VARCHAR, " + -// "payerAccount VARCHAR) " + -// "WITH \"VALUE_TYPE=ru.sbrf.pprb.compliance.database.entities.cumulative.DmsOperationAmountAttribute, " + -// "CACHE_NAME=SQL_PUBLIC_DMSOPERATIONAMOUNTATTRIBUTE, " + -// "BACKUPS=1, " + -// "WRITE_SYNCHRONIZATION_MODE=PRIMARY_SYNC\"" -// ); - - //Thread.sleep(1000); - - for (int i = 0; i < 10; ++i) { - execute("INSERT INTO DMSOPERATIONAMOUNTATTRIBUTE VALUES('" + i + "', 1, null, null, null, null, null, null, null, null, " + - "null, null, null, null, null)"); - } - - execute("SELECT * FROM DMSOPERATIONAMOUNTATTRIBUTE"); - } - - /** - * Execute DDL statement on client node. - * - * @param sql Statement. - */ - private void execute(String sql) { - execute(client(), sql); - } - - /** - * @return Client node. - */ - private IgniteEx client() { - return grid(CLIENT_ID); - } - - /** - * @param idx Index. - */ - private void restartNode(int idx, boolean includeCaches) throws Exception { - grid(idx).close(); - - Ignition.start(serverConfiguration(idx, includeCaches)); - } - - /** - * Get configurations to be used in test. - * - * @return Configurations. - * @throws Exception If failed. - */ - private List configurations() throws Exception { - return Arrays.asList( - serverConfiguration(0, true), - serverConfiguration(1, true), - serverConfiguration(2, true) - //clientConfiguration(3) - ); - } - - /** - * Create server configuration. - * - * @param idx Index. - * @return Configuration. - * @throws Exception If failed. - */ - private IgniteConfiguration serverConfiguration(int idx, boolean includeCaches) throws Exception { - IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(idx)); - - DataRegionConfiguration dataRegionConfiguration = new DataRegionConfiguration() - .setName("default") - .setPersistenceEnabled(false) - .setMetricsEnabled(true) - .setCdcEnabled(true) - .setPageEvictionMode(RANDOM_2_LRU); - - cfg.setDataStorageConfiguration(new DataStorageConfiguration() - .setDefaultDataRegionConfiguration(dataRegionConfiguration)); - -// if(includeCaches) -// cfg.setCacheConfiguration(cacheConfiguration()); - - return cfg; - } - - /** - * Create client configuration. - * - * @param idx Index. - * @return Configuration. - * @throws Exception If failed. - */ - private IgniteConfiguration clientConfiguration(int idx) throws Exception { - return commonConfiguration(idx).setClientMode(true); - } - - /** - * @return Cache configuration. - */ - private CacheConfiguration cacheConfiguration() { - CacheConfiguration ccfg = new CacheConfiguration<>(TEST_CACHE_NAME); - - ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); - ccfg.setBackups(2); - ccfg.setCacheMode(CacheMode.PARTITIONED); - ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.PRIMARY_SYNC); - //ccfg.setStatisticsEnabled(true); - - return ccfg; - } -} \ No newline at end of file From c72ec2e9c09069b6cccfafe2d27a4be075904bdf Mon Sep 17 00:00:00 2001 From: Vladimir Steshin Date: Thu, 16 Jan 2025 15:02:33 +0300 Subject: [PATCH 05/15] raw --- .../org/apache/ignite/internal/processors/query/QuerySchema.java | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java index 9878e7755a002..adc92e019a77d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java @@ -41,7 +41,6 @@ import org.apache.ignite.internal.processors.query.schema.operation.SchemaIndexDropOperation; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.internal.S; -import org.jetbrains.annotations.Nullable; /** * Dynamic cache schema. From ddd4565a674b969dd3f3863df8feba51be5eb13d Mon Sep 17 00:00:00 2001 From: Vladimir Steshin Date: Thu, 16 Jan 2025 19:57:35 +0300 Subject: [PATCH 06/15] raw --- ...istentNodeRestartsWithDynamicSQLTable.java | 179 ------------------ .../integration/TableDdlIntegrationTest.java | 66 +++++++ 2 files changed, 66 insertions(+), 179 deletions(-) delete mode 100644 modules/calcite/src/test/java/org/apache/ignite/internal/processors/TestNonPersistentNodeRestartsWithDynamicSQLTable.java diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/TestNonPersistentNodeRestartsWithDynamicSQLTable.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/TestNonPersistentNodeRestartsWithDynamicSQLTable.java deleted file mode 100644 index f94507c57a41e..0000000000000 --- a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/TestNonPersistentNodeRestartsWithDynamicSQLTable.java +++ /dev/null @@ -1,179 +0,0 @@ -package org.apache.ignite.internal.processors; - -import java.util.List; -import org.apache.ignite.cache.CacheAtomicityMode; -import org.apache.ignite.cache.CacheMode; -import org.apache.ignite.cache.CacheWriteSynchronizationMode; -import org.apache.ignite.cache.query.SqlFieldsQuery; -import org.apache.ignite.cluster.ClusterState; -import org.apache.ignite.configuration.CacheConfiguration; -import org.apache.ignite.configuration.DataRegionConfiguration; -import org.apache.ignite.configuration.DataStorageConfiguration; -import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.internal.util.typedef.G; -import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; -import org.junit.Test; - -/** */ -public class TestNonPersistentNodeRestartsWithDynamicSQLTable extends GridCommonAbstractTest { - /** */ - private static final int NODES_CNT = 3; - - /** */ - private static final int NODE_TO_RESTART_ID = 1; - - /** */ - private static final int EXEC_NODE_ID = 2; - - /** */ - private static final String TEST_CACHE_NAME = "TEST_CACHE"; - - /** */ - private static volatile boolean TEST; - - /** */ - private boolean persistence; - - /** */ - private int backups = 2; - - /** */ - private boolean predefineCaches = true; - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); - - // Enable persistence, make the cluster ACTIVe at the start and the test will work. - DataRegionConfiguration dataRegionConfiguration = new DataRegionConfiguration() - .setName("default") - .setPersistenceEnabled(persistence); - - cfg.setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(dataRegionConfiguration)); - - // Or comment this ant the test will also work. - if (predefineCaches) - cfg.setCacheConfiguration(cacheConfiguration()); - - return cfg; - } - - /** */ - private CacheConfiguration cacheConfiguration() { - CacheConfiguration ccfg = new CacheConfiguration<>(TEST_CACHE_NAME); - - ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); - ccfg.setBackups(backups); - ccfg.setCacheMode(CacheMode.PARTITIONED); - ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.PRIMARY_SYNC); - - return ccfg; - } - - /** */ - @Test - public void testChangeCacheConfig() throws Exception { - startGrid(0); - startGrid(1); - startGrid(2); - - backups = 1; - - stopGrid(2); - - awaitPartitionMapExchange(); - - TEST = true; - - startGrid(2); - } - - /** */ - @Test - public void testChangeSchema() throws Exception { - persistence = true; - predefineCaches = false; - - startGrids(NODES_CNT); - - grid(0).cluster().state(ClusterState.ACTIVE); - - query("CREATE TABLE IF NOT EXISTS TEST_TBL(ID INTEGER PRIMARY KEY, VAL VARCHAR) WITH \"CACHE_NAME=" + TEST_CACHE_NAME + '"'); - - assertEquals(0, query("SELECT * FROM TEST_TBL").size()); - - stopGrid(0); - stopGrid(1); - - //grid(2).destroyCache(TEST_CACHE_NAME); - query("DROP TABLE TEST_TBL"); - assertNull(grid(2).cache(TEST_CACHE_NAME)); - - query("CREATE TABLE IF NOT EXISTS TEST_TBL(ID INTEGER PRIMARY KEY, VAL VARCHAR, VAL2 DOUBLE) WITH \"CACHE_NAME=" + TEST_CACHE_NAME + '"'); - - assertEquals(0, query("SELECT * FROM TEST_TBL").size()); - - stopGrid(2); - - startGrid(0); - startGrid(1); - grid(0).cluster().state(ClusterState.ACTIVE); - - assertEquals(0, query("SELECT * FROM TEST_TBL", 1).size()); - } - - /** */ - @Test - public void testNodeRejoinsAndUsesTheTable() throws Exception { - startGrids(NODES_CNT); - - query("CREATE TABLE IF NOT EXISTS TEST_TBL(ID INTEGER PRIMARY KEY, VAL VARCHAR) WITH \"CACHE_NAME=" + TEST_CACHE_NAME + '"'); - - assertEquals(0, query("SELECT * FROM TEST_TBL").size()); - - TEST = true; - - stopGrid(NODE_TO_RESTART_ID); - startGrid(NODE_TO_RESTART_ID); - - // Btw, comment `awaitPartitionMapExchange()` and the inserts to prevent failure with 'table not found'. - awaitPartitionMapExchange(); - - // Inserts works. - for (int i = 0; i < 100; ++i) - assertEquals(1, query("INSERT INTO TEST_TBL VALUES(" + (i + 1) + ", '" + (i + 1000) + "')").size()); - - assertEquals(100, grid(EXEC_NODE_ID).cache(TEST_CACHE_NAME).size()); - - //Thread.sleep(1000); - - // Failes with 'table not found'. - assertEquals(100, query("SELECT * FROM TEST_TBL").size()); - } - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - G.stopAll(false); - - cleanPersistenceDir(); - - super.afterTest(); - } - - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - super.beforeTest(); - - cleanPersistenceDir(); - } - - /** */ - private List> query(String sql, int nodeIdx) { - return grid(nodeIdx).context().query().querySqlFields(new SqlFieldsQuery(sql).setSchema("PUBLIC"), true).getAll(); - } - - /** */ - private List> query(String sql) { - return query(sql, EXEC_NODE_ID); - } -} diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDdlIntegrationTest.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDdlIntegrationTest.java index 98ce8275f2111..8ac1b2ff917f1 100644 --- a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDdlIntegrationTest.java +++ b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDdlIntegrationTest.java @@ -34,6 +34,8 @@ import org.apache.ignite.cache.CacheWriteSynchronizationMode; import org.apache.ignite.cache.QueryEntity; import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.DataRegionConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.processors.cache.IgniteInternalCache; import org.apache.ignite.internal.processors.query.IgniteSQLException; import org.apache.ignite.internal.processors.query.QueryUtils; @@ -57,6 +59,33 @@ /** */ public class TableDdlIntegrationTest extends AbstractDdlIntegrationTest { + /** */ + private boolean persistence = true; + + /** */ + private int nodesCnt = 1; + + /** */ + private CacheConfiguration[] cacheConfigurations; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + for (DataRegionConfiguration drCfg : cfg.getDataStorageConfiguration().getDataRegionConfigurations()) + drCfg.setPersistenceEnabled(persistence); + + if (!F.isEmpty(cacheConfigurations)) + cfg.setCacheConfiguration(cacheConfigurations); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected int nodeCount() { + return nodesCnt; + } + /** * Creates table with two columns, where the first column is PK, * and verifies created cache. @@ -995,6 +1024,43 @@ public void testPrimaryKeyInlineSize() { "MY_TABLE", 5 + 3); } + /** */ + @Test + public void testNonPersistentRejoinWithDynamicTablesOverPredefinedCaches() throws Exception { + stopAllGrids(); + + persistence = false; + nodesCnt = 3; + + CacheConfiguration cacheCfg = new CacheConfiguration<>("TEST_CACHE") + .setBackups(1) + .setCacheMode(CacheMode.PARTITIONED) + .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL) + .setWriteSynchronizationMode(CacheWriteSynchronizationMode.PRIMARY_SYNC); + + cacheConfigurations = new CacheConfiguration[]{cacheCfg}; + + client = startGrids(3); + + sql("CREATE TABLE IF NOT EXISTS TEST_TBL(ID INTEGER PRIMARY KEY, VAL VARCHAR) WITH \"CACHE_NAME=TEST_CACHE\""); + + assertEquals(0, sql("SELECT * FROM TEST_TBL").size()); + + int testGrid = 2; + + stopGrid(testGrid); + startGrid(testGrid); + + awaitPartitionMapExchange(); + + for (int i = 0; i < 100; ++i) + assertEquals(1, sql("INSERT INTO TEST_TBL VALUES(" + (i + 1) + ", '" + (i + 1000) + "')").size()); + + assertEquals(100, grid(testGrid).cache("TEST_CACHE").size()); + + assertEquals(100, sql("SELECT * FROM TEST_TBL").size()); + } + /** */ private void checkPkInlineSize(String ddl, String tableName, int expectedSize) { sql(ddl); From cdec177e8fa85b97adf21b113fa60f65ba39a4f3 Mon Sep 17 00:00:00 2001 From: Vladimir Steshin Date: Mon, 20 Jan 2025 20:10:46 +0300 Subject: [PATCH 07/15] reimpl --- .../processors/cache/ClusterCachesInfo.java | 64 ++++++++++++------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java index 940825ea0b026..92ddfd8a12ee9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java @@ -1616,37 +1616,35 @@ else if (!GridFunc.eqNotOrdered(desc.schema().entities(), locQryEntities)) cfg.getNearConfiguration() != null); } - updateRegisteredCachesIfNeeded(patchesToApply, cachesToSave, hasSchemaPatchConflict); + if (!hasSchemaPatchConflict) + updateRegisteredCaches(patchesToApply, cachesToSave); } /** - * Merging config or resaving it if it needed. + * Merging config, resaving it if it needed. * * @param patchesToApply Patches which need to apply. * @param cachesToSave Caches which need to resave. - * @param hasSchemaPatchConflict {@code true} if we have conflict during making patch. - */ - private void updateRegisteredCachesIfNeeded(Map patchesToApply, - Collection cachesToSave, boolean hasSchemaPatchConflict) { - //Skip merge of config if least one conflict was found. - if (!hasSchemaPatchConflict) { - boolean isClusterActive = ctx.state().clusterState().active(); - - //Merge of config for cluster only for inactive grid. - if (!isClusterActive && !patchesToApply.isEmpty()) { - for (Map.Entry entry : patchesToApply.entrySet()) { - if (entry.getKey().applySchemaPatch(entry.getValue())) - saveCacheConfiguration(entry.getKey()); - } + */ + private void updateRegisteredCaches( + Map patchesToApply, + Collection cachesToSave + ) { + // Store config only if cluster is nactive. + boolean isClusterActive = ctx.state().clusterState().active(); - for (DynamicCacheDescriptor descriptor : cachesToSave) - saveCacheConfiguration(descriptor); - } - else if (patchesToApply.isEmpty()) { - for (DynamicCacheDescriptor descriptor : cachesToSave) - saveCacheConfiguration(descriptor); + //Merge of config for cluster only for inactive grid. + if (!patchesToApply.isEmpty()) { + for (Map.Entry entry : patchesToApply.entrySet()) { + if (entry.getKey().applySchemaPatch(entry.getValue()) && !isClusterActive) + saveCacheConfiguration(entry.getKey()); } } + + if (isClusterActive) { + for (DynamicCacheDescriptor descriptor : cachesToSave) + saveCacheConfiguration(descriptor); + } } /** @@ -1840,7 +1838,7 @@ private void initStartCachesForLocalJoin(boolean firstNode, boolean reconnect) { nearCfg = locCfg.cacheData().config().getNearConfiguration(); DynamicCacheDescriptor desc0 = new DynamicCacheDescriptor(ctx, - desc.cacheConfiguration(), + mergeConfigs(locCfg.cacheData().config(), cfg), desc.cacheType(), desc.groupDescriptor(), desc.template(), @@ -1881,6 +1879,26 @@ private void initStartCachesForLocalJoin(boolean firstNode, boolean reconnect) { } } + /** + * Merges local cache configuration with the received. Local cache can contain local cache listeners while remote + * cache configuration can bring new schema for a non-persistent node. + * + * @see #registerReceivedCaches + * @see #updateRegisteredCaches + */ + private CacheConfiguration mergeConfigs(CacheConfiguration locCfg, CacheConfiguration gridCfg) { + // The entities are suppesed to get merged. + locCfg.setQueryEntities(gridCfg.getQueryEntities()); + locCfg.setSqlSchema(gridCfg.getSqlSchema()); + locCfg.setSqlFunctionClasses(gridCfg.getSqlFunctionClasses()); + locCfg.setSqlEscapeAll(gridCfg.isSqlEscapeAll()); + + assert locCfg.isSqlOnheapCacheEnabled() == gridCfg.isSqlOnheapCacheEnabled(); + assert locCfg.getSqlOnheapCacheMaxSize() == gridCfg.getSqlOnheapCacheMaxSize(); + + return locCfg; + } + /** * @param msg Message. */ From 8271b78816b46180b0cd7bc3cb755fd9c6968680 Mon Sep 17 00:00:00 2001 From: Vladimir Steshin Date: Mon, 20 Jan 2025 20:55:58 +0300 Subject: [PATCH 08/15] reimpl --- .../integration/TableDdlIntegrationTest.java | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDdlIntegrationTest.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDdlIntegrationTest.java index 8ac1b2ff917f1..d0ac613d04254 100644 --- a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDdlIntegrationTest.java +++ b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDdlIntegrationTest.java @@ -62,9 +62,6 @@ public class TableDdlIntegrationTest extends AbstractDdlIntegrationTest { /** */ private boolean persistence = true; - /** */ - private int nodesCnt = 1; - /** */ private CacheConfiguration[] cacheConfigurations; @@ -81,11 +78,6 @@ public class TableDdlIntegrationTest extends AbstractDdlIntegrationTest { return cfg; } - /** {@inheritDoc} */ - @Override protected int nodeCount() { - return nodesCnt; - } - /** * Creates table with two columns, where the first column is PK, * and verifies created cache. @@ -1029,36 +1021,44 @@ public void testPrimaryKeyInlineSize() { public void testNonPersistentRejoinWithDynamicTablesOverPredefinedCaches() throws Exception { stopAllGrids(); - persistence = false; - nodesCnt = 3; + try { + persistence = false; + + CacheConfiguration cacheCfg = new CacheConfiguration<>("TEST_CACHE") + .setBackups(1) + .setCacheMode(CacheMode.PARTITIONED) + .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL) + .setWriteSynchronizationMode(CacheWriteSynchronizationMode.PRIMARY_SYNC); - CacheConfiguration cacheCfg = new CacheConfiguration<>("TEST_CACHE") - .setBackups(1) - .setCacheMode(CacheMode.PARTITIONED) - .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL) - .setWriteSynchronizationMode(CacheWriteSynchronizationMode.PRIMARY_SYNC); + cacheConfigurations = new CacheConfiguration[] {cacheCfg}; - cacheConfigurations = new CacheConfiguration[]{cacheCfg}; + client = startGrids(3); - client = startGrids(3); + sql("CREATE TABLE IF NOT EXISTS TEST_TBL(ID INTEGER PRIMARY KEY, VAL VARCHAR) WITH \"CACHE_NAME=TEST_CACHE\""); - sql("CREATE TABLE IF NOT EXISTS TEST_TBL(ID INTEGER PRIMARY KEY, VAL VARCHAR) WITH \"CACHE_NAME=TEST_CACHE\""); + assertEquals(0, sql("SELECT * FROM TEST_TBL").size()); - assertEquals(0, sql("SELECT * FROM TEST_TBL").size()); + int testGrid = 2; - int testGrid = 2; + stopGrid(testGrid); + startGrid(testGrid); - stopGrid(testGrid); - startGrid(testGrid); + awaitPartitionMapExchange(); - awaitPartitionMapExchange(); + for (int i = 0; i < 100; ++i) + assertEquals(1, sql("INSERT INTO TEST_TBL VALUES(" + (i + 1) + ", '" + (i + 1000) + "')").size()); + + assertEquals(100, grid(testGrid).cache("TEST_CACHE").size()); - for (int i = 0; i < 100; ++i) - assertEquals(1, sql("INSERT INTO TEST_TBL VALUES(" + (i + 1) + ", '" + (i + 1000) + "')").size()); + assertEquals(100, sql("SELECT * FROM TEST_TBL").size()); + } + finally { + persistence = true; - assertEquals(100, grid(testGrid).cache("TEST_CACHE").size()); + afterTestsStopped(); - assertEquals(100, sql("SELECT * FROM TEST_TBL").size()); + beforeTestsStarted(); + } } /** */ From 6e8facd43f4fdb3320af2abe942ff3658af11ff2 Mon Sep 17 00:00:00 2001 From: Vladimir Steshin Date: Tue, 21 Jan 2025 15:09:52 +0300 Subject: [PATCH 09/15] minority --- .../processors/cache/ClusterCachesInfo.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java index 92ddfd8a12ee9..676552a9f2a10 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java @@ -39,6 +39,7 @@ import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; +import javax.cache.configuration.CacheEntryListenerConfiguration; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteLogger; import org.apache.ignite.IgniteSystemProperties; @@ -1880,23 +1881,20 @@ private void initStartCachesForLocalJoin(boolean firstNode, boolean reconnect) { } /** - * Merges local cache configuration with the received. Local cache can contain local cache listeners while remote - * cache configuration can bring new schema for a non-persistent node. + * Merges local cache configuration with the received. Local cache can contain cache listeners while a remote one + * can bring new schema for a non-persistent node. * + * @param loc Local cache configuration. + * @param received Cache configuration received from the cluster. * @see #registerReceivedCaches * @see #updateRegisteredCaches + * @see CacheConfiguration#writeReplace() */ - private CacheConfiguration mergeConfigs(CacheConfiguration locCfg, CacheConfiguration gridCfg) { - // The entities are suppesed to get merged. - locCfg.setQueryEntities(gridCfg.getQueryEntities()); - locCfg.setSqlSchema(gridCfg.getSqlSchema()); - locCfg.setSqlFunctionClasses(gridCfg.getSqlFunctionClasses()); - locCfg.setSqlEscapeAll(gridCfg.isSqlEscapeAll()); + private CacheConfiguration mergeConfigs(CacheConfiguration loc, CacheConfiguration received) { + for (CacheEntryListenerConfiguration lsnrCfg : loc.getCacheEntryListenerConfigurations()) + received.addCacheEntryListenerConfiguration(lsnrCfg); - assert locCfg.isSqlOnheapCacheEnabled() == gridCfg.isSqlOnheapCacheEnabled(); - assert locCfg.getSqlOnheapCacheMaxSize() == gridCfg.getSqlOnheapCacheMaxSize(); - - return locCfg; + return received; } /** From c92053c3832ea5b919a1b79e392be86133f75b34 Mon Sep 17 00:00:00 2001 From: Vladimir Steshin Date: Tue, 21 Jan 2025 15:12:34 +0300 Subject: [PATCH 10/15] minority --- .../ignite/internal/processors/cache/ClusterCachesInfo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java index 676552a9f2a10..f7ad4cc19e753 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java @@ -1882,13 +1882,13 @@ private void initStartCachesForLocalJoin(boolean firstNode, boolean reconnect) { /** * Merges local cache configuration with the received. Local cache can contain cache listeners while a remote one - * can bring new schema for a non-persistent node. + * can bring schema changes. * * @param loc Local cache configuration. * @param received Cache configuration received from the cluster. * @see #registerReceivedCaches * @see #updateRegisteredCaches - * @see CacheConfiguration#writeReplace() + * @see DynamicCacheDescriptor#makeSchemaPatch(Collection) */ private CacheConfiguration mergeConfigs(CacheConfiguration loc, CacheConfiguration received) { for (CacheEntryListenerConfiguration lsnrCfg : loc.getCacheEntryListenerConfigurations()) From 33b4d86d5bc2f3fb014d449d931d7a0e3bf6393b Mon Sep 17 00:00:00 2001 From: Vladimir Steshin Date: Tue, 21 Jan 2025 15:13:27 +0300 Subject: [PATCH 11/15] + lost doc change --- .../ignite/internal/processors/cache/ClusterCachesInfo.java | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java index f7ad4cc19e753..c258681afe573 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java @@ -1889,6 +1889,7 @@ private void initStartCachesForLocalJoin(boolean firstNode, boolean reconnect) { * @see #registerReceivedCaches * @see #updateRegisteredCaches * @see DynamicCacheDescriptor#makeSchemaPatch(Collection) + * @see CacheConfiguration#writeReplace() */ private CacheConfiguration mergeConfigs(CacheConfiguration loc, CacheConfiguration received) { for (CacheEntryListenerConfiguration lsnrCfg : loc.getCacheEntryListenerConfigurations()) From d52f2d39a3f861df37373ebbae04e663f71ecec6 Mon Sep 17 00:00:00 2001 From: Vladimir Steshin Date: Tue, 21 Jan 2025 15:21:44 +0300 Subject: [PATCH 12/15] trivial renaminga --- .../query/calcite/integration/TableDdlIntegrationTest.java | 2 +- .../internal/processors/cache/ClusterCachesInfo.java | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDdlIntegrationTest.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDdlIntegrationTest.java index d0ac613d04254..d5ccf319bcaaf 100644 --- a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDdlIntegrationTest.java +++ b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDdlIntegrationTest.java @@ -1018,7 +1018,7 @@ public void testPrimaryKeyInlineSize() { /** */ @Test - public void testNonPersistentRejoinWithDynamicTablesOverPredefinedCaches() throws Exception { + public void testNonPersistentRejoinsWithDynamicTablesOverPredefinedCaches() throws Exception { stopAllGrids(); try { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java index c258681afe573..f3d1a0dd7780b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java @@ -1839,7 +1839,7 @@ private void initStartCachesForLocalJoin(boolean firstNode, boolean reconnect) { nearCfg = locCfg.cacheData().config().getNearConfiguration(); DynamicCacheDescriptor desc0 = new DynamicCacheDescriptor(ctx, - mergeConfigs(locCfg.cacheData().config(), cfg), + mergeConfigurations(locCfg.cacheData().config(), cfg), desc.cacheType(), desc.groupDescriptor(), desc.template(), @@ -1881,8 +1881,7 @@ private void initStartCachesForLocalJoin(boolean firstNode, boolean reconnect) { } /** - * Merges local cache configuration with the received. Local cache can contain cache listeners while a remote one - * can bring schema changes. + * Merges local and received cache configurations. * * @param loc Local cache configuration. * @param received Cache configuration received from the cluster. @@ -1891,7 +1890,7 @@ private void initStartCachesForLocalJoin(boolean firstNode, boolean reconnect) { * @see DynamicCacheDescriptor#makeSchemaPatch(Collection) * @see CacheConfiguration#writeReplace() */ - private CacheConfiguration mergeConfigs(CacheConfiguration loc, CacheConfiguration received) { + private CacheConfiguration mergeConfigurations(CacheConfiguration loc, CacheConfiguration received) { for (CacheEntryListenerConfiguration lsnrCfg : loc.getCacheEntryListenerConfigurations()) received.addCacheEntryListenerConfiguration(lsnrCfg); From 2e319854adaffbf125a27790ab775b983d401a90 Mon Sep 17 00:00:00 2001 From: Vladimir Steshin Date: Wed, 12 Feb 2025 22:21:12 +0300 Subject: [PATCH 13/15] research --- .../integration/TableDdlIntegrationTest.java | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDdlIntegrationTest.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDdlIntegrationTest.java index d5ccf319bcaaf..59c281e562ab1 100644 --- a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDdlIntegrationTest.java +++ b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDdlIntegrationTest.java @@ -33,6 +33,7 @@ import org.apache.ignite.cache.CachePeekMode; import org.apache.ignite.cache.CacheWriteSynchronizationMode; import org.apache.ignite.cache.QueryEntity; +import org.apache.ignite.cluster.ClusterState; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.DataRegionConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; @@ -1019,10 +1020,24 @@ public void testPrimaryKeyInlineSize() { /** */ @Test public void testNonPersistentRejoinsWithDynamicTablesOverPredefinedCaches() throws Exception { + testLostSchema(false); + } + + /** */ + @Test + public void testNonPersistentRejoinsWithDynamicTablesOverPredefinedCaches2() throws Exception { + testLostSchema(true); + } + + /** */ + private void testLostSchema(boolean persistence) throws Exception { stopAllGrids(); + if(persistence) + cleanPersistenceDir(); + try { - persistence = false; + this.persistence = persistence; CacheConfiguration cacheCfg = new CacheConfiguration<>("TEST_CACHE") .setBackups(1) @@ -1034,13 +1049,21 @@ public void testNonPersistentRejoinsWithDynamicTablesOverPredefinedCaches() thro client = startGrids(3); + client.cluster().state(ClusterState.ACTIVE); + sql("CREATE TABLE IF NOT EXISTS TEST_TBL(ID INTEGER PRIMARY KEY, VAL VARCHAR) WITH \"CACHE_NAME=TEST_CACHE\""); assertEquals(0, sql("SELECT * FROM TEST_TBL").size()); int testGrid = 2; + String testConsId = grid(testGrid).cluster().localNode().consistentId().toString(); + stopGrid(testGrid); + + if (persistence) + cleanPersistenceDir(testConsId); + startGrid(testGrid); awaitPartitionMapExchange(); @@ -1053,11 +1076,13 @@ public void testNonPersistentRejoinsWithDynamicTablesOverPredefinedCaches() thro assertEquals(100, sql("SELECT * FROM TEST_TBL").size()); } finally { - persistence = true; + if(!persistence) { + this.persistence = true; - afterTestsStopped(); + afterTestsStopped(); - beforeTestsStarted(); + beforeTestsStarted(); + } } } From eec7957b8b9f1653df1db3af7576b2cf77f0a6f7 Mon Sep 17 00:00:00 2001 From: Vladimir Steshin Date: Thu, 13 Feb 2025 16:32:16 +0300 Subject: [PATCH 14/15] reimpl --- .../integration/TableDdlIntegrationTest.java | 91 --------- .../processors/cache/ClusterCachesInfo.java | 46 ++--- .../cache/index/DynamicDdlTest.java | 189 ++++++++++++++++++ .../IgniteCacheQuerySelfTestSuite6.java | 2 + 4 files changed, 213 insertions(+), 115 deletions(-) create mode 100644 modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicDdlTest.java diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDdlIntegrationTest.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDdlIntegrationTest.java index 59c281e562ab1..98ce8275f2111 100644 --- a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDdlIntegrationTest.java +++ b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/TableDdlIntegrationTest.java @@ -33,10 +33,7 @@ import org.apache.ignite.cache.CachePeekMode; import org.apache.ignite.cache.CacheWriteSynchronizationMode; import org.apache.ignite.cache.QueryEntity; -import org.apache.ignite.cluster.ClusterState; import org.apache.ignite.configuration.CacheConfiguration; -import org.apache.ignite.configuration.DataRegionConfiguration; -import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.processors.cache.IgniteInternalCache; import org.apache.ignite.internal.processors.query.IgniteSQLException; import org.apache.ignite.internal.processors.query.QueryUtils; @@ -60,25 +57,6 @@ /** */ public class TableDdlIntegrationTest extends AbstractDdlIntegrationTest { - /** */ - private boolean persistence = true; - - /** */ - private CacheConfiguration[] cacheConfigurations; - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); - - for (DataRegionConfiguration drCfg : cfg.getDataStorageConfiguration().getDataRegionConfigurations()) - drCfg.setPersistenceEnabled(persistence); - - if (!F.isEmpty(cacheConfigurations)) - cfg.setCacheConfiguration(cacheConfigurations); - - return cfg; - } - /** * Creates table with two columns, where the first column is PK, * and verifies created cache. @@ -1017,75 +995,6 @@ public void testPrimaryKeyInlineSize() { "MY_TABLE", 5 + 3); } - /** */ - @Test - public void testNonPersistentRejoinsWithDynamicTablesOverPredefinedCaches() throws Exception { - testLostSchema(false); - } - - /** */ - @Test - public void testNonPersistentRejoinsWithDynamicTablesOverPredefinedCaches2() throws Exception { - testLostSchema(true); - } - - /** */ - private void testLostSchema(boolean persistence) throws Exception { - stopAllGrids(); - - if(persistence) - cleanPersistenceDir(); - - try { - this.persistence = persistence; - - CacheConfiguration cacheCfg = new CacheConfiguration<>("TEST_CACHE") - .setBackups(1) - .setCacheMode(CacheMode.PARTITIONED) - .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL) - .setWriteSynchronizationMode(CacheWriteSynchronizationMode.PRIMARY_SYNC); - - cacheConfigurations = new CacheConfiguration[] {cacheCfg}; - - client = startGrids(3); - - client.cluster().state(ClusterState.ACTIVE); - - sql("CREATE TABLE IF NOT EXISTS TEST_TBL(ID INTEGER PRIMARY KEY, VAL VARCHAR) WITH \"CACHE_NAME=TEST_CACHE\""); - - assertEquals(0, sql("SELECT * FROM TEST_TBL").size()); - - int testGrid = 2; - - String testConsId = grid(testGrid).cluster().localNode().consistentId().toString(); - - stopGrid(testGrid); - - if (persistence) - cleanPersistenceDir(testConsId); - - startGrid(testGrid); - - awaitPartitionMapExchange(); - - for (int i = 0; i < 100; ++i) - assertEquals(1, sql("INSERT INTO TEST_TBL VALUES(" + (i + 1) + ", '" + (i + 1000) + "')").size()); - - assertEquals(100, grid(testGrid).cache("TEST_CACHE").size()); - - assertEquals(100, sql("SELECT * FROM TEST_TBL").size()); - } - finally { - if(!persistence) { - this.persistence = true; - - afterTestsStopped(); - - beforeTestsStarted(); - } - } - } - /** */ private void checkPkInlineSize(String ddl, String tableName, int expectedSize) { sql(ddl); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java index aa41d25f34a09..5e3a764da61bc 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java @@ -39,7 +39,6 @@ import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; -import javax.cache.configuration.CacheEntryListenerConfiguration; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteLogger; import org.apache.ignite.IgniteSystemProperties; @@ -1616,32 +1615,27 @@ else if (!GridFunc.eqNotOrdered(desc.schema().entities(), locQryEntities)) cfg.getNearConfiguration() != null); } - if (!hasSchemaPatchConflict) - updateRegisteredCaches(patchesToApply, cachesToSave); + updateRegisteredCaches(patchesToApply, cachesToSave, hasSchemaPatchConflict); } /** - * Merging config, resaving it if it needed. + * Merging config or resaving it if it needed. * * @param patchesToApply Patches which need to apply. * @param cachesToSave Caches which need to resave. - */ - private void updateRegisteredCaches( - Map patchesToApply, - Collection cachesToSave - ) { - // Store config only if cluster is nactive. - boolean isClusterActive = ctx.state().clusterState().active(); - - //Merge of config for cluster only for inactive grid. - if (!patchesToApply.isEmpty()) { - for (Map.Entry entry : patchesToApply.entrySet()) { - if (entry.getKey().applySchemaPatch(entry.getValue()) && !isClusterActive) - saveCacheConfiguration(entry.getKey()); + * @param hasSchemaPatchConflict {@code true} if we have conflict during making patch. + */ + private void updateRegisteredCaches(Map patchesToApply, + Collection cachesToSave, boolean hasSchemaPatchConflict) { + //Skip merge of config if least one conflict was found. + if (!hasSchemaPatchConflict) { + if (!patchesToApply.isEmpty()) { + for (Map.Entry entry : patchesToApply.entrySet()) { + if (entry.getKey().applySchemaPatch(entry.getValue())) + saveCacheConfiguration(entry.getKey()); + } } - } - if (isClusterActive) { for (DynamicCacheDescriptor descriptor : cachesToSave) saveCacheConfiguration(descriptor); } @@ -1885,15 +1879,19 @@ private void initStartCachesForLocalJoin(boolean firstNode, boolean reconnect) { * @param loc Local cache configuration. * @param received Cache configuration received from the cluster. * @see #registerReceivedCaches - * @see #updateRegisteredCaches * @see DynamicCacheDescriptor#makeSchemaPatch(Collection) - * @see CacheConfiguration#writeReplace() */ private CacheConfiguration mergeConfigurations(CacheConfiguration loc, CacheConfiguration received) { - for (CacheEntryListenerConfiguration lsnrCfg : loc.getCacheEntryListenerConfigurations()) - received.addCacheEntryListenerConfiguration(lsnrCfg); + // Schema is supposed to get merged earlier. + loc.setQueryEntities(received.getQueryEntities()); + loc.setSqlSchema(received.getSqlSchema()); + loc.setSqlFunctionClasses(received.getSqlFunctionClasses()); + loc.setSqlEscapeAll(received.isSqlEscapeAll()); + + assert loc.isSqlOnheapCacheEnabled() == received.isSqlOnheapCacheEnabled(); + assert loc.getSqlOnheapCacheMaxSize() == received.getSqlOnheapCacheMaxSize(); - return received; + return loc; } /** diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicDdlTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicDdlTest.java new file mode 100644 index 0000000000000..cf73065ead5db --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicDdlTest.java @@ -0,0 +1,189 @@ +/* + * 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.internal.processors.cache.index; + +import java.io.File; +import java.util.List; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cluster.ClusterState; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.DataRegionConfiguration; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.query.GridQueryProcessor; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.Test; + +/** */ +public class DynamicDdlTest extends GridCommonAbstractTest { + /** */ + private boolean persistence; + + /** Server cache configurations. */ + private CacheConfiguration[] predefinedCachesCfgs; + + /** */ + private IgniteEx sqlClient; + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + cleanPersistenceDir(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(); + + cleanPersistenceDir(); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + cfg.setDataStorageConfiguration(new DataStorageConfiguration() + .setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(persistence))); + + if (!F.isEmpty(predefinedCachesCfgs)) + cfg.setCacheConfiguration(predefinedCachesCfgs); + + return cfg; + } + + /** */ + @Test + public void testRejoinWithLostDynamicTableOverPredefinedCacheInmemoryActive() throws Exception { + testRejoinWithLostDynamicTableOverPredefinedCache(false, true, false); + } + + /** */ + @Test + public void testRejoinWithLostDynamicTableOverPredefinedCacheInmemoryInactive() throws Exception { + testRejoinWithLostDynamicTableOverPredefinedCache(false, false, false); + } + + /** */ + @Test + public void testRejoinWithLostDynamicTableOverPredefinedCachePersistentActive() throws Exception { + testRejoinWithLostDynamicTableOverPredefinedCache(true, true, false); + } + + /** */ + @Test + public void testRejoinWithLostLostDynamicTableOverPredefinedCachePersistentInactive() throws Exception { + testRejoinWithLostDynamicTableOverPredefinedCache(true, false, false); + } + + /** */ + @Test + public void testRejoinWithLostDynamicTableOverPredefinedCachePersistentActiveClear() throws Exception { + testRejoinWithLostDynamicTableOverPredefinedCache(true, true, true); + } + + /** */ + @Test + public void testRejoinWithLostDynamicTableOverPredefinedCachePersistentInactiveClear() throws Exception { + testRejoinWithLostDynamicTableOverPredefinedCache(true, false, true); + } + + /** + * Tests the scenario when a node rejoins cluster with lost knowladge of previously dynamically created table over + * a predefined in {@link IgniteConfiguration} cache. + * + * @param persistence Flag to test with persistence or in-memory cluster. + * @param active Flag to rejoin to active or inactive cluster. + * @param clearData Flag to clear test node's persistent data before rejoining. Efficient with enabled {@code persistence}. + */ + private void testRejoinWithLostDynamicTableOverPredefinedCache( + boolean persistence, + boolean active, + boolean clearData + ) throws Exception { + this.persistence = persistence; + + CacheConfiguration cacheCfg = new CacheConfiguration<>("TEST_CACHE") + .setBackups(1) + .setCacheMode(CacheMode.PARTITIONED) + .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL) + .setWriteSynchronizationMode(CacheWriteSynchronizationMode.PRIMARY_SYNC); + + predefinedCachesCfgs = new CacheConfiguration[] {cacheCfg}; + + sqlClient = startGrids(3); + +// sqlClient = startClientGrid(G.allGrids().size()); + + sqlClient.cluster().state(ClusterState.ACTIVE); + + sql("CREATE TABLE IF NOT EXISTS TEST_TBL(ID INTEGER PRIMARY KEY, VAL VARCHAR) WITH \"CACHE_NAME=TEST_CACHE\""); + + assertEquals(0, sql("SELECT * FROM TEST_TBL").size()); + + // Grid to restart. + int testGrid = 1; + + File persistPath = grid(testGrid).context().pdsFolderResolver().fileTree().nodeStorage(); + + stopGrid(testGrid); + + if (clearData) + U.delete(persistPath); + + if (!active) + grid(0).cluster().state(ClusterState.INACTIVE); + + log.error("TEST | start"); + + startGrid(testGrid); + + if (!active) + grid(0).cluster().state(ClusterState.ACTIVE); + + awaitPartitionMapExchange(); + + for (int i = 0; i < 100; ++i) + assertEquals(1, sql("INSERT INTO TEST_TBL VALUES(" + (i + 1) + ", '" + (i + 1000) + "')").size()); + + assertEquals(100, grid(testGrid).cache("TEST_CACHE").size()); + + assertEquals(100, sql("SELECT * FROM TEST_TBL").size()); + + sqlClient = grid(testGrid); + + assertEquals(100, sql("SELECT * FROM TEST_TBL").size()); + } + + /** */ + protected List> sql(String sql) { + assert sqlClient != null; + + GridQueryProcessor sqlProc = sqlClient.context().query(); + + return sqlProc.querySqlFields(new SqlFieldsQuery(sql), false).getAll(); + } +} diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite6.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite6.java index 7b8fb8ed9580b..153dde1055ed3 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite6.java +++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite6.java @@ -17,6 +17,7 @@ package org.apache.ignite.testsuites; +import org.apache.ignite.internal.processors.cache.index.DynamicDdlTest; import org.apache.ignite.internal.processors.cache.index.StaticCacheDdlKeepStaticConfigurationTest; import org.apache.ignite.internal.processors.cache.index.StaticCacheDdlTest; import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousBatchAckTest; @@ -71,6 +72,7 @@ CacheContinuousWithTransformerRandomOperationsTest.class, CacheContinuousQueryRandomOperationsTest.class, StaticCacheDdlTest.class, + DynamicDdlTest.class, StaticCacheDdlKeepStaticConfigurationTest.class, MemLeakOnSqlWithClientReconnectTest.class, CacheContinuousQueryFilterDeploymentFailedTest.class, From 2ff502b88d2d1f3bec99f347be6db7ae71fb1ca0 Mon Sep 17 00:00:00 2001 From: Vladimir Steshin Date: Thu, 13 Feb 2025 18:34:03 +0300 Subject: [PATCH 15/15] test improvement --- .../processors/cache/ClusterCachesInfo.java | 5 +- .../cache/index/DynamicDdlTest.java | 189 -------------- .../index/RejoinWithLostDynamicDdlTest.java | 232 ++++++++++++++++++ .../IgniteCacheQuerySelfTestSuite6.java | 4 +- 4 files changed, 237 insertions(+), 193 deletions(-) delete mode 100644 modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicDdlTest.java create mode 100644 modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/RejoinWithLostDynamicDdlTest.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java index 5e3a764da61bc..64ac803fcf292 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java @@ -1615,7 +1615,7 @@ else if (!GridFunc.eqNotOrdered(desc.schema().entities(), locQryEntities)) cfg.getNearConfiguration() != null); } - updateRegisteredCaches(patchesToApply, cachesToSave, hasSchemaPatchConflict); + updateRegisteredCachesIfNeeded(patchesToApply, cachesToSave, hasSchemaPatchConflict); } /** @@ -1625,7 +1625,7 @@ else if (!GridFunc.eqNotOrdered(desc.schema().entities(), locQryEntities)) * @param cachesToSave Caches which need to resave. * @param hasSchemaPatchConflict {@code true} if we have conflict during making patch. */ - private void updateRegisteredCaches(Map patchesToApply, + private void updateRegisteredCachesIfNeeded(Map patchesToApply, Collection cachesToSave, boolean hasSchemaPatchConflict) { //Skip merge of config if least one conflict was found. if (!hasSchemaPatchConflict) { @@ -1880,6 +1880,7 @@ private void initStartCachesForLocalJoin(boolean firstNode, boolean reconnect) { * @param received Cache configuration received from the cluster. * @see #registerReceivedCaches * @see DynamicCacheDescriptor#makeSchemaPatch(Collection) + * @see #updateRegisteredCachesIfNeeded(Map, Collection, boolean) */ private CacheConfiguration mergeConfigurations(CacheConfiguration loc, CacheConfiguration received) { // Schema is supposed to get merged earlier. diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicDdlTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicDdlTest.java deleted file mode 100644 index cf73065ead5db..0000000000000 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicDdlTest.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * 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.internal.processors.cache.index; - -import java.io.File; -import java.util.List; -import org.apache.ignite.cache.CacheAtomicityMode; -import org.apache.ignite.cache.CacheMode; -import org.apache.ignite.cache.CacheWriteSynchronizationMode; -import org.apache.ignite.cache.query.SqlFieldsQuery; -import org.apache.ignite.cluster.ClusterState; -import org.apache.ignite.configuration.CacheConfiguration; -import org.apache.ignite.configuration.DataRegionConfiguration; -import org.apache.ignite.configuration.DataStorageConfiguration; -import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.internal.IgniteEx; -import org.apache.ignite.internal.processors.query.GridQueryProcessor; -import org.apache.ignite.internal.util.typedef.F; -import org.apache.ignite.internal.util.typedef.internal.U; -import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; -import org.junit.Test; - -/** */ -public class DynamicDdlTest extends GridCommonAbstractTest { - /** */ - private boolean persistence; - - /** Server cache configurations. */ - private CacheConfiguration[] predefinedCachesCfgs; - - /** */ - private IgniteEx sqlClient; - - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - super.beforeTest(); - - cleanPersistenceDir(); - } - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - super.afterTest(); - - stopAllGrids(); - - cleanPersistenceDir(); - } - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); - - cfg.setDataStorageConfiguration(new DataStorageConfiguration() - .setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(persistence))); - - if (!F.isEmpty(predefinedCachesCfgs)) - cfg.setCacheConfiguration(predefinedCachesCfgs); - - return cfg; - } - - /** */ - @Test - public void testRejoinWithLostDynamicTableOverPredefinedCacheInmemoryActive() throws Exception { - testRejoinWithLostDynamicTableOverPredefinedCache(false, true, false); - } - - /** */ - @Test - public void testRejoinWithLostDynamicTableOverPredefinedCacheInmemoryInactive() throws Exception { - testRejoinWithLostDynamicTableOverPredefinedCache(false, false, false); - } - - /** */ - @Test - public void testRejoinWithLostDynamicTableOverPredefinedCachePersistentActive() throws Exception { - testRejoinWithLostDynamicTableOverPredefinedCache(true, true, false); - } - - /** */ - @Test - public void testRejoinWithLostLostDynamicTableOverPredefinedCachePersistentInactive() throws Exception { - testRejoinWithLostDynamicTableOverPredefinedCache(true, false, false); - } - - /** */ - @Test - public void testRejoinWithLostDynamicTableOverPredefinedCachePersistentActiveClear() throws Exception { - testRejoinWithLostDynamicTableOverPredefinedCache(true, true, true); - } - - /** */ - @Test - public void testRejoinWithLostDynamicTableOverPredefinedCachePersistentInactiveClear() throws Exception { - testRejoinWithLostDynamicTableOverPredefinedCache(true, false, true); - } - - /** - * Tests the scenario when a node rejoins cluster with lost knowladge of previously dynamically created table over - * a predefined in {@link IgniteConfiguration} cache. - * - * @param persistence Flag to test with persistence or in-memory cluster. - * @param active Flag to rejoin to active or inactive cluster. - * @param clearData Flag to clear test node's persistent data before rejoining. Efficient with enabled {@code persistence}. - */ - private void testRejoinWithLostDynamicTableOverPredefinedCache( - boolean persistence, - boolean active, - boolean clearData - ) throws Exception { - this.persistence = persistence; - - CacheConfiguration cacheCfg = new CacheConfiguration<>("TEST_CACHE") - .setBackups(1) - .setCacheMode(CacheMode.PARTITIONED) - .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL) - .setWriteSynchronizationMode(CacheWriteSynchronizationMode.PRIMARY_SYNC); - - predefinedCachesCfgs = new CacheConfiguration[] {cacheCfg}; - - sqlClient = startGrids(3); - -// sqlClient = startClientGrid(G.allGrids().size()); - - sqlClient.cluster().state(ClusterState.ACTIVE); - - sql("CREATE TABLE IF NOT EXISTS TEST_TBL(ID INTEGER PRIMARY KEY, VAL VARCHAR) WITH \"CACHE_NAME=TEST_CACHE\""); - - assertEquals(0, sql("SELECT * FROM TEST_TBL").size()); - - // Grid to restart. - int testGrid = 1; - - File persistPath = grid(testGrid).context().pdsFolderResolver().fileTree().nodeStorage(); - - stopGrid(testGrid); - - if (clearData) - U.delete(persistPath); - - if (!active) - grid(0).cluster().state(ClusterState.INACTIVE); - - log.error("TEST | start"); - - startGrid(testGrid); - - if (!active) - grid(0).cluster().state(ClusterState.ACTIVE); - - awaitPartitionMapExchange(); - - for (int i = 0; i < 100; ++i) - assertEquals(1, sql("INSERT INTO TEST_TBL VALUES(" + (i + 1) + ", '" + (i + 1000) + "')").size()); - - assertEquals(100, grid(testGrid).cache("TEST_CACHE").size()); - - assertEquals(100, sql("SELECT * FROM TEST_TBL").size()); - - sqlClient = grid(testGrid); - - assertEquals(100, sql("SELECT * FROM TEST_TBL").size()); - } - - /** */ - protected List> sql(String sql) { - assert sqlClient != null; - - GridQueryProcessor sqlProc = sqlClient.context().query(); - - return sqlProc.querySqlFields(new SqlFieldsQuery(sql), false).getAll(); - } -} diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/RejoinWithLostDynamicDdlTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/RejoinWithLostDynamicDdlTest.java new file mode 100644 index 0000000000000..e3698af58a776 --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/RejoinWithLostDynamicDdlTest.java @@ -0,0 +1,232 @@ +/* + * 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.internal.processors.cache.index; + +import java.io.File; +import java.util.Collection; +import java.util.List; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cluster.ClusterState; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.DataRegionConfiguration; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.query.GridQueryProcessor; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.G; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import static org.apache.ignite.testframework.GridTestUtils.cartesianProduct; + +/** Tests the scenario when a node rejoins cluster with lost knowladge of previously created dynamic schema. */ +@RunWith(Parameterized.class) +public class RejoinWithLostDynamicDdlTest extends GridCommonAbstractTest { + /** */ + private static final int SERVERS_CNT = 2; + + /** */ + private static final int LOAD_CNT = 100; + + /** */ + private boolean persistence; + + /** Static cache configurations. */ + private CacheConfiguration[] staticCaches; + + /** */ + private IgniteEx sqlClient; + + /** Grid to test (restart). */ + @Parameterized.Parameter + public int gridToRestart; + + /** Eanables create-if-not-exist table with the rejoining. */ + @Parameterized.Parameter(1) + public boolean recreateTable; + + /** */ + @Parameterized.Parameters(name = "gridToRestart={0}, recreateTable={1}") + public static Collection runConfig() { + // Restart coordinator, another server node and client. + return cartesianProduct( + F.asList(0, 1, SERVERS_CNT), + F.asList(false, true) + ); + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + cleanPersistenceDir(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(); + + cleanPersistenceDir(); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + cfg.setDataStorageConfiguration(new DataStorageConfiguration() + .setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(persistence))); + + if (!F.isEmpty(staticCaches)) + cfg.setCacheConfiguration(staticCaches); + + return cfg; + } + + /** */ + @Test + public void testRejoinWithLostDynamicSchemaInmemoryActive() throws Exception { + testRejoinWithLostDynamicSchema(false, true, false); + } + + /** */ + @Test + public void testRejoinWithLostDynamicSchemaInmemoryInactive() throws Exception { + testRejoinWithLostDynamicSchema(false, false, false); + } + + /** */ + @Test + public void testRejoinWithLostDynamicSchemaPersistentActive() throws Exception { + testRejoinWithLostDynamicSchema(true, true, false); + } + + /** */ + @Test + public void testRejoinWithLostLostDynamicTablePersistentInactive() throws Exception { + testRejoinWithLostDynamicSchema(true, false, false); + } + + /** */ + @Test + public void testRejoinWithLostDynamicSchemaPersistentActiveClear() throws Exception { + testRejoinWithLostDynamicSchema(true, true, true); + } + + /** */ + @Test + public void testRejoinWithLostDynamicSchemaPersistentInactiveClear() throws Exception { + testRejoinWithLostDynamicSchema(true, false, true); + } + + /** + * Tests the scenario when a node rejoins cluster with lost knowladge of previously created dynamic table over + * a predefined cache in {@link IgniteConfiguration}. + * + * @param persistence Flag to test with persistence or in-memory cluster. + * @param rejoinActive Flag to rejoin to active or inactive cluster. + * @param clearData Flag to clear test node's persistent data before rejoining. Efficient with enabled {@code persistence}. + */ + private void testRejoinWithLostDynamicSchema( + boolean persistence, + boolean rejoinActive, + boolean clearData + ) throws Exception { + this.persistence = persistence; + + CacheConfiguration cacheCfg = new CacheConfiguration<>("STATIC_CACHE") + .setBackups(SERVERS_CNT - 1) + .setCacheMode(CacheMode.PARTITIONED) + .setAtomicityMode(CacheAtomicityMode.ATOMIC) + .setWriteSynchronizationMode(CacheWriteSynchronizationMode.PRIMARY_SYNC); + + staticCaches = new CacheConfiguration[] {cacheCfg}; + + startGrids(SERVERS_CNT); + + sqlClient = startClientGrid(G.allGrids().size()); + + if (persistence) + grid(0).cluster().state(ClusterState.ACTIVE); + + cacheCfg.setName("DYN_CACHE"); + + sqlClient.createCache(cacheCfg); + + awaitPartitionMapExchange(); + + sql("CREATE TABLE STATIC_TBL(ID INTEGER PRIMARY KEY, VAL VARCHAR) WITH \"CACHE_NAME=STATIC_CACHE\""); + sql("CREATE TABLE DYN_TBL(ID INTEGER PRIMARY KEY, VAL VARCHAR) WITH \"CACHE_NAME=DYN_CACHE\""); + + assertEquals(0, sql("SELECT * FROM STATIC_TBL").size()); + assertEquals(0, sql("SELECT * FROM DYN_TBL").size()); + + File persistPath = grid(gridToRestart).context().pdsFolderResolver().fileTree().nodeStorage(); + + stopGrid(gridToRestart); + + if (clearData) { + if (log.isDebugEnabled()) + log.debug("Clearing " + persistPath); + + U.delete(persistPath); + } + + if (!rejoinActive) + grid(gridToRestart == SERVERS_CNT ? 1 : SERVERS_CNT).cluster().state(ClusterState.INACTIVE); + + startGrid(gridToRestart); + + if (!rejoinActive) + grid(gridToRestart == SERVERS_CNT ? 1 : SERVERS_CNT).cluster().state(ClusterState.ACTIVE); + + sqlClient = grid(gridToRestart); + + if (recreateTable) { + sql("CREATE TABLE IF NOT EXISTS STATIC_TBL(ID INTEGER PRIMARY KEY, VAL VARCHAR) WITH \"CACHE_NAME=STATIC_CACHE\""); + sql("CREATE TABLE IF NOT EXISTS DYN_TBL(ID INTEGER PRIMARY KEY, VAL VARCHAR) WITH \"CACHE_NAME=DYN_CACHE\""); + } + + for (int i = 0; i < LOAD_CNT; ++i) { + assertEquals(1, sql("INSERT INTO STATIC_TBL VALUES(" + i + ", 'value_" + i + "')").size()); + assertEquals(1, sql("INSERT INTO DYN_TBL VALUES(" + i + ", 'value_" + i + "')").size()); + } + + assertEquals(LOAD_CNT, sqlClient.cache("STATIC_CACHE").size()); + assertEquals(LOAD_CNT, sqlClient.cache("DYN_CACHE").size()); + assertEquals(LOAD_CNT, sql("SELECT * FROM STATIC_TBL").size()); + assertEquals(LOAD_CNT, sql("SELECT * FROM DYN_TBL").size()); + } + + /** */ + protected List> sql(String sql) { + assert sqlClient != null; + + GridQueryProcessor sqlProc = sqlClient.context().query(); + + return sqlProc.querySqlFields(new SqlFieldsQuery(sql), false).getAll(); + } +} diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite6.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite6.java index 153dde1055ed3..e7274eeb2808b 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite6.java +++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite6.java @@ -17,7 +17,7 @@ package org.apache.ignite.testsuites; -import org.apache.ignite.internal.processors.cache.index.DynamicDdlTest; +import org.apache.ignite.internal.processors.cache.index.RejoinWithLostDynamicDdlTest; import org.apache.ignite.internal.processors.cache.index.StaticCacheDdlKeepStaticConfigurationTest; import org.apache.ignite.internal.processors.cache.index.StaticCacheDdlTest; import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousBatchAckTest; @@ -72,7 +72,7 @@ CacheContinuousWithTransformerRandomOperationsTest.class, CacheContinuousQueryRandomOperationsTest.class, StaticCacheDdlTest.class, - DynamicDdlTest.class, + RejoinWithLostDynamicDdlTest.class, StaticCacheDdlKeepStaticConfigurationTest.class, MemLeakOnSqlWithClientReconnectTest.class, CacheContinuousQueryFilterDeploymentFailedTest.class,