Mercurial > p > roundup > code
comparison roundup/backends/back_postgresql.py @ 3717:5770f1802cd0
better conflict retry in postgresql backend [SF#1552809]
fix time log example [SF#1554630]
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Tue, 03 Oct 2006 23:28:51 +0000 |
| parents | 50add98cbbac |
| children | f1363e19121a |
comparison
equal
deleted
inserted
replaced
| 3716:4cbbf9210edd | 3717:5770f1802cd0 |
|---|---|
| 1 #$Id: back_postgresql.py,v 1.35 2006-10-03 23:15:09 richard Exp $ | 1 #$Id: back_postgresql.py,v 1.36 2006-10-03 23:28:51 richard Exp $ |
| 2 # | 2 # |
| 3 # Copyright (c) 2003 Martynas Sklyzmantas, Andrey Lebedev <andrey@micro.lt> | 3 # Copyright (c) 2003 Martynas Sklyzmantas, Andrey Lebedev <andrey@micro.lt> |
| 4 # | 4 # |
| 5 # This module is free software, and you may redistribute it and/or modify | 5 # This module is free software, and you may redistribute it and/or modify |
| 6 # under the same terms as Python, so long as this copyright message and | 6 # under the same terms as Python, so long as this copyright message and |
| 68 raise RuntimeError, '10 attempts to create database failed' | 68 raise RuntimeError, '10 attempts to create database failed' |
| 69 | 69 |
| 70 def pg_command(cursor, command): | 70 def pg_command(cursor, command): |
| 71 '''Execute the postgresql command, which may be blocked by some other | 71 '''Execute the postgresql command, which may be blocked by some other |
| 72 user connecting to the database, and return a true value if it succeeds. | 72 user connecting to the database, and return a true value if it succeeds. |
| 73 | |
| 74 If there is a concurrent update, retry the command. | |
| 73 ''' | 75 ''' |
| 74 try: | 76 try: |
| 75 cursor.execute(command) | 77 cursor.execute(command) |
| 76 except psycopg.ProgrammingError, err: | 78 except psycopg.ProgrammingError, err: |
| 77 response = str(err).split('\n')[0] | 79 response = str(err).split('\n')[0] |
| 78 if response.find('FATAL') != -1: | 80 if response.find('FATAL') != -1: |
| 79 raise RuntimeError, response | 81 raise RuntimeError, response |
| 80 elif response.find('ERROR') != -1: | 82 elif response.find('ERROR') != -1: |
| 81 if response.find('is being accessed by other users') == -1: | 83 msgs = [ |
| 82 raise RuntimeError, response | 84 'is being accessed by other users', |
| 83 time.sleep(1) | 85 'could not serialize access due to concurrent update', |
| 84 return 0 | 86 ] |
| 87 can_retry = 0 | |
| 88 for msg in msgs: | |
| 89 if response.find(msg) == -1: | |
| 90 can_retry = 1 | |
| 91 if can_retry: | |
| 92 time.sleep(1) | |
| 93 return 0 | |
| 94 raise RuntimeError, response | |
| 85 return 1 | 95 return 1 |
| 86 | 96 |
| 87 def db_exists(config): | 97 def db_exists(config): |
| 88 """Check if database already exists""" | 98 """Check if database already exists""" |
| 89 db = connection_dict(config, 'database') | 99 db = connection_dict(config, 'database') |
