You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/09/05 02:29:30 UTC

[GitHub] [iotdb] wangchao316 commented on a diff in pull request #7228: [IOTDB-4301] [IOTDB-4303] fix bug in create regions group procedure

wangchao316 commented on code in PR #7228:
URL: https://github.com/apache/iotdb/pull/7228#discussion_r962430669


##########
confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/CreateRegionGroupsProcedure.java:
##########
@@ -130,6 +153,52 @@ protected int getStateId(CreateRegionGroupsState createRegionGroupsState) {
 
   @Override
   protected CreateRegionGroupsState getInitialState() {
-    return CreateRegionGroupsState.CREATE_REGION_GROUPS;
+    return CreateRegionGroupsState.CREATE_REGION_GROUPS_PREPARE;
+  }
+
+  @Override
+  public void serialize(DataOutputStream stream) throws IOException {
+    // must serialize CREATE_REGION_GROUPS.ordinal() firstly
+    stream.writeInt(ProcedureFactory.ProcedureType.CREATE_REGION_GROUPS.ordinal());
+    super.serialize(stream);
+    createRegionGroupsPlan.serializeForProcedure(stream);
+    stream.writeInt(failedRegions.size());
+    failedRegions.forEach(
+        (groupId, replica) -> {
+          ThriftCommonsSerDeUtils.serializeTConsensusGroupId(groupId, stream);
+          ThriftCommonsSerDeUtils.serializeTRegionReplicaSet(replica, stream);
+        });
+  }
+
+  @Override
+  public void deserialize(ByteBuffer byteBuffer) {
+    super.deserialize(byteBuffer);
+    try {
+      createRegionGroupsPlan.deserializeForProcedure(byteBuffer);
+      failedRegions.clear();
+      int failedRegionsSize = byteBuffer.getInt();
+      while (failedRegionsSize-- > 0) {
+        TConsensusGroupId groupId =
+            ThriftCommonsSerDeUtils.deserializeTConsensusGroupId(byteBuffer);
+        TRegionReplicaSet replica =
+            ThriftCommonsSerDeUtils.deserializeTRegionReplicaSet(byteBuffer);
+        failedRegions.put(groupId, replica);
+      }
+    } catch (Exception e) {
+      LOGGER.error("Deserialize meets error in CreateRegionGroupsProcedure", e);
+      throw new RuntimeException(e);
+    }
+  }
+
+  @Override
+  public boolean equals(Object that) {
+    if (that instanceof CreateRegionGroupsProcedure) {
+      CreateRegionGroupsProcedure thatProc = (CreateRegionGroupsProcedure) that;
+      return thatProc.getProcId() == this.getProcId()
+          && thatProc.getState() == this.getState()
+          && thatProc.createRegionGroupsPlan.equals(this.createRegionGroupsPlan)
+          && thatProc.failedRegions.equals(this.failedRegions);
+    }
+    return false;

Review Comment:
   implementation  @hashcode



-- 
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: reviews-unsubscribe@iotdb.apache.org

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