Search in sources :

Example 6 with QuerySchema

use of org.apache.ignite.internal.processors.query.QuerySchema in project ignite by apache.

the class DynamicCacheChangeRequest method addTemplateRequest.

/**
 * @param ctx Context.
 * @param cfg0 Template configuration.
 * @param splitCfg Cache configuration splitter.
 * @return Request to add template.
 */
static DynamicCacheChangeRequest addTemplateRequest(GridKernalContext ctx, CacheConfiguration<?, ?> cfg0, T2<CacheConfiguration, CacheConfigurationEnrichment> splitCfg) {
    DynamicCacheChangeRequest req = new DynamicCacheChangeRequest(UUID.randomUUID(), cfg0.getName(), ctx.localNodeId());
    req.template(true);
    req.startCacheConfiguration(splitCfg.get1());
    req.cacheConfigurationEnrichment(splitCfg.get2());
    req.schema(new QuerySchema(cfg0.getQueryEntities()));
    req.deploymentId(IgniteUuid.randomUuid());
    return req;
}
Also used : QuerySchema(org.apache.ignite.internal.processors.query.QuerySchema)

Example 7 with QuerySchema

use of org.apache.ignite.internal.processors.query.QuerySchema in project ignite by apache.

the class ClusterCachesInfo method processJoiningNode.

/**
     * @param joinData Joined node discovery data.
     * @param nodeId Joined node ID.
     */
private void processJoiningNode(CacheJoinNodeDiscoveryData joinData, UUID nodeId) {
    for (CacheJoinNodeDiscoveryData.CacheInfo cacheInfo : joinData.templates().values()) {
        CacheConfiguration<?, ?> cfg = cacheInfo.config();
        if (!registeredTemplates.containsKey(cfg.getName())) {
            DynamicCacheDescriptor desc = new DynamicCacheDescriptor(ctx, cfg, cacheInfo.cacheType(), true, nodeId, true, false, joinData.cacheDeploymentId(), new QuerySchema(cfg.getQueryEntities()));
            DynamicCacheDescriptor old = registeredTemplates.put(cfg.getName(), desc);
            assert old == null : old;
        }
    }
    for (CacheJoinNodeDiscoveryData.CacheInfo cacheInfo : joinData.caches().values()) {
        CacheConfiguration<?, ?> cfg = cacheInfo.config();
        if (!registeredCaches.containsKey(cfg.getName())) {
            DynamicCacheDescriptor desc = new DynamicCacheDescriptor(ctx, cfg, cacheInfo.cacheType(), false, nodeId, true, cacheInfo.sql(), joinData.cacheDeploymentId(), new QuerySchema(cfg.getQueryEntities()));
            DynamicCacheDescriptor old = registeredCaches.put(cfg.getName(), desc);
            assert old == null : old;
            ctx.discovery().setCacheFilter(cfg.getName(), cfg.getNodeFilter(), cfg.getNearConfiguration() != null, cfg.getCacheMode());
        }
        ctx.discovery().addClientNode(cfg.getName(), nodeId, cfg.getNearConfiguration() != null);
    }
    if (joinData.startCaches()) {
        for (DynamicCacheDescriptor desc : registeredCaches.values()) {
            ctx.discovery().addClientNode(desc.cacheName(), nodeId, desc.cacheConfiguration().getNearConfiguration() != null);
        }
    }
}
Also used : QuerySchema(org.apache.ignite.internal.processors.query.QuerySchema)

Example 8 with QuerySchema

use of org.apache.ignite.internal.processors.query.QuerySchema in project ignite by apache.

the class GridCacheProcessor method prepareCacheStart.

/**
     * @param startCfg Start configuration.
     * @param reqNearCfg Near configuration if specified for client cache start request.
     * @param desc Cache descriptor.
     * @param exchTopVer Current exchange version.
     * @param schema Query schema.
     * @throws IgniteCheckedException If failed.
     */
private void prepareCacheStart(CacheConfiguration startCfg, @Nullable NearCacheConfiguration reqNearCfg, DynamicCacheDescriptor desc, AffinityTopologyVersion exchTopVer, @Nullable QuerySchema schema) throws IgniteCheckedException {
    assert !caches.containsKey(startCfg.getName()) : startCfg.getName();
    CacheConfiguration ccfg = new CacheConfiguration(startCfg);
    CacheObjectContext cacheObjCtx = ctx.cacheObjects().contextForCache(ccfg);
    boolean affNode;
    if (ccfg.getCacheMode() == LOCAL) {
        affNode = true;
        ccfg.setNearConfiguration(null);
    } else if (CU.affinityNode(ctx.discovery().localNode(), ccfg.getNodeFilter()))
        affNode = true;
    else {
        affNode = false;
        ccfg.setNearConfiguration(reqNearCfg);
    }
    GridCacheContext cacheCtx = createCache(ccfg, null, desc, exchTopVer, cacheObjCtx, affNode, true);
    cacheCtx.dynamicDeploymentId(desc.deploymentId());
    GridCacheAdapter cache = cacheCtx.cache();
    sharedCtx.addCacheContext(cacheCtx);
    caches.put(cacheCtx.name(), cache);
    startCache(cache, schema != null ? schema : new QuerySchema());
    onKernalStart(cache);
}
Also used : QuerySchema(org.apache.ignite.internal.processors.query.QuerySchema) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 9 with QuerySchema

use of org.apache.ignite.internal.processors.query.QuerySchema in project ignite by apache.

the class GridCacheProcessor method createRequest.

/**
     * @param cfg Cache configuration.
     */
private DynamicCacheChangeRequest createRequest(CacheConfiguration cfg, boolean needInit) throws IgniteCheckedException {
    assert cfg != null;
    assert cfg.getName() != null;
    cloneCheckSerializable(cfg);
    if (needInit) {
        CacheObjectContext cacheObjCtx = ctx.cacheObjects().contextForCache(cfg);
        initialize(cfg, cacheObjCtx);
    }
    String cacheName = cfg.getName();
    DynamicCacheChangeRequest req = new DynamicCacheChangeRequest(UUID.randomUUID(), cacheName, ctx.localNodeId());
    req.startCacheConfiguration(cfg);
    req.template(cfg.getName().endsWith("*"));
    req.nearCacheConfiguration(cfg.getNearConfiguration());
    req.deploymentId(IgniteUuid.randomUuid());
    req.schema(new QuerySchema(cfg.getQueryEntities()));
    if (CU.isUtilityCache(cacheName))
        req.cacheType(CacheType.UTILITY);
    else if (internalCaches.contains(cacheName))
        req.cacheType(CacheType.INTERNAL);
    else
        req.cacheType(CacheType.USER);
    return req;
}
Also used : QuerySchema(org.apache.ignite.internal.processors.query.QuerySchema)

Example 10 with QuerySchema

use of org.apache.ignite.internal.processors.query.QuerySchema 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.
 * @param disabledAfterStart If true, cache proxies will be only activated after {@link #restartProxies()}.
 * @param qryEntities Query entities.
 * @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, boolean disabledAfterStart, @Nullable Collection<QueryEntity> qryEntities) throws IgniteCheckedException {
    DynamicCacheDescriptor desc = cacheDescriptor(cacheName);
    DynamicCacheChangeRequest req = new DynamicCacheChangeRequest(UUID.randomUUID(), cacheName, ctx.localNodeId());
    req.sql(sql);
    req.failIfExists(failIfExists);
    req.disabledAfterStart(disabledAfterStart);
    if (ccfg != null) {
        cloneCheckSerializable(ccfg);
        if (desc != null || MetaStorage.METASTORAGE_CACHE_NAME.equals(cacheName)) {
            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 if (!CU.affinityNode(ctx.discovery().localNode(), descCfg.getNodeFilter()))
                    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(qryEntities != null ? QueryUtils.normalizeQueryEntities(qryEntities, cfg) : 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

QuerySchema (org.apache.ignite.internal.processors.query.QuerySchema)19 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)10 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)9 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 CacheExistsException (org.apache.ignite.cache.CacheExistsException)3 QueryEntity (org.apache.ignite.cache.QueryEntity)3 DynamicCacheDescriptor (org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor)2 QuerySchemaPatch (org.apache.ignite.internal.processors.query.QuerySchemaPatch)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 T2 (org.apache.ignite.internal.util.typedef.T2)1 IgniteUuid (org.apache.ignite.lang.IgniteUuid)1 Test (org.junit.Test)1