Search in sources :

Example 1 with IndexName

use of org.apache.ignite.internal.cache.query.index.IndexName in project ignite by apache.

the class LongDestroyDurableBackgroundTaskTest method testConvertOldTaskToNew.

/**
 * Checking the converting of the old problem into the new one.
 */
@Test
public void testConvertOldTaskToNew() {
    String grpName = "grpTest";
    String cacheName = "cacheTest";
    String treeName = "treeTest";
    String idxName = "idxTest";
    List<Long> pages = F.asList(100L);
    DurableBackgroundCleanupIndexTreeTask oldTask = new DurableBackgroundCleanupIndexTreeTask(pages, emptyList(), grpName, cacheName, new IndexName(cacheName, "schemaTest", "tableTest", idxName), treeName);
    DurableBackgroundTask convertedTask = oldTask.convertAfterRestoreIfNeeded();
    assertTrue(convertedTask instanceof DurableBackgroundCleanupIndexTreeTaskV2);
    assertEquals(grpName, getFieldValue(convertedTask, "grpName"));
    assertEquals(cacheName, getFieldValue(convertedTask, "cacheName"));
    assertEquals(treeName, getFieldValue(convertedTask, "oldTreeName"));
    assertNotNull(getFieldValue(convertedTask, "newTreeName"));
    assertEquals(idxName, getFieldValue(convertedTask, "idxName"));
    assertEquals(pages.size(), (int) getFieldValue(convertedTask, "segments"));
}
Also used : IndexName(org.apache.ignite.internal.cache.query.index.IndexName) DurableBackgroundTask(org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTask) AtomicLong(java.util.concurrent.atomic.AtomicLong) DurableBackgroundCleanupIndexTreeTaskV2(org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2) DurableBackgroundCleanupIndexTreeTask(org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTask) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with IndexName

use of org.apache.ignite.internal.cache.query.index.IndexName in project ignite by apache.

the class GeoSpatialUtils method createIndex.

/**
 */
public static GridH2SpatialIndex createIndex(GridH2Table tbl, String idxName, List<IndexColumn> cols) {
    try {
        IndexName name = new IndexName(tbl.cacheName(), tbl.getSchema().getName(), tbl.getName(), idxName);
        LinkedHashMap<String, IndexKeyDefinition> keyDefs = new QueryIndexKeyDefinitionProvider(tbl, cols).keyDefinitions();
        List<InlineIndexKeyType> idxKeyTypes = InlineIndexKeyTypeRegistry.types(keyDefs.values(), DUMMY_SETTINGS);
        QueryIndexRowHandler rowHnd = new QueryIndexRowHandler(tbl, cols, keyDefs, idxKeyTypes, DUMMY_SETTINGS);
        final int segments = tbl.rowDescriptor().cacheInfo().config().getQueryParallelism();
        IndexDefinition def = new GeoSpatialIndexDefinition(name, keyDefs, rowHnd, segments);
        Index idx = tbl.cacheContext().kernalContext().indexProcessor().createIndex(tbl.cacheContext(), GeoSpatialIndexFactory.INSTANCE, def);
        return new GridH2SpatialIndex(idx.unwrap(GeoSpatialIndexImpl.class));
    } catch (Exception e) {
        throw new IgniteException("Failed to instantiate", e);
    }
}
Also used : QueryIndexKeyDefinitionProvider(org.apache.ignite.internal.processors.query.h2.index.QueryIndexKeyDefinitionProvider) IndexKeyDefinition(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition) InlineIndexKeyType(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType) Index(org.apache.ignite.internal.cache.query.index.Index) QueryIndexRowHandler(org.apache.ignite.internal.processors.query.h2.index.QueryIndexRowHandler) IgniteException(org.apache.ignite.IgniteException) IndexName(org.apache.ignite.internal.cache.query.index.IndexName) IndexDefinition(org.apache.ignite.internal.cache.query.index.IndexDefinition) IgniteException(org.apache.ignite.IgniteException)

Example 3 with IndexName

use of org.apache.ignite.internal.cache.query.index.IndexName 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);
    }
}
Also used : H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex) InlineIndex(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndex) IndexColumn(org.h2.table.IndexColumn) IndexName(org.apache.ignite.internal.cache.query.index.IndexName) InlineIndexImpl(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexImpl) QueryIndexDefinition(org.apache.ignite.internal.processors.query.h2.index.QueryIndexDefinition) GridCacheContextInfo(org.apache.ignite.internal.processors.cache.GridCacheContextInfo) H2TreeClientIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeClientIndex) ClientIndexDefinition(org.apache.ignite.internal.processors.query.h2.index.client.ClientIndexDefinition) IndexType(org.h2.index.IndexType)

Example 4 with IndexName

use of org.apache.ignite.internal.cache.query.index.IndexName in project ignite by apache.

the class GridH2Table method destroyIndex.

/**
 * Destroy index with GridIndexManager.
 */
private void destroyIndex(Index idx) {
    if (idx instanceof GridH2IndexBase) {
        GridH2IndexBase h2idx = (GridH2IndexBase) idx;
        // Destroy underlying Ignite index.
        IndexDefinition deleteDef = new IndexDefinition() {

            /**
             * {@inheritDoc}
             */
            @Override
            public IndexName idxName() {
                return new IndexName(cacheName(), getSchema().getName(), tableName, idx.getName());
            }

            /**
             * {@inheritDoc}
             */
            @Override
            public LinkedHashMap<String, IndexKeyDefinition> indexKeyDefinitions() {
                throw new UnsupportedOperationException("Hasn't be invoked for destroyed index.");
            }
        };
        idxMgr.removeIndex(cacheContext(), deleteDef.idxName(), !rmIndex);
        // Call it too, if H2 index stores some state.
        h2idx.destroy(rmIndex);
    }
}
Also used : IndexName(org.apache.ignite.internal.cache.query.index.IndexName) IndexDefinition(org.apache.ignite.internal.cache.query.index.IndexDefinition) IndexKeyDefinition(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition)

Example 5 with IndexName

use of org.apache.ignite.internal.cache.query.index.IndexName in project ignite by apache.

the class IndexQueryFailoverTest method destroyIndex.

/**
 */
private void destroyIndex() {
    IndexName idxName = new IndexName(CACHE, CACHE, Person.class.getSimpleName().toUpperCase(), IDX);
    GridCacheContext cctx = ((GatewayProtectedCacheProxy) cache).context();
    cctx.kernalContext().indexProcessor().removeIndex(cctx, idxName, false);
}
Also used : IndexName(org.apache.ignite.internal.cache.query.index.IndexName) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GatewayProtectedCacheProxy(org.apache.ignite.internal.processors.cache.GatewayProtectedCacheProxy)

Aggregations

IndexName (org.apache.ignite.internal.cache.query.index.IndexName)6 IndexDefinition (org.apache.ignite.internal.cache.query.index.IndexDefinition)2 IndexKeyDefinition (org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition)2 InlineIndex (org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndex)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 IgniteException (org.apache.ignite.IgniteException)1 Index (org.apache.ignite.internal.cache.query.index.Index)1 DurableBackgroundCleanupIndexTreeTask (org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTask)1 DurableBackgroundCleanupIndexTreeTaskV2 (org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2)1 InlineIndexImpl (org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexImpl)1 InlineIndexKeyType (org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType)1 GatewayProtectedCacheProxy (org.apache.ignite.internal.processors.cache.GatewayProtectedCacheProxy)1 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)1 GridCacheContextInfo (org.apache.ignite.internal.processors.cache.GridCacheContextInfo)1 DurableBackgroundTask (org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTask)1 H2TreeClientIndex (org.apache.ignite.internal.processors.query.h2.database.H2TreeClientIndex)1 H2TreeIndex (org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex)1 QueryIndexDefinition (org.apache.ignite.internal.processors.query.h2.index.QueryIndexDefinition)1 QueryIndexKeyDefinitionProvider (org.apache.ignite.internal.processors.query.h2.index.QueryIndexKeyDefinitionProvider)1 QueryIndexRowHandler (org.apache.ignite.internal.processors.query.h2.index.QueryIndexRowHandler)1