Skip to content

[feat][offload] ADD offload_time_threshold policy (time-based offloading) - #17398

Merged
codelipenghui merged 25 commits into
apache:masterfrom
tjiuming:dev/offloader_trigger_time
Oct 24, 2022
Merged

codelipenghui merged 25 commits into
apache:masterfrom
tjiuming:dev/offloader_trigger_time

Conversation

@tjiuming

@tjiuming tjiuming commented Sep 1, 2022

Copy link
Copy Markdown
Contributor

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)

@tjiuming

tjiuming commented Sep 1, 2022

Copy link
Copy Markdown
Contributor Author

for cmd/rest-api update offload policy, I'll create another PR to do.

@github-actions github-actions Bot added the doc-required Your PR changes impact docs and you will update later. label Sep 1, 2022
@tjiuming

tjiuming commented Sep 6, 2022

Copy link
Copy Markdown
Contributor Author

@hangc0276 @codelipenghui PTAL

@zymap zymap added type/feature The PR added a new feature or issue requested a new feature area/tieredstorage labels Sep 7, 2022
@zymap zymap added this to the 2.12.0 milestone Sep 7, 2022

@eolivelli eolivelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@eolivelli eolivelli changed the title [feat][tiered-storage] ADD offload_time_threshold policy [feat][tiered-storage] ADD offload_time_threshold policy (time-based offloading) Oct 19, 2022
@codelipenghui

Copy link
Copy Markdown
Contributor

@tjiuming Please check the check-style issue

@tjiuming tjiuming changed the title [feat][tiered-storage] ADD offload_time_threshold policy (time-based offloading) [feat][storage] ADD offload_time_threshold policy (time-based offloading) Oct 20, 2022
@tjiuming tjiuming changed the title [feat][storage] ADD offload_time_threshold policy (time-based offloading) [feat][storage][offload] ADD offload_time_threshold policy (time-based offloading) Oct 20, 2022
@tjiuming tjiuming changed the title [feat][storage][offload] ADD offload_time_threshold policy (time-based offloading) [offload] ADD offload_time_threshold policy (time-based offloading) Oct 20, 2022
@tjiuming tjiuming changed the title [offload] ADD offload_time_threshold policy (time-based offloading) [feat][offload] ADD offload_time_threshold policy (time-based offloading) Oct 20, 2022
@codecov-commenter

codecov-commenter commented Oct 20, 2022 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.27273% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.86%. Comparing base (6c65ca0) to head (4c84416).
⚠️ Report is 3530 commits behind head on master.

Files with missing lines Patch % Lines
...che/bookkeeper/mledger/impl/ManagedLedgerImpl.java 82.45% 6 Missing and 4 partials ⚠️
...lsar/common/policies/data/OffloadPoliciesImpl.java 42.85% 4 Missing ⚠️
...org/apache/pulsar/broker/ServiceConfiguration.java 50.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              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     
Flag Coverage Δ
unittests 45.86% <77.27%> (+10.94%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...org/apache/pulsar/broker/ServiceConfiguration.java 52.06% <50.00%> (ø)
...lsar/common/policies/data/OffloadPoliciesImpl.java 57.00% <42.85%> (ø)
...che/bookkeeper/mledger/impl/ManagedLedgerImpl.java 71.26% <82.45%> (ø)

... and 1114 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codelipenghui
codelipenghui merged commit bdbbb1e into apache:master Oct 24, 2022
@codelipenghui

Copy link
Copy Markdown
Contributor

Great Job @tjiuming

Comment thread conf/broker.conf Resolved
alreadyOffloadedSize += size;
} else {
if ((offloadThresholdInBytes >= 0 && sizeSummed > offloadThresholdInBytes)
|| (offloadTimeThresholdMillis >= 0 && now - timestamp >= offloadTimeThresholdMillis)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check condition is different with offloadByBytes. I suggest to keep the same.

// offload by size
sizeSummed > offloadThresholdInBytes

// offload by time
now - timestamp >= offloadTimeThresholdMillis

@tjiuming tjiuming Oct 26, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)));
        }
    }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why some tests will be failed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

@momo-jun

Copy link
Copy Markdown
Contributor

Hi @tjiuming, besides configurations (already included in this PR), did you plan to add more information to Pulsar docs about this feature?

@tjiuming

Copy link
Copy Markdown
Contributor Author

Hi @tjiuming, besides configurations (already included in this PR), did you plan to add more information to Pulsar docs about this feature?

@momo-jun I'll open a doc PR after the issue fixed and RestAPI CLI PR merged

@tjiuming
tjiuming deleted the dev/offloader_trigger_time branch November 1, 2022 17:38
@tjiuming
tjiuming restored the dev/offloader_trigger_time branch November 1, 2022 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/tieredstorage doc-required Your PR changes impact docs and you will update later. ready-to-test type/feature The PR added a new feature or issue requested a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] Automatic trigger offloading by time

8 participants