Skip to content

Commit 864cf87

Browse files
committed
Implement global transaction starting in libdtm.
1 parent 8d25b12 commit 864cf87

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

contrib/pg_xtm/libdtm.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,26 @@ static bool dtm_query(DTMConn dtm, char cmd, int argc, ...) {
141141
return true;
142142
}
143143

144+
// Creates an entry for a new global transaction. Returns 'true' on success, or
145+
// 'false' otherwise.
146+
bool DtmGlobalStartTransaction(DTMConn dtm, GlobalTransactionId *gtid) {
147+
bool ok;
148+
int i;
149+
150+
// query
151+
if (!dtm_write_char(dtm, 'b')) return false;
152+
if (!dtm_write_hex16(dtm, 1 + 2 * gtid->nNodes)) return false;
153+
if (!dtm_write_hex16(dtm, gtid->nNodes)) return false;
154+
for (i = 0; i < gtid->nNodes; i++) {
155+
if (!dtm_write_hex16(dtm, gtid->nodes[i])) return false;
156+
if (!dtm_write_hex16(dtm, gtid->xids[i])) return false;
157+
}
158+
159+
// response
160+
if (!dtm_read_bool(dtm, &ok)) return false;
161+
return ok;
162+
}
163+
144164
// Asks DTM for a fresh snapshot. Returns 'true' on success, or 'false'
145165
// otherwise.
146166
bool DtmGlobalGetSnapshot(DTMConn dtm, NodeId nodeid, TransactionId xid, Snapshot s) {

contrib/pg_xtm/libdtm.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ typedef struct {
2525
int nNodes;
2626
} GlobalTransactionId;
2727

28-
// Creates an entry for a new global transaction.
29-
void DtmGlobalStartTransaction(DTMConn dtm, GlobalTransactionId* gtid);
28+
// Creates an entry for a new global transaction. Returns 'true' on success, or
29+
// 'false' otherwise.
30+
bool DtmGlobalStartTransaction(DTMConn dtm, GlobalTransactionId* gtid);
3031

3132
// Asks DTM for a fresh snapshot. Returns 'true' on success, or 'false'
3233
// otherwise.

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