diff options
author | Matthew Hodgson <matthew@matrix.org> | 2017-11-30 01:51:38 +0000 |
---|---|---|
committer | Matthew Hodgson <matthew@matrix.org> | 2017-11-30 01:51:38 +0000 |
commit | f397153dfc4020744e1cf8687abb01d4b7885a7a (patch) | |
tree | 342da238d1e7de6178731ad6a040bf9c3de16ce1 /synapse/storage/_base.py | |
parent | specify default user_directory_include_pattern (diff) | |
parent | Merge pull request #2721 from matrix-org/rav/get_user_by_access_token_comments (diff) | |
download | synapse-f397153dfc4020744e1cf8687abb01d4b7885a7a.tar.xz |
Merge branch 'develop' into matthew/search-all-local-users
Diffstat (limited to 'synapse/storage/_base.py')
-rw-r--r-- | synapse/storage/_base.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py index 0fdf49a2fd..b971f0cb18 100644 --- a/synapse/storage/_base.py +++ b/synapse/storage/_base.py @@ -495,6 +495,7 @@ class SQLBaseStore(object): Deferred(bool): True if a new entry was created, False if an existing one was updated. """ + attempts = 0 while True: try: result = yield self.runInteraction( @@ -504,6 +505,12 @@ class SQLBaseStore(object): ) defer.returnValue(result) except self.database_engine.module.IntegrityError as e: + attempts += 1 + if attempts >= 5: + # don't retry forever, because things other than races + # can cause IntegrityErrors + raise + # presumably we raced with another transaction: let's retry. logger.warn( "IntegrityError when upserting into %s; retrying: %s", @@ -600,20 +607,18 @@ class SQLBaseStore(object): @staticmethod def _simple_select_onecol_txn(txn, table, keyvalues, retcol): - if keyvalues: - where = "WHERE %s" % " AND ".join("%s = ?" % k for k in keyvalues.iterkeys()) - else: - where = "" - sql = ( - "SELECT %(retcol)s FROM %(table)s %(where)s" + "SELECT %(retcol)s FROM %(table)s" ) % { "retcol": retcol, "table": table, - "where": where, } - txn.execute(sql, keyvalues.values()) + if keyvalues: + sql += " WHERE %s" % " AND ".join("%s = ?" % k for k in keyvalues.iterkeys()) + txn.execute(sql, keyvalues.values()) + else: + txn.execute(sql) return [r[0] for r in txn] @@ -624,7 +629,7 @@ class SQLBaseStore(object): Args: table (str): table name - keyvalues (dict): column names and values to select the rows with + keyvalues (dict|None): column names and values to select the rows with retcol (str): column whos value we wish to retrieve. Returns: |