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
diff --git a/database/replication/Makefile b/database/replication/Makefile
index 7cbfa77..c8de967 100644
--- a/database/replication/Makefile
+++ b/database/replication/Makefile
@@ -34,6 +34,19 @@ STAGING_LOGDIR=/srv/staging.launchpad.net/staging-logs
34STAGING_POSTGRESQL_VERSION=1034STAGING_POSTGRESQL_VERSION=10
35DOGFOOD_DUMP=launchpad.dump35DOGFOOD_DUMP=launchpad.dump
3636
37# Database options to pass to PostgreSQL tools.
38STAGING_DBOPTS:=$(shell LPCONFIG=${STAGING_CONFIG} ../../utilities/pgoptions.py)
39
40# If we're restoring locally, then block the restore process while there are
41# too many unshipped WAL files. If we're restoring remotely, we can't
42# easily do this, so we have to just hope that the remote systems can keep
43# up.
44ifeq (,${STAGING_DBOPTS})
45STAGING_WALBLOCK=./walblock.py -n 5000 -d /var/lib/postgresql/${STAGING_POSTGRESQL_VERSION}/staging/pg_wal
46else
47STAGING_WALBLOCK=cat
48endif
49
37# Names of underlying PostgreSQL databases.50# Names of underlying PostgreSQL databases.
38STAGING_DBNAME_MAIN=lpmain_staging51STAGING_DBNAME_MAIN=lpmain_staging
39STAGING_DBNAME_SESSION=session_staging52STAGING_DBNAME_SESSION=session_staging
@@ -74,12 +87,12 @@ stagingsetup:
74 ${STAGING_PGBOUNCER} -c "$$verb $$db"; \87 ${STAGING_PGBOUNCER} -c "$$verb $$db"; \
75 done; \88 done; \
76 done89 done
77 -${PGMASSACRE} ${STAGING_DBNAME_MAIN}90 -LP_DESTROY_REMOTE_DATABASE=yes ${PGMASSACRE} ${STAGING_DBNAME_MAIN}
7891
79 # Quickly clear out the session DB. No need to DISABLE here, as92 # Quickly clear out the session DB. No need to DISABLE here, as
80 # we bring the DB back quickly.93 # we bring the DB back quickly.
81 ${STAGING_PGBOUNCER} -c 'KILL ${STAGING_PGBOUNCER_SESSION}'94 ${STAGING_PGBOUNCER} -c 'KILL ${STAGING_PGBOUNCER_SESSION}'
82 psql -d ${STAGING_DBNAME_SESSION} -c 'TRUNCATE sessiondata CASCADE;'95 psql ${STAGING_DBOPTS} -d ${STAGING_DBNAME_SESSION} -c 'TRUNCATE sessiondata CASCADE;'
83 ${STAGING_PGBOUNCER} -c 'RESUME ${STAGING_PGBOUNCER_SESSION}'96 ${STAGING_PGBOUNCER} -c 'RESUME ${STAGING_PGBOUNCER_SESSION}'
8497
85 # Create the DB with the desired default tablespace.98 # Create the DB with the desired default tablespace.
@@ -87,8 +100,7 @@ stagingsetup:
87 # Restore the database. We need to restore permissions, despite100 # Restore the database. We need to restore permissions, despite
88 # later running security.py, to pull in permissions granted on101 # later running security.py, to pull in permissions granted on
89 # production to users not maintained by security.py.102 # production to users not maintained by security.py.
90 cat ${STAGING_DUMP} \103 < ${STAGING_DUMP} ${STAGING_WALBLOCK}
91 | ./walblock.py -n 5000 -d /var/lib/postgresql/${STAGING_POSTGRESQL_VERSION}/staging/pg_wal \
92 | pg_restore --dbname=${STAGING_DBNAME_MAIN} --no-owner ${EXIT_ON_ERROR} \104 | pg_restore --dbname=${STAGING_DBNAME_MAIN} --no-owner ${EXIT_ON_ERROR} \
93 --use-list=${DUMPLIST} -v105 --use-list=${DUMPLIST} -v
94 rm ${DUMPLIST}106 rm ${DUMPLIST}
@@ -100,8 +112,8 @@ stagingsetup:
100 LPCONFIG=${STAGING_CONFIG} ${SHHH} ../schema/security.py \112 LPCONFIG=${STAGING_CONFIG} ${SHHH} ../schema/security.py \
101 --log-file=INFO:${STAGING_LOGDIR}/dbupgrade.log113 --log-file=INFO:${STAGING_LOGDIR}/dbupgrade.log
102 @echo Setting feature flags114 @echo Setting feature flags
103 psql -d ${STAGING_DBNAME_MAIN} -c "INSERT INTO featureflag (flag, scope, priority, value) VALUES ('profiling.enabled', 'team:launchpad', 0, 'on') ON CONFLICT DO NOTHING"115 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"
104 psql -d ${STAGING_DBNAME_MAIN} -c "INSERT INTO featureflag (flag, scope, priority, value) VALUES ('librarian.swift.enabled', 'default', 0, 'on') ON CONFLICT DO NOTHING"116 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"
105 set -e; for db in ${STAGING_PGBOUNCER_MAIN}; do \117 set -e; for db in ${STAGING_PGBOUNCER_MAIN}; do \
106 ${STAGING_PGBOUNCER} -c "ENABLE $$db"; \118 ${STAGING_PGBOUNCER} -c "ENABLE $$db"; \
107 done119 done

Subscribers

People subscribed via source and target branches

to status/vote changes: