You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2021/08/26 10:13:22 UTC

[iotdb] branch master updated: [IOTDB-1594] Fix show timeseries returns incorrect tag value (#3845)

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

haonan 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 228d62d   [IOTDB-1594] Fix show timeseries returns incorrect tag value (#3845)
228d62d is described below

commit 228d62d622eb772f0317e40cc341aa0b49d38af2
Author: zyk990424 <38...@users.noreply.github.com>
AuthorDate: Thu Aug 26 18:12:59 2021 +0800

     [IOTDB-1594] Fix show timeseries returns incorrect tag value (#3845)
---
 docs/SystemDesign/SchemaManager/SchemaManager.md   |   2 +-
 .../zh/SystemDesign/SchemaManager/SchemaManager.md |   2 +-
 .../apache/iotdb/db/metadata/MeasurementMeta.java  |  85 ---------------
 .../org/apache/iotdb/db/metadata/Metadata.java     | 120 ---------------------
 .../iotdb/db/metadata/logfile/MLogTxtWriter.java   |   1 -
 .../iotdb/db/metadata/logfile/MLogWriter.java      |   1 -
 .../{ => logfile}/MetadataOperationType.java       |   2 +-
 .../db/metadata/{logfile => tag}/TagLogFile.java   |  10 +-
 .../apache/iotdb/db/metadata/tag/TagManager.java   |   1 -
 9 files changed, 9 insertions(+), 215 deletions(-)

diff --git a/docs/SystemDesign/SchemaManager/SchemaManager.md b/docs/SystemDesign/SchemaManager/SchemaManager.md
index 3eb42de..27d8882 100644
--- a/docs/SystemDesign/SchemaManager/SchemaManager.md
+++ b/docs/SystemDesign/SchemaManager/SchemaManager.md
@@ -295,7 +295,7 @@ Schema operation examples and the corresponding parsed mlog record:
     > format: 61,path                                                                                                              
 
 ## TLog
-* org.apache.iotdb.db.metadata.logfile.TagLogFile
+* org.apache.iotdb.db.metadata.tag.TagLogFile
 
 All timeseries tag/attribute information will be saved in the tag file, which defaults to data/system/schema/tlog.txt.
 
diff --git a/docs/zh/SystemDesign/SchemaManager/SchemaManager.md b/docs/zh/SystemDesign/SchemaManager/SchemaManager.md
index a705036..167696f 100644
--- a/docs/zh/SystemDesign/SchemaManager/SchemaManager.md
+++ b/docs/zh/SystemDesign/SchemaManager/SchemaManager.md
@@ -288,7 +288,7 @@ mlog.bin 存储二进制编码。我们可以使用 [MlogParser Tool](https://io
     > 格式:61,path
 
 ## 标签文件
-* org.apache.iotdb.db.metadata.logfile.TagLogFile
+* org.apache.iotdb.db.metadata.tag.TagLogFile
 
 所有时间序列的标签/属性信息都会保存在标签文件中,此文件默认为 data/system/schema/tlog.txt。
 
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/MeasurementMeta.java b/server/src/main/java/org/apache/iotdb/db/metadata/MeasurementMeta.java
deleted file mode 100644
index 59a5068..0000000
--- a/server/src/main/java/org/apache/iotdb/db/metadata/MeasurementMeta.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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.metadata;
-
-import org.apache.iotdb.tsfile.read.TimeValuePair;
-import org.apache.iotdb.tsfile.write.schema.IMeasurementSchema;
-
-public class MeasurementMeta {
-  private IMeasurementSchema measurementSchema;
-  private String alias = null; // TODO get schema by alias
-  private TimeValuePair timeValuePair = null;
-
-  public MeasurementMeta(
-      IMeasurementSchema measurementSchema, String alias, TimeValuePair timeValuePair) {
-    this.measurementSchema = measurementSchema;
-    this.alias = alias;
-    this.timeValuePair = timeValuePair;
-  }
-
-  public MeasurementMeta(IMeasurementSchema measurementSchema, String alias) {
-    this.measurementSchema = measurementSchema;
-    this.alias = alias;
-  }
-
-  public MeasurementMeta(IMeasurementSchema measurementSchema) {
-    this.measurementSchema = measurementSchema;
-  }
-
-  public IMeasurementSchema getMeasurementSchema() {
-    return measurementSchema;
-  }
-
-  public void setMeasurementSchema(IMeasurementSchema measurementSchema) {
-    this.measurementSchema = measurementSchema;
-  }
-
-  public String getAlias() {
-    return alias;
-  }
-
-  public void setAlias(String alias) {
-    this.alias = alias;
-  }
-
-  public TimeValuePair getTimeValuePair() {
-    return timeValuePair;
-  }
-
-  public synchronized void updateCachedLast(
-      TimeValuePair timeValuePair, boolean highPriorityUpdate, Long latestFlushedTime) {
-    if (timeValuePair == null || timeValuePair.getValue() == null) {
-      return;
-    }
-
-    if (this.timeValuePair == null) {
-      // If no cached last, (1) a last query (2) an unseq insertion or (3) a seq insertion will
-      // update cache.
-      if (!highPriorityUpdate || latestFlushedTime <= timeValuePair.getTimestamp()) {
-        this.timeValuePair =
-            new TimeValuePair(timeValuePair.getTimestamp(), timeValuePair.getValue());
-      }
-    } else if (timeValuePair.getTimestamp() > this.timeValuePair.getTimestamp()
-        || (timeValuePair.getTimestamp() == this.timeValuePair.getTimestamp()
-            && highPriorityUpdate)) {
-      this.timeValuePair.setTimestamp(timeValuePair.getTimestamp());
-      this.timeValuePair.setValue(timeValuePair.getValue());
-    }
-  }
-}
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/Metadata.java b/server/src/main/java/org/apache/iotdb/db/metadata/Metadata.java
deleted file mode 100644
index 34ddf1c..0000000
--- a/server/src/main/java/org/apache/iotdb/db/metadata/Metadata.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * 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.metadata;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Objects;
-import java.util.Set;
-
-/** This class stores all the metadata info for every deviceId and every timeseries. */
-public class Metadata implements Serializable {
-
-  private Map<String, List<String>> deviceIdMap;
-
-  public Metadata(Map<String, List<String>> deviceIdMap) {
-    this.deviceIdMap = deviceIdMap;
-  }
-
-  public Map<String, List<String>> getDeviceMap() {
-    return deviceIdMap;
-  }
-
-  /** combine multiple metadatas */
-  public static Metadata combineMetadatas(Metadata[] metadatas) {
-    Map<String, List<String>> deviceIdMap = new HashMap<>();
-
-    if (metadatas == null || metadatas.length == 0) {
-      return new Metadata(deviceIdMap);
-    }
-
-    for (int i = 0; i < metadatas.length; i++) {
-      Map<String, List<String>> subDeviceIdMap = metadatas[i].deviceIdMap;
-      for (Entry<String, List<String>> entry : subDeviceIdMap.entrySet()) {
-        List<String> list = deviceIdMap.getOrDefault(entry.getKey(), new ArrayList<>());
-        list.addAll(entry.getValue());
-
-        if (!deviceIdMap.containsKey(entry.getKey())) {
-          deviceIdMap.put(entry.getKey(), list);
-        }
-      }
-      metadatas[i] = null;
-    }
-
-    return new Metadata(deviceIdMap);
-  }
-
-  @Override
-  public String toString() {
-    return deviceIdMap.toString();
-  }
-
-  @Override
-  public boolean equals(Object obj) {
-    if (this == obj) {
-      return true;
-    }
-    if (obj == null) {
-      return false;
-    }
-    if (this.getClass() != obj.getClass()) {
-      return false;
-    }
-
-    Metadata metadata = (Metadata) obj;
-    return deviceIdMapEquals(deviceIdMap, metadata.deviceIdMap);
-  }
-
-  @Override
-  public int hashCode() {
-    return Objects.hash(deviceIdMap);
-  }
-
-  /** only used to check if deviceIdMap is equal to another deviceIdMap */
-  private boolean deviceIdMapEquals(
-      Map<String, List<String>> map1, Map<String, List<String>> map2) {
-    if (!map1.keySet().equals(map2.keySet())) {
-      return false;
-    }
-
-    for (Entry<String, List<String>> entry : map1.entrySet()) {
-      List list1 = entry.getValue();
-      List list2 = map2.get(entry.getKey());
-
-      if (!listEquals(list1, list2)) {
-        return false;
-      }
-    }
-    return true;
-  }
-
-  private boolean listEquals(List list1, List list2) {
-    Set set1 = new HashSet();
-    set1.addAll(list1);
-    Set set2 = new HashSet();
-    set2.addAll(list2);
-
-    return set1.equals(set2);
-  }
-}
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/logfile/MLogTxtWriter.java b/server/src/main/java/org/apache/iotdb/db/metadata/logfile/MLogTxtWriter.java
index 044b3ea..eb6f329 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/logfile/MLogTxtWriter.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/logfile/MLogTxtWriter.java
@@ -20,7 +20,6 @@ package org.apache.iotdb.db.metadata.logfile;
 
 import org.apache.iotdb.db.engine.fileSystem.SystemFileFactory;
 import org.apache.iotdb.db.metadata.MetadataConstant;
-import org.apache.iotdb.db.metadata.MetadataOperationType;
 import org.apache.iotdb.db.qp.physical.crud.CreateTemplatePlan;
 import org.apache.iotdb.db.qp.physical.crud.SetSchemaTemplatePlan;
 import org.apache.iotdb.db.qp.physical.sys.CreateAlignedTimeSeriesPlan;
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/logfile/MLogWriter.java b/server/src/main/java/org/apache/iotdb/db/metadata/logfile/MLogWriter.java
index 320872c..23aeae6 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/logfile/MLogWriter.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/logfile/MLogWriter.java
@@ -22,7 +22,6 @@ import org.apache.iotdb.db.conf.IoTDBDescriptor;
 import org.apache.iotdb.db.engine.fileSystem.SystemFileFactory;
 import org.apache.iotdb.db.exception.metadata.MetadataException;
 import org.apache.iotdb.db.metadata.MetadataConstant;
-import org.apache.iotdb.db.metadata.MetadataOperationType;
 import org.apache.iotdb.db.metadata.PartialPath;
 import org.apache.iotdb.db.metadata.mnode.IMNode;
 import org.apache.iotdb.db.metadata.mnode.IMeasurementMNode;
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/MetadataOperationType.java b/server/src/main/java/org/apache/iotdb/db/metadata/logfile/MetadataOperationType.java
similarity index 97%
rename from server/src/main/java/org/apache/iotdb/db/metadata/MetadataOperationType.java
rename to server/src/main/java/org/apache/iotdb/db/metadata/logfile/MetadataOperationType.java
index e98c85d..58019c7 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/MetadataOperationType.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/logfile/MetadataOperationType.java
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.iotdb.db.metadata;
+package org.apache.iotdb.db.metadata.logfile;
 
 public class MetadataOperationType {
 
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/logfile/TagLogFile.java b/server/src/main/java/org/apache/iotdb/db/metadata/tag/TagLogFile.java
similarity index 97%
rename from server/src/main/java/org/apache/iotdb/db/metadata/logfile/TagLogFile.java
rename to server/src/main/java/org/apache/iotdb/db/metadata/tag/TagLogFile.java
index e2731f4..929898e 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/logfile/TagLogFile.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/tag/TagLogFile.java
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.iotdb.db.metadata.logfile;
+package org.apache.iotdb.db.metadata.tag;
 
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
 import org.apache.iotdb.db.engine.fileSystem.SystemFileFactory;
@@ -93,10 +93,12 @@ public class TagLogFile implements AutoCloseable {
 
   public long write(Map<String, String> tagMap, Map<String, String> attributeMap)
       throws IOException, MetadataException {
-    long offset = fileChannel.position();
     ByteBuffer byteBuffer = convertMapToByteBuffer(tagMap, attributeMap);
-    fileChannel.write(byteBuffer);
-    return offset;
+    synchronized (this) {
+      long offset = fileChannel.position();
+      fileChannel.write(byteBuffer);
+      return offset;
+    }
   }
 
   /** This method does not modify this file's current position. */
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 6062bd3..e9f9b2e 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
@@ -27,7 +27,6 @@ import org.apache.iotdb.db.exception.metadata.MetadataException;
 import org.apache.iotdb.db.metadata.MTree;
 import org.apache.iotdb.db.metadata.MetadataConstant;
 import org.apache.iotdb.db.metadata.PartialPath;
-import org.apache.iotdb.db.metadata.logfile.TagLogFile;
 import org.apache.iotdb.db.metadata.mnode.IMNode;
 import org.apache.iotdb.db.metadata.mnode.IMeasurementMNode;
 import org.apache.iotdb.db.qp.physical.sys.ShowTimeSeriesPlan;