You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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,...
15
17
</para>
16
18
17
19
<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.
24
21
</para>
25
22
26
23
<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:
31
25
</para>
32
26
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>
74
27
<variablelist>
75
28
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
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.
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).
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.
180
61
</para>
181
-
</listitem>
62
+
</listitem>
182
63
</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.
0 commit comments