launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #30470
[Merge] ~cjwatson/launchpad:stagingsetup-variables into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:stagingsetup-variables into launchpad:master.
Commit message:
Parameterize some more bits of stagingsetup
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/451682
I'd like to change some of the naming of staging's databases soon (lpmain_staging → launchpad_staging; launchpad_staging_slave → launchpad_staging_standby1), so it would be convenient to have these parameterized so that they can be overridden by the script that calls `make -C database/replication stagingsetup`.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:stagingsetup-variables into launchpad:master.
diff --git a/database/replication/Makefile b/database/replication/Makefile
index 8f63dc0..61e04d5 100644
--- a/database/replication/Makefile
+++ b/database/replication/Makefile
@@ -28,9 +28,14 @@ MULTIPROC=
NEW_STAGING_CONFIG=staging-setup # For building the db with a different name.
STAGING_CONFIG=staging-db # For swapping fresh db into place.
+STAGING_DBNAME_MAIN=lpmain_staging
+STAGING_DBNAME_SESSION=session_staging
STAGING_DUMP=launchpad.dump # Dumpfile to build new staging from.
STAGING_TABLESPACE=pg_default # 'pg_default' for default
STAGING_LOGDIR=/srv/staging.launchpad.net/staging-logs
+STAGING_PGBOUNCER_MAIN=launchpad_staging launchpad_staging_slave
+STAGING_PGBOUNCER_SESSION=session_staging
+STAGING_POSTGRESQL_VERSION=10
DOGFOOD_DBNAME=launchpad_dogfood
DOGFOOD_DUMP=launchpad.dump
@@ -60,28 +65,27 @@ stagingsetup:
grep -v -E 'TRIGGER public [^ ]+ _sl_' > ${DUMPLIST}
# Deny new connections to the main DBs and kill any leftovers.
- ${STAGING_PGBOUNCER} -c 'DISABLE launchpad_staging'
- ${STAGING_PGBOUNCER} -c 'DISABLE launchpad_staging_slave'
- ${STAGING_PGBOUNCER} -c 'KILL launchpad_staging'
- ${STAGING_PGBOUNCER} -c 'KILL launchpad_staging_slave'
- ${STAGING_PGBOUNCER} -c 'RESUME launchpad_staging'
- ${STAGING_PGBOUNCER} -c 'RESUME launchpad_staging_slave'
- -${PGMASSACRE} lpmain_staging
+ set -e; for verb in DISABLE KILL RESUME; do \
+ for db in ${STAGING_PGBOUNCER_MAIN}; do \
+ ${STAGING_PGBOUNCER} -c "$$verb $$db"; \
+ done; \
+ done
+ -${PGMASSACRE} ${STAGING_DBNAME_MAIN}
# Quickly clear out the session DB. No need to DISABLE here, as
# we bring the DB back quickly.
- ${STAGING_PGBOUNCER} -c 'KILL session_staging'
- psql -d session_staging -c 'TRUNCATE sessiondata CASCADE;'
- ${STAGING_PGBOUNCER} -c 'RESUME session_staging'
+ ${STAGING_PGBOUNCER} -c 'KILL ${STAGING_PGBOUNCER_SESSION}'
+ psql -d ${STAGING_DBNAME_SESSION} -c 'TRUNCATE sessiondata CASCADE;'
+ ${STAGING_PGBOUNCER} -c 'RESUME ${STAGING_PGBOUNCER_SESSION}'
# Create the DB with the desired default tablespace.
- ${CREATEDB} --tablespace ${STAGING_TABLESPACE} lpmain_staging
+ ${CREATEDB} --tablespace ${STAGING_TABLESPACE} ${STAGING_DBNAME_MAIN}
# Restore the database. We need to restore permissions, despite
# later running security.py, to pull in permissions granted on
# production to users not maintained by security.py.
cat ${STAGING_DUMP} \
- | ./walblock.py -n 5000 -d /var/lib/postgresql/10/staging/pg_wal \
- | pg_restore --dbname=lpmain_staging --no-owner ${EXIT_ON_ERROR} \
+ | ./walblock.py -n 5000 -d /var/lib/postgresql/${STAGING_POSTGRESQL_VERSION}/staging/pg_wal \
+ | pg_restore --dbname=${STAGING_DBNAME_MAIN} --no-owner ${EXIT_ON_ERROR} \
--use-list=${DUMPLIST} -v
rm ${DUMPLIST}
# Apply database patches.
@@ -92,10 +96,11 @@ stagingsetup:
LPCONFIG=${STAGING_CONFIG} ${SHHH} ../schema/security.py \
--log-file=INFO:${STAGING_LOGDIR}/dbupgrade.log
@echo Setting feature flags
- psql -d lpmain_staging -c "INSERT INTO featureflag (flag, scope, priority, value) VALUES ('profiling.enabled', 'team:launchpad', 0, 'on') ON CONFLICT DO NOTHING"
- psql -d lpmain_staging -c "INSERT INTO featureflag (flag, scope, priority, value) VALUES ('librarian.swift.enabled', 'default', 0, 'on') ON CONFLICT DO NOTHING"
- ${STAGING_PGBOUNCER} -c 'ENABLE launchpad_staging'
- ${STAGING_PGBOUNCER} -c 'ENABLE launchpad_staging_slave'
+ psql -d ${STAGING_DBNAME_MAIN} -c "INSERT INTO featureflag (flag, scope, priority, value) VALUES ('profiling.enabled', 'team:launchpad', 0, 'on') ON CONFLICT DO NOTHING"
+ psql -d ${STAGING_DBNAME_MAIN} -c "INSERT INTO featureflag (flag, scope, priority, value) VALUES ('librarian.swift.enabled', 'default', 0, 'on') ON CONFLICT DO NOTHING"
+ set -e; for db in ${STAGING_PGBOUNCER_MAIN}; do \
+ ${STAGING_PGBOUNCER} -c "ENABLE $$db"; \
+ done
stagingswitch:
echo Nothing to do. Staging already built inplace.