Search in sources :

Example 1 with EVT_WAL_SEGMENT_COMPACTED

use of org.apache.ignite.events.EventType.EVT_WAL_SEGMENT_COMPACTED in project ignite by apache.

the class WalCompactionAfterRestartTest method test.

/**
 * @throws Exception If failed.
 */
@Test
public void test() throws Exception {
    IgniteEx ig = startGrid(0);
    ig.cluster().active(true);
    doCachePuts(ig, 10_000);
    ig.cluster().active(false);
    stopGrid(0);
    IgniteEx ig0 = startGrid(0);
    ig0.cluster().active(true);
    List<IgniteBiTuple<Long, Long>> discrepancies = Collections.synchronizedList(new ArrayList<>());
    ig0.events().localListen(e -> {
        long evtSegIdx = ((WalSegmentCompactedEvent) e).getAbsWalSegmentIdx();
        long lastCompactedIdx = ig0.context().cache().context().wal().lastCompactedSegment();
        if (lastCompactedIdx < 0 || lastCompactedIdx > evtSegIdx)
            discrepancies.add(F.t(evtSegIdx, lastCompactedIdx));
        return true;
    }, EVT_WAL_SEGMENT_COMPACTED);
    doCachePuts(ig0, 5_000);
    stopGrid(0);
    if (!discrepancies.isEmpty()) {
        fail("Discrepancies (EVT_WAL_SEGMENT_COMPACTED index vs. lastCompactedSegment):" + System.lineSeparator() + discrepancies.stream().map(t -> String.format("%d <-> %d", t.get1(), t.get2())).collect(Collectors.joining(System.lineSeparator())));
    }
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) ArrayList(java.util.ArrayList) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) WALMode(org.apache.ignite.configuration.WALMode) F(org.apache.ignite.internal.util.typedef.F) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) IgniteCache(org.apache.ignite.IgniteCache) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) WalSegmentCompactedEvent(org.apache.ignite.events.WalSegmentCompactedEvent) Ignore(org.junit.Ignore) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) EVT_WAL_SEGMENT_COMPACTED(org.apache.ignite.events.EventType.EVT_WAL_SEGMENT_COMPACTED) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) IgniteEx(org.apache.ignite.internal.IgniteEx) WalSegmentCompactedEvent(org.apache.ignite.events.WalSegmentCompactedEvent) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Collectors (java.util.stream.Collectors)1 IgniteCache (org.apache.ignite.IgniteCache)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 CacheAtomicityMode (org.apache.ignite.cache.CacheAtomicityMode)1 CacheWriteSynchronizationMode (org.apache.ignite.cache.CacheWriteSynchronizationMode)1 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)1 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 WALMode (org.apache.ignite.configuration.WALMode)1 EVT_WAL_SEGMENT_COMPACTED (org.apache.ignite.events.EventType.EVT_WAL_SEGMENT_COMPACTED)1 WalSegmentCompactedEvent (org.apache.ignite.events.WalSegmentCompactedEvent)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1