Add a flag to the latest snapshot from GTM when situation demands.
authorPavan Deolasee <[email protected]>
Wed, 30 Dec 2015 04:55:56 +0000 (10:25 +0530)
committerPavan Deolasee <[email protected]>
Wed, 30 Dec 2015 04:55:56 +0000 (10:25 +0530)
Catalog scans for example require the latest snapshot to see the latest changes
to the catalogs. This patch fixes the problem with catalog scans

src/backend/storage/ipc/procarray.c
src/backend/storage/lmgr/predicate.c
src/backend/utils/time/snapmgr.c
src/include/storage/procarray.h

index d344c68e4cd247d3280abf30614fe7ffde4a5abb..5c68490a0b696c1e04b9d251aa14201508bfab6a 100644 (file)
@@ -176,7 +176,7 @@ static void DisplayXidCache(void);
 
 #ifdef PGXC  /* PGXC_DATANODE */
 
-static bool GetPGXCSnapshotData(Snapshot snapshot);
+static bool GetPGXCSnapshotData(Snapshot snapshot, bool latest);
 
 typedef struct
 {
@@ -1495,7 +1495,7 @@ GetMaxSnapshotSubxidCount(void)
  * not statically allocated (see xip allocation below).
  */
 Snapshot
-GetSnapshotData(Snapshot snapshot)
+GetSnapshotData(Snapshot snapshot, bool latest)
 {
        ProcArrayStruct *arrayP = procArray;
        TransactionId xmin;
@@ -1528,7 +1528,7 @@ GetSnapshotData(Snapshot snapshot)
                 * Obtain a global snapshot for a Postgres-XC session
                 * if possible.
                 */
-               if (GetPGXCSnapshotData(snapshot))
+               if (GetPGXCSnapshotData(snapshot, latest))
                        return snapshot;
                /*
                 * We only make one exception for using local snapshot and that's the
@@ -3151,7 +3151,7 @@ UnsetGlobalSnapshotData(void)
  * Entry of snapshot obtention for Postgres-XC node
  */
 static bool
-GetPGXCSnapshotData(Snapshot snapshot)
+GetPGXCSnapshotData(Snapshot snapshot, bool latest)
 {
        /*
         * If this node is in recovery phase,
@@ -3171,7 +3171,8 @@ GetPGXCSnapshotData(Snapshot snapshot)
         */
 
        if ((IsConnFromCoord() || IsConnFromDatanode())
-                       && !IsInitProcessingMode() && !GetForceXidFromGTM())
+                       && !IsInitProcessingMode() && !GetForceXidFromGTM() &&
+                       !latest)
        {
                if (globalSnapshot.snapshot_source == SNAPSHOT_COORDINATOR)
                        GetSnapshotFromGlobalSnapshot(snapshot);
index bad5618341e3995e538edefd17561cf6db33721e..ae34b8803bd6b87c1bc2e60d5447c440ebd38755 100644 (file)
@@ -1695,7 +1695,7 @@ GetSerializableTransactionSnapshotInt(Snapshot snapshot,
 
        /* Get the snapshot, or check that it's safe to use */
        if (!TransactionIdIsValid(sourcexid))
-               snapshot = GetSnapshotData(snapshot);
+               snapshot = GetSnapshotData(snapshot, false);
        else if (!ProcArrayInstallImportedXmin(snapshot->xmin, sourcexid))
        {
                ReleasePredXact(sxact);
index 3667e2f7cc60cef661e64b4ac0dce853e38b7600..084e616a615c1fbce70a603f3b1ca21bf829da12 100644 (file)
@@ -228,7 +228,7 @@ GetTransactionSnapshot(void)
                        if (IsolationIsSerializable())
                                CurrentSnapshot = GetSerializableTransactionSnapshot(&CurrentSnapshotData);
                        else
-                               CurrentSnapshot = GetSnapshotData(&CurrentSnapshotData);
+                               CurrentSnapshot = GetSnapshotData(&CurrentSnapshotData, false);
                        /* Make a saved copy */
                        CurrentSnapshot = CopySnapshot(CurrentSnapshot);
                        FirstXactSnapshot = CurrentSnapshot;
@@ -237,7 +237,7 @@ GetTransactionSnapshot(void)
                        pairingheap_add(&RegisteredSnapshots, &FirstXactSnapshot->ph_node);
                }
                else
-                       CurrentSnapshot = GetSnapshotData(&CurrentSnapshotData);
+                       CurrentSnapshot = GetSnapshotData(&CurrentSnapshotData, false);
 
                /* Don't allow catalog snapshot to be older than xact snapshot. */
                CatalogSnapshotStale = true;
@@ -278,7 +278,7 @@ GetTransactionSnapshot(void)
        /* Don't allow catalog snapshot to be older than xact snapshot. */
        CatalogSnapshotStale = true;
 
-       CurrentSnapshot = GetSnapshotData(&CurrentSnapshotData);
+       CurrentSnapshot = GetSnapshotData(&CurrentSnapshotData, false);
 
        return CurrentSnapshot;
 }
@@ -309,7 +309,7 @@ GetLatestSnapshot(void)
        if (!FirstSnapshotSet)
                return GetTransactionSnapshot();
 
-       SecondarySnapshot = GetSnapshotData(&SecondarySnapshotData);
+       SecondarySnapshot = GetSnapshotData(&SecondarySnapshotData, true);
 
        return SecondarySnapshot;
 }
@@ -358,7 +358,7 @@ GetNonHistoricCatalogSnapshot(Oid relid)
        if (CatalogSnapshotStale)
        {
                /* Get new snapshot. */
-               CatalogSnapshot = GetSnapshotData(&CatalogSnapshotData);
+               CatalogSnapshot = GetSnapshotData(&CatalogSnapshotData, true);
 
                /*
                 * Mark new snapshost as valid.  We must do this last, in case an
@@ -426,7 +426,7 @@ SetTransactionSnapshot(Snapshot sourcesnap, TransactionId sourcexid,
         * two variables in exported snapshot files, but it seems better to have
         * snapshot importers compute reasonably up-to-date values for them.)
         */
-       CurrentSnapshot = GetSnapshotData(&CurrentSnapshotData);
+       CurrentSnapshot = GetSnapshotData(&CurrentSnapshotData, false);
 
        /*
         * Now copy appropriate fields from the source snapshot.
index 2ddad067fcc4bce18439345291ba0521f14b3df4..f3986693ff65e06de2e4bdaceca8f41f8c478b71 100644 (file)
@@ -72,7 +72,7 @@ extern void ExpireOldKnownAssignedTransactionIds(TransactionId xid);
 extern int     GetMaxSnapshotXidCount(void);
 extern int     GetMaxSnapshotSubxidCount(void);
 
-extern Snapshot GetSnapshotData(Snapshot snapshot);
+extern Snapshot GetSnapshotData(Snapshot snapshot, bool latest);
 
 extern bool ProcArrayInstallImportedXmin(TransactionId xmin,
                                                         TransactionId sourcexid);