77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.40 1999/05/25 16:11:11 momjian Exp $
10+ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.41 1999/06/03 13:33:13 vadim Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -593,6 +593,10 @@ ShmemInitStruct(char *name, unsigned long size, bool *foundPtr)
593593 *
594594 * Strange place for this func, but we have to lookup process data structures
595595 * for all running backends. - vadim 11/26/96
596+ *
597+ * We should keep all PROC structs not in ShmemIndex - this is too
598+ * general hash table...
599+ *
596600 */
597601bool
598602TransactionIdIsInProgress (TransactionId xid )
@@ -648,10 +652,7 @@ GetSnapshotData(bool serializable)
648652
649653snapshot -> xip = (TransactionId * )malloc (have * sizeof (TransactionId ));
650654snapshot -> xmin = cid ;
651- if (serializable )
652- snapshot -> xmax = cid ;
653- else
654- ReadNewTransactionId (& (snapshot -> xmax ));
655+ ReadNewTransactionId (& (snapshot -> xmax ));
655656
656657SpinAcquire (ShmemIndexLock );
657658
@@ -660,8 +661,10 @@ GetSnapshotData(bool serializable)
660661{
661662if (result == (ShmemIndexEnt * ) TRUE)
662663{
663- if (MyProc -> xmin == InvalidTransactionId )
664+ if (serializable )
664665MyProc -> xmin = snapshot -> xmin ;
666+ /* Serializable snapshot must be computed before any other... */
667+ Assert (MyProc -> xmin != InvalidTransactionId );
665668SpinRelease (ShmemIndexLock );
666669snapshot -> xcnt = count ;
667670return snapshot ;
@@ -670,13 +673,24 @@ GetSnapshotData(bool serializable)
670673strncmp (result -> key ,"PID " ,4 )!= 0 )
671674continue ;
672675proc = (PROC * )MAKE_PTR (result -> location );
673- xid = proc -> xid ;/* we don't use spin-locking in xact.c ! */
674- if (proc == MyProc || xid < FirstTransactionId )
676+ /*
677+ * We don't use spin-locking when changing proc->xid
678+ * in GetNewTransactionId() and in AbortTransaction() !..
679+ */
680+ xid = proc -> xid ;
681+ if (proc == MyProc ||
682+ xid < FirstTransactionId || xid >=snapshot -> xmax )
683+ {
684+ /*
685+ * Seems that there is no sense to store xid >= snapshot->xmax
686+ * (what we got from ReadNewTransactionId above) in snapshot->xip
687+ * - we just assume that all xacts with such xid-s are running
688+ * and may be ignored.
689+ */
675690continue ;
691+ }
676692if (xid < snapshot -> xmin )
677693snapshot -> xmin = xid ;
678- else if (xid > snapshot -> xmax )
679- snapshot -> xmax = xid ;
680694if (have == 0 )
681695{
682696snapshot -> xip = (TransactionId * )realloc (snapshot -> xip ,
@@ -712,7 +726,7 @@ GetXmaxRecent(TransactionId *XmaxRecent)
712726
713727Assert (ShmemIndex );
714728
715- ReadNewTransactionId ( XmaxRecent );
729+ * XmaxRecent = GetCurrentTransactionId ( );
716730
717731SpinAcquire (ShmemIndexLock );
718732
@@ -728,7 +742,7 @@ GetXmaxRecent(TransactionId *XmaxRecent)
728742strncmp (result -> key ,"PID " ,4 )!= 0 )
729743continue ;
730744proc = (PROC * )MAKE_PTR (result -> location );
731- xmin = proc -> xmin ;/* we don't use spin-locking inxact.c ! */
745+ xmin = proc -> xmin ;/* we don't use spin-locking inAbortTransaction() ! */
732746if (proc == MyProc || xmin < FirstTransactionId )
733747continue ;
734748if (xmin < * XmaxRecent )