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 bdb5d3e  Optimize synchronizing scope in MLogWriter.java (#2448)
bdb5d3e is described below

commit bdb5d3e9cfc7cb70885fd4388f35d09b155c5bda
Author: Al Wei <[email protected]>
AuthorDate: Mon Jan 11 17:12:47 2021 +0800

    Optimize synchronizing scope in MLogWriter.java (#2448)
    
    * [MOD] remove all unnecessary try catch clause in MLogWriter.java when 
storing data into mlog.bin file
    
    * [MOD] optimize the scope of synchronizing block
    
    Co-authored-by: weizihan0110 <[email protected]>
---
 .../iotdb/db/metadata/logfile/MLogWriter.java      | 142 +++++++--------------
 1 file changed, 44 insertions(+), 98 deletions(-)

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 ba9d831..e733813 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
@@ -61,7 +61,7 @@ import java.util.Map;
 public class MLogWriter implements AutoCloseable {
 
   private static final Logger logger = 
LoggerFactory.getLogger(MLogWriter.class);
-  private File logFile;
+  private final File logFile;
   private LogWriter logWriter;
   private int logNum;
   private static final String DELETE_FAILED_FORMAT = "Deleting %s failed with 
exception %s";
@@ -104,125 +104,76 @@ public class MLogWriter implements AutoCloseable {
     mlogBuffer.clear();
   }
 
-  private void putLog(PhysicalPlan plan) {
+  private synchronized void putLog(PhysicalPlan plan) throws IOException {
     try {
       plan.serialize(mlogBuffer);
       sync();
       logNum ++;
     } catch (BufferOverflowException e) {
-      logger.warn("MLog {} BufferOverflow !", plan.getOperatorType(), e);
+      throw new IOException(
+          LOG_TOO_LARGE_INFO, e);
     }
   }
 
-  public synchronized void createTimeseries(CreateTimeSeriesPlan 
createTimeSeriesPlan) throws IOException {
-    try {
-      putLog(createTimeSeriesPlan);
-    } catch (BufferOverflowException e) {
-      throw new IOException(
-        LOG_TOO_LARGE_INFO, e);
-    }
+  public void createTimeseries(CreateTimeSeriesPlan createTimeSeriesPlan) 
throws IOException {
+    putLog(createTimeSeriesPlan);
   }
 
-  public synchronized void deleteTimeseries(DeleteTimeSeriesPlan 
deleteTimeSeriesPlan) throws IOException {
-    try {
-      putLog(deleteTimeSeriesPlan);
-    } catch (BufferOverflowException e) {
-      throw new IOException(
-        LOG_TOO_LARGE_INFO, e);
-    }
+  public void deleteTimeseries(DeleteTimeSeriesPlan deleteTimeSeriesPlan) 
throws IOException {
+    putLog(deleteTimeSeriesPlan);
   }
 
-  public synchronized void setStorageGroup(PartialPath storageGroup) throws 
IOException {
-    try {
-      SetStorageGroupPlan plan = new SetStorageGroupPlan(storageGroup);
-      putLog(plan);
-    } catch (BufferOverflowException e) {
-      throw new IOException(
-        LOG_TOO_LARGE_INFO, e);
-    }
+  public void setStorageGroup(PartialPath storageGroup) throws IOException {
+    SetStorageGroupPlan plan = new SetStorageGroupPlan(storageGroup);
+    putLog(plan);
   }
 
-  public synchronized void deleteStorageGroup(PartialPath storageGroup) throws 
IOException {
-    try {
-      DeleteStorageGroupPlan plan = new 
DeleteStorageGroupPlan(Collections.singletonList(storageGroup));
-      putLog(plan);
-    } catch (BufferOverflowException e) {
-      throw new IOException(
-        LOG_TOO_LARGE_INFO, e);
-    }
+  public void deleteStorageGroup(PartialPath storageGroup) throws IOException {
+    DeleteStorageGroupPlan plan = new 
DeleteStorageGroupPlan(Collections.singletonList(storageGroup));
+    putLog(plan);
   }
 
-  public synchronized void setTTL(PartialPath storageGroup, long ttl) throws 
IOException {
-    try {
-      SetTTLPlan plan = new SetTTLPlan(storageGroup, ttl);
-      putLog(plan);
-    } catch (BufferOverflowException e) {
-      throw new IOException(
-        LOG_TOO_LARGE_INFO, e);
-    }
+  public void setTTL(PartialPath storageGroup, long ttl) throws IOException {
+    SetTTLPlan plan = new SetTTLPlan(storageGroup, ttl);
+    putLog(plan);
   }
 
-  public synchronized void changeOffset(PartialPath path, long offset) throws 
IOException {
-    try {
-      ChangeTagOffsetPlan plan = new ChangeTagOffsetPlan(path, offset);
-      putLog(plan);
-    } catch (BufferOverflowException e) {
-      throw new IOException(
-        LOG_TOO_LARGE_INFO, e);
-    }
+  public void changeOffset(PartialPath path, long offset) throws IOException {
+    ChangeTagOffsetPlan plan = new ChangeTagOffsetPlan(path, offset);
+    putLog(plan);
   }
 
-  public synchronized void changeAlias(PartialPath path, String alias) throws 
IOException {
-    try {
-      ChangeAliasPlan plan = new ChangeAliasPlan(path, alias);
-      putLog(plan);
-    } catch (BufferOverflowException e) {
-      throw new IOException(
-        LOG_TOO_LARGE_INFO, e);
-    }
+  public void changeAlias(PartialPath path, String alias) throws IOException {
+    ChangeAliasPlan plan = new ChangeAliasPlan(path, alias);
+    putLog(plan);
   }
 
-  public synchronized void serializeMNode(MNode node) throws IOException {
-    try {
-      int childSize = 0;
-      if (node.getChildren() != null) {
-        childSize = node.getChildren().size();
-      }
-      MNodePlan plan = new MNodePlan(node.getName(), childSize);
-      putLog(plan);
-    } catch (BufferOverflowException e) {
-      throw new IOException(
-        LOG_TOO_LARGE_INFO, e);
+  public void serializeMNode(MNode node) throws IOException {
+    int childSize = 0;
+    if (node.getChildren() != null) {
+      childSize = node.getChildren().size();
     }
+    MNodePlan plan = new MNodePlan(node.getName(), childSize);
+    putLog(plan);
   }
 
-  public synchronized void serializeMeasurementMNode(MeasurementMNode node) 
throws IOException {
-    try {
-      int childSize = 0;
-      if (node.getChildren() != null) {
-        childSize = node.getChildren().size();
-      }
-      MeasurementMNodePlan plan = new MeasurementMNodePlan(node.getName(), 
node.getAlias(),
-        node.getOffset(), childSize, node.getSchema());
-      putLog(plan);
-    } catch (BufferOverflowException e) {
-      throw new IOException(
-        LOG_TOO_LARGE_INFO, e);
+  public void serializeMeasurementMNode(MeasurementMNode node) throws 
IOException {
+    int childSize = 0;
+    if (node.getChildren() != null) {
+      childSize = node.getChildren().size();
     }
+    MeasurementMNodePlan plan = new MeasurementMNodePlan(node.getName(), 
node.getAlias(),
+      node.getOffset(), childSize, node.getSchema());
+    putLog(plan);
   }
 
-  public synchronized void serializeStorageGroupMNode(StorageGroupMNode node) 
throws IOException {
-    try {
-      int childSize = 0;
-      if (node.getChildren() != null) {
-        childSize = node.getChildren().size();
-      }
-      StorageGroupMNodePlan plan = new StorageGroupMNodePlan(node.getName(), 
node.getDataTTL(), childSize);
-      putLog(plan);
-    } catch (BufferOverflowException e) {
-      throw new IOException(
-        LOG_TOO_LARGE_INFO, e);
+  public void serializeStorageGroupMNode(StorageGroupMNode node) throws 
IOException {
+    int childSize = 0;
+    if (node.getChildren() != null) {
+      childSize = node.getChildren().size();
     }
+    StorageGroupMNodePlan plan = new StorageGroupMNodePlan(node.getName(), 
node.getDataTTL(), childSize);
+    putLog(plan);
   }
 
   @SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity 
warning
@@ -326,13 +277,8 @@ public class MLogWriter implements AutoCloseable {
       operation(cmd);
     } else {
       PhysicalPlan plan = convertFromString(cmd);
-      try {
-        if (plan != null) {
-          putLog(plan);
-        }
-      } catch (BufferOverflowException e) {
-        throw new IOException(
-          LOG_TOO_LARGE_INFO, e);
+      if (plan != null) {
+        putLog(plan);
       }
     }
   }

Reply via email to