Skip to content

docker: Speed up startup of the materialized container #33100

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

Merged
merged 1 commit into from
Jul 22, 2025
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
15 changes: 4 additions & 11 deletions misc/images/materialized-base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,18 @@ FROM materialize/console:25.2.3 AS console

MZFROM ubuntu-base

RUN groupadd --system --gid=999 materialize \
&& useradd --system --gid=999 --uid=999 --create-home materialize

ARG CI_SANITIZER=none

RUN apt-get update \
RUN groupadd --system --gid=999 materialize \
&& useradd --system --gid=999 --uid=999 --create-home materialize \
&& apt-get update \
&& TZ=UTC DEBIAN_FRONTEND=noninteractive apt-get -qy install --no-install-recommends \
ca-certificates \
curl \
gettext-base \
nginx \
postgresql \
postgresql-contrib \
tini \
ssh \
tini \
&& if [ "$CI_SANITIZER" != "none" ]; then \
TZ=UTC DEBIAN_FRONTEND=noninteractive apt-get -qy install --no-install-recommends llvm; \
fi \
Expand All @@ -57,7 +54,3 @@ RUN MZ_ENDPOINT=http://localhost:6876 \
&& rm /etc/nginx/templates/default.conf.template

USER materialize

RUN pg_ctlcluster 16 main start \
&& psql -U postgres -c "CREATE ROLE root WITH LOGIN PASSWORD 'root'" \
&& psql -U postgres -c "CREATE DATABASE root OWNER root"
1 change: 1 addition & 0 deletions misc/python/materialize/mzcompose/services/materialized.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def __init__(

environment = [
"MZ_NO_TELEMETRY=1",
"MZ_NO_BUILTIN_CONSOLE=1",
"MZ_TEST_ONLY_DUMMY_SEGMENT_CLIENT=true",
f"MZ_SOFT_ASSERTIONS={int(soft_assertions)}",
# The following settings can not be baked in the default image, as they
Expand Down
10 changes: 10 additions & 0 deletions src/materialized/ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ COPY materialized entrypoint.sh /usr/local/bin/
USER root
RUN ln -s /usr/local/bin/materialized /usr/local/bin/environmentd \
&& ln -s /usr/local/bin/materialized /usr/local/bin/clusterd

USER materialize

RUN bash -c '\
set -euo pipefail; \
tini -- entrypoint.sh & \
tini_pid=$!; \
until curl -sf localhost:6878/api/readyz; do sleep 0.1; done; \
kill -TERM "$tini_pid"; \
wait "$tini_pid" || true; \
pg_ctlcluster 16 main stop --mode=fast --force'

ENTRYPOINT ["tini", "--", "entrypoint.sh"]
13 changes: 8 additions & 5 deletions src/materialized/ci/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,18 @@ EOF

# Start PostgreSQL, unless suppressed.
if [ -z "${MZ_NO_BUILTIN_POSTGRES:-}" ]; then
(trap 'pg_ctlcluster 16 main stop --mode=fast --force' SIGTERM SIGINT
rm -f /var/run/postgresql/.s.PGSQL.26257.lock
pg_ctlcluster 16 main start
psql -U root -c "CREATE SCHEMA IF NOT EXISTS consensus"
psql -U root -c "CREATE SCHEMA IF NOT EXISTS storage"
psql -U root -c "CREATE SCHEMA IF NOT EXISTS adapter"
psql -U root -c "CREATE SCHEMA IF NOT EXISTS tsoracle"
psql -U postgres -c "CREATE ROLE root WITH LOGIN PASSWORD 'root'" || true
psql -U postgres -c "CREATE DATABASE root OWNER root" || true
psql -U root -c "CREATE SCHEMA IF NOT EXISTS consensus; CREATE SCHEMA IF NOT EXISTS storage; CREATE SCHEMA IF NOT EXISTS adapter; CREATE SCHEMA IF NOT EXISTS tsoracle") &
fi

# Start nginx to serve the console.
nginx
if [ -z "${MZ_NO_BUILTIN_CONSOLE:-}" ]; then
nginx &
fi

if [[ ! -f /mzdata/environment-id ]]; then
echo "docker-container-$(cat /proc/sys/kernel/random/uuid)-0" > /mzdata/environment-id
Expand Down
2 changes: 1 addition & 1 deletion test/sqllogictest/cardinality.slt
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ SHOW optimizer_oneshot_stats_timeout;
COMPLETE 1

statement ok
SELECT mz_unsafe.mz_sleep(2)
SELECT mz_unsafe.mz_sleep(3)

query T multiline
EXPLAIN OPTIMIZED PLAN WITH(join implementations, humanized expressions) AS VERBOSE TEXT FOR SELECT * FROM t JOIN t2 ON t.x = t2.x JOIN t3 ON t.x = t3.x JOIN t4 ON t.x = t4.x JOIN t5 ON t.x = t5.x JOIN t6 ON t.x = t6.x JOIN t7 ON t.x = t7.x JOIN t8 ON t.x = t8.x JOIN t9 ON t.x = t9.x JOIN t10 ON t.x = t10.x;
Expand Down