Search in sources :

Example 1 with ReadResponse

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

the class ReadEntryProcessorV3 method safeRun.

@Override
public void safeRun() {
    requestProcessor.readEntrySchedulingDelayStats.registerSuccessfulEvent(MathUtils.elapsedNanos(enqueueNanos), TimeUnit.NANOSECONDS);
    if (!isVersionCompatible()) {
        ReadResponse readResponse = ReadResponse.newBuilder().setLedgerId(ledgerId).setEntryId(entryId).setStatus(StatusCode.EBADVERSION).build();
        sendResponse(readResponse);
        return;
    }
    executeOp();
}
Also used : ReadResponse(org.apache.bookkeeper.proto.BookkeeperProtocol.ReadResponse)

Example 2 with ReadResponse

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

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

the class ReadEntryProcessorV3 method getReadResponse.

protected ReadResponse getReadResponse() {
    final Stopwatch startTimeSw = Stopwatch.createStarted();
    final ReadResponse.Builder readResponse = ReadResponse.newBuilder().setLedgerId(ledgerId).setEntryId(entryId);
    try {
        // handle fence reqest
        if (RequestUtils.isFenceRequest(readRequest)) {
            LOG.info("Ledger fence request received for ledger: {} from address: {}", ledgerId, channel.remoteAddress());
            if (!readRequest.hasMasterKey()) {
                LOG.error("Fence ledger request received without master key for ledger:{} from address: {}", ledgerId, channel.remoteAddress());
                throw BookieException.create(BookieException.Code.UnauthorizedAccessException);
            } else {
                byte[] masterKey = readRequest.getMasterKey().toByteArray();
                fenceResult = requestProcessor.bookie.fenceLedger(ledgerId, masterKey);
            }
        }
        return readEntry(readResponse, entryId, startTimeSw);
    } catch (Bookie.NoLedgerException e) {
        if (RequestUtils.isFenceRequest(readRequest)) {
            LOG.info("No ledger found reading entry {} when fencing ledger {}", entryId, ledgerId);
        } else {
            LOG.info("No ledger found while reading entry: {} from ledger: {}", entryId, ledgerId);
        }
        return buildResponse(readResponse, StatusCode.ENOLEDGER, startTimeSw);
    } catch (Bookie.NoEntryException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("No entry found while reading entry: {} from ledger: {}", entryId, ledgerId);
        }
        return buildResponse(readResponse, StatusCode.ENOENTRY, startTimeSw);
    } catch (IOException e) {
        LOG.error("IOException while reading entry: {} from ledger {} ", entryId, ledgerId, e);
        return buildResponse(readResponse, StatusCode.EIO, startTimeSw);
    } catch (BookieException e) {
        LOG.error("Unauthorized access to ledger:{} while reading entry:{} in request from address: {}", ledgerId, entryId, channel.remoteAddress());
        return buildResponse(readResponse, StatusCode.EUA, startTimeSw);
    }
}
Also used : ReadResponse(org.apache.bookkeeper.proto.BookkeeperProtocol.ReadResponse) Bookie(org.apache.bookkeeper.bookie.Bookie) Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException) BookieException(org.apache.bookkeeper.bookie.BookieException)

Aggregations

ReadResponse (org.apache.bookkeeper.proto.BookkeeperProtocol.ReadResponse)3 Stopwatch (com.google.common.base.Stopwatch)2 IOException (java.io.IOException)2 Bookie (org.apache.bookkeeper.bookie.Bookie)2 Optional (com.google.common.base.Optional)1 Channel (io.netty.channel.Channel)1 HashedWheelTimer (io.netty.util.HashedWheelTimer)1 Timeout (io.netty.util.Timeout)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 BookieException (org.apache.bookkeeper.bookie.BookieException)1 LastAddConfirmedUpdateNotification (org.apache.bookkeeper.bookie.LastAddConfirmedUpdateNotification)1 Watcher (org.apache.bookkeeper.common.util.Watcher)1 Request (org.apache.bookkeeper.proto.BookkeeperProtocol.Request)1 StatusCode (org.apache.bookkeeper.proto.BookkeeperProtocol.StatusCode)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1