use of org.apache.bookkeeper.proto.BookkeeperProtocol.ReadLacResponse in project bookkeeper by apache.
the class ReadLacProcessorV3 method safeRun.
@Override
public void safeRun() {
ReadLacResponse readLacResponse = getReadLacResponse();
sendResponse(readLacResponse);
}
use of org.apache.bookkeeper.proto.BookkeeperProtocol.ReadLacResponse in project bookkeeper by apache.
the class ReadLacProcessorV3 method getReadLacResponse.
// Returns null if there is no exception thrown
private ReadLacResponse getReadLacResponse() {
final long startTimeNanos = MathUtils.nowInNano();
ReadLacRequest readLacRequest = request.getReadLacRequest();
long ledgerId = readLacRequest.getLedgerId();
final ReadLacResponse.Builder readLacResponse = ReadLacResponse.newBuilder().setLedgerId(ledgerId);
if (!isVersionCompatible()) {
readLacResponse.setStatus(StatusCode.EBADVERSION);
return readLacResponse.build();
}
logger.debug("Received ReadLac request: {}", request);
StatusCode status = StatusCode.EOK;
ByteBuf lastEntry = null;
ByteBuf lac = null;
try {
lac = requestProcessor.bookie.getExplicitLac(ledgerId);
if (lac != null) {
readLacResponse.setLacBody(ByteString.copyFrom(lac.nioBuffer()));
}
} catch (Bookie.NoLedgerException e) {
status = StatusCode.ENOLEDGER;
logger.error("No ledger found while performing readLac from ledger: {}", ledgerId, e);
} catch (IOException e) {
status = StatusCode.EIO;
logger.error("IOException while performing readLac from ledger: {}", ledgerId);
} finally {
ReferenceCountUtil.release(lac);
}
try {
lastEntry = requestProcessor.bookie.readEntry(ledgerId, BookieProtocol.LAST_ADD_CONFIRMED);
if (lastEntry != null) {
readLacResponse.setLastEntryBody(ByteString.copyFrom(lastEntry.nioBuffer()));
}
} catch (Bookie.NoLedgerException e) {
status = StatusCode.ENOLEDGER;
logger.error("No ledger found while trying to read last entry: {}", ledgerId, e);
} catch (IOException e) {
status = StatusCode.EIO;
logger.error("IOException while trying to read last entry: {}", ledgerId, e);
} finally {
ReferenceCountUtil.release(lastEntry);
}
if ((lac == null) && (lastEntry == null)) {
status = StatusCode.ENOENTRY;
}
if (status == StatusCode.EOK) {
requestProcessor.readLacStats.registerSuccessfulEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
} else {
requestProcessor.readLacStats.registerFailedEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
}
// Finally set the status and return
readLacResponse.setStatus(status);
return readLacResponse.build();
}
Aggregations