6
6
7
7
#define unless (x ) if (!(x))
8
8
9
- #define NODES 1
10
-
11
-
12
9
int main (int argc , char * * argv ) {
13
- GlobalTransactionId gtid ;
14
- TransactionId base = 42 ;
15
- int transactions = 10000 ;
16
- int i ;
17
- gtid .nNodes = NODES ;
18
- gtid .xids = malloc (sizeof (TransactionId ) * gtid .nNodes );
19
- gtid .nodes = malloc (sizeof (NodeId ) * gtid .nNodes );
20
-
21
- DTMConn conn = DtmConnect ("localhost" , 5431 );
22
- if (!conn ) {
23
- exit (1 );
24
- }
10
+ DtmGlobalConfig ("localhost" , 5002 , "/tmp" );
25
11
12
+ int i ;
26
13
for (i = 0 ; i < transactions ; i ++ ) {
27
-
28
- int n ;
29
- for (n = 0 ; n < gtid .nNodes ; n ++ ) {
30
- gtid .xids [n ] = base + n ;
31
- gtid .nodes [n ] = n ;
14
+ TransactionId xid , gxmin ;
15
+ Snapshot snapshot ;
16
+ xid = DtmGlobalStartTransaction (snapshot , & gxmin );
17
+ if (xid == INVALID_XID ) {
18
+ fprintf (stdout , "global transaction not started\n" );
19
+ exit (EXIT_FAILURE );
32
20
}
33
21
34
- if (!DtmGlobalStartTransaction (conn , & gtid )) {
35
- fprintf (stdout , "global transaction not started\n" );
22
+ DtmGlobalGetSnapshot (xid , snapshot , & gxmin );
23
+
24
+ bool wait = true;
25
+
26
+ XidStatus s = DtmGlobalSetTransStatus (xid , TRANSACTION_STATUS_COMMITTED , wait );
27
+ if (s != TRANSACTION_STATUS_COMMITTED ) {
28
+ fprintf (stdout , "global transaction not committed\n" );
36
29
exit (EXIT_FAILURE );
37
30
}
38
31
39
- if (!DtmGlobalSetTransStatus (conn , 0 , base + 0 , TRANSACTION_STATUS_COMMITTED )) {
32
+ s = DtmGlobalGetTransStatus (xid , wait );
33
+ if (s != TRANSACTION_STATUS_COMMITTED ) {
40
34
fprintf (stdout , "global transaction not committed\n" );
41
35
exit (EXIT_FAILURE );
42
36
}
@@ -48,7 +42,5 @@ int main(int argc, char **argv) {
48
42
base ++ ;
49
43
}
50
44
51
-
52
- DtmDisconnect (conn );
53
45
return EXIT_SUCCESS ;
54
46
}
0 commit comments