You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/10/18 06:05:53 UTC

[GitHub] [pulsar] heesung-sn commented on a diff in pull request #18079: [improve][broker] PIP-192 Added ServiceUnitStateChannel interface

heesung-sn commented on code in PR #18079:
URL: https://github.com/apache/pulsar/pull/18079#discussion_r997751620


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensible/channel/ServiceUnitStateData.java:
##########
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.loadbalance.extensible.channel;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
+/**
+ * Defines data for the service unit state changes.
+ * This data will be broadcast in ServiceUnitStateChannel.
+ */
+@Data
+@ToString
+@NoArgsConstructor
+@AllArgsConstructor
+public class ServiceUnitStateData {
+    private ServiceUnitState state;
+    private String broker;
+    private String sourceBroker;
+    private long timestamp;

Review Comment:
   Updated to `record` classes.



##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/loadbalance/extensible/channel/ServiceUnitStateDataTest.java:
##########
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.loadbalance.extensible.channel;
+
+import static org.apache.pulsar.broker.loadbalance.extensible.channel.ServiceUnitState.Assigned;
+import static org.apache.pulsar.broker.loadbalance.extensible.channel.ServiceUnitState.Owned;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+@Test(groups = "broker")
+public class ServiceUnitStateDataTest {
+
+    @Test
+    public void testConstructors() {
+        ServiceUnitStateData data1 = new ServiceUnitStateData(Owned, "A");
+        assertEquals(data1.getState(), Owned);
+        assertEquals(data1.getBroker(), "A");
+        assertNull(data1.getSourceBroker());
+        assertTrue(data1.getTimestamp() > 0);

Review Comment:
   Updated.



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensible/channel/ServiceUnitState.java:
##########
@@ -0,0 +1,99 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.loadbalance.extensible.channel;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Defines the possible states for service units.
+ *
+ * The following diagram defines the valid state changes
+ *
+ *                  ┌───────────┐
+ *       ┌──────────┤ released  │◄────────┐
+ *       │own       └───────────┘         │release
+ *       │                                │
+ *       │                                │
+ *       ▼                                │
+ *    ┌────────┐    assign          ┌─────┴────┐
+ *    │        ├───────────────────►│          │
+ *    │ owned  │                    │ assigned │
+ *    │        │◄───────────────────┤          │
+ *    └──┬─────┤      own           └──────────┘
+ *       │  ▲  │                         ▲
+ *       │  │  │                         │
+ *       │  │  └──────────────┐          │
+ *       │  │                 │          │
+ *       │  │        unload   │          │ assign
+ * split │  │                 │          │
+ *       │  │                 │          │
+ *       │  │ create(child)   │          │
+ *       │  │                 │          │
+ *       ▼  │                 │          │
+ *    ┌─────┴─────┐           └─────►┌───┴──────┐
+ *    │           │                  │          │
+ *    │ splitting ├────────────────► │not-owned │
+ *    │           │   discard(parent)│          │
+ *    └───────────┘                  └──────────┘
+ */
+public enum ServiceUnitState {
+
+    Owned, // the ownership assignment is complete (terminal state)
+
+    Assigned, // the ownership is assigned(but the assigned broker has not taken the ownership yet)
+
+    Released, // the ownership is released (e.g. the topic connections are closed)
+
+    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<>() {{

Review Comment:
   Updated.



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensible/channel/ServiceUnitState.java:
##########
@@ -0,0 +1,99 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.loadbalance.extensible.channel;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Defines the possible states for service units.
+ *
+ * The following diagram defines the valid state changes
+ *
+ *                  ┌───────────┐
+ *       ┌──────────┤ released  │◄────────┐
+ *       │own       └───────────┘         │release
+ *       │                                │
+ *       │                                │
+ *       ▼                                │
+ *    ┌────────┐    assign          ┌─────┴────┐
+ *    │        ├───────────────────►│          │
+ *    │ owned  │                    │ assigned │
+ *    │        │◄───────────────────┤          │
+ *    └──┬─────┤      own           └──────────┘
+ *       │  ▲  │                         ▲
+ *       │  │  │                         │
+ *       │  │  └──────────────┐          │
+ *       │  │                 │          │
+ *       │  │        unload   │          │ assign
+ * split │  │                 │          │
+ *       │  │                 │          │
+ *       │  │ create(child)   │          │
+ *       │  │                 │          │
+ *       ▼  │                 │          │
+ *    ┌─────┴─────┐           └─────►┌───┴──────┐
+ *    │           │                  │          │
+ *    │ splitting ├────────────────► │not-owned │
+ *    │           │   discard(parent)│          │
+ *    └───────────┘                  └──────────┘
+ */
+public enum ServiceUnitState {
+
+    Owned, // the ownership assignment is complete (terminal state)
+
+    Assigned, // the ownership is assigned(but the assigned broker has not taken the ownership yet)
+
+    Released, // the ownership is released (e.g. the topic connections are closed)
+
+    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<>() {{

Review Comment:
   Updated.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org