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] Handle get owned namespaces admin API in ExtensibleLoadManager #20552

Conversation

Demogorgon314
Copy link
Member

PIP: #16691

Motivation

The ExtensibleLoadManager does not handle the GetOwnedServiceUnits method and GetOwnedNamespaceStatus method.

Since the ServiceUnitStateChannel will store all the owner status, we need to filter all the other brokers when get owned service units to make the behavior the same as OwnershipCache

Modifications

  • Support GetOwnedServiceUnits method to get current broker ownership.
  • Support getOwnedNamespaces admin API.
  • When enabling ExtensibleLoadManager make sure we handled all unloading calls.

Documentation

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

@Demogorgon314 Demogorgon314 added type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages area/broker release/3.0.1 labels Jun 9, 2023
@Demogorgon314 Demogorgon314 self-assigned this Jun 9, 2023
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Jun 9, 2023
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

@@ -1103,6 +1134,10 @@ public OwnershipCache getOwnershipCache() {
}

public Set<NamespaceBundle> getOwnedServiceUnits() {
if (ExtensibleLoadManagerImpl.isLoadManagerExtensionEnabled(config)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Honestly, having all these references to a specific implementation (ExtensibleLoadManagerImpl) is a code smell.

We should rely on object oriented programming principals.
I am not going to block this patch, but I think that we are accumulating some tech debt that we will have to pay later

Copy link
Member Author

@Demogorgon314 Demogorgon314 Jun 9, 2023

Choose a reason for hiding this comment

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

Yes, we must do some refactoring in the feature... We might need to do some abstract for NamespaceService.

Copy link
Contributor

Choose a reason for hiding this comment

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

It appears that the new vs old LM logic variations in NamespaceService are more than what we originally estimated. Yes, we can define NamespaceServiceExtension extends NamespaceService.

If the community decides to only maintain the extension logic in the future(I assume this wont happen in the near future), I think we can clean the old LMlogic in NamespaceService too.

Copy link
Contributor

@heesung-sn heesung-sn left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -714,6 +734,12 @@ private void monitor() {
}
}

public NamespaceBundle getNamespaceBundle(String bundle) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit:move this to a static LoadManagerShared method.

var stateData = entry.getValue();
return stateData.state() == ServiceUnitState.Owned
&& StringUtils.isNotBlank(stateData.dstBroker())
&& stateData.dstBroker().equals(brokerRegistry.getBrokerId());
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: should we define a local var brokerId to avoid repeated registry access?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is repeated registry access will reduce performance?

Copy link
Contributor

@heesung-sn heesung-sn Jun 10, 2023

Choose a reason for hiding this comment

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

I think so. Afaik, the local variables will be likely in the CPU registers, which can be faster. brokerRegistry.getBrokerId() will need to deference, which could cause page hit/miss and stack getBrokerId() and deference again.

I am not sure if the modern java compiler optimizes this code with local var or not.

@@ -1103,6 +1134,10 @@ public OwnershipCache getOwnershipCache() {
}

public Set<NamespaceBundle> getOwnedServiceUnits() {
if (ExtensibleLoadManagerImpl.isLoadManagerExtensionEnabled(config)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It appears that the new vs old LM logic variations in NamespaceService are more than what we originally estimated. Yes, we can define NamespaceServiceExtension extends NamespaceService.

If the community decides to only maintain the extension logic in the future(I assume this wont happen in the near future), I think we can clean the old LMlogic in NamespaceService too.

@codecov-commenter
Copy link

codecov-commenter commented Jun 10, 2023

Codecov Report

Merging #20552 (7fb52e8) into master (45d882a) will increase coverage by 0.00%.
The diff coverage is 97.67%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #20552   +/-   ##
=========================================
  Coverage     72.94%   72.94%           
  Complexity    31930    31930           
=========================================
  Files          1867     1867           
  Lines        138561   138590   +29     
  Branches      15219    15222    +3     
=========================================
+ Hits         101073   101097   +24     
+ Misses        29466    29463    -3     
- Partials       8022     8030    +8     
Flag Coverage Δ
inttests 24.11% <0.00%> (-0.06%) ⬇️
systests 24.97% <6.97%> (+0.02%) ⬆️
unittests 72.23% <97.67%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
...dbalance/extensions/ExtensibleLoadManagerImpl.java 77.99% <92.30%> (-0.68%) ⬇️
...xtensions/channel/ServiceUnitStateChannelImpl.java 84.41% <100.00%> (-0.02%) ⬇️
...sar/broker/loadbalance/impl/LoadManagerShared.java 81.78% <100.00%> (+0.17%) ⬆️
...ache/pulsar/broker/namespace/NamespaceService.java 70.86% <100.00%> (+0.51%) ⬆️

... and 66 files with indirect coverage changes

*/
public Set<NamespaceBundle> getOwnedServiceUnits() {
var entrySet = serviceUnitStateChannel.getOwnershipEntrySet();
var brokerId = brokerRegistry.getBrokerId();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the var keyword necessary here?

While I don't have any objections to using the var keyword (I actually use it at work), it's worth considering the need for consistency in the codebase. As I haven't come across this usage in the project so far, it would be beneficial to reach a consensus on the usage of var.

Copy link
Contributor

Choose a reason for hiding this comment

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

"As I haven't come across this usage in the project so far"

In fact, Pulsar already has been using "var".

Copy link
Contributor

Choose a reason for hiding this comment

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

In fact, Pulsar already has been using "var".

Ah, is that so? Well, if that's the case, I will take back what I said 👍🏻 Thank you for letting me know.

But, may I ask in which class there is var usage? I also saw some in about 10 test classes, but not in production code yet. 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@Demogorgon314 thanks🙏🏽

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, we are not using "var" yet.

Copy link
Member

@mattisonchao mattisonchao Jun 12, 2023

Choose a reason for hiding this comment

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

IMO, It's ok to use var in the new features. Since we are already in the JDK17 and var will help avoid very long code causes us to have to break code into multiple lines to follow checkstyle rule.

For existing code, we should avoid using any new API&Feature to prevent getting a compile error when cherry-picking patches to previous branches.

@Technoboy- Technoboy- added this to the 3.1.0 milestone Jun 12, 2023
@Technoboy- Technoboy- merged commit bad231e into apache:master Jun 12, 2023
@Demogorgon314 Demogorgon314 deleted the Demogorgon314/handle-get-owned-namespace-status-admin-api branch June 21, 2023 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/broker cherry-picked/branch-3.0 doc-not-needed Your PR changes do not impact docs ready-to-test release/3.0.1 type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants