Skip to content

Commit

Permalink
IGNITE-20575 Forbid mixed cache groups with both atomic and transacti…
Browse files Browse the repository at this point in the history
…onal caches (with system property able to allow) (#10976)
  • Loading branch information
anton-vinogradov authored Oct 12, 2023
1 parent 7d90bd7 commit 1141f17
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,13 @@ public final class IgniteSystemProperties {
defaults = "false")
public static final String IGNITE_ALLOW_ATOMIC_OPS_IN_TX = "IGNITE_ALLOW_ATOMIC_OPS_IN_TX";

/**
* Flag indicating whether atomic and transactional caches are allowed inside the same cache group.
* Since 2.16.0 mixed cache groups are not allowed by default.
*/
@SystemProperty(value = "Allows mixed cache groups", defaults = "false")
public static final String IGNITE_ALLOW_MIXED_CACHE_GROUPS = "IGNITE_ALLOW_MIXED_CACHE_GROUPS";

/**
* Atomic cache deferred update response buffer size.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.stream.Collectors;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.IgniteSystemProperties;
import org.apache.ignite.cache.CacheExistsException;
import org.apache.ignite.cache.QueryEntity;
import org.apache.ignite.cluster.ClusterNode;
Expand All @@ -65,6 +66,7 @@
import org.apache.ignite.internal.processors.cluster.ChangeGlobalStateFinishMessage;
import org.apache.ignite.internal.processors.cluster.ChangeGlobalStateMessage;
import org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState;
import org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor;
import org.apache.ignite.internal.processors.query.QuerySchema;
import org.apache.ignite.internal.processors.query.QuerySchemaPatch;
import org.apache.ignite.internal.processors.query.QueryUtils;
Expand All @@ -87,6 +89,7 @@
import org.apache.ignite.spi.systemview.view.CacheView;
import org.jetbrains.annotations.Nullable;

import static org.apache.ignite.IgniteSystemProperties.IGNITE_ALLOW_MIXED_CACHE_GROUPS;
import static org.apache.ignite.cache.CacheMode.PARTITIONED;
import static org.apache.ignite.events.EventType.EVT_NODE_JOINED;
import static org.apache.ignite.internal.GridComponent.DiscoveryDataExchangeType.CACHE_PROC;
Expand Down Expand Up @@ -2566,9 +2569,10 @@ private void validateCacheGroupConfiguration(CacheConfiguration cfg, CacheConfig
CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "cacheMode", "Cache mode",
cfg.getCacheMode(), startCfg.getCacheMode(), true);

// https://issues.apache.org/jira/browse/IGNITE-12622
// CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "atomicityMode", "Atomicity mode",
// attr1.atomicityMode(), attr2.atomicityMode(), true);
if (!IgniteSystemProperties.getBoolean(IGNITE_ALLOW_MIXED_CACHE_GROUPS) // TODO https://issues.apache.org/jira/browse/IGNITE-12622
&& !DataStructuresProcessor.isDataStructureCache(cfg.getName())) // TODO https://issues.apache.org/jira/browse/IGNITE-20623
CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "atomicityMode", "Atomicity mode",
attr1.atomicityMode(), attr2.atomicityMode(), true);

CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "affinity", "Affinity function",
attr1.cacheAffinityClassName(), attr2.cacheAffinityClassName(), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public static CacheConfiguration[] cacheConfigurations() {
return F.asArray(
cacheConfiguration(REPL_ATOMIC_CACHE, REPLICATED, ATOMIC, null),
cacheConfiguration(REPL_TX_CACHE, REPLICATED, TRANSACTIONAL, null),
cacheConfiguration(PART_ATOMIC_CACHE, PARTITIONED, ATOMIC, "part_grp"),
cacheConfiguration(PART_TX_CACHE, PARTITIONED, TRANSACTIONAL, "part_grp")
cacheConfiguration(PART_ATOMIC_CACHE, PARTITIONED, ATOMIC, "part_grp_atomic"),
cacheConfiguration(PART_TX_CACHE, PARTITIONED, TRANSACTIONAL, "part_grp_tx")
);
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.apache.ignite.testframework.GridTestUtils;
import org.apache.ignite.transactions.Transaction;
import org.junit.Test;

import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
import static org.apache.ignite.cache.CacheMode.PARTITIONED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ public void testClusterRestartCachesWithH2Indexes() throws Exception {
// Several caches with the same indexed type (and index names).
ccfgs1[0] = cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1).
setIndexedTypes(Integer.class, Person.class);
ccfgs1[1] = cacheConfiguration(GROUP1, "c2", PARTITIONED, TRANSACTIONAL, 1).
ccfgs1[1] = cacheConfiguration(GROUP2, "c2", PARTITIONED, TRANSACTIONAL, 1).
setIndexedTypes(Integer.class, Person.class);
ccfgs1[2] = cacheConfiguration(GROUP2, "c3", PARTITIONED, ATOMIC, 1).
ccfgs1[2] = cacheConfiguration(GROUP1, "c3", PARTITIONED, ATOMIC, 1).
setIndexedTypes(Integer.class, Person.class);
ccfgs1[3] = cacheConfiguration(GROUP2, "c4", PARTITIONED, TRANSACTIONAL, 1).
setIndexedTypes(Integer.class, Person.class);
Expand Down Expand Up @@ -224,8 +224,8 @@ public void testExpiryPolicy() throws Exception {
CacheConfiguration[] ccfgs1 = new CacheConfiguration[5];

ccfgs1[0] = cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1);
ccfgs1[1] = cacheConfiguration(GROUP1, "c2", PARTITIONED, TRANSACTIONAL, 1);
ccfgs1[2] = cacheConfiguration(GROUP2, "c3", PARTITIONED, ATOMIC, 1);
ccfgs1[1] = cacheConfiguration(GROUP2, "c2", PARTITIONED, TRANSACTIONAL, 1);
ccfgs1[2] = cacheConfiguration(GROUP1, "c3", PARTITIONED, ATOMIC, 1);
ccfgs1[3] = cacheConfiguration(GROUP2, "c4", PARTITIONED, TRANSACTIONAL, 1);
ccfgs1[4] = cacheConfiguration(null, "c5", PARTITIONED, ATOMIC, 1);

Expand Down Expand Up @@ -411,8 +411,8 @@ private void clusterRestart(int nodes, boolean staticCaches) throws Exception {
CacheConfiguration[] ccfgs = new CacheConfiguration[5];

ccfgs[0] = cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1);
ccfgs[1] = cacheConfiguration(GROUP1, "c2", PARTITIONED, TRANSACTIONAL, 1);
ccfgs[2] = cacheConfiguration(GROUP2, "c3", PARTITIONED, ATOMIC, 1);
ccfgs[1] = cacheConfiguration(GROUP2, "c2", PARTITIONED, TRANSACTIONAL, 1);
ccfgs[2] = cacheConfiguration(GROUP1, "c3", PARTITIONED, ATOMIC, 1);
ccfgs[3] = cacheConfiguration(GROUP2, "c4", PARTITIONED, TRANSACTIONAL, 1);
ccfgs[4] = cacheConfiguration(null, "c5", PARTITIONED, ATOMIC, 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@ public void testMultipleCachesInGroupWarn() throws Exception {
checkCachesSnapshotCreationAndRestore(prepareCacheConfs(null, "grp0", "grp0", null));
}

/** */
@Test
public void testMixedGroupWarnOnlyAtomic() throws Exception {
checkCachesSnapshotCreationAndRestore(prepareCacheConfs(null, null, "grp0", "grp0"));
}

/** */
private CacheConfiguration<Integer, Integer>[] prepareCacheConfs(String grp0, String grp1, String grp2, String grp3) {
return new CacheConfiguration[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ public void testJoinQuery2() throws Exception {
*/
@Test
public void testJoinQuery3() throws Exception {
joinQuery(GROUP1, GROUP1, PARTITIONED, PARTITIONED, TRANSACTIONAL, ATOMIC);
joinQuery(GROUP1, GROUP1, PARTITIONED, PARTITIONED, TRANSACTIONAL, TRANSACTIONAL);
}

/**
* @throws Exception If failed.
*/
@Test
public void testJoinQuery4() throws Exception {
joinQuery(GROUP1, GROUP1, REPLICATED, REPLICATED, ATOMIC, TRANSACTIONAL);
joinQuery(GROUP1, GROUP1, REPLICATED, REPLICATED, TRANSACTIONAL, TRANSACTIONAL);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class IgnitePdsSingleNodeWithIndexingAndGroupPutGetPersistenceSelfTest

int parts = aff != null ? aff.partitions() : RendezvousAffinityFunction.DFLT_PARTITION_COUNT;

ccfg.setGroupName("testGroup-parts" + parts);
ccfg.setGroupName("testGroup-parts" + ccfg.getAtomicityMode() + parts);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ public void testCachesViews() throws Exception {
.setName("cache_atomic_part")
.setAtomicityMode(CacheAtomicityMode.ATOMIC)
.setCacheMode(CacheMode.PARTITIONED)
.setGroupName("cache_grp")
.setGroupName("cache_grp_atomic")
.setNodeFilter(new TestNodeFilter(ignite0.cluster().localNode()))
);

Expand All @@ -1499,7 +1499,7 @@ public void testCachesViews() throws Exception {
.setName("cache_tx_part")
.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL)
.setCacheMode(CacheMode.PARTITIONED)
.setGroupName("cache_grp")
.setGroupName("cache_grp_tx")
.setNodeFilter(new TestNodeFilter(ignite0.cluster().localNode()))
);

Expand Down Expand Up @@ -1583,7 +1583,7 @@ public void testCachesViews() throws Exception {
assertEquals("cache_atomic_repl", execSql("SELECT CACHE_NAME FROM " + systemSchemaName() + ".CACHES WHERE " +
"CACHE_MODE = 'REPLICATED' AND ATOMICITY_MODE = 'ATOMIC' AND CACHE_NAME like 'cache%'").get(0).get(0));

assertEquals(2L, execSql("SELECT COUNT(*) FROM " + systemSchemaName() + ".CACHES WHERE CACHE_GROUP_NAME = 'cache_grp'")
assertEquals(2L, execSql("SELECT COUNT(*) FROM " + systemSchemaName() + ".CACHES WHERE CACHE_GROUP_NAME like 'cache_grp%'")
.get(0).get(0));

assertEquals("cache_atomic_repl", execSql("SELECT CACHE_NAME FROM " + systemSchemaName() + ".CACHES " +
Expand Down Expand Up @@ -1645,11 +1645,11 @@ public void testCachesViews() throws Exception {
String.class, String.class, String.class, String.class,
String.class, Long.class, Integer.class, Integer.class);

assertEquals(2, execSql("SELECT CACHE_COUNT FROM " + systemSchemaName() + ".CACHE_GROUPS " +
"WHERE CACHE_GROUP_NAME = 'cache_grp'").get(0).get(0));
assertEquals(1, execSql("SELECT CACHE_COUNT FROM " + systemSchemaName() + ".CACHE_GROUPS " +
"WHERE CACHE_GROUP_NAME like 'cache_grp%'").get(0).get(0));

assertEquals("cache_grp", execSql("SELECT CACHE_GROUP_NAME FROM " + systemSchemaName() + ".CACHE_GROUPS " +
"WHERE IS_SHARED = true AND CACHE_GROUP_NAME like 'cache%'").get(0).get(0));
assertEquals("cache_grp_atomic", execSql("SELECT CACHE_GROUP_NAME FROM " + systemSchemaName() + ".CACHE_GROUPS " +
"WHERE IS_SHARED = true AND CACHE_GROUP_NAME like 'cache%' AND ATOMICITY_MODE = 'ATOMIC'").get(0).get(0));

// Check index on ID column.
assertEquals("cache_tx_repl", execSql("SELECT CACHE_GROUP_NAME FROM " + systemSchemaName() + ".CACHE_GROUPS " +
Expand All @@ -1663,7 +1663,7 @@ public void testCachesViews() throws Exception {
.get(0).get(0));

// Check join by non-indexed column.
assertEquals("cache_grp", execSql("SELECT CG.CACHE_GROUP_NAME FROM " + systemSchemaName() + ".CACHES C JOIN " +
assertEquals("cache_grp_tx", execSql("SELECT CG.CACHE_GROUP_NAME FROM " + systemSchemaName() + ".CACHES C JOIN " +
systemSchemaName() + ".CACHE_GROUPS CG ON C.CACHE_GROUP_NAME = CG.CACHE_GROUP_NAME WHERE C.CACHE_NAME = 'cache_tx_part'")
.get(0).get(0));

Expand All @@ -1690,16 +1690,16 @@ public void testCachesViews() throws Exception {
.get(0).get(0));

// Check that cache groups are the same on different nodes.
assertEquals(6L, execSql("SELECT COUNT(*) FROM " + systemSchemaName() + ".CACHE_GROUPS " +
assertEquals(7L, execSql("SELECT COUNT(*) FROM " + systemSchemaName() + ".CACHE_GROUPS " +
"WHERE CACHE_GROUP_NAME like 'cache%'").get(0).get(0));

assertEquals(6L, execSql(ignite1, "SELECT COUNT(*) FROM " + systemSchemaName() + ".CACHE_GROUPS " +
assertEquals(7L, execSql(ignite1, "SELECT COUNT(*) FROM " + systemSchemaName() + ".CACHE_GROUPS " +
"WHERE CACHE_GROUP_NAME like 'cache%'").get(0).get(0));

assertEquals(6L, execSql(ignite2, "SELECT COUNT(*) FROM " + systemSchemaName() + ".CACHE_GROUPS " +
assertEquals(7L, execSql(ignite2, "SELECT COUNT(*) FROM " + systemSchemaName() + ".CACHE_GROUPS " +
"WHERE CACHE_GROUP_NAME like 'cache%'").get(0).get(0));

assertEquals(6L, execSql(ignite3, "SELECT COUNT(*) FROM " + systemSchemaName() + ".CACHE_GROUPS " +
assertEquals(7L, execSql(ignite3, "SELECT COUNT(*) FROM " + systemSchemaName() + ".CACHE_GROUPS " +
"WHERE CACHE_GROUP_NAME like 'cache%'").get(0).get(0));

assertEquals(5L, execSql(ignite0, "SELECT COUNT(*) FROM " + systemSchemaName() + ".CACHE_GROUPS " +
Expand Down

0 comments on commit 1141f17

Please sign in to comment.