use of org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType.INDEX_ROOT_PAGE_RENAME_RECORD 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());
}
}
Aggregations