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.
* @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;
}
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.
* @param locJoin {@code True} if called on local node join.
* @return Configuration conflict error.
*/
private String processJoiningNode(CacheJoinNodeDiscoveryData joinData, UUID nodeId, boolean locJoin) {
for (CacheJoinNodeDiscoveryData.CacheInfo cacheInfo : joinData.templates().values()) {
CacheConfiguration<?, ?> cfg = cacheInfo.cacheData().config();
if (!registeredTemplates.containsKey(cfg.getName())) {
DynamicCacheDescriptor desc = new DynamicCacheDescriptor(ctx, cfg, cacheInfo.cacheType(), null, true, nodeId, true, false, joinData.cacheDeploymentId(), new QuerySchema(cacheInfo.cacheData().queryEntities()));
DynamicCacheDescriptor old = registeredTemplates.put(cfg.getName(), desc);
assert old == null : old;
}
}
for (CacheJoinNodeDiscoveryData.CacheInfo cacheInfo : joinData.caches().values()) {
CacheConfiguration<?, ?> cfg = cacheInfo.cacheData().config();
if (!registeredCaches.containsKey(cfg.getName())) {
String conflictErr = checkCacheConflict(cfg);
if (conflictErr != null) {
if (locJoin)
return conflictErr;
U.warn(log, "Ignore cache received from joining node. " + conflictErr);
continue;
}
int cacheId = CU.cacheId(cfg.getName());
CacheGroupDescriptor grpDesc = registerCacheGroup(null, null, cfg, cacheId, nodeId, joinData.cacheDeploymentId());
ctx.discovery().setCacheFilter(cacheId, grpDesc.groupId(), cfg.getName(), cfg.getNearConfiguration() != null);
DynamicCacheDescriptor desc = new DynamicCacheDescriptor(ctx, cfg, cacheInfo.cacheType(), grpDesc, false, nodeId, true, cacheInfo.sql(), joinData.cacheDeploymentId(), new QuerySchema(cacheInfo.cacheData().queryEntities()));
DynamicCacheDescriptor old = registeredCaches.put(cfg.getName(), desc);
assert old == null : old;
}
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);
}
}
return null;
}
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.
* @return Request to add template.
*/
static DynamicCacheChangeRequest addTemplateRequest(GridKernalContext ctx, CacheConfiguration<?, ?> cfg0) {
CacheConfiguration<?, ?> cfg = new CacheConfiguration<>(cfg0);
DynamicCacheChangeRequest req = new DynamicCacheChangeRequest(UUID.randomUUID(), cfg.getName(), ctx.localNodeId());
req.template(true);
req.startCacheConfiguration(cfg);
req.schema(new QuerySchema(cfg.getQueryEntities()));
req.deploymentId(IgniteUuid.randomUuid());
return req;
}
use of org.apache.ignite.internal.processors.query.QuerySchema in project ignite by apache.
the class ClusterCachesInfo method onStateChangeRequest.
/**
* @param msg Message.
* @param topVer Current topology version.
* @param curState Current cluster state.
* @return Exchange action.
* @throws IgniteCheckedException If configuration validation failed.
*/
public ExchangeActions onStateChangeRequest(ChangeGlobalStateMessage msg, AffinityTopologyVersion topVer, DiscoveryDataClusterState curState) throws IgniteCheckedException {
ExchangeActions exchangeActions = new ExchangeActions();
if (msg.activate() == curState.active())
return exchangeActions;
if (msg.activate()) {
for (DynamicCacheDescriptor desc : orderedCaches(CacheComparators.DIRECT)) {
desc.startTopologyVersion(topVer);
DynamicCacheChangeRequest req = new DynamicCacheChangeRequest(msg.requestId(), desc.cacheName(), msg.initiatorNodeId());
req.startCacheConfiguration(desc.cacheConfiguration());
req.cacheType(desc.cacheType());
T2<CacheConfiguration, NearCacheConfiguration> locCfg = locCfgsForActivation.get(desc.cacheName());
if (locCfg != null) {
if (locCfg.get1() != null)
req.startCacheConfiguration(locCfg.get1());
req.nearCacheConfiguration(locCfg.get2());
req.locallyConfigured(true);
}
exchangeActions.addCacheToStart(req, desc);
}
for (CacheGroupDescriptor grpDesc : registeredCacheGroups().values()) exchangeActions.addCacheGroupToStart(grpDesc);
List<StoredCacheData> storedCfgs = msg.storedCacheConfigurations();
if (storedCfgs != null) {
List<DynamicCacheChangeRequest> reqs = new ArrayList<>();
IgniteUuid deploymentId = msg.id();
for (StoredCacheData storedCfg : storedCfgs) {
CacheConfiguration ccfg = storedCfg.config();
if (!registeredCaches.containsKey(ccfg.getName())) {
DynamicCacheChangeRequest req = new DynamicCacheChangeRequest(msg.requestId(), ccfg.getName(), msg.initiatorNodeId());
req.deploymentId(deploymentId);
req.startCacheConfiguration(ccfg);
req.cacheType(ctx.cache().cacheType(ccfg.getName()));
req.schema(new QuerySchema(storedCfg.queryEntities()));
req.sql(storedCfg.sql());
reqs.add(req);
}
}
CacheChangeProcessResult res = processCacheChangeRequests(exchangeActions, reqs, topVer, true);
if (!res.errs.isEmpty()) {
IgniteCheckedException err = new IgniteCheckedException("Failed to activate cluster.");
for (IgniteCheckedException err0 : res.errs) err.addSuppressed(err0);
throw err;
}
}
} else {
locCfgsForActivation = new HashMap<>();
for (DynamicCacheDescriptor desc : orderedCaches(CacheComparators.REVERSE)) {
DynamicCacheChangeRequest req = DynamicCacheChangeRequest.stopRequest(ctx, desc.cacheName(), desc.sql(), false);
exchangeActions.addCacheToStop(req, desc);
if (ctx.discovery().cacheClientNode(ctx.discovery().localNode(), desc.cacheName()))
locCfgsForActivation.put(desc.cacheName(), new T2<>((CacheConfiguration) null, (NearCacheConfiguration) null));
}
for (CacheGroupDescriptor grpDesc : registeredCacheGroups().values()) exchangeActions.addCacheGroupToStop(grpDesc, false);
}
return exchangeActions;
}
use of org.apache.ignite.internal.processors.query.QuerySchema in project ignite by apache.
the class ClusterCachesInfo method registerNewCacheTemplates.
/**
* Register new cache templates received from joining node.
*
* @param joinData Data from joining node.
* @param nodeId Joining node id.
*/
private void registerNewCacheTemplates(CacheJoinNodeDiscoveryData joinData, UUID nodeId) {
for (CacheJoinNodeDiscoveryData.CacheInfo cacheInfo : joinData.templates().values()) {
CacheConfiguration<?, ?> cfg = cacheInfo.cacheData().config();
if (!registeredTemplates.containsKey(cfg.getName())) {
DynamicCacheDescriptor desc = new DynamicCacheDescriptor(ctx, cfg, cacheInfo.cacheType(), null, true, nodeId, true, false, joinData.cacheDeploymentId(), new QuerySchema(cacheInfo.cacheData().queryEntities()), cacheInfo.cacheData().cacheConfigurationEnrichment());
DynamicCacheDescriptor old = registeredTemplates.put(cfg.getName(), desc);
assert old == null : old;
}
}
}
Aggregations