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

Commit 2268cd7

Browse files
committed
evict GetLockedGlobalTransactionId()
1 parent 0ccbac7 commit 2268cd7

File tree

4 files changed

+20
-34
lines changed

4 files changed

+20
-34
lines changed

contrib/pg_tsdtm/pg_tsdtm.c

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#define INVALID_CID 0
3737
#define MIN_WAIT_TIMEOUT 1000
3838
#define MAX_WAIT_TIMEOUT 100000
39-
#define MAX_GTID_SIZE 16
4039
#define HASH_PER_ELEM_OVERHEAD 64
4140

4241
#define USEC 1000000
@@ -297,12 +296,6 @@ dtm_shmem_startup(void)
297296
DtmInitialize();
298297
}
299298

300-
static GlobalTransactionId
301-
dtm_get_global_trans_id()
302-
{
303-
return GetLockedGlobalTransactionId();
304-
}
305-
306299
static void
307300
dtm_xact_callback(XactEvent event, void *arg)
308301
{
@@ -324,15 +317,15 @@ dtm_xact_callback(XactEvent event, void *arg)
324317
break;
325318

326319
case XACT_EVENT_ABORT_PREPARED:
327-
DtmLocalAbortPrepared(&dtm_tx, dtm_get_global_trans_id());
320+
DtmLocalAbortPrepared(&dtm_tx);
328321
break;
329322

330323
case XACT_EVENT_COMMIT_PREPARED:
331-
DtmLocalCommitPrepared(&dtm_tx, dtm_get_global_trans_id());
324+
DtmLocalCommitPrepared(&dtm_tx);
332325
break;
333326

334327
case XACT_EVENT_PREPARE:
335-
DtmLocalSavePreparedState(dtm_get_global_trans_id());
328+
DtmLocalSavePreparedState(&dtm_tx);
336329
DtmLocalEnd(&dtm_tx);
337330
break;
338331

@@ -679,6 +672,7 @@ DtmLocalExtend(DtmCurrentTrans * x, GlobalTransactionId gtid)
679672
id->nSubxids = 0;
680673
id->subxids = 0;
681674
}
675+
strncpy(x->gtid, gtid, MAX_GTID_SIZE);
682676
SpinLockRelease(&local->lock);
683677
}
684678
x->is_global = true;
@@ -708,6 +702,7 @@ DtmLocalAccess(DtmCurrentTrans * x, GlobalTransactionId gtid, cid_t global_cid)
708702
x->snapshot = global_cid;
709703
x->is_global = true;
710704
}
705+
strncpy(x->gtid, gtid, MAX_GTID_SIZE);
711706
SpinLockRelease(&local->lock);
712707
if (global_cid < local_cid - DtmVacuumDelay * USEC)
713708
{
@@ -813,13 +808,13 @@ DtmLocalEndPrepare(GlobalTransactionId gtid, cid_t cid)
813808
* Mark tranasction as prepared
814809
*/
815810
void
816-
DtmLocalCommitPrepared(DtmCurrentTrans * x, GlobalTransactionId gtid)
811+
DtmLocalCommitPrepared(DtmCurrentTrans * x)
817812
{
818-
Assert(gtid != NULL);
813+
Assert(x->gtid != NULL);
819814

820815
SpinLockAcquire(&local->lock);
821816
{
822-
DtmTransId *id = (DtmTransId *) hash_search(gtid2xid, gtid, HASH_REMOVE, NULL);
817+
DtmTransId *id = (DtmTransId *) hash_search(gtid2xid, x->gtid, HASH_REMOVE, NULL);
823818

824819
Assert(id != NULL);
825820

@@ -881,13 +876,13 @@ DtmLocalCommit(DtmCurrentTrans * x)
881876
* Mark tranasction as prepared
882877
*/
883878
void
884-
DtmLocalAbortPrepared(DtmCurrentTrans * x, GlobalTransactionId gtid)
879+
DtmLocalAbortPrepared(DtmCurrentTrans * x)
885880
{
886-
Assert(gtid != NULL);
881+
Assert(x->gtid != NULL);
887882

888883
SpinLockAcquire(&local->lock);
889884
{
890-
DtmTransId *id = (DtmTransId *) hash_search(gtid2xid, gtid, HASH_REMOVE, NULL);
885+
DtmTransId *id = (DtmTransId *) hash_search(gtid2xid, x->gtid, HASH_REMOVE, NULL);
891886

892887
Assert(id != NULL);
893888

@@ -998,13 +993,13 @@ DtmGetCsn(TransactionId xid)
998993
* Save state of parepared transaction
999994
*/
1000995
void
1001-
DtmLocalSavePreparedState(GlobalTransactionId gtid)
996+
DtmLocalSavePreparedState(DtmCurrentTrans * x)
1002997
{
1003-
if (gtid != NULL)
998+
if (x->gtid[0])
1004999
{
10051000
SpinLockAcquire(&local->lock);
10061001
{
1007-
DtmTransId *id = (DtmTransId *) hash_search(gtid2xid, gtid, HASH_FIND, NULL);
1002+
DtmTransId *id = (DtmTransId *) hash_search(gtid2xid, x->gtid, HASH_FIND, NULL);
10081003

10091004
if (id != NULL)
10101005
{

contrib/pg_tsdtm/pg_tsdtm.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef DTM_BACKEND_H
22
#define DTM_BACKEND_H
33

4+
#define MAX_GTID_SIZE 16
5+
46
typedef int nodeid_t;
57
typedef uint64 cid_t;
68

@@ -11,6 +13,7 @@ typedef struct
1113
bool is_prepared;
1214
cid_t cid;
1315
cid_t snapshot;
16+
char gtid[MAX_GTID_SIZE];
1417
} DtmCurrentTrans;
1518

1619
typedef char const *GlobalTransactionId;
@@ -37,10 +40,10 @@ cid_t DtmLocalPrepare(GlobalTransactionId gtid, cid_t cid);
3740
void DtmLocalEndPrepare(GlobalTransactionId gtid, cid_t cid);
3841

3942
/* Do local commit of global transaction */
40-
void DtmLocalCommitPrepared(DtmCurrentTrans * x, GlobalTransactionId gtid);
43+
void DtmLocalCommitPrepared(DtmCurrentTrans * x);
4144

4245
/* Do local abort of global transaction */
43-
void DtmLocalAbortPrepared(DtmCurrentTrans * x, GlobalTransactionId gtid);
46+
void DtmLocalAbortPrepared(DtmCurrentTrans * x);
4447

4548
/* Do local commit of global transaction */
4649
void DtmLocalCommit(DtmCurrentTrans * x);
@@ -52,6 +55,6 @@ void DtmLocalAbort(DtmCurrentTrans * x);
5255
void DtmLocalEnd(DtmCurrentTrans * x);
5356

5457
/* Save global preapred transactoin state */
55-
void DtmLocalSavePreparedState(GlobalTransactionId gtid);
58+
void DtmLocalSavePreparedState(DtmCurrentTrans * x);
5659

5760
#endif

src/backend/access/transam/twophase.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,13 +2414,3 @@ PrepareRedoRemove(TransactionId xid, bool giveWarning)
24142414

24152415
return;
24162416
}
2417-
2418-
2419-
/*
2420-
* Return identified of current global transaction
2421-
*/
2422-
const char*
2423-
GetLockedGlobalTransactionId(void)
2424-
{
2425-
return MyLockedGxact ? MyLockedGxact->gid : NULL;
2426-
}

src/include/access/twophase.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,4 @@ extern void PrepareRedoAdd(char *buf, XLogRecPtr start_lsn,
5858
extern void PrepareRedoRemove(TransactionId xid, bool giveWarning);
5959
extern void restoreTwoPhaseData(void);
6060

61-
extern const char *GetLockedGlobalTransactionId(void);
62-
6361
#endif /* TWOPHASE_H */

0 commit comments

Comments
 (0)