Search in sources :

Example 1 with CheckpointHistory

use of org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistory in project ignite by apache.

the class ReleaseSegmentOnHistoricalRebalanceTest method testReleaseBeforeRebalanceIterator.

/**
 * Checks that if release the segment before {@link IgniteCacheOffheapManagerImpl#rebalanceIterator},
 * there will be no errors and the rebalance will be completed.
 *
 * @throws Exception If failed.
 */
@Test
public void testReleaseBeforeRebalanceIterator() throws Exception {
    checkHistoricalRebalance(n -> {
        IgniteInternalCache<?, ?> cachex = n.cachex(DEFAULT_CACHE_NAME);
        GridCacheOffheapManager spy = spy(offheapManager(cachex));
        doAnswer(m -> {
            CheckpointHistory cpHist = dbMgr(n).checkpointHistory();
            for (Long cp : cpHist.checkpoints()) release(n, entry(cpHist, cp).checkpointMark());
            return m.callRealMethod();
        }).when(spy).rebalanceIterator(any(), any());
        offheapManager(cachex, spy);
    });
}
Also used : GridCacheOffheapManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager) CheckpointHistory(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistory) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Test(org.junit.Test)

Example 2 with CheckpointHistory

use of org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistory in project ignite by apache.

the class ReleaseSegmentOnHistoricalRebalanceTest method testReleaseSegmentAfterSearchAndReserveCheckpoints.

/**
 * Checks that if release the segment after {@link CheckpointHistory#searchAndReserveCheckpoints},
 * there will be no errors and the rebalance will be completed.
 *
 * @throws Exception If failed.
 */
@Test
public void testReleaseSegmentAfterSearchAndReserveCheckpoints() throws Exception {
    checkHistoricalRebalance(n -> {
        CheckpointHistory spy = spy(dbMgr(n).checkpointHistory());
        when(spy.searchAndReserveCheckpoints(any())).thenAnswer(m -> {
            CheckpointHistoryResult res = (CheckpointHistoryResult) m.callRealMethod();
            WALPointer reserved = res.reservedCheckpointMark();
            assertNotNull(reserved);
            release(n, reserved);
            return res;
        });
        checkpointHistory(n, spy);
    });
}
Also used : CheckpointHistoryResult(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistoryResult) CheckpointHistory(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistory) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) Test(org.junit.Test)

Example 3 with CheckpointHistory

use of org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistory in project ignite by apache.

the class LocalWalModeChangeDuringRebalancingSelfTest method doTestSimple.

/**
 * @throws Exception If failed.
 */
private void doTestSimple() throws Exception {
    Ignite ignite = startGrids(3);
    ignite.cluster().baselineAutoAdjustEnabled(false);
    ignite.cluster().state(ACTIVE);
    IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
    IgniteCache<Integer, Integer> cache2 = ignite.cache(REPL_CACHE);
    int keysCnt = getKeysCount();
    for (int k = 0; k < keysCnt; k++) {
        cache.put(k, k);
        // Empty cache causes skipped checkpoint.
        cache2.put(k, k);
    }
    IgniteEx newIgnite = startGrid(3);
    final CheckpointHistory cpHist = ((GridCacheDatabaseSharedManager) newIgnite.context().cache().context().database()).checkpointHistory();
    waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return !cpHist.checkpoints().isEmpty();
        }
    }, 10_000);
    // To ensure timestamp granularity.
    U.sleep(10);
    long newIgniteStartedTimestamp = System.currentTimeMillis();
    newIgnite.cluster().setBaselineTopology(4);
    awaitExchange(newIgnite);
    CacheGroupContext grpCtx = newIgnite.cachex(DEFAULT_CACHE_NAME).context().group();
    assertEquals(!disableWalDuringRebalancing, grpCtx.walEnabled());
    // To ensure timestamp granularity.
    U.sleep(10);
    long rebalanceStartedTimestamp = System.currentTimeMillis();
    for (Ignite g : G.allGrids()) g.cache(DEFAULT_CACHE_NAME).rebalance();
    awaitPartitionMapExchange();
    assertTrue(grpCtx.walEnabled());
    // To ensure timestamp granularity.
    U.sleep(10);
    long rebalanceFinishedTimestamp = System.currentTimeMillis();
    for (Integer k = 0; k < keysCnt; k++) assertEquals("k=" + k, k, cache.get(k));
    int checkpointsBeforeNodeStarted = 0;
    int checkpointsBeforeRebalance = 0;
    int checkpointsAfterRebalance = 0;
    for (Long timestamp : cpHist.checkpoints()) {
        if (timestamp < newIgniteStartedTimestamp)
            checkpointsBeforeNodeStarted++;
        else if (timestamp >= newIgniteStartedTimestamp && timestamp < rebalanceStartedTimestamp)
            checkpointsBeforeRebalance++;
        else if (timestamp >= rebalanceStartedTimestamp && timestamp <= rebalanceFinishedTimestamp)
            checkpointsAfterRebalance++;
    }
    // checkpoint on start
    assertEquals(1, checkpointsBeforeNodeStarted);
    assertEquals(0, checkpointsBeforeRebalance);
    // Expecting a checkpoint for each group.
    assertEquals(disableWalDuringRebalancing ? newIgnite.context().cache().cacheGroups().size() : 0, // checkpoint if WAL was re-activated
    checkpointsAfterRebalance);
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) CheckpointHistory(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistory) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext)

Example 4 with CheckpointHistory

use of org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistory in project ignite by apache.

the class LocalWalModeChangeDuringRebalancingSelfTest method testWalDisabledDuringRebalancingWithPendingTxTracker.

/**
 * @throws Exception If failed.
 */
@Test
public void testWalDisabledDuringRebalancingWithPendingTxTracker() throws Exception {
    enablePendingTxTracker = true;
    dfltCacheBackupCnt = 2;
    Ignite ignite = startGrids(3);
    ignite.cluster().baselineAutoAdjustEnabled(false);
    ignite.cluster().state(ACTIVE);
    ignite.cluster().setBaselineTopology(3);
    IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
    stopGrid(2);
    awaitExchange((IgniteEx) ignite);
    // Ensure each partition has received an update.
    for (int k = 0; k < RendezvousAffinityFunction.DFLT_PARTITION_COUNT; k++) cache.put(k, k);
    IgniteEx newIgnite = startGrid(2);
    awaitExchange(newIgnite);
    CacheGroupContext grpCtx = newIgnite.cachex(DEFAULT_CACHE_NAME).context().group();
    assertFalse(grpCtx.walEnabled());
    long rebalanceStartedTs = System.currentTimeMillis();
    for (Ignite g : G.allGrids()) g.cache(DEFAULT_CACHE_NAME).rebalance();
    awaitPartitionMapExchange();
    assertTrue(grpCtx.walEnabled());
    long rebalanceFinishedTs = System.currentTimeMillis();
    CheckpointHistory cpHist = ((GridCacheDatabaseSharedManager) newIgnite.context().cache().context().database()).checkpointHistory();
    assertNotNull(cpHist);
    // Ensure there was a checkpoint on WAL re-activation.
    assertEquals(1, cpHist.checkpoints().stream().filter(ts -> rebalanceStartedTs <= ts && ts <= rebalanceFinishedTs).count());
}
Also used : CheckpointHistory(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistory) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with CheckpointHistory

use of org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistory in project ignite by apache.

the class WalDeletionArchiveAbstractTest method testCheckpointHistoryRemovingByTruncate.

/**
 * Test for check deprecated removing checkpoint by deprecated walHistorySize parameter
 *
 * @deprecated Test old removing process depends on WalHistorySize.
 */
@Test
public void testCheckpointHistoryRemovingByTruncate() throws Exception {
    Ignite ignite = startGrid(dbCfg -> dbCfg.setMaxWalArchiveSize(2 * 1024 * 1024));
    GridCacheDatabaseSharedManager dbMgr = gridDatabase(ignite);
    IgniteCache<Integer, Object> cache = ignite.getOrCreateCache(cacheConfiguration());
    CheckpointHistory hist = dbMgr.checkpointHistory();
    assertNotNull(hist);
    int startHistSize = hist.checkpoints().size();
    int checkpointCnt = 10;
    for (int i = 0; i < checkpointCnt; i++) {
        cache.put(i, i);
        // and: wait for checkpoint finished
        forceCheckpoint();
        // Check that the history is growing.
        assertEquals(startHistSize + (i + 1), hist.checkpoints().size());
    }
    // Ensure rollover and wal archive cleaning.
    for (int i = 0; i < 6; i++) cache.put(i, new byte[ignite.configuration().getDataStorageConfiguration().getWalSegmentSize() / 2]);
    FileWriteAheadLogManager wal = wal(ignite);
    assertTrue(waitForCondition(() -> wal.lastTruncatedSegment() >= 0, 10_000));
    assertTrue(hist.checkpoints().size() < checkpointCnt + startHistSize);
    File[] cpFiles = dbMgr.checkpointDirectory().listFiles();
    // starts & ends + node_start
    assertTrue(cpFiles.length <= (checkpointCnt * 2 + 1));
}
Also used : GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) CheckpointHistory(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistory) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) Ignite(org.apache.ignite.Ignite) File(java.io.File) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

CheckpointHistory (org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistory)8 Test (org.junit.Test)6 Ignite (org.apache.ignite.Ignite)5 IgniteEx (org.apache.ignite.internal.IgniteEx)4 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)4 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)4 File (java.io.File)3 FileWriteAheadLogManager (org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager)3 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2 Consumer (java.util.function.Consumer)2 Stream (java.util.stream.Stream)2 IgniteCache (org.apache.ignite.IgniteCache)2 IGNITE_CHECKPOINT_TRIGGER_ARCHIVE_SIZE_PERCENTAGE (org.apache.ignite.IgniteSystemProperties.IGNITE_CHECKPOINT_TRIGGER_ARCHIVE_SIZE_PERCENTAGE)2 IGNITE_PDS_MAX_CHECKPOINT_MEMORY_HISTORY_SIZE (org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_MAX_CHECKPOINT_MEMORY_HISTORY_SIZE)2 CacheAtomicityMode (org.apache.ignite.cache.CacheAtomicityMode)2 ClusterState (org.apache.ignite.cluster.ClusterState)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)2