Search in sources :

Example 86 with WALPointer

use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.

the class CheckpointHistory method calculateWalSegmentsCovered.

/**
 * Calculates indexes of WAL segments covered by last checkpoint.
 *
 * @return list of indexes or empty list if there are no checkpoints.
 */
private IgniteBiTuple<Long, Long> calculateWalSegmentsCovered() {
    IgniteBiTuple<Long, Long> tup = new IgniteBiTuple<>(-1L, -1L);
    Map.Entry<Long, CheckpointEntry> lastEntry = histMap.lastEntry();
    if (lastEntry == null)
        return tup;
    Map.Entry<Long, CheckpointEntry> previousEntry = histMap.lowerEntry(lastEntry.getKey());
    WALPointer lastWALPointer = lastEntry.getValue().checkpointMark();
    long lastIdx = lastWALPointer.index();
    long prevIdx = 0;
    if (previousEntry != null)
        prevIdx = previousEntry.getValue().checkpointMark().index();
    tup.set1(prevIdx);
    tup.set2(lastIdx - 1);
    return tup;
}
Also used : IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NavigableMap(java.util.NavigableMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)

Example 87 with WALPointer

use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.

the class CdcCacheVersionTest method testOrderIncrease.

/**
 */
@Test
public void testOrderIncrease() throws Exception {
    walProvider = (ctx) -> new FileWriteAheadLogManager(ctx) {

        /**
         */
        private long prevOrder = -1;

        @Override
        public WALPointer log(WALRecord rec) throws IgniteCheckedException {
            if (rec.type() != DATA_RECORD_V2)
                return super.log(rec);
            DataRecord dataRec = (DataRecord) rec;
            for (int i = 0; i < dataRec.entryCount(); i++) {
                assertEquals(CU.cacheId(DEFAULT_CACHE_NAME), dataRec.get(i).cacheId());
                assertEquals(KEY_TO_UPD, (int) dataRec.get(i).key().value(null, false));
                assertTrue(dataRec.get(i).writeVersion().order() > prevOrder);
                prevOrder = dataRec.get(i).writeVersion().order();
                walRecCheckedCntr.incrementAndGet();
            }
            return super.log(rec);
        }
    };
    IgniteConfiguration cfg = getConfiguration("ignite-0");
    IgniteEx ign = startGrid(cfg);
    ign.cluster().state(ACTIVE);
    IgniteCache<Integer, User> cache = ign.getOrCreateCache(new CacheConfiguration<Integer, User>(DEFAULT_CACHE_NAME).setAtomicityMode(atomicityMode).setCacheMode(cacheMode));
    walRecCheckedCntr.set(0);
    // Expect {@link CacheEntryVersion#order()} will monotically increase.
    for (int i = 0; i < KEYS_CNT; i++) cache.put(KEY_TO_UPD, createUser(i));
    assertTrue(waitForCondition(() -> walRecCheckedCntr.get() == KEYS_CNT, getTestTimeout()));
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) Test(org.junit.Test)

Example 88 with WALPointer

use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.

the class IgnitePdsRecoveryAfterFileCorruptionTest method generateWal.

/**
 * @param mem Mem.
 * @param storeMgr Store manager.
 * @param wal Wal.
 * @param cacheId Cache id.
 * @param pages Pages.
 */
private void generateWal(final PageMemoryImpl mem, final IgnitePageStoreManager storeMgr, final IgniteWriteAheadLogManager wal, final int cacheId, FullPageId[] pages) throws Exception {
    // Mark the start position.
    CheckpointRecord cpRec = new CheckpointRecord(null);
    WALPointer start = wal.log(cpRec);
    wal.flush(start, false);
    for (FullPageId fullId : pages) {
        long page = mem.acquirePage(fullId.groupId(), fullId.pageId());
        try {
            long pageAddr = mem.writeLock(fullId.groupId(), fullId.pageId(), page);
            PageIO.setPageId(pageAddr, fullId.pageId());
            try {
                for (int j = PageIO.COMMON_HEADER_END; j < mem.realPageSize(fullId.groupId()); j += 4) PageUtils.putInt(pageAddr, j, j + (int) fullId.pageId());
            } finally {
                mem.writeUnlock(fullId.groupId(), fullId.pageId(), page, null, true);
            }
        } finally {
            mem.releasePage(fullId.groupId(), fullId.pageId(), page);
        }
    }
    Collection<FullPageId> pageIds = mem.beginCheckpoint(new GridFinishedFuture());
    info("Acquired pages for checkpoint: " + pageIds.size());
    try {
        long begin = System.currentTimeMillis();
        long cp = 0;
        AtomicLong write = new AtomicLong();
        PageStoreWriter pageStoreWriter = (fullPageId, buf, tag) -> {
            int groupId = fullPageId.groupId();
            long pageId = fullPageId.pageId();
            for (int j = PageIO.COMMON_HEADER_END; j < mem.realPageSize(groupId); j += 4) assertEquals(j + (int) pageId, buf.getInt(j));
            buf.rewind();
            long writeStart = System.nanoTime();
            storeMgr.write(cacheId, pageId, buf, tag, true);
            long writeEnd = System.nanoTime();
            write.getAndAdd(writeEnd - writeStart);
        };
        ByteBuffer tmpBuf = ByteBuffer.allocate(mem.pageSize());
        tmpBuf.order(ByteOrder.nativeOrder());
        for (FullPageId fullId : pages) {
            if (pageIds.contains(fullId)) {
                long cpStart = System.nanoTime();
                mem.checkpointWritePage(fullId, tmpBuf, pageStoreWriter, null);
                long cpEnd = System.nanoTime();
                cp += cpEnd - cpStart;
            }
        }
        long syncStart = System.currentTimeMillis();
        storeMgr.sync(cacheId, 0);
        long end = System.currentTimeMillis();
        info("Written pages in " + (end - begin) + "ms, copy took " + (cp / 1_000_000) + "ms, " + "write took " + (write.get() / 1_000_000) + "ms, sync took " + (end - syncStart) + "ms");
    } finally {
        info("Finishing checkpoint...");
        mem.finishCheckpoint();
        info("Finished checkpoint");
    }
    wal.flush(wal.log(new CheckpointRecord(null)), false);
    for (FullPageId fullId : pages) {
        long page = mem.acquirePage(fullId.groupId(), fullId.pageId());
        try {
            assertFalse("Page has a temp heap copy after the last checkpoint: [cacheId=" + fullId.groupId() + ", pageId=" + fullId.pageId() + "]", mem.hasTempCopy(page));
            assertFalse("Page is dirty after the last checkpoint: [cacheId=" + fullId.groupId() + ", pageId=" + fullId.pageId() + "]", mem.isDirty(fullId.groupId(), fullId.pageId(), page));
        } finally {
            mem.releasePage(fullId.groupId(), fullId.pageId(), page);
        }
    }
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) GridTestUtils.waitForCondition(org.apache.ignite.testframework.GridTestUtils.waitForCondition) ClusterState(org.apache.ignite.cluster.ClusterState) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteEx(org.apache.ignite.internal.IgniteEx) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) CacheRebalanceMode(org.apache.ignite.cache.CacheRebalanceMode) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) ByteBuffer(java.nio.ByteBuffer) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) FileIO(org.apache.ignite.internal.processors.cache.persistence.file.FileIO) PageUtils(org.apache.ignite.internal.pagemem.PageUtils) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO) RolloverType(org.apache.ignite.internal.pagemem.wal.record.RolloverType) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) WALMode(org.apache.ignite.configuration.WALMode) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) PageIdAllocator(org.apache.ignite.internal.pagemem.PageIdAllocator) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IOException(java.io.IOException) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) Test(org.junit.Test) IgniteCache(org.apache.ignite.IgniteCache) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) PageMemoryImpl(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl) ByteOrder(java.nio.ByteOrder) AtomicLong(java.util.concurrent.atomic.AtomicLong) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgnitePageStoreManager(org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) PageIdUtils(org.apache.ignite.internal.pagemem.PageIdUtils) MvccFeatureChecker(org.apache.ignite.testframework.MvccFeatureChecker) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) AtomicLong(java.util.concurrent.atomic.AtomicLong) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) ByteBuffer(java.nio.ByteBuffer) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture)

Example 89 with WALPointer

use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.

the class LocalWalModeNoChangeDuringRebalanceOnNonNodeAssignTest method check.

/**
 * @throws Exception If failed.
 */
public void check() throws Exception {
    Ignite ig = startGridsMultiThreaded(NODES);
    int entries = 100_000;
    try (IgniteDataStreamer<Integer, Integer> st = ig.dataStreamer(DEFAULT_CACHE_NAME)) {
        st.allowOverwrite(true);
        for (int i = 0; i < entries; i++) st.addData(i, -i);
    }
    IgniteEx ig4 = startGrid(NODES);
    ig4.cluster().setBaselineTopology(ig4.context().discovery().topologyVersion());
    IgniteWalIteratorFactory iteratorFactory = new IgniteWalIteratorFactory(log);
    String name = ig4.name();
    try (WALIterator it = iteratorFactory.iterator(walPath(name), walArchivePath(name))) {
        while (it.hasNext()) {
            IgniteBiTuple<WALPointer, WALRecord> tup = it.next();
            WALRecord rec = tup.get2();
            if (rec.type() == METASTORE_DATA_RECORD) {
                MetastoreDataRecord metastoreDataRecord = (MetastoreDataRecord) rec;
                String key = metastoreDataRecord.key();
                if (key.startsWith("grp-wal-") && key.contains(valueOf(cacheId(DEFAULT_CACHE_NAME))) && metastoreDataRecord.value() != null)
                    fail("WAL was disabled but should not.");
            }
        }
    }
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) MetastoreDataRecord(org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)

Example 90 with WALPointer

use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.

the class ReleaseSegmentOnHistoricalRebalanceTest method testReleaseDuringRebalanceIterator.

/**
 * Checks that if release the segment during {@link IgniteCacheOffheapManagerImpl#rebalanceIterator},
 * there will be no errors and the rebalance will be completed.
 *
 * @throws Exception If failed.
 */
@Test
public void testReleaseDuringRebalanceIterator() throws Exception {
    checkHistoricalRebalance(n -> {
        IgniteInternalCache<?, ?> cachex = n.cachex(DEFAULT_CACHE_NAME);
        GridCacheOffheapManager spy = spy(offheapManager(cachex));
        doAnswer(m -> {
            WALPointer reserved = dbMgr(n).latestWalPointerReservedForPreloading();
            assertNotNull(reserved);
            Object o = m.callRealMethod();
            release(n, reserved);
            assertTrue(segmentAware(n).minReserveIndex(Long.MAX_VALUE));
            return o;
        }).when(spy).rebalanceIterator(any(), any());
        offheapManager(cachex, spy);
    });
}
Also used : GridCacheOffheapManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) Test(org.junit.Test)

Aggregations

WALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)122 WALRecord (org.apache.ignite.internal.pagemem.wal.record.WALRecord)44 Test (org.junit.Test)41 IgniteEx (org.apache.ignite.internal.IgniteEx)38 WALIterator (org.apache.ignite.internal.pagemem.wal.WALIterator)36 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)30 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)27 CheckpointRecord (org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord)24 IgniteWriteAheadLogManager (org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager)23 DataRecord (org.apache.ignite.internal.pagemem.wal.record.DataRecord)23 ArrayList (java.util.ArrayList)20 IgniteWalIteratorFactory (org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory)20 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)19 DataEntry (org.apache.ignite.internal.pagemem.wal.record.DataEntry)19 PageSnapshot (org.apache.ignite.internal.pagemem.wal.record.PageSnapshot)19 File (java.io.File)18 T2 (org.apache.ignite.internal.util.typedef.T2)16 ByteBuffer (java.nio.ByteBuffer)15 UUID (java.util.UUID)15 IOException (java.io.IOException)14