You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ea...@apache.org on 2019/01/23 09:12:21 UTC

[incubator-iotdb] branch fix_sonar updated: fix sonar

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

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


The following commit(s) were added to refs/heads/fix_sonar by this push:
     new c182815  fix sonar
     new 6c89da5  Merge remote-tracking branch 'origin/fix_sonar' into fix_sonar
c182815 is described below

commit c182815c5bd0e2eb62b8584b0a2089bc73502f0d
Author: mdf369 <95...@qq.com>
AuthorDate: Wed Jan 23 17:11:53 2019 +0800

    fix sonar
---
 .../org/apache/iotdb/db/service/CloseMergeService.java  | 17 +++++++++--------
 .../main/java/org/apache/iotdb/db/service/IoTDB.java    |  2 +-
 .../java/org/apache/iotdb/db/utils/CommonUtils.java     |  2 +-
 .../main/java/org/apache/iotdb/db/utils/IOUtils.java    |  5 ++++-
 .../java/org/apache/iotdb/db/utils/LoadDataUtils.java   |  3 +--
 .../main/java/org/apache/iotdb/db/utils/MemUtils.java   | 14 +++++++-------
 .../java/org/apache/iotdb/db/utils/PostbackUtils.java   | 13 ++++++++++---
 .../java/org/apache/iotdb/db/utils/TimeValuePair.java   |  5 +++++
 .../java/org/apache/iotdb/db/utils/TsPrimitiveType.java | 17 +++++++++++------
 9 files changed, 49 insertions(+), 29 deletions(-)

diff --git a/iotdb/src/main/java/org/apache/iotdb/db/service/CloseMergeService.java b/iotdb/src/main/java/org/apache/iotdb/db/service/CloseMergeService.java
index 55a4e06..379b9c2 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/service/CloseMergeService.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/service/CloseMergeService.java
@@ -40,10 +40,10 @@ public class CloseMergeService implements IService {
 
   private static final Logger LOGGER = LoggerFactory.getLogger(CloseMergeService.class);
   private static IoTDBConfig dbConfig = IoTDBDescriptor.getInstance().getConfig();
-  private static final long mergeDelay = dbConfig.periodTimeForMerge;
-  private static final long closeDelay = dbConfig.periodTimeForFlush;
-  private static final long mergePeriod = dbConfig.periodTimeForMerge;
-  private static final long closePeriod = dbConfig.periodTimeForFlush;
+  private static final long MERGE_DELAY = dbConfig.periodTimeForMerge;
+  private static final long CLOSE_DELAY = dbConfig.periodTimeForFlush;
+  private static final long MERGE_PERIOD = dbConfig.periodTimeForMerge;
+  private static final long CLOSE_PERIOD = dbConfig.periodTimeForFlush;
   private static CloseMergeService CLOSE_MERGE_SERVICE = new CloseMergeService();
   private MergeServiceThread mergeService = new MergeServiceThread();
   private CloseServiceThread closeService = new CloseServiceThread();
@@ -99,7 +99,7 @@ public class CloseMergeService implements IService {
         isStart = false;
         synchronized (service) {
           service.shutdown();
-          service.notify();
+          service.notifyAll();
         }
         CLOSE_MERGE_SERVICE = null;
         LOGGER.info("Shutdown close and merge service successfully.");
@@ -139,14 +139,15 @@ public class CloseMergeService implements IService {
 
     @Override
     public void run() {
-      service.scheduleWithFixedDelay(mergeService, mergeDelay, mergePeriod, TimeUnit.SECONDS);
-      service.scheduleWithFixedDelay(closeService, closeDelay, closePeriod, TimeUnit.SECONDS);
+      service.scheduleWithFixedDelay(mergeService, MERGE_DELAY, MERGE_PERIOD, TimeUnit.SECONDS);
+      service.scheduleWithFixedDelay(closeService, CLOSE_DELAY, CLOSE_PERIOD, TimeUnit.SECONDS);
       while (!service.isShutdown()) {
         synchronized (service) {
           try {
             service.wait();
           } catch (InterruptedException e) {
-            e.printStackTrace();
+            LOGGER.error("CLose and merge error.", e);
+            Thread.currentThread().interrupt();
           }
         }
       }
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/service/IoTDB.java b/iotdb/src/main/java/org/apache/iotdb/db/service/IoTDB.java
index 2719a29..841027d 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/service/IoTDB.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/service/IoTDB.java
@@ -141,7 +141,7 @@ public class IoTDB implements IoTDBMBean {
    */
   private void systemDataRecovery() throws RecoverException {
     LOGGER.info("{}: start checking write log...", IoTDBConstant.GLOBAL_DB_NAME);
-    // QueryProcessor processor = new QueryProcessor(new OverflowQPExecutor());
+
     WriteLogNodeManager writeLogManager = MultiFileLogNodeManager.getInstance();
     List<String> filenodeNames = null;
     try {
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/utils/CommonUtils.java b/iotdb/src/main/java/org/apache/iotdb/db/utils/CommonUtils.java
index d256069..308c15a 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/utils/CommonUtils.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/utils/CommonUtils.java
@@ -26,7 +26,7 @@ import sun.nio.ch.DirectBuffer;
 
 public class CommonUtils {
 
-  public static int javaVersion = CommonUtils.getJdkVersion();
+  public static final int javaVersion = CommonUtils.getJdkVersion();
 
   /**
    * get JDK version.
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/utils/IOUtils.java b/iotdb/src/main/java/org/apache/iotdb/db/utils/IOUtils.java
index d644ab3..e4612e5 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/utils/IOUtils.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/utils/IOUtils.java
@@ -165,7 +165,10 @@ public class IOUtils {
   public static void replaceFile(File newFile, File oldFile) throws IOException {
     if (!newFile.renameTo(oldFile)) {
       // some OSs need to delete the old file before renaming to it
-      oldFile.delete();
+      if(!oldFile.delete()){
+        throw new IOException(
+                String.format("Cannot delete old user file : %s", oldFile.getPath()));
+      }
       if (!newFile.renameTo(oldFile)) {
         throw new IOException(
             String.format("Cannot replace old user file with new one : %s", newFile.getPath()));
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/utils/LoadDataUtils.java b/iotdb/src/main/java/org/apache/iotdb/db/utils/LoadDataUtils.java
index 2063700..c1720ad 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/utils/LoadDataUtils.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/utils/LoadDataUtils.java
@@ -83,8 +83,7 @@ public class LoadDataUtils {
     try {
       this.extraDataFileWriter = new BufferedWriter(new FileWriter(extraDataFile));
     } catch (IOException e) {
-      LOG.error("create");
-      e.printStackTrace();
+      LOG.error("create", e);
       close();
       return null;
     }
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/utils/MemUtils.java b/iotdb/src/main/java/org/apache/iotdb/db/utils/MemUtils.java
index 11b0129..f1ac22b 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/utils/MemUtils.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/utils/MemUtils.java
@@ -50,19 +50,19 @@ public class MemUtils {
   private static long getPointSize(DataPoint dataPoint) {
     switch (dataPoint.getType()) {
       case INT32:
-        return 8 + 4;
+        return 8 + 4L;
       case INT64:
-        return 8 + 8;
+        return 8 + 8L;
       case FLOAT:
-        return 8 + 4;
+        return 8 + 4L;
       case DOUBLE:
-        return 8 + 8;
+        return 8 + 8L;
       case BOOLEAN:
-        return 8 + 1;
+        return 8 + 1L;
       case TEXT:
         return 8 + dataPoint.getValue().toString().length() * 2;
       default:
-        return 8 + 8;
+        return 8 + 8L;
     }
   }
 
@@ -94,7 +94,7 @@ public class MemUtils {
    */
   public static long getStringMem(String str) {
     // wide char (2 bytes each) and 64B String overhead
-    return str.length() * 2 + 64;
+    return str.length() * 2 + 64L;
   }
 
   /**
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/utils/PostbackUtils.java b/iotdb/src/main/java/org/apache/iotdb/db/utils/PostbackUtils.java
index d525d6b..c7ca0b5 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/utils/PostbackUtils.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/utils/PostbackUtils.java
@@ -19,6 +19,7 @@
 package org.apache.iotdb.db.utils;
 
 import java.io.File;
+import java.io.IOException;
 import java.text.DecimalFormat;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -135,17 +136,23 @@ public class PostbackUtils {
     }
   }
 
-  public static void deleteFile(File file) {
+  public static void deleteFile(File file) throws IOException {
     if (!file.exists()) {
       return;
     }
     if (file.isFile() || file.list().length == 0) {
-      file.delete();
+      if (!file.delete()){
+        throw new IOException(
+                String.format("Cannot delete file : %s", file.getPath()));
+      }
     } else {
       File[] files = file.listFiles();
       for (File f : files) {
         deleteFile(f);
-        f.delete();
+        if(!f.delete()){
+          throw new IOException(
+                  String.format("Cannot delete file : %s", f.getPath()));
+        }
       }
     }
   }
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/utils/TimeValuePair.java b/iotdb/src/main/java/org/apache/iotdb/db/utils/TimeValuePair.java
index fdcbd4f..900d592 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/utils/TimeValuePair.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/utils/TimeValuePair.java
@@ -63,6 +63,11 @@ public class TimeValuePair implements Serializable {
     return false;
   }
 
+  @Override
+  public int hashCode(){
+    return ((Long)timestamp).hashCode() + value.hashCode();
+  }
+
   public int getSize() {
     return 8 + 8 + value.getSize();
   }
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/utils/TsPrimitiveType.java b/iotdb/src/main/java/org/apache/iotdb/db/utils/TsPrimitiveType.java
index 2466eee..1fe7c37 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/utils/TsPrimitiveType.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/utils/TsPrimitiveType.java
@@ -98,9 +98,14 @@ public abstract class TsPrimitiveType implements Serializable {
         .equals(getValue()));
   }
 
+  @Override
+  public int hashCode(){
+    return getValue().hashCode();
+  }
+
   public static class TsBoolean extends TsPrimitiveType {
 
-    public boolean value;
+    private boolean value;
 
     public TsBoolean(boolean value) {
       this.value = value;
@@ -134,7 +139,7 @@ public abstract class TsPrimitiveType implements Serializable {
 
   public static class TsInt extends TsPrimitiveType {
 
-    public int value;
+    private int value;
 
     public TsInt(int value) {
       this.value = value;
@@ -168,7 +173,7 @@ public abstract class TsPrimitiveType implements Serializable {
 
   public static class TsLong extends TsPrimitiveType {
 
-    public long value;
+    private long value;
 
     public TsLong(long value) {
       this.value = value;
@@ -202,7 +207,7 @@ public abstract class TsPrimitiveType implements Serializable {
 
   public static class TsFloat extends TsPrimitiveType {
 
-    public float value;
+    private float value;
 
     public TsFloat(float value) {
       this.value = value;
@@ -236,7 +241,7 @@ public abstract class TsPrimitiveType implements Serializable {
 
   public static class TsDouble extends TsPrimitiveType {
 
-    public double value;
+    private double value;
 
     public TsDouble(double value) {
       this.value = value;
@@ -270,7 +275,7 @@ public abstract class TsPrimitiveType implements Serializable {
 
   public static class TsBinary extends TsPrimitiveType {
 
-    public Binary value;
+    private Binary value;
 
     public TsBinary(Binary value) {
       this.value = value;