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/incubator-iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 3f9709f  record mlog at last (#1098)
3f9709f is described below

commit 3f9709f820ed73d23933c1919568e630aff5cfbf
Author: Jialin Qiao <[email protected]>
AuthorDate: Sat Apr 25 22:01:47 2020 +0800

    record mlog at last (#1098)
---
 .../org/apache/iotdb/db/metadata/MManager.java     | 56 ++++++++++------------
 1 file changed, 26 insertions(+), 30 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 53f6f10..9c66700 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
@@ -78,6 +78,7 @@ public class MManager {
   // tag key -> tag value -> LeafMNode
   private Map<String, Map<String, Set<LeafMNode>>> tagIndex = new HashMap<>();
 
+  // storage group name -> the series number
   private Map<String, Integer> seriesNumberInStorageGroups = new HashMap<>();
   private long maxSeriesNumberAmongStorageGroup;
   private boolean initialized;
@@ -139,11 +140,6 @@ public class MManager {
     try {
       tagLogFile = new TagLogFile(config.getSchemaDir(), 
MetadataConstant.TAG_LOG);
 
-      if (config.isEnableParameterAdapter()) {
-        // storage group name -> the series number
-        seriesNumberInStorageGroups = new HashMap<>();
-      }
-
       initFromLog(logFile);
 
       if (config.isEnableParameterAdapter()) {
@@ -196,9 +192,7 @@ public class MManager {
       this.mtree = new MTree();
       this.mNodeCache.clear();
       this.tagIndex.clear();
-      if (seriesNumberInStorageGroups != null) {
-        this.seriesNumberInStorageGroups.clear();
-      }
+      this.seriesNumberInStorageGroups.clear();
       this.maxSeriesNumberAmongStorageGroup = 0;
       if (logWriter != null) {
         logWriter.close();
@@ -308,17 +302,6 @@ public class MManager {
         throw e;
       }
 
-      // write log
-      if (writeToLog) {
-        // either tags or attributes is not empty
-        if ((plan.getTags() != null && !plan.getTags().isEmpty()) || 
(plan.getAttributes() != null
-            && !plan.getAttributes().isEmpty())) {
-          offset = tagLogFile.write(plan.getTags(), plan.getAttributes());
-        }
-        logWriter.createTimeseries(plan, offset);
-      }
-      leafMNode.setOffset(offset);
-
       // update tag index
       if (plan.getTags() != null) {
         // tag key, tag value
@@ -337,6 +320,18 @@ public class MManager {
           maxSeriesNumberAmongStorageGroup = size + 1;
         }
       }
+
+      // write log
+      if (writeToLog) {
+        // either tags or attributes is not empty
+        if ((plan.getTags() != null && !plan.getTags().isEmpty()) || 
(plan.getAttributes() != null
+            && !plan.getAttributes().isEmpty())) {
+          offset = tagLogFile.write(plan.getTags(), plan.getAttributes());
+        }
+        logWriter.createTimeseries(plan, offset);
+      }
+      leafMNode.setOffset(offset);
+
     } catch (IOException | ConfigAdjusterException e) {
       throw new MetadataException(e.getMessage());
     } finally {
@@ -439,9 +434,7 @@ public class MManager {
       Pair<String, LeafMNode> pair = 
mtree.deleteTimeseriesAndReturnEmptyStorageGroup(path);
       removeFromTagInvertedIndex(pair.right);
       String storageGroupName = pair.left;
-      if (writeToLog) {
-        logWriter.deleteTimeseries(path);
-      }
+
       // TODO: delete the path node and all its ancestors
       mNodeCache.clear();
       try {
@@ -459,6 +452,10 @@ public class MManager {
               .ifPresent(val -> maxSeriesNumberAmongStorageGroup = val);
         }
       }
+
+      if (writeToLog) {
+        logWriter.deleteTimeseries(path);
+      }
       return storageGroupName;
     } finally {
       lock.writeLock().unlock();
@@ -474,15 +471,15 @@ public class MManager {
     lock.writeLock().lock();
     try {
       mtree.setStorageGroup(storageGroup);
-      if (writeToLog) {
-        logWriter.setStorageGroup(storageGroup);
-      }
       IoTDBConfigDynamicAdapter.getInstance().addOrDeleteStorageGroup(1);
 
       if (config.isEnableParameterAdapter()) {
         ActiveTimeSeriesCounter.getInstance().init(storageGroup);
         seriesNumberInStorageGroups.put(storageGroup, 0);
       }
+      if (writeToLog) {
+        logWriter.setStorageGroup(storageGroup);
+      }
     } catch (IOException e) {
       throw new MetadataException(e.getMessage());
     } catch (ConfigAdjusterException e) {
@@ -504,11 +501,6 @@ public class MManager {
       for (String storageGroup : storageGroups) {
         // try to delete storage group
         mtree.deleteStorageGroup(storageGroup);
-
-        // if success
-        if (writeToLog) {
-          logWriter.deleteStorageGroup(storageGroup);
-        }
         mNodeCache.clear();
 
         if (config.isEnableParameterAdapter()) {
@@ -526,6 +518,10 @@ public class MManager {
             }
           }
         }
+        // if success
+        if (writeToLog) {
+          logWriter.deleteStorageGroup(storageGroup);
+        }
       }
     } catch (ConfigAdjusterException e) {
       throw new MetadataException(e);

Reply via email to