Java Code Examples for org.apache.ignite.configuration.CacheConfiguration#getCacheMode()
The following examples show how to use
org.apache.ignite.configuration.CacheConfiguration#getCacheMode() .
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: PartitionExtractor.java From ignite with Apache License 2.0 | 6 votes |
/** * Prepare affinity identifier for cache. * * @param ccfg Cache configuration. * @return Affinity identifier. */ private static PartitionTableAffinityDescriptor affinityForCache(CacheConfiguration ccfg) { // Partition could be extracted only from PARTITIONED caches. if (ccfg.getCacheMode() != CacheMode.PARTITIONED) return null; PartitionAffinityFunctionType aff = ccfg.getAffinity().getClass().equals(RendezvousAffinityFunction.class) ? PartitionAffinityFunctionType.RENDEZVOUS : PartitionAffinityFunctionType.CUSTOM; boolean hasNodeFilter = ccfg.getNodeFilter() != null && !(ccfg.getNodeFilter() instanceof CacheConfiguration.IgniteAllNodesPredicate); return new PartitionTableAffinityDescriptor( aff, ccfg.getAffinity().partitions(), hasNodeFilter, ccfg.getDataRegionName() ); }
Example 2
Source File: IgniteAbstractTxSuspendResumeTest.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { super.beforeTest(); Ignite client = ignite(gridCount() - 1); assertTrue(client.cluster().localNode().isClient()); for (CacheConfiguration<Integer, Integer> ccfg : cacheConfigurations()) { grid(0).createCache(ccfg); if (ccfg.getCacheMode() != LOCAL && !FORCE_MVCC) client.createNearCache(ccfg.getName(), new NearCacheConfiguration<>()); } awaitPartitionMapExchange(); }
Example 3
Source File: IgniteAbstractTxSuspendResumeTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @param c Closure. */ protected void executeTestForAllCaches(CI2<Ignite, IgniteCache<Integer, Integer>> c) { for (int i = 0; i < gridCount(); i++) { Ignite ignite = ignite(i); ClusterNode locNode = ignite.cluster().localNode(); log.info(">>> Run test for node [node=" + locNode.id() + ", client=" + locNode.isClient() + ']'); for (CacheConfiguration ccfg : cacheConfigurations()) { if (locNode.isClient() && ccfg.getCacheMode() == LOCAL) continue; log.info(">>>> Run test for cache " + ccfg.getName()); c.apply(ignite, ignite.cache(ccfg.getName())); } } }
Example 4
Source File: CacheSerializableTransactionsTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @param cache Cache. * @return Test keys. * @throws Exception If failed. */ private List<Integer> testKeys(IgniteCache<Integer, Integer> cache) throws Exception { CacheConfiguration ccfg = cache.getConfiguration(CacheConfiguration.class); List<Integer> keys = new ArrayList<>(); if (!cache.unwrap(Ignite.class).configuration().isClientMode()) { if (ccfg.getCacheMode() == PARTITIONED) keys.add(nearKey(cache)); keys.add(primaryKey(cache)); if (ccfg.getBackups() != 0) keys.add(backupKey(cache)); } else keys.add(nearKey(cache)); return keys; }
Example 5
Source File: CacheGetEntryAbstractTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @param e Entry. * @param cache Cache. * @throws Exception If failed. */ private void compareVersionWithPrimaryNode(CacheEntry<Integer, ?> e, IgniteCache<Integer, TestValue> cache) throws Exception { CacheConfiguration cfg = cache.getConfiguration(CacheConfiguration.class); if (cfg.getCacheMode() != LOCAL) { Ignite prim = primaryNode(e.getKey(), cache.getName()); GridCacheAdapter<Object, Object> cacheAdapter = ((IgniteKernal)prim).internalCache(cache.getName()); if (cfg.getNearConfiguration() != null) cacheAdapter = ((GridNearCacheAdapter)cacheAdapter).dht(); IgniteCacheObjectProcessor cacheObjects = cacheAdapter.context().cacheObjects(); CacheObjectContext cacheObjCtx = cacheAdapter.context().cacheObjectContext(); GridCacheEntryEx mapEntry = cacheAdapter.entryEx(cacheObjects.toCacheKeyObject( cacheObjCtx, cacheAdapter.context(), e.getKey(), true)); mapEntry.unswap(); assertNotNull("No entry for key: " + e.getKey(), mapEntry); assertEquals(mapEntry.version(), e.version()); } }
Example 6
Source File: ClientCachePartitionsRequest.java From ignite with Apache License 2.0 | 6 votes |
/** * @param ccfg Cache configuration. * @return True if cache is applicable for partition awareness optimisation. */ private static boolean isApplicable(CacheConfiguration ccfg) { // Partition could be extracted only from PARTITIONED caches. if (ccfg.getCacheMode() != CacheMode.PARTITIONED) return false; // Only caches with no custom affinity key mapper is supported. AffinityKeyMapper keyMapper = ccfg.getAffinityMapper(); if (!(keyMapper instanceof CacheDefaultBinaryAffinityKeyMapper)) return false; // Only RendezvousAffinityFunction is supported for now. if (!ccfg.getAffinity().getClass().equals(RendezvousAffinityFunction.class)) return false; IgnitePredicate filter = ccfg.getNodeFilter(); boolean hasNodeFilter = filter != null && !(filter instanceof CacheConfiguration.IgniteAllNodesPredicate); // We cannot be sure that two caches are co-located if custom node filter is present. // Note that technically we may try to compare two filters. However, this adds unnecessary complexity // and potential deserialization issues. return !hasNodeFilter; }
Example 7
Source File: GridCacheClientModesAbstractSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception { if (nearEnabled()) MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.NEAR_CACHE); CacheConfiguration cfg = super.cacheConfiguration(igniteInstanceName); cfg.setCacheStoreFactory(null); cfg.setReadThrough(false); cfg.setWriteThrough(false); cfg.setBackups(1); if (cfg.getCacheMode() == REPLICATED) cfg.setAffinity(null); else cfg.setAffinity(new RendezvousAffinityFunction(false, 32)); return cfg; }
Example 8
Source File: JdbcThinWalModeChangeSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override protected void createCache(Ignite node, CacheConfiguration ccfg) throws IgniteCheckedException { String template = ccfg.getCacheMode() == CacheMode.PARTITIONED ? QueryUtils.TEMPLATE_PARTITIONED : QueryUtils.TEMPLATE_REPLICATED; String cmd = "CREATE TABLE IF NOT EXISTS " + ccfg.getName() + " (k BIGINT PRIMARY KEY, v BIGINT) WITH \"" + "TEMPLATE=" + template + ", " + "CACHE_NAME=" + ccfg.getName() + ", " + "ATOMICITY=" + ccfg.getAtomicityMode() + (ccfg.getGroupName() != null ? ", CACHE_GROUP=" + ccfg.getGroupName() : "") + (ccfg.getDataRegionName() != null ? ", DATA_REGION=" + ccfg.getDataRegionName() : "") + "\""; execute(node, cmd); alignCacheTopologyVersion(node); }
Example 9
Source File: GridCacheUtils.java From ignite with Apache License 2.0 | 5 votes |
/** * Checks if near cache is enabled for cache configuration. * * @param cfg Cache configuration to check. * @return {@code True} if near cache is enabled, {@code false} otherwise. */ @SuppressWarnings("SimplifiableIfStatement") public static boolean isNearEnabled(CacheConfiguration cfg) { if (cfg.getCacheMode() == LOCAL) return false; return cfg.getNearConfiguration() != null; }
Example 10
Source File: ValidationOnNodeJoinUtils.java From ignite with Apache License 2.0 | 5 votes |
/** * @param c Ignite Configuration. * @param cc Cache Configuration. * @param ctx Context. * @return {@code true} if cache is starting on client node and this node is affinity node for the cache. */ private static boolean storesLocallyOnClient(IgniteConfiguration c, CacheConfiguration cc, GridKernalContext ctx) { if (c.isClientMode() && c.getDataStorageConfiguration() == null) { if (cc.getCacheMode() == LOCAL) return true; return ctx.discovery().cacheAffinityNode(ctx.discovery().localNode(), cc.getName()); } else return false; }
Example 11
Source File: GridCacheAbstractFailoverSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception { CacheConfiguration cfg = super.cacheConfiguration(igniteInstanceName); cfg.setRebalanceMode(SYNC); if (cfg.getCacheMode() == CacheMode.PARTITIONED) cfg.setBackups(TOP_CHANGE_THREAD_CNT); return cfg; }
Example 12
Source File: IgniteSqlNotNullConstraintTest.java From ignite with Apache License 2.0 | 5 votes |
/** */ private void executeForNodeAndCache(CacheConfiguration ccfg, Ignite ignite, TestClosure clo, TransactionConcurrency concurrency, TransactionIsolation isolation) throws Exception { String cacheName = ccfg.getName(); IgniteCache cache; if (ignite.configuration().isClientMode() && ccfg.getCacheMode() == CacheMode.PARTITIONED && ccfg.getNearConfiguration() != null) cache = ignite.getOrCreateNearCache(ccfg.getName(), ccfg.getNearConfiguration()); else cache = ignite.cache(ccfg.getName()); cache.removeAll(); assertEquals(0, cache.size()); clo.configure(ignite, cache, concurrency, isolation); log.info("Running test with node " + ignite.name() + ", cache " + cacheName); clo.key1 = 1; clo.key2 = 4; clo.run(); }
Example 13
Source File: WebSessionFilter.java From ignite with Apache License 2.0 | 5 votes |
/** * Init cache. */ @SuppressWarnings("unchecked") void initCache() { cache = webSesIgnite.cache(cacheName); binaryCache = webSesIgnite.cache(cacheName); if (cache == null) throw new IgniteException("Cache for web sessions is not started (is it configured?): " + cacheName); CacheConfiguration cacheCfg = cache.getConfiguration(CacheConfiguration.class); if (cacheCfg.getWriteSynchronizationMode() == FULL_ASYNC) throw new IgniteException("Cache for web sessions cannot be in FULL_ASYNC mode: " + cacheName); if (!cacheCfg.isEagerTtl()) throw new IgniteException("Cache for web sessions cannot operate with lazy TTL. " + "Consider setting eagerTtl to true for cache: " + cacheName); if (cacheCfg.getCacheMode() == LOCAL) U.quietAndWarn(webSesIgnite.log(), "Using LOCAL cache for web sessions caching " + "(this is only OK in test mode): " + cacheName); if (cacheCfg.getCacheMode() == PARTITIONED && cacheCfg.getAtomicityMode() != ATOMIC) U.quietAndWarn(webSesIgnite.log(), "Using " + cacheCfg.getAtomicityMode() + " atomicity for web sessions " + "caching (switch to ATOMIC mode for better performance)"); txEnabled = cacheCfg.getAtomicityMode() == TRANSACTIONAL; }
Example 14
Source File: ZookeeperDiscoveryCommunicationFailureTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @param expCaches Expected caches information (when late assignment doen and rebalance finished). */ void checkCachesInfo(Map<String, T3<Integer, Integer, Integer>> expCaches) { assertNotNull(caches); assertNotNull(affMap); assertNotNull(ownersMap); for (Map.Entry<String, T3<Integer, Integer, Integer>> e : expCaches.entrySet()) { String cacheName = e.getKey(); int parts = e.getValue().get1(); int backups = e.getValue().get2(); int expNodes = e.getValue().get3(); assertTrue(cacheName, caches.containsKey(cacheName)); CacheConfiguration ccfg = caches.get(cacheName); assertEquals(cacheName, ccfg.getName()); if (ccfg.getCacheMode() == CacheMode.REPLICATED) assertEquals(Integer.MAX_VALUE, ccfg.getBackups()); else assertEquals(backups, ccfg.getBackups()); assertEquals(parts, ccfg.getAffinity().partitions()); List<List<ClusterNode>> aff = affMap.get(cacheName); assertNotNull(cacheName, aff); assertEquals(parts, aff.size()); List<List<ClusterNode>> owners = ownersMap.get(cacheName); assertNotNull(cacheName, owners); assertEquals(parts, owners.size()); for (int i = 0; i < parts; i++) { List<ClusterNode> partAff = aff.get(i); assertEquals(cacheName, expNodes, partAff.size()); List<ClusterNode> partOwners = owners.get(i); assertEquals(cacheName, expNodes, partOwners.size()); assertTrue(cacheName, partAff.containsAll(partOwners)); assertTrue(cacheName, partOwners.containsAll(partAff)); } } }
Example 15
Source File: ClusterCachesInfo.java From ignite with Apache License 2.0 | 4 votes |
/** * @param cfg Existing configuration. * @param startCfg Cache configuration to start. * @throws IgniteCheckedException If validation failed. */ private void validateCacheGroupConfiguration(CacheConfiguration cfg, CacheConfiguration startCfg) throws IgniteCheckedException { GridCacheAttributes attr1 = new GridCacheAttributes(cfg); GridCacheAttributes attr2 = new GridCacheAttributes(startCfg); CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "cacheMode", "Cache mode", cfg.getCacheMode(), startCfg.getCacheMode(), true); if (cfg.getAtomicityMode() == TRANSACTIONAL_SNAPSHOT || startCfg.getAtomicityMode() == TRANSACTIONAL_SNAPSHOT) 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); CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "affinityPartitionsCount", "Affinity partitions count", attr1.affinityPartitionsCount(), attr2.affinityPartitionsCount(), true); CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "nodeFilter", "Node filter", attr1.nodeFilterClassName(), attr2.nodeFilterClassName(), true); CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "dataRegionName", "Data region", cfg.getDataRegionName(), startCfg.getDataRegionName(), true); CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "topologyValidator", "Topology validator", attr1.topologyValidatorClassName(), attr2.topologyValidatorClassName(), true); CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "partitionLossPolicy", "Partition Loss Policy", cfg.getPartitionLossPolicy(), startCfg.getPartitionLossPolicy(), true); CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "rebalanceMode", "Rebalance mode", cfg.getRebalanceMode(), startCfg.getRebalanceMode(), true); CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "rebalanceDelay", "Rebalance delay", cfg.getRebalanceDelay(), startCfg.getRebalanceDelay(), false); CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "rebalanceOrder", "Rebalance order", cfg.getRebalanceOrder(), startCfg.getRebalanceOrder(), false); if (cfg.getCacheMode() == PARTITIONED) { CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "backups", "Backups", cfg.getBackups(), startCfg.getBackups(), true); } CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "encryptionEnabled", "Encrypted", cfg.isEncryptionEnabled(), startCfg.isEncryptionEnabled(), true); CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "diskPageCompression", "Disk page compression", cfg.getDiskPageCompression(), startCfg.getDiskPageCompression(), true); CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "diskPageCompressionLevel", "Disk page compression level", cfg.getDiskPageCompressionLevel(), startCfg.getDiskPageCompressionLevel(), true); }
Example 16
Source File: VisorCachePartitionsTask.java From ignite with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override protected VisorCachePartitions run(VisorCachePartitionsTaskArg arg) throws IgniteException { String cacheName = arg.getCacheName(); if (debug) log(ignite.log(), "Collecting partitions for cache: " + escapeName(cacheName)); VisorCachePartitions parts = new VisorCachePartitions(); GridCacheAdapter ca = ignite.context().cache().internalCache(cacheName); // Cache was not started. if (ca == null || !ca.context().started() || VisorTaskUtils.isRestartingCache(ignite, cacheName)) return parts; CacheConfiguration cfg = ca.configuration(); CacheMode mode = cfg.getCacheMode(); boolean partitioned = (mode == CacheMode.PARTITIONED || mode == CacheMode.REPLICATED) && ca.context().affinityNode(); if (partitioned) { GridDhtCacheAdapter dca = null; if (ca instanceof GridNearCacheAdapter) dca = ((GridNearCacheAdapter)ca).dht(); else if (ca instanceof GridDhtCacheAdapter) dca = (GridDhtCacheAdapter)ca; if (dca != null) { GridDhtPartitionTopology top = dca.topology(); List<GridDhtLocalPartition> locParts = top.localPartitions(); for (GridDhtLocalPartition part : locParts) { int p = part.id(); long sz = part.dataStore().cacheSize(ca.context().cacheId()); // Pass NONE as topology version in order not to wait for topology version. if (part.primary(AffinityTopologyVersion.NONE)) parts.addPrimary(p, sz); else if (part.state() == GridDhtPartitionState.OWNING && part.backup(AffinityTopologyVersion.NONE)) parts.addBackup(p, sz); } } } return parts; }
Example 17
Source File: VisorCacheConfiguration.java From ignite with Apache License 2.0 | 4 votes |
/** * Create data transfer object for cache configuration properties. * * @param ignite Grid. * @param ccfg Cache configuration. * @param dynamicDeploymentId Dynamic deployment ID. */ public VisorCacheConfiguration(IgniteEx ignite, CacheConfiguration ccfg, IgniteUuid dynamicDeploymentId) { name = ccfg.getName(); grpName = ccfg.getGroupName(); this.dynamicDeploymentId = dynamicDeploymentId; mode = ccfg.getCacheMode(); atomicityMode = ccfg.getAtomicityMode(); eagerTtl = ccfg.isEagerTtl(); writeSynchronizationMode = ccfg.getWriteSynchronizationMode(); invalidate = ccfg.isInvalidate(); maxConcurrentAsyncOps = ccfg.getMaxConcurrentAsyncOperations(); interceptor = compactClass(ccfg.getInterceptor()); dfltLockTimeout = ccfg.getDefaultLockTimeout(); qryEntities = VisorQueryEntity.list(ccfg.getQueryEntities()); jdbcTypes = VisorCacheJdbcType.list(ccfg.getCacheStoreFactory()); statisticsEnabled = ccfg.isStatisticsEnabled(); mgmtEnabled = ccfg.isManagementEnabled(); ldrFactory = compactClass(ccfg.getCacheLoaderFactory()); writerFactory = compactClass(ccfg.getCacheWriterFactory()); expiryPlcFactory = compactClass(ccfg.getExpiryPolicyFactory()); sys = ignite.context().cache().systemCache(ccfg.getName()); storeKeepBinary = ccfg.isStoreKeepBinary(); onheapCache = ccfg.isOnheapCacheEnabled(); partLossPlc = ccfg.getPartitionLossPolicy(); qryParallelism = ccfg.getQueryParallelism(); affinityCfg = new VisorCacheAffinityConfiguration(ccfg); rebalanceCfg = new VisorCacheRebalanceConfiguration(ccfg); evictCfg = new VisorCacheEvictionConfiguration(ccfg); nearCfg = new VisorCacheNearConfiguration(ccfg); storeCfg = new VisorCacheStoreConfiguration(ignite, ccfg); qryCfg = new VisorQueryConfiguration(ccfg); cpOnRead = ccfg.isCopyOnRead(); evictFilter = compactClass(ccfg.getEvictionFilter()); lsnrConfigurations = compactIterable(ccfg.getCacheEntryListenerConfigurations()); loadPrevVal = ccfg.isLoadPreviousValue(); dataRegName = ccfg.getDataRegionName(); sqlIdxMaxInlineSize = ccfg.getSqlIndexMaxInlineSize(); nodeFilter = compactClass(ccfg.getNodeFilter()); qryDetailMetricsSz = ccfg.getQueryDetailMetricsSize(); readFromBackup = ccfg.isReadFromBackup(); tmLookupClsName = ccfg.getTransactionManagerLookupClassName(); topValidator = compactClass(ccfg.getTopologyValidator()); diskPageCompression = ccfg.getDiskPageCompression(); diskPageCompressionLevel = ccfg.getDiskPageCompressionLevel(); }
Example 18
Source File: IgniteSqlNotNullConstraintTest.java From ignite with Apache License 2.0 | 4 votes |
/** */ protected boolean isLocalAtomic() { CacheConfiguration cfg = cache.getConfiguration(CacheConfiguration.class); return cfg.getCacheMode() == CacheMode.LOCAL && cfg.getAtomicityMode() == CacheAtomicityMode.ATOMIC; }
Example 19
Source File: IgniteCacheReadFromBackupTest.java From ignite with Apache License 2.0 | 3 votes |
/** * @param nodes Number of nodes. * @param ccfg Cache configuration. * @throws Exception If failed. */ private void checkLocalRead(int nodes, CacheConfiguration<Object, Object> ccfg) throws Exception { for (int i = 0; i < nodes; i++) { Ignite ignite = ignite(i); log.info("Check node: " + ignite.name()); IgniteCache<Integer, Integer> cache = ignite.cache(ccfg.getName()); List<Integer> backupKeys = backupKeys(cache, 2, 0); Integer backupKey = backupKeys.get(0); Integer nearKey = ccfg.getCacheMode() == PARTITIONED ? nearKey(cache) : null; checkLocalRead(ignite, ccfg, backupKey, nearKey); Set<Integer> keys = new HashSet<>(backupKeys); Map<Integer, Integer> vals = cache.getAll(keys); for (Integer key : keys) assertNull(vals.get(key)); TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi)ignite.configuration().getCommunicationSpi(); List<Object> msgs = spi.recordedMessages(false); assertEquals(0, msgs.size()); } }
Example 20
Source File: ParametersTest.java From ignite with Apache License 2.0 | 3 votes |
/** * @throws Exception If failed. */ @Test public void testEnumVariationsWithNull() throws Exception { ConfigParameter<CacheConfiguration>[] cfgParam = Parameters.enumParameters(true, "setCacheMode", CacheMode.class); assertEquals(CacheMode.values().length + 1, cfgParam.length); cfgParam[0] = null; Set<CacheMode> set = new HashSet<>(); for (int i = 1; i < cfgParam.length; i++) { ConfigParameter<CacheConfiguration> modeApplier = cfgParam[i]; CacheConfiguration cfg = new CacheConfiguration(DEFAULT_CACHE_NAME); modeApplier.apply(cfg); CacheMode mode = cfg.getCacheMode(); set.add(mode); System.out.println(">>> " + mode); } assertEquals(CacheMode.values().length, set.size()); }