use of org.apache.bookkeeper.util.ByteBufList in project bookkeeper by apache.
the class TestPendingReadLacOp method testPendingReadLacOpMissingExplicitLAC.
@Test
public void testPendingReadLacOpMissingExplicitLAC() throws Exception {
LedgerHandle lh = bkc.createLedger(3, 3, 2, BookKeeper.DigestType.CRC32, pwd);
lh.append(data);
lh.append(data);
lh.append(data);
final CompletableFuture<Long> result = new CompletableFuture<>();
PendingReadLacOp pro = new PendingReadLacOp(lh, (rc, lac) -> result.complete(lac)) {
@Override
public void initiate() {
for (int i = 0; i < lh.metadata.currentEnsemble.size(); i++) {
final int index = i;
ByteBufList buffer = lh.getDigestManager().computeDigestAndPackageForSending(2, 1, data.length, Unpooled.wrappedBuffer(data));
bkc.scheduler.schedule(() -> {
readLacComplete(0, lh.getId(), null, Unpooled.copiedBuffer(buffer.toArray()), index);
}, 0, TimeUnit.SECONDS);
lh.bk.getBookieClient().readLac(lh.metadata.currentEnsemble.get(i), lh.ledgerId, this, i);
}
}
};
pro.initiate();
assertEquals(1, result.get().longValue());
}
use of org.apache.bookkeeper.util.ByteBufList in project bookkeeper by apache.
the class ParallelLedgerRecoveryTest method testRecoveryOnEntryGap.
@Test
public void testRecoveryOnEntryGap() throws Exception {
byte[] passwd = "recovery-on-entry-gap".getBytes(UTF_8);
LedgerHandle lh = bkc.createLedger(1, 1, 1, DigestType.CRC32, passwd);
for (int i = 0; i < 10; i++) {
lh.addEntry(("recovery-on-entry-gap-" + i).getBytes(UTF_8));
}
// simulate ledger writer failure on concurrent writes causing gaps
long entryId = 14;
long lac = 8;
byte[] data = "recovery-on-entry-gap-gap".getBytes(UTF_8);
ByteBufList toSend = lh.macManager.computeDigestAndPackageForSending(entryId, lac, lh.getLength() + 100, Unpooled.wrappedBuffer(data, 0, data.length));
final CountDownLatch addLatch = new CountDownLatch(1);
final AtomicBoolean addSuccess = new AtomicBoolean(false);
LOG.info("Add entry {} with lac = {}", entryId, lac);
lh.bk.getBookieClient().addEntry(lh.metadata.currentEnsemble.get(0), lh.getId(), lh.ledgerKey, entryId, toSend, new WriteCallback() {
@Override
public void writeComplete(int rc, long ledgerId, long entryId, BookieSocketAddress addr, Object ctx) {
addSuccess.set(BKException.Code.OK == rc);
addLatch.countDown();
}
}, 0, BookieProtocol.FLAG_NONE);
addLatch.await();
assertTrue("add entry 14 should succeed", addSuccess.get());
ClientConfiguration newConf = new ClientConfiguration();
newConf.addConfiguration(baseClientConf);
newConf.setEnableParallelRecoveryRead(true);
newConf.setRecoveryReadBatchSize(10);
BookKeeper newBk = new BookKeeper(newConf);
final LedgerHandle recoverLh = newBk.openLedgerNoRecovery(lh.getId(), DigestType.CRC32, passwd);
assertEquals("wrong lac found", 8L, recoverLh.getLastAddConfirmed());
final CountDownLatch recoverLatch = new CountDownLatch(1);
final AtomicLong newLac = new AtomicLong(-1);
final AtomicBoolean isMetadataClosed = new AtomicBoolean(false);
final AtomicInteger numSuccessCalls = new AtomicInteger(0);
final AtomicInteger numFailureCalls = new AtomicInteger(0);
recoverLh.recover(new GenericCallback<Void>() {
@Override
public void operationComplete(int rc, Void result) {
if (BKException.Code.OK == rc) {
newLac.set(recoverLh.getLastAddConfirmed());
isMetadataClosed.set(recoverLh.getLedgerMetadata().isClosed());
numSuccessCalls.incrementAndGet();
} else {
numFailureCalls.incrementAndGet();
}
recoverLatch.countDown();
}
});
recoverLatch.await();
assertEquals("wrong lac found", 9L, newLac.get());
assertTrue("metadata isn't closed after recovery", isMetadataClosed.get());
Thread.sleep(5000);
assertEquals("recovery callback should be triggered only once", 1, numSuccessCalls.get());
assertEquals("recovery callback should be triggered only once", 0, numFailureCalls.get());
}
Aggregations