Visitar URL original
[improve][broker] PIP-192 Added ServiceUnitStateChannel interface by heesung-sohn · Pull Request #18079 · apache/pulsar · GitHub
Skip to content

[improve][broker] PIP-192 Added ServiceUnitStateChannel interface - #18079

Merged
codelipenghui merged 5 commits into
apache:masterfrom
heesung-sohn:pip-192
Nov 14, 2022
Merged

codelipenghui merged 5 commits into
apache:masterfrom
heesung-sohn:pip-192

Conversation

@heesung-sohn

@heesung-sohn heesung-sohn commented Oct 18, 2022 •

Copy link
Copy Markdown
Contributor

Fixes #xyz

Master Issue: #16691

Motivation

We will start raising PRs to implement PIP-192, #16691

Modifications

The PR adds base classes for the new broker load balance project and does not integrate with the existing load balance logic --this PR should not impact the existing broker load balance behavior.

For the pip-192 project, this PR

  • defines the classes under org.apache.pulsar.broker.loadbalance.extensions package.
  • defines this ServiceUnitStateChannel public interface and its expected behaviors.
  • defines ServiceUnitState and ServiceUnitStateData data classes.
  • defines Split and Unload data classes.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • *Added unit tests for the new classes.

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • Anything that affects deployment

Documentation

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

We will have separate PRs to update the Doc later.

Matching PR in forked repository

PR in forked repository: heesung-sohn#11

@github-actions github-actions Bot added the doc-not-needed Your PR changes do not impact docs label Oct 18, 2022
@Demogorgon314 Demogorgon314 added type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages type/feature The PR added a new feature or issue requested a new feature and removed type/feature The PR added a new feature or issue requested a new feature labels Oct 18, 2022

@tisonkun tisonkun left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contribution @heesung-sn! Comments inline.

Since we turn on the semantic PR title checks, it can edit the PR title as: [improve][broker] PIP-192 Added ServiceUnitStateChannel interface

Comment on lines +30 to +38
@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class ServiceUnitStateData {
private ServiceUnitState state;
private String broker;
private String sourceBroker;
private long timestamp;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. @Data already infers @ToString.
  2. Since the broker JDK version is upgraded to 17, do you think of using record class to define data models?
  3. Are these field intended to be mutable?

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.

Updated to record classes.

assertEquals(data1.getState(), Owned);
assertEquals(data1.getBroker(), "A");
assertNull(data1.getSourceBroker());
assertTrue(data1.getTimestamp() > 0);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can use assertj's assertion for better error message:

import static org.assertj.core.api.Assertions.assertThat;

assertThat(data1.getTimestamp()).isGreaterThan(0);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto other assertions.

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.

Updated.


Splitting; // the service unit(e.g. bundle) is in the process of splitting.
private static Map<ServiceUnitState, Set<ServiceUnitState>> validTransitions = new HashMap<>() {{
put(null, new HashSet<>() {{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shall we define a state Free/NotOwned over null? Then we can avoid handling business nulls.

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.

Updated.


Splitting; // the service unit(e.g. bundle) is in the process of splitting.
private static Map<ServiceUnitState, Set<ServiceUnitState>> validTransitions = new HashMap<>() {{
put(null, new HashSet<>() {{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd prefer immutable sets over HashSet here. For example, Set.of(...).

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.

Updated.

@heesung-sohn heesung-sohn changed the title [improve][load-balance][pip-192] Added ServiceUnitStateChannel interface [improve][broker] PIP-192 Added ServiceUnitStateChannel interface Oct 18, 2022

@tisonkun tisonkun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks for your contribution!

cc @codelipenghui @Jason918 @Demogorgon314 @eolivelli

@tisonkun

Copy link
Copy Markdown
Member

/pulsarbot run-failure-checks

@codecov-commenter

codecov-commenter commented Oct 18, 2022 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.05%. Comparing base (b31c5a6) to head (4593988).
⚠️ Report is 3347 commits behind head on master.

Files with missing lines Patch % Lines
...adbalance/extensions/channel/ServiceUnitState.java 0.00% 14 Missing ⚠️
...lance/extensions/channel/ServiceUnitStateData.java 0.00% 9 Missing ⚠️
...r/broker/loadbalance/extensions/models/Unload.java 0.00% 7 Missing ⚠️
...ar/broker/loadbalance/extensions/models/Split.java 0.00% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #18079      +/-   ##
============================================
- Coverage     46.98%   45.05%   -1.94%     
- Complexity    10343    10611     +268     
============================================
  Files           692      756      +64     
  Lines         67766    72557    +4791     
  Branches       7259     7790     +531     
============================================
+ Hits          31842    32689     +847     
- Misses        32344    36204    +3860     
- Partials       3580     3664      +84     
Flag Coverage Δ
unittests 45.05% <0.00%> (-1.94%) ⬇️

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

Files with missing lines Coverage Δ
...ar/broker/loadbalance/extensions/models/Split.java 0.00% <0.00%> (ø)
...r/broker/loadbalance/extensions/models/Unload.java 0.00% <0.00%> (ø)
...lance/extensions/channel/ServiceUnitStateData.java 0.00% <0.00%> (ø)
...adbalance/extensions/channel/ServiceUnitState.java 0.00% <0.00%> (ø)

... and 112 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.

@tisonkun

Copy link
Copy Markdown
Member

/pulsarbot run-failure-checks

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

@heesung-sohn

Copy link
Copy Markdown
Contributor Author

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

Overall LGTM.
My only concern is that can we just use "bundle" instead of introducing the concept "ServiceUnit". It's confusing and a bit of over design to me.
I'm aware that we already have some "service unit" in current codebase. It's already confusing when I first saw that, so can we unify or simplify the concept in this PIP.

* │ │ discard(parent)│ │
* └───────────┘ └──────────┘
*/
public enum ServiceUnitState {

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.

Is this ServiceUnit the same as bundle for now and in the foreseeable future?

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 would like to keep open the door to having also a single topic (partition) and not only a "bundle"

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 see two conflicting comments here.

The intention is to keep this interface open for other service units(topic, etc). But the initial target service units will be bundles only.

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 intention is to keep this interface open for other service units(topic, etc). But the initial target service units will be bundles only.

Does support for other "service units" included in PIP-192?

Both is fine for me, as long as we don't mixing them up. If we stick to service unit, so there won't be any 'bundle' appear in load balance module unless it's some specific implementation, right?

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.

For pip-192, no, it will be bundle only.

Sure, we can stick to "serviceUnit" for var and func names.

/**
* Defines the information required for a bundle split.
*/
public record Split(String bundle, String sourceBroker, Map<String, Optional<String>> splitBundleToDestBroker) {

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.

It's confusing that we use "bundle" here, but use "serviceUnit" in Unload.

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.

+1 to serviceUnit

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.

updated.

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

create work
I left some comments, please take a look

/**
* Defines the information required for a bundle split.
*/
public record Split(String bundle, String sourceBroker, Map<String, Optional<String>> splitBundleToDestBroker) {

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.

+1 to serviceUnit

/**
* Defines the information required to unload or transfer a service unit(e.g. bundle).
*/
public record Unload(String sourceBroker, String serviceUnit, Optional<String> destBroker) {

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 am not sure that using "record" is the best choice here.

IIUC it is not possible to add new components to a record without breaking compatibility.

Can you please confirm that this class (and other similar classes) won't be serialised ?

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.

AFAIK, moving forward(since 2.11), Pulsar has started using java 17.
This new load balancer will be available for the new versions of Pulsar (I assume 2.12 >).

The Unload and Split won't 'be json-serialized(don't get published to topics). These are wrapper objects for internal function calls.

I added the jsonWriteAndReadTest UT for ServiceUnitStateDataTest for this serialization test.

@heesung-sohn heesung-sohn Nov 11, 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 don't see Record related issues right now, and we could easily switch back to the lombok + class if blocked by any. By default, I think it is a good practice to try Record as much as we can.

@heesung-sohn
heesung-sohn requested review from Jason918 and eolivelli and removed request for BewareMyPower, Jason918, codelipenghui and eolivelli November 11, 2022 02:35
@heesung-sohn

Copy link
Copy Markdown
Contributor Author

@Jason918 @eolivelli,
I updated the code based on your comments. Plz, take a look again.

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

+1

@heesung-sohn

heesung-sohn commented Nov 13, 2022 •

Copy link
Copy Markdown
Contributor Author

@Jason918 can you take a look again by any chance? We need to merge this first to raise next PRs.

@Jason918

Copy link
Copy Markdown
Contributor

@Jason918 can you take a look again by any chance? We need to merge this first to raise next PRs.

Sorry for the late reply. This PR LGTM. :)

@heesung-sohn
heesung-sohn deleted the pip-192 branch April 2, 2024 17:45
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 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