/** * Executes example. * * @param args Command line arguments, none required. */ public static void main(String[] args) { try (Ignite ignite = Ignition.start("examples/config/portable/example-ignite-portable.xml")) { System.out.println(); System.out.println(">>> Portable objects cache put-get example started."); CacheConfiguration<Integer, Organization> cfg = new CacheConfiguration<>(); cfg.setCacheMode(CacheMode.PARTITIONED); cfg.setName(CACHE_NAME); cfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); try (IgniteCache<Integer, Organization> cache = ignite.createCache(cfg)) { if (ignite.cluster().forDataNodes(cache.getName()).nodes().isEmpty()) { System.out.println(); System.out.println(">>> This example requires remote cache node nodes to be started."); System.out.println(">>> Please start at least 1 remote cache node."); System.out.println(">>> Refer to example's javadoc for details on configuration."); System.out.println(); return; } putGet(cache); putGetPortable(cache); putGetAll(cache); putGetAllPortable(cache); System.out.println(); } finally { // Delete cache with its content completely. ignite.destroyCache(CACHE_NAME); } } }
/** Configure cacheEmployee. */ private static <K, V> CacheConfiguration<K, V> cacheCar() { CacheConfiguration<K, V> ccfg = cacheConfiguration(CAR_CACHE_NAME); // Configure cacheCar types. Collection<QueryEntity> qryEntities = new ArrayList<>(); // CAR. QueryEntity type = new QueryEntity(); qryEntities.add(type); type.setKeyType(Integer.class.getName()); type.setValueType(Car.class.getName()); // Query fields for CAR. LinkedHashMap<String, String> qryFlds = new LinkedHashMap<>(); qryFlds.put("id", "java.lang.Integer"); qryFlds.put("parkingId", "java.lang.Integer"); qryFlds.put("name", "java.lang.String"); type.setFields(qryFlds); ccfg.setQueryEntities(qryEntities); return ccfg; }
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); TcpDiscoverySpi disco = new TcpDiscoverySpi(); disco.setIpFinder(IP_FINDER); cfg.getTransactionConfiguration().setTxSerializableEnabled(true); cfg.setDiscoverySpi(disco); BasicWarmupClosure warmupClosure = new BasicWarmupClosure(); warmupClosure.setGridCount(2); warmupClosure.setIterationCount(10); warmupClosure.setKeyRange(10); cfg.setWarmupClosure(warmupClosure); CacheConfiguration<Integer, Integer> cacheCfg = new CacheConfiguration<>(); cacheCfg.setCacheMode(CacheMode.PARTITIONED); cacheCfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); cacheCfg.setBackups(1); cacheCfg.setName("test"); cfg.setCacheConfiguration(cacheCfg); return cfg; }
/** * In ATOMIC cache with CLOCK mode if key is updated from different nodes at same time only one * update wins others are ignored (can happen in test event when updates are executed from * different nodes sequentially), this delay is used to avoid lost updates. * * @param cache Cache. * @throws Exception If failed. */ protected void atomicClockModeDelay(IgniteCache cache) throws Exception { CacheConfiguration ccfg = (CacheConfiguration) cache.getConfiguration(CacheConfiguration.class); if (ccfg.getCacheMode() != LOCAL && ccfg.getAtomicityMode() == CacheAtomicityMode.ATOMIC && ccfg.getAtomicWriteOrderMode() == CacheAtomicWriteOrderMode.CLOCK) U.sleep(50); }
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); assertNotNull(clientNodes); ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(ipFinder); boolean client = false; for (Integer clientIdx : clientNodes) { if (getTestGridName(clientIdx).equals(gridName)) { client = true; break; } } cfg.setClientMode(client); CacheConfiguration ccfg = new CacheConfiguration(); ccfg.setBackups(0); ccfg.setRebalanceMode(SYNC); cfg.setCacheConfiguration(ccfg); return cfg; }
/** @throws Exception if failed. */ public void testDynamicCache() throws Exception { IgniteEx ignite = startGrid(0); String cacheName = "dynamic"; CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(cacheName); ccfg.setCacheMode(CacheMode.REPLICATED); ccfg.setRebalanceMode(CacheRebalanceMode.SYNC); IgniteCache<Object, Object> cache = ignite.createCache(ccfg); try (IgniteDataStreamer<Object, Object> streamer = ignite.dataStreamer(cacheName)) { streamer.allowOverwrite(true); for (int i = 0; i < 100_000; i++) streamer.addData(i, i); } assertEquals(CNT, cache.localSize()); Ignite ignite2 = startGrid(1); assertEquals( CNT, ignite2.cache(cacheName).localSize(CachePeekMode.PRIMARY, CachePeekMode.BACKUP)); for (int i = 0; i < CNT; i++) assertEquals(i, ignite2.cache(cacheName).localPeek(i)); }
/** @throws Exception If failed. */ public void testClientNodeNotInAffinity() throws Exception { checkCache(CACHE1, 2); checkCache(CACHE2, 2); checkCache(CACHE3, 2); checkCache(CACHE4, 3); checkCache(CACHE5, 2); Ignite client = ignite(NODE_CNT - 1); CacheConfiguration ccfg = new CacheConfiguration(); ccfg.setBackups(0); ccfg.setNodeFilter(new TestNodesFilter()); IgniteCache<Integer, Integer> cache = client.createCache(ccfg); try { checkCache(null, 1); } finally { cache.destroy(); } cache = client.createCache(ccfg, new NearCacheConfiguration()); try { checkCache(null, 1); } finally { cache.destroy(); } }
/** * Creates cache. * * @param name Cache name. * @param atomicityMode Atomicity mode. * @return Cache configuration. */ private static IgniteCache createCache(String name, CacheAtomicityMode atomicityMode) { CacheConfiguration ccfg = new CacheConfiguration(name); ccfg.setAtomicityMode(atomicityMode); ccfg.setWriteSynchronizationMode(FULL_SYNC); return Ignition.ignite().getOrCreateCache(ccfg); }
/** {@inheritDoc} */ @Override protected CacheConfiguration cacheConfiguration(String gridName) throws Exception { CacheConfiguration cfg = super.cacheConfiguration(gridName); cfg.setNearConfiguration(null); return cfg; }
/** * Create base cache configuration. * * @param name cache name. * @return Cache configuration with basic properties set. */ private static <K, V> CacheConfiguration<K, V> cacheConfiguration(String name) { CacheConfiguration<K, V> ccfg = new CacheConfiguration<>(name); ccfg.setAffinity(new RendezvousAffinityFunction(false, 32)); ccfg.setStartSize(100); ccfg.setStatisticsEnabled(true); return ccfg; }
/** * @param cfg Configuration. * @param cacheName Cache name. * @return Cache configuration. */ protected CacheConfiguration cacheConfiguration(IgniteConfiguration cfg, String cacheName) { for (CacheConfiguration ccfg : cfg.getCacheConfiguration()) { if (F.eq(cacheName, ccfg.getName())) return ccfg; } fail("Failed to find cache configuration for cache: " + cacheName); return null; }
/** Configure cacheEmployee. */ private static <K, V> CacheConfiguration<K, V> cacheEmployee() { CacheConfiguration<K, V> ccfg = cacheConfiguration(EMPLOYEE_CACHE_NAME); ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); ccfg.setBackups(1); // Configure cacheEmployee types. Collection<QueryEntity> qryEntities = new ArrayList<>(); // EMPLOYEE. QueryEntity type = new QueryEntity(); qryEntities.add(type); type.setKeyType(Integer.class.getName()); type.setValueType(Employee.class.getName()); // Query fields for EMPLOYEE. LinkedHashMap<String, String> qryFlds = new LinkedHashMap<>(); qryFlds.put("id", "java.lang.Integer"); qryFlds.put("departmentId", "java.lang.Integer"); qryFlds.put("managerId", "java.lang.Integer"); qryFlds.put("firstName", "java.lang.String"); qryFlds.put("lastName", "java.lang.String"); qryFlds.put("email", "java.lang.String"); qryFlds.put("phoneNumber", "java.lang.String"); qryFlds.put("hireDate", "java.sql.Date"); qryFlds.put("job", "java.lang.String"); qryFlds.put("salary", "java.lang.Double"); type.setFields(qryFlds); // Indexes for EMPLOYEE. Collection<QueryIndex> indexes = new ArrayList<>(); QueryIndex idx = new QueryIndex(); idx.setName("EMP_NAMES"); idx.setIndexType(QueryIndexType.SORTED); LinkedHashMap<String, Boolean> indFlds = new LinkedHashMap<>(); indFlds.put("firstName", Boolean.FALSE); indFlds.put("lastName", Boolean.FALSE); idx.setFields(indFlds); indexes.add(idx); indexes.add(new QueryIndex("salary", QueryIndexType.SORTED, false, "EMP_SALARY")); type.setIndexes(indexes); ccfg.setQueryEntities(qryEntities); return ccfg; }
/** * @return Cache configuration. * @throws Exception In case of error. */ protected CacheConfiguration cacheConfiguration() throws Exception { CacheConfiguration cfg = defaultCacheConfiguration(); cfg.setCacheMode(PARTITIONED); cfg.setBackups(1); cfg.setWriteSynchronizationMode(FULL_SYNC); cfg.setRebalanceMode(SYNC); return cfg; }
/** {@inheritDoc} */ @Override protected CacheConfiguration cacheConfiguration() { CacheConfiguration ccfg = super.cacheConfiguration(); ccfg.setCacheMode(CacheMode.REPLICATED); ccfg.setMemoryMode(CacheMemoryMode.OFFHEAP_TIERED); ccfg.setOffHeapMaxMemory(0); return ccfg; }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration c = super.getConfiguration(gridName); TcpDiscoverySpi disco = new TcpDiscoverySpi(); disco.setIpFinder(ipFinder); c.setDiscoverySpi(disco); // Cache. CacheConfiguration cc = defaultCacheConfiguration(); cc.setCacheMode(CacheMode.PARTITIONED); cc.setAtomicityMode(CacheAtomicityMode.ATOMIC); cc.setNearConfiguration(null); cc.setWriteSynchronizationMode(FULL_SYNC); cc.setRebalanceMode(SYNC); cc.setSwapEnabled(false); cc.setSqlFunctionClasses(GridQueryParsingTest.class); cc.setIndexedTypes( String.class, Address.class, String.class, Person.class); c.setCacheConfiguration(cc); return c; }
/** * Gets cache configuration. * * @return Cache configuration. */ private CacheConfiguration cacheConfiguration() { CacheConfiguration cacheCfg = defaultCacheConfiguration(); cacheCfg.setCacheMode(PARTITIONED); cacheCfg.setBackups(1); cacheCfg.setWriteSynchronizationMode(FULL_SYNC); if (noNodesFilter) cacheCfg.setNodeFilter(F.alwaysFalse()); return cacheCfg; }
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); CacheConfiguration cacheCfg = defaultCacheConfiguration(); cacheCfg.setCacheMode(REPLICATED); cfg.setCacheConfiguration(cacheCfg); return cfg; }
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); CacheConfiguration ccfg = new CacheConfiguration(STATIC_CACHE_NAME); ccfg.setCacheMode(CacheMode.REPLICATED); ccfg.setRebalanceMode(CacheRebalanceMode.SYNC); cfg.setCacheConfiguration(ccfg); return cfg; }
/** * @param ctx Context. * @param cfg Cache config. */ public CachePluginManager(GridKernalContext ctx, CacheConfiguration cfg) { this.ctx = ctx; this.cfg = cfg; if (cfg.getPluginConfigurations() != null) { for (CachePluginConfiguration cachePluginCfg : cfg.getPluginConfigurations()) { CachePluginContext pluginCtx = new GridCachePluginContext(ctx, cfg, cachePluginCfg); CachePluginProvider provider = cachePluginCfg.createProvider(pluginCtx); providersList.add(provider); providersMap.put(pluginCtx, provider); } } }
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { assert gridName != null; IgniteConfiguration cfg = super.getConfiguration(gridName); TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); discoSpi.setIpFinder(IP_FINDER); cfg.setDiscoverySpi(discoSpi); if (gridName.contains("cache")) { String cacheName = "test-checkpoints"; CacheConfiguration cacheCfg = defaultCacheConfiguration(); cacheCfg.setName(cacheName); cacheCfg.setWriteSynchronizationMode(FULL_SYNC); CacheCheckpointSpi spi = new CacheCheckpointSpi(); spi.setCacheName(cacheName); cfg.setCacheConfiguration(cacheCfg); cfg.setCheckpointSpi(spi); } else if (gridName.contains("jdbc")) { JdbcCheckpointSpi spi = new JdbcCheckpointSpi(); jdbcDataSource ds = new jdbcDataSource(); ds.setDatabase("jdbc:hsqldb:mem:gg_test_" + getClass().getSimpleName()); ds.setUser("sa"); ds.setPassword(""); spi.setDataSource(ds); spi.setCheckpointTableName("test_checkpoints"); spi.setKeyFieldName("key"); spi.setValueFieldName("value"); spi.setValueFieldType("longvarbinary"); spi.setExpireDateFieldName("expire_date"); cfg.setCheckpointSpi(spi); } return cfg; }
/** * <code>initiate</code> starts the operations of this system handler. All excecution code for the * plugins is expected to begin at this point. * * @throws UnRetriableException */ @Override public void initiate() throws UnRetriableException { // Initiate the session reset manager. SessionResetManager sessionResetManager = new SessionResetManager(); sessionResetManager.setWorker(this); sessionResetManager.setDatastore(this.getDatastore()); setSessionResetManager(sessionResetManager); String igniteCacheName = "dumbTester"; CacheConfiguration clCfg = new CacheConfiguration(); clCfg.setName(igniteCacheName); clCfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); clCfg.setCacheMode(CacheMode.PARTITIONED); clCfg.setMemoryMode(CacheMemoryMode.ONHEAP_TIERED); LruEvictionPolicy lruEvictionPolicy = new LruEvictionPolicy(5170000); clCfg.setEvictionPolicy(lruEvictionPolicy); clCfg.setSwapEnabled(true); // if(subscriptions instanceof IgniteCache) { // subscriptions = getIgnite().createCache(clCfg); // } // Initiate unirest properties. Unirest.setTimeouts(5000, 5000); }
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); if (getTestGridName(0).equals(gridName)) { cfg.setClientMode(true); cfg.setCacheConfiguration(); } if (getTestGridName(10).equals(gridName)) { CacheConfiguration cc = cfg.getCacheConfiguration()[0]; cc.setRebalanceDelay(-1); } return cfg; }
/** {@inheritDoc} */ @Override public CacheObjectContext contextForCache(CacheConfiguration cfg) throws IgniteCheckedException { assert cfg != null; boolean portableEnabled = marsh instanceof BinaryMarshaller && !GridCacheUtils.isSystemCache(cfg.getName()) && !GridCacheUtils.isIgfsCache(ctx.config(), cfg.getName()); CacheObjectContext ctx0 = super.contextForCache(cfg); CacheObjectContext res = new CacheObjectPortableContext( ctx, ctx0.copyOnGet(), ctx0.storeValue(), portableEnabled, ctx0.addDeploymentInfo()); ctx.resource().injectGeneric(res.defaultAffMapper()); return res; }
/** @throws Exception If failed. */ public void testLoadBean() throws Exception { final String path = "modules/spring/src/test/java/org/apache/ignite/internal/cache.xml"; GridTestUtils.assertThrows( log, new Callable<Object>() { @Override public Object call() throws Exception { Ignition.loadSpringBean(path, "wrongName"); return null; } }, IgniteException.class, null); CacheConfiguration cfg = Ignition.loadSpringBean(path, "cache-configuration"); assertEquals("TestDynamicCache", cfg.getName()); }
/** @throws Exception If failed. */ public void testSystemCache() throws Exception { CollectionConfiguration colCfg = collectionConfiguration(); IgniteQueue queue = grid(0).queue("Queue1", 0, colCfg); final CacheConfiguration ccfg = getQueueCache(queue); GridTestUtils.assertThrows( log, new Callable<Object>() { @Override public Object call() throws Exception { grid(0).cache(ccfg.getName()); return null; } }, IllegalStateException.class, "Failed to get cache because it is a system cache"); assertNotNull(((IgniteKernal) grid(0)).internalCache(ccfg.getName())); }
/** * @param ccfg Cache configuration. * @return Data transfer object for affinity configuration properties. */ public static VisorCacheAffinityConfiguration from(CacheConfiguration ccfg) { AffinityFunction aff = ccfg.getAffinity(); Boolean excludeNeighbors = null; if (aff instanceof RendezvousAffinityFunction) { RendezvousAffinityFunction hashAffFunc = (RendezvousAffinityFunction) aff; excludeNeighbors = hashAffFunc.isExcludeNeighbors(); } VisorCacheAffinityConfiguration cfg = new VisorCacheAffinityConfiguration(); cfg.function = compactClass(aff); cfg.mapper = compactClass(ccfg.getAffinityMapper()); cfg.partitions = aff.partitions(); cfg.partitionedBackups = ccfg.getBackups(); cfg.excludeNeighbors = excludeNeighbors; return cfg; }
/** * Executes example. * * @param args Command line arguments, none required. */ public static void main(String[] args) { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { System.out.println(); System.out.println(">>> Cache star schema example started."); CacheConfiguration<Integer, FactPurchase> factCacheCfg = new CacheConfiguration<>(PARTITIONED_CACHE_NAME); factCacheCfg.setCacheMode(CacheMode.PARTITIONED); factCacheCfg.setIndexedTypes(Integer.class, FactPurchase.class); CacheConfiguration<Integer, Object> dimCacheCfg = new CacheConfiguration<>(REPLICATED_CACHE_NAME); dimCacheCfg.setCacheMode(CacheMode.REPLICATED); dimCacheCfg.setIndexedTypes( Integer.class, DimStore.class, Integer.class, DimProduct.class); try (IgniteCache<Integer, FactPurchase> factCache = ignite.getOrCreateCache(factCacheCfg); IgniteCache<Integer, Object> dimCache = ignite.getOrCreateCache(dimCacheCfg)) { populateDimensions(dimCache); populateFacts(factCache); queryStorePurchases(); queryProductPurchases(); } } }
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(IP_FINDER); CacheConfiguration ccfg = new CacheConfiguration(); ccfg.setWriteSynchronizationMode(FULL_SYNC); QueryEntity person = new QueryEntity(); person.setKeyType(TestKey.class.getName()); person.setValueType(Person.class.getName()); person.addQueryField("name", String.class.getName(), null); ccfg.setQueryEntities(Arrays.asList(person)); cfg.setCacheConfiguration(ccfg); cfg.setMarshaller(null); return cfg; }
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); CacheConfiguration<?, ?> cache = defaultCacheConfiguration(); cache.setCacheMode(PARTITIONED); cache.setBackups(1); cache.setWriteSynchronizationMode(FULL_SYNC); cache.setIndexedTypes(Integer.class, TestObject.class); cfg.setCacheConfiguration(cache); TcpDiscoverySpi disco = new TcpDiscoverySpi(); disco.setIpFinder(IP_FINDER); cfg.setDiscoverySpi(disco); cfg.setConnectorConfiguration(new ConnectorConfiguration()); return cfg; }
/** * @param name Cache name. * @param cacheMode Cache mode. * @param parts Number of partitions. * @return Cache configuration. */ private CacheConfiguration cacheConfiguration(String name, CacheMode cacheMode, int parts) { CacheConfiguration ccfg = new CacheConfiguration(); ccfg.setName(name); ccfg.setCacheMode(cacheMode); ccfg.setAtomicityMode(TRANSACTIONAL); ccfg.setWriteSynchronizationMode(FULL_SYNC); if (cacheMode == PARTITIONED) ccfg.setBackups(1); ccfg.setAffinity(new RendezvousAffinityFunction(false, parts)); return ccfg; }