Skip to content

Commit afdf647

Browse files
committed
Fix some typos and code formatting in libdtm.
1 parent d63b397 commit afdf647

File tree

2 files changed

+27
-36
lines changed

2 files changed

+27
-36
lines changed

contrib/pg_dtm/libdtm.c

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ static char* dtm_unix_sock_dir;
3333

3434
typedef unsigned xid_t;
3535

36-
// Connects to the specified DTM.
3736
static DTMConn DtmConnect(char *host, int port)
3837
{
3938
DTMConn dtm;
@@ -297,10 +296,6 @@ void DtmInitSnapshot(Snapshot snapshot)
297296
#endif
298297
}
299298

300-
// Starts a new global transaction of nParticipants size. Returns the
301-
// transaction id, fills the 'snapshot' and 'gxmin' on success. 'gxmin' is the
302-
// smallest xmin among all snapshots known to DTM. Returns INVALID_XID
303-
// otherwise.
304299
TransactionId DtmGlobalStartTransaction(Snapshot snapshot, TransactionId *gxmin)
305300
{
306301
int i;
@@ -337,8 +332,6 @@ TransactionId DtmGlobalStartTransaction(Snapshot snapshot, TransactionId *gxmin)
337332
return INVALID_XID;
338333
}
339334

340-
// Asks the DTM for a fresh snapshot. Fills the 'snapshot' and 'gxmin' on
341-
// success. 'gxmin' is the smallest xmin among all snapshots known to DTM.
342335
void DtmGlobalGetSnapshot(TransactionId xid, Snapshot snapshot, TransactionId *gxmin)
343336
{
344337
int i;
@@ -376,10 +369,6 @@ void DtmGlobalGetSnapshot(TransactionId xid, Snapshot snapshot, TransactionId *g
376369
);
377370
}
378371

379-
// Commits transaction only once all participants have called this function,
380-
// does not change CLOG otherwise. Set 'wait' to 'true' if you want this call
381-
// to return only after the transaction is considered finished by the DTM.
382-
// Returns the status on success, or -1 otherwise.
383372
XidStatus DtmGlobalSetTransStatus(TransactionId xid, XidStatus status, bool wait)
384373
{
385374
int reslen;
@@ -424,9 +413,6 @@ XidStatus DtmGlobalSetTransStatus(TransactionId xid, XidStatus status, bool wait
424413
return -1;
425414
}
426415

427-
// Gets the status of the transaction identified by 'xid'. Returns the status
428-
// on success, or -1 otherwise. If 'wait' is true, then it does not return
429-
// until the transaction is finished.
430416
XidStatus DtmGlobalGetTransStatus(TransactionId xid, bool wait)
431417
{
432418
int reslen;
@@ -462,11 +448,6 @@ XidStatus DtmGlobalGetTransStatus(TransactionId xid, bool wait)
462448
return -1;
463449
}
464450

465-
// Reserves at least 'nXids' successive xids for local transactions. The xids
466-
// reserved are not less than 'xid' in value. Returns the actual number of xids
467-
// reserved, and sets the 'first' xid accordingly. The number of xids reserved
468-
// is guaranteed to be at least nXids.
469-
// In other words, *first ≥ xid and result ≥ nXids.
470451
int DtmGlobalReserve(TransactionId xid, int nXids, TransactionId *first)
471452
{
472453
xid_t xmin, xmax;
@@ -503,11 +484,11 @@ int DtmGlobalReserve(TransactionId xid, int nXids, TransactionId *first)
503484
bool DtmGlobalDetectDeadLock(TransactionId xid, void* data, int size)
504485
{
505486
int msg_size = size + sizeof(xid)*2;
506-
int data_size = sizeof(ShubMessageHdr) + msg_size;
507-
char* buf = (char*)malloc(data_size);
487+
int data_size = sizeof(ShubMessageHdr) + msg_size;
488+
char* buf = (char*)malloc(data_size);
508489
ShubMessageHdr* msg = (ShubMessageHdr*)buf;
509490
xid_t* body = (xid_t*)(msg+1);
510-
int sent;
491+
int sent;
511492
int reslen;
512493
xid_t results[RESULTS_SIZE];
513494
DTMConn dtm = GetConnection();
@@ -517,8 +498,8 @@ bool DtmGlobalDetectDeadLock(TransactionId xid, void* data, int size)
517498
msg->size = msg_size;
518499

519500
*body++ = CMD_DEADLOCK;
520-
*body++ = xid;
521-
memcpy(body, data, size);
501+
*body++ = xid;
502+
memcpy(body, data, size);
522503

523504
sent = 0;
524505
while (sent < data_size)
@@ -531,10 +512,17 @@ bool DtmGlobalDetectDeadLock(TransactionId xid, void* data, int size)
531512
}
532513
sent += new_bytes;
533514
}
515+
534516
reslen = dtm_recv_results(dtm, RESULTS_SIZE, results);
535-
if (reslen != 1 || (results[0] != RES_OK && results[0] != RES_DEADLOCK)) {
536-
fprintf(stderr, "DtmGlobalDetectDeadLock: failed to check deadlocks for transaction %u\n", xid);
537-
return false;
538-
}
517+
if (reslen != 1 || (results[0] != RES_OK && results[0] != RES_DEADLOCK))
518+
{
519+
fprintf(
520+
stderr,
521+
"DtmGlobalDetectDeadLock: failed"
522+
" to check xid=%u for deadlock\n",
523+
xid
524+
);
525+
return false;
526+
}
539527
return results[0] == RES_DEADLOCK;
540528
}

contrib/pg_dtm/libdtm.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#define INVALID_XID 0
1010

1111
/**
12-
* Sets up the host and port for DTM connection.
12+
* Sets up the host and port for arbiter connection.
1313
* The defaults are "127.0.0.1" and 5431.
1414
*/
1515
void DtmGlobalConfig(char *host, int port, char* sock_dir);
@@ -19,21 +19,21 @@ void DtmInitSnapshot(Snapshot snapshot);
1919
/**
2020
* Starts a new global transaction. Returns the
2121
* transaction id, fills the 'snapshot' and 'gxmin' on success. 'gxmin' is the
22-
* smallest xmin among all snapshots known to DTM. Returns INVALID_XID
22+
* smallest xmin among all snapshots known to arbiter. Returns INVALID_XID
2323
* otherwise.
2424
*/
2525
TransactionId DtmGlobalStartTransaction(Snapshot snapshot, TransactionId *gxmin);
2626

2727
/**
28-
* Asks the DTM for a fresh snapshot. Fills the 'snapshot' and 'gxmin' on
29-
* success. 'gxmin' is the smallest xmin among all snapshots known to DTM.
28+
* Asks the arbiter for a fresh snapshot. Fills the 'snapshot' and 'gxmin' on
29+
* success. 'gxmin' is the smallest xmin among all snapshots known to arbiter.
3030
*/
3131
void DtmGlobalGetSnapshot(TransactionId xid, Snapshot snapshot, TransactionId *gxmin);
3232

3333
/**
3434
* Commits transaction only once all participants have called this function,
3535
* does not change CLOG otherwise. Set 'wait' to 'true' if you want this call
36-
* to return only after the transaction is considered finished by the DTM.
36+
* to return only after the transaction is considered finished by the arbiter.
3737
* Returns the status on success, or -1 otherwise.
3838
*/
3939
XidStatus DtmGlobalSetTransStatus(TransactionId xid, XidStatus status, bool wait);
@@ -55,9 +55,12 @@ XidStatus DtmGlobalGetTransStatus(TransactionId xid, bool wait);
5555
int DtmGlobalReserve(TransactionId xid, int nXids, TransactionId *first);
5656

5757
/**
58-
* Detect global deadlock. This funcions send serialized local resource graph to arbiter which appends them to global graph.
59-
* Once loop is detected in global resoruce graph, arbiter returns true. Otherwise false is returned.
60-
* Abiter should replace local part of resource graph if new graph is recevied from this cluster node (not backend).
58+
* Detect global deadlock. This function sends serialized local resource graph
59+
* to the arbiter which appends them to the global graph. Once a loop is
60+
* detected in global resource graph, the arbiter returns true. Otherwise false
61+
* is returned. Arbiter should replace the corresponding part of the global
62+
* resource graph if a new local graph is received from this cluster node (not
63+
* backend).
6164
*/
6265
bool DtmGlobalDetectDeadLock(TransactionId xid, void* graph, int size);
6366

0 commit comments

Comments
 (0)