Skip to content

Commit 6c06c7d

Browse files
Seekdb optimize (#68)
* wait more times for config file and setting password * support to execute sql commands directly * change log info * adjust timeout * change SeekDB to seekdb, define common values as variable
1 parent c5bbb61 commit 6c06c7d

File tree

4 files changed

+70
-35
lines changed

4 files changed

+70
-35
lines changed

seekdb/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ RUN if [[ ${TARGETPLATFORM} == 'linux/amd64' ]] ; then yum install -y https://mi
1010

1111
COPY start.sh /root/
1212
RUN chmod +x /root/start.sh
13-
ENV REPORTER docker-seekdb
13+
ENV REPORTER=docker-seekdb
1414
ENTRYPOINT ["/root/start.sh"]
1515

seekdb/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
English | [中文版](./README_CN.md)
2-
# Deploy SeekDB with Docker
2+
# Deploy seekdb with Docker
33

44
## Introduction
55

6-
The `seekdb` Docker image, available on [dockerhub](https://hub.docker.com/r/oceanbase/seekdb), [quay.io](https://quay.io/repository/oceanbase/seekdb) and [ghcr.io](https://ghcr.io/oceanbase/seekdb), is designed for users to quickly set up a SeekDB environment for testing purposes.
6+
The `seekdb` Docker image, available on [dockerhub](https://hub.docker.com/r/oceanbase/seekdb), [quay.io](https://quay.io/repository/oceanbase/seekdb) and [ghcr.io](https://ghcr.io/oceanbase/seekdb), is designed for users to quickly set up a seekdb environment for testing purposes.
77

88
### Key Considerations:
99
- There are known issues running this image on MacOS and intel chip with docker version greater than 4.9.0, you can download the desired version of docker from this [link](https://desktop.docker.com/mac/main/amd64/81317/Docker.dmg?_gl=17jelfd_gcl_auOTk5Nzk0MDUwLjE3MTE4ODMyNzM._gaNDQyMjE1MDE5LjE3MTE4ODMyNzQ._ga_XJWPQMJYHQ*MTcxOTIxOTEwMy4xMS4xLjE3MTkyMjEwMTAuNjAuMC4w).
@@ -15,9 +15,9 @@ Before deploying `seekdb`, ensure that the following requirements are met:
1515
- The host machine should have at least 1 physical cores and 2GB of memory.
1616
- Docker should be installed and running on the host machine. Refer to the [Docker installation guide](https://docs.docker.com/get-docker/).
1717

18-
## Starting a SeekDB Instance
18+
## Starting a seekdb Instance
1919

20-
To start a SeekDB instance, use the following commands:
20+
To start a seekdb instance, use the following commands:
2121

2222
```bash
2323
docker run -d -p 2881:2881 -p 2886:2886 oceanbase/seekdb
@@ -42,7 +42,7 @@ Below is a table of supported environment variables for the image:
4242
| INIT_SCRIPTS_PATH | The path in the container containing the init scripts. |
4343
| SEEKDB_DATABASE | The name of the database to be created at startup. |
4444

45-
If you'd like to modify other SeekDB parameters, you can do mount a configuration file into `/etc/oceanbase/seekdb.cnf` in the container, the default configuration file is as follows.
45+
If you'd like to modify other seekdb parameters, you can do mount a configuration file into `/etc/oceanbase/seekdb.cnf` in the container, the default configuration file is as follows.
4646

4747
```
4848
datafile_size=2G
@@ -62,14 +62,14 @@ docker run -d -p 2881:2881 -p 2886:2886 -v {config_file}:/etc/oceanbase/seekdb.c
6262
```
6363

6464
## Data Persistence
65-
SeekDB deploys in directory /var/lib/oceanbase, if you'd like to persist the data on the host server, please mount an empty directory on the host server to this path.
65+
Seekdb deploys in directory /var/lib/oceanbase, if you'd like to persist the data on the host server, please mount an empty directory on the host server to this path.
6666

6767
```
6868
mkdir -p seekdb
6969
docker run -d -p 2881:2881 -p 2886:2886 -v $PWD/seekdb:/var/lib/oceanbase --name seekdb oceanbase/seekdb
7070
```
7171

72-
## Connecting to SeekDB Instance
72+
## Connecting to seekdb Instance
7373

7474
```
7575
mysql -h 127.0.0.1 -P 2881 -u root -p # Connect with the root account

seekdb/README_CN.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
中文版 | [English](./README.md)
2-
# 使用 Docker 部署 SeekDB
2+
# 使用 Docker 部署 seekdb
33

44
## 简介
55

6-
`seekdb` Docker 镜像,可在 [dockerhub](https://hub.docker.com/r/oceanbase/seekdb)[quay.io](https://quay.io/repository/oceanbase/seekdb)[ghcr.io](https://ghcr.io/oceanbase/seekdb) 获取,旨在帮助用户快速搭建 SeekDB 环境进行测试。
6+
`seekdb` Docker 镜像,可在 [dockerhub](https://hub.docker.com/r/oceanbase/seekdb)[quay.io](https://quay.io/repository/oceanbase/seekdb)[ghcr.io](https://ghcr.io/oceanbase/seekdb) 获取,旨在帮助用户快速搭建 seekdb 环境进行测试。
77

88
### 主要注意事项:
99
- 在 MacOS 和 Intel 芯片上运行此镜像时,如果 Docker 版本高于 4.9.0,存在已知问题。您可以从此 [链接](https://desktop.docker.com/mac/main/amd64/81317/Docker.dmg?_gl=17jelfd_gcl_auOTk5Nzk0MDUwLjE3MTE4ODMyNzM._gaNDQyMjE1MDE5LjE3MTE4ODMyNzQ._ga_XJWPQMJYHQ*MTcxOTIxOTEwMy4xMS4xLjE3MTkyMjEwMTAuNjAuMC4w) 下载所需版本的 Docker。
@@ -15,9 +15,9 @@
1515
- 主机应至少有 1 个物理核心和 2GB 内存。
1616
- 主机上应安装并运行 Docker。请参阅 [Docker 安装指南](https://docs.docker.com/get-docker/)
1717

18-
## 启动 SeekDB 实例
18+
## 启动 seekdb 实例
1919

20-
要启动 SeekDB 实例,请使用以下命令:
20+
要启动 seekdb 实例,请使用以下命令:
2121

2222
```bash
2323
docker run -d -p 2881:2881 -p 2886:2886 oceanbase/seekdb
@@ -42,7 +42,7 @@ docker run -d -p 2881:2881 -p 2886:2886 -v {init_sql_folder_path}:/root/boot/ini
4242
| INIT_SCRIPTS_PATH | 容器中包含初始化脚本的路径。 |
4343
| SEEKDB_DATABASE | 启动时要创建的数据库名称。 |
4444

45-
如果您想修改其他 SeekDB 参数,可以将配置文件挂载到容器中的 `/etc/oceanbase/seekdb.cnf`,默认配置文件如下。
45+
如果您想修改其他 seekdb 参数,可以将配置文件挂载到容器中的 `/etc/oceanbase/seekdb.cnf`,默认配置文件如下。
4646

4747
```
4848
datafile_size=2G
@@ -62,14 +62,14 @@ docker run -d -p 2881:2881 -p 2886:2886 -v {config_file}:/etc/oceanbase/seekdb.c
6262
```
6363

6464
## 数据持久化
65-
SeekDB 部署在 `/var/lib/oceanbase` 目录中,如果您想将数据持久化到主机服务器,请将主机服务器上的空目录挂载到此路径。
65+
Seekdb 部署在 `/var/lib/oceanbase` 目录中,如果您想将数据持久化到主机服务器,请将主机服务器上的空目录挂载到此路径。
6666

6767
```
6868
mkdir -p seekdb
6969
docker run -d -p 2881:2881 -p 2886:2886 -v $PWD/seekdb:/var/lib/oceanbase --name seekdb oceanbase/seekdb
7070
```
7171

72-
## 连接到 SeekDB 实例
72+
## 连接到 seekdb 实例
7373

7474
```
7575
mysql -h 127.0.0.1 -P 2881 -u root -p # 使用 root 帐户连接

seekdb/start.sh

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
set -e
44

5+
WAIT_FOR_CONFIG_FILE_ATTEMPTS=600
6+
WAIT_FOR_PASSWORD_SET_ATTEMPTS=300
7+
WAIT_FOR_SERVICE_READY_ATTEMPTS=300
8+
WAIT_INTERVAL_SECONDS=1
9+
510
CONFIG_FILE="/etc/oceanbase/seekdb.cnf"
611

712
# Replace values in config file with environment variables if they are set
@@ -31,50 +36,51 @@ if [ -n "$LOG_DISK_SIZE" ]; then
3136
fi
3237

3338
# Execute the main process
34-
/usr/libexec/oceanbase/scripts/seekdb_systemd_start
39+
/usr/libexec/oceanbase/scripts/seekdb_systemd_start 2>/dev/null
3540

3641
OBSERVER_CONFIG_FILE="/var/lib/oceanbase/etc/observer.config.bin"
37-
for i in {1..10}; do
38-
echo "Loop iteration #$i"
42+
for i in $(seq 1 $WAIT_FOR_CONFIG_FILE_ATTEMPTS); do
3943
if [ -f "$OBSERVER_CONFIG_FILE" ]; then
4044
echo "File '$OBSERVER_CONFIG_FILE' found on attempt #$i."
4145
break
4246
fi
43-
sleep 1
47+
if [ $((i % 10)) -eq 0 ]; then
48+
echo "seekdb is still not ready."
49+
fi
50+
sleep $WAIT_INTERVAL_SECONDS
4451
done
4552
obshell agent start --seekdb --base-dir=/var/lib/oceanbase
4653

4754
INITIALIZED_FLAG="/var/lib/oceanbase/.initialized"
4855

4956
if [ ! -f "$INITIALIZED_FLAG" ]; then
5057
# change password using obshell
51-
for i in {1..10}; do
58+
for i in $(seq 1 $WAIT_FOR_PASSWORD_SET_ATTEMPTS); do
5259
curl -X PUT "http://127.0.0.1:2886/api/v1/observer/user/root/password" -d "{\"password\":\"$ROOT_PASSWORD\"}" --unix-socket "/var/lib/oceanbase/run/obshell.sock"
5360
EXIT_STATUS=$?
5461
if [ $EXIT_STATUS -eq 0 ]; then
5562
echo "Command succeeded on attempt #$i."
5663
break # Exit the loop if successful
5764
else
58-
echo "Command failed on attempt #$i (exit status: $EXIT_STATUS). Retrying in 1 seconds..."
59-
sleep 1
65+
echo "Command failed on attempt #$i (exit status: $EXIT_STATUS). Retrying in $WAIT_INTERVAL_SECONDS seconds..."
66+
sleep $WAIT_INTERVAL_SECONDS
6067
fi
6168
done
6269

63-
# Execute initialization scripts if INIT_SCRIPTS_PATH is set
64-
if [ -n "$INIT_SCRIPTS_PATH" ]; then
65-
echo "Executing initialization scripts from $INIT_SCRIPTS_PATH..."
66-
# Determine mysql connection options
67-
MYSQL_OPTS="-h 127.0.0.1 -P 2881 -u root"
68-
if [ -n "$ROOT_PASSWORD" ]; then
69-
MYSQL_OPTS="$MYSQL_OPTS -p$ROOT_PASSWORD"
70-
fi
70+
# Init database and execute init scripts
71+
MYSQL_OPTS="-h127.0.0.1 -P2881 -uroot"
72+
if [ -n "$ROOT_PASSWORD" ]; then
73+
MYSQL_OPTS="$MYSQL_OPTS -p$ROOT_PASSWORD"
74+
fi
7175

72-
if [ -n "$SEEKDB_DATABASE" ]; then
73-
mysql $MYSQL_OPTS -e "CREATE DATABASE IF NOT EXISTS \`$SEEKDB_DATABASE\`;"
74-
echo "Database $SEEKDB_DATABASE created."
75-
MYSQL_OPTS="$MYSQL_OPTS -D$SEEKDB_DATABASE"
76-
fi
76+
if [ -n "$SEEKDB_DATABASE" ]; then
77+
mysql $MYSQL_OPTS -e "CREATE DATABASE IF NOT EXISTS \`$SEEKDB_DATABASE\`;"
78+
echo "Database $SEEKDB_DATABASE created."
79+
MYSQL_OPTS="$MYSQL_OPTS -D$SEEKDB_DATABASE"
80+
fi
7781

82+
if [ -n "$INIT_SCRIPTS_PATH" ]; then
83+
echo "Executing initialization scripts from $INIT_SCRIPTS_PATH..."
7884
for sql_file in "$INIT_SCRIPTS_PATH"/*.sql; do
7985
if [ -f "$sql_file" ]; then
8086
echo "Executing $sql_file..."
@@ -92,6 +98,35 @@ else
9298
echo "Already initialized. Skipping initialization."
9399
fi
94100

101+
# Execute command passed to docker run if present
102+
if [ $# -gt 0 ]; then
103+
MYSQL_OPTS="-h127.0.0.1 -P2881 -uroot"
104+
if [ -n "$ROOT_PASSWORD" ]; then
105+
MYSQL_OPTS="$MYSQL_OPTS -p$ROOT_PASSWORD"
106+
fi
107+
108+
echo "Waiting for seekdb to be ready..."
109+
for i in $(seq 1 $WAIT_FOR_SERVICE_READY_ATTEMPTS); do
110+
if mysql $MYSQL_OPTS -e "show databases" >/dev/null 2>&1; then
111+
echo "seekdb is ready."
112+
break
113+
fi
114+
if [ $i -eq $WAIT_FOR_SERVICE_READY_ATTEMPTS ]; then
115+
echo "Timeout waiting for seekdb to be ready."
116+
exit 1
117+
fi
118+
sleep $WAIT_INTERVAL_SECONDS
119+
done
120+
121+
if [ -n "$SEEKDB_DATABASE" ]; then
122+
MYSQL_OPTS="$MYSQL_OPTS -D$SEEKDB_DATABASE"
123+
fi
124+
125+
echo "Executing sql: $*"
126+
mysql $MYSQL_OPTS -e "$*"
127+
exit $?
128+
fi
129+
95130
echo "Starting observer health check..."
96131
while pgrep observer > /dev/null; do
97132
sleep 5

0 commit comments

Comments
 (0)