Repository navigation
[pulsar-broker] Support roll-over ledgers for inactive topics - #13073
Conversation
|
@rdhabalia:Thanks for your contribution. For this PR, do we need to update docs? |
There was a problem hiding this comment.
@rdhabalia - can you help me understand how this feature is different from the one associated with managedLedgerMaxLedgerRolloverTimeMinutes? The managed ledger uses max rollover time to scheduled a task that will close the ledger once that much time has passed (assuming the rollover criteria for size or number of entries have not yet been met). I think lowering that max time achieves the behavior proposed in this PR.
EDIT: I took a second look and can see how inactivity is different from the max time for the ledger to be open. However, this feels like an issue that the bookkeeper client should solve. A timeout doesn't completely remove the risk and, if I understand the risk correctly, it seems like the inactivity timeout would have to be pretty low to be effective.
|
|
||
| # Time to rollover ledger for inactive topic (duration without any publish on that topic) | ||
| # Disable rollover with value 0 (Default value 0) | ||
| managedLedgerInActiveLedgerRolloverTimeMinutes=0 |
There was a problem hiding this comment.
Nit: inactive is used as a single word here. I think the casing should be Inactive here and in the rest of the PR.
No, both these configs are made to solve two different problems.
Yes, that problem should be handled at bookkeeper client but broker can have this capability to not only solve this particular problem but allow user to control life span of inactive topic ledgers. |
| long currentTimeMs = System.currentTimeMillis(); | ||
| if (inactiveLedgerRollOverTimeMs > 0 && currentTimeMs > (lastAddEntryTimeMs + inactiveLedgerRollOverTimeMs)) { | ||
| log.info("[{}| Closing inactive ledger, last-add entry {}", name, lastAddEntryTimeMs); | ||
| ledgerClosed(currentLedger); |
There was a problem hiding this comment.
I think we should call rollCurrentLedgerIfFull method which actually close the ledger and it's the same rollover procedure used for topic when they reach the max quota
There was a problem hiding this comment.
rollCurrentLedgerIfFull closes 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.
I meant to extract the code block inside the if
| // Jump to specific thread to avoid contention from writers writing from different threads | ||
| executor.executeOrdered(name, safeRun(() -> { | ||
| OpAddEntry addOperation = OpAddEntry.createNoRetainBuffer(this, buffer, callback, ctx); | ||
| checkInactiveLedgerAndRollOver(lastAddEntryTimeMs); |
There was a problem hiding this comment.
should we wrap also the internalAsyncAddEntry at line 724?
https://github.com/apache/pulsar/pull/13073/files#diff-f6a849bd8fdb782ef6c17a2e07a2c54c3dc7d1655c00ec3546d5f3b3fc61e970L712-R732
There was a problem hiding this comment.
yes. we can move it to avoid adding at the caller method.
| private void checkInactiveLedgerAndRollOver(final long lastAddEntryTimeMs) { | ||
| long currentTimeMs = System.currentTimeMillis(); | ||
| if (inactiveLedgerRollOverTimeMs > 0 && currentTimeMs > (lastAddEntryTimeMs + inactiveLedgerRollOverTimeMs)) { | ||
| log.info("[{}| Closing inactive ledger, last-add entry {}", name, lastAddEntryTimeMs); |
There was a problem hiding this comment.
typo, use ] instead of |
| ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(metadataStore, bkc); | ||
| ManagedLedgerConfig config = new ManagedLedgerConfig(); | ||
| config.setInactiveLedgerRollOverTime(inactiveLedgerRollOverTimeMs, TimeUnit.MILLISECONDS); | ||
| ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open("rollover_inactive", config); |
There was a problem hiding this comment.
we should cleanup resources here
There was a problem hiding this comment.
@nicoloboschi
This is the "style" of this file, it would be better to fix the whole file, but probably in a follow up patch.
| int totalAddEntries = 5; | ||
| for (int i = 0; i < totalAddEntries; i++) { | ||
| String content = "entry"; // 5 bytes | ||
| ledger.addEntry(content.getBytes()); |
There was a problem hiding this comment.
it would be interesting to see what happens in a failure scenario, when the addEntry is rejected.
From your implementation we consider the topic active even if a write fails. it makes sense to me. just asking to add a unit test for that
There was a problem hiding this comment.
I am not sure that this is an important aspect, worth to add a test case.
why is it so important to you ?
if a write fails the ledger will be rolled over in any case
There was a problem hiding this comment.
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.
| 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; |
There was a problem hiding this comment.
minutes or seconds ?
in conf/broker.conf and the doc you set minutes instead of seconds
There was a problem hiding this comment.
good catch. I missed to update doc after changing timeunit in code. I have fixed it now.
eolivelli
left a comment
There was a problem hiding this comment.
@rdhabalia it seems to me that this is some kind of workaround to a BookKeeper bug, is this correct ?
Will upgrading to latest BK help ?
We are going to cut a release of BK soon.
I am not sure we need this change if it is only reducing the risk of data loss.
btw rolling inactive ledgers may have some benefit as they will be move to tier-2 and so I am fine with this change.
+1 (please fix the comments reported by @nicoloboschi, there is a discrepancy between Seconds vs Minutes)
|
@rdhabalia - thank you for your explanation. |
michaeljmarshall
left a comment
There was a problem hiding this comment.
I think it makes sense close out inactive ledgers. I wonder if we should check for inactivity in a different way though.
| @FieldContext( | ||
| dynamic = true, | ||
| category = CATEGORY_STORAGE_ML, | ||
| doc = "Time to rollover ledger for inactive topic (duration without any publish on that topic)." |
There was a problem hiding this comment.
| doc = "Time to rollover ledger for inactive topic (duration without any publish on that topic)." | |
| doc = "Time to rollover ledger for inactive topic (duration without any publish on that topic). " |
| return; | ||
| } | ||
| // check if ledger can be closed due to inactivity | ||
| checkInactiveLedgerAndRollOver(lastAddEntryTimeMs); |
There was a problem hiding this comment.
The implementation relies on messages to trigger ledger closure due to inactivity. While it might be a slightly heavier solution, would it make more sense to have a single scheduled task that runs in the broker service to check for inactive ledgers? Otherwise, a ledger that stops receiving messages will not close until the managedLedgerMaxLedgerRolloverTimeMinutes has passed.
There was a problem hiding this comment.
hmm.. actually lazy check should be enough because eventually ledger will be closed if topic in unloaded, broker restarts or topic receives a new write and that will protect topic from the issue. However, adding scheduled task will not have much harm except it might repetitive close empty ledger but might give certainty to ledger age.
I have made the change and moved check to scheduled task.
6f5b84b to
33599f2
Compare
c2d2e42 to
9eaa882
Compare
|
/pulsarbot run-failure-checks |
e4648b7 to
3c2b844
Compare
|
@michaeljmarshall PTAL |
|
I plan to review this later tonight. Sorry for the delay @rdhabalia |
michaeljmarshall
left a comment
There was a problem hiding this comment.
@rdhabalia - this looks great to me. I have one question about where we schedule the call to check for inactive ledgers. Otherwise, I think we should be good to go.
| // connected, also deactivate active-backlog-cursors which has backlog | ||
| topic.checkBackloggedCursors(); | ||
| // check if topic is inactive and require ledger rollover | ||
| ((PersistentTopic) topic).checkInactiveLedgers(); |
There was a problem hiding this comment.
Nit: I can see that topic.checkBackloaggedCursors() here too, but I wonder if this implementation tightly couples two distinct features. I doubt that someone would turn off the stats feature, but if they did, they'd lose this feature.
We already have an event loop used to delete inactive topics. The broker service initializes several inactivity related loops here:
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 statsUpdateFrequencyInSecs.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 statsUpdateFrequencyInSecs. In my view, that is unexpected coupling.
There was a problem hiding this comment.
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.
|
@rdhabalia Please check @michaeljmarshall's comment and resolve the conflicts |
|
@michaeljmarshall please unblock the PR. |
|
@rdhabalia - do you have a reply for my comment here #13073 (comment)? |
|
@michaeljmarshall yes, I have replied it. unnecessary blocking PR causes delay in feature and releases. |
change inactiveLedgerRollOverTimeMs config address comments: timeunit + logging + moving marking at internal method make inactive-ledger check task scheduled
michaeljmarshall
left a comment
There was a problem hiding this comment.
@rdhabalia - I did not intend to block your PR--I asked what I believe was a legitimate question.
…#13073) change inactiveLedgerRollOverTimeMs config address comments: timeunit + logging + moving marking at internal method make inactive-ledger check task scheduled
Motivation
we need the support of ledger roll-over for inactive topics to prevent data-loss. It happens when Inactive topics that do not have publish for a long time and the current ledger segment ensemble bookies are replaced by replicator when ensemble bookies went into maintenance mode. In this scenario, there is a chance of data loss and rolling over such ledgers prevents data loss.
For example:
1000with bookieb1andb21000has one entry but the broker is kept writing to b1 and b2 bookies which can cause the data loss.Bookie PR#2616 can be helpful in this scenario but rolling over inactive ledger helps to user who are doing bookie replacement/maintenance more frequent to avoid kind of data loss.
Modification
managedLedgerInActiveLedgerRolloverTimeMinutesto enable rollover of inactive ledgers (by default it will be 0)Result
this feature helps in case of inactive topics which write to replaced bookies during any maintenance and helps to avoid data-loss in that situation.