Skip to content

[improve][broker] The interval of scheduled task should be greater than 0 - #18728

Merged
eolivelli merged 1 commit into
apache:masterfrom
yuruguo:interval_is_greater_than_0
Dec 4, 2022
Merged

eolivelli merged 1 commit into
apache:masterfrom
yuruguo:interval_is_greater_than_0

Conversation

@yuruguo

@yuruguo yuruguo commented Dec 3, 2022 •

Copy link
Copy Markdown
Contributor

Motivation

Some scheduled tasks will be started when the broker starting, including:

        // start other housekeeping functions
        this.startStatsUpdater(
                serviceConfig.getStatsUpdateInitialDelayInSecs(),
                serviceConfig.getStatsUpdateFrequencyInSecs());
        this.startInactivityMonitor();
        this.startMessageExpiryMonitor();
        this.startCompactionMonitor();
        this.startConsumedLedgersMonitor();
        this.startBacklogQuotaChecker();
        this.startCheckReplicationPolicies();
        this.startDeduplicationSnapshotMonitor();

But the interval of these scheduled tasks should be greater than 0, otherwise an exception will be reported during startup, as below:

ERROR org.apache.pulsar.broker.PulsarService - Failed to start Pulsar service: null
java.lang.IllegalArgumentException: null
        at java.util.concurrent.ScheduledThreadPoolExecutor.scheduleAtFixedRate(ScheduledThreadPoolExecutor.java:623) ~[?:?]
        at java.util.concurrent.Executors$DelegatedScheduledExecutorService.scheduleAtFixedRate(Executors.java:819) ~[?:?]
        at org.apache.pulsar.broker.service.BrokerService.startInactivityMonitor(BrokerService.java:568) ~[pulsar-broker.jar:2.11.0-SNAPSHOT]
        at org.apache.pulsar.broker.service.BrokerService.start(BrokerService.java:534) ~[pulsar-broker.jar:2.11.0-SNAPSHOT]
        at org.apache.pulsar.broker.PulsarService.start(PulsarService.java:784) ~[pulsar-broker.jar:2.11.0-SNAPSHOT]
        at org.apache.pulsar.PulsarStandalone.start(PulsarStandalone.java:348) ~[pulsar-broker.jar:2.11.0-SNAPSHOT]
        at org.apache.pulsar.PulsarStandaloneStarter.main(PulsarStandaloneStarter.java:141) ~[pulsar-broker.jar:2.11.0-SNAPSHOT]

Therefore, it is necessary to judge whether the interval is greater than 0 and give clear information, as below:

java.lang.IllegalArgumentException: brokerDeleteInactiveTopicsFrequencySeconds value -1 doesn't fit in given range (1, 9223372036854775807)
	at org.apache.pulsar.common.configuration.PulsarConfigurationLoader.isComplete(PulsarConfigurationLoader.java:153)

Modifications

  • check interval > 0 and give clear information

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository:

@github-actions github-actions Bot added the doc-not-needed Your PR changes do not impact docs label Dec 3, 2022
@yuruguo yuruguo self-assigned this Dec 3, 2022
@yuruguo yuruguo added this to the 2.12.0 milestone Dec 3, 2022
@codecov-commenter

codecov-commenter commented Dec 3, 2022 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 48.01%. Comparing base (b579bb8) to head (9e8b896).
⚠️ Report is 3242 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #18728      +/-   ##
============================================
+ Coverage     47.51%   48.01%   +0.49%     
- Complexity    10520    10664     +144     
============================================
  Files           698      703       +5     
  Lines         68079    68795     +716     
  Branches       7280     7373      +93     
============================================
+ Hits          32351    33033     +682     
+ Misses        32151    32062      -89     
- Partials       3577     3700     +123     
Flag Coverage Δ
unittests 48.01% <ø> (+0.49%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 100 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.

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

This patch is basically adding the support for disabling some internal activities in the broker.
This is quite dangerous and can lead to unexpected behavior.

I would prefer to let the broker fail with meaningful errors

@yuruguo
yuruguo force-pushed the interval_is_greater_than_0 branch from 9148a13 to 9e8b896 Compare December 4, 2022 05:05
@yuruguo

yuruguo commented Dec 4, 2022 •

Copy link
Copy Markdown
Contributor Author

I would prefer to let the broker fail with meaningful errors

+1

The minValue = 1 has been added for verification on the interval field, similar to other interval fields:

@FieldContext(minValue = 1,
category = CATEGORY_STORAGE_ML,
doc = "How frequently to refresh the stats. (seconds). Default is 60 seconds")
private int managedLedgerStatsPeriodSeconds = 60;

Then a clear message will be given and the broker will exit If interval < 0.

@yuruguo yuruguo changed the title [fix][broker] The interval of scheduled task should be greater than 0 [improve][broker] The interval of scheduled task should be greater than 0 Dec 4, 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.

I didn't know that we had declarative validation!

Good work

Lgtm

@eolivelli
eolivelli merged commit 31daf51 into apache:master Dec 4, 2022
lifepuzzlefun pushed a commit to lifepuzzlefun/pulsar that referenced this pull request Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/broker doc-not-needed Your PR changes do not impact docs ready-to-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants