diff options
author | jadmanski <jadmanski@592f7852-d20e-0410-864c-8624ca9c26a4> | 2008-05-29 21:03:13 +0000 |
---|---|---|
committer | jadmanski <jadmanski@592f7852-d20e-0410-864c-8624ca9c26a4> | 2008-05-29 21:03:13 +0000 |
commit | f844c6d50505d53523dd71d963f2d3812a271a23 (patch) | |
tree | e431959831e8a8dcef4b372539371b5d408faf75 /tko/db.py | |
parent | ce3f8f18f749a82a303f8243dff06477995677ba (diff) |
Risk: Medium
Visibility: Should eliminate missing results errors due to the final
reparse failing because of intermittent db issues.
Adds an autoretry to the transactions used for the final reparse.
Signed-off-by: John Admanski <jadmanski@google.com>
git-svn-id: svn://test.kernel.org/autotest/trunk@1567 592f7852-d20e-0410-864c-8624ca9c26a4
Diffstat (limited to 'tko/db.py')
-rw-r--r-- | tko/db.py | 24 |
1 files changed, 17 insertions, 7 deletions
@@ -78,11 +78,15 @@ class db_sql: time.sleep(delay) - def _run_with_retry(self, function, *args, **dargs): + def run_with_retry(self, function, *args, **dargs): """Call function(*args, **dargs) until either it passes - without an operational error, or a timeout is reached. This - is intended for internal use with database functions, not - for generic use.""" + without an operational error, or a timeout is reached. + This will re-connect to the database, so it is NOT safe + to use this inside of a database transaction. + + It can be safely used with transactions, but the + transaction start & end must be completely contained + within the call to 'function'.""" OperationalError = _get_error_class("OperationalError") success = False @@ -188,7 +192,10 @@ class db_sql: return self.cur.fetchall() # run the query, re-trying after operational errors - return self._run_with_retry(exec_sql) + if self.autocommit: + return self.run_with_retry(exec_sql) + else: + return exec_sql() def select_sql(self, fields, table, sql, values): @@ -204,7 +211,10 @@ class db_sql: return self.cur.fetchall() # run the query, re-trying after operational errors - return self._run_with_retry(exec_sql) + if self.autocommit: + return self.run_with_retry(exec_sql) + else: + return exec_sql() def _exec_sql_with_commit(self, sql, values, commit): @@ -213,7 +223,7 @@ class db_sql: def exec_sql(): self.cur.execute(sql, values) self.con.commit() - self._run_with_retry(exec_sql) + self.run_with_retry(exec_sql) else: # take one shot at running the query self.cur.execute(sql, values) |