You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by wa...@apache.org on 2022/07/16 09:22:14 UTC

[iotdb] branch master updated: [IOTDB-3840] deserialize RemoveDataNodePlan exception (#6686)

This is an automated email from the ASF dual-hosted git repository.

wangchao316 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new e0453b7d8f [IOTDB-3840]  deserialize RemoveDataNodePlan exception (#6686)
e0453b7d8f is described below

commit e0453b7d8f2cb3459891fb55d5f083079e022e52
Author: QiangShaowei <ba...@163.com>
AuthorDate: Sat Jul 16 17:22:07 2022 +0800

    [IOTDB-3840]  deserialize RemoveDataNodePlan exception (#6686)
    
    [IOTDB-3840]  deserialize RemoveDataNodePlan exception (#6686)
---
 .../request/write/RemoveDataNodePlan.java          |  1 -
 .../request/write/RemoveDataNodePlanTest.java      | 35 ++++++++++++++++++----
 2 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/RemoveDataNodePlan.java b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/RemoveDataNodePlan.java
index a8ea4190e3..e2178e6725 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/RemoveDataNodePlan.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/RemoveDataNodePlan.java
@@ -93,7 +93,6 @@ public class RemoveDataNodePlan extends ConfigPhysicalPlan {
     isUpdate = buffer.getInt() == 1;
     if (isUpdate) {
       execDataNodeIndex = buffer.getInt();
-      buffer.putInt(execDataNodeState.getCode());
       execDataNodeState = DataNodeRemoveState.getStateByCode(buffer.getInt());
       int regionSize = buffer.getInt();
       execDataNodeRegionIds = new ArrayList<>(regionSize);
diff --git a/confignode/src/test/java/org/apache/iotdb/confignode/consensus/request/write/RemoveDataNodePlanTest.java b/confignode/src/test/java/org/apache/iotdb/confignode/consensus/request/write/RemoveDataNodePlanTest.java
index 8f3c64d26b..bb4977a1f7 100644
--- a/confignode/src/test/java/org/apache/iotdb/confignode/consensus/request/write/RemoveDataNodePlanTest.java
+++ b/confignode/src/test/java/org/apache/iotdb/confignode/consensus/request/write/RemoveDataNodePlanTest.java
@@ -38,6 +38,8 @@ import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.List;
 
+import static org.junit.Assert.fail;
+
 public class RemoveDataNodePlanTest {
   private RemoveDataNodePlan req1;
   private RemoveDataNodePlan req2;
@@ -129,23 +131,44 @@ public class RemoveDataNodePlanTest {
   }
 
   @Test
-  public void testSerializeAndDeSerialized() throws IOException {
+  public void testNotUpdatePlanSerializeAndDeSerialize() {
+    try {
+      RemoveDataNodePlan deSerializeReq = runPlanSerializeAndDeSerialize(false);
+      Assert.assertEquals(req1, deSerializeReq);
+    } catch (IOException e) {
+      fail(e.getMessage());
+    }
+  }
+
+  @Test
+  public void testUpdatePlanSerializeAndDeSerialize() {
+    try {
+      RemoveDataNodePlan deSerializeReq = runPlanSerializeAndDeSerialize(true);
+      Assert.assertEquals(req1, deSerializeReq);
+    } catch (IOException e) {
+      fail(e.getMessage());
+    }
+  }
+
+  private RemoveDataNodePlan runPlanSerializeAndDeSerialize(boolean update) throws IOException {
     try (DataOutputStream outputStream =
         new DataOutputStream(Files.newOutputStream(Paths.get(serializedFileName)))) {
+      req1.setUpdate(update);
       req1.serializeImpl(outputStream);
     }
 
-    byte[] data = new byte[40240];
+    byte[] data = new byte[2048];
     try (DataInputStream inputStream =
         new DataInputStream(Files.newInputStream(Paths.get(serializedFileName)))) {
       inputStream.read(data);
     }
     ByteBuffer buffer = ByteBuffer.wrap(data);
+    buffer.rewind();
+    ByteBuffer readOnlyBuffer = buffer.asReadOnlyBuffer();
 
     RemoveDataNodePlan req = new RemoveDataNodePlan();
-    buffer.getInt();
-    req.deserializeImpl(buffer);
-
-    Assert.assertEquals(req, req1);
+    readOnlyBuffer.getInt();
+    req.deserializeImpl(readOnlyBuffer);
+    return req;
   }
 }