use of org.apache.ignite.internal.pagemem.wal.record.IndexRenameRootPageRecord in project ignite by apache.
the class DurableBackgroundCleanupIndexTreeTaskV2 method renameIndexRootPages.
/**
* Renaming the root index pages.
*
* @param grpCtx Cache group context.
* @param cacheName Cache name.
* @param oldTreeName Old name of underlying index tree name.
* @param newTreeName New name of underlying index tree name.
* @param segments Number of segments.
* @throws IgniteCheckedException If failed.
*/
public static void renameIndexRootPages(CacheGroupContext grpCtx, String cacheName, String oldTreeName, String newTreeName, int segments) throws IgniteCheckedException {
IgniteWriteAheadLogManager wal = grpCtx.shared().wal();
int cacheId = CU.cacheId(cacheName);
if (wal != null)
wal.log(new IndexRenameRootPageRecord(cacheId, oldTreeName, newTreeName, segments));
grpCtx.shared().database().checkpointReadLock();
try {
for (int i = 0; i < segments; i++) grpCtx.offheap().renameRootPageForIndex(cacheId, oldTreeName, newTreeName, i);
} finally {
grpCtx.shared().database().checkpointReadUnlock();
}
}
use of org.apache.ignite.internal.pagemem.wal.record.IndexRenameRootPageRecord 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