You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by hu...@apache.org on 2023/02/17 07:00:47 UTC

[iotdb] 11/16: finish ModelInfo

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

hui pushed a commit to branch lmh/modelManager
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit a8af6e7ac1909eb961a4cc249671f5e363d47fc6
Author: Minghui Liu <li...@foxmail.com>
AuthorDate: Fri Jan 6 15:27:02 2023 +0800

    finish ModelInfo
---
 .../request/read/model/ShowModelPlan.java          |  28 +++--
 .../request/read/model/ShowTrailPlan.java          |  36 ++++--
 .../request/write/model/CreateModelPlan.java       |   4 +
 .../request/write/model/DropModelPlan.java         |   4 +
 .../request/write/model/UpdateModelInfoPlan.java   |  27 +++--
 .../consensus/response/ModelTableResp.java         |  19 ++-
 .../consensus/response/TrailTableResp.java         |  19 ++-
 .../iotdb/confignode/persistence/ModelInfo.java    | 132 ++++++++++++---------
 .../procedure/impl/model/CreateModelProcedure.java |   7 +-
 .../procedure/impl/model/DropModelProcedure.java   |   7 +-
 .../iotdb/commons/model/ModelInformation.java      |  23 ++++
 .../org/apache/iotdb/commons/model/ModelTable.java |  66 ++++++++++-
 .../iotdb/commons/model/TrailInformation.java      |   4 +
 .../commons/utils/ThriftCommonsSerDeUtils.java     |  58 ---------
 .../src/main/thrift/confignode.thrift              |  15 +--
 15 files changed, 297 insertions(+), 152 deletions(-)

diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/read/model/ShowModelPlan.java b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/read/model/ShowModelPlan.java
index d5082379fd..3fe4bf0af7 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/read/model/ShowModelPlan.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/read/model/ShowModelPlan.java
@@ -19,10 +19,10 @@
 
 package org.apache.iotdb.confignode.consensus.request.read.model;
 
-import org.apache.iotdb.commons.utils.ThriftCommonsSerDeUtils;
 import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlan;
 import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlanType;
 import org.apache.iotdb.confignode.rpc.thrift.TShowModelReq;
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
 
 import java.io.DataOutputStream;
 import java.io.IOException;
@@ -31,7 +31,7 @@ import java.util.Objects;
 
 public class ShowModelPlan extends ConfigPhysicalPlan {
 
-  private TShowModelReq showModelReq;
+  private String modelId;
 
   public ShowModelPlan() {
     super(ConfigPhysicalPlanType.ShowModel);
@@ -39,18 +39,32 @@ public class ShowModelPlan extends ConfigPhysicalPlan {
 
   public ShowModelPlan(TShowModelReq showModelReq) {
     super(ConfigPhysicalPlanType.ShowModel);
-    this.showModelReq = showModelReq;
+    if (showModelReq.isSetModelId()) {
+      this.modelId = showModelReq.getModelId();
+    }
+  }
+
+  public boolean isSetModelId() {
+    return modelId != null;
+  }
+
+  public String getModelId() {
+    return modelId;
   }
 
   @Override
   protected void serializeImpl(DataOutputStream stream) throws IOException {
     stream.writeShort(getType().getPlanType());
-    ThriftCommonsSerDeUtils.serializeTShowModelReq(showModelReq, stream);
+    ReadWriteIOUtils.write(modelId != null, stream);
+    ReadWriteIOUtils.write(modelId, stream);
   }
 
   @Override
   protected void deserializeImpl(ByteBuffer buffer) throws IOException {
-    showModelReq = ThriftCommonsSerDeUtils.deserializeTShowModelReq(buffer);
+    boolean isSetModelId = ReadWriteIOUtils.readBool(buffer);
+    if (isSetModelId) {
+      this.modelId = ReadWriteIOUtils.readString(buffer);
+    }
   }
 
   @Override
@@ -65,11 +79,11 @@ public class ShowModelPlan extends ConfigPhysicalPlan {
       return false;
     }
     ShowModelPlan that = (ShowModelPlan) o;
-    return Objects.equals(showModelReq, that.showModelReq);
+    return Objects.equals(modelId, that.modelId);
   }
 
   @Override
   public int hashCode() {
-    return Objects.hash(super.hashCode(), showModelReq);
+    return Objects.hash(super.hashCode(), modelId);
   }
 }
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/read/model/ShowTrailPlan.java b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/read/model/ShowTrailPlan.java
index aa9fb83bf2..6a982585e8 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/read/model/ShowTrailPlan.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/read/model/ShowTrailPlan.java
@@ -19,10 +19,10 @@
 
 package org.apache.iotdb.confignode.consensus.request.read.model;
 
-import org.apache.iotdb.commons.utils.ThriftCommonsSerDeUtils;
 import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlan;
 import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlanType;
 import org.apache.iotdb.confignode.rpc.thrift.TShowTrailReq;
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
 
 import java.io.DataOutputStream;
 import java.io.IOException;
@@ -31,7 +31,8 @@ import java.util.Objects;
 
 public class ShowTrailPlan extends ConfigPhysicalPlan {
 
-  private TShowTrailReq showTrailReq;
+  private String modelId;
+  private String trailId;
 
   public ShowTrailPlan() {
     super(ConfigPhysicalPlanType.ShowTrail);
@@ -39,18 +40,39 @@ public class ShowTrailPlan extends ConfigPhysicalPlan {
 
   public ShowTrailPlan(TShowTrailReq showTrailReq) {
     super(ConfigPhysicalPlanType.ShowTrail);
-    this.showTrailReq = showTrailReq;
+    this.modelId = showTrailReq.getModelId();
+    if (showTrailReq.isSetTrailId()) {
+      this.trailId = showTrailReq.getTrailId();
+    }
+  }
+
+  public String getModelId() {
+    return modelId;
+  }
+
+  public boolean isSetTrailId() {
+    return trailId != null;
+  }
+
+  public String getTrailId() {
+    return trailId;
   }
 
   @Override
   protected void serializeImpl(DataOutputStream stream) throws IOException {
     stream.writeShort(getType().getPlanType());
-    ThriftCommonsSerDeUtils.serializeTShowTrailReq(showTrailReq, stream);
+    ReadWriteIOUtils.write(modelId, stream);
+    ReadWriteIOUtils.write(trailId != null, stream);
+    ReadWriteIOUtils.write(trailId, stream);
   }
 
   @Override
   protected void deserializeImpl(ByteBuffer buffer) throws IOException {
-    showTrailReq = ThriftCommonsSerDeUtils.deserializeTShowTrailReq(buffer);
+    this.modelId = ReadWriteIOUtils.readString(buffer);
+    boolean isSetTrailId = ReadWriteIOUtils.readBool(buffer);
+    if (isSetTrailId) {
+      this.trailId = ReadWriteIOUtils.readString(buffer);
+    }
   }
 
   @Override
@@ -65,11 +87,11 @@ public class ShowTrailPlan extends ConfigPhysicalPlan {
       return false;
     }
     ShowTrailPlan that = (ShowTrailPlan) o;
-    return Objects.equals(showTrailReq, that.showTrailReq);
+    return modelId.equals(that.modelId) && Objects.equals(trailId, that.trailId);
   }
 
   @Override
   public int hashCode() {
-    return Objects.hash(super.hashCode(), showTrailReq);
+    return Objects.hash(super.hashCode(), modelId, trailId);
   }
 }
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/model/CreateModelPlan.java b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/model/CreateModelPlan.java
index d5366453d6..29422ef998 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/model/CreateModelPlan.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/model/CreateModelPlan.java
@@ -41,6 +41,10 @@ public class CreateModelPlan extends ConfigPhysicalPlan {
     this.modelInformation = modelInformation;
   }
 
+  public ModelInformation getModelInformation() {
+    return modelInformation;
+  }
+
   @Override
   protected void serializeImpl(DataOutputStream stream) throws IOException {
     stream.writeShort(getType().getPlanType());
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/model/DropModelPlan.java b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/model/DropModelPlan.java
index f2def81121..c94d7e786a 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/model/DropModelPlan.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/model/DropModelPlan.java
@@ -44,6 +44,10 @@ public class DropModelPlan extends ConfigPhysicalPlan {
     this.modelId = modelId;
   }
 
+  public String getModelId() {
+    return modelId;
+  }
+
   @Override
   protected void serializeImpl(DataOutputStream stream) throws IOException {
     stream.writeShort(getType().getPlanType());
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/model/UpdateModelInfoPlan.java b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/model/UpdateModelInfoPlan.java
index e48b6b8fe8..d1eacadae2 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/model/UpdateModelInfoPlan.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/write/model/UpdateModelInfoPlan.java
@@ -19,19 +19,21 @@
 
 package org.apache.iotdb.confignode.consensus.request.write.model;
 
-import org.apache.iotdb.commons.utils.ThriftCommonsSerDeUtils;
 import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlan;
 import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlanType;
 import org.apache.iotdb.confignode.rpc.thrift.TUpdateModelInfoReq;
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
 
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.nio.ByteBuffer;
+import java.util.Map;
 import java.util.Objects;
 
 public class UpdateModelInfoPlan extends ConfigPhysicalPlan {
 
-  private TUpdateModelInfoReq updateModelInfoReq;
+  private String modelId;
+  private Map<String, String> modelInfo;
 
   public UpdateModelInfoPlan() {
     super(ConfigPhysicalPlanType.UpdateModelInfo);
@@ -39,18 +41,29 @@ public class UpdateModelInfoPlan extends ConfigPhysicalPlan {
 
   public UpdateModelInfoPlan(TUpdateModelInfoReq updateModelInfoReq) {
     super(ConfigPhysicalPlanType.UpdateModelInfo);
-    this.updateModelInfoReq = updateModelInfoReq;
+    this.modelId = updateModelInfoReq.getModelId();
+    this.modelInfo = updateModelInfoReq.getModelInfo();
+  }
+
+  public String getModelId() {
+    return modelId;
+  }
+
+  public Map<String, String> getModelInfo() {
+    return modelInfo;
   }
 
   @Override
   protected void serializeImpl(DataOutputStream stream) throws IOException {
     stream.writeShort(getType().getPlanType());
-    ThriftCommonsSerDeUtils.serializeTUpdateModelInfoReq(updateModelInfoReq, stream);
+    ReadWriteIOUtils.write(modelId, stream);
+    ReadWriteIOUtils.write(modelInfo, stream);
   }
 
   @Override
   protected void deserializeImpl(ByteBuffer buffer) throws IOException {
-    updateModelInfoReq = ThriftCommonsSerDeUtils.deserializeTUpdateModelInfoReq(buffer);
+    this.modelId = ReadWriteIOUtils.readString(buffer);
+    this.modelInfo = ReadWriteIOUtils.readMap(buffer);
   }
 
   @Override
@@ -65,11 +78,11 @@ public class UpdateModelInfoPlan extends ConfigPhysicalPlan {
       return false;
     }
     UpdateModelInfoPlan that = (UpdateModelInfoPlan) o;
-    return Objects.equals(updateModelInfoReq, that.updateModelInfoReq);
+    return modelId.equals(that.modelId) && modelInfo.equals(that.modelInfo);
   }
 
   @Override
   public int hashCode() {
-    return Objects.hash(super.hashCode(), updateModelInfoReq);
+    return Objects.hash(super.hashCode(), modelId, modelInfo);
   }
 }
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/consensus/response/ModelTableResp.java b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/response/ModelTableResp.java
index 05afc195bc..82787ca653 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/consensus/response/ModelTableResp.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/response/ModelTableResp.java
@@ -19,13 +19,30 @@
 
 package org.apache.iotdb.confignode.consensus.response;
 
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.model.ModelInformation;
 import org.apache.iotdb.confignode.rpc.thrift.TShowModelResp;
 import org.apache.iotdb.consensus.common.DataSet;
 
 import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
 
 public class ModelTableResp implements DataSet {
+
+  private final TSStatus status;
+  private final List<ByteBuffer> serializedAllModelInformation;
+
+  public ModelTableResp(TSStatus status, List<ModelInformation> allModelInformation) {
+    this.status = status;
+    this.serializedAllModelInformation = new ArrayList<>();
+    for (ModelInformation modelInformation : allModelInformation) {
+      this.serializedAllModelInformation.add(modelInformation.serializeShowModelResult());
+    }
+  }
+
   public TShowModelResp convertToThriftResponse() throws IOException {
-    return null;
+    return new TShowModelResp(status, serializedAllModelInformation);
   }
 }
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/consensus/response/TrailTableResp.java b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/response/TrailTableResp.java
index 565297d053..21e3fcd230 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/consensus/response/TrailTableResp.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/consensus/response/TrailTableResp.java
@@ -19,13 +19,30 @@
 
 package org.apache.iotdb.confignode.consensus.response;
 
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.model.TrailInformation;
 import org.apache.iotdb.confignode.rpc.thrift.TShowTrailResp;
 import org.apache.iotdb.consensus.common.DataSet;
 
 import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
 
 public class TrailTableResp implements DataSet {
+
+  private final TSStatus status;
+  private final List<ByteBuffer> serializedAllTrailInformation;
+
+  public TrailTableResp(TSStatus status, List<TrailInformation> allTrailInformation) {
+    this.status = status;
+    this.serializedAllTrailInformation = new ArrayList<>();
+    for (TrailInformation trailInformation : allTrailInformation) {
+      this.serializedAllTrailInformation.add(trailInformation.serializeShowTrailResult());
+    }
+  }
+
   public TShowTrailResp convertToThriftResponse() throws IOException {
-    return null;
+    return new TShowTrailResp(status, serializedAllTrailInformation);
   }
 }
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/persistence/ModelInfo.java b/confignode/src/main/java/org/apache/iotdb/confignode/persistence/ModelInfo.java
index 525828c5c0..d2c5144d10 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/persistence/ModelInfo.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/persistence/ModelInfo.java
@@ -21,7 +21,8 @@ package org.apache.iotdb.confignode.persistence;
 
 import org.apache.iotdb.common.rpc.thrift.TSStatus;
 import org.apache.iotdb.commons.model.ModelInformation;
-import org.apache.iotdb.commons.model.exception.ModelManagementException;
+import org.apache.iotdb.commons.model.ModelTable;
+import org.apache.iotdb.commons.model.TrailInformation;
 import org.apache.iotdb.commons.snapshot.SnapshotProcessor;
 import org.apache.iotdb.confignode.consensus.request.read.model.ShowModelPlan;
 import org.apache.iotdb.confignode.consensus.request.read.model.ShowTrailPlan;
@@ -30,7 +31,7 @@ import org.apache.iotdb.confignode.consensus.request.write.model.DropModelPlan;
 import org.apache.iotdb.confignode.consensus.request.write.model.UpdateModelInfoPlan;
 import org.apache.iotdb.confignode.consensus.response.ModelTableResp;
 import org.apache.iotdb.confignode.consensus.response.TrailTableResp;
-import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+import org.apache.iotdb.rpc.TSStatusCode;
 
 import org.apache.thrift.TException;
 import org.slf4j.Logger;
@@ -42,9 +43,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.Collections;
 import java.util.concurrent.locks.ReentrantLock;
 
 @ThreadSafe
@@ -54,12 +53,12 @@ public class ModelInfo implements SnapshotProcessor {
 
   private static final String SNAPSHOT_FILENAME = "model_info.snapshot";
 
-  private final Map<String, ModelInformation> modelInfoMap;
+  private ModelTable modelTable;
 
   private final ReentrantLock modelTableLock = new ReentrantLock();
 
   public ModelInfo() {
-    this.modelInfoMap = new HashMap<>();
+    this.modelTable = new ModelTable();
   }
 
   public void acquireModelTableLock() {
@@ -73,23 +72,82 @@ public class ModelInfo implements SnapshotProcessor {
   }
 
   public TSStatus createModel(CreateModelPlan plan) {
+    try {
+      ModelInformation modelInformation = plan.getModelInformation();
+      modelTable.addModel(modelInformation);
+    } catch (Exception e) {
+      final String errorMessage =
+          String.format(
+              "Failed to add model [%s] in ModelTable on Config Nodes, because of %s",
+              plan.getModelInformation().getModelId(), e);
+      LOGGER.warn(errorMessage, e);
+      return new TSStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR.getStatusCode())
+          .setMessage(errorMessage);
+    }
     return null;
   }
 
+  public TSStatus dropModel(DropModelPlan plan) {
+    String modelId = plan.getModelId();
+    if (modelTable.containsModel(modelId)) {
+      modelTable.removeModel(modelId);
+    }
+    return new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode());
+  }
+
   public ModelTableResp showModel(ShowModelPlan plan) {
-    return null;
+    acquireModelTableLock();
+    try {
+      if (plan.isSetModelId()) {
+        ModelInformation modelInformation = modelTable.getModelInformationById(plan.getModelId());
+        return new ModelTableResp(
+            new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode()),
+            modelInformation != null
+                ? Collections.singletonList(modelInformation)
+                : Collections.emptyList());
+      } else {
+        return new ModelTableResp(
+            new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode()),
+            modelTable.getAllModelInformation());
+      }
+    } finally {
+      releaseModelTableLock();
+    }
   }
 
   public TrailTableResp showTrail(ShowTrailPlan plan) {
-    return null;
+    acquireModelTableLock();
+    try {
+      ModelInformation modelInformation = modelTable.getModelInformationById(plan.getModelId());
+      if (plan.isSetTrailId()) {
+        TrailInformation trailInformation =
+            modelInformation.getTrailInformationById(plan.getTrailId());
+        return new TrailTableResp(
+            new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode()),
+            trailInformation != null
+                ? Collections.singletonList(trailInformation)
+                : Collections.emptyList());
+      } else {
+        return new TrailTableResp(
+            new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode()),
+            modelInformation.getAllTrailInformation());
+      }
+    } finally {
+      releaseModelTableLock();
+    }
   }
 
   public TSStatus updateModelInfo(UpdateModelInfoPlan plan) {
-    return null;
-  }
-
-  public TSStatus dropModel(DropModelPlan plan) {
-    return null;
+    acquireModelTableLock();
+    try {
+      String modelId = plan.getModelId();
+      if (modelTable.containsModel(modelId)) {
+        modelTable.updateModel(modelId, plan.getModelInfo());
+      }
+      return new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode());
+    } finally {
+      releaseModelTableLock();
+    }
   }
 
   @Override
@@ -104,21 +162,13 @@ public class ModelInfo implements SnapshotProcessor {
 
     acquireModelTableLock();
     try (FileOutputStream fileOutputStream = new FileOutputStream(snapshotFile)) {
-
-      serialize(fileOutputStream);
+      modelTable.serialize(fileOutputStream);
       return true;
     } finally {
       releaseModelTableLock();
     }
   }
 
-  private void serialize(FileOutputStream stream) throws IOException {
-    ReadWriteIOUtils.write(modelInfoMap.size(), stream);
-    for (ModelInformation entry : modelInfoMap.values()) {
-      entry.serialize(stream);
-    }
-  }
-
   @Override
   public void processLoadSnapshot(File snapshotDir) throws TException, IOException {
     File snapshotFile = new File(snapshotDir, SNAPSHOT_FILENAME);
@@ -130,42 +180,14 @@ public class ModelInfo implements SnapshotProcessor {
     }
     acquireModelTableLock();
     try (FileInputStream fileInputStream = new FileInputStream(snapshotFile)) {
-
-      clear();
-
-      deserialize(fileInputStream);
-
+      modelTable.clear();
+      modelTable = ModelTable.deserialize(fileInputStream);
     } finally {
       releaseModelTableLock();
     }
   }
 
-  private void clear() {
-    modelInfoMap.clear();
-  }
-
-  private void deserialize(InputStream stream) throws IOException {
-    int size = ReadWriteIOUtils.readInt(stream);
-    for (int i = 0; i < size; i++) {
-      ModelInformation modelEntry = ModelInformation.deserialize(stream);
-      modelInfoMap.put(modelEntry.getModelId(), modelEntry);
-    }
-  }
-
-  public void validate(ModelInformation modelInformation) {
-    String modelId = modelInformation.getModelId();
-    if (modelInfoMap.containsKey(modelId)) {
-      throw new ModelManagementException(
-          String.format(
-              "Failed to create model [%s], the same name model has been created", modelId));
-    }
-  }
-
-  public void validate(String modelId) {
-    if (modelInfoMap.containsKey(modelId)) {
-      return;
-    }
-    throw new ModelManagementException(
-        String.format("Failed to drop model [%s], this model has not been created", modelId));
+  public boolean isModelExist(String modelId) {
+    return modelTable.containsModel(modelId);
   }
 }
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/model/CreateModelProcedure.java b/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/model/CreateModelProcedure.java
index 8ec6d16899..0eb4b3800b 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/model/CreateModelProcedure.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/model/CreateModelProcedure.java
@@ -68,7 +68,12 @@ public class CreateModelProcedure extends AbstractNodeProcedure<CreateModelState
 
           ModelInfo modelInfo = env.getConfigManager().getModelManager().getModelInfo();
           modelInfo.acquireModelTableLock();
-          modelInfo.validate(modelInformation);
+          String modelId = modelInformation.getModelId();
+          if (modelInfo.isModelExist(modelId)) {
+            throw new ModelManagementException(
+                String.format(
+                    "Failed to create model [%s], the same name model has been created", modelId));
+          }
           setNextState(CreateModelState.VALIDATED);
           break;
 
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/model/DropModelProcedure.java b/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/model/DropModelProcedure.java
index dcac6e1758..066bbfde90 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/model/DropModelProcedure.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/model/DropModelProcedure.java
@@ -19,6 +19,7 @@
 
 package org.apache.iotdb.confignode.procedure.impl.model;
 
+import org.apache.iotdb.commons.model.exception.ModelManagementException;
 import org.apache.iotdb.confignode.consensus.request.write.model.DropModelPlan;
 import org.apache.iotdb.confignode.consensus.request.write.model.UpdateModelInfoPlan;
 import org.apache.iotdb.confignode.persistence.ModelInfo;
@@ -65,7 +66,11 @@ public class DropModelProcedure extends AbstractNodeProcedure<DropModelState> {
 
           ModelInfo modelInfo = env.getConfigManager().getModelManager().getModelInfo();
           modelInfo.acquireModelTableLock();
-          modelInfo.validate(modelId);
+          if (!modelInfo.isModelExist(modelId)) {
+            throw new ModelManagementException(
+                String.format(
+                    "Failed to drop model [%s], this model has not been created", modelId));
+          }
 
           env.getConfigManager()
               .getConsensusManager()
diff --git a/node-commons/src/main/java/org/apache/iotdb/commons/model/ModelInformation.java b/node-commons/src/main/java/org/apache/iotdb/commons/model/ModelInformation.java
index fc2f57bb1c..d94d16bfd5 100644
--- a/node-commons/src/main/java/org/apache/iotdb/commons/model/ModelInformation.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/model/ModelInformation.java
@@ -19,10 +19,13 @@
 
 package org.apache.iotdb.commons.model;
 
+import org.apache.iotdb.tsfile.utils.PublicBAOS;
+
 import java.io.DataOutputStream;
 import java.io.FileOutputStream;
 import java.io.InputStream;
 import java.nio.ByteBuffer;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -50,6 +53,19 @@ public class ModelInformation {
     return isAuto;
   }
 
+  public TrailInformation getTrailInformationById(String trailId) {
+    if (trailMap.containsKey(trailId)) {
+      return trailMap.get(trailId);
+    }
+    return null;
+  }
+
+  public List<TrailInformation> getAllTrailInformation() {
+    return new ArrayList<>(trailMap.values());
+  }
+
+  public void update(Map<String, String> modelInfo) {}
+
   public void serialize(DataOutputStream stream) {}
 
   public void serialize(FileOutputStream stream) {}
@@ -61,4 +77,11 @@ public class ModelInformation {
   public static ModelInformation deserialize(ByteBuffer buffer) {
     return null;
   }
+
+  public ByteBuffer serializeShowModelResult() {
+    PublicBAOS buffer = new PublicBAOS();
+    DataOutputStream stream = new DataOutputStream(buffer);
+
+    return ByteBuffer.wrap(buffer.getBuf(), 0, buffer.size());
+  }
 }
diff --git a/node-commons/src/main/java/org/apache/iotdb/commons/model/ModelTable.java b/node-commons/src/main/java/org/apache/iotdb/commons/model/ModelTable.java
index 14e4903043..598c26017e 100644
--- a/node-commons/src/main/java/org/apache/iotdb/commons/model/ModelTable.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/model/ModelTable.java
@@ -19,4 +19,68 @@
 
 package org.apache.iotdb.commons.model;
 
-public class ModelTable {}
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class ModelTable {
+
+  private final Map<String, ModelInformation> modelInfoMap;
+
+  public ModelTable() {
+    this.modelInfoMap = new ConcurrentHashMap<>();
+  }
+
+  public boolean containsModel(String modelId) {
+    return modelInfoMap.containsKey(modelId);
+  }
+
+  public void addModel(ModelInformation modelInformation) {
+    modelInfoMap.put(modelInformation.getModelId(), modelInformation);
+  }
+
+  public void removeModel(String modelId) {
+    modelInfoMap.remove(modelId);
+  }
+
+  public List<ModelInformation> getAllModelInformation() {
+    return new ArrayList<>(modelInfoMap.values());
+  }
+
+  public ModelInformation getModelInformationById(String modelId) {
+    if (modelInfoMap.containsKey(modelId)) {
+      modelInfoMap.get(modelId);
+    }
+    return null;
+  }
+
+  public void updateModel(String modelId, Map<String, String> modelInfo) {
+    modelInfoMap.get(modelId).update(modelInfo);
+  }
+
+  public void clear() {
+    modelInfoMap.clear();
+  }
+
+  public void serialize(FileOutputStream stream) throws IOException {
+    ReadWriteIOUtils.write(modelInfoMap.size(), stream);
+    for (ModelInformation entry : modelInfoMap.values()) {
+      entry.serialize(stream);
+    }
+  }
+
+  public static ModelTable deserialize(InputStream stream) throws IOException {
+    ModelTable modelTable = new ModelTable();
+    int size = ReadWriteIOUtils.readInt(stream);
+    for (int i = 0; i < size; i++) {
+      modelTable.addModel(ModelInformation.deserialize(stream));
+    }
+    return modelTable;
+  }
+}
diff --git a/node-commons/src/main/java/org/apache/iotdb/commons/model/TrailInformation.java b/node-commons/src/main/java/org/apache/iotdb/commons/model/TrailInformation.java
index 70ae854edd..7dd3831e7c 100644
--- a/node-commons/src/main/java/org/apache/iotdb/commons/model/TrailInformation.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/model/TrailInformation.java
@@ -19,8 +19,12 @@
 
 package org.apache.iotdb.commons.model;
 
+import java.nio.ByteBuffer;
+
 public abstract class TrailInformation {
 
   private String trailId;
   private TrailState trailState;
+
+  public abstract ByteBuffer serializeShowTrailResult();
 }
diff --git a/node-commons/src/main/java/org/apache/iotdb/commons/utils/ThriftCommonsSerDeUtils.java b/node-commons/src/main/java/org/apache/iotdb/commons/utils/ThriftCommonsSerDeUtils.java
index 3204cdf175..ffa4b5cd01 100644
--- a/node-commons/src/main/java/org/apache/iotdb/commons/utils/ThriftCommonsSerDeUtils.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/utils/ThriftCommonsSerDeUtils.java
@@ -28,10 +28,7 @@ import org.apache.iotdb.common.rpc.thrift.TSeriesPartitionSlot;
 import org.apache.iotdb.common.rpc.thrift.TTimePartitionSlot;
 import org.apache.iotdb.commons.exception.runtime.ThriftSerDeException;
 import org.apache.iotdb.confignode.rpc.thrift.TCreateCQReq;
-import org.apache.iotdb.confignode.rpc.thrift.TShowModelReq;
-import org.apache.iotdb.confignode.rpc.thrift.TShowTrailReq;
 import org.apache.iotdb.confignode.rpc.thrift.TTimeSlotList;
-import org.apache.iotdb.confignode.rpc.thrift.TUpdateModelInfoReq;
 
 import org.apache.thrift.TException;
 import org.apache.thrift.protocol.TBinaryProtocol;
@@ -262,59 +259,4 @@ public class ThriftCommonsSerDeUtils {
     }
     return schemaNode;
   }
-
-  public static void serializeTUpdateModelInfoReq(
-      TUpdateModelInfoReq updateModelInfoReq, DataOutputStream stream) {
-    try {
-      updateModelInfoReq.write(generateWriteProtocol(stream));
-    } catch (TException e) {
-      throw new ThriftSerDeException("Write TUpdateModelInfoReq failed: ", e);
-    }
-  }
-
-  public static TUpdateModelInfoReq deserializeTUpdateModelInfoReq(ByteBuffer buffer) {
-    TUpdateModelInfoReq updateModelInfoReq = new TUpdateModelInfoReq();
-    try {
-      updateModelInfoReq.read(generateReadProtocol(buffer));
-    } catch (TException e) {
-      throw new ThriftSerDeException("Read TUpdateModelInfoReq failed: ", e);
-    }
-    return updateModelInfoReq;
-  }
-
-  public static void serializeTShowModelReq(TShowModelReq showModelReq, DataOutputStream stream) {
-    try {
-      showModelReq.write(generateWriteProtocol(stream));
-    } catch (TException e) {
-      throw new ThriftSerDeException("Write TShowModelReq failed: ", e);
-    }
-  }
-
-  public static TShowModelReq deserializeTShowModelReq(ByteBuffer buffer) {
-    TShowModelReq showModelReq = new TShowModelReq();
-    try {
-      showModelReq.read(generateReadProtocol(buffer));
-    } catch (TException e) {
-      throw new ThriftSerDeException("Read TShowModelReq failed: ", e);
-    }
-    return showModelReq;
-  }
-
-  public static void serializeTShowTrailReq(TShowTrailReq showTrailReq, DataOutputStream stream) {
-    try {
-      showTrailReq.write(generateWriteProtocol(stream));
-    } catch (TException e) {
-      throw new ThriftSerDeException("Write TShowTrailReq failed: ", e);
-    }
-  }
-
-  public static TShowTrailReq deserializeTShowTrailReq(ByteBuffer buffer) {
-    TShowTrailReq showTrailReq = new TShowTrailReq();
-    try {
-      showTrailReq.read(generateReadProtocol(buffer));
-    } catch (TException e) {
-      throw new ThriftSerDeException("Read TShowTrailReq failed: ", e);
-    }
-    return showTrailReq;
-  }
 }
diff --git a/thrift-confignode/src/main/thrift/confignode.thrift b/thrift-confignode/src/main/thrift/confignode.thrift
index 9cdd54d33c..60bbf05872 100644
--- a/thrift-confignode/src/main/thrift/confignode.thrift
+++ b/thrift-confignode/src/main/thrift/confignode.thrift
@@ -683,14 +683,9 @@ struct TShowModelReq {
   1: optional string modelId
 }
 
-struct TModelInfo {
-  1: required string modelId
-  2: required map<string, string> modelInfo
-}
-
 struct TShowModelResp {
   1: required common.TSStatus status
-  2: required list<TModelInfo> modelInfoList
+  2: required list<binary> modelInfoList
 }
 
 struct TShowTrailReq {
@@ -698,15 +693,9 @@ struct TShowTrailReq {
   2: optional string trailId
 }
 
-struct TTrailInfo {
-  1: required string modelId
-  2: required string trailId
-  3: required map<string, string> trailInfo
-}
-
 struct TShowTrailResp {
   1: required common.TSStatus status
-  2: required list<TTrailInfo> trailInfoList
+  2: required list<binary> trailInfoList
 }
 
 struct TUpdateModelInfoReq {