mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-23 02:00:49 +00:00
81 lines
2.5 KiB
Bash
Executable File
81 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
||
|
||
# Скрипт довольно хрупкий.
|
||
|
||
# Попробуем угадать, где расположен конфиг сервера.
|
||
[ -f '/etc/clickhouse-server/config.xml' ] && CONFIG='/etc/clickhouse-server/config.xml' || CONFIG='../src/Server/config.xml'
|
||
|
||
if [ ! -f "$CONFIG" ]; then
|
||
echo "Cannot find config file for clickhouse-server" >&2
|
||
exit 1
|
||
fi
|
||
|
||
# Создадим директории для данных второго сервера.
|
||
PATH2=/tmp/clickhouse/
|
||
mkdir -p ${PATH2}{data,metadata}/default/
|
||
|
||
# Создадим второй конфиг с портом 9001.
|
||
CONFIG2=${CONFIG/\.xml/-9001.xml}
|
||
LOG=${PATH2}log
|
||
|
||
cat "$CONFIG" | sed -r \
|
||
's/<path>.+<\/path>/<path>'${PATH2//\//\\/}'<\/path>/;
|
||
s/8123/8124/;
|
||
s/9000/9001/;
|
||
s/<use_olap_http_server>true/<use_olap_http_server>false/' > $CONFIG2
|
||
|
||
# Запустим второй сервер.
|
||
BINARY=/proc/$(pidof clickhouse-server | tr ' ' '\n' | head -n1)/exe
|
||
|
||
$BINARY --config-file=${CONFIG2} 2>$LOG &
|
||
PID=$!
|
||
|
||
function finish {
|
||
kill $PID
|
||
}
|
||
|
||
trap finish EXIT
|
||
|
||
while true; do
|
||
grep -q 'Ready for connections' ${LOG} && break
|
||
sleep 0.05
|
||
done
|
||
|
||
|
||
# Теперь можно выполнять запросы.
|
||
|
||
CLIENT1='clickhouse-client --port=9000'
|
||
CLIENT2='clickhouse-client --port=9001'
|
||
|
||
|
||
$CLIENT1 -n --query="
|
||
CREATE DATABASE IF NOT EXISTS test;
|
||
DROP TABLE IF EXISTS test.half1;
|
||
DROP TABLE IF EXISTS test.half2;
|
||
CREATE TABLE test.half1 ENGINE = Memory AS SELECT number FROM system.numbers LIMIT 5;
|
||
CREATE TABLE test.half2 ENGINE = Memory AS SELECT number FROM system.numbers WHERE number % 2 = 0 LIMIT 5;
|
||
"
|
||
|
||
$CLIENT2 -n --query="
|
||
CREATE DATABASE IF NOT EXISTS test;
|
||
DROP TABLE IF EXISTS test.half1;
|
||
DROP TABLE IF EXISTS test.half2;
|
||
CREATE TABLE test.half1 ENGINE = Memory AS SELECT number FROM system.numbers LIMIT 5, 5;
|
||
CREATE TABLE test.half2 ENGINE = Memory AS SELECT number FROM system.numbers WHERE number % 2 = 1 LIMIT 5;
|
||
"
|
||
|
||
$CLIENT1 --query="SELECT count() FROM remote('localhost:{9000,9001}', test, half1)
|
||
WHERE number IN (SELECT * FROM test.half2)"
|
||
|
||
$CLIENT1 --query="SELECT count() FROM remote('localhost:{9000,9001}', test, half1)
|
||
WHERE number IN (SELECT * FROM remote('localhost:{9000,9001}', test, half2))"
|
||
|
||
$CLIENT1 --query="SELECT count() FROM remote('localhost:{9000,9001}', test, half1)
|
||
WHERE number GLOBAL IN (SELECT * FROM remote('localhost:{9000,9001}', test, half2))"
|
||
|
||
$CLIENT1 --query="DROP TABLE test.half1"
|
||
$CLIENT2 --query="DROP TABLE test.half1"
|
||
|
||
$CLIENT1 --query="DROP TABLE test.half2"
|
||
$CLIENT2 --query="DROP TABLE test.half2"
|