codelipenghui commented on code in PR #19035:
URL: https://github.com/apache/pulsar/pull/19035#discussion_r1058690786
##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java:
##########
@@ -2056,6 +2056,37 @@ private void internalReadFromLedger(ReadHandle ledger,
OpReadEntry opReadEntry)
long lastEntry = min(firstEntry +
opReadEntry.getNumberOfEntriesToRead() - 1, lastEntryInLedger);
+ // Filer out and skip unnecessary read entry
+ if (opReadEntry.skipCondition != null) {
+ long firstValidEntry = -1L;
+ long lastValidEntry = -1L;
+ long entryId = firstEntry;
+ for (; entryId <= lastEntry; entryId++) {
+ if
(!opReadEntry.skipCondition.test(PositionImpl.get(ledger.getId(), entryId))) {
+ firstValidEntry = entryId;
+ break;
+ }
+ }
+
+ // If all messages in [firstEntry...lastEntry] are filter out,
+ // then manual call internalReadEntriesComplete to advance read
position.
+ if (firstValidEntry == -1L) {
+
opReadEntry.internalReadEntriesComplete(Collections.emptyList(),
opReadEntry.ctx,
+ PositionImpl.get(ledger.getId(), lastEntry));
+ return;
+ }
+
+ for (; entryId <= lastEntry; entryId++) {
+ if
(opReadEntry.skipCondition.test(PositionImpl.get(ledger.getId(), entryId))) {
+ break;
+ }
+ lastValidEntry = entryId;
+ }
Review Comment:
Maybe you can try to optimize with only one loop to find the first invalid
entry range 😁
--
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]