Repository navigation
[pulsar-broker] Support roll-over ledgers for inactive topics #13073
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3424,4 +3424,29 @@ public void testCancellationOfScheduledTasks() throws Exception { | |
| assertTrue(timeoutTask2.isCancelled()); | ||
| assertTrue(checkLedgerRollTask2.isCancelled()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testInactiveLedgerRollOver() throws Exception { | ||
| int inactiveLedgerRollOverTimeMs = 5; | ||
| ManagedLedgerFactoryConfig factoryConf = new ManagedLedgerFactoryConfig(); | ||
| ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(metadataStore, bkc); | ||
| ManagedLedgerConfig config = new ManagedLedgerConfig(); | ||
| config.setInactiveLedgerRollOverTime(inactiveLedgerRollOverTimeMs, TimeUnit.MILLISECONDS); | ||
| ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open("rollover_inactive", config); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should cleanup resources here
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nicoloboschi
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes. fixed it. |
||
| ManagedCursor cursor = ledger.openCursor("c1"); | ||
|
|
||
| int totalAddEntries = 5; | ||
| for (int i = 0; i < totalAddEntries; i++) { | ||
| String content = "entry"; // 5 bytes | ||
| ledger.checkInactiveLedgerAndRollOver(); | ||
| ledger.addEntry(content.getBytes()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it would be interesting to see what happens in a failure scenario, when the addEntry is rejected.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure that this is an important aspect, worth to add a test case. why is it so important to you ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it marks activity if it receives a write without depending on failures or introducing any complexity about the failures. so, I don't see any specific need for that test. |
||
| Thread.sleep(inactiveLedgerRollOverTimeMs * 5); | ||
| } | ||
|
|
||
| List<LedgerInfo> ledgers = ledger.getLedgersInfoAsList(); | ||
| assertEquals(ledgers.size(), totalAddEntries); | ||
| ledger.close(); | ||
| factory.shutdown(); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2402,6 +2402,14 @@ public class ServiceConfiguration implements PulsarConfiguration { | |
| ) | ||
| private int managedLedgerOffloadPrefetchRounds = 1; | ||
|
|
||
| @FieldContext( | ||
| dynamic = true, | ||
| category = CATEGORY_STORAGE_ML, | ||
| doc = "Time to rollover ledger for inactive topic (duration without any publish on that topic). " | ||
| + "Disable rollover with value 0 (Default value 0)" | ||
| ) | ||
| private int managedLedgerInactiveLedgerRolloverTimeSeconds = 0; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minutes or seconds ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch. I missed to update doc after changing timeunit in code. I have fixed it now. |
||
|
|
||
| /**** --- Transaction config variables. --- ****/ | ||
| @FieldContext( | ||
| category = CATEGORY_TRANSACTION, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -139,6 +139,8 @@ public synchronized void updateStats( | |||||||||||||||||||||||||||||||||||||||||||||||||
| // this task: helps to activate inactive-backlog-cursors which have caught up and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // connected, also deactivate active-backlog-cursors which has backlog | ||||||||||||||||||||||||||||||||||||||||||||||||||
| topic.checkBackloggedCursors(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // check if topic is inactive and require ledger rollover | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ((PersistentTopic) topic).checkInactiveLedgers(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I can see that We already have an event loop used to delete inactive topics. The broker service initializes several inactivity related loops here: pulsar/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java Lines 522 to 545 in f97d6e5
What is your perspective on adding this check to that loop? If we don't move the loop, I think we should document somewhere that the frequency of this method is governed by
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, it doesn't depend on any feature. this background thread is being used for multiple simple topic checks such as backlogged-cursor or inactive-ledger checks. and it's internal implementation and we don't have to document it explicitly because it's just a safeguard check at the broker.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's fine if we want to leave it as is, but as it stands, the frequency of this method is determined by the broker config for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as I explained earlier, this background thread performs topic's check including stats, backlogged-cursor-check and this will be an additional one. stats is something an essential part and its frequency should be reasonable enough to handle this kind of check. I don't see any usecase for why anyone disables the stats. however, if it's a real concern then will probably create another PR to separate all topic's checks out of this dedicated thread. but that can be addressed separately and definitely can not be a blocker for this PR. |
||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if (topic instanceof NonPersistentTopic) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| tempNonPersistentTopics.add((NonPersistentTopic) topic); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should call
rollCurrentLedgerIfFullmethod which actually close the ledger and it's the same rollover procedure used for topic when they reach the max quotaThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rollCurrentLedgerIfFullcloses ledger if its full and that won't be helpful in this case because ledger is not full but ledger inactivity criteria has been triggered.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant to extract the code block inside the if