15
15
*
16
16
*
17
17
* IDENTIFICATION
18
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.169 2009/03/26 22:26:07 petere Exp $
18
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.170 2009/04/12 21:02:44 adunstan Exp $
19
19
*
20
20
*-------------------------------------------------------------------------
21
21
*/
@@ -124,6 +124,7 @@ static parallel_restore_result parallel_restore(RestoreArgs *args);
124
124
static void mark_work_done (ArchiveHandle * AH , thandle worker , int status ,
125
125
ParallelSlot * slots , int n_slots );
126
126
static void fix_dependencies (ArchiveHandle * AH );
127
+ static bool has_lock_conflicts (TocEntry * te1 , TocEntry * te2 );
127
128
static void repoint_table_dependencies (ArchiveHandle * AH ,
128
129
DumpId tableId , DumpId tableDataId );
129
130
static void identify_locking_dependencies (TocEntry * te ,
@@ -3350,6 +3351,29 @@ get_next_slot(ParallelSlot *slots, int n_slots)
3350
3351
return NO_SLOT ;
3351
3352
}
3352
3353
3354
+
3355
+ /*
3356
+ * Check if te1 has an exclusive lock requirement for an item that te2 also
3357
+ * requires, whether or not te2's requirement is for an exclusive lock.
3358
+ */
3359
+ static bool
3360
+ has_lock_conflicts (TocEntry * te1 , TocEntry * te2 )
3361
+ {
3362
+ int j ,k ;
3363
+
3364
+ for (j = 0 ; j < te1 -> nLockDeps ; j ++ )
3365
+ {
3366
+ for (k = 0 ; k < te2 -> nDeps ; k ++ )
3367
+ {
3368
+ if (te1 -> lockDeps [j ] == te2 -> dependencies [k ])
3369
+ return true;
3370
+ }
3371
+ }
3372
+ return false;
3373
+ }
3374
+
3375
+
3376
+
3353
3377
/*
3354
3378
* Find the next work item (if any) that is capable of being run now.
3355
3379
*
@@ -3373,7 +3397,7 @@ get_next_work_item(ArchiveHandle *AH, TocEntry **first_unprocessed,
3373
3397
bool pref_non_data = false; /* or get from AH->ropt */
3374
3398
TocEntry * data_te = NULL ;
3375
3399
TocEntry * te ;
3376
- int i ,j , k ;
3400
+ int i ,k ;
3377
3401
3378
3402
/*
3379
3403
* Bogus heuristics for pref_non_data
@@ -3413,8 +3437,8 @@ get_next_work_item(ArchiveHandle *AH, TocEntry **first_unprocessed,
3413
3437
3414
3438
/*
3415
3439
* Check to see if the item would need exclusive lock on something
3416
- * that a currently running item also needs lock on. If so, we
3417
- * don't want to schedule them together.
3440
+ * that a currently running item also needs lock on, or vice versa.
3441
+ * If so, we don't want to schedule them together.
3418
3442
*/
3419
3443
for (i = 0 ; i < n_slots && !conflicts ; i ++ )
3420
3444
{
@@ -3423,16 +3447,12 @@ get_next_work_item(ArchiveHandle *AH, TocEntry **first_unprocessed,
3423
3447
if (slots [i ].args == NULL )
3424
3448
continue ;
3425
3449
running_te = slots [i ].args -> te ;
3426
- for (j = 0 ; j < te -> nLockDeps && !conflicts ; j ++ )
3450
+
3451
+ if (has_lock_conflicts (te , running_te ) ||
3452
+ has_lock_conflicts (running_te , te ))
3427
3453
{
3428
- for (k = 0 ; k < running_te -> nLockDeps ; k ++ )
3429
- {
3430
- if (te -> lockDeps [j ] == running_te -> lockDeps [k ])
3431
- {
3432
- conflicts = true;
3433
- break ;
3434
- }
3435
- }
3454
+ conflicts = true;
3455
+ break ;
3436
3456
}
3437
3457
}
3438
3458
0 commit comments