Search in sources :

Example 1 with WalSegmentArchivedEvent

use of org.apache.ignite.events.WalSegmentArchivedEvent in project ignite by apache.

the class IgniteWalReaderTest method testArchiveIncompleteSegmentAfterInactivity.

/**
 * Tests time out based WAL segment archiving.
 *
 * @throws Exception if failure occurs.
 */
public void testArchiveIncompleteSegmentAfterInactivity() throws Exception {
    final AtomicBoolean waitingForEvt = new AtomicBoolean();
    final CountDownLatch archiveSegmentForInactivity = new CountDownLatch(1);
    archiveIncompleteSegmentAfterInactivityMs = 1000;
    final Ignite ignite = startGrid("node0");
    ignite.active(true);
    final IgniteEvents evts = ignite.events();
    evts.localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event e) {
            WalSegmentArchivedEvent archComplEvt = (WalSegmentArchivedEvent) e;
            long idx = archComplEvt.getAbsWalSegmentIdx();
            log.info("Finished archive for segment [" + idx + ", " + archComplEvt.getArchiveFile() + "]: [" + e + "]");
            if (waitingForEvt.get())
                archiveSegmentForInactivity.countDown();
            return true;
        }
    }, EVT_WAL_SEGMENT_ARCHIVED);
    putDummyRecords(ignite, 100);
    // flag for skipping regular log() and rollOver()
    waitingForEvt.set(true);
    log.info("Wait for archiving segment for inactive grid started");
    boolean recordedAfterSleep = archiveSegmentForInactivity.await(archiveIncompleteSegmentAfterInactivityMs + 1001, TimeUnit.MILLISECONDS);
    stopGrid("node0");
    assertTrue(recordedAfterSleep);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteEvents(org.apache.ignite.IgniteEvents) Event(org.apache.ignite.events.Event) WalSegmentArchivedEvent(org.apache.ignite.events.WalSegmentArchivedEvent) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) WalSegmentArchivedEvent(org.apache.ignite.events.WalSegmentArchivedEvent)

Example 2 with WalSegmentArchivedEvent

use of org.apache.ignite.events.WalSegmentArchivedEvent in project ignite by apache.

the class IgniteWalReaderTest method testArchiveCompletedEventFired.

/**
 * Tests archive completed event is fired.
 *
 * @throws Exception if failed.
 */
public void testArchiveCompletedEventFired() throws Exception {
    final AtomicBoolean evtRecorded = new AtomicBoolean();
    final Ignite ignite = startGrid("node0");
    ignite.active(true);
    final IgniteEvents evts = ignite.events();
    if (!evts.isEnabled(EVT_WAL_SEGMENT_ARCHIVED))
        assertTrue("nothing to test", false);
    evts.localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event e) {
            WalSegmentArchivedEvent archComplEvt = (WalSegmentArchivedEvent) e;
            long idx = archComplEvt.getAbsWalSegmentIdx();
            log.info("Finished archive for segment [" + idx + ", " + archComplEvt.getArchiveFile() + "]: [" + e + "]");
            evtRecorded.set(true);
            return true;
        }
    }, EVT_WAL_SEGMENT_ARCHIVED);
    putDummyRecords(ignite, 500);
    stopGrid("node0");
    assertTrue(evtRecorded.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteEvents(org.apache.ignite.IgniteEvents) Event(org.apache.ignite.events.Event) WalSegmentArchivedEvent(org.apache.ignite.events.WalSegmentArchivedEvent) Ignite(org.apache.ignite.Ignite) WalSegmentArchivedEvent(org.apache.ignite.events.WalSegmentArchivedEvent)

Example 3 with WalSegmentArchivedEvent

use of org.apache.ignite.events.WalSegmentArchivedEvent in project ignite by apache.

the class IgniteWalReaderTest method testFillWalForExactSegmentsCount.

/**
 * Tests archive completed event is fired.
 *
 * @throws Exception if failed.
 */
public void testFillWalForExactSegmentsCount() throws Exception {
    customWalMode = WALMode.FSYNC;
    final CountDownLatch reqSegments = new CountDownLatch(15);
    final Ignite ignite = startGrid("node0");
    ignite.active(true);
    final IgniteEvents evts = ignite.events();
    if (!evts.isEnabled(EVT_WAL_SEGMENT_ARCHIVED))
        assertTrue("nothing to test", false);
    evts.localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event e) {
            WalSegmentArchivedEvent archComplEvt = (WalSegmentArchivedEvent) e;
            long idx = archComplEvt.getAbsWalSegmentIdx();
            log.info("Finished archive for segment [" + idx + ", " + archComplEvt.getArchiveFile() + "]: [" + e + "]");
            reqSegments.countDown();
            return true;
        }
    }, EVT_WAL_SEGMENT_ARCHIVED);
    int totalEntries = 0;
    while (reqSegments.getCount() > 0) {
        final int write = 500;
        putAllDummyRecords(ignite, write);
        totalEntries += write;
        Assert.assertTrue("Too much entries generated, but segments was not become available", totalEntries < 10000);
    }
    final String subfolderName = genDbSubfolderName(ignite, 0);
    stopGrid("node0");
    final String workDir = U.defaultWorkDirectory();
    final IgniteWalIteratorFactory factory = createWalIteratorFactory(workDir, subfolderName);
    scanIterateAndCount(factory, workDir, subfolderName, totalEntries, 0, null, null);
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) IgniteEvents(org.apache.ignite.IgniteEvents) Event(org.apache.ignite.events.Event) WalSegmentArchivedEvent(org.apache.ignite.events.WalSegmentArchivedEvent) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) WalSegmentArchivedEvent(org.apache.ignite.events.WalSegmentArchivedEvent)

Aggregations

Ignite (org.apache.ignite.Ignite)3 IgniteEvents (org.apache.ignite.IgniteEvents)3 Event (org.apache.ignite.events.Event)3 WalSegmentArchivedEvent (org.apache.ignite.events.WalSegmentArchivedEvent)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IgniteWalIteratorFactory (org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory)1