Search in sources :

Example 1 with Request

use of org.apache.bookkeeper.proto.BookkeeperProtocol.Request 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 Request

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

the class PerChannelBookieClient method getBookieInfo.

public void getBookieInfo(final long requested, GetBookieInfoCallback cb, Object ctx) {
    final long txnId = getTxnId();
    final CompletionKey completionKey = new V3CompletionKey(txnId, OperationType.GET_BOOKIE_INFO);
    completionObjects.put(completionKey, new GetBookieInfoCompletion(completionKey, cb, ctx));
    // Build the request and calculate the total size to be included in the packet.
    BKPacketHeader.Builder headerBuilder = BKPacketHeader.newBuilder().setVersion(ProtocolVersion.VERSION_THREE).setOperation(OperationType.GET_BOOKIE_INFO).setTxnId(txnId);
    GetBookieInfoRequest.Builder getBookieInfoBuilder = GetBookieInfoRequest.newBuilder().setRequested(requested);
    final Request getBookieInfoRequest = Request.newBuilder().setHeader(headerBuilder).setGetBookieInfoRequest(getBookieInfoBuilder).build();
    writeAndFlush(channel, completionKey, getBookieInfoRequest);
}
Also used : 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) GetBookieInfoRequest(org.apache.bookkeeper.proto.BookkeeperProtocol.GetBookieInfoRequest) BKPacketHeader(org.apache.bookkeeper.proto.BookkeeperProtocol.BKPacketHeader)

Example 3 with Request

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

the class LongPollReadEntryProcessorV3 method getLongPollReadResponse.

private ReadResponse getLongPollReadResponse() {
    if (!shouldReadEntry() && readRequest.hasTimeOut()) {
        if (logger.isTraceEnabled()) {
            logger.trace("Waiting For LAC Update {}", previousLAC);
        }
        final Stopwatch startTimeSw = Stopwatch.createStarted();
        final boolean watched;
        try {
            watched = requestProcessor.bookie.waitForLastAddConfirmedUpdate(ledgerId, previousLAC, this);
        } catch (Bookie.NoLedgerException e) {
            logger.info("No ledger found while longpoll reading ledger {}, previous lac = {}.", ledgerId, previousLAC);
            return buildErrorResponse(StatusCode.ENOLEDGER, startTimeSw);
        } catch (IOException ioe) {
            logger.error("IOException while longpoll reading ledger {}, previous lac = {} : ", ledgerId, previousLAC, ioe);
            return buildErrorResponse(StatusCode.EIO, startTimeSw);
        }
        registerSuccessfulEvent(requestProcessor.longPollPreWaitStats, startTimeSw);
        lastPhaseStartTime.reset().start();
        if (watched) {
            // successfully registered watcher to lac updates
            if (logger.isTraceEnabled()) {
                logger.trace("Waiting For LAC Update {}: Timeout {}", previousLAC, readRequest.getTimeOut());
            }
            synchronized (this) {
                expirationTimerTask = requestTimer.newTimeout(timeout -> {
                    // When the timeout expires just get whatever is the current
                    // readLastConfirmed
                    LongPollReadEntryProcessorV3.this.scheduleDeferredRead(true);
                }, readRequest.getTimeOut(), TimeUnit.MILLISECONDS);
            }
            return null;
        }
    }
    // request doesn't have timeout or fail to wait, proceed to read entry
    return getReadResponse();
}
Also used : Timeout(io.netty.util.Timeout) Logger(org.slf4j.Logger) Stopwatch(com.google.common.base.Stopwatch) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Request(org.apache.bookkeeper.proto.BookkeeperProtocol.Request) StatusCode(org.apache.bookkeeper.proto.BookkeeperProtocol.StatusCode) Channel(io.netty.channel.Channel) TimeUnit(java.util.concurrent.TimeUnit) ReadResponse(org.apache.bookkeeper.proto.BookkeeperProtocol.ReadResponse) Future(java.util.concurrent.Future) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) LastAddConfirmedUpdateNotification(org.apache.bookkeeper.bookie.LastAddConfirmedUpdateNotification) Watcher(org.apache.bookkeeper.common.util.Watcher) Optional(com.google.common.base.Optional) HashedWheelTimer(io.netty.util.HashedWheelTimer) Bookie(org.apache.bookkeeper.bookie.Bookie) ExecutorService(java.util.concurrent.ExecutorService) Bookie(org.apache.bookkeeper.bookie.Bookie) Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException)

Example 4 with Request

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

the class ProtocolBenchmark method testAddEntryV3.

@Benchmark
public void testAddEntryV3() throws Exception {
    // Build the request and calculate the total size to be included in the packet.
    BKPacketHeader.Builder headerBuilder = BKPacketHeader.newBuilder().setVersion(ProtocolVersion.VERSION_THREE).setOperation(OperationType.ADD_ENTRY).setTxnId(0L);
    ByteBuf toSend = entry.slice();
    byte[] toSendArray = new byte[toSend.readableBytes()];
    toSend.getBytes(toSend.readerIndex(), toSendArray);
    AddRequest.Builder addBuilder = AddRequest.newBuilder().setLedgerId(ledgerId).setEntryId(entryId).setMasterKey(ByteString.copyFrom(masterKey)).setBody(ByteString.copyFrom(toSendArray)).setFlag(AddRequest.Flag.RECOVERY_ADD);
    Request request = Request.newBuilder().setHeader(headerBuilder).setAddRequest(addBuilder).build();
    Object res = this.reqEnDeV3.encode(request, ByteBufAllocator.DEFAULT);
    ReferenceCountUtil.release(res);
}
Also used : AddRequest(org.apache.bookkeeper.proto.BookkeeperProtocol.AddRequest) Request(org.apache.bookkeeper.proto.BookkeeperProtocol.Request) AddRequest(org.apache.bookkeeper.proto.BookkeeperProtocol.AddRequest) ByteBuf(io.netty.buffer.ByteBuf) BKPacketHeader(org.apache.bookkeeper.proto.BookkeeperProtocol.BKPacketHeader) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Aggregations

Request (org.apache.bookkeeper.proto.BookkeeperProtocol.Request)4 AddRequest (org.apache.bookkeeper.proto.BookkeeperProtocol.AddRequest)3 BKPacketHeader (org.apache.bookkeeper.proto.BookkeeperProtocol.BKPacketHeader)3 GetBookieInfoRequest (org.apache.bookkeeper.proto.BookkeeperProtocol.GetBookieInfoRequest)2 ReadLacRequest (org.apache.bookkeeper.proto.BookkeeperProtocol.ReadLacRequest)2 ReadRequest (org.apache.bookkeeper.proto.BookkeeperProtocol.ReadRequest)2 WriteLacRequest (org.apache.bookkeeper.proto.BookkeeperProtocol.WriteLacRequest)2 Optional (com.google.common.base.Optional)1 Stopwatch (com.google.common.base.Stopwatch)1 ByteBuf (io.netty.buffer.ByteBuf)1 Channel (io.netty.channel.Channel)1 HashedWheelTimer (io.netty.util.HashedWheelTimer)1 Timeout (io.netty.util.Timeout)1 IOException (java.io.IOException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 TimeUnit (java.util.concurrent.TimeUnit)1 Bookie (org.apache.bookkeeper.bookie.Bookie)1 LastAddConfirmedUpdateNotification (org.apache.bookkeeper.bookie.LastAddConfirmedUpdateNotification)1