Search in sources :

Example 16 with GridH2IndexBase

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;
    }
}
Also used : GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) IgniteSystemProperties.getString(org.apache.ignite.IgniteSystemProperties.getString) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SqlParseException(org.apache.ignite.internal.sql.SqlParseException) SQLException(java.sql.SQLException) IgniteException(org.apache.ignite.IgniteException) CacheException(javax.cache.CacheException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException)

Example 17 with GridH2IndexBase

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;
    }
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) GridH2IndexBase(org.apache.ignite.internal.processors.query.h2.opt.GridH2IndexBase) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridH2RowDescriptor(org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) GridH2Row(org.apache.ignite.internal.processors.query.h2.opt.GridH2Row) SchemaIndexCacheVisitorClosure(org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheVisitorClosure) IgniteSystemProperties.getString(org.apache.ignite.IgniteSystemProperties.getString) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SqlParseException(org.apache.ignite.internal.sql.SqlParseException) SQLException(java.sql.SQLException) IgniteException(org.apache.ignite.IgniteException) CacheException(javax.cache.CacheException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException)

Example 18 with GridH2IndexBase

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);
    }
}
Also used : DbObject(org.h2.engine.DbObject) QueryUtils(org.apache.ignite.internal.processors.query.QueryUtils) H2IndexType(org.apache.ignite.internal.processors.query.h2.database.H2IndexType) IndexingQueryFilter(org.apache.ignite.spi.indexing.IndexingQueryFilter) DbException(org.h2.message.DbException) H2Utils(org.apache.ignite.internal.processors.query.h2.H2Utils) Index(org.h2.index.Index) SCAN_INDEX_NAME_SUFFIX(org.apache.ignite.internal.processors.query.h2.opt.H2TableScanIndex.SCAN_INDEX_NAME_SUFFIX) IndexKeyDefinition(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition) SysProperties(org.h2.engine.SysProperties) Map(java.util.Map) Row(org.h2.result.Row) IndexingQueryCacheFilter(org.apache.ignite.spi.indexing.IndexingQueryCacheFilter) PARTITIONED(org.apache.ignite.cache.CacheMode.PARTITIONED) IndexProcessor(org.apache.ignite.internal.cache.query.index.IndexProcessor) QueryTable(org.apache.ignite.internal.processors.cache.query.QueryTable) CachePeekMode(org.apache.ignite.cache.CachePeekMode) QueryField(org.apache.ignite.internal.processors.query.QueryField) GridToStringExclude(org.apache.ignite.internal.util.tostring.GridToStringExclude) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SortOrder(org.h2.result.SortOrder) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) Collectors(java.util.stream.Collectors) Insert(org.h2.command.dml.Insert) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex) IndexColumn(org.h2.table.IndexColumn) Stream(java.util.stream.Stream) DataType(org.h2.value.DataType) CreateTableData(org.h2.command.ddl.CreateTableData) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) LongAdder(java.util.concurrent.atomic.LongAdder) AtomicIntegerFieldUpdater(java.util.concurrent.atomic.AtomicIntegerFieldUpdater) SchemaObject(org.h2.schema.SchemaObject) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) IgniteLogger(org.apache.ignite.IgniteLogger) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) QueryRetryException(org.apache.ignite.cache.query.QueryRetryException) IndexInformation(org.apache.ignite.internal.processors.query.h2.database.IndexInformation) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) GridKernalContext(org.apache.ignite.internal.GridKernalContext) LinkedHashMap(java.util.LinkedHashMap) Column(org.h2.table.Column) ObjectStatistics(org.apache.ignite.internal.processors.query.stat.ObjectStatistics) Session(org.h2.engine.Session) IgniteH2Indexing(org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing) IndexType(org.h2.index.IndexType) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IndexName(org.apache.ignite.internal.cache.query.index.IndexName) H2TableDescriptor(org.apache.ignite.internal.processors.query.h2.H2TableDescriptor) Table(org.h2.table.Table) StatisticsKey(org.apache.ignite.internal.processors.query.stat.StatisticsKey) F(org.apache.ignite.internal.util.typedef.F) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) H2TreeIndexBase(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndexBase) GridCacheContextInfo(org.apache.ignite.internal.processors.cache.GridCacheContextInfo) TableType(org.h2.table.TableType) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) SpatialIndex(org.h2.index.SpatialIndex) Lock(java.util.concurrent.locks.Lock) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) IndexDefinition(org.apache.ignite.internal.cache.query.index.IndexDefinition) TableBase(org.h2.table.TableBase) PK_HASH_IDX_NAME(org.apache.ignite.internal.processors.query.h2.H2TableDescriptor.PK_HASH_IDX_NAME) Index(org.h2.index.Index) H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex) SpatialIndex(org.h2.index.SpatialIndex)

Example 19 with GridH2IndexBase

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);
    }
}
Also used : GridH2IndexBase(org.apache.ignite.internal.processors.query.h2.opt.GridH2IndexBase) IgniteException(org.apache.ignite.IgniteException) Method(java.lang.reflect.Method) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) GridH2RetryException(org.apache.ignite.internal.processors.query.h2.opt.GridH2RetryException) SQLException(java.sql.SQLException) CacheException(javax.cache.CacheException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException)

Example 20 with GridH2IndexBase

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;
    }
}
Also used : GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) SQLException(java.sql.SQLException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)9 IgniteException (org.apache.ignite.IgniteException)9 H2TreeIndex (org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex)8 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)7 GridH2IndexBase (org.apache.ignite.internal.processors.query.h2.opt.GridH2IndexBase)7 SQLException (java.sql.SQLException)6 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)6 Index (org.h2.index.Index)6 IndexColumn (org.h2.table.IndexColumn)6 ArrayList (java.util.ArrayList)5 GridH2RowDescriptor (org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor)5 SpatialIndex (org.h2.index.SpatialIndex)5 Column (org.h2.table.Column)4 CacheException (javax.cache.CacheException)3 IgniteSystemProperties.getString (org.apache.ignite.IgniteSystemProperties.getString)3 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)3 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 QueryCancelledException (org.apache.ignite.cache.query.QueryCancelledException)2