Repository navigation
[feat][offload] ADD offload_time_threshold policy (time-based offloading) - #17398
Conversation
|
for cmd/rest-api update offload policy, I'll create another PR to do. |
|
@hangc0276 @codelipenghui PTAL |
|
@tjiuming Please check the check-style issue |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #17398 +/- ##
=============================================
+ Coverage 34.91% 45.86% +10.94%
- Complexity 5707 17639 +11932
=============================================
Files 607 1574 +967
Lines 53396 128656 +75260
Branches 5712 14156 +8444
=============================================
+ Hits 18644 59003 +40359
- Misses 32119 63573 +31454
- Partials 2633 6080 +3447
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
Great Job @tjiuming |
| alreadyOffloadedSize += size; | ||
| } else { | ||
| if ((offloadThresholdInBytes >= 0 && sizeSummed > offloadThresholdInBytes) | ||
| || (offloadTimeThresholdMillis >= 0 && now - timestamp >= offloadTimeThresholdMillis)) { |
There was a problem hiding this comment.
The check condition is different with offloadByBytes. I suggest to keep the same.
// offload by size
sizeSummed > offloadThresholdInBytes
// offload by time
now - timestamp >= offloadTimeThresholdMillis
There was a problem hiding this comment.
I thought about this place, unlike offloadThresholdInBytes, offloadTimeThresholdMillis has certain randomness, From ledgerClosed to this place, maybe need cost 1ms, or maybe not. If we change it from now - timestamp >= offloadTimeThresholdMillis to now - timestamp > offloadTimeThresholdMillis, some tests will be failed. Or, we can delay 1ms in
private void maybeOffloadInBackground(CompletableFuture<PositionImpl> promise) {
if (config.getLedgerOffloader() == null || config.getLedgerOffloader() == NullLedgerOffloader.INSTANCE
|| config.getLedgerOffloader().getOffloadPolicies() == null) {
return;
}
final OffloadPoliciesImpl policies = config.getLedgerOffloader().getOffloadPolicies();
final long offloadThresholdInBytes =
Optional.ofNullable(policies.getManagedLedgerOffloadThresholdInBytes()).orElse(-1L);
final long offloadThresholdInSeconds =
Optional.ofNullable(policies.getManagedLedgerOffloadThresholdInSeconds()).orElse(-1L);
if (offloadThresholdInBytes >= 0 || offloadThresholdInSeconds >= 0) {
// delay 1ms here
Thread.sleep(1);
executor.executeOrdered(name,
safeRun(() -> maybeOffload(offloadThresholdInBytes, offloadThresholdInSeconds, promise)));
}
}
There was a problem hiding this comment.
Why some tests will be failed?
There was a problem hiding this comment.
@hangc0276
Say, in the OffloadPrefixTest, there is a test called public void testAutoTriggerOffload(Long sizeThreshold, Long timeThreshold). And if I set sizeThreshold = null, and timeThreshold = 0.
Each ledger has 10 entries, and I'll write 35 entries into the topic. So, there will 4 ledgers, right? Say, the four ledgers' id are [1,2,3,4]. [1,2,3] reached the 10 entries threshold, and it closed. all the 3 ledgers will be offloaded right? it is the expected behaviour.
However, the result is actually random. [3] ledger maybe offloaded, or maybe not.
In the ledgerClosed() method, we set the LedgerInfo timestamp
LedgerInfo info = LedgerInfo.newBuilder().setLedgerId(lh.getId()).setEntries(entriesInLedger)
.setSize(lh.getLength()).setTimestamp(clock.millis()).build();
ledgers.put(lh.getId(), info);
and trigger offload
maybeOffloadInBackground(NULL_OFFLOAD_PROMISE);
and maybeOffloadInBackground will goes to
private void maybeOffload(long offloadThresholdInBytes, long offloadThresholdInSeconds,
CompletableFuture<PositionImpl> finalPromise) {
// ignore
for (Map.Entry<Long, LedgerInfo> e : ledgers.descendingMap().entrySet()) {
// ignore...
final long timestamp = info.getTimestamp();
final long now = System.currentTimeMillis();
sizeSummed += size;
final boolean alreadyOffloaded = info.hasOffloadContext() && info.getOffloadContext().getComplete();
if (alreadyOffloaded) {
alreadyOffloadedSize += size;
} else {
if ((offloadThresholdInBytes >= 0 && sizeSummed > offloadThresholdInBytes)
|| (offloadTimeThresholdMillis >= 0 && now - timestamp >= offloadTimeThresholdMillis)) {
toOffloadSize += size;
toOffload.addFirst(info);
}
}
}
// ignore
In the process from
LedgerInfo info = LedgerInfo.newBuilder().setLedgerId(lh.getId()).setEntries(entriesInLedger)
.setSize(lh.getLength()).setTimestamp(clock.millis()).build()
to
if ((offloadThresholdInBytes >= 0 && sizeSummed > offloadThresholdInBytes)
|| (offloadTimeThresholdMillis >= 0 && now - timestamp >= offloadTimeThresholdMillis)) {
toOffloadSize += size;
toOffload.addFirst(info);
}
, it may costs more than 1ms, or maybe not. So the last ledger maybe will offloaded, or maybe not.
This brings uncertainty, So I now - timestamp >= offloadTimeThresholdMillis here to eliminate this uncertainty.
|
Hi @tjiuming, besides configurations (already included in this PR), did you plan to add more information to Pulsar docs about this feature? |
Fixes #17361
Motivation
Add auto trigger offload by time policy.
Documentation
Check the box below or label this PR directly.
Need to update docs?
doc-required(Your PR needs to update docs and you will update later)
doc-not-needed(Please explain why)
doc(Your PR contains doc changes)
doc-complete(Docs have been already added)