You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ta...@apache.org on 2023/03/09 13:18:40 UTC
[iotdb] branch rel/1.1 updated: [IOTDB-5616] Fix some code smells (#9241)
This is an automated email from the ASF dual-hosted git repository.
tanxinyu pushed a commit to branch rel/1.1
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/rel/1.1 by this push:
new 2e36fc16d7 [IOTDB-5616] Fix some code smells (#9241)
2e36fc16d7 is described below
commit 2e36fc16d74966cb55f54cf326b3011841111ba2
Author: YuFengLiu <38...@users.noreply.github.com>
AuthorDate: Thu Mar 9 21:18:33 2023 +0800
[IOTDB-5616] Fix some code smells (#9241)
---
.../java/org/apache/iotdb/cli/AbstractCli.java | 54 +++++++++++-----------
.../org/apache/iotdb/tool/AbstractCsvTool.java | 22 +++++----
.../java/org/apache/iotdb/cli/AbstractCliIT.java | 3 +-
.../client/async/AsyncDataNodeClientPool.java | 4 +-
.../iotdb/flink/tsfile/TsFileOutputFormat.java | 2 +-
.../mtree/store/disk/cache/CacheMemoryManager.java | 3 ++
.../tsfile/write/record/datapoint/DataPoint.java | 2 +-
7 files changed, 51 insertions(+), 39 deletions(-)
diff --git a/cli/src/main/java/org/apache/iotdb/cli/AbstractCli.java b/cli/src/main/java/org/apache/iotdb/cli/AbstractCli.java
index fc260f709a..74161ffcb3 100644
--- a/cli/src/main/java/org/apache/iotdb/cli/AbstractCli.java
+++ b/cli/src/main/java/org/apache/iotdb/cli/AbstractCli.java
@@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.iotdb.cli;
import org.apache.iotdb.exception.ArgsErrorException;
@@ -208,7 +209,8 @@ public abstract class AbstractCli {
.argName(TIMEOUT_NAME)
.hasArg()
.desc(
- "The timeout in second. Using the configuration of server if it's not set (optional)")
+ "The timeout in second. "
+ + "Using the configuration of server if it's not set (optional)")
.build();
options.addOption(queryTimeout);
return options;
@@ -246,6 +248,22 @@ public abstract class AbstractCli {
}
}
+ private static int setFetchSize(String specialCmd, String cmd) {
+ String[] values = specialCmd.split("=");
+ if (values.length != 2) {
+ println(String.format("Fetch size format error, please input like %s=10000", SET_FETCH_SIZE));
+ return CODE_ERROR;
+ }
+ try {
+ setFetchSize(cmd.split("=")[1]);
+ } catch (Exception e) {
+ println(String.format("Fetch size format error, %s", e.getMessage()));
+ return CODE_ERROR;
+ }
+ println("Fetch size has set to " + values[1].trim());
+ return CODE_OK;
+ }
+
static void setMaxDisplayNumber(String maxDisplayNum) {
long tmp = Long.parseLong(maxDisplayNum.trim());
if (tmp > Integer.MAX_VALUE) {
@@ -438,8 +456,8 @@ public abstract class AbstractCli {
}
/**
- * if cli has not specified a zondId, it will be set to cli's system timezone by default otherwise
- * for insert and query accuracy cli should set timezone the same for all sessions
+ * if cli has not specified a zoneId, it will be set to cli's system timezone by default otherwise
+ * for insert and query accuracy cli should set timezone the same for all sessions.
*
* @param specialCmd
* @param cmd
@@ -462,22 +480,6 @@ public abstract class AbstractCli {
return CODE_OK;
}
- private static int setFetchSize(String specialCmd, String cmd) {
- String[] values = specialCmd.split("=");
- if (values.length != 2) {
- println(String.format("Fetch size format error, please input like %s=10000", SET_FETCH_SIZE));
- return CODE_ERROR;
- }
- try {
- setFetchSize(cmd.split("=")[1]);
- } catch (Exception e) {
- println(String.format("Fetch size format error, %s", e.getMessage()));
- return CODE_ERROR;
- }
- println("Fetch size has set to " + values[1].trim());
- return CODE_OK;
- }
-
private static int setMaxDisplayNum(String specialCmd, String cmd) {
String[] values = specialCmd.split("=");
if (values.length != 2) {
@@ -594,7 +596,7 @@ public abstract class AbstractCli {
}
/**
- * cache all results
+ * cache all results.
*
* @param resultSet jdbc resultSet
* @param maxSizeList the longest result of every column
@@ -703,12 +705,12 @@ public abstract class AbstractCli {
lists.add(0, new ArrayList<>());
lists.add(1, new ArrayList<>());
- String ACTIVITY_STR = "Activity";
- String ELAPSED_TIME_STR = "Elapsed Time";
- lists.get(0).add(ACTIVITY_STR);
- lists.get(1).add(ELAPSED_TIME_STR);
- maxSizeList.add(0, ACTIVITY_STR.length());
- maxSizeList.add(1, ELAPSED_TIME_STR.length());
+ String activityStr = "Activity";
+ String elapsedTimeStr = "Elapsed Time";
+ lists.get(0).add(activityStr);
+ lists.get(1).add(elapsedTimeStr);
+ maxSizeList.add(0, activityStr.length());
+ maxSizeList.add(1, elapsedTimeStr.length());
List<String> activityList = ((IoTDBJDBCResultSet) resultSet).getActivityList();
List<Long> elapsedTimeList = ((IoTDBJDBCResultSet) resultSet).getElapsedTimeList();
diff --git a/cli/src/main/java/org/apache/iotdb/tool/AbstractCsvTool.java b/cli/src/main/java/org/apache/iotdb/tool/AbstractCsvTool.java
index bcebf62cad..d819e1c316 100644
--- a/cli/src/main/java/org/apache/iotdb/tool/AbstractCsvTool.java
+++ b/cli/src/main/java/org/apache/iotdb/tool/AbstractCsvTool.java
@@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.iotdb.tool;
import org.apache.iotdb.exception.ArgsErrorException;
@@ -29,6 +30,8 @@ import org.apache.commons.cli.Options;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
import org.apache.commons.csv.QuoteMode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.PrintWriter;
@@ -62,7 +65,7 @@ public abstract class AbstractCsvTool {
protected static final int MAX_HELP_CONSOLE_WIDTH = 92;
protected static final String[] TIME_FORMAT =
new String[] {"default", "long", "number", "timestamp"};
- public static final String[] STRING_TIME_FORMAT =
+ protected static final String[] STRING_TIME_FORMAT =
new String[] {
"yyyy-MM-dd HH:mm:ss.SSSX",
"yyyy/MM/dd HH:mm:ss.SSSX",
@@ -113,16 +116,17 @@ public abstract class AbstractCsvTool {
protected static String timeZoneID;
protected static String timeFormat;
protected static Session session;
+ private static final Logger LOGGER = LoggerFactory.getLogger(AbstractCsvTool.class);
- public AbstractCsvTool() {}
+ protected AbstractCsvTool() {}
protected static String checkRequiredArg(String arg, String name, CommandLine commandLine)
throws ArgsErrorException {
String str = commandLine.getOptionValue(arg);
if (str == null) {
String msg = String.format("Required values for option '%s' not provided", name);
- System.out.println(msg);
- System.out.println("Use -help for more information");
+ LOGGER.info(msg);
+ LOGGER.info("Use -help for more information");
throw new ArgsErrorException(msg);
}
return str;
@@ -135,8 +139,7 @@ public abstract class AbstractCsvTool {
zoneId = ZoneId.of(session.getTimeZone());
}
- protected static void parseBasicParams(CommandLine commandLine)
- throws ArgsErrorException, IOException {
+ protected static void parseBasicParams(CommandLine commandLine) throws ArgsErrorException {
host = checkRequiredArg(HOST_ARGS, HOST_NAME, commandLine);
port = checkRequiredArg(PORT_ARGS, PORT_NAME, commandLine);
username = checkRequiredArg(USERNAME_ARGS, USERNAME_NAME, commandLine);
@@ -155,7 +158,7 @@ public abstract class AbstractCsvTool {
return true;
}
}
- System.out.printf(
+ LOGGER.info(
"Input time format %s is not supported, "
+ "please input like yyyy-MM-dd\\ HH:mm:ss.SSS or yyyy-MM-dd'T'HH:mm:ss.SSS%n",
timeFormat);
@@ -221,8 +224,8 @@ public abstract class AbstractCsvTool {
if (headerNames != null) {
csvPrinterWrapper.printRecord(headerNames);
}
- for (List record : records) {
- csvPrinterWrapper.printRecord(record);
+ for (List<Object> CsvRecord : records) {
+ csvPrinterWrapper.printRecord(CsvRecord);
}
csvPrinterWrapper.flush();
csvPrinterWrapper.close();
@@ -262,6 +265,7 @@ public abstract class AbstractCsvTool {
csvPrinter = csvFormat.print(new PrintWriter(filePath));
} catch (IOException e) {
e.printStackTrace();
+ return;
}
}
try {
diff --git a/cli/src/test/java/org/apache/iotdb/cli/AbstractCliIT.java b/cli/src/test/java/org/apache/iotdb/cli/AbstractCliIT.java
index 719a801760..9ae116e0e5 100644
--- a/cli/src/test/java/org/apache/iotdb/cli/AbstractCliIT.java
+++ b/cli/src/test/java/org/apache/iotdb/cli/AbstractCliIT.java
@@ -193,7 +193,8 @@ public class AbstractCliIT {
assertEquals(
OperationResult.CONTINUE_OPER,
- AbstractCli.handleInputCmd(String.format("%s=", AbstractCli.SET_TIME_ZONE), connection));
+ AbstractCli.handleInputCmd(
+ String.format("%s=%s", AbstractCli.SET_TIME_ZONE, "Asis/chongqing"), connection));
assertEquals(
OperationResult.CONTINUE_OPER,
AbstractCli.handleInputCmd(
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/client/async/AsyncDataNodeClientPool.java b/confignode/src/main/java/org/apache/iotdb/confignode/client/async/AsyncDataNodeClientPool.java
index 6b02149ec3..ce07676532 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/client/async/AsyncDataNodeClientPool.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/client/async/AsyncDataNodeClientPool.java
@@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.iotdb.confignode.client.async;
import org.apache.iotdb.common.rpc.thrift.TConsensusGroupId;
@@ -115,6 +116,7 @@ public class AsyncDataNodeClientPool {
clientHandler.getCountDownLatch().await();
} catch (InterruptedException e) {
LOGGER.error("Interrupted during {} on ConfigNode", requestType);
+ Thread.currentThread().interrupt();
}
// Check if there is a DataNode that fails to execute the request, and retry if there exists
@@ -353,7 +355,7 @@ public class AsyncDataNodeClientPool {
}
/**
- * Always call this interface when a DataNode is restarted or removed
+ * Always call this interface when a DataNode is restarted or removed.
*
* @param endPoint The specific DataNode
*/
diff --git a/flink-tsfile-connector/src/main/java/org/apache/iotdb/flink/tsfile/TsFileOutputFormat.java b/flink-tsfile-connector/src/main/java/org/apache/iotdb/flink/tsfile/TsFileOutputFormat.java
index 841a61f995..f5c5a4e980 100644
--- a/flink-tsfile-connector/src/main/java/org/apache/iotdb/flink/tsfile/TsFileOutputFormat.java
+++ b/flink-tsfile-connector/src/main/java/org/apache/iotdb/flink/tsfile/TsFileOutputFormat.java
@@ -56,7 +56,7 @@ public abstract class TsFileOutputFormat<T> extends FileOutputFormat<T> {
private FileOutputStream fos = null;
protected transient TsFileWriter writer = null;
- public TsFileOutputFormat(String path, Schema schema, TSFileConfig config) {
+ protected TsFileOutputFormat(String path, Schema schema, TSFileConfig config) {
super(path == null ? null : new Path(path));
this.schema = Preconditions.checkNotNull(schema);
this.config = config;
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/mtree/store/disk/cache/CacheMemoryManager.java b/server/src/main/java/org/apache/iotdb/db/metadata/mtree/store/disk/cache/CacheMemoryManager.java
index 1fdd34e6c2..63656f9ac6 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/mtree/store/disk/cache/CacheMemoryManager.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/mtree/store/disk/cache/CacheMemoryManager.java
@@ -122,6 +122,7 @@ public class CacheMemoryManager {
}
} catch (InterruptedException e) {
logger.info("ReleaseTaskMonitor thread is interrupted.");
+ Thread.currentThread().interrupt();
}
});
flushTaskMonitor.submit(
@@ -140,6 +141,7 @@ public class CacheMemoryManager {
}
} catch (InterruptedException e) {
logger.info("FlushTaskMonitor thread is interrupted.");
+ Thread.currentThread().interrupt();
}
});
}
@@ -180,6 +182,7 @@ public class CacheMemoryManager {
logger.warn(
"Interrupt because the release task and flush task did not finish within {} milliseconds.",
MAX_WAITING_TIME_WHEN_RELEASING);
+ Thread.currentThread().interrupt();
}
}
}
diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/write/record/datapoint/DataPoint.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/write/record/datapoint/DataPoint.java
index 4c81358741..17c22214c2 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/write/record/datapoint/DataPoint.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/write/record/datapoint/DataPoint.java
@@ -45,7 +45,7 @@ public abstract class DataPoint {
* @param type value type of this DataPoint
* @param measurementId measurementId of this DataPoint
*/
- public DataPoint(TSDataType type, String measurementId) {
+ protected DataPoint(TSDataType type, String measurementId) {
this.type = type;
this.measurementId = measurementId;
}