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

haonan 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 4f65f89698 [IOTDB-4941] Prevent compatibility problems in PipeData 
(#7996)
4f65f89698 is described below

commit 4f65f8969887a014a2c3588cc50e40d87468ef21
Author: Chen YZ <[email protected]>
AuthorDate: Tue Nov 15 18:04:30 2022 +0800

    [IOTDB-4941] Prevent compatibility problems in PipeData (#7996)
---
 .../db/integration/sync/IoTDBSyncSenderIT.java     |  2 +-
 .../iotdb/db/sync/pipedata/DeletionPipeData.java   |  2 +-
 .../apache/iotdb/db/sync/pipedata/PipeData.java    | 31 ++++++++++++++++++----
 .../iotdb/db/sync/pipedata/TsFilePipeData.java     |  2 +-
 .../sync/pipedata/queue/BufferedPipeDataQueue.java |  2 +-
 .../db/sync/transport/server/ReceiverManager.java  |  2 +-
 6 files changed, 31 insertions(+), 10 deletions(-)

diff --git 
a/integration/src/test/java/org/apache/iotdb/db/integration/sync/IoTDBSyncSenderIT.java
 
b/integration/src/test/java/org/apache/iotdb/db/integration/sync/IoTDBSyncSenderIT.java
index 159f42a4aa..5baf7413fa 100644
--- 
a/integration/src/test/java/org/apache/iotdb/db/integration/sync/IoTDBSyncSenderIT.java
+++ 
b/integration/src/test/java/org/apache/iotdb/db/integration/sync/IoTDBSyncSenderIT.java
@@ -268,7 +268,7 @@ public class IoTDBSyncSenderIT {
     int cnt = 0;
     for (String string : resultString) {
       for (PipeData pipeData : resultMap.get(string)) {
-        Assert.assertEquals(pipeData.getType(), list.get(cnt++).getType());
+        Assert.assertEquals(pipeData.getPipeDataType(), 
list.get(cnt++).getPipeDataType());
       }
     }
   }
diff --git 
a/server/src/main/java/org/apache/iotdb/db/sync/pipedata/DeletionPipeData.java 
b/server/src/main/java/org/apache/iotdb/db/sync/pipedata/DeletionPipeData.java
index 12d736576b..43ef452b70 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/sync/pipedata/DeletionPipeData.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/sync/pipedata/DeletionPipeData.java
@@ -54,7 +54,7 @@ public class DeletionPipeData extends PipeData {
   }
 
   @Override
-  public PipeDataType getType() {
+  public PipeDataType getPipeDataType() {
     return PipeDataType.DELETION;
   }
 
diff --git 
a/server/src/main/java/org/apache/iotdb/db/sync/pipedata/PipeData.java 
b/server/src/main/java/org/apache/iotdb/db/sync/pipedata/PipeData.java
index 18d41d2f35..fa9fcbbe3f 100644
--- a/server/src/main/java/org/apache/iotdb/db/sync/pipedata/PipeData.java
+++ b/server/src/main/java/org/apache/iotdb/db/sync/pipedata/PipeData.java
@@ -50,11 +50,11 @@ public abstract class PipeData {
     this.serialNumber = serialNumber;
   }
 
-  public abstract PipeDataType getType();
+  public abstract PipeDataType getPipeDataType();
 
   public long serialize(DataOutputStream stream) throws IOException {
     long serializeSize = 0;
-    stream.writeByte((byte) getType().ordinal());
+    stream.writeByte(getPipeDataType().getType());
     serializeSize += Byte.BYTES;
     stream.writeLong(serialNumber);
     serializeSize += Long.BYTES;
@@ -74,7 +74,7 @@ public abstract class PipeData {
   public static PipeData createPipeData(DataInputStream stream)
       throws IOException, IllegalPathException {
     PipeData pipeData;
-    PipeDataType type = PipeDataType.values()[stream.readByte()];
+    PipeDataType type = PipeDataType.getPipeDataType(stream.readByte());
     switch (type) {
       case TSFILE:
         pipeData = new TsFilePipeData();
@@ -98,7 +98,28 @@ public abstract class PipeData {
   public abstract ILoader createLoader();
 
   public enum PipeDataType {
-    TSFILE,
-    DELETION,
+    TSFILE((byte) 0),
+    DELETION((byte) 1);
+
+    private final byte type;
+
+    PipeDataType(byte type) {
+      this.type = type;
+    }
+
+    public byte getType() {
+      return type;
+    }
+
+    public static PipeDataType getPipeDataType(byte type) {
+      switch (type) {
+        case 0:
+          return PipeDataType.TSFILE;
+        case 1:
+          return PipeDataType.DELETION;
+        default:
+          throw new IllegalArgumentException("Invalid input: " + type);
+      }
+    }
   }
 }
diff --git 
a/server/src/main/java/org/apache/iotdb/db/sync/pipedata/TsFilePipeData.java 
b/server/src/main/java/org/apache/iotdb/db/sync/pipedata/TsFilePipeData.java
index ad99d6a5fb..6eb4e4dca6 100644
--- a/server/src/main/java/org/apache/iotdb/db/sync/pipedata/TsFilePipeData.java
+++ b/server/src/main/java/org/apache/iotdb/db/sync/pipedata/TsFilePipeData.java
@@ -121,7 +121,7 @@ public class TsFilePipeData extends PipeData {
   }
 
   @Override
-  public PipeDataType getType() {
+  public PipeDataType getPipeDataType() {
     return PipeDataType.TSFILE;
   }
 
diff --git 
a/server/src/main/java/org/apache/iotdb/db/sync/pipedata/queue/BufferedPipeDataQueue.java
 
b/server/src/main/java/org/apache/iotdb/db/sync/pipedata/queue/BufferedPipeDataQueue.java
index 4faaacd232..dc3f67fe62 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/sync/pipedata/queue/BufferedPipeDataQueue.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/sync/pipedata/queue/BufferedPipeDataQueue.java
@@ -311,7 +311,7 @@ public class BufferedPipeDataQueue implements PipeDataQueue 
{
         if (commitData == null) {
           return;
         }
-        if (PipeData.PipeDataType.TSFILE.equals(commitData.getType())) {
+        if (PipeData.PipeDataType.TSFILE.equals(commitData.getPipeDataType())) 
{
           List<File> tsFiles = ((TsFilePipeData) commitData).getTsFiles(false);
           for (File file : tsFiles) {
             Files.deleteIfExists(file.toPath());
diff --git 
a/server/src/main/java/org/apache/iotdb/db/sync/transport/server/ReceiverManager.java
 
b/server/src/main/java/org/apache/iotdb/db/sync/transport/server/ReceiverManager.java
index 39b231f3a1..1085617f35 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/sync/transport/server/ReceiverManager.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/sync/transport/server/ReceiverManager.java
@@ -242,7 +242,7 @@ public class ReceiverManager {
     logger.info(
         "Start load pipeData with serialize number {} and type {},value={}",
         pipeData.getSerialNumber(),
-        pipeData.getType(),
+        pipeData.getPipeDataType(),
         pipeData);
     try {
       pipeData.createLoader().load();

Reply via email to