尝试上传 CSV 文件时(约 100 行且 < 100KB) to ClickHouseContainer running in junit, the client is timing out with the following error:
An exception or error caused a run to abort: Code: 159. Execution timed out, server ClickHouseNode [uri=any://localhost:51733/default]@675749754
我有以下代码来初始化 ClickHouseContainer
val image: ClickHouseContainer =
new ClickHouseContainer("clickhouse/clickhouse-server:latest")
.withUrlParam("compress_algorithm", "zstd")
.withUsername("default")
.withPassword("")
.withExposedPorts(8123, 8443, 9000, 9440)
.waitingFor(
Wait
.forHttp("/ping")
.forPort(8123)
.forStatusCode(200)
.withStartupTimeout(Duration.ofSeconds(600)));
image.start()
容器启动后,我将使用 ClickHouseClient 从 CSV 文件加载表。
val server = ClickHouseNode.builder
.host(image.getHost)
.port(image.getMappedPort(ClickHouseProtocol.HTTP.getDefaultPort))
.database("default")
.credentials(ClickHouseCredentials.fromUserAndPassword("default", ""))
.build
// Create a CSV file reference
val file = ClickHouseFile.of(csvFile, ClickHouseCompression.NONE, ClickHouseFormat.CSV)
// Create a client
val client = ClickHouseClient.newInstance(server.getProtocol)
// Specify settings, load data to the specified table and wait for completion
client
.write(server)
.set("input_format_csv_skip_first_lines", "0")
.set("format_csv_delimiter", ",")
.table(tableName)
.data(file)
.executeAndWait()
我什至尝试增加客户端上的套接字超时,但这没有帮助,相反我被对等方重置了连接。
val client = ClickHouseClient
.builder()
.option(ClickHouseClientOption.SOCKET_TIMEOUT, 10000)
.option(ClickHouseClientOption.MAX_THREADS_PER_CLIENT, 100)
.option(ClickHouseClientOption.MAX_EXECUTION_TIME, 1000)
.build()
CSV 文件太小,因此我预计将行插入到 clickhouse 不会花费这么长时间。
仅凭以上信息无法判断原因。但有一些事情可能有助于解决问题
system.query_log
并查找与异常相关的失败查询,https://clickhouse.com/docs/en/operations/system-tables/query_log。您可以按时间戳/查询字符串进行过滤。