Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,11 @@ public Map<String, Long> getProperties() {
public boolean isCursorDataFullyPersistable() {
lock.readLock().lock();
try {
return individualDeletedMessages.size() <= getConfig().getMaxUnackedRangesToPersist();
if (individualDeletedMessages.size() > getConfig().getMaxUnackedRangesToPersist()) {
return false;
}
return batchDeletedIndexes == null
|| batchDeletedIndexes.size() <= getConfig().getMaxBatchDeletedIndexToPersist();
} finally {
lock.readLock().unlock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import lombok.Cleanup;
import org.awaitility.Awaitility;
import org.apache.bookkeeper.mledger.ManagedLedgerConfig;
import org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException;
import org.apache.bookkeeper.mledger.Position;
Expand All @@ -50,6 +51,33 @@ public Object[][] booleans() {
return new Object[][] {{false}, {true}};
}

@Test
public void testIsCursorDataFullyPersistableReflectsBatchDeletedIndexLimit() throws Exception {
ManagedLedgerConfig config = new ManagedLedgerConfig();
config.setDeletionAtBatchIndexLevelEnabled(true);
config.setMaxBatchDeletedIndexToPersist(2);
config.setThrottleMarkDelete(0);
String name = "tenant/ns/persistent/cursor-data-fully-persistable-batch-index";
@Cleanup
ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open(name, config);
ManagedCursorImpl cursor = (ManagedCursorImpl) ledger.openCursor("sub");
List<Position> positions = new ArrayList<>();
for (int i = 0; i <= 3; i++) {
positions.add(ledger.addEntry(new byte[] {(byte) i}));
}
cursor.delete(positions.get(0));
Awaitility.await().until(() -> cursor.getStats().getPersistLedgerSucceed() > 0);

long[][] ackSets = {{2L}, {Long.MIN_VALUE, 1L}, {5L, 0L, 3L}};
for (int i = 1; i < positions.size(); i++) {
Position position = positions.get(i);
cursor.delete(AckSetStateUtil.createPositionWithAckSet(
position.getLedgerId(), position.getEntryId(), ackSets[i - 1]));
}

assertThat(cursor.isCursorDataFullyPersistable()).isFalse();
}

@Test(dataProvider = "batchRecovery")
public void testPartialBatchAckPersistenceRetainsConfiguredCount(int batchCount, boolean metadataStore)
throws Exception {
Expand Down