Search in sources :

Example 1 with WriteLacRequest

use of org.apache.bookkeeper.proto.BookkeeperProtocol.WriteLacRequest in project bookkeeper by apache.

the class PerChannelBookieClient method writeLac.

void writeLac(final long ledgerId, final byte[] masterKey, final long lac, ByteBufList toSend, WriteLacCallback cb, Object ctx) {
    final long txnId = getTxnId();
    final CompletionKey completionKey = new V3CompletionKey(txnId, OperationType.WRITE_LAC);
    // writeLac is mostly like addEntry hence uses addEntryTimeout
    completionObjects.put(completionKey, new WriteLacCompletion(completionKey, cb, ctx, lac));
    // Build the request
    BKPacketHeader.Builder headerBuilder = BKPacketHeader.newBuilder().setVersion(ProtocolVersion.VERSION_THREE).setOperation(OperationType.WRITE_LAC).setTxnId(txnId);
    WriteLacRequest.Builder writeLacBuilder = WriteLacRequest.newBuilder().setLedgerId(ledgerId).setLac(lac).setMasterKey(ByteString.copyFrom(masterKey)).setBody(ByteString.copyFrom(toSend.toArray()));
    final Request writeLacRequest = Request.newBuilder().setHeader(headerBuilder).setWriteLacRequest(writeLacBuilder).build();
    writeAndFlush(channel, completionKey, writeLacRequest);
}
Also used : WriteLacRequest(org.apache.bookkeeper.proto.BookkeeperProtocol.WriteLacRequest) ReadLacRequest(org.apache.bookkeeper.proto.BookkeeperProtocol.ReadLacRequest) WriteLacRequest(org.apache.bookkeeper.proto.BookkeeperProtocol.WriteLacRequest) GetBookieInfoRequest(org.apache.bookkeeper.proto.BookkeeperProtocol.GetBookieInfoRequest) AddRequest(org.apache.bookkeeper.proto.BookkeeperProtocol.AddRequest) ReadRequest(org.apache.bookkeeper.proto.BookkeeperProtocol.ReadRequest) Request(org.apache.bookkeeper.proto.BookkeeperProtocol.Request) BKPacketHeader(org.apache.bookkeeper.proto.BookkeeperProtocol.BKPacketHeader)

Example 2 with WriteLacRequest

use of org.apache.bookkeeper.proto.BookkeeperProtocol.WriteLacRequest 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();
}
Also used : WriteLacRequest(org.apache.bookkeeper.proto.BookkeeperProtocol.WriteLacRequest) WriteLacResponse(org.apache.bookkeeper.proto.BookkeeperProtocol.WriteLacResponse) IOException(java.io.IOException) StatusCode(org.apache.bookkeeper.proto.BookkeeperProtocol.StatusCode) ByteBuffer(java.nio.ByteBuffer) BookieException(org.apache.bookkeeper.bookie.BookieException)

Aggregations

WriteLacRequest (org.apache.bookkeeper.proto.BookkeeperProtocol.WriteLacRequest)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 BookieException (org.apache.bookkeeper.bookie.BookieException)1 AddRequest (org.apache.bookkeeper.proto.BookkeeperProtocol.AddRequest)1 BKPacketHeader (org.apache.bookkeeper.proto.BookkeeperProtocol.BKPacketHeader)1 GetBookieInfoRequest (org.apache.bookkeeper.proto.BookkeeperProtocol.GetBookieInfoRequest)1 ReadLacRequest (org.apache.bookkeeper.proto.BookkeeperProtocol.ReadLacRequest)1 ReadRequest (org.apache.bookkeeper.proto.BookkeeperProtocol.ReadRequest)1 Request (org.apache.bookkeeper.proto.BookkeeperProtocol.Request)1 StatusCode (org.apache.bookkeeper.proto.BookkeeperProtocol.StatusCode)1 WriteLacResponse (org.apache.bookkeeper.proto.BookkeeperProtocol.WriteLacResponse)1