Search in sources :

Example 26 with CacheConfiguration

use of org.apache.ignite.configuration.CacheConfiguration in project ignite by apache.

the class DataRegionsExample method main.

/**
 * Executes example.
 *
 * @param args Command line arguments, none required.
 * @throws IgniteException If example execution failed.
 */
public static void main(String[] args) throws IgniteException {
    try (Ignite ignite = Ignition.start("examples/config/example-data-regions.xml")) {
        System.out.println();
        System.out.println(">>> Data regions example started.");
        /*
             * Preparing configurations for 2 caches that will be bound to the memory region defined by
             * '10MB_Region_Eviction' data region from 'example-data-regions.xml' configuration.
             */
        CacheConfiguration<Integer, Integer> firstCacheCfg = new CacheConfiguration<>("firstCache");
        firstCacheCfg.setDataRegionName(REGION_40MB_EVICTION);
        firstCacheCfg.setCacheMode(CacheMode.PARTITIONED);
        firstCacheCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
        CacheConfiguration<Integer, Integer> secondCacheCfg = new CacheConfiguration<>("secondCache");
        secondCacheCfg.setDataRegionName(REGION_40MB_EVICTION);
        secondCacheCfg.setCacheMode(CacheMode.REPLICATED);
        secondCacheCfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
        IgniteCache<Integer, Integer> firstCache = ignite.createCache(firstCacheCfg);
        IgniteCache<Integer, Integer> secondCache = ignite.createCache(secondCacheCfg);
        System.out.println(">>> Started two caches bound to '" + REGION_40MB_EVICTION + "' memory region.");
        /*
             * Preparing a configuration for a cache that will be bound to the memory region defined by
             * '5MB_Region_Swapping' data region from 'example-data-regions.xml' configuration.
             */
        CacheConfiguration<Integer, Integer> thirdCacheCfg = new CacheConfiguration<>("thirdCache");
        thirdCacheCfg.setDataRegionName(REGION_30MB_MEMORY_MAPPED_FILE);
        IgniteCache<Integer, Integer> thirdCache = ignite.createCache(thirdCacheCfg);
        System.out.println(">>> Started a cache bound to '" + REGION_30MB_MEMORY_MAPPED_FILE + "' memory region.");
        /*
             * Preparing a configuration for a cache that will be bound to the default memory region defined by
             * default 'Default_Region' data region from 'example-data-regions.xml' configuration.
             */
        CacheConfiguration<Integer, Integer> fourthCacheCfg = new CacheConfiguration<>("fourthCache");
        IgniteCache<Integer, Integer> fourthCache = ignite.createCache(fourthCacheCfg);
        System.out.println(">>> Started a cache bound to '" + REGION_DEFAULT + "' memory region.");
        System.out.println(">>> Destroying caches...");
        firstCache.destroy();
        secondCache.destroy();
        thirdCache.destroy();
        fourthCache.destroy();
    }
}
Also used : Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 27 with CacheConfiguration

use of org.apache.ignite.configuration.CacheConfiguration in project ignite by apache.

the class CacheStarSchemaExample method main.

/**
 * 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<>(FACT_CACHE_NAME);
        factCacheCfg.setCacheMode(CacheMode.PARTITIONED);
        factCacheCfg.setIndexedTypes(Integer.class, FactPurchase.class);
        CacheConfiguration<Integer, DimStore> dimStoreCacheCfg = new CacheConfiguration<>(DIM_STORE_CACHE_NAME);
        dimStoreCacheCfg.setCacheMode(CacheMode.REPLICATED);
        dimStoreCacheCfg.setIndexedTypes(Integer.class, DimStore.class);
        CacheConfiguration<Integer, DimProduct> dimProdCacheCfg = new CacheConfiguration<>(DIM_PROD_CACHE_NAME);
        dimProdCacheCfg.setCacheMode(CacheMode.REPLICATED);
        dimProdCacheCfg.setIndexedTypes(Integer.class, DimProduct.class);
        // Auto-close cache at the end of the example.
        try (IgniteCache<Integer, FactPurchase> factCache = ignite.getOrCreateCache(factCacheCfg);
            IgniteCache<Integer, DimStore> dimStoreCache = ignite.getOrCreateCache(dimStoreCacheCfg);
            IgniteCache<Integer, DimProduct> dimProdCache = ignite.getOrCreateCache(dimProdCacheCfg)) {
            populateDimensions(dimStoreCache, dimProdCache);
            populateFacts(factCache);
            queryStorePurchases();
            queryProductPurchases();
        } finally {
            // Distributed cache could be removed from cluster only by #destroyCache() call.
            ignite.destroyCache(FACT_CACHE_NAME);
            ignite.destroyCache(DIM_STORE_CACHE_NAME);
            ignite.destroyCache(DIM_PROD_CACHE_NAME);
        }
    }
}
Also used : Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 28 with CacheConfiguration

use of org.apache.ignite.configuration.CacheConfiguration in project ignite by apache.

the class GridCacheProcessor method initiateCacheChanges.

/**
 * @param reqs Requests.
 * @return Collection of futures.
 */
@SuppressWarnings("TypeMayBeWeakened")
private Collection<DynamicCacheStartFuture> initiateCacheChanges(Collection<DynamicCacheChangeRequest> reqs) {
    Collection<DynamicCacheStartFuture> res = new ArrayList<>(reqs.size());
    Collection<DynamicCacheChangeRequest> sndReqs = new ArrayList<>(reqs.size());
    for (DynamicCacheChangeRequest req : reqs) {
        DynamicCacheStartFuture fut = new DynamicCacheStartFuture(req.requestId());
        try {
            if (req.stop()) {
                DynamicCacheDescriptor desc = cacheDescriptor(req.cacheName());
                if (desc == null)
                    // No-op.
                    fut.onDone(false);
            }
            if (req.start() && req.startCacheConfiguration() != null) {
                CacheConfiguration ccfg = req.startCacheConfiguration();
                try {
                    cachesInfo.validateStartCacheConfiguration(ccfg);
                } catch (IgniteCheckedException e) {
                    fut.onDone(e);
                }
            }
            if (fut.isDone())
                continue;
            DynamicCacheStartFuture old = (DynamicCacheStartFuture) pendingFuts.putIfAbsent(req.requestId(), fut);
            assert old == null;
            if (fut.isDone())
                continue;
            sndReqs.add(req);
        } catch (Exception e) {
            fut.onDone(e);
        } finally {
            res.add(fut);
        }
    }
    Exception err = null;
    if (!sndReqs.isEmpty()) {
        try {
            ctx.discovery().sendCustomEvent(new DynamicCacheChangeBatch(sndReqs));
            err = checkNodeState();
        } catch (IgniteCheckedException e) {
            err = e;
        }
    }
    if (err != null) {
        for (DynamicCacheStartFuture fut : res) fut.onDone(err);
    }
    return res;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ArrayList(java.util.ArrayList) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteException(org.apache.ignite.IgniteException) CacheExistsException(org.apache.ignite.cache.CacheExistsException)

Example 29 with CacheConfiguration

use of org.apache.ignite.configuration.CacheConfiguration in project ignite by apache.

the class GridCacheUtils method hadoopSystemCache.

/**
 * Create system cache used by Hadoop component.
 *
 * @return Hadoop cache configuration.
 */
public static CacheConfiguration hadoopSystemCache() {
    CacheConfiguration cache = new CacheConfiguration();
    cache.setName(CU.SYS_CACHE_HADOOP_MR);
    cache.setCacheMode(REPLICATED);
    cache.setAtomicityMode(TRANSACTIONAL);
    cache.setWriteSynchronizationMode(FULL_SYNC);
    cache.setEvictionPolicyFactory(null);
    cache.setEvictionPolicy(null);
    cache.setCacheStoreFactory(null);
    cache.setNodeFilter(CacheConfiguration.ALL_NODES);
    cache.setEagerTtl(true);
    cache.setRebalanceMode(SYNC);
    return cache;
}
Also used : CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 30 with CacheConfiguration

use of org.apache.ignite.configuration.CacheConfiguration in project ignite by apache.

the class GridCacheAffinityImpl method affinityKey.

/**
 * {@inheritDoc}
 */
@Override
public Object affinityKey(K key) {
    A.notNull(key, "key");
    if (key instanceof CacheObject && !(key instanceof BinaryObject)) {
        CacheObjectContext ctx = cctx.cacheObjectContext();
        if (ctx == null)
            throw new IgniteException(FAILED_TO_FIND_CACHE_ERR_MSG + cctx.name());
        key = ((CacheObject) key).value(ctx, false);
    }
    CacheConfiguration ccfg = cctx.config();
    if (ccfg == null)
        throw new IgniteException(FAILED_TO_FIND_CACHE_ERR_MSG + cctx.name());
    return ccfg.getAffinityMapper().affinityKey(key);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) IgniteException(org.apache.ignite.IgniteException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1234 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)474 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)330 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)292 Ignite (org.apache.ignite.Ignite)202 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)127 ArrayList (java.util.ArrayList)95 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)82 IgniteEx (org.apache.ignite.internal.IgniteEx)60 QueryEntity (org.apache.ignite.cache.QueryEntity)59 IgniteCache (org.apache.ignite.IgniteCache)55 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)54 CacheException (javax.cache.CacheException)51 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)51 IgniteException (org.apache.ignite.IgniteException)50 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)45 LinkedHashMap (java.util.LinkedHashMap)41 IgfsGroupDataBlocksKeyMapper (org.apache.ignite.igfs.IgfsGroupDataBlocksKeyMapper)41 TcpDiscoveryVmIpFinder (org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder)38 Transaction (org.apache.ignite.transactions.Transaction)35