use of org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.ReadEntryCallback in project bookkeeper by apache.
the class LedgerReader method readLacs.
public void readLacs(final LedgerHandle lh, long eid, final GenericCallback<Set<ReadResult<Long>>> callback) {
WriteSet writeSet = lh.distributionSchedule.getWriteSet(eid);
final AtomicInteger numBookies = new AtomicInteger(writeSet.size());
final Set<ReadResult<Long>> readResults = new HashSet<ReadResult<Long>>();
ReadEntryCallback readEntryCallback = (rc, lid, eid1, buffer, ctx) -> {
InetSocketAddress bookieAddress = (InetSocketAddress) ctx;
ReadResult<Long> rr;
if (BKException.Code.OK != rc) {
rr = new ReadResult<Long>(eid1, rc, null, bookieAddress);
} else {
try {
DigestManager.RecoveryData data = lh.macManager.verifyDigestAndReturnLastConfirmed(buffer);
rr = new ReadResult<Long>(eid1, BKException.Code.OK, data.getLastAddConfirmed(), bookieAddress);
} catch (BKException.BKDigestMatchException e) {
rr = new ReadResult<Long>(eid1, BKException.Code.DigestMatchException, null, bookieAddress);
}
}
readResults.add(rr);
if (numBookies.decrementAndGet() == 0) {
callback.operationComplete(BKException.Code.OK, readResults);
}
};
ArrayList<BookieSocketAddress> ensemble = lh.getLedgerMetadata().getEnsemble(eid);
for (int i = 0; i < writeSet.size(); i++) {
int idx = writeSet.get(i);
bookieClient.readEntry(ensemble.get(idx), lh.getId(), eid, readEntryCallback, ensemble.get(idx), BookieProtocol.FLAG_NONE);
}
}
use of org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.ReadEntryCallback in project bookkeeper by apache.
the class LedgerReader method readEntriesFromAllBookies.
public void readEntriesFromAllBookies(final LedgerHandle lh, long eid, final GenericCallback<Set<ReadResult<ByteBuf>>> callback) {
WriteSet writeSet = lh.distributionSchedule.getWriteSet(eid);
final AtomicInteger numBookies = new AtomicInteger(writeSet.size());
final Set<ReadResult<ByteBuf>> readResults = new HashSet<>();
ReadEntryCallback readEntryCallback = new ReadEntryCallback() {
@Override
public void readEntryComplete(int rc, long lid, long eid, ByteBuf buffer, Object ctx) {
BookieSocketAddress bookieAddress = (BookieSocketAddress) ctx;
ReadResult<ByteBuf> rr;
if (BKException.Code.OK != rc) {
rr = new ReadResult<>(eid, rc, null, bookieAddress.getSocketAddress());
} else {
ByteBuf content;
try {
content = lh.macManager.verifyDigestAndReturnData(eid, buffer);
ByteBuf toRet = Unpooled.copiedBuffer(content);
rr = new ReadResult<>(eid, BKException.Code.OK, toRet, bookieAddress.getSocketAddress());
} catch (BKException.BKDigestMatchException e) {
rr = new ReadResult<>(eid, BKException.Code.DigestMatchException, null, bookieAddress.getSocketAddress());
} finally {
buffer.release();
}
}
readResults.add(rr);
if (numBookies.decrementAndGet() == 0) {
callback.operationComplete(BKException.Code.OK, readResults);
}
}
};
ArrayList<BookieSocketAddress> ensemble = lh.getLedgerMetadata().getEnsemble(eid);
for (int i = 0; i < writeSet.size(); i++) {
int idx = writeSet.get(i);
bookieClient.readEntry(ensemble.get(idx), lh.getId(), eid, readEntryCallback, ensemble.get(idx), BookieProtocol.FLAG_NONE);
}
}
use of org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.ReadEntryCallback in project bookkeeper by apache.
the class TestPerChannelBookieClient method testRequestCompletesAfterDisconnectRace.
/**
* Test that requests are completed even if the channel is disconnected
* {@link https://issues.apache.org/jira/browse/BOOKKEEPER-668}.
*/
@Test
public void testRequestCompletesAfterDisconnectRace() throws Exception {
ServerConfiguration conf = killBookie(0);
Bookie delayBookie = new Bookie(conf) {
@Override
public ByteBuf readEntry(long ledgerId, long entryId) throws IOException, NoLedgerException {
try {
Thread.sleep(3000);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new IOException("Interrupted waiting", ie);
}
return super.readEntry(ledgerId, entryId);
}
};
bsConfs.add(conf);
bs.add(startBookie(conf, delayBookie));
EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
final OrderedExecutor executor = getOrderedSafeExecutor();
BookieSocketAddress addr = getBookie(0);
final PerChannelBookieClient client = new PerChannelBookieClient(executor, eventLoopGroup, addr, authProvider, extRegistry);
final CountDownLatch completion = new CountDownLatch(1);
final ReadEntryCallback cb = new ReadEntryCallback() {
@Override
public void readEntryComplete(int rc, long ledgerId, long entryId, ByteBuf buffer, Object ctx) {
completion.countDown();
}
};
client.connectIfNeededAndDoOp(new GenericCallback<PerChannelBookieClient>() {
@Override
public void operationComplete(final int rc, PerChannelBookieClient pcbc) {
if (rc != BKException.Code.OK) {
executor.executeOrdered(1, new SafeRunnable() {
@Override
public void safeRun() {
cb.readEntryComplete(rc, 1, 1, null, null);
}
});
return;
}
client.readEntry(1, 1, cb, null, BookieProtocol.FLAG_DO_FENCING, "00000111112222233333".getBytes());
}
});
Thread.sleep(1000);
client.disconnect();
client.close();
assertTrue("Request should have completed", completion.await(5, TimeUnit.SECONDS));
eventLoopGroup.shutdownGracefully();
executor.shutdown();
}
use of org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.ReadEntryCallback in project distributedlog by twitter.
the class LedgerReader method readEntriesFromAllBookies.
public void readEntriesFromAllBookies(final LedgerHandle lh, long eid, final GenericCallback<Set<ReadResult<InputStream>>> callback) {
List<Integer> writeSet = lh.distributionSchedule.getWriteSet(eid);
final AtomicInteger numBookies = new AtomicInteger(writeSet.size());
final Set<ReadResult<InputStream>> readResults = new HashSet<ReadResult<InputStream>>();
ReadEntryCallback readEntryCallback = new ReadEntryCallback() {
@Override
public void readEntryComplete(int rc, long lid, long eid, ChannelBuffer buffer, Object ctx) {
BookieSocketAddress bookieAddress = (BookieSocketAddress) ctx;
ReadResult<InputStream> rr;
if (BKException.Code.OK != rc) {
rr = new ReadResult<InputStream>(eid, rc, null, bookieAddress.getSocketAddress());
} else {
try {
ChannelBufferInputStream is = lh.macManager.verifyDigestAndReturnData(eid, buffer);
rr = new ReadResult<InputStream>(eid, BKException.Code.OK, is, bookieAddress.getSocketAddress());
} catch (BKException.BKDigestMatchException e) {
rr = new ReadResult<InputStream>(eid, BKException.Code.DigestMatchException, null, bookieAddress.getSocketAddress());
}
}
readResults.add(rr);
if (numBookies.decrementAndGet() == 0) {
callback.operationComplete(BKException.Code.OK, readResults);
}
}
};
ArrayList<BookieSocketAddress> ensemble = lh.getLedgerMetadata().getEnsemble(eid);
for (Integer idx : writeSet) {
bookieClient.readEntry(ensemble.get(idx), lh.getId(), eid, readEntryCallback, ensemble.get(idx));
}
}
use of org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.ReadEntryCallback in project distributedlog by twitter.
the class LedgerReader method readLacs.
public void readLacs(final LedgerHandle lh, long eid, final GenericCallback<Set<ReadResult<Long>>> callback) {
List<Integer> writeSet = lh.distributionSchedule.getWriteSet(eid);
final AtomicInteger numBookies = new AtomicInteger(writeSet.size());
final Set<ReadResult<Long>> readResults = new HashSet<ReadResult<Long>>();
ReadEntryCallback readEntryCallback = new ReadEntryCallback() {
@Override
public void readEntryComplete(int rc, long lid, long eid, ChannelBuffer buffer, Object ctx) {
InetSocketAddress bookieAddress = (InetSocketAddress) ctx;
ReadResult<Long> rr;
if (BKException.Code.OK != rc) {
rr = new ReadResult<Long>(eid, rc, null, bookieAddress);
} else {
try {
DigestManager.RecoveryData data = lh.macManager.verifyDigestAndReturnLastConfirmed(buffer);
rr = new ReadResult<Long>(eid, BKException.Code.OK, data.lastAddConfirmed, bookieAddress);
} catch (BKException.BKDigestMatchException e) {
rr = new ReadResult<Long>(eid, BKException.Code.DigestMatchException, null, bookieAddress);
}
}
readResults.add(rr);
if (numBookies.decrementAndGet() == 0) {
callback.operationComplete(BKException.Code.OK, readResults);
}
}
};
ArrayList<BookieSocketAddress> ensemble = lh.getLedgerMetadata().getEnsemble(eid);
for (Integer idx : writeSet) {
bookieClient.readEntry(ensemble.get(idx), lh.getId(), eid, readEntryCallback, ensemble.get(idx));
}
}
Aggregations