You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by hx...@apache.org on 2019/01/24 13:11:14 UTC

[incubator-iotdb] branch fix_sonar updated: fix checkstyle problem, assert and unused getMaxBytesForCompression() calling in ChunkBuffer, and delete a bad fileSize count method

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

hxd 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 73fe916  fix checkstyle problem, assert and unused getMaxBytesForCompression() calling in ChunkBuffer, and delete a bad fileSize count method
     new a5c8dde  Merge branch 'fix_sonar' of github.com:apache/incubator-iotdb into fix_sonar
73fe916 is described below

commit 73fe916e4140bfecc4d038b98f0e466652d4248a
Author: xiangdong huang <sa...@gmail.com>
AuthorDate: Thu Jan 24 21:10:37 2019 +0800

    fix checkstyle problem, assert and unused getMaxBytesForCompression() calling in ChunkBuffer, and delete a bad fileSize count method
---
 .../org/apache/iotdb/cli/client/AbstractClient.java  |  6 +++---
 .../java/org/apache/iotdb/cli/client/Client.java     | 13 ++++++++-----
 .../java/org/apache/iotdb/cli/client/WinClient.java  | 20 +++++++++++---------
 .../strategy/MaxDiskUsableSpaceFirstStrategy.java    | 12 ++----------
 .../iotdb/db/postback/sender/FileSenderImpl.java     |  4 ++--
 .../apache/iotdb/tsfile/write/chunk/ChunkBuffer.java |  8 +++-----
 6 files changed, 29 insertions(+), 34 deletions(-)

diff --git a/iotdb-cli/src/main/java/org/apache/iotdb/cli/client/AbstractClient.java b/iotdb-cli/src/main/java/org/apache/iotdb/cli/client/AbstractClient.java
index d19a8c4..81aa183 100644
--- a/iotdb-cli/src/main/java/org/apache/iotdb/cli/client/AbstractClient.java
+++ b/iotdb-cli/src/main/java/org/apache/iotdb/cli/client/AbstractClient.java
@@ -132,7 +132,7 @@ public abstract class AbstractClient {
   protected static int[] maxValueLengthForShow = new int[]{75, 45, 8, 8};
   protected static String formatTime = "%" + maxTimeLength + "s|";
   protected static String formatValue = "%" + maxValueLength + "s|";
-  protected static int dividinglinelen = 40;
+  private static final int DIVIDING_LINE_LENGTH = 40;
   protected static String host = "127.0.0.1";
   protected static String port = "6667";
   protected static String username;
@@ -246,7 +246,7 @@ public abstract class AbstractClient {
       }
     }
 
-    System.out.println(StringUtils.repeat('-', dividinglinelen));
+    System.out.println(StringUtils.repeat('-', DIVIDING_LINE_LENGTH));
     if (isShow) {
       int type = res.getType();
       if (type == IoTDBMetadataResultSet.MetadataType.STORAGE_GROUP.ordinal()) { // storage group
@@ -422,7 +422,7 @@ public abstract class AbstractClient {
         System.out.printf(formatValue, resultSetMetaData.getColumnLabel(i));
       }
     }
-    System.out.printf("%n");
+    System.out.println();
   }
 
   protected static String[] removePasswordArgs(String[] args) {
diff --git a/iotdb-cli/src/main/java/org/apache/iotdb/cli/client/Client.java b/iotdb-cli/src/main/java/org/apache/iotdb/cli/client/Client.java
index e4f12b2..da0d8b2 100644
--- a/iotdb-cli/src/main/java/org/apache/iotdb/cli/client/Client.java
+++ b/iotdb-cli/src/main/java/org/apache/iotdb/cli/client/Client.java
@@ -120,7 +120,7 @@ public class Client extends AbstractClient {
       return;
     }
 
-    try(ConsoleReader reader = new ConsoleReader()) {
+    try (ConsoleReader reader = new ConsoleReader()) {
       reader.setExpandEvents(false);
       String s;
 
@@ -132,7 +132,8 @@ public class Client extends AbstractClient {
       if (password == null) {
         password = reader.readLine("please input your password:", '\0');
       }
-      try (IoTDBConnection connection = (IoTDBConnection) DriverManager.getConnection(Config.IOTDB_URL_PREFIX + host + ":" + port + "/", username, password)){
+      try (IoTDBConnection connection = (IoTDBConnection) DriverManager
+          .getConnection(Config.IOTDB_URL_PREFIX + host + ":" + port + "/", username, password)) {
         properties = connection.getServerProperties();
         AGGREGRATE_TIME_LIST.addAll(properties.getSupportedTimeAggregationOperations());
         displayLogo(properties.getVersion());
@@ -158,11 +159,13 @@ public class Client extends AbstractClient {
           }
         }
       } catch (SQLException e) {
-        System.out.println(String.format("%s> %s Host is %s, port is %s.", IOTDB_CLI_PREFIX, e.getMessage(), host, port));
+        System.out.println(String
+            .format("%s> %s Host is %s, port is %s.", IOTDB_CLI_PREFIX, e.getMessage(), host,
+                port));
       }
-    } catch(ArgsErrorException e){
+    } catch (ArgsErrorException e) {
       System.out.println(IOTDB_CLI_PREFIX + "> input params error because" + e.getMessage());
-    }catch (Exception e) {
+    } catch (Exception e) {
       System.out.println(IOTDB_CLI_PREFIX + "> exit client with error " + e.getMessage());
     }
   }
diff --git a/iotdb-cli/src/main/java/org/apache/iotdb/cli/client/WinClient.java b/iotdb-cli/src/main/java/org/apache/iotdb/cli/client/WinClient.java
index cf3473f..be7f0fd 100644
--- a/iotdb-cli/src/main/java/org/apache/iotdb/cli/client/WinClient.java
+++ b/iotdb-cli/src/main/java/org/apache/iotdb/cli/client/WinClient.java
@@ -84,7 +84,7 @@ public class WinClient extends AbstractClient {
       return;
     }
 
-    try (Scanner scanner = new Scanner(System.in)){
+    try (Scanner scanner = new Scanner(System.in)) {
       host = checkRequiredArg(HOST_ARGS, HOST_NAME, commandLine, false, host);
       port = checkRequiredArg(PORT_ARGS, PORT_NAME, commandLine, false, port);
       username = checkRequiredArg(USERNAME_ARGS, USERNAME_NAME, commandLine, true, null);
@@ -92,8 +92,8 @@ public class WinClient extends AbstractClient {
       if (password == null) {
         password = readPassword();
       }
-      try(IoTDBConnection connection = (IoTDBConnection) DriverManager
-                .getConnection(Config.IOTDB_URL_PREFIX + host + ":" + port + "/", username, password)){
+      try (IoTDBConnection connection = (IoTDBConnection) DriverManager
+          .getConnection(Config.IOTDB_URL_PREFIX + host + ":" + port + "/", username, password)) {
         properties = connection.getServerProperties();
         AGGREGRATE_TIME_LIST.addAll(properties.getSupportedTimeAggregationOperations());
         displayLogo(properties.getVersion());
@@ -101,7 +101,7 @@ public class WinClient extends AbstractClient {
         while (true) {
           System.out.print(IOTDB_CLI_PREFIX + "> ");
           String s = scanner.nextLine();
-          if(s != null){
+          if (s != null) {
             String[] cmds = s.trim().split(";");
             for (int i = 0; i < cmds.length; i++) {
               String cmd = cmds[i];
@@ -119,14 +119,16 @@ public class WinClient extends AbstractClient {
             }
           }
         }
-			} catch (SQLException e) {
-        System.out.println(String.format("%s> %s Host is %s, port is %s.", IOTDB_CLI_PREFIX, e.getMessage(), host, port));
+      } catch (SQLException e) {
+        System.out.println(String
+            .format("%s> %s Host is %s, port is %s.", IOTDB_CLI_PREFIX, e.getMessage(), host,
+                port));
       }
     } catch (ArgsErrorException e) {
       System.out.println(IOTDB_CLI_PREFIX + "> input params error because" + e.getMessage());
-    }catch (Exception e) {
-    	System.out.println(IOTDB_CLI_PREFIX + "> exit client with error " + e.getMessage());
-	  }
+    } catch (Exception e) {
+      System.out.println(IOTDB_CLI_PREFIX + "> exit client with error " + e.getMessage());
+    }
   }
 
   private static String readPassword() {
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/conf/directories/strategy/MaxDiskUsableSpaceFirstStrategy.java b/iotdb/src/main/java/org/apache/iotdb/db/conf/directories/strategy/MaxDiskUsableSpaceFirstStrategy.java
index bda3d6e..8ff1450 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/conf/directories/strategy/MaxDiskUsableSpaceFirstStrategy.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/conf/directories/strategy/MaxDiskUsableSpaceFirstStrategy.java
@@ -25,9 +25,6 @@ import java.util.Random;
 
 public class MaxDiskUsableSpaceFirstStrategy extends DirectoryStrategy {
 
-  // disk space is measured by MB
-  private static final double DATA_SIZE_SHIFT = 1024D * 1024;
-
   @Override
   public int nextFolderIndex() {
     return getMaxSpaceFolder();
@@ -41,9 +38,9 @@ public class MaxDiskUsableSpaceFirstStrategy extends DirectoryStrategy {
     long max;
 
     candidates.add(0);
-    max = getUsableSpace(folders.get(0));
+    max = new File(folders.get(0)).getUsableSpace();
     for (int i = 1; i < folders.size(); i++) {
-      long current = getUsableSpace(folders.get(i));
+      long current = new File(folders.get(i)).getUsableSpace();
       if (max < current) {
         candidates.clear();
         candidates.add(i);
@@ -58,9 +55,4 @@ public class MaxDiskUsableSpaceFirstStrategy extends DirectoryStrategy {
 
     return candidates.get(index);
   }
-
-  private long getUsableSpace(String path) {
-    double freespace = new File(path).getUsableSpace() / DATA_SIZE_SHIFT;
-    return (long) freespace;
-  }
 }
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/postback/sender/FileSenderImpl.java b/iotdb/src/main/java/org/apache/iotdb/db/postback/sender/FileSenderImpl.java
index 8f750e4..a308893 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/postback/sender/FileSenderImpl.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/postback/sender/FileSenderImpl.java
@@ -494,7 +494,7 @@ public class FileSenderImpl implements FileSender {
         try {
           PostbackUtils.deleteFile(new File(snapshotPath));
         } catch (IOException e) {
-          e.printStackTrace();
+          LOGGER.error("can not delete file {}, {}", snapshotPath, e.getMessage());
         }
       }
     }
@@ -535,7 +535,7 @@ public class FileSenderImpl implements FileSender {
     for (Entry<String, Set<String>> entry : sendingFileList.entrySet()) {
       Set<String> sendingList = entry.getValue();
       Set<String> sendingSnapshotList = sendingFileSnapshotList.get(entry.getKey());
-      if (sendingSnapshotList.size() == 0) {
+      if (sendingSnapshotList.isEmpty()) {
         continue;
       }
       LOGGER.info("IoTDB post back sender : postback process starts to transfer data of "
diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/write/chunk/ChunkBuffer.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/write/chunk/ChunkBuffer.java
index 6ab899e..7fd9a0e 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/write/chunk/ChunkBuffer.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/write/chunk/ChunkBuffer.java
@@ -99,7 +99,6 @@ public class ChunkBuffer {
     }
     this.maxTimestamp = maxTimestamp;
     int uncompressedSize = data.remaining();
-    compressor.getMaxBytesForCompression(uncompressedSize);
     int compressedSize = 0;
     int compressedPosition = 0;
     byte[] compressedBytes = null;
@@ -107,7 +106,7 @@ public class ChunkBuffer {
     if (compressor.getType().equals(CompressionType.UNCOMPRESSED)) {
       compressedSize = data.remaining();
     } else {
-        compressedBytes = new byte[compressor.getMaxBytesForCompression(uncompressedSize)];
+      compressedBytes = new byte[compressor.getMaxBytesForCompression(uncompressedSize)];
       try {
         compressedPosition = 0;
         // data is never a directByteBuffer now, so we can use data.array()
@@ -141,7 +140,7 @@ public class ChunkBuffer {
     this.totalValueCount += valueCount;
 
     // write page content to temp PBAOS
-    try(WritableByteChannel channel = Channels.newChannel(pageBuffer)) {
+    try (WritableByteChannel channel = Channels.newChannel(pageBuffer)) {
       LOG.debug("start to flush a page data into buffer, buffer position {} ", pageBuffer.size());
       if (compressor.getType().equals(CompressionType.UNCOMPRESSED)) {
         channel.write(data);
@@ -149,7 +148,6 @@ public class ChunkBuffer {
         if (data.isDirect()) {
           channel.write(compressedData);
         } else {
-          assert compressedBytes != null;
           pageBuffer.write(compressedBytes, compressedPosition, compressedSize);
         }
       }
@@ -218,7 +216,7 @@ public class ChunkBuffer {
    */
   public long estimateMaxPageMemSize() {
     // return the sum of size of buffer and page max size
-    return (long)(pageBuffer.size() + estimateMaxPageHeaderSize());
+    return (long) (pageBuffer.size() + estimateMaxPageHeaderSize());
   }
 
   private int estimateMaxPageHeaderSize() {