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