Search in sources :

Example 1 with DurableBackgroundCleanupIndexTreeTaskV2.findIndexRootPages

use of org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2.findIndexRootPages 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 DurableBackgroundCleanupIndexTreeTaskV2.findIndexRootPages

use of org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2.findIndexRootPages 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)

Example 3 with DurableBackgroundCleanupIndexTreeTaskV2.findIndexRootPages

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

the class DropIndexTest method testTaskNotExecuteIfAbsentCacheGroupOrRootPages.

/**
 * Check that the {@link DurableBackgroundCleanupIndexTreeTaskV2} will not
 * be executed if the cache group and root pages are not found.
 *
 * @throws Exception If failed.
 */
@Test
public void testTaskNotExecuteIfAbsentCacheGroupOrRootPages() throws Exception {
    IgniteEx n = startGrid(0);
    String fake = UUID.randomUUID().toString();
    GridCacheContext<Integer, Person> cctx = cacheContext(n.cache(DEFAULT_CACHE_NAME));
    List<DurableBackgroundCleanupIndexTreeTaskV2> tasks = F.asList(new DurableBackgroundCleanupIndexTreeTaskV2(fake, fake, fake, fake, fake, 10, null), new DurableBackgroundCleanupIndexTreeTaskV2(cctx.group().name(), cctx.name(), fake, fake, fake, 10, null));
    for (DurableBackgroundCleanupIndexTreeTaskV2 task : tasks) {
        DurableBackgroundTaskResult<Long> res = task.executeAsync(n.context()).get(0);
        assertTrue(res.completed());
        assertNull(res.error());
        assertNull(res.result());
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) Person(org.apache.ignite.client.Person) DurableBackgroundCleanupIndexTreeTaskV2(org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2) Test(org.junit.Test)

Example 4 with DurableBackgroundCleanupIndexTreeTaskV2.findIndexRootPages

use of org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2.findIndexRootPages 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

DurableBackgroundCleanupIndexTreeTaskV2 (org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2)4 Test (org.junit.Test)4 Person (org.apache.ignite.client.Person)3 IgniteEx (org.apache.ignite.internal.IgniteEx)3 SortedIndexDefinition (org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition)2 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)2 RootPage (org.apache.ignite.internal.processors.cache.persistence.RootPage)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 UUID (java.util.UUID)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Collectors.toList (java.util.stream.Collectors.toList)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 StreamSupport.stream (java.util.stream.StreamSupport.stream)1 IgniteCache (org.apache.ignite.IgniteCache)1