use of org.apache.ignite.internal.processors.query.h2.opt.GridH2IndexBase in project ignite by apache.
the class IgniteH2Indexing method addInitialUserIndex.
/**
* Add initial user index.
*
* @param schemaName Schema name.
* @param desc Table descriptor.
* @param h2Idx User index.
* @throws IgniteCheckedException If failed.
*/
private void addInitialUserIndex(String schemaName, H2TableDescriptor desc, GridH2IndexBase h2Idx) throws IgniteCheckedException {
GridH2Table h2Tbl = desc.table();
h2Tbl.proposeUserIndex(h2Idx);
try {
String sql = H2Utils.indexCreateSql(desc.fullTableName(), h2Idx, false);
executeSql(schemaName, sql);
} catch (Exception e) {
// Rollback and re-throw.
h2Tbl.rollbackUserIndex(h2Idx.getName());
throw e;
}
}
use of org.apache.ignite.internal.processors.query.h2.opt.GridH2IndexBase in project ignite by apache.
the class IgniteH2Indexing method dynamicIndexCreate.
/**
* {@inheritDoc}
*/
@Override
public void dynamicIndexCreate(final String schemaName, final String tblName, final QueryIndexDescriptorImpl idxDesc, boolean ifNotExists, SchemaIndexCacheVisitor cacheVisitor) throws IgniteCheckedException {
// Locate table.
H2Schema schema = schemas.get(schemaName);
H2TableDescriptor desc = (schema != null ? schema.tableByName(tblName) : null);
if (desc == null)
throw new IgniteCheckedException("Table not found in internal H2 database [schemaName=" + schemaName + ", tblName=" + tblName + ']');
GridH2Table h2Tbl = desc.table();
// Create index.
final GridH2IndexBase h2Idx = desc.createUserIndex(idxDesc);
h2Tbl.proposeUserIndex(h2Idx);
try {
// Populate index with existing cache data.
final GridH2RowDescriptor rowDesc = h2Tbl.rowDescriptor();
SchemaIndexCacheVisitorClosure clo = new SchemaIndexCacheVisitorClosure() {
@Override
public void apply(CacheDataRow row) throws IgniteCheckedException {
GridH2Row h2Row = rowDesc.createRow(row);
h2Idx.putx(h2Row);
}
};
cacheVisitor.visit(clo);
// At this point index is in consistent state, promote it through H2 SQL statement, so that cached
// prepared statements are re-built.
String sql = H2Utils.indexCreateSql(desc.fullTableName(), h2Idx, ifNotExists);
executeSql(schemaName, sql);
} catch (Exception e) {
// Rollback and re-throw.
h2Tbl.rollbackUserIndex(h2Idx.getName());
throw e;
}
}
use of org.apache.ignite.internal.processors.query.h2.opt.GridH2IndexBase in project ignite by apache.
the class GridH2Table method proposeUserIndex.
/**
* Add index that is in an intermediate state and is still being built, thus is not used in queries until it is
* promoted.
*
* @param idx Index to add.
* @throws IgniteCheckedException If failed.
*/
public void proposeUserIndex(Index idx) throws IgniteCheckedException {
assert idx instanceof GridH2IndexBase;
lock(true);
try {
ensureNotDestroyed();
Index idxExist = checkIndexPresence(idx);
if (idxExist != null) {
String idxCols = Stream.of(idxExist.getIndexColumns()).map(k -> k.columnName).collect(Collectors.joining(", "));
U.warn(log, "Index with the given set or subset of columns already exists " + "(consider dropping either new or existing index) [cacheName=" + cacheInfo.name() + ", " + "schemaName=" + getSchema().getName() + ", tableName=" + getName() + ", newIndexName=" + idx.getName() + ", existingIndexName=" + idxExist.getName() + ", existingIndexColumns=[" + idxCols + "]]");
}
Index oldTmpIdx = tmpIdxs.put(idx.getName(), (GridH2IndexBase) idx);
assert oldTmpIdx == null;
} finally {
unlock(true);
}
}
use of org.apache.ignite.internal.processors.query.h2.opt.GridH2IndexBase in project ignite by apache.
the class H2Utils method createSpatialIndex.
/**
* Create spatial index.
*
* @param tbl Table.
* @param idxName Index name.
* @param cols Columns.
*/
@SuppressWarnings("ConstantConditions")
public static GridH2IndexBase createSpatialIndex(GridH2Table tbl, String idxName, List<IndexColumn> cols) {
try {
Class<?> fctCls = Class.forName(SPATIAL_IDX_FACTORY_CLS);
Method fctMethod = fctCls.getMethod("createIndex", GridH2Table.class, String.class, List.class);
return (GridH2IndexBase) fctMethod.invoke(null, tbl, idxName, cols);
} catch (Exception e) {
throw new IgniteException("Failed to instantiate: " + SPATIAL_IDX_CLS, e);
}
}
use of org.apache.ignite.internal.processors.query.h2.opt.GridH2IndexBase in project ignite by apache.
the class SchemaManager method createInitialUserIndex.
/**
* Add initial user index.
*
* @param schemaName Schema name.
* @param desc Table descriptor.
* @param h2Idx User index.
* @throws IgniteCheckedException If failed.
*/
private void createInitialUserIndex(String schemaName, H2TableDescriptor desc, GridH2IndexBase h2Idx) throws IgniteCheckedException {
GridH2Table h2Tbl = desc.table();
h2Tbl.proposeUserIndex(h2Idx);
try {
String sql = H2Utils.indexCreateSql(desc.fullTableName(), h2Idx, false);
connMgr.executeStatement(schemaName, sql);
} catch (Exception e) {
// Rollback and re-throw.
h2Tbl.rollbackUserIndex(h2Idx.getName());
throw e;
}
}
Aggregations