Search in sources :

Example 1 with H2TreeIndex

use of org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex in project ignite by apache.

the class IgniteH2Indexing method rebuildIndexesFromHash.

/** {@inheritDoc} */
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
@Override
public void rebuildIndexesFromHash(GridCacheContext cctx, String schemaName, String typeName) throws IgniteCheckedException {
    H2TableDescriptor tbl = tableDescriptor(schemaName, typeName);
    if (tbl == null)
        return;
    assert tbl.table() != null;
    assert tbl.table().rebuildFromHashInProgress();
    H2PkHashIndex hashIdx = tbl.primaryKeyHashIndex();
    Cursor cursor = hashIdx.find((Session) null, null, null);
    while (cursor.next()) {
        CacheDataRow dataRow = (CacheDataRow) cursor.get();
        boolean done = false;
        while (!done) {
            GridCacheEntryEx entry = cctx.cache().entryEx(dataRow.key());
            try {
                synchronized (entry) {
                    // TODO : How to correctly get current value and link here?
                    GridH2Row row = tbl.table().rowDescriptor().createRow(entry.key(), entry.partition(), dataRow.value(), entry.version(), entry.expireTime());
                    row.link(dataRow.link());
                    List<Index> indexes = tbl.table().getAllIndexes();
                    for (int i = 2; i < indexes.size(); i++) {
                        Index idx = indexes.get(i);
                        if (idx instanceof H2TreeIndex)
                            ((H2TreeIndex) idx).put(row);
                    }
                    done = true;
                }
            } catch (GridCacheEntryRemovedException e) {
            // No-op
            }
        }
    }
    tbl.table().markRebuildFromHashInProgress(false);
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.database.CacheDataRow) H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridH2Row(org.apache.ignite.internal.processors.query.h2.opt.GridH2Row) Index(org.h2.index.Index) H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex) H2PkHashIndex(org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) H2PkHashIndex(org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex) QueryCursor(org.apache.ignite.cache.query.QueryCursor) Cursor(org.h2.index.Cursor) FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor)

Example 2 with H2TreeIndex

use of org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex in project ignite by apache.

the class IgniteH2Indexing method createSortedIndex.

/**
     * Create sorted index.
     *
     * @param schema Schema.
     * @param name Index name,
     * @param tbl Table.
     * @param pk Primary key flag.
     * @param cols Columns.
     * @return Index.
     */
public GridH2IndexBase createSortedIndex(H2Schema schema, String name, GridH2Table tbl, boolean pk, List<IndexColumn> cols, int inlineSize) {
    try {
        GridCacheContext cctx = tbl.cache();
        if (log.isDebugEnabled())
            log.debug("Creating cache index [cacheId=" + cctx.cacheId() + ", idxName=" + name + ']');
        final int segments = tbl.rowDescriptor().context().config().getQueryParallelism();
        return new H2TreeIndex(cctx, tbl, name, pk, cols, inlineSize, segments);
    } catch (IgniteCheckedException e) {
        throw new IgniteException(e);
    }
}
Also used : H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException)

Example 3 with H2TreeIndex

use of org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex in project ignite by apache.

the class GridH2Table method createDuplicateIndexIfNeeded.

/**
     * Creates proxy index for given target index.
     * Proxy index refers to alternative key and val columns.
     *
     * @param target Index to clone.
     * @return Proxy index.
     */
public Index createDuplicateIndexIfNeeded(Index target) {
    if (!(target instanceof H2TreeIndex) && !(target instanceof SpatialIndex))
        return null;
    IndexColumn[] cols = target.getIndexColumns();
    List<IndexColumn> proxyCols = new ArrayList<>(cols.length);
    boolean modified = false;
    for (IndexColumn col : cols) {
        IndexColumn proxyCol = new IndexColumn();
        proxyCol.columnName = col.columnName;
        proxyCol.column = col.column;
        proxyCol.sortType = col.sortType;
        int altColId = desc.getAlternativeColumnId(proxyCol.column.getColumnId());
        if (altColId != proxyCol.column.getColumnId()) {
            proxyCol.column = getColumn(altColId);
            proxyCol.columnName = proxyCol.column.getName();
            modified = true;
        }
        proxyCols.add(proxyCol);
    }
    if (modified) {
        String proxyName = target.getName() + "_proxy";
        if (target.getIndexType().isSpatial())
            return new GridH2ProxySpatialIndex(this, proxyName, proxyCols, target);
        return new GridH2ProxyIndex(this, proxyName, proxyCols, target);
    }
    return null;
}
Also used : H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex) SpatialIndex(org.h2.index.SpatialIndex) ArrayList(java.util.ArrayList) IndexColumn(org.h2.table.IndexColumn)

Aggregations

H2TreeIndex (org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex)3 ArrayList (java.util.ArrayList)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 FieldsQueryCursor (org.apache.ignite.cache.query.FieldsQueryCursor)1 QueryCursor (org.apache.ignite.cache.query.QueryCursor)1 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)1 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)1 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)1 CacheDataRow (org.apache.ignite.internal.processors.cache.database.CacheDataRow)1 H2PkHashIndex (org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex)1 GridH2Row (org.apache.ignite.internal.processors.query.h2.opt.GridH2Row)1 Cursor (org.h2.index.Cursor)1 Index (org.h2.index.Index)1 SpatialIndex (org.h2.index.SpatialIndex)1 IndexColumn (org.h2.table.IndexColumn)1