1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
|
/* Copyright (C) 2003 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <ndb_global.h>
#include <NdbOut.hpp>
#include <NdbTransaction.hpp>
#include <NdbOperation.hpp>
#include <NdbScanOperation.hpp>
#include <NdbIndexScanOperation.hpp>
#include <NdbIndexOperation.hpp>
#include "NdbApiSignal.hpp"
#include "TransporterFacade.hpp"
#include "API.hpp"
#include "NdbBlob.hpp"
#include <signaldata/TcKeyConf.hpp>
#include <signaldata/TcIndx.hpp>
#include <signaldata/TcCommit.hpp>
#include <signaldata/TcKeyFailConf.hpp>
#include <signaldata/TcHbRep.hpp>
/*****************************************************************************
NdbTransaction( Ndb* aNdb );
Return Value: None
Parameters: aNdb: Pointers to the Ndb object
Remark: Creates a connection object.
*****************************************************************************/
NdbTransaction::NdbTransaction( Ndb* aNdb ) :
theSendStatus(NotInit),
theCallbackFunction(NULL),
theCallbackObject(NULL),
theTransArrayIndex(0),
theStartTransTime(0),
theErrorLine(0),
theErrorOperation(NULL),
theNdb(aNdb),
theNext(NULL),
theFirstOpInList(NULL),
theLastOpInList(NULL),
theFirstExecOpInList(NULL),
theLastExecOpInList(NULL),
theCompletedFirstOp(NULL),
theCompletedLastOp(NULL),
theNoOfOpSent(0),
theNoOfOpCompleted(0),
theMyRef(0),
theTCConPtr(0),
theTransactionId(0),
theGlobalCheckpointId(0),
p_latest_trans_gci(0),
theStatus(NotConnected),
theCompletionStatus(NotCompleted),
theCommitStatus(NotStarted),
theMagicNumber(0xFE11DC),
theTransactionIsStarted(false),
theDBnode(0),
theReleaseOnClose(false),
// Scan operations
m_waitForReply(true),
m_theFirstScanOperation(NULL),
m_theLastScanOperation(NULL),
m_firstExecutedScanOp(NULL),
// Scan operations
theScanningOp(NULL),
theBuddyConPtr(0xFFFFFFFF),
theBlobFlag(false),
thePendingBlobOps(0)
{
theListState = NotInList;
theError.code = 0;
//theId = NdbObjectIdMap::InvalidId;
theId = theNdb->theImpl->theNdbObjectIdMap.map(this);
#define CHECK_SZ(mask, sz) assert((sizeof(mask)/sizeof(mask[0])) == sz)
CHECK_SZ(m_db_nodes, NdbNodeBitmask::Size);
CHECK_SZ(m_failed_db_nodes, NdbNodeBitmask::Size);
}//NdbTransaction::NdbTransaction()
/*****************************************************************************
~NdbTransaction();
Remark: Deletes the connection object.
*****************************************************************************/
NdbTransaction::~NdbTransaction()
{
DBUG_ENTER("NdbTransaction::~NdbTransaction");
theNdb->theImpl->theNdbObjectIdMap.unmap(theId, this);
DBUG_VOID_RETURN;
}//NdbTransaction::~NdbTransaction()
/*****************************************************************************
void init();
Remark: Initialise connection object for new transaction.
*****************************************************************************/
int
NdbTransaction::init()
{
theListState = NotInList;
theInUseState = true;
theTransactionIsStarted = false;
theNext = NULL;
theFirstOpInList = NULL;
theLastOpInList = NULL;
theScanningOp = NULL;
theFirstExecOpInList = NULL;
theLastExecOpInList = NULL;
theCompletedFirstOp = NULL;
theCompletedLastOp = NULL;
theGlobalCheckpointId = 0;
p_latest_trans_gci =
theNdb->theImpl->m_ndb_cluster_connection.get_latest_trans_gci();
theCommitStatus = Started;
theCompletionStatus = NotCompleted;
theError.code = 0;
theErrorLine = 0;
theErrorOperation = NULL;
theReleaseOnClose = false;
theSimpleState = true;
theSendStatus = InitState;
theMagicNumber = 0x37412619;
// Scan operations
m_waitForReply = true;
m_theFirstScanOperation = NULL;
m_theLastScanOperation = NULL;
m_firstExecutedScanOp = 0;
theBuddyConPtr = 0xFFFFFFFF;
//
theBlobFlag = false;
thePendingBlobOps = 0;
if (theId == NdbObjectIdMap::InvalidId)
{
theId = theNdb->theImpl->theNdbObjectIdMap.map(this);
if (theId == NdbObjectIdMap::InvalidId)
{
theError.code = 4000;
return -1;
}
}
return 0;
}//NdbTransaction::init()
/*****************************************************************************
setOperationErrorCode(int error);
Remark: Sets an error code on the connection object from an
operation object.
*****************************************************************************/
void
NdbTransaction::setOperationErrorCode(int error)
{
DBUG_ENTER("NdbTransaction::setOperationErrorCode");
setErrorCode(error);
DBUG_VOID_RETURN;
}
/*****************************************************************************
setOperationErrorCodeAbort(int error);
Remark: Sets an error code on the connection object from an
operation object.
*****************************************************************************/
void
NdbTransaction::setOperationErrorCodeAbort(int error, int abortOption)
{
DBUG_ENTER("NdbTransaction::setOperationErrorCodeAbort");
if (theTransactionIsStarted == false) {
theCommitStatus = Aborted;
} else if ((theCommitStatus != Committed) &&
(theCommitStatus != Aborted)) {
theCommitStatus = NeedAbort;
}//if
setErrorCode(error);
DBUG_VOID_RETURN;
}
/*****************************************************************************
setErrorCode(int anErrorCode);
Remark: Sets an error indication on the connection object.
*****************************************************************************/
void
NdbTransaction::setErrorCode(int error)
{
DBUG_ENTER("NdbTransaction::setErrorCode");
DBUG_PRINT("enter", ("error: %d, theError.code: %d", error, theError.code));
if (theError.code == 0)
theError.code = error;
DBUG_VOID_RETURN;
}//NdbTransaction::setErrorCode()
int
NdbTransaction::restart(){
DBUG_ENTER("NdbTransaction::restart");
if(theCompletionStatus == CompletedSuccess){
releaseCompletedOperations();
Uint64 tTransid = theNdb->theFirstTransId;
theTransactionId = tTransid;
if ((tTransid & 0xFFFFFFFF) == 0xFFFFFFFF) {
theNdb->theFirstTransId = (tTransid >> 32) << 32;
} else {
theNdb->theFirstTransId = tTransid + 1;
}
theCommitStatus = Started;
theCompletionStatus = NotCompleted;
theTransactionIsStarted = false;
DBUG_RETURN(0);
}
DBUG_PRINT("error",("theCompletionStatus != CompletedSuccess"));
DBUG_RETURN(-1);
}
/*****************************************************************************
void handleExecuteCompletion(void);
Remark: Handle time-out on a transaction object.
*****************************************************************************/
void
NdbTransaction::handleExecuteCompletion()
{
/***************************************************************************
* Move the NdbOperation objects from the list of executing
* operations to list of completed
**************************************************************************/
NdbOperation* tFirstExecOp = theFirstExecOpInList;
NdbOperation* tLastExecOp = theLastExecOpInList;
if (tLastExecOp != NULL) {
tLastExecOp->next(theCompletedFirstOp);
theCompletedFirstOp = tFirstExecOp;
if (theCompletedLastOp == NULL)
theCompletedLastOp = tLastExecOp;
theFirstExecOpInList = NULL;
theLastExecOpInList = NULL;
}//if
theSendStatus = InitState;
return;
}//NdbTransaction::handleExecuteCompletion()
/*****************************************************************************
int execute(ExecType aTypeOfExec, CommitType aTypeOfCommit, int forceSend);
Return Value: Return 0 : execute was successful.
Return -1: In all other case.
Parameters : aTypeOfExec: Type of execute.
Remark: Initialise connection object for new transaction.
*****************************************************************************/
int
NdbTransaction::execute(ExecType aTypeOfExec,
NdbOperation::AbortOption abortOption,
int forceSend)
{
NdbError savedError= theError;
DBUG_ENTER("NdbTransaction::execute");
DBUG_PRINT("enter", ("aTypeOfExec: %d, abortOption: %d",
aTypeOfExec, abortOption));
if (! theBlobFlag)
DBUG_RETURN(executeNoBlobs(aTypeOfExec, abortOption, forceSend));
/*
* execute prepared ops in batches, as requested by blobs
* - blob error does not terminate execution
* - blob error sets error on operation
* - if error on operation skip blob calls
*/
ExecType tExecType;
NdbOperation* tPrepOp;
NdbOperation* tCompletedFirstOp = NULL;
NdbOperation* tCompletedLastOp = NULL;
int ret = 0;
do {
tExecType = aTypeOfExec;
tPrepOp = theFirstOpInList;
while (tPrepOp != NULL) {
if (tPrepOp->theError.code == 0) {
bool batch = false;
NdbBlob* tBlob = tPrepOp->theBlobList;
while (tBlob != NULL) {
if (tBlob->preExecute(tExecType, batch) == -1)
{
ret = -1;
if(savedError.code==0)
savedError= theError;
}
tBlob = tBlob->theNext;
}
if (batch) {
// blob asked to execute all up to here now
tExecType = NoCommit;
break;
}
}
tPrepOp = tPrepOp->next();
}
// save rest of prepared ops if batch
NdbOperation* tRestOp= 0;
NdbOperation* tLastOp= 0;
if (tPrepOp != NULL) {
tRestOp = tPrepOp->next();
tPrepOp->next(NULL);
tLastOp = theLastOpInList;
theLastOpInList = tPrepOp;
}
if (tExecType == Commit) {
NdbOperation* tOp = theCompletedFirstOp;
while (tOp != NULL) {
if (tOp->theError.code == 0) {
NdbBlob* tBlob = tOp->theBlobList;
while (tBlob != NULL) {
if (tBlob->preCommit() == -1)
{
ret = -1;
if(savedError.code==0)
savedError= theError;
}
tBlob = tBlob->theNext;
}
}
tOp = tOp->next();
}
}
// completed ops are in unspecified order
if (theCompletedFirstOp != NULL) {
if (tCompletedFirstOp == NULL) {
tCompletedFirstOp = theCompletedFirstOp;
tCompletedLastOp = theCompletedLastOp;
} else {
tCompletedLastOp->next(theCompletedFirstOp);
tCompletedLastOp = theCompletedLastOp;
}
theCompletedFirstOp = NULL;
theCompletedLastOp = NULL;
}
if (executeNoBlobs(tExecType,
NdbOperation::DefaultAbortOption,
forceSend) == -1)
{
if(savedError.code==0)
savedError= theError;
DBUG_RETURN(-1);
}
#ifdef ndb_api_crash_on_complex_blob_abort
assert(theFirstOpInList == NULL && theLastOpInList == NULL);
#else
theFirstOpInList = theLastOpInList = NULL;
#endif
{
NdbOperation* tOp = theCompletedFirstOp;
while (tOp != NULL) {
if (tOp->theError.code == 0) {
NdbBlob* tBlob = tOp->theBlobList;
while (tBlob != NULL) {
// may add new operations if batch
if (tBlob->postExecute(tExecType) == -1)
{
ret = -1;
if(savedError.code==0)
savedError= theError;
}
tBlob = tBlob->theNext;
}
}
tOp = tOp->next();
}
}
// add saved prepared ops if batch
if (tPrepOp != NULL && tRestOp != NULL) {
if (theFirstOpInList == NULL)
theFirstOpInList = tRestOp;
else
theLastOpInList->next(tRestOp);
theLastOpInList = tLastOp;
}
assert(theFirstOpInList == NULL || tExecType == NoCommit);
} while (theFirstOpInList != NULL || tExecType != aTypeOfExec);
if (tCompletedFirstOp != NULL) {
tCompletedLastOp->next(theCompletedFirstOp);
theCompletedFirstOp = tCompletedFirstOp;
if (theCompletedLastOp == NULL)
theCompletedLastOp = tCompletedLastOp;
}
#if ndb_api_count_completed_ops_after_blob_execute
{ NdbOperation* tOp; unsigned n = 0;
for (tOp = theCompletedFirstOp; tOp != NULL; tOp = tOp->next()) n++;
ndbout << "completed ops: " << n << endl;
}
#endif
if(savedError.code!=0 && theError.code==4350) // Trans already aborted
theError= savedError;
DBUG_RETURN(ret);
}
int
NdbTransaction::executeNoBlobs(NdbTransaction::ExecType aTypeOfExec,
NdbOperation::AbortOption abortOption,
int forceSend)
{
DBUG_ENTER("NdbTransaction::executeNoBlobs");
DBUG_PRINT("enter", ("aTypeOfExec: %d, abortOption: %d",
aTypeOfExec, abortOption));
//------------------------------------------------------------------------
// We will start by preparing all operations in the transaction defined
// since last execute or since beginning. If this works ok we will continue
// by calling the poll with wait method. This method will return when
// the NDB kernel has completed its task or when 10 seconds have passed.
// The NdbTransactionCallBack-method will receive the return code of the
// transaction. The normal methods of reading error codes still apply.
//------------------------------------------------------------------------
Ndb* tNdb = theNdb;
Uint32 timeout = theNdb->theImpl->m_transporter_facade->m_waitfor_timeout;
m_waitForReply = false;
executeAsynchPrepare(aTypeOfExec, NULL, NULL, abortOption);
if (m_waitForReply){
while (1) {
int noOfComp = tNdb->sendPollNdb(3 * timeout, 1, forceSend);
if (noOfComp == 0) {
/**
* This timeout situation can occur if NDB crashes.
*/
ndbout << "This timeout should never occur, execute(..)" << endl;
theError.code = 4012;
setOperationErrorCodeAbort(4012); // Error code for "Cluster Failure"
DBUG_RETURN(-1);
}//if
/*
* Check that the completed transactions include this one. There
* could be another thread running asynchronously. Even in pure
* async case rollback is done synchronously.
*/
if (theListState != NotInList)
continue;
#ifdef VM_TRACE
unsigned anyway = 0;
for (unsigned i = 0; i < theNdb->theNoOfPreparedTransactions; i++)
anyway += theNdb->thePreparedTransactionsArray[i] == this;
for (unsigned i = 0; i < theNdb->theNoOfSentTransactions; i++)
anyway += theNdb->theSentTransactionsArray[i] == this;
for (unsigned i = 0; i < theNdb->theNoOfCompletedTransactions; i++)
anyway += theNdb->theCompletedTransactionsArray[i] == this;
if (anyway) {
theNdb->printState("execute %x", this);
abort();
}
#endif
if (theReturnStatus == ReturnFailure) {
DBUG_RETURN(-1);
}//if
break;
}
}
thePendingBlobOps = 0;
DBUG_RETURN(0);
}//NdbTransaction::execute()
/*****************************************************************************
void executeAsynchPrepare(ExecType aTypeOfExec,
NdbAsynchCallback callBack,
void* anyObject,
CommitType aTypeOfCommit);
Return Value: No return value
Parameters : aTypeOfExec: Type of execute.
anyObject: An object provided in the callback method
callBack: The callback method
aTypeOfCommit: What to do when read/updated/deleted records
are missing or inserted records already exist.
Remark: Prepare a part of a transaction in an asynchronous manner.
*****************************************************************************/
void
NdbTransaction::executeAsynchPrepare(NdbTransaction::ExecType aTypeOfExec,
NdbAsynchCallback aCallback,
void* anyObject,
NdbOperation::AbortOption abortOption)
{
DBUG_ENTER("NdbTransaction::executeAsynchPrepare");
DBUG_PRINT("enter", ("aTypeOfExec: %d, aCallback: 0x%lx, anyObject: Ox%lx",
aTypeOfExec, (long) aCallback, (long) anyObject));
/**
* Reset error.code on execute
*/
if (theError.code != 0)
DBUG_PRINT("enter", ("Resetting error %d on execute", theError.code));
theError.code = 0;
NdbScanOperation* tcOp = m_theFirstScanOperation;
if (tcOp != 0){
// Execute any cursor operations
while (tcOp != NULL) {
int tReturnCode;
tReturnCode = tcOp->executeCursor(theDBnode);
if (tReturnCode == -1) {
DBUG_VOID_RETURN;
}//if
tcOp = (NdbScanOperation*)tcOp->next();
} // while
m_theLastScanOperation->next(m_firstExecutedScanOp);
m_firstExecutedScanOp = m_theFirstScanOperation;
// Discard cursor operations, since these are also
// in the complete operations list we do not need
// to release them.
m_theFirstScanOperation = m_theLastScanOperation = NULL;
}
bool tTransactionIsStarted = theTransactionIsStarted;
NdbOperation* tLastOp = theLastOpInList;
Ndb* tNdb = theNdb;
CommitStatusType tCommitStatus = theCommitStatus;
Uint32 tnoOfPreparedTransactions = tNdb->theNoOfPreparedTransactions;
theReturnStatus = ReturnSuccess;
theCallbackFunction = aCallback;
theCallbackObject = anyObject;
m_waitForReply = true;
tNdb->thePreparedTransactionsArray[tnoOfPreparedTransactions] = this;
theTransArrayIndex = tnoOfPreparedTransactions;
theListState = InPreparedList;
tNdb->theNoOfPreparedTransactions = tnoOfPreparedTransactions + 1;
if ((tCommitStatus != Started) ||
(aTypeOfExec == Rollback)) {
/*****************************************************************************
* Rollback have been ordered on a started transaction. Call rollback.
* Could also be state problem or previous problem which leads to the
* same action.
****************************************************************************/
if (aTypeOfExec == Rollback) {
if (theTransactionIsStarted == false || theSimpleState) {
theCommitStatus = Aborted;
theSendStatus = sendCompleted;
} else {
theSendStatus = sendABORT;
}
} else {
theSendStatus = sendABORTfail;
}//if
if (theCommitStatus == Aborted){
DBUG_PRINT("exit", ("theCommitStatus: Aborted"));
setErrorCode(4350);
}
DBUG_VOID_RETURN;
}//if
if (tTransactionIsStarted == true) {
if (tLastOp != NULL) {
if (aTypeOfExec == Commit) {
/*****************************************************************************
* Set commit indicator on last operation when commit has been ordered
* and also a number of operations.
******************************************************************************/
tLastOp->theCommitIndicator = 1;
}//if
} else {
if (aTypeOfExec == Commit && !theSimpleState) {
/**********************************************************************
* A Transaction have been started and no more operations exist.
* We will use the commit method.
*********************************************************************/
theSendStatus = sendCOMMITstate;
DBUG_VOID_RETURN;
} else {
/**********************************************************************
* We need to put it into the array of completed transactions to
* ensure that we report the completion in a proper way.
* We cannot do this here since that would endanger the completed
* transaction array since that is also updated from the receiver
* thread and thus we need to do it under mutex lock and thus we
* set the sendStatus to ensure that the send method will
* put it into the completed array.
**********************************************************************/
theSendStatus = sendCompleted;
DBUG_VOID_RETURN; // No Commit with no operations is OK
}//if
}//if
} else if (tTransactionIsStarted == false) {
NdbOperation* tFirstOp = theFirstOpInList;
if (tLastOp != NULL) {
tFirstOp->setStartIndicator();
if (aTypeOfExec == Commit) {
tLastOp->theCommitIndicator = 1;
}//if
} else {
/***********************************************************************
* No operations are defined and we have not started yet.
* Simply return OK. Set commit status if Commit.
***********************************************************************/
if (aTypeOfExec == Commit) {
theCommitStatus = Committed;
}//if
/***********************************************************************
* We need to put it into the array of completed transactions to
* ensure that we report the completion in a proper way. We
* cannot do this here since that would endanger the completed
* transaction array since that is also updated from the
* receiver thread and thus we need to do it under mutex lock
* and thus we set the sendStatus to ensure that the send method
* will put it into the completed array.
***********************************************************************/
theSendStatus = sendCompleted;
DBUG_VOID_RETURN;
}//if
}
NdbOperation* tOp = theFirstOpInList;
theCompletionStatus = NotCompleted;
while (tOp) {
int tReturnCode;
NdbOperation* tNextOp = tOp->next();
tReturnCode = tOp->prepareSend(theTCConPtr, theTransactionId, abortOption);
if (tReturnCode == -1) {
theSendStatus = sendABORTfail;
DBUG_VOID_RETURN;
}//if
/*************************************************************************
* Now that we have successfully prepared the send of this operation we
* move it to the list of executing operations and remove it from the
* list of defined operations.
************************************************************************/
tOp = tNextOp;
}
NdbOperation* tLastOpInList = theLastOpInList;
NdbOperation* tFirstOpInList = theFirstOpInList;
theFirstOpInList = NULL;
theLastOpInList = NULL;
theFirstExecOpInList = tFirstOpInList;
theLastExecOpInList = tLastOpInList;
theCompletionStatus = CompletedSuccess;
theNoOfOpSent = 0;
theNoOfOpCompleted = 0;
theSendStatus = sendOperations;
NdbNodeBitmask::clear(m_db_nodes);
NdbNodeBitmask::clear(m_failed_db_nodes);
DBUG_VOID_RETURN;
}//NdbTransaction::executeAsynchPrepare()
void
NdbTransaction::executeAsynch(ExecType aTypeOfExec,
NdbAsynchCallback aCallback,
void* anyObject,
NdbOperation::AbortOption abortOption,
int forceSend)
{
executeAsynchPrepare(aTypeOfExec, aCallback, anyObject, abortOption);
theNdb->sendPreparedTransactions(forceSend);
}
void NdbTransaction::close()
{
theNdb->closeTransaction(this);
}
int NdbTransaction::refresh(){
return sendTC_HBREP();
}
/*****************************************************************************
int sendTC_HBREP();
Return Value: No return value.
Parameters : None.
Remark: Order NDB to refresh the timeout counter of the transaction.
******************************************************************************/
int
NdbTransaction::sendTC_HBREP() // Send a TC_HBREP signal;
{
NdbApiSignal* tSignal;
Ndb* tNdb = theNdb;
Uint32 tTransId1, tTransId2;
tSignal = tNdb->getSignal();
if (tSignal == NULL) {
return -1;
}
if (tSignal->setSignal(GSN_TC_HBREP) == -1) {
return -1;
}
TcHbRep * const tcHbRep = CAST_PTR(TcHbRep, tSignal->getDataPtrSend());
tcHbRep->apiConnectPtr = theTCConPtr;
tTransId1 = (Uint32) theTransactionId;
tTransId2 = (Uint32) (theTransactionId >> 32);
tcHbRep->transId1 = tTransId1;
tcHbRep->transId2 = tTransId2;
TransporterFacade *tp = theNdb->theImpl->m_transporter_facade;
tp->lock_mutex();
const int res = tp->sendSignal(tSignal,theDBnode);
tp->unlock_mutex();
tNdb->releaseSignal(tSignal);
if (res == -1){
return -1;
}
return 0;
}//NdbTransaction::sendTC_HBREP()
/*****************************************************************************
int doSend();
Return Value: Return 0 : send was successful.
Return -1: In all other case.
Remark: Send all operations belonging to this connection.
The caller of this method has the responsibility to remove the
object from the prepared transactions array on the Ndb-object.
*****************************************************************************/
int
NdbTransaction::doSend()
{
DBUG_ENTER("NdbTransaction::doSend");
/*
This method assumes that at least one operation have been defined. This
is ensured by the caller of this routine (=execute).
*/
switch(theSendStatus){
case sendOperations: {
NdbOperation * tOp = theFirstExecOpInList;
do {
NdbOperation* tNextOp = tOp->next();
const Uint32 lastFlag = ((tNextOp == NULL) ? 1 : 0);
const int tReturnCode = tOp->doSend(theDBnode, lastFlag);
if (tReturnCode == -1) {
theReturnStatus = ReturnFailure;
break;
}//if
tOp = tNextOp;
} while (tOp != NULL);
Ndb* tNdb = theNdb;
theSendStatus = sendTC_OP;
theTransactionIsStarted = true;
tNdb->insert_sent_list(this);
DBUG_RETURN(0);
}//case
case sendABORT:
case sendABORTfail:{
/***********************************************************************
* Rollback have been ordered on a not started transaction.
* Simply return OK and set abort status.
***********************************************************************/
if (theSendStatus == sendABORTfail) {
theReturnStatus = ReturnFailure;
}//if
if (sendROLLBACK() == 0) {
DBUG_RETURN(0);
}//if
break;
}//case
case sendCOMMITstate:
if (sendCOMMIT() == 0) {
DBUG_RETURN(0);
}//if
break;
case sendCompleted:
theNdb->insert_completed_list(this);
DBUG_RETURN(0);
default:
ndbout << "Inconsistent theSendStatus = "
<< (Uint32) theSendStatus << endl;
abort();
break;
}//switch
setOperationErrorCodeAbort(4002);
theReleaseOnClose = true;
theTransactionIsStarted = false;
theCommitStatus = Aborted;
DBUG_RETURN(-1);
}//NdbTransaction::doSend()
/**************************************************************************
int sendROLLBACK();
Return Value: Return -1 if send unsuccessful.
Parameters : None.
Remark: Order NDB to rollback the transaction.
**************************************************************************/
int
NdbTransaction::sendROLLBACK() // Send a TCROLLBACKREQ signal;
{
Ndb* tNdb = theNdb;
if ((theTransactionIsStarted == true) &&
(theCommitStatus != Committed) &&
(theCommitStatus != Aborted)) {
/**************************************************************************
* The user did not perform any rollback but simply closed the
* transaction. We must rollback Ndb since Ndb have been contacted.
*************************************************************************/
NdbApiSignal tSignal(tNdb->theMyRef);
Uint32 tTransId1, tTransId2;
TransporterFacade *tp = theNdb->theImpl->m_transporter_facade;
int tReturnCode;
tTransId1 = (Uint32) theTransactionId;
tTransId2 = (Uint32) (theTransactionId >> 32);
tSignal.setSignal(GSN_TCROLLBACKREQ);
tSignal.setData(theTCConPtr, 1);
tSignal.setData(tTransId1, 2);
tSignal.setData(tTransId2, 3);
tReturnCode = tp->sendSignal(&tSignal,theDBnode);
if (tReturnCode != -1) {
theSendStatus = sendTC_ROLLBACK;
tNdb->insert_sent_list(this);
return 0;
}//if
/*********************************************************************
* It was not possible to abort the transaction towards the NDB kernel
* and thus we put it into the array of completed transactions that
* are ready for reporting to the application.
*********************************************************************/
return -1;
} else {
/*
It is not necessary to abort the transaction towards the NDB kernel and
thus we put it into the array of completed transactions that are ready
for reporting to the application.
*/
theSendStatus = sendCompleted;
tNdb->insert_completed_list(this);
return 0;
;
}//if
}//NdbTransaction::sendROLLBACK()
/***************************************************************************
int sendCOMMIT();
Return Value: Return 0 : send was successful.
Return -1: In all other case.
Parameters : None.
Remark: Order NDB to commit the transaction.
***************************************************************************/
int
NdbTransaction::sendCOMMIT() // Send a TC_COMMITREQ signal;
{
NdbApiSignal tSignal(theNdb->theMyRef);
Uint32 tTransId1, tTransId2;
TransporterFacade *tp = theNdb->theImpl->m_transporter_facade;
int tReturnCode;
tTransId1 = (Uint32) theTransactionId;
tTransId2 = (Uint32) (theTransactionId >> 32);
tSignal.setSignal(GSN_TC_COMMITREQ);
tSignal.setData(theTCConPtr, 1);
tSignal.setData(tTransId1, 2);
tSignal.setData(tTransId2, 3);
tReturnCode = tp->sendSignal(&tSignal,theDBnode);
if (tReturnCode != -1) {
theSendStatus = sendTC_COMMIT;
theNdb->insert_sent_list(this);
return 0;
} else {
return -1;
}//if
}//NdbTransaction::sendCOMMIT()
/******************************************************************************
void release();
Remark: Release all operations.
******************************************************************************/
void
NdbTransaction::release(){
releaseOperations();
if ( (theTransactionIsStarted == true) &&
((theCommitStatus != Committed) &&
(theCommitStatus != Aborted))) {
/************************************************************************
* The user did not perform any rollback but simply closed the
* transaction. We must rollback Ndb since Ndb have been contacted.
************************************************************************/
if (!theSimpleState)
{
execute(Rollback);
}
}//if
theMagicNumber = 0xFE11DC;
theInUseState = false;
#ifdef VM_TRACE
if (theListState != NotInList) {
theNdb->printState("release %x", this);
abort();
}
#endif
}//NdbTransaction::release()
void
NdbTransaction::releaseOps(NdbOperation* tOp){
while (tOp != NULL) {
NdbOperation* tmp = tOp;
tOp->release();
tOp = tOp->next();
theNdb->releaseOperation(tmp);
}//while
}
/******************************************************************************
void releaseOperations();
Remark: Release all operations.
******************************************************************************/
void
NdbTransaction::releaseOperations()
{
// Release any open scans
releaseScanOperations(m_theFirstScanOperation);
releaseScanOperations(m_firstExecutedScanOp);
releaseOps(theCompletedFirstOp);
releaseOps(theFirstOpInList);
releaseOps(theFirstExecOpInList);
theCompletedFirstOp = NULL;
theCompletedLastOp = NULL;
theFirstOpInList = NULL;
theFirstExecOpInList = NULL;
theLastOpInList = NULL;
theLastExecOpInList = NULL;
theScanningOp = NULL;
m_theFirstScanOperation = NULL;
m_theLastScanOperation = NULL;
m_firstExecutedScanOp = NULL;
}//NdbTransaction::releaseOperations()
void
NdbTransaction::releaseCompletedOperations()
{
releaseOps(theCompletedFirstOp);
theCompletedFirstOp = NULL;
theCompletedLastOp = NULL;
}//NdbTransaction::releaseOperations()
/******************************************************************************
void releaseScanOperations();
Remark: Release all cursor operations.
(NdbScanOperation and NdbIndexOperation)
******************************************************************************/
void
NdbTransaction::releaseScanOperations(NdbIndexScanOperation* cursorOp)
{
while(cursorOp != 0){
NdbIndexScanOperation* next = (NdbIndexScanOperation*)cursorOp->next();
cursorOp->release();
theNdb->releaseScanOperation(cursorOp);
cursorOp = next;
}
}//NdbTransaction::releaseScanOperations()
/*****************************************************************************
void releaseScanOperation();
Remark: Release scan op when hupp'ed trans closed (save memory)
******************************************************************************/
void
NdbTransaction::releaseExecutedScanOperation(NdbIndexScanOperation* cursorOp)
{
DBUG_ENTER("NdbTransaction::releaseExecutedScanOperation");
DBUG_PRINT("enter", ("this: 0x%lx op: 0x%lx", (long) this, (long) cursorOp));
releaseScanOperation(&m_firstExecutedScanOp, 0, cursorOp);
DBUG_VOID_RETURN;
}//NdbTransaction::releaseExecutedScanOperation()
bool
NdbTransaction::releaseScanOperation(NdbIndexScanOperation** listhead,
NdbIndexScanOperation** listtail,
NdbIndexScanOperation* op)
{
if (* listhead == op)
{
* listhead = (NdbIndexScanOperation*)op->theNext;
if (listtail && *listtail == op)
{
assert(* listhead == 0);
* listtail = 0;
}
}
else
{
NdbIndexScanOperation* tmp = * listhead;
while (tmp != NULL)
{
if (tmp->theNext == op)
{
tmp->theNext = (NdbIndexScanOperation*)op->theNext;
if (listtail && *listtail == op)
{
assert(op->theNext == 0);
*listtail = tmp;
}
break;
}
tmp = (NdbIndexScanOperation*)tmp->theNext;
}
if (tmp == NULL)
op = NULL;
}
if (op != NULL)
{
op->release();
theNdb->releaseScanOperation(op);
return true;
}
return false;
}
/*****************************************************************************
NdbOperation* getNdbOperation(const char* aTableName);
Return Value Return a pointer to a NdbOperation object if getNdbOperation
was succesful.
Return NULL : In all other case.
Parameters: aTableName : Name of the database table.
Remark: Get an operation from NdbOperation idlelist and get the
NdbTransaction object
who was fetch by startTransaction pointing to this operation
getOperation will set the theTableId in the NdbOperation object.
synchronous
******************************************************************************/
NdbOperation*
NdbTransaction::getNdbOperation(const char* aTableName)
{
if (theCommitStatus == Started){
NdbTableImpl* table = theNdb->theDictionary->getTable(aTableName);
if (table != 0){
return getNdbOperation(table);
} else {
setErrorCode(theNdb->theDictionary->getNdbError().code);
return NULL;
}//if
}
setOperationErrorCodeAbort(4114);
return NULL;
}//NdbTransaction::getNdbOperation()
/*****************************************************************************
NdbOperation* getNdbOperation(int aTableId);
Return Value Return a pointer to a NdbOperation object if getNdbOperation
was succesful.
Return NULL: In all other case.
Parameters: tableId : Id of the database table beeing deleted.
Remark: Get an operation from NdbOperation object idlelist and
get the NdbTransaction object who was fetch by
startTransaction pointing to this operation
getOperation will set the theTableId in the NdbOperation
object, synchronous.
*****************************************************************************/
NdbOperation*
NdbTransaction::getNdbOperation(const NdbTableImpl * tab, NdbOperation* aNextOp)
{
NdbOperation* tOp;
if (theScanningOp != NULL){
setErrorCode(4607);
return NULL;
}
tOp = theNdb->getOperation();
if (tOp == NULL)
goto getNdbOp_error1;
if (aNextOp == NULL) {
if (theLastOpInList != NULL) {
theLastOpInList->next(tOp);
theLastOpInList = tOp;
} else {
theLastOpInList = tOp;
theFirstOpInList = tOp;
}//if
tOp->next(NULL);
} else {
// add before the given op
if (theFirstOpInList == aNextOp) {
theFirstOpInList = tOp;
} else {
NdbOperation* aLoopOp = theFirstOpInList;
while (aLoopOp != NULL && aLoopOp->next() != aNextOp)
aLoopOp = aLoopOp->next();
assert(aLoopOp != NULL);
aLoopOp->next(tOp);
}
tOp->next(aNextOp);
}
if (tOp->init(tab, this) != -1) {
return tOp;
} else {
theNdb->releaseOperation(tOp);
}//if
return NULL;
getNdbOp_error1:
setOperationErrorCodeAbort(4000);
return NULL;
}//NdbTransaction::getNdbOperation()
NdbOperation* NdbTransaction::getNdbOperation(const NdbDictionary::Table * table)
{
if (table)
return getNdbOperation(& NdbTableImpl::getImpl(*table));
else
return NULL;
}//NdbTransaction::getNdbOperation()
// NdbScanOperation
/*****************************************************************************
NdbScanOperation* getNdbScanOperation(const char* aTableName);
Return Value Return a pointer to a NdbScanOperation object if getNdbScanOperation was succesful.
Return NULL : In all other case.
Parameters: aTableName : Name of the database table.
Remark: Get an operation from NdbScanOperation idlelist and get the NdbTransaction object
who was fetch by startTransaction pointing to this operation
getOperation will set the theTableId in the NdbOperation object.synchronous
******************************************************************************/
NdbScanOperation*
NdbTransaction::getNdbScanOperation(const char* aTableName)
{
if (theCommitStatus == Started){
NdbTableImpl* tab = theNdb->theDictionary->getTable(aTableName);
if (tab != 0){
return getNdbScanOperation(tab);
} else {
setOperationErrorCodeAbort(theNdb->theDictionary->m_error.code);
return NULL;
}//if
}
setOperationErrorCodeAbort(4114);
return NULL;
}//NdbTransaction::getNdbScanOperation()
/*****************************************************************************
NdbScanOperation* getNdbIndexScanOperation(const char* anIndexName, const char* aTableName);
Return Value Return a pointer to a NdbIndexScanOperation object if getNdbIndexScanOperation was succesful.
Return NULL : In all other case.
Parameters: anIndexName : Name of the index to use.
aTableName : Name of the database table.
Remark: Get an operation from NdbIndexScanOperation idlelist and get the NdbTransaction object
who was fetch by startTransaction pointing to this operation
getOperation will set the theTableId in the NdbIndexScanOperation object.synchronous
******************************************************************************/
NdbIndexScanOperation*
NdbTransaction::getNdbIndexScanOperation(const char* anIndexName,
const char* aTableName)
{
NdbIndexImpl* index =
theNdb->theDictionary->getIndex(anIndexName, aTableName);
if (index == 0)
{
setOperationErrorCodeAbort(theNdb->theDictionary->getNdbError().code);
return 0;
}
NdbTableImpl* table = theNdb->theDictionary->getTable(aTableName);
if (table == 0)
{
setOperationErrorCodeAbort(theNdb->theDictionary->getNdbError().code);
return 0;
}
return getNdbIndexScanOperation(index, table);
}
NdbIndexScanOperation*
NdbTransaction::getNdbIndexScanOperation(const NdbIndexImpl* index,
const NdbTableImpl* table)
{
if (theCommitStatus == Started){
const NdbTableImpl * indexTable = index->getIndexTable();
if (indexTable != 0){
NdbIndexScanOperation* tOp = getNdbScanOperation(indexTable);
if(tOp)
{
tOp->m_currentTable = table;
// Mark that this really an NdbIndexScanOperation
tOp->m_type = NdbOperation::OrderedIndexScan;
}
return tOp;
} else {
setOperationErrorCodeAbort(4271);
return NULL;
}//if
}
setOperationErrorCodeAbort(4114);
return NULL;
}//NdbTransaction::getNdbIndexScanOperation()
NdbIndexScanOperation*
NdbTransaction::getNdbIndexScanOperation(const NdbDictionary::Index * index)
{
if (index)
{
const NdbDictionary::Table *table=
theNdb->theDictionary->getTable(index->getTable());
if (table)
return getNdbIndexScanOperation(index, table);
setOperationErrorCodeAbort(theNdb->theDictionary->getNdbError().code);
return NULL;
}
setOperationErrorCodeAbort(4271);
return NULL;
}
NdbIndexScanOperation*
NdbTransaction::getNdbIndexScanOperation(const NdbDictionary::Index * index,
const NdbDictionary::Table * table)
{
if (index && table)
return getNdbIndexScanOperation(& NdbIndexImpl::getImpl(*index),
& NdbTableImpl::getImpl(*table));
setOperationErrorCodeAbort(4271);
return NULL;
}//NdbTransaction::getNdbIndexScanOperation()
/*****************************************************************************
NdbScanOperation* getNdbScanOperation(int aTableId);
Return Value Return a pointer to a NdbScanOperation object if getNdbScanOperation was succesful.
Return NULL: In all other case.
Parameters: tableId : Id of the database table beeing deleted.
Remark: Get an operation from NdbScanOperation object idlelist and get the NdbTransaction
object who was fetch by startTransaction pointing to this operation
getOperation will set the theTableId in the NdbScanOperation object, synchronous.
*****************************************************************************/
NdbIndexScanOperation*
NdbTransaction::getNdbScanOperation(const NdbTableImpl * tab)
{
NdbIndexScanOperation* tOp;
tOp = theNdb->getScanOperation();
if (tOp == NULL)
goto getNdbOp_error1;
if (tOp->init(tab, this) != -1) {
define_scan_op(tOp);
// Mark that this NdbIndexScanOperation is used as NdbScanOperation
tOp->m_type = NdbOperation::TableScan;
return tOp;
} else {
theNdb->releaseScanOperation(tOp);
}//if
return NULL;
getNdbOp_error1:
setOperationErrorCodeAbort(4000);
return NULL;
}//NdbTransaction::getNdbScanOperation()
void
NdbTransaction::remove_list(NdbOperation*& list, NdbOperation* op){
NdbOperation* tmp= list;
if(tmp == op)
list = op->next();
else {
while(tmp && tmp->next() != op) tmp = tmp->next();
if(tmp)
tmp->next(op->next());
}
op->next(NULL);
}
void
NdbTransaction::define_scan_op(NdbIndexScanOperation * tOp){
// Link scan operation into list of cursor operations
if (m_theLastScanOperation == NULL)
m_theFirstScanOperation = m_theLastScanOperation = tOp;
else {
m_theLastScanOperation->next(tOp);
m_theLastScanOperation = tOp;
}
tOp->next(NULL);
}
NdbScanOperation*
NdbTransaction::getNdbScanOperation(const NdbDictionary::Table * table)
{
if (table)
return getNdbScanOperation(& NdbTableImpl::getImpl(*table));
else
return NULL;
}//NdbTransaction::getNdbScanOperation()
// IndexOperation
/*****************************************************************************
NdbIndexOperation* getNdbIndexOperation(const char* anIndexName,
const char* aTableName);
Return Value Return a pointer to a NdbOperation object if getNdbIndexOperation was succesful.
Return NULL : In all other case.
Parameters: aTableName : Name of the database table.
Remark: Get an operation from NdbIndexOperation idlelist and get the NdbTransaction object
who was fetch by startTransaction pointing to this operation
getOperation will set the theTableId in the NdbIndexOperation object.synchronous
******************************************************************************/
NdbIndexOperation*
NdbTransaction::getNdbIndexOperation(const char* anIndexName,
const char* aTableName)
{
if (theCommitStatus == Started) {
NdbTableImpl * table = theNdb->theDictionary->getTable(aTableName);
NdbIndexImpl * index;
if (table == 0)
{
setOperationErrorCodeAbort(theNdb->theDictionary->getNdbError().code);
return NULL;
}
if (table->m_frm.get_data())
{
// This unique index is defined from SQL level
static const char* uniqueSuffix= "$unique";
BaseString uniqueIndexName(anIndexName);
uniqueIndexName.append(uniqueSuffix);
index = theNdb->theDictionary->getIndex(uniqueIndexName.c_str(),
aTableName);
}
else
index = theNdb->theDictionary->getIndex(anIndexName,
aTableName);
if(table != 0 && index != 0){
return getNdbIndexOperation(index, table);
}
if(index == 0){
setOperationErrorCodeAbort(4243);
return NULL;
}
setOperationErrorCodeAbort(4243);
return NULL;
}
setOperationErrorCodeAbort(4114);
return 0;
}//NdbTransaction::getNdbIndexOperation()
/*****************************************************************************
NdbIndexOperation* getNdbIndexOperation(int anIndexId, int aTableId);
Return Value Return a pointer to a NdbIndexOperation object if getNdbIndexOperation was succesful.
Return NULL: In all other case.
Parameters: tableId : Id of the database table beeing deleted.
Remark: Get an operation from NdbIndexOperation object idlelist and get the NdbTransaction
object who was fetch by startTransaction pointing to this operation
getOperation will set the theTableId in the NdbIndexOperation object, synchronous.
*****************************************************************************/
NdbIndexOperation*
NdbTransaction::getNdbIndexOperation(const NdbIndexImpl * anIndex,
const NdbTableImpl * aTable,
NdbOperation* aNextOp)
{
NdbIndexOperation* tOp;
tOp = theNdb->getIndexOperation();
if (tOp == NULL)
goto getNdbOp_error1;
if (aNextOp == NULL) {
if (theLastOpInList != NULL) {
theLastOpInList->next(tOp);
theLastOpInList = tOp;
} else {
theLastOpInList = tOp;
theFirstOpInList = tOp;
}//if
tOp->next(NULL);
} else {
// add before the given op
if (theFirstOpInList == aNextOp) {
theFirstOpInList = tOp;
} else {
NdbOperation* aLoopOp = theFirstOpInList;
while (aLoopOp != NULL && aLoopOp->next() != aNextOp)
aLoopOp = aLoopOp->next();
assert(aLoopOp != NULL);
aLoopOp->next(tOp);
}
tOp->next(aNextOp);
}
if (tOp->indxInit(anIndex, aTable, this)!= -1) {
return tOp;
} else {
theNdb->releaseOperation(tOp);
}//if
return NULL;
getNdbOp_error1:
setOperationErrorCodeAbort(4000);
return NULL;
}//NdbTransaction::getNdbIndexOperation()
NdbIndexOperation*
NdbTransaction::getNdbIndexOperation(const NdbDictionary::Index * index)
{
if (index)
{
const NdbDictionary::Table *table=
theNdb->theDictionary->getTable(index->getTable());
if (table)
return getNdbIndexOperation(index, table);
setOperationErrorCodeAbort(theNdb->theDictionary->getNdbError().code);
return NULL;
}
setOperationErrorCodeAbort(4271);
return NULL;
}
NdbIndexOperation*
NdbTransaction::getNdbIndexOperation(const NdbDictionary::Index * index,
const NdbDictionary::Table * table)
{
if (index && table)
return getNdbIndexOperation(& NdbIndexImpl::getImpl(*index),
& NdbTableImpl::getImpl(*table));
setOperationErrorCodeAbort(4271);
return NULL;
}//NdbTransaction::getNdbIndexOperation()
/*******************************************************************************
int receiveDIHNDBTAMPER(NdbApiSignal* aSignal)
Return Value: Return 0 : receiveDIHNDBTAMPER was successful.
Return -1: In all other case.
Parameters: aSignal: The signal object pointer.
Remark: Sets theRestartGCI in the NDB object.
*******************************************************************************/
int
NdbTransaction::receiveDIHNDBTAMPER(NdbApiSignal* aSignal)
{
if (theStatus != Connecting) {
return -1;
} else {
theNdb->RestartGCI((Uint32)aSignal->readData(2));
theStatus = Connected;
}//if
return 0;
}//NdbTransaction::receiveDIHNDBTAMPER()
/*******************************************************************************
int receiveTCSEIZECONF(NdbApiSignal* aSignal);
Return Value: Return 0 : receiveTCSEIZECONF was successful.
Return -1: In all other case.
Parameters: aSignal: The signal object pointer.
Remark: Sets TC Connect pointer at reception of TCSEIZECONF.
*******************************************************************************/
int
NdbTransaction::receiveTCSEIZECONF(NdbApiSignal* aSignal)
{
if (theStatus != Connecting)
{
return -1;
} else
{
theTCConPtr = (Uint32)aSignal->readData(2);
theStatus = Connected;
}
return 0;
}//NdbTransaction::receiveTCSEIZECONF()
/*******************************************************************************
int receiveTCSEIZEREF(NdbApiSignal* aSignal);
Return Value: Return 0 : receiveTCSEIZEREF was successful.
Return -1: In all other case.
Parameters: aSignal: The signal object pointer.
Remark: Sets TC Connect pointer.
*******************************************************************************/
int
NdbTransaction::receiveTCSEIZEREF(NdbApiSignal* aSignal)
{
DBUG_ENTER("NdbTransaction::receiveTCSEIZEREF");
if (theStatus != Connecting)
{
DBUG_RETURN(-1);
} else
{
theStatus = ConnectFailure;
theNdb->theError.code = aSignal->readData(2);
DBUG_PRINT("info",("error code %d, %s",
theNdb->getNdbError().code,
theNdb->getNdbError().message));
DBUG_RETURN(0);
}
}//NdbTransaction::receiveTCSEIZEREF()
/*******************************************************************************
int receiveTCRELEASECONF(NdbApiSignal* aSignal);
Return Value: Return 0 : receiveTCRELEASECONF was successful.
Return -1: In all other case.
Parameters: aSignal: The signal object pointer.
Remark: DisConnect TC Connect pointer to NDBAPI.
*******************************************************************************/
int
NdbTransaction::receiveTCRELEASECONF(NdbApiSignal* aSignal)
{
if (theStatus != DisConnecting)
{
return -1;
} else
{
theStatus = NotConnected;
}
return 0;
}//NdbTransaction::receiveTCRELEASECONF()
/*******************************************************************************
int receiveTCRELEASEREF(NdbApiSignal* aSignal);
Return Value: Return 0 : receiveTCRELEASEREF was successful.
Return -1: In all other case.
Parameters: aSignal: The signal object pointer.
Remark: DisConnect TC Connect pointer to NDBAPI Failure.
*******************************************************************************/
int
NdbTransaction::receiveTCRELEASEREF(NdbApiSignal* aSignal)
{
if (theStatus != DisConnecting) {
return -1;
} else {
theStatus = ConnectFailure;
theNdb->theError.code = aSignal->readData(2);
return 0;
}//if
}//NdbTransaction::receiveTCRELEASEREF()
/******************************************************************************
int receiveTC_COMMITCONF(NdbApiSignal* aSignal);
Return Value: Return 0 : receiveTC_COMMITCONF was successful.
Return -1: In all other case.
Parameters: aSignal: The signal object pointer.
Remark:
******************************************************************************/
int
NdbTransaction::receiveTC_COMMITCONF(const TcCommitConf * commitConf)
{
if(checkState_TransId(&commitConf->transId1)){
theCommitStatus = Committed;
theCompletionStatus = CompletedSuccess;
theGlobalCheckpointId = commitConf->gci;
// theGlobalCheckpointId == 0 if NoOp transaction
if (theGlobalCheckpointId)
*p_latest_trans_gci = theGlobalCheckpointId;
return 0;
} else {
#ifdef NDB_NO_DROPPED_SIGNAL
abort();
#endif
}
return -1;
}//NdbTransaction::receiveTC_COMMITCONF()
/******************************************************************************
int receiveTC_COMMITREF(NdbApiSignal* aSignal);
Return Value: Return 0 : receiveTC_COMMITREF was successful.
Return -1: In all other case.
Parameters: aSignal: The signal object pointer.
Remark:
******************************************************************************/
int
NdbTransaction::receiveTC_COMMITREF(NdbApiSignal* aSignal)
{
const TcCommitRef * ref = CAST_CONSTPTR(TcCommitRef, aSignal->getDataPtr());
if(checkState_TransId(&ref->transId1)){
setOperationErrorCodeAbort(ref->errorCode);
theCommitStatus = Aborted;
theCompletionStatus = CompletedFailure;
theReturnStatus = ReturnFailure;
return 0;
} else {
#ifdef NDB_NO_DROPPED_SIGNAL
abort();
#endif
}
return -1;
}//NdbTransaction::receiveTC_COMMITREF()
/******************************************************************************
int receiveTCROLLBACKCONF(NdbApiSignal* aSignal);
Return Value: Return 0 : receiveTCROLLBACKCONF was successful.
Return -1: In all other case.
Parameters: aSignal: The signal object pointer.
Remark:
******************************************************************************/
int
NdbTransaction::receiveTCROLLBACKCONF(NdbApiSignal* aSignal)
{
if(checkState_TransId(aSignal->getDataPtr() + 1)){
theCommitStatus = Aborted;
theCompletionStatus = CompletedSuccess;
return 0;
} else {
#ifdef NDB_NO_DROPPED_SIGNAL
abort();
#endif
}
return -1;
}//NdbTransaction::receiveTCROLLBACKCONF()
/*******************************************************************************
int receiveTCROLLBACKREF(NdbApiSignal* aSignal);
Return Value: Return 0 : receiveTCROLLBACKREF was successful.
Return -1: In all other case.
Parameters: aSignal: The signal object pointer.
Remark:
*******************************************************************************/
int
NdbTransaction::receiveTCROLLBACKREF(NdbApiSignal* aSignal)
{
if(checkState_TransId(aSignal->getDataPtr() + 1)){
setOperationErrorCodeAbort(aSignal->readData(4));
theCommitStatus = Aborted;
theCompletionStatus = CompletedFailure;
theReturnStatus = ReturnFailure;
return 0;
} else {
#ifdef NDB_NO_DROPPED_SIGNAL
abort();
#endif
}
return -1;
}//NdbTransaction::receiveTCROLLBACKREF()
/*****************************************************************************
int receiveTCROLLBACKREP( NdbApiSignal* aSignal)
Return Value: Return 0 : send was succesful.
Return -1: In all other case.
Parameters: aSignal: the signal object that contains the
TCROLLBACKREP signal from TC.
Remark: Handles the reception of the ROLLBACKREP signal.
*****************************************************************************/
int
NdbTransaction::receiveTCROLLBACKREP( NdbApiSignal* aSignal)
{
/****************************************************************************
Check that we are expecting signals from this transaction and that it doesn't
belong to a transaction already completed. Simply ignore messages from other
transactions.
****************************************************************************/
if(checkState_TransId(aSignal->getDataPtr() + 1)){
theError.code = aSignal->readData(4);// Override any previous errors
/**********************************************************************/
/* A serious error has occured. This could be due to deadlock or */
/* lack of resources or simply a programming error in NDB. This */
/* transaction will be aborted. Actually it has already been */
/* and we only need to report completion and return with the */
/* error code to the application. */
/**********************************************************************/
theCompletionStatus = CompletedFailure;
theCommitStatus = Aborted;
theReturnStatus = ReturnFailure;
return 0;
} else {
#ifdef NDB_NO_DROPPED_SIGNAL
abort();
#endif
}
return -1;
}//NdbTransaction::receiveTCROLLBACKREP()
/*******************************************************************************
int receiveTCKEYCONF(NdbApiSignal* aSignal, Uint32 long_short_ind);
Return Value: Return 0 : receiveTCKEYCONF was successful.
Return -1: In all other case.
Parameters: aSignal: The signal object pointer.
Remark:
*******************************************************************************/
int
NdbTransaction::receiveTCKEYCONF(const TcKeyConf * keyConf, Uint32 aDataLength)
{
NdbReceiver* tOp;
const Uint32 tTemp = keyConf->confInfo;
/***************************************************************************
Check that we are expecting signals from this transaction and that it
doesn't belong to a transaction already completed. Simply ignore messages
from other transactions.
***************************************************************************/
if(checkState_TransId(&keyConf->transId1)){
const Uint32 tNoOfOperations = TcKeyConf::getNoOfOperations(tTemp);
const Uint32 tCommitFlag = TcKeyConf::getCommitFlag(tTemp);
const Uint32* tPtr = (Uint32 *)&keyConf->operations[0];
Uint32 tNoComp = theNoOfOpCompleted;
for (Uint32 i = 0; i < tNoOfOperations ; i++) {
tOp = theNdb->void2rec(theNdb->int2void(*tPtr++));
const Uint32 tAttrInfoLen = *tPtr++;
if (tOp && tOp->checkMagicNumber()) {
Uint32 done = tOp->execTCOPCONF(tAttrInfoLen);
if(tAttrInfoLen > TcKeyConf::SimpleReadBit){
Uint32 node = tAttrInfoLen & (~TcKeyConf::SimpleReadBit);
NdbNodeBitmask::set(m_db_nodes, node);
if(NdbNodeBitmask::get(m_failed_db_nodes, node) && !done)
{
done = 1;
tOp->setErrorCode(4119);
theCompletionStatus = CompletedFailure;
theReturnStatus = NdbTransaction::ReturnFailure;
}
}
tNoComp += done;
} else {
return -1;
}//if
}//for
Uint32 tNoSent = theNoOfOpSent;
theNoOfOpCompleted = tNoComp;
Uint32 tGCI = keyConf->gci;
if (tCommitFlag == 1) {
theCommitStatus = Committed;
theGlobalCheckpointId = tGCI;
if (tGCI) // Read(dirty) only transaction doesnt get GCI
{
*p_latest_trans_gci = tGCI;
}
} else if ((tNoComp >= tNoSent) &&
(theLastExecOpInList->theCommitIndicator == 1)){
/**********************************************************************/
// We sent the transaction with Commit flag set and received a CONF with
// no Commit flag set. This is clearly an anomaly.
/**********************************************************************/
theError.code = 4011;
theCompletionStatus = CompletedFailure;
theReturnStatus = NdbTransaction::ReturnFailure;
theCommitStatus = Aborted;
return 0;
}//if
if (tNoComp >= tNoSent) {
return 0; // No more operations to wait for
}//if
// Not completed the reception yet.
} else {
#ifdef NDB_NO_DROPPED_SIGNAL
abort();
#endif
}
return -1;
}//NdbTransaction::receiveTCKEYCONF()
/*****************************************************************************
int receiveTCKEY_FAILCONF( NdbApiSignal* aSignal)
Return Value: Return 0 : receive was completed.
Return -1: In all other case.
Parameters: aSignal: the signal object that contains the
TCKEY_FAILCONF signal from TC.
Remark: Handles the reception of the TCKEY_FAILCONF signal.
*****************************************************************************/
int
NdbTransaction::receiveTCKEY_FAILCONF(const TcKeyFailConf * failConf)
{
NdbOperation* tOp;
/*
Check that we are expecting signals from this transaction and that it
doesn't belong to a transaction already completed. Simply ignore
messages from other transactions.
*/
if(checkState_TransId(&failConf->transId1)){
/*
A node failure of the TC node occured. The transaction has
been committed.
*/
theCommitStatus = Committed;
tOp = theFirstExecOpInList;
while (tOp != NULL) {
/*
* Check if the transaction expected read values...
* If it did some of them might have gotten lost even if we succeeded
* in committing the transaction.
*/
switch(tOp->theOperationType){
case NdbOperation::UpdateRequest:
case NdbOperation::InsertRequest:
case NdbOperation::DeleteRequest:
case NdbOperation::WriteRequest:
tOp = tOp->next();
break;
case NdbOperation::ReadRequest:
case NdbOperation::ReadExclusive:
case NdbOperation::OpenScanRequest:
case NdbOperation::OpenRangeScanRequest:
theCompletionStatus = CompletedFailure;
theReturnStatus = NdbTransaction::ReturnFailure;
setOperationErrorCodeAbort(4115);
tOp = NULL;
break;
case NdbOperation::NotDefined:
case NdbOperation::NotDefined2:
assert(false);
break;
}//if
}//while
theReleaseOnClose = true;
return 0;
} else {
#ifdef VM_TRACE
ndbout_c("Recevied TCKEY_FAILCONF wo/ operation");
#endif
}
return -1;
}//NdbTransaction::receiveTCKEY_FAILCONF()
/*************************************************************************
int receiveTCKEY_FAILREF( NdbApiSignal* aSignal)
Return Value: Return 0 : receive was completed.
Return -1: In all other case.
Parameters: aSignal: the signal object that contains the
TCKEY_FAILREF signal from TC.
Remark: Handles the reception of the TCKEY_FAILREF signal.
**************************************************************************/
int
NdbTransaction::receiveTCKEY_FAILREF(NdbApiSignal* aSignal)
{
/*
Check that we are expecting signals from this transaction and
that it doesn't belong to a transaction already
completed. Simply ignore messages from other transactions.
*/
if(checkState_TransId(aSignal->getDataPtr()+1)){
/*
We received an indication of that this transaction was aborted due to a
node failure.
*/
if (theSendStatus == NdbTransaction::sendTC_ROLLBACK) {
/*
We were in the process of sending a rollback anyways. We will
report it as a success.
*/
theCompletionStatus = NdbTransaction::CompletedSuccess;
} else {
theReturnStatus = NdbTransaction::ReturnFailure;
theCompletionStatus = NdbTransaction::CompletedFailure;
theError.code = 4031;
}//if
theReleaseOnClose = true;
theCommitStatus = NdbTransaction::Aborted;
return 0;
} else {
#ifdef VM_TRACE
ndbout_c("Recevied TCKEY_FAILREF wo/ operation");
#endif
}
return -1;
}//NdbTransaction::receiveTCKEY_FAILREF()
/******************************************************************************
int receiveTCINDXCONF(NdbApiSignal* aSignal, Uint32 long_short_ind);
Return Value: Return 0 : receiveTCINDXCONF was successful.
Return -1: In all other case.
Parameters: aSignal: The signal object pointer.
Remark:
******************************************************************************/
int
NdbTransaction::receiveTCINDXCONF(const TcIndxConf * indxConf,
Uint32 aDataLength)
{
if(checkState_TransId(&indxConf->transId1)){
const Uint32 tTemp = indxConf->confInfo;
const Uint32 tNoOfOperations = TcIndxConf::getNoOfOperations(tTemp);
const Uint32 tCommitFlag = TcKeyConf::getCommitFlag(tTemp);
const Uint32* tPtr = (Uint32 *)&indxConf->operations[0];
Uint32 tNoComp = theNoOfOpCompleted;
for (Uint32 i = 0; i < tNoOfOperations ; i++) {
NdbReceiver* tOp = theNdb->void2rec(theNdb->int2void(*tPtr));
tPtr++;
const Uint32 tAttrInfoLen = *tPtr;
tPtr++;
if (tOp && tOp->checkMagicNumber()) {
tNoComp += tOp->execTCOPCONF(tAttrInfoLen);
} else {
return -1;
}//if
}//for
Uint32 tNoSent = theNoOfOpSent;
Uint32 tGCI = indxConf->gci;
theNoOfOpCompleted = tNoComp;
if (tCommitFlag == 1) {
theCommitStatus = Committed;
theGlobalCheckpointId = tGCI;
if (tGCI) // Read(dirty) only transaction doesnt get GCI
{
*p_latest_trans_gci = tGCI;
}
} else if ((tNoComp >= tNoSent) &&
(theLastExecOpInList->theCommitIndicator == 1)){
/**********************************************************************/
// We sent the transaction with Commit flag set and received a CONF with
// no Commit flag set. This is clearly an anomaly.
/**********************************************************************/
theError.code = 4011;
theCompletionStatus = NdbTransaction::CompletedFailure;
theCommitStatus = NdbTransaction::Aborted;
theReturnStatus = NdbTransaction::ReturnFailure;
return 0;
}//if
if (tNoComp >= tNoSent) {
return 0; // No more operations to wait for
}//if
// Not completed the reception yet.
} else {
#ifdef NDB_NO_DROPPED_SIGNAL
abort();
#endif
}
return -1;
}//NdbTransaction::receiveTCINDXCONF()
/*******************************************************************************
int OpCompletedFailure();
Return Value: Return 0 : OpCompleteSuccess was successful.
Return -1: In all other case.
Parameters: aErrorCode: The error code.
Remark: An operation was completed with failure.
*******************************************************************************/
int
NdbTransaction::OpCompleteFailure(NdbOperation* op)
{
Uint32 tNoComp = theNoOfOpCompleted;
Uint32 tNoSent = theNoOfOpSent;
tNoComp++;
theNoOfOpCompleted = tNoComp;
return (tNoComp == tNoSent) ? 0 : -1;
}//NdbTransaction::OpCompleteFailure()
/******************************************************************************
int OpCompleteSuccess();
Return Value: Return 0 : OpCompleteSuccess was successful.
Return -1: In all other case.
Remark: An operation was completed with success.
*******************************************************************************/
int
NdbTransaction::OpCompleteSuccess()
{
Uint32 tNoComp = theNoOfOpCompleted;
Uint32 tNoSent = theNoOfOpSent;
tNoComp++;
theNoOfOpCompleted = tNoComp;
if (tNoComp == tNoSent) { // Last operation completed
return 0;
} else if (tNoComp < tNoSent) {
return -1; // Continue waiting for more signals
} else {
setOperationErrorCodeAbort(4113); // Too many operations,
// stop waiting for more
theCompletionStatus = NdbTransaction::CompletedFailure;
theReturnStatus = NdbTransaction::ReturnFailure;
return 0;
}//if
}//NdbTransaction::OpCompleteSuccess()
/******************************************************************************
int getGCI();
Remark: Get global checkpoint identity of the transaction
*******************************************************************************/
int
NdbTransaction::getGCI()
{
if (theCommitStatus == NdbTransaction::Committed) {
return theGlobalCheckpointId;
}//if
return 0;
}//NdbTransaction::getGCI()
/*******************************************************************************
Uint64 getTransactionId(void);
Remark: Get the transaction identity.
*******************************************************************************/
Uint64
NdbTransaction::getTransactionId()
{
return theTransactionId;
}//NdbTransaction::getTransactionId()
NdbTransaction::CommitStatusType
NdbTransaction::commitStatus()
{
return theCommitStatus;
}//NdbTransaction::commitStatus()
int
NdbTransaction::getNdbErrorLine()
{
return theErrorLine;
}
NdbOperation*
NdbTransaction::getNdbErrorOperation()
{
return theErrorOperation;
}//NdbTransaction::getNdbErrorOperation()
const NdbOperation *
NdbTransaction::getNextCompletedOperation(const NdbOperation * current) const {
if(current == 0)
return theCompletedFirstOp;
return current->theNext;
}
#ifdef VM_TRACE
#define CASE(x) case x: ndbout << " " << #x; break
void
NdbTransaction::printState()
{
ndbout << "con=" << hex << this << dec;
ndbout << " node=" << getConnectedNodeId();
switch (theStatus) {
CASE(NotConnected);
CASE(Connecting);
CASE(Connected);
CASE(DisConnecting);
CASE(ConnectFailure);
default: ndbout << (Uint32) theStatus;
}
switch (theListState) {
CASE(NotInList);
CASE(InPreparedList);
CASE(InSendList);
CASE(InCompletedList);
default: ndbout << (Uint32) theListState;
}
switch (theSendStatus) {
CASE(NotInit);
CASE(InitState);
CASE(sendOperations);
CASE(sendCompleted);
CASE(sendCOMMITstate);
CASE(sendABORT);
CASE(sendABORTfail);
CASE(sendTC_ROLLBACK);
CASE(sendTC_COMMIT);
CASE(sendTC_OP);
default: ndbout << (Uint32) theSendStatus;
}
switch (theCommitStatus) {
CASE(NotStarted);
CASE(Started);
CASE(Committed);
CASE(Aborted);
CASE(NeedAbort);
default: ndbout << (Uint32) theCommitStatus;
}
switch (theCompletionStatus) {
CASE(NotCompleted);
CASE(CompletedSuccess);
CASE(CompletedFailure);
CASE(DefinitionFailure);
default: ndbout << (Uint32) theCompletionStatus;
}
ndbout << endl;
}
#undef CASE
#endif
int
NdbTransaction::report_node_failure(Uint32 id){
NdbNodeBitmask::set(m_failed_db_nodes, id);
if(!NdbNodeBitmask::get(m_db_nodes, id))
{
return 0;
}
/**
* Arrived
* TCKEYCONF TRANSIDAI
* 1) - -
* 2) - X
* 3) X -
* 4) X X
*/
NdbOperation* tmp = theFirstExecOpInList;
const Uint32 len = TcKeyConf::SimpleReadBit | id;
Uint32 tNoComp = theNoOfOpCompleted;
Uint32 tNoSent = theNoOfOpSent;
Uint32 count = 0;
while(tmp != 0)
{
if(tmp->theReceiver.m_expected_result_length == len &&
tmp->theReceiver.m_received_result_length == 0)
{
count++;
tmp->theError.code = 4119;
}
tmp = tmp->next();
}
tNoComp += count;
theNoOfOpCompleted = tNoComp;
if(count)
{
theReturnStatus = NdbTransaction::ReturnFailure;
if(tNoComp == tNoSent)
{
theError.code = 4119;
theCompletionStatus = NdbTransaction::CompletedFailure;
return 1;
}
}
return 0;
}
|