use of org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2.renameIndexRootPages 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"));
}
use of org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2.renameIndexRootPages 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());
}
}
use of org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2.renameIndexRootPages 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());
}
}
use of org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2.renameIndexRootPages 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"));
}
Aggregations