You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by qi...@apache.org on 2022/01/16 06:32:59 UTC

[iotdb] branch master updated: [IOTDB-2181] Fix cluster throw exception when queried tag does not exist (#4613)

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

qiaojialin 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 707c2b4   [IOTDB-2181] Fix cluster throw exception when queried tag does not exist (#4613)
707c2b4 is described below

commit 707c2b46ca8825aea861371d05a6434df20ab98a
Author: Zhong Wang <wa...@alibaba-inc.com>
AuthorDate: Sun Jan 16 14:32:08 2022 +0800

     [IOTDB-2181] Fix cluster throw exception when queried tag does not exist (#4613)
---
 docs/SystemDesign/SchemaManager/SchemaManager.md          |  8 ++++----
 docs/zh/SystemDesign/SchemaManager/SchemaManager.md       |  2 +-
 .../org/apache/iotdb/db/integration/IoTDBTagAlterIT.java  |  7 ++-----
 .../java/org/apache/iotdb/db/integration/IoTDBTagIT.java  | 15 +++++----------
 .../java/org/apache/iotdb/db/metadata/tag/TagManager.java | 13 ++++++++++---
 .../src/test/java/org/apache/iotdb/db/sql/Cases.java      | 12 +++---------
 6 files changed, 25 insertions(+), 32 deletions(-)

diff --git a/docs/SystemDesign/SchemaManager/SchemaManager.md b/docs/SystemDesign/SchemaManager/SchemaManager.md
index 1d9269f..9846e7e 100644
--- a/docs/SystemDesign/SchemaManager/SchemaManager.md
+++ b/docs/SystemDesign/SchemaManager/SchemaManager.md
@@ -35,7 +35,7 @@ Metadata of IoTDB is managed by MManger, including:
 	> tag key -> tag value -> timeseries LeafMNode
 
 In the process of initializing, MManager will replay the mlog to load the metadata into memory. There are seven types of operation log:
-> At the beginning of each operation, it will try to obatin the write lock of MManager, and release it after operation.
+> At the beginning of each operation, it will try to obtain the write lock of MManager, and release it after operation.
 
 * Create Timeseries
     * check if the storage group exists, if not and the auto create is enable, create it.
@@ -92,7 +92,7 @@ In the process of initializing, MManager will replay the mlog to load the metada
 
 In addition to these seven operation that are needed to be logged, there are another six alter operation to tag/attribute info of timeseries.
  
-Same as above, at the beginning of each operation, it will try to obatin the write lock of MManager, and release it after operation.
+Same as above, at the beginning of each operation, it will try to obtain the write lock of MManager, and release it after operation.
 
 * Rename Tag/Attribute
 	* obtain the LeafMNode of that timeseries
@@ -327,11 +327,11 @@ In this case, we need to pass the limit(if not exists, set fetch size as limit)
 
 #### findPath
 
-It's a recursive function to get all the statisfied MNode in MTree from root until the number of timeseries list has reached limit or all the MTree has been traversed.
+It's a recursive function to get all the satisfied MNode in MTree from root until the number of timeseries list has reached limit or all the MTree has been traversed.
 
 ### show timeseries with index
 
-The filter condition here can only be tag attribute, or it will throw an exception.
+Currently, timeseries can only be filtered with tag. If the designated tag does not exist, an empty result set will be returned.
 
 We can fetch all the satisfied `MeasurementMNode` through the inverted tag index in MTree fast without traversing the whole tree.
 
diff --git a/docs/zh/SystemDesign/SchemaManager/SchemaManager.md b/docs/zh/SystemDesign/SchemaManager/SchemaManager.md
index 348fae2..596dd3d 100644
--- a/docs/zh/SystemDesign/SchemaManager/SchemaManager.md
+++ b/docs/zh/SystemDesign/SchemaManager/SchemaManager.md
@@ -324,7 +324,7 @@ mlog.bin 存储二进制编码。我们可以使用 [MlogParser Tool](https://io
 
 ### 带过滤条件的元数据查询
 
-这里的过滤条件只能是 tag 属性,否则抛异常。
+目前仅支持以 tag 为索引条件。如果过滤条件中的 tag 不存在,则会返回空结果集。
 
 通过在 MManager 中维护的 tag 的倒排索引,获得所有满足索引条件的`MeasurementMNode`。
 
diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBTagAlterIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBTagAlterIT.java
index 251e531..e396b3d 100644
--- a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBTagAlterIT.java
+++ b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBTagAlterIT.java
@@ -320,11 +320,8 @@ public class IoTDBTagAlterIT {
       }
       assertEquals(ret2.length, count);
 
-      try {
-        statement.execute("show timeseries where tag1=v1");
-        fail();
-      } catch (Exception e) {
-        assertTrue(e.getMessage().contains("The key tag1 is not a tag"));
+      try (ResultSet rs = statement.executeQuery("show timeseries where tag1=v1")) {
+        assertFalse(rs.next());
       }
     } catch (Exception e) {
       e.printStackTrace();
diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBTagIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBTagIT.java
index 35f7d1b..47bf8b7 100644
--- a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBTagIT.java
+++ b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBTagIT.java
@@ -38,6 +38,7 @@ import java.util.List;
 import java.util.Set;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -992,11 +993,8 @@ public class IoTDBTagIT {
         statement.execute(sql);
       }
 
-      try {
-        statement.execute("show timeseries where H_Alarm=90");
-        fail();
-      } catch (Exception e) {
-        assertTrue(e.getMessage().contains("The key H_Alarm is not a tag"));
+      try (ResultSet rs = statement.executeQuery("show timeseries where H_Alarm=90")) {
+        assertFalse(rs.next());
       }
     } catch (Exception e) {
       e.printStackTrace();
@@ -1059,11 +1057,8 @@ public class IoTDBTagIT {
       assertEquals(ret.size(), count);
 
       statement.execute("delete storage group root.turbine");
-      try {
-        statement.execute("show timeseries where tag1=v1");
-        fail();
-      } catch (Exception e) {
-        assertTrue(e.getMessage().contains("The key tag1 is not a tag"));
+      try (ResultSet rs = statement.executeQuery("show timeseries where tag1=v1")) {
+        assertFalse(rs.next());
       }
     } catch (Exception e) {
       e.printStackTrace();
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/tag/TagManager.java b/server/src/main/java/org/apache/iotdb/db/metadata/tag/TagManager.java
index 1af1f60..cb0da36 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/tag/TagManager.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/tag/TagManager.java
@@ -40,7 +40,14 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
 import static java.util.stream.Collectors.toList;
@@ -117,11 +124,11 @@ public class TagManager {
   public List<IMeasurementMNode> getMatchedTimeseriesInIndex(
       ShowTimeSeriesPlan plan, QueryContext context) throws MetadataException {
     if (!tagIndex.containsKey(plan.getKey())) {
-      throw new MetadataException("The key " + plan.getKey() + " is not a tag.", true);
+      return Collections.emptyList();
     }
     Map<String, Set<IMeasurementMNode>> value2Node = tagIndex.get(plan.getKey());
     if (value2Node.isEmpty()) {
-      throw new MetadataException("The key " + plan.getKey() + " is not a tag.");
+      return Collections.emptyList();
     }
 
     List<IMeasurementMNode> allMatchedNodes = new ArrayList<>();
diff --git a/testcontainer/src/test/java/org/apache/iotdb/db/sql/Cases.java b/testcontainer/src/test/java/org/apache/iotdb/db/sql/Cases.java
index e27cc76..6758a10 100644
--- a/testcontainer/src/test/java/org/apache/iotdb/db/sql/Cases.java
+++ b/testcontainer/src/test/java/org/apache/iotdb/db/sql/Cases.java
@@ -471,15 +471,9 @@ public abstract class Cases {
 
     // try to read data on each node. SHOW TIMESERIES root.ln.wf01.* where tag3=v1"
     for (Statement readStatement : readStatements) {
-      ResultSet resultSet = null;
-      try {
-        resultSet = readStatement.executeQuery("SHOW TIMESERIES root.ln.wf01.* where tag3=v1");
-      } catch (Exception e) {
-        Assert.assertTrue(e.getMessage().contains("The key tag3 is not a tag"));
-      } finally {
-        if (resultSet != null) {
-          resultSet.close();
-        }
+      try (ResultSet rs =
+          readStatement.executeQuery("SHOW TIMESERIES root.ln.wf01.* where tag3=v1")) {
+        Assert.assertFalse(rs.next());
       }
     }
   }