Skip to content

Commit 2a314ad

Browse files
committed
Whoops, I was a tad too enthusiastic about using shared lock mode for
SInvalLock. GetSnapshotData(true) has to use exclusive lock, since it sets MyProc->xmin.
1 parent 6fdf7be commit 2a314ad

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/backend/storage/ipc/sinval.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.41 2001/09/29 04:02:24 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.42 2001/09/29 15:29:48 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -310,19 +310,24 @@ GetSnapshotData(bool serializable)
310310
if (snapshot == NULL)
311311
elog(ERROR, "Memory exhausted in GetSnapshotData");
312312

313-
snapshot->xmin = GetCurrentTransactionId();
314-
315-
LWLockAcquire(SInvalLock, LW_SHARED);
316-
317313
/*
318-
* There can be no more than lastBackend active transactions, so this
319-
* is enough space:
314+
* Allocating space for MaxBackends xids is usually overkill;
315+
* lastBackend would be sufficient. But it seems better to do the
316+
* malloc while not holding the lock, so we can't look at lastBackend.
320317
*/
321318
snapshot->xip = (TransactionId *)
322-
malloc(segP->lastBackend * sizeof(TransactionId));
319+
malloc(MaxBackends * sizeof(TransactionId));
323320
if (snapshot->xip == NULL)
324321
elog(ERROR, "Memory exhausted in GetSnapshotData");
325322

323+
snapshot->xmin = GetCurrentTransactionId();
324+
325+
/*
326+
* If we are going to set MyProc->xmin then we'd better get exclusive
327+
* lock; if not, this is a read-only operation so it can be shared.
328+
*/
329+
LWLockAcquire(SInvalLock, serializable ? LW_EXCLUSIVE : LW_SHARED);
330+
326331
/*--------------------
327332
* Unfortunately, we have to call ReadNewTransactionId() after acquiring
328333
* SInvalLock above. It's not good because ReadNewTransactionId() does

0 commit comments

Comments
 (0)