Skip to content

Commit 9226662

Browse files
committed
Add comments to DTM
1 parent c2f8668 commit 9226662

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

contrib/pg_xtm/pg_dtm.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ typedef struct
5555

5656
#define DTM_SHMEM_SIZE (1024*1024)
5757
#define DTM_HASH_SIZE 1003
58-
#define XTM_CONNECT_ATTEMPTS 10
59-
6058

6159
void _PG_init(void);
6260
void _PG_fini(void);
@@ -79,7 +77,7 @@ static TransactionId DtmGetGlobalTransactionId(void);
7977
static bool TransactionIdIsInSnapshot(TransactionId xid, Snapshot snapshot);
8078
static bool TransactionIdIsInDoubt(TransactionId xid);
8179

82-
static void dtm_shmem_startup(void);
80+
static void DtmShmemStartup(void);
8381

8482
static shmem_startup_hook_type prev_shmem_startup_hook;
8583
static HTAB* xid_in_doubt;
@@ -121,18 +119,27 @@ static void DumpSnapshot(Snapshot s, char *name)
121119
XTM_INFO("%s\n", buf);
122120
}
123121

122+
/* In snapshots provided by DTMD xip array is sorted, so we can use bsearch */
124123
static bool TransactionIdIsInSnapshot(TransactionId xid, Snapshot snapshot)
125124
{
126125
return xid >= snapshot->xmax
127126
|| bsearch(&xid, snapshot->xip, snapshot->xcnt, sizeof(TransactionId), xidComparator) != NULL;
128127
}
129128

130-
129+
/* Transaction is considered as in-doubt if it is globally committed by DTMD but local commit is not yet completed.
130+
* It can happen because we report DTMD about transaction commit in SetTransactionStatus, which is called inside commit
131+
* after saving transaction state in WAL but before releasing locks. So DTMD can include this transaction in snapshot
132+
* before local commit is completed and transaction is marked as completed in local CLOG.
133+
*
134+
* We use xid_in_doubt hash table to mark transactions which are "precommitted". Entry is inserted in hash table
135+
* before seding status to DTMD and removed after receving response from DTMD and setting transaction status in local CLOG.
136+
* So information about transaction should always present either in xid_in_doubt either in CLOG.
137+
*/
131138
static bool TransactionIdIsInDoubt(TransactionId xid)
132139
{
133140
bool inDoubt;
134141

135-
if (!TransactionIdIsInSnapshot(xid, &DtmSnapshot)) {
142+
if (!TransactionIdIsInSnapshot(xid, &DtmSnapshot)) { /* transaction is completed according to the snaphot */
136143
LWLockAcquire(dtm->hashLock, LW_SHARED);
137144
inDoubt = hash_search(xid_in_doubt, &xid, HASH_FIND, NULL) != NULL;
138145
LWLockRelease(dtm->hashLock);
@@ -740,7 +747,7 @@ _PG_init(void)
740747
* Install hooks.
741748
*/
742749
prev_shmem_startup_hook = shmem_startup_hook;
743-
shmem_startup_hook = dtm_shmem_startup;
750+
shmem_startup_hook = DtmShmemStartup;
744751
}
745752

746753
/*
@@ -753,7 +760,7 @@ _PG_fini(void)
753760
}
754761

755762

756-
static void dtm_shmem_startup(void)
763+
static void DtmShmemStartup(void)
757764
{
758765
if (prev_shmem_startup_hook) {
759766
prev_shmem_startup_hook();

src/backend/storage/ipc/procarray.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,19 +1003,6 @@ TransactionIdIsRunning(TransactionId xid)
10031003
TransactionId topxid;
10041004
int i,
10051005
j;
1006-
1007-
if (VisibilityCallback)
1008-
{
1009-
/* Just wait for in-doubt transactions */
1010-
(*VisibilityCallback)(xid);
1011-
/*
1012-
if (result != XID_IN_DOUBT)
1013-
{
1014-
return result == XID_INVISIBLE;
1015-
}
1016-
*/
1017-
}
1018-
10191006
/*
10201007
* Don't bother checking a transaction older than RecentXmin; it could not
10211008
* possibly still be running. (Note: in particular, this guarantees that

0 commit comments

Comments
 (0)