Skip to content
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

[improve][broker] PIP-192: Implement extensible load manager #19102

Conversation

Demogorgon314
Copy link
Member

PIP: #16691

Motivation

Implement extensible load manager.

Modifications

For the PIP-192, this PR adds ExtensibleLoadManagerImpl and unit tests.

This PR also changes:

  1. Added CompletableFuture<Optional<LookupResult>> findBrokerServiceUrl( Optional<ServiceUnitId> topic, ServiceUnitId bundle) to LoadManager interface.
  2. Added CompletableFuture<Boolean> checkOwnershipAsync(Optional<ServiceUnitId> topic, ServiceUnitId bundle) to LoadManager interface.
  3. Change CompletableFuture<String> getOwnerAsync(String serviceUnit) to CompletableFuture<Optional<String>> getOwnerAsync(String serviceUnit) to unify the result.

Documentation

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

Matching PR in forked repository

PR in forked repository: Demogorgon314#10

@Demogorgon314 Demogorgon314 self-assigned this Dec 29, 2022
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Dec 29, 2022
@Demogorgon314 Demogorgon314 force-pushed the Demogorgon314/Implement_extensible_load_manager branch from 5f44f74 to acc4788 Compare December 29, 2022 08:06
@Demogorgon314 Demogorgon314 marked this pull request as ready for review December 29, 2022 08:12
@Demogorgon314 Demogorgon314 force-pushed the Demogorgon314/Implement_extensible_load_manager branch from acc4788 to d48b52a Compare December 29, 2022 08:20
public CompletableFuture<Optional<LookupResult>> getBrokerServiceUrlAsync(TopicName topic, LookupOptions options) {
long startTime = System.nanoTime();

CompletableFuture<Optional<LookupResult>> future = getBundleAsync(topic)
.thenCompose(bundle -> findBrokerServiceUrl(bundle, options));
.thenCompose(bundle -> {
if (isExtensibleLoadManager()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I was working on these NamespaceService change as per pluggable new broker load balancer work.

Do you want to keep this change here in this PR?

I think we need to add NamespaceService unit tests to track this variation.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add the units test to cover enable the extensible load manager case.

@Demogorgon314 Demogorgon314 force-pushed the Demogorgon314/Implement_extensible_load_manager branch from e9a9959 to 3d54c15 Compare December 30, 2022 03:53
@@ -55,6 +55,7 @@
import org.apache.pulsar.broker.loadbalance.LeaderElectionService;
import org.apache.pulsar.broker.loadbalance.LoadManager;
import org.apache.pulsar.broker.loadbalance.ResourceUnit;
import org.apache.pulsar.broker.loadbalance.extensions.ExtensibleLoadManagerImpl;
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be great to add unit tests in NamespaceServiceTest for these if-else variations. (assert if the new/old load manager is called for these Namespace public funcs).

Or, please add a TODO comment if we want to add such tests later.

if (ExtensibleLoadManagerImpl.isLoadManagerExtensionEnabled(config)) {
// new logic
} else {
// old logic
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I'll add it later.

Copy link
Member Author

Choose a reason for hiding this comment

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

After thinking about it, I guess adding tests later might be better since some methods of NamespaceService still need to add new logic when using extensible load manager.

Copy link
Contributor

@heesung-sn heesung-sn Jan 10, 2023

Choose a reason for hiding this comment

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

nit: It would be great if we can have a separate PR to integrate ExtensibleLoadManagerImpl into the existing code(to the NamespaceService and PulsarService). This PR could be ExtensibleLoadManagerImpl (and other dependent changes) only.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to split it into two PRs, but ExtensibleLoadManagerImpl test dependency topic lookup because we are using TableView in ServiceUnitStateChannel, so I have to implement the load manager function.

@Demogorgon314 Demogorgon314 force-pushed the Demogorgon314/Implement_extensible_load_manager branch from ee5785f to cf0ad90 Compare January 4, 2023 10:07
@@ -55,6 +55,7 @@
import org.apache.pulsar.broker.loadbalance.LeaderElectionService;
import org.apache.pulsar.broker.loadbalance.LoadManager;
import org.apache.pulsar.broker.loadbalance.ResourceUnit;
import org.apache.pulsar.broker.loadbalance.extensions.ExtensibleLoadManagerImpl;
Copy link
Contributor

@heesung-sn heesung-sn Jan 10, 2023

Choose a reason for hiding this comment

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

nit: It would be great if we can have a separate PR to integrate ExtensibleLoadManagerImpl into the existing code(to the NamespaceService and PulsarService). This PR could be ExtensibleLoadManagerImpl (and other dependent changes) only.

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

+1

@Demogorgon314 Demogorgon314 force-pushed the Demogorgon314/Implement_extensible_load_manager branch from 6df4f47 to 3765839 Compare January 17, 2023 09:20
@Demogorgon314 Demogorgon314 requested a review from shibd January 19, 2023 01:59
@codelipenghui codelipenghui added this to the 3.0.0 milestone Jan 31, 2023
@@ -0,0 +1,222 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you remove the BrokerRegistryImpl related code in this PR since I see they were added in #18810?

Copy link
Contributor

@gaoran10 gaoran10 left a comment

Choose a reason for hiding this comment

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

Great work! left some trivial comments.

@@ -0,0 +1,222 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

+1, we'd better merge the PR #18810 first.

…nager

# Conflicts:
#	pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/BrokerRegistry.java
#	pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/BrokerRegistryImpl.java
#	pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/extensions/BrokerRegistryTest.java
@codecov-commenter
Copy link

codecov-commenter commented Feb 3, 2023

Codecov Report

Attention: Patch coverage is 8.69565% with 168 lines in your changes missing coverage. Please review.

Project coverage is 62.49%. Comparing base (60d8e64) to head (3684d5c).
Report is 1733 commits behind head on master.

Files with missing lines Patch % Lines
...dbalance/extensions/ExtensibleLoadManagerImpl.java 7.54% 98 Missing ⚠️
...lance/extensions/ExtensibleLoadManagerWrapper.java 0.00% 28 Missing ⚠️
...ache/pulsar/broker/namespace/NamespaceService.java 23.07% 14 Missing and 6 partials ⚠️
.../apache/pulsar/broker/loadbalance/LoadManager.java 0.00% 6 Missing ⚠️
...loadbalance/extensions/LoadManagerContextImpl.java 0.00% 6 Missing ⚠️
...xtensions/channel/ServiceUnitStateChannelImpl.java 0.00% 6 Missing ⚠️
...n/java/org/apache/pulsar/broker/PulsarService.java 33.33% 2 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #19102      +/-   ##
============================================
- Coverage     63.24%   62.49%   -0.76%     
+ Complexity    25936    25660     -276     
============================================
  Files          1823     1829       +6     
  Lines        133338   133915     +577     
  Branches      14677    14732      +55     
============================================
- Hits          84330    83690     -640     
- Misses        41290    42565    +1275     
+ Partials       7718     7660      -58     
Flag Coverage Δ
inttests 24.85% <8.69%> (-0.04%) ⬇️
systests 25.68% <8.69%> (+0.01%) ⬆️
unittests 59.72% <8.69%> (-0.91%) ⬇️

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

Files with missing lines Coverage Δ
...ensions/strategy/LeastResourceUsageWithWeight.java 0.00% <ø> (ø)
...n/java/org/apache/pulsar/broker/PulsarService.java 73.87% <33.33%> (+1.10%) ⬆️
.../apache/pulsar/broker/loadbalance/LoadManager.java 58.33% <0.00%> (-19.45%) ⬇️
...loadbalance/extensions/LoadManagerContextImpl.java 0.00% <0.00%> (ø)
...xtensions/channel/ServiceUnitStateChannelImpl.java 0.96% <0.00%> (-0.01%) ⬇️
...ache/pulsar/broker/namespace/NamespaceService.java 59.14% <23.07%> (-2.06%) ⬇️
...lance/extensions/ExtensibleLoadManagerWrapper.java 0.00% <0.00%> (ø)
...dbalance/extensions/ExtensibleLoadManagerImpl.java 7.54% <7.54%> (ø)

... and 158 files with indirect coverage changes

@Demogorgon314 Demogorgon314 merged commit c3126c6 into apache:master Feb 3, 2023
@lhotari
Copy link
Member

lhotari commented Apr 4, 2023

This PR introduced a new flaky test #20007 . @Demogorgon314 Do you have a chance to fix that?

if (ExtensibleLoadManagerImpl.isLoadManagerExtensionEnabled(config)) {
return loadManager.get().findBrokerServiceUrl(Optional.of(topic), bundle);
} else {
// TODO: Add unit tests cover it.
Copy link
Contributor

Choose a reason for hiding this comment

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

My personal habit is to never add those TODOs - they never get done.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for your advice. We should refactor the NamespaceService instead of adding so many if else here. We can remove this to-do when we're doing refactoring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

9 participants