Merge lp:~allenap/launchpad/oneiric-librarian-bug-871596 into lp:launchpad

Proposed by Gavin Panella
Status: Rejected
Rejected by: Gavin Panella
Proposed branch: lp:~allenap/launchpad/oneiric-librarian-bug-871596
Merge into: lp:launchpad
Diff against target: 56 lines (+18/-8)
1 file modified
lib/lp/services/database/__init__.py (+18/-8)
To merge this branch: bzr merge lp:~allenap/launchpad/oneiric-librarian-bug-871596
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Disapprove
Launchpad code reviewers Pending
Review via email: mp+79175@code.launchpad.net

Description of the change

It seems that disconnection errors behave slightly differently on Oneiric... possibly. This branch intercepts pgcode 57P01 - admin_shutdown - and allows transactions to be retried instead of just breaking at the first opportunity. Doing this lets the example test command given in the bug to complete without failure.

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

Rather than fix this in every system, we should just fix it once in Storm. Storm catches the PostgreSQL exceptions, puts its stores in a state so they will attempt to reconnect, and raises DisconnectionError. In particular, I don't think the proposed patch works as the Storm store is being left in an inconsistent state (the next request will likely fail, and the subsequent one might reconnect).

I think this might also be the issue Garry saw with making the appserver return 503 errors when the database was unavailable.

review: Disapprove

Unmerged revisions

14139. By Gavin Panella

Use pgcode instead of string matching.

14138. By Gavin Panella

Treat unexpected disconnections from the database as a possible transient error.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/services/database/__init__.py'
2--- lib/lp/services/database/__init__.py 2010-09-24 15:21:05 +0000
3+++ lib/lp/services/database/__init__.py 2011-10-12 20:06:13 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """The lp.services.database package."""
10@@ -9,14 +9,16 @@
11 'write_transaction',
12 ]
13
14+from psycopg2 import OperationalError
15 from psycopg2.extensions import TransactionRollbackError
16-from storm.exceptions import DisconnectionError, IntegrityError
17+from storm.exceptions import (
18+ DisconnectionError,
19+ IntegrityError,
20+ )
21 import transaction
22 from twisted.python.util import mergeFunctionMetadata
23
24-from canonical.database.sqlbase import (
25- reset_store,
26- )
27+from canonical.database.sqlbase import reset_store
28
29
30 RETRY_ATTEMPTS = 3
31@@ -35,9 +37,18 @@
32 try:
33 return func(*args, **kwargs)
34 except (DisconnectionError, IntegrityError,
35- TransactionRollbackError), exc:
36+ TransactionRollbackError):
37 if attempt >= RETRY_ATTEMPTS:
38- raise # tried too many times
39+ raise # tried too many times
40+ except OperationalError, error:
41+ # 57P01 is admin_shutdown:
42+ # FATAL: terminating connection due to administrator command
43+ # SSL connection has been closed unexpectedly
44+ if error.pgcode == "57P01":
45+ if attempt >= RETRY_ATTEMPTS:
46+ raise # tried too many times
47+ else:
48+ raise
49 return mergeFunctionMetadata(func, retry_transaction_decorator)
50
51
52@@ -77,4 +88,3 @@
53 return ret
54 return retry_transaction(mergeFunctionMetadata(
55 func, write_transaction_decorator))
56-