Skip to content

Commit

Permalink
Code clean.
Browse files Browse the repository at this point in the history
  • Loading branch information
horizonzy committed Dec 2, 2023
1 parent 5a3791f commit 7ae6631
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 42 deletions.
1 change: 0 additions & 1 deletion bookkeeper-proto/src/main/proto/BookkeeperProtocol.proto
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ enum StatusCode {
EREADONLY = 505;
ETOOMANYREQUESTS = 506;
EUNKNOWNLEDGERSTATE = 507;
EBADREQUESTPARAMETER = 508;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ public interface Code {
int CookieExistsException = -109;
int EntryLogMetadataMapException = -110;
int DataUnknownException = -111;
int BadRequestParameterException = -112;
}

public int getCode() {
Expand Down Expand Up @@ -369,27 +368,4 @@ public DataUnknownException(String reason, Throwable t) {
super(Code.DataUnknownException, reason, t);
}
}

/**
* Signal the client request parameter is bad for bookie server.
*/
public static class BadRequestParameterException extends BookieException {
public BadRequestParameterException() {
super(Code.BadRequestParameterException);
}

public BadRequestParameterException(Throwable t) {
super(Code.BadRequestParameterException, t);
}

public BadRequestParameterException(String reason) {
super(Code.BadRequestParameterException, reason);
}

public BadRequestParameterException(String reason, Throwable t) {
super(Code.BadRequestParameterException, reason, t);
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ClientInternalConf {
final boolean useV2WireProtocol;
final boolean enforceMinNumFaultDomainsForWrite;
final boolean batchReadFailBackToSingleRead;
final int nettyMaxFrameSizeBytes;

static ClientInternalConf defaultValues() {
return fromConfig(new ClientConfiguration());
Expand All @@ -74,8 +75,8 @@ private ClientInternalConf(ClientConfiguration conf,
this.throttleValue = conf.getThrottleValue();
this.bookieFailureHistoryExpirationMSec = conf.getBookieFailureHistoryExpirationMSec();
this.batchReadFailBackToSingleRead = conf.isBatchReadFailBackToSingleRead();
this.nettyMaxFrameSizeBytes = conf.getNettyMaxFrameSizeBytes();
this.disableEnsembleChangeFeature = featureProvider.getFeature(conf.getDisableEnsembleChangeFeatureName());

this.delayEnsembleChange = conf.getDelayEnsembleChange();
this.maxAllowedEnsembleChanges = conf.getMaxAllowedEnsembleChanges();
this.timeoutMonitorIntervalSec = conf.getTimeoutMonitorIntervalSec();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,11 @@ private CompletableFuture<LedgerEntries> failBackSingleRead(long startEntry, int

private CompletableFuture<LedgerEntries> readEntriesInternalAsync(long startEntry, int maxCount, long maxSize,
boolean isRecoveryRead) {
if (maxSize > clientCtx.getConf().nettyMaxFrameSizeBytes) {
LOG.error("IncorrectParameterException on batch read. maxSize:{} is greater than nettyMaxFrameSizeBytes:{}",
maxSize, clientCtx.getConf().nettyMaxFrameSizeBytes);
return FutureUtils.exception(new BKIncorrectParameterException());
}
BatchedReadOp op = new BatchedReadOp(this, clientCtx,
startEntry, maxCount, maxSize, isRecoveryRead);
if (!clientCtx.isClientClosed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,40 @@
import io.netty.buffer.ByteBuf;
import io.netty.util.Recycler;
import io.netty.util.ReferenceCounted;
import org.apache.bookkeeper.bookie.BookieException;
import org.apache.bookkeeper.bookie.Bookie;
import org.apache.bookkeeper.proto.BookieProtocol.BatchedReadRequest;
import org.apache.bookkeeper.util.ByteBufList;

import java.util.concurrent.ExecutorService;

class BatchedReadEntryProcessor extends ReadEntryProcessor {

private long nettyMaxFrameSizeBytes;

boolean rejust = Boolean.getBoolean("aaa");
public static BatchedReadEntryProcessor create(BatchedReadRequest request,
BookieRequestHandler requestHandler,
BookieRequestProcessor requestProcessor,
ExecutorService fenceThreadPool,
boolean throttleReadResponses,
int nettyMaxFrameSizeBytes) {
boolean throttleReadResponses) {
BatchedReadEntryProcessor rep = RECYCLER.get();
rep.init(request, requestHandler, requestProcessor);
rep.fenceThreadPool = fenceThreadPool;
rep.throttleReadResponses = throttleReadResponses;
rep.nettyMaxFrameSizeBytes = nettyMaxFrameSizeBytes;
requestProcessor.onReadRequestStart(requestHandler.ctx().channel());
return rep;
}

@Override
protected ReferenceCounted readData() throws Exception {
// need to handle the max frame size
ByteBufList data = null;
BatchedReadRequest batchRequest = (BatchedReadRequest) request;
long maxSize = batchRequest.getMaxSize();
if (maxSize > nettyMaxFrameSizeBytes) {
throw new BookieException.BadRequestParameterException();
}
long entrySize = 0;
for (int i = 0; i < batchRequest.getMaxCount(); i++) {
try {
if (rejust && i == 0) {
throw new Bookie.NoEntryException(39, 0);
}
ByteBuf entry = requestProcessor.getBookie().readEntry(request.getLedgerId(), request.getEntryId() + i);
if (data == null) {
data = ByteBufList.get(entry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ public static short getFlags(int packetHeader) {
* Ledger in unknown state.
*/
int EUNKNOWNLEDGERSTATE = 107;

int EBADREQUESTPARAMETER = 108;

short FLAG_NONE = 0x0;
short FLAG_DO_FENCING = 0x0001;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ private void processReadRequest(final BookieProtocol.ReadRequest r, final Bookie
null == highPriorityThreadPool ? null : highPriorityThreadPool.chooseThread(requestHandler.ctx());
ReadEntryProcessor read = r instanceof BookieProtocol.BatchedReadRequest
? BatchedReadEntryProcessor.create((BookieProtocol.BatchedReadRequest) r, requestHandler,
this, fenceThreadPool, throttleReadResponses, serverCfg.getNettyMaxFrameSizeBytes())
this, fenceThreadPool, throttleReadResponses)
: ReadEntryProcessor.create(r, requestHandler,
this, fenceThreadPool, throttleReadResponses);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ protected void processPacket() {
LOG.debug("Error reading {}", request, e);
}
errorCode = BookieProtocol.EIO;
} catch (BookieException.BadRequestParameterException e) {
LOG.error("The request parameter is bad for bookie server, request: {}", request);
errorCode = BookieProtocol.EBADREQUESTPARAMETER;
} catch (BookieException.DataUnknownException e) {
LOG.error("Ledger {} is in an unknown state", request.getLedgerId(), e);
errorCode = BookieProtocol.EUNKNOWNLEDGERSTATE;
Expand Down

0 comments on commit 7ae6631

Please sign in to comment.