use of org.apache.ignite.internal.processors.query.QuerySchema in project ignite by apache.
the class GridCacheProcessor method prepareCacheStart.
/**
* @param startCfg Cache configuration to use.
* @param desc Cache descriptor.
* @param reqNearCfg Near configuration if specified for client cache start request.
* @param exchTopVer Current exchange version.
* @param disabledAfterStart If true, then we will discard restarting state from proxies. If false then we will change
* state of proxies to restarting
* @throws IgniteCheckedException If failed.
*/
void prepareCacheStart(CacheConfiguration startCfg, DynamicCacheDescriptor desc, @Nullable NearCacheConfiguration reqNearCfg, AffinityTopologyVersion exchTopVer, boolean disabledAfterStart) 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(), desc.groupDescriptor().config().getNodeFilter()))
affNode = true;
else {
affNode = false;
ccfg.setNearConfiguration(reqNearCfg);
}
if (sharedCtx.pageStore() != null && affNode)
sharedCtx.pageStore().initializeForCache(desc.groupDescriptor(), desc.toStoredData());
String grpName = startCfg.getGroupName();
CacheGroupContext grp = null;
if (grpName != null) {
for (CacheGroupContext grp0 : cacheGrps.values()) {
if (grp0.sharedGroup() && grpName.equals(grp0.name())) {
grp = grp0;
break;
}
}
if (grp == null) {
grp = startCacheGroup(desc.groupDescriptor(), desc.cacheType(), affNode, cacheObjCtx, exchTopVer);
}
} else {
grp = startCacheGroup(desc.groupDescriptor(), desc.cacheType(), affNode, cacheObjCtx, exchTopVer);
}
GridCacheContext cacheCtx = createCache(ccfg, grp, null, desc, exchTopVer, cacheObjCtx, affNode, true, disabledAfterStart);
cacheCtx.dynamicDeploymentId(desc.deploymentId());
GridCacheAdapter cache = cacheCtx.cache();
sharedCtx.addCacheContext(cacheCtx);
caches.put(cacheCtx.name(), cache);
startCache(cache, desc.schema() != null ? desc.schema() : new QuerySchema());
grp.onCacheStarted(cacheCtx);
onKernalStart(cache);
IgniteCacheProxyImpl<?, ?> proxy = jCacheProxies.get(ccfg.getName());
if (!disabledAfterStart && proxy != null && proxy.isRestarting()) {
proxy.onRestarted(cacheCtx, cache);
if (cacheCtx.dataStructuresCache())
ctx.dataStructures().restart(proxy.internalProxy());
}
}
use of org.apache.ignite.internal.processors.query.QuerySchema in project ignite by apache.
the class GridCacheProcessor method startCacheInRecoveryMode.
/**
* @param desc Cache descriptor.
* @throws IgniteCheckedException If failed.
*/
private GridCacheContext<?, ?> startCacheInRecoveryMode(DynamicCacheDescriptor desc) throws IgniteCheckedException {
// Only affinity nodes are able to start cache in recovery mode.
desc = enricher().enrich(desc, true);
CacheConfiguration cfg = desc.cacheConfiguration();
CacheObjectContext cacheObjCtx = ctx.cacheObjects().contextForCache(cfg);
preparePageStore(desc, true);
CacheGroupContext grpCtx;
GridCacheContext cacheCtx;
ctx.cache().context().database().checkpointReadLock();
try {
grpCtx = getOrCreateCacheGroupContext(desc, AffinityTopologyVersion.NONE, cacheObjCtx, true, cfg.getGroupName(), true);
cacheCtx = createCacheContext(cfg, grpCtx, null, desc, AffinityTopologyVersion.NONE, cacheObjCtx, true, true, false, true);
initCacheContext(cacheCtx, cfg);
} finally {
ctx.cache().context().database().checkpointReadUnlock();
}
cacheCtx.onStarted();
String dataRegion = cfg.getDataRegionName();
if (dataRegion == null && ctx.config().getDataStorageConfiguration() != null)
dataRegion = ctx.config().getDataStorageConfiguration().getDefaultDataRegionConfiguration().getName();
grpCtx.onCacheStarted(cacheCtx);
ctx.query().onCacheStart(new GridCacheContextInfo(cacheCtx, false), desc.schema() != null ? desc.schema() : new QuerySchema(), desc.sql());
if (log.isInfoEnabled()) {
String expPlcInfo = buildExpirePolicyInfo(cacheCtx);
log.info("Started cache in recovery mode [name=" + cfg.getName() + ", id=" + cacheCtx.cacheId() + (cfg.getGroupName() != null ? ", group=" + cfg.getGroupName() : "") + ", dataRegionName=" + dataRegion + ", mode=" + cfg.getCacheMode() + ", atomicity=" + cfg.getAtomicityMode() + ", backups=" + cfg.getBackups() + ", mvcc=" + cacheCtx.mvccEnabled() + (expPlcInfo != null ? ", " + expPlcInfo : "") + ']');
}
return cacheCtx;
}
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 restartId Restart requester id (it'll allow to start this cache only him).
* @param disabledAfterStart If true, cache proxies will be only activated after {@link #restartProxies()}.
* @param qryEntities Query entities.
* @param encKey Encryption key.
* @param masterKeyDigest Master key digest.
* @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, IgniteUuid restartId, boolean disabledAfterStart, @Nullable Collection<QueryEntity> qryEntities, @Nullable byte[] encKey, @Nullable byte[] masterKeyDigest) throws IgniteCheckedException {
DynamicCacheDescriptor desc = cacheDescriptor(cacheName);
DynamicCacheChangeRequest req = new DynamicCacheChangeRequest(UUID.randomUUID(), cacheName, ctx.localNodeId());
req.sql(sql);
req.failIfExists(failIfExists);
req.disabledAfterStart(disabledAfterStart);
req.masterKeyDigest(masterKeyDigest);
req.encryptionKey(encKey);
req.restartId(restartId);
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 (isLocalAffinity(descCfg)) {
// 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 (!isLocalAffinity(descCfg))
req.clientStartOnly(true);
req.deploymentId(desc.deploymentId());
T2<CacheConfiguration, CacheConfigurationEnrichment> splitCfg = backwardCompatibleSplitter().split(desc);
req.startCacheConfiguration(splitCfg.get1());
req.cacheConfigurationEnrichment(splitCfg.get2());
req.schema(desc.schema());
}
} else {
CacheConfiguration cfg = new CacheConfiguration(ccfg);
CacheObjectContext cacheObjCtx = ctx.cacheObjects().contextForCache(cfg);
// Cache configuration must be initialized before splitting.
initialize(cfg, cacheObjCtx);
req.deploymentId(IgniteUuid.randomUuid());
T2<CacheConfiguration, CacheConfigurationEnrichment> splitCfg = backwardCompatibleSplitter().split(cfg);
req.startCacheConfiguration(splitCfg.get1());
req.cacheConfigurationEnrichment(splitCfg.get2());
cfg = splitCfg.get1();
if (restartId != null)
req.schema(new QuerySchema(qryEntities == null ? cfg.getQueryEntities() : qryEntities));
else
req.schema(new QuerySchema(qryEntities != null ? QueryUtils.normalizeQueryEntities(ctx, 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());
T2<CacheConfiguration, CacheConfigurationEnrichment> splitCfg = backwardCompatibleSplitter().split(ccfg);
req.startCacheConfiguration(splitCfg.get1());
req.cacheConfigurationEnrichment(splitCfg.get2());
req.schema(desc.schema());
}
if (nearCfg != null)
req.nearCacheConfiguration(nearCfg);
req.cacheType(cacheType);
return req;
}
use of org.apache.ignite.internal.processors.query.QuerySchema in project ignite by apache.
the class GridCacheProcessor method prepareCacheContext.
/**
* Preparing cache context to start.
*
* @param desc Cache descriptor.
* @param reqNearCfg Near configuration if specified for client cache start request.
* @param exchTopVer Current exchange version.
* @param disabledAfterStart If true, then we will discard restarting state from proxies. If false then we will change
* state of proxies to restarting
* @return Created {@link GridCacheContext}.
* @throws IgniteCheckedException if failed.
*/
private GridCacheContext prepareCacheContext(DynamicCacheDescriptor desc, @Nullable NearCacheConfiguration reqNearCfg, AffinityTopologyVersion exchTopVer, boolean disabledAfterStart) throws IgniteCheckedException {
desc = enricher().enrich(desc, desc.cacheConfiguration().getCacheMode() == LOCAL || isLocalAffinity(desc.cacheConfiguration()));
CacheConfiguration startCfg = desc.cacheConfiguration();
if (caches.containsKey(startCfg.getName())) {
GridCacheAdapter<?, ?> existingCache = caches.get(startCfg.getName());
GridCacheContext<?, ?> cctx = existingCache.context();
assert cctx.isRecoveryMode();
QuerySchema localSchema = recovery.querySchemas.get(desc.cacheId());
QuerySchemaPatch localSchemaPatch = localSchema.makePatch(desc.schema().entities());
// Cache schema is changed after restart, workaround is stop existing cache and start new.
if (!localSchemaPatch.isEmpty() || localSchemaPatch.hasConflicts())
stopCacheSafely(cctx);
else
return existingCache.context();
}
assert !caches.containsKey(startCfg.getName()) : startCfg.getName();
CacheConfiguration ccfg = new CacheConfiguration(startCfg);
CacheObjectContext cacheObjCtx = ctx.cacheObjects().contextForCache(ccfg);
boolean affNode = checkForAffinityNode(desc, reqNearCfg, ccfg);
ctx.cache().context().database().checkpointReadLock();
try {
CacheGroupContext grp = getOrCreateCacheGroupContext(desc, exchTopVer, cacheObjCtx, affNode, startCfg.getGroupName(), false);
GridCacheContext cacheCtx = createCacheContext(ccfg, grp, null, desc, exchTopVer, cacheObjCtx, affNode, true, disabledAfterStart, false);
initCacheContext(cacheCtx, ccfg);
return cacheCtx;
} finally {
ctx.cache().context().database().checkpointReadUnlock();
}
}
use of org.apache.ignite.internal.processors.query.QuerySchema in project ignite by apache.
the class ClusterCachesInfo method registerNewCache.
/**
* Register new cache received from joining node.
*
* @param joinData Data from joining node.
* @param nodeId Joining node id.
* @param cacheInfo Cache info of new node.
*/
private void registerNewCache(CacheJoinNodeDiscoveryData joinData, UUID nodeId, CacheJoinNodeDiscoveryData.CacheInfo cacheInfo) {
CacheConfiguration<?, ?> cfg = cacheInfo.cacheData().config();
int cacheId = CU.cacheId(cfg.getName());
CacheGroupDescriptor grpDesc = registerCacheGroup(null, null, cfg, cacheId, nodeId, joinData.cacheDeploymentId(), null, cacheInfo.cacheData().cacheConfigurationEnrichment());
ctx.discovery().setCacheFilter(cacheId, grpDesc.groupId(), cfg.getName(), cfg.getNearConfiguration() != null);
DynamicCacheDescriptor desc = new DynamicCacheDescriptor(ctx, cfg, cacheInfo.cacheType(), grpDesc, false, nodeId, cacheInfo.isStaticallyConfigured(), cacheInfo.sql(), joinData.cacheDeploymentId(), new QuerySchema(cacheInfo.cacheData().queryEntities()), cacheInfo.cacheData().cacheConfigurationEnrichment());
DynamicCacheDescriptor old = registeredCaches.put(cfg.getName(), desc);
registeredCachesById.put(desc.cacheId(), desc);
assert old == null : old;
}
Aggregations