Skip to content

Commit 145a999

Browse files
committed
Add XTM implementation
1 parent fd1b4ca commit 145a999

File tree

12 files changed

+186
-663
lines changed

12 files changed

+186
-663
lines changed

contrib/pg_gtm/pg_dtm.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "storage/procarray.h"
2222
#include "access/xlogdefs.h"
2323
#include "access/xact.h"
24+
#include "access/xtm.h"
2425
#include "access/transam.h"
2526
#include "access/xlog.h"
2627
#include "access/twophase.h"
@@ -80,8 +81,6 @@ static DtmNodeState* local;
8081
static DtmTransState dtm_tx;
8182
static DTMConn dtm_conn;
8283

83-
static SnapshotProvider DefaultSnapshotProvider;
84-
8584
void _PG_init(void);
8685
void _PG_fini(void);
8786

@@ -392,7 +391,7 @@ void DtmInitialize()
392391
HASH_ELEM | HASH_FUNCTION | HASH_COMPARE | HASH_KEYCOPY);
393392

394393
RegisterTransactionVisibilityCallback(DtmVisibilityCheck);
395-
DefaultSnapshotProvider = SetSnapshotProvider(DtmSnapshotProvider);
394+
TM->GetSnapshotData = DtmGetSnapshotData;
396395

397396
LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
398397
local = (DtmNodeState*)ShmemInitStruct("dtm", sizeof(DtmNodeState), &found);
@@ -413,10 +412,10 @@ void DtmInitialize()
413412
}
414413

415414

416-
Snapshot DtmSnapshotProvider(Snapshot snapshot)
415+
Snapshot DtmGetSnapshotData(Snapshot snapshot)
417416
{
418417
if (dtm_tx.local_snapshot == NULL) {
419-
dtm_tx.local_snapshot = DefaultSnapshotProvider(snapshot);
418+
dtm_tx.local_snapshot = GetLocalSnapshotData(snapshot);
420419
}
421420
if (local->last_xid != InvalidTransactionId && RecentGlobalDataXmin > local->last_xid) {
422421
RecentGlobalDataXmin = local->last_xid;

contrib/pg_xtm/libdtm.h

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,19 @@ DTMConn DtmConnect(char *host, int port);
2020
// bad things will happen.
2121
void DtmDisconnect(DTMConn dtm);
2222

23-
// Asks DTM for a fresh snapshot. Returns a snapshot on success, or NULL
24-
// otherwise. Please free the snapshot memory yourself after use.
25-
Snapshot DtmGlobalGetSnapshot(DTMConn dtm);
2623

27-
// Starts a transaction. Returns the 'gxid' on success, or INVALID_GXID otherwise.
28-
xid_t DtmGlobalBegin(DTMConn dtm);
24+
typedef struct {
25+
TransasactionId* xids;
26+
int nXids;
27+
} GlobalTransactionId;
2928

30-
// Marks a given transaction as 'committed'. Returns 'true' on success,
31-
// 'false' otherwise.
32-
bool DtmGlobalCommit(DTMConn dtm, xid_t gxid);
29+
/* create entry for new global transaction */
30+
void DtmGlobalStartTransaction(DTMConn dtm, TransactionId* gitd);
3331

34-
// Marks a given transaction as 'aborted'.
35-
void DtmGlobalRollback(DTMConn dtm, xid_t gxid);
32+
void DtmGlobalGetSnapshot(DTMConn dtm, TransactionId xid, Snapshot snapshot);
3633

37-
// Gets the status of the commit identified by 'gxid'. Returns the status on
38-
// success, or -1 otherwise.
39-
int DtmGlobalGetTransStatus(DTMConn dtm, xid_t gxid);
34+
void DtmGlobalSetTransStatus(DTMConn dtm, TransactionId xid, XidStatus status); /* commit transaction only once all participants are committed, before it do not change CLOG */
35+
36+
XidStatus DtmGlobalGetTransStatus(DTMConn dtm, TransactionId xid);
4037

4138
#endif

contrib/pg_xtm/pg_dtm--1.0.sql

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,11 @@
11
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
22
\echo Use "CREATE EXTENSION pg_dtm" to load this file. \quit
33

4-
CREATE FUNCTION dtm_register_node(id integer) RETURNS void
5-
AS 'MODULE_PATHNAME','dtm_register_node'
4+
CREATE FUNCTION dtm_global_transaction(xids integer[]) RETURNS void
5+
AS 'MODULE_PATHNAME','dtm_global_transaction'
66
LANGUAGE C;
77

8-
CREATE FUNCTION dtm_extend(gtid cstring default null) RETURNS bigint
9-
AS 'MODULE_PATHNAME','dtm_extend'
8+
CREATE FUNCTION dtm_get_snapshot() RETURNS void
9+
AS 'MODULE_PATHNAME','dtm_get_snapshot'
1010
LANGUAGE C;
1111

12-
CREATE FUNCTION dtm_access(snapshot bigint, gtid cstring default null) RETURNS bigint
13-
AS 'MODULE_PATHNAME','dtm_access'
14-
LANGUAGE C;
15-
16-
CREATE FUNCTION dtm_begin_prepare(gtid cstring, coordinator integer) RETURNS void
17-
AS 'MODULE_PATHNAME','dtm_begin_prepare'
18-
LANGUAGE C;
19-
20-
CREATE FUNCTION dtm_prepare(gtid cstring, csn bigint) RETURNS bigint
21-
AS 'MODULE_PATHNAME','dtm_prepare'
22-
LANGUAGE C;
23-
24-
CREATE FUNCTION dtm_end_prepare(gtid cstring, csn bigint) RETURNS void
25-
AS 'MODULE_PATHNAME','dtm_end_prepare'
26-
LANGUAGE C;

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