Merge ~cjwatson/launchpad:stagingsetup-remote into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 1e6f89aea4b8f95c22e6fdcead1384cf8299d8e2
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:stagingsetup-remote
Merge into: launchpad:master
Diff against target: 60 lines (+18/-6)
1 file modified
database/replication/Makefile (+18/-6)
Reviewer Review Type Date Requested Status
Guruprasad Approve
Review via email: mp+451925@code.launchpad.net

Commit message

Allow stagingsetup to work remotely

Description of the change

I haven't actually been able to test this yet, so this is a little theoretical, but it should be a no-op for the existing setup (because `LPCONFIG=staging-db ../../utilities/pgoptions.py` returns empty).

William and I think that `walblock` will prove to be unnecessary since replication should be able to keep up on PS5, so for now let's try without it rather than trying to figure out how to port it.

To post a comment you must log in.
Revision history for this message
Guruprasad (lgp171188) wrote :

LGTM 👍

review: Approve
Revision history for this message
Colin Watson (cjwatson) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/database/replication/Makefile b/database/replication/Makefile
2index 7cbfa77..c8de967 100644
3--- a/database/replication/Makefile
4+++ b/database/replication/Makefile
5@@ -34,6 +34,19 @@ STAGING_LOGDIR=/srv/staging.launchpad.net/staging-logs
6 STAGING_POSTGRESQL_VERSION=10
7 DOGFOOD_DUMP=launchpad.dump
8
9+# Database options to pass to PostgreSQL tools.
10+STAGING_DBOPTS:=$(shell LPCONFIG=${STAGING_CONFIG} ../../utilities/pgoptions.py)
11+
12+# If we're restoring locally, then block the restore process while there are
13+# too many unshipped WAL files. If we're restoring remotely, we can't
14+# easily do this, so we have to just hope that the remote systems can keep
15+# up.
16+ifeq (,${STAGING_DBOPTS})
17+STAGING_WALBLOCK=./walblock.py -n 5000 -d /var/lib/postgresql/${STAGING_POSTGRESQL_VERSION}/staging/pg_wal
18+else
19+STAGING_WALBLOCK=cat
20+endif
21+
22 # Names of underlying PostgreSQL databases.
23 STAGING_DBNAME_MAIN=lpmain_staging
24 STAGING_DBNAME_SESSION=session_staging
25@@ -74,12 +87,12 @@ stagingsetup:
26 ${STAGING_PGBOUNCER} -c "$$verb $$db"; \
27 done; \
28 done
29- -${PGMASSACRE} ${STAGING_DBNAME_MAIN}
30+ -LP_DESTROY_REMOTE_DATABASE=yes ${PGMASSACRE} ${STAGING_DBNAME_MAIN}
31
32 # Quickly clear out the session DB. No need to DISABLE here, as
33 # we bring the DB back quickly.
34 ${STAGING_PGBOUNCER} -c 'KILL ${STAGING_PGBOUNCER_SESSION}'
35- psql -d ${STAGING_DBNAME_SESSION} -c 'TRUNCATE sessiondata CASCADE;'
36+ psql ${STAGING_DBOPTS} -d ${STAGING_DBNAME_SESSION} -c 'TRUNCATE sessiondata CASCADE;'
37 ${STAGING_PGBOUNCER} -c 'RESUME ${STAGING_PGBOUNCER_SESSION}'
38
39 # Create the DB with the desired default tablespace.
40@@ -87,8 +100,7 @@ stagingsetup:
41 # Restore the database. We need to restore permissions, despite
42 # later running security.py, to pull in permissions granted on
43 # production to users not maintained by security.py.
44- cat ${STAGING_DUMP} \
45- | ./walblock.py -n 5000 -d /var/lib/postgresql/${STAGING_POSTGRESQL_VERSION}/staging/pg_wal \
46+ < ${STAGING_DUMP} ${STAGING_WALBLOCK}
47 | pg_restore --dbname=${STAGING_DBNAME_MAIN} --no-owner ${EXIT_ON_ERROR} \
48 --use-list=${DUMPLIST} -v
49 rm ${DUMPLIST}
50@@ -100,8 +112,8 @@ stagingsetup:
51 LPCONFIG=${STAGING_CONFIG} ${SHHH} ../schema/security.py \
52 --log-file=INFO:${STAGING_LOGDIR}/dbupgrade.log
53 @echo Setting feature flags
54- psql -d ${STAGING_DBNAME_MAIN} -c "INSERT INTO featureflag (flag, scope, priority, value) VALUES ('profiling.enabled', 'team:launchpad', 0, 'on') ON CONFLICT DO NOTHING"
55- psql -d ${STAGING_DBNAME_MAIN} -c "INSERT INTO featureflag (flag, scope, priority, value) VALUES ('librarian.swift.enabled', 'default', 0, 'on') ON CONFLICT DO NOTHING"
56+ psql ${STAGING_DBOPTS} -d ${STAGING_DBNAME_MAIN} -c "INSERT INTO featureflag (flag, scope, priority, value) VALUES ('profiling.enabled', 'team:launchpad', 0, 'on') ON CONFLICT DO NOTHING"
57+ psql ${STAGING_DBOPTS} -d ${STAGING_DBNAME_MAIN} -c "INSERT INTO featureflag (flag, scope, priority, value) VALUES ('librarian.swift.enabled', 'default', 0, 'on') ON CONFLICT DO NOTHING"
58 set -e; for db in ${STAGING_PGBOUNCER_MAIN}; do \
59 ${STAGING_PGBOUNCER} -c "ENABLE $$db"; \
60 done

Subscribers

People subscribed via source and target branches

to status/vote changes: