Search in sources :

Example 6 with IndexRenameRootPageRecord

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();
    }
}
Also used : IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) IndexRenameRootPageRecord(org.apache.ignite.internal.pagemem.wal.record.IndexRenameRootPageRecord)

Example 7 with IndexRenameRootPageRecord

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());
    }
}
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

IndexRenameRootPageRecord (org.apache.ignite.internal.pagemem.wal.record.IndexRenameRootPageRecord)7 CheckpointRecord (org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord)4 DataRecord (org.apache.ignite.internal.pagemem.wal.record.DataRecord)4 MetastoreDataRecord (org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord)4 WALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 UUID (java.util.UUID)3 MasterKeyChangeRecordV2 (org.apache.ignite.internal.pagemem.wal.record.MasterKeyChangeRecordV2)3 PageSnapshot (org.apache.ignite.internal.pagemem.wal.record.PageSnapshot)3 PartitionClearingStartRecord (org.apache.ignite.internal.pagemem.wal.record.PartitionClearingStartRecord)3 ReencryptionStartRecord (org.apache.ignite.internal.pagemem.wal.record.ReencryptionStartRecord)3 WALRecord (org.apache.ignite.internal.pagemem.wal.record.WALRecord)3 DataPageInsertFragmentRecord (org.apache.ignite.internal.pagemem.wal.record.delta.DataPageInsertFragmentRecord)3 DataPageInsertRecord (org.apache.ignite.internal.pagemem.wal.record.delta.DataPageInsertRecord)3 DataPageUpdateRecord (org.apache.ignite.internal.pagemem.wal.record.delta.DataPageUpdateRecord)3 MetaPageUpdateIndexDataRecord (org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdateIndexDataRecord)3 MetaPageUpdatePartitionDataRecord (org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdatePartitionDataRecord)3 PartitionMetaStateRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PartitionMetaStateRecord)3 GroupKeyEncrypted (org.apache.ignite.internal.managers.encryption.GroupKeyEncrypted)2