horizonzy commented on code in PR #4188:
URL: https://github.com/apache/bookkeeper/pull/4188#discussion_r1467395039
##########
bookkeeper-server/src/test/java/org/apache/bookkeeper/proto/MockBookies.java:
##########
@@ -123,6 +123,47 @@ public ByteBuf readEntry(BookieId bookieId, int flags,
long ledgerId, long entry
return entry;
}
+ public ByteBufList batchReadEntry(BookieId bookieId, int flags, long
ledgerId, long startEntryId,
Review Comment:
make sense.
##########
bookkeeper-server/src/test/java/org/apache/bookkeeper/proto/MockBookies.java:
##########
@@ -123,6 +123,47 @@ public ByteBuf readEntry(BookieId bookieId, int flags,
long ledgerId, long entry
return entry;
}
+ public ByteBufList batchReadEntry(BookieId bookieId, int flags, long
ledgerId, long startEntryId,
+ int maxCount, long maxSize) throws BKException {
+ MockLedgerData ledger = getBookieData(bookieId).get(ledgerId);
+
+ if (ledger == null) {
+ LOG.warn("[{};L{}] ledger not found", bookieId, ledgerId);
+ throw new BKException.BKNoSuchLedgerExistsException();
+ }
+
+ if ((flags & BookieProtocol.FLAG_DO_FENCING) ==
BookieProtocol.FLAG_DO_FENCING) {
+ ledger.fence();
+ }
+ //Refer: BatchedReadEntryProcessor.readData
+ ByteBufList data = null;
+ if (maxCount <= 0) {
+ maxCount = Integer.MAX_VALUE;
+ }
+ long frameSize = 24 + 8 + 4;
+ for (long i = startEntryId; i < startEntryId + maxCount; i++) {
+ try {
+ ByteBuf entry = ledger.getEntry(i);
+ frameSize += entry.readableBytes() + 4;
+ if (data == null) {
+ data = ByteBufList.get(entry);
+ } else {
+ if (frameSize > maxSize) {
+ entry.release();
+ break;
+ }
+ data.add(entry);
+ }
+ } catch (Throwable e) {
Review Comment:
Make sense, I copy the code from the BatchedReadEntryProcessor, here we
don't need catch the exception.
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java:
##########
@@ -687,7 +688,7 @@ void
connectIfNeededAndDoOp(GenericCallback<PerChannelBookieClient> op) {
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,
+ final CompletionKey completionKey = new TxnCompletionKey(txnId,
Review Comment:
The `V3CompletionKey` may mislead. In this PR, it's used for the v2 batch
read. The V3CompletionKey uses txnId to trace, so I change the name to
TxnCompletionKe.
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java:
##########
@@ -2340,28 +2467,28 @@ private long getTxnId() {
return txnIdGenerator.incrementAndGet();
}
- private final Recycler<V2CompletionKey> v2KeyRecycler = new
Recycler<V2CompletionKey>() {
+ private final Recycler<EntryCompletionKey> v2KeyRecycler = new
Recycler<EntryCompletionKey>() {
Review Comment:
We are renaming V3CompletionKey to TxnCompletionKey. Therefore, I want to
downplay the concepts of V2 and V3 and name it based on its purpose.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]