You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2020/06/11 11:11:15 UTC

[incubator-iotdb] branch bug/AlterBug created (now 0706737)

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

jackietien pushed a change to branch bug/AlterBug
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git.


      at 0706737  add more remove tag log

This branch includes the following new commits:

     new 0706737  add more remove tag log

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[incubator-iotdb] 01/01: add more remove tag log

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 0706737785005da38d0c13cfafd6b14b480b16b6
Author: JackieTien97 <Ja...@foxmail.com>
AuthorDate: Thu Jun 11 12:31:19 2020 +0800

    add more remove tag log
---
 .../org/apache/iotdb/db/metadata/MManager.java     | 115 +++++++++++++++++----
 1 file changed, 96 insertions(+), 19 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/MManager.java b/server/src/main/java/org/apache/iotdb/db/metadata/MManager.java
index 5995fc8..9c20c8e 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/MManager.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/MManager.java
@@ -435,6 +435,12 @@ public class MManager {
       for (Entry<String, String> entry : tagMap.entrySet()) {
         if (tagIndex.containsKey(entry.getKey()) && tagIndex.get(entry.getKey())
             .containsKey(entry.getValue())) {
+          if (logger.isDebugEnabled()) {
+            logger.debug(String.format(
+                "Delete: TimeSeries %s is removed from tag inverted index, "
+                    + "tag key is %s, tag value is %s, tlog offset is %d",
+                node.getFullPath(), entry.getKey(), entry.getValue(), node.getOffset()));
+          }
           tagIndex.get(entry.getKey()).get(entry.getValue()).remove(node);
           if (tagIndex.get(entry.getKey()).get(entry.getValue()).isEmpty()) {
             tagIndex.get(entry.getKey()).remove(entry.getValue());
@@ -443,11 +449,11 @@ public class MManager {
             }
           }
         } else {
-          if (logger.isWarnEnabled()) {
-            logger.warn(String.format(
-                "TimeSeries %s's tag info has been removed from tag inverted index before "
-                    + "deleting it, tag key is %s, tag value is %s",
-                node.getFullPath(), entry.getKey(), entry.getValue()));
+          if (logger.isDebugEnabled()) {
+            logger.debug(String.format(
+                "Delete: TimeSeries %s's tag info has been removed from tag inverted index before "
+                    + "deleting it, tag key is %s, tag value is %s, tlog offset is %d, contains key %b",
+                node.getFullPath(), entry.getKey(), entry.getValue(), node.getOffset(), tagIndex.containsKey(entry.getKey())));
           }
         }
       }
@@ -526,12 +532,15 @@ public class MManager {
     lock.writeLock().lock();
     try {
       for (String storageGroup : storageGroups) {
+
+        // clear cached MNode
+        mNodeCache.clear();
+
         // try to delete storage group
         List<LeafMNode> leafMNodes = mtree.deleteStorageGroup(storageGroup);
         for (LeafMNode leafMNode : leafMNodes) {
           removeFromTagInvertedIndex(leafMNode);
         }
-        mNodeCache.clear();
 
         if (config.isEnableParameterAdapter()) {
           IoTDBConfigDynamicAdapter.getInstance().addOrDeleteStorageGroup(-1);
@@ -750,6 +759,7 @@ public class MManager {
         throw new MetadataException("The key " + plan.getKey() + " is not a tag.");
       }
       Set<LeafMNode> allMatchedNodes = new TreeSet<>(Comparator.comparing(MNode::getFullPath));
+
       if (plan.isContains()) {
         for (Entry<String, Set<LeafMNode>> entry : value2Node.entrySet()) {
           String tagValue = entry.getKey();
@@ -1118,9 +1128,26 @@ public class MManager {
           // if the key has existed and the value is not equal to the new one
           // we should remove before key-value from inverted index map
           if (beforeValue != null && !beforeValue.equals(value)) {
-            tagIndex.get(key).get(beforeValue).remove(leafMNode);
-            if (tagIndex.get(key).get(beforeValue).isEmpty()) {
-              tagIndex.get(key).remove(beforeValue);
+
+            if (tagIndex.containsKey(key) && tagIndex.get(key).containsKey(beforeValue)) {
+              if (logger.isDebugEnabled()) {
+                logger.debug(String.format(
+                    "Upsert: TimeSeries %s is removed from tag inverted index, "
+                        + "tag key is %s, tag value is %s, tlog offset is %d",
+                    leafMNode.getFullPath(), key, beforeValue, leafMNode.getOffset()));
+              }
+
+              tagIndex.get(key).get(beforeValue).remove(leafMNode);
+              if (tagIndex.get(key).get(beforeValue).isEmpty()) {
+                tagIndex.get(key).remove(beforeValue);
+              }
+            } else {
+              if (logger.isDebugEnabled()) {
+                logger.debug(String.format(
+                    "Upsert: TimeSeries %s's tag info has been removed from tag inverted index "
+                        + "before deleting it, tag key is %s, tag value is %s, tlog offset is %d, contains key %b",
+                    leafMNode.getFullPath(), key, beforeValue, leafMNode.getOffset(), tagIndex.containsKey(key)));
+              }
             }
           }
 
@@ -1132,9 +1159,7 @@ public class MManager {
           }
         }
       }
-      if (tagsMap != null) {
-        pair.left.putAll(tagsMap);
-      }
+
       pair.right.putAll(attributesMap);
 
       // persist the change to disk
@@ -1281,13 +1306,30 @@ public class MManager {
         String key = entry.getKey();
         String value = entry.getValue();
         // change the tag inverted index map
-        tagIndex.get(key).get(value).remove(leafMNode);
-        if (tagIndex.get(key).get(value).isEmpty()) {
-          tagIndex.get(key).remove(value);
-          if (tagIndex.get(key).isEmpty()) {
-            tagIndex.remove(key);
+        if (tagIndex.containsKey(key) && tagIndex.get(key).containsKey(value)) {
+          if (logger.isDebugEnabled()) {
+            logger.debug(String.format(
+                "Drop: TimeSeries %s is removed from tag inverted index, "
+                    + "tag key is %s, tag value is %s, tlog offset is %d",
+                leafMNode.getFullPath(), entry.getKey(), entry.getValue(), leafMNode.getOffset()));
+          }
+
+          tagIndex.get(key).get(value).remove(leafMNode);
+          if (tagIndex.get(key).get(value).isEmpty()) {
+            tagIndex.get(key).remove(value);
+            if (tagIndex.get(key).isEmpty()) {
+              tagIndex.remove(key);
+            }
+          }
+        } else {
+          if (logger.isDebugEnabled()) {
+            logger.debug(String.format(
+                "Drop: TimeSeries %s's tag info has been removed from tag inverted index "
+                    + "before deleting it, tag key is %s, tag value is %s, tlog offset is %d, contains key %b",
+                leafMNode.getFullPath(), key, value, leafMNode.getOffset(), tagIndex.containsKey(key)));
           }
         }
+
       }
     } finally {
       lock.writeLock().unlock();
@@ -1345,7 +1387,24 @@ public class MManager {
         String beforeValue = entry.getValue();
         String currentValue = newTagValue.get(key);
         // change the tag inverted index map
-        tagIndex.get(key).get(beforeValue).remove(leafMNode);
+        if (tagIndex.containsKey(key) && tagIndex.get(key).containsKey(beforeValue)) {
+
+          if (logger.isDebugEnabled()) {
+            logger.debug(String.format(
+                "Set: TimeSeries %s is removed from tag inverted index, "
+                    + "tag key is %s, tag value is %s, tlog offset is %d",
+                leafMNode.getFullPath(), entry.getKey(), beforeValue, leafMNode.getOffset()));
+          }
+
+          tagIndex.get(key).get(beforeValue).remove(leafMNode);
+        } else {
+          if (logger.isDebugEnabled()) {
+            logger.debug(String.format(
+                "Set: TimeSeries %s's tag info has been removed from tag inverted index "
+                    + "before deleting it, tag key is %s, tag value is %s, tlog offset is %d, contains key %b",
+                leafMNode.getFullPath(), key, beforeValue, leafMNode.getOffset(), tagIndex.containsKey(key)));
+          }
+        }
         tagIndex.computeIfAbsent(key, k -> new HashMap<>())
             .computeIfAbsent(currentValue, k -> new HashSet<>()).add(leafMNode);
       }
@@ -1392,7 +1451,25 @@ public class MManager {
         // persist the change to disk
         tagLogFile.write(pair.left, pair.right, leafMNode.getOffset());
         // change the tag inverted index map
-        tagIndex.get(oldKey).get(value).remove(leafMNode);
+        if (tagIndex.containsKey(oldKey) && tagIndex.get(oldKey).containsKey(value)) {
+
+          if (logger.isDebugEnabled()) {
+            logger.debug(String.format(
+                "Rename: TimeSeries %s is removed from tag inverted index, "
+                    + "tag key is %s, tag value is %s, tlog offset is %d",
+                leafMNode.getFullPath(), oldKey, value, leafMNode.getOffset()));
+          }
+
+          tagIndex.get(oldKey).get(value).remove(leafMNode);
+
+        } else {
+          if (logger.isDebugEnabled()) {
+            logger.debug(String.format(
+                "Rename: TimeSeries %s's tag info has been removed from tag inverted index "
+                    + "before deleting it, tag key is %s, tag value is %s, tlog offset is %d, contains key %b",
+                leafMNode.getFullPath(), oldKey, value, leafMNode.getOffset(), tagIndex.containsKey(oldKey)));
+          }
+        }
         tagIndex.computeIfAbsent(newKey, k -> new HashMap<>())
             .computeIfAbsent(value, k -> new HashSet<>()).add(leafMNode);
       } else if (pair.right.containsKey(oldKey)) {