Project

General

Profile

« Previous | Next » 

Revision 2908

sql.py: put_table(), mk_select(): Switched back to having put_table() acquire the EXCLUSIVE locks, but right at the beginning of the transaction, in order to avoid lock upgrades which cause deadlocks

View differences:

lib/sql.py
561 561
        if join_.type_ is sql_gen.filter_out: # filter no match
562 562
            conds.append((sql_gen.Col(table_not_null_col(db, table), table),
563 563
                sql_gen.CompareCond(None, '~=')))
564
            # Prevent concurrent duplicate keys when used with INSERT SELECT
565
            lock_table(db, sql_gen.underlying_table(table), 'EXCLUSIVE')
566 564
        
567 565
        query += '\n'+join_.to_str(db, left_table)
568 566
        
......
1177 1175
    input_joins = [in_tables0]+[sql_gen.Join(v,
1178 1176
        {in_pkey: sql_gen.join_same_not_null}) for v in in_tables_]
1179 1177
    
1178
    log_debug('Locking output tables to prevent concurrent duplicate keys')
1179
    # Must happen before any SELECT query on these tables to avoid lock upgrades
1180
    for table in [out_table, errors_table_]: lock_table(db, table, 'EXCLUSIVE')
1181
    
1180 1182
    if into == None:
1181 1183
        into = into_table_name(out_table, in_tables0, mapping, is_func)
1182 1184
    into = sql_gen.as_Table(into)

Also available in: Unified diff