You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/03/15 10:32:51 UTC
[GitHub] [pulsar] BewareMyPower commented on a change in pull request #14672: Change ``rollCurrentLedgerIfFull`` logic to follow lazy creation of ledger
BewareMyPower commented on a change in pull request #14672:
URL: https://github.com/apache/pulsar/pull/14672#discussion_r826779386
##########
File path: managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerTest.java
##########
@@ -1972,15 +1975,25 @@ public void testDeletionAfterLedgerClosedAndRetention() throws Exception {
Field stateUpdater = ManagedLedgerImpl.class.getDeclaredField("state");
stateUpdater.setAccessible(true);
stateUpdater.set(ml, ManagedLedgerImpl.State.LedgerOpened);
+ long preLedgerId = ml.getLedgersInfoAsList().get(ml.getLedgersInfoAsList().size() -1).getLedgerId();
+ ml.pendingAddEntries.add(OpAddEntry.
+ createNoRetainBuffer(ml, ByteBufAllocator.DEFAULT.buffer(128).retain(), null, null));
ml.rollCurrentLedgerIfFull();
+ AtomicLong currentLedgerId = new AtomicLong(-1);
+ // create a new ledger
+ Awaitility.await().untilAsserted(()-> {
Review comment:
```suggestion
Awaitility.await().untilAsserted(() -> {
```
##########
File path: managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerTest.java
##########
@@ -1972,15 +1975,25 @@ public void testDeletionAfterLedgerClosedAndRetention() throws Exception {
Field stateUpdater = ManagedLedgerImpl.class.getDeclaredField("state");
stateUpdater.setAccessible(true);
stateUpdater.set(ml, ManagedLedgerImpl.State.LedgerOpened);
Review comment:
I think we can remove the explicit state reset as well because now the `maxEntriesPerLedger` is 2 and the state is `LedgerOpened` not `ClosedLedger`.
##########
File path: pulsar-broker/src/test/java/org/apache/pulsar/broker/service/CurrentLedgerRolloverIfFullTest.java
##########
@@ -104,12 +110,51 @@ public void testCurrentLedgerRolloverIfFull() throws Exception {
stateUpdater.set(managedLedger, ManagedLedgerImpl.State.LedgerOpened);
managedLedger.rollCurrentLedgerIfFull();
- // the last ledger will be closed and removed and we have one ledger for empty
+ // If there are no pending write messages, the last ledger will be closed and still held.
Awaitility.await()
.pollInterval(Duration.ofMillis(1000L))
.untilAsserted(() -> {
Assert.assertEquals(managedLedger.getLedgersInfoAsList().size(), 1);
- Assert.assertEquals(managedLedger.getTotalSize(), 0);
+ Assert.assertNotEquals(managedLedger.getCurrentLedgerSize(), 0);
+ MLDataFormats.ManagedLedgerInfo.LedgerInfo lastLhAfterRollover =
+ managedLedger.getLedgersInfoAsList().get(managedLedger.getLedgersInfoAsList().size() - 1);
Review comment:
Maybe we can add a `getLastLedgerId` method to simplify the code.
```java
Supplier<Long> lastLedgerIdSupplier = () -> {
final List<LedgerInfo> ledgers = managedLedger.getLedgersInfoAsList();
Assert.assertFalse(ledgers.isEmpty());
return ledgers.get(ledgers.size() - 1).getLedgerId();
};
```
--
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: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org