Search in sources :

Example 1 with Index

use of org.apache.ignite.internal.cache.query.index.Index 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 2 with Index

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

the class ComputeInlineSizeTest method checkIdxsInlineSizes.

/**
 */
private void checkIdxsInlineSizes() {
    Collection<Index> idx = ignite.context().indexProcessor().indexes(context());
    Map<String, Integer> expInlineSize = new HashMap<String, Integer>() {

        {
            // 9 is inline for _KEY (LongIndexKeyType).
            put("PERSON_STR_IDX", 9 + InlineIndexTree.IGNITE_VARIABLE_TYPE_DEFAULT_INLINE_SIZE);
            put("PERSON_STRPRECBIG_IDX", InlineIndexTree.IGNITE_MAX_INDEX_PAYLOAD_SIZE_DEFAULT);
            // 3 is for storing info (type, length) of inlined key.
            put("PERSON_STRPREC_IDX", 9 + InlineIndexTree.IGNITE_VARIABLE_TYPE_DEFAULT_INLINE_SIZE + 10 + 3);
            put("PERSON_BYTES_IDX", 9 + InlineIndexTree.IGNITE_VARIABLE_TYPE_DEFAULT_INLINE_SIZE);
            put("PERSON_BYTESPREC_IDX", 9 + InlineIndexTree.IGNITE_VARIABLE_TYPE_DEFAULT_INLINE_SIZE + 20 + 3);
        }
    };
    for (Index i : idx) {
        InlineIndexImpl impl = (InlineIndexImpl) i;
        if (expInlineSize.containsKey(impl.name())) {
            int inlineSize = expInlineSize.remove(impl.name());
            assertEquals(inlineSize, impl.inlineSize());
        }
    }
    assertTrue(expInlineSize.isEmpty());
}
Also used : InlineIndexImpl(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexImpl) HashMap(java.util.HashMap) Index(org.apache.ignite.internal.cache.query.index.Index)

Example 3 with Index

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

the class DropIndexTest method checkDestroyIndexTrees.

/**
 * Checking {@link DurableBackgroundCleanupIndexTreeTaskV2#destroyIndexTrees}.
 *
 * @param persistent Persistent default data region.
 * @param expRes Expected result should not be less than which.
 * @throws Exception If failed.
 */
private void checkDestroyIndexTrees(boolean persistent, long expRes) throws Exception {
    IgniteEx n = startGrid(0, cfg -> {
        cfg.getDataStorageConfiguration().getDefaultDataRegionConfiguration().setPersistenceEnabled(persistent);
    });
    n.cluster().state(ACTIVE);
    IgniteCache<Integer, Person> cache = n.cache(DEFAULT_CACHE_NAME);
    populate(cache, 100);
    String idxName = "IDX0";
    createIdx(cache, idxName);
    GridCacheContext<Integer, Person> cctx = cacheContext(cache);
    Index idx = index(n, cache, idxName);
    SortedIndexDefinition idxDef = indexDefinition(idx);
    String treeName = idxDef.treeName();
    int segments = idxDef.segments();
    Map<Integer, RootPage> rootPages = new HashMap<>();
    if (persistent)
        rootPages.putAll(findIndexRootPages(cctx.group(), cctx.name(), treeName, segments));
    else
        rootPages.putAll(toRootPages(segments(idx)));
    assertFalse(rootPages.isEmpty());
    // Emulating worker cancellation, let's make sure it doesn't cause problems.
    Thread.currentThread().interrupt();
    long pageCnt = 0;
    for (Map.Entry<Integer, RootPage> e : rootPages.entrySet()) pageCnt += destroyIndexTrees(cctx.group(), e.getValue(), cctx.name(), treeName, e.getKey());
    assertTrue(pageCnt >= expRes);
    assertTrue(findIndexRootPages(cctx.group(), cctx.name(), treeName, segments).isEmpty());
}
Also used : HashMap(java.util.HashMap) SortedIndexDefinition(org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition) Index(org.apache.ignite.internal.cache.query.index.Index) IgniteEx(org.apache.ignite.internal.IgniteEx) RootPage(org.apache.ignite.internal.processors.cache.persistence.RootPage) Person(org.apache.ignite.client.Person) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with Index

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

the class DropIndexTest method testCorrectTaskExecute.

/**
 * Checking that the {@link DurableBackgroundCleanupIndexTreeTaskV2} will work correctly.
 *
 * @throws Exception If failed.
 */
@Test
public void testCorrectTaskExecute() throws Exception {
    IgniteEx n = startGrid(0);
    IgniteCache<Integer, Person> cache = n.cache(DEFAULT_CACHE_NAME);
    populate(cache, 100);
    String idxName = "IDX0";
    createIdx(cache, idxName);
    GridCacheContext<Integer, Person> cctx = cacheContext(cache);
    Index idx = index(n, cache, idxName);
    SortedIndexDefinition idxDef = indexDefinition(idx);
    InlineIndexTree[] trees = segments(idx);
    Map<Integer, RootPage> rootPages = toRootPages(trees);
    for (int i = 0; i < trees.length; i++) {
        InlineIndexTree tree = trees[i];
        assertEquals(new FullPageId(tree.getMetaPageId(), tree.groupId()), rootPages.get(i).pageId());
    }
    String oldTreeName = idxDef.treeName();
    String newTreeName = UUID.randomUUID().toString();
    int segments = idxDef.segments();
    assertFalse(findIndexRootPages(cctx.group(), cctx.name(), oldTreeName, segments).isEmpty());
    assertTrue(findIndexRootPages(cctx.group(), cctx.name(), newTreeName, segments).isEmpty());
    DurableBackgroundCleanupIndexTreeTaskV2 task = new DurableBackgroundCleanupIndexTreeTaskV2(cctx.group().name(), cctx.name(), idxName, oldTreeName, newTreeName, segments, trees);
    assertTrue(task.name().startsWith(taskNamePrefix(cctx.name(), idxName)));
    assertTrue(getFieldValue(task, "needToRen"));
    GridFutureAdapter<Void> startFut = new GridFutureAdapter<>();
    GridFutureAdapter<Void> endFut = new GridFutureAdapter<>();
    idxTreeFactory = taskIndexTreeFactoryEx(startFut, endFut);
    IgniteInternalFuture<DurableBackgroundTaskResult<Long>> taskFut = task.executeAsync(n.context());
    startFut.get(getTestTimeout());
    assertTrue(findIndexRootPages(cctx.group(), cctx.name(), oldTreeName, segments).isEmpty());
    assertFalse(findIndexRootPages(cctx.group(), cctx.name(), newTreeName, segments).isEmpty());
    endFut.onDone();
    DurableBackgroundTaskResult<Long> res = taskFut.get(getTestTimeout());
    assertTrue(res.completed());
    assertNull(res.error());
    assertTrue(res.result() >= 3);
    assertTrue(findIndexRootPages(cctx.group(), cctx.name(), oldTreeName, segments).isEmpty());
    assertTrue(findIndexRootPages(cctx.group(), cctx.name(), newTreeName, segments).isEmpty());
    assertFalse(getFieldValue(task, "needToRen"));
}
Also used : SortedIndexDefinition(org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition) InlineIndexTree(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexTree) Index(org.apache.ignite.internal.cache.query.index.Index) DurableBackgroundTaskResult(org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTaskResult) DurableBackgroundCleanupIndexTreeTaskV2(org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2) IgniteEx(org.apache.ignite.internal.IgniteEx) RootPage(org.apache.ignite.internal.processors.cache.persistence.RootPage) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) Person(org.apache.ignite.client.Person) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) Test(org.junit.Test)

Aggregations

Index (org.apache.ignite.internal.cache.query.index.Index)4 HashMap (java.util.HashMap)2 Person (org.apache.ignite.client.Person)2 IgniteEx (org.apache.ignite.internal.IgniteEx)2 SortedIndexDefinition (org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition)2 RootPage (org.apache.ignite.internal.processors.cache.persistence.RootPage)2 Map (java.util.Map)1 IgniteException (org.apache.ignite.IgniteException)1 IndexDefinition (org.apache.ignite.internal.cache.query.index.IndexDefinition)1 IndexName (org.apache.ignite.internal.cache.query.index.IndexName)1 DurableBackgroundCleanupIndexTreeTaskV2 (org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2)1 IndexKeyDefinition (org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition)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 InlineIndexTree (org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexTree)1 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)1 DurableBackgroundTaskResult (org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTaskResult)1 QueryIndexKeyDefinitionProvider (org.apache.ignite.internal.processors.query.h2.index.QueryIndexKeyDefinitionProvider)1 QueryIndexRowHandler (org.apache.ignite.internal.processors.query.h2.index.QueryIndexRowHandler)1 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)1