Search in sources :

Example 6 with SortedIndexDefinition

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

the class IndexQueryProcessor method prepareQuery.

/**
 * Prepare index query.
 *
 * @return Prepared query for index range.
 */
private IndexRangeQuery prepareQuery(SortedSegmentedIndex idx, IndexQueryDesc idxQryDesc) throws IgniteCheckedException {
    SortedIndexDefinition idxDef = (SortedIndexDefinition) idxProc.indexDefinition(idx.id());
    // For PK indexes will serialize _KEY column.
    if (F.isEmpty(idxQryDesc.criteria()))
        return new IndexRangeQuery(1);
    InlineIndexImpl sortedIdx = (InlineIndexImpl) idx;
    Map<String, RangeIndexQueryCriterion> merged = mergeIndexQueryCriteria(sortedIdx, idxDef, idxQryDesc);
    return alignCriteriaWithIndex(sortedIdx, merged, idxDef);
}
Also used : InlineIndexImpl(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexImpl) SortedIndexDefinition(org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition) RangeIndexQueryCriterion(org.apache.ignite.internal.cache.query.RangeIndexQueryCriterion)

Example 7 with SortedIndexDefinition

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

the class InlineIndexFactory method createIndex.

/**
 * {@inheritDoc}
 */
@Override
public Index createIndex(GridCacheContext<?, ?> cctx, IndexDefinition def) {
    SortedIndexDefinition sdef = (SortedIndexDefinition) def;
    InlineIndexTree[] trees = new InlineIndexTree[sdef.segments()];
    InlineRecommender recommender = new InlineRecommender(cctx, sdef);
    IoStatisticsHolderIndex stats = new IoStatisticsHolderIndex(SORTED_INDEX, cctx.name(), sdef.idxName().idxName(), cctx.kernalContext().metric());
    try {
        for (int i = 0; i < sdef.segments(); ++i) {
            // Required for persistence.
            IgniteCacheDatabaseSharedManager db = cctx.shared().database();
            db.checkpointReadLock();
            try {
                RootPage page = rootPage(cctx, sdef.treeName(), i);
                trees[i] = createIndexSegment(cctx, sdef, page, stats, recommender, i);
            } finally {
                db.checkpointReadUnlock();
            }
        }
        return new InlineIndexImpl(cctx, sdef, trees, stats);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : SortedIndexDefinition(org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition) IoStatisticsHolderIndex(org.apache.ignite.internal.metric.IoStatisticsHolderIndex) RootPage(org.apache.ignite.internal.processors.cache.persistence.RootPage) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)

Example 8 with SortedIndexDefinition

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

the class RenameIndexTreeTest method testNotPersistRenamingIndexRootPage.

/**
 * Checking that if we rename the index root pages without a checkpoint,
 * then after restarting the node we will not find them.
 *
 * @throws Exception If failed.
 */
@Test
public void testNotPersistRenamingIndexRootPage() throws Exception {
    IgniteEx n = startGrid(0);
    IgniteCache<Integer, Person> cache = n.cache(DEFAULT_CACHE_NAME);
    populate(cache, 100);
    String idxName = "IDX0";
    createIdx(cache, idxName);
    enableCheckpoints(n, getTestIgniteInstanceName(), false);
    SortedIndexDefinition idxDef = indexDefinition(index(n, cache, idxName));
    String oldTreeName = idxDef.treeName();
    String newTreeName = UUID.randomUUID().toString();
    int segments = idxDef.segments();
    assertEquals(segments, renameIndexRoot(cache, oldTreeName, newTreeName, segments).size());
    stopGrid(0);
    n = startGrid(0);
    cache = n.cache(DEFAULT_CACHE_NAME);
    assertExistIndexRoot(cache, oldTreeName, segments, true);
    assertExistIndexRoot(cache, newTreeName, segments, false);
}
Also used : SortedIndexDefinition(org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition) IgniteEx(org.apache.ignite.internal.IgniteEx) Person(org.apache.ignite.client.Person) Test(org.junit.Test)

Example 9 with SortedIndexDefinition

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

the class RenameIndexTreeTest method testRenamingIndexRootPage.

/**
 * Checking the correct renaming of the index root pages.
 *
 * @throws Exception If failed.
 */
@Test
public void testRenamingIndexRootPage() throws Exception {
    IgniteEx n = startGrid(0);
    IgniteCache<Integer, Person> cache = n.cache(DEFAULT_CACHE_NAME);
    populate(cache, 100);
    String idxName = "IDX0";
    createIdx(cache, idxName);
    SortedIndexDefinition idxDef = indexDefinition(index(n, cache, idxName));
    int segments = idxDef.segments();
    String oldTreeName = idxDef.treeName();
    assertExistIndexRoot(cache, oldTreeName, segments, true);
    String newTreeName = UUID.randomUUID().toString();
    // There will be no renaming.
    assertExistIndexRoot(cache, newTreeName, segments, false);
    assertTrue(renameIndexRoot(cache, newTreeName, newTreeName, segments).isEmpty());
    // Checking the validation of the new index name.
    String moreMaxLenName = Arrays.toString(new byte[MAX_IDX_NAME_LEN + 1]);
    assertThrows(log, () -> renameIndexRoot(cache, oldTreeName, moreMaxLenName, segments), Exception.class, null);
    assertEquals(segments, renameIndexRoot(cache, oldTreeName, newTreeName, segments).size());
    assertExistIndexRoot(cache, oldTreeName, segments, false);
    assertExistIndexRoot(cache, newTreeName, segments, true);
}
Also used : SortedIndexDefinition(org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition) IgniteEx(org.apache.ignite.internal.IgniteEx) Person(org.apache.ignite.client.Person) Test(org.junit.Test)

Example 10 with SortedIndexDefinition

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

the class RenameIndexTreeTest method testRenameFromTask.

/**
 * Checking the correctness of {@link DurableBackgroundCleanupIndexTreeTaskV2#findIndexRootPages}
 * and {@link DurableBackgroundCleanupIndexTreeTaskV2#renameIndexRootPages}.
 *
 * @throws Exception If failed.
 */
@Test
public void testRenameFromTask() throws Exception {
    IgniteEx n = startGrid(0);
    IgniteCache<Integer, Person> cache = n.cache(DEFAULT_CACHE_NAME);
    populate(cache, 100);
    String idxName = "IDX0";
    createIdx(cache, idxName);
    SortedIndexDefinition idxDef = indexDefinition(index(n, cache, idxName));
    GridCacheContext<Integer, Person> cctx = cacheContext(cache);
    String oldTreeName = idxDef.treeName();
    int segments = idxDef.segments();
    assertExistIndexRoot(cache, oldTreeName, segments, true);
    Map<Integer, RootPage> rootPages0 = findIndexRoots(cache, oldTreeName, segments);
    Map<Integer, RootPage> rootPages1 = findIndexRootPages(cctx.group(), cctx.name(), oldTreeName, segments);
    assertEqualsCollections(toPageIds(rootPages0), toPageIds(rootPages1));
    long currSegIdx = walMgr(n).currentSegment();
    String newTreeName = UUID.randomUUID().toString();
    renameIndexRootPages(cctx.group(), cctx.name(), oldTreeName, newTreeName, segments);
    assertExistIndexRoot(cache, oldTreeName, segments, false);
    assertExistIndexRoot(cache, newTreeName, segments, true);
    assertTrue(findIndexRootPages(cctx.group(), cctx.name(), oldTreeName, segments).isEmpty());
    rootPages0 = findIndexRoots(cache, newTreeName, segments);
    rootPages1 = findIndexRootPages(cctx.group(), cctx.name(), newTreeName, segments);
    assertEqualsCollections(toPageIds(rootPages0), toPageIds(rootPages1));
    WALPointer start = new WALPointer(currSegIdx, 0, 0);
    IgniteBiPredicate<WALRecord.RecordType, WALPointer> pred = (t, p) -> t == INDEX_ROOT_PAGE_RENAME_RECORD;
    try (WALIterator it = walMgr(n).replay(start, pred)) {
        List<WALRecord> records = stream(it.spliterator(), false).map(IgniteBiTuple::get2).collect(toList());
        assertEquals(1, records.size());
        IndexRenameRootPageRecord record = (IndexRenameRootPageRecord) records.get(0);
        assertEquals(cctx.cacheId(), record.cacheId());
        assertEquals(oldTreeName, record.oldTreeName());
        assertEquals(newTreeName, record.newTreeName());
        assertEquals(segments, record.segments());
    }
}
Also used : WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) INDEX_ROOT_PAGE_RENAME_RECORD(org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType.INDEX_ROOT_PAGE_RENAME_RECORD) Arrays(java.util.Arrays) Person(org.apache.ignite.client.Person) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) GridTestUtils.assertThrows(org.apache.ignite.testframework.GridTestUtils.assertThrows) HashMap(java.util.HashMap) IgniteEx(org.apache.ignite.internal.IgniteEx) DurableBackgroundCleanupIndexTreeTaskV2.findIndexRootPages(org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2.findIndexRootPages) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) ArrayList(java.util.ArrayList) GridTestUtils.cacheContext(org.apache.ignite.testframework.GridTestUtils.cacheContext) IndexRenameRootPageRecord(org.apache.ignite.internal.pagemem.wal.record.IndexRenameRootPageRecord) Map(java.util.Map) Collectors.toSet(java.util.stream.Collectors.toSet) DurableBackgroundCleanupIndexTreeTaskV2(org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2) RootPage(org.apache.ignite.internal.processors.cache.persistence.RootPage) SortedIndexDefinition(org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition) Collection(java.util.Collection) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) Set(java.util.Set) DurableBackgroundCleanupIndexTreeTaskV2.renameIndexRootPages(org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2.renameIndexRootPages) Test(org.junit.Test) UUID(java.util.UUID) IgniteCache(org.apache.ignite.IgniteCache) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) StreamSupport.stream(java.util.stream.StreamSupport.stream) CU(org.apache.ignite.internal.util.typedef.internal.CU) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) MAX_IDX_NAME_LEN(org.apache.ignite.internal.processors.cache.persistence.IndexStorageImpl.MAX_IDX_NAME_LEN) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) SortedIndexDefinition(org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) IgniteEx(org.apache.ignite.internal.IgniteEx) RootPage(org.apache.ignite.internal.processors.cache.persistence.RootPage) Person(org.apache.ignite.client.Person) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) IndexRenameRootPageRecord(org.apache.ignite.internal.pagemem.wal.record.IndexRenameRootPageRecord) Test(org.junit.Test)

Aggregations

SortedIndexDefinition (org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition)12 Person (org.apache.ignite.client.Person)7 IgniteEx (org.apache.ignite.internal.IgniteEx)7 Test (org.junit.Test)6 RootPage (org.apache.ignite.internal.processors.cache.persistence.RootPage)4 IndexRow (org.apache.ignite.internal.cache.query.index.sorted.IndexRow)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Index (org.apache.ignite.internal.cache.query.index.Index)2 DurableBackgroundCleanupIndexTreeTaskV2 (org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2)2 InlineIndexImpl (org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexImpl)2 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)2 IndexRenameRootPageRecord (org.apache.ignite.internal.pagemem.wal.record.IndexRenameRootPageRecord)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1 Set (java.util.Set)1 UUID (java.util.UUID)1