use of org.apache.bookkeeper.proto.BookkeeperProtocol.StatusCode in project bookkeeper by apache.
the class WriteLacProcessorV3 method getWriteLacResponse.
// Returns null if there is no exception thrown
private WriteLacResponse getWriteLacResponse() {
final long startTimeNanos = MathUtils.nowInNano();
WriteLacRequest writeLacRequest = request.getWriteLacRequest();
long lac = writeLacRequest.getLac();
long ledgerId = writeLacRequest.getLedgerId();
final WriteLacResponse.Builder writeLacResponse = WriteLacResponse.newBuilder().setLedgerId(ledgerId);
if (!isVersionCompatible()) {
writeLacResponse.setStatus(StatusCode.EBADVERSION);
return writeLacResponse.build();
}
if (requestProcessor.bookie.isReadOnly()) {
logger.warn("BookieServer is running as readonly mode, so rejecting the request from the client!");
writeLacResponse.setStatus(StatusCode.EREADONLY);
return writeLacResponse.build();
}
StatusCode status = null;
ByteBuffer lacToAdd = writeLacRequest.getBody().asReadOnlyByteBuffer();
byte[] masterKey = writeLacRequest.getMasterKey().toByteArray();
try {
requestProcessor.bookie.setExplicitLac(Unpooled.wrappedBuffer(lacToAdd), channel, masterKey);
status = StatusCode.EOK;
} catch (IOException e) {
logger.error("Error saving lac {} for ledger:{}", lac, ledgerId, e);
status = StatusCode.EIO;
} catch (BookieException e) {
logger.error("Unauthorized access to ledger:{} while adding lac:{}", ledgerId, lac, e);
status = StatusCode.EUA;
} catch (Throwable t) {
logger.error("Unexpected exception while writing lac {} for ledger:{}", lac, ledgerId, t);
// some bad request which cause unexpected exception
status = StatusCode.EBADREQ;
}
// dosn't return a response back to the caller.
if (status.equals(StatusCode.EOK)) {
requestProcessor.writeLacStats.registerSuccessfulEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
} else {
requestProcessor.writeLacStats.registerFailedEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
}
writeLacResponse.setStatus(status);
return writeLacResponse.build();
}
Aggregations