From: Pavan Deolasee Date: Wed, 30 Dec 2015 04:55:56 +0000 (+0530) Subject: Add a flag to the latest snapshot from GTM when situation demands. X-Git-Tag: XL9_5_R1BETA1~120 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=fa21a84a52532edd1340f9732165cfc9e22e1676;p=postgres-xl.git Add a flag to the latest snapshot from GTM when situation demands. Catalog scans for example require the latest snapshot to see the latest changes to the catalogs. This patch fixes the problem with catalog scans --- diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c index d344c68e4c..5c68490a0b 100644 --- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -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); diff --git a/src/backend/storage/lmgr/predicate.c b/src/backend/storage/lmgr/predicate.c index bad5618341..ae34b8803b 100644 --- a/src/backend/storage/lmgr/predicate.c +++ b/src/backend/storage/lmgr/predicate.c @@ -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); diff --git a/src/backend/utils/time/snapmgr.c b/src/backend/utils/time/snapmgr.c index 3667e2f7cc..084e616a61 100644 --- a/src/backend/utils/time/snapmgr.c +++ b/src/backend/utils/time/snapmgr.c @@ -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. diff --git a/src/include/storage/procarray.h b/src/include/storage/procarray.h index 2ddad067fc..f3986693ff 100644 --- a/src/include/storage/procarray.h +++ b/src/include/storage/procarray.h @@ -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);