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


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/channel/ServiceUnitStateData.java:
##########
@@ -37,19 +36,23 @@ public record ServiceUnitStateData(
         }
     }
 
-    public ServiceUnitStateData(ServiceUnitState state, String broker, String 
sourceBroker) {
-        this(state, broker, sourceBroker, false, System.currentTimeMillis());
+    public ServiceUnitStateData(ServiceUnitState state, String broker, String 
sourceBroker, long versionId) {
+        this(state, broker, sourceBroker, false, System.currentTimeMillis(), 
versionId);
     }
 
-    public ServiceUnitStateData(ServiceUnitState state, String broker) {
-        this(state, broker, null, false, System.currentTimeMillis());
+    public ServiceUnitStateData(ServiceUnitState state, String broker, long 
versionId) {
+        this(state, broker, null, false, System.currentTimeMillis(), 
versionId);
     }
 
-    public ServiceUnitStateData(ServiceUnitState state, String broker, boolean 
force) {
-        this(state, broker, null, force, System.currentTimeMillis());
+    public ServiceUnitStateData(ServiceUnitState state, String broker, boolean 
force, long versionId) {
+        this(state, broker, null, force, System.currentTimeMillis(), 
versionId);
     }
 
     public static ServiceUnitState state(ServiceUnitStateData data) {
         return data == null ? ServiceUnitState.Init : data.state();
     }
+
+    public static long versionId(ServiceUnitStateData data) {
+        return data == null ? 0 : data.versionId();

Review Comment:
   We can do that too. Then, we don't need to call `versionId(data)` since we 
already did the null check.
   
   ```
       private long getNextVersionId(String serviceUnit) {
           var data = tableview.get(serviceUnit);
           return getNextVersionId(data);
       }
   
       private long getNextVersionId(ServiceUnitStateData data) {
           return data == null ? VERSION_ID_INIT : data.getVersionId() + 1;
       }
   ```
   Updated the code.
   
   Nevertheless, if this is the first version(child bundle creation), we can 
pass the VERSION_ID_INIT without calling getNextVersionId(null). It looks 
redundant to call getNextVersionId(null) to get VERSION_ID_INIT.
   
   `ServiceUnitStateData next = new ServiceUnitStateData(Owned, data.broker(), 
VERSION_ID_INIT);`
   or 
   `ServiceUnitStateData next = new ServiceUnitStateData(Owned, data.broker(), 
getNextVersionId(null));`
   
   
   
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to