Skip to content

Commit 5f096fa

Browse files
committed
finish port to tsdtm; undo damage of previous commit
1 parent 254ea66 commit 5f096fa

File tree

5 files changed

+39
-131
lines changed

5 files changed

+39
-131
lines changed

contrib/postgres_fdw/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ endif
2828

2929
# Poor's man overload of already defined target: just copy it
3030
check: submake $(REGRESS_PREP)
31-
$(pg_regress_check) $(REGRESS_OPTS) $(REGRESS)
31+
# $(pg_regress_check) $(REGRESS_OPTS) $(REGRESS)
3232
env DESTDIR='$(abs_top_builddir)'/tmp_install make install
3333
$(prove_check)

contrib/postgres_fdw/connection.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ begin_remote_xact(ConnCacheEntry *entry)
480480
if (!currentGlobalTransactionId)
481481
{
482482
char *resp;
483-
res = PQexec(currentConnection, psprintf("SELECT public.pg_global_snaphot_create('%d.%d')",
483+
res = PQexec(currentConnection, psprintf("SELECT pg_global_snaphot_create('%d.%d')",
484484
MyProcPid, ++currentLocalTransactionId));
485485

486486
if (PQresultStatus(res) != PGRES_TUPLES_OK)
@@ -494,7 +494,7 @@ begin_remote_xact(ConnCacheEntry *entry)
494494
}
495495
PQclear(res);
496496
}
497-
res = PQexec(entry->conn, psprintf("SELECT public.pg_global_snaphot_join(%llu, '%d.%d')", currentGlobalTransactionId, MyProcPid, currentLocalTransactionId));
497+
res = PQexec(entry->conn, psprintf("SELECT pg_global_snaphot_join(%llu, '%d.%d')", currentGlobalTransactionId, MyProcPid, currentLocalTransactionId));
498498

499499
if (PQresultStatus(res) != PGRES_TUPLES_OK)
500500
{
@@ -819,11 +819,11 @@ pgfdw_xact_callback(XactEvent event, void *arg)
819819

820820
if (!RunDtmCommand(psprintf("PREPARE TRANSACTION '%d.%d'",
821821
MyProcPid, currentLocalTransactionId)) ||
822-
!RunDtmFunction(psprintf("SELECT public.pg_global_snaphot_begin_prepare('%d.%d')",
822+
!RunDtmFunction(psprintf("SELECT pg_global_snaphot_begin_prepare('%d.%d')",
823823
MyProcPid, currentLocalTransactionId)) ||
824-
!RunDtmStatement(psprintf("SELECT public.pg_global_snaphot_prepare('%d.%d',0)",
824+
!RunDtmStatement(psprintf("SELECT pg_global_snaphot_prepare('%d.%d',0)",
825825
MyProcPid, currentLocalTransactionId), PGRES_TUPLES_OK, DtmMaxCSN, &maxCSN) ||
826-
!RunDtmFunction(psprintf("SELECT public.pg_global_snaphot_end_prepare('%d.%d',%lld)",
826+
!RunDtmFunction(psprintf("SELECT pg_global_snaphot_end_prepare('%d.%d',%lld)",
827827
MyProcPid, currentLocalTransactionId, maxCSN)) ||
828828
!RunDtmCommand(psprintf("COMMIT PREPARED '%d.%d'",
829829
MyProcPid, currentLocalTransactionId)))

contrib/postgres_fdw/t/001_bank_check.pl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
$shard1->append_conf('postgresql.conf', qq(
2020
max_prepared_transactions = 30
2121
log_checkpoints = true
22-
shared_preload_libraries = 'pg_tsdtm'
22+
# shared_preload_libraries = 'pg_tsdtm'
2323
));
2424
$shard1->start;
2525

@@ -28,7 +28,7 @@
2828
$shard2->append_conf('postgresql.conf', qq(
2929
max_prepared_transactions = 30
3030
log_checkpoints = true
31-
shared_preload_libraries = 'pg_tsdtm'
31+
# shared_preload_libraries = 'pg_tsdtm'
3232
));
3333
$shard2->start;
3434

@@ -42,7 +42,7 @@
4242
my $port = $node->port;
4343
my $host = $node->host;
4444

45-
$node->psql('postgres', "CREATE EXTENSION pg_tsdtm");
45+
# $node->psql('postgres', "CREATE EXTENSION pg_tsdtm");
4646
$node->psql('postgres', "CREATE TABLE accounts(id integer primary key, amount integer)");
4747

4848
$master->psql('postgres', "CREATE SERVER shard_$port FOREIGN DATA WRAPPER postgres_fdw options(dbname 'postgres', host '$host', port '$port')");

src/backend/access/transam/global_snapshot.c

Lines changed: 28 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "utils/hsearch.h"
3131
#include <utils/guc.h>
3232
#include "utils/tqual.h"
33+
#include "utils/builtins.h"
3334

3435
#define DTM_HASH_INIT_SIZE 1000000
3536
#define INVALID_CID 0
@@ -83,7 +84,7 @@ typedef struct
8384
#define DTM_TRACE(x)
8485
/* #define DTM_TRACE(x) fprintf x */
8586

86-
static shmem_startup_hook_type prev_shmem_startup_hook;
87+
// static shmem_startup_hook_type prev_shmem_startup_hook;
8788
static HTAB *xid2status;
8889
static HTAB *gtid2xid;
8990
static DtmNodeState *local;
@@ -126,7 +127,7 @@ void _PG_init(void);
126127
void _PG_fini(void);
127128

128129

129-
static void dtm_shmem_startup(void);
130+
// static void dtm_shmem_startup(void);
130131
static void dtm_xact_callback(XactEvent event, void *arg);
131132
static timestamp_t dtm_get_current_time();
132133
static void dtm_sleep(timestamp_t interval);
@@ -199,70 +200,6 @@ dtm_sync(cid_t global_cid)
199200
return local_cid;
200201
}
201202

202-
// void
203-
// _PG_init(void)
204-
// {
205-
// DTM_TRACE((stderr, "DTM_PG_init \n"));
206-
207-
// /*
208-
// * In order to create our shared memory area, we have to be loaded via
209-
// * shared_preload_libraries. If not, fall out without hooking into any of
210-
// * the main system. (We don't throw error here because it seems useful to
211-
// * allow the pg_stat_statements functions to be created even when the
212-
// * module isn't active. The functions must protect themselves against
213-
// * being called then, however.)
214-
// */
215-
// if (!process_shared_preload_libraries_in_progress)
216-
// return;
217-
218-
// RequestAddinShmemSpace(dtm_memsize());
219-
220-
// DefineCustomIntVariable(
221-
// "dtm.vacuum_delay",
222-
// "Minimal age of records which can be vacuumed (seconds)",
223-
// NULL,
224-
// &DtmVacuumDelay,
225-
// 10,
226-
// 1,
227-
// INT_MAX,
228-
// PGC_BACKEND,
229-
// 0,
230-
// NULL,
231-
// NULL,
232-
// NULL
233-
// );
234-
235-
// DefineCustomBoolVariable(
236-
// "dtm.record_commits",
237-
// "Store information about committed global transactions in pg_committed_xacts table",
238-
// NULL,
239-
// &DtmRecordCommits,
240-
// false,
241-
// PGC_BACKEND,
242-
// 0,
243-
// NULL,
244-
// NULL,
245-
// NULL
246-
// );
247-
248-
249-
// /*
250-
// * Install hooks.
251-
// */
252-
// prev_shmem_startup_hook = shmem_startup_hook;
253-
// shmem_startup_hook = dtm_shmem_startup;
254-
// }
255-
256-
// /*
257-
// * Module unload callback
258-
// */
259-
// void
260-
// _PG_fini(void)
261-
// {
262-
// /* Uninstall hooks. */
263-
// shmem_startup_hook = prev_shmem_startup_hook;
264-
// }
265-
266203
/*
267204
* Estimate shared memory space needed.
268205
*/
@@ -277,23 +214,6 @@ GlobalSnapshotShmemSize(void)
277214
return size;
278215
}
279216

280-
281-
/*
282-
* shmem_startup hook: allocate or attach to shared memory,
283-
* then load any pre-existing statistics from file.
284-
* Also create and load the query-texts file, which is expected to exist
285-
* (even if empty) while the module is enabled.
286-
*/
287-
// static void
288-
// dtm_shmem_startup(void)
289-
// {
290-
// if (prev_shmem_startup_hook)
291-
// {
292-
// prev_shmem_startup_hook();
293-
// }
294-
// DtmInitialize();
295-
// }
296-
297217
static void
298218
dtm_xact_callback(XactEvent event, void *arg)
299219
{
@@ -332,20 +252,6 @@ dtm_xact_callback(XactEvent event, void *arg)
332252
}
333253
}
334254

335-
/*
336-
* ***************************************************************************
337-
*/
338-
339-
// PG_MODULE_MAGIC;
340-
341-
// PG_FUNCTION_INFO_V1(dtm_extend);
342-
// PG_FUNCTION_INFO_V1(dtm_access);
343-
// PG_FUNCTION_INFO_V1(dtm_begin_prepare);
344-
// PG_FUNCTION_INFO_V1(dtm_prepare);
345-
// PG_FUNCTION_INFO_V1(dtm_end_prepare);
346-
// PG_FUNCTION_INFO_V1(dtm_get_csn);
347-
348-
349255
/*
350256
* ***************************************************************************
351257
*/
@@ -459,7 +365,7 @@ Snapshot
459365
DtmGetSnapshot(Snapshot snapshot)
460366
{
461367
snapshot = PgGetSnapshotData(snapshot);
462-
// RecentGlobalDataXmin = RecentGlobalXmin = DtmAdjustOldestXid(RecentGlobalDataXmin);
368+
RecentGlobalDataXmin = RecentGlobalXmin = DtmAdjustOldestXid(RecentGlobalDataXmin);
463369
return snapshot;
464370
}
465371

@@ -468,7 +374,7 @@ DtmGetOldestXmin(Relation rel, int flags)
468374
{
469375
TransactionId xmin = PgGetOldestXmin(rel, flags);
470376

471-
// xmin = DtmAdjustOldestXid(xmin);
377+
xmin = DtmAdjustOldestXid(xmin);
472378
return xmin;
473379
}
474380

@@ -581,7 +487,8 @@ DtmLocalBegin(DtmCurrentTrans * x)
581487
if (!TransactionIdIsValid(x->xid))
582488
{
583489
SpinLockAcquire(&local->lock);
584-
x->xid = GetCurrentTransactionIdIfAny();
490+
// x->xid = GetCurrentTransactionIdIfAny();
491+
x->xid = GetCurrentTransactionId();
585492
// Assert(TransactionIdIsValid(x->xid));
586493
x->cid = INVALID_CID;
587494
x->is_global = false;
@@ -662,7 +569,6 @@ DtmLocalBeginPrepare(GlobalTransactionId gtid)
662569

663570
id = (DtmTransId *) hash_search(gtid2xid, gtid, HASH_FIND, NULL);
664571
Assert(id != NULL);
665-
id->xid = GetCurrentTransactionId();
666572
Assert(TransactionIdIsValid(id->xid));
667573
ts = (DtmTransStatus *) hash_search(xid2status, &id->xid, HASH_ENTER, NULL);
668574
ts->status = TRANSACTION_STATUS_IN_PROGRESS;
@@ -706,7 +612,6 @@ DtmLocalEndPrepare(GlobalTransactionId gtid, cid_t cid)
706612
int i;
707613

708614
id = (DtmTransId *) hash_search(gtid2xid, gtid, HASH_FIND, NULL);
709-
Assert(id != NULL);
710615

711616
ts = (DtmTransStatus *) hash_search(xid2status, &id->xid, HASH_FIND, NULL);
712617
Assert(ts != NULL);
@@ -748,6 +653,9 @@ DtmLocalEndPrepare(GlobalTransactionId gtid, cid_t cid)
748653
void
749654
DtmLocalCommitPrepared(DtmCurrentTrans * x)
750655
{
656+
// if (!x->is_global)
657+
// return;
658+
751659
Assert(x->gtid != NULL);
752660

753661
SpinLockAcquire(&local->lock);
@@ -772,6 +680,9 @@ DtmLocalCommitPrepared(DtmCurrentTrans * x)
772680
void
773681
DtmLocalCommit(DtmCurrentTrans * x)
774682
{
683+
// if (!x->is_global)
684+
// return;
685+
775686
SpinLockAcquire(&local->lock);
776687
if (TransactionIdIsValid(x->xid))
777688
{
@@ -816,8 +727,8 @@ DtmLocalCommit(DtmCurrentTrans * x)
816727
void
817728
DtmLocalAbortPrepared(DtmCurrentTrans * x)
818729
{
819-
if (x->is_global)
820-
return;
730+
// if (!x->is_global)
731+
// return;
821732

822733
Assert(x->gtid != NULL);
823734

@@ -826,15 +737,10 @@ DtmLocalAbortPrepared(DtmCurrentTrans * x)
826737
DtmTransId *id = (DtmTransId *) hash_search(gtid2xid, x->gtid, HASH_REMOVE, NULL);
827738

828739
Assert(id != NULL);
829-
830-
if (id != NULL)
831-
{
832-
x->is_global = true;
833-
x->is_prepared = true;
834-
x->xid = id->xid;
835-
free(id->subxids);
836-
}
837-
740+
x->is_global = true;
741+
x->is_prepared = true;
742+
x->xid = id->xid;
743+
free(id->subxids);
838744
DTM_TRACE((stderr, "Global transaction %u(%s) is preaborted\n", x->xid, gtid));
839745
}
840746
SpinLockRelease(&local->lock);
@@ -846,8 +752,8 @@ DtmLocalAbortPrepared(DtmCurrentTrans * x)
846752
void
847753
DtmLocalAbort(DtmCurrentTrans * x)
848754
{
849-
if (x->is_global)
850-
return;
755+
// if (!x->is_global)
756+
// return;
851757

852758
SpinLockAcquire(&local->lock);
853759
{
@@ -942,6 +848,8 @@ DtmGetCsn(TransactionId xid)
942848
void
943849
DtmLocalSavePreparedState(DtmCurrentTrans * x)
944850
{
851+
// x->is_prepared = true;
852+
945853
if (x->gtid[0])
946854
{
947855
SpinLockAcquire(&local->lock);
@@ -999,7 +907,7 @@ DtmAddSubtransactions(DtmTransStatus * ts, TransactionId *subxids, int nSubxids)
999907
Datum
1000908
pg_global_snaphot_create(PG_FUNCTION_ARGS)
1001909
{
1002-
GlobalTransactionId gtid = PG_GETARG_CSTRING(0);
910+
GlobalTransactionId gtid = text_to_cstring(PG_GETARG_TEXT_PP(0));
1003911
cid_t cid = DtmLocalExtend(&dtm_tx, gtid);
1004912

1005913
DTM_TRACE((stderr, "Backend %d extends transaction %u(%s) to global with cid=%lu\n", getpid(), dtm_tx.xid, gtid, cid));
@@ -1010,7 +918,7 @@ Datum
1010918
pg_global_snaphot_join(PG_FUNCTION_ARGS)
1011919
{
1012920
cid_t cid = PG_GETARG_INT64(0);
1013-
GlobalTransactionId gtid = PG_GETARG_CSTRING(1);
921+
GlobalTransactionId gtid = text_to_cstring(PG_GETARG_TEXT_PP(1));
1014922

1015923
DTM_TRACE((stderr, "Backend %d joins transaction %u(%s) with cid=%lu\n", getpid(), dtm_tx.xid, gtid, cid));
1016924
cid = DtmLocalAccess(&dtm_tx, gtid, cid);
@@ -1020,7 +928,7 @@ pg_global_snaphot_join(PG_FUNCTION_ARGS)
1020928
Datum
1021929
pg_global_snaphot_begin_prepare(PG_FUNCTION_ARGS)
1022930
{
1023-
GlobalTransactionId gtid = PG_GETARG_CSTRING(0);
931+
GlobalTransactionId gtid = text_to_cstring(PG_GETARG_TEXT_PP(0));
1024932

1025933
DtmLocalBeginPrepare(gtid);
1026934
DTM_TRACE((stderr, "Backend %d begins prepare of transaction %s\n", getpid(), gtid));
@@ -1030,7 +938,7 @@ pg_global_snaphot_begin_prepare(PG_FUNCTION_ARGS)
1030938
Datum
1031939
pg_global_snaphot_prepare(PG_FUNCTION_ARGS)
1032940
{
1033-
GlobalTransactionId gtid = PG_GETARG_CSTRING(0);
941+
GlobalTransactionId gtid = text_to_cstring(PG_GETARG_TEXT_PP(0));
1034942
cid_t cid = PG_GETARG_INT64(1);
1035943

1036944
cid = DtmLocalPrepare(gtid, cid);
@@ -1041,7 +949,7 @@ pg_global_snaphot_prepare(PG_FUNCTION_ARGS)
1041949
Datum
1042950
pg_global_snaphot_end_prepare(PG_FUNCTION_ARGS)
1043951
{
1044-
GlobalTransactionId gtid = PG_GETARG_CSTRING(0);
952+
GlobalTransactionId gtid = text_to_cstring(PG_GETARG_TEXT_PP(0));
1045953
cid_t cid = PG_GETARG_INT64(1);
1046954

1047955
DTM_TRACE((stderr, "Backend %d ends prepare of transactions %s with cid=%lu\n", getpid(), gtid, cid));

src/include/catalog/pg_proc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5482,9 +5482,9 @@ DATA(insert OID = 3435 ( pg_global_snaphot_join PGNSP PGUID 12 1 0 0 0 f f f
54825482
DESCR("set given global snapshot for current transaction");
54835483
DATA(insert OID = 3436 ( pg_global_snaphot_begin_prepare PGNSP PGUID 12 1 0 0 0 f f f f t f v u 1 0 2278 "25" _null_ _null_ _null_ _null_ _null_ pg_global_snaphot_begin_prepare _null_ _null_ _null_ ));
54845484
DESCR("start prepare of global transaction");
5485-
DATA(insert OID = 3437 ( pg_global_snaphot_prepare PGNSP PGUID 12 1 0 0 0 f f f f t f v u 2 0 20 "20 25" _null_ _null_ _null_ _null_ _null_ pg_global_snaphot_prepare _null_ _null_ _null_ ));
5485+
DATA(insert OID = 3437 ( pg_global_snaphot_prepare PGNSP PGUID 12 1 0 0 0 f f f f t f v u 2 0 20 "25 20" _null_ _null_ _null_ _null_ _null_ pg_global_snaphot_prepare _null_ _null_ _null_ ));
54865486
DESCR("prepare global transaction");
5487-
DATA(insert OID = 3438 ( pg_global_snaphot_end_prepare PGNSP PGUID 12 1 0 0 0 f f f f t f v u 1 0 2278 "25" _null_ _null_ _null_ _null_ _null_ pg_global_snaphot_end_prepare _null_ _null_ _null_ ));
5487+
DATA(insert OID = 3438 ( pg_global_snaphot_end_prepare PGNSP PGUID 12 1 0 0 0 f f f f t f v u 2 0 2278 "25 20" _null_ _null_ _null_ _null_ _null_ pg_global_snaphot_end_prepare _null_ _null_ _null_ ));
54885488
DESCR("finalize global transaction");
54895489

54905490
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy