You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by zy...@apache.org on 2023/05/19 09:44:25 UTC

[iotdb] branch master updated: [IOTDB-5899] Fix unexpected TemplateNotExistException when deactivating template (#9889)

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

zyk 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 804fe050a07 [IOTDB-5899] Fix unexpected TemplateNotExistException when deactivating template (#9889)
804fe050a07 is described below

commit 804fe050a07efe5d2741884fc6a2217ec1d54d1c
Author: Marcos_Zyk <38...@users.noreply.github.com>
AuthorDate: Fri May 19 17:44:19 2023 +0800

    [IOTDB-5899] Fix unexpected TemplateNotExistException when deactivating template (#9889)
---
 .../db/it/schema/IoTDBDeactivateTemplateIT.java    | 22 ++++++++++++++++++++++
 .../iotdb/db/metadata/mtree/ConfigMTree.java       |  8 +++++---
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBDeactivateTemplateIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBDeactivateTemplateIT.java
index f42afc83379..ddc48ab4f7e 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBDeactivateTemplateIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBDeactivateTemplateIT.java
@@ -274,4 +274,26 @@ public class IoTDBDeactivateTemplateIT extends AbstractSchemaIT {
       }
     }
   }
+
+  @Test
+  public void testPathNotSetAndUsingTemplate() throws Exception {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute("create database root.db.factory0");
+      statement.execute("create database root.db.factory1");
+      statement.execute("create database root.db.factory2");
+
+      statement.execute("set schema template t1 to root.db.factory0");
+      statement.execute("set schema template t1 to root.db.factory1");
+
+      try {
+        statement.execute("deactivate schema template from root.db.**");
+      } catch (SQLException e) {
+        Assert.assertTrue(
+            e.getMessage()
+                .contains(
+                    "Target schema Template is not activated on any path matched by given path pattern"));
+      }
+    }
+  }
 }
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/mtree/ConfigMTree.java b/server/src/main/java/org/apache/iotdb/db/metadata/mtree/ConfigMTree.java
index 170d5127a75..1e5f3294eb0 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/mtree/ConfigMTree.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/mtree/ConfigMTree.java
@@ -549,9 +549,11 @@ public class ConfigMTree {
 
           @Override
           protected Void collectMNode(IConfigMNode node) {
-            result
-                .computeIfAbsent(node.getSchemaTemplateId(), k -> new HashSet<>())
-                .add(getPartialPathFromRootToNode(node));
+            if (node.getSchemaTemplateId() != NON_TEMPLATE && !node.isSchemaTemplatePreUnset()) {
+              result
+                  .computeIfAbsent(node.getSchemaTemplateId(), k -> new HashSet<>())
+                  .add(getPartialPathFromRootToNode(node));
+            }
             return null;
           }