Java Code Examples for org.apache.ignite.configuration.CacheConfiguration#setAffinity()
The following examples show how to use
org.apache.ignite.configuration.CacheConfiguration#setAffinity() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImputingExample.java From ignite with Apache License 2.0 | 6 votes |
/** * */ private static IgniteCache<Integer, Vector> createCache(Ignite ignite) { CacheConfiguration<Integer, Vector> cacheConfiguration = new CacheConfiguration<>(); cacheConfiguration.setName("PERSONS"); cacheConfiguration.setAffinity(new RendezvousAffinityFunction(false, 2)); IgniteCache<Integer, Vector> persons = ignite.createCache(cacheConfiguration); persons.put(1, new DenseVector(new Serializable[] {"Mike", 10, 1})); persons.put(1, new DenseVector(new Serializable[] {"John", 20, 2})); persons.put(1, new DenseVector(new Serializable[] {"George", 15, 1})); persons.put(1, new DenseVector(new Serializable[] {"Piter", 25, Double.NaN})); persons.put(1, new DenseVector(new Serializable[] {"Karl", Double.NaN, 1})); persons.put(1, new DenseVector(new Serializable[] {"Gustaw", 20, 2})); persons.put(1, new DenseVector(new Serializable[] {"Alex", 20, 2})); return persons; }
Example 2
Source File: AlgorithmSpecificDatasetExample.java From ignite with Apache License 2.0 | 6 votes |
/** * */ private static IgniteCache<Integer, Vector> createCache(Ignite ignite) { CacheConfiguration<Integer, Vector> cacheConfiguration = new CacheConfiguration<>(); cacheConfiguration.setName("PERSONS"); cacheConfiguration.setAffinity(new RendezvousAffinityFunction(false, 2)); IgniteCache<Integer, Vector> persons = ignite.createCache(cacheConfiguration); persons.put(1, new DenseVector(new Serializable[] {"Mike", 42, 10000})); persons.put(2, new DenseVector(new Serializable[] {"John", 32, 64000})); persons.put(3, new DenseVector(new Serializable[] {"George", 53, 120000})); persons.put(4, new DenseVector(new Serializable[] {"Karl", 24, 70000})); return persons; }
Example 3
Source File: StandardScalerExample.java From ignite with Apache License 2.0 | 6 votes |
/** * */ private static IgniteCache<Integer, Vector> createCache(Ignite ignite) { CacheConfiguration<Integer, Vector> cacheConfiguration = new CacheConfiguration<>(); cacheConfiguration.setName("PERSONS"); cacheConfiguration.setAffinity(new RendezvousAffinityFunction(false, 2)); IgniteCache<Integer, Vector> persons = ignite.createCache(cacheConfiguration); persons.put(1, new DenseVector(new Serializable[] {"Mike", 42, 10000})); persons.put(2, new DenseVector(new Serializable[] {"John", 32, 64000})); persons.put(3, new DenseVector(new Serializable[] {"George", 53, 120000})); persons.put(4, new DenseVector(new Serializable[] {"Karl", 24, 70000})); return persons; }
Example 4
Source File: BinarizationExample.java From ignite with Apache License 2.0 | 6 votes |
/** * */ private static IgniteCache<Integer, Vector> createCache(Ignite ignite) { CacheConfiguration<Integer, Vector> cacheConfiguration = new CacheConfiguration<>(); cacheConfiguration.setName("PERSONS"); cacheConfiguration.setAffinity(new RendezvousAffinityFunction(false, 2)); IgniteCache<Integer, Vector> persons = ignite.createCache(cacheConfiguration); persons.put(1, new DenseVector(new Serializable[] {"Mike", 42, 10000})); persons.put(2, new DenseVector(new Serializable[] {"John", 32, 64000})); persons.put(3, new DenseVector(new Serializable[] {"George", 53, 120000})); persons.put(4, new DenseVector(new Serializable[] {"Karl", 24, 70000})); return persons; }
Example 5
Source File: CacheMvccAbstractTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @param cacheMode Cache mode. * @param syncMode Write synchronization mode. * @param backups Number of backups. * @param parts Number of partitions. * @return Cache configuration. */ final CacheConfiguration<Object, Object> cacheConfiguration( CacheMode cacheMode, CacheWriteSynchronizationMode syncMode, int backups, int parts) { CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME); ccfg.setCacheMode(cacheMode); ccfg.setAtomicityMode(TRANSACTIONAL_SNAPSHOT); ccfg.setWriteSynchronizationMode(syncMode); ccfg.setAffinity(new RendezvousAffinityFunction(false, parts)); if (cacheMode == PARTITIONED) ccfg.setBackups(backups); return ccfg; }
Example 6
Source File: CacheStoreReadFromBackupTest.java From ignite with Apache License 2.0 | 6 votes |
/** */ @SuppressWarnings("unchecked") private CacheConfiguration cacheConfig(String cacheName) { CacheConfiguration ccfg = new CacheConfiguration<>(cacheName); ccfg.setCacheMode(cacheMode); ccfg.setBackups(backups); ccfg.setAtomicityMode(atomicityMode()); ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); ccfg.setAffinity(new RendezvousAffinityFunction(false, 1)); ccfg.setReadThrough(true); ccfg.setReadFromBackup(true); ccfg.setCacheStoreFactory(FactoryBuilder.factoryOf(TestStore.class)); if (near) ccfg.setNearConfiguration(new NearCacheConfiguration()); return ccfg; }
Example 7
Source File: NormalizationExample.java From ignite with Apache License 2.0 | 6 votes |
/** * */ private static IgniteCache<Integer, Vector> createCache(Ignite ignite) { CacheConfiguration<Integer, Vector> cacheConfiguration = new CacheConfiguration<>(); cacheConfiguration.setName("PERSONS"); cacheConfiguration.setAffinity(new RendezvousAffinityFunction(false, 2)); IgniteCache<Integer, Vector> persons = ignite.createCache(cacheConfiguration); persons.put(1, new DenseVector(new Serializable[] {"Mike", 10, 20})); persons.put(2, new DenseVector(new Serializable[] {"John", 20, 10})); persons.put(3, new DenseVector(new Serializable[] {"George", 30, 0})); persons.put(4, new DenseVector(new Serializable[] {"Karl", 25, 15})); return persons; }
Example 8
Source File: TrainingWithBinaryObjectExample.java From ignite with Apache License 2.0 | 6 votes |
/** * Populate cache with some binary objects. */ private static IgniteCache<Integer, BinaryObject> populateCache(Ignite ignite) { CacheConfiguration<Integer, BinaryObject> cacheConfiguration = new CacheConfiguration<>(); cacheConfiguration.setName("PERSONS"); cacheConfiguration.setAffinity(new RendezvousAffinityFunction(false, 2)); IgniteCache<Integer, BinaryObject> cache = ignite.createCache(cacheConfiguration).withKeepBinary(); BinaryObjectBuilder builder = ignite.binary().builder("testType"); for (int i = 0; i < 100; i++) { if (i > 50) cache.put(i, builder.setField("feature1", 0.0).setField("label", 0.0).build()); else cache.put(i, builder.setField("feature1", 1.0).setField("label", 1.0).build()); } return cache; }
Example 9
Source File: GridCacheDhtEntrySelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); CacheConfiguration cacheCfg = defaultCacheConfiguration(); cacheCfg.setCacheMode(PARTITIONED); cacheCfg.setAffinity(new RendezvousAffinityFunction(false, 10)); cacheCfg.setBackups(0); cacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); cacheCfg.setAtomicityMode(TRANSACTIONAL); cfg.setCacheConfiguration(cacheCfg); return cfg; }
Example 10
Source File: GridAffinityProcessorAbstractSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setForceServerMode(true); if (withCache) { CacheConfiguration cacheCfg = defaultCacheConfiguration(); cacheCfg.setName(CACHE_NAME); cacheCfg.setCacheMode(PARTITIONED); cacheCfg.setBackups(1); cacheCfg.setAffinity(affinityFunction()); cfg.setCacheConfiguration(cacheCfg); } return cfg; }
Example 11
Source File: GridCachePreloadingEvictionsSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); CacheConfiguration partCacheCfg = defaultCacheConfiguration(); partCacheCfg.setCacheMode(PARTITIONED); partCacheCfg.setAffinity(new GridCacheModuloAffinityFunction(1, 1)); partCacheCfg.setWriteSynchronizationMode(FULL_SYNC); partCacheCfg.setNearConfiguration(null); partCacheCfg.setEvictionPolicy(null); partCacheCfg.setRebalanceMode(ASYNC); partCacheCfg.setAtomicityMode(TRANSACTIONAL); // This test requires artificial slowing down of the preloading. partCacheCfg.setRebalanceThrottle(2000); cfg.setCacheConfiguration(partCacheCfg); cfg.setUserAttributes(F.asMap(GridCacheModuloAffinityFunction.IDX_ATTR, idxGen.getAndIncrement())); cfg.setNetworkTimeout(60000); return cfg; }
Example 12
Source File: GridCacheNearMultiNodeSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.NEAR_CACHE); MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.CACHE_STORE); MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.ENTRY_LOCK); IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); CacheConfiguration cacheCfg = defaultCacheConfiguration(); cacheCfg.setCacheMode(PARTITIONED); cacheCfg.setCacheStoreFactory(singletonFactory(store)); cacheCfg.setReadThrough(true); cacheCfg.setWriteThrough(true); cacheCfg.setLoadPreviousValue(true); cacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); cacheCfg.setAffinity(aff); cacheCfg.setAtomicityMode(atomicityMode()); cacheCfg.setBackups(BACKUPS); cacheCfg.setNearConfiguration(new NearCacheConfiguration()); cfg.setCacheConfiguration(cacheCfg); cfg.setUserAttributes(F.asMap(GridCacheModuloAffinityFunction.IDX_ATTR, cntr.getAndIncrement())); return cfg; }
Example 13
Source File: GridCacheRendezvousAffinityClientSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setForceServerMode(true); CacheConfiguration ccfg = defaultCacheConfiguration(); ccfg.setCacheMode(CacheMode.PARTITIONED); ccfg.setBackups(1); ccfg.setAffinity(new RendezvousAffinityFunction()); cfg.setCacheConfiguration(ccfg); return cfg; }
Example 14
Source File: JdbcThinPartitionAwarenessSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Check that in case of non-rendezvous affinity function, client side partition awareness is skipped. * * @throws Exception If failed. */ @Test public void testCacheWithNonRendezvousAffinityFunction() throws Exception { final String cacheName = "cacheWithCustomAffinityFunction"; CacheConfiguration<Object, Object> cache = prepareCacheConfig(cacheName); cache.setAffinity(new DummyAffinity()); ignite(0).createCache(cache); fillCache(cacheName); verifyPartitionResultIsNull("select * from \"" + cacheName + "\".Person where _key = 1", 1); }
Example 15
Source File: WalCompactionAfterRestartTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String name) throws Exception { IgniteConfiguration cfg = super.getConfiguration(name); cfg.setDataStorageConfiguration(new DataStorageConfiguration() .setDefaultDataRegionConfiguration(new DataRegionConfiguration() .setPersistenceEnabled(true) .setMaxSize(200L * 1024 * 1024)) .setWalMode(WALMode.LOG_ONLY) .setWalSegmentSize(512 * 1024) .setWalCompactionEnabled(true) .setMaxWalArchiveSize(2 * 512 * 1024) ); CacheConfiguration ccfg = new CacheConfiguration(); ccfg.setName(DEFAULT_CACHE_NAME); ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); ccfg.setAffinity(new RendezvousAffinityFunction(false, 16)); ccfg.setBackups(0); cfg.setCacheConfiguration(ccfg); cfg.setConsistentId(name); cfg.setIncludeEventTypes(EVT_WAL_SEGMENT_COMPACTED); return cfg; }
Example 16
Source File: GridCacheVersionTopologyChangeTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param name Cache name. * @param atomicityMode Cache atomicity mode. * @param aff Affinity. * @param backups Backups number. * @return Cache configuration. */ private CacheConfiguration<Object, Object> cacheConfiguration(String name, CacheAtomicityMode atomicityMode, AffinityFunction aff, int backups) { CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME); ccfg.setBackups(backups); ccfg.setName(name); ccfg.setAtomicityMode(atomicityMode); ccfg.setAffinity(aff); ccfg.setWriteSynchronizationMode(FULL_SYNC); return ccfg; }
Example 17
Source File: HibernateL2CacheSelfTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @param regionName Region name. * @return Cache configuration for {@link TransactionalDataRegion}. */ protected CacheConfiguration transactionalRegionConfiguration(String regionName) { CacheConfiguration cfg = new CacheConfiguration(DEFAULT_CACHE_NAME); cfg.setName(regionName); cfg.setCacheMode(PARTITIONED); cfg.setAtomicityMode(TRANSACTIONAL); cfg.setWriteSynchronizationMode(FULL_SYNC); cfg.setBackups(1); cfg.setAffinity(new RendezvousAffinityFunction(false, 10)); return cfg; }
Example 18
Source File: ClientAffinityAssignmentWithBaselineTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @param cacheName Cache name. */ private CacheConfiguration<Integer, String> cacheConfig(String cacheName) { CacheConfiguration<Integer, String> cfg = new CacheConfiguration<>(); if (PARTITIONED_ATOMIC_CACHE_NAME.equals(cacheName)) { cfg.setName(PARTITIONED_ATOMIC_CACHE_NAME); cfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); cfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); cfg.setAffinity(new RendezvousAffinityFunction(false, 32)); cfg.setBackups(2); } else if (PARTITIONED_TX_CACHE_NAME.equals(cacheName)) { cfg.setName(PARTITIONED_TX_CACHE_NAME); cfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); cfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); cfg.setAffinity(new RendezvousAffinityFunction(false, 32)); cfg.setBackups(2); } else if (PARTITIONED_TX_CLIENT_CACHE_NAME.equals(cacheName)) { cfg.setName(PARTITIONED_TX_CLIENT_CACHE_NAME); cfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); cfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); cfg.setAffinity(new RendezvousAffinityFunction(false, 32)); cfg.setBackups(2); } else if (PARTITIONED_TX_PRIM_SYNC_CACHE_NAME.equals(cacheName)) { cfg.setName(PARTITIONED_TX_PRIM_SYNC_CACHE_NAME); cfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); cfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.PRIMARY_SYNC); cfg.setAffinity(new RendezvousAffinityFunction(false, 41)); // To break collocation. cfg.setBackups(2); } else if (REPLICATED_ATOMIC_CACHE_NAME.equals(cacheName)) { cfg.setName(REPLICATED_ATOMIC_CACHE_NAME); cfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); cfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); cfg.setAffinity(new RendezvousAffinityFunction(false, 32)); cfg.setCacheMode(CacheMode.REPLICATED); } else if (REPLICATED_TX_CACHE_NAME.equals(cacheName)) { cfg.setName(REPLICATED_TX_CACHE_NAME); cfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); cfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); cfg.setAffinity(new RendezvousAffinityFunction(false, 32)); cfg.setCacheMode(CacheMode.REPLICATED); } else throw new IllegalArgumentException("Unexpected cache name"); return cfg; }
Example 19
Source File: CacheLateAffinityAssignmentTest.java From ignite with Apache License 2.0 | 2 votes |
/** * Wait for rebalance, cache is destroyed and created again. * * @throws Exception If failed. */ @Test public void testDelayAssignmentCacheDestroyCreate() throws Exception { Ignite ignite0 = startServer(0, 1); CacheConfiguration ccfg = cacheConfiguration(); ccfg.setName(CACHE_NAME2); ignite0.createCache(ccfg); DiscoverySpiTestListener lsnr = new DiscoverySpiTestListener(); ((IgniteDiscoverySpi)ignite0.configuration().getDiscoverySpi()).setInternalListener(lsnr); TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi)ignite0.configuration().getCommunicationSpi(); blockSupplySend(spi, CACHE_NAME2); lsnr.blockCustomEvent(CacheAffinityChangeMessage.class); startServer(1, 2); startGrid(3); checkAffinity(3, topVer(3, 0), false); spi.stopBlock(); lsnr.waitCustomEvent(); ignite0.destroyCache(CACHE_NAME2); ccfg = cacheConfiguration(); ccfg.setName(CACHE_NAME2); ccfg.setAffinity(affinityFunction(10)); ignite0.createCache(ccfg); lsnr.stopBlockCustomEvents(); checkAffinity(3, topVer(3, 1), false); checkAffinity(3, topVer(3, 2), false); idealAff.get(2L).remove(CU.cacheId(CACHE_NAME2)); calculateAffinity(3); checkAffinity(3, topVer(3, 3), true); }
Example 20
Source File: CacheLateAffinityAssignmentTest.java From ignite with Apache License 2.0 | 2 votes |
/** * @param cacheOnCrd If {@code false} does not create cache on coordinator. * @throws Exception If failed. */ private void cacheDestroyAndCreate(boolean cacheOnCrd) throws Exception { if (!cacheOnCrd) cacheNodeFilter = new TestCacheNodeExcludingFilter(Collections.singletonList(getTestIgniteInstanceName(0))); startServer(0, 1); startServer(1, 2); startServer(2, 3); checkAffinity(3, topVer(3, 1), true); startClient(3, 4); checkAffinity(4, topVer(4, 0), true); CacheConfiguration ccfg = cacheConfiguration(); ccfg.setName(CACHE_NAME2); ignite(1).createCache(ccfg); calculateAffinity(4); checkAffinity(4, topVer(4, 1), true); ignite(1).destroyCache(CACHE_NAME2); idealAff.get(4L).remove(CU.cacheId(CACHE_NAME2)); ccfg = cacheConfiguration(); ccfg.setName(CACHE_NAME2); ccfg.setAffinity(affinityFunction(10)); ignite(1).createCache(ccfg); calculateAffinity(4); checkAffinity(4, topVer(4, 3), true); checkCaches(); ignite(1).destroyCache(CACHE_NAME2); idealAff.get(4L).remove(CU.cacheId(CACHE_NAME2)); ccfg = cacheConfiguration(); ccfg.setName(CACHE_NAME2); ccfg.setAffinity(affinityFunction(20)); ignite(1).createCache(ccfg); calculateAffinity(4); checkAffinity(4, topVer(4, 5), true); }