Search in sources :

Example 1 with IdleReaderException

use of org.apache.distributedlog.exceptions.IdleReaderException in project bookkeeper by apache.

the class BKAsyncLogReader method markReaderAsIdle.

private void markReaderAsIdle() {
    idleReaderError.inc();
    IdleReaderException ire = new IdleReaderException("Reader on stream " + readHandler.getFullyQualifiedName() + " is idle for " + idleErrorThresholdMillis + " ms");
    setLastException(ire);
    // cancel all pending reads directly rather than notifying on error
    // because idle reader could happen on idle read requests that usually means something wrong
    // in scheduling reads
    cancelAllPendingReads(ire);
}
Also used : IdleReaderException(org.apache.distributedlog.exceptions.IdleReaderException)

Example 2 with IdleReaderException

use of org.apache.distributedlog.exceptions.IdleReaderException in project bookkeeper by apache.

the class TestAsyncReaderWriter method testAsyncReadMissingLogSegmentsNotification.

@DistributedLogAnnotations.FlakyTest
@Test(timeout = 60000)
public void testAsyncReadMissingLogSegmentsNotification() throws Exception {
    String name = "distrlog-async-reader-missing-zk-notification";
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.loadConf(testConf);
    confLocal.setOutputBufferSize(0);
    confLocal.setImmediateFlushEnabled(true);
    confLocal.setReadAheadBatchSize(1);
    confLocal.setReadAheadMaxRecords(1);
    confLocal.setReadLACLongPollTimeout(49);
    confLocal.setReaderIdleWarnThresholdMillis(100);
    confLocal.setReaderIdleErrorThresholdMillis(20000);
    final DistributedLogManager dlm = createNewDLM(confLocal, name);
    final Thread currentThread = Thread.currentThread();
    final int segmentSize = 10;
    final int numSegments = 3;
    final CountDownLatch latch = new CountDownLatch(1);
    final CountDownLatch readLatch = new CountDownLatch(1);
    final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
    executor.schedule(new Runnable() {

        @Override
        public void run() {
            try {
                int txid = 1;
                for (long i = 0; i < numSegments; i++) {
                    BKSyncLogWriter writer = (BKSyncLogWriter) dlm.startLogSegmentNonPartitioned();
                    for (long j = 1; j <= segmentSize; j++) {
                        writer.write(DLMTestUtil.getLargeLogRecordInstance(txid++));
                        if ((i == 0) && (j == 1)) {
                            latch.countDown();
                        } else {
                            // wait for reader to start
                            readLatch.await();
                        }
                    }
                    writer.closeAndComplete();
                    Thread.sleep(100);
                }
            } catch (Exception exc) {
                if (!executor.isShutdown()) {
                    currentThread.interrupt();
                }
            }
        }
    }, 0, TimeUnit.MILLISECONDS);
    latch.await();
    BKAsyncLogReader reader = (BKAsyncLogReader) dlm.getAsyncLogReader(DLSN.InitialDLSN);
    reader.disableReadAheadLogSegmentsNotification();
    boolean exceptionEncountered = false;
    int recordCount = 0;
    try {
        while (true) {
            CompletableFuture<LogRecordWithDLSN> record = reader.readNext();
            Utils.ioResult(record);
            if (recordCount == 0) {
                readLatch.countDown();
            }
            recordCount++;
            if (recordCount >= segmentSize * numSegments) {
                break;
            }
        }
    } catch (IdleReaderException exc) {
        exceptionEncountered = true;
    }
    assertTrue(!exceptionEncountered);
    Assert.assertEquals(recordCount, segmentSize * numSegments);
    assertTrue(!currentThread.isInterrupted());
    Utils.close(reader);
    executor.shutdown();
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) CountDownLatch(java.util.concurrent.CountDownLatch) IdleReaderException(org.apache.distributedlog.exceptions.IdleReaderException) OverCapacityException(org.apache.distributedlog.exceptions.OverCapacityException) ReadCancelledException(org.apache.distributedlog.exceptions.ReadCancelledException) DLIllegalStateException(org.apache.distributedlog.exceptions.DLIllegalStateException) WriteException(org.apache.distributedlog.exceptions.WriteException) LockingException(org.apache.distributedlog.exceptions.LockingException) BKTransmitException(org.apache.distributedlog.exceptions.BKTransmitException) EndOfStreamException(org.apache.distributedlog.exceptions.EndOfStreamException) IOException(java.io.IOException) LogRecordTooLongException(org.apache.distributedlog.exceptions.LogRecordTooLongException) DynamicDistributedLogConfiguration(org.apache.distributedlog.config.DynamicDistributedLogConfiguration) IdleReaderException(org.apache.distributedlog.exceptions.IdleReaderException) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) Test(org.junit.Test)

Example 3 with IdleReaderException

use of org.apache.distributedlog.exceptions.IdleReaderException in project bookkeeper by apache.

the class TestAsyncReaderWriter method testIdleReaderExceptionWhenKeepAliveIsDisabled.

@Test(timeout = 60000)
public void testIdleReaderExceptionWhenKeepAliveIsDisabled() throws Exception {
    String name = runtime.getMethodName();
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.addConfiguration(testConf);
    confLocal.setOutputBufferSize(0);
    confLocal.setImmediateFlushEnabled(false);
    confLocal.setPeriodicFlushFrequencyMilliSeconds(0);
    confLocal.setPeriodicKeepAliveMilliSeconds(0);
    confLocal.setReadLACLongPollTimeout(9);
    confLocal.setReaderIdleWarnThresholdMillis(20);
    confLocal.setReaderIdleErrorThresholdMillis(40);
    URI uri = createDLMURI("/" + name);
    ensureURICreated(uri);
    DistributedLogManager dlm = createNewDLM(confLocal, name);
    BKAsyncLogWriter writer = (BKAsyncLogWriter) Utils.ioResult(dlm.openAsyncLogWriter());
    writer.write(DLMTestUtil.getLogRecordInstance(1L));
    AsyncLogReader reader = Utils.ioResult(dlm.openAsyncLogReader(DLSN.InitialDLSN));
    try {
        Utils.ioResult(reader.readNext());
        fail("Should fail when stream is idle");
    } catch (IdleReaderException ire) {
    // expected
    }
    Utils.close(reader);
    writer.close();
    dlm.close();
}
Also used : DynamicDistributedLogConfiguration(org.apache.distributedlog.config.DynamicDistributedLogConfiguration) IdleReaderException(org.apache.distributedlog.exceptions.IdleReaderException) AsyncLogReader(org.apache.distributedlog.api.AsyncLogReader) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) URI(java.net.URI) Test(org.junit.Test)

Example 4 with IdleReaderException

use of org.apache.distributedlog.exceptions.IdleReaderException in project bookkeeper by apache.

the class TestNonBlockingReads method testNonBlockingReadAheadStall.

@Test(timeout = 60000)
public void testNonBlockingReadAheadStall() throws Exception {
    String name = "distrlog-non-blocking-reader-stall";
    final DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.loadConf(conf);
    confLocal.setReadAheadBatchSize(1);
    confLocal.setReadAheadMaxRecords(3);
    confLocal.setReadLACLongPollTimeout(249);
    confLocal.setReaderIdleWarnThresholdMillis(500);
    confLocal.setReaderIdleErrorThresholdMillis(30000);
    final DistributedLogManager dlm = createNewDLM(confLocal, name);
    ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
    ScheduledFuture writerClosedFuture = null;
    try {
        final Thread currentThread = Thread.currentThread();
        writerClosedFuture = executor.schedule(new Runnable() {

            @Override
            public void run() {
                try {
                    writeRecordsForNonBlockingReads(confLocal, dlm, false, 3);
                } catch (Exception exc) {
                    currentThread.interrupt();
                }
            }
        }, 10, TimeUnit.MILLISECONDS);
        boolean exceptionEncountered = false;
        try {
            readNonBlocking(dlm, false, 3, false);
        } catch (IdleReaderException exc) {
            LOG.info("Exception encountered", exc);
            exceptionEncountered = true;
        }
        assertFalse(exceptionEncountered);
        assertFalse(currentThread.isInterrupted());
    } finally {
        if (writerClosedFuture != null) {
            // ensure writer.closeAndComplete is done before we close dlm
            writerClosedFuture.get();
        }
        executor.shutdown();
        dlm.close();
    }
}
Also used : IdleReaderException(org.apache.distributedlog.exceptions.IdleReaderException) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ScheduledFuture(java.util.concurrent.ScheduledFuture) IdleReaderException(org.apache.distributedlog.exceptions.IdleReaderException) Test(org.junit.Test)

Example 5 with IdleReaderException

use of org.apache.distributedlog.exceptions.IdleReaderException in project bookkeeper by apache.

the class TestNonBlockingReads method testNonBlockingReadIdleError.

@Test(timeout = 100000)
public void testNonBlockingReadIdleError() throws Exception {
    String name = "distrlog-non-blocking-reader-error";
    final DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.loadConf(conf);
    confLocal.setReadAheadBatchSize(1);
    confLocal.setReadAheadMaxRecords(1);
    confLocal.setReadLACLongPollTimeout(24);
    confLocal.setReaderIdleWarnThresholdMillis(50);
    confLocal.setReaderIdleErrorThresholdMillis(100);
    final DistributedLogManager dlm = createNewDLM(confLocal, name);
    ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
    ScheduledFuture writerClosedFuture = null;
    try {
        final Thread currentThread = Thread.currentThread();
        writerClosedFuture = executor.schedule(new Runnable() {

            @Override
            public void run() {
                try {
                    writeRecordsForNonBlockingReads(confLocal, dlm, false);
                } catch (Exception exc) {
                    currentThread.interrupt();
                }
            }
        }, 100, TimeUnit.MILLISECONDS);
        boolean exceptionEncountered = false;
        try {
            readNonBlocking(dlm, false, DEFAULT_SEGMENT_SIZE, true);
        } catch (IdleReaderException exc) {
            exceptionEncountered = true;
        }
        assertTrue(exceptionEncountered);
        assertFalse(currentThread.isInterrupted());
    } finally {
        if (writerClosedFuture != null) {
            // ensure writer.closeAndComplete is done before we close dlm
            writerClosedFuture.get();
        }
        executor.shutdown();
        dlm.close();
    }
}
Also used : IdleReaderException(org.apache.distributedlog.exceptions.IdleReaderException) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ScheduledFuture(java.util.concurrent.ScheduledFuture) IdleReaderException(org.apache.distributedlog.exceptions.IdleReaderException) Test(org.junit.Test)

Aggregations

IdleReaderException (org.apache.distributedlog.exceptions.IdleReaderException)7 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)5 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)4 Test (org.junit.Test)4 DynamicDistributedLogConfiguration (org.apache.distributedlog.config.DynamicDistributedLogConfiguration)3 IOException (java.io.IOException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ScheduledFuture (java.util.concurrent.ScheduledFuture)2 BKTransmitException (org.apache.distributedlog.exceptions.BKTransmitException)2 DLIllegalStateException (org.apache.distributedlog.exceptions.DLIllegalStateException)2 EndOfStreamException (org.apache.distributedlog.exceptions.EndOfStreamException)2 LockingException (org.apache.distributedlog.exceptions.LockingException)2 LogRecordTooLongException (org.apache.distributedlog.exceptions.LogRecordTooLongException)2 OverCapacityException (org.apache.distributedlog.exceptions.OverCapacityException)2 ReadCancelledException (org.apache.distributedlog.exceptions.ReadCancelledException)2 WriteException (org.apache.distributedlog.exceptions.WriteException)2 URI (java.net.URI)1 AsyncLogReader (org.apache.distributedlog.api.AsyncLogReader)1