You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by do...@apache.org on 2019/02/27 04:10:15 UTC
[incubator-iotdb] branch master updated: [IOTDB-26] client-cli
output error when exiting (#73)
This is an automated email from the ASF dual-hosted git repository.
dope 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 a1e3a30 [IOTDB-26] client-cli output error when exiting (#73)
a1e3a30 is described below
commit a1e3a303a5e62a5d00b261d84b16ad38e044d80a
Author: XuYi <My...@users.noreply.github.com>
AuthorDate: Wed Feb 27 12:10:11 2019 +0800
[IOTDB-26] client-cli output error when exiting (#73)
---
.../org/apache/iotdb/cli/client/AbstractClient.java | 20 +++++++++++++-------
.../java/org/apache/iotdb/cli/client/Client.java | 14 +++++++++-----
.../java/org/apache/iotdb/cli/client/WinClient.java | 14 +++++++++-----
.../apache/iotdb/cli/client/AbstractClientIT.java | 4 ++--
.../org/apache/iotdb/db/service/JDBCService.java | 12 ++++++------
.../java/org/apache/iotdb/jdbc/IoTDBConnection.java | 2 +-
6 files changed, 40 insertions(+), 26 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 267355b..6f78f7c 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
@@ -42,6 +42,7 @@ import org.apache.iotdb.cli.tool.ImportCsv;
import org.apache.iotdb.jdbc.IoTDBConnection;
import org.apache.iotdb.jdbc.IoTDBDatabaseMetadata;
import org.apache.iotdb.jdbc.IoTDBMetadataResultSet;
+import org.apache.iotdb.jdbc.IoTDBSQLException;
import org.apache.iotdb.service.rpc.thrift.ServerProperties;
import org.apache.thrift.TException;
@@ -90,6 +91,7 @@ public abstract class AbstractClient {
protected static int fetchSize = 10000;
protected static int maxTimeLength = ISO_DATETIME_LEN;
protected static int maxValueLength = 15;
+ protected static boolean isQuit = false;
/**
* control the width of columns for 'show timeseries path' and 'show storage group'.
* <p>
@@ -493,15 +495,15 @@ public abstract class AbstractClient {
protected static OperationResult handleInputCmd(String cmd, IoTDBConnection connection) {
String specialCmd = cmd.toLowerCase().trim();
- if (specialCmd.equals(QUIT_COMMAND) || specialCmd.equals(EXIT_COMMAND)) {
- println(specialCmd + " normally");
- return OperationResult.RETURN_OPER;
+ if (QUIT_COMMAND.equals(specialCmd) || EXIT_COMMAND.equals(specialCmd)) {
+ isQuit = true;
+ return OperationResult.STOP_OPER;
}
- if (specialCmd.equals(HELP)) {
+ if (HELP.equals(specialCmd)) {
showHelp();
return OperationResult.CONTINUE_OPER;
}
- if (specialCmd.equals(SHOW_METADATA_COMMAND)) {
+ if (SHOW_METADATA_COMMAND.equals(specialCmd)) {
showMetaData(connection);
return OperationResult.CONTINUE_OPER;
}
@@ -526,7 +528,11 @@ public abstract class AbstractClient {
}
if (specialCmd.startsWith(SHOW_TIMEZONE)) {
-
+ try {
+ println("Current time zone: " + connection.getTimeZone());
+ } catch (IoTDBSQLException | TException e) {
+ handleException(e);
+ }
return OperationResult.CONTINUE_OPER;
}
if (specialCmd.startsWith(SHOW_TIMESTAMP_DISPLAY)) {
@@ -714,7 +720,7 @@ public abstract class AbstractClient {
}
enum OperationResult {
- RETURN_OPER, CONTINUE_OPER, NO_OPER
+ STOP_OPER, CONTINUE_OPER, NO_OPER
}
private static void printf(String format, Object ... 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 c9d1d65..bd9ab7c 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
@@ -133,8 +133,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());
@@ -143,13 +143,12 @@ public class Client extends AbstractClient {
s = reader.readLine(IOTDB_CLI_PREFIX + "> ", null);
if (s != null) {
String[] cmds = s.trim().split(";");
- for (int i = 0; i < cmds.length; i++) {
+ for (int i = 0; i < cmds.length && !isQuit; i++) {
String cmd = cmds[i];
if (cmd != null && !"".equals(cmd.trim())) {
OperationResult result = handleInputCmd(cmd, connection);
switch (result) {
- case RETURN_OPER:
- return;
+ case STOP_OPER:
case CONTINUE_OPER:
continue;
default:
@@ -158,7 +157,12 @@ public class Client extends AbstractClient {
}
}
}
+ if(isQuit) {
+ break;
+ }
}
+ connection.close();
+ System.out.println(String.format("%s> exit normally.", IOTDB_CLI_PREFIX));
} catch (SQLException e) {
System.out.println(String
.format("%s> %s Host is %s, port is %s.", IOTDB_CLI_PREFIX, e.getMessage(), host,
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 4e9e2e5..dde9b85 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
@@ -93,8 +93,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());
@@ -104,13 +104,12 @@ public class WinClient extends AbstractClient {
String s = scanner.nextLine();
if (s != null) {
String[] cmds = s.trim().split(";");
- for (int i = 0; i < cmds.length; i++) {
+ for (int i = 0; i < cmds.length && !isQuit; i++) {
String cmd = cmds[i];
if (cmd != null && !"".equals(cmd.trim())) {
OperationResult result = handleInputCmd(cmd, connection);
switch (result) {
- case RETURN_OPER:
- return;
+ case STOP_OPER:
case CONTINUE_OPER:
continue;
default:
@@ -119,7 +118,12 @@ public class WinClient extends AbstractClient {
}
}
}
+ if(isQuit) {
+ break;
+ }
}
+ connection.close();
+ System.out.println(String.format("%s> exit normally.", IOTDB_CLI_PREFIX));
} catch (SQLException e) {
System.out.println(String
.format("%s> %s Host is %s, port is %s.", IOTDB_CLI_PREFIX, e.getMessage(), host,
diff --git a/iotdb-cli/src/test/java/org/apache/iotdb/cli/client/AbstractClientIT.java b/iotdb-cli/src/test/java/org/apache/iotdb/cli/client/AbstractClientIT.java
index 275bb9b..2fe6ee8 100644
--- a/iotdb-cli/src/test/java/org/apache/iotdb/cli/client/AbstractClientIT.java
+++ b/iotdb-cli/src/test/java/org/apache/iotdb/cli/client/AbstractClientIT.java
@@ -141,8 +141,8 @@ public class AbstractClientIT {
@Test
public void testHandleInputInputCmd() {
- assertEquals(OperationResult.RETURN_OPER, AbstractClient.handleInputCmd(AbstractClient.EXIT_COMMAND, connection));
- assertEquals(OperationResult.RETURN_OPER, AbstractClient.handleInputCmd(AbstractClient.QUIT_COMMAND, connection));
+ assertEquals(OperationResult.STOP_OPER, AbstractClient.handleInputCmd(AbstractClient.EXIT_COMMAND, connection));
+ assertEquals(OperationResult.STOP_OPER, AbstractClient.handleInputCmd(AbstractClient.QUIT_COMMAND, connection));
assertEquals(OperationResult.CONTINUE_OPER, AbstractClient.handleInputCmd(AbstractClient.SHOW_METADATA_COMMAND, connection));
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/service/JDBCService.java b/iotdb/src/main/java/org/apache/iotdb/db/service/JDBCService.java
index f75b62f..cb28312 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/service/JDBCService.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/service/JDBCService.java
@@ -70,14 +70,14 @@ public class JDBCService implements JDBCServiceMBean, IService {
public String getJDBCServiceStatus() {
// TODO debug log, will be deleted in production env
if(startLatch == null) {
- LOGGER.debug("Start latch is null when getting status");
+ LOGGER.info("Start latch is null when getting status");
} else {
- LOGGER.debug("Start latch is {} when getting status", startLatch.getCount());
+ LOGGER.info("Start latch is {} when getting status", startLatch.getCount());
}
if(stopLatch == null) {
- LOGGER.debug("Stop latch is null when getting status");
+ LOGGER.info("Stop latch is null when getting status");
} else {
- LOGGER.debug("Stop latch is {} when getting status", stopLatch.getCount());
+ LOGGER.info("Stop latch is {} when getting status", stopLatch.getCount());
}
// debug log, will be deleted in production env
@@ -218,9 +218,9 @@ public class JDBCService implements JDBCServiceMBean, IService {
close();
// TODO debug log, will be deleted in production env
if(threadStopLatch == null) {
- LOGGER.debug("Stop Count Down latch is null");
+ LOGGER.info("Stop Count Down latch is null");
} else {
- LOGGER.debug("Stop Count Down latch is {}", threadStopLatch.getCount());
+ LOGGER.info("Stop Count Down latch is {}", threadStopLatch.getCount());
}
// debug log, will be deleted in production env
diff --git a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
index fbb1aa2..871a665 100644
--- a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
+++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
@@ -131,7 +131,7 @@ public class IoTDBConnection implements Connection {
try {
client.closeSession(req);
} catch (TException e) {
- throw new SQLException("Error occurs when closing session at server", e);
+ throw new SQLException("Error occurs when closing session at server. Maybe server is down.", e);
} finally {
isClosed = true;
if (transport != null) {