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();
}
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();
}
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);
}
}
Aggregations