use of org.apache.distributedlog.exceptions.BKTransmitException in project bookkeeper by apache.
the class BKLogSegmentWriter method flushIfNeeded.
// Based on transmit buffer size, immediate flush, etc., should we flush the current
// packet now.
void flushIfNeeded() throws BKTransmitException, WriteException, InvalidEnvelopedEntryException, LockingException, FlushException {
if (outstandingBytes > transmissionThreshold) {
// If flush delay is disabled, flush immediately, else schedule appropriately.
if (0 == minDelayBetweenImmediateFlushMs) {
checkStateAndTransmit();
} else {
scheduleFlushWithDelayIfNeeded(new Callable<Void>() {
@Override
public Void call() throws Exception {
checkStateAndTransmit();
return null;
}
}, transmitSchedFutureRefUpdater);
// Timing here is not very important--the last flush failed and we should
// indicate this to the caller. The next flush may succeed and unset the
// scheduledFlushException in which case the next write will succeed (if the caller
// hasn't already closed the writer).
Exception exec = scheduledFlushExceptionUpdater.get(this);
if (exec != null) {
throw new FlushException("Last flush encountered an error while writing data to the backend", getLastTxId(), getLastTxIdAcknowledged(), exec);
}
}
}
}
use of org.apache.distributedlog.exceptions.BKTransmitException in project bookkeeper by apache.
the class BKLogSegmentEntryStore method openRandomAccessReader.
@Override
public CompletableFuture<LogSegmentRandomAccessEntryReader> openRandomAccessReader(final LogSegmentMetadata segment, final boolean fence) {
final BookKeeper bk;
try {
bk = this.bkc.get();
} catch (IOException e) {
return FutureUtils.exception(e);
}
final CompletableFuture<LogSegmentRandomAccessEntryReader> openPromise = new CompletableFuture<LogSegmentRandomAccessEntryReader>();
AsyncCallback.OpenCallback openCallback = new AsyncCallback.OpenCallback() {
@Override
public void openComplete(int rc, LedgerHandle lh, Object ctx) {
if (BKException.Code.OK != rc) {
FutureUtils.completeExceptionally(openPromise, new BKTransmitException("Failed to open ledger handle for log segment " + segment, rc));
return;
}
LogSegmentRandomAccessEntryReader reader = new BKLogSegmentRandomAccessEntryReader(segment, lh, conf);
FutureUtils.complete(openPromise, reader);
}
};
if (segment.isInProgress() && !fence) {
bk.asyncOpenLedgerNoRecovery(segment.getLogSegmentId(), BookKeeper.DigestType.CRC32, passwd, openCallback, null);
} else {
bk.asyncOpenLedger(segment.getLogSegmentId(), BookKeeper.DigestType.CRC32, passwd, openCallback, null);
}
return openPromise;
}
use of org.apache.distributedlog.exceptions.BKTransmitException in project bookkeeper by apache.
the class BKLogSegmentEntryStore method openComplete.
@Override
public void openComplete(int rc, LedgerHandle lh, Object ctx) {
OpenReaderRequest request = (OpenReaderRequest) ctx;
if (BKException.Code.OK != rc) {
FutureUtils.completeExceptionally(request.openPromise, new BKTransmitException("Failed to open ledger handle for log segment " + request.segment, rc));
return;
}
// successfully open a ledger
try {
LogSegmentEntryReader reader = new BKLogSegmentEntryReader(request.segment, lh, request.startEntryId, bkc.get(), scheduler, conf, statsLogger, failureInjector);
FutureUtils.complete(request.openPromise, reader);
} catch (IOException e) {
FutureUtils.completeExceptionally(request.openPromise, e);
}
}
use of org.apache.distributedlog.exceptions.BKTransmitException in project bookkeeper by apache.
the class BKLogSegmentRandomAccessEntryReader method readComplete.
@SuppressWarnings("unchecked")
@Override
public void readComplete(int rc, LedgerHandle lh, Enumeration<LedgerEntry> entries, Object ctx) {
CompletableFuture<List<Entry.Reader>> promise = (CompletableFuture<List<Entry.Reader>>) ctx;
if (BKException.Code.OK == rc) {
List<Entry.Reader> entryList = Lists.newArrayList();
while (entries.hasMoreElements()) {
LedgerEntry entry = entries.nextElement();
try {
entryList.add(processReadEntry(entry));
} catch (IOException ioe) {
// release the buffers
while (entries.hasMoreElements()) {
LedgerEntry le = entries.nextElement();
le.getEntryBuffer().release();
}
FutureUtils.completeExceptionally(promise, ioe);
return;
} finally {
entry.getEntryBuffer().release();
}
}
FutureUtils.complete(promise, entryList);
} else {
FutureUtils.completeExceptionally(promise, new BKTransmitException("Failed to read entries :", rc));
}
}
use of org.apache.distributedlog.exceptions.BKTransmitException in project bookkeeper by apache.
the class TestBKLogSegmentWriter method testNondurableWriteAfterLedgerIsFenced.
/**
* Non durable write should fail if the log segment is fenced.
*
* @throws Exception
*/
@Test(timeout = 60000)
public void testNondurableWriteAfterLedgerIsFenced() throws Exception {
DistributedLogConfiguration confLocal = newLocalConf();
confLocal.setImmediateFlushEnabled(false);
confLocal.setOutputBufferSize(Integer.MAX_VALUE);
confLocal.setPeriodicFlushFrequencyMilliSeconds(0);
confLocal.setDurableWriteEnabled(false);
ZKDistributedLock lock = createLock("/test/lock-" + runtime.getMethodName(), zkc, true);
BKLogSegmentWriter writer = createLogSegmentWriter(confLocal, 0L, -1L, lock);
// fence the ledger
fenceLedger(getLedgerHandle(writer));
LogRecord record = DLMTestUtil.getLogRecordInstance(1);
record.setControl();
try {
Utils.ioResult(writer.asyncWrite(record));
fail("Should fail the writer if the log segment is already fenced");
} catch (BKTransmitException bkte) {
// expected
assertEquals(BKException.Code.LedgerFencedException, bkte.getBKResultCode());
}
try {
Utils.ioResult(writer.asyncWrite(DLMTestUtil.getLogRecordInstance(2)));
fail("Should fail the writer if the log segment is already fenced");
} catch (WriteException we) {
// expected
}
abortWriterAndLock(writer, lock);
}
Aggregations