Search in sources :

Example 16 with CacheConfiguration

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

the class CacheApiExample 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-ignite.xml")) {
        System.out.println();
        System.out.println(">>> Cache API example started.");
        CacheConfiguration<Integer, String> cfg = new CacheConfiguration<>();
        cfg.setCacheMode(CacheMode.PARTITIONED);
        cfg.setName(CACHE_NAME);
        // Auto-close cache at the end of the example.
        try (IgniteCache<Integer, String> cache = ignite.getOrCreateCache(cfg)) {
            // Demonstrate atomic map operations.
            atomicMapOperations(cache);
        } finally {
            // Distributed cache could be removed from cluster only by #destroyCache() call.
            ignite.destroyCache(CACHE_NAME);
        }
    }
}
Also used : Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 17 with CacheConfiguration

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

the class RedisProtocolSelfTest method getConfiguration.

/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setLocalHost(HOST);
    assert cfg.getConnectorConfiguration() == null;
    ConnectorConfiguration redisCfg = new ConnectorConfiguration();
    redisCfg.setHost(HOST);
    redisCfg.setPort(PORT);
    cfg.setConnectorConfiguration(redisCfg);
    TcpDiscoverySpi disco = new TcpDiscoverySpi();
    disco.setIpFinder(IP_FINDER);
    cfg.setDiscoverySpi(disco);
    CacheConfiguration ccfg = defaultCacheConfiguration();
    ccfg.setStatisticsEnabled(true);
    ccfg.setIndexedTypes(String.class, String.class);
    cfg.setCacheConfiguration(ccfg);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ConnectorConfiguration(org.apache.ignite.configuration.ConnectorConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 18 with CacheConfiguration

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

the class GridCachePartitionExchangeManager method clientTopology.

/**
     * @param cacheId Cache ID.
     * @param exchFut Exchange future.
     * @return Topology.
     */
public GridDhtPartitionTopology clientTopology(int cacheId, GridDhtPartitionsExchangeFuture exchFut) {
    GridClientPartitionTopology top = clientTops.get(cacheId);
    if (top != null)
        return top;
    Object affKey = null;
    DynamicCacheDescriptor desc = cctx.cache().cacheDescriptor(cacheId);
    if (desc != null) {
        CacheConfiguration ccfg = desc.cacheConfiguration();
        AffinityFunction aff = ccfg.getAffinity();
        affKey = cctx.kernalContext().affinity().similaryAffinityKey(aff, ccfg.getNodeFilter(), ccfg.getBackups(), aff.partitions());
    }
    GridClientPartitionTopology old = clientTops.putIfAbsent(cacheId, top = new GridClientPartitionTopology(cctx, cacheId, exchFut, affKey));
    return old != null ? old : top;
}
Also used : GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridClientPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.GridClientPartitionTopology)

Example 19 with CacheConfiguration

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

the class GridCacheProcessor method addCacheOnJoinFromPersistentStore.

/**
     * @param caches Caches map.
     * @param templates Templates map.
     * @throws IgniteCheckedException If failed.
     */
private void addCacheOnJoinFromPersistentStore(Map<String, CacheJoinNodeDiscoveryData.CacheInfo> caches, Map<String, CacheJoinNodeDiscoveryData.CacheInfo> templates) throws IgniteCheckedException {
    assert !ctx.config().isDaemon();
    if (sharedCtx.pageStore() != null && sharedCtx.database().persistenceEnabled()) {
        Set<String> savedCacheNames = sharedCtx.pageStore().savedCacheNames();
        savedCacheNames.removeAll(caches.keySet());
        savedCacheNames.removeAll(internalCaches);
        if (!F.isEmpty(savedCacheNames)) {
            if (log.isInfoEnabled())
                log.info("Register persistent caches: " + savedCacheNames);
            for (String name : savedCacheNames) {
                CacheConfiguration cfg = sharedCtx.pageStore().readConfiguration(name);
                // TODO IGNITE-5306 - set correct SQL flag below.
                if (cfg != null)
                    addCacheOnJoin(cfg, false, caches, templates);
            }
        }
    }
}
Also used : CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 20 with CacheConfiguration

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

the class GridCacheProcessor method prepareCacheChangeRequest.

/**
     * Prepares DynamicCacheChangeRequest for cache creation.
     *
     * @param ccfg Cache configuration
     * @param cacheName Cache name
     * @param nearCfg Near cache configuration
     * @param cacheType Cache type
     * @param sql Whether the cache needs to be created as the result of SQL {@code CREATE TABLE} command.
     * @param failIfExists Fail if exists flag.
     * @param failIfNotStarted If {@code true} fails if cache is not started.
     * @return Request or {@code null} if cache already exists.
     * @throws IgniteCheckedException if some of pre-checks failed
     * @throws CacheExistsException if cache exists and failIfExists flag is {@code true}
     */
private DynamicCacheChangeRequest prepareCacheChangeRequest(@Nullable CacheConfiguration ccfg, String cacheName, @Nullable NearCacheConfiguration nearCfg, CacheType cacheType, boolean sql, boolean failIfExists, boolean failIfNotStarted) throws IgniteCheckedException {
    DynamicCacheDescriptor desc = cacheDescriptor(cacheName);
    DynamicCacheChangeRequest req = new DynamicCacheChangeRequest(UUID.randomUUID(), cacheName, ctx.localNodeId());
    req.sql(sql);
    req.failIfExists(failIfExists);
    if (ccfg != null) {
        cloneCheckSerializable(ccfg);
        if (desc != null) {
            if (failIfExists) {
                throw new CacheExistsException("Failed to start cache " + "(a cache with the same name is already started): " + cacheName);
            } else {
                CacheConfiguration descCfg = desc.cacheConfiguration();
                // Check if we were asked to start a near cache.
                if (nearCfg != null) {
                    if (CU.affinityNode(ctx.discovery().localNode(), descCfg.getNodeFilter())) {
                        // If we are on a data node and near cache was enabled, return success, else - fail.
                        if (descCfg.getNearConfiguration() != null)
                            return null;
                        else
                            throw new IgniteCheckedException("Failed to start near " + "cache (local node is an affinity node for cache): " + cacheName);
                    } else
                        // If local node has near cache, return success.
                        req.clientStartOnly(true);
                } else
                    req.clientStartOnly(true);
                req.deploymentId(desc.deploymentId());
                req.startCacheConfiguration(descCfg);
                req.schema(desc.schema());
            }
        } else {
            req.deploymentId(IgniteUuid.randomUuid());
            CacheConfiguration cfg = new CacheConfiguration(ccfg);
            CacheObjectContext cacheObjCtx = ctx.cacheObjects().contextForCache(cfg);
            initialize(cfg, cacheObjCtx);
            req.startCacheConfiguration(cfg);
            req.schema(new QuerySchema(cfg.getQueryEntities()));
        }
    } else {
        req.clientStartOnly(true);
        if (desc != null)
            ccfg = desc.cacheConfiguration();
        if (ccfg == null) {
            if (failIfNotStarted) {
                throw new CacheExistsException("Failed to start client cache " + "(a cache with the given name is not started): " + cacheName);
            } else
                return null;
        }
        req.deploymentId(desc.deploymentId());
        req.startCacheConfiguration(ccfg);
        req.schema(desc.schema());
    }
    if (nearCfg != null)
        req.nearCacheConfiguration(nearCfg);
    req.cacheType(cacheType);
    return req;
}
Also used : QuerySchema(org.apache.ignite.internal.processors.query.QuerySchema) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheExistsException(org.apache.ignite.cache.CacheExistsException) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

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