Skip to content

Commit

Permalink
Close old compacted ledger when open new. (#13210)
Browse files Browse the repository at this point in the history
(cherry picked from commit 07ef923)
  • Loading branch information
Technoboy- authored and eolivelli committed Dec 13, 2021
1 parent 66b58dc commit 2055eca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ public CompactorSubscription(PersistentTopic topic, CompactedTopic compactedTopi
Map<String, Long> properties = cursor.getProperties();
if (properties.containsKey(Compactor.COMPACTED_TOPIC_LEDGER_PROPERTY)) {
long compactedLedgerId = properties.get(Compactor.COMPACTED_TOPIC_LEDGER_PROPERTY);
compactedTopic.newCompactedLedger(cursor.getMarkDeletedPosition(),
compactedLedgerId);
compactedTopic.newCompactedLedger(cursor.getMarkDeletedPosition(), compactedLedgerId)
.thenAccept(previousContext -> {
if (previousContext != null) {
compactedTopic.deleteCompactedLedger(previousContext.getLedger().getId());
}
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1873,6 +1873,8 @@ public void testCompactorSubscriptionUpdatedOnInit() throws Exception {

PersistentTopic topic = new PersistentTopic(successTopicName, ledgerMock, brokerService);
CompactedTopic compactedTopic = mock(CompactedTopic.class);
when(compactedTopic.newCompactedLedger(any(Position.class), anyLong()))
.thenReturn(CompletableFuture.completedFuture(null));
new CompactorSubscription(topic, compactedTopic, Compactor.COMPACTION_SUBSCRIPTION, cursorMock);
verify(compactedTopic, Mockito.times(1)).newCompactedLedger(position, ledgerId);
}
Expand Down

0 comments on commit 2055eca

Please sign in to comment.