@Override public void apply(Ignite ignite) { for (int i = 0; i < 100; i++) { CollectionConfiguration colCfg = new CollectionConfiguration(); colCfg.setCollocated(collocated); colCfg.setBackups(1); colCfg.setCacheMode(PARTITIONED); colCfg.setAtomicityMode(i % 2 == 0 ? TRANSACTIONAL : ATOMIC); IgniteSet set = ignite.set("set-" + i, colCfg); set.close(); } } });
/** * @param cfg Collection configuration. * @param name Cache name. * @param grpName Group name. * @return Cache configuration. */ private CacheConfiguration cacheConfiguration(CollectionConfiguration cfg, String name, String grpName) { CacheConfiguration ccfg = new CacheConfiguration(); ccfg.setName(name); ccfg.setGroupName(grpName); ccfg.setBackups(cfg.getBackups()); ccfg.setCacheMode(cfg.getCacheMode()); ccfg.setAtomicityMode(cfg.getAtomicityMode()); ccfg.setNodeFilter(cfg.getNodeFilter()); ccfg.setWriteSynchronizationMode(FULL_SYNC); ccfg.setRebalanceMode(SYNC); return ccfg; }
/** * Non-collocated mode only makes sense for and is only supported for PARTITIONED caches, so * collocated mode should be enabled for non-partitioned cache by default. * * @param cfg Collection configuration. * @return {@code True} If collocated mode should be enabled. */ private boolean isCollocated(CollectionConfiguration cfg) { return cfg != null && (cfg.isCollocated() || cfg.getCacheMode() != PARTITIONED); }
/** Get {@link CollectionConfiguration} with number of backups equal to {@link AtomicConfiguration} default */ private CollectionConfiguration getCollectionConfiguration() { return new CollectionConfiguration().setBackups(AtomicConfiguration.DFLT_BACKUPS); } }
/** * @param cacheAtomicityMode Atomicity mode. * @return Configuration. */ private static CollectionConfiguration collectionConfiguration(CacheAtomicityMode cacheAtomicityMode) { CollectionConfiguration colCfg = new CollectionConfiguration(); colCfg.setAtomicityMode(cacheAtomicityMode); return colCfg; }
/** * @return Collection configuration. */ protected CollectionConfiguration collectionConfiguration() { CollectionConfiguration colCfg = new CollectionConfiguration(); colCfg.setCacheMode(collectionCacheMode()); colCfg.setAtomicityMode(collectionCacheAtomicityMode()); colCfg.setOffHeapMaxMemory(collectionOffHeapMaxMemory()); if (colCfg.getCacheMode() == PARTITIONED) colCfg.setBackups(1); return colCfg; }
collectionCfg = new CollectionConfiguration(); collectionCfg.setAtomicityMode(cacheCfg.getAtomicityMode()); collectionCfg.setBackups(cacheCfg.getBackups()); break; collectionCfg = new CollectionConfiguration();
final CollectionConfiguration colCfg = collectionConfiguration(); colCfg.setCollocated(false); colCfg.setGroupName("testGroup"); colCfg.setCacheMode(CacheMode.PARTITIONED); colCfg.setCollocated(true);
public void initializeCache() throws Exception { CacheConfiguration<String, Integer> cacheCfg = new CacheConfiguration<>(); cacheCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); cacheCfg.setName(CHANNELS); cacheCfg.setBackups(2); channelCache = ignite.getOrCreateCache(cacheCfg); logger.info("Channel cache:"+channelCache); colCfg = new CollectionConfiguration(); colCfg.setCollocated(true); colCfg.setBackups(1); channelSize = Integer.parseInt(System.getProperty(CHANNEL_CAPACITY, DEFAULT_CHANNEL_CAPACITY)); logger.info("Starting alert receiver"); }
/** {@inheritDoc} */ @Override protected CollectionConfiguration collectionConfiguration() { CollectionConfiguration colCfg = super.collectionConfiguration(); colCfg.setBackups(0); return colCfg; }
/** * @throws Exception If failed. */ @Test public void testCanCloseQueueInInterruptedThread() throws Exception { doCloseByInterruptedThread(grid(0).queue(STRUCTURE_NAME, 0, new CollectionConfiguration())); }
/** {@inheritDoc} */ @Override protected CollectionConfiguration collectionConfiguration() { CollectionConfiguration colCfg = super.collectionConfiguration(); if (colCfg.getCacheMode() == PARTITIONED) colCfg.setBackups(1); return colCfg; }
/** * @param collocated Collocation flag. */ private void testCacheReuse(boolean collocated) { Ignite ignite = grid(0); CollectionConfiguration colCfg = collectionConfiguration().setCollocated(collocated); colCfg.setAtomicityMode(ATOMIC); colCfg.setGroupName("grp1"); IgniteSet set1 = ignite.set("set1", colCfg); IgniteSet set2 = ignite.set("set2", colCfg); assertEquals(separated(set1), cctx(set1).cacheId() != cctx(set2).cacheId()); colCfg.setAtomicityMode(TRANSACTIONAL); IgniteSet set3 = ignite.set("set3", colCfg); IgniteSet set4 = ignite.set("set4", colCfg); assertEquals(separated(set3), cctx(set3).cacheId() != cctx(set4).cacheId()); assertTrue(cctx(set1).cacheId() != cctx(set3).cacheId()); assertTrue(cctx(set1).groupId() == cctx(set3).groupId()); colCfg.setGroupName("gtp2"); IgniteSet set5 = ignite.set("set5", colCfg); IgniteSet set6 = ignite.set("set6", colCfg); assertEquals(separated(set5), cctx(set5).cacheId() != cctx(set6).cacheId()); assertTrue(cctx(set1).groupId() != cctx(set5).groupId()); Stream.of(set1, set2, set3, set4, set5, set6).forEach(IgniteSet::close); }
final String setName = "queue-rmv" + colCfg.getAtomicityMode(); if (colCfg.getAtomicityMode() == ATOMIC) commSpi.blockMessage(GridNearAtomicUpdateResponse.class); else assertTrue("Future was not failed. Atomic mode: " + colCfg.getAtomicityMode() + ".", (Boolean)fut.get());
/** * @throws Exception If failed. */ @Test public void testNotReuseCache() throws Exception { CollectionConfiguration colCfg1 = collectionConfiguration(); CollectionConfiguration colCfg2 = collectionConfiguration(); if (colCfg2.getAtomicityMode() == ATOMIC) colCfg2.setAtomicityMode(TRANSACTIONAL); else colCfg2.setAtomicityMode(ATOMIC); IgniteQueue queue1 = initQueue(0, "Queue1", 0, colCfg1); IgniteQueue queue2 = initQueue(0, "Queue2", 0, colCfg2); assertNotSame(getQueueCache(queue1), getQueueCache(queue2)); }
/** * Test that queues within the same group and compatible configurations are stored in the same cache. * * @throws Exception If failed. */ @Test public void testCacheReuse() throws Exception { CollectionConfiguration colCfg = collectionConfiguration(); colCfg.setAtomicityMode(ATOMIC); colCfg.setGroupName("grp1"); IgniteQueue queue1 = initQueue(0, "queue1", 100, colCfg); IgniteQueue queue2 = initQueue(0, "queue2", 100, colCfg); assert cctx(queue1).cacheId() == cctx(queue2).cacheId(); colCfg.setAtomicityMode(TRANSACTIONAL); IgniteQueue queue3 = initQueue(0, "queue3", 100, colCfg); IgniteQueue queue4 = initQueue(0, "queue4", 100, colCfg); assert cctx(queue3).cacheId() == cctx(queue4).cacheId(); assert cctx(queue1).cacheId() != cctx(queue3).cacheId(); assert cctx(queue1).groupId() == cctx(queue3).groupId(); colCfg.setGroupName("gtp2"); IgniteQueue queue5 = initQueue(0, "queue5", 100, colCfg); IgniteQueue queue6 = initQueue(0, "queue6", 100, colCfg); assert cctx(queue5).cacheId() == cctx(queue6).cacheId(); assert cctx(queue1).groupId() != cctx(queue5).groupId(); }
if (cfg != null && cfg.getGroupName() != null) grpName = cfg.getGroupName(); else grpName = DEFAULT_DS_GROUP_NAME; if (cfg != null && ((DistributedCollectionMetadata)oldVal).configuration().isCollocated() != cfg.isCollocated()) { throw new IgniteCheckedException("Another collection with the same name but different " + "configuration already created [name=" + name + ", newCollocated=" + cfg.isCollocated() + ", existingCollocated=" + !cfg.isCollocated() + ']');
/** * @param collocated Collocated flag. * @return Collection configuration. */ protected final CollectionConfiguration config(boolean collocated) { CollectionConfiguration cfg = collectionConfiguration(); cfg.setCollocated(collocated); return cfg; }
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); ((TcpCommunicationSpi)cfg.getCommunicationSpi()).setSharedMemoryPort(-1); AtomicConfiguration atomicCfg = new AtomicConfiguration(); atomicCfg.setCacheMode(collectionCacheMode()); atomicCfg.setBackups(collectionConfiguration().getBackups()); cfg.setAtomicConfiguration(atomicCfg); CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME); ccfg.setName(TRANSACTIONAL_CACHE_NAME); ccfg.setAtomicityMode(TRANSACTIONAL); cfg.setCacheConfiguration(ccfg); if (client) { cfg.setClientMode(client); ((TcpDiscoverySpi)(cfg.getDiscoverySpi())).setForceServerMode(true); } return cfg; }
collectionCfg = new CollectionConfiguration(); collectionCfg.setAtomicityMode(cacheCfg.getAtomicityMode()); collectionCfg.setBackups(cacheCfg.getBackups()); break; collectionCfg = new CollectionConfiguration();