@@ -55,8 +55,6 @@ typedef struct
55
55
56
56
#define DTM_SHMEM_SIZE (1024*1024)
57
57
#define DTM_HASH_SIZE 1003
58
- #define XTM_CONNECT_ATTEMPTS 10
59
-
60
58
61
59
void _PG_init (void );
62
60
void _PG_fini (void );
@@ -79,7 +77,7 @@ static TransactionId DtmGetGlobalTransactionId(void);
79
77
static bool TransactionIdIsInSnapshot (TransactionId xid , Snapshot snapshot );
80
78
static bool TransactionIdIsInDoubt (TransactionId xid );
81
79
82
- static void dtm_shmem_startup (void );
80
+ static void DtmShmemStartup (void );
83
81
84
82
static shmem_startup_hook_type prev_shmem_startup_hook ;
85
83
static HTAB * xid_in_doubt ;
@@ -121,18 +119,27 @@ static void DumpSnapshot(Snapshot s, char *name)
121
119
XTM_INFO ("%s\n" , buf );
122
120
}
123
121
122
+ /* In snapshots provided by DTMD xip array is sorted, so we can use bsearch */
124
123
static bool TransactionIdIsInSnapshot (TransactionId xid , Snapshot snapshot )
125
124
{
126
125
return xid >= snapshot -> xmax
127
126
|| bsearch (& xid , snapshot -> xip , snapshot -> xcnt , sizeof (TransactionId ), xidComparator ) != NULL ;
128
127
}
129
128
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
+ */
131
138
static bool TransactionIdIsInDoubt (TransactionId xid )
132
139
{
133
140
bool inDoubt ;
134
141
135
- if (!TransactionIdIsInSnapshot (xid , & DtmSnapshot )) {
142
+ if (!TransactionIdIsInSnapshot (xid , & DtmSnapshot )) { /* transaction is completed according to the snaphot */
136
143
LWLockAcquire (dtm -> hashLock , LW_SHARED );
137
144
inDoubt = hash_search (xid_in_doubt , & xid , HASH_FIND , NULL ) != NULL ;
138
145
LWLockRelease (dtm -> hashLock );
@@ -740,7 +747,7 @@ _PG_init(void)
740
747
* Install hooks.
741
748
*/
742
749
prev_shmem_startup_hook = shmem_startup_hook ;
743
- shmem_startup_hook = dtm_shmem_startup ;
750
+ shmem_startup_hook = DtmShmemStartup ;
744
751
}
745
752
746
753
/*
@@ -753,7 +760,7 @@ _PG_fini(void)
753
760
}
754
761
755
762
756
- static void dtm_shmem_startup (void )
763
+ static void DtmShmemStartup (void )
757
764
{
758
765
if (prev_shmem_startup_hook ) {
759
766
prev_shmem_startup_hook ();
0 commit comments