diff options
| -rw-r--r-- | src/backend/storage/ipc/procarray.c | 53 | ||||
| -rw-r--r-- | src/backend/utils/misc/guc.c | 29 | ||||
| -rw-r--r-- | src/include/storage/procarray.h | 9 |
3 files changed, 71 insertions, 20 deletions
diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c index 1407bfc07d..d344c68e4c 100644 --- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -79,6 +79,7 @@ #include "pgxc/pgxc.h" #include "access/gtm.h" #include "storage/ipc.h" +#include "utils/guc.h" /* PGXC_DATANODE */ #include "postmaster/autovacuum.h" #endif @@ -219,6 +220,10 @@ static TransactionId KnownAssignedXidsGetOldestXmin(void); static void KnownAssignedXidsDisplay(int trace_level); static void KnownAssignedXidsReset(void); +#ifdef XCP +int GlobalSnapshotSource; +#endif + /* * Report shared-memory space needed by CreateSharedProcArray. */ @@ -1508,22 +1513,35 @@ GetSnapshotData(Snapshot snapshot) #ifdef PGXC /* PGXC_DATANODE */ /* - * Obtain a global snapshot for a Postgres-XC session - * if possible. - */ - if (GetPGXCSnapshotData(snapshot)) - return snapshot; - /* - * We only make one exception for using local snapshot and that's the - * initdb time. When IsPostmasterEnvironment is true, snapshots must either - * be pushed down from the coordinator or directly obtained from the - * GTM. - * - * !!TODO We don't seem to fully support Hot Standby. So why should we even - * exempt RecoveryInProgress()? - */ - if (IsPostmasterEnvironment && !useLocalXid) - elog(ERROR, "Was unable to obtain a snapshot from GTM."); + * If the user has chosen to work with a coordinator-local snapshot, just + * compute snapshot locally. This can have adverse effects on the global + * consistency, in a multi-coordinator environment, but also in a + * single-coordinator setup because our recent changes to transaction + * management now allows datanodes to start global snapshots or more + * precisely attach current transaction to a global transaction. But users + * may still want to use this model for performance of their XL cluster, at + * the cost of reduced global consistency + */ + if (GlobalSnapshotSource == GLOBAL_SNAPSHOT_SOURCE_GTM) + { + /* + * Obtain a global snapshot for a Postgres-XC session + * if possible. + */ + if (GetPGXCSnapshotData(snapshot)) + return snapshot; + /* + * We only make one exception for using local snapshot and that's the + * initdb time. When IsPostmasterEnvironment is true, snapshots must + * either be pushed down from the coordinator or directly obtained from + * the GTM. + * + * !!TODO We don't seem to fully support Hot Standby. So why should we + * even exempt RecoveryInProgress()? + */ + if (IsPostmasterEnvironment && !useLocalXid) + elog(ERROR, "Was unable to obtain a snapshot from GTM."); + } #endif /* @@ -3254,8 +3272,6 @@ GetSnapshotFromGlobalSnapshot(Snapshot snapshot) globalSnapshot.snapshot_source == SNAPSHOT_DIRECT) && TransactionIdIsValid(globalSnapshot.gxmin)) { - int index; - ProcArrayStruct *arrayP = procArray; TransactionId global_xmin; snapshot->xmin = globalSnapshot.gxmin; @@ -4360,7 +4376,6 @@ ProcArrayCheckXminConsistency(TransactionId global_xmin) for (index = 0; index < arrayP->numProcs; index++) { int pgprocno = arrayP->pgprocnos[index]; - volatile PGPROC *proc = &allProcs[pgprocno]; volatile PGXACT *pgxact = &allPgXact[pgprocno]; TransactionId xid; diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index ae251089cc..bf80a0ed60 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -71,13 +71,14 @@ #include "pgxc/poolmgr.h" #include "pgxc/nodemgr.h" #include "pgxc/xc_maintenance_mode.h" +#include "storage/procarray.h" #endif #ifdef XCP #include "commands/sequence.h" +#include "parser/parse_utilcmd.h" #include "pgxc/nodemgr.h" #include "pgxc/squeue.h" #include "utils/snapmgr.h" -#include "parser/parse_utilcmd.h" #endif #include "postmaster/autovacuum.h" #include "postmaster/bgworker.h" @@ -445,6 +446,18 @@ static const struct config_enum_entry row_security_options[] = { {NULL, 0, false} }; +#ifdef XCP +/* + * Set global-snapshot source. 'gtm' is default, but user can choose + * 'coordinator' for performance improvement at the cost of reduced consistency + */ +static const struct config_enum_entry global_snapshot_source_options[] = { + {"gtm", GLOBAL_SNAPSHOT_SOURCE_GTM, true}, + {"coordinator", GLOBAL_SNAPSHOT_SOURCE_COORDINATOR, true}, + {NULL, 0, false} +}; +#endif + /* * Options for enum values stored in other modules */ @@ -4051,6 +4064,20 @@ static struct config_enum ConfigureNamesEnum[] = NULL, NULL, NULL }, +#ifdef XCP + { + {"global_snapshot_source", PGC_USERSET, DEVELOPER_OPTIONS, + gettext_noop("Set preferred source of a snapshot."), + gettext_noop("When set to 'coordinator', a snapshot is taken at " + "the coordinator at the risk of reduced consistency. " + "Default is 'gtm'") + }, + &GlobalSnapshotSource, + GLOBAL_SNAPSHOT_SOURCE_GTM, global_snapshot_source_options, + NULL, NULL, NULL + }, +#endif + /* End-of-list marker */ { {NULL, 0, 0, NULL, NULL}, NULL, 0, NULL, NULL, NULL, NULL diff --git a/src/include/storage/procarray.h b/src/include/storage/procarray.h index f17fc22e65..2ddad067fc 100644 --- a/src/include/storage/procarray.h +++ b/src/include/storage/procarray.h @@ -24,6 +24,15 @@ #include "utils/relcache.h" #include "utils/snapshot.h" +#ifdef XCP +extern int GlobalSnapshotSource; + +typedef enum GlobalSnapshotSourceType +{ + GLOBAL_SNAPSHOT_SOURCE_GTM, + GLOBAL_SNAPSHOT_SOURCE_COORDINATOR +} GlobalSnapshotSourceType; +#endif extern Size ProcArrayShmemSize(void); extern void CreateSharedProcArray(void); |
