You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/10/25 00:48:12 UTC

[GitHub] [iotdb] MarcosZyk commented on a diff in pull request #7658: [IOTDB-4692] SchemaFile adaptation for cluster metadata validation

MarcosZyk commented on code in PR #7658:
URL: https://github.com/apache/iotdb/pull/7658#discussion_r1003891693


##########
server/src/main/java/org/apache/iotdb/db/metadata/mtree/MTreeBelowSGCachedImpl.java:
##########
@@ -331,6 +335,62 @@ public List<IMeasurementMNode> createAlignedTimeseries(
     }
   }
 
+  @Override
+  public Map<Integer, MetadataException> checkMeasurementExistence(
+      PartialPath devicePath, List<String> measurementList, List<String> aliasList) {
+    IMNode device = null;
+    try {
+      device = getNodeByPath(devicePath);
+    } catch (MetadataException e) {
+      return Collections.emptyMap();
+    }
+    try {
+      if (!device.isEntity()) {
+        return Collections.emptyMap();
+      }
+      Map<Integer, MetadataException> failingMeasurementMap = new HashMap<>();
+      for (int i = 0; i < measurementList.size(); i++) {
+        try {
+          if (store.hasChild(device, measurementList.get(i))) {
+            IMNode node = store.getChild(device, measurementList.get(i));

Review Comment:
   Use ```node = store.getChild``` and judge ```node == null``` to avoid reading disk twice.



##########
integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBMetadataFetchSchemaFileIT.java:
##########
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.db.it.schema;
+
+import org.apache.iotdb.db.metadata.schemaregion.SchemaEngineMode;
+import org.apache.iotdb.it.env.ConfigFactory;
+import org.apache.iotdb.it.framework.IoTDBTestRunner;
+import org.apache.iotdb.itbase.category.ClusterIT;
+import org.apache.iotdb.itbase.category.LocalStandaloneIT;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+/**
+ * Notice that, all test begins with "IoTDB" is integration test. All test which will start the
+ * IoTDB server should be defined as integration test.
+ */
+@RunWith(IoTDBTestRunner.class)
+@Category({LocalStandaloneIT.class, ClusterIT.class})
+public class IoTDBMetadataFetchSchemaFileIT extends IoTDBMetadataFetchIT {
+
+  protected static String schemaEngineMode;
+
+  @Before
+  public void setUp() throws Exception {
+    schemaEngineMode = ConfigFactory.getConfig().getSchemaEngineMode();
+    ConfigFactory.getConfig().setSchemaEngineMode(SchemaEngineMode.Schema_File.toString());

Review Comment:
   What about directly use string to modify the config rather than import ```SchemaEngineMode```?



##########
server/src/main/java/org/apache/iotdb/db/metadata/mtree/MTreeBelowSGCachedImpl.java:
##########
@@ -331,6 +335,62 @@ public List<IMeasurementMNode> createAlignedTimeseries(
     }
   }
 
+  @Override
+  public Map<Integer, MetadataException> checkMeasurementExistence(
+      PartialPath devicePath, List<String> measurementList, List<String> aliasList) {
+    IMNode device = null;
+    try {
+      device = getNodeByPath(devicePath);
+    } catch (MetadataException e) {
+      return Collections.emptyMap();
+    }
+    try {
+      if (!device.isEntity()) {
+        return Collections.emptyMap();
+      }
+      Map<Integer, MetadataException> failingMeasurementMap = new HashMap<>();
+      for (int i = 0; i < measurementList.size(); i++) {
+        try {
+          if (store.hasChild(device, measurementList.get(i))) {
+            IMNode node = store.getChild(device, measurementList.get(i));
+            if (node.isMeasurement()) {
+              if (node.getAsMeasurementMNode().isPreDeleted()) {
+                failingMeasurementMap.put(
+                    i,
+                    new MeasurementInBlackListException(
+                        devicePath.concatNode(measurementList.get(i))));
+              } else {
+                failingMeasurementMap.put(
+                    i,
+                    new MeasurementAlreadyExistException(
+                        devicePath.getFullPath() + "." + measurementList.get(i),
+                        node.getAsMeasurementMNode().getMeasurementPath()));
+              }

Review Comment:
   UnPin the child node after usage.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org