use of org.apache.distributedlog.exceptions.IdleReaderException in project bookkeeper by apache.
the class TestAsyncReaderWriter method testAsyncReadIdleErrorInternal.
private void testAsyncReadIdleErrorInternal(String name, final int idleReaderErrorThreshold, final boolean heartBeatUsingControlRecs, final boolean simulateReaderStall) throws Exception {
DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.loadConf(testConf);
confLocal.setOutputBufferSize(0);
confLocal.setImmediateFlushEnabled(true);
confLocal.setReadAheadBatchSize(1);
confLocal.setReadAheadMaxRecords(1);
confLocal.setReaderIdleWarnThresholdMillis(0);
confLocal.setReaderIdleErrorThresholdMillis(idleReaderErrorThreshold);
final DistributedLogManager dlm = createNewDLM(confLocal, name);
final Thread currentThread = Thread.currentThread();
final int segmentSize = 3;
final int numSegments = 3;
final CountDownLatch latch = 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++) {
long start = txid;
BKSyncLogWriter writer = (BKSyncLogWriter) dlm.startLogSegmentNonPartitioned();
for (long j = 1; j <= segmentSize; j++) {
writer.write(DLMTestUtil.getLargeLogRecordInstance(txid++));
if ((i == 0) && (j == 1)) {
latch.countDown();
}
}
if (heartBeatUsingControlRecs) {
// There should be a control record such that
// wait time + commit time (BK) < Idle Reader Threshold
int threadSleepTime = idleReaderErrorThreshold - // BK commitTime
200 - // safety margin
100;
for (int iter = 1; iter <= (2 * idleReaderErrorThreshold / threadSleepTime); iter++) {
Thread.sleep(threadSleepTime);
writer.write(DLMTestUtil.getLargeLogRecordInstance(txid, true));
writer.flush();
}
Thread.sleep(threadSleepTime);
}
writer.closeAndComplete();
if (!heartBeatUsingControlRecs) {
Thread.sleep(2 * idleReaderErrorThreshold);
}
}
} catch (Exception exc) {
if (!executor.isShutdown()) {
currentThread.interrupt();
}
}
}
}, 0, TimeUnit.MILLISECONDS);
latch.await();
BKAsyncLogReader reader = (BKAsyncLogReader) dlm.getAsyncLogReader(DLSN.InitialDLSN);
if (simulateReaderStall) {
reader.disableProcessingReadRequests();
}
boolean exceptionEncountered = false;
int recordCount = 0;
try {
while (true) {
CompletableFuture<LogRecordWithDLSN> record = reader.readNext();
Utils.ioResult(record);
recordCount++;
if (recordCount >= segmentSize * numSegments) {
break;
}
}
} catch (IdleReaderException exc) {
exceptionEncountered = true;
}
if (simulateReaderStall) {
assertTrue(exceptionEncountered);
} else if (heartBeatUsingControlRecs) {
assertFalse(exceptionEncountered);
Assert.assertEquals(segmentSize * numSegments, recordCount);
} else {
assertTrue(exceptionEncountered);
Assert.assertEquals(segmentSize, recordCount);
}
assertFalse(currentThread.isInterrupted());
Utils.close(reader);
executor.shutdown();
}
use of org.apache.distributedlog.exceptions.IdleReaderException in project bookkeeper by apache.
the class BKSyncLogReader method markReaderAsIdle.
private void markReaderAsIdle() throws IdleReaderException {
idleReaderError.inc();
IdleReaderException ire = new IdleReaderException("Sync reader on stream " + readHandler.getFullyQualifiedName() + " is idle for more than " + idleErrorThresholdMillis + " ms");
readerException.compareAndSet(null, ire);
throw ire;
}
Aggregations