Skip to content

Commit 58bc188

Browse files
committed
extracted from xtm branch of postgres
0 parents  commit 58bc188

File tree

18 files changed

+1902
-0
lines changed

18 files changed

+1902
-0
lines changed

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
MODULE_big = pg_dtm
2+
OBJS = pg_dtm.o
3+
4+
EXTENSION = pg_dtm
5+
DATA = pg_dtm--1.0.sql
6+
7+
ifndef PG_CONFIG
8+
PG_CONFIG = pg_config
9+
endif
10+
11+
PGXS := $(shell $(PG_CONFIG) --pgxs)
12+
include $(PGXS)
13+

README

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
===
2+
dtm
3+
===
4+
5+
Distributed transaction management tools for PostgreSQL.
6+
7+
--------------------
8+
Communication scheme
9+
--------------------
10+
11+
.- Backend -.
12+
/ \
13+
/ \
14+
DTM ---- Backend ---- Coordinator
15+
\ /
16+
\ /
17+
`- Backend -´
18+
19+
-----------------------
20+
Coordinator-Backend API
21+
-----------------------
22+
23+
This API includes a set of postgres procedures that
24+
the coordinator can call with "select" statement.
25+
26+
extend_transaction (n integer) -> (higcid gcid)
27+
join_transaction (higcid gcid) -> ()
28+
FIXME: add procedures that would start and finish 2pc
29+
30+
----------
31+
libdtm api
32+
----------
33+
34+
typedef unsigned long long cid_t;
35+
36+
// Connects to the specified DTM.
37+
DTMConn DtmConnect(char *host, int port);
38+
39+
// Disconnects from the DTM. Do not use the 'dtm' pointer after this call, or
40+
// bad things will happen.
41+
void DtmDisconnect(DTMConn dtm);
42+
43+
// Asks DTM for the first 'gcid' with unknown status. This 'gcid' is used as a
44+
// kind of snapshot. Returns the 'gcid' on success, or INVALID_GCID otherwise.
45+
cid_t DtmGlobalGetNextCid(DTMConn dtm);
46+
47+
// Prepares a commit. Returns the 'gcid' on success, or INVALID_GCID otherwise.
48+
cid_t DtmGlobalPrepare(DTMConn dtm);
49+
50+
// Finishes a given commit with 'committed' status. Returns 'true' on success,
51+
// 'false' otherwise.
52+
bool DtmGlobalCommit(DTMConn dtm, cid_t gcid);
53+
54+
// Finishes a given commit with 'aborted' status.
55+
void DtmGlobalRollback(DTMConn dtm, cid_t gcid);
56+
57+
// Gets the status of the commit identified by 'gcid'. Returns the status on
58+
// success, or -1 otherwise.
59+
int DtmGlobalGetTransStatus(DTMConn dtm, cid_t gcid);
60+
61+
--------------------
62+
Backend-DTM Protocol
63+
--------------------
64+
65+
DTM <--> Backend:
66+
67+
<- 'p'<hex16 self> - "prepare"
68+
-> '+'<hex16 gcid> - "commit prepared"
69+
-> '-' - "something went wrong"
70+
71+
<- 'c'<hex16 gcid> - "commit"
72+
-> '+' - "commit saved"
73+
-> '-' - "something went wrong"
74+
75+
<- 'a'<hex16 gcid> - "abort"
76+
-> '+' - "abort saved"
77+
-> '-' - "something went wrong"
78+
79+
<- 'h' - "horizon"
80+
-> '+'<hex16 gcid> - "here is a gcid you can use as a snapshot"
81+
-> '-' - "something went wrong"
82+
83+
<- 's'<hex16 gcid> - "status"
84+
-> '+''c|a|?' - "here is the transaction status"
85+
(c)ommitted, (a)borted or (?)unknown
86+
-> '-' - "something went wrong"
87+
88+
Backend disconnection is considered as an abort of all incomplete commits
89+
prepared by that backend.

pg_dtm--1.0.sql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
2+
\echo Use "CREATE EXTENSION pg_dtm" to load this file. \quit
3+
4+
CREATE FUNCTION dtm_extend(gtid cstring default null) RETURNS bigint
5+
AS 'MODULE_PATHNAME','dtm_extend'
6+
LANGUAGE C;
7+
8+
CREATE FUNCTION dtm_access(snapshot bigint, gtid cstring default null) RETURNS bigint
9+
AS 'MODULE_PATHNAME','dtm_access'
10+
LANGUAGE C;
11+
12+
CREATE FUNCTION dtm_begin_prepare(gtid cstring) RETURNS void
13+
AS 'MODULE_PATHNAME','dtm_begin_prepare'
14+
LANGUAGE C;
15+
16+
CREATE FUNCTION dtm_prepare(gtid cstring, csn bigint) RETURNS bigint
17+
AS 'MODULE_PATHNAME','dtm_prepare'
18+
LANGUAGE C;
19+
20+
CREATE FUNCTION dtm_end_prepare(gtid cstring, csn bigint) RETURNS void
21+
AS 'MODULE_PATHNAME','dtm_end_prepare'
22+
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