2014-07-04 01:54:43 +00:00
|
|
|
|
#!/bin/bash -e
|
2014-07-04 01:38:49 +00:00
|
|
|
|
|
|
|
|
|
# Скрипт довольно хрупкий.
|
|
|
|
|
|
|
|
|
|
# Попробуем угадать, где расположен конфиг сервера.
|
2014-07-04 01:54:43 +00:00
|
|
|
|
[ -f '/etc/clickhouse-server/config-preprocessed.xml' ] && CONFIG='/etc/clickhouse-server/config-preprocessed.xml' || CONFIG='../src/Server/config-preprocessed.xml'
|
2014-07-04 01:38:49 +00:00
|
|
|
|
|
|
|
|
|
if [ ! -f "$CONFIG" ]; then
|
|
|
|
|
echo "Cannot find config file for clickhouse-server" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Создадим директории для данных второго сервера.
|
|
|
|
|
PATH2=/tmp/clickhouse/
|
2015-03-15 07:40:05 +00:00
|
|
|
|
[ -d "$PATH2" ] && rm -rf $PATH2
|
2014-07-04 01:38:49 +00:00
|
|
|
|
mkdir -p ${PATH2}{data,metadata}/default/
|
|
|
|
|
|
|
|
|
|
# Создадим второй конфиг с портом 9001.
|
2014-07-04 01:54:43 +00:00
|
|
|
|
CONFIG2="config-9001.xml"
|
|
|
|
|
|
2014-07-04 01:38:49 +00:00
|
|
|
|
LOG=${PATH2}log
|
|
|
|
|
|
|
|
|
|
cat "$CONFIG" | sed -r \
|
|
|
|
|
's/<path>.+<\/path>/<path>'${PATH2//\//\\/}'<\/path>/;
|
2014-07-04 01:59:53 +00:00
|
|
|
|
s/<http_port>[0-9]+/<http_port>8124/;
|
|
|
|
|
s/<tcp_port>[0-9]+/<tcp_port>9001/;
|
2014-07-04 02:01:32 +00:00
|
|
|
|
s/<interserver_http_port>[0-9]+/<interserver_http_port>9010/;
|
2014-07-04 14:27:10 +00:00
|
|
|
|
s/<use_olap_http_server>true/<use_olap_http_server>false/;
|
|
|
|
|
s/users\.xml/users-preprocessed.xml/' > $CONFIG2
|
2014-07-04 01:38:49 +00:00
|
|
|
|
|
2014-07-04 02:03:53 +00:00
|
|
|
|
cp ${CONFIG/config/users} .
|
2014-07-04 01:54:43 +00:00
|
|
|
|
|
2014-07-04 01:38:49 +00:00
|
|
|
|
# Запустим второй сервер.
|
2014-07-04 01:58:00 +00:00
|
|
|
|
BINARY=$(readlink /proc/$(pidof clickhouse-server | tr ' ' '\n' | head -n1)/exe || echo "/usr/bin/clickhouse-server")
|
2014-07-04 01:38:49 +00:00
|
|
|
|
|
2014-12-30 02:49:09 +00:00
|
|
|
|
if [ ! -x "$BINARY" ] && [ -n "$(pgrep memcheck)" ]; then
|
|
|
|
|
# В случае, если сервер был запущен под valgrind-ом.
|
2014-12-30 03:25:12 +00:00
|
|
|
|
BINARY=$(readlink /proc/$(pgrep memcheck)/cwd)/$(cat /proc/$(pgrep memcheck)/cmdline | cut -f2 -d '')
|
2014-12-30 02:49:09 +00:00
|
|
|
|
fi
|
|
|
|
|
|
2014-07-04 14:27:10 +00:00
|
|
|
|
if [ ! -x "$BINARY" ]; then
|
|
|
|
|
echo "Cannot find executable binary for running clickhouse-server" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2014-07-04 01:38:49 +00:00
|
|
|
|
$BINARY --config-file=${CONFIG2} 2>$LOG &
|
|
|
|
|
PID=$!
|
|
|
|
|
|
|
|
|
|
function finish {
|
|
|
|
|
kill $PID
|
2015-03-15 07:40:05 +00:00
|
|
|
|
wait
|
2014-07-04 01:38:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trap finish EXIT
|
|
|
|
|
|
2014-07-04 01:54:43 +00:00
|
|
|
|
i=0
|
2014-07-04 01:38:49 +00:00
|
|
|
|
while true; do
|
|
|
|
|
grep -q 'Ready for connections' ${LOG} && break
|
2014-07-04 01:54:43 +00:00
|
|
|
|
grep -q 'shutting down' ${LOG} && echo "Cannot start second clickhouse-server" && exit 1
|
2014-07-04 01:38:49 +00:00
|
|
|
|
sleep 0.05
|
2014-07-04 01:54:43 +00:00
|
|
|
|
|
|
|
|
|
i=$(($i + 1))
|
|
|
|
|
[[ $i == 100 ]] && echo "Cannot start second clickhouse-server" && exit 1
|
2014-07-04 01:38:49 +00:00
|
|
|
|
done
|
|
|
|
|
|
2014-07-04 01:54:43 +00:00
|
|
|
|
rm "$CONFIG2"
|
|
|
|
|
|
2014-07-04 01:38:49 +00:00
|
|
|
|
|
|
|
|
|
# Теперь можно выполнять запросы.
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
"
|
|
|
|
|
|
2014-07-04 02:05:45 +00:00
|
|
|
|
$CLIENT1 -n --query="
|
|
|
|
|
SELECT count() FROM remote('localhost:{9000,9001}', test, half1)
|
|
|
|
|
WHERE number IN (SELECT * FROM test.half2);
|
|
|
|
|
|
|
|
|
|
SELECT count() FROM remote('localhost:{9000,9001}', test, half1)
|
|
|
|
|
WHERE number IN (SELECT * FROM remote('localhost:{9000,9001}', test, half2));
|
|
|
|
|
|
|
|
|
|
SELECT count() FROM remote('localhost:{9000,9001}', test, half1)
|
|
|
|
|
WHERE number GLOBAL IN (SELECT * FROM remote('localhost:{9000,9001}', test, half2));
|
|
|
|
|
"
|
|
|
|
|
|
|
|
|
|
$CLIENT1 -n --query="
|
|
|
|
|
DROP TABLE test.half1;
|
|
|
|
|
DROP TABLE test.half2;"
|
|
|
|
|
|
|
|
|
|
$CLIENT2 -n --query="
|
|
|
|
|
DROP TABLE test.half1;
|
|
|
|
|
DROP TABLE test.half2;"
|