8000 Unbreak lock conflict detection for Hot Standby. · danielcode/postgres@8d1fbf9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d1fbf9

Browse files
committed
Unbreak lock conflict detection for Hot Standby.
This got broken in the original fast-path locking patch, because I failed to account for the fact that Hot Standby startup process might take a strong relation lock on a relation in a database to which it is not bound, and confused MyDatabaseId with the database ID of the relation being locked. Report and diagnosis by Andres Freund. Final form of patch by me.
1 parent 71c53d5 commit 8d1fbf9

File tree

1 file changed

+6
-6
lines changed
  • src/backend/storage/lmgr

1 file changed

+6
-6
lines changed

src/backend/storage/lmgr/lock.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,8 +2296,8 @@ FastPathTransferRelationLocks(LockMethod lockMethodTable, const LOCKTAG *locktag
22962296
LWLockAcquire(proc->backendLock, LW_EXCLUSIVE);
22972297

22982298
/*
2299-
* If the target backend isn't referencing the same database as we
2300-
* are, then we needn't examine the individual relation IDs at all;
2299+
* If the target backend isn't referencing the same database as the
2300+
* lock, then we needn't examine the individual relation IDs at all;
23012301
* none of them can be relevant.
23022302
*
23032303
* proc->databaseId is set at backend startup time and never changes
@@ -2310,7 +2310,7 @@ FastPathTransferRelationLocks(LockMethod lockMethodTable, const LOCKTAG *locktag
23102310
* fencing operation since the other backend set proc->databaseId. So
23112311
* for now, we test it after acquiring the LWLock just to be safe.
23122312
*/
2313-
if (proc->databaseId != MyDatabaseId)
2313+
if (proc->databaseId != locktag->locktag_field1)
23142314
{
23152315
LWLockRelease(proc->backendLock);
23162316
continue;
@@ -2528,14 +2528,14 @@ GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode)
25282528
LWLockAcquire(proc->backendLock, LW_SHARED);
25292529

25302530
/*
2531-
* If the target backend isn't referencing the same database as we
2532-
* are, then we needn't examine the individual relation IDs at
2531+
* If the target backend isn't referencing the same database as the
2532+
* lock, then we needn't examine the individual relation IDs at
25332533
* all; none of them can be relevant.
25342534
*
25352535
* See FastPathTransferLocks() for discussion of why we do this
25362536
* test after acquiring the lock.
25372537
*/
2538-
if (proc->databaseId != MyDatabaseId)
2538+
if (proc->databaseId != locktag->locktag_field1)
25392539
{
25402540
LWLockRelease(proc->backendLock);
25412541
continue;

0 commit comments

Comments
 (0)
0