Merge lp:~stub/launchpad/pending-db-changes into lp:launchpad/db-devel

Proposed by Stuart Bishop
Status: Merged
Merged at revision: 9445
Proposed branch: lp:~stub/launchpad/pending-db-changes
Merge into: lp:launchpad/db-devel
Diff against target: 127 lines (+35/-17)
4 files modified
database/replication/helpers.py (+10/-4)
database/schema/fti.py (+10/-13)
database/schema/patch-2207-62-0.sql (+14/-0)
database/schema/security.cfg (+1/-0)
To merge this branch: bzr merge lp:~stub/launchpad/pending-db-changes
Reviewer Review Type Date Requested Status
Michael Nelson (community) code Approve
Review via email: mp+27263@code.launchpad.net

Commit message

SourcePackageRelease.component NOT NULL, omit OAuthNonce from replication per current production setup, Py 2.6 deprecation fix, nagios perm

Description of the change

Collection of minor DB tweaks.

We have stopped replicating the OAuthNonce table, and tweaks to our replication maintenance scripts to stop it being added back.

fti.py was spitting a deprecation warning under Python 2.6 - fix that.

The Bug #49717 DB patch I though had been landed had not been landed. Extend this with a tweak for the OAuthNonce table, so things still cope now it is no longer replicated.

A DB permission for our nagios checks.

To post a comment you must log in.
Revision history for this message
Michael Nelson (michael.nelson) wrote :
Download full text (3.9 KiB)

Hi Stuart,

Just a few notes below. The main one I'm interested in is whether we should include the BuildFarmJob.status index in the db patch.

Thanks!

> === modified file 'database/replication/helpers.py'
> --- database/replication/helpers.py 2010-04-29 12:38:05 +0000
> +++ database/replication/helpers.py 2010-06-10 13:40:07 +0000
> @@ -420,7 +424,8 @@
> """ % sqlvalues(namespace, tablename))
> for namespace, tablename in cur.fetchall():
> key = (namespace, tablename)
> - if key not in tables and key not in pending_tables:
> + if (key not in tables and key not in pending_tables
> + and '%s.%s' % (namespace, tablename) not in IGNORED_TABLES):
> pending_tables.add(key)

Just out of interest, this kind of change (or these helpers) *could* be tested couldn't they?

>
> # Generate the set of sequences that are linked to any of our set of
> @@ -441,8 +446,9 @@
> ) AS whatever
> WHERE seq IS NOT NULL;
> """ % sqlvalues(fqn(namespace, tablename), namespace, tablename))
> - for row in cur.fetchall():
> - sequences.add(row[0])
> + for sequence, in cur.fetchall():

Nice, but would it be clearer to do:

           for sequence, whateverelse in cur.fetchall():

using something appropriate?

?
> + if sequence not in IGNORED_SEQUENCES:
> + sequences.add(sequence)
>
> # We can't easily convert the sequence name to (namespace, name) tuples,
> # so we might as well convert the tables to dot notation for consistancy.
>
> === modified file 'database/schema/fti.py'
> --- database/schema/fti.py 2010-05-19 18:07:56 +0000
> +++ database/schema/fti.py 2010-06-10 13:40:07 +0000
> @@ -319,18 +319,15 @@
> cmd += ' -h %s' % lp.dbhost
> if options.dbuser:
> cmd += ' -U %s' % options.dbuser
> - p = popen2.Popen4(cmd)
> - c = p.tochild
> - print >> c, "SET client_min_messages=ERROR;"
> - print >> c, "CREATE SCHEMA ts2;"
> - print >> c, open(tsearch2_sql_path).read().replace(
> - 'public;','ts2, public;'
> - )
> - p.tochild.close()
> - rv = p.wait()
> - if rv != 0:
> + p = subprocess.Popen(
> + cmd.split(' '), stdin=subprocess.PIPE,
> + stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
> + out, err = p.communicate(
> + "SET client_min_messages=ERROR; CREATE SCHEMA ts2;"
> + + open(tsearch2_sql_path).read().replace('public;','ts2, public;'))
> + if p.returncode != 0:
> log.fatal('Error executing %s:', cmd)
> - log.debug(p.fromchild.read())
> + log.debug(out)

Is err not useful here?

> sys.exit(rv)
>
> # Create ftq helper and its sibling _ftq.
>
> === added file 'database/schema/patch-2207-62-0.sql'
> --- database/schema/patch-2207-62-0.sql 1970-01-01 00:00:00 +0000
> +++ database/schema/patch-2207-62-0.sql 2010-06-10 13:40:07 +0000
> @@ -0,0 +1,14 @@
> +SET client_min_messages=ERROR;
> +
> +-- Bug #49717
> +ALTER TABLE SourcePackageRele...

Read more...

review: Approve (code)
Revision history for this message
Stuart Bishop (stub) wrote :

On Thu, Jun 10, 2010 at 8:53 PM, Michael Nelson
<email address hidden> wrote:

>> === modified file 'database/replication/helpers.py'
>> --- database/replication/helpers.py   2010-04-29 12:38:05 +0000
>> +++ database/replication/helpers.py   2010-06-10 13:40:07 +0000
>> @@ -420,7 +424,8 @@
>>              """ % sqlvalues(namespace, tablename))
>>          for namespace, tablename in cur.fetchall():
>>              key = (namespace, tablename)
>> -            if key not in tables and key not in pending_tables:
>> +            if (key not in tables and key not in pending_tables
>> +                and '%s.%s' % (namespace, tablename) not in IGNORED_TABLES):
>>                  pending_tables.add(key)
>
> Just out of interest, this kind of change (or these helpers) *could* be tested couldn't they?

Bits could. I tend to consider staging the test environment for most
of this though, and haven't worried about the few bits that are
testable. Its all a bit ugly, but now we know it is all working I
guess we can start cleaning things up.

>>      # Generate the set of sequences that are linked to any of our set of
>> @@ -441,8 +446,9 @@
>>                  ) AS whatever
>>              WHERE seq IS NOT NULL;
>>              """ % sqlvalues(fqn(namespace, tablename), namespace, tablename))
>> -        for row in cur.fetchall():
>> -            sequences.add(row[0])
>> +        for sequence, in cur.fetchall():
>
> Nice, but would it be clearer to do:
>
>           for sequence, whateverelse in cur.fetchall():
>
> using something appropriate?

That would give an index exception, as there is only a single column
being returned.

>> +        p = subprocess.Popen(
>> +            cmd.split(' '), stdin=subprocess.PIPE,
>> +            stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
>> +        out, err = p.communicate(
>> +            "SET client_min_messages=ERROR; CREATE SCHEMA ts2;"
>> +            + open(tsearch2_sql_path).read().replace('public;','ts2, public;'))
>> +        if p.returncode != 0:
>>              log.fatal('Error executing %s:', cmd)
>> -            log.debug(p.fromchild.read())
>> +            log.debug(out)
>
> Is err not useful here?

No. It is None because I specified stderr=subprocess.STDOUT to munge
stdout and stderr together.

> I think you added a missing index to BuildFarmJob.status last Friday too. Although it may not have helped the direct issue there, I think it should still be included. Do you?

That has already landed as patch-2207-60-1.sql. Its in a different db
patch as it has already been applied to production.

--
Stuart Bishop <email address hidden>
http://www.stuartbishop.net/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'database/replication/helpers.py'
2--- database/replication/helpers.py 2010-04-29 12:38:05 +0000
3+++ database/replication/helpers.py 2010-06-10 12:51:38 +0000
4@@ -44,7 +44,6 @@
5 ('public', 'nameblacklist'),
6 ('public', 'openidconsumerassociation'),
7 ('public', 'openidconsumernonce'),
8- ('public', 'oauthnonce'),
9 ('public', 'codeimportmachine'),
10 ('public', 'scriptactivity'),
11 ('public', 'standardshipitrequest'),
12@@ -71,6 +70,8 @@
13 # Database statistics
14 'public.databasetablestats',
15 'public.databasecpustats',
16+ # Don't replicate OAuthNonce - too busy and no real gain.
17+ 'public.oauthnonce',
18 # Ubuntu SSO database. These tables where created manually by ISD
19 # and the Launchpad scripts should not mess with them. Eventually
20 # these tables will be in a totally separate database.
21@@ -353,6 +354,9 @@
22
23 A replication set must contain all tables linked by foreign key
24 reference to the given table, and sequences used to generate keys.
25+ Tables and sequences can be added to the IGNORED_TABLES and
26+ IGNORED_SEQUENCES lists for cases where we known can safely ignore
27+ this restriction.
28
29 :param seeds: [(namespace, tablename), ...]
30
31@@ -420,7 +424,8 @@
32 """ % sqlvalues(namespace, tablename))
33 for namespace, tablename in cur.fetchall():
34 key = (namespace, tablename)
35- if key not in tables and key not in pending_tables:
36+ if (key not in tables and key not in pending_tables
37+ and '%s.%s' % (namespace, tablename) not in IGNORED_TABLES):
38 pending_tables.add(key)
39
40 # Generate the set of sequences that are linked to any of our set of
41@@ -441,8 +446,9 @@
42 ) AS whatever
43 WHERE seq IS NOT NULL;
44 """ % sqlvalues(fqn(namespace, tablename), namespace, tablename))
45- for row in cur.fetchall():
46- sequences.add(row[0])
47+ for sequence, in cur.fetchall():
48+ if sequence not in IGNORED_SEQUENCES:
49+ sequences.add(sequence)
50
51 # We can't easily convert the sequence name to (namespace, name) tuples,
52 # so we might as well convert the tables to dot notation for consistancy.
53
54=== modified file 'database/schema/fti.py'
55--- database/schema/fti.py 2010-05-19 18:07:56 +0000
56+++ database/schema/fti.py 2010-06-10 12:51:38 +0000
57@@ -14,10 +14,10 @@
58 import _pythonpath
59
60 from distutils.version import LooseVersion
61-import sys
62 import os.path
63 from optparse import OptionParser
64-import popen2
65+import subprocess
66+import sys
67 from tempfile import NamedTemporaryFile
68 from textwrap import dedent
69 import time
70@@ -319,18 +319,15 @@
71 cmd += ' -h %s' % lp.dbhost
72 if options.dbuser:
73 cmd += ' -U %s' % options.dbuser
74- p = popen2.Popen4(cmd)
75- c = p.tochild
76- print >> c, "SET client_min_messages=ERROR;"
77- print >> c, "CREATE SCHEMA ts2;"
78- print >> c, open(tsearch2_sql_path).read().replace(
79- 'public;','ts2, public;'
80- )
81- p.tochild.close()
82- rv = p.wait()
83- if rv != 0:
84+ p = subprocess.Popen(
85+ cmd.split(' '), stdin=subprocess.PIPE,
86+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
87+ out, err = p.communicate(
88+ "SET client_min_messages=ERROR; CREATE SCHEMA ts2;"
89+ + open(tsearch2_sql_path).read().replace('public;','ts2, public;'))
90+ if p.returncode != 0:
91 log.fatal('Error executing %s:', cmd)
92- log.debug(p.fromchild.read())
93+ log.debug(out)
94 sys.exit(rv)
95
96 # Create ftq helper and its sibling _ftq.
97
98=== added file 'database/schema/patch-2207-62-0.sql'
99--- database/schema/patch-2207-62-0.sql 1970-01-01 00:00:00 +0000
100+++ database/schema/patch-2207-62-0.sql 2010-06-10 12:51:38 +0000
101@@ -0,0 +1,14 @@
102+SET client_min_messages=ERROR;
103+
104+-- Bug #49717
105+ALTER TABLE SourcePackageRelease ALTER component SET NOT NULL;
106+
107+-- We are taking OAuthNonce out of replication, so we make the foreign
108+-- key reference ON DELETE CASCADE so things don't explode when we
109+-- shuffle the lpmain master around.
110+ALTER TABLE OAuthNonce DROP CONSTRAINT oauthnonce__access_token__fk;
111+ALTER TABLE OAuthNonce ADD CONSTRAINT oauthnonce__access_token__fk
112+ FOREIGN KEY (access_token) REFERENCES OAuthAccessToken
113+ ON DELETE CASCADE;
114+
115+INSERT INTO LaunchpadDatabaseRevision VALUES (2207, 62, 0);
116
117=== modified file 'database/schema/security.cfg'
118--- database/schema/security.cfg 2010-06-07 10:24:03 +0000
119+++ database/schema/security.cfg 2010-06-10 12:51:38 +0000
120@@ -1826,6 +1826,7 @@
121 type=user
122 public.archive = SELECT
123 public.buildfarmjob = SELECT
124+public.databasereplicationlag = SELECT
125 public.packagebuild = SELECT
126 public.binarypackagebuild = SELECT
127 public.buildqueue = SELECT

Subscribers

People subscribed via source and target branches

to status/vote changes: