[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize docker build and run #9

Merged
merged 1 commit into from
Apr 17, 2023
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
optimize docker build and run
  • Loading branch information
zhiliyao-polarx committed Apr 17, 2023
commit 344e1be6d17a0bc581c867e93e4377693061e5c3
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ stop() {
echo "cn is stopped."

echo "stop dn & gms..."
ps aux | grep "$(BUILD_DIR)/run/polardbx-engine/u01/mysql/bin/mysqld" | grep -v "grep" | awk '{print $$2}'| xargs kill -9
ps aux | grep "$(BUILD_DIR)/run/polardbx-engine/u01/mysql/bin/mysqld" | grep -v "grep" | awk '{print $$2}'| xargs kill -15
echo "dn & gms are stopped."
}

Expand Down
2 changes: 2 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ WORKDIR /home/polarx
ADD --chown=polarx run.tar.gz $BUILD_PATH
COPY --chown=polarx entrypoint.sh entrypoint.sh

ENV TZ Asia/Shanghai

ENV BUILD_PATH=$BUILD_PATH
ENTRYPOINT /home/polarx/entrypoint.sh $BUILD_PATH/run
6 changes: 3 additions & 3 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ docker pull polardbx/polardb-x
之后运行如下命令启动一个 PolarDB-X 容器,建议docker内存>=12GB (CN/DN/CDC各自分配mem_size=4096):

```shell
docker run -d --name polardb-x -m 12GB -p 3306:8527 polardbx/polardb-x
docker run -d --name polardb-x -m 12GB -p 3306:8527 -v /etc/localtime:/etc/localtime polardbx/polardb-x
```

等待之后即可通过 MySQL Client 连接到 PolarDB-X :
Expand Down Expand Up @@ -70,7 +70,7 @@ show mpp;

1. 首先运行 polardb-x 容器,传递 mem_size 环境变量,并将数据目录挂载到本地:
```shell
docker run -d --name polardb-x -p 3306:8527 --env mem_size=8192 -v polardbx-data:/home/polarx/polardbx/build/run/polardbx-engine/data polardbx/polardb-x
docker run -d --name polardb-x -p 3306:8527 --env mem_size=8192 -v /etc/localtime:/etc/localtime -v polardbx-data:/home/polarx/polardbx/build/run/polardbx-engine/data polardbx/polardb-x
```
上述指令,使得 CN 、DN、 CDC 分别占用不超过 8GB 内存,即一共占用不超过 24GB 内存。
同时,DN 的 `innodb_buffer_pool_size` 将设置为 `0.3*8192 MB`,最终取整为 2560MB。
Expand Down Expand Up @@ -101,7 +101,7 @@ polardbx-engine(即 DN ) 是 MySQL 8.x 的一个分支,可参考 MySQL 官
CN 的运行依赖DN和GMS,GMS可以看做一个扮演特殊角色的DN,所以在进行CN开发时,可用一个容器同时扮演DN和GMS的角色。运行这样一个容器的命令如下:

```shell
docker run -d --name polardb-x --env mode=dev -p 4886:4886 -p 34886:34886 -v polardb-x-data:/home/polarx/polardbx/build/run/polardbx-engine/data polardbx/polardb-x
docker run -d --name polardb-x --env mode=dev -p 4886:4886 -p 34886:34886 -v /etc/localtime:/etc/localtime -v polardb-x-data:/home/polarx/polardbx/build/run/polardbx-engine/data polardbx/polardb-x
```

该命令会启动一个名叫 polardb-x 的容器,通过环境变量 `mode` 设置容器运行模式为开发模式(即 `mode=dev`)并将 MySQL 协议端口和私有协议端口暴露出来以供 CN 使用。
Expand Down
42 changes: 32 additions & 10 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ function dn_pid() {
}

function get_pid() {
if [ x"$mode" = x"play" ]; then
cn_pid
elif [ x"$mode" = x"dev" ]; then
dn_pid
else
echo "mode=$mode does not support yet."
echo ""
fi
if [ x"$mode" = x"play" ]; then
cn_pid
elif [ x"$mode" = x"dev" ]; then
dn_pid
else
echo "mode=$mode does not support yet."
echo ""
fi
}

function stop_all() {
Expand Down Expand Up @@ -106,9 +106,24 @@ function start() {
start_process
}

function waitterm() {
local PID
# any process to block
tail -f /dev/null &
PID="$!"
# setup trap, could do nothing, or just kill the blocker
trap "kill -TERM ${PID}" TERM INT
# wait for signal, ignore wait exit code
wait "${PID}" || true
# clear trap
trap - TERM INT
# wait blocker, ignore blocker exit code
wait "${PID}" 2>/dev/null || true
}

# Retry start and watch

retry_interval=5
retry_interval=30
retry_cnt=0
retry_limit=10
if [[ "$#" -ge 2 ]]; then
Expand All @@ -117,7 +132,10 @@ fi

while [[ $retry_cnt -lt $retry_limit ]]; do
start
watch

if report_pid; then
break
fi

((retry_cnt++))

Expand All @@ -126,5 +144,9 @@ while [[ $retry_cnt -lt $retry_limit ]]; do
fi
done

waitterm

stop_all

# Abort.
exit 1