Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public final class CliMessages {
// CliContext
public static final String EXITING_WITH_CODE = "Exiting with code %d";

// Cli
public static final String SUCCESSFULLY_LOGIN_AT = "Successfully login at %s";

Comment thread
HTHou marked this conversation as resolved.
// IoTDBDataBackTool
public static final String TARGET_DIR_EMPTY =
" -targetdir cannot be empty, The backup folder must be specified";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public final class CliMessages {
// CliContext
public static final String EXITING_WITH_CODE = "正在退出,退出码 %d";

// Cli
public static final String SUCCESSFULLY_LOGIN_AT = "成功登录到 %s";

// IoTDBDataBackTool
public static final String TARGET_DIR_EMPTY =
" -targetdir 不能为空,必须指定备份目录";
Expand Down
19 changes: 14 additions & 5 deletions iotdb-client/cli/src/main/java/org/apache/iotdb/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@

package org.apache.iotdb.cli;

import org.apache.iotdb.cli.i18n.CliMessages;
import org.apache.iotdb.cli.type.ExitType;
import org.apache.iotdb.cli.utils.CliContext;
import org.apache.iotdb.cli.utils.JlineUtils;
import org.apache.iotdb.exception.ArgsErrorException;
import org.apache.iotdb.jdbc.Config;
import org.apache.iotdb.jdbc.IoTDBConnection;
import org.apache.iotdb.rpc.RpcUtils;
import org.apache.iotdb.rpc.UrlUtils;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
Expand Down Expand Up @@ -204,8 +206,7 @@ private static void serve(CliContext ctx) {

private static void executeSql(CliContext ctx) throws TException {
try (IoTDBConnection connection =
(IoTDBConnection)
DriverManager.getConnection(Config.IOTDB_URL_PREFIX + host + ":" + port + "/", info)) {
(IoTDBConnection) DriverManager.getConnection(buildJdbcUrl(host, port), info)) {
connection.setQueryTimeout(queryTimeout);
properties = connection.getServerProperties();
timestampPrecision = properties.getTimestampPrecision();
Expand All @@ -220,15 +221,15 @@ private static void executeSql(CliContext ctx) throws TException {

private static void receiveCommands(CliContext ctx) throws TException {
try (IoTDBConnection connection =
(IoTDBConnection)
DriverManager.getConnection(Config.IOTDB_URL_PREFIX + host + ":" + port + "/", info)) {
(IoTDBConnection) DriverManager.getConnection(buildJdbcUrl(host, port), info)) {
connection.setQueryTimeout(queryTimeout);
properties = connection.getServerProperties();
timestampPrecision = properties.getTimestampPrecision();

echoStarting(ctx);
displayLogo(ctx, properties.getLogo(), properties.getVersion(), properties.getBuildInfo());
ctx.getPrinter().println(String.format("Successfully login at %s:%s", host, port));
ctx.getPrinter()
.println(String.format(CliMessages.SUCCESSFULLY_LOGIN_AT, formatEndpoint(host, port)));
while (true) {
boolean readLine = readerReadLine(ctx, connection);
if (readLine) {
Expand All @@ -241,6 +242,14 @@ private static void receiveCommands(CliContext ctx) throws TException {
}
}

private static String formatEndpoint(String host, String port) {
return UrlUtils.formatTEndPointIpv4AndIpv6Url(host, port);
}

private static String buildJdbcUrl(String host, String port) {
return Config.IOTDB_URL_PREFIX + formatEndpoint(host, port) + "/";
}

private static boolean readerReadLine(CliContext ctx, IoTDBConnection connection) {
String s;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.iotdb.isession.SessionDataSet;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.rpc.UrlUtils;
import org.apache.iotdb.session.TableSessionBuilder;
import org.apache.iotdb.tool.common.Constants;

Expand Down Expand Up @@ -65,7 +66,7 @@ public class ExportDataTable extends AbstractExportData {
public void init() throws IoTDBConnectionException, StatementExecutionException {
TableSessionBuilder tableSessionBuilder =
new TableSessionBuilder()
.nodeUrls(Collections.singletonList(host + ":" + port))
.nodeUrls(Collections.singletonList(UrlUtils.formatTEndPointIpv4AndIpv6Url(host, port)))
.username(username)
.password(password)
.database(database)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.iotdb.isession.pool.ITableSessionPool;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.rpc.UrlUtils;
import org.apache.iotdb.session.pool.TableSessionPoolBuilder;
import org.apache.iotdb.tool.common.Constants;
import org.apache.iotdb.tool.tsfile.ImportTsFileScanTool;
Expand Down Expand Up @@ -79,7 +80,7 @@
public void init() throws InterruptedException {
TableSessionPoolBuilder tableSessionPoolBuilder =
new TableSessionPoolBuilder()
.nodeUrls(Collections.singletonList(host + ":" + port))
.nodeUrls(Collections.singletonList(UrlUtils.formatTEndPointIpv4AndIpv6Url(host, port)))
.user(username)
.password(password)
.maxSize(threadNum + 1)
Expand Down Expand Up @@ -133,7 +134,7 @@
}
}
} else {
ioTPrinter.println(String.format(Constants.TARGET_TABLE_NOT_EXIST_MSG, null));

Check warning on line 137 in iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/ImportDataTable.java

View workflow job for this annotation

GitHub Actions / dependency-check (17, ubuntu-latest)

non-varargs call of varargs method with inexact argument type for last parameter;

Check warning on line 137 in iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/ImportDataTable.java

View workflow job for this annotation

GitHub Actions / zh-locale-compile

non-varargs call of varargs method with inexact argument type for last parameter;

Check warning on line 137 in iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/ImportDataTable.java

View workflow job for this annotation

GitHub Actions / sonar

non-varargs call of varargs method with inexact argument type for last parameter;

Check warning on line 137 in iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/ImportDataTable.java

View workflow job for this annotation

GitHub Actions / unit-test (17, ubuntu-latest, others)

non-varargs call of varargs method with inexact argument type for last parameter;

Check warning on line 137 in iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/ImportDataTable.java

View workflow job for this annotation

GitHub Actions / unit-test (17, ubuntu-latest, others)

non-varargs call of varargs method with inexact argument type for last parameter;

Check warning on line 137 in iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/ImportDataTable.java

View workflow job for this annotation

GitHub Actions / Simple (17)

non-varargs call of varargs method with inexact argument type for last parameter;

Check warning on line 137 in iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/ImportDataTable.java

View workflow job for this annotation

GitHub Actions / Ubuntu

non-varargs call of varargs method with inexact argument type for last parameter;

Check warning on line 137 in iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/ImportDataTable.java

View workflow job for this annotation

GitHub Actions / Ubuntu

non-varargs call of varargs method with inexact argument type for last parameter;
System.exit(1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.iotdb.isession.pool.ITableSessionPool;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.rpc.UrlUtils;
import org.apache.iotdb.session.pool.TableSessionPoolBuilder;
import org.apache.iotdb.tool.common.Constants;

Expand Down Expand Up @@ -55,7 +56,7 @@ public class ExportSchemaTable extends AbstractExportSchema {
public void init() throws InterruptedException {
TableSessionPoolBuilder tableSessionPoolBuilder =
new TableSessionPoolBuilder()
.nodeUrls(Collections.singletonList(host + ":" + port))
.nodeUrls(Collections.singletonList(UrlUtils.formatTEndPointIpv4AndIpv6Url(host, port)))
.user(username)
.password(password)
.maxSize(threadNum + 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.iotdb.isession.pool.ITableSessionPool;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.rpc.UrlUtils;
import org.apache.iotdb.session.pool.TableSessionPoolBuilder;
import org.apache.iotdb.tool.common.Constants;
import org.apache.iotdb.tool.data.ImportDataScanTool;
Expand All @@ -51,7 +52,7 @@ public class ImportSchemaTable extends AbstractImportSchema {
public void init() throws InterruptedException {
TableSessionPoolBuilder tableSessionPoolBuilder =
new TableSessionPoolBuilder()
.nodeUrls(Collections.singletonList(host + ":" + port))
.nodeUrls(Collections.singletonList(UrlUtils.formatTEndPointIpv4AndIpv6Url(host, port)))
.user(username)
.password(password)
.maxSize(threadNum + 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ public static String convertTEndPointIpv4AndIpv6Url(TEndPoint endPoint) {

/** Format host and port as host:port or [ipv6]:port. This method expects host without a port. */
public static String formatTEndPointIpv4AndIpv6Url(String host, int port) {
return formatTEndPointIpv4AndIpv6Url(host, String.valueOf(port));
}

/**
* Format host and port as host:port or [ipv6]:port. This method expects host without a port and
* leaves port validation to the endpoint consumer.
*/
public static String formatTEndPointIpv4AndIpv6Url(String host, String port) {
String formattedHost = host;
if (isIpv6Literal(host) && !isBracketedIpv6Literal(host)) {
formattedHost = IPV6_BEGIN_MARK + host + IPV6_END_MARK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public void testConvertIPV4URL() {
@Test
public void testConvertHostNameURL() {
assertEquals("localhost:22227", UrlUtils.formatTEndPointIpv4AndIpv6Url("localhost", 22227));
assertEquals("localhost:22227", UrlUtils.formatTEndPointIpv4AndIpv6Url("localhost", "22227"));
}

@Test
Expand All @@ -122,6 +123,8 @@ public void testConvertIPV6AbbURL() {
public void testConvertBracketedIPV6URL() {
assertEquals(
"[D80::ABAA:0]:22227", UrlUtils.formatTEndPointIpv4AndIpv6Url("[D80::ABAA:0]", 22227));
assertEquals(
"[D80::ABAA:0]:invalid", UrlUtils.formatTEndPointIpv4AndIpv6Url("D80::ABAA:0", "invalid"));
Comment thread
HTHou marked this conversation as resolved.
}

@Test
Expand Down
8 changes: 6 additions & 2 deletions scripts/tools/ops/health_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,14 @@ remote_ports_check() {
if [ -n "$unreachable_ports" ]; then
unreachable_combinations+=("IP: $host, Ports: $unreachable_ports")
fi
display_host="$host"
if [[ "$display_host" == *:* ]] && [[ "${display_host:0:1}" != "[" ]]; then
display_host="[$display_host]"
fi
if [ -n "$ip_port_list" ]; then
ip_port_list="$ip_port_list,$host:$all_ports"
ip_port_list="$ip_port_list,$display_host:$all_ports"
else
ip_port_list="$host:$all_ports"
ip_port_list="$display_host:$all_ports"
fi
done
echo ""
Expand Down
16 changes: 12 additions & 4 deletions scripts/tools/windows/ops/backup.bat
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,32 @@ set "operation_dirs="
set dn_rpc_port_occupied=0
set cn_internal_port_occupied=0

for /f "tokens=1,3,7 delims=: " %%i in ('netstat /ano') do (
for /f "tokens=1,2,5" %%i in ('netstat /ano') do (
set "local_endpoint=%%j"
if "!local_endpoint:~0,1!"=="[" (
set "local_port=!local_endpoint:*]:=!"
) else (
set "local_port=!local_endpoint:*:=!"
)
if %%i==TCP (
if %%j==%dn_rpc_port% (
if !local_port!==%dn_rpc_port% (
if !dn_rpc_port_occupied!==0 (
set spid=%%k
call :checkIfIOTDBProcess !spid! is_iotdb
if !is_iotdb!==1 (
set local_iotdb_occupied_ports=%dn_rpc_port% !local_iotdb_occupied_ports!
)
set dn_rpc_port_occupied=1
)
Comment thread
HTHou marked this conversation as resolved.

) else if %%j==%cn_internal_port% (
) else if !local_port!==%cn_internal_port% (
if !cn_internal_port_occupied!==0 (
set spid=%%k
call :checkIfIOTDBProcess !spid! is_iotdb
if !is_iotdb!==1 (
set local_iotdb_occupied_ports=%cn_internal_port% !local_iotdb_occupied_ports!
)
set cn_internal_port_occupied=1
)
)
)
Expand Down Expand Up @@ -135,4 +143,4 @@ exit /b

:checkFail
echo Please stop IoTDB
exit /b
exit /b
41 changes: 27 additions & 14 deletions scripts/tools/windows/ops/health_check.bat
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ for %%a in (%*) do (
)
:: Append IP and port to the ips string
if !isPort! equ 1 (
set "ips=!ips!,!ip!:%%a"
set "ips=!ips!,!ip!;%%a"
)
)
)
Expand All @@ -72,7 +72,7 @@ for %%a in (%*) do (
)
:: Append IP and port to the ips string
if !isPort! equ 1 (
set "ips=!ips!,!ip!:%%a"
set "ips=!ips!,!ip!;%%a"
)
)
)
Expand Down Expand Up @@ -430,9 +430,15 @@ set dn_data_region_consensus_port_occupied=0
set cn_internal_port_occupied=0
set cn_consensus_port_occupied=0
set local_ports=%dn_rpc_port% %dn_internal_port% %dn_mpp_data_exchange_port% %dn_schema_region_consensus_port% %dn_data_region_consensus_port% %cn_consensus_port% %cn_internal_port%
for /f "tokens=1,3,7 delims=: " %%i in ('netstat /ano') do (
for /f "tokens=1,2,5" %%i in ('netstat /ano') do (
set "local_endpoint=%%j"
if "!local_endpoint:~0,1!"=="[" (
set "local_port=!local_endpoint:*]:=!"
) else (
set "local_port=!local_endpoint:*:=!"
)
if %%i==TCP (
if %%j==%dn_rpc_port% (
if !local_port!==%dn_rpc_port% (
if !dn_rpc_port_occupied!==0 (
set spid=%%k
call :checkIfIOTDBProcess !spid! is_iotdb
Expand All @@ -443,7 +449,7 @@ for /f "tokens=1,3,7 delims=: " %%i in ('netstat /ano') do (
)
set dn_rpc_port_occupied=1
)
) else if %%j==%dn_internal_port% (
) else if !local_port!==%dn_internal_port% (
if !dn_internal_port_occupied!==0 (
set spid=%%k
call :checkIfIOTDBProcess !spid! is_iotdb
Expand All @@ -454,7 +460,7 @@ for /f "tokens=1,3,7 delims=: " %%i in ('netstat /ano') do (
)
set dn_internal_port_occupied=1
)
) else if %%j==%dn_mpp_data_exchange_port% (
) else if !local_port!==%dn_mpp_data_exchange_port% (
if !dn_mpp_data_exchange_port_occupied!==0 (
set spid=%%k
call :checkIfIOTDBProcess !spid! is_iotdb
Expand All @@ -465,7 +471,7 @@ for /f "tokens=1,3,7 delims=: " %%i in ('netstat /ano') do (
)
set dn_mpp_data_exchange_port_occupied=1
)
) else if %%j==%dn_schema_region_consensus_port% (
) else if !local_port!==%dn_schema_region_consensus_port% (
if !dn_schema_region_consensus_port_occupied!==0 (
set spid=%%k
call :checkIfIOTDBProcess !spid! is_iotdb
Expand All @@ -476,7 +482,7 @@ for /f "tokens=1,3,7 delims=: " %%i in ('netstat /ano') do (
)
set dn_schema_region_consensus_port_occupied=1
)
) else if %%j==%dn_data_region_consensus_port% (
) else if !local_port!==%dn_data_region_consensus_port% (
if !dn_data_region_consensus_port_occupied!==0 (
set spid=%%k
call :checkIfIOTDBProcess !spid! is_iotdb
Expand All @@ -488,7 +494,7 @@ for /f "tokens=1,3,7 delims=: " %%i in ('netstat /ano') do (
)
set dn_data_region_consensus_port_occupied=1
)
) else if %%j==%cn_internal_port% (
) else if !local_port!==%cn_internal_port% (
if !cn_internal_port_occupied!==0 (
set spid=%%k
call :checkIfIOTDBProcess !spid! is_iotdb
Expand All @@ -499,7 +505,7 @@ for /f "tokens=1,3,7 delims=: " %%i in ('netstat /ano') do (
)
set cn_internal_port_occupied=1
)
) else if %%j==%cn_consensus_port% (
) else if !local_port!==%cn_consensus_port% (
if !cn_consensus_port_occupied!==0 (
set spid=%%k
call :checkIfIOTDBProcess !spid! is_iotdb
Expand Down Expand Up @@ -556,22 +562,29 @@ exit /b
:remote_ports_check
for %%e in ("%endpoints:,=" "%") do (
set counter=0
for /f "tokens=1,2 delims=:" %%i in ("%%~e") do (
for /f "tokens=1,2 delims=;" %%i in ("%%~e") do (
set "ip=%%i"
set "port=%%j"
if "!ip:~0,1!"=="[" if "!ip:~-1!"=="]" set "ip=!ip:~1,-1!"
set "display_ip=!ip!"
if not "!display_ip::=!"=="!display_ip!" (
if not "!display_ip:~0,1!"=="[" (
set "display_ip=[!display_ip!]"
)
)
if "!allpreip!" == "!ip!" (
set "iplist=!iplist! !port!"
) else (
set allpreip=!ip!
if !counter! EQU 0 (
set /a counter+=1
if defined iplist (
set "iplist=!iplist!,!ip!:!port!"
set "iplist=!iplist!,!display_ip!:!port!"
) else (
set "iplist=!ip!:!port!"
set "iplist=!display_ip!:!port!"
)
) else (
set "iplist=!iplist!,!ip!:!port!"
set "iplist=!iplist!,!display_ip!:!port!"
)
)

Expand Down
Loading