You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by lt...@apache.org on 2019/04/09 01:33:08 UTC

[incubator-iotdb] branch cluster updated: fix a bug of set read consistency level

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

lta pushed a commit to branch cluster
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git


The following commit(s) were added to refs/heads/cluster by this push:
     new 078ed72  fix a bug of set read consistency level
078ed72 is described below

commit 078ed72c9e792fb1ca2e956bc5a1c8ed4768a40e
Author: lta <li...@163.com>
AuthorDate: Tue Apr 9 09:32:52 2019 +0800

    fix a bug of set read consistency level
---
 .../org/apache/iotdb/cluster/config/ClusterConstant.java |  4 ++--
 .../iotdb/cluster/rpc/service/TSServiceClusterImpl.java  |  2 +-
 .../iotdb/cluster/integration/IoTDBMetadataFetchIT.java  |  2 +-
 .../apache/iotdb/cluster/qp/ClusterQPExecutorTest.java   | 16 ++++++++--------
 .../java/org/apache/iotdb/db/conf/IoTDBConstant.java     |  2 ++
 .../java/org/apache/iotdb/db/service/TSServiceImpl.java  | 13 +++++++++++--
 6 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterConstant.java b/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterConstant.java
index 43adb42..dc73165 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterConstant.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterConstant.java
@@ -24,9 +24,9 @@ public class ClusterConstant {
 
   }
 
-  public static final String SET_READ_METADATA_CONSISTENCY_LEVEL_PATTERN = "set\\s+read\\s+metadata\\s+level\\s+\\d+";
+  public static final String SET_READ_METADATA_CONSISTENCY_LEVEL_PATTERN = "set\\s+read\\s+metadata\\s+level\\s+to\\s+\\d+";
 
-  public static final String SET_READ_DATA_CONSISTENCY_LEVEL_PATTERN = "set\\s+read\\s+data\\s+level\\s+\\d+";
+  public static final String SET_READ_DATA_CONSISTENCY_LEVEL_PATTERN = "set\\s+read\\s+data\\s+level\\s+to\\s+\\d+";
 
   public static final int MAX_CONSISTENCY_LEVEL = 2;
 
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/service/TSServiceClusterImpl.java b/cluster/src/main/java/org/apache/iotdb/cluster/rpc/service/TSServiceClusterImpl.java
index 5a60438..ba4e59d 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/service/TSServiceClusterImpl.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/rpc/service/TSServiceClusterImpl.java
@@ -209,7 +209,7 @@ public class TSServiceClusterImpl extends TSServiceImpl {
         return false;
       }
     } catch (ConsistencyLevelException e){
-      throw new Exception("meet error while executing set consistency level command!", e);
+      throw new Exception(e.getMessage());
     }
   }
 
diff --git a/cluster/src/test/java/org/apache/iotdb/cluster/integration/IoTDBMetadataFetchIT.java b/cluster/src/test/java/org/apache/iotdb/cluster/integration/IoTDBMetadataFetchIT.java
index a94d827..ad95425 100644
--- a/cluster/src/test/java/org/apache/iotdb/cluster/integration/IoTDBMetadataFetchIT.java
+++ b/cluster/src/test/java/org/apache/iotdb/cluster/integration/IoTDBMetadataFetchIT.java
@@ -80,7 +80,7 @@ public class IoTDBMetadataFetchIT {
     Connection connection = null;
     try {
       connection = DriverManager.getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
-      insertSQL(connection, false);
+      insertSQL(connection, true);
       testShowTimeseries(connection);
       testShowTimeseriesPath(connection);
     } finally {
diff --git a/cluster/src/test/java/org/apache/iotdb/cluster/qp/ClusterQPExecutorTest.java b/cluster/src/test/java/org/apache/iotdb/cluster/qp/ClusterQPExecutorTest.java
index 59b0253..60d41b7 100644
--- a/cluster/src/test/java/org/apache/iotdb/cluster/qp/ClusterQPExecutorTest.java
+++ b/cluster/src/test/java/org/apache/iotdb/cluster/qp/ClusterQPExecutorTest.java
@@ -62,7 +62,7 @@ public class ClusterQPExecutorTest {
     assertEquals(CLUSTER_CONFIG.getReadMetadataConsistencyLevel(),
         executor.getReadMetadataConsistencyLevel());
     boolean exec;
-    exec= impl.execSetConsistencyLevel("set read metadata level 1");
+    exec= impl.execSetConsistencyLevel("set read metadata level to 1");
     assertTrue(exec);
     assertEquals(1, executor.getReadMetadataConsistencyLevel());
 
@@ -70,16 +70,16 @@ public class ClusterQPExecutorTest {
     assertEquals(1, executor.getReadMetadataConsistencyLevel());
     assertFalse(exec);
 
-    exec= impl.execSetConsistencyLevel("set read metadata level 2");
+    exec= impl.execSetConsistencyLevel("set read metadata level to 2");
     assertTrue(exec);
     assertEquals(2, executor.getReadMetadataConsistencyLevel());
 
-    exec = impl.execSetConsistencyLevel("set read metadata level -2");
+    exec = impl.execSetConsistencyLevel("set read metadata level to -2");
     assertEquals(2, executor.getReadMetadataConsistencyLevel());
     assertFalse(exec);
 
     try {
-      impl.execSetConsistencyLevel("set read metadata level 90");
+      impl.execSetConsistencyLevel("set read metadata level to 90");
     } catch (Exception e) {
       assertEquals("Consistency level 90 not support", e.getMessage());
     }
@@ -91,7 +91,7 @@ public class ClusterQPExecutorTest {
     assertEquals(CLUSTER_CONFIG.getReadDataConsistencyLevel(),
         executor.getReadDataConsistencyLevel());
     boolean exec;
-    exec= impl.execSetConsistencyLevel("set read data level 1");
+    exec= impl.execSetConsistencyLevel("set read data level to 1");
     assertTrue(exec);
     assertEquals(1, executor.getReadDataConsistencyLevel());
 
@@ -99,16 +99,16 @@ public class ClusterQPExecutorTest {
     assertEquals(1, executor.getReadDataConsistencyLevel());
     assertFalse(exec);
 
-    exec= impl.execSetConsistencyLevel("set read data level 2");
+    exec= impl.execSetConsistencyLevel("set read data level  to 2");
     assertTrue(exec);
     assertEquals(2, executor.getReadDataConsistencyLevel());
 
-    exec = impl.execSetConsistencyLevel("set read data level -2");
+    exec = impl.execSetConsistencyLevel("set read data level  to -2");
     assertEquals(2, executor.getReadDataConsistencyLevel());
     assertFalse(exec);
 
     try {
-      impl.execSetConsistencyLevel("set read data level 90");
+      impl.execSetConsistencyLevel("set read data level  to 90");
     } catch (Exception e) {
       assertEquals("Consistency level 90 not support", e.getMessage());
     }
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/conf/IoTDBConstant.java b/iotdb/src/main/java/org/apache/iotdb/db/conf/IoTDBConstant.java
index f9c5462..48e927f 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/conf/IoTDBConstant.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/conf/IoTDBConstant.java
@@ -57,4 +57,6 @@ public class IoTDBConstant {
   public static final String MIN_TIME = "min_time";
   public static final int MIN_SUPPORTED_JDK_VERSION = 8;
 
+  // for cluster, set read consistency level
+  public static final String SET_READ_CONSISTENCY_LEVEL_PATTERN = "set\\s+read.*level.*";
 }
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java b/iotdb/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
index d5d250a..79dbd53 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
@@ -27,6 +27,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.regex.Pattern;
 import org.apache.iotdb.db.auth.AuthException;
 import org.apache.iotdb.db.auth.AuthorityChecker;
 import org.apache.iotdb.db.auth.authorizer.IAuthorizer;
@@ -523,8 +524,16 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
    * Set consistency level
    */
   public boolean execSetConsistencyLevel(String statement) throws Exception {
-    throw new Exception(
-        "IoTDB Stand-alone version does not support setting read-write consistency level");
+    if (statement == null) {
+      return false;
+    }
+    statement = statement.toLowerCase().trim();
+    if (Pattern.matches(IoTDBConstant.SET_READ_CONSISTENCY_LEVEL_PATTERN, statement)) {
+      throw new Exception(
+          "IoTDB Stand-alone version does not support setting read-write consistency level");
+    } else {
+      return false;
+    }
   }
 
   @Override