use of org.apache.ignite.internal.processors.cache.GridCacheContextInfo in project ignite by apache.
the class GridQueryProcessor method processSchemaOperationLocal.
/**
* Process schema operation.
*
* @param op Operation.
* @param type Type descriptor.
* @param depId Cache deployment ID.
* @param cancelTok Cancel token.
* @throws SchemaOperationException If failed.
*/
public void processSchemaOperationLocal(SchemaAbstractOperation op, QueryTypeDescriptorImpl type, IgniteUuid depId, IndexRebuildCancelToken cancelTok) throws SchemaOperationException {
if (log.isDebugEnabled())
log.debug("Started local index operation [opId=" + op.id() + ']');
String cacheName = op.cacheName();
GridCacheContextInfo<?, ?> cacheInfo = null;
if (op instanceof SchemaAddQueryEntityOperation) {
GridCacheContext<?, ?> cctx = ctx.cache().context().cacheContext(CU.cacheId(cacheName));
if (cctx != null)
cacheInfo = new GridCacheContextInfo<>(cctx, false);
else
return;
} else
cacheInfo = idx.registeredCacheInfo(cacheName);
if (cacheInfo == null || !F.eq(depId, cacheInfo.dynamicDeploymentId()))
throw new SchemaOperationException(SchemaOperationException.CODE_CACHE_NOT_FOUND, cacheName);
try {
if (op instanceof SchemaIndexCreateOperation) {
SchemaIndexCreateOperation op0 = (SchemaIndexCreateOperation) op;
QueryIndexDescriptorImpl idxDesc = QueryUtils.createIndexDescriptor(type, op0.index());
SchemaIndexCacheVisitor visitor;
if (cacheInfo.isCacheContextInited()) {
int buildIdxPoolSize = ctx.config().getBuildIndexThreadPoolSize();
int parallel = op0.parallel();
if (parallel > buildIdxPoolSize) {
String idxName = op0.indexName();
log.warning("Provided parallelism " + parallel + " for creation of index " + idxName + " is greater than the number of index building threads. Will use " + buildIdxPoolSize + " threads to build index. Increase by IgniteConfiguration.setBuildIndexThreadPoolSize" + " and restart the node if you want to use more threads. [tableName=" + op0.tableName() + ", indexName=" + idxName + ", requestedParallelism=" + parallel + ", buildIndexPoolSize=" + buildIdxPoolSize + "]");
}
GridFutureAdapter<Void> createIdxFut = new GridFutureAdapter<>();
GridCacheContext<?, ?> cacheCtx = cacheInfo.cacheContext();
visitor = new SchemaIndexCacheVisitorImpl(cacheCtx, cancelTok, createIdxFut) {
/**
* {@inheritDoc}
*/
@Override
public void visit(SchemaIndexCacheVisitorClosure clo) {
idxBuildStatusStorage.onStartBuildNewIndex(cacheCtx);
try {
super.visit(clo);
buildIdxFut.get();
} catch (Exception e) {
throw new IgniteException(e);
} finally {
idxBuildStatusStorage.onFinishBuildNewIndex(cacheName);
}
}
};
} else
// For not started caches we shouldn't add any data to index.
visitor = clo -> {
};
idx.dynamicIndexCreate(op0.schemaName(), op0.tableName(), idxDesc, op0.ifNotExists(), visitor);
} else if (op instanceof SchemaIndexDropOperation) {
SchemaIndexDropOperation op0 = (SchemaIndexDropOperation) op;
idx.dynamicIndexDrop(op0.schemaName(), op0.indexName(), op0.ifExists());
} else if (op instanceof SchemaAlterTableAddColumnOperation) {
SchemaAlterTableAddColumnOperation op0 = (SchemaAlterTableAddColumnOperation) op;
processDynamicAddColumn(type, op0.columns());
idx.dynamicAddColumn(op0.schemaName(), op0.tableName(), op0.columns(), op0.ifTableExists(), op0.ifNotExists());
} else if (op instanceof SchemaAlterTableDropColumnOperation) {
SchemaAlterTableDropColumnOperation op0 = (SchemaAlterTableDropColumnOperation) op;
processDynamicDropColumn(type, op0.columns());
idx.dynamicDropColumn(op0.schemaName(), op0.tableName(), op0.columns(), op0.ifTableExists(), op0.ifExists());
} else if (op instanceof SchemaAddQueryEntityOperation) {
SchemaAddQueryEntityOperation op0 = (SchemaAddQueryEntityOperation) op;
if (!cacheNames.contains(op0.cacheName())) {
cacheInfo.onSchemaAddQueryEntity(op0);
T3<Collection<QueryTypeCandidate>, Map<String, QueryTypeDescriptorImpl>, Map<String, QueryTypeDescriptorImpl>> candRes = createQueryCandidates(op0.cacheName(), op0.schemaName(), cacheInfo, op0.entities(), op0.isSqlEscape());
registerCache0(op0.cacheName(), op.schemaName(), cacheInfo, candRes.get1(), false);
}
if (idxRebuildFutStorage.prepareRebuildIndexes(singleton(cacheInfo.cacheId()), null).isEmpty())
rebuildIndexesFromHash0(cacheInfo.cacheContext(), false, cancelTok);
else {
if (log.isInfoEnabled())
log.info("Rebuilding indexes for the cache is already in progress: " + cacheInfo.name());
}
} else
throw new SchemaOperationException("Unsupported operation: " + op);
} catch (Throwable e) {
if (e instanceof SchemaOperationException)
throw (SchemaOperationException) e;
else
throw new SchemaOperationException("Schema change operation failed: " + e.getMessage(), e);
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheContextInfo in project ignite by apache.
the class QueryParser method mvccCacheIdForSelect.
/**
* Get ID of the first MVCC cache for SELECT.
*
* @param objMap Object map.
* @return ID of the first MVCC cache or {@code null} if no MVCC caches involved.
*/
private Integer mvccCacheIdForSelect(Map<Object, Object> objMap) {
Boolean mvccEnabled = null;
Integer mvccCacheId = null;
GridCacheContextInfo cctx = null;
for (Object o : objMap.values()) {
if (o instanceof GridSqlAlias)
o = GridSqlAlias.unwrap((GridSqlAst) o);
if (o instanceof GridSqlTable && ((GridSqlTable) o).dataTable() != null) {
GridSqlTable tbl = (GridSqlTable) o;
if (tbl.dataTable() != null) {
GridCacheContextInfo curCctx = tbl.dataTable().cacheInfo();
assert curCctx != null;
boolean curMvccEnabled = curCctx.config().getAtomicityMode() == CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT;
if (mvccEnabled == null) {
mvccEnabled = curMvccEnabled;
if (mvccEnabled)
mvccCacheId = curCctx.cacheId();
cctx = curCctx;
} else if (mvccEnabled != curMvccEnabled)
MvccUtils.throwAtomicityModesMismatchException(cctx.config(), curCctx.config());
}
}
}
return mvccCacheId;
}
use of org.apache.ignite.internal.processors.cache.GridCacheContextInfo in project ignite by apache.
the class QueryParser method prepareDmlStatement.
/**
* Prepare DML statement.
*
* @param planKey Plan key.
* @param prepared Prepared.
* @return Statement.
*/
private QueryParserResultDml prepareDmlStatement(QueryDescriptor planKey, Prepared prepared) {
if (F.eq(QueryUtils.SCHEMA_SYS, planKey.schemaName()))
throw new IgniteSQLException("DML statements are not supported on " + planKey.schemaName() + " schema", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
// Prepare AST.
GridSqlQueryParser parser = new GridSqlQueryParser(false, log);
GridSqlStatement stmt = parser.parse(prepared);
List<GridH2Table> tbls = parser.tablesForDml();
// available on local node.
for (GridH2Table h2tbl : tbls) H2Utils.checkAndStartNotStartedCache(idx.kernalContext(), h2tbl);
// Check MVCC mode.
GridCacheContextInfo ctx = null;
boolean mvccEnabled = false;
for (GridH2Table h2tbl : tbls) {
GridCacheContextInfo curCtx = h2tbl.cacheInfo();
boolean curMvccEnabled = curCtx.config().getAtomicityMode() == CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT;
if (ctx == null) {
ctx = curCtx;
mvccEnabled = curMvccEnabled;
} else if (curMvccEnabled != mvccEnabled)
MvccUtils.throwAtomicityModesMismatchException(ctx.config(), curCtx.config());
}
// Get streamer info.
GridH2Table streamTbl = null;
if (GridSqlQueryParser.isStreamableInsertStatement(prepared)) {
GridSqlInsert insert = (GridSqlInsert) stmt;
streamTbl = DmlAstUtils.gridTableForElement(insert.into()).dataTable();
}
// Create update plan.
UpdatePlan plan;
try {
plan = UpdatePlanBuilder.planForStatement(planKey, stmt, mvccEnabled, idx, log, forceFillAbsentPKsWithDefaults);
} catch (Exception e) {
if (e instanceof IgniteSQLException)
throw (IgniteSQLException) e;
else
throw new IgniteSQLException("Failed to prepare update plan.", e);
}
return new QueryParserResultDml(stmt, mvccEnabled, streamTbl, plan);
}
use of org.apache.ignite.internal.processors.cache.GridCacheContextInfo in project ignite by apache.
the class IgniteH2Indexing method createSortedIndex.
/**
* Create sorted index.
*
* @param name Index name,
* @param tbl Table.
* @param pk Primary key flag.
* @param affinityKey Affinity key flag.
* @param unwrappedCols Unwrapped index columns for complex types.
* @param wrappedCols Index columns as is complex types.
* @param inlineSize Index inline size.
* @param cacheVisitor whether index created with new cache or on existing one.
* @return Index.
*/
@SuppressWarnings("ConstantConditions")
GridH2IndexBase createSortedIndex(String name, GridH2Table tbl, boolean pk, boolean affinityKey, List<IndexColumn> unwrappedCols, List<IndexColumn> wrappedCols, int inlineSize, @Nullable SchemaIndexCacheVisitor cacheVisitor) {
GridCacheContextInfo cacheInfo = tbl.cacheInfo();
if (log.isDebugEnabled())
log.debug("Creating cache index [cacheId=" + cacheInfo.cacheId() + ", idxName=" + name + ']');
if (cacheInfo.affinityNode()) {
QueryIndexDefinition idxDef = new QueryIndexDefinition(tbl, name, ctx.indexProcessor().rowCacheCleaner(cacheInfo.groupId()), pk, affinityKey, unwrappedCols, wrappedCols, inlineSize);
org.apache.ignite.internal.cache.query.index.Index index;
if (cacheVisitor != null)
index = ctx.indexProcessor().createIndexDynamically(tbl.cacheContext(), idxFactory, idxDef, cacheVisitor);
else
index = ctx.indexProcessor().createIndex(tbl.cacheContext(), idxFactory, idxDef);
InlineIndexImpl queryIndex = index.unwrap(InlineIndexImpl.class);
return new H2TreeIndex(queryIndex, tbl, unwrappedCols.toArray(new IndexColumn[0]), pk, log);
} else {
ClientIndexDefinition d = new ClientIndexDefinition(tbl, new IndexName(tbl.cacheName(), tbl.getSchema().getName(), tbl.getName(), name), unwrappedCols, inlineSize, tbl.cacheInfo().config().getSqlIndexMaxInlineSize());
org.apache.ignite.internal.cache.query.index.Index index = ctx.indexProcessor().createIndex(tbl.cacheContext(), ClientIndexFactory.INSTANCE, d);
InlineIndex idx = index.unwrap(InlineIndex.class);
IndexType idxType = pk ? IndexType.createPrimaryKey(false, false) : IndexType.createNonUnique(false, false, false);
return new H2TreeClientIndex(idx, tbl, name, unwrappedCols.toArray(new IndexColumn[0]), idxType);
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheContextInfo in project ignite by apache.
the class GridQueryProcessor method initQueryStructuresForNotStartedCache.
/**
* Initialize query infrastructure for not started cache.
*
* @param cacheDesc Cache descriptor.
* @throws IgniteCheckedException If failed.
*/
public void initQueryStructuresForNotStartedCache(DynamicCacheDescriptor cacheDesc) throws IgniteCheckedException {
QuerySchema schema = cacheDesc.schema() != null ? cacheDesc.schema() : new QuerySchema();
GridCacheContextInfo cacheInfo = new GridCacheContextInfo(cacheDesc);
onCacheStart(cacheInfo, schema, cacheDesc.sql());
}
Aggregations