Skip to content

Commit 4bc3b50

Browse files
committed
fix documentation build; put it into ToC
1 parent 98b6d8c commit 4bc3b50

File tree

3 files changed

+158
-167
lines changed

3 files changed

+158
-167
lines changed

doc/src/sgml/filelist.sgml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
<!ENTITY sources SYSTEM "sources.sgml">
101101
<!ENTITY storage SYSTEM "storage.sgml">
102102
<!ENTITY tablesample-method SYSTEM "tablesample-method.sgml">
103+
<!ENTITY xtm SYSTEM "xtm.sgml">
103104

104105
<!-- contrib information -->
105106
<!ENTITY contrib SYSTEM "contrib.sgml">

doc/src/sgml/postgres.sgml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@
254254
&storage;
255255
&bki;
256256
&planstats;
257+
&xtm;
257258

258259
</part>
259260

doc/src/sgml/xtm.sgml

Lines changed: 156 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -1,186 +1,175 @@
11
<!-- doc/src/sgml/xtm.sgml -->
2-
<chapter id="XTM">
2+
<chapter id="xtm">
33
<title>eXtensible Transaction Manager</title>
4-
<indexterm zone="XTM">
5-
<primary>eXtensible Transaction Manager</primary>
4+
5+
<indexterm zone="xtm">
6+
<primary>eXtensible Transaction Manager</primary>
67
</indexterm>
8+
79
<para>
810
PostgreSQL is open and extensible system, allowing to define own types (UDT), access methods, build custom execution plans, work with
9-
external storage (FDW), ... But until this moment transaction manager implementation was hardcoded in Postgres core.
10-
XTM allows to Postgres extensions to define their own transaction managers. For example, it can be used to implement distributed transaction manager
11-
(DTM) for various cluster extensions of Postgres. Existed cluster extensions for Postgres, such as Postgres-XL, Greenplum, ...
12-
have to patch code of Postgres core, which significantly complicates their development and maintenance. Presence of XTM makes it
13-
possible to implement such clusters as Postgres extension, not touching Postgres core. Such approach can easily be integrated with existed
14-
Postgres extension, such as pg_shard, postgres_fdw,...
11+
external storage (FDW), ... But until this moment transaction manager implementation was hardcoded in Postgres core.
12+
XTM allows to Postgres extensions to define their own transaction managers. For example, it can be used to implement distributed transaction manager
13+
(MyTM) for various cluster extensions of Postgres. Existed cluster extensions for Postgres, such as Postgres-XL, Greenplum, ...
14+
have to patch code of Postgres core, which significantly complicates their development and maintenance. Presence of XTM makes it
15+
possible to implement such clusters as Postgres extension, not touching Postgres core. Such approach can easily be integrated with existed
16+
Postgres extension, such as pg_shard, postgres_fdw,...
1517
</para>
1618

1719
<para>
18-
Transaction manager in Postgres is deeply integrated in the core and depends on many other components (clog, xlog, lock manager, procarray,...)
19-
as well as them depend on transaction manager. So it is not easy to completely encapsulate all transaction manager functionality. In other
20-
words XTM doesn't allow to implement arbitrary transaction manager. Subset of function included in XTM is not proven to be a necessary and sufficient.
21-
We were primary interested in development of distributed transaction manager, so we have tried to implement several possible DTMs
22-
(snapshot sharing, timestamp based, incremental distributed snapshot) and tried to find out minimal subset of transaction manager function in Postgres which
23-
has to be overridden.
20+
Transaction manager in Postgres is deeply integrated in the core and depends on many other components (clog, xlog, lock manager, procarray,...) as well as them depend on transaction manager. So it is not easy to completely encapsulate all transaction manager functionality. In other words XTM doesn't allow to implement arbitrary transaction manager. Subset of function included in XTM is not proven to be a necessary and sufficient. We were primary interested in development of distributed transaction manager, so we have tried to implement several possible MyTMs (snapshot sharing, timestamp based, incremental distributed snapshot) and tried to find out minimal subset of transaction manager function in Postgres which has to be overridden.
2421
</para>
2522

2623
<para>
27-
XTM tries to minimize changes in Postgres core and still provide the highest level of flexibility. We do not want to change format of tuple header
28-
or affect lock manager: it requires significant rewriting of all Postgres code. We decided not to introduce new abstract method and instead of it takes
29-
some most fundamental Postgres transaction manager function and make it possible to override them.
30-
Generally we want to control the following things:
24+
XTM tries to minimize changes in Postgres core and still provide the highest level of flexibility. We do not want to change format of tuple header or affect lock manager: it requires significant rewriting of all Postgres code. We decided not to introduce new abstract method and instead of it takes some most fundamental Postgres transaction manager function and make it possible to override them. Generally we want to control the following things:
3125
</para>
3226

33-
<variablelist>
34-
<varlistentry>
35-
<term>Snapshots and visibility</term>
36-
<listitem>
37-
<para>
38-
tension should be able to generate its own snapshot and determine own rules for checking visibility of tuples.
39-
</para>
40-
</listitem>
41-
</varlistentry>
42-
43-
<varlistentry>
44-
<term>Transaction status</term>
45-
<listitem>
46-
<para>
47-
It should be possible to alter modification and retrieving of transaction status (in-progress, committed, aborted...).
48-
We do not want to override Postgres commit/rollback function because their implementation include quite complex state automaton responsible
49-
for transaction control for commands and blocks. Instead of it we override low level functions which actually record transaction state.
50-
</para>
51-
</listitem>
52-
</varlistentry>
53-
54-
<varlistentry>
55-
<term>Transaction identifier (XID)</term>
56-
<listitem>
57-
<para>
58-
Custom TM should have capability to assign its own XIDs. XID representation is not changed: it is still 32-bit integer.
59-
But TM can define its own transaction identifier (for example commit serial numbers (CSN) and provide mapping between CSNs and XIDs).
60-
</para>
61-
</listitem>
62-
</varlistentry>
63-
64-
<varlistentry>
65-
<term>Deadlock detection</term>
66-
<listitem>
67-
<para>
68-
Custom deadlock detection is needed DTM to be able to handle distributed deadlocks.
69-
Actually deadlock detection is part of lock manager, but as far as essentially depends on intrinsic of TM implementation, we
70-
decided to place them in XTM API instead of proposing extensible API for lock manager.
71-
</para>
72-
</listitem>
73-
<varlistentry>
7427
<variablelist>
7528

76-
<para>
77-
We place all XTM functions in single structure <structname>TransactionManager</structname>T to simplify overriding of transaction manager and make it more error prone.
78-
Placing all function in one interface actually introduces new abstraction and helps to easily understand what custom TM is implementing itself
79-
and where it depends on basic Postgres functionality. Postgres already has some mechanism of defining transaction hooks: pre/post commit/abort.
80-
We decided to leave it and even extend set of hooks, adding hook for start of transaction and preparing transaction for two phase commit.
81-
In principle it is possible to replace hooks with API functions, but we find using of hooks in some cases more convenient and what to
82-
preserve backward compatibility.
83-
</para>
84-
85-
86-
<sect1 id="xtm-functions">
87-
<title>eXtensible Transaction Manager functions</title>
88-
89-
<varlistentry id="GetTransactionStatus">
90-
<term><synopsis>XidStatus (*GetTransactionStatus) (TransactionId xid, XLogRecPtr *lsn)</synopsis></term>
91-
<listitem>
29+
<varlistentry>
30+
<term>Snapshots and visibility</term>
31+
<listitem>
9232
<para>
93-
Get current transaction status (encapsulation of <function>TransactionIdGetStatus</function> in <filename>clog.c</filename>)
33+
tension should be able to generate its own snapshot and determine own rules for checking visibility of tuples.
9434
</para>
95-
</listitem>
35+
</listitem>
9636
</varlistentry>
9737

98-
<varlistentry id="SetTransactionStatus">
99-
<term><synopsis>void (*SetTransactionStatus) (TransactionId xid, int nsubxids, TransactionId *subxids, XidStatus status, XLogRecPtr lsn)</synopsis></term>
100-
<listitem>
101-
<para>
102-
Set current transaction status (encapsulation of <function>TransactionIdSetTreeStatus</function> in <filename>clog.c</filename>)
103-
</para>
104-
</listitem>
105-
</varlistentry>
106-
107-
<varlistentry id="GetSnapshot">
108-
<term><synopsis>Snapshot (*GetSnapshot) (Snapshot snapshot)</synopsis></term>
109-
<listitem>
110-
<para>
111-
Get current transaction snapshot (encapsulation of <function>GetSnapshotData</function> in <filename>procarray.c</filename>)
112-
</para>
113-
</listitem>
114-
</varlistentry>
115-
116-
<varlistentry id="GetNewTransactionId">
117-
<term><synopsis>TransactionId (*GetNewTransactionId) (bool isSubXact)</synopsis></term>
118-
<listitem>
119-
<para>
120-
Assign new Xid to transaction (encapsulation of <function>GetNewTransactionId</function> in <filename>varsup.c</filename>)
121-
</para>
122-
</listitem>
123-
</varlistentry>
124-
125-
<varlistentry id="GetOldestXmin">
126-
<term><synopsis>TransactionId (*GetOldestXmin) (Relation rel, bool ignoreVacuum)</synopsis></term>
127-
<listitem>
128-
<para>
129-
Get oldest transaction Xid that was running when any current
130-
transaction was started (encapsulation of <function>GetOldestXmin</function> in <filename>procarray.c</filename>)
131-
</para>
132-
</listitem>
133-
</varlistentry>
134-
135-
<varlistentry id="IsInProgress">
136-
<term><synopsis>bool (*IsInProgress) (TransactionId xid)</synopsis></term>
137-
<listitem>
38+
<varlistentry>
39+
<term>Transaction status</term>
40+
<listitem>
13841
<para>
139-
Check if current transaction is not yet completed (encapsulation of
140-
<function>TransactionIdIsInProgress</function> in <filename>procarray.c</filename>)
42+
It should be possible to alter modification and retrieving of transaction status (in-progress, committed, aborted...). We do not want to override Postgres commit/rollback function because their implementation include quite complex state automaton responsible for transaction control for commands and blocks. Instead of it we override low level functions which actually record transaction state.
14143
</para>
142-
</listitem>
44+
</listitem>
14345
</varlistentry>
144-
145-
<varlistentry id="GetGlobalTransactionId">
146-
<term><synopsis>TransactionId (*GetGlobalTransactionId) (void)</synopsis></term>
147-
<listitem>
148-
<para>
149-
Get global transaction XID: returns XID of current transaction if it is
150-
global, <varname>InvalidTransactionId</varname> otherwise.
151-
</para>
152-
</listitem>
153-
</varlistentry>
154-
155-
<varlistentry id="IsInSnapshot">
156-
<term><synopsis>bool (*IsInSnapshot) (TransactionId xid, Snapshot snapshot)</synopsis></term>
157-
<listitem>
158-
<para>
159-
Is the given XID still-in-progress according to the snapshot
160-
(encapsulation of <function>XidInMVCCSnapshot</function> in <filename>tqual.c</filename>)
161-
</para>
162-
</listitem>
163-
</varlistentry>
164-
165-
166-
<varlistentry id="DetectGlobalDeadLock">
167-
<term><synopsis>bool (*DetectGlobalDeadLock) (PGPROC *proc)</synopsis></term>
168-
<listitem>
46+
47+
<varlistentry>
48+
<term>Transaction identifier (XID)</term>
49+
<listitem>
16950
<para>
170-
Detect distributed deadlock
51+
Custom TM should have capability to assign its own XIDs. XID representation is not changed: it is still 32-bit integer. But TM can define its own transaction identifier (for example commit serial numbers (CSN) and provide mapping between CSNs and XIDs).
17152
</para>
172-
</listitem>
53+
</listitem>
17354
</varlistentry>
174-
175-
<varlistentry id="GetName">
176-
<term><synopsis>char const *(*GetName) (void)</synopsis></term>
177-
<listitem>
55+
56+
<varlistentry>
57+
<term>Deadlock detection</term>
58+
<listitem>
17859
<para>
179-
Get transaction manager name
60+
Custom deadlock detection is needed MyTM to be able to handle distributed deadlocks. Actually deadlock detection is part of lock manager, but as far as essentially depends on intrinsic of TM implementation, we decided to place them in XTM API instead of proposing extensible API for lock manager.
18061
</para>
181-
</listitem>
62+
</listitem>
18263
</varlistentry>
64+
65+
</variablelist>
66+
67+
<para>
68+
We place all XTM functions in single structure <structname>TransactionManager</structname>T to simplify overriding of transaction manager and make it more error prone. Placing all function in one interface actually introduces new abstraction and helps to easily understand what custom TM is implementing itself and where it depends on basic Postgres functionality. Postgres already has some mechanism of defining transaction hooks: pre/post commit/abort. We decided to leave it and even extend set of hooks, adding hook for start of transaction and preparing transaction for two phase commit. In principle it is possible to replace hooks with API functions, but we find using of hooks in some cases more convenient and what to preserve backward compatibility.
69+
</para>
70+
71+
<sect1 id="xtm-functions">
72+
<title>eXtensible Transaction Manager functions</title>
73+
74+
<variablelist>
75+
76+
<varlistentry id="GetTransactionStatus">
77+
<term><synopsis>XidStatus (*GetTransactionStatus) (TransactionId xid, XLogRecPtr *lsn)</synopsis></term>
78+
<listitem>
79+
<para>
80+
Get current transaction status (encapsulation of <function>TransactionIdGetStatus</function> in <filename>clog.c</filename>)
81+
</para>
82+
</listitem>
83+
</varlistentry>
84+
85+
<varlistentry id="SetTransactionStatus">
86+
<term><synopsis>void (*SetTransactionStatus) (TransactionId xid, int nsubxids, TransactionId *subxids, XidStatus status, XLogRecPtr lsn)</synopsis></term>
87+
<listitem>
88+
<para>
89+
Set current transaction status (encapsulation of <function>TransactionIdSetTreeStatus</function> in <filename>clog.c</filename>)
90+
</para>
91+
</listitem>
92+
</varlistentry>
93+
94+
<varlistentry id="GetSnapshot">
95+
<term><synopsis>Snapshot (*GetSnapshot) (Snapshot snapshot)</synopsis></term>
96+
<listitem>
97+
<para>
98+
Get current transaction snapshot (encapsulation of <function>GetSnapshotData</function> in <filename>procarray.c</filename>)
99+
</para>
100+
</listitem>
101+
</varlistentry>
102+
103+
<varlistentry id="GetNewTransactionId">
104+
<term><synopsis>TransactionId (*GetNewTransactionId) (bool isSubXact)</synopsis></term>
105+
<listitem>
106+
<para>
107+
Assign new Xid to transaction (encapsulation of <function>GetNewTransactionId</function> in <filename>varsup.c</filename>)
108+
</para>
109+
</listitem>
110+
</varlistentry>
111+
112+
<varlistentry id="GetOldestXmin">
113+
<term><synopsis>TransactionId (*GetOldestXmin) (Relation rel, bool ignoreVacuum)</synopsis></term>
114+
<listitem>
115+
<para>
116+
Get oldest transaction Xid that was running when any current
117+
transaction was started (encapsulation of <function>GetOldestXmin</function> in <filename>procarray.c</filename>)
118+
</para>
119+
</listitem>
120+
</varlistentry>
121+
122+
<varlistentry id="IsInProgress">
123+
<term><synopsis>bool (*IsInProgress) (TransactionId xid)</synopsis></term>
124+
<listitem>
125+
<para>
126+
Check if current transaction is not yet completed (encapsulation of
127+
<function>TransactionIdIsInProgress</function> in <filename>procarray.c</filename>)
128+
</para>
129+
</listitem>
130+
</varlistentry>
131+
132+
<varlistentry id="GetGlobalTransactionId">
133+
<term><synopsis>TransactionId (*GetGlobalTransactionId) (void)</synopsis></term>
134+
<listitem>
135+
<para>
136+
Get global transaction XID: returns XID of current transaction if it is
137+
global, <varname>InvalidTransactionId</varname> otherwise.
138+
</para>
139+
</listitem>
140+
</varlistentry>
141+
142+
<varlistentry id="IsInSnapshot">
143+
<term><synopsis>bool (*IsInSnapshot) (TransactionId xid, Snapshot snapshot)</synopsis></term>
144+
<listitem>
145+
<para>
146+
Is the given XID still-in-progress according to the snapshot
147+
(encapsulation of <function>XidInMVCCSnapshot</function> in <filename>tqual.c</filename>)
148+
</para>
149+
</listitem>
150+
</varlistentry>
151+
152+
153+
<varlistentry id="DetectGlobalDeadLock">
154+
<term><synopsis>bool (*DetectGlobalDeadLock) (PGPROC *proc)</synopsis></term>
155+
<listitem>
156+
<para>
157+
Detect distributed deadlock
158+
</para>
159+
</listitem>
160+
</varlistentry>
161+
162+
<varlistentry id="GetName">
163+
<term><synopsis>char const *(*GetName) (void)</synopsis></term>
164+
<listitem>
165+
<para>
166+
Get transaction manager name
167+
</para>
168+
</listitem>
169+
</varlistentry>
183170

171+
</variablelist>
172+
184173
</sect1>
185174

186175
<sect1 id="xtm-usage">
@@ -197,23 +186,23 @@ But TM can define its own transaction identifier (for example commit serial numb
197186
</para>
198187

199188
<programlisting>
200-
static TransactionManager DtmTM = {
201-
DtmGetTransactionStatus,
202-
DtmSetTransactionStatus,
203-
DtmGetSnapshot,
204-
DtmGetNewTransactionId,
205-
DtmGetOldestXmin,
206-
PgTransactionIdIsInProgress,
207-
DtmGetGlobalTransactionId,
208-
PgXidInMVCCSnapshot,
209-
DtmDetectGlobalDeadLock,
210-
DtmGetName
189+
static TransactionManager MyTM = {
190+
MyTMGetTransactionStatus,
191+
MyTMSetTransactionStatus,
192+
MyTMGetSnapshot,
193+
MyTMGetNewTransactionId,
194+
MyTMGetOldestXmin,
195+
PgTransactionIdIsInProgress,
196+
MyTMGetGlobalTransactionId,
197+
PgXidInMVCCSnapshot,
198+
MyTMDetectGlobalDeadLock,
199+
MyTMGetName
211200
};
212201

213-
static void DtmInitialize()
202+
static void MyTMInitialize()
214203
{
215204
...
216-
TM = &DtmTM;
205+
TM = &amp;MyTM;
217206
}
218207
</programlisting>
219208

0 commit comments

Comments
 (0)