Repository navigation
[improve][broker] PIP-192 Added ServiceUnitStateChannel interface - #18079
Conversation
| @Data | ||
| @ToString | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class ServiceUnitStateData { | ||
| private ServiceUnitState state; | ||
| private String broker; | ||
| private String sourceBroker; | ||
| private long timestamp; |
There was a problem hiding this comment.
@Dataalready infers@ToString.- Since the broker JDK version is upgraded to 17, do you think of using record class to define data models?
- Are these field intended to be mutable?
There was a problem hiding this comment.
Updated to record classes.
| assertEquals(data1.getState(), Owned); | ||
| assertEquals(data1.getBroker(), "A"); | ||
| assertNull(data1.getSourceBroker()); | ||
| assertTrue(data1.getTimestamp() > 0); |
There was a problem hiding this comment.
You can use assertj's assertion for better error message:
import static org.assertj.core.api.Assertions.assertThat;
assertThat(data1.getTimestamp()).isGreaterThan(0);|
|
||
| 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<>() {{ |
There was a problem hiding this comment.
Shall we define a state Free/NotOwned over null? Then we can avoid handling business nulls.
|
|
||
| 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<>() {{ |
There was a problem hiding this comment.
I'd prefer immutable sets over HashSet here. For example, Set.of(...).
tisonkun
left a comment
There was a problem hiding this comment.
LGTM. Thanks for your contribution!
|
/pulsarbot run-failure-checks |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
/pulsarbot run-failure-checks |
d7a4a71 to
aba6dc7
Compare
|
Jason918
left a comment
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Is this ServiceUnit the same as bundle for now and in the foreseeable future?
There was a problem hiding this comment.
I would like to keep open the door to having also a single topic (partition) and not only a "bundle"
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
It's confusing that we use "bundle" here, but use "serviceUnit" in Unload.
eolivelli
left a comment
There was a problem hiding this comment.
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) { |
| /** | ||
| * Defines the information required to unload or transfer a service unit(e.g. bundle). | ||
| */ | ||
| public record Unload(String sourceBroker, String serviceUnit, Optional<String> destBroker) { |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
@Jason918 @eolivelli, |
|
@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. :) |
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
org.apache.pulsar.broker.loadbalance.extensionspackage.Verifying this change
This change added tests and can be verified as follows:
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
docdoc-requireddoc-not-neededdoc-completeWe will have separate PRs to update the Doc later.
Matching PR in forked repository
PR in forked repository: heesung-sohn#11