Skip to content

Commit 256f931

Browse files
committed
Fix cbuild problems with XTM
1 parent 9d0cc59 commit 256f931

File tree

8 files changed

+60
-69
lines changed

8 files changed

+60
-69
lines changed

contrib/pg_xtm/libdtm.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void DtmDisconnect(DTMConn dtm) {
121121

122122
// Asks DTM for a fresh snapshot. Returns a snapshot on success, or NULL
123123
// otherwise. Please free the snapshot memory yourself after use.
124-
Snapshot DtmGlobalGetSnapshot(DTMConn dtm) {
124+
Snapshot DtmGlobalGetSnapshot(DTMConn dtm, TransactionId xid, Snapshot s) {
125125
bool ok;
126126
int i;
127127
xid_t number;
@@ -137,10 +137,6 @@ Snapshot DtmGlobalGetSnapshot(DTMConn dtm) {
137137
return NULL;
138138
}
139139

140-
// FIXME: We should not expose the postgres Snapshot here, should we?
141-
// Can we use a custom structure?
142-
Snapshot s = palloc(sizeof(SnapshotData));
143-
144140
if (!dtm_read_hex16(dtm, &number)) {
145141
goto cleanup_snapshot;
146142
}
@@ -239,7 +235,7 @@ void DtmGlobalRollback(DTMConn dtm, xid_t gxid) {
239235

240236
// Gets the status of the transaction identified by 'gxid'. Returns the status
241237
// on success, or -1 otherwise.
242-
int DtmGlobalGetTransStatus(DTMConn dtm, xid_t gxid) {
238+
XidStatus DtmGlobalGetTransStatus(DTMConn dtm, TransactionId gxid) {
243239
bool result;
244240
char statuschar;
245241

contrib/pg_xtm/libdtm.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
#define LIBDTM_H
33

44
#include "postgres.h"
5-
#include "utils/snapshot.h"
5+
#include "utils/snapmgr.h"
6+
#include "access/clog.h"
67

78
#define INVALID_GXID 0
89
#define COMMIT_UNKNOWN 0
@@ -22,14 +23,14 @@ void DtmDisconnect(DTMConn dtm);
2223

2324

2425
typedef struct {
25-
TransasactionId* xids;
26+
TransactionId* xids;
2627
int nXids;
2728
} GlobalTransactionId;
2829

2930
/* create entry for new global transaction */
30-
void DtmGlobalStartTransaction(DTMConn dtm, TransactionId* gitd);
31+
void DtmGlobalStartTransaction(DTMConn dtm, GlobalTransactionId* gitd);
3132

32-
void DtmGlobalGetSnapshot(DTMConn dtm, TransactionId xid, Snapshot snapshot);
33+
Snapshot DtmGlobalGetSnapshot(DTMConn dtm, TransactionId xid, Snapshot snapshot);
3334

3435
void DtmGlobalSetTransStatus(DTMConn dtm, TransactionId xid, XidStatus status); /* commit transaction only once all participants are committed, before it do not change CLOG */
3536

contrib/pg_xtm/pg_dtm.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@
1919
#include "storage/ipc.h"
2020
#include "access/xlogdefs.h"
2121
#include "access/xact.h"
22+
#include "access/xtm.h"
2223
#include "access/transam.h"
2324
#include "access/xlog.h"
25+
#include "storage/procarray.h"
2426
#include "access/twophase.h"
2527
#include "utils/hsearch.h"
2628
#include "utils/tqual.h"
29+
#include "utils/array.h"
30+
#include "utils/builtins.h"
2731

2832
#include "libdtm.h"
29-
#include "pg_dtm.h"
3033

3134
void _PG_init(void);
3235
void _PG_fini(void);
@@ -66,7 +69,7 @@ static XidStatus DtmGetTransactionStatus(TransactionId xid, XLogRecPtr *lsn)
6669
if (status == TRANSACTION_STATUS_IN_PROGRESS) {
6770
DtmEnsureConnection();
6871
status = DtmGlobalGetTransStatus(DtmConn, xid);
69-
CLOGTransactionIdSetTreeStatus(xid, 0, NULL, status, NULL);
72+
CLOGTransactionIdSetTreeStatus(xid, 0, NULL, status, InvalidXLogRecPtr);
7073
}
7174
return status;
7275
}
@@ -76,7 +79,7 @@ static void DtmSetTransactionStatus(TransactionId xid, int nsubxids, Transaction
7679
{
7780
DtmEnsureConnection();
7881
CLOGTransactionIdSetTreeStatus(xid, nsubxids, subxids, TRANSACTION_STATUS_IN_PROGRESS, lsn);
79-
DtmHasSnapshpt = false;
82+
DtmHasSnapshot = false;
8083
return DtmGlobalSetTransStatus(DtmConn, xid, status);
8184
}
8285

@@ -112,6 +115,9 @@ Datum
112115
dtm_global_transaction(PG_FUNCTION_ARGS)
113116
{
114117
GlobalTransactionId gtid;
118+
ArrayType* a = PG_GETARG_ARRAYTYPE_P(0);
119+
gtid.xids = (TransactionId*)ARR_DATA_PTR(a);
120+
gtid.nXids = ArrayGetNItems( ARR_NDIM(a), ARR_DIMS(a));
115121
DtmEnsureConnection();
116122
DtmGlobalStartTransaction(DtmConn, &gtid);
117123
PG_RETURN_VOID();
@@ -120,7 +126,7 @@ dtm_global_transaction(PG_FUNCTION_ARGS)
120126
Datum
121127
dtm_get_snapshot(PG_FUNCTION_ARGS)
122128
{
123-
TransationIn xmin;
129+
TransactionId xmin;
124130
DtmEnsureConnection();
125131
DtmGlobalGetSnapshot(DtmConn, GetCurrentTransactionId(), &DtmSnapshot);
126132
/* Move it to DtmGlobalGetSnapshot? */
@@ -138,7 +144,7 @@ dtm_get_snapshot(PG_FUNCTION_ARGS)
138144
}
139145
RecentXmin = xmin;
140146
}
141-
snapshot->curcid = GetCurrentCommandId(false);
147+
DtmSnapshot.curcid = GetCurrentCommandId(false);
142148
DtmHasSnapshot = true;
143149
PG_RETURN_VOID();
144150
}

src/backend/access/transam/clog.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#include "miscadmin.h"
4444
#include "pg_trace.h"
4545

46-
TransactionManager DefaultTM = { CLOGTransactionIdSetTreeStatus, CLOGTransactionIdGetStatus, GetLocalSnapshotData };
46+
TransactionManager DefaultTM = { CLOGTransactionIdGetStatus, CLOGTransactionIdSetTreeStatus, GetLocalSnapshotData };
4747
TransactionManager* TM = &DefaultTM;
4848

4949
/*
@@ -402,7 +402,7 @@ TransactionIdSetStatusBit(TransactionId xid, XidStatus status, XLogRecPtr lsn, i
402402
XidStatus
403403
TransactionIdGetStatus(TransactionId xid, XLogRecPtr *lsn)
404404
{
405-
TM->GetTransactionStatus(xid, lsn);
405+
return TM->GetTransactionStatus(xid, lsn);
406406
}
407407

408408
XidStatus

src/backend/storage/ipc/procarray.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,8 @@ TransactionIdIsInProgress(TransactionId xid)
984984

985985
if (VisibilityCallback)
986986
{
987-
VisibilityCheckResult result = (*VisibilityCallback)(xid);
987+
/* Just wait for in-doubt transactions */
988+
(*VisibilityCallback)(xid);
988989
/*
989990
if (result != XID_IN_DOUBT)
990991
{

src/backend/utils/time/tqual.c

Lines changed: 33 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -949,8 +949,8 @@ HeapTupleSatisfiesDirty(HeapTuple htup, Snapshot snapshot,
949949
* basis of the true state of the transaction, even if we then pretend we
950950
* can't see it.)
951951
*/
952-
int
953-
HeapTupleSatisfiesMVCC_Impl(HeapTuple htup, Snapshot snapshot,
952+
bool
953+
HeapTupleSatisfiesMVCC(HeapTuple htup, Snapshot snapshot,
954954
Buffer buffer)
955955
{
956956
HeapTupleHeader tuple = htup->t_data;
@@ -961,22 +961,22 @@ HeapTupleSatisfiesMVCC_Impl(HeapTuple htup, Snapshot snapshot,
961961
if (!HeapTupleHeaderXminCommitted(tuple))
962962
{
963963
if (HeapTupleHeaderXminInvalid(tuple))
964-
return 1;
964+
return false;
965965

966966
/* Used by pre-9.0 binary upgrades */
967967
if (tuple->t_infomask & HEAP_MOVED_OFF)
968968
{
969969
TransactionId xvac = HeapTupleHeaderGetXvac(tuple);
970970

971971
if (TransactionIdIsCurrentTransactionId(xvac))
972-
return 2;
972+
return false;
973973
if (!TransactionIdIsInProgress(xvac))
974974
{
975975
if (TransactionIdDidCommit(xvac))
976976
{
977977
SetHintBits(tuple, buffer, HEAP_XMIN_INVALID,
978978
InvalidTransactionId);
979-
return 3;
979+
return false;
980980
}
981981
SetHintBits(tuple, buffer, HEAP_XMIN_COMMITTED,
982982
InvalidTransactionId);
@@ -990,28 +990,28 @@ HeapTupleSatisfiesMVCC_Impl(HeapTuple htup, Snapshot snapshot,
990990
if (!TransactionIdIsCurrentTransactionId(xvac))
991991
{
992992
if (TransactionIdIsInProgress(xvac))
993-
return 4;
993+
return false;
994994
if (TransactionIdDidCommit(xvac))
995995
SetHintBits(tuple, buffer, HEAP_XMIN_COMMITTED,
996996
InvalidTransactionId);
997997
else
998998
{
999999
SetHintBits(tuple, buffer, HEAP_XMIN_INVALID,
10001000
InvalidTransactionId);
1001-
return 5;
1001+
return false;
10021002
}
10031003
}
10041004
}
10051005
else if (TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmin(tuple)))
10061006
{
10071007
if (HeapTupleHeaderGetCmin(tuple) >= snapshot->curcid)
1008-
return 6; /* inserted after scan started */
1008+
return false; /* inserted after scan started */
10091009

10101010
if (tuple->t_infomask & HEAP_XMAX_INVALID) /* xid invalid */
1011-
return 0;
1011+
return true;
10121012

10131013
if (HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_infomask)) /* not deleter */
1014-
return 0;
1014+
return true;
10151015

10161016
if (tuple->t_infomask & HEAP_XMAX_IS_MULTI)
10171017
{
@@ -1024,28 +1024,28 @@ HeapTupleSatisfiesMVCC_Impl(HeapTuple htup, Snapshot snapshot,
10241024

10251025
/* updating subtransaction must have aborted */
10261026
if (!TransactionIdIsCurrentTransactionId(xmax))
1027-
return 0;
1027+
return true;
10281028
else if (HeapTupleHeaderGetCmax(tuple) >= snapshot->curcid)
1029-
return 0; /* updated after scan started */
1029+
return true; /* updated after scan started */
10301030
else
1031-
return 7; /* updated before scan started */
1031+
return false; /* updated before scan started */
10321032
}
10331033

10341034
if (!TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmax(tuple)))
10351035
{
10361036
/* deleting subtransaction must have aborted */
10371037
SetHintBits(tuple, buffer, HEAP_XMAX_INVALID,
10381038
InvalidTransactionId);
1039-
return 0;
1039+
return true;
10401040
}
10411041

10421042
if (HeapTupleHeaderGetCmax(tuple) >= snapshot->curcid)
1043-
return 0; /* deleted after scan started */
1043+
return true; /* deleted after scan started */
10441044
else
1045-
return 9; /* deleted before scan started */
1045+
return false; /* deleted before scan started */
10461046
}
10471047
else if (TransactionIdIsInProgress(HeapTupleHeaderGetRawXmin(tuple)))
1048-
return 10;
1048+
return false;
10491049
else if (TransactionIdDidCommit(HeapTupleHeaderGetRawXmin(tuple)))
10501050
SetHintBits(tuple, buffer, HEAP_XMIN_COMMITTED,
10511051
HeapTupleHeaderGetRawXmin(tuple));
@@ -1054,7 +1054,7 @@ HeapTupleSatisfiesMVCC_Impl(HeapTuple htup, Snapshot snapshot,
10541054
/* it must have aborted or crashed */
10551055
SetHintBits(tuple, buffer, HEAP_XMIN_INVALID,
10561056
InvalidTransactionId);
1057-
return 11;
1057+
return false;
10581058
}
10591059
}
10601060

@@ -1064,13 +1064,13 @@ HeapTupleSatisfiesMVCC_Impl(HeapTuple htup, Snapshot snapshot,
10641064
*/
10651065
if (!HeapTupleHeaderXminFrozen(tuple)
10661066
&& XidInMVCCSnapshot(HeapTupleHeaderGetRawXmin(tuple), snapshot))
1067-
return 12; /* treat as still in progress */
1067+
return false; /* treat as still in progress */
10681068

10691069
if (tuple->t_infomask & HEAP_XMAX_INVALID) /* xid invalid or aborted */
1070-
return 0;
1070+
return true;
10711071

10721072
if (HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_infomask))
1073-
return 0;
1073+
return true;
10741074

10751075
if (tuple->t_infomask & HEAP_XMAX_IS_MULTI)
10761076
{
@@ -1087,42 +1087,42 @@ HeapTupleSatisfiesMVCC_Impl(HeapTuple htup, Snapshot snapshot,
10871087
if (TransactionIdIsCurrentTransactionId(xmax))
10881088
{
10891089
if (HeapTupleHeaderGetCmax(tuple) >= snapshot->curcid)
1090-
return 0; /* deleted after scan started */
1090+
return true; /* deleted after scan started */
10911091
else
1092-
return 13; /* deleted before scan started */
1092+
return false; /* deleted before scan started */
10931093
}
10941094
if (TransactionIdIsInProgress(xmax))
1095-
return 0;
1095+
return true;
10961096
if (TransactionIdDidCommit(xmax))
10971097
{
10981098
/* updating transaction committed, but when? */
10991099
if (XidInMVCCSnapshot(xmax, snapshot))
1100-
return 0; /* treat as still in progress */
1101-
return 14;
1100+
return true; /* treat as still in progress */
1101+
return false;
11021102
}
11031103
/* it must have aborted or crashed */
1104-
return 0;
1104+
return true;
11051105
}
11061106

11071107
if (!(tuple->t_infomask & HEAP_XMAX_COMMITTED))
11081108
{
11091109
if (TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmax(tuple)))
11101110
{
11111111
if (HeapTupleHeaderGetCmax(tuple) >= snapshot->curcid)
1112-
return 0; /* deleted after scan started */
1112+
return true; /* deleted after scan started */
11131113
else
1114-
return 15; /* deleted before scan started */
1114+
return false; /* deleted before scan started */
11151115
}
11161116

11171117
if (TransactionIdIsInProgress(HeapTupleHeaderGetRawXmax(tuple)))
1118-
return 0;
1118+
return true;
11191119

11201120
if (!TransactionIdDidCommit(HeapTupleHeaderGetRawXmax(tuple)))
11211121
{
11221122
/* it must have aborted or crashed */
11231123
SetHintBits(tuple, buffer, HEAP_XMAX_INVALID,
11241124
InvalidTransactionId);
1125-
return 0;
1125+
return true;
11261126
}
11271127

11281128
/* xmax transaction committed */
@@ -1134,25 +1134,9 @@ HeapTupleSatisfiesMVCC_Impl(HeapTuple htup, Snapshot snapshot,
11341134
* OK, the deleting transaction committed too ... but when?
11351135
*/
11361136
if (XidInMVCCSnapshot(HeapTupleHeaderGetRawXmax(tuple), snapshot))
1137-
return 0; /* treat as still in progress */
1138-
1139-
return 16;
1140-
}
1137+
return true; /* treat as still in progress */
11411138

1142-
bool
1143-
HeapTupleSatisfiesMVCC(HeapTuple htup, Snapshot snapshot,
1144-
Buffer buffer)
1145-
{
1146-
HeapTupleHeader tuple = htup->t_data;
1147-
int result = HeapTupleSatisfiesMVCC_Impl(htup, snapshot, buffer);
1148-
if (result != 0) {
1149-
elog(WARNING, "Backed %d: tuple [%u,%u] is not visible in snapshot [%u..%u] because of %d, RecentXmin=%u, RecentGlobalXmin=%u\n", getpid(),
1150-
HeapTupleHeaderGetRawXmin(tuple), HeapTupleHeaderGetRawXmax(tuple),
1151-
snapshot->xmin, snapshot->xmax,
1152-
result, RecentXmin, RecentGlobalXmin);
1153-
return false;
1154-
}
1155-
return true;
1139+
return false;
11561140
}
11571141

11581142
/*

src/include/access/twophase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ extern void CheckPointTwoPhase(XLogRecPtr redo_horizon);
5656

5757
extern void FinishPreparedTransaction(const char *gid, bool isCommit);
5858

59-
extern const char* GetLockedGlobalTransactionId();
59+
extern const char* GetLockedGlobalTransactionId(void);
6060

6161
#endif /* TWOPHASE_H */

src/include/access/xtm.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
#ifndef XTM_H
1212
#define XTM_H
1313

14+
#include "access/clog.h"
15+
#include "utils/snapmgr.h"
16+
1417
typedef struct
1518
{
1619
XidStatus (*GetTransactionStatus)(TransactionId xid, XLogRecPtr *lsn);
1720
void (*SetTransactionStatus)(TransactionId xid, int nsubxids, TransactionId *subxids, XidStatus status, XLogRecPtr lsn);
18-
Snapshot (*GetSnapshot)(Snaphot);
21+
Snapshot (*GetSnapshot)(Snapshot snapshot);
1922
} TransactionManager;
2023

2124
extern TransactionManager* TM;

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