Project

General

Profile

« Previous | Next » 

Revision 2905

sql.py: DbConn: Always set the transaction isolation level to READ COMMITTED so that when a table is locked for update, its contents are frozen at that point rather than earlier. This ensures that no concurrent duplicate keys were inserted between the time the table was snapshotted (at the beginning of the transaction for SERIALIZABLE) and the time it was locked for update.

View differences:

lib/sql.py
148 148
log_debug_none = lambda msg, level=2: None
149 149

  
150 150
class DbConn:
151
    def __init__(self, db_config, serializable=True, autocommit=False,
152
        caching=True, log_debug=log_debug_none):
151
    def __init__(self, db_config, autocommit=False, caching=True,
152
        log_debug=log_debug_none):
153 153
        self.db_config = db_config
154
        self.serializable = serializable
155 154
        self.autocommit = autocommit
156 155
        self.caching = caching
157 156
        self.log_debug = log_debug
......
191 190
            self.__db = module.connect(**db_config)
192 191
            
193 192
            # Configure connection
194
            if self.serializable: self.run_query(
195
                'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE', log_level=4)
193
            self.run_query('SET TRANSACTION ISOLATION LEVEL READ COMMITTED',
194
                log_level=3)
196 195
            if schemas != None:
197 196
                search_path = [self.esc_name(s) for s in schemas.split(',')]
198 197
                search_path.append(value(run_query(self, 'SHOW search_path',

Also available in: Unified diff