mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Use Snapshot in heap access methods.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.28 1998/07/21 06:17:35 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.29 1998/07/27 19:38:10 vadim Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -585,7 +585,6 @@ ShmemInitStruct(char *name, unsigned long size, bool *foundPtr)
|
||||
return (structPtr);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* TransactionIdIsInProgress -- is given transaction running by some backend
|
||||
*
|
||||
@@ -625,3 +624,75 @@ TransactionIdIsInProgress(TransactionId xid)
|
||||
elog(ERROR, "TransactionIdIsInProgress: ShmemIndex corrupted");
|
||||
return (false);
|
||||
}
|
||||
|
||||
#ifdef LowLevelLocking
|
||||
/*
|
||||
* GetSnapshotData -- returns information about running transactions.
|
||||
*
|
||||
* InvalidTransactionId is used as terminator in snapshot->xip array.
|
||||
* If serialized is true then XID >= current xact ID will not be
|
||||
* placed in array. Current xact ID are never placed there (just
|
||||
* to reduce its length, xmin/xmax may be equal to cid).
|
||||
* MyProc->xmin will be setted if equal to InvalidTransactionId.
|
||||
*
|
||||
* Yet another strange func for this place... - vadim 07/21/98
|
||||
*/
|
||||
Snapshot
|
||||
GetSnapshotData(bool serialized)
|
||||
{
|
||||
Snapshot snapshot = (Snapshot) malloc(sizeof(SnapshotData));
|
||||
TransactionId snapshot->xip = (TransactionId*)
|
||||
malloc(32 * sizeof(TransactionId));
|
||||
ShmemIndexEnt *result;
|
||||
PROC *proc;
|
||||
TransactionId cid = GetCurrentTransactionId();
|
||||
uint count = 0;
|
||||
unit free = 31;
|
||||
|
||||
Assert(ShmemIndex);
|
||||
|
||||
snapshot->xmax = cid;
|
||||
snapshot->xmin = cid;
|
||||
|
||||
SpinAcquire(ShmemIndexLock);
|
||||
|
||||
hash_seq((HTAB *) NULL);
|
||||
while ((result = (ShmemIndexEnt *) hash_seq(ShmemIndex)) != NULL)
|
||||
{
|
||||
if (result == (ShmemIndexEnt *) TRUE)
|
||||
{
|
||||
if (MyProc->xmin == InvalidTransactionId)
|
||||
MyProc->xmin = snapshot->xmin;
|
||||
SpinRelease(ShmemIndexLock);
|
||||
snapshot->xip[count] = InvalidTransactionId;
|
||||
return (snapshot);
|
||||
}
|
||||
if (result->location == INVALID_OFFSET ||
|
||||
strncmp(result->key, "PID ", 4) != 0)
|
||||
continue;
|
||||
proc = (PROC *) MAKE_PTR(result->location);
|
||||
if (proc == MyProc || proc->xid < FirstTransactionId ||
|
||||
serialized && proc->xid >= cid)
|
||||
continue;
|
||||
if (proc->xid < snapshot->xmin)
|
||||
snapshot->xmin = proc->xid;
|
||||
else if (proc->xid > snapshot->xmax)
|
||||
snapshot->xmax = proc->xid;
|
||||
if (free == 0)
|
||||
{
|
||||
snapshot->xip = (TransactionId*) realloc(snapshot->xip,
|
||||
(count + 33) * sizeof(TransactionId));
|
||||
free = 32;
|
||||
}
|
||||
snapshot->xip[count] = proc->xid;
|
||||
free--;
|
||||
count++;
|
||||
}
|
||||
|
||||
SpinRelease(ShmemIndexLock);
|
||||
free(snapshot->xip);
|
||||
free(snapshot);
|
||||
elog(ERROR, "GetSnapshotData: ShmemIndex corrupted");
|
||||
return (NULL);
|
||||
}
|
||||
#endif
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.31 1998/07/21 04:17:24 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.32 1998/07/27 19:38:11 vadim Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -656,9 +656,13 @@ inv_fetchtup(LargeObjectDesc *obj_desc, Buffer *bufP)
|
||||
* For time travel, we need to use the actual time qual here,
|
||||
* rather that NowTimeQual. We currently have no way to pass
|
||||
* a time qual in.
|
||||
*
|
||||
* This is now valid for snapshot !!!
|
||||
* And should be fixed in some way... - vadim 07/28/98
|
||||
*
|
||||
*/
|
||||
|
||||
htup = heap_fetch(obj_desc->heap_r, false,
|
||||
htup = heap_fetch(obj_desc->heap_r, SnapshotNow,
|
||||
&(res->heap_iptr), bufP);
|
||||
|
||||
} while (htup == (HeapTuple) NULL);
|
||||
@@ -669,7 +673,7 @@ inv_fetchtup(LargeObjectDesc *obj_desc, Buffer *bufP)
|
||||
}
|
||||
else
|
||||
{
|
||||
htup = heap_fetch(obj_desc->heap_r, false,
|
||||
htup = heap_fetch(obj_desc->heap_r, SnapshotNow,
|
||||
&(obj_desc->htid), bufP);
|
||||
}
|
||||
|
||||
@@ -1235,7 +1239,7 @@ _inv_getsize(Relation hreln, TupleDesc hdesc, Relation ireln)
|
||||
if (buf != InvalidBuffer)
|
||||
ReleaseBuffer(buf);
|
||||
|
||||
htup = heap_fetch(hreln, false, &(res->heap_iptr), &buf);
|
||||
htup = heap_fetch(hreln, SnapshotNow, &(res->heap_iptr), &buf);
|
||||
pfree(res);
|
||||
|
||||
} while (!HeapTupleIsValid(htup));
|
||||
|
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.39 1998/06/30 02:33:32 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.40 1998/07/27 19:38:15 vadim Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -46,7 +46,7 @@
|
||||
* This is so that we can support more backends. (system-wide semaphore
|
||||
* sets run out pretty fast.) -ay 4/95
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.39 1998/06/30 02:33:32 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.40 1998/07/27 19:38:15 vadim Exp $
|
||||
*/
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
@@ -252,6 +252,9 @@ InitProcess(IPCKey key)
|
||||
MyProc->pid = MyProcPid;
|
||||
#endif
|
||||
MyProc->xid = InvalidTransactionId;
|
||||
#ifdef LowLevelLocking
|
||||
MyProc->xmin = InvalidTransactionId;
|
||||
#endif
|
||||
|
||||
/* ----------------
|
||||
* Start keeping spin lock stats from here on. Any botch before
|
||||
@@ -479,11 +482,13 @@ ProcSleep(PROC_QUEUE *waitQueue,
|
||||
MyProc->token = token;
|
||||
MyProc->waitLock = lock;
|
||||
|
||||
#ifndef LowLevelLocking
|
||||
/* -------------------
|
||||
* currently, we only need this for the ProcWakeup routines
|
||||
* -------------------
|
||||
*/
|
||||
TransactionIdStore((TransactionId) GetCurrentTransactionId(), &MyProc->xid);
|
||||
#endif
|
||||
|
||||
/* -------------------
|
||||
* assume that these two operations are atomic (because
|
||||
|
Reference in New Issue
Block a user