Skip to content

Commit 07b41ba

Browse files
committed
Add a check (with timeout) for the database to exist before starting the TE process.
Add diagnostics to TE and SM startup logging. Update README. Add comments to .env file.
1 parent 51aad41 commit 07b41ba

File tree

3 files changed

+68
-19
lines changed

3 files changed

+68
-19
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Docker compose files for starting a nuodb database on the local host.
33

44
These docker compose files will create:
55
* a new docker network specifically for this database;
6-
* separate AP (admin), TE, and SM containers for the NuoDB processes;
6+
* separate AP (admin), TE, and SM containers for each NuoDB process;
77
* a separate CD (collector) container for each engine container - to enable NuoDB Insights;
88
* an influxdb and grafana container to host the NuoDB Insights dashboards.
99

@@ -16,5 +16,14 @@ Note that the container names will have the `project` name embedded - which is t
1616
- if you want to use the a specific SQL engine, you will need an image that supports that engine;
1717
- if you want to access the database from outside the `docker network` then set `EXTERNAL_ADDRESS`
1818
-- either in the `.env` file, _or_ by setting `EXTERNAL_ADDRESS` on the `docker-compose up` command-line;
19+
- if you want to import initial state from a backup into the new database, set `IMPORT_SOURCE` to a path
20+
on the _local_ machine. The SM container will mount this file as a volume and extract (untar) it into the
21+
archive dir prior to starting the SM process;
22+
(only if the archive dir is empty - so the SM container can be stopped and restarted without being reinitialised.)
23+
-- if you have set `IMPORT_SOURCE` _and_ it is a large file that takes multiple minutes to extract, you _may_ need to
24+
set `STARTUP_TIMEOUT` to a larger value, to stop the starup from timeing our _before_ the IMPORT has completed.
1925
3. create and start the nuodb database with `docker-compose up -d`;
2026
4. stop and delete everything with `docker-compose down`;
27+
28+
To specify env vars on the command-line, specify them _before_ the `docker-compose` command.
29+
Ex: `IMPORT_SOURCE=./mydb.bak.tgz STARTUP_TIMEOUT=300 docker-compose up -d`

nuodb/.env

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,33 @@
22
# default ENV VAR values
33
#
44

5-
NUODB_VERSION=nuodb/nuodb-ce:4.1.2.vee-4
5+
NUODB_IMAGE=nuodb/nuodb-ce:4.1.2.vee-4
66

7-
DB_NAME=bryo
7+
DB_NAME=demo
88
DB_USER=dba
9-
DB_PASSWORD=secret
9+
DB_PASSWORD=dba
1010
ENGINE_MEM=1Gi
1111
SQL_ENGINE=vee
1212

13+
# Set to a larger value if SM startup takes unusually long
14+
# - for example if IMPORT_SOURCE (see below) is a large file that takes multiple minutes to extract.
15+
STARTUP_TIMEOUT=60
16+
17+
# Uncomment and set, or set on the docker-compose command-line to add further engine options
18+
# ENGINE_OPTIONS=
19+
20+
# normally this is left unset, causing the default to be used.
21+
ARCHIVE_PATH=
22+
23+
# set IMPORT_SOURCE to the path of a LOCAL file on the host where docker-compose is being run.
24+
# It will be mounted from that location into the SM container, from where it will be extracted
25+
# and used as the initial state of the database.
1326
IMPORT_SOURCE=
1427
IMPORT_LEVEL=1
1528
IMPORT_PATH=/var/opt/nuodb/import.tz
16-
# Set the max time that an archive IMPORT operation could take default=600000 (10 minutes)
17-
# - this configures the engine startup timeout to be at least this long
18-
# MAX_IMPORT_TIME_MS=
1929

2030
PEER_ADDRESS=nuoadmin1
2131
NUOCMD_API_SERVER=nuoadmin1:8888
2232

23-
# Uncomment, or provide on the command-line to enable external access to the database
33+
# Uncomment and set, or set on the docker-compose command-line to enable external access to the database
2434
# EXTERNAL_ADDRESS=

nuodb/docker-compose.yaml

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '3'
22
services:
33
nuoadmin1:
4-
image: $NUODB_VERSION
4+
image: $NUODB_IMAGE
55
environment:
66
NUODB_DOMAIN_ENTRYPOINT: $PEER_ADDRESS
77
hostname: $PEER_ADDRESS
@@ -11,47 +11,73 @@ services:
1111
command:
1212
- "nuoadmin"
1313
- "--"
14-
- "pendingProcessTimeout=${MAX_IMPORT_TIME_MS:-600000}"
14+
- "pendingProcessTimeout=${STARTUP_TIMEOUT:-60}000"
1515
- "pendingReconnectTimeout=90000"
1616
- "thrift.message.max=1073741824"
1717
- "processLivenessCheckSec=30"
1818

1919
sm:
20-
image: $NUODB_VERSION
20+
image: $NUODB_IMAGE
2121
environment:
2222
# push the current resolved value of the VAR
2323
NUOCMD_API_SERVER:
24+
ARCHIVE_DIR: ${ARCHIVE_PATH:-/var/opt/nuodb/archive}
25+
DB_OPTIONS: "mem ${ENGINE_MEM:-1Gi} execution-engine ${SQL_ENGINE:-vee} ${ENGINE_OPTIONS:-}"
2426
hostname: sm1
2527
depends_on:
2628
- nuoadmin1
2729
volumes:
2830
- ${IMPORT_SOURCE:-./.env}:${IMPORT_PATH:-/var/tmp/env}
31+
32+
## NOTE: use '$$' for any variable that is to be evaluated at runtime IN THE SHELL.
33+
# Any variable with a single '$' is resolved by docker-compose and written literally into the command string.
2934
command:
3035
- "sh"
3136
- "-c"
3237
- |
33-
if [ -n "$IMPORT_SOURCE" -a -f $IMPORT_PATH -a ! -f /var/opt/nuodb/archive/1.atm ]; then
34-
echo "Importing from $IMPORT_PATH into /var/opt/nuodb/archive..."
35-
tar xf $IMPORT_PATH --strip-components ${IMPORT_LEVEL:-1} -C /var/opt/nuodb/archive || exit 98
36-
nuodocker restore archive --origin-dir /var/opt/nuodb/archive --restore-dir /var/opt/nuodb/archive --db-name $DB_NAME --clean-metadata || exit 99
38+
if [ -n "$IMPORT_SOURCE" -a -f "$IMPORT_PATH" -a ! -f $$ARCHIVE_DIR/1.atm ]; then
39+
echo "Importing from $IMPORT_PATH into $$ARCHIVE_DIR..."
40+
tar xf $IMPORT_PATH --strip-components ${IMPORT_LEVEL:-1} -C $$ARCHIVE_DIR || exit 98
41+
find $$ARCHIVE_DIR -name '1.*'
42+
nuodocker restore archive --origin-dir $$ARCHIVE_DIR --restore-dir $$ARCHIVE_DIR --db-name $DB_NAME --clean-metadata || exit 99
3743
fi
38-
nuodocker start sm --db-name "$DB_NAME" --server-id "$PEER_ADDRESS" --dba-user "$DB_USER" --dba-password "$DB_PASSWORD" --options "alt-address sm1" --database-options "mem ${ENGINE_MEM:-1Gi} execution-engine ${SQL_ENGINE:-vee}"
44+
nuodocker start sm --db-name "$DB_NAME" --server-id "$PEER_ADDRESS" --dba-user "$DB_USER" --dba-password "$DB_PASSWORD" --options "alt-address sm1" --database-options "$$DB_OPTIONS"
3945
4046
te1:
41-
image: $NUODB_VERSION
47+
image: $NUODB_IMAGE
4248
environment:
4349
# push the current resolved value of the VAR
4450
NUOCMD_API_SERVER:
51+
STARTUP_TIMEOUT: ${STARTUP_TIMEOUT:-90}
4552
hostname: te1
4653
depends_on:
4754
- nuoadmin1
4855
- sm
4956
ports:
5057
- 48006:48006
51-
command: [ "nuodocker", "start", "te", "--db-name", "$DB_NAME", "--server-id", "$PEER_ADDRESS", "--options", "alt-address ${EXTERNAL_ADDRESS:-te1}" ]
58+
59+
## NOTE: use '$$' for any variable that is to be evaluated at runtime IN THE SHELL.
60+
# Any variable with a single '$' is resolved by docker-compose and written literally into the command string.
61+
command:
62+
- "sh"
63+
- "-c"
64+
- |
65+
sleepTime=0
66+
sleepQuantum=30
67+
while [ -z "$$(nuocmd get database --db-name $DB_NAME)" -o $$? -ne 0 ] ; do
68+
if [ $$sleepTime -ge $$STARTUP_TIMEOUT ]; then
69+
echo "Timed out waiting for database startup ($$sleepTime sec)..."
70+
exit 97
71+
fi
72+
echo "Waiting for confirmation that database $DB_NAME exists..."
73+
sleep $$sleepQuantum
74+
sleepTime=$$(( sleepTime + sleepQuantum ))
75+
[ $$sleepQuantum -lt $$((STARTUP_TIMEOUT / 2)) ] && sleepQuantum=$$(( sleepQuantum + 30 ))
76+
done
77+
nuodocker start te --db-name "$DB_NAME" --server-id "$PEER_ADDRESS" --options "alt-address ${EXTERNAL_ADDRESS:-te1}"
5278
5379
# te2:
54-
# image: $NUODB_VERSION
80+
# image: $NUODB_IMAGE
5581
# environment:
5682
# # push the current resolved value of the VAR
5783
# NUOCMD_API_SERVER:
@@ -72,6 +98,7 @@ services:
7298
# - "8082:8082"
7399
volumes:
74100
- ./conf/initdb.sh:/docker-entrypoint-initdb.d/initdb.sh
101+
75102
nuocd-sm:
76103
image: nuodb/nuodb-collector:latest
77104
depends_on:
@@ -82,6 +109,7 @@ services:
82109
INFLUXURL: http://influxdb:8086
83110
NUOCD_HOSTNAME: sm1
84111
pid: 'service:sm'
112+
85113
nuocd-te1:
86114
image: nuodb/nuodb-collector:latest
87115
depends_on:
@@ -92,6 +120,7 @@ services:
92120
INFLUXURL: http://influxdb:8086
93121
NUOCD_HOSTNAME: te1
94122
pid: 'service:te1'
123+
95124
# nuocd-te2:
96125
# image: nuodb/nuodb-collector:latest
97126
# depends_on:
@@ -114,6 +143,7 @@ services:
114143
- ./provisioning:/etc/grafana/provisioning
115144
ports:
116145
- "3000:3000"
146+
117147
# ycsb-demo:
118148
# image: nuodb/ycsb:latest
119149
# depends_on:

0 commit comments

Comments
 (0)