Merge lp:~stub/launchpad/db-deploy into lp:launchpad

Proposed by Stuart Bishop
Status: Merged
Approved by: Stuart Bishop
Approved revision: no longer in the source branch.
Merged at revision: 13013
Proposed branch: lp:~stub/launchpad/db-deploy
Merge into: lp:launchpad
Diff against target: 66 lines (+27/-5)
1 file modified
database/schema/preflight.py (+27/-5)
To merge this branch: bzr merge lp:~stub/launchpad/db-deploy
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review via email: mp+60491@code.launchpad.net

Commit message

[r=stub][bug=777559] Connections to databases not subscribed to the main Launchpad replication set should not block Launchpad database updates.

Description of the change

Connections to the SSO database should not block production rollouts.

The SSO database is not subscribed to the main Launchpad replications set. This is the only set of tables that is locked during a database update, so connections to the SSO database do not affect rollouts (this is by design).

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

In the name of the Senate and Peoples of Rome.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'database/schema/preflight.py'
2--- database/schema/preflight.py 2011-04-27 09:13:48 +0000
3+++ database/schema/preflight.py 2011-05-10 11:33:17 +0000
4@@ -26,7 +26,7 @@
5
6
7 # Ignore connections by these users.
8-SYSTEM_USERS = frozenset(['postgres', 'slony', 'nagios'])
9+SYSTEM_USERS = frozenset(['postgres', 'slony', 'nagios', 'lagmon'])
10
11 # How lagged the cluster can be before failing the preflight check.
12 MAX_LAG = timedelta(seconds=45)
13@@ -37,14 +37,32 @@
14 self.log = log
15 self.is_replicated = replication.helpers.slony_installed(master_con)
16 if self.is_replicated:
17- self.nodes = replication.helpers.get_all_cluster_nodes(master_con)
18+ self.nodes = set(
19+ replication.helpers.get_all_cluster_nodes(master_con))
20 for node in self.nodes:
21 node.con = psycopg2.connect(node.connection_string)
22 node.con.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
23 else:
24 node = replication.helpers.Node(None, None, None, True)
25 node.con = master_con
26- self.nodes = [node]
27+ self.nodes = set([node])
28+
29+ # Create a list of nodes subscribed to the replicated sets we
30+ # are modifying.
31+ cur = master_con.cursor()
32+ cur.execute("""
33+ WITH subscriptions AS (
34+ SELECT *
35+ FROM _sl.sl_subscribe
36+ WHERE sub_set = 1 AND sub_active IS TRUE)
37+ SELECT sub_provider FROM subscriptions
38+ UNION
39+ SELECT sub_receiver FROM subscriptions
40+ """)
41+ lpmain_node_ids = set(row[0] for row in cur.fetchall())
42+ self.lpmain_nodes = set(
43+ node for node in self.nodes
44+ if node.node_id in lpmain_node_ids)
45
46 def check_is_superuser(self):
47 """Return True if all the node connections are as superusers."""
48@@ -65,12 +83,16 @@
49 return success
50
51 def check_open_connections(self):
52- """Return False if any nodes have connections from non-system users.
53+ """False if any lpmain nodes have connections from non-system users.
54+
55+ We only check on subscribed nodes, as there will be active systems
56+ connected to other nodes in the replication cluster (such as the
57+ SSO servers).
58
59 System users are defined by SYSTEM_USERS.
60 """
61 success = True
62- for node in self.nodes:
63+ for node in self.lpmain_nodes:
64 cur = node.con.cursor()
65 cur.execute("""
66 SELECT datname, usename, COUNT(*) AS num_connections