Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f7a08e7

Browse files
committed
Fix logic to detect conflicts or blocks involving exclusive locks in parallel restore items.
If a currently running item needs an exclusive lock on any item that the candidate items needs any sort of lock on, or vice versa, then the candidate item is not allowed to run now, and must wait till later.
1 parent e1e17e2 commit f7a08e7

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* 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 $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -124,6 +124,7 @@ static parallel_restore_result parallel_restore(RestoreArgs *args);
124124
static void mark_work_done(ArchiveHandle *AH, thandle worker, int status,
125125
ParallelSlot *slots, int n_slots);
126126
static void fix_dependencies(ArchiveHandle *AH);
127+
static bool has_lock_conflicts(TocEntry *te1, TocEntry *te2);
127128
static void repoint_table_dependencies(ArchiveHandle *AH,
128129
DumpId tableId, DumpId tableDataId);
129130
static void identify_locking_dependencies(TocEntry *te,
@@ -3350,6 +3351,29 @@ get_next_slot(ParallelSlot *slots, int n_slots)
33503351
return NO_SLOT;
33513352
}
33523353

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+
33533377
/*
33543378
* Find the next work item (if any) that is capable of being run now.
33553379
*
@@ -3373,7 +3397,7 @@ get_next_work_item(ArchiveHandle *AH, TocEntry **first_unprocessed,
33733397
bool pref_non_data = false; /* or get from AH->ropt */
33743398
TocEntry *data_te = NULL;
33753399
TocEntry *te;
3376-
int i,j,k;
3400+
int i,k;
33773401

33783402
/*
33793403
* Bogus heuristics for pref_non_data
@@ -3413,8 +3437,8 @@ get_next_work_item(ArchiveHandle *AH, TocEntry **first_unprocessed,
34133437

34143438
/*
34153439
* 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.
34183442
*/
34193443
for (i = 0; i < n_slots && !conflicts; i++)
34203444
{
@@ -3423,16 +3447,12 @@ get_next_work_item(ArchiveHandle *AH, TocEntry **first_unprocessed,
34233447
if (slots[i].args == NULL)
34243448
continue;
34253449
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))
34273453
{
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;
34363456
}
34373457
}
34383458

0 commit comments

Comments
 (0)