Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 401949d

Browse files
committed
Add GUC enabling global snapshots.
(cherry picked from commit 6160f0346d39b6d831395f3ee3b5e59da69145f6)
1 parent 5d68c84 commit 401949d

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

src/backend/access/transam/global_snapshot.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ typedef struct
8484
#define DTM_TRACE(x)
8585
/* #define DTM_TRACE(x) fprintf x */
8686

87+
/* GUC enabling global snapshots */
88+
bool track_global_snapshots;
89+
8790
// static shmem_startup_hook_type prev_shmem_startup_hook;
8891
static HTAB *xid2status;
8992
static HTAB *gtid2xid;
@@ -1019,8 +1022,12 @@ Datum
10191022
pg_global_snaphot_create(PG_FUNCTION_ARGS)
10201023
{
10211024
GlobalTransactionId gtid = text_to_cstring(PG_GETARG_TEXT_PP(0));
1022-
cid_t cid = DtmLocalExtend(&dtm_tx, gtid);
1025+
cid_t cid;
1026+
1027+
if (!track_global_snapshots)
1028+
elog(ERROR, "Global snapshots are disabled");
10231029

1030+
cid = DtmLocalExtend(&dtm_tx, gtid);
10241031
DTM_TRACE((stderr, "Backend %d extends transaction %u(%s) to global with cid=%lu\n", getpid(), dtm_tx.xid, gtid, cid));
10251032
PG_RETURN_INT64(cid);
10261033
}
@@ -1031,6 +1038,9 @@ pg_global_snaphot_join(PG_FUNCTION_ARGS)
10311038
cid_t cid = PG_GETARG_INT64(0);
10321039
GlobalTransactionId gtid = text_to_cstring(PG_GETARG_TEXT_PP(1));
10331040

1041+
if (!track_global_snapshots)
1042+
elog(ERROR, "Global snapshots are disabled");
1043+
10341044
DTM_TRACE((stderr, "Backend %d joins transaction %u(%s) with cid=%lu\n", getpid(), dtm_tx.xid, gtid, cid));
10351045
cid = DtmLocalAccess(&dtm_tx, gtid, cid);
10361046
PG_RETURN_INT64(cid);
@@ -1041,6 +1051,9 @@ pg_global_snaphot_begin_prepare(PG_FUNCTION_ARGS)
10411051
{
10421052
GlobalTransactionId gtid = text_to_cstring(PG_GETARG_TEXT_PP(0));
10431053

1054+
if (!track_global_snapshots)
1055+
elog(ERROR, "Global snapshots are disabled");
1056+
10441057
DtmLocalBeginPrepare(gtid);
10451058
DTM_TRACE((stderr, "Backend %d begins prepare of transaction %s\n", getpid(), gtid));
10461059
PG_RETURN_VOID();
@@ -1052,6 +1065,10 @@ pg_global_snaphot_prepare(PG_FUNCTION_ARGS)
10521065
GlobalTransactionId gtid = text_to_cstring(PG_GETARG_TEXT_PP(0));
10531066
cid_t cid = PG_GETARG_INT64(1);
10541067

1068+
if (!track_global_snapshots)
1069+
elog(ERROR, "Global snapshots are disabled");
1070+
1071+
10551072
cid = DtmLocalPrepare(gtid, cid);
10561073
DTM_TRACE((stderr, "Backend %d prepares transaction %s with cid=%lu\n", getpid(), gtid, cid));
10571074
PG_RETURN_INT64(cid);
@@ -1063,6 +1080,9 @@ pg_global_snaphot_end_prepare(PG_FUNCTION_ARGS)
10631080
GlobalTransactionId gtid = text_to_cstring(PG_GETARG_TEXT_PP(0));
10641081
cid_t cid = PG_GETARG_INT64(1);
10651082

1083+
if (!track_global_snapshots)
1084+
elog(ERROR, "Global snapshots are disabled");
1085+
10661086
DTM_TRACE((stderr, "Backend %d ends prepare of transactions %s with cid=%lu\n", getpid(), gtid, cid));
10671087
DtmLocalEndPrepare(gtid, cid);
10681088
PG_RETURN_VOID();

src/backend/storage/ipc/ipci.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "access/clog.h"
1818
#include "access/commit_ts.h"
1919
#include "access/heapam.h"
20+
#include "access/global_snapshot.h"
2021
#include "access/multixact.h"
2122
#include "access/nbtree.h"
2223
#include "access/subtrans.h"
@@ -286,6 +287,9 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port)
286287
WaitLSNShmemInit();
287288
DtmInitialize();
288289

290+
if (track_global_snapshots)
291+
DtmInitialize();
292+
289293
#ifdef EXEC_BACKEND
290294

291295
/*

src/backend/utils/misc/guc.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "access/commit_ts.h"
3030
#include "access/gin.h"
31+
#include "access/global_snapshot.h"
3132
#include "access/rmgr.h"
3233
#include "access/transam.h"
3334
#include "access/twophase.h"
@@ -1708,15 +1709,25 @@ static struct config_bool ConfigureNamesBool[] =
17081709
NULL, NULL, NULL
17091710
},
17101711

1712+
{
1713+
{"track_global_snapshots", PGC_POSTMASTER, CUSTOM_OPTIONS,
1714+
gettext_noop("Track global snapshots, allowing to use global_snapshot API"),
1715+
NULL
1716+
},
1717+
&track_global_snapshots,
1718+
false,
1719+
NULL, NULL, NULL
1720+
},
1721+
17111722
{
17121723
{"cfs_encryption", PGC_POSTMASTER, UNGROUPED,
17131724
gettext_noop("Encrypt CFS pages"),
17141725
NULL,
1715-
},
1726+
},
17161727
&cfs_encryption,
1717-
false,
1718-
NULL, NULL, NULL
1719-
},
1728+
false,
1729+
NULL, NULL, NULL
1730+
},
17201731

17211732
{
17221733
{"cfs_gc", PGC_SIGHUP, UNGROUPED,

src/include/access/global_snapshot.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
typedef int nodeid_t;
77
typedef uint64 cid_t;
88

9+
extern bool track_global_snapshots;
10+
911
typedef struct
1012
{
1113
TransactionId xid;

0 commit comments

Comments
 (0)