Merge lp:~stub/launchpad/staging into lp:launchpad/db-devel

Proposed by Stuart Bishop
Status: Merged
Merged at revision: 10887
Proposed branch: lp:~stub/launchpad/staging
Merge into: lp:launchpad/db-devel
Diff against target: 102 lines (+42/-23)
2 files modified
database/schema/full-update.py (+6/-6)
database/schema/preflight.py (+36/-17)
To merge this branch: bzr merge lp:~stub/launchpad/staging
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Review via email: mp+71184@code.launchpad.net

Commit message

[r=allenap][bug=809123,824462] Wait for killed connections to terminate before proceeding to long transaction checks.

Description of the change

= Summary =

Wait for killed connections to terminate before proceeding to long transaction checks.

== Proposed fix ==

Loop until the connections are gone, repeatedly attempting to kill them. Report failure if they can't be killed after 10 seconds.

== Pre-implementation notes ==

== Implementation details ==

== Tests ==

== Demo and Q/A ==

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  database/schema/preflight.py
  database/schema/full-update.py

./database/schema/preflight.py
       7: '_pythonpath' imported but unused
./database/schema/full-update.py
       7: '_pythonpath' imported but unused

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'database/schema/full-update.py'
2--- database/schema/full-update.py 2011-08-03 14:30:44 +0000
3+++ database/schema/full-update.py 2011-08-11 11:42:24 +0000
4@@ -105,17 +105,17 @@
5 # work unattended.
6 #
7
8+ # Confirm we can invoke PGBOUNCER_INITD
9+ log.debug("Confirming sudo access to pgbouncer startup script")
10+ pgbouncer_rc = run_pgbouncer(log, 'status')
11+ if pgbouncer_rc != 0:
12+ return pgbouncer_rc
13+
14 # We initially ignore open connections, as they will shortly be
15 # killed.
16 if not NoConnectionCheckPreflight(log).check_all():
17 return 99
18
19- # Confirm we can invoke PGBOUNCER_INITD
20- log.debug("Confirming sudo access to pgbouncer startup script")
21- pgbouncer_rc = run_pgbouncer(log, 'status')
22- if pgbouncer_rc != 0:
23- return pgbouncer_rc
24-
25 #
26 # Start the actual upgrade. Failures beyond this point need to
27 # generate informative messages to help with recovery.
28
29=== modified file 'database/schema/preflight.py'
30--- database/schema/preflight.py 2011-08-05 13:29:24 +0000
31+++ database/schema/preflight.py 2011-08-11 11:42:24 +0000
32@@ -15,7 +15,7 @@
33
34 from datetime import timedelta
35 from optparse import OptionParser
36-import sys
37+import time
38
39 import psycopg2
40
41@@ -282,21 +282,40 @@
42
43 System users are defined by SYSTEM_USERS.
44 """
45- for node in self.lpmain_nodes:
46- cur = node.con.cursor()
47- cur.execute("""
48- SELECT
49- procpid, datname, usename, pg_terminate_backend(procpid)
50- FROM pg_stat_activity
51- WHERE
52- datname=current_database()
53- AND procpid <> pg_backend_pid()
54- AND usename NOT IN %s
55- """ % sqlvalues(SYSTEM_USERS))
56- for procpid, datname, usename, ignored in cur.fetchall():
57- self.log.warning(
58- "Killed %s [%s] on %s", usename, procpid, datname)
59- return True
60+ # We keep trying to terminate connections every 0.5 seconds for
61+ # up to 10 seconds.
62+ num_tries = 20
63+ seconds_to_pause = 0.5
64+ for loop_count in range(num_tries):
65+ all_clear = True
66+ for node in self.lpmain_nodes:
67+ cur = node.con.cursor()
68+ cur.execute("""
69+ SELECT
70+ procpid, datname, usename,
71+ pg_terminate_backend(procpid)
72+ FROM pg_stat_activity
73+ WHERE
74+ datname=current_database()
75+ AND procpid <> pg_backend_pid()
76+ AND usename NOT IN %s
77+ """ % sqlvalues(SYSTEM_USERS))
78+ for procpid, datname, usename, ignored in cur.fetchall():
79+ all_clear = False
80+ if loop_count == num_tries - 1:
81+ self.log.fatal(
82+ "Unable to kill %s [%s] on %s",
83+ usename, procpid, datname)
84+ else:
85+ self.log.warning(
86+ "Killed %s [%s] on %s", usename, procpid, datname)
87+ if all_clear:
88+ break
89+
90+ # Wait a little for any terminated connections to actually
91+ # terminate.
92+ time.sleep(seconds_to_pause)
93+ return all_clear
94
95
96 def main():
97@@ -337,4 +356,4 @@
98
99
100 if __name__ == '__main__':
101- sys.exit(main())
102+ raise SystemExit(main())

Subscribers

People subscribed via source and target branches

to status/vote changes: