Skip to content

Commit e9d1f0b

Browse files
author
Richard Jones
committed
Postgres backend allows transaction collisions to be ignored when...
...committing clenup in the sessions database
1 parent b2a417d commit e9d1f0b

File tree

8 files changed

+70
-15
lines changed

8 files changed

+70
-15
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Fixed:
4747
backends
4848
- Bug with name-collisions in sorted classes when sorting by Link
4949
properties in metakit backend fixed
50+
- Postgres backend allows transaction collisions to be ignored when
51+
committing clenup in the sessions database
5052

5153
2006-04-27 1.1.2
5254
Feature:

roundup/backends/back_anydbm.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_anydbm.py,v 1.201 2006-08-21 12:19:48 schlatterbeck Exp $
18+
#$Id: back_anydbm.py,v 1.202 2006-08-29 04:20:50 richard Exp $
1919
'''This module defines a backend that saves the hyperdatabase in a
2020
database chosen by anydbm. It is guaranteed to always be available in python
2121
versions >2.1.1 (the dumbdbm fallback in 2.1.1 and earlier has several
@@ -590,8 +590,17 @@ def pack(self, pack_before):
590590
#
591591
# Basic transaction support
592592
#
593-
def commit(self):
593+
def commit(self, fail_ok=False):
594594
''' Commit the current transactions.
595+
596+
Save all data changed since the database was opened or since the
597+
last commit() or rollback().
598+
599+
fail_ok indicates that the commit is allowed to fail. This is used
600+
in the web interface when committing cleaning of the session
601+
database. We don't care if there's a concurrency issue there.
602+
603+
The only backend this seems to affect is postgres.
595604
'''
596605
logging.getLogger('hyperdb').info('commit %s transactions'%(
597606
len(self.transactions)))

roundup/backends/back_metakit.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: back_metakit.py,v 1.112 2006-08-21 12:19:48 schlatterbeck Exp $
1+
# $Id: back_metakit.py,v 1.113 2006-08-29 04:20:50 richard Exp $
22
'''Metakit backend for Roundup, originally by Gordon McMillan.
33
44
Known Current Bugs:
@@ -147,8 +147,18 @@ def getclasses(self):
147147
# --- end of ping's spec
148148

149149
# --- exposed methods
150-
def commit(self):
151-
'''commit all changes to the database'''
150+
def commit(self, fail_ok=False):
151+
''' Commit the current transactions.
152+
153+
Save all data changed since the database was opened or since the
154+
last commit() or rollback().
155+
156+
fail_ok indicates that the commit is allowed to fail. This is used
157+
in the web interface when committing cleaning of the session
158+
database. We don't care if there's a concurrency issue there.
159+
160+
The only backend this seems to affect is postgres.
161+
'''
152162
if self.dirty:
153163
self._db.commit()
154164
for cl in self.classes.values():

roundup/backends/back_mysql.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#$Id: back_mysql.py,v 1.70 2006-07-13 10:14:56 schlatterbeck Exp $
1+
#$Id: back_mysql.py,v 1.71 2006-08-29 04:20:50 richard Exp $
22
#
33
# Copyright (c) 2003 Martynas Sklyzmantas, Andrey Lebedev <[email protected]>
44
#
@@ -528,10 +528,13 @@ def create_class(self, spec):
528528
vals = (spec.classname, 1)
529529
self.sql(sql, vals)
530530

531-
def sql_commit(self):
531+
def sql_commit(self, fail_ok=False):
532532
''' Actually commit to the database.
533533
'''
534534
logging.getLogger('hyperdb').info('commit')
535+
536+
# MySQL commits don't seem to ever fail, the latest update winning.
537+
# makes you wonder why they have transactions...
535538
self.conn.commit()
536539

537540
# open a new cursor for subsequent work

roundup/backends/back_postgresql.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#$Id: back_postgresql.py,v 1.33 2006-08-23 12:57:10 schlatterbeck Exp $
1+
#$Id: back_postgresql.py,v 1.34 2006-08-29 04:20:50 richard Exp $
22
#
33
# Copyright (c) 2003 Martynas Sklyzmantas, Andrey Lebedev <[email protected]>
44
#
@@ -181,6 +181,24 @@ def add_actor_column(self):
181181
def __repr__(self):
182182
return '<roundpsycopgsql 0x%x>' % id(self)
183183

184+
def sql_commit(self, fail_ok=False):
185+
''' Actually commit to the database.
186+
'''
187+
logging.getLogger('hyperdb').info('commit')
188+
189+
try:
190+
self.conn.commit()
191+
except psycopg.ProgrammingError, message:
192+
# we've been instructed that this commit is allowed to fail
193+
if fail_ok and str(message).endswith('could not serialize '
194+
'access due to concurrent update'):
195+
logging.getLogger('hyperdb').info('commit FAILED, but fail_ok')
196+
else:
197+
raise
198+
199+
# open a new cursor for subsequent work
200+
self.cursor = self.conn.cursor()
201+
184202
def sql_stringquote(self, value):
185203
''' psycopg.QuotedString returns a "buffer" object with the
186204
single-quotes around it... '''

roundup/backends/rdbms_common.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: rdbms_common.py,v 1.177 2006-08-23 12:57:10 schlatterbeck Exp $
18+
#$Id: rdbms_common.py,v 1.178 2006-08-29 04:20:50 richard Exp $
1919
''' Relational database (SQL) backend common code.
2020
2121
Basics:
@@ -1188,23 +1188,30 @@ def pack(self, pack_before):
11881188
"action<>'create'"%(classname, self.arg)
11891189
self.sql(sql, (date_stamp,))
11901190

1191-
def sql_commit(self):
1191+
def sql_commit(self, fail_ok=False):
11921192
''' Actually commit to the database.
11931193
'''
11941194
logging.getLogger('hyperdb').info('commit')
1195+
11951196
self.conn.commit()
11961197

11971198
# open a new cursor for subsequent work
11981199
self.cursor = self.conn.cursor()
11991200

1200-
def commit(self):
1201+
def commit(self, fail_ok=False):
12011202
''' Commit the current transactions.
12021203
12031204
Save all data changed since the database was opened or since the
12041205
last commit() or rollback().
1206+
1207+
fail_ok indicates that the commit is allowed to fail. This is used
1208+
in the web interface when committing cleaning of the session
1209+
database. We don't care if there's a concurrency issue there.
1210+
1211+
The only backend this seems to affect is postgres.
12051212
'''
12061213
# commit the database
1207-
self.sql_commit()
1214+
self.sql_commit(fail_ok)
12081215

12091216
# now, do all the other transaction stuff
12101217
for method, args in self.transactions:

roundup/cgi/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: client.py,v 1.226 2006-06-06 01:44:44 richard Exp $
1+
# $Id: client.py,v 1.227 2006-08-29 04:20:50 richard Exp $
22

33
"""WWW request handler (also used in the stand-alone server).
44
"""
@@ -334,7 +334,7 @@ def clean_sessions(self):
334334
sessions.clean(now)
335335
self.db.getOTKManager().clean(now)
336336
sessions.set('last_clean', last_use=time.time())
337-
self.db.commit()
337+
self.db.commit(fail_ok=True)
338338

339339
def determine_charset(self):
340340
"""Look for client charset in the form parameters or browser cookie.

roundup/hyperdb.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: hyperdb.py,v 1.125 2006-08-22 19:33:02 schlatterbeck Exp $
18+
# $Id: hyperdb.py,v 1.126 2006-08-29 04:20:50 richard Exp $
1919

2020
"""Hyperdatabase implementation, especially field types.
2121
"""
@@ -728,6 +728,12 @@ def commit(self):
728728
729729
Save all data changed since the database was opened or since the
730730
last commit() or rollback().
731+
732+
fail_ok indicates that the commit is allowed to fail. This is used
733+
in the web interface when committing cleaning of the session
734+
database. We don't care if there's a concurrency issue there.
735+
736+
The only backend this seems to affect is postgres.
731737
'''
732738
raise NotImplementedError
733739

0 commit comments

Comments
 (0)