7
7
*
8
8
*
9
9
* 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 $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -593,6 +593,10 @@ ShmemInitStruct(char *name, unsigned long size, bool *foundPtr)
593
593
*
594
594
* Strange place for this func, but we have to lookup process data structures
595
595
* 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
+ *
596
600
*/
597
601
bool
598
602
TransactionIdIsInProgress (TransactionId xid )
@@ -648,10 +652,7 @@ GetSnapshotData(bool serializable)
648
652
649
653
snapshot -> xip = (TransactionId * ) malloc (have * sizeof (TransactionId ));
650
654
snapshot -> xmin = cid ;
651
- if (serializable )
652
- snapshot -> xmax = cid ;
653
- else
654
- ReadNewTransactionId (& (snapshot -> xmax ));
655
+ ReadNewTransactionId (& (snapshot -> xmax ));
655
656
656
657
SpinAcquire (ShmemIndexLock );
657
658
@@ -660,8 +661,10 @@ GetSnapshotData(bool serializable)
660
661
{
661
662
if (result == (ShmemIndexEnt * ) TRUE)
662
663
{
663
- if (MyProc -> xmin == InvalidTransactionId )
664
+ if (serializable )
664
665
MyProc -> xmin = snapshot -> xmin ;
666
+ /* Serializable snapshot must be computed before any other... */
667
+ Assert (MyProc -> xmin != InvalidTransactionId );
665
668
SpinRelease (ShmemIndexLock );
666
669
snapshot -> xcnt = count ;
667
670
return snapshot ;
@@ -670,13 +673,24 @@ GetSnapshotData(bool serializable)
670
673
strncmp (result -> key , "PID " , 4 ) != 0 )
671
674
continue ;
672
675
proc = (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
+ */
675
690
continue ;
691
+ }
676
692
if (xid < snapshot -> xmin )
677
693
snapshot -> xmin = xid ;
678
- else if (xid > snapshot -> xmax )
679
- snapshot -> xmax = xid ;
680
694
if (have == 0 )
681
695
{
682
696
snapshot -> xip = (TransactionId * ) realloc (snapshot -> xip ,
@@ -712,7 +726,7 @@ GetXmaxRecent(TransactionId *XmaxRecent)
712
726
713
727
Assert (ShmemIndex );
714
728
715
- ReadNewTransactionId ( XmaxRecent );
729
+ * XmaxRecent = GetCurrentTransactionId ( );
716
730
717
731
SpinAcquire (ShmemIndexLock );
718
732
@@ -728,7 +742,7 @@ GetXmaxRecent(TransactionId *XmaxRecent)
728
742
strncmp (result -> key , "PID " , 4 ) != 0 )
729
743
continue ;
730
744
proc = (PROC * ) MAKE_PTR (result -> location );
731
- xmin = proc -> xmin ; /* we don't use spin-locking in xact.c ! */
745
+ xmin = proc -> xmin ; /* we don't use spin-locking in AbortTransaction() ! */
732
746
if (proc == MyProc || xmin < FirstTransactionId )
733
747
continue ;
734
748
if (xmin < * XmaxRecent )
0 commit comments