2020-08-28 20:40:23 +00:00
#!/usr/bin/env bash
2020-11-11 15:29:36 +00:00
# Don't check for ODR violation, since we may test shared build with ASAN
export ASAN_OPTIONS = detect_odr_violation = 0
2019-04-11 17:20:36 +00:00
export CLICKHOUSE_DATABASE = ${ CLICKHOUSE_DATABASE : = "test" }
2019-03-20 20:04:49 +00:00
export CLICKHOUSE_CLIENT_SERVER_LOGS_LEVEL = ${ CLICKHOUSE_CLIENT_SERVER_LOGS_LEVEL : = "warning" }
2021-03-15 05:29:05 +00:00
# Unique zookeeper path (based on test name and current database) to avoid overlaps
export CLICKHOUSE_TEST_PATH = " ${ BASH_SOURCE [1] } "
CLICKHOUSE_TEST_NAME = " $( basename " $CLICKHOUSE_TEST_PATH " .sh) "
export CLICKHOUSE_TEST_NAME
export CLICKHOUSE_TEST_ZOOKEEPER_PREFIX = " ${ CLICKHOUSE_TEST_NAME } _ ${ CLICKHOUSE_DATABASE } "
2021-10-30 09:54:17 +00:00
export CLICKHOUSE_TEST_UNIQUE_NAME = " ${ CLICKHOUSE_TEST_NAME } _ ${ CLICKHOUSE_DATABASE } "
2021-03-15 05:29:05 +00:00
2020-08-28 20:40:23 +00:00
[ -v CLICKHOUSE_CONFIG_CLIENT ] && CLICKHOUSE_CLIENT_OPT0 += " --config-file= ${ CLICKHOUSE_CONFIG_CLIENT } "
[ -v CLICKHOUSE_HOST ] && CLICKHOUSE_CLIENT_OPT0 += " --host= ${ CLICKHOUSE_HOST } "
[ -v CLICKHOUSE_PORT_TCP ] && CLICKHOUSE_CLIENT_OPT0 += " --port= ${ CLICKHOUSE_PORT_TCP } "
2021-02-10 18:09:13 +00:00
[ -v CLICKHOUSE_PORT_TCP ] && CLICKHOUSE_BENCHMARK_OPT0 += " --port= ${ CLICKHOUSE_PORT_TCP } "
2020-08-28 20:40:23 +00:00
[ -v CLICKHOUSE_CLIENT_SERVER_LOGS_LEVEL ] && CLICKHOUSE_CLIENT_OPT0 += " --send_logs_level= ${ CLICKHOUSE_CLIENT_SERVER_LOGS_LEVEL } "
[ -v CLICKHOUSE_DATABASE ] && CLICKHOUSE_CLIENT_OPT0 += " --database= ${ CLICKHOUSE_DATABASE } "
2022-02-26 20:03:53 +00:00
[ -v CLICKHOUSE_LOG_COMMENT ] && CLICKHOUSE_CLIENT_OPT0 += " --log_comment $( printf '%q' ${ CLICKHOUSE_LOG_COMMENT } ) "
2020-11-05 12:32:03 +00:00
[ -v CLICKHOUSE_DATABASE ] && CLICKHOUSE_BENCHMARK_OPT0 += " --database= ${ CLICKHOUSE_DATABASE } "
2022-02-26 20:03:53 +00:00
[ -v CLICKHOUSE_LOG_COMMENT ] && CLICKHOUSE_BENCHMARK_OPT0 += " --log_comment $( printf '%q' ${ CLICKHOUSE_LOG_COMMENT } ) "
2019-03-20 20:04:49 +00:00
2017-10-12 19:46:24 +00:00
export CLICKHOUSE_BINARY = ${ CLICKHOUSE_BINARY : = "clickhouse" }
2021-02-28 19:31:27 +00:00
# client
2019-03-20 20:04:49 +00:00
[ -x " $CLICKHOUSE_BINARY -client " ] && CLICKHOUSE_CLIENT_BINARY = ${ CLICKHOUSE_CLIENT_BINARY : = $CLICKHOUSE_BINARY -client }
[ -x " $CLICKHOUSE_BINARY " ] && CLICKHOUSE_CLIENT_BINARY = ${ CLICKHOUSE_CLIENT_BINARY : = $CLICKHOUSE_BINARY client }
2018-11-07 11:00:46 +00:00
export CLICKHOUSE_CLIENT_BINARY = ${ CLICKHOUSE_CLIENT_BINARY : = $CLICKHOUSE_BINARY -client }
2020-12-18 13:26:11 +00:00
export CLICKHOUSE_CLIENT_OPT = " ${ CLICKHOUSE_CLIENT_OPT0 :- } ${ CLICKHOUSE_CLIENT_OPT :- } "
export CLICKHOUSE_CLIENT = ${ CLICKHOUSE_CLIENT : = " $CLICKHOUSE_CLIENT_BINARY ${ CLICKHOUSE_CLIENT_OPT :- } " }
2021-02-28 19:31:27 +00:00
# local
2018-11-07 11:00:46 +00:00
[ -x " ${ CLICKHOUSE_BINARY } -local " ] && CLICKHOUSE_LOCAL = ${ CLICKHOUSE_LOCAL : = " ${ CLICKHOUSE_BINARY } -local " }
[ -x " ${ CLICKHOUSE_BINARY } " ] && CLICKHOUSE_LOCAL = ${ CLICKHOUSE_LOCAL : = " ${ CLICKHOUSE_BINARY } local " }
2017-11-01 11:46:58 +00:00
export CLICKHOUSE_LOCAL = ${ CLICKHOUSE_LOCAL : = " ${ CLICKHOUSE_BINARY } -local " }
2021-02-28 19:31:27 +00:00
# server
[ -x " ${ CLICKHOUSE_BINARY } -server " ] && CLICKHOUSE_SERVER_BINARY = ${ CLICKHOUSE_SERVER_BINARY : = " ${ CLICKHOUSE_BINARY } -server " }
[ -x " ${ CLICKHOUSE_BINARY } " ] && CLICKHOUSE_SERVER_BINARY = ${ CLICKHOUSE_SERVER_BINARY : = " ${ CLICKHOUSE_BINARY } server " }
export CLICKHOUSE_SERVER_BINARY = ${ CLICKHOUSE_SERVER_BINARY : = " ${ CLICKHOUSE_BINARY } -server " }
# others
2020-02-17 08:05:48 +00:00
export CLICKHOUSE_OBFUSCATOR = ${ CLICKHOUSE_OBFUSCATOR : = " ${ CLICKHOUSE_BINARY } -obfuscator " }
2020-12-29 20:10:51 +00:00
export CLICKHOUSE_COMPRESSOR = ${ CLICKHOUSE_COMPRESSOR : = " ${ CLICKHOUSE_BINARY } -compressor " }
2020-11-05 12:32:03 +00:00
export CLICKHOUSE_BENCHMARK = ${ CLICKHOUSE_BENCHMARK : = " ${ CLICKHOUSE_BINARY } -benchmark ${ CLICKHOUSE_BENCHMARK_OPT0 :- } " }
2020-12-18 21:54:24 +00:00
export CLICKHOUSE_GIT_IMPORT = ${ CLICKHOUSE_GIT_IMPORT = " ${ CLICKHOUSE_BINARY } -git-import " }
2017-10-12 19:46:24 +00:00
2017-12-15 19:34:19 +00:00
export CLICKHOUSE_CONFIG = ${ CLICKHOUSE_CONFIG : = "/etc/clickhouse-server/config.xml" }
2018-05-28 20:55:13 +00:00
export CLICKHOUSE_CONFIG_CLIENT = ${ CLICKHOUSE_CONFIG_CLIENT : = "/etc/clickhouse-client/config.xml" }
2018-11-07 11:00:46 +00:00
[ -x " ${ CLICKHOUSE_BINARY } -extract-from-config " ] && CLICKHOUSE_EXTRACT_CONFIG = ${ CLICKHOUSE_EXTRACT_CONFIG : = " $CLICKHOUSE_BINARY -extract-from-config --config= $CLICKHOUSE_CONFIG " }
[ -x " ${ CLICKHOUSE_BINARY } " ] && CLICKHOUSE_EXTRACT_CONFIG = ${ CLICKHOUSE_EXTRACT_CONFIG : = " $CLICKHOUSE_BINARY extract-from-config --config= $CLICKHOUSE_CONFIG " }
2018-05-11 14:16:16 +00:00
export CLICKHOUSE_EXTRACT_CONFIG = ${ CLICKHOUSE_EXTRACT_CONFIG : = " $CLICKHOUSE_BINARY -extract-from-config --config= $CLICKHOUSE_CONFIG " }
2018-11-07 11:00:46 +00:00
2019-06-14 14:00:37 +00:00
[ -x " ${ CLICKHOUSE_BINARY } -format " ] && CLICKHOUSE_FORMAT = ${ CLICKHOUSE_FORMAT : = " $CLICKHOUSE_BINARY -format " }
2019-05-16 19:26:32 +00:00
[ -x " ${ CLICKHOUSE_BINARY } " ] && CLICKHOUSE_FORMAT = ${ CLICKHOUSE_FORMAT : = " $CLICKHOUSE_BINARY format " }
export CLICKHOUSE_FORMAT = ${ CLICKHOUSE_FORMAT : = " $CLICKHOUSE_BINARY -format " }
2018-12-27 14:48:58 +00:00
export CLICKHOUSE_CONFIG_GREP = ${ CLICKHOUSE_CONFIG_GREP : = "/etc/clickhouse-server/preprocessed/config.xml" }
2017-12-15 19:34:19 +00:00
2017-10-12 19:46:24 +00:00
export CLICKHOUSE_HOST = ${ CLICKHOUSE_HOST : = "localhost" }
2020-08-01 01:20:22 +00:00
export CLICKHOUSE_PORT_TCP = ${ CLICKHOUSE_PORT_TCP : = $( ${ CLICKHOUSE_EXTRACT_CONFIG } --try --key= tcp_port 2>/dev/null) } 2>/dev/null
2017-10-12 19:46:24 +00:00
export CLICKHOUSE_PORT_TCP = ${ CLICKHOUSE_PORT_TCP : = "9000" }
2020-08-01 01:20:22 +00:00
export CLICKHOUSE_PORT_TCP_SECURE = ${ CLICKHOUSE_PORT_TCP_SECURE : = $( ${ CLICKHOUSE_EXTRACT_CONFIG } --try --key= tcp_port_secure 2>/dev/null) } 2>/dev/null
2018-03-29 01:41:06 +00:00
export CLICKHOUSE_PORT_TCP_SECURE = ${ CLICKHOUSE_PORT_TCP_SECURE : = "9440" }
2020-12-02 21:05:51 +00:00
export CLICKHOUSE_PORT_TCP_WITH_PROXY = ${ CLICKHOUSE_PORT_TCP_WITH_PROXY : = $( ${ CLICKHOUSE_EXTRACT_CONFIG } --try --key= tcp_with_proxy_port 2>/dev/null) } 2>/dev/null
export CLICKHOUSE_PORT_TCP_WITH_PROXY = ${ CLICKHOUSE_PORT_TCP_WITH_PROXY : = "9010" }
2020-08-01 01:20:22 +00:00
export CLICKHOUSE_PORT_HTTP = ${ CLICKHOUSE_PORT_HTTP : = $( ${ CLICKHOUSE_EXTRACT_CONFIG } --key= http_port 2>/dev/null) }
2017-10-12 19:46:24 +00:00
export CLICKHOUSE_PORT_HTTP = ${ CLICKHOUSE_PORT_HTTP : = "8123" }
2020-08-01 01:20:22 +00:00
export CLICKHOUSE_PORT_HTTPS = ${ CLICKHOUSE_PORT_HTTPS : = $( ${ CLICKHOUSE_EXTRACT_CONFIG } --try --key= https_port 2>/dev/null) } 2>/dev/null
2017-10-12 19:46:24 +00:00
export CLICKHOUSE_PORT_HTTPS = ${ CLICKHOUSE_PORT_HTTPS : = "8443" }
export CLICKHOUSE_PORT_HTTP_PROTO = ${ CLICKHOUSE_PORT_HTTP_PROTO : = "http" }
2021-02-18 13:27:51 +00:00
export CLICKHOUSE_PORT_MYSQL = ${ CLICKHOUSE_PORT_MYSQL : = $( ${ CLICKHOUSE_EXTRACT_CONFIG } --try --key= mysql_port 2>/dev/null) } 2>/dev/null
export CLICKHOUSE_PORT_MYSQL = ${ CLICKHOUSE_PORT_MYSQL : = "9004" }
2021-04-12 18:40:34 +00:00
export CLICKHOUSE_PORT_POSTGRESQL = ${ CLICKHOUSE_PORT_POSTGRESQL : = $( ${ CLICKHOUSE_EXTRACT_CONFIG } --try --key= postgresql_port 2>/dev/null) } 2>/dev/null
export CLICKHOUSE_PORT_POSTGRESQL = ${ CLICKHOUSE_PORT_POSTGRESQL : = "9005" }
2021-11-19 13:36:13 +00:00
export CLICKHOUSE_PORT_KEEPER = ${ CLICKHOUSE_PORT_KEEPER : = $( ${ CLICKHOUSE_EXTRACT_CONFIG } --try --key= keeper_server.tcp_port 2>/dev/null) } 2>/dev/null
2021-11-19 09:30:58 +00:00
export CLICKHOUSE_PORT_KEEPER = ${ CLICKHOUSE_PORT_KEEPER : = "9181" }
2019-10-11 12:08:11 +00:00
2022-05-05 19:11:38 +00:00
export CLICKHOUSE_CLIENT_SECURE = ${ CLICKHOUSE_CLIENT_SECURE : = $( echo " ${ CLICKHOUSE_CLIENT } " | sed 's/--secure //' | sed 's/' " --port= ${ CLICKHOUSE_PORT_TCP } " '//g; s/$/' " --secure --port= ${ CLICKHOUSE_PORT_TCP_SECURE } " '/g' ) }
2021-06-23 09:28:18 +00:00
2021-01-28 17:31:34 +00:00
# Add database and log comment to url params
2020-08-28 20:40:23 +00:00
if [ -v CLICKHOUSE_URL_PARAMS ]
2019-10-11 12:08:11 +00:00
then
2019-10-11 13:34:26 +00:00
export CLICKHOUSE_URL_PARAMS = " ${ CLICKHOUSE_URL_PARAMS } &database= ${ CLICKHOUSE_DATABASE } "
2019-10-11 12:08:11 +00:00
else
2019-10-11 13:34:26 +00:00
export CLICKHOUSE_URL_PARAMS = " database= ${ CLICKHOUSE_DATABASE } "
2019-10-11 12:08:11 +00:00
fi
2021-01-30 23:22:55 +00:00
# Note: missing url encoding of the log comment.
2021-02-10 18:09:13 +00:00
[ -v CLICKHOUSE_LOG_COMMENT ] && export CLICKHOUSE_URL_PARAMS = " ${ CLICKHOUSE_URL_PARAMS } &log_comment= ${ CLICKHOUSE_LOG_COMMENT } "
2019-10-11 12:08:11 +00:00
2017-10-12 19:46:24 +00:00
export CLICKHOUSE_URL = ${ CLICKHOUSE_URL : = " ${ CLICKHOUSE_PORT_HTTP_PROTO } :// ${ CLICKHOUSE_HOST } : ${ CLICKHOUSE_PORT_HTTP } / " }
2018-03-13 20:38:35 +00:00
export CLICKHOUSE_URL_HTTPS = ${ CLICKHOUSE_URL_HTTPS : = " https:// ${ CLICKHOUSE_HOST } : ${ CLICKHOUSE_PORT_HTTPS } / " }
2019-10-11 12:08:11 +00:00
# Add url params to url
2020-08-28 20:40:23 +00:00
if [ -v CLICKHOUSE_URL_PARAMS ]
2019-10-11 12:08:11 +00:00
then
2019-10-11 13:34:26 +00:00
export CLICKHOUSE_URL = " ${ CLICKHOUSE_URL } ? ${ CLICKHOUSE_URL_PARAMS } "
export CLICKHOUSE_URL_HTTPS = " ${ CLICKHOUSE_URL_HTTPS } ? ${ CLICKHOUSE_URL_PARAMS } "
2019-10-11 12:08:11 +00:00
fi
2020-08-01 01:20:22 +00:00
export CLICKHOUSE_PORT_INTERSERVER = ${ CLICKHOUSE_PORT_INTERSERVER : = $( ${ CLICKHOUSE_EXTRACT_CONFIG } --try --key= interserver_http_port 2>/dev/null) } 2>/dev/null
2019-05-20 17:04:36 +00:00
export CLICKHOUSE_PORT_INTERSERVER = ${ CLICKHOUSE_PORT_INTERSERVER : = "9009" }
export CLICKHOUSE_URL_INTERSERVER = ${ CLICKHOUSE_URL_INTERSERVER : = " ${ CLICKHOUSE_PORT_HTTP_PROTO } :// ${ CLICKHOUSE_HOST } : ${ CLICKHOUSE_PORT_INTERSERVER } / " }
2018-03-29 19:12:24 +00:00
export CLICKHOUSE_CURL_COMMAND = ${ CLICKHOUSE_CURL_COMMAND : = "curl" }
2020-11-30 09:11:17 +00:00
# The queries in CI are prone to sudden delays, and we often don't check for curl
# errors, so it makes sense to set a relatively generous timeout.
export CLICKHOUSE_CURL_TIMEOUT = ${ CLICKHOUSE_CURL_TIMEOUT : = "60" }
2020-08-28 20:40:23 +00:00
export CLICKHOUSE_CURL = ${ CLICKHOUSE_CURL : = " ${ CLICKHOUSE_CURL_COMMAND } -q -s --max-time ${ CLICKHOUSE_CURL_TIMEOUT } " }
2017-12-27 15:56:42 +00:00
export CLICKHOUSE_TMP = ${ CLICKHOUSE_TMP : = "." }
mkdir -p ${ CLICKHOUSE_TMP }
2019-02-21 09:21:20 +00:00
2021-02-18 13:27:51 +00:00
export MYSQL_CLIENT_BINARY = ${ MYSQL_CLIENT_BINARY : = "mysql" }
export MYSQL_CLIENT_CLICKHOUSE_USER = ${ MYSQL_CLIENT_CLICKHOUSE_USER : = "default" }
# Avoids "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'" when connecting to localhost
[ -v CLICKHOUSE_HOST ] && MYSQL_CLIENT_OPT0 += " --protocol tcp "
[ -v CLICKHOUSE_HOST ] && MYSQL_CLIENT_OPT0 += " --host ${ CLICKHOUSE_HOST } "
[ -v CLICKHOUSE_PORT_MYSQL ] && MYSQL_CLIENT_OPT0 += " --port ${ CLICKHOUSE_PORT_MYSQL } "
[ -v CLICKHOUSE_DATABASE ] && MYSQL_CLIENT_OPT0 += " --database ${ CLICKHOUSE_DATABASE } "
MYSQL_CLIENT_OPT0 += " --user ${ MYSQL_CLIENT_CLICKHOUSE_USER } "
export MYSQL_CLIENT_OPT = " ${ MYSQL_CLIENT_OPT0 :- } ${ MYSQL_CLIENT_OPT :- } "
export MYSQL_CLIENT = ${ MYSQL_CLIENT : = " $MYSQL_CLIENT_BINARY ${ MYSQL_CLIENT_OPT :- } " }
2021-04-12 17:19:46 +00:00
export PROTOC_BINARY = ${ PROTOC_BINARY : = "protoc" }
2019-02-21 09:21:20 +00:00
function clickhouse_client_removed_host_parameter( )
{
2020-06-16 01:08:01 +00:00
# removing only `--host=value` and `--host value` (removing '-hvalue' feels to dangerous) with python regex.
# bash regex magic is arcane, but version dependant and weak; sed or awk are not really portable.
2020-10-02 16:54:07 +00:00
$( echo " $CLICKHOUSE_CLIENT " | python3 -c "import sys, re; print(re.sub('--host(\s+|=)[^\s]+', '', sys.stdin.read()))" ) " $@ "
2019-02-21 09:21:20 +00:00
}
2022-06-14 14:11:16 +00:00
function wait_for_queries_to_finish( )
{
# Wait for all queries to finish (query may still be running if thread is killed by timeout)
num_tries = 0
while [ [ $( $CLICKHOUSE_CLIENT -q "SELECT count() FROM system.processes WHERE current_database=currentDatabase() AND query NOT LIKE '%system.processes%'" ) -ne 0 ] ] ; do
sleep 0.5;
num_tries = $(( num_tries+1))
if [ $num_tries -eq 20 ] ; then
2022-06-21 16:47:55 +00:00
$CLICKHOUSE_CLIENT -q "SELECT * FROM system.processes WHERE current_database=currentDatabase() AND query NOT LIKE '%system.processes%' FORMAT Vertical"
2022-06-14 14:11:16 +00:00
break
fi
done
}
2022-06-28 09:14:23 +00:00
function random_str( )
{
local n = $1 && shift
tr -cd '[:lower:]' < /dev/urandom | head -c" $n "
}