|
| 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. |
0 commit comments