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);
}
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();
}
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();
}
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();
}
}
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();
}
}
Aggregations