summaryrefslogtreecommitdiff
path: root/storage/ndb/test
diff options
context:
space:
mode:
Diffstat (limited to 'storage/ndb/test')
-rw-r--r--storage/ndb/test/Makefile.am24
-rw-r--r--storage/ndb/test/include/AtrtClient.hpp57
-rw-r--r--storage/ndb/test/include/CpcClient.hpp103
-rwxr-xr-xstorage/ndb/test/include/DbUtil.hpp177
-rw-r--r--storage/ndb/test/include/HugoAsynchTransactions.hpp75
-rw-r--r--storage/ndb/test/include/HugoCalculator.hpp53
-rw-r--r--storage/ndb/test/include/HugoOperations.hpp137
-rw-r--r--storage/ndb/test/include/HugoTransactions.hpp155
-rw-r--r--storage/ndb/test/include/NDBT.hpp39
-rw-r--r--storage/ndb/test/include/NDBT_DataSet.hpp140
-rw-r--r--storage/ndb/test/include/NDBT_DataSetTransaction.hpp162
-rw-r--r--storage/ndb/test/include/NDBT_Error.hpp101
-rw-r--r--storage/ndb/test/include/NDBT_Output.hpp30
-rw-r--r--storage/ndb/test/include/NDBT_ResultRow.hpp61
-rw-r--r--storage/ndb/test/include/NDBT_ReturnCodes.h42
-rw-r--r--storage/ndb/test/include/NDBT_Stats.hpp74
-rw-r--r--storage/ndb/test/include/NDBT_Table.hpp94
-rw-r--r--storage/ndb/test/include/NDBT_Tables.hpp56
-rw-r--r--storage/ndb/test/include/NDBT_Test.hpp470
-rw-r--r--storage/ndb/test/include/NDBT_Thread.hpp227
-rw-r--r--storage/ndb/test/include/NdbBackup.hpp54
-rw-r--r--storage/ndb/test/include/NdbConfig.hpp39
-rw-r--r--storage/ndb/test/include/NdbGrep.hpp53
-rw-r--r--storage/ndb/test/include/NdbMixRestarter.hpp75
-rw-r--r--storage/ndb/test/include/NdbRestarter.hpp121
-rw-r--r--storage/ndb/test/include/NdbRestarts.hpp120
-rw-r--r--storage/ndb/test/include/NdbSchemaCon.hpp147
-rw-r--r--storage/ndb/test/include/NdbSchemaOp.hpp546
-rw-r--r--storage/ndb/test/include/NdbTest.hpp35
-rw-r--r--storage/ndb/test/include/NdbTimer.hpp109
-rw-r--r--storage/ndb/test/include/TestNdbEventOperation.hpp24
-rw-r--r--storage/ndb/test/include/UtilTransactions.hpp136
-rw-r--r--storage/ndb/test/include/getarg.h115
-rw-r--r--storage/ndb/test/ndbapi/InsertRecs.cpp571
-rw-r--r--storage/ndb/test/ndbapi/Makefile.am192
-rw-r--r--storage/ndb/test/ndbapi/ScanFilter.hpp131
-rw-r--r--storage/ndb/test/ndbapi/ScanFunctions.hpp352
-rw-r--r--storage/ndb/test/ndbapi/ScanInterpretTest.hpp515
-rw-r--r--storage/ndb/test/ndbapi/TraceNdbApi.cpp543
-rw-r--r--storage/ndb/test/ndbapi/VerifyNdbApi.cpp151
-rw-r--r--storage/ndb/test/ndbapi/acid.cpp533
-rw-r--r--storage/ndb/test/ndbapi/acid2.cpp693
-rw-r--r--storage/ndb/test/ndbapi/acrt/NdbRepStress.cpp457
-rw-r--r--storage/ndb/test/ndbapi/adoInsertRecs.cpp363
-rw-r--r--storage/ndb/test/ndbapi/asyncGenerator.cpp571
-rw-r--r--storage/ndb/test/ndbapi/bank/Bank.cpp2521
-rw-r--r--storage/ndb/test/ndbapi/bank/Bank.hpp147
-rw-r--r--storage/ndb/test/ndbapi/bank/BankLoad.cpp602
-rw-r--r--storage/ndb/test/ndbapi/bank/Makefile.am36
-rw-r--r--storage/ndb/test/ndbapi/bank/bankCreator.cpp68
-rw-r--r--storage/ndb/test/ndbapi/bank/bankMakeGL.cpp64
-rw-r--r--storage/ndb/test/ndbapi/bank/bankSumAccounts.cpp64
-rw-r--r--storage/ndb/test/ndbapi/bank/bankTimer.cpp67
-rw-r--r--storage/ndb/test/ndbapi/bank/bankTransactionMaker.cpp67
-rw-r--r--storage/ndb/test/ndbapi/bank/bankValidateAllGLs.cpp65
-rw-r--r--storage/ndb/test/ndbapi/bank/testBank.cpp153
-rw-r--r--storage/ndb/test/ndbapi/bench/asyncGenerator.cpp570
-rw-r--r--storage/ndb/test/ndbapi/bench/dbGenerator.h63
-rw-r--r--storage/ndb/test/ndbapi/bench/dbPopulate.cpp244
-rw-r--r--storage/ndb/test/ndbapi/bench/dbPopulate.h59
-rw-r--r--storage/ndb/test/ndbapi/bench/macros.h51
-rw-r--r--storage/ndb/test/ndbapi/bench/mainAsyncGenerator.cpp503
-rw-r--r--storage/ndb/test/ndbapi/bench/mainPopulate.cpp81
-rw-r--r--storage/ndb/test/ndbapi/bench/ndb_async1.cpp647
-rw-r--r--storage/ndb/test/ndbapi/bench/ndb_async2.cpp757
-rw-r--r--storage/ndb/test/ndbapi/bench/ndb_error.hpp81
-rw-r--r--storage/ndb/test/ndbapi/bench/ndb_schema.hpp78
-rw-r--r--storage/ndb/test/ndbapi/bench/ndb_user_transaction.cpp825
-rw-r--r--storage/ndb/test/ndbapi/bench/ndb_user_transaction2.cpp825
-rw-r--r--storage/ndb/test/ndbapi/bench/ndb_user_transaction3.cpp793
-rw-r--r--storage/ndb/test/ndbapi/bench/ndb_user_transaction4.cpp770
-rw-r--r--storage/ndb/test/ndbapi/bench/ndb_user_transaction5.cpp769
-rw-r--r--storage/ndb/test/ndbapi/bench/ndb_user_transaction6.cpp561
-rw-r--r--storage/ndb/test/ndbapi/bench/testData.h156
-rw-r--r--storage/ndb/test/ndbapi/bench/testDefinitions.h90
-rw-r--r--storage/ndb/test/ndbapi/bench/userInterface.cpp744
-rw-r--r--storage/ndb/test/ndbapi/bench/userInterface.h151
-rw-r--r--storage/ndb/test/ndbapi/benchronja.cpp1208
-rw-r--r--storage/ndb/test/ndbapi/bulk_copy.cpp276
-rw-r--r--storage/ndb/test/ndbapi/cdrserver.cpp1628
-rw-r--r--storage/ndb/test/ndbapi/celloDb.cpp1504
-rw-r--r--storage/ndb/test/ndbapi/create_all_tabs.cpp69
-rw-r--r--storage/ndb/test/ndbapi/create_tab.cpp138
-rw-r--r--storage/ndb/test/ndbapi/drop_all_tabs.cpp63
-rw-r--r--storage/ndb/test/ndbapi/flexAsynch.cpp1002
-rw-r--r--storage/ndb/test/ndbapi/flexBench.cpp1166
-rw-r--r--storage/ndb/test/ndbapi/flexHammer.cpp888
-rw-r--r--storage/ndb/test/ndbapi/flexScan.cpp1662
-rw-r--r--storage/ndb/test/ndbapi/flexTT.cpp944
-rw-r--r--storage/ndb/test/ndbapi/flexTimedAsynch.cpp859
-rw-r--r--storage/ndb/test/ndbapi/flex_bench_mysql.cpp1751
-rw-r--r--storage/ndb/test/ndbapi/index.cpp998
-rw-r--r--storage/ndb/test/ndbapi/index2.cpp836
-rw-r--r--storage/ndb/test/ndbapi/initronja.cpp332
-rw-r--r--storage/ndb/test/ndbapi/interpreterInTup.cpp1518
-rw-r--r--storage/ndb/test/ndbapi/mainAsyncGenerator.cpp391
-rw-r--r--storage/ndb/test/ndbapi/msa.cpp1206
-rw-r--r--storage/ndb/test/ndbapi/ndb_async1.cpp647
-rw-r--r--storage/ndb/test/ndbapi/ndb_async2.cpp754
-rw-r--r--storage/ndb/test/ndbapi/ndb_user_populate.cpp165
-rw-r--r--storage/ndb/test/ndbapi/ndb_user_transaction.cpp825
-rw-r--r--storage/ndb/test/ndbapi/ndb_user_transaction2.cpp825
-rw-r--r--storage/ndb/test/ndbapi/ndb_user_transaction3.cpp793
-rw-r--r--storage/ndb/test/ndbapi/ndb_user_transaction4.cpp770
-rw-r--r--storage/ndb/test/ndbapi/ndb_user_transaction5.cpp769
-rw-r--r--storage/ndb/test/ndbapi/ndb_user_transaction6.cpp561
-rw-r--r--storage/ndb/test/ndbapi/restarter.cpp130
-rw-r--r--storage/ndb/test/ndbapi/restarter2.cpp117
-rw-r--r--storage/ndb/test/ndbapi/restarts.cpp116
-rw-r--r--storage/ndb/test/ndbapi/size.cpp28
-rw-r--r--storage/ndb/test/ndbapi/slow_select.cpp243
-rw-r--r--storage/ndb/test/ndbapi/testBackup.cpp559
-rw-r--r--storage/ndb/test/ndbapi/testBasic.cpp1850
-rw-r--r--storage/ndb/test/ndbapi/testBasicAsynch.cpp187
-rw-r--r--storage/ndb/test/ndbapi/testBitfield.cpp623
-rw-r--r--storage/ndb/test/ndbapi/testBlobs.cpp2230
-rw-r--r--storage/ndb/test/ndbapi/testDataBuffers.cpp642
-rw-r--r--storage/ndb/test/ndbapi/testDeadlock.cpp523
-rw-r--r--storage/ndb/test/ndbapi/testDict.cpp3301
-rw-r--r--storage/ndb/test/ndbapi/testGrepVerify.cpp118
-rw-r--r--storage/ndb/test/ndbapi/testIndex.cpp1758
-rw-r--r--storage/ndb/test/ndbapi/testIndexStat.cpp1405
-rw-r--r--storage/ndb/test/ndbapi/testInterpreter.cpp443
-rw-r--r--storage/ndb/test/ndbapi/testLcp.cpp558
-rw-r--r--storage/ndb/test/ndbapi/testMgm.cpp839
-rw-r--r--storage/ndb/test/ndbapi/testNDBT.cpp174
-rw-r--r--storage/ndb/test/ndbapi/testNdbApi.cpp1736
-rw-r--r--storage/ndb/test/ndbapi/testNodeRestart.cpp2517
-rw-r--r--storage/ndb/test/ndbapi/testOIBasic.cpp5850
-rw-r--r--storage/ndb/test/ndbapi/testOperations.cpp796
-rw-r--r--storage/ndb/test/ndbapi/testOrderedIndex.cpp225
-rw-r--r--storage/ndb/test/ndbapi/testPartitioning.cpp448
-rw-r--r--storage/ndb/test/ndbapi/testReadPerf.cpp409
-rw-r--r--storage/ndb/test/ndbapi/testRestartGci.cpp222
-rw-r--r--storage/ndb/test/ndbapi/testSRBank.cpp298
-rw-r--r--storage/ndb/test/ndbapi/testScan.cpp1757
-rw-r--r--storage/ndb/test/ndbapi/testScanFilter.cpp861
-rw-r--r--storage/ndb/test/ndbapi/testScanInterpreter.cpp281
-rw-r--r--storage/ndb/test/ndbapi/testScanPerf.cpp372
-rw-r--r--storage/ndb/test/ndbapi/testSystemRestart.cpp1863
-rw-r--r--storage/ndb/test/ndbapi/testTimeout.cpp562
-rw-r--r--storage/ndb/test/ndbapi/testTransactions.cpp419
-rw-r--r--storage/ndb/test/ndbapi/test_event.cpp2051
-rw-r--r--storage/ndb/test/ndbapi/test_event_merge.cpp2331
-rw-r--r--storage/ndb/test/ndbapi/test_event_multi_table.cpp558
-rw-r--r--storage/ndb/test/ndbapi/userInterface.cpp117
-rw-r--r--storage/ndb/test/ndbnet/test.run19
-rw-r--r--storage/ndb/test/ndbnet/testError.run284
-rw-r--r--storage/ndb/test/ndbnet/testMNF.run295
-rw-r--r--storage/ndb/test/ndbnet/testNR.run76
-rw-r--r--storage/ndb/test/ndbnet/testNR1.run79
-rw-r--r--storage/ndb/test/ndbnet/testNR4.run95
-rw-r--r--storage/ndb/test/ndbnet/testSRhang.run66
-rw-r--r--storage/ndb/test/ndbnet/testTR295.run93
-rw-r--r--storage/ndb/test/newtonapi/basic_test/Makefile25
-rw-r--r--storage/ndb/test/newtonapi/basic_test/basic/Makefile14
-rw-r--r--storage/ndb/test/newtonapi/basic_test/basic/basic.cpp321
-rw-r--r--storage/ndb/test/newtonapi/basic_test/bulk_read/Makefile14
-rw-r--r--storage/ndb/test/newtonapi/basic_test/bulk_read/br_test.cpp262
-rw-r--r--storage/ndb/test/newtonapi/basic_test/common.cpp133
-rw-r--r--storage/ndb/test/newtonapi/basic_test/common.hpp66
-rw-r--r--storage/ndb/test/newtonapi/basic_test/ptr_binding/Makefile14
-rw-r--r--storage/ndb/test/newtonapi/basic_test/ptr_binding/ptr_binding_test.cpp264
-rw-r--r--storage/ndb/test/newtonapi/basic_test/too_basic.cpp105
-rw-r--r--storage/ndb/test/newtonapi/perf_test/Makefile14
-rw-r--r--storage/ndb/test/newtonapi/perf_test/perf.cpp647
-rw-r--r--storage/ndb/test/odbc/SQL99_test/Makefile26
-rw-r--r--storage/ndb/test/odbc/SQL99_test/SQL99_test.cpp2145
-rw-r--r--storage/ndb/test/odbc/SQL99_test/SQL99_test.h261
-rw-r--r--storage/ndb/test/odbc/client/Makefile95
-rw-r--r--storage/ndb/test/odbc/client/NDBT_ALLOCHANDLE.cpp53
-rw-r--r--storage/ndb/test/odbc/client/NDBT_ALLOCHANDLE_HDBC.cpp59
-rw-r--r--storage/ndb/test/odbc/client/NDBT_SQLConnect.cpp82
-rw-r--r--storage/ndb/test/odbc/client/NDBT_SQLPrepare.cpp109
-rw-r--r--storage/ndb/test/odbc/client/SQLAllocEnvTest.cpp115
-rw-r--r--storage/ndb/test/odbc/client/SQLAllocHandleTest.cpp314
-rw-r--r--storage/ndb/test/odbc/client/SQLAllocHandleTest_bf.cpp259
-rw-r--r--storage/ndb/test/odbc/client/SQLBindColTest.cpp537
-rw-r--r--storage/ndb/test/odbc/client/SQLBindParameterTest.cpp219
-rw-r--r--storage/ndb/test/odbc/client/SQLCancelTest.cpp254
-rw-r--r--storage/ndb/test/odbc/client/SQLCloseCursorTest.cpp92
-rw-r--r--storage/ndb/test/odbc/client/SQLColAttributeTest.cpp328
-rw-r--r--storage/ndb/test/odbc/client/SQLColAttributeTest1.cpp143
-rw-r--r--storage/ndb/test/odbc/client/SQLColAttributeTest2.cpp277
-rw-r--r--storage/ndb/test/odbc/client/SQLColAttributeTest3.cpp275
-rw-r--r--storage/ndb/test/odbc/client/SQLConnectTest.cpp165
-rw-r--r--storage/ndb/test/odbc/client/SQLCopyDescTest.cpp140
-rw-r--r--storage/ndb/test/odbc/client/SQLDescribeColTest.cpp260
-rw-r--r--storage/ndb/test/odbc/client/SQLDisconnectTest.cpp155
-rw-r--r--storage/ndb/test/odbc/client/SQLDriverConnectTest.cpp96
-rw-r--r--storage/ndb/test/odbc/client/SQLEndTranTest.cpp108
-rw-r--r--storage/ndb/test/odbc/client/SQLErrorTest.cpp107
-rw-r--r--storage/ndb/test/odbc/client/SQLExecDirectTest.cpp353
-rw-r--r--storage/ndb/test/odbc/client/SQLExecuteTest.cpp122
-rw-r--r--storage/ndb/test/odbc/client/SQLFetchScrollTest.cpp82
-rw-r--r--storage/ndb/test/odbc/client/SQLFetchTest.cpp438
-rw-r--r--storage/ndb/test/odbc/client/SQLFreeHandleTest.cpp195
-rw-r--r--storage/ndb/test/odbc/client/SQLFreeStmtTest.cpp182
-rw-r--r--storage/ndb/test/odbc/client/SQLGetConnectAttrTest.cpp131
-rw-r--r--storage/ndb/test/odbc/client/SQLGetCursorNameTest.cpp221
-rw-r--r--storage/ndb/test/odbc/client/SQLGetDataTest.cpp358
-rw-r--r--storage/ndb/test/odbc/client/SQLGetDescFieldTest.cpp113
-rw-r--r--storage/ndb/test/odbc/client/SQLGetDescRecTest.cpp95
-rw-r--r--storage/ndb/test/odbc/client/SQLGetDiagFieldTest.cpp236
-rw-r--r--storage/ndb/test/odbc/client/SQLGetDiagRecSimpleTest.cpp167
-rw-r--r--storage/ndb/test/odbc/client/SQLGetDiagRecTest.cpp207
-rw-r--r--storage/ndb/test/odbc/client/SQLGetEnvAttrTest.cpp110
-rw-r--r--storage/ndb/test/odbc/client/SQLGetFunctionsTest.cpp284
-rw-r--r--storage/ndb/test/odbc/client/SQLGetInfoTest.cpp215
-rw-r--r--storage/ndb/test/odbc/client/SQLGetStmtAttrTest.cpp155
-rw-r--r--storage/ndb/test/odbc/client/SQLGetTypeInfoTest.cpp202
-rw-r--r--storage/ndb/test/odbc/client/SQLMoreResultsTest.cpp91
-rw-r--r--storage/ndb/test/odbc/client/SQLNumResultColsTest.cpp202
-rw-r--r--storage/ndb/test/odbc/client/SQLParamDataTest.cpp105
-rw-r--r--storage/ndb/test/odbc/client/SQLPrepareTest.cpp285
-rw-r--r--storage/ndb/test/odbc/client/SQLPutDataTest.cpp108
-rw-r--r--storage/ndb/test/odbc/client/SQLRowCountTest.cpp203
-rw-r--r--storage/ndb/test/odbc/client/SQLSetConnectAttrTest.cpp131
-rw-r--r--storage/ndb/test/odbc/client/SQLSetCursorNameTest.cpp215
-rw-r--r--storage/ndb/test/odbc/client/SQLSetDescFieldTest.cpp100
-rw-r--r--storage/ndb/test/odbc/client/SQLSetDescRecTest.cpp99
-rw-r--r--storage/ndb/test/odbc/client/SQLSetEnvAttrTest.cpp108
-rw-r--r--storage/ndb/test/odbc/client/SQLSetStmtAttrTest.cpp108
-rw-r--r--storage/ndb/test/odbc/client/SQLTablesTest.cpp227
-rw-r--r--storage/ndb/test/odbc/client/SQLTransactTest.cpp305
-rw-r--r--storage/ndb/test/odbc/client/common.hpp81
-rw-r--r--storage/ndb/test/odbc/client/main.cpp158
-rw-r--r--storage/ndb/test/odbc/dm-iodbc/Makefile38
-rw-r--r--storage/ndb/test/odbc/dm-unixodbc/Makefile39
-rw-r--r--storage/ndb/test/odbc/driver/Makefile30
-rw-r--r--storage/ndb/test/odbc/driver/testOdbcDriver.cpp4948
-rw-r--r--storage/ndb/test/odbc/test_compiler/Makefile21
-rw-r--r--storage/ndb/test/odbc/test_compiler/test_compiler.cpp233
-rw-r--r--storage/ndb/test/run-test/16node-tests.txt749
-rw-r--r--storage/ndb/test/run-test/ATRT_SETUP_README.txt292
-rw-r--r--storage/ndb/test/run-test/ATRT_USAGE_README.txt224
-rw-r--r--storage/ndb/test/run-test/Makefile.am55
-rw-r--r--storage/ndb/test/run-test/README43
-rw-r--r--storage/ndb/test/run-test/README.ATRT34
-rwxr-xr-xstorage/ndb/test/run-test/atrt-analyze-result.sh30
-rwxr-xr-xstorage/ndb/test/run-test/atrt-clear-result.sh22
-rw-r--r--storage/ndb/test/run-test/atrt-example.tgzbin2196 -> 0 bytes
-rwxr-xr-xstorage/ndb/test/run-test/atrt-gather-result.sh34
-rwxr-xr-xstorage/ndb/test/run-test/atrt-mysql-test-run36
-rwxr-xr-xstorage/ndb/test/run-test/atrt-setup.sh24
-rwxr-xr-xstorage/ndb/test/run-test/atrt-testBackup24
-rw-r--r--storage/ndb/test/run-test/atrt.hpp161
-rw-r--r--storage/ndb/test/run-test/autotest-boot.sh205
-rw-r--r--storage/ndb/test/run-test/autotest-run.sh287
-rw-r--r--storage/ndb/test/run-test/basic.txt779
-rw-r--r--storage/ndb/test/run-test/conf-dl145a.cnf26
-rw-r--r--storage/ndb/test/run-test/conf-ndbmaster.cnf23
-rw-r--r--storage/ndb/test/run-test/conf-repl.cnf28
-rw-r--r--storage/ndb/test/run-test/conf-test.cnf26
-rw-r--r--storage/ndb/test/run-test/daily-basic-tests.txt1072
-rw-r--r--storage/ndb/test/run-test/daily-devel-tests.txt260
-rw-r--r--storage/ndb/test/run-test/example-my.cnf116
-rw-r--r--storage/ndb/test/run-test/example.conf10
-rw-r--r--storage/ndb/test/run-test/files.cpp402
-rw-r--r--storage/ndb/test/run-test/main.cpp1249
-rwxr-xr-xstorage/ndb/test/run-test/make-config.sh119
-rwxr-xr-xstorage/ndb/test/run-test/make-html-reports.sh210
-rwxr-xr-xstorage/ndb/test/run-test/make-index.sh261
-rwxr-xr-xstorage/ndb/test/run-test/ndb-autotest.sh424
-rw-r--r--storage/ndb/test/run-test/setup.cpp990
-rw-r--r--storage/ndb/test/run-test/test-tests.txt24
-rw-r--r--storage/ndb/test/run-test/upgrade-boot.sh235
-rw-r--r--storage/ndb/test/src/AtrtClient.cpp216
-rw-r--r--storage/ndb/test/src/CpcClient.cpp552
-rwxr-xr-xstorage/ndb/test/src/DbUtil.cpp678
-rw-r--r--storage/ndb/test/src/HugoAsynchTransactions.cpp486
-rw-r--r--storage/ndb/test/src/HugoCalculator.cpp314
-rw-r--r--storage/ndb/test/src/HugoOperations.cpp753
-rw-r--r--storage/ndb/test/src/HugoTransactions.cpp1864
-rw-r--r--storage/ndb/test/src/Makefile.am47
-rw-r--r--storage/ndb/test/src/NDBT_Error.cpp283
-rw-r--r--storage/ndb/test/src/NDBT_Output.cpp36
-rw-r--r--storage/ndb/test/src/NDBT_ResultRow.cpp156
-rw-r--r--storage/ndb/test/src/NDBT_ReturnCodes.cpp50
-rw-r--r--storage/ndb/test/src/NDBT_Table.cpp92
-rw-r--r--storage/ndb/test/src/NDBT_Tables.cpp1116
-rw-r--r--storage/ndb/test/src/NDBT_Test.cpp1525
-rw-r--r--storage/ndb/test/src/NDBT_Thread.cpp284
-rw-r--r--storage/ndb/test/src/NdbBackup.cpp452
-rw-r--r--storage/ndb/test/src/NdbConfig.cpp83
-rw-r--r--storage/ndb/test/src/NdbGrep.cpp333
-rw-r--r--storage/ndb/test/src/NdbMixRestarter.cpp313
-rw-r--r--storage/ndb/test/src/NdbRestarter.cpp751
-rw-r--r--storage/ndb/test/src/NdbRestarts.cpp875
-rw-r--r--storage/ndb/test/src/NdbSchemaCon.cpp169
-rw-r--r--storage/ndb/test/src/NdbSchemaOp.cpp219
-rw-r--r--storage/ndb/test/src/UtilTransactions.cpp1472
-rw-r--r--storage/ndb/test/src/getarg.c608
-rw-r--r--storage/ndb/test/tools/Makefile.am47
-rw-r--r--storage/ndb/test/tools/connect.cpp151
-rw-r--r--storage/ndb/test/tools/copy_tab.cpp103
-rw-r--r--storage/ndb/test/tools/cpcc.cpp352
-rw-r--r--storage/ndb/test/tools/create_index.cpp111
-rw-r--r--storage/ndb/test/tools/hugoCalculator.cpp71
-rw-r--r--storage/ndb/test/tools/hugoFill.cpp86
-rw-r--r--storage/ndb/test/tools/hugoLoad.cpp120
-rw-r--r--storage/ndb/test/tools/hugoLockRecords.cpp96
-rw-r--r--storage/ndb/test/tools/hugoPkDelete.cpp181
-rw-r--r--storage/ndb/test/tools/hugoPkRead.cpp178
-rw-r--r--storage/ndb/test/tools/hugoPkReadRecord.cpp146
-rw-r--r--storage/ndb/test/tools/hugoPkUpdate.cpp183
-rw-r--r--storage/ndb/test/tools/hugoScanRead.cpp132
-rw-r--r--storage/ndb/test/tools/hugoScanUpdate.cpp114
-rw-r--r--storage/ndb/test/tools/listen.cpp375
-rw-r--r--storage/ndb/test/tools/log_listner.cpp106
-rw-r--r--storage/ndb/test/tools/rep_latency.cpp305
-rw-r--r--storage/ndb/test/tools/restart.cpp84
-rw-r--r--storage/ndb/test/tools/transproxy.cpp361
-rw-r--r--storage/ndb/test/tools/verify_index.cpp91
314 files changed, 0 insertions, 132515 deletions
diff --git a/storage/ndb/test/Makefile.am b/storage/ndb/test/Makefile.am
deleted file mode 100644
index e9742ba202e..00000000000
--- a/storage/ndb/test/Makefile.am
+++ /dev/null
@@ -1,24 +0,0 @@
-# Copyright (C) 2004 MySQL AB
-# Use is subject to license terms
-#
-# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-SUBDIRS = src tools ndbapi run-test
-
-EXTRA_DIST = include
-
-dist-hook:
- -rm -rf `find $(distdir) -type d -name SCCS`
-
-windoze-dsp:
diff --git a/storage/ndb/test/include/AtrtClient.hpp b/storage/ndb/test/include/AtrtClient.hpp
deleted file mode 100644
index 89f44d4ac58..00000000000
--- a/storage/ndb/test/include/AtrtClient.hpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/* Copyright (c) 2003, 2008 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef ATRT_CLIENT_HPP
-#define ATRT_CLIENT_HPP
-
-#include <DbUtil.hpp>
-
-class AtrtClient: public DbUtil {
-public:
-
- enum AtrtCommandType {
- ATCT_CHANGE_VERSION= 1,
- ATCT_RESET_PROC= 2
- };
-
- AtrtClient(const char* _user= "root",
- const char* _password= "",
- const char* _suffix= ".1.atrt");
- AtrtClient(MYSQL*);
- ~AtrtClient();
-
-
- // Command functions
- bool changeVersion(int process_id, const char* process_args);
- bool resetProc(int process_id);
-
- // Query functions
- bool getConnectString(int cluster_id, SqlResultSet& result);
- bool getClusters(SqlResultSet& result);
- bool getMgmds(int cluster_id, SqlResultSet& result);
- bool getNdbds(int cluster_id, SqlResultSet& result);
-
-private:
- int writeCommand(AtrtCommandType _type,
- const Properties& args);
- bool readCommand(uint command_id,
- SqlResultSet& result);
-
- bool doCommand(AtrtCommandType _type,
- const Properties& args);
-};
-
-#endif
diff --git a/storage/ndb/test/include/CpcClient.hpp b/storage/ndb/test/include/CpcClient.hpp
deleted file mode 100644
index bc65e5ee485..00000000000
--- a/storage/ndb/test/include/CpcClient.hpp
+++ /dev/null
@@ -1,103 +0,0 @@
-/* Copyright (c) 2003-2005, 2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef __CPCCLIENT_HPP_INCLUDED__
-#define __CPCCLIENT_HPP_INCLUDED__
-
-#include <Parser.hpp>
-#include <SocketServer.hpp>
-#include <util/InputStream.hpp>
-#include <util/OutputStream.hpp>
-
-/**
- * Simple CPC client class. The whole management client should be replaced
- * something smarter and more worked through.
- */
-class SimpleCpcClient {
-public:
- SimpleCpcClient(const char *host, int port);
- ~SimpleCpcClient();
-
- static void run(SimpleCpcClient &);
-
- int getPort() const { return port;}
- const char * getHost() const { return host;}
-
- struct Process {
- int m_id;
- BaseString m_name;
-
- BaseString m_owner;
- BaseString m_group;
- BaseString m_runas;
-
- BaseString m_cwd;
- BaseString m_env;
- BaseString m_path;
- BaseString m_args;
-
- BaseString m_type;
- BaseString m_status;
-
- BaseString m_stdin;
- BaseString m_stdout;
- BaseString m_stderr;
- BaseString m_ulimit;
- BaseString m_shutdown_options;
- };
-
-private:
- class ParserDummy : SocketServer::Session {
- public:
- ParserDummy(NDB_SOCKET_TYPE sock);
- };
-
- typedef Parser<ParserDummy> Parser_t;
- typedef ParserRow<ParserDummy> ParserRow_t;
-
- char *host;
- int port;
- NDB_SOCKET_TYPE cpc_sock;
-
-public:
- int connect();
-
- void cmd_list(char *arg);
- void cmd_start(char *arg);
- void cmd_stop(char *arg);
- void cmd_help(char *arg);
-
- int list_processes(Vector<Process>&, Properties &reply);
- int start_process(Uint32 id, Properties& reply);
- int stop_process(Uint32 id, Properties& reply);
- int undefine_process(Uint32 id, Properties& reply);
- int define_process(Process & p, Properties& reply);
-
-private:
- int cpc_send(const char *cmd,
- const Properties &args);
-
-
- Parser_t::ParserStatus cpc_recv(const ParserRow_t *syntax,
- const Properties **reply,
- void **user_data = NULL);
-
- const Properties *cpc_call(const char *cmd,
- const Properties &args,
- const ParserRow_t *reply_syntax);
-};
-
-#endif /* !__CPCCLIENT_HPP_INCLUDED__ */
diff --git a/storage/ndb/test/include/DbUtil.hpp b/storage/ndb/test/include/DbUtil.hpp
deleted file mode 100755
index 47b335d060e..00000000000
--- a/storage/ndb/test/include/DbUtil.hpp
+++ /dev/null
@@ -1,177 +0,0 @@
-/* Copyright (c) 2007, 2008 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-// dbutil.h: interface for the database utilities class.
-// Supplies a database to the test application
-
-#ifndef DBUTIL_HPP
-#define DBUTIL_HPP
-
-#include <NDBT.hpp>
-#include <BaseString.hpp>
-#include <Properties.hpp>
-#include <Vector.hpp>
-#include <mysql.h>
-
-//#define DEBUG
-#define DIE_UNLESS(expr) \
- ((void) ((expr) ? 0 : (Die(__FILE__, __LINE__, #expr), 0)))
-#define DIE(expr) \
- Die(__FILE__, __LINE__, #expr)
-#define myerror(msg) printError(msg)
-#define mysterror(stmt, msg) printStError(stmt, msg)
-#define CheckStmt(stmt) \
-{ \
-if ( stmt == 0) \
- myerror(NULL); \
-DIE_UNLESS(stmt != 0); \
-}
-
-#define check_execute(stmt, r) \
-{ \
-if (r) \
- mysterror(stmt, NULL); \
-DIE_UNLESS(r == 0);\
-}
-
-
-class SqlResultSet : public Properties {
-public:
-
- // Get row with number
- bool get_row(int row_num);
- // Load next row
- bool next(void);
- // Reset iterator
- void reset(void);
- // Remove current row from resultset
- void remove();
-
- SqlResultSet();
- ~SqlResultSet();
-
- const char* column(const char* col_name);
- uint columnAsInt(const char* col_name);
-
- uint insertId();
- uint affectedRows();
- uint numRows(void);
- uint mysqlErrno();
- const char* mysqlError();
- const char* mysqlSqlstate();
-
-private:
- uint get_int(const char* name);
- const char* get_string(const char* name);
-
- const Properties* m_curr_row;
- uint m_curr_row_num;
-};
-
-
-#define DBU_FAILED 1
-#define DBU_OK 0
-
-class DbUtil
-{
-public:
-
- DbUtil(MYSQL* mysql);
- DbUtil(const char* dbname = "mysql",
- const char* user = "root",
- const char* pass = "",
- const char* suffix = NULL);
- ~DbUtil();
-
- bool doQuery(const char* query);
- bool doQuery(const char* query, SqlResultSet& result);
- bool doQuery(const char* query, const Properties& args, SqlResultSet& result);
-
- bool doQuery(BaseString& str);
- bool doQuery(BaseString& str, SqlResultSet& result);
- bool doQuery(BaseString& str, const Properties& args, SqlResultSet& result);
-
- bool waitConnected(int timeout);
-
- /* Deprecated, see connect() */
- void databaseLogin(const char * system,
- const char * usr,
- const char * password,
- unsigned int portIn,
- const char * sockIn,
- bool transactional);
-
- const char * getDbName() {return m_dbname.c_str();};
- const char * getUser() {return m_user.c_str();};
- const char * getPassword(){return m_pass.c_str();};
- const char * getHost() {return m_host.c_str();};
- const char * getSocket() {return m_socket.c_str();};
- const char * getServerType(){return mysql_get_server_info(m_mysql);};
- const char * getError();
-
- MYSQL * getMysql(){return m_mysql;};
- MYSQL_STMT * STDCALL mysqlSimplePrepare(const char *query);
-
- void databaseLogout();
- void mysqlCloseStmHandle(MYSQL_STMT *my_stmt);
-
- int connect();
- void disconnect();
- int selectDb();
- int selectDb(const char *);
- int createDb(BaseString&);
- int getErrorNumber();
-
- unsigned long selectCountTable(const char * table);
-
-protected:
-
- bool runQuery(const char* query,
- const Properties& args,
- SqlResultSet& rows);
-
- bool isConnected();
-
- MYSQL * m_mysql;
- bool m_free_mysql; /* Don't free mysql* if allocated elsewhere */
-
-private:
-
- bool m_connected;
-
- BaseString m_host; // Computer to connect to
- BaseString m_user; // MySQL User
- BaseString m_pass; // MySQL User Password
- BaseString m_dbname; // Database to use
- BaseString m_socket; // MySQL Server Unix Socket
- BaseString m_default_file;
- BaseString m_default_group;
-
- unsigned int m_port; // MySQL Server port
-
- void setDbName(const char * name){m_dbname.assign(name);};
- void setUser(const char * user_name){m_user.assign(user_name);};
- void setPassword(const char * password){m_pass.assign(password);};
- void setHost(const char * system){m_host.assign(system);};
- void setPort(unsigned int portIn){m_port=portIn;};
- void setSocket(const char * sockIn){m_socket.assign(sockIn);};
- void printError(const char *msg);
- void printStError(MYSQL_STMT *stmt, const char *msg);
- void die(const char *file, int line, const char *expr); // stop program
-
-};
-#endif
-
diff --git a/storage/ndb/test/include/HugoAsynchTransactions.hpp b/storage/ndb/test/include/HugoAsynchTransactions.hpp
deleted file mode 100644
index ac3e0782ef8..00000000000
--- a/storage/ndb/test/include/HugoAsynchTransactions.hpp
+++ /dev/null
@@ -1,75 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef HUGO_ASYNCH_TRANSACTIONS_HPP
-#define HUGO_ASYNCH_TRANSACTIONS_HPP
-
-
-#include <NDBT.hpp>
-#include <HugoCalculator.hpp>
-#include <HugoTransactions.hpp>
-
-class HugoAsynchTransactions : private HugoTransactions {
-public:
- HugoAsynchTransactions(const NdbDictionary::Table&);
- ~HugoAsynchTransactions();
- int loadTableAsynch(Ndb*,
- int records = 0,
- int batch = 1,
- int trans = 1,
- int operations = 1);
- int pkReadRecordsAsynch(Ndb*,
- int records = 0,
- int batch= 1,
- int trans = 1,
- int operations = 1);
- int pkUpdateRecordsAsynch(Ndb*,
- int records = 0,
- int batch= 1,
- int trans = 1,
- int operations = 1);
- int pkDelRecordsAsynch(Ndb*,
- int records = 0,
- int batch = 1,
- int trans = 1,
- int operations = 1);
- void transactionCompleted();
-
- long getTransactionsCompleted();
-
-private:
- enum NDB_OPERATION {NO_INSERT, NO_UPDATE, NO_READ, NO_DELETE};
-
- void allocTransactions(int trans);
- void deallocTransactions();
-
- int executeAsynchOperation(Ndb*,
- int records,
- int batch,
- int trans,
- int operations,
- NDB_OPERATION theOperation,
- ExecType theType = Commit);
-
- long transactionsCompleted;
- int numTransactions;
- NdbConnection** transactions;
-};
-
-
-
-#endif
-
diff --git a/storage/ndb/test/include/HugoCalculator.hpp b/storage/ndb/test/include/HugoCalculator.hpp
deleted file mode 100644
index 602eefe9398..00000000000
--- a/storage/ndb/test/include/HugoCalculator.hpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NDBT_CALC_HPP
-#define NDBT_CALC_HPP
-
-#include <NDBT_ResultRow.hpp>
-
-/* *************************************************************
- * HugoCalculator
- *
- * Comon class for the Hugo test suite, provides the functions
- * that is used for calculating values to load in to table and
- * also knows how to verify a row that's been read from db
- *
- * ************************************************************/
-class HugoCalculator {
-public:
- HugoCalculator(const NdbDictionary::Table& tab);
- Int32 calcValue(int record, int attrib, int updates) const;
- const char* calcValue(int record, int attrib, int updates, char* buf,
- int len, Uint32* real_len) const;
-
- int verifyRowValues(NDBT_ResultRow* const pRow) const;
- int getIdValue(NDBT_ResultRow* const pRow) const;
- int getUpdatesValue(NDBT_ResultRow* const pRow) const;
- int isIdCol(int colId) { return m_idCol == colId; };
- int isUpdateCol(int colId){ return m_updatesCol == colId; };
-private:
- const NdbDictionary::Table& m_tab;
- int m_idCol;
- int m_updatesCol;
-};
-
-
-#endif
-
-
-
-
diff --git a/storage/ndb/test/include/HugoOperations.hpp b/storage/ndb/test/include/HugoOperations.hpp
deleted file mode 100644
index f3479185891..00000000000
--- a/storage/ndb/test/include/HugoOperations.hpp
+++ /dev/null
@@ -1,137 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef HUGO_OPERATIONS_HPP
-#define HUGO_OPERATIONS_HPP
-
-#include <NDBT.hpp>
-#include <HugoCalculator.hpp>
-#include <UtilTransactions.hpp>
-#include <Vector.hpp>
-
-class HugoOperations : public UtilTransactions {
-public:
- HugoOperations(const NdbDictionary::Table&,
- const NdbDictionary::Index* idx = 0);
-
- ~HugoOperations();
- int startTransaction(Ndb*, const NdbDictionary::Table *table= 0,
- const char *keyData= 0, Uint32 keyLen= 0);
- int setTransaction(NdbTransaction*,bool not_null_ok= false);
- int closeTransaction(Ndb*);
- NdbTransaction* getTransaction();
- void refresh();
-
- void setTransactionId(Uint64);
-
- int pkInsertRecord(Ndb*,
- int recordNo,
- int numRecords = 1,
- int updatesValue = 0);
-
- int pkWriteRecord(Ndb*,
- int recordNo,
- int numRecords = 1,
- int updatesValue = 0);
-
- int pkWritePartialRecord(Ndb*,
- int recordNo,
- int numRecords = 1);
-
- int pkReadRecord(Ndb*,
- int recordNo,
- int numRecords = 1,
- NdbOperation::LockMode lm = NdbOperation::LM_Read);
-
- int pkUpdateRecord(Ndb*,
- int recordNo,
- int numRecords = 1,
- int updatesValue = 0);
-
- int pkDeleteRecord(Ndb*,
- int recordNo,
- int numRecords = 1);
-
- int execute_Commit(Ndb*,
- AbortOption ao = AbortOnError);
- int execute_NoCommit(Ndb*,
- AbortOption ao = AbortOnError);
- int execute_Rollback(Ndb*);
-
- int saveCopyOfRecord(int numRecords = 1);
- int compareRecordToCopy(int numRecords = 1);
-
- BaseString getRecordStr(int recordNum);
- int getRecordGci(int recordNum);
-
- int setValueForAttr(NdbOperation*,
- int attrId,
- int rowId,
- int updateId);
-
- int equalForAttr(NdbOperation*,
- int attrId,
- int rowId);
-
- int equalForRow(NdbOperation*, int rowid);
-
- int setValues(NdbOperation*, int rowId, int updateId);
-
- int verifyUpdatesValue(int updatesValue, int _numRows = 0);
-
- int indexReadRecords(Ndb*, const char * idxName, int recordNo,
- bool exclusive = false,
- int records = 1);
-
- int indexUpdateRecord(Ndb*,
- const char * idxName,
- int recordNo,
- int numRecords = 1,
- int updatesValue = 0);
-
- int scanReadRecords(Ndb*, NdbScanOperation::LockMode =
- NdbScanOperation::LM_CommittedRead,
- int numRecords = 1);
-
- NdbIndexScanOperation* pIndexScanOp;
-
- NDBT_ResultRow& get_row(Uint32 idx) { return *rows[idx];}
-
- int execute_async(Ndb*, NdbTransaction::ExecType, NdbOperation::AbortOption = NdbOperation::AbortOnError);
- int execute_async_prepare(Ndb*, NdbTransaction::ExecType, NdbOperation::AbortOption = NdbOperation::AbortOnError);
-
- int wait_async(Ndb*, int timeout = -1);
-
-protected:
- void allocRows(int rows);
- void deallocRows();
-
- Vector<NDBT_ResultRow*> rows;
- HugoCalculator calc;
-
- Vector<BaseString> savedRecords;
-
- struct RsPair { NdbScanOperation* m_result_set; int records; };
- Vector<RsPair> m_result_sets;
- Vector<RsPair> m_executed_result_sets;
-
- int m_async_reply;
- int m_async_return;
- friend void HugoOperations_async_callback(int, NdbTransaction*, void*);
- void callback(int res, NdbTransaction*);
-};
-
-#endif
diff --git a/storage/ndb/test/include/HugoTransactions.hpp b/storage/ndb/test/include/HugoTransactions.hpp
deleted file mode 100644
index 207c03d4290..00000000000
--- a/storage/ndb/test/include/HugoTransactions.hpp
+++ /dev/null
@@ -1,155 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef HUGO_TRANSACTIONS_HPP
-#define HUGO_TRANSACTIONS_HPP
-
-
-#include <NDBT.hpp>
-#include <HugoCalculator.hpp>
-#include <HugoOperations.hpp>
-class NDBT_Stats;
-
-class HugoTransactions : public HugoOperations {
-public:
- HugoTransactions(const NdbDictionary::Table&,
- const NdbDictionary::Index* idx = 0);
- ~HugoTransactions();
- int loadTable(Ndb*,
- int records,
- int batch = 512,
- bool allowConstraintViolation = true,
- int doSleep = 0,
- bool oneTrans = false,
- int updateValue = 0,
- bool abort = false);
-
- int loadTableStartFrom(Ndb*,
- int startFrom,
- int records,
- int batch = 512,
- bool allowConstraintViolation = true,
- int doSleep = 0,
- bool oneTrans = false,
- int updateValue = 0,
- bool abort = false);
-
- int scanReadRecords(Ndb*,
- int records,
- int abort = 0,
- int parallelism = 0,
- NdbOperation::LockMode = NdbOperation::LM_Read,
- int scan_flags = 0);
-
- int scanReadRecords(Ndb*,
- const NdbDictionary::Index*,
- int records,
- int abort = 0,
- int parallelism = 0,
- NdbOperation::LockMode = NdbOperation::LM_Read,
- int scan_flags = 0);
-
- int pkReadRecords(Ndb*,
- int records,
- int batchsize = 1,
- NdbOperation::LockMode = NdbOperation::LM_Read);
-
- int scanUpdateRecords(Ndb*, NdbScanOperation::ScanFlag,
- int records,
- int abort = 0,
- int parallelism = 0);
-
- int scanUpdateRecords(Ndb*,
- int records,
- int abort = 0,
- int parallelism = 0);
-
- int scanUpdateRecords1(Ndb*,
- int records,
- int abort = 0,
- int parallelism = 0);
- int scanUpdateRecords2(Ndb*,
- int records,
- int abort = 0,
- int parallelism = 0);
- int scanUpdateRecords3(Ndb*,
- int records,
- int abort = 0,
- int parallelism = 0);
-
- int pkUpdateRecords(Ndb*,
- int records,
- int batchsize = 1,
- int doSleep = 0);
- int pkInterpretedUpdateRecords(Ndb*,
- int records,
- int batchsize = 1);
- int pkDelRecords(Ndb*,
- int records = 0,
- int batch = 1,
- bool allowConstraintViolation = true,
- int doSleep = 0);
- int lockRecords(Ndb*,
- int records,
- int percentToLock = 1,
- int lockTime = 1000);
-
- int fillTable(Ndb*,
- int batch=512);
-
- int fillTableStartFrom(Ndb*, int startFrom, int batch=512);
-
- /**
- * Reading using UniqHashIndex with key = pk
- */
- int indexReadRecords(Ndb*,
- const char * idxName,
- int records,
- int batchsize = 1);
-
- int indexUpdateRecords(Ndb*,
- const char * idxName,
- int records,
- int batchsize = 1);
-
- void setRetryMax(int retryMax = 100) { m_retryMax = retryMax; }
-
- Uint32 m_latest_gci;
-
- void setStatsLatency(NDBT_Stats* stats) { m_stats_latency = stats; }
-
- // allows multiple threads to update separate batches
- void setThrInfo(int thr_count, int thr_no) {
- m_thr_count = thr_count;
- m_thr_no = thr_no;
- }
-
-protected:
- NDBT_ResultRow row;
- int m_defaultScanUpdateMethod;
- int m_retryMax;
-
- NDBT_Stats* m_stats_latency;
-
- int m_thr_count; // 0 if no separation between threads
- int m_thr_no;
-};
-
-
-
-
-#endif
-
diff --git a/storage/ndb/test/include/NDBT.hpp b/storage/ndb/test/include/NDBT.hpp
deleted file mode 100644
index b30d12dc22c..00000000000
--- a/storage/ndb/test/include/NDBT.hpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NDB_TEST_HPP
-#define NDB_TEST_HPP
-
-/**
- * NdbTest.hpp
- * This is the main include file to include in test programs
- * It will include all the other include files in the NDBT-toolkit
- *
- */
-
-#include "NDBT_ReturnCodes.h"
-
-#ifdef __cplusplus
-#include "NDBT_Table.hpp"
-#include "NDBT_Tables.hpp"
-#include "NDBT_Error.hpp"
-#include "NDBT_ResultRow.hpp"
-#include "NDBT_Output.hpp"
-
-#endif
-
-
-#endif
diff --git a/storage/ndb/test/include/NDBT_DataSet.hpp b/storage/ndb/test/include/NDBT_DataSet.hpp
deleted file mode 100644
index ed1dda7c438..00000000000
--- a/storage/ndb/test/include/NDBT_DataSet.hpp
+++ /dev/null
@@ -1,140 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NDBT_DATA_SET_HPP
-#define NDBT_DATA_SET_HPP
-
-#include "NDBT_Table.hpp"
-#include <NdbApi.hpp>
-
-class NDBT_DataSet;
-
-class NDBT_DataSetFactory {
-public:
- NDBT_DataSet * createEmpty(const NDBT_Table & table,
- const char * columns[]);
-
- NDBT_DataSet * createRandom(const NDBT_DataSet & table,
- const char * columns[],
- int rows);
-
- NDBT_DataSet * createXXX(int noOfDS, const NDBT_DataSet ** datasets);
-};
-
-class NDBT_DataSet {
- friend class NDBT_DataSetFactory;
-public:
- /**
- * Rows in the data set
- */
- void setRows(int rows);
- void addRows(int rows);
-
- int getNoOfRows() const;
-
- /**
- * Columns for a row in the data set
- */
- int getNoOfColumns() const;
- int getNoOfPKs() const;
-
- const NDBT_Attribute * getColumn(int index);
- const NDBT_Attribute * getColumn(const char * name);
-
- /**
- * Data status in dataset
- */
- bool hasPK(int row);
- bool hasData(int row);
-
- /**
- * Do all rows in the dataset have a PK
- */
- bool hasPK();
-
- /**
- * Do all rows in the dataset has data
- */
- bool hasData();
-
- /**
- * Getters for data
- */
- Uint32 getUInt(int row, int index) const;
- Uint32 getUInt(int row, const char * attribute) const;
-
- Int32 getInt(int row, int index) const;
- Int32 getInt(int row, const char * attribute) const;
-
- const char * getString(int row, int index) const;
- const char * getString(int row, const char * attribute) const;
-
- bool getIsNull(int row, int index) const;
- bool getIsNull(int row, const char * attribute) const;
-
- /**
- * Setters for data
- */
- void set(int row, int index, Int32 value);
- void set(int row, const char * attr, Int32 value);
-
- void set(int row, int index, Uint32 value);
- void set(int row, const char * attr, Uint32 value);
-
- void set(int row, int index, const char * value);
- void set(int row, const char * attr, const char * value);
-
- /**
- * Comparators
- */
-
- /**
- * Is this dataset identical to other dataset
- *
- * If either of the datasets have "undefined" rows the answer is false
- */
- bool equal(const NDBT_DataSet & other) const;
-
- /**
- * Do these dataset have identical PK's
- *
- * I.e noOfRows equal
- *
- * and for each row there is a corresponding row in the other ds
- * with the same pk
- */
- bool equalPK(const NDBT_DataSet & other) const;
-
-private:
- NDBT_Attribute * columns;
-
- Uint32 noOfRows;
- Uint32 noOfPKs;
-
- Uint32 * pks;
- Uint32 * columnSizes;
-
- char * pkData;
- char * data;
-
- char * pk(int row, int pkIndex);
- char * column(int row, int columnIndex);
-
- Uint32 * hasPK;
- Uint32 * hasData;
-};
-
-#endif
diff --git a/storage/ndb/test/include/NDBT_DataSetTransaction.hpp b/storage/ndb/test/include/NDBT_DataSetTransaction.hpp
deleted file mode 100644
index 77cd2818b20..00000000000
--- a/storage/ndb/test/include/NDBT_DataSetTransaction.hpp
+++ /dev/null
@@ -1,162 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NDBT_DATA_SET_TRANSACTION_HPP
-#define NDBT_DATA_SET_TRANSACTION_HPP
-
-#include "NDBT_Table.hpp"
-#include <NdbApi.hpp>
-
-class NDBT_DataSet;
-
-/**
- * This class contains a bunch a methods
- * that operates on NDB together with a NDBT_DataSet
- * using <b>one</b> transaction
- */
-class NDBT_DataSetTransaction {
-public:
- /**
- * Store the data into ndb
- */
- static void insert(Ndb * theNdbObject,
- const NDBT_DataSet *,
- bool rollback = false);
-
- /**
- * Read data (using pk) from ndb
- */
- static void readByPk(Ndb * theNdbObject,
- NDBT_DataSet *,
- bool rollback = false);
-
- /**
- * Update data using pk
- *
- */
- static void updateByPk(Ndb * theNdbObject,
- const NDBT_DataSet *,
- bool rollback = false);
-
- /**
- * Delete
- */
- static void deleteByPk(Ndb * theNdbObject,
- const NDBT_DataSet *,
- bool rollback = false);
-};
-
-class NDBT_DataSetAsyncTransaction {
-public:
- enum OperationType {
- OT_Insert,
- OT_ReadByPk,
- OT_UpdateByPk,
- OT_DeleteByPk
- };
-
- /**
- * A callback for the NDBT_DataSetAsyncTransaction
- * interface.
- *
- * The callback method returns:
- * - the operation performed
- * - the data set
- * - if the transaction was commited or aborted
- */
- typedef (* NDBT_DataSetAsyncTransactionCallback)(OperationType,
- const NDBT_DataSet *,
- bool commit,
- void * anyObject);
- /**
- * Store the data into ndb
- */
- static void insert(Ndb * theNdbObject,
- const NDBT_DataSet *,
- bool rollback = false,
- NDBT_DataSetAsyncTransactionCallback fun,
- void * anyObject);
-
- /**
- * Read data (using pk) from ndb
- */
- static void readByPk(Ndb * theNdbObject,
- NDBT_DataSet *,
- bool rollback = false,
- NDBT_DataSetAsyncTransactionCallback fun,
- void * anyObject);
-
-
- /**
- * Update data using pk
- *
- */
- static void updateByPk(Ndb * theNdbObject,
- const NDBT_DataSet *,
- bool rollback = false,
- NDBT_DataSetAsyncTransactionCallback fun,
- void * anyObject);
-
-
- /**
- * Delete
- */
- static void deleteByPk(Ndb * theNdbObject,
- const NDBT_DataSet *,
- bool rollback = false,
- NDBT_DataSetAsyncTransactionCallback fun,
- void * anyObject);
-
-};
-
-class NDBT_DataSetBulkOperation {
-public:
- /**
- * Store the data into ndb
- */
- static void insert(Ndb * theNdbObject,
- const NDBT_DataSet *,
- int parallellTransactions = 1,
- int operationsPerTransaction = 10);
-
- /**
- * Read data (using pk) from ndb
- */
- static void readByPk(Ndb * theNdbObject,
- NDBT_DataSet *,
- int parallellTransactions = 1,
- int operationsPerTransaction = 10);
-
- /**
- * Update data using pk
- *
- */
- static void updateByPk(Ndb * theNdbObject,
- const NDBT_DataSet *,
- int parallellTransactions = 1,
- int operationsPerTransaction = 10);
-
- /**
- * Delete
- */
- static void deleteByPk(Ndb * theNdbObject,
- const NDBT_DataSet *,
- int parallellTransactions = 1,
- int operationsPerTransaction = 10);
-};
-
-
-#endif
diff --git a/storage/ndb/test/include/NDBT_Error.hpp b/storage/ndb/test/include/NDBT_Error.hpp
deleted file mode 100644
index 1d057d6b90f..00000000000
--- a/storage/ndb/test/include/NDBT_Error.hpp
+++ /dev/null
@@ -1,101 +0,0 @@
-/* Copyright (c) 2003, 2005, 2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NDBT_Error_HPP
-#define NDBT_Error_HPP
-
-#include <NdbOut.hpp>
-#include <NdbError.hpp>
-
-/**
- * NDBT_Error.hpp
- * This is the main include file about error handling in NDBT test programs
- *
- */
-class ErrorData {
-
-public:
- ErrorData();
- ~ErrorData();
-
- /**
- * Parse cmd line arg
- *
- * Return true if successeful
- */
- bool parseCmdLineArg(const char ** argv, int & i);
-
- /**
- * Print cmd line arguments
- */
- void printCmdLineArgs(NdbOut & out = ndbout);
-
- /**
- * Print settings
- */
- void printSettings(NdbOut & out = ndbout);
-
- /**
- * Print error count
- */
- void printErrorCounters(NdbOut & out = ndbout) const;
-
- /**
- * Reset error counters
- */
- void resetErrorCounters();
-
- /**
- *
- */
- int handleErrorCommon(const NdbError & error);
-
-private:
- bool key_error;
- bool temporary_resource_error;
- bool insufficient_space_error;
- bool node_recovery_error;
- bool overload_error;
- bool timeout_error;
- bool internal_error;
- bool user_error;
- bool application_error;
-
- Uint32 * errorCountArray;
-};
-
-//
-// ERR prints an NdbError object together with a description of where the
-// error occured
-//
-#define ERR_OUT(where, error) \
- { where << "ERROR: " << error.code << " " \
- << error.message << endl \
- << " " << "Status: " << error.status \
- << ", Classification: " << error.classification << endl\
- << " " << "File: " << __FILE__ \
- << " (Line: " << __LINE__ << ")" << endl \
- ; \
- }
-
-#define ERR(error) \
-{ \
- const NdbError &_error= (error); \
- ERR_OUT(g_err, _error); \
-}
-#define ERR_INFO(error) ERR_OUT(g_info, error)
-
-#endif
diff --git a/storage/ndb/test/include/NDBT_Output.hpp b/storage/ndb/test/include/NDBT_Output.hpp
deleted file mode 100644
index 3d1fa94acc4..00000000000
--- a/storage/ndb/test/include/NDBT_Output.hpp
+++ /dev/null
@@ -1,30 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NDBT_Output_HPP
-#define NDBT_Output_HPP
-
-#include <OutputStream.hpp>
-#include <NdbOut.hpp>
-
-void setOutputLevel(int i);
-
-extern FilteredNdbOut g_err;
-extern FilteredNdbOut g_warning;
-extern FilteredNdbOut g_info;
-extern FilteredNdbOut g_debug;
-
-#endif
diff --git a/storage/ndb/test/include/NDBT_ResultRow.hpp b/storage/ndb/test/include/NDBT_ResultRow.hpp
deleted file mode 100644
index 073eef64396..00000000000
--- a/storage/ndb/test/include/NDBT_ResultRow.hpp
+++ /dev/null
@@ -1,61 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NDBT_RESULTROW_HPP
-#define NDBT_RESULTROW_HPP
-
-#include <NdbApi.hpp>
-
-class NDBT_ResultRow {
-public:
- NDBT_ResultRow(const NdbDictionary::Table &tab, char attrib_delimiter='\t');
- ~NDBT_ResultRow();
- NdbRecAttr * & attributeStore(int i);
- const NdbRecAttr * attributeStore(int i) const ;
- const NdbRecAttr * attributeStore(const char* name) const ;
-
- BaseString c_str() const ;
-
- NdbOut & header (NdbOut &) const;
- friend NdbOut & operator << (NdbOut&, const NDBT_ResultRow &);
-
- /**
- * Make copy of NDBT_ResultRow
- */
- NDBT_ResultRow * clone() const;
-
- bool operator==(const NDBT_ResultRow&) const ;
- bool operator!=(const NDBT_ResultRow& other) const {
- return ! (*this == other);
- }
-
-private:
- int cols;
- char **names;
- NdbRecAttr **data;
- char ad[2];
-
- bool m_ownData;
- const NdbDictionary::Table & m_table;
-
- NDBT_ResultRow(const NDBT_ResultRow &);
- NDBT_ResultRow& operator=(const NDBT_ResultRow &);
-};
-
-
-
-
-#endif
diff --git a/storage/ndb/test/include/NDBT_ReturnCodes.h b/storage/ndb/test/include/NDBT_ReturnCodes.h
deleted file mode 100644
index f28f37e3838..00000000000
--- a/storage/ndb/test/include/NDBT_ReturnCodes.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/* Copyright (c) 2003, 2005, 2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NDBT_RETURNCODES_H
-#define NDBT_RETURNCODES_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define NDBT_OK 0
-#define NDBT_FAILED 1
-#define NDBT_WRONGARGS 2
-#define NDBT_TEMPORARY 3
-/**
- * NDBT_ProgramExit
- * This function will print the returncode together with a prefix on
- * the screen and then exit the test program.
- * Call this function when exiting the main function in your test programs
- * Returns the return code
- */
-int NDBT_ProgramExit(int rcode);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/storage/ndb/test/include/NDBT_Stats.hpp b/storage/ndb/test/include/NDBT_Stats.hpp
deleted file mode 100644
index 62b831a65db..00000000000
--- a/storage/ndb/test/include/NDBT_Stats.hpp
+++ /dev/null
@@ -1,74 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NDBT_STATS_HPP
-#define NDBT_STATS_HPP
-
-#include <ndb_global.h>
-
-class NDBT_Stats {
-public:
- NDBT_Stats() { reset(); }
-
- void reset() { sum = sum2 = 0.0; max = DBL_MIN; ; min = DBL_MAX; n = 0;}
-
- void addObservation(double t) {
- sum+= t;
- sum2 += (t*t);
- n++;
- if(min > t) min = t;
- if(max < t) max = t;
- }
-
- double getMean() const { return sum/n;}
- double getStddev() const { return sqrt(getVariance()); }
- double getVariance() const { return (n*sum2 - (sum*sum))/(n*n);}
- double getMin() const { return min;}
- double getMax() const { return max;}
- int getCount() const { return n;}
-
- NDBT_Stats & operator+=(const NDBT_Stats & c){
- sum += c.sum;
- sum2 += c.sum2;
- n += c.n;
- if(min > c.min) min = c.min;
- if(max < c.max) max = c.max;
- return * this;
- }
-private:
- double sum;
- double sum2;
- int n;
- double min, max;
-};
-
-inline
-double
-NDB_SQRT(double x){
- assert(x >= 0);
-
- double y = 0;
- double s = 1;
- double r = 0;
- while(y <= x){
- y += s;
- s += 2;
- r += 1;
- }
- return r - 1;
-}
-
-#endif
diff --git a/storage/ndb/test/include/NDBT_Table.hpp b/storage/ndb/test/include/NDBT_Table.hpp
deleted file mode 100644
index 05b94b8ffca..00000000000
--- a/storage/ndb/test/include/NDBT_Table.hpp
+++ /dev/null
@@ -1,94 +0,0 @@
-/* Copyright (c) 2003-2006 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NDBT_TABLE_HPP
-#define NDBT_TABLE_HPP
-
-#include <ndb_global.h>
-
-#include <NdbApi.hpp>
-#include <NdbOut.hpp>
-
-class NDBT_Attribute : public NdbDictionary::Column {
-public:
- NDBT_Attribute(const char* _name,
- NdbDictionary::Column::Type _type,
- int _length = 1,
- bool _pk = false,
- bool _nullable = false,
- CHARSET_INFO *cs= 0,
- NdbDictionary::Column::StorageType storage = NdbDictionary::Column::StorageTypeMemory):
- NdbDictionary::Column(_name)
- {
- assert(_name != 0);
-
- setType(_type);
- setLength(_length);
- setNullable(_nullable);
- setPrimaryKey(_pk);
- if (cs)
- {
- setCharset(cs);
- }
- setStorageType(storage);
- }
-};
-
-class NDBT_Table : public NdbDictionary::Table {
- /**
- * Print meta information about table
- * (information on how it is strored, what the attributes look like etc.)
- */
- friend class NdbOut& operator <<(class NdbOut&, const NDBT_Table &);
-public:
-
- NDBT_Table(const char* name,
- int noOfAttributes,
- const NdbDictionary::Column attributes[])
- : NdbDictionary::Table(name)
- {
- assert(name != 0);
-
- //setStoredTable(stored);
- for(int i = 0; i<noOfAttributes; i++)
- addColumn(attributes[i]);
-
- // validate() might cause initialization order problem with charset
- NdbError error;
- int ret = aggregate(error);
- assert(ret == 0);
- }
-
- static const NdbDictionary::Table * discoverTableFromDb(Ndb* ndb,
- const char * name);
-};
-
-inline
-const NdbDictionary::Table *
-NDBT_Table::discoverTableFromDb(Ndb* ndb, const char * name){
- return ndb->getDictionary()->getTable(name);
-}
-
-
-/**
- * Print meta information about index
- * (information on how it is strored, what the attributes look like etc.)
- */
-class NdbOut& operator <<(class NdbOut&, const NdbDictionary::Index &);
-
-
-
-#endif
diff --git a/storage/ndb/test/include/NDBT_Tables.hpp b/storage/ndb/test/include/NDBT_Tables.hpp
deleted file mode 100644
index 573559f7ea0..00000000000
--- a/storage/ndb/test/include/NDBT_Tables.hpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Copyright (c) 2003-2006 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NDBT_TABLES_HPP
-#define NDBT_TABLES_HPP
-
-
-#include <NDBT.hpp>
-#include <Ndb.hpp>
-#include <NdbDictionary.hpp>
-#include <NDBT_Table.hpp>
-
-typedef int (* NDBT_CreateTableHook)(Ndb*, NdbDictionary::Table&, int when,
- void* arg);
-
-class NDBT_Tables {
-public:
-
- static int createTable(Ndb* pNdb, const char* _name, bool _temp = false,
- bool existsOK = false, NDBT_CreateTableHook = 0,
- void* arg = 0);
- static int createAllTables(Ndb* pNdb, bool _temp, bool existsOK = false);
- static int createAllTables(Ndb* pNdb);
-
- static int dropAllTables(Ndb* pNdb);
-
- static int print(const char * name);
- static int printAll();
-
- static const NdbDictionary::Table* getTable(const char* _nam);
- static const NdbDictionary::Table* getTable(int _num);
- static int getNumTables();
-
- static const char** getIndexes(const char* table);
-
- static int create_default_tablespace(Ndb* pNdb);
-
-private:
- static const NdbDictionary::Table* tableWithPkSize(const char* _nam, Uint32 pkSize);
-};
-#endif
-
-
diff --git a/storage/ndb/test/include/NDBT_Test.hpp b/storage/ndb/test/include/NDBT_Test.hpp
deleted file mode 100644
index 1197d9646b5..00000000000
--- a/storage/ndb/test/include/NDBT_Test.hpp
+++ /dev/null
@@ -1,470 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NDBT_TEST_HPP
-#define NDBT_TEST_HPP
-
-#include <ndb_global.h>
-
-#include "NDBT_ReturnCodes.h"
-#include <Properties.hpp>
-#include <NdbThread.h>
-#include <NdbSleep.h>
-#include <NdbCondition.h>
-#include <NdbTimer.hpp>
-#include <Vector.hpp>
-#include <NdbApi.hpp>
-#include <NdbDictionary.hpp>
-
-class NDBT_Step;
-class NDBT_TestCase;
-class NDBT_TestSuite;
-class NDBT_TestCaseImpl1;
-
-class NDBT_Context {
-public:
- Ndb_cluster_connection& m_cluster_connection;
-
- NDBT_Context(Ndb_cluster_connection&);
- ~NDBT_Context();
- const NdbDictionary::Table* getTab();
- const NdbDictionary::Table** getTables();
- int getNumTables() const;
- const char * getTableName(int) const;
- NDBT_TestSuite* getSuite();
- NDBT_TestCase* getCase();
-
- // Get arguments
- int getNumRecords() const;
- int getNumLoops() const;
- char * getRemoteMgm() const;
- // Common place to store state between
- // steps, for example information from one step to the
- // verifier about how many records have been inserted
- Uint32 getProperty(const char*, Uint32 = 0 );
- const char* getProperty(const char*, const char* );
- void setProperty(const char*, Uint32);
- void setProperty(const char*, const char*);
-
- // Signal that a property value that another
- // thread might be waiting for has changed
- void broadcast();
- // Wait for the signal that a property has changed
- void wait();
- void wait_timeout(int msec);
-
- // Wait until the property has been set to a certain value
- bool getPropertyWait(const char*, Uint32);
- const char* getPropertyWait(const char*, const char* );
-
- void decProperty(const char *);
- void incProperty(const char *);
-
- // Communicate with other tests
- void stopTest();
- bool isTestStopped();
-
- // Communicate with tests in other API nodes
- // This is done using a "system" table in the database
- Uint32 getDbProperty(const char*);
- bool setDbProperty(const char*, Uint32);
-
- void setTab(const NdbDictionary::Table*);
- void addTab(const NdbDictionary::Table*);
- void setRemoteMgm(char * mgm);
-
- /**
- * Get no of steps running/completed
- */
- int getNoOfRunningSteps() const ;
- int getNoOfCompletedSteps() const ;
-
- /**
- * Thread sync
- */
- void sync_down(const char * key);
- void sync_up_and_wait(const char * key, Uint32 count = 0);
-private:
- friend class NDBT_Step;
- friend class NDBT_TestSuite;
- friend class NDBT_TestCase;
- friend class NDBT_TestCaseImpl1;
-
- void setSuite(NDBT_TestSuite*);
- void setCase(NDBT_TestCase*);
- void setNumRecords(int);
- void setNumLoops(int);
- Vector<const NdbDictionary::Table*> tables;
- NDBT_TestSuite* suite;
- NDBT_TestCase* testcase;
- Ndb* ndb;
- int records;
- int loops;
- bool stopped;
- char * remote_mgm;
- Properties props;
- NdbMutex* propertyMutexPtr;
- NdbCondition* propertyCondPtr;
-};
-
-typedef int (NDBT_TESTFUNC)(NDBT_Context*, NDBT_Step*);
-
-class NDBT_Step {
-public:
- NDBT_Step(NDBT_TestCase* ptest,
- const char* pname,
- NDBT_TESTFUNC* pfunc);
- virtual ~NDBT_Step() {}
- int execute(NDBT_Context*);
- virtual int setUp(Ndb_cluster_connection&) = 0;
- virtual void tearDown() = 0;
- void setContext(NDBT_Context*);
- NDBT_Context* getContext();
- void print();
- const char* getName() { return name; }
- int getStepNo() { return step_no; }
- void setStepNo(int n) { step_no = n; }
-protected:
- NDBT_Context* m_ctx;
- const char* name;
- NDBT_TESTFUNC* func;
- NDBT_TestCase* testcase;
- int step_no;
-};
-
-class NDBT_NdbApiStep : public NDBT_Step {
-public:
- NDBT_NdbApiStep(NDBT_TestCase* ptest,
- const char* pname,
- NDBT_TESTFUNC* pfunc);
- virtual ~NDBT_NdbApiStep() {}
- virtual int setUp(Ndb_cluster_connection&);
- virtual void tearDown();
-
- Ndb* getNdb();
-protected:
- Ndb* ndb;
-};
-
-class NDBT_ParallelStep : public NDBT_NdbApiStep {
-public:
- NDBT_ParallelStep(NDBT_TestCase* ptest,
- const char* pname,
- NDBT_TESTFUNC* pfunc);
- virtual ~NDBT_ParallelStep() {}
-};
-
-class NDBT_Verifier : public NDBT_NdbApiStep {
-public:
- NDBT_Verifier(NDBT_TestCase* ptest,
- const char* name,
- NDBT_TESTFUNC* func);
- virtual ~NDBT_Verifier() {}
-};
-
-class NDBT_Initializer : public NDBT_NdbApiStep {
-public:
- NDBT_Initializer(NDBT_TestCase* ptest,
- const char* name,
- NDBT_TESTFUNC* func);
- virtual ~NDBT_Initializer() {}
-};
-
-class NDBT_Finalizer : public NDBT_NdbApiStep {
-public:
- NDBT_Finalizer(NDBT_TestCase* ptest,
- const char* name,
- NDBT_TESTFUNC* func);
- virtual ~NDBT_Finalizer() {}
-};
-
-
-class NDBT_TestCase {
-public:
- NDBT_TestCase(NDBT_TestSuite* psuite,
- const char* name,
- const char* comment);
- virtual ~NDBT_TestCase() {}
-
- // This is the default executor of a test case
- // When a test case is executed it will need to be suplied with a number of
- // different parameters and settings, these are passed to the test in the
- // NDBT_Context object
- virtual int execute(NDBT_Context*);
- void setProperty(const char*, Uint32);
- void setProperty(const char*, const char*);
- virtual void print() = 0;
- virtual void printHTML() = 0;
-
- const char* getName(){return name;};
- virtual bool tableExists(NdbDictionary::Table* aTable) = 0;
- virtual bool isVerify(const NdbDictionary::Table* aTable) = 0;
-
- virtual void saveTestResult(const NdbDictionary::Table* ptab, int result) = 0;
- virtual void printTestResult() = 0;
- void initBeforeTest(){ timer.doReset();};
-
- /**
- * Get no of steps running/completed
- */
- virtual int getNoOfRunningSteps() const = 0;
- virtual int getNoOfCompletedSteps() const = 0;
-
- bool m_all_tables;
- bool m_has_run;
-
-protected:
- virtual int runInit(NDBT_Context* ctx) = 0;
- virtual int runSteps(NDBT_Context* ctx) = 0;
- virtual int runVerifier(NDBT_Context* ctx) = 0;
- virtual int runFinal(NDBT_Context* ctx) = 0;
- virtual void addTable(const char* aTableName, bool isVerify=true) = 0;
-
- void startTimer(NDBT_Context*);
- void stopTimer(NDBT_Context*);
- void printTimer(NDBT_Context*);
-
- BaseString _name;
- BaseString _comment;
- const char* name;
- const char* comment;
- NDBT_TestSuite* suite;
- Properties props;
- NdbTimer timer;
- bool isVerifyTables;
-};
-
-static const int FAILED_TO_CREATE = 1000;
-static const int FAILED_TO_DISCOVER = 1001;
-
-
-class NDBT_TestCaseResult{
-public:
- NDBT_TestCaseResult(const char* name, int _result, NDB_TICKS _ticks):
- m_result(_result){
- m_name.assign(name);
- m_ticks = _ticks;
-
- };
- const char* getName(){return m_name.c_str(); };
- int getResult(){return m_result; };
- const char* getTimeStr(){
- // Convert to Uint32 in order to be able to print it to screen
- Uint32 lapTime = (Uint32)m_ticks;
- Uint32 secTime = lapTime/1000;
- BaseString::snprintf(buf, 255, "%d secs (%d ms)", secTime, lapTime);
- return buf;
- }
-private:
- char buf[255];
- int m_result;
- BaseString m_name;
- NDB_TICKS m_ticks;
-};
-
-class NDBT_TestCaseImpl1 : public NDBT_TestCase {
-public:
- NDBT_TestCaseImpl1(NDBT_TestSuite* psuite,
- const char* name,
- const char* comment);
- virtual ~NDBT_TestCaseImpl1();
- int addStep(NDBT_Step*);
- int addVerifier(NDBT_Verifier*);
- int addInitializer(NDBT_Initializer*);
- int addFinalizer(NDBT_Finalizer*);
- void addTable(const char*, bool);
- bool tableExists(NdbDictionary::Table*);
- bool isVerify(const NdbDictionary::Table*);
- void reportStepResult(const NDBT_Step*, int result);
- // int execute(NDBT_Context* ctx);
- int runInit(NDBT_Context* ctx);
- int runSteps(NDBT_Context* ctx);
- int runVerifier(NDBT_Context* ctx);
- int runFinal(NDBT_Context* ctx);
- void print();
- void printHTML();
-
- virtual int getNoOfRunningSteps() const;
- virtual int getNoOfCompletedSteps() const;
-private:
- static const int NORESULT = 999;
-
- void saveTestResult(const NdbDictionary::Table* ptab, int result);
- void printTestResult();
-
- void startStepInThread(int stepNo, NDBT_Context* ctx);
- void waitSteps();
- Vector<NDBT_Step*> steps;
- Vector<NdbThread*> threads;
- Vector<int> results;
- Vector<NDBT_Verifier*> verifiers;
- Vector<NDBT_Initializer*> initializers;
- Vector<NDBT_Finalizer*> finalizers;
- Vector<const NdbDictionary::Table*> testTables;
- Vector<NDBT_TestCaseResult*> testResults;
- unsigned numStepsFail;
- unsigned numStepsOk;
- unsigned numStepsCompleted;
- NdbMutex* waitThreadsMutexPtr;
- NdbCondition* waitThreadsCondPtr;
-};
-
-
-// A NDBT_TestSuite is a collection of TestCases
-// the test suite will know how to execute the test cases
-class NDBT_TestSuite {
-public:
- NDBT_TestSuite(const char* name);
- ~NDBT_TestSuite();
-
- // Default executor of a test suite
- // supply argc and argv as parameters
- int execute(int, const char**);
-
- // NDBT's test tables are fixed and it always create
- // and drop fixed table when execute, add this method
- // in order to run CTX only and adapt to some new
- // customized testsuite
- int executeOneCtx(Ndb_cluster_connection&,
- const NdbDictionary::Table* ptab, const char* testname = NULL);
-
- // These function can be used from main in the test program
- // to control the behaviour of the testsuite
- void setCreateTable(bool); // Create table before test func is called
- void setCreateAllTables(bool); // Create all tables before testsuite is executed
- void setRunAllTables(bool); // Run once with all tables
-
- // Prints the testsuite, testcases and teststeps
- void printExecutionTree();
- void printExecutionTreeHTML();
-
- // Prints list of testcases
- void printCases();
-
- // Print summary of executed tests
- void printTestCaseSummary(const char* tcname = NULL);
-
- /**
- * Returns current date and time in the format of 2002-12-04 10:00:01
- */
- const char* getDate();
-
- // Returns true if timing info should be printed
- bool timerIsOn();
-
- int addTest(NDBT_TestCase* pTest);
-
- // Table create tweaks
- int createHook(Ndb*, NdbDictionary::Table&, int when);
- Vector<BaseString> m_tables_in_test;
-
- void setTemporaryTables(bool val);
- bool getTemporaryTables() const;
-private:
- int executeOne(Ndb_cluster_connection&,
- const char* _tabname, const char* testname = NULL);
- int executeAll(Ndb_cluster_connection&,
- const char* testname = NULL);
- void execute(Ndb_cluster_connection&,
- Ndb*, const NdbDictionary::Table*, const char* testname = NULL);
-
- int report(const char* _tcname = NULL);
- int reportAllTables(const char* );
- const char* name;
- char* remote_mgm;
- int numTestsOk;
- int numTestsFail;
- int numTestsExecuted;
- Vector<NDBT_TestCase*> tests;
- NDBT_Context* ctx;
- int records;
- int loops;
- int timer;
- NdbTimer testSuiteTimer;
- bool createTable;
- bool diskbased;
- bool runonce;
- const char* tsname;
- bool createAllTables;
- bool temporaryTables;
-};
-
-
-
-#define NDBT_TESTSUITE(suitname) \
-class C##suitname : public NDBT_TestSuite { \
-public: \
-C##suitname():NDBT_TestSuite(#suitname){ \
- NDBT_TestCaseImpl1* pt; pt = NULL; \
- NDBT_Step* pts; pts = NULL; \
- NDBT_Verifier* ptv; ptv = NULL; \
- NDBT_Initializer* pti; pti = NULL; \
- NDBT_Finalizer* ptf; ptf = NULL;
-
-#define TESTCASE(testname, comment) \
- pt = new NDBT_TestCaseImpl1(this, testname, comment); \
- addTest(pt);
-
-#define TC_PROPERTY(propname, propval) \
- pt->setProperty(propname, propval);
-
-#define STEP(stepfunc) \
- pts = new NDBT_ParallelStep(pt, #stepfunc, stepfunc); \
- pt->addStep(pts);
-
-// Add a number of equal steps to the testcase
-#define STEPS(stepfunc, num) \
- { int i; for (i = 0; i < num; i++){ \
- pts = new NDBT_ParallelStep(pt, #stepfunc, stepfunc); \
- pt->addStep(pts);\
- } }
-
-#define VERIFIER(stepfunc) \
- ptv = new NDBT_Verifier(pt, #stepfunc, stepfunc); \
- pt->addVerifier(ptv);
-
-#define INITIALIZER(stepfunc) \
- pti = new NDBT_Initializer(pt, #stepfunc, stepfunc); \
- pt->addInitializer(pti);
-
-#define FINALIZER(stepfunc) \
- ptf = new NDBT_Finalizer(pt, #stepfunc, stepfunc); \
- pt->addFinalizer(ptf);
-
-// Test case can be run only on this table(s), can be multiple tables
-// Ex TABLE("T1")
-// TABLE("T3")
-// Means test will only be run on T1 and T3
-#define TABLE(tableName) \
- pt->addTable(tableName, true);
-
-// Test case can be run on all tables except
-// Ex NOT_TABLE("T10")
-// Means test will be run on all tables execept T10
-#define NOT_TABLE(tableName) \
- pt->addTable(tableName, false);
-
-// Text case will only be run once, not once per table as normally
-#define ALL_TABLES() \
- pt->m_all_tables= true;
-
-#define NDBT_TESTSUITE_END(suitname) \
- } } ; C##suitname suitname
-
-// Helper functions for retrieving variables from NDBT_Step
-#define GETNDB(ps) ((NDBT_NdbApiStep*)ps)->getNdb()
-
-#endif
diff --git a/storage/ndb/test/include/NDBT_Thread.hpp b/storage/ndb/test/include/NDBT_Thread.hpp
deleted file mode 100644
index e0ac3e675b9..00000000000
--- a/storage/ndb/test/include/NDBT_Thread.hpp
+++ /dev/null
@@ -1,227 +0,0 @@
-/* Copyright (c) 2003, 2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NDB_THREAD_HPP
-#define NDB_THREAD_HPP
-
-#include <NdbMutex.h>
-#include <NdbCondition.h>
-#include <NdbThread.h>
-
-// NDBT_Thread ctor -> NDBT_Thread_run -> thr.run()
-extern "C" {
-static void* NDBT_Thread_run(void* arg);
-}
-
-// Function to run in a thread.
-
-typedef void NDBT_ThreadFunc(class NDBT_Thread&);
-
-/*
- * NDBT_Thread
- *
- * Represents a thread. The thread pauses at startup.
- * Main process sets a function to run. When the function
- * returns, the thread pauses again to wait for a command.
- * This allows main process to sync with the thread and
- * exchange data with it.
- *
- * Input to thread is typically options. The input area
- * is read-only in the thread. Output from thread is
- * results such as statistics. Error code is handled
- * separately.
- *
- * Pointer to Ndb object and method to create it are
- * provided for convenience.
- */
-
-class NDBT_ThreadSet;
-
-class NDBT_Thread {
-public:
- NDBT_Thread();
- NDBT_Thread(NDBT_ThreadSet* thread_set, int thread_no);
- void create(NDBT_ThreadSet* thread_set, int thread_no);
- ~NDBT_Thread();
-
- // if part of a set
- inline NDBT_ThreadSet& get_thread_set() const {
- assert(m_thread_set != 0);
- return *m_thread_set;
- }
- inline int get_thread_no() const {
- return m_thread_no;
- }
-
- // { Wait -> Start -> Stop }+ -> Exit
- enum State {
- Wait = 1, // wait for command
- Start, // run current function
- Stop, // stopped (paused) when current function done
- Exit // exit thread
- };
-
- // tell thread to start running current function
- void start();
- // wait for thread to stop when function is done
- void stop();
- // tell thread to exit
- void exit();
- // collect thread after exit
- void join();
-
- // set function to run
- inline void set_func(NDBT_ThreadFunc* func) {
- m_func = func;
- }
-
- // input area
- inline void set_input(const void* input) {
- m_input = input;
- }
- inline const void* get_input() const {
- return m_input;
- }
-
- // output area
- inline void set_output(void* output) {
- m_output = output;
- }
- inline void* get_output() const {
- return m_output;
- }
- template <class T> inline void set_output() {
- set_output(new T);
- }
- inline void delete_output() {
- delete m_output;
- m_output = 0;
- }
-
- // thread-specific Ndb object
- inline class Ndb* get_ndb() const {
- return m_ndb;
- }
- int connect(class Ndb_cluster_connection*, const char* db = "TEST_DB");
- void disconnect();
-
- // error code (OS, Ndb, other)
- void clear_err() {
- m_err = 0;
- }
- void set_err(int err) {
- m_err = err;
- }
- int get_err() const {
- return m_err;
- }
-
-private:
- friend class NDBT_ThreadSet;
- friend void* NDBT_Thread_run(void* arg);
-
- enum { Magic = 0xabacadae };
- Uint32 m_magic;
-
- State m_state;
- NDBT_ThreadSet* m_thread_set;
- int m_thread_no;
-
- NDBT_ThreadFunc* m_func;
- const void* m_input;
- void* m_output;
- class Ndb* m_ndb;
- int m_err;
-
- // run the thread
- void run();
-
- void lock() {
- NdbMutex_Lock(m_mutex);
- }
- void unlock() {
- NdbMutex_Unlock(m_mutex);
- }
-
- void wait() {
- NdbCondition_Wait(m_cond, m_mutex);
- }
- void signal() {
- NdbCondition_Signal(m_cond);
- }
-
- NdbMutex* m_mutex;
- NdbCondition* m_cond;
- NdbThread* m_thread;
- void* m_status;
-};
-
-/*
- * A set of threads, indexed from 0 to count-1. Methods
- * are applied to each thread (serially). Input area is
- * common to all threads. Output areas are allocated
- * separately according to a template class.
- */
-
-class NDBT_ThreadSet {
-public:
- NDBT_ThreadSet(int count);
- ~NDBT_ThreadSet();
-
- inline int get_count() const {
- return m_count;
- }
- inline NDBT_Thread& get_thread(int n) {
- assert(n < m_count && m_thread[n] != 0);
- return *m_thread[n];
- }
-
- // tell each thread to start running
- void start();
- // wait for each thread to stop
- void stop();
- // tell each thread to exit
- void exit();
- // collect each thread after exit
- void join();
-
- // set function to run in each thread
- void set_func(NDBT_ThreadFunc* func);
-
- // set input area (same instance in each thread)
- void set_input(const void* input);
-
- // set output areas
- template <class T> inline void set_output() {
- for (int n = 0; n < m_count; n++) {
- NDBT_Thread& thr = *m_thread[n];
- thr.set_output<T>();
- }
- }
- void delete_output();
-
- // thread-specific Ndb objects
- int connect(class Ndb_cluster_connection*, const char* db = "TEST_DB");
- void disconnect();
-
- int get_err() const;
-
-private:
- int m_count;
- NDBT_Thread** m_thread;
-};
-
-#endif
diff --git a/storage/ndb/test/include/NdbBackup.hpp b/storage/ndb/test/include/NdbBackup.hpp
deleted file mode 100644
index 44bec57fb55..00000000000
--- a/storage/ndb/test/include/NdbBackup.hpp
+++ /dev/null
@@ -1,54 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NDBT_BACKUP_HPP
-#define NDBT_BACKUP_HPP
-
-#include <mgmapi.h>
-#include <Vector.hpp>
-#include "NdbConfig.hpp"
-#include <NdbRestarter.hpp>
-
-class NdbBackup : public NdbConfig {
-public:
- NdbBackup(int _own_id, const char* _addr = 0)
- : NdbConfig(_own_id, _addr) {};
-
- int start(unsigned & _backup_id);
- int restore(unsigned _backup_id);
-
- int NFMaster(NdbRestarter& _restarter);
- int NFMasterAsSlave(NdbRestarter& _restarter);
- int NFSlave(NdbRestarter& _restarter);
- int NF(NdbRestarter& _restarter, int *NFDuringBackup_codes, const int sz, bool onMaster);
-
- int FailMaster(NdbRestarter& _restarter);
- int FailMasterAsSlave(NdbRestarter& _restarter);
- int FailSlave(NdbRestarter& _restarter);
- int Fail(NdbRestarter& _restarter, int *Fail_codes, const int sz, bool onMaster);
-
-private:
-
- int execRestore(bool _restore_data,
- bool _restore_meta,
- int _node_id,
- unsigned _backup_id);
-
- const char * getBackupDataDirForNode(int _node_id);
-
-};
-
-#endif
diff --git a/storage/ndb/test/include/NdbConfig.hpp b/storage/ndb/test/include/NdbConfig.hpp
deleted file mode 100644
index 4e8ca7141ec..00000000000
--- a/storage/ndb/test/include/NdbConfig.hpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NDBT_CONFIG_HPP
-#define NDBT_CONFIG_HPP
-
-#include <ndb_types.h>
-#include <mgmapi.h>
-#include <Vector.hpp>
-#include <NdbRestarter.hpp>
-#include <mgmapi_config_parameters.h>
-
-class NdbConfig : public NdbRestarter {
-public:
- NdbConfig(int own_id, const char* addr = 0)
- : NdbRestarter(addr),
- ownNodeId(own_id) {};
-
- bool getProperty(unsigned nodeid, unsigned type, unsigned key, Uint32 * val);
-
- bool getHostName(unsigned int node_id, const char ** hostname);
- //protected:
- int ownNodeId;
-};
-
-#endif
diff --git a/storage/ndb/test/include/NdbGrep.hpp b/storage/ndb/test/include/NdbGrep.hpp
deleted file mode 100644
index dc7fa770c9d..00000000000
--- a/storage/ndb/test/include/NdbGrep.hpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NDBT_GREP_HPP
-#define NDBT_GREP_HPP
-
-#include <mgmapi.h>
-#include <Vector.hpp>
-#include "NdbConfig.hpp"
-#include <NdbRestarter.hpp>
-#include <NDBT.hpp>
-#include <NDBT_Test.hpp>
-class NdbGrep : public NdbConfig {
-public:
- NdbGrep(int _own_id, const char* _addr = 0)
- : NdbConfig(_own_id, _addr) {};
-
- int start();
- int stop();
- int query();
-
-
- int verify(NDBT_Context* ctx);
-
-
- int NFMaster(NdbRestarter& _restarter);
- int NFMasterAsSlave(NdbRestarter& _restarter);
- int NFSlave(NdbRestarter& _restarter);
- int NF(NdbRestarter& _restarter, int *NFDuringGrep_codes, const int sz, bool onMaster);
-
- int FailMaster(NdbRestarter& _restarter);
- int FailMasterAsSlave(NdbRestarter& _restarter);
- int FailSlave(NdbRestarter& _restarter);
- int Fail(NdbRestarter& _restarter, int *Fail_codes, const int sz, bool onMaster);
-
-private:
-
-};
-
-#endif
diff --git a/storage/ndb/test/include/NdbMixRestarter.hpp b/storage/ndb/test/include/NdbMixRestarter.hpp
deleted file mode 100644
index c532243297c..00000000000
--- a/storage/ndb/test/include/NdbMixRestarter.hpp
+++ /dev/null
@@ -1,75 +0,0 @@
-/* Copyright (c) 2003, 2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NDBT_MIX_RESTARTER_HPP
-#define NDBT_MIX_RESTARTER_HPP
-
-#include <mgmapi.h>
-#include <Vector.hpp>
-#include <BaseString.hpp>
-#include "NdbRestarter.hpp"
-#include "NDBT_Test.hpp"
-
-#define NMR_SR "SR"
-#define NMR_SR_THREADS "SR_ThreadCount"
-#define NMR_SR_THREADS_STOPPED "SR_ThreadsStoppedCount"
-#define NMR_SR_VALIDATE_THREADS "SR_ValidateThreadCount"
-#define NMR_SR_VALIDATE_THREADS_DONE "SR_ValidateThreadsDoneCount"
-
-class NdbMixRestarter : public NdbRestarter
-{
-public:
- enum RestartTypeMask
- {
- RTM_RestartCluster = 0x01,
- RTM_RestartNode = 0x02,
- RTM_RestartNodeInitial = 0x04,
- RTM_StopNode = 0x08,
- RTM_StopNodeInitial = 0x10,
- RTM_StartNode = 0x20,
-
- RTM_COUNT = 6,
-
- RTM_ALL = 0xFF,
- RTM_SR = RTM_RestartCluster,
- RTM_NR = 0x2 | 0x4 | 0x8 | 0x10 | 0x20
- };
-
- enum SR_State {
- SR_RUNNING = 0,
- SR_STOPPING = 1,
- SR_STOPPED = 2,
- SR_VALIDATING = 3
- };
-
- NdbMixRestarter(const char* _addr = 0);
- ~NdbMixRestarter();
-
- void setRestartTypeMask(Uint32 mask);
- int runUntilStopped(NDBT_Context* ctx, NDBT_Step* step, Uint32 freq);
- int runPeriod(NDBT_Context* ctx, NDBT_Step* step, Uint32 time, Uint32 freq);
-
- int init(NDBT_Context* ctx, NDBT_Step* step);
- int dostep(NDBT_Context* ctx, NDBT_Step* step);
- int finish(NDBT_Context* ctx, NDBT_Step* step);
-
-private:
- Uint32 m_mask;
- Vector<ndb_mgm_node_state> m_nodes;
- int restart_cluster(NDBT_Context* ctx, NDBT_Step* step, bool abort = true);
-};
-
-#endif
diff --git a/storage/ndb/test/include/NdbRestarter.hpp b/storage/ndb/test/include/NdbRestarter.hpp
deleted file mode 100644
index 0cc754872e5..00000000000
--- a/storage/ndb/test/include/NdbRestarter.hpp
+++ /dev/null
@@ -1,121 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NDBT_RESTARTER_HPP
-#define NDBT_RESTARTER_HPP
-
-#include <mgmapi.h>
-#include <Vector.hpp>
-#include <BaseString.hpp>
-
-class NdbRestarter {
-public:
- NdbRestarter(const char* _addr = 0);
- ~NdbRestarter();
-
- int getDbNodeId(int _i);
-
- enum RestartFlags {
- NRRF_INITIAL = 0x1,
- NRRF_NOSTART = 0x2,
- NRRF_ABORT = 0x4
- };
-
- int restartOneDbNode(int _nodeId,
- bool initial = false,
- bool nostart = false,
- bool abort = false);
-
- int restartOneDbNode2(int _nodeId, Uint32 flags){
- return restartOneDbNode(_nodeId,
- flags & NRRF_INITIAL,
- flags & NRRF_NOSTART,
- flags & NRRF_ABORT);
- }
-
- int restartAll(bool initial = false,
- bool nostart = false,
- bool abort = false);
-
- int restartAll2(Uint32 flags){
- return restartAll(flags & NRRF_INITIAL,
- flags & NRRF_NOSTART,
- flags & NRRF_ABORT);
- }
-
- int startAll();
- int startNodes(const int * _nodes, int _num_nodes);
- int waitClusterStarted(unsigned int _timeout = 120);
- int waitClusterSingleUser(unsigned int _timeout = 120);
- int waitClusterStartPhase(int _startphase, unsigned int _timeout = 120);
- int waitClusterNoStart(unsigned int _timeout = 120);
- int waitNodesStarted(const int * _nodes, int _num_nodes,
- unsigned int _timeout = 120);
- int waitNodesStartPhase(const int * _nodes, int _num_nodes,
- int _startphase, unsigned int _timeout = 120);
- int waitNodesNoStart(const int * _nodes, int _num_nodes,
- unsigned int _timeout = 120);
-
-
- int getNumDbNodes();
- int insertErrorInNode(int _nodeId, int error);
- int insertErrorInAllNodes(int error);
-
- int enterSingleUserMode(int _nodeId);
- int exitSingleUserMode();
-
- int dumpStateOneNode(int _nodeId, const int * _args, int _num_args);
- int dumpStateAllNodes(const int * _args, int _num_args);
-
- int getMasterNodeId();
- int getNextMasterNodeId(int nodeId);
- int getNodeGroup(int nodeId);
- int getRandomNodeSameNodeGroup(int nodeId, int randomNumber);
- int getRandomNodeOtherNodeGroup(int nodeId, int randomNumber);
- int getRandomNotMasterNodeId(int randomNumber);
-
- NdbMgmHandle handle;
-
-protected:
-
- int waitClusterState(ndb_mgm_node_status _status,
- unsigned int _timeout,
- int _startphase = -1);
-
- int waitNodesState(const int * _nodes, int _num_nodes,
- ndb_mgm_node_status _status,
- unsigned int _timeout,
- int _startphase = -1);
-
- bool isConnected();
- int connect();
- void disconnect();
- int getStatus();
-
- Vector<ndb_mgm_node_state> mgmNodes;
- Vector<ndb_mgm_node_state> apiNodes;
-
- bool connected;
- BaseString addr;
- ndb_mgm_configuration * m_config;
-protected:
- ndb_mgm_configuration * getConfig();
-
-public:
- Vector<ndb_mgm_node_state> ndbNodes;
-};
-
-#endif
diff --git a/storage/ndb/test/include/NdbRestarts.hpp b/storage/ndb/test/include/NdbRestarts.hpp
deleted file mode 100644
index 187d34c5bfc..00000000000
--- a/storage/ndb/test/include/NdbRestarts.hpp
+++ /dev/null
@@ -1,120 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NDBT_RESTARTS_HPP
-#define NDBT_RESTARTS_HPP
-
-#include <NdbRestarter.hpp>
-#include <NdbTick.h>
-#include <random.h>
-
-/**
- * This class is used to test Ndb's ability to handle
- * node- and system-restarts.
- * For example:
- * Node restart: Restart one node in the cluster.
- * System restart: Restart all nodes in the cluster.
- * Node crash: Crash one node in the middle of execution and bring it up again.
- * Multiple node crash: Crash multiple nodes with a few seconds or milliseconds delay between.
- * Initial node restart: Restart one node in the cluster without a filesystem on disk.
- *
- * Each restart type is represented by a NdbRestart class and a collection of these are stored
- * in the NdbRestarts class.
- *
- * This class may be used from other programs to execute a particular restart.
- *
- */
-
-
-class NdbRestarts {
-public:
- NdbRestarts(const char* _addr = 0):
- m_restarter(_addr)
- {
- myRandom48Init(NdbTick_CurrentMillisecond());
- }
-
- enum NdbRestartType{
- NODE_RESTART,
- MULTIPLE_NODE_RESTART,
- SYSTEM_RESTART
- };
-
- struct NdbRestart {
- typedef int (restartFunc)(NdbRestarter&, const NdbRestart*);
-
- NdbRestart(const char* _name,
- NdbRestartType _type,
- restartFunc* _func,
- int _requiredNodes,
- int _arg1 = -1);
-
- const char * m_name;
- NdbRestartType m_type;
- restartFunc* m_restartFunc;
- int m_numRequiredNodes;
- int m_arg1;
-
- };
-
- int getNumRestarts();
-
- int executeRestart(int _num, unsigned int _timeout = 120);
- int executeRestart(const char* _name, unsigned int _timeout = 120);
-
- void listRestarts();
- void listRestarts(NdbRestartType _type);
-private:
- int executeRestart(const NdbRestart*, unsigned int _timeout);
-
- struct NdbErrorInsert {
- NdbErrorInsert(const char* _name,
- int _errorNo);
-
- const char * m_name;
- int m_errorNo;
-
- public:
- const char* getName();
- };
-
- int getNumErrorInserts();
- const NdbErrorInsert* getError(int _num);
- const NdbErrorInsert* getRandomError();
-
- static const NdbErrorInsert m_errors[];
- static const int m_NoOfErrors;
-
- const NdbRestart* getRestart(int _num);
- const NdbRestart* getRestart(const char* _name);
-
- static const NdbRestart m_restarts[];
- static const int m_NoOfRestarts;
-
- NdbRestarter m_restarter;
-};
-
-
-
-
-
-
-
-
-
-
-
-#endif
diff --git a/storage/ndb/test/include/NdbSchemaCon.hpp b/storage/ndb/test/include/NdbSchemaCon.hpp
deleted file mode 100644
index 7166705d7b0..00000000000
--- a/storage/ndb/test/include/NdbSchemaCon.hpp
+++ /dev/null
@@ -1,147 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NdbSchemaCon_H
-#define NdbSchemaCon_H
-
-#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
-
-#include <ndb_types.h>
-#include "NdbError.hpp"
-#include <NdbSchemaOp.hpp>
-
-class NdbSchemaOp;
-class Ndb;
-class NdbApiSignal;
-
-/**
- * @class NdbSchemaCon
- * @brief Represents a schema transaction.
- *
- * When creating a new table,
- * the first step is to get a NdbSchemaCon object to represent
- * the schema transaction.
- * This is done by calling Ndb::startSchemaTransaction.
- *
- * The next step is to get a NdbSchemaOp object by calling
- * NdbSchemaCon::getNdbSchemaOp.
- * The NdbSchemaOp object then has methods to define the table and
- * its attributes.
- *
- * Finally, the NdbSchemaCon::execute method inserts the table
- * into the database.
- *
- * @note Currently only one table can be added per transaction.
- * @note Depricated, use NdbDictionary
- */
-class NdbSchemaCon
-{
-friend class Ndb;
-friend class NdbSchemaOp;
-
-public:
-
- static
- NdbSchemaCon* startSchemaTrans(Ndb* pNdb){
- return new NdbSchemaCon(pNdb);
- }
-
- static
- void closeSchemaTrans(NdbSchemaCon* pSchCon){
- delete pSchCon;
- }
-
-
- /**
- * Execute a schema transaction.
- *
- * @return 0 if successful otherwise -1.
- */
- int execute();
-
- /**
- * Get a schemaoperation.
- *
- * @note Currently, only one operation per transaction is allowed.
- *
- * @return Pointer to a NdbSchemaOp or NULL if unsuccessful.
- */
- NdbSchemaOp* getNdbSchemaOp();
-
- /**
- * Get the latest error
- *
- * @return Error object.
- */
- const NdbError & getNdbError() const;
-
-private:
-
-/******************************************************************************
- * These are the create and delete methods of this class.
- *****************************************************************************/
-
- NdbSchemaCon(Ndb* aNdb);
- ~NdbSchemaCon();
-
-/******************************************************************************
- * These are the private methods of this class.
- *****************************************************************************/
-
- void release(); // Release all schemaop in schemaCon
-
- /***************************************************************************
- * These methods are service methods to other classes in the NDBAPI.
- ***************************************************************************/
-
- int checkMagicNumber(); // Verify correct object
- int receiveDICTTABCONF(NdbApiSignal* aSignal);
- int receiveDICTTABREF(NdbApiSignal* aSignal);
-
-
- int receiveCREATE_INDX_CONF(NdbApiSignal*);
- int receiveCREATE_INDX_REF(NdbApiSignal*);
- int receiveDROP_INDX_CONF(NdbApiSignal*);
- int receiveDROP_INDX_REF(NdbApiSignal*);
-
-
-/*****************************************************************************
- * These are the private variables of this class.
- *****************************************************************************/
-
-
- NdbError theError; // Errorcode
- Ndb* theNdb; // Pointer to Ndb object
-
- NdbSchemaOp* theFirstSchemaOpInList; // First operation in operation list.
- int theMagicNumber; // Magic number
-};
-
-inline
-int
-NdbSchemaCon::checkMagicNumber()
-{
- if (theMagicNumber != 0x75318642)
- return -1;
- return 0;
-}//NdbSchemaCon::checkMagicNumber()
-
-
-
-#endif
-#endif
-
-
diff --git a/storage/ndb/test/include/NdbSchemaOp.hpp b/storage/ndb/test/include/NdbSchemaOp.hpp
deleted file mode 100644
index ea878f1a8ee..00000000000
--- a/storage/ndb/test/include/NdbSchemaOp.hpp
+++ /dev/null
@@ -1,546 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NdbSchemaOp_H
-#define NdbSchemaOp_H
-
-#include <NdbDictionary.hpp>
-
-#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
-
- /**
- * Type of attribute
- *
- * NOTE! AttrType is deprecated, use NdbDictionary::Column::Type instead!
- */
- enum AttrType {
- Signed, ///< Attributes of this type can be read with:
- ///< NdbRecAttr::int64_value,
- ///< NdbRecAttr::int32_value,
- ///< NdbRecAttr::short_value,
- ///< NdbRecAttr::char_value
- UnSigned, ///< Attributes of this type can be read with:
- ///< NdbRecAttr::u_64_value,
- ///< NdbRecAttr::u_32_value,
- ///< NdbRecAttr::u_short_value,
- ///< NdbRecAttr::u_char_value
- Float, ///< Attributes of this type can be read with:
- ///< NdbRecAttr::float_value and
- ///< NdbRecAttr::double_value
- String, ///< Attributes of this type can be read with:
- ///< NdbRecAttr::aRef,
- ///< NdbRecAttr::getAttributeObject
- NoAttrTypeDef ///< Used for debugging only
- };
-
-
- /**
- * @deprecated
- */
- enum NullAttributeType {
- NoNullTypeDefined = -1,
- NotNullAttribute,
- NullAttribute,
- AttributeDefined
- };
- /**
- * Indicates whether the attribute is part of a primary key or not
- */
- enum KeyType {
- Undefined = -1, ///< Used for debugging only
- NoKey, ///< Attribute is not part of primary key
- ///< or tuple identity
- TupleKey, ///< Attribute is part of primary key
- TupleId ///< Attribute is part of tuple identity
- ///< (This type of attribute is created
- ///< internally, and should not be
- ///< manually created.)
- };
- /**
- * Indicate whether the attribute should be stored on disk or not
- * Only for legacy createAttribute().
- */
- enum StorageMode {
- MMBased = NDB_STORAGETYPE_MEMORY,
- DiskBased = NDB_STORAGETYPE_DISK
- };
-
- /**
- * Type of fragmentation used for a table
- */
- enum FragmentType {
- Default = 0, ///< (All is default!)
- Single = 1, ///< Only one fragment
- All = 2, ///< Default value. One fragment per node group
- DistributionGroup = 3, ///< Distribution Group used for fragmentation.
- ///< One fragment per node group
- DistributionKey = 4, ///< Distribution Key used for fragmentation.
- ///< One fragment per node group.
- AllLarge = 5, ///< Sixten fragments per node group.
- DGroupLarge = 6, ///< Distribution Group used for fragmentation.
- ///< Sixten fragments per node group
- DKeyLarge = 7 ///< Distribution Key used for fragmentation.
- ///< Sixten fragments per node group
- };
-
- /**
- * Type of table or index.
- */
- enum TableType {
- UndefTableType = 0,
- SystemTable = 1, ///< Internal.Table cannot be updated by user
- UserTable = 2, ///< Normal application table
- UniqueHashIndex = 3, ///< Unique un-ordered hash index
- HashIndex = 4, ///< Non-unique un-ordered hash index
- UniqueOrderedIndex = 5, ///< Unique ordered index
- OrderedIndex = 6 ///< Non-unique ordered index
- };
-
-
-class NdbSchemaCon;
-class Ndb;
-
-
-/**
- * @class NdbSchemaOp
- * @brief Represents various operations for use in schema transactions
- *
- * This class is used for schema operations, e.g. creating tables and
- * attributes.
- *
- * The NdbSchemaOp object is created using NdbSchemaCon::getNdbSchemaOp.
- *
- * @note This class is depricated and is now replaced with the class
- * NdbDictionary.
- */
-class NdbSchemaOp
-{
- friend class Ndb;
- friend class NdbSchemaCon;
-
-public:
-
-
- /**
- * Create a new table in the database.
- *
- * @note The NdbSchemaCon should be closed with
- * Ndb::closeSchemaTransaction, even if this method fails.
- *
- * @param aTableName Table name. Should not be NULL.
- * @param aTableSize (Performance parameter.)
- * Initial size of the data part of the table
- * expressed in kByte.
- * The database handles
- * bad parameter setting but at a certain
- * loss in performance.
- * The size given here is
- * the initial size allocated for the table
- * storage (the data part).
- * When calculating the data storage one should
- * add the size of all attributes (each attribute
- * consumes at least 4 bytes) and also an overhead
- * of 12 byte.
- * Variable size attributes (not supported yet)
- * will have a size of 12 bytes plus the actual
- * data storage parts where there is an
- * additional overhead based on the size of the
- * variable part.
- * <br>
- * An example table with 5 attributes:
- * one 64 bit attribute, one 32 bit attribute,
- * two 16 bit attributes and one array of 64 8 bits.
- * This table will consume
- * 12 (overhead) + 8 + 4 + 2*4 (4 is minimum) + 64 =
- * 96 bytes per record.
- * Additionally an overhead of about 2 % as page
- * headers and waste should be allocated.
- * Thus, 1 million records should consume 96 MBytes
- * plus the overhead 2 MByte and rounded up to
- * 100 000 kBytes.
- * <br><em>
- * This parameter is currently not used.
- * </em>
- * @param aTupleKey Indicates if the table has a primary key or not.
- * <br>
- * <b>TupleKey</b> means that a <em>primary key</em>
- * consisting of one to four attributes
- * (at most one of variable size)
- * uniquely identifies each record in the created
- * table.
- * <br>
- * <b>TupleId</b> means that a <em>tuple identity</em>
- * is used. The tuple identity is
- * a unique key indentifying each record of the
- * created table.
- * The tuple identity is a (non-stored)
- * 64 bit attribute named <b>NDB$TID</b>.
- * <br>
- * When inserting a record (tuple), the method
- * NdbOperation::setTupleId
- * will generate a unique tuple identity
- * and return it to the user.
- * <br>
- * When reading, updating or deleting a record
- * in a table with <b>TupleId</b>,
- * NdbOperation::equal("NDB$TID", value_Uint64)
- * can be used to identify the record.
- * <br>
- * Legal values: TupleKey or TupleId.
- * @param aNrOfPages (Performance parameter.)
- * Specifies the initial size of the index storage.
- * When calculating the index storage,
- * each key has approximately 14 byte of
- * overhead plus the size of the key.
- * Each key attribute takes up at least 4 bytes
- * of storage.
- * Thus a mixed key consisting of a
- * 64 bit attribute, a 32 bit attribute
- * and a 16 bit attribute will
- * consume approx. 30 bytes per key.
- * Thus, the if initial size is to be 1 million rows,
- * then aNrOfPages should be set to
- * 30 M / 8k = 2670 pages.
- * <br><em>
- * This parameter is currently not used.
- * </em>
- * @param aFragmentType Type of fragmentation.<br>
- * <b>All</b> (default) means that the
- * table fragments are automatically
- * distributed on all nodes in the system.<br>
- * <b>DistributionGroup</b> and
- * <b>DistributionKey</b> are
- * also supported. For further details about
- * these types see the documentation of
- * Ndb::startTransaction.
- * @param aKValue (Hash parameter.)
- * Only allowed value is 6.
- * Later implementations might add flexibility
- * in this parameter.
- * @param aMinLoadFactor (Hash parameter.)
- * This value specifies the load factor when
- * starting to shrink the hash table.
- * It must be smaller than aMaxLoadFactor.
- * Both these factors are given in percentage.
- * @param aMaxLoadFactor (Hash parameter.)
- * This value specifies the load factor when
- * starting to split the containers in the local
- * hash tables. 100 is the maximum which will
- * optimize memory usage (this is the figure
- * used for the above calculations).
- * A lower figure will store less information in
- * each container and thus
- * find the key faster but consume more memory.
- * @param aMemoryType Currently only 1 is allowed which specifies
- * storage of table in main memory.
- * Later 2 will be added where the table is stored
- * completely on disk
- * and 3 where the index is in main memory but
- * data is on disk.
- * If 1 is chosen an individual attribute can
- * still be specified as a disk attribute.
- * @param aStoredTable If set to false it indicates that the table is
- * a temporary table and should not be logged
- * to disk.
- * In case of a system restart the table will still
- * be defined and exist but will be empty.
- * Thus no checkpointing and
- * no logging is performed on the table.
- * The default value is true and indicates a
- * normal table with full checkpointing and
- * logging activated.
- * @return Returns 0 when successful and returns -1 otherwise.
- */
- int createTable( const char* aTableName,
- Uint32 aTableSize = 8,
- KeyType aTupleKey = TupleKey,
- int aNrOfPages = 2,
- FragmentType aFragmentType = All,
- int aKValue = 6,
- int aMinLoadFactor = 78,
- int aMaxLoadFactor = 80,
- int aMemoryType = 1,
- bool aStoredTable = true);
-
- /**
- * This is the old function declaration, don't use.
- *
- * @deprecated do not use!
- */
-#ifndef NDB_WIN32
- inline int createTable( const char* aTableName,
- Uint32 aTableSize,
- KeyType aTupleKey,
- int aNrOfPages,
- FragmentType aFragmentType,
- int aKValue,
- int aMinLoadFactor,
- int aMaxLoadFactor,
- int aMemoryType,
- int aStoredTable){
- return createTable(aTableName,
- aTableSize,
- aTupleKey,
- aNrOfPages,
- aFragmentType,
- aKValue,
- aMinLoadFactor,
- aMaxLoadFactor,
- aMemoryType,
- (aStoredTable == 1 ? true : false));
- }
-#endif
-
- /**
- * Add a new attribute to a database table.
- *
- * Attributes can only be added to a table in the same transaction
- * as the transaction creating the table.
- *
- * @note The NdbSchemaCon transaction should be closed with
- * Ndb::closeSchemaTransaction, even if this method fails.
- *
- * Example creating an unsigned int attribute belonging to the primary key
- * of the table it is created in:
- * @code
- * MySchemaOp->createAttribute("Attr1", // Attribute name
- * TupleKey, // Belongs to primary key
- * 32, // 32 bits
- * 1, // Not an array attribute
- * UnSigned, // Unsigned type
- * );
- * @endcode
- *
- * Example creating a string attribute belonging to the primary key
- * of the table it is created in:
- * @code
- * MySchemaOp->createAttribute("Attr1", // Attribute name
- * TupleKey, // Belongs to primary key
- * 8, // Each character is 8 bits
- * 12, // Max 12 chars in string
- * String, // Attribute if of type string
- * );
- * @endcode
- *
- * A <em>distribution key</em> is a set of attributes which are used
- * to distribute the tuples onto the NDB nodes.
- * A <em>distribution group</em> is a part (currently 16 bits)
- * of an attribute used to distribute the tuples onto the NDB nodes.
- * The distribution key uses the NDB Cluster hashing function,
- * while the distribution group uses a simpler function.
- *
- * @param aAttrName Attribute name. Should not be NULL.
- * @param aTupleKey This parameter specifies whether the
- * attribute is part of the primary key or not.
- * Floats are not allowed in the primary key.
- * <br>
- * Legal values: NoKey, TupleKey
- * @param aAttrSize Specifies the size of the elements of the
- * attribute. (An attribute can consist
- * of an array of elements.)
- * <br>
- * Legal values: 8, 16, 32, 64 and 128 bits.
- * @param aArraySize Size of array.
- * <br>
- * Legal values:
- * 0 = variable-sized array,
- * 1 = no array, and
- * 2- = fixed size array.
- * <br>
- * <em>
- * Variable-sized array attributes are
- * not yet supported.
- * </em>
- * <br>
- * There is no upper limit of the array size
- * for a single attribute.
- * @param aAttrType The attribute type.
- * This is only of interest if calculations are
- * made within NDB.
- * <br>
- * Legal values: UnSigned, Signed, Float, String
- * @param aStorageMode Main memory based or disk based attribute.<br>
- * Legal values: MMBased, DiskBased
- * <br>
- * <em>
- * Disk-based attributes are not yet supported.
- * </em>
- * @param nullable Set to true if NULL is a correct value for
- * the attribute.
- * <br>
- * Legal values: true, false
- * @param aStType Obsolete since wl-2066
- * @param aDistributionKey Sometimes it is preferable to use a subset
- * of the primary key as the distribution key.
- * An example is TPC-C where it might be
- * good to use the warehouse id and district id
- * as the distribution key.
- * <br>
- * Locally in the fragments the full primary key
- * will still be used with the hashing algorithm.
- * Set to 1 if this attribute is part of the
- * distribution key.
- * All distribution key attributes must be
- * defined before
- * any other attributes are defined.
- * @param aDistributionGroup In other applications it is desirable to use
- * only a part of an attribute to create the
- * distribution key.
- * This is applicable for some telecom
- * applications.
- * <br>
- * In these situations one must provide how many
- * bits of the attribute that is to
- * be used as the distribution hash value.
- * <br>
- * This provides some control to the
- * application of the distribution.
- * It still needs to be part of a primary key
- * the attribute and must be defined as the
- * first attribute.
- * @param aDistributionGroupNoOfBits
- * Number of bits to use of the
- * distribution group attribute in the
- * distribution hash value.
- * <br>
- * Currently, only 16 bits is supported. It will
- * always be the last 16 bits in the attribute
- * which is used for the distribution group.
- * @param aAutoIncrement Set to autoincrement attribute.
- * @param aDefaultValue Set a default value of attribute.
- *
- * @return Returns 0 when successful and returns -1 otherwise.
- ****************************************************************************/
- int createAttribute(const char* aAttrName,
- KeyType aTupleKey = NoKey,
- int aAttrSize = 32,
- int aArraySize = 1,
- AttrType aAttrType = UnSigned,
- StorageMode aStorageMode = MMBased,
- bool nullable = false,
- int aStType= 0, // obsolete
- int aDistributionKey = 0,
- int aDistributionGroup = 0,
- int aDistributionGroupNoOfBits = 16,
- bool aAutoIncrement = false,
- const char* aDefaultValue = 0);
-
- /**
- * @deprecated do not use!
- */
- int createAttribute(const char* aAttrName,
- KeyType aTupleKey,
- int aAttrSize,
- int aArraySize,
- AttrType aAttrType,
- StorageMode aStorageMode,
- NullAttributeType aNullAttr,
- int aStType, // obsolete
- int aDistributionKey = 0,
- int aDistributionGroup = 0,
- int aDistributionGroupNoOfBits = 16){
- return createAttribute(aAttrName,
- aTupleKey,
- aAttrSize,
- aArraySize,
- aAttrType,
- aStorageMode,
- aNullAttr == NullAttribute,
- aStType,
- aDistributionKey,
- aDistributionGroup,
- aDistributionGroupNoOfBits);
- }
-
- const NdbError & getNdbError() const;
-
-protected:
-
-/*****************************************************************************
- * These are the methods used to create and delete the NdbOperation objects.
- ****************************************************************************/
- NdbSchemaOp(Ndb* aNdb);
-
- ~NdbSchemaOp();
-
-/******************************************************************************
- * These methods are service routines used by the other NDBAPI classes.
- *****************************************************************************/
-
- void release(); // Release all memory connected
- // to the operations object.
-
-/****************************************************************************
- * The methods below is the execution part of the NdbSchemaOp class.
- *****************************************************************************/
-
- int sendRec();
- int sendSignals(Uint32 aNodeId, bool HaveMutex);
-
- int init(NdbSchemaCon* aSchemaCon);
-
- /**************************************************************************
- * These are the private variables that are defined in the operation
- * objects.
- **************************************************************************/
- Ndb* theNdb; // Point back to the Ndb object.
- NdbSchemaCon* theSchemaCon; // Point back to the connection object.
-
-
- class NdbDictionary::Table * m_currentTable;
-};
-
-
-/**
- * Get old attribute type from new type
- *
- * NOTE! attrType is deprecated, use getType instead!
- *
- * @return Type of attribute: { Signed, UnSigned, Float,a String }
- */
-inline
-AttrType
-convertColumnTypeToAttrType(NdbDictionary::Column::Type _type)
-{
-
- switch(_type){
- case NdbDictionary::Column::Bigint:
- case NdbDictionary::Column::Int:
- return Signed;
- case NdbDictionary::Column::Bigunsigned:
- case NdbDictionary::Column::Unsigned:
- return UnSigned;
- case NdbDictionary::Column::Float:
- case NdbDictionary::Column::Olddecimal:
- case NdbDictionary::Column::Olddecimalunsigned:
- case NdbDictionary::Column::Decimal:
- case NdbDictionary::Column::Decimalunsigned:
- case NdbDictionary::Column::Double:
- return Float;
- case NdbDictionary::Column::Char:
- case NdbDictionary::Column::Varchar:
- case NdbDictionary::Column::Binary:
- case NdbDictionary::Column::Varbinary:
- return String;
- default:
- return NoAttrTypeDef;
- }
-}
-#endif
-
-#endif
-
-
diff --git a/storage/ndb/test/include/NdbTest.hpp b/storage/ndb/test/include/NdbTest.hpp
deleted file mode 100644
index 3bea743a3a0..00000000000
--- a/storage/ndb/test/include/NdbTest.hpp
+++ /dev/null
@@ -1,35 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NDB_TEST_HPP
-#define NDB_TEST_HPP
-
-/**
- * NdbTest.hpp
- * This is the main include file to include in test programs
- * It will include all the other include files in the NDBT-toolkit
- *
- */
-
-#include "NDBT_ReturnCodes.h"
-
-#ifdef __cplusplus
-#include "NDBT_Table.hpp"
-#include "NDBT_Error.hpp"
-#endif
-
-
-#endif
diff --git a/storage/ndb/test/include/NdbTimer.hpp b/storage/ndb/test/include/NdbTimer.hpp
deleted file mode 100644
index 5b3ca3357a3..00000000000
--- a/storage/ndb/test/include/NdbTimer.hpp
+++ /dev/null
@@ -1,109 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NDBTIMER_H
-#define NDBTIMER_H
-
-#include <NdbTick.h>
-#include <NdbOut.hpp>
-
-//
-// Class used for measuring time and priting the results
-//
-// Currently measures time in milliseconds
-//
-
-class NdbTimer
-{
-public:
-
- NdbTimer();
- ~NdbTimer() {};
-
- void doStart();
- void doStop();
- void doReset();
- NDB_TICKS elapsedTime();
- void printTransactionStatistics(const char* text,
- int numTransactions,
- int numOperations);
- void printTestTimer(int numLoops,
- int numRecords);
- void printTotalTime(void);
-private:
- NDB_TICKS startTime;
- NDB_TICKS stopTime;
-};
-
-inline NdbTimer::NdbTimer(){
- doReset();
-}
-
-inline void NdbTimer::doReset(void){
- startTime = 0;
- stopTime = 0;
-}
-
-inline void NdbTimer::doStart(void){
- startTime = NdbTick_CurrentMillisecond();
-}
-
-inline void NdbTimer::doStop(void){
- stopTime = NdbTick_CurrentMillisecond();
-}
-
-inline NDB_TICKS NdbTimer::elapsedTime(void){
- return (stopTime - startTime);
-}
-
-inline void NdbTimer::printTransactionStatistics(const char* text,
- int numTransactions,
- int numOperations){
-
- // Convert to Uint32 in order to be able to print it to screen
- Uint32 lapTime = (Uint32)elapsedTime();
- ndbout_c("%i transactions, %i %s total time = %d ms\nAverage %f ms/transaction, %f ms/%s.\n%f transactions/second, %f %ss/second.\n",
- numTransactions, numTransactions*numOperations, text, lapTime,
- ((double)lapTime/numTransactions), ((double)lapTime/(numTransactions*numOperations)), text,
- 1000.0/((double)lapTime/numOperations), 1000.0/((double)lapTime/(numTransactions*numOperations)), text);
-}
-
-
-
-inline void NdbTimer::printTestTimer(int numLoops,
- int numRecords){
- // Convert to Uint32 in order to be able to print it to screen
- Uint32 lapTime = (Uint32)elapsedTime();
- ndbout_c("%i loop * %i records, total time = %d ms\nAverage %f ms/loop, %f ms/record.\n%f looop/second, %f records/second.\n",
- numLoops, numRecords, lapTime,
- ((double)lapTime/numLoops), ((double)lapTime/(numLoops*numRecords)),
- 1000.0/((double)lapTime/numLoops), 1000.0/((double)lapTime/(numLoops*numRecords)));
-}
-
-
-inline void NdbTimer::printTotalTime(void){
- // Convert to Uint32 in order to be able to print it to screen
- Uint32 lapTime = (Uint32)elapsedTime();
- Uint32 secTime = lapTime/1000;
- ndbout_c("Total time : %d seconds (%d ms)\n", secTime, lapTime);
-}
-
-
-
-
-
-
-#endif
diff --git a/storage/ndb/test/include/TestNdbEventOperation.hpp b/storage/ndb/test/include/TestNdbEventOperation.hpp
deleted file mode 100644
index 4a92f01d15f..00000000000
--- a/storage/ndb/test/include/TestNdbEventOperation.hpp
+++ /dev/null
@@ -1,24 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-struct EventOperationStats {
- int n_inserts;
- int n_deletes;
- int n_updates;
- int n_duplicates;
- int n_consecutive;
- int n_inconsistent_gcis;
-};
diff --git a/storage/ndb/test/include/UtilTransactions.hpp b/storage/ndb/test/include/UtilTransactions.hpp
deleted file mode 100644
index fc36ca568c3..00000000000
--- a/storage/ndb/test/include/UtilTransactions.hpp
+++ /dev/null
@@ -1,136 +0,0 @@
-/* Copyright (c) 2003-2005, 2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef UTIL_TRANSACTIONS_HPP
-#define UTIL_TRANSACTIONS_HPP
-
-#include <NDBT.hpp>
-
-typedef int (ReadCallBackFn)(NDBT_ResultRow*);
-
-class UtilTransactions {
-public:
- UtilTransactions(const NdbDictionary::Table&,
- const NdbDictionary::Index* idx = 0);
- UtilTransactions(Ndb* ndb,
- const char * tableName, const char * indexName = 0);
-
- int closeTransaction(Ndb*);
-
- int clearTable(Ndb*,
- NdbScanOperation::ScanFlag,
- int records = 0,
- int parallelism = 0);
-
- int clearTable(Ndb*,
- int records = 0,
- int parallelism = 0);
-
- // Delete all records from the table using a scan
- int clearTable1(Ndb*,
- int records = 0,
- int parallelism = 0);
- // Delete all records from the table using a scan
- // Using batching
- int clearTable2(Ndb*,
- int records = 0,
- int parallelism = 0);
-
- int clearTable3(Ndb*,
- int records = 0,
- int parallelism = 0);
-
- int selectCount(Ndb*,
- int parallelism = 0,
- int* count_rows = NULL,
- NdbOperation::LockMode lm = NdbOperation::LM_CommittedRead,
- NdbConnection* pTrans = NULL);
- int scanReadRecords(Ndb*,
- int parallelism,
- NdbOperation::LockMode lm,
- int records,
- int noAttribs,
- int* attrib_list,
- ReadCallBackFn* fn = NULL);
- int verifyIndex(Ndb*,
- const char* indexName,
- int parallelism = 0,
- bool transactional = false);
-
- int copyTableData(Ndb*,
- const char* destName);
-
- /**
- * Compare this table with other_table
- *
- * return 0 - on equality
- * -1 - on error
- * >0 - otherwise
- */
- int compare(Ndb*, const char * other_table, int flags);
-
-private:
- static int takeOverAndDeleteRecord(Ndb*,
- NdbOperation*);
-
- int addRowToDelete(Ndb* pNdb,
- NdbConnection* pDelTrans,
- NdbOperation* pOrgOp);
-
-
- int addRowToInsert(Ndb* pNdb,
- NdbConnection* pInsTrans,
- NDBT_ResultRow & row,
- const char* insertTabName);
-
-
- int verifyUniqueIndex(Ndb*,
- const NdbDictionary::Index *,
- int parallelism = 0,
- bool transactional = false);
-
- int scanAndCompareUniqueIndex(Ndb* pNdb,
- const NdbDictionary::Index *,
- int parallelism,
- bool transactional);
-
- int readRowFromTableAndIndex(Ndb* pNdb,
- NdbConnection* pTrans,
- const NdbDictionary::Index *,
- NDBT_ResultRow& row );
-
- int verifyOrderedIndex(Ndb*,
- const NdbDictionary::Index *,
- int parallelism = 0,
- bool transactional = false);
-
-
- int get_values(NdbOperation* op, NDBT_ResultRow& dst);
- int equal(const NdbDictionary::Table*, NdbOperation*, const NDBT_ResultRow&);
- int equal(const NdbDictionary::Index*, NdbOperation*, const NDBT_ResultRow&);
-
-protected:
- int m_defaultClearMethod;
- const NdbDictionary::Table& tab;
- const NdbDictionary::Index* idx;
- NdbConnection* pTrans;
-
- NdbOperation* getOperation(NdbConnection*,
- NdbOperation::OperationType);
- NdbScanOperation* getScanOperation(NdbConnection*);
-};
-
-#endif
diff --git a/storage/ndb/test/include/getarg.h b/storage/ndb/test/include/getarg.h
deleted file mode 100644
index 70ae0b8d128..00000000000
--- a/storage/ndb/test/include/getarg.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-/*
- * Copyright (c) 1997, 1999 Kungliga Tekniska Högskolan
- * (Royal Institute of Technology, Stockholm, Sweden).
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/* $KTH: getarg.h,v 1.9 2000/09/01 21:25:55 lha Exp $ */
-
-#ifndef __GETARG_H__
-#define __GETARG_H__
-
-#include <ndb_global.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef enum {
- arg_integer,
- arg_string,
- arg_flag,
- arg_negative_flag,
- arg_strings,
- arg_double,
- arg_collect,
- arg_counter
-} arg_type;
-
-struct getargs{
- const char *long_name;
- char short_name;
- arg_type type;
- void *value;
- const char *help;
- const char *arg_help;
-};
-
-enum {
- ARG_ERR_NO_MATCH = 1,
- ARG_ERR_BAD_ARG,
- ARG_ERR_NO_ARG
-};
-
-typedef struct getarg_strings {
- int num_strings;
- char **strings;
-} getarg_strings;
-
-typedef int (*getarg_collect_func)(int short_opt,
- int argc,
- const char **argv,
- int *optind,
- int *optarg,
- void *data);
-
-typedef struct getarg_collect_info {
- getarg_collect_func func;
- void *data;
-} getarg_collect_info;
-
-int getarg(struct getargs *args, size_t num_args,
- int argc, const char **argv, int *optind);
-
-void arg_printusage (struct getargs *args,
- size_t num_args,
- const char *progname,
- const char *extra_string);
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __GETARG_H__ */
diff --git a/storage/ndb/test/ndbapi/InsertRecs.cpp b/storage/ndb/test/ndbapi/InsertRecs.cpp
deleted file mode 100644
index da31a8ff671..00000000000
--- a/storage/ndb/test/ndbapi/InsertRecs.cpp
+++ /dev/null
@@ -1,571 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-// InsertRecs.cpp : Defines the entry point for the console application.
-//
-
-
-#include <NdbApi.hpp>
-#include <windows.h>
-#include <tchar.h>
-
-
-// data for CALL_CONTEXT and GROUP_RESOURCE
-static TCHAR STATUS_DATA[]=_T("000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F")
- _T("101112131415161718191A1B1C1D1E1F000102030405060708090A0B0C0D0E0F")
- _T("202122232425262728292A2B2C2D2E2F000102030405060708090A0B0C0D0E0F")
- _T("303132333435363738393A3B3C3D3E3F000102030405060708090A0B0C0D0E0F")
- _T("404142434445464748494A4B4C4D4E4F000102030405060708090A0B0C0D0E0F")
- _T("505152535455565758595A5B5C5D5E5F000102030405060708090A0B0C0D0E0F")
- _T("606162636465666768696A6B6C6D6E6F000102030405060708090A0B0C0D0E0F")
- _T("707172737475767778797A7B7C7D7E7F000102030405060708090A0B0C0D0E0F")
- _T("808182838485868788898A8B8C8D8E8F000102030405060708090A0B0C0D0E0F")
- _T("909192939495969798999A9B9C9D9E9F000102030405060708090A0B0C0D0E0F")
- _T("10010110210310410510610710810910A000102030405060708090A0B0C0D0EF")
- _T("10B10C10D10E10F110111112113114115000102030405060708090A0B0C0D0EF")
- _T("11611711811911A11B11C11D11E11F120000102030405060708090A0B0C0D0EF")
- _T("12112212312412512612712812912A12B000102030405060708090A0B0C0D0EF")
- _T("12C12D12E12F130131132134135136137000102030405060708090A0B0C0D0EF")
- _T("13813913A13B13C13D13E13F140141142000102030405060708090A0B0C0D0EF")
- _T("14314414514614714814914A14B14C14D000102030405060708090A0B0C0D0EF")
- _T("14E14F150151152153154155156157158000102030405060708090A0B0C0D0EF")
- _T("15915A15B15C15D15E15F160161162163000102030405060708090A0B0C0D0EF")
- _T("16416516616716816916A16B16C16D16E000102030405060708090A0B0C0D0EF")
- _T("16F170171172173174175176177178179000102030405060708090A0B0C0D0EF")
- _T("17A17B17C17D17E17F180181182183184000102030405060708090A0B0C0D0EF")
- _T("18518618718818918A18B18C18D18E18F000102030405060708090A0B0C0D0EF")
- _T("19019119219319419519619719819919A000102030405060708090A0B0C0D0EF")
- _T("19B19C19D19E19F200201202203204205000102030405060708090A0B0C0D0EF")
- _T("20620720820920A20B20C20D20F210211000102030405060708090A0B0C0D0EF")
- _T("21221321421521621721821921A21B21C000102030405060708090A0B0C0D0EF")
- _T("21D21E21F220221222223224225226227000102030405060708090A0B0C0D0EF")
- _T("22822922A22B22C22D22E22F230231232000102030405060708090A0B0C0D0EF")
- _T("23323423523623723823923A23B23C23D000102030405060708090A0B0C0D0EF")
- _T("23E23F240241242243244245246247248000102030405060708090A0B0C0D0EF")
- _T("24924A24B24C24D24E24F250251252253000102030405060708090A0B0C0D0EF")
- _T("101112131415161718191A1B1C1D1E1F000102030405060708090A0B0C0D0E0F")
- _T("202122232425262728292A2B2C2D2E2F000102030405060708090A0B0C0D0E0F")
- _T("303132333435363738393A3B3C3D3E3F000102030405060708090A0B0C0D0E0F")
- _T("404142434445464748494A4B4C4D4E4F000102030405060708090A0B0C0D0E0F")
- _T("505152535455565758595A5B5C5D5E5F000102030405060708090A0B0C0D0E0F")
- _T("606162636465666768696A6B6C6D6E6F000102030405060708090A0B0C0D0E0F")
- _T("707172737475767778797A7B7C7D7E7F000102030405060708090A0B0C0D0E0F")
- _T("808182838485868788898A8B8C8D8E8F000102030405060708090A0B0C0D0E0F")
- _T("909192939495969798999A9B9C9D9E9F000102030405060708090A0B0C0D0E0F")
- _T("10010110210310410510610710810910A000102030405060708090A0B0C0D0EF")
- _T("10B10C10D10E10F110111112113114115000102030405060708090A0B0C0D0EF")
- _T("11611711811911A11B11C11D11E11F120000102030405060708090A0B0C0D0EF")
- _T("12112212312412512612712812912A12B000102030405060708090A0B0C0D0EF")
- _T("12C12D12E12F130131132134135136137000102030405060708090A0B0C0D0EF")
- _T("13813913A13B13C13D13E13F140141142000102030405060708090A0B0C0D0EF")
- _T("14314414514614714814914A14B14C14D000102030405060708090A0B0C0D0EF")
- _T("14E14F150151152153154155156157158000102030405060708090A0B0C0D0EF")
- _T("15915A15B15C15D15E15F160161162163000102030405060708090A0B0C0D0EF")
- _T("16416516616716816916A16B16C16D16E000102030405060708090A0B0C0D0EF")
- _T("16F170171172173174175176177178179000102030405060708090A0B0C0D0EF")
- _T("17A17B17C17D17E17F180181182183184000102030405060708090A0B0C0D0EF")
- _T("18518618718818918A18B18C18D18E18F000102030405060708090A0B0C0D0EF")
- _T("19019119219319419519619719819919A000102030405060708090A0B0C0D0EF")
- _T("19B19C19D19E19F200201202203204205000102030405060708090A0B0C0D0EF")
- _T("20620720820920A20B20C20D20F210211000102030405060708090A0B0C0D0EF")
- _T("21221321421521621721821921A21B21C000102030405060708090A0B0C0D0EF")
- _T("21D21E21F220221222223224225226227000102030405060708090A0B0C0D0EF")
- _T("22822922A22B22C22D22E22F230231232000102030405060708090A0B0C0D0EF")
- _T("23323423523623723823923A23B23C23D000102030405060708090A0B0C0D0EF")
- _T("2366890FE1438751097E7F6325DC0E6326F")
- _T("25425525625725825925A25B25C25D25E25F000102030405060708090A0B0C0F");
-// Thread function for Call Context Inserts
-
-struct _ParamStruct
-{
- HANDLE hShutdownEvent;
- int nStartingRecordNum;
- long* pnNumCallsProcessed;
-};
-
-HANDLE hShutdownEvent = 0;
-
-BOOL WINAPI ConsoleCtrlHandler(DWORD dwCtrlType)
-{
- if(CTRL_C_EVENT == dwCtrlType)
- {
- SetEvent(hShutdownEvent);
- return TRUE;
- }
- return FALSE;
-}
-
-
-
-
-DWORD WINAPI RuntimeCallContext(LPVOID lpParam)
-{
- long nNumCallsProcessed = 0;
-
- struct _ParamStruct* pData = (struct _ParamStruct*)lpParam;
- int nStartingRecordID = pData->nStartingRecordNum;
-
- Ndb* pNdb;
- NdbConnection* pNdbConnection;
- NdbOperation* pNdbOperation;
- NdbRecAttr* pNdbRecAttrContextData;
-
- char pchContextData[4008];
-
- LARGE_INTEGER freq;
- LARGE_INTEGER liStartTime, liEndTime;
-
- pNdb = new Ndb("TEST_DB");
- if(!pNdb)
- {
- printf("new Ndb failed\n");
- return 0;
- }
-
- try
- {
- if(pNdb->init(1)
- || pNdb->waitUntilReady())
- {
- throw pNdb;
- }
-
- while(WaitForSingleObject(pData->hShutdownEvent,0) != WAIT_OBJECT_0)
- {
- nStartingRecordID++;
-
- bool bTimeLatency = (nStartingRecordID == 100) ? TRUE : FALSE;
-
- if (bTimeLatency)
- {
- BOOL bSuccess = QueryPerformanceFrequency(&freq);
- if (!bSuccess)
- printf("Error retrieving frequency: %d\n", GetLastError());
-
- }
-
- for (int i=0; i < 20; i++)
- {
- switch(i)
- {
- case 3:
- case 6:
- case 9:
- case 11:
- case 12:
- case 15:
- case 18: // Query Record
- if (bTimeLatency)
- QueryPerformanceCounter(&liStartTime);
-
- pNdbConnection = pNdb->startTransaction((Uint32)0, (const char*)&nStartingRecordID, (Uint32)4);
- if(!pNdbConnection)
- {
- throw pNdb;
- }
- pNdbOperation = pNdbConnection->getNdbOperation(_T("CallContext"));
- if(!pNdbOperation)
- {
- throw pNdbConnection;
- }
- if(pNdbOperation->readTuple()
- || pNdbOperation->equal(_T("ContextId"), nStartingRecordID))
- {
- throw pNdbOperation;
- }
- pNdbRecAttrContextData = pNdbOperation->getValue(_T("ContextData"), pchContextData);
- if(!pNdbRecAttrContextData)
- {
- throw pNdbOperation;
- }
- if(pNdbConnection->execute(Commit))
- {
- throw pNdbConnection;
- }
- pNdb->closeTransaction(pNdbConnection);
-
- if (bTimeLatency)
- {
- QueryPerformanceCounter(&liEndTime);
- printf("Read = %d msec.\n", (liEndTime.QuadPart - liStartTime.QuadPart) / (freq.QuadPart/1000));
- }
- break;
-
- case 19: // Delete Record
- if (bTimeLatency)
- QueryPerformanceCounter(&liStartTime);
-
- pNdbConnection = pNdb->startTransaction((Uint32)0, (const char*)&nStartingRecordID, (Uint32)4);
- if(!pNdbConnection)
- {
- throw pNdb;
- }
- pNdbOperation = pNdbConnection->getNdbOperation(_T("CallContext"));
- if(!pNdbOperation)
- {
- throw pNdbConnection;
- }
- if(pNdbOperation->deleteTuple()
- || pNdbOperation->equal(_T("ContextId"), nStartingRecordID))
- {
- throw pNdbOperation;
- }
- if(pNdbConnection->execute(Commit))
- {
- throw pNdbConnection;
- }
- pNdb->closeTransaction(pNdbConnection);
-
- if (bTimeLatency)
- {
- QueryPerformanceCounter(&liEndTime);
- printf("Delete = %d msec.\n", (liEndTime.QuadPart - liStartTime.QuadPart) / (freq.QuadPart/1000));
- }
- break;
-
- case 0: // Insert Record
- if (bTimeLatency)
- QueryPerformanceCounter(&liStartTime);
-
- pNdbConnection = pNdb->startTransaction((Uint32)0, (const char*)&nStartingRecordID, (Uint32)4);
- if(!pNdbConnection)
- {
- throw pNdb;
- }
- pNdbOperation = pNdbConnection->getNdbOperation(_T("CallContext"));
- if(!pNdbOperation)
- {
- throw pNdbConnection;
- }
- if(pNdbOperation->insertTuple()
- || pNdbOperation->equal(_T("ContextId"), nStartingRecordID)
- || pNdbOperation->setValue(_T("Version"), Int32(1))
- || pNdbOperation->setValue(_T("LockFlag"), Int32(1))
- || pNdbOperation->setValue(_T("LockTime"), Int32(1))
- || pNdbOperation->setValue(_T("LockTimeUSec"), Int32(1))
- || pNdbOperation->setValue(_T("ContextData"), STATUS_DATA, sizeof(STATUS_DATA)))
- {
- throw pNdbOperation;
- }
- if(pNdbConnection->execute(Commit))
- {
- throw pNdbConnection;
- }
- pNdb->closeTransaction(pNdbConnection);
-
- if (bTimeLatency)
- {
- QueryPerformanceCounter(&liEndTime);
- printf("Insert = %d msec.\n", (liEndTime.QuadPart - liStartTime.QuadPart) / (freq.QuadPart/1000));
- }
- break;
-
- default: // Update Record
- if (bTimeLatency)
- QueryPerformanceCounter(&liStartTime);
-
- pNdbConnection = pNdb->startTransaction((Uint32)0, (const char*)&nStartingRecordID, (Uint32)4);
- if(!pNdbConnection)
- {
- throw pNdb;
- }
- pNdbOperation = pNdbConnection->getNdbOperation(_T("CallContext"));
- if(!pNdbOperation)
- {
- throw pNdbConnection;
- }
- if(pNdbOperation->updateTuple())
- {
- throw pNdbOperation;
- }
- if(pNdbOperation->equal(_T("ContextId"), nStartingRecordID)
- || pNdbOperation->setValue(_T("ContextData"), STATUS_DATA, sizeof(STATUS_DATA)))
- {
- throw pNdbOperation;
- }
- if(pNdbConnection->execute(Commit))
- {
- throw pNdbConnection;
- }
- pNdb->closeTransaction(pNdbConnection);
-
- if (bTimeLatency)
- {
- QueryPerformanceCounter(&liEndTime);
- printf("Update = %d msec.\n", (liEndTime.QuadPart - liStartTime.QuadPart) / (freq.QuadPart/1000));
- }
-
- break;
- }
- }
-
- nNumCallsProcessed++;
-
- InterlockedIncrement(pData->pnNumCallsProcessed);
- }
-
- delete pNdb;
- }
- catch(Ndb* pNdb)
- {
- printf("%d: \n\t%s\n\t%s\n",
- pNdb->getNdbError(),
- pNdb->getNdbErrorString(),
- "Ndb");
- delete pNdb;
- }
- catch(NdbConnection* pNdbConnection)
- {
- printf("%d: \n\t%s\n\t%s\n",
- pNdbConnection->getNdbError(),
- pNdbConnection->getNdbErrorString(),
- "NdbConnection");
- pNdb->closeTransaction(pNdbConnection);
- delete pNdb;
- }
- catch(NdbOperation* pNdbOperation)
- {
- printf("%d: \n\t%s\n\t%s\n",
- pNdbOperation->getNdbError(),
- pNdbOperation->getNdbErrorString(),
- "NdbOperation");
- pNdb->closeTransaction(pNdbConnection);
- delete pNdb;
- }
-
- return 0;
-}
-
-
-void Initialize(Ndb* pNdb, long nInsert, bool bStoredTable)
-{
- NdbSchemaCon* pNdbSchemaCon;
- NdbSchemaOp* pNdbSchemaOp;
- NdbConnection* pNdbConnection;
- NdbOperation* pNdbOperation;
-
- try
- {
- _tprintf(_T("Create CallContext table\n"));
-
- pNdbSchemaCon = pNdb->startSchemaTransaction();
- if(!pNdbSchemaCon)
- {
- throw pNdb;
- }
- pNdbSchemaOp = pNdbSchemaCon->getNdbSchemaOp();
- if(!pNdbSchemaOp)
- {
- throw pNdbSchemaCon;
- }
- if(pNdbSchemaOp->createTable(_T("CallContext"), 8, TupleKey, 2, All, 6, 78, 80, 1, bStoredTable)
- || pNdbSchemaOp->createAttribute(_T("ContextId"), TupleKey, 32, 1, Signed)
- || pNdbSchemaOp->createAttribute(_T("Version"), NoKey, 32, 1, Signed)
- || pNdbSchemaOp->createAttribute(_T("LockFlag"), NoKey, 32, 1, Signed)
- || pNdbSchemaOp->createAttribute(_T("LockTime"), NoKey, 32, 1, Signed)
- || pNdbSchemaOp->createAttribute(_T("LockTimeUSec"), NoKey, 32, 1, Signed)
- || pNdbSchemaOp->createAttribute(_T("ContextData"), NoKey, 8, 4004, String))
- {
- throw pNdbSchemaOp;
- }
- if(pNdbSchemaCon->execute())
- {
- throw pNdbSchemaCon;
- }
- pNdb->closeSchemaTransaction(pNdbSchemaCon);
-
- _tprintf(_T("Insert %d tuples in the CallContext table\n"), nInsert);
- for(long i=0; i<nInsert; ++i)
- {
- long iContextId = -i;
- pNdbConnection = pNdb->startTransaction((Uint32)0, (const char*)&iContextId, (Uint32)4);
- if(!pNdbConnection)
- {
- throw pNdb;
- }
- pNdbOperation = pNdbConnection->getNdbOperation(_T("CallContext"));
- if(!pNdbOperation)
- {
- throw pNdbConnection;
- }
- if(pNdbOperation->insertTuple()
- || pNdbOperation->equal(_T("ContextId"), iContextId)
- || pNdbOperation->setValue(_T("Version"), Int32(1))
- || pNdbOperation->setValue(_T("LockFlag"), Int32(1))
- || pNdbOperation->setValue(_T("LockTime"), Int32(1))
- || pNdbOperation->setValue(_T("LockTimeUSec"), Int32(1))
- || pNdbOperation->setValue(_T("ContextData"), STATUS_DATA, sizeof(STATUS_DATA)))
- {
- throw pNdbOperation;
- }
- if(pNdbConnection->execute(Commit))
- {
- throw pNdbConnection;
- }
- pNdb->closeTransaction(pNdbConnection);
- }
- _tprintf(_T("initialisation done\n"));
- }
- catch(Ndb* pNdb)
- {
- printf("%d: \n\t%s\n\t%s\n",
- pNdb->getNdbError(),
- pNdb->getNdbErrorString(),
- "Ndb");
- delete pNdb;
- }
- catch(NdbConnection* pNdbConnection)
- {
- printf("%d: \n\t%s\n\t%s\n",
- pNdbConnection->getNdbError(),
- pNdbConnection->getNdbErrorString(),
- "NdbConnection");
- pNdb->closeTransaction(pNdbConnection);
- delete pNdb;
- }
- catch(NdbOperation* pNdbOperation)
- {
- printf("%d: \n\t%s\n\t%s\n",
- pNdbOperation->getNdbError(),
- pNdbOperation->getNdbErrorString(),
- "NdbOperation");
- pNdb->closeTransaction(pNdbConnection);
- delete pNdb;
- }
- catch(NdbSchemaCon* pNdbSchemaCon)
- {
- printf("%d: \n\t%s\n\t%s\n",
- pNdbSchemaCon->getNdbError(),
- pNdbSchemaCon->getNdbErrorString(),
- "pNdbSchemaCon");
- pNdb->closeSchemaTransaction(pNdbSchemaCon);
- delete pNdb;
- }
- catch(NdbSchemaOp* pNdbSchemaOp)
- {
- printf("%d: \n\t%s\n\t%s\n",
- pNdbSchemaOp->getNdbError(),
- pNdbSchemaOp->getNdbErrorString(),
- "pNdbSchemaOp");
- pNdb->closeTransaction(pNdbConnection);
- delete pNdb;
- }
-}
-
-
-int _tmain(int argc, _TCHAR* argv[])
-{
- long nNumThreads=4;
- long nSeed = 0;
- long nInsert = 0;
- bool bStoredTable = true;
- if(lstrcmp(argv[1],_T("/?")) == 0)
- {
- _tprintf(_T("InsertRecs [No.Of Threads] [Record Seed No.] [Init no. of rec.] [Stored?]\n"));
- return 0;
- }
-
- if(argc > 1)
- nNumThreads = _ttol(argv[1]);
- else
- nNumThreads = 4;
- if (argc > 2)
- nSeed = _ttol(argv[2]);
- _tprintf(_T("Num of Threads = %d, Seed = %d"), nNumThreads, nSeed);
-
- if(argc>3)
- nInsert = _ttol(argv[3]);
- if(argc>4)
- bStoredTable = (_ttol(argv[4])!=0);
-
- long nNumCallsProcessed = 0;
-
- SetConsoleCtrlHandler(ConsoleCtrlHandler,true);
- hShutdownEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
-
- // initiate windows sockets
- WORD wVersionRequested;
- WSADATA wsaData;
- int err;
- wVersionRequested = MAKEWORD( 2, 2 );
- err = WSAStartup( wVersionRequested, &wsaData );
- if ( err != 0 ) {
- _tprintf(_T("could not find a usable WinSock DLL\n"));
- return 0;
- }
- if ( LOBYTE( wsaData.wVersion ) != 2
- || HIBYTE( wsaData.wVersion ) != 2 )
- {
- _tprintf(_T("could not find a usable WinSock DLL\n"));
- WSACleanup();
- return 0;
- }
-
- Ndb* pNdb = new Ndb("TEST_DB");
- if(!pNdb)
- {
- _tprintf(_T("could not construct ndb\n"));
- return 0;
- }
- if(pNdb->init(1)
- || pNdb->waitUntilReady())
- {
- _tprintf(_T("could not initialize ndb\n"));
- return 0;
- }
-
- if(nInsert>0)
- {
- Initialize(pNdb, nInsert, bStoredTable);
- }
-
- if(nNumThreads>0)
- {
- _tprintf(_T("creating %d threads\n"), nNumThreads);
- DWORD dwStartTime = GetTickCount();
-
- DWORD dwThreadID = 0;
- HANDLE hThreads[50];
-
- struct _ParamStruct params[50];
-
- for(int ij=0;ij<nNumThreads;ij++) {
- params[ij].hShutdownEvent = hShutdownEvent;
- params[ij].nStartingRecordNum = (ij*5000) + nSeed;
- params[ij].pnNumCallsProcessed = &nNumCallsProcessed;
- }
-
- for(ij=0;ij<nNumThreads;ij++) {
- hThreads[ij] = CreateThread(NULL,NULL,RuntimeCallContext,&params[ij],0,&dwThreadID);
- }
-
- //Wait for the threads to finish
- WaitForMultipleObjects(nNumThreads,hThreads,TRUE,INFINITE);
- DWORD dwEndTime = GetTickCount();
-
- //Print time taken
- _tprintf(_T("Time Taken for %d Calls is %ld msec (= %ld calls/sec\n"),
- nNumCallsProcessed,dwEndTime-dwStartTime, (1000*nNumCallsProcessed/(dwEndTime-dwStartTime)));
- }
-
- delete pNdb;
- WSACleanup();
- CloseHandle(hShutdownEvent);
-
- return 0;
-}
-
-
diff --git a/storage/ndb/test/ndbapi/Makefile.am b/storage/ndb/test/ndbapi/Makefile.am
deleted file mode 100644
index d34d5e0590b..00000000000
--- a/storage/ndb/test/ndbapi/Makefile.am
+++ /dev/null
@@ -1,192 +0,0 @@
-# Copyright (C) 2004-2006 MySQL AB
-# Use is subject to license terms
-#
-# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-SUBDIRS = bank
-
-ndbtest_PROGRAMS = \
-flexBench \
-drop_all_tabs \
-create_all_tabs \
-create_tab \
-flexAsynch \
-flexBench \
-flexHammer \
-flexTT \
-testBackup \
-testBasic \
-testBasicAsynch \
-testBlobs \
-testDataBuffers \
-testDict \
-testIndex \
-testMgm \
-testNdbApi \
-testNodeRestart \
-testOIBasic \
-testOperations \
-testRestartGci \
-testScan \
-testInterpreter \
-testScanFilter \
-testScanInterpreter \
-testScanPerf \
-testSystemRestart \
-testTimeout \
-testTransactions \
-testDeadlock \
-test_event ndbapi_slow_select testReadPerf testLcp \
-testPartitioning \
-testBitfield \
-DbCreate DbAsyncGenerator \
-testSRBank \
-test_event_merge \
-testIndexStat \
-testNDBT \
-NdbRepStress
-
-EXTRA_PROGRAMS = \
- test_event \
- test_event_merge \
- test_event_multi_table
-#flexTimedAsynch
-#testBlobs
-#flex_bench_mysql
-
-create_all_tabs_SOURCES = create_all_tabs.cpp
-create_tab_SOURCES = create_tab.cpp
-drop_all_tabs_SOURCES = drop_all_tabs.cpp
-flexAsynch_SOURCES = flexAsynch.cpp
-flexBench_SOURCES = flexBench.cpp
-flexHammer_SOURCES = flexHammer.cpp
-flexTT_SOURCES = flexTT.cpp
-#flexTimedAsynch_SOURCES = flexTimedAsynch.cpp
-#flex_bench_mysql_SOURCES = flex_bench_mysql.cpp
-testBackup_SOURCES = testBackup.cpp
-testBasic_SOURCES = testBasic.cpp
-testBasicAsynch_SOURCES = testBasicAsynch.cpp
-testBlobs_SOURCES = testBlobs.cpp
-testDataBuffers_SOURCES = testDataBuffers.cpp
-testDict_SOURCES = testDict.cpp
-testIndex_SOURCES = testIndex.cpp
-testMgm_SOURCES = testMgm.cpp
-testNdbApi_SOURCES = testNdbApi.cpp
-testNodeRestart_SOURCES = testNodeRestart.cpp
-testOIBasic_SOURCES = testOIBasic.cpp
-testOperations_SOURCES = testOperations.cpp
-testRestartGci_SOURCES = testRestartGci.cpp
-testScan_SOURCES = testScan.cpp ScanFunctions.hpp
-testInterpreter_SOURCES = testInterpreter.cpp
-testScanFilter_SOURCES = testScanFilter.cpp
-testScanInterpreter_SOURCES = testScanInterpreter.cpp ScanFilter.hpp ScanInterpretTest.hpp
-testScanPerf_SOURCES = testScanPerf.cpp
-testSystemRestart_SOURCES = testSystemRestart.cpp
-testTimeout_SOURCES = testTimeout.cpp
-testTransactions_SOURCES = testTransactions.cpp
-testDeadlock_SOURCES = testDeadlock.cpp
-test_event_SOURCES = test_event.cpp
-ndbapi_slow_select_SOURCES = slow_select.cpp
-testReadPerf_SOURCES = testReadPerf.cpp
-testLcp_SOURCES = testLcp.cpp
-testPartitioning_SOURCES = testPartitioning.cpp
-testNDBT_SOURCES = testNDBT.cpp
-testNDBT_LDADD = $(LDADD) $(top_srcdir)/libmysql_r/libmysqlclient_r.la
-testBitfield_SOURCES = testBitfield.cpp
-NdbRepStress_SOURCES = acrt/NdbRepStress.cpp
-DbCreate_SOURCES = bench/mainPopulate.cpp bench/dbPopulate.cpp bench/userInterface.cpp bench/dbPopulate.h bench/userInterface.h bench/testData.h bench/testDefinitions.h bench/ndb_schema.hpp bench/ndb_error.hpp
-DbAsyncGenerator_SOURCES = bench/mainAsyncGenerator.cpp bench/asyncGenerator.cpp bench/ndb_async2.cpp bench/dbGenerator.h bench/macros.h bench/userInterface.h bench/testData.h bench/testDefinitions.h bench/ndb_schema.hpp bench/ndb_error.hpp
-testSRBank_SOURCES = testSRBank.cpp
-test_event_merge_SOURCES = test_event_merge.cpp
-test_event_multi_table_SOURCES = test_event_multi_table.cpp
-testIndexStat_SOURCES = testIndexStat.cpp
-
-INCLUDES_LOC = -I$(top_srcdir)/storage/ndb/include/kernel
-
-include $(top_srcdir)/storage/ndb/config/common.mk.am
-include $(top_srcdir)/storage/ndb/config/type_ndbapitest.mk.am
-
-##testDict_INCLUDES = $(INCLUDES) -I$(top_srcdir)/ndb/include/kernel
-##testIndex_INCLUDES = $(INCLUDES) -I$(top_srcdir)/ndb/include/kernel
-##testSystemRestart_INCLUDES = $(INCLUDES) -I$(top_srcdir)/ndb/include/kernel
-##testTransactions_INCLUDES = $(INCLUDES) -I$(top_srcdir)/ndb/include/kernel
-NdbRepStress_INCLUDES = $(INCLUDES) -I$(top_srcdir)/ndb/test/include -I$(top_srcdir)/include
-testBackup_LDADD = $(LDADD) bank/libbank.a
-testSRBank_LDADD = bank/libbank.a $(LDADD)
-NdbRepStress_LDADD = $(LDADD) $(top_builddir)/libmysql_r/libmysqlclient_r.la
-
-windoze-dsp: flexBench.dsp testBasic.dsp testBlobs.dsp \
- testScan.dsp
-
-flexBench.dsp: Makefile \
- $(top_srcdir)/storage/ndb/config/win-prg.am \
- $(top_srcdir)/storage/ndb/config/win-name \
- $(top_srcdir)/storage/ndb/config/win-includes \
- $(top_srcdir)/storage/ndb/config/win-sources \
- $(top_srcdir)/storage/ndb/config/win-libraries
- cat $(top_srcdir)/storage/ndb/config/win-prg.am > $@
- @$(top_srcdir)/storage/ndb/config/win-name $@ flexBench
- @$(top_srcdir)/storage/ndb/config/win-includes $@ $(INCLUDES)
- @$(top_srcdir)/storage/ndb/config/win-sources $@ $(flexBench_SOURCES)
- @$(top_srcdir)/storage/ndb/config/win-libraries $@ LINK $(LDADD)
-
-testBasic.dsp: Makefile \
- $(top_srcdir)/storage/ndb/config/win-prg.am \
- $(top_srcdir)/storage/ndb/config/win-name \
- $(top_srcdir)/storage/ndb/config/win-includes \
- $(top_srcdir)/storage/ndb/config/win-sources \
- $(top_srcdir)/storage/ndb/config/win-libraries
- cat $(top_srcdir)/storage/ndb/config/win-prg.am > $@
- @$(top_srcdir)/storage/ndb/config/win-name $@ testBasic
- @$(top_srcdir)/storage/ndb/config/win-includes $@ $(INCLUDES)
- @$(top_srcdir)/storage/ndb/config/win-sources $@ $(testBasic_SOURCES)
- @$(top_srcdir)/storage/ndb/config/win-libraries $@ LINK $(LDADD)
-
-testOIBasic.dsp: Makefile \
- $(top_srcdir)/storage/ndb/config/win-prg.am \
- $(top_srcdir)/storage/ndb/config/win-name \
- $(top_srcdir)/storage/ndb/config/win-includes \
- $(top_srcdir)/storage/ndb/config/win-sources \
- $(top_srcdir)/storage/ndb/config/win-libraries
- cat $(top_srcdir)/storage/ndb/config/win-prg.am > $@
- @$(top_srcdir)/storage/ndb/config/win-name $@ testOIBasic
- @$(top_srcdir)/storage/ndb/config/win-includes $@ $(INCLUDES)
- @$(top_srcdir)/storage/ndb/config/win-sources $@ $(testOIBasic_SOURCES)
- @$(top_srcdir)/storage/ndb/config/win-libraries $@ LINK $(LDADD)
-
-testBlobs.dsp: Makefile \
- $(top_srcdir)/storage/ndb/config/win-prg.am \
- $(top_srcdir)/storage/ndb/config/win-name \
- $(top_srcdir)/storage/ndb/config/win-includes \
- $(top_srcdir)/storage/ndb/config/win-sources \
- $(top_srcdir)/storage/ndb/config/win-libraries
- cat $(top_srcdir)/storage/ndb/config/win-prg.am > $@
- @$(top_srcdir)/storage/ndb/config/win-name $@ testBlobs
- @$(top_srcdir)/storage/ndb/config/win-includes $@ $(INCLUDES)
- @$(top_srcdir)/storage/ndb/config/win-sources $@ $(testBlobs_SOURCES)
- @$(top_srcdir)/storage/ndb/config/win-libraries $@ LINK $(LDADD)
-
-testScan.dsp: Makefile \
- $(top_srcdir)/storage/ndb/config/win-prg.am \
- $(top_srcdir)/storage/ndb/config/win-name \
- $(top_srcdir)/storage/ndb/config/win-includes \
- $(top_srcdir)/storage/ndb/config/win-sources \
- $(top_srcdir)/storage/ndb/config/win-libraries
- cat $(top_srcdir)/storage/ndb/config/win-prg.am > $@
- @$(top_srcdir)/storage/ndb/config/win-name $@ testScan
- @$(top_srcdir)/storage/ndb/config/win-includes $@ $(INCLUDES)
- @$(top_srcdir)/storage/ndb/config/win-sources $@ $(testScan_SOURCES)
- @$(top_srcdir)/storage/ndb/config/win-libraries $@ LINK $(LDADD)
-
-
diff --git a/storage/ndb/test/ndbapi/ScanFilter.hpp b/storage/ndb/test/ndbapi/ScanFilter.hpp
deleted file mode 100644
index b4c51fa14f1..00000000000
--- a/storage/ndb/test/ndbapi/ScanFilter.hpp
+++ /dev/null
@@ -1,131 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef SCAN_FILTER_HPP
-#define SCAN_FILTER_HPP
-
-class ScanFilter {
-public:
-#if 0
- /**
- * Create a scan filter for table tab
- * colNo - column to filter on
- * val - val to use when selecting valu to filter on
- *
- */
- ScanFilter(const NDBT_Table& tab,
- int colNo,
- int val);
-#endif
- ScanFilter(int records = 1000){};
- virtual int filterOp(NdbOperation*) = 0;
- virtual int verifyRecord(NDBT_ResultRow&) = 0;
-private:
-
- // const NDBT_Table& tab;
-};
-
-class LessThanFilter : public ScanFilter {
-public:
- LessThanFilter(int records){ compare_value = records / 100; };
-private:
- Uint32 compare_value;
- int filterOp(NdbOperation* pOp);
- int verifyRecord(NDBT_ResultRow&);
-};
-
-class EqualFilter : public ScanFilter {
- static const Uint32 compare_value = 100;
- int filterOp(NdbOperation* pOp);
- int verifyRecord(NDBT_ResultRow&);
-};
-
-class NoFilter : public ScanFilter {
- int filterOp(NdbOperation* pOp);
- int verifyRecord(NDBT_ResultRow&);
-};
-
-
-int LessThanFilter::filterOp(NdbOperation* pOp){
-
- if (pOp->load_const_u32(1, compare_value) != 0)
- return NDBT_FAILED;
-
- if (pOp->read_attr("KOL2", 2) != 0)
- return NDBT_FAILED;
-
- if (pOp->branch_lt(1, 2, 0) != 0)
- return NDBT_FAILED;
-
- if (pOp->interpret_exit_nok() != 0)
- return NDBT_FAILED;
-
- if (pOp->def_label(0) != 0)
- return NDBT_FAILED;
-
- if (pOp->interpret_exit_ok() != 0)
- return NDBT_FAILED;
-
- return NDBT_OK;
-}
-
-int LessThanFilter::verifyRecord(NDBT_ResultRow& row){
- NdbRecAttr* rec = row.attributeStore(1);
- if (rec->u_32_value() < compare_value)
- return NDBT_OK;
- return NDBT_FAILED;
-}
-
-int EqualFilter::filterOp(NdbOperation* pOp){
-
- if (pOp->load_const_u32(1, compare_value) != 0)
- return NDBT_FAILED;
-
- if (pOp->read_attr("KOL2", 2) != 0)
- return NDBT_FAILED;
-
- if (pOp->branch_eq(1, 2, 0) != 0)
- return NDBT_FAILED;
-
- if (pOp->interpret_exit_nok() != 0)
- return NDBT_FAILED;
-
- if (pOp->def_label(0) != 0)
- return NDBT_FAILED;
-
- if (pOp->interpret_exit_ok() != 0)
- return NDBT_FAILED;
-
- return NDBT_OK;
-}
-
-int EqualFilter::verifyRecord(NDBT_ResultRow& row){
- NdbRecAttr* rec = row.attributeStore(1);
- if (rec->u_32_value() == compare_value)
- return NDBT_OK;
- return NDBT_FAILED;
-}
-
-int NoFilter::filterOp(NdbOperation* pOp){
- return NDBT_OK;
-}
-
-int NoFilter::verifyRecord(NDBT_ResultRow& row){
- // Check if this record should be in the result set or not
- return NDBT_OK;
-}
-
-#endif
diff --git a/storage/ndb/test/ndbapi/ScanFunctions.hpp b/storage/ndb/test/ndbapi/ScanFunctions.hpp
deleted file mode 100644
index e2f6e75f88f..00000000000
--- a/storage/ndb/test/ndbapi/ScanFunctions.hpp
+++ /dev/null
@@ -1,352 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT.hpp>
-#include <NDBT_Test.hpp>
-
-
-
-struct Attrib {
- int numAttribs;
- int attribs[1024];
-};
-class AttribList {
-public:
- AttribList(){};
- ~AttribList(){
- for(size_t i = 0; i < attriblist.size(); i++){
- delete attriblist[i];
- }
- };
- void buildAttribList(const NdbDictionary::Table* pTab);
- Vector<Attrib*> attriblist;
-};
-
-
-// Functions that help out in testing that we may call
-// scan functions in wrong order etc
-// and receive a proper errormessage
-class ScanFunctions {
-public:
- ScanFunctions(const NdbDictionary::Table& _tab) : tab(_tab){
- }
- enum ActionType {
- CloseWithoutStop,
- NextScanWhenNoMore,
- ExecuteScanWithOutOpenScan,
- OnlyOneScanPerTrans,
- OnlyOneOpBeforeOpenScan,
- OnlyOpenScanOnce,
- OnlyOneOpInScanTrans,
- CheckInactivityTimeOut,
- CheckInactivityBeforeClose ,
- NoCloseTransaction,
- EqualAfterOpenScan
- };
-
-
- int scanReadFunctions(Ndb* pNdb,
- int records,
- int parallelism,
- ActionType action,
- bool exclusive);
-private:
- const NdbDictionary::Table& tab;
-};
-
-
-inline
-int
-ScanFunctions::scanReadFunctions(Ndb* pNdb,
- int records,
- int parallelism,
- ActionType action,
- bool exclusive){
- int retryAttempt = 0;
- const int retryMax = 100;
- int sleepTime = 10;
- int check;
- NdbConnection *pTrans = 0;
- NdbScanOperation *pOp = 0;
-
- while (true){
- if (retryAttempt >= retryMax){
- g_err << "ERROR: has retried this operation " << retryAttempt
- << " times, failing!" << endl;
- return NDBT_FAILED;
- }
-
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- const NdbError err = pNdb->getNdbError();
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- return NDBT_FAILED;
- }
-
- // Execute the scan without defining a scan operation
- pOp = pTrans->getNdbScanOperation(tab.getName());
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- if( pOp->readTuples(exclusive ?
- NdbScanOperation::LM_Exclusive :
- NdbScanOperation::LM_Read) ) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
-
- if (action == OnlyOpenScanOnce){
- // Call openScan one more time when it's already defined
- if( pOp->readTuples(NdbScanOperation::LM_Read) ) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
- }
-
- if (action==EqualAfterOpenScan){
- check = pOp->equal(tab.getColumn(0)->getName(), 10);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
- }
-
- check = pOp->interpret_exit_ok();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- for(int a = 0; a<tab.getNoOfColumns(); a++){
- if(pOp->getValue(tab.getColumn(a)->getName()) == NULL) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
- }
-
- check = pTrans->execute(NoCommit);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- int abortCount = records / 10;
- bool abortTrans = (action==CloseWithoutStop);
- int eof;
- int rows = 0;
- eof = pOp->nextResult();
-
- while(eof == 0){
- rows++;
-
- if (abortCount == rows && abortTrans == true){
- g_info << "Scan is aborted after "<<abortCount<<" rows" << endl;
-
- if (action != CloseWithoutStop){
- // Test that we can closeTrans without stopScan
- pOp->close();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
- }
-
-
- pNdb->closeTransaction(pTrans);
- return NDBT_OK;
- }
-
- if(action == CheckInactivityTimeOut){
- if ((rows % (records / 10)) == 0){
- // Sleep for a long time before calling nextScanResult
- if (sleepTime > 1)
- sleepTime--;
- g_info << "Sleeping "<<sleepTime<<" secs " << endl;
- NdbSleep_SecSleep(sleepTime);
- }
- }
-
- eof = pOp->nextResult();
- }
- if (eof == -1) {
- const NdbError err = pTrans->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
-
- // Be cruel, call nextScanResult after error
- for(int i=0; i<10; i++){
- eof = pOp->nextResult();
- if(eof == 0){
- g_err << "nextScanResult returned eof = " << eof << endl
- << " That is an error when there are no more records" << endl;
- return NDBT_FAILED;
- }
- }
- // Be cruel end
-
- pNdb->closeTransaction(pTrans);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- g_info << "Starting over" << endl;
-
- // If test is CheckInactivityTimeOut
- // error 296 is expected
- if ((action == CheckInactivityTimeOut) &&
- (err.code == 296))
- return NDBT_OK;
-
- continue;
- }
- ERR(err);
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- if (action == NextScanWhenNoMore){
- g_info << "Calling nextScanresult when there are no more records" << endl;
- for(int i=0; i<10; i++){
- eof = pOp->nextResult();
- if(eof == 0){
- g_err << "nextScanResult returned eof = " << eof << endl
- << " That is an error when there are no more records" << endl;
- return NDBT_FAILED;
- }
- }
-
- }
- if(action == CheckInactivityBeforeClose){
- // Sleep for a long time before calling close
- g_info << "NdbSleep_SecSleep(5) before close transaction" << endl;
- NdbSleep_SecSleep(5);
- }
- if(action == NoCloseTransaction)
- g_info << "Forgetting to close transaction" << endl;
- else
- pNdb->closeTransaction(pTrans);
-
- g_info << rows << " rows have been read" << endl;
- if (records != 0 && rows != records){
- g_err << "Check expected number of records failed" << endl
- << " expected=" << records <<", " << endl
- << " read=" << rows << endl;
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
- }
- return NDBT_FAILED;
-
-
-}
-
-void AttribList::buildAttribList(const NdbDictionary::Table* pTab){
- attriblist.clear();
-
- Attrib* attr;
- // Build attrib definitions that describes which attributes to read
- // Try to build strange combinations, not just "all" or all PK's
-
- // Scan without reading any attributes
- attr = new Attrib;
- attr->numAttribs = 0;
- attriblist.push_back(attr);
- int i;
- for(i = 1; i < pTab->getNoOfColumns(); i++){
- attr = new Attrib;
- attr->numAttribs = i;
- for(int a = 0; a<i; a++)
- attr->attribs[a] = a;
- attriblist.push_back(attr);
- }
- for(i = pTab->getNoOfColumns()-1; i > 0; i--){
- attr = new Attrib;
- attr->numAttribs = i;
- for(int a = 0; a<i; a++)
- attr->attribs[a] = a;
- attriblist.push_back(attr);
- }
- for(i = pTab->getNoOfColumns(); i > 0; i--){
- attr = new Attrib;
- attr->numAttribs = pTab->getNoOfColumns() - i;
- for(int a = 0; a<pTab->getNoOfColumns() - i; a++)
- attr->attribs[a] = pTab->getNoOfColumns()-a-1;
- attriblist.push_back(attr);
- }
- for(i = 1; i < pTab->getNoOfColumns(); i++){
- attr = new Attrib;
- attr->numAttribs = pTab->getNoOfColumns() - i;
- for(int a = 0; a<pTab->getNoOfColumns() - i; a++)
- attr->attribs[a] = pTab->getNoOfColumns()-a-1;
- attriblist.push_back(attr);
- }
- for(i = 1; i < pTab->getNoOfColumns(); i++){
- attr = new Attrib;
- attr->numAttribs = 2;
- for(int a = 0; a<2; a++){
- attr->attribs[a] = i%pTab->getNoOfColumns();
- }
- attriblist.push_back(attr);
- }
-
- // Last
- attr = new Attrib;
- attr->numAttribs = 1;
- attr->attribs[0] = pTab->getNoOfColumns()-1;
- attriblist.push_back(attr);
-
- // Last and first
- attr = new Attrib;
- attr->numAttribs = 2;
- attr->attribs[0] = pTab->getNoOfColumns()-1;
- attr->attribs[1] = 0;
- attriblist.push_back(attr);
-
- // First and last
- attr = new Attrib;
- attr->numAttribs = 2;
- attr->attribs[0] = 0;
- attr->attribs[1] = pTab->getNoOfColumns()-1;
- attriblist.push_back(attr);
-
-#if 1
- for(size_t j = 0; j < attriblist.size(); j++){
-
- g_info << attriblist[j]->numAttribs << ": " ;
- for(int a = 0; a < attriblist[j]->numAttribs; a++)
- g_info << attriblist[j]->attribs[a] << ", ";
- g_info << endl;
- }
-#endif
-
-}
diff --git a/storage/ndb/test/ndbapi/ScanInterpretTest.hpp b/storage/ndb/test/ndbapi/ScanInterpretTest.hpp
deleted file mode 100644
index 52eb0f46cc4..00000000000
--- a/storage/ndb/test/ndbapi/ScanInterpretTest.hpp
+++ /dev/null
@@ -1,515 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef SCAN_INTERPRET_TEST_HPP
-#define SCAN_INTERPRET_TEST_HPP
-
-#include "ScanFilter.hpp"
-
-class ScanInterpretTest {
-public:
- ScanInterpretTest(const NdbDictionary::Table& _tab,
- const NdbDictionary::Table& _restab) :
- tab(_tab),
- restab(_restab),
- row(_tab){
- }
-
- int scanRead(Ndb*,
- int records,
- int parallelism,
- ScanFilter& filter);
- int scanReadVerify(Ndb*,
- int records,
- int parallelism,
- ScanFilter& filter);
-
- int addRowToInsert(Ndb* pNdb,
- NdbConnection* pInsTrans);
- int addRowToCheckTrans(Ndb* pNdb,
- NdbConnection* pCheckTrans);
-private:
- const NdbDictionary::Table& tab;
- const NdbDictionary::Table& restab;
- NDBT_ResultRow row;
-
-};
-
-
-inline
-int
-ScanInterpretTest::addRowToInsert(Ndb* pNdb,
- NdbConnection* pInsTrans){
-
- NdbOperation* pOp =
- pInsTrans->getNdbOperation(restab.getName());
- if (pOp == NULL) {
- ERR(pInsTrans->getNdbError());
- pNdb->closeTransaction(pInsTrans);
- return NDBT_FAILED;
- }
-
- if( pOp->insertTuple() == -1 ) {
- ERR(pInsTrans->getNdbError());
- pNdb->closeTransaction(pInsTrans);
- return NDBT_FAILED;
- }
-
- // Copy all attribute to the new operation
- for (int a = 0; a<restab.getNoOfColumns(); a++){
- const NdbDictionary::Column* attr = tab.getColumn(a);
- NdbRecAttr* reca = row.attributeStore(a);
- int check = -1;
- switch (attr->getType()){
- case NdbDictionary::Column::Char:
- case NdbDictionary::Column::Varchar:
- case NdbDictionary::Column::Binary:
- case NdbDictionary::Column::Varbinary:{
- check = pOp->setValue( attr->getName(),
- reca->aRef());
- break;
- }
- case NdbDictionary::Column::Int:{
- check = pOp->setValue( attr->getName(),
- reca->int32_value());
- }
- break;
- case NdbDictionary::Column::Bigint:{
- check = pOp->setValue( attr->getName(),
- reca->int64_value());
- }
- break;
- case NdbDictionary::Column::Unsigned:{
- check = pOp->setValue( attr->getName(),
- reca->u_32_value());
- }
- break;
- case NdbDictionary::Column::Bigunsigned:{
- check = pOp->setValue( attr->getName(),
- reca->u_64_value());
- }
- break;
- case NdbDictionary::Column::Float:
- check = pOp->setValue( attr->getName(),
- reca->float_value());
-
- break;
- default:
- check = -1;
- break;
- }
- if(check != 0){
- ERR(pInsTrans->getNdbError());
- pNdb->closeTransaction(pInsTrans);
- return NDBT_FAILED;
- }
- }
-
- return NDBT_OK;
-}
-
-inline
-int
-ScanInterpretTest::addRowToCheckTrans(Ndb* pNdb,
- NdbConnection* pCheckTrans){
-
- NdbOperation* pOp =
- pCheckTrans->getNdbOperation(restab.getName());
- if (pOp == NULL) {
- ERR(pNdb->getNdbError());
- return NDBT_FAILED;
- }
-
- if(pOp->readTuple() != 0) {
- ERR(pNdb->getNdbError());
- return NDBT_FAILED;
- }
-
- // Copy pk attribute's to the new operation
- for (int a = 0; a<restab.getNoOfColumns(); a++){
- const NdbDictionary::Column* attr = restab.getColumn(a);
- if (attr->getPrimaryKey() == true){
- NdbRecAttr* reca = row.attributeStore(a);
- int check = -1;
- switch (attr->getType()){
- case NdbDictionary::Column::Char:
- case NdbDictionary::Column::Varchar:
- case NdbDictionary::Column::Binary:
- case NdbDictionary::Column::Varbinary:{
- check = pOp->equal( attr->getName(),
- reca->aRef());
- break;
- }
- case NdbDictionary::Column::Int:{
- check = pOp->equal( attr->getName(),
- reca->int32_value());
- }
- break;
- case NdbDictionary::Column::Bigint:{
- check = pOp->equal( attr->getName(),
- reca->int64_value());
- }
- break;
- case NdbDictionary::Column::Unsigned:{
- check = pOp->equal( attr->getName(),
- reca->u_32_value());
- }
- break;
- case NdbDictionary::Column::Bigunsigned:{
- check = pOp->equal( attr->getName(),
- reca->u_64_value());
- }
- break;
- default:
- check = -1;
- break;
- }
- if(check != 0){
- ERR(pNdb->getNdbError());
- return NDBT_FAILED;
- }
- }
- }
-
- return NDBT_OK;
-}
-
-inline
-int
-ScanInterpretTest::scanRead(Ndb* pNdb,
- int records,
- int parallelism,
- ScanFilter& filter){
- int retryAttempt = 0;
- int retryMax = 100;
- int check;
- NdbConnection *pTrans;
- NdbScanOperation *pOp;
-
- while (true){
-
- if (retryAttempt >= retryMax){
- ndbout << "ERROR: has retried this operation " << retryAttempt
- << " times, failing!" << endl;
- return NDBT_FAILED;
- }
-
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- const NdbError err = pNdb->getNdbError();
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- return NDBT_FAILED;
- }
-
- pOp = pTrans->getNdbScanOperation(tab.getName());
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- if( pOp->readTuples(NdbScanOperation::LM_Read, 0, parallelism) ) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- if (filter.filterOp(pOp) != 0){
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- // Read all attributes
- for(int a = 0; a<tab.getNoOfColumns(); a++){
- if((row.attributeStore(a) =
- pOp->getValue(tab.getColumn(a)->getName())) == 0) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
- }
- check = pTrans->execute(NoCommit);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- int eof;
- int rows = 0;
- NdbConnection* pInsTrans;
-
- while((eof = pOp->nextResult(true)) == 0){
- do {
- rows++;
- if (addRowToInsert(pNdb, pTrans) != 0){
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
- } while((eof = pOp->nextResult(false)) == 0);
-
- check = pTrans->execute(Commit);
- if( check == -1 ) {
- const NdbError err = pTrans->getNdbError();
- ERR(err);
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
- }
- if (eof == -1) {
- const NdbError err = pTrans->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- pNdb->closeTransaction(pTrans);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- pNdb->closeTransaction(pTrans);
-
- g_info << rows << " rows have been scanned" << endl;
-
- return NDBT_OK;
- }
- return NDBT_FAILED;
-}
-
-inline
-int
-ScanInterpretTest::scanReadVerify(Ndb* pNdb,
- int records,
- int parallelism,
- ScanFilter& filter){
- int retryAttempt = 0;
- const int retryMax = 100;
- int check;
- NdbConnection *pTrans;
- NdbScanOperation *pOp;
-
- while (true){
-
- if (retryAttempt >= retryMax){
- ndbout << "ERROR: has retried this operation " << retryAttempt
- << " times, failing!" << endl;
- return NDBT_FAILED;
- }
-
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- const NdbError err = pNdb->getNdbError();
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- return NDBT_FAILED;
- }
-
-
- pOp = pTrans->getNdbScanOperation(tab.getName());
- if (pOp == NULL) { if (pOp->getValue("KOL2") == 0){
- ERR(pNdb->getNdbError());
- return NDBT_FAILED;
- }
-
-
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- if( pOp->readTuples(NdbScanOperation::LM_Read, 0, parallelism) ) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp->interpret_exit_ok();
- if (check == -1) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
-
- // Read all attributes
- for(int a = 0; a<tab.getNoOfColumns(); a++){
- if((row.attributeStore(a) =
- pOp->getValue(tab.getColumn(a)->getName())) == 0) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
- }
- check = pTrans->execute(NoCommit);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- int eof;
- int rows = 0;
- int rowsNoExist = 0;
- int rowsExist = 0;
- int existingRecordsNotFound = 0;
- int nonExistingRecordsFound = 0;
-
-
- NdbConnection* pExistTrans;
- NdbConnection* pNoExistTrans;
-
- while((eof = pOp->nextResult(true)) == 0){
- pExistTrans = pNdb->startTransaction();
- if (pExistTrans == NULL) {
- const NdbError err = pNdb->getNdbError();
- ERR(err);
- return NDBT_FAILED;
- }
- pNoExistTrans = pNdb->startTransaction();
- if (pNoExistTrans == NULL) {
- const NdbError err = pNdb->getNdbError();
- ERR(err);
- return NDBT_FAILED;
- }
- do {
- rows++;
- if (filter.verifyRecord(row) == NDBT_OK){
- rowsExist++;
- if (addRowToCheckTrans(pNdb, pExistTrans) != 0){
- pNdb->closeTransaction(pTrans);
- pNdb->closeTransaction(pExistTrans);
- pNdb->closeTransaction(pNoExistTrans);
- return NDBT_FAILED;
- }
- }else{
- rowsNoExist++;
- if (addRowToCheckTrans(pNdb, pNoExistTrans) != 0){
- pNdb->closeTransaction(pTrans);
- pNdb->closeTransaction(pExistTrans);
- pNdb->closeTransaction(pNoExistTrans);
- return NDBT_FAILED;
- }
- }
- } while((eof = pOp->nextResult(false)) == 0);
-
-
- // Execute the transaction containing reads of
- // all the records that should be in the result table
- check = pExistTrans->execute(Commit);
- if( check == -1 ) {
- const NdbError err = pExistTrans->getNdbError();
- ERR(err);
- if (err.code != 626){
- pNdb->closeTransaction(pExistTrans);
- pNdb->closeTransaction(pNoExistTrans);
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }else{
- // Some of the records expected to be found wasn't
- // there
- existingRecordsNotFound = 1;
- }
- }
- pNdb->closeTransaction(pExistTrans);
-
- // Execute the transaction containing reads of
- // all the records that should NOT be in the result table
- check = pNoExistTrans->execute(Commit, CommitAsMuchAsPossible);
- if( check == -1 ) {
- const NdbError err = pNoExistTrans->getNdbError();
- // The transactions error code should be zero
- if (err.code != 626){
- ERR(err);
- pNdb->closeTransaction(pNoExistTrans);
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
- // Loop through the no existing transaction and check that no
- // operations where successful
- const NdbOperation* pOp2 = NULL;
- while ((pOp2 = pNoExistTrans->getNextCompletedOperation(pOp2)) != NULL){
- const NdbError err = pOp2->getNdbError();
- if (err.code != 626){
- ndbout << "err.code = " << err.code<< endl;
- nonExistingRecordsFound = 1;
- }
- }
- }
-
- pNdb->closeTransaction(pNoExistTrans);
-
-
- }
- if (eof == -1) {
- const NdbError err = pTrans->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- pNdb->closeTransaction(pTrans);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- int testResult = NDBT_OK;
- int rowsResult = 0;
- UtilTransactions utilTrans(restab);
- if (utilTrans.selectCount(pNdb,
- 240,
- &rowsResult) != 0){
- return NDBT_FAILED;
- }
- if (existingRecordsNotFound == 1){
- ndbout << "!!! Expected records not found" << endl;
- testResult = NDBT_FAILED;
- }
- if (nonExistingRecordsFound == 1){
- ndbout << "!!! Unxpected records found" << endl;
- testResult = NDBT_FAILED;
- }
- ndbout << rows << " rows scanned("
- << rowsExist << " found, " << rowsResult<<" expected)" << endl;
- if (rowsResult != rowsExist){
- ndbout << "!!! Number of rows in result table different from expected" << endl;
- testResult = NDBT_FAILED;
- }
-
- return testResult;
- }
- return NDBT_FAILED;
-}
-
-#endif
diff --git a/storage/ndb/test/ndbapi/TraceNdbApi.cpp b/storage/ndb/test/ndbapi/TraceNdbApi.cpp
deleted file mode 100644
index 434485f0198..00000000000
--- a/storage/ndb/test/ndbapi/TraceNdbApi.cpp
+++ /dev/null
@@ -1,543 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NdbApi.hpp>
-#include <NdbOut.hpp>
-#include <NdbMutex.h>
-
-#include "TraceNdbApi.hpp"
-
-
-int g_nParamTrace;
-NdbMutex* g_pNdbMutexTrace = 0;
-
-
-void TraceBegin(void)
-{
- if(!g_pNdbMutexTrace)
- {
- g_pNdbMutexTrace = NdbMutex_Create();
- }
- NdbMutex_Lock(g_pNdbMutexTrace);
- g_nParamTrace = 0;
-}
-
-void TraceEnd(void)
-{
- ndbout << endl;
- g_nParamTrace = 0;
- NdbMutex_Unlock(g_pNdbMutexTrace);
-}
-
-void TraceMethod(const char* szMethod)
-{
- ndbout << "->" << szMethod << "(";
- g_nParamTrace = 0;
-}
-
-void TraceParamComma(void)
-{
- if(g_nParamTrace)
- {
- ndbout << ", ";
- }
- ++g_nParamTrace;
-}
-
-void TraceNdb(Ndb* pNdb)
-{
- TraceParamComma();
- ndbout << "((Ndb*)" << hex << (Uint32)pNdb << ")";
-}
-
-void TraceNdbSchemaCon(NdbSchemaCon* pNdbSchemaCon)
-{
- TraceParamComma();
- ndbout << "((NdbSchemaCon*)" << hex << (Uint32)pNdbSchemaCon << ")";
-}
-
-void TraceNdbSchemaOp(NdbSchemaOp* pNdbSchemaOp)
-{
- TraceParamComma();
- ndbout << "((NdbSchemaOp*)" << hex << (Uint32)pNdbSchemaOp << ")";
-}
-
-void TraceNdbConnection(const NdbConnection* pNdbConnection)
-{
- TraceParamComma();
- ndbout << "((NdbConnection*)" << hex << (Uint32)pNdbConnection << ")";
-}
-
-void TraceNdbOperation(NdbOperation* pNdbOperation)
-{
- TraceParamComma();
- ndbout << "((NdbOperation*)" << hex << (Uint32)pNdbOperation << ")";
-}
-
-void TraceNdbIndexOperation(NdbIndexOperation* pNdbIndexOperation)
-{
- TraceParamComma();
- ndbout << "((NdbIndexOperation*)" << hex << (Uint32)pNdbIndexOperation << ")";
-}
-
-void TraceNdbRecAttr(NdbRecAttr* pNdbRecAttr)
-{
- TraceParamComma();
- ndbout << "((NdbRecAttr*)" << hex << (Uint32)pNdbRecAttr << ")";
-}
-
-void TraceTable(Table* pTable)
-{
- TraceParamComma();
- ndbout << "((Table*)" << hex << (Uint32)pTable << ")";
-}
-
-void TraceString(const char* szParam)
-{
- TraceParamComma();
- ndbout << "\"" << szParam << "\"";
-}
-
-void TraceInt(const int i)
-{
- TraceParamComma();
- ndbout << "(int)" << dec << i;
-}
-
-void TraceUint32(const Uint32 n)
-{
- TraceParamComma();
- ndbout << "(Uint32)" << dec << n;
-}
-
-void TraceKeyType(const KeyType aKeyType)
-{
- TraceParamComma();
- switch(aKeyType)
- {
- case Undefined: ndbout << "Undefined"; break;
- case NoKey: ndbout << "NoKey"; break;
- case TupleKey: ndbout << "TupleKey"; break;
- case TupleId: ndbout << "TupleId"; break;
- default: ndbout << "(KeyType)" << aKeyType; break;
- }
-}
-
-void TraceExecType(const ExecType aExecType)
-{
- switch(aExecType)
- {
- case NoExecTypeDef: ndbout << "NoExecTypeDef"; break;
- case Prepare: ndbout << "Prepare"; break;
- case NoCommit: ndbout << "NoCommit"; break;
- case Commit: ndbout << "Commit"; break;
- case Rollback: ndbout << "Rollback"; break;
- default: ndbout << "(ExecType)" << aExecType; break;
- }
-}
-
-
-void TraceNdbError(const NdbError& err)
-{
- TraceParamComma();
- ndbout << "(NdbError)" << err;
-}
-
-
-
-void TraceVoid(void)
-{
- ndbout << "void";
-}
-
-void TraceReturn(void)
-{
- ndbout << "); // return ";
- g_nParamTrace = 0;
-}
-
-
-// TraceNdbSchemaOp
-
-int CTraceNdbSchemaOp::createTable(const char* aTableName)
-{
- int i = NdbSchemaOp::createTable(aTableName);
- TraceBegin();
- TraceNdbSchemaOp(this);
- TraceMethod("createTable");
- TraceString(aTableName);
- TraceReturn();
- TraceInt(i);
- TraceEnd();
- return i;
-}
-
-int CTraceNdbSchemaOp::createAttribute(const char* aAttrName, KeyType aTupleyKey)
-{
- int i = NdbSchemaOp::createAttribute(aAttrName, aTupleyKey);
- TraceBegin();
- TraceNdbSchemaOp(this);
- TraceMethod("createAttribute");
- TraceString(aAttrName);
- TraceKeyType(aTupleyKey);
- TraceReturn();
- TraceInt(i);
- TraceEnd();
- return i;
-}
-
-
-
-// TraceNdbSchemaCon
-
-CTraceNdbSchemaOp* CTraceNdbSchemaCon::getNdbSchemaOp()
-{
- NdbSchemaOp* pNdbSchemaOp = NdbSchemaCon::getNdbSchemaOp();
- TraceBegin();
- TraceNdbSchemaCon(this);
- TraceMethod("getNdbSchemaOp");
- TraceReturn();
- TraceNdbSchemaOp(pNdbSchemaOp);
- TraceEnd();
- return (CTraceNdbSchemaOp*)pNdbSchemaOp;
-}
-
-int CTraceNdbSchemaCon::execute()
-{
- int i = NdbSchemaCon::execute();
- TraceBegin();
- TraceNdbSchemaCon(this);
- TraceMethod("execute");
- TraceReturn();
- TraceInt(i);
- TraceEnd();
- return i;
-}
-
-
-
-// TraceNdbRecAttr
-
-Uint32 CTraceNdbRecAttr::u_32_value()
-{
- Uint32 n = NdbRecAttr::u_32_value();
- TraceBegin();
- TraceNdbRecAttr(this);
- TraceMethod("u_32_value");
- TraceReturn();
- TraceUint32(n);
- TraceEnd();
- return n;
-}
-
-
-
-// TraceNdbOperation
-
-int CTraceNdbOperation::insertTuple()
-{
- int i = NdbOperation::insertTuple();
- TraceBegin();
- TraceNdbOperation(this);
- TraceMethod("insertTuple");
- TraceReturn();
- TraceInt(i);
- TraceEnd();
- return i;
-}
-
-int CTraceNdbOperation::updateTuple()
-{
- int i = NdbOperation::updateTuple();
- TraceBegin();
- TraceNdbOperation(this);
- TraceMethod("updateTuple");
- TraceReturn();
- TraceInt(i);
- TraceEnd();
- return i;
-}
-
-int CTraceNdbOperation::interpretedUpdateTuple()
-{
- int i = NdbOperation::interpretedUpdateTuple();
- TraceBegin();
- TraceNdbOperation(this);
- TraceMethod("interpretedUpdateTuple");
- TraceReturn();
- TraceInt(i);
- TraceEnd();
- return i;
-}
-
-int CTraceNdbOperation::readTuple()
-{
- int i = NdbOperation::readTuple();
- TraceBegin();
- TraceNdbOperation(this);
- TraceMethod("readTuple");
- TraceReturn();
- TraceInt(i);
- TraceEnd();
- return i;
-}
-
-
-int CTraceNdbOperation::readTupleExclusive()
-{
- int i = NdbOperation::readTupleExclusive();
- TraceBegin();
- TraceNdbOperation(this);
- TraceMethod("readTupleExclusive");
- TraceReturn();
- TraceInt(i);
- TraceEnd();
- return i;
-}
-
-
-int CTraceNdbOperation::deleteTuple()
-{
- int i = NdbOperation::deleteTuple();
- TraceBegin();
- TraceNdbOperation(this);
- TraceMethod("deleteTuple");
- TraceReturn();
- TraceInt(i);
- TraceEnd();
- return i;
-}
-
-int CTraceNdbOperation::equal(const char* anAttrName, Uint32 aValue)
-{
- int i = NdbOperation::equal(anAttrName, aValue);
- TraceBegin();
- TraceNdbOperation(this);
- TraceMethod("equal");
- TraceString(anAttrName);
- TraceUint32(aValue);
- TraceReturn();
- TraceInt(i);
- TraceEnd();
- return i;
-}
-
-int CTraceNdbOperation::setValue(const char* anAttrName, Uint32 aValue)
-{
- int i = NdbOperation::setValue(anAttrName, aValue);
- TraceBegin();
- TraceNdbOperation(this);
- TraceMethod("setValue");
- TraceString(anAttrName);
- TraceUint32(aValue);
- TraceReturn();
- TraceInt(i);
- TraceEnd();
- return i;
-}
-
-int CTraceNdbOperation::incValue(const char* anAttrName, Uint32 aValue)
-{
- int i = NdbOperation::incValue(anAttrName, aValue);
- TraceBegin();
- TraceNdbOperation(this);
- TraceMethod("incValue");
- TraceString(anAttrName);
- TraceUint32(aValue);
- TraceReturn();
- TraceInt(i);
- TraceEnd();
- return i;
-}
-
-CTraceNdbRecAttr* CTraceNdbOperation::getValue(const char* anAttrName)
-{
- NdbRecAttr* pNdbRecAttr = NdbOperation::getValue(anAttrName);
- TraceBegin();
- TraceNdbOperation(this);
- TraceMethod("getValue");
- TraceString(anAttrName);
- TraceReturn();
- TraceNdbRecAttr(pNdbRecAttr);
- TraceEnd();
- return (CTraceNdbRecAttr*)pNdbRecAttr;
-}
-
-
-// TraceNdbIndexOperation
-
-int CTraceNdbIndexOperation::equal(const char* anAttrName, Uint32 aValue)
-{
- int i = NdbIndexOperation::equal(anAttrName, aValue);
- TraceBegin();
- TraceNdbIndexOperation(this);
- TraceMethod("equal");
- TraceString(anAttrName);
- TraceUint32(aValue);
- TraceReturn();
- TraceInt(i);
- TraceEnd();
- return i;
-}
-
-
-int CTraceNdbIndexOperation::incValue(const char* anAttrName, Uint32 aValue)
-{
- int i = NdbIndexOperation::incValue(anAttrName, aValue);
- TraceBegin();
- TraceNdbIndexOperation(this);
- TraceMethod("incValue");
- TraceString(anAttrName);
- TraceUint32(aValue);
- TraceReturn();
- TraceInt(i);
- TraceEnd();
- return i;
-}
-
-
-CTraceNdbRecAttr* CTraceNdbIndexOperation::getValue(const char* anAttrName)
-{
- NdbRecAttr* pNdbRecAttr = NdbIndexOperation::getValue(anAttrName);
- TraceBegin();
- TraceNdbIndexOperation(this);
- TraceMethod("getValue");
- TraceString(anAttrName);
- TraceReturn();
- TraceNdbRecAttr(pNdbRecAttr);
- TraceEnd();
- return (CTraceNdbRecAttr*)pNdbRecAttr;
-}
-
-
-// TraceNdbConnection
-
-CTraceNdbOperation* CTraceNdbConnection::getNdbOperation(const char* aTableName)
-{
- NdbOperation* pNdbOperation = NdbConnection::getNdbOperation(aTableName);
- TraceBegin();
- TraceNdbConnection(this);
- TraceMethod("getNdbOperation");
- TraceString(aTableName);
- TraceReturn();
- TraceNdbOperation(pNdbOperation);
- TraceEnd();
- return (CTraceNdbOperation*)pNdbOperation;
-}
-
-CTraceNdbIndexOperation* CTraceNdbConnection::getNdbIndexOperation(const char* anIndexName, const char* aTableName)
-{
- NdbIndexOperation* pNdbIndexOperation = NdbConnection::getNdbIndexOperation(anIndexName, aTableName);
- TraceBegin();
- TraceNdbConnection(this);
- TraceMethod("getNdbIndexOperation");
- TraceString(anIndexName);
- TraceString(aTableName);
- TraceReturn();
- TraceNdbIndexOperation(pNdbIndexOperation);
- TraceEnd();
- return (CTraceNdbIndexOperation*)pNdbIndexOperation;
-}
-
-int CTraceNdbConnection::execute(ExecType aTypeOfExec)
-{
- int i = NdbConnection::execute(aTypeOfExec);
- TraceBegin();
- TraceNdbConnection(this);
- TraceMethod("execute");
- TraceExecType(aTypeOfExec);
- TraceReturn();
- TraceInt(i);
- TraceEnd();
- return i;
-}
-
-const NdbError & CTraceNdbConnection::getNdbError(void) const
-{
- const NdbError& err = NdbConnection::getNdbError();
- TraceBegin();
- TraceNdbConnection(this);
- TraceMethod("getNdbError");
- TraceReturn();
- TraceNdbError(err);
- TraceEnd();
- return err;
-}
-
-
-
-// TraceNdb
-
-CTraceNdb::CTraceNdb(const char* aDataBase)
-: Ndb(aDataBase)
-{
- TraceBegin();
- TraceNdb(this);
- TraceMethod("Ndb");
- TraceString(aDataBase);
- TraceReturn();
- TraceVoid();
- TraceEnd();
-}
-
-CTraceNdbSchemaCon* CTraceNdb::startSchemaTransaction()
-{
- NdbSchemaCon* pNdbSchemaCon = Ndb::startSchemaTransaction();
- TraceBegin();
- TraceNdb(this);
- TraceMethod("startSchemaTransaction");
- TraceReturn();
- TraceNdbSchemaCon(pNdbSchemaCon);
- TraceEnd();
- return (CTraceNdbSchemaCon*)pNdbSchemaCon;
-}
-
-void CTraceNdb::closeSchemaTransaction(CTraceNdbSchemaCon* aSchemaCon)
-{
- Ndb::closeSchemaTransaction(aSchemaCon);
- TraceBegin();
- TraceNdb(this);
- TraceMethod("closeSchemaTransaction");
- TraceReturn();
- TraceVoid();
- TraceEnd();
-}
-
-CTraceNdbConnection* CTraceNdb::startTransaction()
-{
- NdbConnection* pNdbConnection = Ndb::startTransaction();
- TraceBegin();
- TraceNdb(this);
- TraceMethod("startTransaction");
- TraceReturn();
- TraceNdbConnection(pNdbConnection);
- TraceEnd();
- return (CTraceNdbConnection*)pNdbConnection;
-}
-
-void CTraceNdb::closeTransaction(CTraceNdbConnection* aConnection)
-{
- Ndb::closeTransaction(aConnection);
- TraceBegin();
- TraceNdb(this);
- TraceMethod("closeTransaction");
- TraceNdbConnection(aConnection);
- TraceReturn();
- TraceVoid();
- TraceEnd();
-}
-
-
diff --git a/storage/ndb/test/ndbapi/VerifyNdbApi.cpp b/storage/ndb/test/ndbapi/VerifyNdbApi.cpp
deleted file mode 100644
index d2052b14591..00000000000
--- a/storage/ndb/test/ndbapi/VerifyNdbApi.cpp
+++ /dev/null
@@ -1,151 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-#include <NdbApi.hpp>
-#include <NdbOut.hpp>
-#include <NdbMutex.h>
-
-#include "VerifyNdbApi.hpp"
-
-
-NdbMutex* g_pNdbMutexVerify = 0;
-
-
-void VerifyBegin(void)
-{
- if(!g_pNdbMutexVerify)
- {
- g_pNdbMutexVerify = NdbMutex_Create();
- }
- NdbMutex_Lock(g_pNdbMutexVerify);
-}
-
-void VerifyEnd(void)
-{
- NdbMutex_Unlock(g_pNdbMutexVerify);
-}
-
-
-
-void CVerifyNdbSchemaOp::VerifyIntError(const int i, const char* szMethod)
-{
- VerifyBegin();
- ndbout << "NdbSchemaOp::" << szMethod << " returned " << dec << i;
- ndbout << " : " << dec << getNdbError().code << " : " << getNdbError().message << endl;
- VerifyEnd();
-}
-
-
-void CVerifyNdbSchemaCon::VerifyIntError(const int i, const char* szMethod)
-{
- VerifyBegin();
- ndbout << "NdbSchemaCon::" << szMethod << " returned " << dec << i;
- ndbout << " : " << dec << getNdbError().code << " : " << getNdbError().message << endl;
- VerifyEnd();
-}
-
-
-void CVerifyNdbSchemaCon::VerifyPtrError(void* p, const char* szMethod)
-{
- VerifyBegin();
- ndbout << "NdbSchemaCon::" << szMethod << " returned " << hex << (Uint32)p;
- ndbout << " : " << dec << getNdbError().code << " : " << getNdbError().message << endl;
- VerifyEnd();
-}
-
-
-void CVerifyNdbRecAttr::VerifyValueError(const int iNull, const char* szMethod)
-{
- VerifyBegin();
- ndbout << "NdbRecAttr::" << szMethod << " : isNULL() returned " << dec << iNull;
- ndbout << endl;
- VerifyEnd();
-}
-
-
-void CVerifyNdbOperation::VerifyIntError(const int i, const char* szMethod)
-{
- VerifyBegin();
- ndbout << "NdbOperation::" << szMethod << " returned " << dec << i;
- ndbout << " : " << dec << getNdbError().code << " : " << getNdbError().message << endl;
- VerifyEnd();
-}
-
-
-void CVerifyNdbOperation::VerifyPtrError(void* p, const char* szMethod)
-{
- VerifyBegin();
- ndbout << "NdbOperation::" << szMethod << " returned " << hex << (Uint32)p;
- ndbout << " : " << dec << getNdbError().code << " : " << getNdbError().message << endl;
- VerifyEnd();
-}
-
-
-void CVerifyNdbIndexOperation::VerifyIntError(const int i, const char* szMethod)
-{
- VerifyBegin();
- ndbout << "NdbIndexOperation::" << szMethod << " returned " << dec << i;
- ndbout << " : " << dec << getNdbError().code << " : " << getNdbError().message << endl;
- VerifyEnd();
-}
-
-
-void CVerifyNdbIndexOperation::VerifyPtrError(void* p, const char* szMethod)
-{
- VerifyBegin();
- ndbout << "NdbIndexOperation::" << szMethod << " returned " << hex << (Uint32)p;
- ndbout << " : " << dec << getNdbError().code << " : " << getNdbError().message << endl;
- VerifyEnd();
-}
-
-
-void CVerifyNdbConnection::VerifyIntError(const int i, const char* szMethod)
-{
- VerifyBegin();
- ndbout << "NdbConnection::" << szMethod << " returned " << dec << i;
- ndbout << " : " << dec << getNdbError().code << " : " << getNdbError().message << endl;
- VerifyEnd();
-}
-
-
-void CVerifyNdbConnection::VerifyPtrError(void* p, const char* szMethod)
-{
- VerifyBegin();
- ndbout << "NdbConnection::" << szMethod << " returned " << hex << (Uint32)p;
- ndbout << " : " << dec << getNdbError().code << " : " << getNdbError().message << endl;
- VerifyEnd();
-}
-
-
-void CVerifyNdb::VerifyPtrError(void* p, const char* szMethod)
-{
- VerifyBegin();
- ndbout << "Ndb::" << szMethod << " returned " << hex << (Uint32)p;
- ndbout << " : " << dec << getNdbError().code << " : " << getNdbError().message << endl;
- VerifyEnd();
-}
-
-
-void CVerifyNdb::VerifyVoidError(const int iCode, const char* szMethod)
-{
- VerifyBegin();
- ndbout << "Ndb::" << szMethod << " : getNdbError().code returned " << dec << iCode;
- ndbout << " : " << getNdbError().message << endl;
- VerifyEnd();
-}
-
-
diff --git a/storage/ndb/test/ndbapi/acid.cpp b/storage/ndb/test/ndbapi/acid.cpp
deleted file mode 100644
index 375a41cd076..00000000000
--- a/storage/ndb/test/ndbapi/acid.cpp
+++ /dev/null
@@ -1,533 +0,0 @@
-/* Copyright (c) 2003-2006 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NdbApi.hpp>
-#include <NdbSchemaCon.hpp>
-#include <NdbMutex.h>
-#include <NdbOut.hpp>
-#include <NdbSleep.h>
-#include <NdbThread.h>
-#include <NdbTick.h>
-#include <NdbMain.h>
-#include <NdbTest.hpp>
-#include <random.h>
-
-//#define TRACE
-#define DEBUG
-//#define RELEASE
-#define NODE_REC // epaulsa: introduces pointer checks to help 'acid' keep core
-// during node recovery
-
-#ifdef TRACE
-
-#define VerifyMethodInt(c, m) (ReportMethodInt(c->m, c, #c, #m, __FILE__, __LINE__))
-#define VerifyMethodPtr(v, c, m) (v=ReportMethodPtr(c->m, c, #v, #c, #m, __FILE__, __LINE__))
-#define VerifyMethodVoid(c, m) (c->m, ReportMethodVoid(c, #c, #m, __FILE__, __LINE__))
-
-int ReportMethodInt(int iRes, NdbConnection* pNdbConnection, const char* szClass, const char* szMethod, const char* szFile, const int iLine)
-{
- ndbout << szFile << "(" << iLine << ") : ";
- ndbout << szClass << "->" << szMethod << " return " << iRes << " : ";
- ndbout << pNdbConnection->getNdbError();
- NdbOperation* pNdbOperation = pNdbConnection->getNdbErrorOperation();
- if(pNdbOperation) {
- ndbout << " : " << pNdbOperation->getNdbError();
- }
- ndbout << " : " << pNdbConnection->getNdbErrorLine();
- ndbout << endl;
- return iRes;
-}
-
-template <class C>
-int ReportMethodInt(int iRes, C* pC, const char* szClass, const char* szMethod, const char* szFile, const int iLine)
-{
- ndbout << szFile << "(" << iLine << ") : ";
- ndbout << szClass << "->" << szMethod << " return " << iRes << " : ";
- ndbout << pC->getNdbError();
- ndbout << endl;
- return iRes;
-}
-
-template <class R, class C>
-R* ReportMethodPtr(R* pR, C* pC, const char* szVariable, const char* szClass, const char* szMethod, const char* szFile, const int iLine)
-{
- ndbout << szFile << "(" << iLine << ") : ";
- ndbout << szVariable << " = " << szClass << "->" << szMethod << " return " << (long)(void*)pR << " : ";
- ndbout << pC->getNdbError();
- ndbout << endl;
- return pR;
-}
-
-template <class C>
-void ReportMethodVoid(C* pC, const char* szClass, const char* szMethod, const char* szFile, const int iLine)
-{
- ndbout << szFile << "(" << iLine << ") : ";
- ndbout << szClass << "->" << szMethod << " : ";
- ndbout << pC->getNdbError();
- ndbout << endl;
-}
-#endif /* TRACE */
-
-
-#ifdef DEBUG
-
-#define VerifyMethodInt(c, m) (ReportMethodInt(c->m, c, #c, #m, __FILE__, __LINE__))
-#define VerifyMethodPtr(v, c, m) (v=ReportMethodPtr(c->m, c, #v, #c, #m, __FILE__, __LINE__))
-#define VerifyMethodVoid(c, m) (c->m, ReportMethodVoid(c, #c, #m, __FILE__, __LINE__))
-
-int ReportMethodInt(int iRes, NdbConnection* pNdbConnection, const char* szClass, const char* szMethod, const char* szFile, const int iLine)
-{
- if(iRes<0) {
- ndbout << szFile << "(" << iLine << ") : ";
- ndbout << szClass << "->" << szMethod << " return " << iRes << " : ";
- ndbout << pNdbConnection->getNdbError();
- NdbOperation* pNdbOperation = pNdbConnection->getNdbErrorOperation();
- if(pNdbOperation) {
- ndbout << " : " << pNdbOperation->getNdbError();
- }
- ndbout << " : " << pNdbConnection->getNdbErrorLine();
- ndbout << " : ";
- ndbout << endl;
- }
- return iRes;
-}
-
-template <class C>
-int ReportMethodInt(int iRes, C* pC, const char* szClass, const char* szMethod, const char* szFile, const int iLine)
-{
- if(iRes<0) {
- ndbout << szFile << "(" << iLine << ") : ";
- ndbout << szClass << "->" << szMethod << " return " << iRes << " : ";
- ndbout << pC->getNdbError();
- ndbout << endl;
- }
- return iRes;
-}
-
-template <class R, class C>
-R* ReportMethodPtr(R* pR, C* pC, const char* szVariable, const char* szClass, const char* szMethod, const char* szFile, const int iLine)
-{
- if(!pR) {
- ndbout << szFile << "(" << iLine << ") : ";
- ndbout << szVariable << " = " << szClass << "->" << szMethod << " return " << " : ";
- ndbout << pC->getNdbError();
- ndbout << endl;
- }
- return pR;
-}
-
-template <class C>
-void ReportMethodVoid(C* pC, const char* szClass, const char* szMethod, const char* szFile, const int iLine)
-{
- if(pC->getNdbError().code) {
- ndbout << szFile << "(" << iLine << ") : ";
- ndbout << szClass << "->" << szMethod << " : ";
- ndbout << pC->getNdbError();
- ndbout << endl;
- }
-}
-
-
-#endif /* DEBUG */
-
-
-#ifdef RELEASE
-
-#define VerifyMethodInt(c, m) (c->m)
-#define VerifyMethodPtr(v, c, m) (v=(c->m))
-#define VerifyMethodVoid(c, m) (c->m)
-
-int ReportMethodInt(int iRes, NdbConnection* pNdbConnection, const char* szClass, const char* szMethod, const char* szFile, const int iLine)
-{
- if(iRes<0) {
- ndbout << szFile << "(" << iLine << ") : ";
- ndbout << szClass << "->" << szMethod << " return " << iRes << " : ";
- ndbout << pNdbConnection->getNdbError();
- NdbOperation* pNdbOperation = pNdbConnection->getNdbErrorOperation();
- if(pNdbOperation) {
- ndbout << " : " << pNdbOperation->getNdbError();
- }
- ndbout << " : " << pNdbConnection->getNdbErrorLine();
- ndbout << endl;
- }
- return iRes;
-}
-
-#endif /* RELEASE */
-
-// epaulsa =>
-#ifndef NODE_REC
-#define CHK_TR(p)
-#else
-#define CHK_TR(p) if(!p){ \
- ndbout <<"startTransaction failed, returning now." << endl ; \
- delete pNdb ; \
- pNdb = NULL ; \
- return 0 ; \
- }
-#endif // NODE_REC
-// <= epaulsa
-
-const char* c_szWarehouse = "WAREHOUSE";
-const char* c_szWarehouseNumber = "W_ID";
-const char* c_szWarehouseSum = "W_SUM";
-const char* c_szWarehouseCount = "W_CNT";
-const char* c_szDistrict = "DISTRICT";
-const char* c_szDistrictWarehouseNumber = "D_W_ID";
-const char* c_szDistrictNumber = "D_ID";
-const char* c_szDistrictSum = "D_SUM";
-const char* c_szDistrictCount = "D_CNT";
-
-Uint32 g_nWarehouseCount = 10;
-Uint32 g_nDistrictPerWarehouse = 10;
-Uint32 g_nThreadCount = 1;
-NdbMutex* g_pNdbMutex = 0;
-
-extern "C" void* NdbThreadFuncInsert(void* pArg)
-{
- myRandom48Init((long int)NdbTick_CurrentMillisecond());
- unsigned nSucc = 0;
- unsigned nFail = 0;
- Ndb* pNdb = NULL ;
- pNdb = new Ndb("TEST_DB");
- VerifyMethodInt(pNdb, init());
- VerifyMethodInt(pNdb, waitUntilReady());
-
- while(NdbMutex_Trylock(g_pNdbMutex)) {
- Uint32 nWarehouse = myRandom48(g_nWarehouseCount);
- NdbConnection* pNdbConnection = NULL ;
- VerifyMethodPtr(pNdbConnection, pNdb, startTransaction());
- CHK_TR(pNdbConnection);
- NdbOperation* pNdbOperationW = NULL ;
- VerifyMethodPtr(pNdbOperationW, pNdbConnection, getNdbOperation(c_szWarehouse));
- VerifyMethodInt(pNdbOperationW, insertTuple());
- VerifyMethodInt(pNdbOperationW, equal(c_szWarehouseNumber, nWarehouse));
- VerifyMethodInt(pNdbOperationW, setValue(c_szWarehouseCount, Uint32(1)));
- Uint32 nWarehouseSum = 0;
- for(Uint32 nDistrict=0; nDistrict<g_nDistrictPerWarehouse; ++nDistrict) {
- NdbOperation* pNdbOperationD = NULL ;
- VerifyMethodPtr(pNdbOperationD, pNdbConnection, getNdbOperation(c_szDistrict));
- VerifyMethodInt(pNdbOperationD, insertTuple());
- VerifyMethodInt(pNdbOperationD, equal(c_szDistrictWarehouseNumber, nWarehouse));
- VerifyMethodInt(pNdbOperationD, equal(c_szDistrictNumber, nDistrict));
- VerifyMethodInt(pNdbOperationD, setValue(c_szDistrictCount, Uint32(1)));
- Uint32 nDistrictSum = myRandom48(100);
- nWarehouseSum += nDistrictSum;
- VerifyMethodInt(pNdbOperationD, setValue(c_szDistrictSum, nDistrictSum));
- }
- VerifyMethodInt(pNdbOperationW, setValue(c_szWarehouseSum, nWarehouseSum));
- int iExec = pNdbConnection->execute(Commit);
- int iError = pNdbConnection->getNdbError().code;
-
- if(iExec<0 && iError!=0 && iError!=266 && iError!=630) {
- ReportMethodInt(iExec, pNdbConnection, "pNdbConnection", "execute(Commit)", __FILE__, __LINE__);
- }
- if(iExec==0) {
- ++nSucc;
- } else {
- ++nFail;
- }
- VerifyMethodVoid(pNdb, closeTransaction(pNdbConnection));
- }
- ndbout << "insert: " << nSucc << " succeeded, " << nFail << " failed " << endl;
- NdbMutex_Unlock(g_pNdbMutex);
- delete pNdb;
- pNdb = NULL ;
- return NULL;
-}
-
-
-extern "C" void* NdbThreadFuncUpdate(void* pArg)
-{
- myRandom48Init((long int)NdbTick_CurrentMillisecond());
- unsigned nSucc = 0;
- unsigned nFail = 0;
- Ndb* pNdb = NULL ;
- pNdb = new Ndb("TEST_DB");
- VerifyMethodInt(pNdb, init());
- VerifyMethodInt(pNdb, waitUntilReady());
-
- while(NdbMutex_Trylock(g_pNdbMutex)) {
- Uint32 nWarehouse = myRandom48(g_nWarehouseCount);
- NdbConnection* pNdbConnection = NULL ;
- VerifyMethodPtr(pNdbConnection, pNdb, startTransaction());
- CHK_TR(pNdbConnection) ; // epaulsa
- NdbOperation* pNdbOperationW = NULL ;
- VerifyMethodPtr(pNdbOperationW, pNdbConnection, getNdbOperation(c_szWarehouse));
- VerifyMethodInt(pNdbOperationW, interpretedUpdateTuple());
- VerifyMethodInt(pNdbOperationW, equal(c_szWarehouseNumber, nWarehouse));
- VerifyMethodInt(pNdbOperationW, incValue(c_szWarehouseCount, Uint32(1)));
- Uint32 nWarehouseSum = 0;
- for(Uint32 nDistrict=0; nDistrict<g_nDistrictPerWarehouse; ++nDistrict) {
- NdbOperation* pNdbOperationD = NULL ;
- VerifyMethodPtr(pNdbOperationD, pNdbConnection, getNdbOperation(c_szDistrict));
- VerifyMethodInt(pNdbOperationD, interpretedUpdateTuple());
- VerifyMethodInt(pNdbOperationD, equal(c_szDistrictWarehouseNumber, nWarehouse));
- VerifyMethodInt(pNdbOperationD, equal(c_szDistrictNumber, nDistrict));
- VerifyMethodInt(pNdbOperationD, incValue(c_szDistrictCount, Uint32(1)));
- Uint32 nDistrictSum = myRandom48(100);
- nWarehouseSum += nDistrictSum;
- VerifyMethodInt(pNdbOperationD, setValue(c_szDistrictSum, nDistrictSum));
- }
- VerifyMethodInt(pNdbOperationW, setValue(c_szWarehouseSum, nWarehouseSum));
- int iExec = pNdbConnection->execute(Commit);
- int iError = pNdbConnection->getNdbError().code;
-
- if(iExec<0 && iError!=0 && iError!=266 && iError!=626) {
- ReportMethodInt(iExec, pNdbConnection, "pNdbConnection", "execute(Commit)", __FILE__, __LINE__);
- }
- if(iExec==0) {
- ++nSucc;
- } else {
- ++nFail;
- }
- VerifyMethodVoid(pNdb, closeTransaction(pNdbConnection));
- }
- ndbout << "update: " << nSucc << " succeeded, " << nFail << " failed " << endl;
- NdbMutex_Unlock(g_pNdbMutex);
- delete pNdb;
- pNdb = NULL ;
- return NULL;
-}
-
-
-extern "C" void* NdbThreadFuncDelete(void* pArg)
-{
- myRandom48Init((long int)NdbTick_CurrentMillisecond());
- unsigned nSucc = 0;
- unsigned nFail = 0;
- Ndb* pNdb = NULL ;
- pNdb = new Ndb("TEST_DB");
- VerifyMethodInt(pNdb, init());
- VerifyMethodInt(pNdb, waitUntilReady());
-
- while(NdbMutex_Trylock(g_pNdbMutex)) {
- Uint32 nWarehouse = myRandom48(g_nWarehouseCount);
- NdbConnection* pNdbConnection = NULL ;
- VerifyMethodPtr(pNdbConnection, pNdb, startTransaction());
- CHK_TR(pNdbConnection) ; // epaulsa
- NdbOperation* pNdbOperationW = NULL ;
- VerifyMethodPtr(pNdbOperationW, pNdbConnection, getNdbOperation(c_szWarehouse));
- VerifyMethodInt(pNdbOperationW, deleteTuple());
- VerifyMethodInt(pNdbOperationW, equal(c_szWarehouseNumber, nWarehouse));
- for(Uint32 nDistrict=0; nDistrict<g_nDistrictPerWarehouse; ++nDistrict) {
- NdbOperation* pNdbOperationD = NULL ;
- VerifyMethodPtr(pNdbOperationD, pNdbConnection, getNdbOperation(c_szDistrict));
- VerifyMethodInt(pNdbOperationD, deleteTuple());
- VerifyMethodInt(pNdbOperationD, equal(c_szDistrictWarehouseNumber, nWarehouse));
- VerifyMethodInt(pNdbOperationD, equal(c_szDistrictNumber, nDistrict));
- }
- int iExec = pNdbConnection->execute(Commit);
- int iError = pNdbConnection->getNdbError().code;
-
- if(iExec<0 && iError!=0 && iError!=266 && iError!=626) {
- ReportMethodInt(iExec, pNdbConnection, "pNdbConnection", "execute(Commit)", __FILE__, __LINE__);
- }
- if(iExec==0) {
- ++nSucc;
- } else {
- ++nFail;
- }
- VerifyMethodVoid(pNdb, closeTransaction(pNdbConnection));
- }
- ndbout << "delete: " << nSucc << " succeeded, " << nFail << " failed " << endl;
- NdbMutex_Unlock(g_pNdbMutex);
- delete pNdb;
- pNdb = NULL ;
- return NULL;
-}
-
-
-extern "C" void* NdbThreadFuncRead(void* pArg)
-{
- myRandom48Init((long int)NdbTick_CurrentMillisecond());
- unsigned nSucc = 0;
- unsigned nFail = 0;
- NdbRecAttr** ppNdbRecAttrDSum = new NdbRecAttr*[g_nDistrictPerWarehouse];
- NdbRecAttr** ppNdbRecAttrDCnt = new NdbRecAttr*[g_nDistrictPerWarehouse];
- Ndb* pNdb = NULL ;
- pNdb = new Ndb("TEST_DB");
- VerifyMethodInt(pNdb, init());
- VerifyMethodInt(pNdb, waitUntilReady());
-
- while(NdbMutex_Trylock(g_pNdbMutex)) {
- Uint32 nWarehouse = myRandom48(g_nWarehouseCount);
- NdbConnection* pNdbConnection = NULL ;
- VerifyMethodPtr(pNdbConnection, pNdb, startTransaction());
- CHK_TR(pNdbConnection) ; // epaulsa
- NdbOperation* pNdbOperationW = NULL ;
- VerifyMethodPtr(pNdbOperationW, pNdbConnection, getNdbOperation(c_szWarehouse));
- VerifyMethodInt(pNdbOperationW, readTuple());
- VerifyMethodInt(pNdbOperationW, equal(c_szWarehouseNumber, nWarehouse));
- NdbRecAttr* pNdbRecAttrWSum;
- VerifyMethodPtr(pNdbRecAttrWSum, pNdbOperationW, getValue(c_szWarehouseSum, 0));
- NdbRecAttr* pNdbRecAttrWCnt;
- VerifyMethodPtr(pNdbRecAttrWCnt, pNdbOperationW, getValue(c_szWarehouseCount, 0));
- for(Uint32 nDistrict=0; nDistrict<g_nDistrictPerWarehouse; ++nDistrict) {
- NdbOperation* pNdbOperationD = NULL ;
- VerifyMethodPtr(pNdbOperationD, pNdbConnection, getNdbOperation(c_szDistrict));
- VerifyMethodInt(pNdbOperationD, readTuple());
- VerifyMethodInt(pNdbOperationD, equal(c_szDistrictWarehouseNumber, nWarehouse));
- VerifyMethodInt(pNdbOperationD, equal(c_szDistrictNumber, nDistrict));
- VerifyMethodPtr(ppNdbRecAttrDSum[nDistrict], pNdbOperationD, getValue(c_szDistrictSum, 0));
- VerifyMethodPtr(ppNdbRecAttrDCnt[nDistrict], pNdbOperationD, getValue(c_szDistrictCount, 0));
- }
- int iExec = pNdbConnection->execute(Commit);
- int iError = pNdbConnection->getNdbError().code;
-
- if(iExec<0 && iError!=0 && iError!=266 && iError!=626) {
- ReportMethodInt(iExec, pNdbConnection, "pNdbConnection", "execute(Commit)", __FILE__, __LINE__);
- }
- if(iExec==0) {
- Uint32 nSum = 0;
- Uint32 nCnt = 0;
- for(Uint32 nDistrict=0; nDistrict<g_nDistrictPerWarehouse; ++nDistrict) {
- nSum += ppNdbRecAttrDSum[nDistrict]->u_32_value();
- nCnt += ppNdbRecAttrDCnt[nDistrict]->u_32_value();
- }
- if(nSum!=pNdbRecAttrWSum->u_32_value()
- || nCnt!=g_nDistrictPerWarehouse*pNdbRecAttrWCnt->u_32_value()) {
- ndbout << "INCONSISTENT!" << endl;
- ndbout << "iExec==" << iExec << endl;
- ndbout << "iError==" << iError << endl;
- ndbout << endl;
- ndbout << c_szWarehouseSum << "==" << pNdbRecAttrWSum->u_32_value() << ", ";
- ndbout << c_szWarehouseCount << "==" << pNdbRecAttrWCnt->u_32_value() << endl;
- ndbout << "nSum==" << nSum << ", nCnt=" << nCnt << endl;
- for(Uint32 nDistrict=0; nDistrict<g_nDistrictPerWarehouse; ++nDistrict) {
- ndbout << c_szDistrictSum << "[" << nDistrict << "]==" << ppNdbRecAttrDSum[nDistrict]->u_32_value() << ", ";
- ndbout << c_szDistrictCount << "[" << nDistrict << "]==" << ppNdbRecAttrDCnt[nDistrict]->u_32_value() << endl;
- }
- VerifyMethodVoid(pNdb, closeTransaction(pNdbConnection));
- delete pNdb; pNdb = NULL ;
- delete[] ppNdbRecAttrDSum; ppNdbRecAttrDSum = NULL ;
- delete[] ppNdbRecAttrDCnt; ppNdbRecAttrDCnt = NULL ;
- NDBT_ProgramExit(NDBT_FAILED);
- }
- ++nSucc;
- } else {
- ++nFail;
- }
- VerifyMethodVoid(pNdb, closeTransaction(pNdbConnection));
- }
- ndbout << "read: " << nSucc << " succeeded, " << nFail << " failed " << endl;
- NdbMutex_Unlock(g_pNdbMutex);
- delete pNdb; pNdb = NULL ;
- delete[] ppNdbRecAttrDSum; ppNdbRecAttrDSum = NULL ;
- delete[] ppNdbRecAttrDCnt; ppNdbRecAttrDCnt = NULL ;
- return NULL;
-}
-
-
-NDB_COMMAND(acid, "acid", "acid", "acid", 65535)
-{
- ndb_init();
- long nSeconds = 60;
- int rc = NDBT_OK;
-
- for(int i=1; i<argc; ++i) {
- if(argv[i][0]=='-' || argv[i][0]=='/') {
- switch(argv[i][1]) {
- case 'w': g_nWarehouseCount=atol(argv[i]+2); break;
- case 'd': g_nDistrictPerWarehouse=atol(argv[i]+2); break;
- case 's': nSeconds=atol(argv[i]+2); break;
- case 't': g_nThreadCount=atol(argv[i]+2); break;
- default: ndbout << "invalid option" << endl; return 1;
- }
- } else {
- ndbout << "invalid operand" << endl;
- return 1;
- }
- }
- ndbout << argv[0];
- ndbout << " -w" << g_nWarehouseCount;
- ndbout << " -d" << g_nDistrictPerWarehouse;
- ndbout << " -s" << (int)nSeconds;
- ndbout << " -t" << g_nThreadCount;
- ndbout << endl;
-
- Ndb* pNdb = NULL ;
- pNdb = new Ndb("TEST_DB");
- VerifyMethodInt(pNdb, init());
- VerifyMethodInt(pNdb, waitUntilReady());
-
- NdbSchemaCon* pNdbSchemaCon= NdbSchemaCon::startSchemaTrans(pNdb);
- if(!pNdbSchemaCon){
- ndbout <<"startSchemaTransaction failed, exiting now" << endl ;
- delete pNdb ;
- NDBT_ProgramExit(NDBT_FAILED) ;
- }
- NdbSchemaOp* pNdbSchemaOp = NULL ;
- VerifyMethodPtr(pNdbSchemaOp, pNdbSchemaCon, getNdbSchemaOp());
- VerifyMethodInt(pNdbSchemaOp, createTable(
- c_szWarehouse,
- (4+4+4+12)*1.02*g_nWarehouseCount/1024+1,
- TupleKey,
- (4+14)*g_nWarehouseCount/8/1024+1));
-
- VerifyMethodInt(pNdbSchemaOp, createAttribute(c_szWarehouseNumber, TupleKey, 32, 1, UnSigned, MMBased, false));
- VerifyMethodInt(pNdbSchemaOp, createAttribute(c_szWarehouseSum, NoKey, 32, 1, UnSigned, MMBased, false));
- VerifyMethodInt(pNdbSchemaOp, createAttribute(c_szWarehouseCount, NoKey, 32, 1, UnSigned, MMBased, false));
- VerifyMethodInt(pNdbSchemaCon, execute());
- NdbSchemaCon::closeSchemaTrans(pNdbSchemaCon);
-
- pNdbSchemaCon= NdbSchemaCon::startSchemaTrans(pNdb);
- VerifyMethodPtr(pNdbSchemaOp, pNdbSchemaCon, getNdbSchemaOp());
- VerifyMethodInt(pNdbSchemaOp, createTable(
- c_szDistrict,
- (4+4+4+4+12)*1.02*g_nWarehouseCount*g_nDistrictPerWarehouse/1024+1,
- TupleKey,
- (4+4+14)*g_nWarehouseCount*g_nDistrictPerWarehouse/8/1024+1));
-
-
- VerifyMethodInt(pNdbSchemaOp, createAttribute(c_szDistrictWarehouseNumber, TupleKey, 32, 1, UnSigned, MMBased, false));
- VerifyMethodInt(pNdbSchemaOp, createAttribute(c_szDistrictNumber, TupleKey, 32, 1, UnSigned, MMBased, false));
- VerifyMethodInt(pNdbSchemaOp, createAttribute(c_szDistrictSum, NoKey, 32, 1, UnSigned, MMBased, false));
- VerifyMethodInt(pNdbSchemaOp, createAttribute(c_szDistrictCount, NoKey, 32, 1, UnSigned, MMBased, false));
- VerifyMethodInt(pNdbSchemaCon, execute());
- NdbSchemaCon::closeSchemaTrans(pNdbSchemaCon);
- g_pNdbMutex = NdbMutex_Create();
- NdbMutex_Lock(g_pNdbMutex);
-
- NdbThread** ppNdbThread = new NdbThread*[g_nThreadCount*4];
- for(Uint32 nThread=0; nThread<g_nThreadCount; ++nThread) {
- ppNdbThread[nThread*4+0] = NdbThread_Create(NdbThreadFuncInsert, 0, 65535, "insert",
- NDB_THREAD_PRIO_LOW);
- ppNdbThread[nThread*4+1] = NdbThread_Create(NdbThreadFuncUpdate, 0, 65535, "update",
- NDB_THREAD_PRIO_LOW);
- ppNdbThread[nThread*4+2] = NdbThread_Create(NdbThreadFuncDelete, 0, 65535, "delete",
- NDB_THREAD_PRIO_LOW);
- ppNdbThread[nThread*4+3] = NdbThread_Create(NdbThreadFuncRead, 0, 65535, "read",
- NDB_THREAD_PRIO_LOW);
- }
-
- NdbSleep_SecSleep(nSeconds);
- NdbMutex_Unlock(g_pNdbMutex);
-
- void* pStatus;
- for(Uint32 nThread=0; nThread<g_nThreadCount; ++nThread) {
- NdbThread_WaitFor(ppNdbThread[nThread*4+0], &pStatus);
- NdbThread_WaitFor(ppNdbThread[nThread*4+1], &pStatus);
- NdbThread_WaitFor(ppNdbThread[nThread*4+2], &pStatus);
- NdbThread_WaitFor(ppNdbThread[nThread*4+3], &pStatus);
- }
-
- NdbMutex_Destroy(g_pNdbMutex);
- delete[] ppNdbThread;
- delete pNdb;
- return NDBT_ProgramExit(rc);
-}
-
diff --git a/storage/ndb/test/ndbapi/acid2.cpp b/storage/ndb/test/ndbapi/acid2.cpp
deleted file mode 100644
index d5fe8778aab..00000000000
--- a/storage/ndb/test/ndbapi/acid2.cpp
+++ /dev/null
@@ -1,693 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-#include <NdbApi.hpp>
-#include <NdbOut.hpp>
-#include <NdbThread.h>
-#include <NdbSleep.h>
-#include <NdbMutex.h>
-
-#include "TraceNdbApi.hpp"
-#include "VerifyNdbApi.hpp"
-
-
-#define Ndb CTraceNdb
-#define NdbSchemaCon CTraceNdbSchemaCon
-#define NdbSchemaOp CTraceNdbSchemaOp
-#define NdbConnection CTraceNdbConnection
-#define NdbOperation CTraceNdbOperation
-#define NdbIndexOperation CTraceNdbIndexOperation
-#define NdbRecAttr CTraceNdbRecAttr
-#define Table CTraceTable
-#define Index CTraceIndex
-#define Column CTraceColumn
-#define NdbDictionary CTraceNdbDictionary
-
-/*
-#define Ndb CVerifyNdb
-#define NdbSchemaCon CVerifyNdbSchemaCon
-#define NdbSchemaOp CVerifyNdbSchemaOp
-#define NdbConnection CVerifyNdbConnection
-#define NdbOperation CVerifyNdbOperation
-#define NdbIndexOperation CVerifyNdbIndexOperation
-#define NdbRecAttr CVerifyNdbRecAttr
-#define Table CVerifyTable
-#define Index CVerifyIndex
-#define Column CVerifyColumn
-#define NdbDictionary CVerifyNdbDictionary
-*/
-
-NdbMutex* g_pNdbMutexStop = 0;
-Uint32 g_nPart = 1;
-Uint32 g_nTable = 1;
-Uint32 g_nTuple = 1;
-Uint32 g_nAttribute = 1;
-char* g_szTable = 0;
-char* g_szIndex = 0;
-char* g_szAttribute = 0;
-bool g_bVerify = false;
-bool g_bUseIndex = false;
-
-
-
-#define N 624
-#define M 397
-#define MATRIX_A 0x9908b0df
-#define UPPER_MASK 0x80000000
-#define LOWER_MASK 0x7fffffff
-
-#define TEMPERING_MASK_B 0x9d2c5680
-#define TEMPERING_MASK_C 0xefc60000
-#define TEMPERING_SHIFT_U(y) (y >> 11)
-#define TEMPERING_SHIFT_S(y) (y << 7)
-#define TEMPERING_SHIFT_T(y) (y << 15)
-#define TEMPERING_SHIFT_L(y) (y >> 18)
-
-
-class MT19937
-{
-public:
- MT19937(void);
- void sgenrand(unsigned long seed);
- unsigned long genrand(void);
-
-private:
- unsigned long mt[N];
- int mti;
- unsigned long mag01[2];
-};
-
-
-MT19937::MT19937(void)
-{
- mti = N+1;
- mag01[0] = 0x0;
- mag01[1] = MATRIX_A;
- sgenrand(4357);
-}
-
-
-void MT19937::sgenrand(unsigned long seed)
-{
- mt[0]= seed & 0xffffffff;
- for (mti=1; mti<N; mti++)
- mt[mti] = (69069 * mt[mti-1]) & 0xffffffff;
-}
-
-
-unsigned long MT19937::genrand(void)
-{
- unsigned long y;
- if (mti >= N) {
- int kk;
- if (mti == N+1)
- {
- sgenrand(4357);
- }
- for (kk=0;kk<N-M;kk++) {
- y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
- mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1];
- }
- for (;kk<N-1;kk++) {
- y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
- mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1];
- }
- y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
- mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1];
- mti = 0;
- }
- y = mt[mti++];
- y ^= TEMPERING_SHIFT_U(y);
- y ^= TEMPERING_SHIFT_S(y) & TEMPERING_MASK_B;
- y ^= TEMPERING_SHIFT_T(y) & TEMPERING_MASK_C;
- y ^= TEMPERING_SHIFT_L(y);
- return y;
-}
-
-
-
-
-
-void CreateTables(Ndb* pNdb)
-{
- for(Uint32 iTable=0; iTable<g_nTable; ++iTable)
- {
- NdbDictionary::Dictionary* pDictionary = pNdb->getDictionary();
-
- NdbDictionary::Table table;
- table.setName(g_szTable+iTable*4);
-
- NdbDictionary::Index index;
- index.setName(g_szIndex+iTable*4);
- index.setTable(table.getName());
- index.setType(NdbDictionary::Index::UniqueHashIndex);
-
- NdbDictionary::Column columnPK;
- columnPK.setName("PK");
- columnPK.setTupleKey(true);
- table.addColumn(columnPK);
- index.addIndexColumn(columnPK.getName());
-
- for(Uint32 iAttr=0; iAttr<g_nAttribute; ++iAttr)
- {
- NdbDictionary::Column columnAttr;
- columnAttr.setName(g_szAttribute+iAttr*4);
- columnAttr.setTupleKey(false);
- table.addColumn(columnAttr);
- }
-
- pDictionary->createTable(table);
- pDictionary->createIndex(index);
-
- /*
- NdbSchemaCon* pNdbSchemaCon = pNdb->startSchemaTransaction();
- NdbSchemaOp* pNdbSchemaOp = pNdbSchemaCon->getNdbSchemaOp();
- pNdbSchemaOp->createTable(g_szTable+iTable*4);
- pNdbSchemaOp->createAttribute("PK", TupleKey);
- for(Uint32 iAttr=0; iAttr<g_nAttribute; ++iAttr)
- {
- pNdbSchemaOp->createAttribute(g_szAttribute+iAttr*4, NoKey);
- }
-
- pNdbSchemaCon->execute();
- pNdb->closeSchemaTransaction(pNdbSchemaCon);
- */
- }
-}
-
-
-int InsertTransaction(Ndb* pNdb, const Uint32 iPart, const bool bIndex)
-{
- int iExec = -1;
- int iCode = -1;
- NdbConnection* pNdbConnection = pNdb->startTransaction();
- if(pNdbConnection)
- {
- for(Uint32 iTable=0; iTable<g_nTable; ++iTable)
- {
- for(Uint32 iTuple=0; iTuple<g_nTuple; ++iTuple)
- {
- if(bIndex)
- {
- NdbIndexOperation* pNdbIndexOperation = pNdbConnection->getNdbIndexOperation(g_szIndex+iTable*4, g_szTable+iTable*4);
- pNdbIndexOperation->insertTuple();
- Uint32 nPK = iPart*g_nTuple + iTuple;
- pNdbIndexOperation->equal("PK", nPK);
- for(Uint32 iAttr=0; iAttr<g_nAttribute; ++iAttr)
- {
- Uint32 nValue = ((iPart*g_nTable+iTable)*g_nTuple+iTuple)*g_nAttribute+iAttr;
- pNdbIndexOperation->setValue(g_szAttribute+iAttr*4, nValue);
- }
- }
- else
- {
- NdbOperation* pNdbOperation = pNdbConnection->getNdbOperation(g_szTable+iTable*4);
- pNdbOperation->insertTuple();
- Uint32 nPK = iPart*g_nTuple + iTuple;
- pNdbOperation->equal("PK", nPK);
- for(Uint32 iAttr=0; iAttr<g_nAttribute; ++iAttr)
- {
- Uint32 nValue = ((iPart*g_nTable+iTable)*g_nTuple+iTuple)*g_nAttribute+iAttr;
- pNdbOperation->setValue(g_szAttribute+iAttr*4, nValue);
- }
- }
- }
- }
- iExec = pNdbConnection->execute_ok(Commit);
- if (iExec == -1)
- {
- ndbout << pNdbConnection->getNdbError() << endl;
- }
- pNdb->closeTransaction(pNdbConnection);
- }
- return 0;
-}
-
-
-int UpdateGetAndSetTransaction(Ndb* pNdb, const Uint32 iPart, const bool bIndex)
-{
- int iExec = -1;
- int iCode = -1;
- NdbRecAttr** ppNdbRecAttr = new NdbRecAttr*[g_nTable*g_nTuple*g_nAttribute];
- NdbConnection* pNdbConnection = pNdb->startTransaction();
- if(pNdbConnection)
- {
- for(Uint32 iTable=0; iTable<g_nTable; ++iTable)
- {
- for(Uint32 iTuple=0; iTuple<g_nTuple; ++iTuple)
- {
- if(bIndex)
- {
- NdbIndexOperation* pNdbIndexOperation = pNdbConnection->getNdbIndexOperation(g_szIndex+iTable*4, g_szTable+iTable*4);
- pNdbIndexOperation->readTupleExclusive();
- Uint32 nPK = iPart*g_nTuple + iTuple;
- pNdbIndexOperation->equal("PK", nPK);
- for(Uint32 iAttr=0; iAttr<g_nAttribute; ++iAttr)
- {
- ppNdbRecAttr[(iTable*g_nTuple+iTuple)*g_nAttribute+iAttr]
- = pNdbIndexOperation->getValue(g_szAttribute+iAttr*4);
- }
- }
- else
- {
- NdbOperation* pNdbOperation = pNdbConnection->getNdbOperation(g_szTable+iTable*4);
- pNdbOperation->readTupleExclusive();
- Uint32 nPK = iPart*g_nTuple + iTuple;
- pNdbOperation->equal("PK", nPK);
- for(Uint32 iAttr=0; iAttr<g_nAttribute; ++iAttr)
- {
- ppNdbRecAttr[(iTable*g_nTuple+iTuple)*g_nAttribute+iAttr]
- = pNdbOperation->getValue(g_szAttribute+iAttr*4);
- }
- }
- }
- }
- iExec = pNdbConnection->execute_ok(NoCommit);
- if( iExec == -1)
- {
- ndbout << pNdbConnection->getNdbError() << endl;
- }
- }
- iCode = pNdbConnection->getNdbError().code;
- if(iExec==0)
- {
- for(Uint32 iTable=0; iTable<g_nTable; ++iTable)
- {
- for(Uint32 iTuple=0; iTuple<g_nTuple; ++iTuple)
- {
- if(bIndex)
- {
- NdbIndexOperation* pNdbIndexOperation = pNdbConnection->getNdbIndexOperation(g_szIndex+iTable*4, g_szTable+iTable*4);
- pNdbIndexOperation->updateTuple();
- Uint32 nPK = iPart*g_nTuple + iTuple;
- pNdbIndexOperation->equal("PK", nPK);
- for(Uint32 iAttr=0; iAttr<g_nAttribute; ++iAttr)
- {
- NdbRecAttr* pNdbRecAttr
- = ppNdbRecAttr[(iTable*g_nTuple+iTuple)*g_nAttribute+iAttr];
- Uint32 nValue = pNdbRecAttr->u_32_value() + 1;
- pNdbIndexOperation->setValue(g_szAttribute+iAttr*4, nValue);
- }
- }
- else
- {
- NdbOperation* pNdbOperation = pNdbConnection->getNdbOperation(g_szTable+iTable*4);
- pNdbOperation->updateTuple();
- Uint32 nPK = iPart*g_nTuple + iTuple;
- pNdbOperation->equal("PK", nPK);
- for(Uint32 iAttr=0; iAttr<g_nAttribute; ++iAttr)
- {
- NdbRecAttr* pNdbRecAttr
- = ppNdbRecAttr[(iTable*g_nTuple+iTuple)*g_nAttribute+iAttr];
- Uint32 nValue = pNdbRecAttr->u_32_value() + 1;
- pNdbOperation->setValue(g_szAttribute+iAttr*4, nValue);
- }
- }
- }
- }
- iExec = pNdbConnection->execute(Commit);
- if (iExec == -1)
- {
- ndbout << pNdbConnection->getNdbError() << endl;
- }
- pNdb->closeTransaction(pNdbConnection);
- }
- delete[] ppNdbRecAttr;
- return 0;
-}
-
-
-int UpdateInterpretedTransaction(Ndb* pNdb, const Uint32 iPart, const bool bIndex)
-{
- int iExec = -1;
- int iCode = -1;
- NdbConnection* pNdbConnection = pNdb->startTransaction();
- if(pNdbConnection)
- {
- for(Uint32 iTable=0; iTable<g_nTable; ++iTable)
- {
- for(Uint32 iTuple=0; iTuple<g_nTuple; ++iTuple)
- {
- if(bIndex)
- {
- NdbIndexOperation* pNdbIndexOperation = pNdbConnection->getNdbIndexOperation(g_szIndex+iTable*4, g_szTable+iTable*4);
- pNdbIndexOperation->interpretedUpdateTuple();
- Uint32 nPK = iPart*g_nTuple + iTuple;
- pNdbIndexOperation->equal("PK", nPK);
- for(Uint32 iAttr=0; iAttr<g_nAttribute; ++iAttr)
- {
- pNdbIndexOperation->incValue(g_szAttribute+iAttr*4, (Uint32)1);
- }
- }
- else
- {
- NdbOperation* pNdbOperation = pNdbConnection->getNdbOperation(g_szTable+iTable*4);
- pNdbOperation->interpretedUpdateTuple();
- Uint32 nPK = iPart*g_nTuple + iTuple;
- pNdbOperation->equal("PK", nPK);
- for(Uint32 iAttr=0; iAttr<g_nAttribute; ++iAttr)
- {
- pNdbOperation->incValue(g_szAttribute+iAttr*4, (Uint32)1);
- }
- }
- }
- }
- iExec = pNdbConnection->execute_ok(Commit);
-
- if (iExec == -1)
- {
- ndbout << pNdbConnection->getNdbError() << endl;
- }
- pNdb->closeTransaction(pNdbConnection);
- }
- return 0;
-}
-
-
-void ReportInconsistency (const Uint32 iPart,
- const Uint32 iTable,
- const Uint32 iTuple,
- const Uint32 iAttr,
- const Uint32 nValue,
- const Uint32 nExpected )
-{
- ndbout << "INCONSISTENCY: ";
- ndbout << "Part " << iPart;
- ndbout << ", Table " << iTable;
- ndbout << ", Tuple " << iTuple;
- ndbout << ", Attr " << iAttr;
- ndbout << ", Value " << nValue;
- ndbout << ", Expected " << nExpected;
- ndbout << endl;
-}
-
-
-int ReadTransaction(Ndb* pNdb, const Uint32 iPart, const bool bIndex)
-{
- int iExec = -1;
- int iCode = -1;
- NdbRecAttr** ppNdbRecAttr = new NdbRecAttr*[g_nTable*g_nTuple*g_nAttribute];
- NdbConnection* pNdbConnection = pNdb->startTransaction();
- if(pNdbConnection)
- {
- for(Uint32 iTable=0; iTable<g_nTable; ++iTable)
- {
- for(Uint32 iTuple=0; iTuple<g_nTuple; ++iTuple)
- {
- if(bIndex)
- {
- NdbIndexOperation* pNdbIndexOperation = pNdbConnection->getNdbIndexOperation(g_szIndex+iTable*4, g_szTable+iTable*4);
- pNdbIndexOperation->readTuple();
- Uint32 nPK = iPart*g_nTuple + iTuple;
- pNdbIndexOperation->equal("PK", nPK);
- for(Uint32 iAttr=0; iAttr<g_nAttribute; ++iAttr)
- {
- ppNdbRecAttr[(iTable*g_nTuple+iTuple)*g_nAttribute+iAttr]
- = pNdbIndexOperation->getValue(g_szAttribute+iAttr*4);
- }
- }
- else
- {
- NdbOperation* pNdbOperation = pNdbConnection->getNdbOperation(g_szTable+iTable*4);
- pNdbOperation->readTuple();
- Uint32 nPK = iPart*g_nTuple + iTuple;
- pNdbOperation->equal("PK", nPK);
- for(Uint32 iAttr=0; iAttr<g_nAttribute; ++iAttr)
- {
- ppNdbRecAttr[(iTable*g_nTuple+iTuple)*g_nAttribute+iAttr]
- = pNdbOperation->getValue(g_szAttribute+iAttr*4);
- }
- }
- }
- }
- iExec = pNdbConnection->execute_ok(Commit);
- if (iExec == -1)
- {
- ndbout << pNdbConnection->getNdbError() << endl;
- }
- if(iExec==0)
- {
- Uint32 nValue0 = ppNdbRecAttr[0]->u_32_value();
- for(Uint32 iTable=0; iTable<g_nTable; ++iTable)
- {
- for(Uint32 iTuple=0; iTuple<g_nTuple; ++iTuple)
- {
- for(Uint32 iAttr=0; iAttr<g_nAttribute; ++iAttr)
- {
- Uint32 nValue = ppNdbRecAttr[(iTable*g_nTuple+iTuple)*g_nAttribute+iAttr]->u_32_value();
- Uint32 nExpected = nValue0 + (iTable*g_nTuple+iTuple)*g_nAttribute+iAttr;
- if(nValue!=nExpected)
- {
- ReportInconsistency(iPart, iTable, iTuple, iAttr, nValue, nExpected);
- }
- }
- }
- }
- }
- pNdb->closeTransaction(pNdbConnection);
- }
- return 0;
-}
-
-
-int DeleteTransaction(Ndb* pNdb, const Uint32 iPart, const bool bIndex)
-{
- int iExec = -1;
- int iCode = -1;
- NdbConnection* pNdbConnection = pNdb->startTransaction();
- if(pNdbConnection)
- {
- for(Uint32 iTable=0; iTable<g_nTable; ++iTable)
- {
- for(Uint32 iTuple=0; iTuple<g_nTuple; ++iTuple)
- {
- if(bIndex)
- {
- NdbIndexOperation* pNdbIndexOperation = pNdbConnection->getNdbIndexOperation(g_szIndex+iTable*4, g_szTable+iTable*4);
- pNdbIndexOperation->deleteTuple();
- Uint32 nPK = iPart*g_nTuple + iTuple;
- pNdbIndexOperation->equal("PK", nPK);
- }
- else
- {
- NdbOperation* pNdbOperation = pNdbConnection->getNdbOperation(g_szTable+iTable*4);
- pNdbOperation->deleteTuple();
- Uint32 nPK = iPart*g_nTuple + iTuple;
- pNdbOperation->equal("PK", nPK);
- }
- }
- }
- iExec = pNdbConnection->execute_ok(Commit);
-
- if (iExec == -1)
- {
- ndbout << pNdbConnection->getNdbError() << endl;
- }
- pNdb->closeTransaction(pNdbConnection);
- }
- return 0;
-}
-
-
-extern "C" void* ThreadFunc(void*)
-{
- Ndb* pNdb = new Ndb("TEST_DB");
- pNdb->init();
- pNdb->waitUntilReady();
-
- MT19937 rndgen;
- rndgen.sgenrand((unsigned long)pNdb);
-
- Uint32 nInsertError = 0;
- Uint32 nInsertCommit = 0;
- Uint32 nInsertRollback = 0;
- Uint32 nUpdateGetAndSetError = 0;
- Uint32 nUpdateGetAndSetCommit = 0;
- Uint32 nUpdateGetAndSetRollback = 0;
- Uint32 nReadError = 0;
- Uint32 nReadCommit = 0;
- Uint32 nReadRollback = 0;
- Uint32 nUpdateInterpretedError = 0;
- Uint32 nUpdateInterpretedCommit = 0;
- Uint32 nUpdateInterpretedRollback = 0;
- Uint32 nDeleteError = 0;
- Uint32 nDeleteCommit = 0;
- Uint32 nDeleteRollback = 0;
-
- if (g_bVerify)
- {
- for (Uint32 iPart = 0; iPart < g_nPart; iPart++)
- {
- switch(ReadTransaction(pNdb, iPart, false))
- {
- case -1: ++nReadError; break;
- case 0: ++nReadCommit; break;
- case 1: ++nReadRollback; break;
- }
- }
- }
- else
- while(NdbMutex_Trylock(g_pNdbMutexStop))
- {
- Uint32 iPart = rndgen.genrand() % g_nPart;
- Uint32 iTrans = rndgen.genrand() % 5;
- bool bIndex = ((rndgen.genrand() & 1) ? true : false);
- switch(iTrans)
- {
- case 0:
- switch(InsertTransaction(pNdb, iPart, bIndex))
- {
- case -1: ++nInsertError; break;
- case 0: ++nInsertCommit; break;
- case 1: ++nInsertRollback; break;
- }
- break;
-
- case 1:
- switch(UpdateGetAndSetTransaction(pNdb, iPart, bIndex))
- {
- case -1: ++nUpdateGetAndSetError; break;
- case 0: ++nUpdateGetAndSetCommit; break;
- case 1: ++nUpdateGetAndSetRollback; break;
- }
- break;
-
- case 2:
- switch(ReadTransaction(pNdb, iPart, bIndex))
- {
- case -1: ++nReadError; break;
- case 0: ++nReadCommit; break;
- case 1: ++nReadRollback; break;
- }
- break;
-
- case 3:
- switch(UpdateInterpretedTransaction(pNdb, iPart, bIndex))
- {
- case -1: ++nUpdateInterpretedError; break;
- case 0: ++nUpdateInterpretedCommit; break;
- case 1: ++nUpdateInterpretedRollback; break;
- }
- break;
-
- case 4:
- switch(DeleteTransaction(pNdb, iPart, bIndex))
- {
- case -1: ++nDeleteError; break;
- case 0: ++nDeleteCommit; break;
- case 1: ++nDeleteRollback; break;
- }
- break;
- }
- }
-
- ndbout << "I:" << nInsertError << ":" << nInsertCommit << ":" << nInsertRollback;
- ndbout << " UG:" << nUpdateGetAndSetError << ":" << nUpdateGetAndSetCommit << ":" << nUpdateGetAndSetRollback;
- ndbout << " R:" << nReadError << ":" << nReadCommit << ":" << nReadRollback;
- ndbout << " UI:" << nUpdateInterpretedError << ":" << nUpdateInterpretedCommit << ":" << nUpdateInterpretedRollback;
- ndbout << " D:" << nDeleteError << ":" << nDeleteCommit << ":" << nDeleteRollback << endl;
- ndbout << endl;
-
- NdbMutex_Unlock(g_pNdbMutexStop);
- delete pNdb;
- return 0;
-}
-
-
-int main(int argc, char* argv[])
-{
- ndb_init();
- Uint32 nSeconds = 1;
- Uint32 nThread = 1;
-
- for(int iArg=1; iArg<argc; ++iArg)
- {
- if(argv[iArg][0]=='-')
- {
- switch(argv[iArg][1])
- {
- case 'p': g_nPart = atol(argv[iArg]+2); break;
- case 'b': g_nTable = atol(argv[iArg]+2); break;
- case 'u': g_nTuple = atol(argv[iArg]+2); break;
- case 'a': g_nAttribute = atol(argv[iArg]+2); break;
- case 'v': g_bVerify = true; break;
- case 't': nThread = atol(argv[iArg]+2); break;
- case 's': nSeconds = atol(argv[iArg]+2); break;
- case 'i': g_bUseIndex = true; break;
- }
- }
- }
- ndbout << argv[0];
- ndbout << " -p" << g_nPart;
- ndbout << " -b" << g_nTable;
- ndbout << " -u" << g_nTuple;
- ndbout << " -a" << g_nAttribute;
- if (g_bVerify)
- ndbout << " -v";
- ndbout << " -t" << nThread;
- ndbout << " -s" << nSeconds;
- ndbout << endl;
-
- g_szTable = new char[g_nTable*4];
- for(Uint32 iTable=0; iTable<g_nTable; ++iTable)
- {
- sprintf(g_szTable+iTable*4, "T%02d", iTable);
- }
-
- g_szIndex = new char[g_nTable*4];
- for(Uint32 iIndex=0; iIndex<g_nTable; ++iIndex)
- {
- sprintf(g_szIndex+iIndex*4, "I%02d", iIndex);
- }
-
- g_szAttribute = new char[g_nAttribute*4];
- for(Uint32 iAttr=0; iAttr<g_nAttribute; ++iAttr)
- {
- sprintf(g_szAttribute+iAttr*4, "A%02d", iAttr);
- }
-
-
- Ndb* pNdb = new Ndb("TEST_DB");
- pNdb->init();
- pNdb->waitUntilReady();
-
- if (!g_bVerify) CreateTables(pNdb);
- g_pNdbMutexStop = NdbMutex_Create();
- NdbMutex_Lock(g_pNdbMutexStop);
-
- NdbThread_SetConcurrencyLevel(nThread+1);
- NdbThread** ppNdbThread = new NdbThread*[nThread];
- for(Uint32 iThread=0; iThread<nThread; ++iThread)
- {
- ppNdbThread[iThread] = NdbThread_Create(ThreadFunc, 0, 0, "ThreadFunc", NDB_THREAD_PRIO_MEAN);
- }
-
- NdbSleep_SecSleep(nSeconds);
- NdbMutex_Unlock(g_pNdbMutexStop);
-
- for(Uint32 iThread=0; iThread<nThread; ++iThread)
- {
- void* status;
- NdbThread_WaitFor(ppNdbThread[iThread], &status);
- }
-
- NdbMutex_Destroy(g_pNdbMutexStop);
- g_pNdbMutexStop = 0;
- delete pNdb;
-}
-
-
diff --git a/storage/ndb/test/ndbapi/acrt/NdbRepStress.cpp b/storage/ndb/test/ndbapi/acrt/NdbRepStress.cpp
deleted file mode 100644
index 5b9e0ffdb71..00000000000
--- a/storage/ndb/test/ndbapi/acrt/NdbRepStress.cpp
+++ /dev/null
@@ -1,457 +0,0 @@
-/* Copyright (c) 2003, 2008 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT_Test.hpp>
-#include <NDBT_ReturnCodes.h>
-#include <HugoTransactions.hpp>
-#include <UtilTransactions.hpp>
-#include <DbUtil.hpp>
-#include <mysql.h>
-
-/*
-Will include restart testing in future phases
-#include <NdbRestarter.hpp>
-#include <NdbRestarts.hpp>
-*/
-
-/**** TOOL SECTION ****/
-
-static uint
-urandom()
-{
- uint r = (uint)random();
- return r;
-}
-
-static uint
-urandom(uint m)
-{
- if (m == 0)
- return NDBT_OK;
- uint r = urandom();
- r = r % m;
- return r;
-}
-
-#define GETNDB(ps) ((NDBT_NdbApiStep*)ps)->getNdb()
-/*
-*/
-
-int
-syncSlaveWithMaster()
-{
- /*
- We need to look at the MAX epoch of the
- mysql.ndb_binlog_index table so we will
- know when the slave has caught up
- */
-
- SqlResultSet result;
- unsigned int masterEpoch = 0;
- unsigned int slaveEpoch = 0;
- unsigned int slaveEpochOld = 0;
- int maxLoops = 100;
- int loopCnt = 0;
-
- //Create a DbUtil object for the master
- DbUtil master("mysql","");
-
- //Login to Master
- if (!master.connect())
- {
- return NDBT_FAILED;
- }
-
- //Get max epoch from master
- if(master.doQuery("SELECT MAX(epoch) FROM mysql.ndb_binlog_index", result))
- {
- return NDBT_FAILED;
- }
- masterEpoch = result.columnAsInt("epoch");
-
- /*
- Now we will pull current epoch from slave. If not the
- same as master, we will continue to retrieve the epoch
- and compare until it matches or we reach the max loops
- allowed.
- */
-
- //Create a dbutil object for the slave
- DbUtil slave("mysql",".slave");
-
- //Login to slave
- if (!slave.connect())
- {
- return NDBT_FAILED;
- }
-
- while(slaveEpoch != masterEpoch && loopCnt < maxLoops)
- {
- if(slave.doQuery("SELECT epoch FROM mysql.ndb_apply_status",result))
- {
- return NDBT_FAILED;
- }
- slaveEpoch = result.columnAsInt("epoch");
-
- if(slaveEpoch != slaveEpochOld)
- {
- slaveEpochOld = slaveEpoch;
- if(loopCnt > 0)
- loopCnt--;
- sleep(3);
- }
- else
- {
- sleep(1);
- loopCnt++;
- }
- }
-
- if(slaveEpoch != masterEpoch)
- {
- g_err << "Slave not in sync with master!" << endl;
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int
-verifySlaveLoad(BaseString &table)
-{
- //BaseString sqlStm;
- BaseString db;
- unsigned int masterCount = 0;
- unsigned int slaveCount = 0;
-
- db.assign("TEST_DB");
- //sqlStm.assfmt("SELECT COUNT(*) FROM %s", table);
-
- //First thing to do is sync slave
- if(syncSlaveWithMaster())
- {
- g_err << "Verify Load -> Syncing with slave failed" << endl;
- return NDBT_FAILED;
- }
-
- //Now that slave is sync we can verify load
- DbUtil master(db.c_str()," ");
-
- //Login to Master
- if (!master.connect())
- {
- return NDBT_FAILED;
- }
-
- if((masterCount = master.selectCountTable(table.c_str())) == 0 )
- {
- return NDBT_FAILED;
- }
-
- //Create a DB Object for slave
- DbUtil slave(db.c_str(),".slave");
-
- //Login to slave
- if (!slave.connect())
- {
- return NDBT_FAILED;
- }
-
- if((slaveCount = slave.selectCountTable(table.c_str())) == 0 )
- {
- return NDBT_FAILED;
- }
-
- if(slaveCount != masterCount)
- {
- g_err << "Verify Load -> Slave Count != Master Count "
- << endl;
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int
-createTEST_DB(NDBT_Context* ctx, NDBT_Step* step)
-{
- BaseString cdb;
- cdb.assign("TEST_DB");
-
- //Create a dbutil object
- DbUtil master("mysql","");
-
- if (master.connect())
- {
- if (master.createDb(cdb) == NDBT_OK)
- {
- return NDBT_OK;
- }
- }
- return NDBT_FAILED;
-}
-
-int
-dropTEST_DB(NDBT_Context* ctx, NDBT_Step* step)
-{
- //Create an SQL Object
- DbUtil master("mysql","");
-
- //Login to Master
- if (!master.connect())
- {
- return NDBT_FAILED;
- }
-
- if(master.doQuery("DROP DATABASE TEST_DB") != NDBT_OK)
- {
- return NDBT_FAILED;
- }
-
- if(syncSlaveWithMaster() != NDBT_OK)
- {
- g_err << "Drop DB -> Syncing with slave failed"
- << endl;
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int
-verifySlave(BaseString& sqlStm, BaseString& db, BaseString& column)
-{
- SqlResultSet result;
- float masterSum;
- float slaveSum;
-
- //Create SQL Objects
- DbUtil master(db.c_str(),"");
- DbUtil slave(db.c_str(),".slave");
-
- if(syncSlaveWithMaster() != NDBT_OK)
- {
- g_err << "Verify Slave rep1 -> Syncing with slave failed"
- << endl;
- return NDBT_FAILED;
- }
-
- //Login to Master
- if (!master.connect())
- {
- return NDBT_FAILED;
- }
-
- if(master.doQuery(sqlStm.c_str(),result) != NDBT_OK)
- {
- return NDBT_FAILED;
- }
- masterSum = result.columnAsInt(column.c_str());
-
- //Login to slave
- if (!slave.connect())
- {
- return NDBT_FAILED;
- }
-
- if(slave.doQuery(sqlStm.c_str(),result) != NDBT_OK)
- {
- return NDBT_FAILED;
- }
- slaveSum = result.columnAsInt(column.c_str());
-
- if(masterSum != slaveSum)
- {
- g_err << "VerifySlave -> masterSum != slaveSum..." << endl;
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-
-/**** Test Section ****/
-
-int
-createDB(NDBT_Context* ctx, NDBT_Step* step)
-{
- BaseString cdb;
- cdb.assign("TEST_DB");
-
- //Create a dbutil object
- DbUtil master("mysql","");
-
- if (master.connect())
- {
- if (master.createDb(cdb) == NDBT_OK)
- {
- return NDBT_OK;
- }
- }
- return NDBT_FAILED;
-}
-
-int
-createTable_rep1(NDBT_Context* ctx, NDBT_Step* step)
-{
- BaseString table;
- BaseString db;
-
- table.assign("rep1");
- db.assign("TEST_DB");
-
- //Ensure slave is up and ready
- if(syncSlaveWithMaster() != NDBT_OK)
- {
- g_err << "Create Table -> Syncing with slave failed"
- << endl;
- return NDBT_FAILED;
- }
-
- //Create an SQL Object
- DbUtil master(db.c_str(),"");
-
- //Login to Master
- if (!master.connect())
- {
- return NDBT_FAILED;
- }
-
- if (master.doQuery("CREATE TABLE rep1 (c1 MEDIUMINT NOT NULL AUTO_INCREMENT,"
- " c2 FLOAT, c3 CHAR(5), c4 bit(8), c5 FLOAT, c6 INT,"
- " c7 INT, PRIMARY KEY (c1))ENGINE=NDB"))
- {
- return NDBT_FAILED;
- }
- ctx->setProperty("TABLES",table.c_str());
- HugoTransactions hugoTrans(*ctx->getTab());
-
- if (hugoTrans.loadTable(GETNDB(step), ctx->getNumRecords(), 1, true, 0) != NDBT_OK)
- {
- g_err << "Create Table -> Load failed!" << endl;
- return NDBT_FAILED;
- }
-
- if(verifySlaveLoad(table)!= NDBT_OK)
- {
- g_err << "Create Table -> Failed on verify slave load!"
- << endl;
- return NDBT_FAILED;
- }
- //else everything is okay
- return NDBT_OK;
-}
-
-int
-stressNDB_rep1(NDBT_Context* ctx, NDBT_Step* step)
-{
- const NdbDictionary::Table * table= ctx->getTab();
- HugoTransactions hugoTrans(* table);
- while(!ctx->isTestStopped())
- {
- if (hugoTrans.pkUpdateRecords(GETNDB(step), ctx->getNumRecords(), 1, 30) != 0)
- {
- g_err << "pkUpdate Failed!" << endl;
- return NDBT_FAILED;
- }
- if (hugoTrans.scanUpdateRecords(GETNDB(step), ctx->getNumRecords(), 1, 30) != 0)
- {
- g_err << "scanUpdate Failed!" << endl;
- return NDBT_FAILED;
- }
- }
- return NDBT_OK;
-}
-
-int
-stressSQL_rep1(NDBT_Context* ctx, NDBT_Step* step)
-{
- BaseString sqlStm;
-
- DbUtil master("TEST_DB","");
- int loops = ctx->getNumLoops();
- uint record = 0;
-
- //Login to Master
- if (!master.connect())
- {
- ctx->stopTest();
- return NDBT_FAILED;
- }
-
- for (int j= 0; loops == 0 || j < loops; j++)
- {
- record = urandom(ctx->getNumRecords());
- sqlStm.assfmt("UPDATE TEST_DB.rep1 SET c2 = 33.3221 where c1 = %u", record);
- if(master.doQuery(sqlStm.c_str()))
- {
- return NDBT_FAILED;
- }
- }
- ctx->stopTest();
- return NDBT_OK;
-}
-
-int
-verifySlave_rep1(NDBT_Context* ctx, NDBT_Step* step)
-{
- BaseString sql;
- BaseString db;
- BaseString column;
-
- sql.assign("SELECT SUM(c3) FROM rep1");
- db.assign("TEST_DB");
- column.assign("c3");
-
- if (verifySlave(sql,db,column) != NDBT_OK)
- return NDBT_FAILED;
- return NDBT_OK;
-}
-
-/* TOOLS LIST
-
- syncSlaveWithMaster()
- {ensures slave is at same epoch as master}
-
- verifySlaveLoad(BaseString *table)
- {ensures slave table has same record count as master}
-
- createTEST_DB()
- {Creates TEST_DB database on master}
-
- dropTEST_DB()
- {Drops TEST_DB database on master}
-
- verifySlave(BaseString& sql, BaseSting& db, BaseSting& column)
- {The SQL statement must sum a column and will verify
- that the sum of the column is equal on master & slave}
-*/
-
-
-NDBT_TESTSUITE(NdbRepStress);
-TESTCASE("PHASE_I_Stress","Basic Replication Stressing")
-{
- INITIALIZER(createDB);
- INITIALIZER(createTable_rep1);
- STEP(stressNDB_rep1);
- STEP(stressSQL_rep1);
- FINALIZER(verifySlave_rep1);
- FINALIZER(dropTEST_DB);
-}
-NDBT_TESTSUITE_END(NdbRepStress);
-
-int main(int argc, const char** argv){
- ndb_init();
- NdbRepStress.setCreateAllTables(true);
- return NdbRepStress.execute(argc, argv);
-}
-
diff --git a/storage/ndb/test/ndbapi/adoInsertRecs.cpp b/storage/ndb/test/ndbapi/adoInsertRecs.cpp
deleted file mode 100644
index 4e9ec5aa444..00000000000
--- a/storage/ndb/test/ndbapi/adoInsertRecs.cpp
+++ /dev/null
@@ -1,363 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-// InsertRecs.cpp : Defines the entry point for the console application.
-//
-
-
-#include "stdafx.h"
-#import "C:\Program Files\Common Files\System\ADO\msado15.dll" \
- no_namespace rename("EOF", "EndOfFile")
-
-
-// data for CALL_CONTEXT and GROUP_RESOURCE
-static TCHAR STATUS_DATA[]=_T("000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F")
- _T("101112131415161718191A1B1C1D1E1F000102030405060708090A0B0C0D0E0F")
- _T("202122232425262728292A2B2C2D2E2F000102030405060708090A0B0C0D0E0F")
- _T("303132333435363738393A3B3C3D3E3F000102030405060708090A0B0C0D0E0F")
- _T("404142434445464748494A4B4C4D4E4F000102030405060708090A0B0C0D0E0F")
- _T("505152535455565758595A5B5C5D5E5F000102030405060708090A0B0C0D0E0F")
- _T("606162636465666768696A6B6C6D6E6F000102030405060708090A0B0C0D0E0F")
- _T("707172737475767778797A7B7C7D7E7F000102030405060708090A0B0C0D0E0F")
- _T("808182838485868788898A8B8C8D8E8F000102030405060708090A0B0C0D0E0F")
- _T("909192939495969798999A9B9C9D9E9F000102030405060708090A0B0C0D0E0F")
- _T("10010110210310410510610710810910A000102030405060708090A0B0C0D0EF")
- _T("10B10C10D10E10F110111112113114115000102030405060708090A0B0C0D0EF")
- _T("11611711811911A11B11C11D11E11F120000102030405060708090A0B0C0D0EF")
- _T("12112212312412512612712812912A12B000102030405060708090A0B0C0D0EF")
- _T("12C12D12E12F130131132134135136137000102030405060708090A0B0C0D0EF")
- _T("13813913A13B13C13D13E13F140141142000102030405060708090A0B0C0D0EF")
- _T("14314414514614714814914A14B14C14D000102030405060708090A0B0C0D0EF")
- _T("14E14F150151152153154155156157158000102030405060708090A0B0C0D0EF")
- _T("15915A15B15C15D15E15F160161162163000102030405060708090A0B0C0D0EF")
- _T("16416516616716816916A16B16C16D16E000102030405060708090A0B0C0D0EF")
- _T("16F170171172173174175176177178179000102030405060708090A0B0C0D0EF")
- _T("17A17B17C17D17E17F180181182183184000102030405060708090A0B0C0D0EF")
- _T("18518618718818918A18B18C18D18E18F000102030405060708090A0B0C0D0EF")
- _T("19019119219319419519619719819919A000102030405060708090A0B0C0D0EF")
- _T("19B19C19D19E19F200201202203204205000102030405060708090A0B0C0D0EF")
- _T("20620720820920A20B20C20D20F210211000102030405060708090A0B0C0D0EF")
- _T("21221321421521621721821921A21B21C000102030405060708090A0B0C0D0EF")
- _T("21D21E21F220221222223224225226227000102030405060708090A0B0C0D0EF")
- _T("22822922A22B22C22D22E22F230231232000102030405060708090A0B0C0D0EF")
- _T("23323423523623723823923A23B23C23D000102030405060708090A0B0C0D0EF")
- _T("23E23F240241242243244245246247248000102030405060708090A0B0C0D0EF")
- _T("24924A24B24C24D24E24F250251252253000102030405060708090A0B0C0D0EF")
- _T("101112131415161718191A1B1C1D1E1F000102030405060708090A0B0C0D0E0F")
- _T("202122232425262728292A2B2C2D2E2F000102030405060708090A0B0C0D0E0F")
- _T("303132333435363738393A3B3C3D3E3F000102030405060708090A0B0C0D0E0F")
- _T("404142434445464748494A4B4C4D4E4F000102030405060708090A0B0C0D0E0F")
- _T("505152535455565758595A5B5C5D5E5F000102030405060708090A0B0C0D0E0F")
- _T("606162636465666768696A6B6C6D6E6F000102030405060708090A0B0C0D0E0F")
- _T("707172737475767778797A7B7C7D7E7F000102030405060708090A0B0C0D0E0F")
- _T("808182838485868788898A8B8C8D8E8F000102030405060708090A0B0C0D0E0F")
- _T("909192939495969798999A9B9C9D9E9F000102030405060708090A0B0C0D0E0F")
- _T("10010110210310410510610710810910A000102030405060708090A0B0C0D0EF")
- _T("10B10C10D10E10F110111112113114115000102030405060708090A0B0C0D0EF")
- _T("11611711811911A11B11C11D11E11F120000102030405060708090A0B0C0D0EF")
- _T("12112212312412512612712812912A12B000102030405060708090A0B0C0D0EF")
- _T("12C12D12E12F130131132134135136137000102030405060708090A0B0C0D0EF")
- _T("13813913A13B13C13D13E13F140141142000102030405060708090A0B0C0D0EF")
- _T("14314414514614714814914A14B14C14D000102030405060708090A0B0C0D0EF")
- _T("14E14F150151152153154155156157158000102030405060708090A0B0C0D0EF")
- _T("15915A15B15C15D15E15F160161162163000102030405060708090A0B0C0D0EF")
- _T("16416516616716816916A16B16C16D16E000102030405060708090A0B0C0D0EF")
- _T("16F170171172173174175176177178179000102030405060708090A0B0C0D0EF")
- _T("17A17B17C17D17E17F180181182183184000102030405060708090A0B0C0D0EF")
- _T("18518618718818918A18B18C18D18E18F000102030405060708090A0B0C0D0EF")
- _T("19019119219319419519619719819919A000102030405060708090A0B0C0D0EF")
- _T("19B19C19D19E19F200201202203204205000102030405060708090A0B0C0D0EF")
- _T("20620720820920A20B20C20D20F210211000102030405060708090A0B0C0D0EF")
- _T("21221321421521621721821921A21B21C000102030405060708090A0B0C0D0EF")
- _T("21D21E21F220221222223224225226227000102030405060708090A0B0C0D0EF")
- _T("22822922A22B22C22D22E22F230231232000102030405060708090A0B0C0D0EF")
- _T("23323423523623723823923A23B23C23D000102030405060708090A0B0C0D0EF")
- _T("2366890FE1438751097E7F6325DC0E6326F")
- _T("25425525625725825925A25B25C25D25E25F000102030405060708090A0B0C0F");
-// Thread function for Call Context Inserts
-
-struct _ParamStruct
-{
- HANDLE hShutdownEvent;
- int nStartingRecordNum;
- long* pnNumCallsProcessed;
-};
-
-HANDLE hShutdownEvent = 0;
-
-BOOL WINAPI ConsoleCtrlHandler(DWORD dwCtrlType)
-{
- if(CTRL_C_EVENT == dwCtrlType)
- {
- SetEvent(hShutdownEvent);
- return TRUE;
- }
- return FALSE;
-}
-
-DWORD WINAPI RuntimeCallContext(LPVOID lpParam)
-{
- long nNumCallsProcessed = 0;
-
- struct _ParamStruct* pData = (struct _ParamStruct*)lpParam;
- int nStartingRecordID = pData->nStartingRecordNum;
-
- HRESULT hr = CoInitialize(NULL);
- if(FAILED(hr))
- {
- printf("Error Initializing COM Library\n");
- return (int)hr;
- }
-
- _ConnectionPtr cn = NULL;
- _CommandPtr cmdUpdate = NULL, cmdInsert = NULL, cmdDelete = NULL, cmdSelect = NULL;
- _RecordsetPtr rs = NULL;
- _ParameterPtr paramContextID = NULL;
- _ParameterPtr paramVersion = NULL;
- _ParameterPtr paramLockFlag = NULL;
- _ParameterPtr ttparamLockFlag = NULL;
- _ParameterPtr paramLockTime = NULL;
- _ParameterPtr paramLockTimeUSec = NULL;
- _ParameterPtr paramContextData = NULL;
- _variant_t vtVersion;
- _variant_t vtLockFlag;
- _variant_t vtLockTime;
- _variant_t vtLockTimeUSec;
- _variant_t vtContextData;
- // Initialize Values
- vtVersion = CALL_CONTEXT_VERSION;
- vtLockFlag = CALL_CONTEXT_LOCK_FLAG;
- vtLockTime = CALL_CONTEXT_LOCK_TIME;
- vtLockTimeUSec = CALL_CONTEXT_LOCK_TIME_USEC;
- vtContextData = STATUS_DATA;
-
- LARGE_INTEGER freq;
-
- DWORD dwStartTime, dwEndTime;
- LARGE_INTEGER liStartTime, liEndTime;
-
- try
- {
- cn.CreateInstance(__uuidof(Connection));
- cn->ConnectionString = _T("DSN=TTTelcoCS;");
- cn->Open(_T(""),_T(""),_T(""),adConnectUnspecified);
-
- cmdUpdate.CreateInstance(__uuidof(Command));
- cmdInsert.CreateInstance(__uuidof(Command));
- cmdDelete.CreateInstance(__uuidof(Command));
- cmdSelect.CreateInstance(__uuidof(Command));
-
- TCHAR tszInsert[10000], tszUpdate[10000];
- memset(tszInsert, 0, sizeof(tszInsert));
- memset(tszUpdate, 0, sizeof(tszUpdate));
- strcpy(tszInsert, "INSERT INTO dbo.CallContext(ContextId,Version,LockFlag,LockTime,LockTimeUSec,ContextData) VALUES(?,?,?,?,?,'");
- strcat(tszInsert, STATUS_DATA);
- strcat(tszInsert, "')");
-
- cmdInsert->CommandText= tszInsert;
- cmdInsert->ActiveConnection = cn;
- cmdInsert->Prepared = TRUE;
-
-
- strcpy(tszUpdate, "UPDATE dbo.CallContext SET ContextData = '");
- strcat(tszUpdate, STATUS_DATA);
- strcat(tszUpdate, "' WHERE ContextId = ?");
- cmdUpdate->CommandText= tszUpdate;
- cmdUpdate->ActiveConnection = cn;
- cmdUpdate->Prepared = TRUE;
-
- cmdDelete->CommandText=_T("DELETE FROM dbo.CallContext WHERE ContextId = ?");
- cmdDelete->ActiveConnection = cn;
- cmdDelete->Prepared = TRUE;
-
- cmdSelect->CommandText=_T("SELECT ContextData FROM dbo.CallContext WHERE ContextId = ?");
- cmdSelect->ActiveConnection = cn;
- cmdSelect->Prepared = TRUE;
-
-
- //Create params
- paramContextID = cmdInsert->CreateParameter(_T("ContextID"),adInteger,adParamInput,sizeof(int),nStartingRecordID);
- paramVersion = cmdInsert->CreateParameter(_T("Version"),adInteger,adParamInput,sizeof(int),1);//vtVersion);
- paramLockFlag = cmdInsert->CreateParameter(_T("LockFlag"),adInteger,adParamInput,sizeof(int),1);//vtLockFlag);
- ttparamLockFlag = cmdUpdate->CreateParameter(_T("LockFlag"),adInteger,adParamInput,sizeof(int),1);//vtLockFlag);
- paramLockTime = cmdInsert->CreateParameter(_T("LockTime"),adInteger,adParamInput,sizeof(int),1);//vtLockTime);
- paramLockTimeUSec = cmdInsert->CreateParameter(_T("LockTimeUSec"),adInteger,adParamInput,sizeof(int),1);//vtLockTimeUSec);
- paramContextData = cmdInsert->CreateParameter(_T("ContextData"), adBSTR, adParamInput, SysStringByteLen(vtContextData.bstrVal), vtContextData);
- //paramContextData->put_Value(vtContextData);
-
-
-
- //Append params
- cmdInsert->Parameters->Append(paramContextID);
- cmdInsert->Parameters->Append(paramVersion);
- cmdInsert->Parameters->Append(paramLockFlag);
- cmdInsert->Parameters->Append(paramLockTime);
- cmdInsert->Parameters->Append(paramLockTimeUSec);
- //cmdInsert->Parameters->Append(paramContextData);
-
-
- cmdUpdate->Parameters->Append(paramContextID);
- //cmdUpdate->Parameters->Append(paramContextID);
-
- cmdSelect->Parameters->Append(paramContextID);
-
- cmdDelete->Parameters->Append(paramContextID);
-
- while(WaitForSingleObject(pData->hShutdownEvent,0) != WAIT_OBJECT_0)
- {
- paramContextID->Value = nStartingRecordID++;
-
- bool bTimeLatency = (nStartingRecordID == 100) ? TRUE : FALSE;
-
- if (bTimeLatency)
- {
- BOOL bSuccess = QueryPerformanceFrequency(&freq);
- if (!bSuccess)
- printf("Error retrieving frequency: %d\n", GetLastError());
-
- }
-
-
-
- for (int i=0; i < 20; i++)
- {
- switch(i)
- {
- case 3:
- case 6:
- case 9:
- case 11:
- case 12:
- case 15:
- case 18: // Query Record
- if (bTimeLatency)
- QueryPerformanceCounter(&liStartTime);
-
- cmdSelect->Execute(NULL, NULL, -1);
- if (bTimeLatency)
- {
- QueryPerformanceCounter(&liEndTime);
- printf("Read = %d msec.\n", (liEndTime.QuadPart - liStartTime.QuadPart) / (freq.QuadPart/1000));
- }
- break;
- case 19: // Delete Record
- if (bTimeLatency)
- QueryPerformanceCounter(&liStartTime);
- cmdDelete->Execute(NULL,NULL,adExecuteNoRecords);
- if (bTimeLatency)
- {
- QueryPerformanceCounter(&liEndTime);
- printf("Delete = %d msec.\n", (liEndTime.QuadPart - liStartTime.QuadPart) / (freq.QuadPart/1000));
- }
- break;
- case 0: // Insert Record
- if (bTimeLatency)
- QueryPerformanceCounter(&liStartTime);
- cmdInsert->Execute(NULL,NULL,adExecuteNoRecords);
- if (bTimeLatency)
- {
- QueryPerformanceCounter(&liEndTime);
- printf("Insert = %d msec.\n", (liEndTime.QuadPart - liStartTime.QuadPart) / (freq.QuadPart/1000));
- }
- break;
- default: // Update Record
- if (bTimeLatency)
- QueryPerformanceCounter(&liStartTime);
- cmdUpdate->Execute(NULL,NULL,adExecuteNoRecords);
- if (bTimeLatency)
- {
- QueryPerformanceCounter(&liEndTime);
- printf("Update = %d msec.\n", (liEndTime.QuadPart - liStartTime.QuadPart) / (freq.QuadPart/1000));
- }
-
- break;
- }
- }
-
- nNumCallsProcessed++;
-
- InterlockedIncrement(pData->pnNumCallsProcessed);
- }
-
- cn->Close();
- }
- catch(_com_error &e)
- {
- printf("%d: \n\t%s\n\t%s\n",
- e.Error(),
- e.ErrorMessage(),
- e.Source());
-
- }
-
- return 0;
-}
-
-
-int _tmain(int argc, _TCHAR* argv[])
-{
- long nNumThreads=4;
- long nSeed = 0;
- if(lstrcmp(argv[1],_T("/?")) == 0)
- {
- _tprintf(_T("InsertRecs [No.Of Threads] [Record Seed No.]\n"));
- return 0;
- }
-
- if(argc > 1)
- nNumThreads = _ttol(argv[1]);
- else
- nNumThreads = 4;
- if (argc > 2)
- nSeed = _ttol(argv[2]);
- _tprintf(_T("Num of Threads = %d, Seed = %d"), nNumThreads, nSeed);
-
- long nNumCallsProcessed = 0;
-
- SetConsoleCtrlHandler(ConsoleCtrlHandler,true);
- hShutdownEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
-
- DWORD dwStartTime = GetTickCount();
-
- DWORD dwThreadID = 0;
- HANDLE hThreads[50];
-
- struct _ParamStruct params[50];
-
-
- for(int ij=0;ij<nNumThreads;ij++) {
- params[ij].hShutdownEvent = hShutdownEvent;
- params[ij].nStartingRecordNum = (ij*5000) + nSeed;
- params[ij].pnNumCallsProcessed = &nNumCallsProcessed;
- }
-
-
- for(int ij=0;ij<nNumThreads;ij++) {
- hThreads[ij] = CreateThread(NULL,NULL,RuntimeCallContext,&params[ij],0,&dwThreadID);
- }
-
- //Wait for the threads to finish
- WaitForMultipleObjects(nNumThreads,hThreads,TRUE,INFINITE);
- DWORD dwEndTime = GetTickCount();
-
- CloseHandle(hShutdownEvent);
-
- //Print time taken
- _tprintf(_T("Time Taken for %d Calls is %ld msec (= %ld calls/sec\n"),
- nNumCallsProcessed,dwEndTime-dwStartTime, (1000*nNumCallsProcessed/(dwEndTime-dwStartTime)));
- return 0;
-
-}
diff --git a/storage/ndb/test/ndbapi/asyncGenerator.cpp b/storage/ndb/test/ndbapi/asyncGenerator.cpp
deleted file mode 100644
index 1d7e7180bf5..00000000000
--- a/storage/ndb/test/ndbapi/asyncGenerator.cpp
+++ /dev/null
@@ -1,571 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-/***************************************************************
-* I N C L U D E D F I L E S *
-***************************************************************/
-
-#include <ndb_global.h>
-
-#include "dbGenerator.h"
-#include <NdbApi.hpp>
-#include <NdbOut.hpp>
-#include <NdbSleep.h>
-
-/***************************************************************
-* L O C A L C O N S T A N T S *
-***************************************************************/
-
-/***************************************************************
-* L O C A L D A T A S T R U C T U R E S *
-***************************************************************/
-
-/***************************************************************
-* L O C A L F U N C T I O N S *
-***************************************************************/
-
-static void getRandomSubscriberNumber(SubscriberNumber number);
-static void getRandomServerId(ServerId *serverId);
-static void getRandomChangedBy(ChangedBy changedBy);
-static void getRandomChangedTime(ChangedTime changedTime);
-
-static void clearTransaction(TransactionDefinition *trans);
-static void initGeneratorStatistics(GeneratorStatistics *gen);
-
-static void doOneTransaction(ThreadData * td,
- int parallellism,
- int millisSendPoll,
- int minEventSendPoll,
- int forceSendPoll);
-static void doTransaction_T1(Ndb * pNDB, ThreadData * td, int async);
-static void doTransaction_T2(Ndb * pNDB, ThreadData * td, int async);
-static void doTransaction_T3(Ndb * pNDB, ThreadData * td, int async);
-static void doTransaction_T4(Ndb * pNDB, ThreadData * td, int async);
-static void doTransaction_T5(Ndb * pNDB, ThreadData * td, int async);
-
-/***************************************************************
-* L O C A L D A T A *
-***************************************************************/
-
-static SequenceValues transactionDefinition[] = {
- {25, 1},
- {25, 2},
- {20, 3},
- {15, 4},
- {15, 5},
- {0, 0}
-};
-
-static SequenceValues rollbackDefinition[] = {
- {98, 0},
- {2 , 1},
- {0, 0}
-};
-
-static int maxsize = 0;
-
-/***************************************************************
-* P U B L I C D A T A *
-***************************************************************/
-
-/***************************************************************
-****************************************************************
-* L O C A L F U N C T I O N S C O D E S E C T I O N *
-****************************************************************
-***************************************************************/
-
-static void getRandomSubscriberNumber(SubscriberNumber number)
-{
- uint32 tmp;
- char sbuf[SUBSCRIBER_NUMBER_LENGTH + 1];
- tmp = myRandom48(NO_OF_SUBSCRIBERS);
- sprintf(sbuf, "%.*d", SUBSCRIBER_NUMBER_LENGTH, tmp);
- memcpy(number, sbuf, SUBSCRIBER_NUMBER_LENGTH);
-}
-
-static void getRandomServerId(ServerId *serverId)
-{
- *serverId = myRandom48(NO_OF_SERVERS);
-}
-
-static void getRandomChangedBy(ChangedBy changedBy)
-{
- memset(changedBy, myRandom48(26)+'A', CHANGED_BY_LENGTH);
- changedBy[CHANGED_BY_LENGTH] = 0;
-}
-
-static void getRandomChangedTime(ChangedTime changedTime)
-{
- memset(changedTime, myRandom48(26)+'A', CHANGED_TIME_LENGTH);
- changedTime[CHANGED_TIME_LENGTH] = 0;
-}
-
-static void clearTransaction(TransactionDefinition *trans)
-{
- trans->count = 0;
- trans->branchExecuted = 0;
- trans->rollbackExecuted = 0;
- trans->latencyCounter = myRandom48(127);
- trans->latency.reset();
-}
-
-static int listFull(SessionList *list)
-{
- return(list->numberInList == SESSION_LIST_LENGTH);
-}
-
-static int listEmpty(SessionList *list)
-{
- return(list->numberInList == 0);
-}
-
-static void insertSession(SessionList *list,
- SubscriberNumber number,
- ServerId serverId)
-{
- SessionElement *e;
- if( listFull(list) ) return;
-
- e = &list->list[list->writeIndex];
-
- strcpy(e->subscriberNumber, number);
- e->serverId = serverId;
-
- list->writeIndex = (list->writeIndex + 1) % SESSION_LIST_LENGTH;
- list->numberInList++;
-
- if( list->numberInList > maxsize )
- maxsize = list->numberInList;
-}
-
-static SessionElement *getNextSession(SessionList *list)
-{
- if( listEmpty(list) ) return(0);
-
- return(&list->list[list->readIndex]);
-}
-
-static void deleteSession(SessionList *list)
-{
- if( listEmpty(list) ) return;
-
- list->readIndex = (list->readIndex + 1) % SESSION_LIST_LENGTH;
- list->numberInList--;
-}
-
-static void initGeneratorStatistics(GeneratorStatistics *gen)
-{
- int i;
-
- if( initSequence(&gen->transactionSequence,
- transactionDefinition) != 0 ) {
- ndbout_c("could not set the transaction types");
- exit(0);
- }
-
- if( initSequence(&gen->rollbackSequenceT4,
- rollbackDefinition) != 0 ) {
- ndbout_c("could not set the rollback sequence");
- exit(0);
- }
-
- if( initSequence(&gen->rollbackSequenceT5,
- rollbackDefinition) != 0 ) {
- ndbout_c("could not set the rollback sequence");
- exit(0);
- }
-
- for(i = 0; i < NUM_TRANSACTION_TYPES; i++ )
- clearTransaction(&gen->transactions[i]);
-
- gen->totalTransactions = 0;
-
- gen->activeSessions.numberInList = 0;
- gen->activeSessions.readIndex = 0;
- gen->activeSessions.writeIndex = 0;
-}
-
-
-static
-void
-doOneTransaction(ThreadData * td, int p, int millis, int minEvents, int force)
-{
- int i;
- unsigned int transactionType;
- int async = 1;
- if (p == 1) {
- async = 0;
- }//if
- for(i = 0; i<p; i++){
- if(td[i].runState == Runnable){
- transactionType = getNextRandom(&td[i].generator.transactionSequence);
-
- switch(transactionType) {
- case 1:
- doTransaction_T1(td[i].pNDB, &td[i], async);
- break;
- case 2:
- doTransaction_T2(td[i].pNDB, &td[i], async);
- break;
- case 3:
- doTransaction_T3(td[i].pNDB, &td[i], async);
- break;
- case 4:
- doTransaction_T4(td[i].pNDB, &td[i], async);
- break;
- case 5:
- doTransaction_T5(td[i].pNDB, &td[i], async);
- break;
- default:
- ndbout_c("Unknown transaction type: %d", transactionType);
- }
- }
- }
- if (async == 1) {
- td[0].pNDB->sendPollNdb(millis, minEvents, force);
- }//if
-}
-
-static
-void
-doTransaction_T1(Ndb * pNDB, ThreadData * td, int async)
-{
- /*----------------*/
- /* Init arguments */
- /*----------------*/
- getRandomSubscriberNumber(td->transactionData.number);
- getRandomChangedBy(td->transactionData.changed_by);
- BaseString::snprintf(td->transactionData.changed_time,
- sizeof(td->transactionData.changed_time),
- "%ld - %d", td->changedTime++, myRandom48(65536*1024));
- //getRandomChangedTime(td->transactionData.changed_time);
- td->transactionData.location = td->transactionData.changed_by[0];
-
- /*-----------------*/
- /* Run transaction */
- /*-----------------*/
- td->runState = Running;
- td->generator.transactions[0].startLatency();
-
- start_T1(pNDB, td, async);
-}
-
-static
-void
-doTransaction_T2(Ndb * pNDB, ThreadData * td, int async)
-{
- /*----------------*/
- /* Init arguments */
- /*----------------*/
- getRandomSubscriberNumber(td->transactionData.number);
-
- /*-----------------*/
- /* Run transaction */
- /*-----------------*/
- td->runState = Running;
- td->generator.transactions[1].startLatency();
-
- start_T2(pNDB, td, async);
-}
-
-static
-void
-doTransaction_T3(Ndb * pNDB, ThreadData * td, int async)
-{
- SessionElement *se;
-
- /*----------------*/
- /* Init arguments */
- /*----------------*/
- se = getNextSession(&td->generator.activeSessions);
- if( se ) {
- strcpy(td->transactionData.number, se->subscriberNumber);
- td->transactionData.server_id = se->serverId;
- td->transactionData.sessionElement = 1;
- } else {
- getRandomSubscriberNumber(td->transactionData.number);
- getRandomServerId(&td->transactionData.server_id);
- td->transactionData.sessionElement = 0;
- }
-
- td->transactionData.server_bit = (1 << td->transactionData.server_id);
-
- /*-----------------*/
- /* Run transaction */
- /*-----------------*/
- td->runState = Running;
- td->generator.transactions[2].startLatency();
- start_T3(pNDB, td, async);
-}
-
-static
-void
-doTransaction_T4(Ndb * pNDB, ThreadData * td, int async)
-{
- /*----------------*/
- /* Init arguments */
- /*----------------*/
- getRandomSubscriberNumber(td->transactionData.number);
- getRandomServerId(&td->transactionData.server_id);
-
- td->transactionData.server_bit = (1 << td->transactionData.server_id);
- td->transactionData.do_rollback =
- getNextRandom(&td->generator.rollbackSequenceT4);
-
-#if 0
- memset(td->transactionData.session_details,
- myRandom48(26)+'A', SESSION_DETAILS_LENGTH);
-#endif
- td->transactionData.session_details[SESSION_DETAILS_LENGTH] = 0;
-
- /*-----------------*/
- /* Run transaction */
- /*-----------------*/
- td->runState = Running;
- td->generator.transactions[3].startLatency();
- start_T4(pNDB, td, async);
-}
-
-static
-void
-doTransaction_T5(Ndb * pNDB, ThreadData * td, int async)
-{
- SessionElement * se;
- se = getNextSession(&td->generator.activeSessions);
- if( se ) {
- strcpy(td->transactionData.number, se->subscriberNumber);
- td->transactionData.server_id = se->serverId;
- td->transactionData.sessionElement = 1;
- }
- else {
- getRandomSubscriberNumber(td->transactionData.number);
- getRandomServerId(&td->transactionData.server_id);
- td->transactionData.sessionElement = 0;
- }
-
- td->transactionData.server_bit = (1 << td->transactionData.server_id);
- td->transactionData.do_rollback
- = getNextRandom(&td->generator.rollbackSequenceT5);
-
- /*-----------------*/
- /* Run transaction */
- /*-----------------*/
- td->runState = Running;
- td->generator.transactions[4].startLatency();
- start_T5(pNDB, td, async);
-}
-
-void
-complete_T1(ThreadData * data){
- data->generator.transactions[0].stopLatency();
- data->generator.transactions[0].count++;
-
- data->runState = Runnable;
- data->generator.totalTransactions++;
-}
-
-void
-complete_T2(ThreadData * data){
- data->generator.transactions[1].stopLatency();
- data->generator.transactions[1].count++;
-
- data->runState = Runnable;
- data->generator.totalTransactions++;
-}
-
-void
-complete_T3(ThreadData * data){
-
- data->generator.transactions[2].stopLatency();
- data->generator.transactions[2].count++;
-
- if(data->transactionData.branchExecuted)
- data->generator.transactions[2].branchExecuted++;
-
- data->runState = Runnable;
- data->generator.totalTransactions++;
-}
-
-void
-complete_T4(ThreadData * data){
-
- data->generator.transactions[3].stopLatency();
- data->generator.transactions[3].count++;
-
- if(data->transactionData.branchExecuted)
- data->generator.transactions[3].branchExecuted++;
- if(data->transactionData.do_rollback)
- data->generator.transactions[3].rollbackExecuted++;
-
- if(data->transactionData.branchExecuted &&
- !data->transactionData.do_rollback){
- insertSession(&data->generator.activeSessions,
- data->transactionData.number,
- data->transactionData.server_id);
- }
-
- data->runState = Runnable;
- data->generator.totalTransactions++;
-
-}
-void
-complete_T5(ThreadData * data){
-
- data->generator.transactions[4].stopLatency();
- data->generator.transactions[4].count++;
-
- if(data->transactionData.branchExecuted)
- data->generator.transactions[4].branchExecuted++;
- if(data->transactionData.do_rollback)
- data->generator.transactions[4].rollbackExecuted++;
-
- if(data->transactionData.sessionElement &&
- !data->transactionData.do_rollback){
- deleteSession(&data->generator.activeSessions);
- }
-
- data->runState = Runnable;
- data->generator.totalTransactions++;
-}
-
-/***************************************************************
-****************************************************************
-* P U B L I C F U N C T I O N S C O D E S E C T I O N *
-****************************************************************
-***************************************************************/
-void
-asyncGenerator(ThreadData *data,
- int parallellism,
- int millisSendPoll,
- int minEventSendPoll,
- int forceSendPoll)
-{
- ThreadData * startUp;
-
- GeneratorStatistics *st;
- double periodStop;
- double benchTimeStart;
- double benchTimeEnd;
- int i, j, done;
-
- myRandom48Init(data->randomSeed);
-
- for(i = 0; i<parallellism; i++){
- initGeneratorStatistics(&data[i].generator);
- }
-
- startUp = (ThreadData*)malloc(parallellism * sizeof(ThreadData));
- memcpy(startUp, data, (parallellism * sizeof(ThreadData)));
-
- /*----------------*/
- /* warm up period */
- /*----------------*/
- periodStop = userGetTime() + (double)data[0].warmUpSeconds;
-
- while(userGetTime() < periodStop){
- doOneTransaction(startUp, parallellism,
- millisSendPoll, minEventSendPoll, forceSendPoll);
- }
-
- ndbout_c("Waiting for startup to finish");
-
- /**
- * Wait for all transactions
- */
- done = 0;
- while(!done){
- done = 1;
- for(i = 0; i<parallellism; i++){
- if(startUp[i].runState != Runnable){
- done = 0;
- break;
- }
- }
- if(!done){
- startUp[0].pNDB->sendPollNdb();
- }
- }
- ndbout_c("Benchmark period starts");
-
- /*-------------------------*/
- /* normal benchmark period */
- /*-------------------------*/
- benchTimeStart = userGetTime();
-
- periodStop = benchTimeStart + (double)data[0].testSeconds;
- while(userGetTime() < periodStop)
- doOneTransaction(data, parallellism,
- millisSendPoll, minEventSendPoll, forceSendPoll);
-
- benchTimeEnd = userGetTime();
-
- ndbout_c("Benchmark period done");
-
- /**
- * Wait for all transactions
- */
- done = 0;
- while(!done){
- done = 1;
- for(i = 0; i<parallellism; i++){
- if(data[i].runState != Runnable){
- done = 0;
- break;
- }
- }
- if(!done){
- data[0].pNDB->sendPollNdb();
- }
- }
-
- /*------------------*/
- /* cool down period */
- /*------------------*/
- periodStop = userGetTime() + (double)data[0].coolDownSeconds;
- while(userGetTime() < periodStop){
- doOneTransaction(startUp, parallellism,
- millisSendPoll, minEventSendPoll, forceSendPoll);
- }
-
- done = 0;
- while(!done){
- done = 1;
- for(i = 0; i<parallellism; i++){
- if(startUp[i].runState != Runnable){
- done = 0;
- break;
- }
- }
- if(!done){
- startUp[0].pNDB->sendPollNdb();
- }
- }
-
-
- /*---------------------------------------------------------*/
- /* add the times for all transaction for inner loop timing */
- /*---------------------------------------------------------*/
- for(j = 0; j<parallellism; j++){
- st = &data[j].generator;
-
- st->outerLoopTime = benchTimeEnd - benchTimeStart;
- st->outerTps = getTps(st->totalTransactions, st->outerLoopTime);
- }
- /* ndbout_c("maxsize = %d\n",maxsize); */
-
- free(startUp);
-}
-
diff --git a/storage/ndb/test/ndbapi/bank/Bank.cpp b/storage/ndb/test/ndbapi/bank/Bank.cpp
deleted file mode 100644
index bb662680202..00000000000
--- a/storage/ndb/test/ndbapi/bank/Bank.cpp
+++ /dev/null
@@ -1,2521 +0,0 @@
-/* Copyright (c) 2003-2006 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include "Bank.hpp"
-#include <time.h>
-#include <NdbSleep.h>
-#include <UtilTransactions.hpp>
-
-Bank::Bank(Ndb_cluster_connection& con, bool _init, const char * dbase):
- m_ndb(&con, dbase),
- m_maxAccount(-1),
- m_initialized(false),
- m_skip_create(false)
-{
- if(_init)
- init();
-}
-
-int Bank::init(){
- if (m_initialized == true)
- return NDBT_OK;
-
- myRandom48Init(NdbTick_CurrentMillisecond());
-
- m_ndb.init();
- if (m_ndb.waitUntilReady(30) != 0)
- {
- ndbout << "Ndb not ready" << endl;
- return NDBT_FAILED;
- }
-
- if (getNumAccounts() != NDBT_OK)
- return NDBT_FAILED;
-
- m_initialized = true;
- return NDBT_OK;
-}
-
-int Bank::performTransactions(int maxSleepBetweenTrans, int yield){
-
- int transactions = 0;
-
- while(performTransaction() == NDBT_OK)
- {
- transactions++;
-
- if (maxSleepBetweenTrans > 0){
- int val = myRandom48(maxSleepBetweenTrans);
- NdbSleep_MilliSleep(val);
- }
-
- if((transactions % 100) == 0)
- g_info << transactions << endl;
-
- if (yield != 0 && transactions >= yield)
- return NDBT_OK;
- }
-
- return NDBT_FAILED;
-
-}
-
-int Bank::performTransaction(){
- int result = NDBT_OK;
-
- if (m_maxAccount <= 0){
- g_err << "No accounts in bank" << endl;
- return NDBT_FAILED;
- }
-
- int fromAccount = myRandom48(m_maxAccount);
- int toAccount = myRandom48(m_maxAccount);
-
- if (fromAccount == toAccount){
- // Increase toAccount with 1
- toAccount = (toAccount+1)%m_maxAccount;
- }
-
- int maxAmount = getMaxAmount();
-
- int amount = myRandom48(maxAmount);
-
-retry_transaction:
- int res = performTransaction(fromAccount, toAccount, amount);
- if (res != 0){
- switch (res){
- case NDBT_FAILED:
- g_err << "performTransaction returned NDBT_FAILED" << endl
- << " fromAccount = " << fromAccount << endl
- << " toAccount = " << toAccount << endl
- << " amount = " << amount << endl;
- result = NDBT_FAILED;
- break;
- case NOT_ENOUGH_FUNDS:
- // ndbout << "performTransaction returned NOT_ENOUGH_FUNDS" << endl;
- break;
- case NDBT_TEMPORARY:
- g_err << "TEMPORARY_ERRROR retrying" << endl;
- NdbSleep_MilliSleep(50);
- goto retry_transaction;
- break;
- default:
- g_info << "performTransaction returned "<<res << endl;
- break;
- }
- }
- return result;
-}
-
-/**
- * Perform a transaction in the bank.
- * Ie. transfer money from one account to another.
- *
- * @param
- * @return 0 if successful or an error code
- */
-int Bank::performTransaction(int fromAccountId,
- int toAccountId,
- int amount ){
- /**
- * 1. Start transaction
- * 2. Check balance on from account, if there is
- * not enough funds abort transaction
- * 3. Update ACCOUNT set balance = balance - amount on
- * from account
- * 4. Insert withdrawal in TRANSACTION
- * 5. Insert deposit in transaction
- * 6. Update ACCOUNT set balance = balance + amount on
- * to account
- * 7. Commit transaction
- */
- // g_info << "performTransaction " << fromAccountId
- // << ", "<<toAccountId<<", "<<amount << endl;
-
- // Call the first implementation of this trans
- // In the future we can have several different versions of this trans
- // and call them randomly
- return performTransactionImpl1(fromAccountId, toAccountId, amount);
-}
-
-
-int Bank::performTransactionImpl1(int fromAccountId,
- int toAccountId,
- int amount ){
-
- int check;
-
- // Ok, all clear to do the transaction
- Uint64 transId;
- int result = NDBT_OK;
- if ((result= getNextTransactionId(transId)) != NDBT_OK){
- return result;
- }
-
- NdbConnection* pTrans = m_ndb.startTransaction();
-
- if( pTrans == NULL ) {
- const NdbError err = m_ndb.getNdbError();
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- return NDBT_TEMPORARY;
- }
- ERR(err);
- return NDBT_FAILED;
- }
-
- Uint64 currTime;
- if (prepareGetCurrTimeOp(pTrans, currTime) != NDBT_OK){
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- /**
- * Check balance on from account
- */
- NdbOperation* pOp = pTrans->getNdbOperation("ACCOUNT");
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp->readTupleExclusive();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp->equal("ACCOUNT_ID", fromAccountId);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* balanceFromRec = pOp->getValue("BALANCE");
- if( balanceFromRec ==NULL ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* fromAccountTypeRec = pOp->getValue("ACCOUNT_TYPE");
- if( fromAccountTypeRec == NULL ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- /**
- * Read balance on to account
- */
- NdbOperation* pOp6 = pTrans->getNdbOperation("ACCOUNT");
- if (pOp6 == NULL) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp6->readTupleExclusive();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp6->equal("ACCOUNT_ID", toAccountId);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* balanceToRec = pOp6->getValue("BALANCE");
- if( balanceToRec == NULL ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* toAccountTypeRec = pOp6->getValue("ACCOUNT_TYPE");
- if( toAccountTypeRec == NULL ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pTrans->execute(NoCommit);
- if( check == -1 ) {
- const NdbError err = pTrans->getNdbError();
- m_ndb.closeTransaction(pTrans);
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- return NDBT_TEMPORARY;
- }
- ERR(err);
- return NDBT_FAILED;
- }
-
-
- Uint32 balanceFrom = balanceFromRec->u_32_value();
- // ndbout << "balanceFrom: " << balanceFrom << endl;
-
- if (((Int64)balanceFrom - amount) < 0){
- m_ndb.closeTransaction(pTrans);
- //ndbout << "Not enough funds" << endl;
- return NOT_ENOUGH_FUNDS;
- }
-
- Uint32 fromAccountType = fromAccountTypeRec->u_32_value();
-
- Uint32 balanceTo = balanceToRec->u_32_value();
- // ndbout << "balanceTo: " << balanceTo << endl;
- Uint32 toAccountType = toAccountTypeRec->u_32_value();
-
- /**
- * Update balance on from account
- */
- NdbOperation* pOp2 = pTrans->getNdbOperation("ACCOUNT");
- if (pOp2 == NULL) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp2->updateTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp2->equal("ACCOUNT_ID", fromAccountId);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp2->setValue("BALANCE", balanceFrom - amount);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- /**
- * Update balance on to account
- */
- NdbOperation* pOp3 = pTrans->getNdbOperation("ACCOUNT");
- if (pOp3 == NULL) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp3->updateTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp3->equal("ACCOUNT_ID", toAccountId);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp3->setValue("BALANCE", balanceTo + amount);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- /**
- * Insert withdrawal transaction
- */
- NdbOperation* pOp4 = pTrans->getNdbOperation("TRANSACTION");
- if (pOp4 == NULL) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp4->insertTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp4->equal("TRANSACTION_ID", transId);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp4->equal("ACCOUNT", fromAccountId);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp4->setValue("ACCOUNT_TYPE", fromAccountType);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp4->setValue("OTHER_ACCOUNT", toAccountId);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp4->setValue("TRANSACTION_TYPE", WithDrawal);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp4->setValue("TIME", currTime);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp4->setValue("AMOUNT", amount);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- /**
- * Insert deposit transaction
- */
- NdbOperation* pOp5 = pTrans->getNdbOperation("TRANSACTION");
- if (pOp5 == NULL) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp5->insertTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp5->equal("TRANSACTION_ID", transId);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp5->equal("ACCOUNT", toAccountId);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp5->setValue("ACCOUNT_TYPE", toAccountType);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp5->setValue("OTHER_ACCOUNT", fromAccountId);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp5->setValue("TRANSACTION_TYPE", Deposit);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp5->setValue("TIME", currTime);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp5->setValue("AMOUNT", amount);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pTrans->execute(Commit);
- if( check == -1 ) {
- const NdbError err = pTrans->getNdbError();
- m_ndb.closeTransaction(pTrans);
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- return NDBT_TEMPORARY;
- }
- ERR(err);
- return NDBT_FAILED;
- }
-
- m_ndb.closeTransaction(pTrans);
- return NDBT_OK;
-}
-
-
-
-
-int Bank::performMakeGLs(int yield){
- int result;
-
- int counter, maxCounter;
- int yieldCounter = 0;
-
- while (1){
- // Counters to keep tracck of how many
- // GLs should be made before performing a validation
- counter = 0;
- maxCounter = 50 + myRandom48(100);
-
- /**
- * Validate GLs and Transactions for previous days
- *
- */
- result = performValidateGLs();
- if (result != NDBT_OK){
- if (result == VERIFICATION_FAILED){
- g_err << "performValidateGLs verification failed" << endl;
- return NDBT_FAILED;
- }
- g_info << "performValidateGLs failed" << endl;
- return NDBT_FAILED;
- continue;
- }
-
- result = performValidatePurged();
- if (result != NDBT_OK){
- if (result == VERIFICATION_FAILED){
- g_err << "performValidatePurged verification failed" << endl;
- return NDBT_FAILED;
- }
- g_info << "performValidatePurged failed" << endl;
- return NDBT_FAILED;
- }
-
- while (1){
-
- yieldCounter++;
- if (yield != 0 && yieldCounter >= yield)
- return NDBT_OK;
-
- /**
- * Find last GL time.
- * ( GL record with highest time value)
- */
- Uint64 lastGLTime;
- if (findLastGL(lastGLTime) != NDBT_OK){
- g_info << "findLastGL failed" << endl;
- // Break out of inner while loop
- break;
- }
-
- lastGLTime++;
-
- /**
- * If last GL time + 1 is smaller than current time
- * perform a GL for that time
- */
- Uint64 currTime;
- if (getCurrTime(currTime) != NDBT_OK){
- g_info << "getCurrTime failed" << endl;
- // Break out of inner while loop
- break;
- }
- if (lastGLTime < currTime){
- counter++;
- if (performMakeGL(lastGLTime) != NDBT_OK){
- g_info << "performMakeGL failed" << endl;
- // Break out of inner while loop
- break;
- }
-
- if (counter > maxCounter){
- // Break out of inner while loop and
- // validatePreviousGLs
- g_info << "counter("<<counter<<") > maxCounter("<<maxCounter<<")" << endl;
- break;
- }
-
- } else {
- ;//ndbout << "It's not time to make GL yet" << endl;
-
- // ndbout << "Sleeping 1 second" << endl;
- NdbSleep_SecSleep(1);
-
- }
-
- Uint32 age = 3;
- if (purgeOldGLTransactions(currTime, age) != NDBT_OK){
- g_info << "purgeOldGLTransactions failed" << endl;
- // Break out of inner while loop
- break;
- }
-
- }
- }
-
- return NDBT_FAILED;
-
-}
-
-int Bank::performValidateAllGLs(){
- int result;
-
- while (1){
-
- /**
- * Validate GLs and Transactions for previous days
- * Set age so that ALL GL's are validated
- */
- int age = 100000;
- result = performValidateGLs(age);
- if (result != NDBT_OK){
- if (result == VERIFICATION_FAILED){
- g_err << "performValidateGLs verification failed" << endl;
- return NDBT_FAILED;
- }
- g_err << "performValidateGLs failed" << endl;
- return NDBT_FAILED;
- }
-
- /**
- *
- *
- */
- result = performValidatePurged();
- if (result != NDBT_OK){
- if (result == VERIFICATION_FAILED){
- g_err << "performValidatePurged verification failed" << endl;
- return NDBT_FAILED;
- }
- g_err << "performValidatePurged failed" << endl;
- return NDBT_FAILED;
- }
- return NDBT_OK;
- }
-
- return NDBT_FAILED;
-
-}
-
-int Bank::findLastGL(Uint64 &lastTime){
-
- int check;
- /**
- * SELECT MAX(time) FROM GL
- */
- NdbConnection* pScanTrans = m_ndb.startTransaction();
- if (pScanTrans == NULL) {
- ERR(m_ndb.getNdbError());
- return NDBT_FAILED;
- }
-
- NdbScanOperation* pOp = pScanTrans->getNdbScanOperation("GL");
- if (pOp == NULL) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- if( pOp->readTuples() ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- check = pOp->interpret_exit_ok();
- if( check == -1 ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* timeRec = pOp->getValue("TIME");
- if( timeRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- check = pScanTrans->execute(NoCommit);
- if( check == -1 ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- int eof;
- int rows = 0;
- eof = pOp->nextResult();
- lastTime = 0;
-
- while(eof == 0){
- rows++;
- Uint64 t = timeRec->u_32_value();
-
- if (t > lastTime)
- lastTime = t;
-
- eof = pOp->nextResult();
- }
- if (eof == -1) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- m_ndb.closeTransaction(pScanTrans);
-
- return NDBT_OK;
-}
-
-
-int Bank::performMakeGL(int time){
- g_info << "performMakeGL: " << time << endl;
- /**
- * Create one GL record for each account type.
- * All in the same transaction
- */
- // Start transaction
- NdbConnection* pTrans = m_ndb.startTransaction();
- if (pTrans == NULL){
- ERR(m_ndb.getNdbError());
- return NDBT_FAILED;
- }
- for (int i = 0; i < getNumAccountTypes(); i++){
-
- if (performMakeGLForAccountType(pTrans, time, i) != NDBT_OK){
- g_err << "performMakeGLForAccountType returned NDBT_FAILED"<<endl;
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
- }
- // Execute transaction
- if( pTrans->execute(Commit) == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
- m_ndb.closeTransaction(pTrans);
-
- return NDBT_OK;
-}
-
-int Bank::performMakeGLForAccountType(NdbConnection* pTrans,
- Uint64 glTime,
- Uint32 accountTypeId){
- int check;
-
- Uint32 balance = 0;
- Uint32 withdrawalCount = 0;
- Uint32 withdrawalSum = 0;
- Uint32 depositSum = 0;
- Uint32 depositCount = 0;
- Uint32 countTransactions = 0;
- Uint32 purged = 0;
-
- // Insert record in GL so that we know
- // that no one else is performing the same task
- // Set purged = 0 to indicate that TRANSACTION
- // records still exist
- NdbOperation* pOp = pTrans->getNdbOperation("GL");
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp->insertTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp->equal("TIME", glTime);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp->equal("ACCOUNT_TYPE", accountTypeId);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp->setValue("BALANCE", balance);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp->setValue("DEPOSIT_COUNT", depositCount);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp->setValue("DEPOSIT_SUM", depositSum);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp->setValue("WITHDRAWAL_COUNT", withdrawalCount);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp->setValue("WITHDRAWAL_SUM", withdrawalSum);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp->setValue("PURGED", purged);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pTrans->execute(NoCommit);
- if( check == -1 ) {
- ERR(pOp->getNdbError());
- return NDBT_FAILED;
- }
-
- // Read previous GL record to get old balance
- NdbOperation* pOp2 = pTrans->getNdbOperation("GL");
- if (pOp2 == NULL) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp2->readTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp2->equal("TIME", glTime-1);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp2->equal("ACCOUNT_TYPE", accountTypeId);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- NdbRecAttr* oldBalanceRec = pOp2->getValue("BALANCE");
- if( oldBalanceRec == NULL ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pTrans->execute(NoCommit);
- if( check == -1 ) {
- ERR(pOp2->getNdbError());
- return NDBT_FAILED;
- }
-
- Uint32 oldBalance = oldBalanceRec->u_32_value();
- // ndbout << "oldBalance = "<<oldBalance<<endl;
- balance = oldBalance;
- // Start a scan transaction to search
- // for TRANSACTION records with TIME = time
- // and ACCOUNT_TYPE = accountTypeId
- // Build sum of all found transactions
-
- if (sumTransactionsForGL(glTime,
- accountTypeId,
- balance,
- withdrawalCount,
- withdrawalSum,
- depositSum,
- depositCount,
- countTransactions,
- pTrans) != NDBT_OK){
- return NDBT_FAILED;
- }
- // ndbout << "sumTransactionsForGL completed" << endl;
- // ndbout << "balance="<<balance<<endl
- // << "withdrawalCount="<<withdrawalCount<<endl
- // << "withdrawalSum="<<withdrawalSum<<endl
- // << "depositCount="<<depositCount<<endl
- // << "depositSum="<<depositSum<<endl;
-
-
-
- NdbOperation* pOp3 = pTrans->getNdbOperation("GL");
- if (pOp3 == NULL) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp3->updateTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp3->equal("TIME", glTime);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp3->equal("ACCOUNT_TYPE", accountTypeId);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp3->setValue("BALANCE", balance);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp3->setValue("DEPOSIT_COUNT", depositCount);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp3->setValue("DEPOSIT_SUM", depositSum);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp3->setValue("WITHDRAWAL_COUNT", withdrawalCount);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp3->setValue("WITHDRAWAL_SUM", withdrawalSum);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp3->setValue("PURGED", purged);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- // Execute transaction
- check = pTrans->execute(NoCommit);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-
-
-
-int Bank::sumTransactionsForGL(const Uint64 glTime,
- const Uint32 accountType,
- Uint32& balance,
- Uint32& withdrawalCount,
- Uint32& withdrawalSum,
- Uint32& depositSum,
- Uint32& depositCount,
- Uint32& transactionsCount,
- NdbConnection* pTrans){
- int check;
-
- // g_info << "sumTransactionsForGL: " << glTime << ", " << accountType << endl;
-
- NdbConnection* pScanTrans = m_ndb.startTransaction();
- if (pScanTrans == NULL) {
- ERR(m_ndb.getNdbError());
- return NDBT_FAILED;
- }
-
- NdbScanOperation* pOp = pScanTrans->getNdbScanOperation("TRANSACTION");
- if (pOp == NULL) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- if( pOp->readTuplesExclusive()) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- check = pOp->interpret_exit_ok();
- if( check == -1 ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* accountTypeRec = pOp->getValue("ACCOUNT_TYPE");
- if( accountTypeRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* timeRec = pOp->getValue("TIME");
- if( timeRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* transTypeRec = pOp->getValue("TRANSACTION_TYPE");
- if( transTypeRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* amountRec = pOp->getValue("AMOUNT");
- if( amountRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- check = pScanTrans->execute(NoCommit);
- if( check == -1 ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- int eof;
- int rows = 0;
- int rowsFound = 0;
- eof = pOp->nextResult();
-
- while(eof == 0){
- rows++;
- Uint32 a = accountTypeRec->u_32_value();
- Uint64 t = timeRec->u_64_value();
-
- if (a == accountType && t == glTime){
- rowsFound++;
- // One record found
- int transType = transTypeRec->u_32_value();
- int amount = amountRec->u_32_value();
- if (transType == WithDrawal){
- withdrawalCount++;
- withdrawalSum += amount;
- balance -= amount;
- } else {
- assert(transType == Deposit);
- depositCount++;
- depositSum += amount;
- balance += amount;
- }
- }
-
- eof = pOp->nextResult();
-
- if ((rows % 100) == 0){
- // "refresh" ownner transaction every 100th row
- if (pTrans->refresh() == -1) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
- }
-
- }
- if (eof == -1) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- m_ndb.closeTransaction(pScanTrans);
- // ndbout << rows << " TRANSACTIONS have been read" << endl;
- transactionsCount = rowsFound;
-
- return NDBT_OK;
-
-}
-
- int Bank::performValidateGLs(Uint64 age){
-
- Uint64 currTime;
- if (getCurrTime(currTime) != NDBT_OK){
- return NDBT_FAILED;
- }
- Uint64 glTime = currTime - 1;
- while((glTime > 0) && ((glTime + age) >= currTime)){
-
- int result = performValidateGL(glTime);
- if (result != NDBT_OK){
- g_err << "performValidateGL failed" << endl;
- return result;
- }
-
- glTime--;
- }
-
- return NDBT_OK;
- }
-
-int Bank::performValidateGL(Uint64 glTime){
-
- ndbout << "performValidateGL: " << glTime << endl;
- /**
- * Rules:
- * - There should be zero or NoAccountTypes GL records for each glTime
- * - If purged == 0, then the TRANSACTION table should be checked
- * to see that there are:
- * + DEPOSIT_COUNT deposit transactions with account_type == ACCOUNT_TYPE
- * and TIME == glTime. The sum of these transactions should be
- * DEPOSIT_SUM
- * + WITHDRAWAL_COUNT withdrawal transactions with account_type ==
- * ACCOUNT_TYPE and TIME == glTime. The sum of these transactions
- * should be WITHDRAWAL_SUM
- * + BALANCE should be equal to the sum of all transactions plus
- * the balance of the previous GL record
- * - If purged == 1 then there should be NO transactions with TIME == glTime
- * and ACCOUNT_TYPE == account_type
- *
- */
-
- int check;
- /**
- * SELECT * FROM GL WHERE account_type = @accountType and time = @time
- */
- NdbConnection* pScanTrans = m_ndb.startTransaction();
- if (pScanTrans == NULL) {
- ERR(m_ndb.getNdbError());
- return NDBT_FAILED;
- }
-
- NdbScanOperation* pOp = pScanTrans->getNdbScanOperation("GL");
- if (pOp == NULL) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- if( pOp->readTuples() ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- check = pOp->interpret_exit_ok();
- if( check == -1 ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* accountTypeRec = pOp->getValue("ACCOUNT_TYPE");
- if( accountTypeRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* timeRec = pOp->getValue("TIME");
- if( timeRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* purgedRec = pOp->getValue("PURGED");
- if( purgedRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* balanceRec = pOp->getValue("BALANCE");
- if( balanceRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* depositSumRec = pOp->getValue("DEPOSIT_SUM");
- if( depositSumRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* depositCountRec = pOp->getValue("DEPOSIT_COUNT");
- if( depositCountRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* withdrawalSumRec = pOp->getValue("WITHDRAWAL_SUM");
- if( withdrawalSumRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
- NdbRecAttr* withdrawalCountRec = pOp->getValue("WITHDRAWAL_COUNT");
- if( withdrawalCountRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- check = pScanTrans->execute(NoCommit);
- if( check == -1 ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- int eof;
- int rows = 0;
- int countGlRecords = 0;
- int result = NDBT_OK;
- eof = pOp->nextResult();
-
- while(eof == 0){
- rows++;
- Uint64 t = timeRec->u_64_value();
-
- if (t == glTime){
- countGlRecords++;
- Uint32 a = accountTypeRec->u_32_value();
- Uint32 purged = purgedRec->u_32_value();
- Uint32 wsum = withdrawalSumRec->u_32_value();
- Uint32 wcount = withdrawalCountRec->u_32_value();
- Uint32 dsum = depositSumRec->u_32_value();
- Uint32 dcount = depositCountRec->u_32_value();
- Uint32 b = balanceRec->u_32_value();
-
- Uint32 balance = 0;
- Uint32 withdrawalSum = 0;
- Uint32 withdrawalCount = 0;
- Uint32 depositSum = 0;
- Uint32 depositCount = 0;
- Uint32 countTransactions = 0;
- if (purged == 0){
- // If purged == 0, then the TRANSACTION table should be checked
- // to see that there are:
- // + DEPOSIT_COUNT deposit transactions with account_type == ACCOUNT_TYPE
- // and TIME == glTime. The sum of these transactions should be
- // DEPOSIT_SUM
- // + WITHDRAWAL_COUNT withdrawal transactions with account_type ==
- // ACCOUNT_TYPE and TIME == glTime. The sum of these transactions
- // should be WITHDRAWAL_SUM
- // + BALANCE should be equal to the sum of all transactions plus
- // the balance of the previous GL record
- if (sumTransactionsForGL(t,
- a,
- balance,
- withdrawalCount,
- withdrawalSum,
- depositSum,
- depositCount,
- countTransactions,
- pScanTrans) != NDBT_OK){
- result = NDBT_FAILED;
- } else {
- Uint32 prevBalance = 0;
- if (getBalanceForGL(t-1, a, prevBalance) != NDBT_OK){
- result = NDBT_FAILED;
- } else
- if (((prevBalance + balance) != b) ||
- (wsum != withdrawalSum) ||
- (wcount != withdrawalCount) ||
- (dsum != depositSum) ||
- (dcount != depositCount)){
- g_err << "performValidateGL, sums and counts failed" << endl
- << "balance : " << balance+prevBalance << "!="<<b<<endl
- << "with sum : " << withdrawalSum << "!="<<wsum<<endl
- << "with count: " << withdrawalCount << "!="<<wcount<<endl
- << "dep sum : " << depositSum << "!="<<dsum<<endl
- << "dep count : " << depositCount << "!="<<dcount<<endl;
- result = VERIFICATION_FAILED;
- }
- }
-
- } else {
- assert(purged == 1);
- // If purged == 1 then there should be NO transactions with
- // TIME == glTime and ACCOUNT_TYPE == account_type
-
- if (sumTransactionsForGL(t,
- a,
- balance,
- withdrawalCount,
- withdrawalSum,
- depositSum,
- depositCount,
- countTransactions,
- pScanTrans) != NDBT_OK){
- result = NDBT_FAILED;
- } else {
- if (countTransactions != 0){
- g_err << "performValidateGL, countTransactions("<<countTransactions<<") != 0" << endl;
- result = VERIFICATION_FAILED;
- }
- }
- }
-
- }
- eof = pOp->nextResult();
- }
- if (eof == -1) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- m_ndb.closeTransaction(pScanTrans);
-
- // - There should be zero or NoAccountTypes GL records for each glTime
- if ((countGlRecords != 0) && (countGlRecords != getNumAccountTypes())){
- g_err << "performValidateGL: " << endl
- << "countGlRecords = " << countGlRecords << endl;
- result = VERIFICATION_FAILED;
- }
-
- return result;
-
-
- }
-
-int Bank::getBalanceForGL(const Uint64 glTime,
- const Uint32 accountTypeId,
- Uint32 &balance){
- int check;
-
- NdbConnection* pTrans = m_ndb.startTransaction();
- if (pTrans == NULL) {
- ERR(m_ndb.getNdbError());
- return NDBT_FAILED;
- }
-
- NdbOperation* pOp = pTrans->getNdbOperation("GL");
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp->readTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp->equal("TIME", glTime);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp->equal("ACCOUNT_TYPE", accountTypeId);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- NdbRecAttr* balanceRec = pOp->getValue("BALANCE");
- if( balanceRec == NULL ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pTrans->execute(Commit);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- m_ndb.closeTransaction(pTrans);
-
- balance = balanceRec->u_32_value();
-
- return NDBT_OK;
-}
-
-
-
-int Bank::getOldestPurgedGL(const Uint32 accountType,
- Uint64 &oldest){
- int check;
- /**
- * SELECT MAX(time) FROM GL WHERE account_type = @accountType and purged=1
- */
- NdbConnection* pScanTrans = 0;
- do
- {
- pScanTrans = m_ndb.startTransaction();
- if (pScanTrans == NULL) {
- ERR(m_ndb.getNdbError());
- return NDBT_FAILED;
- }
-
- NdbScanOperation* pOp = pScanTrans->getNdbScanOperation("GL");
- if (pOp == NULL) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- if( pOp->readTuples() ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- check = pOp->interpret_exit_ok();
- if( check == -1 ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* accountTypeRec = pOp->getValue("ACCOUNT_TYPE");
- if( accountTypeRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* timeRec = pOp->getValue("TIME");
- if( timeRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* purgedRec = pOp->getValue("PURGED");
- if( purgedRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- check = pScanTrans->execute(NoCommit);
- if( check == -1 ) {
- NdbError err = pScanTrans->getNdbError();
- ERR(err);
- m_ndb.closeTransaction(pScanTrans);
- if (err.status == NdbError::TemporaryError)
- {
- NdbSleep_MilliSleep(50);
- continue;
- }
- return NDBT_FAILED;
- }
-
- int eof;
- int rows = 0;
- eof = pOp->nextResult();
- oldest = 0;
-
- while(eof == 0){
- rows++;
- Uint32 a = accountTypeRec->u_32_value();
- Uint32 p = purgedRec->u_32_value();
-
- if (a == accountType && p == 1){
- // One record found
- Uint64 t = timeRec->u_64_value();
- if (t > oldest)
- oldest = t;
- }
- eof = pOp->nextResult();
- }
- if (eof == -1)
- {
- NdbError err = pScanTrans->getNdbError();
- ERR(err);
- m_ndb.closeTransaction(pScanTrans);
-
- if (err.status == NdbError::TemporaryError)
- {
- NdbSleep_MilliSleep(50);
- continue;
- }
- return NDBT_FAILED;
- }
- break;
- } while(true);
-
- m_ndb.closeTransaction(pScanTrans);
-
- return NDBT_OK;
-}
-
-int Bank::getOldestNotPurgedGL(Uint64 &oldest,
- Uint32 &accountTypeId,
- bool &found){
- int check;
- /**
- * SELECT time, accountTypeId FROM GL
- * WHERE purged=0 order by time asc
- */
- NdbConnection* pScanTrans = m_ndb.startTransaction();
- if (pScanTrans == NULL) {
- ERR(m_ndb.getNdbError());
- return NDBT_FAILED;
- }
-
- NdbScanOperation* pOp = pScanTrans->getNdbScanOperation("GL");
- if (pOp == NULL) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- if( pOp->readTuples() ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- check = pOp->interpret_exit_ok();
- if( check == -1 ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* accountTypeRec = pOp->getValue("ACCOUNT_TYPE");
- if( accountTypeRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* timeRec = pOp->getValue("TIME");
- if( timeRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* purgedRec = pOp->getValue("PURGED");
- if( purgedRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- check = pScanTrans->execute(NoCommit);
- if( check == -1 ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- int eof;
- int rows = 0;
- eof = pOp->nextResult();
- oldest = (Uint64)-1;
- found = false;
-
- while(eof == 0){
- rows++;
- Uint32 p = purgedRec->u_32_value();
- if (p == 0){
- found = true;
- // One record found
- Uint32 a = accountTypeRec->u_32_value();
- Uint64 t = timeRec->u_64_value();
- if (t < oldest){
- oldest = t;
- accountTypeId = a;
- }
- }
- eof = pOp->nextResult();
- }
- if (eof == -1) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- m_ndb.closeTransaction(pScanTrans);
-
- return NDBT_OK;
-}
-
-
-int Bank::checkNoTransactionsOlderThan(const Uint32 accountType,
- const Uint64 oldest){
- /**
- * SELECT COUNT(transaction_id) FROM TRANSACTION
- * WHERE account_type = @accountType and time <= @oldest
- *
- */
-
- int loop = 0;
- int found = 0;
- NdbConnection* pScanTrans = 0;
- do {
- int check;
- loop++;
- pScanTrans = m_ndb.startTransaction();
- if (pScanTrans == NULL) {
- ERR(m_ndb.getNdbError());
- return NDBT_FAILED;
- }
-
- NdbScanOperation* pOp = pScanTrans->getNdbScanOperation("TRANSACTION");
- if (pOp == NULL) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- if( pOp->readTuples() ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- check = pOp->interpret_exit_ok();
- if( check == -1 ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* accountTypeRec = pOp->getValue("ACCOUNT_TYPE");
- if( accountTypeRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* timeRec = pOp->getValue("TIME");
- if( timeRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* transactionIdRec = pOp->getValue("TRANSACTION_ID");
- if( transactionIdRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- check = pScanTrans->execute(NoCommit);
- if( check == -1 ) {
- NdbError err = pScanTrans->getNdbError();
- ERR(err);
- m_ndb.closeTransaction(pScanTrans);
-
- if (err.status == NdbError::TemporaryError)
- {
- NdbSleep_MilliSleep(50);
- continue;
- }
- return NDBT_FAILED;
- }
-
- int eof;
- int rows = 0;
- found = 0;
- eof = pOp->nextResult();
-
- while(eof == 0){
- rows++;
- Uint32 a = accountTypeRec->u_32_value();
- Uint32 t = timeRec->u_32_value();
-
- if (a == accountType && t <= oldest){
- // One record found
- Uint64 ti = transactionIdRec->u_64_value();
- g_err << "checkNoTransactionsOlderThan found one record" << endl
- << " t = " << t << endl
- << " a = " << a << endl
- << " ti = " << ti << endl;
- found++;
- }
- eof = pOp->nextResult();
- }
- if (eof == -1) {
- NdbError err = pScanTrans->getNdbError();
- ERR(err);
- m_ndb.closeTransaction(pScanTrans);
-
- if (err.status == NdbError::TemporaryError)
- {
- NdbSleep_MilliSleep(50);
- continue;
- }
-
- return NDBT_FAILED;
- }
-
- break;
- } while(true);
-
- m_ndb.closeTransaction(pScanTrans);
-
- if (found == 0)
- return NDBT_OK;
- else
- return VERIFICATION_FAILED;
-}
-
-
- int Bank::performValidatePurged(){
- /**
- * Make sure there are no TRANSACTIONS older than the oldest
- * purged GL record
- *
- */
-
- for (int i = 0; i < getNumAccountTypes(); i++){
- ndbout << "performValidatePurged: " << i << endl;
- Uint64 oldestGlTime;
- if (getOldestPurgedGL(i, oldestGlTime) != NDBT_OK){
- g_err << "getOldestPurgedGL failed" << endl;
- return NDBT_FAILED;
- }
- int result = checkNoTransactionsOlderThan(i, oldestGlTime);
- if (result != NDBT_OK){
- g_err << "checkNoTransactionsOlderThan failed" << endl;
- return result;
- }
-
- }
-
- return NDBT_OK;
- }
-
- int Bank::purgeOldGLTransactions(Uint64 currTime, Uint32 age){
- /**
- * For each GL record that are older than age and have purged == 0
- * - delete all TRANSACTIONS belonging to the GL and set purged = 1
- *
- *
- */
- bool found;
- int count = 0;
-
- while(1){
- count++;
- if (count > 100)
- return NDBT_OK;
-
- // Search for the oldest GL record with purged == 0
- Uint64 oldestGlTime;
- Uint32 accountTypeId;
- if (getOldestNotPurgedGL(oldestGlTime, accountTypeId, found) != NDBT_OK){
- g_err << "getOldestNotPurgedGL failed" << endl;
- return NDBT_FAILED;
- }
-
-
- if (found == false){
- // ndbout << "not found" << endl;
- return NDBT_OK;
- }
-
-
-// ndbout << "purgeOldGLTransactions" << endl
-// << " oldestGlTime = " << oldestGlTime << endl
-// << " currTime = " << currTime << endl
-// << " age = " << age << endl;
- // Check if this GL is old enough to be purged
- if ((currTime < age) || (oldestGlTime > (currTime-age))){
- // ndbout << "is not old enough" << endl;
- return NDBT_OK;
- }
-
- if (purgeTransactions(oldestGlTime, accountTypeId) != NDBT_OK){
- g_err << "purgeTransactions failed" << endl;
- return NDBT_FAILED;
- }
- }
- g_err << "abnormal return" << endl;
- return NDBT_FAILED;
- }
-
-
-int Bank::purgeTransactions(const Uint64 glTime,
- const Uint32 accountTypeId)
-{
- int check;
- g_info << "purgeTransactions: " << glTime << ", "<<accountTypeId<<endl;
- NdbConnection* pTrans = m_ndb.startTransaction();
- if (pTrans == NULL){
- ERR(m_ndb.getNdbError());
- return NDBT_FAILED;
- }
-
- // Start by updating the GL record with purged = 1, use NoCommit
- NdbOperation* pOp = pTrans->getNdbOperation("GL");
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp->updateTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp->equal("TIME", glTime);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp->equal("ACCOUNT_TYPE", accountTypeId);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- Uint32 purged = 1;
- check = pOp->setValue("PURGED", purged);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- // Execute transaction
- check = pTrans->execute(NoCommit);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- // Find all transactions and take over them for delete
-
- if(findTransactionsToPurge(glTime,
- accountTypeId,
- pTrans) != NDBT_OK){
- g_err << "findTransactionToPurge failed" << endl;
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
-
-
- check = pTrans->execute(Commit);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- m_ndb.closeTransaction(pTrans);
- return NDBT_OK;
-}
-
-
-int Bank::findTransactionsToPurge(const Uint64 glTime,
- const Uint32 accountType,
- NdbConnection* pTrans){
- int check;
-
- NdbConnection* pScanTrans = m_ndb.startTransaction();
- if (pScanTrans == NULL) {
- ERR(m_ndb.getNdbError());
- return NDBT_FAILED;
- }
-
- NdbScanOperation* pOp = pScanTrans->getNdbScanOperation("TRANSACTION");
- if (pOp == NULL) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- if( pOp->readTuplesExclusive() ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- check = pOp->interpret_exit_ok();
- if( check == -1 ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* timeRec = pOp->getValue("TIME");
- if( timeRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* accountTypeRec = pOp->getValue("ACCOUNT_TYPE");
- if( accountTypeRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- check = pScanTrans->execute(NoCommit);
- if( check == -1 ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- int eof;
- int rows = 0;
- int rowsFound = 0;
- eof = pOp->nextResult();
-
- while(eof == 0){
- rows++;
- Uint64 t = timeRec->u_64_value();
- Uint32 a = accountTypeRec->u_32_value();
-
- if (a == accountType && t == glTime){
- rowsFound++;
- // One record found
- check = pOp->deleteCurrentTuple(pTrans);
- if (check == -1){
- ERR(m_ndb.getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- // Execute transaction
- check = pTrans->execute(NoCommit);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
- }
- eof = pOp->nextResult();
- }
- if (eof == -1) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- m_ndb.closeTransaction(pScanTrans);
- // ndbout << rowsFound << " TRANSACTIONS have been deleted" << endl;
-
- return NDBT_OK;
-
-}
-
-
-int Bank::performIncreaseTime(int maxSleepBetweenDays, int yield)
-{
- int yieldCounter = 0;
-
- while(1){
-
- Uint64 currTime;
- if (incCurrTime(currTime) != NDBT_OK)
- break;
-
- g_info << "Current time is " << currTime << endl;
- if (maxSleepBetweenDays > 0){
- int val = myRandom48(maxSleepBetweenDays);
- NdbSleep_SecSleep(val);
- }
-
- yieldCounter++;
- if (yield != 0 && yieldCounter >= yield)
- return NDBT_OK;
-
- }
- return NDBT_FAILED;
-}
-
-int Bank::readSystemValue(SystemValueId sysValId, Uint64 & value){
-
- int check;
- NdbConnection* pTrans = 0;
- while (true)
- {
- pTrans = m_ndb.startTransaction();
- if (pTrans == NULL)
- {
- ERR(m_ndb.getNdbError());
- if(m_ndb.getNdbError().status == NdbError::TemporaryError)
- {
- NdbSleep_MilliSleep(50);
- continue;
- }
- return NDBT_FAILED;
- }
-
- int result;
- if ((result= prepareReadSystemValueOp(pTrans, sysValId, value)) != NDBT_OK)
- {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return result;
- }
-
- check = pTrans->execute(Commit);
- if( check == -1 ) {
- NdbError err = pTrans->getNdbError();
- m_ndb.closeTransaction(pTrans);
- ERR(err);
- if(err.status == NdbError::TemporaryError)
- {
- NdbSleep_MilliSleep(50);
- continue;
- }
- return NDBT_FAILED;
- }
-
- break;
- }
-
- m_ndb.closeTransaction(pTrans);
- return NDBT_OK;
-
-}
-
-int Bank::prepareReadSystemValueOp(NdbConnection* pTrans, SystemValueId sysValId, Uint64 & value){
-
- int check;
-
- NdbOperation* pOp = pTrans->getNdbOperation("SYSTEM_VALUES");
- if (pOp == NULL) {
- return NDBT_FAILED;
- }
-
- check = pOp->readTuple();
- if( check == -1 ) {
- return NDBT_FAILED;
- }
-
- check = pOp->equal("SYSTEM_VALUES_ID", sysValId);
- if( check == -1 ) {
- return NDBT_FAILED;
- }
-
- NdbRecAttr* valueRec = pOp->getValue("VALUE", (char *)&value);
- if( valueRec == NULL ) {
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-int Bank::writeSystemValue(SystemValueId sysValId, Uint64 value){
-
- int check;
-
- NdbConnection* pTrans = m_ndb.startTransaction();
- if (pTrans == NULL){
- ERR(m_ndb.getNdbError());
- return NDBT_FAILED;
- }
-
- NdbOperation* pOp = pTrans->getNdbOperation("SYSTEM_VALUES");
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp->insertTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp->equal("SYSTEM_VALUES_ID", sysValId);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp->setValue("VALUE", value);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pTrans->execute(Commit);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- m_ndb.closeTransaction(pTrans);
- return NDBT_OK;
-
-}
-
-int Bank::getNextTransactionId(Uint64 &value){
- return increaseSystemValue2(LastTransactionId, value);
-}
-
-int Bank::incCurrTime(Uint64 &value){
- return increaseSystemValue(CurrentTime, value);
-}
-
-
-int Bank::increaseSystemValue(SystemValueId sysValId, Uint64 &value){
- /**
- * Increase value with one and return
- * updated value
- *
- */
-
- DBUG_ENTER("Bank::increaseSystemValue");
-
- int check;
-
- NdbConnection* pTrans = m_ndb.startTransaction();
- if (pTrans == NULL){
- ERR(m_ndb.getNdbError());
- if (m_ndb.getNdbError().status == NdbError::TemporaryError)
- DBUG_RETURN(NDBT_TEMPORARY);
- DBUG_RETURN(NDBT_FAILED);
- }
-
- NdbOperation* pOp = pTrans->getNdbOperation("SYSTEM_VALUES");
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- DBUG_RETURN(NDBT_FAILED);
- }
-
- check = pOp->readTupleExclusive();
- // check = pOp->readTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- DBUG_RETURN(NDBT_FAILED);
- }
-
- check = pOp->equal("SYSTEM_VALUES_ID", sysValId);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- DBUG_RETURN(NDBT_FAILED);
- }
-
- NdbRecAttr* valueRec = pOp->getValue("VALUE");
- if( valueRec ==NULL ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- DBUG_RETURN(NDBT_FAILED);
- }
-
- check = pTrans->execute(NoCommit);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- if (pTrans->getNdbError().status == NdbError::TemporaryError)
- {
- m_ndb.closeTransaction(pTrans);
- DBUG_RETURN(NDBT_TEMPORARY);
- }
- m_ndb.closeTransaction(pTrans);
- DBUG_RETURN(NDBT_FAILED);
- }
-
- value = valueRec->u_64_value();
- value++;
-
- NdbOperation* pOp2 = pTrans->getNdbOperation("SYSTEM_VALUES");
- if (pOp2 == NULL) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- DBUG_RETURN(NDBT_FAILED);
- }
-
- check = pOp2->updateTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- DBUG_RETURN(NDBT_FAILED);
- }
-
- check = pOp2->equal("SYSTEM_VALUES_ID", sysValId);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- DBUG_RETURN(NDBT_FAILED);
- }
-
- check = pOp2->setValue("VALUE", value);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- DBUG_RETURN(NDBT_FAILED);
- }
-
- check = pTrans->execute(NoCommit);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- DBUG_RETURN(NDBT_FAILED);
- }
-
- NdbOperation* pOp3 = pTrans->getNdbOperation("SYSTEM_VALUES");
- if (pOp3 == NULL) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- DBUG_RETURN(NDBT_FAILED);
- }
-
- check = pOp3->readTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- DBUG_RETURN(NDBT_FAILED);
- }
-
- check = pOp3->equal("SYSTEM_VALUES_ID", sysValId);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- DBUG_RETURN(NDBT_FAILED);
- }
-
- // Read new value
- NdbRecAttr* valueNewRec = pOp3->getValue("VALUE");
- if( valueNewRec ==NULL ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- DBUG_RETURN(NDBT_FAILED);
- }
-
- check = pTrans->execute(Commit);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- if (pTrans->getNdbError().status == NdbError::TemporaryError)
- {
- m_ndb.closeTransaction(pTrans);
- DBUG_RETURN(NDBT_TEMPORARY);
- }
- m_ndb.closeTransaction(pTrans);
- DBUG_RETURN(NDBT_FAILED);
- }
-
- // Check that value updated equals the value we read after the update
- if (valueNewRec->u_64_value() != value){
-
- printf("value actual=%lld\n", valueNewRec->u_64_value());
- printf("value expected=%lld actual=%lld\n", value, valueNewRec->u_64_value());
-
- DBUG_PRINT("info", ("value expected=%ld actual=%ld", value, valueNewRec->u_64_value()));
- g_err << "getNextTransactionId: value was not updated" << endl;
- m_ndb.closeTransaction(pTrans);
- DBUG_RETURN(NDBT_FAILED);
- }
-
- m_ndb.closeTransaction(pTrans);
-
- DBUG_RETURN(0);
-}
-
-int Bank::increaseSystemValue2(SystemValueId sysValId, Uint64 &value){
- /**
- * Increase value with one and return
- * updated value
- * A more optimized version using interpreted update!
- *
- */
-
- int check;
-
- NdbConnection* pTrans = m_ndb.startTransaction();
- if (pTrans == NULL){
- ERR(m_ndb.getNdbError());
- if(m_ndb.getNdbError().status == NdbError::TemporaryError)
- return NDBT_TEMPORARY;
- return NDBT_FAILED;
- }
-
- NdbOperation* pOp = pTrans->getNdbOperation("SYSTEM_VALUES");
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp->interpretedUpdateTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp->equal("SYSTEM_VALUES_ID", sysValId );
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- Uint32 valToIncWith = 1;
- check = pOp->incValue("VALUE", valToIncWith);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* valueRec = pOp->getValue("VALUE");
- if( valueRec == NULL ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pTrans->execute(Commit);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- if(pTrans->getNdbError().status == NdbError::TemporaryError)
- {
- m_ndb.closeTransaction(pTrans);
- return NDBT_TEMPORARY;
- }
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- value = valueRec->u_64_value();
-
- m_ndb.closeTransaction(pTrans);
-
- return 0;
-
-}
-
-
-
-int Bank::getCurrTime(Uint64 &time){
- return readSystemValue(CurrentTime, time);
-}
-
-int Bank::prepareGetCurrTimeOp(NdbConnection *pTrans, Uint64 &time){
- return prepareReadSystemValueOp(pTrans, CurrentTime, time);
-}
-
-
-int Bank::performSumAccounts(int maxSleepBetweenSums, int yield){
-
- int yieldCounter = 0;
-
- while (1){
-
- Uint32 sumAccounts = 0;
- Uint32 numAccounts = 0;
- if (getSumAccounts(sumAccounts, numAccounts) != NDBT_OK){
- g_err << "getSumAccounts FAILED" << endl;
- } else {
-
- g_info << "num="<<numAccounts<<", sum=" << sumAccounts << endl;
-
- if (sumAccounts != (10000000 + (10000*(numAccounts-1)))){
- g_err << "performSumAccounts FAILED" << endl
- << " sumAccounts="<<sumAccounts<<endl
- << " expected ="<<(10000000 + (10000*(numAccounts-1)))<<endl
- << " numAccounts="<<numAccounts<<endl;
- return NDBT_FAILED;
- }
-
- if (maxSleepBetweenSums > 0){
- int val = myRandom48(maxSleepBetweenSums);
- NdbSleep_MilliSleep(val);
- }
- }
-
- yieldCounter++;
- if (yield != 0 && yieldCounter >= yield)
- return NDBT_OK;
- }
- return NDBT_FAILED;
-}
-
-
-int Bank::getSumAccounts(Uint32 &sumAccounts,
- Uint32 &numAccounts){
-
- // SELECT SUM(balance) FROM ACCOUNT
-
- int check;
- NdbConnection* pScanTrans = m_ndb.startTransaction();
- if (pScanTrans == NULL) {
- ERR(m_ndb.getNdbError());
- return NDBT_FAILED;
- }
-
- NdbScanOperation* pOp = pScanTrans->getNdbScanOperation("ACCOUNT");
- if (pOp == NULL) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- if( pOp->readTuplesExclusive() ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- check = pOp->interpret_exit_ok();
- if( check == -1 ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* balanceRec = pOp->getValue("BALANCE");
- if( balanceRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- check = pScanTrans->execute(NoCommit);
- if( check == -1 ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbConnection* pTrans = m_ndb.startTransaction();
- if (pTrans == NULL) {
- ERR(m_ndb.getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- int eof;
- eof = pOp->nextResult();
-
- while(eof == 0){
- Uint32 b = balanceRec->u_32_value();
-
- sumAccounts += b;
- numAccounts++;
-
- // ndbout << numAccounts << ": balance =" << b
- // << ", sum="<< sumAccounts << endl;
-
- // Take over the operation so that the lock is kept in db
- NdbOperation* pLockOp = pOp->updateCurrentTuple(pTrans);
- if (pLockOp == NULL){
- ERR(m_ndb.getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- Uint32 illegalBalance = 99;
- check = pLockOp->setValue("BALANCE", illegalBalance);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- // Execute transaction
- check = pTrans->execute(NoCommit);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- eof = pOp->nextResult();
- }
- if (eof == -1) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- // TODO Forget about rolling back, just close pTrans!!
-
- // Rollback transaction
- check = pTrans->execute(Rollback);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- m_ndb.closeTransaction(pScanTrans);
- m_ndb.closeTransaction(pTrans);
-
-
- return NDBT_OK;
-
-}
diff --git a/storage/ndb/test/ndbapi/bank/Bank.hpp b/storage/ndb/test/ndbapi/bank/Bank.hpp
deleted file mode 100644
index 17e5c1b93ce..00000000000
--- a/storage/ndb/test/ndbapi/bank/Bank.hpp
+++ /dev/null
@@ -1,147 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef BANK_HPP
-#define BANK_HPP
-
-#include <NdbOut.hpp>
-#include <NdbApi.hpp>
-#include <NDBT.hpp>
-#include <NdbTick.h>
-#include <random.h>
-
-
-class Bank {
-public:
-
- Bank(Ndb_cluster_connection&, bool init = true, const char *dbase="BANK");
-
- void setSkipCreate(bool skip) { m_skip_create = skip; }
- int createAndLoadBank(bool overWrite, bool disk= false, int num_accounts=10);
- int dropBank();
-
- int performTransactions(int maxSleepBetweenTrans = 20, int yield=0);
- int performMakeGLs(int yield=0);
- int performValidateAllGLs();
- int performSumAccounts(int maxSleepBetweenSums = 2000, int yield=0);
- int performIncreaseTime(int maxSleepBetweenDays = 30, int yield=0);
-private:
-
- int init();
-
- enum TransactionTypes{
- WithDrawal = 2000,
- Deposit = 3000
- };
-
- static const int NOT_ENOUGH_FUNDS = 1000;
- static const int VERIFICATION_FAILED = 1001;
-
- int performTransaction();
- int performTransaction(int fromAccountId,
- int toAccountId,
- int amount );
- int performTransactionImpl1(int fromAccountId,
- int toAccountId,
- int amount );
-
- int performValidateGLs(Uint64 age = 20);
- int performValidateGL(Uint64 GLTime);
- int performValidatePurged();
-
- int performMakeGL(int time);
- int performMakeGLForAccountType(NdbConnection* pTrans,
- Uint64 time,
- Uint32 accountTypeId);
- int sumTransactionsForGL(const Uint64 time,
- const Uint32 accountType,
- Uint32& balance,
- Uint32& withdrawalCount,
- Uint32& withdrawalSum,
- Uint32& depositSum,
- Uint32& depositCount,
- Uint32& transactionsCount,
- NdbConnection* pTrans);
- int getBalanceForAccountType(const Uint32 accountType,
- Uint32& balance);
- int getBalanceForGL(const Uint64 glTime,
- const Uint32 accountType,
- Uint32 &balance);
-
- int checkNoTransactionsOlderThan(const Uint32 accountType,
- const Uint64 oldest);
- int getOldestPurgedGL(const Uint32 accountType,
- Uint64 &oldest);
- int getOldestNotPurgedGL(Uint64 &oldest,
- Uint32 &accountTypeId,
- bool &found);
- int findLastGL(Uint64 &lastTime);
- int purgeOldGLTransactions(Uint64 currTime, Uint32 age);
-
- int purgeTransactions(const Uint64 glTime,
- const Uint32 accountTypeId);
- int findTransactionsToPurge(const Uint64 glTime,
- const Uint32 accountType,
- NdbConnection* pTrans);
-
-
- int getSumAccounts(Uint32 &sumAccounts,
- Uint32 &numAccounts);
- int getNumAccounts();
- int getNumAccountTypes();
- int getMaxAmount();
-
-
- enum SystemValueId {
- LastTransactionId = 0,
- CurrentTime = 1
- };
-
-
- int readSystemValue(SystemValueId sysValId, Uint64 & value);
- int increaseSystemValue(SystemValueId sysValId, Uint64 &value);
- int increaseSystemValue2(SystemValueId sysValId, Uint64 &value);
- int writeSystemValue(SystemValueId sysValId, Uint64 value);
- int getNextTransactionId(Uint64 &value);
- int incCurrTime(Uint64 &value);
- int getCurrTime(Uint64 &time);
-
- int prepareReadSystemValueOp(NdbConnection*, SystemValueId sysValId, Uint64 &time);
- int prepareGetCurrTimeOp(NdbConnection*, Uint64 &time);
-
- int createTables(bool disk);
- int createTable(const char* tabName, bool disk);
-
- int dropTables();
- int dropTable(const char* tabName);
-
- int clearTables();
- int clearTable(const char* tabName);
-
- int loadGl();
- int loadAccountType();
- int loadAccount (int numAccounts);
- int loadSystemValues();
-
-private:
-
- Ndb m_ndb;
- int m_maxAccount;
- bool m_initialized;
- bool m_skip_create;
-};
-
-#endif
diff --git a/storage/ndb/test/ndbapi/bank/BankLoad.cpp b/storage/ndb/test/ndbapi/bank/BankLoad.cpp
deleted file mode 100644
index 7ab318f9026..00000000000
--- a/storage/ndb/test/ndbapi/bank/BankLoad.cpp
+++ /dev/null
@@ -1,602 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include "Bank.hpp"
-#include <UtilTransactions.hpp>
-
-/**
- * Default account types
- *
- */
-struct AccountTypesStruct {
- int id;
- const char descr[64];
-};
-const AccountTypesStruct accountTypes[] = {
- { 0, "KASSA"},
- { 1, "BANKOMAT"},
- { 2, "POSTGIRO"},
- { 3, "LÖNEKONTO"},
- { 4, "SPARKONTO"}
-};
-
-const int
-accountTypesSize = sizeof(accountTypes)/sizeof(AccountTypesStruct);
-
-
-const char* tableNames[] = {
- "GL",
- "ACCOUNT",
- "SYSTEM_VALUES",
- "TRANSACTION",
- "ACCOUNT_TYPE"
-};
-
-const int
-tableNamesSize = sizeof(tableNames)/sizeof(const char*);
-
-
-int Bank::getNumAccountTypes(){
- return accountTypesSize;
-}
-
-int Bank::createAndLoadBank(bool ovrWrt, bool disk, int num_accounts){
-
- m_ndb.init();
- if (m_ndb.waitUntilReady() != 0)
- return NDBT_FAILED;
-
- const NdbDictionary::Table* pSysValTab =
- m_ndb.getDictionary()->getTable("SYSTEM_VALUES");
- if (pSysValTab != NULL){
- // The table exists
- if (ovrWrt == false){
- ndbout << "Bank already exist and overwrite == false" << endl;
- return NDBT_FAILED;
- }
- }
-
- if (!m_skip_create && createTables(disk) != NDBT_OK)
- return NDBT_FAILED;
-
- if (clearTables() != NDBT_OK)
- return NDBT_FAILED;
-
- if (loadAccountType() != NDBT_OK)
- return NDBT_FAILED;
-
- if (loadAccount(num_accounts) != NDBT_OK)
- return NDBT_FAILED;
-
- if (loadSystemValues() != NDBT_OK)
- return NDBT_FAILED;
-
- if (loadGl() != NDBT_OK)
- return NDBT_FAILED;
-
- return NDBT_OK;
-
-}
-
-int Bank::dropBank(){
-
- m_ndb.init();
- if (m_ndb.waitUntilReady() != 0)
- return NDBT_FAILED;
-
- if (dropTables() != NDBT_OK)
- return NDBT_FAILED;
-
- return NDBT_OK;
-
-}
-
-int Bank::createTables(bool disk){
- for (int i = 0; i < tableNamesSize; i++){
- if (createTable(tableNames[i], disk) != NDBT_OK)
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-
-int Bank::dropTables(){
- for (int i = 0; i < tableNamesSize; i++){
- if (dropTable(tableNames[i]) != NDBT_OK)
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int Bank::clearTables(){
- for (int i = 0; i < tableNamesSize; i++){
- if (clearTable(tableNames[i]) != NDBT_OK)
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int Bank::clearTable(const char* tabName){
- UtilTransactions util(&m_ndb, tabName);
- if(util.clearTable(&m_ndb, 64) != 0)
- return NDBT_FAILED;
- return NDBT_OK;
-}
-
-int Bank::createTable(const char* tabName, bool disk){
- ndbout << "createTable " << tabName << endl;
-
- const NdbDictionary::Table* pTab = NDBT_Tables::getTable(tabName);
- if (pTab == NULL)
- return NDBT_FAILED;
-
- const NdbDictionary::Table* org =
- m_ndb.getDictionary()->getTable(tabName);
-
- if (org != 0 && (disk || pTab->equal(* org)))
- {
- return NDBT_OK;
- }
-
- if (org != 0){
- ndbout << "Different table with same name exists" << endl;
- return NDBT_FAILED;
- }
-
- if (disk)
- {
- if (NDBT_Tables::create_default_tablespace(&m_ndb))
- {
- ndbout << "Failed to create tablespaces" << endl;
- return NDBT_FAILED;
- }
- NdbDictionary::Table copy(* pTab);
- copy.setTablespaceName("DEFAULT-TS");
- for (Uint32 i = 0; i<copy.getNoOfColumns(); i++)
- copy.getColumn(i)->setStorageType(NdbDictionary::Column::StorageTypeDisk);
- if(m_ndb.getDictionary()->createTable(copy) == -1){
- ndbout << "Failed to create table: " <<
- m_ndb.getNdbError() << endl;
- return NDBT_FAILED;
- }
- }
- else
- {
- if(m_ndb.getDictionary()->createTable(* pTab) == -1){
- ndbout << "Failed to create table: " <<
- m_ndb.getNdbError() << endl;
- return NDBT_FAILED;
- }
- }
-
- return NDBT_OK;
-}
-
-int Bank::dropTable(const char* tabName){
- const NdbDictionary::Table* org =
- m_ndb.getDictionary()->getTable(tabName);
-
- if (org == NULL)
- return NDBT_OK;
-
- ndbout << "dropTable " <<tabName<<endl;
- if (m_ndb.getDictionary()->dropTable(tabName) != 0){
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-
-
-
-
-
-
-
-/**
- * Load SYSTEM_VALUES table
- * This table keeps track of system wide settings
- * For example:
- * - next transaction id
- *
- */
-int Bank::loadSystemValues (){
-int result;
-
-/**
- * Insert start value for next transaction id
- *
- */
-result = writeSystemValue(LastTransactionId, 0);
-
-/**
- * Insert start value for current time
- *
- */
-result = writeSystemValue(CurrentTime, 1);
-
-return result;
-
-}
-
-
-/**
- * Load GL table
- *
- * Insert GL records for time = 0 with balance 0
- */
-int Bank::loadGl(){
- g_info << "loadGl" << endl;
- int check;
-
- NdbConnection* pTrans = m_ndb.startTransaction();
- if (pTrans == NULL){
- ERR(m_ndb.getNdbError());
- return NDBT_FAILED;
- }
-
- for (int i = 0; i < getNumAccountTypes(); i++){
-
- NdbOperation* pOp = pTrans->getNdbOperation("GL");
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp->insertTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- Uint64 time = 0;
- check = pOp->equal("TIME", time);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp->equal("ACCOUNT_TYPE", i);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- Uint32 balance = 0;
- if (getBalanceForAccountType(i, balance) != NDBT_OK){
- return NDBT_FAILED;
- }
-
- check = pOp->setValue("BALANCE", balance);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- Uint32 depositCount = 0;
- check = pOp->setValue("DEPOSIT_COUNT", depositCount);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- Uint32 depositSum = 0;
- check = pOp->setValue("DEPOSIT_SUM", depositSum);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- Uint32 withdrawalCount = 0;
- check = pOp->setValue("WITHDRAWAL_COUNT", withdrawalCount);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- Uint32 withdrawalSum = 0;
- check = pOp->setValue("WITHDRAWAL_SUM", withdrawalSum);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- Uint32 purged = 1;
- check = pOp->setValue("PURGED", purged);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- }
- check = pTrans->execute(Commit);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- m_ndb.closeTransaction(pTrans);
- return NDBT_OK;
-}
-
-
-int Bank::getBalanceForAccountType(const Uint32 accountType,
- Uint32& balance){
- int check;
- g_info << "getBalanceForAccountType: accountType="<<accountType<<endl;
-
- NdbConnection* pScanTrans = m_ndb.startTransaction();
- if (pScanTrans == NULL) {
- ERR(m_ndb.getNdbError());
- return NDBT_FAILED;
- }
-
- NdbScanOperation* pOp = pScanTrans->getNdbScanOperation("ACCOUNT");
- if (pOp == NULL) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- if( pOp->readTuples() ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- check = pOp->interpret_exit_ok();
- if( check == -1 ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* accountTypeRec = pOp->getValue("ACCOUNT_TYPE");
- if( accountTypeRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* balanceRec = pOp->getValue("BALANCE");
- if( balanceRec ==NULL ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- check = pScanTrans->execute(NoCommit);
- if( check == -1 ) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- int eof;
- int rows = 0;
- eof = pOp->nextResult();
-
- while(eof == 0){
- rows++;
- Uint32 a = accountTypeRec->u_32_value();
- Uint32 b = balanceRec->u_32_value();
-
- if (a == accountType){
- // One record found
- balance += b;
- }
-
- eof = pOp->nextResult();
- }
- if (eof == -1) {
- ERR(pScanTrans->getNdbError());
- m_ndb.closeTransaction(pScanTrans);
- return NDBT_FAILED;
- }
-
- m_ndb.closeTransaction(pScanTrans);
- // ndbout << rows << " rows have been read" << endl;
-
- return NDBT_OK;
-
-}
-
-/**
- * Load ACCOUNT_TYPE table
- *
- *
- */
-int Bank::loadAccountType(){
- g_info << "loadAccountType" << endl;
- int check;
-
- NdbConnection* pTrans = m_ndb.startTransaction();
- if (pTrans == NULL){
- ERR(m_ndb.getNdbError());
- return NDBT_FAILED;
- }
-
- for (int i = 0; i < getNumAccountTypes(); i++){
-
- NdbOperation* pOp = pTrans->getNdbOperation("ACCOUNT_TYPE");
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp->insertTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp->equal("ACCOUNT_TYPE_ID", accountTypes[i].id);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp->setValue("DESCRIPTION", accountTypes[i].descr);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
- }
- check = pTrans->execute(Commit);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- m_ndb.closeTransaction(pTrans);
- return NDBT_OK;
-}
-
-/**
- * Load ACCOUNT table
- *
- *
- *
- */
-int Bank::loadAccount (int numAccounts){
- g_info << "loadAccount" << endl;
- int check;
-
- NdbConnection* pTrans = m_ndb.startTransaction();
- if (pTrans == NULL){
- ERR(m_ndb.getNdbError());
- return NDBT_FAILED;
- }
-
- for (int i = 0; i < numAccounts; i++){
-
- NdbOperation* pOp = pTrans->getNdbOperation("ACCOUNT");
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp->insertTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pOp->equal("ACCOUNT_ID", i);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- int owner;
- if (i == 0)
- owner = 0;
- else
- owner = i + 3000;
- check = pOp->setValue("OWNER", owner);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- // Load balance so that the bank's account = 0 has 10 millions
- // and all other accounts have 10000
- // This set the total balance for the entire bank to
- // 10000000 + (10000 * numAccounts-1)
- // Since no money should dissapear from to the bank nor
- // any money should be added this is a rule that can be checked when
- // validating the db
- int balance;
- if (i == 0){
- balance = 10000000;
- } else {
- balance = 10000;
- }
- check = pOp->setValue("BALANCE", balance);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- // TODO - This is how to set a value in a 16, 1 attribute, not so nice?
- // NOTE - its not even possible to set the value 0 in this column
- // since that is equal to NULL when casting to char*
- // check = pOp->setValue("ACCOUNT_TYPE", (const char*)(Uint16)(i/accountTypesSize), 2);
- // NOTE attribute now changed to be a 32 bit
-
-
- int accountType;
- if (i == 0)
- accountType = 0; // KASSA
- else
- accountType = ((i%accountTypesSize) == 0 ? 1 : (i%getNumAccountTypes()));
- check = pOp->setValue("ACCOUNT_TYPE", accountType);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
- }
- check = pTrans->execute(Commit);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- m_ndb.closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- m_ndb.closeTransaction(pTrans);
- return NDBT_OK;
-}
-
-
-int Bank::getNumAccounts(){
- const NdbDictionary::Table* accountTab =
- m_ndb.getDictionary()->getTable("ACCOUNT");
- if (accountTab == NULL){
- g_err << "Table ACCOUNT does not exist" << endl;
- return NDBT_FAILED;
- }
- UtilTransactions util(*accountTab);
- if(util.selectCount(&m_ndb, 64, &m_maxAccount) != 0)
- return NDBT_FAILED;
- return NDBT_OK;
-}
-
-int Bank::getMaxAmount(){
- return 10000;
-}
diff --git a/storage/ndb/test/ndbapi/bank/Makefile.am b/storage/ndb/test/ndbapi/bank/Makefile.am
deleted file mode 100644
index 972f60ac2bc..00000000000
--- a/storage/ndb/test/ndbapi/bank/Makefile.am
+++ /dev/null
@@ -1,36 +0,0 @@
-# Copyright (C) 2004 MySQL AB
-# Use is subject to license terms
-#
-# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-ndbtest_PROGRAMS = testBank bankSumAccounts bankValidateAllGLs bankMakeGL bankTransactionMaker bankCreator bankTimer
-
-noinst_LIBRARIES = libbank.a
-
-libbank_a_SOURCES = Bank.cpp BankLoad.cpp Bank.hpp
-
-testBank_SOURCES = testBank.cpp
-bankSumAccounts_SOURCES = bankSumAccounts.cpp
-bankValidateAllGLs_SOURCES = bankValidateAllGLs.cpp
-bankMakeGL_SOURCES = bankMakeGL.cpp
-bankTransactionMaker_SOURCES = bankTransactionMaker.cpp
-bankCreator_SOURCES = bankCreator.cpp
-bankTimer_SOURCES = bankTimer.cpp
-
-LDADD_LOC = $(noinst_LIBRARIES)
-
-include $(top_srcdir)/storage/ndb/config/common.mk.am
-include $(top_srcdir)/storage/ndb/config/type_ndbapitest.mk.am
-
-windoze-dsp:
diff --git a/storage/ndb/test/ndbapi/bank/bankCreator.cpp b/storage/ndb/test/ndbapi/bank/bankCreator.cpp
deleted file mode 100644
index 8b2ec6bb10b..00000000000
--- a/storage/ndb/test/ndbapi/bank/bankCreator.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-/* Copyright (c) 2003-2006 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-#include <ndb_global.h>
-#include <NdbOut.hpp>
-
-#include <NdbApi.hpp>
-#include <NdbMain.h>
-#include <NDBT.hpp>
-#include <NdbSleep.h>
-#include <getarg.h>
-#include "Bank.hpp"
-
-
-int main(int argc, const char** argv){
- ndb_init();
- int _help = 0;
- char * _database = "BANK";
- int disk = 0;
- int skip_create = 0;
-
- struct getargs args[] = {
- { "database", 'd', arg_string, &_database, "Database name", ""},
- { "disk", 0, arg_flag, &disk, "Use disk tables", "" },
- { "skip-create", 0, arg_flag, &skip_create, "Skip create", "" },
- { "usage", '?', arg_flag, &_help, "Print help", "" }
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "This program will create and load the tables for bank\n";
-
- if(getarg(args, num_args, argc, argv, &optind) || _help) {
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- Bank bank(con,_database);
- int overWriteExisting = true;
- bank.setSkipCreate(skip_create);
- if (bank.createAndLoadBank(overWriteExisting, disk) != NDBT_OK)
- return NDBT_ProgramExit(NDBT_FAILED);
- return NDBT_ProgramExit(NDBT_OK);
-
-}
-
-
-
diff --git a/storage/ndb/test/ndbapi/bank/bankMakeGL.cpp b/storage/ndb/test/ndbapi/bank/bankMakeGL.cpp
deleted file mode 100644
index 6b5bbcf7715..00000000000
--- a/storage/ndb/test/ndbapi/bank/bankMakeGL.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-#include <ndb_global.h>
-#include <NdbOut.hpp>
-
-#include <NdbApi.hpp>
-#include <NdbMain.h>
-#include <NDBT.hpp>
-#include <NdbSleep.h>
-#include <getarg.h>
-#include "Bank.hpp"
-
-
-int main(int argc, const char** argv){
- ndb_init();
- int _help = 0;
- char * _database = "BANK";
-
- struct getargs args[] = {
- { "usage", '?', arg_flag, &_help, "Print help", "" },
- { "database", 'd', arg_string, &_database, "Database name", ""}
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "This program will make GL records in the bank\n";
-
- if(getarg(args, num_args, argc, argv, &optind) || _help) {
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- Bank bank(con,_database);
-
- if (bank.performMakeGLs() != 0)
- return NDBT_ProgramExit(NDBT_FAILED);
-
- return NDBT_ProgramExit(NDBT_OK);
-
-}
-
-
-
diff --git a/storage/ndb/test/ndbapi/bank/bankSumAccounts.cpp b/storage/ndb/test/ndbapi/bank/bankSumAccounts.cpp
deleted file mode 100644
index c2fcad9fe22..00000000000
--- a/storage/ndb/test/ndbapi/bank/bankSumAccounts.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-#include <ndb_global.h>
-#include <NdbOut.hpp>
-
-#include <NdbApi.hpp>
-#include <NdbMain.h>
-#include <NDBT.hpp>
-#include <NdbSleep.h>
-#include <getarg.h>
-#include "Bank.hpp"
-
-
-int main(int argc, const char** argv){
- ndb_init();
- int _help = 0;
- char * _database="BANK";
-
- struct getargs args[] = {
- { "usage", '?', arg_flag, &_help, "Print help", "" },
- { "database", 'd', arg_string, &_database, "Database name", ""}
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "This program will check the sum of all ACCOUNTS in the bank\n";
-
- if(getarg(args, num_args, argc, argv, &optind) || _help) {
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- Bank bank(con,_database);
-
- if (bank.performSumAccounts() != 0)
- return NDBT_ProgramExit(NDBT_FAILED);
-
- return NDBT_ProgramExit(NDBT_OK);
-
-}
-
-
-
diff --git a/storage/ndb/test/ndbapi/bank/bankTimer.cpp b/storage/ndb/test/ndbapi/bank/bankTimer.cpp
deleted file mode 100644
index da8687a5a78..00000000000
--- a/storage/ndb/test/ndbapi/bank/bankTimer.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-#include <ndb_global.h>
-
-#include <NdbOut.hpp>
-
-#include <NdbApi.hpp>
-#include <NdbMain.h>
-#include <NDBT.hpp>
-#include <NdbSleep.h>
-#include <getarg.h>
-#include "Bank.hpp"
-
-
-int main(int argc, const char** argv){
- ndb_init();
- int _help = 0;
- int _wait = 30;
- char * _database="BANK";
-
- struct getargs args[] = {
- { "wait", 'w', arg_integer, &_wait, "Max time to wait between days", "secs" },
- { "database", 'd', arg_string, &_database, "Database name", ""},
- { "usage", '?', arg_flag, &_help, "Print help", "" }
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "This program will increase time in the bank\n";
-
- if(getarg(args, num_args, argc, argv, &optind) || _help) {
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- Bank bank(con,_database);
-
- if (bank.performIncreaseTime(_wait) != 0)
- return NDBT_ProgramExit(NDBT_FAILED);
-
- return NDBT_ProgramExit(NDBT_OK);
-
-}
-
-
-
diff --git a/storage/ndb/test/ndbapi/bank/bankTransactionMaker.cpp b/storage/ndb/test/ndbapi/bank/bankTransactionMaker.cpp
deleted file mode 100644
index 9ace590aabf..00000000000
--- a/storage/ndb/test/ndbapi/bank/bankTransactionMaker.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-#include <ndb_global.h>
-
-#include <NdbOut.hpp>
-
-#include <NdbApi.hpp>
-#include <NdbMain.h>
-#include <NDBT.hpp>
-#include <NdbSleep.h>
-#include <getarg.h>
-#include "Bank.hpp"
-
-
-int main(int argc, const char** argv){
- ndb_init();
- int _help = 0;
- int _wait = 20;
- char * _database = "BANK";
-
- struct getargs args[] = {
- { "wait", 'w', arg_integer, &_wait, "Time to wait between transactions", "ms" },
- { "database", 'd', arg_string, &_database, "Database name", ""},
- { "usage", '?', arg_flag, &_help, "Print help", "" }
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "This program will perform transactions in the bank\n";
-
- if(getarg(args, num_args, argc, argv, &optind) || _help) {
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- Bank bank(con,_database);
-
- if (bank.performTransactions(_wait) != 0)
- return NDBT_ProgramExit(NDBT_FAILED);
-
- return NDBT_ProgramExit(NDBT_OK);
-
-}
-
-
-
diff --git a/storage/ndb/test/ndbapi/bank/bankValidateAllGLs.cpp b/storage/ndb/test/ndbapi/bank/bankValidateAllGLs.cpp
deleted file mode 100644
index 80882198f19..00000000000
--- a/storage/ndb/test/ndbapi/bank/bankValidateAllGLs.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-#include <ndb_global.h>
-
-#include <NdbOut.hpp>
-
-#include <NdbApi.hpp>
-#include <NdbMain.h>
-#include <NDBT.hpp>
-#include <NdbSleep.h>
-#include <getarg.h>
-#include "Bank.hpp"
-
-
-int main(int argc, const char** argv){
- ndb_init();
- int _help = 0;
- char * _database="BANK";
-
- struct getargs args[] = {
- { "usage", '?', arg_flag, &_help, "Print help", "" },
- { "database", 'd', arg_string, &_database, "Database name", ""}
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "This program will validate all GLs in the bank\n";
-
- if(getarg(args, num_args, argc, argv, &optind) || _help) {
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- Bank bank(con,_database);
-
- if (bank.performValidateAllGLs() != 0)
- return NDBT_ProgramExit(NDBT_FAILED);
-
- return NDBT_ProgramExit(NDBT_OK);
-
-}
-
-
-
diff --git a/storage/ndb/test/ndbapi/bank/testBank.cpp b/storage/ndb/test/ndbapi/bank/testBank.cpp
deleted file mode 100644
index 0e710bd8947..00000000000
--- a/storage/ndb/test/ndbapi/bank/testBank.cpp
+++ /dev/null
@@ -1,153 +0,0 @@
-/* Copyright (c) 2003-2006 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT.hpp>
-#include <NDBT_Test.hpp>
-#include <HugoTransactions.hpp>
-#include <UtilTransactions.hpp>
-#include <NdbRestarter.hpp>
-#include <NdbBackup.hpp>
-
-
-#define CHECK(b) if (!(b)) { \
- g_err << "ERR: "<< step->getName() \
- << " failed on line " << __LINE__ << endl; \
- result = NDBT_FAILED; \
- continue; }
-
-
-#include "Bank.hpp"
-
-const char* _database = "BANK";
-
-int runCreateBank(NDBT_Context* ctx, NDBT_Step* step){
- Bank bank(ctx->m_cluster_connection, _database);
- int overWriteExisting = true;
- if (bank.createAndLoadBank(overWriteExisting) != NDBT_OK)
- return NDBT_FAILED;
- return NDBT_OK;
-}
-
-int runBankTimer(NDBT_Context* ctx, NDBT_Step* step){
- Bank bank(ctx->m_cluster_connection, _database);
- int wait = 30; // Max seconds between each "day"
- int yield = 1; // Loops before bank returns
-
- while (ctx->isTestStopped() == false) {
- bank.performIncreaseTime(wait, yield);
- }
- return NDBT_OK;
-}
-
-int runBankTransactions(NDBT_Context* ctx, NDBT_Step* step){
- Bank bank(ctx->m_cluster_connection, _database);
- int wait = 10; // Max ms between each transaction
- int yield = 100; // Loops before bank returns
-
- while (ctx->isTestStopped() == false) {
- bank.performTransactions(wait, yield);
- }
- return NDBT_OK;
-}
-
-int runBankGL(NDBT_Context* ctx, NDBT_Step* step){
- Bank bank(ctx->m_cluster_connection, _database);
- int yield = 20; // Loops before bank returns
- int result = NDBT_OK;
-
- while (ctx->isTestStopped() == false) {
- if (bank.performMakeGLs(yield) != NDBT_OK){
- ndbout << "bank.performMakeGLs FAILED" << endl;
- result = NDBT_FAILED;
- }
- }
- return NDBT_OK;
-}
-
-int runBankSum(NDBT_Context* ctx, NDBT_Step* step){
- Bank bank(ctx->m_cluster_connection, _database);
- int wait = 2000; // Max ms between each sum of accounts
- int yield = 1; // Loops before bank returns
- int result = NDBT_OK;
-
- while (ctx->isTestStopped() == false) {
- if (bank.performSumAccounts(wait, yield) != NDBT_OK){
- ndbout << "bank.performSumAccounts FAILED" << endl;
- result = NDBT_FAILED;
- }
- }
- return result ;
-}
-
-int runDropBank(NDBT_Context* ctx, NDBT_Step* step){
- Bank bank(ctx->m_cluster_connection, _database);
- if (bank.dropBank() != NDBT_OK)
- return NDBT_FAILED;
- return NDBT_OK;
-}
-
-int runBankController(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int l = 0;
- int result = NDBT_OK;
-
- while (l < loops && result != NDBT_FAILED){
-
- if (pNdb->waitUntilReady() != 0){
- result = NDBT_FAILED;
- continue;
- }
-
- // Sleep for a while
- NdbSleep_SecSleep(records);
-
- l++;
- }
-
- if (pNdb->waitUntilReady() != 0){
- result = NDBT_FAILED;
- }
-
- ctx->stopTest();
-
- return result;
-}
-
-NDBT_TESTSUITE(testBank);
-TESTCASE("Bank",
- "Run the bank\n"){
- INITIALIZER(runCreateBank);
- STEP(runBankTimer);
- STEP(runBankTransactions);
- STEP(runBankGL);
- // TODO STEP(runBankSum);
- STEP(runBankController);
- FINALIZER(runDropBank);
-
-}
-NDBT_TESTSUITE_END(testBank);
-
-int main(int argc, const char** argv){
- ndb_init();
- // Tables should not be auto created
- testBank.setCreateTable(false);
-
- return testBank.execute(argc, argv);
-}
-
-
diff --git a/storage/ndb/test/ndbapi/bench/asyncGenerator.cpp b/storage/ndb/test/ndbapi/bench/asyncGenerator.cpp
deleted file mode 100644
index 8b8fe993127..00000000000
--- a/storage/ndb/test/ndbapi/bench/asyncGenerator.cpp
+++ /dev/null
@@ -1,570 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-/***************************************************************
-* I N C L U D E D F I L E S *
-***************************************************************/
-
-#include <ndb_global.h>
-
-#include "dbGenerator.h"
-#include <NdbApi.hpp>
-#include <NdbOut.hpp>
-#include <NdbSleep.h>
-
-/***************************************************************
-* L O C A L C O N S T A N T S *
-***************************************************************/
-
-/***************************************************************
-* L O C A L D A T A S T R U C T U R E S *
-***************************************************************/
-
-/***************************************************************
-* L O C A L F U N C T I O N S *
-***************************************************************/
-
-static void getRandomSubscriberNumber(SubscriberNumber number);
-static void getRandomServerId(ServerId *serverId);
-static void getRandomChangedBy(ChangedBy changedBy);
-static void getRandomChangedTime(ChangedTime changedTime);
-
-static void clearTransaction(TransactionDefinition *trans);
-static void initGeneratorStatistics(GeneratorStatistics *gen);
-
-static void doOneTransaction(ThreadData * td,
- int parallellism,
- int millisSendPoll,
- int minEventSendPoll,
- int forceSendPoll);
-static void doTransaction_T1(Ndb * pNDB, ThreadData * td, int async);
-static void doTransaction_T2(Ndb * pNDB, ThreadData * td, int async);
-static void doTransaction_T3(Ndb * pNDB, ThreadData * td, int async);
-static void doTransaction_T4(Ndb * pNDB, ThreadData * td, int async);
-static void doTransaction_T5(Ndb * pNDB, ThreadData * td, int async);
-
-/***************************************************************
-* L O C A L D A T A *
-***************************************************************/
-
-static SequenceValues transactionDefinition[] = {
- {25, 1},
- {25, 2},
- {20, 3},
- {15, 4},
- {15, 5},
- {0, 0}
-};
-
-static SequenceValues rollbackDefinition[] = {
- {98, 0},
- {2 , 1},
- {0, 0}
-};
-
-static int maxsize = 0;
-
-/***************************************************************
-* P U B L I C D A T A *
-***************************************************************/
-
-/***************************************************************
-****************************************************************
-* L O C A L F U N C T I O N S C O D E S E C T I O N *
-****************************************************************
-***************************************************************/
-
-static void getRandomSubscriberNumber(SubscriberNumber number)
-{
- uint32 tmp;
- char sbuf[SUBSCRIBER_NUMBER_LENGTH + 1];
- tmp = myRandom48(NO_OF_SUBSCRIBERS);
- sprintf(sbuf, "%.*d", SUBSCRIBER_NUMBER_LENGTH, tmp);
- memcpy(number, sbuf, SUBSCRIBER_NUMBER_LENGTH);
-}
-
-static void getRandomServerId(ServerId *serverId)
-{
- *serverId = myRandom48(NO_OF_SERVERS);
-}
-
-static void getRandomChangedBy(ChangedBy changedBy)
-{
- memset(changedBy, myRandom48(26)+'A', CHANGED_BY_LENGTH);
- changedBy[CHANGED_BY_LENGTH] = 0;
-}
-
-static void getRandomChangedTime(ChangedTime changedTime)
-{
- memset(changedTime, myRandom48(26)+'A', CHANGED_TIME_LENGTH);
- changedTime[CHANGED_TIME_LENGTH] = 0;
-}
-
-static void clearTransaction(TransactionDefinition *trans)
-{
- trans->count = 0;
- trans->branchExecuted = 0;
- trans->rollbackExecuted = 0;
- trans->latencyCounter = myRandom48(127);
- trans->latency.reset();
-}
-
-static int listFull(SessionList *list)
-{
- return(list->numberInList == SESSION_LIST_LENGTH);
-}
-
-static int listEmpty(SessionList *list)
-{
- return(list->numberInList == 0);
-}
-
-static void insertSession(SessionList *list,
- SubscriberNumber number,
- ServerId serverId)
-{
- SessionElement *e;
- if( listFull(list) ) return;
-
- e = &list->list[list->writeIndex];
-
- strcpy(e->subscriberNumber, number);
- e->serverId = serverId;
-
- list->writeIndex = (list->writeIndex + 1) % SESSION_LIST_LENGTH;
- list->numberInList++;
-
- if( list->numberInList > maxsize )
- maxsize = list->numberInList;
-}
-
-static SessionElement *getNextSession(SessionList *list)
-{
- if( listEmpty(list) ) return(0);
-
- return(&list->list[list->readIndex]);
-}
-
-static void deleteSession(SessionList *list)
-{
- if( listEmpty(list) ) return;
-
- list->readIndex = (list->readIndex + 1) % SESSION_LIST_LENGTH;
- list->numberInList--;
-}
-
-static void initGeneratorStatistics(GeneratorStatistics *gen)
-{
- int i;
-
- if( initSequence(&gen->transactionSequence,
- transactionDefinition) != 0 ) {
- ndbout_c("could not set the transaction types");
- exit(0);
- }
-
- if( initSequence(&gen->rollbackSequenceT4,
- rollbackDefinition) != 0 ) {
- ndbout_c("could not set the rollback sequence");
- exit(0);
- }
-
- if( initSequence(&gen->rollbackSequenceT5,
- rollbackDefinition) != 0 ) {
- ndbout_c("could not set the rollback sequence");
- exit(0);
- }
-
- for(i = 0; i < NUM_TRANSACTION_TYPES; i++ )
- clearTransaction(&gen->transactions[i]);
-
- gen->totalTransactions = 0;
-
- gen->activeSessions.numberInList = 0;
- gen->activeSessions.readIndex = 0;
- gen->activeSessions.writeIndex = 0;
-}
-
-
-static
-void
-doOneTransaction(ThreadData * td, int p, int millis, int minEvents, int force)
-{
- int i;
- unsigned int transactionType;
- int async = 1;
- if (p == 1) {
- async = 0;
- }//if
- for(i = 0; i<p; i++){
- if(td[i].runState == Runnable){
- transactionType = getNextRandom(&td[i].generator.transactionSequence);
-
- switch(transactionType) {
- case 1:
- doTransaction_T1(td[i].pNDB, &td[i], async);
- break;
- case 2:
- doTransaction_T2(td[i].pNDB, &td[i], async);
- break;
- case 3:
- doTransaction_T3(td[i].pNDB, &td[i], async);
- break;
- case 4:
- doTransaction_T4(td[i].pNDB, &td[i], async);
- break;
- case 5:
- doTransaction_T5(td[i].pNDB, &td[i], async);
- break;
- default:
- ndbout_c("Unknown transaction type: %d", transactionType);
- }
- }
- }
- if (async == 1) {
- td[0].pNDB->sendPollNdb(millis, minEvents, force);
- }//if
-}
-
-static
-void
-doTransaction_T1(Ndb * pNDB, ThreadData * td, int async)
-{
- /*----------------*/
- /* Init arguments */
- /*----------------*/
- getRandomSubscriberNumber(td->transactionData.number);
- getRandomChangedBy(td->transactionData.changed_by);
- BaseString::snprintf(td->transactionData.changed_time,
- sizeof(td->transactionData.changed_time),
- "%ld - %d", td->changedTime++, myRandom48(65536*1024));
- //getRandomChangedTime(td->transactionData.changed_time);
- td->transactionData.location = td->transactionData.changed_by[0];
-
- /*-----------------*/
- /* Run transaction */
- /*-----------------*/
- td->runState = Running;
- td->generator.transactions[0].startLatency();
-
- start_T1(pNDB, td, async);
-}
-
-static
-void
-doTransaction_T2(Ndb * pNDB, ThreadData * td, int async)
-{
- /*----------------*/
- /* Init arguments */
- /*----------------*/
- getRandomSubscriberNumber(td->transactionData.number);
-
- /*-----------------*/
- /* Run transaction */
- /*-----------------*/
- td->runState = Running;
- td->generator.transactions[1].startLatency();
-
- start_T2(pNDB, td, async);
-}
-
-static
-void
-doTransaction_T3(Ndb * pNDB, ThreadData * td, int async)
-{
- SessionElement *se;
-
- /*----------------*/
- /* Init arguments */
- /*----------------*/
- se = getNextSession(&td->generator.activeSessions);
- if( se ) {
- strcpy(td->transactionData.number, se->subscriberNumber);
- td->transactionData.server_id = se->serverId;
- td->transactionData.sessionElement = 1;
- } else {
- getRandomSubscriberNumber(td->transactionData.number);
- getRandomServerId(&td->transactionData.server_id);
- td->transactionData.sessionElement = 0;
- }
-
- td->transactionData.server_bit = (1 << td->transactionData.server_id);
-
- /*-----------------*/
- /* Run transaction */
- /*-----------------*/
- td->runState = Running;
- td->generator.transactions[2].startLatency();
- start_T3(pNDB, td, async);
-}
-
-static
-void
-doTransaction_T4(Ndb * pNDB, ThreadData * td, int async)
-{
- /*----------------*/
- /* Init arguments */
- /*----------------*/
- getRandomSubscriberNumber(td->transactionData.number);
- getRandomServerId(&td->transactionData.server_id);
-
- td->transactionData.server_bit = (1 << td->transactionData.server_id);
- td->transactionData.do_rollback =
- getNextRandom(&td->generator.rollbackSequenceT4);
-
- memset(td->transactionData.session_details+2,
- myRandom48(26)+'A', SESSION_DETAILS_LENGTH-3);
- td->transactionData.session_details[SESSION_DETAILS_LENGTH-1] = 0;
- int2store(td->transactionData.session_details,SESSION_DETAILS_LENGTH-2);
-
- /*-----------------*/
- /* Run transaction */
- /*-----------------*/
- td->runState = Running;
- td->generator.transactions[3].startLatency();
- start_T4(pNDB, td, async);
-}
-
-static
-void
-doTransaction_T5(Ndb * pNDB, ThreadData * td, int async)
-{
- SessionElement * se;
- se = getNextSession(&td->generator.activeSessions);
- if( se ) {
- strcpy(td->transactionData.number, se->subscriberNumber);
- td->transactionData.server_id = se->serverId;
- td->transactionData.sessionElement = 1;
- }
- else {
- getRandomSubscriberNumber(td->transactionData.number);
- getRandomServerId(&td->transactionData.server_id);
- td->transactionData.sessionElement = 0;
- }
-
- td->transactionData.server_bit = (1 << td->transactionData.server_id);
- td->transactionData.do_rollback
- = getNextRandom(&td->generator.rollbackSequenceT5);
-
- /*-----------------*/
- /* Run transaction */
- /*-----------------*/
- td->runState = Running;
- td->generator.transactions[4].startLatency();
- start_T5(pNDB, td, async);
-}
-
-void
-complete_T1(ThreadData * data){
- data->generator.transactions[0].stopLatency();
- data->generator.transactions[0].count++;
-
- data->runState = Runnable;
- data->generator.totalTransactions++;
-}
-
-void
-complete_T2(ThreadData * data){
- data->generator.transactions[1].stopLatency();
- data->generator.transactions[1].count++;
-
- data->runState = Runnable;
- data->generator.totalTransactions++;
-}
-
-void
-complete_T3(ThreadData * data){
-
- data->generator.transactions[2].stopLatency();
- data->generator.transactions[2].count++;
-
- if(data->transactionData.branchExecuted)
- data->generator.transactions[2].branchExecuted++;
-
- data->runState = Runnable;
- data->generator.totalTransactions++;
-}
-
-void
-complete_T4(ThreadData * data){
-
- data->generator.transactions[3].stopLatency();
- data->generator.transactions[3].count++;
-
- if(data->transactionData.branchExecuted)
- data->generator.transactions[3].branchExecuted++;
- if(data->transactionData.do_rollback)
- data->generator.transactions[3].rollbackExecuted++;
-
- if(data->transactionData.branchExecuted &&
- !data->transactionData.do_rollback){
- insertSession(&data->generator.activeSessions,
- data->transactionData.number,
- data->transactionData.server_id);
- }
-
- data->runState = Runnable;
- data->generator.totalTransactions++;
-
-}
-void
-complete_T5(ThreadData * data){
-
- data->generator.transactions[4].stopLatency();
- data->generator.transactions[4].count++;
-
- if(data->transactionData.branchExecuted)
- data->generator.transactions[4].branchExecuted++;
- if(data->transactionData.do_rollback)
- data->generator.transactions[4].rollbackExecuted++;
-
- if(data->transactionData.sessionElement &&
- !data->transactionData.do_rollback){
- deleteSession(&data->generator.activeSessions);
- }
-
- data->runState = Runnable;
- data->generator.totalTransactions++;
-}
-
-/***************************************************************
-****************************************************************
-* P U B L I C F U N C T I O N S C O D E S E C T I O N *
-****************************************************************
-***************************************************************/
-void
-asyncGenerator(ThreadData *data,
- int parallellism,
- int millisSendPoll,
- int minEventSendPoll,
- int forceSendPoll)
-{
- ThreadData * startUp;
-
- GeneratorStatistics *st;
- double periodStop;
- double benchTimeStart;
- double benchTimeEnd;
- int i, j, done;
-
- myRandom48Init(data->randomSeed);
-
- for(i = 0; i<parallellism; i++){
- initGeneratorStatistics(&data[i].generator);
- }
-
- startUp = (ThreadData*)malloc(parallellism * sizeof(ThreadData));
- memcpy(startUp, data, (parallellism * sizeof(ThreadData)));
-
- /*----------------*/
- /* warm up period */
- /*----------------*/
- periodStop = userGetTime() + (double)data[0].warmUpSeconds;
-
- while(userGetTime() < periodStop){
- doOneTransaction(startUp, parallellism,
- millisSendPoll, minEventSendPoll, forceSendPoll);
- }
-
- ndbout_c("Waiting for startup to finish");
-
- /**
- * Wait for all transactions
- */
- done = 0;
- while(!done){
- done = 1;
- for(i = 0; i<parallellism; i++){
- if(startUp[i].runState != Runnable){
- done = 0;
- break;
- }
- }
- if(!done){
- startUp[0].pNDB->sendPollNdb();
- }
- }
- ndbout_c("Benchmark period starts");
-
- /*-------------------------*/
- /* normal benchmark period */
- /*-------------------------*/
- benchTimeStart = userGetTime();
-
- periodStop = benchTimeStart + (double)data[0].testSeconds;
- while(userGetTime() < periodStop)
- doOneTransaction(data, parallellism,
- millisSendPoll, minEventSendPoll, forceSendPoll);
-
- benchTimeEnd = userGetTime();
-
- ndbout_c("Benchmark period done");
-
- /**
- * Wait for all transactions
- */
- done = 0;
- while(!done){
- done = 1;
- for(i = 0; i<parallellism; i++){
- if(data[i].runState != Runnable){
- done = 0;
- break;
- }
- }
- if(!done){
- data[0].pNDB->sendPollNdb();
- }
- }
-
- /*------------------*/
- /* cool down period */
- /*------------------*/
- periodStop = userGetTime() + (double)data[0].coolDownSeconds;
- while(userGetTime() < periodStop){
- doOneTransaction(startUp, parallellism,
- millisSendPoll, minEventSendPoll, forceSendPoll);
- }
-
- done = 0;
- while(!done){
- done = 1;
- for(i = 0; i<parallellism; i++){
- if(startUp[i].runState != Runnable){
- done = 0;
- break;
- }
- }
- if(!done){
- startUp[0].pNDB->sendPollNdb();
- }
- }
-
-
- /*---------------------------------------------------------*/
- /* add the times for all transaction for inner loop timing */
- /*---------------------------------------------------------*/
- for(j = 0; j<parallellism; j++){
- st = &data[j].generator;
-
- st->outerLoopTime = benchTimeEnd - benchTimeStart;
- st->outerTps = getTps(st->totalTransactions, st->outerLoopTime);
- }
- /* ndbout_c("maxsize = %d\n",maxsize); */
-
- free(startUp);
-}
-
diff --git a/storage/ndb/test/ndbapi/bench/dbGenerator.h b/storage/ndb/test/ndbapi/bench/dbGenerator.h
deleted file mode 100644
index d9655e12bf5..00000000000
--- a/storage/ndb/test/ndbapi/bench/dbGenerator.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef DBGENERATOR_H
-#define DBGENERATOR_H
-
-/***************************************************************
-* I N C L U D E D F I L E S *
-***************************************************************/
-
-#include "testData.h"
-#include "userInterface.h"
-
-/***************************************************************
-* M A C R O S *
-***************************************************************/
-
-/***************************************************************/
-/* C O N S T A N T S */
-/***************************************************************/
-
-/***************************************************************
-* D A T A S T R U C T U R E S *
-***************************************************************/
-
-/***************************************************************
-* P U B L I C F U N C T I O N S *
-***************************************************************/
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern void asyncGenerator(ThreadData *d, int parallellism,
- int millisSendPoll,
- int minEventSendPoll,
- int forceSendPoll);
-
-#ifdef __cplusplus
-}
-#endif
-
-/***************************************************************
-* E X T E R N A L D A T A *
-***************************************************************/
-
-
-
-#endif /* DBGENERATOR_H */
-
diff --git a/storage/ndb/test/ndbapi/bench/dbPopulate.cpp b/storage/ndb/test/ndbapi/bench/dbPopulate.cpp
deleted file mode 100644
index 3c9d1c5d8fd..00000000000
--- a/storage/ndb/test/ndbapi/bench/dbPopulate.cpp
+++ /dev/null
@@ -1,244 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-/***************************************************************
-* I N C L U D E D F I L E S *
-***************************************************************/
-
-#include <ndb_global.h>
-
-#include "userInterface.h"
-
-#include "dbPopulate.h"
-#include <NdbOut.hpp>
-#include <random.h>
-
-/***************************************************************
-* L O C A L C O N S T A N T S *
-***************************************************************/
-
-/***************************************************************
-* L O C A L D A T A S T R U C T U R E S *
-***************************************************************/
-
-/***************************************************************
-* L O C A L F U N C T I O N S *
-***************************************************************/
-
-static void getRandomSubscriberData(int subscriberNo,
- SubscriberNumber number,
- SubscriberName name);
-
-static void populate(char *title,
- int count,
- void (*func)(UserHandle*,int),
- UserHandle *uh);
-
-static void populateServers(UserHandle *uh, int count);
-static void populateSubscribers(UserHandle *uh, int count);
-static void populateGroups(UserHandle *uh, int count);
-
-/***************************************************************
-* L O C A L D A T A *
-***************************************************************/
-
-static SequenceValues permissionsDefinition[] = {
- {90, 1},
- {10, 0},
- {0, 0}
-};
-
-/***************************************************************
-* P U B L I C D A T A *
-***************************************************************/
-
-
-/***************************************************************
-****************************************************************
-* L O C A L F U N C T I O N S C O D E S E C T I O N *
-****************************************************************
-***************************************************************/
-
-static void getRandomSubscriberData(int subscriberNo,
- SubscriberNumber number,
- SubscriberName name)
-{
- char sbuf[SUBSCRIBER_NUMBER_LENGTH + 1];
- sprintf(sbuf, "%.*d", SUBSCRIBER_NUMBER_LENGTH, subscriberNo);
- memcpy(number, sbuf, SUBSCRIBER_NUMBER_LENGTH);
-
- memset(name, myRandom48(26)+'A', SUBSCRIBER_NAME_LENGTH);
-}
-
-static void populate(char *title,
- int count,
- void (*func)(UserHandle*, int),
- UserHandle *uh)
-{
- ndbout_c("Populating %d '%s' ... ",count, title);
- /* fflush(stdout); */
- func(uh,count);
- ndbout_c("done");
-}
-
-static void populateServers(UserHandle *uh, int count)
-{
- int i, j;
- int len;
- char tmp[80];
- int suffix_length = 1;
- ServerName serverName;
- SubscriberSuffix suffix;
-
- int commitCount = 0;
-
- for(i = 0; i < SUBSCRIBER_NUMBER_SUFFIX_LENGTH; i++)
- suffix_length *= 10;
-
- for(i = 0; i < count; i++) {
- sprintf(tmp, "-Server %d-", i);
-
- len = strlen(tmp);
- for(j = 0; j < SERVER_NAME_LENGTH; j++){
- serverName[j] = tmp[j % len];
- }
- /* serverName[j] = 0; not null-terminated */
-
- for(j = 0; j < suffix_length; j++){
- char sbuf[SUBSCRIBER_NUMBER_SUFFIX_LENGTH + 1];
- sprintf(sbuf, "%.*d", SUBSCRIBER_NUMBER_SUFFIX_LENGTH, j);
- memcpy(suffix, sbuf, SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
- userDbInsertServer(uh, i, suffix, serverName);
- commitCount ++;
- if((commitCount % OP_PER_TRANS) == 0)
- userDbCommit(uh);
- }
- }
- if((commitCount % OP_PER_TRANS) != 0)
- userDbCommit(uh);
-}
-
-static void populateSubscribers(UserHandle *uh, int count)
-{
- SubscriberNumber number;
- SubscriberName name;
- int i, j, k;
- int res;
-
- SequenceValues values[NO_OF_GROUPS+1];
- RandomSequence seq;
-
- for(i = 0; i < NO_OF_GROUPS; i++) {
- values[i].length = 1;
- values[i].value = i;
- }
-
- values[i].length = 0;
- values[i].value = 0;
-
- if( initSequence(&seq, values) != 0 ) {
- ndbout_c("could not set the sequence of random groups");
- exit(0);
- }
-
-#define RETRIES 25
-
- for(i = 0; i < count; i+= OP_PER_TRANS) {
- for(j = 0; j<RETRIES; j++){
- for(k = 0; k<OP_PER_TRANS && i+k < count; k++){
- getRandomSubscriberData(i+k, number, name);
- userDbInsertSubscriber(uh, number, getNextRandom(&seq), name);
- }
- res = userDbCommit(uh);
- if(res == 0)
- break;
- if(res != 1){
- ndbout_c("Terminating");
- exit(0);
- }
- }
- if(j == RETRIES){
- ndbout_c("Terminating");
- exit(0);
- }
- }
-}
-
-static void populateGroups(UserHandle *uh, int count)
-{
- int i;
- int j;
- int len;
- RandomSequence seq;
- Permission allow[NO_OF_GROUPS];
- ServerBit serverBit;
- GroupName groupName;
- char tmp[80];
- int commitCount = 0;
-
- if( initSequence(&seq, permissionsDefinition) != 0 ) {
- ndbout_c("could not set the sequence of random permissions");
- exit(0);
- }
-
- for(i = 0; i < NO_OF_GROUPS; i++)
- allow[i] = 0;
-
- for(i = 0; i < NO_OF_SERVERS; i++) {
- serverBit = 1 << i;
-
- for(j = 0; j < NO_OF_GROUPS; j++ ) {
- if( getNextRandom(&seq) )
- allow[j] |= serverBit;
- }
- }
-
- for(i = 0; i < NO_OF_GROUPS; i++) {
- sprintf(tmp, "-Group %d-", i);
-
- len = strlen(tmp);
-
- for(j = 0; j < GROUP_NAME_LENGTH; j++) {
- groupName[j] = tmp[j % len];
- }
- /* groupName[j] = 0; not null-terminated */
-
- userDbInsertGroup(uh,
- i,
- groupName,
- allow[i],
- allow[i],
- allow[i]);
- commitCount ++;
- if((commitCount % OP_PER_TRANS) == 0)
- userDbCommit(uh);
- }
- if((commitCount % OP_PER_TRANS) != 0)
- userDbCommit(uh);
-}
-
-/***************************************************************
-****************************************************************
-* P U B L I C F U N C T I O N S C O D E S E C T I O N *
-****************************************************************
-***************************************************************/
-
-void dbPopulate(UserHandle *uh)
-{
- populate("servers", NO_OF_SERVERS, populateServers, uh);
- populate("subscribers", NO_OF_SUBSCRIBERS, populateSubscribers, uh);
- populate("groups", NO_OF_GROUPS, populateGroups, uh);
-}
diff --git a/storage/ndb/test/ndbapi/bench/dbPopulate.h b/storage/ndb/test/ndbapi/bench/dbPopulate.h
deleted file mode 100644
index 8003c42c008..00000000000
--- a/storage/ndb/test/ndbapi/bench/dbPopulate.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef DBPOPULATE_H
-#define DBPOPULATE_H
-
-/***************************************************************
-* I N C L U D E D F I L E S *
-***************************************************************/
-
-#include "userInterface.h"
-
-/***************************************************************
-* M A C R O S *
-***************************************************************/
-
-/***************************************************************/
-/* C O N S T A N T S */
-/***************************************************************/
-
-/***************************************************************
-* D A T A S T R U C T U R E S *
-***************************************************************/
-
-/***************************************************************
-* P U B L I C F U N C T I O N S *
-***************************************************************/
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern void dbPopulate(UserHandle *uh);
-
-#ifdef __cplusplus
-}
-#endif
-
-/***************************************************************
-* E X T E R N A L D A T A *
-***************************************************************/
-
-
-
-#endif /* DBPOPULATE_H */
-
diff --git a/storage/ndb/test/ndbapi/bench/macros.h b/storage/ndb/test/ndbapi/bench/macros.h
deleted file mode 100644
index 35e0804f0f7..00000000000
--- a/storage/ndb/test/ndbapi/bench/macros.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef MACROS_H
-#define MACROS_H
-
-#include <ndb_global.h>
-#include <NdbOut.hpp>
-
-#define ERROR(x) {ndbout_c((x));}
-#define ERROR1(x,y) {ndbout_c((x), (y));}
-#define ERROR2(x,y,z) {ndbout_c((x), (y), (z));}
-#define ERROR3(x,y,z,u) {ndbout_c((x), (y), (z), (u));}
-#define ERROR4(x,y,z,u,w) {ndbout_c((x), (y), (z), (u), (w));}
-
-#define INIT_RANDOM(x) srand48((x))
-#define UI_RANDOM(x) ((unsigned int)(lrand48()%(x)))
-
-#define ASSERT(cond, message) \
- { if(!(cond)) { ERROR(message); exit(-1); }}
-
-#ifdef DEBUG_ON
-#define DEBUG(x) {ndbout_c((x));}
-#define DEBUG1(x,y) {ndbout_c((x), (y));}
-#define DEBUG2(x,y,z) {ndbout_c((x), (y), (z));}
-#define DEBUG3(x,y,z,u) {ndbout_c((x), (y), (z), (u));}
-#define DEBUG4(x,y,z,u,w) {ndbout_c((x), (y), (z), (u), (w));}
-#define DEBUG5(x,y,z,u,w, v) {ndbout_c((x), (y), (z), (u), (w), (v));}
-#else
-#define DEBUG(x)
-#define DEBUG1(x,y)
-#define DEBUG2(x,y,z)
-#define DEBUG3(x,y,z,u)
-#define DEBUG4(x,y,z,u,w)
-#define DEBUG5(x,y,z,u,w, v)
-#endif
-
-#endif
diff --git a/storage/ndb/test/ndbapi/bench/mainAsyncGenerator.cpp b/storage/ndb/test/ndbapi/bench/mainAsyncGenerator.cpp
deleted file mode 100644
index 78fb684a060..00000000000
--- a/storage/ndb/test/ndbapi/bench/mainAsyncGenerator.cpp
+++ /dev/null
@@ -1,503 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-
-#include <NdbHost.h>
-#include <NdbSleep.h>
-#include <NdbThread.h>
-#include <NdbMain.h>
-#include <NdbOut.hpp>
-#include <NdbEnv.h>
-#include <NdbTest.hpp>
-
-#include "userInterface.h"
-#include "dbGenerator.h"
-
-static int numProcesses;
-static int numSeconds;
-static int numWarmSeconds;
-static int parallellism;
-static int millisSendPoll;
-static int minEventSendPoll;
-static int forceSendPoll;
-
-static ThreadData *data;
-static Ndb_cluster_connection *g_cluster_connection= 0;
-
-
-static void usage(const char *prog)
-{
- const char *progname;
-
- /*--------------------------------------------*/
- /* Get the name of the program (without path) */
- /*--------------------------------------------*/
- progname = strrchr(prog, '/');
-
- if (progname == 0)
- progname = prog;
- else
- ++progname;
-
- ndbout_c(
- "Usage: %s [-proc <num>] [-warm <num>] [-time <num>] [ -p <num>] "
- "[-t <num> ] [ -e <num> ] [ -f <num>] \n"
- " -proc <num> Specifies that <num> is the number of\n"
- " threads. The default is 1.\n"
- " -time <num> Specifies that the test will run for <num> sec.\n"
- " The default is 10 sec\n"
- " -warm <num> Specifies the warm-up/cooldown period of <num> "
- "sec.\n"
- " The default is 10 sec\n"
- " -p <num> The no of parallell transactions started by "
- "one thread\n"
- " -e <num> Minimum no of events before wake up in call to "
- "sendPoll\n"
- " Default is 1\n"
- " -f <num> force parameter to sendPoll\n"
- " Default is 0\n",
- progname);
-}
-
-static
-int
-parse_args(int argc, const char **argv)
-{
- int i;
-
- numProcesses = 1;
- numSeconds = 10;
- numWarmSeconds = 10;
- parallellism = 1;
- millisSendPoll = 10000;
- minEventSendPoll = 1;
- forceSendPoll = 0;
-
-
- i = 1;
- while (i < argc){
- if (strcmp("-proc",argv[i]) == 0) {
- if (i + 1 >= argc) {
- return 1;
- }
- if (sscanf(argv[i+1], "%d", &numProcesses) == -1 ||
- numProcesses <= 0 || numProcesses > 127) {
- ndbout_c("-proc flag requires a positive integer argument [1..127]");
- return 1;
- }
- i += 2;
- } else if (strcmp("-p", argv[i]) == 0){
- if(i + 1 >= argc){
- usage(argv[0]);
- return 1;
- }
- if (sscanf(argv[i+1], "%d", &parallellism) == -1 ||
- parallellism <= 0){
- ndbout_c("-p flag requires a positive integer argument");
- return 1;
- }
- i += 2;
- }
- else if (strcmp("-time",argv[i]) == 0) {
- if (i + 1 >= argc) {
- return 1;
- }
- if (sscanf(argv[i+1], "%d", &numSeconds) == -1 ||
- numSeconds < 0) {
- ndbout_c("-time flag requires a positive integer argument");
- return 1;
- }
- i += 2;
- }
- else if (strcmp("-warm",argv[i]) == 0) {
- if (i + 1 >= argc) {
- return 1;
- }
- if (sscanf(argv[i+1], "%d", &numWarmSeconds) == -1 ||
- numWarmSeconds < 0) {
- ndbout_c("-warm flag requires a positive integer argument");
- return 1;
- }
- i += 2;
- }
- else if (strcmp("-e",argv[i]) == 0) {
- if (i + 1 >= argc) {
- return 1;
- }
- if (sscanf(argv[i+1], "%d", &minEventSendPoll) == -1 ||
- minEventSendPoll < 0) {
- ndbout_c("-e flag requires a positive integer argument");
- return 1;
- }
- i += 2;
- }
- else if (strcmp("-f",argv[i]) == 0) {
- if (i + 1 >= argc) {
- usage(argv[0]);
- return 1;
- }
- if (sscanf(argv[i+1], "%d", &forceSendPoll) == -1 ||
- forceSendPoll < 0) {
- ndbout_c("-f flag requires a positive integer argument");
- return 1;
- }
- i += 2;
- }
- else {
- return 1;
- }
- }
-
- if(minEventSendPoll > parallellism){
- ndbout_c("minEventSendPoll(%d) > parallellism(%d)",
- minEventSendPoll, parallellism);
- ndbout_c("not very good...");
- ndbout_c("very bad...");
- ndbout_c("exiting...");
- return 1;
- }
- return 0;
-}
-
-static
-void
-print_transaction(const char *header,
- unsigned long totalCount,
- TransactionDefinition *trans,
- unsigned int printBranch,
- unsigned int printRollback)
-{
- double f;
-
- ndbout_c(" %s: %d (%.2f%%) "
- "Latency(ms) avg: %d min: %d max: %d std: %d n: %d",
- header,
- trans->count,
- (double)trans->count / (double)totalCount * 100.0,
- (int)trans->latency.getMean(),
- (int)trans->latency.getMin(),
- (int)trans->latency.getMax(),
- (int)trans->latency.getStddev(),
- (int)trans->latency.getCount()
- );
-
- if( printBranch ){
- if( trans->count == 0 )
- f = 0.0;
- else
- f = (double)trans->branchExecuted / (double)trans->count * 100.0;
- ndbout_c(" Branches Executed: %d (%.2f%%)", trans->branchExecuted, f);
- }
-
- if( printRollback ){
- if( trans->count == 0 )
- f = 0.0;
- else
- f = (double)trans->rollbackExecuted / (double)trans->count * 100.0;
- ndbout_c(" Rollback Executed: %d (%.2f%%)",trans->rollbackExecuted,f);
- }
-}
-
-void
-print_stats(const char *title,
- unsigned int length,
- unsigned int transactionFlag,
- GeneratorStatistics *gen,
- int numProc, int parallellism)
-{
- int i;
- char buf[10];
- char name[MAXHOSTNAMELEN];
-
- name[0] = 0;
- NdbHost_GetHostName(name);
-
- ndbout_c("\n------ %s ------",title);
- ndbout_c("Length : %d %s",
- length,
- transactionFlag ? "Transactions" : "sec");
- ndbout_c("Processor : %s", name);
- ndbout_c("Number of Proc: %d",numProc);
- ndbout_c("Parallellism : %d", parallellism);
- ndbout_c("\n");
-
- if( gen->totalTransactions == 0 ) {
- ndbout_c(" No Transactions for this test");
- }
- else {
- for(i = 0; i < 5; i++) {
- sprintf(buf, "T%d",i+1);
- print_transaction(buf,
- gen->totalTransactions,
- &gen->transactions[i],
- i >= 2,
- i >= 3 );
- }
-
- ndbout_c("\n");
- ndbout_c(" Overall Statistics:");
- ndbout_c(" Transactions: %d", gen->totalTransactions);
- ndbout_c(" Outer : %.0f TPS",gen->outerTps);
- ndbout_c("\n");
- }
-}
-
-static
-void *
-threadRoutine(void *arg)
-{
- int i;
- ThreadData *data = (ThreadData *)arg;
- Ndb * pNDB;
-
- pNDB = asyncDbConnect(parallellism);
- /* NdbSleep_MilliSleep(rand() % 10); */
-
- for(i = 0; i<parallellism; i++){
- data[i].pNDB = pNDB;
- }
- millisSendPoll = 30000;
- asyncGenerator(data, parallellism,
- millisSendPoll, minEventSendPoll, forceSendPoll);
-
- asyncDbDisconnect(pNDB);
-
- return NULL;
-}
-
-NDB_COMMAND(DbAsyncGenerator, "DbAsyncGenerator",
- "DbAsyncGenerator", "DbAsyncGenerator", 65535)
-{
- ndb_init();
- int i;
- int j;
- int k;
- struct NdbThread* pThread = NULL;
- GeneratorStatistics stats;
- GeneratorStatistics *p;
- char threadName[32];
- int rc = NDBT_OK;
- void* tmp = NULL;
- if(parse_args(argc,argv) != 0){
- usage(argv[0]);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
-
- ndbout_c("\nStarting Test with %d process(es) for %d %s parallellism %d",
- numProcesses,
- numSeconds,
- "sec",
- parallellism);
-
- ndbout_c(" WarmUp/coolDown = %d sec", numWarmSeconds);
-
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- ndbout << "Unable to connect to management server." << endl;
- return 0;
- }
- if (con.wait_until_ready(30,0) < 0)
- {
- ndbout << "Cluster nodes not ready in 30 seconds." << endl;
- return 0;
- }
-
- g_cluster_connection= &con;
- data = (ThreadData*)malloc((numProcesses*parallellism)*sizeof(ThreadData));
-
- for(i = 0; i < numProcesses; i++) {
- for(j = 0; j<parallellism; j++){
- data[i*parallellism+j].warmUpSeconds = numWarmSeconds;
- data[i*parallellism+j].testSeconds = numSeconds;
- data[i*parallellism+j].coolDownSeconds = numWarmSeconds;
- data[i*parallellism+j].randomSeed =
- NdbTick_CurrentMillisecond()+i+j;
- data[i*parallellism+j].changedTime = 0;
- data[i*parallellism+j].runState = Runnable;
- }
- sprintf(threadName, "AsyncThread[%d]", i);
- pThread = NdbThread_Create(threadRoutine,
- (void**)&data[i*parallellism],
- 65535,
- threadName,
- NDB_THREAD_PRIO_LOW);
- if(pThread != 0 && pThread != NULL){
- (&data[i*parallellism])->pThread = pThread;
- } else {
- perror("Failed to create thread");
- rc = NDBT_FAILED;
- }
- }
-
- showTime();
-
- /*--------------------------------*/
- /* Wait for all processes to exit */
- /*--------------------------------*/
- for(i = 0; i < numProcesses; i++) {
- NdbThread_WaitFor(data[i*parallellism].pThread, &tmp);
- NdbThread_Destroy(&data[i*parallellism].pThread);
- }
-
- ndbout_c("All threads have finished");
-
- /*-------------------------------------------*/
- /* Clear all structures for total statistics */
- /*-------------------------------------------*/
- stats.totalTransactions = 0;
- stats.outerTps = 0.0;
-
- for(i = 0; i < NUM_TRANSACTION_TYPES; i++ ) {
- stats.transactions[i].count = 0;
- stats.transactions[i].branchExecuted = 0;
- stats.transactions[i].rollbackExecuted = 0;
- stats.transactions[i].latency.reset();
- }
-
- /*--------------------------------*/
- /* Add the values for all Threads */
- /*--------------------------------*/
- for(i = 0; i < numProcesses; i++) {
- for(k = 0; k<parallellism; k++){
- p = &data[i*parallellism+k].generator;
-
- stats.totalTransactions += p->totalTransactions;
- stats.outerTps += p->outerTps;
-
- for(j = 0; j < NUM_TRANSACTION_TYPES; j++ ) {
- stats.transactions[j].count +=
- p->transactions[j].count;
- stats.transactions[j].branchExecuted +=
- p->transactions[j].branchExecuted;
- stats.transactions[j].rollbackExecuted +=
- p->transactions[j].rollbackExecuted;
- stats.transactions[j].latency +=
- p->transactions[j].latency;
- }
- }
- }
-
- print_stats("Test Results",
- numSeconds,
- 0,
- &stats,
- numProcesses,
- parallellism);
-
- free(data);
-
- NDBT_ProgramExit(rc);
-}
-/***************************************************************
-* I N C L U D E D F I L E S *
-***************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <time.h>
-
-#include "ndb_schema.hpp"
-#include "ndb_error.hpp"
-#include "userInterface.h"
-#include <NdbMutex.h>
-#include <NdbThread.h>
-#include <NdbTick.h>
-#include <NdbApi.hpp>
-#include <NdbOut.hpp>
-
-/***************************************************************
-* L O C A L C O N S T A N T S *
-***************************************************************/
-
-/***************************************************************
-* L O C A L D A T A S T R U C T U R E S *
-***************************************************************/
-
-/***************************************************************
-* L O C A L F U N C T I O N S *
-***************************************************************/
-
-#ifndef NDB_WIN32
-#include <unistd.h>
-#endif
-
-Ndb*
-asyncDbConnect(int parallellism){
- Ndb * pNDB = new Ndb(g_cluster_connection, "TEST_DB");
-
- pNDB->init(parallellism + 1);
-
- while(pNDB->waitUntilReady() != 0){
- }
-
- return pNDB;
-}
-
-void
-asyncDbDisconnect(Ndb* pNDB)
-{
- delete pNDB;
-}
-
-double
-userGetTime(void)
-{
- static bool initialized = false;
- static NDB_TICKS initSecs = 0;
- static Uint32 initMicros = 0;
- double timeValue = 0;
-
- if ( !initialized ) {
- initialized = true;
- NdbTick_CurrentMicrosecond(&initSecs, &initMicros);
- timeValue = 0.0;
- } else {
- NDB_TICKS secs = 0;
- Uint32 micros = 0;
-
- NdbTick_CurrentMicrosecond(&secs, &micros);
- double s = (double)secs - (double)initSecs;
- double us = (double)micros - (double)initMicros;
-
- timeValue = s + (us / 1000000.0);
- }
- return timeValue;
-}
-
-void showTime()
-{
- char buf[128];
- struct tm* tm_now;
- time_t now;
- now = ::time((time_t*)NULL);
- tm_now = ::gmtime(&now);
-
- ::snprintf(buf, 128,
- "%d-%.2d-%.2d %.2d:%.2d:%.2d",
- tm_now->tm_year + 1900,
- tm_now->tm_mon,
- tm_now->tm_mday,
- tm_now->tm_hour,
- tm_now->tm_min,
- tm_now->tm_sec);
-
- ndbout_c("Time: %s", buf);
-}
-
diff --git a/storage/ndb/test/ndbapi/bench/mainPopulate.cpp b/storage/ndb/test/ndbapi/bench/mainPopulate.cpp
deleted file mode 100644
index d9f10ab1ebc..00000000000
--- a/storage/ndb/test/ndbapi/bench/mainPopulate.cpp
+++ /dev/null
@@ -1,81 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-#include <ndb_opts.h>
-
-#include "userInterface.h"
-#include "dbPopulate.h"
-#include <NdbMain.h>
-#include <NdbOut.hpp>
-#include <random.h>
-#include <NDBT.hpp>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-int useTableLogging;
-#ifdef __cplusplus
-}
-#endif
-
-
-static void usage()
-{
-}
-
-static
-void usage(const char *prog)
-{
-
- ndbout_c(
- "Usage: %s [-l]\n"
- " -l Use logging and checkpointing on tables\n",
- prog);
-
- exit(1);
-}
-
-NDB_STD_OPTS_VARS;
-
-NDB_COMMAND(DbCreate, "DbCreate", "DbCreate", "DbCreate", 16384)
-{
- ndb_init();
- int i;
- UserHandle *uh;
-
- useTableLogging = 0;
-
- for(i = 1; i<argc; i++){
- if(strcmp(argv[i], "-l") == 0){
- useTableLogging = 1;
- } else {
- usage(argv[0]);
- return 0;
- }
- }
-
- ndbout_c("Using %s tables",
- useTableLogging ? "logging" : "temporary");
-
- myRandom48Init(0x3e6f);
-
- uh = userDbConnect(1, "TEST_DB");
- dbPopulate(uh);
- userDbDisconnect(uh);
-
- return NDBT_ProgramExit(NDBT_OK);
-}
diff --git a/storage/ndb/test/ndbapi/bench/ndb_async1.cpp b/storage/ndb/test/ndbapi/bench/ndb_async1.cpp
deleted file mode 100644
index f6f4f0bd98e..00000000000
--- a/storage/ndb/test/ndbapi/bench/ndb_async1.cpp
+++ /dev/null
@@ -1,647 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-//#define DEBUG_ON
-
-#include "userInterface.h"
-
-#include "macros.h"
-#include "ndb_schema.hpp"
-#include "ndb_error.hpp"
-
-#include <NdbApi.hpp>
-
-inline
-NdbConnection *
-startTransaction(Ndb * pNDB,
- ServerId inServerId,
- const SubscriberNumber inNumber){
-
- const int keyDataLenBytes = sizeof(ServerId)+SUBSCRIBER_NUMBER_LENGTH;
- const int keyDataLen_64Words = keyDataLenBytes >> 3;
-
- Uint64 keyDataBuf[keyDataLen_64Words+1]; // The "+1" is for rounding...
-
- char * keyDataBuf_charP = (char *)&keyDataBuf[0];
- Uint32 * keyDataBuf_wo32P = (Uint32 *)&keyDataBuf[0];
-
- // Server Id comes first
- keyDataBuf_wo32P[0] = inServerId;
- // Then subscriber number
- memcpy(&keyDataBuf_charP[sizeof(ServerId)], inNumber,
- SUBSCRIBER_NUMBER_LENGTH);
-
- return pNDB->startTransaction(0, keyDataBuf_charP, keyDataLenBytes);
-}
-
-void T1_Callback(int result, NdbConnection * pCon, void * threadData);
-void T2_Callback(int result, NdbConnection * pCon, void * threadData);
-void T3_Callback_1(int result, NdbConnection * pCon, void * threadData);
-void T3_Callback_2(int result, NdbConnection * pCon, void * threadData);
-void T3_Callback_3(int result, NdbConnection * pCon, void * threadData);
-void T4_Callback_1(int result, NdbConnection * pCon, void * threadData);
-void T4_Callback_2(int result, NdbConnection * pCon, void * threadData);
-void T4_Callback_3(int result, NdbConnection * pCon, void * threadData);
-void T5_Callback_1(int result, NdbConnection * pCon, void * threadData);
-void T5_Callback_2(int result, NdbConnection * pCon, void * threadData);
-void T5_Callback_3(int result, NdbConnection * pCon, void * threadData);
-
-/**
- * Transaction 1 - T1
- *
- * Update location and changed by/time on a subscriber
- *
- * Input:
- * SubscriberNumber,
- * Location,
- * ChangedBy,
- * ChangedTime
- *
- * Output:
- */
-void
-start_T1(Ndb * pNDB, ThreadData * td){
-
- DEBUG2("T1(%.*s): - Starting\n", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number);
-
- int check;
- NdbConnection * pCON = pNDB->startTransaction();
- if (pCON != NULL) {
- NdbOperation *MyOp = pCON->getNdbOperation(SUBSCRIBER_TABLE);
- if (MyOp != NULL) {
- MyOp->updateTuple();
- MyOp->equal(IND_SUBSCRIBER_NUMBER,
- td->transactionData.number);
- MyOp->setValue(IND_SUBSCRIBER_LOCATION,
- (char *)&td->transactionData.location);
- MyOp->setValue(IND_SUBSCRIBER_CHANGED_BY,
- td->transactionData.changed_by);
- MyOp->setValue(IND_SUBSCRIBER_CHANGED_TIME,
- td->transactionData.changed_time);
- pCON->executeAsynchPrepare( Commit , T1_Callback, td);
- } else {
- CHECK_NULL(MyOp, "T1: getNdbOperation", pCON);
- }//if
- } else {
- error_handler("T1-1: startTranscation",
- pNDB->getNdbErrorString(),
- pNDB->getNdbError());
- }//if
-}
-
-void
-T1_Callback(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
-
- DEBUG2("T1(%.*s): - Completing\n", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number);
-
- CHECK_MINUS_ONE(result, "T1: Commit",
- pCON);
- td->pNDB->closeTransaction(pCON);
- complete_T1(td);
-}
-
-/**
- * Transaction 2 - T2
- *
- * Read from Subscriber:
- *
- * Input:
- * SubscriberNumber
- *
- * Output:
- * Location
- * Changed by
- * Changed Timestamp
- * Name
- */
-void
-start_T2(Ndb * pNDB, ThreadData * td){
-
- DEBUG3("T2(%.*s, %p): - Starting\n", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.location);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * pCON = pNDB->startTransaction();
- if (pCON == NULL)
- error_handler("T2-1: startTransaction",
- pNDB->getNdbErrorString(),
- pNDB->getNdbError());
-
- NdbOperation *MyOp= pCON->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOp, "T2: getNdbOperation",
- pCON);
-
- MyOp->readTuple();
- MyOp->equal(IND_SUBSCRIBER_NUMBER,
- td->transactionData.number);
- MyOp->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)&td->transactionData.location);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_BY,
- td->transactionData.changed_by);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- td->transactionData.changed_time);
- MyOp->getValue(IND_SUBSCRIBER_NAME,
- td->transactionData.name);
- pCON->executeAsynchPrepare( Commit, T2_Callback, td );
-}
-
-void
-T2_Callback(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
- DEBUG3("T2(%.*s, %p): - Completing\n", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.location);
-
- CHECK_MINUS_ONE(result, "T2: Commit", pCON);
- td->pNDB->closeTransaction(pCON);
- complete_T2(td);
-}
-
-/**
- * Transaction 3 - T3
- *
- * Read session details
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- *
- * Output:
- * BranchExecuted
- * SessionDetails
- * ChangedBy
- * ChangedTime
- * Location
- */
-void
-start_T3(Ndb * pNDB, ThreadData * td){
-
- DEBUG3("T3(%.*s, %.2d): - Starting\n", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * pCON = startTransaction(pNDB,
- td->transactionData.server_id,
- td->transactionData.number);
- if (pCON == NULL)
- error_handler("T3-1: startTranscation",
- pNDB->getNdbErrorString(),
- pNDB->getNdbError());
-
- NdbOperation *MyOp= pCON->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOp, "T3-1: getNdbOperation",
- pCON);
-
- MyOp->readTuple();
- MyOp->equal(IND_SUBSCRIBER_NUMBER,
- td->transactionData.number);
- MyOp->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)&td->transactionData.location);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_BY,
- td->transactionData.changed_by);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- td->transactionData.changed_time);
- MyOp->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&td->transactionData.group_id);
- MyOp->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&td->transactionData.sessions);
- pCON->executeAsynchPrepare( NoCommit , T3_Callback_1, td);
-}
-
-void
-T3_Callback_1(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
- DEBUG3("T3(%.*s, %.2d): - Callback 1\n", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- CHECK_MINUS_ONE(result, "T3-1: NoCommit", pCON);
-
- NdbOperation * MyOp = pCON->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOp, "T3-2: getNdbOperation",
- pCON);
-
- MyOp->readTuple();
- MyOp->equal(IND_GROUP_ID,
- (char*)&td->transactionData.group_id);
- MyOp->getValue(IND_GROUP_ALLOW_READ,
- (char *)&td->transactionData.permission);
- pCON->executeAsynchPrepare( NoCommit, T3_Callback_2, td );
-}
-
-void
-T3_Callback_2(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
-
- CHECK_MINUS_ONE(result, "T3-2: NoCommit", pCON);
-
- Uint32 permission = td->transactionData.permission;
- Uint32 sessions = td->transactionData.sessions;
- Uint32 server_bit = td->transactionData.server_bit;
-
- if(((permission & server_bit) == server_bit) &&
- ((sessions & server_bit) == server_bit)){
-
- memcpy(td->transactionData.suffix,
- &td->transactionData.number
- [SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH],
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
- DEBUG5("T3(%.*s, %.2d): - Callback 2 - reading(%.*s)\n",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id,
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH,
- td->transactionData.suffix);
-
- /* Operation 3 */
- NdbOperation * MyOp = pCON->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOp, "T3-3: getNdbOperation",
- pCON);
-
- MyOp->simpleRead();
- MyOp->equal(IND_SESSION_SUBSCRIBER,
- (char*)td->transactionData.number);
- MyOp->equal(IND_SESSION_SERVER,
- (char*)&td->transactionData.server_id);
- MyOp->getValue(IND_SESSION_DATA,
- (char *)td->transactionData.session_details);
-
- /* Operation 4 */
- MyOp = pCON->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOp, "T3-4: getNdbOperation",
- pCON);
-
- MyOp->interpretedUpdateTuple();
- MyOp->equal(IND_SERVER_ID,
- (char*)&td->transactionData.server_id);
- MyOp->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)td->transactionData.suffix);
- MyOp->incValue(IND_SERVER_READS, (uint32)1);
- td->transactionData.branchExecuted = 1;
- } else {
- DEBUG3("T3(%.*s, %.2d): - Callback 2 - no read\n",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
- td->transactionData.branchExecuted = 0;
- }
- pCON->executeAsynchPrepare( Commit, T3_Callback_3, td );
-}
-
-void
-T3_Callback_3(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
- DEBUG3("T3(%.*s, %.2d): - Completing\n", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- CHECK_MINUS_ONE(result, "T3-3: Commit", pCON);
-
- td->pNDB->closeTransaction(pCON);
- complete_T3(td);
-}
-
-/**
- * Transaction 4 - T4
- *
- * Create session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * SessionDetails,
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-void
-start_T4(Ndb * pNDB, ThreadData * td){
-
- DEBUG3("T4(%.*s, %.2d): - Starting\n", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * pCON = startTransaction(pNDB,
- td->transactionData.server_id,
- td->transactionData.number);
- if (pCON == NULL)
- error_handler("T4-1: startTranscation",
- pNDB->getNdbErrorString(),
- pNDB->getNdbError());
-
- NdbOperation *MyOp= pCON->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOp, "T4-1: getNdbOperation",
- pCON);
-
- MyOp->interpretedUpdateTuple();
- MyOp->equal(IND_SUBSCRIBER_NUMBER,
- td->transactionData.number);
- MyOp->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)&td->transactionData.location);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_BY,
- td->transactionData.changed_by);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- td->transactionData.changed_time);
- MyOp->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&td->transactionData.group_id);
- MyOp->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&td->transactionData.sessions);
- MyOp->incValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)td->transactionData.server_bit);
- pCON->executeAsynchPrepare( NoCommit , T4_Callback_1, td);
-}
-
-void
-T4_Callback_1(int result, NdbConnection * pCON, void * threadData){
- CHECK_MINUS_ONE(result, "T4-1: NoCommit", pCON);
- ThreadData * td = (ThreadData *)threadData;
-
- DEBUG3("T4(%.*s, %.2d): - Callback 1\n",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
-
- NdbOperation * MyOp = pCON->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOp, "T4-2: getNdbOperation",
- pCON);
-
- MyOp->readTuple();
- MyOp->equal(IND_GROUP_ID,
- (char*)&td->transactionData.group_id);
- MyOp->getValue(IND_GROUP_ALLOW_INSERT,
- (char *)&td->transactionData.permission);
- pCON->executeAsynchPrepare( NoCommit , T4_Callback_2, td);
-}
-
-void
-T4_Callback_2(int result, NdbConnection * pCON, void * threadData){
- CHECK_MINUS_ONE(result, "T4-2: NoCommit", pCON);
- ThreadData * td = (ThreadData *)threadData;
-
- Uint32 permission = td->transactionData.permission;
- Uint32 sessions = td->transactionData.sessions;
- Uint32 server_bit = td->transactionData.server_bit;
-
- if(((permission & server_bit) == server_bit) &&
- ((sessions & server_bit) == 0)){
-
- memcpy(td->transactionData.suffix,
- &td->transactionData.number
- [SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH],
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
-
- DEBUG5("T4(%.*s, %.2d): - Callback 2 - inserting(%.*s)\n",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id,
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH,
- td->transactionData.suffix);
-
- /* Operation 3 */
-
- NdbOperation * MyOp = pCON->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOp, "T4-3: getNdbOperation",
- pCON);
-
- MyOp->insertTuple();
- MyOp->equal(IND_SESSION_SUBSCRIBER,
- (char*)td->transactionData.number);
- MyOp->equal(IND_SESSION_SERVER,
- (char*)&td->transactionData.server_id);
- MyOp->setValue(SESSION_DATA,
- (char *)td->transactionData.session_details);
- /* Operation 4 */
-
- /* Operation 5 */
- MyOp = pCON->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOp, "T4-5: getNdbOperation",
- pCON);
-
- MyOp->interpretedUpdateTuple();
- MyOp->equal(IND_SERVER_ID,
- (char*)&td->transactionData.server_id);
- MyOp->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)td->transactionData.suffix);
- MyOp->incValue(IND_SERVER_INSERTS, (uint32)1);
- td->transactionData.branchExecuted = 1;
- } else {
- td->transactionData.branchExecuted = 0;
- DEBUG5("T4(%.*s, %.2d): - Callback 2 - %s %s\n",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id,
- ((permission & server_bit) ?
- "permission - " : "no permission - "),
- ((sessions & server_bit) ?
- "in session - " : "no in session - "));
- }
-
- if(!td->transactionData.do_rollback && td->transactionData.branchExecuted){
- pCON->executeAsynchPrepare(Commit, T4_Callback_3, td);
- } else {
- pCON->executeAsynchPrepare(Rollback, T4_Callback_3, td);
- }
-}
-
-void
-T4_Callback_3(int result, NdbConnection * pCON, void * threadData){
- CHECK_MINUS_ONE(result, "T4-3: Commit", pCON);
- ThreadData * td = (ThreadData *)threadData;
-
- DEBUG3("T4(%.*s, %.2d): - Completing\n",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- td->pNDB->closeTransaction(pCON);
- complete_T4(td);
-}
-
-/**
- * Transaction 5 - T5
- *
- * Delete session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-void
-start_T5(Ndb * pNDB, ThreadData * td){
-
- DEBUG3("T5(%.*s, %.2d): - Starting\n", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * pCON = pNDB->startTransaction();
- if (pCON == NULL)
- error_handler("T5-1: startTranscation",
- pNDB->getNdbErrorString(),
- pNDB->getNdbError());
-
- NdbOperation * MyOp= pCON->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOp, "T5-1: getNdbOperation",
- pCON);
-
- MyOp->interpretedUpdateTuple();
- MyOp->equal(IND_SUBSCRIBER_NUMBER,
- td->transactionData.number);
- MyOp->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)&td->transactionData.location);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_BY,
- td->transactionData.changed_by);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- td->transactionData.changed_time);
- MyOp->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&td->transactionData.group_id);
- MyOp->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&td->transactionData.sessions);
- MyOp->subValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)td->transactionData.server_bit);
- pCON->executeAsynchPrepare( NoCommit, T5_Callback_1, td );
-}
-
-void
-T5_Callback_1(int result, NdbConnection * pCON, void * threadData){
- CHECK_MINUS_ONE(result, "T5-1: NoCommit", pCON);
- ThreadData * td = (ThreadData *)threadData;
-
- DEBUG3("T5(%.*s, %.2d): - Callback 1\n",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- NdbOperation * MyOp = pCON->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOp, "T5-2: getNdbOperation",
- pCON);
-
- MyOp->readTuple();
- MyOp->equal(IND_GROUP_ID,
- (char*)&td->transactionData.group_id);
- MyOp->getValue(IND_GROUP_ALLOW_DELETE,
- (char *)&td->transactionData.permission);
- pCON->executeAsynchPrepare( NoCommit, T5_Callback_2, td );
-}
-
-void
-T5_Callback_2(int result, NdbConnection * pCON, void * threadData){
- CHECK_MINUS_ONE(result, "T5-2: NoCommit", pCON);
- ThreadData * td = (ThreadData *)threadData;
-
- Uint32 permission = td->transactionData.permission;
- Uint32 sessions = td->transactionData.sessions;
- Uint32 server_bit = td->transactionData.server_bit;
-
- if(((permission & server_bit) == server_bit) &&
- ((sessions & server_bit) == server_bit)){
-
- memcpy(td->transactionData.suffix,
- &td->transactionData.number
- [SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH],
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
-
- DEBUG5("T5(%.*s, %.2d): - Callback 2 - deleting(%.*s)\n",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id,
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH,
- td->transactionData.suffix);
-
- /* Operation 3 */
- NdbOperation * MyOp = pCON->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOp, "T5-3: getNdbOperation",
- pCON);
-
- MyOp->deleteTuple();
- MyOp->equal(IND_SESSION_SUBSCRIBER,
- (char*)td->transactionData.number);
- MyOp->equal(IND_SESSION_SERVER,
- (char*)&td->transactionData.server_id);
- /* Operation 4 */
-
- /* Operation 5 */
- MyOp = pCON->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOp, "T5-5: getNdbOperation",
- pCON);
-
- MyOp->interpretedUpdateTuple();
- MyOp->equal(IND_SERVER_ID,
- (char*)&td->transactionData.server_id);
- MyOp->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)td->transactionData.suffix);
- MyOp->incValue(IND_SERVER_DELETES, (uint32)1);
- td->transactionData.branchExecuted = 1;
- } else {
- td->transactionData.branchExecuted = 0;
-
- DEBUG5("T5(%.*s, %.2d): - Callback 2 - no delete - %s %s\n",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id,
- ((permission & server_bit) ?
- "permission - " : "no permission - "),
- ((sessions & server_bit) ?
- "in session - " : "no in session - "));
- }
-
- if(!td->transactionData.do_rollback && td->transactionData.branchExecuted){
- pCON->executeAsynchPrepare(Commit, T5_Callback_3, td);
- } else {
- pCON->executeAsynchPrepare(Rollback, T5_Callback_3, td);
- }
-}
-
-void
-T5_Callback_3(int result, NdbConnection * pCON, void * threadData){
- CHECK_MINUS_ONE(result, "T5-3: Commit", pCON);
- ThreadData * td = (ThreadData *)threadData;
-
- DEBUG3("T5(%.*s, %.2d): - Completing\n",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- td->pNDB->closeTransaction(pCON);
- complete_T5(td);
-}
diff --git a/storage/ndb/test/ndbapi/bench/ndb_async2.cpp b/storage/ndb/test/ndbapi/bench/ndb_async2.cpp
deleted file mode 100644
index c1316967904..00000000000
--- a/storage/ndb/test/ndbapi/bench/ndb_async2.cpp
+++ /dev/null
@@ -1,757 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-//#define DEBUG_ON
-
-#include <string.h>
-#include "userInterface.h"
-
-#include "macros.h"
-#include "ndb_schema.hpp"
-#include "ndb_error.hpp"
-#include <NdbSleep.h>
-
-#include <NdbApi.hpp>
-
-void T1_Callback(int result, NdbConnection * pCon, void * threadData);
-void T2_Callback(int result, NdbConnection * pCon, void * threadData);
-void T3_Callback_1(int result, NdbConnection * pCon, void * threadData);
-void T3_Callback_2(int result, NdbConnection * pCon, void * threadData);
-void T3_Callback_3(int result, NdbConnection * pCon, void * threadData);
-void T4_Callback_1(int result, NdbConnection * pCon, void * threadData);
-void T4_Callback_2(int result, NdbConnection * pCon, void * threadData);
-void T4_Callback_3(int result, NdbConnection * pCon, void * threadData);
-void T5_Callback_1(int result, NdbConnection * pCon, void * threadData);
-void T5_Callback_2(int result, NdbConnection * pCon, void * threadData);
-void T5_Callback_3(int result, NdbConnection * pCon, void * threadData);
-
-static int stat_async = 0;
-
-/**
- * Transaction 1 - T1
- *
- * Update location and changed by/time on a subscriber
- *
- * Input:
- * SubscriberNumber,
- * Location,
- * ChangedBy,
- * ChangedTime
- *
- * Output:
- */
-
-#define SFX_START (SUBSCRIBER_NUMBER_LENGTH - SUBSCRIBER_NUMBER_SUFFIX_LENGTH)
-
-inline
-NdbConnection *
-startTransaction(Ndb * pNDB, ThreadData * td){
- return pNDB->startTransaction();
-#ifdef OLD_CODE
- return pNDB->startTransactionDGroup (0,
- &td->transactionData.number[SFX_START],
- 1);
-#endif
-}
-
-void
-start_T1(Ndb * pNDB, ThreadData * td, int async){
-
- DEBUG2("T1(%.*s): - Starting", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number);
-
- NdbConnection * pCON = 0;
- while((pCON = startTransaction(pNDB, td)) == 0){
- CHECK_ALLOWED_ERROR("T1: startTransaction", td, pNDB->getNdbError());
- NdbSleep_MilliSleep(10);
- }
-
- NdbOperation *MyOp = pCON->getNdbOperation(SUBSCRIBER_TABLE);
- if (MyOp != NULL) {
- MyOp->updateTuple();
- MyOp->equal(IND_SUBSCRIBER_NUMBER,
- td->transactionData.number);
- MyOp->setValue(IND_SUBSCRIBER_LOCATION,
- (char *)&td->transactionData.location);
- MyOp->setValue(IND_SUBSCRIBER_CHANGED_BY,
- td->transactionData.changed_by);
- MyOp->setValue(IND_SUBSCRIBER_CHANGED_TIME,
- td->transactionData.changed_time);
- if (async == 1) {
- pCON->executeAsynchPrepare( Commit , T1_Callback, td);
- } else {
- int result = pCON->execute(Commit);
- T1_Callback(result, pCON, (void*)td);
- return;
- }//if
- } else {
- CHECK_NULL(MyOp, "T1: getNdbOperation", td, pCON->getNdbError());
- }//if
-}
-
-void
-T1_Callback(int result, NdbConnection * pCON, void * threadData) {
- ThreadData * td = (ThreadData *)threadData;
-
- DEBUG2("T1(%.*s): - Completing", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number);
-
- if (result == -1) {
- CHECK_ALLOWED_ERROR("T1: Commit", td, pCON->getNdbError());
- td->pNDB->closeTransaction(pCON);
- start_T1(td->pNDB, td, stat_async);
- return;
- }//if
- td->pNDB->closeTransaction(pCON);
- complete_T1(td);
-}
-
-/**
- * Transaction 2 - T2
- *
- * Read from Subscriber:
- *
- * Input:
- * SubscriberNumber
- *
- * Output:
- * Location
- * Changed by
- * Changed Timestamp
- * Name
- */
-void
-start_T2(Ndb * pNDB, ThreadData * td, int async){
-
- DEBUG3("T2(%.*s, %d): - Starting", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.location);
-
- NdbConnection * pCON = 0;
-
- while((pCON = startTransaction(pNDB, td)) == 0){
- CHECK_ALLOWED_ERROR("T2-1: startTransaction", td, pNDB->getNdbError());
- NdbSleep_MilliSleep(10);
- }
-
- NdbOperation *MyOp= pCON->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOp, "T2: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->readTuple();
- MyOp->equal(IND_SUBSCRIBER_NUMBER,
- td->transactionData.number);
- MyOp->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)&td->transactionData.location);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_BY,
- td->transactionData.changed_by);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- td->transactionData.changed_time);
- MyOp->getValue(IND_SUBSCRIBER_NAME,
- td->transactionData.name);
- if (async == 1) {
- pCON->executeAsynchPrepare( Commit , T2_Callback, td);
- } else {
- int result = pCON->execute(Commit);
- T2_Callback(result, pCON, (void*)td);
- return;
- }//if
-}
-
-void
-T2_Callback(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
- DEBUG3("T2(%.*s, %d): - Completing", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.location);
-
- if (result == -1) {
- CHECK_ALLOWED_ERROR("T2: Commit", td, pCON->getNdbError());
- td->pNDB->closeTransaction(pCON);
- start_T2(td->pNDB, td, stat_async);
- return;
- }//if
- td->pNDB->closeTransaction(pCON);
- complete_T2(td);
-}
-
-/**
- * Transaction 3 - T3
- *
- * Read session details
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- *
- * Output:
- * BranchExecuted
- * SessionDetails
- * ChangedBy
- * ChangedTime
- * Location
- */
-void
-start_T3(Ndb * pNDB, ThreadData * td, int async){
-
- DEBUG3("T3(%.*s, %.2d): - Starting", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- NdbConnection * pCON = 0;
-
- while((pCON = startTransaction(pNDB, td)) == 0){
- CHECK_ALLOWED_ERROR("T3-1: startTransaction", td, pNDB->getNdbError());
- NdbSleep_MilliSleep(10);
- }
-
- NdbOperation *MyOp= pCON->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOp, "T3-1: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->readTuple();
- MyOp->equal(IND_SUBSCRIBER_NUMBER,
- td->transactionData.number);
- MyOp->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)&td->transactionData.location);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_BY,
- td->transactionData.changed_by);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- td->transactionData.changed_time);
- MyOp->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&td->transactionData.group_id);
- MyOp->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&td->transactionData.sessions);
- stat_async = async;
- if (async == 1) {
- pCON->executeAsynchPrepare( NoCommit , T3_Callback_1, td);
- } else {
- int result = pCON->execute( NoCommit );
- T3_Callback_1(result, pCON, (void*)td);
- return;
- }//if
-}
-
-void
-T3_Callback_1(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
- DEBUG3("T3(%.*s, %.2d): - Callback 1", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- if (result == -1) {
- CHECK_ALLOWED_ERROR("T3-1: execute", td, pCON->getNdbError());
- td->pNDB->closeTransaction(pCON);
- start_T3(td->pNDB, td, stat_async);
- return;
- }//if
-
- NdbOperation * MyOp = pCON->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOp, "T3-2: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->readTuple();
- MyOp->equal(IND_GROUP_ID,
- (char*)&td->transactionData.group_id);
- MyOp->getValue(IND_GROUP_ALLOW_READ,
- (char *)&td->transactionData.permission);
- if (stat_async == 1) {
- pCON->executeAsynchPrepare( NoCommit , T3_Callback_2, td);
- } else {
- int result = pCON->execute( NoCommit );
- T3_Callback_2(result, pCON, (void*)td);
- return;
- }//if
-}
-
-void
-T3_Callback_2(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
-
- if (result == -1) {
- CHECK_ALLOWED_ERROR("T3-2: execute", td, pCON->getNdbError());
- td->pNDB->closeTransaction(pCON);
- start_T3(td->pNDB, td, stat_async);
- return;
- }//if
-
- Uint32 permission = td->transactionData.permission;
- Uint32 sessions = td->transactionData.sessions;
- Uint32 server_bit = td->transactionData.server_bit;
-
- if(((permission & server_bit) == server_bit) &&
- ((sessions & server_bit) == server_bit)){
-
- memcpy(td->transactionData.suffix,
- &td->transactionData.number[SFX_START],
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
- DEBUG5("T3(%.*s, %.2d): - Callback 2 - reading(%.*s)",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id,
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH,
- td->transactionData.suffix);
-
- /* Operation 3 */
- NdbOperation * MyOp = pCON->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOp, "T3-3: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->simpleRead();
- MyOp->equal(IND_SESSION_SUBSCRIBER,
- (char*)td->transactionData.number);
- MyOp->equal(IND_SESSION_SERVER,
- (char*)&td->transactionData.server_id);
- MyOp->getValue(IND_SESSION_DATA,
- (char *)td->transactionData.session_details);
-
- /* Operation 4 */
- MyOp = pCON->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOp, "T3-4: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->interpretedUpdateTuple();
- MyOp->equal(IND_SERVER_ID,
- (char*)&td->transactionData.server_id);
- MyOp->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)td->transactionData.suffix);
- MyOp->incValue(IND_SERVER_READS, (uint32)1);
- td->transactionData.branchExecuted = 1;
- } else {
- DEBUG3("T3(%.*s, %.2d): - Callback 2 - no read",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
- td->transactionData.branchExecuted = 0;
- }
- if (stat_async == 1) {
- pCON->executeAsynchPrepare( Commit , T3_Callback_3, td);
- } else {
- int result = pCON->execute( Commit );
- T3_Callback_3(result, pCON, (void*)td);
- return;
- }//if
-}
-
-void
-T3_Callback_3(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
- DEBUG3("T3(%.*s, %.2d): - Completing", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- if (result == -1) {
- CHECK_ALLOWED_ERROR("T3-3: Commit", td, pCON->getNdbError());
- td->pNDB->closeTransaction(pCON);
- start_T3(td->pNDB, td, stat_async);
- return;
- }//if
- td->pNDB->closeTransaction(pCON);
- complete_T3(td);
-}
-
-/**
- * Transaction 4 - T4
- *
- * Create session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * SessionDetails,
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-void
-start_T4(Ndb * pNDB, ThreadData * td, int async){
-
- DEBUG3("T4(%.*s, %.2d): - Starting", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- NdbConnection * pCON = 0;
- while((pCON = startTransaction(pNDB, td)) == 0){
- CHECK_ALLOWED_ERROR("T4-1: startTransaction", td, pNDB->getNdbError());
- NdbSleep_MilliSleep(10);
- }
-
- NdbOperation *MyOp= pCON->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOp, "T4-1: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->interpretedUpdateTuple();
- MyOp->equal(IND_SUBSCRIBER_NUMBER,
- td->transactionData.number);
- MyOp->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)&td->transactionData.location);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_BY,
- td->transactionData.changed_by);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- td->transactionData.changed_time);
- MyOp->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&td->transactionData.group_id);
- MyOp->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&td->transactionData.sessions);
- MyOp->incValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)td->transactionData.server_bit);
- stat_async = async;
- if (async == 1) {
- pCON->executeAsynchPrepare( NoCommit , T4_Callback_1, td);
- } else {
- int result = pCON->execute( NoCommit );
- T4_Callback_1(result, pCON, (void*)td);
- return;
- }//if
-}
-
-void
-T4_Callback_1(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
- if (result == -1) {
- CHECK_ALLOWED_ERROR("T4-1: execute", td, pCON->getNdbError());
- td->pNDB->closeTransaction(pCON);
- start_T4(td->pNDB, td, stat_async);
- return;
- }//if
-
- DEBUG3("T4(%.*s, %.2d): - Callback 1",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
-
- NdbOperation * MyOp = pCON->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOp, "T4-2: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->readTuple();
- MyOp->equal(IND_GROUP_ID,
- (char*)&td->transactionData.group_id);
- MyOp->getValue(IND_GROUP_ALLOW_INSERT,
- (char *)&td->transactionData.permission);
- if (stat_async == 1) {
- pCON->executeAsynchPrepare( NoCommit , T4_Callback_2, td);
- } else {
- int result = pCON->execute( NoCommit );
- T4_Callback_2(result, pCON, (void*)td);
- return;
- }//if
-}
-
-void
-T4_Callback_2(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
- if (result == -1) {
- CHECK_ALLOWED_ERROR("T4-2: execute", td, pCON->getNdbError());
- td->pNDB->closeTransaction(pCON);
- start_T4(td->pNDB, td, stat_async);
- return;
- }//if
-
- Uint32 permission = td->transactionData.permission;
- Uint32 sessions = td->transactionData.sessions;
- Uint32 server_bit = td->transactionData.server_bit;
-
- if(((permission & server_bit) == server_bit) &&
- ((sessions & server_bit) == 0)){
-
- memcpy(td->transactionData.suffix,
- &td->transactionData.number[SFX_START],
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
-
- DEBUG5("T4(%.*s, %.2d): - Callback 2 - inserting(%.*s)",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id,
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH,
- td->transactionData.suffix);
-
- /* Operation 3 */
-
- NdbOperation * MyOp = pCON->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOp, "T4-3: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->insertTuple();
- MyOp->equal(IND_SESSION_SUBSCRIBER,
- (char*)td->transactionData.number);
- MyOp->equal(IND_SESSION_SERVER,
- (char*)&td->transactionData.server_id);
- MyOp->setValue(SESSION_DATA,
- (char *)td->transactionData.session_details);
- /* Operation 4 */
-
- /* Operation 5 */
- MyOp = pCON->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOp, "T4-5: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->interpretedUpdateTuple();
- MyOp->equal(IND_SERVER_ID,
- (char*)&td->transactionData.server_id);
- MyOp->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)td->transactionData.suffix);
- MyOp->incValue(IND_SERVER_INSERTS, (uint32)1);
- td->transactionData.branchExecuted = 1;
- } else {
- td->transactionData.branchExecuted = 0;
- DEBUG5("T4(%.*s, %.2d): - Callback 2 - %s %s",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id,
- ((permission & server_bit) ?
- "permission - " : "no permission - "),
- ((sessions & server_bit) ?
- "in session - " : "no in session - "));
- }
-
- if(!td->transactionData.do_rollback && td->transactionData.branchExecuted){
- if (stat_async == 1) {
- pCON->executeAsynchPrepare( Commit , T4_Callback_3, td);
- } else {
- int result = pCON->execute( Commit );
- T4_Callback_3(result, pCON, (void*)td);
- return;
- }//if
- } else {
- if (stat_async == 1) {
- pCON->executeAsynchPrepare( Rollback , T4_Callback_3, td);
- } else {
- int result = pCON->execute( Rollback );
- T4_Callback_3(result, pCON, (void*)td);
- return;
- }//if
- }
-}
-
-void
-T4_Callback_3(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
- if (result == -1) {
- CHECK_ALLOWED_ERROR("T4-3: Commit", td, pCON->getNdbError());
- td->pNDB->closeTransaction(pCON);
- start_T4(td->pNDB, td, stat_async);
- return;
- }//if
-
- DEBUG3("T4(%.*s, %.2d): - Completing",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- td->pNDB->closeTransaction(pCON);
- complete_T4(td);
-}
-
-/**
- * Transaction 5 - T5
- *
- * Delete session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-void
-start_T5(Ndb * pNDB, ThreadData * td, int async){
-
- DEBUG3("T5(%.*s, %.2d): - Starting", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- NdbConnection * pCON = 0;
- while((pCON = startTransaction(pNDB, td)) == 0){
- CHECK_ALLOWED_ERROR("T5-1: startTransaction", td, pNDB->getNdbError());
- NdbSleep_MilliSleep(10);
- }
-
- NdbOperation * MyOp= pCON->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOp, "T5-1: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->interpretedUpdateTuple();
- MyOp->equal(IND_SUBSCRIBER_NUMBER,
- td->transactionData.number);
- MyOp->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)&td->transactionData.location);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_BY,
- td->transactionData.changed_by);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- td->transactionData.changed_time);
- MyOp->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&td->transactionData.group_id);
- MyOp->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&td->transactionData.sessions);
- MyOp->subValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)td->transactionData.server_bit);
- stat_async = async;
- if (async == 1) {
- pCON->executeAsynchPrepare( NoCommit , T5_Callback_1, td);
- } else {
- int result = pCON->execute( NoCommit );
- T5_Callback_1(result, pCON, (void*)td);
- return;
- }//if
-}
-
-void
-T5_Callback_1(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
- if (result == -1) {
- CHECK_ALLOWED_ERROR("T5-1: execute", td, pCON->getNdbError());
- td->pNDB->closeTransaction(pCON);
- start_T5(td->pNDB, td, stat_async);
- return;
- }//if
-
- DEBUG3("T5(%.*s, %.2d): - Callback 1",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- NdbOperation * MyOp = pCON->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOp, "T5-2: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->readTuple();
- MyOp->equal(IND_GROUP_ID,
- (char*)&td->transactionData.group_id);
- MyOp->getValue(IND_GROUP_ALLOW_DELETE,
- (char *)&td->transactionData.permission);
- if (stat_async == 1) {
- pCON->executeAsynchPrepare( NoCommit , T5_Callback_2, td);
- } else {
- int result = pCON->execute( NoCommit );
- T5_Callback_2(result, pCON, (void*)td);
- return;
- }//if
-}
-
-void
-T5_Callback_2(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
- if (result == -1) {
- CHECK_ALLOWED_ERROR("T5-2: execute", td, pCON->getNdbError());
- td->pNDB->closeTransaction(pCON);
- start_T5(td->pNDB, td, stat_async);
- return;
- }//if
-
- Uint32 permission = td->transactionData.permission;
- Uint32 sessions = td->transactionData.sessions;
- Uint32 server_bit = td->transactionData.server_bit;
-
- if(((permission & server_bit) == server_bit) &&
- ((sessions & server_bit) == server_bit)){
-
- memcpy(td->transactionData.suffix,
- &td->transactionData.number[SFX_START],
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
-
- DEBUG5("T5(%.*s, %.2d): - Callback 2 - deleting(%.*s)",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id,
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH,
- td->transactionData.suffix);
-
- /* Operation 3 */
- NdbOperation * MyOp = pCON->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOp, "T5-3: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->deleteTuple();
- MyOp->equal(IND_SESSION_SUBSCRIBER,
- (char*)td->transactionData.number);
- MyOp->equal(IND_SESSION_SERVER,
- (char*)&td->transactionData.server_id);
- /* Operation 4 */
-
- /* Operation 5 */
- MyOp = pCON->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOp, "T5-5: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->interpretedUpdateTuple();
- MyOp->equal(IND_SERVER_ID,
- (char*)&td->transactionData.server_id);
- MyOp->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)td->transactionData.suffix);
- MyOp->incValue(IND_SERVER_DELETES, (uint32)1);
- td->transactionData.branchExecuted = 1;
- } else {
- td->transactionData.branchExecuted = 0;
-
- DEBUG5("T5(%.*s, %.2d): - Callback 2 - no delete - %s %s",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id,
- ((permission & server_bit) ?
- "permission - " : "no permission - "),
- ((sessions & server_bit) ?
- "in session - " : "no in session - "));
- }
-
- if(!td->transactionData.do_rollback && td->transactionData.branchExecuted){
- if (stat_async == 1) {
- pCON->executeAsynchPrepare( Commit , T5_Callback_3, td);
- } else {
- int result = pCON->execute( Commit );
- T5_Callback_3(result, pCON, (void*)td);
- return;
- }//if
- } else {
- if (stat_async == 1) {
- pCON->executeAsynchPrepare( Rollback , T5_Callback_3, td);
- } else {
- int result = pCON->execute( Rollback );
- T5_Callback_3(result, pCON, (void*)td);
- return;
- }//if
- }
-}
-
-void
-T5_Callback_3(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
- if (result == -1) {
- CHECK_ALLOWED_ERROR("T5-3: Commit", td, pCON->getNdbError());
- td->pNDB->closeTransaction(pCON);
- start_T5(td->pNDB, td, stat_async);
- return;
- }//if
-
- DEBUG3("T5(%.*s, %.2d): - Completing",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- td->pNDB->closeTransaction(pCON);
- complete_T5(td);
-}
diff --git a/storage/ndb/test/ndbapi/bench/ndb_error.hpp b/storage/ndb/test/ndbapi/bench/ndb_error.hpp
deleted file mode 100644
index 67e6b92de7a..00000000000
--- a/storage/ndb/test/ndbapi/bench/ndb_error.hpp
+++ /dev/null
@@ -1,81 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NDB_ERROR_H
-#define NDB_ERROR_H
-
-#include <ndb_global.h>
-#include <NdbOut.hpp>
-#include "userInterface.h"
-#include <NdbError.hpp>
-#include <NdbApi.hpp>
-
-#define error_handler(x,y, z) { \
- ndbout << x << " " << y << endl; \
- exit(-1); }
-
-#define CHECK_MINUS_ONE(x, y, z) if(x == -1) \
- error_handler(y,(z->getNdbError()), 0)
-
-inline
-void
-CHECK_ALLOWED_ERROR(const char * str,
- const ThreadData * td,
- const struct NdbError & error){
-
- char buf[100];
- snprintf(buf, sizeof(buf), "subscriber = %.*s ",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number);
- ndbout << str << " " << error << endl
- << buf;
- showTime();
-
- switch(error.classification) {
- case NdbError::TimeoutExpired:
- case NdbError::OverloadError:
- case NdbError::TemporaryResourceError:
- case NdbError::NodeRecoveryError:
- break;
- default:
- if(error.status != NdbError::TemporaryError)
- exit(-1);
- }
-}
-
-inline
-void
-CHECK_NULL(void * null,
- const char * str,
- const ThreadData * td,
- const struct NdbError & err){
- if(null == 0){
- CHECK_ALLOWED_ERROR(str, td, err);
- exit(-1);
- }
-}
-
-inline
-void
-CHECK_NULL(void * null, const char* msg, NdbConnection* obj)
-{
- if(null == 0)
- {
- error_handler(msg, obj->getNdbError(), 0);
- }
-}
-
-#endif
diff --git a/storage/ndb/test/ndbapi/bench/ndb_schema.hpp b/storage/ndb/test/ndbapi/bench/ndb_schema.hpp
deleted file mode 100644
index 8c114cd3c3c..00000000000
--- a/storage/ndb/test/ndbapi/bench/ndb_schema.hpp
+++ /dev/null
@@ -1,78 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef NDB_SCHEMA_H
-#define NDB_SCHEMA_H
-
-#include "testDefinitions.h"
-
-#define SUBSCRIBER_TABLE "SUBSCRIBER"
-#define SUBSCRIBER_NUMBER "NUMBER"
-#define SUBSCRIBER_LOCATION "LOCATION"
-#define SUBSCRIBER_NAME "NAME"
-#define SUBSCRIBER_GROUP "GROUP_ID"
-#define SUBSCRIBER_SESSIONS "SESSIONS"
-#define SUBSCRIBER_CHANGED_BY "CHANGED_BY"
-#define SUBSCRIBER_CHANGED_TIME "CHANGED_TIME"
-
-#define SERVER_TABLE "SERVER"
-#define SERVER_ID "SERVER_ID"
-#define SERVER_SUBSCRIBER_SUFFIX "SUFFIX"
-#define SERVER_NAME "NAME"
-#define SERVER_READS "NO_OF_READ"
-#define SERVER_INSERTS "NO_OF_INSERT"
-#define SERVER_DELETES "NO_OF_DELETE"
-
-#define GROUP_TABLE "GROUP_T"
-#define GROUP_ID "GROUP_ID"
-#define GROUP_NAME "GROUP_NAME"
-#define GROUP_ALLOW_READ "ALLOW_READ"
-#define GROUP_ALLOW_INSERT "ALLOW_INSERT"
-#define GROUP_ALLOW_DELETE "ALLOW_DELETE"
-
-#define SESSION_TABLE "SESSION"
-#define SESSION_SERVER "SERVER_ID"
-#define SESSION_SUBSCRIBER "NUMBER"
-#define SESSION_DATA "DATA"
-
-/** Numbers */
-
-#define IND_SUBSCRIBER_NUMBER (unsigned)0
-#define IND_SUBSCRIBER_NAME (unsigned)1
-#define IND_SUBSCRIBER_GROUP (unsigned)2
-#define IND_SUBSCRIBER_LOCATION (unsigned)3
-#define IND_SUBSCRIBER_SESSIONS (unsigned)4
-#define IND_SUBSCRIBER_CHANGED_BY (unsigned)5
-#define IND_SUBSCRIBER_CHANGED_TIME (unsigned)6
-
-#define IND_SERVER_SUBSCRIBER_SUFFIX (unsigned)0
-#define IND_SERVER_ID (unsigned)1
-#define IND_SERVER_NAME (unsigned)2
-#define IND_SERVER_READS (unsigned)3
-#define IND_SERVER_INSERTS (unsigned)4
-#define IND_SERVER_DELETES (unsigned)5
-
-#define IND_GROUP_ID (unsigned)0
-#define IND_GROUP_NAME (unsigned)1
-#define IND_GROUP_ALLOW_READ (unsigned)2
-#define IND_GROUP_ALLOW_INSERT (unsigned)3
-#define IND_GROUP_ALLOW_DELETE (unsigned)4
-
-#define IND_SESSION_SUBSCRIBER (unsigned)0
-#define IND_SESSION_SERVER (unsigned)1
-#define IND_SESSION_DATA (unsigned)2
-
-#endif
diff --git a/storage/ndb/test/ndbapi/bench/ndb_user_transaction.cpp b/storage/ndb/test/ndbapi/bench/ndb_user_transaction.cpp
deleted file mode 100644
index 0b3d777ba78..00000000000
--- a/storage/ndb/test/ndbapi/bench/ndb_user_transaction.cpp
+++ /dev/null
@@ -1,825 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-//#define DEBUG_ON
-
-extern "C" {
-#include "user_transaction.h"
-};
-
-#include "macros.h"
-#include "ndb_schema.hpp"
-#include "ndb_error.hpp"
-
-#include <time.h>
-#include <NdbApi.hpp>
-
-/**
- * Transaction 1 - T1
- *
- * Update location and changed by/time on a subscriber
- *
- * Input:
- * SubscriberNumber,
- * Location,
- * ChangedBy,
- * ChangedTime
- *
- * Output:
- */
-int
-T1(void * obj,
- const SubscriberNumber number,
- const Location new_location,
- const ChangedBy changed_by,
- const ChangedTime changed_time,
- BenchmarkTime * transaction_time){
-
- Ndb * pNDB = (Ndb *) obj;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T1: getNdbOperation", MyTransaction);
-
- check = MyOperation->updateTuple();
- CHECK_MINUS_ONE(check, "T1: updateTuple",
- MyTransaction);
-
- check = MyOperation->equal(SUBSCRIBER_NUMBER,
- number);
- CHECK_MINUS_ONE(check, "T1: equal subscriber",
- MyTransaction);
-
- check = MyOperation->setValue(SUBSCRIBER_LOCATION,
- (char *)&new_location);
- CHECK_MINUS_ONE(check, "T1: setValue location",
- MyTransaction);
-
- check = MyOperation->setValue(SUBSCRIBER_CHANGED_BY,
- changed_by);
- CHECK_MINUS_ONE(check, "T1: setValue changed_by",
- MyTransaction);
-
- check = MyOperation->setValue(SUBSCRIBER_CHANGED_TIME,
- changed_time);
- CHECK_MINUS_ONE(check, "T1: setValue changed_time",
- MyTransaction);
-
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T1: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(transaction_time);
- time_diff(transaction_time, &start);
- return 0;
-}
-
-/**
- * Transaction 2 - T2
- *
- * Read from Subscriber:
- *
- * Input:
- * SubscriberNumber
- *
- * Output:
- * Location
- * Changed by
- * Changed Timestamp
- * Name
- */
-int
-T2(void * obj,
- const SubscriberNumber number,
- Location * readLocation,
- ChangedBy changed_by,
- ChangedTime changed_time,
- SubscriberName subscriberName,
- BenchmarkTime * transaction_time){
-
- Ndb * pNDB = (Ndb *) obj;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T2: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(SUBSCRIBER_NUMBER,
- number);
- CHECK_MINUS_ONE(check, "T2: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_LOCATION,
- (char *)readLocation);
- CHECK_NULL(check2, "T2: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_CHANGED_BY,
- changed_by);
- CHECK_NULL(check2, "T2: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_CHANGED_TIME,
- changed_time);
- CHECK_NULL(check2, "T2: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_NAME,
- subscriberName);
- CHECK_NULL(check2, "T2: getValue name",
- MyTransaction);
-
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T2: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(transaction_time);
- time_diff(transaction_time, &start);
- return 0;
-}
-
-/**
- * Transaction 3 - T3
- *
- * Read session details
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- *
- * Output:
- * BranchExecuted
- * SessionDetails
- * ChangedBy
- * ChangedTime
- * Location
- */
-int
-T3(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- SessionDetails outSessionDetails,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- Ndb * pNDB = (Ndb *) obj;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T3-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T3-1: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T3-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T3-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T3-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T3-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T3-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T3-1: getValue sessions",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T3-2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T3-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(GROUP_ALLOW_READ,
- (char *)&permission);
- CHECK_NULL(check2, "T3-2: getValue allow_read",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-2: NoCommit",
- MyTransaction);
-
- DEBUG3("T3(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == inServerBit)){
-
- DEBUG("reading - ");
-
- /* Operation 3 */
-
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T3-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-3: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T3-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T3-3: equal server id",
- MyTransaction);
-
- check2 = MyOperation->getValue(SESSION_DATA,
- (char *)outSessionDetails);
- CHECK_NULL(check2, "T3-3: getValue session details",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-3: NoCommit",
- MyTransaction);
-
- /* Operation 4 */
-
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T3-4: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T3-4: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T3-4: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T3-4: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(SERVER_READS, (uint32)1);
- CHECK_MINUS_ONE(check, "T3-4: inc value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-4: NoCommit",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- (* outBranchExecuted) = 0;
- }
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T3: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
-
-/**
- * Transaction 4 - T4
- *
- * Create session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * SessionDetails,
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-int
-T4(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- const SessionDetails inSessionDetails,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- DoRollback inDoRollback,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- Ndb * pNDB = (Ndb *) obj;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T4-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- DEBUG3("T4(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- NdbOperation * MyOperation = 0;
-
- MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T4-1: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTupleExclusive();
- CHECK_MINUS_ONE(check, "T4-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T4-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T4-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T4-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T4-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T4-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T4-1: getValue sessions",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T4-2: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T4-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T4-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(GROUP_ALLOW_INSERT,
- (char *)&permission);
- CHECK_NULL(check2, "T4-2: getValue allow_insert",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-2: NoCommit",
- MyTransaction);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == 0)){
-
- DEBUG("inserting - ");
-
- /* Operation 3 */
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T4-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->insertTuple();
- CHECK_MINUS_ONE(check, "T4-3: insertTuple",
- MyTransaction);
-
- check = MyOperation->equal(SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T4-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T4-3: equal server id",
- MyTransaction);
-
- check = MyOperation->setValue(SESSION_DATA,
- (char *)inSessionDetails);
- CHECK_MINUS_ONE(check, "T4-3: setValue session details",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-3: NoCommit",
- MyTransaction);
-
- /* Operation 4 */
- MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T4-4: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T4-4: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(SUBSCRIBER_NUMBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T4-4: equal number",
- MyTransaction);
-
- check = MyOperation->incValue(SUBSCRIBER_SESSIONS,
- (uint32)inServerBit);
- CHECK_MINUS_ONE(check, "T4-4: inc value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-4: NoCommit",
- MyTransaction);
-
- /* Operation 5 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T4-5: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T4-5: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T4-5: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T4-5: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(SERVER_INSERTS, (uint32)1);
- CHECK_MINUS_ONE(check, "T4-5: inc value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-5: NoCommit",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
- DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
- (* outBranchExecuted) = 0;
- }
-
- if(!inDoRollback){
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T4: Commit",
- MyTransaction);
- } else {
- DEBUG("rollback\n");
- check = MyTransaction->execute(Rollback);
- CHECK_MINUS_ONE(check, "T4:Rollback",
- MyTransaction);
-
- }
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
-
-/**
- * Transaction 5 - T5
- *
- * Delete session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-int
-T5(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- DoRollback inDoRollback,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- Ndb * pNDB = (Ndb *) obj;
- NdbConnection * MyTransaction = 0;
- NdbOperation * MyOperation = 0;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T5-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T5-1: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTupleExclusive();
- CHECK_MINUS_ONE(check, "T5-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T5-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T5-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T5-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T5-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T5-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T5-1: getValue sessions",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T5-2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T5-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T5-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(GROUP_ALLOW_DELETE,
- (char *)&permission);
- CHECK_NULL(check2, "T5-2: getValue allow_delete",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-2: NoCommit",
- MyTransaction);
-
- DEBUG3("T5(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == inServerBit)){
-
- DEBUG("deleting - ");
-
- /* Operation 3 */
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T5-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->deleteTuple();
- CHECK_MINUS_ONE(check, "T5-3: deleteTuple",
- MyTransaction);
-
- check = MyOperation->equal(SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T5-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T5-3: equal server id",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-3: NoCommit",
- MyTransaction);
-
- /* Operation 4 */
- MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T5-4: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T5-4: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(SUBSCRIBER_NUMBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T5-4: equal number",
- MyTransaction);
-
- check = MyOperation->subValue(SUBSCRIBER_SESSIONS,
- (uint32)inServerBit);
- CHECK_MINUS_ONE(check, "T5-4: dec value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-4: NoCommit",
- MyTransaction);
-
- /* Operation 5 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T5-5: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T5-5: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T5-5: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T5-5: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(SERVER_DELETES, (uint32)1);
- CHECK_MINUS_ONE(check, "T5-5: inc value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-5: NoCommit",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
- DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
- (* outBranchExecuted) = 0;
- }
-
- if(!inDoRollback){
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T5: Commit",
- MyTransaction);
- } else {
- DEBUG("rollback\n");
- check = MyTransaction->execute(Rollback);
- CHECK_MINUS_ONE(check, "T5:Rollback",
- MyTransaction);
-
- }
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
diff --git a/storage/ndb/test/ndbapi/bench/ndb_user_transaction2.cpp b/storage/ndb/test/ndbapi/bench/ndb_user_transaction2.cpp
deleted file mode 100644
index 845379b4652..00000000000
--- a/storage/ndb/test/ndbapi/bench/ndb_user_transaction2.cpp
+++ /dev/null
@@ -1,825 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-//#define DEBUG_ON
-
-extern "C" {
-#include "user_transaction.h"
-};
-
-#include "macros.h"
-#include "ndb_schema.hpp"
-#include "ndb_error.hpp"
-
-#include <time.h>
-#include <NdbApi.hpp>
-
-/**
- * Transaction 1 - T1
- *
- * Update location and changed by/time on a subscriber
- *
- * Input:
- * SubscriberNumber,
- * Location,
- * ChangedBy,
- * ChangedTime
- *
- * Output:
- */
-int
-T1(void * obj,
- const SubscriberNumber number,
- const Location new_location,
- const ChangedBy changed_by,
- const ChangedTime changed_time,
- BenchmarkTime * transaction_time){
-
- Ndb * pNDB = (Ndb *) obj;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T1: getNdbOperation", MyTransaction);
-
- check = MyOperation->updateTuple();
- CHECK_MINUS_ONE(check, "T1: updateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- number);
- CHECK_MINUS_ONE(check, "T1: equal subscriber",
- MyTransaction);
-
- check = MyOperation->setValue(IND_SUBSCRIBER_LOCATION,
- (char *)&new_location);
- CHECK_MINUS_ONE(check, "T1: setValue location",
- MyTransaction);
-
- check = MyOperation->setValue(IND_SUBSCRIBER_CHANGED_BY,
- changed_by);
- CHECK_MINUS_ONE(check, "T1: setValue changed_by",
- MyTransaction);
-
- check = MyOperation->setValue(IND_SUBSCRIBER_CHANGED_TIME,
- changed_time);
- CHECK_MINUS_ONE(check, "T1: setValue changed_time",
- MyTransaction);
-
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T1: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(transaction_time);
- time_diff(transaction_time, &start);
- return 0;
-}
-
-/**
- * Transaction 2 - T2
- *
- * Read from Subscriber:
- *
- * Input:
- * SubscriberNumber
- *
- * Output:
- * Location
- * Changed by
- * Changed Timestamp
- * Name
- */
-int
-T2(void * obj,
- const SubscriberNumber number,
- Location * readLocation,
- ChangedBy changed_by,
- ChangedTime changed_time,
- SubscriberName subscriberName,
- BenchmarkTime * transaction_time){
-
- Ndb * pNDB = (Ndb *) obj;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T2: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- number);
- CHECK_MINUS_ONE(check, "T2: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)readLocation);
- CHECK_NULL(check2, "T2: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- changed_by);
- CHECK_NULL(check2, "T2: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- changed_time);
- CHECK_NULL(check2, "T2: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_NAME,
- subscriberName);
- CHECK_NULL(check2, "T2: getValue name",
- MyTransaction);
-
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T2: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(transaction_time);
- time_diff(transaction_time, &start);
- return 0;
-}
-
-/**
- * Transaction 3 - T3
- *
- * Read session details
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- *
- * Output:
- * BranchExecuted
- * SessionDetails
- * ChangedBy
- * ChangedTime
- * Location
- */
-int
-T3(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- SessionDetails outSessionDetails,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- Ndb * pNDB = (Ndb *) obj;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T3-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T3-1: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T3-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T3-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T3-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T3-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T3-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T3-1: getValue sessions",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T3-2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T3-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_GROUP_ALLOW_READ,
- (char *)&permission);
- CHECK_NULL(check2, "T3-2: getValue allow_read",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-2: NoCommit",
- MyTransaction);
-
- DEBUG3("T3(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == inServerBit)){
-
- DEBUG("reading - ");
-
- /* Operation 3 */
-
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T3-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-3: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T3-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T3-3: equal server id",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SESSION_DATA,
- (char *)outSessionDetails);
- CHECK_NULL(check2, "T3-3: getValue session details",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-3: NoCommit",
- MyTransaction);
-
- /* Operation 4 */
-
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T3-4: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T3-4: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T3-4: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T3-4: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SERVER_READS, (uint32)1);
- CHECK_MINUS_ONE(check, "T3-4: inc value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-4: NoCommit",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- (* outBranchExecuted) = 0;
- }
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T3: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
-
-/**
- * Transaction 4 - T4
- *
- * Create session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * SessionDetails,
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-int
-T4(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- const SessionDetails inSessionDetails,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- DoRollback inDoRollback,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- Ndb * pNDB = (Ndb *) obj;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T4-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- DEBUG3("T4(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- NdbOperation * MyOperation = 0;
-
- MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T4-1: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTupleExclusive();
- CHECK_MINUS_ONE(check, "T4-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T4-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T4-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T4-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T4-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T4-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T4-1: getValue sessions",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T4-2: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T4-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T4-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_GROUP_ALLOW_INSERT,
- (char *)&permission);
- CHECK_NULL(check2, "T4-2: getValue allow_insert",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-2: NoCommit",
- MyTransaction);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == 0)){
-
- DEBUG("inserting - ");
-
- /* Operation 3 */
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T4-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->insertTuple();
- CHECK_MINUS_ONE(check, "T4-3: insertTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T4-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T4-3: equal server id",
- MyTransaction);
-
- check = MyOperation->setValue(SESSION_DATA,
- (char *)inSessionDetails);
- CHECK_MINUS_ONE(check, "T4-3: setValue session details",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-3: NoCommit",
- MyTransaction);
-
- /* Operation 4 */
- MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T4-4: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T4-4: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T4-4: equal number",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)inServerBit);
- CHECK_MINUS_ONE(check, "T4-4: inc value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-4: NoCommit",
- MyTransaction);
-
- /* Operation 5 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T4-5: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T4-5: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T4-5: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T4-5: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SERVER_INSERTS, (uint32)1);
- CHECK_MINUS_ONE(check, "T4-5: inc value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-5: NoCommit",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
- DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
- (* outBranchExecuted) = 0;
- }
-
- if(!inDoRollback){
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T4: Commit",
- MyTransaction);
- } else {
- DEBUG("rollback\n");
- check = MyTransaction->execute(Rollback);
- CHECK_MINUS_ONE(check, "T4:Rollback",
- MyTransaction);
-
- }
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
-
-/**
- * Transaction 5 - T5
- *
- * Delete session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-int
-T5(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- DoRollback inDoRollback,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- Ndb * pNDB = (Ndb *) obj;
- NdbConnection * MyTransaction = 0;
- NdbOperation * MyOperation = 0;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T5-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T5-1: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTupleExclusive();
- CHECK_MINUS_ONE(check, "T5-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T5-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T5-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T5-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T5-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T5-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T5-1: getValue sessions",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T5-2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T5-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T5-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_GROUP_ALLOW_DELETE,
- (char *)&permission);
- CHECK_NULL(check2, "T5-2: getValue allow_delete",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-2: NoCommit",
- MyTransaction);
-
- DEBUG3("T5(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == inServerBit)){
-
- DEBUG("deleting - ");
-
- /* Operation 3 */
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T5-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->deleteTuple();
- CHECK_MINUS_ONE(check, "T5-3: deleteTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T5-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T5-3: equal server id",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-3: NoCommit",
- MyTransaction);
-
- /* Operation 4 */
- MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T5-4: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T5-4: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T5-4: equal number",
- MyTransaction);
-
- check = MyOperation->subValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)inServerBit);
- CHECK_MINUS_ONE(check, "T5-4: dec value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-4: NoCommit",
- MyTransaction);
-
- /* Operation 5 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T5-5: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T5-5: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T5-5: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T5-5: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SERVER_DELETES, (uint32)1);
- CHECK_MINUS_ONE(check, "T5-5: inc value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-5: NoCommit",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
- DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
- (* outBranchExecuted) = 0;
- }
-
- if(!inDoRollback){
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T5: Commit",
- MyTransaction);
- } else {
- DEBUG("rollback\n");
- check = MyTransaction->execute(Rollback);
- CHECK_MINUS_ONE(check, "T5:Rollback",
- MyTransaction);
-
- }
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
diff --git a/storage/ndb/test/ndbapi/bench/ndb_user_transaction3.cpp b/storage/ndb/test/ndbapi/bench/ndb_user_transaction3.cpp
deleted file mode 100644
index ee46089128a..00000000000
--- a/storage/ndb/test/ndbapi/bench/ndb_user_transaction3.cpp
+++ /dev/null
@@ -1,793 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-//#define DEBUG_ON
-
-extern "C" {
-#include "user_transaction.h"
-};
-
-#include "macros.h"
-#include "ndb_schema.hpp"
-#include "ndb_error.hpp"
-
-#include <time.h>
-#include <NdbApi.hpp>
-
-/**
- * Transaction 1 - T1
- *
- * Update location and changed by/time on a subscriber
- *
- * Input:
- * SubscriberNumber,
- * Location,
- * ChangedBy,
- * ChangedTime
- *
- * Output:
- */
-int
-T1(void * obj,
- const SubscriberNumber number,
- const Location new_location,
- const ChangedBy changed_by,
- const ChangedTime changed_time,
- BenchmarkTime * transaction_time){
-
- Ndb * pNDB = (Ndb *) obj;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T1: getNdbOperation", MyTransaction);
-
- check = MyOperation->updateTuple();
- CHECK_MINUS_ONE(check, "T1: updateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- number);
- CHECK_MINUS_ONE(check, "T1: equal subscriber",
- MyTransaction);
-
- check = MyOperation->setValue(IND_SUBSCRIBER_LOCATION,
- (char *)&new_location);
- CHECK_MINUS_ONE(check, "T1: setValue location",
- MyTransaction);
-
- check = MyOperation->setValue(IND_SUBSCRIBER_CHANGED_BY,
- changed_by);
- CHECK_MINUS_ONE(check, "T1: setValue changed_by",
- MyTransaction);
-
- check = MyOperation->setValue(IND_SUBSCRIBER_CHANGED_TIME,
- changed_time);
- CHECK_MINUS_ONE(check, "T1: setValue changed_time",
- MyTransaction);
-
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T1: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(transaction_time);
- time_diff(transaction_time, &start);
- return 0;
-}
-
-/**
- * Transaction 2 - T2
- *
- * Read from Subscriber:
- *
- * Input:
- * SubscriberNumber
- *
- * Output:
- * Location
- * Changed by
- * Changed Timestamp
- * Name
- */
-int
-T2(void * obj,
- const SubscriberNumber number,
- Location * readLocation,
- ChangedBy changed_by,
- ChangedTime changed_time,
- SubscriberName subscriberName,
- BenchmarkTime * transaction_time){
-
- Ndb * pNDB = (Ndb *) obj;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T2: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- number);
- CHECK_MINUS_ONE(check, "T2: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)readLocation);
- CHECK_NULL(check2, "T2: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- changed_by);
- CHECK_NULL(check2, "T2: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- changed_time);
- CHECK_NULL(check2, "T2: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_NAME,
- subscriberName);
- CHECK_NULL(check2, "T2: getValue name",
- MyTransaction);
-
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T2: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(transaction_time);
- time_diff(transaction_time, &start);
- return 0;
-}
-
-/**
- * Transaction 3 - T3
- *
- * Read session details
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- *
- * Output:
- * BranchExecuted
- * SessionDetails
- * ChangedBy
- * ChangedTime
- * Location
- */
-int
-T3(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- SessionDetails outSessionDetails,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- Ndb * pNDB = (Ndb *) obj;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T3-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T3-1: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T3-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T3-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T3-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T3-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T3-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T3-1: getValue sessions",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T3-2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T3-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_GROUP_ALLOW_READ,
- (char *)&permission);
- CHECK_NULL(check2, "T3-2: getValue allow_read",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-2: NoCommit",
- MyTransaction);
-
- DEBUG3("T3(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == inServerBit)){
-
- DEBUG("reading - ");
-
- /* Operation 3 */
-
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T3-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-3: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T3-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T3-3: equal server id",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SESSION_DATA,
- (char *)outSessionDetails);
- CHECK_NULL(check2, "T3-3: getValue session details",
- MyTransaction);
-
- /* Operation 4 */
-
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T3-4: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T3-4: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T3-4: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T3-4: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SERVER_READS, (uint32)1);
- CHECK_MINUS_ONE(check, "T3-4: inc value",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- (* outBranchExecuted) = 0;
- }
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T3: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
-
-/**
- * Transaction 4 - T4
- *
- * Create session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * SessionDetails,
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-int
-T4(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- const SessionDetails inSessionDetails,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- DoRollback inDoRollback,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- Ndb * pNDB = (Ndb *) obj;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T4-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- DEBUG3("T4(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- NdbOperation * MyOperation = 0;
-
- MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T4-1: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTupleExclusive();
- CHECK_MINUS_ONE(check, "T4-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T4-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T4-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T4-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T4-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T4-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T4-1: getValue sessions",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T4-2: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T4-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T4-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_GROUP_ALLOW_INSERT,
- (char *)&permission);
- CHECK_NULL(check2, "T4-2: getValue allow_insert",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-2: NoCommit",
- MyTransaction);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == 0)){
-
- DEBUG("inserting - ");
-
- /* Operation 3 */
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T4-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->insertTuple();
- CHECK_MINUS_ONE(check, "T4-3: insertTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T4-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T4-3: equal server id",
- MyTransaction);
-
- check = MyOperation->setValue(SESSION_DATA,
- (char *)inSessionDetails);
- CHECK_MINUS_ONE(check, "T4-3: setValue session details",
- MyTransaction);
-
- /* Operation 4 */
- MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T4-4: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T4-4: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T4-4: equal number",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)inServerBit);
- CHECK_MINUS_ONE(check, "T4-4: inc value",
- MyTransaction);
-
- /* Operation 5 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T4-5: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T4-5: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T4-5: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T4-5: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SERVER_INSERTS, (uint32)1);
- CHECK_MINUS_ONE(check, "T4-5: inc value",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
- DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
- (* outBranchExecuted) = 0;
- }
-
- if(!inDoRollback){
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T4: Commit",
- MyTransaction);
- } else {
- DEBUG("rollback\n");
- check = MyTransaction->execute(Rollback);
- CHECK_MINUS_ONE(check, "T4:Rollback",
- MyTransaction);
-
- }
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
-
-/**
- * Transaction 5 - T5
- *
- * Delete session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-int
-T5(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- DoRollback inDoRollback,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- Ndb * pNDB = (Ndb *) obj;
- NdbConnection * MyTransaction = 0;
- NdbOperation * MyOperation = 0;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T5-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T5-1: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTupleExclusive();
- CHECK_MINUS_ONE(check, "T5-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T5-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T5-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T5-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T5-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T5-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T5-1: getValue sessions",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T5-2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T5-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T5-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_GROUP_ALLOW_DELETE,
- (char *)&permission);
- CHECK_NULL(check2, "T5-2: getValue allow_delete",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-2: NoCommit",
- MyTransaction);
-
- DEBUG3("T5(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == inServerBit)){
-
- DEBUG("deleting - ");
-
- /* Operation 3 */
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T5-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->deleteTuple();
- CHECK_MINUS_ONE(check, "T5-3: deleteTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T5-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T5-3: equal server id",
- MyTransaction);
-
- /* Operation 4 */
- MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T5-4: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T5-4: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T5-4: equal number",
- MyTransaction);
-
- check = MyOperation->subValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)inServerBit);
- CHECK_MINUS_ONE(check, "T5-4: dec value",
- MyTransaction);
-
- /* Operation 5 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T5-5: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T5-5: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T5-5: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T5-5: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SERVER_DELETES, (uint32)1);
- CHECK_MINUS_ONE(check, "T5-5: inc value",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
- DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
- (* outBranchExecuted) = 0;
- }
-
- if(!inDoRollback){
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T5: Commit",
- MyTransaction);
- } else {
- DEBUG("rollback\n");
- check = MyTransaction->execute(Rollback);
- CHECK_MINUS_ONE(check, "T5:Rollback",
- MyTransaction);
-
- }
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
diff --git a/storage/ndb/test/ndbapi/bench/ndb_user_transaction4.cpp b/storage/ndb/test/ndbapi/bench/ndb_user_transaction4.cpp
deleted file mode 100644
index 46d4f9e404e..00000000000
--- a/storage/ndb/test/ndbapi/bench/ndb_user_transaction4.cpp
+++ /dev/null
@@ -1,770 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-//#define DEBUG_ON
-
-extern "C" {
-#include "user_transaction.h"
-};
-
-#include "macros.h"
-#include "ndb_schema.hpp"
-#include "ndb_error.hpp"
-
-#include <time.h>
-#include <NdbApi.hpp>
-
-/**
- * Transaction 1 - T1
- *
- * Update location and changed by/time on a subscriber
- *
- * Input:
- * SubscriberNumber,
- * Location,
- * ChangedBy,
- * ChangedTime
- *
- * Output:
- */
-int
-T1(void * obj,
- const SubscriberNumber number,
- const Location new_location,
- const ChangedBy changed_by,
- const ChangedTime changed_time,
- BenchmarkTime * transaction_time){
-
- Ndb * pNDB = (Ndb *) obj;
-
- DEBUG2("T1(%.*s):\n", SUBSCRIBER_NUMBER_LENGTH, number);
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T1-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T1: getNdbOperation", MyTransaction);
-
- check = MyOperation->updateTuple();
- CHECK_MINUS_ONE(check, "T1: updateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- number);
- CHECK_MINUS_ONE(check, "T1: equal subscriber",
- MyTransaction);
-
- check = MyOperation->setValue(IND_SUBSCRIBER_LOCATION,
- (char *)&new_location);
- CHECK_MINUS_ONE(check, "T1: setValue location",
- MyTransaction);
-
- check = MyOperation->setValue(IND_SUBSCRIBER_CHANGED_BY,
- changed_by);
- CHECK_MINUS_ONE(check, "T1: setValue changed_by",
- MyTransaction);
-
- check = MyOperation->setValue(IND_SUBSCRIBER_CHANGED_TIME,
- changed_time);
- CHECK_MINUS_ONE(check, "T1: setValue changed_time",
- MyTransaction);
-
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T1: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(transaction_time);
- time_diff(transaction_time, &start);
- return 0;
-}
-
-/**
- * Transaction 2 - T2
- *
- * Read from Subscriber:
- *
- * Input:
- * SubscriberNumber
- *
- * Output:
- * Location
- * Changed by
- * Changed Timestamp
- * Name
- */
-int
-T2(void * obj,
- const SubscriberNumber number,
- Location * readLocation,
- ChangedBy changed_by,
- ChangedTime changed_time,
- SubscriberName subscriberName,
- BenchmarkTime * transaction_time){
-
- Ndb * pNDB = (Ndb *) obj;
-
- DEBUG2("T2(%.*s):\n", SUBSCRIBER_NUMBER_LENGTH, number);
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T2-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- number);
- CHECK_MINUS_ONE(check, "T2: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)readLocation);
- CHECK_NULL(check2, "T2: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- changed_by);
- CHECK_NULL(check2, "T2: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- changed_time);
- CHECK_NULL(check2, "T2: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_NAME,
- subscriberName);
- CHECK_NULL(check2, "T2: getValue name",
- MyTransaction);
-
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T2: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(transaction_time);
- time_diff(transaction_time, &start);
- return 0;
-}
-
-/**
- * Transaction 3 - T3
- *
- * Read session details
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- *
- * Output:
- * BranchExecuted
- * SessionDetails
- * ChangedBy
- * ChangedTime
- * Location
- */
-int
-T3(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- SessionDetails outSessionDetails,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- DEBUG3("T3(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- Ndb * pNDB = (Ndb *) obj;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T3-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T3-1: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T3-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T3-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T3-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T3-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T3-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T3-1: getValue sessions",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T3-2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T3-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_GROUP_ALLOW_READ,
- (char *)&permission);
- CHECK_NULL(check2, "T3-2: getValue allow_read",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-2: NoCommit",
- MyTransaction);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == inServerBit)){
-
- DEBUG("reading - ");
-
- /* Operation 3 */
-
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T3-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-3: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T3-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T3-3: equal server id",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SESSION_DATA,
- (char *)outSessionDetails);
- CHECK_NULL(check2, "T3-3: getValue session details",
- MyTransaction);
-
- /* Operation 4 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T3-4: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T3-4: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T3-4: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T3-4: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SERVER_READS, (uint32)1);
- CHECK_MINUS_ONE(check, "T3-4: inc value",
- MyTransaction);
- (* outBranchExecuted) = 1;
- } else {
- (* outBranchExecuted) = 0;
- }
- DEBUG("commit...");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T3: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- DEBUG("done\n");
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
-
-/**
- * Transaction 4 - T4
- *
- * Create session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * SessionDetails,
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-int
-T4(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- const SessionDetails inSessionDetails,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- DoRollback inDoRollback,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- DEBUG3("T4(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- Ndb * pNDB = (Ndb *) obj;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T4-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T4-1: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T4-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T4-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T4-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T4-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T4-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T4-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T4-1: getValue sessions",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)inServerBit);
- CHECK_MINUS_ONE(check, "T4-4: inc value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T4-2: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T4-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T4-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_GROUP_ALLOW_INSERT,
- (char *)&permission);
- CHECK_NULL(check2, "T4-2: getValue allow_insert",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-2: NoCommit",
- MyTransaction);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == 0)){
-
- DEBUG("inserting - ");
-
- /* Operation 3 */
-
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T4-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->insertTuple();
- CHECK_MINUS_ONE(check, "T4-3: insertTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T4-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T4-3: equal server id",
- MyTransaction);
-
- check = MyOperation->setValue(SESSION_DATA,
- (char *)inSessionDetails);
- CHECK_MINUS_ONE(check, "T4-3: setValue session details",
- MyTransaction);
-
- /* Operation 4 */
-
- /* Operation 5 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T4-5: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T4-5: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T4-5: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T4-5: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SERVER_INSERTS, (uint32)1);
- CHECK_MINUS_ONE(check, "T4-5: inc value",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
- DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
- (* outBranchExecuted) = 0;
- }
-
- if(!inDoRollback && (* outBranchExecuted)){
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T4: Commit",
- MyTransaction);
- } else {
- DEBUG("rollback\n");
- check = MyTransaction->execute(Rollback);
- CHECK_MINUS_ONE(check, "T4:Rollback",
- MyTransaction);
-
- }
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
-
-/**
- * Transaction 5 - T5
- *
- * Delete session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-int
-T5(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- DoRollback inDoRollback,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- DEBUG3("T5(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- Ndb * pNDB = (Ndb *) obj;
- NdbConnection * MyTransaction = 0;
- NdbOperation * MyOperation = 0;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T5-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T5-1: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T5-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T5-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T5-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T5-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T5-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T5-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T5-1: getValue sessions",
- MyTransaction);
-
- check = MyOperation->subValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)inServerBit);
- CHECK_MINUS_ONE(check, "T5-4: dec value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T5-2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T5-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T5-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_GROUP_ALLOW_DELETE,
- (char *)&permission);
- CHECK_NULL(check2, "T5-2: getValue allow_delete",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-2: NoCommit",
- MyTransaction);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == inServerBit)){
-
- DEBUG("deleting - ");
-
- /* Operation 3 */
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T5-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->deleteTuple();
- CHECK_MINUS_ONE(check, "T5-3: deleteTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T5-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T5-3: equal server id",
- MyTransaction);
-
- /* Operation 4 */
-
- /* Operation 5 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T5-5: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T5-5: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T5-5: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T5-5: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SERVER_DELETES, (uint32)1);
- CHECK_MINUS_ONE(check, "T5-5: inc value",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
- DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
- (* outBranchExecuted) = 0;
- }
-
- if(!inDoRollback && (* outBranchExecuted)){
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T5: Commit",
- MyTransaction);
- } else {
- DEBUG("rollback\n");
- check = MyTransaction->execute(Rollback);
- CHECK_MINUS_ONE(check, "T5:Rollback",
- MyTransaction);
-
- }
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
diff --git a/storage/ndb/test/ndbapi/bench/ndb_user_transaction5.cpp b/storage/ndb/test/ndbapi/bench/ndb_user_transaction5.cpp
deleted file mode 100644
index b6781474b5c..00000000000
--- a/storage/ndb/test/ndbapi/bench/ndb_user_transaction5.cpp
+++ /dev/null
@@ -1,769 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-//#define DEBUG_ON
-
-extern "C" {
-#include "user_transaction.h"
-};
-
-#include "macros.h"
-#include "ndb_schema.hpp"
-#include "ndb_error.hpp"
-
-#include <time.h>
-#include <NdbApi.hpp>
-
-/**
- * Transaction 1 - T1
- *
- * Update location and changed by/time on a subscriber
- *
- * Input:
- * SubscriberNumber,
- * Location,
- * ChangedBy,
- * ChangedTime
- *
- * Output:
- */
-int
-T1(void * obj,
- const SubscriberNumber number,
- const Location new_location,
- const ChangedBy changed_by,
- const ChangedTime changed_time,
- BenchmarkTime * transaction_time){
-
- Ndb * pNDB = (Ndb *) obj;
-
- DEBUG2("T1(%.*s):\n", SUBSCRIBER_NUMBER_LENGTH, number);
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T1-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T1: getNdbOperation", MyTransaction);
-
- check = MyOperation->updateTuple();
- CHECK_MINUS_ONE(check, "T1: updateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- number);
- CHECK_MINUS_ONE(check, "T1: equal subscriber",
- MyTransaction);
-
- check = MyOperation->setValue(IND_SUBSCRIBER_LOCATION,
- (char *)&new_location);
- CHECK_MINUS_ONE(check, "T1: setValue location",
- MyTransaction);
-
- check = MyOperation->setValue(IND_SUBSCRIBER_CHANGED_BY,
- changed_by);
- CHECK_MINUS_ONE(check, "T1: setValue changed_by",
- MyTransaction);
-
- check = MyOperation->setValue(IND_SUBSCRIBER_CHANGED_TIME,
- changed_time);
- CHECK_MINUS_ONE(check, "T1: setValue changed_time",
- MyTransaction);
-
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T1: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(transaction_time);
- time_diff(transaction_time, &start);
- return 0;
-}
-
-/**
- * Transaction 2 - T2
- *
- * Read from Subscriber:
- *
- * Input:
- * SubscriberNumber
- *
- * Output:
- * Location
- * Changed by
- * Changed Timestamp
- * Name
- */
-int
-T2(void * obj,
- const SubscriberNumber number,
- Location * readLocation,
- ChangedBy changed_by,
- ChangedTime changed_time,
- SubscriberName subscriberName,
- BenchmarkTime * transaction_time){
-
- Ndb * pNDB = (Ndb *) obj;
-
- DEBUG2("T2(%.*s):\n", SUBSCRIBER_NUMBER_LENGTH, number);
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T2-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- number);
- CHECK_MINUS_ONE(check, "T2: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)readLocation);
- CHECK_NULL(check2, "T2: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- changed_by);
- CHECK_NULL(check2, "T2: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- changed_time);
- CHECK_NULL(check2, "T2: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_NAME,
- subscriberName);
- CHECK_NULL(check2, "T2: getValue name",
- MyTransaction);
-
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T2: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(transaction_time);
- time_diff(transaction_time, &start);
- return 0;
-}
-
-/**
- * Transaction 3 - T3
- *
- * Read session details
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- *
- * Output:
- * BranchExecuted
- * SessionDetails
- * ChangedBy
- * ChangedTime
- * Location
- */
-int
-T3(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- SessionDetails outSessionDetails,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- Ndb * pNDB = (Ndb *) obj;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T3-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T3-1: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T3-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T3-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T3-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T3-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T3-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T3-1: getValue sessions",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T3-2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T3-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_GROUP_ALLOW_READ,
- (char *)&permission);
- CHECK_NULL(check2, "T3-2: getValue allow_read",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-2: NoCommit",
- MyTransaction);
-
- DEBUG3("T3(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == inServerBit)){
-
- DEBUG("reading - ");
-
- /* Operation 3 */
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T3-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->simpleRead();
- CHECK_MINUS_ONE(check, "T3-3: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T3-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T3-3: equal server id",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SESSION_DATA,
- (char *)outSessionDetails);
- CHECK_NULL(check2, "T3-3: getValue session details",
- MyTransaction);
-
- /* Operation 4 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T3-4: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T3-4: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T3-4: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T3-4: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SERVER_READS, (uint32)1);
- CHECK_MINUS_ONE(check, "T3-4: inc value",
- MyTransaction);
- (* outBranchExecuted) = 1;
- } else {
- (* outBranchExecuted) = 0;
- }
- DEBUG("commit...");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T3: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- DEBUG("done\n");
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
-
-/**
- * Transaction 4 - T4
- *
- * Create session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * SessionDetails,
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-int
-T4(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- const SessionDetails inSessionDetails,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- DoRollback inDoRollback,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- Ndb * pNDB = (Ndb *) obj;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T4-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T4-1: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T4-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T4-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T4-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T4-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T4-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T4-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T4-1: getValue sessions",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)inServerBit);
- CHECK_MINUS_ONE(check, "T4-4: inc value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T4-2: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T4-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T4-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_GROUP_ALLOW_INSERT,
- (char *)&permission);
- CHECK_NULL(check2, "T4-2: getValue allow_insert",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-2: NoCommit",
- MyTransaction);
-
- DEBUG3("T4(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == 0)){
-
- DEBUG("inserting - ");
-
- /* Operation 3 */
-
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T4-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->insertTuple();
- CHECK_MINUS_ONE(check, "T4-3: insertTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T4-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T4-3: equal server id",
- MyTransaction);
-
- check = MyOperation->setValue(SESSION_DATA,
- (char *)inSessionDetails);
- CHECK_MINUS_ONE(check, "T4-3: setValue session details",
- MyTransaction);
-
- /* Operation 4 */
-
- /* Operation 5 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T4-5: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T4-5: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T4-5: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T4-5: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SERVER_INSERTS, (uint32)1);
- CHECK_MINUS_ONE(check, "T4-5: inc value",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
- DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
- (* outBranchExecuted) = 0;
- }
-
- if(!inDoRollback && (* outBranchExecuted)){
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T4: Commit",
- MyTransaction);
- } else {
- DEBUG("rollback\n");
- check = MyTransaction->execute(Rollback);
- CHECK_MINUS_ONE(check, "T4:Rollback",
- MyTransaction);
-
- }
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
-
-/**
- * Transaction 5 - T5
- *
- * Delete session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-int
-T5(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- DoRollback inDoRollback,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- Ndb * pNDB = (Ndb *) obj;
- NdbConnection * MyTransaction = 0;
- NdbOperation * MyOperation = 0;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T5-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T5-1: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T5-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T5-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T5-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T5-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T5-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T5-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T5-1: getValue sessions",
- MyTransaction);
-
- check = MyOperation->subValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)inServerBit);
- CHECK_MINUS_ONE(check, "T5-4: dec value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T5-2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T5-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T5-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_GROUP_ALLOW_DELETE,
- (char *)&permission);
- CHECK_NULL(check2, "T5-2: getValue allow_delete",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-2: NoCommit",
- MyTransaction);
-
- DEBUG3("T5(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == inServerBit)){
-
- DEBUG("deleting - ");
-
- /* Operation 3 */
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T5-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->deleteTuple();
- CHECK_MINUS_ONE(check, "T5-3: deleteTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T5-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T5-3: equal server id",
- MyTransaction);
-
- /* Operation 4 */
-
- /* Operation 5 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T5-5: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T5-5: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T5-5: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T5-5: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SERVER_DELETES, (uint32)1);
- CHECK_MINUS_ONE(check, "T5-5: inc value",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
- DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
- (* outBranchExecuted) = 0;
- }
-
- if(!inDoRollback && (* outBranchExecuted)){
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T5: Commit",
- MyTransaction);
- } else {
- DEBUG("rollback\n");
- check = MyTransaction->execute(Rollback);
- CHECK_MINUS_ONE(check, "T5:Rollback",
- MyTransaction);
-
- }
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
diff --git a/storage/ndb/test/ndbapi/bench/ndb_user_transaction6.cpp b/storage/ndb/test/ndbapi/bench/ndb_user_transaction6.cpp
deleted file mode 100644
index 0fc5ca9ec9c..00000000000
--- a/storage/ndb/test/ndbapi/bench/ndb_user_transaction6.cpp
+++ /dev/null
@@ -1,561 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-//#define DEBUG_ON
-
-#include <string.h>
-#include "userHandle.h"
-#include "userInterface.h"
-
-#include "macros.h"
-#include "ndb_schema.hpp"
-#include "ndb_error.hpp"
-
-#include <NdbApi.hpp>
-
-
-void
-userCheckpoint(UserHandle *uh){
-}
-
-inline
-NdbConnection *
-startTransaction(Ndb * pNDB, ServerId inServerId, const SubscriberNumber inNumber){
-
- const int keyDataLenBytes = sizeof(ServerId)+SUBSCRIBER_NUMBER_LENGTH;
- const int keyDataLen_64Words = keyDataLenBytes >> 3;
-
- Uint64 keyDataBuf[keyDataLen_64Words+1]; // The "+1" is for rounding...
-
- char * keyDataBuf_charP = (char *)&keyDataBuf[0];
- Uint32 * keyDataBuf_wo32P = (Uint32 *)&keyDataBuf[0];
-
- // Server Id comes first
- keyDataBuf_wo32P[0] = inServerId;
- // Then subscriber number
- memcpy(&keyDataBuf_charP[sizeof(ServerId)], inNumber, SUBSCRIBER_NUMBER_LENGTH);
-
- return pNDB->startTransaction(0, keyDataBuf_charP, keyDataLenBytes);
-}
-
-/**
- * Transaction 1 - T1
- *
- * Update location and changed by/time on a subscriber
- *
- * Input:
- * SubscriberNumber,
- * Location,
- * ChangedBy,
- * ChangedTime
- *
- * Output:
- */
-void
-userTransaction_T1(UserHandle * uh,
- SubscriberNumber number,
- Location new_location,
- ChangedBy changed_by,
- ChangedTime changed_time){
- Ndb * pNDB = uh->pNDB;
-
- DEBUG2("T1(%.*s):\n", SUBSCRIBER_NUMBER_LENGTH, number);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction != NULL) {
- NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- if (MyOperation != NULL) {
- MyOperation->updateTuple();
- MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- number);
- MyOperation->setValue(IND_SUBSCRIBER_LOCATION,
- (char *)&new_location);
- MyOperation->setValue(IND_SUBSCRIBER_CHANGED_BY,
- changed_by);
- MyOperation->setValue(IND_SUBSCRIBER_CHANGED_TIME,
- changed_time);
- check = MyTransaction->execute( Commit );
- if (check != -1) {
- pNDB->closeTransaction(MyTransaction);
- return;
- } else {
- CHECK_MINUS_ONE(check, "T1: Commit",
- MyTransaction);
- }//if
- } else {
- CHECK_NULL(MyOperation, "T1: getNdbOperation", MyTransaction);
- }//if
- } else {
- error_handler("T1-1: startTranscation", pNDB->getNdbErrorString(), pNDB->getNdbError());
- }//if
-}
-
-/**
- * Transaction 2 - T2
- *
- * Read from Subscriber:
- *
- * Input:
- * SubscriberNumber
- *
- * Output:
- * Location
- * Changed by
- * Changed Timestamp
- * Name
- */
-void
-userTransaction_T2(UserHandle * uh,
- SubscriberNumber number,
- Location * readLocation,
- ChangedBy changed_by,
- ChangedTime changed_time,
- SubscriberName subscriberName){
- Ndb * pNDB = uh->pNDB;
-
- DEBUG2("T2(%.*s):\n", SUBSCRIBER_NUMBER_LENGTH, number);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T2-1: startTransaction", pNDB->getNdbErrorString(), pNDB->getNdbError());
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T2: getNdbOperation",
- MyTransaction);
-
- MyOperation->readTuple();
- MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- number);
- MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)readLocation);
- MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- changed_by);
- MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- changed_time);
- MyOperation->getValue(IND_SUBSCRIBER_NAME,
- subscriberName);
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T2: Commit",
- MyTransaction);
- pNDB->closeTransaction(MyTransaction);
-}
-
-/**
- * Transaction 3 - T3
- *
- * Read session details
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- *
- * Output:
- * BranchExecuted
- * SessionDetails
- * ChangedBy
- * ChangedTime
- * Location
- */
-void
-userTransaction_T3(UserHandle * uh,
- SubscriberNumber inNumber,
- ServerId inServerId,
- ServerBit inServerBit,
- SessionDetails outSessionDetails,
- BranchExecuted * outBranchExecuted){
- Ndb * pNDB = uh->pNDB;
-
- char outChangedBy [sizeof(ChangedBy) +(4-(sizeof(ChangedBy) & 3))];
- char outChangedTime [sizeof(ChangedTime)+(4-(sizeof(ChangedTime) & 3))];
- Location outLocation;
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
- SubscriberSuffix inSuffix;
-
- DEBUG3("T3(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = startTransaction(pNDB, inServerId, inNumber);
- if (MyTransaction == NULL)
- error_handler("T3-1: startTranscation", pNDB->getNdbErrorString(), pNDB->getNdbError());
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T3-1: getNdbOperation",
- MyTransaction);
-
- MyOperation->readTuple();
- MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)&outLocation);
- MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T3-2: getNdbOperation",
- MyTransaction);
-
-
- MyOperation->readTuple();
- MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- MyOperation->getValue(IND_GROUP_ALLOW_READ,
- (char *)&permission);
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-2: NoCommit",
- MyTransaction);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == inServerBit)){
-
- memcpy(inSuffix,
- &inNumber[SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH], SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
- DEBUG2("reading(%.*s) - ", SUBSCRIBER_NUMBER_SUFFIX_LENGTH, inSuffix);
-
- /* Operation 3 */
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T3-3: getNdbOperation",
- MyTransaction);
-
- MyOperation->simpleRead();
-
- MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- MyOperation->getValue(IND_SESSION_DATA,
- (char *)outSessionDetails);
- /* Operation 4 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T3-4: getNdbOperation",
- MyTransaction);
-
- MyOperation->interpretedUpdateTuple();
- MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- MyOperation->incValue(IND_SERVER_READS, (uint32)1);
- (* outBranchExecuted) = 1;
- } else {
- (* outBranchExecuted) = 0;
- }
- DEBUG("commit...");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T3: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- DEBUG("done\n");
-}
-
-
-/**
- * Transaction 4 - T4
- *
- * Create session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * SessionDetails,
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-void
-userTransaction_T4(UserHandle * uh,
- SubscriberNumber inNumber,
- ServerId inServerId,
- ServerBit inServerBit,
- SessionDetails inSessionDetails,
- DoRollback inDoRollback,
- BranchExecuted * outBranchExecuted){
-
- Ndb * pNDB = uh->pNDB;
-
- char outChangedBy [sizeof(ChangedBy) +(4-(sizeof(ChangedBy) & 3))];
- char outChangedTime [sizeof(ChangedTime)+(4-(sizeof(ChangedTime) & 3))];
- Location outLocation;
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
- SubscriberSuffix inSuffix;
-
- DEBUG3("T4(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = startTransaction(pNDB, inServerId, inNumber);
- if (MyTransaction == NULL)
- error_handler("T4-1: startTranscation", pNDB->getNdbErrorString(), pNDB->getNdbError());
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T4-1: getNdbOperation",
- MyTransaction);
-
- MyOperation->interpretedUpdateTuple();
- MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)&outLocation);
- MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- MyOperation->incValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)inServerBit);
- check = MyTransaction->execute( NoCommit );
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T4-2: getNdbOperation",
- MyTransaction);
-
- MyOperation->readTuple();
- MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- MyOperation->getValue(IND_GROUP_ALLOW_INSERT,
- (char *)&permission);
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-2: NoCommit",
- MyTransaction);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == 0)){
-
- memcpy(inSuffix,
- &inNumber[SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH], SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
-
- DEBUG2("inserting(%.*s) - ", SUBSCRIBER_NUMBER_SUFFIX_LENGTH, inSuffix);
-
- /* Operation 3 */
-
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T4-3: getNdbOperation",
- MyTransaction);
-
- MyOperation->insertTuple();
- MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- MyOperation->setValue(SESSION_DATA,
- (char *)inSessionDetails);
- /* Operation 4 */
-
- /* Operation 5 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T4-5: getNdbOperation",
- MyTransaction);
-
- MyOperation->interpretedUpdateTuple();
- MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- MyOperation->incValue(IND_SERVER_INSERTS, (uint32)1);
- (* outBranchExecuted) = 1;
- } else {
- (* outBranchExecuted) = 0;
- DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
- DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
- }
-
- if(!inDoRollback && (* outBranchExecuted)){
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T4: Commit",
- MyTransaction);
- } else {
- DEBUG("rollback\n");
- check = MyTransaction->execute(Rollback);
- CHECK_MINUS_ONE(check, "T4:Rollback",
- MyTransaction);
-
- }
-
- pNDB->closeTransaction(MyTransaction);
-}
-
-
-/**
- * Transaction 5 - T5
- *
- * Delete session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-void
-userTransaction_T5(UserHandle * uh,
- SubscriberNumber inNumber,
- ServerId inServerId,
- ServerBit inServerBit,
- DoRollback inDoRollback,
- BranchExecuted * outBranchExecuted){
- Ndb * pNDB = uh->pNDB;
-
- DEBUG3("T5(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- NdbConnection * MyTransaction = 0;
- NdbOperation * MyOperation = 0;
-
- char outChangedBy [sizeof(ChangedBy) +(4-(sizeof(ChangedBy) & 3))];
- char outChangedTime [sizeof(ChangedTime)+(4-(sizeof(ChangedTime) & 3))];
- Location outLocation;
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
- SubscriberSuffix inSuffix;
-
- int check;
- NdbRecAttr * check2;
-
- MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T5-1: startTranscation", pNDB->getNdbErrorString(), pNDB->getNdbError());
-
- MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T5-1: getNdbOperation",
- MyTransaction);
-
- MyOperation->interpretedUpdateTuple();
- MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)&outLocation);
- MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- &outChangedBy[0]);
- MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- &outChangedTime[0]);
- MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- MyOperation->subValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)inServerBit);
- MyTransaction->execute( NoCommit );
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T5-2: getNdbOperation",
- MyTransaction);
-
- MyOperation->readTuple();
- MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- MyOperation->getValue(IND_GROUP_ALLOW_DELETE,
- (char *)&permission);
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-2: NoCommit",
- MyTransaction);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == inServerBit)){
-
- memcpy(inSuffix,
- &inNumber[SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH], SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
-
- DEBUG2("deleting(%.*s) - ", SUBSCRIBER_NUMBER_SUFFIX_LENGTH, inSuffix);
-
- /* Operation 3 */
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T5-3: getNdbOperation",
- MyTransaction);
-
- MyOperation->deleteTuple();
- MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- /* Operation 4 */
-
- /* Operation 5 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T5-5: getNdbOperation",
- MyTransaction);
-
-
- MyOperation->interpretedUpdateTuple();
- MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- MyOperation->incValue(IND_SERVER_DELETES, (uint32)1);
- (* outBranchExecuted) = 1;
- } else {
- (* outBranchExecuted) = 0;
- DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
- DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
- }
-
- if(!inDoRollback && (* outBranchExecuted)){
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T5: Commit",
- MyTransaction);
- } else {
- DEBUG("rollback\n");
- check = MyTransaction->execute(Rollback);
- CHECK_MINUS_ONE(check, "T5:Rollback",
- MyTransaction);
-
- }
-
- pNDB->closeTransaction(MyTransaction);
-}
-
diff --git a/storage/ndb/test/ndbapi/bench/testData.h b/storage/ndb/test/ndbapi/bench/testData.h
deleted file mode 100644
index 6b05b4a06fa..00000000000
--- a/storage/ndb/test/ndbapi/bench/testData.h
+++ /dev/null
@@ -1,156 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef TESTDATA_H
-#define TESTDATA_H
-
-/***************************************************************
-* I N C L U D E D F I L E S *
-***************************************************************/
-#include <NdbTick.h>
-#include <NdbThread.h>
-#include <NDBT_Stats.hpp>
-#include <random.h>
-#include "testDefinitions.h"
-
-/***************************************************************
-* M A C R O S *
-***************************************************************/
-
-/***************************************************************/
-/* C O N S T A N T S */
-/***************************************************************/
-
-#define NUM_TRANSACTION_TYPES 5
-#define SESSION_LIST_LENGTH 1000
-
-/***************************************************************
-* D A T A S T R U C T U R E S *
-***************************************************************/
-
-typedef struct {
- SubscriberNumber subscriberNumber;
- ServerId serverId;
-} SessionElement;
-
-typedef struct {
- SessionElement list[SESSION_LIST_LENGTH];
- unsigned int readIndex;
- unsigned int writeIndex;
- unsigned int numberInList;
-} SessionList;
-
-typedef struct {
- unsigned int count;
- unsigned int branchExecuted;
- unsigned int rollbackExecuted;
-
- /**
- * Latency measures
- */
- NDB_TICKS startTime;
- NDBT_Stats latency;
- unsigned int latencyCounter;
-
- inline void startLatency(){
- if((latencyCounter & 127) == 127)
- startTime = NdbTick_CurrentMillisecond();
- }
-
- inline void stopLatency(){
- if((latencyCounter & 127) == 127){
- const NDB_TICKS tmp = NdbTick_CurrentMillisecond() - startTime;
- latency.addObservation(tmp);
- }
- latencyCounter++;
- }
-} TransactionDefinition;
-
-typedef struct {
- RandomSequence transactionSequence;
- RandomSequence rollbackSequenceT4;
- RandomSequence rollbackSequenceT5;
-
- TransactionDefinition transactions[NUM_TRANSACTION_TYPES];
-
- unsigned int totalTransactions;
-
- double outerLoopTime;
- double outerTps;
-
- SessionList activeSessions;
-
-} GeneratorStatistics;
-
-typedef enum{
- Runnable,
- Running
-} RunState ;
-
-typedef struct {
- SubscriberNumber number;
- SubscriberSuffix suffix;
- SubscriberName name;
- Location location;
- ChangedBy changed_by;
- ChangedTime changed_time;
- ServerId server_id;
- ServerBit server_bit;
- SessionDetails session_details;
-
- GroupId group_id;
- ActiveSessions sessions;
- Permission permission;
-
- unsigned int do_rollback;
-
- unsigned int branchExecuted;
- unsigned int sessionElement;
-} TransactionData ;
-
-typedef struct {
- struct NdbThread* pThread;
-
- unsigned long randomSeed;
- unsigned long changedTime;
-
- unsigned int warmUpSeconds;
- unsigned int testSeconds;
- unsigned int coolDownSeconds;
-
- GeneratorStatistics generator;
-
- /**
- * For async execution
- */
- RunState runState;
- double startTime;
- TransactionData transactionData;
- struct Ndb * pNDB;
-} ThreadData;
-
-/***************************************************************
- * P U B L I C F U N C T I O N S *
- ***************************************************************/
-
-/***************************************************************
- * E X T E R N A L D A T A *
- ***************************************************************/
-
-
-
-#endif /* TESTDATA_H */
-
diff --git a/storage/ndb/test/ndbapi/bench/testDefinitions.h b/storage/ndb/test/ndbapi/bench/testDefinitions.h
deleted file mode 100644
index 04a661d1f37..00000000000
--- a/storage/ndb/test/ndbapi/bench/testDefinitions.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef TESTDEFINITIONS_H
-#define TESTDEFINITIONS_H
-
-/***************************************************************/
-/* I N C L U D E D F I L E S */
-/***************************************************************/
-
-#include <ndb_types.h>
-
-/***************************************************************/
-/* C O N S T A N T S */
-/***************************************************************/
-
-#define OP_PER_TRANS 200
-#define NO_OF_SUBSCRIBERS 500000
-#define NO_OF_GROUPS 100
-#define NO_OF_SERVERS 20
-
-#define SUBSCRIBER_NUMBER_LENGTH 12
-#define SUBSCRIBER_NUMBER_SUFFIX_LENGTH 2
-
-#define SUBSCRIBER_NAME_LENGTH 32
-#define CHANGED_BY_LENGTH 32
-#define CHANGED_TIME_LENGTH 32
-#define SESSION_DETAILS_LENGTH 2000
-#define SERVER_NAME_LENGTH 32
-#define GROUP_NAME_LENGTH 32
-
-/***************************************************************
-* D A T A S T R U C T U R E S *
-***************************************************************/
-
-#define PADDING 4
-
-typedef char SubscriberNumber[SUBSCRIBER_NUMBER_LENGTH];
-typedef char SubscriberSuffix[SUBSCRIBER_NUMBER_SUFFIX_LENGTH + 2];
-typedef char SubscriberName[SUBSCRIBER_NAME_LENGTH];
-typedef char ServerName[SERVER_NAME_LENGTH];
-typedef char GroupName[GROUP_NAME_LENGTH];
-typedef char ChangedBy[CHANGED_BY_LENGTH];
-typedef char ChangedTime[CHANGED_TIME_LENGTH];
-typedef char SessionDetails[SESSION_DETAILS_LENGTH];
-typedef Uint32 ServerId;
-typedef Uint32 ServerBit;
-typedef Uint32 GroupId;
-typedef Uint32 Location;
-typedef Uint32 Permission;
-
-typedef Uint32 Counter;
-typedef Uint32 ActiveSessions;
-typedef unsigned int BranchExecuted;
-typedef unsigned int DoRollback;
-
-/***************************************************************
-* P U B L I C F U N C T I O N S *
-***************************************************************/
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#ifdef __cplusplus
-}
-#endif
-
-/***************************************************************
-* E X T E R N A L D A T A *
-***************************************************************/
-
-
-
-#endif /* TESTDEFINITIONS_H */
-
diff --git a/storage/ndb/test/ndbapi/bench/userInterface.cpp b/storage/ndb/test/ndbapi/bench/userInterface.cpp
deleted file mode 100644
index c187d327dae..00000000000
--- a/storage/ndb/test/ndbapi/bench/userInterface.cpp
+++ /dev/null
@@ -1,744 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-/***************************************************************
-* I N C L U D E D F I L E S *
-***************************************************************/
-
-#include <ndb_global.h>
-#ifndef NDB_WIN32
-#include <sys/time.h>
-#endif
-
-#include "ndb_error.hpp"
-#include "userInterface.h"
-#include <NdbThread.h>
-#include <NdbTick.h>
-#include <NdbMutex.h>
-#include <NdbSleep.h>
-#include "ndb_schema.hpp"
-#include <NDBT.hpp>
-#include <NdbSchemaCon.hpp>
-
-/***************************************************************
-* L O C A L C O N S T A N T S *
-***************************************************************/
-
-/***************************************************************
-* L O C A L D A T A S T R U C T U R E S *
-***************************************************************/
-
-/***************************************************************
-* L O C A L F U N C T I O N S *
-***************************************************************/
-
-extern int localDbPrepare(UserHandle *uh);
-
-static int dbCreate(UserHandle *uh);
-
-/***************************************************************
-* L O C A L D A T A *
-***************************************************************/
-
-/***************************************************************
-* P U B L I C D A T A *
-***************************************************************/
-
-
-/***************************************************************
-****************************************************************
-* L O C A L F U N C T I O N S C O D E S E C T I O N *
-****************************************************************
-***************************************************************/
-
-/***************************************************************
-****************************************************************
-* P U B L I C F U N C T I O N S C O D E S E C T I O N *
-****************************************************************
-***************************************************************/
-
-/*-----------------------------------*/
-/* Time related Functions */
-/* */
-/* Returns a double value in seconds */
-/*-----------------------------------*/
-double userGetTimeSync(void)
-{
- static int initialized = 0;
- static NDB_TICKS initSecs = 0;
- static Uint32 initMicros = 0;
- double timeValue = 0;
-
- if ( !initialized ) {
- initialized = 1;
- NdbTick_CurrentMicrosecond(&initSecs, &initMicros);
- timeValue = 0.0;
- } else {
- NDB_TICKS secs = 0;
- Uint32 micros = 0;
-
- NdbTick_CurrentMicrosecond(&secs, &micros);
-
- double s = (double)secs - (double)initSecs;
- double us = (double)secs - (double)initMicros;
-
- timeValue = s + (us / 1000000.0);
- }
-
- return timeValue;
-}
-
-// 0 - OK
-// 1 - Retry transaction
-// 2 - Permanent
-int
-userDbCommit(UserHandle *uh){
- if(uh->pCurrTrans != 0){
- int check = uh->pCurrTrans->execute( Commit );
- NdbError err = uh->pCurrTrans->getNdbError();
- uh->pNDB->closeTransaction(uh->pCurrTrans);
- uh->pCurrTrans = 0;
-
- if(err.status != NdbError::Success)
- ndbout << err << endl;
-
- if(err.status == NdbError::TemporaryError &&
- err.classification == NdbError::OverloadError){
- NdbSleep_SecSleep(3);
- }
-
- return err.status;
- }
- return 2;
-}
-
-/**
- * TRUE - Normal table
- * FALSE - Table w.o. checkpoing and logging
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-extern int useTableLogging;
-#ifdef __cplusplus
-}
-#endif
-
-
-int
-create_table_server(Ndb * pNdb){
- int check;
- NdbSchemaCon * MySchemaTransaction = NdbSchemaCon::startSchemaTrans(pNdb);
- if( MySchemaTransaction == NULL )
- error_handler("startSchemaTransaction", pNdb->getNdbError(), 0);
-
- NdbSchemaOp * MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
- if( MySchemaOp == NULL )
- error_handler("getNdbSchemaOp", MySchemaTransaction->getNdbError(), 0);
-
- // Create table
- check = MySchemaOp->createTable( SERVER_TABLE,
- 8, // Table size
- TupleKey, // Key Type
- 1 // Nr of Pages
- ,DistributionGroup,
- 6,
- 78,
- 80,
- 1,
- useTableLogging
- );
- if( check == -1 )
- error_handler("createTable", MySchemaTransaction->getNdbError(), 0);
-
- check = MySchemaOp->createAttribute
- ( SERVER_SUBSCRIBER_SUFFIX,
- TupleKey,
- sizeof(char) << 3,
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH,
- String,
- MMBased,
- NotNullAttribute,
- 0,
- 0,
- 1,
- 16);
- if( check == -1 )
- error_handler("createAttribute (subscriber suffix)",
- MySchemaTransaction->getNdbError(), 0);
-
- // Create first column, primary key
- check = MySchemaOp->createAttribute( SERVER_ID,
- TupleKey,
- sizeof(ServerId) << 3,
- 1,
- UnSigned,
- MMBased,
- NotNullAttribute );
- if( check == -1 )
- error_handler("createAttribute (serverid)",
- MySchemaTransaction->getNdbError(), 0);
-
-
- check = MySchemaOp->createAttribute( SERVER_NAME,
- NoKey,
- sizeof(char) << 3,
- SERVER_NAME_LENGTH,
- String,
- MMBased,
- NotNullAttribute );
- if( check == -1 )
- error_handler("createAttribute (server name)",
- MySchemaTransaction->getNdbError(), 0);
-
-
- check = MySchemaOp->createAttribute( SERVER_READS,
- NoKey,
- sizeof(Counter) << 3,
- 1,
- UnSigned,
- MMBased,
- NotNullAttribute );
- if( check == -1 )
- error_handler("createAttribute (server reads)",
- MySchemaTransaction->getNdbError(), 0);
-
- check = MySchemaOp->createAttribute( SERVER_INSERTS,
- NoKey,
- sizeof(Counter) << 3,
- 1,
- UnSigned,
- MMBased,
- NotNullAttribute );
- if( check == -1 )
- error_handler("createAttribute (server inserts)",
- MySchemaTransaction->getNdbError(), 0);
-
- check = MySchemaOp->createAttribute( SERVER_DELETES,
- NoKey,
- sizeof(Counter) << 3,
- 1,
- UnSigned,
- MMBased,
- NotNullAttribute );
- if( check == -1 )
- error_handler("createAttribute (server deletes)",
- MySchemaTransaction->getNdbError(), 0);
-
- if( MySchemaTransaction->execute() == -1 ) {
- error_handler("schemaTransaction->execute()",
- MySchemaTransaction->getNdbError(), 0);
- }
- NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
- return 0;
-}
-
-int
-create_table_group(Ndb * pNdb){
- int check;
-
- NdbSchemaCon * MySchemaTransaction = NdbSchemaCon::startSchemaTrans(pNdb);
- if( MySchemaTransaction == NULL )
- error_handler("startSchemaTransaction", pNdb->getNdbError(), 0);
-
- NdbSchemaOp * MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
- if( MySchemaOp == NULL )
- error_handler("getNdbSchemaOp", MySchemaTransaction->getNdbError(), 0);
-
- // Create table
- check = MySchemaOp->createTable( GROUP_TABLE,
- 8, // Table size
- TupleKey, // Key Type
- 1 // Nr of Pages
- ,All,
- 6,
- 78,
- 80,
- 1,
- useTableLogging
- );
-
- if( check == -1 )
- error_handler("createTable", MySchemaTransaction->getNdbError(), 0);
-
- // Create first column, primary key
- check = MySchemaOp->createAttribute( GROUP_ID,
- TupleKey,
- sizeof(GroupId) << 3,
- 1,
- UnSigned,
- MMBased,
- NotNullAttribute );
- if( check == -1 )
- error_handler("createAttribute (group id)",
- MySchemaTransaction->getNdbError(), 0);
-
- check = MySchemaOp->createAttribute( GROUP_NAME,
- NoKey,
- sizeof(char) << 3,
- GROUP_NAME_LENGTH,
- String,
- MMBased,
- NotNullAttribute );
- if( check == -1 )
- error_handler("createAttribute (group name)",
- MySchemaTransaction->getNdbError(), 0);
-
-
- check = MySchemaOp->createAttribute( GROUP_ALLOW_READ,
- NoKey,
- sizeof(Permission) << 3,
- 1,
- String,
- MMBased,
- NotNullAttribute );
- if( check == -1 )
- error_handler("createAttribute (group read)",
- MySchemaTransaction->getNdbError(), 0);
-
-
- check = MySchemaOp->createAttribute( GROUP_ALLOW_INSERT,
- NoKey,
- sizeof(Permission) << 3,
- 1,
- UnSigned,
- MMBased,
- NotNullAttribute );
- if( check == -1 )
- error_handler("createAttribute (group insert)",
- MySchemaTransaction->getNdbError(), 0);
-
- check = MySchemaOp->createAttribute( GROUP_ALLOW_DELETE,
- NoKey,
- sizeof(Permission) << 3,
- 1,
- UnSigned,
- MMBased,
- NotNullAttribute );
- if( check == -1 )
- error_handler("createAttribute (group delete)",
- MySchemaTransaction->getNdbError(), 0);
-
- if( MySchemaTransaction->execute() == -1 ) {
- error_handler("schemaTransaction->execute()",
- MySchemaTransaction->getNdbError(), 0);
- }
- NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
- return 0;
-}
-
-int
-create_table_subscriber(Ndb * pNdb){
- int check;
- NdbSchemaCon * MySchemaTransaction = NdbSchemaCon::startSchemaTrans(pNdb);
- if( MySchemaTransaction == NULL )
- error_handler("startSchemaTransaction", pNdb->getNdbError(), 0);
-
- NdbSchemaOp * MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
- if( MySchemaOp == NULL )
- error_handler("getNdbSchemaOp", MySchemaTransaction->getNdbError(), 0);
-
- // Create table
- check = MySchemaOp->createTable( SUBSCRIBER_TABLE,
- 8, // Table size
- TupleKey, // Key Type
- 1 // Nr of Pages
- ,DistributionGroup,
- 6,
- 78,
- 80,
- 1,
- useTableLogging
- );
- if( check == -1 )
- error_handler("createTable", MySchemaTransaction->getNdbError(), 0);
-
- // Create first column, primary key
- check = MySchemaOp->createAttribute
- ( SUBSCRIBER_NUMBER,
- TupleKey,
- sizeof(char) << 3,
- SUBSCRIBER_NUMBER_LENGTH,
- String,
- MMBased,
- NotNullAttribute,
- 0,
- 0,
- 1,
- 16);
- if( check == -1 )
- error_handler("createAttribute (subscriber number)",
- MySchemaTransaction->getNdbError(), 0);
-
- check = MySchemaOp->createAttribute( SUBSCRIBER_NAME,
- NoKey,
- sizeof(char) << 3,
- SUBSCRIBER_NAME_LENGTH,
- String,
- MMBased,
- NotNullAttribute );
- if( check == -1 )
- error_handler("createAttribute (subscriber name)",
- MySchemaTransaction->getNdbError(), 0);
-
-
- check = MySchemaOp->createAttribute( SUBSCRIBER_GROUP,
- NoKey,
- sizeof(GroupId) << 3,
- 1,
- UnSigned,
- MMBased,
- NotNullAttribute );
- if( check == -1 )
- error_handler("createAttribute (subscriber_group)",
- MySchemaTransaction->getNdbError(), 0);
-
-
- check = MySchemaOp->createAttribute( SUBSCRIBER_LOCATION,
- NoKey,
- sizeof(Location) << 3,
- 1,
- UnSigned,
- MMBased,
- NotNullAttribute );
- if( check == -1 )
- error_handler("createAttribute (server reads)",
- MySchemaTransaction->getNdbError(), 0);
-
- check = MySchemaOp->createAttribute( SUBSCRIBER_SESSIONS,
- NoKey,
- sizeof(ActiveSessions) << 3,
- 1,
- UnSigned,
- MMBased,
- NotNullAttribute );
- if( check == -1 )
- error_handler("createAttribute (subscriber_sessions)",
- MySchemaTransaction->getNdbError(), 0);
-
- check = MySchemaOp->createAttribute( SUBSCRIBER_CHANGED_BY,
- NoKey,
- sizeof(char) << 3,
- CHANGED_BY_LENGTH,
- String,
- MMBased,
- NotNullAttribute );
- if( check == -1 )
- error_handler("createAttribute (subscriber_changed_by)",
- MySchemaTransaction->getNdbError(), 0);
-
- check = MySchemaOp->createAttribute( SUBSCRIBER_CHANGED_TIME,
- NoKey,
- sizeof(char) << 3,
- CHANGED_TIME_LENGTH,
- String,
- MMBased,
- NotNullAttribute );
- if( check == -1 )
- error_handler("createAttribute (subscriber_changed_time)",
- MySchemaTransaction->getNdbError(), 0);
-
- if( MySchemaTransaction->execute() == -1 ) {
- error_handler("schemaTransaction->execute()",
- MySchemaTransaction->getNdbError(), 0);
- }
- NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
- return 0;
-}
-
-int
-create_table_session(Ndb * pNdb){
- int check;
- NdbSchemaCon * MySchemaTransaction = NdbSchemaCon::startSchemaTrans(pNdb);
- if( MySchemaTransaction == NULL )
- error_handler("startSchemaTransaction", pNdb->getNdbError(), 0);
-
- NdbSchemaOp * MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
- if( MySchemaOp == NULL )
- error_handler("getNdbSchemaOp",
- MySchemaTransaction->getNdbError(), 0);
-
- // Create table
- check = MySchemaOp->createTable( SESSION_TABLE,
- 8, // Table size
- TupleKey, // Key Type
- 1 // Nr of Pages
- ,DistributionGroup,
- 6,
- 78,
- 80,
- 1,
- useTableLogging
- );
- if( check == -1 )
- error_handler("createTable", MySchemaTransaction->getNdbError(), 0);
-
- check = MySchemaOp->createAttribute( SESSION_SUBSCRIBER,
- TupleKey,
- sizeof(char) << 3,
- SUBSCRIBER_NUMBER_LENGTH,
- String,
- MMBased,
- NotNullAttribute,
- 0,
- 0,
- 1,
- 16);
- if( check == -1 )
- error_handler("createAttribute (session_subscriber)",
- MySchemaTransaction->getNdbError(), 0);
-
- // Create first column, primary key
- check = MySchemaOp->createAttribute( SESSION_SERVER,
- TupleKey,
- sizeof(ServerId) << 3,
- 1,
- UnSigned,
- MMBased,
- NotNullAttribute );
- if( check == -1 )
- error_handler("createAttribute (session_server)",
- MySchemaTransaction->getNdbError(), 0);
-
-
- check = MySchemaOp->createAttribute( SESSION_DATA,
- NoKey,
- sizeof(char) << 3,
- SESSION_DETAILS_LENGTH,
- String,
- MMBased,
- NotNullAttribute );
- if( check == -1 )
- error_handler("createAttribute (session_data)",
- MySchemaTransaction->getNdbError(), 0);
-
- if( MySchemaTransaction->execute() == -1 ) {
- error_handler("schemaTransaction->execute()",
- MySchemaTransaction->getNdbError(), 0);
- }
- NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
- return 0;
-}
-
-void
-create_table(const char * name, int (* function)(Ndb * pNdb), Ndb* pNdb){
- printf("creating table %s...", name);
- if(pNdb->getDictionary()->getTable(name) != 0){
- printf(" it already exists\n");
- return;
- } else {
- printf("\n");
- }
- function(pNdb);
- printf("creating table %s... done\n", name);
-}
-
-static int dbCreate(Ndb * pNdb)
-{
- create_table(SUBSCRIBER_TABLE, create_table_subscriber, pNdb);
- create_table(GROUP_TABLE , create_table_group, pNdb);
- create_table(SESSION_TABLE , create_table_session, pNdb);
- create_table(SERVER_TABLE , create_table_server, pNdb);
- return 0;
-}
-
-#ifndef NDB_WIN32
-#include <unistd.h>
-#endif
-
-UserHandle*
-userDbConnect(uint32 createDb, char *dbName)
-{
- Ndb_cluster_connection *con= new Ndb_cluster_connection();
- if(con->connect(12, 5, 1) != 0)
- {
- ndbout << "Unable to connect to management server." << endl;
- return 0;
- }
- if (con->wait_until_ready(30,0) < 0)
- {
- ndbout << "Cluster nodes not ready in 30 seconds." << endl;
- return 0;
- }
-
- Ndb * pNdb = new Ndb(con, dbName);
-
- //printf("Initializing...\n");
- pNdb->init();
-
- //printf("Waiting...");
- while(pNdb->waitUntilReady() != 0){
- //printf("...");
- }
- // printf("done\n");
-
- if( createDb )
- dbCreate(pNdb);
-
-
- UserHandle * uh = new UserHandle;
- uh->pNCC = con;
- uh->pNDB = pNdb;
- uh->pCurrTrans = 0;
-
- return uh;
-}
-
-void userDbDisconnect(UserHandle *uh)
-{
- delete uh;
-}
-
-int userDbInsertServer(UserHandle *uh,
- ServerId serverId,
- SubscriberSuffix suffix,
- ServerName name)
-{
- int check;
-
- uint32 noOfRead = 0;
- uint32 noOfInsert = 0;
- uint32 noOfDelete = 0;
-
- NdbConnection * MyTransaction = 0;
- if(uh->pCurrTrans != 0){
- MyTransaction = uh->pCurrTrans;
- } else {
- uh->pCurrTrans = MyTransaction = uh->pNDB->startTransaction();
- }
- if (MyTransaction == NULL)
- error_handler("startTranscation", uh->pNDB->getNdbError(), 0);
-
- NdbOperation *MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);
-
- check = MyOperation->insertTuple();
- CHECK_MINUS_ONE(check, "insert tuple", MyTransaction);
-
- check = MyOperation->equal(SERVER_ID, (char*)&serverId);
- CHECK_MINUS_ONE(check, "setValue id", MyTransaction);
-
- check = MyOperation->setValue(SERVER_SUBSCRIBER_SUFFIX, suffix);
- CHECK_MINUS_ONE(check, "setValue suffix", MyTransaction);
-
- check = MyOperation->setValue(SERVER_NAME, name);
- CHECK_MINUS_ONE(check, "setValue name", MyTransaction);
-
- check = MyOperation->setValue(SERVER_READS, (char*)&noOfRead);
- CHECK_MINUS_ONE(check, "setValue reads", MyTransaction);
-
- check = MyOperation->setValue(SERVER_INSERTS, (char*)&noOfInsert);
- CHECK_MINUS_ONE(check, "setValue inserts", MyTransaction);
-
- check = MyOperation->setValue(SERVER_DELETES, (char*)&noOfDelete);
- CHECK_MINUS_ONE(check, "setValue deletes", MyTransaction);
-
- return 0;
-}
-
-int userDbInsertSubscriber(UserHandle *uh,
- SubscriberNumber number,
- uint32 groupId,
- SubscriberName name)
-{
- int check;
- uint32 activeSessions = 0;
- Location l = 0;
- ChangedBy changedBy; snprintf(changedBy, sizeof(changedBy), "ChangedBy");
- ChangedTime changedTime; snprintf(changedTime, sizeof(changedTime), "ChangedTime");
-
- NdbConnection * MyTransaction = 0;
- if(uh->pCurrTrans != 0){
- MyTransaction = uh->pCurrTrans;
- } else {
- uh->pCurrTrans = MyTransaction = uh->pNDB->startTransaction();
- }
- if (MyTransaction == NULL)
- error_handler("startTranscation", uh->pNDB->getNdbError(), 0);
-
- NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);
-
- check = MyOperation->insertTuple();
- CHECK_MINUS_ONE(check, "insertTuple", MyTransaction);
-
- check = MyOperation->equal(SUBSCRIBER_NUMBER, number);
- CHECK_MINUS_ONE(check, "equal", MyTransaction);
-
- check = MyOperation->setValue(SUBSCRIBER_NAME, name);
- CHECK_MINUS_ONE(check, "setValue name", MyTransaction);
-
- check = MyOperation->setValue(SUBSCRIBER_GROUP, (char*)&groupId);
- CHECK_MINUS_ONE(check, "setValue group", MyTransaction);
-
- check = MyOperation->setValue(SUBSCRIBER_LOCATION, (char*)&l);
- CHECK_MINUS_ONE(check, "setValue location", MyTransaction);
-
- check = MyOperation->setValue(SUBSCRIBER_SESSIONS, (char*)&activeSessions);
- CHECK_MINUS_ONE(check, "setValue sessions", MyTransaction);
-
- check = MyOperation->setValue(SUBSCRIBER_CHANGED_BY, changedBy);
- CHECK_MINUS_ONE(check, "setValue changedBy", MyTransaction);
-
- check = MyOperation->setValue(SUBSCRIBER_CHANGED_TIME, changedTime);
- CHECK_MINUS_ONE(check, "setValue changedTime", MyTransaction);
-
- return 0;
-}
-
-int userDbInsertGroup(UserHandle *uh,
- GroupId groupId,
- GroupName name,
- Permission allowRead,
- Permission allowInsert,
- Permission allowDelete)
-{
- int check;
-
- NdbConnection * MyTransaction = 0;
- if(uh->pCurrTrans != 0){
- MyTransaction = uh->pCurrTrans;
- } else {
- uh->pCurrTrans = MyTransaction = uh->pNDB->startTransaction();
- }
- if (MyTransaction == NULL)
- error_handler("startTranscation", uh->pNDB->getNdbError(), 0);
-
- NdbOperation *MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);
-
- check = MyOperation->insertTuple();
- CHECK_MINUS_ONE(check, "insertTuple", MyTransaction);
-
- check = MyOperation->equal(GROUP_ID, (char*)&groupId);
- CHECK_MINUS_ONE(check, "equal", MyTransaction);
-
- check = MyOperation->setValue(GROUP_NAME, name);
- CHECK_MINUS_ONE(check, "setValue name", MyTransaction);
-
- check = MyOperation->setValue(GROUP_ALLOW_READ, (char*)&allowRead);
- CHECK_MINUS_ONE(check, "setValue allowRead", MyTransaction);
-
- check = MyOperation->setValue(GROUP_ALLOW_INSERT, (char*)&allowInsert);
- CHECK_MINUS_ONE(check, "setValue allowInsert", MyTransaction);
-
- check = MyOperation->setValue(GROUP_ALLOW_DELETE, (char*)&allowDelete);
- CHECK_MINUS_ONE(check, "setValue allowDelete", MyTransaction);
-
- return 0;
-}
-
diff --git a/storage/ndb/test/ndbapi/bench/userInterface.h b/storage/ndb/test/ndbapi/bench/userInterface.h
deleted file mode 100644
index 2793731fde3..00000000000
--- a/storage/ndb/test/ndbapi/bench/userInterface.h
+++ /dev/null
@@ -1,151 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef DBINTERFACE_H
-#define DBINTERFACE_H
-
-/***************************************************************/
-/* I N C L U D E D F I L E S */
-/***************************************************************/
-
-#include "testDefinitions.h"
-#include "testData.h"
-
-/***************************************************************
-* M A C R O S *
-***************************************************************/
-
-/***************************************************************/
-/* C O N S T A N T S */
-/***************************************************************/
-
-/*-----------------------*/
-/* Default Database Name */
-/*-----------------------*/
-#define DEFAULTDB "TestDbClient"
-
-/***************************************************************
-* D A T A S T R U C T U R E S *
-***************************************************************/
-
-/***************************************************************
-* P U B L I C F U N C T I O N S *
-***************************************************************/
-
-typedef struct Ndb Ndb;
-
-#ifdef __cplusplus
-extern "C" {
-#endif
- extern void showTime();
- extern double userGetTime(void);
- extern Ndb *asyncDbConnect(int parallellism);
- extern void asyncDbDisconnect(Ndb* pNDB);
-
- extern void start_T1(Ndb * uh, ThreadData * data, int async);
- extern void start_T2(Ndb * uh, ThreadData * data, int async);
- extern void start_T3(Ndb * uh, ThreadData * data, int async);
- extern void start_T4(Ndb * uh, ThreadData * data, int async);
- extern void start_T5(Ndb * uh, ThreadData * data, int async);
-
- extern void complete_T1(ThreadData * data);
- extern void complete_T2(ThreadData * data);
- extern void complete_T3(ThreadData * data);
- extern void complete_T4(ThreadData * data);
- extern void complete_T5(ThreadData * data);
-
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-
-/***************************************************************/
-/* I N C L U D E D F I L E S */
-/***************************************************************/
-
-#include "testDefinitions.h"
-
-/***************************************************************
-* M A C R O S *
-***************************************************************/
-
-/***************************************************************/
-/* C O N S T A N T S */
-/***************************************************************/
-
-/*-----------------------*/
-/* Default Database Name */
-/*-----------------------*/
-#define DEFAULTDB "TestDbClient"
-
-/***************************************************************
-* D A T A S T R U C T U R E S *
-***************************************************************/
-
-typedef struct {
- struct Ndb_cluster_connection* pNCC;
- struct Ndb * pNDB;
- struct NdbTransaction * pCurrTrans;
-} UserHandle;
-
-/***************************************************************
-* P U B L I C F U N C T I O N S *
-***************************************************************/
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern double userGetTimeSync(void);
-
-extern void userCheckpoint(UserHandle *uh);
-
-extern UserHandle *userDbConnect(uint32 createDb, char *dbName);
-extern void userDbDisconnect(UserHandle *uh);
-
-extern int userDbInsertServer(UserHandle *uh,
- ServerId serverId,
- SubscriberSuffix suffix,
- ServerName name);
-
-extern int userDbInsertSubscriber(UserHandle *uh,
- SubscriberNumber number,
- uint32 groupId,
- SubscriberName name);
-
-extern int userDbInsertGroup(UserHandle *uh,
- GroupId groupId,
- GroupName name,
- Permission allowRead,
- Permission allowInsert,
- Permission allowDelete);
-
- extern int userDbCommit(UserHandle *uh);
- extern int userDbRollback(UserHandle *uh);
-
-#ifdef __cplusplus
-}
-#endif
-
-/***************************************************************
-* E X T E R N A L D A T A *
-***************************************************************/
-
-#endif /* DBINTERFACE_H */
-
diff --git a/storage/ndb/test/ndbapi/benchronja.cpp b/storage/ndb/test/ndbapi/benchronja.cpp
deleted file mode 100644
index 39640623ad8..00000000000
--- a/storage/ndb/test/ndbapi/benchronja.cpp
+++ /dev/null
@@ -1,1208 +0,0 @@
-/* Copyright (c) 2003-2005, 2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-/* ***************************************************
- NODEREC
- Perform benchmark of insert, update and delete transactions
-
- Arguments:
- -t Number of threads to start, default 1
- -o Number of loops per thread, default 100000
-
-
- * *************************************************** */
-
-#include <ndb_global.h>
-
-#include <NdbApi.hpp>
-#include <NdbTest.hpp>
-#include <NdbOut.hpp>
-#include <NdbThread.h>
-#include <NdbSleep.h>
-#include <NdbMain.h>
-#include <NdbTimer.hpp>
-#include <NdbTick.h>
-#include <random.h>
-
-#define MAX_TIMERS 4
-#define MAXSTRLEN 16
-#define MAXATTR 64
-#define MAXTABLES 64
-#define NDB_MAXTHREADS 256
-/*
- NDB_MAXTHREADS used to be just MAXTHREADS, which collides with a
- #define from <sys/thread.h> on AIX (IBM compiler). We explicitly
- #undef it here lest someone use it by habit and get really funny
- results. K&R says we may #undef non-existent symbols, so let's go.
-*/
-#undef MAXTHREADS
-#define MAXATTRSIZE 8000
-#define START_TIMER NdbTimer timer; timer.doStart();
-#define STOP_TIMER timer.doStop();
-#define START_TIMER_TOP NdbTimer timer_top; timer_top.doStart();
-#define STOP_TIMER_TOP timer_top.doStop();
-
-void* ThreadExec(void*);
-struct ThreadNdb
-{
- int NoOfOps;
- int ThreadNo;
- Ndb* NdbRef;
-};
-
-static NdbThread* threadLife[NDB_MAXTHREADS];
-static unsigned int tNoOfThreads;
-static unsigned int tNoOfOpsPerExecute;
-static unsigned int tNoOfRecords;
-static unsigned int tNoOfOperations;
-static int ThreadReady[NDB_MAXTHREADS];
-static int ThreadStart[NDB_MAXTHREADS];
-
-NDB_COMMAND(benchronja, "benchronja", "benchronja", "benchronja", 65535){
- ndb_init();
-
- ThreadNdb tabThread[NDB_MAXTHREADS];
- int i = 0 ;
- int cont = 0 ;
- Ndb* pMyNdb = NULL ; //( "TEST_DB" );
- int tmp = 0 ;
- int nTest = 0 ;
- char inp[100] ;
-
- tNoOfThreads = 1; // Default Value
- tNoOfOpsPerExecute = 1; // Default Value
- tNoOfOperations = 100000; // Default Value
- tNoOfRecords = 500 ; // Default Value <epaulsa: changed from original 500,000 to match 'initronja's' default
- i = 1;
- while (argc > 1)
- {
- if (strcmp(argv[i], "-t") == 0){
- tNoOfThreads = atoi(argv[i+1]);
- if ((tNoOfThreads < 1) || (tNoOfThreads > NDB_MAXTHREADS)) goto error_input;
- }else if (strcmp(argv[i], "-o") == 0){
- tNoOfOperations = atoi(argv[i+1]);
- if (tNoOfOperations < 1) goto error_input;
- }else if (strcmp(argv[i], "-r") == 0){
- tNoOfRecords = atoi(argv[i+1]);
- if ((tNoOfRecords < 1) || (tNoOfRecords > 1000000000)) goto error_input;
- }else if (strcmp(argv[i], "-p") == 0){
- nTest = atoi(argv[i+1]) ;
- if (0 > nTest || 18 < nTest) goto error_input ;
- }else if (strcmp(argv[i], "-c") == 0){
- tNoOfOpsPerExecute = atoi(argv[i+1]);
- if ((tNoOfOpsPerExecute < 1) || (tNoOfOpsPerExecute > 1024)) goto error_input;
- }else{
- goto error_input;
- }
- argc -= 2;
- i = i + 2;
- }
-
- ndbout << "Initialisation started. " << endl;
- pMyNdb = new Ndb("TEST_DB") ;
- pMyNdb->init();
- ndbout << "Initialisation completed. " << endl;
-
- ndbout << endl << "Execute Ronja Benchmark" << endl;
- ndbout << " NdbAPI node with id = " << pMyNdb->getNodeId() << endl;
- ndbout << " " << tNoOfThreads << " thread(s) " << endl;
- ndbout << " " << tNoOfOperations << " transaction(s) per thread and round " << endl;
-
- if (pMyNdb->waitUntilReady(120) != 0) {
- ndbout << "Benchmark failed - NDB is not ready" << endl;
- delete pMyNdb ;
- return NDBT_ProgramExit(NDBT_FAILED);
- }//if
-
- NdbThread_SetConcurrencyLevel(2 + tNoOfThreads);
-
- for (i = 0; i < tNoOfThreads ; i++) {
- ThreadReady[i] = 0;
- ThreadStart[i] = 0;
- }//for
-
- for (i = 0; i < tNoOfThreads ; i++) {
- tabThread[i].ThreadNo = i;
- tabThread[i].NdbRef = NULL;
- tabThread[i].NoOfOps = tNoOfOperations;
- threadLife[i] = NdbThread_Create(ThreadExec,
- (void**)&tabThread[i],
- 32768,
- "RonjaThread",
- NDB_THREAD_PRIO_LOW);
- }//for
-
- cont = 1;
- while (cont) {
- NdbSleep_MilliSleep(10);
- cont = 0;
- for (i = 0; i < tNoOfThreads ; i++)
- if (!ThreadReady[i]) cont = 1;
- }//while
-
- ndbout << "All threads started" << endl;
-
- if(!nTest){
-
- for (;;){
-
- inp[0] = 0;
- ndbout << endl << "What to do next:" << endl;
- ndbout << "1 \t=> Perform lookups in short table" << endl;
- ndbout << "2 \t=> Perform lookups in long table" << endl;
- ndbout << "3 \t=> Perform updates in short table" << endl;
- ndbout << "4 \t=> Perform updates in long table" << endl;
- ndbout << "5 \t=> Perform 50% lookups/50% updates in short table" << endl;
- ndbout << "6 \t=> Perform 50% lookups/50% updates in long table" << endl;
- ndbout << "7 \t=> Perform 80% lookups/20% updates in short table" << endl;
- ndbout << "8 \t=> Perform 80% lookups/20% updates in long table" << endl;
- ndbout << "9 \t=> Perform 25% lookups short/25% lookups long/25% updates short/25% updates long" << endl;
- ndbout << "10\t=> Test bug with replicated interpreted updates, short table" << endl;
- ndbout << "11\t=> Test interpreter functions, short table" << endl;
- ndbout << "12\t=> Test bug with replicated interpreted updates, long table" << endl;
- ndbout << "13\t=> Test interpreter functions, long table" << endl;
- ndbout << "14\t=> Perform lookups in short table, no guess of TC" << endl;
- ndbout << "15\t=> Perform lookups in long table, no guess of TC" << endl;
- ndbout << "16\t=> Perform updates in short table, no guess of TC" << endl;
- ndbout << "17\t=> Perform updates in long table, no guess of TC" << endl;
- ndbout << "18\t=> Multi record updates of transactions" << endl;
- ndbout << "All other responses will exit" << endl;
- ndbout << "_____________________________" << endl << endl ;
-
- int inp_i = 0;
- do {
- inp[inp_i] = (char) fgetc(stdin);
- if (inp[inp_i] == '\n' || inp[inp_i] == EOF) {
- inp[inp_i] ='\0';
- break;
- }
- inp_i++;
-
- } while (inp[inp_i - 1] != '\n' && inp[inp_i - 1] != EOF);
-
- tmp = atoi(inp);
-
- if ((tmp > 18) || (tmp <= 0)) break;
-
- ndbout << "Starting test " << tmp << "..." << endl;
-
- for (i = 0; i < tNoOfThreads ; i++){ ThreadStart[i] = tmp; }
-
- cont = 1;
- while (cont) {
- NdbSleep_MilliSleep(10);
- cont = 0;
- for (i = 0; i < tNoOfThreads ; i++){
- if (!ThreadReady[i]) cont = 1;
- }
- }//while
- }//for(;;)
-
- }else{
-
- if(19 == nTest){
- ndbout << "Executing all 18 available tests..." << endl << endl;
- for (int count = 1; count < nTest; count++){
- ndbout << "Test " << count << endl ;
- ndbout << "------" << endl << endl ;
- for (i = 0; i < tNoOfThreads ; i++) { ThreadStart[i] = count ; }
- cont = 1;
- while (cont) {
- NdbSleep_MilliSleep(10);
- cont = 0;
- for (i = 0; i < tNoOfThreads ; i++){
- if (!ThreadReady[i]) cont = 1;
- }
- }
- }//for
- }else{
- ndbout << endl << "Executing test " << nTest << endl << endl;
- for (i = 0; i < tNoOfThreads ; i++) { ThreadStart[i] = nTest ; }
- cont = 1;
- while (cont) {
- NdbSleep_MilliSleep(10);
- cont = 0;
- for (i = 0; i < tNoOfThreads ; i++){
- if (!ThreadReady[i]) cont = 1;
- }
- }
- }//if(18 == nTest)
- } //if(!nTest)
-
- ndbout << "--------------------------------------------------" << endl;
-
- for (i = 0; i < tNoOfThreads ; i++) ThreadReady[i] = 0;
- // Signaling threads to stop
- for (i = 0; i < tNoOfThreads ; i++) ThreadStart[i] = 999;
-
- // Wait for threads to stop
- cont = 1;
- do {
- NdbSleep_MilliSleep(1);
- cont = 0;
- for (i = 0; i < tNoOfThreads ; i++){
- if (ThreadReady[i] == 0) cont = 1;
- }
- } while (cont == 1);
-
- delete pMyNdb ;
- ndbout << endl << "Ronja Benchmark completed" << endl;
- return NDBT_ProgramExit(NDBT_OK) ;
-
-error_input:
- ndbout << endl << " Ivalid parameter(s)" << endl;
- ndbout << " Usage: benchronja [-t threads][-r rec] [-o ops] [-c ops_per_exec] [-p test], where:" << endl;
- ndbout << " threads - the number of threads to start; default: 1" << endl;
- ndbout << " rec - the number of records in the tables; default: 500" << endl;
- ndbout << " ops - the number of operations per transaction; default: 100000" << endl;
- ndbout << " ops_per_exec - the number of operations per execution; default: 1" << endl ;
- ndbout << " test - the number of test to execute; 19 executes all available tests; default: 0"<< endl ;
- ndbout << " which enters a loop expecting manual input of test number to execute." << endl << endl ;
- delete pMyNdb ;
- return NDBT_ProgramExit(NDBT_WRONGARGS) ;
-
- }
-////////////////////////////////////////
-
-void commitTrans(Ndb* aNdb, NdbConnection* aCon)
-{
- int ret = aCon->execute(Commit);
- assert (ret != -1);
- aNdb->closeTransaction(aCon);
-}
-
-void rollbackTrans(Ndb* aNdb, NdbConnection* aCon)
-{
- int ret = aCon->execute(Rollback);
- assert (ret != -1);
- aNdb->closeTransaction(aCon);
-}
-
-void updateNoCommit(NdbConnection* aCon, Uint32* flip, unsigned int key)
-{
- NdbOperation* theOperation;
-
- *flip = *flip + 1;
- theOperation = aCon->getNdbOperation("SHORT_REC");
- theOperation->updateTuple();
- theOperation->equal((Uint32)0, key);
- theOperation->setValue((Uint32)1, (char*)flip);
- int ret = aCon->execute(NoCommit);
- assert (ret != -1);
-}
-
-void updateNoCommitFail(NdbConnection* aCon, unsigned int key)
-{
- NdbOperation* theOperation;
-
- Uint32 flip = 0;
- theOperation = aCon->getNdbOperation("SHORT_REC");
- theOperation->updateTuple();
- theOperation->equal((Uint32)0, key);
- theOperation->setValue((Uint32)1, (char*)flip);
- int ret = aCon->execute(NoCommit);
- assert (ret == -1);
-}
-
-void deleteNoCommit(NdbConnection* aCon, Uint32* flip, unsigned int key)
-{
- NdbOperation* theOperation;
-
- *flip = 0;
- theOperation = aCon->getNdbOperation("SHORT_REC");
- theOperation->deleteTuple();
- theOperation->equal((Uint32)0, key);
- int ret = aCon->execute(NoCommit);
- assert (ret != -1);
-}
-
-void insertNoCommit(NdbConnection* aCon, Uint32* flip, unsigned int key)
-{
- NdbOperation* theOperation;
- Uint32 placeholder[100];
-
- *flip = *flip + 1;
- theOperation = aCon->getNdbOperation("SHORT_REC");
- theOperation->insertTuple();
- theOperation->equal((Uint32)0, key);
- theOperation->setValue((Uint32)1, (char*)flip);
- theOperation->setValue((Uint32)2, (char*)&placeholder[0]);
- theOperation->setValue((Uint32)3, (char*)&placeholder[0]);
- int ret = aCon->execute(NoCommit);
- assert (ret != -1);
-}
-
-void writeNoCommit(NdbConnection* aCon, Uint32* flip, unsigned int key)
-{
- NdbOperation* theOperation;
- Uint32 placeholder[100];
-
- *flip = *flip + 1;
- theOperation = aCon->getNdbOperation("SHORT_REC");
- theOperation->writeTuple();
- theOperation->equal((Uint32)0, key);
- theOperation->setValue((Uint32)1, (char*)flip);
- theOperation->setValue((Uint32)2, (char*)&placeholder[0]);
- theOperation->setValue((Uint32)3, (char*)&placeholder[0]);
- int ret = aCon->execute(NoCommit);
- assert (ret != -1);
-}
-
-void readNoCommit(NdbConnection* aCon, Uint32* flip, Uint32 key, int expected_ret)
-{
- NdbOperation* theOperation;
- Uint32 readFlip;
-
- theOperation = aCon->getNdbOperation("SHORT_REC");
- theOperation->readTuple();
- theOperation->equal((Uint32)0, key);
- theOperation->getValue((Uint32)1, (char*)&readFlip);
- int ret = aCon->execute(NoCommit);
- assert (ret == expected_ret);
- if (ret == 0)
- assert (*flip == readFlip);
-}
-
-void readDirtyNoCommit(NdbConnection* aCon, Uint32* flip, Uint32 key, int expected_ret)
-{
- NdbOperation* theOperation;
- Uint32 readFlip;
-
- theOperation = aCon->getNdbOperation("SHORT_REC");
- theOperation->committedRead();
- theOperation->equal((Uint32)0, key);
- theOperation->getValue((Uint32)1, (char*)&readFlip);
- int ret = aCon->execute(NoCommit);
- assert (ret == expected_ret);
- if (ret == 0)
- assert (*flip == readFlip);
-}
-
-void readVerify(Ndb* aNdb, Uint32* flip, Uint32 key, int expected_ret)
-{
- NdbConnection* theTransaction;
- theTransaction = aNdb->startTransaction();
- readNoCommit(theTransaction, flip, key, expected_ret);
- commitTrans(aNdb, theTransaction);
-}
-
-void readDirty(Ndb* aNdb, Uint32* flip, Uint32 key, int expected_ret)
-{
- NdbOperation* theOperation;
- NdbConnection* theTransaction;
- Uint32 readFlip;
-
- theTransaction = aNdb->startTransaction();
- theOperation = theTransaction->getNdbOperation("SHORT_REC");
- theOperation->committedRead();
- theOperation->equal((Uint32)0, key);
- theOperation->getValue((Uint32)1, (char*)&readFlip);
- int ret = theTransaction->execute(Commit);
- assert (ret == expected_ret);
- if (ret == 0)
- assert (*flip == readFlip);
- aNdb->closeTransaction(theTransaction);
-}
-
-int multiRecordTest(Ndb* aNdb, unsigned int key)
-{
- NdbConnection* theTransaction;
- Uint32 flip = 0;
- Uint32 save_flip;
- ndbout << "0" << endl;
-
- theTransaction = aNdb->startTransaction();
-
- updateNoCommit(theTransaction, &flip, key);
-
- readNoCommit(theTransaction, &flip, key, 0);
-
- updateNoCommit(theTransaction, &flip, key);
-
- readNoCommit(theTransaction, &flip, key, 0);
-
- commitTrans(aNdb, theTransaction);
-
- ndbout << "1 " << endl;
-
- readVerify(aNdb, &flip, key, 0);
- readDirty(aNdb, &flip, key, 0);
- save_flip = flip;
- ndbout << "1.1 " << endl;
-
- theTransaction = aNdb->startTransaction();
-
- deleteNoCommit(theTransaction, &flip, key);
-
- readNoCommit(theTransaction, &flip, key, -1);
- readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
- readDirtyNoCommit(theTransaction, &flip, key, -1);
- ndbout << "1.2 " << endl;
-
- insertNoCommit(theTransaction, &flip, key);
-
- readNoCommit(theTransaction, &flip, key, 0);
- readDirtyNoCommit(theTransaction, &flip, key, 0);
- readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
- ndbout << "1.3 " << endl;
-
- updateNoCommit(theTransaction, &flip, key);
-
- readNoCommit(theTransaction, &flip, key, 0);
- readDirtyNoCommit(theTransaction, &flip, key, 0);
- readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
- ndbout << "1.4 " << endl;
-
- commitTrans(aNdb, theTransaction);
-
- ndbout << "2 " << endl;
-
- readDirty(aNdb, &flip, key, 0); // COMMITTED READ!!!
- readVerify(aNdb, &flip, key, 0);
-
- save_flip = flip;
- theTransaction = aNdb->startTransaction();
-
- deleteNoCommit(theTransaction, &flip, key);
-
- readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
- readDirtyNoCommit(theTransaction, &flip, key, -1); // COMMITTED READ!!!
- readNoCommit(theTransaction, &flip, key, -1);
-
- insertNoCommit(theTransaction, &flip, key);
-
- readNoCommit(theTransaction, &flip, key, 0);
-
- updateNoCommit(theTransaction, &flip, key);
-
- readNoCommit(theTransaction, &flip, key, 0);
- readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
- readDirtyNoCommit(theTransaction, &flip, key, 0); // COMMITTED READ!!!
-
- deleteNoCommit(theTransaction, &flip, key);
-
- readNoCommit(theTransaction, &flip, key, -1);
- readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
- readDirtyNoCommit(theTransaction, &flip, key, -1);
-
- rollbackTrans(aNdb, theTransaction);
-
- ndbout << "3 " << endl;
-
- flip = save_flip;
- readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
- readVerify(aNdb, &flip, key, 0);
-
- theTransaction = aNdb->startTransaction();
-
- updateNoCommit(theTransaction, &flip, key);
-
- readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
- readDirtyNoCommit(theTransaction, &flip, key, 0);
- readNoCommit(theTransaction, &flip, key, 0);
-
- deleteNoCommit(theTransaction, &flip, key);
-
- readNoCommit(theTransaction, &flip, key, -1);
- readDirtyNoCommit(theTransaction, &flip, key, -1);
- readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
-
- insertNoCommit(theTransaction, &flip, key);
-
- readNoCommit(theTransaction, &flip, key, 0);
- readDirtyNoCommit(theTransaction, &flip, key, 0);
- readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
-
- updateNoCommit(theTransaction, &flip, key);
-
- readNoCommit(theTransaction, &flip, key, 0);
- readDirtyNoCommit(theTransaction, &flip, key, 0);
- readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
-
- deleteNoCommit(theTransaction, &flip, key);
-
- readDirty(aNdb, &save_flip, key, 0); // COMMITTED READ!!!
- readNoCommit(theTransaction, &flip, key, -1);
- readDirtyNoCommit(theTransaction, &flip, key, -1);
-
- commitTrans(aNdb, theTransaction);
-
- ndbout << "4 " << endl;
-
- readVerify(aNdb, &flip, key, -1);
-
- theTransaction = aNdb->startTransaction();
-
- insertNoCommit(theTransaction, &flip, key);
-
- readDirty(aNdb, &save_flip, key, -1); // COMMITTED READ!!!
- readNoCommit(theTransaction, &flip, key, 0);
- readDirtyNoCommit(theTransaction, &flip, key, 0);
-
- deleteNoCommit(theTransaction, &flip, key);
-
- readDirty(aNdb, &save_flip, key, -1); // COMMITTED READ!!!
- readNoCommit(theTransaction, &flip, key, -1);
- readDirtyNoCommit(theTransaction, &flip, key, -1);
-
- insertNoCommit(theTransaction, &flip, key);
-
- readDirty(aNdb, &save_flip, key, -1); // COMMITTED READ!!!
- readNoCommit(theTransaction, &flip, key, 0);
- readDirtyNoCommit(theTransaction, &flip, key, 0);
-
- updateNoCommit(theTransaction, &flip, key);
-
- readDirty(aNdb, &save_flip, key, -1); // COMMITTED READ!!!
- readNoCommit(theTransaction, &flip, key, 0);
- readDirtyNoCommit(theTransaction, &flip, key, 0);
-
- deleteNoCommit(theTransaction, &flip, key);
-
- readDirty(aNdb, &save_flip, key, -1); // COMMITTED READ!!!
- readNoCommit(theTransaction, &flip, key, -1);
- readDirtyNoCommit(theTransaction, &flip, key, -1);
-
- commitTrans(aNdb, theTransaction);
-
- ndbout << "5 " << endl;
-
- readDirty(aNdb, &flip, key, -1); // COMMITTED READ!!!
- readVerify(aNdb, &flip, key, -1);
-
- theTransaction = aNdb->startTransaction();
-
- insertNoCommit(theTransaction, &flip, key);
-
- readDirty(aNdb, &flip, key, -1); // COMMITTED READ!!!
- readDirtyNoCommit(theTransaction, &flip, key, 0); // COMMITTED READ!!!
-
- commitTrans(aNdb, theTransaction);
- readDirty(aNdb, &flip, key, 0); // COMMITTED READ!!!
-
- ndbout << "6 " << endl;
-
- theTransaction = aNdb->startTransaction();
-
- deleteNoCommit(theTransaction, &flip, key);
- updateNoCommitFail(theTransaction, key);
- rollbackTrans(aNdb, theTransaction);
- return 0;
-}
-
-int lookup(Ndb* aNdb, unsigned int key, unsigned int long_short, int guess){
-
- int placeholder[500];
- unsigned int flip, count;
- int ret_value, i;
- NdbConnection* theTransaction;
- NdbOperation* theOperation;
- if ( !aNdb ) return -1 ;
-
- if (guess != 0)
- theTransaction = aNdb->startTransaction((Uint32)0, (const char*)&key, (Uint32)4);
- else
- theTransaction = aNdb->startTransaction();
-
- for (i = 0; i < tNoOfOpsPerExecute; i++) {
- if (long_short == 0)
- theOperation = theTransaction->getNdbOperation("SHORT_REC");
- else
- theOperation = theTransaction->getNdbOperation("LONG_REC");
- if (theOperation == NULL) {
- ndbout << "Table missing" << endl;
- aNdb->closeTransaction(theTransaction) ;
- return -1;
- }//if
- theOperation->simpleRead();
- theOperation->equal((Uint32)0, key);
- theOperation->getValue((Uint32)1, (char*)&flip);
- theOperation->getValue((Uint32)2, (char*)&count);
- if (theOperation->getValue((Uint32)3, (char*)&placeholder[0]) == NULL) {
- ndbout << "Error in definition phase = " << theTransaction->getNdbError() << endl;
- aNdb->closeTransaction(theTransaction);
- return -1;
- }//if
- }//for
- ret_value = theTransaction->execute(Commit);
- if (ret_value == -1)
- ndbout << "Error in lookup:" << theTransaction->getNdbError() << endl;
- aNdb->closeTransaction(theTransaction);
- return ret_value;
-}//lookup()
-
-int update(Ndb* aNdb, unsigned int key, unsigned int long_short, int guess)
-{
- int placeholder[500];
- int ret_value, i;
- unsigned int flip, count;
- NdbConnection* theTransaction;
- NdbOperation* theOperation;
-
- if ( !aNdb ) return -1 ;
-
- if (guess != 0)
- theTransaction = aNdb->startTransaction((Uint32)0, (const char*)&key, (Uint32)4);
- else
- theTransaction = aNdb->startTransaction();
-
- for (i = 0; i < tNoOfOpsPerExecute; i++) {
- if (long_short == 0)
- theOperation = theTransaction->getNdbOperation("SHORT_REC"); // Use table SHORT_REC
- else
- theOperation = theTransaction->getNdbOperation("LONG_REC"); // Use table LONG_REC
- if (theOperation == NULL) {
- ndbout << "Table missing" << endl;
- aNdb->closeTransaction(theTransaction) ;
- delete aNdb ;
- return -1;
- }//if
- theOperation->interpretedUpdateTuple(); // Send interpreted program to NDB kernel
- theOperation->equal((Uint32)0, key); // Search key
- theOperation->getValue((Uint32)1, (char*)&flip); // Read value of flip
- theOperation->getValue((Uint32)2, (char*)&count); // Read value of count
- theOperation->getValue((Uint32)3, (char*)&placeholder[0]); // Read value of placeholder
- theOperation->load_const_u32((Uint32)1, (Uint32)0); // Load register 1 with 0
- theOperation->read_attr((Uint32)1, (Uint32)2); // Read Flip value into register 2
- theOperation->branch_eq((Uint32)1, (Uint32)2, (Uint32)0); // If Flip (register 2) == 0 (register 1) goto label 0
- theOperation->branch_label((Uint32)1); // Goto label 1
- theOperation->def_label((Uint32)0); // Define label 0
- theOperation->load_const_u32((Uint32)1, (Uint32)1); // Load register 1 with 1
- theOperation->def_label((Uint32)1); // Define label 0
- theOperation->write_attr((Uint32)1, (Uint32)1); // Write 1 (register 1) into Flip
- ret_value = theOperation->incValue((Uint32)2, (Uint32)1); // Increment Count by 1
- if (ret_value == -1) {
- ndbout << "Error in definition phase " << endl;
- aNdb->closeTransaction(theTransaction);
- return ret_value;
- }//if
- }//for
- ret_value = theTransaction->execute(Commit); // Perform the actual read and update
- if (ret_value == -1) {
- ndbout << "Error in update:" << theTransaction->getNdbError() << endl;
- aNdb->closeTransaction(theTransaction); // < epaulsa
- return ret_value ;
- }//if
- aNdb->closeTransaction(theTransaction);
- return ret_value;
-}//update()
-
-int update_bug(Ndb* aNdb, unsigned int key, unsigned int long_short)
-{
- int placeholder[500];
- int ret_value, i;
- unsigned int flip, count;
- NdbConnection* theTransaction;
- NdbOperation* theOperation;
-
- if ( !aNdb ) return -1 ;
-
- theTransaction = aNdb->startTransaction();
- for (i = 0; i < tNoOfOpsPerExecute; i++) {
- if (long_short == 0)
- theOperation = theTransaction->getNdbOperation("SHORT_REC"); // Use table SHORT_REC
- else
- theOperation = theTransaction->getNdbOperation("LONG_REC"); // Use table LONG_REC
- if (theOperation == NULL) {
- ndbout << "Table missing" << endl;
- aNdb->closeTransaction(theTransaction) ;
- return -1;
- }//if
- theOperation->interpretedUpdateTuple(); // Send interpreted program to NDB kernel
- theOperation->equal((Uint32)0, key); // Search key
- theOperation->getValue((Uint32)1, (char*)&flip); // Read value of flip
- theOperation->getValue((Uint32)2, (char*)&count); // Read value of count
- theOperation->getValue((Uint32)3, (char*)&placeholder[0]); // Read value of placeholder
- theOperation->load_const_u32((Uint32)1, (Uint32)0); // Load register 1 with 0
- theOperation->read_attr((Uint32)1, (Uint32)2); // Read Flip value into register 2
- theOperation->branch_eq((Uint32)1, (Uint32)2, (Uint32)0); // If Flip (register 2) == 0 (register 1) goto label 0
- theOperation->branch_label((Uint32)1); // Goto label 1
- theOperation->def_label((Uint32)0); // Define label 0
- theOperation->load_const_u32((Uint32)1, (Uint32)1); // Load register 1 with 1
- theOperation->def_label((Uint32)1); // Define label 0
- theOperation->write_attr((Uint32)1, (Uint32)1); // Write 1 (register 1) into Flip
- ret_value = theOperation->incValue((Uint32)2, (Uint32)1); // Increment Count by 1
- if (ret_value == -1) {
- ndbout << "Error in definition phase " << endl;
- aNdb->closeTransaction(theTransaction);
- return ret_value;
- }//if
- }//for
- ret_value = theTransaction->execute(NoCommit); // Perform the actual read and update
- if (ret_value == -1) {
- ndbout << "Error in update:" << theTransaction->getNdbError() << endl;
- aNdb->closeTransaction(theTransaction);
- return ret_value ;
- }//if
- aNdb->closeTransaction(theTransaction);
- return ret_value;
-}//update_bug()
-
-int update_interpreter_test(Ndb* aNdb, unsigned int key, unsigned int long_short)
-{
- int placeholder[500];
- int ret_value, i;
- unsigned int flip, count;
- NdbConnection* theTransaction;
- NdbOperation* theOperation;
- Uint32 Tlabel = 0;
-
- if ( !aNdb ) return -1 ;
-
-//------------------------------------------------------------------------------
-// Start the transaction and get a unique transaction id
-//------------------------------------------------------------------------------
- theTransaction = aNdb->startTransaction();
- for (i = 0; i < tNoOfOpsPerExecute; i++) {
-//------------------------------------------------------------------------------
-// Get the proper table object and load schema information if not already
-// present.
-//------------------------------------------------------------------------------
- if (long_short == 0)
- theOperation = theTransaction->getNdbOperation("SHORT_REC"); // Use table SHORT_REC
- else
- theOperation = theTransaction->getNdbOperation("LONG_REC"); // Use table LONG_REC
- if (theOperation == NULL) {
- ndbout << "Table missing" << endl;
- aNdb->closeTransaction(theTransaction) ;
- return -1;
- }//if
-//------------------------------------------------------------------------------
-// Define the operation type and the tuple key (primary key in this case).
-//------------------------------------------------------------------------------
- theOperation->interpretedUpdateTuple(); // Send interpreted program to NDB kernel
- theOperation->equal((Uint32)0, key); // Search key
-
-//------------------------------------------------------------------------------
-// Perform initial read of attributes before updating them
-//------------------------------------------------------------------------------
- theOperation->getValue((Uint32)1, (char*)&flip); // Read value of flip
- theOperation->getValue((Uint32)2, (char*)&count); // Read value of count
- theOperation->getValue((Uint32)3, (char*)&placeholder[0]); // Read value of placeholder
-
-//------------------------------------------------------------------------------
-// Test that the various branch operations can handle things correctly.
-// Test first 2 + 3 = 5 with 32 bit registers
-// Next test the same with 32 bit + 64 bit = 64
-//------------------------------------------------------------------------------
- theOperation->load_const_u32((Uint32)4, (Uint32)0); // Load register 4 with 0
-
- theOperation->load_const_u32((Uint32)0, (Uint32)0);
- theOperation->load_const_u32((Uint32)1, (Uint32)3);
- theOperation->load_const_u32((Uint32)2, (Uint32)5);
- theOperation->load_const_u32((Uint32)3, (Uint32)1);
- theOperation->def_label(Tlabel++);
- theOperation->def_label(Tlabel++);
- theOperation->sub_reg((Uint32)2, (Uint32)3, (Uint32)2);
- theOperation->branch_ne((Uint32)2, (Uint32)0, (Uint32)0);
- theOperation->load_const_u32((Uint32)2, (Uint32)5);
- theOperation->sub_reg((Uint32)1, (Uint32)3, (Uint32)1);
- theOperation->branch_ne((Uint32)1, (Uint32)0, (Uint32)1);
-
- theOperation->load_const_u32((Uint32)1, (Uint32)2); // Load register 1 with 2
- theOperation->load_const_u32((Uint32)2, (Uint32)3); // Load register 2 with 3
- theOperation->add_reg((Uint32)1, (Uint32)2, (Uint32)1); // 2+3 = 5 into reg 1
- theOperation->load_const_u32((Uint32)2, (Uint32)5); // Load register 2 with 5
-
- theOperation->def_label(Tlabel++);
-
- theOperation->branch_eq((Uint32)1, (Uint32)2, Tlabel);
- theOperation->interpret_exit_nok((Uint32)6001);
-
- theOperation->def_label(Tlabel++);
- theOperation->branch_ne((Uint32)1, (Uint32)2, Tlabel);
- theOperation->branch_label(Tlabel + 1);
- theOperation->def_label(Tlabel++);
- theOperation->interpret_exit_nok((Uint32)6002);
-
- theOperation->def_label(Tlabel++);
- theOperation->branch_lt((Uint32)1, (Uint32)2, Tlabel);
- theOperation->branch_label(Tlabel + 1);
- theOperation->def_label(Tlabel++);
- theOperation->interpret_exit_nok((Uint32)6003);
-
- theOperation->def_label(Tlabel++);
- theOperation->branch_gt((Uint32)1, (Uint32)2, Tlabel);
- theOperation->branch_label(Tlabel + 1);
- theOperation->def_label(Tlabel++);
- theOperation->interpret_exit_nok((Uint32)6005);
-
- theOperation->def_label(Tlabel++);
- theOperation->branch_eq_null((Uint32)1, Tlabel);
- theOperation->branch_label(Tlabel + 1);
- theOperation->def_label(Tlabel++);
- theOperation->interpret_exit_nok((Uint32)6006);
-
- theOperation->def_label(Tlabel++);
- theOperation->branch_ne_null((Uint32)1,Tlabel);
- theOperation->interpret_exit_nok((Uint32)6007);
-
- theOperation->def_label(Tlabel++);
- theOperation->branch_ge((Uint32)1, (Uint32)2, Tlabel);
- theOperation->interpret_exit_nok((Uint32)6008);
-
- theOperation->def_label(Tlabel++);
- theOperation->branch_eq_null((Uint32)6,Tlabel);
- theOperation->interpret_exit_nok((Uint32)6009);
-
- theOperation->def_label(Tlabel++);
- theOperation->branch_ne_null((Uint32)6, Tlabel);
- theOperation->branch_label(Tlabel + 1);
- theOperation->def_label(Tlabel++);
- theOperation->interpret_exit_nok((Uint32)6010);
-
- theOperation->def_label(Tlabel++);
-
- theOperation->load_const_u32((Uint32)5, (Uint32)1);
- theOperation->add_reg((Uint32)4, (Uint32)5, (Uint32)4);
-
- theOperation->load_const_u32((Uint32)5, (Uint32)1);
- theOperation->branch_eq((Uint32)4, (Uint32)5, Tlabel);
-
-
- theOperation->load_const_u32((Uint32)5, (Uint32)2);
- theOperation->branch_eq((Uint32)4, (Uint32)5, (Tlabel + 1));
-
- theOperation->load_const_u32((Uint32)5, (Uint32)3);
- theOperation->branch_eq((Uint32)4, (Uint32)5, (Tlabel + 2));
-
- theOperation->load_const_u32((Uint32)5, (Uint32)4);
- theOperation->branch_eq((Uint32)4, (Uint32)5, (Tlabel + 3));
-
- theOperation->branch_label(Tlabel + 4);
-
- theOperation->def_label(Tlabel++);
- theOperation->load_const_u32((Uint32)1, (Uint32)200000);
- theOperation->load_const_u32((Uint32)2, (Uint32)300000);
- theOperation->add_reg((Uint32)1, (Uint32)2, (Uint32)1);
- theOperation->load_const_u32((Uint32)2, (Uint32)500000);
- theOperation->branch_label((Uint32)2);
-
- theOperation->def_label(Tlabel++);
- theOperation->load_const_u32((Uint32)1, (Uint32)200000);
- theOperation->load_const_u32((Uint32)2, (Uint32)300000);
- theOperation->add_reg((Uint32)1, (Uint32)2, (Uint32)1);
- theOperation->load_const_u32((Uint32)2, (Uint32)500000);
- theOperation->branch_label((Uint32)2);
-
- theOperation->def_label(Tlabel++);
- theOperation->load_const_u32((Uint32)1, (Uint32)2);
- Uint64 x = 0;
- theOperation->load_const_u64((Uint32)2, (Uint64)(x - 1));
- theOperation->add_reg((Uint32)1, (Uint32)2, (Uint32)1);
- theOperation->load_const_u32((Uint32)2, (Uint32)1);
- theOperation->branch_label((Uint32)2);
-
- theOperation->def_label(Tlabel++);
- theOperation->load_const_u32((Uint32)1, (Uint32)2);
- theOperation->load_const_u64((Uint32)2, (Uint64)(x - 1));
- theOperation->add_reg((Uint32)1, (Uint32)2, (Uint32)1);
- theOperation->load_const_u64((Uint32)2, (Uint64)1);
- theOperation->branch_label((Uint32)2);
-
- theOperation->def_label(Tlabel++);
- theOperation->read_attr((Uint32)1, (Uint32)2);
- theOperation->branch_eq((Uint32)1, (Uint32)2, Tlabel);
- theOperation->load_const_u32((Uint32)1, (Uint32)0);
- theOperation->branch_label(Tlabel + 1);
- theOperation->def_label(Tlabel++);
- theOperation->load_const_u32((Uint32)1, (Uint32)1);
- theOperation->def_label(Tlabel++);
- theOperation->write_attr((Uint32)1, (Uint32)1);
- ret_value = theOperation->incValue((Uint32)2, (Uint32)1);
- if (ret_value == -1) {
- ndbout << "Error in definition phase " << endl;
- ndbout << "Error = " << theOperation->getNdbError() << " on line = " << theOperation->getNdbErrorLine() << endl;
- aNdb->closeTransaction(theTransaction);
- return ret_value;
- }//if
- }//for
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
- ret_value = theTransaction->execute(Commit); // Perform the actual read and update
- if (ret_value == -1) {
- ndbout << "Error in update:" << theTransaction->getNdbError() << endl;
- aNdb->closeTransaction(theTransaction); // < epaulsa
- return ret_value ;
- }//if
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
- aNdb->closeTransaction(theTransaction);
- return ret_value;
-}//update_interpreter_test()
-
-void* ThreadExec(void* ThreadData){
-
- ThreadNdb* tabThread = (ThreadNdb*)ThreadData;
- Ndb* pMyNdb = NULL ;
- myRandom48Init(NdbTick_CurrentMillisecond());
-
- int Tsuccess = 0 ;
- int check = 0 ;
- int loop_count_ops = 0;
- int count, i, Ti;
- int tType = 0 ;
- int remType = 0 ;
- unsigned int thread_no = 0 ;
- unsigned long total_milliseconds;
- unsigned int key = 0 ;
- unsigned int prob = 0 ;
- unsigned long transaction_time = 0 ;
- unsigned long transaction_max_time = 0 ;
- unsigned long min_time, max_time[MAX_TIMERS];
- double mean_time, mean_square_time, std_time;
-
- thread_no = tabThread->ThreadNo;
- pMyNdb = tabThread->NdbRef;
- if (!pMyNdb) {
- pMyNdb = new Ndb( "TEST_DB" );
- pMyNdb->init();
- }//if
-
- for (;;){
-
- min_time = 0xFFFFFFFF;
- //for (Ti = 0; Ti < MAX_TIMERS ; Ti++) max_time[Ti] = 0;
- memset(&max_time, 0, sizeof max_time) ;
- mean_time = 0;
- mean_square_time = 0;
- ThreadReady[thread_no] = 1;
-
- while (!ThreadStart[thread_no]){
- NdbSleep_MilliSleep(1);
- }
-
- // Check if signal to exit is received
- if (ThreadStart[thread_no] == 999){
- delete pMyNdb;
- pMyNdb = NULL ;
- ThreadReady[thread_no] = 1;
- return 0 ;
- }//if
-
- tType = ThreadStart[thread_no];
- remType = tType;
- ThreadStart[thread_no] = 0;
- ThreadReady[thread_no] = 0 ;
-
- // Start transaction, type of transaction
- // is received in the array ThreadStart
- loop_count_ops = tNoOfOperations;
-
- START_TIMER_TOP
- for (count=0 ; count < loop_count_ops ; count++) {
-
- Tsuccess = 0;
-//----------------------------------------------------
-// Generate a random key between 0 and tNoOfRecords - 1
-//----------------------------------------------------
- key = myRandom48(tNoOfRecords);
-//----------------------------------------------------
-// Start time measurement of transaction.
-//----------------------------------------------------
- START_TIMER
- //do {
- switch (remType){
- case 1:
-//----------------------------------------------------
-// Only lookups in short record table
-//----------------------------------------------------
- Tsuccess = lookup(pMyNdb, key, 0, 1);
- break;
-
- case 2:
-//----------------------------------------------------
-// Only lookups in long record table
-//----------------------------------------------------
- Tsuccess = lookup(pMyNdb, key, 1, 1);
- break;
- case 3:
-//----------------------------------------------------
-// Only updates in short record table
-//----------------------------------------------------
- Tsuccess = update(pMyNdb, key, 0, 1);
- break;
- case 4:
-//----------------------------------------------------
-// Only updates in long record table
-//----------------------------------------------------
- Tsuccess = update(pMyNdb, key, 1, 1);
- break;
- case 5:
-//----------------------------------------------------
-// 50% read/50 % update in short record table
-//----------------------------------------------------
- prob = myRandom48(100);
- if (prob < 50)
- Tsuccess = update(pMyNdb, key, 0, 1);
- else
- Tsuccess = lookup(pMyNdb, key, 0, 1);
- break;
- case 6:
-//----------------------------------------------------
-// 50% read/50 % update in long record table
-//----------------------------------------------------
- prob = myRandom48(100);
- if (prob < 50)
- Tsuccess = update(pMyNdb, key, 1, 1);
- else
- Tsuccess = lookup(pMyNdb, key, 1, 1);
- break;
- case 7:
-//----------------------------------------------------
-// 80 read/20 % update in short record table
-//----------------------------------------------------
- prob = myRandom48(100);
- if (prob < 20)
- Tsuccess = update(pMyNdb, key, 0, 1);
- else
- Tsuccess = lookup(pMyNdb, key, 0, 1);
- break;
- case 8:
-//----------------------------------------------------
-// 80 read/20 % update in long record table
-//----------------------------------------------------
- prob = myRandom48(100);
- if (prob < 20)
- Tsuccess = update(pMyNdb, key, 1, 1);
- else
- Tsuccess = lookup(pMyNdb, key, 1, 1);
- break;
- case 9:
-//----------------------------------------------------
-// 25 read short/25 % read long/25 % update short/25 % update long
-//----------------------------------------------------
- prob = myRandom48(100);
- if (prob < 25)
- Tsuccess = update(pMyNdb, key, 0, 1);
- else if (prob < 50)
- Tsuccess = update(pMyNdb, key, 1, 1);
- else if (prob < 75)
- Tsuccess = lookup(pMyNdb, key, 0, 1);
- else
- Tsuccess = lookup(pMyNdb, key, 1, 1);
- break;
- case 10:
-//----------------------------------------------------
-// Test bug with replicated interpreted update, short table
-//----------------------------------------------------
- Tsuccess = update_bug(pMyNdb, key, 0);
- break;
- case 11:
-//----------------------------------------------------
-// Test interpreter functions, short table
-//----------------------------------------------------
- Tsuccess = update_interpreter_test(pMyNdb, key, 0);
- break;
- case 12:
-//----------------------------------------------------
-// Test bug with replicated interpreted update, long table
-//----------------------------------------------------
- Tsuccess = update_bug(pMyNdb, key, 1);
- break;
- case 13:
-//----------------------------------------------------
-// Test interpreter functions, long table
-//----------------------------------------------------
- Tsuccess = update_interpreter_test(pMyNdb, key, 1);
- break;
- case 14:
-//----------------------------------------------------
-// Only lookups in short record table
-//----------------------------------------------------
- Tsuccess = lookup(pMyNdb, key, 0, 0);
- break;
- case 15:
-//----------------------------------------------------
-// Only lookups in long record table
-//----------------------------------------------------
- Tsuccess = lookup(pMyNdb, key, 1, 0);
- break;
- case 16:
-//----------------------------------------------------
-// Only updates in short record table
-//----------------------------------------------------
- Tsuccess = update(pMyNdb, key, 0, 0);
- break;
- case 17:
-//----------------------------------------------------
-// Only updates in long record table
-//----------------------------------------------------
- Tsuccess = update(pMyNdb, key, 1, 0);
- break;
- case 18:
- Tsuccess = multiRecordTest(pMyNdb, key);
- break;
- default:
- break;
- }//switch
- //} while (0);//
- if(-1 == Tsuccess) {
- NDBT_ProgramExit(NDBT_FAILED);
- exit(-1);
- } // for
-//----------------------------------------------------
-// Stop time measurement of transaction.
-//----------------------------------------------------
- STOP_TIMER
- transaction_time = (unsigned long)timer.elapsedTime() ;//stopTimer(&theStartTime);
-//----------------------------------------------------
-// Perform calculations of time measurements.
-//----------------------------------------------------
- transaction_max_time = transaction_time;
- for (Ti = 0; Ti < MAX_TIMERS; Ti++) {
- if (transaction_max_time > max_time[Ti]) {
- Uint32 tmp = max_time[Ti];
- max_time[Ti] = transaction_max_time;
- transaction_max_time = tmp;
- }//if
- }//if
- if (transaction_time < min_time) min_time = transaction_time;
- mean_time = (double)transaction_time + mean_time;
- mean_square_time = (double)(transaction_time * transaction_time) + mean_square_time;
- }//for
-//----------------------------------------------------
-// Calculate mean and standard deviation
-//----------------------------------------------------
- STOP_TIMER_TOP
- total_milliseconds = (unsigned long)timer_top.elapsedTime() ;//stopTimer(&total_time);
- mean_time = mean_time / loop_count_ops;
- mean_square_time = mean_square_time / loop_count_ops;
- std_time = sqrt(mean_square_time - (mean_time * mean_time));
-//----------------------------------------------------
-// Report statistics
-//----------------------------------------------------
- ndbout << "Thread = " << thread_no << " reporting:" << endl ;
- ndbout << "------------------------------" << endl ;
- ndbout << "Total time is " << (unsigned int)(total_milliseconds /1000);
- ndbout << " seconds and " << (unsigned int)(total_milliseconds % 1000);
- ndbout << " milliseconds" << endl;
- ndbout << "Minimum time = " << (unsigned int)min_time << " milliseconds" << endl;
- for (Ti = 0; Ti < MAX_TIMERS; Ti++) {
- ndbout << "Maximum timer " << Ti << " = " << (unsigned int)max_time[Ti] << " milliseconds" << endl;
- ndbout << "Mean time = " << (unsigned int)mean_time << " milliseconds" << endl;
- ndbout << "Standard deviation on time = " << (unsigned int)std_time;
- ndbout << " milliseconds" << endl << endl ;
- }//for
- ndbout << endl ;
-
- } // for(;;)
-
- delete pMyNdb ;
- return 0 ;
-}
-
diff --git a/storage/ndb/test/ndbapi/bulk_copy.cpp b/storage/ndb/test/ndbapi/bulk_copy.cpp
deleted file mode 100644
index 6a5a15b456a..00000000000
--- a/storage/ndb/test/ndbapi/bulk_copy.cpp
+++ /dev/null
@@ -1,276 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-#include <NdbOut.hpp>
-#include <NdbApi.hpp>
-#include <NdbSleep.h>
-#include <NDBT.hpp>
-
-#include <getarg.h>
-
-
-int setValuesFromLine(NdbOperation* pOp,
- const NdbDictionary::Table* pTab,
- char* line){
-
- int check = 0;
- char* p = line;
- char* pn;
- char buf[8000];
- // Loop through each attribute in this table
- for (int a = 0; a<pTab->getNoOfColumns(); a++){
-
- pn = p;
- while (*pn != ';')
- pn++;
-
- memset(buf, 0, sizeof(buf));
- strncpy(buf, p, pn-p);
- // ndbout << a << ": " << buf << endl;
- const NdbDictionary::Column* attr = pTab->getColumn(a);
- switch (attr->getType()){
- case NdbDictionary::Column::Unsigned:
- Int32 sval;
- if (sscanf(buf, "%d", &sval) == 0)
- return -2;
- check = pOp->setValue(a, sval);
- break;
-
- case NdbDictionary::Column::Int:
- Uint32 uval;
- if (sscanf(buf, "%u", &uval) == 0)
- return -2;
- check = pOp->setValue(a, uval);
- break;
-
- case NdbDictionary::Column::Char:
- char buf2[8000];
- char* p2;
- memset(buf2, 0, sizeof(buf));
- p2 = &buf2[0];
- while(*p != ';'){
- *p2 = *p;
- p++;p2++;
- };
- *p2 = 0;
- check = pOp->setValue(a, buf2);
- break;
-
- default:
- check = -2;
- break;
- }
-
- // Move pointer to after next ";"
- while (*p != ';')
- p++;
- p++;
-
- }
-
- return check;
-}
-
-
-int insertLine(Ndb* pNdb,
- const NdbDictionary::Table* pTab,
- char* line){
- int check;
- int retryAttempt = 0;
- int retryMax = 5;
- NdbConnection *pTrans;
- NdbOperation *pOp;
-
- while (retryAttempt < retryMax){
-
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- ERR(pNdb->getNdbError());
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
-
- pOp = pTrans->getNdbOperation(pTab->getName());
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return -1;
- }
-
- check = pOp->insertTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return -1;
- }
-
- check = setValuesFromLine(pOp,
- pTab,
- line);
- if (check == -2){
- pNdb->closeTransaction(pTrans);
- return -2;
- }
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return -1;
- }
-
-
- // Execute the transaction and insert the record
- check = pTrans->execute( Commit );
- if(check == -1 ) {
- const NdbError err = pTrans->getNdbError();
- pNdb->closeTransaction(pTrans);
-
- switch(err.status){
- case NdbError::Success:
- ERR(err);
- ndbout << "ERROR: NdbError reports success when transcaction failed" << endl;
- return -1;
- break;
-
- case NdbError::TemporaryError:
- ERR(err);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- break;
-
- case NdbError::UnknownResult:
- ERR(err);
- return -1;
- break;
-
- case NdbError::PermanentError:
- switch (err.classification){
- case NdbError::ConstraintViolation:
- // Tuple already existed, OK in this application, but should be reported
- ndbout << err.code << " " << err.message << endl;
- break;
- default:
- ERR(err);
- return -1;
- break;
- }
- break;
- }
- }
- else{
-
- pNdb->closeTransaction(pTrans);
- }
- return 0;
- }
- return check;
-}
-
-int insertFile(Ndb* pNdb,
- const NdbDictionary::Table* pTab,
- const char* fileName){
-
- const int MAX_LINE_LEN = 8000;
- char line[MAX_LINE_LEN];
- int lineNo = 0;
-
- FILE* instr = fopen(fileName, "r");
- if (instr == NULL){
- ndbout << "Coul'd not open " << fileName << endl;
- return -1;
- }
-
- while(fgets(line, MAX_LINE_LEN, instr)){
- lineNo++;
-
- if (line[strlen(line)-1] == '\n') {
- line[strlen(line)-1] = '\0';
- }
-
- int check = insertLine(pNdb, pTab, line);
- if (check == -2){
- ndbout << "Wrong format in input data file, line: " << lineNo << endl;
- fclose(instr);
- return -1;
- }
- if (check == -1){
- fclose(instr);
- return -1;
-
- }
- }
-
- fclose(instr);
- return 0;
-}
-
-
-int main(int argc, const char** argv){
- ndb_init();
-
- const char* _tabname = NULL;
- int _help = 0;
-
- struct getargs args[] = {
- { "usage", '?', arg_flag, &_help, "Print help", "" }
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "tabname\n"\
- "This program will bulk copy data from a file to a table in Ndb.\n";
-
- if(getarg(args, num_args, argc, argv, &optind) ||
- argv[optind] == NULL || _help) {
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
- _tabname = argv[optind];
- ndbout << "Tablename: " << _tabname << endl;
-
- // Connect to Ndb
- Ndb MyNdb( "TEST_DB" );
-
- if(MyNdb.init() != 0){
- ERR(MyNdb.getNdbError());
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- // Connect to Ndb and wait for it to become ready
- while(MyNdb.waitUntilReady() != 0)
- ndbout << "Waiting for ndb to become ready..." << endl;
-
- // Check if table exists in db
- const NdbDictionary::Table* pTab = MyNdb.getDictionary()->getTable(_tabname);
- if(pTab == NULL){
- ndbout << " Table " << _tabname << " does not exist!" << endl;
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- char buf[255];
- BaseString::snprintf(buf, sizeof(buf), "%s.data", (const char*)_tabname);
- if (insertFile(&MyNdb, pTab, buf) != 0){
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- return NDBT_ProgramExit(NDBT_OK);
-
-}
-
-
-
diff --git a/storage/ndb/test/ndbapi/cdrserver.cpp b/storage/ndb/test/ndbapi/cdrserver.cpp
deleted file mode 100644
index f867e9db934..00000000000
--- a/storage/ndb/test/ndbapi/cdrserver.cpp
+++ /dev/null
@@ -1,1628 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-/* **************************************************************** */
-/* */
-/* S E R V . T C P */
-/* * This is an example program that demonstrates the use of */
-/* stream sockets as an IPC mechanism. This contains the server, */
-/* and is intended to operate in conjunction with the client */
-/* program found in client.tcp. Together, these two programs */
-/* demonstrate many of the features of sockets, as well as good */
-/* conventions for using these features. */
-/* * This program provides a service called "example". In order for*/
-/* it to function, an entry for it needs to exist in the */
-/* ./etc/services file. The port address for this service can be */
-/* any port number that is likely to be unused, such as 22375, */
-/* for example. The host on which the client will be running */
-/* must also have the same entry (same port number) in its */
-/* ./etc/services file. */
-/* **************************************************************** */
-
-#include <ndb_global.h>
-
-/******** NDB INCLUDE ******/
-#include <NdbApi.hpp>
-/***************************/
-/*#include <sys/shm.h>*/
-#include <pthread.h>
-#include <sys/sem.h>
-#include <sys/shm.h>
-#include <netinet/in.h>
-#include <signal.h>
-#include <netdb.h>
-#include <time.h>
-#include <synch.h>
-#include <sched.h>
-
-extern "C" {
-#include "utv.h"
-#include "vcdrfunc.h"
-#include "bcd.h"
-}
-
-#ifndef TESTLEV
-#define TESTLEV
-#endif
-//#define DEBUG
-//#define MYDEBUG
-//#define SETDBG
-
-//#define ops_before_exe 64
-#define MAXOPSEXEC 1024
-
-/* Used in nanosleep */
-/**** NDB ********/
-static int bTestPassed;
-void create_table(Ndb* pMyNdb);
-void error_handler(const char* errorText);
-/*****************/
-static struct timespec tmspec1;
-static int server(long int);
-
-/* Function for initiating the cdr-area and make it clean for ongoing calls */
-
-static int s; /* connected socket descriptor */
-static int ls; /* listen socket descriptor */
-
-static struct hostent *hp; /* pointer to host info for remote host */
-static struct servent *sp; /* pointer to service information */
-
-struct linger linger; /* allow a lingering, graceful close; */
- /* used when setting SO_LINGER */
-
-static struct sockaddr_in myaddr_in; /* for local socket address */
-static struct sockaddr_in peeraddr_in; /* for peer socket address */
-
-static FILE *fi; /* Log output */
-static char temp[600]="";
-
-static int ops_before_exe = 1; /* Number of operations per execute, default is 1,
- but it can be changed with the -o parameter. */
-
-/*----------------------------------------------------------------------
-
- M A I N
- * This routine starts the server. It forks, leaving the child
- to do all the work, so it does not have to be run in the
- background. It sets up the listen socket, and for each incoming
- connection, it forks a child process to process the data. It
- will loop forever, until killed by a signal.
-
- ----------------------------------------------------------------------*/
-
-/****** NDB *******/
-static char *tableName = "VWTABLE";
-/******************/
-
-#include <iostream>
-using namespace std;
-
-int main(int argc, const char** argv)
-{
- ndb_init();
- /******** NDB ***********/
- /*
- Ndb MyNdb( "TEST_DB" );
- int tTableId;
- */
- /************************/
- char tmpbuf[400];
- /* Loop and status variables */
- int i,j,found;
-
- /* Used by the server */
- int addrlen;
-
- /* return code used with functions */
- int rc;
-
- i = 1;
- while (argc > 1)
- {
- if (strcmp(argv[i], "-o") == 0)
- {
- ops_before_exe = atoi(argv[i+1]);
- if ((ops_before_exe < 1) || (ops_before_exe > MAXOPSEXEC))
- {
- cout << "Number of operations per execute must be at least 1, and at most " << MAXOPSEXEC << endl;
- exit(1);
- }
-
- }
- else
- {
- cout << "Invalid parameter!" << endl << "Look in cdrserver.C for more info." << endl;
- exit(1);
- }
-
- argc -= 2;
- i = i + 2;
- }
-
-
- /* Setup log handling */
- logname(temp,"Cdrserver","Mother","");
- puts(temp);
- fi=fopen(temp,"w");
- if (fi == NULL)
- {
- perror(argv[0]);
- exit(EXIT_FAILURE);
- }
- m2log(fi,"Initiation of program");
-
- /***** NDB ******/
- /*
- MyNdb.init();
- if (MyNdb.waitUntilReady(30) != 0)
- {
- puts("Not ready");
- exit(-1);
- }
- tTableId = MyNdb.getTable()->openTable(tableName);
- if (tTableId == -1)
- {
- printf("%d: Creating table",getpid());
- create_table(&MyNdb);
- }
- else printf("%d: Table already create",getpid());
- */
-
- /****************/
-
- /* clear out address structures */
- memset ((char *)&myaddr_in, 0, sizeof(struct sockaddr_in));
- memset ((char *)&peeraddr_in, 0, sizeof(struct sockaddr_in));
-
- m2log(fi,"Socket setup starting");
-
- /* Set up address structure for the listen socket. */
- myaddr_in.sin_family = AF_INET;
-
- /* The server should listen on the wildcard address, */
- /* rather than its own internet address. This is */
- /* generally good practice for servers, because on */
- /* systems which are connected to more than one */
- /* network at once will be able to have one server */
- /* listening on all networks at once. Even when the */
- /* host is connected to only one network, this is good */
- /* practice, because it makes the server program more */
- /* portable. */
-
- myaddr_in.sin_addr.s_addr = INADDR_ANY;
- /* Find the information for the "cdrserver" server */
- /* in order to get the needed port number. */
-
- sp = getservbyname ("cdrserver", "tcp");
- if (sp == NULL) {
- m2log(fi,"Service cdrserver not found in /etc/services");
- m2log(fi,"Terminating.");
- exit(EXIT_FAILURE);
- }
-
- myaddr_in.sin_port = sp->s_port;
-
- /* Create the listen socket.i */
-
- ls = socket (AF_INET, SOCK_STREAM, 0);
- if (ls == -1) {
- m2log(fi,"Unable to create socket");
- m2log(fi,"Terminating.");
- exit(EXIT_FAILURE);
- }
- printf("Socket created\n");
- printf("Wait..........\n");
- /* Bind the listen address to the socket. */
- if (bind(ls,(struct sockaddr*)&myaddr_in, sizeof(struct sockaddr_in)) == -1) {
- m2log(fi,"Unable to bind address");
- m2log(fi,"Terminating.");
- exit(EXIT_FAILURE);
- }
-
- /* Initiate the listen on the socket so remote users */
- /* can connect. The listen backlog is set to 5, which */
- /* is the largest currently supported. */
-
- if (listen(ls, 5) == -1) {
- m2log(fi,"Unable to listen on socket");
- m2log(fi,"Terminating.");
- exit(EXIT_FAILURE);
- }
-
- /* Now, all the initialization of the server is */
- /* complete, and any user errors will have already */
- /* been detected. Now we can fork the daemon and */
- /* return to the user. We need to do a setpgrp */
- /* so that the daemon will no longer be associated */
- /* with the user's control terminal. This is done */
- /* before the fork, so that the child will not be */
- /* a process group leader. Otherwise, if the child */
- /* were to open a terminal, it would become associated */
- /* with that terminal as its control terminal. It is */
- /* always best for the parent to do the setpgrp. */
-
- m2log(fi,"Socket setup completed");
- m2log(fi,"Start server");
-
- setpgrp();
-
- /* Initiate the tmspec struct for use with nanosleep() */
- tmspec1.tv_sec = 0;
- tmspec1.tv_nsec = 1;
-
- printf("Waiting for client to connect.........\n");
- printf("Done\n");
- switch (fork()) {
- case -1: /* Unable to fork, for some reason. */
- m2log(fi,"Failed to start server");
- m2log(fi,"Terminating.");
- fclose(fi);
- perror(argv[0]);
- fprintf(stderr, "%s: unable to fork daemon\n", argv[0]);
- exit(EXIT_FAILURE);
-
- break;
- case 0: /* The child process (daemon) comes here. */
- m2log(fi,"Server started");
-
- /* Close stdin and stderr so that they will not */
- /* be kept open. Stdout is assumed to have been */
- /* redirected to some logging file, or /dev/null. */
- /* From now on, the daemon will not report any */
- /* error messages. This daemon will loop forever, */
- /* waiting for connections and forking a child */
- /* server to handle each one. */
-
- close((int)stdin);
- close((int)stderr);
- /* Set SIGCLD to SIG_IGN, in order to prevent */
- /* the accumulation of zombies as each child */
- /* terminates. This means the daemon does not */
- /* have to make wait calls to clean them up. */
-
- signal(SIGCLD, SIG_IGN);
- for(EVER) {
- if ((checkchangelog(fi,temp))==0)
- m2log(fi,"Waiting for connection");
- /* Note that addrlen is passed as a pointer */
- /* so that the accept call can return the */
- /* size of the returned address. */
-
- addrlen = sizeof(struct sockaddr_in);
-
- /* This call will block until a new */
- /* connection arrives. Then, it will */
- /* return the address of the connecting */
- /* peer, and a new socket descriptor, s, */
- /* for that connection. */
-
- s = accept(ls,(struct sockaddr*) &peeraddr_in, &addrlen);
- #ifdef MYDEBUG
- puts("accepted");
- #endif
- if ((checkchangelog(fi,temp))==0)
- m2log(fi,"Connection attempt from a client");
- if ((checkchangelog(fi,temp))==0)
- m2log(fi,"Start communication server");
-
- if ( s == -1) exit(EXIT_FAILURE);
- switch (fork()) {
- case -1: /* Can't fork, just exit. */
- if ((checkchangelog(fi,temp))==0)
- m2log(fi,"Start communication server failed.");
- exit(EXIT_FAILURE);
- break;
- case 0: /* Child process comes here. */
-
- /* Get clients adress and save it in the info area */
- /* Keep track of how many times the client connects to the server */
- printf("Connect attempt from client %u\n",peeraddr_in.sin_addr.s_addr);
- server(peeraddr_in.sin_addr.s_addr);
- exit(EXIT_FAILURE);
- break;
- default: /* Daemon process comes here. */
- /* The daemon needs to remember */
- /* to close the new accept socket */
- /* after forking the child. This */
- /* prevents the daemon from running */
- /* out of file descriptor space. It */
- /* also means that when the server */
- /* closes the socket, that it will */
- /* allow the socket to be destroyed */
- /* since it will be the last close. */
- close(s);
- break;
- }
- }
- default: /* Parent process comes here. */
- exit(EXIT_FAILURE);
- }
- return EXIT_SUCCESS;
-}
-
-/*----------------------------------------------------------------------
-
- S E R V E R
- * This is the actual server routine that the daemon forks to
- handle each individual connection. Its purpose is to receive
- the request packets from the remote client, process them,
- and return the results to the client. It will also write some
- logging information to stdout.
-
- ----------------------------------------------------------------------*/
-
-server(long int servernum)
-{
- /******** NDB ***********/
- Ndb MyNdb( "TEST_DB" );
- int tTableId;
- NdbConnection *MyTransaction;
- NdbOperation *MyOperation;
- int check;
- int c1 = 0;
- int c2 = 0;
- int c3 = 0;
- int c4 = 0;
- int act_index = 0;
- /************************/
- register unsigned int reqcnt; /* keeps count of number of requests */
- register unsigned int i; /* Loop counters */
- register int x;
- register short done; /* Loop variable */
- short int found;
-
- /* The server index number */
- int thisServer;
-
- /* Variables used to keep track of some statistics */
- time_t ourtime;
- time_t tmptime;
- int tmpvalue;
- long int tmptransfer;
- long int transfer;
- int ops = 0;
-
- /* Variables used by the server */
- char buf[400]; /* This example uses 10 byte messages. */
- char *inet_ntoa();
- char *hostname; /* points to the remote host's name string */
- int len;
- int rcvbuf_size;
-
- long ctid;
-
- unsigned char uc;
-
- /* Variables used by the logging facilitiy */
- char msg[600];
- char crap[600];
- char lognamn[600];
-
- FILE *log;
-
- /* scheduling parameter for pthread */
- struct sched_param param1,param2,param3;
-
- /* Header information */
- /* cdrtype not used */
- /*short cdrtype; */ /* 1 CDR Typ */
- short cdrlen; /* 2 CDR recored length in bytes excluding CDR type */
- short cdrsubtype; /* 1 CDR subtype */
- unsigned int cdrid; /* 8 CDR unique number of each call */
- unsigned int cdrtime; /* 4 CDR Time in seconds */
- short cdrmillisec; /* 2 CDR Milliseconds */
- short cdrstatus; /* 1 CDR For future use */
- short cdrequipeid; /* 1 CDR Equipment id */
- int cdrreserved1; /* 4 CDR For future use */
-
- /* Defined or calculated for each record */
- int cdrrestlen; /* Unprocessed data left in record in bytes */
-
- /* Gemensamma datatyper */
- unsigned short parmtype_prev; /* 1 Parameter type */
- unsigned short parmtype; /* 1 Parameter type */
- unsigned short parmlen; /* 1 Parameter type */
-
- int rc; /* return code for functions */
-
- /* Attribute object used with threads */
- pthread_attr_t attr1;
- pthread_attr_t attr2;
- pthread_attr_t attr3;
- struct cdr_record *tmpcdrptr,*ftest;
- void *dat;
-
- int error_from_client = 0;
-
- /* Konstanter */
- const int headerlen = 24; /* Length of header record */
-
- parmtype_prev = 99;
- reqcnt = 0;
-
- /* Close the listen socket inherited from the daemon. */
- close(ls);
-
- printf("Use the readinfo program to get information about server status\n\n");
-
- if((checkchangelog(fi,temp))==0)
- c2log(fi,"Communication server started");
-
- /* Look up the host information for the remote host */
- /* that we have connected with. Its internet address */
- /* was returned by the accept call, in the main */
- /* daemon loop above. */
-
- hp=gethostbyaddr((char *) &peeraddr_in.sin_addr,sizeof(struct in_addr),peeraddr_in.sin_family);
-
- if (hp == NULL) {
- /* The information is unavailable for the remote */
- /* host. Just format its internet address to be */
- /* printed out in the logging information. The */
- /* address will be shown in "internet dot format". */
-
- /*
- hostname = inet_ntoa(peeraddr_in.sin_addr);
- */
- sprintf(hostname,"Test");
- logname(lognamn,"Cdrserver","Child",hostname);
- }
- else {
- hostname = hp->h_name; /* point to host's name */
- logname(lognamn,"Cdrserver","Child",hostname);
- }
-
- log=fopen(lognamn,"w");
- if (log == NULL)
- {
- perror(hostname);
- exit(EXIT_FAILURE);
- }
- n2log(log,"Setup in progress");
- /* Log a startup message. */
-
- /* The port number must be converted first to host byte */
- /* order before printing. On most hosts, this is not */
- /* necessary, but the ntohs() call is included here so */
- /* that this program could easily be ported to a host */
- /* that does require it. */
-
- BaseString::snprintf(msg,sizeof(msg),"Startup from %s port %u",hostname,ntohs(peeraddr_in.sin_port));
- if ((checkchangelog(fi,temp))==0)
- c2log(fi,msg);
- n2log(log,msg);
- BaseString::snprintf(msg,sizeof(msg),"For further information, see log(%s)",lognamn);
- if ((checkchangelog(fi,temp))==0)
- c2log(fi,msg);
-
- /* Set the socket for a lingering, graceful close. */
- /* This will cause a final close of this socket to wait until */
- /* all * data sent on it has been received by the remote host. */
-
- linger.l_onoff =1;
- linger.l_linger =0;
- if (setsockopt(s, SOL_SOCKET, SO_LINGER,(const char*)&linger,sizeof(linger)) == -1) {
- BaseString::snprintf(msg,sizeof(msg),"Setting SO_LINGER, l_onoff=%d, l_linger=%d",linger.l_onoff,linger.l_linger);
- if ((checkchangelog(log,lognamn))==0)
- n2log(log,msg);
- goto errout;
- }
-
- /* Set the socket for a lingering, graceful close. */
- /* This will cause a final close of this socket to wait until all * data sent */
- /* on it has been received by the remote host. */
-
- rcvbuf_size=64*1024;
-
- if (setsockopt(s, SOL_SOCKET, SO_RCVBUF,(const char*) &rcvbuf_size,sizeof(rcvbuf_size)) == -1) {
- BaseString::snprintf(msg,sizeof(msg),"Setting SO_RCVBUF = %d",rcvbuf_size);
- if ((checkchangelog(log,lognamn))==0)
- n2log(log,msg);
- goto errout;
- }
-
- /* Set nodelay on socket */
- n2log(log,"Port setup complete");
-
- /* Go into a loop, receiving requests from the remote */
- /* client. After the client has sent the last request, */
- /* it will do a shutdown for sending, which will cause */
- /* an end-of-file condition to appear on this end of the */
- /* connection. After all of the client's requests have */
- /* been received, the next recv call will return zero */
- /* bytes, signalling an end-of-file condition. This is */
- /* how the server will know that no more requests will */
- /* follow, and the loop will be exited. */
-
- n2log(log,"Setup completed");
-
- /* Fetch the process id for the server */
-
- /* Inititate the variables used for counting transfer rates and rec/sec */
- tmpvalue = 0;
- tmptime = 0;
- tmptransfer = 0;
- transfer = 0;
-
- printf("Client %s connected\nStarting to process the data\n\n",hostname);
-
- tmpcdrptr = (struct cdr_record*)malloc(sizeof(struct cdr_record));
-
- /***** NDB ******/
- MyNdb.init();
- if (MyNdb.waitUntilReady(30) != 0)
- {
- puts("Not ready");
- exit(-1);
- }
- tTableId = MyNdb.getTable()->openTable(tableName);
- if (tTableId == -1)
- {
- printf("%d: Creating table",getpid());
- create_table(&MyNdb);
- }
- else printf("%d: Table already created",getpid());
-
- /****************/
-
- while (len = recv(s,buf,headerlen,MSG_WAITALL)) {
- if (len == -1) {
- snprintf(msg,sizeof(msg),"Error from recv");
- if ((checkchangelog(log,lognamn))==0)
- n2log(log,msg);
- goto errout; /* error from recv */
- }
-
- /* The reason this while loop exists is that there */
- /* is a remote possibility of the above recv returning */
- /* less than 10 bytes. This is because a recv returns */
- /* as soon as there is some data, and will not wait for */
- /* all of the requested data to arrive. Since 10 bytes */
- /* is relatively small compared to the allowed TCP */
- /* packet sizes, a partial receive is unlikely. If */
- /* this example had used 2048 bytes requests instead, */
- /* a partial receive would be far more likely. */
- /* This loop will keep receiving until all 10 bytes */
- /* have been received, thus guaranteeing that the */
- /* next recv at the top of the loop will start at */
- /* the begining of the next request. */
-
- for (;len < headerlen;) {
- x = recv(s,buf,(headerlen-len),0);
- if (x == -1) {
- snprintf(msg,sizeof(msg),"Error from recv");
- if ((checkchangelog(log,lognamn))==0)
- n2log(log,msg);
- goto errout; /* error from recv */
- }
- len=len+x;
- }
-
- if (ops == 0) {
- MyTransaction = MyNdb.startTransaction();
- if (MyTransaction == NULL)
- error_handler(MyNdb.getNdbErrorString());
- }//if
-
- MyOperation = MyTransaction->getNdbOperation(tableName);
- if (MyOperation == NULL)
- error_handler(MyTransaction->getNdbErrorString());
- /*------------------------------------------------------*/
- /* Parse header of CDR records */
- /*------------------------------------------------------*/
-
- /*------------------------------------------------------*/
- /* 1. Type of cdr */
- /*------------------------------------------------------*/
- /* Not used for the moment
- cdrtype=(char)buf[0];
- */
- /*------------------------------------------------------*/
- /* 2. Total length of CDR */
- /*------------------------------------------------------*/
- swab(buf+1,buf+1,2);
- memcpy(&cdrlen,buf+1,2);
- /*------------------------------------------------------*/
- /* 3. Partial type of CDR */
- /*------------------------------------------------------*/
- cdrsubtype=(char)buf[3];
- switch (cdrsubtype)
- {
- case 0:
- c1++;
- tmpcdrptr->CallAttemptState = 1;
- check = MyOperation->insertTuple();
- break;
- case 1:
- c2++;
- tmpcdrptr->CallAttemptState = 2;
- check = MyOperation->updateTuple();
- break;
- case 2:
- c3++;
- tmpcdrptr->CallAttemptState = 3;
- check = MyOperation->deleteTuple();
- break;
- case 3:
- c4++;
- tmpcdrptr->CallAttemptState = 4;
- check = MyOperation->deleteTuple();
- break;
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- }
- /*cdrsubtype=(cdrsubtype << 24) >> 24;*/
- /*------------------------------------------------------*/
- /* 4. ID number */
- /*------------------------------------------------------*/
- /*swab(buf+4,buf+4,4);*/ /* ABCD -> BADC */
- /*
- swab(buf+4,buf+4,4);
- swab(buf+5,buf+5,2);
- swab(buf+6,buf+6,2);
- swab(buf+4,buf+4,2);
- swab(buf+5,buf+5,2);
- */
- memcpy(&cdrid,buf+4,4);
- tmpcdrptr->CallIdentificationNumber = cdrid;
- #ifdef SETDBG
- puts("CIN");
- #endif
- check = MyOperation->equal("CIN",(char*)&cdrid);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- #ifdef SETDBG
- puts("CAS");
- #endif
-
- if (cdrsubtype < 2)
- {
- check = MyOperation->setValue("CAS",(char*)&cdrsubtype);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- }
- /*------------------------------------------------------*/
- /* 5. Time stamp */
- /*------------------------------------------------------*/
- swab(buf+12,buf+12,4);
- swab(buf+13,buf+13,2);
- swab(buf+14,buf+14,2);
- swab(buf+12,buf+12,2);
- swab(buf+13,buf+13,2);
- memcpy(&cdrtime,buf+12,4);
- switch (cdrsubtype)
- {
- case 0:
- #ifdef SETDBG
- puts("START_TIME");
- #endif
- check = MyOperation->setValue("START_TIME",(char*)&cdrtime);
- break;
- case 1:
- #ifdef SETDBG
- puts("Start1");
- #endif
- check = MyOperation->setValue("StartOfCharge",(char*)&cdrtime);
- break;
- case 2:
- #ifdef SETDBG
- puts("Start2");
- #endif
- /*
- check = MyOperation->setValue("StopOfCharge",(char*)&cdrtime);
- */
- check = 0;
- break;
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- }
- /*------------------------------------------------------*/
- /* 6. Milliseconds */
- /*------------------------------------------------------*/
- /* Not used by application
- swab(buf+16,buf+16,2);
- memcpy(&cdrmillisec,buf+16,2);
- */
- /*------------------------------------------------------*/
- /* 7. CDR status reserverd for future use */
- /*------------------------------------------------------*/
- /* Not used by application
- memcpy(&cdrstatus,buf+18,1);
- */
- /*------------------------------------------------------*/
- /* 8. CDR equipe id, number of sending equipement */
- /*------------------------------------------------------*/
- /* Not used by application
- memcpy(&cdrequipeid,buf+19,1);
- */
- /*cdrequipeid=(cdrequipeid << 24) >> 24;*/
- /*------------------------------------------------------*/
- /* 9. CDR reserverd for furter use */
- /*------------------------------------------------------*/
- /* Not used by applikation
- swab(buf+20,buf+20,4);
- swab(buf+21,buf+21,2);
- swab(buf+22,buf+22,2);
- swab(buf+20,buf+20,2);
- swab(buf+21,buf+21,2);
- memcpy(&cdrreserved1,buf+20,4);
- */
- /*------------------------------------------------------*/
- /* calculate length of datapart in record */
- /* Formula recordlength-headerlen-1 */
- /*------------------------------------------------------*/
- cdrrestlen=cdrlen-(headerlen-1);
- /*------------------------------------------------------*/
- /* Finished with header */
- /*------------------------------------------------------*/
- /* Read remaining cdr data into buffer for furter */
- /* handling. */
- /*------------------------------------------------------*/
- len = recv(s,buf,cdrrestlen,MSG_WAITALL);
- if (len == -1) {
- snprintf(msg,sizeof(msg),"Error from recv");
- if ((checkchangelog(log,lognamn))==0)
- n2log(log,msg);
- goto errout; /* error from recv */
- }
- for (;len<cdrrestlen;) {
- x = recv(s,buf,len-cdrrestlen,0);
- if (x == -1) {
- snprintf(msg,sizeof(msg),"Error from recv");
- if ((checkchangelog(log,lognamn))==0)
- n2log(log,msg);
- goto errout; /* error from recv */
- }
- len=len+x;
- }
- done=FALSE;
-
- /* Count the transfer/sec */
- tmptransfer += cdrlen;
- if (cdrsubtype > 1)
- {
- #ifdef SETDBG
- puts("Going to execute");
- #endif
- ops++;
- if (ops == ops_before_exe) {
- ops = 0;
- check = MyTransaction->execute(Commit, CommitAsMuchAsPossible);
- if ((check == -1) && (MyTransaction->getNdbError() != 0))
- error_handler(MyTransaction->getNdbErrorString());
- MyNdb.closeTransaction(MyTransaction);
- #ifdef SETDBG
- puts("Transaction closed");
- #endif
- }//if
- reqcnt++;
- continue;
- }
- for (x=0;x<=cdrrestlen && !done && cdrrestlen > 1;) {
- uc=buf[x];
- parmtype=uc;
- /*parmtype=(parmtype << 24) >> 24;*/ /* Modified in sun worked in hp */
-
- parmlen = buf[x+1];
- /*parmlen =(parmlen << 24) >> 24;*/
- x+=2;
-
- switch (parmtype) {
- case 4: /* Called party number */
- bcd_decode2(parmlen,&buf[x],crap);
- tmpcdrptr->BSubscriberNumberLength = (char)parmlen;
- strcpy(tmpcdrptr->BSubscriberNumber,crap);
- tmpcdrptr->BSubscriberNumber[parmlen] = '\0';
- x=x+(parmlen/2);
- if (parmlen % 2) x++;
- tmpcdrptr->USED_FIELDS |= B_BSubscriberNumber;
- #ifdef SETDBG
- puts("BNumber");
- #endif
- check = MyOperation->setValue("BNumber",(char*)&tmpcdrptr->BSubscriberNumber);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- break;
- case 9: /* Calling Partys cataegory */
- if (parmlen != 1) printf("ERROR: Calling partys category has wrong length %d\n",parmlen);
- else tmpcdrptr->ACategory=(char)buf[x];
- x+=parmlen;
- tmpcdrptr->USED_FIELDS |= B_ACategory;
- #ifdef SETDBG
- puts("ACategory");
- #endif
- check = MyOperation->setValue("ACategory",(char*)&tmpcdrptr->ACategory);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- break;
- case 10: /* Calling Party Number */
- bcd_decode2(parmlen,&buf[x],crap);
- tmpcdrptr->ASubscriberNumberLength = (char)parmlen;
- strcpy(tmpcdrptr->ASubscriberNumber,crap);
- tmpcdrptr->ASubscriberNumber[parmlen] = '\0';
- x=x+(parmlen/2);
- if (parmlen % 2) x++;
- tmpcdrptr->USED_FIELDS |= B_ASubscriberNumber;
- #ifdef SETDBG
- puts("ANumber");
- #endif
- check = MyOperation->setValue("ANumber",(char*)&tmpcdrptr->ASubscriberNumber);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- break;
- case 11: /* Redirecting number */
- bcd_decode2(parmlen,&buf[x],crap);
- strcpy(tmpcdrptr->RedirectingNumber,crap);
- x=x+(parmlen/2);
- if (parmlen % 2) x++;
- tmpcdrptr->USED_FIELDS |= B_RedirectingNumber;
- #ifdef SETDBG
- puts("RNumber");
- #endif
- check = MyOperation->setValue("RNumber",(char*)&tmpcdrptr->RedirectingNumber);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- break;
- case 17: /* Called partys category */
- if (parmlen != 1) printf("ERROR: Called partys category has wrong length %d\n",parmlen);
- else tmpcdrptr->EndOfSelectionInformation=(char)buf[x];
- x+=parmlen;
- tmpcdrptr->USED_FIELDS |= B_EndOfSelectionInformation;
- #ifdef SETDBG
- puts("EndOfSelInf");
- #endif
- check = MyOperation->setValue("EndOfSelInf",(char*)&tmpcdrptr->EndOfSelectionInformation);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- break;
- case 18: /* Release reason */
- if (parmlen != 1) printf("ERROR: Release reason has wrong length %d\n",parmlen);
- else tmpcdrptr->CauseCode=(char)buf[x];
- x+=parmlen;
- tmpcdrptr->USED_FIELDS |= B_CauseCode;
- #ifdef SETDBG
- puts("CauseCode");
- #endif
- check = MyOperation->setValue("CauseCode",(char*)&tmpcdrptr->CauseCode);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- break;
- case 19: /* Redirection information */
- switch (parmlen) {
- case 1:
- tmpcdrptr->ReroutingIndicator= (char)buf[x];
- tmpcdrptr->USED_FIELDS |= B_ReroutingIndicator;
- break;
- case 2:
- swab(buf+x,buf+x,2);
- tmpcdrptr->ReroutingIndicator= buf[x];
- tmpcdrptr->USED_FIELDS |= B_ReroutingIndicator;
- break;
- default :
- BaseString::snprintf(msg,sizeof(msg),"ERROR: Redirection information has wrong length %d\n",parmlen);
- if ((checkchangelog(log,lognamn))==0)
- n2log(log,msg);
- break;
- #ifdef SETDBG
- puts("RI");
- #endif
- check = MyOperation->setValue("RI",(char*)&tmpcdrptr->ReroutingIndicator);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- }
- x+=parmlen;
- break;
- case 32: /* User to user information */
- if (parmlen != 1) printf("ERROR: User to User information has wrong length %d\n",parmlen);
- else tmpcdrptr->UserToUserInformation=(char)buf[x];
- x+=parmlen;
- tmpcdrptr->USED_FIELDS |= B_UserToUserInformation;
- #ifdef SETDBG
- puts("UserToUserInf");
- #endif
- check = MyOperation->setValue("UserToUserInf",(char*)&tmpcdrptr->UserToUserInformation);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- break;
- case 40: /* Original called number */
- bcd_decode2(parmlen,&buf[x],crap);
- strcpy(tmpcdrptr->OriginalCalledNumber,crap);
- x=x+(parmlen/2);
- if (parmlen % 2) x++;
- tmpcdrptr->USED_FIELDS |= B_OriginalCalledNumber;
- #ifdef SETDBG
- puts("ONumber");
- #endif
- check = MyOperation->setValue("ONumber",(char*)&tmpcdrptr->OriginalCalledNumber);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- break;
- case 42: /* User to user indicator */
- if (parmlen != 1) printf("ERROR: User to User indicator has wrong length %d\n",parmlen);
- else tmpcdrptr->UserToUserIndicatior=(char)buf[x];
- x+=parmlen;
- tmpcdrptr->USED_FIELDS |= B_UserToUserIndicatior;
- #ifdef SETDBG
- puts("UserToUserInd");
- #endif
- check = MyOperation->setValue("UserToUserInd",(char*)&tmpcdrptr->UserToUserIndicatior);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- break;
- case 63: /* Location number */
- bcd_decode2(parmlen,&buf[x],crap);
- strcpy(tmpcdrptr->LocationCode,crap);
- x=x+(parmlen/2);
- if (parmlen % 2) x++;
- tmpcdrptr->USED_FIELDS |= B_LocationCode;
- #ifdef SETDBG
- puts("LocationCode");
- #endif
- check = MyOperation->setValue("LocationCode",(char*)&tmpcdrptr->LocationCode);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- break;
- case 240: /* Calling Partys cataegory */
- if (parmlen != 1) printf("ERROR: Calling partys category has wrong length %d\n",parmlen);
- else tmpcdrptr->NetworkIndicator=(char)buf[x];
- x+=parmlen;
- tmpcdrptr->USED_FIELDS |= B_NetworkIndicator;
- #ifdef SETDBG
- puts("NIndicator");
- #endif
- check = MyOperation->setValue("NIndicator",(char*)&tmpcdrptr->NetworkIndicator);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- break;
- case 241: /* Calling Partys cataegory */
- if (parmlen != 1) printf("ERROR: Calling partys category has wrong length %d\n",parmlen);
- else tmpcdrptr->TonASubscriberNumber=(char)buf[x];
- x+=parmlen;
- tmpcdrptr->USED_FIELDS |= B_TonASubscriberNumber;
- #ifdef SETDBG
- puts("TonANumber");
- #endif
- check = MyOperation->setValue("TonANumber",(char*)&tmpcdrptr->TonASubscriberNumber);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- break;
- case 242: /* Calling Partys cataegory */
- if (parmlen != 1) printf("ERROR: Calling partys category has wrong length %d\n",parmlen);
- else tmpcdrptr->TonBSubscriberNumber=(char)buf[x];
- x+=parmlen;
- tmpcdrptr->USED_FIELDS |= B_TonBSubscriberNumber;
- #ifdef SETDBG
- puts("TonBNumber");
- #endif
- check = MyOperation->setValue("TonBNumber",(char*)&tmpcdrptr->TonBSubscriberNumber);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- break;
- case 243: /* Calling Partys cataegory */
- if (parmlen != 1) printf("ERROR: Calling partys category has wrong length %d\n",parmlen);
- else tmpcdrptr->TonRedirectingNumber=(char)buf[x];
- x+=parmlen;
- tmpcdrptr->USED_FIELDS |= B_TonRedirectingNumber;
- #ifdef SETDBG
- puts("TonRNumber");
- #endif
- check = MyOperation->setValue("TonRNumber",(char*)&tmpcdrptr->TonRedirectingNumber);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- break;
- case 244: /* Calling Partys cataegory */
- if (parmlen != 1) printf("ERROR: Calling partys category has wrong length %d\n",parmlen);
- else tmpcdrptr->TonOriginalCalledNumber=(char)buf[x];
- x+=parmlen;
- tmpcdrptr->USED_FIELDS |= B_TonOriginalCalledNumber;
- #ifdef SETDBG
- puts("TonONumber");
- #endif
- check = MyOperation->setValue("TonONumber",(char*)&tmpcdrptr->TonOriginalCalledNumber);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- break;
- case 245: /* Calling Partys cataegory */
- if (parmlen != 1) printf("ERROR: Calling partys category has wrong length %d\n",parmlen);
- else tmpcdrptr->TonLocationCode=(char)buf[x];
- x+=parmlen;
- tmpcdrptr->USED_FIELDS |= B_TonLocationCode;
- #ifdef SETDBG
- puts("TonLocationCode");
- #endif
- check = MyOperation->setValue("TonLocationCode",(char*)&tmpcdrptr->TonLocationCode);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- break;
- case 252: /* RINParameter Parameter */
- switch (parmlen) {
- case 1:
- tmpcdrptr->RINParameter=buf[x];
- tmpcdrptr->USED_FIELDS |= B_RINParameter;
- break;
- case 2:
- swab(buf+x,buf+x,2);
- tmpcdrptr->RINParameter = buf[x] << 8;
- tmpcdrptr->USED_FIELDS |= B_RINParameter;
- break;
- default :
- BaseString::snprintf(msg,sizeof(msg),"ERROR: Rin parameter has wrong length %d\n",parmlen);
- if ((checkchangelog(log,lognamn))==0)
- n2log(log,msg);
- break;
- }
- x+=parmlen;
- #ifdef SETDBG
- puts("RINParameter");
- #endif
- check = MyOperation->setValue("RINParameter",(char*)&tmpcdrptr->RINParameter);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- break;
- case 253: /* OriginatingPointCode */
- switch (parmlen) {
- case 2:
- swab(buf+x,buf+x,2);
- memcpy(&tmpcdrptr->OriginatingPointCode,(buf+x),2);
- tmpcdrptr->USED_FIELDS |= B_OriginatingPointCode;
- break;
- case 3:
- swab(buf+x,buf+x,2);
- swab(buf+(x+1),buf+(x+1),2);
- swab(buf+x,buf+x,2);
- memcpy(&tmpcdrptr->OriginatingPointCode,(buf+x),3);
- tmpcdrptr->USED_FIELDS |= B_OriginatingPointCode;
- break;
- default :
- BaseString::snprintf(msg,sizeof(msg),"ERROR: OriginatingPointCode parameter has wrong length %d\n",parmlen);
- if ((checkchangelog(log,lognamn))==0)
- n2log(log,msg);
- break;
- }
- x+=parmlen;
- #ifdef SETDBG
- puts("OPC");
- #endif
- check = MyOperation->setValue("OPC",(char*)&tmpcdrptr->OriginatingPointCode);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- break;
- case 254: /* DestinationPointCode */
- switch (parmlen) {
- case 2:
- swab(buf+x,buf+x,2);
- memcpy(&tmpcdrptr->DestinationPointCode,(buf+x),2);
- /*
- tmpcdrptr->DestinationPointCode = buf[x] << 8;
- */
- tmpcdrptr->USED_FIELDS |= B_DestinationPointCode;
- break;
- case 3:
- swab(buf+x,buf+x,2);
- swab(buf+(x+1),buf+(x+1),2);
- swab(buf+x,buf+x,2);
- memcpy(&tmpcdrptr->DestinationPointCode,(buf+x),3);
- tmpcdrptr->USED_FIELDS |= B_DestinationPointCode;
- break;
- default :
- BaseString::snprintf(msg,sizeof(msg),"ERROR: DestinationPointCode parameter has wrong length %d\n",parmlen);
- if ((checkchangelog(log,lognamn))==0)
- n2log(log,msg);
- break;
- }
- x+=parmlen;
- #ifdef SETDBG
- puts("DPC");
- #endif
- check = MyOperation->setValue("DPC",(char*)&tmpcdrptr->DestinationPointCode);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- break;
- case 255: /* CircuitIdentificationCode */
- swab(buf+x,buf+x,2);
- memcpy(&tmpcdrptr->CircuitIdentificationCode,(buf+x),2);
- tmpcdrptr->USED_FIELDS |= B_CircuitIdentificationCode;
- x+=parmlen;
- #ifdef SETDBG
- puts("CIC");
- #endif
- check = MyOperation->setValue("CIC",(char*)&tmpcdrptr->CircuitIdentificationCode);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- break;
- default:
- printf("ERROR: Undefined parmtype %d , previous %d, length %d\n",parmtype,parmtype_prev,parmlen);
- BaseString::snprintf(msg,sizeof(msg),"ERROR: Undefined parmtype %d , previous %d, length %d\n",parmtype,parmtype_prev,parmlen);
- if ((checkchangelog(log,lognamn))==0)
- n2log(log,msg);
- if (parmlen == 0) {
- x++;
- }
- x+=parmlen;
- break;
- }
- parmtype_prev=parmtype;
- if ((cdrrestlen-x) == 1) {
- done=TRUE;
- }
- }
- time(&ourtime);
- if (ourtime != tmptime)
- {
- transfer = tmptransfer;
- tmptransfer = 0;
- if (++act_index == 30)
- {
- act_index = 0;
- printf("Transfer=%d\n",transfer);
- printf("Total operations=%d\n",reqcnt);
- printf("CAS1=%d\n",c1/30);
- printf("CAS2=%d\n",c2/30);
- printf("CAS3=%d\n",c3/30);
- c1=0;
- c2=0;
- c3=0;
- }
- tmptime = ourtime;
- }
- switch (cdrsubtype) {
- case 0:
- tmpcdrptr->ClientId = servernum;
- #ifdef SETDBG
- puts("ClientId");
- #endif
- check = MyOperation->setValue("ClientId",(char*)&tmpcdrptr->ClientId);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- tmpcdrptr->OurSTART_TIME = ourtime;
- #ifdef SETDBG
- puts("OurSTART_TIME");
- #endif
- check = MyOperation->setValue("OurSTART_TIME",(char*)&tmpcdrptr->OurSTART_TIME);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- tmpcdrptr->USED_FIELDS |= B_START_TIME;
- #ifdef SETDBG
- puts("USED_FIELDS");
- #endif
- check = MyOperation->setValue("USED_FIELDS",(char*)&tmpcdrptr->USED_FIELDS);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- break;
-
- case 1:
- tmpcdrptr->OurTimeForStartOfCharge = ourtime;
- #ifdef SETDBG
- puts("OurStartOfCharge");
- #endif
- check = MyOperation->setValue("OurStartOfCharge",(char*)&tmpcdrptr->OurTimeForStartOfCharge);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- tmpcdrptr->USED_FIELDS |= B_TimeForStartOfCharge;
- #ifdef SETDBG
- puts("USED_FIELDS");
- #endif
- check = MyOperation->setValue("USED_FIELDS",(char*)&tmpcdrptr->USED_FIELDS);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- break;
-
- case 2:
- tmpcdrptr->OurTimeForStopOfCharge = ourtime;
- #ifdef SETDBG
- puts("OurStopOfCharge");
- #endif
- check = MyOperation->setValue("OurStopOfCharge",(char*)&tmpcdrptr->OurTimeForStopOfCharge);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- tmpcdrptr->USED_FIELDS |= B_TimeForStopOfCharge;
- #ifdef SETDBG
- puts("USED_FIELDS");
- #endif
- check = MyOperation->setValue("USED_FIELDS",(char*)&tmpcdrptr->USED_FIELDS);
- if (check == -1)
- error_handler(MyTransaction->getNdbErrorString());
- break;
-
- case 3:
- tmpcdrptr->CallAttemptState = 4;
- break;
- default:
- snprintf(msg,sizeof(msg),"cdrtype %d unknown",cdrsubtype);
- if ((checkchangelog(log,lognamn))==0)
- n2log(log,msg);
- goto errout;
- break;
- }
- ops++;
- if (ops == ops_before_exe) {
- ops = 0;
- #ifdef SETDBG
- puts("Going to execute");
- #endif
- check = MyTransaction->execute(Commit, CommitAsMuchAsPossible);
- if ((check == -1) && (MyTransaction->getNdbError() != 0))
- error_handler(MyTransaction->getNdbErrorString());
- MyNdb.closeTransaction(MyTransaction);
- #ifdef SETDBG
- puts("Transaction closed");
- #endif
-
- #ifdef SETDBG
- puts("New transaction initiated");
- #endif
- }//if
- /* Increment the request count. */
- reqcnt++;
-
- /* Send a response back to the client. */
-
- /* if (send(s, buf, 10, 0) != 10) goto errout; */
- }
-
- /* The loop has terminated, because there are no */
- /* more requests to be serviced. As mentioned above, */
- /* this close will block until all of the sent replies */
- /* have been received by the remote host. The reason */
- /* for lingering on the close is so that the server will */
- /* have a better idea of when the remote has picked up */
- /* all of the data. This will allow the start and finish */
- /* times printed in the log file to reflect more accurately */
- /* the length of time this connection was */
- /* The port number must be converted first to host byte */
- /* order before printing. On most hosts, this is not */
- /* necessary, but the ntohs() call is included here so */
- /* that this program could easily be ported to a host */
- /* that does require it. */
-
- BaseString::snprintf(msg,sizeof(msg),"Completed %s port %u, %d requests",hostname,ntohs(peeraddr_in.sin_port), reqcnt);
- if ((checkchangelog(fi,temp))==0)
- c2log(fi,msg);
- error_from_client = 1;
- BaseString::snprintf(msg,sizeof(msg),"Communicate with threads");
- if ((checkchangelog(log,lognamn))==0)
- n2log(log,msg);
- BaseString::snprintf(msg,sizeof(msg),"Waiting for threads to return from work");
- if ((checkchangelog(log,lognamn))==0)
- n2log(log,msg);
- BaseString::snprintf(msg,sizeof(msg),"Closing down");
- if ((checkchangelog(log,lognamn))==0)
- n2log(log,msg);
- close(s);
- fclose(log);
- return EXIT_SUCCESS;
-
-errout:
- BaseString::snprintf(msg,sizeof(msg),"Connection with %s aborted on error\n", hostname);
- if ((checkchangelog(log,lognamn))==0)
- n2log(log,msg);
- if ((checkchangelog(fi,temp))==0)
- c2log(fi,msg);
- error_from_client = 1;
- BaseString::snprintf(msg,sizeof(msg),"Communicate with threads");
- if ((checkchangelog(log,lognamn))==0)
- n2log(log,msg);
- BaseString::snprintf(msg,sizeof(msg),"Waiting for threads to return from work");
- if ((checkchangelog(log,lognamn))==0)
- n2log(log,msg);
- BaseString::snprintf(msg,sizeof(msg),"Closing down");
- if ((checkchangelog(log,lognamn))==0)
- n2log(log,msg);
- close(s);
- fclose(log);
- return EXIT_FAILURE;
-}
-
-void
-create_table(Ndb* pMyNdb)
-{
-
- /****************************************************************
- * Create table and attributes.
- *
- * create table basictab1(
- * col1 int,
- * col2 int not null,
- * col3 int not null,
- * col4 int not null
- * )
- *
- ***************************************************************/
-
- int check;
- int i;
- NdbSchemaCon *MySchemaTransaction;
- NdbSchemaOp *MySchemaOp;
- int tAttributeSize;
-
- tAttributeSize = 1;
-
- cout << "Creating " << tableName << "..." << endl;
-
- MySchemaTransaction = pMyNdb->startSchemaTransaction();
- if( MySchemaTransaction == NULL )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
- if( MySchemaOp == NULL )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // Createtable
- check = MySchemaOp->createTable( tableName,
- 8, // Table Size
- TupleKey, // Key Type
- 40 // Nr of Pages
- );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // CallIdentificationNumber Create first column, primary key
- check = MySchemaOp->createAttribute( "CIN",
- TupleKey,
- 32,
- tAttributeSize,
- UnSigned, MMBased,
- NotNullAttribute
- );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
-
- // USED_FIELDS Create attributes
- check = MySchemaOp->createAttribute( "USED_FIELDS", NoKey, 32,
- tAttributeSize, UnSigned, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // ClientId Create attributes
- check = MySchemaOp->createAttribute( "ClientId", NoKey, 32,
- tAttributeSize, UnSigned, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // START_TIME Create attributes
- check = MySchemaOp->createAttribute( "START_TIME", NoKey, 32,
- tAttributeSize, UnSigned, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // OurSTART_TIME Create attributes
- check = MySchemaOp->createAttribute( "OurSTART_TIME", NoKey, 32,
- tAttributeSize, UnSigned, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // TimeForStartOfCharge Create attributes
- check = MySchemaOp->createAttribute( "StartOfCharge", NoKey, 32,
- tAttributeSize, UnSigned, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // TimeForStopOfCharge Create attributes
- check = MySchemaOp->createAttribute( "StopOfCharge", NoKey, 32,
- tAttributeSize, UnSigned, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // OurTimeForStartOfCharge Create attributes
- check = MySchemaOp->createAttribute( "OurStartOfCharge", NoKey, 32,
- tAttributeSize, UnSigned, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // OurTimeForStopOfCharge Create attributes
- check = MySchemaOp->createAttribute( "OurStopOfCharge", NoKey, 32,
- tAttributeSize, UnSigned, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // DestinationPointCode Create attributes
- check = MySchemaOp->createAttribute( "DPC", NoKey, 16,
- tAttributeSize, UnSigned, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // OriginatingPointCode Create attributes
- check = MySchemaOp->createAttribute( "OPC", NoKey, 16,
- tAttributeSize, UnSigned, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // CircuitIdentificationCode Create attributes
- check = MySchemaOp->createAttribute( "CIC", NoKey, 16,
- tAttributeSize, UnSigned, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // ReroutingIndicator Create attributes
- check = MySchemaOp->createAttribute( "RI", NoKey, 16,
- tAttributeSize, UnSigned, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // RINParameter Create attributes
- check = MySchemaOp->createAttribute( "RINParameter", NoKey, 16,
- tAttributeSize, UnSigned, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // NetworkIndicator Create attributes
- check = MySchemaOp->createAttribute( "NIndicator", NoKey, 8,
- tAttributeSize, Signed, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // CallAttemptState Create attributes
- check = MySchemaOp->createAttribute( "CAS", NoKey, 8,
- tAttributeSize, Signed, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // ACategory Create attributes
- check = MySchemaOp->createAttribute( "ACategory", NoKey, 8,
- tAttributeSize, Signed, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // EndOfSelectionInformation Create attributes
- check = MySchemaOp->createAttribute( "EndOfSelInf", NoKey, 8,
- tAttributeSize, Signed, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // UserToUserInformation Create attributes
- check = MySchemaOp->createAttribute( "UserToUserInf", NoKey, 8,
- tAttributeSize, Signed, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // UserToUserIndicator Create attributes
- check = MySchemaOp->createAttribute( "UserToUserInd", NoKey, 8,
- tAttributeSize, Signed, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // CauseCode Create attributes
- check = MySchemaOp->createAttribute( "CauseCode", NoKey, 8,
- tAttributeSize, Signed, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // ASubscriberNumber attributes
- check = MySchemaOp->createAttribute( "ANumber", NoKey, 8,
- ASubscriberNumber_SIZE, Signed, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // ASubscriberNumberLenght attributes
- check = MySchemaOp->createAttribute( "ANumberLength", NoKey, 8,
- tAttributeSize, Signed, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // TonASubscriberNumber attributes
- check = MySchemaOp->createAttribute( "TonANumber", NoKey, 8,
- tAttributeSize, Signed, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // BSubscriberNumber attributes
- check = MySchemaOp->createAttribute( "BNumber", NoKey, 8,
- BSubscriberNumber_SIZE, Signed, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // BSubscriberNumberLength attributes
- check = MySchemaOp->createAttribute( "BNumberLength", NoKey, 8,
- tAttributeSize, Signed, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // TonBSubscriberNumber attributes
- check = MySchemaOp->createAttribute( "TonBNumber", NoKey, 8,
- tAttributeSize, Signed, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // RedirectingNumber attributes
- check = MySchemaOp->createAttribute( "RNumber", NoKey, 8,
- ASubscriberNumber_SIZE, Signed, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // TonRedirectingNumber attributes
- check = MySchemaOp->createAttribute( "TonRNumber", NoKey, 8,
- tAttributeSize, Signed, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // OriginalCalledNumber attributes
- check = MySchemaOp->createAttribute( "ONumber", NoKey, 8,
- ASubscriberNumber_SIZE, Signed, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // TonOriginalCalledNumber attributes
- check = MySchemaOp->createAttribute( "TonONumber", NoKey, 8,
- tAttributeSize, Signed, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // LocationCode attributes
- check = MySchemaOp->createAttribute( "LocationCode", NoKey, 8,
- ASubscriberNumber_SIZE, Signed, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // TonLocationCode attributes
- check = MySchemaOp->createAttribute( "TonLocationCode", NoKey, 8,
- tAttributeSize, Signed, MMBased,
- NullAttribute );
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- if( MySchemaTransaction->execute() == -1 ) {
- cout << tableName << " already exist" << endl;
- cout << "Message: " << MySchemaTransaction->getNdbErrorString() << endl;
- }
- else
- {
- cout << tableName << " created" << endl;
- }
- pMyNdb->closeSchemaTransaction(MySchemaTransaction);
-
- return;
-}
-
-void
-error_handler(const char* errorText)
-{
- // Test failed
- cout << endl << "ErrorMessage: " << errorText << endl;
- bTestPassed = -1;
-}
diff --git a/storage/ndb/test/ndbapi/celloDb.cpp b/storage/ndb/test/ndbapi/celloDb.cpp
deleted file mode 100644
index b4c4ec69e24..00000000000
--- a/storage/ndb/test/ndbapi/celloDb.cpp
+++ /dev/null
@@ -1,1504 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-/* ***************************************************
- BASIC TEST 1
- Test basic functions and status of NDB
-
- Arguments:
- none
-
- Returns:
- 0 - Test passed
- -1 - Test failed
- 1 - Invalid arguments
-flexBench
- * *************************************************** */
-
-#include <NdbApi.hpp>
-#include <NdbMain.h>
-
-#define MAXATTR 4
-#define MAXTABLES 4
-#define PAGESIZE 8192
-#define OVERHEAD 0.02
-#define NUMBEROFRECORDS 10
-#define PKSIZE 1
-#define ATTRNAMELEN 16
-
-
-static void createTable_IPACCT(Ndb*);
-static void createTable_RPACCT(Ndb*);
-static void createTable_SBMCALL(Ndb*);
-static void createTable_TODACCT(Ndb*);
-
-static void error_handler(const char*);
-static bool error_handler2(const char*, int) ;
-
-static void setAttrNames(void);
-static void setTableNames(void);
-static void create_table(Ndb*);
-static void insert_rows(Ndb*);
-static void update_rows(Ndb*);
-static void delete_rows(Ndb*);
-static void verify_deleted(Ndb*);
-static void read_and_verify_rows(Ndb*);
-
-static void insert_IPACCT(Ndb*, Uint32, Uint32, Uint32, Uint32, Uint32); //3 for Pk, and two data. just to test;
-
-static void read_IPACCT(Ndb* , Uint32 , Uint32 , Uint32 );
-
-static int tAttributeSize;
-static int bTestPassed;
-
-static char tableName[MAXTABLES][ATTRNAMELEN];static char attrName[MAXATTR][ATTRNAMELEN];
-static int attrValue[NUMBEROFRECORDS];
-static int pkValue[NUMBEROFRECORDS];
-static int failed = 0 ;
-#include <NdbOut.hpp>
-
-NDB_COMMAND(celloDb, "celloDb", "celloDb", "celloDb", 65535)
-{
- ndb_init();
-
- int tTableId;
- int i;
- Ndb MyNdb( "CELLO-SESSION-DB" );
-
- MyNdb.init();
-
- // Assume test passed
- bTestPassed = 0;
- /*
- // Initialize global variables
- for (i = 0; i < NUMBEROFRECORDS; i ++)
- pkValue[i] = i;
-
- for (i = 0; i < NUMBEROFRECORDS; i ++)
- attrValue[i] = i;
- */
- tAttributeSize = 1;
-
- // Wait for Ndb to become ready
- if (MyNdb.waitUntilReady() == 0) {
- ndbout << endl << "Cello session db - Starting " << endl;
- ndbout << "Test basic functions and status of NDB" << endl;
-
-
-
- createTable_SBMCALL (&MyNdb );
- createTable_RPACCT (&MyNdb );
- createTable_TODACCT (&MyNdb );
- createTable_IPACCT (&MyNdb );
-
- insert_IPACCT(&MyNdb, 1,2,1,2,2);
- read_IPACCT(&MyNdb, 1, 2 , 1);
- /*
- insert_rows(&MyNdb);
-
- read_and_verify_rows(&MyNdb);
-
-
- // Create some new values to use for update
- for (i = 0; i < NUMBEROFRECORDS; i++)
- attrValue[i] = NUMBEROFRECORDS-i;
-
- update_rows(&MyNdb);
-
- read_and_verify_rows(&MyNdb);
-
- delete_rows(&MyNdb);
-
- verify_deleted(&MyNdb);
- */
- }
- else {
- bTestPassed = -1;
- }
-
-
- if (bTestPassed == 0)
- {
- // Test passed
- ndbout << "OK - Test passed" << endl;
- }
- else
- {
- // Test failed
- ndbout << "FAIL - Test failed" << endl;
- exit(-1);
- }
- return NULL;
-}
-
-static void
-error_handler(const char* errorText)
-{
- // Test failed
- ndbout << endl << "ErrorMessage: " << errorText << endl;
- bTestPassed = -1;
-}
-
-static void
-createTable_SBMCALL ( Ndb* pMyNdb )
-{
- /****************************************************************
- * Create table and attributes.
- *
- * create table SBMCALL(
- * for attribs, see the REQ SPEC for cello session DB
- * )
- *
- ***************************************************************/
-
- const char* tname = "SBMCALL";
- Uint32 recordsize = 244; //including 12 byte overhead
- Uint32 pksize = 8; //size of total prim. key. in bytes. sum of entire composite PK.
- Uint32 tTableId = pMyNdb->getTable()->openTable(tname);
-
- if (tTableId == -1) {
- Uint32 check;
- Uint32 i;
- NdbSchemaCon *MySchemaTransaction;
- NdbSchemaOp *MySchemaOp;
-
- ndbout << "Creating " << tname << "..." << endl;
-
- MySchemaTransaction = pMyNdb->startSchemaTransaction();
- if( ( MySchemaTransaction == NULL ) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
- MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
- if( ( MySchemaOp == NULL ) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
- // Createtable
-
- Uint32 tablesize=(recordsize*NUMBEROFRECORDS + OVERHEAD * NUMBEROFRECORDS)/1024;
- Uint32 noPages=(pksize*NUMBEROFRECORDS)/PAGESIZE;
-
- ndbout << "table size " << tablesize << "for table name " << tname << endl;
-
- check = MySchemaOp->createTable( tname,
- tablesize, // Table Size
- TupleKey, // Key Type
- noPages, // Nr of Pages
- All,
- 6,
- 78,
- 80,
- 1,
- true
- );
-
- if( check == -1 ) {
- error_handler(MySchemaTransaction->getNdbErrorString());
- exit(-1);
- }
-
-
-
- // Create first column, primary key
- check = MySchemaOp->createAttribute( "SPBBOARDID",
- TupleKey,
- 32,
- PKSIZE,
- UnSigned,
- MMBased,
- NotNullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
- // Create second column, primary key
- check = MySchemaOp->createAttribute( "CALLID",
- TupleKey,
- 32,
- PKSIZE,
- UnSigned,
- MMBased,
- NotNullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
- // Creat thrid column, RP Session info, byte[16] represented as (String, 16)
- check = MySchemaOp->createAttribute( "RPSESS",
- NoKey,
- 32,
- 16,
- String,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-// Creat fourth column, GRE Tunnel info, byte[16] represented as (String, 16)
- check = MySchemaOp->createAttribute( "GRETUNNEL",
- NoKey,
- 32,
- 16,
- String,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-// Creat fifth column, PPP Session info, byte[24] represented as (String, 24)
- check = MySchemaOp->createAttribute( "PPPSESS",
- NoKey,
- 32,
- 24,
- String,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
- if( (MySchemaTransaction->execute() == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
- pMyNdb->closeSchemaTransaction(MySchemaTransaction);
- ndbout << "done" << endl;
-
-
- } //if
-
- //else table already created , proceed
-}
-
-
-
-static void
-createTable_RPACCT(Ndb*pMyNdb)
-{
-
- /****************************************************************
- * Create table and attributes.
- *
- * create table RPACCT(
- * for attribs, see the REQ SPEC for cello session DB
- * )
- *
- ***************************************************************/
-
- const char* tname = "RPACCT";
- Uint32 recordsize = 380; //including 12 byte overhead
- Uint32 pksize = 8; //size of total prim. key. in bytes.
- Uint32 tTableId = pMyNdb->getTable()->openTable(tname);
-
- if (tTableId == -1) {
- Uint32 check;
- Uint32 i;
- NdbSchemaCon *MySchemaTransaction;
- NdbSchemaOp *MySchemaOp;
-
- ndbout << "Creating " << tname << "..." << endl;
-
- MySchemaTransaction = pMyNdb->startSchemaTransaction();
- if( MySchemaTransaction == NULL )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
- if( MySchemaOp == NULL )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // Createtable
-
- Uint32 tablesize=(recordsize*NUMBEROFRECORDS + OVERHEAD * NUMBEROFRECORDS)/1024;
- Uint32 noPages=(pksize*NUMBEROFRECORDS)/PAGESIZE;
-
- ndbout << "table size " << tablesize << "for table name " << tname << endl;
-
- check = MySchemaOp->createTable( tname,
- tablesize, // Table Size
- TupleKey, // Key Type
- noPages // Nr of Pages
- );
-
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
-
-
- // Create first column, primary key
- check = MySchemaOp->createAttribute( "SPBBOARDID",
- TupleKey,
- 32,
- PKSIZE,
- UnSigned,
- MMBased,
- NotNullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
- // Create second column, primary key
- check = MySchemaOp->createAttribute( "CALLID",
- TupleKey,
- 32,
- PKSIZE,
- UnSigned,
- MMBased,
- NotNullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
- // Creat thrid column MS ID, 4 byte unsigned
- check = MySchemaOp->createAttribute( "MSID",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
- // Create PDSN FA Address, 4 byte unsigned
- check = MySchemaOp->createAttribute( "PDSN",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
- // Create Serving PCF, 4 byte unsigned
- check = MySchemaOp->createAttribute( "SPCF",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
-
- // Create BS ID, 12 byte char, represented as String,12
- check = MySchemaOp->createAttribute( "BSID",
- NoKey,
- 32,
- 12,
- String,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
-
-
-
- // Create User Zone, 4 byte unsigned
- check = MySchemaOp->createAttribute( "UZ",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
- // Create Forward Multiplex, 4 byte unsigned
- check = MySchemaOp->createAttribute( "FMO",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
- // Create Reverse Multiplex, 4 byte unsigned
- check = MySchemaOp->createAttribute( "RMO",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
- // Create Forward Fund rate, 4 byte unsigned
- check = MySchemaOp->createAttribute( "FFR",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
- // Create Reverse Fund rate, 4 byte unsigned
- check = MySchemaOp->createAttribute( "RFR",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
-
- // Create Service Option, 4 byte unsigned
- check = MySchemaOp->createAttribute( "SO",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
-
-
- // Create Forward Traffic Type, 4 byte unsigned
- check = MySchemaOp->createAttribute( "FTT",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
-
-// Create Reverse Traffic Type, 4 byte unsigned
- check = MySchemaOp->createAttribute( "RTT",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
-
-// Create Fund Frame Size, 4 byte unsigned
- check = MySchemaOp->createAttribute( "FFS",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
-
-// Create Forware Fund RC, 4 byte unsigned
- check = MySchemaOp->createAttribute( "FFRC",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
-
- // Create Reverse Fund RC, 4 byte unsigned
- check = MySchemaOp->createAttribute( "RFRC",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
- // Create DCCH Frame Format, 4 byte unsigned
- check = MySchemaOp->createAttribute( "DCCH",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
- // Create Airlink QOS, 4 byte unsigned
- check = MySchemaOp->createAttribute( "AQOS",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
-
-// Create Bad PPP Frame Count , 4 byte unsigned
- check = MySchemaOp->createAttribute( "BPPPFC",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
-
-
-// Create Active Time , 4 byte unsigned
- check = MySchemaOp->createAttribute( "AT",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
-
-// Create Nb Active Transitions , 4 byte unsigned
- check = MySchemaOp->createAttribute( "NBAT",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
-// Create SDB Octet Count In , 4 byte unsigned
- check = MySchemaOp->createAttribute( "SDBOCI",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
-
-
-// Create Nb SDB In, 4 byte unsigned
- check = MySchemaOp->createAttribute( "NBSDBI",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
-
-
-// Create Nb SDB Out, 4 byte unsigned
- check = MySchemaOp->createAttribute( "NBSDBO",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
-
-
-// Create HDLC Bytes received, 4 byte unsigned
- check = MySchemaOp->createAttribute( "HDLC",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
-
- if( (MySchemaTransaction->execute() == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
- pMyNdb->closeSchemaTransaction(MySchemaTransaction);
- ndbout << "done" << endl;
-
- } //if
-
- //else table already created , proceed
- }
-
-
-static void
-createTable_IPACCT(Ndb* pMyNdb)
-{
-
-
- /****************************************************************
- * Create table and attributes.
- *
- * create table IPACCT(
- * for attribs, see the REQ SPEC for cello session DB
- * )
- *
- ***************************************************************/
-
- const char* tname = "IPACCT";
- Uint32 recordsize = 70; //including 12 byte overhead
- Uint32 pksize = 12; //size of total prim. key. in bytes.
- Uint32 tTableId = pMyNdb->getTable()->openTable(tname);
-
- if (tTableId == -1) {
- Uint32 check;
- Uint32 i;
- NdbSchemaCon *MySchemaTransaction;
- NdbSchemaOp *MySchemaOp;
-
- ndbout << "Creating " << tname << "..." << endl;
-
- MySchemaTransaction = pMyNdb->startSchemaTransaction();
- if( MySchemaTransaction == NULL )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
- if( MySchemaOp == NULL )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // Createtable
-
- Uint32 tablesize=(recordsize*NUMBEROFRECORDS + OVERHEAD * NUMBEROFRECORDS)/1024;
- Uint32 noPages=(pksize*NUMBEROFRECORDS)/PAGESIZE;
-
- ndbout << "table size " << tablesize << "for table name " << tname << endl;
-
- check = MySchemaOp->createTable( tname,
- tablesize, // Table Size
- TupleKey, // Key Type
- noPages // Nr of Pages
- );
-
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
-
-
- // Create first column, primary key
- check = MySchemaOp->createAttribute( "SPBBOARDID",
- TupleKey,
- 32,
- PKSIZE,
- UnSigned,
- MMBased,
- NotNullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
- // Create second column, primary key
- check = MySchemaOp->createAttribute( "CALLID",
- TupleKey,
- 32,
- PKSIZE,
- UnSigned,
- MMBased,
- NotNullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
- // Create third column, primary key
- check = MySchemaOp->createAttribute( "IPADDR",
- TupleKey,
- 32,
- PKSIZE,
- String,
- MMBased,
- NotNullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
-
-
-// Create Acct session id 4 byte unsigned
- check = MySchemaOp->createAttribute( "ASID",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
-// Create Correlation ID, 4 byte unsigned
- check = MySchemaOp->createAttribute( "CID",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
-// Create MIP HA Address, 4 byte unsigned
- check = MySchemaOp->createAttribute( "MIPHA",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
-
-
-
-// Create IP technology, 4 byte unsigned
- check = MySchemaOp->createAttribute( "IPT",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
-
-// Create Compuls Tunnel ID, 4 byte unsigned
- check = MySchemaOp->createAttribute( "CTID",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-// Create IP QOS, 4 byte unsigned
- check = MySchemaOp->createAttribute( "IPQOS",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
- // Create Data octet count in, 4 byte unsigned
- check = MySchemaOp->createAttribute( "DOCI",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
- // Create Data octet count out, 4 byte unsigned
- check = MySchemaOp->createAttribute( "DOCO",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
- // Create Event time, 4 byte unsigned
- check = MySchemaOp->createAttribute( "ET",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
- // Create In mip sig count, 4 byte unsigned
- check = MySchemaOp->createAttribute( "IMSC",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-// Create Out mip sig count, 4 byte unsigned
- check = MySchemaOp->createAttribute( "OMSC",
- NoKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
- if( (MySchemaTransaction->execute() == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
- pMyNdb->closeSchemaTransaction(MySchemaTransaction);
- ndbout << "done" << endl;
-
-
-
- } //if
-
- //else table already created , proceed
-}
-
-
-static void
-createTable_TODACCT(Ndb* pMyNdb)
-{
-
-
- /****************************************************************
- * Create table and attributes.
- *
- * create table TODACCT(
- * for attribs, see the REQ SPEC for cello session DB
- * )
- *
- ***************************************************************/
-
- const char* tname = "TODACCT";
- Uint32 recordsize = 92; //including 12 byte overhead
- Uint32 pksize = 12; //size of total prim. key. in bytes.
- Uint32 tTableId = pMyNdb->getTable()->openTable(tname);
-
- if (tTableId == -1) {
- Uint32 check;
- Uint32 i;
- NdbSchemaCon *MySchemaTransaction;
- NdbSchemaOp *MySchemaOp;
-
- ndbout << "Creating " << tname << "..." << endl;
-
- MySchemaTransaction = pMyNdb->startSchemaTransaction();
- if( MySchemaTransaction == NULL )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
- if( MySchemaOp == NULL )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
- // Createtable
-
- Uint32 tablesize=(recordsize*NUMBEROFRECORDS + OVERHEAD * NUMBEROFRECORDS)/1024;
- Uint32 noPages=(pksize*NUMBEROFRECORDS)/PAGESIZE;
-
- ndbout << "table size " << tablesize << "for table name " << tname << endl;
-
- check = MySchemaOp->createTable( tname,
- tablesize, // Table Size
- TupleKey, // Key Type
- noPages // Nr of Pages
- );
-
- if( check == -1 )
- error_handler(MySchemaTransaction->getNdbErrorString());
-
-
-
- // Create first column, primary key
- check = MySchemaOp->createAttribute( "SPBBOARDID",
- TupleKey,
- 32,
- PKSIZE,
- UnSigned,
- MMBased,
- NotNullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
- // Create second column, primary key
- check = MySchemaOp->createAttribute( "CALLID",
- TupleKey,
- 32,
- PKSIZE,
- UnSigned,
- MMBased,
- NotNullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
- // Create third column, primary key
- check = MySchemaOp->createAttribute( "IPADDR",
- TupleKey,
- 32,
- PKSIZE,
- String,
- MMBased,
- NotNullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
-
- // Create third column, primary key
- check = MySchemaOp->createAttribute( "INDEX",
- TupleKey,
- 32,
- PKSIZE,
- UnSigned,
- MMBased,
- NotNullAttribute );
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
-
-
-// Create Acct session id 4 byte unsigned
- check = MySchemaOp->createAttribute( "TOD",
- NoKey,
- 32,
- 16,
- String,
- MMBased,
- NullAttribute );
-
-
- if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
-
-
- if( (MySchemaTransaction->execute() == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
- exit (-1) ;
-
- pMyNdb->closeSchemaTransaction(MySchemaTransaction);
- ndbout << "done" << endl;
-
- } //if
-
- //else table already created , proceed
-}
-
-
-
-
-
-
-static void read_IPACCT(Ndb* pMyNdb, Uint32 CALLID, Uint32 SPBBOARDID , Uint32 IPADDR)
-{
-
-
- int check;
- int loop_count_ops;
- int count;
- int count_attributes;
- char* value;
- NdbConnection *MyTransaction;
- NdbOperation *MyOperation;
- NdbRecAttr* tTmp;
-
-
-
- MyTransaction = pMyNdb->startTransaction();
- if (MyTransaction == NULL)
- error_handler(pMyNdb->getNdbErrorString());
-
- MyOperation = MyTransaction->getNdbOperation("IPACCT");
- if (MyOperation == NULL)
- error_handler( MyTransaction->getNdbErrorString());
-
- check = MyOperation->readTuple();
- if( check == -1 )
- error_handler( MyTransaction->getNdbErrorString());
-
- check = MyOperation->equal( "SPBBOARDID",SPBBOARDID );
- if( check == -1 )
- error_handler( MyTransaction->getNdbErrorString());
-
-
- check = MyOperation->equal( "IPADDR","IPADDR" );
- if( check == -1 )
- error_handler( MyTransaction->getNdbErrorString());
-
-
- check = MyOperation->equal( "CALLID",CALLID );
- if( check == -1 )
- error_handler( MyTransaction->getNdbErrorString());
-
-
-
-
- tTmp = MyOperation->getValue("IPQOS", NULL );
- if( tTmp == NULL )
- error_handler( MyTransaction->getNdbErrorString());
- ndbout << " tTmp " << tTmp->isNULL() << endl;
- MyTransaction->execute(Commit);
-
- ndbout << " value read " << tTmp->int32_value() << endl;
-
-}
-
-
-
-static void insert_IPACCT(Ndb* pMyNdb, Uint32 CALLID, Uint32 SPBBOARDID , Uint32 IPADDR, Uint32 ASID, Uint32 IPQOS)
-{
- /****************************************************************
- * Insert rows
- *
- ***************************************************************/
-
- int check;
- int loop_count_ops;
- int count;
- int i;
- NdbConnection *MyTransaction;
- NdbOperation *MyOperation;
-
- ndbout << "Inserting records..." << flush;
-
- MyTransaction = pMyNdb->startTransaction();
- if (MyTransaction == NULL)
- error_handler(pMyNdb->getNdbErrorString());
-
- MyOperation = MyTransaction->getNdbOperation("IPACCT");
- if (MyOperation == NULL)
- error_handler(MyTransaction->getNdbErrorString());
-
-
-
- check = MyOperation->insertTuple();
- if( check == -1 )
- error_handler(MyTransaction->getNdbErrorString());
-
- ndbout << "insertTuple" << endl;
-
- check = MyOperation->equal("CALLID",CALLID );
- if( check == -1 )
- error_handler(MyTransaction->getNdbErrorString());
- ndbout << "equal" << endl;
-
-
- check = MyOperation->equal("SPBBOARDID",SPBBOARDID );
- if( check == -1 )
- error_handler(MyTransaction->getNdbErrorString());
- ndbout << "equal" << endl;
-
-
- check = MyOperation->equal("IPADDR","IPADDR" );
- if( check == -1 )
- error_handler(MyTransaction->getNdbErrorString());
- ndbout << "equal" << endl;
-
-
- check = MyOperation->setValue( "IPQOS", IPQOS);
- if( check == -1 )
- error_handler(MyTransaction->getNdbErrorString());
- ndbout << "Set Value" << endl;
-
-
-
- check = MyOperation->setValue( "ASID", ASID);
- if( check == -1 )
- error_handler(MyTransaction->getNdbErrorString());
- ndbout << "Set Value" << endl;
-
-
- check = MyTransaction->execute( Commit );
- if(check == -1 ) {
- ndbout << "error at commit" << endl;
- error_handler(MyTransaction->getNdbErrorString());
- }
- else
- ;//ndbout << ".";
-
- pMyNdb->closeTransaction(MyTransaction);
-
-
-
- ndbout << "OK" << endl;
-
- return;
-}
-
-static void
-update_rows(Ndb* pMyNdb){
- /****************************************************************
- * Update rows in SimpleTable
- *
- ***************************************************************/
-
- int check;
- int loop_count_ops;
- int count;
- int i;
- NdbConnection *MyTransaction;
- NdbOperation *MyOperation;
-
- ndbout << "Updating records..." << flush;
-
- loop_count_ops = NUMBEROFRECORDS;
-
- for (count=0 ; count < loop_count_ops ; count++) {
-
- MyTransaction = pMyNdb->startTransaction();
- if (MyTransaction == NULL)
- error_handler( pMyNdb->getNdbErrorString() );
-
- MyOperation = MyTransaction->getNdbOperation(tableName[0]);
- if (MyOperation == NULL)
- error_handler(MyTransaction->getNdbErrorString());
-
- check = MyOperation->updateTuple();
- if( check == -1 )
- error_handler(MyTransaction->getNdbErrorString());
-
- check = MyOperation->equal( attrName[0], (char*)&pkValue[count] );
- if( check == -1 )
- error_handler(MyTransaction->getNdbErrorString());
-
- for (i = 1; i < MAXATTR; i++)
- {
- check = MyOperation->setValue( attrName[i], (char*)&attrValue[count]);
- if( check == -1 )
- error_handler(MyTransaction->getNdbErrorString());
- }
-
- if( MyTransaction->execute( Commit ) == -1 )
- error_handler(MyTransaction->getNdbErrorString());
- else
- ;//ndbout << ".";
-
- pMyNdb->closeTransaction(MyTransaction);
-
- }
-
- ndbout << "OK" << endl;
- return;
-
-};
-
-static void
-delete_rows(Ndb* pMyNdb){
-
- /****************************************************************
- * Delete rows from SimpleTable
- *
- ***************************************************************/
-
- int check;
- int loop_count_ops;
- int count;
- NdbConnection *MyTransaction;
- NdbOperation *MyOperation;
-
- ndbout << "Deleting records..."<< flush;
-
- loop_count_ops = NUMBEROFRECORDS;
-
- for (count=0 ; count < loop_count_ops ; count++) {
-
- MyTransaction = pMyNdb->startTransaction();
- if (MyTransaction == NULL)
- error_handler( pMyNdb->getNdbErrorString() );
-
- MyOperation = MyTransaction->getNdbOperation(tableName[0]);
- if (MyOperation == NULL)
- error_handler(MyTransaction->getNdbErrorString());
-
-
- check = MyOperation->deleteTuple();
- if( check == -1 )
- error_handler(MyTransaction->getNdbErrorString());
-
- check = MyOperation->equal( attrName[0], (char*)&pkValue[count] );
- if( check == -1 )
- error_handler(MyTransaction->getNdbErrorString());
-
-
- if( MyTransaction->execute( Commit ) == -1 )
- error_handler(MyTransaction->getNdbErrorString());
- else
- ;// ndbout << ".";
-
- pMyNdb->closeTransaction(MyTransaction);
-
- }
-
- ndbout << "OK" << endl;
- return;
-
-};
-
-static void
-verify_deleted(Ndb* pMyNdb){
- int check;
- int loop_count_ops;
- int count;
- NdbConnection *MyTransaction;
- NdbOperation *MyOperation;
-
- ndbout << "Verifying deleted records..."<< flush;
-
- loop_count_ops = NUMBEROFRECORDS;
-
- for (count=0 ; count < loop_count_ops ; count++)
- {
- MyTransaction = pMyNdb->startTransaction();
- if (MyTransaction == NULL)
- error_handler(pMyNdb->getNdbErrorString());
-
- MyOperation = MyTransaction->getNdbOperation(tableName[0]);
- if (MyOperation == NULL)
- error_handler( MyTransaction->getNdbErrorString());
-
- check = MyOperation->readTuple();
- if( check == -1 )
- error_handler( MyTransaction->getNdbErrorString());
-
- check = MyOperation->equal( attrName[0],(char*)&pkValue[count] );
- if( check == -1 )
- error_handler( MyTransaction->getNdbErrorString());
-
- // Exepect to receive an error
- if( MyTransaction->execute( Commit ) != -1 )
- error_handler(MyTransaction->getNdbErrorString());
- else
- {
- ;//ndbout << ".";
- }
-
- pMyNdb->closeTransaction(MyTransaction);
-
- }
-
- ndbout << "OK" << endl;
- return;
-};
-
-static void
-read_and_verify_rows(Ndb* pMyNdb)
-{
-
- int check;
- int loop_count_ops;
- int count;
- int count_attributes;
-
- NdbConnection *MyTransaction;
- NdbOperation *MyOperation;
- NdbRecAttr* tTmp;
-
- int readValue[MAXATTR];
-
- ndbout << "Verifying records..."<< flush;
-
- loop_count_ops = NUMBEROFRECORDS;
-
- for (count=0 ; count < loop_count_ops ; count++)
- {
- MyTransaction = pMyNdb->startTransaction();
- if (MyTransaction == NULL)
- error_handler(pMyNdb->getNdbErrorString());
-
- MyOperation = MyTransaction->getNdbOperation(tableName[0]);
- if (MyOperation == NULL)
- error_handler( MyTransaction->getNdbErrorString());
-
- check = MyOperation->readTuple();
- if( check == -1 )
- error_handler( MyTransaction->getNdbErrorString());
-
- check = MyOperation->equal( attrName[0],(char*)&pkValue[count] );
- if( check == -1 )
- error_handler( MyTransaction->getNdbErrorString());
-
- for (count_attributes = 1; count_attributes < MAXATTR; count_attributes++)
- {
- tTmp = MyOperation->getValue( (char*)attrName[count_attributes], (char*)&readValue[count_attributes] );
- if( tTmp == NULL )
- error_handler( MyTransaction->getNdbErrorString());
- }
-
- if( MyTransaction->execute( Commit ) == -1 )
- error_handler(MyTransaction->getNdbErrorString());
- else
- {
- // Check value in db against value in mem
-
- //ndbout << readValue[1] << " == " << attrValue[count] << endl;
-
- if ( readValue[1]!=attrValue[count] )
- error_handler("Verification error!");
- else
- if ( readValue[2]!=attrValue[count] )
- error_handler("Verification error!");
- else
- if ( readValue[3]!=attrValue[count] )
- error_handler("Verification error!");
- else
- {
- ;//ndbout << ".";
- }
- }
- pMyNdb->closeTransaction(MyTransaction);
-
- }
-
- ndbout << "OK" << endl;
- return;
-
-
-
-};
-
-
-static void
-setAttrNames()
-{
- int i;
-
- for (i = 0; i < MAXATTR ; i++)
- {
- sprintf(&attrName[i][0], "Col%d", i);
- }
-}
-
-static void
-setTableNames()
-{
- int i;
-
- sprintf(&tableName[0][0], "SBMCALL", 0);
- sprintf(&tableName[1][0], "RPACCT", 0);
- sprintf(&tableName[2][0], "IPACCT", 0);
- sprintf(&tableName[3][0], "TODACCT", 0);
-
-}
-
-
-bool error_handler2(const char* error_string, int error_int) {
- failed++ ;
- ndbout << error_string << endl ;
- if ( 4008==error_int || 721==error_int || 266==error_int ){
- ndbout << endl << "Attempting to recover and continue now..." << endl ;
- return true ; // return true to retry
- }
- return false ; // return false to abort
-}
diff --git a/storage/ndb/test/ndbapi/create_all_tabs.cpp b/storage/ndb/test/ndbapi/create_all_tabs.cpp
deleted file mode 100644
index d4d1ba3e874..00000000000
--- a/storage/ndb/test/ndbapi/create_all_tabs.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-
-#include <NdbOut.hpp>
-#include <NdbApi.hpp>
-#include <NDBT.hpp>
-
-#include <getarg.h>
-
-
-
-int main(int argc, const char** argv){
- ndb_init();
-
- int _temp = false;
- int _help = 0;
-
- struct getargs args[] = {
- { "temp", 't', arg_flag, &_temp, "Temporary table", "temp" },
- { "usage", '?', arg_flag, &_help, "Print help", "" }
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "This program will create all standard tables in Ndb.\n"\
- "The tables is selected from a fixed list of tables\n"\
- "defined in NDBT_Tables class\n";
-
- if(getarg(args, num_args, argc, argv, &optind) || _help) {
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- // Connect to Ndb
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- Ndb MyNdb(&con, "TEST_DB" );
-
- if(MyNdb.init() != 0){
- ERR(MyNdb.getNdbError());
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- while(MyNdb.waitUntilReady() != 0)
- ndbout << "Waiting for ndb to become ready..." << endl;
-
- return NDBT_Tables::createAllTables(&MyNdb, _temp);
-
- }
-
-
diff --git a/storage/ndb/test/ndbapi/create_tab.cpp b/storage/ndb/test/ndbapi/create_tab.cpp
deleted file mode 100644
index 6e897c48dbc..00000000000
--- a/storage/ndb/test/ndbapi/create_tab.cpp
+++ /dev/null
@@ -1,138 +0,0 @@
-/* Copyright (c) 2003-2005, 2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-
-#include <NdbOut.hpp>
-#include <NdbApi.hpp>
-#include <NDBT.hpp>
-
-#include <getarg.h>
-
-static int g_diskbased = 0;
-static const char* g_tsname = 0;
-
-static int
-g_create_hook(Ndb* ndb, NdbDictionary::Table& tab, int when, void* arg)
-{
- if (when == 0) {
- if (g_diskbased) {
- for (int i = 0; i < tab.getNoOfColumns(); i++) {
- NdbDictionary::Column* col = tab.getColumn(i);
- if (! col->getPrimaryKey()) {
- col->setStorageType(NdbDictionary::Column::StorageTypeDisk);
- }
- }
- }
- if (g_tsname != NULL) {
- tab.setTablespaceName(g_tsname);
- }
- }
- return 0;
-}
-
-int main(int argc, const char** argv){
- ndb_init();
-
- int _temp = false;
- int _help = 0;
- int _all = 0;
- int _print = 0;
- const char* _connectstr = NULL;
- int _diskbased = 0;
- const char* _tsname = NULL;
-
- struct getargs args[] = {
- { "all", 'a', arg_flag, &_all, "Create/print all tables", 0 },
- { "print", 'p', arg_flag, &_print, "Print table(s) instead of creating it", 0},
- { "temp", 't', arg_flag, &_temp, "Temporary table", 0 },
- { "connstr", 'c', arg_string, &_connectstr, "Connect string", "cs" },
- { "diskbased", 0, arg_flag, &_diskbased, "Store attrs on disk if possible", 0 },
- { "tsname", 0, arg_string, &_tsname, "Tablespace name", "ts" },
- { "usage", '?', arg_flag, &_help, "Print help", "" }
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "tabname\n"\
- "This program will create one table in Ndb.\n"\
- "The tables may be selected from a fixed list of tables\n"\
- "defined in NDBT_Tables class\n";
-
- if(getarg(args, num_args, argc, argv, &optind) || _help){
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- if(argv[optind] == NULL && !_all){
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- g_diskbased = _diskbased;
- g_tsname = _tsname;
-
- int res = 0;
- if(_print){
- /**
- * Print instead of creating
- */
- if(optind < argc){
- for(int i = optind; i<argc; i++){
- NDBT_Tables::print(argv[i]);
- }
- } else {
- NDBT_Tables::printAll();
- }
- } else {
- /**
- * Creating
- */
-
- // Connect to Ndb
- Ndb_cluster_connection con(_connectstr);
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- Ndb MyNdb(&con, "TEST_DB" );
-
- if(MyNdb.init() != 0){
- ERR(MyNdb.getNdbError());
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- while(MyNdb.waitUntilReady() != 0)
- ndbout << "Waiting for ndb to become ready..." << endl;
-
- if(_all){
- res = NDBT_Tables::createAllTables(&MyNdb, _temp);
- } else {
- int tmp;
- for(int i = optind; i<argc; i++){
- ndbout << "Trying to create " << argv[i] << endl;
- if((tmp = NDBT_Tables::createTable(&MyNdb, argv[i], _temp, false,
- g_create_hook)) != 0)
- res = tmp;
- }
- }
- }
-
- if(res != 0)
- return NDBT_ProgramExit(NDBT_FAILED);
- else
- return NDBT_ProgramExit(NDBT_OK);
-}
diff --git a/storage/ndb/test/ndbapi/drop_all_tabs.cpp b/storage/ndb/test/ndbapi/drop_all_tabs.cpp
deleted file mode 100644
index 5c6316cceaa..00000000000
--- a/storage/ndb/test/ndbapi/drop_all_tabs.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-
-#include <NdbOut.hpp>
-#include <NdbApi.hpp>
-#include <NDBT.hpp>
-
-#include <getarg.h>
-
-int main(int argc, const char** argv){
- ndb_init();
-
- int _help = 0;
- struct getargs args[] = {
- { "usage", '?', arg_flag, &_help, "Print help", "" }
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "This program will drop all Ndb standard tables from NDB\n";
-
- if(getarg(args, num_args, argc, argv, &optind) || _help) {
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- // Connect to Ndb
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- Ndb MyNdb(&con, "TEST_DB" );
-
- if(MyNdb.init() != 0){
- ERR(MyNdb.getNdbError());
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- while(MyNdb.waitUntilReady() != 0)
- ndbout << "Waiting for ndb to become ready..." << endl;
-
- return NDBT_Tables::dropAllTables(&MyNdb);
-
- }
-
-
diff --git a/storage/ndb/test/ndbapi/flexAsynch.cpp b/storage/ndb/test/ndbapi/flexAsynch.cpp
deleted file mode 100644
index d24965a9134..00000000000
--- a/storage/ndb/test/ndbapi/flexAsynch.cpp
+++ /dev/null
@@ -1,1002 +0,0 @@
-/* Copyright (c) 2003-2005, 2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-
-#include <ndb_global.h>
-#include "NdbApi.hpp"
-#include <NdbSchemaCon.hpp>
-#include <NdbMain.h>
-#include <md5_hash.hpp>
-
-#include <NdbThread.h>
-#include <NdbSleep.h>
-#include <NdbTick.h>
-#include <NdbOut.hpp>
-#include <NdbTimer.hpp>
-#include <NDBT_Error.hpp>
-
-#include <NdbTest.hpp>
-
-#define MAX_PARTS 4
-#define MAX_SEEK 16
-#define MAXSTRLEN 16
-#define MAXATTR 64
-#define MAXTABLES 64
-#define NDB_MAXTHREADS 128
-/*
- NDB_MAXTHREADS used to be just MAXTHREADS, which collides with a
- #define from <sys/thread.h> on AIX (IBM compiler). We explicitly
- #undef it here lest someone use it by habit and get really funny
- results. K&R says we may #undef non-existent symbols, so let's go.
-*/
-#undef MAXTHREADS
-#define MAXPAR 1024
-#define MAXATTRSIZE 1000
-#define PKSIZE 2
-
-enum StartType {
- stIdle,
- stInsert,
- stRead,
- stUpdate,
- stDelete,
- stStop
-} ;
-
-extern "C" { static void* threadLoop(void*); }
-static void setAttrNames(void);
-static void setTableNames(void);
-static int readArguments(int argc, const char** argv);
-static int createTables(Ndb*);
-static void defineOperation(NdbConnection* aTransObject, StartType aType,
- Uint32 base, Uint32 aIndex);
-static void execute(StartType aType);
-static bool executeThread(StartType aType, Ndb* aNdbObject, unsigned int);
-static void executeCallback(int result, NdbConnection* NdbObject,
- void* aObject);
-static bool error_handler(const NdbError & err);
-static Uint32 getKey(Uint32, Uint32) ;
-static void input_error();
-
-
-static int retry_opt = 3 ;
-static int failed = 0 ;
-
-ErrorData * flexAsynchErrorData;
-
-struct ThreadNdb
-{
- int NoOfOps;
- int ThreadNo;
-};
-
-static NdbThread* threadLife[NDB_MAXTHREADS];
-static int tNodeId;
-static int ThreadReady[NDB_MAXTHREADS];
-static StartType ThreadStart[NDB_MAXTHREADS];
-static char tableName[MAXTABLES][MAXSTRLEN+1];
-static char attrName[MAXATTR][MAXSTRLEN+1];
-
-// Program Parameters
-static bool tLocal = false;
-static int tLocalPart = 0;
-static int tSendForce = 0;
-static int tNoOfLoops = 1;
-static int tAttributeSize = 1;
-static unsigned int tNoOfThreads = 1;
-static unsigned int tNoOfParallelTrans = 32;
-static unsigned int tNoOfAttributes = 25;
-static unsigned int tNoOfTransactions = 500;
-static unsigned int tNoOfOpsPerTrans = 1;
-static unsigned int tLoadFactor = 80;
-static bool tempTable = false;
-static bool startTransGuess = true;
-
-//Program Flags
-static int theTestFlag = 0;
-static int theSimpleFlag = 0;
-static int theDirtyFlag = 0;
-static int theWriteFlag = 0;
-static int theStdTableNameFlag = 0;
-static int theTableCreateFlag = 0;
-
-#define START_REAL_TIME
-#define STOP_REAL_TIME
-#define START_TIMER { NdbTimer timer; timer.doStart();
-#define STOP_TIMER timer.doStop();
-#define PRINT_TIMER(text, trans, opertrans) timer.printTransactionStatistics(text, trans, opertrans); };
-
-static void
-resetThreads(){
-
- for (int i = 0; i < tNoOfThreads ; i++) {
- ThreadReady[i] = 0;
- ThreadStart[i] = stIdle;
- }//for
-}
-
-static void
-waitForThreads(void)
-{
- int cont = 0;
- do {
- cont = 0;
- NdbSleep_MilliSleep(20);
- for (int i = 0; i < tNoOfThreads ; i++) {
- if (ThreadReady[i] == 0) {
- cont = 1;
- }//if
- }//for
- } while (cont == 1);
-}
-
-static void
-tellThreads(StartType what)
-{
- for (int i = 0; i < tNoOfThreads ; i++)
- ThreadStart[i] = what;
-}
-
-static Ndb_cluster_connection *g_cluster_connection= 0;
-
-NDB_COMMAND(flexAsynch, "flexAsynch", "flexAsynch", "flexAsynch", 65535)
-{
- ndb_init();
- ThreadNdb* pThreadData;
- int tLoops=0, i;
- int returnValue = NDBT_OK;
-
- flexAsynchErrorData = new ErrorData;
- flexAsynchErrorData->resetErrorCounters();
-
- if (readArguments(argc, argv) != 0){
- input_error();
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- pThreadData = new ThreadNdb[NDB_MAXTHREADS];
-
- ndbout << endl << "FLEXASYNCH - Starting normal mode" << endl;
- ndbout << "Perform benchmark of insert, update and delete transactions";
- ndbout << endl;
- ndbout << " " << tNoOfThreads << " number of concurrent threads " << endl;
- ndbout << " " << tNoOfParallelTrans;
- ndbout << " number of parallel operation per thread " << endl;
- ndbout << " " << tNoOfTransactions << " transaction(s) per round " << endl;
- ndbout << " " << tNoOfLoops << " iterations " << endl;
- ndbout << " " << "Load Factor is " << tLoadFactor << "%" << endl;
- ndbout << " " << tNoOfAttributes << " attributes per table " << endl;
- ndbout << " " << tAttributeSize;
- ndbout << " is the number of 32 bit words per attribute " << endl;
- if (tempTable == true) {
- ndbout << " Tables are without logging " << endl;
- } else {
- ndbout << " Tables are with logging " << endl;
- }//if
- if (startTransGuess == true) {
- ndbout << " Transactions are executed with hint provided" << endl;
- } else {
- ndbout << " Transactions are executed with round robin scheme" << endl;
- }//if
- if (tSendForce == 0) {
- ndbout << " No force send is used, adaptive algorithm used" << endl;
- } else if (tSendForce == 1) {
- ndbout << " Force send used" << endl;
- } else {
- ndbout << " No force send is used, adaptive algorithm disabled" << endl;
- }//if
-
- ndbout << endl;
-
- NdbThread_SetConcurrencyLevel(2 + tNoOfThreads);
-
- /* print Setting */
- flexAsynchErrorData->printSettings(ndbout);
-
- setAttrNames();
- setTableNames();
-
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- g_cluster_connection= &con;
-
- Ndb * pNdb = new Ndb(g_cluster_connection, "TEST_DB");
- pNdb->init();
- tNodeId = pNdb->getNodeId();
-
- ndbout << " NdbAPI node with id = " << pNdb->getNodeId() << endl;
- ndbout << endl;
-
- ndbout << "Waiting for ndb to become ready..." <<endl;
- if (pNdb->waitUntilReady(10000) != 0){
- ndbout << "NDB is not ready" << endl;
- ndbout << "Benchmark failed!" << endl;
- returnValue = NDBT_FAILED;
- }
-
- if(returnValue == NDBT_OK){
- if (createTables(pNdb) != 0){
- returnValue = NDBT_FAILED;
- }
- }
-
- if(returnValue == NDBT_OK){
- /****************************************************************
- * Create NDB objects. *
- ****************************************************************/
- resetThreads();
- for (i = 0; i < tNoOfThreads ; i++) {
- pThreadData[i].ThreadNo = i
-;
- threadLife[i] = NdbThread_Create(threadLoop,
- (void**)&pThreadData[i],
- 32768,
- "flexAsynchThread",
- NDB_THREAD_PRIO_LOW);
- }//for
- ndbout << endl << "All NDB objects and table created" << endl << endl;
- int noOfTransacts = tNoOfParallelTrans*tNoOfTransactions*tNoOfThreads;
- /****************************************************************
- * Execute program. *
- ****************************************************************/
-
- for(;;) {
-
- int loopCount = tLoops + 1 ;
- ndbout << endl << "Loop # " << loopCount << endl << endl ;
-
- /****************************************************************
- * Perform inserts. *
- ****************************************************************/
-
- failed = 0 ;
-
- START_TIMER;
- execute(stInsert);
- STOP_TIMER;
- PRINT_TIMER("insert", noOfTransacts, tNoOfOpsPerTrans);
-
- if (0 < failed) {
- i = retry_opt ;
- int ci = 1 ;
- while (0 < failed && 0 < i){
- ndbout << failed << " of the transactions returned errors!"
- << endl << endl;
- ndbout << "Attempting to redo the failed transactions now..."
- << endl ;
- ndbout << "Redo attempt " << ci <<" out of " << retry_opt
- << endl << endl;
- failed = 0 ;
- START_TIMER;
- execute(stInsert);
- STOP_TIMER;
- PRINT_TIMER("insert", noOfTransacts, tNoOfOpsPerTrans);
- i-- ;
- ci++;
- }
- if(0 == failed ){
- ndbout << endl <<"Redo attempt succeeded" << endl << endl;
- }else{
- ndbout << endl <<"Redo attempt failed, moving on now..." << endl
- << endl;
- }//if
- }//if
-
- /****************************************************************
- * Perform read. *
- ****************************************************************/
-
- failed = 0 ;
-
- START_TIMER;
- execute(stRead);
- STOP_TIMER;
- PRINT_TIMER("read", noOfTransacts, tNoOfOpsPerTrans);
-
- if (0 < failed) {
- i = retry_opt ;
- int cr = 1;
- while (0 < failed && 0 < i){
- ndbout << failed << " of the transactions returned errors!"<<endl ;
- ndbout << endl;
- ndbout <<"Attempting to redo the failed transactions now..." << endl;
- ndbout << endl;
- ndbout <<"Redo attempt " << cr <<" out of ";
- ndbout << retry_opt << endl << endl;
- failed = 0 ;
- START_TIMER;
- execute(stRead);
- STOP_TIMER;
- PRINT_TIMER("read", noOfTransacts, tNoOfOpsPerTrans);
- i-- ;
- cr++ ;
- }//while
- if(0 == failed ) {
- ndbout << endl <<"Redo attempt succeeded" << endl << endl ;
- }else{
- ndbout << endl <<"Redo attempt failed, moving on now..." << endl << endl ;
- }//if
- }//if
-
-
- /****************************************************************
- * Perform update. *
- ****************************************************************/
-
- failed = 0 ;
-
- START_TIMER;
- execute(stUpdate);
- STOP_TIMER;
- PRINT_TIMER("update", noOfTransacts, tNoOfOpsPerTrans) ;
-
- if (0 < failed) {
- i = retry_opt ;
- int cu = 1 ;
- while (0 < failed && 0 < i){
- ndbout << failed << " of the transactions returned errors!"<<endl ;
- ndbout << endl;
- ndbout <<"Attempting to redo the failed transactions now..." << endl;
- ndbout << endl <<"Redo attempt " << cu <<" out of ";
- ndbout << retry_opt << endl << endl;
- failed = 0 ;
- START_TIMER;
- execute(stUpdate);
- STOP_TIMER;
- PRINT_TIMER("update", noOfTransacts, tNoOfOpsPerTrans);
- i-- ;
- cu++ ;
- }//while
- if(0 == failed ){
- ndbout << endl <<"Redo attempt succeeded" << endl << endl;
- } else {
- ndbout << endl;
- ndbout <<"Redo attempt failed, moving on now..." << endl << endl;
- }//if
- }//if
-
- /****************************************************************
- * Perform read. *
- ****************************************************************/
-
- failed = 0 ;
-
- START_TIMER;
- execute(stRead);
- STOP_TIMER;
- PRINT_TIMER("read", noOfTransacts, tNoOfOpsPerTrans);
-
- if (0 < failed) {
- i = retry_opt ;
- int cr2 = 1 ;
- while (0 < failed && 0 < i){
- ndbout << failed << " of the transactions returned errors!"<<endl ;
- ndbout << endl;
- ndbout <<"Attempting to redo the failed transactions now..." << endl;
- ndbout << endl <<"Redo attempt " << cr2 <<" out of ";
- ndbout << retry_opt << endl << endl;
- failed = 0 ;
- START_TIMER;
- execute(stRead);
- STOP_TIMER;
- PRINT_TIMER("read", noOfTransacts, tNoOfOpsPerTrans);
- i-- ;
- cr2++ ;
- }//while
- if(0 == failed ){
- ndbout << endl <<"Redo attempt succeeded" << endl << endl;
- }else{
- ndbout << endl;
- ndbout << "Redo attempt failed, moving on now..." << endl << endl;
- }//if
- }//if
-
-
- /****************************************************************
- * Perform delete. *
- ****************************************************************/
-
- failed = 0 ;
-
- START_TIMER;
- execute(stDelete);
- STOP_TIMER;
- PRINT_TIMER("delete", noOfTransacts, tNoOfOpsPerTrans);
-
- if (0 < failed) {
- i = retry_opt ;
- int cd = 1 ;
- while (0 < failed && 0 < i){
- ndbout << failed << " of the transactions returned errors!"<< endl ;
- ndbout << endl;
- ndbout <<"Attempting to redo the failed transactions now:" << endl ;
- ndbout << endl <<"Redo attempt " << cd <<" out of ";
- ndbout << retry_opt << endl << endl;
- failed = 0 ;
- START_TIMER;
- execute(stDelete);
- STOP_TIMER;
- PRINT_TIMER("read", noOfTransacts, tNoOfOpsPerTrans);
- i-- ;
- cd++ ;
- }//while
- if(0 == failed ){
- ndbout << endl <<"Redo attempt succeeded" << endl << endl ;
- }else{
- ndbout << endl;
- ndbout << "Redo attempt failed, moving on now..." << endl << endl;
- }//if
- }//if
-
- tLoops++;
- ndbout << "--------------------------------------------------" << endl;
-
- if(tNoOfLoops != 0){
- if(tNoOfLoops <= tLoops)
- break ;
- }
- }//for
-
- execute(stStop);
- void * tmp;
- for(i = 0; i<tNoOfThreads; i++){
- NdbThread_WaitFor(threadLife[i], &tmp);
- NdbThread_Destroy(&threadLife[i]);
- }
- }
- delete [] pThreadData;
- delete pNdb;
-
- //printing errorCounters
- flexAsynchErrorData->printErrorCounters(ndbout);
-
- return NDBT_ProgramExit(returnValue);
-}//main()
-
-
-static void execute(StartType aType)
-{
- resetThreads();
- tellThreads(aType);
- waitForThreads();
-}//execute()
-
-static void*
-threadLoop(void* ThreadData)
-{
- Ndb* localNdb;
- StartType tType;
- ThreadNdb* tabThread = (ThreadNdb*)ThreadData;
- int threadNo = tabThread->ThreadNo;
- localNdb = new Ndb(g_cluster_connection, "TEST_DB");
- localNdb->init(1024);
- localNdb->waitUntilReady(10000);
- unsigned int threadBase = (threadNo << 16) + tNodeId ;
-
- for (;;){
- while (ThreadStart[threadNo] == stIdle) {
- NdbSleep_MilliSleep(10);
- }//while
-
- // Check if signal to exit is received
- if (ThreadStart[threadNo] == stStop) {
- break;
- }//if
-
- tType = ThreadStart[threadNo];
- ThreadStart[threadNo] = stIdle;
- if(!executeThread(tType, localNdb, threadBase)){
- break;
- }
- ThreadReady[threadNo] = 1;
- }//for
-
- delete localNdb;
- ThreadReady[threadNo] = 1;
-
- return NULL;
-}//threadLoop()
-
-static
-bool
-executeThread(StartType aType, Ndb* aNdbObject, unsigned int threadBase) {
- int i, j, k;
- NdbConnection* tConArray[1024];
- unsigned int tBase;
- unsigned int tBase2;
-
- for (i = 0; i < tNoOfTransactions; i++) {
- if (tLocal == false) {
- tBase = i * tNoOfParallelTrans * tNoOfOpsPerTrans;
- } else {
- tBase = i * tNoOfParallelTrans * MAX_SEEK;
- }//if
- START_REAL_TIME;
- for (j = 0; j < tNoOfParallelTrans; j++) {
- if (tLocal == false) {
- tBase2 = tBase + (j * tNoOfOpsPerTrans);
- } else {
- tBase2 = tBase + (j * MAX_SEEK);
- tBase2 = getKey(threadBase, tBase2);
- }//if
- if (startTransGuess == true) {
- Uint64 Tkey64;
- Uint32* Tkey32 = (Uint32*)&Tkey64;
- Tkey32[0] = threadBase;
- Tkey32[1] = tBase2;
- tConArray[j] = aNdbObject->startTransaction((Uint32)0, //Priority
- (const char*)&Tkey64, //Main PKey
- (Uint32)4); //Key Length
- } else {
- tConArray[j] = aNdbObject->startTransaction();
- }//if
- if (tConArray[j] == NULL &&
- !error_handler(aNdbObject->getNdbError()) ){
- ndbout << endl << "Unable to recover! Quiting now" << endl ;
- return false;
- }//if
-
- for (k = 0; k < tNoOfOpsPerTrans; k++) {
- //-------------------------------------------------------
- // Define the operation, but do not execute it yet.
- //-------------------------------------------------------
- defineOperation(tConArray[j], aType, threadBase, (tBase2 + k));
- }//for
-
- tConArray[j]->executeAsynchPrepare(Commit, &executeCallback, NULL);
- }//for
- STOP_REAL_TIME;
- //-------------------------------------------------------
- // Now we have defined a set of operations, it is now time
- // to execute all of them.
- //-------------------------------------------------------
- int Tcomp = aNdbObject->sendPollNdb(3000, 0, 0);
- while (Tcomp < tNoOfParallelTrans) {
- int TlocalComp = aNdbObject->pollNdb(3000, 0);
- Tcomp += TlocalComp;
- }//while
- for (j = 0 ; j < tNoOfParallelTrans ; j++) {
- aNdbObject->closeTransaction(tConArray[j]);
- }//for
- }//for
- return true;
-}//executeThread()
-
-static
-Uint32
-getKey(Uint32 aBase, Uint32 anIndex) {
- Uint32 Tfound = anIndex;
- Uint64 Tkey64;
- Uint32* Tkey32 = (Uint32*)&Tkey64;
- Tkey32[0] = aBase;
- Uint32 hash;
- for (Uint32 i = anIndex; i < (anIndex + MAX_SEEK); i++) {
- Tkey32[1] = (Uint32)i;
- hash = md5_hash((Uint64*)&Tkey64, (Uint32)2);
- hash = (hash >> 6) & (MAX_PARTS - 1);
- if (hash == tLocalPart) {
- Tfound = i;
- break;
- }//if
- }//for
- return Tfound;
-}//getKey()
-
-static void
-executeCallback(int result, NdbConnection* NdbObject, void* aObject)
-{
- if (result == -1) {
-
- // Add complete error handling here
-
- int retCode = flexAsynchErrorData->handleErrorCommon(NdbObject->getNdbError());
- if (retCode == 1) {
- if (NdbObject->getNdbError().code != 626 && NdbObject->getNdbError().code != 630){
- ndbout_c("execute: %s", NdbObject->getNdbError().message);
- ndbout_c("Error code = %d", NdbObject->getNdbError().code);}
- } else if (retCode == 2) {
- ndbout << "4115 should not happen in flexAsynch" << endl;
- } else if (retCode == 3) {
- /* What can we do here? */
- ndbout_c("execute: %s", NdbObject->getNdbError().message);
- }//if(retCode == 3)
-
- // ndbout << "Error occured in poll:" << endl;
- // ndbout << NdbObject->getNdbError() << endl;
- failed++ ;
- return;
- }//if
- return;
-}//executeCallback()
-
-
-
-static void
-defineOperation(NdbConnection* localNdbConnection, StartType aType,
- Uint32 threadBase, Uint32 aIndex)
-{
- NdbOperation* localNdbOperation;
- unsigned int loopCountAttributes = tNoOfAttributes;
- unsigned int countAttributes;
- Uint32 attrValue[MAXATTRSIZE];
-
- //-------------------------------------------------------
- // Set-up the attribute values for this operation.
- //-------------------------------------------------------
- attrValue[0] = threadBase;
- attrValue[1] = aIndex;
- for (int k = 2; k < loopCountAttributes; k++) {
- attrValue[k] = aIndex;
- }//for
- localNdbOperation = localNdbConnection->getNdbOperation(tableName[0]);
- if (localNdbOperation == NULL) {
- error_handler(localNdbConnection->getNdbError());
- }//if
- switch (aType) {
- case stInsert: { // Insert case
- if (theWriteFlag == 1 && theDirtyFlag == 1) {
- localNdbOperation->dirtyWrite();
- } else if (theWriteFlag == 1) {
- localNdbOperation->writeTuple();
- } else {
- localNdbOperation->insertTuple();
- }//if
- break;
- }//case
- case stRead: { // Read Case
- if (theSimpleFlag == 1) {
- localNdbOperation->simpleRead();
- } else if (theDirtyFlag == 1) {
- localNdbOperation->dirtyRead();
- } else {
- localNdbOperation->readTuple();
- }//if
- break;
- }//case
- case stUpdate: { // Update Case
- if (theWriteFlag == 1 && theDirtyFlag == 1) {
- localNdbOperation->dirtyWrite();
- } else if (theWriteFlag == 1) {
- localNdbOperation->writeTuple();
- } else if (theDirtyFlag == 1) {
- localNdbOperation->dirtyUpdate();
- } else {
- localNdbOperation->updateTuple();
- }//if
- break;
- }//case
- case stDelete: { // Delete Case
- localNdbOperation->deleteTuple();
- break;
- }//case
- default: {
- error_handler(localNdbOperation->getNdbError());
- }//default
- }//switch
- localNdbOperation->equal((Uint32)0,(char*)&attrValue[0]);
- switch (aType) {
- case stInsert: // Insert case
- case stUpdate: // Update Case
- {
- for (countAttributes = 1;
- countAttributes < loopCountAttributes; countAttributes++) {
- localNdbOperation->setValue(countAttributes,
- (char*)&attrValue[0]);
- }//for
- break;
- }//case
- case stRead: { // Read Case
- for (countAttributes = 1;
- countAttributes < loopCountAttributes; countAttributes++) {
- localNdbOperation->getValue(countAttributes,
- (char*)&attrValue[0]);
- }//for
- break;
- }//case
- case stDelete: { // Delete Case
- break;
- }//case
- default: {
- //goto error_handler; < epaulsa
- error_handler(localNdbOperation->getNdbError());
- }//default
- }//switch
- return;
-}//defineOperation()
-
-static void setAttrNames()
-{
- int i;
-
- for (i = 0; i < MAXATTR ; i++){
- BaseString::snprintf(attrName[i], MAXSTRLEN, "COL%d", i);
- }
-}
-
-
-static void setTableNames()
-{
- // Note! Uses only uppercase letters in table name's
- // so that we can look at the tables wits SQL
- int i;
- for (i = 0; i < MAXTABLES ; i++){
- if (theStdTableNameFlag==0){
- BaseString::snprintf(tableName[i], MAXSTRLEN, "TAB%d_%d", i,
- (int)(NdbTick_CurrentMillisecond()/1000));
- } else {
- BaseString::snprintf(tableName[i], MAXSTRLEN, "TAB%d", i);
- }
- }
-}
-
-static
-int
-createTables(Ndb* pMyNdb){
-
- NdbSchemaCon *MySchemaTransaction;
- NdbSchemaOp *MySchemaOp;
- int check;
-
- if (theTableCreateFlag == 0) {
- for(int i=0; i < 1 ;i++) {
- ndbout << "Creating " << tableName[i] << "..." << endl;
- MySchemaTransaction = NdbSchemaCon::startSchemaTrans(pMyNdb);
-
- if(MySchemaTransaction == NULL &&
- (!error_handler(MySchemaTransaction->getNdbError())))
- return -1;
-
- MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
- if(MySchemaOp == NULL &&
- (!error_handler(MySchemaTransaction->getNdbError())))
- return -1;
-
-
- check = MySchemaOp->createTable( tableName[i]
- ,8 // Table Size
- ,TupleKey // Key Type
- ,40 // Nr of Pages
- ,All
- ,6
- ,(tLoadFactor - 5)
- ,(tLoadFactor)
- ,1
- ,!tempTable
- );
-
- if (check == -1 &&
- (!error_handler(MySchemaTransaction->getNdbError())))
- return -1;
-
- check = MySchemaOp->createAttribute( (char*)attrName[0],
- TupleKey,
- 32,
- PKSIZE,
- UnSigned,
- MMBased,
- NotNullAttribute );
-
- if (check == -1 &&
- (!error_handler(MySchemaTransaction->getNdbError())))
- return -1;
- for (int j = 1; j < tNoOfAttributes ; j++){
- check = MySchemaOp->createAttribute( (char*)attrName[j],
- NoKey,
- 32,
- tAttributeSize,
- UnSigned,
- MMBased,
- NotNullAttribute );
- if (check == -1 &&
- (!error_handler(MySchemaTransaction->getNdbError())))
- return -1;
- }
-
- if (MySchemaTransaction->execute() == -1 &&
- (!error_handler(MySchemaTransaction->getNdbError())))
- return -1;
-
- NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
- }
- }
-
- return 0;
-}
-
-static
-bool error_handler(const NdbError & err){
- ndbout << err << endl ;
- switch(err.classification){
- case NdbError::TemporaryResourceError:
- case NdbError::OverloadError:
- case NdbError::SchemaError:
- ndbout << endl << "Attempting to recover and continue now..." << endl ;
- return true;
- }
- return false ; // return false to abort
-}
-static
-bool error_handler(const char* error_string, int error_int) {
- ndbout << error_string << endl ;
- if ((4008 == error_int) ||
- (721 == error_int) ||
- (266 == error_int)){
- ndbout << endl << "Attempting to recover and continue now..." << endl ;
- return true ; // return true to retry
- }
- return false ; // return false to abort
-}
-
-static
-int
-readArguments(int argc, const char** argv){
-
- int i = 1;
- while (argc > 1){
- if (strcmp(argv[i], "-t") == 0){
- tNoOfThreads = atoi(argv[i+1]);
- if ((tNoOfThreads < 1) || (tNoOfThreads > NDB_MAXTHREADS)){
- ndbout_c("Invalid no of threads");
- return -1;
- }
- } else if (strcmp(argv[i], "-p") == 0){
- tNoOfParallelTrans = atoi(argv[i+1]);
- if ((tNoOfParallelTrans < 1) || (tNoOfParallelTrans > MAXPAR)){
- ndbout_c("Invalid no of parallell transactions");
- return -1;
- }
- } else if (strcmp(argv[i], "-load_factor") == 0){
- tLoadFactor = atoi(argv[i+1]);
- if ((tLoadFactor < 40) || (tLoadFactor > 99)){
- ndbout_c("Invalid load factor");
- return -1;
- }
- } else if (strcmp(argv[i], "-c") == 0) {
- tNoOfOpsPerTrans = atoi(argv[i+1]);
- if (tNoOfOpsPerTrans < 1){
- ndbout_c("Invalid no of operations per transaction");
- return -1;
- }
- } else if (strcmp(argv[i], "-o") == 0) {
- tNoOfTransactions = atoi(argv[i+1]);
- if (tNoOfTransactions < 1){
- ndbout_c("Invalid no of transactions");
- return -1;
- }
- } else if (strcmp(argv[i], "-a") == 0){
- tNoOfAttributes = atoi(argv[i+1]);
- if ((tNoOfAttributes < 2) || (tNoOfAttributes > MAXATTR)){
- ndbout_c("Invalid no of attributes");
- return -1;
- }
- } else if (strcmp(argv[i], "-n") == 0){
- theStdTableNameFlag = 1;
- argc++;
- i--;
- } else if (strcmp(argv[i], "-l") == 0){
- tNoOfLoops = atoi(argv[i+1]);
- if ((tNoOfLoops < 0) || (tNoOfLoops > 100000)){
- ndbout_c("Invalid no of loops");
- return -1;
- }
- } else if (strcmp(argv[i], "-s") == 0){
- tAttributeSize = atoi(argv[i+1]);
- if ((tAttributeSize < 1) || (tAttributeSize > MAXATTRSIZE)){
- ndbout_c("Invalid attributes size");
- return -1;
- }
- } else if (strcmp(argv[i], "-local") == 0){
- tLocalPart = atoi(argv[i+1]);
- tLocal = true;
- startTransGuess = true;
- if ((tLocalPart < 0) || (tLocalPart > MAX_PARTS)){
- ndbout_c("Invalid local part");
- return -1;
- }
- } else if (strcmp(argv[i], "-simple") == 0){
- theSimpleFlag = 1;
- argc++;
- i--;
- } else if (strcmp(argv[i], "-adaptive") == 0){
- tSendForce = 0;
- argc++;
- i--;
- } else if (strcmp(argv[i], "-force") == 0){
- tSendForce = 1;
- argc++;
- i--;
- } else if (strcmp(argv[i], "-non_adaptive") == 0){
- tSendForce = 2;
- argc++;
- i--;
- } else if (strcmp(argv[i], "-write") == 0){
- theWriteFlag = 1;
- argc++;
- i--;
- } else if (strcmp(argv[i], "-dirty") == 0){
- theDirtyFlag = 1;
- argc++;
- i--;
- } else if (strcmp(argv[i], "-test") == 0){
- theTestFlag = 1;
- argc++;
- i--;
- } else if (strcmp(argv[i], "-no_table_create") == 0){
- theTableCreateFlag = 1;
- argc++;
- i--;
- } else if (strcmp(argv[i], "-temp") == 0){
- tempTable = true;
- argc++;
- i--;
- } else if (strcmp(argv[i], "-no_hint") == 0){
- startTransGuess = false;
- argc++;
- i--;
- } else {
- return -1;
- }
-
- argc -= 2;
- i = i + 2;
- }//while
- if (tLocal == true) {
- if (tNoOfOpsPerTrans != 1) {
- ndbout_c("Not valid to have more than one op per trans with local");
- }//if
- if (startTransGuess == false) {
- ndbout_c("Not valid to use no_hint with local");
- }//if
- }//if
- return 0;
-}
-
-static
-void
-input_error(){
-
- ndbout_c("FLEXASYNCH");
- ndbout_c(" Perform benchmark of insert, update and delete transactions");
- ndbout_c("");
- ndbout_c("Arguments:");
- ndbout_c(" -t Number of threads to start, default 1");
- ndbout_c(" -p Number of parallel transactions per thread, default 32");
- ndbout_c(" -o Number of transactions per loop, default 500");
- ndbout_c(" -l Number of loops to run, default 1, 0=infinite");
- ndbout_c(" -load_factor Number Load factor in index in percent (40 -> 99)");
- ndbout_c(" -a Number of attributes, default 25");
- ndbout_c(" -c Number of operations per transaction");
- ndbout_c(" -s Size of each attribute, default 1 ");
- ndbout_c(" (PK is always of size 1, independent of this value)");
- ndbout_c(" -simple Use simple read to read from database");
- ndbout_c(" -dirty Use dirty read to read from database");
- ndbout_c(" -write Use writeTuple in insert and update");
- ndbout_c(" -n Use standard table names");
- ndbout_c(" -no_table_create Don't create tables in db");
- ndbout_c(" -temp Create table(s) without logging");
- ndbout_c(" -no_hint Don't give hint on where to execute transaction coordinator");
- ndbout_c(" -adaptive Use adaptive send algorithm (default)");
- ndbout_c(" -force Force send when communicating");
- ndbout_c(" -non_adaptive Send at a 10 millisecond interval");
- ndbout_c(" -local Number of part, only use keys in one part out of 16");
-}
-
-
-
diff --git a/storage/ndb/test/ndbapi/flexBench.cpp b/storage/ndb/test/ndbapi/flexBench.cpp
deleted file mode 100644
index c54cb6588f4..00000000000
--- a/storage/ndb/test/ndbapi/flexBench.cpp
+++ /dev/null
@@ -1,1166 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-/* ***************************************************
-FLEXBENCH
-Perform benchmark of insert, update and delete transactions
-
-Arguments:
- -t Number of threads to start, default 1
- -o Number of operations per loop, default 500
- -l Number of loops to run, default 1, 0=infinite
- -a Number of attributes, default 25
- -c Number of tables, default 1
- -s Size of each attribute, default 1 (Primary Key is always of size 1,
- independent of this value)
- -lkn Number of long primary keys, default 1
- -lks Size of each long primary key, default 1
- -simple Use simple read to read from database
- -dirty Use dirty read to read from database
- -write Use writeTuple in insert and update
- -stdtables Use standard table names
- -no_table_create Don't create tables in db
- -sleep Sleep a number of seconds before running the test, this
- can be used so that another flexBench have time to create tables
- -temp Use tables without logging
- -verify Verify inserts, updates and deletes
-#ifdef CEBIT_STAT
- -statserv host:port statistics server to report to
- -statfreq ops report every ops operations (default 100)
-#endif
- Returns:
- 0 - Test passed
- 1 - Test failed
- 2 - Invalid arguments
-
-* *************************************************** */
-
-#include <ndb_global.h>
-#include "NdbApi.hpp"
-
-#include <NdbMain.h>
-#include <NdbOut.hpp>
-#include <NdbSleep.h>
-#include <NdbTick.h>
-#include <NdbTimer.hpp>
-#include <NdbThread.h>
-
-#include <NdbTest.hpp>
-
-#define MAXSTRLEN 16
-#define MAXATTR 64
-#define MAXTABLES 128
-#define MAXATTRSIZE 1000
-#define MAXNOLONGKEY 16 // Max number of long keys.
-#define MAXLONGKEYTOTALSIZE 1023 // words = 4092 bytes
-
-extern "C" { static void* flexBenchThread(void*); }
-static int readArguments(int argc, const char** argv);
-static int createTables(Ndb*);
-static void sleepBeforeStartingTest(int seconds);
-static void input_error();
-
-enum StartType {
- stIdle,
- stInsert,
- stVerify,
- stRead,
- stUpdate,
- stDelete,
- stTryDelete,
- stVerifyDelete,
- stStop
-};
-
-struct ThreadData
-{
- int threadNo;
- NdbThread* threadLife;
- int threadReady;
- StartType threadStart;
- int threadResult;
-};
-
-static int tNodeId = 0 ;
-static char tableName[MAXTABLES][MAXSTRLEN+1];
-static char attrName[MAXATTR][MAXSTRLEN+1];
-static char** longKeyAttrName;
-
-// Program Parameters
-static int tNoOfLoops = 1;
-static int tAttributeSize = 1;
-static unsigned int tNoOfThreads = 1;
-static unsigned int tNoOfTables = 1;
-static unsigned int tNoOfAttributes = 25;
-static unsigned int tNoOfOperations = 500;
-static unsigned int tSleepTime = 0;
-static unsigned int tNoOfLongPK = 1;
-static unsigned int tSizeOfLongPK = 1;
-
-//Program Flags
-static int theSimpleFlag = 0;
-static int theDirtyFlag = 0;
-static int theWriteFlag = 0;
-static int theStdTableNameFlag = 0;
-static int theTableCreateFlag = 0;
-static bool theTempTable = false;
-static bool VerifyFlag = true;
-static bool useLongKeys = false;
-
-
-static ErrorData theErrorData; // Part of flexBench-program
-
-#define START_TIMER { NdbTimer timer; timer.doStart();
-#define STOP_TIMER timer.doStop();
-#define PRINT_TIMER(text, trans, opertrans) timer.printTransactionStatistics(text, trans, opertrans); };
-
-#include <NdbTCP.h>
-
-#ifdef CEBIT_STAT
-#include <NdbMutex.h>
-static bool statEnable = false;
-static char statHost[100];
-static int statFreq = 100;
-static int statPort = 0;
-static int statSock = -1;
-static enum { statError = -1, statClosed, statOpen } statState;
-static NdbMutex statMutex = NDB_MUTEX_INITIALIZER;
-#endif
-
-//-------------------------------------------------------------------
-// Statistical Reporting routines
-//-------------------------------------------------------------------
-#ifdef CEBIT_STAT
-// Experimental client-side statistic for CeBIT
-
-static void
-statReport(enum StartType st, int ops)
-{
- if (!statEnable)
- return;
- if (NdbMutex_Lock(&statMutex) < 0) {
- if (statState != statError) {
- ndbout_c("stat: lock mutex failed: %s", strerror(errno));
- statState = statError;
- }
- return;
- }
- static int nodeid;
- // open connection
- if (statState != statOpen) {
- char *p = getenv("NDB_NODEID"); // ndbnet sets NDB_NODEID
- nodeid = p == 0 ? 0 : atoi(p);
- if ((statSock = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
- if (statState != statError) {
- ndbout_c("stat: create socket failed: %s", strerror(errno));
- statState = statError;
- }
- (void)NdbMutex_Unlock(&statMutex);
- return;
- }
- struct sockaddr_in saddr;
- memset(&saddr, 0, sizeof(saddr));
- saddr.sin_family = AF_INET;
- saddr.sin_port = htons(statPort);
- if (Ndb_getInAddr(&saddr.sin_addr, statHost) < 0) {
- if (statState != statError) {
- ndbout_c("stat: host %s not found", statHost);
- statState = statError;
- }
- (void)close(statSock);
- (void)NdbMutex_Unlock(&statMutex);
- return;
- }
- if (connect(statSock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
- if (statState != statError) {
- ndbout_c("stat: connect failed: %s", strerror(errno));
- statState = statError;
- }
- (void)close(statSock);
- (void)NdbMutex_Unlock(&statMutex);
- return;
- }
- statState = statOpen;
- ndbout_c("stat: connection to %s:%d opened", statHost, (int)statPort);
- }
- const char *text;
- switch (st) {
- case stInsert:
- text = "insert";
- break;
- case stVerify:
- text = "verify";
- break;
- case stRead:
- text = "read";
- break;
- case stUpdate:
- text = "update";
- break;
- case stDelete:
- text = "delete";
- break;
- case stVerifyDelete:
- text = "verifydelete";
- break;
- default:
- text = "unknown";
- break;
- }
- char buf[100];
- sprintf(buf, "%d %s %d\n", nodeid, text, ops);
- int len = strlen(buf);
- // assume SIGPIPE already ignored
- if (write(statSock, buf, len) != len) {
- if (statState != statError) {
- ndbout_c("stat: write failed: %s", strerror(errno));
- statState = statError;
- }
- (void)close(statSock);
- (void)NdbMutex_Unlock(&statMutex);
- return;
- }
- (void)NdbMutex_Unlock(&statMutex);
-}
-#endif // CEBIT_STAT
-
-static void
-resetThreads(ThreadData* pt){
- for (unsigned int i = 0; i < tNoOfThreads; i++){
- pt[i].threadReady = 0;
- pt[i].threadResult = 0;
- pt[i].threadStart = stIdle;
- }
-}
-
-static int
-checkThreadResults(ThreadData* pt){
- for (unsigned int i = 0; i < tNoOfThreads; i++){
- if(pt[i].threadResult != 0){
- ndbout_c("Thread%d reported fatal error %d", i, pt[i].threadResult);
- return -1;
- }
- }
- return 0;
-}
-
-static
-void
-waitForThreads(ThreadData* pt)
-{
- int cont = 1;
- while (cont){
- NdbSleep_MilliSleep(100);
- cont = 0;
- for (unsigned int i = 0; i < tNoOfThreads; i++){
- if (pt[i].threadReady == 0)
- cont = 1;
- }
- }
-}
-
-static void
-tellThreads(ThreadData* pt, StartType what)
-{
- for (unsigned int i = 0; i < tNoOfThreads; i++)
- pt[i].threadStart = what;
-}
-
-static Ndb_cluster_connection *g_cluster_connection= 0;
-
-NDB_COMMAND(flexBench, "flexBench", "flexBench", "flexbench", 65535)
-{
- ndb_init();
- ThreadData* pThreadsData;
- int tLoops = 0, i;
- int returnValue = NDBT_OK;
-
- if (readArguments(argc, argv) != 0){
- input_error();
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- if(useLongKeys){
- longKeyAttrName = (char **) malloc(sizeof(char*) * tNoOfLongPK);
- for (Uint32 i = 0; i < tNoOfLongPK; i++) {
- longKeyAttrName[i] = (char *) malloc(strlen("KEYATTR ") + 1);
- memset(longKeyAttrName[i], 0, strlen("KEYATTR ") + 1);
- sprintf(longKeyAttrName[i], "KEYATTR%i", i);
- }
- }
-
- pThreadsData = new ThreadData[tNoOfThreads];
-
- ndbout << endl << "FLEXBENCH - Starting normal mode" << endl;
- ndbout << "Perform benchmark of insert, update and delete transactions"<< endl;
- ndbout << " " << tNoOfThreads << " thread(s) " << endl;
- ndbout << " " << tNoOfLoops << " iterations " << endl;
- ndbout << " " << tNoOfTables << " table(s) and " << 1 << " operation(s) per transaction " <<endl;
- ndbout << " " << tNoOfAttributes << " attributes per table " << endl;
- ndbout << " " << tNoOfOperations << " transaction(s) per thread and round " << endl;
- ndbout << " " << tAttributeSize << " is the number of 32 bit words per attribute "<< endl;
- ndbout << " " << "Table(s) without logging: " << (Uint32)theTempTable << endl;
-
- if(useLongKeys)
- ndbout << " " << "Using long keys with " << tNoOfLongPK << " keys a' " <<
- tSizeOfLongPK * 4 << " bytes each." << endl;
-
- ndbout << " " << "Verification is " ;
- if(VerifyFlag) {
- ndbout << "enabled" << endl ;
- }else{
- ndbout << "disabled" << endl ;
- }
- theErrorData.printSettings(ndbout);
-
- NdbThread_SetConcurrencyLevel(tNoOfThreads + 2);
-
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- g_cluster_connection= &con;
-
- Ndb* pNdb;
- pNdb = new Ndb(&con, "TEST_DB" );
- pNdb->init();
-
- tNodeId = pNdb->getNodeId();
- ndbout << " NdbAPI node with id = " << tNodeId << endl;
- ndbout << endl;
-
- ndbout << "Waiting for ndb to become ready..." <<endl;
- if (pNdb->waitUntilReady(2000) != 0){
- ndbout << "NDB is not ready" << endl;
- ndbout << "Benchmark failed!" << endl;
- returnValue = NDBT_FAILED;
- }
-
- if(returnValue == NDBT_OK){
- if (createTables(pNdb) != 0){
- returnValue = NDBT_FAILED;
- }
- }
-
- if(returnValue == NDBT_OK){
-
- sleepBeforeStartingTest(tSleepTime);
-
- /****************************************************************
- * Create threads. *
- ****************************************************************/
- resetThreads(pThreadsData);
-
- for (i = 0; i < tNoOfThreads; i++){
- pThreadsData[i].threadNo = i;
- pThreadsData[i].threadLife = NdbThread_Create(flexBenchThread,
- (void**)&pThreadsData[i],
- 32768,
- "flexBenchThread",
- NDB_THREAD_PRIO_LOW);
- }
-
- waitForThreads(pThreadsData);
-
- ndbout << endl << "All threads started" << endl << endl;
-
- /****************************************************************
- * Execute program. *
- ****************************************************************/
-
- for(;;){
-
- int loopCount = tLoops + 1;
- ndbout << endl << "Loop # " << loopCount << endl << endl;
-
- /****************************************************************
- * Perform inserts. *
- ****************************************************************/
- // Reset and start timer
- START_TIMER;
- // Give insert-command to all threads
- resetThreads(pThreadsData);
- tellThreads(pThreadsData, stInsert);
- waitForThreads(pThreadsData);
- if (checkThreadResults(pThreadsData) != 0){
- ndbout << "Error: Threads failed in performing insert" << endl;
- returnValue = NDBT_FAILED;
- break;
- }
- // stop timer and print results.
- STOP_TIMER;
- PRINT_TIMER("insert", tNoOfOperations*tNoOfThreads, tNoOfTables);
- /****************************************************************
- * Verify inserts. *
- ****************************************************************/
- if (VerifyFlag) {
- resetThreads(pThreadsData);
- ndbout << "Verifying inserts...\t" ;
- tellThreads(pThreadsData, stVerify);
- waitForThreads(pThreadsData);
- if (checkThreadResults(pThreadsData) != 0){
- ndbout << "Error: Threads failed while verifying inserts" << endl;
- returnValue = NDBT_FAILED;
- break;
- }else{
- ndbout << "\t\tOK" << endl << endl ;
- }
- }
-
- /****************************************************************
- * Perform read. *
- ****************************************************************/
- // Reset and start timer
- START_TIMER;
- // Give read-command to all threads
- resetThreads(pThreadsData);
- tellThreads(pThreadsData, stRead);
- waitForThreads(pThreadsData);
- if (checkThreadResults(pThreadsData) != 0){
- ndbout << "Error: Threads failed in performing read" << endl;
- returnValue = NDBT_FAILED;
- break;
- }
- // stop timer and print results.
- STOP_TIMER;
- PRINT_TIMER("read", tNoOfOperations*tNoOfThreads, tNoOfTables);
-
- /****************************************************************
- * Perform update. *
- ****************************************************************/
- // Reset and start timer
- START_TIMER;
- // Give insert-command to all threads
- resetThreads(pThreadsData);
- tellThreads(pThreadsData, stUpdate);
- waitForThreads(pThreadsData);
- if (checkThreadResults(pThreadsData) != 0){
- ndbout << "Error: Threads failed in performing update" << endl;
- returnValue = NDBT_FAILED;
- break;
- }
- // stop timer and print results.
- STOP_TIMER;
- PRINT_TIMER("update", tNoOfOperations*tNoOfThreads, tNoOfTables);
-
- /****************************************************************
- * Verify updates. *
- ****************************************************************/
- if (VerifyFlag) {
- resetThreads(pThreadsData);
- ndbout << "Verifying updates...\t" ;
- tellThreads(pThreadsData, stVerify);
- waitForThreads(pThreadsData);
- if (checkThreadResults(pThreadsData) != 0){
- ndbout << "Error: Threads failed while verifying updates" << endl;
- returnValue = NDBT_FAILED;
- break;
- }else{
- ndbout << "\t\tOK" << endl << endl ;
- }
- }
-
- /****************************************************************
- * Perform read. *
- ****************************************************************/
- // Reset and start timer
- START_TIMER;
- // Give insert-command to all threads
- resetThreads(pThreadsData);
- tellThreads(pThreadsData, stRead);
- waitForThreads(pThreadsData);
- if (checkThreadResults(pThreadsData) != 0){
- ndbout << "Error: Threads failed in performing read" << endl;
- returnValue = NDBT_FAILED;
- break;
- }
- // stop timer and print results.
- STOP_TIMER;
- PRINT_TIMER("read", tNoOfOperations*tNoOfThreads, tNoOfTables);
-
- /****************************************************************
- * Perform delete. *
- ****************************************************************/
- // Reset and start timer
- START_TIMER;
- // Give insert-command to all threads
- resetThreads(pThreadsData);
- tellThreads(pThreadsData, stDelete);
- waitForThreads(pThreadsData);
- if (checkThreadResults(pThreadsData) != 0){
- ndbout << "Error: Threads failed in performing delete" << endl;
- returnValue = NDBT_FAILED;
- break;
- }
- // stop timer and print results.
- STOP_TIMER;
- PRINT_TIMER("delete", tNoOfOperations*tNoOfThreads, tNoOfTables);
-
- /****************************************************************
- * Verify deletes. *
- ****************************************************************/
- if (VerifyFlag) {
- resetThreads(pThreadsData);
- ndbout << "Verifying tuple deletion..." ;
- tellThreads(pThreadsData, stVerifyDelete);
- waitForThreads(pThreadsData);
- if (checkThreadResults(pThreadsData) != 0){
- ndbout << "Error: Threads failed in verifying deletes" << endl;
- returnValue = NDBT_FAILED;
- break;
- }else{
- ndbout << "\t\tOK" << endl << endl ;
- }
- }
-
- ndbout << "--------------------------------------------------" << endl;
-
- tLoops++;
-
- if ( 0 != tNoOfLoops && tNoOfLoops <= tLoops )
- break;
- theErrorData.printErrorCounters();
- }
-
- resetThreads(pThreadsData);
- tellThreads(pThreadsData, stStop);
- waitForThreads(pThreadsData);
-
- void * tmp;
- for(i = 0; i<tNoOfThreads; i++){
- NdbThread_WaitFor(pThreadsData[i].threadLife, &tmp);
- NdbThread_Destroy(&pThreadsData[i].threadLife);
- }
- }
-
- if (useLongKeys == true) {
- // Only free these areas if they have been allocated
- // Otherwise cores will happen
- for (i = 0; i < tNoOfLongPK; i++)
- free(longKeyAttrName[i]);
- free(longKeyAttrName);
- } // if
-
- delete [] pThreadsData;
- delete pNdb;
- theErrorData.printErrorCounters();
- return NDBT_ProgramExit(returnValue);
-}
-////////////////////////////////////////
-
-
-unsigned long get_hash(unsigned long * hash_key, int len)
-{
- unsigned long hash_value = 147;
- unsigned h_key;
- int i;
- for (i = 0; i < len; i++)
- {
- h_key = hash_key[i];
- hash_value = (hash_value << 5) + hash_value + (h_key & 255);
- hash_value = (hash_value << 5) + hash_value + ((h_key >> 8) & 255);
- hash_value = (hash_value << 5) + hash_value + ((h_key >> 16) & 255);
- hash_value = (hash_value << 5) + hash_value + ((h_key >> 24) & 255);
- }
- return hash_value;
-}
-
-// End of warming up phase
-
-
-
-static void* flexBenchThread(void* pArg)
-{
- ThreadData* pThreadData = (ThreadData*)pArg;
- unsigned int threadNo, threadBase;
- Ndb* pNdb = NULL ;
- NdbConnection *pTrans = NULL ;
- NdbOperation** pOps = NULL ;
- StartType tType ;
- StartType tSaveType ;
- NdbRecAttr* tTmp = NULL ;
- int* attrValue = NULL ;
- int* attrRefValue = NULL ;
- int check = 0 ;
- int loopCountOps, loopCountTables, loopCountAttributes;
- int tAttemptNo = 0;
- int tRetryAttempts = 20;
- int tResult = 0;
- int tSpecialTrans = 0;
- int nRefLocalOpOffset = 0 ;
- int nReadBuffSize =
- tNoOfTables * tNoOfAttributes * sizeof(int) * tAttributeSize ;
- int nRefBuffSize =
- tNoOfOperations * tNoOfAttributes * sizeof(int) * tAttributeSize ;
- unsigned*** longKeyAttrValue;
-
-
- threadNo = pThreadData->threadNo ;
-
- attrValue = (int*)malloc(nReadBuffSize) ;
- attrRefValue = (int*)malloc(nRefBuffSize) ;
- pOps = (NdbOperation**)malloc(tNoOfTables*sizeof(NdbOperation*)) ;
- pNdb = new Ndb(g_cluster_connection, "TEST_DB" );
-
- if(!attrValue || !attrRefValue || !pOps || !pNdb){
- // Check allocations to make sure we got all the memory we asked for
- ndbout << "One or more memory allocations failed when starting thread #";
- ndbout << threadNo << endl ;
- ndbout << "Thread #" << threadNo << " will now exit" << endl ;
- tResult = 13 ;
- free(attrValue) ;
- free(attrRefValue) ;
- free(pOps) ;
- delete pNdb ;
- return 0; // thread exits
- }
-
- pNdb->init();
- pNdb->waitUntilReady();
-
- // To make sure that two different threads doesn't operate on the same record
- // Calculate an "unique" number to use as primary key
- threadBase = (threadNo * 2000000) + (tNodeId * 260000000);
-
- if(useLongKeys){
- // Allocate and populate the longkey array.
- longKeyAttrValue = (unsigned ***) malloc(sizeof(unsigned**) * tNoOfOperations );
- Uint32 n;
- for (n = 0; n < tNoOfOperations; n++)
- longKeyAttrValue[n] = (unsigned **) malloc(sizeof(unsigned*) * tNoOfLongPK );
- for (n = 0; n < tNoOfOperations; n++){
- for (Uint32 i = 0; i < tNoOfLongPK ; i++) {
- longKeyAttrValue[n][i] = (unsigned *) malloc(sizeof(unsigned) * tSizeOfLongPK);
- memset(longKeyAttrValue[n][i], 0, sizeof(unsigned) * tSizeOfLongPK);
- for(Uint32 j = 0; j < tSizeOfLongPK; j++) {
- // Repeat the unique value to fill up the long key.
- longKeyAttrValue[n][i][j] = threadBase + n;
- }
- }
- }
- }
-
- int nRefOpOffset = 0 ;
- //Assign reference attribute values to memory
- for(Uint32 ops = 1 ; ops < tNoOfOperations ; ops++){
- // Calculate offset value before going into the next loop
- nRefOpOffset = tAttributeSize*tNoOfAttributes*(ops-1) ;
- for(Uint32 a = 0 ; a < tNoOfAttributes ; a++){
- *(int*)&attrRefValue[nRefOpOffset + tAttributeSize*a] =
- (int)(threadBase + ops + a) ;
- }
- }
-
-#ifdef CEBIT_STAT
- // ops not yet reported
- int statOps = 0;
-#endif
- for (;;) {
- pThreadData->threadResult = tResult; // Report error to main thread,
- // normally tResult is set to 0
- pThreadData->threadReady = 1;
-
- while (pThreadData->threadStart == stIdle){
- NdbSleep_MilliSleep(100);
- }//while
-
- // Check if signal to exit is received
- if (pThreadData->threadStart == stStop){
- pThreadData->threadReady = 1;
- // ndbout_c("Thread%d is stopping", threadNo);
- // In order to stop this thread, the main thread has signaled
- // stStop, break out of the for loop so that destructors
- // and the proper exit functions are called
- break;
- }//if
-
- tType = pThreadData->threadStart;
- tSaveType = tType;
- pThreadData->threadStart = stIdle;
-
- // Start transaction, type of transaction
- // is received in the array ThreadStart
- loopCountOps = tNoOfOperations;
- loopCountTables = tNoOfTables;
- loopCountAttributes = tNoOfAttributes;
-
- for (int count = 1; count < loopCountOps && tResult == 0;){
-
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- // This is a fatal error, abort program
- ndbout << "Could not start transaction in thread" << threadNo;
- ndbout << endl;
- ndbout << pNdb->getNdbError() << endl;
- tResult = 1; // Indicate fatal error
- break; // Break out of for loop
- }
-
- // Calculate the current operation offset in the reference array
- nRefLocalOpOffset = tAttributeSize*tNoOfAttributes*(count - 1) ;
-
- for (int countTables = 0;
- countTables < loopCountTables && tResult == 0;
- countTables++) {
-
- pOps[countTables] = pTrans->getNdbOperation(tableName[countTables]);
- if (pOps[countTables] == NULL) {
- // This is a fatal error, abort program
- ndbout << "getNdbOperation: " << pTrans->getNdbError();
- tResult = 2; // Indicate fatal error
- break;
- }//if
-
- switch (tType) {
- case stInsert: // Insert case
- if (theWriteFlag == 1 && theDirtyFlag == 1)
- pOps[countTables]->dirtyWrite();
- else if (theWriteFlag == 1)
- pOps[countTables]->writeTuple();
- else
- pOps[countTables]->insertTuple();
- break;
- case stRead: // Read Case
- if (theSimpleFlag == 1)
- pOps[countTables]->simpleRead();
- else if (theDirtyFlag == 1)
- pOps[countTables]->dirtyRead();
- else
- pOps[countTables]->readTuple();
- break;
- case stUpdate: // Update Case
- if (theWriteFlag == 1 && theDirtyFlag == 1)
- pOps[countTables]->dirtyWrite();
- else if (theWriteFlag == 1)
- pOps[countTables]->writeTuple();
- else if (theDirtyFlag == 1)
- pOps[countTables]->dirtyUpdate();
- else
- pOps[countTables]->updateTuple();
- break;
- case stDelete: // Delete Case
- pOps[countTables]->deleteTuple();
- break;
- case stVerify:
- pOps[countTables]->readTuple();
- break;
- case stVerifyDelete:
- pOps[countTables]->readTuple();
- break;
- default:
- assert(false);
- }//switch
-
-
- if(useLongKeys){
- // Loop the equal call so the complete key is send to the kernel.
- for(Uint32 i = 0; i < tNoOfLongPK; i++)
- pOps[countTables]->equal(longKeyAttrName[i],
- (char *)longKeyAttrValue[count - 1][i], tSizeOfLongPK*4);
- }
- else
- pOps[countTables]->equal((Uint32)0,
- (char*)&attrRefValue[nRefLocalOpOffset]);
-
- if (tType == stInsert || tType == stUpdate){
- for (int ca = 1; ca < loopCountAttributes; ca++){
- pOps[countTables]->setValue((Uint32)ca,
- (char*)&attrRefValue[nRefLocalOpOffset + tAttributeSize*ca]);
- }//for
- } else if (tType == stRead || stVerify == tType) {
- int nTableOffset = tAttributeSize *
- loopCountAttributes *
- countTables ;
- for (int ca = 1; ca < loopCountAttributes; ca++) {
- tTmp = pOps[countTables]->getValue((Uint32)ca,
- (char*)&attrValue[nTableOffset + tAttributeSize*ca]);
- }//for
- } else if (stVerifyDelete == tType) {
- if(useLongKeys){
- int nTableOffset = tAttributeSize *
- loopCountAttributes *
- countTables ;
- tTmp = pOps[countTables]->getValue(longKeyAttrName[0],
- (char*)&attrValue[nTableOffset]);
- } else {
- int nTableOffset = tAttributeSize *
- loopCountAttributes *
- countTables ;
- tTmp = pOps[countTables]->getValue((Uint32)0,
- (char*)&attrValue[nTableOffset]);
- }
- }//if
- }//for Tables loop
-
- if (tResult != 0)
- break;
- check = pTrans->execute(Commit);
-
- // Decide what kind of error this is
- if ((tSpecialTrans == 1) &&
- (check == -1)) {
- // --------------------------------------------------------------------
- // A special transaction have been executed, change to check = 0 in
- // certain situations.
- // --------------------------------------------------------------------
- switch (tType) {
- case stInsert: // Insert case
- if (630 == pTrans->getNdbError().code ) {
- check = 0;
- ndbout << "Insert with 4007 was successful" << endl;
- }//if
- break;
- case stDelete: // Delete Case
- if (626 == pTrans->getNdbError().code ) {
- check = 0;
- ndbout << "Delete with 4007 was successful" << endl;
- }//if
- break;
- default:
- assert(false);
- }//switch
- }//if
- tSpecialTrans = 0;
- if (check == -1) {
- if ((stVerifyDelete == tType) &&
- (626 == pTrans->getNdbError().code)) {
- // ----------------------------------------------
- // It's good news - the deleted tuple is gone,
- // so reset "check" flag
- // ----------------------------------------------
- check = 0 ;
- } else {
- int retCode =
- theErrorData.handleErrorCommon(pTrans->getNdbError());
- if (retCode == 1) {
- ndbout_c("execute: %d, %d, %s", count, tType,
- pTrans->getNdbError().message );
- ndbout_c("Error code = %d", pTrans->getNdbError().code );
- tResult = 20;
- } else if (retCode == 2) {
- ndbout << "4115 should not happen in flexBench" << endl;
- tResult = 20;
- } else if (retCode == 3) {
- // --------------------------------------------------------------------
- // We are not certain if the transaction was successful or not.
- // We must reexecute but might very well find that the transaction
- // actually was updated. Updates and Reads are no problem here. Inserts
- // will not cause a problem if error code 630 arrives. Deletes will
- // not cause a problem if 626 arrives.
- // --------------------------------------------------------------------
- if ((tType == stInsert) || (tType == stDelete)) {
- tSpecialTrans = 1;
- }//if
- }//if
- }//if
- }//if
- // Check if retries should be made
- if (check == -1 && tResult == 0) {
- if (tAttemptNo < tRetryAttempts){
- tAttemptNo++;
- } else {
- // --------------------------------------------------------------------
- // Too many retries have been made, report error and break out of loop
- // --------------------------------------------------------------------
- ndbout << "Thread" << threadNo;
- ndbout << ": too many errors reported" << endl;
- tResult = 10;
- break;
- }//if
- }//if
-
- if (check == 0){
- // Go to the next record
- count++;
- tAttemptNo = 0;
-#ifdef CEBIT_STAT
- // report successful ops
- if (statEnable) {
- statOps += loopCountTables;
- if (statOps >= statFreq) {
- statReport(tType, statOps);
- statOps = 0;
- }//if
- }//if
-#endif
- }//if
-
- if (stVerify == tType && 0 == check){
- int nTableOffset = 0 ;
- for (int a = 1 ; a < loopCountAttributes ; a++){
- for (int tables = 0 ; tables < loopCountTables ; tables++){
- nTableOffset = tables*loopCountAttributes*tAttributeSize ;
- if (*(int*)&attrValue[nTableOffset + tAttributeSize*a] != *(int*)&attrRefValue[nRefLocalOpOffset + tAttributeSize*a]){
- ndbout << "Error in verify:" << endl ;
- ndbout << "attrValue[" << nTableOffset + tAttributeSize*a << "] = " << attrValue[a] << endl ;
- ndbout << "attrRefValue[" << nRefLocalOpOffset + tAttributeSize*a << "]" << attrRefValue[nRefLocalOpOffset + tAttributeSize*a] << endl ;
- tResult = 11 ;
- break ;
- }//if
- }//for
- }//for
- }// if(stVerify ... )
- pNdb->closeTransaction(pTrans) ;
- }// operations loop
-#ifdef CEBIT_STAT
- // report remaining successful ops
- if (statEnable) {
- if (statOps > 0) {
- statReport(tType, statOps);
- statOps = 0;
- }//if
- }//if
-#endif
- }
- delete pNdb;
- free(attrValue) ;
- free(attrRefValue) ;
- free(pOps) ;
-
- if (useLongKeys == true) {
- // Only free these areas if they have been allocated
- // Otherwise cores will occur
- for (Uint32 n = 0; n < tNoOfOperations; n++){
- for (Uint32 i = 0; i < tNoOfLongPK; i++) {
- free(longKeyAttrValue[n][i]);
- }
- free(longKeyAttrValue[n]);
- }
- free(longKeyAttrValue);
- } // if
-
- return NULL; // Thread exits
-}
-
-
-static int readArguments(int argc, const char** argv)
-{
-
- int i = 1;
- while (argc > 1){
- if (strcmp(argv[i], "-t") == 0){
- tNoOfThreads = atoi(argv[i+1]);
- if ((tNoOfThreads < 1))
- return -1;
- argc -= 1;
- i++;
- }else if (strcmp(argv[i], "-o") == 0){
- tNoOfOperations = atoi(argv[i+1]);
- if (tNoOfOperations < 1)
- return -1;;
- argc -= 1;
- i++;
- }else if (strcmp(argv[i], "-a") == 0){
- tNoOfAttributes = atoi(argv[i+1]);
- if ((tNoOfAttributes < 2) || (tNoOfAttributes > MAXATTR))
- return -1;
- argc -= 1;
- i++;
- }else if (strcmp(argv[i], "-lkn") == 0){
- tNoOfLongPK = atoi(argv[i+1]);
- useLongKeys = true;
- if ((tNoOfLongPK < 1) || (tNoOfLongPK > MAXNOLONGKEY) ||
- (tNoOfLongPK * tSizeOfLongPK) > MAXLONGKEYTOTALSIZE){
- ndbout << "Argument -lkn is not in the proper range." << endl;
- return -1;
- }
- argc -= 1;
- i++;
- }else if (strcmp(argv[i], "-lks") == 0){
- tSizeOfLongPK = atoi(argv[i+1]);
- useLongKeys = true;
- if ((tSizeOfLongPK < 1) || (tNoOfLongPK * tSizeOfLongPK) > MAXLONGKEYTOTALSIZE){
- ndbout << "Argument -lks is not in the proper range 1 to " <<
- MAXLONGKEYTOTALSIZE << endl;
- return -1;
- }
- argc -= 1;
- i++;
- }else if (strcmp(argv[i], "-c") == 0){
- tNoOfTables = atoi(argv[i+1]);
- if ((tNoOfTables < 1) || (tNoOfTables > MAXTABLES))
- return -1;
- argc -= 1;
- i++;
- }else if (strcmp(argv[i], "-stdtables") == 0){
- theStdTableNameFlag = 1;
- }else if (strcmp(argv[i], "-l") == 0){
- tNoOfLoops = atoi(argv[i+1]);
- if ((tNoOfLoops < 0) || (tNoOfLoops > 100000))
- return -1;
- argc -= 1;
- i++;
- }else if (strcmp(argv[i], "-s") == 0){
- tAttributeSize = atoi(argv[i+1]);
- if ((tAttributeSize < 1) || (tAttributeSize > MAXATTRSIZE))
- return -1;
- argc -= 1;
- i++;
- }else if (strcmp(argv[i], "-sleep") == 0){
- tSleepTime = atoi(argv[i+1]);
- if ((tSleepTime < 1) || (tSleepTime > 3600))
- return -1;
- argc -= 1;
- i++;
- }else if (strcmp(argv[i], "-simple") == 0){
- theSimpleFlag = 1;
- }else if (strcmp(argv[i], "-write") == 0){
- theWriteFlag = 1;
- }else if (strcmp(argv[i], "-dirty") == 0){
- theDirtyFlag = 1;
- }else if (strcmp(argv[i], "-no_table_create") == 0){
- theTableCreateFlag = 1;
- }else if (strcmp(argv[i], "-temp") == 0){
- theTempTable = true;
- }else if (strcmp(argv[i], "-noverify") == 0){
- VerifyFlag = false ;
- }else if (theErrorData.parseCmdLineArg(argv, i) == true){
- ; //empty, updated in errorArg(..)
- }else if (strcmp(argv[i], "-verify") == 0){
- VerifyFlag = true ;
-#ifdef CEBIT_STAT
- }else if (strcmp(argv[i], "-statserv") == 0){
- if (! (argc > 2))
- return -1;
- const char *p = argv[i+1];
- const char *q = strrchr(p, ':');
- if (q == 0)
- return -1;
- BaseString::snprintf(statHost, sizeof(statHost), "%.*s", q-p, p);
- statPort = atoi(q+1);
- statEnable = true;
- argc -= 1;
- i++;
- }else if (strcmp(argv[i], "-statfreq") == 0){
- if (! (argc > 2))
- return -1;
- statFreq = atoi(argv[i+1]);
- if (statFreq < 1)
- return -1;
- argc -= 1;
- i++;
-#endif
- }else{
- return -1;
- }
- argc -= 1;
- i++;
- }
- return 0;
-}
-
-static void sleepBeforeStartingTest(int seconds){
- if (seconds > 0){
- ndbout << "Sleeping(" <<seconds << ")...";
- NdbSleep_SecSleep(seconds);
- ndbout << " done!" << endl;
- }
-}
-
-
-static int
-createTables(Ndb* pMyNdb){
- int i;
- for (i = 0; i < tNoOfAttributes; i++){
- BaseString::snprintf(attrName[i], MAXSTRLEN, "COL%d", i);
- }
-
- // Note! Uses only uppercase letters in table name's
- // so that we can look at the tables with SQL
- for (i = 0; i < tNoOfTables; i++){
- if (theStdTableNameFlag == 0){
- BaseString::snprintf(tableName[i], MAXSTRLEN, "TAB%d_%d", i,
- (int)(NdbTick_CurrentMillisecond() / 1000));
- } else {
- BaseString::snprintf(tableName[i], MAXSTRLEN, "TAB%d", i);
- }
- }
-
- for(i = 0; i < tNoOfTables; i++){
- ndbout << "Creating " << tableName[i] << "... ";
-
- NdbDictionary::Table tmpTable(tableName[i]);
-
- tmpTable.setStoredTable(!theTempTable);
-
- if(useLongKeys){
- for(Uint32 i = 0; i < tNoOfLongPK; i++) {
- NdbDictionary::Column col(longKeyAttrName[i]);
- col.setType(NdbDictionary::Column::Unsigned);
- col.setLength(tSizeOfLongPK);
- col.setPrimaryKey(true);
- tmpTable.addColumn(col);
- }
- } else {
- NdbDictionary::Column col(attrName[0]);
- col.setType(NdbDictionary::Column::Unsigned);
- col.setLength(1);
- col.setPrimaryKey(true);
- tmpTable.addColumn(col);
- }
-
-
- NdbDictionary::Column col;
- col.setType(NdbDictionary::Column::Unsigned);
- col.setLength(tAttributeSize);
- for (unsigned j = 1; j < tNoOfAttributes; j++){
- col.setName(attrName[j]);
- tmpTable.addColumn(col);
- }
-
- if(pMyNdb->getDictionary()->createTable(tmpTable) == -1){
- return -1;
- }
- ndbout << "done" << endl;
- }
-
- return 0;
-}
-
-
-static void input_error(){
- ndbout << endl << "Invalid argument!" << endl;
- ndbout << endl << "Arguments:" << endl;
- ndbout << " -t Number of threads to start, default 1" << endl;
- ndbout << " -o Number of operations per loop, default 500" << endl;
- ndbout << " -l Number of loops to run, default 1, 0=infinite" << endl;
- ndbout << " -a Number of attributes, default 25" << endl;
- ndbout << " -c Number of tables, default 1" << endl;
- ndbout << " -s Size of each attribute, default 1 (Primary Key is always of size 1," << endl;
- ndbout << " independent of this value)" << endl;
- ndbout << " -lkn Number of long primary keys, default 1" << endl;
- ndbout << " -lks Size of each long primary key, default 1" << endl;
-
- ndbout << " -simple Use simple read to read from database" << endl;
- ndbout << " -dirty Use dirty read to read from database" << endl;
- ndbout << " -write Use writeTuple in insert and update" << endl;
- ndbout << " -stdtables Use standard table names" << endl;
- ndbout << " -no_table_create Don't create tables in db" << endl;
- ndbout << " -sleep Sleep a number of seconds before running the test, this" << endl;
- ndbout << " can be used so that another flexBench have time to create tables" << endl;
- ndbout << " -temp Use tables without logging" << endl;
- ndbout << " -verify Verify inserts, updates and deletes" << endl ;
- theErrorData.printCmdLineArgs(ndbout);
- ndbout << endl <<"Returns:" << endl;
- ndbout << "\t 0 - Test passed" << endl;
- ndbout << "\t 1 - Test failed" << endl;
- ndbout << "\t 2 - Invalid arguments" << endl << endl;
-}
-
-// vim: set sw=2:
diff --git a/storage/ndb/test/ndbapi/flexHammer.cpp b/storage/ndb/test/ndbapi/flexHammer.cpp
deleted file mode 100644
index 7b837bd9b24..00000000000
--- a/storage/ndb/test/ndbapi/flexHammer.cpp
+++ /dev/null
@@ -1,888 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-/* ***************************************************
- FLEXHAMMER
- Hammer ndb with read, insert, update and delete transactions.
-
- Arguments:
- -t Number of threads to start, default 1
- -o Number of operations per hammering-round, default 500
- -l Number of loops to run, default 1, 0=infinite
- -a Number of attributes, default 25
- -c Number of tables, default 1
- -s Size of each attribute, default 1
- -simple Use simple read to read from database
- -dirty Use dirty read to read from database
- -write Use writeTuple to write to db
- -r Number of records to Hammer
- -no_table_create Don't create tables in db
- -regulate To be able to regulate the load flexHammer produces.
- -stdtables Use standard table names
- -sleep Sleep a number of seconds before running the test, this
- can be used so that another flexProgram have tome to create tables
-
- Returns:
- 0 - Test passed
- -1 - Test failed
- 1 - Invalid arguments
-
-Revision history:
- 1.7 020208 epesson: Adapted to use NDBT
- 1.10 020222 epesson: Finalised handling of thread results
- 1.11 020222 epesson: Bug in checking results during delete fixed
-
- * *************************************************** */
-
-#include <ndb_global.h>
-#include <NdbApi.hpp>
-
-#include <NdbMain.h>
-#include <NdbThread.h>
-#include <NdbSleep.h>
-#include <NdbTick.h>
-#include <NdbOut.hpp>
-#include <NdbTimer.hpp>
-#include <NdbTick.h>
-#include <NdbTest.hpp>
-#include <NDBT_Error.hpp>
-#include <NdbSchemaCon.hpp>
-
-ErrorData * flexHammerErrorData;
-
-
-#define MAXSTRLEN 16
-#define MAXATTR 64
-#define MAXTABLES 64
-#define NDB_MAXTHREADS 256
-/*
- NDB_MAXTHREADS used to be just MAXTHREADS, which collides with a
- #define from <sys/thread.h> on AIX (IBM compiler). We explicitly
- #undef it here lest someone use it by habit and get really funny
- results. K&R says we may #undef non-existent symbols, so let's go.
-*/
-#undef MAXTHREADS
-#define MAXATTRSIZE 100
-// Max number of retries if something fails
-#define MaxNoOfAttemptsC 10
-
-enum StartType {
- stIdle,
- stHammer,
- stStop,
- stLast};
-
-enum MyOpType {
- otInsert,
- otRead,
- otDelete,
- otUpdate,
- otLast};
-
-struct ThreadNdb {
- int threadNo;
- NdbThread* threadLife;
- int threadReady;
- StartType threadStart;
- int threadResult;};
-
-extern "C" void* flexHammerThread(void*);
-static int setAttrNames(void);
-static int setTableNames(void);
-static int readArguments(int, const char**);
-static int createTables(Ndb*);
-static void sleepBeforeStartingTest(int seconds);
-static int checkThreadResults(ThreadNdb *threadArrayP, char* phase);
-
-//enum OperationType {
-// otInsert,
-// otRead,
-// otUpdate,
-// otDelete,
-// otVerifyDelete,
-// otLast };
-
-enum ReadyType {
- stReady,
- stRunning
-} ;
-static int tNoOfThreads;
-static int tNoOfAttributes;
-static int tNoOfTables;
-static int tNoOfBackups;
-static int tAttributeSize;
-static int tNoOfOperations;
-static int tNoOfRecords;
-static int tNoOfLoops;
-static ReadyType ThreadReady[NDB_MAXTHREADS];
-static StartType ThreadStart[NDB_MAXTHREADS];
-static char tableName[MAXTABLES][MAXSTRLEN];
-static char attrName[MAXATTR][MAXSTRLEN];
-static int theSimpleFlag = 0;
-static int theWriteFlag = 0;
-static int theDirtyFlag = 0;
-static int theTableCreateFlag = 0;
-static int theStandardTableNameFlag = 0;
-static unsigned int tSleepTime = 0;
-
-#define START_TIMER { NdbTimer timer; timer.doStart();
-#define STOP_TIMER timer.doStop();
-#define PRINT_TIMER(text, trans, opertrans) timer.printTransactionStatistics(text, trans, opertrans); };
-
-
-// Initialise thread data
-void
-resetThreads(ThreadNdb *threadArrayP) {
-
- for (int i = 0; i < tNoOfThreads ; i++)
- {
- threadArrayP[i].threadReady = 0;
- threadArrayP[i].threadResult = 0;
- threadArrayP[i].threadStart = stIdle;
- }
-} // resetThreads
-
-void
-waitForThreads(ThreadNdb *threadArrayP)
-{
- int cont = 1;
-
- while (cont) {
- NdbSleep_MilliSleep(100);
- cont = 0;
- for (int i = 0; i < tNoOfThreads ; i++) {
- if (threadArrayP[i].threadReady == 0) {
- cont = 1;
- } // if
- } // for
- } // while
-} // waitForThreads
-
-void
-tellThreads(ThreadNdb* threadArrayP, const StartType what)
-{
- for (int i = 0; i < tNoOfThreads ; i++)
- {
- threadArrayP[i].threadStart = what;
- } // for
-} // tellThreads
-
-static Ndb_cluster_connection *g_cluster_connection= 0;
-
-NDB_COMMAND(flexHammer, "flexHammer", "flexHammer", "flexHammer", 65535)
-//main(int argc, const char** argv)
-{
- ndb_init();
- ThreadNdb* pThreads = NULL; // Pointer to thread data array
- Ndb* pMyNdb = NULL; // Pointer to Ndb object
- int tLoops = 0;
- int returnValue = 0;
- int check = 0;
-
- flexHammerErrorData = new ErrorData;
-
- flexHammerErrorData->resetErrorCounters();
-
- if (readArguments(argc, argv) != 0) {
- ndbout << "Wrong arguments to flexHammer" << endl;
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- } // if
-
- /* print Setting */
- flexHammerErrorData->printSettings(ndbout);
-
- check = setAttrNames();
- if (check == -1) {
- ndbout << "Couldn't set attribute names" << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- } // if
- check = setTableNames();
- if (check == -1) {
- ndbout << "Couldn't set table names" << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- } // if
-
- // Create thread data array
- pThreads = new ThreadNdb[tNoOfThreads];
- // NdbThread_SetConcurrencyLevel(tNoOfThreads + 2);
-
- // Create and init Ndb object
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- g_cluster_connection= &con;
- pMyNdb = new Ndb(g_cluster_connection, "TEST_DB");
- pMyNdb->init();
-
- // Wait for Ndb to become ready
- if (pMyNdb->waitUntilReady(10000) != 0) {
- ndbout << "NDB is not ready" << endl << "Benchmark failed" << endl;
- returnValue = NDBT_FAILED;
- }
-
- else {
- check = createTables(pMyNdb);
- if (check != 0) {
- returnValue = NDBT_FAILED;
- } // if
- else {
- sleepBeforeStartingTest(tSleepTime);
-
- // Create threads. *
- resetThreads(pThreads);
- for (int i = 0; i < tNoOfThreads ; i++) {
- pThreads[i].threadNo = i;
- pThreads[i].threadLife = NdbThread_Create(flexHammerThread,
- (void**)&pThreads[i],
- 65535,
- "flexHammerThread",
- NDB_THREAD_PRIO_LOW);
- } // for
-
- // And wait until they are ready
- waitForThreads(pThreads);
- if (checkThreadResults(pThreads, "init") != 0) {
- returnValue = NDBT_FAILED;
- } // if
-
-
- if (returnValue == NDBT_OK) {
- ndbout << endl << "All threads started" << endl << endl;
-
- for(;;) {
-
- // Check if it's time to exit program
- if((tNoOfLoops != 0) && (tNoOfLoops <= tLoops))
- break;
-
- // Tell all threads to start hammer
- ndbout << "Hammering..." << endl;
-
- resetThreads(pThreads);
-
- START_TIMER;
- tellThreads(pThreads, stHammer);
-
- waitForThreads(pThreads);
- ndbout << "Threads ready to continue..." << endl;
- STOP_TIMER;
-
- // Check here if anything went wrong
- if (checkThreadResults(pThreads, "hammer") != 0) {
- ndbout << "Thread(s) failed." << endl;
- returnValue = NDBT_FAILED;
- } // if
-
- PRINT_TIMER("hammer", tNoOfOperations*tNoOfThreads, tNoOfTables*6);
-
- ndbout << endl;
-
- tLoops++;
-
- } // for
- } // if
-
- // Signaling threads to stop
- resetThreads(pThreads);
- tellThreads(pThreads, stStop);
-
- // Wait for threads to stop
- waitForThreads(pThreads);
-
- ndbout << "----------------------------------------------" << endl << endl;
- ndbout << "Benchmark completed" << endl;
- } // else
- } // else
- // Clean up
-
- flexHammerErrorData->printErrorCounters(ndbout);
-
- // Kill them all!
- void* tmp;
- for(int i = 0; i < tNoOfThreads; i++){
- NdbThread_WaitFor(pThreads[i].threadLife, &tmp);
- NdbThread_Destroy(&pThreads[i].threadLife);
- }
- delete flexHammerErrorData;
- delete [] pThreads;
- delete pMyNdb;
-
- // Exit via NDBT
- return NDBT_ProgramExit(returnValue);
-
-} //main
-
-extern "C"
-void*
-flexHammerThread(void* pArg)
-{
- ThreadNdb* pThreadData = (ThreadNdb*)pArg;
- unsigned int threadNo = pThreadData->threadNo;
- Ndb* pMyNdb = NULL ;
- NdbConnection *pMyTransaction = NULL ;
- // NdbOperation* pMyOperation[MAXTABLES] = {NULL};
- NdbOperation* pMyOperation[MAXTABLES];
- int check = 0;
- int loop_count_ops = 0;
- int loop_count_tables = 0;
- int loop_count_attributes = 0;
- int count_round = 0;
- int count = 0;
- int count_tables = 0;
- int count_attributes = 0;
- int i = 0;
- int j = 0;
- int tThreadResult = 0;
- MyOpType tMyOpType = otLast;
- int pkValue = 0;
- int readValue[MAXATTR][MAXATTRSIZE] = {0};
- int attrValue[MAXATTRSIZE];
- NdbRecAttr* tTmp = NULL;
- int tNoOfAttempts = 0;
-
- for (i = 0; i < MAXATTRSIZE; i++)
- attrValue[i] = 0;
- // Ndb object for each thread
- pMyNdb = new Ndb(g_cluster_connection, "TEST_DB" );
- pMyNdb->init();
- if (pMyNdb->waitUntilReady(10000) != 0) {
- // Error, NDB is not ready
- tThreadResult = 99;
- // Go to idle directly
- pThreadData->threadStart = stIdle;
- } // if
-
- for(;;) {
- pThreadData->threadResult = tThreadResult;
- pThreadData->threadReady = 1; // Signalling ready to main
-
- // If Idle just wait to be stopped from main
- while (pThreadData->threadStart == stIdle) {
- NdbSleep_MilliSleep(100);
- } // while
-
- // Check if signal to exit is received
- if (pThreadData->threadStart == stStop) {
- pThreadData->threadReady = 1;
- // break out of eternal loop
- break;
- } // if
-
- // Set to Idle to prepare for possible error break
- pThreadData->threadStart = stIdle;
-
- // Prepare transaction
- loop_count_ops = tNoOfOperations;
- loop_count_tables = tNoOfTables;
- loop_count_attributes = tNoOfAttributes;
-
- for (count=0 ; count < loop_count_ops ; count++) {
-
- //pkValue = (int)(count + thread_base);
- // This limits the number of records used in this test
- pkValue = count % tNoOfRecords;
-
- for (count_round = 0; count_round < 5; ) {
- switch (count_round) {
- case 0: // Insert
- tMyOpType = otInsert;
- // Increase attrValues
- for (i=0; i < MAXATTRSIZE; i ++) {
- attrValue[i]++;
- }
- break;
- case 1:
- case 3: // Read and verify
- tMyOpType = otRead;
- break;
- case 2: // Update
- // Increase attrValues
- for(i=0; i < MAXATTRSIZE; i ++) {
- attrValue[i]++;
- }
- tMyOpType = otUpdate;
- break;
- case 4: // Delete
- tMyOpType = otDelete;
- break;
- default:
- assert(false);
- break;
- } // switch
-
- // Get transaction object
- pMyTransaction = pMyNdb->startTransaction();
- if (pMyTransaction == NULL) {
- // Fatal error
- tThreadResult = 1;
- // break out of for count_round loop waiting to be stopped by main
- break;
- } // if
-
- for (count_tables = 0; count_tables < loop_count_tables;
- count_tables++) {
- pMyOperation[count_tables] =
- pMyTransaction->getNdbOperation(tableName[count_tables]);
- if (pMyOperation[count_tables] == NULL) {
- //Fatal error
- tThreadResult = 2;
- // break out of inner for count_tables loop
- break;
- } // if
-
- switch (tMyOpType) {
- case otInsert: // Insert case
- if (theWriteFlag == 1 && theDirtyFlag == 1) {
- check = pMyOperation[count_tables]->dirtyWrite();
- } else if (theWriteFlag == 1) {
- check = pMyOperation[count_tables]->writeTuple();
- } else {
- check = pMyOperation[count_tables]->insertTuple();
- } // if else
- break;
- case otRead: // Read Case
- if (theSimpleFlag == 1) {
- check = pMyOperation[count_tables]->simpleRead();
- } else if (theDirtyFlag == 1) {
- check = pMyOperation[count_tables]->dirtyRead();
- } else {
- check = pMyOperation[count_tables]->readTuple();
- } // if else
- break;
- case otUpdate: // Update Case
- if (theWriteFlag == 1 && theDirtyFlag == 1) {
- check = pMyOperation[count_tables]->dirtyWrite();
- } else if (theWriteFlag == 1) {
- check = pMyOperation[count_tables]->writeTuple();
- } else if (theDirtyFlag == 1) {
- check = pMyOperation[count_tables]->dirtyUpdate();
- } else {
- check = pMyOperation[count_tables]->updateTuple();
- } // if else
- break;
- case otDelete: // Delete Case
- check = pMyOperation[count_tables]->deleteTuple();
- break;
- default:
- assert(false);
- break;
- } // switch
- if (check == -1) {
- // Fatal error
- tThreadResult = 3;
- // break out of inner for count_tables loop
- break;
- } // if
-
- check = pMyOperation[count_tables]->equal( (char*)attrName[0],
- (char*)&pkValue );
-
- if (check == -1) {
- // Fatal error
- tThreadResult = 4;
- ndbout << "pMyOperation equal failed" << endl;
- // break out of inner for count_tables loop
- break;
- } // if
-
- check = -1;
- tTmp = NULL;
- switch (tMyOpType) {
- case otInsert: // Insert case
- case otUpdate: // Update Case
- for (count_attributes = 1; count_attributes < loop_count_attributes;
- count_attributes++) {
- check =
- pMyOperation[count_tables]->setValue((char*)attrName[count_attributes], (char*)&attrValue[0]);
- } // for
- break;
- case otRead: // Read Case
- for (count_attributes = 1; count_attributes < loop_count_attributes;
- count_attributes++) {
- tTmp = pMyOperation[count_tables]->
- getValue( (char*)attrName[count_attributes],
- (char*)&readValue[count_attributes][0] );
- } // for
- break;
- case otDelete: // Delete Case
- break;
- default:
- assert(false);
- break;
- } // switch
- if (check == -1 && tTmp == NULL && tMyOpType != otDelete) {
- // Fatal error
- tThreadResult = 5;
- break;
- } // if
- } // for count_tables
-
- // Only execute if everything is OK
- if (tThreadResult != 0) {
- // Close transaction (below)
- // and continue with next count_round
- count_round++;
- tNoOfAttempts = 0;
- } // if
- else {
- check = pMyTransaction->execute(Commit);
- if (check == -1 ) {
- const NdbError & err = pMyTransaction->getNdbError();
-
- // Add complete error handling here
-
- int retCode = flexHammerErrorData->handleErrorCommon(pMyTransaction->getNdbError());
- if (retCode == 1) {
- //if (strcmp(pMyTransaction->getNdbError().message, "Tuple did not exist") != 0 && strcmp(pMyTransaction->getNdbError().message,"Tuple already existed when attempting to insert") != 0) ndbout_c("execute: %s", pMyTransaction->getNdbError().message);
-
- if (pMyTransaction->getNdbError().code != 626 && pMyTransaction->getNdbError().code != 630){
- ndbout_c("Error code = %d", pMyTransaction->getNdbError().code);
- ndbout_c("execute: %s", pMyTransaction->getNdbError().message);}
-
- } else if (retCode == 2) {
- ndbout << "4115 should not happen in flexHammer" << endl;
- } else if (retCode == 3) {
-// --------------------------------------------------------------------
-// We are not certain if the transaction was successful or not.
-// We must reexecute but might very well find that the transaction
-// actually was updated. Updates and Reads are no problem here. Inserts
-// will not cause a problem if error code 630 arrives. Deletes will
-// not cause a problem if 626 arrives.
-// --------------------------------------------------------------------
- /* What can we do here? */
- ndbout_c("execute: %s", pMyTransaction->getNdbError().message);
- }//if(retCode == 3)
- // End of adding complete error handling
-
- switch( err.classification) {
- case NdbError::ConstraintViolation: // Tuple already existed
- count_round++;
- tNoOfAttempts = 0;
- break;
- case NdbError::TimeoutExpired:
- case NdbError::NodeRecoveryError:
- case NdbError::TemporaryResourceError:
- case NdbError::OverloadError:
- if (tNoOfAttempts <= MaxNoOfAttemptsC) {
- // Retry
- tNoOfAttempts++;
- } else {
- // Too many retries, continue with next
- count_round++;
- tNoOfAttempts = 0;
- } // else if
- break;
- // Fatal, just continue
- default:
- count_round++;
- tNoOfAttempts = 0;
- break;
- } // switch
- } // if
- else {
- // Execute commit was OK
- // This is verifying read values
- //switch (tMyOpType) {
- //case otRead: // Read case
- //for (j = 0; j < tNoOfAttributes; j++) {
- //for(i = 1; i < tAttributeSize; i++) {
- //if ( readValue[j][i] != attrValue[i]) {
- //ndbout << "pkValue = " << pkValue << endl;
- //ndbout << "readValue != attrValue" << endl;
- //ndbout << readValue[j][i] << " != " << attrValue[i] << endl;
- //} // if
- // } // for
- //} // for
- //break;
- //} // switch
- count_round++;
- tNoOfAttempts = 0;
- } // else if
- } // else if
- pMyNdb->closeTransaction(pMyTransaction);
- } // for count_round
- } // for count
- } // for (;;)
-
- // Clean up
- delete pMyNdb;
- pMyNdb = NULL;
-
- flexHammerErrorData->resetErrorCounters();
-
- return NULL; // thread exits
-
-} // flexHammerThread
-
-
-int
-readArguments (int argc, const char** argv)
-{
- int i = 1;
-
- tNoOfThreads = 5; // Default Value
- tNoOfOperations = 500; // Default Value
- tNoOfRecords = 1; // Default Value
- tNoOfLoops = 1; // Default Value
- tNoOfAttributes = 25; // Default Value
- tNoOfTables = 1; // Default Value
- tNoOfBackups = 0; // Default Value
- tAttributeSize = 1; // Default Value
- theTableCreateFlag = 0;
-
- while (argc > 1) {
- if (strcmp(argv[i], "-t") == 0) {
- tNoOfThreads = atoi(argv[i+1]);
- if ((tNoOfThreads < 1) || (tNoOfThreads > NDB_MAXTHREADS))
- return(1);
- }
- else if (strcmp(argv[i], "-o") == 0) {
- tNoOfOperations = atoi(argv[i+1]);
- if (tNoOfOperations < 1)
- return(1);
- }
- else if (strcmp(argv[i], "-r") == 0) {
- tNoOfRecords = atoi(argv[i+1]);
- if (tNoOfRecords < 1)
- return(1);
- }
- else if (strcmp(argv[i], "-a") == 0) {
- tNoOfAttributes = atoi(argv[i+1]);
- if ((tNoOfAttributes < 2) || (tNoOfAttributes > MAXATTR))
- return(1);
- }
- else if (strcmp(argv[i], "-c") == 0) {
- tNoOfTables = atoi(argv[i+1]);
- if ((tNoOfTables < 1) || (tNoOfTables > MAXTABLES))
- return(1);
- }
- else if (strcmp(argv[i], "-l") == 0) {
- tNoOfLoops = atoi(argv[i+1]);
- if ((tNoOfLoops < 0) || (tNoOfLoops > 100000))
- return(1);
- }
- else if (strcmp(argv[i], "-s") == 0) {
- tAttributeSize = atoi(argv[i+1]);
- if ((tAttributeSize < 1) || (tAttributeSize > MAXATTRSIZE))
- return(1);
- }
- else if (strcmp(argv[i], "-sleep") == 0) {
- tSleepTime = atoi(argv[i+1]);
- if ((tSleepTime < 1) || (tSleepTime > 3600))
- exit(-1);
- }
- else if (strcmp(argv[i], "-simple") == 0) {
- theSimpleFlag = 1;
- argc++;
- i--;
- }
- else if (strcmp(argv[i], "-write") == 0) {
- theWriteFlag = 1;
- argc++;
- i--;
- }
- else if (strcmp(argv[i], "-dirty") == 0) {
- theDirtyFlag = 1;
- argc++;
- i--;
- }
- else if (strcmp(argv[i], "-no_table_create") == 0) {
- theTableCreateFlag = 1;
- argc++;
- i--;
- }
- else if (strcmp(argv[i], "-stdtables") == 0) {
- theStandardTableNameFlag = 1;
- argc++;
- i--;
- } // if
- else {
- return(1);
- }
-
- argc -= 2;
- i = i + 2;
- } // while
-
- ndbout << endl << "FLEXHAMMER - Starting normal mode" << endl;
- ndbout << "Hammer ndb with read, insert, update and delete transactions"<< endl << endl;
-
- ndbout << " " << tNoOfThreads << " thread(s) " << endl;
- ndbout << " " << tNoOfLoops << " iterations " << endl;
- ndbout << " " << tNoOfTables << " table(s) and " << 1 << " operation(s) per transaction " << endl;
- ndbout << " " << tNoOfRecords << " records to hammer(limit this with the -r option)" << endl;
- ndbout << " " << tNoOfAttributes << " attributes per table " << endl;
- ndbout << " " << tNoOfOperations << " transaction(s) per thread and round " << endl;
- ndbout << " " << tAttributeSize << " is the number of 32 bit words per attribute " << endl << endl;
- return 0;
-} // readArguments
-
-
-void sleepBeforeStartingTest(int seconds)
-{
- if (seconds > 0) {
- ndbout << "Sleeping(" << seconds << ")...";
- NdbSleep_SecSleep(seconds);
- ndbout << " done!" << endl;
- } // if
-} // sleepBeforeStartingTest
-
-static int
-createTables(Ndb* pMyNdb)
-{
- int i = 0;
- int j = 0;
- int check = 0;
- NdbSchemaCon *MySchemaTransaction = NULL;
- NdbSchemaOp *MySchemaOp = NULL;
-
- // Create Table and Attributes.
- if (theTableCreateFlag == 0) {
-
- for (i = 0; i < tNoOfTables; i++) {
-
- ndbout << "Creating " << tableName[i] << "...";
- // Check if table exists already
- const void * p = pMyNdb->getDictionary()->getTable(tableName[i]);
- if (p != 0) {
- ndbout << " already exists." << endl;
- // Continue with next table at once
- continue;
- } // if
- ndbout << endl;
-
- MySchemaTransaction = NdbSchemaCon::startSchemaTrans(pMyNdb);
- if (MySchemaTransaction == NULL) {
- return(-1);
- } // if
-
- MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
- if (MySchemaOp == NULL) {
- // Clean up opened schema transaction
- NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
- return(-1);
- } // if
-
- // Create tables, rest of parameters are default right now
- check = MySchemaOp->createTable(tableName[i],
- 8, // Table Size
- TupleKey, // Key Type
- 40); // Nr of Pages
-
- if (check == -1) {
- // Clean up opened schema transaction
- NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
- return(-1);
- } // if
-
- // Primary key
- //ndbout << " pk " << (char*)&attrName[0] << "..." << endl;
- check = MySchemaOp->createAttribute( (char*)attrName[0], TupleKey, 32,
- 1, UnSigned, MMBased,
- NotNullAttribute );
- if (check == -1) {
- // Clean up opened schema transaction
- NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
- return(-1);
- } // if
-
- // Rest of attributes
- for (j = 1; j < tNoOfAttributes ; j++) {
- //ndbout << " " << (char*)attrName[j] << "..." << endl;
- check = MySchemaOp->createAttribute( (char*)attrName[j], NoKey, 32,
- tAttributeSize, UnSigned, MMBased,
- NotNullAttribute );
- if (check == -1) {
- // Clean up opened schema transaction
- NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
- return(-1);
- } // if
- } // for
-
- // Execute creation
- check = MySchemaTransaction->execute();
- if (check == -1) {
- // Clean up opened schema transaction
- NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
- return(-1);
- } // if
-
- NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
- } // for
- } // if
-
- return(0);
-
-} // createTables
-
-
-static int setAttrNames()
-{
- int i = 0;
- int retVal = 0;
-
- for (i = 0; i < MAXATTR ; i++) {
- retVal = BaseString::snprintf(attrName[i], MAXSTRLEN, "COL%d", i);
- if (retVal < 0) {
- // Error in conversion
- return(-1);
- } // if
- } // for
-
- return (0);
-} // setAttrNames
-
-static int setTableNames()
-{
- // Note! Uses only uppercase letters in table name's
- // so that we can look at the tables wits SQL
- int i = 0;
- int retVal = 0;
-
- for (i = 0; i < MAXTABLES ; i++) {
- if (theStandardTableNameFlag == 0) {
- retVal = BaseString::snprintf(tableName[i], MAXSTRLEN, "TAB%d_%d", i,
- NdbTick_CurrentMillisecond()/1000);
- } // if
- else {
- retVal = BaseString::snprintf(tableName[i], MAXSTRLEN, "TAB%d", i);
- } // else
- if (retVal < 0) {
- // Error in conversion
- return(-1);
- } // if
- } // for
-
- return(0);
-} // setTableNames
-
-static int checkThreadResults(ThreadNdb *threadArrayP, char* phase)
-{
- int i = 0;
-
- for (i = 0; i < tNoOfThreads; i++) {
- if (threadArrayP[i].threadResult != 0) {
- ndbout << "Thread " << i << " reported fatal error "
- << threadArrayP[i].threadResult << " during " << phase << endl;
- return(-1);
- } // if
- } // for
-
- return(0);
-}
-
diff --git a/storage/ndb/test/ndbapi/flexScan.cpp b/storage/ndb/test/ndbapi/flexScan.cpp
deleted file mode 100644
index 7a3d759d657..00000000000
--- a/storage/ndb/test/ndbapi/flexScan.cpp
+++ /dev/null
@@ -1,1662 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-/* ***************************************************
- FLEXSCAN
- Perform benchmark of:
- insert
- read
- scan read
- update
- scan update
- read
- scan delete
- verify delete
-
- Arguments:
- -f Location of my.cnf file, default my.cnf
- -t Number of threads to start, default 1
- -o Number of operations per loop, default 500 -l Number of loops to run, default 1, 0=infinite
- -a Number of attributes, default 25
- -c Number of tables, default 1
- -s Size of each attribute, default 1
- -stdtables Use standard table names
- -no_table_create Don't create tables in db
- -sleep Sleep a number of seconds before running the test, this
- can be used so that another flexBench hav etome to create tables
- -p Parallellism to use 1-32, default:1
- -abort <number> Test scan abort after a number of tuples
- -h Print help text
- -no_scan_update Don't do scan updates
- -no_scan_delete Don't do scan deletes
-
- Returns:
- NDBT_OK - Test passed
- NDBT_FAILED - Test failed
-
- Revision history:
- 1.12 020222 epesson: Rewritten to use NDBT. Major bugs fixed
-
- * *************************************************** */
-
-#include "NdbApi.hpp"
-
-#include <NdbThread.h>
-#include <NdbSleep.h>
-#include <NdbTick.h>
-#include <NdbOut.hpp>
-#include <NdbTimer.hpp>
-#include <NdbMain.h>
-#include <NdbTest.hpp>
-#include <NDBT_Error.hpp>
-#include <NdbSchemaCon.hpp>
-
-#define PKSIZE 1
-#define FOREVER 1
-#define MAXSTRLEN 16
-#define MAXATTR 64
-#define MAXTABLES 64
-#define NDB_MAXTHREADS 256
-/*
- NDB_MAXTHREADS used to be just MAXTHREADS, which collides with a
- #define from <sys/thread.h> on AIX (IBM compiler). We explicitly
- #undef it here lest someone use it by habit and get really funny
- results. K&R says we may #undef non-existent symbols, so let's go.
-*/
-#undef MAXTHREADS
-#define MAXATTRSIZE 64
-
-enum StartType {
- stIdle,
- stInsert,
- stRead,
- stScanRead,
- stUpdate,
- stScanUpdate,
- stDelete,
- stVerifyDelete,
- stScanDelete,
- stStop,
- stLast} ;
-
-
-struct ThreadNdb
-{
- int ThreadNo;
- NdbThread* threadLife;
- StartType threadStart;
- int threadResult;
- int threadReady;
-};
-
-extern "C" void* flexScanThread(void*);
-static int setAttrNames(void);
-static int setTableNames(void);
-static int createTables(Ndb* pMyNdb);
-static void sleepBeforeStartingTest(int seconds);
-static int readArguments(int argc, const char** argv);
-static void setAttrValues(int* attrValue,
- int* readValue,
- int Offset);
-static int insertRows(Ndb* pNdb, int* pkValue, int* attrValue, StartType tType);
-static int readRows(Ndb* pNdb, int* pkValue, int* readValue);
-static int deleteRows(Ndb* pNdb, int* pkValue);
-static int scanReadRows(Ndb* pNdb, int* readValue);
-static int scanUpdateRows(Ndb* pNdb, int* readValue, int* attrValue);
-static int scanDeleteRows(Ndb* pNdb, int* readValue);
-static int verifyDeleteRows(Ndb* pNdb, int* pkValue, int* readValue);
-static void Compare(int* attrValue, int* readValue);
-static void UpdateArray(int *attrValue);
-
-static int tNoOfThreads = 1;
-static int tNoOfAttributes = 25;
-static int tNoOfTables = 1;
-static int tAttributeSize = 1;
-static int tNodeId = 0;
-static int tNoOfOperations = 500;
-static int tNoOfLoops = 1;
-static int tAbortAfter = 0;
-static int tParallellism = 1;
-
-static char tableName[MAXTABLES][MAXSTRLEN];
-static char attrName[MAXATTR][MAXSTRLEN];
-
-static unsigned int tSleepTime = 0;
-
-static int theStdTableNameFlag = 0;
-static int theTableCreateFlag = 0;
-static int theScanAbortTestFlag = 0;
-static int theNoScanUpdateFlag = 0;
-static int theNoScanDeleteFlag = 0;
-
-//flexScanErrorData = new ErrorData;
-ErrorData * flexScanErrorData;
-NdbError * anerror;
-
-//static errorData theErrorData;
-//static unsigned int tErrorCounter[6000];
-
-#define START_TIMER { NdbTimer timer; timer.doStart();
-#define STOP_TIMER timer.doStop();
-#define PRINT_TIMER(text, trans, opertrans) timer.printTransactionStatistics(text, trans, opertrans); };
-
-static void UpdateArray(int *attrValue)
-{
- int tableCount = 0;
- int attrCount = 0;
- int opCount = 0;
- int sizeCount = 0;
- int* pValue = attrValue;
-
- for (tableCount = 0; tableCount < tNoOfTables; tableCount++) {
- for (attrCount = 0; attrCount < tNoOfAttributes-1; attrCount++) {
- for (opCount = 0; opCount < tNoOfOperations; opCount++) {
- for (sizeCount = 0; sizeCount < tAttributeSize; sizeCount++) {
- // Update value in array
- (*pValue)++;
- //ndbout << "attrValue[" << tableCount*tNoOfAttributes*tNoOfOperations*tAttributeSize +
- //attrCount*tNoOfOperations*tAttributeSize + opCount*tAttributeSize + sizeCount <<
- //"] = " << attrValue[tableCount*tNoOfAttributes*tNoOfOperations*tAttributeSize +
- //attrCount*tNoOfOperations*tAttributeSize + opCount*tAttributeSize + sizeCount] << endl;
- // Increment pointer
- pValue++;
- } // sizeCount
- } // for opCount
- } // for attrCount
- } // for tableCount
-
-} // Update
-
-static void Compare(int* attrValue, int* readValue)
-{
- int tableCount = 0;
- int attrCount = 0;
- int OpCount = 0;
- int first = 0;
-
- for (tableCount = 0; tableCount < tNoOfTables; tableCount++) {
- for (attrCount = 0; attrCount < tNoOfAttributes-1; attrCount++) {
- for (OpCount = 0; OpCount < tNoOfOperations; OpCount++) {
- if (memcmp(&(attrValue[tableCount*(tNoOfAttributes-1)*tNoOfOperations +
- attrCount*tNoOfOperations + OpCount]),
- &(readValue[tableCount*(tNoOfAttributes-1)*tNoOfOperations +
- attrCount*tNoOfOperations + OpCount]),
- tAttributeSize) != 0) {
- // Values mismatch
- if (first == 0) {
- //ndbout << "Read and set values differ for:" << endl;
- first = 1;
- ndbout << "Mismatch found.";
- } // if
- // Comparision of values after scan update is meaningless right now
- //ndbout << " table " << tableName[tableCount] <<
- //" - attr " << attrName[attrCount+1];
- //for (sizeCount = 0; sizeCount < tAttributeSize; sizeCount++) {
- //ndbout << ": set " <<
- //attrValue[tableCount*(tNoOfAttributes-1)*tNoOfOperations*tAttributeSize +
- //attrCount*tNoOfOperations*tAttributeSize +
- //tNoOfOperations*tAttributeSize + sizeCount] << " read " <<
- //readValue[tableCount*(tNoOfAttributes-1)*tNoOfOperations*tAttributeSize +
- //attrCount*tNoOfOperations*tAttributeSize +
- //tNoOfOperations*tAttributeSize + sizeCount] << endl;
- //} // for
- } // if
- } // for OpCount
- } // for attrCount
- } // for tableCount
-
- // A final pretty-print
- if (first == 1) {
- ndbout << endl;
- } // if
-} // Compare
-
-static void printInfo()
-{
- ndbout << endl << "FLEXSCAN - Starting normal mode" << endl;
- ndbout << "Perform benchmark of insert, update and delete transactions"<< endl;
- ndbout << " NdbAPI node with id = " << tNodeId << endl;
- ndbout << " " << tNoOfThreads << " thread(s) " << endl;
- ndbout << " " << tNoOfLoops << " iterations " << endl;
- ndbout << " " << tNoOfTables << " table(s) and " << 1 << " operation(s) per transaction "
- << endl;
- ndbout << " " << tNoOfAttributes << " attributes per table incl. pk" << endl;
- ndbout << " " << tNoOfOperations << " transaction(s) per thread and round " << endl;
- if (theScanAbortTestFlag == 1) {
- ndbout << " Scan abort test after " << tAbortAfter << " tuples" << endl;
- } // if
- ndbout << " " << tParallellism << " parallellism in scans" << endl;
- ndbout << " " << tAttributeSize << " is the number of 32 bit words per attribute " <<
- endl << endl;
-
-} // printInfo
-
-static void tellThreads(ThreadNdb *threadArrayP, StartType what)
-{
- int i = 0;
-
- for (i = 0; i < tNoOfThreads ; i++)
- threadArrayP[i].threadStart = what;
-} // tellThreads
-
-static void waitForThreads(ThreadNdb *threadArrayP)
-{
- int i = 0;
- int cont = 1;
-
- while (cont == 1){
-
- NdbSleep_MilliSleep(10);
- cont = 0;
-
- for (i = 0; i < tNoOfThreads ; i++) {
- if (threadArrayP[i].threadReady == 0) {
-// ndbout << "Main is reporting thread " << i << " not ready" << endl;
- cont = 1;
- } // if
- } // for
- } // while
-} // waitForThreads
-
-
-static void resetThreads(ThreadNdb *threadArrayP)
-{
- int i = 0;
-
- for (i = 0; i < tNoOfThreads ; i++) {
- threadArrayP[i].threadReady = 0;
- threadArrayP[i].threadResult = 0;
- threadArrayP[i].threadStart = stIdle;
- //ndbout << "threadStart[" << i << "]=" <<
- //threadArrayP[i].threadStart << endl;
- } // for
-} // resetThreads
-
-static int checkThreadResults(ThreadNdb *threadArrayP, char *action)
-{
- int i = 0;
- int retValue = 0;
-
- for (i = 0; i < tNoOfThreads; i++) {
- if (threadArrayP[i].threadResult != 0) {
- ndbout << "Thread " << i << " reported fatal error "
- << threadArrayP[i].threadResult << " during " << action << endl;
- retValue = -1;
- break;
- } // if
- } // for
-
- return(retValue);
-} // checkThreadResults
-
-NDB_COMMAND(flexScan, "flexScan", "flexScan", "flexScan", 65535)
-{
- ndb_init();
- ThreadNdb* pThreads = NULL;
- Ndb* pMyNdb = NULL;
- int tLoops = 0;
- int check = 0;
- int returnValue = NDBT_OK;
- int every2ndScanDelete = 0; // Switch between scan delete and normal delete
-
- flexScanErrorData = new ErrorData;
-
- flexScanErrorData->resetErrorCounters();
-
- if (readArguments(argc, argv) != 0) {
- ndbout << "Wrong arguments to flexScan" << endl;
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- } // if
-
- /* print Setting */
- flexScanErrorData->printSettings(ndbout);
-
- check = setAttrNames();
- if (check != 0) {
- ndbout << "Couldn't set attribute names" << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- } // if
- check = setTableNames();
- if (check != 0) {
- ndbout << "Couldn't set table names" << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- } // if
-
- pMyNdb = new Ndb ("TEST_DB");
- pMyNdb->init();
- tNodeId = pMyNdb->getNodeId();
-
- printInfo();
-
- NdbThread_SetConcurrencyLevel(tNoOfThreads + 2);
- //NdbThread_SetConcurrencyLevel(tNoOfThreads + 8);
-
- pThreads = new ThreadNdb[tNoOfThreads];
-
- if (pMyNdb->waitUntilReady(10000) != 0) {
- ndbout << "NDB is not ready" << endl << "Benchmark failed" << endl;
- returnValue = NDBT_FAILED;
- } // if
-
- else {
-
- if (createTables(pMyNdb) != 0) {
- ndbout << "Could not create tables" << endl;
- returnValue = NDBT_FAILED;
- } // if
- else {
- sleepBeforeStartingTest(tSleepTime);
-
- resetThreads(pThreads);
- // Create threads
- for (int i = 0; i < tNoOfThreads ; i++){
- pThreads[i].ThreadNo = i;
- // Ignore the case that thread creation may fail
- pThreads[i].threadLife = NdbThread_Create(flexScanThread,
- (void**)&pThreads[i],
- 327680,
- "flexScanThread", NDB_THREAD_PRIO_LOW);
- if (pThreads[i].threadLife == NULL) {
- ndbout << "Could not create thread " << i << endl;
- returnValue = NDBT_FAILED;
- // Use the number of threads that were actually created
- tNoOfThreads = i;
- break; // break for loop
- } // if
- } // for
-
- waitForThreads(pThreads);
- if (checkThreadResults(pThreads, "init") != 0) {
- returnValue = NDBT_FAILED;
- } // if
-
- if (returnValue == NDBT_OK) {
- ndbout << "All threads started" << endl;
-
- while (FOREVER) {
-
- resetThreads(pThreads);
-
- if ((tNoOfLoops != 0) && (tNoOfLoops <= tLoops)) {
- break;
- } // if
-
- // Insert
- START_TIMER;
-
- tellThreads(pThreads, stInsert);
- waitForThreads(pThreads);
-
- STOP_TIMER;
- if (checkThreadResults(pThreads, "insert") != 0) {
- returnValue = NDBT_FAILED;
- break;
- } // if
- PRINT_TIMER("insert", tNoOfOperations*tNoOfThreads, tNoOfTables);
-
- resetThreads(pThreads);
-
- // Read
- START_TIMER;
-
- tellThreads(pThreads, stRead);
- waitForThreads(pThreads);
-
- STOP_TIMER;
- if (checkThreadResults(pThreads, "read") != 0) {
- returnValue = NDBT_FAILED;
- break;
- } // if
- PRINT_TIMER("read", tNoOfOperations*tNoOfThreads, tNoOfTables);
-
- resetThreads(pThreads);
-
- // Update
- START_TIMER;
-
- tellThreads(pThreads, stUpdate);
- waitForThreads(pThreads);
-
- STOP_TIMER;
- if (checkThreadResults(pThreads, "update") != 0) {
- returnValue = NDBT_FAILED;
- break;
- } // if
- PRINT_TIMER("update", tNoOfOperations*tNoOfThreads, tNoOfTables);
-
- resetThreads(pThreads);
-
- // Scan read
- START_TIMER;
-
- tellThreads(pThreads, stScanRead);
- waitForThreads(pThreads);
-
- STOP_TIMER;
- if (checkThreadResults(pThreads, "scanread") != 0) {
- returnValue = NDBT_FAILED;
- break;
- } // if
- PRINT_TIMER("scanread", tNoOfTables*tNoOfThreads, 1);
-
- resetThreads(pThreads);
-
- // Update
- START_TIMER;
-
- tellThreads(pThreads, stUpdate);
- waitForThreads(pThreads);
-
- STOP_TIMER;
- if (checkThreadResults(pThreads, "update") != 0) {
- returnValue = NDBT_FAILED;
- break;
- } // if
- PRINT_TIMER("update", tNoOfOperations*tNoOfThreads, tNoOfTables);
-
- resetThreads(pThreads);
-
- // Read
- START_TIMER;
-
- tellThreads(pThreads, stRead);
- waitForThreads(pThreads);
-
- STOP_TIMER;
- if (checkThreadResults(pThreads, "read") != 0) {
- returnValue = NDBT_FAILED;
- break;
- } // if
- PRINT_TIMER("read", tNoOfOperations*tNoOfThreads, tNoOfTables);
-
- resetThreads(pThreads);
-
- // Only do scan update if told to do so
- if (theNoScanUpdateFlag == 0) {
- // Scan update
- START_TIMER;
-
- tellThreads(pThreads, stScanUpdate);
- waitForThreads(pThreads);
-
- STOP_TIMER;
- if (checkThreadResults(pThreads, "scanupdate") != 0) {
- returnValue = NDBT_FAILED;
- break;
- } // if
- PRINT_TIMER("scanupdate", tNoOfTables*tNoOfThreads, 1);
-
- resetThreads(pThreads);
-
- // Read
- START_TIMER;
-
- tellThreads(pThreads, stRead);
- // tellThreads(pThreads, stScanRead);
- waitForThreads(pThreads);
-
- STOP_TIMER;
- if (checkThreadResults(pThreads, "read") != 0) {
- returnValue = NDBT_FAILED;
- break;
- } // if
- PRINT_TIMER("read", tNoOfOperations*tNoOfThreads, tNoOfTables);
-
- resetThreads(pThreads);
- } // if theNoScanUpdateFlag
-
- // Shift between delete and scan delete
- if ((every2ndScanDelete % 2 == 0) || (theNoScanDeleteFlag == 1)){
- // Delete
- START_TIMER;
- tellThreads(pThreads, stDelete);
- waitForThreads(pThreads);
-
- STOP_TIMER;
- if (checkThreadResults(pThreads, "delete") != 0) {
- returnValue = NDBT_FAILED;
- break;
- } // if
- PRINT_TIMER("delete", tNoOfOperations*tNoOfThreads, tNoOfTables);
- resetThreads(pThreads);
- } // if
- else {
- resetThreads(pThreads); // Scan delete
- START_TIMER;
- tellThreads(pThreads, stScanDelete);
- waitForThreads(pThreads);
-
- STOP_TIMER;
- if (checkThreadResults(pThreads, "scandelete") != 0) {
- returnValue = NDBT_FAILED;
- break;
- } // if
- PRINT_TIMER("scandelete", tNoOfTables*tNoOfThreads, 1);
-
- resetThreads(pThreads);
- } // else
- every2ndScanDelete++;
-
- resetThreads(pThreads); // Verify delete
- START_TIMER;
- tellThreads(pThreads, stVerifyDelete);
- waitForThreads(pThreads);
-
- STOP_TIMER;
- if (checkThreadResults(pThreads, "verifydelete") != 0) {
- returnValue = NDBT_FAILED;
- break;
- } // if
- PRINT_TIMER("verifydelete", tNoOfOperations*tNoOfThreads*tNoOfTables, 1);
-
- resetThreads(pThreads);
-
- ndbout << "--------------------------------------------------" << endl;
- tLoops++;
-
- } // while
- } // if
- } // else
- } // else
-
- // Stop threads in a nice way
- tellThreads(pThreads, stStop);
- waitForThreads(pThreads);
-
- // Clean up
- delete [] pThreads;
- delete pMyNdb;
-
- flexScanErrorData->printErrorCounters(ndbout);
-
- if (returnValue == NDBT_OK) {
- ndbout << endl << "Benchmark completed successfully" << endl;
- } // if
- else {
- ndbout << endl << "Benchmark failed" << endl;
- } // else
-
- // Exit via NDBT
- return NDBT_ProgramExit(returnValue);;
-} // main
-
-void*
-flexScanThread(void* ThreadData)
-{
- ThreadNdb* pThreadData = (ThreadNdb*)ThreadData;
- unsigned int thread_no = pThreadData->ThreadNo;
- unsigned int thread_base = (thread_no * 2000000) + (tNodeId * 26000);
- int tThreadResult = 0;
- Ndb* MyNdb = NULL;
- int check = 0;
- StartType tType = stLast;
- int* pkValue = NULL;
- int* attrValue = NULL;
- int* readValue = NULL;
- int AllocSize = 0;
-
- AllocSize = tNoOfTables * (tNoOfAttributes-1) * tNoOfOperations *
- tAttributeSize * sizeof(int);
- attrValue = (int*)malloc(AllocSize);
- readValue = (int*)malloc(AllocSize);
- pkValue = (int*)malloc(tNoOfOperations * sizeof(int));
- if ((attrValue == NULL) || (readValue == NULL) || (pkValue == NULL)) {
- tThreadResult = 98;
- pThreadData->threadStart = stIdle;
- } // if
-
- setAttrValues(attrValue, readValue, thread_base);
-
- MyNdb = new Ndb( "TEST_DB" );
- MyNdb->init();
- if (MyNdb->waitUntilReady(10000) != 0) {
- tThreadResult = 99;
- pThreadData->threadStart = stIdle;
- } // if
-
- // Set primary key value, same for all tables
- for (int c = 0; c < tNoOfOperations; c++) {
- pkValue[c] = (int)(c + thread_base);
- } // for
-
- while (FOREVER) {
- pThreadData->threadResult = tThreadResult;
- pThreadData->threadReady = 1;
-
- while (pThreadData->threadStart == stIdle) {
- NdbSleep_MilliSleep(10);
- } // while
-
- // Check if signal to exit is received
- if (pThreadData->threadStart >= stStop){
- pThreadData->threadReady = 1;
- break;
- } // if
- tType = pThreadData->threadStart;
- pThreadData->threadStart = stIdle;
-
- switch (tType) {
- case stInsert:
- check = insertRows(MyNdb, pkValue, attrValue, tType);
- break;
- case stRead:
- check = readRows(MyNdb, pkValue, readValue);
- Compare(attrValue, readValue);
- break;
- case stUpdate:
- UpdateArray(attrValue);
- check = insertRows(MyNdb, pkValue, attrValue, tType);
- break;
- case stScanRead:
- //check = readRows(MyNdb, pkValue, readValue);
- check = scanReadRows(MyNdb, readValue);
- Compare(attrValue, readValue);
- break;
- case stScanUpdate:
- UpdateArray(attrValue);
- //tType = stUpdate;
- //check = insertRows(MyNdb, pkValue, attrValue, tType);
- check = scanUpdateRows(MyNdb, readValue, attrValue);
- break;
- case stDelete:
- check = deleteRows(MyNdb, pkValue);
- break;
- case stScanDelete:
- check = scanDeleteRows(MyNdb, readValue);
- break;
- case stVerifyDelete:
- check = verifyDeleteRows(MyNdb, pkValue, readValue);
- break;
- default:
- ndbout << "tType is " << tType << endl;
- assert(false);
- break;
- } // switch
-
- tThreadResult = check;
-
- if (tThreadResult != 0) {
- // Check if error is fatak or not
- } // if
- else {
- continue;
- } // else
- } // while
-
- // Clean up
- delete MyNdb;
- if (attrValue != NULL) {
- free(attrValue);
- } //if
- if (readValue != NULL) {
- free(readValue);
- } // if
- if (pkValue != NULL) {
- free(pkValue);
- } // if
-
- return NULL; // thread exits
-
-} // flexScanThread
-
-
-static int setAttrNames()
-{
- int i = 0;
- int retVal = 0;
-
- for (i = 0; i < MAXATTR ; i++) {
- retVal = BaseString::snprintf(attrName[i], MAXSTRLEN, "COL%d", i);
- if (retVal < 0) {
- return(-1);
- } // if
- } // for
-
- return(0);
-} // setAttrNames
-
-
-static int setTableNames()
-{
- // Note! Uses only uppercase letters in table name's
- // so that we can look at the tables with SQL
- int i = 0;
- int retVal = 0;
-
- for (i = 0; i < MAXTABLES ; i++) {
-
- if (theStdTableNameFlag == 0) {
- retVal = BaseString::snprintf(tableName[i], MAXSTRLEN, "TAB%d_%d", i,
- (int)(NdbTick_CurrentMillisecond() / 1000));
- } // if
- else {
- retVal = BaseString::snprintf(tableName[i], MAXSTRLEN, "TAB%d", i);
- } // if else
-
- if (retVal < 0) {
- return(-1);
- } // if
- } // for
-
- return(0);
-} // setTableNames
-
-
-// Create Table and Attributes.
-static int createTables(Ndb* pMyNdb)
-{
-
- NdbSchemaCon *MySchemaTransaction = NULL;
- NdbSchemaOp *MySchemaOp = NULL;
- int i = 0;
- int j = 0;
- int check = 0;
-
- if (theTableCreateFlag == 0) {
-
- i = 0;
- do {
- i++;
- ndbout << endl << "Creating " << tableName[i - 1] << "..." << endl;
-
- MySchemaTransaction = NdbSchemaCon::startSchemaTrans(pMyNdb);
- if( MySchemaTransaction == NULL ) {
- return (-1);
- } // if
-
- MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
- if( MySchemaOp == NULL ) {
- NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
- return (-1);
- } // if
-
- check = MySchemaOp->createTable(tableName[i - 1]
- ,8 // Table Size
- ,TupleKey // Key Type
- ,40); // Nr of Pages
-
- if (check == -1) {
- NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
- return -1;
- } // if
-
- check = MySchemaOp->createAttribute( (char*)attrName[0], TupleKey, 32, PKSIZE,
- UnSigned, MMBased, NotNullAttribute );
- if (check == -1) {
- NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
- return -1;
- } // if
-
- for (j = 1; j < tNoOfAttributes ; j++) {
- check = MySchemaOp->createAttribute( (char*)attrName[j], NoKey, 32, tAttributeSize,
- UnSigned, MMBased, NotNullAttribute );
- if (check == -1) {
- NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
- return -1;
- } // if
- } // for
-
- if (MySchemaTransaction->execute() == -1) {
- ndbout << MySchemaTransaction->getNdbError().message << endl;
- ndbout << "Probably, " << tableName[i - 1] << " already exist" << endl;
- } // if
-
- NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
- } while (tNoOfTables > i);
- }
-
- return 0;
-} // createTables
-
-static void printUsage()
-{
- ndbout << "Usage of flexScan:" << endl;
- ndbout << "-f <path> Location of my.cnf file, default: my.cnf" << endl;
- ndbout << "-t <int> Number of threads to start, default 1" << endl;
- ndbout << "-o <int> Number of operations per loop, default 500" << endl;
- ndbout << "-l <int> Number of loops to run, default 1, 0=infinite" << endl;
- ndbout << "-a <int> Number of attributes, default 25" << endl;
- ndbout << "-c <int> Number of tables, default 1" << endl;
- ndbout << "-s <int> Size of each attribute, default 1" << endl;
- ndbout << "-stdtables Use standard table names" << endl;
- ndbout << "-no_table_create Don't create tables in db" << endl;
- ndbout << "-sleep <int> Sleep a number of seconds before running the test" << endl;
- ndbout << "-p <int> Parallellism to use 1-32, default:1" << endl;
- ndbout << "-abort <int> Test scan abort after a number of tuples" << endl;
- ndbout << "-no_scan_update Don't do scan updates" << endl;
- ndbout << "-no_scan_delete Don't do scan deletes" << endl;
- ndbout << "-h Print this text" << endl;
- // inputErrorArg();
- flexScanErrorData->printCmdLineArgs(ndbout);
-}
-
-static int readArguments(int argc, const char** argv)
-{
- int i = 1;
- int retValue = 0;
- int printFlag = 0;
-
- tNoOfThreads = 1; // Set default Value
- tNoOfTables = 1; // Default Value
-
- while (argc > 1) {
- if (strcmp(argv[i], "-t") == 0) {
- if (argv[i + 1] != NULL) {
- tNoOfThreads = atoi(argv[i + 1]);
- if ((tNoOfThreads < 1) || (tNoOfThreads > NDB_MAXTHREADS)) {
- retValue = -1;
- } // if
- } // if
- else {
- retValue = -1;
- } // else
- } // if
- else if (strcmp(argv[i], "-o") == 0) {
- if (argv[i + 1] != NULL) {
- tNoOfOperations = atoi(argv[i + 1]);
- if (tNoOfOperations < 1) {
- retValue = -1;
- } // if
- } // if
- else {
- retValue = -1;
- } // else
- } // else if
- else if (strcmp(argv[i], "-a") == 0) {
- if (argv[i + 1] != NULL) {
- tNoOfAttributes = atoi(argv[i + 1]);
- if ((tNoOfAttributes < 2) || (tNoOfAttributes > MAXATTR)) {
- retValue = -1;
- } // if
- } // if
- else {
- retValue = -1;
- } // else
- } // else if
- else if (strcmp(argv[i], "-c") == 0) {
- if (argv[i + 1] != NULL) {
- tNoOfTables = atoi(argv[i+1]);
- if ((tNoOfTables < 1) || (tNoOfTables > MAXTABLES)) {
- retValue = -1;
- } // if
- } // if
- else {
- retValue = -1;
- } // else
- } // else if
- else if (strcmp(argv[i], "-l") == 0) {
- if (argv[i + 1] != NULL) {
- tNoOfLoops = atoi(argv[i+1]);
- if ((tNoOfLoops < 0) || (tNoOfLoops > 100000)) {
- retValue = -1;
- } // if
- } // if
- else {
- retValue = -1;
- } // else
- } // else if
- else if (strcmp(argv[i], "-s") == 0) {
- if (argv[i + 1] != NULL) {
- tAttributeSize = atoi(argv[i+1]);
- if ((tAttributeSize < 1) || (tAttributeSize > MAXATTRSIZE)) {
- retValue = -1;
- } // if
- } // if
- else {
- retValue = -1;
- } // else
- } // else if
- else if (strcmp(argv[i], "-no_table_create") == 0) {
- theTableCreateFlag = 1;
- argc++;
- i--;
- } // else if
- else if (strcmp(argv[i], "-stdtables") == 0) {
- theStdTableNameFlag = 1;
- argc++;
- i--;
- } // else if
- else if (strcmp(argv[i], "-sleep") == 0) {
- if (argv[i + 1] != NULL) {
- tSleepTime = atoi(argv[i+1]);
- if ((tSleepTime < 1) || (tSleepTime > 3600)) {
- retValue = -1;
- } // if
- } // if
- else {
- retValue = -1;
- } // else
- } // else if
- else if (strcmp(argv[i], "-abort") == 0) {
- // Test scan abort after a number of tuples
- theScanAbortTestFlag = 1;
- if (argv[i + 1] != NULL) {
- tAbortAfter = atoi(argv[i + 1]);
- } // if
- else {
- retValue = -1;
- } // else
- } // else if
- else if (strcmp(argv[i], "-p") == 0) {
- if (argv[i + 1] != NULL) {
- tParallellism = atoi(argv[i + 1]);
- if ((tParallellism < 1) || (tParallellism > 32)) {
- retValue = -1;
- } // if
- } // if
- else {
- retValue = -1;
- } // else
- } // else if
- else if (strcmp(argv[i], "-h") == 0) {
- printFlag = 1;
- argc++;
- i--;
- } // else if
- else if (strcmp(argv[i], "-no_scan_update") == 0) {
- theNoScanUpdateFlag = 1;
- argc++;
- i--;
- } // else if
- else if (strcmp(argv[i], "-no_scan_delete") == 0) {
- theNoScanDeleteFlag = 1;
- argc++;
- i--;
- } // else if
- else {
- retValue = -1;
- } // else
-
- argc -= 2;
- i = i + 2;
- }
-
- if ((retValue != 0) || (printFlag == 1)) {
- printUsage();
- } // if
-
- return(retValue);
-
-} // readArguments
-
-static void sleepBeforeStartingTest(int seconds)
-{
- if (seconds > 0) {
- ndbout << "Sleeping(" <<seconds << ")...";
- NdbSleep_SecSleep(seconds);
- ndbout << " done!" << endl;
- } // if
-} // sleepBeforeStartingTest
-
-static void setAttrValues(int* attrValue,
- int* readValue,
- int Offset)
-{
- int tableCount = 0;
- int attrCount = 0;
- int OpCount = 0;
- int attrSize = 0;
- int* pAttr = NULL;
- int* pRead = NULL;
-
- // Set attribute values in memory array
- for (tableCount = 0; tableCount < tNoOfTables; tableCount++) {
- for (attrCount = 0; attrCount < tNoOfAttributes-1; attrCount++) {
- for (OpCount = 0; OpCount < tNoOfOperations; OpCount++) {
- pAttr = &(attrValue[tableCount*(tNoOfAttributes-1)*tNoOfOperations +
- attrCount*tNoOfOperations + OpCount]);
- pRead = &(readValue[tableCount*(tNoOfAttributes-1)*tNoOfOperations +
- attrCount*tNoOfOperations + OpCount]);
- for (attrSize = 0; attrSize < tAttributeSize; attrSize++){
- *pAttr = (int)(Offset + tableCount + attrCount + OpCount + attrSize);
- //ndbout << "attrValue[" << tableCount*(tNoOfAttributes-1)*tNoOfOperations +
- //attrCount*tNoOfOperations + OpCount + attrSize << "] = " <<
- //attrValue[tableCount*(tNoOfAttributes-1)*tNoOfOperations +
- //attrCount*tNoOfOperations + OpCount + attrSize] << endl;
- *pRead = 0;
- pAttr++;
- pRead++;
- } // for attrSize
- } // for OpCount
- } // for attrCount
- } // for tableCount
-
-} // setAttrValues
-
-static int insertRows(Ndb* pNdb, // NDB object
- int* pkValue, // Primary key values
- int* attrValue, // Attribute values
- StartType tType)
-{
- int tResult = 0;
- int check = 0;
- int tableCount = 0;
- int attrCount = 0;
- NdbConnection* MyTransaction = NULL;
- NdbOperation* MyOperations[MAXTABLES] = {NULL};
- int opCount = 0;
-
- for (opCount = 0; opCount < tNoOfOperations; opCount++) {
- MyTransaction = pNdb->startTransaction();
- if (MyTransaction == NULL) {
- tResult = 1;
- } // if
- else {
- for (tableCount = 0; tableCount < tNoOfTables; tableCount++) {
-
- MyOperations[tableCount] =
- MyTransaction->getNdbOperation(tableName[tableCount]);
- if (MyOperations[tableCount] == NULL) {
- tResult = 2;
- // Break for tableCount loop
- break;
- } // if
-
- if (tType == stUpdate) {
- check = MyOperations[tableCount]->updateTuple();
- } // if
- else if (tType == stInsert) {
- check = MyOperations[tableCount]->insertTuple();
- } // else if
- else {
- assert(false);
- } // else
-
- if (check == -1) {
- tResult = 3;
- break;
- } // if
- check = MyOperations[tableCount]->equal((char*)attrName[0],
- (char*)&(pkValue[opCount]));
- if (check == -1) {
- tResult = 7;
- break;
- } // if
-
- for (attrCount = 0; attrCount < tNoOfAttributes - 1; attrCount++) {
- int Index = tableCount * (tNoOfAttributes - 1) * tNoOfOperations * tAttributeSize +
- attrCount * tNoOfOperations * tAttributeSize + opCount * tAttributeSize;
- check = MyOperations[tableCount]->
- setValue((char*)attrName[attrCount + 1],
- (char*)&(attrValue[Index]));
- if (check == -1) {
- tResult = 8;
- break; // break attrCount loop
- } // if
- } // for
- } // for tableCount
-
- // Execute transaction with insert one tuple in every table
- check = MyTransaction->execute(Commit);
- if (check == -1) {
- ndbout << MyTransaction->getNdbError().message << endl;
-
- // Add complete error handling here
-
- int retCode = flexScanErrorData->handleErrorCommon(MyTransaction->getNdbError());
- if (retCode == 1) {
- if (MyTransaction->getNdbError().code != 626 && MyTransaction->getNdbError().code != 630){
- ndbout_c("execute: %d, %d, %s", opCount, tType, MyTransaction->getNdbError().message);
- ndbout_c("Error code = %d", MyTransaction->getNdbError().code);}
- tResult = 20;
- } else if (retCode == 2) {
- ndbout << "4115 should not happen in flexBench" << endl;
- tResult = 20;
- } else if (retCode == 3) {
-// --------------------------------------------------------------------
-// We are not certain if the transaction was successful or not.
-// We must reexecute but might very well find that the transaction
-// actually was updated. Updates and Reads are no problem here. Inserts
-// will not cause a problem if error code 630 arrives. Deletes will
-// not cause a problem if 626 arrives.
-// --------------------------------------------------------------------
- /* What can we do here? */
- ndbout_c("execute: %s", MyTransaction->getNdbError().message);
- }//if(retCode == 3)
-
- } // if(check == -1)
-
- pNdb->closeTransaction(MyTransaction);
- } // else
- } // for opCount
-
- return(tResult);
-} // insertRows
-
-static int readRows(Ndb* pNdb,
- int* pkValue,
- int* readValue)
-{
- int tResult = 0;
- int tableCount = 0;
- int attrCount = 0;
- int check = 0;
- NdbConnection* MyTransaction = NULL;
- NdbOperation* MyOperations[MAXTABLES] = {NULL};
- NdbRecAttr* tmp = NULL;
- int Value = 0;
- int Index = 0;
- int opCount = 0;
-
- for (opCount = 0; opCount < tNoOfOperations; opCount++) {
- MyTransaction = pNdb->startTransaction();
- if (MyTransaction == NULL) {
- tResult = 1;
- } // if
- else {
- for (tableCount = 0; tableCount < tNoOfTables; tableCount++) {
-
- MyOperations[tableCount] =
- MyTransaction->getNdbOperation(tableName[tableCount]);
- if (MyOperations[tableCount] == NULL) {
- tResult = 2;
- // Break for tableCount loop
- break;
- } // if
-
- check = MyOperations[tableCount]->readTuple();
- if (check == -1) {
- tResult = 3;
- break;
- } // if
-
- check = MyOperations[tableCount]->
- equal((char*)attrName[0], (char*)&(pkValue[opCount]));
- if (check == -1) {
- tResult = 7;
- break;
- } // if
-
- for (int attrCount = 0; attrCount < tNoOfAttributes - 1; attrCount++) {
- Index = tableCount * (tNoOfAttributes - 1) * tNoOfOperations * tAttributeSize +
- attrCount * tNoOfOperations * tAttributeSize + opCount * tAttributeSize;
- tmp = MyOperations[tableCount]->
- getValue((char*)attrName[attrCount + 1], (char*)&(readValue[Index]));
-
- if (tmp == NULL) {
- tResult = 9;
- break;
- } // if
- } // for attrCount
- } // for tableCount
- // Execute transaction reading one tuple in every table
- check = MyTransaction->execute(Commit);
- if (check == -1) {
- ndbout << MyTransaction->getNdbError().message << endl;
-
- // Add complete error handling here
-
- int retCode = flexScanErrorData->handleErrorCommon(MyTransaction->getNdbError());
- if (retCode == 1) {
- if (MyTransaction->getNdbError().code != 626 && MyTransaction->getNdbError().code != 630){
- ndbout_c("execute: %d, %s", opCount, MyTransaction ->getNdbError().message );
- ndbout_c("Error code = %d", MyTransaction->getNdbError().code );}
- tResult = 20;
- } else if (retCode == 2) {
- ndbout << "4115 should not happen in flexBench" << endl;
- tResult = 20;
- } else if (retCode == 3) {
-// --------------------------------------------------------------------
-// We are not certain if the transaction was successful or not.
-// We must reexecute but might very well find that the transaction
-// actually was updated. Updates and Reads are no problem here. Inserts
-// will not cause a problem if error code 630 arrives. Deletes will
-// not cause a problem if 626 arrives.
-// --------------------------------------------------------------------
- /* What can we do here? */
- ndbout_c("execute: %s", MyTransaction ->getNdbError().message );
- }//if(retCode == 3)
-
- } // if
-
- pNdb->closeTransaction(MyTransaction);
- } // else
- } // for opCount
-
- return(tResult);
-} // readRows
-
-static int scanReadRows(Ndb* pNdb, int* readValue)
-{
- int tResult = 0;
- int tableCount = 0;
- int attrCount = 0;
- int check = 0;
- int countAbort = 0; // Counts loops until scan abort if requested
- NdbConnection* MyTransaction = NULL;
- NdbOperation* MyOperation = NULL;
- NdbRecAttr* tmp = NULL;
-
-
- for (tableCount = 0; tableCount < tNoOfTables; tableCount++) {
- MyTransaction = pNdb->startTransaction();
- if (MyTransaction == NULL) {
- tResult = 1;
- break;
- } // if
- MyOperation = MyTransaction->getNdbOperation(tableName[tableCount]);
- if (MyOperation == NULL) {
- tResult = 2;
- break;
- } // if
-
- check = MyOperation->openScanRead(tParallellism);
- if (check == -1) {
- tResult = 10;
- break;
- } // if
-
- for (int attrCount = 0; attrCount < tNoOfAttributes-1; attrCount++) {
- // Get all attributes
- tmp = MyOperation->
- getValue((char*)attrName[attrCount+1],
- (char*)&(readValue[tableCount*(tNoOfAttributes-1)*tNoOfOperations*tAttributeSize +
- attrCount*tNoOfOperations*tAttributeSize]));
- if (tmp == NULL) {
- tResult = 9;
- break;
- } // if
- } // for attrCount
-
- check = MyTransaction->executeScan();
- if (check == -1) {
- tResult = 12;
- break;
- } // if
-
- check = MyTransaction->nextScanResult();
- while (check == 0) {
- // Check if scan abort is requested
- if (theScanAbortTestFlag == 1) {
- if (countAbort == tAbortAfter) {
- MyTransaction->stopScan();
- ndbout << "scanread aborted on request after " << countAbort*tParallellism <<
- " tuples" << endl;
- break; // break while loop
- } // if
- countAbort++;
- } // if
- check = MyTransaction->nextScanResult();
- } // while
-
- pNdb->closeTransaction(MyTransaction);
- } // for tableCount
-
- return(tResult);
-} // scanReadRows
-
-static int scanUpdateRows(Ndb* pNdb,
- int* readValue,
- int* attrValue)
-{
- int tResult = 0;
- int tableCount = 0;
- int attrCount = 0;
- int check = 0;
- int opCount = 0;
- NdbConnection* MyTransaction = NULL;
- NdbOperation* MyOperation = NULL;
- NdbConnection* MyTakeOverTrans = NULL;
- NdbOperation* MyTakeOverOp = NULL;
- NdbRecAttr* tTmp = NULL;
-
- for (tableCount = 0; tableCount < tNoOfTables; tableCount++) {
- MyTransaction = pNdb->startTransaction();
- if (MyTransaction == NULL) {
- tResult = 1;
- break; // break tableCount for loop
- } // if
- MyOperation = MyTransaction->getNdbOperation(tableName[tableCount]);
- if (MyOperation == NULL) {
- tResult = 2;
- break;
- } // if
-
- check = MyOperation->openScanExclusive(tParallellism);
- if (check == -1) {
- tResult = 11;
- break;
- } // if
-
- MyOperation->interpret_exit_ok();
- // Fetch all attributes
- for (int attrCount = 0; attrCount < tNoOfAttributes-1; attrCount++) {
- tTmp = MyOperation->
- getValue((char*)attrName[attrCount+1],
- (char*)&(readValue[tableCount*(tNoOfAttributes-1)*tNoOfOperations*tAttributeSize +
- attrCount*tNoOfOperations*tAttributeSize]));
- if (tTmp == NULL) {
- tResult = 9;
- break; // break for loop
- } // if
- } // for
- if (tResult != 0) {
- break; // break while loop also
- } // if
-
- check = MyTransaction->executeScan();
- if (check == -1) {
- tResult = 12;
- break;
- } // if
- check = MyTransaction->nextScanResult();
- opCount = 0;
- while (check == 0) {
- MyTakeOverTrans = pNdb->startTransaction();
- MyTakeOverOp = MyOperation->takeOverForUpdate(MyTakeOverTrans);
- for (attrCount = 0; attrCount < tNoOfAttributes-1; attrCount++) {
- check = MyTakeOverOp->setValue((char*)attrName[attrCount+1],
- (char*)&(attrValue[tableCount*(tNoOfAttributes-1)*tNoOfOperations*tAttributeSize +
- attrCount*tNoOfOperations*tAttributeSize + opCount*tAttributeSize]));
- } // for
-
- check = MyTakeOverTrans->execute(Commit);
- if (check == 0) {
- check = MyTransaction->nextScanResult();
- opCount++;
- } // if
- else {
- tResult = 95;
-
- /* MyTransaction, MyTakeOverTrans, Which one? */
-
- // Any further error handling?
- int retCode = flexScanErrorData->handleErrorCommon(MyTakeOverTrans->getNdbError());
- if (retCode == 1) {
- if (MyTakeOverTrans->getNdbError().code != 626 && MyTakeOverTrans->getNdbError().code != 630){
- ndbout_c("execute: %s", MyTakeOverTrans->getNdbError().message);
- ndbout_c("Error code = %d", MyTakeOverTrans->getNdbError().code);}
- tResult = 20;
- } else if (retCode == 2) {
- ndbout << "4115 should not happen in flexBench" << endl;
- tResult = 20;
- } else if (retCode == 3) {
- // --------------------------------------------------------------------
- // We are not certain if the transaction was successful or not.
- // We must reexecute but might very well find that the transaction
- // actually was updated. Updates and Reads are no problem here. Inserts
- // will not cause a problem if error code 630 arrives. Deletes will
- // not cause a problem if 626 arrives.
- // --------------------------------------------------------------------
- /* What can we do here? */
- ndbout_c("execute: %s", MyTakeOverTrans->getNdbError().message);
- }//if(retCode == 3)
-
- } // else
- pNdb->closeTransaction(MyTakeOverTrans);
- } // while
-
- pNdb->closeTransaction(MyTransaction);
- } // for
-
- return(tResult);
-} // scanUpdateRows
-
-static int scanDeleteRows(Ndb* pNdb, int* readValue)
-{
- int tResult = 0;
- int tableCount = 0;
- int attrCount = 0;
- int check = 0;
- NdbRecAttr* tTmp = NULL;
- NdbConnection* MyTransaction = NULL;
- NdbOperation* MyOperation = NULL;
- NdbConnection* MyTakeOverTrans = NULL;
- NdbOperation* MyTakeOverOp = NULL;
-
- for (tableCount = 0; tableCount < tNoOfTables; tableCount++) {
- MyTransaction = pNdb->startTransaction();
- if (MyTransaction == NULL) {
- tResult = 1;
- break; // break tableCount for loop
- } // if
-
- MyOperation = MyTransaction->getNdbOperation(tableName[tableCount]);
- if (MyOperation == NULL) {
- tResult = 2;
- break;
- } // if
-
- check = MyOperation->openScanExclusive(tParallellism);
- if (check == -1) {
- tResult = 11;
- break;
- } // if
-
- MyOperation->interpret_exit_ok();
- for (int attrCount = 0; attrCount < tNoOfAttributes-1; attrCount++) {
- tTmp = MyOperation->
- getValue((char*)attrName[attrCount+1],
- (char*)&(readValue[tableCount*(tNoOfAttributes-1)*tNoOfOperations +
- attrCount*tNoOfOperations]));
- if (tTmp == NULL) {
- tResult = 9;
- break;
- } // if
- } // for
-
- check = MyTransaction->executeScan();
- if (check == -1) {
- tResult = 12;
- break;
- } // if
- check = MyTransaction->nextScanResult();
- while (check == 0) {
- MyTakeOverTrans = pNdb->startTransaction();
- MyTakeOverOp = MyOperation->takeOverForDelete(MyTakeOverTrans);
- check = MyTakeOverOp->deleteTuple();
-
- check = MyTakeOverTrans->execute(Commit);
-
- //Error handling here
-
- int retCode =flexScanErrorData->handleErrorCommon(MyTakeOverTrans->getNdbError());
- if (retCode == 1) {
- if (MyTakeOverTrans->getNdbError().code != 626 && MyTakeOverTrans->getNdbError().code != 630){
- ndbout_c("execute: %s", MyTakeOverTrans->getNdbError().message );
- ndbout_c("Error code = %d", MyTakeOverTrans->getNdbError().code );}
- tResult = 20;
- } else if (retCode == 2) {
- ndbout << "4115 should not happen in flexBench" << endl;
- tResult = 20;
- } else if (retCode == 3) {
-// --------------------------------------------------------------------
-// We are not certain if the transaction was successful or not.
-// We must reexecute but might very well find that the transaction
-// actually was updated. Updates and Reads are no problem here. Inserts
-// will not cause a problem if error code 630 arrives. Deletes will
-// not cause a problem if 626 arrives.
-// --------------------------------------------------------------------
- /* What can we do here? */
- ndbout_c("execute: %s", MyTakeOverTrans->getNdbError().message );
- }//if(retCode == 3) End of error handling
-
- pNdb->closeTransaction(MyTakeOverTrans);
- check = MyTransaction->nextScanResult();
- } // while
- pNdb->closeTransaction(MyTransaction);
- } // for tableCount
- return(tResult);
-} // scanDeleteRows
-
-static int deleteRows(Ndb* pNdb,
- int* pkValue)
-{
- int tResult = 0;
- NdbConnection* MyTransaction = NULL;
- int tableCount = 0;
- int opCount = 0;
- int check = 0;
- NdbOperation* MyOperations[MAXTABLES] = {NULL};
-
- for (opCount = 0; opCount < tNoOfOperations; opCount++) {
- MyTransaction = pNdb->startTransaction();
- if (MyTransaction == NULL) {
- tResult = 1;
- } // if
- else {
- for (tableCount = 0; tableCount < tNoOfTables; tableCount++) {
-
- MyOperations[tableCount] =
- MyTransaction->getNdbOperation(tableName[tableCount]);
- if (MyOperations[tableCount] == NULL) {
- tResult = 2;
- // Break for tableCount loop
- break;
- } // if
-
- check = MyOperations[tableCount]->deleteTuple();
- if (check == -1) {
- tResult = 3;
- break;
- } // if
-
- check = MyOperations[tableCount]->
- equal((char*)attrName[0], (char*)&(pkValue[opCount]));
- if (check == -1) {
- tResult = 7;
- break;
- } // if
-
- } // for tableCount
-
- // Execute transaction deleting one tuple in every table
- check = MyTransaction->execute(Commit);
- if (check == -1) {
- ndbout << MyTransaction->getNdbError().message << endl;
- // Add complete error handling here
-
- int retCode = flexScanErrorData->handleErrorCommon(MyTransaction->getNdbError());
- if (retCode == 1) {
- if (MyTransaction->getNdbError().code != 626 && MyTransaction->getNdbError().code != 630){
- ndbout_c("execute: %d, %s", opCount, MyTransaction->getNdbError().message );
- ndbout_c("Error code = %d", MyTransaction->getNdbError().code );}
- tResult = 20;
- } else if (retCode == 2) {
- ndbout << "4115 should not happen in flexBench" << endl;
- tResult = 20;
- } else if (retCode == 3) {
-// --------------------------------------------------------------------
-// We are not certain if the transaction was successful or not.
-// We must reexecute but might very well find that the transaction
-// actually was updated. Updates and Reads are no problem here. Inserts
-// will not cause a problem if error code 630 arrives. Deletes will
-// not cause a problem if 626 arrives.
-// --------------------------------------------------------------------
- /* What can we do here? */
- ndbout_c("execute: %s", MyTransaction->getNdbError().message );
- }//if(retCode == 3)
-
- } // if
-
- pNdb->closeTransaction(MyTransaction);
- } // else
- } // for opCount
-
- return(tResult);
-
-} // deleteRows
-
-////////////////////////////////////////
-//
-// Name: verifyDeleteRows
-//
-// Purpose: Verifies that all tables are empty by reading every tuple
-// No deletions made here
-//
-// Returns: 'Standard' error codes
-//
-/////////////////////////////////////
-static int verifyDeleteRows(Ndb* pNdb,
- int* pkValue,
- int* readValue)
-{
- int tResult = 0;
- int tableCount = 0;
- int attrCount = 0;
- int check = 0;
- NdbConnection* MyTransaction = NULL;
- NdbOperation* MyOperations = NULL;
- NdbRecAttr* tmp = NULL;
- int Value = 0;
- int Index = 0;
- int opCount = 0;
-
- for (opCount = 0; opCount < tNoOfOperations; opCount++) {
- for (tableCount = 0; tableCount < tNoOfTables; tableCount++) {
- MyTransaction = pNdb->startTransaction();
- if (MyTransaction == NULL) {
- tResult = 1;
- } // if
- else {
-
- MyOperations =
- MyTransaction->getNdbOperation(tableName[tableCount]);
- if (MyOperations == NULL) {
- tResult = 2;
- // Break for tableCount loop
- break;
- } // if
-
- check = MyOperations->readTuple();
- if (check == -1) {
- tResult = 3;
- break;
- } // if
-
- check = MyOperations->
- equal((char*)attrName[0], (char*)&(pkValue[opCount]));
- if (check == -1) {
- tResult = 7;
- break;
- } // if
-
- for (int attrCount = 0; attrCount < tNoOfAttributes - 1; attrCount++) {
- Index = tableCount * (tNoOfAttributes - 1) * tNoOfOperations * tAttributeSize +
- attrCount * tNoOfOperations * tAttributeSize + opCount * tAttributeSize;
- tmp = MyOperations->
- getValue((char*)attrName[attrCount + 1], (char*)&(readValue[Index]));
-
- if (tmp == NULL) {
- tResult = 9;
- break;
- } // if
- } // for attrCount
- // Execute transaction reading one tuple in every table
- check = MyTransaction->execute(Commit);
- if ((check == -1) && (MyTransaction->getNdbError().code == 626)){
- // This is expected because everything should be deleted
- } // if
- else if (check == 0) {
- // We have found a tuple that should have been deleted
- ndbout << "tuple " << tableName[tableCount] << ":" <<
- opCount << " was never deleted" << endl;
- tResult = 97;
- } // else if
- else {
- // Unexpected error
- ndbout << "Unexpected error during delete" << endl;
- assert(false);
- } // else
-
- pNdb->closeTransaction(MyTransaction);
-
- } // else
- } // for tableCount
- } // for opCount
-
- return(tResult);
-} // verifyDeleteRows
diff --git a/storage/ndb/test/ndbapi/flexTT.cpp b/storage/ndb/test/ndbapi/flexTT.cpp
deleted file mode 100644
index e4fb364b7ea..00000000000
--- a/storage/ndb/test/ndbapi/flexTT.cpp
+++ /dev/null
@@ -1,944 +0,0 @@
-/* Copyright (c) 2003-2005, 2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-#include <ndb_global.h>
-
-#include <NdbApi.hpp>
-#include <NdbSchemaCon.hpp>
-#include <NdbMain.h>
-#include <md5_hash.hpp>
-
-#include <NdbThread.h>
-#include <NdbSleep.h>
-#include <NdbTick.h>
-#include <NdbOut.hpp>
-#include <NdbTimer.hpp>
-
-#include <NdbTest.hpp>
-#include <NDBT_Error.hpp>
-
-#define MAX_PARTS 4
-#define MAX_SEEK 16
-#define MAXSTRLEN 16
-#define MAXATTR 64
-#define MAXTABLES 64
-#define NDB_MAXTHREADS 128
-/*
- NDB_MAXTHREADS used to be just MAXTHREADS, which collides with a
- #define from <sys/thread.h> on AIX (IBM compiler). We explicitly
- #undef it here lest someone use it by habit and get really funny
- results. K&R says we may #undef non-existent symbols, so let's go.
-*/
-#undef MAXTHREADS
-#define MAXPAR 1024
-#define MAXATTRSIZE 1000
-#define PKSIZE 1
-
-
-#ifdef NDB_WIN32
-inline long lrand48(void) { return rand(); };
-#endif
-
-
-enum StartType {
- stIdle,
- stInsert,
- stRead,
- stUpdate,
- stDelete,
- stStop
-} ;
-
-struct ThreadNdb
-{
- int threadNo;
- Ndb* threadNdb;
- Uint32 threadBase;
- Uint32 threadLoopCounter;
- Uint32 threadNextStart;
- Uint32 threadStop;
- Uint32 threadLoopStop;
- Uint32 threadIncrement;
- Uint32 threadNoCompleted;
- bool threadCompleted;
- StartType threadStartType;
-};
-
-struct TransNdb
-{
- char transRecord[128];
- Ndb* transNdb;
- StartType transStartType;
- Uint32 vpn_number;
- Uint32 vpn_identity;
- Uint32 transErrorCount;
- NdbOperation* transOperation;
- ThreadNdb* transThread;
-};
-
-extern "C" { static void* threadLoop(void*); }
-static void setAttrNames(void);
-static void setTableNames(void);
-static int readArguments(int argc, const char** argv);
-static int createTables(Ndb*);
-static bool defineOperation(NdbConnection* aTransObject, TransNdb*,
- Uint32 vpn_nb, Uint32 vpn_id);
-static bool executeTransaction(TransNdb* transNdbRef);
-static StartType random_choice();
-static void execute(StartType aType);
-static bool executeThread(ThreadNdb*, TransNdb*);
-static void executeCallback(int result, NdbConnection* NdbObject,
- void* aObject);
-static bool error_handler(const NdbError & err) ;
-static Uint32 getKey(Uint32, Uint32) ;
-static void input_error();
-
-ErrorData * flexTTErrorData;
-
-static NdbThread* threadLife[NDB_MAXTHREADS];
-static int tNodeId;
-static int ThreadReady[NDB_MAXTHREADS];
-static StartType ThreadStart[NDB_MAXTHREADS];
-static char tableName[1][MAXSTRLEN+1];
-static char attrName[5][MAXSTRLEN+1];
-
-// Program Parameters
-static bool tInsert = false;
-static bool tDelete = false;
-static bool tReadUpdate = true;
-static int tUpdateFreq = 20;
-static bool tLocal = false;
-static int tLocalPart = 0;
-static int tMinEvents = 0;
-static int tSendForce = 0;
-static int tNoOfLoops = 1;
-static Uint32 tNoOfThreads = 1;
-static Uint32 tNoOfParallelTrans = 32;
-static Uint32 tNoOfTransactions = 500;
-static Uint32 tLoadFactor = 80;
-static bool tempTable = false;
-static bool startTransGuess = true;
-
-//Program Flags
-static int theSimpleFlag = 0;
-static int theDirtyFlag = 0;
-static int theWriteFlag = 0;
-static int theTableCreateFlag = 1;
-
-#define START_REAL_TIME
-#define STOP_REAL_TIME
-#define START_TIMER { NdbTimer timer; timer.doStart();
-#define STOP_TIMER timer.doStop();
-#define PRINT_TIMER(text, trans, opertrans) timer.printTransactionStatistics(text, trans, opertrans); };
-
-static void
-resetThreads(){
-
- for (int i = 0; i < tNoOfThreads ; i++) {
- ThreadReady[i] = 0;
- ThreadStart[i] = stIdle;
- }//for
-}
-
-static void
-waitForThreads(void)
-{
- int cont = 0;
- do {
- cont = 0;
- NdbSleep_MilliSleep(20);
- for (int i = 0; i < tNoOfThreads ; i++) {
- if (ThreadReady[i] == 0) {
- cont = 1;
- }//if
- }//for
- } while (cont == 1);
-}
-
-static void
-tellThreads(StartType what)
-{
- for (int i = 0; i < tNoOfThreads ; i++)
- ThreadStart[i] = what;
-}
-
-static Ndb_cluster_connection *g_cluster_connection= 0;
-
-NDB_COMMAND(flexTT, "flexTT", "flexTT", "flexTT", 65535)
-{
- ndb_init();
- ThreadNdb* pThreadData;
- int returnValue = NDBT_OK;
- int i;
- flexTTErrorData = new ErrorData;
- flexTTErrorData->resetErrorCounters();
-
- if (readArguments(argc, argv) != 0){
- input_error();
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- pThreadData = new ThreadNdb[NDB_MAXTHREADS];
-
- ndbout << endl << "FLEXTT - Starting normal mode" << endl;
- ndbout << "Perform TimesTen benchmark" << endl;
- ndbout << " " << tNoOfThreads << " number of concurrent threads " << endl;
- ndbout << " " << tNoOfParallelTrans;
- ndbout << " number of parallel transaction per thread " << endl;
- ndbout << " " << tNoOfTransactions << " transaction(s) per round " << endl;
- ndbout << " " << tNoOfLoops << " iterations " << endl;
- ndbout << " " << "Update Frequency is " << tUpdateFreq << "%" << endl;
- ndbout << " " << "Load Factor is " << tLoadFactor << "%" << endl;
- if (tLocal == true) {
- ndbout << " " << "We only use Local Part = ";
- ndbout << tLocalPart << endl;
- }//if
- if (tempTable == true) {
- ndbout << " Tables are without logging " << endl;
- } else {
- ndbout << " Tables are with logging " << endl;
- }//if
- if (startTransGuess == true) {
- ndbout << " Transactions are executed with hint provided" << endl;
- } else {
- ndbout << " Transactions are executed with round robin scheme" << endl;
- }//if
- if (tSendForce == 0) {
- ndbout << " No force send is used, adaptive algorithm used" << endl;
- } else if (tSendForce == 1) {
- ndbout << " Force send used" << endl;
- } else {
- ndbout << " No force send is used, adaptive algorithm disabled" << endl;
- }//if
-
- ndbout << endl;
-
- /* print Setting */
- flexTTErrorData->printSettings(ndbout);
-
- NdbThread_SetConcurrencyLevel(2 + tNoOfThreads);
-
- setAttrNames();
- setTableNames();
-
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- g_cluster_connection= &con;
-
- Ndb * pNdb = new Ndb(g_cluster_connection, "TEST_DB");
- pNdb->init();
- tNodeId = pNdb->getNodeId();
-
- ndbout << " NdbAPI node with id = " << pNdb->getNodeId() << endl;
- ndbout << endl;
-
- ndbout << "Waiting for ndb to become ready..." <<endl;
- if (pNdb->waitUntilReady(2000) != 0){
- ndbout << "NDB is not ready" << endl;
- ndbout << "Benchmark failed!" << endl;
- returnValue = NDBT_FAILED;
- }
-
- if(returnValue == NDBT_OK){
- if (createTables(pNdb) != 0){
- returnValue = NDBT_FAILED;
- }
- }
-
- if(returnValue == NDBT_OK){
- /****************************************************************
- * Create NDB objects. *
- ****************************************************************/
- resetThreads();
- for (i = 0; i < tNoOfThreads ; i++) {
- pThreadData[i].threadNo = i;
- threadLife[i] = NdbThread_Create(threadLoop,
- (void**)&pThreadData[i],
- 32768,
- "flexAsynchThread",
- NDB_THREAD_PRIO_LOW);
- }//for
- ndbout << endl << "All NDB objects and table created" << endl << endl;
- int noOfTransacts = tNoOfParallelTrans * tNoOfTransactions *
- tNoOfThreads * tNoOfLoops;
- /****************************************************************
- * Execute program. *
- ****************************************************************/
- /****************************************************************
- * Perform inserts. *
- ****************************************************************/
-
- if (tInsert == true) {
- tInsert = false;
- tReadUpdate = false;
- START_TIMER;
- execute(stInsert);
- STOP_TIMER;
- PRINT_TIMER("insert", noOfTransacts, 1);
- }//if
- /****************************************************************
- * Perform read + updates. *
- ****************************************************************/
-
- if (tReadUpdate == true) {
- START_TIMER;
- execute(stRead);
- STOP_TIMER;
- PRINT_TIMER("update + read", noOfTransacts, 1);
- }//if
- /****************************************************************
- * Perform delete. *
- ****************************************************************/
-
- if (tDelete == true) {
- tDelete = false;
- START_TIMER;
- execute(stDelete);
- STOP_TIMER;
- PRINT_TIMER("delete", noOfTransacts, 1);
- }//if
- ndbout << "--------------------------------------------------" << endl;
-
- execute(stStop);
- void * tmp;
- for(i = 0; i<tNoOfThreads; i++){
- NdbThread_WaitFor(threadLife[i], &tmp);
- NdbThread_Destroy(&threadLife[i]);
- }
- }
- delete [] pThreadData;
- delete pNdb;
-
- //printing errorCounters
- flexTTErrorData->printErrorCounters(ndbout);
-
- return NDBT_ProgramExit(returnValue);
-}//main()
-
-
-static void execute(StartType aType)
-{
- resetThreads();
- tellThreads(aType);
- waitForThreads();
-}//execute()
-
-static void*
-threadLoop(void* ThreadData)
-{
- Ndb* localNdb;
- ThreadNdb* tabThread = (ThreadNdb*)ThreadData;
- int loc_threadNo = tabThread->threadNo;
-
- void * mem = malloc(sizeof(TransNdb)*tNoOfParallelTrans);
- TransNdb* pTransData = (TransNdb*)mem;
-
- localNdb = new Ndb(g_cluster_connection, "TEST_DB");
- localNdb->init(1024);
- localNdb->waitUntilReady();
-
- if (tLocal == false) {
- tabThread->threadIncrement = 1;
- } else {
- tabThread->threadIncrement = MAX_SEEK;
- }//if
- tabThread->threadBase = (loc_threadNo << 16) + tNodeId;
- tabThread->threadNdb = localNdb;
- tabThread->threadStop = tNoOfParallelTrans * tNoOfTransactions;
- tabThread->threadStop *= tabThread->threadIncrement;
- tabThread->threadLoopStop = tNoOfLoops;
- Uint32 i, j;
- for (i = 0; i < tNoOfParallelTrans; i++) {
- pTransData[i].transNdb = localNdb;
- pTransData[i].transThread = tabThread;
- pTransData[i].transOperation = NULL;
- pTransData[i].transStartType = stIdle;
- pTransData[i].vpn_number = tabThread->threadBase;
- pTransData[i].vpn_identity = 0;
- pTransData[i].transErrorCount = 0;
- for (j = 0; j < 128; j++) {
- pTransData[i].transRecord[j] = 0x30;
- }//for
- }//for
-
- for (;;){
- while (ThreadStart[loc_threadNo] == stIdle) {
- NdbSleep_MilliSleep(10);
- }//while
-
- // Check if signal to exit is received
- if (ThreadStart[loc_threadNo] == stStop) {
- break;
- }//if
-
- tabThread->threadStartType = ThreadStart[loc_threadNo];
- tabThread->threadLoopCounter = 0;
- tabThread->threadCompleted = false;
- tabThread->threadNoCompleted = 0;
- tabThread->threadNextStart = 0;
-
- ThreadStart[loc_threadNo] = stIdle;
- if(!executeThread(tabThread, pTransData)){
- break;
- }
- ThreadReady[loc_threadNo] = 1;
- }//for
-
- free(mem);
- delete localNdb;
- ThreadReady[loc_threadNo] = 1;
-
- return NULL; // Thread exits
-}//threadLoop()
-
-static
-bool
-executeThread(ThreadNdb* tabThread, TransNdb* atransDataArrayPtr) {
- Uint32 i;
- for (i = 0; i < tNoOfParallelTrans; i++) {
- TransNdb* transNdbPtr = &atransDataArrayPtr[i];
- transNdbPtr->vpn_identity = i * tabThread->threadIncrement;
- transNdbPtr->transStartType = tabThread->threadStartType;
- if (executeTransaction(transNdbPtr) == false) {
- return false;
- }//if
- }//for
- tabThread->threadNextStart = tNoOfParallelTrans * tabThread->threadIncrement;
- do {
- tabThread->threadNdb->sendPollNdb(3000, tMinEvents, tSendForce);
- } while (tabThread->threadCompleted == false);
- return true;
-}//executeThread()
-
-static
-bool executeTransaction(TransNdb* transNdbRef)
-{
- NdbConnection* MyTrans;
- ThreadNdb* tabThread = transNdbRef->transThread;
- Ndb* aNdbObject = transNdbRef->transNdb;
- Uint32 threadBase = tabThread->threadBase;
- Uint32 startKey = transNdbRef->vpn_identity;
- if (tLocal == true) {
- startKey = getKey(startKey, threadBase);
- }//if
- if (startTransGuess == true) {
- Uint32 tKey[2];
- tKey[0] = startKey;
- tKey[1] = threadBase;
- MyTrans = aNdbObject->startTransaction((Uint32)0, //Priority
- (const char*)&tKey[0], //Main PKey
- (Uint32)8); //Key Length
- } else {
- MyTrans = aNdbObject->startTransaction();
- }//if
- if (MyTrans == NULL) {
- error_handler(aNdbObject->getNdbError());
- ndbout << endl << "Unable to recover! Quiting now" << endl ;
- return false;
- }//if
- //-------------------------------------------------------
- // Define the operation, but do not execute it yet.
- //-------------------------------------------------------
- if (!defineOperation(MyTrans, transNdbRef, startKey, threadBase))
- return false;
-
- return true;
-}//executeTransaction()
-
-
-static
-Uint32
-getKey(Uint32 aBase, Uint32 aThreadBase) {
- Uint32 Tfound = aBase;
- Uint32 hash;
- Uint64 Tkey64;
- Uint32* tKey32 = (Uint32*)&Tkey64;
- tKey32[0] = aThreadBase;
- for (int i = aBase; i < (aBase + MAX_SEEK); i++) {
- tKey32[1] = (Uint32)i;
- hash = md5_hash((Uint64*)&Tkey64, (Uint32)2);
- hash = (hash >> 6) & (MAX_PARTS - 1);
- if (hash == tLocalPart) {
- Tfound = i;
- break;
- }//if
- }//for
- return Tfound;
-}//getKey()
-
-static void
-executeCallback(int result, NdbConnection* NdbObject, void* aObject)
-{
- TransNdb* transNdbRef = (TransNdb*)aObject;
- ThreadNdb* tabThread = transNdbRef->transThread;
- Ndb* tNdb = transNdbRef->transNdb;
- Uint32 vpn_id = transNdbRef->vpn_identity;
- Uint32 vpn_nb = tabThread->threadBase;
-
- if (result == -1) {
-// Add complete error handling here
- int retCode = flexTTErrorData->handleErrorCommon(NdbObject->getNdbError());
- if (retCode == 1) {
- if (NdbObject->getNdbError().code != 626 &&
- NdbObject->getNdbError().code != 630) {
- ndbout_c("execute: %s", NdbObject->getNdbError().message);
- ndbout_c("Error code = %d", NdbObject->getNdbError().code);
- }
- } else if (retCode == 2) {
- ndbout << "4115 should not happen in flexTT" << endl;
- } else if (retCode == 3) {
- /* What can we do here? */
- ndbout_c("execute: %s", NdbObject->getNdbError().message);
- }//if(retCode == 3)
- transNdbRef->transErrorCount++;
- const NdbError & err = NdbObject->getNdbError();
- switch (err.classification) {
- case NdbError::NoDataFound:
- case NdbError::ConstraintViolation:
- ndbout << "Error with vpn_id = " << vpn_id << " and vpn_nb = ";
- ndbout << vpn_nb << endl;
- ndbout << err << endl;
- goto checkCompleted;
- case NdbError::OverloadError:
- NdbSleep_MilliSleep(10);
- case NdbError::NodeRecoveryError:
- case NdbError::UnknownResultError:
- case NdbError::TimeoutExpired:
- break;
- default:
- goto checkCompleted;
- }//if
- if ((transNdbRef->transErrorCount > 10) ||
- (tabThread->threadNoCompleted > 0)) {
- goto checkCompleted;
- }//if
- } else {
- if (tabThread->threadNoCompleted == 0) {
- transNdbRef->transErrorCount = 0;
- transNdbRef->vpn_identity = tabThread->threadNextStart;
- if (tabThread->threadNextStart == tabThread->threadStop) {
- tabThread->threadLoopCounter++;
- transNdbRef->vpn_identity = 0;
- tabThread->threadNextStart = 0;
- if (tabThread->threadLoopCounter == tNoOfLoops) {
- goto checkCompleted;
- }//if
- }//if
- tabThread->threadNextStart += tabThread->threadIncrement;
- } else {
- goto checkCompleted;
- }//if
- }//if
- tNdb->closeTransaction(NdbObject);
- executeTransaction(transNdbRef);
- return;
-
-checkCompleted:
- tNdb->closeTransaction(NdbObject);
- tabThread->threadNoCompleted++;
- if (tabThread->threadNoCompleted == tNoOfParallelTrans) {
- tabThread->threadCompleted = true;
- }//if
- return;
-}//executeCallback()
-
-static
-StartType
-random_choice()
-{
-//----------------------------------------------------
-// Generate a random key between 0 and tNoOfRecords - 1
-//----------------------------------------------------
- UintR random_number = lrand48() % 100;
- if (random_number < tUpdateFreq)
- return stUpdate;
- else
- return stRead;
-}//random_choice()
-
-static bool
-defineOperation(NdbConnection* localNdbConnection, TransNdb* transNdbRef,
- unsigned int vpn_id, unsigned int vpn_nb)
-{
- NdbOperation* localNdbOperation;
- StartType TType = transNdbRef->transStartType;
-
- //-------------------------------------------------------
- // Set-up the attribute values for this operation.
- //-------------------------------------------------------
- localNdbOperation = localNdbConnection->getNdbOperation(tableName[0]);
- if (localNdbOperation == NULL) {
- error_handler(localNdbConnection->getNdbError());
- return false;
- }//if
- switch (TType) {
- case stInsert: // Insert case
- if (theWriteFlag == 1 && theDirtyFlag == 1) {
- localNdbOperation->dirtyWrite();
- } else if (theWriteFlag == 1) {
- localNdbOperation->writeTuple();
- } else {
- localNdbOperation->insertTuple();
- }//if
- break;
- case stRead: // Read Case
- TType = random_choice();
- if (TType == stRead) {
- if (theSimpleFlag == 1) {
- localNdbOperation->simpleRead();
- } else if (theDirtyFlag == 1) {
- localNdbOperation->dirtyRead();
- } else {
- localNdbOperation->readTuple();
- }//if
- } else {
- if (theWriteFlag == 1 && theDirtyFlag == 1) {
- localNdbOperation->dirtyWrite();
- } else if (theWriteFlag == 1) {
- localNdbOperation->writeTuple();
- } else if (theDirtyFlag == 1) {
- localNdbOperation->dirtyUpdate();
- } else {
- localNdbOperation->updateTuple();
- }//if
- }//if
- break;
- case stDelete: // Delete Case
- localNdbOperation->deleteTuple();
- break;
- default:
- error_handler(localNdbOperation->getNdbError());
- }//switch
- localNdbOperation->equal((Uint32)0,vpn_id);
- localNdbOperation->equal((Uint32)1,vpn_nb);
- char* attrValue = &transNdbRef->transRecord[0];
- switch (TType) {
- case stInsert: // Insert case
- localNdbOperation->setValue((Uint32)2, attrValue);
- localNdbOperation->setValue((Uint32)3, attrValue);
- localNdbOperation->setValue((Uint32)4, attrValue);
- break;
- case stUpdate: // Update Case
- localNdbOperation->setValue((Uint32)3, attrValue);
- break;
- case stRead: // Read Case
- localNdbOperation->getValue((Uint32)2, attrValue);
- localNdbOperation->getValue((Uint32)3, attrValue);
- localNdbOperation->getValue((Uint32)4, attrValue);
- break;
- case stDelete: // Delete Case
- break;
- default:
- error_handler(localNdbOperation->getNdbError());
- }//switch
- localNdbConnection->executeAsynchPrepare(Commit, &executeCallback,
- (void*)transNdbRef);
- return true;
-}//defineOperation()
-
-
-static void setAttrNames()
-{
- BaseString::snprintf(attrName[0], MAXSTRLEN, "VPN_ID");
- BaseString::snprintf(attrName[1], MAXSTRLEN, "VPN_NB");
- BaseString::snprintf(attrName[2], MAXSTRLEN, "DIRECTORY_NB");
- BaseString::snprintf(attrName[3], MAXSTRLEN, "LAST_CALL_PARTY");
- BaseString::snprintf(attrName[4], MAXSTRLEN, "DESCR");
-}
-
-
-static void setTableNames()
-{
- BaseString::snprintf(tableName[0], MAXSTRLEN, "VPN_USERS");
-}
-
-static
-int
-createTables(Ndb* pMyNdb){
-
- NdbSchemaCon *MySchemaTransaction;
- NdbSchemaOp *MySchemaOp;
- int check;
-
- if (theTableCreateFlag == 0) {
- ndbout << "Creating Table: vpn_users " << "..." << endl;
- MySchemaTransaction = NdbSchemaCon::startSchemaTrans(pMyNdb);
-
- if(MySchemaTransaction == NULL &&
- (!error_handler(MySchemaTransaction->getNdbError())))
- return -1;
-
- MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
- if(MySchemaOp == NULL &&
- (!error_handler(MySchemaTransaction->getNdbError())))
- return -1;
-
- check = MySchemaOp->createTable( tableName[0]
- ,8 // Table Size
- ,TupleKey // Key Type
- ,40 // Nr of Pages
- ,All
- ,6
- ,(tLoadFactor - 5)
- ,tLoadFactor
- ,1
- ,!tempTable
- );
-
- if (check == -1 &&
- (!error_handler(MySchemaTransaction->getNdbError())))
- return -1;
-
- check = MySchemaOp->createAttribute( (char*)attrName[0],
- TupleKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NotNullAttribute );
-
- if (check == -1 &&
- (!error_handler(MySchemaTransaction->getNdbError())))
- return -1;
- check = MySchemaOp->createAttribute( (char*)attrName[1],
- TupleKey,
- 32,
- 1,
- UnSigned,
- MMBased,
- NotNullAttribute );
-
- if (check == -1 &&
- (!error_handler(MySchemaTransaction->getNdbError())))
- return -1;
- check = MySchemaOp->createAttribute( (char*)attrName[2],
- NoKey,
- 8,
- 10,
- UnSigned,
- MMBased,
- NotNullAttribute );
- if (check == -1 &&
- (!error_handler(MySchemaTransaction->getNdbError())))
- return -1;
-
- check = MySchemaOp->createAttribute( (char*)attrName[3],
- NoKey,
- 8,
- 10,
- UnSigned,
- MMBased,
- NotNullAttribute );
- if (check == -1 &&
- (!error_handler(MySchemaTransaction->getNdbError())))
- return -1;
-
- check = MySchemaOp->createAttribute( (char*)attrName[4],
- NoKey,
- 8,
- 100,
- UnSigned,
- MMBased,
- NotNullAttribute );
- if (check == -1 &&
- (!error_handler(MySchemaTransaction->getNdbError())))
- return -1;
-
- if (MySchemaTransaction->execute() == -1 &&
- (!error_handler(MySchemaTransaction->getNdbError())))
- return -1;
-
- NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
- }//if
-
- return 0;
-}
-
-bool error_handler(const NdbError& err){
- ndbout << err << endl ;
- switch(err.classification){
- case NdbError::NodeRecoveryError:
- case NdbError::SchemaError:
- case NdbError::TimeoutExpired:
- ndbout << endl << "Attempting to recover and continue now..." << endl ;
- return true ; // return true to retry
- }
- return false;
-}
-#if 0
-bool error_handler(const char* error_string, int error_int) {
- ndbout << error_string << endl ;
- if ((4008 == error_int) ||
- (677 == error_int) ||
- (891 == error_int) ||
- (1221 == error_int) ||
- (721 == error_int) ||
- (266 == error_int)) {
- ndbout << endl << "Attempting to recover and continue now..." << endl ;
- return true ; // return true to retry
- }
- return false ; // return false to abort
-}
-#endif
-
-static
-int
-readArguments(int argc, const char** argv){
-
- int i = 1;
- while (argc > 1){
- if (strcmp(argv[i], "-t") == 0){
- tNoOfThreads = atoi(argv[i+1]);
- if ((tNoOfThreads < 1) || (tNoOfThreads > NDB_MAXTHREADS)){
- ndbout_c("Invalid no of threads");
- return -1;
- }
- } else if (strcmp(argv[i], "-p") == 0){
- tNoOfParallelTrans = atoi(argv[i+1]);
- if ((tNoOfParallelTrans < 1) || (tNoOfParallelTrans > MAXPAR)){
- ndbout_c("Invalid no of parallell transactions");
- return -1;
- }
- } else if (strcmp(argv[i], "-o") == 0) {
- tNoOfTransactions = atoi(argv[i+1]);
- if (tNoOfTransactions < 1){
- ndbout_c("Invalid no of transactions");
- return -1;
- }
- } else if (strcmp(argv[i], "-l") == 0){
- tNoOfLoops = atoi(argv[i+1]);
- if (tNoOfLoops < 1) {
- ndbout_c("Invalid no of loops");
- return -1;
- }
- } else if (strcmp(argv[i], "-e") == 0){
- tMinEvents = atoi(argv[i+1]);
- if ((tMinEvents < 1) || (tMinEvents > tNoOfParallelTrans)) {
- ndbout_c("Invalid no of loops");
- return -1;
- }
- } else if (strcmp(argv[i], "-local") == 0){
- tLocalPart = atoi(argv[i+1]);
- tLocal = true;
- startTransGuess = true;
- if ((tLocalPart < 0) || (tLocalPart > MAX_PARTS)){
- ndbout_c("Invalid local part");
- return -1;
- }
- } else if (strcmp(argv[i], "-ufreq") == 0){
- tUpdateFreq = atoi(argv[i+1]);
- if ((tUpdateFreq < 0) || (tUpdateFreq > 100)){
- ndbout_c("Invalid Update Frequency");
- return -1;
- }
- } else if (strcmp(argv[i], "-load_factor") == 0){
- tLoadFactor = atoi(argv[i+1]);
- if ((tLoadFactor < 40) || (tLoadFactor >= 100)){
- ndbout_c("Invalid LoadFactor");
- return -1;
- }
- } else if (strcmp(argv[i], "-d") == 0){
- tDelete = true;
- argc++;
- i--;
- } else if (strcmp(argv[i], "-i") == 0){
- tInsert = true;
- argc++;
- i--;
- } else if (strcmp(argv[i], "-simple") == 0){
- theSimpleFlag = 1;
- argc++;
- i--;
- } else if (strcmp(argv[i], "-adaptive") == 0){
- tSendForce = 0;
- argc++;
- i--;
- } else if (strcmp(argv[i], "-force") == 0){
- tSendForce = 1;
- argc++;
- i--;
- } else if (strcmp(argv[i], "-non_adaptive") == 0){
- tSendForce = 2;
- argc++;
- i--;
- } else if (strcmp(argv[i], "-write") == 0){
- theWriteFlag = 1;
- argc++;
- i--;
- } else if (strcmp(argv[i], "-dirty") == 0){
- theDirtyFlag = 1;
- argc++;
- i--;
- } else if (strcmp(argv[i], "-table_create") == 0){
- theTableCreateFlag = 0;
- tInsert = true;
- argc++;
- i--;
- } else if (strcmp(argv[i], "-temp") == 0){
- tempTable = true;
- argc++;
- i--;
- } else if (strcmp(argv[i], "-no_hint") == 0){
- startTransGuess = false;
- argc++;
- i--;
- } else {
- return -1;
- }
-
- argc -= 2;
- i = i + 2;
- }//while
- if (tLocal == true) {
- if (startTransGuess == false) {
- ndbout_c("Not valid to use no_hint with local");
- }//if
- }//if
- return 0;
-}
-
-static
-void
-input_error(){
-
- ndbout_c("FLEXTT");
- ndbout_c(" Perform benchmark of insert, update and delete transactions");
- ndbout_c("");
- ndbout_c("Arguments:");
- ndbout_c(" -t Number of threads to start, default 1");
- ndbout_c(" -p Number of parallel transactions per thread, default 32");
- ndbout_c(" -o Number of transactions per loop, default 500");
- ndbout_c(" -ufreq Number Update Frequency in percent (0 -> 100), rest is read");
- ndbout_c(" -load_factor Number Fill level in index in percent (40 -> 99)");
- ndbout_c(" -l Number of loops to run, default 1, 0=infinite");
- ndbout_c(" -i Start by inserting all records");
- ndbout_c(" -d End by deleting all records (only one loop)");
- ndbout_c(" -simple Use simple read to read from database");
- ndbout_c(" -dirty Use dirty read to read from database");
- ndbout_c(" -write Use writeTuple in insert and update");
- ndbout_c(" -n Use standard table names");
- ndbout_c(" -table_create Create tables in db");
- ndbout_c(" -temp Create table(s) without logging");
- ndbout_c(" -no_hint Don't give hint on where to execute transaction coordinator");
- ndbout_c(" -adaptive Use adaptive send algorithm (default)");
- ndbout_c(" -force Force send when communicating");
- ndbout_c(" -non_adaptive Send at a 10 millisecond interval");
- ndbout_c(" -local Number of part, only use keys in one part out of 16");
-}
diff --git a/storage/ndb/test/ndbapi/flexTimedAsynch.cpp b/storage/ndb/test/ndbapi/flexTimedAsynch.cpp
deleted file mode 100644
index 2a846008c56..00000000000
--- a/storage/ndb/test/ndbapi/flexTimedAsynch.cpp
+++ /dev/null
@@ -1,859 +0,0 @@
-/* Copyright (c) 2003-2005, 2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-/* ***************************************************
- FLEXTIMEDASYNCH
- Perform benchmark of insert, update and delete transactions.
-
- Arguments:
- -t Number of threads to start, i.e., number of parallel loops, default 1
- -p Number of transactions in a batch, default 32
- -o Number of batches per loop, default 200
- -i Time between batch starts, default 0
- -l Number of loops to run, default 1, 0=infinite
- -a Number of attributes, default 25
- -c Number of operations per transaction
- -s Size of each attribute in 32 bit word, default 1 (Primary Key is always of size 1,
- independent of this value)
- -simple Use simple read to read from database
- -dirty Use dirty read to read from database
- -write Use writeTuple in insert and update
- -n Use standard table names
- -no_table_create Don't create tables in db
- -temp Use temporary tables, no writing to disk.
-
- Returns:
- 0 - Test passed
- -1 - Test failed
- 1 - Invalid arguments
-
- * *************************************************** */
-
-#include "NdbApi.hpp"
-
-#include <NdbThread.h>
-#include <NdbSleep.h>
-#include <NdbTick.h>
-#include <NdbOut.hpp>
-#include <NdbTimer.hpp>
-#include <string.h>
-#include <NdbMain.h>
-#include <NdbTest.hpp>
-
-#include <NDBT_Error.hpp>
-
-#define MAXSTRLEN 16
-#define MAXATTR 64
-#define MAXTABLES 64
-#define NDB_MAXTHREADS 256
-/*
- NDB_MAXTHREADS used to be just MAXTHREADS, which collides with a
- #define from <sys/thread.h> on AIX (IBM compiler). We explicitly
- #undef it here lest someone use it by habit and get really funny
- results. K&R says we may #undef non-existent symbols, so let's go.
-*/
-#undef MAXTHREADS
-#define MAXATTRSIZE 1000
-#define PKSIZE 1
-
-enum StartType { stIdle,
- stInsert,
- stRead,
- stUpdate,
- stDelete,
- stStop } ;
-
-ErrorData * flexTimedAsynchErrorData;
-
-struct ThreadNdb
-{
- int NoOfOps;
- int ThreadNo;
- unsigned int threadBase;
- unsigned int transactionCompleted;
-};
-
-extern "C" void* threadLoop(void*);
-void setAttrNames(void);
-void setTableNames(void);
-void readArguments(int argc, const char** argv);
-void createAttributeSpace();
-void createTables(Ndb*);
-void defineOperation(NdbConnection* aTransObject, StartType aType, unsigned int key, int *);
-void execute(StartType aType);
-void executeThread(StartType aType, Ndb* aNdbObject, ThreadNdb* threadInfo);
-void executeCallback(int result, NdbConnection* NdbObject, void* aObject);
-
-/* epaulsa > *************************************************************/
-bool error_handler(const NdbError &) ; //replaces 'goto' things
-static int failed = 0 ; // lame global variable that keeps track of failed transactions
- // incremented in executeCallback() and reset in main()
-/************************************************************* < epaulsa */
-
-static NdbThread* threadLife[NDB_MAXTHREADS];
-static int tNodeId;
-static int ThreadReady[NDB_MAXTHREADS];
-static StartType ThreadStart[NDB_MAXTHREADS];
-static char tableName[MAXTABLES][MAXSTRLEN+1];
-static char attrName[MAXATTR][MAXSTRLEN+1];
-static int *getAttrValueTable;
-
-// Program Parameters
-static int tNoOfLoops = 1;
-static int tAttributeSize = 1;
-static unsigned int tNoOfThreads = 1;
-static unsigned int tNoOfTransInBatch = 32;
-static unsigned int tNoOfAttributes = 25;
-static unsigned int tNoOfBatchesInLoop = 200;
-static unsigned int tNoOfOpsPerTrans = 1;
-static unsigned int tTimeBetweenBatches = 0;
-
-//Program Flags
-static int theTestFlag = 0;
-static int theTempFlag = 1;
-static int theSimpleFlag = 0;
-static int theDirtyFlag = 0;
-static int theWriteFlag = 0;
-static int theStdTableNameFlag = 0;
-static int theTableCreateFlag = 0;
-
-#define START_REAL_TIME NdbTimer timer; timer.doStart();
-#define STOP_REAL_TIME timer.doStop();
-
-#define START_TIMER { NdbTimer timer; timer.doStart();
-#define STOP_TIMER timer.doStop();
-#define PRINT_TIMER(text, trans, opertrans) timer.printTransactionStatistics(text, trans, opertrans); };
-
-void
-resetThreads(){
-
- for (int i = 0; i < tNoOfThreads ; i++) {
- ThreadReady[i] = 0;
- ThreadStart[i] = stIdle;
- }
-}
-
-void
-waitForThreads(void)
-{
- int cont;
- do {
- cont = 0;
- NdbSleep_MilliSleep(20);
- for (int i = 0; i < tNoOfThreads ; i++) {
- if (ThreadReady[i] == 0) {
- cont = 1;
- }
- }
- } while (cont == 1);
-}
-
-void
-tellThreads(StartType what)
-{
- for (int i = 0; i < tNoOfThreads ; i++)
- ThreadStart[i] = what;
-}
-
-void createAttributeSpace(){
- getAttrValueTable = new int[tAttributeSize*
- tNoOfThreads *
- tNoOfAttributes ];
-
-}
-
-void deleteAttributeSpace(){
- delete [] getAttrValueTable;
-}
-
-NDB_COMMAND(flexTimedAsynch, "flexTimedAsynch", "flexTimedAsynch [-tpoilcas]", "flexTimedAsynch", 65535)
-{
- ndb_init();
- ThreadNdb tabThread[NDB_MAXTHREADS];
- int tLoops=0;
- int returnValue;
- //NdbOut flexTimedAsynchNdbOut;
-
- flexTimedAsynchErrorData = new ErrorData;
- flexTimedAsynchErrorData->resetErrorCounters();
-
- Ndb* pNdb;
- pNdb = new Ndb( "TEST_DB" );
- pNdb->init();
-
- readArguments(argc, argv);
-
- createAttributeSpace();
-
- ndbout << endl << "FLEXTIMEDASYNCH - Starting normal mode" << endl;
- ndbout << "Perform benchmark of insert, update and delete transactions" << endl << endl;
-
- if(theTempFlag == 0)
- ndbout << " " << "Using temporary tables. " << endl;
-
- // -t, tNoOfThreads
- ndbout << " " << tNoOfThreads << " number of concurrent threads " << endl;
- // -c, tNoOfOpsPerTrans
- ndbout << " " << tNoOfOpsPerTrans << " operations per transaction " << endl;
- // -p, tNoOfTransInBatch
- ndbout << " " << tNoOfTransInBatch << " number of transactions in a batch per thread " << endl;
- // -o, tNoOfBatchesInLoop
- ndbout << " " << tNoOfBatchesInLoop << " number of batches per loop " << endl;
- // -i, tTimeBetweenBatches
- ndbout << " " << tTimeBetweenBatches << " milli seconds at least between batch starts " << endl;
- // -l, tNoOfLoops
- ndbout << " " << tNoOfLoops << " loops " << endl;
- // -a, tNoOfAttributes
- ndbout << " " << tNoOfAttributes << " attributes per table " << endl;
- // -s, tAttributeSize
- ndbout << " " << tAttributeSize << " is the number of 32 bit words per attribute " << endl << endl;
-
- NdbThread_SetConcurrencyLevel(2 + tNoOfThreads);
-
- /* print Setting */
- flexTimedAsynchErrorData->printSettings(ndbout);
-
- setAttrNames();
- setTableNames();
-
- ndbout << "Waiting for ndb to become ready..." <<endl;
- if (pNdb->waitUntilReady() == 0) {
- tNodeId = pNdb->getNodeId();
- ndbout << " NdbAPI node with id = " << tNodeId << endl;
- createTables(pNdb);
-
- /****************************************************************
- * Create NDB objects. *
- ****************************************************************/
- resetThreads();
- for (int i = 0; i < tNoOfThreads ; i++) {
- tabThread[i].ThreadNo = i;
-
- threadLife[i] = NdbThread_Create(threadLoop,
- (void**)&tabThread[i],
- 32768,
- "flexTimedAsynchThread",
- NDB_THREAD_PRIO_LOW);
- }
- ndbout << endl << "All NDB objects and table created" << endl << endl;
- int noOfTransacts = tNoOfTransInBatch*tNoOfBatchesInLoop*tNoOfThreads;
-
- /****************************************************************
- * Execute program. *
- ****************************************************************/
-
-
- for(;;) {
-
- int loopCount = tLoops + 1 ;
- ndbout << endl << "Loop # " << loopCount << endl << endl ;
-
- /****************************************************************
- * Perform inserts. *
- ****************************************************************/
-
- failed = 0 ;
-
- START_TIMER;
- execute(stInsert);
- STOP_TIMER;
- PRINT_TIMER("insert", noOfTransacts, tNoOfOpsPerTrans);
-
- if (0 < failed) {
- ndbout << failed << " of the transactions returned errors!, moving on now..."<<endl ;
- }
-
- /****************************************************************
- * Perform read. *
- ****************************************************************/
-
- failed = 0 ;
-
- START_TIMER;
- execute(stRead);
- STOP_TIMER;
- PRINT_TIMER("read", noOfTransacts, tNoOfOpsPerTrans);
-
- if (0 < failed) {
- ndbout << failed << " of the transactions returned errors!, moving on now..."<<endl ;
- }
-
-
-
- /****************************************************************
- * Perform update. *
- ***************************************************************/
-
- failed = 0 ;
-
- START_TIMER;
- execute(stUpdate);
- STOP_TIMER;
- PRINT_TIMER("update", noOfTransacts, tNoOfOpsPerTrans) ;
-
- if (0 < failed) {
- ndbout << failed << " of the transactions returned errors!, moving on now..."<<endl ;
- }
-
- /****************************************************************
- * Perform read after update.
- ****************************************************************/
-
- failed = 0 ;
-
- START_TIMER;
- execute(stRead);
- STOP_TIMER;
- PRINT_TIMER("read", noOfTransacts, tNoOfOpsPerTrans);
-
- if (0 < failed) {
- ndbout << failed << " of the transactions returned errors!, moving on now..."<<endl ;
- }
-
-
- /****************************************************************
- * Perform delete. *
- ****************************************************************/
-
- failed = 0;
-
- START_TIMER;
- execute(stDelete);
- STOP_TIMER;
- PRINT_TIMER("delete", noOfTransacts, tNoOfOpsPerTrans);
-
- if (0 < failed) {
- ndbout << failed << " of the transactions returned errors!, moving on now..."<<endl ;
- }
-
- tLoops++;
- ndbout << "--------------------------------------------------" << endl;
-
- if(tNoOfLoops != 0){
- if(tNoOfLoops <= tLoops)
- break ;
- }
- }
-
- ndbout << endl << "Benchmark completed!" << endl;
- returnValue = NDBT_OK;
-
- execute(stStop);
- void * tmp;
- for(int i = 0; i<tNoOfThreads; i++){
- NdbThread_WaitFor(threadLife[i], &tmp);
- NdbThread_Destroy(&threadLife[i]);
- }
- } else {
- ndbout << "NDB is not ready" << endl;
- ndbout << "Benchmark failed!" << endl;
- returnValue = NDBT_FAILED;
- }
-
- deleteAttributeSpace();
- delete pNdb;
-
- //printing errorCounters
- flexTimedAsynchErrorData->printErrorCounters(ndbout);
-
- return NDBT_ProgramExit(returnValue);
-}//main()
-
-////////////////////////////////////////
-
-void execute(StartType aType)
-{
- resetThreads();
- tellThreads(aType);
- waitForThreads();
-}
-
-void*
-threadLoop(void* ThreadData)
-{
- // Do work until signaled to stop.
-
- Ndb* localNdb;
- StartType tType;
- ThreadNdb* threadInfo = (ThreadNdb*)ThreadData;
- int threadNo = threadInfo->ThreadNo;
- localNdb = new Ndb("TEST_DB");
- localNdb->init(512);
- localNdb->waitUntilReady();
- threadInfo->threadBase = (threadNo * 2000000) + (tNodeId * 260000000);
-
- for (;;) {
- while (ThreadStart[threadNo] == stIdle) {
- NdbSleep_MilliSleep(10);
- }
-
- // Check if signal to exit is received
- if (ThreadStart[threadNo] == stStop) {
- break;
- }
-
- tType = ThreadStart[threadNo];
- ThreadStart[threadNo] = stIdle;
- executeThread(tType, localNdb, threadInfo);
- ThreadReady[threadNo] = 1;
- }
-
- delete localNdb;
- ThreadReady[threadNo] = 1;
-
- return NULL; // thread exits
-}
-
-void executeThread(StartType aType, Ndb* aNdbObject, ThreadNdb* threadInfo)
-{
- // Do all batch job in loop with start specified delay
- int i, j, k;
- NdbConnection* tConArray[1024];
- unsigned int tBase;
- unsigned int tBase2;
- int threadId = threadInfo->ThreadNo;
- int *getValueRowAddress = NULL;
-
- NdbTimer timer;
- timer.doStart();
-
- for (i = 0; i < tNoOfBatchesInLoop; i++) {
- //tBase = threadBase + (i * tNoOfTransInBatch * tNoOfOpsPerTrans);
- tBase = threadInfo->threadBase + (i * tNoOfTransInBatch * tNoOfOpsPerTrans);
- //tCompleted = 0;
- threadInfo->transactionCompleted = 0;
-
- for (j = 0; j < tNoOfTransInBatch; j++) {
- tBase2 = tBase + (j * tNoOfOpsPerTrans);
- tConArray[j] = aNdbObject->startTransaction();
- if ( tConArray[j] == NULL && !error_handler(aNdbObject->getNdbError())) {
- ndbout << endl << "Unable to recover! Quiting now" << endl ;
- exit (-1) ;
- return ;
- }
-
- for (k = 0; k < tNoOfOpsPerTrans; k++) {
- //-------------------------------------------------------
- // Define the operation, but do not execute it yet.
- //-------------------------------------------------------
- if(aType == stRead){
- getValueRowAddress = getAttrValueTable +
- threadId * tNoOfAttributes * tAttributeSize;
- }
- defineOperation(tConArray[j], aType, (tBase2 + k), getValueRowAddress);
- }
-
- tConArray[j]->executeAsynchPrepare(Commit, &executeCallback, threadInfo);
- }
-
- //-------------------------------------------------------
- // Now we have defined a set of transactions (= batch), it is now time
- // to execute all of them.
- //-------------------------------------------------------
- aNdbObject->sendPollNdb(3000, 0, 0);
-
- //while (tCompleted < tNoOfTransInBatch) {
- while (threadInfo->transactionCompleted < tNoOfTransInBatch) {
- aNdbObject->pollNdb(3000, 0);
- ndbout << "threadInfo->transactionCompleted = " <<
- threadInfo->transactionCompleted << endl;
- }
-
- for (j = 0 ; j < tNoOfTransInBatch ; j++) {
- aNdbObject->closeTransaction(tConArray[j]);
- }
-
- // Control the elapsed time since the last batch start.
- // Wait at least tTimeBetweenBatches milli seconds.
- timer.doStop();
- while(timer.elapsedTime() < tTimeBetweenBatches){
- NdbSleep_MilliSleep(1);
- timer.doStop();
- }
- // Ready to start new batch
- timer.doStart();
- }
- return;
-}
-
-void
-executeCallback(int result, NdbConnection* NdbObject, void* aObject)
-{
- //tCompleted++;
- ThreadNdb *threadInfo = (ThreadNdb *)aObject;
- threadInfo->transactionCompleted++;
-
- if (result == -1) {
-
- // Add complete error handling here
-
- int retCode = flexTimedAsynchErrorData->handleErrorCommon(NdbObject->getNdbError());
- if (retCode == 1) {
- if (NdbObject->getNdbError().code != 626 && NdbObject->getNdbError().code != 630){
- ndbout_c("execute: %s", NdbObject->getNdbError().message);
- ndbout_c("Error code = %d", NdbObject->getNdbError().code);}
- } else if (retCode == 2) {
- ndbout << "4115 should not happen in flexAsynch" << endl;
- } else if (retCode == 3) {
- /* What can we do here? */
- ndbout_c("execute: %s", NdbObject->getNdbError().message);
- }//if(retCode == 3)
-
- // ndbout << "Error occured in poll:" << NdbObject->getNdbError() <<
- // " ErrorCode = " << NdbObject->getNdbError() << endl;
- ndbout << "executeCallback threadInfo->transactionCompleted = " <<
- threadInfo->transactionCompleted << endl;
- failed++ ;
- return;
- }
- return;
-}
-
-void
-defineOperation(NdbConnection* localNdbConnection,
- StartType aType,
- unsigned int threadBase,
- int *pRow )
-{
- NdbOperation* localNdbOperation;
- unsigned int loopCountAttributes = tNoOfAttributes;
- unsigned int countAttributes;
- int attrValue[MAXATTRSIZE];
-
- //-------------------------------------------------------
- // Set-up the attribute values for this operation.
- //-------------------------------------------------------
- for (int k = 0; k < loopCountAttributes; k++) {
- *(int *)&attrValue[k] = (int)threadBase;
- }
- localNdbOperation = localNdbConnection->getNdbOperation(tableName[0]);
- if (localNdbOperation == NULL) {
- error_handler(localNdbOperation->getNdbError()) ;
- }
-
- switch (aType) {
- case stInsert: { // Insert case
- if (theWriteFlag == 1 && theDirtyFlag == 1) {
- localNdbOperation->dirtyWrite();
- } else if (theWriteFlag == 1) {
- localNdbOperation->writeTuple();
- } else {
- localNdbOperation->insertTuple();
- }
- break;
- }
- case stRead: { // Read Case
- if (theSimpleFlag == 1) {
- localNdbOperation->simpleRead();
- } else if (theDirtyFlag == 1) {
- localNdbOperation->dirtyRead();
- } else {
- localNdbOperation->readTuple();
- }
- break;
- }
- case stUpdate: { // Update Case
- if (theWriteFlag == 1 && theDirtyFlag == 1) {
- localNdbOperation->dirtyWrite();
- } else if (theWriteFlag == 1) {
- localNdbOperation->writeTuple();
- } else if (theDirtyFlag == 1) {
- localNdbOperation->dirtyUpdate();
- } else {
- localNdbOperation->updateTuple();
- }
- break;
- }
- case stDelete: { // Delete Case
- localNdbOperation->deleteTuple();
- break;
- }
- default: {
- error_handler(localNdbOperation->getNdbError());
- }
- }
-
- localNdbOperation->equal((char*)attrName[0],(char*)&attrValue[0]);
-
- switch (aType) {
- case stInsert: // Insert case
- case stUpdate: // Update Case
- {
- for (countAttributes = 1; countAttributes < loopCountAttributes; countAttributes++) {
- localNdbOperation->setValue( (char*)attrName[countAttributes],(char*)&attrValue[0]);
- }
- break;
- }
- case stRead: { // Read Case
- for (countAttributes = 1; countAttributes < loopCountAttributes; countAttributes++) {
- //localNdbOperation->getValue((char*)attrName[countAttributes],(char*)&attrValue[0]);
- localNdbOperation->getValue((char*)attrName[countAttributes],
- (char *) (pRow + countAttributes*tAttributeSize));
- }
- break;
- }
- case stDelete: { // Delete Case
- break;
- }
- default: {
- error_handler(localNdbOperation->getNdbError());
- }
- }
- return;
-}
-
-void readArguments(int argc, const char** argv)
-{
- int i = 1;
- while (argc > 1)
- {
- if (strcmp(argv[i], "-t") == 0)
- {
- tNoOfThreads = atoi(argv[i+1]);
- // if ((tNoOfThreads < 1) || (tNoOfThreads > NDB_MAXTHREADS))
- if ((tNoOfThreads < 1) || (tNoOfThreads > NDB_MAXTHREADS))
- exit(-1);
- }
- else if (strcmp(argv[i], "-i") == 0)
- {
- tTimeBetweenBatches = atoi(argv[i+1]);
- if (tTimeBetweenBatches < 0)
- exit(-1);
- }
- else if (strcmp(argv[i], "-p") == 0)
- {
- tNoOfTransInBatch = atoi(argv[i+1]);
- //if ((tNoOfTransInBatch < 1) || (tNoOfTransInBatch > NDB_MAXTHREADS))
- if ((tNoOfTransInBatch < 1) || (tNoOfTransInBatch > 10000))
- exit(-1);
- }
- else if (strcmp(argv[i], "-c") == 0)
- {
- tNoOfOpsPerTrans = atoi(argv[i+1]);
- if (tNoOfOpsPerTrans < 1)
- exit(-1);
- }
- else if (strcmp(argv[i], "-o") == 0)
- {
- tNoOfBatchesInLoop = atoi(argv[i+1]);
- if (tNoOfBatchesInLoop < 1)
- exit(-1);
- }
- else if (strcmp(argv[i], "-a") == 0)
- {
- tNoOfAttributes = atoi(argv[i+1]);
- if ((tNoOfAttributes < 2) || (tNoOfAttributes > MAXATTR))
- exit(-1);
- }
- else if (strcmp(argv[i], "-n") == 0)
- {
- theStdTableNameFlag = 1;
- argc++;
- i--;
- }
- else if (strcmp(argv[i], "-l") == 0)
- {
- tNoOfLoops = atoi(argv[i+1]);
- if ((tNoOfLoops < 0) || (tNoOfLoops > 100000))
- exit(-1);
- }
- else if (strcmp(argv[i], "-s") == 0)
- {
- tAttributeSize = atoi(argv[i+1]);
- if ((tAttributeSize < 1) || (tAttributeSize > MAXATTRSIZE))
- exit(-1);
- }
- else if (strcmp(argv[i], "-simple") == 0)
- {
- theSimpleFlag = 1;
- argc++;
- i--;
- }
- else if (strcmp(argv[i], "-write") == 0)
- {
- theWriteFlag = 1;
- argc++;
- i--;
- }
- else if (strcmp(argv[i], "-dirty") == 0)
- {
- theDirtyFlag = 1;
- argc++;
- i--;
- }
- else if (strcmp(argv[i], "-test") == 0)
- {
- theTestFlag = 1;
- argc++;
- i--;
- }
- else if (strcmp(argv[i], "-temp") == 0)
- {
- theTempFlag = 0; // 0 if temporary tables.
- argc++;
- i--;
- }
- else if (strcmp(argv[i], "-no_table_create") == 0)
- {
- theTableCreateFlag = 1;
- argc++;
- i--;
- }
- else
- {
- ndbout << "Arguments: " << endl;
- ndbout << "-t Number of threads to start, i.e., number of parallel loops, default 1 " << endl;
- ndbout << "-p Number of transactions in a batch, default 32 " << endl;
- ndbout << "-o Number of batches per loop, default 200 " << endl;
- ndbout << "-i Minimum time between batch starts in milli seconds, default 0 " << endl;
- ndbout << "-l Number of loops to run, default 1, 0=infinite " << endl;
- ndbout << "-a Number of attributes, default 25 " << endl;
- ndbout << "-c Number of operations per transaction, default 1 " << endl;
- ndbout << "-s Size of each attribute in 32 bit word, default 1"
- "(Primary Key is always of size 1, independent of this value) " << endl;
- ndbout << "-simple Use simple read to read from database " << endl;
- ndbout << "-dirty Use dirty read to read from database " << endl;
- ndbout << "-write Use writeTuple in insert and update " << endl;
- ndbout << "-n Use standard table names " << endl;
- ndbout << "-no_table_create Don't create tables in db " << endl;
- ndbout << "-temp Use temporary tables, no writing to disk. " << endl;
- exit(-1);
- }
-
- argc -= 2;
- i = i + 2;
- }
-}
-
-void setAttrNames()
-{
- int i;
-
- for (i = 0; i < MAXATTR ; i++)
- {
- sprintf(attrName[i], "COL%d", i);
- }
-}
-
-
-void setTableNames()
-{
- // Note! Uses only uppercase letters in table name's
- // so that we can look at the tables with SQL
- int i;
- for (i = 0; i < MAXTABLES ; i++)
- {
- if (theStdTableNameFlag==1)
- {
- sprintf(tableName[i], "TAB%d_%d", tNoOfAttributes,
- NdbTick_CurrentMillisecond()/1000);
- } else {
- sprintf(tableName[i], "TAB%d_%d", tNoOfAttributes, tAttributeSize*4);
- }
- }
-}
-
-void createTables(Ndb* pMyNdb)
-{
-
- NdbSchemaCon *MySchemaTransaction;
- NdbSchemaOp *MySchemaOp;
- int check;
-
- if (theTableCreateFlag == 0)
- {
- for(int i=0; i < 1 ;i++)
- {
- ndbout << "Creating " << tableName[i] << "..." << endl;
- MySchemaTransaction = pMyNdb->startSchemaTransaction();
-
- if( MySchemaTransaction ==
- NULL && (!error_handler(MySchemaTransaction->getNdbError())))
- exit(-1) ;/*goto error_handler; <epaulsa*/
-
- MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
- if( MySchemaOp == NULL
- && (!error_handler(MySchemaTransaction->getNdbError())))
- exit(-1) ;
-
- check = MySchemaOp->createTable( tableName[i],
- 8, // Table Size
- TupleKey, // Key Type
- 40, // Nr of Pages
- All, // FragmentType
- 6,
- 78,
- 80,
- 1, // MemoryType
- theTempFlag // 0 if temporary tables else 1
- );
-
- if ( check == -1 && (!error_handler(MySchemaTransaction->getNdbError())))
- exit(-1) ; /* epaulsa > goto error_handler; < epaulsa */
-
-
- check = MySchemaOp->createAttribute( (char*)attrName[0],
- TupleKey,
- 32,
- PKSIZE,
- UnSigned,
- MMBased,
- NotNullAttribute );
-
- if ( check == -1 &&(!error_handler(MySchemaTransaction->getNdbError())))
- exit(-1) ; /* epaulsa > goto error_handler; < epaulsa */
-
- for (int j = 1; j < tNoOfAttributes ; j++)
- {
- check = MySchemaOp->createAttribute( (char*)attrName[j],
- NoKey,
- 32,
- tAttributeSize,
- UnSigned,
- MMBased,
- NotNullAttribute );
- if ( check == -1
- && (!error_handler(MySchemaTransaction->getNdbError())))
- exit(-1) ; /* epaulsa > goto error_handler; < epaulsa */
- }
-
- if ( MySchemaTransaction->execute() == -1
- &&(!error_handler(MySchemaTransaction->getNdbError())))
- exit(-1) ; /* epaulsa > goto error_handler; < epaulsa */
-
- pMyNdb->closeSchemaTransaction(MySchemaTransaction);
- }
- }
-
- return;
-}
-
-bool error_handler(const NdbError & err) {
- ndbout << err << endl ;
- if ( 4008==err.code || 721==err.code || 266==err.code ){
- ndbout << endl << "Attempting to recover and continue now..." << endl ;
- return true ; // return true to retry
- }
- return false ; // return false to abort
-}
-
-
-//*******************************************************************************************
-
-
-
-
-
diff --git a/storage/ndb/test/ndbapi/flex_bench_mysql.cpp b/storage/ndb/test/ndbapi/flex_bench_mysql.cpp
deleted file mode 100644
index d3379b9751c..00000000000
--- a/storage/ndb/test/ndbapi/flex_bench_mysql.cpp
+++ /dev/null
@@ -1,1751 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-/* ***************************************************
-FLEXBENCH
-Perform benchmark of insert, update and delete transactions
-
-Arguments:
- -t Number of threads to start, default 1
- -o Number of operations per loop, default 500
- -l Number of loops to run, default 1, 0=infinite
- -a Number of attributes, default 25
- -c Number of tables, default 1
- -s Size of each attribute, default 1 (Primary Key is always of size 1,
- independent of this value)
- -lkn Number of long primary keys, default 1
- -lks Size of each long primary key, default 1
- -simple Use simple read to read from database
- -dirty Use dirty read to read from database
- -write Use writeTuple in insert and update
- -stdtables Use standard table names
- -no_table_create Don't create tables in db
- -sleep Sleep a number of seconds before running the test, this
- can be used so that another flexBench have time to create tables
- -temp Use tables without logging
- -verify Verify inserts, updates and deletes
- -use_ndb Use NDB API, otherwise use mysql client
-#ifdef CEBIT_STAT
- -statserv host:port statistics server to report to
- -statfreq ops report every ops operations (default 100)
-#endif
- Returns:
- 0 - Test passed
- 1 - Test failed
- 2 - Invalid arguments
-
-* *************************************************** */
-
-#define USE_MYSQL
-#ifdef USE_MYSQL
-#include <mysql.h>
-#endif
-
-#include "NdbApi.hpp"
-
-#include <NdbMain.h>
-#include <NdbOut.hpp>
-#include <NdbSleep.h>
-#include <NdbTick.h>
-#include <NdbTimer.hpp>
-#include <NdbThread.h>
-#include <NdbAutoPtr.hpp>
-
-#include <NdbTest.hpp>
-
-#define MAXSTRLEN 16
-#define MAXATTR 64
-#define MAXTABLES 128
-#define MAXATTRSIZE 1000
-#define MAXNOLONGKEY 16 // Max number of long keys.
-#define MAXLONGKEYTOTALSIZE 1023 // words = 4092 bytes
-
-extern "C" { static void* flexBenchThread(void*); }
-static int readArguments(int argc, const char** argv);
-#ifdef USE_MYSQL
-static int createTables(MYSQL*);
-static int dropTables(MYSQL*);
-#endif
-static int createTables(Ndb*);
-static void sleepBeforeStartingTest(int seconds);
-static void input_error();
-
-enum StartType {
- stIdle,
- stInsert,
- stVerify,
- stRead,
- stUpdate,
- stDelete,
- stTryDelete,
- stVerifyDelete,
- stStop
-};
-
-struct ThreadData
-{
- int threadNo;
- NdbThread* threadLife;
- int threadReady;
- StartType threadStart;
- int threadResult;
-};
-
-static int tNodeId = 0 ;
-static char tableName[MAXTABLES][MAXSTRLEN+1];
-static char attrName[MAXATTR][MAXSTRLEN+1];
-static char** longKeyAttrName;
-
-// Program Parameters
-static int tNoOfLoops = 1;
-static int tAttributeSize = 1;
-static unsigned int tNoOfThreads = 1;
-static unsigned int tNoOfTables = 1;
-static unsigned int tNoOfAttributes = 25;
-static unsigned int tNoOfOperations = 500;
-static unsigned int tSleepTime = 0;
-static unsigned int tNoOfLongPK = 1;
-static unsigned int tSizeOfLongPK = 1;
-static unsigned int t_instances = 1;
-
-//Program Flags
-static int theSimpleFlag = 0;
-static int theDirtyFlag = 0;
-static int theWriteFlag = 0;
-static int theStdTableNameFlag = 0;
-static int theTableCreateFlag = 0;
-static bool theTempTable = false;
-static bool VerifyFlag = true;
-static bool useLongKeys = false;
-static bool verbose = false;
-#ifdef USE_MYSQL
-static bool use_ndb = false;
-static int engine_id = 0;
-static int sockets[16];
-static int n_sockets = 0;
-static char* engine[] =
- {
- " ENGINE = NDBCLUSTER ", // use default engine
- " ENGINE = MEMORY ",
- " ENGINE = MYISAM ",
- " ENGINE = INNODB "
- };
-#else
-static bool use_ndb = true;
-#endif
-
-static ErrorData theErrorData; // Part of flexBench-program
-
-#define START_TIMER { NdbTimer timer; timer.doStart();
-#define STOP_TIMER timer.doStop();
-#define PRINT_TIMER(text, trans, opertrans) timer.printTransactionStatistics(text, trans, opertrans); };
-
-#include <NdbTCP.h>
-
-#ifdef CEBIT_STAT
-#include <NdbMutex.h>
-static bool statEnable = false;
-static char statHost[100];
-static int statFreq = 100;
-static int statPort = 0;
-static int statSock = -1;
-static enum { statError = -1, statClosed, statOpen } statState;
-static NdbMutex statMutex = NDB_MUTEX_INITIALIZER;
-#endif
-
-//-------------------------------------------------------------------
-// Statistical Reporting routines
-//-------------------------------------------------------------------
-#ifdef CEBIT_STAT
-// Experimental client-side statistic for CeBIT
-
-static void
-statReport(enum StartType st, int ops)
-{
- if (!statEnable)
- return;
- if (NdbMutex_Lock(&statMutex) < 0) {
- if (statState != statError) {
- ndbout_c("stat: lock mutex failed: %s", strerror(errno));
- statState = statError;
- }
- return;
- }
- static int nodeid;
- // open connection
- if (statState != statOpen) {
- char *p = getenv("NDB_NODEID"); // ndbnet sets NDB_NODEID
- nodeid = p == 0 ? 0 : atoi(p);
- if ((statSock = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
- if (statState != statError) {
- ndbout_c("stat: create socket failed: %s", strerror(errno));
- statState = statError;
- }
- (void)NdbMutex_Unlock(&statMutex);
- return;
- }
- struct sockaddr_in saddr;
- memset(&saddr, 0, sizeof(saddr));
- saddr.sin_family = AF_INET;
- saddr.sin_port = htons(statPort);
- if (Ndb_getInAddr(&saddr.sin_addr, statHost) < 0) {
- if (statState != statError) {
- ndbout_c("stat: host %s not found", statHost);
- statState = statError;
- }
- (void)close(statSock);
- (void)NdbMutex_Unlock(&statMutex);
- return;
- }
- if (connect(statSock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
- if (statState != statError) {
- ndbout_c("stat: connect failed: %s", strerror(errno));
- statState = statError;
- }
- (void)close(statSock);
- (void)NdbMutex_Unlock(&statMutex);
- return;
- }
- statState = statOpen;
- ndbout_c("stat: connection to %s:%d opened", statHost, (int)statPort);
- }
- const char *text;
- switch (st) {
- case stInsert:
- text = "insert";
- break;
- case stVerify:
- text = "verify";
- break;
- case stRead:
- text = "read";
- break;
- case stUpdate:
- text = "update";
- break;
- case stDelete:
- text = "delete";
- break;
- case stVerifyDelete:
- text = "verifydelete";
- break;
- default:
- text = "unknown";
- break;
- }
- char buf[100];
- sprintf(buf, "%d %s %d\n", nodeid, text, ops);
- int len = strlen(buf);
- // assume SIGPIPE already ignored
- if (write(statSock, buf, len) != len) {
- if (statState != statError) {
- ndbout_c("stat: write failed: %s", strerror(errno));
- statState = statError;
- }
- (void)close(statSock);
- (void)NdbMutex_Unlock(&statMutex);
- return;
- }
- (void)NdbMutex_Unlock(&statMutex);
-}
-#endif // CEBIT_STAT
-
-static void
-resetThreads(ThreadData* pt){
- for (unsigned int i = 0; i < tNoOfThreads; i++){
- pt[i].threadReady = 0;
- pt[i].threadResult = 0;
- pt[i].threadStart = stIdle;
- }
-}
-
-static int
-checkThreadResults(ThreadData* pt){
- for (unsigned int i = 0; i < tNoOfThreads; i++){
- if(pt[i].threadResult != 0){
- ndbout_c("Thread%d reported fatal error %d", i, pt[i].threadResult);
- return -1;
- }
- }
- return 0;
-}
-
-static
-void
-waitForThreads(ThreadData* pt)
-{
- int cont = 1;
- while (cont){
- NdbSleep_MilliSleep(100);
- cont = 0;
- for (unsigned int i = 0; i < tNoOfThreads; i++){
- if (pt[i].threadReady == 0)
- cont = 1;
- }
- }
-}
-
-static void
-tellThreads(ThreadData* pt, StartType what)
-{
- for (unsigned int i = 0; i < tNoOfThreads; i++)
- pt[i].threadStart = what;
-}
-
-NDB_COMMAND(flexBench, "flexBench", "flexBench", "flexbench", 65535)
-{
- ndb_init();
- ThreadData* pThreadsData;
- int tLoops = 0;
- int returnValue = NDBT_OK;
- if (readArguments(argc, argv) != 0){
- input_error();
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
- NdbAutoPtr<char> p10;
- if(useLongKeys){
- int e1 = sizeof(char*) * tNoOfLongPK;
- int e2_1 = strlen("KEYATTR ") + 1;
- int e2 = e2_1 * tNoOfLongPK;
- char *tmp = (char *) malloc(e1 + e2);
- p10.reset(tmp);
- longKeyAttrName = (char **) tmp;
- tmp += e1;
- for (Uint32 i = 0; i < tNoOfLongPK; i++) {
- // longKeyAttrName[i] = (char *) malloc(strlen("KEYATTR ") + 1);
- longKeyAttrName[i] = tmp;
- tmp += e2_1;
- memset(longKeyAttrName[i], 0, e2_1);
- sprintf(longKeyAttrName[i], "KEYATTR%i", i);
- }
- }
-
- NdbAutoObjArrayPtr<ThreadData>
- p12( pThreadsData = new ThreadData[tNoOfThreads] );
-
-
- ndbout << endl << "FLEXBENCH - Starting normal mode" << endl;
- ndbout << "Perform benchmark of insert, update and delete transactions"<< endl;
- ndbout << " " << tNoOfThreads << " thread(s) " << endl;
- ndbout << " " << tNoOfLoops << " iterations " << endl;
- ndbout << " " << tNoOfTables << " table(s) and " << 1 << " operation(s) per transaction " <<endl;
- ndbout << " " << tNoOfAttributes << " attributes per table " << endl;
- ndbout << " " << tNoOfOperations << " transaction(s) per thread and round " << endl;
- ndbout << " " << tAttributeSize << " is the number of 32 bit words per attribute "<< endl;
- ndbout << " " << "Table(s) without logging: " << (Uint32)theTempTable << endl;
-
- if(useLongKeys)
- ndbout << " " << "Using long keys with " << tNoOfLongPK << " keys a' " <<
- tSizeOfLongPK * 4 << " bytes each." << endl;
-
- ndbout << " " << "Verification is " ;
- if(VerifyFlag) {
- ndbout << "enabled" << endl ;
- }else{
- ndbout << "disabled" << endl ;
- }
- if (use_ndb) {
- ndbout << "Use NDB API with NdbPool in this test case" << endl;
- ndbout << "Pool size = " << t_instances << endl;
- } else {
- ndbout << "Use mysql client with " << engine[engine_id];
- ndbout << " as engine" << endl;
- }
- theErrorData.printSettings(ndbout);
-
- NdbThread_SetConcurrencyLevel(tNoOfThreads + 2);
-
-#ifdef USE_MYSQL
- MYSQL mysql;
- if (!use_ndb) {
- if ( mysql_thread_safe() == 0 ) {
- ndbout << "Not thread safe mysql library..." << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- ndbout << "Connecting to MySQL..." <<endl;
-
- mysql_init(&mysql);
- {
- int the_socket = sockets[0];
- char the_socket_name[1024];
- sprintf(the_socket_name, "%s%u%s", "/tmp/mysql.",the_socket,".sock");
- // sprintf(the_socket_name, "%s", "/tmp/mysql.sock");
- ndbout << the_socket_name << endl;
- if ( mysql_real_connect(&mysql,
- "localhost",
- "root",
- "",
- "test",
- the_socket,
- the_socket_name,
- 0) == NULL ) {
- ndbout << "Connect failed" <<endl;
- returnValue = NDBT_FAILED;
- }
- mysql.reconnect= 1;
- }
- if(returnValue == NDBT_OK){
- mysql_set_server_option(&mysql, MYSQL_OPTION_MULTI_STATEMENTS_ON);
- if (createTables(&mysql) != 0){
- returnValue = NDBT_FAILED;
- }
- }
- }
-#endif
- if (use_ndb) {
- Uint32 ndb_id = 0;
- if (!create_instance(t_instances, 1, t_instances)) {
- ndbout << "Creation of the NdbPool failed" << endl;
- returnValue = NDBT_FAILED;
- } else {
- Ndb* pNdb = get_ndb_object(ndb_id, "test", "def");
- if (pNdb == NULL) {
- ndbout << "Failed to get a NDB object" << endl;
- returnValue = NDBT_FAILED;
- } else {
- tNodeId = pNdb->getNodeId();
- ndbout << " NdbAPI node with id = " << tNodeId << endl;
- ndbout << endl;
-
- ndbout << "Waiting for ndb to become ready..." <<endl;
- if (pNdb->waitUntilReady(2000) != 0){
- ndbout << "NDB is not ready" << endl;
- ndbout << "Benchmark failed!" << endl;
- returnValue = NDBT_FAILED;
- }
- if(returnValue == NDBT_OK){
- if (createTables(pNdb) != 0){
- returnValue = NDBT_FAILED;
- }
- }
- return_ndb_object(pNdb, ndb_id);
- }
- }
- }
- if(returnValue == NDBT_OK){
-
- sleepBeforeStartingTest(tSleepTime);
-
- /****************************************************************
- * Create threads. *
- ****************************************************************/
- resetThreads(pThreadsData);
-
- for (unsigned int i = 0; i < tNoOfThreads; i++){
- pThreadsData[i].threadNo = i;
- pThreadsData[i].threadLife = NdbThread_Create(flexBenchThread,
- (void**)&pThreadsData[i],
- 32768,
- "flexBenchThread",
- NDB_THREAD_PRIO_LOW);
- }
-
- waitForThreads(pThreadsData);
-
- ndbout << endl << "All threads started" << endl << endl;
-
- /****************************************************************
- * Execute program. *
- ****************************************************************/
-
- for(;;){
-
- int loopCount = tLoops + 1;
- ndbout << endl << "Loop # " << loopCount << endl << endl;
-
- /****************************************************************
- * Perform inserts. *
- ****************************************************************/
- // Reset and start timer
- START_TIMER;
- // Give insert-command to all threads
- resetThreads(pThreadsData);
- tellThreads(pThreadsData, stInsert);
- waitForThreads(pThreadsData);
- if (checkThreadResults(pThreadsData) != 0){
- ndbout << "Error: Threads failed in performing insert" << endl;
- returnValue = NDBT_FAILED;
- break;
- }
- // stop timer and print results.
- STOP_TIMER;
- PRINT_TIMER("insert", tNoOfOperations*tNoOfThreads, tNoOfTables);
- /****************************************************************
- * Verify inserts. *
- ****************************************************************/
- if (VerifyFlag) {
- resetThreads(pThreadsData);
- ndbout << "Verifying inserts...\t" ;
- tellThreads(pThreadsData, stVerify);
- waitForThreads(pThreadsData);
- if (checkThreadResults(pThreadsData) != 0){
- ndbout << "Error: Threads failed while verifying inserts" << endl;
- returnValue = NDBT_FAILED;
- break;
- }else{
- ndbout << "\t\tOK" << endl << endl ;
- }
- }
-
- /****************************************************************
- * Perform read. *
- ****************************************************************/
- // Reset and start timer
- START_TIMER;
- // Give read-command to all threads
- resetThreads(pThreadsData);
- tellThreads(pThreadsData, stRead);
- waitForThreads(pThreadsData);
- if (checkThreadResults(pThreadsData) != 0){
- ndbout << "Error: Threads failed in performing read" << endl;
- returnValue = NDBT_FAILED;
- break;
- }
- // stop timer and print results.
- STOP_TIMER;
- PRINT_TIMER("read", tNoOfOperations*tNoOfThreads, tNoOfTables);
-
- /****************************************************************
- * Perform update. *
- ****************************************************************/
- // Reset and start timer
- START_TIMER;
- // Give update-command to all threads
- resetThreads(pThreadsData);
- tellThreads(pThreadsData, stUpdate);
- waitForThreads(pThreadsData);
- if (checkThreadResults(pThreadsData) != 0){
- ndbout << "Error: Threads failed in performing update" << endl;
- returnValue = NDBT_FAILED;
- break;
- }
- // stop timer and print results.
- STOP_TIMER;
- PRINT_TIMER("update", tNoOfOperations*tNoOfThreads, tNoOfTables);
-
- /****************************************************************
- * Verify updates. *
- ****************************************************************/
- if (VerifyFlag) {
- resetThreads(pThreadsData);
- ndbout << "Verifying updates...\t" ;
- tellThreads(pThreadsData, stVerify);
- waitForThreads(pThreadsData);
- if (checkThreadResults(pThreadsData) != 0){
- ndbout << "Error: Threads failed while verifying updates" << endl;
- returnValue = NDBT_FAILED;
- break;
- }else{
- ndbout << "\t\tOK" << endl << endl ;
- }
- }
-
- /****************************************************************
- * Perform read. *
- ****************************************************************/
- // Reset and start timer
- START_TIMER;
- // Give read-command to all threads
- resetThreads(pThreadsData);
- tellThreads(pThreadsData, stRead);
- waitForThreads(pThreadsData);
- if (checkThreadResults(pThreadsData) != 0){
- ndbout << "Error: Threads failed in performing read" << endl;
- returnValue = NDBT_FAILED;
- break;
- }
- // stop timer and print results.
- STOP_TIMER;
- PRINT_TIMER("read", tNoOfOperations*tNoOfThreads, tNoOfTables);
-
- /****************************************************************
- * Perform delete. *
- ****************************************************************/
- // Reset and start timer
- START_TIMER;
- // Give delete-command to all threads
- resetThreads(pThreadsData);
- tellThreads(pThreadsData, stDelete);
- waitForThreads(pThreadsData);
- if (checkThreadResults(pThreadsData) != 0){
- ndbout << "Error: Threads failed in performing delete" << endl;
- returnValue = NDBT_FAILED;
- break;
- }
- // stop timer and print results.
- STOP_TIMER;
- PRINT_TIMER("delete", tNoOfOperations*tNoOfThreads, tNoOfTables);
-
- /****************************************************************
- * Verify deletes. *
- ****************************************************************/
- if (VerifyFlag) {
- resetThreads(pThreadsData);
- ndbout << "Verifying tuple deletion..." ;
- tellThreads(pThreadsData, stVerifyDelete);
- waitForThreads(pThreadsData);
- if (checkThreadResults(pThreadsData) != 0){
- ndbout << "Error: Threads failed in verifying deletes" << endl;
- returnValue = NDBT_FAILED;
- break;
- }else{
- ndbout << "\t\tOK" << endl << endl ;
- }
- }
-
- ndbout << "--------------------------------------------------" << endl;
-
- tLoops++;
-
- if ( 0 != tNoOfLoops && tNoOfLoops <= tLoops )
- break;
- theErrorData.printErrorCounters();
- }
-
- resetThreads(pThreadsData);
- tellThreads(pThreadsData, stStop);
- waitForThreads(pThreadsData);
-
- void * tmp;
- for(Uint32 i = 0; i<tNoOfThreads; i++){
- NdbThread_WaitFor(pThreadsData[i].threadLife, &tmp);
- NdbThread_Destroy(&pThreadsData[i].threadLife);
- }
- }
-#ifdef USE_MYSQL
- if (!use_ndb) {
- dropTables(&mysql);
- mysql_close(&mysql);
- }
-#endif
- if (use_ndb) {
- drop_instance();
- }
- theErrorData.printErrorCounters();
- return NDBT_ProgramExit(returnValue);
-}
-////////////////////////////////////////
-
-
-unsigned long get_hash(unsigned long * hash_key, int len)
-{
- unsigned long hash_value = 147;
- unsigned h_key;
- int i;
- for (i = 0; i < len; i++)
- {
- h_key = hash_key[i];
- hash_value = (hash_value << 5) + hash_value + (h_key & 255);
- hash_value = (hash_value << 5) + hash_value + ((h_key >> 8) & 255);
- hash_value = (hash_value << 5) + hash_value + ((h_key >> 16) & 255);
- hash_value = (hash_value << 5) + hash_value + ((h_key >> 24) & 255);
- }
- return hash_value;
-}
-
-// End of warming up phase
-
-
-
-static void* flexBenchThread(void* pArg)
-{
- ThreadData* pThreadData = (ThreadData*)pArg;
- unsigned int threadNo, threadBase;
- Ndb* pNdb = NULL ;
- Uint32 ndb_id = 0;
- NdbConnection *pTrans = NULL ;
- NdbOperation** pOps = NULL ;
- StartType tType ;
- StartType tSaveType ;
- NdbRecAttr* tTmp = NULL ;
- int* attrValue = NULL ;
- int* attrRefValue = NULL ;
- int check = 0 ;
- int loopCountOps, loopCountTables, loopCountAttributes;
- int tAttemptNo = 0;
- int tRetryAttempts = 20;
- int tResult = 0;
- int tSpecialTrans = 0;
- int nRefLocalOpOffset = 0 ;
- int nReadBuffSize =
- tNoOfTables * tNoOfAttributes * sizeof(int) * tAttributeSize ;
- int nRefBuffSize =
- tNoOfOperations * tNoOfAttributes * sizeof(int) * tAttributeSize ;
- unsigned*** longKeyAttrValue = NULL;
-
-
- threadNo = pThreadData->threadNo ;
-
-#ifdef USE_MYSQL
- MYSQL mysql;
- int the_socket = sockets[threadNo % n_sockets];
- char the_socket_name[1024];
- //sprintf(the_socket_name, "%s", "/tmp/mysql.sock");
- sprintf(the_socket_name, "%s%u%s", "/tmp/mysql.",the_socket,".sock");
- if (!use_ndb) {
- ndbout << the_socket_name << endl;
- ndbout << "Thread connecting to MySQL... " << endl;
- mysql_init(&mysql);
-
- if ( mysql_real_connect(&mysql,
- "localhost",
- "root",
- "",
- "test",
- the_socket,
- the_socket_name,
- 0) == NULL ) {
- ndbout << "failed" << endl;
- return 0;
- }
- mysql.reconnect= 1;
- ndbout << "ok" << endl;
-
- int r;
- if (tNoOfTables > 1)
- r = mysql_autocommit(&mysql, 0);
- else
- r = mysql_autocommit(&mysql, 1);
-
- if (r) {
- ndbout << "autocommit on/off failed" << endl;
- return 0;
- }
- }
-#endif
-
- NdbAutoPtr<int> p00( attrValue= (int*)malloc(nReadBuffSize) ) ;
- NdbAutoPtr<int> p01( attrRefValue= (int*)malloc(nRefBuffSize) );
- if (use_ndb) {
- pOps = (NdbOperation**)malloc(tNoOfTables*sizeof(NdbOperation*)) ;
- }
- NdbAutoPtr<NdbOperation*> p02( pOps );
-
- if( !attrValue || !attrRefValue ||
- ( use_ndb && ( !pOps) ) ){
- // Check allocations to make sure we got all the memory we asked for
- ndbout << "One or more memory allocations failed when starting thread #";
- ndbout << threadNo << endl ;
- ndbout << "Thread #" << threadNo << " will now exit" << endl ;
- tResult = 13 ;
- return 0;
- }
-
- if (use_ndb) {
- pNdb = get_ndb_object(ndb_id, "test", "def");
- if (pNdb == NULL) {
- ndbout << "Failed to get an NDB object" << endl;
- ndbout << "Thread #" << threadNo << " will now exit" << endl ;
- tResult = 13;
- return 0;
- }
- pNdb->waitUntilReady();
- return_ndb_object(pNdb, ndb_id);
- pNdb = NULL;
- }
-
- // To make sure that two different threads doesn't operate on the same record
- // Calculate an "unique" number to use as primary key
- threadBase = (threadNo * 2000000) + (tNodeId * 260000000);
-
- NdbAutoPtr<char> p22;
- if(useLongKeys){
- // Allocate and populate the longkey array.
- int e1 = sizeof(unsigned**) * tNoOfOperations;
- int e2 = sizeof(unsigned*) * tNoOfLongPK * tNoOfOperations;
- int e3 = sizeof(unsigned) * tSizeOfLongPK * tNoOfLongPK * tNoOfOperations;
- char* tmp;
- p22.reset(tmp = (char*)malloc(e1+e2+e3));
-
- longKeyAttrValue = (unsigned ***) tmp;
- tmp += e1;
- for (Uint32 n = 0; n < tNoOfOperations; n++) {
- longKeyAttrValue[n] = (unsigned **) tmp;
- tmp += sizeof(unsigned*) * tNoOfLongPK;
- }
-
- for (Uint32 n = 0; n < tNoOfOperations; n++){
- for (Uint32 i = 0; i < tNoOfLongPK ; i++) {
- longKeyAttrValue[n][i] = (unsigned *) tmp;
- tmp += sizeof(unsigned) * tSizeOfLongPK;
- memset(longKeyAttrValue[n][i], 0, sizeof(unsigned) * tSizeOfLongPK);
- for(Uint32 j = 0; j < tSizeOfLongPK; j++) {
- // Repeat the unique value to fill up the long key.
- longKeyAttrValue[n][i][j] = threadBase + n;
- }
- }
- }
- }
-
- int nRefOpOffset = 0 ;
- //Assign reference attribute values to memory
- for(Uint32 ops = 1 ; ops < tNoOfOperations ; ops++){
- // Calculate offset value before going into the next loop
- nRefOpOffset = tAttributeSize*tNoOfAttributes*(ops-1) ;
- for(Uint32 a = 0 ; a < tNoOfAttributes ; a++){
- *(int*)&attrRefValue[nRefOpOffset + tAttributeSize*a] =
- (int)(threadBase + ops + a) ;
- }
- }
-
-#ifdef CEBIT_STAT
- // ops not yet reported
- int statOps = 0;
-#endif
-
-#ifdef USE_MYSQL
- // temporary buffer to store prepared statement text
- char buf[2048];
- MYSQL_STMT** prep_read = NULL;
- MYSQL_STMT** prep_delete = NULL;
- MYSQL_STMT** prep_update = NULL;
- MYSQL_STMT** prep_insert = NULL;
- MYSQL_BIND* bind_delete = NULL;
- MYSQL_BIND* bind_read = NULL;
- MYSQL_BIND* bind_update = NULL;
- MYSQL_BIND* bind_insert = NULL;
- int* mysql_data = NULL;
-
- NdbAutoPtr<char> p21;
-
- if (!use_ndb) {
- // data array to which prepared statements are bound
- char* tmp;
- int e1 = sizeof(int)*tAttributeSize*tNoOfAttributes;
- int e2 = sizeof(MYSQL_BIND)*tNoOfAttributes;
- int e3 = sizeof(MYSQL_BIND)*tNoOfAttributes;
- int e4 = sizeof(MYSQL_BIND)*tNoOfAttributes;
- int e5 = sizeof(MYSQL_BIND)*1;
- int e6 = sizeof(MYSQL_STMT*)*tNoOfTables;
- int e7 = sizeof(MYSQL_STMT*)*tNoOfTables;
- int e8 = sizeof(MYSQL_STMT*)*tNoOfTables;
- int e9 = sizeof(MYSQL_STMT*)*tNoOfTables;
- p21.reset(tmp = (char*)malloc(e1+e2+e3+e4+e5+e6+e7+e8+e9));
-
- mysql_data = (int*)tmp; tmp += e1;
- bind_insert = (MYSQL_BIND*)tmp; tmp += e2;
- bind_update = (MYSQL_BIND*)tmp; tmp += e3;
- bind_read = (MYSQL_BIND*)tmp; tmp += e4;
- bind_delete = (MYSQL_BIND*)tmp; tmp += e5;
- prep_insert = (MYSQL_STMT**)tmp; tmp += e6;
- prep_update = (MYSQL_STMT**)tmp; tmp += e7;
- prep_read = (MYSQL_STMT**)tmp; tmp += e8;
- prep_delete = (MYSQL_STMT**)tmp;
-
- for (Uint32 ca = 0; ca < tNoOfAttributes; ca++){
- MYSQL_BIND& bi = bind_insert[ca];
- bi.buffer_type = MYSQL_TYPE_LONG;
- bi.buffer = (char*)&mysql_data[ca*tAttributeSize];
- bi.buffer_length = 0;
- bi.length = NULL;
- bi.is_null = NULL;
- }//for
-
- for (Uint32 ca = 0; ca < tNoOfAttributes; ca++){
- MYSQL_BIND& bi = bind_update[ca];
- bi.buffer_type = MYSQL_TYPE_LONG;
- if ( ca == tNoOfAttributes-1 ) // the primary key comes last in statement
- bi.buffer = (char*)&mysql_data[0];
- else
- bi.buffer = (char*)&mysql_data[(ca+1)*tAttributeSize];
- bi.buffer_length = 0;
- bi.length = NULL;
- bi.is_null = NULL;
- }//for
-
- for (Uint32 ca = 0; ca < tNoOfAttributes; ca++){
- MYSQL_BIND& bi = bind_read[ca];
- bi.buffer_type = MYSQL_TYPE_LONG;
- bi.buffer = (char*)&mysql_data[ca*tAttributeSize];
- bi.buffer_length = 4;
- bi.length = NULL;
- bi.is_null = NULL;
- }//for
-
- for (Uint32 ca = 0; ca < 1; ca++){
- MYSQL_BIND& bi = bind_delete[ca];
- bi.buffer_type = MYSQL_TYPE_LONG;
- bi.buffer = (char*)&mysql_data[ca*tAttributeSize];
- bi.buffer_length = 0;
- bi.length = NULL;
- bi.is_null = NULL;
- }//for
-
- for (Uint32 i = 0; i < tNoOfTables; i++) {
- int pos = 0;
- pos += sprintf(buf+pos, "%s%s%s",
- "INSERT INTO ",
- tableName[i],
- " VALUES(");
- pos += sprintf(buf+pos, "%s", "?");
- for (Uint32 j = 1; j < tNoOfAttributes; j++) {
- pos += sprintf(buf+pos, "%s", ",?");
- }
- pos += sprintf(buf+pos, "%s", ")");
- if (verbose)
- ndbout << buf << endl;
- prep_insert[i] = mysql_prepare(&mysql, buf, pos);
- if (prep_insert[i] == 0) {
- ndbout << "mysql_prepare: " << mysql_error(&mysql) << endl;
- return 0;
- }
- if (mysql_bind_param(prep_insert[i], bind_insert)) {
- ndbout << "mysql_bind_param: " << mysql_error(&mysql) << endl;
- return 0;
- }
- }
-
- for (Uint32 i = 0; i < tNoOfTables; i++) {
- int pos = 0;
- pos += sprintf(buf+pos, "%s%s%s",
- "UPDATE ",
- tableName[i],
- " SET ");
- for (Uint32 j = 1; j < tNoOfAttributes; j++) {
- if (j != 1)
- pos += sprintf(buf+pos, "%s", ",");
- pos += sprintf(buf+pos, "%s%s", attrName[j],"=?");
- }
- pos += sprintf(buf+pos, "%s%s%s", " WHERE ", attrName[0], "=?");
-
- if (verbose)
- ndbout << buf << endl;
- prep_update[i] = mysql_prepare(&mysql, buf, pos);
- if (prep_update[i] == 0) {
- ndbout << "mysql_prepare: " << mysql_error(&mysql) << endl;
- return 0;
- }
- if (mysql_bind_param(prep_update[i], bind_update)) {
- ndbout << "mysql_bind_param: " << mysql_error(&mysql) << endl;
- return 0;
- }
- }
-
- for (Uint32 i = 0; i < tNoOfTables; i++) {
- int pos = 0;
- pos += sprintf(buf+pos, "%s", "SELECT ");
- for (Uint32 j = 1; j < tNoOfAttributes; j++) {
- if (j != 1)
- pos += sprintf(buf+pos, "%s", ",");
- pos += sprintf(buf+pos, "%s", attrName[j]);
- }
- pos += sprintf(buf+pos, "%s%s%s%s%s",
- " FROM ",
- tableName[i],
- " WHERE ",
- attrName[0],
- "=?");
- if (verbose)
- ndbout << buf << endl;
- prep_read[i] = mysql_prepare(&mysql, buf, pos);
- if (prep_read[i] == 0) {
- ndbout << "mysql_prepare: " << mysql_error(&mysql) << endl;
- return 0;
- }
- if (mysql_bind_param(prep_read[i], bind_read)) {
- ndbout << "mysql_bind_param: " << mysql_error(&mysql) << endl;
- return 0;
- }
- if (mysql_bind_result(prep_read[i], &bind_read[1])) {
- ndbout << "mysql_bind_result: " << mysql_error(&mysql) << endl;
- return 0;
- }
- }
-
- for (Uint32 i = 0; i < tNoOfTables; i++) {
- int pos = 0;
- pos += sprintf(buf+pos, "%s%s%s%s%s",
- "DELETE FROM ",
- tableName[i],
- " WHERE ",
- attrName[0],
- "=?");
- if (verbose)
- ndbout << buf << endl;
- prep_delete[i] = mysql_prepare(&mysql, buf, pos);
- if (prep_delete[i] == 0) {
- ndbout << "mysql_prepare: " << mysql_error(&mysql) << endl;
- return 0;
- }
- if (mysql_bind_param(prep_delete[i], bind_delete)) {
- ndbout << "mysql_bind_param: " << mysql_error(&mysql) << endl;
- return 0;
- }
- }
- }
-#endif
-
- for (;;) {
- pThreadData->threadResult = tResult; // Report error to main thread,
- // normally tResult is set to 0
- pThreadData->threadReady = 1;
-
- while (pThreadData->threadStart == stIdle){
- NdbSleep_MilliSleep(100);
- }//while
-
- // Check if signal to exit is received
- if (pThreadData->threadStart == stStop){
- pThreadData->threadReady = 1;
- // ndbout_c("Thread%d is stopping", threadNo);
- // In order to stop this thread, the main thread has signaled
- // stStop, break out of the for loop so that destructors
- // and the proper exit functions are called
- break;
- }//if
-
- tType = pThreadData->threadStart;
- tSaveType = tType;
- pThreadData->threadStart = stIdle;
-
- // Start transaction, type of transaction
- // is received in the array ThreadStart
- loopCountOps = tNoOfOperations;
- loopCountTables = tNoOfTables;
- loopCountAttributes = tNoOfAttributes;
- for (int count = 1; count < loopCountOps && tResult == 0;){
-
- if (use_ndb) {
- pNdb = get_ndb_object(ndb_id, "test", "def");
- if (pNdb == NULL) {
- ndbout << "Could not get Ndb object in thread" << threadNo;
- ndbout << endl;
- tResult = 1; //Indicate fatal error
- break;
- }
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- // This is a fatal error, abort program
- ndbout << "Could not start transaction in thread" << threadNo;
- ndbout << endl;
- ndbout << pNdb->getNdbError() << endl;
- tResult = 1; // Indicate fatal error
- break; // Break out of for loop
- }
- }
-
- // Calculate the current operation offset in the reference array
- nRefLocalOpOffset = tAttributeSize*tNoOfAttributes*(count - 1) ;
- int* tmpAttrRefValue = attrRefValue + nRefLocalOpOffset;
-
- for (int countTables = 0;
- countTables < loopCountTables && tResult == 0;
- countTables++) {
-
- int nTableOffset = tAttributeSize *
- loopCountAttributes *
- countTables ;
-
- int* tmpAttrValue = attrValue + nTableOffset;
-
- if (use_ndb) {
- pOps[countTables] = pTrans->getNdbOperation(tableName[countTables]);
- if (pOps[countTables] == NULL) {
- // This is a fatal error, abort program
- ndbout << "getNdbOperation: " << pTrans->getNdbError();
- tResult = 2; // Indicate fatal error
- break;
- }//if
-
- switch (tType) {
- case stInsert: // Insert case
- if (theWriteFlag == 1 && theDirtyFlag == 1)
- pOps[countTables]->dirtyWrite();
- else if (theWriteFlag == 1)
- pOps[countTables]->writeTuple();
- else
- pOps[countTables]->insertTuple();
- break;
- case stRead: // Read Case
- if (theSimpleFlag == 1)
- pOps[countTables]->simpleRead();
- else if (theDirtyFlag == 1)
- pOps[countTables]->dirtyRead();
- else
- pOps[countTables]->readTuple();
- break;
- case stUpdate: // Update Case
- if (theWriteFlag == 1 && theDirtyFlag == 1)
- pOps[countTables]->dirtyWrite();
- else if (theWriteFlag == 1)
- pOps[countTables]->writeTuple();
- else if (theDirtyFlag == 1)
- pOps[countTables]->dirtyUpdate();
- else
- pOps[countTables]->updateTuple();
- break;
- case stDelete: // Delete Case
- pOps[countTables]->deleteTuple();
- break;
- case stVerify:
- pOps[countTables]->readTuple();
- break;
- case stVerifyDelete:
- pOps[countTables]->readTuple();
- break;
- default:
- assert(false);
- }//switch
-
- if(useLongKeys){
- // Loop the equal call so the complete key is send to the kernel.
- for(Uint32 i = 0; i < tNoOfLongPK; i++)
- pOps[countTables]->equal(longKeyAttrName[i],
- (char *)longKeyAttrValue[count - 1][i],
- tSizeOfLongPK*4);
- }
- else
- pOps[countTables]->equal((char*)attrName[0],
- (char*)&tmpAttrRefValue[0]);
-
- if (tType == stInsert) {
- for (int ca = 1; ca < loopCountAttributes; ca++){
- pOps[countTables]->setValue((char*)attrName[ca],
- (char*)&tmpAttrRefValue[tAttributeSize*ca]);
- }//for
- } else if (tType == stUpdate) {
- for (int ca = 1; ca < loopCountAttributes; ca++){
- int* tmp = (int*)&tmpAttrRefValue[tAttributeSize*ca];
- if (countTables == 0)
- (*tmp)++;
- pOps[countTables]->setValue((char*)attrName[ca],(char*)tmp);
- }//for
- } else if (tType == stRead || stVerify == tType) {
- for (int ca = 1; ca < loopCountAttributes; ca++) {
- tTmp =
- pOps[countTables]->getValue((char*)attrName[ca],
- (char*)&tmpAttrValue[tAttributeSize*ca]);
- }//for
- } else if (stVerifyDelete == tType) {
- if(useLongKeys){
- tTmp = pOps[countTables]->getValue(longKeyAttrName[0],
- (char*)&tmpAttrValue[0]);
- } else {
- tTmp = pOps[countTables]->getValue((char*)attrName[0],
- (char*)&tmpAttrValue[0]);
- }
- }//if
- } else { // !use_ndb
-#ifndef USE_MYSQL
- assert(false);
-#else
- switch (tType)
- {
- case stInsert:
- for (int ca = 0; ca < loopCountAttributes; ca++){
- mysql_data[ca] = tmpAttrRefValue[tAttributeSize*ca];
- }//for
- if (mysql_execute(prep_insert[countTables])) {
- ndbout << tableName[countTables];
- ndbout << " mysql_execute: " << mysql_error(&mysql) << endl;
- tResult = 1 ;
- }
- break;
- case stUpdate: // Update Case
- mysql_data[0] = tmpAttrRefValue[0];
- for (int ca = 1; ca < loopCountAttributes; ca++){
- int* tmp = (int*)&tmpAttrRefValue[tAttributeSize*ca];
- if (countTables == 0)
- (*tmp)++;
- mysql_data[ca] = *tmp;
- }//for
- if (mysql_execute(prep_update[countTables])) {
- ndbout << tableName[countTables];
- ndbout << " mysql_execute: " << mysql_error(&mysql) << endl;
- tResult = 2 ;
- }
- break;
- case stVerify:
- case stRead: // Read Case
- mysql_data[0] = tmpAttrRefValue[0];
- if (mysql_execute(prep_read[countTables])) {
- ndbout << tableName[countTables];
- ndbout << " mysql_execute: " << mysql_error(&mysql) << endl;
- tResult = 3 ;
- break;
- }
- if (mysql_stmt_store_result(prep_read[countTables])) {
- ndbout << tableName[countTables];
- ndbout << " mysql_stmt_store_result: "
- << mysql_error(&mysql) << endl;
- tResult = 4 ;
- break;
- }
- {
- int rows= 0;
- int r;
- while ( (r= mysql_fetch(prep_read[countTables])) == 0 ){
- rows++;
- }
- if ( r == 1 ) {
- ndbout << tableName[countTables];
- ndbout << " mysql_fetch: " << mysql_error(&mysql) << endl;
- tResult = 5 ;
- break;
- }
- if ( rows != 1 ) {
- ndbout << tableName[countTables];
- ndbout << " mysql_fetch: rows = " << rows << endl;
- tResult = 6 ;
- break;
- }
- }
- {
- for (int ca = 1; ca < loopCountAttributes; ca++) {
- tmpAttrValue[tAttributeSize*ca] = mysql_data[ca];
- }
- }
- break;
- case stDelete: // Delete Case
- mysql_data[0] = tmpAttrRefValue[0];
- if (mysql_execute(prep_delete[countTables])) {
- ndbout << tableName[countTables];
- ndbout << " mysql_execute: " << mysql_error(&mysql) << endl;
- tResult = 7 ;
- break;
- }
- break;
- case stVerifyDelete:
- {
- sprintf(buf, "%s%s%s",
- "SELECT COUNT(*) FROM ",tableName[countTables],";");
- if (mysql_query(&mysql, buf)) {
- ndbout << buf << endl;
- ndbout << "Error: " << mysql_error(&mysql) << endl;
- tResult = 8 ;
- break;
- }
- MYSQL_RES *res = mysql_store_result(&mysql);
- if ( res == NULL ) {
- ndbout << "mysql_store_result: "
- << mysql_error(&mysql) << endl
- << "errno: " << mysql_errno(&mysql) << endl;
- tResult = 9 ;
- break;
- }
- int num_fields = mysql_num_fields(res);
- int num_rows = mysql_num_rows(res);
- if ( num_rows != 1 || num_fields != 1 ) {
- ndbout << tableName[countTables];
- ndbout << " mysql_store_result: num_rows = " << num_rows
- << " num_fields = " << num_fields << endl;
- tResult = 10 ;
- break;
- }
- MYSQL_ROW row = mysql_fetch_row(res);
- if ( row == NULL ) {
- ndbout << "mysql_fetch_row: "
- << mysql_error(&mysql) << endl;
- tResult = 11 ;
- break;
- }
- if ( *(char*)row[0] != '0' ) {
- ndbout << tableName[countTables];
- ndbout << " mysql_fetch_row: value = "
- << (char*)(row[0]) << endl;
- tResult = 12 ;
- break;
- }
- mysql_free_result(res);
- }
- break;
- default:
- assert(false);
- }
-#endif
- }
- }//for Tables loop
-
- if (tResult != 0)
- break;
-
- if (use_ndb){
- check = pTrans->execute(Commit);
- } else {
-#ifdef USE_MYSQL
- if (tNoOfTables > 1)
- if (mysql_commit(&mysql)) {
- ndbout << " mysql_commit: " << mysql_error(&mysql) << endl;
- tResult = 13;
- } else
- check = 0;
-#endif
- }
-
- if (use_ndb) {
- // Decide what kind of error this is
- if ((tSpecialTrans == 1) &&
- (check == -1)) {
-// --------------------------------------------------------------------
-// A special transaction have been executed, change to check = 0 in
-// certain situations.
-// --------------------------------------------------------------------
- switch (tType) {
- case stInsert: // Insert case
- if (630 == pTrans->getNdbError().code ) {
- check = 0;
- ndbout << "Insert with 4007 was successful" << endl;
- }//if
- break;
- case stDelete: // Delete Case
- if (626 == pTrans->getNdbError().code ) {
- check = 0;
- ndbout << "Delete with 4007 was successful" << endl;
- }//if
- break;
- default:
- assert(false);
- }//switch
- }//if
- tSpecialTrans = 0;
- if (check == -1) {
- if ((stVerifyDelete == tType) &&
- (626 == pTrans->getNdbError().code)) {
- // ----------------------------------------------
- // It's good news - the deleted tuple is gone,
- // so reset "check" flag
- // ----------------------------------------------
- check = 0 ;
- } else {
- int retCode =
- theErrorData.handleErrorCommon(pTrans->getNdbError());
- if (retCode == 1) {
- ndbout_c("execute: %d, %d, %s", count, tType,
- pTrans->getNdbError().message );
- ndbout_c("Error code = %d", pTrans->getNdbError().code );
- tResult = 20;
- } else if (retCode == 2) {
- ndbout << "4115 should not happen in flexBench" << endl;
- tResult = 20;
- } else if (retCode == 3) {
-// --------------------------------------------------------------------
-// We are not certain if the transaction was successful or not.
-// We must reexecute but might very well find that the transaction
-// actually was updated. Updates and Reads are no problem here. Inserts
-// will not cause a problem if error code 630 arrives. Deletes will
-// not cause a problem if 626 arrives.
-// --------------------------------------------------------------------
- if ((tType == stInsert) || (tType == stDelete)) {
- tSpecialTrans = 1;
- }//if
- }//if
- }//if
- }//if
- // Check if retries should be made
- if (check == -1 && tResult == 0) {
- if (tAttemptNo < tRetryAttempts){
- tAttemptNo++;
- } else {
-// --------------------------------------------------------------------
-// Too many retries have been made, report error and break out of loop
-// --------------------------------------------------------------------
- ndbout << "Thread" << threadNo;
- ndbout << ": too many errors reported" << endl;
- tResult = 10;
- break;
- }//if
- }//if
- }
-
- if (check == 0){
- // Go to the next record
- count++;
- tAttemptNo = 0;
-#ifdef CEBIT_STAT
- // report successful ops
- if (statEnable) {
- statOps += loopCountTables;
- if (statOps >= statFreq) {
- statReport(tType, statOps);
- statOps = 0;
- }//if
- }//if
-#endif
- }//if
-
- if (stVerify == tType && 0 == check){
- int nTableOffset = 0 ;
- for (int a = 1 ; a < loopCountAttributes ; a++){
- for (int tables = 0 ; tables < loopCountTables ; tables++){
- nTableOffset = tables*loopCountAttributes*tAttributeSize;
- int ov =*(int*)&attrValue[nTableOffset + tAttributeSize*a];
- int nv =*(int*)&tmpAttrRefValue[tAttributeSize*a];
- if (ov != nv){
- ndbout << "Error in verify ";
- ndbout << "pk = " << tmpAttrRefValue[0] << ":" << endl;
- ndbout << "attrValue[" << nTableOffset + tAttributeSize*a << "] = " << ov << endl ;
- ndbout << "attrRefValue[" << nRefLocalOpOffset + tAttributeSize*a << "]" << nv << endl ;
- tResult = 11 ;
- break ;
- }//if
- }//for
- }//for
- }// if(stVerify ... )
- if (use_ndb) {
- pNdb->closeTransaction(pTrans);
- return_ndb_object(pNdb, ndb_id);
- pNdb = NULL;
- }
- }// operations loop
-#ifdef CEBIT_STAT
- // report remaining successful ops
- if (statEnable) {
- if (statOps > 0) {
- statReport(tType, statOps);
- statOps = 0;
- }//if
- }//if
-#endif
- if (pNdb) {
- pNdb->closeTransaction(pTrans);
- return_ndb_object(pNdb, ndb_id);
- pNdb = NULL;
- }
- }
-
-#ifdef USE_MYSQL
- if (!use_ndb) {
- mysql_close(&mysql);
- for (Uint32 i = 0; i < tNoOfTables; i++) {
- mysql_stmt_close(prep_insert[i]);
- mysql_stmt_close(prep_update[i]);
- mysql_stmt_close(prep_delete[i]);
- mysql_stmt_close(prep_read[i]);
- }
- }
-#endif
- if (use_ndb && pNdb) {
- ndbout << "I got here " << endl;
- return_ndb_object(pNdb, ndb_id);
- }
- return NULL;
-}
-
-
-static int readArguments(int argc, const char** argv)
-{
-
- int i = 1;
- while (argc > 1){
- if (strcmp(argv[i], "-t") == 0){
- tNoOfThreads = atoi(argv[i+1]);
- if ((tNoOfThreads < 1))
- return -1;
- argc -= 1;
- i++;
- }else if (strcmp(argv[i], "-o") == 0){
- tNoOfOperations = atoi(argv[i+1]);
- if (tNoOfOperations < 1)
- return -1;;
- argc -= 1;
- i++;
- }else if (strcmp(argv[i], "-a") == 0){
- tNoOfAttributes = atoi(argv[i+1]);
- if ((tNoOfAttributes < 2) || (tNoOfAttributes > MAXATTR))
- return -1;
- argc -= 1;
- i++;
- }else if (strcmp(argv[i], "-c") == 0){
- tNoOfTables = atoi(argv[i+1]);
- if ((tNoOfTables < 1) || (tNoOfTables > MAXTABLES))
- return -1;
- argc -= 1;
- i++;
- }else if (strcmp(argv[i], "-stdtables") == 0){
- theStdTableNameFlag = 1;
- }else if (strcmp(argv[i], "-l") == 0){
- tNoOfLoops = atoi(argv[i+1]);
- if ((tNoOfLoops < 0) || (tNoOfLoops > 100000))
- return -1;
- argc -= 1;
- i++;
- }else if (strcmp(argv[i], "-pool_size") == 0){
- t_instances = atoi(argv[i+1]);
- if ((t_instances < 1) || (t_instances > 240))
- return -1;
- argc -= 1;
- i++;
-#ifdef USE_MYSQL
- }else if (strcmp(argv[i], "-engine") == 0){
- engine_id = atoi(argv[i+1]);
- if ((engine_id < 0) || (engine_id > 3))
- return -1;
- argc -= 1;
- i++;
- }else if (strcmp(argv[i], "-socket") == 0){
- sockets[n_sockets] = atoi(argv[i+1]);
- if (sockets[n_sockets] <= 0)
- return -1;
- n_sockets++;
- argc -= 1;
- i++;
- }else if (strcmp(argv[i], "-use_ndb") == 0){
- use_ndb = true;
-#endif
- }else if (strcmp(argv[i], "-s") == 0){
- tAttributeSize = atoi(argv[i+1]);
- if ((tAttributeSize < 1) || (tAttributeSize > MAXATTRSIZE))
- return -1;
- argc -= 1;
- i++;
- }else if (strcmp(argv[i], "-lkn") == 0){
- tNoOfLongPK = atoi(argv[i+1]);
- useLongKeys = true;
- if ((tNoOfLongPK < 1) || (tNoOfLongPK > MAXNOLONGKEY) ||
- (tNoOfLongPK * tSizeOfLongPK) > MAXLONGKEYTOTALSIZE){
- ndbout << "Argument -lkn is not in the proper range." << endl;
- return -1;
- }
- argc -= 1;
- i++;
- }else if (strcmp(argv[i], "-lks") == 0){
- tSizeOfLongPK = atoi(argv[i+1]);
- useLongKeys = true;
- if ((tSizeOfLongPK < 1) || (tNoOfLongPK * tSizeOfLongPK) > MAXLONGKEYTOTALSIZE){
- ndbout << "Argument -lks is not in the proper range 1 to " <<
- MAXLONGKEYTOTALSIZE << endl;
- return -1;
- }
- argc -= 1;
- i++;
- }else if (strcmp(argv[i], "-simple") == 0){
- theSimpleFlag = 1;
- }else if (strcmp(argv[i], "-write") == 0){
- theWriteFlag = 1;
- }else if (strcmp(argv[i], "-dirty") == 0){
- theDirtyFlag = 1;
- }else if (strcmp(argv[i], "-sleep") == 0){
- tSleepTime = atoi(argv[i+1]);
- if ((tSleepTime < 1) || (tSleepTime > 3600))
- return -1;
- argc -= 1;
- i++;
- }else if (strcmp(argv[i], "-no_table_create") == 0){
- theTableCreateFlag = 1;
- }else if (strcmp(argv[i], "-temp") == 0){
- theTempTable = true;
- }else if (strcmp(argv[i], "-noverify") == 0){
- VerifyFlag = false ;
- }else if (theErrorData.parseCmdLineArg(argv, i) == true){
- ; //empty, updated in errorArg(..)
- }else if (strcmp(argv[i], "-verify") == 0){
- VerifyFlag = true ;
-#ifdef CEBIT_STAT
- }else if (strcmp(argv[i], "-statserv") == 0){
- if (! (argc > 2))
- return -1;
- const char *p = argv[i+1];
- const char *q = strrchr(p, ':');
- if (q == 0)
- return -1;
- BaseString::snprintf(statHost, sizeof(statHost), "%.*s", q-p, p);
- statPort = atoi(q+1);
- statEnable = true;
- argc -= 1;
- i++;
- }else if (strcmp(argv[i], "-statfreq") == 0){
- if (! (argc > 2))
- return -1;
- statFreq = atoi(argv[i+1]);
- if (statFreq < 1)
- return -1;
- argc -= 1;
- i++;
-#endif
- }else{
- return -1;
- }
- argc -= 1;
- i++;
- }
-#ifdef USE_MYSQL
- if (n_sockets == 0) {
- n_sockets = 1;
- sockets[0] = 3306;
- }
-#endif
- return 0;
-}
-
-static void sleepBeforeStartingTest(int seconds){
- if (seconds > 0){
- ndbout << "Sleeping(" <<seconds << ")...";
- NdbSleep_SecSleep(seconds);
- ndbout << " done!" << endl;
- }
-}
-
-
-#ifdef USE_MYSQL
-static int
-dropTables(MYSQL* mysqlp){
- char buf[2048];
- for(unsigned i = 0; i < tNoOfTables; i++){
- int pos = 0;
- ndbout << "Dropping " << tableName[i] << "... ";
- pos += sprintf(buf+pos, "%s", "DROP TABLE ");
- pos += sprintf(buf+pos, "%s%s", tableName[i], ";");
- if (verbose)
- ndbout << endl << buf << endl;
- if (mysql_query(mysqlp, buf) != 0){
- ndbout << "Failed!"<<endl
- <<mysql_error(mysqlp)<<endl
- <<buf<<endl;
- } else
- ndbout << "OK!" << endl;
- }
-
- return 0;
-}
-#endif
-
-#ifdef USE_MYSQL
-static int
-createTables(MYSQL* mysqlp){
-
- for (Uint32 i = 0; i < tNoOfAttributes; i++){
- BaseString::snprintf(attrName[i], MAXSTRLEN, "COL%d", i);
- }
-
- // Note! Uses only uppercase letters in table name's
- // so that we can look at the tables with SQL
- for (Uint32 i = 0; i < tNoOfTables; i++){
- if (theStdTableNameFlag == 0){
- BaseString::snprintf(tableName[i], MAXSTRLEN, "TAB%d_%d", i,
- (int)(NdbTick_CurrentMillisecond() / 1000));
- } else {
- BaseString::snprintf(tableName[i], MAXSTRLEN, "TAB%d", i);
- }
- }
-
- char buf[2048];
- for(unsigned i = 0; i < tNoOfTables; i++){
- int pos = 0;
- ndbout << "Creating " << tableName[i] << "... ";
-
- pos += sprintf(buf+pos, "%s", "CREATE TABLE ");
- pos += sprintf(buf+pos, "%s%s", tableName[i], " ");
- if(useLongKeys){
- for(Uint32 i = 0; i < tNoOfLongPK; i++) {
- }
- } else {
- pos += sprintf(buf+pos, "%s%s%s",
- "(", attrName[0], " int unsigned primary key");
- }
- for (unsigned j = 1; j < tNoOfAttributes; j++)
- pos += sprintf(buf+pos, "%s%s%s", ",", attrName[j], " int unsigned");
- pos += sprintf(buf+pos, "%s%s%s", ")", engine[engine_id], ";");
- if (verbose)
- ndbout << endl << buf << endl;
- if (mysql_query(mysqlp, buf) != 0)
- return -1;
- ndbout << "done" << endl;
- }
- return 0;
-}
-#endif
-
-static int
-createTables(Ndb* pMyNdb){
-
- for (Uint32 i = 0; i < tNoOfAttributes; i++){
- BaseString::snprintf(attrName[i], MAXSTRLEN, "COL%d", i);
- }
-
- // Note! Uses only uppercase letters in table name's
- // so that we can look at the tables with SQL
- for (Uint32 i = 0; i < tNoOfTables; i++){
- if (theStdTableNameFlag == 0){
- BaseString::snprintf(tableName[i], MAXSTRLEN, "TAB%d_%d", i,
- (int)(NdbTick_CurrentMillisecond() / 1000));
- } else {
- BaseString::snprintf(tableName[i], MAXSTRLEN, "TAB%d", i);
- }
- }
-
- for(unsigned i = 0; i < tNoOfTables; i++){
- ndbout << "Creating " << tableName[i] << "... ";
-
- NdbDictionary::Table tmpTable(tableName[i]);
-
- tmpTable.setStoredTable(!theTempTable);
-
- if(useLongKeys){
- for(Uint32 i = 0; i < tNoOfLongPK; i++) {
- NdbDictionary::Column col(longKeyAttrName[i]);
- col.setType(NdbDictionary::Column::Unsigned);
- col.setLength(tSizeOfLongPK);
- col.setPrimaryKey(true);
- tmpTable.addColumn(col);
- }
- } else {
- NdbDictionary::Column col(attrName[0]);
- col.setType(NdbDictionary::Column::Unsigned);
- col.setLength(1);
- col.setPrimaryKey(true);
- tmpTable.addColumn(col);
- }
- NdbDictionary::Column col;
- col.setType(NdbDictionary::Column::Unsigned);
- col.setLength(tAttributeSize);
- for (unsigned j = 1; j < tNoOfAttributes; j++){
- col.setName(attrName[j]);
- tmpTable.addColumn(col);
- }
- if(pMyNdb->getDictionary()->createTable(tmpTable) == -1){
- return -1;
- }
- ndbout << "done" << endl;
- }
-
- return 0;
-}
-
-
-static void input_error(){
- ndbout << endl << "Invalid argument!" << endl;
- ndbout << endl << "Arguments:" << endl;
- ndbout << " -t Number of threads to start, default 1" << endl;
- ndbout << " -o Number of operations per loop, default 500" << endl;
- ndbout << " -l Number of loops to run, default 1, 0=infinite" << endl;
- ndbout << " -a Number of attributes, default 25" << endl;
- ndbout << " -c Number of tables, default 1" << endl;
- ndbout << " -s Size of each attribute, default 1 (Primary Key is always of size 1," << endl;
- ndbout << " independent of this value)" << endl;
- ndbout << " -lkn Number of long primary keys, default 1" << endl;
- ndbout << " -lks Size of each long primary key, default 1" << endl;
-
- ndbout << " -simple Use simple read to read from database" << endl;
- ndbout << " -dirty Use dirty read to read from database" << endl;
- ndbout << " -write Use writeTuple in insert and update" << endl;
- ndbout << " -stdtables Use standard table names" << endl;
- ndbout << " -no_table_create Don't create tables in db" << endl;
- ndbout << " -sleep Sleep a number of seconds before running the test, this" << endl;
- ndbout << " can be used so that another flexBench have time to create tables" << endl;
- ndbout << " -temp Use tables without logging" << endl;
- ndbout << " -verify Verify inserts, updates and deletes" << endl ;
- ndbout << " -use_ndb Use NDB API (otherwise use mysql client)" << endl ;
- ndbout << " -pool_size Number of Ndb objects in pool" << endl ;
- theErrorData.printCmdLineArgs(ndbout);
- ndbout << endl <<"Returns:" << endl;
- ndbout << "\t 0 - Test passed" << endl;
- ndbout << "\t 1 - Test failed" << endl;
- ndbout << "\t 2 - Invalid arguments" << endl << endl;
-}
-
-// vim: set sw=2:
diff --git a/storage/ndb/test/ndbapi/index.cpp b/storage/ndb/test/ndbapi/index.cpp
deleted file mode 100644
index 0d2e1ccd0f3..00000000000
--- a/storage/ndb/test/ndbapi/index.cpp
+++ /dev/null
@@ -1,998 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-/* ***************************************************
- INDEX TEST 1
- Test index functionality of NDB
-
- Arguments:
- -T create table
- -L include a long attribute in key or index
- -2 define primary key with two attributes
- -c create index
- -p make index unique (include primary key attribute)
- -r read using index
- -u update using index
- -d delete using index
- -n<no operations> do n operations (for -I -r -u -d -R -U -D)
- -o<no parallel operations> (for -I -r -u -d -R -U -D)
- -m<no indexes>
-
- Returns:
- 0 - Test passed
- -1 - Test failed
- 1 - Invalid arguments
- * *************************************************** */
-
-#include <ndb_global.h>
-
-#include <NdbApi.hpp>
-#include <NdbOut.hpp>
-#include <NdbTick.h>
-#include <NdbMain.h>
-#include <NdbTest.hpp>
-#include <NDBT_Error.hpp>
-
-#ifndef MIN
-#define MIN(x,y) (((x)<(y))?(x):(y))
-#endif
-
-#define MAX_NO_PARALLEL_OPERATIONS 100
-
-bool testPassed = true;
-
-static void
-error_handler(const NdbError & err)
-{
- // Test failed
- ndbout << endl << err << endl;
- testPassed = false;
-}
-
-static void
-error_handler4(int line, const NdbError & err){
- ndbout << endl << "Line " << line << endl;
- // Test failed
- ndbout << err << endl;
- testPassed = false;
-}
-
-static char *longName, *sixtysix, *ninetynine, *hundred;
-
-static void createTable(Ndb &myNdb, bool storeInACC, bool twoKey, bool longKey)
-{
- NdbDictionary::Dictionary* dict = myNdb.getDictionary();
- NdbDictionary::Table table("PERSON");
- //NdbDictionary::Column column(); // Bug
- NdbDictionary::Column column;
- int res;
-
- column.setName("NAME");
- column.setType(NdbDictionary::Column::Char);
- column.setLength((longKey)?
- 1024 // 1KB => long key
- :12);
- column.setPrimaryKey(true);
- column.setNullable(false);
- table.addColumn(column);
-
- if (twoKey) {
- column.setName("KEY2");
- column.setType(NdbDictionary::Column::Unsigned);
- column.setLength(1);
- column.setPrimaryKey(true);
- column.setNullable(false);
- table.addColumn(column);
- }
-
- column.setName("PNUM1");
- column.setType(NdbDictionary::Column::Unsigned);
- column.setLength(1);
- column.setPrimaryKey(false);
- column.setNullable(false);
- table.addColumn(column);
-
- column.setName("PNUM2");
- column.setType(NdbDictionary::Column::Unsigned);
- column.setLength(1);
- column.setPrimaryKey(false);
- column.setNullable(false);
- table.addColumn(column);
-
- column.setName("PNUM3");
- column.setType(NdbDictionary::Column::Unsigned);
- column.setLength(1);
- column.setPrimaryKey(false);
- column.setNullable(false);
- table.addColumn(column);
-
- column.setName("PNUM4");
- column.setType(NdbDictionary::Column::Unsigned);
- column.setLength(1);
- column.setPrimaryKey(false);
- column.setNullable(false);
- table.addColumn(column);
-
- column.setName("AGE");
- column.setType(NdbDictionary::Column::Unsigned);
- column.setLength(1);
- column.setPrimaryKey(false);
- column.setNullable(false);
- table.addColumn(column);
-
- column.setName("STRING_AGE");
- column.setType(NdbDictionary::Column::Char);
- column.setLength(1);
- column.setLength(256);
- column.setPrimaryKey(false);
- column.setNullable(false);
- table.addColumn(column);
-
- if ((res = dict->createTable(table)) == -1) {
- error_handler(dict->getNdbError());
- }
- else
- ndbout << "Created table" << ((longKey)?" with long key":"") <<endl;
-}
-
-static void createIndex(Ndb &myNdb, bool includePrimary, unsigned int noOfIndexes)
-{
- Uint64 before, after;
- NdbDictionary::Dictionary* dict = myNdb.getDictionary();
- char indexName[] = "PNUMINDEX0000";
- int res;
-
- for(unsigned int indexNum = 0; indexNum < noOfIndexes; indexNum++) {
- sprintf(indexName, "PNUMINDEX%.4u", indexNum);
- NdbDictionary::Index index(indexName);
- index.setTable("PERSON");
- index.setType(NdbDictionary::Index::UniqueHashIndex);
- if (includePrimary) {
- const char* attr_arr[] = {"NAME", "PNUM1", "PNUM3"};
- index.addIndexColumns(3, attr_arr);
- }
- else {
- const char* attr_arr[] = {"PNUM1", "PNUM3"};
- index.addIndexColumns(2, attr_arr);
- }
- before = NdbTick_CurrentMillisecond();
- if ((res = dict->createIndex(index)) == -1) {
- error_handler(dict->getNdbError());
- }
- after = NdbTick_CurrentMillisecond();
- ndbout << "Created index " << indexName << ", " << after - before << " msec" << endl;
- }
-}
-
-static void insertTable(Ndb &myNdb, unsigned int noOfTuples, unsigned int noOfOperations, bool oneTrans, bool twoKey, bool longKey)
-{
- Uint64 tbefore, tafter, before, after;
- NdbConnection *myTrans;
- NdbOperation *myOp;
- char name[] = "Kalle0000000";
-
- tbefore = NdbTick_CurrentMillisecond();
- if (oneTrans) myTrans = myNdb.startTransaction();
- for (unsigned int i = 0; i<noOfTuples; i++) {
- if (!oneTrans) myTrans = myNdb.startTransaction();
- for(unsigned int j = 1;
- ((j<=noOfOperations)&&(i<noOfTuples));
- (++j<=noOfOperations)?i++:i) {
- if (myTrans == NULL)
- error_handler4(__LINE__, myNdb.getNdbError());
-
- myOp = myTrans->getNdbOperation("PERSON");
- if (myOp == NULL)
- error_handler4(__LINE__, myTrans->getNdbError());
-
- myOp->insertTuple();
- sprintf(name, "Kalle%.7i", i);
- if (longKey)
- memcpy(longName, name, strlen(name));
- if (myOp->equal("NAME", (longKey)?longName:name) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- if (twoKey)
- if (myOp->equal("KEY2", i) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- if (myOp->setValue("PNUM1", 17) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- if (myOp->setValue("PNUM2", 18)) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- if (myOp->setValue("PNUM3", 19)) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- if (myOp->setValue("PNUM4", 20)) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- if (myOp->setValue("AGE", ((i % 2) == 0)?66:99) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- if (myOp->setValue("STRING_AGE", ((i % 2) == 0)?sixtysix:ninetynine) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- }
- if (noOfOperations == 1)
- printf("Trying to insert person %s\n", name);
- else
- printf("Trying to insert %u persons\n", noOfOperations);
- before = NdbTick_CurrentMillisecond();
- if (myTrans->execute( (oneTrans) ? NoCommit : Commit ) == -1)
- {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- after = NdbTick_CurrentMillisecond();
- if (noOfOperations == 1)
- printf("Inserted person %s, %u msec\n", name, (Uint32) after - before);
- else
- printf("Inserted %u persons, %u msec\n", noOfOperations, (Uint32) after - before);
- if (!oneTrans) myNdb.closeTransaction(myTrans);
- }
- if (oneTrans) {
- if (myTrans->execute( Commit ) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- }
- myNdb.closeTransaction(myTrans);
- }
- tafter = NdbTick_CurrentMillisecond();
-
- ndbout << "Inserted "<< noOfTuples << " tuples in " << ((oneTrans) ? 1 : noOfTuples) << " transaction(s), " << tafter - tbefore << " msec" << endl;
-}
-
-static void updateTable(Ndb &myNdb, unsigned int noOfTuples, unsigned int noOfOperations, bool oneTrans, bool twoKey, bool longKey)
-{
- Uint64 tbefore, tafter, before, after;
- NdbConnection *myTrans;
- NdbOperation *myOp;
- char name[] = "Kalle0000000";
-
- tbefore = NdbTick_CurrentMillisecond();
- if (oneTrans) myTrans = myNdb.startTransaction();
- for (unsigned int i = 0; i<noOfTuples; i++) {
- if (!oneTrans) myTrans = myNdb.startTransaction();
- for(unsigned int j = 1;
- ((j<=noOfOperations)&&(i<noOfTuples));
- (++j<=noOfOperations)?i++:i) {
- if (myTrans == NULL)
- error_handler4(__LINE__, myNdb.getNdbError());
-
- myOp = myTrans->getNdbOperation("PERSON");
- if (myOp == NULL)
- error_handler4(__LINE__, myTrans->getNdbError());
-
- myOp->updateTuple();
- sprintf(name, "Kalle%.7i", i);
- if (longKey)
- memcpy(longName, name, strlen(name));
- if (myOp->equal("NAME", (longKey)?longName:name) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- if (twoKey)
- if (myOp->equal("KEY2", i) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- if (myOp->setValue("PNUM1", 77) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- if (myOp->setValue("PNUM2", 88)) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- if (myOp->setValue("PNUM4", 99)) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- if (myOp->setValue("AGE", 100) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- if (myOp->setValue("STRING_AGE", hundred) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- }
- if (noOfOperations == 1)
- printf("Trying to update person %s\n", name);
- else
- printf("Trying to update %u persons\n", noOfOperations);
- before = NdbTick_CurrentMillisecond();
- if (myTrans->execute( (oneTrans) ? NoCommit : Commit ) == -1)
- {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- after = NdbTick_CurrentMillisecond();
- if (noOfOperations == 1)
- printf("Updated person %s, %u msec\n", name, (Uint32) after - before);
- else
- printf("Update %u persons, %u msec\n", noOfOperations, (Uint32) after - before);
- if (!oneTrans) myNdb.closeTransaction(myTrans);
- }
- if (oneTrans) {
- if (myTrans->execute( Commit ) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- }
- myNdb.closeTransaction(myTrans);
- }
- tafter = NdbTick_CurrentMillisecond();
-
- ndbout << "Updated "<< noOfTuples << " tuples in " << ((oneTrans) ? 1 : noOfTuples) << " transaction(s), " << tafter - tbefore << " msec" << endl;
-}
-
-static void deleteTable(Ndb &myNdb, unsigned int noOfTuples, unsigned int noOfOperations, bool oneTrans, bool twoKey, bool longKey)
-{
- Uint64 tbefore, tafter, before, after;
- NdbConnection *myTrans;
- NdbOperation *myOp;
- char name[] = "Kalle0000000";
-
- tbefore = NdbTick_CurrentMillisecond();
- if (oneTrans) myTrans = myNdb.startTransaction();
- for (unsigned int i = 0; i<noOfTuples; i++) {
- if (!oneTrans) myTrans = myNdb.startTransaction();
- for(unsigned int j = 1;
- ((j<=noOfOperations)&&(i<noOfTuples));
- (++j<=noOfOperations)?i++:i) {
- if (myTrans == NULL)
- error_handler4(__LINE__, myNdb.getNdbError());
-
- myOp = myTrans->getNdbOperation("PERSON");
- if (myOp == NULL)
- error_handler4(__LINE__, myTrans->getNdbError());
-
- myOp->deleteTuple();
- sprintf(name, "Kalle%.7i", i);
- if (longKey)
- memcpy(longName, name, strlen(name));
- if (myOp->equal("NAME", (longKey)?longName:name) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- if (twoKey)
- if (myOp->equal("KEY2", i) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- }
- if (noOfOperations == 1)
- printf("Trying to delete person %s\n", name);
- else
- printf("Trying to delete %u persons\n", noOfOperations);
- before = NdbTick_CurrentMillisecond();
- if (myTrans->execute( (oneTrans) ? NoCommit : Commit ) == -1)
- {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- after = NdbTick_CurrentMillisecond();
- if (noOfOperations == 1)
- printf("Deleted person %s, %u msec\n", name, (Uint32) after - before);
- else
- printf("Deleted %u persons, %u msec\n", noOfOperations, (Uint32) after - before);
-
- if (!oneTrans) myNdb.closeTransaction(myTrans);
- }
- if (oneTrans) {
- if (myTrans->execute( Commit ) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- }
- myNdb.closeTransaction(myTrans);
- }
- tafter = NdbTick_CurrentMillisecond();
-
- ndbout << "Deleted "<< noOfTuples << " tuples in " << ((oneTrans) ? 1 : noOfTuples) << " transaction(s), " << tafter - tbefore << " msec" << endl;
-}
-
-static void readTable(Ndb &myNdb, unsigned int noOfTuples, unsigned int noOfOperations, bool oneTrans, bool twoKey, bool longKey)
-{
- Uint64 tbefore, tafter, before, after;
- NdbConnection *myTrans;
- NdbOperation *myOp;
- char name[] = "Kalle0000000";
- NdbRecAttr* myRecAttrArr[MAX_NO_PARALLEL_OPERATIONS];
-
- tbefore = NdbTick_CurrentMillisecond();
- if (oneTrans) myTrans = myNdb.startTransaction();
- for (unsigned int i = 0; i<noOfTuples; i++) {
- if (!oneTrans) myTrans = myNdb.startTransaction();
- for(unsigned int j = 1;
- ((j<=noOfOperations)&&(i<noOfTuples));
- (++j<=noOfOperations)?i++:i) {
- if (myTrans == NULL)
- error_handler4(__LINE__, myNdb.getNdbError());
-
- myOp = myTrans->getNdbOperation("PERSON");
- if (myOp == NULL)
- error_handler4(__LINE__, myTrans->getNdbError());
-
- myOp->readTuple();
- sprintf(name, "Kalle%.7i", i);
- if (longKey)
- memcpy(longName, name, strlen(name));
- if (myOp->equal("NAME", (longKey)?longName:name) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- if (twoKey)
- if (myOp->equal("KEY2", i) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- myRecAttrArr[j-1] = myOp->getValue("PNUM2", NULL);
- }
- if (noOfOperations == 1)
- printf("Trying to read person %s\n", name);
- else
- printf("Trying to read %u persons\n", noOfOperations);
- before = NdbTick_CurrentMillisecond();
- if (myTrans->execute( (oneTrans) ? NoCommit : Commit ) == -1)
- {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- after = NdbTick_CurrentMillisecond();
- if (noOfOperations == 1)
- printf("Read person %s, %u msec\n", name, (Uint32) after - before);
- else
- printf("Read %u persons, %u msec\n", noOfOperations, (Uint32) after - before);
- for(unsigned int j = 0; j<noOfOperations; j++)
- printf("PNUM2 = %u\n", myRecAttrArr[j]->u_32_value());
- if (!oneTrans) myNdb.closeTransaction(myTrans);
- }
- if (oneTrans) {
- if (myTrans->execute( Commit ) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- }
- myNdb.closeTransaction(myTrans);
- }
- tafter = NdbTick_CurrentMillisecond();
-
- ndbout << "Read "<< noOfTuples << " tuples in " << ((oneTrans) ? 1 : noOfTuples) << " transaction(s), " << tafter - tbefore << " msec" << endl;
-}
-
-static void readIndex(Ndb &myNdb, unsigned int noOfTuples, unsigned int noOfOperations, bool includePrimary, bool oneTrans, bool longKey)
-{
- Uint64 tbefore, tafter, before, after;
- NdbConnection *myTrans;
- NdbIndexOperation *myOp;
- char indexName[] = "PNUMINDEX0000";
- char name[] = "Kalle0000000";
- NdbRecAttr* myRecAttrArr[MAX_NO_PARALLEL_OPERATIONS];
-
- tbefore = NdbTick_CurrentMillisecond();
- if (oneTrans) myTrans = myNdb.startTransaction();
- for (unsigned int i = 0; i<noOfTuples; i++) {
- if (!oneTrans) myTrans = myNdb.startTransaction();
- for(unsigned int j = 1;
- ((j<=noOfOperations)&&(i<noOfTuples));
- (++j<=noOfOperations)?i++:i) {
- if (myTrans == NULL)
- error_handler4(__LINE__, myNdb.getNdbError());
-
- myOp = myTrans->getNdbIndexOperation(indexName, "PERSON");
- if (myOp == NULL)
- error_handler4(__LINE__, myTrans->getNdbError());
-
- myOp->readTuple();
- if (includePrimary) {
- sprintf(name, "Kalle%.7i", i);
- if (longKey)
- memcpy(longName, name, strlen(name));
- if (myOp->equal("NAME", (longKey)?longName:name) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- }
- if (myOp->equal("PNUM1", 17) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- if (myOp->equal("PNUM3", 19) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- myRecAttrArr[j-1] = myOp->getValue("PNUM2", NULL);
- }
- if (noOfOperations == 1)
- printf("Trying to read person %s\n", name);
- else
- printf("Trying to read %u persons\n", noOfOperations);
- before = NdbTick_CurrentMillisecond();
- if (myTrans->execute( (oneTrans) ? NoCommit : Commit ) == -1)
- {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- after = NdbTick_CurrentMillisecond();
- if (noOfOperations == 1)
- printf("Read person %s, %u msec\n", name, (Uint32) after - before);
- else
- printf("Read %u persons, %u msec\n", noOfOperations, (Uint32) after - before);
- for(unsigned int j = 0; j<noOfOperations; j++)
- printf("PNUM2 = %u\n", myRecAttrArr[j]->u_32_value());
- if (!oneTrans) myNdb.closeTransaction(myTrans);
- }
- if (oneTrans) {
- if (myTrans->execute( Commit ) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- }
- myNdb.closeTransaction(myTrans);
- }
- tafter = NdbTick_CurrentMillisecond();
-
- ndbout << "Read "<< noOfTuples << " tuples in " << ((oneTrans) ? 1 : noOfTuples) << " transaction(s), " << tafter - tbefore << " msec" << endl;
-}
-
-static void updateIndex(Ndb &myNdb, unsigned int noOfTuples, unsigned int noOfOperations, bool includePrimary, bool oneTrans, bool longKey)
-{
- Uint64 tbefore, tafter, before, after;
- NdbConnection *myTrans;
- NdbIndexOperation *myOp;
- char indexName[] = "PNUMINDEX0000";
- char name[] = "Kalle0000000";
-
- tbefore = NdbTick_CurrentMillisecond();
- if (oneTrans) myTrans = myNdb.startTransaction();
- for (unsigned int i = 0; i<noOfTuples; i++) {
- if (!oneTrans) myTrans = myNdb.startTransaction();
- for(unsigned int j = 1;
- ((j<=noOfOperations)&&(i<noOfTuples));
- (++j<=noOfOperations)?i++:i) {
- if (myTrans == NULL)
- error_handler4(__LINE__, myNdb.getNdbError());
-
- myOp = myTrans->getNdbIndexOperation(indexName, "PERSON");
- if (myOp == NULL)
- error_handler4(__LINE__, myTrans->getNdbError());
-
- myOp->updateTuple();
- if (includePrimary) {
- sprintf(name, "Kalle%.7i", i);
- if (longKey)
- memcpy(longName, name, strlen(name));
- if (myOp->equal("NAME", (longKey)?longName:name) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- }
- if (myOp->equal("PNUM1", 17) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- if (myOp->equal("PNUM3", 19) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- // Update index itself, should be possible
- if (myOp->setValue("PNUM1", 77) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- if (myOp->setValue("PNUM2", 88)) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- if (myOp->setValue("PNUM4", 99)) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- if (myOp->setValue("AGE", 100) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- if (myOp->setValue("STRING_AGE", hundred) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- }
- if (noOfOperations == 1)
- printf("Trying to update person %s\n", name);
- else
- printf("Trying to update %u persons\n", noOfOperations);
- before = NdbTick_CurrentMillisecond();
- if (myTrans->execute( (oneTrans) ? NoCommit : Commit ) == -1)
- {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- after = NdbTick_CurrentMillisecond();
- if (noOfOperations == 1)
- printf("Updated person %s, %u msec\n", name, (Uint32) after - before);
- else
- printf("Updated %u persons, %u msec\n", noOfOperations, (Uint32) after - before);
- if (!oneTrans) myNdb.closeTransaction(myTrans);
- }
- if (oneTrans) {
- if (myTrans->execute( Commit ) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- }
- myNdb.closeTransaction(myTrans);
- }
- tafter = NdbTick_CurrentMillisecond();
-
- ndbout << "Updated "<< noOfTuples << " tuples in " << ((oneTrans) ? 1 : noOfTuples) << " transaction(s), " << tafter - tbefore << " msec" << endl;
-}
-
-static void deleteIndex(Ndb &myNdb, unsigned int noOfTuples, unsigned int noOfOperations, bool includePrimary, bool oneTrans, bool longKey)
-{
- Uint64 tbefore, tafter, before, after;
- NdbConnection *myTrans;
- NdbIndexOperation *myOp;
- char indexName[] = "PNUMINDEX0000";
- char name[] = "Kalle0000000";
-
- tbefore = NdbTick_CurrentMillisecond();
- if (oneTrans) myTrans = myNdb.startTransaction();
- for (unsigned int i = 0; i<noOfTuples; i++) {
- for(unsigned int j = 1;
- ((j<=noOfOperations)&&(i<noOfTuples));
- (++j<=noOfOperations)?i++:i) {
- if (!oneTrans) myTrans = myNdb.startTransaction();
- if (myTrans == NULL)
- error_handler4(__LINE__, myNdb.getNdbError());
-
- myOp = myTrans->getNdbIndexOperation(indexName, "PERSON");
- if (myOp == NULL)
- error_handler4(__LINE__, myTrans->getNdbError());
-
- myOp->deleteTuple();
- if (includePrimary) {
- sprintf(name, "Kalle%.7i", i);
- if (longKey)
- memcpy(longName, name, strlen(name));
- if (myOp->equal("NAME", (longKey)?longName:name) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- }
- if (myOp->equal("PNUM1", 17) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- if (myOp->equal("PNUM3", 19) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- }
- if (noOfOperations == 1)
- printf("Trying to delete person %s\n", name);
- else
- printf("Trying to delete %u persons\n", noOfOperations);
- before = NdbTick_CurrentMillisecond();
- if (myTrans->execute( (oneTrans) ? NoCommit : Commit ) == -1)
- {
- error_handler4(__LINE__, myTrans->getNdbError());
- myNdb.closeTransaction(myTrans);
- break;
- }
- after = NdbTick_CurrentMillisecond();
- if (noOfOperations == 1)
- printf("Deleted person %s, %u msec\n", name, (Uint32) after - before);
- else
- printf("Deleted %u persons, %u msec\n", noOfOperations, (Uint32) after - before);
- if (!oneTrans) myNdb.closeTransaction(myTrans);
- }
- if (oneTrans) {
- if (myTrans->execute( Commit ) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError());
- }
- myNdb.closeTransaction(myTrans);
- }
- tafter = NdbTick_CurrentMillisecond();
-
- ndbout << "Deleted "<< noOfTuples << " tuples in " << ((oneTrans) ? 1 : noOfTuples) << " transaction(s), " << tafter - tbefore << " msec" << endl;
-}
-
-static void dropIndex(Ndb &myNdb, unsigned int noOfIndexes)
-{
- for(unsigned int indexNum = 0; indexNum < noOfIndexes; indexNum++) {
- char indexName[255];
- sprintf(indexName, "PNUMINDEX%.4u", indexNum);
- const Uint64 before = NdbTick_CurrentMillisecond();
- const int retVal = myNdb.getDictionary()->dropIndex(indexName, "PERSON");
- const Uint64 after = NdbTick_CurrentMillisecond();
-
- if(retVal == 0){
- ndbout << "Dropped index " << indexName << ", "
- << after - before << " msec" << endl;
- } else {
- ndbout << "Failed to drop index " << indexName << endl;
- ndbout << myNdb.getDictionary()->getNdbError() << endl;
- }
- }
-}
-
-NDB_COMMAND(indexTest, "indexTest", "indexTest", "indexTest", 65535)
-{
- ndb_init();
- bool createTableOp, createIndexOp, dropIndexOp, insertOp, updateOp, deleteOp, readOp, readIndexOp, updateIndexOp, deleteIndexOp, twoKey, longKey;
- unsigned int noOfTuples = 1;
- unsigned int noOfOperations = 1;
- unsigned int noOfIndexes = 1;
- int i = 1;
- Ndb myNdb( "TEST_DB" );
- int check;
- bool storeInACC = false;
- bool includePrimary = false;
- bool oneTransaction = false;
-
- createTableOp = createIndexOp = dropIndexOp = insertOp = updateOp = deleteOp = readOp = readIndexOp = updateIndexOp = deleteIndexOp = twoKey = longKey = false;
- // Read arguments
- if (argc > 1)
- while (argc > 1)
- {
- if (strcmp(argv[i], "-T") == 0)
- {
- createTableOp = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-c") == 0)
- {
- createIndexOp = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-X") == 0)
- {
- dropIndexOp = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-I") == 0)
- {
- insertOp = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-D") == 0)
- {
- deleteOp = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-U") == 0)
- {
- updateOp = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-R") == 0)
- {
- readOp = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-r") == 0)
- {
- readIndexOp = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-u") == 0)
- {
- updateIndexOp = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-d") == 0)
- {
- deleteIndexOp = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-s") == 0)
- {
- storeInACC = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-p") == 0)
- {
- includePrimary = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-L") == 0)
- {
- longKey = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-1") == 0)
- {
- oneTransaction = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-2") == 0)
- {
- twoKey = true;
- argc -= 1;
- i++;
- }
- else if (strstr(argv[i], "-n") != 0)
- {
- noOfTuples = atoi(argv[i]+2);
- argc -= 1;
- i++;
- }
- else if (strstr(argv[i], "-o") != 0)
- {
- noOfOperations = MIN(MAX_NO_PARALLEL_OPERATIONS, atoi(argv[i]+2));
- argc -= 1;
- i++;
- }
- else if (strstr(argv[i], "-m") != 0)
- {
- noOfIndexes = atoi(argv[i]+2);
- argc -= 1;
- i++;
- }
- else if (strstr(argv[i], "-h") != 0)
- {
- printf("Synopsis:\n");
- printf("index\n");
- printf("\t-T create table\n");
- printf("\t-L include a long attribute in key or index\n");
- printf("\t-2 define primary key with two attributes\n");
- printf("\t-c create index\n");
- printf("\t-p make index unique (include primary key attribute)\n");
- printf("\t-r read using index\n");
- printf("\t-u update using index\n");
- printf("\t-d delete using index\n");
- printf("\t-n<no operations> do n operations (for -I -r -u -d -R -U -D)\n");
- printf("\t-o<no parallel operations> (for -I -r -u -d -R -U -D)\n");
- printf("\t-m<no indexes>\n");
- argc -= 1;
- i++;
- }
- else {
- char errStr[256];
-
- printf(errStr, "Illegal argument: %s", argv[i]);
- exit(-1);
- }
- }
- else
- {
- createTableOp = createIndexOp = dropIndexOp = insertOp = updateOp = deleteOp = true;
- }
- if (longKey) {
- longName = (char *) malloc(1024);
- for (int i = 0; i < 1023; i++)
- longName[i] = 'x';
- longName[1023] = '\0';
- }
- sixtysix = (char *) malloc(256);
- for (int i = 0; i < 255; i++)
- sixtysix[i] = ' ';
- sixtysix[255] = '\0';
- strncpy(sixtysix, "sixtysix", strlen("sixtysix"));
- ninetynine = (char *) malloc(256);
- for (int i = 0; i < 255; i++)
- ninetynine[i] = ' ';
- ninetynine[255] = '\0';
- strncpy(ninetynine, "ninetynine", strlen("ninetynine"));
- hundred = (char *) malloc(256);
- for (int i = 0; i < 255; i++)
- hundred[i] = ' ';
- hundred[255] = '\0';
- strncpy(hundred, "hundred", strlen("hundred"));
- myNdb.init();
- // Wait for Ndb to become ready
- if (myNdb.waitUntilReady(30) == 0)
- {
- if (createTableOp)
- createTable(myNdb, storeInACC, twoKey, longKey);
-
- if (createIndexOp)
- createIndex(myNdb, includePrimary, noOfIndexes);
-
- if (insertOp)
- insertTable(myNdb, noOfTuples, noOfOperations, oneTransaction, twoKey, longKey);
-
- if (updateOp)
- updateTable(myNdb, noOfTuples, noOfOperations, oneTransaction, twoKey, longKey);
-
- if (deleteOp)
- deleteTable(myNdb, noOfTuples, noOfOperations, oneTransaction, twoKey, longKey);
-
- if (readOp)
- readTable(myNdb, noOfTuples, noOfOperations, oneTransaction, twoKey, longKey);
-
- if (readIndexOp)
- readIndex(myNdb, noOfTuples, noOfOperations, includePrimary, oneTransaction, longKey);
-
- if (updateIndexOp)
- updateIndex(myNdb, noOfTuples, noOfOperations, includePrimary, oneTransaction, longKey);
-
- if (deleteIndexOp)
- deleteIndex(myNdb, noOfTuples, noOfOperations, includePrimary, oneTransaction, longKey);
-
- if (dropIndexOp)
- dropIndex(myNdb, noOfIndexes);
- }
-
- if (testPassed)
- {
- // Test passed
- ndbout << "OK - Test passed" << endl;
- }
- else
- {
- // Test failed
- ndbout << "FAIL - Test failed" << endl;
- exit(-1);
- }
- return 0;
-}
-
-
diff --git a/storage/ndb/test/ndbapi/index2.cpp b/storage/ndb/test/ndbapi/index2.cpp
deleted file mode 100644
index f36a6209d8d..00000000000
--- a/storage/ndb/test/ndbapi/index2.cpp
+++ /dev/null
@@ -1,836 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-/* ***************************************************
- INDEX TEST 1
- Test index functionality of NDB
-
- Arguments:
- -T create table
- -L include a long attribute in key or index
- -2 define primary key with two attributes
- -c create index
- -p make index unique (include primary key attribute)
- -r read using index
- -u update using index
- -d delete using index
- -n<no operations> do n operations (for -I -r -u -d -R -U -D)
- -o<no parallel operations> (for -I -r -u -d -R -U -D)
- -m<no indexes>
-
- Returns:
- 0 - Test passed
- -1 - Test failed
- 1 - Invalid arguments
- * *************************************************** */
-
-#include <ndb_global.h>
-
-#include <NdbApi.hpp>
-#include <NdbOut.hpp>
-#include <NdbTick.h>
-#include <NdbMain.h>
-#include <NdbTest.hpp>
-#include <NDBT_Error.hpp>
-
-#ifndef MIN
-#define MIN(x,y) (((x)<(y))?(x):(y))
-#endif
-
-#define MAX_NO_PARALLEL_OPERATIONS 100
-
-bool testPassed = true;
-
-static void
-error_handler(const char* errorText)
-{
- // Test failed
- ndbout << endl << "ErrorMessage: " << errorText << endl;
- testPassed = false;
-}
-
-static void
-error_handler4(int line, int status, int classif, int errNo, const char* errorText)
-{
- ndbout << endl << "Line " << line << endl;
- // Test failed
- ndbout << "Status " << status << ", Classification " << classif<< ", Error code " << errNo << "\n" << errorText << endl;
- testPassed = false;
-}
-
-static char *longName, *sixtysix, *ninetynine, *hundred;
-
-static void createTable(Ndb &myNdb, bool storeInACC, bool twoKey, bool longKey)
-{
- NdbDictionary::Dictionary* dict = myNdb.getDictionary();
- NdbDictionary::Table table("THE_TABLE");
- NdbDictionary::Column column;
- int res;
-
- column.setName("X");
- column.setType(NdbDictionary::Column::Unsigned);
- column.setLength(1);
- column.setPrimaryKey(true);
- column.setNullable(false);
- table.addColumn(column);
-
- column.setName("Y");
- column.setType(NdbDictionary::Column::Unsigned);
- column.setLength(1);
- column.setPrimaryKey(false);
- column.setNullable(false);
- table.addColumn(column);
-
- if ((res = dict->createTable(table)) == -1) {
- error_handler(dict->getNdbError().message);
- }
- else
- ndbout << "Created table" << ((longKey)?" with long key":"") <<endl;
-}
-
-static void createIndex(Ndb &myNdb, bool includePrimary, unsigned int noOfIndexes)
-{
- Uint64 before, after;
- NdbDictionary::Dictionary* dict = myNdb.getDictionary();
- char indexName[] = "INDEX0000";
- int res;
-
- for(unsigned int indexNum = 0; indexNum < noOfIndexes; indexNum++) {
- sprintf(indexName, "INDEX%.4u", indexNum);
- NdbDictionary::Index index(indexName);
- index.setTable("THE_TABLE");
- index.setType(NdbDictionary::Index::UniqueHashIndex);
- if (includePrimary) {
- const char* attr_arr[] = {"X", "Y"};
- index.addIndexColumns(2, attr_arr);
- }
- else {
- const char* attr_arr[] = {"Y"};
- index.addIndexColumns(2, attr_arr);
- }
- before = NdbTick_CurrentMillisecond();
- if ((res = dict->createIndex(index)) == -1) {
- error_handler(dict->getNdbError().message);
- }
- after = NdbTick_CurrentMillisecond();
- ndbout << "Created index " << indexName << ", " << after - before << " msec"<< endl;
- }
-}
-
-static void insertTable(Ndb &myNdb, unsigned int noOfTuples, unsigned int noOfOperations, bool oneTrans, bool twoKey, bool longKey)
-{
- Uint64 tbefore, tafter, before, after;
- NdbConnection *myTrans;
- NdbOperation *myOp;
-
- tbefore = NdbTick_CurrentMillisecond();
- if (oneTrans) myTrans = myNdb.startTransaction();
- for (unsigned int i = 0; i<noOfTuples; i++) {
- if (!oneTrans) myTrans = myNdb.startTransaction();
- for(unsigned int j = 1;
- ((j<=noOfOperations)&&(i<noOfTuples));
- (++j<=noOfOperations)?i++:i) {
- if (myTrans == NULL)
- error_handler4(__LINE__, myNdb.getNdbError().status, myNdb.getNdbError().classification,
- myNdb.getNdbError().code, myNdb.getNdbError().message);
-
- myOp = myTrans->getNdbOperation("THE_TABLE");
- if (myOp == NULL)
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
-
- myOp->insertTuple();
- if (myOp->equal("X", i) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- myNdb.closeTransaction(myTrans);
- break;
- }
- if (myOp->setValue("Y", i+1) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- myNdb.closeTransaction(myTrans);
- break;
- }
- }
- before = NdbTick_CurrentMillisecond();
- if (myTrans->execute( (oneTrans) ? NoCommit : Commit ) == -1)
- {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- myNdb.closeTransaction(myTrans);
- break;
- }
- after = NdbTick_CurrentMillisecond();
- if (noOfOperations == 1)
- printf("Inserted 1 tuple, %u msec\n", (Uint32) after - before);
- else
- printf("Inserted %u tuples, %u msec\n", noOfOperations, (Uint32) after - before);
-
- if (!oneTrans) myNdb.closeTransaction(myTrans);
- }
- if (oneTrans) {
- if (myTrans->execute( Commit ) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- }
- myNdb.closeTransaction(myTrans);
- }
- tafter = NdbTick_CurrentMillisecond();
-
- ndbout << "Inserted "<< noOfTuples << " tuples in " << ((oneTrans) ? 1 : noOfTuples) << " transaction(s), " << tafter - tbefore << " msec" << endl;
-}
-
-static void updateTable(Ndb &myNdb, unsigned int noOfTuples, unsigned int noOfOperations, bool oneTrans, bool twoKey, bool longKey)
-{
- Uint64 tbefore, tafter, before, after;
- NdbConnection *myTrans;
- NdbOperation *myOp;
-
- tbefore = NdbTick_CurrentMillisecond();
- if (oneTrans) myTrans = myNdb.startTransaction();
- for (unsigned int i = 0; i<noOfTuples; i++) {
- if (!oneTrans) myTrans = myNdb.startTransaction();
- for(unsigned int j = 1;
- ((j<=noOfOperations)&&(i<noOfTuples));
- (++j<=noOfOperations)?i++:i) {
- if (myTrans == NULL)
- error_handler4(__LINE__, myNdb.getNdbError().status, myNdb.getNdbError().classification,
- myNdb.getNdbError().code, myNdb.getNdbError().message);
-
- myOp = myTrans->getNdbOperation("THE_TABLE");
- if (myOp == NULL)
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
-
- myOp->updateTuple();
- if (myOp->equal("X", i) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- myNdb.closeTransaction(myTrans);
- break;
- }
- if (myOp->setValue("Y", i+2) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- myNdb.closeTransaction(myTrans);
- break;
- }
- }
- before = NdbTick_CurrentMillisecond();
- if (myTrans->execute( (oneTrans) ? NoCommit : Commit ) == -1)
- {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- myNdb.closeTransaction(myTrans);
- break;
- }
- after = NdbTick_CurrentMillisecond();
- if (noOfOperations == 1)
- printf("Updated 1 tuple, %u msec\n", (Uint32) after - before);
- else
- printf("Update %u tuples, %u msec\n", noOfOperations, (Uint32) after - before);
-
- if (!oneTrans) myNdb.closeTransaction(myTrans);
- }
- if (oneTrans) {
- if (myTrans->execute( Commit ) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- }
- myNdb.closeTransaction(myTrans);
- }
- tafter = NdbTick_CurrentMillisecond();
-
- ndbout << "Updated "<< noOfTuples << " tuples in " << ((oneTrans) ? 1 : noOfTuples) << " transaction(s), " << tafter - tbefore << " msec" << endl;
-}
-
-static void deleteTable(Ndb &myNdb, unsigned int noOfTuples, unsigned int noOfOperations, bool oneTrans, bool twoKey, bool longKey)
-{
- Uint64 tbefore, tafter, before, after;
- NdbConnection *myTrans;
- NdbOperation *myOp;
-
- tbefore = NdbTick_CurrentMillisecond();
- if (oneTrans) myTrans = myNdb.startTransaction();
- for (unsigned int i = 0; i<noOfTuples; i++) {
- if (!oneTrans) myTrans = myNdb.startTransaction();
- for(unsigned int j = 1;
- ((j<=noOfOperations)&&(i<noOfTuples));
- (++j<=noOfOperations)?i++:i) {
- if (myTrans == NULL)
- error_handler4(__LINE__, myNdb.getNdbError().status, myNdb.getNdbError().classification,
- myNdb.getNdbError().code, myNdb.getNdbError().message);
-
- myOp = myTrans->getNdbOperation("THE_TABLE");
- if (myOp == NULL)
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
-
- myOp->deleteTuple();
- if (myOp->equal("X", i) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- myNdb.closeTransaction(myTrans);
- break;
- }
- before = NdbTick_CurrentMillisecond();
- if (myTrans->execute( (oneTrans) ? NoCommit : Commit ) == -1)
- {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- myNdb.closeTransaction(myTrans);
- break;
- }
- }
- after = NdbTick_CurrentMillisecond();
- if (noOfOperations == 1)
- printf("Deleted 1 tuple, %u msec\n", (Uint32) after - before);
- else
- printf("Deleted %u tuples, %u msec\n", noOfOperations, (Uint32) after - before);
-
- if (!oneTrans) myNdb.closeTransaction(myTrans);
- }
- if (oneTrans) {
- if (myTrans->execute( Commit ) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- }
- myNdb.closeTransaction(myTrans);
- }
- tafter = NdbTick_CurrentMillisecond();
-
- ndbout << "Deleted "<< noOfTuples << " tuples in " << ((oneTrans) ? 1 : noOfTuples) << " transaction(s), " << tafter - tbefore << " msec" << endl;
-}
-
-static void readTable(Ndb &myNdb, unsigned int noOfTuples, unsigned int noOfOperations, bool oneTrans, bool twoKey, bool longKey)
-{
- Uint64 tbefore, tafter, before, after;
- NdbConnection *myTrans;
- NdbOperation *myOp;
- NdbRecAttr* myRecAttrArr[MAX_NO_PARALLEL_OPERATIONS];
-
- tbefore = NdbTick_CurrentMillisecond();
- if (oneTrans) myTrans = myNdb.startTransaction();
- for (unsigned int i = 0; i<noOfTuples; i++) {
- if (!oneTrans) myTrans = myNdb.startTransaction();
- for(unsigned int j = 1;
- ((j<=noOfOperations)&&(i<noOfTuples));
- (++j<=noOfOperations)?i++:i) {
- if (myTrans == NULL)
- error_handler4(__LINE__, myNdb.getNdbError().status, myNdb.getNdbError().classification,
- myNdb.getNdbError().code, myNdb.getNdbError().message);
-
- myOp = myTrans->getNdbOperation("THE_TABLE");
- if (myOp == NULL)
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
-
- myOp->readTuple();
- if (myOp->equal("X", i) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- myNdb.closeTransaction(myTrans);
- break;
- }
- myRecAttrArr[j-1] = myOp->getValue("Y", NULL);
- }
- before = NdbTick_CurrentMillisecond();
- if (myTrans->execute( (oneTrans) ? NoCommit : Commit ) == -1)
- {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- myNdb.closeTransaction(myTrans);
- break;
- }
- after = NdbTick_CurrentMillisecond();
- if (noOfOperations == 1)
- printf("Read 1 tuple, %u msec\n", (Uint32) after - before);
- else
- printf("Read %u tuples, %u msec\n", noOfOperations, (Uint32) after - before);
- for(unsigned int j = 0; j<noOfOperations; j++)
- printf("Y = %u\n", myRecAttrArr[j]->u_32_value());
- if (!oneTrans) myNdb.closeTransaction(myTrans);
- }
- if (oneTrans) {
- if (myTrans->execute( Commit ) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- }
- myNdb.closeTransaction(myTrans);
- }
- tafter = NdbTick_CurrentMillisecond();
-
- ndbout << "Read "<< noOfTuples << " tuples in " << ((oneTrans) ? 1 : noOfTuples) << " transaction(s), " << tafter - tbefore << " msec" << endl;
-}
-
-static void readIndex(Ndb &myNdb, unsigned int noOfTuples, unsigned int noOfOperations, bool includePrimary, bool oneTrans, bool longKey)
-{
- Uint64 tbefore, tafter, before, after;
- NdbConnection *myTrans;
- NdbIndexOperation *myOp;
- char indexName[] = "INDEX0000";
- NdbRecAttr* myRecAttrArr[MAX_NO_PARALLEL_OPERATIONS];
-
- tbefore = NdbTick_CurrentMillisecond();
- if (oneTrans) myTrans = myNdb.startTransaction();
- for (unsigned int i = 0; i<noOfTuples; i++) {
- if (!oneTrans) myTrans = myNdb.startTransaction();
- for(unsigned int j = 1;
- ((j<=noOfOperations)&&(i<noOfTuples));
- (++j<=noOfOperations)?i++:i) {
- if (myTrans == NULL)
- error_handler4(__LINE__, myNdb.getNdbError().status, myNdb.getNdbError().classification,
- myNdb.getNdbError().code, myNdb.getNdbError().message);
-
- myOp = myTrans->getNdbIndexOperation(indexName, "THE_TABLE");
- if (myOp == NULL)
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
-
- myOp->readTuple();
- if (includePrimary) {
- if (myOp->equal("X", i) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- myNdb.closeTransaction(myTrans);
- break;
- }
- }
- if (myOp->equal("Y", i+1) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- myNdb.closeTransaction(myTrans);
- break;
- }
- myRecAttrArr[j-1] = myOp->getValue("Y", NULL);
- }
- before = NdbTick_CurrentMillisecond();
- if (myTrans->execute( (oneTrans) ? NoCommit : Commit ) == -1)
- {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- myNdb.closeTransaction(myTrans);
- break;
- }
- after = NdbTick_CurrentMillisecond();
- if (noOfOperations == 1)
- printf("Read 1 tuple, %u msec\n", (Uint32) after - before);
- else
- printf("Read %u tuples, %u msec\n", noOfOperations, (Uint32) after - before);
- for(unsigned int j = 0; j<noOfOperations; j++)
- printf("Y = %u\n", myRecAttrArr[j]->u_32_value());
- if (!oneTrans) myNdb.closeTransaction(myTrans);
- }
- if (oneTrans) {
- if (myTrans->execute( Commit ) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- }
- myNdb.closeTransaction(myTrans);
- }
- tafter = NdbTick_CurrentMillisecond();
-
- ndbout << "Read "<< noOfTuples << " tuples in " << ((oneTrans) ? 1 : noOfTuples) << " transaction(s), " << tafter - tbefore << " msec" << endl;
-}
-
-static void updateIndex(Ndb &myNdb, unsigned int noOfTuples, unsigned int noOfOperations, bool includePrimary, bool oneTrans, bool longKey)
-{
- Uint64 tbefore, tafter, before, after;
- NdbConnection *myTrans;
- NdbIndexOperation *myOp;
- char indexName[] = "INDEX0000";
-
- tbefore = NdbTick_CurrentMillisecond();
- if (oneTrans) myTrans = myNdb.startTransaction();
- for (unsigned int i = 0; i<noOfTuples; i++) {
- if (!oneTrans) myTrans = myNdb.startTransaction();
- for(unsigned int j = 1;
- ((j<=noOfOperations)&&(i<noOfTuples));
- (++j<=noOfOperations)?i++:i) {
- if (myTrans == NULL)
- error_handler4(__LINE__, myNdb.getNdbError().status, myNdb.getNdbError().classification,
- myNdb.getNdbError().code, myNdb.getNdbError().message);
-
- myOp = myTrans->getNdbIndexOperation(indexName, "THE_TABLE");
- if (myOp == NULL)
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
-
- myOp->updateTuple();
- if (includePrimary) {
- if (myOp->equal("X", i) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- myNdb.closeTransaction(myTrans);
- break;
- }
- }
- if (myOp->equal("Y", i+1) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- myNdb.closeTransaction(myTrans);
- break;
- }
- // Update index itself, should be possible
- if (myOp->setValue("Y", i+2) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- myNdb.closeTransaction(myTrans);
- break;
- }
- }
- before = NdbTick_CurrentMillisecond();
- if (myTrans->execute( (oneTrans) ? NoCommit : Commit ) == -1)
- {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- myNdb.closeTransaction(myTrans);
- break;
- }
-
- after = NdbTick_CurrentMillisecond();
- if (noOfOperations == 1)
- printf("Updated 1 tuple, %u msec\n", (Uint32) after - before);
- else
- printf("Updated %u tuples, %u msec\n", noOfOperations, (Uint32) after - before);
- if (!oneTrans) myNdb.closeTransaction(myTrans);
- }
- if (oneTrans) {
- if (myTrans->execute( Commit ) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- }
- myNdb.closeTransaction(myTrans);
- }
- tafter = NdbTick_CurrentMillisecond();
-
- ndbout << "Updated "<< noOfTuples << " tuples in " << ((oneTrans) ? 1 : noOfTuples) << " transaction(s), " << tafter - tbefore << " msec" << endl;
-}
-
-static void deleteIndex(Ndb &myNdb, unsigned int noOfTuples, unsigned int noOfOperations, bool includePrimary, bool oneTrans, bool longKey)
-{
- Uint64 tbefore, tafter, before, after;
- NdbConnection *myTrans;
- NdbIndexOperation *myOp;
- char indexName[] = "INDEX0000";
-
- tbefore = NdbTick_CurrentMillisecond();
- if (oneTrans) myTrans = myNdb.startTransaction();
- for (unsigned int i = 0; i<noOfTuples; i++) {
- for(unsigned int j = 1;
- ((j<=noOfOperations)&&(i<noOfTuples));
- (++j<=noOfOperations)?i++:i) {
- if (!oneTrans) myTrans = myNdb.startTransaction();
- if (myTrans == NULL)
- error_handler4(__LINE__, myNdb.getNdbError().status, myNdb.getNdbError().classification,
- myNdb.getNdbError().code, myNdb.getNdbError().message);
-
- myOp = myTrans->getNdbIndexOperation(indexName, "THE_TABLE");
- if (myOp == NULL)
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
-
- myOp->deleteTuple();
- if (includePrimary) {
- if (myOp->equal("X", i) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- myNdb.closeTransaction(myTrans);
- break;
- }
- }
- if (myOp->equal("Y", i+1) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- myNdb.closeTransaction(myTrans);
- break;
- }
- }
- before = NdbTick_CurrentMillisecond();
- if (myTrans->execute( (oneTrans) ? NoCommit : Commit ) == -1)
- {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- myNdb.closeTransaction(myTrans);
- break;
- }
- after = NdbTick_CurrentMillisecond();
- if (noOfOperations == 1)
- printf("Deleted 1 tuple, %u msec\n", (Uint32) after - before);
- else
- printf("Deleted %u tuples, %u msec\n", noOfOperations, (Uint32) after - before);
- if (!oneTrans) myNdb.closeTransaction(myTrans);
- }
- if (oneTrans) {
- if (myTrans->execute( Commit ) == -1) {
- error_handler4(__LINE__, myTrans->getNdbError().status, myTrans->getNdbError().classification,
- myTrans->getNdbError().code, myTrans->getNdbError().message);
- }
- myNdb.closeTransaction(myTrans);
- }
- tafter = NdbTick_CurrentMillisecond();
-
- ndbout << "Deleted "<< noOfTuples << " tuples in " << ((oneTrans) ? 1 : noOfTuples) << " transaction(s), " << tafter - tbefore << " msec" << endl;
-}
-
-static void dropIndex(Ndb &myNdb, unsigned int noOfIndexes)
-{
- for(unsigned int indexNum = 0; indexNum < noOfIndexes; indexNum++) {
- char indexName[255];
- sprintf(indexName, "INDEX%.4u", indexNum);
- const Uint64 before = NdbTick_CurrentMillisecond();
- const int retVal = myNdb.getDictionary()->dropIndex(indexName,"THE_TABLE");
- const Uint64 after = NdbTick_CurrentMillisecond();
-
- if(retVal == 0){
- ndbout << "Dropped index " << indexName << ", "
- << after - before << " msec" << endl;
- } else {
- ndbout << "Failed to drop index " << indexName << endl;
- ndbout << myNdb.getDictionary()->getNdbError() << endl;
- }
- }
-}
-
-NDB_COMMAND(indexTest, "indexTest", "indexTest", "indexTest", 65535)
-{
- ndb_init();
- bool createTableOp, createIndexOp, dropIndexOp, insertOp, updateOp, deleteOp, readOp, readIndexOp, updateIndexOp, deleteIndexOp, twoKey, longKey;
- unsigned int noOfTuples = 1;
- unsigned int noOfOperations = 1;
- unsigned int noOfIndexes = 1;
- int i = 1;
- Ndb myNdb( "TEST_DB" );
- int check;
- bool storeInACC = false;
- bool includePrimary = false;
- bool oneTransaction = false;
-
- createTableOp = createIndexOp = dropIndexOp = insertOp = updateOp = deleteOp = readOp = readIndexOp = updateIndexOp = deleteIndexOp = twoKey = longKey = false;
- // Read arguments
- if (argc > 1)
- while (argc > 1)
- {
- if (strcmp(argv[i], "-T") == 0)
- {
- createTableOp = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-c") == 0)
- {
- createIndexOp = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-X") == 0)
- {
- dropIndexOp = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-I") == 0)
- {
- insertOp = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-D") == 0)
- {
- deleteOp = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-U") == 0)
- {
- updateOp = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-R") == 0)
- {
- readOp = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-r") == 0)
- {
- readIndexOp = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-u") == 0)
- {
- updateIndexOp = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-d") == 0)
- {
- deleteIndexOp = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-s") == 0)
- {
- storeInACC = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-p") == 0)
- {
- includePrimary = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-L") == 0)
- {
- longKey = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-1") == 0)
- {
- oneTransaction = true;
- argc -= 1;
- i++;
- }
- else if (strcmp(argv[i], "-2") == 0)
- {
- twoKey = true;
- argc -= 1;
- i++;
- }
- else if (strstr(argv[i], "-n") != 0)
- {
- noOfTuples = atoi(argv[i]+2);
- argc -= 1;
- i++;
- }
- else if (strstr(argv[i], "-o") != 0)
- {
- noOfOperations = MIN(MAX_NO_PARALLEL_OPERATIONS, atoi(argv[i]+2));
- argc -= 1;
- i++;
- }
- else if (strstr(argv[i], "-m") != 0)
- {
- noOfIndexes = atoi(argv[i]+2);
- argc -= 1;
- i++;
- }
- else if (strstr(argv[i], "-h") != 0)
- {
- printf("Synopsis: \
- index\
- -T create table\
- -L include a long attribute in key or index\
- -2 define primary key with two attributes\
- -c create index\
- -p make index unique (include primary key attribute)\
- -r read using index\
- -u update using index\
- -d delete using index\
- -n<no operations> do n operations (for -I -r -u -d -R -U -D)\
- -o<no parallel operations> (for -I -r -u -d -R -U -D)\
- -m<no indexes>\n");
- argc -= 1;
- i++;
- }
- else {
- char errStr[256];
-
- sprintf(errStr, "Illegal argument: %s", argv[i]);
- error_handler(errStr);
- exit(-1);
- }
- }
- else
- {
- createTableOp = createIndexOp = dropIndexOp = insertOp = updateOp = deleteOp = true;
- }
- if (longKey) {
- longName = (char *) malloc(1024);
- for (int i = 0; i < 1023; i++)
- longName[i] = 'x';
- longName[1023] = '\0';
- }
- sixtysix = (char *) malloc(256);
- for (int i = 0; i < 255; i++)
- sixtysix[i] = ' ';
- sixtysix[255] = '\0';
- strncpy(sixtysix, "sixtysix", strlen("sixtysix"));
- ninetynine = (char *) malloc(256);
- for (int i = 0; i < 255; i++)
- ninetynine[i] = ' ';
- ninetynine[255] = '\0';
- strncpy(ninetynine, "ninetynine", strlen("ninetynine"));
- hundred = (char *) malloc(256);
- for (int i = 0; i < 255; i++)
- hundred[i] = ' ';
- hundred[255] = '\0';
- strncpy(hundred, "hundred", strlen("hundred"));
- myNdb.init();
- // Wait for Ndb to become ready
- if (myNdb.waitUntilReady(30) == 0)
- {
- if (createTableOp)
- createTable(myNdb, storeInACC, twoKey, longKey);
-
- if (createIndexOp)
- createIndex(myNdb, includePrimary, noOfIndexes);
-
- if (insertOp)
- insertTable(myNdb, noOfTuples, noOfOperations, oneTransaction, twoKey, longKey);
-
- if (updateOp)
- updateTable(myNdb, noOfTuples, noOfOperations, oneTransaction, twoKey, longKey);
-
- if (deleteOp)
- deleteTable(myNdb, noOfTuples, noOfOperations, oneTransaction, twoKey, longKey);
-
- if (readOp)
- readTable(myNdb, noOfTuples, noOfOperations, oneTransaction, twoKey, longKey);
-
- if (readIndexOp)
- readIndex(myNdb, noOfTuples, noOfOperations, includePrimary, oneTransaction, longKey);
-
- if (updateIndexOp)
- updateIndex(myNdb, noOfTuples, noOfOperations, includePrimary, oneTransaction, longKey);
-
- if (deleteIndexOp)
- deleteIndex(myNdb, noOfTuples, noOfOperations, includePrimary, oneTransaction, longKey);
-
- if (dropIndexOp)
- dropIndex(myNdb, noOfIndexes);
- }
-
- if (testPassed)
- {
- // Test passed
- ndbout << "OK - Test passed" << endl;
- }
- else
- {
- // Test failed
- ndbout << "FAIL - Test failed" << endl;
- exit(-1);
- }
- return NULL;
-}
-
-
diff --git a/storage/ndb/test/ndbapi/initronja.cpp b/storage/ndb/test/ndbapi/initronja.cpp
deleted file mode 100644
index 9b96e7e8625..00000000000
--- a/storage/ndb/test/ndbapi/initronja.cpp
+++ /dev/null
@@ -1,332 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-/* ***************************************************
- INITRONJA
- Initialise benchmark for Ronja Database
- * *************************************************** */
-
-#include "NdbApi.hpp"
-#include "NdbSchemaCon.hpp"
-#include <NdbOut.hpp>
-#include <NdbMain.h>
-#include <NdbTest.hpp>
-#include <string.h>
-
-#define MAXSTRLEN 16
-#define MAXATTR 64
-#define MAXTABLES 64
-#define NDB_MAXTHREADS 256
-/*
- NDB_MAXTHREADS used to be just MAXTHREADS, which collides with a
- #define from <sys/thread.h> on AIX (IBM compiler). We explicitly
- #undef it here lest someone use it by habit and get really funny
- results. K&R says we may #undef non-existent symbols, so let's go.
-*/
-#undef MAXTHREADS
-#define MAXATTRSIZE 8000
-
-static unsigned int tNoOfRecords;
-static unsigned int tNoOfLoops;
-static unsigned int tNoOfTables;
-static int tAttributeSize;
-static int tNodeId;
-static unsigned int tValue;
-static unsigned int tNoOfOperations;
-static char tableName[MAXTABLES][MAXSTRLEN];
-static char attrName[MAXATTR][MAXSTRLEN];
-
-inline int InsertRecords(Ndb*, int) ;
-
-NDB_COMMAND(initronja, "initronja", "initronja", "initronja", 65535){
- ndb_init();
-
- Ndb* pNdb = NULL ;
- NdbSchemaCon *MySchemaTransaction = NULL ;
- NdbSchemaOp *MySchemaOp = NULL ;
-
-
- int check, status, i, j, cont ;
- check = status = i = j = cont = 0 ;
- tNoOfRecords = 500 ;
- tNoOfLoops = tNoOfRecords / 10;
-
- i = 1;
- while (argc > 1){
-
- if (strcmp(argv[i], "-r") == 0){
- if( NULL == argv[i+1] ) goto error_input ;
- tNoOfRecords = atoi(argv[i+1]);
- tNoOfRecords = tNoOfRecords - (tNoOfRecords % 10);
- tNoOfLoops = tNoOfRecords / 10;
- if ((tNoOfRecords < 1) || (tNoOfRecords > 1000000000)) goto error_input;
- }else{
- goto error_input;
- }
-
- argc -= 2;
- i = i + 2; //
- }
-
- pNdb = new Ndb( "TEST_DB" ) ;
- ndbout << "Initialisation started. " << endl;
- pNdb->init();
- ndbout << "Initialisation completed. " << endl;
-
- tNodeId = pNdb->getNodeId();
- ndbout << endl << "Initial loading of Ronja Database" << endl;
- ndbout << " NdbAPI node with id = " << tNodeId << endl;
-
- if (pNdb->waitUntilReady(30) != 0) {
- ndbout << "Benchmark failed - NDB is not ready" << endl;
- delete pNdb ;
- return NDBT_ProgramExit(NDBT_FAILED) ;
- }//if
-
- ndbout << endl << "Creating the table SHORT_REC" << "..." << endl;
-
- MySchemaTransaction = NdbSchemaCon::startSchemaTrans(pNdb);
- if(!MySchemaTransaction) goto error_handler;
- MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
- if(!MySchemaOp) goto error_handler;
- check = MySchemaOp->createTable( "SHORT_REC"
- ,8 // Table Size
- ,TupleKey // Key Type
- ,40 // Nr of Pages
- );
- if (check == -1) goto error_handler;
-
- ndbout << "Key attribute..." ;
- check = MySchemaOp->createAttribute( (char*)"Key", TupleKey, 32, 1,
- UnSigned, MMBased, NotNullAttribute );
- if (check == -1) goto error_handler;
- ndbout << "\t\tOK" << endl ;
-
- ndbout << "Flip attribute..." ;
- check = MySchemaOp->createAttribute("Flip", NoKey, 32, 1,
- UnSigned, MMBased, NotNullAttribute );
- if (check == -1) goto error_handler;
- ndbout << "\t\tOK" << endl ;
-
- ndbout << "Count attribute..." ;
- check = MySchemaOp->createAttribute("Count", NoKey, 32, 1,
- UnSigned, MMBased, NotNullAttribute );
- if (check == -1) goto error_handler;
- ndbout << "\t\tOK" << endl ;
-
- ndbout << "Placeholder attribute..." ;
- check = MySchemaOp->createAttribute("Placeholder", NoKey, 8, 90,
- UnSigned, MMBased, NotNullAttribute );
- if (check == -1) goto error_handler;
- ndbout << "\tOK" << endl ;
-
- if (MySchemaTransaction->execute() == -1) {
- if(721 == MySchemaOp->getNdbError().code){
- ndbout << "Table SHORT_REC already exists" << endl ;
- }else{
- ndbout << MySchemaTransaction->getNdbError() << endl;
- }
- }else{
- ndbout << "SHORT_REC created " << endl;
- }// if
-
- NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
-
- ndbout << endl << "Creating the table LONG_REC..." << endl;
-
- MySchemaTransaction = NdbSchemaCon::startSchemaTrans(pNdb);
- if(!MySchemaTransaction) goto error_handler;
-
- MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
- if(!MySchemaOp) goto error_handler;
- check = MySchemaOp->createTable( "LONG_REC"
- ,8 // Table Size
- ,TupleKey // Key Type
- ,40 // Nr of Pages
- );
-
- if (check == -1) goto error_handler;
-
- ndbout << "Key attribute..." ;
- check = MySchemaOp->createAttribute( (char*)"Key", TupleKey, 32, 1,
- UnSigned, MMBased, NotNullAttribute );
- if (check == -1) goto error_handler;
- ndbout << "\t\tOK" << endl ;
-
- ndbout << "Flip attribute..." ;
- check = MySchemaOp->createAttribute("Flip", NoKey, 32, 1,
- UnSigned, MMBased, NotNullAttribute );
- if (check == -1) goto error_handler;
- ndbout << "\t\tOK" << endl ;
-
- ndbout << "Count attribute..." ;
- check = MySchemaOp->createAttribute("Count", NoKey, 32, 1,
- UnSigned, MMBased, NotNullAttribute );
- if (check == -1) goto error_handler;
- ndbout << "\t\tOK" << endl ;
-
- ndbout << "Placeholder attribute..." ;
- check = MySchemaOp->createAttribute("Placeholder", NoKey, 8, 1014,
- UnSigned, MMBased, NotNullAttribute );
- if (check == -1) goto error_handler;
- ndbout << "\tOK" << endl ;
-
- if (MySchemaTransaction->execute() == -1) {
- if(721 == MySchemaOp->getNdbError().code){
- ndbout << "Table LONG_REC already exists" << endl ;
- }else{
- ndbout << MySchemaTransaction->getNdbError() << endl;
- }
- }else{
- ndbout << "LONG_REC created" << endl;
- }// if
-
- NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
-
-
- check = InsertRecords(pNdb, tNoOfRecords);
-
- delete pNdb ;
-
- if(-1 == check){
- ndbout << endl << "Initial loading of Ronja Database failed" << endl;
- return NDBT_ProgramExit(NDBT_FAILED) ;
- }else{
- ndbout << endl << "Initial loading of Ronja Database completed" << endl;
- return NDBT_ProgramExit(NDBT_OK) ;
- }
-
-
-
-
-
-error_handler:
- ndbout << "SchemaTransaction returned error:" ;
- ndbout << MySchemaTransaction->getNdbError() << endl;
- NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
- delete pNdb ;
- NDBT_ProgramExit(NDBT_FAILED) ;
- exit(-1);
-
-error_input:
- ndbout << endl << " Ivalid parameter(s)" << endl;
- ndbout << " Usage: initronja [-r n] , where 'n' is the number of records to be inserted" << endl;
- ndbout << " If omitted, 500 records will be created by default" << endl;
- ndbout << " Note: use this number in combination with '-r' argument when running 'benchronja'" << endl << endl;
- NDBT_ProgramExit(NDBT_WRONGARGS) ;
- exit(1);
-}
-////////////////////////////////////////
-
-inline int InsertRecords(Ndb* pNdb, int nNoRecords){
-
- NdbConnection *MyTransaction = NULL ;
- NdbOperation* MyOperation[10];
-
- int Tsuccess = 0 ;
- int loop_count_ops = 2 * tNoOfLoops;
- int loop_count_tables = 10;
- int loop_count_attributes = 0 ;
- int check = 0;
- int count = 0 ;
- int count_tables = 0;
- int count_attributes = 0 ;
- int i = 0 ;
- int tType = 0 ;
- unsigned int attrValue[1000];
- unsigned int setAttrValue = 0;
- unsigned int keyValue[3];
-
- for (i = 0; i < 1000; i ++) attrValue[i] = 1;
-
- for (count=0 ; count < loop_count_ops ; count++){
- if ((((count / 100)* 100) == count) && (count != 0)){
- ndbout << "1000 records inserted again, " << (count/100) << "000 records now inserted" << endl;
- }
-
- MyTransaction = pNdb->startTransaction();
- if(!MyTransaction){
- ndbout << "startTransaction: " << pNdb->getNdbError();
- ndbout << " count = " << count << endl;
- return -1 ;
- }
-
- for (count_tables = 0; count_tables < loop_count_tables; count_tables++) {
- if (count < tNoOfLoops) {
- keyValue[0] = count*10 + count_tables ;
- MyOperation[count_tables] = MyTransaction->getNdbOperation("SHORT_REC") ;
- }else{
- keyValue[0] = (count - tNoOfLoops)*10 + count_tables;
- MyOperation[count_tables] = MyTransaction->getNdbOperation("LONG_REC");
- }//if
-
- if (!MyOperation[count_tables]) goto error_handler1;
-
- check = MyOperation[count_tables]->insertTuple();
- if (check == -1) goto error_handler2;
-
- check = MyOperation[count_tables]->equal("Key",(char*)&keyValue[0]);
- if (check == -1) goto error_handler4;
-
- check = MyOperation[count_tables]->setValue("Flip",(char*)&setAttrValue);
- if (check == -1) goto error_handler5;
-
- check = MyOperation[count_tables]->setValue("Count",(char*)&setAttrValue);
- if (check == -1) goto error_handler5;
-
- check = MyOperation[count_tables]->setValue("Placeholder",(char*)&attrValue[0]);
- if (check == -1) goto error_handler5;
- }//for
-
- if (MyTransaction->execute( Commit ) == -1){
- ndbout << MyTransaction->getNdbError()<< endl ;
- ndbout << "count = " << count << endl;
- }//if
-
- pNdb->closeTransaction(MyTransaction) ;
- }//for
- return 0;
-
-error_handler1:
- ndbout << "Error occured in getNdbOperation " << endl;
- ndbout << MyTransaction->getNdbError() << endl;
- pNdb->closeTransaction(MyTransaction);
- return -1 ;
-
-error_handler2:
- ndbout << "Error occured in defining operation " << endl;
- ndbout << MyOperation[count_tables]->getNdbError() << endl;
- pNdb->closeTransaction(MyTransaction);
- return -1 ;
-
-error_handler3:
- pNdb->closeTransaction(MyTransaction);
- return -1 ;
-
-error_handler4:
- ndbout << "Error occured in equal " << endl;
- ndbout << MyOperation[count_tables]->getNdbError() << endl;
- pNdb->closeTransaction(MyTransaction);
- return -1 ;
-
-error_handler5:
- ndbout << "Error occured in get/setValue " << endl;
- ndbout << MyOperation[count_tables]->getNdbError() << endl;
- pNdb->closeTransaction(MyTransaction);
- return -1 ;
-
-}
diff --git a/storage/ndb/test/ndbapi/interpreterInTup.cpp b/storage/ndb/test/ndbapi/interpreterInTup.cpp
deleted file mode 100644
index c525b70d277..00000000000
--- a/storage/ndb/test/ndbapi/interpreterInTup.cpp
+++ /dev/null
@@ -1,1518 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-/* ***************************************************
- TEST OF INTERPRETER IN TUP
- Verify that the interpreter in TUP is able to
- handle and execute all the commands that the
- NdbApi can isssue
-
- Arguments:
-
- operationType 1 openScanRead,
- 2 openScanExclusive,
- 3 interpretedUpdateTuple,
- 4 interpretedDirtyUpdate,
- 5 interpretedDeleteTuple
- 6 deleteTuple
- 7 insertTuple
- 8 updateTuple
- 9 writeTuple
- 10 readTuple
- 11 readTupleExclusive
- 12 simpleRead
- 13 dirtyRead
- 14 dirtyUpdate
- 15 dirtyWrite
-
- tupTest 1 exitMethods
- 2 incValue
- 3 subValue
- 4 readAttr
- 5 writeAttr
- 6 loadConst
- 7 branch
- 8 branchIfNull
- 9 addReg
- 10 subReg
- 11 subroutineWithBranchLabel
-
- scanTest Number of the test within each tupTest
-
-* *************************************************** */
-
-#include <NdbOut.hpp>
-#include <NdbThread.h>
-#include <NdbMutex.h>
-#include <NdbApi.hpp>
-#include <NdbSchemaCon.hpp>
-#include <NDBT.hpp>
-
-#define MAXATTR 3
-#define MAXTABLES 12
-#define MAXSTRLEN 8
-#define NUMBEROFRECORDS 1000
-
-typedef enum {
- FAIL = 0,
- NO_FAIL,
- UNDEF
-} TTYPE;
-
-inline void setAttrNames() ;
-inline void setTableNames() ;
-void error_handler(const NdbError & err, TTYPE);
-void create_table(Ndb*);
-void write_rows(Ndb*);
-void update_rows(Ndb*, int, int);
-void delete_rows(Ndb*, int, int);
-void verify_deleted(Ndb*);
-void read_and_verify_rows(Ndb*, bool pre);
-void scan_rows(Ndb*, int, int, int);
-TTYPE t_exitMethods(int, NdbOperation*, int);
-TTYPE t_incValue(int, NdbOperation*);
-TTYPE t_subValue(int, NdbOperation*);
-TTYPE t_readAttr(int, NdbOperation*);
-TTYPE t_writeAttr(int, NdbOperation*);
-TTYPE t_loadConst(int, NdbOperation*, int);
-TTYPE t_branch(int, NdbOperation*);
-TTYPE t_branchIfNull(int, NdbOperation*);
-TTYPE t_addReg(int, NdbOperation*);
-TTYPE t_subReg(int, NdbOperation*);
-TTYPE t_subroutineWithBranchLabel(int, NdbOperation*);
-
-char tableName[MAXSTRLEN+1];
-char attrName[MAXATTR][MAXSTRLEN+1];
-int attrValue[NUMBEROFRECORDS] = {0};
-int pkValue[NUMBEROFRECORDS] = {0};
-const int tAttributeSize = 1 ;
-const int nRecords = 20 ;
-int bTestPassed = 0;
-
-
-
-int main(int argc, const char** argv) {
- ndb_init();
-
- int operationType = 0;
- int tupTest = 0;
- int scanTest = 0;
-
- Ndb* pNdb = new Ndb("TEST_DB");
- pNdb->init();
-
- if (argc != 4 || sscanf(argv[1],"%d", &operationType) != 1) {
- operationType = 1 ;
- }
- if (argc != 4 || sscanf(argv[2],"%d", &tupTest) != 1) {
- tupTest = 1 ;
- }
- if (argc != 4 || sscanf(argv[3],"%d", &scanTest) != 1) {
- scanTest = 1 ;
- }
-
- ndbout << endl
- << "Test the interpreter in TUP using SimpleTable with\n"
- << nRecords << " records" << endl << endl ;
-
- if (pNdb->waitUntilReady(30) != 0) {
- ndbout << "NDB is not ready" << endl;
- return -1;
- }
-
- // Init the pk and attr values.
- for (int i = 0; i < NUMBEROFRECORDS; i ++)
- pkValue[i] = attrValue[i] = i ;
-
- setAttrNames() ;
- setTableNames() ;
-
- const void * p = NDBT_Table::discoverTableFromDb(pNdb, tableName);
- if (p != 0){
- create_table(pNdb);
- }
-
- write_rows(pNdb);
-
- ndbout << endl << "Starting interpreter in TUP test." << endl << "Operation type: " ;
-
- switch(operationType) {
- case 1:
- ndbout << "openScanRead" << endl;
- scan_rows(pNdb, operationType, tupTest, scanTest);
- break;
- case 2:
- ndbout << "openScanExclusive" << endl;
- scan_rows(pNdb, operationType, tupTest, scanTest);
- break;
- case 3:
- ndbout << "interpretedUpdateTuple" << endl;
- update_rows(pNdb, tupTest, operationType);
- break;
- case 4:
- ndbout << "interpretedDirtyUpdate" << endl;
- update_rows(pNdb, tupTest, operationType);
- break;
- case 5:
- ndbout << "interpretedDeleteTuple" << endl;
- delete_rows(pNdb, tupTest, operationType);
- break;
- case 6:
- ndbout << "deleteTuple" << endl;
- break;
- case 7:
- ndbout << "insertTuple" << endl;
- break;
- case 8:
- ndbout << "updateTuple" << endl;
- break;
- case 9:
- ndbout << "writeTuple" << endl;
- break;
- case 10:
- ndbout << "readTuple" << endl;
- break;
- case 11:
- ndbout << "readTupleExclusive" << endl;
- break;
- case 12:
- ndbout << "simpleRead" << endl;
- break;
- case 13:
- ndbout << "dirtyRead" << endl;
- break;
- case 14:
- ndbout << "dirtyUpdate" << endl;
- break;
- case 15:
- ndbout << "dirtyWrite" << endl;
- break;
- default:
- break ;
-
- }
-
-// read_and_verify_rows(pNdb, false);
-
-// delete_rows(pNdb, 0, 0) ;
- delete pNdb ;
-
- if (bTestPassed == 0) {
- ndbout << "OK: test passed" << endl;
- exit(0);
- }else{
- ndbout << "FAIL: test failed" << endl;
- exit(-1);
- }
-}
-
-void error_handler(const NdbError & err, TTYPE type_expected) {
-
- ndbout << err << endl ;
-
- switch (type_expected){
- case NO_FAIL:
- bTestPassed = -1 ;
- break ;
- case FAIL:
- ndbout << "OK: error is expected" << endl;
- break ;
- case UNDEF:
- ndbout << "assumed OK: expected result undefined" << endl ;
- break ;
- default:
- break ;
- }
-}
-
-void create_table(Ndb* pMyNdb) {
-
- /****************************************************************
- * Create SimpleTable and Attributes.
- *
- * create table SimpleTable1(
- * col0 int,
- * col1 int not null,
- * col2 int not null,
- * col3 int not null ... 129)
- *
- ***************************************************************/
-
- int check = -1 ;
- NdbSchemaOp *MySchemaOp = NULL ;
-
- ndbout << endl << "Creating " << tableName << " ... " << endl;
-
- NdbSchemaCon* MySchemaTransaction = NdbSchemaCon::startSchemaTrans(pMyNdb);
- if(!MySchemaTransaction) error_handler(MySchemaTransaction->getNdbError(), NO_FAIL);
-
- MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
- if( !MySchemaOp ) error_handler(MySchemaTransaction->getNdbError(), NO_FAIL);
- // Create table
- check = MySchemaOp->createTable( tableName,
- 8, // Table size
- TupleKey, // Key Type
- 40 // Nr of Pages
- );
-
- if( check == -1 ) error_handler(MySchemaTransaction->getNdbError(), NO_FAIL);
-
- ndbout << "Creating attributes ... " << flush;
-
- // Create first column, primary key
- check = MySchemaOp->createAttribute( attrName[0],
- TupleKey,
- 32,
- 1/*3, tAttributeSize */,
- UnSigned,
- MMBased,
- NotNullAttribute );
-
- if( check == -1 ) error_handler(MySchemaTransaction->getNdbError(), NO_FAIL);
-
- // create the 2 .. n columns.
- for ( int i = 1; i < MAXATTR; i++ ){
- check = MySchemaOp->createAttribute( attrName[i],
- NoKey,
- 32,
- tAttributeSize,
- UnSigned,
- MMBased,
- NotNullAttribute );
-
- if( check == -1 ) error_handler(MySchemaTransaction->getNdbError(), NO_FAIL);
- }
-
- ndbout << "OK" << endl;
-
- if( MySchemaTransaction->execute() == -1 ) {
- ndbout << MySchemaTransaction->getNdbError() << endl;
- }else{
- ndbout << tableName[0] << " created" << endl;
- }
-
-
- NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
-
- return;
-
-}
-
-
-
-void write_rows (Ndb* pMyNdb) {
-
- /****************************************************************
- * Insert rows into SimpleTable
- *
- ***************************************************************/
-
- int check = -1 ;
- int loop_count_ops = nRecords ;
- NdbOperation *MyOperation = NULL ;
- NdbConnection *MyTransaction = NULL ;
-
- ndbout << endl << "Writing records ..." << flush;
-
- for (int count=0 ; count < loop_count_ops ; count++){
- MyTransaction = pMyNdb->startTransaction();
- if (!MyTransaction) {
- error_handler(pMyNdb->getNdbError(), NO_FAIL);
- }//if
-
- MyOperation = MyTransaction->getNdbOperation(tableName);
- if (!MyOperation) {
- error_handler(pMyNdb->getNdbError(), NO_FAIL);
- }//if
-
- check = MyOperation->writeTuple();
- if( check == -1 ) error_handler(MyTransaction->getNdbError(), NO_FAIL);
-
- check = MyOperation->equal( attrName[0],(char*)&pkValue[count] );
- if( check == -1 ) error_handler(MyTransaction->getNdbError(), NO_FAIL);
-
- // Update the columns, index column already ok.
- for (int i = 1 ; i < MAXATTR; i++){
- if ((i == 2) && (count > 4)){
- check = MyOperation->setValue(attrName[i], (char*)&attrValue[count + 1]);
- }else{
- check = MyOperation->setValue(attrName[i], (char*)&attrValue[count]);
- }
- if( check == -1 ) error_handler(MyTransaction->getNdbError(), NO_FAIL);
- }
- check = MyTransaction->execute( Commit );
- if(check == -1 ) error_handler(MyTransaction->getNdbError(), NO_FAIL);
-
- pMyNdb->closeTransaction(MyTransaction);
- }
- ndbout <<" \tOK" << endl;
- return;
-}
-
-void verify_deleted(Ndb* pMyNdb) {
-
- int check = -1 ;
- int loop_count_ops = nRecords;
- NdbOperation* pMyOperation = NULL ;
-
- ndbout << "Verifying deleted records..."<< flush;
-
- for (int count=0 ; count < loop_count_ops ; count++){
-
- NdbConnection* pMyTransaction = pMyNdb->startTransaction();
- if (!pMyTransaction) error_handler(pMyNdb->getNdbError(), NO_FAIL);
-
- pMyOperation = pMyTransaction->getNdbOperation(tableName);
- if (!pMyOperation) error_handler(pMyNdb->getNdbError(), NO_FAIL);
-
- check = pMyOperation->readTuple();
- if( check == -1 ) error_handler( pMyTransaction->getNdbError(), NO_FAIL);
-
- check = pMyOperation->equal( attrName[0],(char*)&pkValue[count] );
- if( check == -1 ) error_handler( pMyTransaction->getNdbError(), NO_FAIL);
-
- // Exepect to receive an error
- if(pMyTransaction->execute(Commit) != -1)
- if( 626 == pMyTransaction->getNdbError().code){
- ndbout << pMyTransaction->getNdbError() << endl ;
- ndbout << "OK" << endl ;
- }else{
- error_handler(pMyTransaction->getNdbError(), NO_FAIL) ;
- }
-
- pMyNdb->closeTransaction(pMyTransaction);
- }
-
- ndbout << "OK" << endl;
- return;
-};
-
-void read_and_verify_rows(Ndb* pMyNdb, bool pre) {
-
- int check = -1 ;
- int loop_count_ops = nRecords;
- char expectedCOL1[NUMBEROFRECORDS] = {0} ;
- char expectedCOL2[NUMBEROFRECORDS] = {0} ;
- NdbConnection *pMyTransaction = NULL ;
- NdbOperation *MyOp = NULL ;
- NdbRecAttr* tTmp = NULL ;
- int readValue[MAXATTR] = {0} ;
-
- ndbout << "Verifying records...\n"<< endl;
-
- for (int count=0 ; count < loop_count_ops ; count++){
-
- pMyTransaction = pMyNdb->startTransaction();
- if (!pMyTransaction) error_handler(pMyNdb->getNdbError(), NO_FAIL);
-
- MyOp = pMyTransaction->getNdbOperation(tableName);
- if (!MyOp) error_handler( pMyTransaction->getNdbError(), NO_FAIL);
-
-
- check = MyOp->readTuple();
- if( check == -1 ) error_handler( MyOp->getNdbError(), NO_FAIL);
-
- check = MyOp->equal( attrName[0],(char*)&pkValue[count] );
- if( check == -1 ) error_handler( MyOp->getNdbError(), NO_FAIL);
-
- for (int count_attributes = 1; count_attributes < MAXATTR; count_attributes++){
-
- tTmp = MyOp->getValue( (char*)attrName[count_attributes], (char*)&readValue[count_attributes] );
- if(!tTmp) error_handler( MyOp->getNdbError(), NO_FAIL);
- }
-
- if( pMyTransaction->execute( Commit ) == -1 ) {
- error_handler(pMyTransaction->getNdbError(), NO_FAIL);
- } else {
- if (pre) {
- expectedCOL1[count] = readValue[1];
- expectedCOL2[count] = readValue[2];
- }
-
- ndbout << attrName[1] << "\t " << readValue[1] << "\t "
- << attrName[2] << "\t " << readValue[2] << endl;
- }
-
- pMyNdb->closeTransaction(pMyTransaction);
-
- }
-
- ndbout << "\nOK\n" << endl;
-
- return;
-
-};
-
-TTYPE t_exitMethods(int nCalls, NdbOperation * pOp, int opType) {
-
- ndbout << "Defining exitMethods test " << nCalls << ": " << endl ;;
- TTYPE ret_val = NO_FAIL ;
-
- switch(nCalls){
- case 1: // exit_nok if attr value matches
- pOp->read_attr("COL1", 1);
- pOp->load_const_u32(2, 14);
- pOp->branch_eq(1, 2, 0);
- pOp->interpret_exit_ok() ;
- pOp->def_label(0);
- pOp->interpret_exit_nok();
- break;
- case 2: // exit_ok if attr value doesn't match
- pOp->read_attr("COL1", 1);
- pOp->load_const_u32(2, 14);
- pOp->branch_eq(1, 2, 0);
- pOp->interpret_exit_nok() ;
- pOp->def_label(0);
- if (opType == 3) {
- // For update transactions use incValue to update the tuple
- Uint32 val32 = 5;
- pOp->incValue("COL2", val32);
- }
- pOp->interpret_exit_ok();
- break ;
- case 3: // Non-existent value (128): exit_ok if if the value matches
- pOp->read_attr("COL1", 1);
- pOp->load_const_u32(2, 128);
- pOp->branch_eq(1, 2, 0);
- pOp->interpret_exit_nok();
- pOp->def_label(0);
- pOp->interpret_exit_ok();
- ret_val = FAIL ;
- break;
- case 4: // Non-existent value (128): exit_nok if the value matches
- pOp->read_attr("COL1", 1);
- pOp->load_const_u32(2, 128);
- pOp->branch_eq(1, 2, 0);
- pOp->interpret_exit_ok();
- pOp->def_label(0);
- pOp->interpret_exit_nok();
- ret_val = FAIL ;
- break;
- case 5: // exit_nok of the value matches
- pOp->read_attr("COL1", 1);
- pOp->load_const_u32(2, 2);
- pOp->branch_eq(1, 2, 0);
- pOp->interpret_exit_ok();
- pOp->def_label(0);
- pOp->interpret_exit_nok();
- break ;
- case 6: // exit_ok of the value matches
- pOp->read_attr("COL1", 1);
- pOp->load_const_u32(2, 2);
- pOp->branch_eq(1, 2, 0);
- pOp->interpret_exit_nok();
- pOp->def_label(0);
- if (opType == 3) {
- // For update transactions use incValue to update the tuple
- Uint32 val32 = 5;
- pOp->incValue("COL2", val32);
- }
- pOp->interpret_exit_ok();
- break;
- case 7: // exit_nok if the value matches
- pOp->read_attr("COL1", 1);
- pOp->load_const_u32(2, 6);
- pOp->branch_eq(1, 2, 0);
- pOp->interpret_exit_ok();
- pOp->def_label(0);
- pOp->interpret_exit_nok();
- break;
- case 8: // exit_ok if the value matches
- pOp->read_attr("COL1", 1);
- pOp->load_const_u32(2, 6);
- pOp->branch_ne(1, 2, 0);
- pOp->interpret_exit_nok();
- pOp->def_label(0);
- if (opType == 3) {
- // For update transactions use incValue to update the tuple
- Uint32 val32 = 5;
- pOp->incValue("COL2", val32);
- }
- pOp->interpret_exit_ok();
- break ;
- case 9: // exit_nok if the value matches
- pOp->read_attr("COL1", 1);
- pOp->load_const_u32(2, 8);
- pOp->branch_eq(1, 2, 0);
- pOp->interpret_exit_ok();
- pOp->def_label(0);
- pOp->interpret_exit_nok();
- break;
- case 10: // exit_ok if the value matches
- pOp->read_attr("COL1", 1);
- pOp->load_const_u32(2, 8);
- pOp->branch_eq(1, 2, 0);
- pOp->interpret_exit_nok();
- pOp->def_label(0);
- if (opType == 3) {
- // For update transactions use incValue to update the tuple
- Uint32 val32 = 5;
- pOp->incValue("COL2", val32);
- }
- pOp->interpret_exit_ok();
- break;
- case 11: // exit_nok if the value matches
- pOp->read_attr("COL1", 1);
- pOp->load_const_u32(2, 10);
- pOp->branch_eq(1, 2, 0);
- pOp->interpret_exit_ok();
- pOp->def_label(0);
- pOp->interpret_exit_nok();
- break;
- case 12:
- pOp->read_attr("COL1", 1);
- pOp->load_const_u32(2, 10);
- pOp->branch_eq(1, 2, 0);
- pOp->interpret_exit_nok();
- pOp->def_label(0);
- if (opType == 3) {
- // For update transactions use incValue to update the tuple
- Uint32 val32 = 5;
- pOp->incValue("COL2", val32);
- }
- pOp->interpret_exit_ok();
- break;
- case 13:
- pOp->read_attr("COL1", 1);
- pOp->load_const_u32(2, 10);
- pOp->branch_eq(1, 2, 0);
- pOp->interpret_exit_ok();
- pOp->def_label(0);
- pOp->interpret_exit_nok();
- break;
- case 14: // exit_nok if the value matches
- pOp->read_attr("COL1", 1);
- pOp->load_const_u32(2, 12);
- pOp->branch_eq(1, 2, 0);
- pOp->interpret_exit_ok();
- pOp->def_label(0);
- pOp->interpret_exit_nok();
- break;
- case 15: // exit_ok if the value matches
- pOp->read_attr("COL1", 1);
- pOp->load_const_u32(2, 12);
- pOp->branch_eq(1, 2, 0);
- pOp->interpret_exit_nok();
- pOp->def_label(0);
- if (opType == 3) {
- // For update transactions use incValue to update the tuple
- Uint32 val32 = 5;
- pOp->incValue("COL2", val32);
- }
- pOp->interpret_exit_ok();
- case 16:
- pOp->interpret_exit_nok();
- ret_val = FAIL ;
- break;
- case 17:
- pOp->interpret_exit_ok();
- break ;
- case 18:
- pOp->interpret_exit_nok();
- ret_val = FAIL ;
- break ;
- default:
- break ;
- }
- return ret_val;
-}
-
-TTYPE t_incValue(int nCalls, NdbOperation* pOp) {
-
- ndbout << "Defining incValue test " << nCalls << ": ";
- TTYPE ret_val = NO_FAIL;
-
- Uint32 val32 = 5;
- Uint64 val64 = 5;
- Uint32 attr0 = 0;
- Uint32 attr1 = 1;
- Uint32 attr20 = 20;
-
- switch(nCalls) {
- case 1:
- pOp->incValue(attrName[1], val32);
- break;
- case 2:
- pOp->incValue(attr1, val32);
- break;
- case 3:
- pOp->incValue(attrName[1], val64);
- break;
- case 4:
- pOp->incValue(attr1, val64);
- break;
- case 5:
- pOp->incValue(attrName[0], val32);
- ret_val = FAIL ;
- break;
- case 6:
- pOp->incValue(attrName[0], val64);
- ret_val = FAIL ;
- break;
- case 7:
- pOp->incValue(attr0, val32);
- ret_val = FAIL ;
- break;
- case 8:
- pOp->incValue(attr0, val64);
- ret_val = FAIL ;
- break;
- case 9:
- pOp->incValue("COL20", val32);
- ret_val = FAIL ;
- break;
- case 10:
- pOp->incValue("COL20", val64);
- ret_val = FAIL ;
- break;
- case 11:
- pOp->incValue(attr20, val32);
- ret_val = FAIL ;
- break;
- case 12:
- pOp->incValue(attr20, val64);
- ret_val = FAIL ;
- break;
- default:
- break ;
- }
- return ret_val;
-}
-
-TTYPE t_subValue(int nCalls, NdbOperation* pOp) {
-
- ndbout << "Defining subValue test " << nCalls << ": ";
-
- Uint32 val32 = 5;
- Uint64 val64 = 5;
- Uint32 attr0 = 0;
- Uint32 attr1 = 1;
- Uint32 attr20 = 20;
-
- TTYPE ret_val = NO_FAIL;
-
- switch(nCalls) {
- case 1:
- pOp->subValue("COL2", val32);
- break;
- case 2:
- pOp->subValue(attr1, val32);
- break;
- case 3:
- pOp->subValue("COL0", val32);
- ret_val = FAIL ;
- break;
- case 4:
- pOp->subValue(attr0, val32);
- ret_val = FAIL ;
- break;
- case 5:
- pOp->subValue("COL20", val32);
- ret_val = FAIL ;
- break;
- case 6:
- pOp->subValue(attr20, val32);
- ret_val = FAIL ;
- break;
- case 7:
- // Missing implementation
- //pOp->subValue("COL20", val64);
- ndbout << "Missing implementation" << endl;
- break;
- case 8:
- // Missing implementation
- //pOp->subValue("COL2", val64);
- ndbout << "Missing implementation" << endl;
- break;
- case 9:
- // Missing implementation
- //pOp->subValue("COL0", val64);
- ndbout << "Missing implementation" << endl;
- break;
- case 10:
- // Missing implementation
- //pOp->subValue(attr1, val64);
- ndbout << "Missing implementation" << endl;
- break;
- case 11:
- // Missing implementation
- //pOp->subValue(attr0, val64);
- ndbout << "Missing implementation" << endl;
- break;
- case 12:
- // Missing implementation
- //pOp->subValue(attr20, val64);
- ndbout << "Missing implementation" << endl;
- break;
- default:
- break ;
- }
- return ret_val ;
-}
-
-TTYPE t_readAttr(int nCalls, NdbOperation* pOp) {
-
- ndbout << "Defining readAttr test " << nCalls << ": ";
-
- Uint32 attr0 = 0;
- Uint32 attr1 = 1;
- Uint32 attr20 = 20;
- TTYPE ret_val = NO_FAIL;
-
- switch(nCalls) {
- case 1:
- pOp->read_attr("COL1", 1);
- break;
- case 2:
- pOp->read_attr(attr1, 1);
- ret_val = NO_FAIL ;
- break;
- case 3:
- pOp->read_attr("COL0", 1);
- ret_val = NO_FAIL ;
- break;
- case 4:
- pOp->read_attr(attr0, 1);
- ret_val = NO_FAIL ;
- break;
- case 5:
- pOp->read_attr("COL20", 1);
- ret_val = FAIL ;
- break;
- case 6:
- pOp->read_attr(20, 1);
- ret_val = FAIL ;
- break;
- case 7:
- pOp->read_attr("COL1", 8);
- ret_val = FAIL ;
- break;
- case 8:
- pOp->read_attr(attr1, 8);
- ret_val = FAIL ;
- break;
- default:
- break ;
- }
- return ret_val;
-}
-
-TTYPE t_writeAttr(int nCalls, NdbOperation* pOp) {
-
- ndbout << "Defining writeAttr test " << nCalls << ": ";
-
- pOp->load_const_u32(1, 5);
-
- Uint32 attr0 = 0;
- Uint32 attr1 = 1;
- Uint32 attr20 = 20;
- TTYPE ret_val = NO_FAIL ;
-
- switch(nCalls) {
- case 1:
- pOp->write_attr("COL1", 1);
- break;
- case 2:
- pOp->write_attr(attr1, 1);
- break;
- case 3:
- pOp->write_attr("COL0", 1);
- ret_val = FAIL ;
- break;
- case 4:
- pOp->write_attr(attr0, 1);
- ret_val = FAIL ;
- break;
- case 5:
- pOp->write_attr("COL20", 1);
- ret_val = FAIL ;
- break;
- case 6:
- pOp->write_attr(20, 1);
- ret_val = FAIL ;
- break;
- case 7:
- pOp->write_attr("COL1", 2);
- ret_val = FAIL ;
- break;
- case 8:
- pOp->write_attr(attr1, 2);
- ret_val = FAIL ;
- break;
- case 9:
- pOp->write_attr("COL1", 8);
- ret_val = FAIL ;
- break;
- case 10:
- pOp->write_attr(attr1, 8);
- ret_val = FAIL ;
- break;
- default:
- break ;
- }
- return ret_val ;
-}
-
-TTYPE t_loadConst(int nCalls, NdbOperation* pOp, int opType) {
-
- ndbout << "Defining loadConst test " << nCalls << " : ";
- TTYPE ret_val = NO_FAIL ;
-
- switch(nCalls) {
- case 1:
- // Loading null into a valid register
- pOp->load_const_null(1);
- break;
- case 2:
- // Loading null into an invalid register
- pOp->load_const_null(8);
- ret_val = FAIL ;
- break;
- case 3:
- // Test loading a 32-bit value (>65536)
- pOp->load_const_u32(1, 65600);
- break;
- case 4:
- // Test loading a 16-bit value (<65536)
- pOp->load_const_u32(1, 65500);
- break;
- case 5:
- // Test by loading to a non-valid register
- pOp->load_const_u32(8, 2);
- ret_val = FAIL ;
- break;
- case 6:
- // Test by loading a 64-bit value
- pOp->load_const_u64(1, 65600);
- break;
- case 7:
- // Test by loading a non-valid register
- pOp->load_const_u64(8, 2);
- ret_val = FAIL ;
- break;
- case 8:
- // Test by loading a valid register with -1
- pOp->load_const_u64(1, -1);
- ret_val = FAIL ;
- break;
-
- default:
- break ;
- }
-
- if (opType == 3 && FAIL != ret_val)
- pOp->write_attr("COL1", 1);
- return ret_val;
-}
-
-TTYPE t_branch(int nCalls, NdbOperation* pOp) {
-
- ndbout << "Defining branch test " << nCalls << ": " ;
-
- TTYPE ret_val = NO_FAIL ;
- Uint32 val32=5;
-
- pOp->read_attr("COL1", 1);
- pOp->load_const_u32(2, val32);
-
- switch(nCalls) {
- case 1:
- pOp->branch_eq(1, 2, 0);
- pOp->interpret_exit_nok();
- pOp->def_label(0);
- pOp->interpret_exit_ok();
- break;
- case 2:
- pOp->branch_eq(2, 1, 0);
- pOp->interpret_exit_nok();
- pOp->def_label(0);
- pOp->interpret_exit_ok();
- break;
- case 3:
- pOp->branch_eq(1, 1, 0);
- pOp->interpret_exit_nok();
- pOp->def_label(0);
- pOp->interpret_exit_ok();
- break;
- default:
- //ndbout << "t_branch: default case (no test case)" << endl ;
- //return ret_val = NO_FAIL ;
- break ;
- }
- return ret_val;
-}
-
-TTYPE t_branchIfNull(int nCalls, NdbOperation* pOp) {
-
- TTYPE ret_val = NO_FAIL;
- ndbout << "Defining branchIfNull test " << nCalls << ": " << endl ;
-
- switch(nCalls) {
- case 1:
- pOp->load_const_u32(1, 1);
- pOp->branch_ne_null(1, 0);
- pOp->interpret_exit_nok();
- pOp->def_label(0);
- pOp->interpret_exit_ok();
- break;
- case 2:
- pOp->load_const_null(1);
- pOp->branch_ne_null(1, 0);
- pOp->interpret_exit_ok();
- pOp->def_label(0);
- pOp->interpret_exit_nok();
- break;
- case 3:
- pOp->load_const_u32(1, 1);
- pOp->branch_eq_null(1, 0);
- pOp->interpret_exit_ok();
- pOp->def_label(0);
- pOp->interpret_exit_nok();
- break;
- case 4:
- pOp->load_const_null(1);
- pOp->branch_ne_null(1, 0);
- pOp->interpret_exit_ok();
- pOp->def_label(0);
- pOp->interpret_exit_nok();
- break;
- case 5:
- // Test with a non-initialized register
- pOp->branch_ne_null(3, 0);
- pOp->interpret_exit_ok();
- pOp->def_label(0);
- pOp->interpret_exit_nok();
- ret_val = FAIL ;
- break;
- case 6:
- // Test with a non-existing register
- pOp->branch_ne_null(8, 0);
- pOp->interpret_exit_ok();
- pOp->def_label(0);
- pOp->interpret_exit_nok();
- ret_val = FAIL ;
- break;
- case 7:
- // Test with a non-initialized register
- pOp->branch_eq_null(3, 0);
- pOp->interpret_exit_ok();
- pOp->def_label(0);
- pOp->interpret_exit_nok();
- ret_val = FAIL ;
- break;
- case 8:
- // Test with a non-existing register
- pOp->branch_ne_null(8, 0);
- pOp->interpret_exit_ok();
- pOp->def_label(0);
- pOp->interpret_exit_nok();
- ret_val = FAIL ;
- break;
- default:
- break ;
- }
-
- return ret_val;
-}
-
-TTYPE t_addReg(int nCalls, NdbOperation* pOp) {
-
- TTYPE ret_val = NO_FAIL ;
-
- ndbout << "Defining addReg test " << nCalls << ": ";
-
- pOp->load_const_u32(1, 65500);
- pOp->load_const_u32(2, 500);
- pOp->load_const_u64(3, 65600);
- pOp->load_const_u64(4, 95600);
-
- switch(nCalls) {
- case 1:
- pOp->add_reg(1, 2, 5);
- break;
- case 2:
- pOp->add_reg(1, 3, 5);
- break;
- case 3:
- pOp->add_reg(3, 1, 5);
- break;
- case 4:
- pOp->add_reg(3, 4, 5);
- break;
- case 5:
- pOp->add_reg(1, 6, 5);
- break;
- case 6:
- pOp->add_reg(6, 1, 5);
- break;
- case 7: // illegal register
- pOp->add_reg(1, 8, 5);
- ret_val = FAIL ;
- break;
- case 8: // another illegal register
- pOp->add_reg(8, 1, 5);
- ret_val = FAIL ;
- break;
- case 9: // and another one
- pOp->add_reg(1, 2, 8);
- ret_val = FAIL ;
- break;
- default:
- break ;
- }
- pOp->load_const_u32(7, 65000);
- pOp->branch_eq(5, 7, 0);
- pOp->interpret_exit_nok();
- pOp->def_label(0);
- pOp->interpret_exit_ok();
-
- return ret_val ;
-}
-
-TTYPE t_subReg(int nCalls, NdbOperation* pOp) {
-
- TTYPE ret_val = NO_FAIL ;
- ndbout << "Defining subReg test: " << nCalls << endl;
-
- pOp->load_const_u32(1, 65500);
- pOp->load_const_u32(2, 500);
- pOp->load_const_u64(3, 65600);
- pOp->load_const_u64(4, 95600);
-
- switch(nCalls) {
- case 1:
- pOp->sub_reg(1, 2, 5);
- pOp->load_const_u32(7, 65000);
- break;
- case 2:
- pOp->sub_reg(1, 3, 5);
- pOp->load_const_u64(7, (Uint64)-100);
- break;
- case 3:
- pOp->sub_reg(3, 1, 5);
- pOp->load_const_u64(7, (Uint64)100);
- break;
- case 4:
- pOp->sub_reg(3, 4, 5);
- pOp->load_const_u64(7, (Uint64)-30000);
- break;
- case 5:
- pOp->sub_reg(1, 6, 5);
- pOp->load_const_u64(7, 0);
- ret_val = FAIL ;
- break;
- case 6:
- pOp->sub_reg(6, 1, 5);
- pOp->load_const_u64(7, 0);
- ret_val = FAIL ;
- break;
- case 7:
- pOp->sub_reg(1, 8, 5);
- pOp->load_const_u64(7, 0);
- ret_val = FAIL ;
- break;
- case 8:
- pOp->sub_reg(8, 1, 5);
- pOp->load_const_u64(7, 0);
- ret_val = FAIL ;
- break;
- case 9:
- pOp->sub_reg(1, 2, 8);
- pOp->load_const_u32(7, (Uint32)65000);
- ret_val = FAIL;
- break;
- default:
- //ndbout << "t_subReg: default case (no test case)" << endl ;
- //return ret_val = NO_FAIL ;
- break ;
- }
- pOp->branch_eq(5, 7, 0);
- pOp->interpret_exit_nok() ;
- pOp->def_label(0);
- pOp->interpret_exit_ok() ;
-
- return ret_val;
-}
-
-TTYPE t_subroutineWithBranchLabel(int nCalls, NdbOperation* pOp) {
-
- TTYPE ret_val = NO_FAIL ;
- ndbout << "Defining subroutineWithBranchLabel test:" << nCalls << endl;
-
- pOp->load_const_u32(1, 65500);
- pOp->load_const_u32(2, 500);
- pOp->load_const_u64(3, 65600);
- pOp->load_const_u64(4, 95600);
- pOp->load_const_u32(7, 65000);
- pOp->call_sub(0) ;
-
- switch(nCalls) {
- case 1:
- pOp->def_subroutine(0) ;
- pOp->add_reg(1, 2, 5);
- break;
- case 2:
- pOp->def_subroutine(0) ;
- pOp->add_reg(1, 3, 5);
- break;
- case 3:
- pOp->def_subroutine(0) ;
- pOp->add_reg(3, 1, 5);
- break;
- case 4:
- pOp->def_subroutine(0) ;
- pOp->add_reg(3, 4, 5);
- break;
- case 5:
- pOp->def_subroutine(0) ;
- pOp->add_reg(1, 6, 5);
- break;
- case 6:
- pOp->def_subroutine(0) ;
- pOp->add_reg(6, 1, 5);
- break;
- case 7: // illegal register
- pOp->def_subroutine(0) ;
- pOp->add_reg(1, 8, 5);
- ret_val = FAIL ;
- break;
- case 8: // another illegal register
- pOp->def_subroutine(0) ;
- pOp->add_reg(8, 1, 5);
- ret_val = FAIL ;
- break;
- case 9: // and another one
- pOp->def_subroutine(0) ;
- pOp->add_reg(1, 2, 8);
- ret_val = FAIL ;
- break;
- case 10: // test subroutine nesting
- for(int sub = 0; sub < 25 ; ++sub){
- pOp->call_sub(sub) ;
- pOp->def_subroutine(sub + 1) ;
- pOp->interpret_exit_ok() ;
- pOp->ret_sub() ;
- }
- ret_val = FAIL ;
- default:
- break ;
- }
-
- pOp->branch_label(0) ;
- pOp->interpret_exit_nok() ;
- pOp->def_label(0) ;
- pOp->interpret_exit_ok() ;
- pOp->ret_sub() ;
-
- return ret_val ;
-}
-
-
-void scan_rows(Ndb* pMyNdb, int opType, int tupleType, int scanType) {
-
- int check = -1 ;
- int loop_count_ops = nRecords ;
- int eOf = -1 ;
- int readValue = 0 ;
- int readValue2 = 0 ;
- int scanCount = 0 ;
- TTYPE fail = NO_FAIL ;
-
- for (int count=0 ; count < loop_count_ops ; count++) {
- NdbConnection* MyTransaction = pMyNdb->startTransaction();
- if (!MyTransaction) error_handler(pMyNdb->getNdbError(), NO_FAIL);
-
- NdbOperation* MyOperation = MyTransaction->getNdbOperation(tableName);
- if (!MyOperation) error_handler(pMyNdb->getNdbError(), NO_FAIL);
-
- if (opType == 1)
- // Open for scan read, Creates the SCAN_TABREQ and if needed
- // SCAN_TABINFO signals.
- check = MyOperation->openScanRead(1);
- else if (opType == 2)
- // Open for scan with update of rows.
- check = MyOperation->openScanExclusive(1);
-
- // Create ATTRINFO signal(s) for interpreted program used for
- // defining search criteria and column values that should be returned.
-
- scanCount = count+1 ;
-
- switch(tupleType) {
- case 1:
- fail = t_exitMethods(scanCount, MyOperation, opType);
- break;
- case 2:
- fail = t_incValue(scanCount, MyOperation);
- break;
- case 3:
- fail = t_subValue(scanCount, MyOperation);
- break;
- case 4:
- fail = t_readAttr(scanCount, MyOperation);
- break;
- case 5:
- fail = t_writeAttr(scanCount, MyOperation);
- break;
- case 6:
- fail = t_loadConst(scanCount, MyOperation, opType);
- break;
- case 7:
- fail = t_branch(scanCount, MyOperation);
- break;
- case 8:
- fail = t_branchIfNull(scanCount, MyOperation);
- break;
- case 9:
- fail = t_addReg(scanCount, MyOperation);
- break;
- case 10:
- fail = t_subReg(scanCount, MyOperation);
- break;
- case 11:
- fail = t_subroutineWithBranchLabel(scanCount, MyOperation);
- break;
- default:
- break ;
- }
-
- if(11 != tupleType) MyOperation->getValue(attrName[1], (char*)&readValue);
-
- // Sends the SCAN_TABREQ, (SCAN_TABINFO) and ATTRINFO signals and then
- // reads the answer in TRANSID_AI. Confirmation is received through SCAN_TABCONF or
- // SCAN_TABREF if failure.
- check = MyTransaction->executeScan();
- if (check == -1) {
- //ndbout << endl << "executeScan returned: " << MyTransaction->getNdbError() << endl;
- error_handler(MyTransaction->getNdbError(), fail) ;
- pMyNdb->closeTransaction(MyTransaction);
- }else{
- // Sends the SCAN_NEXTREQ signal(s) and reads the answer in TRANS_ID signals.
- // SCAN_TABCONF or SCAN_TABREF is the confirmation.
- while ((eOf = MyTransaction->nextScanResult()) == 0) {
- ndbout << readValue <<"; ";
- // Here we call takeOverScanOp for update of the tuple.
- }
- ndbout << endl ;
-
- pMyNdb->closeTransaction(MyTransaction);
- if (eOf == -1) {
- ndbout << endl << "nextScanResult returned: "<< MyTransaction->getNdbError() << endl;
- } else {
- ndbout << "OK" << endl;
- }
- }
- }
- return;
-
-};
-
-
-void update_rows(Ndb* pMyNdb, int tupleType, int opType) {
- /****************************************************************
- * Update rows in SimpleTable
- * Only updates the first 3 cols.
- ***************************************************************/
-
- int check = -1 ;
- int loop_count_ops = nRecords ;
- int readValue[MAXATTR] = {0} ;
- TTYPE ret_val = NO_FAIL ;
- NdbConnection *MyTransaction = NULL ;
- NdbOperation *MyOperation = NULL ;
-
- ndbout << "Updating records ..." << endl << endl;
-
- for (int count=0 ; count < loop_count_ops ; count++){
-
- MyTransaction = pMyNdb->startTransaction();
- if (!MyTransaction) {
- error_handler(pMyNdb->getNdbError(), NO_FAIL);
- return;
- }//if
-
- MyOperation = MyTransaction->getNdbOperation(tableName);
- if (MyOperation == NULL) {
- error_handler(pMyNdb->getNdbError(), NO_FAIL);
- return;
- }//if
-
- // if (operationType == 3)
- check = MyOperation->interpretedUpdateTuple();
- // else if (operationType == 4)
- // check = MyOperation->interpretedDirtyUpdate();
- if( check == -1 )
- error_handler(MyTransaction->getNdbError(), NO_FAIL);
-
- check = MyOperation->equal( attrName[0], (char*)&pkValue[count] );
- if( check == -1 )
- error_handler(MyTransaction->getNdbError(), NO_FAIL);
-
- switch(tupleType) {
- case 1:
- ret_val = t_exitMethods(count+1, MyOperation, opType);
- break;
- case 2:
- ret_val = t_incValue(count+1, MyOperation);
- break;
- case 3:
- ret_val = t_subValue(count+1, MyOperation);
- break;
- case 4:
- ret_val = t_readAttr(count+1, MyOperation);
- break;
- case 5:
- ret_val = t_writeAttr(count+1, MyOperation);
- break;
- case 6:
- ret_val = t_loadConst(count+1, MyOperation, opType);
- break;
- case 7:
- ret_val = t_branch(count+1, MyOperation);
- break;
- case 8:
- ret_val = t_branchIfNull(count+1, MyOperation);
- break;
- case 9:
- ret_val = t_addReg(count+1, MyOperation);
- break;
- case 10:
- ret_val = t_subReg(count+1, MyOperation);
- break;
- case 11:
- ret_val = t_subroutineWithBranchLabel(count+1, MyOperation);
- break;
- default:
- break ;
- }
-
- MyOperation->getValue("COL1", (char*)&readValue);
-
- if (MyTransaction->execute( Commit ) == -1 ) {
- error_handler(MyTransaction->getNdbError(), ret_val);
- }else if (NO_FAIL == ret_val ) {
- ndbout << "OK" << endl;
- } else {
- bTestPassed = -1;
- ndbout << "Test passed when expected to fail" << endl;
- }//if
- pMyNdb->closeTransaction(MyTransaction);
-
- }
-
- ndbout << "Finished updating records" << endl;
- return;
-};
-
-void delete_rows(Ndb* pMyNdb, int tupleTest, int opType) {
-
- /****************************************************************
- * Delete rows from SimpleTable
- *
- ***************************************************************/
-
- int check = 1 ;
- int loop_count_ops = nRecords ;
- int readValue[MAXATTR] = {0};
- NdbConnection *MyTransaction = NULL ;
- NdbOperation *MyOperation = NULL ;
- TTYPE ret_val = NO_FAIL ;
-
- ndbout << "Deleting records ..."<< endl << endl;
-
- for (int count=0 ; count < loop_count_ops ; count++) {
-
- MyTransaction = pMyNdb->startTransaction();
- if (!MyTransaction) error_handler(pMyNdb->getNdbError(), NO_FAIL) ;
-
- MyOperation = MyTransaction->getNdbOperation(tableName);
- if (!MyOperation) error_handler(pMyNdb->getNdbError(), NO_FAIL) ;
-
- check = MyOperation->interpretedDeleteTuple();
- if( check == -1 ) error_handler(MyTransaction->getNdbError(), NO_FAIL) ;
-
- check = MyOperation->equal( attrName[0], (char*)&pkValue[count] );
- if( check == -1 ) error_handler(MyTransaction->getNdbError(), NO_FAIL) ;
-
- switch(tupleTest) {
- case 1:
- ret_val = t_exitMethods(count+1, MyOperation, opType);
- break;
- case 2:
- ret_val = t_incValue(count+1, MyOperation);
- break;
- case 3:
- ret_val = t_subValue(count+1, MyOperation);
- break;
- case 4:
- ret_val = t_readAttr(count+1, MyOperation);
- break;
- case 5:
- ret_val = t_writeAttr(count+1, MyOperation);
- break;
- case 6:
- ret_val = t_loadConst(count+1, MyOperation, opType);
- break;
- case 7:
- ret_val = t_branch(count+1, MyOperation);
- break;
- case 8:
- ret_val = t_branchIfNull(count+1, MyOperation);
- break;
- case 9:
- ret_val = t_addReg(count+1, MyOperation);
- break;
- case 10:
- ret_val = t_subReg(count+1, MyOperation);
- break;
- case 11:
- ret_val = t_subroutineWithBranchLabel(count+1, MyOperation);
- break;
- default:
- break ;
- }
-
- if(11 != tupleTest)MyOperation->getValue(attrName[1], (char*)&readValue) ;
-
- if (MyTransaction->execute( Commit ) == -1 ) {
- error_handler(MyTransaction->getNdbError(), ret_val);
- } else if (NO_FAIL == ret_val /*|| UNDEF == ret_val*/ ) {
- ndbout << "OK" << endl;
- } else {
- bTestPassed = -1;
- ndbout << "Test passed when expected to fail" << endl;
- }//if
- ndbout << endl;
- pMyNdb->closeTransaction(MyTransaction);
- }
-
- ndbout << "Finished deleting records" << endl;
- return;
-
-};
-
-
-inline void setAttrNames(){
- for (int i = 0; i < MAXATTR; i++){
- BaseString::snprintf(attrName[i], MAXSTRLEN, "COL%d", i);
- }
-}
-
-
-inline void setTableNames(){
- BaseString::snprintf(tableName, MAXSTRLEN, "TAB1");
-}
-
diff --git a/storage/ndb/test/ndbapi/mainAsyncGenerator.cpp b/storage/ndb/test/ndbapi/mainAsyncGenerator.cpp
deleted file mode 100644
index 31d191476e3..00000000000
--- a/storage/ndb/test/ndbapi/mainAsyncGenerator.cpp
+++ /dev/null
@@ -1,391 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-
-#include <NdbHost.h>
-#include <NdbSleep.h>
-#include <NdbThread.h>
-#include <NdbMain.h>
-#include <NdbOut.hpp>
-#include <NdbEnv.h>
-#include <NdbTest.hpp>
-
-#include "userInterface.h"
-#include "dbGenerator.h"
-
-static int numProcesses;
-static int numSeconds;
-static int numWarmSeconds;
-static int parallellism;
-static int millisSendPoll;
-static int minEventSendPoll;
-static int forceSendPoll;
-
-static ThreadData *data;
-
-static void usage(const char *prog)
-{
- const char *progname;
-
- /*--------------------------------------------*/
- /* Get the name of the program (without path) */
- /*--------------------------------------------*/
- progname = strrchr(prog, '/');
-
- if (progname == 0)
- progname = prog;
- else
- ++progname;
-
- ndbout_c(
- "Usage: %s [-proc <num>] [-warm <num>] [-time <num>] [ -p <num>] "
- "[-t <num> ] [ -e <num> ] [ -f <num>] \n"
- " -proc <num> Specifies that <num> is the number of\n"
- " threads. The default is 1.\n"
- " -time <num> Specifies that the test will run for <num> sec.\n"
- " The default is 10 sec\n"
- " -warm <num> Specifies the warm-up/cooldown period of <num> "
- "sec.\n"
- " The default is 10 sec\n"
- " -p <num> The no of parallell transactions started by "
- "one thread\n"
- " -e <num> Minimum no of events before wake up in call to "
- "sendPoll\n"
- " Default is 1\n"
- " -f <num> force parameter to sendPoll\n"
- " Default is 0\n",
- progname);
-}
-
-static
-int
-parse_args(int argc, const char **argv)
-{
- int i;
-
- numProcesses = 1;
- numSeconds = 10;
- numWarmSeconds = 10;
- parallellism = 1;
- millisSendPoll = 10000;
- minEventSendPoll = 1;
- forceSendPoll = 0;
-
-
- i = 1;
- while (i < argc){
- if (strcmp("-proc",argv[i]) == 0) {
- if (i + 1 >= argc) {
- return 1;
- }
- if (sscanf(argv[i+1], "%d", &numProcesses) == -1 ||
- numProcesses <= 0 || numProcesses > 127) {
- ndbout_c("-proc flag requires a positive integer argument [1..127]");
- return 1;
- }
- i += 2;
- } else if (strcmp("-p", argv[i]) == 0){
- if(i + 1 >= argc){
- usage(argv[0]);
- return 1;
- }
- if (sscanf(argv[i+1], "%d", &parallellism) == -1 ||
- parallellism <= 0){
- ndbout_c("-p flag requires a positive integer argument");
- return 1;
- }
- i += 2;
- }
- else if (strcmp("-time",argv[i]) == 0) {
- if (i + 1 >= argc) {
- return 1;
- }
- if (sscanf(argv[i+1], "%d", &numSeconds) == -1 ||
- numSeconds < 0) {
- ndbout_c("-time flag requires a positive integer argument");
- return 1;
- }
- i += 2;
- }
- else if (strcmp("-warm",argv[i]) == 0) {
- if (i + 1 >= argc) {
- return 1;
- }
- if (sscanf(argv[i+1], "%d", &numWarmSeconds) == -1 ||
- numWarmSeconds < 0) {
- ndbout_c("-warm flag requires a positive integer argument");
- return 1;
- }
- i += 2;
- }
- else if (strcmp("-e",argv[i]) == 0) {
- if (i + 1 >= argc) {
- return 1;
- }
- if (sscanf(argv[i+1], "%d", &minEventSendPoll) == -1 ||
- minEventSendPoll < 0) {
- ndbout_c("-e flag requires a positive integer argument");
- return 1;
- }
- i += 2;
- }
- else if (strcmp("-f",argv[i]) == 0) {
- if (i + 1 >= argc) {
- usage(argv[0]);
- return 1;
- }
- if (sscanf(argv[i+1], "%d", &forceSendPoll) == -1 ||
- forceSendPoll < 0) {
- ndbout_c("-f flag requires a positive integer argument");
- return 1;
- }
- i += 2;
- }
- else {
- return 1;
- }
- }
-
- if(minEventSendPoll > parallellism){
- ndbout_c("minEventSendPoll(%d) > parallellism(%d)",
- minEventSendPoll, parallellism);
- ndbout_c("not very good...");
- ndbout_c("very bad...");
- ndbout_c("exiting...");
- return 1;
- }
- return 0;
-}
-
-static
-void
-print_transaction(const char *header,
- unsigned long totalCount,
- TransactionDefinition *trans,
- unsigned int printBranch,
- unsigned int printRollback)
-{
- double f;
-
- ndbout_c(" %s: %d (%.2f%%) "
- "Latency(ms) avg: %d min: %d max: %d std: %d n: %d",
- header,
- trans->count,
- (double)trans->count / (double)totalCount * 100.0,
- (int)trans->latency.getMean(),
- (int)trans->latency.getMin(),
- (int)trans->latency.getMax(),
- (int)trans->latency.getStddev(),
- (int)trans->latency.getCount()
- );
-
- if( printBranch ){
- if( trans->count == 0 )
- f = 0.0;
- else
- f = (double)trans->branchExecuted / (double)trans->count * 100.0;
- ndbout_c(" Branches Executed: %d (%.2f%%)", trans->branchExecuted, f);
- }
-
- if( printRollback ){
- if( trans->count == 0 )
- f = 0.0;
- else
- f = (double)trans->rollbackExecuted / (double)trans->count * 100.0;
- ndbout_c(" Rollback Executed: %d (%.2f%%)",trans->rollbackExecuted,f);
- }
-}
-
-void
-print_stats(const char *title,
- unsigned int length,
- unsigned int transactionFlag,
- GeneratorStatistics *gen,
- int numProc, int parallellism)
-{
- int i;
- char buf[10];
- char name[MAXHOSTNAMELEN];
-
- name[0] = 0;
- NdbHost_GetHostName(name);
-
- ndbout_c("\n------ %s ------",title);
- ndbout_c("Length : %d %s",
- length,
- transactionFlag ? "Transactions" : "sec");
- ndbout_c("Processor : %s", name);
- ndbout_c("Number of Proc: %d",numProc);
- ndbout_c("Parallellism : %d", parallellism);
- ndbout_c("\n");
-
- if( gen->totalTransactions == 0 ) {
- ndbout_c(" No Transactions for this test");
- }
- else {
- for(i = 0; i < 5; i++) {
- sprintf(buf, "T%d",i+1);
- print_transaction(buf,
- gen->totalTransactions,
- &gen->transactions[i],
- i >= 2,
- i >= 3 );
- }
-
- ndbout_c("\n");
- ndbout_c(" Overall Statistics:");
- ndbout_c(" Transactions: %d", gen->totalTransactions);
- ndbout_c(" Outer : %.0f TPS",gen->outerTps);
- ndbout_c("\n");
- }
-}
-
-static
-void *
-threadRoutine(void *arg)
-{
- int i;
- ThreadData *data = (ThreadData *)arg;
- Ndb * pNDB;
-
- pNDB = asyncDbConnect(parallellism);
- /* NdbSleep_MilliSleep(rand() % 10); */
-
- for(i = 0; i<parallellism; i++){
- data[i].pNDB = pNDB;
- }
- millisSendPoll = 30000;
- asyncGenerator(data, parallellism,
- millisSendPoll, minEventSendPoll, forceSendPoll);
-
- asyncDbDisconnect(pNDB);
-
- return NULL;
-}
-
-NDB_COMMAND(DbAsyncGenerator, "DbAsyncGenerator",
- "DbAsyncGenerator", "DbAsyncGenerator", 65535)
-{
- ndb_init();
- int i;
- int j;
- int k;
- struct NdbThread* pThread = NULL;
- GeneratorStatistics stats;
- GeneratorStatistics *p;
- char threadName[32];
- int rc = NDBT_OK;
- void* tmp = NULL;
- if(parse_args(argc,argv) != 0){
- usage(argv[0]);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
-
- ndbout_c("\nStarting Test with %d process(es) for %d %s parallellism %d",
- numProcesses,
- numSeconds,
- "sec",
- parallellism);
-
- ndbout_c(" WarmUp/coolDown = %d sec", numWarmSeconds);
-
- data = (ThreadData*)malloc((numProcesses*parallellism)*sizeof(ThreadData));
-
- for(i = 0; i < numProcesses; i++) {
- for(j = 0; j<parallellism; j++){
- data[i*parallellism+j].warmUpSeconds = numWarmSeconds;
- data[i*parallellism+j].testSeconds = numSeconds;
- data[i*parallellism+j].coolDownSeconds = numWarmSeconds;
- data[i*parallellism+j].randomSeed =
- NdbTick_CurrentMillisecond()+i+j;
- data[i*parallellism+j].changedTime = 0;
- data[i*parallellism+j].runState = Runnable;
- }
- sprintf(threadName, "AsyncThread[%d]", i);
- pThread = NdbThread_Create(threadRoutine,
- (void**)&data[i*parallellism],
- 65535,
- threadName,
- NDB_THREAD_PRIO_LOW);
- if(pThread != 0 && pThread != NULL){
- (&data[i*parallellism])->pThread = pThread;
- } else {
- perror("Failed to create thread");
- rc = NDBT_FAILED;
- }
- }
-
- showTime();
-
- /*--------------------------------*/
- /* Wait for all processes to exit */
- /*--------------------------------*/
- for(i = 0; i < numProcesses; i++) {
- NdbThread_WaitFor(data[i*parallellism].pThread, &tmp);
- NdbThread_Destroy(&data[i*parallellism].pThread);
- }
-
- ndbout_c("All threads have finished");
-
- /*-------------------------------------------*/
- /* Clear all structures for total statistics */
- /*-------------------------------------------*/
- stats.totalTransactions = 0;
- stats.outerTps = 0.0;
-
- for(i = 0; i < NUM_TRANSACTION_TYPES; i++ ) {
- stats.transactions[i].count = 0;
- stats.transactions[i].branchExecuted = 0;
- stats.transactions[i].rollbackExecuted = 0;
- stats.transactions[i].latency.reset();
- }
-
- /*--------------------------------*/
- /* Add the values for all Threads */
- /*--------------------------------*/
- for(i = 0; i < numProcesses; i++) {
- for(k = 0; k<parallellism; k++){
- p = &data[i*parallellism+k].generator;
-
- stats.totalTransactions += p->totalTransactions;
- stats.outerTps += p->outerTps;
-
- for(j = 0; j < NUM_TRANSACTION_TYPES; j++ ) {
- stats.transactions[j].count +=
- p->transactions[j].count;
- stats.transactions[j].branchExecuted +=
- p->transactions[j].branchExecuted;
- stats.transactions[j].rollbackExecuted +=
- p->transactions[j].rollbackExecuted;
- stats.transactions[j].latency +=
- p->transactions[j].latency;
- }
- }
- }
-
- print_stats("Test Results",
- numSeconds,
- 0,
- &stats,
- numProcesses,
- parallellism);
-
- free(data);
-
- NDBT_ProgramExit(rc);
-}
diff --git a/storage/ndb/test/ndbapi/msa.cpp b/storage/ndb/test/ndbapi/msa.cpp
deleted file mode 100644
index e01d5e1934d..00000000000
--- a/storage/ndb/test/ndbapi/msa.cpp
+++ /dev/null
@@ -1,1206 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-
-#include <NdbApi.hpp>
-#include <NdbSchemaCon.hpp>
-#include <NdbCondition.h>
-#include <NdbMutex.h>
-#include <NdbSleep.h>
-#include <NdbThread.h>
-#include <NdbTick.h>
-
-const char* const c_szDatabaseName = "TEST_DB";
-
-const char* const c_szTableNameStored = "CCStored";
-const char* const c_szTableNameTemp = "CCTemp";
-
-const char* const c_szContextId = "ContextId";
-const char* const c_szVersion = "Version";
-const char* const c_szLockFlag = "LockFlag";
-const char* const c_szLockTime = "LockTime";
-const char* const c_szLockTimeUSec = "LockTimeUSec";
-const char* const c_szContextData = "ContextData";
-
-const char* g_szTableName = c_szTableNameStored;
-
-
-#ifdef NDB_WIN32
-HANDLE hShutdownEvent = 0;
-#else
-#include <signal.h>
-bool bShutdownEvent = false;
-#endif
-long g_nMaxContextIdPerThread = 5000;
-long g_nNumThreads = 0;
-long g_nMaxCallsPerSecond = 0;
-long g_nMaxRetry = 50;
-bool g_bWriteTuple = false;
-bool g_bInsertInitial = false;
-bool g_bVerifyInitial = false;
-
-NdbMutex* g_pNdbMutexPrintf = 0;
-NdbMutex* g_pNdbMutexIncrement = 0;
-long g_nNumCallsProcessed = 0;
-NDB_TICKS g_tStartTime = 0;
-NDB_TICKS g_tEndTime = 0;
-
-long g_nNumberOfInitialInsert = 0;
-long g_nNumberOfInitialVerify = 0;
-
-const long c_nMaxMillisecForAllCall = 5000;
-long* g_plCountMillisecForCall = 0;
-const long c_nMaxMillisecForAllTrans = 5000;
-long* g_plCountMillisecForTrans = 0;
-bool g_bReport = false;
-bool g_bReportPlus = false;
-
-
-// data for CALL_CONTEXT and GROUP_RESOURCE
-static char STATUS_DATA[]=
-"000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F"
-"101112131415161718191A1B1C1D1E1F000102030405060708090A0B0C0D0E0F"
-"202122232425262728292A2B2C2D2E2F000102030405060708090A0B0C0D0E0F"
-"303132333435363738393A3B3C3D3E3F000102030405060708090A0B0C0D0E0F"
-"404142434445464748494A4B4C4D4E4F000102030405060708090A0B0C0D0E0F"
-"505152535455565758595A5B5C5D5E5F000102030405060708090A0B0C0D0E0F"
-"606162636465666768696A6B6C6D6E6F000102030405060708090A0B0C0D0E0F"
-"707172737475767778797A7B7C7D7E7F000102030405060708090A0B0C0D0E0F"
-"808182838485868788898A8B8C8D8E8F000102030405060708090A0B0C0D0E0F"
-"909192939495969798999A9B9C9D9E9F000102030405060708090A0B0C0D0E0F"
-"10010110210310410510610710810910A000102030405060708090A0B0C0D0EF"
-"10B10C10D10E10F110111112113114115000102030405060708090A0B0C0D0EF"
-"11611711811911A11B11C11D11E11F120000102030405060708090A0B0C0D0EF"
-"12112212312412512612712812912A12B000102030405060708090A0B0C0D0EF"
-"12C12D12E12F130131132134135136137000102030405060708090A0B0C0D0EF"
-"13813913A13B13C13D13E13F140141142000102030405060708090A0B0C0D0EF"
-"14314414514614714814914A14B14C14D000102030405060708090A0B0C0D0EF"
-"14E14F150151152153154155156157158000102030405060708090A0B0C0D0EF"
-"15915A15B15C15D15E15F160161162163000102030405060708090A0B0C0D0EF"
-"16416516616716816916A16B16C16D16E000102030405060708090A0B0C0D0EF"
-"16F170171172173174175176177178179000102030405060708090A0B0C0D0EF"
-"17A17B17C17D17E17F180181182183184000102030405060708090A0B0C0D0EF"
-"18518618718818918A18B18C18D18E18F000102030405060708090A0B0C0D0EF"
-"19019119219319419519619719819919A000102030405060708090A0B0C0D0EF"
-"19B19C19D19E19F200201202203204205000102030405060708090A0B0C0D0EF"
-"20620720820920A20B20C20D20F210211000102030405060708090A0B0C0D0EF"
-"21221321421521621721821921A21B21C000102030405060708090A0B0C0D0EF"
-"21D21E21F220221222223224225226227000102030405060708090A0B0C0D0EF"
-"22822922A22B22C22D22E22F230231232000102030405060708090A0B0C0D0EF"
-"23323423523623723823923A23B23C23D000102030405060708090A0B0C0D0EF"
-"23E23F240241242243244245246247248000102030405060708090A0B0C0D0EF"
-"24924A24B24C24D24E24F250251252253000102030405060708090A0B0C0D0EF"
-"101112131415161718191A1B1C1D1E1F000102030405060708090A0B0C0D0E0F"
-"202122232425262728292A2B2C2D2E2F000102030405060708090A0B0C0D0E0F"
-"303132333435363738393A3B3C3D3E3F000102030405060708090A0B0C0D0E0F"
-"404142434445464748494A4B4C4D4E4F000102030405060708090A0B0C0D0E0F"
-"505152535455565758595A5B5C5D5E5F000102030405060708090A0B0C0D0E0F"
-"606162636465666768696A6B6C6D6E6F000102030405060708090A0B0C0D0E0F"
-"707172737475767778797A7B7C7D7E7F000102030405060708090A0B0C0D0E0F"
-"808182838485868788898A8B8C8D8E8F000102030405060708090A0B0C0D0E0F"
-"909192939495969798999A9B9C9D9E9F000102030405060708090A0B0C0D0E0F"
-"10010110210310410510610710810910A000102030405060708090A0B0C0D0EF"
-"10B10C10D10E10F110111112113114115000102030405060708090A0B0C0D0EF"
-"11611711811911A11B11C11D11E11F120000102030405060708090A0B0C0D0EF"
-"12112212312412512612712812912A12B000102030405060708090A0B0C0D0EF"
-"12C12D12E12F130131132134135136137000102030405060708090A0B0C0D0EF"
-"13813913A13B13C13D13E13F140141142000102030405060708090A0B0C0D0EF"
-"14314414514614714814914A14B14C14D000102030405060708090A0B0C0D0EF"
-"14E14F150151152153154155156157158000102030405060708090A0B0C0D0EF"
-"15915A15B15C15D15E15F160161162163000102030405060708090A0B0C0D0EF"
-"16416516616716816916A16B16C16D16E000102030405060708090A0B0C0D0EF"
-"16F170171172173174175176177178179000102030405060708090A0B0C0D0EF"
-"17A17B17C17D17E17F180181182183184000102030405060708090A0B0C0D0EF"
-"18518618718818918A18B18C18D18E18F000102030405060708090A0B0C0D0EF"
-"19019119219319419519619719819919A000102030405060708090A0B0C0D0EF"
-"19B19C19D19E19F200201202203204205000102030405060708090A0B0C0D0EF"
-"20620720820920A20B20C20D20F210211000102030405060708090A0B0C0D0EF"
-"21221321421521621721821921A21B21C000102030405060708090A0B0C0D0EF"
-"21D21E21F220221222223224225226227000102030405060708090A0B0C0D0EF"
-"22822922A22B22C22D22E22F230231232000102030405060708090A0B0C0D0EF"
-"23323423523623723823923A23B23C23D000102030405060708090A0B0C0D0EF"
-"2366890FE1438751097E7F6325DC0E6326F"
-"25425525625725825925A25B25C25D25E25F000102030405060708090A0B0C0F";
-
-long g_nStatusDataSize = sizeof(STATUS_DATA);
-
-
-// Thread function for Call Context Inserts
-
-
-#ifdef NDB_WIN32
-
-BOOL WINAPI ConsoleCtrlHandler(DWORD dwCtrlType)
-{
- if(CTRL_C_EVENT == dwCtrlType)
- {
- SetEvent(hShutdownEvent);
- return TRUE;
- }
- return FALSE;
-}
-
-#else
-
-void CtrlCHandler(int)
-{
- bShutdownEvent = true;
-}
-
-#endif
-
-
-
-void ReportNdbError(const char* szMsg, const NdbError& err)
-{
- NdbMutex_Lock(g_pNdbMutexPrintf);
- printf("%s: %d: %s\n", szMsg, err.code, (err.message ? err.message : ""));
- NdbMutex_Unlock(g_pNdbMutexPrintf);
-}
-
-
-void
-ReportCallsPerSecond(long nNumCallsProcessed,
- NDB_TICKS tStartTime,
- NDB_TICKS tEndTime)
-{
- NDB_TICKS tElapsed = tEndTime - tStartTime;
- long lCallsPerSec;
- if(tElapsed>0)
- lCallsPerSec = (long)((1000*nNumCallsProcessed)/tElapsed);
- else
- lCallsPerSec = 0;
-
- NdbMutex_Lock(g_pNdbMutexPrintf);
- printf("Time Taken for %ld Calls is %ld msec (= %ld calls/sec)\n",
- nNumCallsProcessed, (long)tElapsed, lCallsPerSec);
- NdbMutex_Unlock(g_pNdbMutexPrintf);
-}
-
-
-#ifndef NDB_WIN32
-void InterlockedIncrement(long* lp) // expensive
-{
- NdbMutex_Lock(g_pNdbMutexIncrement);
- (*lp)++;
- NdbMutex_Unlock(g_pNdbMutexIncrement);
-}
-#endif
-
-
-void InterlockedIncrementAndReport(void)
-{
- NdbMutex_Lock(g_pNdbMutexIncrement);
- ++g_nNumCallsProcessed;
- if((g_nNumCallsProcessed%1000)==0)
- {
- g_tEndTime = NdbTick_CurrentMillisecond();
- if(g_tStartTime)
- ReportCallsPerSecond(1000, g_tStartTime, g_tEndTime);
-
- g_tStartTime = g_tEndTime;
- }
- NdbMutex_Unlock(g_pNdbMutexIncrement);
-}
-
-
-void SleepOneCall(void)
-{
- int iMillisecToSleep;
- if(g_nMaxCallsPerSecond>0)
- iMillisecToSleep = (1000*g_nNumThreads)/g_nMaxCallsPerSecond;
- else
- iMillisecToSleep = 50;
-
- if(iMillisecToSleep>0)
- NdbSleep_MilliSleep(iMillisecToSleep);
-
-}
-
-
-
-int QueryTransaction(Ndb* pNdb,
- long iContextId,
- long* piVersion,
- long* piLockFlag,
- long* piLockTime,
- long* piLockTimeUSec,
- char* pchContextData,
- NdbError& err)
-{
- int iRes = -1;
- NdbConnection* pNdbConnection = pNdb->startTransaction(0, (const char*)&iContextId, 4);
- if(pNdbConnection)
- {
- NdbOperation* pNdbOperation = pNdbConnection->getNdbOperation(g_szTableName);
- if(pNdbOperation)
- {
- NdbRecAttr* pNdbRecAttrVersion;
- NdbRecAttr* pNdbRecAttrLockFlag;
- NdbRecAttr* pNdbRecAttrLockTime;
- NdbRecAttr* pNdbRecAttrLockTimeUSec;
- NdbRecAttr* pNdbRecAttrContextData;
- if(!pNdbOperation->readTuple()
- && !pNdbOperation->equal(c_szContextId, (Int32)iContextId)
- && (pNdbRecAttrVersion=pNdbOperation->getValue(c_szVersion, (char*)piVersion))
- && (pNdbRecAttrLockFlag=pNdbOperation->getValue(c_szLockFlag, (char*)piLockFlag))
- && (pNdbRecAttrLockTime=pNdbOperation->getValue(c_szLockTime, (char*)piLockTime))
- && (pNdbRecAttrLockTimeUSec=pNdbOperation->getValue(c_szLockTimeUSec, (char*)piLockTimeUSec))
- && (pNdbRecAttrContextData=pNdbOperation->getValue(c_szContextData, pchContextData)))
- {
- if(!pNdbConnection->execute(Commit))
- iRes = 0;
- else
- err = pNdbConnection->getNdbError();
- }
- else
- err = pNdbOperation->getNdbError();
- }
- else
- err = pNdbConnection->getNdbError();
-
- pNdb->closeTransaction(pNdbConnection);
- }
- else
- err = pNdb->getNdbError();
-
- return iRes;
-}
-
-
-int RetryQueryTransaction(Ndb* pNdb,
- long iContextId,
- long* piVersion,
- long* piLockFlag,
- long* piLockTime,
- long* piLockTimeUSec,
- char* pchContextData,
- NdbError& err,
- int& nRetry)
-{
- int iRes = -1;
- nRetry = 0;
- bool bRetry = true;
- while(bRetry && nRetry<g_nMaxRetry)
- {
- if(!QueryTransaction(pNdb, iContextId, piVersion, piLockFlag,
- piLockTime, piLockTimeUSec, pchContextData, err))
- {
- iRes = 0;
- bRetry = false;
- }
- else
- {
- switch(err.status)
- {
- case NdbError::TemporaryError:
- case NdbError::UnknownResult:
- SleepOneCall();
- ++nRetry;
- break;
-
- case NdbError::PermanentError:
- default:
- bRetry = false;
- break;
- }
- }
- }
- return iRes;
-}
-
-
-int DeleteTransaction(Ndb* pNdb, long iContextId, NdbError& err)
-{
- int iRes = -1;
- NdbConnection* pNdbConnection = pNdb->startTransaction(0, (const char*)&iContextId, 4);
- if(pNdbConnection)
- {
- NdbOperation* pNdbOperation = pNdbConnection->getNdbOperation(g_szTableName);
- if(pNdbOperation)
- {
- if(!pNdbOperation->deleteTuple()
- && !pNdbOperation->equal(c_szContextId, (Int32)iContextId))
- {
- if(pNdbConnection->execute(Commit) == 0)
- iRes = 0;
- else
- err = pNdbConnection->getNdbError();
- }
- else
- err = pNdbOperation->getNdbError();
- }
- else
- err = pNdbConnection->getNdbError();
-
- pNdb->closeTransaction(pNdbConnection);
- }
- else
- err = pNdb->getNdbError();
-
- return iRes;
-}
-
-
-
-int RetryDeleteTransaction(Ndb* pNdb, long iContextId, NdbError& err, int& nRetry)
-{
- int iRes = -1;
- nRetry = 0;
- bool bRetry = true;
- bool bUnknown = false;
- while(bRetry && nRetry<g_nMaxRetry)
- {
- if(!DeleteTransaction(pNdb, iContextId, err))
- {
- iRes = 0;
- bRetry = false;
- }
- else
- {
- switch(err.status)
- {
- case NdbError::UnknownResult:
- bUnknown = true;
- ++nRetry;
- break;
-
- case NdbError::TemporaryError:
- bUnknown = false;
- SleepOneCall();
- ++nRetry;
- break;
-
- case NdbError::PermanentError:
- if(err.code==626 && bUnknown)
- iRes = 0;
- bRetry = false;
- break;
-
- default:
- bRetry = false;
- break;
- }
- }
- }
- return iRes;
-}
-
-
-
-int InsertTransaction(Ndb* pNdb,
- long iContextID,
- long iVersion,
- long iLockFlag,
- long iLockTime,
- long iLockTimeUSec,
- const char* pchContextData,
- NdbError& err)
-{
- int iRes = -1;
- NdbConnection* pNdbConnection = pNdb->startTransaction(0, (const char*)&iContextID, 4);
- if(pNdbConnection)
- {
- NdbOperation* pNdbOperation = pNdbConnection->getNdbOperation(g_szTableName);
- if(pNdbOperation)
- {
- if(!(g_bWriteTuple ? pNdbOperation->writeTuple() : pNdbOperation->insertTuple())
- && !pNdbOperation->equal(c_szContextId, (Int32)iContextID)
- && !pNdbOperation->setValue(c_szVersion, (Int32)iVersion)
- && !pNdbOperation->setValue(c_szLockFlag, (Int32)iLockFlag)
- && !pNdbOperation->setValue(c_szLockTime, (Int32)iLockTime)
- && !pNdbOperation->setValue(c_szLockTimeUSec, (Int32)iLockTimeUSec)
- && !pNdbOperation->setValue(c_szContextData, pchContextData, g_nStatusDataSize))
- {
- if(!pNdbConnection->execute(Commit))
- iRes = 0;
- else
- err = pNdbConnection->getNdbError();
- }
- else
- err = pNdbOperation->getNdbError();
- }
- else
- err = pNdbConnection->getNdbError();
-
- pNdb->closeTransaction(pNdbConnection);
- }
- else
- err = pNdb->getNdbError();
-
- return iRes;
-}
-
-
-
-int RetryInsertTransaction(Ndb* pNdb,
- long iContextId,
- long iVersion,
- long iLockFlag,
- long iLockTime,
- long iLockTimeUSec,
- const char* pchContextData,
- NdbError& err, int& nRetry)
-{
- int iRes = -1;
- nRetry = 0;
- bool bRetry = true;
- bool bUnknown = false;
- while(bRetry && nRetry<g_nMaxRetry)
- {
- if(!InsertTransaction(pNdb, iContextId, iVersion, iLockFlag,
- iLockTime, iLockTimeUSec, pchContextData, err))
- {
- iRes = 0;
- bRetry = false;
- }
- else
- {
- switch(err.status)
- {
- case NdbError::UnknownResult:
- bUnknown = true;
- ++nRetry;
- break;
-
- case NdbError::TemporaryError:
- bUnknown = false;
- SleepOneCall();
- ++nRetry;
- break;
-
- case NdbError::PermanentError:
- if(err.code==630 && bUnknown)
- iRes = 0;
- bRetry = false;
- break;
-
- default:
- bRetry = false;
- break;
- }
- }
- }
- return iRes;
-}
-
-
-int UpdateTransaction(Ndb* pNdb, long iContextId, NdbError& err)
-{
- int iRes = -1;
- NdbConnection* pNdbConnection = pNdb->startTransaction(0, (const char*)&iContextId, 4);
- if(pNdbConnection)
- {
- NdbOperation* pNdbOperation = pNdbConnection->getNdbOperation(g_szTableName);
- if(pNdbOperation)
- {
- if(!pNdbOperation->updateTuple()
- && !pNdbOperation->equal(c_szContextId, (Int32)iContextId)
- && !pNdbOperation->setValue(c_szContextData, STATUS_DATA, g_nStatusDataSize))
- {
- if(!pNdbConnection->execute(Commit))
- iRes = 0;
- else
- err = pNdbConnection->getNdbError();
- }
- else
- err = pNdbOperation->getNdbError();
- }
- else
- err = pNdbConnection->getNdbError();
-
- pNdb->closeTransaction(pNdbConnection);
- }
- else
- err = pNdb->getNdbError();
-
- return iRes;
-}
-
-
-int RetryUpdateTransaction(Ndb* pNdb, long iContextId, NdbError& err, int& nRetry)
-{
- int iRes = -1;
- nRetry = 0;
- bool bRetry = true;
- while(bRetry && nRetry<g_nMaxRetry)
- {
- if(!UpdateTransaction(pNdb, iContextId, err))
- {
- iRes = 0;
- bRetry = false;
- }
- else
- {
- switch(err.status)
- {
- case NdbError::TemporaryError:
- case NdbError::UnknownResult:
- SleepOneCall();
- ++nRetry;
- break;
-
- case NdbError::PermanentError:
- default:
- bRetry = false;
- break;
- }
- }
- }
- return iRes;
-}
-
-
-
-int InsertInitialRecords(Ndb* pNdb, long nInsert, long nSeed)
-{
- int iRes = -1;
- char szMsg[100];
- for(long i=0; i<nInsert; ++i)
- {
- int iContextID = i+nSeed;
- int nRetry = 0;
- NdbError err;
- memset(&err, 0, sizeof(err));
- NDB_TICKS tStartTrans = NdbTick_CurrentMillisecond();
- iRes = RetryInsertTransaction(pNdb, iContextID, nSeed, iContextID,
- (long)(tStartTrans/1000), (long)((tStartTrans%1000)*1000),
- STATUS_DATA, err, nRetry);
- NDB_TICKS tEndTrans = NdbTick_CurrentMillisecond();
- long lMillisecForThisTrans = (long)(tEndTrans-tStartTrans);
- if(nRetry>0)
- {
- sprintf(szMsg, "insert retried %d times, time %ld msec.",
- nRetry, lMillisecForThisTrans);
- ReportNdbError(szMsg, err);
- }
- if(iRes)
- {
- ReportNdbError("Insert initial record failed", err);
- return iRes;
- }
- InterlockedIncrement(&g_nNumberOfInitialInsert);
- }
- return iRes;
-}
-
-
-
-int VerifyInitialRecords(Ndb* pNdb, long nVerify, long nSeed)
-{
- int iRes = -1;
- char* pchContextData = new char[g_nStatusDataSize];
- char szMsg[100];
- long iPrevLockTime = -1;
- long iPrevLockTimeUSec = -1;
- for(long i=0; i<nVerify; ++i)
- {
- int iContextID = i+nSeed;
- long iVersion = 0;
- long iLockFlag = 0;
- long iLockTime = 0;
- long iLockTimeUSec = 0;
- int nRetry = 0;
- NdbError err;
- memset(&err, 0, sizeof(err));
- NDB_TICKS tStartTrans = NdbTick_CurrentMillisecond();
- iRes = RetryQueryTransaction(pNdb, iContextID, &iVersion, &iLockFlag,
- &iLockTime, &iLockTimeUSec, pchContextData, err, nRetry);
- NDB_TICKS tEndTrans = NdbTick_CurrentMillisecond();
- long lMillisecForThisTrans = (long)(tEndTrans-tStartTrans);
- if(nRetry>0)
- {
- sprintf(szMsg, "verify retried %d times, time %ld msec.",
- nRetry, lMillisecForThisTrans);
- ReportNdbError(szMsg, err);
- }
- if(iRes)
- {
- ReportNdbError("Read initial record failed", err);
- delete[] pchContextData;
- return iRes;
- }
- if(memcmp(pchContextData, STATUS_DATA, g_nStatusDataSize))
- {
- sprintf(szMsg, "wrong context data in tuple %d", iContextID);
- ReportNdbError(szMsg, err);
- delete[] pchContextData;
- return -1;
- }
- if(iVersion!=nSeed
- || iLockFlag!=iContextID
- || iLockTime<iPrevLockTime
- || (iLockTime==iPrevLockTime && iLockTimeUSec<iPrevLockTimeUSec))
- {
- sprintf(szMsg, "wrong call data in tuple %d", iContextID);
- ReportNdbError(szMsg, err);
- delete[] pchContextData;
- return -1;
- }
- iPrevLockTime = iLockTime;
- iPrevLockTimeUSec = iLockTimeUSec;
- InterlockedIncrement(&g_nNumberOfInitialVerify);
- }
- delete[] pchContextData;
- return iRes;
-}
-
-
-
-
-
-void* RuntimeCallContext(void* lpParam)
-{
- long nNumCallsProcessed = 0;
- int nStartingRecordID = *(int*)lpParam;
-
- Ndb* pNdb;
- char* pchContextData = new char[g_nStatusDataSize];
- char szMsg[100];
-
- int iRes;
- const char* szOp;
- long iVersion;
- long iLockFlag;
- long iLockTime;
- long iLockTimeUSec;
-
- pNdb = new Ndb("TEST_DB");
- if(!pNdb)
- {
- NdbMutex_Lock(g_pNdbMutexPrintf);
- printf("new Ndb failed\n");
- NdbMutex_Unlock(g_pNdbMutexPrintf);
- delete[] pchContextData;
- return 0;
- }
-
- if(pNdb->init(1) || pNdb->waitUntilReady())
- {
- ReportNdbError("init of Ndb failed", pNdb->getNdbError());
- delete pNdb;
- delete[] pchContextData;
- return 0;
- }
-
- if(g_bInsertInitial)
- {
- if(InsertInitialRecords(pNdb, g_nMaxContextIdPerThread, -nStartingRecordID-g_nMaxContextIdPerThread))
- {
- delete pNdb;
- delete[] pchContextData;
- return 0;
- }
- }
-
- if(g_bVerifyInitial)
- {
- NdbError err;
- memset(&err, 0, sizeof(err));
- if(VerifyInitialRecords(pNdb, g_nMaxContextIdPerThread, -nStartingRecordID-g_nMaxContextIdPerThread))
- {
- delete pNdb;
- delete[] pchContextData;
- return 0;
- }
- }
- if(g_bInsertInitial || g_bVerifyInitial)
- {
- delete[] pchContextData;
- return 0;
- }
-
- long nContextID = nStartingRecordID;
-#ifdef NDB_WIN32
- while(WaitForSingleObject(hShutdownEvent,0) != WAIT_OBJECT_0)
-#else
- while(!bShutdownEvent)
-#endif
- {
- ++nContextID;
- nContextID %= g_nMaxContextIdPerThread;
- nContextID += nStartingRecordID;
-
- bool bTimeLatency = (nContextID==100);
-
- NDB_TICKS tStartCall = NdbTick_CurrentMillisecond();
- for (int i=0; i < 20; i++)
- {
- int nRetry = 0;
- NdbError err;
- memset(&err, 0, sizeof(err));
- NDB_TICKS tStartTrans = NdbTick_CurrentMillisecond();
- switch(i)
- {
- case 3:
- case 6:
- case 9:
- case 11:
- case 12:
- case 15:
- case 18: // Query Record
- szOp = "Read";
- iRes = RetryQueryTransaction(pNdb, nContextID, &iVersion, &iLockFlag,
- &iLockTime, &iLockTimeUSec, pchContextData, err, nRetry);
- break;
-
- case 19: // Delete Record
- szOp = "Delete";
- iRes = RetryDeleteTransaction(pNdb, nContextID, err, nRetry);
- break;
-
- case 0: // Insert Record
- szOp = "Insert";
- iRes = RetryInsertTransaction(pNdb, nContextID, 1, 1, 1, 1, STATUS_DATA, err, nRetry);
- break;
-
- default: // Update Record
- szOp = "Update";
- iRes = RetryUpdateTransaction(pNdb, nContextID, err, nRetry);
- break;
- }
- NDB_TICKS tEndTrans = NdbTick_CurrentMillisecond();
- long lMillisecForThisTrans = (long)(tEndTrans-tStartTrans);
-
- if(g_bReport)
- {
- assert(lMillisecForThisTrans>=0 && lMillisecForThisTrans<c_nMaxMillisecForAllTrans);
- InterlockedIncrement(g_plCountMillisecForTrans+lMillisecForThisTrans);
- }
-
- if(nRetry>0)
- {
- sprintf(szMsg, "%s retried %d times, time %ld msec.",
- szOp, nRetry, lMillisecForThisTrans);
- ReportNdbError(szMsg, err);
- }
- else if(bTimeLatency)
- {
- NdbMutex_Lock(g_pNdbMutexPrintf);
- printf("%s = %ld msec.\n", szOp, lMillisecForThisTrans);
- NdbMutex_Unlock(g_pNdbMutexPrintf);
- }
-
- if(iRes)
- {
- sprintf(szMsg, "%s failed after %ld calls, terminating thread",
- szOp, nNumCallsProcessed);
- ReportNdbError(szMsg, err);
- delete pNdb;
- delete[] pchContextData;
- return 0;
- }
- }
- NDB_TICKS tEndCall = NdbTick_CurrentMillisecond();
- long lMillisecForThisCall = (long)(tEndCall-tStartCall);
-
- if(g_bReport)
- {
- assert(lMillisecForThisCall>=0 && lMillisecForThisCall<c_nMaxMillisecForAllCall);
- InterlockedIncrement(g_plCountMillisecForCall+lMillisecForThisCall);
- }
-
- if(bTimeLatency)
- {
- NdbMutex_Lock(g_pNdbMutexPrintf);
- printf("Total time for call is %ld msec.\n", (long)lMillisecForThisCall);
- NdbMutex_Unlock(g_pNdbMutexPrintf);
- }
-
- nNumCallsProcessed++;
- InterlockedIncrementAndReport();
- if(g_nMaxCallsPerSecond>0)
- {
- int iMillisecToSleep = (1000*g_nNumThreads)/g_nMaxCallsPerSecond;
- iMillisecToSleep -= lMillisecForThisCall;
- if(iMillisecToSleep>0)
- {
- NdbSleep_MilliSleep(iMillisecToSleep);
- }
- }
- }
-
- NdbMutex_Lock(g_pNdbMutexPrintf);
- printf("Terminating thread after %ld calls\n", nNumCallsProcessed);
- NdbMutex_Unlock(g_pNdbMutexPrintf);
-
- delete pNdb;
- delete[] pchContextData;
- return 0;
-}
-
-
-int CreateCallContextTable(Ndb* pNdb, const char* szTableName, bool bStored)
-{
- int iRes = -1;
- NdbError err;
- memset(&err, 0, sizeof(err));
-
- NdbSchemaCon* pNdbSchemaCon = NdbSchemaCon::startSchemaTrans(pNdb);
- if(pNdbSchemaCon)
- {
- NdbSchemaOp* pNdbSchemaOp = pNdbSchemaCon->getNdbSchemaOp();
- if(pNdbSchemaOp)
- {
- if(!pNdbSchemaOp->createTable(szTableName, 8, TupleKey, 2,
- All, 6, 78, 80, 1, bStored)
- && !pNdbSchemaOp->createAttribute(c_szContextId, TupleKey, 32, 1, Signed)
- && !pNdbSchemaOp->createAttribute(c_szVersion, NoKey, 32, 1, Signed)
- && !pNdbSchemaOp->createAttribute(c_szLockFlag, NoKey, 32, 1, Signed)
- && !pNdbSchemaOp->createAttribute(c_szLockTime, NoKey, 32, 1, Signed)
- && !pNdbSchemaOp->createAttribute(c_szLockTimeUSec, NoKey, 32, 1, Signed)
- && !pNdbSchemaOp->createAttribute(c_szContextData, NoKey, 8, g_nStatusDataSize, String))
- {
- if(!pNdbSchemaCon->execute())
- iRes = 0;
- else
- err = pNdbSchemaCon->getNdbError();
- }
- else
- err = pNdbSchemaOp->getNdbError();
- }
- else
- err = pNdbSchemaCon->getNdbError();
-
- NdbSchemaCon::closeSchemaTrans(pNdbSchemaCon);
- }
- else
- err = pNdb->getNdbError();
-
- if(iRes)
- {
- ReportNdbError("create call context table failed", err);
- }
- return iRes;
-}
-
-
-
-void ReportResponseTimeStatistics(const char* szStat, long* plCount, const long lSize)
-{
- long lCount = 0;
- Int64 llSum = 0;
- Int64 llSum2 = 0;
- long lMin = -1;
- long lMax = -1;
-
- for(long l=0; l<lSize; ++l)
- {
- if(plCount[l]>0)
- {
- lCount += plCount[l];
- llSum += (Int64)l*(Int64)plCount[l];
- llSum2 += (Int64)l*(Int64)l*(Int64)plCount[l];
- if(lMin==-1 || l<lMin)
- {
- lMin = l;
- }
- if(lMax==-1 || l>lMax)
- {
- lMax = l;
- }
- }
- }
-
- long lAvg = long(llSum/lCount);
- double dblVar = ((double)lCount*(double)llSum2 - (double)llSum*(double)llSum)/((double)lCount*(double)(lCount-1));
- long lStd = long(sqrt(dblVar));
-
- long lMed = -1;
- long l95 = -1;
- long lSel = -1;
- for(long l=lMin; l<=lMax; ++l)
- {
- if(plCount[l]>0)
- {
- lSel += plCount[l];
- if(lMed==-1 && lSel>=(lCount/2))
- {
- lMed = l;
- }
- if(l95==-1 && lSel>=((lCount*95)/100))
- {
- l95 = l;
- }
- if(g_bReportPlus)
- {
- printf("%ld\t%ld\n", l, plCount[l]);
- }
- }
- }
-
- printf("%s: Count=%ld, Min=%ld, Max=%ld, Avg=%ld, Std=%ld, Med=%ld, 95%%=%ld\n",
- szStat, lCount, lMin, lMax, lAvg, lStd, lMed, l95);
-}
-
-
-
-void ShowHelp(const char* szCmd)
-{
- printf("%s -t<threads> [-s<seed>] [-b<batch>] [-c<maxcps>] [-m<size>] [-d] [-i] [-v] [-f] [-w] [-r[+]]\n", szCmd);
- printf("%s -?\n", szCmd);
- puts("-d\t\tcreate the table");
- puts("-i\t\tinsert initial records");
- puts("-v\t\tverify initial records");
- puts("-t<threads>\tnumber of threads making calls");
- puts("-s<seed>\toffset for primary key");
- puts("-b<batch>\tbatch size per thread");
- puts("-c<maxcps>\tmax number of calls per second for this process");
- puts("-m<size>\tsize of context data");
- puts("-f\t\tno checkpointing and no logging");
- puts("-w\t\tuse writeTuple instead of insertTuple");
- puts("-r\t\treport response time statistics");
- puts("-r+\t\treport response time distribution");
- puts("-?\t\thelp");
-}
-
-
-int main(int argc, char* argv[])
-{
- ndb_init();
- int iRes = -1;
- g_nNumThreads = 0;
- g_nMaxCallsPerSecond = 0;
- long nSeed = 0;
- bool bStoredTable = true;
- bool bCreateTable = false;
- g_bWriteTuple = false;
- g_bReport = false;
- g_bReportPlus = false;
-
- for(int i=1; i<argc; ++i)
- {
- if(argv[i][0]=='-' || argv[i][0]=='/')
- {
- switch(argv[i][1])
- {
- case 't':
- g_nNumThreads = atol(argv[i]+2);
- break;
- case 's':
- nSeed = atol(argv[i]+2);
- break;
- case 'b':
- g_nMaxContextIdPerThread = atol(argv[i]+2);
- break;
- case 'm':
- g_nStatusDataSize = atol(argv[i]+2);
- if(g_nStatusDataSize>sizeof(STATUS_DATA))
- {
- g_nStatusDataSize = sizeof(STATUS_DATA);
- }
- break;
- case 'i':
- g_bInsertInitial = true;
- break;
- case 'v':
- g_bVerifyInitial = true;
- break;
- case 'd':
- bCreateTable = true;
- break;
- case 'f':
- bStoredTable = false;
- break;
- case 'w':
- g_bWriteTuple = true;
- break;
- case 'r':
- g_bReport = true;
- if(argv[i][2]=='+')
- {
- g_bReportPlus = true;
- }
- break;
- case 'c':
- g_nMaxCallsPerSecond = atol(argv[i]+2);
- break;
- case '?':
- default:
- ShowHelp(argv[0]);
- return -1;
- }
- }
- else
- {
- ShowHelp(argv[0]);
- return -1;
- }
- }
- if(bCreateTable)
- puts("-d\tcreate the table");
- if(g_bInsertInitial)
- printf("-i\tinsert initial records\n");
- if(g_bVerifyInitial)
- printf("-v\tverify initial records\n");
- if(g_nNumThreads>0)
- printf("-t%ld\tnumber of threads making calls\n", g_nNumThreads);
- if(g_nNumThreads>0)
- {
- printf("-s%ld\toffset for primary key\n", nSeed);
- printf("-b%ld\tbatch size per thread\n", g_nMaxContextIdPerThread);
- }
- if(g_nMaxCallsPerSecond>0)
- printf("-c%ld\tmax number of calls per second for this process\n", g_nMaxCallsPerSecond);
- if(!bStoredTable)
- puts("-f\tno checkpointing and no logging to disk");
- if(g_bWriteTuple)
- puts("-w\tuse writeTuple instead of insertTuple");
- if(g_bReport)
- puts("-r\treport response time statistics");
- if(g_bReportPlus)
- puts("-r+\treport response time distribution");
-
- if(!bCreateTable && g_nNumThreads<=0)
- {
- ShowHelp(argv[0]);
- return -1;
- }
- printf("-m%ld\tsize of context data\n", g_nStatusDataSize);
-
- g_szTableName = (bStoredTable ? c_szTableNameStored : c_szTableNameTemp);
-
-#ifdef NDB_WIN32
- SetConsoleCtrlHandler(ConsoleCtrlHandler, true);
-#else
- signal(SIGINT, CtrlCHandler);
-#endif
-
- if(g_bReport)
- {
- g_plCountMillisecForCall = new long[c_nMaxMillisecForAllCall];
- memset(g_plCountMillisecForCall, 0, c_nMaxMillisecForAllCall*sizeof(long));
- g_plCountMillisecForTrans = new long[c_nMaxMillisecForAllTrans];
- memset(g_plCountMillisecForTrans, 0, c_nMaxMillisecForAllTrans*sizeof(long));
- }
-
- g_pNdbMutexIncrement = NdbMutex_Create();
- g_pNdbMutexPrintf = NdbMutex_Create();
-#ifdef NDB_WIN32
- hShutdownEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
-#endif
-
- Ndb* pNdb = new Ndb(c_szDatabaseName);
- if(!pNdb)
- {
- printf("could not construct ndb\n");
- return 1;
- }
-
- if(pNdb->init(1) || pNdb->waitUntilReady())
- {
- ReportNdbError("could not initialize ndb\n", pNdb->getNdbError());
- delete pNdb;
- return 2;
- }
-
- if(bCreateTable)
- {
- printf("Create CallContext table\n");
- if (bStoredTable)
- {
- if (CreateCallContextTable(pNdb, c_szTableNameStored, true))
- {
- printf("Create table failed\n");
- delete pNdb;
- return 3;
- }
- }
- else
- {
- if (CreateCallContextTable(pNdb, c_szTableNameTemp, false))
- {
- printf("Create table failed\n");
- delete pNdb;
- return 3;
- }
- }
- }
-
- if(g_nNumThreads>0)
- {
- printf("creating %d threads\n", (int)g_nNumThreads);
- if(g_bInsertInitial)
- {
- printf("each thread will insert %ld initial records, total %ld inserts\n",
- g_nMaxContextIdPerThread, g_nNumThreads*g_nMaxContextIdPerThread);
- }
- if(g_bVerifyInitial)
- {
- printf("each thread will verify %ld initial records, total %ld reads\n",
- g_nMaxContextIdPerThread, g_nNumThreads*g_nMaxContextIdPerThread);
- }
-
- g_nNumberOfInitialInsert = 0;
- g_nNumberOfInitialVerify = 0;
-
- NDB_TICKS tStartTime = NdbTick_CurrentMillisecond();
- NdbThread* pThreads[256];
- int pnStartingRecordNum[256];
- int ij;
- for(ij=0;ij<g_nNumThreads;ij++)
- {
- pnStartingRecordNum[ij] = (ij*g_nMaxContextIdPerThread) + nSeed;
- }
-
- for(ij=0;ij<g_nNumThreads;ij++)
- {
- pThreads[ij] = NdbThread_Create(RuntimeCallContext,
- (void**)(pnStartingRecordNum+ij),
- 0, "RuntimeCallContext", NDB_THREAD_PRIO_LOW);
- }
-
- //Wait for the threads to finish
- for(ij=0;ij<g_nNumThreads;ij++)
- {
- void* status;
- NdbThread_WaitFor(pThreads[ij], &status);
- }
- NDB_TICKS tEndTime = NdbTick_CurrentMillisecond();
-
- //Print time taken
- printf("Time Taken for %ld Calls is %ld msec (= %ld calls/sec)\n",
- g_nNumCallsProcessed,
- (long)(tEndTime-tStartTime),
- (long)((1000*g_nNumCallsProcessed)/(tEndTime-tStartTime)));
-
- if(g_bInsertInitial)
- printf("successfully inserted %ld tuples\n", g_nNumberOfInitialInsert);
- if(g_bVerifyInitial)
- printf("successfully verified %ld tuples\n", g_nNumberOfInitialVerify);
- }
-
- delete pNdb;
-
-#ifdef NDB_WIN32
- CloseHandle(hShutdownEvent);
-#endif
- NdbMutex_Destroy(g_pNdbMutexIncrement);
- NdbMutex_Destroy(g_pNdbMutexPrintf);
-
- if(g_bReport)
- {
- ReportResponseTimeStatistics("Calls", g_plCountMillisecForCall, c_nMaxMillisecForAllCall);
- ReportResponseTimeStatistics("Transactions", g_plCountMillisecForTrans, c_nMaxMillisecForAllTrans);
-
- delete[] g_plCountMillisecForCall;
- delete[] g_plCountMillisecForTrans;
- }
-
- return 0;
-}
-
diff --git a/storage/ndb/test/ndbapi/ndb_async1.cpp b/storage/ndb/test/ndbapi/ndb_async1.cpp
deleted file mode 100644
index 86bf1cd0543..00000000000
--- a/storage/ndb/test/ndbapi/ndb_async1.cpp
+++ /dev/null
@@ -1,647 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-//#define DEBUG_ON
-
-#include "userInterface.h"
-
-#include "macros.h"
-#include "ndb_schema.hpp"
-#include "ndb_error.hpp"
-
-#include <NdbApi.hpp>
-
-inline
-NdbConnection *
-startTransaction(Ndb * pNDB,
- ServerId inServerId,
- const SubscriberNumber inNumber){
-
- const int keyDataLenBytes = sizeof(ServerId)+SUBSCRIBER_NUMBER_LENGTH;
- const int keyDataLen_64Words = keyDataLenBytes >> 3;
-
- Uint64 keyDataBuf[keyDataLen_64Words+1]; // The "+1" is for rounding...
-
- char * keyDataBuf_charP = (char *)&keyDataBuf[0];
- Uint32 * keyDataBuf_wo32P = (Uint32 *)&keyDataBuf[0];
-
- // Server Id comes first
- keyDataBuf_wo32P[0] = inServerId;
- // Then subscriber number
- memcpy(&keyDataBuf_charP[sizeof(ServerId)], inNumber,
- SUBSCRIBER_NUMBER_LENGTH);
-
- return pNDB->startTransaction(0, keyDataBuf_charP, keyDataLenBytes);
-}
-
-void T1_Callback(int result, NdbConnection * pCon, void * threadData);
-void T2_Callback(int result, NdbConnection * pCon, void * threadData);
-void T3_Callback_1(int result, NdbConnection * pCon, void * threadData);
-void T3_Callback_2(int result, NdbConnection * pCon, void * threadData);
-void T3_Callback_3(int result, NdbConnection * pCon, void * threadData);
-void T4_Callback_1(int result, NdbConnection * pCon, void * threadData);
-void T4_Callback_2(int result, NdbConnection * pCon, void * threadData);
-void T4_Callback_3(int result, NdbConnection * pCon, void * threadData);
-void T5_Callback_1(int result, NdbConnection * pCon, void * threadData);
-void T5_Callback_2(int result, NdbConnection * pCon, void * threadData);
-void T5_Callback_3(int result, NdbConnection * pCon, void * threadData);
-
-/**
- * Transaction 1 - T1
- *
- * Update location and changed by/time on a subscriber
- *
- * Input:
- * SubscriberNumber,
- * Location,
- * ChangedBy,
- * ChangedTime
- *
- * Output:
- */
-void
-start_T1(Ndb * pNDB, ThreadData * td){
-
- DEBUG2("T1(%.*s): - Starting\n", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number);
-
- int check;
- NdbConnection * pCON = pNDB->startTransaction();
- if (pCON != NULL) {
- NdbOperation *MyOp = pCON->getNdbOperation(SUBSCRIBER_TABLE);
- if (MyOp != NULL) {
- MyOp->updateTuple();
- MyOp->equal(IND_SUBSCRIBER_NUMBER,
- td->transactionData.number);
- MyOp->setValue(IND_SUBSCRIBER_LOCATION,
- (char *)&td->transactionData.location);
- MyOp->setValue(IND_SUBSCRIBER_CHANGED_BY,
- td->transactionData.changed_by);
- MyOp->setValue(IND_SUBSCRIBER_CHANGED_TIME,
- td->transactionData.changed_time);
- pCON->executeAsynchPrepare( Commit , T1_Callback, td);
- } else {
- CHECK_NULL(MyOp, "T1: getNdbOperation", pCON);
- }//if
- } else {
- error_handler("T1-1: startTranscation",
- pNDB->getNdbErrorString(),
- pNDB->getNdbError());
- }//if
-}
-
-void
-T1_Callback(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
-
- DEBUG2("T1(%.*s): - Completing\n", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number);
-
- CHECK_MINUS_ONE(result, "T1: Commit",
- pCON);
- td->pNDB->closeTransaction(pCON);
- complete_T1(td);
-}
-
-/**
- * Transaction 2 - T2
- *
- * Read from Subscriber:
- *
- * Input:
- * SubscriberNumber
- *
- * Output:
- * Location
- * Changed by
- * Changed Timestamp
- * Name
- */
-void
-start_T2(Ndb * pNDB, ThreadData * td){
-
- DEBUG3("T2(%.*s, %p): - Starting\n", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.location);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * pCON = pNDB->startTransaction();
- if (pCON == NULL)
- error_handler("T2-1: startTransaction",
- pNDB->getNdbErrorString(),
- pNDB->getNdbError());
-
- NdbOperation *MyOp= pCON->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOp, "T2: getNdbOperation",
- pCON);
-
- MyOp->readTuple();
- MyOp->equal(IND_SUBSCRIBER_NUMBER,
- td->transactionData.number);
- MyOp->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)&td->transactionData.location);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_BY,
- td->transactionData.changed_by);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- td->transactionData.changed_time);
- MyOp->getValue(IND_SUBSCRIBER_NAME,
- td->transactionData.name);
- pCON->executeAsynchPrepare( Commit, T2_Callback, td );
-}
-
-void
-T2_Callback(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
- DEBUG3("T2(%.*s, %p): - Completing\n", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.location);
-
- CHECK_MINUS_ONE(result, "T2: Commit", pCON);
- td->pNDB->closeTransaction(pCON);
- complete_T2(td);
-}
-
-/**
- * Transaction 3 - T3
- *
- * Read session details
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- *
- * Output:
- * BranchExecuted
- * SessionDetails
- * ChangedBy
- * ChangedTime
- * Location
- */
-void
-start_T3(Ndb * pNDB, ThreadData * td){
-
- DEBUG3("T3(%.*s, %.2d): - Starting\n", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * pCON = startTransaction(pNDB,
- td->transactionData.server_id,
- td->transactionData.number);
- if (pCON == NULL)
- error_handler("T3-1: startTranscation",
- pNDB->getNdbErrorString(),
- pNDB->getNdbError());
-
- NdbOperation *MyOp= pCON->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOp, "T3-1: getNdbOperation",
- pCON);
-
- MyOp->readTuple();
- MyOp->equal(IND_SUBSCRIBER_NUMBER,
- td->transactionData.number);
- MyOp->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)&td->transactionData.location);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_BY,
- td->transactionData.changed_by);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- td->transactionData.changed_time);
- MyOp->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&td->transactionData.group_id);
- MyOp->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&td->transactionData.sessions);
- pCON->executeAsynchPrepare( NoCommit , T3_Callback_1, td);
-}
-
-void
-T3_Callback_1(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
- DEBUG3("T3(%.*s, %.2d): - Callback 1\n", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- CHECK_MINUS_ONE(result, "T3-1: NoCommit", pCON);
-
- NdbOperation * MyOp = pCON->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOp, "T3-2: getNdbOperation",
- pCON);
-
- MyOp->readTuple();
- MyOp->equal(IND_GROUP_ID,
- (char*)&td->transactionData.group_id);
- MyOp->getValue(IND_GROUP_ALLOW_READ,
- (char *)&td->transactionData.permission);
- pCON->executeAsynchPrepare( NoCommit, T3_Callback_2, td );
-}
-
-void
-T3_Callback_2(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
-
- CHECK_MINUS_ONE(result, "T3-2: NoCommit", pCON);
-
- Uint32 permission = td->transactionData.permission;
- Uint32 sessions = td->transactionData.sessions;
- Uint32 server_bit = td->transactionData.server_bit;
-
- if(((permission & server_bit) == server_bit) &&
- ((sessions & server_bit) == server_bit)){
-
- memcpy(td->transactionData.suffix,
- &td->transactionData.number
- [SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH],
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
- DEBUG5("T3(%.*s, %.2d): - Callback 2 - reading(%.*s)\n",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id,
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH,
- td->transactionData.suffix);
-
- /* Operation 3 */
- NdbOperation * MyOp = pCON->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOp, "T3-3: getNdbOperation",
- pCON);
-
- MyOp->simpleRead();
- MyOp->equal(IND_SESSION_SUBSCRIBER,
- (char*)td->transactionData.number);
- MyOp->equal(IND_SESSION_SERVER,
- (char*)&td->transactionData.server_id);
- MyOp->getValue(IND_SESSION_DATA,
- (char *)td->transactionData.session_details);
-
- /* Operation 4 */
- MyOp = pCON->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOp, "T3-4: getNdbOperation",
- pCON);
-
- MyOp->interpretedUpdateTuple();
- MyOp->equal(IND_SERVER_ID,
- (char*)&td->transactionData.server_id);
- MyOp->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)td->transactionData.suffix);
- MyOp->incValue(IND_SERVER_READS, (uint32)1);
- td->transactionData.branchExecuted = 1;
- } else {
- DEBUG3("T3(%.*s, %.2d): - Callback 2 - no read\n",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
- td->transactionData.branchExecuted = 0;
- }
- pCON->executeAsynchPrepare( Commit, T3_Callback_3, td );
-}
-
-void
-T3_Callback_3(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
- DEBUG3("T3(%.*s, %.2d): - Completing\n", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- CHECK_MINUS_ONE(result, "T3-3: Commit", pCON);
-
- td->pNDB->closeTransaction(pCON);
- complete_T3(td);
-}
-
-/**
- * Transaction 4 - T4
- *
- * Create session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * SessionDetails,
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-void
-start_T4(Ndb * pNDB, ThreadData * td){
-
- DEBUG3("T4(%.*s, %.2d): - Starting\n", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * pCON = startTransaction(pNDB,
- td->transactionData.server_id,
- td->transactionData.number);
- if (pCON == NULL)
- error_handler("T4-1: startTranscation",
- pNDB->getNdbErrorString(),
- pNDB->getNdbError());
-
- NdbOperation *MyOp= pCON->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOp, "T4-1: getNdbOperation",
- pCON);
-
- MyOp->interpretedUpdateTuple();
- MyOp->equal(IND_SUBSCRIBER_NUMBER,
- td->transactionData.number);
- MyOp->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)&td->transactionData.location);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_BY,
- td->transactionData.changed_by);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- td->transactionData.changed_time);
- MyOp->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&td->transactionData.group_id);
- MyOp->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&td->transactionData.sessions);
- MyOp->incValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)td->transactionData.server_bit);
- pCON->executeAsynchPrepare( NoCommit , T4_Callback_1, td);
-}
-
-void
-T4_Callback_1(int result, NdbConnection * pCON, void * threadData){
- CHECK_MINUS_ONE(result, "T4-1: NoCommit", pCON);
- ThreadData * td = (ThreadData *)threadData;
-
- DEBUG3("T4(%.*s, %.2d): - Callback 1\n",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
-
- NdbOperation * MyOp = pCON->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOp, "T4-2: getNdbOperation",
- pCON);
-
- MyOp->readTuple();
- MyOp->equal(IND_GROUP_ID,
- (char*)&td->transactionData.group_id);
- MyOp->getValue(IND_GROUP_ALLOW_INSERT,
- (char *)&td->transactionData.permission);
- pCON->executeAsynchPrepare( NoCommit , T4_Callback_2, td);
-}
-
-void
-T4_Callback_2(int result, NdbConnection * pCON, void * threadData){
- CHECK_MINUS_ONE(result, "T4-2: NoCommit", pCON);
- ThreadData * td = (ThreadData *)threadData;
-
- Uint32 permission = td->transactionData.permission;
- Uint32 sessions = td->transactionData.sessions;
- Uint32 server_bit = td->transactionData.server_bit;
-
- if(((permission & server_bit) == server_bit) &&
- ((sessions & server_bit) == 0)){
-
- memcpy(td->transactionData.suffix,
- &td->transactionData.number
- [SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH],
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
-
- DEBUG5("T4(%.*s, %.2d): - Callback 2 - inserting(%.*s)\n",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id,
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH,
- td->transactionData.suffix);
-
- /* Operation 3 */
-
- NdbOperation * MyOp = pCON->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOp, "T4-3: getNdbOperation",
- pCON);
-
- MyOp->insertTuple();
- MyOp->equal(IND_SESSION_SUBSCRIBER,
- (char*)td->transactionData.number);
- MyOp->equal(IND_SESSION_SERVER,
- (char*)&td->transactionData.server_id);
- MyOp->setValue(SESSION_DATA,
- (char *)td->transactionData.session_details);
- /* Operation 4 */
-
- /* Operation 5 */
- MyOp = pCON->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOp, "T4-5: getNdbOperation",
- pCON);
-
- MyOp->interpretedUpdateTuple();
- MyOp->equal(IND_SERVER_ID,
- (char*)&td->transactionData.server_id);
- MyOp->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)td->transactionData.suffix);
- MyOp->incValue(IND_SERVER_INSERTS, (uint32)1);
- td->transactionData.branchExecuted = 1;
- } else {
- td->transactionData.branchExecuted = 0;
- DEBUG5("T4(%.*s, %.2d): - Callback 2 - %s %s\n",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id,
- ((permission & server_bit) ?
- "permission - " : "no permission - "),
- ((sessions & server_bit) ?
- "in session - " : "no in session - "));
- }
-
- if(!td->transactionData.do_rollback && td->transactionData.branchExecuted){
- pCON->executeAsynchPrepare(Commit, T4_Callback_3, td);
- } else {
- pCON->executeAsynchPrepare(Rollback, T4_Callback_3, td);
- }
-}
-
-void
-T4_Callback_3(int result, NdbConnection * pCON, void * threadData){
- CHECK_MINUS_ONE(result, "T4-3: Commit", pCON);
- ThreadData * td = (ThreadData *)threadData;
-
- DEBUG3("T4(%.*s, %.2d): - Completing\n",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- td->pNDB->closeTransaction(pCON);
- complete_T4(td);
-}
-
-/**
- * Transaction 5 - T5
- *
- * Delete session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-void
-start_T5(Ndb * pNDB, ThreadData * td){
-
- DEBUG3("T5(%.*s, %.2d): - Starting\n", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * pCON = pNDB->startTransaction();
- if (pCON == NULL)
- error_handler("T5-1: startTranscation",
- pNDB->getNdbErrorString(),
- pNDB->getNdbError());
-
- NdbOperation * MyOp= pCON->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOp, "T5-1: getNdbOperation",
- pCON);
-
- MyOp->interpretedUpdateTuple();
- MyOp->equal(IND_SUBSCRIBER_NUMBER,
- td->transactionData.number);
- MyOp->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)&td->transactionData.location);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_BY,
- td->transactionData.changed_by);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- td->transactionData.changed_time);
- MyOp->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&td->transactionData.group_id);
- MyOp->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&td->transactionData.sessions);
- MyOp->subValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)td->transactionData.server_bit);
- pCON->executeAsynchPrepare( NoCommit, T5_Callback_1, td );
-}
-
-void
-T5_Callback_1(int result, NdbConnection * pCON, void * threadData){
- CHECK_MINUS_ONE(result, "T5-1: NoCommit", pCON);
- ThreadData * td = (ThreadData *)threadData;
-
- DEBUG3("T5(%.*s, %.2d): - Callback 1\n",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- NdbOperation * MyOp = pCON->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOp, "T5-2: getNdbOperation",
- pCON);
-
- MyOp->readTuple();
- MyOp->equal(IND_GROUP_ID,
- (char*)&td->transactionData.group_id);
- MyOp->getValue(IND_GROUP_ALLOW_DELETE,
- (char *)&td->transactionData.permission);
- pCON->executeAsynchPrepare( NoCommit, T5_Callback_2, td );
-}
-
-void
-T5_Callback_2(int result, NdbConnection * pCON, void * threadData){
- CHECK_MINUS_ONE(result, "T5-2: NoCommit", pCON);
- ThreadData * td = (ThreadData *)threadData;
-
- Uint32 permission = td->transactionData.permission;
- Uint32 sessions = td->transactionData.sessions;
- Uint32 server_bit = td->transactionData.server_bit;
-
- if(((permission & server_bit) == server_bit) &&
- ((sessions & server_bit) == server_bit)){
-
- memcpy(td->transactionData.suffix,
- &td->transactionData.number
- [SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH],
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
-
- DEBUG5("T5(%.*s, %.2d): - Callback 2 - deleting(%.*s)\n",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id,
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH,
- td->transactionData.suffix);
-
- /* Operation 3 */
- NdbOperation * MyOp = pCON->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOp, "T5-3: getNdbOperation",
- pCON);
-
- MyOp->deleteTuple();
- MyOp->equal(IND_SESSION_SUBSCRIBER,
- (char*)td->transactionData.number);
- MyOp->equal(IND_SESSION_SERVER,
- (char*)&td->transactionData.server_id);
- /* Operation 4 */
-
- /* Operation 5 */
- MyOp = pCON->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOp, "T5-5: getNdbOperation",
- pCON);
-
- MyOp->interpretedUpdateTuple();
- MyOp->equal(IND_SERVER_ID,
- (char*)&td->transactionData.server_id);
- MyOp->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)td->transactionData.suffix);
- MyOp->incValue(IND_SERVER_DELETES, (uint32)1);
- td->transactionData.branchExecuted = 1;
- } else {
- td->transactionData.branchExecuted = 0;
-
- DEBUG5("T5(%.*s, %.2d): - Callback 2 - no delete - %s %s\n",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id,
- ((permission & server_bit) ?
- "permission - " : "no permission - "),
- ((sessions & server_bit) ?
- "in session - " : "no in session - "));
- }
-
- if(!td->transactionData.do_rollback && td->transactionData.branchExecuted){
- pCON->executeAsynchPrepare(Commit, T5_Callback_3, td);
- } else {
- pCON->executeAsynchPrepare(Rollback, T5_Callback_3, td);
- }
-}
-
-void
-T5_Callback_3(int result, NdbConnection * pCON, void * threadData){
- CHECK_MINUS_ONE(result, "T5-3: Commit", pCON);
- ThreadData * td = (ThreadData *)threadData;
-
- DEBUG3("T5(%.*s, %.2d): - Completing\n",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- td->pNDB->closeTransaction(pCON);
- complete_T5(td);
-}
diff --git a/storage/ndb/test/ndbapi/ndb_async2.cpp b/storage/ndb/test/ndbapi/ndb_async2.cpp
deleted file mode 100644
index e02407f8471..00000000000
--- a/storage/ndb/test/ndbapi/ndb_async2.cpp
+++ /dev/null
@@ -1,754 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-//#define DEBUG_ON
-
-#include <string.h>
-#include "userInterface.h"
-
-#include "macros.h"
-#include "ndb_schema.hpp"
-#include "ndb_error.hpp"
-#include <NdbSleep.h>
-
-#include <NdbApi.hpp>
-
-void T1_Callback(int result, NdbConnection * pCon, void * threadData);
-void T2_Callback(int result, NdbConnection * pCon, void * threadData);
-void T3_Callback_1(int result, NdbConnection * pCon, void * threadData);
-void T3_Callback_2(int result, NdbConnection * pCon, void * threadData);
-void T3_Callback_3(int result, NdbConnection * pCon, void * threadData);
-void T4_Callback_1(int result, NdbConnection * pCon, void * threadData);
-void T4_Callback_2(int result, NdbConnection * pCon, void * threadData);
-void T4_Callback_3(int result, NdbConnection * pCon, void * threadData);
-void T5_Callback_1(int result, NdbConnection * pCon, void * threadData);
-void T5_Callback_2(int result, NdbConnection * pCon, void * threadData);
-void T5_Callback_3(int result, NdbConnection * pCon, void * threadData);
-
-static int stat_async = 0;
-
-/**
- * Transaction 1 - T1
- *
- * Update location and changed by/time on a subscriber
- *
- * Input:
- * SubscriberNumber,
- * Location,
- * ChangedBy,
- * ChangedTime
- *
- * Output:
- */
-
-#define SFX_START (SUBSCRIBER_NUMBER_LENGTH - SUBSCRIBER_NUMBER_SUFFIX_LENGTH)
-
-inline
-NdbConnection *
-startTransaction(Ndb * pNDB, ThreadData * td){
- return pNDB->startTransactionDGroup (0,
- &td->transactionData.number[SFX_START],
- 1);
-}
-
-void
-start_T1(Ndb * pNDB, ThreadData * td, int async){
-
- DEBUG2("T1(%.*s): - Starting", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number);
-
- NdbConnection * pCON = 0;
- while((pCON = startTransaction(pNDB, td)) == 0){
- CHECK_ALLOWED_ERROR("T1: startTransaction", td, pNDB->getNdbError());
- NdbSleep_MilliSleep(10);
- }
-
- NdbOperation *MyOp = pCON->getNdbOperation(SUBSCRIBER_TABLE);
- if (MyOp != NULL) {
- MyOp->updateTuple();
- MyOp->equal(IND_SUBSCRIBER_NUMBER,
- td->transactionData.number);
- MyOp->setValue(IND_SUBSCRIBER_LOCATION,
- (char *)&td->transactionData.location);
- MyOp->setValue(IND_SUBSCRIBER_CHANGED_BY,
- td->transactionData.changed_by);
- MyOp->setValue(IND_SUBSCRIBER_CHANGED_TIME,
- td->transactionData.changed_time);
- if (async == 1) {
- pCON->executeAsynchPrepare( Commit , T1_Callback, td);
- } else {
- int result = pCON->execute(Commit);
- T1_Callback(result, pCON, (void*)td);
- return;
- }//if
- } else {
- CHECK_NULL(MyOp, "T1: getNdbOperation", td, pCON->getNdbError());
- }//if
-}
-
-void
-T1_Callback(int result, NdbConnection * pCON, void * threadData) {
- ThreadData * td = (ThreadData *)threadData;
-
- DEBUG2("T1(%.*s): - Completing", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number);
-
- if (result == -1) {
- CHECK_ALLOWED_ERROR("T1: Commit", td, pCON->getNdbError());
- td->pNDB->closeTransaction(pCON);
- start_T1(td->pNDB, td, stat_async);
- return;
- }//if
- td->pNDB->closeTransaction(pCON);
- complete_T1(td);
-}
-
-/**
- * Transaction 2 - T2
- *
- * Read from Subscriber:
- *
- * Input:
- * SubscriberNumber
- *
- * Output:
- * Location
- * Changed by
- * Changed Timestamp
- * Name
- */
-void
-start_T2(Ndb * pNDB, ThreadData * td, int async){
-
- DEBUG3("T2(%.*s, %d): - Starting", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.location);
-
- NdbConnection * pCON = 0;
-
- while((pCON = startTransaction(pNDB, td)) == 0){
- CHECK_ALLOWED_ERROR("T2-1: startTransaction", td, pNDB->getNdbError());
- NdbSleep_MilliSleep(10);
- }
-
- NdbOperation *MyOp= pCON->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOp, "T2: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->readTuple();
- MyOp->equal(IND_SUBSCRIBER_NUMBER,
- td->transactionData.number);
- MyOp->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)&td->transactionData.location);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_BY,
- td->transactionData.changed_by);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- td->transactionData.changed_time);
- MyOp->getValue(IND_SUBSCRIBER_NAME,
- td->transactionData.name);
- if (async == 1) {
- pCON->executeAsynchPrepare( Commit , T2_Callback, td);
- } else {
- int result = pCON->execute(Commit);
- T2_Callback(result, pCON, (void*)td);
- return;
- }//if
-}
-
-void
-T2_Callback(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
- DEBUG3("T2(%.*s, %d): - Completing", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.location);
-
- if (result == -1) {
- CHECK_ALLOWED_ERROR("T2: Commit", td, pCON->getNdbError());
- td->pNDB->closeTransaction(pCON);
- start_T2(td->pNDB, td, stat_async);
- return;
- }//if
- td->pNDB->closeTransaction(pCON);
- complete_T2(td);
-}
-
-/**
- * Transaction 3 - T3
- *
- * Read session details
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- *
- * Output:
- * BranchExecuted
- * SessionDetails
- * ChangedBy
- * ChangedTime
- * Location
- */
-void
-start_T3(Ndb * pNDB, ThreadData * td, int async){
-
- DEBUG3("T3(%.*s, %.2d): - Starting", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- NdbConnection * pCON = 0;
-
- while((pCON = startTransaction(pNDB, td)) == 0){
- CHECK_ALLOWED_ERROR("T3-1: startTransaction", td, pNDB->getNdbError());
- NdbSleep_MilliSleep(10);
- }
-
- NdbOperation *MyOp= pCON->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOp, "T3-1: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->readTuple();
- MyOp->equal(IND_SUBSCRIBER_NUMBER,
- td->transactionData.number);
- MyOp->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)&td->transactionData.location);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_BY,
- td->transactionData.changed_by);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- td->transactionData.changed_time);
- MyOp->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&td->transactionData.group_id);
- MyOp->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&td->transactionData.sessions);
- stat_async = async;
- if (async == 1) {
- pCON->executeAsynchPrepare( NoCommit , T3_Callback_1, td);
- } else {
- int result = pCON->execute( NoCommit );
- T3_Callback_1(result, pCON, (void*)td);
- return;
- }//if
-}
-
-void
-T3_Callback_1(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
- DEBUG3("T3(%.*s, %.2d): - Callback 1", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- if (result == -1) {
- CHECK_ALLOWED_ERROR("T3-1: execute", td, pCON->getNdbError());
- td->pNDB->closeTransaction(pCON);
- start_T3(td->pNDB, td, stat_async);
- return;
- }//if
-
- NdbOperation * MyOp = pCON->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOp, "T3-2: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->readTuple();
- MyOp->equal(IND_GROUP_ID,
- (char*)&td->transactionData.group_id);
- MyOp->getValue(IND_GROUP_ALLOW_READ,
- (char *)&td->transactionData.permission);
- if (stat_async == 1) {
- pCON->executeAsynchPrepare( NoCommit , T3_Callback_2, td);
- } else {
- int result = pCON->execute( NoCommit );
- T3_Callback_2(result, pCON, (void*)td);
- return;
- }//if
-}
-
-void
-T3_Callback_2(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
-
- if (result == -1) {
- CHECK_ALLOWED_ERROR("T3-2: execute", td, pCON->getNdbError());
- td->pNDB->closeTransaction(pCON);
- start_T3(td->pNDB, td, stat_async);
- return;
- }//if
-
- Uint32 permission = td->transactionData.permission;
- Uint32 sessions = td->transactionData.sessions;
- Uint32 server_bit = td->transactionData.server_bit;
-
- if(((permission & server_bit) == server_bit) &&
- ((sessions & server_bit) == server_bit)){
-
- memcpy(td->transactionData.suffix,
- &td->transactionData.number[SFX_START],
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
- DEBUG5("T3(%.*s, %.2d): - Callback 2 - reading(%.*s)",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id,
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH,
- td->transactionData.suffix);
-
- /* Operation 3 */
- NdbOperation * MyOp = pCON->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOp, "T3-3: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->simpleRead();
- MyOp->equal(IND_SESSION_SUBSCRIBER,
- (char*)td->transactionData.number);
- MyOp->equal(IND_SESSION_SERVER,
- (char*)&td->transactionData.server_id);
- MyOp->getValue(IND_SESSION_DATA,
- (char *)td->transactionData.session_details);
-
- /* Operation 4 */
- MyOp = pCON->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOp, "T3-4: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->interpretedUpdateTuple();
- MyOp->equal(IND_SERVER_ID,
- (char*)&td->transactionData.server_id);
- MyOp->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)td->transactionData.suffix);
- MyOp->incValue(IND_SERVER_READS, (uint32)1);
- td->transactionData.branchExecuted = 1;
- } else {
- DEBUG3("T3(%.*s, %.2d): - Callback 2 - no read",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
- td->transactionData.branchExecuted = 0;
- }
- if (stat_async == 1) {
- pCON->executeAsynchPrepare( Commit , T3_Callback_3, td);
- } else {
- int result = pCON->execute( Commit );
- T3_Callback_3(result, pCON, (void*)td);
- return;
- }//if
-}
-
-void
-T3_Callback_3(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
- DEBUG3("T3(%.*s, %.2d): - Completing", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- if (result == -1) {
- CHECK_ALLOWED_ERROR("T3-3: Commit", td, pCON->getNdbError());
- td->pNDB->closeTransaction(pCON);
- start_T3(td->pNDB, td, stat_async);
- return;
- }//if
- td->pNDB->closeTransaction(pCON);
- complete_T3(td);
-}
-
-/**
- * Transaction 4 - T4
- *
- * Create session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * SessionDetails,
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-void
-start_T4(Ndb * pNDB, ThreadData * td, int async){
-
- DEBUG3("T4(%.*s, %.2d): - Starting", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- NdbConnection * pCON = 0;
- while((pCON = startTransaction(pNDB, td)) == 0){
- CHECK_ALLOWED_ERROR("T4-1: startTransaction", td, pNDB->getNdbError());
- NdbSleep_MilliSleep(10);
- }
-
- NdbOperation *MyOp= pCON->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOp, "T4-1: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->interpretedUpdateTuple();
- MyOp->equal(IND_SUBSCRIBER_NUMBER,
- td->transactionData.number);
- MyOp->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)&td->transactionData.location);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_BY,
- td->transactionData.changed_by);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- td->transactionData.changed_time);
- MyOp->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&td->transactionData.group_id);
- MyOp->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&td->transactionData.sessions);
- MyOp->incValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)td->transactionData.server_bit);
- stat_async = async;
- if (async == 1) {
- pCON->executeAsynchPrepare( NoCommit , T4_Callback_1, td);
- } else {
- int result = pCON->execute( NoCommit );
- T4_Callback_1(result, pCON, (void*)td);
- return;
- }//if
-}
-
-void
-T4_Callback_1(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
- if (result == -1) {
- CHECK_ALLOWED_ERROR("T4-1: execute", td, pCON->getNdbError());
- td->pNDB->closeTransaction(pCON);
- start_T4(td->pNDB, td, stat_async);
- return;
- }//if
-
- DEBUG3("T4(%.*s, %.2d): - Callback 1",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
-
- NdbOperation * MyOp = pCON->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOp, "T4-2: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->readTuple();
- MyOp->equal(IND_GROUP_ID,
- (char*)&td->transactionData.group_id);
- MyOp->getValue(IND_GROUP_ALLOW_INSERT,
- (char *)&td->transactionData.permission);
- if (stat_async == 1) {
- pCON->executeAsynchPrepare( NoCommit , T4_Callback_2, td);
- } else {
- int result = pCON->execute( NoCommit );
- T4_Callback_2(result, pCON, (void*)td);
- return;
- }//if
-}
-
-void
-T4_Callback_2(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
- if (result == -1) {
- CHECK_ALLOWED_ERROR("T4-2: execute", td, pCON->getNdbError());
- td->pNDB->closeTransaction(pCON);
- start_T4(td->pNDB, td, stat_async);
- return;
- }//if
-
- Uint32 permission = td->transactionData.permission;
- Uint32 sessions = td->transactionData.sessions;
- Uint32 server_bit = td->transactionData.server_bit;
-
- if(((permission & server_bit) == server_bit) &&
- ((sessions & server_bit) == 0)){
-
- memcpy(td->transactionData.suffix,
- &td->transactionData.number[SFX_START],
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
-
- DEBUG5("T4(%.*s, %.2d): - Callback 2 - inserting(%.*s)",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id,
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH,
- td->transactionData.suffix);
-
- /* Operation 3 */
-
- NdbOperation * MyOp = pCON->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOp, "T4-3: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->insertTuple();
- MyOp->equal(IND_SESSION_SUBSCRIBER,
- (char*)td->transactionData.number);
- MyOp->equal(IND_SESSION_SERVER,
- (char*)&td->transactionData.server_id);
- MyOp->setValue(SESSION_DATA,
- (char *)td->transactionData.session_details);
- /* Operation 4 */
-
- /* Operation 5 */
- MyOp = pCON->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOp, "T4-5: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->interpretedUpdateTuple();
- MyOp->equal(IND_SERVER_ID,
- (char*)&td->transactionData.server_id);
- MyOp->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)td->transactionData.suffix);
- MyOp->incValue(IND_SERVER_INSERTS, (uint32)1);
- td->transactionData.branchExecuted = 1;
- } else {
- td->transactionData.branchExecuted = 0;
- DEBUG5("T4(%.*s, %.2d): - Callback 2 - %s %s",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id,
- ((permission & server_bit) ?
- "permission - " : "no permission - "),
- ((sessions & server_bit) ?
- "in session - " : "no in session - "));
- }
-
- if(!td->transactionData.do_rollback && td->transactionData.branchExecuted){
- if (stat_async == 1) {
- pCON->executeAsynchPrepare( Commit , T4_Callback_3, td);
- } else {
- int result = pCON->execute( Commit );
- T4_Callback_3(result, pCON, (void*)td);
- return;
- }//if
- } else {
- if (stat_async == 1) {
- pCON->executeAsynchPrepare( Rollback , T4_Callback_3, td);
- } else {
- int result = pCON->execute( Rollback );
- T4_Callback_3(result, pCON, (void*)td);
- return;
- }//if
- }
-}
-
-void
-T4_Callback_3(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
- if (result == -1) {
- CHECK_ALLOWED_ERROR("T4-3: Commit", td, pCON->getNdbError());
- td->pNDB->closeTransaction(pCON);
- start_T4(td->pNDB, td, stat_async);
- return;
- }//if
-
- DEBUG3("T4(%.*s, %.2d): - Completing",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- td->pNDB->closeTransaction(pCON);
- complete_T4(td);
-}
-
-/**
- * Transaction 5 - T5
- *
- * Delete session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-void
-start_T5(Ndb * pNDB, ThreadData * td, int async){
-
- DEBUG3("T5(%.*s, %.2d): - Starting", SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- NdbConnection * pCON = 0;
- while((pCON = startTransaction(pNDB, td)) == 0){
- CHECK_ALLOWED_ERROR("T5-1: startTransaction", td, pNDB->getNdbError());
- NdbSleep_MilliSleep(10);
- }
-
- NdbOperation * MyOp= pCON->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOp, "T5-1: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->interpretedUpdateTuple();
- MyOp->equal(IND_SUBSCRIBER_NUMBER,
- td->transactionData.number);
- MyOp->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)&td->transactionData.location);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_BY,
- td->transactionData.changed_by);
- MyOp->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- td->transactionData.changed_time);
- MyOp->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&td->transactionData.group_id);
- MyOp->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&td->transactionData.sessions);
- MyOp->subValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)td->transactionData.server_bit);
- stat_async = async;
- if (async == 1) {
- pCON->executeAsynchPrepare( NoCommit , T5_Callback_1, td);
- } else {
- int result = pCON->execute( NoCommit );
- T5_Callback_1(result, pCON, (void*)td);
- return;
- }//if
-}
-
-void
-T5_Callback_1(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
- if (result == -1) {
- CHECK_ALLOWED_ERROR("T5-1: execute", td, pCON->getNdbError());
- td->pNDB->closeTransaction(pCON);
- start_T5(td->pNDB, td, stat_async);
- return;
- }//if
-
- DEBUG3("T5(%.*s, %.2d): - Callback 1",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- NdbOperation * MyOp = pCON->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOp, "T5-2: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->readTuple();
- MyOp->equal(IND_GROUP_ID,
- (char*)&td->transactionData.group_id);
- MyOp->getValue(IND_GROUP_ALLOW_DELETE,
- (char *)&td->transactionData.permission);
- if (stat_async == 1) {
- pCON->executeAsynchPrepare( NoCommit , T5_Callback_2, td);
- } else {
- int result = pCON->execute( NoCommit );
- T5_Callback_2(result, pCON, (void*)td);
- return;
- }//if
-}
-
-void
-T5_Callback_2(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
- if (result == -1) {
- CHECK_ALLOWED_ERROR("T5-2: execute", td, pCON->getNdbError());
- td->pNDB->closeTransaction(pCON);
- start_T5(td->pNDB, td, stat_async);
- return;
- }//if
-
- Uint32 permission = td->transactionData.permission;
- Uint32 sessions = td->transactionData.sessions;
- Uint32 server_bit = td->transactionData.server_bit;
-
- if(((permission & server_bit) == server_bit) &&
- ((sessions & server_bit) == server_bit)){
-
- memcpy(td->transactionData.suffix,
- &td->transactionData.number[SFX_START],
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
-
- DEBUG5("T5(%.*s, %.2d): - Callback 2 - deleting(%.*s)",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id,
- SUBSCRIBER_NUMBER_SUFFIX_LENGTH,
- td->transactionData.suffix);
-
- /* Operation 3 */
- NdbOperation * MyOp = pCON->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOp, "T5-3: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->deleteTuple();
- MyOp->equal(IND_SESSION_SUBSCRIBER,
- (char*)td->transactionData.number);
- MyOp->equal(IND_SESSION_SERVER,
- (char*)&td->transactionData.server_id);
- /* Operation 4 */
-
- /* Operation 5 */
- MyOp = pCON->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOp, "T5-5: getNdbOperation", td,
- pCON->getNdbError());
-
- MyOp->interpretedUpdateTuple();
- MyOp->equal(IND_SERVER_ID,
- (char*)&td->transactionData.server_id);
- MyOp->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)td->transactionData.suffix);
- MyOp->incValue(IND_SERVER_DELETES, (uint32)1);
- td->transactionData.branchExecuted = 1;
- } else {
- td->transactionData.branchExecuted = 0;
-
- DEBUG5("T5(%.*s, %.2d): - Callback 2 - no delete - %s %s",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id,
- ((permission & server_bit) ?
- "permission - " : "no permission - "),
- ((sessions & server_bit) ?
- "in session - " : "no in session - "));
- }
-
- if(!td->transactionData.do_rollback && td->transactionData.branchExecuted){
- if (stat_async == 1) {
- pCON->executeAsynchPrepare( Commit , T5_Callback_3, td);
- } else {
- int result = pCON->execute( Commit );
- T5_Callback_3(result, pCON, (void*)td);
- return;
- }//if
- } else {
- if (stat_async == 1) {
- pCON->executeAsynchPrepare( Rollback , T5_Callback_3, td);
- } else {
- int result = pCON->execute( Rollback );
- T5_Callback_3(result, pCON, (void*)td);
- return;
- }//if
- }
-}
-
-void
-T5_Callback_3(int result, NdbConnection * pCON, void * threadData){
- ThreadData * td = (ThreadData *)threadData;
- if (result == -1) {
- CHECK_ALLOWED_ERROR("T5-3: Commit", td, pCON->getNdbError());
- td->pNDB->closeTransaction(pCON);
- start_T5(td->pNDB, td, stat_async);
- return;
- }//if
-
- DEBUG3("T5(%.*s, %.2d): - Completing",
- SUBSCRIBER_NUMBER_LENGTH,
- td->transactionData.number,
- td->transactionData.server_id);
-
- td->pNDB->closeTransaction(pCON);
- complete_T5(td);
-}
diff --git a/storage/ndb/test/ndbapi/ndb_user_populate.cpp b/storage/ndb/test/ndbapi/ndb_user_populate.cpp
deleted file mode 100644
index 68b97ab3e5f..00000000000
--- a/storage/ndb/test/ndbapi/ndb_user_populate.cpp
+++ /dev/null
@@ -1,165 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-extern "C" {
-#include "user_populate.h"
-}
-
-#include <ndb_global.h>
-#include <NdbApi.hpp>
-
-#include "ndb_schema.hpp"
-#include "ndb_error.hpp"
-
-int
-insert_subscriber(void * obj,
- SubscriberNumber number,
- SubscriberName name,
- GroupId groupId,
- Location l,
- ActiveSessions activeSessions,
- ChangedBy changedBy,
- ChangedTime changedTime){
- Ndb * pNDB = (Ndb *)obj;
- int check;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);
-
- check = MyOperation->insertTuple();
- CHECK_MINUS_ONE(check, "insertTuple", MyTransaction);
-
- check = MyOperation->equal(SUBSCRIBER_NUMBER, number);
- CHECK_MINUS_ONE(check, "equal", MyTransaction);
-
- check = MyOperation->setValue(SUBSCRIBER_NAME, name);
- CHECK_MINUS_ONE(check, "setValue name", MyTransaction);
-
- check = MyOperation->setValue(SUBSCRIBER_GROUP, (char*)&groupId);
- CHECK_MINUS_ONE(check, "setValue group", MyTransaction);
-
- check = MyOperation->setValue(SUBSCRIBER_LOCATION, (char*)&l);
- CHECK_MINUS_ONE(check, "setValue location", MyTransaction);
-
- check = MyOperation->setValue(SUBSCRIBER_SESSIONS, (char*)&activeSessions);
- CHECK_MINUS_ONE(check, "setValue sessions", MyTransaction);
-
- check = MyOperation->setValue(SUBSCRIBER_CHANGED_BY, changedBy);
- CHECK_MINUS_ONE(check, "setValue changedBy", MyTransaction);
-
- check = MyOperation->setValue(SUBSCRIBER_CHANGED_TIME, changedTime);
- CHECK_MINUS_ONE(check, "setValue changedTime", MyTransaction);
-
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "commit", MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
- return 0;
-}
-
-int
-insert_server(void * obj,
- ServerId serverId,
- SubscriberSuffix suffix,
- ServerName name,
- Counter noOfRead,
- Counter noOfInsert,
- Counter noOfDelete){
- Ndb * pNDB = (Ndb *)obj;
- int check;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);
-
- check = MyOperation->insertTuple();
- CHECK_MINUS_ONE(check, "insert tuple", MyTransaction);
-
- check = MyOperation->equal(SERVER_ID, (char*)&serverId);
- CHECK_MINUS_ONE(check, "setValue id", MyTransaction);
-
- check = MyOperation->setValue(SERVER_SUBSCRIBER_SUFFIX, suffix);
- CHECK_MINUS_ONE(check, "setValue suffix", MyTransaction);
-
- check = MyOperation->setValue(SERVER_NAME, name);
- CHECK_MINUS_ONE(check, "setValue name", MyTransaction);
-
- check = MyOperation->setValue(SERVER_READS, (char*)&noOfRead);
- CHECK_MINUS_ONE(check, "setValue reads", MyTransaction);
-
- check = MyOperation->setValue(SERVER_INSERTS, (char*)&noOfInsert);
- CHECK_MINUS_ONE(check, "setValue inserts", MyTransaction);
-
- check = MyOperation->setValue(SERVER_DELETES, (char*)&noOfDelete);
- CHECK_MINUS_ONE(check, "setValue deletes", MyTransaction);
-
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "commit", MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
- return 0;
-}
-
-int
-insert_group(void * obj,
- GroupId groupId,
- GroupName name,
- Permission allowRead,
- Permission allowInsert,
- Permission allowDelete){
- Ndb * pNDB = (Ndb *)obj;
- int check;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);
-
- check = MyOperation->insertTuple();
- CHECK_MINUS_ONE(check, "insertTuple", MyTransaction);
-
- check = MyOperation->equal(GROUP_ID, (char*)&groupId);
- CHECK_MINUS_ONE(check, "equal", MyTransaction);
-
- check = MyOperation->setValue(GROUP_NAME, name);
- CHECK_MINUS_ONE(check, "setValue name", MyTransaction);
-
- check = MyOperation->setValue(GROUP_ALLOW_READ, (char*)&allowRead);
- CHECK_MINUS_ONE(check, "setValue allowRead", MyTransaction);
-
- check = MyOperation->setValue(GROUP_ALLOW_INSERT, (char*)&allowInsert);
- CHECK_MINUS_ONE(check, "setValue allowInsert", MyTransaction);
-
- check = MyOperation->setValue(GROUP_ALLOW_DELETE, (char*)&allowDelete);
- CHECK_MINUS_ONE(check, "setValue allowDelete", MyTransaction);
-
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "commit", MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
- return 0;
-}
-
diff --git a/storage/ndb/test/ndbapi/ndb_user_transaction.cpp b/storage/ndb/test/ndbapi/ndb_user_transaction.cpp
deleted file mode 100644
index 39dc48fae02..00000000000
--- a/storage/ndb/test/ndbapi/ndb_user_transaction.cpp
+++ /dev/null
@@ -1,825 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-//#define DEBUG_ON
-
-extern "C" {
-#include "user_transaction.h"
-};
-
-#include "macros.h"
-#include "ndb_schema.hpp"
-#include "ndb_error.hpp"
-
-#include <time.h>
-#include <NdbApi.hpp>
-
-/**
- * Transaction 1 - T1
- *
- * Update location and changed by/time on a subscriber
- *
- * Input:
- * SubscriberNumber,
- * Location,
- * ChangedBy,
- * ChangedTime
- *
- * Output:
- */
-int
-T1(void * obj,
- const SubscriberNumber number,
- const Location new_location,
- const ChangedBy changed_by,
- const ChangedTime changed_time,
- BenchmarkTime * transaction_time){
-
- Ndb * pNDB = (Ndb *) obj;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T1: getNdbOperation", MyTransaction);
-
- check = MyOperation->updateTuple();
- CHECK_MINUS_ONE(check, "T1: updateTuple",
- MyTransaction);
-
- check = MyOperation->equal(SUBSCRIBER_NUMBER,
- number);
- CHECK_MINUS_ONE(check, "T1: equal subscriber",
- MyTransaction);
-
- check = MyOperation->setValue(SUBSCRIBER_LOCATION,
- (char *)&new_location);
- CHECK_MINUS_ONE(check, "T1: setValue location",
- MyTransaction);
-
- check = MyOperation->setValue(SUBSCRIBER_CHANGED_BY,
- changed_by);
- CHECK_MINUS_ONE(check, "T1: setValue changed_by",
- MyTransaction);
-
- check = MyOperation->setValue(SUBSCRIBER_CHANGED_TIME,
- changed_time);
- CHECK_MINUS_ONE(check, "T1: setValue changed_time",
- MyTransaction);
-
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T1: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(transaction_time);
- time_diff(transaction_time, &start);
- return 0;
-}
-
-/**
- * Transaction 2 - T2
- *
- * Read from Subscriber:
- *
- * Input:
- * SubscriberNumber
- *
- * Output:
- * Location
- * Changed by
- * Changed Timestamp
- * Name
- */
-int
-T2(void * obj,
- const SubscriberNumber number,
- Location * readLocation,
- ChangedBy changed_by,
- ChangedTime changed_time,
- SubscriberName subscriberName,
- BenchmarkTime * transaction_time){
-
- Ndb * pNDB = (Ndb *) obj;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T2: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(SUBSCRIBER_NUMBER,
- number);
- CHECK_MINUS_ONE(check, "T2: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_LOCATION,
- (char *)readLocation);
- CHECK_NULL(check2, "T2: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_CHANGED_BY,
- changed_by);
- CHECK_NULL(check2, "T2: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_CHANGED_TIME,
- changed_time);
- CHECK_NULL(check2, "T2: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_NAME,
- subscriberName);
- CHECK_NULL(check2, "T2: getValue name",
- MyTransaction);
-
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T2: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(transaction_time);
- time_diff(transaction_time, &start);
- return 0;
-}
-
-/**
- * Transaction 3 - T3
- *
- * Read session details
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- *
- * Output:
- * BranchExecuted
- * SessionDetails
- * ChangedBy
- * ChangedTime
- * Location
- */
-int
-T3(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- SessionDetails outSessionDetails,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- Ndb * pNDB = (Ndb *) obj;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T3-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T3-1: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T3-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T3-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T3-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T3-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T3-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T3-1: getValue sessions",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T3-2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T3-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(GROUP_ALLOW_READ,
- (char *)&permission);
- CHECK_NULL(check2, "T3-2: getValue allow_read",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-2: NoCommit",
- MyTransaction);
-
- DEBUG3("T3(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == inServerBit)){
-
- DEBUG("reading - ");
-
- /* Operation 3 */
-
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T3-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-3: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T3-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T3-3: equal server id",
- MyTransaction);
-
- check2 = MyOperation->getValue(SESSION_DATA,
- (char *)outSessionDetails);
- CHECK_NULL(check2, "T3-3: getValue session details",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-3: NoCommit",
- MyTransaction);
-
- /* Operation 4 */
-
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T3-4: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T3-4: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T3-4: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T3-4: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(SERVER_READS, (uint32)1);
- CHECK_MINUS_ONE(check, "T3-4: inc value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-4: NoCommit",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- (* outBranchExecuted) = 0;
- }
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T3: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
-
-/**
- * Transaction 4 - T4
- *
- * Create session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * SessionDetails,
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-int
-T4(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- const SessionDetails inSessionDetails,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- DoRollback inDoRollback,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- Ndb * pNDB = (Ndb *) obj;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T4-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- DEBUG3("T4(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- NdbOperation * MyOperation = 0;
-
- MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T4-1: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTupleExclusive();
- CHECK_MINUS_ONE(check, "T4-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T4-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T4-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T4-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T4-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T4-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T4-1: getValue sessions",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T4-2: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T4-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T4-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(GROUP_ALLOW_INSERT,
- (char *)&permission);
- CHECK_NULL(check2, "T4-2: getValue allow_insert",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-2: NoCommit",
- MyTransaction);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == 0)){
-
- DEBUG("inserting - ");
-
- /* Operation 3 */
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T4-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->insertTuple();
- CHECK_MINUS_ONE(check, "T4-3: insertTuple",
- MyTransaction);
-
- check = MyOperation->equal(SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T4-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T4-3: equal server id",
- MyTransaction);
-
- check = MyOperation->setValue(SESSION_DATA,
- (char *)inSessionDetails);
- CHECK_MINUS_ONE(check, "T4-3: setValue session details",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-3: NoCommit",
- MyTransaction);
-
- /* Operation 4 */
- MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T4-4: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T4-4: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(SUBSCRIBER_NUMBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T4-4: equal number",
- MyTransaction);
-
- check = MyOperation->incValue(SUBSCRIBER_SESSIONS,
- (uint32)inServerBit);
- CHECK_MINUS_ONE(check, "T4-4: inc value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-4: NoCommit",
- MyTransaction);
-
- /* Operation 5 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T4-5: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T4-5: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T4-5: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T4-5: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(SERVER_INSERTS, (uint32)1);
- CHECK_MINUS_ONE(check, "T4-5: inc value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-5: NoCommit",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
- DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
- (* outBranchExecuted) = 0;
- }
-
- if(!inDoRollback){
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T4: Commit",
- MyTransaction);
- } else {
- DEBUG("rollback\n");
- check = MyTransaction->execute(Rollback);
- CHECK_MINUS_ONE(check, "T4:Rollback",
- MyTransaction);
-
- }
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
-
-/**
- * Transaction 5 - T5
- *
- * Delete session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-int
-T5(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- DoRollback inDoRollback,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- Ndb * pNDB = (Ndb *) obj;
- NdbConnection * MyTransaction = 0;
- NdbOperation * MyOperation = 0;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T5-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T5-1: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTupleExclusive();
- CHECK_MINUS_ONE(check, "T5-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T5-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T5-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T5-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T5-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T5-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T5-1: getValue sessions",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T5-2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T5-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T5-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(GROUP_ALLOW_DELETE,
- (char *)&permission);
- CHECK_NULL(check2, "T5-2: getValue allow_delete",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-2: NoCommit",
- MyTransaction);
-
- DEBUG3("T5(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == inServerBit)){
-
- DEBUG("deleting - ");
-
- /* Operation 3 */
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T5-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->deleteTuple();
- CHECK_MINUS_ONE(check, "T5-3: deleteTuple",
- MyTransaction);
-
- check = MyOperation->equal(SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T5-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T5-3: equal server id",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-3: NoCommit",
- MyTransaction);
-
- /* Operation 4 */
- MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T5-4: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T5-4: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(SUBSCRIBER_NUMBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T5-4: equal number",
- MyTransaction);
-
- check = MyOperation->subValue(SUBSCRIBER_SESSIONS,
- (uint32)inServerBit);
- CHECK_MINUS_ONE(check, "T5-4: dec value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-4: NoCommit",
- MyTransaction);
-
- /* Operation 5 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T5-5: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T5-5: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T5-5: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T5-5: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(SERVER_DELETES, (uint32)1);
- CHECK_MINUS_ONE(check, "T5-5: inc value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-5: NoCommit",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
- DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
- (* outBranchExecuted) = 0;
- }
-
- if(!inDoRollback){
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T5: Commit",
- MyTransaction);
- } else {
- DEBUG("rollback\n");
- check = MyTransaction->execute(Rollback);
- CHECK_MINUS_ONE(check, "T5:Rollback",
- MyTransaction);
-
- }
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
diff --git a/storage/ndb/test/ndbapi/ndb_user_transaction2.cpp b/storage/ndb/test/ndbapi/ndb_user_transaction2.cpp
deleted file mode 100644
index cc41df4cc6a..00000000000
--- a/storage/ndb/test/ndbapi/ndb_user_transaction2.cpp
+++ /dev/null
@@ -1,825 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-//#define DEBUG_ON
-
-extern "C" {
-#include "user_transaction.h"
-};
-
-#include "macros.h"
-#include "ndb_schema.hpp"
-#include "ndb_error.hpp"
-
-#include <time.h>
-#include <NdbApi.hpp>
-
-/**
- * Transaction 1 - T1
- *
- * Update location and changed by/time on a subscriber
- *
- * Input:
- * SubscriberNumber,
- * Location,
- * ChangedBy,
- * ChangedTime
- *
- * Output:
- */
-int
-T1(void * obj,
- const SubscriberNumber number,
- const Location new_location,
- const ChangedBy changed_by,
- const ChangedTime changed_time,
- BenchmarkTime * transaction_time){
-
- Ndb * pNDB = (Ndb *) obj;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T1: getNdbOperation", MyTransaction);
-
- check = MyOperation->updateTuple();
- CHECK_MINUS_ONE(check, "T1: updateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- number);
- CHECK_MINUS_ONE(check, "T1: equal subscriber",
- MyTransaction);
-
- check = MyOperation->setValue(IND_SUBSCRIBER_LOCATION,
- (char *)&new_location);
- CHECK_MINUS_ONE(check, "T1: setValue location",
- MyTransaction);
-
- check = MyOperation->setValue(IND_SUBSCRIBER_CHANGED_BY,
- changed_by);
- CHECK_MINUS_ONE(check, "T1: setValue changed_by",
- MyTransaction);
-
- check = MyOperation->setValue(IND_SUBSCRIBER_CHANGED_TIME,
- changed_time);
- CHECK_MINUS_ONE(check, "T1: setValue changed_time",
- MyTransaction);
-
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T1: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(transaction_time);
- time_diff(transaction_time, &start);
- return 0;
-}
-
-/**
- * Transaction 2 - T2
- *
- * Read from Subscriber:
- *
- * Input:
- * SubscriberNumber
- *
- * Output:
- * Location
- * Changed by
- * Changed Timestamp
- * Name
- */
-int
-T2(void * obj,
- const SubscriberNumber number,
- Location * readLocation,
- ChangedBy changed_by,
- ChangedTime changed_time,
- SubscriberName subscriberName,
- BenchmarkTime * transaction_time){
-
- Ndb * pNDB = (Ndb *) obj;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T2: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- number);
- CHECK_MINUS_ONE(check, "T2: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)readLocation);
- CHECK_NULL(check2, "T2: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- changed_by);
- CHECK_NULL(check2, "T2: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- changed_time);
- CHECK_NULL(check2, "T2: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_NAME,
- subscriberName);
- CHECK_NULL(check2, "T2: getValue name",
- MyTransaction);
-
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T2: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(transaction_time);
- time_diff(transaction_time, &start);
- return 0;
-}
-
-/**
- * Transaction 3 - T3
- *
- * Read session details
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- *
- * Output:
- * BranchExecuted
- * SessionDetails
- * ChangedBy
- * ChangedTime
- * Location
- */
-int
-T3(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- SessionDetails outSessionDetails,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- Ndb * pNDB = (Ndb *) obj;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T3-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T3-1: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T3-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T3-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T3-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T3-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T3-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T3-1: getValue sessions",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T3-2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T3-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_GROUP_ALLOW_READ,
- (char *)&permission);
- CHECK_NULL(check2, "T3-2: getValue allow_read",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-2: NoCommit",
- MyTransaction);
-
- DEBUG3("T3(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == inServerBit)){
-
- DEBUG("reading - ");
-
- /* Operation 3 */
-
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T3-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-3: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T3-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T3-3: equal server id",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SESSION_DATA,
- (char *)outSessionDetails);
- CHECK_NULL(check2, "T3-3: getValue session details",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-3: NoCommit",
- MyTransaction);
-
- /* Operation 4 */
-
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T3-4: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T3-4: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T3-4: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T3-4: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SERVER_READS, (uint32)1);
- CHECK_MINUS_ONE(check, "T3-4: inc value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-4: NoCommit",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- (* outBranchExecuted) = 0;
- }
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T3: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
-
-/**
- * Transaction 4 - T4
- *
- * Create session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * SessionDetails,
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-int
-T4(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- const SessionDetails inSessionDetails,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- DoRollback inDoRollback,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- Ndb * pNDB = (Ndb *) obj;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T4-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- DEBUG3("T4(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- NdbOperation * MyOperation = 0;
-
- MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T4-1: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTupleExclusive();
- CHECK_MINUS_ONE(check, "T4-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T4-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T4-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T4-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T4-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T4-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T4-1: getValue sessions",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T4-2: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T4-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T4-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_GROUP_ALLOW_INSERT,
- (char *)&permission);
- CHECK_NULL(check2, "T4-2: getValue allow_insert",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-2: NoCommit",
- MyTransaction);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == 0)){
-
- DEBUG("inserting - ");
-
- /* Operation 3 */
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T4-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->insertTuple();
- CHECK_MINUS_ONE(check, "T4-3: insertTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T4-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T4-3: equal server id",
- MyTransaction);
-
- check = MyOperation->setValue(SESSION_DATA,
- (char *)inSessionDetails);
- CHECK_MINUS_ONE(check, "T4-3: setValue session details",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-3: NoCommit",
- MyTransaction);
-
- /* Operation 4 */
- MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T4-4: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T4-4: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T4-4: equal number",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)inServerBit);
- CHECK_MINUS_ONE(check, "T4-4: inc value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-4: NoCommit",
- MyTransaction);
-
- /* Operation 5 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T4-5: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T4-5: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T4-5: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T4-5: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SERVER_INSERTS, (uint32)1);
- CHECK_MINUS_ONE(check, "T4-5: inc value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-5: NoCommit",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
- DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
- (* outBranchExecuted) = 0;
- }
-
- if(!inDoRollback){
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T4: Commit",
- MyTransaction);
- } else {
- DEBUG("rollback\n");
- check = MyTransaction->execute(Rollback);
- CHECK_MINUS_ONE(check, "T4:Rollback",
- MyTransaction);
-
- }
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
-
-/**
- * Transaction 5 - T5
- *
- * Delete session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-int
-T5(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- DoRollback inDoRollback,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- Ndb * pNDB = (Ndb *) obj;
- NdbConnection * MyTransaction = 0;
- NdbOperation * MyOperation = 0;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T5-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T5-1: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTupleExclusive();
- CHECK_MINUS_ONE(check, "T5-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T5-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T5-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T5-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T5-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T5-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T5-1: getValue sessions",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T5-2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T5-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T5-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_GROUP_ALLOW_DELETE,
- (char *)&permission);
- CHECK_NULL(check2, "T5-2: getValue allow_delete",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-2: NoCommit",
- MyTransaction);
-
- DEBUG3("T5(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == inServerBit)){
-
- DEBUG("deleting - ");
-
- /* Operation 3 */
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T5-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->deleteTuple();
- CHECK_MINUS_ONE(check, "T5-3: deleteTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T5-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T5-3: equal server id",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-3: NoCommit",
- MyTransaction);
-
- /* Operation 4 */
- MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T5-4: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T5-4: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T5-4: equal number",
- MyTransaction);
-
- check = MyOperation->subValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)inServerBit);
- CHECK_MINUS_ONE(check, "T5-4: dec value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-4: NoCommit",
- MyTransaction);
-
- /* Operation 5 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T5-5: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T5-5: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T5-5: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T5-5: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SERVER_DELETES, (uint32)1);
- CHECK_MINUS_ONE(check, "T5-5: inc value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-5: NoCommit",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
- DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
- (* outBranchExecuted) = 0;
- }
-
- if(!inDoRollback){
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T5: Commit",
- MyTransaction);
- } else {
- DEBUG("rollback\n");
- check = MyTransaction->execute(Rollback);
- CHECK_MINUS_ONE(check, "T5:Rollback",
- MyTransaction);
-
- }
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
diff --git a/storage/ndb/test/ndbapi/ndb_user_transaction3.cpp b/storage/ndb/test/ndbapi/ndb_user_transaction3.cpp
deleted file mode 100644
index eb5295eea12..00000000000
--- a/storage/ndb/test/ndbapi/ndb_user_transaction3.cpp
+++ /dev/null
@@ -1,793 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-//#define DEBUG_ON
-
-extern "C" {
-#include "user_transaction.h"
-};
-
-#include "macros.h"
-#include "ndb_schema.hpp"
-#include "ndb_error.hpp"
-
-#include <time.h>
-#include <NdbApi.hpp>
-
-/**
- * Transaction 1 - T1
- *
- * Update location and changed by/time on a subscriber
- *
- * Input:
- * SubscriberNumber,
- * Location,
- * ChangedBy,
- * ChangedTime
- *
- * Output:
- */
-int
-T1(void * obj,
- const SubscriberNumber number,
- const Location new_location,
- const ChangedBy changed_by,
- const ChangedTime changed_time,
- BenchmarkTime * transaction_time){
-
- Ndb * pNDB = (Ndb *) obj;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T1: getNdbOperation", MyTransaction);
-
- check = MyOperation->updateTuple();
- CHECK_MINUS_ONE(check, "T1: updateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- number);
- CHECK_MINUS_ONE(check, "T1: equal subscriber",
- MyTransaction);
-
- check = MyOperation->setValue(IND_SUBSCRIBER_LOCATION,
- (char *)&new_location);
- CHECK_MINUS_ONE(check, "T1: setValue location",
- MyTransaction);
-
- check = MyOperation->setValue(IND_SUBSCRIBER_CHANGED_BY,
- changed_by);
- CHECK_MINUS_ONE(check, "T1: setValue changed_by",
- MyTransaction);
-
- check = MyOperation->setValue(IND_SUBSCRIBER_CHANGED_TIME,
- changed_time);
- CHECK_MINUS_ONE(check, "T1: setValue changed_time",
- MyTransaction);
-
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T1: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(transaction_time);
- time_diff(transaction_time, &start);
- return 0;
-}
-
-/**
- * Transaction 2 - T2
- *
- * Read from Subscriber:
- *
- * Input:
- * SubscriberNumber
- *
- * Output:
- * Location
- * Changed by
- * Changed Timestamp
- * Name
- */
-int
-T2(void * obj,
- const SubscriberNumber number,
- Location * readLocation,
- ChangedBy changed_by,
- ChangedTime changed_time,
- SubscriberName subscriberName,
- BenchmarkTime * transaction_time){
-
- Ndb * pNDB = (Ndb *) obj;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T2: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- number);
- CHECK_MINUS_ONE(check, "T2: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)readLocation);
- CHECK_NULL(check2, "T2: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- changed_by);
- CHECK_NULL(check2, "T2: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- changed_time);
- CHECK_NULL(check2, "T2: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_NAME,
- subscriberName);
- CHECK_NULL(check2, "T2: getValue name",
- MyTransaction);
-
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T2: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(transaction_time);
- time_diff(transaction_time, &start);
- return 0;
-}
-
-/**
- * Transaction 3 - T3
- *
- * Read session details
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- *
- * Output:
- * BranchExecuted
- * SessionDetails
- * ChangedBy
- * ChangedTime
- * Location
- */
-int
-T3(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- SessionDetails outSessionDetails,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- Ndb * pNDB = (Ndb *) obj;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T3-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T3-1: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T3-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T3-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T3-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T3-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T3-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T3-1: getValue sessions",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T3-2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T3-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_GROUP_ALLOW_READ,
- (char *)&permission);
- CHECK_NULL(check2, "T3-2: getValue allow_read",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-2: NoCommit",
- MyTransaction);
-
- DEBUG3("T3(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == inServerBit)){
-
- DEBUG("reading - ");
-
- /* Operation 3 */
-
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T3-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-3: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T3-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T3-3: equal server id",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SESSION_DATA,
- (char *)outSessionDetails);
- CHECK_NULL(check2, "T3-3: getValue session details",
- MyTransaction);
-
- /* Operation 4 */
-
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T3-4: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T3-4: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T3-4: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T3-4: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SERVER_READS, (uint32)1);
- CHECK_MINUS_ONE(check, "T3-4: inc value",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- (* outBranchExecuted) = 0;
- }
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T3: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
-
-/**
- * Transaction 4 - T4
- *
- * Create session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * SessionDetails,
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-int
-T4(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- const SessionDetails inSessionDetails,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- DoRollback inDoRollback,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- Ndb * pNDB = (Ndb *) obj;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T4-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- DEBUG3("T4(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- NdbOperation * MyOperation = 0;
-
- MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T4-1: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTupleExclusive();
- CHECK_MINUS_ONE(check, "T4-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T4-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T4-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T4-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T4-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T4-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T4-1: getValue sessions",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T4-2: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T4-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T4-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_GROUP_ALLOW_INSERT,
- (char *)&permission);
- CHECK_NULL(check2, "T4-2: getValue allow_insert",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-2: NoCommit",
- MyTransaction);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == 0)){
-
- DEBUG("inserting - ");
-
- /* Operation 3 */
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T4-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->insertTuple();
- CHECK_MINUS_ONE(check, "T4-3: insertTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T4-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T4-3: equal server id",
- MyTransaction);
-
- check = MyOperation->setValue(SESSION_DATA,
- (char *)inSessionDetails);
- CHECK_MINUS_ONE(check, "T4-3: setValue session details",
- MyTransaction);
-
- /* Operation 4 */
- MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T4-4: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T4-4: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T4-4: equal number",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)inServerBit);
- CHECK_MINUS_ONE(check, "T4-4: inc value",
- MyTransaction);
-
- /* Operation 5 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T4-5: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T4-5: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T4-5: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T4-5: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SERVER_INSERTS, (uint32)1);
- CHECK_MINUS_ONE(check, "T4-5: inc value",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
- DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
- (* outBranchExecuted) = 0;
- }
-
- if(!inDoRollback){
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T4: Commit",
- MyTransaction);
- } else {
- DEBUG("rollback\n");
- check = MyTransaction->execute(Rollback);
- CHECK_MINUS_ONE(check, "T4:Rollback",
- MyTransaction);
-
- }
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
-
-/**
- * Transaction 5 - T5
- *
- * Delete session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-int
-T5(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- DoRollback inDoRollback,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- Ndb * pNDB = (Ndb *) obj;
- NdbConnection * MyTransaction = 0;
- NdbOperation * MyOperation = 0;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T5-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T5-1: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTupleExclusive();
- CHECK_MINUS_ONE(check, "T5-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T5-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T5-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T5-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T5-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T5-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T5-1: getValue sessions",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T5-2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T5-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T5-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_GROUP_ALLOW_DELETE,
- (char *)&permission);
- CHECK_NULL(check2, "T5-2: getValue allow_delete",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-2: NoCommit",
- MyTransaction);
-
- DEBUG3("T5(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == inServerBit)){
-
- DEBUG("deleting - ");
-
- /* Operation 3 */
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T5-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->deleteTuple();
- CHECK_MINUS_ONE(check, "T5-3: deleteTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T5-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T5-3: equal server id",
- MyTransaction);
-
- /* Operation 4 */
- MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T5-4: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T5-4: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T5-4: equal number",
- MyTransaction);
-
- check = MyOperation->subValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)inServerBit);
- CHECK_MINUS_ONE(check, "T5-4: dec value",
- MyTransaction);
-
- /* Operation 5 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T5-5: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T5-5: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T5-5: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T5-5: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SERVER_DELETES, (uint32)1);
- CHECK_MINUS_ONE(check, "T5-5: inc value",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
- DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
- (* outBranchExecuted) = 0;
- }
-
- if(!inDoRollback){
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T5: Commit",
- MyTransaction);
- } else {
- DEBUG("rollback\n");
- check = MyTransaction->execute(Rollback);
- CHECK_MINUS_ONE(check, "T5:Rollback",
- MyTransaction);
-
- }
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
diff --git a/storage/ndb/test/ndbapi/ndb_user_transaction4.cpp b/storage/ndb/test/ndbapi/ndb_user_transaction4.cpp
deleted file mode 100644
index 7eeb5660cdf..00000000000
--- a/storage/ndb/test/ndbapi/ndb_user_transaction4.cpp
+++ /dev/null
@@ -1,770 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-//#define DEBUG_ON
-
-extern "C" {
-#include "user_transaction.h"
-};
-
-#include "macros.h"
-#include "ndb_schema.hpp"
-#include "ndb_error.hpp"
-
-#include <time.h>
-#include <NdbApi.hpp>
-
-/**
- * Transaction 1 - T1
- *
- * Update location and changed by/time on a subscriber
- *
- * Input:
- * SubscriberNumber,
- * Location,
- * ChangedBy,
- * ChangedTime
- *
- * Output:
- */
-int
-T1(void * obj,
- const SubscriberNumber number,
- const Location new_location,
- const ChangedBy changed_by,
- const ChangedTime changed_time,
- BenchmarkTime * transaction_time){
-
- Ndb * pNDB = (Ndb *) obj;
-
- DEBUG2("T1(%.*s):\n", SUBSCRIBER_NUMBER_LENGTH, number);
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T1-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T1: getNdbOperation", MyTransaction);
-
- check = MyOperation->updateTuple();
- CHECK_MINUS_ONE(check, "T1: updateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- number);
- CHECK_MINUS_ONE(check, "T1: equal subscriber",
- MyTransaction);
-
- check = MyOperation->setValue(IND_SUBSCRIBER_LOCATION,
- (char *)&new_location);
- CHECK_MINUS_ONE(check, "T1: setValue location",
- MyTransaction);
-
- check = MyOperation->setValue(IND_SUBSCRIBER_CHANGED_BY,
- changed_by);
- CHECK_MINUS_ONE(check, "T1: setValue changed_by",
- MyTransaction);
-
- check = MyOperation->setValue(IND_SUBSCRIBER_CHANGED_TIME,
- changed_time);
- CHECK_MINUS_ONE(check, "T1: setValue changed_time",
- MyTransaction);
-
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T1: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(transaction_time);
- time_diff(transaction_time, &start);
- return 0;
-}
-
-/**
- * Transaction 2 - T2
- *
- * Read from Subscriber:
- *
- * Input:
- * SubscriberNumber
- *
- * Output:
- * Location
- * Changed by
- * Changed Timestamp
- * Name
- */
-int
-T2(void * obj,
- const SubscriberNumber number,
- Location * readLocation,
- ChangedBy changed_by,
- ChangedTime changed_time,
- SubscriberName subscriberName,
- BenchmarkTime * transaction_time){
-
- Ndb * pNDB = (Ndb *) obj;
-
- DEBUG2("T2(%.*s):\n", SUBSCRIBER_NUMBER_LENGTH, number);
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T2-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- number);
- CHECK_MINUS_ONE(check, "T2: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)readLocation);
- CHECK_NULL(check2, "T2: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- changed_by);
- CHECK_NULL(check2, "T2: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- changed_time);
- CHECK_NULL(check2, "T2: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_NAME,
- subscriberName);
- CHECK_NULL(check2, "T2: getValue name",
- MyTransaction);
-
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T2: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(transaction_time);
- time_diff(transaction_time, &start);
- return 0;
-}
-
-/**
- * Transaction 3 - T3
- *
- * Read session details
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- *
- * Output:
- * BranchExecuted
- * SessionDetails
- * ChangedBy
- * ChangedTime
- * Location
- */
-int
-T3(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- SessionDetails outSessionDetails,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- DEBUG3("T3(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- Ndb * pNDB = (Ndb *) obj;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T3-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T3-1: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T3-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T3-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T3-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T3-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T3-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T3-1: getValue sessions",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T3-2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T3-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_GROUP_ALLOW_READ,
- (char *)&permission);
- CHECK_NULL(check2, "T3-2: getValue allow_read",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-2: NoCommit",
- MyTransaction);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == inServerBit)){
-
- DEBUG("reading - ");
-
- /* Operation 3 */
-
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T3-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-3: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T3-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T3-3: equal server id",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SESSION_DATA,
- (char *)outSessionDetails);
- CHECK_NULL(check2, "T3-3: getValue session details",
- MyTransaction);
-
- /* Operation 4 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T3-4: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T3-4: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T3-4: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T3-4: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SERVER_READS, (uint32)1);
- CHECK_MINUS_ONE(check, "T3-4: inc value",
- MyTransaction);
- (* outBranchExecuted) = 1;
- } else {
- (* outBranchExecuted) = 0;
- }
- DEBUG("commit...");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T3: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- DEBUG("done\n");
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
-
-/**
- * Transaction 4 - T4
- *
- * Create session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * SessionDetails,
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-int
-T4(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- const SessionDetails inSessionDetails,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- DoRollback inDoRollback,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- DEBUG3("T4(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- Ndb * pNDB = (Ndb *) obj;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T4-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T4-1: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T4-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T4-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T4-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T4-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T4-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T4-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T4-1: getValue sessions",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)inServerBit);
- CHECK_MINUS_ONE(check, "T4-4: inc value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T4-2: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T4-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T4-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_GROUP_ALLOW_INSERT,
- (char *)&permission);
- CHECK_NULL(check2, "T4-2: getValue allow_insert",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-2: NoCommit",
- MyTransaction);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == 0)){
-
- DEBUG("inserting - ");
-
- /* Operation 3 */
-
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T4-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->insertTuple();
- CHECK_MINUS_ONE(check, "T4-3: insertTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T4-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T4-3: equal server id",
- MyTransaction);
-
- check = MyOperation->setValue(SESSION_DATA,
- (char *)inSessionDetails);
- CHECK_MINUS_ONE(check, "T4-3: setValue session details",
- MyTransaction);
-
- /* Operation 4 */
-
- /* Operation 5 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T4-5: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T4-5: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T4-5: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T4-5: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SERVER_INSERTS, (uint32)1);
- CHECK_MINUS_ONE(check, "T4-5: inc value",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
- DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
- (* outBranchExecuted) = 0;
- }
-
- if(!inDoRollback && (* outBranchExecuted)){
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T4: Commit",
- MyTransaction);
- } else {
- DEBUG("rollback\n");
- check = MyTransaction->execute(Rollback);
- CHECK_MINUS_ONE(check, "T4:Rollback",
- MyTransaction);
-
- }
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
-
-/**
- * Transaction 5 - T5
- *
- * Delete session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-int
-T5(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- DoRollback inDoRollback,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- DEBUG3("T5(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- Ndb * pNDB = (Ndb *) obj;
- NdbConnection * MyTransaction = 0;
- NdbOperation * MyOperation = 0;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T5-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T5-1: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T5-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T5-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T5-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T5-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T5-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T5-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T5-1: getValue sessions",
- MyTransaction);
-
- check = MyOperation->subValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)inServerBit);
- CHECK_MINUS_ONE(check, "T5-4: dec value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T5-2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T5-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T5-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_GROUP_ALLOW_DELETE,
- (char *)&permission);
- CHECK_NULL(check2, "T5-2: getValue allow_delete",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-2: NoCommit",
- MyTransaction);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == inServerBit)){
-
- DEBUG("deleting - ");
-
- /* Operation 3 */
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T5-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->deleteTuple();
- CHECK_MINUS_ONE(check, "T5-3: deleteTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T5-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T5-3: equal server id",
- MyTransaction);
-
- /* Operation 4 */
-
- /* Operation 5 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T5-5: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T5-5: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T5-5: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T5-5: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SERVER_DELETES, (uint32)1);
- CHECK_MINUS_ONE(check, "T5-5: inc value",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
- DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
- (* outBranchExecuted) = 0;
- }
-
- if(!inDoRollback && (* outBranchExecuted)){
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T5: Commit",
- MyTransaction);
- } else {
- DEBUG("rollback\n");
- check = MyTransaction->execute(Rollback);
- CHECK_MINUS_ONE(check, "T5:Rollback",
- MyTransaction);
-
- }
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
diff --git a/storage/ndb/test/ndbapi/ndb_user_transaction5.cpp b/storage/ndb/test/ndbapi/ndb_user_transaction5.cpp
deleted file mode 100644
index 4a1bd344ad6..00000000000
--- a/storage/ndb/test/ndbapi/ndb_user_transaction5.cpp
+++ /dev/null
@@ -1,769 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-//#define DEBUG_ON
-
-extern "C" {
-#include "user_transaction.h"
-};
-
-#include "macros.h"
-#include "ndb_schema.hpp"
-#include "ndb_error.hpp"
-
-#include <time.h>
-#include <NdbApi.hpp>
-
-/**
- * Transaction 1 - T1
- *
- * Update location and changed by/time on a subscriber
- *
- * Input:
- * SubscriberNumber,
- * Location,
- * ChangedBy,
- * ChangedTime
- *
- * Output:
- */
-int
-T1(void * obj,
- const SubscriberNumber number,
- const Location new_location,
- const ChangedBy changed_by,
- const ChangedTime changed_time,
- BenchmarkTime * transaction_time){
-
- Ndb * pNDB = (Ndb *) obj;
-
- DEBUG2("T1(%.*s):\n", SUBSCRIBER_NUMBER_LENGTH, number);
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T1-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T1: getNdbOperation", MyTransaction);
-
- check = MyOperation->updateTuple();
- CHECK_MINUS_ONE(check, "T1: updateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- number);
- CHECK_MINUS_ONE(check, "T1: equal subscriber",
- MyTransaction);
-
- check = MyOperation->setValue(IND_SUBSCRIBER_LOCATION,
- (char *)&new_location);
- CHECK_MINUS_ONE(check, "T1: setValue location",
- MyTransaction);
-
- check = MyOperation->setValue(IND_SUBSCRIBER_CHANGED_BY,
- changed_by);
- CHECK_MINUS_ONE(check, "T1: setValue changed_by",
- MyTransaction);
-
- check = MyOperation->setValue(IND_SUBSCRIBER_CHANGED_TIME,
- changed_time);
- CHECK_MINUS_ONE(check, "T1: setValue changed_time",
- MyTransaction);
-
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T1: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(transaction_time);
- time_diff(transaction_time, &start);
- return 0;
-}
-
-/**
- * Transaction 2 - T2
- *
- * Read from Subscriber:
- *
- * Input:
- * SubscriberNumber
- *
- * Output:
- * Location
- * Changed by
- * Changed Timestamp
- * Name
- */
-int
-T2(void * obj,
- const SubscriberNumber number,
- Location * readLocation,
- ChangedBy changed_by,
- ChangedTime changed_time,
- SubscriberName subscriberName,
- BenchmarkTime * transaction_time){
-
- Ndb * pNDB = (Ndb *) obj;
-
- DEBUG2("T2(%.*s):\n", SUBSCRIBER_NUMBER_LENGTH, number);
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T2-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- number);
- CHECK_MINUS_ONE(check, "T2: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)readLocation);
- CHECK_NULL(check2, "T2: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- changed_by);
- CHECK_NULL(check2, "T2: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- changed_time);
- CHECK_NULL(check2, "T2: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_NAME,
- subscriberName);
- CHECK_NULL(check2, "T2: getValue name",
- MyTransaction);
-
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T2: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(transaction_time);
- time_diff(transaction_time, &start);
- return 0;
-}
-
-/**
- * Transaction 3 - T3
- *
- * Read session details
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- *
- * Output:
- * BranchExecuted
- * SessionDetails
- * ChangedBy
- * ChangedTime
- * Location
- */
-int
-T3(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- SessionDetails outSessionDetails,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- Ndb * pNDB = (Ndb *) obj;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T3-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T3-1: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T3-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T3-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T3-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T3-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T3-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T3-1: getValue sessions",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T3-2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T3-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T3-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_GROUP_ALLOW_READ,
- (char *)&permission);
- CHECK_NULL(check2, "T3-2: getValue allow_read",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-2: NoCommit",
- MyTransaction);
-
- DEBUG3("T3(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == inServerBit)){
-
- DEBUG("reading - ");
-
- /* Operation 3 */
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T3-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->simpleRead();
- CHECK_MINUS_ONE(check, "T3-3: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T3-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T3-3: equal server id",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SESSION_DATA,
- (char *)outSessionDetails);
- CHECK_NULL(check2, "T3-3: getValue session details",
- MyTransaction);
-
- /* Operation 4 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T3-4: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T3-4: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T3-4: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T3-4: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SERVER_READS, (uint32)1);
- CHECK_MINUS_ONE(check, "T3-4: inc value",
- MyTransaction);
- (* outBranchExecuted) = 1;
- } else {
- (* outBranchExecuted) = 0;
- }
- DEBUG("commit...");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T3: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- DEBUG("done\n");
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
-
-/**
- * Transaction 4 - T4
- *
- * Create session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * SessionDetails,
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-int
-T4(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- const SessionDetails inSessionDetails,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- DoRollback inDoRollback,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- Ndb * pNDB = (Ndb *) obj;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T4-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T4-1: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T4-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T4-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T4-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T4-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T4-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T4-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T4-1: getValue sessions",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)inServerBit);
- CHECK_MINUS_ONE(check, "T4-4: inc value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T4-2: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T4-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T4-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_GROUP_ALLOW_INSERT,
- (char *)&permission);
- CHECK_NULL(check2, "T4-2: getValue allow_insert",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-2: NoCommit",
- MyTransaction);
-
- DEBUG3("T4(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == 0)){
-
- DEBUG("inserting - ");
-
- /* Operation 3 */
-
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T4-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->insertTuple();
- CHECK_MINUS_ONE(check, "T4-3: insertTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T4-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T4-3: equal server id",
- MyTransaction);
-
- check = MyOperation->setValue(SESSION_DATA,
- (char *)inSessionDetails);
- CHECK_MINUS_ONE(check, "T4-3: setValue session details",
- MyTransaction);
-
- /* Operation 4 */
-
- /* Operation 5 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T4-5: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T4-5: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T4-5: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T4-5: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SERVER_INSERTS, (uint32)1);
- CHECK_MINUS_ONE(check, "T4-5: inc value",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
- DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
- (* outBranchExecuted) = 0;
- }
-
- if(!inDoRollback && (* outBranchExecuted)){
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T4: Commit",
- MyTransaction);
- } else {
- DEBUG("rollback\n");
- check = MyTransaction->execute(Rollback);
- CHECK_MINUS_ONE(check, "T4:Rollback",
- MyTransaction);
-
- }
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
-
-/**
- * Transaction 5 - T5
- *
- * Delete session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-int
-T5(void * obj,
- const SubscriberNumber inNumber,
- const SubscriberSuffix inSuffix,
- const ServerId inServerId,
- const ServerBit inServerBit,
- ChangedBy outChangedBy,
- ChangedTime outChangedTime,
- Location * outLocation,
- DoRollback inDoRollback,
- BranchExecuted * outBranchExecuted,
- BenchmarkTime * outTransactionTime){
-
- Ndb * pNDB = (Ndb *) obj;
- NdbConnection * MyTransaction = 0;
- NdbOperation * MyOperation = 0;
-
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
-
- BenchmarkTime start;
- get_time(&start);
-
- int check;
- NdbRecAttr * check2;
-
- MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T5-1: startTranscation", pNDB->getNdbErrorString(), 0);
-
- MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T5-1: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T5-1: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- CHECK_MINUS_ONE(check, "T5-1: equal subscriber",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)outLocation);
- CHECK_NULL(check2, "T5-1: getValue location",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- CHECK_NULL(check2, "T5-1: getValue changed_by",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- CHECK_NULL(check2, "T5-1: getValue changed_time",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- CHECK_NULL(check2, "T5-1: getValue group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- CHECK_NULL(check2, "T5-1: getValue sessions",
- MyTransaction);
-
- check = MyOperation->subValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)inServerBit);
- CHECK_MINUS_ONE(check, "T5-4: dec value",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T5-2: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->readTuple();
- CHECK_MINUS_ONE(check, "T5-2: readTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- CHECK_MINUS_ONE(check, "T5-2: equal group",
- MyTransaction);
-
- check2 = MyOperation->getValue(IND_GROUP_ALLOW_DELETE,
- (char *)&permission);
- CHECK_NULL(check2, "T5-2: getValue allow_delete",
- MyTransaction);
-
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-2: NoCommit",
- MyTransaction);
-
- DEBUG3("T5(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == inServerBit)){
-
- DEBUG("deleting - ");
-
- /* Operation 3 */
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T5-3: getNdbOperation",
- MyTransaction);
-
- check = MyOperation->deleteTuple();
- CHECK_MINUS_ONE(check, "T5-3: deleteTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- CHECK_MINUS_ONE(check, "T5-3: equal number",
- MyTransaction);
-
- check = MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T5-3: equal server id",
- MyTransaction);
-
- /* Operation 4 */
-
- /* Operation 5 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T5-5: getNdbOperation",
- MyTransaction);
-
-
- check = MyOperation->interpretedUpdateTuple();
- CHECK_MINUS_ONE(check, "T5-5: interpretedUpdateTuple",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- CHECK_MINUS_ONE(check, "T5-5: equal serverId",
- MyTransaction);
-
- check = MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- CHECK_MINUS_ONE(check, "T5-5: equal suffix",
- MyTransaction);
-
- check = MyOperation->incValue(IND_SERVER_DELETES, (uint32)1);
- CHECK_MINUS_ONE(check, "T5-5: inc value",
- MyTransaction);
-
- (* outBranchExecuted) = 1;
- } else {
- DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
- DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
- (* outBranchExecuted) = 0;
- }
-
- if(!inDoRollback && (* outBranchExecuted)){
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T5: Commit",
- MyTransaction);
- } else {
- DEBUG("rollback\n");
- check = MyTransaction->execute(Rollback);
- CHECK_MINUS_ONE(check, "T5:Rollback",
- MyTransaction);
-
- }
-
- pNDB->closeTransaction(MyTransaction);
-
- get_time(outTransactionTime);
- time_diff(outTransactionTime, &start);
- return 0;
-}
-
diff --git a/storage/ndb/test/ndbapi/ndb_user_transaction6.cpp b/storage/ndb/test/ndbapi/ndb_user_transaction6.cpp
deleted file mode 100644
index 54e7d1300d6..00000000000
--- a/storage/ndb/test/ndbapi/ndb_user_transaction6.cpp
+++ /dev/null
@@ -1,561 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-//#define DEBUG_ON
-
-#include <string.h>
-#include "userHandle.h"
-#include "userInterface.h"
-
-#include "macros.h"
-#include "ndb_schema.hpp"
-#include "ndb_error.hpp"
-
-#include <NdbApi.hpp>
-
-
-void
-userCheckpoint(UserHandle *uh){
-}
-
-inline
-NdbConnection *
-startTransaction(Ndb * pNDB, ServerId inServerId, const SubscriberNumber inNumber){
-
- const int keyDataLenBytes = sizeof(ServerId)+SUBSCRIBER_NUMBER_LENGTH;
- const int keyDataLen_64Words = keyDataLenBytes >> 3;
-
- Uint64 keyDataBuf[keyDataLen_64Words+1]; // The "+1" is for rounding...
-
- char * keyDataBuf_charP = (char *)&keyDataBuf[0];
- Uint32 * keyDataBuf_wo32P = (Uint32 *)&keyDataBuf[0];
-
- // Server Id comes first
- keyDataBuf_wo32P[0] = inServerId;
- // Then subscriber number
- memcpy(&keyDataBuf_charP[sizeof(ServerId)], inNumber, SUBSCRIBER_NUMBER_LENGTH);
-
- return pNDB->startTransaction(0, keyDataBuf_charP, keyDataLenBytes);
-}
-
-/**
- * Transaction 1 - T1
- *
- * Update location and changed by/time on a subscriber
- *
- * Input:
- * SubscriberNumber,
- * Location,
- * ChangedBy,
- * ChangedTime
- *
- * Output:
- */
-void
-userTransaction_T1(UserHandle * uh,
- SubscriberNumber number,
- Location new_location,
- ChangedBy changed_by,
- ChangedTime changed_time){
- Ndb * pNDB = uh->pNDB;
-
- DEBUG2("T1(%.*s):\n", SUBSCRIBER_NUMBER_LENGTH, number);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction != NULL) {
- NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- if (MyOperation != NULL) {
- MyOperation->updateTuple();
- MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- number);
- MyOperation->setValue(IND_SUBSCRIBER_LOCATION,
- (char *)&new_location);
- MyOperation->setValue(IND_SUBSCRIBER_CHANGED_BY,
- changed_by);
- MyOperation->setValue(IND_SUBSCRIBER_CHANGED_TIME,
- changed_time);
- check = MyTransaction->execute( Commit );
- if (check != -1) {
- pNDB->closeTransaction(MyTransaction);
- return;
- } else {
- CHECK_MINUS_ONE(check, "T1: Commit",
- MyTransaction);
- }//if
- } else {
- CHECK_NULL(MyOperation, "T1: getNdbOperation", MyTransaction);
- }//if
- } else {
- error_handler("T1-1: startTranscation", pNDB->getNdbErrorString(), pNDB->getNdbError());
- }//if
-}
-
-/**
- * Transaction 2 - T2
- *
- * Read from Subscriber:
- *
- * Input:
- * SubscriberNumber
- *
- * Output:
- * Location
- * Changed by
- * Changed Timestamp
- * Name
- */
-void
-userTransaction_T2(UserHandle * uh,
- SubscriberNumber number,
- Location * readLocation,
- ChangedBy changed_by,
- ChangedTime changed_time,
- SubscriberName subscriberName){
- Ndb * pNDB = uh->pNDB;
-
- DEBUG2("T2(%.*s):\n", SUBSCRIBER_NUMBER_LENGTH, number);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T2-1: startTransaction", pNDB->getNdbErrorString(), pNDB->getNdbError());
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T2: getNdbOperation",
- MyTransaction);
-
- MyOperation->readTuple();
- MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- number);
- MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)readLocation);
- MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- changed_by);
- MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- changed_time);
- MyOperation->getValue(IND_SUBSCRIBER_NAME,
- subscriberName);
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T2: Commit",
- MyTransaction);
- pNDB->closeTransaction(MyTransaction);
-}
-
-/**
- * Transaction 3 - T3
- *
- * Read session details
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- *
- * Output:
- * BranchExecuted
- * SessionDetails
- * ChangedBy
- * ChangedTime
- * Location
- */
-void
-userTransaction_T3(UserHandle * uh,
- SubscriberNumber inNumber,
- ServerId inServerId,
- ServerBit inServerBit,
- SessionDetails outSessionDetails,
- BranchExecuted * outBranchExecuted){
- Ndb * pNDB = uh->pNDB;
-
- char outChangedBy [sizeof(ChangedBy) +(4-(sizeof(ChangedBy) & 3))];
- char outChangedTime [sizeof(ChangedTime)+(4-(sizeof(ChangedTime) & 3))];
- Location outLocation;
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
- SubscriberSuffix inSuffix;
-
- DEBUG3("T3(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = startTransaction(pNDB, inServerId, inNumber);
- if (MyTransaction == NULL)
- error_handler("T3-1: startTranscation", pNDB->getNdbErrorString(), pNDB->getNdbError());
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T3-1: getNdbOperation",
- MyTransaction);
-
- MyOperation->readTuple();
- MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)&outLocation);
- MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-1: NoCommit",
- MyTransaction);
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T3-2: getNdbOperation",
- MyTransaction);
-
-
- MyOperation->readTuple();
- MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- MyOperation->getValue(IND_GROUP_ALLOW_READ,
- (char *)&permission);
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T3-2: NoCommit",
- MyTransaction);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == inServerBit)){
-
- memcpy(inSuffix,
- &inNumber[SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH], SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
- DEBUG2("reading(%.*s) - ", SUBSCRIBER_NUMBER_SUFFIX_LENGTH, inSuffix);
-
- /* Operation 3 */
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T3-3: getNdbOperation",
- MyTransaction);
-
- MyOperation->simpleRead();
-
- MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- MyOperation->getValue(IND_SESSION_DATA,
- (char *)outSessionDetails);
- /* Operation 4 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T3-4: getNdbOperation",
- MyTransaction);
-
- MyOperation->interpretedUpdateTuple();
- MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- MyOperation->incValue(IND_SERVER_READS, (uint32)1);
- (* outBranchExecuted) = 1;
- } else {
- (* outBranchExecuted) = 0;
- }
- DEBUG("commit...");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T3: Commit",
- MyTransaction);
-
- pNDB->closeTransaction(MyTransaction);
-
- DEBUG("done\n");
-}
-
-
-/**
- * Transaction 4 - T4
- *
- * Create session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * SessionDetails,
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-void
-userTransaction_T4(UserHandle * uh,
- SubscriberNumber inNumber,
- ServerId inServerId,
- ServerBit inServerBit,
- SessionDetails inSessionDetails,
- DoRollback inDoRollback,
- BranchExecuted * outBranchExecuted){
-
- Ndb * pNDB = uh->pNDB;
-
- char outChangedBy [sizeof(ChangedBy) +(4-(sizeof(ChangedBy) & 3))];
- char outChangedTime [sizeof(ChangedTime)+(4-(sizeof(ChangedTime) & 3))];
- Location outLocation;
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
- SubscriberSuffix inSuffix;
-
- DEBUG3("T4(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- int check;
- NdbRecAttr * check2;
-
- NdbConnection * MyTransaction = startTransaction(pNDB, inServerId, inNumber);
- if (MyTransaction == NULL)
- error_handler("T4-1: startTranscation", pNDB->getNdbErrorString(), pNDB->getNdbError());
-
- NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T4-1: getNdbOperation",
- MyTransaction);
-
- MyOperation->interpretedUpdateTuple();
- MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)&outLocation);
- MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- outChangedBy);
- MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- outChangedTime);
- MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- MyOperation->incValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)inServerBit);
- check = MyTransaction->execute( NoCommit );
-
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T4-2: getNdbOperation",
- MyTransaction);
-
- MyOperation->readTuple();
- MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- MyOperation->getValue(IND_GROUP_ALLOW_INSERT,
- (char *)&permission);
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T4-2: NoCommit",
- MyTransaction);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == 0)){
-
- memcpy(inSuffix,
- &inNumber[SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH], SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
-
- DEBUG2("inserting(%.*s) - ", SUBSCRIBER_NUMBER_SUFFIX_LENGTH, inSuffix);
-
- /* Operation 3 */
-
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T4-3: getNdbOperation",
- MyTransaction);
-
- MyOperation->insertTuple();
- MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- MyOperation->setValue(SESSION_DATA,
- (char *)inSessionDetails);
- /* Operation 4 */
-
- /* Operation 5 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T4-5: getNdbOperation",
- MyTransaction);
-
- MyOperation->interpretedUpdateTuple();
- MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- MyOperation->incValue(IND_SERVER_INSERTS, (uint32)1);
- (* outBranchExecuted) = 1;
- } else {
- (* outBranchExecuted) = 0;
- DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
- DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
- }
-
- if(!inDoRollback && (* outBranchExecuted)){
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T4: Commit",
- MyTransaction);
- } else {
- DEBUG("rollback\n");
- check = MyTransaction->execute(Rollback);
- CHECK_MINUS_ONE(check, "T4:Rollback",
- MyTransaction);
-
- }
-
- pNDB->closeTransaction(MyTransaction);
-}
-
-
-/**
- * Transaction 5 - T5
- *
- * Delete session
- *
- * Input:
- * SubscriberNumber
- * ServerId
- * ServerBit
- * DoRollback
- * Output:
- * ChangedBy
- * ChangedTime
- * Location
- * BranchExecuted
- */
-void
-userTransaction_T5(UserHandle * uh,
- SubscriberNumber inNumber,
- ServerId inServerId,
- ServerBit inServerBit,
- DoRollback inDoRollback,
- BranchExecuted * outBranchExecuted){
- Ndb * pNDB = uh->pNDB;
-
- DEBUG3("T5(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
-
- NdbConnection * MyTransaction = 0;
- NdbOperation * MyOperation = 0;
-
- char outChangedBy [sizeof(ChangedBy) +(4-(sizeof(ChangedBy) & 3))];
- char outChangedTime [sizeof(ChangedTime)+(4-(sizeof(ChangedTime) & 3))];
- Location outLocation;
- GroupId groupId;
- ActiveSessions sessions;
- Permission permission;
- SubscriberSuffix inSuffix;
-
- int check;
- NdbRecAttr * check2;
-
- MyTransaction = pNDB->startTransaction();
- if (MyTransaction == NULL)
- error_handler("T5-1: startTranscation", pNDB->getNdbErrorString(), pNDB->getNdbError());
-
- MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
- CHECK_NULL(MyOperation, "T5-1: getNdbOperation",
- MyTransaction);
-
- MyOperation->interpretedUpdateTuple();
- MyOperation->equal(IND_SUBSCRIBER_NUMBER,
- inNumber);
- MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
- (char *)&outLocation);
- MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
- &outChangedBy[0]);
- MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
- &outChangedTime[0]);
- MyOperation->getValue(IND_SUBSCRIBER_GROUP,
- (char *)&groupId);
- MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
- (char *)&sessions);
- MyOperation->subValue(IND_SUBSCRIBER_SESSIONS,
- (uint32)inServerBit);
- MyTransaction->execute( NoCommit );
- /* Operation 2 */
-
- MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
- CHECK_NULL(MyOperation, "T5-2: getNdbOperation",
- MyTransaction);
-
- MyOperation->readTuple();
- MyOperation->equal(IND_GROUP_ID,
- (char*)&groupId);
- MyOperation->getValue(IND_GROUP_ALLOW_DELETE,
- (char *)&permission);
- check = MyTransaction->execute( NoCommit );
- CHECK_MINUS_ONE(check, "T5-2: NoCommit",
- MyTransaction);
-
- if(((permission & inServerBit) == inServerBit) &&
- ((sessions & inServerBit) == inServerBit)){
-
- memcpy(inSuffix,
- &inNumber[SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH], SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
-
- DEBUG2("deleting(%.*s) - ", SUBSCRIBER_NUMBER_SUFFIX_LENGTH, inSuffix);
-
- /* Operation 3 */
- MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
- CHECK_NULL(MyOperation, "T5-3: getNdbOperation",
- MyTransaction);
-
- MyOperation->deleteTuple();
- MyOperation->equal(IND_SESSION_SUBSCRIBER,
- (char*)inNumber);
- MyOperation->equal(IND_SESSION_SERVER,
- (char*)&inServerId);
- /* Operation 4 */
-
- /* Operation 5 */
- MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
- CHECK_NULL(MyOperation, "T5-5: getNdbOperation",
- MyTransaction);
-
-
- MyOperation->interpretedUpdateTuple();
- MyOperation->equal(IND_SERVER_ID,
- (char*)&inServerId);
- MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
- (char*)inSuffix);
- MyOperation->incValue(IND_SERVER_DELETES, (uint32)1);
- (* outBranchExecuted) = 1;
- } else {
- (* outBranchExecuted) = 0;
- DEBUG1("%s", ((permission & inServerBit) ? "permission - " : "no permission - "));
- DEBUG1("%s", ((sessions & inServerBit) ? "in session - " : "no in session - "));
- }
-
- if(!inDoRollback && (* outBranchExecuted)){
- DEBUG("commit\n");
- check = MyTransaction->execute( Commit );
- CHECK_MINUS_ONE(check, "T5: Commit",
- MyTransaction);
- } else {
- DEBUG("rollback\n");
- check = MyTransaction->execute(Rollback);
- CHECK_MINUS_ONE(check, "T5:Rollback",
- MyTransaction);
-
- }
-
- pNDB->closeTransaction(MyTransaction);
-}
-
diff --git a/storage/ndb/test/ndbapi/restarter.cpp b/storage/ndb/test/ndbapi/restarter.cpp
deleted file mode 100644
index 25caa3161e0..00000000000
--- a/storage/ndb/test/ndbapi/restarter.cpp
+++ /dev/null
@@ -1,130 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-#include "mgmapi.h"
-#include <string.h>
-#include <NdbMain.h>
-#include <OutputStream.hpp>
-#include <NdbOut.hpp>
-#include <NdbSleep.h>
-#include <getarg.h>
-
-#include <NdbRestarter.hpp>
-#include <NdbRestarts.hpp>
-#include <NDBT.hpp>
-
-int main(int argc, const char** argv){
- ndb_init();
-
- const char* _hostName = NULL;
- int _loops = 10;
- int _wait = 15;
- int _help = 0;
- int _error_insert = 0;
- int _initial = 0;
- int _master = 0;
- int _maxwait = 120;
- int _multiple = 0;
-
- struct getargs args[] = {
- { "seconds", 's', arg_integer, &_wait,
- "Seconds to wait between each restart(0=random)", "secs" },
- { "max seconds", 'm', arg_integer, &_maxwait,
- "Max seconds to wait between each restart. Default is 120 seconds",
- "msecs" },
- { "loops", 'l', arg_integer, &_loops,
- "Number of loops(0=forever)", "loops"},
- { "initial", 'i', arg_flag, &_initial, "Initial node restart"},
- { "error-insert", 'e', arg_flag, &_error_insert, "Use error insert"},
- { "master", 'm', arg_flag, &_master,
- "Restart the master"},
- { "multiple", 'x', arg_flag, &_multiple,
- "Multiple random node restarts. OBS! Even and odd node Ids must be separated into each node group"},
- { "usage", '?', arg_flag, &_help, "Print help", "" }
-
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "hostname:port\n"\
- "This program will connect to the mgmsrv of a NDB cluster.\n"\
- "It will then wait for all nodes to be started, then restart node(s)\n"\
- "and wait for all to restart inbetween. It will do this \n"\
- "loop number of times\n";
-
- if(getarg(args, num_args, argc, argv, &optind) || _help) {
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
- _hostName = argv[optind];
-
-
- NdbRestarts restarts(_hostName);
- NdbRestarter restarter(_hostName);
-
- const char* restartName = "";
- if (_multiple){
- if (_master){
- restartName = "TwoMasterNodeFailure";
- }
- else {
- // Restart 50 percent of nodes
- restartName = "FiftyPercentFail";
- }
- }
- else if (_master){
- restartName = "RestartMasterNodeError";
- }else {
- if (_error_insert)
- restartName = "RestartRandomNodeError";
- else if (_initial)
- restartName = "RestartRandomNodeInitial";
- else
- restartName = "RestartRandomNode";
- }
-
- ndbout << "Performing " << restartName << endl;
-
- int result = NDBT_OK;
- int l = 0;
- while (_loops == 0 || l<_loops){
-
- g_info << "Waiting for cluster to start" << endl;
- while (restarter.waitClusterStarted(1) != 0){
- //g_warning << "Ndb failed to start in 2 minutes" << endl;
- }
-
- int seconds = _wait;
- if(seconds==0) {
- // Create random value, default 120 secs
- seconds = (rand() % _maxwait) + 1;
- }
- g_info << "Waiting for " << seconds << "(" << _maxwait
- << ") secs " << endl;
- NdbSleep_SecSleep(seconds);
-
- g_info << l << ": Restarting node(s) " << endl;
-
- if (restarts.executeRestart(restartName) != 0){
- result = NDBT_FAILED;
- break;
- }
-
- l++;
- }
- return NDBT_ProgramExit(NDBT_OK);
-}
diff --git a/storage/ndb/test/ndbapi/restarter2.cpp b/storage/ndb/test/ndbapi/restarter2.cpp
deleted file mode 100644
index 2010110dce0..00000000000
--- a/storage/ndb/test/ndbapi/restarter2.cpp
+++ /dev/null
@@ -1,117 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-#include <string.h>
-#include <NdbMain.h>
-#include <OutputStream.hpp>
-#include <NdbOut.hpp>
-#include <NdbSleep.h>
-#include <getarg.h>
-
-#include <NdbRestarter.hpp>
-#include <NDBT.hpp>
-
-int main(int argc, const char** argv){
- ndb_init();
-
- const char* _hostName = NULL;
- int _loops = 10;
- int _wait = 15;
- int _help = 0;
-#if 0
- int _crash = 0;
- int _abort = 0;
-#endif
-
- struct getargs args[] = {
- { "seconds", 's', arg_integer, &_wait, "Seconds to wait between each restart(0=random)", "secs" },
- { "loops", 'l', arg_integer, &_loops, "Number of loops", "loops 0=forever"},
-#if 0
- // Not yet!
- { "abort", 'a', arg_flag, &_abort, "Restart abort"},
- { "crash", 'c', arg_flag, &_crash, "Crash instead of restart"},
-#endif
- { "usage", '?', arg_flag, &_help, "Print help", "" }
-
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "hostname:port\n"\
- "This program will connect to the mgmsrv of a NDB cluster.\n"\
- "It will wait for all nodes to be started, then restart all nodes\n"\
- "into nostart state. Then after a random delay it will tell all nodes\n"\
- "to start. It will do this loop number of times\n";
-
- if(getarg(args, num_args, argc, argv, &optind) || _help) {
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
- _hostName = argv[optind];
-
- NdbRestarter restarter(_hostName);
-#if 0
- if(_abort && _crash){
- g_err << "You can't specify both abort and crash" << endl;
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
- if(_abort){
- restarter.setRestartType(NdbRestarter::AbortRestart);
- }
- if(_crash){
- restarter.setRestartType(NdbRestarter::Crash);
- }
-#endif
-
- int l = 0;
- while (_loops == 0 || l<_loops){
- g_info << "Waiting for cluster to start" << endl;
- while(restarter.waitClusterStarted(120) != 0){
- g_warning << "Ndb failed to start in 2 minutes" << endl;
- }
-
- int seconds = _wait;
- if(seconds==0)
- seconds = (rand() % 120) + 1; // Create random value max 120 secs
- g_info << "Waiting for "<<seconds<<" secs" << endl;
- NdbSleep_SecSleep(seconds);
-
- g_info << l << ": restarting all nodes with nostart" << endl;
- const bool b = (restarter.restartAll(false, true, false) == 0);
- assert(b);
-
- g_info << "Waiting for cluster to enter nostart" << endl;
- while(restarter.waitClusterNoStart(120) != 0){
- g_warning << "Ndb failed to enter no start in 2 minutes" << endl;
- }
-
- seconds = _wait;
- if(seconds==0)
- seconds = (rand() % 120) + 1; // Create random value max 120 secs
- g_info << "Waiting for " <<seconds<<" secs" << endl;
- NdbSleep_SecSleep(seconds);
-
- g_info << l << ": Telling all nodes to start" << endl;
- const bool b2 = (restarter.startAll() == 0);
- assert(b2);
-
- l++;
- }
-
- return NDBT_ProgramExit(NDBT_OK);
-}
diff --git a/storage/ndb/test/ndbapi/restarts.cpp b/storage/ndb/test/ndbapi/restarts.cpp
deleted file mode 100644
index 5d00693c525..00000000000
--- a/storage/ndb/test/ndbapi/restarts.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-#include "mgmapi.h"
-#include <string.h>
-#include <NdbMain.h>
-#include <OutputStream.hpp>
-#include <NdbOut.hpp>
-#include <NdbSleep.h>
-#include <getarg.h>
-
-#include <NdbRestarts.hpp>
-#include <NDBT.hpp>
-
-int main(int argc, const char** argv){
- ndb_init();
-
- const char* _restartName = NULL;
- int _loops = 1;
- int _wait = -1;
- int _maxwait = 120;
- int _help = 0;
- int _list = 0;
- int _random = 0;
- int _timeout = 0;
- int _all = 0;
-
- struct getargs args[] = {
- { "seconds", 's', arg_integer, &_wait,
- "Seconds to wait between each restart(0=random)", "secs" },
- { "max seconds", 'm', arg_integer, &_maxwait,
- "Max seconds to wait between each restart. Default is 120 seconds", "msecs" },
- { "loops", 'l', arg_integer, &_loops, "Number of loops(0=forever)", "loops"},
- { "timeout", 't', arg_integer, &_timeout, "Timeout waiting for nodes to start", "seconds"},
- { "random", 'r', arg_flag, &_random, "Select restart case randomly",
- ""},
- { "all", 'a', arg_flag, &_all, "Run all restarts",
- ""},
- { "list-restarts", '\0', arg_flag, &_list, "List available restarts", ""},
- { "usage", '?', arg_flag, &_help, "Print help", "" }
-
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "testname\n" \
- "This program will perform node restart, \n"\
- "multiple node restart or system-restart.\n"\
- "Use --list-restarts to see whats available\n";
-
- if(getarg(args, num_args, argc, argv, &optind) || _help) {
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- if (_list){
- NdbRestarts restarts;
- restarts.listRestarts();
- return NDBT_ProgramExit(NDBT_OK);
- }
-
- if ((argv[optind] == NULL) && (_random == 0)){
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
- _restartName = argv[optind];
-
- NdbRestarts restarts;
-
- int res = NDBT_OK;
- int l = 0;
- while (_loops == 0 || l < _loops){
-
- if (_all) {
- // Execute all restarts, set loops to numRestarts
- // so that ecvery restart is executed once
- _loops = restarts.getNumRestarts();
- res = restarts.executeRestart(l, _timeout);
- } else if (_random) {
- int num = rand() % restarts.getNumRestarts();
- res = restarts.executeRestart(num, _timeout);
- } else {
- res = restarts.executeRestart(_restartName, _timeout);
- }
- if (res != NDBT_OK)
- break;
-
- if (_wait >= 0){
- int seconds = _wait;
- if(seconds==0) {
- // Create random value, default 120 secs
- seconds = (rand() % _maxwait) + 1;
- }
- g_info << "Waiting for " << seconds << "(" << _maxwait
- << ") secs " << endl;
- NdbSleep_SecSleep(seconds);
- }
-
- l++;
- }
- return NDBT_ProgramExit(res);
-}
diff --git a/storage/ndb/test/ndbapi/size.cpp b/storage/ndb/test/ndbapi/size.cpp
deleted file mode 100644
index eed5995fd01..00000000000
--- a/storage/ndb/test/ndbapi/size.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-#include "utv.h"
-
-int main(void)
-{
- ndb_init();
- printf("cdrstruct=%d\n",sizeof(struct cdr_record));
- printf("long int=%d\n",sizeof(long int));
- printf("int=%d\n",sizeof(int));
- printf("short int=%d\n",sizeof(short int));
- return 0;
-}
diff --git a/storage/ndb/test/ndbapi/slow_select.cpp b/storage/ndb/test/ndbapi/slow_select.cpp
deleted file mode 100644
index c3af77248e4..00000000000
--- a/storage/ndb/test/ndbapi/slow_select.cpp
+++ /dev/null
@@ -1,243 +0,0 @@
-/* Copyright (C) 2004, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-#include <NdbApi.hpp>
-#include <NdbOut.hpp>
-#include <NdbTick.h>
-
-struct
-S_Scan {
- const char * m_table;
- const char * m_index;
- NdbIndexScanOperation * m_scan;
- Uint32 metaid;
- Uint32 match_count;
- Uint32 row_count;
-};
-
-static S_Scan g_scans[] = {
- { "affiliatestometa", "ind_affiliatestometa", 0, 0, 0, 0 },
- { "media", "metaid", 0, 0, 0, 0 },
- { "meta", "PRIMARY", 0, 0, 0, 0 },
- { "artiststometamap", "PRIMARY", 0, 0, 0, 0 },
- { "subgenrestometamap", "metaid", 0, 0, 0, 0 }
-};
-
-#define require(x) if(!(x)) { ndbout << "LINE: " << __LINE__ << endl;abort(); }
-#define require2(o, x) if(!(x)) { ndbout << o->getNdbError() << endl; abort(); }
-Uint32 g_affiliateid = 2;
-Uint32 g_formatids[] = { 8, 31, 76 };
-
-Uint64 start;
-Uint32 g_artistid = 0;
-Uint32 g_subgenreid = 0;
-
-NdbConnection* g_trans = 0;
-static void lookup();
-
-int
-main(void){
- ndb_init();
-
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return 1;
- }
-
- Ndb g_ndb(&con, "test");
- g_ndb.init(1024);
-
- require(g_ndb.waitUntilReady() == 0);
-
- while(true){
- g_trans = g_ndb.startTransaction();
- require(g_trans);
-
- size_t i, j;
- const size_t cnt = sizeof(g_scans)/sizeof(g_scans[0]);
-
- start = NdbTick_CurrentMillisecond();
-
- for(i = 0; i<cnt; i++){
- ndbout_c("starting scan on: %s %s",
- g_scans[i].m_table, g_scans[i].m_index);
- g_scans[i].m_scan = g_trans->getNdbIndexScanOperation(g_scans[i].m_index,
- g_scans[i].m_table);
- NdbIndexScanOperation* scan = g_scans[i].m_scan;
- require(scan);
- require(scan->readTuples(NdbScanOperation::LM_CommittedRead,
- 0, 0, true) == 0);
- }
-
- require(!g_scans[0].m_scan->setBound((Uint32)0,
- NdbIndexScanOperation::BoundEQ,
- &g_affiliateid,
- sizeof(g_affiliateid)));
-#if 0
- require(!g_scans[1].m_scan->setBound((Uint32)0,
- NdbIndexScanOperation::BoundLE,
- &g_formatids[0],
- sizeof(g_formatids[0])));
-#endif
-
- NdbScanFilter sf(g_scans[1].m_scan);
- sf.begin(NdbScanFilter::OR);
- sf.eq(2, g_formatids[0]);
- sf.eq(2, g_formatids[1]);
- sf.eq(2, g_formatids[2]);
- sf.end();
-
- // affiliatestometa
- require(g_scans[0].m_scan->getValue("uniquekey"));
- require(g_scans[0].m_scan->getValue("xml"));
-
- // media
- require(g_scans[1].m_scan->getValue("path"));
- require(g_scans[1].m_scan->getValue("mediaid"));
- require(g_scans[1].m_scan->getValue("formatid"));
-
- // meta
- require(g_scans[2].m_scan->getValue("name"));
- require(g_scans[2].m_scan->getValue("xml"));
-
- // artiststometamap
- require(g_scans[3].m_scan->getValue("artistid", (char*)&g_artistid));
-
- // subgenrestometamap
- require(g_scans[4].m_scan->getValue("subgenreid", (char*)&g_subgenreid));
-
- for(i = 0; i<cnt; i++){
- g_scans[i].m_scan->getValue("metaid", (char*)&g_scans[i].metaid);
- }
-
- g_trans->execute(NoCommit, AbortOnError, 1);
-
- Uint32 max_val = 0;
- Uint32 match_val = 0;
-
- S_Scan * F [5], * Q [5], * nextF [5];
- Uint32 F_sz = 0, Q_sz = 0;
- for(i = 0; i<cnt; i++){
- F_sz++;
- F[i] = &g_scans[i];
- }
-
- Uint32 match_count = 0;
- while(F_sz > 0){
- Uint32 prev_F_sz = F_sz;
- F_sz = 0;
- bool found = false;
- //for(i = 0; i<cnt; i++)
- //ndbout_c("%s - %d", g_scans[i].m_table, g_scans[i].metaid);
-
- for(i = 0; i<prev_F_sz; i++){
- int res = F[i]->m_scan->nextResult();
- if(res == -1)
- abort();
-
- if(res == 1){
- continue;
- }
-
- Uint32 metaid = F[i]->metaid;
- F[i]->row_count++;
-
- if(metaid == match_val){
- //ndbout_c("flera");
- nextF[F_sz++] = F[i];
- require(F_sz >= 0 && F_sz <= cnt);
- F[i]->match_count++;
- Uint32 comb = 1;
- for(j = 0; j<cnt; j++){
- comb *= (&g_scans[j] == F[i] ? 1 : g_scans[j].match_count);
- }
- match_count += comb;
- found = true;
- continue;
- }
- if(metaid < max_val){
- nextF[F_sz++] = F[i];
- require(F_sz >= 0 && F_sz <= cnt);
- continue;
- }
- if(metaid > max_val){
- for(j = 0; j<Q_sz; j++)
- nextF[F_sz++] = Q[j];
- require(F_sz >= 0 && F_sz <= cnt);
- Q_sz = 0;
- max_val = metaid;
- }
- Q[Q_sz++] = F[i];
- require(Q_sz >= 0 && Q_sz <= cnt);
- }
- if(F_sz == 0 && Q_sz > 0){
- match_val = max_val;
- for(j = 0; j<Q_sz; j++){
- nextF[F_sz++] = Q[j];
- Q[j]->match_count = 1;
- }
- require(F_sz >= 0 && F_sz <= cnt);
- require(Q_sz >= 0 && Q_sz <= cnt);
- Q_sz = 0;
- match_count++;
- lookup();
- } else if(!found && F_sz + Q_sz < cnt){
- F_sz = 0;
- }
- require(F_sz >= 0 && F_sz <= cnt);
- for(i = 0; i<F_sz; i++)
- F[i] = nextF[i];
- }
-
- start = NdbTick_CurrentMillisecond() - start;
- ndbout_c("Elapsed: %lldms", start);
-
- ndbout_c("rows: %d", match_count);
- for(i = 0; i<cnt; i++){
- ndbout_c("%s : %d", g_scans[i].m_table, g_scans[i].row_count);
- }
- g_trans->close();
- }
-}
-
-static
-void
-lookup(){
- {
- NdbOperation* op = g_trans->getNdbOperation("artists");
- require2(g_trans, op);
- require2(op, op->readTuple() == 0);
- require2(op, op->equal("artistid", g_artistid) == 0);
- require2(op, op->getValue("name"));
- }
-
- {
- NdbOperation* op = g_trans->getNdbOperation("subgenres");
- require2(g_trans, op);
- require2(op, op->readTuple() == 0);
- require2(op, op->equal("subgenreid", g_subgenreid) == 0);
- require2(op, op->getValue("name"));
- }
-
- static int loop = 0;
- if(loop++ >= 16){
- loop = 0;
- require(g_trans->execute(NoCommit) == 0);
- }
- //require(g_trans->restart() == 0);
-}
diff --git a/storage/ndb/test/ndbapi/testBackup.cpp b/storage/ndb/test/ndbapi/testBackup.cpp
deleted file mode 100644
index 98ae98ab073..00000000000
--- a/storage/ndb/test/ndbapi/testBackup.cpp
+++ /dev/null
@@ -1,559 +0,0 @@
-/* Copyright (c) 2003-2006 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT.hpp>
-#include <NDBT_Test.hpp>
-#include <HugoTransactions.hpp>
-#include <UtilTransactions.hpp>
-#include <NdbBackup.hpp>
-
-
-#define CHECK(b) if (!(b)) { \
- g_err << "ERR: "<< step->getName() \
- << " failed on line " << __LINE__ << endl; \
- result = NDBT_FAILED; \
- continue; }
-
-
-int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
-
- int records = ctx->getNumRecords();
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.loadTable(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-bool testMaster = true;
-bool testSlave = false;
-
-int setMaster(NDBT_Context* ctx, NDBT_Step* step){
- testMaster = true;
- testSlave = false;
- return NDBT_OK;
-}
-int setMasterAsSlave(NDBT_Context* ctx, NDBT_Step* step){
- testMaster = true;
- testSlave = true;
- return NDBT_OK;
-}
-int setSlave(NDBT_Context* ctx, NDBT_Step* step){
- testMaster = false;
- testSlave = true;
- return NDBT_OK;
-}
-
-int runAbort(NDBT_Context* ctx, NDBT_Step* step){
- NdbBackup backup(GETNDB(step)->getNodeId()+1);
-
- NdbRestarter restarter;
-
- if (restarter.getNumDbNodes() < 2){
- ctx->stopTest();
- return NDBT_OK;
- }
-
- if(restarter.waitClusterStarted(60) != 0){
- g_err << "Cluster failed to start" << endl;
- return NDBT_FAILED;
- }
-
- if (testMaster) {
- if (testSlave) {
- if (backup.NFMasterAsSlave(restarter) != NDBT_OK){
- return NDBT_FAILED;
- }
- } else {
- if (backup.NFMaster(restarter) != NDBT_OK){
- return NDBT_FAILED;
- }
- }
- } else {
- if (backup.NFSlave(restarter) != NDBT_OK){
- return NDBT_FAILED;
- }
- }
-
- return NDBT_OK;
-}
-
-int runFail(NDBT_Context* ctx, NDBT_Step* step){
- NdbBackup backup(GETNDB(step)->getNodeId()+1);
-
- NdbRestarter restarter;
-
- if (restarter.getNumDbNodes() < 2){
- ctx->stopTest();
- return NDBT_OK;
- }
-
- if(restarter.waitClusterStarted(60) != 0){
- g_err << "Cluster failed to start" << endl;
- return NDBT_FAILED;
- }
-
- if (testMaster) {
- if (testSlave) {
- if (backup.FailMasterAsSlave(restarter) != NDBT_OK){
- return NDBT_FAILED;
- }
- } else {
- if (backup.FailMaster(restarter) != NDBT_OK){
- return NDBT_FAILED;
- }
- }
- } else {
- if (backup.FailSlave(restarter) != NDBT_OK){
- return NDBT_FAILED;
- }
- }
-
- return NDBT_OK;
-}
-
-int runBackupOne(NDBT_Context* ctx, NDBT_Step* step){
- NdbBackup backup(GETNDB(step)->getNodeId()+1);
- unsigned backupId = 0;
-
- if (backup.start(backupId) == -1){
- return NDBT_FAILED;
- }
- ndbout << "Started backup " << backupId << endl;
- ctx->setProperty("BackupId", backupId);
-
- return NDBT_OK;
-}
-
-int
-runBackupLoop(NDBT_Context* ctx, NDBT_Step* step){
- NdbBackup backup(GETNDB(step)->getNodeId()+1);
- unsigned backupId = 0;
-
- int loops = ctx->getNumLoops();
- while(!ctx->isTestStopped() && loops--)
- {
- if (backup.start(backupId) == -1)
- {
- sleep(1);
- loops++;
- }
- else
- {
- sleep(3);
- }
- }
-
- ctx->stopTest();
- return NDBT_OK;
-}
-
-int
-runDDL(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb= GETNDB(step);
- NdbDictionary::Dictionary* pDict = pNdb->getDictionary();
-
- const int tables = NDBT_Tables::getNumTables();
- while(!ctx->isTestStopped())
- {
- const int tab_no = rand() % (tables);
- NdbDictionary::Table tab = *NDBT_Tables::getTable(tab_no);
- BaseString name= tab.getName();
- name.appfmt("-%d", step->getStepNo());
- tab.setName(name.c_str());
- if(pDict->createTable(tab) == 0)
- {
- HugoTransactions hugoTrans(* pDict->getTable(name.c_str()));
- if (hugoTrans.loadTable(pNdb, 10000) != 0){
- return NDBT_FAILED;
- }
-
- while(pDict->dropTable(tab.getName()) != 0 &&
- pDict->getNdbError().code != 4009)
- g_err << pDict->getNdbError() << endl;
-
- sleep(1);
-
- }
- }
- return NDBT_OK;
-}
-
-
-int runDropTablesRestart(NDBT_Context* ctx, NDBT_Step* step){
- NdbRestarter restarter;
-
- Ndb* pNdb = GETNDB(step);
-
- const NdbDictionary::Table *tab = ctx->getTab();
- pNdb->getDictionary()->dropTable(tab->getName());
-
- if (restarter.restartAll(false) != 0)
- return NDBT_FAILED;
-
- if (restarter.waitClusterStarted() != 0)
- return NDBT_FAILED;
-
- return NDBT_OK;
-}
-
-int runRestoreOne(NDBT_Context* ctx, NDBT_Step* step){
- NdbBackup backup(GETNDB(step)->getNodeId()+1);
- unsigned backupId = ctx->getProperty("BackupId");
-
- ndbout << "Restoring backup " << backupId << endl;
-
- if (backup.restore(backupId) == -1){
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-int runVerifyOne(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
- Ndb* pNdb = GETNDB(step);
- int result = NDBT_OK;
- int count = 0;
-
- const NdbDictionary::Table* tab =
- GETNDB(step)->getDictionary()->getTable(ctx->getTab()->getName());
- if(tab == 0)
- return NDBT_FAILED;
-
- UtilTransactions utilTrans(* tab);
- HugoTransactions hugoTrans(* tab);
-
- do{
-
- // Check that there are as many records as we expected
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
-
- g_err << "count = " << count;
- g_err << " records = " << records;
- g_err << endl;
-
- CHECK(count == records);
-
- // Read and verify every record
- CHECK(hugoTrans.pkReadRecords(pNdb, records) == 0);
-
- } while (false);
-
- return result;
-}
-
-int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
-
- UtilTransactions utilTrans(*ctx->getTab());
- if (utilTrans.clearTable2(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runDropTable(NDBT_Context* ctx, NDBT_Step* step){
- GETNDB(step)->getDictionary()->dropTable(ctx->getTab()->getName());
- return NDBT_OK;
-}
-
-#include "bank/Bank.hpp"
-
-int runCreateBank(NDBT_Context* ctx, NDBT_Step* step){
- Bank bank(ctx->m_cluster_connection);
- int overWriteExisting = true;
- if (bank.createAndLoadBank(overWriteExisting, 10) != NDBT_OK)
- return NDBT_FAILED;
- return NDBT_OK;
-}
-
-int runBankTimer(NDBT_Context* ctx, NDBT_Step* step){
- Bank bank(ctx->m_cluster_connection);
- int wait = 30; // Max seconds between each "day"
- int yield = 1; // Loops before bank returns
-
- while (ctx->isTestStopped() == false) {
- bank.performIncreaseTime(wait, yield);
- }
- return NDBT_OK;
-}
-
-int runBankTransactions(NDBT_Context* ctx, NDBT_Step* step){
- Bank bank(ctx->m_cluster_connection);
- int wait = 10; // Max ms between each transaction
- int yield = 100; // Loops before bank returns
-
- while (ctx->isTestStopped() == false) {
- bank.performTransactions(wait, yield);
- }
- return NDBT_OK;
-}
-
-int runBankGL(NDBT_Context* ctx, NDBT_Step* step){
- Bank bank(ctx->m_cluster_connection);
- int yield = 20; // Loops before bank returns
- int result = NDBT_OK;
-
- while (ctx->isTestStopped() == false) {
- if (bank.performMakeGLs(yield) != NDBT_OK){
- ndbout << "bank.performMakeGLs FAILED" << endl;
- result = NDBT_FAILED;
- }
- }
- return NDBT_OK;
-}
-
-int runBankSum(NDBT_Context* ctx, NDBT_Step* step){
- Bank bank(ctx->m_cluster_connection);
- int wait = 2000; // Max ms between each sum of accounts
- int yield = 1; // Loops before bank returns
- int result = NDBT_OK;
-
- while (ctx->isTestStopped() == false) {
- if (bank.performSumAccounts(wait, yield) != NDBT_OK){
- ndbout << "bank.performSumAccounts FAILED" << endl;
- result = NDBT_FAILED;
- }
- }
- return result ;
-}
-
-int runDropBank(NDBT_Context* ctx, NDBT_Step* step){
- Bank bank(ctx->m_cluster_connection);
- if (bank.dropBank() != NDBT_OK)
- return NDBT_FAILED;
- return NDBT_OK;
-}
-
-int runBackupBank(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops();
- int l = 0;
- int maxSleep = 30; // Max seconds between each backup
- Ndb* pNdb = GETNDB(step);
- NdbBackup backup(GETNDB(step)->getNodeId()+1);
- unsigned minBackupId = ~0;
- unsigned maxBackupId = 0;
- unsigned backupId = 0;
- int result = NDBT_OK;
-
- while (l < loops && result != NDBT_FAILED){
-
- if (pNdb->waitUntilReady() != 0){
- result = NDBT_FAILED;
- continue;
- }
-
- // Sleep for a while
- NdbSleep_SecSleep(maxSleep);
-
- // Perform backup
- if (backup.start(backupId) != 0){
- ndbout << "backup.start failed" << endl;
- result = NDBT_FAILED;
- continue;
- }
- ndbout << "Started backup " << backupId << endl;
-
- // Remember min and max backupid
- if (backupId < minBackupId)
- minBackupId = backupId;
-
- if (backupId > maxBackupId)
- maxBackupId = backupId;
-
- ndbout << " maxBackupId = " << maxBackupId
- << ", minBackupId = " << minBackupId << endl;
- ctx->setProperty("MinBackupId", minBackupId);
- ctx->setProperty("MaxBackupId", maxBackupId);
-
- l++;
- }
-
- ctx->stopTest();
-
- return result;
-}
-
-int runRestoreBankAndVerify(NDBT_Context* ctx, NDBT_Step* step){
- NdbRestarter restarter;
- NdbBackup backup(GETNDB(step)->getNodeId()+1);
- unsigned minBackupId = ctx->getProperty("MinBackupId");
- unsigned maxBackupId = ctx->getProperty("MaxBackupId");
- unsigned backupId = minBackupId;
- int result = NDBT_OK;
- int errSumAccounts = 0;
- int errValidateGL = 0;
-
- ndbout << " maxBackupId = " << maxBackupId << endl;
- ndbout << " minBackupId = " << minBackupId << endl;
-
- while (backupId <= maxBackupId){
-
- // TEMPORARY FIX
- // To erase all tables from cache(s)
- // To be removed, maybe replaced by ndb.invalidate();
- runDropTable(ctx,step);
- {
- Bank bank(ctx->m_cluster_connection);
-
- if (bank.dropBank() != NDBT_OK){
- result = NDBT_FAILED;
- break;
- }
- }
- // END TEMPORARY FIX
-
- ndbout << "Performing restart" << endl;
- if (restarter.restartAll(false) != 0)
- return NDBT_FAILED;
-
- if (restarter.waitClusterStarted() != 0)
- return NDBT_FAILED;
-
- ndbout << "Restoring backup " << backupId << endl;
- if (backup.restore(backupId) == -1){
- return NDBT_FAILED;
- }
- ndbout << "Backup " << backupId << " restored" << endl;
-
- // Let bank verify
- Bank bank(ctx->m_cluster_connection);
-
- int wait = 0;
- int yield = 1;
- if (bank.performSumAccounts(wait, yield) != 0){
- ndbout << "bank.performSumAccounts FAILED" << endl;
- ndbout << " backupId = " << backupId << endl << endl;
- result = NDBT_FAILED;
- errSumAccounts++;
- }
-
- if (bank.performValidateAllGLs() != 0){
- ndbout << "bank.performValidateAllGLs FAILED" << endl;
- ndbout << " backupId = " << backupId << endl << endl;
- result = NDBT_FAILED;
- errValidateGL++;
- }
-
- backupId++;
- }
-
- if (result != NDBT_OK){
- ndbout << "Verification of backup failed" << endl
- << " errValidateGL="<<errValidateGL<<endl
- << " errSumAccounts="<<errSumAccounts<<endl << endl;
- }
-
- return result;
-}
-
-NDBT_TESTSUITE(testBackup);
-TESTCASE("BackupOne",
- "Test that backup and restore works on one table \n"
- "1. Load table\n"
- "2. Backup\n"
- "3. Drop tables and restart \n"
- "4. Restore\n"
- "5. Verify count and content of table\n"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runBackupOne);
- INITIALIZER(runDropTablesRestart);
- INITIALIZER(runRestoreOne);
- VERIFIER(runVerifyOne);
- FINALIZER(runClearTable);
-}
-TESTCASE("BackupDDL",
- "Test that backup and restore works on with DDL ongoing\n"
- "1. Backups and DDL (create,drop,table.index)"){
- INITIALIZER(runLoadTable);
- STEP(runBackupLoop);
- STEP(runDDL);
- STEP(runDDL);
- FINALIZER(runClearTable);
-}
-TESTCASE("BackupBank",
- "Test that backup and restore works during transaction load\n"
- " by backing up the bank"
- "1. Create bank\n"
- "2a. Start bank and let it run\n"
- "2b. Perform loop number of backups of the bank\n"
- " when backups are finished tell bank to close\n"
- "3. Restart ndb -i and reload each backup\n"
- " let bank verify that the backup is consistent\n"
- "4. Drop bank\n"){
- INITIALIZER(runCreateBank);
- STEP(runBankTimer);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankGL);
- // TODO STEP(runBankSum);
- STEP(runBackupBank);
- VERIFIER(runRestoreBankAndVerify);
- // FINALIZER(runDropBank);
-}
-TESTCASE("NFMaster",
- "Test that backup behaves during node failiure\n"){
- INITIALIZER(setMaster);
- STEP(runAbort);
-
-}
-TESTCASE("NFMasterAsSlave",
- "Test that backup behaves during node failiure\n"){
- INITIALIZER(setMasterAsSlave);
- STEP(runAbort);
-
-}
-TESTCASE("NFSlave",
- "Test that backup behaves during node failiure\n"){
- INITIALIZER(setSlave);
- STEP(runAbort);
-
-}
-TESTCASE("FailMaster",
- "Test that backup behaves during node failiure\n"){
- INITIALIZER(setMaster);
- STEP(runFail);
-
-}
-TESTCASE("FailMasterAsSlave",
- "Test that backup behaves during node failiure\n"){
- INITIALIZER(setMasterAsSlave);
- STEP(runFail);
-
-}
-TESTCASE("FailSlave",
- "Test that backup behaves during node failiure\n"){
- INITIALIZER(setSlave);
- STEP(runFail);
-
-}
-NDBT_TESTSUITE_END(testBackup);
-
-int main(int argc, const char** argv){
- ndb_init();
- return testBackup.execute(argc, argv);
-}
-
-
diff --git a/storage/ndb/test/ndbapi/testBasic.cpp b/storage/ndb/test/ndbapi/testBasic.cpp
deleted file mode 100644
index 3345db2d711..00000000000
--- a/storage/ndb/test/ndbapi/testBasic.cpp
+++ /dev/null
@@ -1,1850 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT_Test.hpp>
-#include <NDBT_ReturnCodes.h>
-#include <HugoTransactions.hpp>
-#include <UtilTransactions.hpp>
-#include <NdbRestarter.hpp>
-
-#define GETNDB(ps) ((NDBT_NdbApiStep*)ps)->getNdb()
-
-
-/**
- * TODO
- * dirtyWrite, write, dirtyUpdate
- * delete should be visible to same transaction
- *
- */
-int runLoadTable2(NDBT_Context* ctx, NDBT_Step* step)
-{
- int records = ctx->getNumRecords();
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.loadTable(GETNDB(step), records, 512, false, 0, true) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runLoadTable(NDBT_Context* ctx, NDBT_Step* step)
-{
- int records = ctx->getNumRecords();
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.loadTable(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runInsert(NDBT_Context* ctx, NDBT_Step* step){
-
- int records = ctx->getNumRecords();
- HugoTransactions hugoTrans(*ctx->getTab());
- // Insert records, dont allow any
- // errors(except temporary) while inserting
- if (hugoTrans.loadTable(GETNDB(step), records, 1, false) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runInsertTwice(NDBT_Context* ctx, NDBT_Step* step){
-
- int records = ctx->getNumRecords();
- HugoTransactions hugoTrans(*ctx->getTab());
- // Insert records, expect primary key violation 630
- if (hugoTrans.loadTable(GETNDB(step), records, 1, false) != 630){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runVerifyInsert(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
-
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.pkDelRecords(GETNDB(step), records, 1, false) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runInsertUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
- int i = 0;
- HugoTransactions hugoTrans(*ctx->getTab());
- while (ctx->isTestStopped() == false) {
- g_info << i << ": ";
- if (hugoTrans.loadTable(GETNDB(step), records) != 0){
- g_info << endl;
- return NDBT_FAILED;
- }
- i++;
- }
- g_info << endl;
- return NDBT_OK;
-}
-
-int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
- int batchSize = ctx->getProperty("BatchSize", 1);
-
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.pkDelRecords(GETNDB(step), records, batchSize) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runPkDelete(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
-
- int i = 0;
- HugoTransactions hugoTrans(*ctx->getTab());
- while (i<loops) {
- g_info << i << ": ";
- if (hugoTrans.pkDelRecords(GETNDB(step), records) != 0){
- g_info << endl;
- return NDBT_FAILED;
- }
- // Load table, don't allow any primary key violations
- if (hugoTrans.loadTable(GETNDB(step), records, 512, false) != 0){
- g_info << endl;
- return NDBT_FAILED;
- }
- i++;
- }
- g_info << endl;
- return NDBT_OK;
-}
-
-
-int runPkRead(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int batchSize = ctx->getProperty("BatchSize", 1);
- int lm = ctx->getProperty("LockMode", NdbOperation::LM_Read);
- int i = 0;
- HugoTransactions hugoTrans(*ctx->getTab());
- while (i<loops) {
- g_info << i << ": ";
- if (hugoTrans.pkReadRecords(GETNDB(step), records, batchSize,
- (NdbOperation::LockMode)lm) != NDBT_OK){
- g_info << endl;
- return NDBT_FAILED;
- }
- i++;
- }
- g_info << endl;
- return NDBT_OK;
-}
-
-int runPkReadUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
- int batchSize = ctx->getProperty("BatchSize", 1);
- int i = 0;
- HugoTransactions hugoTrans(*ctx->getTab());
- while (ctx->isTestStopped() == false) {
- g_info << i << ": ";
- if (hugoTrans.pkReadRecords(GETNDB(step), records, batchSize) != 0){
- g_info << endl;
- return NDBT_FAILED;
- }
- i++;
- }
- g_info << endl;
- return NDBT_OK;
-}
-
-int runPkUpdate(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int batchSize = ctx->getProperty("BatchSize", 1);
- int i = 0;
- HugoTransactions hugoTrans(*ctx->getTab());
- while (i<loops) {
- g_info << "|- " << i << ": ";
- if (hugoTrans.pkUpdateRecords(GETNDB(step), records, batchSize) != 0){
- g_info << endl;
- return NDBT_FAILED;
- }
- i++;
- }
- g_info << endl;
- return NDBT_OK;
-}
-
-int runPkUpdateUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
- int batchSize = ctx->getProperty("BatchSize", 1);
- int i = 0;
- HugoTransactions hugoTrans(*ctx->getTab());
- while (ctx->isTestStopped()) {
- g_info << i << ": ";
- if (hugoTrans.pkUpdateRecords(GETNDB(step), records, batchSize) != 0){
- g_info << endl;
- return NDBT_FAILED;
- }
- i++;
- }
- g_info << endl;
- return NDBT_OK;
-}
-
-int runLocker(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int records = ctx->getNumRecords();
- HugoTransactions hugoTrans(*ctx->getTab());
-
- if (hugoTrans.lockRecords(GETNDB(step), records, 10, 500) != 0){
- result = NDBT_FAILED;
- }
- ctx->stopTest();
-
- return result;
-}
-
-int
-runInsertOne(NDBT_Context* ctx, NDBT_Step* step){
-
- if(ctx->getProperty("InsertCommitted", (Uint32)0) != 0){
- abort();
- }
-
- while(ctx->getProperty("Read1Performed", (Uint32)0) == 0){
- NdbSleep_MilliSleep(20);
- }
-
- HugoTransactions hugoTrans(*ctx->getTab());
-
- if (hugoTrans.loadTable(GETNDB(step), 1, 1) != 0){
- return NDBT_FAILED;
- }
-
- ctx->setProperty("InsertCommitted", 1);
-
- NdbSleep_SecSleep(2);
-
- return NDBT_OK;
-}
-
-static
-int
-readOneNoCommit(Ndb* pNdb, NdbConnection* pTrans,
- const NdbDictionary::Table* tab,NDBT_ResultRow * row){
- int a;
- NdbOperation * pOp = pTrans->getNdbOperation(tab->getName());
- if (pOp == NULL){
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- HugoTransactions tmp(*tab);
-
- int check = pOp->readTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- // Define primary keys
- for(a = 0; a<tab->getNoOfColumns(); a++){
- if (tab->getColumn(a)->getPrimaryKey() == true){
- if(tmp.equalForAttr(pOp, a, 0) != 0){
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
- }
- }
-
- // Define attributes to read
- for(a = 0; a<tab->getNoOfColumns(); a++){
- if((row->attributeStore(a) =
- pOp->getValue(tab->getColumn(a)->getName())) == 0) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
- }
-
- check = pTrans->execute(NoCommit);
- if( check == -1 ) {
- const NdbError err = pTrans->getNdbError();
- ERR(err);
- return err.code;
- }
- return NDBT_OK;
-}
-
-int
-runReadOne(NDBT_Context* ctx, NDBT_Step* step){
-
- Ndb* pNdb = GETNDB(step);
- const NdbDictionary::Table* tab = ctx->getTab();
- NDBT_ResultRow row1(*tab);
- NDBT_ResultRow row2(*tab);
-
- if(ctx->getProperty("Read1Performed", (Uint32)0) != 0){
- abort();
- }
-
- if(ctx->getProperty("InsertCommitted", (Uint32)0) != 0){
- abort();
- }
-
- NdbConnection * pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- abort();
- }
-
- // Read a record with NoCommit
- // Since the record isn't inserted yet it wil return 626
- const int res1 = readOneNoCommit(pNdb, pTrans, tab, &row1);
- g_info << "|- res1 = " << res1 << endl;
-
- ctx->setProperty("Read1Performed", 1);
-
- while(ctx->getProperty("InsertCommitted", (Uint32)0) == 0 &&
- !ctx->isTestStopped()){
- g_info << "|- Waiting for insert" << endl;
- NdbSleep_MilliSleep(20);
- }
-
- if(ctx->isTestStopped()){
- abort();
- }
-
- // Now the record should have been inserted
- // Read it once again in the same transaction
- // Should also reutrn 626 if reads are consistent
-
- // NOTE! Currently it's not possible to start a new operation
- // on a transaction that has returned an error code
- // This is wat fail in this test
- // MASV 20030624
- const int res2 = readOneNoCommit(pNdb, pTrans, tab, &row2);
-
- pTrans->execute(Commit);
- pNdb->closeTransaction(pTrans);
- g_info << "|- res2 = " << res2 << endl;
-
- if (res2 == 626 && res1 == res2)
- return NDBT_OK;
- else
- return NDBT_FAILED;
-}
-
-int runFillTable(NDBT_Context* ctx, NDBT_Step* step){
- int batch = 512; //4096;
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.fillTable(GETNDB(step), batch ) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runClearTable2(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
-
- UtilTransactions utilTrans(*ctx->getTab());
- if (utilTrans.clearTable2(GETNDB(step), records, 240) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-#define CHECK(b) if (!(b)) { \
- ndbout << "ERR: "<< step->getName() \
- << " failed on line " << __LINE__ << endl; \
- result = NDBT_FAILED; \
- break; }
-
-int runNoCommitSleep(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
- int sleepTime = 100; // ms
- for (int i = 2; i < 8; i++){
-
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
-
- ndbout << i <<": Sleeping for " << sleepTime << " ms" << endl;
- NdbSleep_MilliSleep(sleepTime);
-
- // Dont care about result of these ops
- hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive);
- hugoOps.closeTransaction(pNdb);
-
- sleepTime = sleepTime *i;
- }
-
- hugoOps.closeTransaction(pNdb);
-
- return result;
-}
-
-int runCommit626(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- do{
- // Commit transaction
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_Commit(pNdb) == 626);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
-
- // Commit transaction
- // Multiple operations
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 2, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 3, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_Commit(pNdb) == 626);
- }while(false);
-
- hugoOps.closeTransaction(pNdb);
-
- return result;
-}
-
-int runCommit630(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- do{
- // Commit transaction
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkInsertRecord(pNdb, 1) == 0);
- CHECK(hugoOps.execute_Commit(pNdb) == 630);
- }while(false);
-
- hugoOps.closeTransaction(pNdb);
-
- return result;
-}
-
-int runCommit_TryCommit626(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- do{
- // Commit transaction, TryCommit
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_Commit(pNdb, TryCommit) == 626);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
-
- // Commit transaction, TryCommit
- // Several operations in one transaction
- // The insert is OK
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 2, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 3, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.pkInsertRecord(pNdb, 1) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 4, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_Commit(pNdb, TryCommit) == 626);
- }while(false);
-
- hugoOps.closeTransaction(pNdb);
-
- return result;
-}
-
-int runCommit_TryCommit630(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- do{
- // Commit transaction, TryCommit
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkInsertRecord(pNdb, 1) == 0);
- CHECK(hugoOps.execute_Commit(pNdb, TryCommit) == 630);
- }while(false);
-
- hugoOps.closeTransaction(pNdb);
-
- return result;
-}
-
-int runCommit_CommitAsMuchAsPossible626(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- do{
- // Commit transaction, CommitAsMuchAsPossible
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_Commit(pNdb, CommitAsMuchAsPossible) == 626);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
-
- // Commit transaction, CommitAsMuchAsPossible
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 2, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 3, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.pkInsertRecord(pNdb, 1) == 0);
- CHECK(hugoOps.execute_Commit(pNdb, CommitAsMuchAsPossible) == 626);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
-
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 1) == 0);
- CHECK(hugoOps.execute_Commit(pNdb) == 0);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
- } while(false);
-
- hugoOps.closeTransaction(pNdb);
-
- return result;
-}
-
-int runCommit_CommitAsMuchAsPossible630(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- do{
- // Commit transaction, CommitAsMuchAsPossible
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkInsertRecord(pNdb, 1) == 0);
- CHECK(hugoOps.pkDeleteRecord(pNdb, 2) == 0);
- CHECK(hugoOps.execute_Commit(pNdb, CommitAsMuchAsPossible) == 630);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
-
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 2) == 0);
- CHECK(hugoOps.execute_Commit(pNdb) == 0);
- } while(false);
-
- hugoOps.closeTransaction(pNdb);
-
- return result;
-}
-
-int runNoCommit626(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- do{
- // No commit transaction, readTuple
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Read) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 626);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
-
- // No commit transaction, readTupleExcluive
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 626);
- }while(false);
-
- hugoOps.closeTransaction(pNdb);
-
- return result;
-}
-
-int runNoCommit630(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- do{
- // No commit transaction
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkInsertRecord(pNdb, 1) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 630);
- }while(false);
-
- hugoOps.closeTransaction(pNdb);
-
- return result;
-}
-
-int runNoCommitRollback626(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- do{
- // No commit transaction, rollback
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 626);
- CHECK(hugoOps.execute_Rollback(pNdb) == 0);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
-
- // No commit transaction, rollback
- // Multiple operations
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 2, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 3, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 4, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 626);
- CHECK(hugoOps.execute_Rollback(pNdb) == 0);
- }while(false);
-
- hugoOps.closeTransaction(pNdb);
-
- return result;
-}
-
-int runNoCommitRollback630(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- do{
- // No commit transaction, rollback
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkInsertRecord(pNdb, 1) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 630);
- CHECK(hugoOps.execute_Rollback(pNdb) == 0);
- }while(false);
-
- hugoOps.closeTransaction(pNdb);
-
- return result;
-}
-
-
-int runNoCommitAndClose(NDBT_Context* ctx, NDBT_Step* step){
- int i, result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- do{
- // Read
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- for (i = 0; i < 10; i++)
- CHECK(hugoOps.pkReadRecord(pNdb, i, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
-
- // Update
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- for (i = 0; i < 10; i++)
- CHECK(hugoOps.pkUpdateRecord(pNdb, i) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
-
- // Delete
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- for (i = 0; i < 10; i++)
- CHECK(hugoOps.pkDeleteRecord(pNdb, i) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
-
- // Try to insert, record should already exist
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- for (i = 0; i < 10; i++)
- CHECK(hugoOps.pkInsertRecord(pNdb, i) == 0);
- CHECK(hugoOps.execute_Commit(pNdb) == 630);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
-
- }while(false);
-
- hugoOps.closeTransaction(pNdb);
-
- return result;
-}
-
-
-
-int runCheckRollbackDelete(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- do{
-
- // Read value and save it for later
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 5) == 0);
- CHECK(hugoOps.execute_Commit(pNdb) == 0);
- CHECK(hugoOps.saveCopyOfRecord() == NDBT_OK);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
-
- // Delete record 5
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkDeleteRecord(pNdb, 5) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
-
- // Check record is deleted
- CHECK(hugoOps.pkReadRecord(pNdb, 5, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 626);
- CHECK(hugoOps.execute_Rollback(pNdb) == 0);
-
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
-
- // Check record is not deleted
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 5, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_Commit(pNdb) == 0);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
-
- // Check record is back to original value
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 5, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_Commit(pNdb) == 0);
- CHECK(hugoOps.compareRecordToCopy() == NDBT_OK);
-
-
- }while(false);
-
- hugoOps.closeTransaction(pNdb);
-
- return result;
-}
-
-int runCheckRollbackUpdate(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
- int numRecords = 5;
- do{
-
- // Read value and save it for later
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 1, numRecords) == 0);
- CHECK(hugoOps.execute_Commit(pNdb) == 0);
- CHECK(hugoOps.verifyUpdatesValue(0) == NDBT_OK); // Update value 0
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
-
- // Update record 5
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkUpdateRecord(pNdb, 1, numRecords, 5) == 0);// Updates value 5
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
-
- // Check record is updated
- CHECK(hugoOps.pkReadRecord(pNdb, 1, numRecords, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
- CHECK(hugoOps.verifyUpdatesValue(5) == NDBT_OK); // Updates value 5
- CHECK(hugoOps.execute_Rollback(pNdb) == 0);
-
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
-
- // Check record is back to original value
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 1, numRecords, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_Commit(pNdb) == 0);
- CHECK(hugoOps.verifyUpdatesValue(0) == NDBT_OK); // Updates value 0
-
- }while(false);
-
- hugoOps.closeTransaction(pNdb);
-
- return result;
-}
-
-int runCheckRollbackDeleteMultiple(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- do{
- // Read value and save it for later
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 5, 10) == 0);
- CHECK(hugoOps.execute_Commit(pNdb) == 0);
- CHECK(hugoOps.verifyUpdatesValue(0) == NDBT_OK);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
-
- Uint32 updatesValue = 0;
- Uint32 j;
- for(Uint32 i = 0; i<1; i++){
- // Read record 5 - 10
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 5, 10, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
-
- for(j = 0; j<10; j++){
- // Update record 5 - 10
- updatesValue++;
- CHECK(hugoOps.pkUpdateRecord(pNdb, 5, 10, updatesValue) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
-
- CHECK(hugoOps.pkReadRecord(pNdb, 5, 10, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
- CHECK(hugoOps.verifyUpdatesValue(updatesValue) == 0);
- }
-
- for(j = 0; j<10; j++){
- // Delete record 5 - 10 times
- CHECK(hugoOps.pkDeleteRecord(pNdb, 5, 10) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
-
-#if 0
- // Check records are deleted
- CHECK(hugoOps.pkReadRecord(pNdb, 5, 10, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 626);
-#endif
-
- updatesValue++;
- CHECK(hugoOps.pkInsertRecord(pNdb, 5, 10, updatesValue) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
-
- CHECK(hugoOps.pkReadRecord(pNdb, 5, 10, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
- CHECK(hugoOps.verifyUpdatesValue(updatesValue) == 0);
- }
-
- CHECK(hugoOps.pkDeleteRecord(pNdb, 5, 10) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
-
- // Check records are deleted
- CHECK(hugoOps.pkReadRecord(pNdb, 5, 10, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 626);
- CHECK(hugoOps.execute_Rollback(pNdb) == 0);
-
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
- }
-
- // Check records are not deleted
- // after rollback
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 5, 10, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_Commit(pNdb) == 0);
- CHECK(hugoOps.verifyUpdatesValue(0) == NDBT_OK);
-
- }while(false);
-
- hugoOps.closeTransaction(pNdb);
-
- return result;
-}
-
-
-int runCheckImplicitRollbackDelete(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- do{
- // Read record 5
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 5, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
-
- // Update record 5
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkUpdateRecord(pNdb, 5) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
-
- // Delete record 5
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkDeleteRecord(pNdb, 5) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
-
- // Check record is not deleted
- // Close transaction should have rollbacked
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 5, 1, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_Commit(pNdb) == 0);
- }while(false);
-
- hugoOps.closeTransaction(pNdb);
-
- return result;
-}
-
-int runCheckCommitDelete(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- do{
- // Read 10 records
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 5, 10, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
-
- // Update 10 records
- CHECK(hugoOps.pkUpdateRecord(pNdb, 5, 10) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
-
- // Delete 10 records
- CHECK(hugoOps.pkDeleteRecord(pNdb, 5, 10) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
-
- CHECK(hugoOps.execute_Commit(pNdb) == 0);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
-
- // Check record's are deleted
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 5, 10, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_Commit(pNdb) == 626);
-
- }while(false);
-
- hugoOps.closeTransaction(pNdb);
-
- return result;
-}
-
-int runRollbackNothing(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- do{
- // Delete record 5 - 15
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkDeleteRecord(pNdb, 5, 10) == 0);
- // Rollback
- CHECK(hugoOps.execute_Rollback(pNdb) == 0);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
-
- // Check records are not deleted
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 5, 10, NdbOperation::LM_Exclusive) == 0);
- CHECK(hugoOps.execute_Commit(pNdb) == 0);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
-
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.execute_Rollback(pNdb) == 0);
-
- }while(false);
-
- hugoOps.closeTransaction(pNdb);
-
- return result;
-}
-
-int runMassiveRollback(NDBT_Context* ctx, NDBT_Step* step){
-
- NdbRestarter restarter;
- const int records = 4 * restarter.getNumDbNodes();
-
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.loadTable(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
-
- int result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- const Uint32 OPS_PER_TRANS = 256;
- const Uint32 OPS_TOTAL = 4096;
-
- for(int row = 0; row < records; row++){
- int res;
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- for(Uint32 i = 0; i<OPS_TOTAL; i += OPS_PER_TRANS){
- for(Uint32 j = 0; j<OPS_PER_TRANS; j++){
- CHECK(hugoOps.pkUpdateRecord(pNdb, row, 1, i) == 0);
- }
- g_info << "Performed " << (i+OPS_PER_TRANS) << " updates on row: " << row
- << endl;
- if(result != NDBT_OK){
- break;
- }
- res = hugoOps.execute_NoCommit(pNdb);
- if(res != 0){
- NdbError err = pNdb->getNdbError(res);
- CHECK(err.classification == NdbError::TimeoutExpired);
- break;
- }
- }
- if(result != NDBT_OK){
- break;
- }
- g_info << "executeRollback" << endl;
- CHECK(hugoOps.execute_Rollback(pNdb) == 0);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
- }
-
- hugoOps.closeTransaction(pNdb);
- return result;
-}
-
-int
-runMassiveRollback2(NDBT_Context* ctx, NDBT_Step* step){
-
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.loadTable(GETNDB(step), 1) != 0){
- return NDBT_FAILED;
- }
-
- int result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- const Uint32 OPS_TOTAL = 4096;
- const Uint32 LOOPS = 10;
-
- for(Uint32 loop = 0; loop<LOOPS; loop++){
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- for(Uint32 i = 0; i<OPS_TOTAL-1; i ++){
- if((i & 1) == 0){
- CHECK(hugoOps.pkUpdateRecord(pNdb, 0, 1, loop) == 0);
- } else {
- CHECK(hugoOps.pkUpdateRecord(pNdb, 1, 1, loop) == 0);
- }
- }
- CHECK(hugoOps.execute_Commit(pNdb) == 626);
- CHECK(hugoOps.execute_Rollback(pNdb) == 0);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
- }
-
- hugoOps.closeTransaction(pNdb);
- return result;
-}
-
-int
-runMassiveRollback3(NDBT_Context* ctx, NDBT_Step* step){
-
- int result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- const Uint32 BATCH = 10;
- const Uint32 OPS_TOTAL = 50;
- const Uint32 LOOPS = 100;
-
- for(Uint32 loop = 0; loop<LOOPS; loop++)
- {
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- bool ok = true;
- for (Uint32 i = 0; i<OPS_TOTAL; i+= BATCH)
- {
- CHECK(hugoOps.pkInsertRecord(pNdb, i, BATCH, 0) == 0);
- if (hugoOps.execute_NoCommit(pNdb) != 0)
- {
- ok = false;
- break;
- }
- }
- hugoOps.execute_Rollback(pNdb);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
- }
-
- hugoOps.closeTransaction(pNdb);
- return result;
-}
-
-int
-runMassiveRollback4(NDBT_Context* ctx, NDBT_Step* step){
-
- int result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- const Uint32 BATCH = 10;
- const Uint32 OPS_TOTAL = 20;
- const Uint32 LOOPS = 100;
-
- for(Uint32 loop = 0; loop<LOOPS; loop++)
- {
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- bool ok = true;
- for (Uint32 i = 0; i<OPS_TOTAL; i+= BATCH)
- {
- CHECK(hugoOps.pkInsertRecord(pNdb, i, BATCH, 0) == 0);
- CHECK(hugoOps.pkDeleteRecord(pNdb, i, BATCH) == 0);
- if (hugoOps.execute_NoCommit(pNdb) != 0)
- {
- ok = false;
- break;
- }
- }
- hugoOps.execute_Rollback(pNdb);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
- }
-
- hugoOps.closeTransaction(pNdb);
- return result;
-}
-
-/**
- * TUP errors
- */
-struct TupError
-{
- enum Bits {
- TE_VARSIZE = 0x1,
- TE_MULTI_OP = 0x2,
- TE_DISK = 0x4,
- TE_REPLICA = 0x8
- };
- int op;
- int error;
- int bits;
-};
-
-static
-TupError
-f_tup_errors[] =
-{
- { NdbOperation::InsertRequest, 4014, 0 }, // Out of undo buffer
- { NdbOperation::InsertRequest, 4015, TupError::TE_DISK }, // Out of log space
- { NdbOperation::InsertRequest, 4016, 0 }, // AI Inconsistency
- { NdbOperation::InsertRequest, 4017, 0 }, // Out of memory
- { NdbOperation::InsertRequest, 4018, 0 }, // Null check error
- { NdbOperation::InsertRequest, 4019, TupError::TE_REPLICA }, //Alloc rowid error
- { NdbOperation::InsertRequest, 4020, TupError::TE_MULTI_OP }, // Size change error
- { NdbOperation::InsertRequest, 4021, TupError::TE_DISK }, // Out of disk space
- { -1, 0, 0 }
-};
-
-int
-runTupErrors(NDBT_Context* ctx, NDBT_Step* step){
-
- NdbRestarter restarter;
- HugoTransactions hugoTrans(*ctx->getTab());
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- const NdbDictionary::Table * tab = ctx->getTab();
- Uint32 i;
- int bits = TupError::TE_MULTI_OP;
- for(i = 0; i<tab->getNoOfColumns(); i++)
- {
- if (tab->getColumn(i)->getArrayType() != NdbDictionary::Column::ArrayTypeFixed)
- bits |= TupError::TE_VARSIZE;
- if (tab->getColumn(i)->getStorageType()!= NdbDictionary::Column::StorageTypeMemory)
- bits |= TupError::TE_DISK;
- }
-
- if (restarter.getNumDbNodes() >= 2)
- {
- bits |= TupError::TE_REPLICA;
- }
-
- /**
- * Insert
- */
- for(i = 0; f_tup_errors[i].op != -1; i++)
- {
- if (f_tup_errors[i].op != NdbOperation::InsertRequest)
- {
- g_info << "Skipping " << f_tup_errors[i].error
- << " - not insert" << endl;
- continue;
- }
-
- if ((f_tup_errors[i].bits & bits) != f_tup_errors[i].bits)
- {
- g_info << "Skipping " << f_tup_errors[i].error
- << " - req bits: " << hex << f_tup_errors[i].bits
- << " bits: " << hex << bits << endl;
- continue;
- }
-
- g_info << "Testing error insert: " << f_tup_errors[i].error << endl;
- restarter.insertErrorInAllNodes(f_tup_errors[i].error);
- if (f_tup_errors[i].bits & TupError::TE_MULTI_OP)
- {
-
- }
- else
- {
- hugoTrans.loadTable(pNdb, 5);
- }
- restarter.insertErrorInAllNodes(0);
- if (hugoTrans.clearTable(pNdb, 5) != 0)
- {
- return NDBT_FAILED;
- }
- }
-
- return NDBT_OK;
-}
-
-int
-runInsertError(NDBT_Context* ctx, NDBT_Step* step){
-
- int result = NDBT_OK;
- HugoOperations hugoOp1(*ctx->getTab());
- HugoOperations hugoOp2(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- NdbRestarter restarter;
- restarter.insertErrorInAllNodes(4017);
- const Uint32 LOOPS = 10;
- for (Uint32 i = 0; i<LOOPS; i++)
- {
- CHECK(hugoOp1.startTransaction(pNdb) == 0);
- CHECK(hugoOp1.pkInsertRecord(pNdb, 1) == 0);
-
- CHECK(hugoOp2.startTransaction(pNdb) == 0);
- CHECK(hugoOp2.pkReadRecord(pNdb, 1, 1) == 0);
-
- CHECK(hugoOp1.execute_async_prepare(pNdb, NdbTransaction::Commit) == 0);
- CHECK(hugoOp2.execute_async_prepare(pNdb, NdbTransaction::Commit) == 0);
- hugoOp1.wait_async(pNdb);
- hugoOp2.wait_async(pNdb);
- CHECK(hugoOp1.closeTransaction(pNdb) == 0);
- CHECK(hugoOp2.closeTransaction(pNdb) == 0);
- }
-
- restarter.insertErrorInAllNodes(0);
-
- return result;
-}
-
-int
-runInsertError2(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- HugoOperations hugoOp1(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- NdbRestarter restarter;
- restarter.insertErrorInAllNodes(4017);
-
- const Uint32 LOOPS = 1;
- for (Uint32 i = 0; i<LOOPS; i++)
- {
- CHECK(hugoOp1.startTransaction(pNdb) == 0);
- CHECK(hugoOp1.pkInsertRecord(pNdb, 1) == 0);
- CHECK(hugoOp1.pkDeleteRecord(pNdb, 1) == 0);
-
- hugoOp1.execute_NoCommit(pNdb);
- CHECK(hugoOp1.closeTransaction(pNdb) == 0);
- }
-
- restarter.insertErrorInAllNodes(0);
- return NDBT_OK;
-}
-
-int
-runBug25090(NDBT_Context* ctx, NDBT_Step* step){
-
- Ndb* pNdb = GETNDB(step);
- NdbDictionary::Dictionary * dict = pNdb->getDictionary();
-
- HugoOperations ops(*ctx->getTab());
-
- int loops = ctx->getNumLoops();
- const int rows = ctx->getNumRecords();
-
- while (loops--)
- {
- ops.startTransaction(pNdb);
- ops.pkReadRecord(pNdb, 1, 1);
- ops.execute_Commit(pNdb, AO_IgnoreError);
- sleep(10);
- ops.closeTransaction(pNdb);
- }
-
- return NDBT_OK;
-}
-
-int
-runDeleteRead(NDBT_Context* ctx, NDBT_Step* step){
-
- Ndb* pNdb = GETNDB(step);
-
- const NdbDictionary::Table* tab = ctx->getTab();
- NDBT_ResultRow row(*ctx->getTab());
- HugoTransactions tmp(*ctx->getTab());
-
- int a;
- int loops = ctx->getNumLoops();
- const int rows = ctx->getNumRecords();
-
- while (loops--)
- {
- NdbTransaction* pTrans = pNdb->startTransaction();
- NdbOperation* pOp = pTrans->getNdbOperation(tab->getName());
- pOp->deleteTuple();
- tmp.equalForRow(pOp, loops);
-
- // Define attributes to read
- for(a = 0; a<tab->getNoOfColumns(); a++)
- {
- if((row.attributeStore(a) = pOp->getValue(tab->getColumn(a)->getName())) == 0) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
- }
-
- pTrans->execute(Commit);
- pTrans->close();
-
- pTrans = pNdb->startTransaction();
- pOp = pTrans->getNdbOperation(tab->getName());
- pOp->insertTuple();
- tmp.setValues(pOp, loops, 0);
-
- pOp = pTrans->getNdbOperation(tab->getName());
- pOp->deleteTuple();
- tmp.equalForRow(pOp, loops);
- for(a = 0; a<tab->getNoOfColumns(); a++)
- {
- if((row.attributeStore(a) = pOp->getValue(tab->getColumn(a)->getName())) == 0)
- {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
- }
- if (pTrans->execute(Commit) != 0)
- {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- pTrans->close();
- }
-
- return NDBT_OK;
-}
-
-int
-runBug27756(NDBT_Context* ctx, NDBT_Step* step)
-{
-
- Ndb* pNdb = GETNDB(step);
- NdbDictionary::Dictionary * dict = pNdb->getDictionary();
-
- HugoOperations ops(*ctx->getTab());
-
- int loops = ctx->getNumLoops();
- const int rows = ctx->getNumRecords();
-
- Vector<Uint64> copies;
- while (loops--)
- {
- ops.startTransaction(pNdb);
- ops.pkInsertRecord(pNdb, 1, 1);
- ops.execute_NoCommit(pNdb);
-
- NdbTransaction* pTrans = ops.getTransaction();
- NdbOperation* op = pTrans->getNdbOperation(ctx->getTab()->getName());
- op->interpretedUpdateTuple();
- ops.equalForRow(op, 1);
- NdbRecAttr* attr = op->getValue(NdbDictionary::Column::COPY_ROWID);
- ops.execute_NoCommit(pNdb);
-
- copies.push_back(attr->u_64_value());
- ndbout_c("copy at: %llx", copies.back());
- ops.execute_NoCommit(pNdb);
-
- ops.pkDeleteRecord(pNdb, 1, 1);
- ops.execute_NoCommit(pNdb);
-
- if (loops & 1)
- {
- ops.execute_Rollback(pNdb);
- ops.closeTransaction(pNdb);
- }
- else
- {
- ops.execute_Commit(pNdb);
- ops.closeTransaction(pNdb);
- ops.clearTable(pNdb, 100);
- }
- }
-
- for (Uint32 i = 0; i<copies.size(); i++)
- if (copies[i] != copies.back())
- {
- ndbout_c("Memleak detected");
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-int
-runBug28073(NDBT_Context *ctx, NDBT_Step* step)
-{
- int result = NDBT_OK;
- const NdbDictionary::Table *table= ctx->getTab();
- HugoOperations hugoOp1(*table);
- HugoOperations hugoOp2(*table);
- Ndb* pNdb = GETNDB(step);
- int loops = ctx->getNumLoops();
- bool inserted= false;
-
- while (loops--)
- {
- if (!inserted)
- {
- CHECK(hugoOp1.startTransaction(pNdb) == 0);
- CHECK(hugoOp1.pkInsertRecord(pNdb, 1, 1) == 0);
- CHECK(hugoOp1.execute_Commit(pNdb) == 0);
- CHECK(hugoOp1.closeTransaction(pNdb) == 0);
- inserted= 1;
- }
-
- // Use TC hint to hit the same node in both transactions.
- Uint32 key_val= 0;
- const char *key= (const char *)(&key_val);
- CHECK(hugoOp1.startTransaction(pNdb, table, key, 4) == 0);
- CHECK(hugoOp2.startTransaction(pNdb, table, key, 4) == 0);
-
- // First take 2*read lock on the tuple in transaction 1.
- for (Uint32 i= 0; i < 2; i++)
- {
- CHECK(hugoOp1.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Read) == 0);
- CHECK(hugoOp1.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Read) == 0);
- }
- CHECK(hugoOp1.execute_NoCommit(pNdb) == 0);
-
- // Now send ops in two transactions, one batch.
- // First 2*read in transaction 2.
- for (Uint32 i= 0; i < 2; i++)
- {
- CHECK(hugoOp2.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Read) == 0);
- CHECK(hugoOp2.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Read) == 0);
- }
- CHECK(hugoOp2.execute_async_prepare(pNdb, NdbTransaction::NoCommit) == 0);
-
- // Second op an update in transaction 1.
- CHECK(hugoOp1.pkUpdateRecord(pNdb, 1, 1) == 0);
- CHECK(hugoOp1.execute_async_prepare(pNdb, NdbTransaction::Commit) == 0);
-
- // Transaction 1 will now hang waiting on transaction 2 to commit before it
- // can upgrade its read lock to a write lock.
- // With the bug, we get a node failure due to watchdog timeout here.
- CHECK(hugoOp2.wait_async(pNdb) == 0);
-
- // Now commit transaction 2, we should see transaction 1 finish with the
- // update.
- CHECK(hugoOp2.execute_async_prepare(pNdb, NdbTransaction::Commit) == 0);
- CHECK(hugoOp2.wait_async(pNdb) == 0);
- // No error check, as transaction 1 may have terminated already.
- hugoOp1.wait_async(pNdb);
-
- CHECK(hugoOp1.closeTransaction(pNdb) == 0);
- CHECK(hugoOp2.closeTransaction(pNdb) == 0);
- }
-
- return result;
-}
-
-template class Vector<Uint64>;
-
-int
-runBug20535(NDBT_Context* ctx, NDBT_Step* step)
-{
- Uint32 i;
- Ndb* pNdb = GETNDB(step);
- const NdbDictionary::Table * tab = ctx->getTab();
- NdbDictionary::Dictionary * dict = pNdb->getDictionary();
-
- bool null = false;
- for (i = 0; i<tab->getNoOfColumns(); i++)
- {
- if (tab->getColumn(i)->getNullable())
- {
- null = true;
- break;
- }
- }
-
- if (!null)
- return NDBT_OK;
-
- HugoTransactions hugoTrans(* tab);
- hugoTrans.loadTable(pNdb, 1);
-
- NdbTransaction* pTrans = pNdb->startTransaction();
- NdbOperation* pOp = pTrans->getNdbOperation(tab->getName());
- pOp->deleteTuple();
- hugoTrans.equalForRow(pOp, 0);
- if (pTrans->execute(NoCommit) != 0)
- return NDBT_FAILED;
-
- pOp = pTrans->getNdbOperation(tab->getName());
- pOp->insertTuple();
- hugoTrans.equalForRow(pOp, 0);
- for (i = 0; i<tab->getNoOfColumns(); i++)
- {
- if (!tab->getColumn(i)->getPrimaryKey() &&
- !tab->getColumn(i)->getNullable())
- {
- hugoTrans.setValueForAttr(pOp, i, 0, 1);
- }
- }
-
- if (pTrans->execute(Commit) != 0)
- return NDBT_FAILED;
-
- pTrans->close();
-
- pTrans = pNdb->startTransaction();
- pOp = pTrans->getNdbOperation(tab->getName());
- pOp->readTuple();
- hugoTrans.equalForRow(pOp, 0);
- Vector<NdbRecAttr*> values;
- for (i = 0; i<tab->getNoOfColumns(); i++)
- {
- if (!tab->getColumn(i)->getPrimaryKey() &&
- tab->getColumn(i)->getNullable())
- {
- values.push_back(pOp->getValue(i));
- }
- }
-
- if (pTrans->execute(Commit) != 0)
- return NDBT_FAILED;
-
- null = true;
- for (i = 0; i<values.size(); i++)
- {
- if (!values[i]->isNULL())
- {
- null = false;
- ndbout_c("column %s is not NULL", values[i]->getColumn()->getName());
- }
- }
-
- pTrans->close();
-
- if (null)
- return NDBT_OK;
- else
- return NDBT_FAILED;
-}
-
-template class Vector<NdbRecAttr*>;
-
-NDBT_TESTSUITE(testBasic);
-TESTCASE("PkInsert",
- "Verify that we can insert and delete from this table using PK"
- "NOTE! No errors are allowed!" ){
- INITIALIZER(runInsert);
- VERIFIER(runVerifyInsert);
-}
-TESTCASE("PkRead",
- "Verify that we can insert, read and delete from this table using PK"){
- TC_PROPERTY("LockMode", NdbOperation::LM_Read);
- INITIALIZER(runLoadTable);
- STEP(runPkRead);
- FINALIZER(runClearTable);
-}
-TESTCASE("PkDirtyRead",
- "Verify that we can insert, dirty read and delete from this table using PK"){
- TC_PROPERTY("LockMode", NdbOperation::LM_Dirty);
- INITIALIZER(runLoadTable);
- STEP(runPkRead);
- FINALIZER(runClearTable);
-}
-TESTCASE("PkSimpleRead",
- "Verify that we can insert, simple read and delete from this table using PK"){
- TC_PROPERTY("LockMode", NdbOperation::LM_SimpleRead);
- INITIALIZER(runLoadTable);
- STEP(runPkRead);
- FINALIZER(runClearTable);
-}
-TESTCASE("PkUpdate",
- "Verify that we can insert, update and delete from this table using PK"){
- INITIALIZER(runLoadTable);
- STEP(runPkUpdate);
- FINALIZER(runClearTable);
-}
-TESTCASE("PkDelete",
- "Verify that we can delete from this table using PK"){
- INITIALIZER(runLoadTable);
- STEP(runPkDelete);
- FINALIZER(runClearTable);
-}
-TESTCASE("UpdateAndRead",
- "Verify that we can read and update at the same time"){
- INITIALIZER(runLoadTable);
- STEP(runPkRead);
- STEP(runPkRead);
- STEP(runPkRead);
- STEP(runPkUpdate);
- STEP(runPkUpdate);
- STEP(runPkUpdate);
- FINALIZER(runClearTable);
-}
-TESTCASE("PkReadAndLocker",
- "Verify that we can read although there are "\
- " a number of 1 second locks in the table"){
- INITIALIZER(runLoadTable);
- STEP(runPkReadUntilStopped);
- STEP(runLocker);
- FINALIZER(runClearTable);
-}
-TESTCASE("PkReadAndLocker2",
- "Verify that we can read and update although there are "\
- " a number of 1 second locks in the table"){
- INITIALIZER(runLoadTable);
- STEP(runPkReadUntilStopped);
- STEP(runPkReadUntilStopped);
- STEP(runPkReadUntilStopped);
- STEP(runPkReadUntilStopped);
- STEP(runPkReadUntilStopped);
- STEP(runPkReadUntilStopped);
- STEP(runLocker);
- FINALIZER(runClearTable);
-}
-TESTCASE("PkReadUpdateAndLocker",
- "Verify that we can read and update although there are "\
- " a number of 1 second locks in the table"){
- INITIALIZER(runLoadTable);
- STEP(runPkReadUntilStopped);
- STEP(runPkReadUntilStopped);
- STEP(runPkUpdateUntilStopped);
- STEP(runPkUpdateUntilStopped);
- STEP(runLocker);
- FINALIZER(runClearTable);
-}
-TESTCASE("ReadWithLocksAndInserts",
- "TR457: This test is added to verify that an insert of a records "\
- "that is already in the database does not delete the record"){
- INITIALIZER(runLoadTable);
- STEP(runPkReadUntilStopped);
- STEP(runPkReadUntilStopped);
- STEP(runLocker);
- STEP(runInsertUntilStopped);
- FINALIZER(runClearTable);
-}
-TESTCASE("PkInsertTwice",
- "Verify that we can't insert an already inserted record."
- "Error should be returned" ){
- INITIALIZER(runLoadTable);
- STEP(runInsertTwice);
- FINALIZER(runClearTable);
-}
-TESTCASE("NoCommitSleep",
- "Verify what happens when a NoCommit transaction is aborted by "
- "NDB because the application is sleeping" ){
- INITIALIZER(runLoadTable);
- INITIALIZER(runNoCommitSleep);
- FINALIZER(runClearTable2);
-}
-TESTCASE("Commit626",
- "Verify what happens when a Commit transaction is aborted by "
- "NDB because the record does no exist" ){
- INITIALIZER(runClearTable2);
- INITIALIZER(runCommit626);
- FINALIZER(runClearTable2);
-}
-TESTCASE("CommitTry626",
- "Verify what happens when a Commit(TryCommit) \n"
- "transaction is aborted by "
- "NDB because the record does no exist" ){
- INITIALIZER(runClearTable2);
- INITIALIZER(runCommit_TryCommit626);
- FINALIZER(runClearTable2);
-}
-TESTCASE("CommitAsMuch626",
- "Verify what happens when a Commit(CommitAsMuchAsPossible) \n"
- "transaction is aborted by\n"
- "NDB because the record does no exist" ){
- INITIALIZER(runClearTable2);
- INITIALIZER(runCommit_CommitAsMuchAsPossible626);
- FINALIZER(runClearTable2);
-}
-TESTCASE("NoCommit626",
- "Verify what happens when a NoCommit transaction is aborted by "
- "NDB because the record does no exist" ){
- INITIALIZER(runClearTable2);
- INITIALIZER(runNoCommit626);
- FINALIZER(runClearTable2);
-}
-TESTCASE("NoCommitRollback626",
- "Verify what happens when a NoCommit transaction is aborted by "
- "NDB because the record does no exist and then we try to rollback\n"
- "the transaction" ){
- INITIALIZER(runClearTable2);
- INITIALIZER(runNoCommitRollback626);
- FINALIZER(runClearTable2);
-}
-TESTCASE("Commit630",
- "Verify what happens when a Commit transaction is aborted by "
- "NDB because the record already exist" ){
- INITIALIZER(runLoadTable);
- INITIALIZER(runCommit630);
- FINALIZER(runClearTable2);
-}
-TESTCASE("CommitTry630",
- "Verify what happens when a Commit(TryCommit) \n"
- "transaction is aborted by "
- "NDB because the record already exist" ){
- INITIALIZER(runLoadTable);
- INITIALIZER(runCommit_TryCommit630);
- FINALIZER(runClearTable2);
-}
-TESTCASE("CommitAsMuch630",
- "Verify what happens when a Commit(CommitAsMuchAsPossible) \n"
- "transaction is aborted by\n"
- "NDB because the record already exist" ){
- INITIALIZER(runLoadTable);
- INITIALIZER(runCommit_CommitAsMuchAsPossible630);
- FINALIZER(runClearTable2);
-}
-TESTCASE("NoCommit630",
- "Verify what happens when a NoCommit transaction is aborted by "
- "NDB because the record already exist" ){
- INITIALIZER(runLoadTable);
- INITIALIZER(runNoCommit630);
- FINALIZER(runClearTable2);
-}
-TESTCASE("NoCommitRollback630",
- "Verify what happens when a NoCommit transaction is aborted by "
- "NDB because the record already exist and then we try to rollback\n"
- "the transaction" ){
- INITIALIZER(runLoadTable);
- INITIALIZER(runNoCommitRollback630);
- FINALIZER(runClearTable2);
-}
-TESTCASE("NoCommitAndClose",
- "Verify what happens when a NoCommit transaction is closed "
- "without rolling back the transaction " ){
- INITIALIZER(runLoadTable);
- INITIALIZER(runNoCommitAndClose);
- FINALIZER(runClearTable2);
-}
-TESTCASE("RollbackDelete",
- "Test rollback of a no committed delete"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runCheckRollbackDelete);
- FINALIZER(runClearTable2);
-}
-TESTCASE("RollbackUpdate",
- "Test rollback of a no committed update"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runCheckRollbackUpdate);
- FINALIZER(runClearTable2);
-}
-TESTCASE("RollbackDeleteMultiple",
- "Test rollback of 10 non committed delete"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runCheckRollbackDeleteMultiple);
- FINALIZER(runClearTable2);
-}
-TESTCASE("ImplicitRollbackDelete",
- "Test close transaction after a no commited delete\n"
- "this would give an implicit rollback of the delete\n"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runCheckImplicitRollbackDelete);
- FINALIZER(runClearTable2);
-}
-TESTCASE("CommitDelete",
- "Test close transaction after a no commited delete\n"
- "this would give an implicit rollback of the delete\n"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runCheckCommitDelete);
- FINALIZER(runClearTable2);
-}
-TESTCASE("RollbackNothing",
- "Test rollback of nothing"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runRollbackNothing);
- FINALIZER(runClearTable2);
-}
-TESTCASE("MassiveRollback",
- "Test rollback of 4096 operations"){
- INITIALIZER(runClearTable2);
- INITIALIZER(runMassiveRollback);
- FINALIZER(runClearTable2);
-}
-TESTCASE("MassiveRollback2",
- "Test rollback of 4096 operations"){
- INITIALIZER(runClearTable2);
- INITIALIZER(runMassiveRollback2);
- FINALIZER(runClearTable2);
-}
-TESTCASE("MassiveRollback3",
- "Test rollback of 4096 operations"){
- INITIALIZER(runClearTable2);
- STEP(runMassiveRollback3);
- STEP(runMassiveRollback3);
- FINALIZER(runClearTable2);
-}
-TESTCASE("MassiveRollback4",
- "Test rollback of 4096 operations"){
- INITIALIZER(runClearTable2);
- STEP(runMassiveRollback4);
- STEP(runMassiveRollback4);
- FINALIZER(runClearTable2);
-}
-TESTCASE("MassiveTransaction",
- "Test very large insert transaction"){
- INITIALIZER(runLoadTable2);
- FINALIZER(runClearTable2);
-}
-TESTCASE("TupError",
- "Verify what happens when we fill the db" ){
- INITIALIZER(runTupErrors);
-}
-TESTCASE("InsertError", "" ){
- INITIALIZER(runInsertError);
-}
-TESTCASE("InsertError2", "" ){
- INITIALIZER(runInsertError2);
-}
-TESTCASE("Fill",
- "Verify what happens when we fill the db" ){
- INITIALIZER(runFillTable);
- INITIALIZER(runPkRead);
- FINALIZER(runClearTable2);
-}
-TESTCASE("Bug25090",
- "Verify what happens when we fill the db" ){
- STEP(runBug25090);
-}
-TESTCASE("DeleteRead",
- "Verify Delete+Read" ){
- INITIALIZER(runLoadTable);
- INITIALIZER(runDeleteRead);
- FINALIZER(runClearTable2);
-}
-TESTCASE("Bug27756",
- "Verify what happens when we fill the db" ){
- STEP(runBug27756);
-}
-TESTCASE("Bug28073",
- "Infinite loop in lock queue" ){
- STEP(runBug28073);
-}
-TESTCASE("Bug20535",
- "Verify what happens when we fill the db" ){
- STEP(runBug20535);
-}
-NDBT_TESTSUITE_END(testBasic);
-
-#if 0
-TESTCASE("ReadConsistency",
- "Check that a read within a transaction returns the " \
- "same result no matter"){
- STEP(runInsertOne);
- STEP(runReadOne);
- FINALIZER(runClearTable2);
-}
-TESTCASE("Fill",
- "Verify what happens when we fill the db" ){
- INITIALIZER(runFillTable);
- INITIALIZER(runPkRead);
- FINALIZER(runClearTable2);
-}
-#endif
-
-int main(int argc, const char** argv){
- ndb_init();
- return testBasic.execute(argc, argv);
-}
-
-
-
diff --git a/storage/ndb/test/ndbapi/testBasicAsynch.cpp b/storage/ndb/test/ndbapi/testBasicAsynch.cpp
deleted file mode 100644
index 37391550977..00000000000
--- a/storage/ndb/test/ndbapi/testBasicAsynch.cpp
+++ /dev/null
@@ -1,187 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include "NDBT_Test.hpp"
-#include "NDBT_ReturnCodes.h"
-#include "HugoTransactions.hpp"
-#include "HugoAsynchTransactions.hpp"
-#include "UtilTransactions.hpp"
-
-#define GETNDB(ps) ((NDBT_NdbApiStep*)ps)->getNdb()
-
-int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
-
- int records = ctx->getNumRecords();
- int batchSize = ctx->getProperty("BatchSize", 1);
- int transactions = (records / 100) + 1;
- int operations = (records / transactions) + 1;
-
- HugoAsynchTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.loadTableAsynch(GETNDB(step), records, batchSize,
- transactions, operations) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runInsert(NDBT_Context* ctx, NDBT_Step* step){
-
- int records = ctx->getNumRecords();
- int batchSize = ctx->getProperty("BatchSize", 1);
- int transactions = (records / 100) + 1;
- int operations = (records / transactions) + 1;
-
- HugoAsynchTransactions hugoTrans(*ctx->getTab());
- // Insert records, dont allow any
- // errors(except temporary) while inserting
- if (hugoTrans.loadTableAsynch(GETNDB(step), records, batchSize,
- transactions, operations) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runVerifyInsert(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
- int batchSize = ctx->getProperty("BatchSize", 1);
- int transactions = (records / 100) + 1;
- int operations = (records / transactions) + 1;
-
- HugoAsynchTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.pkDelRecordsAsynch(GETNDB(step), records, batchSize,
- transactions, operations) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
- int batchSize = ctx->getProperty("BatchSize", 1);
- int transactions = (records / 100) + 1;
- int operations = (records / transactions) + 1;
-
- HugoAsynchTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.pkDelRecordsAsynch(GETNDB(step), records, batchSize,
- transactions, operations) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runPkDelete(NDBT_Context* ctx, NDBT_Step* step){
-
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int batchSize = ctx->getProperty("BatchSize", 1);
- int transactions = (records / 100) + 1;
- int operations = (records / transactions) + 1;
-
- int i = 0;
- HugoAsynchTransactions hugoTrans(*ctx->getTab());
- while (i<loops) {
- ndbout << i << ": ";
- if (hugoTrans.pkDelRecordsAsynch(GETNDB(step), records, batchSize,
- transactions, operations) != 0){
- return NDBT_FAILED;
- }
- // Load table, don't allow any primary key violations
- if (hugoTrans.loadTableAsynch(GETNDB(step), records, batchSize,
- transactions, operations) != 0){
- return NDBT_FAILED;
- }
- i++;
- }
- return NDBT_OK;
-}
-
-
-int runPkRead(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int batchSize = ctx->getProperty("BatchSize", 1);
- int transactions = (records / 100) + 1;
- int operations = (records / transactions) + 1;
-
- int i = 0;
- HugoAsynchTransactions hugoTrans(*ctx->getTab());
- while (i<loops) {
- ndbout << i << ": ";
- if (hugoTrans.pkReadRecordsAsynch(GETNDB(step), records, batchSize,
- transactions, operations) != NDBT_OK){
- return NDBT_FAILED;
- }
- i++;
- }
- return NDBT_OK;
-}
-
-int runPkUpdate(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int batchSize = ctx->getProperty("BatchSize", 1);
- int transactions = (records / 100) + 1;
- int operations = (records / transactions) + 1;
-
- int i = 0;
- HugoAsynchTransactions hugoTrans(*ctx->getTab());
- while (i<loops) {
- ndbout << i << ": ";
- if (hugoTrans.pkUpdateRecordsAsynch(GETNDB(step), records,
- batchSize, transactions,
- operations) != 0){
- return NDBT_FAILED;
- }
- i++;
- }
- return NDBT_OK;
-}
-
-NDBT_TESTSUITE(testBasicAsynch);
-TESTCASE("PkInsertAsynch",
- "Verify that we can insert and delete from this table using PK"
- " NOTE! No errors are allowed!" ){
- INITIALIZER(runInsert);
- VERIFIER(runVerifyInsert);
-}
-TESTCASE("PkReadAsynch",
- "Verify that we can insert, read and delete from this table"
- " using PK"){
- INITIALIZER(runLoadTable);
- STEP(runPkRead);
- FINALIZER(runClearTable);
-}
-TESTCASE("PkUpdateAsynch",
- "Verify that we can insert, update and delete from this table"
- " using PK"){
- INITIALIZER(runLoadTable);
- STEP(runPkUpdate);
- FINALIZER(runClearTable);
-}
-TESTCASE("PkDeleteAsynch",
- "Verify that we can delete from this table using PK"){
- INITIALIZER(runLoadTable);
- STEP(runPkDelete);
- FINALIZER(runClearTable);
-}
-
-NDBT_TESTSUITE_END(testBasicAsynch);
-
-int main(int argc, const char** argv){
- ndb_init();
- return testBasicAsynch.execute(argc, argv);
-}
-
diff --git a/storage/ndb/test/ndbapi/testBitfield.cpp b/storage/ndb/test/ndbapi/testBitfield.cpp
deleted file mode 100644
index fbc9668a721..00000000000
--- a/storage/ndb/test/ndbapi/testBitfield.cpp
+++ /dev/null
@@ -1,623 +0,0 @@
-/* Copyright (C) 2004, 2008 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-#include <ndb_opts.h>
-#include <NDBT.hpp>
-#include <NdbApi.hpp>
-#include <HugoTransactions.hpp>
-#include <Bitmask.hpp>
-#include <Vector.hpp>
-
-static const char* _dbname = "TEST_DB";
-static int g_loops = 7;
-
-
-NDB_STD_OPTS_VARS;
-
-static struct my_option my_long_options[] =
-{
- NDB_STD_OPTS("ndb_desc"),
- { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
-};
-
-static void usage()
-{
- ndb_std_print_version();
-}
-#if 0
-static my_bool
-get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
- const char *argument)
-{
- return ndb_std_get_one_option(optid, opt, argument ? argument :
- "d:t:O,/tmp/testBitfield.trace");
-}
-#endif
-
-static const NdbDictionary::Table* create_random_table(Ndb*);
-static int transactions(Ndb*, const NdbDictionary::Table* tab);
-static int unique_indexes(Ndb*, const NdbDictionary::Table* tab);
-static int ordered_indexes(Ndb*, const NdbDictionary::Table* tab);
-static int node_restart(Ndb*, const NdbDictionary::Table* tab);
-static int system_restart(Ndb*, const NdbDictionary::Table* tab);
-static int testBitmask();
-
-int
-main(int argc, char** argv){
- NDB_INIT(argv[0]);
- const char *load_default_groups[]= { "mysql_cluster",0 };
- load_defaults("my",load_default_groups,&argc,&argv);
- int ho_error;
-
- if ((ho_error=handle_options(&argc, &argv, my_long_options,
- ndb_std_get_one_option)))
- return NDBT_ProgramExit(NDBT_WRONGARGS);
-
- int res = NDBT_FAILED;
-
- /* Run cluster-independent tests */
- for (int i=0; i<(10*g_loops); i++)
- {
- if (NDBT_OK != (res= testBitmask()))
- return NDBT_ProgramExit(res);
- }
-
- Ndb_cluster_connection con(opt_connect_str);
- if(con.connect(12, 5, 1))
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
-
- Ndb* pNdb;
- pNdb = new Ndb(&con, _dbname);
- pNdb->init();
- while (pNdb->waitUntilReady() != 0);
-
- NdbDictionary::Dictionary * dict = pNdb->getDictionary();
-
- const NdbDictionary::Table* pTab = 0;
- for (int i = 0; i < (argc ? argc : g_loops) ; i++)
- {
- res = NDBT_FAILED;
- if(argc == 0)
- {
- pTab = create_random_table(pNdb);
- }
- else
- {
- dict->dropTable(argv[i]);
- NDBT_Tables::createTable(pNdb, argv[i]);
- pTab = dict->getTable(argv[i]);
- }
-
- if (pTab == 0)
- {
- ndbout << "Failed to create table" << endl;
- ndbout << dict->getNdbError() << endl;
- break;
- }
-
- if(transactions(pNdb, pTab))
- break;
-
- if(unique_indexes(pNdb, pTab))
- break;
-
- if(ordered_indexes(pNdb, pTab))
- break;
-
- if(node_restart(pNdb, pTab))
- break;
-
- if(system_restart(pNdb, pTab))
- break;
-
- dict->dropTable(pTab->getName());
- res = NDBT_OK;
- }
-
- if(res != NDBT_OK && pTab)
- {
- dict->dropTable(pTab->getName());
- }
-
- delete pNdb;
- return NDBT_ProgramExit(res);
-}
-
-static
-const NdbDictionary::Table*
-create_random_table(Ndb* pNdb)
-{
- do {
- NdbDictionary::Table tab;
- Uint32 cols = 1 + (rand() % (NDB_MAX_ATTRIBUTES_IN_TABLE - 1));
- Uint32 length = 4090;
-
- BaseString name;
- name.assfmt("TAB_%d", rand() & 65535);
- tab.setName(name.c_str());
- for(Uint32 i = 0; i<cols && length > 2; i++)
- {
- NdbDictionary::Column col;
- name.assfmt("COL_%d", i);
- col.setName(name.c_str());
- if(i == 0 || i == 1)
- {
- col.setType(NdbDictionary::Column::Unsigned);
- col.setLength(1);
- col.setNullable(false);
- col.setPrimaryKey(i == 0);
- tab.addColumn(col);
- continue;
- }
-
- col.setType(NdbDictionary::Column::Bit);
-
- Uint32 len = 1 + (rand() % (length - 1));
- col.setLength(len); length -= len;
- int nullable = (rand() >> 16) & 1;
- col.setNullable(nullable); length -= nullable;
- col.setPrimaryKey(false);
- tab.addColumn(col);
- }
-
- pNdb->getDictionary()->dropTable(tab.getName());
- if(pNdb->getDictionary()->createTable(tab) == 0)
- {
- ndbout << (NDBT_Table&)tab << endl;
- return pNdb->getDictionary()->getTable(tab.getName());
- }
- } while(0);
- return 0;
-}
-
-static
-int
-transactions(Ndb* pNdb, const NdbDictionary::Table* tab)
-{
- int i = 0;
- HugoTransactions trans(* tab);
- i |= trans.loadTable(pNdb, 1000);
- i |= trans.pkReadRecords(pNdb, 1000, 13);
- i |= trans.scanReadRecords(pNdb, 1000, 25);
- i |= trans.pkUpdateRecords(pNdb, 1000, 37);
- i |= trans.scanUpdateRecords(pNdb, 1000, 25);
- i |= trans.pkDelRecords(pNdb, 500, 23);
- i |= trans.clearTable(pNdb);
- return i;
-}
-
-static
-int
-unique_indexes(Ndb* pNdb, const NdbDictionary::Table* tab)
-{
- return 0;
-}
-
-static
-int
-ordered_indexes(Ndb* pNdb, const NdbDictionary::Table* tab)
-{
- return 0;
-}
-
-static
-int
-node_restart(Ndb* pNdb, const NdbDictionary::Table* tab)
-{
- return 0;
-}
-
-static
-int
-system_restart(Ndb* pNdb, const NdbDictionary::Table* tab)
-{
- return 0;
-}
-
-/* Note : folowing classes test functionality of storage/ndb/src/common/util/Bitmask.cpp
- * and were originally defined there.
- * Set BITMASK_DEBUG to 1 to get more test debugging info.
- */
-#define BITMASK_DEBUG 0
-
-static
-bool cmp(const Uint32 b1[], const Uint32 b2[], Uint32 len)
-{
- Uint32 sz32 = (len + 31) >> 5;
- for(Uint32 i = 0; i<len; i++)
- {
- if(BitmaskImpl::get(sz32, b1, i) ^ BitmaskImpl::get(sz32, b2, i))
- return false;
- }
- return true;
-}
-
-static
-void print(const Uint32 src[], Uint32 len, Uint32 pos = 0)
-{
- printf("b'");
- for(unsigned i = 0; i<len; i++)
- {
- if(BitmaskImpl::get((pos + len + 31) >> 5, src, i+pos))
- printf("1");
- else
- printf("0");
- if((i & 31) == 31)
- printf(" ");
- }
-}
-
-static int lrand()
-{
- return rand();
-}
-
-static
-void rand(Uint32 dst[], Uint32 len)
-{
- for(Uint32 i = 0; i<len; i++)
- BitmaskImpl::set((len + 31) >> 5, dst, i, (lrand() % 1000) > 500);
-}
-
-static
-int checkNoTramplingGetSetField(const Uint32 totalTests)
-{
- const Uint32 numWords= 67;
- const Uint32 maxBitsToCopy= (numWords * 32);
- Uint32 sourceBuf[numWords];
- Uint32 targetBuf[numWords];
-
- ndbout << "Testing : Bitmask NoTrampling\n";
-
- memset(sourceBuf, 0x00, (numWords*4));
-
- for (Uint32 test=0; test<totalTests; test++)
- {
- /* Always copy at least 1 bit */
- Uint32 srcStart= rand() % (maxBitsToCopy -1);
- Uint32 length= (rand() % ((maxBitsToCopy -1) - srcStart)) + 1;
-
- if (BITMASK_DEBUG)
- ndbout << "Testing start %u, length %u \n"
- << srcStart
- << length;
- // Set target to all ones.
- memset(targetBuf, 0xff, (numWords*4));
-
- BitmaskImpl::getField(numWords, sourceBuf, srcStart, length, targetBuf);
-
- // Check that there is no trampling
- Uint32 firstUntrampledWord= (length + 31)/32;
-
- for (Uint32 word=0; word< numWords; word++)
- {
- Uint32 targetWord= targetBuf[word];
- if (BITMASK_DEBUG)
- ndbout << "word=%d, targetWord=%u, firstUntrampledWord..=%u"
- << word << targetWord << firstUntrampledWord;
-
- if (! (word < firstUntrampledWord) ?
- (targetWord == 0) :
- (targetWord == 0xffffffff))
- {
- ndbout << "Notrampling getField failed for srcStart "
- << srcStart
- << " length " << length
- << " at word " << word << "\n";
- ndbout << "word=%d, targetWord=%u, firstUntrampledWord..=%u"
- << word << targetWord << firstUntrampledWord;
- return -1;
- }
-
- }
-
- /* Set target back to all ones. */
- memset(targetBuf, 0xff, (numWords*4));
-
- BitmaskImpl::setField(numWords, targetBuf, srcStart, length, sourceBuf);
-
- /* Check we've got all ones, with zeros only where expected */
- for (Uint32 word=0; word< numWords; word++)
- {
- Uint32 targetWord= targetBuf[word];
-
- for (Uint32 bit=0; bit< 32; bit++)
- {
- Uint32 bitNum= (word << 5) + bit;
- bool expectedValue= !((bitNum >= srcStart) &&
- (bitNum < (srcStart + length)));
- bool actualValue= (((targetWord >> bit) & 1) == 1);
- if (BITMASK_DEBUG)
- ndbout << "bitNum=%u expectedValue=%u, actual value=%u"
- << bitNum << expectedValue << actualValue;
-
- if (actualValue != expectedValue)
- {
- ndbout << "Notrampling setField failed for srcStart "
- << srcStart
- << " length " << length
- << " at word " << word << " bit " << bit << "\n";
- ndbout << "bitNum=%u expectedValue=%u, actual value=%u"
- << bitNum << expectedValue << actualValue;
- return -1;
- }
- }
- }
-
- }
-
- return 0;
-}
-
-static
-int simple(int pos, int size)
-{
- ndbout << "Testing : Bitmask simple pos: " << pos << " size: " << size << "\n";
- Vector<Uint32> _mask;
- Vector<Uint32> _src;
- Vector<Uint32> _dst;
- Uint32 sz32 = (size + pos + 32) >> 5;
- const Uint32 sz = 4 * sz32;
-
- Uint32 zero = 0;
- _mask.fill(sz32+1, zero);
- _src.fill(sz32+1, zero);
- _dst.fill(sz32+1, zero);
-
- Uint32 * src = _src.getBase();
- Uint32 * dst = _dst.getBase();
- Uint32 * mask = _mask.getBase();
-
- memset(src, 0x0, sz);
- memset(dst, 0x0, sz);
- memset(mask, 0xFF, sz);
- rand(src, size);
- BitmaskImpl::setField(sz32, mask, pos, size, src);
- BitmaskImpl::getField(sz32, mask, pos, size, dst);
- if (BITMASK_DEBUG)
- {
- printf("src: "); print(src, size+31); printf("\n");
- printf("msk: "); print(mask, (sz32 << 5) + 31); printf("\n");
- printf("dst: "); print(dst, size+31); printf("\n");
- }
- return (cmp(src, dst, size+31)?0 : -1);
-};
-
-struct Alloc
-{
- Uint32 pos;
- Uint32 size;
- Vector<Uint32> data;
-};
-
-static
-int
-testRanges(Uint32 bitmask_size)
-{
- Vector<Alloc> alloc_list;
- bitmask_size = (bitmask_size + 31) & ~31;
- Uint32 sz32 = (bitmask_size >> 5);
- Vector<Uint32> alloc_mask;
- Vector<Uint32> test_mask;
-
- ndbout_c("Testing : Bitmask ranges for bitmask of size %d", bitmask_size);
- Uint32 zero = 0;
- alloc_mask.fill(sz32, zero);
- test_mask.fill(sz32, zero);
-
- /* Loop a number of times, setting and clearing bits in the mask
- * and tracking the modifications in a separate structure.
- * Check that both structures remain in sync
- */
- for(int i = 0; i<5000; i++)
- {
- Vector<Uint32> tmp;
- tmp.fill(sz32, zero);
-
- Uint32 pos = lrand() % (bitmask_size - 1);
- Uint32 free = 0;
- if(BitmaskImpl::get(sz32, alloc_mask.getBase(), pos))
- {
- // Bit was allocated
- // 1) Look up allocation
- // 2) Check data
- // 3) free it
- size_t j;
- Uint32 min, max;
- for(j = 0; j<alloc_list.size(); j++)
- {
- min = alloc_list[j].pos;
- max = min + alloc_list[j].size;
- if(pos >= min && pos < max)
- {
- break;
- }
- }
- if (! ((pos >= min) && (pos < max)))
- {
- printf("Failed with pos %u, min %u, max %u\n",
- pos, min, max);
- return -1;
- }
- BitmaskImpl::getField(sz32, test_mask.getBase(), min, max-min,
- tmp.getBase());
- if(BITMASK_DEBUG)
- {
- printf("freeing [ %d %d ]", min, max);
- printf("- mask: ");
- print(tmp.getBase(), max - min);
-
- printf(" save: ");
- size_t k;
- Alloc& a = alloc_list[j];
- for(k = 0; k<a.data.size(); k++)
- printf("%.8x ", a.data[k]);
- printf("\n");
- }
- if(!cmp(tmp.getBase(), alloc_list[j].data.getBase(), max - min))
- {
- return -1;
- }
- while(min < max)
- BitmaskImpl::clear(sz32, alloc_mask.getBase(), min++);
- alloc_list.erase(j);
- }
- else
- {
- Vector<Uint32> tmp;
- tmp.fill(sz32, zero);
-
- // Bit was free
- // 1) Check how much space is avaiable
- // 2) Create new allocation of lrandom size
- // 3) Fill data with lrandom data
- // 4) Update alloc mask
- while(pos+free < bitmask_size &&
- !BitmaskImpl::get(sz32, alloc_mask.getBase(), pos+free))
- free++;
-
- Uint32 sz =
- (free <= 64 && ((lrand() % 100) > 80)) ? free : (lrand() % free);
- sz = sz ? sz : 1;
- sz = pos + sz == bitmask_size ? sz - 1 : sz;
- Alloc a;
- a.pos = pos;
- a.size = sz;
- a.data.fill(((sz+31)>> 5)-1, zero);
- if(BITMASK_DEBUG)
- printf("pos %d -> alloc [ %d %d ]", pos, pos, pos+sz);
- for(size_t j = 0; j<sz; j++)
- {
- BitmaskImpl::set(sz32, alloc_mask.getBase(), pos+j);
- if((lrand() % 1000) > 500)
- BitmaskImpl::set((sz + 31) >> 5, a.data.getBase(), j);
- }
- if(BITMASK_DEBUG)
- {
- printf("- mask: ");
- print(a.data.getBase(), sz);
- printf("\n");
- }
- BitmaskImpl::setField(sz32, test_mask.getBase(), pos, sz,
- a.data.getBase());
- alloc_list.push_back(a);
- }
- }
-
-#define NDB_BM_SUPPORT_RANGE
-#ifdef NDB_BM_SUPPORT_RANGE
- for(Uint32 i = 0; i<1000; i++)
- {
- Uint32 sz32 = 10+rand() % 100;
- Uint32 zero = 0;
- Vector<Uint32> map;
- map.fill(sz32, zero);
-
- Uint32 sz = 32 * sz32;
- Uint32 start = (rand() % sz);
- Uint32 stop = start + ((rand() % (sz - start)) & 0xFFFFFFFF);
-
- Vector<Uint32> check;
- check.fill(sz32, zero);
-
- /* Verify range setting method works correctly */
- for(Uint32 j = 0; j<sz; j++)
- {
- bool expect = (j >= start && j<stop);
- if(expect)
- BitmaskImpl::set(sz32, check.getBase(), j);
- }
-
- BitmaskImpl::set_range(sz32, map.getBase(), start, stop);
- if (!BitmaskImpl::equal(sz32, map.getBase(), check.getBase()))
- {
- ndbout_c(" FAIL 1 sz: %d [ %d %d ]", sz, start, stop);
- printf("check: ");
- for(Uint32 j = 0; j<sz32; j++)
- printf("%.8x ", check[j]);
- printf("\n");
-
- printf("map : ");
- for(Uint32 j = 0; j<sz32; j++)
- printf("%.8x ", map[j]);
- printf("\n");
- return -1;
- }
-
- map.clear();
- check.clear();
-
- /* Verify range clearing method works correctly */
- Uint32 one = ~(Uint32)0;
- map.fill(sz32, one);
- check.fill(sz32, one);
-
- for(Uint32 j = 0; j<sz; j++)
- {
- bool expect = (j >= start && j<stop);
- if(expect)
- BitmaskImpl::clear(sz32, check.getBase(), j);
- }
-
- BitmaskImpl::clear_range(sz32, map.getBase(), start, stop);
- if (!BitmaskImpl::equal(sz32, map.getBase(), check.getBase()))
- {
- ndbout_c(" FAIL 2 sz: %d [ %d %d ]", sz, start, stop);
- printf("check: ");
- for(Uint32 j = 0; j<sz32; j++)
- printf("%.8x ", check[j]);
- printf("\n");
-
- printf("map : ");
- for(Uint32 j = 0; j<sz32; j++)
- printf("%.8x ", map[j]);
- printf("\n");
- return -1;
- }
- }
-#endif
-
- return 0;
-}
-
-static
-int
-testBitmask()
-{
- /* Some testcases from storage/ndb/src/common/util/Bitmask.cpp */
- int res= 0;
-
- if ((res= checkNoTramplingGetSetField(100 /* totalTests */)) != 0)
- return res;
-
- if ((res= simple(rand() % 33, // position
- (rand() % 63)+1) // size
- ) != 0)
- return res;
-
- if ((res= testRanges(1+(rand() % 1000) // bitmask size
- )) != 0)
- return res;
-
- return 0;
-}
-
-template class Vector<Alloc>;
-template class Vector<Uint32>;
diff --git a/storage/ndb/test/ndbapi/testBlobs.cpp b/storage/ndb/test/ndbapi/testBlobs.cpp
deleted file mode 100644
index 1a2e04f8b54..00000000000
--- a/storage/ndb/test/ndbapi/testBlobs.cpp
+++ /dev/null
@@ -1,2230 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-/*
- * testBlobs
- */
-
-#include <ndb_global.h>
-#include <NdbMain.h>
-#include <NdbOut.hpp>
-#include <NdbTest.hpp>
-#include <NdbTick.h>
-
-struct Bcol {
- bool m_nullable;
- unsigned m_inline;
- unsigned m_partsize;
- unsigned m_stripe;
- char m_btname[200];
- Bcol(bool a, unsigned b, unsigned c, unsigned d) :
- m_nullable(a),
- m_inline(b),
- m_partsize(c),
- m_stripe(d)
- {}
-};
-
-struct Opt {
- unsigned m_batch;
- bool m_core;
- bool m_dbg;
- bool m_dbgall;
- const char* m_dbug;
- bool m_fac;
- bool m_full;
- unsigned m_loop;
- unsigned m_parts;
- unsigned m_rows;
- unsigned m_seed;
- const char* m_skip;
- const char* m_test;
- // metadata
- const char* m_tname;
- const char* m_x1name; // hash index
- const char* m_x2name; // ordered index
- unsigned m_pk1off;
- unsigned m_pk2len;
- bool m_oneblob;
- Bcol m_blob1;
- Bcol m_blob2;
- // perf
- const char* m_tnameperf;
- unsigned m_rowsperf;
- // bugs
- int m_bug;
- int (*m_bugtest)();
- Opt() :
- m_batch(7),
- m_core(false),
- m_dbg(false),
- m_dbgall(false),
- m_dbug(0),
- m_fac(false),
- m_full(false),
- m_loop(1),
- m_parts(10),
- m_rows(100),
- m_seed(0),
- m_skip(0),
- m_test(0),
- // metadata
- m_tname("TBLOB1"),
- m_x1name("TBLOB1X1"),
- m_x2name("TBLOB1X2"),
- m_pk1off(0x12340000),
- m_pk2len(55),
- m_oneblob(false),
- m_blob1(false, 7, 1137, 10),
- m_blob2(true, 99, 55, 1),
- // perf
- m_tnameperf("TBLOB2"),
- m_rowsperf(10000),
- // bugs
- m_bug(0),
- m_bugtest(0) {
- }
-};
-
-static const unsigned g_max_pk2len = 256;
-
-static void
-printusage()
-{
- Opt d;
- ndbout
- << "usage: testBlobs options [default/max]" << endl
- << " -batch N number of pk ops in batch [" << d.m_batch << "]" << endl
- << " -core dump core on error" << endl
- << " -dbg print debug" << endl
- << " -dbgall print also NDB API debug (if compiled in)" << endl
- << " -dbug opt dbug options" << endl
- << " -fac fetch across commit in scan delete [" << d.m_fac << "]" << endl
- << " -full read/write only full blob values" << endl
- << " -loop N loop N times 0=forever [" << d.m_loop << "]" << endl
- << " -parts N max parts in blob value [" << d.m_parts << "]" << endl
- << " -rows N number of rows [" << d.m_rows << "]" << endl
- << " -rowsperf N rows for performace test [" << d.m_rowsperf << "]" << endl
- << " -seed N random seed 0=loop number [" << d.m_seed << "]" << endl
- << " -skip xxx skip given tests (see list) [no tests]" << endl
- << " -test xxx only given tests (see list) [all tests]" << endl
- << "metadata" << endl
- << " -pk2len N length of PK2 [" << d.m_pk2len << "/" << g_max_pk2len <<"]" << endl
- << " -oneblob only 1 blob attribute [default 2]" << endl
- << "test cases for test/skip" << endl
- << " k primary key ops" << endl
- << " i hash index ops" << endl
- << " s table scans" << endl
- << " r ordered index scans" << endl
- << " p performance test" << endl
- << "operations for test/skip" << endl
- << " u update existing blob value" << endl
- << " n normal insert and update" << endl
- << " w insert and update using writeTuple" << endl
- << "blob operation styles for test/skip" << endl
- << " 0 getValue / setValue" << endl
- << " 1 setActiveHook" << endl
- << " 2 readData / writeData" << endl
- << "example: -test kn0 (need all 3 parts)" << endl
- << "bug tests" << endl
- << " -bug 4088 ndb api hang with mixed ops on index table" << endl
- << " -bug 27018 middle partial part write clobbers rest of part" << endl
- << " -bug 27370 Potential inconsistent blob reads for ReadCommitted reads" << endl
- ;
-}
-
-static Opt g_opt;
-
-static bool
-testcase(char x)
-{
- if (x < 10)
- x += '0';
- return
- (g_opt.m_test == 0 || strchr(g_opt.m_test, x) != 0) &&
- (g_opt.m_skip == 0 || strchr(g_opt.m_skip, x) == 0);
-}
-
-static Ndb_cluster_connection* g_ncc = 0;
-static Ndb* g_ndb = 0;
-static NdbDictionary::Dictionary* g_dic = 0;
-static NdbConnection* g_con = 0;
-static NdbOperation* g_opr = 0;
-static NdbIndexOperation* g_opx = 0;
-static NdbScanOperation* g_ops = 0;
-static NdbBlob* g_bh1 = 0;
-static NdbBlob* g_bh2 = 0;
-static bool g_printerror = true;
-static unsigned g_loop = 0;
-
-static void
-printerror(int line, const char* msg)
-{
- ndbout << "line " << line << " FAIL " << msg << endl;
- if (! g_printerror) {
- return;
- }
- if (g_ndb != 0 && g_ndb->getNdbError().code != 0) {
- ndbout << "ndb: " << g_ndb->getNdbError() << endl;
- }
- if (g_dic != 0 && g_dic->getNdbError().code != 0) {
- ndbout << "dic: " << g_dic->getNdbError() << endl;
- }
- if (g_con != 0 && g_con->getNdbError().code != 0) {
- ndbout << "con: " << g_con->getNdbError() << endl;
- if (g_opr != 0 && g_opr->getNdbError().code != 0) {
- ndbout << "opr: table=" << g_opr->getTableName() << " " << g_opr->getNdbError() << endl;
- }
- if (g_opx != 0 && g_opx->getNdbError().code != 0) {
- ndbout << "opx: table=" << g_opx->getTableName() << " " << g_opx->getNdbError() << endl;
- }
- if (g_ops != 0 && g_ops->getNdbError().code != 0) {
- ndbout << "ops: table=" << g_ops->getTableName() << " " << g_ops->getNdbError() << endl;
- }
- NdbOperation* ope = g_con->getNdbErrorOperation();
- if (ope != 0 && ope->getNdbError().code != 0) {
- if (ope != g_opr && ope != g_opx && ope != g_ops)
- ndbout << "ope: table=" << ope->getTableName() << " " << ope->getNdbError() << endl;
- }
- }
- if (g_bh1 != 0 && g_bh1->getNdbError().code != 0) {
- ndbout << "bh1: " << g_bh1->getNdbError() << endl;
- }
- if (g_bh2 != 0 && g_bh2->getNdbError().code != 0) {
- ndbout << "bh2: " << g_bh2->getNdbError() << endl;
- }
- if (g_opt.m_core) {
- abort();
- }
- g_printerror = false;
-}
-
-#define CHK(x) \
- do { \
- if (x) break; \
- printerror(__LINE__, #x); return -1; \
- } while (0)
-#define DBG(x) \
- do { \
- if (! g_opt.m_dbg) break; \
- ndbout << "line " << __LINE__ << " " << x << endl; \
- } while (0)
-
-static int
-dropTable()
-{
- NdbDictionary::Table tab(g_opt.m_tname);
- if (g_dic->getTable(g_opt.m_tname) != 0)
- CHK(g_dic->dropTable(g_opt.m_tname) == 0);
- return 0;
-}
-
-static int
-createTable()
-{
- NdbDictionary::Table tab(g_opt.m_tname);
- tab.setLogging(false);
- // col PK1 - Uint32
- { NdbDictionary::Column col("PK1");
- col.setType(NdbDictionary::Column::Unsigned);
- col.setPrimaryKey(true);
- tab.addColumn(col);
- }
- // col BL1 - Blob not-nullable
- { NdbDictionary::Column col("BL1");
- const Bcol& b = g_opt.m_blob1;
- col.setType(NdbDictionary::Column::Blob);
- col.setInlineSize(b.m_inline);
- col.setPartSize(b.m_partsize);
- col.setStripeSize(b.m_stripe);
- tab.addColumn(col);
- }
- // col PK2 - Char[55]
- if (g_opt.m_pk2len != 0)
- { NdbDictionary::Column col("PK2");
- col.setType(NdbDictionary::Column::Char);
- col.setLength(g_opt.m_pk2len);
- col.setPrimaryKey(true);
- tab.addColumn(col);
- }
- // col BL2 - Text nullable
- if (! g_opt.m_oneblob)
- { NdbDictionary::Column col("BL2");
- const Bcol& b = g_opt.m_blob2;
- col.setType(NdbDictionary::Column::Text);
- col.setNullable(true);
- col.setInlineSize(b.m_inline);
- col.setPartSize(b.m_partsize);
- col.setStripeSize(b.m_stripe);
- tab.addColumn(col);
- }
- // create table
- CHK(g_dic->createTable(tab) == 0);
- // unique hash index on PK2
- if (g_opt.m_pk2len != 0)
- { NdbDictionary::Index idx(g_opt.m_x1name);
- idx.setType(NdbDictionary::Index::UniqueHashIndex);
- idx.setLogging(false);
- idx.setTable(g_opt.m_tname);
- idx.addColumnName("PK2");
- CHK(g_dic->createIndex(idx) == 0);
- }
- // ordered index on PK2
- if (g_opt.m_pk2len != 0)
- { NdbDictionary::Index idx(g_opt.m_x2name);
- idx.setType(NdbDictionary::Index::OrderedIndex);
- idx.setLogging(false);
- idx.setTable(g_opt.m_tname);
- idx.addColumnName("PK2");
- CHK(g_dic->createIndex(idx) == 0);
- }
- return 0;
-}
-
-// tuples
-
-struct Bval {
- char* m_val;
- unsigned m_len;
- char* m_buf; // read/write buffer
- unsigned m_buflen;
- int m_error_code; // for testing expected error code
- Bval() :
- m_val(0),
- m_len(0),
- m_buf(0),
- m_buflen(0),
- m_error_code(0)
- {}
- ~Bval() { delete [] m_val; delete [] m_buf; }
- void alloc(unsigned buflen) {
- m_buflen = buflen;
- delete [] m_buf;
- m_buf = new char [m_buflen];
- trash();
- }
- void copyfrom(const Bval& v) {
- m_len = v.m_len;
- delete [] m_val;
- if (v.m_val == 0)
- m_val = 0;
- else
- m_val = (char*)memcpy(new char [m_len], v.m_val, m_len);
- }
- void trash() const {
- assert(m_buf != 0);
- memset(m_buf, 'x', m_buflen);
- }
-private:
- Bval(const Bval&);
- Bval& operator=(const Bval&);
-};
-
-struct Tup {
- bool m_exists; // exists in table
- Uint32 m_pk1; // primary keys concatenated like keyinfo
- char m_pk2[g_max_pk2len + 1];
- Bval m_blob1;
- Bval m_blob2;
- Tup() :
- m_exists(false)
- {}
- ~Tup() { }
- // alloc buffers of max size
- void alloc() {
- m_blob1.alloc(g_opt.m_blob1.m_inline + g_opt.m_blob1.m_partsize * g_opt.m_parts);
- m_blob2.alloc(g_opt.m_blob2.m_inline + g_opt.m_blob2.m_partsize * g_opt.m_parts);
- }
- void copyfrom(const Tup& tup) {
- assert(m_pk1 == tup.m_pk1);
- m_blob1.copyfrom(tup.m_blob1);
- m_blob2.copyfrom(tup.m_blob2);
- }
-private:
- Tup(const Tup&);
- Tup& operator=(const Tup&);
-};
-
-static Tup* g_tups;
-
-static unsigned
-urandom(unsigned n)
-{
- return n == 0 ? 0 : random() % n;
-}
-
-static void
-calcBval(const Bcol& b, Bval& v, bool keepsize)
-{
- if (b.m_nullable && urandom(10) == 0) {
- v.m_len = 0;
- delete [] v.m_val;
- v.m_val = 0;
- v.m_buf = new char [1];
- } else {
- if (keepsize && v.m_val != 0)
- ;
- else if (urandom(10) == 0)
- v.m_len = urandom(b.m_inline);
- else
- v.m_len = urandom(b.m_inline + g_opt.m_parts * b.m_partsize + 1);
- delete [] v.m_val;
- v.m_val = new char [v.m_len + 1];
- for (unsigned i = 0; i < v.m_len; i++)
- v.m_val[i] = 'a' + urandom(25);
- v.m_val[v.m_len] = 0;
- v.m_buf = new char [v.m_len];
- }
- v.m_buflen = v.m_len;
- v.trash();
-}
-
-static void
-calcBval(Tup& tup, bool keepsize)
-{
- calcBval(g_opt.m_blob1, tup.m_blob1, keepsize);
- if (! g_opt.m_oneblob)
- calcBval(g_opt.m_blob2, tup.m_blob2, keepsize);
-}
-
-static void
-calcTups(bool keepsize)
-{
- for (unsigned k = 0; k < g_opt.m_rows; k++) {
- Tup& tup = g_tups[k];
- tup.m_pk1 = g_opt.m_pk1off + k;
- for (unsigned i = 0, n = k; i < g_opt.m_pk2len; i++) {
- if (n != 0) {
- tup.m_pk2[i] = '0' + n % 10;
- n = n / 10;
- } else {
- tup.m_pk2[i] = 'a' + i % 26;
- }
- }
- calcBval(tup, keepsize);
- }
-}
-
-// blob handle ops
-
-static int
-getBlobHandles(NdbOperation* opr)
-{
- CHK((g_bh1 = opr->getBlobHandle("BL1")) != 0);
- if (! g_opt.m_oneblob)
- CHK((g_bh2 = opr->getBlobHandle("BL2")) != 0);
- return 0;
-}
-
-static int
-getBlobHandles(NdbIndexOperation* opx)
-{
- CHK((g_bh1 = opx->getBlobHandle("BL1")) != 0);
- if (! g_opt.m_oneblob)
- CHK((g_bh2 = opx->getBlobHandle("BL2")) != 0);
- return 0;
-}
-
-static int
-getBlobHandles(NdbScanOperation* ops)
-{
- CHK((g_bh1 = ops->getBlobHandle("BL1")) != 0);
- if (! g_opt.m_oneblob)
- CHK((g_bh2 = ops->getBlobHandle("BL2")) != 0);
- return 0;
-}
-
-static int
-getBlobLength(NdbBlob* h, unsigned& len)
-{
- Uint64 len2 = (unsigned)-1;
- CHK(h->getLength(len2) == 0);
- len = (unsigned)len2;
- assert(len == len2);
- bool isNull;
- CHK(h->getNull(isNull) == 0);
- DBG("getBlobLength " << h->getColumn()->getName() << " len=" << len << " null=" << isNull);
- return 0;
-}
-
-// setValue / getValue
-
-static int
-setBlobValue(NdbBlob* h, const Bval& v, int error_code = 0)
-{
- bool null = (v.m_val == 0);
- bool isNull;
- unsigned len;
- DBG("setValue " << h->getColumn()->getName() << " len=" << v.m_len << " null=" << null);
- if (null) {
- CHK(h->setNull() == 0 || h->getNdbError().code == error_code);
- if (error_code)
- return 0;
- isNull = false;
- CHK(h->getNull(isNull) == 0 && isNull == true);
- CHK(getBlobLength(h, len) == 0 && len == 0);
- } else {
- CHK(h->setValue(v.m_val, v.m_len) == 0 || h->getNdbError().code == error_code);
- if (error_code)
- return 0;
- CHK(h->getNull(isNull) == 0 && isNull == false);
- CHK(getBlobLength(h, len) == 0 && len == v.m_len);
- }
- return 0;
-}
-
-static int
-setBlobValue(const Tup& tup, int error_code = 0)
-{
- CHK(setBlobValue(g_bh1, tup.m_blob1, error_code) == 0);
- if (! g_opt.m_oneblob)
- CHK(setBlobValue(g_bh2, tup.m_blob2, error_code) == 0);
- return 0;
-}
-
-static int
-getBlobValue(NdbBlob* h, const Bval& v)
-{
- bool null = (v.m_val == 0);
- DBG("getValue " << h->getColumn()->getName() << " buflen=" << v.m_buflen);
- CHK(h->getValue(v.m_buf, v.m_buflen) == 0);
- return 0;
-}
-
-static int
-getBlobValue(const Tup& tup)
-{
- CHK(getBlobValue(g_bh1, tup.m_blob1) == 0);
- if (! g_opt.m_oneblob)
- CHK(getBlobValue(g_bh2, tup.m_blob2) == 0);
- return 0;
-}
-
-static int
-verifyBlobValue(NdbBlob* h, const Bval& v)
-{
- bool null = (v.m_val == 0);
- bool isNull;
- unsigned len;
- if (null) {
- isNull = false;
- CHK(h->getNull(isNull) == 0 && isNull == true);
- CHK(getBlobLength(h, len) == 0 && len == 0);
- } else {
- isNull = true;
- CHK(h->getNull(isNull) == 0 && isNull == false);
- CHK(getBlobLength(h, len) == 0 && len == v.m_len);
- for (unsigned i = 0; i < v.m_len; i++)
- CHK(v.m_val[i] == v.m_buf[i]);
- }
- return 0;
-}
-
-static int
-verifyBlobValue(const Tup& tup)
-{
- CHK(verifyBlobValue(g_bh1, tup.m_blob1) == 0);
- if (! g_opt.m_oneblob)
- CHK(verifyBlobValue(g_bh2, tup.m_blob2) == 0);
- return 0;
-}
-
-// readData / writeData
-
-static int
-writeBlobData(NdbBlob* h, const Bval& v)
-{
- bool null = (v.m_val == 0);
- bool isNull;
- unsigned len;
- DBG("write " << h->getColumn()->getName() << " len=" << v.m_len << " null=" << null);
- int error_code = v.m_error_code;
- if (null) {
- CHK(h->setNull() == 0 || h->getNdbError().code == error_code);
- if (error_code)
- return 0;
- isNull = false;
- CHK(h->getNull(isNull) == 0 && isNull == true);
- CHK(getBlobLength(h, len) == 0 && len == 0);
- } else {
- CHK(h->truncate(v.m_len) == 0 || h->getNdbError().code == error_code);
- if (error_code)
- return 0;
- unsigned n = 0;
- do {
- unsigned m = g_opt.m_full ? v.m_len : urandom(v.m_len + 1);
- if (m > v.m_len - n)
- m = v.m_len - n;
- DBG("write pos=" << n << " cnt=" << m);
- CHK(h->writeData(v.m_val + n, m) == 0);
- n += m;
- } while (n < v.m_len);
- assert(n == v.m_len);
- isNull = true;
- CHK(h->getNull(isNull) == 0 && isNull == false);
- CHK(getBlobLength(h, len) == 0 && len == v.m_len);
- }
- return 0;
-}
-
-static int
-writeBlobData(Tup& tup, int error_code = 0)
-{
- tup.m_blob1.m_error_code = error_code;
- CHK(writeBlobData(g_bh1, tup.m_blob1) == 0);
- if (! g_opt.m_oneblob) {
- tup.m_blob2.m_error_code = error_code;
- CHK(writeBlobData(g_bh2, tup.m_blob2) == 0);
- }
- return 0;
-}
-
-static int
-readBlobData(NdbBlob* h, const Bval& v)
-{
- bool null = (v.m_val == 0);
- bool isNull;
- unsigned len;
- DBG("read " << h->getColumn()->getName() << " len=" << v.m_len << " null=" << null);
- if (null) {
- isNull = false;
- CHK(h->getNull(isNull) == 0 && isNull == true);
- CHK(getBlobLength(h, len) == 0 && len == 0);
- } else {
- isNull = true;
- CHK(h->getNull(isNull) == 0 && isNull == false);
- CHK(getBlobLength(h, len) == 0 && len == v.m_len);
- v.trash();
- unsigned n = 0;
- while (n < v.m_len) {
- unsigned m = g_opt.m_full ? v.m_len : urandom(v.m_len + 1);
- if (m > v.m_len - n)
- m = v.m_len - n;
- DBG("read pos=" << n << " cnt=" << m);
- const unsigned m2 = m;
- CHK(h->readData(v.m_buf + n, m) == 0);
- CHK(m2 == m);
- n += m;
- }
- assert(n == v.m_len);
- // need to execute to see the data
- CHK(g_con->execute(NoCommit) == 0);
- for (unsigned i = 0; i < v.m_len; i++)
- CHK(v.m_val[i] == v.m_buf[i]);
- }
- return 0;
-}
-
-static int
-readBlobData(const Tup& tup)
-{
- CHK(readBlobData(g_bh1, tup.m_blob1) == 0);
- if (! g_opt.m_oneblob)
- CHK(readBlobData(g_bh2, tup.m_blob2) == 0);
- return 0;
-}
-
-// hooks
-
-static NdbBlob::ActiveHook blobWriteHook;
-
-static int
-blobWriteHook(NdbBlob* h, void* arg)
-{
- DBG("blobWriteHook");
- Bval& v = *(Bval*)arg;
- CHK(writeBlobData(h, v) == 0);
- return 0;
-}
-
-static int
-setBlobWriteHook(NdbBlob* h, Bval& v, int error_code = 0)
-{
- DBG("setBlobWriteHook");
- v.m_error_code = error_code;
- CHK(h->setActiveHook(blobWriteHook, &v) == 0);
- return 0;
-}
-
-static int
-setBlobWriteHook(Tup& tup, int error_code = 0)
-{
- CHK(setBlobWriteHook(g_bh1, tup.m_blob1, error_code) == 0);
- if (! g_opt.m_oneblob)
- CHK(setBlobWriteHook(g_bh2, tup.m_blob2, error_code) == 0);
- return 0;
-}
-
-static NdbBlob::ActiveHook blobReadHook;
-
-// no PK yet to identify tuple so just read the value
-static int
-blobReadHook(NdbBlob* h, void* arg)
-{
- DBG("blobReadHook");
- Bval& v = *(Bval*)arg;
- unsigned len;
- CHK(getBlobLength(h, len) == 0);
- v.alloc(len);
- Uint32 maxlen = 0xffffffff;
- CHK(h->readData(v.m_buf, maxlen) == 0);
- DBG("read " << maxlen << " bytes");
- CHK(len == maxlen);
- return 0;
-}
-
-static int
-setBlobReadHook(NdbBlob* h, Bval& v)
-{
- DBG("setBlobReadHook");
- CHK(h->setActiveHook(blobReadHook, &v) == 0);
- return 0;
-}
-
-static int
-setBlobReadHook(Tup& tup)
-{
- CHK(setBlobReadHook(g_bh1, tup.m_blob1) == 0);
- if (! g_opt.m_oneblob)
- CHK(setBlobReadHook(g_bh2, tup.m_blob2) == 0);
- return 0;
-}
-
-// verify blob data
-
-static int
-verifyHeadInline(const Bcol& c, const Bval& v, NdbRecAttr* ra)
-{
- if (v.m_val == 0) {
- CHK(ra->isNULL() == 1);
- } else {
- CHK(ra->isNULL() == 0);
- const NdbBlob::Head* head = (const NdbBlob::Head*)ra->aRef();
- CHK(head->length == v.m_len);
- const char* data = (const char*)(head + 1);
- for (unsigned i = 0; i < head->length && i < c.m_inline; i++)
- CHK(data[i] == v.m_val[i]);
- }
- return 0;
-}
-
-static int
-verifyHeadInline(const Tup& tup)
-{
- DBG("verifyHeadInline pk1=" << hex << tup.m_pk1);
- CHK((g_con = g_ndb->startTransaction()) != 0);
- CHK((g_opr = g_con->getNdbOperation(g_opt.m_tname)) != 0);
- CHK(g_opr->readTuple() == 0);
- CHK(g_opr->equal("PK1", tup.m_pk1) == 0);
- if (g_opt.m_pk2len != 0)
- CHK(g_opr->equal("PK2", tup.m_pk2) == 0);
- NdbRecAttr* ra1;
- NdbRecAttr* ra2;
- CHK((ra1 = g_opr->getValue("BL1")) != 0);
- if (! g_opt.m_oneblob)
- CHK((ra2 = g_opr->getValue("BL2")) != 0);
- if (tup.m_exists) {
- CHK(g_con->execute(Commit, AbortOnError) == 0);
- DBG("verifyHeadInline BL1");
- CHK(verifyHeadInline(g_opt.m_blob1, tup.m_blob1, ra1) == 0);
- if (! g_opt.m_oneblob) {
- DBG("verifyHeadInline BL2");
- CHK(verifyHeadInline(g_opt.m_blob2, tup.m_blob2, ra2) == 0);
- }
- } else {
- CHK(g_con->execute(Commit, AbortOnError) == -1 &&
- g_con->getNdbError().code == 626);
- }
- g_ndb->closeTransaction(g_con);
- g_opr = 0;
- g_con = 0;
- return 0;
-}
-
-static int
-verifyBlobTable(const Bcol& b, const Bval& v, Uint32 pk1, bool exists)
-{
- DBG("verify " << b.m_btname << " pk1=" << hex << pk1);
- NdbRecAttr* ra_pk;
- NdbRecAttr* ra_part;
- NdbRecAttr* ra_data;
- CHK((g_con = g_ndb->startTransaction()) != 0);
- CHK((g_ops = g_con->getNdbScanOperation(b.m_btname)) != 0);
- CHK(g_ops->readTuples() == 0);
- CHK((ra_pk = g_ops->getValue("PK")) != 0);
- CHK((ra_part = g_ops->getValue("PART")) != 0);
- CHK((ra_data = g_ops->getValue("DATA")) != 0);
- CHK(g_con->execute(NoCommit) == 0);
- unsigned partcount;
- if (! exists || v.m_len <= b.m_inline)
- partcount = 0;
- else
- partcount = (v.m_len - b.m_inline + b.m_partsize - 1) / b.m_partsize;
- char* seen = new char [partcount];
- memset(seen, 0, partcount);
- while (1) {
- int ret;
- CHK((ret = g_ops->nextResult()) == 0 || ret == 1);
- if (ret == 1)
- break;
- if (pk1 != ra_pk->u_32_value())
- continue;
- Uint32 part = ra_part->u_32_value();
- DBG("part " << part << " of " << partcount);
- const char* data = ra_data->aRef();
- CHK(part < partcount && ! seen[part]);
- seen[part] = 1;
- unsigned n = b.m_inline + part * b.m_partsize;
- assert(exists && v.m_val != 0 && n < v.m_len);
- unsigned m = v.m_len - n;
- if (m > b.m_partsize)
- m = b.m_partsize;
- CHK(memcmp(data, v.m_val + n, m) == 0);
- }
- for (unsigned i = 0; i < partcount; i++)
- CHK(seen[i] == 1);
- g_ndb->closeTransaction(g_con);
- g_ops = 0;
- g_con = 0;
- return 0;
-}
-
-static int
-verifyBlobTable(const Tup& tup)
-{
- CHK(verifyBlobTable(g_opt.m_blob1, tup.m_blob1, tup.m_pk1, tup.m_exists) == 0);
- if (! g_opt.m_oneblob)
- CHK(verifyBlobTable(g_opt.m_blob2, tup.m_blob2, tup.m_pk1, tup.m_exists) == 0);
- return 0;
-}
-
-static int
-verifyBlob()
-{
- for (unsigned k = 0; k < g_opt.m_rows; k++) {
- const Tup& tup = g_tups[k];
- DBG("verifyBlob pk1=" << hex << tup.m_pk1);
- CHK(verifyHeadInline(tup) == 0);
- CHK(verifyBlobTable(tup) == 0);
- }
- return 0;
-}
-
-// operations
-
-static const char* stylename[3] = {
- "style=getValue/setValue",
- "style=setActiveHook",
- "style=readData/writeData"
-};
-
-// pk ops
-
-static int
-insertPk(int style)
-{
- DBG("--- insertPk " << stylename[style] << " ---");
- unsigned n = 0;
- CHK((g_con = g_ndb->startTransaction()) != 0);
- for (unsigned k = 0; k < g_opt.m_rows; k++) {
- Tup& tup = g_tups[k];
- DBG("insertPk pk1=" << hex << tup.m_pk1);
- CHK((g_opr = g_con->getNdbOperation(g_opt.m_tname)) != 0);
- CHK(g_opr->insertTuple() == 0);
- CHK(g_opr->equal("PK1", tup.m_pk1) == 0);
- if (g_opt.m_pk2len != 0)
- CHK(g_opr->equal("PK2", tup.m_pk2) == 0);
- CHK(getBlobHandles(g_opr) == 0);
- if (style == 0) {
- CHK(setBlobValue(tup) == 0);
- } else if (style == 1) {
- // non-nullable must be set
- CHK(g_bh1->setValue("", 0) == 0);
- CHK(setBlobWriteHook(tup) == 0);
- } else {
- // non-nullable must be set
- CHK(g_bh1->setValue("", 0) == 0);
- CHK(g_con->execute(NoCommit) == 0);
- CHK(writeBlobData(tup) == 0);
- }
- if (++n == g_opt.m_batch) {
- CHK(g_con->execute(Commit) == 0);
- g_ndb->closeTransaction(g_con);
- CHK((g_con = g_ndb->startTransaction()) != 0);
- n = 0;
- }
- g_opr = 0;
- tup.m_exists = true;
- }
- if (n != 0) {
- CHK(g_con->execute(Commit) == 0);
- n = 0;
- }
- g_ndb->closeTransaction(g_con);
- g_con = 0;
- return 0;
-}
-
-static int
-readPk(int style)
-{
- DBG("--- readPk " << stylename[style] << " ---");
- for (unsigned k = 0; k < g_opt.m_rows; k++) {
- Tup& tup = g_tups[k];
- DBG("readPk pk1=" << hex << tup.m_pk1);
- CHK((g_con = g_ndb->startTransaction()) != 0);
- CHK((g_opr = g_con->getNdbOperation(g_opt.m_tname)) != 0);
- if (urandom(2) == 0)
- CHK(g_opr->readTuple() == 0);
- else
- CHK(g_opr->readTuple(NdbOperation::LM_CommittedRead) == 0);
- CHK(g_opr->equal("PK1", tup.m_pk1) == 0);
- if (g_opt.m_pk2len != 0)
- CHK(g_opr->equal("PK2", tup.m_pk2) == 0);
- CHK(getBlobHandles(g_opr) == 0);
- if (style == 0) {
- CHK(getBlobValue(tup) == 0);
- } else if (style == 1) {
- CHK(setBlobReadHook(tup) == 0);
- } else {
- CHK(g_con->execute(NoCommit) == 0);
- CHK(readBlobData(tup) == 0);
- }
- CHK(g_con->execute(Commit) == 0);
- // verify lock mode upgrade
- CHK(g_opr->getLockMode() == NdbOperation::LM_Read);
- if (style == 0 || style == 1) {
- CHK(verifyBlobValue(tup) == 0);
- }
- g_ndb->closeTransaction(g_con);
- g_opr = 0;
- g_con = 0;
- }
- return 0;
-}
-
-static int
-updatePk(int style)
-{
- DBG("--- updatePk " << stylename[style] << " ---");
- for (unsigned k = 0; k < g_opt.m_rows; k++) {
- Tup& tup = g_tups[k];
- DBG("updatePk pk1=" << hex << tup.m_pk1);
- while (1) {
- int mode = urandom(3);
- int error_code = mode == 0 ? 0 : 4275;
- CHK((g_con = g_ndb->startTransaction()) != 0);
- CHK((g_opr = g_con->getNdbOperation(g_opt.m_tname)) != 0);
- if (mode == 0) {
- DBG("using updateTuple");
- CHK(g_opr->updateTuple() == 0);
- } else if (mode == 1) {
- DBG("using readTuple exclusive");
- CHK(g_opr->readTuple(NdbOperation::LM_Exclusive) == 0);
- } else {
- DBG("using readTuple - will fail and retry");
- CHK(g_opr->readTuple() == 0);
- }
- CHK(g_opr->equal("PK1", tup.m_pk1) == 0);
- if (g_opt.m_pk2len != 0)
- CHK(g_opr->equal("PK2", tup.m_pk2) == 0);
- CHK(getBlobHandles(g_opr) == 0);
- if (style == 0) {
- CHK(setBlobValue(tup, error_code) == 0);
- } else if (style == 1) {
- CHK(setBlobWriteHook(tup, error_code) == 0);
- } else {
- CHK(g_con->execute(NoCommit) == 0);
- CHK(writeBlobData(tup, error_code) == 0);
- }
- if (error_code == 0) {
- CHK(g_con->execute(Commit) == 0);
- g_ndb->closeTransaction(g_con);
- break;
- }
- g_ndb->closeTransaction(g_con);
- }
- g_opr = 0;
- g_con = 0;
- tup.m_exists = true;
- }
- return 0;
-}
-
-static int
-writePk(int style)
-{
- DBG("--- writePk " << stylename[style] << " ---");
- for (unsigned k = 0; k < g_opt.m_rows; k++) {
- Tup& tup = g_tups[k];
- DBG("writePk pk1=" << hex << tup.m_pk1);
- CHK((g_con = g_ndb->startTransaction()) != 0);
- CHK((g_opr = g_con->getNdbOperation(g_opt.m_tname)) != 0);
- CHK(g_opr->writeTuple() == 0);
- CHK(g_opr->equal("PK1", tup.m_pk1) == 0);
- if (g_opt.m_pk2len != 0)
- CHK(g_opr->equal("PK2", tup.m_pk2) == 0);
- CHK(getBlobHandles(g_opr) == 0);
- if (style == 0) {
- CHK(setBlobValue(tup) == 0);
- } else if (style == 1) {
- // non-nullable must be set
- CHK(g_bh1->setValue("", 0) == 0);
- CHK(setBlobWriteHook(tup) == 0);
- } else {
- // non-nullable must be set
- CHK(g_bh1->setValue("", 0) == 0);
- CHK(g_con->execute(NoCommit) == 0);
- CHK(writeBlobData(tup) == 0);
- }
- CHK(g_con->execute(Commit) == 0);
- g_ndb->closeTransaction(g_con);
- g_opr = 0;
- g_con = 0;
- tup.m_exists = true;
- }
- return 0;
-}
-
-static int
-deletePk()
-{
- DBG("--- deletePk ---");
- unsigned n = 0;
- CHK((g_con = g_ndb->startTransaction()) != 0);
- for (unsigned k = 0; k < g_opt.m_rows; k++) {
- Tup& tup = g_tups[k];
- DBG("deletePk pk1=" << hex << tup.m_pk1);
- CHK((g_opr = g_con->getNdbOperation(g_opt.m_tname)) != 0);
- CHK(g_opr->deleteTuple() == 0);
- CHK(g_opr->equal("PK1", tup.m_pk1) == 0);
- if (g_opt.m_pk2len != 0)
- CHK(g_opr->equal("PK2", tup.m_pk2) == 0);
- if (++n == g_opt.m_batch) {
- CHK(g_con->execute(Commit) == 0);
- g_ndb->closeTransaction(g_con);
- CHK((g_con = g_ndb->startTransaction()) != 0);
- n = 0;
- }
- g_opr = 0;
- tup.m_exists = false;
- }
- if (n != 0) {
- CHK(g_con->execute(Commit) == 0);
- n = 0;
- }
- g_ndb->closeTransaction(g_con);
- g_con = 0;
- return 0;
-}
-
-static int
-deleteNoPk()
-{
- DBG("--- deleteNoPk ---");
- Tup no_tup; // bug#24028
- no_tup.m_pk1 = 0xb1ffb1ff;
- sprintf(no_tup.m_pk2, "%-*.*s", g_opt.m_pk2len, g_opt.m_pk2len, "b1ffb1ff");
- CHK((g_con = g_ndb->startTransaction()) != 0);
- Tup& tup = no_tup;
- DBG("deletePk pk1=" << hex << tup.m_pk1);
- CHK((g_opr = g_con->getNdbOperation(g_opt.m_tname)) != 0);
- CHK(g_opr->deleteTuple() == 0);
- CHK(g_opr->equal("PK1", tup.m_pk1) == 0);
- if (g_opt.m_pk2len != 0)
- CHK(g_opr->equal("PK2", tup.m_pk2) == 0);
- CHK(g_con->execute(Commit) == -1); // fail
- // BUG: error should be on op but is on con now
- DBG("con: " << g_con->getNdbError());
- DBG("opr: " << g_opr->getNdbError());
- CHK(g_con->getNdbError().code == 626 || g_opr->getNdbError().code == 626);
- g_ndb->closeTransaction(g_con);
- g_opr = 0;
- g_con = 0;
- return 0;
-}
-
-// hash index ops
-
-static int
-readIdx(int style)
-{
- DBG("--- readIdx " << stylename[style] << " ---");
- for (unsigned k = 0; k < g_opt.m_rows; k++) {
- Tup& tup = g_tups[k];
- DBG("readIdx pk1=" << hex << tup.m_pk1);
- CHK((g_con = g_ndb->startTransaction()) != 0);
- CHK((g_opx = g_con->getNdbIndexOperation(g_opt.m_x1name, g_opt.m_tname)) != 0);
- if (urandom(2) == 0)
- CHK(g_opx->readTuple() == 0);
- else
- CHK(g_opx->readTuple(NdbOperation::LM_CommittedRead) == 0);
- CHK(g_opx->equal("PK2", tup.m_pk2) == 0);
- CHK(getBlobHandles(g_opx) == 0);
- if (style == 0) {
- CHK(getBlobValue(tup) == 0);
- } else if (style == 1) {
- CHK(setBlobReadHook(tup) == 0);
- } else {
- CHK(g_con->execute(NoCommit) == 0);
- CHK(readBlobData(tup) == 0);
- }
- CHK(g_con->execute(Commit) == 0);
- // verify lock mode upgrade (already done by NdbIndexOperation)
- CHK(g_opx->getLockMode() == NdbOperation::LM_Read);
- if (style == 0 || style == 1) {
- CHK(verifyBlobValue(tup) == 0);
- }
- g_ndb->closeTransaction(g_con);
- g_opx = 0;
- g_con = 0;
- }
- return 0;
-}
-
-static int
-updateIdx(int style)
-{
- DBG("--- updateIdx " << stylename[style] << " ---");
- for (unsigned k = 0; k < g_opt.m_rows; k++) {
- Tup& tup = g_tups[k];
- DBG("updateIdx pk1=" << hex << tup.m_pk1);
- // skip 4275 testing
- CHK((g_con = g_ndb->startTransaction()) != 0);
- CHK((g_opx = g_con->getNdbIndexOperation(g_opt.m_x1name, g_opt.m_tname)) != 0);
- CHK(g_opx->updateTuple() == 0);
- CHK(g_opx->equal("PK2", tup.m_pk2) == 0);
- CHK(getBlobHandles(g_opx) == 0);
- if (style == 0) {
- CHK(setBlobValue(tup) == 0);
- } else if (style == 1) {
- CHK(setBlobWriteHook(tup) == 0);
- } else {
- CHK(g_con->execute(NoCommit) == 0);
- CHK(writeBlobData(tup) == 0);
- }
- CHK(g_con->execute(Commit) == 0);
- g_ndb->closeTransaction(g_con);
- g_opx = 0;
- g_con = 0;
- tup.m_exists = true;
- }
- return 0;
-}
-
-static int
-writeIdx(int style)
-{
- DBG("--- writeIdx " << stylename[style] << " ---");
- for (unsigned k = 0; k < g_opt.m_rows; k++) {
- Tup& tup = g_tups[k];
- DBG("writeIdx pk1=" << hex << tup.m_pk1);
- CHK((g_con = g_ndb->startTransaction()) != 0);
- CHK((g_opx = g_con->getNdbIndexOperation(g_opt.m_x1name, g_opt.m_tname)) != 0);
- CHK(g_opx->writeTuple() == 0);
- CHK(g_opx->equal("PK2", tup.m_pk2) == 0);
- CHK(getBlobHandles(g_opx) == 0);
- if (style == 0) {
- CHK(setBlobValue(tup) == 0);
- } else if (style == 1) {
- // non-nullable must be set
- CHK(g_bh1->setValue("", 0) == 0);
- CHK(setBlobWriteHook(tup) == 0);
- } else {
- // non-nullable must be set
- CHK(g_bh1->setValue("", 0) == 0);
- CHK(g_con->execute(NoCommit) == 0);
- CHK(writeBlobData(tup) == 0);
- }
- CHK(g_con->execute(Commit) == 0);
- g_ndb->closeTransaction(g_con);
- g_opx = 0;
- g_con = 0;
- tup.m_exists = true;
- }
- return 0;
-}
-
-static int
-deleteIdx()
-{
- DBG("--- deleteIdx ---");
- unsigned n = 0;
- CHK((g_con = g_ndb->startTransaction()) != 0);
- for (unsigned k = 0; k < g_opt.m_rows; k++) {
- Tup& tup = g_tups[k];
- DBG("deleteIdx pk1=" << hex << tup.m_pk1);
- CHK((g_opx = g_con->getNdbIndexOperation(g_opt.m_x1name, g_opt.m_tname)) != 0);
- CHK(g_opx->deleteTuple() == 0);
- CHK(g_opx->equal("PK2", tup.m_pk2) == 0);
- if (++n == g_opt.m_batch) {
- CHK(g_con->execute(Commit) == 0);
- g_ndb->closeTransaction(g_con);
- CHK((g_con = g_ndb->startTransaction()) != 0);
- n = 0;
- }
- g_opx = 0;
- tup.m_exists = false;
- }
- if (n != 0) {
- CHK(g_con->execute(Commit) == 0);
- n = 0;
- }
- return 0;
-}
-
-// scan ops table and index
-
-static int
-readScan(int style, bool idx)
-{
- DBG("--- " << "readScan" << (idx ? "Idx" : "") << " " << stylename[style] << " ---");
- Tup tup;
- tup.alloc(); // allocate buffers
- CHK((g_con = g_ndb->startTransaction()) != 0);
- if (! idx) {
- CHK((g_ops = g_con->getNdbScanOperation(g_opt.m_tname)) != 0);
- } else {
- CHK((g_ops = g_con->getNdbIndexScanOperation(g_opt.m_x2name, g_opt.m_tname)) != 0);
- }
- if (urandom(2) == 0)
- CHK(g_ops->readTuples(NdbOperation::LM_Read) == 0);
- else
- CHK(g_ops->readTuples(NdbOperation::LM_CommittedRead) == 0);
- CHK(g_ops->getValue("PK1", (char*)&tup.m_pk1) != 0);
- if (g_opt.m_pk2len != 0)
- CHK(g_ops->getValue("PK2", tup.m_pk2) != 0);
- CHK(getBlobHandles(g_ops) == 0);
- if (style == 0) {
- CHK(getBlobValue(tup) == 0);
- } else if (style == 1) {
- CHK(setBlobReadHook(tup) == 0);
- }
- CHK(g_con->execute(NoCommit) == 0);
- // verify lock mode upgrade
- CHK(g_ops->getLockMode() == NdbOperation::LM_Read);
- unsigned rows = 0;
- while (1) {
- int ret;
- tup.m_pk1 = (Uint32)-1;
- memset(tup.m_pk2, 'x', g_opt.m_pk2len);
- CHK((ret = g_ops->nextResult(true)) == 0 || ret == 1);
- if (ret == 1)
- break;
- DBG("readScan" << (idx ? "Idx" : "") << " pk1=" << hex << tup.m_pk1);
- Uint32 k = tup.m_pk1 - g_opt.m_pk1off;
- CHK(k < g_opt.m_rows && g_tups[k].m_exists);
- tup.copyfrom(g_tups[k]);
- if (style == 0) {
- CHK(verifyBlobValue(tup) == 0);
- } else if (style == 1) {
- // execute ops generated by callbacks, if any
- CHK(verifyBlobValue(tup) == 0);
- } else {
- CHK(readBlobData(tup) == 0);
- }
- rows++;
- }
- g_ndb->closeTransaction(g_con);
- g_con = 0;
- g_ops = 0;
- CHK(g_opt.m_rows == rows);
- return 0;
-}
-
-static int
-updateScan(int style, bool idx)
-{
- DBG("--- " << "updateScan" << (idx ? "Idx" : "") << " " << stylename[style] << " ---");
- Tup tup;
- tup.alloc(); // allocate buffers
- CHK((g_con = g_ndb->startTransaction()) != 0);
- if (! idx) {
- CHK((g_ops = g_con->getNdbScanOperation(g_opt.m_tname)) != 0);
- } else {
- CHK((g_ops = g_con->getNdbIndexScanOperation(g_opt.m_x2name, g_opt.m_tname)) != 0);
- }
- CHK(g_ops->readTuples(NdbOperation::LM_Exclusive) == 0);
- CHK(g_ops->getValue("PK1", (char*)&tup.m_pk1) != 0);
- if (g_opt.m_pk2len != 0)
- CHK(g_ops->getValue("PK2", tup.m_pk2) != 0);
- CHK(g_con->execute(NoCommit) == 0);
- unsigned rows = 0;
- while (1) {
- int ret;
- tup.m_pk1 = (Uint32)-1;
- memset(tup.m_pk2, 'x', g_opt.m_pk2len);
- CHK((ret = g_ops->nextResult(true)) == 0 || ret == 1);
- if (ret == 1)
- break;
- DBG("updateScan" << (idx ? "Idx" : "") << " pk1=" << hex << tup.m_pk1);
- Uint32 k = tup.m_pk1 - g_opt.m_pk1off;
- CHK(k < g_opt.m_rows && g_tups[k].m_exists);
- // calculate new blob values
- calcBval(g_tups[k], false);
- tup.copyfrom(g_tups[k]);
- // cannot do 4275 testing, scan op error code controls execution
- CHK((g_opr = g_ops->updateCurrentTuple()) != 0);
- CHK(getBlobHandles(g_opr) == 0);
- if (style == 0) {
- CHK(setBlobValue(tup) == 0);
- } else if (style == 1) {
- CHK(setBlobWriteHook(tup) == 0);
- } else {
- CHK(g_con->execute(NoCommit) == 0);
- CHK(writeBlobData(tup) == 0);
- }
- CHK(g_con->execute(NoCommit) == 0);
- g_opr = 0;
- rows++;
- }
- CHK(g_con->execute(Commit) == 0);
- g_ndb->closeTransaction(g_con);
- g_con = 0;
- g_ops = 0;
- CHK(g_opt.m_rows == rows);
- return 0;
-}
-
-static int
-deleteScan(bool idx)
-{
- DBG("--- " << "deleteScan" << (idx ? "Idx" : "") << " ---");
- Tup tup;
- CHK((g_con = g_ndb->startTransaction()) != 0);
- if (! idx) {
- CHK((g_ops = g_con->getNdbScanOperation(g_opt.m_tname)) != 0);
- } else {
- CHK((g_ops = g_con->getNdbIndexScanOperation(g_opt.m_x2name, g_opt.m_tname)) != 0);
- }
- CHK(g_ops->readTuples(NdbOperation::LM_Exclusive) == 0);
- CHK(g_ops->getValue("PK1", (char*)&tup.m_pk1) != 0);
- if (g_opt.m_pk2len != 0)
- CHK(g_ops->getValue("PK2", tup.m_pk2) != 0);
- CHK(g_con->execute(NoCommit) == 0);
- unsigned rows = 0;
- unsigned n = 0;
- while (1) {
- int ret;
- tup.m_pk1 = (Uint32)-1;
- memset(tup.m_pk2, 'x', g_opt.m_pk2len);
- CHK((ret = g_ops->nextResult(true)) == 0 || ret == 1);
- if (ret == 1)
- break;
- while (1) {
- DBG("deleteScan" << (idx ? "Idx" : "") << " pk1=" << hex << tup.m_pk1);
- Uint32 k = tup.m_pk1 - g_opt.m_pk1off;
- CHK(k < g_opt.m_rows && g_tups[k].m_exists);
- g_tups[k].m_exists = false;
- CHK(g_ops->deleteCurrentTuple() == 0);
- rows++;
- tup.m_pk1 = (Uint32)-1;
- memset(tup.m_pk2, 'x', g_opt.m_pk2len);
- CHK((ret = g_ops->nextResult(false)) == 0 || ret == 1 || ret == 2);
- if (++n == g_opt.m_batch || ret == 2) {
- DBG("execute batch: n=" << n << " ret=" << ret);
- if (! g_opt.m_fac) {
- CHK(g_con->execute(NoCommit) == 0);
- } else {
- CHK(g_con->execute(Commit) == 0);
- CHK(g_con->restart() == 0);
- }
- n = 0;
- }
- if (ret == 2)
- break;
- }
- }
- CHK(g_con->execute(Commit) == 0);
- g_ndb->closeTransaction(g_con);
- g_con = 0;
- g_ops = 0;
- CHK(g_opt.m_rows == rows);
- return 0;
-}
-
-// main
-
-// from here on print always
-#undef DBG
-#define DBG(x) \
- do { \
- ndbout << "line " << __LINE__ << " " << x << endl; \
- } while (0)
-
-static int
-testmain()
-{
- g_ndb = new Ndb(g_ncc, "TEST_DB");
- CHK(g_ndb->init(20) == 0);
- CHK(g_ndb->waitUntilReady() == 0);
- g_dic = g_ndb->getDictionary();
- g_tups = new Tup [g_opt.m_rows];
- CHK(dropTable() == 0);
- CHK(createTable() == 0);
- if (g_opt.m_bugtest != 0) {
- // test a general bug instead of blobs
- CHK((*g_opt.m_bugtest)() == 0);
- return 0;
- }
- Bcol& b1 = g_opt.m_blob1;
- CHK(NdbBlob::getBlobTableName(b1.m_btname, g_ndb, g_opt.m_tname, "BL1") == 0);
- DBG("BL1: inline=" << b1.m_inline << " part=" << b1.m_partsize << " table=" << b1.m_btname);
- if (! g_opt.m_oneblob) {
- Bcol& b2 = g_opt.m_blob2;
- CHK(NdbBlob::getBlobTableName(b2.m_btname, g_ndb, g_opt.m_tname, "BL2") == 0);
- DBG("BL2: inline=" << b2.m_inline << " part=" << b2.m_partsize << " table=" << b2.m_btname);
- }
- if (g_opt.m_seed != 0)
- srandom(g_opt.m_seed);
- for (g_loop = 0; g_opt.m_loop == 0 || g_loop < g_opt.m_loop; g_loop++) {
- int style;
- DBG("=== loop " << g_loop << " ===");
- if (g_opt.m_seed == 0)
- srandom(g_loop);
- // pk
- for (style = 0; style <= 2; style++) {
- if (! testcase('k') || ! testcase(style))
- continue;
- DBG("--- pk ops " << stylename[style] << " ---");
- if (testcase('n')) {
- calcTups(false);
- CHK(insertPk(style) == 0);
- CHK(verifyBlob() == 0);
- CHK(readPk(style) == 0);
- if (testcase('u')) {
- calcTups(style);
- CHK(updatePk(style) == 0);
- CHK(verifyBlob() == 0);
- CHK(readPk(style) == 0);
- }
- CHK(deletePk() == 0);
- CHK(deleteNoPk() == 0);
- CHK(verifyBlob() == 0);
- }
- if (testcase('w')) {
- calcTups(false);
- CHK(writePk(style) == 0);
- CHK(verifyBlob() == 0);
- CHK(readPk(style) == 0);
- if (testcase('u')) {
- calcTups(style);
- CHK(writePk(style) == 0);
- CHK(verifyBlob() == 0);
- CHK(readPk(style) == 0);
- }
- CHK(deletePk() == 0);
- CHK(deleteNoPk() == 0);
- CHK(verifyBlob() == 0);
- }
- }
- // hash index
- for (style = 0; style <= 2; style++) {
- if (! testcase('i') || ! testcase(style))
- continue;
- DBG("--- idx ops " << stylename[style] << " ---");
- if (testcase('n')) {
- calcTups(false);
- CHK(insertPk(style) == 0);
- CHK(verifyBlob() == 0);
- CHK(readIdx(style) == 0);
- if (testcase('u')) {
- calcTups(style);
- CHK(updateIdx(style) == 0);
- CHK(verifyBlob() == 0);
- CHK(readIdx(style) == 0);
- }
- CHK(deleteIdx() == 0);
- CHK(verifyBlob() == 0);
- }
- if (testcase('w')) {
- calcTups(false);
- CHK(writePk(style) == 0);
- CHK(verifyBlob() == 0);
- CHK(readIdx(style) == 0);
- if (testcase('u')) {
- calcTups(style);
- CHK(writeIdx(style) == 0);
- CHK(verifyBlob() == 0);
- CHK(readIdx(style) == 0);
- }
- CHK(deleteIdx() == 0);
- CHK(verifyBlob() == 0);
- }
- }
- // scan table
- for (style = 0; style <= 2; style++) {
- if (! testcase('s') || ! testcase(style))
- continue;
- DBG("--- table scan " << stylename[style] << " ---");
- calcTups(false);
- CHK(insertPk(style) == 0);
- CHK(verifyBlob() == 0);
- CHK(readScan(style, false) == 0);
- if (testcase('u')) {
- CHK(updateScan(style, false) == 0);
- CHK(verifyBlob() == 0);
- }
- CHK(deleteScan(false) == 0);
- CHK(verifyBlob() == 0);
- }
- // scan index
- for (style = 0; style <= 2; style++) {
- if (! testcase('r') || ! testcase(style))
- continue;
- DBG("--- index scan " << stylename[style] << " ---");
- calcTups(false);
- CHK(insertPk(style) == 0);
- CHK(verifyBlob() == 0);
- CHK(readScan(style, true) == 0);
- if (testcase('u')) {
- CHK(updateScan(style, true) == 0);
- CHK(verifyBlob() == 0);
- }
- CHK(deleteScan(true) == 0);
- CHK(verifyBlob() == 0);
- }
- }
- delete g_ndb;
- return 0;
-}
-
-// separate performance test
-
-struct Tmr { // stolen from testOIBasic
- Tmr() {
- clr();
- }
- void clr() {
- m_on = m_ms = m_cnt = m_time[0] = m_text[0] = 0;
- }
- void on() {
- assert(m_on == 0);
- m_on = NdbTick_CurrentMillisecond();
- }
- void off(unsigned cnt = 0) {
- NDB_TICKS off = NdbTick_CurrentMillisecond();
- assert(m_on != 0 && off >= m_on);
- m_ms += off - m_on;
- m_cnt += cnt;
- m_on = 0;
- }
- const char* time() {
- if (m_cnt == 0)
- sprintf(m_time, "%u ms", m_ms);
- else
- sprintf(m_time, "%u ms per %u ( %u ms per 1000 )", m_ms, m_cnt, (1000 * m_ms) / m_cnt);
- return m_time;
- }
- const char* pct (const Tmr& t1) {
- if (0 < t1.m_ms)
- sprintf(m_text, "%u pct", (100 * m_ms) / t1.m_ms);
- else
- sprintf(m_text, "[cannot measure]");
- return m_text;
- }
- const char* over(const Tmr& t1) {
- if (0 < t1.m_ms) {
- if (t1.m_ms <= m_ms)
- sprintf(m_text, "%u pct", (100 * (m_ms - t1.m_ms)) / t1.m_ms);
- else
- sprintf(m_text, "-%u pct", (100 * (t1.m_ms - m_ms)) / t1.m_ms);
- } else
- sprintf(m_text, "[cannot measure]");
- return m_text;
- }
- NDB_TICKS m_on;
- unsigned m_ms;
- unsigned m_cnt;
- char m_time[100];
- char m_text[100];
-};
-
-static int
-testperf()
-{
- if (! testcase('p'))
- return 0;
- DBG("=== perf test ===");
- g_bh1 = g_bh2 = 0;
- g_ndb = new Ndb(g_ncc, "TEST_DB");
- CHK(g_ndb->init() == 0);
- CHK(g_ndb->waitUntilReady() == 0);
- g_dic = g_ndb->getDictionary();
- NdbDictionary::Table tab(g_opt.m_tnameperf);
- if (g_dic->getTable(tab.getName()) != 0)
- CHK(g_dic->dropTable(tab.getName()) == 0);
- // col A - pk
- { NdbDictionary::Column col("A");
- col.setType(NdbDictionary::Column::Unsigned);
- col.setPrimaryKey(true);
- tab.addColumn(col);
- }
- // col B - char 20
- { NdbDictionary::Column col("B");
- col.setType(NdbDictionary::Column::Char);
- col.setLength(20);
- col.setNullable(true);
- tab.addColumn(col);
- }
- // col C - text
- { NdbDictionary::Column col("C");
- col.setType(NdbDictionary::Column::Text);
- col.setInlineSize(20);
- col.setPartSize(512);
- col.setStripeSize(1);
- col.setNullable(true);
- tab.addColumn(col);
- }
- // create
- CHK(g_dic->createTable(tab) == 0);
- Uint32 cA = 0, cB = 1, cC = 2;
- // timers
- Tmr t1;
- Tmr t2;
- // insert char (one trans)
- {
- DBG("--- insert char ---");
- char b[20];
- t1.on();
- CHK((g_con = g_ndb->startTransaction()) != 0);
- for (Uint32 k = 0; k < g_opt.m_rowsperf; k++) {
- CHK((g_opr = g_con->getNdbOperation(tab.getName())) != 0);
- CHK(g_opr->insertTuple() == 0);
- CHK(g_opr->equal(cA, (char*)&k) == 0);
- memset(b, 0x20, sizeof(b));
- b[0] = 'b';
- CHK(g_opr->setValue(cB, b) == 0);
- CHK(g_con->execute(NoCommit) == 0);
- }
- t1.off(g_opt.m_rowsperf);
- CHK(g_con->execute(Rollback) == 0);
- DBG(t1.time());
- g_opr = 0;
- g_con = 0;
- }
- // insert text (one trans)
- {
- DBG("--- insert text ---");
- t2.on();
- CHK((g_con = g_ndb->startTransaction()) != 0);
- for (Uint32 k = 0; k < g_opt.m_rowsperf; k++) {
- CHK((g_opr = g_con->getNdbOperation(tab.getName())) != 0);
- CHK(g_opr->insertTuple() == 0);
- CHK(g_opr->equal(cA, (char*)&k) == 0);
- CHK((g_bh1 = g_opr->getBlobHandle(cC)) != 0);
- CHK((g_bh1->setValue("c", 1) == 0));
- CHK(g_con->execute(NoCommit) == 0);
- }
- t2.off(g_opt.m_rowsperf);
- CHK(g_con->execute(Rollback) == 0);
- DBG(t2.time());
- g_bh1 = 0;
- g_opr = 0;
- g_con = 0;
- }
- // insert overhead
- DBG("insert overhead: " << t2.over(t1));
- t1.clr();
- t2.clr();
- // insert
- {
- DBG("--- insert for read test ---");
- unsigned n = 0;
- char b[20];
- CHK((g_con = g_ndb->startTransaction()) != 0);
- for (Uint32 k = 0; k < g_opt.m_rowsperf; k++) {
- CHK((g_opr = g_con->getNdbOperation(tab.getName())) != 0);
- CHK(g_opr->insertTuple() == 0);
- CHK(g_opr->equal(cA, (char*)&k) == 0);
- memset(b, 0x20, sizeof(b));
- b[0] = 'b';
- CHK(g_opr->setValue(cB, b) == 0);
- CHK((g_bh1 = g_opr->getBlobHandle(cC)) != 0);
- CHK((g_bh1->setValue("c", 1) == 0));
- if (++n == g_opt.m_batch) {
- CHK(g_con->execute(Commit) == 0);
- g_ndb->closeTransaction(g_con);
- CHK((g_con = g_ndb->startTransaction()) != 0);
- n = 0;
- }
- }
- if (n != 0) {
- CHK(g_con->execute(Commit) == 0);
- g_ndb->closeTransaction(g_con); g_con = 0;
- n = 0;
- }
- g_bh1 = 0;
- g_opr = 0;
- }
- // pk read char (one trans)
- {
- DBG("--- pk read char ---");
- CHK((g_con = g_ndb->startTransaction()) != 0);
- Uint32 a;
- char b[20];
- t1.on();
- for (Uint32 k = 0; k < g_opt.m_rowsperf; k++) {
- CHK((g_opr = g_con->getNdbOperation(tab.getName())) != 0);
- CHK(g_opr->readTuple() == 0);
- CHK(g_opr->equal(cA, (char*)&k) == 0);
- CHK(g_opr->getValue(cA, (char*)&a) != 0);
- CHK(g_opr->getValue(cB, b) != 0);
- a = (Uint32)-1;
- b[0] = 0;
- CHK(g_con->execute(NoCommit) == 0);
- CHK(a == k && b[0] == 'b');
- }
- CHK(g_con->execute(Commit) == 0);
- t1.off(g_opt.m_rowsperf);
- DBG(t1.time());
- g_opr = 0;
- g_ndb->closeTransaction(g_con); g_con = 0;
- }
- // pk read text (one trans)
- {
- DBG("--- pk read text ---");
- CHK((g_con = g_ndb->startTransaction()) != 0);
- Uint32 a;
- char c[20];
- t2.on();
- for (Uint32 k = 0; k < g_opt.m_rowsperf; k++) {
- CHK((g_opr = g_con->getNdbOperation(tab.getName())) != 0);
- CHK(g_opr->readTuple() == 0);
- CHK(g_opr->equal(cA, (char*)&k) == 0);
- CHK(g_opr->getValue(cA, (char*)&a) != 0);
- CHK((g_bh1 = g_opr->getBlobHandle(cC)) != 0);
- a = (Uint32)-1;
- c[0] = 0;
- CHK(g_con->execute(NoCommit) == 0);
- Uint32 m = 20;
- CHK(g_bh1->readData(c, m) == 0);
- CHK(a == k && m == 1 && c[0] == 'c');
- }
- CHK(g_con->execute(Commit) == 0);
- t2.off(g_opt.m_rowsperf);
- DBG(t2.time());
- g_ndb->closeTransaction(g_con); g_opr = 0;
- g_con = 0;
- }
- // pk read overhead
- DBG("pk read overhead: " << t2.over(t1));
- t1.clr();
- t2.clr();
- // scan read char
- {
- DBG("--- scan read char ---");
- Uint32 a;
- char b[20];
- CHK((g_con = g_ndb->startTransaction()) != 0);
- CHK((g_ops = g_con->getNdbScanOperation(tab.getName())) != 0);
- CHK(g_ops->readTuples(NdbOperation::LM_Read) == 0);
- CHK(g_ops->getValue(cA, (char*)&a) != 0);
- CHK(g_ops->getValue(cB, b) != 0);
- CHK(g_con->execute(NoCommit) == 0);
- unsigned n = 0;
- t1.on();
- while (1) {
- a = (Uint32)-1;
- b[0] = 0;
- int ret;
- CHK((ret = g_ops->nextResult(true)) == 0 || ret == 1);
- if (ret == 1)
- break;
- CHK(a < g_opt.m_rowsperf && b[0] == 'b');
- n++;
- }
- CHK(n == g_opt.m_rowsperf);
- t1.off(g_opt.m_rowsperf);
- DBG(t1.time());
- g_ndb->closeTransaction(g_con); g_ops = 0;
- g_con = 0;
- }
- // scan read text
- {
- DBG("--- read text ---");
- Uint32 a;
- char c[20];
- CHK((g_con = g_ndb->startTransaction()) != 0);
- CHK((g_ops = g_con->getNdbScanOperation(tab.getName())) != 0);
- CHK(g_ops->readTuples(NdbOperation::LM_Read) == 0);
- CHK(g_ops->getValue(cA, (char*)&a) != 0);
- CHK((g_bh1 = g_ops->getBlobHandle(cC)) != 0);
- CHK(g_con->execute(NoCommit) == 0);
- unsigned n = 0;
- t2.on();
- while (1) {
- a = (Uint32)-1;
- c[0] = 0;
- int ret;
- CHK((ret = g_ops->nextResult(true)) == 0 || ret == 1);
- if (ret == 1)
- break;
- Uint32 m = 20;
- CHK(g_bh1->readData(c, m) == 0);
- CHK(a < g_opt.m_rowsperf && m == 1 && c[0] == 'c');
- n++;
- }
- CHK(n == g_opt.m_rowsperf);
- t2.off(g_opt.m_rowsperf);
- DBG(t2.time());
- g_bh1 = 0;
- g_ops = 0;
- g_ndb->closeTransaction(g_con); g_con = 0;
- }
- // scan read overhead
- DBG("scan read overhead: " << t2.over(t1));
- t1.clr();
- t2.clr();
- delete g_ndb;
- return 0;
-}
-
-// bug tests
-
-static int
-bugtest_4088()
-{
- unsigned i;
- DBG("bug test 4088 - ndb api hang with mixed ops on index table");
- // insert rows
- calcTups(false);
- CHK(insertPk(false) == 0);
- // new trans
- CHK((g_con = g_ndb->startTransaction()) != 0);
- for (unsigned k = 0; k < g_opt.m_rows; k++) {
- Tup& tup = g_tups[k];
- // read table pk via index as a table
- const unsigned pkcnt = 2;
- Tup pktup[pkcnt];
- for (i = 0; i < pkcnt; i++) {
- char name[20];
- // XXX guess table id
- sprintf(name, "%d/%s", 4, g_opt.m_x1name);
- CHK((g_opr = g_con->getNdbOperation(name)) != 0);
- CHK(g_opr->readTuple() == 0);
- CHK(g_opr->equal("PK2", tup.m_pk2) == 0);
- CHK(g_opr->getValue("NDB$PK", (char*)&pktup[i].m_pk1) != 0);
- }
- // read blob inline via index as an index
- CHK((g_opx = g_con->getNdbIndexOperation(g_opt.m_x1name, g_opt.m_tname)) != 0);
- CHK(g_opx->readTuple() == 0);
- CHK(g_opx->equal("PK2", tup.m_pk2) == 0);
- assert(tup.m_blob1.m_buf != 0);
- CHK(g_opx->getValue("BL1", (char*)tup.m_blob1.m_buf) != 0);
- // execute
- // BUG 4088: gets 1 tckeyconf, 1 tcindxconf, then hangs
- CHK(g_con->execute(Commit) == 0);
- // verify
- for (i = 0; i < pkcnt; i++) {
- CHK(pktup[i].m_pk1 == tup.m_pk1);
- CHK(memcmp(pktup[i].m_pk2, tup.m_pk2, g_opt.m_pk2len) == 0);
- }
- CHK(memcmp(tup.m_blob1.m_val, tup.m_blob1.m_buf, 8 + g_opt.m_blob1.m_inline) == 0);
- }
- return 0;
-}
-
-static int
-bugtest_27018()
-{
- DBG("bug test 27018 - middle partial part write clobbers rest of part");
-
- // insert rows
- calcTups(false);
- CHK(insertPk(false) == 0);
- // new trans
- for (unsigned k= 0; k < g_opt.m_rows; k++)
- {
- Tup& tup= g_tups[k];
-
- CHK((g_con= g_ndb->startTransaction()) != 0);
- CHK((g_opr= g_con->getNdbOperation(g_opt.m_tname)) != 0);
- CHK(g_opr->updateTuple() == 0);
- CHK(g_opr->equal("PK1", tup.m_pk1) == 0);
- if (g_opt.m_pk2len != 0)
- CHK(g_opr->equal("PK2", tup.m_pk2) == 0);
- CHK(getBlobHandles(g_opr) == 0);
- CHK(g_con->execute(NoCommit) == 0);
-
- /* Update one byte in random position. */
- Uint32 offset= urandom(tup.m_blob1.m_len);
- tup.m_blob1.m_buf[0]= 0xff ^ tup.m_blob1.m_val[offset];
- CHK(g_bh1->setPos(offset) == 0);
- CHK(g_bh1->writeData(&(tup.m_blob1.m_buf[0]), 1) == 0);
- CHK(g_con->execute(Commit) == 0);
- g_ndb->closeTransaction(g_con);
-
- CHK((g_con= g_ndb->startTransaction()) != 0);
- CHK((g_opr= g_con->getNdbOperation(g_opt.m_tname)) != 0);
- CHK(g_opr->readTuple() == 0);
- CHK(g_opr->equal("PK1", tup.m_pk1) == 0);
- if (g_opt.m_pk2len != 0)
- CHK(g_opr->equal("PK2", tup.m_pk2) == 0);
- CHK(getBlobHandles(g_opr) == 0);
-
- CHK(g_bh1->getValue(tup.m_blob1.m_buf, tup.m_blob1.m_len) == 0);
- CHK(g_con->execute(Commit) == 0);
- Uint64 len= ~0;
- CHK(g_bh1->getLength(len) == 0 && len == tup.m_blob1.m_len);
- tup.m_blob1.m_buf[offset]^= 0xff;
- CHK(memcmp(tup.m_blob1.m_buf, tup.m_blob1.m_val, tup.m_blob1.m_len) == 0);
- g_ndb->closeTransaction(g_con);
- }
-
- return 0;
-}
-
-
-struct bug27370_data {
- Ndb *m_ndb;
- char m_current_write_value;
- char *m_writebuf;
- Uint32 m_blob1_size;
- Uint32 m_pk1;
- char m_pk2[g_max_pk2len + 1];
- bool m_thread_stop;
-};
-
-void *bugtest_27370_thread(void *arg)
-{
- bug27370_data *data= (bug27370_data *)arg;
-
- while (!data->m_thread_stop)
- {
- memset(data->m_writebuf, data->m_current_write_value, data->m_blob1_size);
- data->m_current_write_value++;
-
- NdbConnection *con;
- if ((con= data->m_ndb->startTransaction()) == 0)
- return (void *)"Failed to create transaction";
- NdbOperation *opr;
- if ((opr= con->getNdbOperation(g_opt.m_tname)) == 0)
- return (void *)"Failed to create operation";
- if (opr->writeTuple() != 0)
- return (void *)"writeTuple() failed";
- if (opr->equal("PK1", data->m_pk1) != 0)
- return (void *)"equal(PK1) failed";
- if (g_opt.m_pk2len != 0)
- if (opr->equal("PK2", data->m_pk2) != 0)
- return (void *)"equal(PK2) failed";
- NdbBlob *bh;
- if ((bh= opr->getBlobHandle("BL1")) == 0)
- return (void *)"getBlobHandle() failed";
- if (bh->setValue(data->m_writebuf, data->m_blob1_size) != 0)
- return (void *)"setValue() failed";
- if (con->execute(Commit, AbortOnError, 1) != 0)
- return (void *)"execute() failed";
- data->m_ndb->closeTransaction(con);
- }
-
- return NULL; // Success
-}
-
-static int
-bugtest_27370()
-{
- DBG("bug test 27370 - Potential inconsistent blob reads for ReadCommitted reads");
-
- bug27370_data data;
-
- data.m_ndb= new Ndb(g_ncc, "TEST_DB");
- CHK(data.m_ndb->init(20) == 0);
- CHK(data.m_ndb->waitUntilReady() == 0);
-
- data.m_current_write_value= 0;
- data.m_blob1_size= g_opt.m_blob1.m_inline + 10 * g_opt.m_blob1.m_partsize;
- CHK((data.m_writebuf= new char [data.m_blob1_size]) != 0);
- data.m_pk1= 27370;
- memset(data.m_pk2, 'x', g_max_pk2len);
- data.m_pk2[g_max_pk2len]= '\0';
- data.m_thread_stop= false;
-
- memset(data.m_writebuf, data.m_current_write_value, data.m_blob1_size);
- data.m_current_write_value++;
-
- CHK((g_con= g_ndb->startTransaction()) != 0);
- CHK((g_opr= g_con->getNdbOperation(g_opt.m_tname)) != 0);
- CHK(g_opr->writeTuple() == 0);
- CHK(g_opr->equal("PK1", data.m_pk1) == 0);
- if (g_opt.m_pk2len != 0)
- CHK(g_opr->equal("PK2", data.m_pk2) == 0);
- CHK((g_bh1= g_opr->getBlobHandle("BL1")) != 0);
- CHK(g_bh1->setValue(data.m_writebuf, data.m_blob1_size) == 0);
- CHK(g_con->execute(Commit) == 0);
- g_ndb->closeTransaction(g_con);
- g_con= NULL;
-
- pthread_t thread_handle;
- CHK(pthread_create(&thread_handle, NULL, bugtest_27370_thread, &data) == 0);
-
- DBG("bug test 27370 - PK blob reads");
- Uint32 seen_updates= 0;
- while (seen_updates < 50)
- {
- CHK((g_con= g_ndb->startTransaction()) != 0);
- CHK((g_opr= g_con->getNdbOperation(g_opt.m_tname)) != 0);
- CHK(g_opr->readTuple(NdbOperation::LM_CommittedRead) == 0);
- CHK(g_opr->equal("PK1", data.m_pk1) == 0);
- if (g_opt.m_pk2len != 0)
- CHK(g_opr->equal("PK2", data.m_pk2) == 0);
- CHK((g_bh1= g_opr->getBlobHandle("BL1")) != 0);
- CHK(g_con->execute(NoCommit, AbortOnError, 1) == 0);
-
- const Uint32 loop_max= 10;
- char read_char;
- char original_read_char= 0;
- Uint32 readloop;
- for (readloop= 0;; readloop++)
- {
- if (readloop > 0)
- {
- if (readloop > 1)
- {
- /* Compare against first read. */
- CHK(read_char == original_read_char);
- }
- else
- {
- /*
- We count the number of times we see the other thread had the
- chance to update, so that we can be sure it had the opportunity
- to run a reasonable number of times before we stop.
- */
- if (original_read_char != read_char)
- seen_updates++;
- original_read_char= read_char;
- }
- }
- if (readloop > loop_max)
- break;
- Uint32 readSize= 1;
- CHK(g_bh1->setPos(urandom(data.m_blob1_size)) == 0);
- CHK(g_bh1->readData(&read_char, readSize) == 0);
- CHK(readSize == 1);
- ExecType commitType= readloop == loop_max ? Commit : NoCommit;
- CHK(g_con->execute(commitType, AbortOnError, 1) == 0);
- }
- g_ndb->closeTransaction(g_con);
- g_con= NULL;
- }
-
- DBG("bug test 27370 - table scan blob reads");
- seen_updates= 0;
- while (seen_updates < 50)
- {
- CHK((g_con= g_ndb->startTransaction()) != 0);
- CHK((g_ops= g_con->getNdbScanOperation(g_opt.m_tname)) != 0);
- CHK(g_ops->readTuples(NdbOperation::LM_CommittedRead) == 0);
- CHK((g_bh1= g_ops->getBlobHandle("BL1")) != 0);
- CHK(g_con->execute(NoCommit, AbortOnError, 1) == 0);
- CHK(g_ops->nextResult(true) == 0);
-
- const Uint32 loop_max= 10;
- char read_char;
- char original_read_char= 0;
- Uint32 readloop;
- for (readloop= 0;; readloop++)
- {
- if (readloop > 0)
- {
- if (readloop > 1)
- {
- /* Compare against first read. */
- CHK(read_char == original_read_char);
- }
- else
- {
- /*
- We count the number of times we see the other thread had the
- chance to update, so that we can be sure it had the opportunity
- to run a reasonable number of times before we stop.
- */
- if (original_read_char != read_char)
- seen_updates++;
- original_read_char= read_char;
- }
- }
- if (readloop > loop_max)
- break;
- Uint32 readSize= 1;
- CHK(g_bh1->setPos(urandom(data.m_blob1_size)) == 0);
- CHK(g_bh1->readData(&read_char, readSize) == 0);
- CHK(readSize == 1);
- CHK(g_con->execute(NoCommit, AbortOnError, 1) == 0);
- }
-
- CHK(g_ops->nextResult(true) == 1);
- g_ndb->closeTransaction(g_con);
- g_con= NULL;
- }
-
- data.m_thread_stop= true;
- void *thread_return;
- CHK(pthread_join(thread_handle, &thread_return) == 0);
- DBG("bug 27370 - thread return status: " <<
- (thread_return ? (char *)thread_return : "<null>"));
- CHK(thread_return == 0);
-
- g_con= NULL;
- g_opr= NULL;
- g_bh1= NULL;
- return 0;
-}
-
-static struct {
- int m_bug;
- int (*m_test)();
-} g_bugtest[] = {
- { 4088, bugtest_4088 },
- { 27018, bugtest_27018 },
- { 27370, bugtest_27370 }
-};
-
-NDB_COMMAND(testOdbcDriver, "testBlobs", "testBlobs", "testBlobs", 65535)
-{
- ndb_init();
- while (++argv, --argc > 0) {
- const char* arg = argv[0];
- if (strcmp(arg, "-batch") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_batch = atoi(argv[0]);
- continue;
- }
- }
- if (strcmp(arg, "-core") == 0) {
- g_opt.m_core = true;
- continue;
- }
- if (strcmp(arg, "-dbg") == 0) {
- g_opt.m_dbg = true;
- continue;
- }
- if (strcmp(arg, "-dbgall") == 0) {
- g_opt.m_dbg = true;
- g_opt.m_dbgall = true;
- putenv(strdup("NDB_BLOB_DEBUG=1"));
- continue;
- }
- if (strcmp(arg, "-dbug") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_dbug = strdup(argv[0]);
- continue;
- }
- }
- if (strcmp(arg, "-fac") == 0) {
- g_opt.m_fac = true;
- continue;
- }
- if (strcmp(arg, "-full") == 0) {
- g_opt.m_full = true;
- continue;
- }
- if (strcmp(arg, "-loop") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_loop = atoi(argv[0]);
- continue;
- }
- }
- if (strcmp(arg, "-parts") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_parts = atoi(argv[0]);
- continue;
- }
- }
- if (strcmp(arg, "-rows") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_rows = atoi(argv[0]);
- continue;
- }
- }
- if (strcmp(arg, "-rowsperf") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_rowsperf = atoi(argv[0]);
- continue;
- }
- }
- if (strcmp(arg, "-seed") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_seed = atoi(argv[0]);
- continue;
- }
- }
- if (strcmp(arg, "-skip") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_skip = strdup(argv[0]);
- continue;
- }
- }
- if (strcmp(arg, "-test") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_test = strdup(argv[0]);
- continue;
- }
- }
- // metadata
- if (strcmp(arg, "-pk2len") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_pk2len = atoi(argv[0]);
- if (g_opt.m_pk2len <= g_max_pk2len)
- continue;
- }
- }
- if (strcmp(arg, "-oneblob") == 0) {
- g_opt.m_oneblob = true;
- continue;
- }
- // bugs
- if (strcmp(arg, "-bug") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_bug = atoi(argv[0]);
- for (unsigned i = 0; i < sizeof(g_bugtest)/sizeof(g_bugtest[0]); i++) {
- if (g_opt.m_bug == g_bugtest[i].m_bug) {
- g_opt.m_bugtest = g_bugtest[i].m_test;
- break;
- }
- }
- if (g_opt.m_bugtest != 0)
- continue;
- }
- }
- ndbout << "testOIBasic: unknown option " << arg << endl;
- printusage();
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
- if (g_opt.m_dbug != 0) {
- DBUG_PUSH(g_opt.m_dbug);
- }
- if (g_opt.m_pk2len == 0) {
- char b[100];
- b[0] = 0;
- if (g_opt.m_skip != 0)
- strcpy(b, g_opt.m_skip);
- strcat(b, "i");
- strcat(b, "r");
- g_opt.m_skip = strdup(b);
- }
- g_ncc = new Ndb_cluster_connection();
- if (g_ncc->connect(30) != 0 || testmain() == -1 || testperf() == -1) {
- ndbout << "line " << __LINE__ << " FAIL loop=" << g_loop << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- delete g_ncc;
- g_ncc = 0;
- return NDBT_ProgramExit(NDBT_OK);
-}
-
-// vim: set sw=2 et:
diff --git a/storage/ndb/test/ndbapi/testDataBuffers.cpp b/storage/ndb/test/ndbapi/testDataBuffers.cpp
deleted file mode 100644
index 0a0a355003c..00000000000
--- a/storage/ndb/test/ndbapi/testDataBuffers.cpp
+++ /dev/null
@@ -1,642 +0,0 @@
-/* Copyright (c) 2003-2006 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-/*
- * testDataBuffers
- *
- * Test getValue() of byte arrays:
- * - using application buffers of different alignments and sizes
- * - using NdbApi allocated small (<32) and big (>=32) buffers
- *
- * Verifies fixes to tickets 189 and 206.
- *
- * Options: see printusage() below.
- *
- * Creates tables TB00 to TB15
- */
-
-#include <ndb_global.h>
-
-#include <NdbMain.h>
-#include <NdbOut.hpp>
-#include <NdbApi.hpp>
-#include <NdbTest.hpp>
-#include <NdbSchemaCon.hpp>
-// limits
-static int const MaxAttr = 64;
-static int const MaxOper = 1000;
-static int const MaxSize = 10000;
-static int const MaxOff = 64; // max offset to add to data buffer
-static int const MaxData = MaxSize + MaxOff + 100;
-
-// options
-static int attrcnt = 25;
-static int existok = 0;
-static bool kontinue = false;
-static int loopcnt = 1;
-static int opercnt = 100; // also does this many scans
-static int randomizer = 171317;
-static int sizelim = 500;
-static int xverbose = 0;
-
-static void printusage() {
- ndbout
- << "usage: testDataBuffers options [default/max]"
- << endl
- << "NOTE: too large combinations result in NDB error"
- << endl
- << "-a N number of attributes (including the key) [25/64]"
- << endl
- << "-e no error if table exists (assumed to have same structure)"
- << endl
- << "-k on error continue with next test case"
- << endl
- << "-l N number of loops to run, 0 means infinite [1]"
- << endl
- << "-o N number of operations (rows in each table) [100/1000]"
- << endl
- << "-r N source of randomness (big number (prime)) [171317]"
- << endl
- << "-s N array size limit (rounded up in some tests) [500/10000]"
- << endl
- << "-x extremely verbose"
- << endl
- << "Tables: TB00 .. TB15"
- << endl
- ;
-}
-
-static Ndb* ndb = 0;
-static NdbSchemaCon* tcon = 0;
-static NdbSchemaOp* top = 0;
-static NdbConnection* con = 0;
-static NdbOperation* op = 0;
-static NdbScanOperation* sop = 0;
-static NdbResultSet* rs = 0;
-
-static int
-ndberror(char const* fmt, ...)
-{
- va_list ap;
- char buf[200];
- va_start(ap, fmt);
- BaseString::vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
- ndbout << buf << " --" << endl;
- if (ndb)
- ndbout << "ndb : " << ndb->getNdbError() << endl;
- if (tcon)
- ndbout << "tcon: " << tcon->getNdbError() << endl;
- if (top)
- ndbout << "top: " << top->getNdbError() << endl;
- if (con)
- ndbout << "con : " << con->getNdbError() << endl;
- if (op)
- ndbout << "op : " << op->getNdbError() << endl;
- return -1;
-}
-
-static int
-chkerror(char const* fmt, ...)
-{
- va_list ap;
- char buf[200];
- va_start(ap, fmt);
- BaseString::vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
- ndbout << "*** check failed: " << buf << " ***" << endl;
- return -1;
-}
-
-// alignment of addresses and data sizes
-
-static bool isAligned(UintPtr x)
-{
- return ((x & 3) == 0);
-}
-static bool isAligned(char* p)
-{
- return isAligned(UintPtr(p));
-}
-static unsigned toAligned(UintPtr x)
-{
- while (! isAligned(x))
- x++;
- return x;
-}
-static char* toAligned(char* p)
-{
- while (! isAligned(p))
- p++;
- return p;
-}
-
-// byte value for key k column i byte j
-static int byteVal(int k, int i, int j)
-{
- return '0' + (k + i + j) % 10;
-}
-
-// tables
-
-static char tab[20] = "";
-
-static struct col {
- char aAttrName[20];
- AttrType aAttrType;
- int aAttrSize;
- int aArraySize;
- KeyType aTupleKey;
- bool nullable;
- NdbRecAttr* aRa;
- char* buf;
- int bufsiz;
- char data[MaxData];
-} ccol[MaxAttr];
-
-static int key = 0;
-
-// independent test bits
-static bool alignAddr; // align our buffer addresses to 4x
-static bool alignSize; // align data sizes to 4x
-static bool useBuf; // use our buffers for output
-static bool noRandom; // do not randomize sizes and offsets
-static int testbits = 4;
-
-static int
-makeSize(int i)
-{
- int n;
- if (noRandom)
- n = i;
- else
- n = i * randomizer;
- n %= sizelim;
- if (n <= 0)
- n = 1;
- if (alignSize)
- n = toAligned(n);
- return n;
-}
-
-static int
-makeOff(int k)
-{
- int n;
- if (alignAddr)
- n = 0;
- else if (noRandom)
- n = k;
- else
- n = k * randomizer;
- n %= MaxOff;
- if (n < 0)
- n = -n;
- return n;
-}
-
-static int
-testcase(Ndb_cluster_connection&cc, int flag)
-{
- ndbout << "--- case " << flag << " ---" << endl;
- sprintf(tab, "TB%02d", flag);
-
- alignAddr = ! (flag & 1);
- ndbout << (alignAddr ? "align addresses" : "mis-align addresses") << endl;
- alignSize = ! (flag & 2);
- ndbout << (alignSize ? "align data sizes" : "mis-align data sizes") << endl;
- useBuf = ! (flag & 4);
- ndbout << (useBuf ? "use our buffers" : "use ndbapi buffers") << endl;
- noRandom = ! (flag & 8);
- ndbout << (noRandom ? "simple sizes" : "randomize sizes") << endl;
-
- int smax = 0, stot = 0, i;
- if (xverbose)
- ndbout << "- define table " << tab << endl;
- for (i = 0; i < attrcnt; i++) {
- col& c = ccol[i];
- memset(&c, 0, sizeof(c));
- sprintf(c.aAttrName, "C%d", i);
- if (i == 0) {
- c.aAttrType = UnSigned;
- c.aAttrSize = 32;
- c.aArraySize = 1;
- c.aTupleKey = TupleKey;
- c.nullable = false;
- } else {
- c.aAttrType = String;
- c.aAttrSize = 8;
- c.aArraySize = makeSize(i);
- if (smax < c.aArraySize)
- smax = c.aArraySize;
- stot += c.aArraySize;
- c.aTupleKey = NoKey;
- c.nullable = true;
- if (xverbose)
- ndbout << "-- column " << i << " size=" << c.aArraySize << endl;
- }
- c.buf = toAligned(c.data);
- c.bufsiz = sizeof(c.data) - (c.buf - c.data);
- }
- ndbout << "tab=" << tab << " cols=" << attrcnt
- << " size max=" << smax << " tot=" << stot << endl;
-
- if ((tcon = NdbSchemaCon::startSchemaTrans(ndb)) == 0)
- return ndberror("startSchemaTransaction");
- if ((top = tcon->getNdbSchemaOp()) == 0)
- return ndberror("getNdbSchemaOp");
- if (top->createTable(tab) < 0)
- return ndberror("createTable");
- for (i = 0; i < attrcnt; i++) {
- col& c = ccol[i];
- if (top->createAttribute(
- c.aAttrName,
- c.aTupleKey,
- c.aAttrSize,
- c.aArraySize,
- c.aAttrType,
- MMBased,
- c.nullable
- ) < 0)
- return ndberror("createAttribute col=%d", i);
- }
- if (tcon->execute() < 0) {
- if (! (tcon->getNdbError().code == 721 && existok))
- return ndberror("execute");
- ndbout << "using " << tab << endl;
- } else {
- ndbout << "created " << tab << endl;
- }
- top = 0;
- tcon = 0;
-
- if (xverbose)
- ndbout << "- delete" << endl;
- int delcnt = 0;
- for (key = 0; key < opercnt; key++) {
- if ((con = ndb->startTransaction()) == 0)
- return ndberror("startTransaction key=%d", key);
- if ((op = con->getNdbOperation(tab)) == 0)
- return ndberror("getNdbOperation key=%d", key);
- if (op->deleteTuple() < 0)
- return ndberror("deleteTuple key=%d", key);
- for (i = 0; i < attrcnt; i++) {
- col& c = ccol[i];
- if (i == 0) {
- if (op->equal(c.aAttrName, (char*)&key, sizeof(key)) < 0)
- return ndberror("equal key=%d", key);
- } else {
- }
- }
- if (con->execute(Commit) < 0) {
- if (con->getNdbError().code != 626)
- return ndberror("execute key=%d", key);
- } else {
- delcnt++;
- }
- ndb->closeTransaction(con);
- }
- con = 0;
- op = 0;
- ndbout << "deleted " << delcnt << endl;
-
- if (xverbose)
- ndbout << "- insert" << endl;
- for (key = 0; key < opercnt; key++) {
- int off = makeOff(key);
- if ((con = ndb->startTransaction()) == 0)
- return ndberror("startTransaction key=%d", key);
- if ((op = con->getNdbOperation(tab)) == 0)
- return ndberror("getNdbOperation key=%d", key);
- if (op->insertTuple() < 0)
- return ndberror("insertTuple key=%d", key);
- for (i = 0; i < attrcnt; i++) {
- col& c = ccol[i];
- if (i == 0) {
- if (op->equal(c.aAttrName, (char*)&key, sizeof(key)) < 0)
- return ndberror("equal key=%d", key);
- } else {
- memset(c.buf, 'A', c.bufsiz);
- for (int j = 0; j < c.aArraySize; j++)
- c.buf[j + off] = byteVal(key, i, j);
- if (op->setValue(c.aAttrName, c.buf + off, c.aArraySize) < 0)
- return ndberror("setValue key=%d col=%d", key, i);
- }
- }
- if (con->execute(Commit) < 0)
- return ndberror("execute key=%d", key);
- ndb->closeTransaction(con);
- }
- con = 0;
- op = 0;
- ndbout << "inserted " << key << endl;
-
- if (xverbose)
- ndbout << "- select" << endl;
- for (key = 0; key < opercnt; key++) {
- int off = makeOff(key);
- if (xverbose)
- ndbout << "-- key " << key << " off=" << off << endl;
- if ((con = ndb->startTransaction()) == 0)
- return ndberror("startTransaction key=%d", key);
- if ((op = con->getNdbOperation(tab)) == 0)
- return ndberror("getNdbOperation key=%d", key);
- if (op->readTuple() < 0)
- return ndberror("readTuple key=%d", key);
- for (i = 0; i < attrcnt; i++) {
- col& c = ccol[i];
- if (i == 0) {
- if (op->equal(c.aAttrName, (char*)&key, sizeof(key)) < 0)
- return ndberror("equal key=%d", key);
- } else {
- if (xverbose) {
- char tmp[20];
- if (useBuf)
- sprintf(tmp, "0x%p", c.buf + off);
- else
- strcpy(tmp, "ndbapi");
- ndbout << "--- column " << i << " addr=" << tmp << endl;
- }
- memset(c.buf, 'B', c.bufsiz);
- if (useBuf) {
- if (op->getValue(c.aAttrName, c.buf + off) < 0)
- return ndberror("getValue key=%d col=%d", key, i);
- } else {
- if ((c.aRa = op->getValue(c.aAttrName)) == 0)
- return ndberror("getValue key=%d col=%d", key, i);
- }
- }
- }
- if (con->execute(Commit) != 0)
- return ndberror("execute key=%d", key);
- for (i = 0; i < attrcnt; i++) {
- col& c = ccol[i];
- if (i == 0) {
- } else if (useBuf) {
- int j;
- for (j = 0; j < off; j++) {
- if (c.buf[j] != 'B') {
- return chkerror("mismatch before key=%d col=%d pos=%d ok=%02x bad=%02x",
- key, i, j, 'B', c.buf[j]);
- }
- }
- for (j = 0; j < c.aArraySize; j++) {
- if (c.buf[j + off] != byteVal(key, i, j)) {
- return chkerror("mismatch key=%d col=%d pos=%d ok=%02x bad=%02x",
- key, i, j, byteVal(key, i, j), c.buf[j]);
- }
- }
- for (j = c.aArraySize + off; j < c.bufsiz; j++) {
- if (c.buf[j] != 'B') {
- return chkerror("mismatch after key=%d col=%d pos=%d ok=%02x bad=%02x",
- key, i, j, 'B', c.buf[j]);
- }
- }
- } else {
- char* buf = c.aRa->aRef();
- if (buf == 0)
- return ndberror("null aRef key=%d col%d", key, i);
- for (int j = 0; j < c.aArraySize; j++) {
- if (buf[j] != byteVal(key, i, j)) {
- return chkerror("mismatch key=%d col=%d pos=%d ok=%02x bad=%02x",
- key, i, j, byteVal(key, i, j), buf[j]);
- }
- }
- }
- }
- ndb->closeTransaction(con);
- }
- con = 0;
- op = 0;
- ndbout << "selected " << key << endl;
-
- if (xverbose)
- ndbout << "- scan" << endl;
- char found[MaxOper];
- int k;
- for (k = 0; k < opercnt; k++)
- found[k] = 0;
- for (key = 0; key < opercnt; key++) {
- int off = makeOff(key);
- if (xverbose)
- ndbout << "-- key " << key << " off=" << off << endl;
- int newkey = 0;
- if ((con = ndb->startTransaction()) == 0)
- return ndberror("startTransaction key=%d", key);
- if ((op = sop = con->getNdbScanOperation(tab)) == 0)
- return ndberror("getNdbOperation key=%d", key);
- if (sop->readTuples(1))
- return ndberror("openScanRead key=%d", key);
- {
- col& c = ccol[0];
- if (op->load_const_u32(1, key) < 0)
- return ndberror("load_const_u32");
- if (op->read_attr(c.aAttrName, 2) < 0)
- return ndberror("read_attr");
- if (op->branch_eq(1, 2, 0) < 0)
- return ndberror("branch_eq");
- if (op->interpret_exit_nok() < 0)
- return ndberror("interpret_exit_nok");
- if (op->def_label(0) < 0)
- return ndberror("def_label");
- if (op->interpret_exit_ok() < 0)
- return ndberror("interpret_exit_ok");
- }
- for (i = 0; i < attrcnt; i++) {
- col& c = ccol[i];
- if (i == 0) {
- if (op->getValue(c.aAttrName, (char*)&newkey) < 0)
- return ndberror("getValue key=%d col=%d", key, i);
- } else {
- if (xverbose) {
- char tmp[20];
- if (useBuf)
- sprintf(tmp, "0x%p", c.buf + off);
- else
- strcpy(tmp, "ndbapi");
- ndbout << "--- column " << i << " addr=" << tmp << endl;
- }
- memset(c.buf, 'C', c.bufsiz);
- if (useBuf) {
- if (op->getValue(c.aAttrName, c.buf + off) < 0)
- return ndberror("getValue key=%d col=%d", key, i);
- } else {
- if ((c.aRa = op->getValue(c.aAttrName)) == 0)
- return ndberror("getValue key=%d col=%d", key, i);
- }
- }
- }
- if (con->execute(NoCommit) < 0)
- return ndberror("executeScan key=%d", key);
- int ret, cnt = 0;
- while ((ret = sop->nextResult()) == 0) {
- if (key != newkey)
- return ndberror("unexpected key=%d newkey=%d", key, newkey);
- for (i = 1; i < attrcnt; i++) {
- col& c = ccol[i];
- if (useBuf) {
- int j;
- for (j = 0; j < off; j++) {
- if (c.buf[j] != 'C') {
- return chkerror("mismatch before key=%d col=%d pos=%d ok=%02x bad=%02x",
- key, i, j, 'C', c.buf[j]);
- }
- }
- for (j = 0; j < c.aArraySize; j++) {
- if (c.buf[j + off] != byteVal(key, i, j)) {
- return chkerror("mismatch key=%d col=%d pos=%d ok=%02x bad=%02x",
- key, i, j, byteVal(key, i, j), c.buf[j]);
- }
- }
- for (j = c.aArraySize + off; j < c.bufsiz; j++) {
- if (c.buf[j] != 'C') {
- return chkerror("mismatch after key=%d col=%d pos=%d ok=%02x bad=%02x",
- key, i, j, 'C', c.buf[j]);
- }
- }
- } else {
- char* buf = c.aRa->aRef();
- if (buf == 0)
- return ndberror("null aRef key=%d col%d", key, i);
- for (int j = 0; j < c.aArraySize; j++) {
- if (buf[j] != byteVal(key, i, j)) {
- return chkerror("mismatch key=%d col=%d pos=%d ok=%02x bad=%02x",
- key, i, j, byteVal(key, i, j), buf[j]);
- }
- }
- }
- }
- cnt++;
- }
- if (ret < 0)
- return ndberror("nextScanResult key=%d", key);
- if (cnt != 1)
- return ndberror("scan key=%d found %d", key, cnt);
- found[key] = 1;
- ndb->closeTransaction(con);
- }
- con = 0;
- op = 0;
- for (k = 0; k < opercnt; k++)
- if (! found[k])
- return ndberror("key %d not found", k);
- ndbout << "scanned " << key << endl;
-
- ndbout << "done" << endl;
- return 0;
-}
-
-NDB_COMMAND(testDataBuffers, "testDataBuffers", "testDataBuffers", "testDataBuffers", 65535)
-{
- int i;
- ndb_init();
- while (++argv, --argc > 0) {
- char const* p = argv[0];
- if (*p++ != '-' || strlen(p) != 1)
- goto wrongargs;
- switch (*p) {
- case 'a':
- if (++argv, --argc > 0) {
- attrcnt = atoi(argv[0]);
- if (1 <= attrcnt && attrcnt <= MaxAttr)
- break;
- }
- goto wrongargs;
- case 'e':
- existok = 1;
- break;
- case 'k':
- kontinue = true;
- break;
- case 'l':
- if (++argv, --argc > 0) {
- loopcnt = atoi(argv[0]);
- if (0 <= loopcnt)
- break;
- }
- goto wrongargs;
- case 'o':
- if (++argv, --argc > 0) {
- opercnt = atoi(argv[0]);
- if (0 <= opercnt && opercnt <= MaxOper)
- break;
- }
- goto wrongargs;
- case 'r':
- if (++argv, --argc > 0) {
- randomizer = atoi(argv[0]);
- if (1 <= randomizer)
- break;
- }
- goto wrongargs;
- case 's':
- if (++argv, --argc > 0) {
- sizelim = atoi(argv[0]);
- if (1 <= sizelim && sizelim <= MaxSize)
- break;
- }
- goto wrongargs;
- case 'x':
- xverbose = 1;
- break;
- default:
- wrongargs:
- printusage();
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
- }
-
- unsigned ok = true;
-
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1))
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- ndb = new Ndb(&con, "TEST_DB");
- if (ndb->init() != 0)
- {
- ndberror("init");
- ok = false;
- goto out;
- }
- if (ndb->waitUntilReady(30) < 0)
- {
- ndberror("waitUntilReady");
- ok = false;
- goto out;
- }
-
- for (i = 1; 0 == loopcnt || i <= loopcnt; i++) {
- ndbout << "=== loop " << i << " ===" << endl;
- for (int flag = 0; flag < (1<<testbits); flag++) {
- if (testcase(con, flag) < 0) {
- ok = false;
- if (! kontinue)
- goto out;
- }
- NdbDictionary::Dictionary * dict = ndb->getDictionary();
- dict->dropTable(tab);
- }
- }
-
-out:
- delete ndb;
- return NDBT_ProgramExit(ok ? NDBT_OK : NDBT_FAILED);
-}
-
-// vim: set sw=4:
diff --git a/storage/ndb/test/ndbapi/testDeadlock.cpp b/storage/ndb/test/ndbapi/testDeadlock.cpp
deleted file mode 100644
index 9c95b163e0b..00000000000
--- a/storage/ndb/test/ndbapi/testDeadlock.cpp
+++ /dev/null
@@ -1,523 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-#include <NdbMain.h>
-#include <NdbApi.hpp>
-#include <NdbOut.hpp>
-#include <NdbMutex.h>
-#include <NdbCondition.h>
-#include <NdbThread.h>
-#include <NdbTest.hpp>
-
-struct Opt {
- bool m_dbg;
- const char* m_scan;
- const char* m_tname;
- const char* m_xname;
- Opt() :
- m_dbg(true),
- m_scan("tx"),
- m_tname("T"),
- m_xname("X")
- {}
-};
-
-static void
-printusage()
-{
- Opt d;
- ndbout
- << "usage: testDeadlock" << endl
- << "-scan tx scan table, index [" << d.m_scan << "]" << endl
- ;
-}
-
-static Opt g_opt;
-
-static NdbMutex *ndbout_mutex= NULL;
-static Ndb_cluster_connection *g_cluster_connection= 0;
-#define DBG(x) \
- do { \
- if (! g_opt.m_dbg) break; \
- NdbMutex_Lock(ndbout_mutex); \
- ndbout << "line " << __LINE__ << " " << x << endl; \
- NdbMutex_Unlock(ndbout_mutex); \
- } while (0)
-
-#define CHK(x) \
- do { \
- if (x) break; \
- ndbout << "line " << __LINE__ << ": " << #x << " failed" << endl; \
- return -1; \
- } while (0)
-
-#define CHN(p, x) \
- do { \
- if (x) break; \
- ndbout << "line " << __LINE__ << ": " << #x << " failed" << endl; \
- ndbout << (p)->getNdbError() << endl; \
- return -1; \
- } while (0)
-
-// threads
-
-typedef int (*Runstep)(struct Thr& thr);
-
-struct Thr {
- enum State { Wait, Start, Stop, Stopped, Exit };
- State m_state;
- int m_no;
- Runstep m_runstep;
- int m_ret;
- NdbMutex* m_mutex;
- NdbCondition* m_cond;
- NdbThread* m_thread;
- void* m_status;
- Ndb* m_ndb;
- NdbConnection* m_con;
- NdbScanOperation* m_scanop;
- NdbIndexScanOperation* m_indexscanop;
- //
- Thr(int no);
- ~Thr();
- int run();
- void start(Runstep runstep);
- void stop();
- void stopped();
- void lock() { NdbMutex_Lock(m_mutex); }
- void unlock() { NdbMutex_Unlock(m_mutex); }
- void wait() { NdbCondition_Wait(m_cond, m_mutex); }
- void signal() { NdbCondition_Signal(m_cond); }
- void exit();
- void join() { NdbThread_WaitFor(m_thread, &m_status); }
-};
-
-static NdbOut&
-operator<<(NdbOut& out, const Thr& thr) {
- out << "thr " << thr.m_no;
- return out;
-}
-
-extern "C" { static void* runthread(void* arg); }
-
-Thr::Thr(int no)
-{
- m_state = Wait;
- m_no = no;
- m_runstep = 0;
- m_ret = 0;
- m_mutex = NdbMutex_Create();
- m_cond = NdbCondition_Create();
- assert(m_mutex != 0 && m_cond != 0);
- const unsigned stacksize = 256 * 1024;
- const NDB_THREAD_PRIO prio = NDB_THREAD_PRIO_LOW;
- m_thread = NdbThread_Create(runthread, (void**)this, stacksize, "me", prio);
- if (m_thread == 0) {
- DBG("create thread failed: errno=" << errno);
- m_ret = -1;
- }
- m_status = 0;
- m_ndb = 0;
- m_con = 0;
- m_scanop = 0;
- m_indexscanop = 0;
-}
-
-Thr::~Thr()
-{
- if (m_thread != 0)
- NdbThread_Destroy(&m_thread);
- if (m_cond != 0)
- NdbCondition_Destroy(m_cond);
- if (m_mutex != 0)
- NdbMutex_Destroy(m_mutex);
-}
-
-static void*
-runthread(void* arg) {
- Thr& thr = *(Thr*)arg;
- thr.run();
- return 0;
-}
-
-int
-Thr::run()
-{
- DBG(*this << " run");
- while (true) {
- lock();
- while (m_state != Start && m_state != Exit) {
- wait();
- }
- if (m_state == Exit) {
- DBG(*this << " exit");
- unlock();
- break;
- }
- m_ret = (*m_runstep)(*this);
- m_state = Stopped;
- signal();
- unlock();
- if (m_ret != 0) {
- DBG(*this << " error exit");
- break;
- }
- }
- delete m_ndb;
- m_ndb = 0;
- return 0;
-}
-
-void
-Thr::start(Runstep runstep)
-{
- lock();
- m_state = Start;
- m_runstep = runstep;
- signal();
- unlock();
-}
-
-void
-Thr::stopped()
-{
- lock();
- while (m_state != Stopped) {
- wait();
- }
- m_state = Wait;
- unlock();
-}
-
-void
-Thr::exit()
-{
- lock();
- m_state = Exit;
- signal();
- unlock();
-}
-
-// general
-
-static int
-runstep_connect(Thr& thr)
-{
- Ndb* ndb = thr.m_ndb = new Ndb(g_cluster_connection, "TEST_DB");
- CHN(ndb, ndb->init() == 0);
- CHN(ndb, ndb->waitUntilReady() == 0);
- DBG(thr << " connected");
- return 0;
-}
-
-static int
-runstep_starttx(Thr& thr)
-{
- Ndb* ndb = thr.m_ndb;
- assert(ndb != 0);
- CHN(ndb, (thr.m_con = ndb->startTransaction()) != 0);
- DBG("thr " << thr.m_no << " tx started");
- return 0;
-}
-
-/*
- * WL1822 flush locks
- *
- * Table T with 3 tuples X, Y, Z.
- * Two transactions (* = lock wait).
- *
- * - tx1 reads and locks Z
- * - tx2 scans X, Y, *Z
- * - tx2 returns X, Y before lock wait on Z
- * - tx1 reads and locks *X
- * - api asks for next tx2 result
- * - LQH unlocks X via ACC or TUX [*]
- * - tx1 gets lock on X
- * - tx1 returns X to api
- * - api commits tx1
- * - tx2 gets lock on Z
- * - tx2 returs Z to api
- *
- * The point is deadlock is avoided due to [*].
- * The test is for 1 db node and 1 fragment table.
- */
-
-static char wl1822_scantx = 0;
-
-static const Uint32 wl1822_valA[3] = { 0, 1, 2 };
-static const Uint32 wl1822_valB[3] = { 3, 4, 5 };
-
-static Uint32 wl1822_bufA = ~0;
-static Uint32 wl1822_bufB = ~0;
-
-// map scan row to key (A) and reverse
-static unsigned wl1822_r2k[3] = { 0, 0, 0 };
-static unsigned wl1822_k2r[3] = { 0, 0, 0 };
-
-static int
-wl1822_createtable(Thr& thr)
-{
- Ndb* ndb = thr.m_ndb;
- assert(ndb != 0);
- NdbDictionary::Dictionary* dic = ndb->getDictionary();
- // drop T
- if (dic->getTable(g_opt.m_tname) != 0)
- CHN(dic, dic->dropTable(g_opt.m_tname) == 0);
- // create T
- NdbDictionary::Table tab(g_opt.m_tname);
- tab.setFragmentType(NdbDictionary::Object::FragAllSmall);
- { NdbDictionary::Column col("A");
- col.setType(NdbDictionary::Column::Unsigned);
- col.setPrimaryKey(true);
- tab.addColumn(col);
- }
- { NdbDictionary::Column col("B");
- col.setType(NdbDictionary::Column::Unsigned);
- col.setPrimaryKey(false);
- tab.addColumn(col);
- }
- CHN(dic, dic->createTable(tab) == 0);
- // create X
- NdbDictionary::Index ind(g_opt.m_xname);
- ind.setTable(g_opt.m_tname);
- ind.setType(NdbDictionary::Index::OrderedIndex);
- ind.setLogging(false);
- ind.addColumn("B");
- CHN(dic, dic->createIndex(ind) == 0);
- DBG("created " << g_opt.m_tname << ", " << g_opt.m_xname);
- return 0;
-}
-
-static int
-wl1822_insertrows(Thr& thr)
-{
- // insert X, Y, Z
- Ndb* ndb = thr.m_ndb;
- assert(ndb != 0);
- NdbConnection* con;
- NdbOperation* op;
- for (unsigned k = 0; k < 3; k++) {
- CHN(ndb, (con = ndb->startTransaction()) != 0);
- CHN(con, (op = con->getNdbOperation(g_opt.m_tname)) != 0);
- CHN(op, op->insertTuple() == 0);
- CHN(op, op->equal("A", (char*)&wl1822_valA[k]) == 0);
- CHN(op, op->setValue("B", (char*)&wl1822_valB[k]) == 0);
- CHN(con, con->execute(Commit) == 0);
- ndb->closeTransaction(con);
- }
- DBG("inserted X, Y, Z");
- return 0;
-}
-
-static int
-wl1822_getscanorder(Thr& thr)
-{
- // cheat, table order happens to be key order in my test
- wl1822_r2k[0] = 0;
- wl1822_r2k[1] = 1;
- wl1822_r2k[2] = 2;
- wl1822_k2r[0] = 0;
- wl1822_k2r[1] = 1;
- wl1822_k2r[2] = 2;
- DBG("scan order determined");
- return 0;
-}
-
-static int
-wl1822_tx1_readZ(Thr& thr)
-{
- // tx1 read Z with exclusive lock
- NdbConnection* con = thr.m_con;
- assert(con != 0);
- NdbOperation* op;
- CHN(con, (op = con->getNdbOperation(g_opt.m_tname)) != 0);
- CHN(op, op->readTupleExclusive() == 0);
- CHN(op, op->equal("A", wl1822_valA[wl1822_r2k[2]]) == 0);
- wl1822_bufB = ~0;
- CHN(op, op->getValue("B", (char*)&wl1822_bufB) != 0);
- CHN(con, con->execute(NoCommit) == 0);
- CHK(wl1822_bufB == wl1822_valB[wl1822_r2k[2]]);
- DBG("tx1 locked Z");
- return 0;
-}
-
-static int
-wl1822_tx2_scanXY(Thr& thr)
-{
- // tx2 scan X, Y with exclusive lock
- NdbConnection* con = thr.m_con;
- assert(con != 0);
- NdbScanOperation* scanop;
- NdbIndexScanOperation* indexscanop;
- NdbResultSet* rs;
- if (wl1822_scantx == 't') {
- CHN(con, (scanop = thr.m_scanop = con->getNdbScanOperation(g_opt.m_tname)) != 0);
- DBG("tx2 scan exclusive " << g_opt.m_tname);
- }
- if (wl1822_scantx == 'x') {
- CHN(con, (scanop = thr.m_scanop = indexscanop = thr.m_indexscanop = con->getNdbIndexScanOperation(g_opt.m_xname, g_opt.m_tname)) != 0);
- DBG("tx2 scan exclusive " << g_opt.m_xname);
- }
- CHN(scanop, scanop->readTuplesExclusive(16) == 0);
- CHN(scanop, scanop->getValue("A", (char*)&wl1822_bufA) != 0);
- CHN(scanop, scanop->getValue("B", (char*)&wl1822_bufB) != 0);
- CHN(con, con->execute(NoCommit) == 0);
- unsigned row = 0;
- while (row < 2) {
- DBG("before row " << row);
- int ret;
- wl1822_bufA = wl1822_bufB = ~0;
- CHN(con, (ret = scanop->nextResult(true)) == 0);
- DBG("got row " << row << " a=" << wl1822_bufA << " b=" << wl1822_bufB);
- CHK(wl1822_bufA == wl1822_valA[wl1822_r2k[row]]);
- CHK(wl1822_bufB == wl1822_valB[wl1822_r2k[row]]);
- row++;
- }
- return 0;
-}
-
-static int
-wl1822_tx1_readX_commit(Thr& thr)
-{
- // tx1 read X with exclusive lock and commit
- NdbConnection* con = thr.m_con;
- assert(con != 0);
- NdbOperation* op;
- CHN(con, (op = con->getNdbOperation(g_opt.m_tname)) != 0);
- CHN(op, op->readTupleExclusive() == 0);
- CHN(op, op->equal("A", wl1822_valA[wl1822_r2k[2]]) == 0);
- wl1822_bufB = ~0;
- CHN(op, op->getValue("B", (char*)&wl1822_bufB) != 0);
- CHN(con, con->execute(NoCommit) == 0);
- CHK(wl1822_bufB == wl1822_valB[wl1822_r2k[2]]);
- DBG("tx1 locked X");
- CHN(con, con->execute(Commit) == 0);
- DBG("tx1 commit");
- return 0;
-}
-
-static int
-wl1822_tx2_scanZ_close(Thr& thr)
-{
- // tx2 scan Z with exclusive lock and close scan
- Ndb* ndb = thr.m_ndb;
- NdbConnection* con = thr.m_con;
- NdbScanOperation* scanop = thr.m_scanop;
- assert(ndb != 0 && con != 0 && scanop != 0);
- unsigned row = 2;
- while (true) {
- DBG("before row " << row);
- int ret;
- wl1822_bufA = wl1822_bufB = ~0;
- CHN(con, (ret = scanop->nextResult(true)) == 0 || ret == 1);
- if (ret == 1)
- break;
- DBG("got row " << row << " a=" << wl1822_bufA << " b=" << wl1822_bufB);
- CHK(wl1822_bufA == wl1822_valA[wl1822_r2k[row]]);
- CHK(wl1822_bufB == wl1822_valB[wl1822_r2k[row]]);
- row++;
- }
- ndb->closeTransaction(con);
- CHK(row == 3);
- return 0;
-}
-
-// threads are synced between each step
-static Runstep wl1822_step[][2] = {
- { runstep_connect, runstep_connect },
- { wl1822_createtable, 0 },
- { wl1822_insertrows, 0 },
- { wl1822_getscanorder, 0 },
- { runstep_starttx, runstep_starttx },
- { wl1822_tx1_readZ, 0 },
- { 0, wl1822_tx2_scanXY },
- { wl1822_tx1_readX_commit, wl1822_tx2_scanZ_close }
-};
-const unsigned wl1822_stepcount = sizeof(wl1822_step)/sizeof(wl1822_step[0]);
-
-static int
-wl1822_main(char scantx)
-{
- wl1822_scantx = scantx;
- static const unsigned thrcount = 2;
- // create threads for tx1 and tx2
- Thr* thrlist[2];
- int n;
- for (n = 0; n < thrcount; n++) {
- Thr& thr = *(thrlist[n] = new Thr(1 + n));
- CHK(thr.m_ret == 0);
- }
- // run the steps
- for (unsigned i = 0; i < wl1822_stepcount; i++) {
- DBG("step " << i << " start");
- for (n = 0; n < thrcount; n++) {
- Thr& thr = *thrlist[n];
- Runstep runstep = wl1822_step[i][n];
- if (runstep != 0)
- thr.start(runstep);
- }
- for (n = 0; n < thrcount; n++) {
- Thr& thr = *thrlist[n];
- Runstep runstep = wl1822_step[i][n];
- if (runstep != 0)
- thr.stopped();
- }
- }
- // delete threads
- for (n = 0; n < thrcount; n++) {
- Thr& thr = *thrlist[n];
- thr.exit();
- thr.join();
- delete &thr;
- }
- return 0;
-}
-
-NDB_COMMAND(testOdbcDriver, "testDeadlock", "testDeadlock", "testDeadlock", 65535)
-{
- ndb_init();
- if (ndbout_mutex == NULL)
- ndbout_mutex= NdbMutex_Create();
- while (++argv, --argc > 0) {
- const char* arg = argv[0];
- if (strcmp(arg, "-scan") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_scan = strdup(argv[0]);
- continue;
- }
- }
- printusage();
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- g_cluster_connection= &con;
-
- if (
- strchr(g_opt.m_scan, 't') != 0 && wl1822_main('t') == -1 ||
- strchr(g_opt.m_scan, 'x') != 0 && wl1822_main('x') == -1
- ) {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- return NDBT_ProgramExit(NDBT_OK);
-}
-
-// vim: set sw=2 et:
diff --git a/storage/ndb/test/ndbapi/testDict.cpp b/storage/ndb/test/ndbapi/testDict.cpp
deleted file mode 100644
index 88e94239ea8..00000000000
--- a/storage/ndb/test/ndbapi/testDict.cpp
+++ /dev/null
@@ -1,3301 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT.hpp>
-#include <NDBT_Test.hpp>
-#include <HugoTransactions.hpp>
-#include <UtilTransactions.hpp>
-#include <NdbRestarter.hpp>
-#include <Vector.hpp>
-#include <signaldata/DumpStateOrd.hpp>
-#include <../../include/kernel/ndb_limits.h>
-#include <random.h>
-#include <NdbAutoPtr.hpp>
-#include <NdbMixRestarter.hpp>
-
-#define CHECK(b) if (!(b)) { \
- g_err << "ERR: "<< step->getName() \
- << " failed on line " << __LINE__ << endl; \
- result = NDBT_FAILED; \
- break; }
-
-#define CHECK2(b, c) if (!(b)) { \
- g_err << "ERR: "<< step->getName() \
- << " failed on line " << __LINE__ << ": " << c << endl; \
- result = NDBT_FAILED; \
- goto end; }
-
-int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- int records = ctx->getNumRecords();
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.loadTable(pNdb, records) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-
-int runCreateInvalidTables(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- int result = NDBT_OK;
-
- char failTabName[256];
-
- for (int i = 0; i < 10; i++){
- BaseString::snprintf(failTabName, 256, "F%d", i);
-
- const NdbDictionary::Table* pFailTab = NDBT_Tables::getTable(failTabName);
- if (pFailTab != NULL){
- ndbout << "|- " << failTabName << endl;
-
- // Try to create table in db
- if (pFailTab->createTableInDb(pNdb) == 0){
- ndbout << failTabName << " created, this was not expected"<< endl;
- result = NDBT_FAILED;
- }
-
- // Verify that table is not in db
- const NdbDictionary::Table* pTab2 =
- NDBT_Table::discoverTableFromDb(pNdb, failTabName) ;
- if (pTab2 != NULL){
- ndbout << failTabName << " was found in DB, this was not expected"<< endl;
- result = NDBT_FAILED;
- if (pFailTab->equal(*pTab2) == true){
- ndbout << "It was equal" << endl;
- } else {
- ndbout << "It was not equal" << endl;
- }
- int records = 1000;
- HugoTransactions hugoTrans(*pTab2);
- if (hugoTrans.loadTable(pNdb, records) != 0){
- ndbout << "It can NOT be loaded" << endl;
- } else{
- ndbout << "It can be loaded" << endl;
-
- UtilTransactions utilTrans(*pTab2);
- if (utilTrans.clearTable(pNdb, records, 64) != 0){
- ndbout << "It can NOT be cleared" << endl;
- } else{
- ndbout << "It can be cleared" << endl;
- }
- }
-
- if (pNdb->getDictionary()->dropTable(pTab2->getName()) == -1){
- ndbout << "It can NOT be dropped" << endl;
- } else {
- ndbout << "It can be dropped" << endl;
- }
- }
- }
- }
- return result;
-}
-
-int runCreateTheTable(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- const NdbDictionary::Table* pTab = ctx->getTab();
-
- // Try to create table in db
- if (NDBT_Tables::createTable(pNdb, pTab->getName()) != 0){
- return NDBT_FAILED;
- }
-
- // Verify that table is in db
- const NdbDictionary::Table* pTab2 =
- NDBT_Table::discoverTableFromDb(pNdb, pTab->getName());
- if (pTab2 == NULL){
- ndbout << pTab->getName() << " was not found in DB"<< endl;
- return NDBT_FAILED;
- }
- ctx->setTab(pTab2);
-
- return NDBT_OK;
-}
-
-int runDropTheTable(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- const NdbDictionary::Table* pTab = ctx->getTab();
-
- // Try to create table in db
- pNdb->getDictionary()->dropTable(pTab->getName());
-
- return NDBT_OK;
-}
-
-int runCreateTableWhenDbIsFull(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- int result = NDBT_OK;
- const char* tabName = "TRANSACTION"; //Use a util table
-
- const NdbDictionary::Table* pTab = NDBT_Tables::getTable(tabName);
- if (pTab != NULL){
- ndbout << "|- " << tabName << endl;
-
- // Verify that table is not in db
- if (NDBT_Table::discoverTableFromDb(pNdb, tabName) != NULL){
- ndbout << tabName << " was found in DB"<< endl;
- return NDBT_FAILED;
- }
-
- // Try to create table in db
- if (NDBT_Tables::createTable(pNdb, pTab->getName()) == 0){
- result = NDBT_FAILED;
- }
-
- // Verify that table is in db
- if (NDBT_Table::discoverTableFromDb(pNdb, tabName) != NULL){
- ndbout << tabName << " was found in DB"<< endl;
- result = NDBT_FAILED;
- }
- }
-
- return result;
-}
-
-int runDropTableWhenDbIsFull(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- int result = NDBT_OK;
- const char* tabName = "TRANSACTION"; //Use a util table
-
- const NdbDictionary::Table* pTab = NDBT_Table::discoverTableFromDb(pNdb, tabName);
- if (pTab != NULL){
- ndbout << "|- TRANSACTION" << endl;
-
- // Try to drop table in db
- if (pNdb->getDictionary()->dropTable(pTab->getName()) == -1){
- result = NDBT_FAILED;
- }
-
- // Verify that table is not in db
- if (NDBT_Table::discoverTableFromDb(pNdb, tabName) != NULL){
- ndbout << tabName << " was found in DB"<< endl;
- result = NDBT_FAILED;
- }
- }
-
- return result;
-
-}
-
-
-int runCreateAndDrop(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- int loops = ctx->getNumLoops();
- int i = 0;
-
- const NdbDictionary::Table* pTab = ctx->getTab();
- ndbout << "|- " << pTab->getName() << endl;
-
- while (i < loops){
-
- ndbout << i << ": ";
- // Try to create table in db
- if (NDBT_Tables::createTable(pNdb, pTab->getName()) != 0){
- return NDBT_FAILED;
- }
-
- // Verify that table is in db
- const NdbDictionary::Table* pTab2 =
- NDBT_Table::discoverTableFromDb(pNdb, pTab->getName());
- if (pTab2 == NULL){
- ndbout << pTab->getName() << " was not found in DB"<< endl;
- return NDBT_FAILED;
- }
-
- if (pNdb->getDictionary()->dropTable(pTab2->getName())){
- ndbout << "Failed to drop "<<pTab2->getName()<<" in db" << endl;
- return NDBT_FAILED;
- }
-
- // Verify that table is not in db
- const NdbDictionary::Table* pTab3 =
- NDBT_Table::discoverTableFromDb(pNdb, pTab->getName());
- if (pTab3 != NULL){
- ndbout << pTab3->getName() << " was found in DB"<< endl;
- return NDBT_FAILED;
- }
- i++;
- }
-
- return NDBT_OK;
-}
-
-int runCreateAndDropAtRandom(NDBT_Context* ctx, NDBT_Step* step)
-{
- myRandom48Init(NdbTick_CurrentMillisecond());
- Ndb* pNdb = GETNDB(step);
- NdbDictionary::Dictionary* pDic = pNdb->getDictionary();
- int loops = ctx->getNumLoops();
- int numTables = NDBT_Tables::getNumTables();
- bool* tabList = new bool [ numTables ];
- int tabCount;
-
- {
- for (int num = 0; num < numTables; num++) {
- (void)pDic->dropTable(NDBT_Tables::getTable(num)->getName());
- tabList[num] = false;
- }
- tabCount = 0;
- }
-
- NdbRestarter restarter;
- int result = NDBT_OK;
- int bias = 1; // 0-less 1-more
- int i = 0;
-
- while (i < loops) {
- g_info << "loop " << i << " tabs " << tabCount << "/" << numTables << endl;
- int num = myRandom48(numTables);
- const NdbDictionary::Table* pTab = NDBT_Tables::getTable(num);
- char tabName[200];
- strcpy(tabName, pTab->getName());
-
- if (tabList[num] == false) {
- if (bias == 0 && myRandom48(100) < 80)
- continue;
- g_info << tabName << ": create" << endl;
- if (pDic->createTable(*pTab) != 0) {
- const NdbError err = pDic->getNdbError();
- g_err << tabName << ": create failed: " << err << endl;
- result = NDBT_FAILED;
- break;
- }
- const NdbDictionary::Table* pTab2 = pDic->getTable(tabName);
- if (pTab2 == NULL) {
- const NdbError err = pDic->getNdbError();
- g_err << tabName << ": verify create: " << err << endl;
- result = NDBT_FAILED;
- break;
- }
- tabList[num] = true;
- assert(tabCount < numTables);
- tabCount++;
- if (tabCount == numTables)
- bias = 0;
- }
- else {
- if (bias == 1 && myRandom48(100) < 80)
- continue;
- g_info << tabName << ": drop" << endl;
- if (restarter.insertErrorInAllNodes(4013) != 0) {
- g_err << "error insert failed" << endl;
- result = NDBT_FAILED;
- break;
- }
- if (pDic->dropTable(tabName) != 0) {
- const NdbError err = pDic->getNdbError();
- g_err << tabName << ": drop failed: " << err << endl;
- result = NDBT_FAILED;
- break;
- }
- const NdbDictionary::Table* pTab2 = pDic->getTable(tabName);
- if (pTab2 != NULL) {
- g_err << tabName << ": verify drop: table exists" << endl;
- result = NDBT_FAILED;
- break;
- }
- if (pDic->getNdbError().code != 709 &&
- pDic->getNdbError().code != 723) {
- const NdbError err = pDic->getNdbError();
- g_err << tabName << ": verify drop: " << err << endl;
- result = NDBT_FAILED;
- break;
- }
- tabList[num] = false;
- assert(tabCount > 0);
- tabCount--;
- if (tabCount == 0)
- bias = 1;
- }
- i++;
- }
-
- for (Uint32 i = 0; i<numTables; i++)
- if (tabList[i])
- pDic->dropTable(NDBT_Tables::getTable(i)->getName());
-
- delete [] tabList;
- return result;
-}
-
-
-int runCreateAndDropWithData(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int i = 0;
-
- NdbRestarter restarter;
- int val = DumpStateOrd::DihMinTimeBetweenLCP;
- if(restarter.dumpStateAllNodes(&val, 1) != 0){
- int result;
- do { CHECK(0); } while (0);
- g_err << "Unable to change timebetween LCP" << endl;
- return NDBT_FAILED;
- }
-
- const NdbDictionary::Table* pTab = ctx->getTab();
- ndbout << "|- " << pTab->getName() << endl;
-
- while (i < loops){
- ndbout << i << ": ";
- // Try to create table in db
-
- if (NDBT_Tables::createTable(pNdb, pTab->getName()) != 0){
- return NDBT_FAILED;
- }
-
- // Verify that table is in db
- const NdbDictionary::Table* pTab2 =
- NDBT_Table::discoverTableFromDb(pNdb, pTab->getName());
- if (pTab2 == NULL){
- ndbout << pTab->getName() << " was not found in DB"<< endl;
- return NDBT_FAILED;
- }
-
- HugoTransactions hugoTrans(*pTab2);
- if (hugoTrans.loadTable(pNdb, records) != 0){
- return NDBT_FAILED;
- }
-
- int count = 0;
- UtilTransactions utilTrans(*pTab2);
- if (utilTrans.selectCount(pNdb, 64, &count) != 0){
- return NDBT_FAILED;
- }
- if (count != records){
- ndbout << count <<" != "<<records << endl;
- return NDBT_FAILED;
- }
-
- if (pNdb->getDictionary()->dropTable(pTab2->getName()) != 0){
- ndbout << "Failed to drop "<<pTab2->getName()<<" in db" << endl;
- return NDBT_FAILED;
- }
-
- // Verify that table is not in db
- const NdbDictionary::Table* pTab3 =
- NDBT_Table::discoverTableFromDb(pNdb, pTab->getName());
- if (pTab3 != NULL){
- ndbout << pTab3->getName() << " was found in DB"<< endl;
- return NDBT_FAILED;
- }
-
-
- i++;
- }
-
- return NDBT_OK;
-}
-
-int runFillTable(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.fillTable(pNdb) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- int records = ctx->getNumRecords();
-
- UtilTransactions utilTrans(*ctx->getTab());
- if (utilTrans.clearTable(pNdb, records) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runCreateAndDropDuring(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int i = 0;
-
- const NdbDictionary::Table* pTab = ctx->getTab();
- ndbout << "|- " << pTab->getName() << endl;
-
- while (i < loops && result == NDBT_OK){
- ndbout << i << ": " << endl;
- // Try to create table in db
-
- Ndb* pNdb = GETNDB(step);
- g_debug << "Creating table" << endl;
-
- if (NDBT_Tables::createTable(pNdb, pTab->getName()) != 0){
- g_err << "createTableInDb failed" << endl;
- result = NDBT_FAILED;
- continue;
- }
-
- g_debug << "Verifying creation of table" << endl;
-
- // Verify that table is in db
- const NdbDictionary::Table* pTab2 =
- NDBT_Table::discoverTableFromDb(pNdb, pTab->getName());
- if (pTab2 == NULL){
- g_err << pTab->getName() << " was not found in DB"<< endl;
- result = NDBT_FAILED;
- continue;
- }
-
- NdbSleep_MilliSleep(3000);
-
- g_debug << "Dropping table" << endl;
-
- if (pNdb->getDictionary()->dropTable(pTab2->getName()) != 0){
- g_err << "Failed to drop "<<pTab2->getName()<<" in db" << endl;
- result = NDBT_FAILED;
- continue;
- }
-
- g_debug << "Verifying dropping of table" << endl;
-
- // Verify that table is not in db
- const NdbDictionary::Table* pTab3 =
- NDBT_Table::discoverTableFromDb(pNdb, pTab->getName());
- if (pTab3 != NULL){
- g_err << pTab3->getName() << " was found in DB"<< endl;
- result = NDBT_FAILED;
- continue;
- }
- i++;
- }
- ctx->stopTest();
-
- return result;
-}
-
-
-int runUseTableUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
-
- const NdbDictionary::Table* pTab = ctx->getTab();
-
- while (ctx->isTestStopped() == false) {
- // g_info << i++ << ": ";
-
-
- // Delete and recreate Ndb object
- // Otherwise you always get Invalid Schema Version
- // It would be a nice feature to remove this two lines
- //step->tearDown();
- //step->setUp();
-
- Ndb* pNdb = GETNDB(step);
-
- const NdbDictionary::Table* pTab2 =
- NDBT_Table::discoverTableFromDb(pNdb, pTab->getName());
- if (pTab2 == NULL)
- continue;
-
- int res;
- HugoTransactions hugoTrans(*pTab2);
- if ((res = hugoTrans.loadTable(pNdb, records)) != 0){
- NdbError err = pNdb->getNdbError(res);
- if(err.classification == NdbError::SchemaError){
- pNdb->getDictionary()->invalidateTable(pTab->getName());
- }
- continue;
- }
-
- UtilTransactions utilTrans(*pTab2);
- if ((res = utilTrans.clearTable(pNdb, records)) != 0){
- NdbError err = pNdb->getNdbError(res);
- if(err.classification == NdbError::SchemaError){
- pNdb->getDictionary()->invalidateTable(pTab->getName());
- }
- continue;
- }
- }
- g_info << endl;
- return NDBT_OK;
-}
-
-
-int
-runCreateMaxTables(NDBT_Context* ctx, NDBT_Step* step)
-{
- char tabName[256];
- int numTables = ctx->getProperty("tables", 1000);
- Ndb* pNdb = GETNDB(step);
- NdbDictionary::Dictionary* pDic = pNdb->getDictionary();
- int i = 0;
- for (i = 0; i < numTables; i++) {
- BaseString::snprintf(tabName, 256, "MAXTAB%d", i);
- if (pNdb->waitUntilReady(30) != 0) {
- // Db is not ready, return with failure
- return NDBT_FAILED;
- }
- const NdbDictionary::Table* pTab = ctx->getTab();
- //ndbout << "|- " << tabName << endl;
- // Set new name for T1
- NdbDictionary::Table newTab(* pTab);
- newTab.setName(tabName);
- // Drop any old (or try to)
- (void)pDic->dropTable(newTab.getName());
- // Try to create table in db
- if (newTab.createTableInDb(pNdb) != 0) {
- ndbout << tabName << " could not be created: "
- << pDic->getNdbError() << endl;
- if (pDic->getNdbError().code == 707 ||
- pDic->getNdbError().code == 708 ||
- pDic->getNdbError().code == 826 ||
- pDic->getNdbError().code == 827)
- break;
- return NDBT_FAILED;
- }
- // Verify that table exists in db
- const NdbDictionary::Table* pTab3 =
- NDBT_Table::discoverTableFromDb(pNdb, tabName) ;
- if (pTab3 == NULL){
- ndbout << tabName << " was not found in DB: "
- << pDic->getNdbError() << endl;
- return NDBT_FAILED;
- }
- if (! newTab.equal(*pTab3)) {
- ndbout << "It was not equal" << endl; abort();
- return NDBT_FAILED;
- }
- int records = ctx->getNumRecords();
- HugoTransactions hugoTrans(*pTab3);
- if (hugoTrans.loadTable(pNdb, records) != 0) {
- ndbout << "It can NOT be loaded" << endl;
- return NDBT_FAILED;
- }
- UtilTransactions utilTrans(*pTab3);
- if (utilTrans.clearTable(pNdb, records, 64) != 0) {
- ndbout << "It can NOT be cleared" << endl;
- return NDBT_FAILED;
- }
- }
- if (pNdb->waitUntilReady(30) != 0) {
- // Db is not ready, return with failure
- return NDBT_FAILED;
- }
- ctx->setProperty("maxtables", i);
- // HURRAAA!
- return NDBT_OK;
-}
-
-int runDropMaxTables(NDBT_Context* ctx, NDBT_Step* step)
-{
- char tabName[256];
- int numTables = ctx->getProperty("maxtables", (Uint32)0);
- Ndb* pNdb = GETNDB(step);
- NdbDictionary::Dictionary* pDic = pNdb->getDictionary();
- for (int i = 0; i < numTables; i++) {
- BaseString::snprintf(tabName, 256, "MAXTAB%d", i);
- if (pNdb->waitUntilReady(30) != 0) {
- // Db is not ready, return with failure
- return NDBT_FAILED;
- }
- // Verify that table exists in db
- const NdbDictionary::Table* pTab3 =
- NDBT_Table::discoverTableFromDb(pNdb, tabName) ;
- if (pTab3 == NULL) {
- ndbout << tabName << " was not found in DB: "
- << pDic->getNdbError() << endl;
- return NDBT_FAILED;
- }
- // Try to drop table in db
- if (pDic->dropTable(pTab3->getName()) != 0) {
- ndbout << tabName << " could not be dropped: "
- << pDic->getNdbError() << endl;
- return NDBT_FAILED;
- }
- }
- return NDBT_OK;
-}
-
-int runTestFragmentTypes(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
- int fragTtype = ctx->getProperty("FragmentType");
- Ndb* pNdb = GETNDB(step);
- int result = NDBT_OK;
- NdbRestarter restarter;
-
- if (pNdb->waitUntilReady(30) != 0){
- // Db is not ready, return with failure
- return NDBT_FAILED;
- }
-
- const NdbDictionary::Table* pTab = ctx->getTab();
- pNdb->getDictionary()->dropTable(pTab->getName());
-
- NdbDictionary::Table newTab(* pTab);
- // Set fragment type for table
- newTab.setFragmentType((NdbDictionary::Object::FragmentType)fragTtype);
-
- // Try to create table in db
- if (newTab.createTableInDb(pNdb) != 0){
- ndbout << newTab.getName() << " could not be created"
- << ", fragmentType = "<<fragTtype <<endl;
- ndbout << pNdb->getDictionary()->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- // Verify that table exists in db
- const NdbDictionary::Table* pTab3 =
- NDBT_Table::discoverTableFromDb(pNdb, pTab->getName()) ;
- if (pTab3 == NULL){
- ndbout << pTab->getName() << " was not found in DB"<< endl;
- return NDBT_FAILED;
-
- }
-
- if (pTab3->getFragmentType() != fragTtype){
- ndbout << pTab->getName() << " fragmentType error "<< endl;
- result = NDBT_FAILED;
- goto drop_the_tab;
- }
-/**
- This test does not work since fragmentation is
- decided by the kernel, hence the fragementation
- attribute on the column will differ
-
- if (newTab.equal(*pTab3) == false){
- ndbout << "It was not equal" << endl;
- result = NDBT_FAILED;
- goto drop_the_tab;
- }
-*/
- do {
-
- HugoTransactions hugoTrans(*pTab3);
- UtilTransactions utilTrans(*pTab3);
- int count;
- CHECK(hugoTrans.loadTable(pNdb, records) == 0);
- CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == records);
- CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);
- CHECK(hugoTrans.scanUpdateRecords(pNdb, records/2) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == (records/2));
-
- // restart all
- ndbout << "Restarting cluster" << endl;
- CHECK(restarter.restartAll() == 0);
- int timeout = 120;
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- // Verify content
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == (records/2));
-
- CHECK(utilTrans.clearTable(pNdb, records) == 0);
- CHECK(hugoTrans.loadTable(pNdb, records) == 0);
- CHECK(utilTrans.clearTable(pNdb, records) == 0);
- CHECK(hugoTrans.loadTable(pNdb, records) == 0);
- CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
- CHECK(utilTrans.clearTable(pNdb, records, 64) == 0);
-
- } while(false);
-
- drop_the_tab:
-
- // Try to drop table in db
- if (pNdb->getDictionary()->dropTable(pTab3->getName()) != 0){
- ndbout << pTab3->getName() << " could not be dropped"<< endl;
- result = NDBT_FAILED;
- }
-
- return result;
-}
-
-
-int runTestTemporaryTables(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- Ndb* pNdb = GETNDB(step);
- int i = 0;
- NdbRestarter restarter;
-
- const NdbDictionary::Table* pTab = ctx->getTab();
- ndbout << "|- " << pTab->getName() << endl;
-
- NdbDictionary::Table newTab(* pTab);
- // Set table as temporary
- newTab.setStoredTable(false);
-
- // Try to create table in db
- if (newTab.createTableInDb(pNdb) != 0){
- return NDBT_FAILED;
- }
-
- // Verify that table is in db
- const NdbDictionary::Table* pTab2 =
- NDBT_Table::discoverTableFromDb(pNdb, pTab->getName());
- if (pTab2 == NULL){
- ndbout << pTab->getName() << " was not found in DB"<< endl;
- return NDBT_FAILED;
- }
-
- if (pTab2->getStoredTable() != false){
- ndbout << pTab->getName() << " was not temporary in DB"<< endl;
- result = NDBT_FAILED;
- goto drop_the_tab;
- }
-
-
- while (i < loops && result == NDBT_OK){
- ndbout << i << ": ";
-
- HugoTransactions hugoTrans(*pTab2);
- CHECK(hugoTrans.loadTable(pNdb, records) == 0);
-
- int count = 0;
- UtilTransactions utilTrans(*pTab2);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == records);
-
- // restart all
- ndbout << "Restarting cluster" << endl;
- CHECK(restarter.restartAll() == 0);
- int timeout = 120;
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- ndbout << "Verifying records..." << endl;
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == 0);
-
- i++;
- }
-
- drop_the_tab:
-
-
- if (pNdb->getDictionary()->dropTable(pTab2->getName()) != 0){
- ndbout << "Failed to drop "<<pTab2->getName()<<" in db" << endl;
- result = NDBT_FAILED;
- }
-
- // Verify that table is not in db
- const NdbDictionary::Table* pTab3 =
- NDBT_Table::discoverTableFromDb(pNdb, pTab->getName());
- if (pTab3 != NULL){
- ndbout << pTab3->getName() << " was found in DB"<< endl;
- result = NDBT_FAILED;
- }
-
- return result;
-}
-
-int runPkSizes(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- char tabName[256];
- int minPkSize = 1;
- ndbout << "minPkSize=" <<minPkSize<<endl;
- int maxPkSize = MAX_KEY_SIZE_IN_WORDS * 4;
- ndbout << "maxPkSize=" <<maxPkSize<<endl;
- Ndb* pNdb = GETNDB(step);
- int numRecords = ctx->getNumRecords();
-
- for (int i = minPkSize; i < maxPkSize; i++){
- BaseString::snprintf(tabName, 256, "TPK_%d", i);
-
- int records = numRecords;
- int max = ~0;
- // Limit num records for small PKs
- if (i == 1)
- max = 99;
- if (i == 2)
- max = 999;
- if (i == 3)
- max = 9999;
- if (records > max)
- records = max;
- ndbout << "records =" << records << endl;
-
- if (pNdb->waitUntilReady(30) != 0){
- // Db is not ready, return with failure
- return NDBT_FAILED;
- }
-
- ndbout << "|- " << tabName << endl;
-
- if (NDBT_Tables::createTable(pNdb, tabName) != 0){
- ndbout << tabName << " could not be created"<< endl;
- return NDBT_FAILED;
- }
-
- // Verify that table exists in db
- const NdbDictionary::Table* pTab3 =
- NDBT_Table::discoverTableFromDb(pNdb, tabName) ;
- if (pTab3 == NULL){
- g_err << tabName << " was not found in DB"<< endl;
- return NDBT_FAILED;
- }
-
- // ndbout << *pTab3 << endl;
-
- if (pTab3->equal(*NDBT_Tables::getTable(tabName)) == false){
- g_err << "It was not equal" << endl;
- return NDBT_FAILED;
- }
-
- do {
- // Do it all
- HugoTransactions hugoTrans(*pTab3);
- UtilTransactions utilTrans(*pTab3);
- int count;
- CHECK(hugoTrans.loadTable(pNdb, records) == 0);
- CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == records);
- CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);
- CHECK(hugoTrans.scanUpdateRecords(pNdb, records/2) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == (records/2));
- CHECK(utilTrans.clearTable(pNdb, records) == 0);
-
-#if 0
- // Fill table
- CHECK(hugoTrans.fillTable(pNdb) == 0);
- CHECK(utilTrans.clearTable2(pNdb, records) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == 0);
-#endif
- } while(false);
-
- // Drop table
- if (pNdb->getDictionary()->dropTable(pTab3->getName()) != 0){
- ndbout << "Failed to drop "<<pTab3->getName()<<" in db" << endl;
- return NDBT_FAILED;
- }
- }
- return result;
-}
-
-int runStoreFrm(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- const NdbDictionary::Table* pTab = ctx->getTab();
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
-
- for (int l = 0; l < loops && result == NDBT_OK ; l++){
-
- Uint32 dataLen = (Uint32)myRandom48(MAX_FRM_DATA_SIZE);
- // size_t dataLen = 10;
- unsigned char data[MAX_FRM_DATA_SIZE];
-
- char start = l + 248;
- for(Uint32 i = 0; i < dataLen; i++){
- data[i] = start;
- start++;
- }
-#if 0
- ndbout << "dataLen="<<dataLen<<endl;
- for (Uint32 i = 0; i < dataLen; i++){
- unsigned char c = data[i];
- ndbout << hex << c << ", ";
- }
- ndbout << endl;
-#endif
-
- NdbDictionary::Table newTab(* pTab);
- void* pData = &data;
- newTab.setFrm(pData, dataLen);
-
- // Try to create table in db
- if (newTab.createTableInDb(pNdb) != 0){
- result = NDBT_FAILED;
- continue;
- }
-
- // Verify that table is in db
- const NdbDictionary::Table* pTab2 =
- NDBT_Table::discoverTableFromDb(pNdb, pTab->getName());
- if (pTab2 == NULL){
- g_err << pTab->getName() << " was not found in DB"<< endl;
- result = NDBT_FAILED;
- continue;
- }
-
- const void* pData2 = pTab2->getFrmData();
- Uint32 resultLen = pTab2->getFrmLength();
- if (dataLen != resultLen){
- g_err << "Length of data failure" << endl
- << " expected = " << dataLen << endl
- << " got = " << resultLen << endl;
- result = NDBT_FAILED;
- }
-
- // Verfiy the frm data
- if (memcmp(pData, pData2, resultLen) != 0){
- g_err << "Wrong data recieved" << endl;
- for (size_t i = 0; i < dataLen; i++){
- unsigned char c = ((unsigned char*)pData2)[i];
- g_err << hex << c << ", ";
- }
- g_err << endl;
- result = NDBT_FAILED;
- }
-
- if (pNdb->getDictionary()->dropTable(pTab2->getName()) != 0){
- g_err << "It can NOT be dropped" << endl;
- result = NDBT_FAILED;
- }
- }
-
- return result;
-}
-
-int runStoreFrmError(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- const NdbDictionary::Table* pTab = ctx->getTab();
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
-
- for (int l = 0; l < loops && result == NDBT_OK ; l++){
-
- const Uint32 dataLen = MAX_FRM_DATA_SIZE + 10;
- unsigned char data[dataLen];
-
- char start = l + 248;
- for(Uint32 i = 0; i < dataLen; i++){
- data[i] = start;
- start++;
- }
-#if 0
- ndbout << "dataLen="<<dataLen<<endl;
- for (Uint32 i = 0; i < dataLen; i++){
- unsigned char c = data[i];
- ndbout << hex << c << ", ";
- }
- ndbout << endl;
-#endif
-
- NdbDictionary::Table newTab(* pTab);
-
- void* pData = &data;
- newTab.setFrm(pData, dataLen);
-
- // Try to create table in db
- if (newTab.createTableInDb(pNdb) == 0){
- result = NDBT_FAILED;
- continue;
- }
-
- const NdbDictionary::Table* pTab2 =
- NDBT_Table::discoverTableFromDb(pNdb, pTab->getName());
- if (pTab2 != NULL){
- g_err << pTab->getName() << " was found in DB"<< endl;
- result = NDBT_FAILED;
- if (pNdb->getDictionary()->dropTable(pTab2->getName()) != 0){
- g_err << "It can NOT be dropped" << endl;
- result = NDBT_FAILED;
- }
-
- continue;
- }
-
- }
-
- return result;
-}
-
-int verifyTablesAreEqual(const NdbDictionary::Table* pTab, const NdbDictionary::Table* pTab2){
- // Verify that getPrimaryKey only returned true for primary keys
- for (int i = 0; i < pTab2->getNoOfColumns(); i++){
- const NdbDictionary::Column* col = pTab->getColumn(i);
- const NdbDictionary::Column* col2 = pTab2->getColumn(i);
- if (col->getPrimaryKey() != col2->getPrimaryKey()){
- g_err << "col->getPrimaryKey() != col2->getPrimaryKey()" << endl;
- return NDBT_FAILED;
- }
- }
-
- if (!pTab->equal(*pTab2)){
- g_err << "equal failed" << endl;
- g_info << *(NDBT_Table*)pTab; // gcc-4.1.2
- g_info << *(NDBT_Table*)pTab2;
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runGetPrimaryKey(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- const NdbDictionary::Table* pTab = ctx->getTab();
- ndbout << "|- " << pTab->getName() << endl;
- g_info << *(NDBT_Table*)pTab;
- // Try to create table in db
- if (pTab->createTableInDb(pNdb) != 0){
- return NDBT_FAILED;
- }
-
- const NdbDictionary::Table* pTab2 =
- NDBT_Table::discoverTableFromDb(pNdb, pTab->getName());
- if (pTab2 == NULL){
- ndbout << pTab->getName() << " was not found in DB"<< endl;
- return NDBT_FAILED;
- }
-
- int result = NDBT_OK;
- if (verifyTablesAreEqual(pTab, pTab2) != NDBT_OK)
- result = NDBT_FAILED;
-
-
-#if 0
- // Create an index on the table and see what
- // the function returns now
- char name[200];
- sprintf(name, "%s_X007", pTab->getName());
- NDBT_Index* pInd = new NDBT_Index(name);
- pInd->setTable(pTab->getName());
- pInd->setType(NdbDictionary::Index::UniqueHashIndex);
- // pInd->setLogging(false);
- for (int i = 0; i < 2; i++){
- const NDBT_Attribute* pAttr = pTab->getAttribute(i);
- pInd->addAttribute(*pAttr);
- }
- g_info << "Create index:" << endl << *pInd;
- if (pInd->createIndexInDb(pNdb, false) != 0){
- result = NDBT_FAILED;
- }
- delete pInd;
-
- const NdbDictionary::Table* pTab3 =
- NDBT_Table::discoverTableFromDb(pNdb, pTab->getName());
- if (pTab3 == NULL){
- ndbout << pTab->getName() << " was not found in DB"<< endl;
- return NDBT_FAILED;
- }
-
- if (verifyTablesAreEqual(pTab, pTab3) != NDBT_OK)
- result = NDBT_FAILED;
- if (verifyTablesAreEqual(pTab2, pTab3) != NDBT_OK)
- result = NDBT_FAILED;
-#endif
-
-#if 0
- if (pTab2->getDictionary()->dropTable(pNdb) != 0){
- ndbout << "Failed to drop "<<pTab2->getName()<<" in db" << endl;
- return NDBT_FAILED;
- }
-
- // Verify that table is not in db
- const NdbDictionary::Table* pTab4 =
- NDBT_Table::discoverTableFromDb(pNdb, pTab->getName());
- if (pTab4 != NULL){
- ndbout << pTab4->getName() << " was found in DB"<< endl;
- return NDBT_FAILED;
- }
-#endif
-
- return result;
-}
-
-struct ErrorCodes { int error_id; bool crash;};
-ErrorCodes
-NF_codes[] = {
- {6003, true}
- ,{6004, true}
- //,6005, true,
- //{7173, false}
-};
-
-int
-runNF1(NDBT_Context* ctx, NDBT_Step* step){
- NdbRestarter restarter;
- if(restarter.getNumDbNodes() < 2)
- return NDBT_OK;
-
- myRandom48Init(NdbTick_CurrentMillisecond());
-
- Ndb* pNdb = GETNDB(step);
- const NdbDictionary::Table* pTab = ctx->getTab();
-
- NdbDictionary::Dictionary* dict = pNdb->getDictionary();
- dict->dropTable(pTab->getName());
-
- int result = NDBT_OK;
-
- const int loops = ctx->getNumLoops();
- for (int l = 0; l < loops && result == NDBT_OK ; l++){
- const int sz = sizeof(NF_codes)/sizeof(NF_codes[0]);
- for(int i = 0; i<sz; i++){
- int rand = myRandom48(restarter.getNumDbNodes());
- int nodeId = restarter.getRandomNotMasterNodeId(rand);
- struct ErrorCodes err_struct = NF_codes[i];
- int error = err_struct.error_id;
- bool crash = err_struct.crash;
-
- g_info << "NF1: node = " << nodeId << " error code = " << error << endl;
-
- int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 3};
-
- CHECK2(restarter.dumpStateOneNode(nodeId, val2, 2) == 0,
- "failed to set RestartOnErrorInsert");
-
- CHECK2(restarter.insertErrorInNode(nodeId, error) == 0,
- "failed to set error insert");
-
- CHECK2(dict->createTable(* pTab) == 0,
- "failed to create table");
-
- if (crash) {
- CHECK2(restarter.waitNodesNoStart(&nodeId, 1) == 0,
- "waitNodesNoStart failed");
-
- if(myRandom48(100) > 50){
- CHECK2(restarter.startNodes(&nodeId, 1) == 0,
- "failed to start node");
-
- CHECK2(restarter.waitClusterStarted() == 0,
- "waitClusterStarted failed");
-
- CHECK2(dict->dropTable(pTab->getName()) == 0,
- "drop table failed");
- } else {
- CHECK2(dict->dropTable(pTab->getName()) == 0,
- "drop table failed");
-
- CHECK2(restarter.startNodes(&nodeId, 1) == 0,
- "failed to start node");
-
- CHECK2(restarter.waitClusterStarted() == 0,
- "waitClusterStarted failed");
- }
- }
- }
- }
- end:
- dict->dropTable(pTab->getName());
-
- return result;
-}
-
-#define APIERROR(error) \
- { g_err << "Error in " << __FILE__ << ", line:" << __LINE__ << ", code:" \
- << error.code << ", msg: " << error.message << "." << endl; \
- }
-
-int
-runCreateAutoincrementTable(NDBT_Context* ctx, NDBT_Step* step){
-
- Uint32 startvalues[5] = {256-2, 0, 256*256-2, ~0, 256*256*256-2};
-
- int ret = NDBT_OK;
-
- for (int jj = 0; jj < 5 && ret == NDBT_OK; jj++) {
- char tabname[] = "AUTOINCTAB";
- Uint32 startvalue = startvalues[jj];
-
- NdbDictionary::Table myTable;
- NdbDictionary::Column myColumn;
-
- Ndb* myNdb = GETNDB(step);
- NdbDictionary::Dictionary* myDict = myNdb->getDictionary();
-
-
- if (myDict->getTable(tabname) != NULL) {
- g_err << "NDB already has example table: " << tabname << endl;
- APIERROR(myNdb->getNdbError());
- return NDBT_FAILED;
- }
-
- myTable.setName(tabname);
-
- myColumn.setName("ATTR1");
- myColumn.setType(NdbDictionary::Column::Unsigned);
- myColumn.setLength(1);
- myColumn.setPrimaryKey(true);
- myColumn.setNullable(false);
- myColumn.setAutoIncrement(true);
- if (startvalue != ~0) // check that default value starts with 1
- myColumn.setAutoIncrementInitialValue(startvalue);
- myTable.addColumn(myColumn);
-
- if (myDict->createTable(myTable) == -1) {
- g_err << "Failed to create table " << tabname << endl;
- APIERROR(myNdb->getNdbError());
- return NDBT_FAILED;
- }
-
-
- if (startvalue == ~0) // check that default value starts with 1
- startvalue = 1;
-
- for (int i = 0; i < 16; i++) {
-
- Uint64 value;
- if (myNdb->getAutoIncrementValue(tabname, value, 1) == -1) {
- g_err << "getAutoIncrementValue failed on " << tabname << endl;
- APIERROR(myNdb->getNdbError());
- return NDBT_FAILED;
- }
- else if (value != (startvalue+i)) {
- g_err << "value = " << value << " expected " << startvalue+i << endl;;
- APIERROR(myNdb->getNdbError());
- // ret = NDBT_FAILED;
- // break;
- }
- }
-
- if (myDict->dropTable(tabname) == -1) {
- g_err << "Failed to drop table " << tabname << endl;
- APIERROR(myNdb->getNdbError());
- ret = NDBT_FAILED;
- }
- }
-
- return ret;
-}
-
-int
-runTableRename(NDBT_Context* ctx, NDBT_Step* step){
-
- int result = NDBT_OK;
-
- Ndb* pNdb = GETNDB(step);
- NdbDictionary::Dictionary* dict = pNdb->getDictionary();
- int records = ctx->getNumRecords();
- const int loops = ctx->getNumLoops();
-
- ndbout << "|- " << ctx->getTab()->getName() << endl;
-
- for (int l = 0; l < loops && result == NDBT_OK ; l++){
- const NdbDictionary::Table* pTab = ctx->getTab();
-
- // Try to create table in db
- if (pTab->createTableInDb(pNdb) != 0){
- return NDBT_FAILED;
- }
-
- // Verify that table is in db
- const NdbDictionary::Table* pTab2 =
- NDBT_Table::discoverTableFromDb(pNdb, pTab->getName());
- if (pTab2 == NULL){
- ndbout << pTab->getName() << " was not found in DB"<< endl;
- return NDBT_FAILED;
- }
- ctx->setTab(pTab2);
-
- // Load table
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.loadTable(pNdb, records) != 0){
- return NDBT_FAILED;
- }
-
- // Rename table
- BaseString pTabName(pTab->getName());
- BaseString pTabNewName(pTabName);
- pTabNewName.append("xx");
-
- const NdbDictionary::Table * oldTable = dict->getTable(pTabName.c_str());
- if (oldTable) {
- NdbDictionary::Table newTable = *oldTable;
- newTable.setName(pTabNewName.c_str());
- CHECK2(dict->alterTable(newTable) == 0,
- "TableRename failed");
- }
- else {
- result = NDBT_FAILED;
- }
-
- // Verify table contents
- NdbDictionary::Table pNewTab(pTabNewName.c_str());
-
- UtilTransactions utilTrans(pNewTab);
- if (utilTrans.clearTable(pNdb, records) != 0){
- continue;
- }
-
- // Drop table
- dict->dropTable(pNewTab.getName());
- }
- end:
-
- return result;
-}
-
-int
-runTableRenameNF(NDBT_Context* ctx, NDBT_Step* step){
- NdbRestarter restarter;
- if(restarter.getNumDbNodes() < 2)
- return NDBT_OK;
-
- int result = NDBT_OK;
-
- Ndb* pNdb = GETNDB(step);
- NdbDictionary::Dictionary* dict = pNdb->getDictionary();
- int records = ctx->getNumRecords();
- const int loops = ctx->getNumLoops();
-
- ndbout << "|- " << ctx->getTab()->getName() << endl;
-
- for (int l = 0; l < loops && result == NDBT_OK ; l++){
- const NdbDictionary::Table* pTab = ctx->getTab();
-
- // Try to create table in db
- if (pTab->createTableInDb(pNdb) != 0){
- return NDBT_FAILED;
- }
-
- // Verify that table is in db
- const NdbDictionary::Table* pTab2 =
- NDBT_Table::discoverTableFromDb(pNdb, pTab->getName());
- if (pTab2 == NULL){
- ndbout << pTab->getName() << " was not found in DB"<< endl;
- return NDBT_FAILED;
- }
- ctx->setTab(pTab2);
-
- // Load table
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.loadTable(pNdb, records) != 0){
- return NDBT_FAILED;
- }
-
- BaseString pTabName(pTab->getName());
- BaseString pTabNewName(pTabName);
- pTabNewName.append("xx");
-
- const NdbDictionary::Table * oldTable = dict->getTable(pTabName.c_str());
- if (oldTable) {
- NdbDictionary::Table newTable = *oldTable;
- newTable.setName(pTabNewName.c_str());
- CHECK2(dict->alterTable(newTable) == 0,
- "TableRename failed");
- }
- else {
- result = NDBT_FAILED;
- }
-
- // Restart one node at a time
-
- /**
- * Need to run LCP at high rate otherwise
- * packed replicas become "to many"
- */
- int val = DumpStateOrd::DihMinTimeBetweenLCP;
- if(restarter.dumpStateAllNodes(&val, 1) != 0){
- do { CHECK(0); } while(0);
- g_err << "Failed to set LCP to min value" << endl;
- return NDBT_FAILED;
- }
-
- const int numNodes = restarter.getNumDbNodes();
- for(int i = 0; i<numNodes; i++){
- int nodeId = restarter.getDbNodeId(i);
- int error = NF_codes[i].error_id;
-
- g_info << "NF1: node = " << nodeId << " error code = " << error << endl;
-
- CHECK2(restarter.restartOneDbNode(nodeId) == 0,
- "failed to set restartOneDbNode");
-
- CHECK2(restarter.waitClusterStarted() == 0,
- "waitClusterStarted failed");
-
- }
-
- // Verify table contents
- NdbDictionary::Table pNewTab(pTabNewName.c_str());
-
- UtilTransactions utilTrans(pNewTab);
- if (utilTrans.clearTable(pNdb, records) != 0){
- continue;
- }
-
- // Drop table
- dict->dropTable(pTabNewName.c_str());
- }
- end:
- return result;
-}
-
-int
-runTableRenameSR(NDBT_Context* ctx, NDBT_Step* step){
- NdbRestarter restarter;
- if(restarter.getNumDbNodes() < 2)
- return NDBT_OK;
-
- int result = NDBT_OK;
-
- Ndb* pNdb = GETNDB(step);
- NdbDictionary::Dictionary* dict = pNdb->getDictionary();
- int records = ctx->getNumRecords();
- const int loops = ctx->getNumLoops();
-
- ndbout << "|- " << ctx->getTab()->getName() << endl;
-
- for (int l = 0; l < loops && result == NDBT_OK ; l++){
- // Rename table
- const NdbDictionary::Table* pTab = ctx->getTab();
-
- // Try to create table in db
- if (pTab->createTableInDb(pNdb) != 0){
- return NDBT_FAILED;
- }
-
- // Verify that table is in db
- const NdbDictionary::Table* pTab2 =
- NDBT_Table::discoverTableFromDb(pNdb, pTab->getName());
- if (pTab2 == NULL){
- ndbout << pTab->getName() << " was not found in DB"<< endl;
- return NDBT_FAILED;
- }
- ctx->setTab(pTab2);
-
- // Load table
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.loadTable(pNdb, records) != 0){
- return NDBT_FAILED;
- }
-
- BaseString pTabName(pTab->getName());
- BaseString pTabNewName(pTabName);
- pTabNewName.append("xx");
-
- const NdbDictionary::Table * oldTable = dict->getTable(pTabName.c_str());
- if (oldTable) {
- NdbDictionary::Table newTable = *oldTable;
- newTable.setName(pTabNewName.c_str());
- CHECK2(dict->alterTable(newTable) == 0,
- "TableRename failed");
- }
- else {
- result = NDBT_FAILED;
- }
-
- // Restart cluster
-
- /**
- * Need to run LCP at high rate otherwise
- * packed replicas become "to many"
- */
- int val = DumpStateOrd::DihMinTimeBetweenLCP;
- if(restarter.dumpStateAllNodes(&val, 1) != 0){
- do { CHECK(0); } while(0);
- g_err << "Failed to set LCP to min value" << endl;
- return NDBT_FAILED;
- }
-
- CHECK2(restarter.restartAll() == 0,
- "failed to set restartOneDbNode");
-
- CHECK2(restarter.waitClusterStarted() == 0,
- "waitClusterStarted failed");
-
- // Verify table contents
- NdbDictionary::Table pNewTab(pTabNewName.c_str());
-
- UtilTransactions utilTrans(pNewTab);
- if (utilTrans.clearTable(pNdb, records) != 0){
- continue;
- }
-
- // Drop table
- dict->dropTable(pTabNewName.c_str());
- }
- end:
- return result;
-}
-
-static void
-f(const NdbDictionary::Column * col){
- if(col == 0){
- abort();
- }
-}
-
-int
-runTestDictionaryPerf(NDBT_Context* ctx, NDBT_Step* step){
- Vector<char*> cols;
- Vector<const NdbDictionary::Table*> tabs;
- int i;
-
- Ndb* pNdb = GETNDB(step);
-
- const Uint32 count = NDBT_Tables::getNumTables();
- for (i=0; i < count; i++){
- const NdbDictionary::Table * tab = NDBT_Tables::getTable(i);
- pNdb->getDictionary()->createTable(* tab);
-
- const NdbDictionary::Table * tab2 = pNdb->getDictionary()->getTable(tab->getName());
-
- for(size_t j = 0; j<tab->getNoOfColumns(); j++){
- cols.push_back((char*)tab2);
- cols.push_back(strdup(tab->getColumn(j)->getName()));
- }
- }
-
- const Uint32 times = 10000000;
-
- ndbout_c("%d tables and %d columns",
- NDBT_Tables::getNumTables(), cols.size()/2);
-
- char ** tcols = cols.getBase();
-
- srand(time(0));
- Uint32 size = cols.size() / 2;
- char ** columns = &cols[0];
- Uint64 start = NdbTick_CurrentMillisecond();
- for(i = 0; i<times; i++){
- int j = 2 * (rand() % size);
- const NdbDictionary::Table* tab = (const NdbDictionary::Table*)tcols[j];
- const char * col = tcols[j+1];
- const NdbDictionary::Column* column = tab->getColumn(col);
- f(column);
- }
- Uint64 stop = NdbTick_CurrentMillisecond();
- stop -= start;
-
- Uint64 per = stop;
- per *= 1000;
- per /= times;
-
- ndbout_c("%d random getColumn(name) in %Ld ms -> %d us/get",
- times, stop, per);
-
- return NDBT_OK;
-}
-
-int
-runCreateLogfileGroup(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- NdbDictionary::LogfileGroup lg;
- lg.setName("DEFAULT-LG");
- lg.setUndoBufferSize(8*1024*1024);
-
- int res;
- res = pNdb->getDictionary()->createLogfileGroup(lg);
- if(res != 0){
- g_err << "Failed to create logfilegroup:"
- << endl << pNdb->getDictionary()->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- NdbDictionary::Undofile uf;
- uf.setPath("undofile01.dat");
- uf.setSize(5*1024*1024);
- uf.setLogfileGroup("DEFAULT-LG");
-
- res = pNdb->getDictionary()->createUndofile(uf);
- if(res != 0){
- g_err << "Failed to create undofile:"
- << endl << pNdb->getDictionary()->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- uf.setPath("undofile02.dat");
- uf.setSize(5*1024*1024);
- uf.setLogfileGroup("DEFAULT-LG");
-
- res = pNdb->getDictionary()->createUndofile(uf);
- if(res != 0){
- g_err << "Failed to create undofile:"
- << endl << pNdb->getDictionary()->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-int
-runCreateTablespace(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- NdbDictionary::Tablespace lg;
- lg.setName("DEFAULT-TS");
- lg.setExtentSize(1024*1024);
- lg.setDefaultLogfileGroup("DEFAULT-LG");
-
- int res;
- res = pNdb->getDictionary()->createTablespace(lg);
- if(res != 0){
- g_err << "Failed to create tablespace:"
- << endl << pNdb->getDictionary()->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- NdbDictionary::Datafile uf;
- uf.setPath("datafile01.dat");
- uf.setSize(10*1024*1024);
- uf.setTablespace("DEFAULT-TS");
-
- res = pNdb->getDictionary()->createDatafile(uf);
- if(res != 0){
- g_err << "Failed to create datafile:"
- << endl << pNdb->getDictionary()->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-int
-runCreateDiskTable(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
-
- NdbDictionary::Table tab = *ctx->getTab();
- tab.setTablespaceName("DEFAULT-TS");
-
- for(Uint32 i = 0; i<tab.getNoOfColumns(); i++)
- if(!tab.getColumn(i)->getPrimaryKey())
- tab.getColumn(i)->setStorageType(NdbDictionary::Column::StorageTypeDisk);
-
- int res;
- res = pNdb->getDictionary()->createTable(tab);
- if(res != 0){
- g_err << "Failed to create table:"
- << endl << pNdb->getDictionary()->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-int runFailAddFragment(NDBT_Context* ctx, NDBT_Step* step){
- static int acclst[] = { 3001 };
- static int tuplst[] = { 4007, 4008, 4009, 4010, 4011, 4012 };
- static int tuxlst[] = { 12001, 12002, 12003, 12004, 12005, 12006 };
- static unsigned acccnt = sizeof(acclst)/sizeof(acclst[0]);
- static unsigned tupcnt = sizeof(tuplst)/sizeof(tuplst[0]);
- static unsigned tuxcnt = sizeof(tuxlst)/sizeof(tuxlst[0]);
-
- NdbRestarter restarter;
- int nodeId = restarter.getMasterNodeId();
- Ndb* pNdb = GETNDB(step);
- NdbDictionary::Dictionary* pDic = pNdb->getDictionary();
- NdbDictionary::Table tab(*ctx->getTab());
- tab.setFragmentType(NdbDictionary::Object::FragAllLarge);
-
- // ordered index on first few columns
- NdbDictionary::Index idx("X");
- idx.setTable(tab.getName());
- idx.setType(NdbDictionary::Index::OrderedIndex);
- idx.setLogging(false);
- for (int i_hate_broken_compilers = 0;
- i_hate_broken_compilers < 3 &&
- i_hate_broken_compilers < tab.getNoOfColumns();
- i_hate_broken_compilers++) {
- idx.addColumn(*tab.getColumn(i_hate_broken_compilers));
- }
-
- const int loops = ctx->getNumLoops();
- int result = NDBT_OK;
- (void)pDic->dropTable(tab.getName());
-
- for (int l = 0; l < loops; l++) {
- for (unsigned i0 = 0; i0 < acccnt; i0++) {
- unsigned j = (l == 0 ? i0 : myRandom48(acccnt));
- int errval = acclst[j];
- g_info << "insert error node=" << nodeId << " value=" << errval << endl;
- CHECK2(restarter.insertErrorInNode(nodeId, errval) == 0,
- "failed to set error insert");
- CHECK2(pDic->createTable(tab) != 0,
- "failed to fail after error insert " << errval);
- CHECK2(pDic->createTable(tab) == 0,
- pDic->getNdbError());
- CHECK2(pDic->dropTable(tab.getName()) == 0,
- pDic->getNdbError());
- }
- for (unsigned i1 = 0; i1 < tupcnt; i1++) {
- unsigned j = (l == 0 ? i1 : myRandom48(tupcnt));
- int errval = tuplst[j];
- g_info << "insert error node=" << nodeId << " value=" << errval << endl;
- CHECK2(restarter.insertErrorInNode(nodeId, errval) == 0,
- "failed to set error insert");
- CHECK2(pDic->createTable(tab) != 0,
- "failed to fail after error insert " << errval);
- CHECK2(pDic->createTable(tab) == 0,
- pDic->getNdbError());
- CHECK2(pDic->dropTable(tab.getName()) == 0,
- pDic->getNdbError());
- }
- for (unsigned i2 = 0; i2 < tuxcnt; i2++) {
- unsigned j = (l == 0 ? i2 : myRandom48(tuxcnt));
- int errval = tuxlst[j];
- g_info << "insert error node=" << nodeId << " value=" << errval << endl;
- CHECK2(restarter.insertErrorInNode(nodeId, errval) == 0,
- "failed to set error insert");
- CHECK2(pDic->createTable(tab) == 0,
- pDic->getNdbError());
- CHECK2(pDic->createIndex(idx) != 0,
- "failed to fail after error insert " << errval);
- CHECK2(pDic->createIndex(idx) == 0,
- pDic->getNdbError());
- CHECK2(pDic->dropTable(tab.getName()) == 0,
- pDic->getNdbError());
- }
- }
-end:
- return result;
-}
-
-// NFNR
-
-// Restarter controls dict ops : 1-run 2-pause 3-stop
-// synced by polling...
-
-static bool
-send_dict_ops_cmd(NDBT_Context* ctx, Uint32 cmd)
-{
- ctx->setProperty("DictOps_CMD", cmd);
- while (1) {
- if (ctx->isTestStopped())
- return false;
- if (ctx->getProperty("DictOps_ACK") == cmd)
- break;
- NdbSleep_MilliSleep(100);
- }
- return true;
-}
-
-static bool
-recv_dict_ops_run(NDBT_Context* ctx)
-{
- while (1) {
- if (ctx->isTestStopped())
- return false;
- Uint32 cmd = ctx->getProperty("DictOps_CMD");
- ctx->setProperty("DictOps_ACK", cmd);
- if (cmd == 1)
- break;
- if (cmd == 3)
- return false;
- NdbSleep_MilliSleep(100);
- }
- return true;
-}
-
-int
-runRestarts(NDBT_Context* ctx, NDBT_Step* step)
-{
- static int errlst_master[] = { // non-crashing
- 7175, // send one fake START_PERMREF
- 0
- };
- static int errlst_node[] = {
- 7174, // crash before sending DICT_LOCK_REQ
- 7176, // pretend master does not support DICT lock
- 7121, // crash at receive START_PERMCONF
- 0
- };
- const uint errcnt_master = sizeof(errlst_master)/sizeof(errlst_master[0]);
- const uint errcnt_node = sizeof(errlst_node)/sizeof(errlst_node[0]);
-
- myRandom48Init(NdbTick_CurrentMillisecond());
- NdbRestarter restarter;
- int result = NDBT_OK;
- const int loops = ctx->getNumLoops();
-
- for (int l = 0; l < loops && result == NDBT_OK; l++) {
- g_info << "1: === loop " << l << " ===" << endl;
-
- // assuming 2-way replicated
-
- int numnodes = restarter.getNumDbNodes();
- CHECK(numnodes >= 1);
- if (numnodes == 1)
- break;
-
- int masterNodeId = restarter.getMasterNodeId();
- CHECK(masterNodeId != -1);
-
- // for more complex cases need more restarter support methods
-
- int nodeIdList[2] = { 0, 0 };
- int nodeIdCnt = 0;
-
- if (numnodes >= 2) {
- int rand = myRandom48(numnodes);
- int nodeId = restarter.getRandomNotMasterNodeId(rand);
- CHECK(nodeId != -1);
- nodeIdList[nodeIdCnt++] = nodeId;
- }
-
- if (numnodes >= 4 && myRandom48(2) == 0) {
- int rand = myRandom48(numnodes);
- int nodeId = restarter.getRandomNodeOtherNodeGroup(nodeIdList[0], rand);
- CHECK(nodeId != -1);
- if (nodeId != masterNodeId)
- nodeIdList[nodeIdCnt++] = nodeId;
- }
-
- g_info << "1: master=" << masterNodeId << " nodes=" << nodeIdList[0] << "," << nodeIdList[1] << endl;
-
- const uint timeout = 60; //secs for node wait
- const unsigned maxsleep = 2000; //ms
-
- bool NF_ops = ctx->getProperty("Restart_NF_ops");
- uint NF_type = ctx->getProperty("Restart_NF_type");
- bool NR_ops = ctx->getProperty("Restart_NR_ops");
- bool NR_error = ctx->getProperty("Restart_NR_error");
-
- g_info << "1: " << (NF_ops ? "run" : "pause") << " dict ops" << endl;
- if (! send_dict_ops_cmd(ctx, NF_ops ? 1 : 2))
- break;
- NdbSleep_MilliSleep(myRandom48(maxsleep));
-
- {
- for (int i = 0; i < nodeIdCnt; i++) {
- int nodeId = nodeIdList[i];
-
- bool nostart = true;
- bool abort = NF_type == 0 ? myRandom48(2) : (NF_type == 2);
- bool initial = myRandom48(2);
-
- char flags[40];
- strcpy(flags, "flags: nostart");
- if (abort)
- strcat(flags, ",abort");
- if (initial)
- strcat(flags, ",initial");
-
- g_info << "1: restart " << nodeId << " " << flags << endl;
- CHECK(restarter.restartOneDbNode(nodeId, initial, nostart, abort) == 0);
- }
- }
-
- g_info << "1: wait for nostart" << endl;
- CHECK(restarter.waitNodesNoStart(nodeIdList, nodeIdCnt, timeout) == 0);
- NdbSleep_MilliSleep(myRandom48(maxsleep));
-
- int err_master = 0;
- int err_node[2] = { 0, 0 };
-
- if (NR_error) {
- err_master = errlst_master[l % errcnt_master];
-
- // limitation: cannot have 2 node restarts and crash_insert
- // one node may die for real (NF during startup)
-
- for (int i = 0; i < nodeIdCnt && nodeIdCnt == 1; i++) {
- err_node[i] = errlst_node[l % errcnt_node];
-
- // 7176 - no DICT lock protection
-
- if (err_node[i] == 7176) {
- g_info << "1: no dict ops due to error insert "
- << err_node[i] << endl;
- NR_ops = false;
- }
- }
- }
-
- g_info << "1: " << (NR_ops ? "run" : "pause") << " dict ops" << endl;
- if (! send_dict_ops_cmd(ctx, NR_ops ? 1 : 2))
- break;
- NdbSleep_MilliSleep(myRandom48(maxsleep));
-
- g_info << "1: start nodes" << endl;
- CHECK(restarter.startNodes(nodeIdList, nodeIdCnt) == 0);
-
- if (NR_error) {
- {
- int err = err_master;
- if (err != 0) {
- g_info << "1: insert master error " << err << endl;
- CHECK(restarter.insertErrorInNode(masterNodeId, err) == 0);
- }
- }
-
- for (int i = 0; i < nodeIdCnt; i++) {
- int nodeId = nodeIdList[i];
-
- int err = err_node[i];
- if (err != 0) {
- g_info << "1: insert node " << nodeId << " error " << err << endl;
- CHECK(restarter.insertErrorInNode(nodeId, err) == 0);
- }
- }
- }
- NdbSleep_MilliSleep(myRandom48(maxsleep));
-
- g_info << "1: wait cluster started" << endl;
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- NdbSleep_MilliSleep(myRandom48(maxsleep));
-
- g_info << "1: restart done" << endl;
- }
-
- g_info << "1: stop dict ops" << endl;
- send_dict_ops_cmd(ctx, 3);
-
- return result;
-}
-
-int
-runDictOps(NDBT_Context* ctx, NDBT_Step* step)
-{
- myRandom48Init(NdbTick_CurrentMillisecond());
- int result = NDBT_OK;
-
- for (int l = 0; result == NDBT_OK; l++) {
- if (! recv_dict_ops_run(ctx))
- break;
-
- g_info << "2: === loop " << l << " ===" << endl;
-
- Ndb* pNdb = GETNDB(step);
- NdbDictionary::Dictionary* pDic = pNdb->getDictionary();
- const NdbDictionary::Table* pTab = ctx->getTab();
- //const char* tabName = pTab->getName(); //XXX what goes on?
- char tabName[40];
- strcpy(tabName, pTab->getName());
-
- const unsigned long maxsleep = 100; //ms
-
- g_info << "2: create table" << endl;
- {
- uint count = 0;
- try_create:
- count++;
- if (pDic->createTable(*pTab) != 0) {
- const NdbError err = pDic->getNdbError();
- if (count == 1)
- g_err << "2: " << tabName << ": create failed: " << err << endl;
- if (err.code != 711) {
- result = NDBT_FAILED;
- break;
- }
- NdbSleep_MilliSleep(myRandom48(maxsleep));
- goto try_create;
- }
- }
- NdbSleep_MilliSleep(myRandom48(maxsleep));
-
- g_info << "2: verify create" << endl;
- const NdbDictionary::Table* pTab2 = pDic->getTable(tabName);
- if (pTab2 == NULL) {
- const NdbError err = pDic->getNdbError();
- g_err << "2: " << tabName << ": verify create: " << err << endl;
- result = NDBT_FAILED;
- break;
- }
- NdbSleep_MilliSleep(myRandom48(maxsleep));
-
- // replace by the Retrieved table
- pTab = pTab2;
-
- // create indexes
- const char** indlist = NDBT_Tables::getIndexes(tabName);
- uint indnum = 0;
- while (indlist != 0 && *indlist != 0) {
- uint count = 0;
- try_create_index:
- count++;
- if (count == 1)
- g_info << "2: create index " << indnum << " " << *indlist << endl;
- NdbDictionary::Index ind;
- char indName[200];
- sprintf(indName, "%s_X%u", tabName, indnum);
- ind.setName(indName);
- ind.setTable(tabName);
- if (strcmp(*indlist, "UNIQUE") == 0) {
- ind.setType(NdbDictionary::Index::UniqueHashIndex);
- ind.setLogging(pTab->getLogging());
- } else if (strcmp(*indlist, "ORDERED") == 0) {
- ind.setType(NdbDictionary::Index::OrderedIndex);
- ind.setLogging(false);
- } else {
- assert(false);
- }
- const char** indtemp = indlist;
- while (*++indtemp != 0) {
- ind.addColumn(*indtemp);
- }
- if (pDic->createIndex(ind) != 0) {
- const NdbError err = pDic->getNdbError();
- if (count == 1)
- g_err << "2: " << indName << ": create failed: " << err << endl;
- if (err.code != 711) {
- result = NDBT_FAILED;
- break;
- }
- NdbSleep_MilliSleep(myRandom48(maxsleep));
- goto try_create_index;
- }
- indlist = ++indtemp;
- indnum++;
- }
- if (result == NDBT_FAILED)
- break;
-
- uint indcount = indnum;
-
- int records = myRandom48(ctx->getNumRecords());
- g_info << "2: load " << records << " records" << endl;
- HugoTransactions hugoTrans(*pTab);
- if (hugoTrans.loadTable(pNdb, records) != 0) {
- // XXX get error code from hugo
- g_err << "2: " << tabName << ": load failed" << endl;
- result = NDBT_FAILED;
- break;
- }
- NdbSleep_MilliSleep(myRandom48(maxsleep));
-
- // drop indexes
- indnum = 0;
- while (indnum < indcount) {
- uint count = 0;
- try_drop_index:
- count++;
- if (count == 1)
- g_info << "2: drop index " << indnum << endl;
- char indName[200];
- sprintf(indName, "%s_X%u", tabName, indnum);
- if (pDic->dropIndex(indName, tabName) != 0) {
- const NdbError err = pDic->getNdbError();
- if (count == 1)
- g_err << "2: " << indName << ": drop failed: " << err << endl;
- if (err.code != 711) {
- result = NDBT_FAILED;
- break;
- }
- NdbSleep_MilliSleep(myRandom48(maxsleep));
- goto try_drop_index;
- }
- indnum++;
- }
- if (result == NDBT_FAILED)
- break;
-
- g_info << "2: drop" << endl;
- {
- uint count = 0;
- try_drop:
- count++;
- if (pDic->dropTable(tabName) != 0) {
- const NdbError err = pDic->getNdbError();
- if (count == 1)
- g_err << "2: " << tabName << ": drop failed: " << err << endl;
- if (err.code != 711) {
- result = NDBT_FAILED;
- break;
- }
- NdbSleep_MilliSleep(myRandom48(maxsleep));
- goto try_drop;
- }
- }
- NdbSleep_MilliSleep(myRandom48(maxsleep));
-
- g_info << "2: verify drop" << endl;
- const NdbDictionary::Table* pTab3 = pDic->getTable(tabName);
- if (pTab3 != NULL) {
- g_err << "2: " << tabName << ": verify drop: table exists" << endl;
- result = NDBT_FAILED;
- break;
- }
- if (pDic->getNdbError().code != 709 &&
- pDic->getNdbError().code != 723) {
- const NdbError err = pDic->getNdbError();
- g_err << "2: " << tabName << ": verify drop: " << err << endl;
- result = NDBT_FAILED;
- break;
- }
- NdbSleep_MilliSleep(myRandom48(maxsleep));
- }
-
- return result;
-}
-
-int
-runBug21755(NDBT_Context* ctx, NDBT_Step* step)
-{
- char buf[256];
- NdbRestarter res;
- NdbDictionary::Table pTab0 = * ctx->getTab();
- NdbDictionary::Table pTab1 = pTab0;
-
- if (res.getNumDbNodes() < 2)
- return NDBT_OK;
-
- Ndb* pNdb = GETNDB(step);
- NdbDictionary::Dictionary* pDic = pNdb->getDictionary();
-
- if (pDic->createTable(pTab0))
- {
- ndbout << pDic->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- NdbDictionary::Index idx0;
- BaseString::snprintf(buf, sizeof(buf), "%s-idx", pTab0.getName());
- idx0.setName(buf);
- idx0.setType(NdbDictionary::Index::OrderedIndex);
- idx0.setTable(pTab0.getName());
- idx0.setStoredIndex(false);
- for (Uint32 i = 0; i<pTab0.getNoOfColumns(); i++)
- {
- const NdbDictionary::Column * col = pTab0.getColumn(i);
- if(col->getPrimaryKey()){
- idx0.addIndexColumn(col->getName());
- }
- }
-
- if (pDic->createIndex(idx0))
- {
- ndbout << pDic->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- BaseString::snprintf(buf, sizeof(buf), "%s-2", pTab1.getName());
- pTab1.setName(buf);
-
- if (pDic->createTable(pTab1))
- {
- ndbout << pDic->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- {
- HugoTransactions t0 (*pDic->getTable(pTab0.getName()));
- t0.loadTable(pNdb, 1000);
- }
-
- {
- HugoTransactions t1 (*pDic->getTable(pTab1.getName()));
- t1.loadTable(pNdb, 1000);
- }
-
- int node = res.getRandomNotMasterNodeId(rand());
- res.restartOneDbNode(node, false, true, true);
-
- if (pDic->dropTable(pTab1.getName()))
- {
- ndbout << pDic->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- BaseString::snprintf(buf, sizeof(buf), "%s-idx2", pTab0.getName());
- idx0.setName(buf);
- if (pDic->createIndex(idx0))
- {
- ndbout << pDic->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- res.waitNodesNoStart(&node, 1);
- res.startNodes(&node, 1);
-
- if (res.waitClusterStarted())
- {
- return NDBT_FAILED;
- }
-
- if (pDic->dropTable(pTab0.getName()))
- {
- ndbout << pDic->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-static
-int
-create_tablespace(NdbDictionary::Dictionary* pDict,
- const char * lgname,
- const char * tsname,
- const char * dfname)
-{
- NdbDictionary::Tablespace ts;
- ts.setName(tsname);
- ts.setExtentSize(1024*1024);
- ts.setDefaultLogfileGroup(lgname);
-
- if(pDict->createTablespace(ts) != 0)
- {
- g_err << "Failed to create tablespace:"
- << endl << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- NdbDictionary::Datafile df;
- df.setPath(dfname);
- df.setSize(1*1024*1024);
- df.setTablespace(tsname);
-
- if(pDict->createDatafile(df) != 0)
- {
- g_err << "Failed to create datafile:"
- << endl << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
- return 0;
-}
-
-int
-runBug24631(NDBT_Context* ctx, NDBT_Step* step)
-{
- char tsname[256];
- char dfname[256];
- char lgname[256];
- char ufname[256];
- NdbRestarter res;
-
- if (res.getNumDbNodes() < 2)
- return NDBT_OK;
-
- Ndb* pNdb = GETNDB(step);
- NdbDictionary::Dictionary* pDict = pNdb->getDictionary();
-
- NdbDictionary::Dictionary::List list;
- if (pDict->listObjects(list) == -1)
- return NDBT_FAILED;
-
- const char * lgfound = 0;
-
- for (Uint32 i = 0; i<list.count; i++)
- {
- switch(list.elements[i].type){
- case NdbDictionary::Object::LogfileGroup:
- lgfound = list.elements[i].name;
- break;
- default:
- break;
- }
- if (lgfound)
- break;
- }
-
- if (lgfound == 0)
- {
- BaseString::snprintf(lgname, sizeof(lgname), "LG-%u", rand());
- NdbDictionary::LogfileGroup lg;
-
- lg.setName(lgname);
- lg.setUndoBufferSize(8*1024*1024);
- if(pDict->createLogfileGroup(lg) != 0)
- {
- g_err << "Failed to create logfilegroup:"
- << endl << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- NdbDictionary::Undofile uf;
- BaseString::snprintf(ufname, sizeof(ufname), "%s-%u", lgname, rand());
- uf.setPath(ufname);
- uf.setSize(2*1024*1024);
- uf.setLogfileGroup(lgname);
-
- if(pDict->createUndofile(uf) != 0)
- {
- g_err << "Failed to create undofile:"
- << endl << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
- }
- else
- {
- BaseString::snprintf(lgname, sizeof(lgname), "%s", lgfound);
- }
-
- BaseString::snprintf(tsname, sizeof(tsname), "TS-%u", rand());
- BaseString::snprintf(dfname, sizeof(dfname), "%s-%u.dat", tsname, rand());
-
- if (create_tablespace(pDict, lgname, tsname, dfname))
- return NDBT_FAILED;
-
-
- int node = res.getRandomNotMasterNodeId(rand());
- res.restartOneDbNode(node, false, true, true);
- NdbSleep_SecSleep(3);
-
- if (pDict->dropDatafile(pDict->getDatafile(0, dfname)) != 0)
- {
- g_err << "Failed to drop datafile: " << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- if (pDict->dropTablespace(pDict->getTablespace(tsname)) != 0)
- {
- g_err << "Failed to drop tablespace: " << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- if (res.waitNodesNoStart(&node, 1))
- return NDBT_FAILED;
-
- res.startNodes(&node, 1);
- if (res.waitClusterStarted())
- return NDBT_FAILED;
-
- if (create_tablespace(pDict, lgname, tsname, dfname))
- return NDBT_FAILED;
-
- if (pDict->dropDatafile(pDict->getDatafile(0, dfname)) != 0)
- {
- g_err << "Failed to drop datafile: " << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- if (pDict->dropTablespace(pDict->getTablespace(tsname)) != 0)
- {
- g_err << "Failed to drop tablespace: " << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- if (lgfound == 0)
- {
- if (pDict->dropLogfileGroup(pDict->getLogfileGroup(lgname)) != 0)
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-int
-runBug29186(NDBT_Context* ctx, NDBT_Step* step)
-{
- int lgError = 15000;
- int tsError = 16000;
- int res;
- char lgname[256];
- char ufname[256];
- char tsname[256];
- char dfname[256];
-
- NdbRestarter restarter;
-
- if (restarter.getNumDbNodes() < 2){
- ctx->stopTest();
- return NDBT_OK;
- }
-
- Ndb* pNdb = GETNDB(step);
- NdbDictionary::Dictionary* pDict = pNdb->getDictionary();
- NdbDictionary::Dictionary::List list;
-
- if (pDict->listObjects(list) == -1)
- return NDBT_FAILED;
-
- // 1.create logfile group
- const char * lgfound = 0;
-
- for (Uint32 i = 0; i<list.count; i++)
- {
- switch(list.elements[i].type){
- case NdbDictionary::Object::LogfileGroup:
- lgfound = list.elements[i].name;
- break;
- default:
- break;
- }
- if (lgfound)
- break;
- }
-
- if (lgfound == 0)
- {
- BaseString::snprintf(lgname, sizeof(lgname), "LG-%u", rand());
- NdbDictionary::LogfileGroup lg;
-
- lg.setName(lgname);
- lg.setUndoBufferSize(8*1024*1024);
- if(pDict->createLogfileGroup(lg) != 0)
- {
- g_err << "Failed to create logfilegroup:"
- << endl << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
- }
- else
- {
- BaseString::snprintf(lgname, sizeof(lgname), "%s", lgfound);
- }
-
- if(restarter.waitClusterStarted(60)){
- g_err << "waitClusterStarted failed"<< endl;
- return NDBT_FAILED;
- }
-
- if(restarter.insertErrorInAllNodes(lgError) != 0){
- g_err << "failed to set error insert"<< endl;
- return NDBT_FAILED;
- }
-
- g_info << "error inserted" << endl;
- g_info << "waiting some before add log file" << endl;
- g_info << "starting create log file group" << endl;
-
- NdbDictionary::Undofile uf;
- BaseString::snprintf(ufname, sizeof(ufname), "%s-%u", lgname, rand());
- uf.setPath(ufname);
- uf.setSize(2*1024*1024);
- uf.setLogfileGroup(lgname);
-
- if(pDict->createUndofile(uf) == 0)
- {
- g_err << "Create log file group should fail on error_insertion " << lgError << endl;
- return NDBT_FAILED;
- }
-
- //clear lg error
- if(restarter.insertErrorInAllNodes(15099) != 0){
- g_err << "failed to set error insert"<< endl;
- return NDBT_FAILED;
- }
- NdbSleep_SecSleep(5);
-
- //lg error has been cleared, so we can add undo file
- if(pDict->createUndofile(uf) != 0)
- {
- g_err << "Failed to create undofile:"
- << endl << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- if(restarter.waitClusterStarted(60)){
- g_err << "waitClusterStarted failed"<< endl;
- return NDBT_FAILED;
- }
-
- if(restarter.insertErrorInAllNodes(tsError) != 0){
- g_err << "failed to set error insert"<< endl;
- return NDBT_FAILED;
- }
- g_info << "error inserted" << endl;
- g_info << "waiting some before create table space" << endl;
- g_info << "starting create table space" << endl;
-
- //r = runCreateTablespace(ctx, step);
- BaseString::snprintf(tsname, sizeof(tsname), "TS-%u", rand());
- BaseString::snprintf(dfname, sizeof(dfname), "%s-%u-1.dat", tsname, rand());
-
- NdbDictionary::Tablespace ts;
- ts.setName(tsname);
- ts.setExtentSize(1024*1024);
- ts.setDefaultLogfileGroup(lgname);
-
- if(pDict->createTablespace(ts) != 0)
- {
- g_err << "Failed to create tablespace:"
- << endl << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- NdbDictionary::Datafile df;
- df.setPath(dfname);
- df.setSize(1*1024*1024);
- df.setTablespace(tsname);
-
- if(pDict->createDatafile(df) == 0)
- {
- g_err << "Create table space should fail on error_insertion " << tsError << endl;
- return NDBT_FAILED;
- }
- //Clear the inserted error
- if(restarter.insertErrorInAllNodes(16099) != 0){
- g_err << "failed to set error insert"<< endl;
- return NDBT_FAILED;
- }
- NdbSleep_SecSleep(5);
-
- if (pDict->dropTablespace(pDict->getTablespace(tsname)) != 0)
- {
- g_err << "Failed to drop tablespace: " << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- if (lgfound == 0)
- {
- if (pDict->dropLogfileGroup(pDict->getLogfileGroup(lgname)) != 0)
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-struct RandSchemaOp
-{
- struct Obj
- {
- BaseString m_name;
- Uint32 m_type;
- struct Obj* m_parent;
- Vector<Obj*> m_dependant;
- };
-
- Vector<Obj*> m_objects;
-
- int schema_op(Ndb*);
- int validate(Ndb*);
- int cleanup(Ndb*);
-
- Obj* get_obj(Uint32 mask);
- int create_table(Ndb*);
- int create_index(Ndb*, Obj*);
- int drop_obj(Ndb*, Obj*);
-
- void remove_obj(Obj*);
-};
-
-template class Vector<RandSchemaOp::Obj*>;
-
-int
-RandSchemaOp::schema_op(Ndb* ndb)
-{
- struct Obj* obj = 0;
- Uint32 type = 0;
-loop:
- switch((rand() >> 16) & 3){
- case 0:
- return create_table(ndb);
- case 1:
- if ((obj = get_obj(1 << NdbDictionary::Object::UserTable)) == 0)
- goto loop;
- return create_index(ndb, obj);
- case 2:
- type = (1 << NdbDictionary::Object::UserTable);
- goto drop_object;
- case 3:
- type =
- (1 << NdbDictionary::Object::UniqueHashIndex) |
- (1 << NdbDictionary::Object::OrderedIndex);
- goto drop_object;
- default:
- goto loop;
- }
-
-drop_object:
- if ((obj = get_obj(type)) == 0)
- goto loop;
- return drop_obj(ndb, obj);
-}
-
-RandSchemaOp::Obj*
-RandSchemaOp::get_obj(Uint32 mask)
-{
- Vector<Obj*> tmp;
- for (Uint32 i = 0; i<m_objects.size(); i++)
- {
- if ((1 << m_objects[i]->m_type) & mask)
- tmp.push_back(m_objects[i]);
- }
-
- if (tmp.size())
- {
- return tmp[rand()%tmp.size()];
- }
- return 0;
-}
-
-int
-RandSchemaOp::create_table(Ndb* ndb)
-{
- int numTables = NDBT_Tables::getNumTables();
- int num = myRandom48(numTables);
- NdbDictionary::Table pTab = * NDBT_Tables::getTable(num);
-
- NdbDictionary::Dictionary* pDict = ndb->getDictionary();
-
- if (pDict->getTable(pTab.getName()))
- {
- char buf[100];
- BaseString::snprintf(buf, sizeof(buf), "%s-%d",
- pTab.getName(), rand());
- pTab.setName(buf);
- if (pDict->createTable(pTab))
- return NDBT_FAILED;
- }
- else
- {
- if (NDBT_Tables::createTable(ndb, pTab.getName()))
- {
- return NDBT_FAILED;
- }
- }
-
- ndbout_c("create table %s", pTab.getName());
- const NdbDictionary::Table* tab2 = pDict->getTable(pTab.getName());
- HugoTransactions trans(*tab2);
- trans.loadTable(ndb, 1000);
-
- Obj *obj = new Obj;
- obj->m_name.assign(pTab.getName());
- obj->m_type = NdbDictionary::Object::UserTable;
- obj->m_parent = 0;
- m_objects.push_back(obj);
-
- return NDBT_OK;
-}
-
-int
-RandSchemaOp::create_index(Ndb* ndb, Obj* tab)
-{
- NdbDictionary::Dictionary* pDict = ndb->getDictionary();
- const NdbDictionary::Table * pTab = pDict->getTable(tab->m_name.c_str());
-
- if (pTab == 0)
- {
- return NDBT_FAILED;
- }
-
- bool ordered = (rand() >> 16) & 1;
- bool stored = (rand() >> 16) & 1;
-
- Uint32 type = ordered ?
- NdbDictionary::Index::OrderedIndex :
- NdbDictionary::Index::UniqueHashIndex;
-
- char buf[255];
- BaseString::snprintf(buf, sizeof(buf), "%s-%s",
- pTab->getName(),
- ordered ? "OI" : "UI");
-
- if (pDict->getIndex(buf, pTab->getName()))
- {
- // Index exists...let it be ok
- return NDBT_OK;
- }
-
- ndbout_c("create index %s", buf);
- NdbDictionary::Index idx0;
- idx0.setName(buf);
- idx0.setType((NdbDictionary::Index::Type)type);
- idx0.setTable(pTab->getName());
- idx0.setStoredIndex(ordered ? false : stored);
-
- for (Uint32 i = 0; i<pTab->getNoOfColumns(); i++)
- {
- if (pTab->getColumn(i)->getPrimaryKey())
- idx0.addColumn(pTab->getColumn(i)->getName());
- }
- if (pDict->createIndex(idx0))
- {
- ndbout << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
- Obj *obj = new Obj;
- obj->m_name.assign(buf);
- obj->m_type = type;
- obj->m_parent = tab;
- m_objects.push_back(obj);
-
- tab->m_dependant.push_back(obj);
- return NDBT_OK;
-}
-
-int
-RandSchemaOp::drop_obj(Ndb* ndb, Obj* obj)
-{
- NdbDictionary::Dictionary* pDict = ndb->getDictionary();
-
- if (obj->m_type == NdbDictionary::Object::UserTable)
- {
- ndbout_c("drop table %s", obj->m_name.c_str());
- /**
- * Drop of table automatically drops all indexes
- */
- if (pDict->dropTable(obj->m_name.c_str()))
- {
- return NDBT_FAILED;
- }
- while(obj->m_dependant.size())
- {
- remove_obj(obj->m_dependant[0]);
- }
- remove_obj(obj);
- }
- else if (obj->m_type == NdbDictionary::Object::UniqueHashIndex ||
- obj->m_type == NdbDictionary::Object::OrderedIndex)
- {
- ndbout_c("drop index %s", obj->m_name.c_str());
- if (pDict->dropIndex(obj->m_name.c_str(),
- obj->m_parent->m_name.c_str()))
- {
- return NDBT_FAILED;
- }
- remove_obj(obj);
- }
- return NDBT_OK;
-}
-
-void
-RandSchemaOp::remove_obj(Obj* obj)
-{
- Uint32 i;
- if (obj->m_parent)
- {
- bool found = false;
- for (i = 0; i<obj->m_parent->m_dependant.size(); i++)
- {
- if (obj->m_parent->m_dependant[i] == obj)
- {
- found = true;
- obj->m_parent->m_dependant.erase(i);
- break;
- }
- }
- assert(found);
- }
-
- {
- bool found = false;
- for (i = 0; i<m_objects.size(); i++)
- {
- if (m_objects[i] == obj)
- {
- found = true;
- m_objects.erase(i);
- break;
- }
- }
- assert(found);
- }
- delete obj;
-}
-
-int
-RandSchemaOp::validate(Ndb* ndb)
-{
- NdbDictionary::Dictionary* pDict = ndb->getDictionary();
- for (Uint32 i = 0; i<m_objects.size(); i++)
- {
- if (m_objects[i]->m_type == NdbDictionary::Object::UserTable)
- {
- const NdbDictionary::Table* tab2 =
- pDict->getTable(m_objects[i]->m_name.c_str());
- HugoTransactions trans(*tab2);
- trans.scanUpdateRecords(ndb, 1000);
- trans.clearTable(ndb);
- trans.loadTable(ndb, 1000);
- }
- }
-
- return NDBT_OK;
-}
-
-/*
- SystemTable = 1, ///< System table
- UserTable = 2, ///< User table (may be temporary)
- UniqueHashIndex = 3, ///< Unique un-ordered hash index
- OrderedIndex = 6, ///< Non-unique ordered index
- HashIndexTrigger = 7, ///< Index maintenance, internal
- IndexTrigger = 8, ///< Index maintenance, internal
- SubscriptionTrigger = 9,///< Backup or replication, internal
- ReadOnlyConstraint = 10,///< Trigger, internal
- Tablespace = 20, ///< Tablespace
- LogfileGroup = 21, ///< Logfile group
- Datafile = 22, ///< Datafile
- Undofile = 23 ///< Undofile
-*/
-
-int
-RandSchemaOp::cleanup(Ndb* ndb)
-{
- Int32 i;
- for (i = m_objects.size() - 1; i >= 0; i--)
- {
- switch(m_objects[i]->m_type){
- case NdbDictionary::Object::UniqueHashIndex:
- case NdbDictionary::Object::OrderedIndex:
- if (drop_obj(ndb, m_objects[i]))
- return NDBT_FAILED;
-
- break;
- default:
- break;
- }
- }
-
- for (i = m_objects.size() - 1; i >= 0; i--)
- {
- switch(m_objects[i]->m_type){
- case NdbDictionary::Object::UserTable:
- if (drop_obj(ndb, m_objects[i]))
- return NDBT_FAILED;
- break;
- default:
- break;
- }
- }
-
- assert(m_objects.size() == 0);
- return NDBT_OK;
-}
-
-int
-runDictRestart(NDBT_Context* ctx, NDBT_Step* step)
-{
- Ndb* pNdb = GETNDB(step);
- int loops = ctx->getNumLoops();
-
- NdbMixRestarter res;
-
- RandSchemaOp dict;
- if (res.getNumDbNodes() < 2)
- return NDBT_OK;
-
- if (res.init(ctx, step))
- return NDBT_FAILED;
-
- for (Uint32 i = 0; i<loops; i++)
- {
- for (Uint32 j = 0; j<10; j++)
- if (dict.schema_op(pNdb))
- return NDBT_FAILED;
-
- if (res.dostep(ctx, step))
- return NDBT_FAILED;
-
- if (dict.validate(pNdb))
- return NDBT_FAILED;
- }
-
- if (res.finish(ctx, step))
- return NDBT_FAILED;
-
- if (dict.validate(pNdb))
- return NDBT_FAILED;
-
- if (dict.cleanup(pNdb))
- return NDBT_FAILED;
-
- return NDBT_OK;
-}
-
-int
-runBug29501(NDBT_Context* ctx, NDBT_Step* step) {
- NdbRestarter res;
- NdbDictionary::LogfileGroup lg;
- lg.setName("DEFAULT-LG");
- lg.setUndoBufferSize(8*1024*1024);
-
- if (res.getNumDbNodes() < 2)
- return NDBT_OK;
-
- Ndb* pNdb = GETNDB(step);
- NdbDictionary::Dictionary* pDict = pNdb->getDictionary();
-
- int node = res.getRandomNotMasterNodeId(rand());
- res.restartOneDbNode(node, true, true, false);
-
- if(pDict->createLogfileGroup(lg) != 0){
- g_err << "Failed to create logfilegroup:"
- << endl << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- NdbDictionary::Undofile uf;
- uf.setPath("undofile01.dat");
- uf.setSize(5*1024*1024);
- uf.setLogfileGroup("DEFAULT-LG");
-
- if(pDict->createUndofile(uf) != 0){
- g_err << "Failed to create undofile:"
- << endl << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- res.waitNodesNoStart(&node, 1);
- res.startNodes(&node, 1);
-
- if (res.waitClusterStarted()){
- g_err << "Node restart failed"
- << endl << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- if (pDict->dropLogfileGroup(pDict->getLogfileGroup(lg.getName())) != 0){
- g_err << "Drop of LFG Failed"
- << endl << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-int
-runDropDDObjects(NDBT_Context* ctx, NDBT_Step* step){
- //Purpose is to drop all tables, data files, Table spaces and LFG's
- Uint32 i = 0;
-
- Ndb* pNdb = GETNDB(step);
- NdbDictionary::Dictionary* pDict = pNdb->getDictionary();
-
- NdbDictionary::Dictionary::List list;
- if (pDict->listObjects(list) == -1)
- return NDBT_FAILED;
-
- //Search the list and drop all tables found
- const char * tableFound = 0;
- for (i = 0; i < list.count; i++){
- switch(list.elements[i].type){
- case NdbDictionary::Object::UserTable:
- tableFound = list.elements[i].name;
- if(tableFound != 0){
- if(strcmp(tableFound, "ndb_apply_status") != 0 &&
- strcmp(tableFound, "NDB$BLOB_2_3") != 0 &&
- strcmp(tableFound, "ndb_schema") != 0){
- if(pDict->dropTable(tableFound) != 0){
- g_err << "Failed to drop table: " << tableFound << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
- }
- }
- tableFound = 0;
- break;
- default:
- break;
- }
- }
-
- //Search the list and drop all data file found
- const char * dfFound = 0;
- for (i = 0; i < list.count; i++){
- switch(list.elements[i].type){
- case NdbDictionary::Object::Datafile:
- dfFound = list.elements[i].name;
- if(dfFound != 0){
- if(pDict->dropDatafile(pDict->getDatafile(0, dfFound)) != 0){
- g_err << "Failed to drop datafile: " << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
- }
- dfFound = 0;
- break;
- default:
- break;
- }
- }
-
- //Search the list and drop all Table Spaces Found
- const char * tsFound = 0;
- for (i = 0; i <list.count; i++){
- switch(list.elements[i].type){
- case NdbDictionary::Object::Tablespace:
- tsFound = list.elements[i].name;
- if(tsFound != 0){
- if(pDict->dropTablespace(pDict->getTablespace(tsFound)) != 0){
- g_err << "Failed to drop tablespace: " << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
- }
- tsFound = 0;
- break;
- default:
- break;
- }
- }
-
- //Search the list and drop all LFG Found
- //Currently only 1 LGF is supported, but written for future
- //when more then one is supported.
- const char * lgFound = 0;
- for (i = 0; i < list.count; i++){
- switch(list.elements[i].type){
- case NdbDictionary::Object::LogfileGroup:
- lgFound = list.elements[i].name;
- if(lgFound != 0){
- if (pDict->dropLogfileGroup(pDict->getLogfileGroup(lgFound)) != 0){
- g_err << "Failed to drop tablespace: " << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
- }
- lgFound = 0;
- break;
- default:
- break;
- }
- }
-
- return NDBT_OK;
-}
-
-int
-runWaitStarted(NDBT_Context* ctx, NDBT_Step* step){
-
- NdbRestarter restarter;
- restarter.waitClusterStarted(300);
-
- NdbSleep_SecSleep(3);
- return NDBT_OK;
-}
-
-int
-testDropDDObjectsSetup(NDBT_Context* ctx, NDBT_Step* step){
- //Purpose is to setup to test DropDDObjects
- char tsname[256];
- char dfname[256];
-
- Ndb* pNdb = GETNDB(step);
- NdbDictionary::Dictionary* pDict = pNdb->getDictionary();
-
- NdbDictionary::LogfileGroup lg;
- lg.setName("DEFAULT-LG");
- lg.setUndoBufferSize(8*1024*1024);
-
-
- if(pDict->createLogfileGroup(lg) != 0){
- g_err << "Failed to create logfilegroup:"
- << endl << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- NdbDictionary::Undofile uf;
- uf.setPath("undofile01.dat");
- uf.setSize(5*1024*1024);
- uf.setLogfileGroup("DEFAULT-LG");
-
- if(pDict->createUndofile(uf) != 0){
- g_err << "Failed to create undofile:"
- << endl << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- BaseString::snprintf(tsname, sizeof(tsname), "TS-%u", rand());
- BaseString::snprintf(dfname, sizeof(dfname), "%s-%u.dat", tsname, rand());
-
- if (create_tablespace(pDict, lg.getName(), tsname, dfname)){
- g_err << "Failed to create undofile:"
- << endl << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-int
-DropDDObjectsVerify(NDBT_Context* ctx, NDBT_Step* step){
- //Purpose is to verify test DropDDObjects worked
- Uint32 i = 0;
-
- Ndb* pNdb = GETNDB(step);
- NdbDictionary::Dictionary* pDict = pNdb->getDictionary();
-
- NdbDictionary::Dictionary::List list;
- if (pDict->listObjects(list) == -1)
- return NDBT_FAILED;
-
- bool ddFound = false;
- for (i = 0; i <list.count; i++){
- switch(list.elements[i].type){
- case NdbDictionary::Object::Tablespace:
- ddFound = true;
- break;
- case NdbDictionary::Object::LogfileGroup:
- ddFound = true;
- break;
- default:
- break;
- }
- if(ddFound == true){
- g_err << "DropDDObjects Failed: DD found:"
- << endl;
- return NDBT_FAILED;
- }
- }
- return NDBT_OK;
-}
-
-NDBT_TESTSUITE(testDict);
-TESTCASE("testDropDDObjects",
- "* 1. start cluster\n"
- "* 2. Create LFG\n"
- "* 3. create TS\n"
- "* 4. run DropDDObjects\n"
- "* 5. Verify DropDDObjectsRestart worked\n"){
-INITIALIZER(runWaitStarted);
-INITIALIZER(runDropDDObjects);
-INITIALIZER(testDropDDObjectsSetup);
-STEP(runDropDDObjects);
-FINALIZER(DropDDObjectsVerify);
-}
-
-TESTCASE("Bug29501",
- "* 1. start cluster\n"
- "* 2. Restart 1 node -abort -nostart\n"
- "* 3. create LFG\n"
- "* 4. Restart data node\n"
- "* 5. Restart 1 node -nostart\n"
- "* 6. Drop LFG\n"){
-INITIALIZER(runWaitStarted);
-INITIALIZER(runDropDDObjects);
-STEP(runBug29501);
-FINALIZER(runDropDDObjects);
-}
-TESTCASE("CreateAndDrop",
- "Try to create and drop the table loop number of times\n"){
- INITIALIZER(runCreateAndDrop);
-}
-TESTCASE("CreateAndDropAtRandom",
- "Try to create and drop table at random loop number of times\n"
- "Uses all available tables\n"
- "Uses error insert 4013 to make TUP verify table descriptor"){
- INITIALIZER(runCreateAndDropAtRandom);
-}
-TESTCASE("CreateAndDropWithData",
- "Try to create and drop the table when it's filled with data\n"
- "do this loop number of times\n"){
- INITIALIZER(runCreateAndDropWithData);
-}
-TESTCASE("CreateAndDropDuring",
- "Try to create and drop the table when other thread is using it\n"
- "do this loop number of times\n"){
- STEP(runCreateAndDropDuring);
- STEP(runUseTableUntilStopped);
-}
-TESTCASE("CreateInvalidTables",
- "Try to create the invalid tables we have defined\n"){
- INITIALIZER(runCreateInvalidTables);
-}
-TESTCASE("CreateTableWhenDbIsFull",
- "Try to create a new table when db already is full\n"){
- INITIALIZER(runCreateTheTable);
- INITIALIZER(runFillTable);
- INITIALIZER(runCreateTableWhenDbIsFull);
- INITIALIZER(runDropTableWhenDbIsFull);
- FINALIZER(runDropTheTable);
-}
-TESTCASE("FragmentTypeSingle",
- "Create the table with fragment type Single\n"){
- TC_PROPERTY("FragmentType", NdbDictionary::Table::FragSingle);
- INITIALIZER(runTestFragmentTypes);
-}
-TESTCASE("FragmentTypeAllSmall",
- "Create the table with fragment type AllSmall\n"){
- TC_PROPERTY("FragmentType", NdbDictionary::Table::FragAllSmall);
- INITIALIZER(runTestFragmentTypes);
-}
-TESTCASE("FragmentTypeAllMedium",
- "Create the table with fragment type AllMedium\n"){
- TC_PROPERTY("FragmentType", NdbDictionary::Table::FragAllMedium);
- INITIALIZER(runTestFragmentTypes);
-}
-TESTCASE("FragmentTypeAllLarge",
- "Create the table with fragment type AllLarge\n"){
- TC_PROPERTY("FragmentType", NdbDictionary::Table::FragAllLarge);
- INITIALIZER(runTestFragmentTypes);
-}
-TESTCASE("TemporaryTables",
- "Create the table as temporary and make sure it doesn't\n"
- "contain any data when system is restarted\n"){
- INITIALIZER(runTestTemporaryTables);
-}
-TESTCASE("CreateMaxTables",
- "Create tables until db says that it can't create any more\n"){
- TC_PROPERTY("tables", 1000);
- INITIALIZER(runCreateMaxTables);
- INITIALIZER(runDropMaxTables);
-}
-TESTCASE("PkSizes",
- "Create tables with all different primary key sizes.\n"\
- "Test all data operations insert, update, delete etc.\n"\
- "Drop table."){
- INITIALIZER(runPkSizes);
-}
-TESTCASE("StoreFrm",
- "Test that a frm file can be properly stored as part of the\n"
- "data in Dict."){
- INITIALIZER(runStoreFrm);
-}
-TESTCASE("GetPrimaryKey",
- "Test the function NdbDictionary::Column::getPrimaryKey\n"
- "It should return true only if the column is part of \n"
- "the primary key in the table"){
- INITIALIZER(runGetPrimaryKey);
-}
-TESTCASE("StoreFrmError",
- "Test that a frm file with too long length can't be stored."){
- INITIALIZER(runStoreFrmError);
-}
-TESTCASE("NF1",
- "Test that create table can handle NF (not master)"){
- INITIALIZER(runNF1);
-}
-TESTCASE("TableRename",
- "Test basic table rename"){
- INITIALIZER(runTableRename);
-}
-TESTCASE("TableRenameNF",
- "Test that table rename can handle node failure"){
- INITIALIZER(runTableRenameNF);
-}
-TESTCASE("TableRenameSR",
- "Test that table rename can handle system restart"){
- INITIALIZER(runTableRenameSR);
-}
-TESTCASE("DictionaryPerf",
- ""){
- INITIALIZER(runTestDictionaryPerf);
-}
-TESTCASE("CreateLogfileGroup", ""){
- INITIALIZER(runCreateLogfileGroup);
-}
-TESTCASE("CreateTablespace", ""){
- INITIALIZER(runCreateTablespace);
-}
-TESTCASE("CreateDiskTable", ""){
- INITIALIZER(runCreateDiskTable);
-}
-TESTCASE("FailAddFragment",
- "Fail add fragment or attribute in ACC or TUP or TUX\n"){
- INITIALIZER(runFailAddFragment);
-}
-TESTCASE("Restart_NF1",
- "DICT ops during node graceful shutdown (not master)"){
- TC_PROPERTY("Restart_NF_ops", 1);
- TC_PROPERTY("Restart_NF_type", 1);
- STEP(runRestarts);
- STEP(runDictOps);
-}
-TESTCASE("Restart_NF2",
- "DICT ops during node shutdown abort (not master)"){
- TC_PROPERTY("Restart_NF_ops", 1);
- TC_PROPERTY("Restart_NF_type", 2);
- STEP(runRestarts);
- STEP(runDictOps);
-}
-TESTCASE("Restart_NR1",
- "DICT ops during node startup (not master)"){
- TC_PROPERTY("Restart_NR_ops", 1);
- STEP(runRestarts);
- STEP(runDictOps);
-}
-TESTCASE("Restart_NR2",
- "DICT ops during node startup with crash inserts (not master)"){
- TC_PROPERTY("Restart_NR_ops", 1);
- TC_PROPERTY("Restart_NR_error", 1);
- STEP(runRestarts);
- STEP(runDictOps);
-}
-TESTCASE("Bug21755",
- ""){
- INITIALIZER(runBug21755);
-}
-TESTCASE("DictRestart",
- ""){
- INITIALIZER(runDictRestart);
-}
-TESTCASE("Bug24631",
- ""){
- INITIALIZER(runBug24631);
-}
-TESTCASE("Bug29186",
- ""){
- INITIALIZER(runBug29186);
-}
-NDBT_TESTSUITE_END(testDict);
-
-int main(int argc, const char** argv){
- ndb_init();
- // Tables should not be auto created
- testDict.setCreateTable(false);
- myRandom48Init(NdbTick_CurrentMillisecond());
- return testDict.execute(argc, argv);
-}
diff --git a/storage/ndb/test/ndbapi/testGrepVerify.cpp b/storage/ndb/test/ndbapi/testGrepVerify.cpp
deleted file mode 100644
index 9388f28bf41..00000000000
--- a/storage/ndb/test/ndbapi/testGrepVerify.cpp
+++ /dev/null
@@ -1,118 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-#include "mgmapi.h"
-#include <string.h>
-#include <NdbMain.h>
-#include <OutputStream.hpp>
-#include <NdbOut.hpp>
-#include <NdbSleep.h>
-#include <getarg.h>
-
-#include <NdbApi.hpp>
-#include <NDBT.hpp>
-
-#include <NDBT_Test.hpp>
-#include <HugoTransactions.hpp>
-#include <UtilTransactions.hpp>
-#include <ConfigRetriever.hpp>
-#include <ndb_version.h>
-
-
-#define CHECK(b) if (!(b)) { \
- g_err << "ERR: "<< "getStep" \
- << " failed on line " << __LINE__ << endl; \
- result = NDBT_FAILED; \
- continue; }
-
-int main(int argc, const char** argv){
- ndb_init();
-
-
- const char * connectString = NULL;
- const char * table = NULL;
- int records = 0;
- int _help = 0;
-
- struct getargs args[] = {
- { "connectString", 'c', arg_string, &connectString,
- "ConnectString", "nodeid=<api id>;host=<hostname:port>" },
- { "tableName", 't', arg_string, &table,
- "table", "Table" },
- { "records", 'r', arg_integer, &records, "Number of records", "recs"},
- { "usage", '?', arg_flag, &_help, "Print help", "" }
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "hostname:port\n"\
- "This program will connect to the mgmsrv of a NDB cluster.\n"\
- "It will then wait for all nodes to be started, then restart node(s)\n"\
- "and wait for all to restart inbetween. It will do this \n"\
- "loop number of times\n";
-
- if(getarg(args, num_args, argc, argv, &optind) || _help) {
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
- ndbout_c("table %s connectStirng %s", table, connectString);
- if(connectString == 0)
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- if(table == 0)
- return NDBT_ProgramExit(NDBT_WRONGARGS);
-
- Ndb * m_ndb = new Ndb("");
- m_ndb->useFullyQualifiedNames(false);
- m_ndb->setConnectString(connectString);
- /**
- * @todo Set proper max no of transactions?? needed?? Default 12??
- */
- m_ndb->init(2048);
- if (m_ndb->waitUntilReady() != 0){
- ndbout_c("NDB Cluster not ready for connections");
- }
-
- int count = 0;
- int result = NDBT_OK;
-
-
- const NdbDictionary::Table * tab = NDBT_Table::discoverTableFromDb( m_ndb, table);
-// ndbout << *tab << endl;
-
- UtilTransactions utilTrans(*tab);
- HugoTransactions hugoTrans(*tab);
-
- do{
-
- // Check that there are as many records as we expected
- CHECK(utilTrans.selectCount(m_ndb, 64, &count) == 0);
-
- g_err << "count = " << count;
- g_err << " records = " << records;
- g_err << endl;
-
- CHECK(count == records);
-
- // Read and verify every record
- CHECK(hugoTrans.pkReadRecords(m_ndb, records) == 0);
-
- } while (false);
-
-
- return NDBT_ProgramExit(result);
-
-}
diff --git a/storage/ndb/test/ndbapi/testIndex.cpp b/storage/ndb/test/ndbapi/testIndex.cpp
deleted file mode 100644
index e5699502171..00000000000
--- a/storage/ndb/test/ndbapi/testIndex.cpp
+++ /dev/null
@@ -1,1758 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT.hpp>
-#include <NDBT_Test.hpp>
-#include <HugoTransactions.hpp>
-#include <UtilTransactions.hpp>
-#include <NdbRestarter.hpp>
-#include <NdbRestarts.hpp>
-#include <Vector.hpp>
-#include <signaldata/DumpStateOrd.hpp>
-
-#define CHECK(b) if (!(b)) { \
- g_err << "ERR: "<< step->getName() \
- << " failed on line " << __LINE__ << endl; \
- result = NDBT_FAILED; break;\
-}
-
-
-struct Attrib {
- bool indexCreated;
- int numAttribs;
- int attribs[1024];
- Attrib(){
- numAttribs = 0;
- indexCreated = false;
- }
-};
-class AttribList {
-public:
- AttribList(){};
- ~AttribList(){
- for(size_t i = 0; i < attriblist.size(); i++){
- delete attriblist[i];
- }
- };
- void buildAttribList(const NdbDictionary::Table* pTab);
- Vector<Attrib*> attriblist;
-};
-
-void AttribList::buildAttribList(const NdbDictionary::Table* pTab){
- attriblist.clear();
-
- Attrib* attr;
- // Build attrib definitions that describes which attributes to build index
- // Try to build strange combinations, not just "all" or all PK's
-
- int i;
-
- for(i = 1; i <= pTab->getNoOfColumns(); i++){
- attr = new Attrib;
- attr->numAttribs = i;
- for(int a = 0; a<i; a++)
- attr->attribs[a] = a;
- attriblist.push_back(attr);
- }
- int b = 0;
- for(i = pTab->getNoOfColumns()-1; i > 0; i--){
- attr = new Attrib;
- attr->numAttribs = i;
- b++;
- for(int a = 0; a<i; a++)
- attr->attribs[a] = a+b;
- attriblist.push_back(attr);
- }
- for(i = pTab->getNoOfColumns(); i > 0; i--){
- attr = new Attrib;
- attr->numAttribs = pTab->getNoOfColumns() - i;
- for(int a = 0; a<pTab->getNoOfColumns() - i; a++)
- attr->attribs[a] = pTab->getNoOfColumns()-a-1;
- attriblist.push_back(attr);
- }
- for(i = 1; i < pTab->getNoOfColumns(); i++){
- attr = new Attrib;
- attr->numAttribs = pTab->getNoOfColumns() - i;
- for(int a = 0; a<pTab->getNoOfColumns() - i; a++)
- attr->attribs[a] = pTab->getNoOfColumns()-a-1;
- attriblist.push_back(attr);
- }
- for(i = 1; i < pTab->getNoOfColumns(); i++){
- attr = new Attrib;
- attr->numAttribs = 2;
- for(int a = 0; a<2; a++){
- attr->attribs[a] = i%pTab->getNoOfColumns();
- }
- attriblist.push_back(attr);
- }
-
- // Last
- attr = new Attrib;
- attr->numAttribs = 1;
- attr->attribs[0] = pTab->getNoOfColumns()-1;
- attriblist.push_back(attr);
-
- // Last and first
- attr = new Attrib;
- attr->numAttribs = 2;
- attr->attribs[0] = pTab->getNoOfColumns()-1;
- attr->attribs[1] = 0;
- attriblist.push_back(attr);
-
- // First and last
- attr = new Attrib;
- attr->numAttribs = 2;
- attr->attribs[0] = 0;
- attr->attribs[1] = pTab->getNoOfColumns()-1;
- attriblist.push_back(attr);
-
-#if 0
- for(size_t i = 0; i < attriblist.size(); i++){
-
- ndbout << attriblist[i]->numAttribs << ": " ;
- for(int a = 0; a < attriblist[i]->numAttribs; a++)
- ndbout << attriblist[i]->attribs[a] << ", ";
- ndbout << endl;
- }
-#endif
-
-}
-
-char idxName[255];
-char pkIdxName[255];
-
-static const int SKIP_INDEX = 99;
-
-int create_index(NDBT_Context* ctx, int indxNum,
- const NdbDictionary::Table* pTab,
- Ndb* pNdb, Attrib* attr, bool logged){
- bool orderedIndex = ctx->getProperty("OrderedIndex", (unsigned)0);
- int result = NDBT_OK;
-
- HugoCalculator calc(*pTab);
-
- if (attr->numAttribs == 1 &&
- calc.isUpdateCol(attr->attribs[0]) == true){
- // Don't create index for the Hugo update column
- // since it's not unique
- return SKIP_INDEX;
- }
-
- // Create index
- BaseString::snprintf(idxName, 255, "IDC%d", indxNum);
- if (orderedIndex)
- ndbout << "Creating " << ((logged)?"logged ": "temporary ") << "ordered index "<<idxName << " (";
- else
- ndbout << "Creating " << ((logged)?"logged ": "temporary ") << "unique index "<<idxName << " (";
- ndbout << flush;
- NdbDictionary::Index pIdx(idxName);
- pIdx.setTable(pTab->getName());
- if (orderedIndex)
- pIdx.setType(NdbDictionary::Index::OrderedIndex);
- else
- pIdx.setType(NdbDictionary::Index::UniqueHashIndex);
- for (int c = 0; c< attr->numAttribs; c++){
- int attrNo = attr->attribs[c];
- pIdx.addIndexColumn(pTab->getColumn(attrNo)->getName());
- ndbout << pTab->getColumn(attrNo)->getName()<<" ";
- }
-
- pIdx.setStoredIndex(logged);
- ndbout << ") ";
- if (pNdb->getDictionary()->createIndex(pIdx) != 0){
- attr->indexCreated = false;
- ndbout << "FAILED!" << endl;
- const NdbError err = pNdb->getDictionary()->getNdbError();
- ERR(err);
- if(err.classification == NdbError::ApplicationError)
- return SKIP_INDEX;
-
- return NDBT_FAILED;
- } else {
- ndbout << "OK!" << endl;
- attr->indexCreated = true;
- }
- return result;
-}
-
-
-int drop_index(int indxNum, Ndb* pNdb,
- const NdbDictionary::Table* pTab, Attrib* attr){
- int result = NDBT_OK;
-
- if (attr->indexCreated == false)
- return NDBT_OK;
-
- BaseString::snprintf(idxName, 255, "IDC%d", indxNum);
-
- // Drop index
- ndbout << "Dropping index "<<idxName<<"(" << pTab->getName() << ") ";
- if (pNdb->getDictionary()->dropIndex(idxName, pTab->getName()) != 0){
- ndbout << "FAILED!" << endl;
- ERR(pNdb->getDictionary()->getNdbError());
- result = NDBT_FAILED;
- } else {
- ndbout << "OK!" << endl;
- }
- return result;
-}
-
-int runCreateIndexes(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops();
- int l = 0;
- const NdbDictionary::Table* pTab = ctx->getTab();
- Ndb* pNdb = GETNDB(step);
- int result = NDBT_OK;
- // NOTE If we need to test creating both logged and non logged indexes
- // this should be divided into two testcases
- // The paramater logged should then be specified
- // as a TC_PROPERTY. ex TC_PROPERTY("LoggedIndexes", 1);
- // and read into the test step like
- bool logged = ctx->getProperty("LoggedIndexes", 1);
-
- AttribList attrList;
- attrList.buildAttribList(pTab);
-
-
- while (l < loops && result == NDBT_OK){
- unsigned int i;
- for (i = 0; i < attrList.attriblist.size(); i++){
-
- // Try to create index
- if (create_index(ctx, i, pTab, pNdb, attrList.attriblist[i], logged) == NDBT_FAILED)
- result = NDBT_FAILED;
- }
-
- // Now drop all indexes that where created
- for (i = 0; i < attrList.attriblist.size(); i++){
-
- // Try to drop index
- if (drop_index(i, pNdb, pTab, attrList.attriblist[i]) != NDBT_OK)
- result = NDBT_FAILED;
- }
-
- l++;
- }
-
- return result;
-}
-
-int createRandomIndex(NDBT_Context* ctx, NDBT_Step* step){
- const NdbDictionary::Table* pTab = ctx->getTab();
- Ndb* pNdb = GETNDB(step);
- bool logged = ctx->getProperty("LoggedIndexes", 1);
-
- AttribList attrList;
- attrList.buildAttribList(pTab);
-
- int retries = 100;
- while(retries > 0){
- const Uint32 i = rand() % attrList.attriblist.size();
- int res = create_index(ctx, i, pTab, pNdb, attrList.attriblist[i],
- logged);
- if (res == SKIP_INDEX){
- retries--;
- continue;
- }
-
- if (res == NDBT_FAILED){
- return NDBT_FAILED;
- }
-
- ctx->setProperty("createRandomIndex", i);
- // Now drop all indexes that where created
-
- return NDBT_OK;
- }
-
- return NDBT_FAILED;
-}
-
-int createRandomIndex_Drop(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
-
- Uint32 i = ctx->getProperty("createRandomIndex");
-
- BaseString::snprintf(idxName, 255, "IDC%d", i);
-
- // Drop index
- ndbout << "Dropping index " << idxName << " ";
- if (pNdb->getDictionary()->dropIndex(idxName,
- ctx->getTab()->getName()) != 0){
- ndbout << "FAILED!" << endl;
- ERR(pNdb->getDictionary()->getNdbError());
- return NDBT_FAILED;
- } else {
- ndbout << "OK!" << endl;
- }
-
- return NDBT_OK;
-}
-
-int createPkIndex(NDBT_Context* ctx, NDBT_Step* step){
- bool orderedIndex = ctx->getProperty("OrderedIndex", (unsigned)0);
-
- const NdbDictionary::Table* pTab = ctx->getTab();
- Ndb* pNdb = GETNDB(step);
-
- bool logged = ctx->getProperty("LoggedIndexes", 1);
-
- // Create index
- BaseString::snprintf(pkIdxName, 255, "IDC_PK_%s", pTab->getName());
- if (orderedIndex)
- ndbout << "Creating " << ((logged)?"logged ": "temporary ") << "ordered index "
- << pkIdxName << " (";
- else
- ndbout << "Creating " << ((logged)?"logged ": "temporary ") << "unique index "
- << pkIdxName << " (";
-
- NdbDictionary::Index pIdx(pkIdxName);
- pIdx.setTable(pTab->getName());
- if (orderedIndex)
- pIdx.setType(NdbDictionary::Index::OrderedIndex);
- else
- pIdx.setType(NdbDictionary::Index::UniqueHashIndex);
- for (int c = 0; c< pTab->getNoOfColumns(); c++){
- const NdbDictionary::Column * col = pTab->getColumn(c);
- if(col->getPrimaryKey()){
- pIdx.addIndexColumn(col->getName());
- ndbout << col->getName() <<" ";
- }
- }
-
- pIdx.setStoredIndex(logged);
- ndbout << ") ";
- if (pNdb->getDictionary()->createIndex(pIdx) != 0){
- ndbout << "FAILED!" << endl;
- const NdbError err = pNdb->getDictionary()->getNdbError();
- ERR(err);
- return NDBT_FAILED;
- }
-
- ndbout << "OK!" << endl;
- return NDBT_OK;
-}
-
-int createPkIndex_Drop(NDBT_Context* ctx, NDBT_Step* step){
- const NdbDictionary::Table* pTab = ctx->getTab();
- Ndb* pNdb = GETNDB(step);
-
- // Drop index
- ndbout << "Dropping index " << pkIdxName << " ";
- if (pNdb->getDictionary()->dropIndex(pkIdxName,
- pTab->getName()) != 0){
- ndbout << "FAILED!" << endl;
- ERR(pNdb->getDictionary()->getNdbError());
- return NDBT_FAILED;
- } else {
- ndbout << "OK!" << endl;
- }
-
- return NDBT_OK;
-}
-
-int
-runVerifyIndex(NDBT_Context* ctx, NDBT_Step* step){
- // Verify that data in index match
- // table data
- Ndb* pNdb = GETNDB(step);
- UtilTransactions utilTrans(*ctx->getTab());
- const int batchSize = ctx->getProperty("BatchSize", 16);
- const int parallelism = batchSize > 240 ? 240 : batchSize;
-
- do {
- if (utilTrans.verifyIndex(pNdb, idxName, parallelism, true) != 0){
- g_err << "Inconsistent index" << endl;
- return NDBT_FAILED;
- }
- } while(ctx->isTestStopped() == false);
- return NDBT_OK;
-}
-
-int
-runTransactions1(NDBT_Context* ctx, NDBT_Step* step){
- // Verify that data in index match
- // table data
- Ndb* pNdb = GETNDB(step);
- HugoTransactions hugoTrans(*ctx->getTab());
- const int batchSize = ctx->getProperty("BatchSize", 50);
-
- int rows = ctx->getNumRecords();
- while (ctx->isTestStopped() == false) {
- if (hugoTrans.pkUpdateRecords(pNdb, rows, batchSize) != 0){
- g_err << "Updated table failed" << endl;
- return NDBT_FAILED;
- }
-
- ctx->sync_down("PauseThreads");
- if(ctx->isTestStopped())
- break;
-
- if (hugoTrans.scanUpdateRecords(pNdb, rows, batchSize) != 0){
- g_err << "Updated table failed" << endl;
- return NDBT_FAILED;
- }
-
- ctx->sync_down("PauseThreads");
- }
- return NDBT_OK;
-}
-
-int
-runTransactions2(NDBT_Context* ctx, NDBT_Step* step){
- // Verify that data in index match
- // table data
- Ndb* pNdb = GETNDB(step);
- HugoTransactions hugoTrans(*ctx->getTab());
- const int batchSize = ctx->getProperty("BatchSize", 50);
-
- int rows = ctx->getNumRecords();
- while (ctx->isTestStopped() == false) {
-#if 1
- if (hugoTrans.indexReadRecords(pNdb, pkIdxName, rows, batchSize) != 0){
- g_err << "Index read failed" << endl;
- return NDBT_FAILED;
- }
-#endif
- ctx->sync_down("PauseThreads");
- if(ctx->isTestStopped())
- break;
-#if 1
- if (hugoTrans.indexUpdateRecords(pNdb, pkIdxName, rows, batchSize) != 0){
- g_err << "Index update failed" << endl;
- return NDBT_FAILED;
- }
-#endif
- ctx->sync_down("PauseThreads");
- }
- return NDBT_OK;
-}
-
-int
-runTransactions3(NDBT_Context* ctx, NDBT_Step* step){
- // Verify that data in index match
- // table data
- Ndb* pNdb = GETNDB(step);
- HugoTransactions hugoTrans(*ctx->getTab());
- UtilTransactions utilTrans(*ctx->getTab());
- const int batchSize = ctx->getProperty("BatchSize", 32);
- const int parallel = batchSize > 240 ? 240 : batchSize;
-
- int rows = ctx->getNumRecords();
- while (ctx->isTestStopped() == false) {
- if(hugoTrans.loadTable(pNdb, rows, batchSize, false) != 0){
- g_err << "Load table failed" << endl;
- return NDBT_FAILED;
- }
- ctx->sync_down("PauseThreads");
- if(ctx->isTestStopped())
- break;
-
- if (hugoTrans.pkUpdateRecords(pNdb, rows, batchSize) != 0){
- g_err << "Updated table failed" << endl;
- return NDBT_FAILED;
- }
-
- ctx->sync_down("PauseThreads");
- if(ctx->isTestStopped())
- break;
-
- if (hugoTrans.indexReadRecords(pNdb, pkIdxName, rows, batchSize) != 0){
- g_err << "Index read failed" << endl;
- return NDBT_FAILED;
- }
-
- ctx->sync_down("PauseThreads");
- if(ctx->isTestStopped())
- break;
-
- if (hugoTrans.indexUpdateRecords(pNdb, pkIdxName, rows, batchSize) != 0){
- g_err << "Index update failed" << endl;
- return NDBT_FAILED;
- }
-
- ctx->sync_down("PauseThreads");
- if(ctx->isTestStopped())
- break;
-
- if (hugoTrans.scanUpdateRecords(pNdb, rows, 5, parallel) != 0){
- g_err << "Scan updated table failed" << endl;
- return NDBT_FAILED;
- }
-
- ctx->sync_down("PauseThreads");
- if(ctx->isTestStopped())
- break;
-
- if(utilTrans.clearTable(pNdb, rows, parallel) != 0){
- g_err << "Clear table failed" << endl;
- return NDBT_FAILED;
- }
-
- ctx->sync_down("PauseThreads");
- if(ctx->isTestStopped())
- break;
-
- int count = -1;
- if(utilTrans.selectCount(pNdb, 64, &count) != 0 || count != 0)
- return NDBT_FAILED;
- ctx->sync_down("PauseThreads");
- }
- return NDBT_OK;
-}
-
-int runRestarts(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- NDBT_TestCase* pCase = ctx->getCase();
- NdbRestarts restarts;
- int i = 0;
- int timeout = 240;
- int sync_threads = ctx->getProperty("Threads", (unsigned)0);
-
- while(i<loops && result != NDBT_FAILED && !ctx->isTestStopped()){
- if(restarts.executeRestart("RestartRandomNodeAbort", timeout) != 0){
- g_err << "Failed to executeRestart(" <<pCase->getName() <<")" << endl;
- result = NDBT_FAILED;
- break;
- }
- ctx->sync_up_and_wait("PauseThreads", sync_threads);
- i++;
- }
- ctx->stopTest();
- return result;
-}
-
-int runCreateLoadDropIndex(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int l = 0;
- const NdbDictionary::Table* pTab = ctx->getTab();
- Ndb* pNdb = GETNDB(step);
- int result = NDBT_OK;
- int batchSize = ctx->getProperty("BatchSize", 1);
- int parallelism = batchSize > 240? 240: batchSize;
- ndbout << "batchSize="<<batchSize<<endl;
- bool logged = ctx->getProperty("LoggedIndexes", 1);
-
- HugoTransactions hugoTrans(*pTab);
- UtilTransactions utilTrans(*pTab);
- AttribList attrList;
- attrList.buildAttribList(pTab);
-
- for (unsigned int i = 0; i < attrList.attriblist.size(); i++){
-
- while (l < loops && result == NDBT_OK){
-
- if ((l % 2) == 0){
- // Create index first and then load
-
- // Try to create index
- if (create_index(ctx, i, pTab, pNdb, attrList.attriblist[i], logged) == NDBT_FAILED){
- result = NDBT_FAILED;
- }
-
- // Load the table with data
- ndbout << "Loading data after" << endl;
- CHECK(hugoTrans.loadTable(pNdb, records, batchSize) == 0);
-
-
- } else {
- // Load table then create index
-
- // Load the table with data
- ndbout << "Loading data before" << endl;
- CHECK(hugoTrans.loadTable(pNdb, records, batchSize) == 0);
-
- // Try to create index
- if (create_index(ctx, i, pTab, pNdb, attrList.attriblist[i], logged) == NDBT_FAILED)
- result = NDBT_FAILED;
-
- }
-
- // Verify that data in index match
- // table data
- CHECK(utilTrans.verifyIndex(pNdb, idxName, parallelism) == 0);
-
- // Do it all...
- ndbout <<"Doing it all"<<endl;
- int count;
- ndbout << " pkUpdateRecords" << endl;
- CHECK(hugoTrans.pkUpdateRecords(pNdb, records, batchSize) == 0);
- CHECK(utilTrans.verifyIndex(pNdb, idxName, parallelism) == 0);
- CHECK(hugoTrans.pkUpdateRecords(pNdb, records, batchSize) == 0);
- CHECK(utilTrans.verifyIndex(pNdb, idxName, parallelism) == 0);
- ndbout << " pkDelRecords half" << endl;
- CHECK(hugoTrans.pkDelRecords(pNdb, records/2, batchSize) == 0);
- CHECK(utilTrans.verifyIndex(pNdb, idxName, parallelism) == 0);
- ndbout << " scanUpdateRecords" << endl;
- CHECK(hugoTrans.scanUpdateRecords(pNdb, records/2, parallelism) == 0);
- CHECK(utilTrans.verifyIndex(pNdb, idxName, parallelism) == 0);
- ndbout << " clearTable" << endl;
- CHECK(utilTrans.clearTable(pNdb, records/2, parallelism) == 0);
- CHECK(utilTrans.verifyIndex(pNdb, idxName, parallelism) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == 0);
- ndbout << " loadTable" << endl;
- CHECK(hugoTrans.loadTable(pNdb, records, batchSize) == 0);
- CHECK(utilTrans.verifyIndex(pNdb, idxName, parallelism) == 0);
- ndbout << " loadTable again" << endl;
- CHECK(hugoTrans.loadTable(pNdb, records, batchSize) == 0);
- CHECK(utilTrans.verifyIndex(pNdb, idxName, parallelism) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == records);
-
-
- if ((l % 2) == 0){
- // Drop index first and then clear
-
- // Try to create index
- if (drop_index(i, pNdb, pTab, attrList.attriblist[i]) != NDBT_OK){
- result = NDBT_FAILED;
- }
-
- // Clear table
- ndbout << "Clearing table after" << endl;
- CHECK(hugoTrans.clearTable(pNdb, records, parallelism) == 0);
-
-
- } else {
- // Clear table then drop index
-
- //Clear table
- ndbout << "Clearing table before" << endl;
- CHECK(hugoTrans.clearTable(pNdb, records, parallelism) == 0);
-
- // Try to drop index
- if (drop_index(i, pNdb, pTab, attrList.attriblist[i]) != NDBT_OK)
- result = NDBT_FAILED;
- }
-
- ndbout << " Done!" << endl;
- l++;
- }
-
- // Make sure index is dropped
- drop_index(i, pNdb, pTab, attrList.attriblist[i]);
-
- }
-
- return result;
-}
-
-int runInsertDelete(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- const NdbDictionary::Table* pTab = ctx->getTab();
- Ndb* pNdb = GETNDB(step);
- int result = NDBT_OK;
- int batchSize = ctx->getProperty("BatchSize", 1);
- int parallelism = batchSize > 240? 240: batchSize;
- ndbout << "batchSize="<<batchSize<<endl;
- bool logged = ctx->getProperty("LoggedIndexes", 1);
-
- HugoTransactions hugoTrans(*pTab);
- UtilTransactions utilTrans(*pTab);
-
- AttribList attrList;
- attrList.buildAttribList(pTab);
-
- for (unsigned int i = 0; i < attrList.attriblist.size(); i++){
-
- Attrib* attr = attrList.attriblist[i];
- // Create index
- if (create_index(ctx, i, pTab, pNdb, attr, logged) == NDBT_OK){
- int l = 1;
- while (l <= loops && result == NDBT_OK){
-
- CHECK(hugoTrans.loadTable(pNdb, records, batchSize) == 0);
- CHECK(utilTrans.verifyIndex(pNdb, idxName, parallelism) == 0);
- CHECK(utilTrans.clearTable(pNdb, records, parallelism) == 0);
- CHECK(utilTrans.verifyIndex(pNdb, idxName, parallelism) == 0);
- l++;
- }
-
- // Drop index
- if (drop_index(i, pNdb, pTab, attr) != NDBT_OK)
- result = NDBT_FAILED;
- }
- }
-
- return result;
-}
-int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
-
- HugoTransactions hugoTrans(*ctx->getTab());
- int batchSize = ctx->getProperty("BatchSize", 1);
- if(hugoTrans.loadTable(GETNDB(step), records, batchSize) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-
-int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
-
- UtilTransactions utilTrans(*ctx->getTab());
- if (utilTrans.clearTable(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runSystemRestart1(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- int result = NDBT_OK;
- int timeout = 300;
- Uint32 loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int count;
- NdbRestarter restarter;
- Uint32 i = 1;
-
- UtilTransactions utilTrans(*ctx->getTab());
- HugoTransactions hugoTrans(*ctx->getTab());
- const char * name = ctx->getTab()->getName();
- while(i<=loops && result != NDBT_FAILED){
-
- ndbout << "Loop " << i << "/"<< loops <<" started" << endl;
- /*
- 1. Load data
- 2. Restart cluster and verify records
- 3. Update records
- 4. Restart cluster and verify records
- 5. Delete half of the records
- 6. Restart cluster and verify records
- 7. Delete all records
- 8. Restart cluster and verify records
- 9. Insert, update, delete records
- 10. Restart cluster and verify records
- 11. Insert, update, delete records
- 12. Restart cluster with error insert 5020 and verify records
- */
- ndbout << "Loading records..." << endl;
- CHECK(hugoTrans.loadTable(pNdb, records, 1) == 0);
- CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
-
- ndbout << "Restarting cluster" << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- ndbout << "Verifying records..." << endl;
- CHECK(hugoTrans.pkReadRecords(pNdb, records) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == records);
- CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
-
- ndbout << "Updating records..." << endl;
- CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
- CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
-
- ndbout << "Restarting cluster..." << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- ndbout << "Verifying records..." << endl;
- CHECK(hugoTrans.pkReadRecords(pNdb, records) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == records);
- CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
-
- ndbout << "Deleting 50% of records..." << endl;
- CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);
- CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
-
- ndbout << "Restarting cluster..." << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- ndbout << "Verifying records..." << endl;
- CHECK(hugoTrans.scanReadRecords(pNdb, records/2, 0, 64) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == (records/2));
- CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
-
- ndbout << "Deleting all records..." << endl;
- CHECK(utilTrans.clearTable(pNdb, records/2) == 0);
- CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
-
- ndbout << "Restarting cluster..." << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- ndbout << "Verifying records..." << endl;
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == 0);
- CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
-
- ndbout << "Doing it all..." << endl;
- CHECK(hugoTrans.loadTable(pNdb, records, 1) == 0);
- CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
- CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
- CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
- CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);
- CHECK(hugoTrans.scanUpdateRecords(pNdb, records/2) == 0);
- CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
- CHECK(utilTrans.clearTable(pNdb, records) == 0);
- CHECK(hugoTrans.loadTable(pNdb, records, 1) == 0);
- CHECK(utilTrans.clearTable(pNdb, records) == 0);
- CHECK(hugoTrans.loadTable(pNdb, records, 1) == 0);
- CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
- CHECK(utilTrans.clearTable(pNdb, records) == 0);
-
- ndbout << "Restarting cluster..." << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- ndbout << "Verifying records..." << endl;
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == 0);
-
- ndbout << "Doing it all..." << endl;
- CHECK(hugoTrans.loadTable(pNdb, records, 1) == 0);
- CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
- CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
- CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
- CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);
- CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
- CHECK(hugoTrans.scanUpdateRecords(pNdb, records/2) == 0);
- CHECK(utilTrans.verifyIndex(pNdb, idxName, 16, false) == 0);
- CHECK(utilTrans.clearTable(pNdb, records) == 0);
- CHECK(hugoTrans.loadTable(pNdb, records, 1) == 0);
- CHECK(utilTrans.clearTable(pNdb, records) == 0);
-
- ndbout << "Restarting cluster with error insert 5020..." << endl;
- CHECK(restarter.restartAll(false, true) == 0);
- CHECK(restarter.waitClusterNoStart(timeout) == 0);
- CHECK(restarter.insertErrorInAllNodes(5020) == 0);
- CHECK(restarter.startAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- i++;
- }
-
- ctx->stopTest();
- ndbout << "runSystemRestart1 finished" << endl;
-
- return result;
-}
-
-#define CHECK2(b, t) if(!b){ g_err << __LINE__ << ": " << t << endl; break;}
-
-int
-runMixed1(NDBT_Context* ctx, NDBT_Step* step){
- // Verify that data in index match
- // table data
- Ndb* pNdb = GETNDB(step);
- HugoOperations hugoOps(*ctx->getTab());
-
-
- do {
- // TC1
- g_err << "pkRead, indexRead, Commit" << endl;
- CHECK2(hugoOps.startTransaction(pNdb) == 0, "startTransaction");
- CHECK2(hugoOps.indexReadRecords(pNdb, pkIdxName, 0) == 0, "indexReadRecords");
- CHECK2(hugoOps.pkReadRecord(pNdb, 0) == 0, "pkReadRecord");
- CHECK2(hugoOps.execute_Commit(pNdb) == 0, "executeCommit");
- CHECK2(hugoOps.closeTransaction(pNdb) == 0, "closeTransaction");
-
- // TC1
- g_err << "pkRead, indexRead, Commit" << endl;
- CHECK2(hugoOps.startTransaction(pNdb) == 0, "startTransaction");
- CHECK2(hugoOps.pkReadRecord(pNdb, 0) == 0, "pkReadRecord");
- CHECK2(hugoOps.indexReadRecords(pNdb, pkIdxName, 0) == 0, "indexReadRecords");
- CHECK2(hugoOps.execute_Commit(pNdb) == 0, "executeCommit");
- CHECK2(hugoOps.closeTransaction(pNdb) == 0, "closeTransaction");
-
-
- // TC2
- g_err << "pkRead, indexRead, NoCommit, Commit" << endl;
- CHECK2(hugoOps.startTransaction(pNdb) == 0, "startTransaction");
- CHECK2(hugoOps.pkReadRecord(pNdb, 0) == 0, "pkReadRecord");
- CHECK2(hugoOps.indexReadRecords(pNdb, pkIdxName, 0) == 0,
- "indexReadRecords");
- CHECK2(hugoOps.execute_NoCommit(pNdb) == 0, "executeNoCommit");
- CHECK2(hugoOps.execute_Commit(pNdb) == 0, "executeCommit");
- CHECK2(hugoOps.closeTransaction(pNdb) == 0, "closeTransaction");
-
- // TC3
- g_err << "pkRead, pkRead, Commit" << endl;
- CHECK2(hugoOps.startTransaction(pNdb) == 0, "startTransaction ");
- CHECK2(hugoOps.pkReadRecord(pNdb, 0) == 0, "pkReadRecords ");
- CHECK2(hugoOps.pkReadRecord(pNdb, 0) == 0, "pkReadRecords ");
- CHECK2(hugoOps.execute_Commit(pNdb) == 0, "executeCommit");
- CHECK2(hugoOps.closeTransaction(pNdb) == 0, "closeTransaction ");
-
- // TC4
- g_err << "indexRead, indexRead, Commit" << endl;
-
- CHECK2(hugoOps.startTransaction(pNdb) == 0, "startTransaction ");
- CHECK2(hugoOps.indexReadRecords(pNdb, pkIdxName, 0) == 0, "indexReadRecords");
- CHECK2(hugoOps.indexReadRecords(pNdb, pkIdxName, 0) == 0, "indexReadRecords");
- CHECK2(hugoOps.execute_Commit(pNdb) == 0, "executeCommit");
-
- CHECK2(hugoOps.closeTransaction(pNdb) == 0, "closeTransaction ");
-
- return NDBT_OK;
- } while(false);
-
-
- hugoOps.closeTransaction(pNdb);
- return NDBT_FAILED;
-}
-
-int
-runBuildDuring(NDBT_Context* ctx, NDBT_Step* step){
- // Verify that data in index match
- // table data
- const int Threads = ctx->getProperty("Threads", (Uint32)0);
- const int loops = ctx->getNumLoops();
-
- for(int i = 0; i<loops; i++){
-#if 1
- if(createPkIndex(ctx, step) != NDBT_OK){
- g_err << "Failed to create index" << endl;
- return NDBT_FAILED;
- }
-#endif
-
- if(ctx->isTestStopped())
- break;
-
-#if 1
- if(createRandomIndex(ctx, step) != NDBT_OK){
- g_err << "Failed to create index" << endl;
- return NDBT_FAILED;
- }
-#endif
-
- if(ctx->isTestStopped())
- break;
-
- ctx->setProperty("pause", 1);
- int count = 0;
- for(int j = 0; count < Threads && !ctx->isTestStopped();
- j = (j+1) % Threads){
- char buf[255];
- sprintf(buf, "Thread%d_paused", j);
- int tmp = ctx->getProperty(buf, (Uint32)0);
- count += tmp;
- }
-
- if(ctx->isTestStopped())
- break;
-
-#if 1
- if(createPkIndex_Drop(ctx, step) != NDBT_OK){
- g_err << "Failed to drop index" << endl;
- return NDBT_FAILED;
- }
-#endif
-
- if(ctx->isTestStopped())
- break;
-
-#if 1
- if(createRandomIndex_Drop(ctx, step) != NDBT_OK){
- g_err << "Failed to drop index" << endl;
- return NDBT_FAILED;
- }
-#endif
-
- ctx->setProperty("pause", (Uint32)0);
- NdbSleep_SecSleep(2);
- }
-
- ctx->stopTest();
- return NDBT_OK;
-}
-
-static NdbLockable g_lock;
-static int threadCounter = 0;
-
-void
-wait_paused(NDBT_Context* ctx, int id){
- if(ctx->getProperty("pause", (Uint32)0) == 1){
- char buf[255];
- sprintf(buf, "Thread%d_paused", id);
- ctx->setProperty(buf, 1);
- while(!ctx->isTestStopped() && ctx->getProperty("pause", (Uint32)0) == 1){
- NdbSleep_MilliSleep(250);
- }
- ctx->setProperty(buf, (Uint32)0);
- }
-}
-
-int
-runTransactions4(NDBT_Context* ctx, NDBT_Step* step){
-
- g_lock.lock();
- const int ThreadId = threadCounter++;
- g_lock.unlock();
-
- // Verify that data in index match
- // table data
- Ndb* pNdb = GETNDB(step);
- HugoTransactions hugoTrans(*ctx->getTab());
- UtilTransactions utilTrans(*ctx->getTab());
- const int batchSize = ctx->getProperty("BatchSize", 32);
- const int parallel = batchSize > 240 ? 240 : batchSize;
-
- int rows = ctx->getNumRecords();
- while (ctx->isTestStopped() == false) {
- if(hugoTrans.loadTable(pNdb, rows, batchSize, false) != 0){
- g_err << "Load table failed" << endl;
- return NDBT_FAILED;
- }
-
- wait_paused(ctx, ThreadId);
-
- if(ctx->isTestStopped())
- break;
-
- if (hugoTrans.pkUpdateRecords(pNdb, rows, batchSize) != 0){
- g_err << "Updated table failed" << endl;
- return NDBT_FAILED;
- }
-
- wait_paused(ctx, ThreadId);
-
- if(ctx->isTestStopped())
- break;
-
- if (hugoTrans.scanUpdateRecords(pNdb, rows, 5, parallel) != 0){
- g_err << "Scan updated table failed" << endl;
- return NDBT_FAILED;
- }
-
- wait_paused(ctx, ThreadId);
-
- if(ctx->isTestStopped())
- break;
-
- if(utilTrans.clearTable(pNdb, rows, parallel) != 0){
- g_err << "Clear table failed" << endl;
- return NDBT_FAILED;
- }
- }
- return NDBT_OK;
-}
-
-int
-runUniqueNullTransactions(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
-
- bool logged = ctx->getProperty("LoggedIndexes", 1);
- bool orderedIndex = ctx->getProperty("OrderedIndex", (unsigned)0);
- NdbConnection * pTrans = 0;
-
- const NdbDictionary::Table* pTab = ctx->getTab();
- // Create index
- char nullIndex[255];
- BaseString::snprintf(nullIndex, 255, "IDC_PK_%s_NULL", pTab->getName());
- if (orderedIndex)
- ndbout << "Creating " << ((logged)?"logged ": "temporary ") << "ordered index "
- << pkIdxName << " (";
- else
- ndbout << "Creating " << ((logged)?"logged ": "temporary ") << "unique index "
- << pkIdxName << " (";
-
- NdbDictionary::Index pIdx(pkIdxName);
- pIdx.setTable(pTab->getName());
- if (orderedIndex)
- pIdx.setType(NdbDictionary::Index::OrderedIndex);
- else
- pIdx.setType(NdbDictionary::Index::UniqueHashIndex);
- pIdx.setStoredIndex(logged);
- int c;
- for (c = 0; c< pTab->getNoOfColumns(); c++){
- const NdbDictionary::Column * col = pTab->getColumn(c);
- if(col->getPrimaryKey()){
- pIdx.addIndexColumn(col->getName());
- ndbout << col->getName() <<" ";
- }
- }
-
- int colId = -1;
- for (c = 0; c< pTab->getNoOfColumns(); c++){
- const NdbDictionary::Column * col = pTab->getColumn(c);
- if(col->getNullable()){
- pIdx.addIndexColumn(col->getName());
- ndbout << col->getName() <<" ";
- colId = c;
- break;
- }
- }
- ndbout << ") ";
-
- if(colId == -1){
- ndbout << endl << "No nullable column found -> NDBT_FAILED" << endl;
- return NDBT_FAILED;
- }
-
- if (pNdb->getDictionary()->createIndex(pIdx) != 0){
- ndbout << "FAILED!" << endl;
- const NdbError err = pNdb->getDictionary()->getNdbError();
- ERR(err);
- return NDBT_FAILED;
- }
-
- int result = NDBT_OK;
-
- HugoTransactions hugoTrans(*ctx->getTab());
- const int batchSize = ctx->getProperty("BatchSize", 50);
- int loops = ctx->getNumLoops();
- int rows = ctx->getNumRecords();
- while (loops-- > 0 && ctx->isTestStopped() == false) {
- if (hugoTrans.pkUpdateRecords(pNdb, rows, batchSize) != 0){
- g_err << "Updated table failed" << endl;
- result = NDBT_FAILED;
- goto done;
- }
- }
-
- if(ctx->isTestStopped()){
- goto done;
- }
-
- ctx->stopTest();
- while(ctx->getNoOfRunningSteps() > 1){
- NdbSleep_MilliSleep(100);
- }
-
- result = NDBT_FAILED;
- pTrans = pNdb->startTransaction();
- NdbScanOperation * sOp;
- NdbOperation * uOp;
- int eof;
- if(!pTrans) goto done;
- sOp = pTrans->getNdbScanOperation(pTab->getName());
- if(!sOp) goto done;
- if(sOp->readTuples(NdbScanOperation::LM_Exclusive)) goto done;
- if(pTrans->execute(NoCommit) == -1) goto done;
- while((eof = sOp->nextResult(true)) == 0){
- do {
- NdbOperation * uOp = sOp->updateCurrentTuple();
- if(uOp == 0) goto done;
- uOp->setValue(colId, 0);
- } while((eof = sOp->nextResult(false)) == 0);
- eof = pTrans->execute(Commit);
- if(eof == -1) goto done;
- }
-
- done:
- if(pTrans) pNdb->closeTransaction(pTrans);
- pNdb->getDictionary()->dropIndex(nullIndex, pTab->getName());
- return result;
-}
-
-int runLQHKEYREF(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops() * 100;
- NdbRestarter restarter;
-
- myRandom48Init(NdbTick_CurrentMillisecond());
-
-#if 0
- int val = DumpStateOrd::DihMinTimeBetweenLCP;
- if(restarter.dumpStateAllNodes(&val, 1) != 0){
- g_err << "Failed to dump DihMinTimeBetweenLCP" << endl;
- return NDBT_FAILED;
- }
-#endif
-
- for(int i = 0; i<loops && !ctx->isTestStopped(); i++){
- int randomId = myRandom48(restarter.getNumDbNodes());
- int nodeId = restarter.getDbNodeId(randomId);
-
- const Uint32 error = 5031 + (i % 3);
-
- if(restarter.insertErrorInNode(nodeId, error) != 0){
- g_err << "Failed to error insert( " << error << ") in node "
- << nodeId << endl;
- return NDBT_FAILED;
- }
- }
-
- ctx->stopTest();
- return NDBT_OK;
-}
-
-int
-runBug21384(NDBT_Context* ctx, NDBT_Step* step)
-{
- Ndb* pNdb = GETNDB(step);
- HugoTransactions hugoTrans(*ctx->getTab());
- NdbRestarter restarter;
-
- int loops = ctx->getNumLoops();
- const int rows = ctx->getNumRecords();
- const int batchsize = ctx->getProperty("BatchSize", 50);
-
- while (loops--)
- {
- if(restarter.insertErrorInAllNodes(8037) != 0)
- {
- g_err << "Failed to error insert(8037)" << endl;
- return NDBT_FAILED;
- }
-
- if (hugoTrans.indexReadRecords(pNdb, pkIdxName, rows, batchsize) == 0)
- {
- g_err << "Index succeded (it should have failed" << endl;
- return NDBT_FAILED;
- }
-
- if(restarter.insertErrorInAllNodes(0) != 0)
- {
- g_err << "Failed to error insert(0)" << endl;
- return NDBT_FAILED;
- }
-
- if (hugoTrans.indexReadRecords(pNdb, pkIdxName, rows, batchsize) != 0){
- g_err << "Index read failed" << endl;
- return NDBT_FAILED;
- }
- }
-
- return NDBT_OK;
-}
-
-int
-runBug25059(NDBT_Context* ctx, NDBT_Step* step)
-{
- Ndb* pNdb = GETNDB(step);
- NdbDictionary::Dictionary * dict = pNdb->getDictionary();
- const NdbDictionary::Index * idx = dict->getIndex(pkIdxName,
- ctx->getTab()->getName());
-
- HugoOperations ops(*ctx->getTab(), idx);
-
- int res = NDBT_OK;
- int loops = ctx->getNumLoops();
- const int rows = ctx->getNumRecords();
-
- while (res == NDBT_OK && loops--)
- {
- ops.startTransaction(pNdb);
- ops.pkReadRecord(pNdb, 10 + rand() % rows, rows);
- int tmp;
- if (tmp = ops.execute_Commit(pNdb, AO_IgnoreError))
- {
- if (tmp == 4012)
- res = NDBT_FAILED;
- else
- if (ops.getTransaction()->getNdbError().code == 4012)
- res = NDBT_FAILED;
- }
- ops.closeTransaction(pNdb);
- }
-
- loops = ctx->getNumLoops();
- while (res == NDBT_OK && loops--)
- {
- ops.startTransaction(pNdb);
- ops.pkUpdateRecord(pNdb, 10 + rand() % rows, rows);
- int tmp;
- int arg;
- switch(rand() % 2){
- case 0:
- arg = AbortOnError;
- break;
- case 1:
- arg = AO_IgnoreError;
- ndbout_c("ignore error");
- break;
- }
- if (tmp = ops.execute_Commit(pNdb, (AbortOption)arg))
- {
- if (tmp == 4012)
- res = NDBT_FAILED;
- else
- if (ops.getTransaction()->getNdbError().code == 4012)
- res = NDBT_FAILED;
- }
- ops.closeTransaction(pNdb);
- }
-
- return res;
-}
-
-int tcSaveINDX_test(NDBT_Context* ctx, NDBT_Step* step, int inject_err)
-{
- int result= NDBT_OK;
- Ndb* pNdb = GETNDB(step);
- NdbDictionary::Dictionary * dict = pNdb->getDictionary();
- const NdbDictionary::Index * idx = dict->getIndex(pkIdxName,
- ctx->getTab()->getName());
-
- HugoOperations ops(*ctx->getTab(), idx);
-
- g_err << "Using INDEX: " << pkIdxName << endl;
-
- NdbRestarter restarter;
-
- int loops = ctx->getNumLoops();
- const int rows = ctx->getNumRecords();
- const int batchsize = ctx->getProperty("BatchSize", 1);
-
- for(int bs=1; bs < loops; bs++)
- {
- int c= 0;
- while (c++ < loops)
- {
- g_err << "BS " << bs << " LOOP #" << c << endl;
-
- g_err << "inserting error on op#" << c << endl;
-
- CHECK(ops.startTransaction(pNdb) == 0);
- for(int i=1;i<=c;i++)
- {
- if(i==c)
- {
- if(restarter.insertErrorInAllNodes(inject_err)!=0)
- {
- g_err << "**** FAILED to insert error" << endl;
- result= NDBT_FAILED;
- break;
- }
- }
- CHECK(ops.indexReadRecords(pNdb, pkIdxName, i,false,1) == 0);
- if(i%bs==0 || i==c)
- {
- if(i<c)
- {
- if(ops.execute_NoCommit(pNdb, AO_IgnoreError)!=NDBT_OK)
- {
- g_err << "**** executeNoCommit should have succeeded" << endl;
- result= NDBT_FAILED;
- }
- }
- else
- {
- if(ops.execute_NoCommit(pNdb, AO_IgnoreError)!=289)
- {
- g_err << "**** executeNoCommit should have failed with 289"
- << endl;
- result= NDBT_FAILED;
- }
- g_err << "NdbError.code= " <<
- ops.getTransaction()->getNdbError().code << endl;
- break;
- }
- }
- }
-
- CHECK(ops.closeTransaction(pNdb) == 0);
-
- if(restarter.insertErrorInAllNodes(0) != 0)
- {
- g_err << "**** Failed to error insert(0)" << endl;
- return NDBT_FAILED;
- }
-
- CHECK(ops.startTransaction(pNdb) == 0);
- if (ops.indexReadRecords(pNdb, pkIdxName,0,0,rows) != 0){
- g_err << "**** Index read failed" << endl;
- return NDBT_FAILED;
- }
- CHECK(ops.closeTransaction(pNdb) == 0);
- }
- }
-
- return result;
-}
-
-int
-runBug28804(NDBT_Context* ctx, NDBT_Step* step)
-{
- return tcSaveINDX_test(ctx, step, 8052);
-}
-
-int
-runBug28804_ATTRINFO(NDBT_Context* ctx, NDBT_Step* step)
-{
- return tcSaveINDX_test(ctx, step, 8051);
-}
-
-NDBT_TESTSUITE(testIndex);
-TESTCASE("CreateAll",
- "Test that we can create all various indexes on each table\n"
- "Then drop the indexes\n"){
- INITIALIZER(runCreateIndexes);
-}
-TESTCASE("CreateAll_O",
- "Test that we can create all various indexes on each table\n"
- "Then drop the indexes\n"){
- TC_PROPERTY("OrderedIndex", 1);
- TC_PROPERTY("LoggedIndexes", (unsigned)0);
- INITIALIZER(runCreateIndexes);
-}
-TESTCASE("InsertDeleteGentle",
- "Create one index, then perform insert and delete in the table\n"
- "loop number of times. Use batch size 1."){
- TC_PROPERTY("BatchSize", 1);
- INITIALIZER(runInsertDelete);
- FINALIZER(runClearTable);
-}
-TESTCASE("InsertDeleteGentle_O",
- "Create one index, then perform insert and delete in the table\n"
- "loop number of times. Use batch size 1."){
- TC_PROPERTY("OrderedIndex", 1);
- TC_PROPERTY("LoggedIndexes", (unsigned)0);
- TC_PROPERTY("BatchSize", 1);
- INITIALIZER(runInsertDelete);
- FINALIZER(runClearTable);
-}
-TESTCASE("InsertDelete",
- "Create one index, then perform insert and delete in the table\n"
- "loop number of times. Use batchsize 512 to stress db more"){
- TC_PROPERTY("BatchSize", 512);
- INITIALIZER(runInsertDelete);
- FINALIZER(runClearTable);
-
-}
-TESTCASE("InsertDelete_O",
- "Create one index, then perform insert and delete in the table\n"
- "loop number of times. Use batchsize 512 to stress db more"){
- TC_PROPERTY("OrderedIndex", 1);
- TC_PROPERTY("LoggedIndexes", (unsigned)0);
- TC_PROPERTY("BatchSize", 512);
- INITIALIZER(runInsertDelete);
- FINALIZER(runClearTable);
-
-}
-TESTCASE("CreateLoadDropGentle",
- "Try to create, drop and load various indexes \n"
- "on table loop number of times.Usa batch size 1.\n"){
- TC_PROPERTY("BatchSize", 1);
- INITIALIZER(runCreateLoadDropIndex);
-}
-TESTCASE("CreateLoadDropGentle_O",
- "Try to create, drop and load various indexes \n"
- "on table loop number of times.Usa batch size 1.\n"){
- TC_PROPERTY("OrderedIndex", 1);
- TC_PROPERTY("LoggedIndexes", (unsigned)0);
- TC_PROPERTY("BatchSize", 1);
- INITIALIZER(runCreateLoadDropIndex);
-}
-TESTCASE("CreateLoadDrop",
- "Try to create, drop and load various indexes \n"
- "on table loop number of times. Use batchsize 512 to stress db more\n"){
- TC_PROPERTY("BatchSize", 512);
- INITIALIZER(runCreateLoadDropIndex);
-}
-TESTCASE("CreateLoadDrop_O",
- "Try to create, drop and load various indexes \n"
- "on table loop number of times. Use batchsize 512 to stress db more\n"){
- TC_PROPERTY("OrderedIndex", 1);
- TC_PROPERTY("LoggedIndexes", (unsigned)0);
- TC_PROPERTY("BatchSize", 512);
- INITIALIZER(runCreateLoadDropIndex);
-}
-TESTCASE("NFNR1",
- "Test that indexes are correctly maintained during node fail and node restart"){
- TC_PROPERTY("LoggedIndexes", (unsigned)0);
- TC_PROPERTY("PauseThreads", 2);
- INITIALIZER(runClearTable);
- INITIALIZER(createRandomIndex);
- INITIALIZER(runLoadTable);
- STEP(runRestarts);
- STEP(runTransactions1);
- STEP(runTransactions1);
- FINALIZER(runVerifyIndex);
- FINALIZER(createRandomIndex_Drop);
- FINALIZER(runClearTable);
-}
-TESTCASE("NFNR1_O",
- "Test that indexes are correctly maintained during node fail and node restart"){
- TC_PROPERTY("OrderedIndex", 1);
- TC_PROPERTY("LoggedIndexes", (unsigned)0);
- TC_PROPERTY("PauseThreads", 2);
- INITIALIZER(runClearTable);
- INITIALIZER(createRandomIndex);
- INITIALIZER(runLoadTable);
- STEP(runRestarts);
- STEP(runTransactions1);
- STEP(runTransactions1);
- FINALIZER(runVerifyIndex);
- FINALIZER(createRandomIndex_Drop);
- FINALIZER(runClearTable);
-}
-TESTCASE("NFNR2",
- "Test that indexes are correctly maintained during node fail and node restart"){
- TC_PROPERTY("LoggedIndexes", (unsigned)0);
- TC_PROPERTY("PauseThreads", 2);
- INITIALIZER(runClearTable);
- INITIALIZER(createRandomIndex);
- INITIALIZER(createPkIndex);
- INITIALIZER(runLoadTable);
- STEP(runRestarts);
- STEP(runTransactions2);
- STEP(runTransactions2);
- FINALIZER(runVerifyIndex);
- FINALIZER(createRandomIndex_Drop);
- FINALIZER(createPkIndex_Drop);
- FINALIZER(runClearTable);
-}
-TESTCASE("NFNR2_O",
- "Test that indexes are correctly maintained during node fail and node restart"){
- TC_PROPERTY("OrderedIndex", 1);
- TC_PROPERTY("LoggedIndexes", (unsigned)0);
- TC_PROPERTY("PauseThreads", 1);
- INITIALIZER(runClearTable);
- INITIALIZER(createRandomIndex);
- INITIALIZER(createPkIndex);
- INITIALIZER(runLoadTable);
- STEP(runRestarts);
- STEP(runTransactions2);
- //STEP(runTransactions2);
- FINALIZER(runVerifyIndex);
- FINALIZER(createRandomIndex_Drop);
- FINALIZER(createPkIndex_Drop);
- FINALIZER(runClearTable);
-}
-TESTCASE("NFNR3",
- "Test that indexes are correctly maintained during node fail and node restart"){
- TC_PROPERTY("LoggedIndexes", (unsigned)0);
- TC_PROPERTY("PauseThreads", 2);
- INITIALIZER(runClearTable);
- INITIALIZER(createRandomIndex);
- INITIALIZER(createPkIndex);
- STEP(runRestarts);
- STEP(runTransactions3);
- STEP(runVerifyIndex);
- FINALIZER(runVerifyIndex);
- FINALIZER(createPkIndex_Drop);
- FINALIZER(createRandomIndex_Drop);
- FINALIZER(runClearTable);
-}
-TESTCASE("NFNR3_O",
- "Test that indexes are correctly maintained during node fail and node restart"){
- TC_PROPERTY("OrderedIndex", 1);
- TC_PROPERTY("LoggedIndexes", (unsigned)0);
- TC_PROPERTY("PauseThreads", 2);
- INITIALIZER(runClearTable);
- INITIALIZER(createRandomIndex);
- INITIALIZER(createPkIndex);
- STEP(runRestarts);
- STEP(runTransactions3);
- STEP(runVerifyIndex);
- FINALIZER(runVerifyIndex);
- FINALIZER(createPkIndex_Drop);
- FINALIZER(createRandomIndex_Drop);
- FINALIZER(runClearTable);
-}
-TESTCASE("NFNR4",
- "Test that indexes are correctly maintained during node fail and node restart"){
- TC_PROPERTY("LoggedIndexes", (unsigned)0);
- TC_PROPERTY("PauseThreads", 4);
- INITIALIZER(runClearTable);
- INITIALIZER(createRandomIndex);
- INITIALIZER(createPkIndex);
- INITIALIZER(runLoadTable);
- STEP(runRestarts);
- STEP(runTransactions1);
- STEP(runTransactions1);
- STEP(runTransactions2);
- STEP(runTransactions2);
- FINALIZER(runVerifyIndex);
- FINALIZER(createRandomIndex_Drop);
- FINALIZER(createPkIndex_Drop);
- FINALIZER(runClearTable);
-}
-TESTCASE("NFNR4_O",
- "Test that indexes are correctly maintained during node fail and node restart"){
- TC_PROPERTY("OrderedIndex", 1);
- TC_PROPERTY("LoggedIndexes", (unsigned)0);
- TC_PROPERTY("PauseThreads", 4);
- INITIALIZER(runClearTable);
- INITIALIZER(createRandomIndex);
- INITIALIZER(createPkIndex);
- INITIALIZER(runLoadTable);
- STEP(runRestarts);
- STEP(runTransactions1);
- STEP(runTransactions1);
- STEP(runTransactions2);
- STEP(runTransactions2);
- FINALIZER(runVerifyIndex);
- FINALIZER(createRandomIndex_Drop);
- FINALIZER(createPkIndex_Drop);
- FINALIZER(runClearTable);
-}
-TESTCASE("NFNR5",
- "Test that indexes are correctly maintained during node fail and node restart"){
- TC_PROPERTY("LoggedIndexes", (unsigned)0);
- TC_PROPERTY("BatchSize", (unsigned)1);
- INITIALIZER(runClearTable);
- INITIALIZER(createRandomIndex);
- INITIALIZER(createPkIndex);
- INITIALIZER(runLoadTable);
- STEP(runLQHKEYREF);
- STEP(runTransactions1);
- STEP(runTransactions1);
- STEP(runTransactions2);
- STEP(runTransactions2);
- FINALIZER(runVerifyIndex);
- FINALIZER(createRandomIndex_Drop);
- FINALIZER(createPkIndex_Drop);
- FINALIZER(runClearTable);
-}
-TESTCASE("NFNR5_O",
- "Test that indexes are correctly maintained during node fail and node restart"){
- TC_PROPERTY("OrderedIndex", 1);
- TC_PROPERTY("LoggedIndexes", (unsigned)0);
- TC_PROPERTY("BatchSize", (unsigned)1);
- INITIALIZER(runClearTable);
- INITIALIZER(createRandomIndex);
- INITIALIZER(createPkIndex);
- INITIALIZER(runLoadTable);
- STEP(runLQHKEYREF);
- STEP(runTransactions1);
- STEP(runTransactions1);
- STEP(runTransactions2);
- STEP(runTransactions2);
- FINALIZER(runVerifyIndex);
- FINALIZER(createRandomIndex_Drop);
- FINALIZER(createPkIndex_Drop);
- FINALIZER(runClearTable);
-}
-TESTCASE("SR1",
- "Test that indexes are correctly maintained during SR"){
- INITIALIZER(runClearTable);
- INITIALIZER(createRandomIndex);
- INITIALIZER(createPkIndex);
- STEP(runSystemRestart1);
- FINALIZER(runVerifyIndex);
- FINALIZER(createPkIndex_Drop);
- FINALIZER(createRandomIndex_Drop);
- FINALIZER(runClearTable);
-}
-TESTCASE("MixedTransaction",
- "Test mixing of index and normal operations"){
- TC_PROPERTY("LoggedIndexes", (unsigned)0);
- INITIALIZER(runClearTable);
- INITIALIZER(createPkIndex);
- INITIALIZER(runLoadTable);
- STEP(runMixed1);
- FINALIZER(createPkIndex_Drop);
- FINALIZER(runClearTable);
-}
-TESTCASE("SR1_O",
- "Test that indexes are correctly maintained during SR"){
- TC_PROPERTY("OrderedIndex", 1);
- TC_PROPERTY("LoggedIndexes", (unsigned)0);
- INITIALIZER(runClearTable);
- INITIALIZER(createRandomIndex);
- INITIALIZER(createPkIndex);
- STEP(runSystemRestart1);
- FINALIZER(runVerifyIndex);
- FINALIZER(createPkIndex_Drop);
- FINALIZER(createRandomIndex_Drop);
- FINALIZER(runClearTable);
-}
-TESTCASE("BuildDuring",
- "Test that index build when running transactions work"){
- TC_PROPERTY("OrderedIndex", (unsigned)0);
- TC_PROPERTY("LoggedIndexes", (unsigned)0);
- TC_PROPERTY("Threads", 1); // # runTransactions4
- INITIALIZER(runClearTable);
- STEP(runBuildDuring);
- STEP(runTransactions4);
- //STEP(runTransactions4);
- FINALIZER(runClearTable);
-}
-TESTCASE("BuildDuring_O",
- "Test that index build when running transactions work"){
- TC_PROPERTY("OrderedIndex", (unsigned)1);
- TC_PROPERTY("LoggedIndexes", (unsigned)0);
- TC_PROPERTY("Threads", 1); // # runTransactions4
- INITIALIZER(runClearTable);
- STEP(runBuildDuring);
- STEP(runTransactions4);
- //STEP(runTransactions4);
- FINALIZER(runClearTable);
-}
-TESTCASE("UniqueNull",
- "Test that unique indexes and nulls"){
- TC_PROPERTY("LoggedIndexes", (unsigned)0);
- INITIALIZER(runClearTable);
- INITIALIZER(createRandomIndex);
- INITIALIZER(createPkIndex);
- INITIALIZER(runLoadTable);
- STEP(runTransactions1);
- STEP(runTransactions2);
- STEP(runUniqueNullTransactions);
- FINALIZER(runVerifyIndex);
- FINALIZER(createRandomIndex_Drop);
- FINALIZER(createPkIndex_Drop);
- FINALIZER(runClearTable);
-}
-TESTCASE("Bug21384",
- "Test that unique indexes and nulls"){
- TC_PROPERTY("LoggedIndexes", (unsigned)0);
- INITIALIZER(runClearTable);
- INITIALIZER(createPkIndex);
- INITIALIZER(runLoadTable);
- STEP(runBug21384);
- FINALIZER(createPkIndex_Drop);
- FINALIZER(runClearTable);
-}
-TESTCASE("Bug25059",
- "Test that unique indexes and nulls"){
- TC_PROPERTY("LoggedIndexes", (unsigned)0);
- INITIALIZER(createPkIndex);
- INITIALIZER(runLoadTable);
- STEP(runBug25059);
- FINALIZER(createPkIndex_Drop);
-}
-TESTCASE("Bug28804",
- "Test behaviour on out of TransactionBufferMemory for index lookup"){
- TC_PROPERTY("LoggedIndexes", (unsigned)0);
- INITIALIZER(runClearTable);
- INITIALIZER(createPkIndex);
- INITIALIZER(runLoadTable);
- STEP(runBug28804);
- FINALIZER(createPkIndex_Drop);
- FINALIZER(runClearTable);
-}
-TESTCASE("Bug28804_ATTRINFO",
- "Test behaviour on out of TransactionBufferMemory for index lookup"
- " in saveINDXATTRINFO"){
- TC_PROPERTY("LoggedIndexes", (unsigned)0);
- INITIALIZER(runClearTable);
- INITIALIZER(createPkIndex);
- INITIALIZER(runLoadTable);
- STEP(runBug28804_ATTRINFO);
- FINALIZER(createPkIndex_Drop);
- FINALIZER(runClearTable);
-}
-NDBT_TESTSUITE_END(testIndex);
-
-int main(int argc, const char** argv){
- ndb_init();
- return testIndex.execute(argc, argv);
-}
-
-template class Vector<Attrib*>;
diff --git a/storage/ndb/test/ndbapi/testIndexStat.cpp b/storage/ndb/test/ndbapi/testIndexStat.cpp
deleted file mode 100644
index 4dd110650fe..00000000000
--- a/storage/ndb/test/ndbapi/testIndexStat.cpp
+++ /dev/null
@@ -1,1405 +0,0 @@
-/* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-#include <ndb_opts.h>
-#include <NdbApi.hpp>
-#include <NdbIndexStat.hpp>
-#include <NdbTest.hpp>
-#include <my_sys.h>
-#include <ndb_version.h>
-#include <math.h>
-
-/*
- * Sample results:
- *
- * 0. err pct: count: 1000 min: -99.99 max: 99.92 avg: 6.88 stddev: 27.61
- *
- * 0. baseline with same options as handler
- */
-
-#undef min
-#undef max
-#define min(a, b) ((a) <= (b) ? (a) : (b))
-#define max(a, b) ((a) >= (b) ? (a) : (b))
-
-inline NdbOut&
-NdbOut::operator<<(double x)
-{
- char buf[100];
- sprintf(buf, "%.2f", x);
- *this << buf;
- return *this;
-}
-
-struct Opts {
- int loglevel;
- uint seed;
- uint loop;
- uint rows;
- uint ops;
- uint nullkeys;
- uint dupkeys;
- uint scanpct;
- uint eqscans;
- uint dupscans;
- my_bool keeptable;
- my_bool loaddata;
- my_bool nochecks;
- my_bool abort;
- // internal
- uint tryhard;
- Opts() :
- loglevel(0),
- seed(-1),
- loop(1),
- rows(100000),
- ops(1000),
- nullkeys(10),
- dupkeys(1000),
- scanpct(5),
- eqscans(50),
- dupscans(10),
- keeptable(false),
- loaddata(true),
- nochecks(false),
- abort(false),
- // internal
- tryhard(20)
- {}
-};
-
-static Opts g_opts;
-const char* g_progname = "testIndexStat";
-static uint g_loop = 0;
-
-static const char* g_tabname = "ts0";
-static const char* g_indname = "ts0x1";
-static const char g_numattrs = 3;
-static const uint g_charlen = 10;
-static const char* g_csname = "latin1_swedish_ci";
-static CHARSET_INFO* g_cs;
-
-// value and bound ranges
-static uint g_val_b_max = 10;
-static uint g_bnd_b_max = 20;
-static const char* g_val_c_char = "bcd";
-static const char* g_bnd_c_char = "abcde";
-static uint g_val_d_max = 100;
-static uint g_bnd_d_max = 200;
-
-static Ndb_cluster_connection* g_ncc = 0;
-static Ndb* g_ndb = 0;
-static NdbDictionary::Dictionary* g_dic = 0;
-static const NdbDictionary::Table* g_tab = 0;
-static const NdbDictionary::Index* g_ind = 0;
-
-static NdbIndexStat* g_stat = 0;
-
-static NdbTransaction* g_con = 0;
-static NdbOperation* g_op = 0;
-static NdbScanOperation* g_scan_op = 0;
-static NdbIndexScanOperation* g_rangescan_op = 0;
-
-static uint
-urandom()
-{
- uint r = (uint)random();
- return r;
-}
-
-static uint
-urandom(uint m)
-{
- if (m == 0)
- return 0;
- uint r = urandom();
- r = r % m;
- return r;
-}
-
-static int& g_loglevel = g_opts.loglevel; // default log level
-
-#define chkdb(x) \
- do { if (likely(x)) break; ndbout << "line " << __LINE__ << " FAIL " << #x << endl; errdb(); if (g_opts.abort) abort(); return -1; } while (0)
-
-#define chkrc(x) \
- do { if (likely(x)) break; ndbout << "line " << __LINE__ << " FAIL " << #x << endl; if (g_opts.abort) abort(); return -1; } while (0)
-
-#define reqrc(x) \
- do { if (likely(x)) break; ndbout << "line " << __LINE__ << " ASSERT " << #x << endl; abort(); } while (0)
-
-#define llx(n, x) \
- do { if (likely(g_loglevel < n)) break; ndbout << x << endl; } while (0)
-
-#define ll0(x) llx(0, x)
-#define ll1(x) llx(1, x)
-#define ll2(x) llx(2, x)
-#define ll3(x) llx(3, x)
-
-static void
-errdb()
-{
- uint any = 0;
- // g_ncc return no error...
- if (g_ndb != 0) {
- const NdbError& e = g_ndb->getNdbError();
- if (e.code != 0)
- ll0(++any << " ndb: error " << e);
- }
- if (g_dic != 0) {
- const NdbError& e = g_dic->getNdbError();
- if (e.code != 0)
- ll0(++any << " dic: error " << e);
- }
- if (g_con != 0) {
- const NdbError& e = g_con->getNdbError();
- if (e.code != 0)
- ll0(++any << " con: error " << e);
- }
- if (g_op != 0) {
- const NdbError& e = g_op->getNdbError();
- if (e.code != 0)
- ll0(++any << " op: error " << e);
- }
- if (g_scan_op != 0) {
- const NdbError& e = g_scan_op->getNdbError();
- if (e.code != 0)
- ll0(++any << " scan_op: error " << e);
- }
- if (g_rangescan_op != 0) {
- const NdbError& e = g_rangescan_op->getNdbError();
- if (e.code != 0)
- ll0(++any << " rangescan_op: error " << e);
- }
- if (g_stat != 0) {
- const NdbError& e = g_stat->getNdbError();
- if (e.code != 0)
- ll0(++any << " stat: error " << e);
- }
- if (! any)
- ll0("unknown db error");
-}
-
-// create table ts0 (
-// a int unsigned, b smallint not null, c varchar(10), d int unsigned,
-// primary key using hash (a), index (b, c, d) )
-
-static int
-createtable()
-{
- NdbDictionary::Table tab(g_tabname);
- tab.setLogging(false);
- {
- NdbDictionary::Column col("a");
- col.setType(NdbDictionary::Column::Unsigned);
- col.setPrimaryKey(true);
- tab.addColumn(col);
- }
- {
- NdbDictionary::Column col("b");
- col.setType(NdbDictionary::Column::Smallint);
- col.setNullable(false);
- tab.addColumn(col);
- }
- {
- NdbDictionary::Column col("c");
- col.setType(NdbDictionary::Column::Varchar);
- col.setLength(g_charlen);
- col.setCharset(g_cs);
- col.setNullable(true);
- tab.addColumn(col);
- }
- {
- NdbDictionary::Column col("d");
- col.setType(NdbDictionary::Column::Unsigned);
- col.setNullable(true);
- tab.addColumn(col);
- }
- NdbDictionary::Index ind(g_indname);
- ind.setTable(g_tabname);
- ind.setType(NdbDictionary::Index::OrderedIndex);
- ind.setLogging(false);
- ind.addColumnName("b");
- ind.addColumnName("c");
- ind.addColumnName("d");
- g_dic = g_ndb->getDictionary();
- if (! g_opts.keeptable) {
- if (g_dic->getTable(g_tabname) != 0)
- chkdb(g_dic->dropTable(g_tabname) == 0);
- chkdb(g_dic->createTable(tab) == 0);
- chkdb(g_dic->createIndex(ind) == 0);
- } else {
- if (g_dic->getTable(g_tabname) == 0) {
- chkdb(g_dic->createTable(tab) == 0);
- chkdb(g_dic->createIndex(ind) == 0);
- } else
- g_opts.loaddata = false;
- }
- chkdb((g_tab = g_dic->getTable(g_tabname)) != 0);
- chkdb((g_ind = g_dic->getIndex(g_indname, g_tabname)) != 0);
- g_dic = 0;
- return 0;
-}
-
-static int
-droptable()
-{
- g_dic = g_ndb->getDictionary();
- if (! g_opts.keeptable)
- chkdb(g_dic->dropTable(g_tabname) == 0);
- g_dic = 0;
- return 0;
-}
-
-struct Val {
- Int16 b;
- bool c_null;
- uchar c[1 + g_charlen];
- bool d_null;
- Uint32 d;
- // partial values for use in Bnd
- uint numattrs;
- void make(uint n = g_numattrs, bool is_val = true);
- int cmp(const Val& val, uint n = g_numattrs) const;
-};
-
-static NdbOut&
-operator<<(NdbOut& out, const Val& val)
-{
- out << "[";
- if (val.numattrs >= 1) {
- out << val.b;
- }
- if (val.numattrs >= 2) {
- out << " ";
- if (val.c_null)
- out << "NULL";
- else {
- char buf[1 + g_charlen];
- sprintf(buf, "%.*s", val.c[0], &val.c[1]);
- out << "'" << buf << "'";
- }
- }
- if (val.numattrs >= 3) {
- out << " ";
- if (val.d_null)
- out <<" NULL";
- else
- out << val.d;
- }
- out << "]";
- return out;
-}
-
-void
-Val::make(uint n, bool is_val)
-{
- if (n >= 1) {
- uint b_max = is_val ? g_val_b_max : g_bnd_b_max;
- b = (int)urandom(2 * b_max) - (int)b_max;
- }
- if (n >= 2) {
- if (urandom(100) < g_opts.nullkeys)
- c_null = 1;
- else {
- const char* c_char = is_val ? g_val_c_char : g_bnd_c_char;
- // prefer shorter
- uint len = urandom(urandom(g_charlen + 2));
- c[0] = len;
- uint j;
- for (j = 0; j < len; j++) {
- uint k = urandom(strlen(c_char));
- c[1 + j] = c_char[k];
- }
- c_null = 0;
- }
- }
- if (n >= 3) {
- if (urandom(100) < g_opts.nullkeys)
- d_null = 1;
- else {
- uint d_max = is_val ? g_val_d_max : g_bnd_d_max;
- d = urandom(d_max);
- d_null = 0;
- }
- }
- numattrs = n;
-}
-
-int
-Val::cmp(const Val& val, uint n) const
-{
- int k = 0;
- if (k == 0 && n >= 1) {
- if (b < val.b)
- k = -1;
- else if (b > val.b)
- k = +1;
- }
- if (k == 0 && n >= 2) {
- if (! c_null && ! val.c_null) {
- const uchar* s1 = &c[1];
- const uchar* s2 = &val.c[1];
- const uint l1 = (uint)c[0];
- const uint l2 = (uint)val.c[0];
- assert(l1 <= g_charlen && l2 <= g_charlen);
- k = g_cs->coll->strnncollsp(g_cs, s1, l1, s2, l2, 0);
- } else if (! c_null) {
- k = +1;
- } else if (! val.c_null) {
- k = -1;
- }
- }
- if (k == 0 && n >= 3) {
- if (! d_null && ! val.d_null) {
- if (d < val.d)
- k = -1;
- else if (d > val.d)
- k = +1;
- } else if (! d_null) {
- k = +1;
- } else if (! val.d_null) {
- k = -1;
- }
- }
- return k;
-}
-
-struct Key {
- Val val;
- union {
- bool flag;
- uint count;
- uint rpk;
- };
-};
-
-static NdbOut&
-operator<<(NdbOut& out, const Key& key)
-{
- out << key.val << " info:" << key.count;
- return out;
-}
-
-static Key* g_keys = 0;
-static Key* g_sortkeys = 0;
-static uint g_sortcount = 0;
-static Key* g_minkey = 0;
-static Key* g_maxkey = 0;
-
-static void
-freekeys()
-{
- if (g_keys != 0)
- my_free(g_keys);
- if (g_sortkeys != 0)
- my_free(g_sortkeys);
- g_keys = 0;
- g_sortkeys = 0;
-}
-
-static int
-allockeys()
-{
- freekeys();
- size_t sz = sizeof(Key) * g_opts.rows;
- g_keys = (Key*)my_malloc(sz, MYF(0));
- g_sortkeys = (Key*)my_malloc(sz, MYF(0));
- chkrc(g_keys != 0 && g_sortkeys != 0);
- memset(g_keys, 0x1f, sz);
- memset(g_sortkeys, 0x1f, sz);
- return 0;
-}
-
-static void
-makekeys()
-{
- uint i;
- for (i = 0; i < g_opts.rows; i++) {
- Key& key = g_keys[i];
- key.val.make();
- key.flag = false; // mark for dup generation done
- }
- for (i = 0; i < g_opts.rows; i++) {
- Key& key = g_keys[i];
- if (key.flag)
- continue;
- key.flag = true;
- uint fudge = 9;
- uint n = (urandom(fudge * (g_opts.dupkeys - 100)) + 99) / 100;
- uint k;
- for (k = 1; k < n; k++) {
- uint j = urandom(g_opts.rows);
- do {
- Key& dst = g_keys[j];
- if (! dst.flag) {
- dst.val = key.val;
- dst.flag = true;
- break;
- }
- } while (urandom(g_opts.tryhard) != 0);
- }
- }
-}
-
-static int
-insertdata()
-{
- const uint batch = 512;
- chkdb((g_con = g_ndb->startTransaction()) != 0);
- uint i = 0;
- while (i < g_opts.rows) {
- chkdb((g_op = g_con->getNdbOperation(g_tab)) != 0);
- chkdb(g_op->insertTuple() == 0);
- Uint32 a = i;
- const Val& val = g_keys[i].val;
- const char* a_addr = (const char*)&a;
- const char* b_addr = (const char*)&val.b;
- const char* c_addr = ! val.c_null ? (const char*)val.c : 0;
- const char* d_addr = ! val.d_null ? (const char*)&val.d : 0;
- Uint32 no = 0;
- chkdb(g_op->equal(no++, a_addr) == 0);
- chkdb(g_op->setValue(no++, b_addr) == 0);
- chkdb(g_op->setValue(no++, c_addr) == 0);
- chkdb(g_op->setValue(no++, d_addr) == 0);
- if (i++ % batch == 0) {
- chkdb(g_con->execute(NdbTransaction::Commit) == 0);
- g_ndb->closeTransaction(g_con);
- g_con = 0;
- g_op = 0;
- chkdb((g_con = g_ndb->startTransaction()) != 0);
- }
- }
- chkdb(g_con->execute(NdbTransaction::Commit) == 0);
- g_ndb->closeTransaction(g_con);
- g_con = 0;
- g_op = 0;
- ll0(g_tabname << ": inserted " << g_opts.rows << " rows");
- return 0;
-}
-
-static int
-countrows()
-{
- Uint64 rows = 0;
- Uint64 r;
- char* r_addr = (char*)&r;
- chkdb((g_con = g_ndb->startTransaction()) != 0);
- chkdb((g_scan_op = g_con->getNdbScanOperation(g_tab)) != 0);
- chkdb(g_scan_op->readTuples() == 0);
- chkdb(g_scan_op->interpret_exit_last_row() == 0);
- chkdb(g_scan_op->getValue(NdbDictionary::Column::ROW_COUNT, r_addr) != 0);
- chkdb(g_con->execute(NdbTransaction::NoCommit) == 0);
- while (1) {
- int ret;
- r = ~(Uint64)0;
- chkdb((ret = g_scan_op->nextResult()) == 0 || ret == 1);
- if (ret == 1)
- break;
- rows += r;
- }
- g_ndb->closeTransaction(g_con);
- g_con = 0;
- g_scan_op = 0;
- g_opts.rows = rows;
- return 0;
-}
-
-static int
-scandata()
-{
- chkdb((g_con = g_ndb->startTransaction()) != 0);
- chkdb((g_scan_op = g_con->getNdbScanOperation(g_tab)) != 0);
- chkdb(g_scan_op->readTuples() == 0);
- Uint32 a;
- Val val;
- char* a_addr = (char*)&a;
- char* b_addr = (char*)&val.b;
- char* c_addr = (char*)val.c;
- char* d_addr = (char*)&val.d;
- Uint32 no = 0;
- NdbRecAttr* b_ra;
- NdbRecAttr* c_ra;
- NdbRecAttr* d_ra;
- chkdb(g_scan_op->getValue(no++, a_addr) != 0);
- chkdb((b_ra = g_scan_op->getValue(no++, b_addr)) != 0);
- chkdb((c_ra = g_scan_op->getValue(no++, c_addr)) != 0);
- chkdb((d_ra = g_scan_op->getValue(no++, d_addr)) != 0);
- chkdb(g_con->execute(NdbTransaction::NoCommit) == 0);
- uint count = 0;
- uint i;
- for (i = 0; i < g_opts.rows; i++)
- g_keys[i].count = 0;
- while (1) {
- int ret;
- a = ~(Uint32)0;
- chkdb((ret = g_scan_op->nextResult()) == 0 || ret == 1);
- if (ret == 1)
- break;
- assert(b_ra->isNULL() == 0 && c_ra->isNULL() != -1 && d_ra->isNULL() != -1);
- val.c_null = c_ra->isNULL();
- val.d_null = d_ra->isNULL();
- i = (uint)a;
- chkrc(i < g_opts.rows);
- Key& key = g_keys[i];
- if (g_opts.loaddata)
- chkrc(key.val.cmp(val) == 0);
- else
- key.val = val;
- key.count++;
- count++;
- }
- g_ndb->closeTransaction(g_con);
- g_con = 0;
- g_scan_op = 0;
- for (i = 0; i < g_opts.rows; i++)
- chkrc(g_keys[i].count == 1);
- assert(count == g_opts.rows);
- int level = g_opts.loaddata ? 1 : 0;
- llx(level, g_tabname << ": scanned " << g_opts.rows << " rows");
- return 0;
-}
-
-static int
-loaddata()
-{
- if (g_opts.loaddata) {
- chkrc(allockeys() == 0);
- makekeys();
- chkrc(insertdata() == 0);
- } else {
- chkrc(countrows() == 0);
- chkrc(g_opts.rows != 0);
- ll0(g_tabname << ": using old table of " << g_opts.rows << " rows");
- chkrc(allockeys() == 0);
- }
- chkrc(scandata() == 0);
- uint i;
- for (i = 0; i < g_opts.rows; i++)
- ll3(i << ": " << g_keys[i]);
- return 0;
-}
-
-// true = match, index = match or next higher
-static bool
-sortval(const Val& val, int& index)
-{
- if (unlikely(g_sortcount == 0)) {
- index = 0;
- return false;
- }
- int lo = -1;
- int hi = (int)g_sortcount;
- int ret;
- int j;
- do {
- j = (hi + lo) / 2;
- ret = val.cmp(g_sortkeys[j].val);
- if (ret < 0)
- hi = j;
- else if (ret > 0)
- lo = j;
- else
- break;
- } while (hi - lo > 1);
- if (ret == 0) {
- index = j;
- return true;
- }
- index = hi;
- return false;
-}
-
-static void
-sortkeys()
-{
- // insert sort with binary search
- g_sortcount = 0;
- uint i;
- for (i = 0; i < g_opts.rows; i++) {
- const Val& val = g_keys[i].val;
- int index;
- bool match = sortval(val, index);
- Key& dst = g_sortkeys[index];
- if (match) {
- dst.rpk++;
- } else {
- uint bytes = ((int)g_sortcount - index) * sizeof(Key);
- memmove(&dst + 1, &dst, bytes);
- dst.val = val;
- dst.rpk = 1;
- g_sortcount++;
- }
- }
- g_minkey = &g_sortkeys[0];
- g_maxkey = &g_sortkeys[g_sortcount - 1];
- ll1("counted " << g_sortcount << " distinct keys");
-}
-
-struct Bnd {
- Val val;
- /*
- * A bound is a partial key value (0 to g_numattrs attributes).
- * It is not equal to any key value. Instead, it has a "side".
- *
- * side = 0 if the bound is empty
- * side = -1 if the bound is "just before" its value
- * side = +1 if the bound is "just after" its value
- *
- * This is another way of looking at strictness of non-empty
- * start and end keys in a range.
- *
- * start key is strict if side = +1
- * end key is strict if side = -1
- *
- * NDB API specifies strictness in the bound type of the last
- * index attribute which is part of the start/end key.
- *
- * LE (0) - strict: n - side: -1
- * LT (1) - strict: y - side: +1
- * GE (2) - strict: n - side: +1
- * GT (3) - strict: y - side: -1
- *
- * A non-empty bound divides keys into 2 disjoint subsets:
- * keys before (cmp() == -1) and keys after (cmp() == +1).
- */
- int side;
- Bnd& make(uint minattrs);
- Bnd& make(uint minattrs, const Val& theval);
- int cmp(const Val& val) const;
- int type(uint lohi, uint colno) const; // for setBound
-};
-
-static NdbOut&
-operator<<(NdbOut& out, const Bnd& bnd)
-{
- out << bnd.val;
- out << " side: " << bnd.side;
- return out;
-}
-
-Bnd&
-Bnd::make(uint minattrs)
-{
- uint numattrs = minattrs + urandom(g_numattrs - minattrs);
- val.make(numattrs, false);
- side = val.numattrs == 0 ? 0 : urandom(2) == 0 ? -1 : +1;
- return *this;
-}
-
-Bnd&
-Bnd::make(uint minattrs, const Val& theval)
-{
- uint numattrs = minattrs + urandom(g_numattrs - minattrs);
- val = theval;
- val.numattrs = numattrs;
- side = val.numattrs == 0 ? 0 : urandom(2) == 0 ? -1 : +1;
- return *this;
-}
-
-int
-Bnd::cmp(const Val& theval) const
-{
- int place; // debug
- int ret;
- do {
- assert(theval.numattrs == g_numattrs);
- int k = theval.cmp(val, val.numattrs);
- if (k != 0) {
- place = 1;
- ret = k;
- break;
- }
- if (side != 0) {
- place = 2;
- ret = -side;
- break;
- }
- place = 3;
- ret = 0;
- assert(val.numattrs == 0);
- } while (0);
- ll3("cmp: val: " << theval << " bnd: " << *this <<
- " return: " << ret << " at " << place);
- return ret;
-}
-
-int
-Bnd::type(uint lohi, uint colno) const
-{
- int t;
- assert(lohi <= 1 && colno < val.numattrs && (side == -1 || side == +1));
- if (lohi == 0) {
- if (colno + 1 < val.numattrs)
- t = 0; // LE
- else if (side == -1)
- t = 0; // LE
- else
- t = 1; // LT
- } else {
- if (colno + 1 < val.numattrs)
- t = 2; // GE
- else if (side == +1)
- t = 2; // GE
- else
- t = 3; // GT
- }
- return t;
-}
-
-struct Range {
- Bnd bnd[2];
- uint minattrs() const;
- uint maxattrs() const;
- int cmp(const Val& val) const; // -1,0,+1 = key is before,in,after range
- uint rowcount() const;
- bool iseq() const;
- // stats
- bool flag;
- uint statrows;
- uint scanrows;
- double errpct;
-};
-
-static NdbOut&
-operator<<(NdbOut& out, const Range& range)
-{
- out << "bnd0: " << range.bnd[0] << " bnd1: " << range.bnd[1];
- return out;
-}
-
-uint
-Range::minattrs() const
-{
- return min(bnd[0].val.numattrs, bnd[1].val.numattrs);
-}
-
-uint
-Range::maxattrs() const
-{
- return max(bnd[0].val.numattrs, bnd[1].val.numattrs);
-}
-
-int
-Range::cmp(const Val& theval) const
-{
- int place; // debug
- int ret;
- do {
- int k;
- k = bnd[0].cmp(theval);
- if (k < 0) {
- place = 1;
- ret = -1;
- break;
- }
- k = bnd[1].cmp(theval);
- if (k > 0) {
- place = 2;
- ret = +1;
- break;
- }
- place = 3;
- ret = 0;
- } while (0);
- ll3("cmp: val: " << theval << " range: " << *this <<
- " return: " << ret << " at " << place);
- return ret;
-}
-
-uint
-Range::rowcount() const
-{
- ll2("rowcount: " << *this);
- int i;
- // binary search for first and last in range
- int lim[2];
- for (i = 0; i <= 1; i++) {
- ll3("search i=" << i);
- int lo = -1;
- int hi = (int)g_sortcount;
- int ret;
- int j;
- do {
- j = (hi + lo) / 2;
- ret = cmp(g_sortkeys[j].val);
- if (i == 0) {
- if (ret < 0)
- lo = j;
- else
- hi = j;
- } else {
- if (ret > 0)
- hi = j;
- else
- lo = j;
- }
- } while (hi - lo > 1);
- if (ret == 0)
- lim[i] = j;
- else if (i == 0)
- lim[i] = hi;
- else
- lim[i] = lo;
- }
- // the range
- const int lo = max(lim[0], 0);
- const int hi = min(lim[1], (int)g_sortcount - 1);
- if (! g_opts.nochecks) {
- int curr = -1;
- for (i = 0; i < (int)g_sortcount; i++) {
- int k = cmp(g_sortkeys[i].val);
- if (k < 0)
- assert(i < lo);
- else if (k == 0)
- assert(lo <= i && i <= hi);
- else
- assert(i > hi);
- assert(curr <= k);
- if (curr < k)
- curr = k;
- }
- }
- // sum them up
- uint count = 0;
- for (i = lo; i <= hi; i++)
- count += g_sortkeys[i].count;
- ll2("count: " << count << " index lim: " << lim[0] << " " << lim[1]);
- return count;
-}
-
-bool
-Range::iseq() const
-{
- return
- minattrs() == maxattrs() &&
- bnd[0].val.cmp(bnd[1].val, minattrs()) == 0 &&
- bnd[0].side < bnd[1].side;
-}
-
-static Range* g_ranges = 0;
-
-static void
-freeranges()
-{
- if (g_ranges != 0)
- my_free(g_ranges);
- g_ranges = 0;
-}
-
-static int
-allocranges()
-{
- freeranges();
- size_t sz = sizeof(Range) * g_opts.ops;
- g_ranges = (Range*)my_malloc(sz, MYF(0));
- chkrc(g_ranges != 0);
- memset(g_ranges, 0x1f, sz);
- return 0;
-}
-
-static void
-makeranges()
-{
- uint i;
- for (i = 0; i < g_opts.ops; i++) {
- Range& range = g_ranges[i];
- range.flag = false; // mark for dup generation done
- bool fulleq = (urandom(100) < g_opts.eqscans);
- bool eq = fulleq || (urandom(100) < g_opts.eqscans);
- bool matcheq = eq && (urandom(10) != 0);
- if (! eq) {
- // random but prefer non-empty and no more than scanpct
- do {
- range.bnd[0].make(0);
- range.bnd[1].make(0);
- uint count = range.rowcount();
- if (count != 0 && 100 * count <= g_opts.scanpct * g_opts.rows)
- break;
- } while (urandom(g_opts.tryhard) != 0);
- } else {
- uint minattrs = fulleq ? g_numattrs : 1;
- if (! matcheq) {
- range.bnd[0].make(minattrs);
- } else {
- uint m = urandom(g_sortcount);
- const Val& val = g_sortkeys[m].val;
- range.bnd[0].make(minattrs, val);
- }
- range.bnd[1] = range.bnd[0];
- range.bnd[0].side = -1;
- range.bnd[1].side = +1;
- // fix types
- range.bnd[0];
- range.bnd[1];
- assert(range.iseq());
- }
- }
- for (i = 0; i < g_opts.ops; i++) {
- Range& range = g_ranges[i];
- if (range.flag)
- continue;
- range.flag = true;
- if (urandom(100) < g_opts.dupscans) {
- uint j = urandom(g_opts.ops);
- do {
- Range& dst = g_ranges[j];
- if (! dst.flag) {
- dst.bnd[0] = range.bnd[0];
- dst.bnd[1] = range.bnd[1];
- dst.flag = true;
- break;
- }
- } while (urandom(g_opts.tryhard) != 0);
- }
- }
-}
-
-static int
-setbounds(const Range& range)
-{
- // currently must do each attr in order
- ll2("setbounds: " << range);
- uint i;
- const Bnd (&bnd)[2] = range.bnd;
- for (i = 0; i < g_numattrs; i++) {
- const Uint32 no = i; // index attribute number
- uint j;
- int type[2] = { -1, -1 };
- for (j = 0; j <= 1; j++) {
- if (no < bnd[j].val.numattrs)
- type[j] = bnd[j].type(j, no);
- }
- for (j = 0; j <= 1; j++) {
- int t = type[j];
- if (t == -1)
- continue;
- if (no + 1 < bnd[j].val.numattrs)
- t &= ~(uint)1; // strict bit is set on last bound only
- const Val& val = bnd[j].val;
- const void* addr = 0;
- if (no == 0)
- addr = (const void*)&val.b;
- else if (no == 1)
- addr = ! val.c_null ? (const void*)val.c : 0;
- else if (no == 2)
- addr = ! val.d_null ? (const void*)&val.d : 0;
- else
- assert(false);
- ll2("setBound attr:" << no << " type:" << t << " val: " << val);
- chkdb(g_rangescan_op->setBound(no, t, addr) == 0);
- }
- }
- return 0;
-}
-
-static int
-allocstat()
-{
- g_stat = new NdbIndexStat(g_ind);
- chkdb(g_stat->alloc_cache(32) == 0);
- return 0;
-}
-
-static int
-runstat(Range& range, int flags)
-{
- ll2("runstat: " << range << " flags=" << flags);
- chkdb((g_con = g_ndb->startTransaction()) != 0);
- chkdb((g_rangescan_op = g_con->getNdbIndexScanOperation(g_ind, g_tab)) != 0);
- chkdb(g_rangescan_op->readTuples(NdbOperation::LM_CommittedRead) == 0);
- chkrc(setbounds(range) == 0);
- Uint64 count = ~(Uint64)0;
- chkdb(g_stat->records_in_range(g_ind, g_rangescan_op, g_opts.rows, &count, flags) == 0);
- g_ndb->closeTransaction(g_con);
- g_con = 0;
- g_rangescan_op = 0;
- range.statrows = (uint)count;
- chkrc((Uint64)range.statrows == count);
- ll2("stat: " << range.statrows);
- return 0;
-}
-
-static int
-runscan(Range& range)
-{
- ll2("runscan: " << range);
- chkdb((g_con = g_ndb->startTransaction()) != 0);
- chkdb((g_rangescan_op = g_con->getNdbIndexScanOperation(g_ind, g_tab)) != 0);
- chkdb(g_rangescan_op->readTuples() == 0);
- chkrc(setbounds(range) == 0);
- Uint32 a;
- char* a_addr = (char*)&a;
- Uint32 no = 0;
- chkdb(g_rangescan_op->getValue(no++, a_addr) != 0);
- chkdb(g_con->execute(NdbTransaction::NoCommit) == 0);
- uint count = 0;
- uint i;
- for (i = 0; i < g_opts.rows; i++)
- g_keys[i].count = 0;
- while (1) {
- int ret;
- a = ~(Uint32)0;
- chkdb((ret = g_rangescan_op->nextResult()) == 0 || ret == 1);
- if (ret == 1)
- break;
- i = (uint)a;
- chkrc(i < g_opts.rows);
- Key& key = g_keys[i];
- ll3("scan: " << key);
- int k = range.cmp(key.val);
- chkrc(k == 0);
- chkrc(key.count == 0);
- key.count++;
- count++;
- }
- g_ndb->closeTransaction(g_con);
- g_con = 0;
- g_rangescan_op = 0;
- if (! g_opts.nochecks) {
- for (i = 0; i < g_opts.rows; i++) {
- const Key& key = g_keys[i];
- int k = range.cmp(key.val);
- assert((k != 0 && key.count == 0) || (k == 0 && key.count == 1));
- }
- assert(range.rowcount() == count);
- }
- range.scanrows = count;
- ll2("scan: " << range.scanrows);
- return 0;
-}
-
-static int
-runscans()
-{
- uint i;
- for (i = 0; i < g_opts.ops; i++) {
- Range& range = g_ranges[i];
- ll1("range " << i << ": " << range);
- // simulate old handler code
- int flags = 0;
- if (i < 32 || i % 20 == 0)
- flags |= NdbIndexStat::RR_UseDb;
- chkrc(runstat(range, flags) == 0);
- chkrc(runscan(range) == 0);
- // if stat is 0 then it is exact scan count
- chkrc(range.statrows != 0 || range.scanrows == 0);
- // measure error as fraction of total rows
- double x = (double)range.statrows;
- double y = (double)range.scanrows;
- double z = (double)g_opts.rows;
- double err = (x - y) / z;
- // report in pct
- range.errpct = 100.0 * err;
- ll1("range " << i << ":" <<
- " stat: " << range.statrows << " scan: " << range.scanrows <<
- " errpct: " << range.errpct);
- }
- return 0;
-}
-
-struct Stat {
- const char* name;
- uint count;
- double sum;
- double minval;
- double maxval;
- double avg;
- double varsum;
- double var;
- double stddev;
- void init();
- void add(const Stat& stat);
-};
-
-void
-Stat::init()
-{
- name = "stat";
- count = 0;
- sum = minval = maxval = avg = varsum = var = stddev = 0.0;
-}
-
-void
-Stat::add(const Stat& stat)
-{
- if (count == 0) {
- *this = stat;
- return;
- }
- Stat tmp = *this;
- tmp.count = count + stat.count;
- tmp.sum = sum + stat.sum;
- tmp.minval = minval <= stat.minval ? minval : stat.minval;
- tmp.maxval = maxval >= stat.maxval ? maxval : stat.maxval;
- tmp.avg = tmp.sum / double(tmp.count);
- tmp.varsum = varsum + stat.varsum;
- tmp.var = tmp.varsum / double(tmp.count);
- tmp.stddev = sqrt(tmp.var);
- *this = tmp;
-}
-
-static NdbOut&
-operator<<(NdbOut& out, const Stat& stat)
-{
- out << stat.name << ": " << "count: " << stat.count
- << " min: " << stat.minval << " max: " << stat.maxval
- << " avg: " << stat.avg << " stddev: " << stat.stddev;
- return out;
-}
-
-template <class T, class V>
-static void
-computestat(Stat& stat)
-{
- stat.init();
- stat.name = V::name();
- const T* array = V::array();
- stat.count = V::count();
- assert(stat.count != 0);
- uint i;
- for (i = 0; i < stat.count; i++) {
- const T& item = array[i];
- double data = V::data(item);
- stat.sum += data;
- if (i == 0)
- stat.minval = stat.maxval = data;
- else {
- if (stat.minval > data)
- stat.minval = data;
- if (stat.maxval < data)
- stat.maxval = data;
- }
- }
- stat.avg = stat.sum / double(stat.count);
- stat.varsum = 0.0;
- for (i = 0; i < stat.count; i++) {
- const T& item = array[i];
- double data = V::data(item);
- double x = data - stat.avg;
- stat.varsum += x * x;
- }
- stat.var = stat.varsum / double(stat.count);
- stat.stddev = sqrt(stat.var);
-}
-
-struct V_rpk {
- static const char* name() { return "rec per key"; }
- static const Key* array() { return g_sortkeys; }
- static uint count() { return g_sortcount; }
- static double data(const Key& key) { return (double)key.rpk; }
-};
-
-struct V_rir {
- static const char* name() { return "rir err pct"; }
- static const Range* array() { return g_ranges; }
- static uint count() { return g_opts.ops; }
- static double data(const Range& range) { return (double)range.errpct; }
-};
-
-template void computestat<Key, V_rpk>(Stat& stat);
-template void computestat<Range, V_rir>(Stat& stat);
-
-static Stat g_stat_rpk; // summaries over loops
-static Stat g_stat_rir;
-
-static void
-loopstats()
-{
- Stat stat_rpk; // records per key
- Stat stat_rir; // record in range
- if (g_loop == 0) {
- g_stat_rpk.init();
- g_stat_rir.init();
- }
- computestat<Key, V_rpk>(stat_rpk);
- computestat<Range, V_rir>(stat_rir);
- if (g_opts.loop != 1) {
- ll0("=== loop " << g_loop << " summary ===");
- ll0(stat_rpk);
- ll0(stat_rir);
- }
- // accumulate
- g_stat_rpk.add(stat_rpk);
- g_stat_rir.add(stat_rir);
-}
-
-static void
-finalstats()
-{
- ll0("=== summary ===");
- ll0(g_stat_rpk);
- ll0(g_stat_rir);
-}
-
-static void
-setseed(int n)
-{
- uint seed;
- if (n == -1) {
- if (g_opts.seed == 0)
- return;
- if (g_opts.seed != -1)
- seed = (uint)g_opts.seed;
- else
- seed = 1 + (ushort)getpid();
- } else {
- if (g_opts.seed != 0)
- return;
- seed = n;
- }
- ll0("seed=" << seed);
- srandom(seed);
-}
-
-static int
-runtest()
-{
- setseed(-1);
- g_cs = get_charset_by_name(g_csname, MYF(0));
- if (g_cs == 0)
- g_cs = get_charset_by_csname(g_csname, MY_CS_PRIMARY, MYF(0));
- chkrc(g_cs != 0);
- for (g_loop = 0; g_opts.loop == 0 || g_loop < g_opts.loop; g_loop++) {
- ll0("=== loop " << g_loop << " ===");
- setseed(g_loop);
- chkrc(createtable() == 0);
- chkrc(loaddata() == 0);
- sortkeys();
- chkrc(allocranges() == 0);
- makeranges();
- chkrc(allocstat() == 0);
- chkrc(runscans() == 0);
- chkrc(droptable() == 0);
- loopstats();
- }
- finalstats();
- return 0;
-}
-
-NDB_STD_OPTS_VARS;
-
-static struct my_option
-my_long_options[] =
-{
- NDB_STD_OPTS("testIndexStat"),
- { "loglevel", 1001, "Logging level in this program 0-3 (default 0)",
- &g_opts.loglevel, &g_opts.loglevel, 0,
- GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
- { "seed", 1002, "Random seed (0=loop number, default -1=random)",
- &g_opts.seed, &g_opts.seed, 0,
- GET_INT, REQUIRED_ARG, -1, 0, 0, 0, 0, 0 },
- { "loop", 1003, "Number of test loops (default 1, 0=forever)",
- &g_opts.loop, &g_opts.loop, 0,
- GET_INT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0 },
- { "rows", 1004, "Number of rows (default 100000)",
- &g_opts.rows, &g_opts.rows, 0,
- GET_UINT, REQUIRED_ARG, 100000, 0, 0, 0, 0, 0 },
- { "ops", 1005, "Number of index scans per loop (default 1000)",
- &g_opts.ops, &g_opts.ops, 0,
- GET_UINT, REQUIRED_ARG, 1000, 0, 0, 0, 0, 0 },
- { "dupkeys", 1006, "Pct records per key (min 100, default 1000)",
- &g_opts.dupkeys, &g_opts.dupkeys, 0,
- GET_UINT, REQUIRED_ARG, 1000, 0, 0, 0, 0, 0 },
- { "scanpct", 1007, "Preferred max pct of total rows per scan (default 5)",
- &g_opts.scanpct, &g_opts.scanpct, 0,
- GET_UINT, REQUIRED_ARG, 5, 0, 0, 0, 0, 0 },
- { "nullkeys", 1008, "Pct nulls in each key attribute (default 10)",
- &g_opts.nullkeys, &g_opts.nullkeys, 0,
- GET_UINT, REQUIRED_ARG, 10, 0, 0, 0, 0, 0 },
- { "eqscans", 1009, "Pct scans for partial/full equality (default 50)",
- &g_opts.eqscans, &g_opts.eqscans, 0,
- GET_UINT, REQUIRED_ARG, 50, 0, 0, 0, 0, 0 },
- { "dupscans", 1010, "Pct scans using same bounds (default 10)",
- &g_opts.dupscans, &g_opts.dupscans, 0,
- GET_UINT, REQUIRED_ARG, 10, 0, 0, 0, 0, 0 },
- { "keeptable", 1011, "Use existing table and data if any and do not drop",
- &g_opts.keeptable, &g_opts.keeptable, 0,
- GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
- { "no-extra-checks", 1012, "Omit expensive consistency checks",
- &g_opts.nochecks, &g_opts.nochecks, 0,
- GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
- { "abort-on-error", 1013, "Dump core on any error",
- &g_opts.abort, &g_opts.abort, 0,
- GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
- { 0, 0, 0,
- 0, 0, 0,
- GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 }
-};
-
-static void
-usage()
-{
- ndbout
- << g_progname
- << ": measure records_in_range error as percentage of total rows" << endl;
- my_print_help(my_long_options);
-}
-
-static int
-checkoptions()
-{
- chkrc(g_opts.rows != 0);
- chkrc(g_opts.nullkeys <= 100);
- chkrc(g_opts.dupkeys >= 100);
- chkrc(g_opts.scanpct <= 100);
- chkrc(g_opts.eqscans <= 100);
- chkrc(g_opts.dupscans <= 100);
- return 0;
-}
-
-static int
-doconnect()
-{
- g_ncc = new Ndb_cluster_connection();
- chkdb(g_ncc->connect(30) == 0);
- g_ndb = new Ndb(g_ncc, "TEST_DB");
- chkdb(g_ndb->init() == 0 && g_ndb->waitUntilReady(30) == 0);
- return 0;
-}
-
-static void
-freeall()
-{
- delete g_stat;
- freekeys();
- freeranges();
- delete g_ndb;
- delete g_ncc;
-}
-
-int
-main(int argc, char** argv)
-{
- ndb_init();
- const char* g_progname =
- strchr(argv[0], '/') ? strrchr(argv[0], '/') + 1 : argv[0];
- uint i;
- ndbout << g_progname;
- for (i = 1; i < argc; i++)
- ndbout << " " << argv[i];
- ndbout << endl;
- int ret;
- ret = handle_options(&argc, &argv, my_long_options, ndb_std_get_one_option);
- if (ret != 0 || argc != 0)
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- if (checkoptions() == 0 && doconnect() == 0 && runtest() == 0) {
- freeall();
- return NDBT_ProgramExit(NDBT_OK);
- }
- freeall();
- return NDBT_ProgramExit(NDBT_FAILED);
-}
diff --git a/storage/ndb/test/ndbapi/testInterpreter.cpp b/storage/ndb/test/ndbapi/testInterpreter.cpp
deleted file mode 100644
index a85519b0a86..00000000000
--- a/storage/ndb/test/ndbapi/testInterpreter.cpp
+++ /dev/null
@@ -1,443 +0,0 @@
-/* Copyright (c) 2003-2006, 2008 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT.hpp>
-#include <NDBT_Test.hpp>
-#include <HugoTransactions.hpp>
-#include <UtilTransactions.hpp>
-#include <NdbRestarter.hpp>
-#include <NdbRestarts.hpp>
-#include <Vector.hpp>
-#include <random.h>
-#include <NdbTick.h>
-
-
-#define CHECK(b) if (!(b)) { \
- ndbout << "ERR: "<< step->getName() \
- << " failed on line " << __LINE__ << endl; \
- result = NDBT_FAILED; \
- continue; }
-
-int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
- int batchSize = ctx->getProperty("BatchSize", 1);
-
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.pkDelRecords(GETNDB(step), records, batchSize) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
-
- int records = ctx->getNumRecords();
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.loadTable(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runTestIncValue64(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
- // NDBT_Table* pTab = ctx->getTab();
- //Ndb* pNdb = GETNDB(step);
-
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.pkInterpretedUpdateRecords(GETNDB(step),
- records) != 0){
- return NDBT_FAILED;
- }
-
- // Verify the update
- if (hugoTrans.pkReadRecords(GETNDB(step),
- records) != 0){
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-
-}
-
-int runTestIncValue32(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- const NdbDictionary::Table * pTab = ctx->getTab();
- Ndb* pNdb = GETNDB(step);
-
- if (strcmp(pTab->getName(), "T1") != 0) {
- g_err << "runTestBug19537: skip, table != T1" << endl;
- return NDBT_OK;
- }
-
-
- NdbConnection* pTrans = pNdb->startTransaction();
- if (pTrans == NULL){
- ERR(pNdb->getNdbError());
- return NDBT_FAILED;
- }
-
- NdbOperation* pOp = pTrans->getNdbOperation(pTab->getName());
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- int check = pOp->interpretedUpdateTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
-
- // Primary keys
- Uint32 pkVal = 1;
- check = pOp->equal("KOL1", pkVal );
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- // Attributes
-
- // Update column
- Uint32 valToIncWith = 1;
- check = pOp->incValue("KOL2", valToIncWith);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- NdbRecAttr* valueRec = pOp->getValue("KOL2");
- if( valueRec == NULL ) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- check = pTrans->execute(Commit);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- Uint32 value = valueRec->u_32_value();
-
- pNdb->closeTransaction(pTrans);
-
-
- return NDBT_OK;
-}
-
-int runTestBug19537(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- const NdbDictionary::Table * pTab = ctx->getTab();
- Ndb* pNdb = GETNDB(step);
-
- if (strcmp(pTab->getName(), "T1") != 0) {
- g_err << "runTestBug19537: skip, table != T1" << endl;
- return NDBT_OK;
- }
-
-
- NdbConnection* pTrans = pNdb->startTransaction();
- if (pTrans == NULL){
- ERR(pNdb->getNdbError());
- return NDBT_FAILED;
- }
-
- NdbOperation* pOp = pTrans->getNdbOperation(pTab->getName());
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- if (pOp->interpretedUpdateTuple() == -1) {
- ERR(pOp->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
-
- // Primary keys
- const Uint32 pkVal = 1;
- if (pOp->equal("KOL1", pkVal) == -1) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- // Load 64-bit constant into register 1 and
- // write from register 1 to 32-bit column KOL2
- const Uint64 reg_val = 0x0102030405060708ULL;
-
- const Uint32* reg_ptr32 = (const Uint32*)&reg_val;
- if (reg_ptr32[0] == 0x05060708 && reg_ptr32[1] == 0x01020304) {
- g_err << "runTestBug19537: platform is LITTLE endian" << endl;
- } else if (reg_ptr32[0] == 0x01020304 && reg_ptr32[1] == 0x05060708) {
- g_err << "runTestBug19537: platform is BIG endian" << endl;
- } else {
- g_err << "runTestBug19537: impossible platform"
- << hex << " [0]=" << reg_ptr32[0] << " [1]=" <<reg_ptr32[1] << endl;
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- if (pOp->load_const_u64(1, reg_val) == -1 ||
- pOp->write_attr("KOL2", 1) == -1) {
- ERR(pOp->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- if (pTrans->execute(Commit) == -1) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- // Read value via a new transaction
-
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL){
- ERR(pNdb->getNdbError());
- return NDBT_FAILED;
- }
-
- pOp = pTrans->getNdbOperation(pTab->getName());
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- Uint32 kol2 = 0x09090909;
- if (pOp->readTuple() == -1 ||
- pOp->equal("KOL1", pkVal) == -1 ||
- pOp->getValue("KOL2", (char*)&kol2) == 0) {
- ERR(pOp->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- if (pTrans->execute(Commit) == -1) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- // Expected conversion as in C - truncate to lower (logical) word
-
- if (kol2 == 0x01020304) {
- g_err << "runTestBug19537: the bug manifests itself !" << endl;
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- if (kol2 != 0x05060708) {
- g_err << "runTestBug19537: impossible KOL2 " << hex << kol2 << endl;
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- pNdb->closeTransaction(pTrans);
- return NDBT_OK;
-}
-
-
-int runTestBug34107(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- const NdbDictionary::Table * pTab = ctx->getTab();
- Ndb* pNdb = GETNDB(step);
-
- int i;
- for (i = 0; i <= 1; i++) {
- g_info << "bug34107:" << (i == 0 ? " small" : " too big") << endl;
-
- NdbConnection* pTrans = pNdb->startTransaction();
- if (pTrans == NULL){
- ERR(pNdb->getNdbError());
- return NDBT_FAILED;
- }
-
- NdbScanOperation* pOp = pTrans->getNdbScanOperation(pTab->getName());
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- if (pOp->readTuples() == -1) {
- ERR(pOp->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- int n = i == 0 ? 10000 : 30000;
- int k;
-
- for (k = 0; k < n; k++) {
-
- // inserts 1 word ATTRINFO
-
- if (pOp->interpret_exit_ok() == -1) {
- ERR(pOp->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
- }
-
- if (pTrans->execute(NoCommit) == -1) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- int ret;
- while ((ret = pOp->nextResult()) == 0)
- ;
- g_info << "ret=" << ret << " err=" << pOp->getNdbError().code << endl;
-
- if (i == 0 && ret != 1) {
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- if (i == 1 && ret != -1) {
- g_err << "unexpected big filter success" << endl;
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
- if (i == 1 && pOp->getNdbError().code != 874) {
- g_err << "unexpected big filter error code, wanted 874" << endl;
- ERR(pTrans->getNdbError());
- pNdb->closeTransaction(pTrans);
- return NDBT_FAILED;
- }
-
- pNdb->closeTransaction(pTrans);
- }
-
- return NDBT_OK;
-}
-
-
-NDBT_TESTSUITE(testInterpreter);
-TESTCASE("IncValue32",
- "Test incValue for 32 bit integer\n"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runTestIncValue32);
- FINALIZER(runClearTable);
-}
-TESTCASE("IncValue64",
- "Test incValue for 64 bit integer\n"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runTestIncValue64);
- FINALIZER(runClearTable);
-}
-TESTCASE("Bug19537",
- "Test big-endian write_attr of 32 bit integer\n"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runTestBug19537);
- FINALIZER(runClearTable);
-}
-TESTCASE("Bug34107",
- "Test too big scan filter (error 874)\n"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runTestBug34107);
- FINALIZER(runClearTable);
-}
-#if 0
-TESTCASE("MaxTransactions",
- "Start transactions until no more can be created\n"){
- INITIALIZER(runTestMaxTransaction);
-}
-TESTCASE("MaxOperations",
- "Get operations until no more can be created\n"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runTestMaxOperations);
- FINALIZER(runClearTable);
-}
-TESTCASE("MaxGetValue",
- "Call getValue loads of time\n"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runTestGetValue);
- FINALIZER(runClearTable);
-}
-TESTCASE("MaxEqual",
- "Call equal loads of time\n"){
- INITIALIZER(runTestEqual);
-}
-TESTCASE("DeleteNdb",
- "Make sure that a deleted Ndb object is properly deleted\n"
- "and removed from transporter\n"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runTestDeleteNdb);
- FINALIZER(runClearTable);
-}
-TESTCASE("WaitUntilReady",
- "Make sure you get an error message when calling waitUntilReady\n"
- "without an init'ed Ndb\n"){
- INITIALIZER(runTestWaitUntilReady);
-}
-TESTCASE("GetOperationNoTab",
- "Call getNdbOperation on a table that does not exist\n"){
- INITIALIZER(runGetNdbOperationNoTab);
-}
-TESTCASE("MissingOperation",
- "Missing operation request(insertTuple) should give an error code\n"){
- INITIALIZER(runMissingOperation);
-}
-TESTCASE("GetValueInUpdate",
- "Test that it's not possible to perform getValue in an update\n"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runGetValueInUpdate);
- FINALIZER(runClearTable);
-}
-TESTCASE("UpdateWithoutKeys",
- "Test that it's not possible to perform update without setting\n"
- "PKs"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runUpdateWithoutKeys);
- FINALIZER(runClearTable);
-}
-TESTCASE("UpdateWithoutValues",
- "Test that it's not possible to perform update without setValues\n"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runUpdateWithoutValues);
- FINALIZER(runClearTable);
-}
-TESTCASE("NdbErrorOperation",
- "Test that NdbErrorOperation is properly set"){
- INITIALIZER(runCheckGetNdbErrorOperation);
-}
-#endif
-NDBT_TESTSUITE_END(testInterpreter);
-
-int main(int argc, const char** argv){
- ndb_init();
- // TABLE("T1");
- return testInterpreter.execute(argc, argv);
-}
-
-
diff --git a/storage/ndb/test/ndbapi/testLcp.cpp b/storage/ndb/test/ndbapi/testLcp.cpp
deleted file mode 100644
index 2b511fc139f..00000000000
--- a/storage/ndb/test/ndbapi/testLcp.cpp
+++ /dev/null
@@ -1,558 +0,0 @@
-/* Copyright (C) 2004, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT.hpp>
-#include <NdbApi.hpp>
-#include <NdbRestarter.hpp>
-#include <HugoOperations.hpp>
-#include <HugoTransactions.hpp>
-#include <UtilTransactions.hpp>
-#include <signaldata/DumpStateOrd.hpp>
-
-#include <getarg.h>
-#include <InputStream.hpp>
-
-struct CASE
-{
- bool start_row;
- bool end_row;
- bool curr_row;
- const char * op1;
- const char * op2;
- const char * op3;
- int val;
-};
-
-static CASE g_op_types[] =
-{
- { false, true, false, "INS", 0, 0, 0 }, // 0x001 a
- { true, true, false, "UPD", 0, 0, 0 }, // 0x002 d
- { true, false, false, "DEL", 0, 0, 0 }, // 0x004 g
-
- { false, true, false, "INS", "UPD", 0, 0 }, // 0x008 b
- { false, false, false, "INS", "DEL", 0, 0 }, // 0x010 c
- { true, true, false, "UPD", "UPD", 0, 0 }, // 0x020 e
- { true, false, false, "UPD", "DEL", 0, 0 }, // 0x040 f
- { true, true, false, "DEL", "INS", 0, 0 }, // 0x080 h
-
- { false, true, false, "INS", "DEL", "INS", 0 }, // 0x100 i
- { true, false, false, "DEL", "INS", "DEL", 0 } // 0x200 j
-};
-const size_t OP_COUNT = (sizeof(g_op_types)/sizeof(g_op_types[0]));
-
-static Ndb* g_ndb = 0;
-static CASE* g_ops;
-static Ndb_cluster_connection *g_cluster_connection= 0;
-static HugoOperations* g_hugo_ops;
-static int g_use_ops = 1 | 2 | 4;
-static int g_cases = 0x1;
-static int g_case_loop = 2;
-static int g_rows = 10;
-static int g_setup_tables = 1;
-static int g_one_op_at_a_time = 0;
-static const char * g_tablename = "T1";
-static const NdbDictionary::Table* g_table = 0;
-static NdbRestarter g_restarter;
-
-static int init_ndb(int argc, char** argv);
-static int parse_args(int argc, char** argv);
-static int connect_ndb();
-static int drop_all_tables();
-static int load_table();
-static int pause_lcp(int error);
-static int do_op(int row);
-static int continue_lcp(int error = 0);
-static int commit();
-static int restart();
-static int validate();
-
-#define require(x) { bool b = x; if(!b){g_err << __LINE__ << endl; abort();}}
-
-int
-main(int argc, char ** argv){
- ndb_init();
- require(!init_ndb(argc, argv));
- if(parse_args(argc, argv))
- return -1;
- require(!connect_ndb());
-
- if(g_setup_tables){
- require(!drop_all_tables());
-
- if(NDBT_Tables::createTable(g_ndb, g_tablename) != 0){
- exit(-1);
- }
- }
-
- g_table = g_ndb->getDictionary()->getTable(g_tablename);
- if(g_table == 0){
- g_err << "Failed to retreive table: " << g_tablename << endl;
- exit(-1);
- }
- require(g_hugo_ops = new HugoOperations(* g_table));
- require(!g_hugo_ops->startTransaction(g_ndb));
-
- g_ops= new CASE[g_rows];
-
- const int use_ops = g_use_ops;
- for(size_t i = 0; i<OP_COUNT; i++)
- {
- if(g_one_op_at_a_time){
- while(i < OP_COUNT && (use_ops & (1 << i)) == 0) i++;
- if(i == OP_COUNT)
- break;
- ndbout_c("-- loop\noperation: %c use_ops: %x", 'a'+i, use_ops);
- g_use_ops = (1 << i);
- } else {
- i = OP_COUNT - 1;
- }
-
- size_t test_case = 0;
- if((1 << test_case++) & g_cases)
- {
- for(size_t tl = 0; tl<g_case_loop; tl++){
- g_info << "Performing all ops wo/ inteference of LCP" << endl;
-
- g_info << "Testing pre LCP operations, ZLCP_OP_WRITE_RT_BREAK" << endl;
- g_info << " where ZLCP_OP_WRITE_RT_BREAK is "
- " finished before SAVE_PAGES" << endl;
- require(!load_table());
- require(!pause_lcp(5900));
- for(size_t j = 0; j<g_rows; j++){
- require(!do_op(j));
- }
- require(!continue_lcp(5900));
- require(!commit());
- require(!pause_lcp(5900));
- require(!restart());
- require(!validate());
- }
- }
-
- if((1 << test_case++) & g_cases)
- {
- for(size_t tl = 0; tl<g_case_loop; tl++){
- g_info << "Testing pre LCP operations, ZLCP_OP_WRITE_RT_BREAK" << endl;
- g_info << " where ZLCP_OP_WRITE_RT_BREAK is finished after SAVE_PAGES"
- << endl;
- require(!load_table());
- require(!pause_lcp(5901));
- for(size_t j = 0; j<g_rows; j++){
- require(!do_op(j));
- }
- require(!continue_lcp(5901));
- require(!commit());
- require(!pause_lcp(5900));
- require(!restart());
- require(!validate());
- }
- }
-
- if((1 << test_case++) & g_cases)
- {
- for(size_t tl = 0; tl<g_case_loop; tl++){
- g_info << "Testing pre LCP operations, undo-ed at commit" << endl;
- require(!load_table());
- require(!pause_lcp(5902));
- for(size_t j = 0; j<g_rows; j++){
- require(!do_op(j));
- }
- require(!continue_lcp(5902));
- require(!commit());
- require(!continue_lcp(5903));
- require(!pause_lcp(5900));
- require(!restart());
- require(!validate());
- }
- }
-
- if((1 << test_case++) & g_cases)
- {
- for(size_t tl = 0; tl<g_case_loop; tl++){
- g_info << "Testing prepared during LCP and committed after" << endl;
- require(!load_table());
- require(!pause_lcp(5904)); // Start LCP, but don't save pages
- for(size_t j = 0; j<g_rows; j++){
- require(!do_op(j));
- }
- require(!continue_lcp(5904)); // Start ACC save pages
- require(!pause_lcp(5900)); // Next LCP
- require(!commit());
- require(!restart());
- require(!validate());
- }
- }
- }
-}
-
-static int init_ndb(int argc, char** argv)
-{
- ndb_init();
- return 0;
-}
-
-static int parse_args(int argc, char** argv)
-{
- size_t i;
- char * ops= 0, *cases=0;
- struct getargs args[] = {
- { "records", 0, arg_integer, &g_rows, "Number of records", "records" },
- { "operations", 'o', arg_string, &ops, "Operations [a-h]", 0 },
- { "1", '1', arg_flag, &g_one_op_at_a_time, "One op at a time", 0 },
- { "0", '0', arg_negative_flag, &g_one_op_at_a_time, "All ops at once", 0 },
- { "cases", 'c', arg_string, &cases, "Cases [a-c]", 0 },
- { 0, 't', arg_flag, &g_setup_tables, "Create table", 0 },
- { 0, 'u', arg_negative_flag, &g_setup_tables, "Dont create table", 0 }
- };
-
- int optind= 0;
- const int num_args = sizeof(args)/sizeof(args[0]);
- if(getarg(args, num_args, argc, (const char**)argv, &optind)) {
- arg_printusage(args, num_args, argv[0], " tabname1\n");
- ndbout_c("\n -- Operations [a-%c] = ", 'a'+OP_COUNT-1);
- for(i = 0; i<OP_COUNT; i++){
- ndbout_c("\t%c = %s %s",
- 'a'+i, g_op_types[i].op1,
- g_op_types[i].op2 ? g_op_types[i].op2 : "");
- }
- return -1;
- }
-
- if(ops != 0){
- g_use_ops = 0;
- char * s = ops;
- while(* s)
- g_use_ops |= (1 << ((* s++) - 'a'));
- }
-
- if(cases != 0){
- g_cases = 0;
- char * s = cases;
- while(* s)
- g_cases |= (1 << ((* s++) - 'a'));
- }
-
- ndbout_c("table: %s", g_tablename);
- printf("operations: ");
- for(i = 0; i<OP_COUNT; i++)
- if(g_use_ops & (1 << i))
- printf("%c", 'a'+i);
- printf("\n");
-
- printf("test cases: ");
- for(i = 0; i<3; i++)
- if(g_cases & (1 << i))
- printf("%c", '1'+i);
- printf("\n");
- printf("-------------\n");
- return 0;
-}
-
-static int connect_ndb()
-{
- g_cluster_connection = new Ndb_cluster_connection();
- if(g_cluster_connection->connect(12, 5, 1) != 0)
- {
- return 1;
- }
-
- g_ndb = new Ndb(g_cluster_connection, "TEST_DB");
- g_ndb->init(256);
- if(g_ndb->waitUntilReady(30) == 0){
- return 0;
-// int args[] = { DumpStateOrd::DihMaxTimeBetweenLCP };
-// return g_restarter.dumpStateAllNodes(args, 1);
- }
- return -1;
-}
-
-static int disconnect_ndb()
-{
- delete g_ndb;
- delete g_cluster_connection;
- g_ndb = 0;
- g_table = 0;
- g_cluster_connection= 0;
- return 0;
-}
-
-static int drop_all_tables()
-{
- NdbDictionary::Dictionary * dict = g_ndb->getDictionary();
- require(dict);
-
- BaseString db = g_ndb->getDatabaseName();
- BaseString schema = g_ndb->getSchemaName();
-
- NdbDictionary::Dictionary::List list;
- if (dict->listObjects(list, NdbDictionary::Object::TypeUndefined) == -1){
- g_err << "Failed to list tables: " << endl
- << dict->getNdbError() << endl;
- return -1;
- }
- for (unsigned i = 0; i < list.count; i++) {
- NdbDictionary::Dictionary::List::Element& elt = list.elements[i];
- switch (elt.type) {
- case NdbDictionary::Object::SystemTable:
- case NdbDictionary::Object::UserTable:
- g_ndb->setDatabaseName(elt.database);
- g_ndb->setSchemaName(elt.schema);
- if(dict->dropTable(elt.name) != 0){
- g_err << "Failed to drop table: "
- << elt.database << "/" << elt.schema << "/" << elt.name <<endl;
- g_err << dict->getNdbError() << endl;
- return -1;
- }
- break;
- case NdbDictionary::Object::UniqueHashIndex:
- case NdbDictionary::Object::OrderedIndex:
- case NdbDictionary::Object::HashIndexTrigger:
- case NdbDictionary::Object::IndexTrigger:
- case NdbDictionary::Object::SubscriptionTrigger:
- case NdbDictionary::Object::ReadOnlyConstraint:
- default:
- break;
- }
- }
-
- g_ndb->setDatabaseName(db.c_str());
- g_ndb->setSchemaName(schema.c_str());
-
- return 0;
-}
-
-static int load_table()
-{
- UtilTransactions clear(* g_table);
- require(!clear.clearTable(g_ndb));
-
- HugoOperations ops(* g_table);
- require(!ops.startTransaction(g_ndb));
- size_t op = 0;
- size_t rows = 0;
- size_t uncommitted = 0;
- bool prepared = false;
- for(size_t i = 0; i<g_rows; i++){
- for(op %= OP_COUNT; !((1 << op) & g_use_ops); op = (op + 1) % OP_COUNT);
- g_ops[i] = g_op_types[op++];
- if(g_ops[i].start_row){
- g_ops[i].curr_row = true;
- g_ops[i].val = rand();
- require(!ops.pkInsertRecord(g_ndb, i, 1, g_ops[i].val));
- uncommitted++;
- } else {
- g_ops[i].curr_row = false;
- }
- if(uncommitted >= 100){
- require(!ops.execute_Commit(g_ndb));
- require(!ops.getTransaction()->restart());
- rows += uncommitted;
- uncommitted = 0;
- }
- }
- if(uncommitted)
- require(!ops.execute_Commit(g_ndb));
-
- require(!ops.closeTransaction(g_ndb));
- rows += uncommitted;
- g_info << "Inserted " << rows << " rows" << endl;
- return 0;
-}
-
-static int pause_lcp(int error)
-{
- int nodes = g_restarter.getNumDbNodes();
-
- int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_INFO, 0 };
- int fd = ndb_mgm_listen_event(g_restarter.handle, filter);
- require(fd >= 0);
- require(!g_restarter.insertErrorInAllNodes(error));
- int dump[] = { DumpStateOrd::DihStartLcpImmediately };
- require(!g_restarter.dumpStateAllNodes(dump, 1));
-
- char *tmp;
- char buf[1024];
- SocketInputStream in(fd, 1000);
- int count = 0;
- do {
- tmp = in.gets(buf, 1024);
- if(tmp)
- {
- int id;
- if(sscanf(tmp, "%*[^:]: LCP: %d ", &id) == 1 && id == error &&
- --nodes == 0){
- close(fd);
- return 0;
- }
- }
- } while(count++ < 30);
-
- close(fd);
- return -1;
-}
-
-static int do_op(int row)
-{
- HugoOperations & ops = * g_hugo_ops;
- if(strcmp(g_ops[row].op1, "INS") == 0){
- require(!g_ops[row].curr_row);
- g_ops[row].curr_row = true;
- g_ops[row].val = rand();
- require(!ops.pkInsertRecord(g_ndb, row, 1, g_ops[row].val));
- } else if(strcmp(g_ops[row].op1, "UPD") == 0){
- require(g_ops[row].curr_row);
- g_ops[row].val = rand();
- require(!ops.pkUpdateRecord(g_ndb, row, 1, g_ops[row].val));
- } else if(strcmp(g_ops[row].op1, "DEL") == 0){
- require(g_ops[row].curr_row);
- g_ops[row].curr_row = false;
- require(!ops.pkDeleteRecord(g_ndb, row, 1));
- }
-
- require(!ops.execute_NoCommit(g_ndb));
-
- if(g_ops[row].op2 == 0){
- } else if(strcmp(g_ops[row].op2, "INS") == 0){
- require(!g_ops[row].curr_row);
- g_ops[row].curr_row = true;
- g_ops[row].val = rand();
- require(!ops.pkInsertRecord(g_ndb, row, 1, g_ops[row].val));
- } else if(strcmp(g_ops[row].op2, "UPD") == 0){
- require(g_ops[row].curr_row);
- g_ops[row].val = rand();
- require(!ops.pkUpdateRecord(g_ndb, row, 1, g_ops[row].val));
- } else if(strcmp(g_ops[row].op2, "DEL") == 0){
- require(g_ops[row].curr_row);
- g_ops[row].curr_row = false;
- require(!ops.pkDeleteRecord(g_ndb, row, 1));
- }
-
- if(g_ops[row].op2 != 0)
- require(!ops.execute_NoCommit(g_ndb));
-
- if(g_ops[row].op3 == 0){
- } else if(strcmp(g_ops[row].op3, "INS") == 0){
- require(!g_ops[row].curr_row);
- g_ops[row].curr_row = true;
- g_ops[row].val = rand();
- require(!ops.pkInsertRecord(g_ndb, row, 1, g_ops[row].val));
- } else if(strcmp(g_ops[row].op3, "UPD") == 0){
- require(g_ops[row].curr_row);
- g_ops[row].val = rand();
- require(!ops.pkUpdateRecord(g_ndb, row, 1, g_ops[row].val));
- } else if(strcmp(g_ops[row].op3, "DEL") == 0){
- require(g_ops[row].curr_row);
- g_ops[row].curr_row = false;
- require(!ops.pkDeleteRecord(g_ndb, row, 1));
- }
-
- if(g_ops[row].op3 != 0)
- require(!ops.execute_NoCommit(g_ndb));
-
- return 0;
-}
-
-static int continue_lcp(int error)
-{
- int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_INFO, 0 };
- int fd = -1;
- if(error){
- fd = ndb_mgm_listen_event(g_restarter.handle, filter);
- require(fd >= 0);
- }
-
- int args[] = { DumpStateOrd::LCPContinue };
- if(g_restarter.dumpStateAllNodes(args, 1) != 0)
- return -1;
-
- if(error){
- char *tmp;
- char buf[1024];
- SocketInputStream in(fd, 1000);
- int count = 0;
- int nodes = g_restarter.getNumDbNodes();
- do {
- tmp = in.gets(buf, 1024);
- if(tmp)
- {
- int id;
- if(sscanf(tmp, "%*[^:]: LCP: %d ", &id) == 1 && id == error &&
- --nodes == 0){
- close(fd);
- return 0;
- }
- }
- } while(count++ < 30);
-
- close(fd);
- }
- return 0;
-}
-
-static int commit()
-{
- HugoOperations & ops = * g_hugo_ops;
- int res = ops.execute_Commit(g_ndb);
- if(res == 0){
- return ops.getTransaction()->restart();
- }
- return res;
-}
-
-static int restart()
-{
- g_info << "Restarting cluster" << endl;
- g_hugo_ops->closeTransaction(g_ndb);
- disconnect_ndb();
- delete g_hugo_ops;
-
- require(!g_restarter.restartAll());
- require(!g_restarter.waitClusterStarted(30));
- require(!connect_ndb());
-
- g_table = g_ndb->getDictionary()->getTable(g_tablename);
- require(g_table);
- require(g_hugo_ops = new HugoOperations(* g_table));
- require(!g_hugo_ops->startTransaction(g_ndb));
- return 0;
-}
-
-static int validate()
-{
- HugoOperations ops(* g_table);
- for(size_t i = 0; i<g_rows; i++){
- require(g_ops[i].curr_row == g_ops[i].end_row);
- require(!ops.startTransaction(g_ndb));
- ops.pkReadRecord(g_ndb, i, 1);
- int res = ops.execute_Commit(g_ndb);
- if(g_ops[i].curr_row){
- require(res == 0 && ops.verifyUpdatesValue(g_ops[i].val) == 0);
- } else {
- require(res == 626);
- }
- ops.closeTransaction(g_ndb);
- }
-
- for(size_t j = 0; j<10; j++){
- UtilTransactions clear(* g_table);
- require(!clear.clearTable(g_ndb));
-
- HugoTransactions trans(* g_table);
- require(trans.loadTable(g_ndb, 1024) == 0);
- }
- return 0;
-}
-
diff --git a/storage/ndb/test/ndbapi/testMgm.cpp b/storage/ndb/test/ndbapi/testMgm.cpp
deleted file mode 100644
index 5b34a4d252e..00000000000
--- a/storage/ndb/test/ndbapi/testMgm.cpp
+++ /dev/null
@@ -1,839 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT.hpp>
-#include <NDBT_Test.hpp>
-#include <HugoTransactions.hpp>
-#include <UtilTransactions.hpp>
-#include <NdbRestarter.hpp>
-#include <Vector.hpp>
-#include <random.h>
-#include <mgmapi.h>
-#include <mgmapi_debug.h>
-#include <ndb_logevent.h>
-#include <InputStream.hpp>
-#include <signaldata/EventReport.hpp>
-
-int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
-
- int records = ctx->getNumRecords();
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.loadTable(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
-
- UtilTransactions utilTrans(*ctx->getTab());
- if (utilTrans.clearTable2(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-
-int create_index_on_pk(Ndb* pNdb, const char* tabName){
- int result = NDBT_OK;
-
- const NdbDictionary::Table * tab = NDBT_Table::discoverTableFromDb(pNdb,
- tabName);
-
- // Create index
- const char* idxName = "IDX_ON_PK";
- ndbout << "Create: " <<idxName << "( ";
- NdbDictionary::Index pIdx(idxName);
- pIdx.setTable(tabName);
- pIdx.setType(NdbDictionary::Index::UniqueHashIndex);
- for (int c = 0; c< tab->getNoOfPrimaryKeys(); c++){
- pIdx.addIndexColumn(tab->getPrimaryKey(c));
- ndbout << tab->getPrimaryKey(c)<<" ";
- }
-
- ndbout << ") ";
- if (pNdb->getDictionary()->createIndex(pIdx) != 0){
- ndbout << "FAILED!" << endl;
- const NdbError err = pNdb->getDictionary()->getNdbError();
- ERR(err);
- result = NDBT_FAILED;
- } else {
- ndbout << "OK!" << endl;
- }
- return result;
-}
-
-int drop_index_on_pk(Ndb* pNdb, const char* tabName){
- int result = NDBT_OK;
- const char* idxName = "IDX_ON_PK";
- ndbout << "Drop: " << idxName;
- if (pNdb->getDictionary()->dropIndex(idxName, tabName) != 0){
- ndbout << "FAILED!" << endl;
- const NdbError err = pNdb->getDictionary()->getNdbError();
- ERR(err);
- result = NDBT_FAILED;
- } else {
- ndbout << "OK!" << endl;
- }
- return result;
-}
-
-
-#define CHECK(b) if (!(b)) { \
- g_err << "ERR: "<< step->getName() \
- << " failed on line " << __LINE__ << endl; \
- result = NDBT_FAILED; \
- continue; }
-
-int runTestSingleUserMode(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- Ndb* pNdb = GETNDB(step);
- NdbRestarter restarter;
- char tabName[255];
- strncpy(tabName, ctx->getTab()->getName(), 255);
- ndbout << "tabName="<<tabName<<endl;
-
- int i = 0;
- int count;
- HugoTransactions hugoTrans(*ctx->getTab());
- UtilTransactions utilTrans(*ctx->getTab());
- while (i<loops && result == NDBT_OK) {
- g_info << i << ": ";
- int timeout = 120;
- // Test that the single user mode api can do everything
- CHECK(restarter.enterSingleUserMode(pNdb->getNodeId()) == 0);
- CHECK(restarter.waitClusterSingleUser(timeout) == 0);
- CHECK(hugoTrans.loadTable(pNdb, records, 128) == 0);
- CHECK(hugoTrans.pkReadRecords(pNdb, records) == 0);
- CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == records);
- CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);
- CHECK(hugoTrans.scanReadRecords(pNdb, records/2, 0, 64) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == (records/2));
- CHECK(utilTrans.clearTable(pNdb, records/2) == 0);
- CHECK(restarter.exitSingleUserMode() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
-
- // Test create index in single user mode
- CHECK(restarter.enterSingleUserMode(pNdb->getNodeId()) == 0);
- CHECK(restarter.waitClusterSingleUser(timeout) == 0);
- CHECK(create_index_on_pk(pNdb, tabName) == 0);
- CHECK(hugoTrans.loadTable(pNdb, records, 128) == 0);
- CHECK(hugoTrans.pkReadRecords(pNdb, records) == 0);
- CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == records);
- CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);
- CHECK(drop_index_on_pk(pNdb, tabName) == 0);
- CHECK(restarter.exitSingleUserMode() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
-
- // Test recreate index in single user mode
- CHECK(create_index_on_pk(pNdb, tabName) == 0);
- CHECK(hugoTrans.loadTable(pNdb, records, 128) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(restarter.enterSingleUserMode(pNdb->getNodeId()) == 0);
- CHECK(restarter.waitClusterSingleUser(timeout) == 0);
- CHECK(drop_index_on_pk(pNdb, tabName) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(create_index_on_pk(pNdb, tabName) == 0);
- CHECK(restarter.exitSingleUserMode() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(drop_index_on_pk(pNdb, tabName) == 0);
-
- CHECK(utilTrans.clearTable(GETNDB(step), records) == 0);
-
- ndbout << "Restarting cluster" << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- i++;
-
- }
- return result;
-}
-
-int runTestApiSession(NDBT_Context* ctx, NDBT_Step* step)
-{
- char *mgm= ctx->getRemoteMgm();
- Uint64 session_id= 0;
-
- NdbMgmHandle h;
- h= ndb_mgm_create_handle();
- ndb_mgm_set_connectstring(h, mgm);
- ndb_mgm_connect(h,0,0,0);
- int s= ndb_mgm_get_fd(h);
- session_id= ndb_mgm_get_session_id(h);
- ndbout << "MGM Session id: " << session_id << endl;
- write(s,"get",3);
- ndb_mgm_disconnect(h);
- ndb_mgm_destroy_handle(&h);
-
- struct NdbMgmSession sess;
- int slen= sizeof(struct NdbMgmSession);
-
- h= ndb_mgm_create_handle();
- ndb_mgm_set_connectstring(h, mgm);
- ndb_mgm_connect(h,0,0,0);
-
- NdbSleep_SecSleep(1);
-
- if(ndb_mgm_get_session(h,session_id,&sess,&slen))
- {
- ndbout << "Failed, session still exists" << endl;
- ndb_mgm_disconnect(h);
- ndb_mgm_destroy_handle(&h);
- return NDBT_FAILED;
- }
- else
- {
- ndbout << "SUCCESS: session is gone" << endl;
- ndb_mgm_disconnect(h);
- ndb_mgm_destroy_handle(&h);
- return NDBT_OK;
- }
-}
-
-int runTestApiConnectTimeout(NDBT_Context* ctx, NDBT_Step* step)
-{
- char *mgm= ctx->getRemoteMgm();
- int result= NDBT_FAILED;
- int cc= 0;
- int mgmd_nodeid= 0;
- ndb_mgm_reply reply;
-
- NdbMgmHandle h;
- h= ndb_mgm_create_handle();
- ndb_mgm_set_connectstring(h, mgm);
-
- ndbout << "TEST connect timeout" << endl;
-
- ndb_mgm_set_timeout(h, 3000);
-
- struct timeval tstart, tend;
- int secs;
- timerclear(&tstart);
- timerclear(&tend);
- gettimeofday(&tstart,NULL);
-
- ndb_mgm_connect(h,0,0,0);
-
- gettimeofday(&tend,NULL);
-
- secs= tend.tv_sec - tstart.tv_sec;
- ndbout << "Took about: " << secs <<" seconds"<<endl;
-
- if(secs < 4)
- result= NDBT_OK;
- else
- goto done;
-
- ndb_mgm_set_connectstring(h, mgm);
-
- ndbout << "TEST connect timeout" << endl;
-
- ndb_mgm_destroy_handle(&h);
-
- h= ndb_mgm_create_handle();
- ndb_mgm_set_connectstring(h, "1.1.1.1");
-
- ndbout << "TEST connect timeout (invalid host)" << endl;
-
- ndb_mgm_set_timeout(h, 3000);
-
- timerclear(&tstart);
- timerclear(&tend);
- gettimeofday(&tstart,NULL);
-
- ndb_mgm_connect(h,0,0,0);
-
- gettimeofday(&tend,NULL);
-
- secs= tend.tv_sec - tstart.tv_sec;
- ndbout << "Took about: " << secs <<" seconds"<<endl;
-
- if(secs < 4)
- result= NDBT_OK;
- else
- result= NDBT_FAILED;
-
-done:
- ndb_mgm_disconnect(h);
- ndb_mgm_destroy_handle(&h);
-
- return result;
-}
-
-int runTestApiTimeoutBasic(NDBT_Context* ctx, NDBT_Step* step)
-{
- char *mgm= ctx->getRemoteMgm();
- int result= NDBT_FAILED;
- int cc= 0;
- int mgmd_nodeid= 0;
- ndb_mgm_reply reply;
-
- NdbMgmHandle h;
- h= ndb_mgm_create_handle();
- ndb_mgm_set_connectstring(h, mgm);
-
- ndbout << "TEST timout check_connection" << endl;
- int errs[] = { 1, 2, 3, -1};
-
- for(int error_ins_no=0; errs[error_ins_no]!=-1; error_ins_no++)
- {
- int error_ins= errs[error_ins_no];
- ndbout << "trying error " << error_ins << endl;
- ndb_mgm_connect(h,0,0,0);
-
- if(ndb_mgm_check_connection(h) < 0)
- {
- result= NDBT_FAILED;
- goto done;
- }
-
- mgmd_nodeid= ndb_mgm_get_mgmd_nodeid(h);
- if(mgmd_nodeid==0)
- {
- ndbout << "Failed to get mgmd node id to insert error" << endl;
- result= NDBT_FAILED;
- goto done;
- }
-
- reply.return_code= 0;
-
- if(ndb_mgm_insert_error(h, mgmd_nodeid, error_ins, &reply)< 0)
- {
- ndbout << "failed to insert error " << endl;
- result= NDBT_FAILED;
- goto done;
- }
-
- ndb_mgm_set_timeout(h,2500);
-
- cc= ndb_mgm_check_connection(h);
- if(cc < 0)
- result= NDBT_OK;
- else
- result= NDBT_FAILED;
-
- if(ndb_mgm_is_connected(h))
- {
- ndbout << "FAILED: still connected" << endl;
- result= NDBT_FAILED;
- }
- }
-
- ndbout << "TEST get_mgmd_nodeid" << endl;
- ndb_mgm_connect(h,0,0,0);
-
- if(ndb_mgm_insert_error(h, mgmd_nodeid, 0, &reply)< 0)
- {
- ndbout << "failed to remove inserted error " << endl;
- result= NDBT_FAILED;
- goto done;
- }
-
- cc= ndb_mgm_get_mgmd_nodeid(h);
- ndbout << "got node id: " << cc << endl;
- if(cc==0)
- {
- ndbout << "FAILED: didn't get node id" << endl;
- result= NDBT_FAILED;
- }
- else
- result= NDBT_OK;
-
- ndbout << "TEST end_session" << endl;
- ndb_mgm_connect(h,0,0,0);
-
- if(ndb_mgm_insert_error(h, mgmd_nodeid, 4, &reply)< 0)
- {
- ndbout << "FAILED: insert error 1" << endl;
- result= NDBT_FAILED;
- goto done;
- }
-
- cc= ndb_mgm_end_session(h);
- if(cc==0)
- {
- ndbout << "FAILED: success in calling end_session" << endl;
- result= NDBT_FAILED;
- }
- else if(ndb_mgm_get_latest_error(h)!=ETIMEDOUT)
- {
- ndbout << "FAILED: Incorrect error code (" << ndb_mgm_get_latest_error(h)
- << " != expected " << ETIMEDOUT << ") desc: "
- << ndb_mgm_get_latest_error_desc(h)
- << " line: " << ndb_mgm_get_latest_error_line(h)
- << " msg: " << ndb_mgm_get_latest_error_msg(h)
- << endl;
- result= NDBT_FAILED;
- }
- else
- result= NDBT_OK;
-
- if(ndb_mgm_is_connected(h))
- {
- ndbout << "FAILED: is still connected after error" << endl;
- result= NDBT_FAILED;
- }
-done:
- ndb_mgm_disconnect(h);
- ndb_mgm_destroy_handle(&h);
-
- return result;
-}
-
-int runTestApiGetStatusTimeout(NDBT_Context* ctx, NDBT_Step* step)
-{
- char *mgm= ctx->getRemoteMgm();
- int result= NDBT_OK;
- int cc= 0;
- int mgmd_nodeid= 0;
-
- NdbMgmHandle h;
- h= ndb_mgm_create_handle();
- ndb_mgm_set_connectstring(h, mgm);
-
- int errs[] = { 0, 5, 6, 7, 8, 9, -1 };
-
- for(int error_ins_no=0; errs[error_ins_no]!=-1; error_ins_no++)
- {
- int error_ins= errs[error_ins_no];
- ndb_mgm_connect(h,0,0,0);
-
- if(ndb_mgm_check_connection(h) < 0)
- {
- result= NDBT_FAILED;
- goto done;
- }
-
- mgmd_nodeid= ndb_mgm_get_mgmd_nodeid(h);
- if(mgmd_nodeid==0)
- {
- ndbout << "Failed to get mgmd node id to insert error" << endl;
- result= NDBT_FAILED;
- goto done;
- }
-
- ndb_mgm_reply reply;
- reply.return_code= 0;
-
- if(ndb_mgm_insert_error(h, mgmd_nodeid, error_ins, &reply)< 0)
- {
- ndbout << "failed to insert error " << error_ins << endl;
- result= NDBT_FAILED;
- }
-
- ndbout << "trying error: " << error_ins << endl;
-
- ndb_mgm_set_timeout(h,2500);
-
- struct ndb_mgm_cluster_state *cl= ndb_mgm_get_status(h);
-
- if(cl!=NULL)
- free(cl);
-
- /*
- * For whatever strange reason,
- * get_status is okay with not having the last enter there.
- * instead of "fixing" the api, let's have a special case
- * so we don't break any behaviour
- */
-
- if(error_ins!=0 && error_ins!=9 && cl!=NULL)
- {
- ndbout << "FAILED: got a ndb_mgm_cluster_state back" << endl;
- result= NDBT_FAILED;
- }
-
- if(error_ins!=0 && error_ins!=9 && ndb_mgm_is_connected(h))
- {
- ndbout << "FAILED: is still connected after error" << endl;
- result= NDBT_FAILED;
- }
-
- if(error_ins!=0 && error_ins!=9 && ndb_mgm_get_latest_error(h)!=ETIMEDOUT)
- {
- ndbout << "FAILED: Incorrect error code (" << ndb_mgm_get_latest_error(h)
- << " != expected " << ETIMEDOUT << ") desc: "
- << ndb_mgm_get_latest_error_desc(h)
- << " line: " << ndb_mgm_get_latest_error_line(h)
- << " msg: " << ndb_mgm_get_latest_error_msg(h)
- << endl;
- result= NDBT_FAILED;
- }
- }
-
-done:
- ndb_mgm_disconnect(h);
- ndb_mgm_destroy_handle(&h);
-
- return result;
-}
-
-int runTestMgmApiGetConfigTimeout(NDBT_Context* ctx, NDBT_Step* step)
-{
- char *mgm= ctx->getRemoteMgm();
- int result= NDBT_OK;
- int mgmd_nodeid= 0;
-
- NdbMgmHandle h;
- h= ndb_mgm_create_handle();
- ndb_mgm_set_connectstring(h, mgm);
-
- int errs[] = { 0, 1, 2, 3, -1 };
-
- for(int error_ins_no=0; errs[error_ins_no]!=-1; error_ins_no++)
- {
- int error_ins= errs[error_ins_no];
- ndb_mgm_connect(h,0,0,0);
-
- if(ndb_mgm_check_connection(h) < 0)
- {
- result= NDBT_FAILED;
- goto done;
- }
-
- mgmd_nodeid= ndb_mgm_get_mgmd_nodeid(h);
- if(mgmd_nodeid==0)
- {
- ndbout << "Failed to get mgmd node id to insert error" << endl;
- result= NDBT_FAILED;
- goto done;
- }
-
- ndb_mgm_reply reply;
- reply.return_code= 0;
-
- if(ndb_mgm_insert_error(h, mgmd_nodeid, error_ins, &reply)< 0)
- {
- ndbout << "failed to insert error " << error_ins << endl;
- result= NDBT_FAILED;
- }
-
- ndbout << "trying error: " << error_ins << endl;
-
- ndb_mgm_set_timeout(h,2500);
-
- struct ndb_mgm_configuration *c= ndb_mgm_get_configuration(h,0);
-
- if(c!=NULL)
- free(c);
-
- if(error_ins!=0 && c!=NULL)
- {
- ndbout << "FAILED: got a ndb_mgm_configuration back" << endl;
- result= NDBT_FAILED;
- }
-
- if(error_ins!=0 && ndb_mgm_is_connected(h))
- {
- ndbout << "FAILED: is still connected after error" << endl;
- result= NDBT_FAILED;
- }
-
- if(error_ins!=0 && ndb_mgm_get_latest_error(h)!=ETIMEDOUT)
- {
- ndbout << "FAILED: Incorrect error code (" << ndb_mgm_get_latest_error(h)
- << " != expected " << ETIMEDOUT << ") desc: "
- << ndb_mgm_get_latest_error_desc(h)
- << " line: " << ndb_mgm_get_latest_error_line(h)
- << " msg: " << ndb_mgm_get_latest_error_msg(h)
- << endl;
- result= NDBT_FAILED;
- }
- }
-
-done:
- ndb_mgm_disconnect(h);
- ndb_mgm_destroy_handle(&h);
-
- return result;
-}
-
-int runTestMgmApiEventTimeout(NDBT_Context* ctx, NDBT_Step* step)
-{
- char *mgm= ctx->getRemoteMgm();
- int result= NDBT_OK;
- int mgmd_nodeid= 0;
-
- NdbMgmHandle h;
- h= ndb_mgm_create_handle();
- ndb_mgm_set_connectstring(h, mgm);
-
- int errs[] = { 10000, 0, -1 };
-
- for(int error_ins_no=0; errs[error_ins_no]!=-1; error_ins_no++)
- {
- int error_ins= errs[error_ins_no];
- ndb_mgm_connect(h,0,0,0);
-
- if(ndb_mgm_check_connection(h) < 0)
- {
- result= NDBT_FAILED;
- goto done;
- }
-
- mgmd_nodeid= ndb_mgm_get_mgmd_nodeid(h);
- if(mgmd_nodeid==0)
- {
- ndbout << "Failed to get mgmd node id to insert error" << endl;
- result= NDBT_FAILED;
- goto done;
- }
-
- ndb_mgm_reply reply;
- reply.return_code= 0;
-
- if(ndb_mgm_insert_error(h, mgmd_nodeid, error_ins, &reply)< 0)
- {
- ndbout << "failed to insert error " << error_ins << endl;
- result= NDBT_FAILED;
- }
-
- ndbout << "trying error: " << error_ins << endl;
-
- ndb_mgm_set_timeout(h,2500);
-
- int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_BACKUP,
- 1, NDB_MGM_EVENT_CATEGORY_STARTUP,
- 0 };
- int fd= ndb_mgm_listen_event(h, filter);
-
- if(fd==NDB_INVALID_SOCKET)
- {
- ndbout << "FAILED: could not listen to event" << endl;
- result= NDBT_FAILED;
- }
-
- Uint32 theData[25];
- EventReport *fake_event = (EventReport*)theData;
- fake_event->setEventType(NDB_LE_NDBStopForced);
- fake_event->setNodeId(42);
- theData[2]= 0;
- theData[3]= 0;
- theData[4]= 0;
- theData[5]= 0;
-
- ndb_mgm_report_event(h, theData, 6);
-
- char *tmp= 0;
- char buf[512];
- SocketInputStream in(fd,2000);
- for(int i=0; i<20; i++)
- {
- if((tmp = in.gets(buf, sizeof(buf))))
- {
-// const char ping_token[]="<PING>";
-// if(memcmp(ping_token,tmp,sizeof(ping_token)-1))
- if(tmp && strlen(tmp))
- ndbout << tmp;
- }
- else
- {
- if(in.timedout())
- {
- ndbout << "TIMED OUT READING EVENT at iteration " << i << endl;
- break;
- }
- }
- }
-
- /*
- * events go through a *DIFFERENT* socket than the NdbMgmHandle
- * so we should still be connected (and be able to check_connection)
- *
- */
-
- if(ndb_mgm_check_connection(h) && !ndb_mgm_is_connected(h))
- {
- ndbout << "FAILED: is still connected after error" << endl;
- result= NDBT_FAILED;
- }
-
- ndb_mgm_disconnect(h);
- }
-
-done:
- ndb_mgm_disconnect(h);
- ndb_mgm_destroy_handle(&h);
-
- return result;
-}
-
-int runTestMgmApiStructEventTimeout(NDBT_Context* ctx, NDBT_Step* step)
-{
- char *mgm= ctx->getRemoteMgm();
- int result= NDBT_OK;
- int mgmd_nodeid= 0;
-
- NdbMgmHandle h;
- h= ndb_mgm_create_handle();
- ndb_mgm_set_connectstring(h, mgm);
-
- int errs[] = { 10000, 0, -1 };
-
- for(int error_ins_no=0; errs[error_ins_no]!=-1; error_ins_no++)
- {
- int error_ins= errs[error_ins_no];
- ndb_mgm_connect(h,0,0,0);
-
- if(ndb_mgm_check_connection(h) < 0)
- {
- result= NDBT_FAILED;
- goto done;
- }
-
- mgmd_nodeid= ndb_mgm_get_mgmd_nodeid(h);
- if(mgmd_nodeid==0)
- {
- ndbout << "Failed to get mgmd node id to insert error" << endl;
- result= NDBT_FAILED;
- goto done;
- }
-
- ndb_mgm_reply reply;
- reply.return_code= 0;
-
- if(ndb_mgm_insert_error(h, mgmd_nodeid, error_ins, &reply)< 0)
- {
- ndbout << "failed to insert error " << error_ins << endl;
- result= NDBT_FAILED;
- }
-
- ndbout << "trying error: " << error_ins << endl;
-
- ndb_mgm_set_timeout(h,2500);
-
- int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_BACKUP,
- 1, NDB_MGM_EVENT_CATEGORY_STARTUP,
- 0 };
- NdbLogEventHandle le_handle= ndb_mgm_create_logevent_handle(h, filter);
-
- struct ndb_logevent le;
- for(int i=0; i<20; i++)
- {
- if(error_ins==0 || (error_ins!=0 && i<5))
- {
- Uint32 theData[25];
- EventReport *fake_event = (EventReport*)theData;
- fake_event->setEventType(NDB_LE_NDBStopForced);
- fake_event->setNodeId(42);
- theData[2]= 0;
- theData[3]= 0;
- theData[4]= 0;
- theData[5]= 0;
-
- ndb_mgm_report_event(h, theData, 6);
- }
- int r= ndb_logevent_get_next(le_handle, &le, 2500);
- if(r>0)
- {
- ndbout << "Receieved event" << endl;
- }
- else if(r<0)
- {
- ndbout << "ERROR" << endl;
- }
- else // no event
- {
- ndbout << "TIMED OUT READING EVENT at iteration " << i << endl;
- if(error_ins==0)
- result= NDBT_FAILED;
- else
- result= NDBT_OK;
- break;
- }
- }
-
- /*
- * events go through a *DIFFERENT* socket than the NdbMgmHandle
- * so we should still be connected (and be able to check_connection)
- *
- */
-
- if(ndb_mgm_check_connection(h) && !ndb_mgm_is_connected(h))
- {
- ndbout << "FAILED: is still connected after error" << endl;
- result= NDBT_FAILED;
- }
-
- ndb_mgm_disconnect(h);
- }
-
-done:
- ndb_mgm_disconnect(h);
- ndb_mgm_destroy_handle(&h);
-
- return result;
-}
-
-NDBT_TESTSUITE(testMgm);
-TESTCASE("SingleUserMode",
- "Test single user mode"){
- INITIALIZER(runTestSingleUserMode);
- FINALIZER(runClearTable);
-}
-TESTCASE("ApiSessionFailure",
- "Test failures in MGMAPI session"){
- INITIALIZER(runTestApiSession);
-
-}
-TESTCASE("ApiConnectTimeout",
- "Connect timeout tests for MGMAPI"){
- INITIALIZER(runTestApiConnectTimeout);
-
-}
-TESTCASE("ApiTimeoutBasic",
- "Basic timeout tests for MGMAPI"){
- INITIALIZER(runTestApiTimeoutBasic);
-
-}
-TESTCASE("ApiGetStatusTimeout",
- "Test timeout for MGMAPI getStatus"){
- INITIALIZER(runTestApiGetStatusTimeout);
-
-}
-TESTCASE("ApiGetConfigTimeout",
- "Test timeouts for mgmapi get_configuration"){
- INITIALIZER(runTestMgmApiGetConfigTimeout);
-
-}
-TESTCASE("ApiMgmEventTimeout",
- "Test timeouts for mgmapi get_configuration"){
- INITIALIZER(runTestMgmApiEventTimeout);
-
-}
-TESTCASE("ApiMgmStructEventTimeout",
- "Test timeouts for mgmapi get_configuration"){
- INITIALIZER(runTestMgmApiStructEventTimeout);
-
-}
-NDBT_TESTSUITE_END(testMgm);
-
-int main(int argc, const char** argv){
- ndb_init();
- myRandom48Init(NdbTick_CurrentMillisecond());
- return testMgm.execute(argc, argv);
-}
-
diff --git a/storage/ndb/test/ndbapi/testNDBT.cpp b/storage/ndb/test/ndbapi/testNDBT.cpp
deleted file mode 100644
index 170eb4f87d7..00000000000
--- a/storage/ndb/test/ndbapi/testNDBT.cpp
+++ /dev/null
@@ -1,174 +0,0 @@
-/* Copyright (c) 2003, 2008 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT.hpp>
-#include <NDBT_Test.hpp>
-#include <DbUtil.hpp>
-#include <AtrtClient.hpp>
-
-
-int runTestAtrtClient(NDBT_Context* ctx, NDBT_Step* step){
- AtrtClient atrt;
-
- SqlResultSet clusters;
- if (!atrt.getClusters(clusters))
- return NDBT_FAILED;
-
- int i= 0;
- while(clusters.next())
- {
- ndbout << clusters.column("name") << endl;
- if (i++ == 1){
- ndbout << "removing: " << clusters.column("name") << endl;
- clusters.remove();
- }
- }
-
- clusters.reset();
- while(clusters.next())
- {
- ndbout << clusters.column("name") << endl;
- }
-
- return NDBT_OK;
-}
-
-
-int runTestDbUtil(NDBT_Context* ctx, NDBT_Step* step){
- DbUtil sql;
-
- {
- // Select all rows from mysql.user
- SqlResultSet result;
- if (!sql.doQuery("SELECT * FROM mysql.user", result))
- return NDBT_FAILED;
- // result.print();
-
- while(result.next())
- {
- ndbout << result.column("host") << ", "
- << result.column("uSer") << ", "
- << result.columnAsInt("max_updates") << ", "
- << endl;
- }
-
- result.reset();
- while(result.next())
- {
- ndbout << result.column("host") << endl;
- }
- }
-
- {
- // No column name, query should fail
- Properties args;
- SqlResultSet result;
- if (sql.doQuery("SELECT * FROM mysql.user WHERE name=?", args, result))
- return NDBT_FAILED;
- result.print();
- }
-
- {
- // Select nonexisiting rows from mysql.user
- Properties args;
- SqlResultSet result;
- args.put("0", "no_such_host");
- if (!sql.doQuery("SELECT * FROM mysql.user WHERE host=?", args, result))
- return NDBT_FAILED;
- ndbout << "no rows" << endl;
- result.print();
-
- // Change args to an find one row
- args.clear();
- args.put("0", "localhost");
- if (!sql.doQuery("SELECT host, user FROM mysql.user WHERE host=?",
- args, result))
- return NDBT_FAILED;
- result.print();
- }
-
- {
- if (!sql.doQuery("CREATE TABLE sql_client_test (a int, b varchar(255))"))
- return NDBT_FAILED;
-
- if (!sql.doQuery("INSERT INTO sql_client_test VALUES(1, 'hello'), (2, 'bye')"))
- return NDBT_FAILED;
-
- // Select all rows from sql_client_test
- SqlResultSet result;
- if (!sql.doQuery("SELECT * FROM sql_client_test", result))
- return NDBT_FAILED;
- // result.print();
-
- while(result.next())
- {
- }
-
- // Select second row from sql_client_test
- Properties args;
- args.put("0", 2);
- if (!sql.doQuery("SELECT * FROM sql_client_test WHERE a=?", args,result))
- return NDBT_FAILED;
- result.print();
-
- result.reset();
- while(result.next())
- {
- ndbout << "a: " << result.columnAsInt("a") << endl;
- ndbout << "b: " << result.column("b") << endl;
- if (result.columnAsInt("a") != 2){
- ndbout << "hepp1" << endl;
- return NDBT_FAILED;
- }
-
- if (strcmp(result.column("b"), "bye")){
- ndbout << "hepp2" << endl;
- return NDBT_FAILED;
- }
-
- }
-
- if (sql.selectCountTable("sql_client_test") != 2)
- {
- ndbout << "Got wrong count" << endl;
- return NDBT_FAILED;
- }
-
-
- if (!sql.doQuery("DROP TABLE sql_client_test"))
- return NDBT_FAILED;
-
- }
-
- return NDBT_OK;
-}
-
-NDBT_TESTSUITE(testNDBT);
-TESTCASE("AtrtClient",
- "Test AtrtClient class"){
- INITIALIZER(runTestAtrtClient);
-}
-TESTCASE("DbUtil",
- "Test DbUtil class"){
- INITIALIZER(runTestDbUtil);
-}
-NDBT_TESTSUITE_END(testNDBT);
-
-int main(int argc, const char** argv){
- ndb_init();
- return testNDBT.execute(argc, argv);
-}
-
diff --git a/storage/ndb/test/ndbapi/testNdbApi.cpp b/storage/ndb/test/ndbapi/testNdbApi.cpp
deleted file mode 100644
index 0d631023f75..00000000000
--- a/storage/ndb/test/ndbapi/testNdbApi.cpp
+++ /dev/null
@@ -1,1736 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT.hpp>
-#include <NDBT_Test.hpp>
-#include <HugoTransactions.hpp>
-#include <UtilTransactions.hpp>
-#include <NdbRestarter.hpp>
-#include <NdbRestarts.hpp>
-#include <Vector.hpp>
-#include <random.h>
-#include <NdbTick.h>
-
-#define MAX_NDB_OBJECTS 32678
-
-#define CHECK(b) if (!(b)) { \
- ndbout << "ERR: "<< step->getName() \
- << " failed on line " << __LINE__ << endl; \
- result = NDBT_FAILED; \
- continue; }
-
-#define CHECKE(b) if (!(b)) { \
- errors++; \
- ndbout << "ERR: "<< step->getName() \
- << " failed on line " << __LINE__ << endl; \
- result = NDBT_FAILED; \
- continue; }
-
-
-int runTestMaxNdb(NDBT_Context* ctx, NDBT_Step* step){
- Uint32 loops = ctx->getNumLoops();
- Uint32 l = 0;
- int oldi = 0;
- int result = NDBT_OK;
-
- while (l < loops && result == NDBT_OK){
- ndbout_c("loop %d", l + 1);
- int errors = 0;
- int maxErrors = 5;
-
- Vector<Ndb*> ndbVector;
- int i = 0;
- int init = 0;
- do {
-
- Ndb* pNdb = new Ndb(&ctx->m_cluster_connection, "TEST_DB");
- if (pNdb == NULL){
- ndbout << "pNdb == NULL" << endl;
- errors++;
- continue;
-
- }
- i++;
-
- ndbVector.push_back(pNdb);
-
- if (pNdb->init()){
- ERR(pNdb->getNdbError());
- errors++;
- continue;
- }
-
- init++;
-
- } while (errors == 0);
-
- ndbout << i << " ndb objects created" << endl;
-
- if (l > 0 && i != oldi && init != MAX_NDB_OBJECTS){
- ndbout << l << ": not as manyNdb objects created" << endl
- << i << " != " << oldi << endl;
- result = NDBT_FAILED;
- }
-
- oldi = i;
-
-
- for(size_t j = 0; j < ndbVector.size(); j++){
- delete ndbVector[j];
- if(((j+1) % 250) == 0){
- ndbout << "Deleted " << (Uint64) j << " ndb objects " << endl;
- }
- }
- ndbVector.clear();
-
- l++;
- }
-
- return result;
-}
-
-int runTestMaxTransaction(NDBT_Context* ctx, NDBT_Step* step){
- Uint32 loops = ctx->getNumLoops();
- Uint32 l = 0;
- int oldi = 0;
- int result = NDBT_OK;
-
- Ndb* pNdb = new Ndb(&ctx->m_cluster_connection, "TEST_DB");
- if (pNdb == NULL){
- ndbout << "pNdb == NULL" << endl;
- return NDBT_FAILED;
- }
- if (pNdb->init(2048)){
- ERR(pNdb->getNdbError());
- delete pNdb;
- return NDBT_FAILED;
- }
-
- const NdbDictionary::Table* pTab = ctx->getTab();
- if (pTab == 0) abort();
-
- while (l < loops && result == NDBT_OK){
- int errors = 0;
- int maxErrors = 5;
-
- Vector<NdbConnection*> conVector;
-
-
- int i = 0;
- do {
-
- NdbConnection* pCon;
-
- int type = i%2;
- switch (type){
- case 0:
- pCon = pNdb->startTransaction();
- break;
- case 1:
- {
- BaseString key;
- key.appfmt("DATA-%d", i);
- ndbout_c("%s", key.c_str());
- pCon = pNdb->startTransaction(pTab,
- key.c_str(),
- key.length());
- }
- break;
- default:
- abort();
- }
-
- if (pCon == NULL){
- ERR(pNdb->getNdbError());
- errors++;
- continue;
- }
-
- conVector.push_back(pCon);
-
- i++;
- } while (errors < maxErrors);
-
- ndbout << i << " connections created" << endl;
-
- if (l > 0 && i != oldi){
- ndbout << l << ": not as many transactions created" << endl
- << i << " != " << oldi << endl;
- result = NDBT_FAILED;
- }
-
- oldi = i;
-
-
- for(size_t j = 0; j < conVector.size(); j++){
- pNdb->closeTransaction(conVector[j]);
- }
- conVector.clear();
- l++;
-
- }
-
- // BONUS Test closeTransaction with null trans
- pNdb->closeTransaction(NULL);
-
- delete pNdb;
-
-
- return result;
-}
-
-int runTestMaxOperations(NDBT_Context* ctx, NDBT_Step* step){
- Uint32 l = 1;
- int result = NDBT_OK;
- int maxOpsLimit = 1;
- const NdbDictionary::Table* pTab = ctx->getTab();
-
- Ndb* pNdb = new Ndb(&ctx->m_cluster_connection, "TEST_DB");
- if (pNdb == NULL){
- ndbout << "pNdb == NULL" << endl;
- return NDBT_FAILED;
- }
- if (pNdb->init(2048)){
- ERR(pNdb->getNdbError());
- delete pNdb;
- return NDBT_FAILED;
- }
-
- HugoOperations hugoOps(*pTab);
-
- bool endTest = false;
- while (!endTest && result == NDBT_OK){
- int errors = 0;
- int maxErrors = 5;
-
- maxOpsLimit = l*1000;
-
- if (hugoOps.startTransaction(pNdb) != NDBT_OK){
- delete pNdb;
- return NDBT_FAILED;
- }
-
- int i = 0;
- while (errors < maxErrors){
-
- if(hugoOps.pkReadRecord(pNdb,1, 1) != NDBT_OK){
- errors++;
- continue;
- }
-
- i++;
-
- if (i >= maxOpsLimit){
- errors = maxErrors;
- }
-
- }
-
- ndbout << i << " operations used" << endl;
-
- int execResult = hugoOps.execute_Commit(pNdb);
- switch(execResult){
- case NDBT_OK:
- break;
- case 233: // Out of operation records in transaction coordinator
- // OK - end test
- endTest = true;
- break;
- default:
- result = NDBT_FAILED;
- break;
- }
-
- hugoOps.closeTransaction(pNdb);
-
- l++;
-
- }
-
- delete pNdb;
-
- return result;
-}
-
-int runTestGetValue(NDBT_Context* ctx, NDBT_Step* step){
-
- int result = NDBT_OK;
- const NdbDictionary::Table* pTab = ctx->getTab();
-
- Ndb* pNdb = new Ndb(&ctx->m_cluster_connection, "TEST_DB");
- if (pNdb == NULL){
- ndbout << "pNdb == NULL" << endl;
- return NDBT_FAILED;
- }
- if (pNdb->init(2048)){
- ERR(pNdb->getNdbError());
- delete pNdb;
- return NDBT_FAILED;
- }
-
- HugoOperations hugoOps(*pTab);
-
- for (int m = 1; m < 100; m++){
- int errors = 0;
- int maxErrors = 5;
-
- NdbConnection* pCon = pNdb->startTransaction();
- if (pCon == NULL){
- delete pNdb;
- return NDBT_FAILED;
- }
-
- NdbOperation* pOp = pCon->getNdbOperation(pTab->getName());
- if (pOp == NULL){
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
-
- if (pOp->readTuple() != 0){
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
-
- for(int a = 0; a<pTab->getNoOfColumns(); a++){
- if (pTab->getColumn(a)->getPrimaryKey() == true){
- if(hugoOps.equalForAttr(pOp, a, 1) != 0){
- ERR(pCon->getNdbError());
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
- }
- }
-
- int i = 0;
- int maxLimit = 1000*m;
- do {
-
- if (pOp->getValue(pTab->getColumn(1)->getName()) == NULL) {
- const NdbError err = pCon->getNdbError();
- ERR(err);
- if (err.code == 0)
- result = NDBT_FAILED;
- errors++;
- continue;
- }
-
- i++;
-
- } while (errors < maxErrors && i < maxLimit);
-
- ndbout << i << " getValues called" << endl;
-
-
- if (pCon->execute(Commit) != 0){
- const NdbError err = pCon->getNdbError();
- switch(err.code){
- case 880: // TUP - Read too much
- case 823: // TUP - Too much AI
- case 4257: // NDBAPI - Too much AI
- // OK errors
- ERR(pCon->getNdbError());
- break;
- default:
- ERR(pCon->getNdbError());
- ndbout << "Illegal error" << endl;
- result= NDBT_FAILED;
- break;
- }
- }
-
- pNdb->closeTransaction(pCon);
-
- }// m
-
-
- delete pNdb;
-
- return result;
-}
-
-int runTestEqual(NDBT_Context* ctx, NDBT_Step* step){
- Uint32 loops = ctx->getNumLoops();
- Uint32 l = 0;
- int result = NDBT_OK;
- const NdbDictionary::Table* pTab = ctx->getTab();
-
- Ndb* pNdb = new Ndb(&ctx->m_cluster_connection, "TEST_DB");
- if (pNdb == NULL){
- ndbout << "pNdb == NULL" << endl;
- return NDBT_FAILED;
- }
- if (pNdb->init(2048)){
- ERR(pNdb->getNdbError());
- delete pNdb;
- return NDBT_FAILED;
- }
-
- HugoOperations hugoOps(*pTab);
-
- while (l < loops){
- for(int m = 1; m < 10; m++){
- int errors = 0;
- int maxErrors = 5;
-
- NdbConnection* pCon = pNdb->startTransaction();
- if (pCon == NULL){
- ndbout << "Could not start transaction" << endl;
- delete pNdb;
- return NDBT_FAILED;
- }
-
- NdbOperation* pOp = pCon->getNdbOperation(pTab->getName());
- if (pOp == NULL){
- ERR(pCon->getNdbError());
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
-
- if (pOp->readTuple() != 0){
- ERR(pCon->getNdbError());
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
-
- int i = 0;
- int maxLimit = 1000*m;
- do {
-
- if ((l%2)!=0){
- // Forward
- for(int a = 0; a<pTab->getNoOfColumns(); a++){
- if (pTab->getColumn(a)->getPrimaryKey() == true){
- if(hugoOps.equalForAttr(pOp, a, 1) != 0){
- const NdbError err = pCon->getNdbError();
- ERR(err);
- if (err.code == 0)
- result = NDBT_FAILED;
- errors++;
- }
- }
- }
- } else {
- // Backward
- for(int a = pTab->getNoOfColumns()-1; a>=0; a--){
- if (pTab->getColumn(a)->getPrimaryKey() == true){
- if(hugoOps.equalForAttr(pOp, a, 1) != 0){
- const NdbError err = pCon->getNdbError();
- ERR(err);
- if (err.code == 0)
- result = NDBT_FAILED;
- errors++;
- }
- }
- }
- }
-
- i++;
-
- } while (errors < maxErrors && i < maxLimit);
-
- if (pOp->getValue(pTab->getColumn(1)->getName()) == NULL) {
- const NdbError err = pCon->getNdbError();
- ERR(pCon->getNdbError());
- pNdb->closeTransaction(pCon);
- delete pNdb;
- if (err.code == 4225) {
- return NDBT_OK;
- } else {
- return NDBT_FAILED;
- }//if
- }
-
- ndbout << i << " equal called" << endl;
-
-
- int check = pCon->execute(Commit);
- if (check != 0){
- ERR(pCon->getNdbError());
- }
-
- pNdb->closeTransaction(pCon);
-
- }// m
- l++;
-
- }// l
-
- delete pNdb;
- return result;
-}
-
-int runTestDeleteNdb(NDBT_Context* ctx, NDBT_Step* step){
- Uint32 loops = ctx->getNumLoops();
- Uint32 l = 0;
- int result = NDBT_OK;
- NdbRestarts restarts;
- Vector<Ndb*> ndbVector;
- const NdbDictionary::Table* pTab = ctx->getTab();
- HugoTransactions hugoTrans(*pTab);
- int records = ctx->getNumRecords();
-
- while (l < loops && result == NDBT_OK){
-
- // Create 5 ndb objects
- for( int i = 0; i < 5; i++){
- Ndb* pNdb = new Ndb(&ctx->m_cluster_connection, "TEST_DB");
- if (pNdb == NULL){
- ndbout << "pNdb == NULL" << endl;
- result = NDBT_FAILED;
- goto end_test;
- }
- ndbVector.push_back(pNdb);
-
- if (pNdb->init()){
- ERR(pNdb->getNdbError());
- result = NDBT_FAILED;
- goto end_test;
- }
- if (pNdb->waitUntilReady() != 0){
- ERR(pNdb->getNdbError());
- result = NDBT_FAILED;
- goto end_test;
- }
- if (hugoTrans.pkReadRecords(pNdb, records) != 0){
- result = NDBT_FAILED;
- goto end_test;
- }
- }
-
- if ((l % 2) == 0){
- // Restart random node
- ndbout << "Restart random node " << endl;
- if(restarts.executeRestart("RestartRandomNodeAbort", 120) != 0){
- g_err << "Failed to executeRestart(RestartRandomNode)"<<endl;
- result = NDBT_FAILED;
- goto end_test;
- }
- } else {
- // Restart all nodes
- ndbout << "Restart all nodes " << endl;
- if(restarts.executeRestart("RestartAllNodesAbort", 120) != 0){
- g_err << "Failed to executeRestart(RestartAllNodes)"<<endl;
- result = NDBT_FAILED;
- goto end_test;
- }
- }
-
- // Delete the ndb objects
- for(size_t j = 0; j < ndbVector.size(); j++)
- delete ndbVector[j];
- ndbVector.clear();
- l++;
- }
-
-
- end_test:
-
- for(size_t i = 0; i < ndbVector.size(); i++)
- delete ndbVector[i];
- ndbVector.clear();
-
- return result;
-}
-
-
-int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
-
- UtilTransactions utilTrans(*ctx->getTab());
- if (utilTrans.clearTable2(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
-
- int records = ctx->getNumRecords();
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.loadTable(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runTestWaitUntilReady(NDBT_Context* ctx, NDBT_Step* step){
-
- Ndb* pNdb = new Ndb(&ctx->m_cluster_connection, "TEST_DB");
-
- // Forget about calling pNdb->init();
-
- if (pNdb->waitUntilReady() == 0){
- ndbout << "waitUntilReady returned OK" << endl;
- delete pNdb;
- return NDBT_FAILED;
- }
- const NdbError err = pNdb->getNdbError();
- delete pNdb;
-
- ERR(err);
- if (err.code != 4256)
- return NDBT_FAILED;
-
- return NDBT_OK;
-}
-
-int runGetNdbOperationNoTab(NDBT_Context* ctx, NDBT_Step* step){
-
- Ndb* pNdb = new Ndb(&ctx->m_cluster_connection, "TEST_DB");
- if (pNdb == NULL){
- ndbout << "pNdb == NULL" << endl;
- return NDBT_FAILED;
- }
- if (pNdb->init()){
- ERR(pNdb->getNdbError());
- delete pNdb;
- return NDBT_FAILED;
- }
-
- NdbConnection* pCon = pNdb->startTransaction();
- if (pCon == NULL){
- delete pNdb;
- return NDBT_FAILED;
- }
-
- // Call getNdbOperation on an unknown table
- NdbOperation* pOp = pCon->getNdbOperation("HUPP76");
- if (pOp == NULL){
- NdbError err = pCon->getNdbError();
- ERR(err);
- if (err.code == 0){
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
- }
-
- pNdb->closeTransaction(pCon);
-
- delete pNdb;
-
- return NDBT_OK;
-}
-
-int runMissingOperation(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- const NdbDictionary::Table* pTab = ctx->getTab();
-
-
- Ndb* pNdb = new Ndb(&ctx->m_cluster_connection, "TEST_DB");
- if (pNdb == NULL){
- ndbout << "pNdb == NULL" << endl;
- return NDBT_FAILED;
- }
- if (pNdb->init()){
- ERR(pNdb->getNdbError());
- delete pNdb;
- return NDBT_FAILED;
- }
-
- NdbConnection* pCon = pNdb->startTransaction();
- if (pCon == NULL){
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
-
- NdbOperation* pOp = pCon->getNdbOperation(pTab->getName());
- if (pOp == NULL){
- ERR(pCon->getNdbError());
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
-
- // Forget about calling pOp->insertTuple();
-
- // Call getValue should not work
- if (pOp->getValue(pTab->getColumn(1)->getName()) == NULL) {
- const NdbError err = pCon->getNdbError();
- ERR(err);
- if (err.code == 0){
- ndbout << "hupp" << endl;
- result = NDBT_FAILED;
- }
- } else {
- ndbout << "hupp2" << endl;
- result = NDBT_FAILED;
- }
-
- pNdb->closeTransaction(pCon);
- delete pNdb;
-
- return result;
-}
-
-int runGetValueInUpdate(NDBT_Context* ctx, NDBT_Step* step){
- const NdbDictionary::Table* pTab = ctx->getTab();
-
- Ndb* pNdb = new Ndb(&ctx->m_cluster_connection, "TEST_DB");
- if (pNdb == NULL){
- ndbout << "pNdb == NULL" << endl;
- return NDBT_FAILED;
- }
- if (pNdb->init()){
- ERR(pNdb->getNdbError());
- delete pNdb;
- return NDBT_FAILED;
- }
-
- NdbConnection* pCon = pNdb->startTransaction();
- if (pCon == NULL){
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
-
- NdbOperation* pOp = pCon->getNdbOperation(pTab->getName());
- if (pOp == NULL){
- ERR(pCon->getNdbError());
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
-
- if (pOp->updateTuple() != 0){
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
-
- // Call getValue should not work
- if (pOp->getValue(pTab->getColumn(1)->getName()) == NULL) {
- // It didn't work
- const NdbError err = pCon->getNdbError();
- ERR(err);
- if (err.code == 0){
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
- } else {
- // It worked, not good!
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
-
- int check = pCon->execute(Commit);
- if (check != 0){
- ERR(pCon->getNdbError());
- }
-
- pNdb->closeTransaction(pCon);
- delete pNdb;
-
- return NDBT_OK;
-}
-
-int runUpdateWithoutValues(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- const NdbDictionary::Table* pTab = ctx->getTab();
-
- HugoOperations hugoOps(*pTab);
-
- Ndb* pNdb = new Ndb(&ctx->m_cluster_connection, "TEST_DB");
- if (pNdb == NULL){
- ndbout << "pNdb == NULL" << endl;
- return NDBT_FAILED;
- }
- if (pNdb->init()){
- ERR(pNdb->getNdbError());
- delete pNdb;
- return NDBT_FAILED;
- }
-
- NdbConnection* pCon = pNdb->startTransaction();
- if (pCon == NULL){
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
-
- NdbOperation* pOp = pCon->getNdbOperation(pTab->getName());
- if (pOp == NULL){
- ERR(pCon->getNdbError());
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
-
- if (pOp->updateTuple() != 0){
- pNdb->closeTransaction(pCon);
- ERR(pOp->getNdbError());
- delete pNdb;
- return NDBT_FAILED;
- }
-
- for(int a = 0; a<pTab->getNoOfColumns(); a++){
- if (pTab->getColumn(a)->getPrimaryKey() == true){
- if(hugoOps.equalForAttr(pOp, a, 1) != 0){
- ERR(pCon->getNdbError());
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
- }
- }
-
- // Dont' call any setValues
-
- // Execute should work
- int check = pCon->execute(Commit);
- if (check == 0){
- ndbout << "execute worked" << endl;
- } else {
- ERR(pCon->getNdbError());
- result = NDBT_FAILED;
- }
-
- pNdb->closeTransaction(pCon);
- delete pNdb;
-
- return result;
-}
-
-int runUpdateWithoutKeys(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- const NdbDictionary::Table* pTab = ctx->getTab();
-
-
- Ndb* pNdb = new Ndb(&ctx->m_cluster_connection, "TEST_DB");
- if (pNdb == NULL){
- ndbout << "pNdb == NULL" << endl;
- return NDBT_FAILED;
- }
- if (pNdb->init()){
- ERR(pNdb->getNdbError());
- delete pNdb;
- return NDBT_FAILED;
- }
-
- NdbConnection* pCon = pNdb->startTransaction();
- if (pCon == NULL){
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
-
- NdbOperation* pOp = pCon->getNdbOperation(pTab->getName());
- if (pOp == NULL){
- ERR(pCon->getNdbError());
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
-
- if (pOp->updateTuple() != 0){
- pNdb->closeTransaction(pCon);
- ERR(pOp->getNdbError());
- delete pNdb;
- return NDBT_FAILED;
- }
-
- // Dont' call any equal or setValues
-
- // Execute should not work
- int check = pCon->execute(Commit);
- if (check == 0){
- ndbout << "execute worked" << endl;
- result = NDBT_FAILED;
- } else {
- ERR(pCon->getNdbError());
- }
-
- pNdb->closeTransaction(pCon);
- delete pNdb;
-
- return result;
-}
-
-
-int runReadWithoutGetValue(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- const NdbDictionary::Table* pTab = ctx->getTab();
-
- HugoOperations hugoOps(*pTab);
-
- Ndb* pNdb = GETNDB(step);
- Uint32 lm;
-
- for(Uint32 cm= 0; cm < 2; cm++)
- {
- for(lm= 0; lm <= NdbOperation::LM_CommittedRead; lm++)
- {
- NdbConnection* pCon = pNdb->startTransaction();
- if (pCon == NULL){
- pNdb->closeTransaction(pCon);
- return NDBT_FAILED;
- }
-
- NdbOperation* pOp = pCon->getNdbOperation(pTab->getName());
- if (pOp == NULL){
- ERR(pCon->getNdbError());
- pNdb->closeTransaction(pCon);
- return NDBT_FAILED;
- }
-
- if (pOp->readTuple((NdbOperation::LockMode)lm) != 0){
- pNdb->closeTransaction(pCon);
- ERR(pOp->getNdbError());
- return NDBT_FAILED;
- }
-
- for(int a = 0; a<pTab->getNoOfColumns(); a++){
- if (pTab->getColumn(a)->getPrimaryKey() == true){
- if(hugoOps.equalForAttr(pOp, a, 1) != 0){
- ERR(pCon->getNdbError());
- pNdb->closeTransaction(pCon);
- return NDBT_FAILED;
- }
- }
- }
-
- // Dont' call any getValues
-
- // Execute should work
- int check = pCon->execute(cm == 0 ? NoCommit : Commit);
- if (check == 0){
- ndbout << "execute worked" << endl;
- } else {
- ERR(pCon->getNdbError());
- result = NDBT_FAILED;
- }
-
- pNdb->closeTransaction(pCon);
- }
- }
-
- /**
- * Now test scans
- */
- for(lm= 0; lm <= NdbOperation::LM_CommittedRead; lm++)
- {
- NdbConnection* pCon = pNdb->startTransaction();
- if (pCon == NULL){
- pNdb->closeTransaction(pCon);
- return NDBT_FAILED;
- }
-
- NdbScanOperation* pOp = pCon->getNdbScanOperation(pTab->getName());
- if (pOp == NULL){
- ERR(pCon->getNdbError());
- pNdb->closeTransaction(pCon);
- return NDBT_FAILED;
- }
-
- if ((pOp->readTuples((NdbOperation::LockMode)lm)) != 0){
- pNdb->closeTransaction(pCon);
- ERR(pOp->getNdbError());
- return NDBT_FAILED;
- }
-
-
- // Dont' call any getValues
-
- // Execute should work
- int check = pCon->execute(NoCommit);
- if (check == 0){
- ndbout << "execute worked" << endl;
- } else {
- ERR(pCon->getNdbError());
- result = NDBT_FAILED;
- }
-
- int res;
- while((res = pOp->nextResult()) == 0);
- pNdb->closeTransaction(pCon);
-
- if(res != 1)
- result = NDBT_FAILED;
- }
-
- return result;
-}
-
-
-int runCheckGetNdbErrorOperation(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- const NdbDictionary::Table* pTab = ctx->getTab();
-
- Ndb* pNdb = new Ndb(&ctx->m_cluster_connection, "TEST_DB");
- if (pNdb == NULL){
- ndbout << "pNdb == NULL" << endl;
- return NDBT_FAILED;
- }
- if (pNdb->init(2048)){
- ERR(pNdb->getNdbError());
- delete pNdb;
- return NDBT_FAILED;
- }
-
- HugoOperations hugoOps(*pTab);
-
-
- NdbConnection* pCon = pNdb->startTransaction();
- if (pCon == NULL){
- ndbout << "Could not start transaction" << endl;
- delete pNdb;
- return NDBT_FAILED;
- }
-
- NdbOperation* pOp = pCon->getNdbOperation(pTab->getName());
- if (pOp == NULL){
- ERR(pCon->getNdbError());
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
-
- // Dont call readTuple here
- // That's the error!
-
- for(int a = 0; a<pTab->getNoOfColumns(); a++){
- if (pTab->getColumn(a)->getPrimaryKey() == true){
- if(hugoOps.equalForAttr(pOp, a, 1) != 0){
- // An error has occured, check that
- // it's possible to get the NdbErrorOperation
- const NdbError err = pCon->getNdbError();
- ERR(err);
- if (err.code == 0)
- result = NDBT_FAILED;
-
- NdbOperation* pOp2 = pCon->getNdbErrorOperation();
- if (pOp2 == NULL)
- result = NDBT_FAILED;
- else {
- const NdbError err2 = pOp2->getNdbError();
- ERR(err2);
- if (err.code == 0)
- result = NDBT_FAILED;
- }
- }
- }
- }
-
- pNdb->closeTransaction(pCon);
-
- delete pNdb;
- return result;
-}
-
-#define C2(x) { int _x= (x); if(_x == 0){ ndbout << "line: " << __LINE__ << endl; return NDBT_FAILED;} }
-
-int runBug_11133(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- const NdbDictionary::Table* pTab = ctx->getTab();
-
- HugoOperations hugoOps(*pTab);
-
- Ndb* pNdb = GETNDB(step);
- C2(hugoOps.startTransaction(pNdb) == 0);
- C2(hugoOps.pkInsertRecord(pNdb, 0, 1) == 0);
- C2(hugoOps.execute_NoCommit(pNdb) == 0);
- C2(hugoOps.pkDeleteRecord(pNdb, 0, 1) == 0);
- C2(hugoOps.execute_NoCommit(pNdb) == 0);
- C2(hugoOps.pkWriteRecord(pNdb, 0, 1) == 0);
- C2(hugoOps.execute_NoCommit(pNdb) == 0);
- C2(hugoOps.pkWriteRecord(pNdb, 0, 1) == 0);
- C2(hugoOps.execute_NoCommit(pNdb) == 0);
- C2(hugoOps.pkDeleteRecord(pNdb, 0, 1) == 0);
- C2(hugoOps.execute_Commit(pNdb) == 0);
- C2(hugoOps.closeTransaction(pNdb) == 0);
-
- C2(hugoOps.startTransaction(pNdb) == 0);
- C2(hugoOps.pkInsertRecord(pNdb, 0, 1) == 0);
- C2(hugoOps.execute_NoCommit(pNdb) == 0);
- C2(hugoOps.pkWriteRecord(pNdb, 0, 1) == 0);
- C2(hugoOps.execute_NoCommit(pNdb) == 0);
- C2(hugoOps.pkWriteRecord(pNdb, 0, 1) == 0);
- C2(hugoOps.execute_NoCommit(pNdb) == 0);
- C2(hugoOps.pkDeleteRecord(pNdb, 0, 1) == 0);
- C2(hugoOps.execute_Commit(pNdb) == 0);
- C2(hugoOps.closeTransaction(pNdb) == 0);
-
- C2(hugoOps.startTransaction(pNdb) == 0);
- C2(hugoOps.pkInsertRecord(pNdb, 0, 1) == 0);
- C2(hugoOps.execute_Commit(pNdb) == 0);
- C2(hugoOps.closeTransaction(pNdb) == 0);
-
- C2(hugoOps.startTransaction(pNdb) == 0);
- C2(hugoOps.pkReadRecord(pNdb, 0, 1, NdbOperation::LM_Exclusive) == 0);
- C2(hugoOps.execute_NoCommit(pNdb) == 0);
- C2(hugoOps.pkDeleteRecord(pNdb, 0, 1) == 0);
- C2(hugoOps.execute_NoCommit(pNdb) == 0);
- C2(hugoOps.pkWriteRecord(pNdb, 0, 1) == 0);
- C2(hugoOps.execute_NoCommit(pNdb) == 0);
- C2(hugoOps.pkWriteRecord(pNdb, 0, 1) == 0);
- C2(hugoOps.execute_NoCommit(pNdb) == 0);
- C2(hugoOps.pkDeleteRecord(pNdb, 0, 1) == 0);
- C2(hugoOps.execute_Commit(pNdb) == 0);
- C2(hugoOps.closeTransaction(pNdb) == 0);
-
- Ndb ndb2(&ctx->m_cluster_connection, "TEST_DB");
- C2(ndb2.init() == 0);
- C2(ndb2.waitUntilReady() == 0);
- HugoOperations hugoOps2(*pTab);
-
- C2(hugoOps.startTransaction(pNdb) == 0);
- C2(hugoOps.pkInsertRecord(pNdb, 0, 1) == 0);
- C2(hugoOps.execute_NoCommit(pNdb) == 0);
- C2(hugoOps2.startTransaction(&ndb2) == 0);
- C2(hugoOps2.pkWritePartialRecord(&ndb2, 0) == 0);
- C2(hugoOps2.execute_async(&ndb2, NdbTransaction::NoCommit) == 0);
- C2(hugoOps.execute_Commit(pNdb) == 0);
- C2(hugoOps2.wait_async(&ndb2) == 0);
- C2(hugoOps.closeTransaction(pNdb) == 0);
- C2(hugoOps2.closeTransaction(&ndb2) == 0);
-
- C2(hugoOps.startTransaction(pNdb) == 0);
- C2(hugoOps.pkDeleteRecord(pNdb, 0, 1) == 0);
- C2(hugoOps.execute_NoCommit(pNdb) == 0);
- C2(hugoOps2.startTransaction(&ndb2) == 0);
- C2(hugoOps2.pkWriteRecord(&ndb2, 0, 1) == 0);
- C2(hugoOps2.execute_async(&ndb2, NdbTransaction::NoCommit) == 0);
- C2(hugoOps.execute_Commit(pNdb) == 0);
- C2(hugoOps2.wait_async(&ndb2) == 0);
- C2(hugoOps2.execute_Commit(pNdb) == 0);
- C2(hugoOps.closeTransaction(pNdb) == 0);
- C2(hugoOps2.closeTransaction(&ndb2) == 0);
-
- C2(hugoOps.startTransaction(pNdb) == 0);
- C2(hugoOps.pkUpdateRecord(pNdb, 0, 1) == 0);
- C2(hugoOps.execute_NoCommit(pNdb) == 0);
- C2(hugoOps2.startTransaction(&ndb2) == 0);
- C2(hugoOps2.pkWritePartialRecord(&ndb2, 0) == 0);
- C2(hugoOps2.execute_async(&ndb2, NdbTransaction::NoCommit) == 0);
- C2(hugoOps.execute_Commit(pNdb) == 0);
- C2(hugoOps2.wait_async(&ndb2) == 0);
- C2(hugoOps.closeTransaction(pNdb) == 0);
- C2(hugoOps2.closeTransaction(&ndb2) == 0);
-
- C2(hugoOps.startTransaction(pNdb) == 0);
- C2(hugoOps.pkDeleteRecord(pNdb, 0, 1) == 0);
- C2(hugoOps.execute_NoCommit(pNdb) == 0);
- C2(hugoOps2.startTransaction(&ndb2) == 0);
- C2(hugoOps2.pkWritePartialRecord(&ndb2, 0) == 0);
- C2(hugoOps2.execute_async(&ndb2, NdbTransaction::NoCommit) == 0);
- C2(hugoOps.execute_Commit(pNdb) == 0);
- C2(hugoOps2.wait_async(&ndb2) != 0);
- C2(hugoOps.closeTransaction(pNdb) == 0);
- C2(hugoOps2.closeTransaction(&ndb2) == 0);
-
- return result;
-}
-
-int runBug_WritePartialIgnoreError(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- const NdbDictionary::Table* pTab = ctx->getTab();
-
- HugoOperations hugoOps(*pTab);
-
- Ndb* pNdb = GETNDB(step);
- C2(hugoOps.startTransaction(pNdb) == 0);
- C2(hugoOps.pkWritePartialRecord(pNdb, 0, 1) == 0);
- C2(hugoOps.execute_Commit(pNdb, AO_IgnoreError) == 839);
- C2(hugoOps.closeTransaction(pNdb) == 0);
-
- return result;
-}
-
-int runScan_4006(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- const Uint32 max= 5;
- const NdbDictionary::Table* pTab = ctx->getTab();
-
- Ndb* pNdb = new Ndb(&ctx->m_cluster_connection, "TEST_DB");
- if (pNdb == NULL){
- ndbout << "pNdb == NULL" << endl;
- return NDBT_FAILED;
- }
- if (pNdb->init(max)){
- ERR(pNdb->getNdbError());
- delete pNdb;
- return NDBT_FAILED;
- }
-
- NdbConnection* pCon = pNdb->startTransaction();
- if (pCon == NULL){
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
-
- Uint32 i;
- Vector<NdbScanOperation*> scans;
- for(i = 0; i<10*max; i++)
- {
- NdbScanOperation* pOp = pCon->getNdbScanOperation(pTab->getName());
- if (pOp == NULL){
- ERR(pCon->getNdbError());
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
-
- if (pOp->readTuples() != 0){
- pNdb->closeTransaction(pCon);
- ERR(pOp->getNdbError());
- delete pNdb;
- return NDBT_FAILED;
- }
- scans.push_back(pOp);
- }
-
- // Dont' call any equal or setValues
-
- // Execute should not work
- int check = pCon->execute(NoCommit);
- if (check == 0){
- ndbout << "execute worked" << endl;
- } else {
- ERR(pCon->getNdbError());
- }
-
- for(i= 0; i<scans.size(); i++)
- {
- NdbScanOperation* pOp= scans[i];
- while((check= pOp->nextResult()) == 0);
- if(check != 1)
- {
- ERR(pOp->getNdbError());
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
- }
-
- pNdb->closeTransaction(pCon);
-
- Vector<NdbConnection*> cons;
- for(i= 0; i<10*max; i++)
- {
- pCon= pNdb->startTransaction();
- if(pCon)
- cons.push_back(pCon);
- else
- break;
- }
-
- for(i= 0; i<cons.size(); i++)
- {
- cons[i]->close();
- }
-
- if(cons.size() != max)
- {
- result= NDBT_FAILED;
- }
-
- delete pNdb;
-
- return result;
-}
-
-char pkIdxName[255];
-
-int createPkIndex(NDBT_Context* ctx, NDBT_Step* step){
- bool orderedIndex = ctx->getProperty("OrderedIndex", (unsigned)0);
-
- const NdbDictionary::Table* pTab = ctx->getTab();
- Ndb* pNdb = GETNDB(step);
-
- bool logged = ctx->getProperty("LoggedIndexes", 1);
-
- // Create index
- BaseString::snprintf(pkIdxName, 255, "IDC_PK_%s", pTab->getName());
- if (orderedIndex)
- ndbout << "Creating " << ((logged)?"logged ": "temporary ") << "ordered index "
- << pkIdxName << " (";
- else
- ndbout << "Creating " << ((logged)?"logged ": "temporary ") << "unique index "
- << pkIdxName << " (";
-
- NdbDictionary::Index pIdx(pkIdxName);
- pIdx.setTable(pTab->getName());
- if (orderedIndex)
- pIdx.setType(NdbDictionary::Index::OrderedIndex);
- else
- pIdx.setType(NdbDictionary::Index::UniqueHashIndex);
- for (int c = 0; c< pTab->getNoOfColumns(); c++){
- const NdbDictionary::Column * col = pTab->getColumn(c);
- if(col->getPrimaryKey()){
- pIdx.addIndexColumn(col->getName());
- ndbout << col->getName() <<" ";
- }
- }
-
- pIdx.setStoredIndex(logged);
- ndbout << ") ";
- if (pNdb->getDictionary()->createIndex(pIdx) != 0){
- ndbout << "FAILED!" << endl;
- const NdbError err = pNdb->getDictionary()->getNdbError();
- ERR(err);
- return NDBT_FAILED;
- }
-
- ndbout << "OK!" << endl;
- return NDBT_OK;
-}
-
-int createPkIndex_Drop(NDBT_Context* ctx, NDBT_Step* step){
- const NdbDictionary::Table* pTab = ctx->getTab();
- Ndb* pNdb = GETNDB(step);
-
- // Drop index
- ndbout << "Dropping index " << pkIdxName << " ";
- if (pNdb->getDictionary()->dropIndex(pkIdxName,
- pTab->getName()) != 0){
- ndbout << "FAILED!" << endl;
- ERR(pNdb->getDictionary()->getNdbError());
- return NDBT_FAILED;
- } else {
- ndbout << "OK!" << endl;
- }
-
- return NDBT_OK;
-}
-
-static
-int
-op_row(NdbTransaction* pTrans, HugoOperations& hugoOps,
- const NdbDictionary::Table* pTab, int op, int row)
-{
- NdbOperation * pOp = 0;
- switch(op){
- case 0:
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- pOp = pTrans->getNdbOperation(pTab->getName());
- break;
- case 9:
- return 0;
- case 6:
- case 7:
- case 8:
- case 10:
- case 11:
- pOp = pTrans->getNdbIndexOperation(pkIdxName, pTab->getName());
- default:
- break;
- }
-
- switch(op){
- case 0:
- case 6:
- pOp->readTuple();
- break;
- case 1:
- case 7:
- pOp->committedRead();
- break;
- case 2:
- case 8:
- pOp->readTupleExclusive();
- break;
- case 3:
- case 9:
- pOp->insertTuple();
- break;
- case 4:
- case 10:
- pOp->updateTuple();
- break;
- case 5:
- case 11:
- pOp->deleteTuple();
- break;
- default:
- abort();
- }
-
- for(int a = 0; a<pTab->getNoOfColumns(); a++){
- if (pTab->getColumn(a)->getPrimaryKey() == true){
- if(hugoOps.equalForAttr(pOp, a, row) != 0){
- return NDBT_FAILED;
- }
- }
- }
-
- switch(op){
- case 0:
- case 1:
- case 2:
- case 6:
- case 7:
- case 8:
- for(int a = 0; a<pTab->getNoOfColumns(); a++){
- pOp->getValue(a);
- }
- break;
- case 3:
- case 4:
- case 10:
- for(int a = 0; a<pTab->getNoOfColumns(); a++){
- if (pTab->getColumn(a)->getPrimaryKey() == false){
- if(hugoOps.setValueForAttr(pOp, a, row, 2) != 0){
- return NDBT_FAILED;
- }
- }
- }
- break;
- case 5:
- case 11:
- pOp->deleteTuple();
- break;
- case 9:
- default:
- abort();
- }
-
- return NDBT_OK;
-}
-
-static void print(int op)
-{
- const char * str = 0;
- switch(op){
- case 0: str = "pk read-sh"; break;
- case 1: str = "pk read-nl"; break;
- case 2: str = "pk read-ex"; break;
- case 3: str = "pk insert "; break;
- case 4: str = "pk update "; break;
- case 5: str = "pk delete "; break;
- case 6: str = "uk read-sh"; break;
- case 7: str = "uk read-nl"; break;
- case 8: str = "uk read-ex"; break;
- case 9: str = "noop "; break;
- case 10: str = "uk update "; break;
- case 11: str = "uk delete "; break;
- default:
- abort();
- }
- printf("%s ", str);
-}
-
-int
-runTestIgnoreError(NDBT_Context* ctx, NDBT_Step* step)
-{
- int result = NDBT_OK;
- Uint32 loops = ctx->getNumRecords();
- const NdbDictionary::Table* pTab = ctx->getTab();
-
- HugoOperations hugoOps(*pTab);
- HugoTransactions hugoTrans(*pTab);
-
- Ndb* pNdb = GETNDB(step);
-
- struct {
- ExecType et;
- AbortOption ao;
- } tests[] = {
- { Commit, AbortOnError },
- { Commit, AO_IgnoreError },
- { NoCommit, AbortOnError },
- { NoCommit, AO_IgnoreError },
- };
-
- printf("case: <op1> <op2> c/nc ao/ie\n");
- Uint32 tno = 0;
- for (Uint32 op1 = 0; op1 < 12; op1++)
- {
- for (Uint32 op2 = op1; op2 < 12; op2++)
- {
- int ret;
- NdbTransaction* pTrans = 0;
-
- for (Uint32 i = 0; i<4; i++, tno++)
- {
- if (loops != 1000 && loops != tno)
- continue;
- ExecType et = tests[i].et;
- AbortOption ao = tests[i].ao;
-
- printf("%.3d : ", tno);
- print(op1);
- print(op2);
- switch(et){
- case Commit: printf("c "); break;
- case NoCommit: printf("nc "); break;
- }
- switch(ao){
- case AbortOnError: printf("aoe "); break;
- case AO_IgnoreError: printf("ie "); break;
- }
- printf(": ");
-
-
- hugoTrans.loadTable(pNdb, 1);
- pTrans = pNdb->startTransaction();
- op_row(pTrans, hugoOps, pTab, op1, 0);
- ret = pTrans->execute(et, ao);
- pTrans->close();
- printf("%d ", ret);
- hugoTrans.clearTable(pNdb);
-
- hugoTrans.loadTable(pNdb, 1);
- pTrans = pNdb->startTransaction();
- op_row(pTrans, hugoOps, pTab, op1, 1);
- ret = pTrans->execute(et, ao);
- pTrans->close();
- printf("%d ", ret);
- hugoTrans.clearTable(pNdb);
-
- hugoTrans.loadTable(pNdb, 1);
- pTrans = pNdb->startTransaction();
- op_row(pTrans, hugoOps, pTab, op1, 0);
- op_row(pTrans, hugoOps, pTab, op2, 1);
- ret = pTrans->execute(et, ao);
- pTrans->close();
- printf("%d\n", ret);
- hugoTrans.clearTable(pNdb);
-
- hugoTrans.clearTable(pNdb);
- }
- }
- }
- return NDBT_OK;
-}
-
-static void
-testExecuteAsynchCallback(int res, NdbTransaction *con, void *data_ptr)
-{
- int *res_ptr= (int *)data_ptr;
-
- *res_ptr= res;
-}
-
-int runTestExecuteAsynch(NDBT_Context* ctx, NDBT_Step* step){
- /* Test that NdbTransaction::executeAsynch() works (BUG#27495). */
- int result = NDBT_OK;
- const NdbDictionary::Table* pTab = ctx->getTab();
-
- Ndb* pNdb = new Ndb(&ctx->m_cluster_connection, "TEST_DB");
- if (pNdb == NULL){
- ndbout << "pNdb == NULL" << endl;
- return NDBT_FAILED;
- }
- if (pNdb->init(2048)){
- ERR(pNdb->getNdbError());
- delete pNdb;
- return NDBT_FAILED;
- }
-
- NdbConnection* pCon = pNdb->startTransaction();
- if (pCon == NULL){
- ERR(pNdb->getNdbError());
- delete pNdb;
- return NDBT_FAILED;
- }
-
- NdbScanOperation* pOp = pCon->getNdbScanOperation(pTab->getName());
- if (pOp == NULL){
- ERR(pOp->getNdbError());
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
-
- if (pOp->readTuples() != 0){
- ERR(pOp->getNdbError());
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
-
- if (pOp->getValue(NdbDictionary::Column::FRAGMENT) == 0){
- ERR(pOp->getNdbError());
- pNdb->closeTransaction(pCon);
- delete pNdb;
- return NDBT_FAILED;
- }
- int res= 42;
- pCon->executeAsynch(NoCommit, testExecuteAsynchCallback, &res);
- while(pNdb->pollNdb(100000) == 0)
- ;
- if (res != 0){
- ERR(pCon->getNdbError());
- ndbout << "Error returned from execute: " << res << endl;
- result= NDBT_FAILED;
- }
-
- pNdb->closeTransaction(pCon);
-
- delete pNdb;
-
- return result;
-}
-
-template class Vector<NdbScanOperation*>;
-
-int
-runBug28443(NDBT_Context* ctx, NDBT_Step* step)
-{
- int result = NDBT_OK;
- int records = ctx->getNumRecords();
-
- NdbRestarter restarter;
-
- restarter.insertErrorInAllNodes(9003);
-
- for (Uint32 i = 0; i<ctx->getNumLoops(); i++)
- {
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.loadTable(GETNDB(step), records, 2048) != 0)
- {
- result = NDBT_FAILED;
- goto done;
- }
- if (runClearTable(ctx, step) != 0)
- {
- result = NDBT_FAILED;
- goto done;
- }
- }
-
-done:
- restarter.insertErrorInAllNodes(9003);
-
- return result;
-}
-
-NDBT_TESTSUITE(testNdbApi);
-TESTCASE("MaxNdb",
- "Create Ndb objects until no more can be created\n"){
- INITIALIZER(runTestMaxNdb);
-}
-TESTCASE("MaxTransactions",
- "Start transactions until no more can be created\n"){
- INITIALIZER(runTestMaxTransaction);
-}
-TESTCASE("MaxOperations",
- "Get operations until no more can be created\n"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runTestMaxOperations);
- FINALIZER(runClearTable);
-}
-TESTCASE("MaxGetValue",
- "Call getValue loads of time\n"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runTestGetValue);
- FINALIZER(runClearTable);
-}
-TESTCASE("MaxEqual",
- "Call equal loads of time\n"){
- INITIALIZER(runTestEqual);
-}
-TESTCASE("DeleteNdb",
- "Make sure that a deleted Ndb object is properly deleted\n"
- "and removed from transporter\n"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runTestDeleteNdb);
- FINALIZER(runClearTable);
-}
-TESTCASE("WaitUntilReady",
- "Make sure you get an error message when calling waitUntilReady\n"
- "without an init'ed Ndb\n"){
- INITIALIZER(runTestWaitUntilReady);
-}
-TESTCASE("GetOperationNoTab",
- "Call getNdbOperation on a table that does not exist\n"){
- INITIALIZER(runGetNdbOperationNoTab);
-}
-TESTCASE("MissingOperation",
- "Missing operation request(insertTuple) should give an error code\n"){
- INITIALIZER(runMissingOperation);
-}
-TESTCASE("GetValueInUpdate",
- "Test that it's not possible to perform getValue in an update\n"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runGetValueInUpdate);
- FINALIZER(runClearTable);
-}
-TESTCASE("UpdateWithoutKeys",
- "Test that it's not possible to perform update without setting\n"
- "PKs"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runUpdateWithoutKeys);
- FINALIZER(runClearTable);
-}
-TESTCASE("UpdateWithoutValues",
- "Test that it's not possible to perform update without setValues\n"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runUpdateWithoutValues);
- FINALIZER(runClearTable);
-}
-TESTCASE("NdbErrorOperation",
- "Test that NdbErrorOperation is properly set"){
- INITIALIZER(runCheckGetNdbErrorOperation);
-}
-TESTCASE("ReadWithoutGetValue",
- "Test that it's possible to perform read wo/ getvalue's\n"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runReadWithoutGetValue);
- FINALIZER(runClearTable);
-}
-TESTCASE("Bug_11133",
- "Test ReadEx-Delete-Write\n"){
- INITIALIZER(runBug_11133);
- FINALIZER(runClearTable);
-}
-TESTCASE("Bug_WritePartialIgnoreError",
- "Test WritePartialIgnoreError\n"){
- INITIALIZER(runBug_WritePartialIgnoreError);
- FINALIZER(runClearTable);
-}
-TESTCASE("Scan_4006",
- "Check that getNdbScanOperation does not get 4006\n"){
- INITIALIZER(runLoadTable);
- INITIALIZER(runScan_4006);
- FINALIZER(runClearTable);
-}
-TESTCASE("IgnoreError", ""){
- INITIALIZER(createPkIndex);
- STEP(runTestIgnoreError);
- FINALIZER(runClearTable);
- FINALIZER(createPkIndex_Drop);
-}
-TESTCASE("ExecuteAsynch",
- "Check that executeAsync() works (BUG#27495)\n"){
- INITIALIZER(runTestExecuteAsynch);
-}
-TESTCASE("Bug28443",
- ""){
- INITIALIZER(runBug28443);
-}
-NDBT_TESTSUITE_END(testNdbApi);
-
-int main(int argc, const char** argv){
- ndb_init();
- // TABLE("T1");
- return testNdbApi.execute(argc, argv);
-}
-
-template class Vector<Ndb*>;
-template class Vector<NdbConnection*>;
diff --git a/storage/ndb/test/ndbapi/testNodeRestart.cpp b/storage/ndb/test/ndbapi/testNodeRestart.cpp
deleted file mode 100644
index a760ac58bb8..00000000000
--- a/storage/ndb/test/ndbapi/testNodeRestart.cpp
+++ /dev/null
@@ -1,2517 +0,0 @@
-/* Copyright (c) 2003-2008 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT.hpp>
-#include <NDBT_Test.hpp>
-#include <HugoTransactions.hpp>
-#include <UtilTransactions.hpp>
-#include <NdbRestarter.hpp>
-#include <NdbRestarts.hpp>
-#include <Vector.hpp>
-#include <signaldata/DumpStateOrd.hpp>
-#include <Bitmask.hpp>
-#include <RefConvert.hpp>
-#include <NdbEnv.h>
-
-int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
-
- int records = ctx->getNumRecords();
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.loadTable(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runFillTable(NDBT_Context* ctx, NDBT_Step* step){
-
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.fillTable(GETNDB(step)) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runInsertUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int records = ctx->getNumRecords();
- int i = 0;
- HugoTransactions hugoTrans(*ctx->getTab());
- while (ctx->isTestStopped() == false) {
- g_info << i << ": ";
- if (hugoTrans.loadTable(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- i++;
- }
- return result;
-}
-
-int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
-
- UtilTransactions utilTrans(*ctx->getTab());
- if (utilTrans.clearTable(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runClearTableUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
- int i = 0;
-
- UtilTransactions utilTrans(*ctx->getTab());
- while (ctx->isTestStopped() == false) {
- g_info << i << ": ";
- if (utilTrans.clearTable(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- i++;
- }
- return NDBT_OK;
-}
-
-int runScanReadUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int records = ctx->getNumRecords();
- int i = 0;
- HugoTransactions hugoTrans(*ctx->getTab());
- while (ctx->isTestStopped() == false) {
- g_info << i << ": ";
- if (hugoTrans.scanReadRecords(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- i++;
- }
- return result;
-}
-
-int runPkReadUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int records = ctx->getNumRecords();
- NdbOperation::LockMode lm =
- (NdbOperation::LockMode)ctx->getProperty("ReadLockMode",
- (Uint32)NdbOperation::LM_Read);
- int i = 0;
- HugoTransactions hugoTrans(*ctx->getTab());
- while (ctx->isTestStopped() == false) {
- g_info << i << ": ";
- int rows = (rand()%records)+1;
- int batch = (rand()%rows)+1;
- if (hugoTrans.pkReadRecords(GETNDB(step), rows, batch, lm) != 0){
- return NDBT_FAILED;
- }
- i++;
- }
- return result;
-}
-
-int runPkUpdateUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int records = ctx->getNumRecords();
- int multiop = ctx->getProperty("MULTI_OP", 1);
- Ndb* pNdb = GETNDB(step);
- int i = 0;
-
- HugoOperations hugoOps(*ctx->getTab());
- while (ctx->isTestStopped() == false)
- {
- g_info << i << ": ";
- int batch = (rand()%records)+1;
- int row = rand() % records;
-
- if (batch > 25)
- batch = 25;
-
- if(row + batch > records)
- batch = records - row;
-
- if(hugoOps.startTransaction(pNdb) != 0)
- goto err;
-
- if(hugoOps.pkUpdateRecord(pNdb, row, batch, rand()) != 0)
- goto err;
-
- for (int j = 1; j<multiop; j++)
- {
- if(hugoOps.execute_NoCommit(pNdb) != 0)
- goto err;
-
- if(hugoOps.pkUpdateRecord(pNdb, row, batch, rand()) != 0)
- goto err;
- }
-
- if(hugoOps.execute_Commit(pNdb) != 0)
- goto err;
-
- hugoOps.closeTransaction(pNdb);
-
- continue;
-
-err:
- NdbConnection* pCon = hugoOps.getTransaction();
- if(pCon == 0)
- continue;
- NdbError error = pCon->getNdbError();
- hugoOps.closeTransaction(pNdb);
- if (error.status == NdbError::TemporaryError){
- NdbSleep_MilliSleep(50);
- continue;
- }
- return NDBT_FAILED;
-
- i++;
- }
- return result;
-}
-
-int runPkReadPkUpdateUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int records = ctx->getNumRecords();
- Ndb* pNdb = GETNDB(step);
- int i = 0;
- HugoOperations hugoOps(*ctx->getTab());
- while (ctx->isTestStopped() == false) {
- g_info << i++ << ": ";
- int rows = (rand()%records)+1;
- int batch = (rand()%rows)+1;
- int row = (records - rows) ? rand() % (records - rows) : 0;
-
- int j,k;
- for(j = 0; j<rows; j += batch)
- {
- k = batch;
- if(j+k > rows)
- k = rows - j;
-
- if(hugoOps.startTransaction(pNdb) != 0)
- goto err;
-
- if(hugoOps.pkReadRecord(pNdb, row+j, k, NdbOperation::LM_Exclusive) != 0)
- goto err;
-
- if(hugoOps.execute_NoCommit(pNdb) != 0)
- goto err;
-
- if(hugoOps.pkUpdateRecord(pNdb, row+j, k, rand()) != 0)
- goto err;
-
- if(hugoOps.execute_Commit(pNdb) != 0)
- goto err;
-
- if(hugoOps.closeTransaction(pNdb) != 0)
- return NDBT_FAILED;
- }
-
- continue;
-err:
- NdbConnection* pCon = hugoOps.getTransaction();
- if(pCon == 0)
- continue;
- NdbError error = pCon->getNdbError();
- hugoOps.closeTransaction(pNdb);
- if (error.status == NdbError::TemporaryError){
- NdbSleep_MilliSleep(50);
- continue;
- }
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runScanUpdateUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int records = ctx->getNumRecords();
- int parallelism = ctx->getProperty("Parallelism", 1);
- int abort = ctx->getProperty("AbortProb", (Uint32)0);
- int i = 0;
- HugoTransactions hugoTrans(*ctx->getTab());
- while (ctx->isTestStopped() == false) {
- g_info << i << ": ";
- if (hugoTrans.scanUpdateRecords(GETNDB(step), records, abort,
- parallelism) == NDBT_FAILED){
- return NDBT_FAILED;
- }
- i++;
- }
- return result;
-}
-
-int runScanReadVerify(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
- HugoTransactions hugoTrans(*ctx->getTab());
-
- if (hugoTrans.scanReadRecords(GETNDB(step), records, 0, 64) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runRestarter(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int sync_threads = ctx->getProperty("SyncThreads", (unsigned)0);
- NdbRestarter restarter;
- int i = 0;
- int lastId = 0;
-
- if (restarter.getNumDbNodes() < 2){
- ctx->stopTest();
- return NDBT_OK;
- }
-
- if(restarter.waitClusterStarted() != 0){
- g_err << "Cluster failed to start" << endl;
- return NDBT_FAILED;
- }
-
- loops *= restarter.getNumDbNodes();
- while(i<loops && result != NDBT_FAILED && !ctx->isTestStopped()){
-
- int id = lastId % restarter.getNumDbNodes();
- int nodeId = restarter.getDbNodeId(id);
- ndbout << "Restart node " << nodeId << endl;
- if(restarter.restartOneDbNode(nodeId, false, true, true) != 0){
- g_err << "Failed to restartNextDbNode" << endl;
- result = NDBT_FAILED;
- break;
- }
-
- if (restarter.waitNodesNoStart(&nodeId, 1))
- {
- g_err << "Failed to waitNodesNoStart" << endl;
- result = NDBT_FAILED;
- break;
- }
-
- if (restarter.startNodes(&nodeId, 1))
- {
- g_err << "Failed to start node" << endl;
- result = NDBT_FAILED;
- break;
- }
-
- if(restarter.waitClusterStarted() != 0){
- g_err << "Cluster failed to start" << endl;
- result = NDBT_FAILED;
- break;
- }
-
- ctx->sync_up_and_wait("PauseThreads", sync_threads);
-
- lastId++;
- i++;
- }
-
- ctx->stopTest();
-
- return result;
-}
-
-int runCheckAllNodesStarted(NDBT_Context* ctx, NDBT_Step* step){
- NdbRestarter restarter;
-
- if(restarter.waitClusterStarted(1) != 0){
- g_err << "All nodes was not started " << endl;
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-
-
-int runRestarts(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- NDBT_TestCase* pCase = ctx->getCase();
- NdbRestarts restarts;
- int i = 0;
- int timeout = 240;
-
- while(i<loops && result != NDBT_FAILED && !ctx->isTestStopped()){
-
- if(restarts.executeRestart(pCase->getName(), timeout) != 0){
- g_err << "Failed to executeRestart(" <<pCase->getName() <<")" << endl;
- result = NDBT_FAILED;
- break;
- }
- i++;
- }
- ctx->stopTest();
- return result;
-}
-
-int runDirtyRead(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- NdbRestarter restarter;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- int i = 0;
- while(i<loops && result != NDBT_FAILED && !ctx->isTestStopped()){
- g_info << i << ": ";
-
- int id = i % restarter.getNumDbNodes();
- int nodeId = restarter.getDbNodeId(id);
- ndbout << "Restart node " << nodeId << endl;
- restarter.insertErrorInNode(nodeId, 5041);
- restarter.insertErrorInAllNodes(8048 + (i & 1));
-
- for(int j = 0; j<records; j++){
- if(hugoOps.startTransaction(pNdb) != 0)
- return NDBT_FAILED;
-
- if(hugoOps.pkReadRecord(pNdb, j, 1, NdbOperation::LM_CommittedRead) != 0)
- goto err;
-
- int res;
- if((res = hugoOps.execute_Commit(pNdb)) == 4119)
- goto done;
-
- if(res != 0)
- goto err;
-
- if(hugoOps.closeTransaction(pNdb) != 0)
- return NDBT_FAILED;
- }
-done:
- if(hugoOps.closeTransaction(pNdb) != 0)
- return NDBT_FAILED;
-
- i++;
- restarter.waitClusterStarted(60) ;
- }
- return result;
-err:
- hugoOps.closeTransaction(pNdb);
- return NDBT_FAILED;
-}
-
-int runLateCommit(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- NdbRestarter restarter;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- int i = 0;
- while(i<loops && result != NDBT_FAILED && !ctx->isTestStopped()){
- g_info << i << ": ";
-
- if(hugoOps.startTransaction(pNdb) != 0)
- return NDBT_FAILED;
-
- if(hugoOps.pkUpdateRecord(pNdb, 1, 128) != 0)
- return NDBT_FAILED;
-
- if(hugoOps.execute_NoCommit(pNdb) != 0)
- return NDBT_FAILED;
-
- Uint32 transNode= hugoOps.getTransaction()->getConnectedNodeId();
- int id = i % restarter.getNumDbNodes();
- int nodeId;
- while((nodeId = restarter.getDbNodeId(id)) == transNode)
- id = (id + 1) % restarter.getNumDbNodes();
-
- ndbout << "Restart node " << nodeId << endl;
-
- restarter.restartOneDbNode(nodeId,
- /** initial */ false,
- /** nostart */ true,
- /** abort */ true);
-
- restarter.waitNodesNoStart(&nodeId, 1);
-
- int res;
- if(i & 1)
- res= hugoOps.execute_Commit(pNdb);
- else
- res= hugoOps.execute_Rollback(pNdb);
-
- ndbout_c("res= %d", res);
-
- hugoOps.closeTransaction(pNdb);
-
- restarter.startNodes(&nodeId, 1);
- restarter.waitNodesStarted(&nodeId, 1);
-
- if(i & 1)
- {
- if(res != 286)
- return NDBT_FAILED;
- }
- else
- {
- if(res != 0)
- return NDBT_FAILED;
- }
- i++;
- }
-
- return NDBT_OK;
-}
-
-int runBug15587(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- NdbRestarter restarter;
-
- Uint32 tableId = ctx->getTab()->getTableId();
- int dump[2] = { DumpStateOrd::LqhErrorInsert5042, 0 };
- dump[1] = tableId;
-
- int nodeId = restarter.getDbNodeId(1);
-
- ndbout << "Restart node " << nodeId << endl;
-
- if (restarter.restartOneDbNode(nodeId,
- /** initial */ false,
- /** nostart */ true,
- /** abort */ true))
- return NDBT_FAILED;
-
- if (restarter.waitNodesNoStart(&nodeId, 1))
- return NDBT_FAILED;
-
- int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
-
- if (restarter.dumpStateOneNode(nodeId, val2, 2))
- return NDBT_FAILED;
-
- if (restarter.dumpStateOneNode(nodeId, dump, 2))
- return NDBT_FAILED;
-
- if (restarter.startNodes(&nodeId, 1))
- return NDBT_FAILED;
-
- restarter.waitNodesStartPhase(&nodeId, 1, 3);
-
- if (restarter.waitNodesNoStart(&nodeId, 1))
- return NDBT_FAILED;
-
- if (restarter.dumpStateOneNode(nodeId, val2, 1))
- return NDBT_FAILED;
-
- if (restarter.startNodes(&nodeId, 1))
- return NDBT_FAILED;
-
- if (restarter.waitNodesStarted(&nodeId, 1))
- return NDBT_FAILED;
-
- ctx->stopTest();
- return NDBT_OK;
-}
-
-int runBug15632(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- NdbRestarter restarter;
-
- int nodeId = restarter.getDbNodeId(1);
-
- ndbout << "Restart node " << nodeId << endl;
-
- if (restarter.restartOneDbNode(nodeId,
- /** initial */ false,
- /** nostart */ true,
- /** abort */ true))
- return NDBT_FAILED;
-
- if (restarter.waitNodesNoStart(&nodeId, 1))
- return NDBT_FAILED;
-
- if (restarter.insertErrorInNode(nodeId, 7165))
- return NDBT_FAILED;
-
- if (restarter.startNodes(&nodeId, 1))
- return NDBT_FAILED;
-
- if (restarter.waitNodesStarted(&nodeId, 1))
- return NDBT_FAILED;
-
- if (restarter.restartOneDbNode(nodeId,
- /** initial */ false,
- /** nostart */ true,
- /** abort */ true))
- return NDBT_FAILED;
-
- if (restarter.waitNodesNoStart(&nodeId, 1))
- return NDBT_FAILED;
-
- if (restarter.insertErrorInNode(nodeId, 7171))
- return NDBT_FAILED;
-
- if (restarter.startNodes(&nodeId, 1))
- return NDBT_FAILED;
-
- if (restarter.waitNodesStarted(&nodeId, 1))
- return NDBT_FAILED;
-
- ctx->stopTest();
- return NDBT_OK;
-}
-
-int runBug15685(NDBT_Context* ctx, NDBT_Step* step){
-
- Ndb* pNdb = GETNDB(step);
- HugoOperations hugoOps(*ctx->getTab());
- NdbRestarter restarter;
-
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.loadTable(GETNDB(step), 10) != 0){
- return NDBT_FAILED;
- }
-
- if(hugoOps.startTransaction(pNdb) != 0)
- goto err;
-
- if(hugoOps.pkUpdateRecord(pNdb, 0, 1, rand()) != 0)
- goto err;
-
- if(hugoOps.execute_NoCommit(pNdb) != 0)
- goto err;
-
- if (restarter.insertErrorInAllNodes(5100))
- return NDBT_FAILED;
-
- hugoOps.execute_Rollback(pNdb);
-
- if (restarter.waitClusterStarted() != 0)
- goto err;
-
- if (restarter.insertErrorInAllNodes(0))
- return NDBT_FAILED;
-
- ctx->stopTest();
- return NDBT_OK;
-
-err:
- ctx->stopTest();
- return NDBT_FAILED;
-}
-
-int
-runBug16772(NDBT_Context* ctx, NDBT_Step* step){
-
- NdbRestarter restarter;
- if (restarter.getNumDbNodes() < 2)
- {
- ctx->stopTest();
- return NDBT_OK;
- }
-
- int aliveNodeId = restarter.getRandomNotMasterNodeId(rand());
- int deadNodeId = aliveNodeId;
- while (deadNodeId == aliveNodeId)
- deadNodeId = restarter.getDbNodeId(rand() % restarter.getNumDbNodes());
-
- if (restarter.insertErrorInNode(aliveNodeId, 930))
- return NDBT_FAILED;
-
- if (restarter.restartOneDbNode(deadNodeId,
- /** initial */ false,
- /** nostart */ true,
- /** abort */ true))
- return NDBT_FAILED;
-
- if (restarter.waitNodesNoStart(&deadNodeId, 1))
- return NDBT_FAILED;
-
- if (restarter.startNodes(&deadNodeId, 1))
- return NDBT_FAILED;
-
- // It should now be hanging since we throw away NDB_FAILCONF
- int ret = restarter.waitNodesStartPhase(&deadNodeId, 1, 3, 10);
- // So this should fail...i.e it should not reach startphase 3
-
- // Now send a NDB_FAILCONF for deadNo
- int dump[] = { 7020, 323, 252, 0 };
- dump[3] = deadNodeId;
- if (restarter.dumpStateOneNode(aliveNodeId, dump, 4))
- return NDBT_FAILED;
-
- if (restarter.waitNodesStarted(&deadNodeId, 1))
- return NDBT_FAILED;
-
- return ret ? NDBT_OK : NDBT_FAILED;
-}
-
-int
-runBug18414(NDBT_Context* ctx, NDBT_Step* step){
-
- NdbRestarter restarter;
- if (restarter.getNumDbNodes() < 2)
- {
- ctx->stopTest();
- return NDBT_OK;
- }
-
- Ndb* pNdb = GETNDB(step);
- HugoOperations hugoOps(*ctx->getTab());
- HugoTransactions hugoTrans(*ctx->getTab());
- int loop = 0;
- do
- {
- if(hugoOps.startTransaction(pNdb) != 0)
- goto err;
-
- if(hugoOps.pkUpdateRecord(pNdb, 0, 128, rand()) != 0)
- goto err;
-
- if(hugoOps.execute_NoCommit(pNdb) != 0)
- goto err;
-
- int node1 = hugoOps.getTransaction()->getConnectedNodeId();
- int node2 = restarter.getRandomNodeSameNodeGroup(node1, rand());
-
- if (node1 == -1 || node2 == -1)
- break;
-
- if (loop & 1)
- {
- if (restarter.insertErrorInNode(node1, 8050))
- goto err;
- }
-
- int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
- if (restarter.dumpStateOneNode(node2, val2, 2))
- goto err;
-
- if (restarter.insertErrorInNode(node2, 5003))
- goto err;
-
- int res= hugoOps.execute_Rollback(pNdb);
-
- if (restarter.waitNodesNoStart(&node2, 1) != 0)
- goto err;
-
- if (restarter.insertErrorInAllNodes(0))
- goto err;
-
- if (restarter.startNodes(&node2, 1) != 0)
- goto err;
-
- if (restarter.waitClusterStarted() != 0)
- goto err;
-
- if (hugoTrans.scanUpdateRecords(pNdb, 128) != 0)
- goto err;
-
- hugoOps.closeTransaction(pNdb);
-
- } while(++loop < 5);
-
- return NDBT_OK;
-
-err:
- hugoOps.closeTransaction(pNdb);
- return NDBT_FAILED;
-}
-
-int
-runBug18612(NDBT_Context* ctx, NDBT_Step* step){
-
- // Assume two replicas
- NdbRestarter restarter;
- if (restarter.getNumDbNodes() < 2)
- {
- ctx->stopTest();
- return NDBT_OK;
- }
-
- Uint32 cnt = restarter.getNumDbNodes();
-
- for(int loop = 0; loop < ctx->getNumLoops(); loop++)
- {
- int partition0[256];
- int partition1[256];
- bzero(partition0, sizeof(partition0));
- bzero(partition1, sizeof(partition1));
- Bitmask<4> nodesmask;
-
- Uint32 node1 = restarter.getDbNodeId(rand()%cnt);
- for (Uint32 i = 0; i<cnt/2; i++)
- {
- do {
- int tmp = restarter.getRandomNodeOtherNodeGroup(node1, rand());
- if (tmp == -1)
- {
- ctx->stopTest();
- return NDBT_OK;
- }
- node1 = tmp;
- } while(nodesmask.get(node1));
-
- partition0[i] = node1;
- partition1[i] = restarter.getRandomNodeSameNodeGroup(node1, rand());
-
- ndbout_c("nodes %d %d", node1, partition1[i]);
-
- assert(!nodesmask.get(node1));
- assert(!nodesmask.get(partition1[i]));
- nodesmask.set(node1);
- nodesmask.set(partition1[i]);
- }
-
- ndbout_c("done");
-
- int dump[255];
- dump[0] = DumpStateOrd::NdbcntrStopNodes;
- memcpy(dump + 1, partition0, sizeof(int)*cnt/2);
-
- Uint32 master = restarter.getMasterNodeId();
-
- if (restarter.dumpStateOneNode(master, dump, 1+cnt/2))
- return NDBT_FAILED;
-
- if (restarter.waitNodesNoStart(partition0, cnt/2))
- return NDBT_FAILED;
-
- int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
-
- if (restarter.dumpStateAllNodes(val2, 2))
- return NDBT_FAILED;
-
- if (restarter.insertErrorInAllNodes(932))
- return NDBT_FAILED;
-
- dump[0] = 9000;
- memcpy(dump + 1, partition0, sizeof(int)*cnt/2);
- for (Uint32 i = 0; i<cnt/2; i++)
- if (restarter.dumpStateOneNode(partition1[i], dump, 1+cnt/2))
- return NDBT_FAILED;
-
- dump[0] = 9000;
- memcpy(dump + 1, partition1, sizeof(int)*cnt/2);
- for (Uint32 i = 0; i<cnt/2; i++)
- if (restarter.dumpStateOneNode(partition0[i], dump, 1+cnt/2))
- return NDBT_FAILED;
-
- if (restarter.startNodes(partition0, cnt/2))
- return NDBT_FAILED;
-
- if (restarter.waitNodesStartPhase(partition0, cnt/2, 2))
- return NDBT_FAILED;
-
- dump[0] = 9001;
- for (Uint32 i = 0; i<cnt/2; i++)
- if (restarter.dumpStateAllNodes(dump, 2))
- return NDBT_FAILED;
-
- if (restarter.waitNodesNoStart(partition0, cnt/2))
- return NDBT_FAILED;
-
- for (Uint32 i = 0; i<cnt/2; i++)
- if (restarter.restartOneDbNode(partition0[i], true, true, true))
- return NDBT_FAILED;
-
- if (restarter.waitNodesNoStart(partition0, cnt/2))
- return NDBT_FAILED;
-
- if (restarter.startAll())
- return NDBT_FAILED;
-
- if (restarter.waitClusterStarted())
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int
-runBug18612SR(NDBT_Context* ctx, NDBT_Step* step){
-
- // Assume two replicas
- NdbRestarter restarter;
- if (restarter.getNumDbNodes() < 2)
- {
- ctx->stopTest();
- return NDBT_OK;
- }
-
- Uint32 cnt = restarter.getNumDbNodes();
-
- for(int loop = 0; loop < ctx->getNumLoops(); loop++)
- {
- int partition0[256];
- int partition1[256];
- bzero(partition0, sizeof(partition0));
- bzero(partition1, sizeof(partition1));
- Bitmask<4> nodesmask;
-
- Uint32 node1 = restarter.getDbNodeId(rand()%cnt);
- for (Uint32 i = 0; i<cnt/2; i++)
- {
- do {
- int tmp = restarter.getRandomNodeOtherNodeGroup(node1, rand());
- if (tmp == -1)
- break;
- node1 = tmp;
- } while(nodesmask.get(node1));
-
- partition0[i] = node1;
- partition1[i] = restarter.getRandomNodeSameNodeGroup(node1, rand());
-
- ndbout_c("nodes %d %d", node1, partition1[i]);
-
- assert(!nodesmask.get(node1));
- assert(!nodesmask.get(partition1[i]));
- nodesmask.set(node1);
- nodesmask.set(partition1[i]);
- }
-
- ndbout_c("done");
-
- if (restarter.restartAll(false, true, false))
- return NDBT_FAILED;
-
- int dump[255];
- dump[0] = 9000;
- memcpy(dump + 1, partition0, sizeof(int)*cnt/2);
- for (Uint32 i = 0; i<cnt/2; i++)
- if (restarter.dumpStateOneNode(partition1[i], dump, 1+cnt/2))
- return NDBT_FAILED;
-
- dump[0] = 9000;
- memcpy(dump + 1, partition1, sizeof(int)*cnt/2);
- for (Uint32 i = 0; i<cnt/2; i++)
- if (restarter.dumpStateOneNode(partition0[i], dump, 1+cnt/2))
- return NDBT_FAILED;
-
- int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
-
- if (restarter.dumpStateAllNodes(val2, 2))
- return NDBT_FAILED;
-
- if (restarter.insertErrorInAllNodes(932))
- return NDBT_FAILED;
-
- if (restarter.startAll())
- return NDBT_FAILED;
-
- if (restarter.waitClusterStartPhase(2))
- return NDBT_FAILED;
-
- dump[0] = 9001;
- for (Uint32 i = 0; i<cnt/2; i++)
- if (restarter.dumpStateAllNodes(dump, 2))
- return NDBT_FAILED;
-
- if (restarter.waitClusterNoStart(30))
- if (restarter.waitNodesNoStart(partition0, cnt/2, 10))
- if (restarter.waitNodesNoStart(partition1, cnt/2, 10))
- return NDBT_FAILED;
-
- if (restarter.startAll())
- return NDBT_FAILED;
-
- if (restarter.waitClusterStarted())
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runBug20185(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- NdbRestarter restarter;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- const int masterNode = restarter.getMasterNodeId();
-
- int dump[] = { 7090, 20 } ;
- if (restarter.dumpStateAllNodes(dump, 2))
- return NDBT_FAILED;
-
- NdbSleep_MilliSleep(3000);
- Vector<int> nodes;
- for (Uint32 i = 0; i<restarter.getNumDbNodes(); i++)
- nodes.push_back(restarter.getDbNodeId(i));
-
-retry:
- if(hugoOps.startTransaction(pNdb) != 0)
- return NDBT_FAILED;
-
- if(hugoOps.pkUpdateRecord(pNdb, 1, 1) != 0)
- return NDBT_FAILED;
-
- if (hugoOps.execute_NoCommit(pNdb) != 0)
- return NDBT_FAILED;
-
- const int node = hugoOps.getTransaction()->getConnectedNodeId();
- if (node != masterNode)
- {
- hugoOps.closeTransaction(pNdb);
- goto retry;
- }
-
- int nodeId;
- do {
- nodeId = restarter.getDbNodeId(rand() % restarter.getNumDbNodes());
- } while (nodeId == node);
-
- ndbout_c("7031 to %d", nodeId);
- if (restarter.insertErrorInNode(nodeId, 7031))
- return NDBT_FAILED;
-
- for (Uint32 i = 0; i<nodes.size(); i++)
- {
- if (nodes[i] != nodeId)
- if (restarter.insertErrorInNode(nodes[i], 7030))
- return NDBT_FAILED;
- }
-
- NdbSleep_MilliSleep(500);
-
- if (hugoOps.execute_Commit(pNdb) == 0)
- return NDBT_FAILED;
-
- NdbSleep_MilliSleep(3000);
-
- restarter.waitClusterStarted();
-
- if (restarter.dumpStateAllNodes(dump, 1))
- return NDBT_FAILED;
-
- return NDBT_OK;
-}
-
-int runBug24717(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- NdbRestarter restarter;
- Ndb* pNdb = GETNDB(step);
-
- HugoTransactions hugoTrans(*ctx->getTab());
-
- int dump[] = { 9002, 0 } ;
- Uint32 ownNode = refToNode(pNdb->getReference());
- dump[1] = ownNode;
-
- for (; loops; loops --)
- {
- int nodeId = restarter.getRandomNotMasterNodeId(rand());
- restarter.restartOneDbNode(nodeId, false, true, true);
- restarter.waitNodesNoStart(&nodeId, 1);
-
- if (restarter.dumpStateOneNode(nodeId, dump, 2))
- return NDBT_FAILED;
-
- restarter.startNodes(&nodeId, 1);
-
- do {
- for (Uint32 i = 0; i < 100; i++)
- {
- hugoTrans.pkReadRecords(pNdb, 100, 1, NdbOperation::LM_CommittedRead);
- }
- } while (restarter.waitClusterStarted(5) != 0);
- }
-
- return NDBT_OK;
-}
-
-int
-runBug29364(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- NdbRestarter restarter;
- Ndb* pNdb = GETNDB(step);
-
- HugoTransactions hugoTrans(*ctx->getTab());
-
- if (restarter.getNumDbNodes() < 4)
- return NDBT_OK;
-
- int dump0[] = { 9000, 0 } ;
- int dump1[] = { 9001, 0 } ;
- Uint32 ownNode = refToNode(pNdb->getReference());
- dump0[1] = ownNode;
-
- for (; loops; loops --)
- {
- int node0 = restarter.getDbNodeId(rand() % restarter.getNumDbNodes());
- int node1 = restarter.getRandomNodeOtherNodeGroup(node0, rand());
-
- restarter.restartOneDbNode(node0, false, true, true);
- restarter.waitNodesNoStart(&node0, 1);
- restarter.startNodes(&node0, 1);
- restarter.waitClusterStarted();
-
- restarter.restartOneDbNode(node1, false, true, true);
- restarter.waitNodesNoStart(&node1, 1);
- if (restarter.dumpStateOneNode(node1, dump0, 2))
- return NDBT_FAILED;
-
- restarter.startNodes(&node1, 1);
-
- do {
-
- for (Uint32 i = 0; i < 100; i++)
- {
- hugoTrans.pkReadRecords(pNdb, 100, 1, NdbOperation::LM_CommittedRead);
- }
- } while (restarter.waitClusterStarted(5) != 0);
-
- if (restarter.dumpStateOneNode(node1, dump1, 1))
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-int runBug25364(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- NdbRestarter restarter;
- Ndb* pNdb = GETNDB(step);
- int loops = ctx->getNumLoops();
-
- if (restarter.getNumDbNodes() < 4)
- return NDBT_OK;
-
- int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
-
- for (; loops; loops --)
- {
- int master = restarter.getMasterNodeId();
- int victim = restarter.getRandomNodeOtherNodeGroup(master, rand());
- int second = restarter.getRandomNodeSameNodeGroup(victim, rand());
-
- int dump[] = { 935, victim } ;
- if (restarter.dumpStateOneNode(master, dump, 2))
- return NDBT_FAILED;
-
- if (restarter.dumpStateOneNode(master, val2, 2))
- return NDBT_FAILED;
-
- if (restarter.restartOneDbNode(second, false, true, true))
- return NDBT_FAILED;
-
- int nodes[2] = { master, second };
- if (restarter.waitNodesNoStart(nodes, 2))
- return NDBT_FAILED;
-
- restarter.startNodes(nodes, 2);
-
- if (restarter.waitNodesStarted(nodes, 2))
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-int
-runBug21271(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- NdbRestarter restarter;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- const int masterNode = restarter.getMasterNodeId();
- const int nodeId = restarter.getRandomNodeSameNodeGroup(masterNode, rand());
-
- int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
- if (restarter.dumpStateOneNode(nodeId, val2, 2))
- return NDBT_FAILED;
-
- Uint32 tableId = ctx->getTab()->getTableId();
- int dump[] = { DumpStateOrd::LqhErrorInsert5042, 0, 5044 };
- dump[1] = tableId;
-
- if (restarter.dumpStateOneNode(nodeId, dump, 3))
- return NDBT_FAILED;
-
- restarter.waitNodesNoStart(&nodeId, 1);
- ctx->stopTest();
-
- restarter.startNodes(&nodeId, 1);
-
- if (restarter.waitClusterStarted() != 0)
- return NDBT_FAILED;
-
- return NDBT_OK;
- return NDBT_OK;
-}
-
-int
-runBug24543(NDBT_Context* ctx, NDBT_Step* step){
- NdbRestarter restarter;
-
- int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
- if (restarter.dumpStateAllNodes(val2, 2))
- return NDBT_FAILED;
-
- int nodes[2];
- nodes[0] = restarter.getMasterNodeId();
- restarter.insertErrorInNode(nodes[0], 934);
-
- nodes[1] = restarter.getRandomNodeOtherNodeGroup(nodes[0], rand());
- if (nodes[1] == -1)
- {
- nodes[1] = restarter.getRandomNodeSameNodeGroup(nodes[0], rand());
- }
-
- restarter.restartOneDbNode(nodes[1], false, true, true);
- if (restarter.waitNodesNoStart(nodes, 2))
- return NDBT_FAILED;
-
- restarter.startNodes(nodes, 2);
- if (restarter.waitNodesStarted(nodes, 2))
- {
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runBug25468(NDBT_Context* ctx, NDBT_Step* step){
-
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- NdbRestarter restarter;
-
- for (int i = 0; i<loops; i++)
- {
- int master = restarter.getMasterNodeId();
- int node1, node2;
- switch(i % 5){
- case 0:
- node1 = master;
- node2 = restarter.getRandomNodeSameNodeGroup(master, rand());
- break;
- case 1:
- node1 = restarter.getRandomNodeSameNodeGroup(master, rand());
- node2 = master;
- break;
- case 2:
- case 3:
- case 4:
- node1 = restarter.getRandomNodeOtherNodeGroup(master, rand());
- if (node1 == -1)
- node1 = master;
- node2 = restarter.getRandomNodeSameNodeGroup(node1, rand());
- break;
- }
-
- ndbout_c("node1: %d node2: %d master: %d", node1, node2, master);
-
- int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
-
- if (restarter.dumpStateOneNode(node2, val2, 2))
- return NDBT_FAILED;
-
- if (restarter.insertErrorInNode(node1, 7178))
- return NDBT_FAILED;
-
- int val1 = 7099;
- if (restarter.dumpStateOneNode(master, &val1, 1))
- return NDBT_FAILED;
-
- if (restarter.waitNodesNoStart(&node2, 1))
- return NDBT_FAILED;
-
- if (restarter.startAll())
- return NDBT_FAILED;
-
- if (restarter.waitClusterStarted())
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-int runBug25554(NDBT_Context* ctx, NDBT_Step* step){
-
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- NdbRestarter restarter;
-
- if (restarter.getNumDbNodes() < 4)
- return NDBT_OK;
-
- for (int i = 0; i<loops; i++)
- {
- int master = restarter.getMasterNodeId();
- int node1 = restarter.getRandomNodeOtherNodeGroup(master, rand());
- restarter.restartOneDbNode(node1, false, true, true);
-
- int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
-
- if (restarter.dumpStateOneNode(master, val2, 2))
- return NDBT_FAILED;
-
- if (restarter.insertErrorInNode(master, 7141))
- return NDBT_FAILED;
-
- if (restarter.waitNodesNoStart(&node1, 1))
- return NDBT_FAILED;
-
- if (restarter.dumpStateOneNode(node1, val2, 2))
- return NDBT_FAILED;
-
- if (restarter.insertErrorInNode(node1, 932))
- return NDBT_FAILED;
-
- if (restarter.startNodes(&node1, 1))
- return NDBT_FAILED;
-
- int nodes[] = { master, node1 };
- if (restarter.waitNodesNoStart(nodes, 2))
- return NDBT_FAILED;
-
- if (restarter.startNodes(nodes, 2))
- return NDBT_FAILED;
-
- if (restarter.waitClusterStarted())
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-int runBug25984(NDBT_Context* ctx, NDBT_Step* step){
-
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- NdbRestarter restarter;
-
- if (restarter.getNumDbNodes() < 2)
- return NDBT_OK;
-
- if (restarter.restartAll(true, true, true))
- return NDBT_FAILED;
-
- if (restarter.waitClusterNoStart())
- return NDBT_FAILED;
-
- if (restarter.startAll())
- return NDBT_FAILED;
-
- if (restarter.waitClusterStarted())
- return NDBT_FAILED;
-
- int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
- int master = restarter.getMasterNodeId();
- int victim = restarter.getRandomNodeOtherNodeGroup(master, rand());
- if (victim == -1)
- victim = restarter.getRandomNodeSameNodeGroup(master, rand());
-
- restarter.restartOneDbNode(victim, false, true, true);
-
- for (Uint32 i = 0; i<6; i++)
- {
- ndbout_c("Loop: %d", i);
- if (restarter.waitNodesNoStart(&victim, 1))
- return NDBT_FAILED;
-
- if (restarter.dumpStateOneNode(victim, val2, 2))
- return NDBT_FAILED;
-
- if (restarter.insertErrorInNode(victim, 7016))
- return NDBT_FAILED;
-
- if (restarter.startNodes(&victim, 1))
- return NDBT_FAILED;
-
- NdbSleep_SecSleep(3);
- }
-
- if (restarter.waitNodesNoStart(&victim, 1))
- return NDBT_FAILED;
-
- if (restarter.dumpStateOneNode(victim, val2, 2))
- return NDBT_FAILED;
-
- if (restarter.insertErrorInNode(victim, 7170))
- return NDBT_FAILED;
-
- if (restarter.startNodes(&victim, 1))
- return NDBT_FAILED;
-
- if (restarter.waitNodesNoStart(&victim, 1))
- return NDBT_FAILED;
-
- if (restarter.restartAll(false, true, true))
- return NDBT_FAILED;
-
- if (restarter.insertErrorInAllNodes(932))
- return NDBT_FAILED;
-
- if (restarter.insertErrorInNode(master, 7170))
- return NDBT_FAILED;
-
- if (restarter.dumpStateAllNodes(val2, 2))
- return NDBT_FAILED;
-
- restarter.startNodes(&master, 1);
- NdbSleep_MilliSleep(3000);
- restarter.startAll();
-
- if (restarter.waitClusterNoStart())
- return NDBT_FAILED;
-
- if (restarter.restartOneDbNode(victim, true, true, true))
- return NDBT_FAILED;
-
- if (restarter.startAll())
- return NDBT_FAILED;
-
- if (restarter.waitClusterStarted())
- return NDBT_FAILED;
-
- return NDBT_OK;
-}
-
-int
-runBug26457(NDBT_Context* ctx, NDBT_Step* step)
-{
- NdbRestarter res;
- if (res.getNumDbNodes() < 4)
- return NDBT_OK;
-
- int loops = ctx->getNumLoops();
- while (loops --)
- {
-retry:
- int master = res.getMasterNodeId();
- int next = res.getNextMasterNodeId(master);
-
- ndbout_c("master: %d next: %d", master, next);
-
- if (res.getNodeGroup(master) == res.getNodeGroup(next))
- {
- res.restartOneDbNode(next, false, false, true);
- if (res.waitClusterStarted())
- return NDBT_FAILED;
- goto retry;
- }
-
- int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 2 };
-
- if (res.dumpStateOneNode(next, val2, 2))
- return NDBT_FAILED;
-
- if (res.insertErrorInNode(next, 7180))
- return NDBT_FAILED;
-
- res.restartOneDbNode(master, false, false, true);
- if (res.waitClusterStarted())
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-int
-runBug26481(NDBT_Context* ctx, NDBT_Step* step)
-{
-
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- NdbRestarter res;
-
- int node = res.getRandomNotMasterNodeId(rand());
- ndbout_c("node: %d", node);
- if (res.restartOneDbNode(node, true, true, true))
- return NDBT_FAILED;
-
- if (res.waitNodesNoStart(&node, 1))
- return NDBT_FAILED;
-
- int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
- if (res.dumpStateOneNode(node, val2, 2))
- return NDBT_FAILED;
-
- if (res.insertErrorInNode(node, 7018))
- return NDBT_FAILED;
-
- if (res.startNodes(&node, 1))
- return NDBT_FAILED;
-
- res.waitNodesStartPhase(&node, 1, 3);
-
- if (res.waitNodesNoStart(&node, 1))
- return NDBT_FAILED;
-
- res.startNodes(&node, 1);
-
- if (res.waitClusterStarted())
- return NDBT_FAILED;
-
- return NDBT_OK;
-}
-
-int
-runBug26450(NDBT_Context* ctx, NDBT_Step* step)
-{
- Uint32 i;
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- NdbRestarter res;
- Ndb* pNdb = GETNDB(step);
-
- int node = res.getRandomNotMasterNodeId(rand());
- Vector<int> nodes;
- for (unsigned i = 0; i<res.getNumDbNodes(); i++)
- {
- if (res.getDbNodeId(i) != node)
- nodes.push_back(res.getDbNodeId(i));
- }
-
- if (res.restartAll())
- return NDBT_FAILED;
-
- if (res.waitClusterStarted())
- return NDBT_FAILED;
-
- ndbout_c("node: %d", node);
- if (res.restartOneDbNode(node, false, true, true))
- return NDBT_FAILED;
-
- if (res.waitNodesNoStart(&node, 1))
- return NDBT_FAILED;
-
- if (runClearTable(ctx, step))
- return NDBT_FAILED;
-
- for (i = 0; i < 2; i++)
- {
- if (res.restartAll(false, true, i > 0))
- return NDBT_FAILED;
-
- if (res.waitClusterNoStart())
- return NDBT_FAILED;
-
- if (res.startNodes(nodes.getBase(), nodes.size()))
- return NDBT_FAILED;
-
- if (res.waitNodesStarted(nodes.getBase(), nodes.size()))
- return NDBT_FAILED;
- }
-
- if (res.startNodes(&node, 1))
- return NDBT_FAILED;
-
- if (res.waitNodesStarted(&node, 1))
- return NDBT_FAILED;
-
- HugoTransactions trans (* ctx->getTab());
- if (trans.selectCount(pNdb) != 0)
- return NDBT_FAILED;
-
- return NDBT_OK;
-}
-
-int
-runBug27003(NDBT_Context* ctx, NDBT_Step* step)
-{
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- NdbRestarter res;
-
- static const int errnos[] = { 4025, 4026, 4027, 4028, 0 };
-
- int node = res.getRandomNotMasterNodeId(rand());
- ndbout_c("node: %d", node);
- if (res.restartOneDbNode(node, true, true, true))
- return NDBT_FAILED;
-
- Uint32 pos = 0;
- for (Uint32 i = 0; i<loops; i++)
- {
- while (errnos[pos] != 0)
- {
- ndbout_c("Tesing err: %d", errnos[pos]);
-
- if (res.waitNodesNoStart(&node, 1))
- return NDBT_FAILED;
-
- if (res.insertErrorInNode(node, 1000))
- return NDBT_FAILED;
-
- if (res.insertErrorInNode(node, errnos[pos]))
- return NDBT_FAILED;
-
- int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 3 };
- if (res.dumpStateOneNode(node, val2, 2))
- return NDBT_FAILED;
-
- res.startNodes(&node, 1);
- NdbSleep_SecSleep(3);
- pos++;
- }
- pos = 0;
- }
-
- if (res.waitNodesNoStart(&node, 1))
- return NDBT_FAILED;
-
- res.startNodes(&node, 1);
- if (res.waitClusterStarted())
- return NDBT_FAILED;
-
- return NDBT_OK;
-}
-
-
-int
-runBug27283(NDBT_Context* ctx, NDBT_Step* step)
-{
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- NdbRestarter res;
-
- if (res.getNumDbNodes() < 2)
- {
- return NDBT_OK;
- }
-
- static const int errnos[] = { 7181, 7182, 0 };
-
- Uint32 pos = 0;
- for (Uint32 i = 0; i<loops; i++)
- {
- while (errnos[pos] != 0)
- {
- int master = res.getMasterNodeId();
- int next = res.getNextMasterNodeId(master);
- int next2 = res.getNextMasterNodeId(next);
-
- int node = (i & 1) ? next : next2;
- ndbout_c("Tesing err: %d", errnos[pos]);
- if (res.insertErrorInNode(next, errnos[pos]))
- return NDBT_FAILED;
-
- NdbSleep_SecSleep(3);
-
- if (res.waitClusterStarted())
- return NDBT_FAILED;
-
- pos++;
- }
- pos = 0;
- }
-
- return NDBT_OK;
-}
-
-int
-runBug27466(NDBT_Context* ctx, NDBT_Step* step)
-{
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- NdbRestarter res;
-
- if (res.getNumDbNodes() < 2)
- {
- return NDBT_OK;
- }
-
- Uint32 pos = 0;
- for (Uint32 i = 0; i<loops; i++)
- {
- int node1 = res.getDbNodeId(rand() % res.getNumDbNodes());
- int node2 = node1;
- while (node1 == node2)
- {
- node2 = res.getDbNodeId(rand() % res.getNumDbNodes());
- }
-
- ndbout_c("nodes %u %u", node1, node2);
-
- if (res.restartOneDbNode(node1, false, true, true))
- return NDBT_FAILED;
-
- if (res.waitNodesNoStart(&node1, 1))
- return NDBT_FAILED;
-
- int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
- if (res.dumpStateOneNode(node1, val2, 2))
- return NDBT_FAILED;
-
- if (res.insertErrorInNode(node2, 8039))
- return NDBT_FAILED;
-
- res.startNodes(&node1, 1);
- NdbSleep_SecSleep(3);
- if (res.waitNodesNoStart(&node1, 1))
- return NDBT_FAILED;
- NdbSleep_SecSleep(5); // Wait for delayed INCL_NODECONF to arrive
-
- res.startNodes(&node1, 1);
- if (res.waitClusterStarted())
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-int
-runBug28023(NDBT_Context* ctx, NDBT_Step* step)
-{
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- Ndb* pNdb = GETNDB(step);
- NdbRestarter res;
-
- if (res.getNumDbNodes() < 2)
- {
- return NDBT_OK;
- }
-
-
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.loadTable(pNdb, records) != 0){
- return NDBT_FAILED;
- }
-
- if (hugoTrans.clearTable(pNdb, records) != 0)
- {
- return NDBT_FAILED;
- }
-
- for (Uint32 i = 0; i<loops; i++)
- {
- int node1 = res.getDbNodeId(rand() % res.getNumDbNodes());
-
- if (res.restartOneDbNode2(node1,
- NdbRestarter::NRRF_ABORT |
- NdbRestarter::NRRF_NOSTART))
- return NDBT_FAILED;
-
- if (res.waitNodesNoStart(&node1, 1))
- return NDBT_FAILED;
-
- if (hugoTrans.loadTable(pNdb, records) != 0){
- return NDBT_FAILED;
- }
-
- if (hugoTrans.clearTable(pNdb, records) != 0)
- {
- return NDBT_FAILED;
- }
-
- res.startNodes(&node1, 1);
- if (res.waitClusterStarted())
- return NDBT_FAILED;
-
- if (hugoTrans.loadTable(pNdb, records) != 0){
- return NDBT_FAILED;
- }
-
- if (hugoTrans.scanUpdateRecords(pNdb, records) != 0)
- return NDBT_FAILED;
-
- if (hugoTrans.clearTable(pNdb, records) != 0)
- {
- return NDBT_FAILED;
- }
- }
-
- return NDBT_OK;
-}
-
-
-int
-runBug28717(NDBT_Context* ctx, NDBT_Step* step)
-{
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- Ndb* pNdb = GETNDB(step);
- NdbRestarter res;
-
- if (res.getNumDbNodes() < 4)
- {
- return NDBT_OK;
- }
-
- int master = res.getMasterNodeId();
- int node0 = res.getRandomNodeOtherNodeGroup(master, rand());
- int node1 = res.getRandomNodeSameNodeGroup(node0, rand());
-
- ndbout_c("master: %d node0: %d node1: %d", master, node0, node1);
-
- if (res.restartOneDbNode(node0, false, true, true))
- {
- return NDBT_FAILED;
- }
-
- {
- int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_CHECKPOINT, 0 };
- NdbLogEventHandle handle =
- ndb_mgm_create_logevent_handle(res.handle, filter);
-
-
- int dump[] = { DumpStateOrd::DihStartLcpImmediately };
- struct ndb_logevent event;
-
- for (Uint32 i = 0; i<3; i++)
- {
- res.dumpStateOneNode(master, dump, 1);
- while(ndb_logevent_get_next(handle, &event, 0) >= 0 &&
- event.type != NDB_LE_LocalCheckpointStarted);
- while(ndb_logevent_get_next(handle, &event, 0) >= 0 &&
- event.type != NDB_LE_LocalCheckpointCompleted);
- }
- }
-
- if (res.waitNodesNoStart(&node0, 1))
- return NDBT_FAILED;
-
- int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
-
- if (res.dumpStateOneNode(node0, val2, 2))
- return NDBT_FAILED;
-
- if (res.insertErrorInNode(node0, 5010))
- return NDBT_FAILED;
-
- if (res.insertErrorInNode(node1, 1001))
- return NDBT_FAILED;
-
- if (res.startNodes(&node0, 1))
- return NDBT_FAILED;
-
- NdbSleep_SecSleep(3);
-
- if (res.insertErrorInNode(node1, 0))
- return NDBT_FAILED;
-
- if (res.waitNodesNoStart(&node0, 1))
- return NDBT_FAILED;
-
- if (res.startNodes(&node0, 1))
- return NDBT_FAILED;
-
- if (res.waitClusterStarted())
- return NDBT_FAILED;
-
- return NDBT_OK;
-}
-
-int
-runBug31525(NDBT_Context* ctx, NDBT_Step* step)
-{
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- Ndb* pNdb = GETNDB(step);
- NdbRestarter res;
-
- if (res.getNumDbNodes() < 2)
- {
- return NDBT_OK;
- }
-
- int nodes[2];
- nodes[0] = res.getMasterNodeId();
- nodes[1] = res.getNextMasterNodeId(nodes[0]);
-
- while (res.getNodeGroup(nodes[0]) != res.getNodeGroup(nodes[1]))
- {
- ndbout_c("Restarting %u as it not in same node group as %u",
- nodes[1], nodes[0]);
- if (res.restartOneDbNode(nodes[1], false, true, true))
- return NDBT_FAILED;
-
- if (res.waitNodesNoStart(nodes+1, 1))
- return NDBT_FAILED;
-
- if (res.startNodes(nodes+1, 1))
- return NDBT_FAILED;
-
- if (res.waitClusterStarted())
- return NDBT_FAILED;
-
- nodes[1] = res.getNextMasterNodeId(nodes[0]);
- }
-
- ndbout_c("nodes[0]: %u nodes[1]: %u", nodes[0], nodes[1]);
-
- int val = DumpStateOrd::DihMinTimeBetweenLCP;
- if (res.dumpStateAllNodes(&val, 1))
- return NDBT_FAILED;
-
- int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
- if (res.dumpStateAllNodes(val2, 2))
- return NDBT_FAILED;
-
- if (res.insertErrorInAllNodes(932))
- return NDBT_FAILED;
-
- if (res.insertErrorInNode(nodes[1], 7192))
- return NDBT_FAILED;
-
- if (res.insertErrorInNode(nodes[0], 7191))
- return NDBT_FAILED;
-
- if (res.waitClusterNoStart())
- return NDBT_FAILED;
-
- if (res.startAll())
- return NDBT_FAILED;
-
- if (res.waitClusterStarted())
- return NDBT_FAILED;
-
- if (res.restartOneDbNode(nodes[1], false, false, true))
- return NDBT_FAILED;
-
- if (res.waitClusterStarted())
- return NDBT_FAILED;
-
- return NDBT_OK;
-}
-
-int
-runBug32160(NDBT_Context* ctx, NDBT_Step* step)
-{
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- Ndb* pNdb = GETNDB(step);
- NdbRestarter res;
-
- if (res.getNumDbNodes() < 2)
- {
- return NDBT_OK;
- }
-
- int master = res.getMasterNodeId();
- int next = res.getNextMasterNodeId(master);
-
- if (res.insertErrorInNode(next, 7194))
- {
- return NDBT_FAILED;
- }
-
- int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
- if (res.dumpStateOneNode(master, val2, 2))
- return NDBT_FAILED;
-
- if (res.insertErrorInNode(master, 7193))
- return NDBT_FAILED;
-
- int val3[] = { 7099 };
- if (res.dumpStateOneNode(master, val3, 1))
- return NDBT_FAILED;
-
- if (res.waitNodesNoStart(&master, 1))
- return NDBT_FAILED;
-
- if (res.startNodes(&master, 1))
- return NDBT_FAILED;
-
- if (res.waitClusterStarted())
- return NDBT_FAILED;
-
- return NDBT_OK;
-}
-
-int
-runBug34216(NDBT_Context* ctx, NDBT_Step* step)
-{
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- NdbRestarter restarter;
- int i = 0;
- int lastId = 0;
- HugoOperations hugoOps(*ctx->getTab());
- int records = ctx->getNumRecords();
- Ndb* pNdb = GETNDB(step);
-
- if (restarter.getNumDbNodes() < 2)
- {
- ctx->stopTest();
- return NDBT_OK;
- }
-
- if(restarter.waitClusterStarted() != 0){
- g_err << "Cluster failed to start" << endl;
- return NDBT_FAILED;
- }
-
- char buf[100];
- const char * off = NdbEnv_GetEnv("NDB_ERR_OFFSET", buf, sizeof(buf));
- int offset = off ? atoi(off) : 0;
-
- while(i<loops && result != NDBT_FAILED && !ctx->isTestStopped())
- {
- int id = lastId % restarter.getNumDbNodes();
- int nodeId = restarter.getDbNodeId(id);
- int err = 5048 + ((i+offset) % 2);
-
- int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
-
- if(hugoOps.startTransaction(pNdb) != 0)
- goto err;
-
- nodeId = hugoOps.getTransaction()->getConnectedNodeId();
- ndbout << "Restart node " << nodeId << " " << err <<endl;
-
- if (restarter.dumpStateOneNode(nodeId, val2, 2))
- return NDBT_FAILED;
-
- if(restarter.insertErrorInNode(nodeId, err) != 0){
- g_err << "Failed to restartNextDbNode" << endl;
- result = NDBT_FAILED;
- break;
- }
-
- if (restarter.insertErrorInNode(nodeId, 8057) != 0)
- {
- g_err << "Failed to insert error 8057" << endl;
- result = NDBT_FAILED;
- break;
- }
-
- int rows = 10;
- int batch = 1;
- int row = (records - rows) ? rand() % (records - rows) : 0;
-
- if(hugoOps.pkUpdateRecord(pNdb, row, batch, rand()) != 0)
- goto err;
-
- for (int l = 1; l<5; l++)
- {
- if (hugoOps.execute_NoCommit(pNdb) != 0)
- goto err;
-
- if(hugoOps.pkUpdateRecord(pNdb, row, batch, rand()) != 0)
- goto err;
- }
-
- hugoOps.execute_Commit(pNdb);
- hugoOps.closeTransaction(pNdb);
-
- if (restarter.waitNodesNoStart(&nodeId, 1))
- {
- g_err << "Failed to waitNodesNoStart" << endl;
- result = NDBT_FAILED;
- break;
- }
-
- if (restarter.startNodes(&nodeId, 1))
- {
- g_err << "Failed to startNodes" << endl;
- result = NDBT_FAILED;
- break;
- }
-
- if(restarter.waitClusterStarted() != 0){
- g_err << "Cluster failed to start" << endl;
- result = NDBT_FAILED;
- break;
- }
-
- lastId++;
- i++;
- }
-
- ctx->stopTest();
-
- return result;
-err:
- return NDBT_FAILED;
-}
-
-
-int
-runNF_commit(NDBT_Context* ctx, NDBT_Step* step)
-{
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- NdbRestarter restarter;
- if (restarter.getNumDbNodes() < 2)
- {
- ctx->stopTest();
- return NDBT_OK;
- }
-
- if(restarter.waitClusterStarted() != 0){
- g_err << "Cluster failed to start" << endl;
- return NDBT_FAILED;
- }
-
- int i = 0;
- while(i<loops && result != NDBT_FAILED && !ctx->isTestStopped())
- {
- int nodeId = restarter.getDbNodeId(rand() % restarter.getNumDbNodes());
- int err = 5048;
-
- ndbout << "Restart node " << nodeId << " " << err <<endl;
-
- int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
- if (restarter.dumpStateOneNode(nodeId, val2, 2))
- return NDBT_FAILED;
-
- if(restarter.insertErrorInNode(nodeId, err) != 0){
- g_err << "Failed to restartNextDbNode" << endl;
- result = NDBT_FAILED;
- break;
- }
-
- if (restarter.waitNodesNoStart(&nodeId, 1))
- {
- g_err << "Failed to waitNodesNoStart" << endl;
- result = NDBT_FAILED;
- break;
- }
-
- if (restarter.startNodes(&nodeId, 1))
- {
- g_err << "Failed to startNodes" << endl;
- result = NDBT_FAILED;
- break;
- }
-
- if(restarter.waitClusterStarted() != 0){
- g_err << "Cluster failed to start" << endl;
- result = NDBT_FAILED;
- break;
- }
-
- i++;
- }
-
- ctx->stopTest();
-
- return result;
-}
-
-
-NDBT_TESTSUITE(testNodeRestart);
-TESTCASE("NoLoad",
- "Test that one node at a time can be stopped and then restarted "\
- "when there are no load on the system. Do this loop number of times"){
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runRestarter);
- FINALIZER(runClearTable);
-}
-TESTCASE("PkRead",
- "Test that one node at a time can be stopped and then restarted "\
- "perform pk read while restarting. Do this loop number of times"){
- TC_PROPERTY("ReadLockMode", NdbOperation::LM_Read);
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runRestarter);
- STEP(runPkReadUntilStopped);
- FINALIZER(runClearTable);
-}
-TESTCASE("PkReadCommitted",
- "Test that one node at a time can be stopped and then restarted "\
- "perform pk read while restarting. Do this loop number of times"){
- TC_PROPERTY("ReadLockMode", NdbOperation::LM_CommittedRead);
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runRestarter);
- STEP(runPkReadUntilStopped);
- FINALIZER(runClearTable);
-}
-TESTCASE("MixedPkRead",
- "Test that one node at a time can be stopped and then restarted "\
- "perform pk read while restarting. Do this loop number of times"){
- TC_PROPERTY("ReadLockMode", -1);
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runRestarter);
- STEP(runPkReadUntilStopped);
- FINALIZER(runClearTable);
-}
-TESTCASE("PkReadPkUpdate",
- "Test that one node at a time can be stopped and then restarted "\
- "perform pk read and pk update while restarting. Do this loop number of times"){
- TC_PROPERTY("ReadLockMode", NdbOperation::LM_Read);
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runRestarter);
- STEP(runPkReadUntilStopped);
- STEP(runPkUpdateUntilStopped);
- STEP(runPkReadPkUpdateUntilStopped);
- STEP(runPkReadUntilStopped);
- STEP(runPkUpdateUntilStopped);
- STEP(runPkReadPkUpdateUntilStopped);
- FINALIZER(runClearTable);
-}
-TESTCASE("MixedPkReadPkUpdate",
- "Test that one node at a time can be stopped and then restarted "\
- "perform pk read and pk update while restarting. Do this loop number of times"){
- TC_PROPERTY("ReadLockMode", -1);
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runRestarter);
- STEP(runPkReadUntilStopped);
- STEP(runPkUpdateUntilStopped);
- STEP(runPkReadPkUpdateUntilStopped);
- STEP(runPkReadUntilStopped);
- STEP(runPkUpdateUntilStopped);
- STEP(runPkReadPkUpdateUntilStopped);
- FINALIZER(runClearTable);
-}
-TESTCASE("ReadUpdateScan",
- "Test that one node at a time can be stopped and then restarted "\
- "perform pk read, pk update and scan reads while restarting. Do this loop number of times"){
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runRestarter);
- STEP(runPkReadUntilStopped);
- STEP(runPkUpdateUntilStopped);
- STEP(runPkReadPkUpdateUntilStopped);
- STEP(runScanReadUntilStopped);
- STEP(runScanUpdateUntilStopped);
- FINALIZER(runClearTable);
-}
-TESTCASE("MixedReadUpdateScan",
- "Test that one node at a time can be stopped and then restarted "\
- "perform pk read, pk update and scan reads while restarting. Do this loop number of times"){
- TC_PROPERTY("ReadLockMode", -1);
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runRestarter);
- STEP(runPkReadUntilStopped);
- STEP(runPkUpdateUntilStopped);
- STEP(runPkReadPkUpdateUntilStopped);
- STEP(runScanReadUntilStopped);
- STEP(runScanUpdateUntilStopped);
- FINALIZER(runClearTable);
-}
-TESTCASE("Terror",
- "Test that one node at a time can be stopped and then restarted "\
- "perform all kind of transactions while restarting. Do this loop number of times"){
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runRestarter);
- STEP(runPkReadUntilStopped);
- STEP(runPkUpdateUntilStopped);
- STEP(runScanReadUntilStopped);
- STEP(runScanUpdateUntilStopped);
- FINALIZER(runClearTable);
-}
-TESTCASE("FullDb",
- "Test that one node at a time can be stopped and then restarted "\
- "when db is full. Do this loop number of times"){
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runFillTable);
- STEP(runRestarter);
- FINALIZER(runClearTable);
-}
-TESTCASE("RestartRandomNode",
- "Test that we can execute the restart RestartRandomNode loop\n"\
- "number of times"){
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runRestarts);
- FINALIZER(runScanReadVerify);
- FINALIZER(runClearTable);
-}
-TESTCASE("RestartRandomNodeError",
- "Test that we can execute the restart RestartRandomNodeError loop\n"\
- "number of times"){
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runRestarts);
- FINALIZER(runScanReadVerify);
- FINALIZER(runClearTable);
-}
-TESTCASE("RestartRandomNodeInitial",
- "Test that we can execute the restart RestartRandomNodeInitial loop\n"\
- "number of times"){
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runRestarts);
- FINALIZER(runScanReadVerify);
- FINALIZER(runClearTable);
-}
-TESTCASE("RestartNFDuringNR",
- "Test that we can execute the restart RestartNFDuringNR loop\n"\
- "number of times"){
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runRestarts);
- STEP(runPkUpdateUntilStopped);
- STEP(runScanUpdateUntilStopped);
- FINALIZER(runScanReadVerify);
- FINALIZER(runClearTable);
-}
-TESTCASE("RestartMasterNodeError",
- "Test that we can execute the restart RestartMasterNodeError loop\n"\
- "number of times"){
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runRestarts);
- FINALIZER(runScanReadVerify);
- FINALIZER(runClearTable);
-}
-
-TESTCASE("TwoNodeFailure",
- "Test that we can execute the restart TwoNodeFailure\n"\
- "(which is a multiple node failure restart) loop\n"\
- "number of times"){
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runRestarts);
- FINALIZER(runScanReadVerify);
- FINALIZER(runClearTable);
-}
-TESTCASE("TwoMasterNodeFailure",
- "Test that we can execute the restart TwoMasterNodeFailure\n"\
- "(which is a multiple node failure restart) loop\n"\
- "number of times"){
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runRestarts);
- FINALIZER(runScanReadVerify);
- FINALIZER(runClearTable);
-}
-TESTCASE("FiftyPercentFail",
- "Test that we can execute the restart FiftyPercentFail\n"\
- "(which is a multiple node failure restart) loop\n"\
- "number of times"){
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runRestarts);
- FINALIZER(runScanReadVerify);
- FINALIZER(runClearTable);
-}
-TESTCASE("RestartAllNodes",
- "Test that we can execute the restart RestartAllNodes\n"\
- "(which is a system restart) loop\n"\
- "number of times"){
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runRestarts);
- FINALIZER(runScanReadVerify);
- FINALIZER(runClearTable);
-}
-TESTCASE("RestartAllNodesAbort",
- "Test that we can execute the restart RestartAllNodesAbort\n"\
- "(which is a system restart) loop\n"\
- "number of times"){
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runRestarts);
- FINALIZER(runScanReadVerify);
- FINALIZER(runClearTable);
-}
-TESTCASE("RestartAllNodesError9999",
- "Test that we can execute the restart RestartAllNodesError9999\n"\
- "(which is a system restart) loop\n"\
- "number of times"){
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runRestarts);
- FINALIZER(runScanReadVerify);
- FINALIZER(runClearTable);
-}
-TESTCASE("FiftyPercentStopAndWait",
- "Test that we can execute the restart FiftyPercentStopAndWait\n"\
- "(which is a system restart) loop\n"\
- "number of times"){
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runRestarts);
- FINALIZER(runScanReadVerify);
- FINALIZER(runClearTable);
-}
-TESTCASE("RestartNodeDuringLCP",
- "Test that we can execute the restart RestartRandomNode loop\n"\
- "number of times"){
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runRestarts);
- STEP(runPkUpdateUntilStopped);
- STEP(runScanUpdateUntilStopped);
- FINALIZER(runScanReadVerify);
- FINALIZER(runClearTable);
-}
-TESTCASE("StopOnError",
- "Test StopOnError. A node that has StopOnError set to false "\
- "should restart automatically when an error occurs"){
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runRestarts);
- FINALIZER(runScanReadVerify);
- FINALIZER(runClearTable);
-}
-TESTCASE("CommittedRead",
- "Test committed read"){
- INITIALIZER(runLoadTable);
- STEP(runDirtyRead);
- FINALIZER(runClearTable);
-}
-TESTCASE("LateCommit",
- "Test commit after node failure"){
- INITIALIZER(runLoadTable);
- STEP(runLateCommit);
- FINALIZER(runClearTable);
-}
-TESTCASE("Bug15587",
- "Test bug with NF during NR"){
- INITIALIZER(runLoadTable);
- STEP(runScanUpdateUntilStopped);
- STEP(runBug15587);
- FINALIZER(runClearTable);
-}
-TESTCASE("Bug15632",
- "Test bug with NF during NR"){
- INITIALIZER(runLoadTable);
- STEP(runBug15632);
- FINALIZER(runClearTable);
-}
-TESTCASE("Bug15685",
- "Test bug with NF during abort"){
- STEP(runBug15685);
- FINALIZER(runClearTable);
-}
-TESTCASE("Bug16772",
- "Test bug with restarting before NF handling is complete"){
- STEP(runBug16772);
-}
-TESTCASE("Bug18414",
- "Test bug with NF during NR"){
- INITIALIZER(runLoadTable);
- STEP(runBug18414);
- FINALIZER(runClearTable);
-}
-TESTCASE("Bug18612",
- "Test bug with partitioned clusters"){
- INITIALIZER(runLoadTable);
- STEP(runBug18612);
- FINALIZER(runClearTable);
-}
-TESTCASE("Bug18612SR",
- "Test bug with partitioned clusters"){
- INITIALIZER(runLoadTable);
- STEP(runBug18612SR);
- FINALIZER(runClearTable);
-}
-TESTCASE("Bug20185",
- ""){
- INITIALIZER(runLoadTable);
- STEP(runBug20185);
- FINALIZER(runClearTable);
-}
-TESTCASE("Bug24543", "")
-{
- INITIALIZER(runBug24543);
-}
-TESTCASE("Bug21271",
- ""){
- INITIALIZER(runLoadTable);
- STEP(runBug21271);
- STEP(runPkUpdateUntilStopped);
- FINALIZER(runClearTable);
-}
-TESTCASE("Bug31525", ""){
- INITIALIZER(runBug31525);
-}
-TESTCASE("Bug24717", ""){
- INITIALIZER(runBug24717);
-}
-TESTCASE("Bug25364", ""){
- INITIALIZER(runBug25364);
-}
-TESTCASE("Bug25468", ""){
- INITIALIZER(runBug25468);
-}
-TESTCASE("Bug25554", ""){
- INITIALIZER(runBug25554);
-}
-TESTCASE("Bug25984", ""){
- INITIALIZER(runBug25984);
-}
-TESTCASE("Bug26457", ""){
- INITIALIZER(runBug26457);
-}
-TESTCASE("Bug26481", ""){
- INITIALIZER(runBug26481);
-}
-TESTCASE("Bug26450", ""){
- INITIALIZER(runLoadTable);
- INITIALIZER(runBug26450);
-}
-TESTCASE("Bug27003", ""){
- INITIALIZER(runBug27003);
-}
-TESTCASE("Bug27283", ""){
- INITIALIZER(runBug27283);
-}
-TESTCASE("Bug27466", ""){
- INITIALIZER(runBug27466);
-}
-TESTCASE("Bug28023", ""){
- INITIALIZER(runBug28023);
-}
-TESTCASE("Bug28717", ""){
- INITIALIZER(runBug28717);
-}
-TESTCASE("Bug29364", ""){
- INITIALIZER(runBug29364);
-}
-TESTCASE("Bug32160", ""){
- INITIALIZER(runBug32160);
-}
-TESTCASE("Bug34216", ""){
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runBug34216);
- FINALIZER(runClearTable);
-}
-TESTCASE("mixedmultiop", ""){
- TC_PROPERTY("MULTI_OP", 5);
- INITIALIZER(runCheckAllNodesStarted);
- INITIALIZER(runLoadTable);
- STEP(runNF_commit);
- STEP(runPkUpdateUntilStopped);
- STEP(runPkUpdateUntilStopped);
- FINALIZER(runClearTable);
-}
-NDBT_TESTSUITE_END(testNodeRestart);
-
-int main(int argc, const char** argv){
- ndb_init();
-#if 0
- // It might be interesting to have longer defaults for num
- // loops in this test
- // Just performing 100 node restarts would not be enough?
- // We can have initialisers in the NDBT_Testcase class like
- // this...
- testNodeRestart.setDefaultLoops(1000);
-#endif
- return testNodeRestart.execute(argc, argv);
-}
-
diff --git a/storage/ndb/test/ndbapi/testOIBasic.cpp b/storage/ndb/test/ndbapi/testOIBasic.cpp
deleted file mode 100644
index b409f31876d..00000000000
--- a/storage/ndb/test/ndbapi/testOIBasic.cpp
+++ /dev/null
@@ -1,5850 +0,0 @@
-/* Copyright (c) 2003-2006, 2008 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-/*
- * testOIBasic - ordered index test
- */
-
-#include <ndb_global.h>
-
-#include <NdbMain.h>
-#include <NdbOut.hpp>
-#include <NdbApi.hpp>
-#include <NdbTest.hpp>
-#include <NdbMutex.h>
-#include <NdbCondition.h>
-#include <NdbThread.h>
-#include <NdbTick.h>
-#include <NdbSleep.h>
-#include <my_sys.h>
-#include <NdbSqlUtil.hpp>
-#include <ndb_version.h>
-
-// options
-
-struct Opt {
- // common options
- uint m_batch;
- const char* m_bound;
- const char* m_case;
- bool m_collsp;
- bool m_cont;
- bool m_core;
- const char* m_csname;
- CHARSET_INFO* m_cs;
- int m_die;
- bool m_dups;
- NdbDictionary::Object::FragmentType m_fragtype;
- const char* m_index;
- uint m_loop;
- bool m_msglock;
- bool m_nologging;
- bool m_noverify;
- uint m_pctnull;
- uint m_rows;
- uint m_samples;
- uint m_scanbatch;
- uint m_scanpar;
- uint m_scanstop;
- int m_seed;
- const char* m_skip;
- uint m_sloop;
- uint m_ssloop;
- const char* m_table;
- uint m_threads;
- int m_v; // int for lint
- Opt() :
- m_batch(32),
- m_bound("01234"),
- m_case(0),
- m_collsp(false),
- m_cont(false),
- m_core(false),
- m_csname("random"),
- m_cs(0),
- m_die(0),
- m_dups(false),
- m_fragtype(NdbDictionary::Object::FragUndefined),
- m_index(0),
- m_loop(1),
- m_msglock(true),
- m_nologging(false),
- m_noverify(false),
- m_pctnull(10),
- m_rows(1000),
- m_samples(0),
- m_scanbatch(0),
- m_scanpar(0),
- m_scanstop(0),
- m_seed(-1),
- m_skip(0),
- m_sloop(4),
- m_ssloop(4),
- m_table(0),
- m_threads(4),
- m_v(1) {
- }
-};
-
-static Opt g_opt;
-
-static void printcases();
-static void printtables();
-
-static void
-printhelp()
-{
- Opt d;
- ndbout
- << "usage: testOIbasic [options]" << endl
- << " -batch N pk operations in batch [" << d.m_batch << "]" << endl
- << " -bound xyz use only these bound types 0-4 [" << d.m_bound << "]" << endl
- << " -case abc only given test cases (letters a-z)" << endl
- << " -collsp use strnncollsp instead of strnxfrm" << endl
- << " -cont on error continue to next test case [" << d.m_cont << "]" << endl
- << " -core core dump on error [" << d.m_core << "]" << endl
- << " -csname S charset or collation [" << d.m_csname << "]" << endl
- << " -die nnn exit immediately on NDB error code nnn" << endl
- << " -dups allow duplicate tuples from index scan [" << d.m_dups << "]" << endl
- << " -fragtype T fragment type single/small/medium/large" << endl
- << " -index xyz only given index numbers (digits 0-9)" << endl
- << " -loop N loop count full suite 0=forever [" << d.m_loop << "]" << endl
- << " -nologging create tables in no-logging mode" << endl
- << " -noverify skip index verifications" << endl
- << " -pctnull N pct NULL values in nullable column [" << d.m_pctnull << "]" << endl
- << " -rows N rows per thread [" << d.m_rows << "]" << endl
- << " -samples N samples for some timings (0=all) [" << d.m_samples << "]" << endl
- << " -scanbatch N scan batch 0=default [" << d.m_scanbatch << "]" << endl
- << " -scanpar N scan parallel 0=default [" << d.m_scanpar << "]" << endl
- << " -seed N srandom seed 0=loop number -1=random [" << d.m_seed << "]" << endl
- << " -skip abc skip given test cases (letters a-z)" << endl
- << " -sloop N level 2 (sub)loop count [" << d.m_sloop << "]" << endl
- << " -ssloop N level 3 (sub)loop count [" << d.m_ssloop << "]" << endl
- << " -table xyz only given table numbers (digits 0-9)" << endl
- << " -threads N number of threads [" << d.m_threads << "]" << endl
- << " -vN verbosity [" << d.m_v << "]" << endl
- << " -h or -help print this help text" << endl
- ;
- printcases();
- printtables();
-}
-
-// not yet configurable
-static const bool g_store_null_key = true;
-
-// compare NULL like normal value (NULL < not NULL, NULL == NULL)
-static const bool g_compare_null = true;
-
-static const char* hexstr = "0123456789abcdef";
-
-// random ints
-
-static uint
-urandom(uint n)
-{
- if (n == 0)
- return 0;
- uint i = random() % n;
- return i;
-}
-
-static int
-irandom(uint n)
-{
- if (n == 0)
- return 0;
- int i = random() % n;
- if (random() & 0x1)
- i = -i;
- return i;
-}
-
-static bool
-randompct(uint pct)
-{
- if (pct == 0)
- return false;
- if (pct >= 100)
- return true;
- return urandom(100) < pct;
-}
-
-static uint
-random_coprime(uint n)
-{
- uint prime[] = { 101, 211, 307, 401, 503, 601, 701, 809, 907 };
- uint count = sizeof(prime) / sizeof(prime[0]);
- if (n == 0)
- return 0;
- while (1) {
- uint i = urandom(count);
- if (n % prime[i] != 0)
- return prime[i];
- }
-}
-
-// random re-sequence of 0...(n-1)
-
-struct Rsq {
- Rsq(uint n);
- uint next();
-private:
- uint m_n;
- uint m_i;
- uint m_start;
- uint m_prime;
-};
-
-Rsq::Rsq(uint n)
-{
- m_n = n;
- m_i = 0;
- m_start = urandom(n);
- m_prime = random_coprime(n);
-}
-
-uint
-Rsq::next()
-{
- assert(m_n != 0);
- return (m_start + m_i++ * m_prime) % m_n;
-}
-
-// log and error macros
-
-static NdbMutex *ndbout_mutex = NULL;
-static const char* getthrprefix();
-
-#define LLN(n, s) \
- do { \
- if ((n) > g_opt.m_v) break; \
- if (g_opt.m_msglock) NdbMutex_Lock(ndbout_mutex); \
- ndbout << getthrprefix(); \
- if ((n) > 2) \
- ndbout << "line " << __LINE__ << ": "; \
- ndbout << s << endl; \
- if (g_opt.m_msglock) NdbMutex_Unlock(ndbout_mutex); \
- } while(0)
-
-#define LL0(s) LLN(0, s)
-#define LL1(s) LLN(1, s)
-#define LL2(s) LLN(2, s)
-#define LL3(s) LLN(3, s)
-#define LL4(s) LLN(4, s)
-#define LL5(s) LLN(5, s)
-
-#define HEX(x) hex << (x) << dec
-
-// following check a condition and return -1 on failure
-
-#undef CHK // simple check
-#undef CHKTRY // check with action on fail
-#undef CHKCON // print NDB API errors on failure
-
-#define CHK(x) CHKTRY(x, ;)
-
-#define CHKTRY(x, act) \
- do { \
- if (x) break; \
- LL0("line " << __LINE__ << ": " << #x << " failed"); \
- if (g_opt.m_core) abort(); \
- act; \
- return -1; \
- } while (0)
-
-#define CHKCON(x, con) \
- do { \
- if (x) break; \
- LL0("line " << __LINE__ << ": " << #x << " failed"); \
- (con).printerror(ndbout); \
- if (g_opt.m_core) abort(); \
- return -1; \
- } while (0)
-
-// method parameters
-
-class Thr;
-class Con;
-class Tab;
-class ITab;
-class Set;
-class Tmr;
-
-struct Par : public Opt {
- uint m_no;
- Con* m_con;
- Con& con() const { assert(m_con != 0); return *m_con; }
- const Tab* m_tab;
- const Tab& tab() const { assert(m_tab != 0); return *m_tab; }
- const ITab* m_itab;
- const ITab& itab() const { assert(m_itab != 0); return *m_itab; }
- Set* m_set;
- Set& set() const { assert(m_set != 0); return *m_set; }
- Tmr* m_tmr;
- Tmr& tmr() const { assert(m_tmr != 0); return *m_tmr; }
- char m_currcase[2];
- uint m_lno;
- uint m_slno;
- uint m_totrows;
- // value calculation
- uint m_range;
- uint m_pctrange;
- uint m_pctbrange;
- int m_bdir;
- bool m_noindexkeyupdate;
- // choice of key
- bool m_randomkey;
- // do verify after read
- bool m_verify;
- // errors to catch (see Con)
- bool m_catcherr;
- // abort percentage
- uint m_abortpct;
- NdbOperation::LockMode m_lockmode;
- // scan options
- bool m_tupscan;
- bool m_ordered;
- bool m_descending;
- // threads used by current test case
- uint m_usedthreads;
- Par(const Opt& opt) :
- Opt(opt),
- m_no(0),
- m_con(0),
- m_tab(0),
- m_itab(0),
- m_set(0),
- m_tmr(0),
- m_lno(0),
- m_slno(0),
- m_totrows(0),
- m_range(m_rows),
- m_pctrange(40),
- m_pctbrange(80),
- m_bdir(0),
- m_noindexkeyupdate(false),
- m_randomkey(false),
- m_verify(false),
- m_catcherr(0),
- m_abortpct(0),
- m_lockmode(NdbOperation::LM_Read),
- m_tupscan(false),
- m_ordered(false),
- m_descending(false),
- m_usedthreads(0)
- {
- m_currcase[0] = 0;
- }
-};
-
-static bool
-usetable(Par par, uint i)
-{
- return par.m_table == 0 || strchr(par.m_table, '0' + i) != 0;
-}
-
-static bool
-useindex(Par par, uint i)
-{
- return par.m_index == 0 || strchr(par.m_index, '0' + i) != 0;
-}
-
-static uint
-thrrow(Par par, uint j)
-{
- return par.m_usedthreads * j + par.m_no;
-}
-
-static bool
-isthrrow(Par par, uint i)
-{
- return i % par.m_usedthreads == par.m_no;
-}
-
-// timer
-
-struct Tmr {
- void clr();
- void on();
- void off(uint cnt = 0);
- const char* time();
- const char* pct(const Tmr& t1);
- const char* over(const Tmr& t1);
- NDB_TICKS m_on;
- uint m_ms;
- uint m_cnt;
- char m_time[100];
- char m_text[100];
- Tmr() { clr(); }
-};
-
-void
-Tmr::clr()
-{
- m_on = m_ms = m_cnt = m_time[0] = m_text[0] = 0;
-}
-
-void
-Tmr::on()
-{
- assert(m_on == 0);
- m_on = NdbTick_CurrentMillisecond();
-}
-
-void
-Tmr::off(uint cnt)
-{
- NDB_TICKS off = NdbTick_CurrentMillisecond();
- assert(m_on != 0 && off >= m_on);
- m_ms += off - m_on;
- m_cnt += cnt;
- m_on = 0;
-}
-
-const char*
-Tmr::time()
-{
- if (m_cnt == 0) {
- sprintf(m_time, "%u ms", m_ms);
- } else {
- sprintf(m_time, "%u ms per %u ( %u ms per 1000 )", m_ms, m_cnt, (1000 * m_ms) / m_cnt);
- }
- return m_time;
-}
-
-const char*
-Tmr::pct(const Tmr& t1)
-{
- if (0 < t1.m_ms) {
- sprintf(m_text, "%u pct", (100 * m_ms) / t1.m_ms);
- } else {
- sprintf(m_text, "[cannot measure]");
- }
- return m_text;
-}
-
-const char*
-Tmr::over(const Tmr& t1)
-{
- if (0 < t1.m_ms) {
- if (t1.m_ms <= m_ms)
- sprintf(m_text, "%u pct", (100 * (m_ms - t1.m_ms)) / t1.m_ms);
- else
- sprintf(m_text, "-%u pct", (100 * (t1.m_ms - m_ms)) / t1.m_ms);
- } else {
- sprintf(m_text, "[cannot measure]");
- }
- return m_text;
-}
-
-// character sets
-
-static const uint maxcsnumber = 512;
-static const uint maxcharcount = 32;
-static const uint maxcharsize = 4;
-static const uint maxxmulsize = 8;
-
-// single mb char
-struct Chr {
- uchar m_bytes[maxcharsize];
- uchar m_xbytes[maxxmulsize * maxcharsize];
- uint m_size;
- Chr();
-};
-
-Chr::Chr()
-{
- memset(m_bytes, 0, sizeof(m_bytes));
- memset(m_xbytes, 0, sizeof(m_xbytes));
- m_size = 0;
-}
-
-// charset and random valid chars to use
-struct Chs {
- CHARSET_INFO* m_cs;
- uint m_xmul;
- Chr* m_chr;
- Chs(CHARSET_INFO* cs);
- ~Chs();
-};
-
-static NdbOut&
-operator<<(NdbOut& out, const Chs& chs);
-
-Chs::Chs(CHARSET_INFO* cs) :
- m_cs(cs)
-{
- m_xmul = m_cs->strxfrm_multiply;
- if (m_xmul == 0)
- m_xmul = 1;
- assert(m_xmul <= maxxmulsize);
- m_chr = new Chr [maxcharcount];
- uint i = 0;
- uint miss1 = 0;
- uint miss2 = 0;
- uint miss3 = 0;
- uint miss4 = 0;
- while (i < maxcharcount) {
- uchar* bytes = m_chr[i].m_bytes;
- uchar* xbytes = m_chr[i].m_xbytes;
- uint& size = m_chr[i].m_size;
- bool ok;
- size = m_cs->mbminlen + urandom(m_cs->mbmaxlen - m_cs->mbminlen + 1);
- assert(m_cs->mbminlen <= size && size <= m_cs->mbmaxlen);
- // prefer longer chars
- if (size == m_cs->mbminlen && m_cs->mbminlen < m_cs->mbmaxlen && urandom(5) != 0)
- continue;
- for (uint j = 0; j < size; j++) {
- bytes[j] = urandom(256);
- }
- int not_used;
- // check wellformed
- const char* sbytes = (const char*)bytes;
- if ((*cs->cset->well_formed_len)(cs, sbytes, sbytes + size, 1, &not_used) != size) {
- miss1++;
- continue;
- }
- // check no proper prefix wellformed
- ok = true;
- for (uint j = 1; j < size; j++) {
- if ((*cs->cset->well_formed_len)(cs, sbytes, sbytes + j, 1, &not_used) == j) {
- ok = false;
- break;
- }
- }
- if (!ok) {
- miss2++;
- continue;
- }
- // normalize
- memset(xbytes, 0, sizeof(xbytes));
- // currently returns buffer size always
- int xlen = (*cs->coll->strnxfrm)(cs, xbytes, m_xmul * size, bytes, size);
- // check we got something
- ok = false;
- for (uint j = 0; j < xlen; j++) {
- if (xbytes[j] != 0) {
- ok = true;
- break;
- }
- }
- if (!ok) {
- miss3++;
- continue;
- }
- // check for duplicate (before normalize)
- ok = true;
- for (uint j = 0; j < i; j++) {
- const Chr& chr = m_chr[j];
- if (chr.m_size == size && memcmp(chr.m_bytes, bytes, size) == 0) {
- ok = false;
- break;
- }
- }
- if (!ok) {
- miss4++;
- continue;
- }
- i++;
- }
- bool disorder = true;
- uint bubbles = 0;
- while (disorder) {
- disorder = false;
- for (uint i = 1; i < maxcharcount; i++) {
- uint len = sizeof(m_chr[i].m_xbytes);
- if (memcmp(m_chr[i-1].m_xbytes, m_chr[i].m_xbytes, len) > 0) {
- Chr chr = m_chr[i];
- m_chr[i] = m_chr[i-1];
- m_chr[i-1] = chr;
- disorder = true;
- bubbles++;
- }
- }
- }
- LL3("inited charset " << *this << " miss=" << miss1 << "," << miss2 << "," << miss3 << "," << miss4 << " bubbles=" << bubbles);
-}
-
-Chs::~Chs()
-{
- delete [] m_chr;
-}
-
-static NdbOut&
-operator<<(NdbOut& out, const Chs& chs)
-{
- CHARSET_INFO* cs = chs.m_cs;
- out << cs->name << "[" << cs->mbminlen << "-" << cs->mbmaxlen << "," << chs.m_xmul << "]";
- return out;
-}
-
-static Chs* cslist[maxcsnumber];
-
-static void
-resetcslist()
-{
- for (uint i = 0; i < maxcsnumber; i++) {
- delete cslist[i];
- cslist[i] = 0;
- }
-}
-
-static Chs*
-getcs(Par par)
-{
- CHARSET_INFO* cs;
- if (par.m_cs != 0) {
- cs = par.m_cs;
- } else {
- while (1) {
- uint n = urandom(maxcsnumber);
- cs = get_charset(n, MYF(0));
- if (cs != 0) {
- // prefer complex charsets
- if (cs->mbmaxlen != 1 || urandom(5) == 0)
- break;
- }
- }
- }
- if (cslist[cs->number] == 0)
- cslist[cs->number] = new Chs(cs);
- return cslist[cs->number];
-}
-
-// tables and indexes
-
-// Col - table column
-
-struct Col {
- enum Type {
- Unsigned = NdbDictionary::Column::Unsigned,
- Char = NdbDictionary::Column::Char,
- Varchar = NdbDictionary::Column::Varchar,
- Longvarchar = NdbDictionary::Column::Longvarchar
- };
- const class Tab& m_tab;
- uint m_num;
- const char* m_name;
- bool m_pk;
- Type m_type;
- uint m_length;
- uint m_bytelength; // multiplied by char width
- uint m_attrsize; // base type size
- uint m_headsize; // length bytes
- uint m_bytesize; // full value size
- bool m_nullable;
- const Chs* m_chs;
- Col(const class Tab& tab, uint num, const char* name, bool pk, Type type, uint length, bool nullable, const Chs* chs);
- ~Col();
- bool equal(const Col& col2) const;
- void wellformed(const void* addr) const;
-};
-
-Col::Col(const class Tab& tab, uint num, const char* name, bool pk, Type type, uint length, bool nullable, const Chs* chs) :
- m_tab(tab),
- m_num(num),
- m_name(strcpy(new char [strlen(name) + 1], name)),
- m_pk(pk),
- m_type(type),
- m_length(length),
- m_bytelength(length * (chs == 0 ? 1 : chs->m_cs->mbmaxlen)),
- m_attrsize(
- type == Unsigned ? sizeof(Uint32) :
- type == Char ? sizeof(char) :
- type == Varchar ? sizeof(char) :
- type == Longvarchar ? sizeof(char) : ~0),
- m_headsize(
- type == Unsigned ? 0 :
- type == Char ? 0 :
- type == Varchar ? 1 :
- type == Longvarchar ? 2 : ~0),
- m_bytesize(m_headsize + m_attrsize * m_bytelength),
- m_nullable(nullable),
- m_chs(chs)
-{
- // fix long varchar
- if (type == Varchar && m_bytelength > 255) {
- m_type = Longvarchar;
- m_headsize += 1;
- m_bytesize += 1;
- }
-}
-
-Col::~Col()
-{
- delete [] m_name;
-}
-
-bool
-Col::equal(const Col& col2) const
-{
- return m_type == col2.m_type && m_length == col2.m_length && m_chs == col2.m_chs;
-}
-
-void
-Col::wellformed(const void* addr) const
-{
- switch (m_type) {
- case Col::Unsigned:
- break;
- case Col::Char:
- {
- CHARSET_INFO* cs = m_chs->m_cs;
- const char* src = (const char*)addr;
- uint len = m_bytelength;
- int not_used;
- assert((*cs->cset->well_formed_len)(cs, src, src + len, 0xffff, &not_used) == len);
- }
- break;
- case Col::Varchar:
- {
- CHARSET_INFO* cs = m_chs->m_cs;
- const uchar* src = (const uchar*)addr;
- const char* ssrc = (const char*)src;
- uint len = src[0];
- int not_used;
- assert(len <= m_bytelength);
- assert((*cs->cset->well_formed_len)(cs, ssrc + 1, ssrc + 1 + len, 0xffff, &not_used) == len);
- }
- break;
- case Col::Longvarchar:
- {
- CHARSET_INFO* cs = m_chs->m_cs;
- const uchar* src = (const uchar*)addr;
- const char* ssrc = (const char*)src;
- uint len = src[0] + (src[1] << 8);
- int not_used;
- assert(len <= m_bytelength);
- assert((*cs->cset->well_formed_len)(cs, ssrc + 2, ssrc + 2 + len, 0xffff, &not_used) == len);
- }
- break;
- default:
- assert(false);
- break;
- }
-}
-
-static NdbOut&
-operator<<(NdbOut& out, const Col& col)
-{
- out << "col[" << col.m_num << "] " << col.m_name;
- switch (col.m_type) {
- case Col::Unsigned:
- out << " uint";
- break;
- case Col::Char:
- {
- CHARSET_INFO* cs = col.m_chs->m_cs;
- out << " char(" << col.m_length << "*" << cs->mbmaxlen << ";" << cs->name << ")";
- }
- break;
- case Col::Varchar:
- {
- CHARSET_INFO* cs = col.m_chs->m_cs;
- out << " varchar(" << col.m_length << "*" << cs->mbmaxlen << ";" << cs->name << ")";
- }
- break;
- case Col::Longvarchar:
- {
- CHARSET_INFO* cs = col.m_chs->m_cs;
- out << " longvarchar(" << col.m_length << "*" << cs->mbmaxlen << ";" << cs->name << ")";
- }
- break;
- default:
- out << "type" << (int)col.m_type;
- assert(false);
- break;
- }
- out << (col.m_pk ? " pk" : "");
- out << (col.m_nullable ? " nullable" : "");
- return out;
-}
-
-// ICol - index column
-
-struct ICol {
- const class ITab& m_itab;
- uint m_num;
- const Col& m_col;
- ICol(const class ITab& itab, uint num, const Col& col);
- ~ICol();
-};
-
-ICol::ICol(const class ITab& itab, uint num, const Col& col) :
- m_itab(itab),
- m_num(num),
- m_col(col)
-{
-}
-
-ICol::~ICol()
-{
-}
-
-static NdbOut&
-operator<<(NdbOut& out, const ICol& icol)
-{
- out << "icol[" << icol.m_num << "] " << icol.m_col;
- return out;
-}
-
-// ITab - index
-
-struct ITab {
- enum Type {
- OrderedIndex = NdbDictionary::Index::OrderedIndex,
- UniqueHashIndex = NdbDictionary::Index::UniqueHashIndex
- };
- const class Tab& m_tab;
- const char* m_name;
- Type m_type;
- uint m_icols;
- const ICol** m_icol;
- uint m_keymask;
- ITab(const class Tab& tab, const char* name, Type type, uint icols);
- ~ITab();
- void icoladd(uint k, const ICol* icolptr);
-};
-
-ITab::ITab(const class Tab& tab, const char* name, Type type, uint icols) :
- m_tab(tab),
- m_name(strcpy(new char [strlen(name) + 1], name)),
- m_type(type),
- m_icols(icols),
- m_icol(new const ICol* [icols + 1]),
- m_keymask(0)
-{
- for (uint k = 0; k <= m_icols; k++)
- m_icol[k] = 0;
-}
-
-ITab::~ITab()
-{
- delete [] m_name;
- for (uint i = 0; i < m_icols; i++)
- delete m_icol[i];
- delete [] m_icol;
-}
-
-void
-ITab::icoladd(uint k, const ICol* icolptr)
-{
- assert(k == icolptr->m_num && k < m_icols && m_icol[k] == 0);
- m_icol[k] = icolptr;
- m_keymask |= (1 << icolptr->m_col.m_num);
-}
-
-static NdbOut&
-operator<<(NdbOut& out, const ITab& itab)
-{
- out << "itab " << itab.m_name << " icols=" << itab.m_icols;
- for (uint k = 0; k < itab.m_icols; k++) {
- const ICol& icol = *itab.m_icol[k];
- out << endl << icol;
- }
- return out;
-}
-
-// Tab - table
-
-struct Tab {
- const char* m_name;
- uint m_cols;
- const Col** m_col;
- uint m_pkmask;
- uint m_itabs;
- const ITab** m_itab;
- uint m_orderedindexes;
- uint m_hashindexes;
- // pk must contain an Unsigned column
- uint m_keycol;
- void coladd(uint k, Col* colptr);
- void itabadd(uint j, ITab* itab);
- Tab(const char* name, uint cols, uint itabs, uint keycol);
- ~Tab();
-};
-
-Tab::Tab(const char* name, uint cols, uint itabs, uint keycol) :
- m_name(strcpy(new char [strlen(name) + 1], name)),
- m_cols(cols),
- m_col(new const Col* [cols + 1]),
- m_pkmask(0),
- m_itabs(itabs),
- m_itab(new const ITab* [itabs + 1]),
- m_orderedindexes(0),
- m_hashindexes(0),
- m_keycol(keycol)
-{
- for (uint k = 0; k <= cols; k++)
- m_col[k] = 0;
- for (uint j = 0; j <= itabs; j++)
- m_itab[j] = 0;
-}
-
-Tab::~Tab()
-{
- delete [] m_name;
- for (uint i = 0; i < m_cols; i++)
- delete m_col[i];
- delete [] m_col;
- for (uint i = 0; i < m_itabs; i++)
- delete m_itab[i];
- delete [] m_itab;
-}
-
-void
-Tab::coladd(uint k, Col* colptr)
-{
- assert(k == colptr->m_num && k < m_cols && m_col[k] == 0);
- m_col[k] = colptr;
- if (colptr->m_pk)
- m_pkmask |= (1 << k);
-}
-
-void
-Tab::itabadd(uint j, ITab* itabptr)
-{
- assert(j < m_itabs && m_itab[j] == 0 && itabptr != 0);
- m_itab[j] = itabptr;
- if (itabptr->m_type == ITab::OrderedIndex)
- m_orderedindexes++;
- else
- m_hashindexes++;
-}
-
-static NdbOut&
-operator<<(NdbOut& out, const Tab& tab)
-{
- out << "tab " << tab.m_name << " cols=" << tab.m_cols;
- for (uint k = 0; k < tab.m_cols; k++) {
- const Col& col = *tab.m_col[k];
- out << endl << col;
- }
- for (uint i = 0; i < tab.m_itabs; i++) {
- if (tab.m_itab[i] == 0)
- continue;
- const ITab& itab = *tab.m_itab[i];
- out << endl << itab;
- }
- return out;
-}
-
-// make table structs
-
-static const Tab** tablist = 0;
-static uint tabcount = 0;
-
-static void
-verifytables()
-{
- for (uint j = 0; j < tabcount; j++) {
- const Tab* t = tablist[j];
- if (t == 0)
- continue;
- assert(t->m_cols != 0 && t->m_col != 0);
- for (uint k = 0; k < t->m_cols; k++) {
- const Col* c = t->m_col[k];
- assert(c != 0 && c->m_num == k);
- assert(!(c->m_pk && c->m_nullable));
- }
- assert(t->m_col[t->m_cols] == 0);
- {
- assert(t->m_keycol < t->m_cols);
- const Col* c = t->m_col[t->m_keycol];
- assert(c->m_pk && c->m_type == Col::Unsigned);
- }
- assert(t->m_itabs != 0 && t->m_itab != 0);
- for (uint i = 0; i < t->m_itabs; i++) {
- const ITab* x = t->m_itab[i];
- if (x == 0)
- continue;
- assert(x != 0 && x->m_icols != 0 && x->m_icol != 0);
- for (uint k = 0; k < x->m_icols; k++) {
- const ICol* c = x->m_icol[k];
- assert(c != 0 && c->m_num == k && c->m_col.m_num < t->m_cols);
- if (x->m_type == ITab::UniqueHashIndex) {
- assert(!c->m_col.m_nullable);
- }
- }
- }
- assert(t->m_itab[t->m_itabs] == 0);
- }
-}
-
-static void
-makebuiltintables(Par par)
-{
- LL2("makebuiltintables");
- resetcslist();
- tabcount = 3;
- if (tablist == 0) {
- tablist = new const Tab* [tabcount];
- for (uint j = 0; j < tabcount; j++) {
- tablist[j] = 0;
- }
- } else {
- for (uint j = 0; j < tabcount; j++) {
- delete tablist[j];
- tablist[j] = 0;
- }
- }
- // ti0 - basic
- if (usetable(par, 0)) {
- Tab* t = new Tab("ti0", 5, 7, 0);
- // name - pk - type - length - nullable - cs
- t->coladd(0, new Col(*t, 0, "a", 1, Col::Unsigned, 1, 0, 0));
- t->coladd(1, new Col(*t, 1, "b", 0, Col::Unsigned, 1, 1, 0));
- t->coladd(2, new Col(*t, 2, "c", 0, Col::Unsigned, 1, 0, 0));
- t->coladd(3, new Col(*t, 3, "d", 0, Col::Unsigned, 1, 1, 0));
- t->coladd(4, new Col(*t, 4, "e", 0, Col::Unsigned, 1, 0, 0));
- if (useindex(par, 0)) {
- // a
- ITab* x = new ITab(*t, "ti0x0", ITab::OrderedIndex, 1);
- x->icoladd(0, new ICol(*x, 0, *t->m_col[0]));
- t->itabadd(0, x);
- }
- if (useindex(par, 1)) {
- // b
- ITab* x = new ITab(*t, "ti0x1", ITab::OrderedIndex, 1);
- x->icoladd(0, new ICol(*x, 0, *t->m_col[1]));
- t->itabadd(1, x);
- }
- if (useindex(par, 2)) {
- // b, c
- ITab* x = new ITab(*t, "ti0x2", ITab::OrderedIndex, 2);
- x->icoladd(0, new ICol(*x, 0, *t->m_col[1]));
- x->icoladd(1, new ICol(*x, 1, *t->m_col[2]));
- t->itabadd(2, x);
- }
- if (useindex(par, 3)) {
- // b, e, c, d
- ITab* x = new ITab(*t, "ti0x3", ITab::OrderedIndex, 4);
- x->icoladd(0, new ICol(*x, 0, *t->m_col[1]));
- x->icoladd(1, new ICol(*x, 1, *t->m_col[4]));
- x->icoladd(2, new ICol(*x, 2, *t->m_col[2]));
- x->icoladd(3, new ICol(*x, 3, *t->m_col[3]));
- t->itabadd(3, x);
- }
- if (useindex(par, 4)) {
- // a, c
- ITab* x = new ITab(*t, "ti0z4", ITab::UniqueHashIndex, 2);
- x->icoladd(0, new ICol(*x, 0, *t->m_col[0]));
- x->icoladd(1, new ICol(*x, 1, *t->m_col[2]));
- t->itabadd(4, x);
- }
- if (useindex(par, 5)) {
- // a, e
- ITab* x = new ITab(*t, "ti0z5", ITab::UniqueHashIndex, 2);
- x->icoladd(0, new ICol(*x, 0, *t->m_col[0]));
- x->icoladd(1, new ICol(*x, 1, *t->m_col[4]));
- t->itabadd(5, x);
- }
- tablist[0] = t;
- }
- // ti1 - simple char fields
- if (usetable(par, 1)) {
- Tab* t = new Tab("ti1", 5, 7, 1);
- // name - pk - type - length - nullable - cs
- t->coladd(0, new Col(*t, 0, "a", 0, Col::Unsigned, 1, 0, 0));
- t->coladd(1, new Col(*t, 1, "b", 1, Col::Unsigned, 1, 0, 0));
- t->coladd(2, new Col(*t, 2, "c", 0, Col::Varchar, 20, 0, getcs(par)));
- t->coladd(3, new Col(*t, 3, "d", 0, Col::Char, 5, 0, getcs(par)));
- t->coladd(4, new Col(*t, 4, "e", 0, Col::Longvarchar, 5, 1, getcs(par)));
- if (useindex(par, 0)) {
- // b
- ITab* x = new ITab(*t, "ti1x0", ITab::OrderedIndex, 1);
- x->icoladd(0, new ICol(*x, 0, *t->m_col[1]));
- t->itabadd(0, x);
- }
- if (useindex(par, 1)) {
- // c, a
- ITab* x = new ITab(*t, "ti1x1", ITab::OrderedIndex, 2);
- x->icoladd(0, new ICol(*x, 0, *t->m_col[2]));
- x->icoladd(1, new ICol(*x, 1, *t->m_col[0]));
- t->itabadd(1, x);
- }
- if (useindex(par, 2)) {
- // d
- ITab* x = new ITab(*t, "ti1x2", ITab::OrderedIndex, 1);
- x->icoladd(0, new ICol(*x, 0, *t->m_col[3]));
- t->itabadd(2, x);
- }
- if (useindex(par, 3)) {
- // e, d, c, b
- ITab* x = new ITab(*t, "ti1x3", ITab::OrderedIndex, 4);
- x->icoladd(0, new ICol(*x, 0, *t->m_col[4]));
- x->icoladd(1, new ICol(*x, 1, *t->m_col[3]));
- x->icoladd(2, new ICol(*x, 2, *t->m_col[2]));
- x->icoladd(3, new ICol(*x, 3, *t->m_col[1]));
- t->itabadd(3, x);
- }
- if (useindex(par, 4)) {
- // a, b
- ITab* x = new ITab(*t, "ti1z4", ITab::UniqueHashIndex, 2);
- x->icoladd(0, new ICol(*x, 0, *t->m_col[0]));
- x->icoladd(1, new ICol(*x, 1, *t->m_col[1]));
- t->itabadd(4, x);
- }
- if (useindex(par, 5)) {
- // b, c, d
- ITab* x = new ITab(*t, "ti1z5", ITab::UniqueHashIndex, 3);
- x->icoladd(0, new ICol(*x, 0, *t->m_col[1]));
- x->icoladd(1, new ICol(*x, 1, *t->m_col[2]));
- x->icoladd(2, new ICol(*x, 2, *t->m_col[3]));
- t->itabadd(5, x);
- }
- tablist[1] = t;
- }
- // ti2 - complex char fields
- if (usetable(par, 2)) {
- Tab* t = new Tab("ti2", 5, 7, 2);
- // name - pk - type - length - nullable - cs
- t->coladd(0, new Col(*t, 0, "a", 1, Col::Char, 31, 0, getcs(par)));
- t->coladd(1, new Col(*t, 1, "b", 0, Col::Char, 4, 1, getcs(par)));
- t->coladd(2, new Col(*t, 2, "c", 1, Col::Unsigned, 1, 0, 0));
- t->coladd(3, new Col(*t, 3, "d", 1, Col::Varchar, 128, 0, getcs(par)));
- t->coladd(4, new Col(*t, 4, "e", 0, Col::Varchar, 7, 0, getcs(par)));
- if (useindex(par, 0)) {
- // a, c, d
- ITab* x = new ITab(*t, "ti2x0", ITab::OrderedIndex, 3);
- x->icoladd(0, new ICol(*x, 0, *t->m_col[0]));
- x->icoladd(1, new ICol(*x, 1, *t->m_col[2]));
- x->icoladd(2, new ICol(*x, 2, *t->m_col[3]));
- t->itabadd(0, x);
- }
- if (useindex(par, 1)) {
- // e, d, c, b, a
- ITab* x = new ITab(*t, "ti2x1", ITab::OrderedIndex, 5);
- x->icoladd(0, new ICol(*x, 0, *t->m_col[4]));
- x->icoladd(1, new ICol(*x, 1, *t->m_col[3]));
- x->icoladd(2, new ICol(*x, 2, *t->m_col[2]));
- x->icoladd(3, new ICol(*x, 3, *t->m_col[1]));
- x->icoladd(4, new ICol(*x, 4, *t->m_col[0]));
- t->itabadd(1, x);
- }
- if (useindex(par, 2)) {
- // d
- ITab* x = new ITab(*t, "ti2x2", ITab::OrderedIndex, 1);
- x->icoladd(0, new ICol(*x, 0, *t->m_col[3]));
- t->itabadd(2, x);
- }
- if (useindex(par, 3)) {
- // b
- ITab* x = new ITab(*t, "ti2x3", ITab::OrderedIndex, 1);
- x->icoladd(0, new ICol(*x, 0, *t->m_col[1]));
- t->itabadd(3, x);
- }
- if (useindex(par, 4)) {
- // a, c
- ITab* x = new ITab(*t, "ti2z4", ITab::UniqueHashIndex, 2);
- x->icoladd(0, new ICol(*x, 0, *t->m_col[0]));
- x->icoladd(1, new ICol(*x, 1, *t->m_col[2]));
- t->itabadd(4, x);
- }
- if (useindex(par, 5)) {
- // a, c, d, e
- ITab* x = new ITab(*t, "ti2z5", ITab::UniqueHashIndex, 4);
- x->icoladd(0, new ICol(*x, 0, *t->m_col[0]));
- x->icoladd(1, new ICol(*x, 1, *t->m_col[2]));
- x->icoladd(2, new ICol(*x, 2, *t->m_col[3]));
- x->icoladd(3, new ICol(*x, 3, *t->m_col[4]));
- t->itabadd(5, x);
- }
- tablist[2] = t;
- }
- verifytables();
-}
-
-// connections
-
-static Ndb_cluster_connection* g_ncc = 0;
-
-struct Con {
- Ndb* m_ndb;
- NdbDictionary::Dictionary* m_dic;
- NdbTransaction* m_tx;
- Uint64 m_txid;
- NdbOperation* m_op;
- NdbIndexOperation* m_indexop;
- NdbScanOperation* m_scanop;
- NdbIndexScanOperation* m_indexscanop;
- NdbScanFilter* m_scanfilter;
- enum ScanMode { ScanNo = 0, Committed, Latest, Exclusive };
- ScanMode m_scanmode;
- enum ErrType {
- ErrNone = 0,
- ErrDeadlock = 1,
- ErrNospace = 2,
- ErrOther = 4
- };
- ErrType m_errtype;
- char m_errname[100];
- Con() :
- m_ndb(0), m_dic(0), m_tx(0), m_txid(0), m_op(0), m_indexop(0),
- m_scanop(0), m_indexscanop(0), m_scanfilter(0),
- m_scanmode(ScanNo), m_errtype(ErrNone) {}
- ~Con() {
- if (m_tx != 0)
- closeTransaction();
- }
- int connect();
- void connect(const Con& con);
- void disconnect();
- int startTransaction();
- int getNdbOperation(const Tab& tab);
- int getNdbIndexOperation1(const ITab& itab, const Tab& tab);
- int getNdbIndexOperation(const ITab& itab, const Tab& tab);
- int getNdbScanOperation(const Tab& tab);
- int getNdbIndexScanOperation1(const ITab& itab, const Tab& tab);
- int getNdbIndexScanOperation(const ITab& itab, const Tab& tab);
- int getNdbScanFilter();
- int equal(int num, const char* addr);
- int getValue(int num, NdbRecAttr*& rec);
- int setValue(int num, const char* addr);
- int setBound(int num, int type, const void* value);
- int beginFilter(int group);
- int endFilter();
- int setFilter(int num, int cond, const void* value, uint len);
- int execute(ExecType et);
- int execute(ExecType et, uint& err);
- int readTuple(Par par);
- int readTuples(Par par);
- int readIndexTuples(Par par);
- int executeScan();
- int nextScanResult(bool fetchAllowed);
- int nextScanResult(bool fetchAllowed, uint& err);
- int updateScanTuple(Con& con2);
- int deleteScanTuple(Con& con2);
- void closeScan();
- void closeTransaction();
- const char* errname(uint err);
- void printerror(NdbOut& out);
-};
-
-int
-Con::connect()
-{
- assert(m_ndb == 0);
- m_ndb = new Ndb(g_ncc, "TEST_DB");
- CHKCON(m_ndb->init() == 0, *this);
- CHKCON(m_ndb->waitUntilReady(30) == 0, *this);
- m_tx = 0, m_txid = 0, m_op = 0;
- return 0;
-}
-
-void
-Con::connect(const Con& con)
-{
- assert(m_ndb == 0);
- m_ndb = con.m_ndb;
-}
-
-void
-Con::disconnect()
-{
- delete m_ndb;
- m_ndb = 0, m_dic = 0, m_tx = 0, m_txid = 0, m_op = 0;
-}
-
-int
-Con::startTransaction()
-{
- assert(m_ndb != 0);
- if (m_tx != 0)
- closeTransaction();
- CHKCON((m_tx = m_ndb->startTransaction()) != 0, *this);
- m_txid = m_tx->getTransactionId();
- return 0;
-}
-
-int
-Con::getNdbOperation(const Tab& tab)
-{
- assert(m_tx != 0);
- CHKCON((m_op = m_tx->getNdbOperation(tab.m_name)) != 0, *this);
- return 0;
-}
-
-int
-Con::getNdbIndexOperation1(const ITab& itab, const Tab& tab)
-{
- assert(m_tx != 0);
- CHKCON((m_op = m_indexop = m_tx->getNdbIndexOperation(itab.m_name, tab.m_name)) != 0, *this);
- return 0;
-}
-
-int
-Con::getNdbIndexOperation(const ITab& itab, const Tab& tab)
-{
- assert(m_tx != 0);
- uint tries = 0;
- while (1) {
- if (getNdbIndexOperation1(itab, tab) == 0)
- break;
- CHK(++tries < 10);
- NdbSleep_MilliSleep(100);
- }
- return 0;
-}
-
-int
-Con::getNdbScanOperation(const Tab& tab)
-{
- assert(m_tx != 0);
- CHKCON((m_op = m_scanop = m_tx->getNdbScanOperation(tab.m_name)) != 0, *this);
- return 0;
-}
-
-int
-Con::getNdbIndexScanOperation1(const ITab& itab, const Tab& tab)
-{
- assert(m_tx != 0);
- CHKCON((m_op = m_scanop = m_indexscanop = m_tx->getNdbIndexScanOperation(itab.m_name, tab.m_name)) != 0, *this);
- return 0;
-}
-
-int
-Con::getNdbIndexScanOperation(const ITab& itab, const Tab& tab)
-{
- assert(m_tx != 0);
- uint tries = 0;
- while (1) {
- if (getNdbIndexScanOperation1(itab, tab) == 0)
- break;
- CHK(++tries < 10);
- NdbSleep_MilliSleep(100);
- }
- return 0;
-}
-
-int
-Con::getNdbScanFilter()
-{
- assert(m_tx != 0 && m_scanop != 0);
- delete m_scanfilter;
- m_scanfilter = new NdbScanFilter(m_scanop);
- return 0;
-}
-
-int
-Con::equal(int num, const char* addr)
-{
- assert(m_tx != 0 && m_op != 0);
- CHKCON(m_op->equal(num, addr) == 0, *this);
- return 0;
-}
-
-int
-Con::getValue(int num, NdbRecAttr*& rec)
-{
- assert(m_tx != 0 && m_op != 0);
- CHKCON((rec = m_op->getValue(num, 0)) != 0, *this);
- return 0;
-}
-
-int
-Con::setValue(int num, const char* addr)
-{
- assert(m_tx != 0 && m_op != 0);
- CHKCON(m_op->setValue(num, addr) == 0, *this);
- return 0;
-}
-
-int
-Con::setBound(int num, int type, const void* value)
-{
- assert(m_tx != 0 && m_indexscanop != 0);
- CHKCON(m_indexscanop->setBound(num, type, value) == 0, *this);
- return 0;
-}
-
-int
-Con::beginFilter(int group)
-{
- assert(m_tx != 0 && m_scanfilter != 0);
- CHKCON(m_scanfilter->begin((NdbScanFilter::Group)group) == 0, *this);
- return 0;
-}
-
-int
-Con::endFilter()
-{
- assert(m_tx != 0 && m_scanfilter != 0);
- CHKCON(m_scanfilter->end() == 0, *this);
- return 0;
-}
-
-int
-Con::setFilter(int num, int cond, const void* value, uint len)
-{
- assert(m_tx != 0 && m_scanfilter != 0);
- CHKCON(m_scanfilter->cmp((NdbScanFilter::BinaryCondition)cond, num, value, len) == 0, *this);
- return 0;
-}
-
-int
-Con::execute(ExecType et)
-{
- assert(m_tx != 0);
- CHKCON(m_tx->execute(et) == 0, *this);
- return 0;
-}
-
-int
-Con::execute(ExecType et, uint& err)
-{
- int ret = execute(et);
- // err in: errors to catch, out: error caught
- const uint errin = err;
- err = 0;
- if (ret == -1) {
- if (m_errtype == ErrDeadlock && (errin & ErrDeadlock)) {
- LL3("caught deadlock");
- err = ErrDeadlock;
- ret = 0;
- }
- if (m_errtype == ErrNospace && (errin & ErrNospace)) {
- LL3("caught nospace");
- err = ErrNospace;
- ret = 0;
- }
- }
- CHK(ret == 0);
- return 0;
-}
-
-int
-Con::readTuple(Par par)
-{
- assert(m_tx != 0 && m_op != 0);
- NdbOperation::LockMode lm = par.m_lockmode;
- CHKCON(m_op->readTuple(lm) == 0, *this);
- return 0;
-}
-
-int
-Con::readTuples(Par par)
-{
- assert(m_tx != 0 && m_scanop != 0);
- int scan_flags = 0;
- if (par.m_tupscan)
- scan_flags |= NdbScanOperation::SF_TupScan;
- CHKCON(m_scanop->readTuples(par.m_lockmode, scan_flags, par.m_scanpar, par.m_scanbatch) == 0, *this);
- return 0;
-}
-
-int
-Con::readIndexTuples(Par par)
-{
- assert(m_tx != 0 && m_indexscanop != 0);
- int scan_flags = 0;
- if (par.m_ordered)
- scan_flags |= NdbScanOperation::SF_OrderBy;
- if (par.m_descending)
- scan_flags |= NdbScanOperation::SF_Descending;
- CHKCON(m_indexscanop->readTuples(par.m_lockmode, scan_flags, par.m_scanpar, par.m_scanbatch) == 0, *this);
- return 0;
-}
-
-int
-Con::executeScan()
-{
- CHKCON(m_tx->execute(NoCommit) == 0, *this);
- return 0;
-}
-
-int
-Con::nextScanResult(bool fetchAllowed)
-{
- int ret;
- assert(m_scanop != 0);
- CHKCON((ret = m_scanop->nextResult(fetchAllowed)) != -1, *this);
- assert(ret == 0 || ret == 1 || (!fetchAllowed && ret == 2));
- return ret;
-}
-
-int
-Con::nextScanResult(bool fetchAllowed, uint& err)
-{
- int ret = nextScanResult(fetchAllowed);
- // err in: errors to catch, out: error caught
- const uint errin = err;
- err = 0;
- if (ret == -1) {
- if (m_errtype == ErrDeadlock && (errin & ErrDeadlock)) {
- LL3("caught deadlock");
- err = ErrDeadlock;
- ret = 0;
- }
- }
- CHK(ret == 0 || ret == 1 || (!fetchAllowed && ret == 2));
- return ret;
-}
-
-int
-Con::updateScanTuple(Con& con2)
-{
- assert(con2.m_tx != 0);
- CHKCON((con2.m_op = m_scanop->updateCurrentTuple(con2.m_tx)) != 0, *this);
- con2.m_txid = m_txid; // in the kernel
- return 0;
-}
-
-int
-Con::deleteScanTuple(Con& con2)
-{
- assert(con2.m_tx != 0);
- CHKCON(m_scanop->deleteCurrentTuple(con2.m_tx) == 0, *this);
- con2.m_txid = m_txid; // in the kernel
- return 0;
-}
-
-void
-Con::closeScan()
-{
- assert(m_scanop != 0);
- m_scanop->close();
- m_scanop = 0, m_indexscanop = 0;
-
-}
-
-void
-Con::closeTransaction()
-{
- assert(m_ndb != 0 && m_tx != 0);
- m_ndb->closeTransaction(m_tx);
- m_tx = 0, m_txid = 0, m_op = 0;
- m_scanop = 0, m_indexscanop = 0;
-}
-
-const char*
-Con::errname(uint err)
-{
- sprintf(m_errname, "0x%x", err);
- if (err & ErrDeadlock)
- strcat(m_errname, ",deadlock");
- if (err & ErrNospace)
- strcat(m_errname, ",nospace");
- return m_errname;
-}
-
-void
-Con::printerror(NdbOut& out)
-{
- m_errtype = ErrOther;
- uint any = 0;
- int code;
- int die = 0;
- if (m_ndb) {
- if ((code = m_ndb->getNdbError().code) != 0) {
- LL0(++any << " ndb: error " << m_ndb->getNdbError());
- die += (code == g_opt.m_die);
- }
- if (m_dic && (code = m_dic->getNdbError().code) != 0) {
- LL0(++any << " dic: error " << m_dic->getNdbError());
- die += (code == g_opt.m_die);
- }
- if (m_tx) {
- if ((code = m_tx->getNdbError().code) != 0) {
- LL0(++any << " con: error " << m_tx->getNdbError());
- die += (code == g_opt.m_die);
- // 631 is new, occurs only on 4 db nodes, needs to be checked out
- if (code == 266 || code == 274 || code == 296 || code == 297 || code == 499 || code == 631)
- m_errtype = ErrDeadlock;
- if (code == 826 || code == 827 || code == 902)
- m_errtype = ErrNospace;
- }
- if (m_op && m_op->getNdbError().code != 0) {
- LL0(++any << " op : error " << m_op->getNdbError());
- die += (code == g_opt.m_die);
- }
- }
- }
- if (!any) {
- LL0("failed but no NDB error code");
- }
- if (die) {
- if (g_opt.m_core)
- abort();
- exit(1);
- }
-}
-
-// dictionary operations
-
-static int
-invalidateindex(Par par, const ITab& itab)
-{
- Con& con = par.con();
- const Tab& tab = par.tab();
- con.m_ndb->getDictionary()->invalidateIndex(itab.m_name, tab.m_name);
- return 0;
-}
-
-static int
-invalidateindex(Par par)
-{
- Con& con = par.con();
- const Tab& tab = par.tab();
- for (uint i = 0; i < tab.m_itabs; i++) {
- if (tab.m_itab[i] == 0)
- continue;
- const ITab& itab = *tab.m_itab[i];
- invalidateindex(par, itab);
- }
- return 0;
-}
-
-static int
-invalidatetable(Par par)
-{
- Con& con = par.con();
- const Tab& tab = par.tab();
- invalidateindex(par);
- con.m_ndb->getDictionary()->invalidateTable(tab.m_name);
- return 0;
-}
-
-static int
-droptable(Par par)
-{
- Con& con = par.con();
- const Tab& tab = par.tab();
- con.m_dic = con.m_ndb->getDictionary();
- if (con.m_dic->getTable(tab.m_name) == 0) {
- // how to check for error
- LL4("no table " << tab.m_name);
- } else {
- LL3("drop table " << tab.m_name);
- CHKCON(con.m_dic->dropTable(tab.m_name) == 0, con);
- }
- con.m_dic = 0;
- return 0;
-}
-
-static int
-createtable(Par par)
-{
- Con& con = par.con();
- const Tab& tab = par.tab();
- LL3("create table " << tab.m_name);
- LL4(tab);
- NdbDictionary::Table t(tab.m_name);
- if (par.m_fragtype != NdbDictionary::Object::FragUndefined) {
- t.setFragmentType(par.m_fragtype);
- }
- if (par.m_nologging) {
- t.setLogging(false);
- }
- for (uint k = 0; k < tab.m_cols; k++) {
- const Col& col = *tab.m_col[k];
- NdbDictionary::Column c(col.m_name);
- c.setType((NdbDictionary::Column::Type)col.m_type);
- c.setLength(col.m_bytelength); // for char NDB API uses length in bytes
- c.setPrimaryKey(col.m_pk);
- c.setNullable(col.m_nullable);
- if (col.m_chs != 0)
- c.setCharset(col.m_chs->m_cs);
- t.addColumn(c);
- }
- con.m_dic = con.m_ndb->getDictionary();
- CHKCON(con.m_dic->createTable(t) == 0, con);
- con.m_dic = 0;
- return 0;
-}
-
-static int
-dropindex(Par par, const ITab& itab)
-{
- Con& con = par.con();
- const Tab& tab = par.tab();
- con.m_dic = con.m_ndb->getDictionary();
- if (con.m_dic->getIndex(itab.m_name, tab.m_name) == 0) {
- // how to check for error
- LL4("no index " << itab.m_name);
- } else {
- LL3("drop index " << itab.m_name);
- CHKCON(con.m_dic->dropIndex(itab.m_name, tab.m_name) == 0, con);
- }
- con.m_dic = 0;
- return 0;
-}
-
-static int
-dropindex(Par par)
-{
- const Tab& tab = par.tab();
- for (uint i = 0; i < tab.m_itabs; i++) {
- if (tab.m_itab[i] == 0)
- continue;
- const ITab& itab = *tab.m_itab[i];
- CHK(dropindex(par, itab) == 0);
- }
- return 0;
-}
-
-static int
-createindex(Par par, const ITab& itab)
-{
- Con& con = par.con();
- const Tab& tab = par.tab();
- LL3("create index " << itab.m_name);
- LL4(itab);
- NdbDictionary::Index x(itab.m_name);
- x.setTable(tab.m_name);
- x.setType((NdbDictionary::Index::Type)itab.m_type);
- if (par.m_nologging || itab.m_type == ITab::OrderedIndex) {
- x.setLogging(false);
- }
- for (uint k = 0; k < itab.m_icols; k++) {
- const ICol& icol = *itab.m_icol[k];
- const Col& col = icol.m_col;
- x.addColumnName(col.m_name);
- }
- con.m_dic = con.m_ndb->getDictionary();
- CHKCON(con.m_dic->createIndex(x) == 0, con);
- con.m_dic = 0;
- return 0;
-}
-
-static int
-createindex(Par par)
-{
- const Tab& tab = par.tab();
- for (uint i = 0; i < tab.m_itabs; i++) {
- if (tab.m_itab[i] == 0)
- continue;
- const ITab& itab = *tab.m_itab[i];
- CHK(createindex(par, itab) == 0);
- }
- return 0;
-}
-
-// data sets
-
-// Val - typed column value
-
-struct Val {
- const Col& m_col;
- union {
- Uint32 m_uint32;
- uchar* m_char;
- uchar* m_varchar;
- uchar* m_longvarchar;
- };
- bool m_null;
- // construct
- Val(const Col& col);
- ~Val();
- void copy(const Val& val2);
- void copy(const void* addr);
- const void* dataaddr() const;
- void calc(Par par, uint i);
- void calckey(Par par, uint i);
- void calckeychars(Par par, uint i, uint& n, uchar* buf);
- void calcnokey(Par par);
- void calcnokeychars(Par par, uint& n, uchar* buf);
- // operations
- int setval(Par par) const;
- int setval(Par par, const ICol& icol) const;
- // compare
- int cmp(Par par, const Val& val2) const;
- int cmpchars(Par par, const uchar* buf1, uint len1, const uchar* buf2, uint len2) const;
- int verify(Par par, const Val& val2) const;
-private:
- Val& operator=(const Val& val2);
-};
-
-static NdbOut&
-operator<<(NdbOut& out, const Val& val);
-
-// construct
-
-Val::Val(const Col& col) :
- m_col(col)
-{
- switch (col.m_type) {
- case Col::Unsigned:
- m_uint32 = 0x7e7e7e7e;
- break;
- case Col::Char:
- m_char = new uchar [col.m_bytelength];
- memset(m_char, 0x7e, col.m_bytelength);
- break;
- case Col::Varchar:
- m_varchar = new uchar [1 + col.m_bytelength];
- memset(m_char, 0x7e, 1 + col.m_bytelength);
- break;
- case Col::Longvarchar:
- m_longvarchar = new uchar [2 + col.m_bytelength];
- memset(m_char, 0x7e, 2 + col.m_bytelength);
- break;
- default:
- assert(false);
- break;
- }
-}
-
-Val::~Val()
-{
- const Col& col = m_col;
- switch (col.m_type) {
- case Col::Unsigned:
- break;
- case Col::Char:
- delete [] m_char;
- break;
- case Col::Varchar:
- delete [] m_varchar;
- break;
- case Col::Longvarchar:
- delete [] m_longvarchar;
- break;
- default:
- assert(false);
- break;
- }
-}
-
-void
-Val::copy(const Val& val2)
-{
- const Col& col = m_col;
- const Col& col2 = val2.m_col;
- assert(col.m_type == col2.m_type && col.m_length == col2.m_length);
- if (val2.m_null) {
- m_null = true;
- return;
- }
- copy(val2.dataaddr());
-}
-
-void
-Val::copy(const void* addr)
-{
- const Col& col = m_col;
- switch (col.m_type) {
- case Col::Unsigned:
- m_uint32 = *(const Uint32*)addr;
- break;
- case Col::Char:
- memcpy(m_char, addr, col.m_bytelength);
- break;
- case Col::Varchar:
- memcpy(m_varchar, addr, 1 + col.m_bytelength);
- break;
- case Col::Longvarchar:
- memcpy(m_longvarchar, addr, 2 + col.m_bytelength);
- break;
- default:
- assert(false);
- break;
- }
- m_null = false;
-}
-
-const void*
-Val::dataaddr() const
-{
- const Col& col = m_col;
- switch (col.m_type) {
- case Col::Unsigned:
- return &m_uint32;
- case Col::Char:
- return m_char;
- case Col::Varchar:
- return m_varchar;
- case Col::Longvarchar:
- return m_longvarchar;
- default:
- break;
- }
- assert(false);
- return 0;
-}
-
-void
-Val::calc(Par par, uint i)
-{
- const Col& col = m_col;
- col.m_pk ? calckey(par, i) : calcnokey(par);
- if (!m_null)
- col.wellformed(dataaddr());
-}
-
-void
-Val::calckey(Par par, uint i)
-{
- const Col& col = m_col;
- m_null = false;
- switch (col.m_type) {
- case Col::Unsigned:
- m_uint32 = i;
- break;
- case Col::Char:
- {
- const Chs* chs = col.m_chs;
- CHARSET_INFO* cs = chs->m_cs;
- uint n = 0;
- calckeychars(par, i, n, m_char);
- // extend by appropriate space
- (*cs->cset->fill)(cs, (char*)&m_char[n], col.m_bytelength - n, 0x20);
- }
- break;
- case Col::Varchar:
- {
- uint n = 0;
- calckeychars(par, i, n, m_varchar + 1);
- // set length and pad with nulls
- m_varchar[0] = n;
- memset(&m_varchar[1 + n], 0, col.m_bytelength - n);
- }
- break;
- case Col::Longvarchar:
- {
- uint n = 0;
- calckeychars(par, i, n, m_longvarchar + 2);
- // set length and pad with nulls
- m_longvarchar[0] = (n & 0xff);
- m_longvarchar[1] = (n >> 8);
- memset(&m_longvarchar[2 + n], 0, col.m_bytelength - n);
- }
- break;
- default:
- assert(false);
- break;
- }
-}
-
-void
-Val::calckeychars(Par par, uint i, uint& n, uchar* buf)
-{
- const Col& col = m_col;
- const Chs* chs = col.m_chs;
- CHARSET_INFO* cs = chs->m_cs;
- n = 0;
- uint len = 0;
- while (len < col.m_length) {
- if (i % (1 + n) == 0) {
- break;
- }
- const Chr& chr = chs->m_chr[i % maxcharcount];
- assert(n + chr.m_size <= col.m_bytelength);
- memcpy(buf + n, chr.m_bytes, chr.m_size);
- n += chr.m_size;
- len++;
- }
-}
-
-void
-Val::calcnokey(Par par)
-{
- const Col& col = m_col;
- m_null = false;
- if (col.m_nullable && urandom(100) < par.m_pctnull) {
- m_null = true;
- return;
- }
- int r = irandom((par.m_pctrange * par.m_range) / 100);
- if (par.m_bdir != 0 && urandom(10) != 0) {
- if (r < 0 && par.m_bdir > 0 || r > 0 && par.m_bdir < 0)
- r = -r;
- }
- uint v = par.m_range + r;
- switch (col.m_type) {
- case Col::Unsigned:
- m_uint32 = v;
- break;
- case Col::Char:
- {
- const Chs* chs = col.m_chs;
- CHARSET_INFO* cs = chs->m_cs;
- uint n = 0;
- calcnokeychars(par, n, m_char);
- // extend by appropriate space
- (*cs->cset->fill)(cs, (char*)&m_char[n], col.m_bytelength - n, 0x20);
- }
- break;
- case Col::Varchar:
- {
- uint n = 0;
- calcnokeychars(par, n, m_varchar + 1);
- // set length and pad with nulls
- m_varchar[0] = n;
- memset(&m_varchar[1 + n], 0, col.m_bytelength - n);
- }
- break;
- case Col::Longvarchar:
- {
- uint n = 0;
- calcnokeychars(par, n, m_longvarchar + 2);
- // set length and pad with nulls
- m_longvarchar[0] = (n & 0xff);
- m_longvarchar[1] = (n >> 8);
- memset(&m_longvarchar[2 + n], 0, col.m_bytelength - n);
- }
- break;
- default:
- assert(false);
- break;
- }
-}
-
-void
-Val::calcnokeychars(Par par, uint& n, uchar* buf)
-{
- const Col& col = m_col;
- const Chs* chs = col.m_chs;
- CHARSET_INFO* cs = chs->m_cs;
- n = 0;
- uint len = 0;
- while (len < col.m_length) {
- if (urandom(1 + col.m_bytelength) == 0) {
- break;
- }
- uint half = maxcharcount / 2;
- int r = irandom((par.m_pctrange * half) / 100);
- if (par.m_bdir != 0 && urandom(10) != 0) {
- if (r < 0 && par.m_bdir > 0 || r > 0 && par.m_bdir < 0)
- r = -r;
- }
- uint i = half + r;
- assert(i < maxcharcount);
- const Chr& chr = chs->m_chr[i];
- assert(n + chr.m_size <= col.m_bytelength);
- memcpy(buf + n, chr.m_bytes, chr.m_size);
- n += chr.m_size;
- len++;
- }
-}
-
-// operations
-
-int
-Val::setval(Par par) const
-{
- Con& con = par.con();
- const Col& col = m_col;
- if (col.m_pk) {
- assert(!m_null);
- const char* addr = (const char*)dataaddr();
- LL5("setval pk [" << col << "] " << *this);
- CHK(con.equal(col.m_num, addr) == 0);
- } else {
- const char* addr = !m_null ? (const char*)dataaddr() : 0;
- LL5("setval non-pk [" << col << "] " << *this);
- CHK(con.setValue(col.m_num, addr) == 0);
- }
- return 0;
-}
-
-int
-Val::setval(Par par, const ICol& icol) const
-{
- Con& con = par.con();
- assert(!m_null);
- const char* addr = (const char*)dataaddr();
- LL5("setval key [" << icol << "] " << *this);
- CHK(con.equal(icol.m_num, addr) == 0);
- return 0;
-}
-
-// compare
-
-int
-Val::cmp(Par par, const Val& val2) const
-{
- const Col& col = m_col;
- const Col& col2 = val2.m_col;
- assert(col.equal(col2));
- if (m_null || val2.m_null) {
- if (!m_null)
- return +1;
- if (!val2.m_null)
- return -1;
- return 0;
- }
- // verify data formats
- col.wellformed(dataaddr());
- col.wellformed(val2.dataaddr());
- // compare
- switch (col.m_type) {
- case Col::Unsigned:
- {
- if (m_uint32 < val2.m_uint32)
- return -1;
- if (m_uint32 > val2.m_uint32)
- return +1;
- return 0;
- }
- break;
- case Col::Char:
- {
- uint len = col.m_bytelength;
- return cmpchars(par, m_char, len, val2.m_char, len);
- }
- break;
- case Col::Varchar:
- {
- uint len1 = m_varchar[0];
- uint len2 = val2.m_varchar[0];
- return cmpchars(par, m_varchar + 1, len1, val2.m_varchar + 1, len2);
- }
- break;
- case Col::Longvarchar:
- {
- uint len1 = m_longvarchar[0] + (m_longvarchar[1] << 8);
- uint len2 = val2.m_longvarchar[0] + (val2.m_longvarchar[1] << 8);
- return cmpchars(par, m_longvarchar + 2, len1, val2.m_longvarchar + 2, len2);
- }
- break;
- default:
- break;
- }
- assert(false);
- return 0;
-}
-
-int
-Val::cmpchars(Par par, const uchar* buf1, uint len1, const uchar* buf2, uint len2) const
-{
- const Col& col = m_col;
- const Chs* chs = col.m_chs;
- CHARSET_INFO* cs = chs->m_cs;
- int k;
- if (!par.m_collsp) {
- uchar x1[maxxmulsize * 8000];
- uchar x2[maxxmulsize * 8000];
- // make strxfrm pad both to same length
- uint len = maxxmulsize * col.m_bytelength;
- int n1 = NdbSqlUtil::strnxfrm_bug7284(cs, x1, chs->m_xmul * len, buf1, len1);
- int n2 = NdbSqlUtil::strnxfrm_bug7284(cs, x2, chs->m_xmul * len, buf2, len2);
- assert(n1 != -1 && n1 == n2);
- k = memcmp(x1, x2, n1);
- } else {
- k = (*cs->coll->strnncollsp)(cs, buf1, len1, buf2, len2, false);
- }
- return k < 0 ? -1 : k > 0 ? +1 : 0;
-}
-
-int
-Val::verify(Par par, const Val& val2) const
-{
- CHK(cmp(par, val2) == 0);
- return 0;
-}
-
-// print
-
-static void
-printstring(NdbOut& out, const uchar* str, uint len, bool showlen)
-{
- char buf[4 * 8000];
- char *p = buf;
- *p++ = '[';
- if (showlen) {
- sprintf(p, "%u:", len);
- p += strlen(p);
- }
- for (uint i = 0; i < len; i++) {
- uchar c = str[i];
- if (c == '\\') {
- *p++ = '\\';
- *p++ = c;
- } else if (0x20 <= c && c <= 0x7e) {
- *p++ = c;
- } else {
- *p++ = '\\';
- *p++ = hexstr[c >> 4];
- *p++ = hexstr[c & 15];
- }
- }
- *p++ = ']';
- *p = 0;
- out << buf;
-}
-
-static NdbOut&
-operator<<(NdbOut& out, const Val& val)
-{
- const Col& col = val.m_col;
- if (val.m_null) {
- out << "NULL";
- return out;
- }
- switch (col.m_type) {
- case Col::Unsigned:
- out << val.m_uint32;
- break;
- case Col::Char:
- {
- uint len = col.m_bytelength;
- printstring(out, val.m_char, len, false);
- }
- break;
- case Col::Varchar:
- {
- uint len = val.m_varchar[0];
- printstring(out, val.m_varchar + 1, len, true);
- }
- break;
- case Col::Longvarchar:
- {
- uint len = val.m_longvarchar[0] + (val.m_longvarchar[1] << 8);
- printstring(out, val.m_longvarchar + 2, len, true);
- }
- break;
- default:
- out << "type" << col.m_type;
- assert(false);
- break;
- }
- return out;
-}
-
-// Row - table tuple
-
-struct Row {
- const Tab& m_tab;
- Val** m_val;
- enum St {
- StUndef = 0,
- StDefine = 1,
- StPrepare = 2,
- StCommit = 3
- };
- enum Op {
- OpNone = 0,
- OpIns = 2,
- OpUpd = 4,
- OpDel = 8,
- OpRead = 16,
- OpReadEx = 32,
- OpReadCom = 64,
- OpDML = 2 | 4 | 8,
- OpREAD = 16 | 32 | 64
- };
- St m_st;
- Op m_op;
- Uint64 m_txid;
- Row* m_bi;
- // construct
- Row(const Tab& tab);
- ~Row();
- void copy(const Row& row2, bool copy_bi);
- void copyval(const Row& row2, uint colmask = ~0);
- void calc(Par par, uint i, uint colmask = ~0);
- // operations
- int setval(Par par, uint colmask = ~0);
- int setval(Par par, const ITab& itab);
- int insrow(Par par);
- int updrow(Par par);
- int updrow(Par par, const ITab& itab);
- int delrow(Par par);
- int delrow(Par par, const ITab& itab);
- int selrow(Par par);
- int selrow(Par par, const ITab& itab);
- int setrow(Par par);
- // compare
- int cmp(Par par, const Row& row2) const;
- int cmp(Par par, const Row& row2, const ITab& itab) const;
- int verify(Par par, const Row& row2, bool pkonly) const;
-private:
- Row& operator=(const Row& row2);
-};
-
-static NdbOut&
-operator<<(NdbOut& out, const Row* rowp);
-
-static NdbOut&
-operator<<(NdbOut& out, const Row& row);
-
-// construct
-
-Row::Row(const Tab& tab) :
- m_tab(tab)
-{
- m_val = new Val* [tab.m_cols];
- for (uint k = 0; k < tab.m_cols; k++) {
- const Col& col = *tab.m_col[k];
- m_val[k] = new Val(col);
- }
- m_st = StUndef;
- m_op = OpNone;
- m_txid = 0;
- m_bi = 0;
-}
-
-Row::~Row()
-{
- const Tab& tab = m_tab;
- for (uint k = 0; k < tab.m_cols; k++) {
- delete m_val[k];
- }
- delete [] m_val;
- delete m_bi;
-}
-
-void
-Row::copy(const Row& row2, bool copy_bi)
-{
- const Tab& tab = m_tab;
- copyval(row2);
- m_st = row2.m_st;
- m_op = row2.m_op;
- m_txid = row2.m_txid;
- assert(m_bi == 0);
- if (copy_bi && row2.m_bi != 0) {
- m_bi = new Row(tab);
- m_bi->copy(*row2.m_bi, copy_bi);
- }
-}
-
-void
-Row::copyval(const Row& row2, uint colmask)
-{
- const Tab& tab = m_tab;
- assert(&tab == &row2.m_tab);
- for (uint k = 0; k < tab.m_cols; k++) {
- Val& val = *m_val[k];
- const Val& val2 = *row2.m_val[k];
- if ((1 << k) & colmask)
- val.copy(val2);
- }
-}
-
-void
-Row::calc(Par par, uint i, uint colmask)
-{
- const Tab& tab = m_tab;
- for (uint k = 0; k < tab.m_cols; k++) {
- if ((1 << k) & colmask) {
- Val& val = *m_val[k];
- val.calc(par, i);
- }
- }
-}
-
-// operations
-
-int
-Row::setval(Par par, uint colmask)
-{
- const Tab& tab = m_tab;
- Rsq rsq(tab.m_cols);
- for (uint k = 0; k < tab.m_cols; k++) {
- uint k2 = rsq.next();
- if ((1 << k2) & colmask) {
- const Val& val = *m_val[k2];
- CHK(val.setval(par) == 0);
- }
- }
- return 0;
-}
-
-int
-Row::setval(Par par, const ITab& itab)
-{
- Con& con = par.con();
- Rsq rsq(itab.m_icols);
- for (uint k = 0; k < itab.m_icols; k++) {
- uint k2 = rsq.next();
- const ICol& icol = *itab.m_icol[k2];
- const Col& col = icol.m_col;
- uint m = col.m_num;
- const Val& val = *m_val[m];
- CHK(val.setval(par, icol) == 0);
- }
- return 0;
-}
-
-int
-Row::insrow(Par par)
-{
- Con& con = par.con();
- const Tab& tab = m_tab;
- CHK(con.getNdbOperation(tab) == 0);
- CHKCON(con.m_op->insertTuple() == 0, con);
- CHK(setval(par, tab.m_pkmask) == 0);
- CHK(setval(par, ~tab.m_pkmask) == 0);
- assert(m_st == StUndef);
- m_st = StDefine;
- m_op = OpIns;
- m_txid = con.m_txid;
- return 0;
-}
-
-int
-Row::updrow(Par par)
-{
- Con& con = par.con();
- const Tab& tab = m_tab;
- CHK(con.getNdbOperation(tab) == 0);
- CHKCON(con.m_op->updateTuple() == 0, con);
- CHK(setval(par, tab.m_pkmask) == 0);
- CHK(setval(par, ~tab.m_pkmask) == 0);
- assert(m_st == StUndef);
- m_st = StDefine;
- m_op = OpUpd;
- m_txid = con.m_txid;
- return 0;
-}
-
-int
-Row::updrow(Par par, const ITab& itab)
-{
- Con& con = par.con();
- const Tab& tab = m_tab;
- assert(itab.m_type == ITab::UniqueHashIndex && &itab.m_tab == &tab);
- CHK(con.getNdbIndexOperation(itab, tab) == 0);
- CHKCON(con.m_op->updateTuple() == 0, con);
- CHK(setval(par, itab) == 0);
- CHK(setval(par, ~tab.m_pkmask) == 0);
- assert(m_st == StUndef);
- m_st = StDefine;
- m_op = OpUpd;
- m_txid = con.m_txid;
- return 0;
-}
-
-int
-Row::delrow(Par par)
-{
- Con& con = par.con();
- const Tab& tab = m_tab;
- CHK(con.getNdbOperation(m_tab) == 0);
- CHKCON(con.m_op->deleteTuple() == 0, con);
- CHK(setval(par, tab.m_pkmask) == 0);
- assert(m_st == StUndef);
- m_st = StDefine;
- m_op = OpDel;
- m_txid = con.m_txid;
- return 0;
-}
-
-int
-Row::delrow(Par par, const ITab& itab)
-{
- Con& con = par.con();
- const Tab& tab = m_tab;
- assert(itab.m_type == ITab::UniqueHashIndex && &itab.m_tab == &tab);
- CHK(con.getNdbIndexOperation(itab, tab) == 0);
- CHKCON(con.m_op->deleteTuple() == 0, con);
- CHK(setval(par, itab) == 0);
- assert(m_st == StUndef);
- m_st = StDefine;
- m_op = OpDel;
- m_txid = con.m_txid;
- return 0;
-}
-
-int
-Row::selrow(Par par)
-{
- Con& con = par.con();
- const Tab& tab = m_tab;
- CHK(con.getNdbOperation(m_tab) == 0);
- CHKCON(con.readTuple(par) == 0, con);
- CHK(setval(par, tab.m_pkmask) == 0);
- // TODO state
- return 0;
-}
-
-int
-Row::selrow(Par par, const ITab& itab)
-{
- Con& con = par.con();
- const Tab& tab = m_tab;
- assert(itab.m_type == ITab::UniqueHashIndex && &itab.m_tab == &tab);
- CHK(con.getNdbIndexOperation(itab, tab) == 0);
- CHKCON(con.readTuple(par) == 0, con);
- CHK(setval(par, itab) == 0);
- // TODO state
- return 0;
-}
-
-int
-Row::setrow(Par par)
-{
- Con& con = par.con();
- const Tab& tab = m_tab;
- CHK(setval(par, ~tab.m_pkmask) == 0);
- assert(m_st == StUndef);
- m_st = StDefine;
- m_op = OpUpd;
- m_txid = con.m_txid;
- return 0;
-}
-
-// compare
-
-int
-Row::cmp(Par par, const Row& row2) const
-{
- const Tab& tab = m_tab;
- assert(&tab == &row2.m_tab);
- int c = 0;
- for (uint k = 0; k < tab.m_cols; k++) {
- const Val& val = *m_val[k];
- const Val& val2 = *row2.m_val[k];
- if ((c = val.cmp(par, val2)) != 0)
- break;
- }
- return c;
-}
-
-int
-Row::cmp(Par par, const Row& row2, const ITab& itab) const
-{
- const Tab& tab = m_tab;
- int c = 0;
- for (uint i = 0; i < itab.m_icols; i++) {
- const ICol& icol = *itab.m_icol[i];
- const Col& col = icol.m_col;
- uint k = col.m_num;
- assert(k < tab.m_cols);
- const Val& val = *m_val[k];
- const Val& val2 = *row2.m_val[k];
- if ((c = val.cmp(par, val2)) != 0)
- break;
- }
- return c;
-}
-
-int
-Row::verify(Par par, const Row& row2, bool pkonly) const
-{
- const Tab& tab = m_tab;
- const Row& row1 = *this;
- assert(&row1.m_tab == &row2.m_tab);
- for (uint k = 0; k < tab.m_cols; k++) {
- const Col& col = row1.m_val[k]->m_col;
- if (!pkonly || col.m_pk) {
- const Val& val1 = *row1.m_val[k];
- const Val& val2 = *row2.m_val[k];
- CHK(val1.verify(par, val2) == 0);
- }
- }
- return 0;
-}
-
-// print
-
-static NdbOut&
-operator<<(NdbOut& out, const Row::St st)
-{
- if (st == Row::StUndef)
- out << "StUndef";
- else if (st == Row::StDefine)
- out << "StDefine";
- else if (st == Row::StPrepare)
- out << "StPrepare";
- else if (st == Row::StCommit)
- out << "StCommit";
- else
- out << "st=" << st;
- return out;
-}
-
-static NdbOut&
-operator<<(NdbOut& out, const Row::Op op)
-{
- if (op == Row::OpNone)
- out << "OpNone";
- else if (op == Row::OpIns)
- out << "OpIns";
- else if (op == Row::OpUpd)
- out << "OpUpd";
- else if (op == Row::OpDel)
- out << "OpDel";
- else if (op == Row::OpRead)
- out << "OpRead";
- else if (op == Row::OpReadEx)
- out << "OpReadEx";
- else if (op == Row::OpReadCom)
- out << "OpReadCom";
- else
- out << "op=" << op;
- return out;
-}
-
-static NdbOut&
-operator<<(NdbOut& out, const Row* rowp)
-{
- if (rowp == 0)
- out << "[null]";
- else
- out << *rowp;
- return out;
-}
-
-static NdbOut&
-operator<<(NdbOut& out, const Row& row)
-{
- const Tab& tab = row.m_tab;
- out << "[";
- for (uint i = 0; i < tab.m_cols; i++) {
- if (i > 0)
- out << " ";
- out << *row.m_val[i];
- }
- out << " " << row.m_st;
- out << " " << row.m_op;
- out << " " << HEX(row.m_txid);
- if (row.m_bi != 0)
- out << " " << row.m_bi;
- out << "]";
- return out;
-}
-
-// Set - set of table tuples
-
-struct Set {
- const Tab& m_tab;
- uint m_rows;
- Row** m_row;
- uint* m_rowkey; // maps row number (from 0) in scan to tuple key
- Row* m_keyrow;
- NdbRecAttr** m_rec;
- // construct
- Set(const Tab& tab, uint rows);
- ~Set();
- void reset();
- bool compat(Par par, uint i, const Row::Op op) const;
- void push(uint i);
- void copyval(uint i, uint colmask = ~0); // from bi
- void calc(Par par, uint i, uint colmask = ~0);
- uint count() const;
- const Row* getrow(uint i, bool dirty = false) const;
- // transaction
- void post(Par par, ExecType et);
- // operations
- int insrow(Par par, uint i);
- int updrow(Par par, uint i);
- int updrow(Par par, const ITab& itab, uint i);
- int delrow(Par par, uint i);
- int delrow(Par par, const ITab& itab, uint i);
- int selrow(Par par, const Row& keyrow);
- int selrow(Par par, const ITab& itab, const Row& keyrow);
- int setrow(Par par, uint i);
- int getval(Par par);
- int getkey(Par par, uint* i);
- int putval(uint i, bool force, uint n = ~0);
- // compare
- void sort(Par par, const ITab& itab);
- int verify(Par par, const Set& set2, bool pkonly, bool dirty = false) const;
- int verifyorder(Par par, const ITab& itab, bool descending) const;
- // protect structure
- NdbMutex* m_mutex;
- void lock() const {
- NdbMutex_Lock(m_mutex);
- }
- void unlock() const {
- NdbMutex_Unlock(m_mutex);
- }
-private:
- void sort(Par par, const ITab& itab, uint lo, uint hi);
- Set& operator=(const Set& set2);
-};
-
-// construct
-
-Set::Set(const Tab& tab, uint rows) :
- m_tab(tab)
-{
- m_rows = rows;
- m_row = new Row* [m_rows];
- for (uint i = 0; i < m_rows; i++) {
- m_row[i] = 0;
- }
- m_rowkey = new uint [m_rows];
- for (uint n = 0; n < m_rows; n++) {
- m_rowkey[n] = ~0;
- }
- m_keyrow = new Row(tab);
- m_rec = new NdbRecAttr* [tab.m_cols];
- for (uint k = 0; k < tab.m_cols; k++) {
- m_rec[k] = 0;
- }
- m_mutex = NdbMutex_Create();
- assert(m_mutex != 0);
-}
-
-Set::~Set()
-{
- for (uint i = 0; i < m_rows; i++) {
- delete m_row[i];
- }
- delete [] m_row;
- delete [] m_rowkey;
- delete m_keyrow;
- delete [] m_rec;
- NdbMutex_Destroy(m_mutex);
-}
-
-void
-Set::reset()
-{
- for (uint i = 0; i < m_rows; i++) {
- m_row[i] = 0;
- }
-}
-
-// this sucks
-bool
-Set::compat(Par par, uint i, const Row::Op op) const
-{
- Con& con = par.con();
- int ret = -1;
- int place = 0;
- do {
- const Row* rowp = getrow(i);
- if (rowp == 0) {
- ret = op == Row::OpIns;
- place = 1;
- break;
- }
- const Row& row = *rowp;
- if (!(op & Row::OpREAD)) {
- if (row.m_st == Row::StDefine || row.m_st == Row::StPrepare) {
- assert(row.m_op & Row::OpDML);
- assert(row.m_txid != 0);
- if (con.m_txid != row.m_txid) {
- ret = false;
- place = 2;
- break;
- }
- if (row.m_op != Row::OpDel) {
- ret = op == Row::OpUpd || op == Row::OpDel;
- place = 3;
- break;
- }
- ret = op == Row::OpIns;
- place = 4;
- break;
- }
- if (row.m_st == Row::StCommit) {
- assert(row.m_op == Row::OpNone);
- assert(row.m_txid == 0);
- ret = op == Row::OpUpd || op == Row::OpDel;
- place = 5;
- break;
- }
- }
- if (op & Row::OpREAD) {
- bool dirty =
- con.m_txid != row.m_txid &&
- par.m_lockmode == NdbOperation::LM_CommittedRead;
- const Row* rowp2 = getrow(i, dirty);
- if (rowp2 == 0 || rowp2->m_op == Row::OpDel) {
- ret = false;
- place = 6;
- break;
- }
- ret = true;
- place = 7;
- break;
- }
- } while (0);
- LL4("compat ret=" << ret << " place=" << place);
- assert(ret == false || ret == true);
- return ret;
-}
-
-void
-Set::push(uint i)
-{
- const Tab& tab = m_tab;
- assert(i < m_rows);
- Row* bi = m_row[i];
- m_row[i] = new Row(tab);
- Row& row = *m_row[i];
- row.m_bi = bi;
- if (bi != 0)
- row.copyval(*bi);
-}
-
-void
-Set::copyval(uint i, uint colmask)
-{
- assert(m_row[i] != 0);
- Row& row = *m_row[i];
- assert(row.m_bi != 0);
- row.copyval(*row.m_bi, colmask);
-}
-
-void
-Set::calc(Par par, uint i, uint colmask)
-{
- assert(m_row[i] != 0);
- Row& row = *m_row[i];
- row.calc(par, i, colmask);
-}
-
-uint
-Set::count() const
-{
- uint count = 0;
- for (uint i = 0; i < m_rows; i++) {
- if (m_row[i] != 0)
- count++;
- }
- return count;
-}
-
-const Row*
-Set::getrow(uint i, bool dirty) const
-{
- assert(i < m_rows);
- const Row* rowp = m_row[i];
- if (dirty) {
- while (rowp != 0) {
- bool b1 = rowp->m_op == Row::OpNone;
- bool b2 = rowp->m_st == Row::StCommit;
- assert(b1 == b2);
- if (b1) {
- assert(rowp->m_bi == 0);
- break;
- }
- rowp = rowp->m_bi;
- }
- }
- return rowp;
-}
-
-// transaction
-
-void
-Set::post(Par par, ExecType et)
-{
- LL4("post");
- Con& con = par.con();
- assert(con.m_txid != 0);
- uint i;
- for (i = 0; i < m_rows; i++) {
- Row* rowp = m_row[i];
- if (rowp == 0) {
- LL5("skip " << i << " " << rowp);
- continue;
- }
- if (rowp->m_st == Row::StCommit) {
- assert(rowp->m_op == Row::OpNone);
- assert(rowp->m_txid == 0);
- assert(rowp->m_bi == 0);
- LL5("skip committed " << i << " " << rowp);
- continue;
- }
- assert(rowp->m_st == Row::StDefine || rowp->m_st == Row::StPrepare);
- assert(rowp->m_txid != 0);
- if (con.m_txid != rowp->m_txid) {
- LL5("skip txid " << i << " " << HEX(con.m_txid) << " " << rowp);
- continue;
- }
- // TODO read ops
- assert(rowp->m_op & Row::OpDML);
- LL4("post BEFORE " << rowp);
- if (et == NoCommit) {
- if (rowp->m_st == Row::StDefine) {
- rowp->m_st = Row::StPrepare;
- Row* bi = rowp->m_bi;
- while (bi != 0 && bi->m_st == Row::StDefine) {
- bi->m_st = Row::StPrepare;
- bi = bi->m_bi;
- }
- }
- } else if (et == Commit) {
- if (rowp->m_op != Row::OpDel) {
- rowp->m_st = Row::StCommit;
- rowp->m_op = Row::OpNone;
- rowp->m_txid = 0;
- delete rowp->m_bi;
- rowp->m_bi = 0;
- } else {
- delete rowp;
- rowp = 0;
- }
- } else if (et == Rollback) {
- while (rowp != 0 && rowp->m_st != Row::StCommit) {
- Row* tmp = rowp;
- rowp = rowp->m_bi;
- tmp->m_bi = 0;
- delete tmp;
- }
- } else {
- assert(false);
- }
- m_row[i] = rowp;
- LL4("post AFTER " << rowp);
- }
-}
-
-// operations
-
-int
-Set::insrow(Par par, uint i)
-{
- assert(m_row[i] != 0);
- Row& row = *m_row[i];
- CHK(row.insrow(par) == 0);
- return 0;
-}
-
-int
-Set::updrow(Par par, uint i)
-{
- assert(m_row[i] != 0);
- Row& row = *m_row[i];
- CHK(row.updrow(par) == 0);
- return 0;
-}
-
-int
-Set::updrow(Par par, const ITab& itab, uint i)
-{
- assert(m_row[i] != 0);
- Row& row = *m_row[i];
- CHK(row.updrow(par, itab) == 0);
- return 0;
-}
-
-int
-Set::delrow(Par par, uint i)
-{
- assert(m_row[i] != 0);
- Row& row = *m_row[i];
- CHK(row.delrow(par) == 0);
- return 0;
-}
-
-int
-Set::delrow(Par par, const ITab& itab, uint i)
-{
- assert(m_row[i] != 0);
- Row& row = *m_row[i];
- CHK(row.delrow(par, itab) == 0);
- return 0;
-}
-
-int
-Set::selrow(Par par, const Row& keyrow)
-{
- Con& con = par.con();
- const Tab& tab = par.tab();
- LL5("selrow " << tab.m_name << " keyrow " << keyrow);
- m_keyrow->copyval(keyrow, tab.m_pkmask);
- CHK(m_keyrow->selrow(par) == 0);
- CHK(getval(par) == 0);
- return 0;
-}
-
-int
-Set::selrow(Par par, const ITab& itab, const Row& keyrow)
-{
- Con& con = par.con();
- LL5("selrow " << itab.m_name << " keyrow " << keyrow);
- m_keyrow->copyval(keyrow, itab.m_keymask);
- CHK(m_keyrow->selrow(par, itab) == 0);
- CHK(getval(par) == 0);
- return 0;
-}
-
-int
-Set::setrow(Par par, uint i)
-{
- Con& con = par.con();
- assert(m_row[i] != 0);
- CHK(m_row[i]->setrow(par) == 0);
- return 0;
-}
-
-int
-Set::getval(Par par)
-{
- Con& con = par.con();
- const Tab& tab = m_tab;
- Rsq rsq1(tab.m_cols);
- for (uint k = 0; k < tab.m_cols; k++) {
- uint k2 = rsq1.next();
- CHK(con.getValue(k2, m_rec[k2]) == 0);
- }
- return 0;
-}
-
-int
-Set::getkey(Par par, uint* i)
-{
- const Tab& tab = m_tab;
- uint k = tab.m_keycol;
- assert(m_rec[k] != 0);
- const char* aRef = m_rec[k]->aRef();
- Uint32 key = *(const Uint32*)aRef;
- LL5("getkey: " << key);
- CHK(key < m_rows);
- *i = key;
- return 0;
-}
-
-int
-Set::putval(uint i, bool force, uint n)
-{
- const Tab& tab = m_tab;
- LL4("putval key=" << i << " row=" << n << " old=" << m_row[i]);
- if (m_row[i] != 0) {
- assert(force);
- delete m_row[i];
- m_row[i] = 0;
- }
- m_row[i] = new Row(tab);
- Row& row = *m_row[i];
- for (uint k = 0; k < tab.m_cols; k++) {
- Val& val = *row.m_val[k];
- NdbRecAttr* rec = m_rec[k];
- assert(rec != 0);
- if (rec->isNULL()) {
- val.m_null = true;
- continue;
- }
- const char* aRef = m_rec[k]->aRef();
- val.copy(aRef);
- val.m_null = false;
- }
- if (n != ~0)
- m_rowkey[n] = i;
- return 0;
-}
-
-// compare
-
-void
-Set::sort(Par par, const ITab& itab)
-{
- if (m_rows != 0)
- sort(par, itab, 0, m_rows - 1);
-}
-
-void
-Set::sort(Par par, const ITab& itab, uint lo, uint hi)
-{
- assert(lo < m_rows && hi < m_rows && lo <= hi);
- Row* const p = m_row[lo];
- uint i = lo;
- uint j = hi;
- while (i < j) {
- while (i < j && m_row[j]->cmp(par, *p, itab) >= 0)
- j--;
- if (i < j) {
- m_row[i] = m_row[j];
- i++;
- }
- while (i < j && m_row[i]->cmp(par, *p, itab) <= 0)
- i++;
- if (i < j) {
- m_row[j] = m_row[i];
- j--;
- }
- }
- m_row[i] = p;
- if (lo < i)
- sort(par, itab, lo, i - 1);
- if (hi > i)
- sort(par, itab, i + 1, hi);
-}
-
-/*
- * set1 (self) is from dml and can contain un-committed operations.
- * set2 is from read and contains no operations. "dirty" applies
- * to set1: false = use latest row, true = use committed row.
- */
-int
-Set::verify(Par par, const Set& set2, bool pkonly, bool dirty) const
-{
- const Set& set1 = *this;
- assert(&set1.m_tab == &set2.m_tab && set1.m_rows == set2.m_rows);
- LL3("verify dirty:" << dirty);
- for (uint i = 0; i < set1.m_rows; i++) {
- // the row versions we actually compare
- const Row* row1p = set1.getrow(i, dirty);
- const Row* row2p = set2.getrow(i);
- bool ok = true;
- int place = 0;
- if (row1p == 0) {
- if (row2p != 0) {
- ok = false;
- place = 1;
- }
- } else {
- Row::Op op1 = row1p->m_op;
- if (op1 != Row::OpDel) {
- if (row2p == 0) {
- ok = false;
- place = 2;
- } else if (row1p->verify(par, *row2p, pkonly) == -1) {
- ok = false;
- place = 3;
- }
- } else if (row2p != 0) {
- ok = false;
- place = 4;
- }
- }
- if (!ok) {
- LL1("verify " << i << " failed at " << place);
- LL1("row1 " << row1p);
- LL1("row2 " << row2p);
- CHK(false);
- }
- }
- return 0;
-}
-
-int
-Set::verifyorder(Par par, const ITab& itab, bool descending) const
-{
- const Tab& tab = m_tab;
- for (uint n = 0; n < m_rows; n++) {
- uint i2 = m_rowkey[n];
- if (i2 == ~0)
- break;
- if (n == 0)
- continue;
- uint i1 = m_rowkey[n - 1];
- assert(m_row[i1] != 0 && m_row[i2] != 0);
- const Row& row1 = *m_row[i1];
- const Row& row2 = *m_row[i2];
- if (!descending)
- CHK(row1.cmp(par, row2, itab) <= 0);
- else
- CHK(row1.cmp(par, row2, itab) >= 0);
- }
- return 0;
-}
-
-// print
-
-static NdbOut&
-operator<<(NdbOut& out, const Set& set)
-{
- for (uint i = 0; i < set.m_rows; i++) {
- const Row& row = *set.m_row[i];
- if (i > 0)
- out << endl;
- out << row;
- }
- return out;
-}
-
-// BVal - range scan bound
-
-struct BVal : public Val {
- const ICol& m_icol;
- int m_type;
- BVal(const ICol& icol);
- int setbnd(Par par) const;
- int setflt(Par par) const;
-};
-
-BVal::BVal(const ICol& icol) :
- Val(icol.m_col),
- m_icol(icol)
-{
-}
-
-int
-BVal::setbnd(Par par) const
-{
- Con& con = par.con();
- assert(g_compare_null || !m_null);
- const char* addr = !m_null ? (const char*)dataaddr() : 0;
- const ICol& icol = m_icol;
- CHK(con.setBound(icol.m_num, m_type, addr) == 0);
- return 0;
-}
-
-int
-BVal::setflt(Par par) const
-{
- static uint index_bound_to_filter_bound[5] = {
- NdbScanFilter::COND_GE,
- NdbScanFilter::COND_GT,
- NdbScanFilter::COND_LE,
- NdbScanFilter::COND_LT,
- NdbScanFilter::COND_EQ
- };
- Con& con = par.con();
- assert(g_compare_null || !m_null);
- const char* addr = !m_null ? (const char*)dataaddr() : 0;
- const ICol& icol = m_icol;
- const Col& col = icol.m_col;
- uint length = col.m_bytesize;
- uint cond = index_bound_to_filter_bound[m_type];
- CHK(con.setFilter(col.m_num, cond, addr, length) == 0);
- return 0;
-}
-
-static NdbOut&
-operator<<(NdbOut& out, const BVal& bval)
-{
- const ICol& icol = bval.m_icol;
- const Col& col = icol.m_col;
- const Val& val = bval;
- out << "type=" << bval.m_type;
- out << " icol=" << icol.m_num;
- out << " col=" << col.m_num << "," << col.m_name;
- out << " value=" << val;
- return out;
-}
-
-// BSet - set of bounds
-
-struct BSet {
- const Tab& m_tab;
- const ITab& m_itab;
- uint m_alloc;
- uint m_bvals;
- BVal** m_bval;
- BSet(const Tab& tab, const ITab& itab);
- ~BSet();
- void reset();
- void calc(Par par);
- void calcpk(Par par, uint i);
- int setbnd(Par par) const;
- int setflt(Par par) const;
- void filter(Par par, const Set& set, Set& set2) const;
-};
-
-BSet::BSet(const Tab& tab, const ITab& itab) :
- m_tab(tab),
- m_itab(itab),
- m_alloc(2 * itab.m_icols),
- m_bvals(0)
-{
- m_bval = new BVal* [m_alloc];
- for (uint i = 0; i < m_alloc; i++) {
- m_bval[i] = 0;
- }
-}
-
-BSet::~BSet()
-{
- delete [] m_bval;
-}
-
-void
-BSet::reset()
-{
- while (m_bvals > 0) {
- uint i = --m_bvals;
- delete m_bval[i];
- m_bval[i] = 0;
- }
-}
-
-void
-BSet::calc(Par par)
-{
- const ITab& itab = m_itab;
- par.m_pctrange = par.m_pctbrange;
- reset();
- for (uint k = 0; k < itab.m_icols; k++) {
- const ICol& icol = *itab.m_icol[k];
- const Col& col = icol.m_col;
- for (uint i = 0; i <= 1; i++) {
- if (m_bvals == 0 && urandom(100) == 0)
- return;
- if (m_bvals != 0 && urandom(3) == 0)
- return;
- assert(m_bvals < m_alloc);
- BVal& bval = *new BVal(icol);
- m_bval[m_bvals++] = &bval;
- bval.m_null = false;
- uint sel;
- do {
- // equality bound only on i==0
- sel = urandom(5 - i);
- } while (strchr(par.m_bound, '0' + sel) == 0);
- if (sel < 2)
- bval.m_type = 0 | (1 << i);
- else if (sel < 4)
- bval.m_type = 1 | (1 << i);
- else
- bval.m_type = 4;
- if (k + 1 < itab.m_icols)
- bval.m_type = 4;
- if (!g_compare_null)
- par.m_pctnull = 0;
- if (bval.m_type == 0 || bval.m_type == 1)
- par.m_bdir = -1;
- if (bval.m_type == 2 || bval.m_type == 3)
- par.m_bdir = +1;
- do {
- bval.calcnokey(par);
- if (i == 1) {
- assert(m_bvals >= 2);
- const BVal& bv1 = *m_bval[m_bvals - 2];
- const BVal& bv2 = *m_bval[m_bvals - 1];
- if (bv1.cmp(par, bv2) > 0 && urandom(100) != 0)
- continue;
- }
- } while (0);
- // equality bound only once
- if (bval.m_type == 4)
- break;
- }
- }
-}
-
-void
-BSet::calcpk(Par par, uint i)
-{
- const ITab& itab = m_itab;
- reset();
- for (uint k = 0; k < itab.m_icols; k++) {
- const ICol& icol = *itab.m_icol[k];
- const Col& col = icol.m_col;
- assert(col.m_pk);
- assert(m_bvals < m_alloc);
- BVal& bval = *new BVal(icol);
- m_bval[m_bvals++] = &bval;
- bval.m_type = 4;
- bval.calc(par, i);
- }
-}
-
-int
-BSet::setbnd(Par par) const
-{
- if (m_bvals != 0) {
- Rsq rsq1(m_bvals);
- for (uint j = 0; j < m_bvals; j++) {
- uint j2 = rsq1.next();
- const BVal& bval = *m_bval[j2];
- CHK(bval.setbnd(par) == 0);
- }
- // duplicate
- if (urandom(5) == 0) {
- uint j3 = urandom(m_bvals);
- const BVal& bval = *m_bval[j3];
- CHK(bval.setbnd(par) == 0);
- }
- }
- return 0;
-}
-
-int
-BSet::setflt(Par par) const
-{
- Con& con = par.con();
- CHK(con.getNdbScanFilter() == 0);
- CHK(con.beginFilter(NdbScanFilter::AND) == 0);
- if (m_bvals != 0) {
- Rsq rsq1(m_bvals);
- for (uint j = 0; j < m_bvals; j++) {
- uint j2 = rsq1.next();
- const BVal& bval = *m_bval[j2];
- CHK(bval.setflt(par) == 0);
- }
- // duplicate
- if (urandom(5) == 0) {
- uint j3 = urandom(m_bvals);
- const BVal& bval = *m_bval[j3];
- CHK(bval.setflt(par) == 0);
- }
- }
- CHK(con.endFilter() == 0);
- return 0;
-}
-
-void
-BSet::filter(Par par, const Set& set, Set& set2) const
-{
- const Tab& tab = m_tab;
- const ITab& itab = m_itab;
- assert(&tab == &set2.m_tab && set.m_rows == set2.m_rows);
- assert(set2.count() == 0);
- for (uint i = 0; i < set.m_rows; i++) {
- set.lock();
- do {
- if (set.m_row[i] == 0) {
- break;
- }
- const Row& row = *set.m_row[i];
- if (!g_store_null_key) {
- bool ok1 = false;
- for (uint k = 0; k < itab.m_icols; k++) {
- const ICol& icol = *itab.m_icol[k];
- const Col& col = icol.m_col;
- const Val& val = *row.m_val[col.m_num];
- if (!val.m_null) {
- ok1 = true;
- break;
- }
- }
- if (!ok1)
- break;
- }
- bool ok2 = true;
- for (uint j = 0; j < m_bvals; j++) {
- const BVal& bval = *m_bval[j];
- const ICol& icol = bval.m_icol;
- const Col& col = icol.m_col;
- const Val& val = *row.m_val[col.m_num];
- int ret = bval.cmp(par, val);
- LL5("cmp: ret=" << ret << " " << bval << " vs " << val);
- if (bval.m_type == 0)
- ok2 = (ret <= 0);
- else if (bval.m_type == 1)
- ok2 = (ret < 0);
- else if (bval.m_type == 2)
- ok2 = (ret >= 0);
- else if (bval.m_type == 3)
- ok2 = (ret > 0);
- else if (bval.m_type == 4)
- ok2 = (ret == 0);
- else {
- assert(false);
- }
- if (!ok2)
- break;
- }
- if (!ok2)
- break;
- assert(set2.m_row[i] == 0);
- set2.m_row[i] = new Row(tab);
- Row& row2 = *set2.m_row[i];
- row2.copy(row, true);
- } while (0);
- set.unlock();
- }
-}
-
-static NdbOut&
-operator<<(NdbOut& out, const BSet& bset)
-{
- out << "bounds=" << bset.m_bvals;
- for (uint j = 0; j < bset.m_bvals; j++) {
- const BVal& bval = *bset.m_bval[j];
- out << " [bound " << j << ": " << bval << "]";
- }
- return out;
-}
-
-// pk operations
-
-static int
-pkinsert(Par par)
-{
- Con& con = par.con();
- const Tab& tab = par.tab();
- Set& set = par.set();
- LL3("pkinsert " << tab.m_name);
- CHK(con.startTransaction() == 0);
- uint batch = 0;
- for (uint j = 0; j < par.m_rows; j++) {
- uint j2 = !par.m_randomkey ? j : urandom(par.m_rows);
- uint i = thrrow(par, j2);
- set.lock();
- if (!set.compat(par, i, Row::OpIns)) {
- LL3("pkinsert SKIP " << i << " " << set.getrow(i));
- set.unlock();
- } else {
- set.push(i);
- set.calc(par, i);
- CHK(set.insrow(par, i) == 0);
- set.unlock();
- LL4("pkinsert key=" << i << " " << set.getrow(i));
- batch++;
- }
- bool lastbatch = (batch != 0 && j + 1 == par.m_rows);
- if (batch == par.m_batch || lastbatch) {
- uint err = par.m_catcherr;
- ExecType et = !randompct(par.m_abortpct) ? Commit : Rollback;
- CHK(con.execute(et, err) == 0);
- set.lock();
- set.post(par, !err ? et : Rollback);
- set.unlock();
- if (err) {
- LL1("pkinsert key=" << i << " stop on " << con.errname(err));
- break;
- }
- batch = 0;
- if (!lastbatch) {
- con.closeTransaction();
- CHK(con.startTransaction() == 0);
- }
- }
- }
- con.closeTransaction();
- return 0;
-}
-
-static int
-pkupdate(Par par)
-{
- Con& con = par.con();
- const Tab& tab = par.tab();
- Set& set = par.set();
- LL3("pkupdate " << tab.m_name);
- CHK(con.startTransaction() == 0);
- uint batch = 0;
- for (uint j = 0; j < par.m_rows; j++) {
- uint j2 = !par.m_randomkey ? j : urandom(par.m_rows);
- uint i = thrrow(par, j2);
- set.lock();
- if (!set.compat(par, i, Row::OpUpd)) {
- LL3("pkupdate SKIP " << i << " " << set.getrow(i));
- set.unlock();
- } else {
- set.push(i);
- set.copyval(i, tab.m_pkmask);
- set.calc(par, i, ~tab.m_pkmask);
- CHK(set.updrow(par, i) == 0);
- set.unlock();
- LL4("pkupdate key=" << i << " " << set.getrow(i));
- batch++;
- }
- bool lastbatch = (batch != 0 && j + 1 == par.m_rows);
- if (batch == par.m_batch || lastbatch) {
- uint err = par.m_catcherr;
- ExecType et = !randompct(par.m_abortpct) ? Commit : Rollback;
- CHK(con.execute(et, err) == 0);
- set.lock();
- set.post(par, !err ? et : Rollback);
- set.unlock();
- if (err) {
- LL1("pkupdate key=" << i << ": stop on " << con.errname(err));
- break;
- }
- batch = 0;
- if (!lastbatch) {
- con.closeTransaction();
- CHK(con.startTransaction() == 0);
- }
- }
- }
- con.closeTransaction();
- return 0;
-}
-
-static int
-pkdelete(Par par)
-{
- Con& con = par.con();
- const Tab& tab = par.tab();
- Set& set = par.set();
- LL3("pkdelete " << tab.m_name);
- CHK(con.startTransaction() == 0);
- uint batch = 0;
- for (uint j = 0; j < par.m_rows; j++) {
- uint j2 = !par.m_randomkey ? j : urandom(par.m_rows);
- uint i = thrrow(par, j2);
- set.lock();
- if (!set.compat(par, i, Row::OpDel)) {
- LL3("pkdelete SKIP " << i << " " << set.getrow(i));
- set.unlock();
- } else {
- set.push(i);
- set.copyval(i, tab.m_pkmask);
- CHK(set.delrow(par, i) == 0);
- set.unlock();
- LL4("pkdelete key=" << i << " " << set.getrow(i));
- batch++;
- }
- bool lastbatch = (batch != 0 && j + 1 == par.m_rows);
- if (batch == par.m_batch || lastbatch) {
- uint err = par.m_catcherr;
- ExecType et = !randompct(par.m_abortpct) ? Commit : Rollback;
- CHK(con.execute(et, err) == 0);
- set.lock();
- set.post(par, !err ? et : Rollback);
- set.unlock();
- if (err) {
- LL1("pkdelete key=" << i << " stop on " << con.errname(err));
- break;
- }
- batch = 0;
- if (!lastbatch) {
- con.closeTransaction();
- CHK(con.startTransaction() == 0);
- }
- }
- }
- con.closeTransaction();
- return 0;
-}
-
-static int
-pkread(Par par)
-{
- Con& con = par.con();
- const Tab& tab = par.tab();
- Set& set = par.set();
- LL3("pkread " << tab.m_name << " verify=" << par.m_verify);
- // expected
- const Set& set1 = set;
- Set set2(tab, set.m_rows);
- for (uint i = 0; i < set.m_rows; i++) {
- set.lock();
- // TODO lock mode
- if (!set.compat(par, i, Row::OpREAD)) {
- LL3("pkread SKIP " << i << " " << set.getrow(i));
- set.unlock();
- continue;
- }
- set.unlock();
- CHK(con.startTransaction() == 0);
- CHK(set2.selrow(par, *set1.m_row[i]) == 0);
- CHK(con.execute(Commit) == 0);
- uint i2 = (uint)-1;
- CHK(set2.getkey(par, &i2) == 0 && i == i2);
- CHK(set2.putval(i, false) == 0);
- LL4("row " << set2.count() << " " << set2.getrow(i));
- con.closeTransaction();
- }
- if (par.m_verify)
- CHK(set1.verify(par, set2, false) == 0);
- return 0;
-}
-
-static int
-pkreadfast(Par par, uint count)
-{
- Con& con = par.con();
- const Tab& tab = par.tab();
- const Set& set = par.set();
- LL3("pkfast " << tab.m_name);
- Row keyrow(tab);
- // not batched on purpose
- for (uint j = 0; j < count; j++) {
- uint i = urandom(set.m_rows);
- assert(set.compat(par, i, Row::OpREAD));
- CHK(con.startTransaction() == 0);
- // define key
- keyrow.calc(par, i);
- CHK(keyrow.selrow(par) == 0);
- NdbRecAttr* rec;
- // get 1st column
- CHK(con.getValue((Uint32)0, rec) == 0);
- CHK(con.execute(Commit) == 0);
- con.closeTransaction();
- }
- return 0;
-}
-
-// hash index operations
-
-static int
-hashindexupdate(Par par, const ITab& itab)
-{
- Con& con = par.con();
- const Tab& tab = par.tab();
- Set& set = par.set();
- LL3("hashindexupdate " << itab.m_name);
- CHK(con.startTransaction() == 0);
- uint batch = 0;
- for (uint j = 0; j < par.m_rows; j++) {
- uint j2 = !par.m_randomkey ? j : urandom(par.m_rows);
- uint i = thrrow(par, j2);
- set.lock();
- if (!set.compat(par, i, Row::OpUpd)) {
- LL3("hashindexupdate SKIP " << i << " " << set.getrow(i));
- set.unlock();
- } else {
- // table pk and index key are not updated
- set.push(i);
- uint keymask = tab.m_pkmask | itab.m_keymask;
- set.copyval(i, keymask);
- set.calc(par, i, ~keymask);
- CHK(set.updrow(par, itab, i) == 0);
- set.unlock();
- LL4("hashindexupdate " << i << " " << set.getrow(i));
- batch++;
- }
- bool lastbatch = (batch != 0 && j + 1 == par.m_rows);
- if (batch == par.m_batch || lastbatch) {
- uint err = par.m_catcherr;
- ExecType et = !randompct(par.m_abortpct) ? Commit : Rollback;
- CHK(con.execute(et, err) == 0);
- set.lock();
- set.post(par, !err ? et : Rollback);
- set.unlock();
- if (err) {
- LL1("hashindexupdate " << i << " stop on " << con.errname(err));
- break;
- }
- batch = 0;
- if (!lastbatch) {
- con.closeTransaction();
- CHK(con.startTransaction() == 0);
- }
- }
- }
- con.closeTransaction();
- return 0;
-}
-
-static int
-hashindexdelete(Par par, const ITab& itab)
-{
- Con& con = par.con();
- Set& set = par.set();
- LL3("hashindexdelete " << itab.m_name);
- CHK(con.startTransaction() == 0);
- uint batch = 0;
- for (uint j = 0; j < par.m_rows; j++) {
- uint j2 = !par.m_randomkey ? j : urandom(par.m_rows);
- uint i = thrrow(par, j2);
- set.lock();
- if (!set.compat(par, i, Row::OpDel)) {
- LL3("hashindexdelete SKIP " << i << " " << set.getrow(i));
- set.unlock();
- } else {
- set.push(i);
- set.copyval(i, itab.m_keymask);
- CHK(set.delrow(par, itab, i) == 0);
- set.unlock();
- LL4("hashindexdelete " << i << " " << set.getrow(i));
- batch++;
- }
- bool lastbatch = (batch != 0 && j + 1 == par.m_rows);
- if (batch == par.m_batch || lastbatch) {
- uint err = par.m_catcherr;
- ExecType et = !randompct(par.m_abortpct) ? Commit : Rollback;
- CHK(con.execute(et, err) == 0);
- set.lock();
- set.post(par, !err ? et : Rollback);
- set.unlock();
- if (err) {
- LL1("hashindexdelete " << i << " stop on " << con.errname(err));
- break;
- }
- batch = 0;
- if (!lastbatch) {
- con.closeTransaction();
- CHK(con.startTransaction() == 0);
- }
- }
- }
- con.closeTransaction();
- return 0;
-}
-
-static int
-hashindexread(Par par, const ITab& itab)
-{
- Con& con = par.con();
- const Tab& tab = par.tab();
- Set& set = par.set();
- LL3("hashindexread " << itab.m_name << " verify=" << par.m_verify);
- // expected
- const Set& set1 = set;
- Set set2(tab, set.m_rows);
- for (uint i = 0; i < set.m_rows; i++) {
- set.lock();
- // TODO lock mode
- if (!set.compat(par, i, Row::OpREAD)) {
- LL3("hashindexread SKIP " << i << " " << set.getrow(i));
- set.unlock();
- continue;
- }
- set.unlock();
- CHK(con.startTransaction() == 0);
- CHK(set2.selrow(par, itab, *set1.m_row[i]) == 0);
- CHK(con.execute(Commit) == 0);
- uint i2 = (uint)-1;
- CHK(set2.getkey(par, &i2) == 0 && i == i2);
- CHK(set2.putval(i, false) == 0);
- LL4("row " << set2.count() << " " << *set2.m_row[i]);
- con.closeTransaction();
- }
- if (par.m_verify)
- CHK(set1.verify(par, set2, false) == 0);
- return 0;
-}
-
-// scan read
-
-static int
-scanreadtable(Par par)
-{
- Con& con = par.con();
- const Tab& tab = par.tab();
- const Set& set = par.set();
- // expected
- const Set& set1 = set;
- LL3("scanreadtable " << tab.m_name << " lockmode=" << par.m_lockmode << " tupscan=" << par.m_tupscan << " expect=" << set1.count() << " verify=" << par.m_verify);
- Set set2(tab, set.m_rows);
- CHK(con.startTransaction() == 0);
- CHK(con.getNdbScanOperation(tab) == 0);
- CHK(con.readTuples(par) == 0);
- set2.getval(par);
- CHK(con.executeScan() == 0);
- uint n = 0;
- while (1) {
- int ret;
- uint err = par.m_catcherr;
- CHK((ret = con.nextScanResult(true, err)) == 0 || ret == 1);
- if (ret == 1)
- break;
- if (err) {
- LL1("scanreadtable stop on " << con.errname(err));
- break;
- }
- uint i = (uint)-1;
- CHK(set2.getkey(par, &i) == 0);
- CHK(set2.putval(i, false, n) == 0);
- LL4("row " << n << " " << *set2.m_row[i]);
- n++;
- }
- con.closeTransaction();
- if (par.m_verify)
- CHK(set1.verify(par, set2, false) == 0);
- LL3("scanreadtable " << tab.m_name << " done rows=" << n);
- return 0;
-}
-
-static int
-scanreadtablefast(Par par, uint countcheck)
-{
- Con& con = par.con();
- const Tab& tab = par.tab();
- const Set& set = par.set();
- LL3("scanfast " << tab.m_name);
- CHK(con.startTransaction() == 0);
- CHK(con.getNdbScanOperation(tab) == 0);
- CHK(con.readTuples(par) == 0);
- // get 1st column
- NdbRecAttr* rec;
- CHK(con.getValue((Uint32)0, rec) == 0);
- CHK(con.executeScan() == 0);
- uint count = 0;
- while (1) {
- int ret;
- CHK((ret = con.nextScanResult(true)) == 0 || ret == 1);
- if (ret == 1)
- break;
- count++;
- }
- con.closeTransaction();
- CHK(count == countcheck);
- return 0;
-}
-
-// try to get interesting bounds
-static void
-calcscanbounds(Par par, const ITab& itab, BSet& bset, const Set& set, Set& set1)
-{
- while (true) {
- bset.calc(par);
- bset.filter(par, set, set1);
- uint n = set1.count();
- // prefer proper subset
- if (0 < n && n < set.m_rows)
- break;
- if (urandom(5) == 0)
- break;
- set1.reset();
- }
-}
-
-static int
-scanreadindex(Par par, const ITab& itab, BSet& bset, bool calc)
-{
- Con& con = par.con();
- const Tab& tab = par.tab();
- const Set& set = par.set();
- Set set1(tab, set.m_rows);
- if (calc) {
- calcscanbounds(par, itab, bset, set, set1);
- } else {
- bset.filter(par, set, set1);
- }
- LL3("scanreadindex " << itab.m_name << " " << bset << " lockmode=" << par.m_lockmode << " expect=" << set1.count() << " ordered=" << par.m_ordered << " descending=" << par.m_descending << " verify=" << par.m_verify);
- Set set2(tab, set.m_rows);
- CHK(con.startTransaction() == 0);
- CHK(con.getNdbIndexScanOperation(itab, tab) == 0);
- CHK(con.readIndexTuples(par) == 0);
- CHK(bset.setbnd(par) == 0);
- set2.getval(par);
- CHK(con.executeScan() == 0);
- uint n = 0;
- while (1) {
- int ret;
- uint err = par.m_catcherr;
- CHK((ret = con.nextScanResult(true, err)) == 0 || ret == 1);
- if (ret == 1)
- break;
- if (err) {
- LL1("scanreadindex stop on " << con.errname(err));
- break;
- }
- uint i = (uint)-1;
- CHK(set2.getkey(par, &i) == 0);
- CHK(set2.putval(i, par.m_dups, n) == 0);
- LL4("key " << i << " row " << n << " " << *set2.m_row[i]);
- n++;
- }
- con.closeTransaction();
- if (par.m_verify) {
- CHK(set1.verify(par, set2, false) == 0);
- if (par.m_ordered)
- CHK(set2.verifyorder(par, itab, par.m_descending) == 0);
- }
- LL3("scanreadindex " << itab.m_name << " done rows=" << n);
- return 0;
-}
-
-static int
-scanreadindexfast(Par par, const ITab& itab, const BSet& bset, uint countcheck)
-{
- Con& con = par.con();
- const Tab& tab = par.tab();
- const Set& set = par.set();
- LL3("scanfast " << itab.m_name << " " << bset);
- LL4(bset);
- CHK(con.startTransaction() == 0);
- CHK(con.getNdbIndexScanOperation(itab, tab) == 0);
- CHK(con.readIndexTuples(par) == 0);
- CHK(bset.setbnd(par) == 0);
- // get 1st column
- NdbRecAttr* rec;
- CHK(con.getValue((Uint32)0, rec) == 0);
- CHK(con.executeScan() == 0);
- uint count = 0;
- while (1) {
- int ret;
- CHK((ret = con.nextScanResult(true)) == 0 || ret == 1);
- if (ret == 1)
- break;
- count++;
- }
- con.closeTransaction();
- CHK(count == countcheck);
- return 0;
-}
-
-static int
-scanreadfilter(Par par, const ITab& itab, BSet& bset, bool calc)
-{
- Con& con = par.con();
- const Tab& tab = par.tab();
- const Set& set = par.set();
- Set set1(tab, set.m_rows);
- if (calc) {
- calcscanbounds(par, itab, bset, set, set1);
- } else {
- bset.filter(par, set, set1);
- }
- LL3("scanfilter " << itab.m_name << " " << bset << " lockmode=" << par.m_lockmode << " expect=" << set1.count() << " verify=" << par.m_verify);
- Set set2(tab, set.m_rows);
- CHK(con.startTransaction() == 0);
- CHK(con.getNdbScanOperation(tab) == 0);
- CHK(con.readTuples(par) == 0);
- CHK(bset.setflt(par) == 0);
- set2.getval(par);
- CHK(con.executeScan() == 0);
- uint n = 0;
- while (1) {
- int ret;
- uint err = par.m_catcherr;
- CHK((ret = con.nextScanResult(true, err)) == 0 || ret == 1);
- if (ret == 1)
- break;
- if (err) {
- LL1("scanfilter stop on " << con.errname(err));
- break;
- }
- uint i = (uint)-1;
- CHK(set2.getkey(par, &i) == 0);
- CHK(set2.putval(i, par.m_dups, n) == 0);
- LL4("key " << i << " row " << n << " " << *set2.m_row[i]);
- n++;
- }
- con.closeTransaction();
- if (par.m_verify) {
- CHK(set1.verify(par, set2, false) == 0);
- }
- LL3("scanfilter " << itab.m_name << " done rows=" << n);
- return 0;
-}
-
-static int
-scanreadindex(Par par, const ITab& itab)
-{
- const Tab& tab = par.tab();
- for (uint i = 0; i < par.m_ssloop; i++) {
- if (itab.m_type == ITab::OrderedIndex) {
- BSet bset(tab, itab);
- CHK(scanreadfilter(par, itab, bset, true) == 0);
- CHK(scanreadindex(par, itab, bset, true) == 0);
- }
- }
- return 0;
-}
-
-static int
-scanreadindex(Par par)
-{
- const Tab& tab = par.tab();
- for (uint i = 0; i < tab.m_itabs; i++) {
- if (tab.m_itab[i] == 0)
- continue;
- const ITab& itab = *tab.m_itab[i];
- if (itab.m_type == ITab::OrderedIndex) {
- CHK(scanreadindex(par, itab) == 0);
- } else {
- CHK(hashindexread(par, itab) == 0);
- }
- }
- return 0;
-}
-
-static int
-scanreadall(Par par)
-{
- CHK(scanreadtable(par) == 0);
- CHK(scanreadindex(par) == 0);
- return 0;
-}
-
-// timing scans
-
-static int
-timescantable(Par par)
-{
- par.tmr().on();
- CHK(scanreadtablefast(par, par.m_totrows) == 0);
- par.tmr().off(par.set().m_rows);
- return 0;
-}
-
-static int
-timescanpkindex(Par par)
-{
- const Tab& tab = par.tab();
- const ITab& itab = *tab.m_itab[0]; // 1st index is on PK
- BSet bset(tab, itab);
- par.tmr().on();
- CHK(scanreadindexfast(par, itab, bset, par.m_totrows) == 0);
- par.tmr().off(par.set().m_rows);
- return 0;
-}
-
-static int
-timepkreadtable(Par par)
-{
- par.tmr().on();
- uint count = par.m_samples;
- if (count == 0)
- count = par.m_totrows;
- CHK(pkreadfast(par, count) == 0);
- par.tmr().off(count);
- return 0;
-}
-
-static int
-timepkreadindex(Par par)
-{
- const Tab& tab = par.tab();
- const ITab& itab = *tab.m_itab[0]; // 1st index is on PK
- BSet bset(tab, itab);
- uint count = par.m_samples;
- if (count == 0)
- count = par.m_totrows;
- par.tmr().on();
- for (uint j = 0; j < count; j++) {
- uint i = urandom(par.m_totrows);
- bset.calcpk(par, i);
- CHK(scanreadindexfast(par, itab, bset, 1) == 0);
- }
- par.tmr().off(count);
- return 0;
-}
-
-// scan update
-
-static int
-scanupdatetable(Par par)
-{
- Con& con = par.con();
- const Tab& tab = par.tab();
- Set& set = par.set();
- LL3("scanupdatetable " << tab.m_name);
- Set set2(tab, set.m_rows);
- par.m_lockmode = NdbOperation::LM_Exclusive;
- CHK(con.startTransaction() == 0);
- CHK(con.getNdbScanOperation(tab) == 0);
- CHK(con.readTuples(par) == 0);
- set2.getval(par);
- CHK(con.executeScan() == 0);
- uint count = 0;
- // updating trans
- Con con2;
- con2.connect(con);
- CHK(con2.startTransaction() == 0);
- uint batch = 0;
- while (1) {
- int ret;
- uint32 err = par.m_catcherr;
- CHK((ret = con.nextScanResult(true, err)) != -1);
- if (ret != 0)
- break;
- if (err) {
- LL1("scanupdatetable [scan] stop on " << con.errname(err));
- break;
- }
- if (par.m_scanstop != 0 && urandom(par.m_scanstop) == 0) {
- con.closeScan();
- break;
- }
- while (1) {
- uint i = (uint)-1;
- CHK(set2.getkey(par, &i) == 0);
- set.lock();
- if (!set.compat(par, i, Row::OpUpd)) {
- LL3("scanupdatetable SKIP " << i << " " << set.getrow(i));
- } else {
- CHKTRY(set2.putval(i, false) == 0, set.unlock());
- CHKTRY(con.updateScanTuple(con2) == 0, set.unlock());
- Par par2 = par;
- par2.m_con = &con2;
- set.push(i);
- set.calc(par, i, ~tab.m_pkmask);
- CHKTRY(set.setrow(par2, i) == 0, set.unlock());
- LL4("scanupdatetable " << i << " " << set.getrow(i));
- batch++;
- }
- set.unlock();
- CHK((ret = con.nextScanResult(false)) != -1);
- bool lastbatch = (batch != 0 && ret != 0);
- if (batch == par.m_batch || lastbatch) {
- uint err = par.m_catcherr;
- ExecType et = Commit;
- CHK(con2.execute(et, err) == 0);
- set.lock();
- set.post(par, !err ? et : Rollback);
- set.unlock();
- if (err) {
- LL1("scanupdatetable [update] stop on " << con2.errname(err));
- goto out;
- }
- LL4("scanupdatetable committed batch");
- count += batch;
- batch = 0;
- con2.closeTransaction();
- CHK(con2.startTransaction() == 0);
- }
- if (ret != 0)
- break;
- }
- }
-out:
- con2.closeTransaction();
- LL3("scanupdatetable " << tab.m_name << " rows updated=" << count);
- con.closeTransaction();
- return 0;
-}
-
-static int
-scanupdateindex(Par par, const ITab& itab, BSet& bset, bool calc)
-{
- Con& con = par.con();
- const Tab& tab = par.tab();
- Set& set = par.set();
- // expected
- Set set1(tab, set.m_rows);
- if (calc) {
- calcscanbounds(par, itab, bset, set, set1);
- } else {
- bset.filter(par, set, set1);
- }
- LL3("scanupdateindex " << itab.m_name << " " << bset << " expect=" << set1.count() << " ordered=" << par.m_ordered << " descending=" << par.m_descending << " verify=" << par.m_verify);
- Set set2(tab, set.m_rows);
- par.m_lockmode = NdbOperation::LM_Exclusive;
- CHK(con.startTransaction() == 0);
- CHK(con.getNdbIndexScanOperation(itab, tab) == 0);
- CHK(con.readTuples(par) == 0);
- CHK(bset.setbnd(par) == 0);
- set2.getval(par);
- CHK(con.executeScan() == 0);
- uint count = 0;
- // updating trans
- Con con2;
- con2.connect(con);
- CHK(con2.startTransaction() == 0);
- uint batch = 0;
- while (1) {
- int ret;
- uint err = par.m_catcherr;
- CHK((ret = con.nextScanResult(true, err)) != -1);
- if (ret != 0)
- break;
- if (err) {
- LL1("scanupdateindex [scan] stop on " << con.errname(err));
- break;
- }
- if (par.m_scanstop != 0 && urandom(par.m_scanstop) == 0) {
- con.closeScan();
- break;
- }
- while (1) {
- uint i = (uint)-1;
- CHK(set2.getkey(par, &i) == 0);
- set.lock();
- if (!set.compat(par, i, Row::OpUpd)) {
- LL4("scanupdateindex SKIP " << set.getrow(i));
- } else {
- CHKTRY(set2.putval(i, par.m_dups) == 0, set.unlock());
- CHKTRY(con.updateScanTuple(con2) == 0, set.unlock());
- Par par2 = par;
- par2.m_con = &con2;
- set.push(i);
- uint colmask = !par.m_noindexkeyupdate ? ~0 : ~itab.m_keymask;
- set.calc(par, i, colmask);
- CHKTRY(set.setrow(par2, i) == 0, set.unlock());
- LL4("scanupdateindex " << i << " " << set.getrow(i));
- batch++;
- }
- set.unlock();
- CHK((ret = con.nextScanResult(false)) != -1);
- bool lastbatch = (batch != 0 && ret != 0);
- if (batch == par.m_batch || lastbatch) {
- uint err = par.m_catcherr;
- ExecType et = Commit;
- CHK(con2.execute(et, err) == 0);
- set.lock();
- set.post(par, !err ? et : Rollback);
- set.unlock();
- if (err) {
- LL1("scanupdateindex [update] stop on " << con2.errname(err));
- goto out;
- }
- LL4("scanupdateindex committed batch");
- count += batch;
- batch = 0;
- con2.closeTransaction();
- CHK(con2.startTransaction() == 0);
- }
- if (ret != 0)
- break;
- }
- }
-out:
- con2.closeTransaction();
- if (par.m_verify) {
- CHK(set1.verify(par, set2, true) == 0);
- if (par.m_ordered)
- CHK(set2.verifyorder(par, itab, par.m_descending) == 0);
- }
- LL3("scanupdateindex " << itab.m_name << " rows updated=" << count);
- con.closeTransaction();
- return 0;
-}
-
-static int
-scanupdateindex(Par par, const ITab& itab)
-{
- const Tab& tab = par.tab();
- for (uint i = 0; i < par.m_ssloop; i++) {
- if (itab.m_type == ITab::OrderedIndex) {
- BSet bset(tab, itab);
- CHK(scanupdateindex(par, itab, bset, true) == 0);
- } else {
- CHK(hashindexupdate(par, itab) == 0);
- }
- }
- return 0;
-}
-
-static int
-scanupdateindex(Par par)
-{
- const Tab& tab = par.tab();
- for (uint i = 0; i < tab.m_itabs; i++) {
- if (tab.m_itab[i] == 0)
- continue;
- const ITab& itab = *tab.m_itab[i];
- CHK(scanupdateindex(par, itab) == 0);
- }
- return 0;
-}
-
-static int
-scanupdateall(Par par)
-{
- CHK(scanupdatetable(par) == 0);
- CHK(scanupdateindex(par) == 0);
- return 0;
-}
-
-// medium level routines
-
-static int
-readverifyfull(Par par)
-{
- if (par.m_noverify)
- return 0;
- par.m_verify = true;
- if (par.m_abortpct != 0) {
- LL2("skip verify in this version"); // implement in 5.0 version
- par.m_verify = false;
- }
- par.m_lockmode = NdbOperation::LM_CommittedRead;
- const Tab& tab = par.tab();
- if (par.m_no == 0) {
- // thread 0 scans table
- CHK(scanreadtable(par) == 0);
- // once more via tup scan
- par.m_tupscan = true;
- CHK(scanreadtable(par) == 0);
- }
- // each thread scans different indexes
- for (uint i = 0; i < tab.m_itabs; i++) {
- if (i % par.m_usedthreads != par.m_no)
- continue;
- if (tab.m_itab[i] == 0)
- continue;
- const ITab& itab = *tab.m_itab[i];
- if (itab.m_type == ITab::OrderedIndex) {
- BSet bset(tab, itab);
- CHK(scanreadindex(par, itab, bset, false) == 0);
- } else {
- CHK(hashindexread(par, itab) == 0);
- }
- }
- return 0;
-}
-
-static int
-readverifyindex(Par par)
-{
- if (par.m_noverify)
- return 0;
- par.m_verify = true;
- par.m_lockmode = NdbOperation::LM_CommittedRead;
- uint sel = urandom(10);
- if (sel < 9) {
- par.m_ordered = true;
- par.m_descending = (sel < 5);
- }
- CHK(scanreadindex(par) == 0);
- return 0;
-}
-
-static int
-pkops(Par par)
-{
- const Tab& tab = par.tab();
- par.m_randomkey = true;
- for (uint i = 0; i < par.m_ssloop; i++) {
- uint j = 0;
- while (j < tab.m_itabs) {
- if (tab.m_itab[j] != 0) {
- const ITab& itab = *tab.m_itab[j];
- if (itab.m_type == ITab::UniqueHashIndex && urandom(5) == 0)
- break;
- }
- j++;
- }
- uint sel = urandom(10);
- if (par.m_slno % 2 == 0) {
- // favor insert
- if (sel < 8) {
- CHK(pkinsert(par) == 0);
- } else if (sel < 9) {
- if (j == tab.m_itabs)
- CHK(pkupdate(par) == 0);
- else {
- const ITab& itab = *tab.m_itab[j];
- CHK(hashindexupdate(par, itab) == 0);
- }
- } else {
- if (j == tab.m_itabs)
- CHK(pkdelete(par) == 0);
- else {
- const ITab& itab = *tab.m_itab[j];
- CHK(hashindexdelete(par, itab) == 0);
- }
- }
- } else {
- // favor delete
- if (sel < 1) {
- CHK(pkinsert(par) == 0);
- } else if (sel < 2) {
- if (j == tab.m_itabs)
- CHK(pkupdate(par) == 0);
- else {
- const ITab& itab = *tab.m_itab[j];
- CHK(hashindexupdate(par, itab) == 0);
- }
- } else {
- if (j == tab.m_itabs)
- CHK(pkdelete(par) == 0);
- else {
- const ITab& itab = *tab.m_itab[j];
- CHK(hashindexdelete(par, itab) == 0);
- }
- }
- }
- }
- return 0;
-}
-
-static int
-pkupdatescanread(Par par)
-{
- par.m_dups = true;
- par.m_catcherr |= Con::ErrDeadlock;
- uint sel = urandom(10);
- if (sel < 5) {
- CHK(pkupdate(par) == 0);
- } else if (sel < 6) {
- par.m_verify = false;
- CHK(scanreadtable(par) == 0);
- } else {
- par.m_verify = false;
- if (sel < 8) {
- par.m_ordered = true;
- par.m_descending = (sel < 7);
- }
- CHK(scanreadindex(par) == 0);
- }
- return 0;
-}
-
-static int
-mixedoperations(Par par)
-{
- par.m_dups = true;
- par.m_catcherr |= Con::ErrDeadlock;
- par.m_scanstop = par.m_totrows; // randomly close scans
- uint sel = urandom(10);
- if (sel < 2) {
- CHK(pkdelete(par) == 0);
- } else if (sel < 4) {
- CHK(pkupdate(par) == 0);
- } else if (sel < 6) {
- CHK(scanupdatetable(par) == 0);
- } else {
- if (sel < 8) {
- par.m_ordered = true;
- par.m_descending = (sel < 7);
- }
- CHK(scanupdateindex(par) == 0);
- }
- return 0;
-}
-
-static int
-parallelorderedupdate(Par par)
-{
- const Tab& tab = par.tab();
- uint k = 0;
- for (uint i = 0; i < tab.m_itabs; i++) {
- if (tab.m_itab[i] == 0)
- continue;
- const ITab& itab = *tab.m_itab[i];
- if (itab.m_type != ITab::OrderedIndex)
- continue;
- // cannot sync threads yet except via subloop
- if (k++ == par.m_slno % tab.m_orderedindexes) {
- LL3("parallelorderedupdate: " << itab.m_name);
- par.m_noindexkeyupdate = true;
- par.m_ordered = true;
- par.m_descending = (par.m_slno != 0);
- par.m_dups = false;
- par.m_verify = true;
- BSet bset(tab, itab); // empty bounds
- // prefer empty bounds
- uint sel = urandom(10);
- CHK(scanupdateindex(par, itab, bset, sel < 2) == 0);
- }
- }
- return 0;
-}
-
-static int
-pkupdateindexbuild(Par par)
-{
- if (par.m_no == 0) {
- CHK(createindex(par) == 0);
- } else {
- par.m_randomkey = true;
- CHK(pkupdate(par) == 0);
- }
- return 0;
-}
-
-// savepoint tests (single thread for now)
-
-struct Spt {
- enum Res { Committed, Latest, Deadlock };
- bool m_same; // same transaction
- NdbOperation::LockMode m_lm;
- Res m_res;
-};
-
-static Spt sptlist[] = {
- { 1, NdbOperation::LM_Read, Spt::Latest },
- { 1, NdbOperation::LM_Exclusive, Spt::Latest },
- { 1, NdbOperation::LM_CommittedRead, Spt::Latest },
- { 0, NdbOperation::LM_Read, Spt::Deadlock },
- { 0, NdbOperation::LM_Exclusive, Spt::Deadlock },
- { 0, NdbOperation::LM_CommittedRead, Spt::Committed }
-};
-static uint sptcount = sizeof(sptlist)/sizeof(sptlist[0]);
-
-static int
-savepointreadpk(Par par, Spt spt)
-{
- LL3("savepointreadpk");
- Con& con = par.con();
- const Tab& tab = par.tab();
- Set& set = par.set();
- const Set& set1 = set;
- Set set2(tab, set.m_rows);
- uint n = 0;
- for (uint i = 0; i < set.m_rows; i++) {
- set.lock();
- if (!set.compat(par, i, Row::OpREAD)) {
- LL4("savepointreadpk SKIP " << i << " " << set.getrow(i));
- set.unlock();
- continue;
- }
- set.unlock();
- CHK(set2.selrow(par, *set1.m_row[i]) == 0);
- uint err = par.m_catcherr | Con::ErrDeadlock;
- ExecType et = NoCommit;
- CHK(con.execute(et, err) == 0);
- if (err) {
- if (err & Con::ErrDeadlock) {
- CHK(spt.m_res == Spt::Deadlock);
- // all rows have same behaviour
- CHK(n == 0);
- }
- LL1("savepointreadpk stop on " << con.errname(err));
- break;
- }
- uint i2 = (uint)-1;
- CHK(set2.getkey(par, &i2) == 0 && i == i2);
- CHK(set2.putval(i, false) == 0);
- LL4("row " << set2.count() << " " << set2.getrow(i));
- n++;
- }
- bool dirty = (!spt.m_same && spt.m_lm == NdbOperation::LM_CommittedRead);
- if (spt.m_res != Spt::Deadlock)
- CHK(set1.verify(par, set2, false, dirty) == 0);
- return 0;
-}
-
-static int
-savepointreadhashindex(Par par, Spt spt)
-{
- if (spt.m_lm == NdbOperation::LM_CommittedRead && !spt.m_same) {
- LL1("skip hash index dirty read");
- return 0;
- }
- LL3("savepointreadhashindex");
- Con& con = par.con();
- const Tab& tab = par.tab();
- const ITab& itab = par.itab();
- Set& set = par.set();
- const Set& set1 = set;
- Set set2(tab, set.m_rows);
- uint n = 0;
- for (uint i = 0; i < set.m_rows; i++) {
- set.lock();
- if (!set.compat(par, i, Row::OpREAD)) {
- LL3("savepointreadhashindex SKIP " << i << " " << set.getrow(i));
- set.unlock();
- continue;
- }
- set.unlock();
- CHK(set2.selrow(par, itab, *set1.m_row[i]) == 0);
- uint err = par.m_catcherr | Con::ErrDeadlock;
- ExecType et = NoCommit;
- CHK(con.execute(et, err) == 0);
- if (err) {
- if (err & Con::ErrDeadlock) {
- CHK(spt.m_res == Spt::Deadlock);
- // all rows have same behaviour
- CHK(n == 0);
- }
- LL1("savepointreadhashindex stop on " << con.errname(err));
- break;
- }
- uint i2 = (uint)-1;
- CHK(set2.getkey(par, &i2) == 0 && i == i2);
- CHK(set2.putval(i, false) == 0);
- LL4("row " << set2.count() << " " << *set2.m_row[i]);
- n++;
- }
- bool dirty = (!spt.m_same && spt.m_lm == NdbOperation::LM_CommittedRead);
- if (spt.m_res != Spt::Deadlock)
- CHK(set1.verify(par, set2, false, dirty) == 0);
- return 0;
-}
-
-static int
-savepointscantable(Par par, Spt spt)
-{
- LL3("savepointscantable");
- Con& con = par.con();
- const Tab& tab = par.tab();
- const Set& set = par.set();
- const Set& set1 = set; // not modifying current set
- Set set2(tab, set.m_rows); // scan result
- CHK(con.getNdbScanOperation(tab) == 0);
- CHK(con.readTuples(par) == 0);
- set2.getval(par); // getValue all columns
- CHK(con.executeScan() == 0);
- bool deadlock = false;
- uint n = 0;
- while (1) {
- int ret;
- uint err = par.m_catcherr | Con::ErrDeadlock;
- CHK((ret = con.nextScanResult(true, err)) == 0 || ret == 1);
- if (ret == 1)
- break;
- if (err) {
- if (err & Con::ErrDeadlock) {
- CHK(spt.m_res == Spt::Deadlock);
- // all rows have same behaviour
- CHK(n == 0);
- deadlock = true;
- }
- LL1("savepointscantable stop on " << con.errname(err));
- break;
- }
- CHK(spt.m_res != Spt::Deadlock);
- uint i = (uint)-1;
- CHK(set2.getkey(par, &i) == 0);
- CHK(set2.putval(i, false, n) == 0);
- LL4("row " << n << " key " << i << " " << set2.getrow(i));
- n++;
- }
- if (set1.m_rows > 0) {
- if (!deadlock)
- CHK(spt.m_res != Spt::Deadlock);
- else
- CHK(spt.m_res == Spt::Deadlock);
- }
- LL2("savepointscantable " << n << " rows");
- bool dirty = (!spt.m_same && spt.m_lm == NdbOperation::LM_CommittedRead);
- if (spt.m_res != Spt::Deadlock)
- CHK(set1.verify(par, set2, false, dirty) == 0);
- return 0;
-}
-
-static int
-savepointscanindex(Par par, Spt spt)
-{
- LL3("savepointscanindex");
- Con& con = par.con();
- const Tab& tab = par.tab();
- const ITab& itab = par.itab();
- const Set& set = par.set();
- const Set& set1 = set;
- Set set2(tab, set.m_rows);
- CHK(con.getNdbIndexScanOperation(itab, tab) == 0);
- CHK(con.readIndexTuples(par) == 0);
- set2.getval(par);
- CHK(con.executeScan() == 0);
- bool deadlock = false;
- uint n = 0;
- while (1) {
- int ret;
- uint err = par.m_catcherr | Con::ErrDeadlock;
- CHK((ret = con.nextScanResult(true, err)) == 0 || ret == 1);
- if (ret == 1)
- break;
- if (err) {
- if (err & Con::ErrDeadlock) {
- CHK(spt.m_res == Spt::Deadlock);
- // all rows have same behaviour
- CHK(n == 0);
- deadlock = true;
- }
- LL1("savepointscanindex stop on " << con.errname(err));
- break;
- }
- CHK(spt.m_res != Spt::Deadlock);
- uint i = (uint)-1;
- CHK(set2.getkey(par, &i) == 0);
- CHK(set2.putval(i, par.m_dups, n) == 0);
- LL4("row " << n << " key " << i << " " << set2.getrow(i));
- n++;
- }
- if (set1.m_rows > 0) {
- if (!deadlock)
- CHK(spt.m_res != Spt::Deadlock);
- else
- CHK(spt.m_res == Spt::Deadlock);
- }
- LL2("savepointscanindex " << n << " rows");
- bool dirty = (!spt.m_same && spt.m_lm == NdbOperation::LM_CommittedRead);
- if (spt.m_res != Spt::Deadlock)
- CHK(set1.verify(par, set2, false, dirty) == 0);
- return 0;
-}
-
-typedef int (*SptFun)(Par, Spt);
-
-static int
-savepointtest(Par par, Spt spt, SptFun fun)
-{
- Con& con = par.con();
- Par par2 = par;
- Con con2;
- if (!spt.m_same) {
- con2.connect(con); // copy ndb reference
- par2.m_con = &con2;
- CHK(con2.startTransaction() == 0);
- }
- par2.m_lockmode = spt.m_lm;
- CHK((*fun)(par2, spt) == 0);
- if (!spt.m_same) {
- con2.closeTransaction();
- }
- return 0;
-}
-
-static int
-savepointtest(Par par, const char* op)
-{
- Con& con = par.con();
- const Tab& tab = par.tab();
- Set& set = par.set();
- LL2("savepointtest op=\"" << op << "\"");
- CHK(con.startTransaction() == 0);
- const char* p = op;
- char c;
- while ((c = *p++) != 0) {
- uint j;
- for (j = 0; j < par.m_rows; j++) {
- uint i = thrrow(par, j);
- if (c == 'c') {
- ExecType et = Commit;
- CHK(con.execute(et) == 0);
- set.lock();
- set.post(par, et);
- set.unlock();
- CHK(con.startTransaction() == 0);
- } else {
- set.lock();
- set.push(i);
- if (c == 'i') {
- set.calc(par, i);
- CHK(set.insrow(par, i) == 0);
- } else if (c == 'u') {
- set.copyval(i, tab.m_pkmask);
- set.calc(par, i, ~tab.m_pkmask);
- CHK(set.updrow(par, i) == 0);
- } else if (c == 'd') {
- set.copyval(i, tab.m_pkmask);
- CHK(set.delrow(par, i) == 0);
- } else {
- assert(false);
- }
- set.unlock();
- }
- }
- }
- {
- ExecType et = NoCommit;
- CHK(con.execute(et) == 0);
- set.lock();
- set.post(par, et);
- set.unlock();
- }
- for (uint k = 0; k < sptcount; k++) {
- Spt spt = sptlist[k];
- LL2("spt lm=" << spt.m_lm << " same=" << spt.m_same);
- CHK(savepointtest(par, spt, &savepointreadpk) == 0);
- CHK(savepointtest(par, spt, &savepointscantable) == 0);
- for (uint i = 0; i < tab.m_itabs; i++) {
- if (tab.m_itab[i] == 0)
- continue;
- const ITab& itab = *tab.m_itab[i];
- par.m_itab = &itab;
- if (itab.m_type == ITab::OrderedIndex)
- CHK(savepointtest(par, spt, &savepointscanindex) == 0);
- else
- CHK(savepointtest(par, spt, &savepointreadhashindex) == 0);
- par.m_itab = 0;
- }
- }
- {
- ExecType et = Rollback;
- CHK(con.execute(et) == 0);
- set.lock();
- set.post(par, et);
- set.unlock();
- }
- con.closeTransaction();
- return 0;
-}
-
-static int
-savepointtest(Par par)
-{
- assert(par.m_usedthreads == 1);
- const char* oplist[] = {
- // each based on previous and "c" not last
- "i",
- "icu",
- "uuuuu",
- "d",
- "dciuuuuud",
- 0
- };
- int i;
- for (i = 0; oplist[i] != 0; i++) {
- CHK(savepointtest(par, oplist[i]) == 0);
- }
- return 0;
-}
-
-static int
-halloweentest(Par par, const ITab& itab)
-{
- LL2("halloweentest " << itab.m_name);
- Con& con = par.con();
- const Tab& tab = par.tab();
- Set& set = par.set();
- CHK(con.startTransaction() == 0);
- // insert 1 row
- uint i = 0;
- set.push(i);
- set.calc(par, i);
- CHK(set.insrow(par, i) == 0);
- CHK(con.execute(NoCommit) == 0);
- // scan via index until Set m_rows reached
- uint scancount = 0;
- bool stop = false;
- while (!stop) {
- par.m_lockmode = // makes no difference
- scancount % 2 == 0 ? NdbOperation::LM_CommittedRead :
- NdbOperation::LM_Read;
- Set set1(tab, set.m_rows); // expected scan result
- Set set2(tab, set.m_rows); // actual scan result
- BSet bset(tab, itab);
- calcscanbounds(par, itab, bset, set, set1);
- CHK(con.getNdbIndexScanOperation(itab, tab) == 0);
- CHK(con.readIndexTuples(par) == 0);
- CHK(bset.setbnd(par) == 0);
- set2.getval(par);
- CHK(con.executeScan() == 0);
- const uint savepoint = i;
- LL3("scancount=" << scancount << " savepoint=" << savepoint);
- uint n = 0;
- while (1) {
- int ret;
- CHK((ret = con.nextScanResult(true)) == 0 || ret == 1);
- if (ret == 1)
- break;
- uint k = (uint)-1;
- CHK(set2.getkey(par, &k) == 0);
- CHK(set2.putval(k, false, n) == 0);
- LL3("row=" << n << " key=" << k);
- CHK(k <= savepoint);
- if (++i == set.m_rows) {
- stop = true;
- break;
- }
- set.push(i);
- set.calc(par, i);
- CHK(set.insrow(par, i) == 0);
- CHK(con.execute(NoCommit) == 0);
- n++;
- }
- con.closeScan();
- LL3("scanrows=" << n);
- if (!stop) {
- CHK(set1.verify(par, set2, false) == 0);
- }
- scancount++;
- }
- CHK(con.execute(Commit) == 0);
- set.post(par, Commit);
- assert(set.count() == set.m_rows);
- CHK(pkdelete(par) == 0);
- return 0;
-}
-
-static int
-halloweentest(Par par)
-{
- assert(par.m_usedthreads == 1);
- const Tab& tab = par.tab();
- for (uint i = 0; i < tab.m_itabs; i++) {
- if (tab.m_itab[i] == 0)
- continue;
- const ITab& itab = *tab.m_itab[i];
- if (itab.m_type == ITab::OrderedIndex)
- CHK(halloweentest(par, itab) == 0);
- }
- return 0;
-}
-
-// threads
-
-typedef int (*TFunc)(Par par);
-enum TMode { ST = 1, MT = 2 };
-
-extern "C" { static void* runthread(void* arg); }
-
-struct Thr {
- enum State { Wait, Start, Stop, Exit };
- State m_state;
- Par m_par;
- pthread_t m_id;
- NdbThread* m_thread;
- NdbMutex* m_mutex;
- NdbCondition* m_cond;
- TFunc m_func;
- int m_ret;
- void* m_status;
- char m_tmp[20]; // used for debug msg prefix
- Thr(Par par, uint n);
- ~Thr();
- int run();
- void start();
- void stop();
- void exit();
- //
- void lock() {
- NdbMutex_Lock(m_mutex);
- }
- void unlock() {
- NdbMutex_Unlock(m_mutex);
- }
- void wait() {
- NdbCondition_Wait(m_cond, m_mutex);
- }
- void signal() {
- NdbCondition_Signal(m_cond);
- }
- void join() {
- NdbThread_WaitFor(m_thread, &m_status);
- m_thread = 0;
- }
-};
-
-Thr::Thr(Par par, uint n) :
- m_state(Wait),
- m_par(par),
- m_thread(0),
- m_mutex(0),
- m_cond(0),
- m_func(0),
- m_ret(0),
- m_status(0)
-{
- m_par.m_no = n;
- char buf[10];
- sprintf(buf, "thr%03u", par.m_no);
- const char* name = strcpy(new char[10], buf);
- // mutex
- m_mutex = NdbMutex_Create();
- m_cond = NdbCondition_Create();
- assert(m_mutex != 0 && m_cond != 0);
- // run
- const uint stacksize = 256 * 1024;
- const NDB_THREAD_PRIO prio = NDB_THREAD_PRIO_LOW;
- m_thread = NdbThread_Create(runthread, (void**)this, stacksize, name, prio);
-}
-
-Thr::~Thr()
-{
- if (m_thread != 0) {
- NdbThread_Destroy(&m_thread);
- m_thread = 0;
- }
- if (m_cond != 0) {
- NdbCondition_Destroy(m_cond);
- m_cond = 0;
- }
- if (m_mutex != 0) {
- NdbMutex_Destroy(m_mutex);
- m_mutex = 0;
- }
-}
-
-static void*
-runthread(void* arg)
-{
- Thr& thr = *(Thr*)arg;
- thr.m_id = pthread_self();
- if (thr.run() < 0) {
- LL1("exit on error");
- } else {
- LL4("exit ok");
- }
- return 0;
-}
-
-int
-Thr::run()
-{
- LL4("run");
- Con con;
- CHK(con.connect() == 0);
- m_par.m_con = &con;
- LL4("connected");
- while (1) {
- lock();
- while (m_state != Start && m_state != Exit) {
- LL4("wait");
- wait();
- }
- if (m_state == Exit) {
- LL4("exit");
- unlock();
- break;
- }
- LL4("start");
- assert(m_state == Start);
- m_ret = (*m_func)(m_par);
- m_state = Stop;
- LL4("stop");
- signal();
- unlock();
- if (m_ret == -1) {
- if (m_par.m_cont)
- LL1("continue running due to -cont");
- else
- return -1;
- }
- }
- con.disconnect();
- return 0;
-}
-
-void
-Thr::start()
-{
- lock();
- m_state = Start;
- signal();
- unlock();
-}
-
-void
-Thr::stop()
-{
- lock();
- while (m_state != Stop)
- wait();
- m_state = Wait;
- unlock();
-}
-
-void
-Thr::exit()
-{
- lock();
- m_state = Exit;
- signal();
- unlock();
-}
-
-// test run
-
-static Thr** g_thrlist = 0;
-
-static Thr*
-getthr()
-{
- if (g_thrlist != 0) {
- pthread_t id = pthread_self();
- for (uint n = 0; n < g_opt.m_threads; n++) {
- if (g_thrlist[n] != 0) {
- Thr& thr = *g_thrlist[n];
- if (pthread_equal(thr.m_id, id))
- return &thr;
- }
- }
- }
- return 0;
-}
-
-// for debug messages (par.m_no not available)
-static const char*
-getthrprefix()
-{
- Thr* thrp = getthr();
- if (thrp != 0) {
- Thr& thr = *thrp;
- uint n = thr.m_par.m_no;
- uint m =
- g_opt.m_threads < 10 ? 1 :
- g_opt.m_threads < 100 ? 2 : 3;
- sprintf(thr.m_tmp, "[%0*u] ", m, n);
- return thr.m_tmp;
- }
- return "";
-}
-
-static int
-runstep(Par par, const char* fname, TFunc func, uint mode)
-{
- LL2("step: " << fname);
- const int threads = (mode & ST ? 1 : par.m_usedthreads);
- int n;
- for (n = 0; n < threads; n++) {
- LL4("start " << n);
- Thr& thr = *g_thrlist[n];
- Par oldpar = thr.m_par;
- // update parameters
- thr.m_par = par;
- thr.m_par.m_no = oldpar.m_no;
- thr.m_par.m_con = oldpar.m_con;
- thr.m_func = func;
- thr.start();
- }
- uint errs = 0;
- for (n = threads - 1; n >= 0; n--) {
- LL4("stop " << n);
- Thr& thr = *g_thrlist[n];
- thr.stop();
- if (thr.m_ret != 0)
- errs++;
- }
- CHK(errs == 0);
- return 0;
-}
-
-#define RUNSTEP(par, func, mode) \
- CHK(runstep(par, #func, func, mode) == 0)
-
-#define SUBLOOP(par) \
- "sloop: " << par.m_lno << "/" << par.m_currcase << "/" << \
- par.m_tab->m_name << "/" << par.m_slno
-
-static int
-tbuild(Par par)
-{
- RUNSTEP(par, droptable, ST);
- RUNSTEP(par, createtable, ST);
- RUNSTEP(par, invalidatetable, MT);
- for (par.m_slno = 0; par.m_slno < par.m_sloop; par.m_slno++) {
- LL1(SUBLOOP(par));
- if (par.m_slno % 3 == 0) {
- RUNSTEP(par, createindex, ST);
- RUNSTEP(par, invalidateindex, MT);
- RUNSTEP(par, pkinsert, MT);
- RUNSTEP(par, pkupdate, MT);
- } else if (par.m_slno % 3 == 1) {
- RUNSTEP(par, pkinsert, MT);
- RUNSTEP(par, createindex, ST);
- RUNSTEP(par, invalidateindex, MT);
- RUNSTEP(par, pkupdate, MT);
- } else {
- RUNSTEP(par, pkinsert, MT);
- RUNSTEP(par, pkupdate, MT);
- RUNSTEP(par, createindex, ST);
- RUNSTEP(par, invalidateindex, MT);
- }
- RUNSTEP(par, readverifyfull, MT);
- // leave last one
- if (par.m_slno + 1 < par.m_sloop) {
- RUNSTEP(par, pkdelete, MT);
- RUNSTEP(par, readverifyfull, MT);
- RUNSTEP(par, dropindex, ST);
- }
- }
- return 0;
-}
-
-static int
-tindexscan(Par par)
-{
- RUNSTEP(par, droptable, ST);
- RUNSTEP(par, createtable, ST);
- RUNSTEP(par, invalidatetable, MT);
- RUNSTEP(par, createindex, ST);
- RUNSTEP(par, invalidateindex, MT);
- RUNSTEP(par, pkinsert, MT);
- RUNSTEP(par, readverifyfull, MT);
- for (par.m_slno = 0; par.m_slno < par.m_sloop; par.m_slno++) {
- LL1(SUBLOOP(par));
- RUNSTEP(par, readverifyindex, MT);
- }
- return 0;
-}
-
-
-static int
-tpkops(Par par)
-{
- RUNSTEP(par, droptable, ST);
- RUNSTEP(par, createtable, ST);
- RUNSTEP(par, invalidatetable, MT);
- RUNSTEP(par, createindex, ST);
- RUNSTEP(par, invalidateindex, MT);
- for (par.m_slno = 0; par.m_slno < par.m_sloop; par.m_slno++) {
- LL1(SUBLOOP(par));
- RUNSTEP(par, pkops, MT);
- LL2("rows=" << par.set().count());
- RUNSTEP(par, readverifyfull, MT);
- }
- return 0;
-}
-
-static int
-tpkopsread(Par par)
-{
- RUNSTEP(par, droptable, ST);
- RUNSTEP(par, createtable, ST);
- RUNSTEP(par, invalidatetable, MT);
- RUNSTEP(par, pkinsert, MT);
- RUNSTEP(par, createindex, ST);
- RUNSTEP(par, invalidateindex, MT);
- RUNSTEP(par, readverifyfull, MT);
- for (par.m_slno = 0; par.m_slno < par.m_sloop; par.m_slno++) {
- LL1(SUBLOOP(par));
- RUNSTEP(par, pkupdatescanread, MT);
- RUNSTEP(par, readverifyfull, MT);
- }
- RUNSTEP(par, pkdelete, MT);
- RUNSTEP(par, readverifyfull, MT);
- return 0;
-}
-
-static int
-tmixedops(Par par)
-{
- RUNSTEP(par, droptable, ST);
- RUNSTEP(par, createtable, ST);
- RUNSTEP(par, invalidatetable, MT);
- RUNSTEP(par, pkinsert, MT);
- RUNSTEP(par, createindex, ST);
- RUNSTEP(par, invalidateindex, MT);
- RUNSTEP(par, readverifyfull, MT);
- for (par.m_slno = 0; par.m_slno < par.m_sloop; par.m_slno++) {
- LL1(SUBLOOP(par));
- RUNSTEP(par, mixedoperations, MT);
- RUNSTEP(par, readverifyfull, MT);
- }
- return 0;
-}
-
-static int
-tbusybuild(Par par)
-{
- RUNSTEP(par, droptable, ST);
- RUNSTEP(par, createtable, ST);
- RUNSTEP(par, invalidatetable, MT);
- RUNSTEP(par, pkinsert, MT);
- for (par.m_slno = 0; par.m_slno < par.m_sloop; par.m_slno++) {
- LL1(SUBLOOP(par));
- RUNSTEP(par, pkupdateindexbuild, MT);
- RUNSTEP(par, invalidateindex, MT);
- RUNSTEP(par, readverifyfull, MT);
- RUNSTEP(par, dropindex, ST);
- }
- return 0;
-}
-
-static int
-trollback(Par par)
-{
- par.m_abortpct = 50;
- RUNSTEP(par, droptable, ST);
- RUNSTEP(par, createtable, ST);
- RUNSTEP(par, invalidatetable, MT);
- RUNSTEP(par, pkinsert, MT);
- RUNSTEP(par, createindex, ST);
- RUNSTEP(par, invalidateindex, MT);
- RUNSTEP(par, readverifyfull, MT);
- for (par.m_slno = 0; par.m_slno < par.m_sloop; par.m_slno++) {
- LL1(SUBLOOP(par));
- RUNSTEP(par, mixedoperations, MT);
- RUNSTEP(par, readverifyfull, MT);
- }
- return 0;
-}
-
-static int
-tparupdate(Par par)
-{
- RUNSTEP(par, droptable, ST);
- RUNSTEP(par, createtable, ST);
- RUNSTEP(par, invalidatetable, MT);
- RUNSTEP(par, pkinsert, MT);
- RUNSTEP(par, createindex, ST);
- RUNSTEP(par, invalidateindex, MT);
- RUNSTEP(par, readverifyfull, MT);
- for (par.m_slno = 0; par.m_slno < par.m_sloop; par.m_slno++) {
- LL1(SUBLOOP(par));
- RUNSTEP(par, parallelorderedupdate, MT);
- RUNSTEP(par, readverifyfull, MT);
- }
- return 0;
-}
-
-static int
-tsavepoint(Par par)
-{
- RUNSTEP(par, droptable, ST);
- RUNSTEP(par, createtable, ST);
- RUNSTEP(par, invalidatetable, MT);
- RUNSTEP(par, createindex, ST);
- RUNSTEP(par, invalidateindex, MT);
- for (par.m_slno = 0; par.m_slno < par.m_sloop; par.m_slno++) {
- LL1(SUBLOOP(par));
- RUNSTEP(par, savepointtest, MT);
- RUNSTEP(par, readverifyfull, MT);
- }
- return 0;
-}
-
-static int
-thalloween(Par par)
-{
- RUNSTEP(par, droptable, ST);
- RUNSTEP(par, createtable, ST);
- RUNSTEP(par, invalidatetable, MT);
- RUNSTEP(par, createindex, ST);
- RUNSTEP(par, invalidateindex, MT);
- for (par.m_slno = 0; par.m_slno < par.m_sloop; par.m_slno++) {
- LL1(SUBLOOP(par));
- RUNSTEP(par, halloweentest, MT);
- }
- return 0;
-}
-
-static int
-ttimebuild(Par par)
-{
- Tmr t1;
- RUNSTEP(par, droptable, ST);
- RUNSTEP(par, createtable, ST);
- RUNSTEP(par, invalidatetable, MT);
- for (par.m_slno = 0; par.m_slno < par.m_sloop; par.m_slno++) {
- LL1(SUBLOOP(par));
- RUNSTEP(par, pkinsert, MT);
- t1.on();
- RUNSTEP(par, createindex, ST);
- t1.off(par.m_totrows);
- RUNSTEP(par, invalidateindex, MT);
- RUNSTEP(par, dropindex, ST);
- }
- LL1("build index - " << t1.time());
- return 0;
-}
-
-static int
-ttimemaint(Par par)
-{
- Tmr t1, t2;
- RUNSTEP(par, droptable, ST);
- RUNSTEP(par, createtable, ST);
- RUNSTEP(par, invalidatetable, MT);
- for (par.m_slno = 0; par.m_slno < par.m_sloop; par.m_slno++) {
- LL1(SUBLOOP(par));
- RUNSTEP(par, pkinsert, MT);
- t1.on();
- RUNSTEP(par, pkupdate, MT);
- t1.off(par.m_totrows);
- RUNSTEP(par, createindex, ST);
- RUNSTEP(par, invalidateindex, MT);
- t2.on();
- RUNSTEP(par, pkupdate, MT);
- t2.off(par.m_totrows);
- RUNSTEP(par, dropindex, ST);
- }
- LL1("update - " << t1.time());
- LL1("update indexed - " << t2.time());
- LL1("overhead - " << t2.over(t1));
- return 0;
-}
-
-static int
-ttimescan(Par par)
-{
- if (par.tab().m_itab[0] == 0) {
- LL1("ttimescan - no index 0, skipped");
- return 0;
- }
- Tmr t1, t2;
- RUNSTEP(par, droptable, ST);
- RUNSTEP(par, createtable, ST);
- RUNSTEP(par, invalidatetable, MT);
- for (par.m_slno = 0; par.m_slno < par.m_sloop; par.m_slno++) {
- LL1(SUBLOOP(par));
- RUNSTEP(par, pkinsert, MT);
- RUNSTEP(par, createindex, ST);
- par.m_tmr = &t1;
- RUNSTEP(par, timescantable, ST);
- par.m_tmr = &t2;
- RUNSTEP(par, timescanpkindex, ST);
- RUNSTEP(par, dropindex, ST);
- }
- LL1("full scan table - " << t1.time());
- LL1("full scan PK index - " << t2.time());
- LL1("overhead - " << t2.over(t1));
- return 0;
-}
-
-static int
-ttimepkread(Par par)
-{
- if (par.tab().m_itab[0] == 0) {
- LL1("ttimescan - no index 0, skipped");
- return 0;
- }
- Tmr t1, t2;
- RUNSTEP(par, droptable, ST);
- RUNSTEP(par, createtable, ST);
- RUNSTEP(par, invalidatetable, MT);
- for (par.m_slno = 0; par.m_slno < par.m_sloop; par.m_slno++) {
- LL1(SUBLOOP(par));
- RUNSTEP(par, pkinsert, MT);
- RUNSTEP(par, createindex, ST);
- par.m_tmr = &t1;
- RUNSTEP(par, timepkreadtable, ST);
- par.m_tmr = &t2;
- RUNSTEP(par, timepkreadindex, ST);
- RUNSTEP(par, dropindex, ST);
- }
- LL1("pk read table - " << t1.time());
- LL1("pk read PK index - " << t2.time());
- LL1("overhead - " << t2.over(t1));
- return 0;
-}
-
-static int
-tdrop(Par par)
-{
- RUNSTEP(par, droptable, ST);
- return 0;
-}
-
-struct TCase {
- const char* m_name;
- TFunc m_func;
- const char* m_desc;
- TCase(const char* name, TFunc func, const char* desc) :
- m_name(name),
- m_func(func),
- m_desc(desc) {
- }
-};
-
-static const TCase
-tcaselist[] = {
- TCase("a", tbuild, "index build"),
- TCase("b", tindexscan, "index scans"),
- TCase("c", tpkops, "pk operations"),
- TCase("d", tpkopsread, "pk operations and scan reads"),
- TCase("e", tmixedops, "pk operations and scan operations"),
- TCase("f", tbusybuild, "pk operations and index build"),
- TCase("g", trollback, "operations with random rollbacks"),
- TCase("h", tparupdate, "parallel ordered update bug#20446"),
- TCase("i", tsavepoint, "savepoint test locking bug#31477"),
- TCase("j", thalloween, "savepoint test halloween problem"),
- TCase("t", ttimebuild, "time index build"),
- TCase("u", ttimemaint, "time index maintenance"),
- TCase("v", ttimescan, "time full scan table vs index on pk"),
- TCase("w", ttimepkread, "time pk read table vs index on pk"),
- TCase("z", tdrop, "drop test tables")
-};
-
-static const uint
-tcasecount = sizeof(tcaselist) / sizeof(tcaselist[0]);
-
-static void
-printcases()
-{
- ndbout << "test cases:" << endl;
- for (uint i = 0; i < tcasecount; i++) {
- const TCase& tcase = tcaselist[i];
- ndbout << " " << tcase.m_name << " - " << tcase.m_desc << endl;
- }
-}
-
-static void
-printtables()
-{
- Par par(g_opt);
- makebuiltintables(par);
- ndbout << "tables and indexes (x=ordered z=hash x0=on pk):" << endl;
- for (uint j = 0; j < tabcount; j++) {
- if (tablist[j] == 0)
- continue;
- const Tab& tab = *tablist[j];
- const char* tname = tab.m_name;
- ndbout << " " << tname;
- for (uint i = 0; i < tab.m_itabs; i++) {
- if (tab.m_itab[i] == 0)
- continue;
- const ITab& itab = *tab.m_itab[i];
- const char* iname = itab.m_name;
- if (strncmp(tname, iname, strlen(tname)) == 0)
- iname += strlen(tname);
- ndbout << " " << iname;
- ndbout << "(";
- for (uint k = 0; k < itab.m_icols; k++) {
- if (k != 0)
- ndbout << ",";
- const ICol& icol = *itab.m_icol[k];
- const Col& col = icol.m_col;
- ndbout << col.m_name;
- }
- ndbout << ")";
- }
- ndbout << endl;
- }
-}
-
-static bool
-setcasepar(Par& par)
-{
- Opt d;
- const char* c = par.m_currcase;
- switch (c[0]) {
- case 'i':
- {
- if (par.m_usedthreads > 1) {
- par.m_usedthreads = 1;
- LL1("case " << c << " reduce threads to " << par.m_usedthreads);
- }
- const uint rows = 100;
- if (par.m_rows > rows) {
- par.m_rows = rows;
- LL1("case " << c << " reduce rows to " << rows);
- }
- }
- break;
- case 'j':
- {
- if (par.m_usedthreads > 1) {
- par.m_usedthreads = 1;
- LL1("case " << c << " reduce threads to " << par.m_usedthreads);
- }
- }
- break;
- default:
- break;
- }
- return true;
-}
-
-static int
-runtest(Par par)
-{
- int totret = 0;
- if (par.m_seed == -1) {
- // good enough for daily run
- ushort seed = (ushort)getpid();
- LL0("random seed: " << seed);
- srandom((uint)seed);
- } else if (par.m_seed != 0) {
- LL0("random seed: " << par.m_seed);
- srandom(par.m_seed);
- } else {
- LL0("random seed: loop number");
- }
- // cs
- assert(par.m_csname != 0);
- if (strcmp(par.m_csname, "random") != 0) {
- CHARSET_INFO* cs;
- CHK((cs = get_charset_by_name(par.m_csname, MYF(0))) != 0 || (cs = get_charset_by_csname(par.m_csname, MY_CS_PRIMARY, MYF(0))) != 0);
- par.m_cs = cs;
- }
- // con
- Con con;
- CHK(con.connect() == 0);
- par.m_con = &con;
- par.m_catcherr |= Con::ErrNospace;
- // threads
- g_thrlist = new Thr* [par.m_threads];
- uint n;
- for (n = 0; n < par.m_threads; n++) {
- g_thrlist[n] = 0;
- }
- for (n = 0; n < par.m_threads; n++) {
- g_thrlist[n] = new Thr(par, n);
- Thr& thr = *g_thrlist[n];
- assert(thr.m_thread != 0);
- }
- for (par.m_lno = 0; par.m_loop == 0 || par.m_lno < par.m_loop; par.m_lno++) {
- LL1("loop: " << par.m_lno);
- if (par.m_seed == 0) {
- LL1("random seed: " << par.m_lno);
- srandom(par.m_lno);
- }
- for (uint i = 0; i < tcasecount; i++) {
- const TCase& tcase = tcaselist[i];
- if (par.m_case != 0 && strchr(par.m_case, tcase.m_name[0]) == 0 ||
- par.m_skip != 0 && strchr(par.m_skip, tcase.m_name[0]) != 0) {
- continue;
- }
- sprintf(par.m_currcase, "%c", tcase.m_name[0]);
- par.m_usedthreads = par.m_threads;
- if (!setcasepar(par)) {
- LL1("case " << tcase.m_name << " cannot run with given options");
- continue;
- }
- par.m_totrows = par.m_usedthreads * par.m_rows;
- makebuiltintables(par);
- LL1("case: " << par.m_lno << "/" << tcase.m_name << " - " << tcase.m_desc);
- for (uint j = 0; j < tabcount; j++) {
- if (tablist[j] == 0)
- continue;
- const Tab& tab = *tablist[j];
- par.m_tab = &tab;
- par.m_set = new Set(tab, par.m_totrows);
- LL1("table: " << par.m_lno << "/" << tcase.m_name << "/" << tab.m_name);
- int ret = tcase.m_func(par);
- delete par.m_set;
- par.m_set = 0;
- if (ret == -1) {
- if (!par.m_cont)
- return -1;
- totret = -1;
- LL1("continue to next case due to -cont");
- break;
- }
- }
- }
- }
- for (n = 0; n < par.m_threads; n++) {
- Thr& thr = *g_thrlist[n];
- thr.exit();
- }
- for (n = 0; n < par.m_threads; n++) {
- Thr& thr = *g_thrlist[n];
- thr.join();
- delete &thr;
- }
- delete [] g_thrlist;
- g_thrlist = 0;
- con.disconnect();
- return totret;
-}
-
-static const char* g_progname = "testOIBasic";
-
-int
-main(int argc, char** argv)
-{
- ndb_init();
- uint i;
- ndbout << g_progname;
- for (i = 1; i < argc; i++)
- ndbout << " " << argv[i];
- ndbout << endl;
- ndbout_mutex = NdbMutex_Create();
- while (++argv, --argc > 0) {
- const char* arg = argv[0];
- if (*arg != '-') {
- ndbout << "testOIBasic: unknown argument " << arg;
- goto usage;
- }
- if (strcmp(arg, "-batch") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_batch = atoi(argv[0]);
- continue;
- }
- }
- if (strcmp(arg, "-bound") == 0) {
- if (++argv, --argc > 0) {
- const char* p = argv[0];
- if (strlen(p) != 0 && strlen(p) == strspn(p, "01234")) {
- g_opt.m_bound = strdup(p);
- continue;
- }
- }
- }
- if (strcmp(arg, "-case") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_case = strdup(argv[0]);
- continue;
- }
- }
- if (strcmp(arg, "-collsp") == 0) {
- g_opt.m_collsp = true;
- continue;
- }
- if (strcmp(arg, "-cont") == 0) {
- g_opt.m_cont = true;
- continue;
- }
- if (strcmp(arg, "-core") == 0) {
- g_opt.m_core = true;
- continue;
- }
- if (strcmp(arg, "-csname") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_csname = strdup(argv[0]);
- continue;
- }
- }
- if (strcmp(arg, "-die") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_die = atoi(argv[0]);
- continue;
- }
- }
- if (strcmp(arg, "-dups") == 0) {
- g_opt.m_dups = true;
- continue;
- }
- if (strcmp(arg, "-fragtype") == 0) {
- if (++argv, --argc > 0) {
- if (strcmp(argv[0], "single") == 0) {
- g_opt.m_fragtype = NdbDictionary::Object::FragSingle;
- continue;
- }
- if (strcmp(argv[0], "small") == 0) {
- g_opt.m_fragtype = NdbDictionary::Object::FragAllSmall;
- continue;
- }
- if (strcmp(argv[0], "medium") == 0) {
- g_opt.m_fragtype = NdbDictionary::Object::FragAllMedium;
- continue;
- }
- if (strcmp(argv[0], "large") == 0) {
- g_opt.m_fragtype = NdbDictionary::Object::FragAllLarge;
- continue;
- }
- }
- }
- if (strcmp(arg, "-index") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_index = strdup(argv[0]);
- continue;
- }
- }
- if (strcmp(arg, "-loop") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_loop = atoi(argv[0]);
- continue;
- }
- }
- if (strcmp(arg, "-nologging") == 0) {
- g_opt.m_nologging = true;
- continue;
- }
- if (strcmp(arg, "-noverify") == 0) {
- g_opt.m_noverify = true;
- continue;
- }
- if (strcmp(arg, "-pctnull") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_pctnull = atoi(argv[0]);
- continue;
- }
- }
- if (strcmp(arg, "-rows") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_rows = atoi(argv[0]);
- continue;
- }
- }
- if (strcmp(arg, "-samples") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_samples = atoi(argv[0]);
- continue;
- }
- }
- if (strcmp(arg, "-scanbatch") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_scanbatch = atoi(argv[0]);
- continue;
- }
- }
- if (strcmp(arg, "-scanpar") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_scanpar = atoi(argv[0]);
- continue;
- }
- }
- if (strcmp(arg, "-seed") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_seed = atoi(argv[0]);
- continue;
- }
- }
- if (strcmp(arg, "-skip") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_skip = strdup(argv[0]);
- continue;
- }
- }
- if (strcmp(arg, "-sloop") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_sloop = atoi(argv[0]);
- continue;
- }
- }
- if (strcmp(arg, "-ssloop") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_ssloop = atoi(argv[0]);
- continue;
- }
- }
- if (strcmp(arg, "-table") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_table = strdup(argv[0]);
- continue;
- }
- }
- if (strcmp(arg, "-threads") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_threads = atoi(argv[0]);
- if (1 <= g_opt.m_threads)
- continue;
- }
- }
- if (strcmp(arg, "-v") == 0) {
- if (++argv, --argc > 0) {
- g_opt.m_v = atoi(argv[0]);
- continue;
- }
- }
- if (strncmp(arg, "-v", 2) == 0 && isdigit(arg[2])) {
- g_opt.m_v = atoi(&arg[2]);
- continue;
- }
- if (strcmp(arg, "-h") == 0 || strcmp(arg, "-help") == 0) {
- printhelp();
- goto wrongargs;
- }
- ndbout << "testOIBasic: bad or unknown option " << arg;
- goto usage;
- }
- {
- Par par(g_opt);
- g_ncc = new Ndb_cluster_connection();
- if (g_ncc->connect(30) != 0 || runtest(par) < 0)
- goto failed;
- delete g_ncc;
- g_ncc = 0;
- }
-ok:
- return NDBT_ProgramExit(NDBT_OK);
-failed:
- return NDBT_ProgramExit(NDBT_FAILED);
-usage:
- ndbout << " (use -h for help)" << endl;
-wrongargs:
- return NDBT_ProgramExit(NDBT_WRONGARGS);
-}
-
-// vim: set sw=2 et:
diff --git a/storage/ndb/test/ndbapi/testOperations.cpp b/storage/ndb/test/ndbapi/testOperations.cpp
deleted file mode 100644
index 1da6a2457d3..00000000000
--- a/storage/ndb/test/ndbapi/testOperations.cpp
+++ /dev/null
@@ -1,796 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include "NDBT_Test.hpp"
-#include "NDBT_ReturnCodes.h"
-#include "HugoTransactions.hpp"
-#include "UtilTransactions.hpp"
-#include <NdbRestarter.hpp>
-
-struct OperationTestCase {
- const char * name;
- bool preCond; // start transaction | insert | commit
-
- // start transaction
- const char * op1;
- const int res1;
- const int val1;
-
- // no commit
-
- const char * op2;
- const int res2;
- const int val2;
- // Commit
-
- // start transaction
- // op3 = READ
- const int res3;
- const int val3;
- // commit transaction
-};
-
-OperationTestCase matrix[] = {
- { "ReadRead", true, "READ", 0, 0, "READ", 0, 0, 0, 0 },
- { "ReadReadEx", true, "READ", 0, 0, "READ-EX", 0, 0, 0, 0 },
- { "ReadSimpleRead", true, "READ", 0, 0, "S-READ", 0, 0, 0, 0 },
- { "ReadDirtyRead", true, "READ", 0, 0, "D-READ", 0, 0, 0, 0 },
- { "ReadInsert", true, "READ", 0, 0, "INSERT", 630, 1, 0, 0 },
- { "ReadUpdate", true, "READ", 0, 0, "UPDATE", 0, 1, 0, 1 },
- { "ReadDelete", true, "READ", 0, 0, "DELETE", 0, 0, 626, 0 },
-
- { "FReadRead", false, "READ", 626, 0, "READ", 626, 0, 626, 0 },
- { "FReadReadEx", false, "READ", 626, 0, "READ-EX", 626, 0, 626, 0 },
- { "FReadSimpleRead", false, "READ", 626, 0, "S-READ", 626, 0, 626, 0 },
- { "FReadDirtyRead", false, "READ", 626, 0, "D-READ", 626, 0, 626, 0 },
- { "FReadInsert", false, "READ", 626, 0, "INSERT", 0, 1, 0, 1 },
- { "FReadUpdate", false, "READ", 626, 0, "UPDATE", 626, 0, 626, 0 },
- { "FReadDelete", false, "READ", 626, 0, "DELETE", 626, 0, 626, 0 },
-
- { "ReadExRead", true, "READ-EX", 0, 0, "READ", 0, 0, 0, 0 },
- { "ReadExReadEx", true, "READ-EX", 0, 0, "READ-EX", 0, 0, 0, 0 },
- { "ReadExSimpleRead", true, "READ-EX", 0, 0, "S-READ", 0, 0, 0, 0 },
- { "ReadExDirtyRead", true, "READ-EX", 0, 0, "D-READ", 0, 0, 0, 0 },
- { "ReadExInsert", true, "READ-EX", 0, 0, "INSERT", 630, 1, 0, 0 },
- { "ReadExUpdate", true, "READ-EX", 0, 0, "UPDATE", 0, 1, 0, 1 },
- { "ReadExDelete", true, "READ-EX", 0, 0, "DELETE", 0, 0, 626, 0 },
-
- { "InsertRead", false, "INSERT", 0, 0, "READ", 0, 0, 0, 0 },
- { "InsertReadEx", false, "INSERT", 0, 0, "READ-EX", 0, 0, 0, 0 },
- { "InsertSimpleRead",false, "INSERT", 0, 0, "S-READ", 0, 0, 0, 0 },
- { "InsertDirtyRead", false, "INSERT", 0, 0, "D-READ", 0, 0, 0, 0 },
- { "InsertInsert", false, "INSERT", 0, 0, "INSERT", 630, 0, 626, 0 },
- { "InsertUpdate", false, "INSERT", 0, 0, "UPDATE", 0, 1, 0, 1 },
- { "InsertDelete", false, "INSERT", 0, 0, "DELETE", 0, 0, 626, 0 },
-
- { "UpdateRead", true, "UPDATE", 0, 1, "READ", 0, 1, 0, 1 },
- { "UpdateReadEx", true, "UPDATE", 0, 1, "READ-EX", 0, 1, 0, 1 },
- { "UpdateSimpleRead", true, "UPDATE", 0, 1, "S-READ", 0, 1, 0, 1 },
- { "UpdateDirtyRead", true, "UPDATE", 0, 1, "D-READ", 0, 1, 0, 1 },
- { "UpdateInsert", true, "UPDATE", 0, 1, "INSERT", 630, 0, 0, 0 },
- { "UpdateUpdate", true, "UPDATE", 0, 1, "UPDATE", 0, 2, 0, 2 },
- { "UpdateDelete", true, "UPDATE", 0, 1, "DELETE", 0, 0, 626, 0 },
-
- { "DeleteRead", true, "DELETE", 0, 0, "READ", 626, 0, 0, 0 },
- { "DeleteReadEx", true, "DELETE", 0, 0, "READ-EX", 626, 0, 0, 0 },
- { "DeleteSimpleRead", true, "DELETE", 0, 0, "S-READ", 626, 0, 0, 0 },
- { "DeleteDirtyRead", true, "DELETE", 0, 0, "D-READ", 626, 0, 626, 0 },
- { "DeleteInsert", true, "DELETE", 0, 0, "INSERT", 0, 1, 0, 1 },
- { "DeleteUpdate", true, "DELETE", 0, 0, "UPDATE", 626, 1, 0, 0 },
- { "DeleteDelete", true, "DELETE", 0, 0, "DELETE", 626, 0, 0, 0 }
-};
-
-#define CHECK(b) if (!(b)) { \
- g_err << "ERR: "<< step->getName() \
- << " failed on line " << __LINE__ << endl; \
- result = NDBT_FAILED; \
- break; }
-
-#define C3(b) if (!(b)) { \
- g_err << "ERR: failed on line " << __LINE__ << endl; \
- return NDBT_FAILED; }
-
-int
-runOp(HugoOperations & hugoOps,
- Ndb * pNdb,
- const char * op,
- int value){
-
-#define C2(x, y) { int r = (x); int s = (y); if(r != s) {\
- g_err << "ERR: failed on line " << __LINE__ << ": " \
- << r << " != " << s << endl; \
- return NDBT_FAILED; }}
-
- if(strcmp(op, "READ") == 0){
- C2(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Read), 0);
- } else if(strcmp(op, "READ-EX") == 0){
- C2(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive), 0);
- } else if(strcmp(op, "S-READ") == 0){
- C2(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Read), 0);
- } else if(strcmp(op, "D-READ") == 0){
- C2(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_CommittedRead), 0);
- } else if(strcmp(op, "INSERT") == 0){
- C2(hugoOps.pkInsertRecord(pNdb, 1, 1, value), 0);
- } else if(strcmp(op, "UPDATE") == 0){
- C2(hugoOps.pkUpdateRecord(pNdb, 1, 1, value), 0);
- } else if(strcmp(op, "DELETE") == 0){
- C2(hugoOps.pkDeleteRecord(pNdb, 1, 1), 0);
- } else {
- g_err << __FILE__ << " - " << __LINE__
- << ": Unknown operation" << op << endl;
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-int
-checkVal(HugoOperations & hugoOps,
- const char * op,
- int value,
- int result){
- if(result != 0)
- return NDBT_OK;
-
- if(strcmp(op, "READ") == 0){
- } else if(strcmp(op, "READ-EX") == 0){
- } else if(strcmp(op, "S-READ") == 0){
- } else if(strcmp(op, "D-READ") == 0){
- } else {
- return NDBT_OK;
- }
-
- return hugoOps.verifyUpdatesValue(value);
-}
-
-int
-runTwoOperations(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- const char * op1 = ctx->getProperty("op1", "NONE");
- const int val1 = ctx->getProperty("val1", ~0);
- const int res1 = ctx->getProperty("res1", ~0);
- const char * op2 = ctx->getProperty("op2", "NONE");
- const int res2 = ctx->getProperty("res2", ~0);
- const int val2 = ctx->getProperty("val2", ~0);
-
- const int res3 = ctx->getProperty("res3", ~0);
- const int val3 = ctx->getProperty("val3", ~0);
-
- do {
- // Insert, read
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(runOp(hugoOps, pNdb, op1, val1) == 0);
- AbortOption oa = (res1 == 0) ? AbortOnError : AO_IgnoreError;
- CHECK(hugoOps.execute_NoCommit(pNdb, oa) == res1);
- CHECK(checkVal(hugoOps, op1, val1, res1) == 0);
-
- ndbout_c("-- running op 2");
-
- CHECK(runOp(hugoOps, pNdb, op2, val2) == 0);
- CHECK(hugoOps.execute_Commit(pNdb) == res2);
- CHECK(checkVal(hugoOps, op2, val2, res2) == 0);
-
- } while(false);
- hugoOps.closeTransaction(pNdb);
-
- if(result != NDBT_OK)
- return result;
-
- do {
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(runOp(hugoOps, pNdb, "READ", 0) == 0);
- CHECK(hugoOps.execute_Commit(pNdb) == res3);
- CHECK(checkVal(hugoOps, "READ", val3, res3) == 0);
- } while(false);
- hugoOps.closeTransaction(pNdb);
-
- return result;
-}
-
-int
-runInsertRecord(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- do{
- // Insert, insert
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkInsertRecord(pNdb, 1) == 0);
- CHECK(hugoOps.execute_Commit(pNdb) == 0);
-
- } while(false);
-
- hugoOps.closeTransaction(pNdb);
-
- return result;
-}
-
-int
-runClearTable(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
-
- UtilTransactions utilTrans(*ctx->getTab());
- if (utilTrans.clearTable2(GETNDB(step), records, 240) != 0){
- return NDBT_FAILED;
- }
-
- NdbRestarter r;
- int lcp = 7099;
- r.dumpStateAllNodes(&lcp, 1);
-
- return NDBT_OK;
-}
-
-enum OPS { o_DONE= 0, o_INS= 1, o_UPD= 2, o_DEL= 3 };
-typedef Vector<OPS> Sequence;
-
-static
-bool
-valid(const Sequence& s)
-{
- if(s.size() == 0)
- return false;
-
- for(size_t i = 1; i<s.size(); i++)
- {
- switch(s[i]){
- case o_INS:
- if(s[i-1] != o_DEL)
- return false;
- break;
- case o_UPD:
- case o_DEL:
- if(s[i-1] == o_DEL)
- return false;
- break;
- case o_DONE:
- return true;
- }
- }
- return true;
-}
-
-static
-NdbOut& operator<<(NdbOut& out, const Sequence& s)
-{
- out << "[ ";
- for(size_t i = 0; i<s.size(); i++)
- {
- switch(s[i]){
- case o_INS:
- out << "INS ";
- break;
- case o_DEL:
- out << "DEL ";
- break;
- case o_UPD:
- out << "UPD ";
- break;
- case o_DONE:
- abort();
- }
- }
- out << "]";
- return out;
-}
-
-static
-void
-generate(Sequence& out, int no)
-{
- while(no & 3)
- {
- out.push_back((OPS)(no & 3));
- no >>= 2;
- }
-}
-
-static
-void
-generate(Vector<int>& out, size_t len)
-{
- int max= 1;
- while(len)
- {
- max <<= 2;
- len--;
- }
-
- len= 1;
- for(int i = 0; i<max; i++)
- {
- Sequence tmp;
- generate(tmp, i);
-
- if(tmp.size() >= len && valid(tmp))
- {
- out.push_back(i);
- len= tmp.size();
- }
- else
- {
- //ndbout << "DISCARD: " << tmp << endl;
- }
- }
-}
-
-static const Uint32 DUMMY = 0;
-static const Uint32 ROW = 1;
-
-int
-verify_other(NDBT_Context* ctx,
- Ndb* pNdb, int seq, OPS latest, bool initial_row, bool commit)
-{
- Uint32 no_wait = NdbOperation::LM_CommittedRead*
- ctx->getProperty("NoWait", (Uint32)1);
-
- for(size_t j = no_wait; j<3; j++)
- {
- HugoOperations other(*ctx->getTab());
- C3(other.startTransaction(pNdb) == 0);
- C3(other.pkReadRecord(pNdb, ROW, 1, (NdbOperation::LockMode)j) == 0);
- int tmp= other.execute_Commit(pNdb);
- if(seq == 0){
- if(j == NdbOperation::LM_CommittedRead)
- {
- C3(initial_row? tmp==0 && other.verifyUpdatesValue(0) == 0 : tmp==626);
- }
- else
- {
- C3(tmp == 266);
- }
- }
- else if(commit)
- {
- switch(latest){
- case o_INS:
- case o_UPD:
- C3(tmp == 0 && other.verifyUpdatesValue(seq) == 0);
- break;
- case o_DEL:
- C3(tmp == 626);
- break;
- case o_DONE:
- abort();
- }
- }
- else
- {
- // rollback
- C3(initial_row? tmp==0 && other.verifyUpdatesValue(0) == 0 : tmp==626);
- }
- }
-
- return NDBT_OK;
-}
-
-int
-verify_savepoint(NDBT_Context* ctx,
- Ndb* pNdb, int seq, OPS latest,
- Uint64 transactionId)
-{
- bool initial_row= (seq == 0) && latest == o_INS;
-
- for(size_t j = 0; j<3; j++)
- {
- const NdbOperation::LockMode lm= (NdbOperation::LockMode)j;
-
- HugoOperations same(*ctx->getTab());
- C3(same.startTransaction(pNdb) == 0);
- same.setTransactionId(transactionId); // Cheat
-
- /**
- * Increase savepoint to <em>k</em>
- */
- for(size_t l = 1; l<=seq; l++)
- {
- C3(same.pkReadRecord(pNdb, DUMMY, 1, lm) == 0); // Read dummy row
- C3(same.execute_NoCommit(pNdb) == 0);
- g_info << "savepoint: " << l << endl;
- }
-
- g_info << "op(" << seq << "): "
- << " lock mode " << lm << endl;
-
- C3(same.pkReadRecord(pNdb, ROW, 1, lm) == 0); // Read real row
- int tmp= same.execute_Commit(pNdb);
- if(seq == 0)
- {
- if(initial_row)
- {
- C3(tmp == 0 && same.verifyUpdatesValue(0) == 0);
- } else
- {
- C3(tmp == 626);
- }
- }
- else
- {
- switch(latest){
- case o_INS:
- case o_UPD:
- C3(tmp == 0 && same.verifyUpdatesValue(seq) == 0);
- break;
- case o_DEL:
- C3(tmp == 626);
- break;
- case o_DONE:
- abort();
- }
- }
- }
- return NDBT_OK;
-}
-
-int
-runOperations(NDBT_Context* ctx, NDBT_Step* step)
-{
- int tmp;
- Ndb* pNdb = GETNDB(step);
-
- Uint32 seqNo = ctx->getProperty("Sequence", (Uint32)0);
- Uint32 commit= ctx->getProperty("Commit", (Uint32)1);
-
- if(seqNo == 0)
- {
- return NDBT_FAILED;
- }
-
- Sequence seq;
- generate(seq, seqNo);
-
- {
- // Dummy row
- HugoOperations hugoOps(*ctx->getTab());
- C3(hugoOps.startTransaction(pNdb) == 0);
- C3(hugoOps.pkInsertRecord(pNdb, DUMMY, 1, 0) == 0);
- C3(hugoOps.execute_Commit(pNdb) == 0);
- }
-
- const bool initial_row= (seq[0] != o_INS);
- if(initial_row)
- {
- HugoOperations hugoOps(*ctx->getTab());
- C3(hugoOps.startTransaction(pNdb) == 0);
- C3(hugoOps.pkInsertRecord(pNdb, ROW, 1, 0) == 0);
- C3(hugoOps.execute_Commit(pNdb) == 0);
- }
-
- HugoOperations trans1(*ctx->getTab());
- C3(trans1.startTransaction(pNdb) == 0);
- for(size_t i = 0; i<seq.size(); i++)
- {
- /**
- * Perform operation
- */
- switch(seq[i]){
- case o_INS:
- C3(trans1.pkInsertRecord(pNdb, ROW, 1, i+1) == 0);
- break;
- case o_UPD:
- C3(trans1.pkUpdateRecord(pNdb, ROW, 1, i+1) == 0);
- break;
- case o_DEL:
- C3(trans1.pkDeleteRecord(pNdb, ROW, 1) == 0);
- break;
- case o_DONE:
- abort();
- }
- C3(trans1.execute_NoCommit(pNdb) == 0);
-
- /**
- * Verify other transaction
- */
- if(verify_other(ctx, pNdb, 0, seq[0], initial_row, commit) != NDBT_OK)
- return NDBT_FAILED;
-
- /**
- * Verify savepoint read
- */
- Uint64 transactionId= trans1.getTransaction()->getTransactionId();
-
- for(size_t k=0; k<=i+1; k++)
- {
- if(verify_savepoint(ctx, pNdb, k,
- k>0 ? seq[k-1] : initial_row ? o_INS : o_DONE,
- transactionId) != NDBT_OK)
- return NDBT_FAILED;
- }
- }
-
- if(commit)
- {
- C3(trans1.execute_Commit(pNdb) == 0);
- }
- else
- {
- C3(trans1.execute_Rollback(pNdb) == 0);
- }
-
- if(verify_other(ctx, pNdb, seq.size(), seq.back(),
- initial_row, commit) != NDBT_OK)
- return NDBT_FAILED;
-
- return NDBT_OK;
-}
-
-int
-runLockUpgrade1(NDBT_Context* ctx, NDBT_Step* step){
- // Verify that data in index match
- // table data
- Ndb* pNdb = GETNDB(step);
- HugoOperations hugoOps(*ctx->getTab());
- HugoTransactions hugoTrans(*ctx->getTab());
-
- if(hugoTrans.loadTable(pNdb, 1) != 0){
- g_err << "Load table failed" << endl;
- return NDBT_FAILED;
- }
-
- int result= NDBT_OK;
- do
- {
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- if(ctx->getProperty("LOCK_UPGRADE", 1) == 1)
- {
- CHECK(hugoOps.pkReadRecord(pNdb, 0, 1, NdbOperation::LM_Read) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
-
- ctx->setProperty("READ_DONE", 1);
- ctx->broadcast();
- ndbout_c("wait 2");
- ctx->getPropertyWait("READ_DONE", 2);
- ndbout_c("wait 2 - done");
- }
- else
- {
- ctx->setProperty("READ_DONE", 1);
- ctx->broadcast();
- ctx->getPropertyWait("READ_DONE", 2);
- ndbout_c("wait 2 - done");
- CHECK(hugoOps.pkReadRecord(pNdb, 0, 1, NdbOperation::LM_Read) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
- }
- if(ctx->getProperty("LU_OP", o_INS) == o_INS)
- {
- CHECK(hugoOps.pkDeleteRecord(pNdb, 0, 1) == 0);
- CHECK(hugoOps.pkInsertRecord(pNdb, 0, 1, 2) == 0);
- }
- else if(ctx->getProperty("LU_OP", o_UPD) == o_UPD)
- {
- CHECK(hugoOps.pkUpdateRecord(pNdb, 0, 1, 2) == 0);
- }
- else
- {
- CHECK(hugoOps.pkDeleteRecord(pNdb, 0, 1) == 0);
- }
- ctx->setProperty("READ_DONE", 3);
- ctx->broadcast();
- ndbout_c("before update");
- ndbout_c("wait update");
- CHECK(hugoOps.execute_Commit(pNdb) == 0);
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
-
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, 0, 1) == 0);
- int res= hugoOps.execute_Commit(pNdb);
- if(ctx->getProperty("LU_OP", o_INS) == o_INS)
- {
- CHECK(res == 0);
- CHECK(hugoOps.verifyUpdatesValue(2) == 0);
- }
- else if(ctx->getProperty("LU_OP", o_UPD) == o_UPD)
- {
- CHECK(res == 0);
- CHECK(hugoOps.verifyUpdatesValue(2) == 0);
- }
- else
- {
- CHECK(res == 626);
- }
-
- } while(0);
-
- return result;
-}
-
-int
-runLockUpgrade2(NDBT_Context* ctx, NDBT_Step* step){
- // Verify that data in index match
- // table data
- Ndb* pNdb = GETNDB(step);
- HugoOperations hugoOps(*ctx->getTab());
- HugoTransactions hugoTrans(*ctx->getTab());
-
-
- int result= NDBT_OK;
- do
- {
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- ndbout_c("wait 1");
- ctx->getPropertyWait("READ_DONE", 1);
- ndbout_c("wait 1 - done");
- CHECK(hugoOps.pkReadRecord(pNdb, 0, 1, NdbOperation::LM_Read) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
- ctx->setProperty("READ_DONE", 2);
- ctx->broadcast();
- ndbout_c("wait 3");
- ctx->getPropertyWait("READ_DONE", 3);
- ndbout_c("wait 3 - done");
-
- NdbSleep_MilliSleep(200);
- if(ctx->getProperty("LU_COMMIT", (Uint32)0) == 0)
- {
- CHECK(hugoOps.execute_Commit(pNdb) == 0);
- }
- else
- {
- CHECK(hugoOps.execute_Rollback(pNdb) == 0);
- }
- } while(0);
-
- return result;
-}
-
-int
-main(int argc, const char** argv){
- ndb_init();
-
- Vector<int> tmp;
- generate(tmp, 5);
-
- NDBT_TestSuite ts("testOperations");
-
- ts.setTemporaryTables(true);
-
- for(Uint32 i = 0; i < 12; i++)
- {
- if(false && (i == 6 || i == 8 || i == 10))
- continue;
-
- BaseString name("bug_9749");
- name.appfmt("_%d", i);
- NDBT_TestCaseImpl1 *pt = new NDBT_TestCaseImpl1(&ts,
- name.c_str(), "");
-
- pt->setProperty("LOCK_UPGRADE", 1 + (i & 1));
- pt->setProperty("LU_OP", 1 + ((i >> 1) % 3));
- pt->setProperty("LU_COMMIT", i / 6);
-
- pt->addInitializer(new NDBT_Initializer(pt,
- "runClearTable",
- runClearTable));
-
- pt->addStep(new NDBT_ParallelStep(pt,
- "thread1",
- runLockUpgrade1));
-
-
- pt->addStep(new NDBT_ParallelStep(pt,
- "thread2",
- runLockUpgrade2));
-
- pt->addFinalizer(new NDBT_Finalizer(pt,
- "runClearTable",
- runClearTable));
- ts.addTest(pt);
- }
-
- for(size_t i = 0; i<tmp.size(); i++)
- {
- BaseString name;
- Sequence s;
- generate(s, tmp[i]);
- for(size_t j = 0; j<s.size(); j++){
- switch(s[j]){
- case o_INS:
- name.append("_INS");
- break;
- case o_DEL:
- name.append("_DEL");
- break;
- case o_UPD:
- name.append("_UPD");
- break;
- case o_DONE:
- abort();
- }
- }
-
- BaseString n1;
- n1.append(name);
- n1.append("_COMMIT");
-
- NDBT_TestCaseImpl1 *pt = new NDBT_TestCaseImpl1(&ts,
- n1.c_str()+1, "");
-
- pt->setProperty("Sequence", tmp[i]);
- pt->addInitializer(new NDBT_Initializer(pt,
- "runClearTable",
- runClearTable));
-
- pt->addStep(new NDBT_ParallelStep(pt,
- "run",
- runOperations));
-
- pt->addFinalizer(new NDBT_Finalizer(pt,
- "runClearTable",
- runClearTable));
-
- ts.addTest(pt);
-
- name.append("_ABORT");
- pt = new NDBT_TestCaseImpl1(&ts, name.c_str()+1, "");
- pt->setProperty("Sequence", tmp[i]);
- pt->setProperty("Commit", (Uint32)0);
- pt->addInitializer(new NDBT_Initializer(pt,
- "runClearTable",
- runClearTable));
-
- pt->addStep(new NDBT_ParallelStep(pt,
- "run",
- runOperations));
-
- pt->addFinalizer(new NDBT_Finalizer(pt,
- "runClearTable",
- runClearTable));
-
- ts.addTest(pt);
- }
-
- for(Uint32 i = 0; i<sizeof(matrix)/sizeof(matrix[0]); i++){
- NDBT_TestCaseImpl1 *pt = new NDBT_TestCaseImpl1(&ts, matrix[i].name, "");
-
- pt->addInitializer(new NDBT_Initializer(pt,
- "runClearTable",
- runClearTable));
-
- if(matrix[i].preCond){
- pt->addInitializer(new NDBT_Initializer(pt,
- "runInsertRecord",
- runInsertRecord));
- }
-
- pt->setProperty("op1", matrix[i].op1);
- pt->setProperty("res1", matrix[i].res1);
- pt->setProperty("val1", matrix[i].val1);
-
- pt->setProperty("op2", matrix[i].op2);
- pt->setProperty("res2", matrix[i].res2);
- pt->setProperty("val2", matrix[i].val2);
-
- pt->setProperty("res3", matrix[i].res3);
- pt->setProperty("val3", matrix[i].val3);
-
- pt->addStep(new NDBT_ParallelStep(pt,
- matrix[i].name,
- runTwoOperations));
- pt->addFinalizer(new NDBT_Finalizer(pt,
- "runClearTable",
- runClearTable));
-
- ts.addTest(pt);
- }
-
- return ts.execute(argc, argv);
-}
-
-template class Vector<OPS>;
-template class Vector<Sequence>;
diff --git a/storage/ndb/test/ndbapi/testOrderedIndex.cpp b/storage/ndb/test/ndbapi/testOrderedIndex.cpp
deleted file mode 100644
index 2a2c9095a3a..00000000000
--- a/storage/ndb/test/ndbapi/testOrderedIndex.cpp
+++ /dev/null
@@ -1,225 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT.hpp>
-#include <NDBT_Test.hpp>
-#include <HugoTransactions.hpp>
-#include <UtilTransactions.hpp>
-#include <NdbRestarter.hpp>
-#include <Vector.hpp>
-#include <ndbapi_limits.h>
-
-const unsigned MaxTableAttrs = NDB_MAX_ATTRIBUTES_IN_TABLE;
-const unsigned MaxIndexAttrs = NDB_MAX_ATTRIBUTES_IN_INDEX;
-const unsigned MaxIndexes = 20;
-
-static unsigned
-urandom(unsigned n)
-{
- unsigned i = random();
- return i % n;
-}
-
-static int
-runDropIndex(NDBT_Context* ctx, NDBT_Step* step)
-{
- const NdbDictionary::Table* pTab = ctx->getTab();
- Ndb* pNdb = GETNDB(step);
- NdbDictionary::Dictionary* pDic = pNdb->getDictionary();
- NdbDictionary::Dictionary::List list;
- if (pDic->listIndexes(list, pTab->getName()) != 0) {
- g_err << pTab->getName() << ": listIndexes failed" << endl;
- ERR(pDic->getNdbError());
- return NDBT_FAILED;
- }
- for (unsigned i = 0; i < list.count; i++) {
- NDBT_Index* pInd = new NDBT_Index(list.elements[i].name);
- pInd->setTable(pTab->getName());
- g_info << "Drop index:" << endl << *pInd;
- if (pInd->dropIndexInDb(pNdb) != 0) {
- return NDBT_FAILED;
- }
- }
- return NDBT_OK;
-}
-
-static Uint32 workaround[1000];
-
-static void
-setTableProperty(NDBT_Context* ctx, NDBT_Table* pTab, const char* name, Uint32 num)
-{
- char key[200];
- sprintf(key, "%s-%s", name, pTab->getName());
- //ctx->setProperty(key, num);
- workaround[pTab->getTableId()] = num;
-}
-
-static Uint32
-getTableProperty(NDBT_Context* ctx, NDBT_Table* pTab, const char* name)
-{
- char key[200];
- sprintf(key, "%s-%s", name, pTab->getName());
- //Uint32 num = ctx->getProperty(key, (Uint32)-1);
- Uint32 num = workaround[pTab->getTableId()];
- assert(num != (Uint32)-1);
- return num;
-}
-
-static int
-runCreateIndex(NDBT_Context* ctx, NDBT_Step* step)
-{
- srandom(1);
- NDBT_Table* pTab = ctx->getTab();
- Ndb* pNdb = GETNDB(step);
- unsigned numTabAttrs = pTab->getNumAttributes();
- unsigned numIndex = 0;
- while (numIndex < MaxIndexes) {
- if (numIndex != 0 && urandom(10) == 0)
- break;
- char buf[200];
- sprintf(buf, "%s_X%03d", pTab->getName(), numIndex);
- NDBT_Index* pInd = new NDBT_Index(buf);
- pInd->setTable(pTab->getName());
- pInd->setType(NdbDictionary::Index::OrderedIndex);
- pInd->setLogging(false);
- unsigned numAttrs = 0;
- while (numAttrs < MaxIndexAttrs) {
- if (numAttrs != 0 && urandom(5) == 0)
- break;
- unsigned i = urandom(numTabAttrs);
- const NDBT_Attribute* pAttr = pTab->getAttribute(i);
- bool found = false;
- for (unsigned j = 0; j < numAttrs; j++) {
- if (strcmp(pAttr->getName(), pInd->getAttribute(j)->getName()) == 0) {
- found = true;
- break;
- }
- }
- if (found)
- continue;
- pInd->addAttribute(*pAttr);
- numAttrs++;
- }
- g_info << "Create index:" << endl << *pInd;
- if (pInd->createIndexInDb(pNdb, false) != 0)
- continue;
- numIndex++;
- }
- setTableProperty(ctx, pTab, "numIndex", numIndex);
- g_info << "Created " << numIndex << " indexes on " << pTab->getName() << endl;
- return NDBT_OK;
-}
-
-static int
-runInsertUpdate(NDBT_Context* ctx, NDBT_Step* step)
-{
- NDBT_Table* pTab = ctx->getTab();
- Ndb* pNdb = GETNDB(step);
- int ret;
- g_info << "Insert: " << pTab->getName() << endl;
- HugoTransactions hugoTrans(*pTab);
- ret = hugoTrans.loadTable(pNdb, ctx->getNumRecords(), 100);
- if (ret != 0) {
- g_err << "ERR: " << step->getName() << "failed" << endl;
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-static int
-runFullScan(NDBT_Context* ctx, NDBT_Step* step)
-{
- NDBT_Table* pTab = ctx->getTab();
- Ndb* pNdb = GETNDB(step);
- unsigned cntIndex = getTableProperty(ctx, pTab, "numIndex");
- for (unsigned numIndex = 0; numIndex < cntIndex; numIndex++) {
- char buf[200];
- sprintf(buf, "%s_X%03d", pTab->getName(), numIndex);
- NDBT_Index* pInd = NDBT_Index::discoverIndexFromDb(pNdb, buf, pTab->getName());
- assert(pInd != 0);
- g_info << "Scan index:" << pInd->getName() << endl << *pInd;
- NdbConnection* pCon = pNdb->startTransaction();
- if (pCon == 0) {
- ERR(pNdb->getNdbError());
- return NDBT_FAILED;
- }
- NdbOperation* pOp = pCon->getNdbOperation(pInd->getName(),
- pTab->getName());
- if (pOp == 0) {
- ERR(pCon->getNdbError());
- pNdb->closeTransaction(pCon);
- return NDBT_FAILED;
- }
- if (pOp->openScanRead() != 0) {
- ERR(pCon->getNdbError());
- pNdb->closeTransaction(pCon);
- return NDBT_FAILED;
- }
- if (pCon->executeScan() != 0) {
- ERR(pCon->getNdbError());
- pNdb->closeTransaction(pCon);
- return NDBT_FAILED;
- }
- unsigned rows = 0;
- while (1) {
- int ret = pCon->nextScanResult();
- if (ret == 0) {
- rows++;
- } else if (ret == 1) {
- break;
- } else {
- ERR(pCon->getNdbError());
- pNdb->closeTransaction(pCon);
- return NDBT_FAILED;
- }
- }
- pNdb->closeTransaction(pCon);
- g_info << "Scanned " << rows << " rows" << endl;
- }
- return NDBT_OK;
-}
-
-NDBT_TESTSUITE(testOrderedIndex);
-TESTCASE(
- "DropIndex",
- "Drop any old indexes") {
- INITIALIZER(runDropIndex);
-}
-TESTCASE(
- "CreateIndex",
- "Create ordered indexes") {
- INITIALIZER(runCreateIndex);
-}
-TESTCASE(
- "InsertUpdate",
- "Run inserts and updates") {
- INITIALIZER(runInsertUpdate);
-}
-TESTCASE(
- "FullScan",
- "Full scan on each ordered index") {
- INITIALIZER(runFullScan);
-}
-NDBT_TESTSUITE_END(testOrderedIndex);
-
-int
-main(int argc, const char** argv)
-{
- ndb_init();
- return testOrderedIndex.execute(argc, argv);
-}
-
-// vim: set sw=2:
diff --git a/storage/ndb/test/ndbapi/testPartitioning.cpp b/storage/ndb/test/ndbapi/testPartitioning.cpp
deleted file mode 100644
index abe1d151adc..00000000000
--- a/storage/ndb/test/ndbapi/testPartitioning.cpp
+++ /dev/null
@@ -1,448 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT_Test.hpp>
-#include <NDBT_ReturnCodes.h>
-#include <HugoTransactions.hpp>
-#include <UtilTransactions.hpp>
-#include <NdbRestarter.hpp>
-
-#define GETNDB(ps) ((NDBT_NdbApiStep*)ps)->getNdb()
-
-static Uint32 max_dks = 0;
-
-static
-int
-run_drop_table(NDBT_Context* ctx, NDBT_Step* step)
-{
- NdbDictionary::Dictionary* dict = GETNDB(step)->getDictionary();
- dict->dropTable(ctx->getTab()->getName());
- return 0;
-}
-
-static
-int
-add_distribution_key(Ndb*, NdbDictionary::Table& tab, int when, void* arg)
-{
- switch(when){
- case 0: // Before
- break;
- case 1: // After
- return 0;
- default:
- return 0;
- }
-
- int keys = tab.getNoOfPrimaryKeys();
- int dks = (2 * keys + 2) / 3; dks = (dks > max_dks ? max_dks : dks);
- int cnt = 0;
-
- for(unsigned i = 0; i<tab.getNoOfColumns(); i++)
- if(tab.getColumn(i)->getPrimaryKey() &&
- tab.getColumn(i)->getCharset() != 0)
- keys--;
-
- Uint32 max = NDB_MAX_NO_OF_ATTRIBUTES_IN_KEY - tab.getNoOfPrimaryKeys();
-
- if(max_dks < max)
- max = max_dks;
-
- if(keys <= 1 && max > 0)
- {
- dks = 1 + (rand() % max);
- ndbout_c("%s pks: %d dks: %d", tab.getName(), keys, dks);
- while(dks--)
- {
- NdbDictionary::Column col;
- BaseString name;
- name.assfmt("PK_DK_%d", dks);
- col.setName(name.c_str());
- if((rand() % 100) > 50)
- {
- col.setType(NdbDictionary::Column::Unsigned);
- col.setLength(1);
- }
- else
- {
- col.setType(NdbDictionary::Column::Varbinary);
- col.setLength(1+(rand() % 25));
- }
- col.setNullable(false);
- col.setPrimaryKey(true);
- col.setDistributionKey(true);
- tab.addColumn(col);
- }
- }
- else
- {
- for(unsigned i = 0; i<tab.getNoOfColumns(); i++)
- {
- NdbDictionary::Column* col = tab.getColumn(i);
- if(col->getPrimaryKey() && col->getCharset() == 0)
- {
- if(dks >= keys || (rand() % 100) > 50)
- {
- col->setDistributionKey(true);
- dks--;
- }
- keys--;
- }
- }
- }
-
- Uint32 linear_hash_ind = rand() & 1;
- NdbDictionary::Table::FragmentType ftype;
- if (linear_hash_ind)
- ftype = NdbDictionary::Table::DistrKeyLin;
- else
- ftype = NdbDictionary::Table::DistrKeyHash;
- tab.setFragmentType(ftype);
-
- ndbout << (NDBT_Table&)tab << endl;
-
- return 0;
-}
-
-static int
-run_create_table(NDBT_Context* ctx, NDBT_Step* step)
-{
- max_dks = ctx->getProperty("distributionkey", (unsigned)0);
-
- if(NDBT_Tables::createTable(GETNDB(step),
- ctx->getTab()->getName(),
- false, false,
- max_dks?add_distribution_key:0) == NDBT_OK)
- {
- return NDBT_OK;
- }
-
- if(GETNDB(step)->getDictionary()->getNdbError().code == 745)
- return NDBT_OK;
-
- return NDBT_FAILED;
-}
-
-static int
-run_create_pk_index(NDBT_Context* ctx, NDBT_Step* step){
- bool orderedIndex = ctx->getProperty("OrderedIndex", (unsigned)0);
-
- Ndb* pNdb = GETNDB(step);
- const NdbDictionary::Table *pTab =
- pNdb->getDictionary()->getTable(ctx->getTab()->getName());
-
- if(!pTab)
- return NDBT_OK;
-
- bool logged = ctx->getProperty("LoggedIndexes", orderedIndex ? 0 : 1);
-
- BaseString name;
- name.assfmt("IND_%s_PK_%c", pTab->getName(), orderedIndex ? 'O' : 'U');
-
- // Create index
- if (orderedIndex)
- ndbout << "Creating " << ((logged)?"logged ": "temporary ") << "ordered index "
- << name.c_str() << " (";
- else
- ndbout << "Creating " << ((logged)?"logged ": "temporary ") << "unique index "
- << name.c_str() << " (";
-
- NdbDictionary::Index pIdx(name.c_str());
- pIdx.setTable(pTab->getName());
- if (orderedIndex)
- pIdx.setType(NdbDictionary::Index::OrderedIndex);
- else
- pIdx.setType(NdbDictionary::Index::UniqueHashIndex);
- for (int c = 0; c< pTab->getNoOfColumns(); c++){
- const NdbDictionary::Column * col = pTab->getColumn(c);
- if(col->getPrimaryKey()){
- pIdx.addIndexColumn(col->getName());
- ndbout << col->getName() <<" ";
- }
- }
-
- pIdx.setStoredIndex(logged);
- ndbout << ") ";
- if (pNdb->getDictionary()->createIndex(pIdx) != 0){
- ndbout << "FAILED!" << endl;
- const NdbError err = pNdb->getDictionary()->getNdbError();
- ERR(err);
- return NDBT_FAILED;
- }
-
- ndbout << "OK!" << endl;
- return NDBT_OK;
-}
-
-static int run_create_pk_index_drop(NDBT_Context* ctx, NDBT_Step* step){
- bool orderedIndex = ctx->getProperty("OrderedIndex", (unsigned)0);
-
- Ndb* pNdb = GETNDB(step);
- const NdbDictionary::Table *pTab =
- pNdb->getDictionary()->getTable(ctx->getTab()->getName());
-
- if(!pTab)
- return NDBT_OK;
-
- BaseString name;
- name.assfmt("IND_%s_PK_%c", pTab->getName(), orderedIndex ? 'O' : 'U');
-
- ndbout << "Dropping index " << name.c_str() << " ";
- if (pNdb->getDictionary()->dropIndex(name.c_str(), pTab->getName()) != 0){
- ndbout << "FAILED!" << endl;
- ERR(pNdb->getDictionary()->getNdbError());
- return NDBT_FAILED;
- } else {
- ndbout << "OK!" << endl;
- }
-
- return NDBT_OK;
-}
-
-static int
-run_tests(Ndb* p_ndb, HugoTransactions& hugoTrans, int records)
-{
- if (hugoTrans.loadTable(p_ndb, records) != 0)
- {
- return NDBT_FAILED;
- }
-
- if(hugoTrans.pkReadRecords(p_ndb, records) != 0)
- {
- return NDBT_FAILED;
- }
-
- if(hugoTrans.pkUpdateRecords(p_ndb, records) != 0)
- {
- return NDBT_FAILED;
- }
-
- if(hugoTrans.pkDelRecords(p_ndb, records) != 0)
- {
- return NDBT_FAILED;
- }
-
- if (hugoTrans.loadTable(p_ndb, records) != 0)
- {
- return NDBT_FAILED;
- }
-
- if(hugoTrans.scanUpdateRecords(p_ndb, records) != 0)
- {
- return NDBT_FAILED;
- }
-
- Uint32 abort = 23;
- for(Uint32 j = 0; j<5; j++){
- Uint32 parallelism = (j == 1 ? 1 : j * 3);
- ndbout_c("parallelism: %d", parallelism);
- if (hugoTrans.scanReadRecords(p_ndb, records, abort, parallelism,
- NdbOperation::LM_Read) != 0)
- {
- return NDBT_FAILED;
- }
- if (hugoTrans.scanReadRecords(p_ndb, records, abort, parallelism,
- NdbOperation::LM_Exclusive) != 0)
- {
- return NDBT_FAILED;
- }
- if (hugoTrans.scanReadRecords(p_ndb, records, abort, parallelism,
- NdbOperation::LM_CommittedRead) != 0)
- {
- return NDBT_FAILED;
- }
- }
-
- if(hugoTrans.clearTable(p_ndb, records) != 0)
- {
- return NDBT_FAILED;
- }
-
- return 0;
-}
-
-static int
-run_pk_dk(NDBT_Context* ctx, NDBT_Step* step)
-{
- Ndb* p_ndb = GETNDB(step);
- int records = ctx->getNumRecords();
- const NdbDictionary::Table *tab =
- p_ndb->getDictionary()->getTable(ctx->getTab()->getName());
-
- if(!tab)
- return NDBT_OK;
-
- HugoTransactions hugoTrans(*tab);
-
- return run_tests(p_ndb, hugoTrans, records);
-}
-
-int
-run_index_dk(NDBT_Context* ctx, NDBT_Step* step)
-{
- Ndb* p_ndb = GETNDB(step);
- int records = ctx->getNumRecords();
- const NdbDictionary::Table *pTab =
- p_ndb->getDictionary()->getTable(ctx->getTab()->getName());
-
- if(!pTab)
- return NDBT_OK;
-
- bool orderedIndex = ctx->getProperty("OrderedIndex", (unsigned)0);
-
- BaseString name;
- name.assfmt("IND_%s_PK_%c", pTab->getName(), orderedIndex ? 'O' : 'U');
-
- const NdbDictionary::Index * idx =
- p_ndb->getDictionary()->getIndex(name.c_str(), pTab->getName());
-
- if(!idx)
- {
- ndbout << "Failed to retreive index: " << name.c_str() << endl;
- return NDBT_FAILED;
- }
-
- HugoTransactions hugoTrans(*pTab, idx);
-
- return run_tests(p_ndb, hugoTrans, records);
-}
-
-static int
-run_startHint(NDBT_Context* ctx, NDBT_Step* step)
-{
- Ndb* p_ndb = GETNDB(step);
- int records = ctx->getNumRecords();
- const NdbDictionary::Table *tab =
- p_ndb->getDictionary()->getTable(ctx->getTab()->getName());
-
- if(!tab)
- return NDBT_OK;
-
- HugoTransactions hugoTrans(*tab);
- if (hugoTrans.loadTable(p_ndb, records) != 0)
- {
- return NDBT_FAILED;
- }
-
- NdbRestarter restarter;
- if(restarter.insertErrorInAllNodes(8050) != 0)
- return NDBT_FAILED;
-
- HugoCalculator dummy(*tab);
- int result = NDBT_OK;
- for(int i = 0; i<records && result == NDBT_OK; i++)
- {
- char buffer[8000];
- char* start= buffer + (rand() & 7);
- char* pos= start;
-
- for(int j = 0; j<tab->getNoOfColumns(); j++)
- {
- if(tab->getColumn(j)->getPartitionKey())
- {
- ndbout_c(tab->getColumn(j)->getName());
- int sz = tab->getColumn(j)->getSizeInBytes();
- int aligned_size = 4 * ((sz + 3) >> 2);
- memset(pos, 0, aligned_size);
- Uint32 real_size;
- dummy.calcValue(i, j, 0, pos, sz, &real_size);
- pos += (real_size + 3) & ~3;
- }
- }
- // Now we have the pk
- NdbTransaction* pTrans= p_ndb->startTransaction(tab, start,(pos - start));
- HugoOperations ops(*tab);
- ops.setTransaction(pTrans);
- if(ops.pkReadRecord(p_ndb, i, 1) != NDBT_OK)
- {
- result = NDBT_FAILED;
- break;
- }
-
- if(ops.execute_Commit(p_ndb) != 0)
- {
- result = NDBT_FAILED;
- break;
- }
-
- ops.closeTransaction(p_ndb);
- }
- restarter.insertErrorInAllNodes(0);
- return result;
-}
-
-
-NDBT_TESTSUITE(testPartitioning);
-TESTCASE("pk_dk",
- "Primary key operations with distribution key")
-{
- TC_PROPERTY("distributionkey", ~0);
- INITIALIZER(run_drop_table);
- INITIALIZER(run_create_table);
- INITIALIZER(run_pk_dk);
- INITIALIZER(run_drop_table);
-}
-TESTCASE("hash_index_dk",
- "Unique index operatations with distribution key")
-{
- TC_PROPERTY("distributionkey", ~0);
- TC_PROPERTY("OrderedIndex", (unsigned)0);
- INITIALIZER(run_drop_table);
- INITIALIZER(run_create_table);
- INITIALIZER(run_create_pk_index);
- INITIALIZER(run_index_dk);
- INITIALIZER(run_create_pk_index_drop);
- INITIALIZER(run_drop_table);
-}
-TESTCASE("ordered_index_dk",
- "Ordered index operatations with distribution key")
-{
- TC_PROPERTY("distributionkey", (unsigned)1);
- TC_PROPERTY("OrderedIndex", (unsigned)1);
- INITIALIZER(run_drop_table);
- INITIALIZER(run_create_table);
- INITIALIZER(run_create_pk_index);
- INITIALIZER(run_index_dk);
- INITIALIZER(run_create_pk_index_drop);
- INITIALIZER(run_drop_table);
-}
-TESTCASE("startTransactionHint",
- "Test startTransactionHint wo/ distribution key")
-{
- TC_PROPERTY("distributionkey", (unsigned)0);
- INITIALIZER(run_drop_table);
- INITIALIZER(run_create_table);
- INITIALIZER(run_startHint);
- INITIALIZER(run_drop_table);
-}
-TESTCASE("startTransactionHint_dk",
- "Test startTransactionHint with distribution key")
-{
- TC_PROPERTY("distributionkey", (unsigned)~0);
- INITIALIZER(run_drop_table);
- INITIALIZER(run_create_table);
- INITIALIZER(run_startHint);
- INITIALIZER(run_drop_table);
-}
-NDBT_TESTSUITE_END(testPartitioning);
-
-int main(int argc, const char** argv){
- ndb_init();
- testPartitioning.setCreateTable(false);
- return testPartitioning.execute(argc, argv);
-}
-
-
-
diff --git a/storage/ndb/test/ndbapi/testReadPerf.cpp b/storage/ndb/test/ndbapi/testReadPerf.cpp
deleted file mode 100644
index dae48900a16..00000000000
--- a/storage/ndb/test/ndbapi/testReadPerf.cpp
+++ /dev/null
@@ -1,409 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT.hpp>
-#include <NDBT_Test.hpp>
-#include <HugoTransactions.hpp>
-#include <UtilTransactions.hpp>
-#include <random.h>
-#include <getarg.h>
-
-struct Parameter {
- const char * name;
- unsigned value;
- unsigned min;
- unsigned max;
-};
-
-#define P_OPER 0
-#define P_RANGE 1
-#define P_ROWS 2
-#define P_LOOPS 3
-#define P_CREATE 4
-#define P_LOAD 5
-
-#define P_MAX 6
-
-/**
- * operation
- * 0 - serial pk
- * 1 - batch pk
- * 2 - serial uniq
- * 3 - batch uniq
- * 4 - index eq
- * 5 - range scan
- * 6 - ordered range scan
- * 7 - interpreted scan
- */
-static const char * g_ops[] = {
- "serial pk",
- "batch pk",
- "serial uniq index access",
- "batch uniq index access",
- "index eq-bound",
- "index range",
- "index ordered",
- "interpreted scan"
-};
-
-#define P_OP_TYPES 8
-static Uint64 g_times[P_OP_TYPES];
-
-static
-Parameter
-g_paramters[] = {
- { "operation", 0, 0, 6 }, // 0
- { "range", 1000, 1, ~0 },// 1 no of rows to read
- { "size", 1000000, 1, ~0 },// 2 rows in tables
- { "iterations", 3, 1, ~0 },// 3
- { "create_drop", 0, 0, 1 }, // 4
- { "data", 0, 0, 1 } // 5
-};
-
-static Ndb* g_ndb = 0;
-static const NdbDictionary::Table * g_tab;
-static const NdbDictionary::Index * g_i_unique;
-static const NdbDictionary::Index * g_i_ordered;
-static char g_table[256];
-static char g_unique[256];
-static char g_ordered[256];
-static char g_buffer[2*1024*1024];
-
-int create_table();
-int load_table();
-int run_read();
-int clear_table();
-int drop_table();
-void print_result();
-
-int
-main(int argc, const char** argv){
- ndb_init();
- int verbose = 1;
- int optind = 0;
-
- struct getargs args[1+P_MAX] = {
- { "verbose", 'v', arg_flag, &verbose, "Print verbose status", "verbose" }
- };
- const int num_args = 1 + P_MAX;
- int i;
- for(i = 0; i<P_MAX; i++){
- args[i+1].long_name = g_paramters[i].name;
- args[i+1].short_name = * g_paramters[i].name;
- args[i+1].type = arg_integer;
- args[i+1].value = &g_paramters[i].value;
- BaseString tmp;
- tmp.assfmt("min: %d max: %d", g_paramters[i].min, g_paramters[i].max);
- args[i+1].help = strdup(tmp.c_str());
- args[i+1].arg_help = 0;
- }
-
- if(getarg(args, num_args, argc, argv, &optind)) {
- arg_printusage(args, num_args, argv[0], "tabname1 tabname2 ...");
- return NDBT_WRONGARGS;
- }
-
- myRandom48Init(NdbTick_CurrentMillisecond());
- memset(g_times, 0, sizeof(g_times));
-
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1))
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- g_ndb = new Ndb(&con, "TEST_DB");
- if(g_ndb->init() != 0){
- g_err << "init() failed" << endl;
- goto error;
- }
- if(g_ndb->waitUntilReady() != 0){
- g_err << "Wait until ready failed" << endl;
- goto error;
- }
- for(i = optind; i<argc; i++){
- const char * T = argv[i];
- g_info << "Testing " << T << endl;
- BaseString::snprintf(g_table, sizeof(g_table), T);
- BaseString::snprintf(g_ordered, sizeof(g_ordered), "IDX_O_%s", T);
- BaseString::snprintf(g_unique, sizeof(g_unique), "IDX_U_%s", T);
- if(create_table())
- goto error;
- if(load_table())
- goto error;
- for(int l = 0; l<g_paramters[P_LOOPS].value; l++){
- for(int j = 0; j<P_OP_TYPES; j++){
- g_paramters[P_OPER].value = j;
- if(run_read())
- goto error;
- }
- }
- print_result();
- }
-
- if(g_ndb) delete g_ndb;
- return NDBT_OK;
-error:
- if(g_ndb) delete g_ndb;
- return NDBT_FAILED;
-}
-
-int
-create_table(){
- NdbDictionary::Dictionary* dict = g_ndb->getDictionary();
- assert(dict);
- if(g_paramters[P_CREATE].value){
- const NdbDictionary::Table * pTab = NDBT_Tables::getTable(g_table);
- assert(pTab);
- NdbDictionary::Table copy = * pTab;
- copy.setLogging(false);
- if(dict->createTable(copy) != 0){
- g_err << "Failed to create table: " << g_table << endl;
- return -1;
- }
-
- NdbDictionary::Index x(g_ordered);
- x.setTable(g_table);
- x.setType(NdbDictionary::Index::OrderedIndex);
- x.setLogging(false);
- for (unsigned k = 0; k < copy.getNoOfColumns(); k++){
- if(copy.getColumn(k)->getPrimaryKey()){
- x.addColumn(copy.getColumn(k)->getName());
- }
- }
-
- if(dict->createIndex(x) != 0){
- g_err << "Failed to create index: " << endl;
- return -1;
- }
-
- x.setName(g_unique);
- x.setType(NdbDictionary::Index::UniqueHashIndex);
- if(dict->createIndex(x) != 0){
- g_err << "Failed to create index: " << endl;
- return -1;
- }
- }
- g_tab = dict->getTable(g_table);
- g_i_unique = dict->getIndex(g_unique, g_table);
- g_i_ordered = dict->getIndex(g_ordered, g_table);
- assert(g_tab);
- assert(g_i_unique);
- assert(g_i_ordered);
- return 0;
-}
-
-int
-drop_table(){
- if(!g_paramters[P_CREATE].value)
- return 0;
- if(g_ndb->getDictionary()->dropTable(g_tab->getName()) != 0){
- g_err << "Failed to drop table: " << g_tab->getName() << endl;
- return -1;
- }
- g_tab = 0;
- return 0;
-}
-
-int
-load_table(){
- if(!g_paramters[P_LOAD].value)
- return 0;
-
- int rows = g_paramters[P_ROWS].value;
- HugoTransactions hugoTrans(* g_tab);
- if (hugoTrans.loadTable(g_ndb, rows)){
- g_err.println("Failed to load %s with %d rows", g_tab->getName(), rows);
- return -1;
- }
- return 0;
-}
-
-int
-clear_table(){
- if(!g_paramters[P_LOAD].value)
- return 0;
- int rows = g_paramters[P_ROWS].value;
-
- UtilTransactions utilTrans(* g_tab);
- if (utilTrans.clearTable(g_ndb, rows) != 0){
- g_err.println("Failed to clear table %s", g_tab->getName());
- return -1;
- }
- return 0;
-}
-
-inline
-void err(NdbError e){
- ndbout << e << endl;
-}
-
-int
-run_read(){
- int iter = g_paramters[P_LOOPS].value;
- NDB_TICKS start1, stop;
- int sum_time= 0;
-
- const Uint32 rows = g_paramters[P_ROWS].value;
- const Uint32 range = g_paramters[P_RANGE].value;
-
- start1 = NdbTick_CurrentMillisecond();
- NdbConnection * pTrans = g_ndb->startTransaction();
- if(!pTrans){
- g_err << "Failed to start transaction" << endl;
- err(g_ndb->getNdbError());
- return -1;
- }
-
- NdbOperation * pOp;
- NdbScanOperation * pSp;
- NdbIndexOperation * pUp;
- NdbIndexScanOperation * pIp;
-
- Uint32 start_row = rand() % (rows - range);
- Uint32 stop_row = start_row + range;
-
- /**
- * 0 - serial pk
- * 1 - batch pk
- * 2 - serial uniq
- * 3 - batch uniq
- * 4 - index eq
- * 5 - range scan
- * 6 - interpreted scan
- */
- int check = 0;
- void* res = (void*)~0;
- const Uint32 pk = 0;
- Uint32 cnt = 0;
- for(; start_row < stop_row; start_row++){
- switch(g_paramters[P_OPER].value){
- case 0:
- pOp = pTrans->getNdbOperation(g_table);
- check = pOp->readTuple();
- check = pOp->equal(pk, start_row);
- break;
- case 1:
- for(; start_row<stop_row; start_row++){
- pOp = pTrans->getNdbOperation(g_table);
- check = pOp->readTuple();
- check = pOp->equal(pk, start_row);
- for(int j = 0; j<g_tab->getNoOfColumns(); j++){
- res = pOp->getValue(j);
- assert(res);
- }
- }
- break;
- case 2:
- pOp = pTrans->getNdbIndexOperation(g_unique, g_table);
- check = pOp->readTuple();
- check = pOp->equal(pk, start_row);
- break;
- case 3:
- for(; start_row<stop_row; start_row++){
- pOp = pTrans->getNdbIndexOperation(g_unique, g_table);
- check = pOp->readTuple();
- check = pOp->equal(pk, start_row);
- for(int j = 0; j<g_tab->getNoOfColumns(); j++){
- res = pOp->getValue(j);
- assert(res);
- }
- }
- break;
- case 4:
- pOp = pSp = pIp = pTrans->getNdbIndexScanOperation(g_ordered,g_table);
- pIp->readTuples(NdbScanOperation::LM_CommittedRead, 0, 0);
- check = pIp->setBound(pk, NdbIndexScanOperation::BoundEQ, &start_row);
- break;
- case 5:
- pOp = pSp = pIp = pTrans->getNdbIndexScanOperation(g_ordered,g_table);
- pIp->readTuples(NdbScanOperation::LM_CommittedRead, 0, 0);
- check = pIp->setBound(pk, NdbIndexScanOperation::BoundLE, &start_row);
- check = pIp->setBound(pk, NdbIndexScanOperation::BoundGT, &stop_row);
- start_row = stop_row;
- break;
- case 6:
- pOp = pSp = pIp = pTrans->getNdbIndexScanOperation(g_ordered,g_table);
- pIp->readTuples(NdbScanOperation::LM_CommittedRead, 0, 0, true);
- check = pIp->setBound(pk, NdbIndexScanOperation::BoundLE, &start_row);
- check = pIp->setBound(pk, NdbIndexScanOperation::BoundGT, &stop_row);
- start_row = stop_row;
- break;
- case 7:
- pOp = pSp = pTrans->getNdbScanOperation(g_table);
- pSp->readTuples(NdbScanOperation::LM_CommittedRead, 0, 0);
- NdbScanFilter filter(pOp) ;
- filter.begin(NdbScanFilter::AND);
- filter.ge(pk, start_row);
- filter.lt(pk, stop_row);
- filter.end();
- start_row = stop_row;
- break;
- }
-
- assert(res);
- if(check != 0){
- ndbout << pOp->getNdbError() << endl;
- ndbout << pTrans->getNdbError() << endl;
- }
- assert(check == 0);
-
- for(int j = 0; j<g_tab->getNoOfColumns(); j++){
- res = pOp->getValue(j);
- assert(res);
- }
-
- check = pTrans->execute(NoCommit);
- if(check != 0){
- ndbout << pTrans->getNdbError() << endl;
- }
- assert(check == 0);
- if(g_paramters[P_OPER].value >= 4){
- while((check = pSp->nextResult(true)) == 0){
- cnt++;
- }
-
- if(check == -1){
- err(pTrans->getNdbError());
- return -1;
- }
- assert(check == 1);
- pSp->close();
- }
- }
- assert(g_paramters[P_OPER].value < 4 || (cnt == range));
-
- pTrans->close();
-
- stop = NdbTick_CurrentMillisecond();
- g_times[g_paramters[P_OPER].value] += (stop - start1);
- return 0;
-}
-
-void
-print_result(){
- int tmp = 1;
- tmp *= g_paramters[P_RANGE].value;
- tmp *= g_paramters[P_LOOPS].value;
-
- int t, t2;
- for(int i = 0; i<P_OP_TYPES; i++){
- g_err << g_ops[i] << " avg: "
- << (int)((1000*g_times[i])/tmp)
- << " us/row ("
- << (1000 * tmp)/g_times[i] << " rows / sec)" << endl;
- }
-}
diff --git a/storage/ndb/test/ndbapi/testRestartGci.cpp b/storage/ndb/test/ndbapi/testRestartGci.cpp
deleted file mode 100644
index 423f7c53037..00000000000
--- a/storage/ndb/test/ndbapi/testRestartGci.cpp
+++ /dev/null
@@ -1,222 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include "NDBT_Test.hpp"
-#include "NDBT_ReturnCodes.h"
-#include "HugoTransactions.hpp"
-#include "UtilTransactions.hpp"
-#include "NdbRestarter.hpp"
-
-
-/**
- * Global vector to keep track of
- * records stored in db
- */
-
-struct SavedRecord {
- int m_gci;
- BaseString m_str;
- SavedRecord(int _gci, BaseString _str){
- m_gci = _gci;
- m_str.assign(_str);
- }
- SavedRecord(){
- m_gci = 0;
- m_str = "";
- };
-};
-Vector<SavedRecord> savedRecords;
-
-
-#define CHECK(b) if (!(b)) { \
- ndbout << "ERR: "<< step->getName() \
- << " failed on line " << __LINE__ << endl; \
- result = NDBT_FAILED; \
- break; }
-
-int runInsertRememberGci(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int records = ctx->getNumRecords();
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
- int i = 0;
-
- while(ctx->isTestStopped() == false && i < records){
- // Insert record and read it in same transaction
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkInsertRecord(pNdb, i) == 0);
- if (hugoOps.execute_NoCommit(pNdb) != 0){
- ndbout << "Could not insert record " << i << endl;
- result = NDBT_FAILED;
- break;
- }
- CHECK(hugoOps.pkReadRecord(pNdb, i) == 0);
- if (hugoOps.execute_Commit(pNdb) != 0){
- ndbout << "Did not find record in DB " << i << endl;
- result = NDBT_FAILED;
- break;
- }
- savedRecords.push_back(SavedRecord(hugoOps.getRecordGci(0),
- hugoOps.getRecordStr(0)));
-
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
- i++;
- };
-
- return result;
-}
-
-int runRestartGciControl(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
- Ndb* pNdb = GETNDB(step);
- UtilTransactions utilTrans(*ctx->getTab());
- NdbRestarter restarter;
-
- // Wait until we have enough records in db
- int count = 0;
- while (count < records){
- if (utilTrans.selectCount(pNdb, 64, &count) != 0){
- ctx->stopTest();
- return NDBT_FAILED;
- }
- }
-
- // Restart cluster with abort
- if (restarter.restartAll(false, false, true) != 0){
- ctx->stopTest();
- return NDBT_FAILED;
- }
-
- // Stop the other thread
- ctx->stopTest();
-
- if (restarter.waitClusterStarted(300) != 0){
- return NDBT_FAILED;
- }
-
- if (pNdb->waitUntilReady() != 0){
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-int runVerifyInserts(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- Ndb* pNdb = GETNDB(step);
- UtilTransactions utilTrans(*ctx->getTab());
- HugoOperations hugoOps(*ctx->getTab());
- NdbRestarter restarter;
-
- int restartGCI = pNdb->NdbTamper(Ndb::ReadRestartGCI, 0);
-
- ndbout << "restartGCI = " << restartGCI << endl;
- int count = 0;
- if (utilTrans.selectCount(pNdb, 64, &count) != 0){
- return NDBT_FAILED;
- }
-
- // RULE1: The vector with saved records should have exactly as many
- // records with lower or same gci as there are in DB
- int recordsWithLowerOrSameGci = 0;
- unsigned i;
- for (i = 0; i < savedRecords.size(); i++){
- if (savedRecords[i].m_gci <= restartGCI)
- recordsWithLowerOrSameGci++;
- }
- if (recordsWithLowerOrSameGci != count){
- ndbout << "ERR: Wrong number of expected records" << endl;
- result = NDBT_FAILED;
- }
-
-
- // RULE2: The records found in db should have same or lower
- // gci as in the vector
- for (i = 0; i < savedRecords.size(); i++){
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, i) == 0);
- if (hugoOps.execute_Commit(pNdb) != 0){
- // Record was not found in db'
-
- // Check record gci
- if (savedRecords[i].m_gci <= restartGCI){
- ndbout << "ERR: Record "<<i<<" should have existed" << endl;
- result = NDBT_FAILED;
- }
- } else {
- // Record was found in db
- BaseString str = hugoOps.getRecordStr(0);
- // Check record string
- if (!(savedRecords[i].m_str == str)){
- ndbout << "ERR: Record "<<i<<" str did not match "<< endl;
- result = NDBT_FAILED;
- }
- // Check record gci
- if (savedRecords[i].m_gci > restartGCI){
- ndbout << "ERR: Record "<<i<<" should not have existed" << endl;
- result = NDBT_FAILED;
- }
- }
-
- CHECK(hugoOps.closeTransaction(pNdb) == 0);
- }
-
-
- ndbout << "There are " << count << " records in db" << endl;
- ndbout << "There are " << savedRecords.size()
- << " records in vector" << endl;
-
- ndbout << "There are " << recordsWithLowerOrSameGci
- << " records with lower or same gci than " << restartGCI << endl;
-
- return result;
-}
-
-int runClearGlobals(NDBT_Context* ctx, NDBT_Step* step){
- savedRecords.clear();
- return NDBT_OK;
-}
-
-int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
-
- UtilTransactions utilTrans(*ctx->getTab());
- if (utilTrans.clearTable2(GETNDB(step), records, 240) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-
-NDBT_TESTSUITE(testRestartGci);
-TESTCASE("InsertRestartGci",
- "Verify that only expected records are still in NDB\n"
- "after a restart" ){
- INITIALIZER(runClearTable);
- INITIALIZER(runClearGlobals);
- STEP(runInsertRememberGci);
- STEP(runRestartGciControl);
- VERIFIER(runVerifyInserts);
- FINALIZER(runClearTable);
-}
-NDBT_TESTSUITE_END(testRestartGci);
-
-int main(int argc, const char** argv){
- ndb_init();
- return testRestartGci.execute(argc, argv);
-}
-
-template class Vector<SavedRecord>;
diff --git a/storage/ndb/test/ndbapi/testSRBank.cpp b/storage/ndb/test/ndbapi/testSRBank.cpp
deleted file mode 100644
index 64fd5b84fb9..00000000000
--- a/storage/ndb/test/ndbapi/testSRBank.cpp
+++ /dev/null
@@ -1,298 +0,0 @@
-/* Copyright (c) 2003, 2005-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT.hpp>
-#include <NDBT_Test.hpp>
-#include <HugoTransactions.hpp>
-#include <UtilTransactions.hpp>
-#include <NdbBackup.hpp>
-
-#include "bank/Bank.hpp"
-#include <NdbMixRestarter.hpp>
-
-bool disk = false;
-
-#define CHECK(b) if (!(b)) { \
- g_err << "ERR: "<< step->getName() \
- << " failed on line " << __LINE__ << endl; \
- result = NDBT_FAILED; \
- continue; }
-
-int runCreateBank(NDBT_Context* ctx, NDBT_Step* step){
- Bank bank(ctx->m_cluster_connection);
- int overWriteExisting = true;
- if (bank.createAndLoadBank(overWriteExisting, disk, 10) != NDBT_OK)
- return NDBT_FAILED;
- return NDBT_OK;
-}
-
-/**
- *
- * SR 0 - normal
- * SR 1 - shutdown in progress
- * SR 2 - restart in progress
- */
-int
-runBankTimer(NDBT_Context* ctx, NDBT_Step* step){
- int wait = 5; // Max seconds between each "day"
- int yield = 1; // Loops before bank returns
-
- ctx->incProperty(NMR_SR_THREADS);
- while (!ctx->isTestStopped())
- {
- Bank bank(ctx->m_cluster_connection);
- while(!ctx->isTestStopped() &&
- ctx->getProperty(NMR_SR) <= NdbMixRestarter::SR_STOPPING)
- {
- if(bank.performIncreaseTime(wait, yield) == NDBT_FAILED)
- break;
- }
-
- ndbout_c("runBankTimer is stopped");
- ctx->incProperty(NMR_SR_THREADS_STOPPED);
- if(ctx->getPropertyWait(NMR_SR, NdbMixRestarter::SR_RUNNING))
- break;
- }
- return NDBT_OK;
-}
-
-int runBankTransactions(NDBT_Context* ctx, NDBT_Step* step){
- int wait = 0; // Max ms between each transaction
- int yield = 1; // Loops before bank returns
-
- ctx->incProperty(NMR_SR_THREADS);
- while (!ctx->isTestStopped())
- {
- Bank bank(ctx->m_cluster_connection);
- while(!ctx->isTestStopped() &&
- ctx->getProperty(NMR_SR) <= NdbMixRestarter::SR_STOPPING)
- if(bank.performTransactions(0, 1) == NDBT_FAILED)
- break;
-
- ndbout_c("runBankTransactions is stopped");
- ctx->incProperty(NMR_SR_THREADS_STOPPED);
- if(ctx->getPropertyWait(NMR_SR, NdbMixRestarter::SR_RUNNING))
- break;
- }
- return NDBT_OK;
-}
-
-int runBankGL(NDBT_Context* ctx, NDBT_Step* step){
- int yield = 1; // Loops before bank returns
- int result = NDBT_OK;
-
- ctx->incProperty(NMR_SR_THREADS);
- while (ctx->isTestStopped() == false)
- {
- Bank bank(ctx->m_cluster_connection);
- while(!ctx->isTestStopped() &&
- ctx->getProperty(NMR_SR) <= NdbMixRestarter::SR_STOPPING)
- if (bank.performMakeGLs(yield) != NDBT_OK)
- {
- if(ctx->getProperty(NMR_SR) != NdbMixRestarter::SR_RUNNING)
- break;
- ndbout << "bank.performMakeGLs FAILED" << endl;
- abort();
- return NDBT_FAILED;
- }
-
- ndbout_c("runBankGL is stopped");
- ctx->incProperty(NMR_SR_THREADS_STOPPED);
- if(ctx->getPropertyWait(NMR_SR, NdbMixRestarter::SR_RUNNING))
- break;
- }
- return NDBT_OK;
-}
-
-int
-runBankSrValidator(NDBT_Context* ctx, NDBT_Step* step)
-{
-
- ctx->incProperty(NMR_SR_VALIDATE_THREADS);
-
- while(!ctx->isTestStopped())
- {
- if (ctx->getPropertyWait(NMR_SR, NdbMixRestarter::SR_VALIDATING))
- break;
-
- int wait = 0;
- int yield = 1;
- Bank bank(ctx->m_cluster_connection);
- if (bank.performSumAccounts(wait, yield) != 0)
- {
- ndbout << "bank.performSumAccounts FAILED" << endl;
- abort();
- return NDBT_FAILED;
- }
-
- if (bank.performValidateAllGLs() != 0)
- {
- ndbout << "bank.performValidateAllGLs FAILED" << endl;
- abort();
- return NDBT_FAILED;
- }
-
- ctx->incProperty(NMR_SR_VALIDATE_THREADS_DONE);
-
- if (ctx->getPropertyWait(NMR_SR, NdbMixRestarter::SR_RUNNING))
- break;
- }
-
- return NDBT_OK;
-}
-
-#if 0
-int runBankSum(NDBT_Context* ctx, NDBT_Step* step){
- Bank bank(ctx->m_cluster_connection);
- int wait = 2000; // Max ms between each sum of accounts
- int yield = 1; // Loops before bank returns
- int result = NDBT_OK;
-
- while (ctx->isTestStopped() == false)
- {
- if (bank.performSumAccounts(wait, yield) != NDBT_OK){
- ndbout << "bank.performSumAccounts FAILED" << endl;
- result = NDBT_FAILED;
- }
- }
- return result ;
-}
-#endif
-
-
-int
-runMixRestart(NDBT_Context* ctx, NDBT_Step* step)
-{
- int result = NDBT_OK;
- NdbMixRestarter res;
- int runtime = ctx->getNumLoops();
- int sleeptime = ctx->getNumRecords();
- Uint32 mask = ctx->getProperty("Type", ~(Uint32)0);
- res.setRestartTypeMask(mask);
-
- if (res.runPeriod(ctx, step, runtime, sleeptime))
- {
- abort();
- return NDBT_FAILED;
- }
-
- ctx->stopTest();
- return NDBT_OK;
-}
-
-int
-runDropBank(NDBT_Context* ctx, NDBT_Step* step){
- Bank bank(ctx->m_cluster_connection);
- if (bank.dropBank() != NDBT_OK)
- return NDBT_FAILED;
- return NDBT_OK;
-}
-
-
-NDBT_TESTSUITE(testSRBank);
-TESTCASE("SR",
- " Test that a consistent bank is restored after graceful shutdown\n"
- "1. Create bank\n"
- "2. Start bank and let it run\n"
- "3. Restart ndb and verify consistency\n"
- "4. Drop bank\n")
-{
- TC_PROPERTY("Type", NdbMixRestarter::RTM_SR);
- INITIALIZER(runCreateBank);
- STEP(runBankTimer);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankGL);
- STEP(runBankSrValidator);
- STEP(runMixRestart);
-}
-TESTCASE("NR",
- " Test that a consistent bank is restored after graceful shutdown\n"
- "1. Create bank\n"
- "2. Start bank and let it run\n"
- "3. Restart ndb and verify consistency\n"
- "4. Drop bank\n")
-{
- TC_PROPERTY("Type", NdbMixRestarter::RTM_NR);
- INITIALIZER(runCreateBank);
- STEP(runBankTimer);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankGL);
- STEP(runMixRestart);
- FINALIZER(runDropBank);
-}
-TESTCASE("Mix",
- " Test that a consistent bank is restored after graceful shutdown\n"
- "1. Create bank\n"
- "2. Start bank and let it run\n"
- "3. Restart ndb and verify consistency\n"
- "4. Drop bank\n")
-{
- TC_PROPERTY("Type", NdbMixRestarter::RTM_ALL);
- INITIALIZER(runCreateBank);
- STEP(runBankTimer);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankTransactions);
- STEP(runBankGL);
- STEP(runMixRestart);
- STEP(runBankSrValidator);
- FINALIZER(runDropBank);
-}
-NDBT_TESTSUITE_END(testSRBank);
-
-int
-main(int argc, const char** argv){
- ndb_init();
- for (int i = 0; i<argc; i++)
- {
- if (strcmp(argv[i], "--disk") == 0)
- {
- argc--;
- disk = true;
- for (; i<argc; i++)
- argv[i] = argv[i+1];
- break;
- }
- }
- return testSRBank.execute(argc, argv);
-}
-
-template class Vector<ndb_mgm_node_state*>;
diff --git a/storage/ndb/test/ndbapi/testScan.cpp b/storage/ndb/test/ndbapi/testScan.cpp
deleted file mode 100644
index e29a52ff788..00000000000
--- a/storage/ndb/test/ndbapi/testScan.cpp
+++ /dev/null
@@ -1,1757 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT.hpp>
-#include <NDBT_Test.hpp>
-#include <HugoTransactions.hpp>
-#include <UtilTransactions.hpp>
-#include <NdbRestarter.hpp>
-#include <Vector.hpp>
-#include "ScanFunctions.hpp"
-#include <random.h>
-
-const NdbDictionary::Table *
-getTable(Ndb* pNdb, int i){
- const NdbDictionary::Table* t = NDBT_Tables::getTable(i);
- if (t == NULL){
- return 0;
- }
- return pNdb->getDictionary()->getTable(t->getName());
-}
-
-
-int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
-
- int records = ctx->getProperty("Rows", ctx->getNumRecords());
-
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.loadTable(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-
-int runCreateAllTables(NDBT_Context* ctx, NDBT_Step* step){
-
- int a = NDBT_Tables::createAllTables(GETNDB(step), false, true);
- return a;
-}
-
-int runDropAllTablesExceptTestTable(NDBT_Context* ctx, NDBT_Step* step){
-
- for (int i=0; i < NDBT_Tables::getNumTables(); i++){
-
- const NdbDictionary::Table* tab = NDBT_Tables::getTable(i);
- if (tab == NULL){
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- // Don't drop test table
- if (strcmp(tab->getName(), ctx->getTab()->getName()) == 0){
- continue;
- }
-
- int res = GETNDB(step)->getDictionary()->dropTable(tab->getName());
- if(res == -1){
- return NDBT_FAILED;
- }
- }
- return NDBT_OK;
-}
-
-
-int runLoadAllTables(NDBT_Context* ctx, NDBT_Step* step){
-
- int records = ctx->getNumRecords();
- for (int i=0; i < NDBT_Tables::getNumTables(); i++){
-
- const NdbDictionary::Table* tab = getTable(GETNDB(step), i);
- if (tab == NULL){
- return NDBT_FAILED;
- }
- HugoTransactions hugoTrans(*tab);
- if (hugoTrans.loadTable(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- }
- return NDBT_OK;
-}
-
-char orderedPkIdxName[255];
-
-int createOrderedPkIndex(NDBT_Context* ctx, NDBT_Step* step){
-
- const NdbDictionary::Table* pTab = ctx->getTab();
- Ndb* pNdb = GETNDB(step);
-
- // Create index
- BaseString::snprintf(orderedPkIdxName, sizeof(orderedPkIdxName),
- "IDC_O_PK_%s", pTab->getName());
- NdbDictionary::Index pIdx(orderedPkIdxName);
- pIdx.setTable(pTab->getName());
- pIdx.setType(NdbDictionary::Index::OrderedIndex);
- pIdx.setLogging(false);
-
- for (int c = 0; c< pTab->getNoOfColumns(); c++){
- const NdbDictionary::Column * col = pTab->getColumn(c);
- if(col->getPrimaryKey()){
- pIdx.addIndexColumn(col->getName());
- }
- }
-
- if (pNdb->getDictionary()->createIndex(pIdx) != 0){
- ndbout << "FAILED! to create index" << endl;
- const NdbError err = pNdb->getDictionary()->getNdbError();
- ERR(err);
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-int createOrderedPkIndex_Drop(NDBT_Context* ctx, NDBT_Step* step){
- const NdbDictionary::Table* pTab = ctx->getTab();
- Ndb* pNdb = GETNDB(step);
-
- // Drop index
- if (pNdb->getDictionary()->dropIndex(orderedPkIdxName,
- pTab->getName()) != 0){
- ndbout << "FAILED! to drop index" << endl;
- ERR(pNdb->getDictionary()->getNdbError());
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-
-int runScanReadRandomTable(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int parallelism = ctx->getProperty("Parallelism", 240);
- int abort = ctx->getProperty("AbortProb", 5);
-
- int i = 0;
- while (i<loops) {
-
- int tabNum = myRandom48(NDBT_Tables::getNumTables());
- const NdbDictionary::Table* tab = getTable(GETNDB(step), tabNum);
- if (tab == NULL){
- g_info << "tab == NULL" << endl;
- return NDBT_FAILED;
- }
-
- g_info << "Scan reading from table " << tab->getName() << endl;
- HugoTransactions hugoTrans(*tab);
-
- g_info << i << ": ";
- if (hugoTrans.scanReadRecords(GETNDB(step), records, abort, parallelism) != 0){
- return NDBT_FAILED;
- }
- i++;
- }
- return NDBT_OK;
-}
-
-int runInsertUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
- int i = 0;
- HugoTransactions hugoTrans(*ctx->getTab());
- while (ctx->isTestStopped() == false) {
- g_info << i << ": ";
- if (hugoTrans.loadTable(GETNDB(step), records, 1) != 0){
- return NDBT_FAILED;
- }
- i++;
- }
- return NDBT_OK;
-}
-
-int runInsertDelete(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int records = ctx->getNumRecords();
- int loops = ctx->getNumLoops();
- int i = 0;
- HugoTransactions hugoTrans(*ctx->getTab());
- UtilTransactions utilTrans(*ctx->getTab());
- while (i<loops) {
- g_info << i << ": ";
- if (hugoTrans.loadTable(GETNDB(step), records, 1) != 0){
- result = NDBT_FAILED;
- break;
- }
- if (utilTrans.clearTable(GETNDB(step), records) != 0){
- result = NDBT_FAILED;
- break;
- }
- i++;
- }
-
- ctx->stopTest();
-
- return result;
-}
-
-int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
-
- UtilTransactions utilTrans(*ctx->getTab());
- if (utilTrans.clearTable2(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runScanDelete(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
-
- int i = 0;
- UtilTransactions utilTrans(*ctx->getTab());
- HugoTransactions hugoTrans(*ctx->getTab());
- while (i<loops) {
- g_info << i << ": ";
- if (utilTrans.clearTable(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- // Load table, don't allow any primary key violations
- if (hugoTrans.loadTable(GETNDB(step), records, 512, false) != 0){
- return NDBT_FAILED;
- }
- i++;
- }
- return NDBT_OK;
-}
-
-int runScanDelete2(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
-
- int i = 0;
- UtilTransactions utilTrans(*ctx->getTab());
- HugoTransactions hugoTrans(*ctx->getTab());
-
- while (i<loops) {
- g_info << i << ": ";
- if (utilTrans.clearTable2(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- // Load table, don't allow any primary key violations
- if (hugoTrans.loadTable(GETNDB(step), records, 512, false) != 0){
- return NDBT_FAILED;
- }
- i++;
- }
- return NDBT_OK;
-}
-
-int runVerifyTable(NDBT_Context* ctx, NDBT_Step* step){
- return NDBT_OK;
-}
-
-int runScanRead(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops();
- int records = ctx->getProperty("Rows", ctx->getNumRecords());
- int parallelism = ctx->getProperty("Parallelism", 240);
- int abort = ctx->getProperty("AbortProb", 5);
-
- int i = 0;
- HugoTransactions hugoTrans(*ctx->getTab());
- while (i<loops && !ctx->isTestStopped()) {
- g_info << i << ": ";
- if (hugoTrans.scanReadRecords(GETNDB(step), records, abort, parallelism) != 0){
- return NDBT_FAILED;
- }
- i++;
- }
- return NDBT_OK;
-}
-
-int runRandScanRead(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int parallelism = ctx->getProperty("Parallelism", 240);
- int abort = ctx->getProperty("AbortProb", 5);
- int tupscan = ctx->getProperty("TupScan", (Uint32)0);
-
- int i = 0;
- HugoTransactions hugoTrans(*ctx->getTab());
- while (i<loops && !ctx->isTestStopped()) {
- g_info << i << ": ";
- NdbOperation::LockMode lm = (NdbOperation::LockMode)(rand() % 3);
- int scan_flags = 0;
-
- if (tupscan == 1)
- scan_flags |= NdbScanOperation::SF_TupScan;
- else if (tupscan == 2 && ((rand() & 0x800)))
- {
- scan_flags |= NdbScanOperation::SF_TupScan;
- }
-
- if (hugoTrans.scanReadRecords(GETNDB(step),
- records, abort, parallelism,
- lm,
- scan_flags) != 0){
- return NDBT_FAILED;
- }
- i++;
- }
- return NDBT_OK;
-}
-
-int runScanReadIndex(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int parallelism = ctx->getProperty("Parallelism", 240);
- int abort = ctx->getProperty("AbortProb", 5);
- const NdbDictionary::Index * pIdx =
- GETNDB(step)->getDictionary()->getIndex(orderedPkIdxName,
- ctx->getTab()->getName());
-
- int i = 0;
- HugoTransactions hugoTrans(*ctx->getTab());
- while (pIdx && i<loops && !ctx->isTestStopped()) {
- g_info << i << ": ";
- bool sort = (rand() % 100) > 50 ? true : false;
- bool desc = (rand() % 100) > 50 ? true : false;
- desc = false; // random causes too many deadlocks
- int scan_flags =
- (NdbScanOperation::SF_OrderBy & -(int)sort) |
- (NdbScanOperation::SF_Descending & -(int)desc);
- NdbOperation::LockMode lm = (NdbOperation::LockMode)(rand() % 3);
- if (hugoTrans.scanReadRecords(GETNDB(step), pIdx,
- records, abort, parallelism,
- lm,
- scan_flags) != 0){
- return NDBT_FAILED;
- }
- i++;
- }
- return NDBT_OK;
-}
-
-int runScanReadCommitted(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int parallelism = ctx->getProperty("Parallelism", 240);
- int abort = ctx->getProperty("AbortProb", 5);
- bool tupScan = ctx->getProperty("TupScan");
- int scan_flags = (NdbScanOperation::SF_TupScan & -(int)tupScan);
-
- int i = 0;
- HugoTransactions hugoTrans(*ctx->getTab());
- while (i<loops && !ctx->isTestStopped()) {
- g_info << i << ": ";
- if (hugoTrans.scanReadRecords(GETNDB(step), records,
- abort, parallelism,
- NdbOperation::LM_CommittedRead,
- scan_flags) != 0){
- return NDBT_FAILED;
- }
- i++;
- }
- return NDBT_OK;
-}
-
-int runScanReadError(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int parallelism = 240; // Max parallelism
- int error = ctx->getProperty("ErrorCode");
- NdbRestarter restarter;
-
- int i = 0;
- HugoTransactions hugoTrans(*ctx->getTab());
- while (i<loops && !ctx->isTestStopped()) {
- g_info << i << ": ";
-
- ndbout << "insertErrorInAllNodes("<<error<<")"<<endl;
- if (restarter.insertErrorInAllNodes(error) != 0){
- ndbout << "Could not insert error in all nodes "<<endl;
- return NDBT_FAILED;
- }
-
- if (hugoTrans.scanReadRecords(GETNDB(step), records, 0, parallelism) != 0){
- result = NDBT_FAILED;
- }
- i++;
- }
-
- restarter.insertErrorInAllNodes(0);
- return result;
-}
-
-int
-runInsertError(NDBT_Context* ctx, NDBT_Step* step){
- int error = ctx->getProperty("ErrorCode");
- NdbRestarter restarter;
-
- ctx->setProperty("ErrorCode", (Uint32)0);
- if (restarter.insertErrorInAllNodes(error) != 0){
- ndbout << "Could not insert error in all nodes "<<endl;
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runScanReadErrorOneNode(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int parallelism = 240; // Max parallelism
- int error = ctx->getProperty("ErrorCode");
- NdbRestarter restarter;
- int lastId = 0;
-
- if (restarter.getNumDbNodes() < 2){
- ctx->stopTest();
- return NDBT_OK;
- }
-
- int i = 0;
- HugoTransactions hugoTrans(*ctx->getTab());
- while (i<loops && result == NDBT_OK) {
- g_info << i << ": ";
-
- int nodeId = restarter.getDbNodeId(lastId);
- lastId = (lastId + 1) % restarter.getNumDbNodes();
- ndbout << "insertErrorInNode("<<nodeId<<", "<<error<<")"<<endl;
- if (restarter.insertErrorInNode(nodeId, error) != 0){
- ndbout << "Could not insert error in node="<<nodeId<<endl;
- return NDBT_FAILED;
- }
-
- for (int j=0; j<10; j++){
- if (hugoTrans.scanReadRecords(GETNDB(step),
- records, 0, parallelism) != 0)
- result = NDBT_FAILED;
- }
-
-
- if(restarter.waitClusterStarted(120) != 0){
- g_err << "Cluster failed to restart" << endl;
- result = NDBT_FAILED;
- }
- restarter.insertErrorInAllNodes(0);
-
- i++;
- }
- restarter.insertErrorInAllNodes(0);
- return result;
-}
-
-int runRestartAll(NDBT_Context* ctx, NDBT_Step* step){
-
- NdbRestarter restarter;
-
- if (restarter.restartAll() != 0){
- ndbout << "Could not restart all nodes"<<endl;
- return NDBT_FAILED;
- }
-
- if (restarter.waitClusterStarted(120) != 0){
- ndbout << "Could not restarted" << endl;
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-static int RANDOM_PARALLELISM = 9999;
-
-int runScanReadUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
- int i = 0;
-
- int parallelism = ctx->getProperty("Parallelism", 240);
- int para = parallelism;
-
- HugoTransactions hugoTrans(*ctx->getTab());
- while (ctx->isTestStopped() == false) {
- if (parallelism == RANDOM_PARALLELISM)
- para = myRandom48(239)+1;
-
- g_info << i << ": ";
- if (hugoTrans.scanReadRecords(GETNDB(step), records, 0, para) != 0){
- return NDBT_FAILED;
- }
- i++;
- }
- return NDBT_OK;
-}
-
-int runScanReadUntilStoppedNoCount(NDBT_Context* ctx, NDBT_Step* step){
- int i = 0;
- HugoTransactions hugoTrans(*ctx->getTab());
- while (ctx->isTestStopped() == false) {
- g_info << i << ": ";
- if (hugoTrans.scanReadRecords(GETNDB(step), 0) != 0){
- return NDBT_FAILED;
- }
- i++;
- }
- return NDBT_OK;
-}
-
-int runScanReadUntilStoppedPrintTime(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
- int i = 0;
- int parallelism = ctx->getProperty("Parallelism", 240);
- NdbTimer timer;
- Ndb* ndb = GETNDB(step);
-
-
- HugoTransactions hugoTrans(*ctx->getTab());
- while (ctx->isTestStopped() == false) {
- timer.doReset();
- timer.doStart();
- g_info << i << ": ";
- if (ndb->waitUntilReady() != 0)
- return NDBT_FAILED;
- if (hugoTrans.scanReadRecords(GETNDB(step), records, 0, parallelism) != 0)
- return NDBT_FAILED;
- timer.doStop();
- if ((timer.elapsedTime()/1000) > 1)
- timer.printTotalTime();
- i++;
- }
- return NDBT_OK;
-}
-
-
-int runPkRead(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int i = 0;
- HugoTransactions hugoTrans(*ctx->getTab());
- while (i<loops) {
- g_info << i << ": ";
- if (hugoTrans.pkReadRecords(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- i++;
- }
- return NDBT_OK;
-}
-
-int runScanUpdate(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int parallelism = ctx->getProperty("Parallelism", 1);
- int abort = ctx->getProperty("AbortProb", 5);
- int i = 0;
- HugoTransactions hugoTrans(*ctx->getTab());
- while (i<loops) {
- g_info << i << ": ";
-
- if (hugoTrans.scanUpdateRecords(GETNDB(step), records, abort, parallelism) != 0){
- return NDBT_FAILED;
- }
- i++;
- }
- return NDBT_OK;
-}
-
-int runScanUpdateUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
- int i = 0;
-
- int parallelism = ctx->getProperty("Parallelism", 240);
- int para = parallelism;
-
- HugoTransactions hugoTrans(*ctx->getTab());
- while (ctx->isTestStopped() == false) {
- if (parallelism == RANDOM_PARALLELISM)
- para = myRandom48(239)+1;
-
- g_info << i << ": ";
- if (hugoTrans.scanUpdateRecords(GETNDB(step), 0, 0, para) == NDBT_FAILED){
- return NDBT_FAILED;
- }
- i++;
- }
- return NDBT_OK;
-}
-
-
-int runScanUpdate2(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int parallelism = ctx->getProperty("Parallelism", 240);
- int abort = ctx->getProperty("AbortProb", 5);
- int i = 0;
- HugoTransactions hugoTrans(*ctx->getTab());
- while (i<loops) {
- g_info << i << ": ";
- if (hugoTrans.scanUpdateRecords2(GETNDB(step), records, abort, parallelism) != 0){
- return NDBT_FAILED;
- }
- i++;
- }
- return NDBT_OK;
-}
-
-int runLocker(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int records = ctx->getNumRecords();
- HugoTransactions hugoTrans(*ctx->getTab());
-
- if (hugoTrans.lockRecords(GETNDB(step), records, 5, 500) != 0){
- result = NDBT_FAILED;
- }
- ctx->stopTest();
-
- return result;
-}
-
-int runRestarter(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- NdbRestarter restarter;
- int i = 0;
- int lastId = 0;
- int timeout = 240;
-
- if (restarter.getNumDbNodes() < 2){
- ctx->stopTest();
- return NDBT_OK;
- }
- while(i<loops && result != NDBT_FAILED){
- if(restarter.waitClusterStarted(timeout) != 0){
- g_err << "Cluster failed to start 1" << endl;
- result = NDBT_FAILED;
- break;
- }
- NdbSleep_SecSleep(10);
-
- int nodeId = restarter.getDbNodeId(lastId);
- lastId = (lastId + 1) % restarter.getNumDbNodes();
- if(restarter.restartOneDbNode(nodeId, false, false, true) != 0){
- g_err << "Failed to restartNextDbNode" << endl;
- result = NDBT_FAILED;
- break;
- }
- i++;
- }
- if(restarter.waitClusterStarted(timeout) != 0){
- g_err << "Cluster failed to start 2" << endl;
- result = NDBT_FAILED;
- }
-
- ctx->stopTest();
-
- return result;
-}
-
-
-int runStopAndStartNode(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- NdbRestarter restarter;
- int i = 0;
- int lastId = 0;
- int timeout = 240;
-
- if (restarter.getNumDbNodes() < 2){
- ctx->stopTest();
- return NDBT_OK;
- }
- while(i<loops && result != NDBT_FAILED){
- if(restarter.waitClusterStarted(timeout) != 0){
- g_err << "Cluster failed to start 1" << endl;
- result = NDBT_FAILED;
- break;
- }
- NdbSleep_SecSleep(1);
- int nodeId = restarter.getDbNodeId(lastId);
- lastId = (lastId + 1) % restarter.getNumDbNodes();
- g_err << "Stopping node " << nodeId << endl;
-
- if(restarter.restartOneDbNode(nodeId, false, true) != 0){
- g_err << "Failed to restartOneDbNode" << endl;
- result = NDBT_FAILED;
- break;
- }
-
- if(restarter.waitNodesNoStart(&nodeId, 1, timeout) != 0){
- g_err << "Node failed to reach NoStart" << endl;
- result = NDBT_FAILED;
- break;
- }
-
- g_info << "Sleeping for 10 secs" << endl;
- NdbSleep_SecSleep(10);
-
- g_err << "Starting node " << nodeId << endl;
- if(restarter.startNodes(&nodeId, 1) != 0){
- g_err << "Failed to start the node" << endl;
- result = NDBT_FAILED;
- break;
- }
-
- i++;
- }
- if(restarter.waitClusterStarted(timeout) != 0){
- g_err << "Cluster failed to start 2" << endl;
- result = NDBT_FAILED;
- }
-
- ctx->stopTest();
-
- return result;
-}
-
-int runRestarter9999(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- NdbRestarter restarter;
- int i = 0;
- int lastId = 0;
-
- if (restarter.getNumDbNodes() < 2){
- ctx->stopTest();
- return NDBT_OK;
- }
- while(i<loops && result != NDBT_FAILED){
- if(restarter.waitClusterStarted(120) != 0){
- g_err << "Cluster failed to start" << endl;
- result = NDBT_FAILED;
- break;
- }
- NdbSleep_SecSleep(10);
-
- int nodeId = restarter.getDbNodeId(lastId);
- lastId = (lastId + 1) % restarter.getNumDbNodes();
- if(restarter.insertErrorInNode(nodeId, 9999) != 0){
- g_err << "Failed to insertErrorInNode="<<nodeId << endl;
- result = NDBT_FAILED;
- break;
- }
- NdbSleep_SecSleep(10);
- i++;
- }
- if(restarter.waitClusterStarted(120) != 0){
- g_err << "Cluster failed to start" << endl;
- result = NDBT_FAILED;
- }
-
- ctx->stopTest();
-
- return result;
-}
-
-
-int runCheckGetValue(NDBT_Context* ctx, NDBT_Step* step){
- const NdbDictionary::Table* pTab = ctx->getTab();
- int parallelism = ctx->getProperty("Parallelism", 1);
- int records = ctx->getNumRecords();
- int numFailed = 0;
- AttribList alist;
- alist.buildAttribList(pTab);
- UtilTransactions utilTrans(*pTab);
- for(size_t i = 0; i < alist.attriblist.size(); i++){
- g_info << (unsigned)i << endl;
- if(utilTrans.scanReadRecords(GETNDB(step),
- parallelism,
- NdbOperation::LM_Read,
- records,
- alist.attriblist[i]->numAttribs,
- alist.attriblist[i]->attribs) != 0){
- numFailed++;
- }
- if(utilTrans.scanReadRecords(GETNDB(step),
- parallelism,
- NdbOperation::LM_Read,
- records,
- alist.attriblist[i]->numAttribs,
- alist.attriblist[i]->attribs) != 0){
- numFailed++;
- }
- }
-
- if(numFailed > 0)
- return NDBT_FAILED;
- else
- return NDBT_OK;
-}
-
-int runCloseWithoutStop(NDBT_Context* ctx, NDBT_Step* step){
- const NdbDictionary::Table* pTab = ctx->getTab();
- int records = ctx->getNumRecords();
- int numFailed = 0;
- ScanFunctions scanF(*pTab);
- // Iterate over all possible parallelism valuse
- for (int p = 1; p<240; p++){
- g_info << p << " CloseWithoutStop openScan" << endl;
- if (scanF.scanReadFunctions(GETNDB(step),
- records,
- p,
- ScanFunctions::CloseWithoutStop,
- false) != 0){
- numFailed++;
- }
- g_info << p << " CloseWithoutStop openScanExclusive" << endl;
- if (scanF.scanReadFunctions(GETNDB(step),
- records,
- p,
- ScanFunctions::CloseWithoutStop,
- true) != 0){
- numFailed++;
- }
- }
-
- if(numFailed > 0)
- return NDBT_FAILED;
- else
- return NDBT_OK;
-}
-
-int runNextScanWhenNoMore(NDBT_Context* ctx, NDBT_Step* step){
- const NdbDictionary::Table* pTab = ctx->getTab();
- int records = ctx->getNumRecords();
- int numFailed = 0;
- ScanFunctions scanF(*pTab);
- if (scanF.scanReadFunctions(GETNDB(step),
- records,
- 6,
- ScanFunctions::NextScanWhenNoMore,
- false) != 0){
- numFailed++;
- }
- if (scanF.scanReadFunctions(GETNDB(step),
- records,
- 6,
- ScanFunctions::NextScanWhenNoMore,
- true) != 0){
- numFailed++;
- }
-
-
- if(numFailed > 0)
- return NDBT_FAILED;
- else
- return NDBT_OK;
-}
-
-int runEqualAfterOpenScan(NDBT_Context* ctx, NDBT_Step* step){
- const NdbDictionary::Table* pTab = ctx->getTab();
- int records = ctx->getNumRecords();
- int numFailed = 0;
- ScanFunctions scanF(*pTab);
- if (scanF.scanReadFunctions(GETNDB(step),
- records,
- 6,
- ScanFunctions::EqualAfterOpenScan,
- false) == NDBT_OK){
- numFailed++;
- }
- if (scanF.scanReadFunctions(GETNDB(step),
- records,
- 6,
- ScanFunctions::EqualAfterOpenScan,
- true) == NDBT_OK){
- numFailed++;
- }
-
-
- if(numFailed > 0)
- return NDBT_FAILED;
- else
- return NDBT_OK;
-}
-
-int runOnlyOpenScanOnce(NDBT_Context* ctx, NDBT_Step* step){
- const NdbDictionary::Table* pTab = ctx->getTab();
- int records = ctx->getNumRecords();
- int numFailed = 0;
- ScanFunctions scanF(*pTab);
- g_info << "OnlyOpenScanOnce openScanRead" << endl;
- if (scanF.scanReadFunctions(GETNDB(step),
- records,
- 6,
- ScanFunctions::OnlyOpenScanOnce,
- false) == 0){
- numFailed++;
- }
- g_info << "OnlyOpenScanOnce openScanExclusive" << endl;
- if (scanF.scanReadFunctions(GETNDB(step),
- records,
- 6,
- ScanFunctions::OnlyOpenScanOnce,
- true) == 0){
- numFailed++;
- }
-
-
- if(numFailed > 0)
- return NDBT_FAILED;
- else
- return NDBT_OK;
-}
-
-int runOnlyOneOpInScanTrans(NDBT_Context* ctx, NDBT_Step* step){
- return NDBT_OK;
-}
-
-int runExecuteScanWithoutOpenScan(NDBT_Context* ctx, NDBT_Step* step){
- return NDBT_OK;
-}
-
-int runOnlyOneOpBeforeOpenScan(NDBT_Context* ctx, NDBT_Step* step){
- return NDBT_OK;
-}
-
-int runOnlyOneScanPerTrans(NDBT_Context* ctx, NDBT_Step* step){
- return NDBT_OK;
-}
-
-int runNoCloseTransaction(NDBT_Context* ctx, NDBT_Step* step){
- const NdbDictionary::Table* pTab = ctx->getTab();
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int numFailed = 0;
-
- ScanFunctions scanF(*pTab);
- int l = 0;
- while(l < loops){
- if (scanF.scanReadFunctions(GETNDB(step),
- records,
- 6,
- ScanFunctions::NoCloseTransaction,
- false) != 0){
- numFailed++;
- }
- if (scanF.scanReadFunctions(GETNDB(step),
- records,
- 6,
- ScanFunctions::NoCloseTransaction,
- true) != 0){
- numFailed++;
- }
- l++;
- }
-
-
- if(numFailed > 0)
- return NDBT_FAILED;
- else
- return NDBT_OK;
-
-}
-
-int runCheckInactivityTimeOut(NDBT_Context* ctx, NDBT_Step* step){
- const NdbDictionary::Table* pTab = ctx->getTab();
- int records = ctx->getNumRecords();
- int numFailed = 0;
-
- ScanFunctions scanF(*pTab);
- if (scanF.scanReadFunctions(GETNDB(step),
- records,
- 1,
- ScanFunctions::CheckInactivityTimeOut,
- false) != NDBT_OK){
- numFailed++;
- }
- if (scanF.scanReadFunctions(GETNDB(step),
- records,
- 240,
- ScanFunctions::CheckInactivityTimeOut,
- true) != NDBT_OK){
- numFailed++;
- }
-
- if(numFailed > 0)
- return NDBT_FAILED;
- else
- return NDBT_OK;
-
-}
-
-int runCheckInactivityBeforeClose(NDBT_Context* ctx, NDBT_Step* step){
- const NdbDictionary::Table* pTab = ctx->getTab();
- int records = ctx->getNumRecords();
- int numFailed = 0;
-
- ScanFunctions scanF(*pTab);
- if (scanF.scanReadFunctions(GETNDB(step),
- records,
- 16,
- ScanFunctions::CheckInactivityBeforeClose,
- false) != 0){
- numFailed++;
- }
- if (scanF.scanReadFunctions(GETNDB(step),
- records,
- 240,
- ScanFunctions::CheckInactivityBeforeClose,
- true) != 0){
- numFailed++;
- }
-
- if(numFailed > 0)
- return NDBT_FAILED;
- else
- return NDBT_OK;
-
-}
-
-int runScanRestart(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- Ndb * pNdb = GETNDB(step);
- const NdbDictionary::Table* pTab = ctx->getTab();
-
- HugoCalculator calc(* pTab);
- NDBT_ResultRow tmpRow(* pTab);
-
- int i = 0;
- while (i<loops && !ctx->isTestStopped()) {
- g_info << i++ << ": ";
- const int record = (rand() % records);
- g_info << " row=" << record;
-
- NdbConnection* pCon = pNdb->startTransaction();
- NdbScanOperation* pOp = pCon->getNdbScanOperation(pTab->getName());
- if (pOp == NULL) {
- ERR(pCon->getNdbError());
- return NDBT_FAILED;
- }
-
- if( pOp->readTuples() ) {
- ERR(pCon->getNdbError());
- return NDBT_FAILED;
- }
-
- int check = pOp->interpret_exit_ok();
- if( check == -1 ) {
- ERR(pCon->getNdbError());
- return NDBT_FAILED;
- }
-
- // Define attributes to read
- for(int a = 0; a<pTab->getNoOfColumns(); a++){
- if((tmpRow.attributeStore(a) =
- pOp->getValue(pTab->getColumn(a)->getName())) == 0) {
- ERR(pCon->getNdbError());
- return NDBT_FAILED;
- }
- }
-
- check = pCon->execute(NoCommit);
- if( check == -1 ) {
- ERR(pCon->getNdbError());
- return NDBT_FAILED;
- }
-
- int res;
- int row = 0;
- while(row < record && (res = pOp->nextResult()) == 0) {
- if(calc.verifyRowValues(&tmpRow) != 0){
- abort();
- return NDBT_FAILED;
- }
- row++;
- }
- if(row != record){
- ERR(pCon->getNdbError());
- abort();
- return NDBT_FAILED;
- }
- g_info << " restarting" << endl;
- if((res = pOp->restart()) != 0){
- ERR(pCon->getNdbError());
- abort();
- return NDBT_FAILED;
- }
-
- row = 0;
- while((res = pOp->nextResult()) == 0) {
- if(calc.verifyRowValues(&tmpRow) != 0){
- abort();
- return NDBT_FAILED;
- }
- row++;
- }
- if(res != 1 || row != records){
- ERR(pCon->getNdbError());
- abort();
- return NDBT_FAILED;
- }
- pCon->close();
- }
- return NDBT_OK;
-}
-
-
-int
-runScanParallelism(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops() + 3;
- int records = ctx->getNumRecords();
- int abort = ctx->getProperty("AbortProb", 15);
-
- Uint32 fib[] = { 1, 2 };
- Uint32 parallelism = 0; // start with 0
- int i = 0;
- HugoTransactions hugoTrans(*ctx->getTab());
- while (i<loops && !ctx->isTestStopped()) {
- g_info << i << ": ";
-
- if (hugoTrans.scanReadRecords(GETNDB(step), records, abort, parallelism,
- NdbOperation::LM_Read) != 0){
- return NDBT_FAILED;
- }
- if (hugoTrans.scanReadRecords(GETNDB(step), records, abort, parallelism,
- NdbOperation::LM_Exclusive) != 0){
- return NDBT_FAILED;
- }
- if (hugoTrans.scanReadRecords(GETNDB(step), records, abort, parallelism,
- NdbOperation::LM_CommittedRead) != 0){
- return NDBT_FAILED;
- }
- if (hugoTrans.scanUpdateRecords(GETNDB(step), records, abort, parallelism)
- != 0){
- return NDBT_FAILED;
- }
- i++;
- parallelism = fib[0];
- Uint32 next = fib[0] + fib[1];
- fib[0] = fib[1];
- fib[1] = next;
- }
- return NDBT_OK;
-}
-
-int
-runScanVariants(NDBT_Context* ctx, NDBT_Step* step)
-{
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- Ndb * pNdb = GETNDB(step);
- const NdbDictionary::Table* pTab = ctx->getTab();
-
- HugoCalculator calc(* pTab);
- NDBT_ResultRow tmpRow(* pTab);
-
- for(int lm = 0; lm <= NdbOperation::LM_CommittedRead; lm++)
- {
- for(int flags = 0; flags < 4; flags++)
- {
- for (int batch = 0; batch < 100; batch += (1 + batch + (batch >> 3)))
- {
- for (int par = 0; par < 16; par += 1 + (rand() % 3))
- {
- bool disk = flags & 1;
- bool tups = flags & 2;
- g_info << "lm: " << lm
- << " disk: " << disk
- << " tup scan: " << tups
- << " par: " << par
- << " batch: " << batch
- << endl;
-
- NdbConnection* pCon = pNdb->startTransaction();
- NdbScanOperation* pOp = pCon->getNdbScanOperation(pTab->getName());
- if (pOp == NULL) {
- ERR(pCon->getNdbError());
- return NDBT_FAILED;
- }
-
- if( pOp->readTuples((NdbOperation::LockMode)lm,
- tups ? NdbScanOperation::SF_TupScan : 0,
- par,
- batch) != 0)
- {
- ERR(pCon->getNdbError());
- return NDBT_FAILED;
- }
-
- int check = pOp->interpret_exit_ok();
- if( check == -1 ) {
- ERR(pCon->getNdbError());
- return NDBT_FAILED;
- }
-
- // Define attributes to read
- bool found_disk = false;
- for(int a = 0; a<pTab->getNoOfColumns(); a++){
- if (pTab->getColumn(a)->getStorageType() ==
- NdbDictionary::Column::StorageTypeDisk)
- {
- found_disk = true;
- if (!disk)
- continue;
- }
-
- if((pOp->getValue(pTab->getColumn(a)->getName())) == 0) {
- ERR(pCon->getNdbError());
- return NDBT_FAILED;
- }
- }
-
- if (! (disk && !found_disk))
- {
- check = pCon->execute(NoCommit);
- if( check == -1 ) {
- ERR(pCon->getNdbError());
- return NDBT_FAILED;
- }
-
- int res;
- int row = 0;
- while((res = pOp->nextResult()) == 0);
- }
- pCon->close();
- }
- }
- }
- }
- return NDBT_OK;
-}
-
-int
-runBug24447(NDBT_Context* ctx, NDBT_Step* step){
- int loops = 1; //ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int abort = ctx->getProperty("AbortProb", 15);
- NdbRestarter restarter;
- HugoTransactions hugoTrans(*ctx->getTab());
- int i = 0;
- while (i<loops && !ctx->isTestStopped())
- {
- g_info << i++ << ": ";
-
- int nodeId = restarter.getRandomNotMasterNodeId(rand());
- if (nodeId == -1)
- nodeId = restarter.getMasterNodeId();
- if (restarter.insertErrorInNode(nodeId, 8038) != 0)
- {
- ndbout << "Could not insert error in node="<<nodeId<<endl;
- return NDBT_FAILED;
- }
-
- for (Uint32 j = 0; i<10; i++)
- {
- hugoTrans.scanReadRecords(GETNDB(step), records, abort, 0,
- NdbOperation::LM_CommittedRead);
- }
-
- }
- restarter.insertErrorInAllNodes(0);
-
- return NDBT_OK;
-}
-
-NDBT_TESTSUITE(testScan);
-TESTCASE("ScanRead",
- "Verify scan requirement: It should be possible "\
- "to read all records in a table without knowing their "\
- "primary key."){
- INITIALIZER(runLoadTable);
- TC_PROPERTY("Parallelism", 1);
- STEP(runScanRead);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanRead16",
- "Verify scan requirement: It should be possible to scan read "\
- "with parallelism, test with parallelism 16"){
- INITIALIZER(runLoadTable);
- TC_PROPERTY("Parallelism", 16);
- STEP(runScanRead);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanRead240",
- "Verify scan requirement: It should be possible to scan read with "\
- "parallelism, test with parallelism 240(240 would automatically be "\
- "downgraded to the maximum parallelism value for the current config)"){
- INITIALIZER(runLoadTable);
- TC_PROPERTY("Parallelism", 240);
- STEP(runScanRead);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanReadCommitted240",
- "Verify scan requirement: It should be possible to scan read committed with "\
- "parallelism, test with parallelism 240(240 would automatically be "\
- "downgraded to the maximum parallelism value for the current config)"){
- INITIALIZER(runLoadTable);
- TC_PROPERTY("Parallelism", 240);
- TC_PROPERTY("TupScan", (Uint32)0);
- STEP(runScanReadCommitted);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanUpdate",
- "Verify scan requirement: It should be possible "\
- "to update all records in a table without knowing their"\
- " primary key."){
- INITIALIZER(runLoadTable);
- STEP(runScanUpdate);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanUpdate2",
- "Verify scan requirement: It should be possible "\
- "to update all records in a table without knowing their"\
- " primary key. Do this efficently by calling nextScanResult(false) "\
- "in order to update the records already fetched to the api in one batch."){
- INITIALIZER(runLoadTable);
- TC_PROPERTY("Parallelism", 240);
- STEP(runScanUpdate2);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanDelete",
- "Verify scan requirement: It should be possible "\
- "to delete all records in a table without knowing their"\
- " primary key."){
- INITIALIZER(runLoadTable);
- STEP(runScanDelete);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanDelete2",
- "Verify scan requirement: It should be possible "\
- "to delete all records in a table without knowing their"\
- " primary key. Do this efficently by calling nextScanResult(false) "\
- "in order to delete the records already fetched to the api in one batch."){
- INITIALIZER(runLoadTable);
- TC_PROPERTY("Parallelism", 240);
- STEP(runScanDelete2);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanUpdateAndScanRead",
- "Verify scan requirement: It should be possible to run "\
- "scan read and scan update at the same time"){
- INITIALIZER(runLoadTable);
- TC_PROPERTY("Parallelism", 16);
- STEP(runScanRead);
- STEP(runScanUpdate);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanReadAndLocker",
- "Verify scan requirement: The locks are not kept throughout "\
- "the entire scan operation. This means that a scan does not "\
- "lock the entire table, only the records it's currently "\
- "operating on. This will test how scan performs when there are "\
- " a number of 1 second locks in the table"){
- INITIALIZER(runLoadTable);
- STEP(runScanReadUntilStopped);
- STEP(runLocker);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanReadAndPkRead",
- "Verify scan requirement: The locks are not kept throughout "\
- "the entire scan operation. This means that a scan does not "\
- "lock the entire table, only the records it's currently "\
- "operating on. This will test how scan performs when there are "\
- " a pk reads "){
- INITIALIZER(runLoadTable);
- STEPS(runScanRead, 2);
- STEPS(runPkRead, 2);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanRead488",
- "Verify scan requirement: It's only possible to have 11 concurrent "\
- "scans per fragment running in Ndb kernel at the same time. "\
- "When this limit is exceeded the scan will be aborted with errorcode "\
- "488."){
- INITIALIZER(runLoadTable);
- STEPS(runRandScanRead, 70);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanRead488T",
- "Verify scan requirement: It's only possible to have 11 concurrent "\
- "scans per fragment running in Ndb kernel at the same time. "\
- "When this limit is exceeded the scan will be aborted with errorcode "\
- "488."){
- TC_PROPERTY("TupScan", 1);
- INITIALIZER(runLoadTable);
- STEPS(runRandScanRead, 70);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanRead488O",
- "Verify scan requirement: It's only possible to have 11 concurrent "\
- "scans per fragment running in Ndb kernel at the same time. "\
- "When this limit is exceeded the scan will be aborted with errorcode "\
- "488."){
- INITIALIZER(createOrderedPkIndex);
- INITIALIZER(runLoadTable);
- STEPS(runScanReadIndex, 70);
- FINALIZER(createOrderedPkIndex_Drop);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanRead488_Mixed",
- "Verify scan requirement: It's only possible to have 11 concurrent "\
- "scans per fragment running in Ndb kernel at the same time. "\
- "When this limit is exceeded the scan will be aborted with errorcode "\
- "488."){
- TC_PROPERTY("TupScan", 2);
- INITIALIZER(createOrderedPkIndex);
- INITIALIZER(runLoadTable);
- STEPS(runRandScanRead, 50);
- STEPS(runScanReadIndex, 50);
- FINALIZER(createOrderedPkIndex_Drop);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanRead488Timeout",
- ""){
- INITIALIZER(runLoadTable);
- TC_PROPERTY("ErrorCode", 5034);
- STEPS(runScanRead, 30);
- STEP(runScanReadError);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanRead40",
- "Verify scan requirement: Scan with 40 simultaneous threads"){
- INITIALIZER(runLoadTable);
- STEPS(runScanRead, 40);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanRead100",
- "Verify scan requirement: Scan with 100 simultaneous threads"){
- INITIALIZER(runLoadTable);
- STEPS(runScanRead, 100);
- FINALIZER(runClearTable);
-}
-TESTCASE("Scan-bug8262",
- ""){
- TC_PROPERTY("Rows", 1);
- TC_PROPERTY("ErrorCode", 8035);
- INITIALIZER(runLoadTable);
- INITIALIZER(runInsertError); // Will reset error code
- STEPS(runScanRead, 25);
- FINALIZER(runInsertError);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanRead40RandomTable",
- "Verify scan requirement: Scan with 40 simultaneous threads. "\
- "Use random table for the scan"){
- INITIALIZER(runCreateAllTables);
- INITIALIZER(runLoadAllTables);
- STEPS(runScanReadRandomTable, 40);
- FINALIZER(runDropAllTablesExceptTestTable);
-}
-TESTCASE("ScanRead100RandomTable",
- "Verify scan requirement: Scan with 100 simultaneous threads. "\
- "Use random table for the scan"){
- INITIALIZER(runCreateAllTables);
- INITIALIZER(runLoadAllTables);
- STEPS(runScanReadRandomTable, 100);
- FINALIZER(runDropAllTablesExceptTestTable);
-}
-TESTCASE("ScanReadRandomPrepare",
- "Create and load tables for ScanRead40RandomNoTableCreate."){
- INITIALIZER(runCreateAllTables);
- INITIALIZER(runLoadAllTables);
-}
-TESTCASE("ScanRead40RandomNoTableCreate",
- "Verify scan requirement: Scan with 40 simultaneous threads. "\
- "Use random table for the scan. Dont create or load the tables."){
- STEPS(runScanReadRandomTable, 40);
-}
-TESTCASE("ScanRead100RandomNoTableCreate",
- "Verify scan requirement: Scan with 100 simultaneous threads. "\
- "Use random table for the scan. Dont create or load the tables."){
- STEPS(runScanReadRandomTable, 100);
-}
-TESTCASE("ScanWithLocksAndInserts",
- "TR457: This test is added to verify that an insert of a records "\
- "that is already in the database does not delete the record"){
- INITIALIZER(runLoadTable);
- STEPS(runScanReadUntilStopped, 2);
- STEP(runLocker);
- STEP(runInsertUntilStopped);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanReadAbort",
- "Scan requirement: A scan may be aborted by the application "\
- "at any time. This can be performed even if there are more "\
- "tuples to scan."){
- INITIALIZER(runLoadTable);
- TC_PROPERTY("AbortProb", 90);
- STEPS(runScanRead, 3);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanReadAbort15",
- "Scan requirement: A scan may be aborted by the application "\
- "at any time. This can be performed even if there are more "\
- "tuples to scan. Use parallelism 15"){
- INITIALIZER(runLoadTable);
- TC_PROPERTY("Parallelism", 15);
- TC_PROPERTY("AbortProb", 90);
- STEPS(runScanRead, 3);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanReadAbort240",
- "Scan requirement: A scan may be aborted by the application "\
- "at any time. This can be performed even if there are more "\
- "tuples to scan. Use parallelism 240(it will be downgraded to max para for this config)"){
- INITIALIZER(runLoadTable);
- TC_PROPERTY("Parallelism", 240);
- TC_PROPERTY("AbortProb", 90);
- STEPS(runScanRead, 3);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanUpdateAbort16",
- "Scan requirement: A scan may be aborted by the application "\
- "at any time. This can be performed even if there are more "\
- "tuples to scan. Use parallelism 16"){
- INITIALIZER(runLoadTable);
- TC_PROPERTY("Parallelism", 16);
- TC_PROPERTY("AbortProb", 90);
- STEPS(runScanUpdate, 3);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanUpdateAbort240",
- "Scan requirement: A scan may be aborted by the application "\
- "at any time. This can be performed even if there are more "\
- "tuples to scan. Use parallelism 240(it will be downgraded to max para for this config)"){
- INITIALIZER(runLoadTable);
- TC_PROPERTY("Parallelism", 240);
- TC_PROPERTY("AbortProb", 90);
- STEPS(runScanUpdate, 3);
- FINALIZER(runClearTable);
-}
-TESTCASE("CheckGetValue",
- "Check that we can call getValue to read attributes"\
- "Especially interesting to see if we can read only the"\
- " first, last or any two attributes from the table"){
- INITIALIZER(runLoadTable);
- STEP(runCheckGetValue);
- VERIFIER(runScanRead);
- FINALIZER(runClearTable);
-}
-TESTCASE("CloseWithoutStop",
- "Check that we can close the scanning transaction without calling "\
- "stopScan"){
- INITIALIZER(runLoadTable);
- STEP(runCloseWithoutStop);
- VERIFIER(runScanRead);
- FINALIZER(runClearTable);
-}
-TESTCASE("NextScanWhenNoMore",
- "Check that we can call nextScanResult when there are no more "\
- "records, and that it returns a valid value"){
- INITIALIZER(runLoadTable);
- STEP(runNextScanWhenNoMore);
- VERIFIER(runScanRead);
- FINALIZER(runClearTable);
-}
-TESTCASE("EqualAfterOpenScan",
- "Check that we can't call equal after openScan"){
- STEP(runEqualAfterOpenScan);
-}
-TESTCASE("ExecuteScanWithoutOpenScan",
- "Check that we can't call executeScan without defining a scan "\
- "with openScan"){
- INITIALIZER(runLoadTable);
- STEP(runExecuteScanWithoutOpenScan);
- VERIFIER(runScanRead);
- FINALIZER(runClearTable);
-}
-TESTCASE("OnlyOpenScanOnce",
- "Check that we may only call openScan once in the same trans"){
- INITIALIZER(runLoadTable);
- STEP(runOnlyOpenScanOnce);
- VERIFIER(runScanRead);
- FINALIZER(runClearTable);
-}
-TESTCASE("OnlyOneOpInScanTrans",
- "Check that we can have only one operation in a scan trans"){
- INITIALIZER(runLoadTable);
- STEP(runOnlyOneOpInScanTrans);
- VERIFIER(runScanRead);
- FINALIZER(runClearTable);
-}
-TESTCASE("OnlyOneOpBeforeOpenScan",
- "Check that we can have only one operation in a trans defined "\
- "when calling openScan "){
- INITIALIZER(runLoadTable);
- STEP(runOnlyOneOpBeforeOpenScan);
- VERIFIER(runScanRead);
- FINALIZER(runClearTable);
-}
-TESTCASE("OnlyOneScanPerTrans",
- "Check that we can have only one scan operation in a trans"){
- INITIALIZER(runLoadTable);
- STEP(runOnlyOneScanPerTrans);
- VERIFIER(runScanRead);
- FINALIZER(runClearTable);
-}
-TESTCASE("NoCloseTransaction",
- "Check behaviour when close transaction is not called "){
- INITIALIZER(runLoadTable);
- STEP(runNoCloseTransaction);
- VERIFIER(runScanRead);
- FINALIZER(runClearTable);
-}
-TESTCASE("CheckInactivityTimeOut",
- "Check behaviour when the api sleeps for a long time before continuing scan "){
- INITIALIZER(runLoadTable);
- STEP(runCheckInactivityTimeOut);
- VERIFIER(runScanRead);
- FINALIZER(runClearTable);
-}
-TESTCASE("CheckInactivityBeforeClose",
- "Check behaviour when the api sleeps for a long time before calling close scan "){
- INITIALIZER(runLoadTable);
- STEP(runCheckInactivityBeforeClose);
- VERIFIER(runScanRead);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanReadError5021",
- "Scan and insert error 5021, one node is expected to crash"){
- INITIALIZER(runLoadTable);
- TC_PROPERTY("ErrorCode", 5021);
- STEP(runScanReadErrorOneNode);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanReadError5022",
- "Scan and insert error 5022, one node is expected to crash"){
- INITIALIZER(runLoadTable);
- TC_PROPERTY("ErrorCode", 5022);
- TC_PROPERTY("NodeNumber", 2);
- STEP(runScanReadErrorOneNode);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanReadError5023",
- "Scan and insert error 5023"){
- INITIALIZER(runLoadTable);
- TC_PROPERTY("ErrorCode", 5023);
- STEP(runScanReadError);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanReadError5024",
- "Scan and insert error 5024"){
- INITIALIZER(runLoadTable);
- TC_PROPERTY("ErrorCode", 5024);
- STEP(runScanReadError);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanReadError5025",
- "Scan and insert error 5025"){
- INITIALIZER(runLoadTable);
- TC_PROPERTY("ErrorCode", 5025);
- STEP(runScanReadError);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanReadError5030",
- "Scan and insert error 5030."\
- "Drop all SCAN_NEXTREQ signals in LQH until the node is "\
- "shutdown with SYSTEM_ERROR because of scan fragment timeout"){
- INITIALIZER(runLoadTable);
- TC_PROPERTY("ErrorCode", 5030);
- STEP(runScanReadErrorOneNode);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanReadRestart",
- "Scan requirement:A scan should be able to start and "\
- "complete during node recovery and when one or more nodes "\
- "in the cluster is down.Use random parallelism "){
- INITIALIZER(runLoadTable);
- TC_PROPERTY("Parallelism", RANDOM_PARALLELISM); // Random
- STEP(runScanReadUntilStopped);
- STEP(runRestarter);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanUpdateRestart",
- "Scan requirement:A scan should be able to start and "\
- "complete during node recovery and when one or more nodes "\
- "in the cluster is down. Use random parallelism"){
- INITIALIZER(runLoadTable);
- TC_PROPERTY("Parallelism", RANDOM_PARALLELISM); // Random
- STEP(runScanUpdateUntilStopped);
- STEP(runRestarter);
- FINALIZER(runClearTable);
-}
-#if 0
-TESTCASE("ScanReadRestart9999",
- "Scan requirement:A scan should be able to start and "\
- "complete during node recovery and when one or more nodes "\
- "in the cluster is down. Use parallelism 240."\
- "Restart using error insert 9999"){
- INITIALIZER(runLoadTable);
- TC_PROPERTY("Parallelism", 240);
- STEP(runScanReadUntilStopped);
- STEP(runRestarter9999);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanUpdateRestart9999",
- "Scan requirement:A scan should be able to start and "\
- "complete during node recovery and when one or more nodes "\
- "in the cluster is down. Use parallelism 240."\
- "Restart using error insert 9999"){
- INITIALIZER(runLoadTable);
- TC_PROPERTY("Parallelism", 240);
- STEP(runScanReadUntilStopped);
- STEP(runScanUpdateUntilStopped);
- STEP(runRestarter9999);
- FINALIZER(runClearTable);
-}
-#endif
-TESTCASE("InsertDelete",
- "Load and delete all while scan updating and scan reading\n"\
- "Alexander Lukas special"){
- INITIALIZER(runClearTable);
- STEP(runScanReadUntilStoppedNoCount);
- STEP(runScanUpdateUntilStopped);
- STEP(runInsertDelete);
- FINALIZER(runClearTable);
-}
-TESTCASE("CheckAfterTerror",
- "Check that we can still scan read after this terror of NdbApi"){
- INITIALIZER(runLoadTable);
- STEPS(runScanRead, 5);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanReadWhileNodeIsDown",
- "Scan requirement:A scan should be able to run as fast when "\
- "one or more nodes in the cluster is down."){
- INITIALIZER(runLoadTable);
- STEP(runScanReadUntilStoppedPrintTime);
- STEP(runStopAndStartNode);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanRestart",
- "Verify restart functionallity"){
- INITIALIZER(runLoadTable);
- STEP(runScanRestart);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanParallelism",
- "Test scan with different parallelism"){
- INITIALIZER(runLoadTable);
- STEP(runScanParallelism);
- FINALIZER(runClearTable);
-}
-TESTCASE("ScanVariants",
- "Test different scan variants"){
- INITIALIZER(runLoadTable);
- STEP(runScanVariants);
- FINALIZER(runClearTable);
-}
-TESTCASE("Bug24447",
- ""){
- INITIALIZER(runLoadTable);
- STEP(runBug24447);
- FINALIZER(runClearTable);
-}
-NDBT_TESTSUITE_END(testScan);
-
-int main(int argc, const char** argv){
- ndb_init();
- myRandom48Init(NdbTick_CurrentMillisecond());
- return testScan.execute(argc, argv);
-}
-
-template class Vector<Attrib*>;
diff --git a/storage/ndb/test/ndbapi/testScanFilter.cpp b/storage/ndb/test/ndbapi/testScanFilter.cpp
deleted file mode 100644
index 8796fe87e22..00000000000
--- a/storage/ndb/test/ndbapi/testScanFilter.cpp
+++ /dev/null
@@ -1,861 +0,0 @@
-/* Copyright (C) 2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT.hpp>
-#include <NDBT_Test.hpp>
-
-#define ERR_EXIT(obj, msg) \
-do \
-{ \
-fprintf(stderr, "%s: %s (%d) in %s:%d\n", \
-msg, obj->getNdbError().message, obj->getNdbError().code, __FILE__, __LINE__); \
-exit(-1); \
-} \
-while (0);
-
-#define PRINT_ERROR(code,msg) \
-do \
-{ \
-fprintf(stderr, "Error in %s, line: %d, code: %d, msg: %s.\n", __FILE__, __LINE__, code, msg); \
-} \
-while (0);
-
-#define MYSQLERROR(mysql) { \
- PRINT_ERROR(mysql_errno(&mysql),mysql_error(&mysql)); \
- exit(-1); }
-#define APIERROR(error) { \
- PRINT_ERROR(error.code,error.message); \
- exit(-1); }
-
-#define TEST_NAME "TestScanFilter"
-#define TABLE_NAME "TABLE_SCAN"
-
-const char *COL_NAME[] = {"id", "i", "j", "k", "l", "m", "n"};
-const char COL_LEN = 7;
-/*
-* Not to change TUPLE_NUM, because the column in TABLE_NAME is fixed,
-* there are six columns, 'i', 'j', 'k', 'l', 'm', 'n', and each on is equal to 1 or 1,
-* Since each tuple should be unique in this case, then TUPLE_NUM = 2 power 6 = 64
-*/
-#ifdef _AIX
-/*
- IBM xlC_r breaks on the initialization with pow():
- "The expression must be an integral constant expression."
-*/
-const int TUPLE_NUM = 64;
-#else
-const int TUPLE_NUM = (int)pow(2, COL_LEN-1);
-#endif
-
-/*
-* the recursive level of random scan filter, can
-* modify this parameter more or less, range from
-* 1 to 100, larger num consumes more scan time
-*/
-const int RECURSIVE_LEVEL = 10;
-
-const int MAX_STR_LEN = (RECURSIVE_LEVEL * (COL_LEN+1) * 4);
-
-/*
-* Each time stands for one test, it will produce a random
-* filter string, and scan through ndb api and through
-* calculation with tuples' data, then compare the result,
-* if they are equal, this test passed, or failed.
-* Only all TEST_NUM times tests passed, we can believe
-* the suite of test cases are okay.
-* Change TEST_NUM to larger will need more time to test
-*/
-const int TEST_NUM = 5000;
-
-
-/* Table definition*/
-static
-const
-NDBT_Attribute MYTAB1Attribs[] = {
- NDBT_Attribute("id", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("i", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("j", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("k", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("l", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("m", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("n", NdbDictionary::Column::Unsigned),
-};
-static
-const
-NDBT_Table MYTAB1(TABLE_NAME, sizeof(MYTAB1Attribs)/sizeof(NDBT_Attribute), MYTAB1Attribs);
-
-
-int createTable(Ndb* pNdb, const NdbDictionary::Table* tab, bool _temp,
- bool existsOk, NDBT_CreateTableHook f)
-{
- int r = 0;
- do{
- NdbDictionary::Table tmpTab(* tab);
- tmpTab.setStoredTable(_temp ? 0 : 1);
- if(f != 0 && f(pNdb, tmpTab, 0, NULL))
- {
- ndbout << "Failed to create table" << endl;
- return NDBT_FAILED;
- }
- r = pNdb->getDictionary()->createTable(tmpTab);
- if(r == -1){
- if(!existsOk){
- ndbout << "Error: " << pNdb->getDictionary()->getNdbError() << endl;
- break;
- }
- if(pNdb->getDictionary()->getNdbError().code != 721){
- ndbout << "Error: " << pNdb->getDictionary()->getNdbError() << endl;
- break;
- }
- r = 0;
- }
- }while(false);
-
- return r;
-}
-
-/*
-* Function to produce the tuples' data
-*/
-int runPopulate(NDBT_Context* ctx, NDBT_Step* step)
-{
- Ndb *myNdb = GETNDB(step);
- const NdbDictionary::Dictionary* myDict= myNdb->getDictionary();
- const NdbDictionary::Table *myTable= myDict->getTable(TABLE_NAME);
- if(myTable == NULL)
- APIERROR(myDict->getNdbError());
-
- NdbTransaction* myTrans = myNdb->startTransaction();
- if (myTrans == NULL)
- APIERROR(myNdb->getNdbError());
-
- for(int num = 0; num < TUPLE_NUM; num++)
- {
- NdbOperation* myNdbOperation = myTrans->getNdbOperation(myTable);
- if(myNdbOperation == NULL)
- {
- APIERROR(myTrans->getNdbError());
- }
-
-/* the tuples' data in TABLE_NAME
-+----+---+---+---+---+---+---+
-| id | i | j | k | l | m | n |
-+----+---+---+---+---+---+---+
-| 0 | 0 | 0 | 0 | 0 | 0 | 0 |
-| 1 | 0 | 0 | 0 | 0 | 0 | 1 |
-| 2 | 0 | 0 | 0 | 0 | 1 | 0 |
-| 3 | 0 | 0 | 0 | 0 | 1 | 1 |
-| 4 | 0 | 0 | 0 | 1 | 0 | 0 |
-| 5 | 0 | 0 | 0 | 1 | 0 | 1 |
-| 6 | 0 | 0 | 0 | 1 | 1 | 0 |
-| 7 | 0 | 0 | 0 | 1 | 1 | 1 |
-| 8 | 0 | 0 | 1 | 0 | 0 | 0 |
-| 9 | 0 | 0 | 1 | 0 | 0 | 1 |
-| 10 | 0 | 0 | 1 | 0 | 1 | 0 |
-| 11 | 0 | 0 | 1 | 0 | 1 | 1 |
-| 12 | 0 | 0 | 1 | 1 | 0 | 0 |
-| 13 | 0 | 0 | 1 | 1 | 0 | 1 |
-| 14 | 0 | 0 | 1 | 1 | 1 | 0 |
-| 15 | 0 | 0 | 1 | 1 | 1 | 1 |
-| 16 | 0 | 1 | 0 | 0 | 0 | 0 |
-| 17 | 0 | 1 | 0 | 0 | 0 | 1 |
-| 18 | 0 | 1 | 0 | 0 | 1 | 0 |
-| 19 | 0 | 1 | 0 | 0 | 1 | 1 |
-| 20 | 0 | 1 | 0 | 1 | 0 | 0 |
-| 21 | 0 | 1 | 0 | 1 | 0 | 1 |
-| 22 | 0 | 1 | 0 | 1 | 1 | 0 |
-| 23 | 0 | 1 | 0 | 1 | 1 | 1 |
-| 24 | 0 | 1 | 1 | 0 | 0 | 0 |
-| 25 | 0 | 1 | 1 | 0 | 0 | 1 |
-| 26 | 0 | 1 | 1 | 0 | 1 | 0 |
-| 27 | 0 | 1 | 1 | 0 | 1 | 1 |
-| 28 | 0 | 1 | 1 | 1 | 0 | 0 |
-| 29 | 0 | 1 | 1 | 1 | 0 | 1 |
-| 30 | 0 | 1 | 1 | 1 | 1 | 0 |
-| 31 | 0 | 1 | 1 | 1 | 1 | 1 |
-| 32 | 1 | 0 | 0 | 0 | 0 | 0 |
-| 33 | 1 | 0 | 0 | 0 | 0 | 1 |
-| 34 | 1 | 0 | 0 | 0 | 1 | 0 |
-| 35 | 1 | 0 | 0 | 0 | 1 | 1 |
-| 36 | 1 | 0 | 0 | 1 | 0 | 0 |
-| 37 | 1 | 0 | 0 | 1 | 0 | 1 |
-| 38 | 1 | 0 | 0 | 1 | 1 | 0 |
-| 39 | 1 | 0 | 0 | 1 | 1 | 1 |
-| 40 | 1 | 0 | 1 | 0 | 0 | 0 |
-| 41 | 1 | 0 | 1 | 0 | 0 | 1 |
-| 42 | 1 | 0 | 1 | 0 | 1 | 0 |
-| 43 | 1 | 0 | 1 | 0 | 1 | 1 |
-| 44 | 1 | 0 | 1 | 1 | 0 | 0 |
-| 45 | 1 | 0 | 1 | 1 | 0 | 1 |
-| 46 | 1 | 0 | 1 | 1 | 1 | 0 |
-| 47 | 1 | 0 | 1 | 1 | 1 | 1 |
-| 48 | 1 | 1 | 0 | 0 | 0 | 0 |
-| 49 | 1 | 1 | 0 | 0 | 0 | 1 |
-| 50 | 1 | 1 | 0 | 0 | 1 | 0 |
-| 51 | 1 | 1 | 0 | 0 | 1 | 1 |
-| 52 | 1 | 1 | 0 | 1 | 0 | 0 |
-| 53 | 1 | 1 | 0 | 1 | 0 | 1 |
-| 54 | 1 | 1 | 0 | 1 | 1 | 0 |
-| 55 | 1 | 1 | 0 | 1 | 1 | 1 |
-| 56 | 1 | 1 | 1 | 0 | 0 | 0 |
-| 57 | 1 | 1 | 1 | 0 | 0 | 1 |
-| 58 | 1 | 1 | 1 | 0 | 1 | 0 |
-| 59 | 1 | 1 | 1 | 0 | 1 | 1 |
-| 60 | 1 | 1 | 1 | 1 | 0 | 0 |
-| 61 | 1 | 1 | 1 | 1 | 0 | 1 |
-| 62 | 1 | 1 | 1 | 1 | 1 | 0 |
-| 63 | 1 | 1 | 1 | 1 | 1 | 1 |
-+----+---+---+---+---+---+---+
-*/
- myNdbOperation->insertTuple();
- myNdbOperation->equal(COL_NAME[0], num);
- for(int col = 1; col < COL_LEN; col++)
- {
- myNdbOperation->setValue(COL_NAME[col], (num>>(COL_LEN-1-col))&1);
- }
- }
-
- int check = myTrans->execute(NdbTransaction::Commit);
-
- myTrans->close();
-
- if (check == -1)
- return NDBT_FAILED;
- else
- return NDBT_OK;
-
-}
-
-
-
-/*
-* a=AND, o=OR, A=NAND, O=NOR
-*/
-char op_string[] = "aoAO";
-/*
-* the six columns' name of test table
-*/
-char col_string[] = "ijklmn";
-const int op_len = strlen(op_string);
-const int col_len = strlen(col_string);
-
-/*
-* get a random op from "aoAO"
-*/
-int get_rand_op_ch(char *ch)
-{
- static unsigned int num = 0;
- if(++num == 0)
- num = 1;
- srand(num*time(NULL));
- *ch = op_string[rand() % op_len];
- return 1;
-}
-
-/*
-* get a random order form of "ijklmn" trough exchanging letter
-*/
-void change_col_order()
-{
- int pos1,pos2;
- char temp;
- for (int i = 0; i < 10; i++) //exchange for 10 times
- {
- srand(time(NULL)/(i+1));
- pos1 = rand() % col_len;
- srand((i+1)*time(NULL));
- pos2 = rand() % col_len;
- if (pos1 == pos2)
- continue;
- temp = col_string[pos1];
- col_string[pos1] = col_string[pos2];
- col_string[pos2] = temp;
- }
-}
-
-/*
-* get a random sub string of "ijklmn"
-*/
-int get_rand_col_str(char *str)
-{
- int len;
- static unsigned int num = 0;
- if(++num == 0)
- num = 1;
- srand(num*time(NULL));
- len = rand() % col_len + 1;
- change_col_order();
- snprintf(str, len+1, "%s", col_string); //len+1, including '\0'
- return len;
-}
-
-/*
-* get a random string including operation and column
-* eg, Alnikx
-*/
-int get_rand_op_str(char *str)
-{
- char temp[256];
- int len1, len2, len;
- len1 = get_rand_op_ch(temp);
- len2 = get_rand_col_str(temp+len1);
- len = len1 + len2;
- temp[len] = 'x';
- snprintf(str, len+1+1, "%s", temp); //len+1, including '\0'
- return len+1;
-}
-
-/*
-* replace a letter of source string with a new string
-* e.g., source string: 'Aijkx', replace i with new string 'olmx'
-* then source string is changed to 'Aolmxjkx'
-* source: its format should be produced from get_rand_op_str()
-* pos: range from 1 to strlen(source)-2
-*/
-int replace_a_to_str(char *source, int pos, char *newstr)
-{
- char temp[MAX_STR_LEN];
- snprintf(temp, pos+1, "%s", source);
- snprintf(temp+pos, strlen(newstr)+1, "%s", newstr);
- snprintf(temp+pos+strlen(newstr), strlen(source)-pos, "%s", source+pos+1);
- snprintf(source, strlen(temp)+1, "%s", temp);
- return strlen(source);
-}
-
-/*
-* check whether the inputed char is an operation
-*/
-bool check_op(char ch)
-{
- if( ch == 'a' || ch == 'A' || ch == 'o' || ch == 'O')
- return true;
- else
- return false;
-}
-
-/*
-* check whether the inputed char is end flag
-*/
-bool check_end(char ch)
-{
- return (ch == 'x');
-}
-
-/*
-* check whether the inputed char is end flag
-*/
-bool check_col(char ch)
-{
- if( ch == 'i' || ch == 'j' || ch == 'k'
- || ch == 'l' || ch == 'm' || ch == 'n' )
- return true;
- else
- return false;
-}
-
-/*
-* To ensure we can get a random string with RECURSIVE_LEVEL,
-* we need a position where can replace a letter with a new string.
-*/
-int get_rand_replace_pos(char *str, int len)
-{
- int pos_op = 0;
- int pos_x = 0;
- int pos_col = 0;
- int span = 0;
- static int num = 0;
- char temp;
-
- for(int i = 0; i < len; i++)
- {
- temp = str[i];
- if(! check_end(temp))
- {
- if(check_op(temp))
- pos_op = i;
- }
- else
- {
- pos_x = i;
- break;
- }
- }
-
- if(++num == 0)
- num = 1;
-
- span = pos_x - pos_op - 1;
- if(span <= 1)
- {
- pos_col = pos_op + 1;
- }
- else
- {
- srand(num*time(NULL));
- pos_col = pos_op + rand() % span + 1;
- }
- return pos_col;
-}
-
-/*
-* Check whether the given random string is valid
-* and applicable for this test case
-*/
-bool check_random_str(char *str)
-{
- char *p;
- int op_num = 0;
- int end_num = 0;
-
- for(p = str; *p; p++)
- {
- bool tmp1 = false, tmp2 = false;
- if(tmp1 = check_op(*p))
- op_num++;
- if(tmp2 = check_end(*p))
- end_num++;
- if(!(tmp1 || tmp2 || check_col(*p))) //there are illegal letters
- return false;
- }
-
- if(op_num != end_num) //begins are not equal to ends
- return false;
-
- return true;
-}
-
-/*
-* Get a random string with RECURSIVE_LEVEL
-*/
-void get_rand_op_str_compound(char *str)
-{
- char small_str[256];
- int pos;
- int tmp;
- int level;
- static int num = 0;
-
- if(++num == 0)
- num = 1;
-
- srand(num*time(NULL));
- level = 1 + rand() % RECURSIVE_LEVEL;
-
- get_rand_op_str(str);
-
- for(int i = 0; i < level; i++)
- {
- get_rand_op_str(small_str);
- tmp = strlen(small_str);
- get_rand_op_str(small_str + tmp); //get two operations
- pos = get_rand_replace_pos(str, strlen(str));
- replace_a_to_str(str, pos, small_str);
- }
-
- //check the random string
- if(!check_random_str(str))
- {
- fprintf(stderr, "Error random string! \n");
- exit(-1);
- }
-}
-
-/*
-* get column id of i,j,k,l,m,n
-*/
-int get_column_id(char ch)
-{
- return (ch - 'i' + 1); //from 1 to 6
-}
-
-/*
-* check whether column value of the NO. tuple is equal to 1
-* col_id: column id, range from 1 to 6
-* tuple_no: record NO., range from 0 to 63
-*/
-bool check_col_equal_one(int tuple_no, int col_id)
-{
- int i = (int)pow((double)2, (double)(6 - col_id));
- int j = tuple_no / i;
- if(j % 2)
- return true;
- else
- return false;
-}
-
-/*
-* get a result after all elements in the array with AND
-* value: pointer to a bool array
-* len: length of the bool array
-*/
-bool AND_op(bool *value, int len)
-{
- for(int i = 0; i < len; i++)
- {
- if(! value[i])
- return false;
- }
- return true;
-}
-
-/*
-* get a result after all elements in the array with OR
-* value: pointer to a bool array
-* len: length of the bool array
-*/
-bool OR_op(bool *value, int len)
-{
- for(int i = 0; i < len; i++)
- {
- if(value[i])
- return true;
- }
- return false;
-}
-
-/*
-* get a result after all elements in the array with NAND
-* value: pointer to a bool array
-* len: length of the bool array
-*/
-bool NAND_op(bool *value, int len)
-{
- return (! AND_op(value, len));
-}
-
-/*
-* get a result after all elements in the array with NOR
-* value: pointer to a bool array
-* len: length of the bool array
-*/
-bool NOR_op(bool *value, int len)
-{
- return (! OR_op(value, len));
-}
-
-/*
-* AND/NAND/OR/NOR operation for a bool array
-*/
-bool calculate_one_op(char op_type, bool *value, int len)
-{
- switch(op_type)
- {
- case 'a':
- return AND_op(value, len);
- break;
- case 'o':
- return OR_op(value, len);
- break;
- case 'A':
- return NAND_op(value, len);
- break;
- case 'O':
- return NOR_op(value, len);
- break;
- }
- return false; //make gcc happy
-}
-
-typedef struct _stack_element
-{
- char type;
- int num;
-}stack_element;
-
-/*
-* stack_op, store info for AND,OR,NAND,NOR
-* stack_col, store value of column(i,j,k,l,m,n) and temporary result for an operation
-*/
-stack_element stack_op[RECURSIVE_LEVEL * COL_LEN];
-bool stack_col[RECURSIVE_LEVEL * COL_LEN * 2];
-
-/*
-* check whether the given tuple is chosen by judgement condition
-* tuple_no, the NO of tuple in TABLE_NAME, range from 0 to TUPLE_NUM
-* str: a random string of scan opearation and condition
-* len: length of str
-*/
-bool check_one_tuple(int tuple_no, char *str, int len)
-{
- int pop_op = 0;
- int pop_col = 0;
- for(int i = 0; i < len; i++)
- {
- char letter = *(str + i);
- if(check_op(letter)) //push
- {
- stack_op[pop_op].type = letter;
- stack_op[pop_op].num = 0;
- pop_op++;
- }
- if(check_col(letter)) //push
- {
- stack_col[pop_col] = check_col_equal_one(tuple_no, get_column_id(letter));
- pop_col++;
- stack_op[pop_op-1].num += 1;
- }
- if(check_end(letter))
- {
- if(pop_op <= 1)
- {
- return calculate_one_op(stack_op[pop_op-1].type,
- stack_col,
- stack_op[pop_op-1].num);
- }
- else
- {
- bool tmp1 = calculate_one_op(stack_op[pop_op-1].type,
- stack_col + pop_col - stack_op[pop_op-1].num,
- stack_op[pop_op-1].num);
- pop_col -= stack_op[pop_op-1].num; //pop
- pop_op--;
- stack_col[pop_col] = tmp1; //push
- pop_col++;
- stack_op[pop_op-1].num += 1;
- }
- }
- }
- return false; //make gcc happy
-}
-
-/*
-* get lists of tuples which match the scan condiction through calculating
-* str: a random string of scan opearation and condition
-*/
-void check_all_tuples(char *str, bool *res)
-{
- for (int i = 0; i < TUPLE_NUM; i++)
- {
- if(check_one_tuple(i, str, strlen(str)))
- res[i] = true;
- }
-}
-
-/*
-* convert a letter to group number what ndbapi need
-*/
-NdbScanFilter::Group get_api_group(char op_name)
-{
- switch (op_name) {
- case 'a': return NdbScanFilter::AND;
- case 'o': return NdbScanFilter::OR;
- case 'A': return NdbScanFilter::NAND;
- case 'O': return NdbScanFilter::NOR;
- default:
- fprintf(stderr, "Invalid group name %c !\n", op_name);
- exit(3);
- }
-}
-
-/*
-* with ndbapi, call begin, eq/ne/lt/gt/le/ge..., end
-*/
-NdbScanFilter * call_ndbapi(char *str, NdbTransaction *transaction,
- NdbScanOperation *scan, NdbDictionary::Column const *col[])
-{
- NdbScanFilter *scanfilter = new NdbScanFilter(scan);
- char *p;
-
- for (p = str; *p; p++)
- {
- if(check_op(*p))
- {
- if(scanfilter->begin(get_api_group(*p)))
- ERR_EXIT(transaction, "filter begin() failed");
- }
- if(check_col(*p))
- {
- if(scanfilter->eq(col[*p-'i'+1]->getColumnNo(), (Uint32)1))
- ERR_EXIT(transaction, "filter eq() failed");
- }
- if(check_end(*p))
- {
- if(scanfilter->end())
- ERR_EXIT(transaction, "filter end() failed");
- }
- }
-
- return scanfilter;
-}
-
-/*
-* get the tuples through ndbapi, and save the tuples NO.
-* str: a random string of scan opearation and condition
-*/
-void ndbapi_tuples(Ndb *ndb, char *str, bool *res)
-{
- const NdbDictionary::Dictionary *dict = ndb->getDictionary();
- if (!dict)
- ERR_EXIT(ndb, "Can't get dict");
-
- const NdbDictionary::Table *table = dict->getTable(TABLE_NAME);
- if (!table)
- ERR_EXIT(dict, "Can't get table"TABLE_NAME);
-
- const NdbDictionary::Column *col[COL_LEN];
- for(int i = 0; i < COL_LEN; i++)
- {
- char tmp[128];
- col[i] = table->getColumn(COL_NAME[i]);
- if(!col[i])
- {
- snprintf(tmp, 128, "Can't get column %s", COL_NAME[i]);
- ERR_EXIT(dict, tmp);
- }
- }
-
- NdbTransaction *transaction;
- NdbScanOperation *scan;
- NdbScanFilter *filter;
-
- transaction = ndb->startTransaction();
- if (!transaction)
- ERR_EXIT(ndb, "Can't start transaction");
-
- scan = transaction->getNdbScanOperation(table);
- if (!scan)
- ERR_EXIT(transaction, "Can't get scan op");
-
- if (scan->readTuples(NdbOperation::LM_Exclusive))
- ERR_EXIT(scan, "Can't set up read");
-
- NdbRecAttr *rec[COL_LEN];
- for(int i = 0; i < COL_LEN; i++)
- {
- char tmp[128];
- rec[i] = scan->getValue(COL_NAME[i]);
- if(!rec[i])
- {
- snprintf(tmp, 128, "Can't get rec of %s", COL_NAME[i]);
- ERR_EXIT(scan, tmp);
- }
- }
-
- filter = call_ndbapi(str, transaction, scan, col);
-
- if (transaction->execute(NdbTransaction::NoCommit))
- ERR_EXIT(transaction, "Can't execute");
-
- int i,j,k,l,m,n;
- while (scan->nextResult(true) == 0)
- {
- do
- {
- i = rec[1]->u_32_value();
- j = rec[2]->u_32_value();
- k = rec[3]->u_32_value();
- l = rec[4]->u_32_value();
- m = rec[5]->u_32_value();
- n = rec[6]->u_32_value();
- res[32*i+16*j+8*k+4*l+2*m+n] = true;
- } while (scan->nextResult(false) == 0);
- }
-
- delete filter;
- transaction->close();
-}
-
-/*
-* compare the result between calculation and NDBAPI
-* str: a random string of scan opearation and condition
-* return: true stands for ndbapi ok, false stands for ndbapi failed
-*/
-template class Vector<bool>;
-bool compare_cal_ndb(char *str, Ndb *ndb)
-{
- Vector<bool> res_cal;
- Vector<bool> res_ndb;
-
- for(int i = 0; i < TUPLE_NUM; i++)
- {
- res_cal.push_back(false);
- res_ndb.push_back(false);
- }
-
- check_all_tuples(str, res_cal.getBase());
- ndbapi_tuples(ndb, str, res_ndb.getBase());
-
- for(int i = 0; i < TUPLE_NUM; i++)
- {
- if(res_cal[i] != res_ndb[i])
- return false;
- }
- return true;
-}
-
-
-int runCreateTables(NDBT_Context* ctx, NDBT_Step* step)
-{
- Ndb *pNdb = GETNDB(step);
- pNdb->getDictionary()->dropTable(MYTAB1.getName());
- int ret = createTable(pNdb, &MYTAB1, false, true, 0);
- if(ret)
- return ret;
- return NDBT_OK;
-}
-
-
-int runDropTables(NDBT_Context* ctx, NDBT_Step* step)
-{
- int ret = GETNDB(step)->getDictionary()->dropTable(MYTAB1.getName());
- if(ret == -1)
- return NDBT_FAILED;
-
- return NDBT_OK;
-}
-
-int runScanRandomFilterTest(NDBT_Context* ctx, NDBT_Step* step)
-{
- char random_str[MAX_STR_LEN];
- Ndb *myNdb = GETNDB(step);
- bool res = true;
-
- for(int i = 0; i < TEST_NUM; i++)
- {
- get_rand_op_str_compound(random_str);
- if( !compare_cal_ndb(random_str, myNdb))
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-NDBT_TESTSUITE(testScanFilter);
-TESTCASE(TEST_NAME,
- "Scan table TABLE_NAME for the records which accord with \
- conditions of logical scan operations: AND/OR/NAND/NOR")
-{
- INITIALIZER(runCreateTables);
- INITIALIZER(runPopulate);
- INITIALIZER(runScanRandomFilterTest);
- FINALIZER(runDropTables);
-}
-
-NDBT_TESTSUITE_END(testScanFilter);
-
-
-int main(int argc, const char** argv)
-{
- ndb_init();
-
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1))
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- return testScanFilter.executeOneCtx(con, &MYTAB1, TEST_NAME);
-}
diff --git a/storage/ndb/test/ndbapi/testScanInterpreter.cpp b/storage/ndb/test/ndbapi/testScanInterpreter.cpp
deleted file mode 100644
index f734c4ee76a..00000000000
--- a/storage/ndb/test/ndbapi/testScanInterpreter.cpp
+++ /dev/null
@@ -1,281 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include "NDBT_Test.hpp"
-#include "NDBT_ReturnCodes.h"
-#include "HugoTransactions.hpp"
-#include "UtilTransactions.hpp"
-#include "NdbRestarter.hpp"
-#include <Vector.hpp>
-#include "ScanFilter.hpp"
-#include "ScanInterpretTest.hpp"
-
-int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
-
- int records = ctx->getNumRecords();
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.loadTable(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
-
- UtilTransactions utilTrans(*ctx->getTab());
- if (utilTrans.clearTable2(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runClearResTable(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
- const NdbDictionary::Table* pResTab =
- GETNDB(step)->getDictionary()->getTable(ctx->getProperty("ResultTabName", "NULL"));
-
- UtilTransactions utilTrans(*pResTab);
- if (utilTrans.clearTable2(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runScanRead(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int parallelism = ctx->getProperty("Parallelism", 1);
-
- int i = 0;
- HugoTransactions hugoTrans(*ctx->getTab());
- while (i<loops) {
- g_info << i << ": ";
- if (hugoTrans.scanReadRecords(GETNDB(step), records, 0, parallelism) != 0){
- return NDBT_FAILED;
- }
- i++;
- }
- return NDBT_OK;
-}
-
-int runScanReadResTable(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
- int parallelism = ctx->getProperty("Parallelism", 1);
- const NdbDictionary::Table* pResTab =
- NDBT_Table::discoverTableFromDb(GETNDB(step),
- ctx->getProperty("ResultTabName", "NULL"));
-
- HugoTransactions hugoTrans(*pResTab);
- if (hugoTrans.scanReadRecords(GETNDB(step), records, 0, parallelism) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runCreateResultTable(NDBT_Context* ctx, NDBT_Step* step){
-
- const NdbDictionary::Table* pTab = ctx->getTab();
- char newTabName[256];
- BaseString::snprintf(newTabName, 256, "%s_RES", pTab->getName());
- ctx->setProperty("ResultTabName", newTabName);
-
- NdbDictionary::Table resTab(* pTab);
- resTab.setName(newTabName);
-
- if (GETNDB(step)->getDictionary()->createTable(resTab) != 0){
- g_err << newTabName << " creation failed!"<< endl;
- return NDBT_FAILED;
- }else{
- g_info << newTabName << " created!"<< endl;
- return NDBT_OK;
- }
-}
-
-int scanWithFilter(NDBT_Context* ctx, NDBT_Step* step, ScanFilter& filt){
- int records = ctx->getNumRecords();
- const char* resTabName = ctx->getProperty("ResultTabName", "NULL");
- if (strcmp(resTabName, "NULL") == 0)
- return NDBT_FAILED;
- const NdbDictionary::Table* pTab = ctx->getTab();
- const NdbDictionary::Table* pResTab = NDBT_Table::discoverTableFromDb(GETNDB(step), resTabName);
- if (pResTab == NULL)
- return NDBT_FAILED;
-
- ScanInterpretTest interpretTest(*pTab, *pResTab);
- if (interpretTest.scanRead(GETNDB(step),
- records,
- 16,
- filt) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-int runScanLessThan(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
- LessThanFilter filt(records);
- return scanWithFilter(ctx, step, filt);
-}
-int runScanEqual(NDBT_Context* ctx, NDBT_Step* step){
- EqualFilter filt;
- return scanWithFilter(ctx, step, filt);
-}
-
-int scanVerifyWithFilter(NDBT_Context* ctx, NDBT_Step* step, ScanFilter& filt){
- int records = ctx->getNumRecords();
- const char* resTabName = ctx->getProperty("ResultTabName", "NULL");
- if (strcmp(resTabName, "NULL") == 0)
- return NDBT_FAILED;
- const NdbDictionary::Table* pTab = ctx->getTab();
- const NdbDictionary::Table* pResTab = NDBT_Table::discoverTableFromDb(GETNDB(step), resTabName);
- if (pResTab == NULL)
- return NDBT_FAILED;
-
- ScanInterpretTest interpretTest(*pTab, *pResTab);
- if (interpretTest.scanReadVerify(GETNDB(step),
- records,
- 16,
- filt) != NDBT_OK){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-int runScanLessThanVerify(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
- LessThanFilter filt(records);
- return scanVerifyWithFilter(ctx, step, filt);
-}
-int runScanEqualVerify(NDBT_Context* ctx, NDBT_Step* step){
- EqualFilter filt;
- return scanVerifyWithFilter(ctx, step, filt);
-}
-
-int runScanEqualLoop(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops();
- int l = 0;
- EqualFilter filt;
- while(l < loops){
- if (scanWithFilter(ctx, step, filt) != NDBT_OK)
- return NDBT_FAILED;
- if (runClearResTable(ctx, step) != NDBT_OK)
- return NDBT_FAILED;
- l++;
- }
- return NDBT_OK;
-}
-
-
-int runScanEqualVerifyLoop(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops();
- int l = 0;
- EqualFilter filt;
- while(l < loops){
- if (scanWithFilter(ctx, step, filt) != NDBT_OK)
- return NDBT_FAILED;
- if (scanVerifyWithFilter(ctx, step, filt) != NDBT_OK)
- return NDBT_FAILED;
- if (runClearResTable(ctx, step) != NDBT_OK)
- return NDBT_FAILED;
- l++;
- }
- return NDBT_OK;
-}
-
-int runScanLessThanLoop(NDBT_Context* ctx, NDBT_Step* step){
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int l = 0;
- LessThanFilter filt(records);
- while(l < loops){
- if (scanWithFilter(ctx, step, filt) != NDBT_OK)
- return NDBT_FAILED;
- if (runClearResTable(ctx, step) != NDBT_OK)
- return NDBT_FAILED;
- l++;
- }
- return NDBT_OK;
-}
-
-NDBT_TESTSUITE(testScanInterpreter);
-TESTCASE("ScanLessThan",
- "Read all records in table TX with attrX less "\
- "than a value and store the resultset in TX_RES."\
- "Then compare records in TX_RES with records in TX."){
- // TABLE("T1");
- // TABLE("T2");
- INITIALIZER(runLoadTable);
- INITIALIZER(runCreateResultTable);
- STEP(runScanLessThan);
- VERIFIER(runScanLessThanVerify);
- FINALIZER(runClearTable);
- FINALIZER(runClearResTable);
-}
-TESTCASE("ScanEqual",
- "Read all records in table TX with attrX equal "\
- "to a value and store the resultset in TX_RES."\
- "Then compare records in TX_RES with records in TX."){
- // TABLE("T1");
- // TABLE("T2");
- INITIALIZER(runLoadTable);
- INITIALIZER(runCreateResultTable);
- STEP(runScanEqual);
- VERIFIER(runScanEqualVerify);
- FINALIZER(runClearTable);
- FINALIZER(runClearResTable);
-}
-TESTCASE("ScanEqualLoop",
- "Scan all records in TX equal to a value."\
- "Do this loop number of times"){
- // TABLE("T1");
- // TABLE("T2");
- INITIALIZER(runLoadTable);
- INITIALIZER(runCreateResultTable);
- STEP(runScanEqualLoop);
- FINALIZER(runClearTable);
- FINALIZER(runClearResTable);
-}
-TESTCASE("ScanEqualVerifyLoop",
- "Scan all records in TX equal to a value."\
- "Verify record in TX_RES table"\
- "Do this loop number of times"){
- // TABLE("T1");
- // TABLE("T2");
- INITIALIZER(runLoadTable);
- INITIALIZER(runCreateResultTable);
- STEP(runScanEqualVerifyLoop);
- FINALIZER(runClearTable);
- FINALIZER(runClearResTable);
-}
-TESTCASE("ScanLessThanLoop",
- "Scan all records in TX less than a value."\
- "Do this loop number of times"){
- // TABLE("T1");
- // TABLE("T2");
- INITIALIZER(runLoadTable);
- INITIALIZER(runCreateResultTable);
- STEP(runScanLessThanLoop);
- FINALIZER(runClearTable);
- FINALIZER(runClearResTable);
-}
-NDBT_TESTSUITE_END(testScanInterpreter);
-
-int main(int argc, const char** argv){
- ndb_init();
- return testScanInterpreter.execute(argc, argv);
-}
-
-
-
diff --git a/storage/ndb/test/ndbapi/testScanPerf.cpp b/storage/ndb/test/ndbapi/testScanPerf.cpp
deleted file mode 100644
index cea281bf9e1..00000000000
--- a/storage/ndb/test/ndbapi/testScanPerf.cpp
+++ /dev/null
@@ -1,372 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT.hpp>
-#include <NDBT_Test.hpp>
-#include <HugoTransactions.hpp>
-#include <UtilTransactions.hpp>
-#include <random.h>
-#include <getarg.h>
-
-struct Parameter {
- char * name;
- unsigned value;
- unsigned min;
- unsigned max;
-};
-
-#define P_BATCH 0
-#define P_PARRA 1
-#define P_LOCK 2
-#define P_FILT 3
-#define P_BOUND 4
-#define P_ACCESS 5
-#define P_FETCH 6
-#define P_ROWS 7
-#define P_LOOPS 8
-#define P_CREATE 9
-#define P_RESET 11
-#define P_MULTI 12
-
-#define P_MAX 13
-
-static
-Parameter
-g_paramters[] = {
- { "batch", 0, 0, 1 }, // 0, 15
- { "parallelism", 0, 0, 1 }, // 0, 1
- { "lock", 0, 0, 2 }, // read, exclusive, dirty
- { "filter", 0, 0, 3 }, // all, none, 1, 100
- { "range", 0, 0, 3 }, // all, none, 1, 100
- { "access", 0, 0, 2 }, // scan, idx, idx sorted
- { "fetch", 0, 0, 1 }, // No, yes
- { "size", 1000000, 1, ~0 },
- { "iterations", 3, 1, ~0 },
- { "create_drop", 1, 0, 1 },
- { "data", 1, 0, 1 },
- { "q-reset bounds", 0, 1, 0 },
- { "multi read range", 1000, 1, ~0 }
-};
-
-static Ndb* g_ndb = 0;
-static const NdbDictionary::Table * g_table;
-static const NdbDictionary::Index * g_index;
-static char g_tablename[256];
-static char g_indexname[256];
-
-int create_table();
-int run_scan();
-
-int
-main(int argc, const char** argv){
- ndb_init();
- int verbose = 1;
- int optind = 0;
-
- struct getargs args[1+P_MAX] = {
- { "verbose", 'v', arg_flag, &verbose, "Print verbose status", "verbose" }
- };
- const int num_args = 1 + P_MAX;
- int i;
- for(i = 0; i<P_MAX; i++){
- args[i+1].long_name = g_paramters[i].name;
- args[i+1].short_name = * g_paramters[i].name;
- args[i+1].type = arg_integer;
- args[i+1].value = &g_paramters[i].value;
- BaseString tmp;
- tmp.assfmt("min: %d max: %d", g_paramters[i].min, g_paramters[i].max);
- args[i+1].help = strdup(tmp.c_str());
- args[i+1].arg_help = 0;
- }
-
- if(getarg(args, num_args, argc, argv, &optind)) {
- arg_printusage(args, num_args, argv[0], "tabname1 tabname2 ...");
- return NDBT_WRONGARGS;
- }
-
- myRandom48Init(NdbTick_CurrentMillisecond());
-
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1))
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- g_ndb = new Ndb(&con, "TEST_DB");
- if(g_ndb->init() != 0){
- g_err << "init() failed" << endl;
- goto error;
- }
- if(g_ndb->waitUntilReady() != 0){
- g_err << "Wait until ready failed" << endl;
- goto error;
- }
- for(i = optind; i<argc; i++){
- const char * T = argv[i];
- g_info << "Testing " << T << endl;
- BaseString::snprintf(g_tablename, sizeof(g_tablename), T);
- BaseString::snprintf(g_indexname, sizeof(g_indexname), "IDX_%s", T);
- if(create_table())
- goto error;
- if(run_scan())
- goto error;
- }
-
- if(g_ndb) delete g_ndb;
- return NDBT_OK;
- error:
- if(g_ndb) delete g_ndb;
- return NDBT_FAILED;
-}
-
-int
-create_table(){
- NdbDictionary::Dictionary* dict = g_ndb->getDictionary();
- assert(dict);
- if(g_paramters[P_CREATE].value){
- g_ndb->getDictionary()->dropTable(g_tablename);
- const NdbDictionary::Table * pTab = NDBT_Tables::getTable(g_tablename);
- assert(pTab);
- NdbDictionary::Table copy = * pTab;
- copy.setLogging(false);
- if(dict->createTable(copy) != 0){
- g_err << "Failed to create table: " << g_tablename << endl;
- return -1;
- }
-
- NdbDictionary::Index x(g_indexname);
- x.setTable(g_tablename);
- x.setType(NdbDictionary::Index::OrderedIndex);
- x.setLogging(false);
- for (unsigned k = 0; k < copy.getNoOfColumns(); k++){
- if(copy.getColumn(k)->getPrimaryKey()){
- x.addColumnName(copy.getColumn(k)->getName());
- }
- }
-
- if(dict->createIndex(x) != 0){
- g_err << "Failed to create index: " << endl;
- return -1;
- }
- }
- g_table = dict->getTable(g_tablename);
- g_index = dict->getIndex(g_indexname, g_tablename);
- assert(g_table);
- assert(g_index);
-
- if(g_paramters[P_CREATE].value)
- {
- int rows = g_paramters[P_ROWS].value;
- HugoTransactions hugoTrans(* g_table);
- if (hugoTrans.loadTable(g_ndb, rows)){
- g_err.println("Failed to load %s with %d rows",
- g_table->getName(), rows);
- return -1;
- }
- }
-
- return 0;
-}
-
-inline
-void err(NdbError e){
- ndbout << e << endl;
-}
-
-int
-run_scan(){
- int iter = g_paramters[P_LOOPS].value;
- NDB_TICKS start1, stop;
- int sum_time= 0;
-
- int sample_rows = 0;
- int tot_rows = 0;
- NDB_TICKS sample_start = NdbTick_CurrentMillisecond();
-
- Uint32 tot = g_paramters[P_ROWS].value;
-
- if(g_paramters[P_BOUND].value >= 2 || g_paramters[P_FILT].value == 2)
- iter *= g_paramters[P_ROWS].value;
-
- NdbScanOperation * pOp = 0;
- NdbIndexScanOperation * pIOp = 0;
- NdbConnection * pTrans = 0;
- int check = 0;
-
- for(int i = 0; i<iter; i++){
- start1 = NdbTick_CurrentMillisecond();
- pTrans = pTrans ? pTrans : g_ndb->startTransaction();
- if(!pTrans){
- g_err << "Failed to start transaction" << endl;
- err(g_ndb->getNdbError());
- return -1;
- }
-
- int par = g_paramters[P_PARRA].value;
- int bat = 0; // g_paramters[P_BATCH].value;
- NdbScanOperation::LockMode lm;
- switch(g_paramters[P_LOCK].value){
- case 0:
- lm = NdbScanOperation::LM_CommittedRead;
- break;
- case 1:
- lm = NdbScanOperation::LM_Read;
- break;
- case 2:
- lm = NdbScanOperation::LM_Exclusive;
- break;
- default:
- abort();
- }
-
- if(g_paramters[P_ACCESS].value == 0){
- pOp = pTrans->getNdbScanOperation(g_tablename);
- assert(pOp);
- pOp->readTuples(lm, bat, par);
- } else {
- if(g_paramters[P_RESET].value == 0 || pIOp == 0)
- {
- pOp= pIOp= pTrans->getNdbIndexScanOperation(g_indexname, g_tablename);
- bool ord = g_paramters[P_ACCESS].value == 2;
- pIOp->readTuples(lm, bat, par, ord);
- }
- else
- {
- pIOp->reset_bounds();
- }
-
- switch(g_paramters[P_BOUND].value){
- case 0: // All
- break;
- case 1: // None
- pIOp->setBound((Uint32)0, NdbIndexScanOperation::BoundEQ, 0);
- break;
- case 2: { // 1 row
- default:
- assert(g_table->getNoOfPrimaryKeys() == 1); // only impl. so far
- int tot = g_paramters[P_ROWS].value;
- int row = rand() % tot;
-#if 0
- fix_eq_bound(pIOp, row);
-#else
- pIOp->setBound((Uint32)0, NdbIndexScanOperation::BoundEQ, &row);
-#endif
- if(g_paramters[P_RESET].value == 2)
- goto execute;
- break;
- }
- case 3: { // read multi
- int multi = g_paramters[P_MULTI].value;
- int tot = g_paramters[P_ROWS].value;
- for(; multi > 0 && i < iter; --multi, i++)
- {
- int row = rand() % tot;
- pIOp->setBound((Uint32)0, NdbIndexScanOperation::BoundEQ, &row);
- pIOp->end_of_bound(i);
- }
- if(g_paramters[P_RESET].value == 2)
- goto execute;
- break;
- }
- }
- }
- assert(pOp);
-
- switch(g_paramters[P_FILT].value){
- case 0: // All
- check = pOp->interpret_exit_ok();
- break;
- case 1: // None
- check = pOp->interpret_exit_nok();
- break;
- case 2: { // 1 row
- default:
- assert(g_table->getNoOfPrimaryKeys() == 1); // only impl. so far
- abort();
-#if 0
- int tot = g_paramters[P_ROWS].value;
- int row = rand() % tot;
- NdbScanFilter filter(pOp) ;
- filter.begin(NdbScanFilter::AND);
- fix_eq(filter, pOp, row);
- filter.end();
- break;
-#endif
- }
- }
- if(check != 0){
- err(pOp->getNdbError());
- return -1;
- }
- assert(check == 0);
-
- if(g_paramters[P_RESET].value == 1)
- g_paramters[P_RESET].value = 2;
-
- for(int i = 0; i<g_table->getNoOfColumns(); i++){
- pOp->getValue(i);
- }
-
- if(g_paramters[P_RESET].value == 1)
- g_paramters[P_RESET].value = 2;
-execute:
- int rows = 0;
- check = pTrans->execute(NoCommit);
- assert(check == 0);
- int fetch = g_paramters[P_FETCH].value;
- while((check = pOp->nextResult(true)) == 0){
- do {
- rows++;
- } while(!fetch && ((check = pOp->nextResult(false)) == 0));
- if(check == -1){
- err(pTrans->getNdbError());
- return -1;
- }
- assert(check == 2);
- }
-
- if(check == -1){
- err(pTrans->getNdbError());
- return -1;
- }
- assert(check == 1);
- if(g_paramters[P_RESET].value == 0)
- {
- pTrans->close();
- pTrans = 0;
- }
- stop = NdbTick_CurrentMillisecond();
-
- int time_passed= (int)(stop - start1);
- sample_rows += rows;
- sum_time+= time_passed;
- tot_rows+= rows;
-
- if(sample_rows >= tot)
- {
- int sample_time = (int)(stop - sample_start);
- g_info << "Found " << sample_rows << " rows" << endl;
- g_err.println("Time: %d ms = %u rows/sec", sample_time,
- (1000*sample_rows)/sample_time);
- sample_rows = 0;
- sample_start = stop;
- }
- }
-
- g_err.println("Avg time: %d ms = %u rows/sec", sum_time/tot_rows,
- (1000*tot_rows)/sum_time);
- return 0;
-}
diff --git a/storage/ndb/test/ndbapi/testSystemRestart.cpp b/storage/ndb/test/ndbapi/testSystemRestart.cpp
deleted file mode 100644
index 891f5d1a945..00000000000
--- a/storage/ndb/test/ndbapi/testSystemRestart.cpp
+++ /dev/null
@@ -1,1863 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT.hpp>
-#include <NDBT_Test.hpp>
-#include <HugoTransactions.hpp>
-#include <UtilTransactions.hpp>
-#include <NdbRestarter.hpp>
-#include <Vector.hpp>
-#include <signaldata/DumpStateOrd.hpp>
-#include <NdbBackup.hpp>
-
-int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
-
- int records = ctx->getNumRecords();
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.loadTable(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-#define CHECK(b) if (!(b)) { \
- g_err << "ERR: "<< step->getName() \
- << " failed on line " << __LINE__ << endl; \
- result = NDBT_FAILED; \
- continue; }
-
-int runSystemRestart1(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- int result = NDBT_OK;
- int timeout = 300;
- Uint32 loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int count;
- NdbRestarter restarter;
- Uint32 i = 1;
-
- UtilTransactions utilTrans(*ctx->getTab());
- HugoTransactions hugoTrans(*ctx->getTab());
- while(i<=loops && result != NDBT_FAILED){
-
- ndbout << "Loop " << i << "/"<< loops <<" started" << endl;
- /*
- 1. Load data
- 2. Restart cluster and verify records
- 3. Update records
- 4. Restart cluster and verify records
- 5. Delete half of the records
- 6. Restart cluster and verify records
- 7. Delete all records
- 8. Restart cluster and verify records
- 9. Insert, update, delete records
- 10. Restart cluster and verify records
- 11. Insert, update, delete records
- 12. Restart cluster with error insert 5020 and verify records
- */
- ndbout << "Loading records..." << endl;
- CHECK(hugoTrans.loadTable(pNdb, records) == 0);
-
- ndbout << "Restarting cluster" << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- ndbout << "Verifying records..." << endl;
- CHECK(hugoTrans.pkReadRecords(pNdb, records) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == records);
-
- ndbout << "Updating records..." << endl;
- CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
-
- ndbout << "Restarting cluster..." << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- ndbout << "Verifying records..." << endl;
- CHECK(hugoTrans.pkReadRecords(pNdb, records) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == records);
-
- ndbout << "Deleting 50% of records..." << endl;
- CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);
-
- ndbout << "Restarting cluster..." << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- ndbout << "Verifying records..." << endl;
- CHECK(hugoTrans.scanReadRecords(pNdb, records/2, 0, 64) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == (records/2));
-
- ndbout << "Deleting all records..." << endl;
- CHECK(utilTrans.clearTable(pNdb, records/2) == 0);
-
- ndbout << "Restarting cluster..." << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- ndbout << "Verifying records..." << endl;
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == 0);
-
- ndbout << "Doing it all..." << endl;
- CHECK(hugoTrans.loadTable(pNdb, records) == 0);
- CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
- CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);
- CHECK(hugoTrans.scanUpdateRecords(pNdb, records/2) == 0);
- CHECK(utilTrans.clearTable(pNdb, records) == 0);
- CHECK(hugoTrans.loadTable(pNdb, records) == 0);
- CHECK(utilTrans.clearTable(pNdb, records) == 0);
- CHECK(hugoTrans.loadTable(pNdb, records) == 0);
- CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
- CHECK(utilTrans.clearTable(pNdb, records) == 0);
-
- ndbout << "Restarting cluster..." << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- ndbout << "Verifying records..." << endl;
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == 0);
-
- ndbout << "Doing it all..." << endl;
- CHECK(hugoTrans.loadTable(pNdb, records) == 0);
- CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
- CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);
- CHECK(hugoTrans.scanUpdateRecords(pNdb, records/2) == 0);
- CHECK(utilTrans.clearTable(pNdb, records) == 0);
- CHECK(hugoTrans.loadTable(pNdb, records) == 0);
- CHECK(utilTrans.clearTable(pNdb, records) == 0);
-
- ndbout << "Restarting cluster with error insert 5020..." << endl;
- CHECK(restarter.restartAll(false, true) == 0);
- CHECK(restarter.waitClusterNoStart(timeout) == 0);
- CHECK(restarter.insertErrorInAllNodes(5020) == 0);
- CHECK(restarter.startAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- i++;
- }
-
- ndbout << "runSystemRestart1 finished" << endl;
-
- return result;
-}
-
-int runSystemRestart2(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- int result = NDBT_OK;
-/// int timeout = 300;
- int timeout = 120;
- Uint32 loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int count;
- NdbRestarter restarter;
- Uint32 i = 1;
-
- UtilTransactions utilTrans(*ctx->getTab());
- HugoTransactions hugoTrans(*ctx->getTab());
- while(i<=loops && result != NDBT_FAILED && !ctx->isTestStopped()){
-
- ndbout << "Loop " << i << "/"<< loops <<" started" << endl;
- /* Use error 7070 to set time between LCP to it's min value
- 1. Load data
- 2. Restart cluster and verify records
- 3. Update records
- 4. Restart cluster and verify records
- 5. Delete half of the records
- 6. Restart cluster and verify records
- 7. Delete all records
- 8. Restart cluster and verify records
- 9. Insert, update, delete records
- 10. Restart cluster and verify records
- */
- int val = DumpStateOrd::DihMinTimeBetweenLCP;
- CHECK(restarter.dumpStateAllNodes(&val, 1) == 0);
-
- ndbout << "Loading records..." << endl;
- CHECK(hugoTrans.loadTable(pNdb, records) == 0);
-
- ndbout << "Restarting cluster" << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- {
- int val = DumpStateOrd::DihMinTimeBetweenLCP;
- CHECK(restarter.dumpStateAllNodes(&val, 1) == 0);
- }
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- ndbout << "Verifying records..." << endl;
- CHECK(hugoTrans.pkReadRecords(pNdb, records) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == records);
-
- ndbout << "Updating records..." << endl;
- CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
-
- ndbout << "Restarting cluster..." << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- {
- int val = DumpStateOrd::DihMinTimeBetweenLCP;
- CHECK(restarter.dumpStateAllNodes(&val, 1) == 0);
- }
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- ndbout << "Verifying records..." << endl;
- CHECK(hugoTrans.pkReadRecords(pNdb, records) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == records);
-
- ndbout << "Deleting 50% of records..." << endl;
- CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);
-
- ndbout << "Restarting cluster..." << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- {
- int val = DumpStateOrd::DihMinTimeBetweenLCP;
- CHECK(restarter.dumpStateAllNodes(&val, 1) == 0);
- }
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- ndbout << "Verifying records..." << endl;
- CHECK(hugoTrans.scanReadRecords(pNdb, records/2, 0, 64) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == (records/2));
-
- ndbout << "Deleting all records..." << endl;
- CHECK(utilTrans.clearTable(pNdb, records/2) == 0);
-
- ndbout << "Restarting cluster..." << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- {
- int val = DumpStateOrd::DihMinTimeBetweenLCP;
- CHECK(restarter.dumpStateAllNodes(&val, 1) == 0);
- }
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- ndbout << "Verifying records..." << endl;
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == 0);
-
- ndbout << "Doing it all..." << endl;
- CHECK(hugoTrans.loadTable(pNdb, records) == 0);
- CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
- CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);
- CHECK(hugoTrans.scanUpdateRecords(pNdb, records/2) == 0);
- CHECK(utilTrans.clearTable(pNdb, records) == 0);
- CHECK(hugoTrans.loadTable(pNdb, records) == 0);
- CHECK(utilTrans.clearTable(pNdb, records) == 0);
- CHECK(hugoTrans.loadTable(pNdb, records) == 0);
- CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
- CHECK(utilTrans.clearTable(pNdb, records) == 0);
-
- ndbout << "Restarting cluster..." << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- {
- int val = DumpStateOrd::DihMinTimeBetweenLCP;
- CHECK(restarter.dumpStateAllNodes(&val, 1) == 0);
- }
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- ndbout << "Verifying records..." << endl;
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == 0);
-
- i++;
- }
-
- ndbout << "runSystemRestart2 finished" << endl;
-
- return result;
-}
-
-int runSystemRestartTestUndoLog(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- int result = NDBT_OK;
- int timeout = 300;
- Uint32 loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int count;
- NdbRestarter restarter;
- Uint32 i = 1;
-
- int dump7080[2];
- dump7080[0] = 7080;
- dump7080[1] = ctx->getTab()->getTableId();
-
- UtilTransactions utilTrans(*ctx->getTab());
- HugoTransactions hugoTrans(*ctx->getTab());
- while(i<=loops && result != NDBT_FAILED){
-
- ndbout << "Loop " << i << "/"<< loops <<" started" << endl;
- /*
- 1. Start LCP, turn on undologging but delay write of datapages.
- 2. Insert, update, delete records
- 3. Complete writing of data pages and finish LCP.
- 4. Restart cluster and verify records
- */
- // Use dump state 7080 to delay writing of datapages
- // for the current table
- ndbout << "Dump state: "<<dump7080[0]<<", "<<dump7080[1]<<endl;
- CHECK(restarter.dumpStateAllNodes(dump7080, 2) == 0);
- NdbSleep_SecSleep(10);
-
- ndbout << "Doing it all..." << endl;
- CHECK(hugoTrans.loadTable(pNdb, records) == 0);
- CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
- CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);
- CHECK(hugoTrans.scanUpdateRecords(pNdb, records/2) == 0);
- CHECK(utilTrans.clearTable(pNdb, records) == 0);
- CHECK(hugoTrans.loadTable(pNdb, records) == 0);
- CHECK(utilTrans.clearTable(pNdb, records) == 0);
-
- // Reset error and let LCP continue
- CHECK(restarter.insertErrorInAllNodes(0) == 0);
- NdbSleep_SecSleep(60);
-
- ndbout << "Restarting cluster..." << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- ndbout << "Verifying records..." << endl;
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == 0);
-
- // Use dump state 7080 to delay writing of datapages
- // for the current table
- ndbout << "Dump state: "<<dump7080[0]<<", "<<dump7080[1]<<endl;
- CHECK(restarter.dumpStateAllNodes(dump7080, 2) == 0);
- NdbSleep_SecSleep(10);
-
- ndbout << "Doing it all, delete 50%..." << endl;
- CHECK(hugoTrans.loadTable(pNdb, records) == 0);
- CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
- CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);
-
- // Reset error and let LCP continue
- CHECK(restarter.insertErrorInAllNodes(0) == 0);
- NdbSleep_SecSleep(20);
-
- ndbout << "Restarting cluster..." << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- ndbout << "Verifying records..." << endl;
- CHECK(hugoTrans.scanReadRecords(pNdb, records/2, 0, 64) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == (records/2));
- CHECK(utilTrans.clearTable(pNdb, records) == 0);
-
- i++;
- }
-
- ndbout << "runSystemRestartTestUndoLog finished" << endl;
-
- return result;
-}
-
-int runSystemRestartTestFullDb(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- int result = NDBT_OK;
- int timeout = 300;
- Uint32 loops = ctx->getNumLoops();
- int count1, count2;
- NdbRestarter restarter;
- Uint32 i = 1;
-
- UtilTransactions utilTrans(*ctx->getTab());
- HugoTransactions hugoTrans(*ctx->getTab());
- while(i<=loops && result != NDBT_FAILED){
-
- ndbout << "Loop " << i << "/"<< loops <<" started" << endl;
- /*
- 1. Load data until db reports it's full
- 2. Restart cluster and verify records
- */
- ndbout << "Filling up table..." << endl;
- CHECK(hugoTrans.fillTable(pNdb) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count1) == 0);
- ndbout << "Db is full. Table has "<<count1 <<" records."<< endl;
-
- ndbout << "Restarting cluster" << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- ndbout << "Verifying records..." << endl;
- CHECK(hugoTrans.scanReadRecords(pNdb, count1) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count2) == 0);
- CHECK(count1 == count2);
-
- ndbout << "Deleting all records..." << endl;
- CHECK(utilTrans.clearTable2(pNdb, count1) == 0);
-
- ndbout << "Restarting cluster..." << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- ndbout << "Verifying records..." << endl;
- CHECK(utilTrans.selectCount(pNdb, 64, &count1) == 0);
- CHECK(count1 == 0);
-
- i++;
- }
-
- ndbout << "runSystemRestartTestFullDb finished" << endl;
-
- return result;
-}
-
-int runSystemRestart3(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- int result = NDBT_OK;
- int timeout = 300;
- Uint32 loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int count;
- NdbRestarter restarter;
- Uint32 i = 1;
-
- const Uint32 nodeCount = restarter.getNumDbNodes();
- if(nodeCount < 2){
- g_info << "SR3 - Needs atleast 2 nodes to test" << endl;
- return NDBT_OK;
- }
-
- Vector<int> nodeIds;
- for(i = 0; i<nodeCount; i++)
- nodeIds.push_back(restarter.getDbNodeId(i));
-
- Uint32 currentRestartNodeIndex = 0;
- UtilTransactions utilTrans(*ctx->getTab());
- HugoTransactions hugoTrans(*ctx->getTab());
-
- while(i<=loops && result != NDBT_FAILED){
-
- g_info << "Loop " << i << "/"<< loops <<" started" << endl;
- /**
- * 1. Load data
- * 2. Restart 1 node -nostart
- * 3. Update records
- * 4. Restart cluster and verify records
- * 5. Restart 1 node -nostart
- * 6. Delete half of the records
- * 7. Restart cluster and verify records
- * 8. Restart 1 node -nostart
- * 9. Delete all records
- * 10. Restart cluster and verify records
- */
- g_info << "Loading records..." << endl;
- CHECK(hugoTrans.loadTable(pNdb, records) == 0);
-
- /*** 1 ***/
- g_info << "1 - Stopping one node" << endl;
- CHECK(restarter.restartOneDbNode(nodeIds[currentRestartNodeIndex],
- false,
- true,
- false) == 0);
- currentRestartNodeIndex = (currentRestartNodeIndex + 1 ) % nodeCount;
-
- g_info << "Updating records..." << endl;
- CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
-
- g_info << "Restarting cluster..." << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- g_info << "Verifying records..." << endl;
- CHECK(hugoTrans.pkReadRecords(pNdb, records) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == records);
-
- g_info << "2 - Stopping one node" << endl;
- CHECK(restarter.restartOneDbNode(nodeIds[currentRestartNodeIndex],
- false,
- true,
- false) == 0);
- currentRestartNodeIndex = (currentRestartNodeIndex + 1 ) % nodeCount;
-
- g_info << "Deleting 50% of records..." << endl;
- CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);
-
- g_info << "Restarting cluster..." << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- g_info << "Verifying records..." << endl;
- CHECK(hugoTrans.scanReadRecords(pNdb, records/2, 0, 64) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == (records/2));
-
- g_info << "3 - Stopping one node" << endl;
- CHECK(restarter.restartOneDbNode(nodeIds[currentRestartNodeIndex],
- false,
- true,
- false) == 0);
- currentRestartNodeIndex = (currentRestartNodeIndex + 1 ) % nodeCount;
- g_info << "Deleting all records..." << endl;
- CHECK(utilTrans.clearTable(pNdb, records/2) == 0);
-
- g_info << "Restarting cluster..." << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- ndbout << "Verifying records..." << endl;
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == 0);
-
- i++;
- }
-
- g_info << "runSystemRestart3 finished" << endl;
-
- return result;
-}
-
-int runSystemRestart4(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- int result = NDBT_OK;
- int timeout = 300;
- Uint32 loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int count;
- NdbRestarter restarter;
- Uint32 i = 1;
-
- const Uint32 nodeCount = restarter.getNumDbNodes();
- if(nodeCount < 2){
- g_info << "SR4 - Needs atleast 2 nodes to test" << endl;
- return NDBT_OK;
- }
-
- Vector<int> nodeIds;
- for(i = 0; i<nodeCount; i++)
- nodeIds.push_back(restarter.getDbNodeId(i));
-
- Uint32 currentRestartNodeIndex = 0;
- UtilTransactions utilTrans(*ctx->getTab());
- HugoTransactions hugoTrans(*ctx->getTab());
-
- {
- int val = DumpStateOrd::DihMinTimeBetweenLCP;
- if(restarter.dumpStateAllNodes(&val, 1) != 0){
- g_err << "ERR: "<< step->getName()
- << " failed on line " << __LINE__ << endl;
- return NDBT_FAILED;
- }
- }
-
- while(i<=loops && result != NDBT_FAILED){
-
- g_info << "Loop " << i << "/"<< loops <<" started" << endl;
- /**
- * 1. Load data
- * 2. Restart 1 node -nostart
- * 3. Update records
- * 4. Restart cluster and verify records
- * 5. Restart 1 node -nostart
- * 6. Delete half of the records
- * 7. Restart cluster and verify records
- * 8. Restart 1 node -nostart
- * 9. Delete all records
- * 10. Restart cluster and verify records
- */
- g_info << "Loading records..." << endl;
- CHECK(hugoTrans.loadTable(pNdb, records) == 0);
-
- /*** 1 ***/
- g_info << "1 - Stopping one node" << endl;
- CHECK(restarter.restartOneDbNode(nodeIds[currentRestartNodeIndex],
- false,
- true,
- false) == 0);
- currentRestartNodeIndex = (currentRestartNodeIndex + 1 ) % nodeCount;
-
- g_info << "Updating records..." << endl;
- CHECK(hugoTrans.pkUpdateRecords(pNdb, records) == 0);
-
- g_info << "Restarting cluster..." << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- {
- int val = DumpStateOrd::DihMinTimeBetweenLCP;
- CHECK(restarter.dumpStateAllNodes(&val, 1) == 0);
- }
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- g_info << "Verifying records..." << endl;
- CHECK(hugoTrans.pkReadRecords(pNdb, records) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == records);
-
- g_info << "2 - Stopping one node" << endl;
- CHECK(restarter.restartOneDbNode(nodeIds[currentRestartNodeIndex],
- false,
- true,
- false) == 0);
- currentRestartNodeIndex = (currentRestartNodeIndex + 1 ) % nodeCount;
-
- g_info << "Deleting 50% of records..." << endl;
- CHECK(hugoTrans.pkDelRecords(pNdb, records/2) == 0);
-
- g_info << "Restarting cluster..." << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- {
- int val = DumpStateOrd::DihMinTimeBetweenLCP;
- CHECK(restarter.dumpStateAllNodes(&val, 1) == 0);
- }
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- g_info << "Verifying records..." << endl;
- CHECK(hugoTrans.scanReadRecords(pNdb, records/2, 0, 64) == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == (records/2));
-
- g_info << "3 - Stopping one node" << endl;
- CHECK(restarter.restartOneDbNode(nodeIds[currentRestartNodeIndex],
- false,
- true,
- false) == 0);
- currentRestartNodeIndex = (currentRestartNodeIndex + 1 ) % nodeCount;
- g_info << "Deleting all records..." << endl;
- CHECK(utilTrans.clearTable(pNdb, records/2) == 0);
-
- g_info << "Restarting cluster..." << endl;
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- {
- int val = DumpStateOrd::DihMinTimeBetweenLCP;
- CHECK(restarter.dumpStateAllNodes(&val, 1) == 0);
- }
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- ndbout << "Verifying records..." << endl;
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == 0);
-
- i++;
- }
-
- g_info << "runSystemRestart4 finished" << endl;
-
- return result;
-}
-
-int runSystemRestart5(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- int result = NDBT_OK;
- int timeout = 300;
- Uint32 loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int count;
- NdbRestarter restarter;
- Uint32 i = 1;
-
- const Uint32 nodeCount = restarter.getNumDbNodes();
- if(nodeCount < 2){
- g_info << "SR5 - Needs atleast 2 nodes to test" << endl;
- return NDBT_OK;
- }
-
- Vector<int> nodeIds;
- for(i = 0; i<nodeCount; i++)
- nodeIds.push_back(restarter.getDbNodeId(i));
-
- Uint32 currentRestartNodeIndex = 0;
- UtilTransactions utilTrans(*ctx->getTab());
- HugoTransactions hugoTrans(*ctx->getTab());
-
- {
- int val = DumpStateOrd::DihMinTimeBetweenLCP;
- if(restarter.dumpStateAllNodes(&val, 1) != 0){
- g_err << "ERR: "<< step->getName()
- << " failed on line " << __LINE__ << endl;
- return NDBT_FAILED;
- }
- }
-
- while(i<=loops && result != NDBT_FAILED){
-
- g_info << "Loop " << i << "/"<< loops <<" started" << endl;
- /**
- * 1. Load data
- * 2. Restart 1 node -nostart
- * 3. Update records
- * 4. Restart cluster and verify records
- * 5. Restart 1 node -nostart
- * 6. Delete half of the records
- * 7. Restart cluster and verify records
- * 8. Restart 1 node -nostart
- * 9. Delete all records
- * 10. Restart cluster and verify records
- */
- g_info << "Loading records..." << endl;
- hugoTrans.loadTable(pNdb, records);
-
- /*** 1 ***/
- g_info << "1 - Stopping one node" << endl;
- CHECK(restarter.restartOneDbNode(nodeIds[currentRestartNodeIndex],
- false,
- true,
- false) == 0);
- currentRestartNodeIndex = (currentRestartNodeIndex + 1 ) % nodeCount;
-
- g_info << "Updating records..." << endl;
- hugoTrans.pkUpdateRecords(pNdb, records);
-
- g_info << "Restarting cluster..." << endl;
- CHECK(restarter.restartAll(false, false, true) == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- {
- int val = DumpStateOrd::DihMinTimeBetweenLCP;
- CHECK(restarter.dumpStateAllNodes(&val, 1) == 0);
- }
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- g_info << "Verifying records..." << endl;
- hugoTrans.pkReadRecords(pNdb, records);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- //CHECK(count == records);
-
- g_info << "2 - Stopping one node" << endl;
- CHECK(restarter.restartOneDbNode(nodeIds[currentRestartNodeIndex],
- false,
- true,
- false) == 0);
- currentRestartNodeIndex = (currentRestartNodeIndex + 1 ) % nodeCount;
-
- g_info << "Deleting 50% of records..." << endl;
- hugoTrans.pkDelRecords(pNdb, records/2);
-
- g_info << "Restarting cluster..." << endl;
- CHECK(restarter.restartAll(false, false, true) == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- {
- int val = DumpStateOrd::DihMinTimeBetweenLCP;
- CHECK(restarter.dumpStateAllNodes(&val, 1) == 0);
- }
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- g_info << "Verifying records..." << endl;
- hugoTrans.scanReadRecords(pNdb, records/2, 0, 64);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- //CHECK(count == (records/2));
-
- g_info << "3 - Stopping one node" << endl;
- CHECK(restarter.restartOneDbNode(nodeIds[currentRestartNodeIndex],
- false,
- true,
- false) == 0);
- currentRestartNodeIndex = (currentRestartNodeIndex + 1 ) % nodeCount;
- g_info << "Deleting all records..." << endl;
- utilTrans.clearTable(pNdb, records/2);
-
- g_info << "Restarting cluster..." << endl;
- CHECK(restarter.restartAll(false, false, true) == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- {
- int val = DumpStateOrd::DihMinTimeBetweenLCP;
- CHECK(restarter.dumpStateAllNodes(&val, 1) == 0);
- }
- CHECK(pNdb->waitUntilReady(timeout) == 0);
-
- ndbout << "Verifying records..." << endl;
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- //CHECK(count == 0);
-
- CHECK(utilTrans.clearTable(pNdb) == 0);
- i++;
- }
-
- g_info << "runSystemRestart5 finished" << endl;
-
- return result;
-}
-
-int runSystemRestart6(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- int result = NDBT_OK;
- int timeout = 300;
- Uint32 loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- NdbRestarter restarter;
- Uint32 i = 1;
-
- const Uint32 nodeCount = restarter.getNumDbNodes();
- if(nodeCount < 2){
- g_info << "SR6 - Needs atleast 2 nodes to test" << endl;
- return NDBT_OK;
- }
-
- Vector<int> nodeIds;
- for(i = 0; i<nodeCount; i++)
- nodeIds.push_back(restarter.getDbNodeId(i));
-
- Uint32 currentRestartNodeIndex = 0;
- UtilTransactions utilTrans(*ctx->getTab());
- HugoTransactions hugoTrans(*ctx->getTab());
-
- while(i<=loops && result != NDBT_FAILED){
-
- g_info << "Loop " << i << "/"<< loops <<" started" << endl;
- /**
- * 1. Load data
- * 2. Restart all node -nostart
- * 3. Restart some nodes -i -nostart
- * 4. Start all nodes verify records
- */
- g_info << "Loading records..." << endl;
- hugoTrans.loadTable(pNdb, records);
-
- CHECK(restarter.restartAll(false, true, false) == 0);
-
- Uint32 nodeId = nodeIds[currentRestartNodeIndex];
- currentRestartNodeIndex = (currentRestartNodeIndex + 1 ) % nodeCount;
-
- CHECK(restarter.restartOneDbNode(nodeId, true, true,false) == 0);
- CHECK(restarter.waitClusterNoStart(timeout) == 0);
- CHECK(restarter.startAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(pNdb->waitUntilReady(timeout) == 0);
- int count = records - 1;
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == records);
- CHECK(utilTrans.clearTable(pNdb) == 0);
- i++;
- }
-
- g_info << "runSystemRestart6 finished" << endl;
-
- return result;
-}
-
-int runSystemRestart7(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- int result = NDBT_OK;
- Uint32 loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- NdbRestarter restarter;
- Uint32 i = 1;
-
- const Uint32 nodeCount = restarter.getNumDbNodes();
- if(nodeCount < 2){
- g_info << "SR7 - Needs atleast 2 nodes to test" << endl;
- return NDBT_OK;
- }
-
- Vector<int> nodeIds;
- for(i = 0; i<nodeCount; i++)
- nodeIds.push_back(restarter.getDbNodeId(i));
-
- int a_nodeIds[64];
- if(nodeCount > 64)
- abort();
-
- Uint32 currentRestartNodeIndex = 1;
- UtilTransactions utilTrans(*ctx->getTab());
- HugoTransactions hugoTrans(*ctx->getTab());
-
- while(i<=loops && result != NDBT_FAILED){
-
- g_info << "Loop " << i << "/"<< loops <<" started" << endl;
- /**
- * 1. Load data
- * 2. Restart all node -nostart
- * 3. Start all but one node
- * 4. Wait for startphase >= 2
- * 5. Start last node
- * 6. Verify records
- */
- g_info << "Loading records..." << endl;
- hugoTrans.loadTable(pNdb, records);
-
- CHECK(restarter.restartAll(false, true, false) == 0);
-
- int nodeId = nodeIds[currentRestartNodeIndex];
- currentRestartNodeIndex = (currentRestartNodeIndex + 1 ) % nodeCount;
-
- Uint32 j = 0;
- for(Uint32 k = 0; k<nodeCount; k++){
- if(nodeIds[k] != nodeId){
- a_nodeIds[j++] = nodeIds[k];
- }
- }
-
- CHECK(restarter.startNodes(a_nodeIds, nodeCount - 1) == 0);
- CHECK(restarter.waitNodesStarted(a_nodeIds, nodeCount - 1, 120) == 0);
- CHECK(pNdb->waitUntilReady(5) == 0);
- int count = records - 1;
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == records);
-
- CHECK(restarter.startNodes(&nodeId, 1) == 0);
- CHECK(restarter.waitNodesStarted(&nodeId, 1, 120) == 0);
-
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == records);
- CHECK(utilTrans.clearTable(pNdb) == 0);
-
- i++;
- }
-
- g_info << "runSystemRestart7 finished" << endl;
-
- return result;
-}
-
-int runSystemRestart8(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- int result = NDBT_OK;
- int timeout = 300;
- Uint32 loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- NdbRestarter restarter;
- Uint32 i = 1;
-
- const Uint32 nodeCount = restarter.getNumDbNodes();
- if(nodeCount < 2){
- g_info << "SR8 - Needs atleast 2 nodes to test" << endl;
- return NDBT_OK;
- }
-
- Vector<int> nodeIds;
- for(i = 0; i<nodeCount; i++)
- nodeIds.push_back(restarter.getDbNodeId(i));
-
- int a_nodeIds[64];
- if(nodeCount > 64)
- abort();
-
- Uint32 currentRestartNodeIndex = 1;
- UtilTransactions utilTrans(*ctx->getTab());
- HugoTransactions hugoTrans(*ctx->getTab());
-
- while(i<=loops && result != NDBT_FAILED){
-
- g_info << "Loop " << i << "/"<< loops <<" started" << endl;
- /**
- * 1. Load data
- * 2. Restart all node -nostart
- * 3. Start all but one node
- * 4. Verify records
- * 5. Start last node
- * 6. Verify records
- */
- g_info << "Loading records..." << endl;
- hugoTrans.loadTable(pNdb, records);
-
- CHECK(restarter.restartAll(false, true, false) == 0);
-
- int nodeId = nodeIds[currentRestartNodeIndex];
- currentRestartNodeIndex = (currentRestartNodeIndex + 1 ) % nodeCount;
-
- Uint32 j = 0;
- for(Uint32 k = 0; k<nodeCount; k++){
- if(nodeIds[k] != nodeId){
- a_nodeIds[j++] = nodeIds[k];
- }
- }
-
- CHECK(restarter.startNodes(a_nodeIds, nodeCount-1) == 0);
- CHECK(restarter.waitNodesStartPhase(a_nodeIds, nodeCount-1, 3, 120) == 0);
- CHECK(restarter.startNodes(&nodeId, 1) == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
-
- int count = records - 1;
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == records);
- CHECK(utilTrans.clearTable(pNdb) == 0);
- i++;
- }
-
- g_info << "runSystemRestart8 finished" << endl;
-
- return result;
-}
-
-int runSystemRestart9(NDBT_Context* ctx, NDBT_Step* step){
- Ndb* pNdb = GETNDB(step);
- int result = NDBT_OK;
- int timeout = 300;
- Uint32 loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- NdbRestarter restarter;
- Uint32 i = 1;
-
- Uint32 currentRestartNodeIndex = 1;
- UtilTransactions utilTrans(*ctx->getTab());
- HugoTransactions hugoTrans(*ctx->getTab());
-
- int args[] = { DumpStateOrd::DihMaxTimeBetweenLCP };
- int dump[] = { DumpStateOrd::DihStartLcpImmediately };
-
- do {
- CHECK(restarter.dumpStateAllNodes(args, 1) == 0);
-
- HugoOperations ops(* ctx->getTab());
- CHECK(ops.startTransaction(pNdb) == 0);
- for(i = 0; i<10; i++){
- CHECK(ops.pkInsertRecord(pNdb, i, 1, 1) == 0);
- CHECK(ops.execute_NoCommit(pNdb) == 0);
- }
- for(i = 0; i<10; i++){
- CHECK(ops.pkUpdateRecord(pNdb, i, 1) == 0);
- CHECK(ops.execute_NoCommit(pNdb) == 0);
- }
- NdbSleep_SecSleep(10);
- CHECK(restarter.dumpStateAllNodes(dump, 1) == 0);
- NdbSleep_SecSleep(10);
- CHECK(ops.execute_Commit(pNdb) == 0);
-
- CHECK(restarter.restartAll() == 0);
- CHECK(restarter.waitClusterStarted(timeout) == 0);
- CHECK(pNdb->waitUntilReady(timeout) == 0);
- ops.closeTransaction(pNdb);
- } while(0);
-
- g_info << "runSystemRestart9 finished" << endl;
-
- return result;
-}
-
-int runBug18385(NDBT_Context* ctx, NDBT_Step* step){
- NdbRestarter restarter;
- const Uint32 nodeCount = restarter.getNumDbNodes();
- if(nodeCount < 2){
- g_info << "Bug18385 - Needs atleast 2 nodes to test" << endl;
- return NDBT_OK;
- }
-
- int node1 = restarter.getDbNodeId(rand() % nodeCount);
- int node2 = restarter.getRandomNodeSameNodeGroup(node1, rand());
-
- if (node1 == -1 || node2 == -1)
- return NDBT_OK;
-
- int dump[] = { DumpStateOrd::DihSetTimeBetweenGcp, 300 };
-
- int result = NDBT_OK;
- do {
- CHECK(restarter.dumpStateAllNodes(dump, 2) == 0);
- CHECK(restarter.restartOneDbNode(node1, false, true, false) == 0);
- NdbSleep_SecSleep(3);
- CHECK(restarter.restartAll(false, true, false) == 0);
-
- Uint32 cnt = 0;
- int nodes[128];
- for(Uint32 i = 0; i<nodeCount; i++)
- if ((nodes[cnt] = restarter.getDbNodeId(i)) != node2)
- cnt++;
-
- assert(cnt == nodeCount - 1);
-
- CHECK(restarter.startNodes(nodes, cnt) == 0);
- CHECK(restarter.waitNodesStarted(nodes, cnt, 300) == 0);
-
- CHECK(restarter.insertErrorInNode(node2, 7170) == 0);
- CHECK(restarter.waitNodesNoStart(&node2, 1) == 0);
- CHECK(restarter.restartOneDbNode(node2, true, false, true) == 0);
- CHECK(restarter.waitNodesStarted(&node2, 1) == 0);
-
- } while(0);
-
- g_info << "Bug18385 finished" << endl;
-
- return result;
-}
-
-int runWaitStarted(NDBT_Context* ctx, NDBT_Step* step){
-
- NdbRestarter restarter;
- restarter.waitClusterStarted(300);
-
- NdbSleep_SecSleep(3);
- return NDBT_OK;
-}
-
-int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
-
- Ndb* pNdb = GETNDB(step);
- if(pNdb->waitUntilReady(5) != 0){
- return NDBT_FAILED;
- }
-
- UtilTransactions utilTrans(*ctx->getTab());
- if (utilTrans.clearTable2(pNdb, records) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int
-runBug21536(NDBT_Context* ctx, NDBT_Step* step)
-{
- NdbRestarter restarter;
- const Uint32 nodeCount = restarter.getNumDbNodes();
- if(nodeCount != 2){
- g_info << "Bug21536 - 2 nodes to test" << endl;
- return NDBT_OK;
- }
-
- int node1 = restarter.getDbNodeId(rand() % nodeCount);
- int node2 = restarter.getRandomNodeSameNodeGroup(node1, rand());
-
- if (node1 == -1 || node2 == -1)
- return NDBT_OK;
-
- int result = NDBT_OK;
- do {
- CHECK(restarter.restartOneDbNode(node1, false, true, true) == 0);
- CHECK(restarter.waitNodesNoStart(&node1, 1) == 0);
- CHECK(restarter.insertErrorInNode(node1, 1000) == 0);
- int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
- CHECK(restarter.dumpStateOneNode(node1, val2, 2) == 0);
- CHECK(restarter.startNodes(&node1, 1) == 0);
- restarter.waitNodesStartPhase(&node1, 1, 3, 120);
- CHECK(restarter.waitNodesNoStart(&node1, 1) == 0);
-
- CHECK(restarter.restartOneDbNode(node2, true, true, true) == 0);
- CHECK(restarter.waitNodesNoStart(&node2, 1) == 0);
- CHECK(restarter.startNodes(&node1, 1) == 0);
- CHECK(restarter.waitNodesStarted(&node1, 1) == 0);
- CHECK(restarter.startNodes(&node2, 1) == 0);
- CHECK(restarter.waitClusterStarted() == 0);
-
- } while(0);
-
- g_info << "Bug21536 finished" << endl;
-
- return result;
-}
-
-int
-runBug24664(NDBT_Context* ctx, NDBT_Step* step)
-{
- int result = NDBT_OK;
- NdbRestarter restarter;
- Ndb* pNdb = GETNDB(step);
- const Uint32 nodeCount = restarter.getNumDbNodes();
-
- int records = ctx->getNumRecords();
- UtilTransactions utilTrans(*ctx->getTab());
- HugoTransactions hugoTrans(*ctx->getTab());
-
- int args[] = { DumpStateOrd::DihMaxTimeBetweenLCP };
- int dump[] = { DumpStateOrd::DihStartLcpImmediately };
-
- int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_CHECKPOINT, 0 };
- NdbLogEventHandle handle =
- ndb_mgm_create_logevent_handle(restarter.handle, filter);
-
- struct ndb_logevent event;
-
- do {
- CHECK(restarter.dumpStateAllNodes(args, 1) == 0);
- CHECK(restarter.dumpStateAllNodes(dump, 1) == 0);
- while(ndb_logevent_get_next(handle, &event, 0) >= 0 &&
- event.type != NDB_LE_LocalCheckpointStarted);
- while(ndb_logevent_get_next(handle, &event, 0) >= 0 &&
- event.type != NDB_LE_LocalCheckpointCompleted);
-
- if (hugoTrans.loadTable(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
-
- restarter.insertErrorInAllNodes(10036); // Hang LCP
- CHECK(restarter.dumpStateAllNodes(dump, 1) == 0);
- while(ndb_logevent_get_next(handle, &event, 0) >= 0 &&
- event.type != NDB_LE_LocalCheckpointStarted);
- NdbSleep_SecSleep(3);
- CHECK(utilTrans.clearTable(pNdb, records) == 0);
- if (hugoTrans.loadTable(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
-
- restarter.insertErrorInAllNodes(10037); // Resume LCP
- while(ndb_logevent_get_next(handle, &event, 0) >= 0 &&
- event.type != NDB_LE_LocalCheckpointCompleted);
-
- while(ndb_logevent_get_next(handle, &event, 0) >= 0 &&
- event.type != NDB_LE_GlobalCheckpointCompleted);
- while(ndb_logevent_get_next(handle, &event, 0) >= 0 &&
- event.type != NDB_LE_GlobalCheckpointCompleted);
- restarter.restartAll(false, false, true);
- CHECK(restarter.waitClusterStarted() == 0);
- } while(false);
-
- return result;
-}
-
-int
-runBug29167(NDBT_Context* ctx, NDBT_Step* step)
-{
- int result = NDBT_OK;
- NdbRestarter restarter;
- Ndb* pNdb = GETNDB(step);
- const Uint32 nodeCount = restarter.getNumDbNodes();
-
- if (nodeCount < 2)
- return NDBT_OK;
-
- int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_CHECKPOINT, 0 };
- NdbLogEventHandle handle =
- ndb_mgm_create_logevent_handle(restarter.handle, filter);
-
- struct ndb_logevent event;
- int master = restarter.getMasterNodeId();
- do {
- int node1 = restarter.getRandomNodeOtherNodeGroup(master, rand());
- int node2 = restarter.getRandomNodeSameNodeGroup(node1, rand());
-
- int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
- restarter.dumpStateAllNodes(val2, 2);
- int dump[] = { DumpStateOrd::DihSetTimeBetweenGcp, 30000 };
- restarter.dumpStateAllNodes(dump, 2);
-
- while(ndb_logevent_get_next(handle, &event, 0) >= 0 &&
- event.type != NDB_LE_GlobalCheckpointCompleted);
-
- CHECK(restarter.insertErrorInAllNodes(932) == 0);
-
- CHECK(restarter.insertErrorInNode(node1, 7183) == 0);
- CHECK(restarter.insertErrorInNode(node2, 7183) == 0);
-
- CHECK(restarter.waitClusterNoStart() == 0);
- restarter.startAll();
- CHECK(restarter.waitClusterStarted() == 0);
- } while(false);
-
- return result;
-}
-
-int
-runBug28770(NDBT_Context* ctx, NDBT_Step* step) {
- Ndb* pNdb = GETNDB(step);
- NdbRestarter restarter;
- int result = NDBT_OK;
- int count = 0;
- Uint32 i = 0;
- Uint32 loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- UtilTransactions utilTrans(*ctx->getTab());
- HugoTransactions hugoTrans(*ctx->getTab());
-
- g_info << "Loading records..." << endl; hugoTrans.loadTable(pNdb,
- records);
-
-
- while(i<=loops && result != NDBT_FAILED){
- g_info << "Loop " << i << "/"<< loops <<" started" << endl;
- CHECK(restarter.restartAll(false, true, false) == 0);
- NdbSleep_SecSleep(3);
- CHECK(restarter.waitClusterNoStart() == 0);
- restarter.insertErrorInAllNodes(6007);
- CHECK(restarter.startAll()== 0);
- CHECK(restarter.waitClusterStarted() == 0);
- CHECK(utilTrans.selectCount(pNdb, 64, &count) == 0);
- CHECK(count == records);
- i++;
- }
- ndbout << " runBug28770 finished" << endl;
- return result;
-}
-
-int
-runStopper(NDBT_Context* ctx, NDBT_Step* step)
-{
- NdbRestarter restarter;
- Uint32 stop = 0;
-loop:
- while (!ctx->isTestStopped() &&
- ((stop = ctx->getProperty("StopAbort", Uint32(0))) == 0))
- {
- NdbSleep_MilliSleep(30);
- }
-
- if (ctx->isTestStopped())
- {
- return NDBT_OK;
- }
-
- ndbout << "Killing in " << stop << "ms..." << flush;
- NdbSleep_MilliSleep(stop);
- restarter.restartAll(false, true, true);
- ctx->setProperty("StopAbort", Uint32(0));
- goto loop;
-}
-
-int runSR_DD_1(NDBT_Context* ctx, NDBT_Step* step)
-{
- Ndb* pNdb = GETNDB(step);
- int result = NDBT_OK;
- Uint32 loops = ctx->getNumLoops();
- int count;
- NdbRestarter restarter;
- NdbBackup backup(GETNDB(step)->getNodeId()+1);
- bool lcploop = ctx->getProperty("LCP", (unsigned)0);
- bool all = ctx->getProperty("ALL", (unsigned)0);
-
- Uint32 i = 1;
- Uint32 backupId;
-
- int val[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
- int lcp = DumpStateOrd::DihMinTimeBetweenLCP;
-
- int startFrom = 0;
-
- HugoTransactions hugoTrans(*ctx->getTab());
- while(i<=loops && result != NDBT_FAILED)
- {
-
- if (lcploop)
- {
- CHECK(restarter.dumpStateAllNodes(&lcp, 1) == 0);
- }
-
- int nodeId = restarter.getDbNodeId(rand() % restarter.getNumDbNodes());
- //CHECK(restarter.dumpStateAllNodes(&val, 1) == 0);
-
- ndbout << "Loop " << i << "/"<< loops <<" started" << endl;
- ndbout << "Loading records..." << startFrom << endl;
- CHECK(hugoTrans.loadTable(pNdb, startFrom) == 0);
-
- if (!all)
- {
- ndbout << "Making " << nodeId << " crash" << endl;
- int kill[] = { 9999, 1000, 3000 };
- CHECK(restarter.dumpStateOneNode(nodeId, val, 2) == 0);
- CHECK(restarter.dumpStateOneNode(nodeId, kill, 3) == 0);
- }
- else
- {
- ndbout << "Crashing cluster" << endl;
- ctx->setProperty("StopAbort", 1000 + rand() % (3000 - 1000));
- }
- Uint64 end = NdbTick_CurrentMillisecond() + 4000;
- Uint32 row = startFrom;
- do {
- ndbout << "Loading from " << row << " to " << row + 1000 << endl;
- if (hugoTrans.loadTableStartFrom(pNdb, row, 1000) != 0)
- break;
- row += 1000;
- } while (NdbTick_CurrentMillisecond() < end);
-
- if (!all)
- {
- ndbout << "Waiting for " << nodeId << " to restart" << endl;
- CHECK(restarter.waitNodesNoStart(&nodeId, 1) == 0);
- ndbout << "Restarting cluster" << endl;
- CHECK(restarter.restartAll(false, true, true) == 0);
- }
- else
- {
- ndbout << "Waiting for cluster to restart" << endl;
- }
- CHECK(restarter.waitClusterNoStart() == 0);
- CHECK(restarter.startAll() == 0);
- CHECK(restarter.waitClusterStarted() == 0);
-
- ndbout << "Starting backup..." << flush;
- CHECK(backup.start(backupId) == 0);
- ndbout << "done" << endl;
-
- int cnt = 0;
- CHECK(hugoTrans.selectCount(pNdb, 0, &cnt) == 0);
- ndbout << "Found " << cnt << " records..." << endl;
- ndbout << "Clearing..." << endl;
- CHECK(hugoTrans.clearTable(pNdb,
- NdbScanOperation::SF_TupScan, cnt) == 0);
-
- if (cnt > startFrom)
- {
- startFrom = cnt;
- }
- startFrom += 1000;
- i++;
- }
-
- ndbout << "runSR_DD_1 finished" << endl;
- ctx->stopTest();
- return result;
-}
-
-int runSR_DD_2(NDBT_Context* ctx, NDBT_Step* step)
-{
- Ndb* pNdb = GETNDB(step);
- int result = NDBT_OK;
- Uint32 loops = ctx->getNumLoops();
- Uint32 rows = ctx->getNumRecords();
- int count;
- NdbRestarter restarter;
- NdbBackup backup(GETNDB(step)->getNodeId()+1);
- bool lcploop = ctx->getProperty("LCP", (unsigned)0);
- bool all = ctx->getProperty("ALL", (unsigned)0);
-
- Uint32 i = 1;
- Uint32 backupId;
-
- int val[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
- int lcp = DumpStateOrd::DihMinTimeBetweenLCP;
-
- int startFrom = 0;
-
- HugoTransactions hugoTrans(*ctx->getTab());
- while(i<=loops && result != NDBT_FAILED)
- {
-
- if (lcploop)
- {
- CHECK(restarter.dumpStateAllNodes(&lcp, 1) == 0);
- }
-
- int nodeId = restarter.getDbNodeId(rand() % restarter.getNumDbNodes());
-
- if (!all)
- {
- ndbout << "Making " << nodeId << " crash" << endl;
- int kill[] = { 9999, 3000, 10000 };
- CHECK(restarter.dumpStateOneNode(nodeId, val, 2) == 0);
- CHECK(restarter.dumpStateOneNode(nodeId, kill, 3) == 0);
- }
- else
- {
- ndbout << "Crashing cluster" << endl;
- ctx->setProperty("StopAbort", 1000 + rand() % (3000 - 1000));
- }
-
- Uint64 end = NdbTick_CurrentMillisecond() + 11000;
- Uint32 row = startFrom;
- do {
- if (hugoTrans.loadTable(pNdb, rows) != 0)
- break;
-
- if (hugoTrans.clearTable(pNdb, NdbScanOperation::SF_TupScan, rows) != 0)
- break;
- } while (NdbTick_CurrentMillisecond() < end);
-
- if (!all)
- {
- ndbout << "Waiting for " << nodeId << " to restart" << endl;
- CHECK(restarter.waitNodesNoStart(&nodeId, 1) == 0);
- ndbout << "Restarting cluster" << endl;
- CHECK(restarter.restartAll(false, true, true) == 0);
- }
- else
- {
- ndbout << "Waiting for cluster to restart" << endl;
- }
-
- CHECK(restarter.waitClusterNoStart() == 0);
- CHECK(restarter.startAll() == 0);
- CHECK(restarter.waitClusterStarted() == 0);
-
- ndbout << "Starting backup..." << flush;
- CHECK(backup.start(backupId) == 0);
- ndbout << "done" << endl;
-
- int cnt = 0;
- CHECK(hugoTrans.selectCount(pNdb, 0, &cnt) == 0);
- ndbout << "Found " << cnt << " records..." << endl;
- ndbout << "Clearing..." << endl;
- CHECK(hugoTrans.clearTable(pNdb,
- NdbScanOperation::SF_TupScan, cnt) == 0);
- i++;
- }
-
- ndbout << "runSR_DD_2 finished" << endl;
- ctx->stopTest();
- return result;
-}
-
-int runBug22696(NDBT_Context* ctx, NDBT_Step* step)
-{
- Ndb* pNdb = GETNDB(step);
- int result = NDBT_OK;
- Uint32 loops = ctx->getNumLoops();
- Uint32 rows = ctx->getNumRecords();
- NdbRestarter restarter;
- HugoTransactions hugoTrans(*ctx->getTab());
-
- Uint32 i = 0;
- while(i<=loops && result != NDBT_FAILED)
- {
- for (Uint32 j = 0; j<10 && result != NDBT_FAILED; j++)
- CHECK(hugoTrans.scanUpdateRecords(pNdb, rows) == 0);
-
- CHECK(restarter.restartAll(false, true, i > 0 ? true : false) == 0);
- CHECK(restarter.waitClusterNoStart() == 0);
- CHECK(restarter.insertErrorInAllNodes(7072) == 0);
- CHECK(restarter.startAll() == 0);
- CHECK(restarter.waitClusterStarted() == 0);
-
- i++;
- if (i < loops)
- {
- NdbSleep_SecSleep(5); // Wait for a few gcp
- }
- }
-
- ctx->stopTest();
- return result;
-}
-
-int
-runBug27434(NDBT_Context* ctx, NDBT_Step* step)
-{
- int result = NDBT_OK;
- NdbRestarter restarter;
- Ndb* pNdb = GETNDB(step);
- const Uint32 nodeCount = restarter.getNumDbNodes();
-
- if (nodeCount < 2)
- return NDBT_OK;
-
- int args[] = { DumpStateOrd::DihMaxTimeBetweenLCP };
- int dump[] = { DumpStateOrd::DihStartLcpImmediately };
-
- int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_CHECKPOINT, 0 };
- NdbLogEventHandle handle =
- ndb_mgm_create_logevent_handle(restarter.handle, filter);
-
- struct ndb_logevent event;
-
- do {
- int node1 = restarter.getDbNodeId(rand() % nodeCount);
- CHECK(restarter.restartOneDbNode(node1, false, true, true) == 0);
- NdbSleep_SecSleep(3);
- CHECK(restarter.waitNodesNoStart(&node1, 1) == 0);
-
- CHECK(restarter.dumpStateAllNodes(args, 1) == 0);
-
- for (Uint32 i = 0; i<3; i++)
- {
- CHECK(restarter.dumpStateAllNodes(dump, 1) == 0);
- while(ndb_logevent_get_next(handle, &event, 0) >= 0 &&
- event.type != NDB_LE_LocalCheckpointStarted);
- while(ndb_logevent_get_next(handle, &event, 0) >= 0 &&
- event.type != NDB_LE_LocalCheckpointCompleted);
- }
-
- restarter.restartAll(false, true, true);
- NdbSleep_SecSleep(3);
- CHECK(restarter.waitClusterNoStart() == 0);
- restarter.insertErrorInNode(node1, 5046);
- restarter.startAll();
- CHECK(restarter.waitClusterStarted() == 0);
- } while(false);
-
- return result;
-}
-
-NDBT_TESTSUITE(testSystemRestart);
-TESTCASE("SR1",
- "Basic system restart test. Focus on testing restart from REDO log.\n"
- "NOTE! Time between lcp's and gcp's should be left at default, \n"
- "so that Ndb uses the Redo log when restarting\n"
- "1. Load records\n"
- "2. Restart cluster and verify records \n"
- "3. Update records\n"
- "4. Restart cluster and verify records \n"
- "5. Delete half of the records \n"
- "6. Restart cluster and verify records \n"
- "7. Delete all records \n"
- "8. Restart cluster and verify records \n"
- "9. Insert, update, delete records \n"
- "10. Restart cluster and verify records\n"
- "11. Insert, update, delete records \n"
- "12. Restart cluster with error insert 5020 and verify records\n"){
- INITIALIZER(runWaitStarted);
- STEP(runSystemRestart1);
- FINALIZER(runClearTable);
-}
-TESTCASE("SR2",
- "Basic system restart test. Focus on testing restart from LCP\n"
- "NOTE! Time between lcp's is automatically set to it's min value\n"
- "so that Ndb uses LCP's when restarting.\n"
- "1. Load records\n"
- "2. Restart cluster and verify records \n"
- "3. Update records\n"
- "4. Restart cluster and verify records \n"
- "5. Delete half of the records \n"
- "6. Restart cluster and verify records \n"
- "7. Delete all records \n"
- "8. Restart cluster and verify records \n"
- "9. Insert, update, delete records \n"
- "10. Restart cluster and verify records\n"){
- INITIALIZER(runWaitStarted);
- STEP(runSystemRestart2);
- FINALIZER(runClearTable);
-}
-TESTCASE("SR_UNDO",
- "System restart test. Focus on testing of undologging\n"
- "in DBACC and DBTUP.\n"
- "This is done by starting a LCP, turn on undologging \n"
- "but don't start writing the datapages. This will force all\n"
- "operations to be written into the undolog.\n"
- "Then write datapages and complete LCP.\n"
- "Restart the system\n"){
- INITIALIZER(runWaitStarted);
- STEP(runSystemRestartTestUndoLog);
- FINALIZER(runClearTable);
-}
-TESTCASE("SR_FULLDB",
- "System restart test. Test to restart when DB is full.\n"){
- INITIALIZER(runWaitStarted);
- STEP(runSystemRestartTestFullDb);
- FINALIZER(runClearTable);
-}
-TESTCASE("SR3",
- "System restart test. Focus on testing restart from with\n"
- "not all nodes alive when system went down\n"
- "* 1. Load data\n"
- "* 2. Restart 1 node -nostart\n"
- "* 3. Update records\n"
- "* 4. Restart cluster and verify records\n"
- "* 5. Restart 1 node -nostart\n"
- "* 6. Delete half of the records\n"
- "* 7. Restart cluster and verify records\n"
- "* 8. Restart 1 node -nostart\n"
- "* 9. Delete all records\n"
- "* 10. Restart cluster and verify records\n"){
- INITIALIZER(runWaitStarted);
- STEP(runSystemRestart3);
- FINALIZER(runClearTable);
-}
-TESTCASE("SR4",
- "System restart test. Focus on testing restart from with\n"
- "not all nodes alive when system went down but running LCP at\n"
- "high speed so that sometimes a TO is required to start cluster\n"
- "* 1. Load data\n"
- "* 2. Restart 1 node -nostart\n"
- "* 3. Update records\n"
- "* 4. Restart cluster and verify records\n"
- "* 5. Restart 1 node -nostart\n"
- "* 6. Delete half of the records\n"
- "* 7. Restart cluster and verify records\n"
- "* 8. Restart 1 node -nostart\n"
- "* 9. Delete all records\n"
- "* 10. Restart cluster and verify records\n"){
- INITIALIZER(runWaitStarted);
- STEP(runSystemRestart4);
- FINALIZER(runClearTable);
-}
-TESTCASE("SR5",
- "As SR4 but making restart aborts\n"
- "* 1. Load data\n"
- "* 2. Restart 1 node -nostart\n"
- "* 3. Update records\n"
- "* 4. Restart cluster and verify records\n"
- "* 5. Restart 1 node -nostart\n"
- "* 6. Delete half of the records\n"
- "* 7. Restart cluster and verify records\n"
- "* 8. Restart 1 node -nostart\n"
- "* 9. Delete all records\n"
- "* 10. Restart cluster and verify records\n"){
- INITIALIZER(runWaitStarted);
- STEP(runSystemRestart5);
- FINALIZER(runClearTable);
-}
-TESTCASE("SR6",
- "Perform system restart with some nodes having FS others wo/\n"
- "* 1. Load data\n"
- "* 2. Restart all node -nostart\n"
- "* 3. Restart some nodes -i -nostart\n"
- "* 4. Start all nodes verify records\n"){
- INITIALIZER(runWaitStarted);
- INITIALIZER(runClearTable);
- STEP(runSystemRestart6);
- FINALIZER(runClearTable);
-}
-TESTCASE("SR7",
- "Perform partition win system restart\n"
- "* 1. Load data\n"
- "* 2. Restart all node -nostart\n"
- "* 3. Start all but one node\n"
- "* 4. Verify records\n"
- "* 5. Start last node\n"
- "* 6. Verify records\n"){
- INITIALIZER(runWaitStarted);
- INITIALIZER(runClearTable);
- STEP(runSystemRestart7);
- FINALIZER(runClearTable);
-}
-TESTCASE("SR8",
- "Perform partition win system restart with other nodes delayed\n"
- "* 1. Load data\n"
- "* 2. Restart all node -nostart\n"
- "* 3. Start all but one node\n"
- "* 4. Wait for startphase >= 2\n"
- "* 5. Start last node\n"
- "* 6. Verify records\n"){
- INITIALIZER(runWaitStarted);
- INITIALIZER(runClearTable);
- STEP(runSystemRestart8);
- FINALIZER(runClearTable);
-}
-TESTCASE("SR9",
- "Perform partition win system restart with other nodes delayed\n"
- "* 1. Start transaction\n"
- "* 2. insert (1,1)\n"
- "* 3. update (1,2)\n"
- "* 4. start lcp\n"
- "* 5. commit\n"
- "* 6. restart\n"){
- INITIALIZER(runWaitStarted);
- INITIALIZER(runClearTable);
- STEP(runSystemRestart9);
- FINALIZER(runClearTable);
-}
-TESTCASE("Bug18385",
- "Perform partition system restart with other nodes with higher GCI"){
- INITIALIZER(runWaitStarted);
- INITIALIZER(runClearTable);
- STEP(runBug18385);
- FINALIZER(runClearTable);
-}
-TESTCASE("Bug21536",
- "Perform partition system restart with other nodes with higher GCI"){
- INITIALIZER(runWaitStarted);
- INITIALIZER(runClearTable);
- STEP(runBug21536);
- FINALIZER(runClearTable);
-}
-TESTCASE("Bug24664",
- "Check handling of LCP skip/keep")
-{
- INITIALIZER(runWaitStarted);
- INITIALIZER(runClearTable);
- STEP(runBug24664);
- FINALIZER(runClearTable);
-}
-TESTCASE("Bug27434",
- "")
-{
- INITIALIZER(runWaitStarted);
- STEP(runBug27434);
-}
-TESTCASE("SR_DD_1", "")
-{
- TC_PROPERTY("ALL", 1);
- INITIALIZER(runWaitStarted);
- STEP(runStopper);
- STEP(runSR_DD_1);
- FINALIZER(runClearTable);
-}
-TESTCASE("SR_DD_1b", "")
-{
- INITIALIZER(runWaitStarted);
- STEP(runSR_DD_1);
- FINALIZER(runClearTable);
-}
-TESTCASE("SR_DD_1_LCP", "")
-{
- TC_PROPERTY("ALL", 1);
- TC_PROPERTY("LCP", 1);
- INITIALIZER(runWaitStarted);
- STEP(runStopper);
- STEP(runSR_DD_1);
- FINALIZER(runClearTable);
-}
-TESTCASE("SR_DD_1b_LCP", "")
-{
- TC_PROPERTY("LCP", 1);
- INITIALIZER(runWaitStarted);
- STEP(runSR_DD_1);
- FINALIZER(runClearTable);
-}
-TESTCASE("SR_DD_2", "")
-{
- TC_PROPERTY("ALL", 1);
- INITIALIZER(runWaitStarted);
- STEP(runStopper);
- STEP(runSR_DD_2);
- FINALIZER(runClearTable);
-}
-TESTCASE("SR_DD_2b", "")
-{
- INITIALIZER(runWaitStarted);
- STEP(runSR_DD_2);
- FINALIZER(runClearTable);
-}
-TESTCASE("SR_DD_2_LCP", "")
-{
- TC_PROPERTY("ALL", 1);
- TC_PROPERTY("LCP", 1);
- INITIALIZER(runWaitStarted);
- STEP(runStopper);
- STEP(runSR_DD_2);
- FINALIZER(runClearTable);
-}
-TESTCASE("SR_DD_2b_LCP", "")
-{
- TC_PROPERTY("LCP", 1);
- INITIALIZER(runWaitStarted);
- STEP(runSR_DD_2);
- FINALIZER(runClearTable);
-}
-TESTCASE("Bug29167", "")
-{
- INITIALIZER(runWaitStarted);
- STEP(runBug29167);
-}
-TESTCASE("Bug28770",
- "Check readTableFile1 fails, readTableFile2 succeeds\n"
- "1. Restart all node -nostart\n"
- "2. Insert error 6100 into all nodes\n"
- "3. Start all nodes\n"
- "4. Ensure cluster start\n"
- "5. Read and verify reocrds\n"
- "6. Repeat until looping is completed\n"){
- INITIALIZER(runWaitStarted);
- INITIALIZER(runClearTable);
- STEP(runBug28770);
- FINALIZER(runClearTable);
-}
-TESTCASE("Bug22696", "")
-{
- INITIALIZER(runWaitStarted);
- INITIALIZER(runLoadTable);
- INITIALIZER(runBug22696);
- FINALIZER(runClearTable);
-}
-NDBT_TESTSUITE_END(testSystemRestart);
-
-int main(int argc, const char** argv){
- ndb_init();
- return testSystemRestart.execute(argc, argv);
-}
-
-
diff --git a/storage/ndb/test/ndbapi/testTimeout.cpp b/storage/ndb/test/ndbapi/testTimeout.cpp
deleted file mode 100644
index 711a943f965..00000000000
--- a/storage/ndb/test/ndbapi/testTimeout.cpp
+++ /dev/null
@@ -1,562 +0,0 @@
-/* Copyright (c) 2003-2006 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT.hpp>
-#include <NDBT_Test.hpp>
-#include <HugoTransactions.hpp>
-#include <UtilTransactions.hpp>
-#include <random.h>
-#include <NdbConfig.hpp>
-#include <signaldata/DumpStateOrd.hpp>
-
-#define TIMEOUT (Uint32)3000
-Uint32 g_org_timeout = 3000;
-Uint32 g_org_deadlock = 3000;
-
-int
-setTransactionTimeout(NDBT_Context* ctx, NDBT_Step* step){
- NdbRestarter restarter;
- int timeout = ctx->getProperty("TransactionInactiveTimeout",TIMEOUT);
-
- NdbConfig conf(GETNDB(step)->getNodeId()+1);
- unsigned int nodeId = conf.getMasterNodeId();
- if (!conf.getProperty(nodeId,
- NODE_TYPE_DB,
- CFG_DB_TRANSACTION_INACTIVE_TIMEOUT,
- &g_org_timeout)){
- return NDBT_FAILED;
- }
-
- int val[] = { DumpStateOrd::TcSetApplTransactionTimeout, timeout };
- if(restarter.dumpStateAllNodes(val, 2) != 0){
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-int
-resetTransactionTimeout(NDBT_Context* ctx, NDBT_Step* step){
- NdbRestarter restarter;
-
- int val[] = { DumpStateOrd::TcSetApplTransactionTimeout, g_org_timeout };
- if(restarter.dumpStateAllNodes(val, 2) != 0){
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-int
-setDeadlockTimeout(NDBT_Context* ctx, NDBT_Step* step){
- NdbRestarter restarter;
- int timeout = ctx->getProperty("TransactionDeadlockTimeout", TIMEOUT);
-
- NdbConfig conf(GETNDB(step)->getNodeId()+1);
- unsigned int nodeId = conf.getMasterNodeId();
- if (!conf.getProperty(nodeId,
- NODE_TYPE_DB,
- CFG_DB_TRANSACTION_DEADLOCK_TIMEOUT,
- &g_org_deadlock))
- return NDBT_FAILED;
-
- g_err << "Setting timeout: " << timeout << endl;
- int val[] = { DumpStateOrd::TcSetTransactionTimeout, timeout };
- if(restarter.dumpStateAllNodes(val, 2) != 0){
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-int
-getDeadlockTimeout(NDBT_Context* ctx, NDBT_Step* step){
- NdbRestarter restarter;
-
- Uint32 val = 0;
- NdbConfig conf(GETNDB(step)->getNodeId()+1);
- unsigned int nodeId = conf.getMasterNodeId();
- if (!conf.getProperty(nodeId,
- NODE_TYPE_DB,
- CFG_DB_TRANSACTION_DEADLOCK_TIMEOUT,
- &val))
- return NDBT_FAILED;
-
- if (val < 120000)
- val = 120000;
- ctx->setProperty("TransactionDeadlockTimeout", 4*val);
-
- return NDBT_OK;
-}
-
-int
-resetDeadlockTimeout(NDBT_Context* ctx, NDBT_Step* step){
- NdbRestarter restarter;
-
- int val[] = { DumpStateOrd::TcSetTransactionTimeout, g_org_deadlock };
- if(restarter.dumpStateAllNodes(val, 2) != 0){
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-
-int runLoadTable(NDBT_Context* ctx, NDBT_Step* step){
-
- int records = ctx->getNumRecords();
- HugoTransactions hugoTrans(*ctx->getTab());
- if (hugoTrans.loadTable(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runClearTable(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
-
- UtilTransactions utilTrans(*ctx->getTab());
- if (utilTrans.clearTable2(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-
-#define CHECK(b) if (!(b)) { \
- ndbout << "ERR: "<< step->getName() \
- << " failed on line " << __LINE__ << endl; \
- result = NDBT_FAILED; \
- break; }
-
-int runTimeoutTrans2(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int stepNo = step->getStepNo();
- int mul1 = ctx->getProperty("Op1", (Uint32)0);
- int mul2 = ctx->getProperty("Op2", (Uint32)0);
- int records = ctx->getNumRecords();
-
- int timeout = ctx->getProperty("TransactionInactiveTimeout",TIMEOUT);
-
- int minSleep = (int)(timeout * 1.5);
- int maxSleep = timeout * 2;
-
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- for (int l = 0; l<loops && !ctx->isTestStopped() && result == NDBT_OK; l++){
-
- int op1 = 0 + (l + stepNo) * mul1;
- int op2 = 0 + (l + stepNo) * mul2;
-
- op1 = (op1 % 5);
- op2 = (op2 % 5);
-
- ndbout << stepNo << ": TransactionInactiveTimeout="<< timeout
- << ", minSleep="<<minSleep
- << ", maxSleep="<<maxSleep
- << ", op1=" << op1
- << ", op2=" << op2 << endl;;
-
- do{
- // Commit transaction
- CHECK(hugoOps.startTransaction(pNdb) == 0);
-
- switch(op1){
- case 0:
- break;
- case 1:
- if(hugoOps.pkReadRecord(pNdb, stepNo) != 0){
- g_err << stepNo << ": Fail" << __LINE__ << endl;
- result = NDBT_FAILED; break;
- }
- break;
- case 2:
- if(hugoOps.pkUpdateRecord(pNdb, stepNo) != 0){
- g_err << stepNo << ": Fail" << __LINE__ << endl;
- result = NDBT_FAILED; break;
- }
- break;
- case 3:
- if(hugoOps.pkDeleteRecord(pNdb, stepNo) != 0){
- g_err << stepNo << ": Fail" << __LINE__ << endl;
- result = NDBT_FAILED; break;
- }
- break;
- case 4:
- if(hugoOps.pkInsertRecord(pNdb, stepNo+records+l) != 0){
- g_err << stepNo << ": Fail" << __LINE__ << endl;
- result = NDBT_FAILED; break;
- }
- break;
- }
-
- if(result != NDBT_OK)
- break;
-
- int res = hugoOps.execute_NoCommit(pNdb);
- if(res != 0){
- g_err << stepNo << ": Fail" << __LINE__ << endl;
- result = NDBT_FAILED; break;
- }
-
- int sleep = minSleep + myRandom48(maxSleep-minSleep);
- ndbout << stepNo << ": Sleeping for "<< sleep << " milliseconds" << endl;
- NdbSleep_MilliSleep(sleep);
-
- switch(op2){
- case 0:
- break;
- case 1:
- if(hugoOps.pkReadRecord(pNdb, stepNo) != 0){
- g_err << stepNo << ": Fail" << __LINE__ << endl;
- result = NDBT_FAILED; break;
- }
- break;
- case 2:
- if(hugoOps.pkUpdateRecord(pNdb, stepNo) != 0){
- g_err << stepNo << ": Fail" << __LINE__ << endl;
- result = NDBT_FAILED; break;
- }
- break;
- case 3:
- if(hugoOps.pkDeleteRecord(pNdb, stepNo) != 0){
- g_err << stepNo << ": Fail" << __LINE__ << endl;
- result = NDBT_FAILED; break;
- }
- break;
- case 4:
- if(hugoOps.pkInsertRecord(pNdb, stepNo+2*records+l) != 0){
- g_err << stepNo << ": Fail" << __LINE__ << endl;
- result = NDBT_FAILED; break;
- }
- break;
- }
-
- // Expect that transaction has timed-out
- res = hugoOps.execute_Commit(pNdb);
- if(op1 != 0 && res != 266){
- g_err << stepNo << ": Fail: " << res << "!= 237, op1="
- << op1 << ", op2=" << op2 << endl;
- result = NDBT_FAILED; break;
- }
-
- } while(false);
-
- hugoOps.closeTransaction(pNdb);
- }
-
- return result;
-}
-
-int runDontTimeoutTrans(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int stepNo = step->getStepNo();
-
- int timeout = ctx->getProperty("TransactionInactiveTimeout",TIMEOUT);
-
- int maxSleep = (int)(timeout * 0.5);
- ndbout << "TransactionInactiveTimeout="<< timeout
- << ", maxSleep="<<maxSleep<<endl;
-
-
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- for (int l = 0; l < loops && result == NDBT_OK; l++){
-
- do{
- // Commit transaction
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, stepNo) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
-
- int sleep = myRandom48(maxSleep);
- ndbout << "Sleeping for " << sleep << " milliseconds" << endl;
- NdbSleep_MilliSleep(sleep);
-
- // Expect that transaction has NOT timed-out
- CHECK(hugoOps.execute_Commit(pNdb) == 0);
-
- } while(false);
-
- hugoOps.closeTransaction(pNdb);
- }
-
- return result;
-}
-
-int runDeadlockTimeoutTrans(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int stepNo = step->getStepNo();
-
- Uint32 deadlock_timeout;
- NdbConfig conf(GETNDB(step)->getNodeId()+1);
- unsigned int nodeId = conf.getMasterNodeId();
- if (!conf.getProperty(nodeId,
- NODE_TYPE_DB,
- CFG_DB_TRANSACTION_DEADLOCK_TIMEOUT,
- &deadlock_timeout)){
- return NDBT_FAILED;
- }
-
-
- int do_sleep = (int)(deadlock_timeout * 0.5);
-
-
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- for (int l = 0; l < loops && result == NDBT_OK; l++){
-
- do{
- // Commit transaction
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkReadRecord(pNdb, stepNo) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
-
- int sleep = deadlock_timeout * 1.5 + myRandom48(do_sleep);
- ndbout << "Sleeping for " << sleep << " milliseconds" << endl;
- NdbSleep_MilliSleep(sleep);
-
- // Expect that transaction has NOT timed-out
- CHECK(hugoOps.execute_Commit(pNdb) == 0);
-
- } while(false);
-
- hugoOps.closeTransaction(pNdb);
- }
-
- return result;
-}
-
-int runBuddyTransNoTimeout(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int stepNo = step->getStepNo();
- int maxSleep = (int)(TIMEOUT * 0.3);
- ndbout << "TransactionInactiveTimeout="<< TIMEOUT
- << ", maxSleep="<<maxSleep<<endl;
-
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- for (int l = 1; l < loops && result == NDBT_OK; l++){
-
- do{
- // Start an insert trans
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- int recordNo = records + (stepNo*loops) + l;
- CHECK(hugoOps.pkInsertRecord(pNdb, recordNo) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
-
- for (int i = 0; i < 3; i++){
- // Perform buddy scan reads
- CHECK((hugoOps.scanReadRecords(pNdb)) == 0);
- CHECK(hugoOps.execute_NoCommit(pNdb) == 0);
-
- int sleep = myRandom48(maxSleep);
- ndbout << "Sleeping for " << sleep << " milliseconds" << endl;
- NdbSleep_MilliSleep(sleep);
- }
-
- // Expect that transaction has NOT timed-out
- CHECK(hugoOps.execute_Commit(pNdb) == 0);
-
- } while(false);
-
- hugoOps.closeTransaction(pNdb);
- }
-
- return result;
-}
-
-int runBuddyTransTimeout(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- int stepNo = step->getStepNo();
- ndbout << "TransactionInactiveTimeout="<< TIMEOUT <<endl;
-
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- for (int l = 1; l < loops && result == NDBT_OK; l++){
-
- NdbTransaction* pTrans = 0;
- do{
- pTrans = pNdb->startTransaction();
- NdbScanOperation* pOp = pTrans->getNdbScanOperation(ctx->getTab());
- CHECK(pOp->readTuples(NdbOperation::LM_Read, 0, 0, 1) == 0);
- CHECK(pTrans->execute(NoCommit) == 0);
-
- int sleep = 2 * TIMEOUT;
- ndbout << "Sleeping for " << sleep << " milliseconds" << endl;
- NdbSleep_MilliSleep(sleep);
-
- int res = 0;
- while((res = pOp->nextResult()) == 0);
- ndbout_c("res: %d", res);
- CHECK(res == -1);
-
- } while(false);
-
- if (pTrans)
- {
- pTrans->close();
- }
- }
-
- return result;
-}
-
-int
-runError4012(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- int stepNo = step->getStepNo();
-
- int timeout = ctx->getProperty("TransactionDeadlockTimeout", TIMEOUT);
-
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- do{
- // Commit transaction
- CHECK(hugoOps.startTransaction(pNdb) == 0);
- CHECK(hugoOps.pkUpdateRecord(pNdb, 0) == 0);
- int ret = hugoOps.execute_NoCommit(pNdb);
- if (ret == 0)
- {
- int sleep = timeout;
- ndbout << "Sleeping for " << sleep << " milliseconds" << endl;
- NdbSleep_MilliSleep(sleep);
-
- // Expect that transaction has NOT timed-out
- CHECK(hugoOps.execute_Commit(pNdb) == 0);
- }
- else
- {
- CHECK(ret == 4012);
- }
- } while(false);
-
- hugoOps.closeTransaction(pNdb);
-
- return result;
-}
-
-
-NDBT_TESTSUITE(testTimeout);
-TESTCASE("DontTimeoutTransaction",
- "Test that the transaction does not timeout "\
- "if we sleep during the transaction. Use a sleep "\
- "value which is smaller than TransactionInactiveTimeout"){
- INITIALIZER(runLoadTable);
- INITIALIZER(setTransactionTimeout);
- STEPS(runDontTimeoutTrans, 1);
- FINALIZER(resetTransactionTimeout);
- FINALIZER(runClearTable);
-}
-TESTCASE("Bug11290",
- "Setting TransactionInactiveTimeout to 0(zero) "\
- "should result in infinite timeout, and not as "\
- "was the bug, a timeout that is equal to the deadlock timeout"){
- TC_PROPERTY("TransactionInactiveTimeout",(Uint32)0);
- INITIALIZER(runLoadTable);
- INITIALIZER(setTransactionTimeout);
- STEPS(runDeadlockTimeoutTrans, 1);
- FINALIZER(resetTransactionTimeout);
- FINALIZER(runClearTable);
-}
-TESTCASE("DontTimeoutTransaction5",
- "Test that the transaction does not timeout "\
- "if we sleep during the transaction. Use a sleep "\
- "value which is smaller than TransactionInactiveTimeout" \
- "Five simultaneous threads"){
- INITIALIZER(runLoadTable);
- INITIALIZER(setTransactionTimeout);
- STEPS(runDontTimeoutTrans, 5);
- FINALIZER(resetTransactionTimeout);
- FINALIZER(runClearTable);
-}
-TESTCASE("TimeoutRandTransaction",
- "Test that the transaction does timeout "\
- "if we sleep during the transaction. Use a sleep "\
- "value which is larger than TransactionInactiveTimeout"){
- INITIALIZER(runLoadTable);
- INITIALIZER(setTransactionTimeout);
- TC_PROPERTY("Op1", 7);
- TC_PROPERTY("Op2", 11);
- STEPS(runTimeoutTrans2, 5);
- FINALIZER(resetTransactionTimeout);
- FINALIZER(runClearTable);
-}
-TESTCASE("BuddyTransNoTimeout",
- "Start a transaction and perform an insert with NoCommit. " \
- "Start a buddy transaction wich performs long running scans " \
- "and sleeps. " \
- "The total sleep time is longer than TransactionInactiveTimeout" \
- "Commit the first transaction, it should not have timed out."){
- INITIALIZER(runLoadTable);
- INITIALIZER(setTransactionTimeout);
- STEPS(runBuddyTransNoTimeout, 1);
- FINALIZER(resetTransactionTimeout);
- FINALIZER(runClearTable);
-}
-TESTCASE("BuddyTransNoTimeout5",
- "Start a transaction and perform an insert with NoCommit. " \
- "Start a buddy transaction wich performs long running scans " \
- "and sleeps. " \
- "The total sleep time is longer than TransactionInactiveTimeout" \
- "Commit the first transaction, it should not have timed out." \
- "Five simultaneous threads"){
- INITIALIZER(runLoadTable);
- INITIALIZER(setTransactionTimeout);
- STEPS(runBuddyTransNoTimeout, 5);
- FINALIZER(resetTransactionTimeout);
- FINALIZER(runClearTable);
-}
-TESTCASE("BuddyTransTimeout1",
- "Start a scan and check that it gets aborted"){
- INITIALIZER(runLoadTable);
- INITIALIZER(setTransactionTimeout);
- STEPS(runBuddyTransTimeout, 1);
- FINALIZER(resetTransactionTimeout);
- FINALIZER(runClearTable);
-}
-#if 0
-TESTCASE("Error4012", ""){
- TC_PROPERTY("TransactionDeadlockTimeout", 120000);
- INITIALIZER(runLoadTable);
- INITIALIZER(getDeadlockTimeout);
- INITIALIZER(setDeadlockTimeout);
- STEPS(runError4012, 2);
- FINALIZER(runClearTable);
-}
-#endif
-NDBT_TESTSUITE_END(testTimeout);
-
-int main(int argc, const char** argv){
- ndb_init();
- myRandom48Init(NdbTick_CurrentMillisecond());
- return testTimeout.execute(argc, argv);
-}
-
diff --git a/storage/ndb/test/ndbapi/testTransactions.cpp b/storage/ndb/test/ndbapi/testTransactions.cpp
deleted file mode 100644
index 53b3faf6920..00000000000
--- a/storage/ndb/test/ndbapi/testTransactions.cpp
+++ /dev/null
@@ -1,419 +0,0 @@
-/* Copyright (c) 2003-2006 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT_Test.hpp>
-#include <NDBT_ReturnCodes.h>
-#include <HugoTransactions.hpp>
-#include <UtilTransactions.hpp>
-#include <NdbRestarter.hpp>
-#include <signaldata/DumpStateOrd.hpp>
-
-struct OperationTestCase {
- const char * name;
- bool preCond; // start transaction | insert | commit
-
- // start transaction 1
- const char * op1;
- const int val1;
-
- // no commit
-
- // start transaction 2
- const char * op2;
- const int res2;
- const int val2;
- // no commit
-
- // commit transaction 1
- // commit transaction 2
-
- // start transaction
- // op3 = READ
- const int res3;
- const int val3;
- // commit transaction
-};
-
-#define X -1
-
-OperationTestCase matrix[] = {
- { "ReadRead", true, "READ", 1, "READ", 0, 1, 0, 1 },
- { "ReadReadEx", true, "READ", 1, "READ-EX", 266, X, 0, 1 },
- { "ReadSimpleRead", true, "READ", 1, "S-READ", 0, 1, 0, 1 },
- { "ReadDirtyRead", true, "READ", 1, "D-READ", 0, 1, 0, 1 },
- { "ReadInsert", true, "READ", 1, "INSERT", 266, X, 0, 1 },
- { "ReadUpdate", true, "READ", 1, "UPDATE", 266, X, 0, 1 },
- { "ReadDelete", true, "READ", 1, "DELETE", 266, X, 0, 1 },
- { "ReadScan", true, "READ", 1, "SCAN", 0, 1, 0, 1 },
- { "ReadScanHl", true, "READ", 1, "SCAN-HL", 0, 1, 0, 1 },
- { "ReadScanEx", true, "READ", 1, "SCAN-EX", 274, X, 0, 1 },
-#if 0
- { "ReadScanUp", true, "READ", 1, "SCAN-UP", 266, X, 0, 1 },
- { "ReadScanDe", true, "READ", 1, "SCAN-DE", 266, X, 0, 1 },
-#endif
-
- { "ScanRead", true, "SCAN", 1, "READ", 0, 1, 0, 1 },
- { "ScanReadEx", true, "SCAN", 1, "READ-EX", 0, 1, 0, 1 },
- { "ScanSimpleRead", true, "SCAN", 1, "S-READ", 0, 1, 0, 1 },
- { "ScanDirtyRead", true, "SCAN", 1, "D-READ", 0, 1, 0, 1 },
- { "ScanInsert", true, "SCAN", 1, "INSERT", 630, X, 0, 1 },
- { "ScanUpdate", true, "SCAN", 1, "UPDATE", 0, 2, 0, 2 },
- { "ScanDelete", true, "SCAN", 1, "DELETE", 0, X, 626, X },
- { "ScanScan", true, "SCAN", 1, "SCAN", 0, 1, 0, 1 },
- { "ScanScanHl", true, "SCAN", 1, "SCAN-HL", 0, 1, 0, 1 },
- { "ScanScanEx", true, "SCAN", 1, "SCAN-EX", 0, 1, 0, 1 },
-#if 0
- { "ScanScanUp", true, "SCAN", 1, "SCAN-UP", 266, X, 0, 1 },
- { "ScanScanDe", true, "SCAN", 1, "SCAN-DE", 266, X, 0, 1 },
-#endif
-
- { "ScanHlRead", true, "SCAN-HL",1, "READ", 0, 1, 0, 1 },
- { "ScanHlReadEx", true, "SCAN-HL",1, "READ-EX", 266, 1, 0, 1 },
- { "ScanHlSimpleRead", true, "SCAN-HL",1, "S-READ", 0, 1, 0, 1 },
- { "ScanHlDirtyRead", true, "SCAN-HL",1, "D-READ", 0, 1, 0, 1 },
- { "ScanHlInsert", true, "SCAN-HL",1, "INSERT", 266, X, 0, 1 },
- { "ScanHlUpdate", true, "SCAN-HL",1, "UPDATE", 266, 2, 0, 1 },
- { "ScanHlDelete", true, "SCAN-HL",1, "DELETE", 266, X, 0, 1 },
- { "ScanHlScan", true, "SCAN-HL",1, "SCAN", 0, 1, 0, 1 },
- { "ScanHlScanHl", true, "SCAN-HL",1, "SCAN-HL", 0, 1, 0, 1 },
- { "ScanHlScanEx", true, "SCAN-HL",1, "SCAN-EX", 274, X, 0, 1 },
-#if 0
- { "ScanHlScanUp", true, "SCAN-HL",1, "SCAN-UP", 266, X, 0, 1 },
- { "ScanHlScanDe", true, "SCAN-HL",1, "SCAN-DE", 266, X, 0, 1 },
-#endif
-
- { "ScanExRead", true, "SCAN-EX",1, "READ", 266, 1, 0, 1 },
- { "ScanExReadEx", true, "SCAN-EX",1, "READ-EX", 266, 1, 0, 1 },
- { "ScanExSimpleRead", true, "SCAN-EX",1, "S-READ", 266, 1, 0, 1 },
- { "ScanExDirtyRead", true, "SCAN-EX",1, "D-READ", 0, 1, 0, 1 },
- { "ScanExInsert", true, "SCAN-EX",1, "INSERT", 266, X, 0, 1 },
- { "ScanExUpdate", true, "SCAN-EX",1, "UPDATE", 266, 2, 0, 1 },
- { "ScanExDelete", true, "SCAN-EX",1, "DELETE", 266, X, 0, 1 },
- { "ScanExScan", true, "SCAN-EX",1, "SCAN", 0, 1, 0, 1 },
- { "ScanExScanHl", true, "SCAN-EX",1, "SCAN-HL", 274, X, 0, 1 },
- { "ScanExScanEx", true, "SCAN-EX",1, "SCAN-EX", 274, X, 0, 1 },
-#if 0
- { "ScanExScanUp", true, "SCAN-EX",1, "SCAN-UP", 266, X, 0, 1 },
- { "ScanExScanDe", true, "SCAN-EX",1, "SCAN-DE", 266, X, 0, 1 },
-#endif
-
- { "ReadExRead", true, "READ-EX",1, "READ", 266, X, 0, 1 },
- { "ReadExReadEx", true, "READ-EX",1, "READ-EX", 266, X, 0, 1 },
- { "ReadExSimpleRead", true, "READ-EX",1, "S-READ", 266, X, 0, 1 },
- { "ReadExDirtyRead", true, "READ-EX",1, "D-READ", 0, 1, 0, 1 },
- { "ReadExInsert", true, "READ-EX",1, "INSERT", 266, X, 0, 1 },
- { "ReadExUpdate", true, "READ-EX",1, "UPDATE", 266, X, 0, 1 },
- { "ReadExDelete", true, "READ-EX",1, "DELETE", 266, X, 0, 1 },
- { "ReadExScan", true, "READ-EX",1, "SCAN", 0, 1, 0, 1 },
- { "ReadExScanHl", true, "READ-EX",1, "SCAN-HL", 274, X, 0, 1 },
- { "ReadExScanEx", true, "READ-EX",1, "SCAN-EX", 274, X, 0, 1 },
-#if 0
- { "ReadExScanUp", true, "READ-EX",1, "SCAN-UP", 266, X, 0, 1 },
- { "ReadExScanDe", true, "READ-EX",1, "SCAN-DE", 266, X, 0, 1 },
-#endif
-
- { "InsertRead", false, "INSERT", 1, "READ", 266, X, 0, 1 },
- { "InsertReadEx", false, "INSERT", 1, "READ-EX", 266, X, 0, 1 },
- { "InsertSimpleRead",false, "INSERT", 1, "S-READ", 266, X, 0, 1 },
- { "InsertDirtyRead", false, "INSERT", 1, "D-READ", 626, X, 0, 1 },
- { "InsertInsert", false, "INSERT", 1, "INSERT", 266, X, 0, 1 },
- { "InsertUpdate", false, "INSERT", 1, "UPDATE", 266, X, 0, 1 },
- { "InsertDelete", false, "INSERT", 1, "DELETE", 266, X, 0, 1 },
- { "InsertScan", false, "INSERT", 1, "SCAN", 626, X, 0, 1 },
- { "InsertScanHl", false, "INSERT", 1, "SCAN-HL", 274, X, 0, 1 },
- { "InsertScanEx", false, "INSERT", 1, "SCAN-EX", 274, X, 0, 1 },
-#if 0
- { "InsertScanUp", false, "INSERT", 1, "SCAN-UP", 266, X, 0, 1 },
- { "InsertScanDe", false, "INSERT", 1, "SCAN-DE", 266, X, 0, 1 },
-#endif
-
- { "UpdateRead", true, "UPDATE", 2, "READ", 266, X, 0, 2 },
- { "UpdateReadEx", true, "UPDATE", 2, "READ-EX", 266, X, 0, 2 },
- { "UpdateSimpleRead", true, "UPDATE", 2, "S-READ", 266, X, 0, 2 },
- { "UpdateDirtyRead", true, "UPDATE", 2, "D-READ", 0, 1, 0, 2 },
- { "UpdateInsert", true, "UPDATE", 2, "INSERT", 266, X, 0, 2 },
- { "UpdateUpdate", true, "UPDATE", 2, "UPDATE", 266, X, 0, 2 },
- { "UpdateDelete", true, "UPDATE", 2, "DELETE", 266, X, 0, 2 },
- { "UpdateScan", true, "UPDATE", 2, "SCAN", 0, 1, 0, 2 },
- { "UpdateScanHl", true, "UPDATE", 2, "SCAN-HL", 274, X, 0, 2 },
- { "UpdateScanEx", true, "UPDATE", 2, "SCAN-EX", 274, X, 0, 2 },
-#if 0
- { "UpdateScanUp", true, "UPDATE", 2, "SCAN-UP", 266, X, 0, 2 },
- { "UpdateScanDe", true, "UPDATE", 2, "SCAN-DE", 266, X, 0, 2 },
-#endif
-
- { "DeleteRead", true, "DELETE", X, "READ", 266, X, 626, X },
- { "DeleteReadEx", true, "DELETE", X, "READ-EX", 266, X, 626, X },
- { "DeleteSimpleRead", true, "DELETE", X, "S-READ", 266, X, 626, X },
- { "DeleteDirtyRead", true, "DELETE", X, "D-READ", 0, 1, 626, X },
- { "DeleteInsert", true, "DELETE", X, "INSERT", 266, X, 626, X },
- { "DeleteUpdate", true, "DELETE", X, "UPDATE", 266, X, 626, X },
- { "DeleteDelete", true, "DELETE", X, "DELETE", 266, X, 626, X },
- { "DeleteScan", true, "DELETE", X, "SCAN", 0, 1, 626, X },
- { "DeleteScanHl", true, "DELETE", X, "SCAN-HL", 274, X, 626, X },
- { "DeleteScanEx", true, "DELETE", X, "SCAN-EX", 274, X, 626, X },
-#if 0
- { "DeleteScanUp", true, "DELETE", X, "SCAN-UP", 266, X, 626, X },
- { "DeleteScanDe", true, "DELETE", X, "SCAN-DE", 266, X, 626, X }
-#endif
-
-};
-
-#define CHECK(a, b) { int x = a; int y = b; if (x != y) { \
- g_err << "ERR: "<< step->getName() \
- << " failed on line " << __LINE__ << endl << " " \
- << x << " != " << y << endl;\
- result = NDBT_FAILED; \
- break; } }
-
-int
-runOp(HugoOperations & hugoOps,
- Ndb * pNdb,
- const char * op,
- int value){
-
-#define C2(x) if(!(x)) {\
- g_err << "ERR: failed on line " << __LINE__ << endl; \
- return NDBT_FAILED; }
-
- if(strcmp(op, "READ") == 0){
- C2(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Read) == 0);
- } else if(strcmp(op, "READ-EX") == 0){
- C2(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Exclusive) == 0);
- } else if(strcmp(op, "S-READ") == 0){
- C2(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_Read) == 0);
- } else if(strcmp(op, "D-READ") == 0){
- C2(hugoOps.pkReadRecord(pNdb, 1, 1, NdbOperation::LM_CommittedRead) == 0);
- } else if(strcmp(op, "INSERT") == 0){
- C2(hugoOps.pkInsertRecord(pNdb, 1, 1, value) == 0);
- } else if(strcmp(op, "UPDATE") == 0){
- C2(hugoOps.pkUpdateRecord(pNdb, 1, 1, value) == 0);
- } else if(strcmp(op, "DELETE") == 0){
- C2(hugoOps.pkDeleteRecord(pNdb, 1, 1) == 0);
- } else if(strcmp(op, "SCAN") == 0){
- C2(hugoOps.scanReadRecords(pNdb) == 0);
- } else if(strcmp(op, "SCAN-HL") == 0){
- C2(hugoOps.scanReadRecords(pNdb, NdbScanOperation::LM_Read)== 0);
- } else if(strcmp(op, "SCAN-EX") == 0){
- C2(hugoOps.scanReadRecords(pNdb, NdbScanOperation::LM_Exclusive)== 0);
- } else {
- g_err << __FILE__ << " - " << __LINE__
- << ": Unknown operation" << op << endl;
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-int
-checkVal(HugoOperations & hugoOps,
- const char * op,
- int value,
- int result){
-
- if(result != 0)
- return NDBT_OK;
-
- if(strcmp(op, "READ") == 0){
- } else if(strcmp(op, "READ-EX") == 0){
- } else if(strcmp(op, "S-READ") == 0){
- } else if(strcmp(op, "D-READ") == 0){
- } else if(strcmp(op, "SCAN") == 0){
- } else if(strcmp(op, "SCAN-HL") == 0){
- } else if(strcmp(op, "SCAN-EX") == 0){
- } else {
- return NDBT_OK;
- }
-
- return hugoOps.verifyUpdatesValue(value);
-}
-
-#define TIMEOUT 100
-
-int
-setTransactionTimeout(NDBT_Context* ctx, NDBT_Step* step){
- NdbRestarter restarter;
-
- int val[] =
- { DumpStateOrd::TcSetTransactionTimeout, TIMEOUT };
- if(restarter.dumpStateAllNodes(val, 2) != 0){
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-int
-runTwoTrans1(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- HugoOperations T1(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- const char * op1 = ctx->getProperty("op1", "NONE");
- int val1 = ctx->getProperty("val1", ~0);
-
- do {
- // Insert, read
- CHECK(T1.startTransaction(pNdb), 0);
- CHECK(runOp(T1, pNdb, op1, val1), 0);
- CHECK(T1.execute_NoCommit(pNdb), 0);
- CHECK(checkVal(T1, op1, val1, 0), 0);
-
- ctx->setProperty("T1-1-Complete", 1);
- while(ctx->getProperty("T2-Complete", (Uint32)0) == 0){
- T1.refresh();
- NdbSleep_MilliSleep(10);
- }
-
- CHECK(T1.execute_Commit(pNdb), 0);
-
- } while(false);
- T1.closeTransaction(pNdb);
-
- if(result != NDBT_OK)
- return result;
-
- const int res3 = ctx->getProperty("res3", ~0);
- const int val3 = ctx->getProperty("val3", ~0);
-
- do {
- CHECK(T1.startTransaction(pNdb), 0);
- CHECK(runOp(T1, pNdb, "READ", 0), 0);
- CHECK(T1.execute_Commit(pNdb), res3);
- CHECK(checkVal(T1, "READ", val3, res3), 0);
- } while(false);
- T1.closeTransaction(pNdb);
-
- return result;
-}
-
-int
-runTwoTrans2(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- HugoOperations T2(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- const char * op2 = ctx->getProperty("op2", "NONE");
- const int res2 = ctx->getProperty("res2", ~0);
- const int val2 = ctx->getProperty("val2", ~0);
-
- while(ctx->getProperty("T1-1-Complete", (Uint32)0) == 0 &&
- !ctx->isTestStopped()){
- NdbSleep_MilliSleep(100);
- }
-
- if(!ctx->isTestStopped()){
- do {
- CHECK(T2.startTransaction(pNdb), 0);
- CHECK(runOp(T2, pNdb, op2, val2), 0);
- CHECK(T2.execute_NoCommit(pNdb), res2);
- CHECK(checkVal(T2, op2, val2, res2), 0);
- if(res2 == 0){
- CHECK(T2.execute_Commit(pNdb), res2);
- }
- } while(false);
- T2.closeTransaction(pNdb);
- }
-
- ctx->setProperty("T2-Complete", 1);
-
- return result;
-}
-
-int
-runInsertRecord(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- HugoOperations hugoOps(*ctx->getTab());
- Ndb* pNdb = GETNDB(step);
-
- do{
- // Insert, insert
- CHECK(hugoOps.startTransaction(pNdb), 0);
- CHECK(hugoOps.pkInsertRecord(pNdb, 1, 1, 1), 0);
- CHECK(hugoOps.execute_Commit(pNdb), 0);
- } while(false);
-
- hugoOps.closeTransaction(pNdb);
-
- return result;
-}
-
-int
-runClearTable(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
-
- UtilTransactions utilTrans(*ctx->getTab());
- if (utilTrans.clearTable2(GETNDB(step), records, 240) != 0){
- return NDBT_FAILED;
- }
-
- NdbRestarter r;
- int lcp = 7099;
- r.dumpStateAllNodes(&lcp, 1);
-
- return NDBT_OK;
-}
-
-int
-main(int argc, const char** argv){
- ndb_init();
-
- NDBT_TestSuite ts("testOperations");
- ts.setTemporaryTables(true);
-
- for(Uint32 i = 0; i<sizeof(matrix)/sizeof(matrix[0]); i++){
- NDBT_TestCaseImpl1 *pt = new NDBT_TestCaseImpl1(&ts, matrix[i].name, "");
-
- pt->addInitializer(new NDBT_Initializer(pt,
- "runClearTable",
- runClearTable));
-
- if(matrix[i].preCond){
- pt->addInitializer(new NDBT_Initializer(pt,
- "runInsertRecord",
- runInsertRecord));
- }
-
- pt->addInitializer(new NDBT_Initializer(pt,
- "setTransactionTimeout",
- setTransactionTimeout));
-
- pt->setProperty("op1", matrix[i].op1);
- pt->setProperty("val1", matrix[i].val1);
-
- pt->setProperty("op2", matrix[i].op2);
- pt->setProperty("res2", matrix[i].res2);
- pt->setProperty("val2", matrix[i].val2);
-
- pt->setProperty("res3", matrix[i].res3);
- pt->setProperty("val3", matrix[i].val3);
-
- pt->addStep(new NDBT_ParallelStep(pt,
- matrix[i].name,
- runTwoTrans1));
- pt->addStep(new NDBT_ParallelStep(pt,
- matrix[i].name,
- runTwoTrans2));
- pt->addFinalizer(new NDBT_Finalizer(pt,
- "runClearTable",
- runClearTable));
-
- ts.addTest(pt);
- }
-
- return ts.execute(argc, argv);
-}
-
diff --git a/storage/ndb/test/ndbapi/test_event.cpp b/storage/ndb/test/ndbapi/test_event.cpp
deleted file mode 100644
index e435c59e457..00000000000
--- a/storage/ndb/test/ndbapi/test_event.cpp
+++ /dev/null
@@ -1,2051 +0,0 @@
-/* Copyright (c) 2003-2008 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT_Test.hpp>
-#include <NDBT_ReturnCodes.h>
-#include <HugoTransactions.hpp>
-#include <UtilTransactions.hpp>
-#include <TestNdbEventOperation.hpp>
-#include <NdbAutoPtr.hpp>
-#include <NdbRestarter.hpp>
-#include <NdbRestarts.hpp>
-#include <signaldata/DumpStateOrd.hpp>
-
-#define GETNDB(ps) ((NDBT_NdbApiStep*)ps)->getNdb()
-
-static int createEvent(Ndb *pNdb, const NdbDictionary::Table &tab,
- bool merge_events = false)
-{
- char eventName[1024];
- sprintf(eventName,"%s_EVENT",tab.getName());
-
- NdbDictionary::Dictionary *myDict = pNdb->getDictionary();
-
- if (!myDict) {
- g_err << "Dictionary not found "
- << pNdb->getNdbError().code << " "
- << pNdb->getNdbError().message << endl;
- return NDBT_FAILED;
- }
-
- NdbDictionary::Event myEvent(eventName);
- myEvent.setTable(tab.getName());
- myEvent.addTableEvent(NdbDictionary::Event::TE_ALL);
- for(int a = 0; a < tab.getNoOfColumns(); a++){
- myEvent.addEventColumn(a);
- }
- myEvent.mergeEvents(merge_events);
-
- int res = myDict->createEvent(myEvent); // Add event to database
-
- if (res == 0)
- myEvent.print();
- else if (myDict->getNdbError().classification ==
- NdbError::SchemaObjectExists)
- {
- g_info << "Event creation failed event exists\n";
- res = myDict->dropEvent(eventName);
- if (res) {
- g_err << "Failed to drop event: "
- << myDict->getNdbError().code << " : "
- << myDict->getNdbError().message << endl;
- return NDBT_FAILED;
- }
- // try again
- res = myDict->createEvent(myEvent); // Add event to database
- if (res) {
- g_err << "Failed to create event (1): "
- << myDict->getNdbError().code << " : "
- << myDict->getNdbError().message << endl;
- return NDBT_FAILED;
- }
- }
- else
- {
- g_err << "Failed to create event (2): "
- << myDict->getNdbError().code << " : "
- << myDict->getNdbError().message << endl;
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-static int dropEvent(Ndb *pNdb, const NdbDictionary::Table &tab)
-{
- char eventName[1024];
- sprintf(eventName,"%s_EVENT",tab.getName());
- NdbDictionary::Dictionary *myDict = pNdb->getDictionary();
- if (!myDict) {
- g_err << "Dictionary not found "
- << pNdb->getNdbError().code << " "
- << pNdb->getNdbError().message << endl;
- return NDBT_FAILED;
- }
- if (myDict->dropEvent(eventName)) {
- g_err << "Failed to drop event: "
- << myDict->getNdbError().code << " : "
- << myDict->getNdbError().message << endl;
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-static
-NdbEventOperation *createEventOperation(Ndb *ndb,
- const NdbDictionary::Table &tab,
- int do_report_error = 1)
-{
- char buf[1024];
- sprintf(buf, "%s_EVENT", tab.getName());
- NdbEventOperation *pOp= ndb->createEventOperation(buf);
- if (pOp == 0)
- {
- if (do_report_error)
- g_err << "createEventOperation: "
- << ndb->getNdbError().code << " "
- << ndb->getNdbError().message << endl;
- return 0;
- }
- int n_columns= tab.getNoOfColumns();
- for (int j = 0; j < n_columns; j++)
- {
- pOp->getValue(tab.getColumn(j)->getName());
- pOp->getPreValue(tab.getColumn(j)->getName());
- }
- if ( pOp->execute() )
- {
- if (do_report_error)
- g_err << "pOp->execute(): "
- << pOp->getNdbError().code << " "
- << pOp->getNdbError().message << endl;
- ndb->dropEventOperation(pOp);
- return 0;
- }
- return pOp;
-}
-
-static int runCreateEvent(NDBT_Context* ctx, NDBT_Step* step)
-{
- bool merge_events = ctx->getProperty("MergeEvents");
- if (createEvent(GETNDB(step),* ctx->getTab(), merge_events) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-struct receivedEvent {
- Uint32 pk;
- Uint32 count;
- Uint32 event;
-};
-
-static int
-eventOperation(Ndb* pNdb, const NdbDictionary::Table &tab, void* pstats, int records)
-{
- int i;
- const char function[] = "HugoTransactions::eventOperation: ";
- struct receivedEvent* recInsertEvent;
- NdbAutoObjArrayPtr<struct receivedEvent>
- p00( recInsertEvent = new struct receivedEvent[3*records] );
- struct receivedEvent* recUpdateEvent = &recInsertEvent[records];
- struct receivedEvent* recDeleteEvent = &recInsertEvent[2*records];
-
- EventOperationStats &stats = *(EventOperationStats*)pstats;
-
- stats.n_inserts = 0;
- stats.n_deletes = 0;
- stats.n_updates = 0;
- stats.n_consecutive = 0;
- stats.n_duplicates = 0;
- stats.n_inconsistent_gcis = 0;
-
- for (i = 0; i < records; i++) {
- recInsertEvent[i].pk = 0xFFFFFFFF;
- recInsertEvent[i].count = 0;
- recInsertEvent[i].event = 0xFFFFFFFF;
-
- recUpdateEvent[i].pk = 0xFFFFFFFF;
- recUpdateEvent[i].count = 0;
- recUpdateEvent[i].event = 0xFFFFFFFF;
-
- recDeleteEvent[i].pk = 0xFFFFFFFF;
- recDeleteEvent[i].count = 0;
- recDeleteEvent[i].event = 0xFFFFFFFF;
- }
-
- NdbDictionary::Dictionary *myDict = pNdb->getDictionary();
-
- if (!myDict) {
- g_err << function << "Event Creation failedDictionary not found\n";
- return NDBT_FAILED;
- }
-
- int r = 0;
- NdbEventOperation *pOp;
-
- char eventName[1024];
- sprintf(eventName,"%s_EVENT",tab.getName());
- Uint32 noEventColumnName = tab.getNoOfColumns();
-
- g_info << function << "create EventOperation\n";
- pOp = pNdb->createEventOperation(eventName);
- if ( pOp == NULL ) {
- g_err << function << "Event operation creation failed\n";
- return NDBT_FAILED;
- }
-
- g_info << function << "get values\n";
- NdbRecAttr* recAttr[1024];
- NdbRecAttr* recAttrPre[1024];
-
- const NdbDictionary::Table *_table = myDict->getTable(tab.getName());
-
- for (int a = 0; a < noEventColumnName; a++) {
- recAttr[a] = pOp->getValue(_table->getColumn(a)->getName());
- recAttrPre[a] = pOp->getPreValue(_table->getColumn(a)->getName());
- }
-
- // set up the callbacks
- g_info << function << "execute\n";
- if (pOp->execute()) { // This starts changes to "start flowing"
- g_err << function << "operation execution failed: \n";
- g_err << pOp->getNdbError().code << " "
- << pOp->getNdbError().message << endl;
- return NDBT_FAILED;
- }
-
- g_info << function << "ok\n";
-
- int count = 0;
- Uint32 last_inconsitant_gci = 0xEFFFFFF0;
-
- while (r < records){
- //printf("now waiting for event...\n");
- int res = pNdb->pollEvents(1000); // wait for event or 1000 ms
-
- if (res > 0) {
- //printf("got data! %d\n", r);
- NdbEventOperation *tmp;
- while ((tmp= pNdb->nextEvent()))
- {
- assert(tmp == pOp);
- r++;
- count++;
-
- Uint32 gci = pOp->getGCI();
- Uint32 pk = recAttr[0]->u_32_value();
-
- if (!pOp->isConsistent()) {
- if (last_inconsitant_gci != gci) {
- last_inconsitant_gci = gci;
- stats.n_inconsistent_gcis++;
- }
- g_warning << "A node failure has occured and events might be missing\n";
- }
- g_info << function << "GCI " << gci << ": " << count;
- struct receivedEvent* recEvent;
- switch (pOp->getEventType()) {
- case NdbDictionary::Event::TE_INSERT:
- stats.n_inserts++;
- g_info << " INSERT: ";
- recEvent = recInsertEvent;
- break;
- case NdbDictionary::Event::TE_DELETE:
- stats.n_deletes++;
- g_info << " DELETE: ";
- recEvent = recDeleteEvent;
- break;
- case NdbDictionary::Event::TE_UPDATE:
- stats.n_updates++;
- g_info << " UPDATE: ";
- recEvent = recUpdateEvent;
- break;
- default:
- case NdbDictionary::Event::TE_ALL:
- abort();
- }
-
- if ((int)pk < records) {
- recEvent[pk].pk = pk;
- recEvent[pk].count++;
- }
-
- for (i = 1; i < noEventColumnName; i++) {
- if (recAttr[i]->isNULL() >= 0) { // we have a value
- g_info << " post[" << i << "]=";
- if (recAttr[i]->isNULL() == 0) // we have a non-null value
- g_info << recAttr[i]->u_32_value();
- else // we have a null value
- g_info << "NULL";
- }
- if (recAttrPre[i]->isNULL() >= 0) { // we have a value
- g_info << " pre[" << i << "]=";
- if (recAttrPre[i]->isNULL() == 0) // we have a non-null value
- g_info << recAttrPre[i]->u_32_value();
- else // we have a null value
- g_info << "NULL";
- }
- }
- g_info << endl;
- }
- } else
- ;//printf("timed out\n");
- }
-
- g_info << "dropping event operation" << endl;
-
- int res = pNdb->dropEventOperation(pOp);
- if (res != 0) {
- g_err << "operation execution failed\n";
- return NDBT_FAILED;
- }
-
- g_info << " ok" << endl;
-
- if (stats.n_inserts > 0) {
- stats.n_consecutive++;
- }
- if (stats.n_deletes > 0) {
- stats.n_consecutive++;
- }
- if (stats.n_updates > 0) {
- stats.n_consecutive++;
- }
- for (i = 0; i < (Uint32)records/3; i++) {
- if (recInsertEvent[i].pk != i) {
- stats.n_consecutive ++;
- ndbout << "missing insert pk " << i << endl;
- } else if (recInsertEvent[i].count > 1) {
- ndbout << "duplicates insert pk " << i
- << " count " << recInsertEvent[i].count << endl;
- stats.n_duplicates += recInsertEvent[i].count-1;
- }
- if (recUpdateEvent[i].pk != i) {
- stats.n_consecutive ++;
- ndbout << "missing update pk " << i << endl;
- } else if (recUpdateEvent[i].count > 1) {
- ndbout << "duplicates update pk " << i
- << " count " << recUpdateEvent[i].count << endl;
- stats.n_duplicates += recUpdateEvent[i].count-1;
- }
- if (recDeleteEvent[i].pk != i) {
- stats.n_consecutive ++;
- ndbout << "missing delete pk " << i << endl;
- } else if (recDeleteEvent[i].count > 1) {
- ndbout << "duplicates delete pk " << i
- << " count " << recDeleteEvent[i].count << endl;
- stats.n_duplicates += recDeleteEvent[i].count-1;
- }
- }
-
- return NDBT_OK;
-}
-
-int runCreateShadowTable(NDBT_Context* ctx, NDBT_Step* step)
-{
- const NdbDictionary::Table *table= ctx->getTab();
- char buf[1024];
- sprintf(buf, "%s_SHADOW", table->getName());
-
- GETNDB(step)->getDictionary()->dropTable(buf);
- if (GETNDB(step)->getDictionary()->getTable(buf))
- {
- g_err << "unsucessful drop of " << buf << endl;
- return NDBT_FAILED;
- }
-
- NdbDictionary::Table table_shadow(*table);
- table_shadow.setName(buf);
- // TODO should be removed
- // This should work wo/ next line
- //table_shadow.setNodeGroupIds(0, 0);
- GETNDB(step)->getDictionary()->createTable(table_shadow);
- if (GETNDB(step)->getDictionary()->getTable(buf))
- return NDBT_OK;
-
- g_err << "unsucessful create of " << buf << endl;
- return NDBT_FAILED;
-}
-
-int runDropShadowTable(NDBT_Context* ctx, NDBT_Step* step)
-{
- const NdbDictionary::Table *table= ctx->getTab();
- char buf[1024];
- sprintf(buf, "%s_SHADOW", table->getName());
-
- GETNDB(step)->getDictionary()->dropTable(buf);
- return NDBT_OK;
-}
-
-int runCreateDropEventOperation(NDBT_Context* ctx, NDBT_Step* step)
-{
- int loops = ctx->getNumLoops();
- //int records = ctx->getNumRecords();
- HugoTransactions hugoTrans(*ctx->getTab());
- EventOperationStats stats;
-
- //Ndb *pNdb=GETNDB(step);
- const NdbDictionary::Table& tab= *ctx->getTab();
- //NdbEventOperation *pOp;
- char eventName[1024];
- sprintf(eventName,"%s_EVENT",tab.getName());
- //int noEventColumnName = tab.getNoOfColumns();
-
- for (int i= 0; i < loops; i++)
- {
-#if 1
- if (eventOperation(GETNDB(step), tab, (void*)&stats, 0) != 0){
- return NDBT_FAILED;
- }
-#else
- g_info << "create EventOperation\n";
- pOp = pNdb->createEventOperation(eventName);
- if ( pOp == NULL ) {
- g_err << "Event operation creation failed\n";
- return NDBT_FAILED;
- }
-
- g_info << "dropping event operation" << endl;
- int res = pNdb->dropEventOperation(pOp);
- if (res != 0) {
- g_err << "operation execution failed\n";
- return NDBT_FAILED;
- }
-#endif
- }
-
- return NDBT_OK;
-}
-
-int theThreadIdCounter = 0;
-
-int runEventOperation(NDBT_Context* ctx, NDBT_Step* step)
-{
- int tId = theThreadIdCounter++;
- //int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- HugoTransactions hugoTrans(*ctx->getTab());
-
- EventOperationStats stats;
-
- g_info << "***** start Id " << tId << endl;
-
- // sleep(tId);
-
- if (eventOperation(GETNDB(step), *ctx->getTab(), (void*)&stats, 3*records) != 0){
- return NDBT_FAILED;
- }
-
- int ret;
- if (stats.n_inserts == records &&
- stats.n_deletes == records &&
- stats.n_updates == records &&
- stats.n_consecutive == 3 &&
- stats.n_duplicates == 0)
- ret = NDBT_OK;
- else
- ret = NDBT_FAILED;
-
- if (ret == NDBT_FAILED) {
- g_info << "***** end Id " << tId << endl;
- ndbout_c("n_inserts = %d (%d)", stats.n_inserts, records);
- ndbout_c("n_deletes = %d (%d)", stats.n_deletes, records);
- ndbout_c("n_updates = %d (%d)", stats.n_updates, records);
- ndbout_c("n_consecutive = %d (%d)", stats.n_consecutive, 3);
- ndbout_c("n_duplicates = %d (%d)", stats.n_duplicates, 0);
- ndbout_c("n_inconsistent_gcis = %d (%d)", stats.n_inconsistent_gcis, 0);
- }
-
- return ret;
-}
-
-int runEventLoad(NDBT_Context* ctx, NDBT_Step* step)
-{
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- HugoTransactions hugoTrans(*ctx->getTab());
-
- sleep(1);
-#if 0
- sleep(5);
- sleep(theThreadIdCounter);
-#endif
- if (hugoTrans.loadTable(GETNDB(step), records, 1, true, loops) != 0){
- return NDBT_FAILED;
- }
- if (hugoTrans.pkUpdateRecords(GETNDB(step), records, 1, loops) != 0){
- return NDBT_FAILED;
- }
- if (hugoTrans.pkDelRecords(GETNDB(step), records, 1, true, loops) != 0){
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int runEventMixedLoad(NDBT_Context* ctx, NDBT_Step* step)
-{
- int loops = ctx->getNumLoops();
- int records = ctx->getNumRecords();
- HugoTransactions hugoTrans(*ctx->getTab());
-
- if(ctx->getPropertyWait("LastGCI", ~(Uint32)0))
- {
- g_err << "FAIL " << __LINE__ << endl;
- return NDBT_FAILED;
- }
-
- while(loops -- && !ctx->isTestStopped())
- {
- hugoTrans.clearTable(GETNDB(step), 0);
-
- if (hugoTrans.loadTable(GETNDB(step), 3*records, 1, true, 1) != 0){
- g_err << "FAIL " << __LINE__ << endl;
- return NDBT_FAILED;
- }
-
- if (hugoTrans.pkDelRecords(GETNDB(step), 3*records, 1, true, 1) != 0){
- g_err << "FAIL " << __LINE__ << endl;
- return NDBT_FAILED;
- }
- if (hugoTrans.loadTable(GETNDB(step), records, 1, true, 1) != 0){
- g_err << "FAIL " << __LINE__ << endl;
- return NDBT_FAILED;
- }
- if (hugoTrans.pkUpdateRecords(GETNDB(step), records, 1, 1) != 0){
- g_err << "FAIL " << __LINE__ << endl;
- return NDBT_FAILED;
- }
- if (hugoTrans.pkUpdateRecords(GETNDB(step), records, 1, 1) != 0){
- g_err << "FAIL " << __LINE__ << endl;
- return NDBT_FAILED;
- }
- if (hugoTrans.pkUpdateRecords(GETNDB(step), records, 1, 1) != 0){
- g_err << "FAIL " << __LINE__ << endl;
- return NDBT_FAILED;
- }
-
- ctx->setProperty("LastGCI", hugoTrans.m_latest_gci);
- if(ctx->getPropertyWait("LastGCI", ~(Uint32)0))
- {
- g_err << "FAIL " << __LINE__ << endl;
- return NDBT_FAILED;
- }
- }
- ctx->stopTest();
- return NDBT_OK;
-}
-
-int runDropEvent(NDBT_Context* ctx, NDBT_Step* step)
-{
- return NDBT_OK;
-}
-
-int runVerify(NDBT_Context* ctx, NDBT_Step* step)
-{
- const NdbDictionary::Table * table= ctx->getTab();
- char buf[1024];
-
- sprintf(buf, "%s_SHADOW", table->getName());
-
- HugoTransactions hugoTrans(*table);
- if (hugoTrans.compare(GETNDB(step), buf, 0))
- {
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
-}
-
-int runEventApplier(NDBT_Context* ctx, NDBT_Step* step)
-{
- DBUG_ENTER("runEventApplier");
-
- int result = NDBT_OK;
- const NdbDictionary::Table * table= ctx->getTab();
- HugoTransactions hugoTrans(* table);
-
- char shadow[1024], buf[1024];
- sprintf(shadow, "%s_SHADOW", table->getName());
- const NdbDictionary::Table * table_shadow;
- if ((table_shadow = GETNDB(step)->getDictionary()->getTable(shadow)) == 0)
- {
- g_err << "Unable to get table " << shadow << endl;
- DBUG_RETURN(NDBT_FAILED);
- }
-
- sprintf(buf, "%s_EVENT", table->getName());
- NdbEventOperation *pOp, *pCreate = 0;
- pCreate = pOp = GETNDB(step)->createEventOperation(buf);
- if ( pOp == NULL ) {
- g_err << "Event operation creation failed on %s" << buf << endl;
- DBUG_RETURN(NDBT_FAILED);
- }
- bool merge_events = ctx->getProperty("MergeEvents");
- pOp->mergeEvents(merge_events);
-
- int i;
- int n_columns= table->getNoOfColumns();
- NdbRecAttr* recAttr[1024];
- NdbRecAttr* recAttrPre[1024];
- for (i = 0; i < n_columns; i++) {
- recAttr[i] = pOp->getValue(table->getColumn(i)->getName());
- recAttrPre[i] = pOp->getPreValue(table->getColumn(i)->getName());
- }
-
- if (pOp->execute()) { // This starts changes to "start flowing"
- g_err << "execute operation execution failed: \n";
- g_err << pOp->getNdbError().code << " "
- << pOp->getNdbError().message << endl;
- result = NDBT_FAILED;
- goto end;
- }
-
- ctx->setProperty("LastGCI", ~(Uint32)0);
- ctx->broadcast();
-
- while(!ctx->isTestStopped())
- {
- int count= 0;
- Uint32 stop_gci= ~0;
- Uint64 curr_gci = 0;
- Ndb* ndb= GETNDB(step);
-
- while(!ctx->isTestStopped() && curr_gci <= stop_gci)
- {
- ndb->pollEvents(100, &curr_gci);
- while ((pOp= ndb->nextEvent()) != 0)
- {
- assert(pOp == pCreate);
-
- if (pOp->getEventType() >=
- NdbDictionary::Event::TE_FIRST_NON_DATA_EVENT)
- continue;
-
- int noRetries= 0;
- do
- {
- NdbTransaction *trans= GETNDB(step)->startTransaction();
- if (trans == 0)
- {
- g_err << "startTransaction failed "
- << GETNDB(step)->getNdbError().code << " "
- << GETNDB(step)->getNdbError().message << endl;
- result = NDBT_FAILED;
- goto end;
-
- }
-
- NdbOperation *op= trans->getNdbOperation(table_shadow);
- if (op == 0)
- {
- g_err << "getNdbOperation failed "
- << trans->getNdbError().code << " "
- << trans->getNdbError().message << endl;
- result = NDBT_FAILED;
- goto end;
-
- }
-
- switch (pOp->getEventType()) {
- case NdbDictionary::Event::TE_INSERT:
- if (op->writeTuple())
- {
- g_err << "insertTuple "
- << op->getNdbError().code << " "
- << op->getNdbError().message << endl;
- result = NDBT_FAILED;
- goto end;
-
- }
- break;
- case NdbDictionary::Event::TE_DELETE:
- if (op->deleteTuple())
- {
- g_err << "deleteTuple "
- << op->getNdbError().code << " "
- << op->getNdbError().message << endl;
- result = NDBT_FAILED;
- goto end;
-
- }
- break;
- case NdbDictionary::Event::TE_UPDATE:
- if (op->writeTuple())
- {
- g_err << "updateTuple "
- << op->getNdbError().code << " "
- << op->getNdbError().message << endl;
- result = NDBT_FAILED;
- goto end;
-
- }
- break;
- default:
- abort();
- }
-
- for (i= 0; i < n_columns; i++)
- {
- if (recAttr[i]->isNULL())
- {
- if (table->getColumn(i)->getPrimaryKey())
- {
- g_err << "internal error: primary key isNull()="
- << recAttr[i]->isNULL() << endl;
- result = NDBT_FAILED;
- goto end;
-
- }
- switch (pOp->getEventType()) {
- case NdbDictionary::Event::TE_INSERT:
- if (recAttr[i]->isNULL() < 0)
- {
- g_err << "internal error: missing value for insert\n";
- result = NDBT_FAILED;
- goto end;
-
- }
- break;
- case NdbDictionary::Event::TE_DELETE:
- break;
- case NdbDictionary::Event::TE_UPDATE:
- break;
- default:
- abort();
- }
- }
- if (table->getColumn(i)->getPrimaryKey() &&
- op->equal(i,recAttr[i]->aRef()))
- {
- g_err << "equal " << i << " "
- << op->getNdbError().code << " "
- << op->getNdbError().message << endl;
- result = NDBT_FAILED;
- goto end;
-
- }
- }
-
- switch (pOp->getEventType()) {
- case NdbDictionary::Event::TE_INSERT:
- for (i= 0; i < n_columns; i++)
- {
- if (!table->getColumn(i)->getPrimaryKey() &&
- op->setValue(i,recAttr[i]->isNULL() ? 0:recAttr[i]->aRef()))
- {
- g_err << "setValue(insert) " << i << " "
- << op->getNdbError().code << " "
- << op->getNdbError().message << endl;
- result = NDBT_FAILED;
- goto end;
-
- }
- }
- break;
- case NdbDictionary::Event::TE_DELETE:
- break;
- case NdbDictionary::Event::TE_UPDATE:
- for (i= 0; i < n_columns; i++)
- {
- if (!table->getColumn(i)->getPrimaryKey() &&
- recAttr[i]->isNULL() >= 0 &&
- op->setValue(i,recAttr[i]->isNULL() ? 0:recAttr[i]->aRef()))
- {
- g_err << "setValue(update) " << i << " "
- << op->getNdbError().code << " "
- << op->getNdbError().message << endl;
- result = NDBT_FAILED;
- goto end;
-
- }
- }
- break;
- default:
- case NdbDictionary::Event::TE_ALL:
- abort();
- }
- if (trans->execute(Commit) == 0)
- {
- trans->close();
- count++;
- // everything ok
- break;
- }
-
- if (trans->getNdbError().status == NdbError::PermanentError)
- {
- g_err << "Ignoring execute failed "
- << trans->getNdbError().code << " "
- << trans->getNdbError().message << endl;
-
- trans->close();
- count++;
- break;
- }
- else if (noRetries++ == 10)
- {
- g_err << "execute failed "
- << trans->getNdbError().code << " "
- << trans->getNdbError().message << endl;
- trans->close();
- result = NDBT_FAILED;
- goto end;
-
- }
- trans->close();
- NdbSleep_MilliSleep(100); // sleep before retying
- } while(1);
- }
- stop_gci = ctx->getProperty("LastGCI", ~(Uint32)0);
- }
-
- ndbout_c("Applied gci: %d, %d events", stop_gci, count);
- if (hugoTrans.compare(GETNDB(step), shadow, 0))
- {
- g_err << "compare failed" << endl;
- result = NDBT_FAILED;
- goto end;
- }
- ctx->setProperty("LastGCI", ~(Uint32)0);
- ctx->broadcast();
- }
-
-end:
- if(pCreate)
- {
- if (GETNDB(step)->dropEventOperation(pCreate)) {
- g_err << "dropEventOperation execution failed "
- << GETNDB(step)->getNdbError().code << " "
- << GETNDB(step)->getNdbError().message << endl;
- result = NDBT_FAILED;
- }
- }
- ctx->stopTest();
- DBUG_RETURN(result);
-}
-
-int runEventListenerUntilStopped(NDBT_Context* ctx, NDBT_Step* step)
-{
-
- int result = NDBT_OK;
- const NdbDictionary::Table * table= ctx->getTab();
- HugoTransactions hugoTrans(* table);
- Ndb* ndb= GETNDB(step);
-
- char buf[1024];
- sprintf(buf, "%s_EVENT", table->getName());
- NdbEventOperation *pOp, *pCreate = 0;
- pCreate = pOp = ndb->createEventOperation(buf);
- if ( pOp == NULL ) {
- g_err << "Event operation creation failed on %s" << buf << endl;
- return NDBT_FAILED;
- }
-
- int i;
- int n_columns= table->getNoOfColumns();
- NdbRecAttr* recAttr[1024];
- NdbRecAttr* recAttrPre[1024];
- for (i = 0; i < n_columns; i++) {
- recAttr[i] = pOp->getValue(table->getColumn(i)->getName());
- recAttrPre[i] = pOp->getPreValue(table->getColumn(i)->getName());
- }
-
- if (pOp->execute())
- { // This starts changes to "start flowing"
- g_err << "execute operation execution failed: \n";
- g_err << pOp->getNdbError().code << " "
- << pOp->getNdbError().message << endl;
- result = NDBT_FAILED;
- goto end;
- }
-
- while(!ctx->isTestStopped())
- {
- Uint64 curr_gci = 0;
- while(!ctx->isTestStopped())
- {
- ndb->pollEvents(100, &curr_gci);
- while ((pOp= ndb->nextEvent()) != 0)
- {
- assert(pOp == pCreate);
- }
- }
- }
-
-end:
- if(pCreate)
- {
- if (ndb->dropEventOperation(pCreate)) {
- g_err << "dropEventOperation execution failed "
- << ndb->getNdbError().code << " "
- << ndb->getNdbError().message << endl;
- result = NDBT_FAILED;
- }
- }
- return result;
-}
-
-int runRestarter(NDBT_Context* ctx, NDBT_Step* step){
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- NdbRestarter restarter;
- int i = 0;
- int lastId = 0;
-
- if (restarter.getNumDbNodes() < 2){
- ctx->stopTest();
- return NDBT_OK;
- }
-
- if(restarter.waitClusterStarted(60) != 0){
- g_err << "Cluster failed to start" << endl;
- return NDBT_FAILED;
- }
-
- while(result != NDBT_FAILED && !ctx->isTestStopped()){
-
- int id = lastId % restarter.getNumDbNodes();
- int nodeId = restarter.getDbNodeId(id);
- ndbout << "Restart node " << nodeId << endl;
- if(restarter.restartOneDbNode(nodeId, false, false, true) != 0){
- g_err << "Failed to restartNextDbNode" << endl;
- result = NDBT_FAILED;
- break;
- }
-
- if(restarter.waitClusterStarted(60) != 0){
- g_err << "Cluster failed to start" << endl;
- result = NDBT_FAILED;
- break;
- }
-
- lastId++;
- i++;
- }
-
- return result;
-}
-
-int runRestarterLoop(NDBT_Context* ctx, NDBT_Step* step)
-{
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
- NdbRestarter restarter;
- int i = 0;
- int lastId = 0;
-
- if (restarter.getNumDbNodes() < 2){
- ctx->stopTest();
- return NDBT_OK;
- }
-
- if(restarter.waitClusterStarted(60) != 0){
- g_err << "Cluster failed to start" << endl;
- return NDBT_FAILED;
- }
-
- while(result != NDBT_FAILED
- && !ctx->isTestStopped()
- && i < loops)
- {
- int id = lastId % restarter.getNumDbNodes();
- int nodeId = restarter.getDbNodeId(id);
- ndbout << "Restart node " << nodeId << endl;
- if(restarter.restartOneDbNode(nodeId, false, false, true) != 0){
- g_err << "Failed to restartNextDbNode" << endl;
- result = NDBT_FAILED;
- break;
- }
-
- if(restarter.waitClusterStarted(60) != 0){
- g_err << "Cluster failed to start" << endl;
- result = NDBT_FAILED;
- break;
- }
-
- lastId++;
- i++;
- }
-
- ctx->stopTest();
- return result;
-}
-
-Vector<const NdbDictionary::Table*> pTabs;
-Vector<const NdbDictionary::Table*> pShadowTabs;
-
-static int getAllTables(NDBT_Context* ctx, NDBT_Step* step)
-{
- DBUG_ENTER("getAllTables");
- Ndb * ndb= GETNDB(step);
- NdbDictionary::Dictionary * dict = ndb->getDictionary();
- pTabs.clear();
-
- for (int i= 0; i < ctx->getNumTables(); i++)
- {
- const NdbDictionary::Table *pTab= dict->getTable(ctx->getTableName(i));
- if (pTab == 0)
- {
- ndbout << "Failed to get table" << endl;
- ndbout << dict->getNdbError() << endl;
- DBUG_RETURN(NDBT_FAILED);
- }
- pTabs.push_back(pTab);
- ndbout << " " << ctx->getTableName(i);
- }
- pTabs.push_back(NULL);
- ndbout << endl;
-
- DBUG_RETURN(NDBT_OK);
-}
-
-static int createAllEvents(NDBT_Context* ctx, NDBT_Step* step)
-{
- DBUG_ENTER("createAllEvents");
- Ndb * ndb= GETNDB(step);
- for (int i= 0; pTabs[i]; i++)
- {
- if (createEvent(ndb,*pTabs[i]))
- {
- DBUG_RETURN(NDBT_FAILED);
- }
- }
- DBUG_RETURN(NDBT_OK);
-}
-
-static int dropAllEvents(NDBT_Context* ctx, NDBT_Step* step)
-{
- DBUG_ENTER("dropAllEvents");
- Ndb * ndb= GETNDB(step);
- int i;
-
- for (i= 0; pTabs[i]; i++)
- {
- if (dropEvent(ndb,*pTabs[i]))
- {
- DBUG_RETURN(NDBT_FAILED);
- }
- }
- DBUG_RETURN(NDBT_OK);
-}
-
-static int createAllShadows(NDBT_Context* ctx, NDBT_Step* step)
-{
- DBUG_ENTER("createAllShadows");
- Ndb * ndb= GETNDB(step);
- NdbDictionary::Dictionary * dict = ndb->getDictionary();
- // create a "shadow" table for each table
- for (int i= 0; pTabs[i]; i++)
- {
- char buf[1024];
- sprintf(buf, "%s_SHADOW", pTabs[i]->getName());
-
- dict->dropTable(buf);
- if (dict->getTable(buf))
- {
- DBUG_RETURN(NDBT_FAILED);
- }
-
- NdbDictionary::Table table_shadow(*pTabs[i]);
- table_shadow.setName(buf);
- if (dict->createTable(table_shadow))
- {
- g_err << "createTable(" << buf << ") "
- << dict->getNdbError().code << " "
- << dict->getNdbError().message << endl;
- DBUG_RETURN(NDBT_FAILED);
- }
- pShadowTabs.push_back(dict->getTable(buf));
- if (!pShadowTabs[i])
- {
- g_err << "getTable(" << buf << ") "
- << dict->getNdbError().code << " "
- << dict->getNdbError().message << endl;
- DBUG_RETURN(NDBT_FAILED);
- }
- }
- DBUG_RETURN(NDBT_OK);
-}
-
-static int dropAllShadows(NDBT_Context* ctx, NDBT_Step* step)
-{
- DBUG_ENTER("dropAllShadows");
- Ndb * ndb= GETNDB(step);
- NdbDictionary::Dictionary * dict = ndb->getDictionary();
-
- for (int i= 0; pTabs[i]; i++)
- {
- char buf[1024];
- sprintf(buf, "%s_SHADOW", pTabs[i]->getName());
- if (dict->dropTable(buf))
- {
- DBUG_RETURN(NDBT_FAILED);
- }
- }
- DBUG_RETURN(NDBT_OK);
-}
-
-static int start_transaction(Ndb *ndb, Vector<HugoOperations*> &ops)
-{
- if (ops[0]->startTransaction(ndb) != NDBT_OK)
- return -1;
- NdbTransaction * t= ops[0]->getTransaction();
- for (int i= ops.size()-1; i > 0; i--)
- {
- ops[i]->setTransaction(t,true);
- }
- return 0;
-}
-
-static int close_transaction(Ndb *ndb, Vector<HugoOperations*> &ops)
-{
- if (ops[0]->closeTransaction(ndb) != NDBT_OK)
- return -1;
- for (int i= ops.size()-1; i > 0; i--)
- {
- ops[i]->setTransaction(NULL,true);
- }
- return 0;
-}
-
-static int execute_commit(Ndb *ndb, Vector<HugoOperations*> &ops)
-{
- if (ops[0]->execute_Commit(ndb) != NDBT_OK)
- return -1;
- return 0;
-}
-
-static int copy_events(Ndb *ndb)
-{
- DBUG_ENTER("copy_events");
- int r= 0;
- NdbDictionary::Dictionary * dict = ndb->getDictionary();
- int n_inserts= 0;
- int n_updates= 0;
- int n_deletes= 0;
- while (1)
- {
- int res= ndb->pollEvents(1000); // wait for event or 1000 ms
- DBUG_PRINT("info", ("pollEvents res=%d", res));
- if (res <= 0)
- {
- break;
- }
- NdbEventOperation *pOp;
- while ((pOp= ndb->nextEvent()))
- {
- char buf[1024];
- sprintf(buf, "%s_SHADOW", pOp->getEvent()->getTable()->getName());
- const NdbDictionary::Table *table= dict->getTable(buf);
-
- if (table == 0)
- {
- g_err << "unable to find table " << buf << endl;
- DBUG_RETURN(-1);
- }
-
- if (pOp->isOverrun())
- {
- g_err << "buffer overrun\n";
- DBUG_RETURN(-1);
- }
- r++;
-
- if (!pOp->isConsistent()) {
- g_err << "A node failure has occured and events might be missing\n";
- DBUG_RETURN(-1);
- }
-
- int noRetries= 0;
- do
- {
- NdbTransaction *trans= ndb->startTransaction();
- if (trans == 0)
- {
- g_err << "startTransaction failed "
- << ndb->getNdbError().code << " "
- << ndb->getNdbError().message << endl;
- DBUG_RETURN(-1);
- }
-
- NdbOperation *op= trans->getNdbOperation(table);
- if (op == 0)
- {
- g_err << "getNdbOperation failed "
- << trans->getNdbError().code << " "
- << trans->getNdbError().message << endl;
- DBUG_RETURN(-1);
- }
-
- switch (pOp->getEventType()) {
- case NdbDictionary::Event::TE_INSERT:
- if (op->insertTuple())
- {
- g_err << "insertTuple "
- << op->getNdbError().code << " "
- << op->getNdbError().message << endl;
- DBUG_RETURN(-1);
- }
- if (noRetries == 0)
- {
- n_inserts++;
- }
- break;
- case NdbDictionary::Event::TE_DELETE:
- if (op->deleteTuple())
- {
- g_err << "deleteTuple "
- << op->getNdbError().code << " "
- << op->getNdbError().message << endl;
- DBUG_RETURN(-1);
- }
- if (noRetries == 0)
- {
- n_deletes++;
- }
- break;
- case NdbDictionary::Event::TE_UPDATE:
- if (op->updateTuple())
- {
- g_err << "updateTuple "
- << op->getNdbError().code << " "
- << op->getNdbError().message << endl;
- DBUG_RETURN(-1);
- }
- if (noRetries == 0)
- {
- n_updates++;
- }
- break;
- default:
- abort();
- }
-
- {
- for (const NdbRecAttr *pk= pOp->getFirstPkAttr();
- pk;
- pk= pk->next())
- {
- if (pk->isNULL())
- {
- g_err << "internal error: primary key isNull()="
- << pk->isNULL() << endl;
- DBUG_RETURN(NDBT_FAILED);
- }
- if (op->equal(pk->getColumn()->getColumnNo(),pk->aRef()))
- {
- g_err << "equal " << pk->getColumn()->getColumnNo() << " "
- << op->getNdbError().code << " "
- << op->getNdbError().message << endl;
- DBUG_RETURN(NDBT_FAILED);
- }
- }
- }
-
- switch (pOp->getEventType()) {
- case NdbDictionary::Event::TE_INSERT:
- {
- for (const NdbRecAttr *data= pOp->getFirstDataAttr();
- data;
- data= data->next())
- {
- if (data->isNULL() < 0 ||
- op->setValue(data->getColumn()->getColumnNo(),
- data->isNULL() ? 0:data->aRef()))
- {
- g_err << "setValue(insert) " << data->getColumn()->getColumnNo()
- << " " << op->getNdbError().code
- << " " << op->getNdbError().message << endl;
- DBUG_RETURN(-1);
- }
- }
- break;
- }
- case NdbDictionary::Event::TE_DELETE:
- break;
- case NdbDictionary::Event::TE_UPDATE:
- {
- for (const NdbRecAttr *data= pOp->getFirstDataAttr();
- data;
- data= data->next())
- {
- if (data->isNULL() >= 0 &&
- op->setValue(data->getColumn()->getColumnNo(),
- data->isNULL() ? 0:data->aRef()))
- {
- g_err << "setValue(update) " << data->getColumn()->getColumnNo()
- << " " << op->getNdbError().code
- << " " << op->getNdbError().message << endl;
- DBUG_RETURN(NDBT_FAILED);
- }
- }
- break;
- }
- default:
- case NdbDictionary::Event::TE_ALL:
- abort();
- }
- if (trans->execute(Commit) == 0)
- {
- trans->close();
- // everything ok
- break;
- }
- if (noRetries++ == 10 ||
- trans->getNdbError().status != NdbError::TemporaryError)
- {
- g_err << "execute " << r << " failed "
- << trans->getNdbError().code << " "
- << trans->getNdbError().message << endl;
- trans->close();
- DBUG_RETURN(-1);
- }
- trans->close();
- NdbSleep_MilliSleep(100); // sleep before retying
- } while(1);
- } // for
- } // while(1)
- g_info << "n_updates: " << n_updates << " "
- << "n_inserts: " << n_inserts << " "
- << "n_deletes: " << n_deletes << endl;
- DBUG_RETURN(r);
-}
-
-static int verify_copy(Ndb *ndb,
- Vector<const NdbDictionary::Table *> &tabs1,
- Vector<const NdbDictionary::Table *> &tabs2)
-{
- for (unsigned i= 0; i < tabs1.size(); i++)
- if (tabs1[i])
- {
- HugoTransactions hugoTrans(*tabs1[i]);
- if (hugoTrans.compare(ndb, tabs2[i]->getName(), 0))
- return -1;
- }
- return 0;
-}
-
-static int createEventOperations(Ndb * ndb)
-{
- DBUG_ENTER("createEventOperations");
- int i;
-
- // creat all event ops
- for (i= 0; pTabs[i]; i++)
- {
- char buf[1024];
- sprintf(buf, "%s_EVENT", pTabs[i]->getName());
- NdbEventOperation *pOp= ndb->createEventOperation(buf);
- if ( pOp == NULL )
- {
- DBUG_RETURN(NDBT_FAILED);
- }
-
- int n_columns= pTabs[i]->getNoOfColumns();
- for (int j = 0; j < n_columns; j++)
- {
- pOp->getValue(pTabs[i]->getColumn(j)->getName());
- pOp->getPreValue(pTabs[i]->getColumn(j)->getName());
- }
-
- if ( pOp->execute() )
- {
- DBUG_RETURN(NDBT_FAILED);
- }
- }
-
- DBUG_RETURN(NDBT_OK);
-}
-
-static int createAllEventOperations(NDBT_Context* ctx, NDBT_Step* step)
-{
- DBUG_ENTER("createAllEventOperations");
- Ndb * ndb= GETNDB(step);
- int r= createEventOperations(ndb);
- if (r != NDBT_OK)
- {
- DBUG_RETURN(NDBT_FAILED);
- }
- DBUG_RETURN(NDBT_OK);
-}
-
-static int dropEventOperations(Ndb * ndb)
-{
- DBUG_ENTER("dropEventOperations");
-
- NdbEventOperation *pOp;
- while ( (pOp= ndb->getEventOperation()) )
- {
- if (ndb->dropEventOperation(pOp))
- {
- DBUG_RETURN(NDBT_FAILED);
- }
- }
-
- DBUG_RETURN(NDBT_OK);
-}
-
-static int dropAllEventOperations(NDBT_Context* ctx, NDBT_Step* step)
-{
- DBUG_ENTER("dropAllEventOperations");
- Ndb * ndb= GETNDB(step);
- int r= dropEventOperations(ndb);
- if (r != NDBT_OK)
- {
- DBUG_RETURN(NDBT_FAILED);
- }
- DBUG_RETURN(NDBT_OK);
-}
-
-static int runMulti(NDBT_Context* ctx, NDBT_Step* step)
-{
- DBUG_ENTER("runMulti");
-
- Ndb * ndb= GETNDB(step);
-
- int no_error= 1;
- int i;
-
- if (createEventOperations(ndb))
- {
- DBUG_RETURN(NDBT_FAILED);
- }
-
- // create a hugo operation per table
- Vector<HugoOperations *> hugo_ops;
- for (i= 0; no_error && pTabs[i]; i++)
- {
- hugo_ops.push_back(new HugoOperations(*pTabs[i]));
- }
-
- int n_records= 3;
- // insert n_records records per table
- do {
- if (start_transaction(ndb, hugo_ops))
- {
- no_error= 0;
- DBUG_RETURN(NDBT_FAILED);
- }
- for (i= 0; no_error && pTabs[i]; i++)
- {
- hugo_ops[i]->pkInsertRecord(ndb, 0, n_records);
- }
- if (execute_commit(ndb, hugo_ops))
- {
- no_error= 0;
- DBUG_RETURN(NDBT_FAILED);
- }
- if(close_transaction(ndb, hugo_ops))
- {
- no_error= 0;
- DBUG_RETURN(NDBT_FAILED);
- }
- } while(0);
-
- // copy events and verify
- do {
- if (copy_events(ndb) < 0)
- {
- no_error= 0;
- DBUG_RETURN(NDBT_FAILED);
- }
- if (verify_copy(ndb, pTabs, pShadowTabs))
- {
- no_error= 0;
- DBUG_RETURN(NDBT_FAILED);
- }
- } while (0);
-
- // update n_records-1 records in first table
- do {
- if (start_transaction(ndb, hugo_ops))
- {
- no_error= 0;
- DBUG_RETURN(NDBT_FAILED);
- }
-
- hugo_ops[0]->pkUpdateRecord(ndb, n_records-1);
-
- if (execute_commit(ndb, hugo_ops))
- {
- no_error= 0;
- DBUG_RETURN(NDBT_FAILED);
- }
- if(close_transaction(ndb, hugo_ops))
- {
- no_error= 0;
- DBUG_RETURN(NDBT_FAILED);
- }
- } while(0);
-
- // copy events and verify
- do {
- if (copy_events(ndb) < 0)
- {
- no_error= 0;
- DBUG_RETURN(NDBT_FAILED);
- }
- if (verify_copy(ndb, pTabs, pShadowTabs))
- {
- no_error= 0;
- DBUG_RETURN(NDBT_FAILED);
- }
- } while (0);
-
- if (dropEventOperations(ndb))
- {
- DBUG_RETURN(NDBT_FAILED);
- }
-
- if (no_error)
- DBUG_RETURN(NDBT_OK);
- DBUG_RETURN(NDBT_FAILED);
-}
-
-static int runMulti_NR(NDBT_Context* ctx, NDBT_Step* step)
-{
- DBUG_ENTER("runMulti");
-
- int records = ctx->getNumRecords();
- int loops = ctx->getNumLoops();
- Ndb * ndb= GETNDB(step);
-
- int i;
-
- if (createEventOperations(ndb))
- {
- DBUG_RETURN(NDBT_FAILED);
- }
-
- for (i= 0; pTabs[i]; i++)
- {
- HugoTransactions hugo(*pTabs[i]);
- if (hugo.loadTable(ndb, records, 1, true, 1))
- {
- DBUG_RETURN(NDBT_FAILED);
- }
- // copy events and verify
- if (copy_events(ndb) < 0)
- {
- DBUG_RETURN(NDBT_FAILED);
- }
- }
-
- if (verify_copy(ndb, pTabs, pShadowTabs))
- {
- DBUG_RETURN(NDBT_FAILED);
- }
-
- {
- NdbRestarts restarts;
- for (int j= 0; j < loops; j++)
- {
- // restart a node
- int timeout = 240;
- if (restarts.executeRestart("RestartRandomNodeAbort", timeout))
- {
- DBUG_RETURN(NDBT_FAILED);
- }
-
- sleep(5);
- // update all tables
- for (i= 0; pTabs[i]; i++)
- {
- HugoTransactions hugo(*pTabs[i]);
- if (hugo.pkUpdateRecords(ndb, records, 1, 1))
- {
- DBUG_RETURN(NDBT_FAILED);
- }
- if (copy_events(ndb) < 0)
- {
- DBUG_RETURN(NDBT_FAILED);
- }
- }
-
- // copy events and verify
- if (verify_copy(ndb, pTabs, pShadowTabs))
- {
- DBUG_RETURN(NDBT_FAILED);
- }
- }
- }
-
- if (dropEventOperations(ndb))
- {
- DBUG_RETURN(NDBT_FAILED);
- }
-
- DBUG_RETURN(NDBT_OK);
-}
-
-static int restartAllNodes()
-{
- NdbRestarter restarter;
- int id = 0;
- do {
- int nodeId = restarter.getDbNodeId(id++);
- ndbout << "Restart node " << nodeId << endl;
- if(restarter.restartOneDbNode(nodeId, false, false, true) != 0){
- g_err << "Failed to restartNextDbNode" << endl;
- break;
- }
- if(restarter.waitClusterStarted(60) != 0){
- g_err << "Cluster failed to start" << endl;
- break;
- }
- id = id % restarter.getNumDbNodes();
- } while (id);
- return id != 0;
-}
-
-static int runCreateDropNR(NDBT_Context* ctx, NDBT_Step* step)
-{
- DBUG_ENTER("runCreateDropNR");
- Ndb * ndb= GETNDB(step);
- int result = NDBT_OK;
- NdbRestarter restarter;
- int loops = ctx->getNumLoops();
-
- if (restarter.getNumDbNodes() < 2)
- {
- ctx->stopTest();
- return NDBT_OK;
- }
- do
- {
- result = NDBT_FAILED;
- const NdbDictionary::Table* pTab = ctx->getTab();
- if (createEvent(ndb, *pTab))
- {
- g_err << "createEvent failed" << endl;
- break;
- }
- NdbEventOperation *pOp= createEventOperation(ndb, *pTab);
- if (pOp == 0)
- {
- g_err << "Failed to createEventOperation" << endl;
- break;
- }
- if (dropEvent(ndb, *pTab))
- {
- g_err << "Failed to dropEvent()" << endl;
- break;
- }
- ndbout << "Restarting with dropped events with subscribers" << endl;
- if (restartAllNodes())
- break;
- if (ndb->getDictionary()->dropTable(pTab->getName()) != 0){
- g_err << "Failed to drop " << pTab->getName() <<" in db" << endl;
- break;
- }
- ndbout << "Restarting with dropped events and dropped "
- << "table with subscribers" << endl;
- if (restartAllNodes())
- break;
- if (ndb->dropEventOperation(pOp))
- {
- g_err << "Failed dropEventOperation" << endl;
- break;
- }
- NdbDictionary::Table tmp(*pTab);
- //tmp.setNodeGroupIds(0, 0);
- if (ndb->getDictionary()->createTable(tmp) != 0){
- g_err << "createTable failed: "
- << ndb->getDictionary()->getNdbError() << endl;
- break;
- }
- result = NDBT_OK;
- } while (--loops);
-
- DBUG_RETURN(result);
-}
-
-static
-int
-runSubscribeUnsubscribe(NDBT_Context* ctx, NDBT_Step* step)
-{
- char buf[1024];
- const NdbDictionary::Table & tab = * ctx->getTab();
- sprintf(buf, "%s_EVENT", tab.getName());
- Ndb* ndb = GETNDB(step);
- int loops = 5 * ctx->getNumLoops();
-
- while (--loops)
- {
- NdbEventOperation *pOp= ndb->createEventOperation(buf);
- if (pOp == 0)
- {
- g_err << "createEventOperation: "
- << ndb->getNdbError().code << " "
- << ndb->getNdbError().message << endl;
- return NDBT_FAILED;
- }
-
- int n_columns= tab.getNoOfColumns();
- for (int j = 0; j < n_columns; j++)
- {
- pOp->getValue(tab.getColumn(j)->getName());
- pOp->getPreValue(tab.getColumn(j)->getName());
- }
- if ( pOp->execute() )
- {
- g_err << "pOp->execute(): "
- << pOp->getNdbError().code << " "
- << pOp->getNdbError().message << endl;
-
- ndb->dropEventOperation(pOp);
-
- return NDBT_FAILED;
- }
-
- if (ndb->dropEventOperation(pOp))
- {
- g_err << "pOp->execute(): "
- << ndb->getNdbError().code << " "
- << ndb->getNdbError().message << endl;
- return NDBT_FAILED;
- }
- }
-
- return NDBT_OK;
-}
-
-int
-runScanUpdateUntilStopped(NDBT_Context* ctx, NDBT_Step* step){
- int records = ctx->getNumRecords();
- int parallelism = ctx->getProperty("Parallelism", (Uint32)0);
- int abort = ctx->getProperty("AbortProb", (Uint32)0);
- HugoTransactions hugoTrans(*ctx->getTab());
- while (ctx->isTestStopped() == false)
- {
- if (hugoTrans.scanUpdateRecords(GETNDB(step), 0, abort,
- parallelism) == NDBT_FAILED){
- return NDBT_FAILED;
- }
- }
- return NDBT_OK;
-}
-
-int
-runInsertDeleteUntilStopped(NDBT_Context* ctx, NDBT_Step* step)
-{
- int result = NDBT_OK;
- int records = ctx->getNumRecords();
- HugoTransactions hugoTrans(*ctx->getTab());
- UtilTransactions utilTrans(*ctx->getTab());
- while (ctx->isTestStopped() == false)
- {
- if (hugoTrans.loadTable(GETNDB(step), records, 1) != 0){
- return NDBT_FAILED;
- }
- if (utilTrans.clearTable(GETNDB(step), records) != 0){
- return NDBT_FAILED;
- }
- }
-
- return NDBT_OK;
-}
-
-int
-runBug31701(NDBT_Context* ctx, NDBT_Step* step)
-{
- int result = NDBT_OK;
-
- NdbRestarter restarter;
-
- if (restarter.getNumDbNodes() < 2){
- ctx->stopTest();
- return NDBT_OK;
- }
- // This should really wait for applier to start...10s is likely enough
- NdbSleep_SecSleep(10);
-
- int nodeId = restarter.getDbNodeId(rand() % restarter.getNumDbNodes());
-
- int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
- if (restarter.dumpStateOneNode(nodeId, val2, 2))
- return NDBT_FAILED;
-
- restarter.insertErrorInNode(nodeId, 13033);
- if (restarter.waitNodesNoStart(&nodeId, 1))
- return NDBT_FAILED;
-
- if (restarter.startNodes(&nodeId, 1))
- return NDBT_FAILED;
-
- if (restarter.waitClusterStarted())
- return NDBT_FAILED;
-
-
- int records = ctx->getNumRecords();
- HugoTransactions hugoTrans(*ctx->getTab());
-
- if(ctx->getPropertyWait("LastGCI", ~(Uint32)0))
- {
- g_err << "FAIL " << __LINE__ << endl;
- return NDBT_FAILED;
- }
-
- hugoTrans.clearTable(GETNDB(step), 0);
-
- if (hugoTrans.loadTable(GETNDB(step), 3*records, 1, true, 1) != 0){
- g_err << "FAIL " << __LINE__ << endl;
- return NDBT_FAILED;
- }
-
- if (hugoTrans.pkDelRecords(GETNDB(step), 3*records, 1, true, 1) != 0){
- g_err << "FAIL " << __LINE__ << endl;
- return NDBT_FAILED;
- }
- if (hugoTrans.loadTable(GETNDB(step), records, 1, true, 1) != 0){
- g_err << "FAIL " << __LINE__ << endl;
- return NDBT_FAILED;
- }
- if (hugoTrans.pkUpdateRecords(GETNDB(step), records, 1, 1) != 0){
- g_err << "FAIL " << __LINE__ << endl;
- return NDBT_FAILED;
- }
- if (hugoTrans.pkUpdateRecords(GETNDB(step), records, 1, 1) != 0){
- g_err << "FAIL " << __LINE__ << endl;
- return NDBT_FAILED;
- }
- if (hugoTrans.pkUpdateRecords(GETNDB(step), records, 1, 1) != 0){
- g_err << "FAIL " << __LINE__ << endl;
- return NDBT_FAILED;
- }
-
- ctx->setProperty("LastGCI", hugoTrans.m_latest_gci);
- if(ctx->getPropertyWait("LastGCI", ~(Uint32)0))
- {
- g_err << "FAIL " << __LINE__ << endl;
- return NDBT_FAILED;
- }
-
- ctx->stopTest();
- return NDBT_OK;
-}
-
-int
-runBug33793(NDBT_Context* ctx, NDBT_Step* step)
-{
- int result = NDBT_OK;
- int loops = ctx->getNumLoops();
-
- NdbRestarter restarter;
-
- if (restarter.getNumDbNodes() < 2){
- ctx->stopTest();
- return NDBT_OK;
- }
- // This should really wait for applier to start...10s is likely enough
- NdbSleep_SecSleep(10);
-
- while (loops-- && ctx->isTestStopped() == false)
- {
- int nodeId = restarter.getDbNodeId(rand() % restarter.getNumDbNodes());
- int nodecount = 0;
- int nodes[255];
- printf("nodeid: %u : victims: ", nodeId);
- for (int i = 0; i<restarter.getNumDbNodes(); i++)
- {
- int id = restarter.getDbNodeId(i);
- if (id == nodeId)
- continue;
-
- if (restarter.getNodeGroup(id) == restarter.getNodeGroup(nodeId))
- {
- nodes[nodecount++] = id;
- printf("%u ", id);
- int val2[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
- if (restarter.dumpStateOneNode(id, val2, 2))
- return NDBT_FAILED;
- }
- }
- printf("\n"); fflush(stdout);
-
- restarter.insertErrorInNode(nodeId, 13034);
- if (restarter.waitNodesNoStart(nodes, nodecount))
- return NDBT_FAILED;
-
- if (restarter.startNodes(nodes, nodecount))
- return NDBT_FAILED;
-
- if (restarter.waitClusterStarted())
- return NDBT_FAILED;
- }
-
- ctx->stopTest();
- return NDBT_OK;
-}
-
-
-
-NDBT_TESTSUITE(test_event);
-TESTCASE("BasicEventOperation",
- "Verify that we can listen to Events"
- "NOTE! No errors are allowed!" )
-{
-#if 0
- TABLE("T1");
- TABLE("T3");
- TABLE("T5");
- TABLE("T6");
- TABLE("T8");
-#endif
- INITIALIZER(runCreateEvent);
- STEP(runEventOperation);
- STEP(runEventLoad);
- FINALIZER(runDropEvent);
-}
-TESTCASE("CreateDropEventOperation",
- "Verify that we can Create and Drop many times"
- "NOTE! No errors are allowed!" ){
- INITIALIZER(runCreateEvent);
- STEP(runCreateDropEventOperation);
- FINALIZER(runDropEvent);
-}
-TESTCASE("ParallellEventOperation",
- "Verify that we can listen to Events in parallell"
- "NOTE! No errors are allowed!" ){
- INITIALIZER(runCreateEvent);
- STEP(runEventOperation);
- STEP(runEventOperation);
- STEP(runEventLoad);
- FINALIZER(runDropEvent);
-}
-TESTCASE("EventOperationApplier",
- "Verify that if we apply the data we get from event "
- "operation is the same as the original table"
- "NOTE! No errors are allowed!" ){
- INITIALIZER(runCreateEvent);
- INITIALIZER(runCreateShadowTable);
- STEP(runEventApplier);
- STEP(runEventMixedLoad);
- FINALIZER(runDropEvent);
- FINALIZER(runVerify);
- FINALIZER(runDropShadowTable);
-}
-TESTCASE("EventOperationApplier_NR",
- "Verify that if we apply the data we get from event "
- "operation is the same as the original table"
- "NOTE! No errors are allowed!" ){
- INITIALIZER(runCreateEvent);
- INITIALIZER(runCreateShadowTable);
- STEP(runEventApplier);
- STEP(runEventMixedLoad);
- STEP(runRestarter);
- FINALIZER(runDropEvent);
- FINALIZER(runVerify);
- FINALIZER(runDropShadowTable);
-}
-TESTCASE("MergeEventOperationApplier",
- "Verify that if we apply the data we get from merged event "
- "operation is the same as the original table"
- "NOTE! No errors are allowed!" ){
- TC_PROPERTY("MergeEvents", 1);
- INITIALIZER(runCreateEvent);
- INITIALIZER(runCreateShadowTable);
- STEP(runEventApplier);
- STEP(runEventMixedLoad);
- FINALIZER(runDropEvent);
- FINALIZER(runVerify);
- FINALIZER(runDropShadowTable);
-}
-TESTCASE("MergeEventOperationApplier_NR",
- "Verify that if we apply the data we get from merged event "
- "operation is the same as the original table"
- "NOTE! No errors are allowed!" ){
- TC_PROPERTY("MergeEvents", 1);
- INITIALIZER(runCreateEvent);
- INITIALIZER(runCreateShadowTable);
- STEP(runEventApplier);
- STEP(runEventMixedLoad);
- STEP(runRestarter);
- FINALIZER(runDropEvent);
- FINALIZER(runVerify);
- FINALIZER(runDropShadowTable);
-}
-TESTCASE("Multi",
- "Verify that we can work with all tables in parallell"
- "NOTE! HugoOperations::startTransaction, pTrans != NULL errors, "
- "are allowed!" ){
- ALL_TABLES();
- INITIALIZER(getAllTables);
- INITIALIZER(createAllEvents);
- INITIALIZER(createAllShadows);
- STEP(runMulti);
- FINALIZER(dropAllShadows);
- FINALIZER(dropAllEvents);
-}
-TESTCASE("Multi_NR",
- "Verify that we can work with all tables in parallell"
- "NOTE! HugoOperations::startTransaction, pTrans != NULL errors, "
- "are allowed!" ){
- ALL_TABLES();
- INITIALIZER(getAllTables);
- INITIALIZER(createAllEvents);
- INITIALIZER(createAllShadows);
- STEP(runMulti_NR);
- FINALIZER(dropAllShadows);
- FINALIZER(dropAllEvents);
-}
-TESTCASE("CreateDropNR",
- "Verify that we can Create and Drop in any order"
- "NOTE! No errors are allowed!" ){
- FINALIZER(runCreateDropNR);
-}
-TESTCASE("SubscribeUnsubscribe",
- "A bunch of threads doing subscribe/unsubscribe in loop"
- "NOTE! No errors are allowed!" ){
- INITIALIZER(runCreateEvent);
- STEPS(runSubscribeUnsubscribe, 16);
- FINALIZER(runDropEvent);
-}
-TESTCASE("Bug27169", ""){
- INITIALIZER(runCreateEvent);
- STEP(runEventListenerUntilStopped);
- STEP(runInsertDeleteUntilStopped);
- STEP(runScanUpdateUntilStopped);
- STEP(runRestarterLoop);
- FINALIZER(runDropEvent);
-}
-TESTCASE("Bug31701", ""){
- INITIALIZER(runCreateEvent);
- INITIALIZER(runCreateShadowTable);
- STEP(runEventApplier);
- STEP(runBug31701);
- FINALIZER(runDropEvent);
- FINALIZER(runDropShadowTable);
-}
-TESTCASE("Bug33793", ""){
- INITIALIZER(runCreateEvent);
- STEP(runEventListenerUntilStopped);
- STEP(runBug33793);
- FINALIZER(runDropEvent);
-}
-NDBT_TESTSUITE_END(test_event);
-
-int main(int argc, const char** argv){
- ndb_init();
- test_event.setCreateAllTables(true);
- return test_event.execute(argc, argv);
-}
-
-template class Vector<HugoOperations *>;
-template class Vector<NdbEventOperation *>;
-template class Vector<NdbRecAttr*>;
-template class Vector<Vector<NdbRecAttr*> >;
diff --git a/storage/ndb/test/ndbapi/test_event_merge.cpp b/storage/ndb/test/ndbapi/test_event_merge.cpp
deleted file mode 100644
index 1df7fba0920..00000000000
--- a/storage/ndb/test/ndbapi/test_event_merge.cpp
+++ /dev/null
@@ -1,2331 +0,0 @@
-/* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-#include <ndb_opts.h>
-#include <NdbApi.hpp>
-#include <NdbTest.hpp>
-#include <my_sys.h>
-#include <ndb_version.h>
-
-// version >= 5.1 required
-
-#if !defined(min) || !defined(max)
-#define min(x, y) ((x) < (y) ? (x) : (y))
-#define max(x, y) ((x) > (y) ? (x) : (y))
-#endif
-
-/*
- * Test composite operations on same PK via events. The merge of event
- * data can happen in 2 places:
- *
- * 1) In TUP at commit, the detached triggers report a single composite
- * operation and its post/pre data
- *
- * 2) In event API version >= 5.1 separate commits within same GCI are
- * optionally merged. This is required to read blob data via NdbBlob.
- *
- * In this test merge is on by default.
- *
- * Option --separate-events disables GCI merge and implies --no-blobs.
- * This is used to test basic events functionality.
- *
- * Option --no-blobs omits blob attributes. This is used to test GCI
- * merge without getting into blob bugs.
- *
- * Option --no-multiops allows 1 operation per commit. This avoids TUP
- * and blob multi-operation bugs.
- *
- * There are other -no-* options, each added to isolate a specific bug.
- *
- * There are 5 ways (ignoring NUL operand) to compose 2 ops:
- *
- * INS o DEL = NUL
- * INS o UPD = INS
- * DEL o INS = UPD
- * UPD o DEL = DEL
- * UPD o UPD = UPD
- *
- * Event merge in NDB API handles idempotent INS o INS and DEL o DEL
- * which are possible on NF (node failure). This test does not handle
- * them when --separate-events is used.
- */
-
-struct Opts {
- my_bool abort_on_error;
- int loglevel;
- uint loop;
- uint maxops;
- uint maxpk;
- my_bool no_blobs;
- my_bool no_implicit_nulls;
- my_bool no_missing_update;
- my_bool no_multiops;
- my_bool no_nulls;
- my_bool one_blob;
- const char* opstring;
- uint seed;
- int maxtab;
- my_bool separate_events;
- uint tweak; // whatever's useful
- my_bool use_table;
-};
-
-static Opts g_opts;
-static const uint g_maxpk = 1000;
-static const uint g_maxtab = 100;
-static const uint g_maxopstringpart = 100;
-static const char* g_opstringpart[g_maxopstringpart];
-static uint g_opstringparts = 0;
-static uint g_loop = 0;
-
-static Ndb_cluster_connection* g_ncc = 0;
-static Ndb* g_ndb = 0;
-static NdbDictionary::Dictionary* g_dic = 0;
-static NdbTransaction* g_con = 0;
-static NdbOperation* g_op = 0;
-static NdbScanOperation* g_scan_op = 0;
-
-static const uint g_charlen = 5;
-static const char* g_charval = "abcdefgh";
-static const char* g_csname = "latin1_swedish_ci";
-
-static uint g_blobinlinesize = 256;
-static uint g_blobpartsize = 2000;
-static uint g_blobstripesize = 2;
-static const uint g_maxblobsize = 100000;
-
-static NdbEventOperation* g_evt_op = 0;
-static NdbBlob* g_bh = 0;
-
-static uint
-urandom()
-{
- uint r = (uint)random();
- return r;
-}
-
-static uint
-urandom(uint m)
-{
- if (m == 0)
- return 0;
- uint r = urandom();
- r = r % m;
- return r;
-}
-
-static bool
-urandom(uint per, uint cent)
-{
- return urandom(cent) < per;
-}
-
-static int& g_loglevel = g_opts.loglevel; // default log level
-
-#define chkdb(x) \
- do { if (x) break; ndbout << "line " << __LINE__ << " FAIL " << #x << endl; errdb(); if (g_opts.abort_on_error) abort(); return -1; } while (0)
-
-#define chkrc(x) \
- do { if (x) break; ndbout << "line " << __LINE__ << " FAIL " << #x << endl; if (g_opts.abort_on_error) abort(); return -1; } while (0)
-
-#define reqrc(x) \
- do { if (x) break; ndbout << "line " << __LINE__ << " ASSERT " << #x << endl; abort(); } while (0)
-
-#define ll0(x) \
- do { if (g_loglevel < 0) break; ndbout << x << endl; } while (0)
-
-#define ll1(x) \
- do { if (g_loglevel < 1) break; ndbout << x << endl; } while (0)
-
-#define ll2(x) \
- do { if (g_loglevel < 2) break; ndbout << x << endl; } while (0)
-
-#define ll3(x) \
- do { if (g_loglevel < 3) break; ndbout << x << endl; } while (0)
-
-static void
-errdb()
-{
- uint any = 0;
- // g_ncc return no error...
- if (g_ndb != 0) {
- const NdbError& e = g_ndb->getNdbError();
- if (e.code != 0)
- ll0(++any << " ndb: error " << e);
- }
- if (g_dic != 0) {
- const NdbError& e = g_dic->getNdbError();
- if (e.code != 0)
- ll0(++any << " dic: error " << e);
- }
- if (g_con != 0) {
- const NdbError& e = g_con->getNdbError();
- if (e.code != 0)
- ll0(++any << " con: error " << e);
- }
- if (g_op != 0) {
- const NdbError& e = g_op->getNdbError();
- if (e.code != 0)
- ll0(++any << " op: error " << e);
- }
- if (g_scan_op != 0) {
- const NdbError& e = g_scan_op->getNdbError();
- if (e.code != 0)
- ll0(++any << " scan_op: error " << e);
- }
- if (g_evt_op != 0) {
- const NdbError& e = g_evt_op->getNdbError();
- if (e.code != 0)
- ll0(++any << " evt_op: error " << e);
- }
- if (g_bh != 0) {
- const NdbError& e = g_bh->getNdbError();
- if (e.code != 0)
- ll0(++any << " bh: error " << e);
- }
- if (! any)
- ll0("unknown db error");
-}
-
-struct Col {
- uint no;
- const char* name;
- NdbDictionary::Column::Type type;
- bool pk;
- bool nullable;
- uint length;
- uint size;
- bool isblob() const {
- return
- type == NdbDictionary::Column::Text ||
- type == NdbDictionary::Column::Blob;
- }
-};
-
-static const Col g_col[] = {
- { 0, "pk1", NdbDictionary::Column::Unsigned, true, false, 1, 4 },
- { 1, "pk2", NdbDictionary::Column::Char, true, false, g_charlen, g_charlen },
- { 2, "seq", NdbDictionary::Column::Unsigned, false, false, 1, 4 },
- { 3, "cc1", NdbDictionary::Column::Char, false, true, g_charlen, g_charlen },
- { 4, "tx1", NdbDictionary::Column::Text, false, true, 0, 0 },
- { 5, "tx2", NdbDictionary::Column::Text, false, true, 0, 0 },
- { 6, "bl1", NdbDictionary::Column::Blob, false, true, 0, 0 } // tinyblob
-};
-
-static const uint g_maxcol = sizeof(g_col)/sizeof(g_col[0]);
-static const uint g_blobcols = 3;
-
-static uint
-ncol()
-{
- uint n = g_maxcol;
- if (g_opts.no_blobs)
- n -= g_blobcols;
- else if (g_opts.one_blob)
- n -= (g_blobcols - 2);
- return n;
-}
-
-static const Col&
-getcol(uint i)
-{
- if (i < ncol())
- return g_col[i];
- assert(false);
- return g_col[0];
-}
-
-static const Col&
-getcol(const char* name)
-{
- uint i;
- for (i = 0; i < ncol(); i++)
- if (strcmp(g_col[i].name, name) == 0)
- break;
- return getcol(i);
-}
-
-struct Tab {
- char tabname[20];
- const Col* col;
- const NdbDictionary::Table* tab;
- char evtname[20];
- const NdbDictionary::Event* evt;
- Tab(uint idx) :
- col(g_col),
- tab(0),
- evt(0)
- {
- sprintf(tabname, "tem%d", idx);
- sprintf(evtname, "tem%dev", idx);
- }
-};
-
-static Tab* g_tablst[g_maxtab];
-
-static uint
-maxtab()
-{
- return g_opts.maxtab;
-}
-
-static Tab&
-tab(uint i)
-{
- assert(i < maxtab() && g_tablst[i] != 0);
- return *g_tablst[i];
-}
-
-static int
-createtable(Tab& t)
-{
- ll2("createtable: " << t.tabname);
- t.tab = 0;
- NdbDictionary::Table tab(t.tabname);
- tab.setLogging(false);
- CHARSET_INFO* cs;
- chkrc((cs = get_charset_by_name(g_csname, MYF(0))) != 0);
- uint i;
- for (i = 0; i < ncol(); i++) {
- const Col& c = t.col[i];
- NdbDictionary::Column col(c.name);
- col.setType(c.type);
- col.setPrimaryKey(c.pk);
- if (! c.pk)
- col.setNullable(true);
- col.setLength(c.length);
- switch (c.type) {
- case NdbDictionary::Column::Unsigned:
- break;
- case NdbDictionary::Column::Char:
- col.setLength(c.length);
- col.setCharset(cs);
- break;
- case NdbDictionary::Column::Text:
- col.setInlineSize(g_blobinlinesize);
- col.setPartSize(g_blobpartsize);
- col.setStripeSize(g_blobstripesize);
- col.setCharset(cs);
- break;
- case NdbDictionary::Column::Blob:
- col.setInlineSize(g_blobinlinesize);
- col.setPartSize(0);
- col.setStripeSize(0);
- break;
- default:
- assert(false);
- break;
- }
- tab.addColumn(col);
- }
- g_dic = g_ndb->getDictionary();
- if (! g_opts.use_table) {
- if (g_dic->getTable(t.tabname) != 0)
- chkdb(g_dic->dropTable(t.tabname) == 0);
- chkdb(g_dic->createTable(tab) == 0);
- }
- chkdb((t.tab = g_dic->getTable(t.tabname)) != 0);
- g_dic = 0;
- if (! g_opts.use_table) {
- // extra row for GCI probe
- chkdb((g_con = g_ndb->startTransaction()) != 0);
- chkdb((g_op = g_con->getNdbOperation(t.tabname)) != 0);
- chkdb(g_op->insertTuple() == 0);
- Uint32 pk1;
- char pk2[g_charlen + 1];
- pk1 = g_maxpk;
- sprintf(pk2, "%-*u", g_charlen, pk1);
- chkdb(g_op->equal("pk1", (char*)&pk1) == 0);
- chkdb(g_op->equal("pk2", (char*)&pk2[0]) == 0);
- chkdb(g_con->execute(Commit) == 0);
- g_ndb->closeTransaction(g_con);
- g_op = 0;
- g_con = 0;
- }
- return 0;
-}
-
-static int
-createtables()
-{
- ll1("createtables");
- for (uint i = 0; i < maxtab(); i++)
- chkrc(createtable(tab(i)) == 0);
- return 0;
-}
-
-static int
-droptable(Tab& t)
-{
- ll2("droptable: " << t.tabname);
- if (! g_opts.use_table) {
- g_dic = g_ndb->getDictionary();
- chkdb(g_dic->dropTable(t.tabname) == 0);
- t.tab = 0;
- g_dic = 0;
- }
- return 0;
-}
-
-static int
-droptables()
-{
- ll1("droptables");
- for (uint i = 0; i < maxtab(); i++)
- chkrc(droptable(tab(i)) == 0);
- return 0;
-}
-
-static int
-createevent(Tab& t)
-{
- ll2("createevent: " << t.evtname);
- t.evt = 0;
- g_dic = g_ndb->getDictionary();
- NdbDictionary::Event evt(t.evtname);
- assert(t.tab != 0);
- evt.setTable(*t.tab);
- evt.addTableEvent(NdbDictionary::Event::TE_ALL);
- uint i;
- for (i = 0; i < ncol(); i++) {
- const Col& c = g_col[i];
- evt.addEventColumn(c.name);
- }
- evt.setReport(NdbDictionary::Event::ER_UPDATED);
- evt.mergeEvents(! g_opts.separate_events);
-#if 0 // XXX random bugs
- if (g_dic->getEvent(t.evtname) != 0)
- chkdb(g_dic->dropEvent(t.evtname) == 0);
-#else
- (void)g_dic->dropEvent(t.evtname);
- chkdb(g_dic->createEvent(evt) == 0);
-#endif
- chkdb((t.evt = g_dic->getEvent(t.evtname)) != 0);
- g_dic = 0;
- return 0;
-}
-
-static int
-createevents()
-{
- ll1("createevents");
- for (uint i = 0; i < maxtab(); i++)
- chkrc(createevent(tab(i)) == 0);
- return 0;
-}
-
-static int
-dropevent(Tab& t, bool force = false)
-{
- ll2("dropevent: " << t.evtname);
- g_dic = g_ndb->getDictionary();
- chkdb(g_dic->dropEvent(t.evtname) == 0 || force);
- t.evt = 0;
- g_dic = 0;
- return 0;
-}
-
-static int
-dropevents(bool force = false)
-{
- ll1("dropevents");
- for (uint i = 0; i < maxtab(); i++) {
- if (force && g_tablst[i] == 0)
- continue;
- chkrc(dropevent(tab(i), force) == 0 || force);
- }
- return 0;
-}
-
-struct Data {
- struct Txt { char* val; uint len; };
- union Ptr { Uint32* u32; char* ch; Txt* txt; void* v; };
- Uint32 pk1;
- char pk2[g_charlen + 1];
- Uint32 seq;
- char cc1[g_charlen + 1];
- Txt tx1;
- Txt tx2;
- Txt bl1;
- Ptr ptr[g_maxcol];
- int ind[g_maxcol]; // -1 = no data, 1 = NULL, 0 = not NULL
- uint noop; // bit: omit in NdbOperation (implicit NULL INS or no UPD)
- uint ppeq; // bit: post/pre data value equal in GCI data[0]/data[1]
- void init() {
- uint i;
- pk1 = 0;
- memset(pk2, 0, sizeof(pk2));
- seq = 0;
- memset(cc1, 0, sizeof(cc1));
- tx1.val = tx2.val = bl1.val = 0;
- tx1.len = tx2.len = bl1.len = 0;
- ptr[0].u32 = &pk1;
- ptr[1].ch = pk2;
- ptr[2].u32 = &seq;
- ptr[3].ch = cc1;
- ptr[4].txt = &tx1;
- ptr[5].txt = &tx2;
- ptr[6].txt = &bl1;
- for (i = 0; i < g_maxcol; i++)
- ind[i] = -1;
- noop = 0;
- ppeq = 0;
- }
- void freemem() {
- delete [] tx1.val;
- delete [] tx2.val;
- delete [] bl1.val;
- tx1.val = tx2.val = bl1.val = 0;
- tx1.len = tx2.len = bl1.len = 0;
- }
-};
-
-static int
-cmpcol(const Col& c, const Data& d1, const Data& d2)
-{
- uint i = c.no;
- if (d1.ind[i] != d2.ind[i])
- return 1;
- if (d1.ind[i] == 0) {
- switch (c.type) {
- case NdbDictionary::Column::Unsigned:
- if (*d1.ptr[i].u32 != *d2.ptr[i].u32)
- return 1;
- break;
- case NdbDictionary::Column::Char:
- if (memcmp(d1.ptr[i].ch, d2.ptr[i].ch, c.size) != 0)
- return 1;
- break;
- case NdbDictionary::Column::Text:
- case NdbDictionary::Column::Blob:
- {
- const Data::Txt& t1 = *d1.ptr[i].txt;
- const Data::Txt& t2 = *d2.ptr[i].txt;
- if (t1.len != t2.len)
- return 1;
- if (memcmp(t1.val, t2.val, t1.len) != 0)
- return 1;
- }
- break;
- default:
- assert(false);
- break;
- }
- }
- return 0;
-}
-
-static NdbOut&
-operator<<(NdbOut& out, const Data& d)
-{
- uint i;
- for (i = 0; i < ncol(); i++) {
- const Col& c = getcol(i);
- out << (i == 0 ? "" : " ") << c.name;
- out << (! (d.noop & (1 << i)) ? "=" : ":");
- if (d.ind[i] == -1)
- continue;
- if (d.ind[i] == 1) {
- out << "NULL";
- continue;
- }
- switch (c.type) {
- case NdbDictionary::Column::Unsigned:
- out << *d.ptr[i].u32;
- break;
- case NdbDictionary::Column::Char:
- {
- char buf[g_charlen + 1];
- memcpy(buf, d.ptr[i].ch, g_charlen);
- uint n = g_charlen;
- while (1) {
- buf[n] = 0;
- if (n == 0 || buf[n - 1] != 0x20)
- break;
- n--;
- }
- out << "'" << buf << "'";
- }
- break;
- case NdbDictionary::Column::Text:
- case NdbDictionary::Column::Blob:
- {
- Data::Txt& txt = *d.ptr[i].txt;
- bool first = true;
- uint j = 0;
- while (j < txt.len) {
- char c[2];
- c[0] = txt.val[j++];
- c[1] = 0;
- uint m = 1;
- while (j < txt.len && txt.val[j] == c[0])
- j++, m++;
- if (! first)
- out << "+";
- first = false;
- out << m << c;
- }
- }
- break;
- default:
- assert(false);
- break;
- }
- }
- return out;
-}
-
-// some random os may define these
-#undef UNDEF
-#undef INS
-#undef DEL
-#undef UPD
-#undef NUL
-
-static const uint g_optypes = 3; // real ops 0-2
-
-/*
- * Represents single or composite operation or received event. The
- * post/pre data is either computed here for operations or received from
- * the event.
- */
-struct Op { // single or composite
- enum Kind { OP = 1, EV = 2 };
- enum Type { UNDEF = -1, INS, DEL, UPD, NUL };
- Kind kind;
- Type type;
- Op* next_op; // within one commit
- Op* next_com; // next commit chain
- Op* next_gci; // groups commit chains (unless --separate-events)
- Op* next_ev; // next event
- Op* next_free; // free list
- bool free; // on free list
- uint num_op;
- uint num_com;
- Data data[2]; // 0-post 1-pre
- bool match; // matched to event
- Uint32 gci; // defined for com op and event
- void init(Kind a_kind, Type a_type = UNDEF) {
- kind = a_kind;
- assert(kind == OP || kind == EV);
- type = a_type;
- next_op = next_com = next_gci = next_ev = next_free = 0;
- free = false;
- num_op = num_com = 0;
- data[0].init();
- data[1].init();
- match = false;
- gci = 0;
- }
- void freemem() {
- data[0].freemem();
- data[1].freemem();
- }
-};
-
-static NdbOut&
-operator<<(NdbOut& out, Op::Type optype)
-{
- switch (optype) {
- case Op::INS:
- out << "INS";
- break;
- case Op::DEL:
- out << "DEL";
- break;
- case Op::UPD:
- out << "UPD";
- break;
- case Op::NUL:
- out << "NUL";
- break;
- default:
- out << (int)optype;
- break;
- }
- return out;
-}
-
-static NdbOut&
-operator<<(NdbOut& out, const Op& op)
-{
- out << op.type;
- out << " " << op.data[0];
- out << " [" << op.data[1] << "]";
- if (op.gci != 0)
- out << " gci:" << op.gci;
- return out;
-}
-
-static int
-seteventtype(Op* ev, NdbDictionary::Event::TableEvent te)
-{
- Op::Type optype = Op::UNDEF;
- switch (te) {
- case NdbDictionary::Event::TE_INSERT:
- optype = Op::INS;
- break;
- case NdbDictionary::Event::TE_DELETE:
- optype = Op::DEL;
- break;
- case NdbDictionary::Event::TE_UPDATE:
- optype = Op::UPD;
- break;
- default:
- ll0("EVT: " << *ev << ": bad event type " << hex << (uint)te);
- return -1;
- }
- ev->type = optype;
- return 0;
-}
-
-struct Counter { // debug aid
- const char* name;
- uint count;
- Counter(const char* a_name) : name(a_name), count(0) {
- }
- friend class NdbOut& operator<<(NdbOut& out, const Counter& counter) {
- out << counter.name << "(" << counter.count << ")";
- return out;
- }
- operator uint() {
- return count;
- }
- Counter operator ++(int) {
- ll3(*this << "++");
- Counter tmp = *this;
- count++;
- return tmp;
- }
- Counter operator --(int) {
- ll3(*this << "--");
- assert(count != 0);
- Counter tmp = *this;
- count--;
- return tmp;
- }
-};
-
-static Op* g_opfree = 0;
-static uint g_freeops = 0;
-static uint g_usedops = 0;
-static uint g_gciops = 0;
-static uint g_maxcom = 10; // max ops per commit
-static uint g_seq = 0;
-static Op* g_rec_ev;
-static uint g_num_ev = 0;
-
-static const uint g_maxgcis = 500; // max GCIs seen during 1 loop
-
-// operation data per table and each loop
-struct Run : public Tab {
- bool skip; // no ops in current loop
- NdbEventOperation* evt_op;
- uint gcicnt; // number of CGIs seen in current loop
- Uint64 gcinum[g_maxgcis];
- Uint32 gcievtypes[g_maxgcis][2]; // 0-getGCIEventOperations 1-nextEvent
- uint tableops; // real table ops in this loop
- uint blobops; // approx blob part ops in this loop
- uint gciops; // commit chains or (after mergeops) gci chains
- Op* pk_op[g_maxpk]; // GCI chain of ops per PK
- Op* pk_ev[g_maxpk]; // events per PK
- uint ev_pos[g_maxpk]; // counts events
- NdbRecAttr* ev_ra[2][g_maxcol]; // 0-post 1-pre
- NdbBlob* ev_bh[2][g_maxcol]; // 0-post 1-pre
- Run(uint idx) :
- Tab(idx)
- {
- reset();
- }
- void reset()
- {
- int i, j;
- skip = false;
- evt_op = 0;
- gcicnt = 0;
- for (i = 0; i < g_maxgcis; i++) {
- gcinum[i] = (Uint64)0;
- gcievtypes[i][0] = gcievtypes[i][1] = (Uint32)0;
- }
- tableops = 0;
- blobops = 0;
- gciops = 0;
- for (i = 0; i < g_maxpk; i++) {
- pk_op[i] = 0;
- pk_ev[i] = 0;
- ev_pos[i] = 0;
- }
- for (j = 0; i < 2; j ++) {
- for (i = 0; i < g_maxcol; i++) {
- ev_ra[j][i] = 0;
- ev_bh[j][i] = 0;
- }
- }
- }
- int addgci(Uint64 gci)
- {
- assert(gcicnt < g_maxgcis);
- chkrc(gcicnt == 0 || gcinum[gcicnt - 1] < gci);
- gcinum[gcicnt++] = gci;
- return 0;
- }
- void addevtypes(Uint64 gci, Uint32 evtypes, uint i)
- {
- assert(gcicnt != 0 && gci == gcinum[gcicnt - 1]);
- assert(evtypes != 0);
- assert(i < 2);
- gcievtypes[gcicnt - 1][i] |= evtypes;
- }
-};
-
-static Run* g_runlst[g_maxtab];
-
-static uint
-maxrun()
-{
- return maxtab();
-}
-
-static Run&
-run(uint i)
-{
- assert(i < maxrun() && g_runlst[i] != 0);
- return *g_runlst[i];
-}
-
-static void
-initrun()
-{
- uint i;
- for (i = 0; i < maxrun(); i++)
- g_tablst[i] = g_runlst[i] = new Run(i);
-}
-
-static Op*
-getop(Op::Kind a_kind, Op::Type a_type = Op::UNDEF)
-{
- if (g_opfree == 0) {
- assert(g_freeops == 0);
- Op* op = new Op;
- assert(op != 0);
- op->next_free = g_opfree; // 0
- g_opfree = op;
- op->free = true;
- g_freeops++;
- }
- Op* op = g_opfree;
- g_opfree = op->next_free;
- assert(g_freeops != 0);
- g_freeops--;
- g_usedops++;
- op->init(a_kind, a_type);
- op->free = false;
- ll3("getop: " << op);
- return op;
-}
-
-static void
-freeop(Op* op)
-{
- ll3("freeop: " << op);
- assert(! op->free);
- op->freemem();
- op->free = true;
- op->next_free = g_opfree;
- g_opfree = op;
- g_freeops++;
- assert(g_usedops != 0);
- g_usedops--;
-}
-
-static void
-resetmem(Run& r)
-{
- ll2("resetmem");
- Uint32 pk1;
- for (pk1 = 0; pk1 < g_opts.maxpk; pk1++)
- r.ev_pos[pk1] = 0;
- // leave g_seq
- for (pk1 = 0; pk1 < g_opts.maxpk; pk1++) {
- if (r.pk_op[pk1] != 0) {
- Op* tot_op = r.pk_op[pk1];
- while (tot_op->next_gci != 0) {
- Op* gci_op = tot_op->next_gci;
- while (gci_op->next_com != 0) {
- Op* com_op = gci_op->next_com;
- while (com_op->next_op != 0) {
- Op* op = com_op->next_op;
- com_op->next_op = op->next_op;
- freeop(op);
- }
- gci_op->next_com = com_op->next_com;
- freeop(com_op);
- }
- tot_op->next_gci = gci_op->next_gci;
- freeop(gci_op);
- }
- freeop(tot_op);
- r.pk_op[pk1] = 0;
- }
- if (r.pk_ev[pk1] != 0) {
- Op* tot_op = r.pk_ev[pk1];
- while (tot_op->next_ev != 0) {
- Op* ev = tot_op->next_ev;
- tot_op->next_ev = ev->next_ev;
- freeop(ev);
- }
- freeop(tot_op);
- r.pk_ev[pk1] = 0;
- }
- }
- r.reset();
-}
-
-static void
-resetmem()
-{
- if (g_rec_ev != 0) {
- freeop(g_rec_ev);
- g_rec_ev = 0;
- }
- for (uint i = 0; i < maxrun(); i++)
- resetmem(run(i));
- assert(g_usedops == 0);
- g_gciops = g_num_ev = 0;
-}
-
-static void
-deleteops() // for memleak checks
-{
- while (g_opfree != 0) {
- Op* tmp_op = g_opfree;
- g_opfree = g_opfree->next_free;
- delete tmp_op;
- g_freeops--;
- }
- assert(g_freeops == 0);
-}
-
-struct Comp {
- Op::Type t1, t2, t3;
-};
-
-static Comp
-g_comp[] = {
- { Op::INS, Op::DEL, Op::NUL },
- { Op::INS, Op::UPD, Op::INS },
- { Op::DEL, Op::INS, Op::UPD },
- { Op::UPD, Op::DEL, Op::DEL },
- { Op::UPD, Op::UPD, Op::UPD }
-};
-
-static const uint g_ncomp = sizeof(g_comp)/sizeof(g_comp[0]);
-
-static int
-checkop(const Op* op, Uint32& pk1)
-{
- Op::Type optype = op->type;
- assert(optype != Op::UNDEF);
- if (optype == Op::NUL)
- return 0;
- chkrc(optype == Op::INS || optype == Op::DEL || optype == Op::UPD);
- const Data& d0 = op->data[0];
- const Data& d1 = op->data[1];
- {
- const Col& c = getcol("pk1");
- chkrc(d0.ind[c.no] == 0);
- pk1 = d0.pk1;
- chkrc(pk1 < g_opts.maxpk);
- }
- uint i;
- for (i = 0; i < ncol(); i++) {
- const Col& c = getcol(i);
- const int ind0 = d0.ind[i];
- const int ind1 = d1.ind[i];
- // the rules are the rules..
- if (c.pk) {
- chkrc(ind0 == 0); // always PK in post data
- if (optype == Op::INS)
- chkrc(ind1 == -1);
- if (optype == Op::DEL)
- chkrc(ind1 == -1); // no PK in pre data
- if (optype == Op::UPD)
- chkrc(ind1 == 0);
- }
- if (! c.pk) {
- if (optype == Op::INS)
- chkrc(ind0 >= 0 && ind1 == -1);
- if (optype == Op::DEL)
- chkrc(ind0 == -1 && ind1 >= 0); // always non-PK in pre data
- if (optype == Op::UPD)
- chkrc(ind0 == -1 || ind1 >= 0); // update must have pre data
- }
- if (! c.nullable) {
- chkrc(ind0 <= 0 && ind1 <= 0);
- }
- if (c.isblob()) {
- // blob values must be from allowed chars
- int j;
- for (j = 0; j < 2; j++) {
- const Data& d = op->data[j];
- if (d.ind[i] == 0) {
- const Data::Txt& txt = *d.ptr[i].txt;
- int k;
- for (k = 0; k < txt.len; k++) {
- chkrc(strchr(g_charval, txt.val[k]) != 0);
- }
- }
- }
- }
- }
- return 0;
-}
-
-static Comp*
-comptype(Op::Type t1, Op::Type t2) // only non-NUL
-{
- uint i;
- for (i = 0; i < g_ncomp; i++)
- if (g_comp[i].t1 == t1 && g_comp[i].t2 == t2)
- return &g_comp[i];
- return 0;
-}
-
-static void
-copycol(const Col& c, const Data& d1, Data& d3)
-{
- uint i = c.no;
- if ((d3.ind[i] = d1.ind[i]) == 0) {
- if (! c.isblob()) {
- memmove(d3.ptr[i].v, d1.ptr[i].v, c.size);
- } else {
- Data::Txt& t1 = *d1.ptr[i].txt;
- Data::Txt& t3 = *d3.ptr[i].txt;
- delete [] t3.val;
- t3.val = new char [t1.len];
- t3.len = t1.len;
- memcpy(t3.val, t1.val, t1.len);
- }
- }
-}
-
-static void
-copydata(const Data& d1, Data& d3, bool pk, bool nonpk)
-{
- uint i;
- for (i = 0; i < ncol(); i++) {
- const Col& c = g_col[i];
- if (c.pk && pk || ! c.pk && nonpk)
- copycol(c, d1, d3);
- }
-}
-
-static void
-compdata(const Data& d1, const Data& d2, Data& d3, bool pk, bool nonpk)
-{
- uint i;
- for (i = 0; i < ncol(); i++) {
- const Col& c = g_col[i];
- if (c.pk && pk || ! c.pk && nonpk) {
- const Data* d = 0;
- if (d1.ind[i] == -1 && d2.ind[i] == -1)
- d3.ind[i] = -1;
- else if (d1.ind[i] == -1 && d2.ind[i] != -1)
- d = &d2;
- else if (d1.ind[i] != -1 && d2.ind[i] == -1)
- d = &d1;
- else
- d = &d2;
- if (d != 0)
- copycol(c, *d, d3);
- }
- }
-}
-
-static void
-copyop(const Op* op1, Op* op3)
-{
- op3->type = op1->type;
- copydata(op1->data[0], op3->data[0], true, true);
- copydata(op1->data[1], op3->data[1], true, true);
- op3->gci = op1->gci;
- Uint32 pk1_tmp;
- reqrc(checkop(op3, pk1_tmp) == 0);
-}
-
-static int
-compop(const Op* op1, const Op* op2, Op* op3) // op1 o op2 = op3
-{
- assert(op1->type != Op::UNDEF && op2->type != Op::UNDEF);
- Comp* comp;
- if (op2->type == Op::NUL) {
- copyop(op1, op3);
- return 0;
- }
- if (op1->type == Op::NUL) {
- copyop(op2, op3);
- return 0;
- }
- Op::Kind kind =
- op1->kind == Op::OP && op2->kind == Op::OP ? Op::OP : Op::EV;
- Op* res_op = getop(kind);
- chkrc((comp = comptype(op1->type, op2->type)) != 0);
- res_op->type = comp->t3;
- if (res_op->type == Op::INS) {
- // INS o UPD
- compdata(op1->data[0], op2->data[0], res_op->data[0], true, true);
- // pre = undef
- }
- if (res_op->type == Op::DEL) {
- // UPD o DEL
- copydata(op2->data[0], res_op->data[0], true, false); // PK
- copydata(op1->data[1], res_op->data[1], false, true); // non-PK
- }
- if (res_op->type == Op::UPD && op1->type == Op::DEL) {
- // DEL o INS
- copydata(op2->data[0], res_op->data[0], true, true);
- copydata(op1->data[0], res_op->data[1], true, false); // PK
- copydata(op1->data[1], res_op->data[1], false, true); // non-PK
- }
- if (res_op->type == Op::UPD && op1->type == Op::UPD) {
- // UPD o UPD
- compdata(op1->data[0], op2->data[0], res_op->data[0], true, true);
- compdata(op2->data[1], op1->data[1], res_op->data[1], true, true);
- }
- assert(op1->gci == op2->gci);
- res_op->gci = op2->gci;
- Uint32 pk1_tmp;
- reqrc(checkop(res_op, pk1_tmp) == 0);
- copyop(res_op, op3);
- freeop(res_op);
- return 0;
-}
-
-static int
-createeventop(Run& r)
-{
- ll2("createeventop: " << r.tabname);
- chkdb((r.evt_op = g_ndb->createEventOperation(r.evtname)) != 0);
- r.evt_op->mergeEvents(! g_opts.separate_events); // not yet inherited
- uint i;
- for (i = 0; i < ncol(); i++) {
- const Col& c = g_col[i];
- Data (&d)[2] = g_rec_ev->data;
- if (! c.isblob()) {
- chkdb((r.ev_ra[0][i] = r.evt_op->getValue(c.name, (char*)d[0].ptr[i].v)) != 0);
- chkdb((r.ev_ra[1][i] = r.evt_op->getPreValue(c.name, (char*)d[1].ptr[i].v)) != 0);
- } else {
- chkdb((r.ev_bh[0][i] = r.evt_op->getBlobHandle(c.name)) != 0);
- chkdb((r.ev_bh[1][i] = r.evt_op->getPreBlobHandle(c.name)) != 0);
- }
- }
- return 0;
-}
-
-static int
-createeventop()
-{
- ll1("createeventop");
- for (uint i = 0; i < maxrun(); i++)
- chkrc(createeventop(run(i)) == 0);
- return 0;
-}
-
-static int
-executeeventop(Run& r)
-{
- ll2("executeeventop: " << r.tabname);
- chkdb(r.evt_op->execute() == 0);
- return 0;
-}
-
-static int
-executeeventop()
-{
- ll1("executeeventop");
- for (uint i = 0; i < maxrun(); i++)
- chkrc(executeeventop(run(i)) == 0);
- return 0;
-}
-
-static int
-dropeventop(Run& r, bool force = false)
-{
- ll2("dropeventop: " << r.tabname);
- if (r.evt_op != 0) {
- chkdb(g_ndb->dropEventOperation(r.evt_op) == 0 || force);
- r.evt_op = 0;
- }
- return 0;
-}
-
-static int
-dropeventops(bool force = false)
-{
- ll1("dropeventops");
- for (uint i = 0; i < maxrun(); i++) {
- if (force && g_runlst[i] == 0)
- continue;
- chkrc(dropeventop(run(i), force) == 0 || force);
- }
- return 0;
-}
-
-// wait for event to be installed and for GCIs to pass
-static int
-waitgci(uint ngci)
-{
- ll1("waitgci " << ngci);
- Uint32 gci[2];
- uint i = 0;
- while (1) {
- chkdb((g_con = g_ndb->startTransaction()) != 0);
- { // forced to exec a dummy op
- Tab& t = tab(0); // use first table
- Uint32 pk1;
- char pk2[g_charlen + 1];
- pk1 = g_maxpk;
- sprintf(pk2, "%-*u", g_charlen, pk1);
- chkdb((g_op = g_con->getNdbOperation(t.tabname)) != 0);
- chkdb(g_op->readTuple() == 0);
- chkdb(g_op->equal("pk1", (char*)&pk1) == 0);
- chkdb(g_op->equal("pk2", (char*)&pk2[0]) == 0);
- chkdb(g_con->execute(Commit) == 0);
- g_op = 0;
- }
- gci[i] = g_con->getGCI();
- g_ndb->closeTransaction(g_con);
- g_con = 0;
- if (i == 1 && gci[0] + ngci <= gci[1]) {
- ll1("waitgci: " << gci[0] << " " << gci[1]);
- break;
- }
- i = 1;
- sleep(1);
- }
- return 0;
-}
-
-// scan table and set current tot_op for each pk1
-static int
-scantable(Run& r)
-{
- ll2("scantable: " << r.tabname);
- NdbRecAttr* ra[g_maxcol];
- NdbBlob* bh[g_maxcol];
- Op* rec_op = getop(Op::OP);
- Data& d0 = rec_op->data[0];
- chkdb((g_con = g_ndb->startTransaction()) != 0);
- chkdb((g_scan_op = g_con->getNdbScanOperation(r.tabname)) != 0);
- chkdb(g_scan_op->readTuples() == 0);
- uint i;
- for (i = 0; i < ncol(); i++) {
- const Col& c = getcol(i);
- if (! c.isblob()) {
- chkdb((ra[i] = g_scan_op->getValue(c.name, (char*)d0.ptr[i].v)) != 0);
- } else {
- chkdb((bh[i] = g_scan_op->getBlobHandle(c.name)) != 0);
- }
- }
- chkdb(g_con->execute(NoCommit) == 0);
- int ret;
- while ((ret = g_scan_op->nextResult()) == 0) {
- Uint32 pk1 = d0.pk1;
- if (pk1 >= g_opts.maxpk)
- continue;
- rec_op->type = Op::INS;
- for (i = 0; i < ncol(); i++) {
- const Col& c = getcol(i);
- int ind;
- if (! c.isblob()) {
- ind = ra[i]->isNULL();
- } else {
- int ret;
- ret = bh[i]->getDefined(ind);
- assert(ret == 0);
- if (ind == 0) {
- Data::Txt& txt = *d0.ptr[i].txt;
- Uint64 len64;
- ret = bh[i]->getLength(len64);
- assert(ret == 0);
- txt.len = (uint)len64;
- delete [] txt.val;
- txt.val = new char [txt.len];
- memset(txt.val, 'X', txt.len);
- Uint32 len = txt.len;
- ret = bh[i]->readData(txt.val, len);
- assert(ret == 0 && len == txt.len);
- // to see the data, have to execute...
- chkdb(g_con->execute(NoCommit) == 0);
- assert(memchr(txt.val, 'X', txt.len) == 0);
- }
- }
- assert(ind >= 0);
- d0.ind[i] = ind;
- }
- assert(r.pk_op[pk1] == 0);
- Op* tot_op = r.pk_op[pk1] = getop(Op::OP);
- copyop(rec_op, tot_op);
- tot_op->type = Op::INS;
- }
- chkdb(ret == 1);
- g_ndb->closeTransaction(g_con);
- g_scan_op = 0;
- g_con = 0;
- freeop(rec_op);
- return 0;
-}
-
-static int
-scantable()
-{
- ll1("scantable");
- for (uint i = 0; i < maxrun(); i++)
- chkrc(scantable(run(i)) == 0);
- return 0;
-}
-
-static void
-makedata(const Col& c, Data& d, Uint32 pk1, Op::Type optype)
-{
- uint i = c.no;
- if (c.pk) {
- switch (c.type) {
- case NdbDictionary::Column::Unsigned:
- {
- Uint32* p = d.ptr[i].u32;
- *p = pk1;
- }
- break;
- case NdbDictionary::Column::Char:
- {
- char* p = d.ptr[i].ch;
- sprintf(p, "%-*u", g_charlen, pk1);
- }
- break;
- default:
- assert(false);
- break;
- }
- d.ind[i] = 0;
- } else if (optype == Op::DEL) {
- ;
- } else if (i == getcol("seq").no) {
- d.seq = g_seq++;
- d.ind[i] = 0;
- } else if (optype == Op::INS && ! g_opts.no_implicit_nulls && c.nullable && urandom(10, 100)) {
- d.noop |= (1 << i);
- d.ind[i] = 1; // implicit NULL value is known
- } else if (optype == Op::UPD && ! g_opts.no_missing_update && urandom(10, 100)) {
- d.noop |= (1 << i);
- d.ind[i] = -1; // fixed up in caller
- } else if (! g_opts.no_nulls && c.nullable && urandom(10, 100)) {
- d.ind[i] = 1;
- } else {
- switch (c.type) {
- case NdbDictionary::Column::Unsigned:
- {
- Uint32* p = d.ptr[i].u32;
- uint u = urandom();
- *p = u;
- }
- break;
- case NdbDictionary::Column::Char:
- {
- char* p = d.ptr[i].ch;
- uint u = urandom(g_charlen);
- if (u == 0)
- u = urandom(g_charlen); // 2x bias for non-empty
- uint j;
- for (j = 0; j < g_charlen; j++) {
- uint v = urandom(strlen(g_charval));
- p[j] = j < u ? g_charval[v] : 0x20;
- }
- }
- break;
- case NdbDictionary::Column::Text:
- case NdbDictionary::Column::Blob:
- {
- const bool tinyblob = (c.type == NdbDictionary::Column::Blob);
- Data::Txt& txt = *d.ptr[i].txt;
- delete [] txt.val;
- txt.val = 0;
- if (g_opts.tweak & 1) {
- uint u = g_blobinlinesize + (tinyblob ? 0 : g_blobpartsize);
- uint v = (g_opts.tweak & 2) ? 0 : urandom(strlen(g_charval));
- txt.val = new char [u];
- txt.len = u;
- memset(txt.val, g_charval[v], u);
- break;
- }
- uint u = urandom(tinyblob ? g_blobinlinesize : g_maxblobsize);
- u = urandom(u); // 4x bias for smaller blobs
- u = urandom(u);
- txt.val = new char [u];
- txt.len = u;
- uint j = 0;
- while (j < u) {
- assert(u > 0);
- uint k = 1 + urandom(u - 1);
- if (k > u - j)
- k = u - j;
- uint v = urandom(strlen(g_charval));
- memset(&txt.val[j], g_charval[v], k);
- j += k;
- }
- }
- break;
- default:
- assert(false);
- break;
- }
- d.ind[i] = 0;
- }
-}
-
-static void
-makeop(const Op* prev_op, Op* op, Uint32 pk1, Op::Type optype)
-{
- op->type = optype;
- const Data& dp = prev_op->data[0];
- Data& d0 = op->data[0];
- Data& d1 = op->data[1];
- uint i;
- for (i = 0; i < ncol(); i++) {
- const Col& c = getcol(i);
- makedata(c, d0, pk1, optype);
- if (optype == Op::INS) {
- d1.ind[i] = -1;
- } else if (optype == Op::DEL) {
- assert(dp.ind[i] >= 0);
- if (c.pk)
- d1.ind[i] = -1;
- else
- copycol(c, dp, d1);
- } else if (optype == Op::UPD) {
- assert(dp.ind[i] >= 0);
- if (d0.ind[i] == -1) // not updating this col
- copycol(c, dp, d0); // must keep track of data
- copycol(c, dp, d1);
- } else {
- assert(false);
- }
- }
- Uint32 pk1_tmp = ~(Uint32)0;
- reqrc(checkop(op, pk1_tmp) == 0);
- reqrc(pk1 == pk1_tmp);
-}
-
-static uint
-approxblobops(Op* op)
-{
- uint avg_blob_size = g_maxblobsize / 4; // see makedata()
- uint avg_blob_ops = avg_blob_size / 2000;
- uint n = 0;
- if (! g_opts.no_blobs) {
- n += avg_blob_ops;
- if (! g_opts.one_blob)
- n += avg_blob_ops;
- if (op->type == Op::UPD)
- n *= 2;
- }
- return n;
-}
-
-static void
-makeops(Run& r)
-{
- ll1("makeops: " << r.tabname);
- Uint32 pk1 = 0;
- while (1) {
- if (g_opts.opstring == 0) {
- if (r.tableops + r.blobops >= g_opts.maxops) // use up ops
- break;
- pk1 = urandom(g_opts.maxpk);
- } else {
- if (pk1 >= g_opts.maxpk) // use up pks
- break;
- }
- ll2("makeops: pk1=" << pk1);
- // total op on the pk so far
- // optype either NUL=initial/deleted or INS=created
- Op* tot_op = r.pk_op[pk1];
- if (tot_op == 0)
- tot_op = r.pk_op[pk1] = getop(Op::OP, Op::NUL);
- assert(tot_op->type == Op::NUL || tot_op->type == Op::INS);
- // add new commit chain to end
- Op* last_gci = tot_op;
- while (last_gci->next_gci != 0)
- last_gci = last_gci->next_gci;
- Op* gci_op = getop(Op::OP, Op::NUL);
- last_gci->next_gci = gci_op;
- Op* com_op = getop(Op::OP, Op::NUL);
- gci_op->next_com = com_op;
- // length of random chain
- uint len = ~0;
- if (g_opts.opstring == 0) {
- len = 1 + urandom(g_maxcom - 1);
- len = 1 + urandom(len - 1); // 2x bias for short chain
- }
- uint n = 0;
- while (1) {
- // random or from current g_opts.opstring part
- Op::Type optype;
- if (g_opts.opstring == 0) {
- if (n == len)
- break;
- do {
- optype = (Op::Type)urandom(g_optypes);
- } while (tot_op->type == Op::NUL &&
- (optype == Op::DEL || optype == Op::UPD) ||
- tot_op->type == Op::INS && optype == Op::INS);
- } else {
- const char* str = g_opstringpart[g_loop % g_opstringparts];
- uint m = strlen(str);
- uint k = tot_op->num_com + tot_op->num_op;
- assert(k < m);
- char c = str[k];
- if (c == 'c') {
- if (k + 1 == m)
- pk1 += 1;
- break;
- }
- const char* p = "idu";
- const char* q = strchr(p, c);
- assert(q != 0);
- optype = (Op::Type)(q - p);
- }
- Op* op = getop(Op::OP);
- makeop(tot_op, op, pk1, optype);
- r.tableops++;
- r.blobops += approxblobops(op);
- // add to end
- Op* last_op = com_op;
- while (last_op->next_op != 0)
- last_op = last_op->next_op;
- last_op->next_op = op;
- // merge into chain head and total op
- reqrc(compop(com_op, op, com_op) == 0);
- reqrc(compop(tot_op, op, tot_op) == 0);
- assert(tot_op->type == Op::NUL || tot_op->type == Op::INS);
- // counts
- com_op->num_op += 1;
- tot_op->num_op += 1;
- n++;
- }
- // copy to gci level
- copyop(com_op, gci_op);
- tot_op->num_com += 1;
- r.gciops += 1;
- g_gciops += 1;
- }
- ll1("makeops: " << r.tabname << ": com recs = " << r.gciops);
-}
-
-static void
-selecttables()
-{
- uint i;
- for (i = 0; i < maxrun(); i++)
- run(i).skip = false;
- if (g_opts.opstring != 0) {
- ll1("using all tables due to fixed ops");
- return;
- }
- for (i = 0; i + 1 < maxrun(); i++)
- run(urandom(maxrun())).skip = true;
- uint cnt = 0;
- for (i = 0; i < maxrun(); i++) {
- if (! run(i).skip) {
- ll2("use table " << run(i).tabname);
- cnt++;
- }
- }
- ll1("use " << cnt << "/" << maxrun() << " tables in this loop");
-}
-
-static void
-makeops()
-{
- selecttables();
- for (uint i = 0; i < maxrun(); i++)
- if (! run(i).skip)
- makeops(run(i));
- ll1("makeops: used recs = " << g_usedops << " com recs = " << g_gciops);
-}
-
-static int
-addndbop(Run& r, Op* op)
-{
- chkdb((g_op = g_con->getNdbOperation(r.tabname)) != 0);
- switch (op->type) {
- case Op::INS:
- chkdb(g_op->insertTuple() == 0);
- break;
- case Op::DEL:
- chkdb(g_op->deleteTuple() == 0);
- break;
- case Op::UPD:
- chkdb(g_op->updateTuple() == 0);
- break;
- default:
- assert(false);
- break;
- }
- uint i;
- for (i = 0; i < ncol(); i++) {
- const Col& c = getcol(i);
- const Data& d = op->data[0];
- if (! c.pk)
- continue;
- chkdb(g_op->equal(c.name, (const char*)d.ptr[i].v) == 0);
- }
- if (op->type != Op::DEL) {
- for (i = 0; i < ncol(); i++) {
- const Col& c = getcol(i);
- const Data& d = op->data[0];
- if (c.pk)
- continue;
- if (d.noop & (1 << i))
- continue;
- assert(d.ind[i] >= 0);
- if (! c.isblob()) {
- if (d.ind[i] == 0)
- chkdb(g_op->setValue(c.name, (const char*)d.ptr[i].v) == 0);
- else
- chkdb(g_op->setValue(c.name, (const char*)0) == 0);
- } else {
- const Data::Txt& txt = *d.ptr[i].txt;
- g_bh = g_op->getBlobHandle(c.name);
- if (d.ind[i] == 0)
- chkdb(g_bh->setValue(txt.val, txt.len) == 0);
- else
- chkdb(g_bh->setValue(0, 0) == 0);
- g_bh = 0;
- }
- }
- }
- g_op = 0;
- return 0;
-}
-
-static int
-runops()
-{
- ll1("runops");
- Op* gci_op[g_maxtab][g_maxpk];
- uint left = 0; // number of table pks with ops
- int i;
- Uint32 pk1;
- for (i = 0; i < maxrun(); i++) {
- Run& r = run(i);
- for (pk1 = 0; pk1 < g_opts.maxpk; pk1++) {
- gci_op[i][pk1] = 0;
- // total op on the pk
- Op* tot_op = r.pk_op[pk1];
- if (tot_op == 0)
- continue;
- if (tot_op->next_gci == 0) {
- assert(g_loop != 0 && tot_op->type == Op::INS);
- continue;
- }
- // first commit chain
- assert(tot_op->next_gci != 0);
- gci_op[i][pk1] = tot_op->next_gci;
- left++;
- }
- }
- while (left != 0) {
- i = urandom(maxrun());
- pk1 = urandom(g_opts.maxpk);
- if (gci_op[i][pk1] == 0)
- continue;
- Run& r = run(i);
- // do the ops in one transaction
- chkdb((g_con = g_ndb->startTransaction()) != 0);
- Op* com_op = gci_op[i][pk1]->next_com;
- assert(com_op != 0);
- // first op in chain
- Op* op = com_op->next_op;
- assert(op != 0);
- while (op != 0) {
- ll2("runops:" << *op);
- chkrc(addndbop(r, op) == 0);
- op = op->next_op;
- }
- chkdb(g_con->execute(Commit) == 0);
- gci_op[i][pk1]->gci = com_op->gci = g_con->getGCI();
- ll2("commit: " << run(i).tabname << " gci=" << com_op->gci);
- g_ndb->closeTransaction(g_con);
- g_con = 0;
- // next chain
- gci_op[i][pk1] = gci_op[i][pk1]->next_gci;
- if (gci_op[i][pk1] == 0) {
- assert(left != 0);
- left--;
- }
- }
- assert(left == 0);
- return 0;
-}
-
-// move com chains with same gci under same gci entry
-static void
-mergeops(Run& r)
-{
- ll2("mergeops: " << r.tabname);
- uint mergecnt = 0;
- Uint32 pk1;
- for (pk1 = 0; pk1 < g_opts.maxpk; pk1++) {
- Op* tot_op = r.pk_op[pk1];
- if (tot_op == 0)
- continue;
- Op* gci_op = tot_op->next_gci;
- if (gci_op == 0) {
- assert(g_loop != 0 && tot_op->type == Op::INS);
- continue;
- }
- while (gci_op != 0) {
- Op* com_op = gci_op->next_com;
- assert(com_op != 0 && com_op->next_com == 0);
- assert(gci_op->gci == com_op->gci);
- Op* last_com = com_op;
- Op* gci_op2 = gci_op->next_gci;
- while (gci_op2 != 0 && gci_op->gci == gci_op2->gci) {
- // move link to com level
- last_com = last_com->next_com = gci_op2->next_com;
- // merge to gci
- reqrc(compop(gci_op, gci_op2, gci_op) == 0);
- // move to next and discard
- Op* tmp_op = gci_op2;
- gci_op2 = gci_op2->next_gci;
- freeop(tmp_op);
- mergecnt++;
- assert(r.gciops != 0 && g_gciops != 0);
- r.gciops--;
- g_gciops--;
- }
- gci_op = gci_op->next_gci = gci_op2;
- }
- }
- ll1("mergeops: " << r.tabname << ": gci recs = " << r.gciops);
-}
-
-static void
-mergeops()
-{
- for (uint i = 0; i < maxrun(); i++)
- mergeops(run(i));
- ll1("mergeops: used recs = " << g_usedops << " gci recs = " << g_gciops);
-}
-
-// set bit for equal post/pre data in UPD, for use in event match
-static void
-cmppostpre(Run& r)
-{
- ll2("cmppostpre: " << r.tabname);
- Uint32 pk1;
- for (pk1 = 0; pk1 < g_opts.maxpk; pk1++) {
- Op* tot_op = r.pk_op[pk1];
- Op* gci_op = tot_op ? tot_op->next_gci : 0;
- while (gci_op != 0) {
- if (gci_op->type == Op::UPD) {
- Data (&d)[2] = gci_op->data;
- uint i;
- for (i = 0; i < ncol(); i++) {
- const Col& c = getcol(i);
- bool eq =
- d[0].ind[i] == 1 && d[1].ind[i] == 1 ||
- d[0].ind[i] == 0 && d[1].ind[i] == 0 && cmpcol(c, d[0], d[1]) == 0;
- if (eq) {
- d[0].ppeq |= (1 << i);
- d[1].ppeq |= (1 << i);
- }
- }
- }
- gci_op = gci_op->next_gci;
- }
- }
-}
-
-static void
-cmppostpre()
-{
- ll1("cmppostpre");
- for (uint i = 0; i < maxrun(); i++)
- cmppostpre(run(i));
-}
-
-static int
-findevent(const NdbEventOperation* evt_op)
-{
- uint i;
- for (i = 0; i < maxrun(); i++) {
- if (run(i).evt_op == evt_op)
- break;
- }
- chkrc(i < maxrun());
- return i;
-}
-
-static void
-geteventdata(Run& r)
-{
- Data (&d)[2] = g_rec_ev->data;
- int i, j;
- for (j = 0; j < 2; j++) {
- for (i = 0; i < ncol(); i++) {
- const Col& c = getcol(i);
- int ind, ret;
- if (! c.isblob()) {
- NdbRecAttr* ra = r.ev_ra[j][i];
- ind = ra->isNULL();
- } else {
- NdbBlob* bh = r.ev_bh[j][i];
- ret = bh->getDefined(ind);
- assert(ret == 0);
- if (ind == 0) { // value was returned and is not NULL
- Data::Txt& txt = *d[j].ptr[i].txt;
- Uint64 len64;
- ret = bh->getLength(len64);
- assert(ret == 0);
- txt.len = (uint)len64;
- delete [] txt.val;
- txt.val = new char [txt.len];
- memset(txt.val, 'X', txt.len);
- Uint32 len = txt.len;
- ret = bh->readData(txt.val, len);
- assert(ret == 0 && len == txt.len);
- }
- }
- d[j].ind[i] = ind;
- }
- }
-}
-
-static int
-addgcievents(Uint64 gci)
-{
- ll1("getgcieventops");
- uint count = 0;
- uint seen_current = 0;
- Uint32 iter = 0;
- while (1) {
- Uint32 evtypes = 0;
- const NdbEventOperation* evt_op =
- g_ndb->getGCIEventOperations(&iter, &evtypes);
- if (evt_op == 0)
- break;
- // evt_op->getGCI() is not defined yet
- int i;
- chkrc((i = findevent(evt_op)) != -1);
- run(i).addevtypes(gci, evtypes, 0);
- seen_current += (g_evt_op == evt_op);
- count++;
- }
- chkrc(seen_current == 1);
- ll1("addgcievents: " << count);
- return 0;
-}
-
-static int
-runevents()
-{
- ll1("runevents");
- uint mspoll = 1000;
- uint npoll = 6; // strangely long delay
- ll1("poll " << npoll);
- Uint64 gci = (Uint64)0;
- while (npoll != 0) {
- npoll--;
- int ret;
- ret = g_ndb->pollEvents(mspoll);
- if (ret <= 0)
- continue;
- while (1) {
- g_rec_ev->init(Op::EV);
- g_evt_op = g_ndb->nextEvent();
- if (g_evt_op == 0)
- break;
- Uint64 newgci = g_evt_op->getGCI();
- assert(newgci != 0);
- g_rec_ev->gci = newgci;
- if (gci != newgci) {
- ll1("new gci: " << gci << " -> " << newgci);
- gci = newgci;
- // add slot in each tab|e
- uint i;
- for (i = 0; i < maxtab(); i++)
- chkrc(run(i).addgci(gci) == 0);
- chkrc(addgcievents(gci) == 0);
- }
- int i;
- chkrc((i = findevent(g_evt_op)) != -1);
- Run& r = run(i);
- NdbDictionary::Event::TableEvent evtype = g_evt_op->getEventType();
- chkrc(seteventtype(g_rec_ev, evtype) == 0);
- r.addevtypes(gci, (Uint32)evtype, 1);
- geteventdata(r);
- ll2("runevents: EVT: " << *g_rec_ev);
- // check basic sanity
- Uint32 pk1 = ~(Uint32)0;
- chkrc(checkop(g_rec_ev, pk1) == 0);
- // add to events
- Op* tot_ev = r.pk_ev[pk1];
- if (tot_ev == 0)
- tot_ev = r.pk_ev[pk1] = getop(Op::EV);
- Op* last_ev = tot_ev;
- while (last_ev->next_ev != 0)
- last_ev = last_ev->next_ev;
- // copy and add
- Op* ev = getop(Op::EV);
- copyop(g_rec_ev, ev);
- g_rec_ev->freemem();
- last_ev->next_ev = ev;
- g_num_ev++;
- }
- }
- ll1("runevents: used ops = " << g_usedops << " events = " << g_num_ev);
- return 0;
-}
-
-static int
-cmpopevdata(const Data& d1, const Data& d2)
-{
- uint i;
- for (i = 0; i < ncol(); i++) {
- const Col& c = getcol(i);
- if (cmpcol(c, d1, d2) != 0) {
- if ((d1.ppeq & (1 << i)) && d2.ind[i] == -1)
- ; // post/pre data equal and no event data returned is OK
- else
- return 1;
- }
- }
- return 0;
-}
-
-// compare operation to event data
-static int
-cmpopevdata(const Data (&d1)[2], const Data (&d2)[2])
-{
- if (cmpopevdata(d1[0], d2[0]) != 0)
- return 1;
- if (cmpopevdata(d1[1], d2[1]) != 0)
- return 1;
- return 0;
-}
-
-static int
-matchevent(Run& r, Op* ev)
-{
- Data (&d2)[2] = ev->data;
- // get PK
- Uint32 pk1 = d2[0].pk1;
- chkrc(pk1 < g_opts.maxpk);
- // on error repeat and print details
- uint loop = 0;
- while (loop <= 1) {
- int g_loglevel = loop == 0 ? g_opts.loglevel : 2;
- ll1("matchevent: " << r.tabname << ": pk1=" << pk1 << " type=" << ev->type);
- ll2("EVT: " << *ev);
- Op* tot_op = r.pk_op[pk1];
- Op* gci_op = tot_op ? tot_op->next_gci : 0;
- uint pos = 0;
- bool ok = false;
- while (gci_op != 0) {
- ll2("GCI: " << *gci_op);
- // print details
- Op* com_op = gci_op->next_com;
- assert(com_op != 0);
- while (com_op != 0) {
- ll2("COM: " << *com_op);
- Op* op = com_op->next_op;
- assert(op != 0);
- while (op != 0) {
- ll2("OP : " << *op);
- op = op->next_op;
- }
- com_op = com_op->next_com;
- }
- // match against GCI op
- if (gci_op->type != Op::NUL) {
- const Data (&d1)[2] = gci_op->data;
- if (cmpopevdata(d1, d2) == 0) {
- bool tmpok = true;
- if (gci_op->type != ev->type) {
- ll2("***: wrong type " << gci_op->type << " != " << ev->type);
- tmpok = false;
- }
- if (gci_op->match) {
- ll2("***: duplicate match");
- tmpok = false;
- }
- if (pos != r.ev_pos[pk1]) {
- ll2("***: wrong pos " << pos << " != " << r.ev_pos[pk1]);
- tmpok = false;
- }
- if (gci_op->gci != ev->gci) {
- ll2("***: wrong gci " << gci_op->gci << " != " << ev->gci);
- tmpok = false;
- }
- if (tmpok) {
- ok = gci_op->match = true;
- ll2("match");
- }
- }
- pos++;
- }
- gci_op = gci_op->next_gci;
- }
- if (ok) {
- ll2("matchevent: match");
- return 0;
- }
- ll0("matchevent: ERROR: no match");
- if (g_loglevel >= 2)
- return -1;
- loop++;
- }
- return 0;
-}
-
-static int
-matchevents(Run& r)
-{
- ll1("matchevents: " << r.tabname);
- uint nomatch = 0;
- Uint32 pk1;
- for (pk1 = 0; pk1 < g_opts.maxpk; pk1++) {
- Op* tot_ev = r.pk_ev[pk1];
- if (tot_ev == 0)
- continue;
- Op* ev = tot_ev->next_ev;
- while (ev != 0) {
- if (matchevent(r, ev) < 0)
- nomatch++;
- r.ev_pos[pk1]++;
- ev = ev->next_ev;
- }
- }
- chkrc(nomatch == 0);
- return 0;
-}
-
-static int
-matchevents()
-{
- ll1("matchevents");
- for (uint i = 0; i < maxrun(); i++)
- chkrc(matchevents(run(i)) == 0);
- return 0;
-}
-
-static int
-matchops(Run& r)
-{
- ll1("matchops: " << r.tabname);
- uint nomatch = 0;
- Uint32 pk1;
- for (pk1 = 0; pk1 < g_opts.maxpk; pk1++) {
- Op* tot_op = r.pk_op[pk1];
- if (tot_op == 0)
- continue;
- Op* gci_op = tot_op->next_gci;
- while (gci_op != 0) {
- if (gci_op->type == Op::NUL) {
- ll2("GCI: " << *gci_op << " [skip NUL]");
- } else if (gci_op->match) {
- ll2("GCI: " << *gci_op << " [match OK]");
- } else {
- ll0("GCI: " << *gci_op);
- Op* com_op = gci_op->next_com;
- assert(com_op != 0);
- ll0("COM: " << *com_op);
- Op* op = com_op->next_op;
- assert(op != 0);
- while (op != 0) {
- ll0("OP : " << *op);
- op = op->next_op;
- }
- ll0("no matching event");
- nomatch++;
- }
- gci_op = gci_op->next_gci;
- }
- }
- chkrc(nomatch == 0);
- return 0;
-}
-
-static int
-matchops()
-{
- ll1("matchops");
- for (uint i = 0; i < maxrun(); i++)
- chkrc(matchops(run(i)) == 0);
- return 0;
-}
-
-static int
-matchgcievents(Run& r)
-{
- ll1("matchgcievents: " << r.tabname);
- uint i;
- for (i = 0; i < r.gcicnt; i++) {
- Uint32 t0 = r.gcievtypes[i][0];
- Uint32 t1 = r.gcievtypes[i][1];
- ll1("gci: " << r.gcinum[i] << hex << " report: " << t0 << " seen: " << t1);
-
- if (r.skip)
- chkrc(t0 == 0 && t1 == 0);
- if (t0 == 0 && t1 == 0)
- continue;
-
- // check if not reported event op seen
- chkrc(t0 != 0);
- // check if not reported event type seen
- chkrc((~t0 & t1) == 0);
-
- // the other way does not work under merge
- if (g_opts.separate_events) {
- // check if reported event op not seen
- chkrc(t1 != 0);
- // check if reported event type not seen
- chkrc((t0 & ~t1) == 0);
- }
- }
- return 0;
-}
-
-static int
-matchgcievents()
-{
- ll1("matchgcievents");
- for (uint i = 0; i < maxrun(); i++)
- chkrc(matchgcievents(run(i)) == 0);
- return 0;
-}
-
-static void
-setseed(int n)
-{
- uint seed;
- if (n == -1) {
- if (g_opts.seed == 0)
- return;
- if (g_opts.seed != -1)
- seed = (uint)g_opts.seed;
- else
- seed = 1 + (ushort)getpid();
- } else {
- if (g_opts.seed != 0)
- return;
- seed = n;
- }
- ll0("seed=" << seed);
- srandom(seed);
-}
-
-static int
-runtest()
-{
- setseed(-1);
- initrun();
- chkrc(createtables() == 0);
- chkrc(createevents() == 0);
- for (g_loop = 0; g_opts.loop == 0 || g_loop < g_opts.loop; g_loop++) {
- ll0("=== loop " << g_loop << " ===");
- setseed(g_loop);
- resetmem();
- chkrc(scantable() == 0); // alternative: save tot_op for loop > 0
- makeops();
- g_rec_ev = getop(Op::EV);
- chkrc(createeventop() == 0);
- chkrc(executeeventop() == 0);
- chkrc(waitgci(3) == 0);
- chkrc(runops() == 0);
- if (! g_opts.separate_events)
- mergeops();
- cmppostpre();
- chkrc(runevents() == 0);
- ll0("counts: gci ops = " << g_gciops << " ev ops = " << g_num_ev);
- chkrc(matchevents() == 0);
- chkrc(matchops() == 0);
- chkrc(matchgcievents() == 0);
- chkrc(dropeventops() == 0);
- // time erases everything..
- chkrc(waitgci(1) == 0);
- }
- chkrc(dropevents() == 0);
- chkrc(droptables() == 0);
- resetmem();
- deleteops();
- return 0;
-}
-
-NDB_STD_OPTS_VARS;
-
-static struct my_option
-my_long_options[] =
-{
- NDB_STD_OPTS("test_event_merge"),
- { "abort-on-error", 1001, "Do abort() on any error",
- &g_opts.abort_on_error, &g_opts.abort_on_error, 0,
- GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
- { "loglevel", 1002, "Logging level in this program 0-3 (default 0)",
- &g_opts.loglevel, &g_opts.loglevel, 0,
- GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
- { "loop", 1003, "Number of test loops (default 5, 0=forever)",
- &g_opts.loop, &g_opts.loop, 0,
- GET_INT, REQUIRED_ARG, 5, 0, 0, 0, 0, 0 },
- { "maxops", 1004, "Approx number of PK operations per table (default 1000)",
- &g_opts.maxops, &g_opts.maxops, 0,
- GET_UINT, REQUIRED_ARG, 1000, 0, 0, 0, 0, 0 },
- { "maxpk", 1005, "Number of different PK values (default 10, max 1000)",
- &g_opts.maxpk, &g_opts.maxpk, 0,
- GET_UINT, REQUIRED_ARG, 10, 0, 0, 0, 0, 0 },
- { "maxtab", 1006, "Number of tables (default 10, max 100)",
- &g_opts.maxtab, &g_opts.maxtab, 0,
- GET_INT, REQUIRED_ARG, 10, 0, 0, 0, 0, 0 },
- { "no-blobs", 1007, "Omit blob attributes (5.0: true)",
- &g_opts.no_blobs, &g_opts.no_blobs, 0,
- GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
- { "no-implicit-nulls", 1008, "Insert must include all attrs"
- " i.e. no implicit NULLs",
- &g_opts.no_implicit_nulls, &g_opts.no_implicit_nulls, 0,
- GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
- { "no-missing-update", 1009, "Update must include all non-PK attrs",
- &g_opts.no_missing_update, &g_opts.no_missing_update, 0,
- GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
- { "no-multiops", 1010, "Allow only 1 operation per commit",
- &g_opts.no_multiops, &g_opts.no_multiops, 0,
- GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
- { "no-nulls", 1011, "Create no NULL values",
- &g_opts.no_nulls, &g_opts.no_nulls, 0,
- GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
- { "one-blob", 1012, "Only one blob attribute (default 2)",
- &g_opts.one_blob, &g_opts.one_blob, 0,
- GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
- { "opstring", 1013, "Operations to run e.g. idiucdc (c is commit) or"
- " iuuc:uudc (the : separates loops)",
- &g_opts.opstring, &g_opts.opstring, 0,
- GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
- { "seed", 1014, "Random seed (0=loop number, default -1=random)",
- &g_opts.seed, &g_opts.seed, 0,
- GET_INT, REQUIRED_ARG, -1, 0, 0, 0, 0, 0 },
- { "separate-events", 1015, "Do not combine events per GCI (5.0: true)",
- &g_opts.separate_events, &g_opts.separate_events, 0,
- GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
- { "tweak", 1016, "Whatever the source says",
- &g_opts.tweak, &g_opts.tweak, 0,
- GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
- { "use-table", 1017, "Use existing tables",
- &g_opts.use_table, &g_opts.use_table, 0,
- GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
- { 0, 0, 0,
- 0, 0, 0,
- GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 }
-};
-
-static void
-usage()
-{
- my_print_help(my_long_options);
-}
-
-static int
-checkopts()
-{
- if (g_opts.separate_events) {
- g_opts.no_blobs = true;
- }
- if (g_opts.no_multiops) {
- g_maxcom = 1;
- }
- if (g_opts.opstring != 0) {
- uint len = strlen(g_opts.opstring);
- char* str = new char [len + 1];
- memcpy(str, g_opts.opstring, len + 1);
- char* s = str;
- while (1) {
- g_opstringpart[g_opstringparts++] = s;
- s = strchr(s, ':');
- if (s == 0)
- break;
- *s++ = 0;
- }
- uint i;
- for (i = 0; i < g_opstringparts; i++) {
- const char* s = g_opstringpart[i];
- while (*s != 0) {
- if (strchr("iduc", *s++) == 0) {
- ll0("opstring chars are i,d,u,c");
- return -1;
- }
- }
- if (s == g_opstringpart[i] || s[-1] != 'c') {
- ll0("opstring chain must end in 'c'");
- return -1;
- }
- }
- }
- if (g_opts.no_nulls) {
- g_opts.no_implicit_nulls = true;
- }
- if (g_opts.maxpk > g_maxpk ||
- g_opts.maxtab > g_maxtab) {
- return -1;
- }
- return 0;
-}
-
-static int
-doconnect()
-{
- g_ncc = new Ndb_cluster_connection();
- chkdb(g_ncc->connect(30) == 0);
- g_ndb = new Ndb(g_ncc, "TEST_DB");
- chkdb(g_ndb->init() == 0 && g_ndb->waitUntilReady(30) == 0);
- return 0;
-}
-
-int
-main(int argc, char** argv)
-{
- ndb_init();
- const char* progname =
- strchr(argv[0], '/') ? strrchr(argv[0], '/') + 1 : argv[0];
- uint i;
- ndbout << progname;
- for (i = 1; i < argc; i++)
- ndbout << " " << argv[i];
- ndbout << endl;
- int ret;
- ret = handle_options(&argc, &argv, my_long_options, ndb_std_get_one_option);
- if (ret != 0 || argc != 0 || checkopts() != 0)
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- if (doconnect() == 0 && runtest() == 0) {
- delete g_ndb;
- delete g_ncc;
- return NDBT_ProgramExit(NDBT_OK);
- }
- dropeventops(true);
- dropevents(true);
- delete g_ndb;
- delete g_ncc;
- return NDBT_ProgramExit(NDBT_FAILED);
-}
diff --git a/storage/ndb/test/ndbapi/test_event_multi_table.cpp b/storage/ndb/test/ndbapi/test_event_multi_table.cpp
deleted file mode 100644
index a8cf0fa86c0..00000000000
--- a/storage/ndb/test/ndbapi/test_event_multi_table.cpp
+++ /dev/null
@@ -1,558 +0,0 @@
-/* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-#include <ndb_opts.h>
-#include <NDBT_Test.hpp>
-#include <NDBT_ReturnCodes.h>
-#include <HugoTransactions.hpp>
-#include <UtilTransactions.hpp>
-#include <TestNdbEventOperation.hpp>
-#include <NdbRestarter.hpp>
-#include <NdbRestarts.hpp>
-
-static void usage()
-{
- ndb_std_print_version();
-}
-
-static int start_transaction(Ndb *ndb, Vector<HugoOperations*> &ops)
-{
- if (ops[0]->startTransaction(ndb) != NDBT_OK)
- return -1;
- NdbTransaction * t= ops[0]->getTransaction();
- for (int i= ops.size()-1; i > 0; i--)
- {
- ops[i]->setTransaction(t);
- }
- return 0;
-}
-
-static int close_transaction(Ndb *ndb, Vector<HugoOperations*> &ops)
-{
- if (ops[0]->closeTransaction(ndb) != NDBT_OK)
- return -1;
- for (int i= ops.size()-1; i > 0; i--)
- {
- ops[i]->setTransaction(NULL);
- }
- return 0;
-}
-
-static int execute_commit(Ndb *ndb, Vector<HugoOperations*> &ops)
-{
- if (ops[0]->execute_Commit(ndb) != NDBT_OK)
- return -1;
- return 0;
-}
-
-static int copy_events(Ndb *ndb)
-{
- DBUG_ENTER("copy_events");
- int r= 0;
- NdbDictionary::Dictionary * dict = ndb->getDictionary();
- while (1)
- {
- int res= ndb->pollEvents(1000); // wait for event or 1000 ms
- DBUG_PRINT("info", ("pollEvents res=%d", res));
- if (res <= 0)
- {
- break;
- }
- int error= 0;
- NdbEventOperation *pOp;
- while ((pOp= ndb->nextEvent(&error)))
- {
- char buf[1024];
- sprintf(buf, "%s_SHADOW", pOp->getTable()->getName());
- const NdbDictionary::Table *table= dict->getTable(buf);
-
- if (table == 0)
- {
- g_err << "unable to find table " << buf << endl;
- DBUG_RETURN(-1);
- }
-
- if (pOp->isOverrun())
- {
- g_err << "buffer overrun\n";
- DBUG_RETURN(-1);
- }
- r++;
-
- Uint32 gci= pOp->getGCI();
-
- if (!pOp->isConsistent()) {
- g_err << "A node failure has occured and events might be missing\n";
- DBUG_RETURN(-1);
- }
-
- int noRetries= 0;
- do
- {
- NdbTransaction *trans= ndb->startTransaction();
- if (trans == 0)
- {
- g_err << "startTransaction failed "
- << ndb->getNdbError().code << " "
- << ndb->getNdbError().message << endl;
- DBUG_RETURN(-1);
- }
-
- NdbOperation *op= trans->getNdbOperation(table);
- if (op == 0)
- {
- g_err << "getNdbOperation failed "
- << trans->getNdbError().code << " "
- << trans->getNdbError().message << endl;
- DBUG_RETURN(-1);
- }
-
- switch (pOp->getEventType()) {
- case NdbDictionary::Event::TE_INSERT:
- if (op->insertTuple())
- {
- g_err << "insertTuple "
- << op->getNdbError().code << " "
- << op->getNdbError().message << endl;
- DBUG_RETURN(-1);
- }
- break;
- case NdbDictionary::Event::TE_DELETE:
- if (op->deleteTuple())
- {
- g_err << "deleteTuple "
- << op->getNdbError().code << " "
- << op->getNdbError().message << endl;
- DBUG_RETURN(-1);
- }
- break;
- case NdbDictionary::Event::TE_UPDATE:
- if (op->updateTuple())
- {
- g_err << "updateTuple "
- << op->getNdbError().code << " "
- << op->getNdbError().message << endl;
- DBUG_RETURN(-1);
- }
- break;
- default:
- abort();
- }
-
- {
- for (const NdbRecAttr *pk= pOp->getFirstPkAttr(); pk; pk= pk->next())
- {
- if (pk->isNULL())
- {
- g_err << "internal error: primary key isNull()="
- << pk->isNULL() << endl;
- DBUG_RETURN(NDBT_FAILED);
- }
- if (op->equal(pk->getColumn()->getColumnNo(),pk->aRef()))
- {
- g_err << "equal " << pk->getColumn()->getColumnNo() << " "
- << op->getNdbError().code << " "
- << op->getNdbError().message << endl;
- DBUG_RETURN(NDBT_FAILED);
- }
- }
- }
-
- switch (pOp->getEventType()) {
- case NdbDictionary::Event::TE_INSERT:
- {
- for (const NdbRecAttr *data= pOp->getFirstDataAttr(); data; data= data->next())
- {
- if (data->isNULL() < 0 ||
- op->setValue(data->getColumn()->getColumnNo(),
- data->isNULL() ? 0:data->aRef()))
- {
- g_err << "setValue(insert) " << data->getColumn()->getColumnNo() << " "
- << op->getNdbError().code << " "
- << op->getNdbError().message << endl;
- DBUG_RETURN(-1);
- }
- }
- break;
- }
- case NdbDictionary::Event::TE_DELETE:
- break;
- case NdbDictionary::Event::TE_UPDATE:
- {
- for (const NdbRecAttr *data= pOp->getFirstDataAttr(); data; data= data->next())
- {
- if (data->isNULL() >= 0 &&
- op->setValue(data->getColumn()->getColumnNo(),
- data->isNULL() ? 0:data->aRef()))
- {
- g_err << "setValue(update) " << data->getColumn()->getColumnNo() << " "
- << op->getNdbError().code << " "
- << op->getNdbError().message << endl;
- DBUG_RETURN(NDBT_FAILED);
- }
- }
- break;
- }
- case NdbDictionary::Event::TE_ALL:
- abort();
- }
- if (trans->execute(Commit) == 0)
- {
- trans->close();
- // everything ok
- break;
- }
- if (noRetries++ == 10 ||
- trans->getNdbError().status != NdbError::TemporaryError)
- {
- g_err << "execute " << r << " failed "
- << trans->getNdbError().code << " "
- << trans->getNdbError().message << endl;
- trans->close();
- DBUG_RETURN(-1);
- }
- trans->close();
- NdbSleep_MilliSleep(100); // sleep before retying
- } while(1);
- } // for
- if (error)
- {
- g_err << "nextEvent()\n";
- DBUG_RETURN(-1);
- }
- } // while(1)
- DBUG_RETURN(r);
-}
-
-static int verify_copy(Ndb *ndb,
- Vector<const NdbDictionary::Table *> &tabs1,
- Vector<const NdbDictionary::Table *> &tabs2)
-{
- for (unsigned i= 0; i < tabs1.size(); i++)
- if (tabs1[i])
- {
- HugoTransactions hugoTrans(*tabs1[i]);
- if (hugoTrans.compare(ndb, tabs2[i]->getName(), 0))
- return -1;
- }
- return 0;
-}
-
-NDB_STD_OPTS_VARS;
-
-static const char* _dbname = "TEST_DB";
-static struct my_option my_long_options[] =
-{
- NDB_STD_OPTS(""),
- { "database", 'd', "Name of database table is in",
- &_dbname, &_dbname, 0,
- GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
- { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
-};
-
-int
-main(int argc, char** argv)
-{
- NDB_INIT(argv[0]);
- const char *load_default_groups[]= { "mysql_cluster",0 };
- load_defaults("my",load_default_groups,&argc,&argv);
-
- int ho_error;
-#ifndef DBUG_OFF
- opt_debug= "d:t:F:L";
-#endif
- if ((ho_error=handle_options(&argc, &argv, my_long_options,
- ndb_std_get_one_option)))
- return NDBT_ProgramExit(NDBT_WRONGARGS);
-
- DBUG_ENTER("main");
- Ndb_cluster_connection con(opt_connect_str);
- if(con.connect(12, 5, 1))
- {
- DBUG_RETURN(NDBT_ProgramExit(NDBT_FAILED));
- }
-
-
- Ndb ndb(&con,_dbname);
- ndb.init();
- while (ndb.waitUntilReady() != 0);
-
- NdbDictionary::Dictionary * dict = ndb.getDictionary();
- int no_error= 1;
- int i;
-
- // create all tables
- Vector<const NdbDictionary::Table*> pTabs;
- if (argc == 0)
- {
- NDBT_Tables::dropAllTables(&ndb);
- NDBT_Tables::createAllTables(&ndb);
- for (i= 0; no_error && i < NDBT_Tables::getNumTables(); i++)
- {
- const NdbDictionary::Table *pTab= dict->getTable(NDBT_Tables::getTable(i)->getName());
- if (pTab == 0)
- {
- ndbout << "Failed to create table" << endl;
- ndbout << dict->getNdbError() << endl;
- no_error= 0;
- break;
- }
- pTabs.push_back(pTab);
- }
- }
- else
- {
- for (i= 0; no_error && argc; argc--, i++)
- {
- dict->dropTable(argv[i]);
- NDBT_Tables::createTable(&ndb, argv[i]);
- const NdbDictionary::Table *pTab= dict->getTable(argv[i]);
- if (pTab == 0)
- {
- ndbout << "Failed to create table" << endl;
- ndbout << dict->getNdbError() << endl;
- no_error= 0;
- break;
- }
- pTabs.push_back(pTab);
- }
- }
- pTabs.push_back(NULL);
-
- // create an event for each table
- for (i= 0; no_error && pTabs[i]; i++)
- {
- HugoTransactions ht(*pTabs[i]);
- if (ht.createEvent(&ndb)){
- no_error= 0;
- break;
- }
- }
-
- // create an event operation for each event
- Vector<NdbEventOperation *> pOps;
- for (i= 0; no_error && pTabs[i]; i++)
- {
- char buf[1024];
- sprintf(buf, "%s_EVENT", pTabs[i]->getName());
- NdbEventOperation *pOp= ndb.createEventOperation(buf, 1000);
- if ( pOp == NULL )
- {
- no_error= 0;
- break;
- }
- pOps.push_back(pOp);
- }
-
- // get storage for each event operation
- for (i= 0; no_error && pTabs[i]; i++)
- {
- int n_columns= pTabs[i]->getNoOfColumns();
- for (int j = 0; j < n_columns; j++) {
- pOps[i]->getValue(pTabs[i]->getColumn(j)->getName());
- pOps[i]->getPreValue(pTabs[i]->getColumn(j)->getName());
- }
- }
-
- // start receiving events
- for (i= 0; no_error && pTabs[i]; i++)
- {
- if ( pOps[i]->execute() )
- {
- no_error= 0;
- break;
- }
- }
-
- // create a "shadow" table for each table
- Vector<const NdbDictionary::Table*> pShadowTabs;
- for (i= 0; no_error && pTabs[i]; i++)
- {
- char buf[1024];
- sprintf(buf, "%s_SHADOW", pTabs[i]->getName());
-
- dict->dropTable(buf);
- if (dict->getTable(buf))
- {
- no_error= 0;
- break;
- }
-
- NdbDictionary::Table table_shadow(*pTabs[i]);
- table_shadow.setName(buf);
- dict->createTable(table_shadow);
- pShadowTabs.push_back(dict->getTable(buf));
- if (!pShadowTabs[i])
- {
- no_error= 0;
- break;
- }
- }
-
- // create a hugo operation per table
- Vector<HugoOperations *> hugo_ops;
- for (i= 0; no_error && pTabs[i]; i++)
- {
- hugo_ops.push_back(new HugoOperations(*pTabs[i]));
- }
-
- int n_records= 3;
- // insert n_records records per table
- do {
- if (start_transaction(&ndb, hugo_ops))
- {
- no_error= 0;
- break;
- }
- for (i= 0; no_error && pTabs[i]; i++)
- {
- hugo_ops[i]->pkInsertRecord(&ndb, 0, n_records);
- }
- if (execute_commit(&ndb, hugo_ops))
- {
- no_error= 0;
- break;
- }
- if(close_transaction(&ndb, hugo_ops))
- {
- no_error= 0;
- break;
- }
- } while(0);
-
- // copy events and verify
- do {
- if (copy_events(&ndb) < 0)
- {
- no_error= 0;
- break;
- }
- if (verify_copy(&ndb, pTabs, pShadowTabs))
- {
- no_error= 0;
- break;
- }
- } while (0);
-
- // update n_records-1 records in first table
- do {
- if (start_transaction(&ndb, hugo_ops))
- {
- no_error= 0;
- break;
- }
-
- hugo_ops[0]->pkUpdateRecord(&ndb, n_records-1);
-
- if (execute_commit(&ndb, hugo_ops))
- {
- no_error= 0;
- break;
- }
- if(close_transaction(&ndb, hugo_ops))
- {
- no_error= 0;
- break;
- }
- } while(0);
-
- // copy events and verify
- do {
- if (copy_events(&ndb) < 0)
- {
- no_error= 0;
- break;
- }
- if (verify_copy(&ndb, pTabs, pShadowTabs))
- {
- no_error= 0;
- break;
- }
- } while (0);
-
-
- {
- NdbRestarts restarts;
- for (int j= 0; j < 10; j++)
- {
- // restart a node
- if (no_error)
- {
- int timeout = 240;
- if (restarts.executeRestart("RestartRandomNodeAbort", timeout))
- {
- no_error= 0;
- break;
- }
- }
-
- // update all n_records records on all tables
- if (start_transaction(&ndb, hugo_ops))
- {
- no_error= 0;
- break;
- }
-
- for (int r= 0; r < n_records; r++)
- {
- for (i= 0; pTabs[i]; i++)
- {
- hugo_ops[i]->pkUpdateRecord(&ndb, r);
- }
- }
- if (execute_commit(&ndb, hugo_ops))
- {
- no_error= 0;
- break;
- }
- if(close_transaction(&ndb, hugo_ops))
- {
- no_error= 0;
- break;
- }
-
- // copy events and verify
- if (copy_events(&ndb) < 0)
- {
- no_error= 0;
- break;
- }
- if (verify_copy(&ndb, pTabs, pShadowTabs))
- {
- no_error= 0;
- break;
- }
- }
- }
-
- // drop the event operations
- for (i= 0; i < (int)pOps.size(); i++)
- {
- if (ndb.dropEventOperation(pOps[i]))
- {
- no_error= 0;
- }
- }
-
- if (no_error)
- DBUG_RETURN(NDBT_ProgramExit(NDBT_OK));
- DBUG_RETURN(NDBT_ProgramExit(NDBT_FAILED));
-}
-
-template class Vector<HugoOperations *>;
-template class Vector<NdbEventOperation *>;
-template class Vector<NdbRecAttr*>;
-template class Vector<Vector<NdbRecAttr*> >;
diff --git a/storage/ndb/test/ndbapi/userInterface.cpp b/storage/ndb/test/ndbapi/userInterface.cpp
deleted file mode 100644
index e64d89d7055..00000000000
--- a/storage/ndb/test/ndbapi/userInterface.cpp
+++ /dev/null
@@ -1,117 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-/***************************************************************
-* I N C L U D E D F I L E S *
-***************************************************************/
-
-#include <ndb_global.h>
-#include <time.h>
-
-#include "ndb_schema.hpp"
-#include "ndb_error.hpp"
-#include "userInterface.h"
-#include <NdbMutex.h>
-#include <NdbThread.h>
-#include <NdbTick.h>
-#include <NdbApi.hpp>
-#include <NdbOut.hpp>
-
-/***************************************************************
-* L O C A L C O N S T A N T S *
-***************************************************************/
-
-/***************************************************************
-* L O C A L D A T A S T R U C T U R E S *
-***************************************************************/
-
-/***************************************************************
-* L O C A L F U N C T I O N S *
-***************************************************************/
-
-#ifndef NDB_WIN32
-#include <unistd.h>
-#endif
-
-
-static NdbMutex* startupMutex = NdbMutex_Create();
-
-Ndb*
-asyncDbConnect(int parallellism){
- NdbMutex_Lock(startupMutex);
- Ndb * pNDB = new Ndb("");
-
- pNDB->init(parallellism + 1);
-
- while(pNDB->waitUntilReady() != 0){
- }
-
- NdbMutex_Unlock(startupMutex);
-
- return pNDB;
-}
-
-void
-asyncDbDisconnect(Ndb* pNDB)
-{
- delete pNDB;
-}
-
-double
-userGetTime(void)
-{
- static bool initialized = false;
- static NDB_TICKS initSecs = 0;
- static Uint32 initMicros = 0;
- double timeValue = 0;
-
- if ( !initialized ) {
- initialized = true;
- NdbTick_CurrentMicrosecond(&initSecs, &initMicros);
- timeValue = 0.0;
- } else {
- NDB_TICKS secs = 0;
- Uint32 micros = 0;
-
- NdbTick_CurrentMicrosecond(&secs, &micros);
- double s = (double)secs - (double)initSecs;
- double us = (double)micros - (double)initMicros;
-
- timeValue = s + (us / 1000000.0);
- }
- return timeValue;
-}
-
-void showTime()
-{
- char buf[128];
- struct tm* tm_now;
- time_t now;
- now = ::time((time_t*)NULL);
- tm_now = ::gmtime(&now);
-
- BaseString::snprintf(buf, 128,
- "%d-%.2d-%.2d %.2d:%.2d:%.2d",
- tm_now->tm_year + 1900,
- tm_now->tm_mon,
- tm_now->tm_mday,
- tm_now->tm_hour,
- tm_now->tm_min,
- tm_now->tm_sec);
-
- ndbout_c("Time: %s", buf);
-}
-
diff --git a/storage/ndb/test/ndbnet/test.run b/storage/ndb/test/ndbnet/test.run
deleted file mode 100644
index a00cba846ad..00000000000
--- a/storage/ndb/test/ndbnet/test.run
+++ /dev/null
@@ -1,19 +0,0 @@
-# Copyright (c) 2004, 2005 MySQL AB
-# Use is subject to license terms
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Library 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
-# Library General Public License for more details.
-#
-# You should have received a copy of the GNU Library General Public
-# License along with this library; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301, USA
-
-system("printenv|sort");
diff --git a/storage/ndb/test/ndbnet/testError.run b/storage/ndb/test/ndbnet/testError.run
deleted file mode 100644
index 8802f0150a6..00000000000
--- a/storage/ndb/test/ndbnet/testError.run
+++ /dev/null
@@ -1,284 +0,0 @@
-# Copyright (c) 2004, 2005 MySQL AB
-# Use is subject to license terms
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Library 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
-# Library General Public License for more details.
-#
-# You should have received a copy of the GNU Library General Public
-# License along with this library; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301, USA
-
-#
-# file : test/ndbnet/testError.run
-# usage: perl testError.run
-#
-# you need to have $NDB_TOP/lib/perl5 on search path $PERL5LIB
-# or else write perl -I$NDB_TOP/lib/perl5 test1.run
-#
-# The database is specified by the $NDB_DATABASE environment variable
-#
-# method names and argument style will change slightly.
-#
-#
-
-use strict;
-use NDB::Run;
-
-my $env = NDB::Run->getenv;
-my $log = $env->getlog;
-$log->setpart(time => 1, line => 0);
-$log->setprio("info");
-
-my $database = $ENV{NDB_DATABASE};
-my $api_cmd = $ENV{API_CMD};
-$log->put("start test database=$database");
-$env->init or $log->push("init failed")->fatal;
-
-my $db = $env->getdb($database) or $log->push->fatal;
-my $mgm = $db->getnode(1) or $log->push->fatal;
-my $api = $db->getnode(4) or $log->push->fatal;
-
-my @dbnode = (); # array of db nodes indexed 2..3
-for my $i (2..3) {
- $dbnode[$i] = $db->getnode($i) or $log->push->fatal;
-}
-
-# list of db nodes and errors to insert
-my @errors = ( # array of array refs
- [ 2, 9998 ],
- [ 2, 37017 ],
- [ 2, 37018 ],
- [ 2, 37017 ],
- [ 2, 37018 ],
- [ 2, 37017 ],
- [ 2, 37018 ],
- [ 2, 37017 ],
- [ 2, 37018 ],
- [ 2, 37017 ],
- [ 2, 37018 ],
- [ 2, 37017 ],
- [ 2, 9998 ],
- [ 3, 9998 ],
- [ 3, 9998 ],
- [ 2, 9998 ],
- [ 3, 9998 ],
- [ 3, 9998 ],
- [ 2, 38002 ],
- [ 2, 38002 ],
- [ 2, 8002 ],
- [ 3, 8029 ],
- [ 2, 8030 ],
- [ 2, 8031 ],
- [ 3, 8020 ],
- [ 2, 8021 ],
- [ 3, 8022 ],
- [ 2, 8023 ],
- [ 3, 8025 ],
- [ 2, 8027 ],
- [ 2, 38002 ],
- [ 3, 38029 ],
- [ 2, 38030 ],
- [ 2, 38031 ],
- [ 3, 38020 ],
- [ 2, 38021 ],
- [ 3, 38022 ],
- [ 2, 38023 ],
- [ 3, 38025 ],
- [ 2, 38027 ],
- [ 2, 48002 ],
- [ 3, 48029 ],
- [ 2, 48030 ],
- [ 2, 48031 ],
- [ 3, 48020 ],
- [ 2, 48021 ],
- [ 3, 48022 ],
- [ 2, 48023 ],
- [ 3, 48025 ],
- [ 2, 48027 ],
- [ 2, 9999 ],
- [ 3, 9999 ],
- [ 3, 9999 ],
- [ 2, 9998 ],
- [ 3, 9998 ],
- [ 3, 9998 ],
- [ 2, 9998 ],
- [ 3, 9998 ],
- [ 3, 9998 ],
- [ 3, 37000 ],
- [ 2, 37001 ],
- [ 2, 37002 ],
- [ 2, 37003 ],
- [ 2, 47005 ],
- [ 2, 47006 ],
- [ 2, 47007 ],
- [ 2, 47008 ],
- [ 2, 45000 ],
- [ 2, 37005 ],
- [ 2, 37006 ],
- [ 2, 37007 ],
- [ 2, 37008 ],
- [ 2, 35000 ],
- [ 2, 37009 ],
- [ 2, 37010 ],
- [ 2, 37013 ],
- [ 2, 37014 ],
- [ 2, 37015 ],
- [ 2, 37016 ],
- [ 2, 37017 ],
- [ 2, 37018 ],
- [ 2, 37019 ],
- [ 2, 47020 ],
- [ 2, 37020 ],
- [ 2, 48000 ],
- [ 2, 38000 ],
- [ 2, 48001 ],
- [ 2, 38001 ],
- [ 2, 45001 ],
- [ 2, 35001 ],
-);
-
-$db->kill;
-$db->start({init_rm=>1}) or $log->push->fatal;
-sleep 10;
-
-# should be option (or default) in $db->start
-sub wait_until_started {
- my $local_cnt = 60;
- while (--$local_cnt > 0) {
- sleep 2;
- my $ret = $mgm->write("all status", { wait => 3 });
- $ret or $log->fatal;
- my $output = $ret->{output};
- if ($output =~ /\bstarted\b(.|\n)*started\b/i) {
- $log->put("*** db is started ***")->info;
- return;
- }
- if ($output =~ /\bno.contact\b(.|\n)*no.contact\b/i) {
- print "NDBT_ProgramExit: 1 - test error\n";
- $log->put("*** db is dead ***")->fatal;
- }
- }
- print "NDBT_ProgramExit: 1 - test error\n";
- $log->put("*** node recovery failed ***")->fatal;
-}
-
-sub getdbstatus {
- my $ret = $mgm->write("all status", { wait => 3 });
- $ret or return undef;
- my $output = $ret->{output};
- my @status = (); # indexed 2..3
- for my $i (2..3) {
- my $s = "Unknown";
- if ($output =~ /Node\s*$i\s*:\s*(\w+)/i) {
- $s = $1;
- }#if
- $status[$i] = lc $s;
- }#for
- return \@status;
-}
-
-# count elapsed time
-my $lasttime;
-sub settime { $lasttime = time };
-sub gettime { return time - $lasttime };
-
-wait_until_started();
-$api->start({run=>$api_cmd});
-sleep 10;
-
-# loop over error inserts
-for my $e (@errors) {
-for my $loop (1..7) {
- my $i = $e->[0]; # db node number 2..3
- my $c = $e->[1]; # error code
- my $dead_node_id = $i;
- my $dbnode = $dbnode[$i];
- my $two = 2;
- my $three = 3;
- my $kill_no = 9998;
-
- $log->put("insert error $c")->push($dbnode)->notice;
-
- # insert error
- if ($c eq $kill_no) {
- $dbnode->kill
- or $log->put("Kill 1 failed")->fatal;
- } else {
- $mgm->write("$i error $c")
- or $log->put("insert error fault")->fatal;
- }#if
-
- # after a few seconds check that node is dead
- settime();
- loop: {
- gettime() <= 300
- or $log->put("db node $i refuses to die")->fatal;
- my $status = getdbstatus()
- or $log->put("getdbstatus error")->fatal;
-
- if (($status->[$two] eq 'no') && ($status->[$three] eq 'no')) {
- print "NDBT_ProgramExit: 1 - test error\n";
- $log->put("*** db is dead ***")->fatal;
- }#if
- if ($c < 10000) {
- if ($status->[$i] ne 'no') { # ...contact
- sleep 2;
- redo loop;
- }#if
- $dead_node_id = $i;
- } else {
- if (($status->[$two] eq 'no') &&
- ($status->[$three] eq 'started')) {
- $dead_node_id = 2;
- } else {
- if (($status->[$three] eq 'no') &&
- ($status->[$two] eq 'started')) {
- $dead_node_id = 3;
- } else {
- sleep 2;
- redo loop;
- }#if
- }#if
- }#if
- }#loop
-
- my $dead_node = $dbnode[$dead_node_id];
- # have to even check the process is gone
- sleep 5;
- if ($dead_node->stat ne "down") {
- $log->put("ndb did not die, kill it")->push($dead_node)->warn;
- $dead_node->kill
- or $log->put("Kill 2 failed")->fatal;
- }#if
-
- $log->put("node $dead_node_id is dead")->notice;
-
- # start the failed node
- $dead_node->start
- or $log->put("Start ndb node failed")->fatal;
-
- wait_until_started();
- $log->put("node $dead_node_id is up again")->notice;
-
- # check test pgm is running
- my $stat = $api->stat
- or $log->put("api->stat failed")->fatal;
- if ($stat ne "up") {
- print "NDBT_ProgramExit: 1 - test error\n";
- $db->kill;
- $log->put("flexBench has crashed")->fatal;
- }#if
-}#for
-}#for
-print "NDBT_ProgramExit: 0 - test ready\n";
-$db->kill;
-
-# vim: set sw=4:
diff --git a/storage/ndb/test/ndbnet/testMNF.run b/storage/ndb/test/ndbnet/testMNF.run
deleted file mode 100644
index 288e1398897..00000000000
--- a/storage/ndb/test/ndbnet/testMNF.run
+++ /dev/null
@@ -1,295 +0,0 @@
-# Copyright (c) 2004, 2005 MySQL AB
-# Use is subject to license terms
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Library 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
-# Library General Public License for more details.
-#
-# You should have received a copy of the GNU Library General Public
-# License along with this library; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301, USA
-
-#
-# file : test/ndbnet/testError.run
-# usage: perl testError.run
-#
-# you need to have $NDB_TOP/lib/perl5 on search path $PERL5LIB
-# or else write perl -I$NDB_TOP/lib/perl5 test1.run
-#
-# The database is specified by the $NDB_DATABASE environment variable
-#
-# method names and argument style will change slightly.
-#
-#
-
-use strict;
-use NDB::Run;
-
-my $env = NDB::Run->getenv;
-my $log = $env->getlog;
-$log->setpart(time => 1, line => 0);
-$log->setprio("info");
-
-my $database = $ENV{NDB_DATABASE};
-my $api_cmd = $ENV{API_CMD};
-my $api_cmd2 = $ENV{API_CMD2};
-$log->put("start test database=$database");
-$env->init or $log->push("init failed")->fatal;
-
-my $db = $env->getdb($database) or $log->push->fatal;
-my $mgm = $db->getnode(1) or $log->push->fatal;
-my $api = $db->getnode(6) or $log->push->fatal;
-my $api2 = $db->getnode(7) or $log->push->fatal;
-
-my @dbnode = (); # array of db nodes indexed 2..5
-for my $i (2..5) {
- $dbnode[$i] = $db->getnode($i) or $log->push->fatal;
-}
-
-# list of db nodes and errors to insert
-my @errors = ( # array of array refs
- [ 3, 4, 8030, 8031 ],
- [ 2, 5, 8027, 8030 ],
- [ 2, 4, 5000, 5000 ],
- [ 2, 5, 5000, 5000 ],
- [ 3, 4, 5000, 7008 ],
- [ 3, 5, 5000, 7008 ],
- [ 2, 4, 5000, 7007 ],
- [ 3, 4, 5000, 7007 ],
- [ 3, 5, 5000, 7006 ],
- [ 2, 5, 5000, 7006 ],
- [ 2, 4, 5000, 7005 ],
- [ 3, 5, 5000, 7005 ],
- [ 3, 4, 7005, 7005 ],
- [ 2, 5, 7005, 7005 ],
- [ 3, 4, 7005, 7007 ],
- [ 3, 5, 7005, 7007 ],
- [ 2, 5, 7005, 7008 ],
- [ 2, 4, 7005, 7008 ],
- [ 3, 5, 7006, 7006 ],
- [ 3, 4, 7006, 7006 ],
- [ 2, 4, 7006, 7007 ],
- [ 2, 5, 7006, 7007 ],
- [ 2, 5, 7006, 7008 ],
- [ 2, 4, 7006, 7008 ],
- [ 3, 4, 7007, 7007 ],
- [ 3, 5, 7007, 7007 ],
- [ 3, 5, 7007, 7008 ],
- [ 3, 4, 7007, 7008 ],
- [ 2, 4, 7008, 7008 ],
- [ 2, 5, 7008, 7008 ],
- [ 2, 5, 7008, 7008 ],
- [ 2, 5, 7008, 7008 ],
- [ 2, 5, 8000, 8000 ],
- [ 2, 4, 8000, 8000 ],
- [ 3, 5, 8000, 8001 ],
- [ 3, 4, 8000, 8001 ],
- [ 2, 5, 8000, 5001 ],
- [ 3, 5, 8000, 5001 ],
- [ 3, 4, 8001, 5001 ],
- [ 2, 4, 8001, 5001 ],
- [ 2, 5, 8002, 8029 ],
- [ 3, 4, 8030, 8031 ],
- [ 3, 5, 8020, 8021 ],
- [ 2, 4, 8022, 9999 ],
- [ 2, 4, 8023, 8025 ],
- [ 2, 5, 8027, 8030 ],
- [ 3, 4, 8002, 8002 ],
- [ 3, 5, 8029, 8030 ],
- [ 3, 5, 8031, 8031 ],
- [ 3, 4, 8020, 8020 ],
- [ 2, 4, 8021, 8021 ],
- [ 2, 5, 8022, 8022 ],
- [ 3, 4, 8023, 8023 ],
- [ 3, 5, 8025, 8025 ],
- [ 2, 4, 8027, 8027 ],
- [ 2, 5, 8027, 8027 ],
- [ 3, 4, 8023, 9999 ],
- [ 3, 5, 8025, 9998 ],
- [ 2, 4, 8027, 9999 ],
- [ 2, 5, 8027, 9998 ],
- [ 3, 4, 8000, 9999 ],
- [ 3, 5, 8001, 9998 ],
- [ 2, 4, 5001, 9999 ],
- [ 2, 5, 5000, 9999 ],
- [ 3, 4, 7005, 9999 ],
- [ 3, 5, 7006, 9999 ],
- [ 2, 4, 7007, 9999 ],
- [ 2, 5, 7008, 9999 ],
- [ 2, 4, 9998, 9998 ],
- [ 3, 5, 9998, 9998 ],
- [ 2, 4, 9998, 9998 ],
- [ 2, 4, 9998, 9998 ],
- [ 3, 5, 9998, 9998 ],
- [ 2, 4, 9999, 9999 ],
- [ 2, 4, 9998, 9998 ],
- [ 3, 5, 9999, 9999 ],
- [ 2, 4, 9999, 9999 ],
- [ 2, 4, 9999, 9999 ],
- [ 3, 5, 9999, 9999 ],
-);
-
-$db->kill;
-$db->start({init_rm=>1}) or $log->push->fatal;
-sleep 10;
-
-# should be option (or default) in $db->start
-sub wait_until_started {
- my $local_cnt = 60;
- while (--$local_cnt > 0) {
- sleep 5;
- my $ret = $mgm->write("all status", { wait => 3 });
- $ret or $log->fatal;
- my $output = $ret->{output};
- if ($output =~ /((.|\n)*\bstarted\b(.|\n)*){4}/i) {
- $log->put("*** db is started ***")->info;
- return;
- }
- if ($output =~ /((.|\n)*\bno.contact\b(.|\n)*){4}/i) {
- print "NDBT_ProgramExit: 1 - test error\n";
- $log->put("*** db is dead ***")->fatal;
- }
- }
- print "NDBT_ProgramExit: 1 - test error\n";
- $log->put("*** node recovery failed ***")->fatal;
-}
-
-sub getdbstatus {
- my $ret = $mgm->write("all status", { wait => 3 });
- $ret or return undef;
- my $output = $ret->{output};
- my @status = (); # indexed 2..5
- for my $i (2..5) {
- my $s = "Unknown";
- if ($output =~ /Node\s*$i\s*:\s*(\w+)/i) {
- $s = $1;
- }#if
- $status[$i] = lc $s;
- }#for
- return \@status;
-}
-
-# count elapsed time
-my $lasttime;
-sub settime { $lasttime = time };
-sub gettime { return time - $lasttime };
-
-wait_until_started();
-$api->start({run=>$api_cmd});
-sleep 15;
-$api2->start({run=>$api_cmd2});
-sleep 15;
-
-# loop over error inserts
-for my $x (0..1) {
-for my $e (@errors) {
-for my $z (0..3) {
- my $i1 = $e->[0]; # db node number 2..5
- my $i2 = $e->[1]; # db node number 2..5
- my $c1 = $e->[2]; # error code
- my $c2 = $e->[3]; # error code
- my $dbnode1 = $dbnode[$i1];
- my $dbnode2 = $dbnode[$i2];
- my $kill_no = 9998;
- my @survivor = ();
- my $survivor_count = 0;
-
- $log->put("insert error $c1 on node $i1")->push($dbnode1)->notice;
- $log->put("and insert error $c2 on node $i2")->push($dbnode2)->notice;
-
- for my $node (2..5) {
- if (($node ne $i1) && ($node ne $i2)) {
- $survivor[$survivor_count] = $node;
- $survivor_count++;
- }#if
- }#for
- # insert error
- if ($c1 eq $kill_no) {
- $dbnode1->kill
- or $log->put("Kill 1 failed")->fatal;
- } else {
- $mgm->write("$i1 error $c1")
- or $log->put("insert error 1 fault")->fatal;
- }#if
- if ($c2 eq $kill_no) {
- $dbnode2->kill
- or $log->put("Kill 2 failed")->fatal;
- } else {
- $mgm->write("$i2 error $c2")
- or $log->put("insert error 2 fault")->fatal;
- }#if
-
- # after a few seconds check that node is dead
- settime();
- loop: {
- gettime() <= 300
- or $log->put("db node $i1 or $i2 refuses to die")->fatal;
- my $status = getdbstatus()
- or $log->put("getdbstatus error")->fatal;
-
- if (($status->[$survivor[0]] eq 'no') ||
- ($status->[$survivor[1]] eq 'no')) {
- print "NDBT_ProgramExit: 1 - test error\n";
- $db->kill;
- $log->put("*** db is dead ***")->fatal;
- }#if
- if (($status->[$i1] ne 'no') || ($status->[$i2] ne 'no')) { # ...contact
- sleep 2;
- redo loop;
- }#if
- }#loop
-
- # have to even check the process is gone
- sleep 5;
- if ($dbnode1->stat ne "down") {
- $log->put("ndb did not die, kill it")->push($dbnode1)->warn;
- $dbnode1->kill
- or $log->put("Kill 3 failed")->fatal;
- }#if
- if ($dbnode2->stat ne "down") {
- $log->put("ndb did not die, kill it")->push($dbnode2)->warn;
- $dbnode2->kill
- or $log->put("Kill 4 failed")->fatal;
- }#if
-
- $log->put("node $i1 and node $i2 is dead")->notice;
-
- # start the failed nodes
- $dbnode1->start
- or $log->put("Start ndb node 1 failed")->fatal;
- $dbnode2->start
- or $log->put("Start ndb node 2 failed")->fatal;
- wait_until_started();
- $log->put("node $i1 and node $i2 is up again")->notice;
-
- # check test pgm is running
- my $stat = $api->stat
- or $log->put("api->stat failed")->fatal;
- if ($stat ne "up") {
- print "NDBT_ProgramExit: 1 - test error\n";
- sleep 15;
- $db->kill;
- $log->put("flexBench has crashed")->fatal;
- }#if
- my $stat = $api2->stat
- or $log->put("api2->stat failed")->fatal;
- if ($stat ne "up") {
- print "NDBT_ProgramExit: 1 - test error\n";
- sleep 15;
- $db->kill;
- $log->put("flexBench2 has crashed")->fatal;
- }#if
-}#for
-}#for
-}#for
-print "NDBT_ProgramExit: 0 - test ready\n";
-$db->kill;
-
-# vim: set sw=4:
diff --git a/storage/ndb/test/ndbnet/testNR.run b/storage/ndb/test/ndbnet/testNR.run
deleted file mode 100644
index 911b2fe2a4b..00000000000
--- a/storage/ndb/test/ndbnet/testNR.run
+++ /dev/null
@@ -1,76 +0,0 @@
-# Copyright (c) 2004, 2005 MySQL AB
-# Use is subject to license terms
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Library 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
-# Library General Public License for more details.
-#
-# You should have received a copy of the GNU Library General Public
-# License along with this library; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301, USA
-
-use strict;
-use NDB::Run;
-
-my $env = NDB::Run->getenv;
-my $log = $env->getlog;
-$log->setpart(time => 1, line => 0);
-$log->setprio("info");
-
-my $database = $ENV{NDB_DATABASE};
-$log->put("start test database=$database");
-$env->init or $log->push("init failed")->fatal;
-
-my $db = $env->getdb($database) or $log->push->fatal;
-my $mgm = $db->getnode(1) or $log->push->fatal;
-my $db1 = $db->getnode(2) or $log->push->fatal;
-my $db2 = $db->getnode(3) or $log->push->fatal;
-my $api = $db->getnode(4) or $log->push->fatal;
-
-$db->kill;
-$db->start({init_rm=>1}) or $db->kill, $log->push->fatal;
-sleep 10;
-
-# should be option (or default) in $db->start
-sub wait_until_started {
- my $local_cnt = 100;
- while (--$local_cnt > 0) {
- sleep 2;
- my $ret = $mgm->write("all status", { wait => 2 });
- $ret or $db->kill, $log->fatal;
- my $output = $ret->{output};
- if ($output =~ /\bstarted\b(.|\n)*started\b/i) {
- $log->put("*** db is started ***")->info;
- return;
- }
- if ($output =~ /\bno.contact\b(.|\n)*no.contact\b/i) {
- print "NDBT_ProgramExit: 1 - test error\n";
- $db->kill, $log->put("*** db is dead ***")->fatal;
- }
- }
- print "NDBT_ProgramExit: 1 - test error\n";
- $db->kill, $log->put("*** node recovery failed ***")->fatal;
-}
-
-my $cnt = 0;
-wait_until_started();
-$api->start({run=>"flexBench -t 32 -l 800"});
-while (1) {
- wait_until_started();
- sleep 2;
- my $dbx = (++$cnt % 2 == 1 ? $db1 : $db2);
- $dbx->kill or $db->kill, $log->fatal;
- sleep 2;
- $dbx->start; # start the node
-}
-
-$db->kill;
-
-# vim: set sw=4:
diff --git a/storage/ndb/test/ndbnet/testNR1.run b/storage/ndb/test/ndbnet/testNR1.run
deleted file mode 100644
index d5bc32f746b..00000000000
--- a/storage/ndb/test/ndbnet/testNR1.run
+++ /dev/null
@@ -1,79 +0,0 @@
-# Copyright (c) 2004, 2005 MySQL AB
-# Use is subject to license terms
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Library 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
-# Library General Public License for more details.
-#
-# You should have received a copy of the GNU Library General Public
-# License along with this library; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301, USA
-
-# Node recovery killing 1 node out of 4 at the time and waiting for recover
-
-use strict;
-use NDB::Run;
-
-my $env = NDB::Run->getenv;
-my $log = $env->getlog;
-$log->setpart(time => 1, line => 0);
-$log->setprio("info");
-
-my $database = $ENV{NDB_DATABASE};
-$log->put("start test database=$database");
-$env->init or $log->push("init failed")->fatal;
-
-my $db = $env->getdb($database) or $log->push->fatal;
-my $mgm = $db->getnode(1) or $log->push->fatal;
-my $db1 = $db->getnode(2) or $log->push->fatal;
-my $api = $db->getnode(6) or $log->push->fatal;
-
-$db->kill;
-$db->start({init_rm=>1}) or $log->push->fatal;
-sleep 10;
-
-# should be option (or default) in $db->start
-sub wait_until_started {
- my $local_cnt = 100;
- while (--$local_cnt > 0) {
- sleep 2;
- my $ret = $mgm->write("all status", { wait => 2 });
- $ret or $log->fatal;
- my $output = $ret->{output};
- if ($output =~ /((.|\n)*\bstarted\b(.|\n)*){1}/i) {
-# if all 4 nodes started
- $log->put("*** db is started ***")->info;
- return;
- }
- if ($output =~ /((.|\n)*\bno.contact\b(.|\n)*){1}/i) {
-#if all 4 nodes no contact
- print "NDBT_ProgramExit: 1 - test error\n";
- $log->put("*** db is dead ***")->fatal;
- }
- }
- print "NDBT_ProgramExit: 1 - test error\n";
- $log->put("*** node recovery failed ***")->fatal;
-}
-
-my $cnt = 0;
-wait_until_started();
-$api->start({run=>"flexBench -t 32 -l 800"});
-while (1) {
- wait_until_started();
- sleep 10;
- $db1->kill or $log->fatal;
- sleep 10;
- $db1->start; # start the node
- sleep 10;
-}
-
-$db->kill;
-
-# vim: set sw=4:
diff --git a/storage/ndb/test/ndbnet/testNR4.run b/storage/ndb/test/ndbnet/testNR4.run
deleted file mode 100644
index 89eece66c42..00000000000
--- a/storage/ndb/test/ndbnet/testNR4.run
+++ /dev/null
@@ -1,95 +0,0 @@
-# Copyright (c) 2004, 2005 MySQL AB
-# Use is subject to license terms
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Library 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
-# Library General Public License for more details.
-#
-# You should have received a copy of the GNU Library General Public
-# License along with this library; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301, USA
-
-# Node recovery killing 1 node out of 4 at the time and waiting for recover
-
-use strict;
-use NDB::Run;
-
-my $env = NDB::Run->getenv;
-my $log = $env->getlog;
-$log->setpart(time => 1, line => 0);
-$log->setprio("info");
-
-my $database = $ENV{NDB_DATABASE};
-$log->put("start test database=$database");
-$env->init or $log->push("init failed")->fatal;
-
-my $db = $env->getdb($database) or $log->push->fatal;
-my $mgm = $db->getnode(1) or $log->push->fatal;
-my $db1 = $db->getnode(2) or $log->push->fatal;
-my $db2 = $db->getnode(3) or $log->push->fatal;
-my $db3 = $db->getnode(4) or $log->push->fatal;
-my $db4 = $db->getnode(5) or $log->push->fatal;
-my $api = $db->getnode(6) or $log->push->fatal;
-
-$db->kill;
-$db->start({init_rm=>1}) or $log->push->fatal;
-sleep 10;
-
-# should be option (or default) in $db->start
-sub wait_until_started {
- my $local_cnt = 100;
- while (--$local_cnt > 0) {
- sleep 2;
- my $ret = $mgm->write("all status", { wait => 2 });
- $ret or $log->fatal;
- my $output = $ret->{output};
- if ($output =~ /((.|\n)*\bstarted\b(.|\n)*){4}/i) {
-# if all 4 nodes started
- $log->put("*** db is started ***")->info;
- return;
- }
- if ($output =~ /((.|\n)*\bno.contact\b(.|\n)*){4}/i) {
-#if all 4 nodes no contact
- print "NDBT_ProgramExit: 1 - test error\n";
- $log->put("*** db is dead ***")->fatal;
- }
- }
- print "NDBT_ProgramExit: 1 - test error\n";
- $log->put("*** node recovery failed ***")->fatal;
-}
-
-my $cnt = 0;
-wait_until_started();
-$api->start({run=>"flexBench -t 32 -l 800"});
-while (1) {
- wait_until_started();
- sleep 10;
- my $id = (++$cnt % 4);
- my $dbx = 0;
- if ($id eq 0) {
- $dbx = $db1;
- }
- elsif ($id eq 1) {
- $dbx = $db2;
- }
- elsif ($id eq 2) {
- $dbx = $db3;
- }
- else {
- $dbx = $db4;
- }
- $dbx->kill or $log->fatal;
- sleep 10;
- $dbx->start; # start the node
-}
-
-$db->kill;
-
-# vim: set sw=4:
diff --git a/storage/ndb/test/ndbnet/testSRhang.run b/storage/ndb/test/ndbnet/testSRhang.run
deleted file mode 100644
index 01ba4cdad71..00000000000
--- a/storage/ndb/test/ndbnet/testSRhang.run
+++ /dev/null
@@ -1,66 +0,0 @@
-# Copyright (c) 2004, 2005 MySQL AB
-# Use is subject to license terms
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Library 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
-# Library General Public License for more details.
-#
-# You should have received a copy of the GNU Library General Public
-# License along with this library; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301, USA
-
-use strict;
-use NDB::Run;
-
-my $env = NDB::Run->getenv;
-my $log = $env->getlog;
-$log->setpart(time => 1, line => 0);
-$log->setprio("info");
-
-my $database = $ENV{NDB_DATABASE};
-$log->put("start test database=$database");
-$env->init or $log->push("init failed")->fatal;
-
-my $db = $env->getdb($database) or $log->push->fatal;
-my $mgm = $db->getnode(1) or $log->push->fatal;
-
-# should be option (or default) in $db->start
-sub wait_until_started {
- my $local_cnt = 200;
- while (--$local_cnt > 0) {
- sleep 2;
- if ($local_cnt < 150) {
- my $x = $mgm->write("all dump 1", { wait => 2 });
- }#if
- my $ret = $mgm->write("all status", { wait => 2 });
- $ret or $log->fatal;
- my $output = $ret->{output};
- if ($output =~ /\bstarted\b(.|\n)*started\b/i) {
- $log->put("*** db is started ***")->info;
- return;
- }#if
- if ($output =~ /\bno.contact\b(.|\n)*no.contact\b/i) {
- print "NDBT_ProgramExit: 1 - test error\n";
- $db->kill;
- $log->put("*** db is dead ***")->fatal;
- }#if
- }#while
- print "NDBT_ProgramExit: 1 - test error\n";
- $db->kill;
- $log->put("*** initial start failed ***")->fatal;
-}#sub wait_until_started
-while (1) {
- $db->kill;
- $db->start({init_rm=>1}) or $log->push->fatal;
- sleep 10;
- wait_until_started();
-}#while
-
-# vim: set sw=4:
diff --git a/storage/ndb/test/ndbnet/testTR295.run b/storage/ndb/test/ndbnet/testTR295.run
deleted file mode 100644
index e269bc6196d..00000000000
--- a/storage/ndb/test/ndbnet/testTR295.run
+++ /dev/null
@@ -1,93 +0,0 @@
-# Copyright (c) 2004, 2005 MySQL AB
-# Use is subject to license terms
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Library 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
-# Library General Public License for more details.
-#
-# You should have received a copy of the GNU Library General Public
-# License along with this library; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301, USA
-
-# testing TR295, kill non-master when recovering in phase 4
-
-use strict;
-use NDB::Run;
-
-my $env = NDB::Run->getenv;
-my $log = $env->getlog;
-$log->setpart(time => 1, line => 0);
-$log->setprio("info");
-
-my $database = $ENV{NDB_DATABASE};
-$log->put("start test database=$database");
-$env->init or $log->push("init failed")->fatal;
-
-my $db = $env->getdb($database) or $log->push->fatal;
-my $mgm = $db->getnode(1) or $log->push->fatal;
-my $db1 = $db->getnode(2) or $log->push->fatal;
-my $db2 = $db->getnode(3) or $log->push->fatal;
-
-$db->kill;
-$db->start({init_rm=>1}) or $log->push->fatal;
-sleep 10;
-
-# should be option (or default) in $db->start
-sub wait_until_started {
- my $local_cnt = 100;
- while (--$local_cnt > 0) {
- sleep 2;
- my $ret = $mgm->write("all status", { wait => 2 });
- $ret or $log->fatal;
- my $output = $ret->{output};
- if ($output =~ /\bstarted\b(.|\n)*started\b/i) {
- $log->put("*** db is started ***")->info;
- return;
- }
- if ($output =~ /\bno.contact\b(.|\n)*no.contact\b/i) {
- print "NDBT_ProgramExit: 1 - test error\n";
- $log->put("*** db is dead ***")->fatal;
- # Maybe try a system restart?
- }
- }
- print "NDBT_ProgramExit: 1 - test error\n";
- $log->put("*** node recovery failed ***")->fatal;
-}
-sub wait_until_phase4_and_kill {
-# kill db2 as quick as possible when it has reached phase4
-my $cnt = 1000;
- while (--$cnt > 0) {
- my $ret = $mgm->write("3 status", {wait => 0});
- #$ret or log->fatal;
- my $output = $ret->{output};
- if ($output =~ /\bphase 4\b/i) {
- $db2->kill or log->fatal;
- return;
- }
- }
- print "NDBT_ProgramExit: 1 -test error\n";
- $log->put("*** node restart failed after 1000 loops ***")->fatal;
-}
-
-my $cnt = 0;
-wait_until_started();
-while (1) {
- wait_until_started();
- sleep 2;
- $db2->kill or $log->fatal;
- $db2->start; # start the node
- wait_until_phase4_and_kill();
- sleep 10;
- $db2->start;
-}
-
-$db->kill;
-
-# vim: set sw=4:
diff --git a/storage/ndb/test/newtonapi/basic_test/Makefile b/storage/ndb/test/newtonapi/basic_test/Makefile
deleted file mode 100644
index d7eaf984b12..00000000000
--- a/storage/ndb/test/newtonapi/basic_test/Makefile
+++ /dev/null
@@ -1,25 +0,0 @@
-include .defs.mk
-
-TYPE := util
-
-PIC_ARCHIVE := Y
-ARCHIVE_TARGET := newtonbasictestcommon
-
-A_LIB := Y
-SO_LIB := Y
-PIC_LIB := Y
-
-LIB_TARGET := NEWTON_BASICTEST_COMMON
-LIB_TARGET_ARCHIVES := $(ARCHIVE_TARGET) NEWTON_API
-
-
-SOURCES = common.cpp
-
-DIRS := basic \
- ptr_binding \
- bulk_read
-
-CCFLAGS_LOC := -I$(call fixpath,$(NDB_TOP)/include/util) -I$(call fixpath,$(NDB_TOP)/include/newtonapi)
-
-include $(NDB_TOP)/Epilogue.mk
-
diff --git a/storage/ndb/test/newtonapi/basic_test/basic/Makefile b/storage/ndb/test/newtonapi/basic_test/basic/Makefile
deleted file mode 100644
index 7e2945d2e5f..00000000000
--- a/storage/ndb/test/newtonapi/basic_test/basic/Makefile
+++ /dev/null
@@ -1,14 +0,0 @@
-include .defs.mk
-
-TYPE := ndbapitest
-
-BIN_TARGET := newton_basic
-BIN_TARGET_LIBS :=
-BIN_TARGET_ARCHIVES := NEWTON_BASICTEST_COMMON NEWTON_API
-SOURCES := basic.cpp
-
-CCFLAGS_LOC := -I.. -I$(call fixpath,$(NDB_TOP)/include/util) -I$(call fixpath,$(NDB_TOP)/include/newtonapi) -I$(call fixpath,$(NDB_TOP)/include/portlib)
-
-include $(NDB_TOP)/Epilogue.mk
-
-
diff --git a/storage/ndb/test/newtonapi/basic_test/basic/basic.cpp b/storage/ndb/test/newtonapi/basic_test/basic/basic.cpp
deleted file mode 100644
index 2cb40120b38..00000000000
--- a/storage/ndb/test/newtonapi/basic_test/basic/basic.cpp
+++ /dev/null
@@ -1,321 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-
-/****** THIS LINE IS 80 CHARACTERS WIDE - DO *NOT* EXCEED 80 CHARACTERS! ****/
-extern "C" {
-#include <dba.h>
-}
-
-#include "common.hpp"
-
-#include <NdbOut.hpp>
-#include <NdbSleep.h>
-#include <NdbMain.h>
-
-static const
-DBA_ColumnDesc_t EmpColDesc[] = {
- { "emp_no", DBA_INT, PCN_SIZE_OF( Employee, EmpNo ), PCN_TRUE },
- { "first_name", DBA_CHAR, PCN_SIZE_OF( Employee, FirstName ), PCN_FALSE },
- { "last_name", DBA_CHAR, PCN_SIZE_OF( Employee, LastName ), PCN_FALSE }
-};
-
-static const
-DBA_ColumnDesc_t AddColDesc[] = {
- { "emp_no", DBA_INT, PCN_SIZE_OF( Address, EmpNo ), PCN_TRUE },
- { "street_name", DBA_CHAR, PCN_SIZE_OF( Address, StreetName ), PCN_FALSE},
- { "street_no", DBA_INT, PCN_SIZE_OF( Address, StreetNo ), PCN_FALSE},
- { "city", DBA_CHAR, PCN_SIZE_OF( Address, City ), PCN_FALSE}
-} ;
-
-static const
-DBA_ColumnBinding_t EmpBindings[] = {
- DBA_BINDING( "emp_no", DBA_INT, Employee, EmpNo ),
- DBA_BINDING( "last_name", DBA_CHAR, Employee, LastName ),
- DBA_BINDING( "first_name", DBA_CHAR, Employee, FirstName)
-};
-
-static const
-DBA_ColumnBinding_t AddBindings[] = {
- DBA_BINDING( "emp_no", DBA_INT, Address, EmpNo ),
- DBA_BINDING( "street_name", DBA_CHAR, Address, StreetName ),
- DBA_BINDING( "street_no", DBA_INT, Address, StreetNo ),
- DBA_BINDING( "city", DBA_CHAR, Address, City )
-};
-
-static DBA_Binding_t * EmpB;
-static DBA_Binding_t * AddB;
-
-static const int Rows = 6;
-
-static
-Employee_t EMP_TABLE_DATA[] = {
- { 1242, "Joe", "Dalton" },
- { 123, "Lucky", "Luke" },
- { 456, "Averell", "Dalton" },
- { 8976, "Gaston", "Lagaffe" },
- { 1122, "Jolly", "Jumper" },
- { 3211, "Leffe", "Pagrotsky" }
-};
-
-static
-Employee_t EMP_TABLE_DATA_READ[] = {
- { 1242, "", "" },
- { 123, "", "" },
- { 456, "", "" },
- { 8976, "", "" },
- { 1122, "", "" },
- { 3211, "", "" }
-};
-
-static
-Address_t ADD_TABLE_DATA[] = {
- { 1242, "Lonesome Street", 12, "Crime Town" },
- { 123, "Pistol Road", 13, "Fort Mount" },
- { 456, "Banking Blv.", 43, "Las Vegas" },
- { 8976, "ChancylleZee", 54, "Paris" },
- { 1122, "Lucky", 111, "Wild West" },
- { 3211, "Parlament St.", 11, "Stockholm" }
-};
-
-static
-Address_t ADD_TABLE_DATA_READ[] = {
- { 1242, "", 0, "" },
- { 123, "", 0, "" },
- { 456, "", 0, "" },
- { 8976, "", 0, "" },
- { 1122, "", 0, "" },
- { 3211, "", 0, "" }
-};
-
-static const char EMP_TABLE[] = "employees";
-static const char ADD_TABLE[] = "addresses";
-
-static const int EmpNbCol = 3;
-static const int AddNbCol = 4;
-
-static
-void
-DbCreate(void){
-
- ndbout << "Opening database" << endl;
- require( DBA_Open() == DBA_NO_ERROR );
-
- ndbout << "Creating tables" << endl;
- require( DBA_CreateTable( EMP_TABLE, EmpNbCol, EmpColDesc ) == DBA_NO_ERROR );
- require( DBA_CreateTable( ADD_TABLE, AddNbCol, AddColDesc ) == DBA_NO_ERROR );
-
- ndbout << "Checking for table existance" << endl;
- require( DBA_TableExists( EMP_TABLE ) );
- require( DBA_TableExists( ADD_TABLE ) );
-}
-
-static
-void
-CreateBindings(void){
- ndbout << "Creating bindings" << endl;
-
- EmpB = DBA_CreateBinding(EMP_TABLE,
- EmpNbCol,
- EmpBindings,
- sizeof(Employee_t) );
- require(EmpB != 0);
-
- AddB = DBA_CreateBinding(ADD_TABLE,
- AddNbCol,
- AddBindings,
- sizeof(Address_t) );
- require(AddB != 0);
-}
-
-extern "C" {
- static void insertCallback( DBA_ReqId_t, DBA_Error_t, DBA_ErrorCode_t );
- static void deleteCallback( DBA_ReqId_t, DBA_Error_t, DBA_ErrorCode_t );
- static void updateCallback( DBA_ReqId_t, DBA_Error_t, DBA_ErrorCode_t );
- static void readCallback ( DBA_ReqId_t, DBA_Error_t, DBA_ErrorCode_t );
- static void writeCallback ( DBA_ReqId_t, DBA_Error_t, DBA_ErrorCode_t );
-}
-
-static
-void BasicArray(){
- ndbout << "Testing basic array operations" << endl;
-
- // Basic insert
- DBA_ArrayInsertRows(EmpB, EMP_TABLE_DATA, Rows-2, insertCallback);
- NdbSleep_SecSleep(1);
- DBA_ArrayReadRows(EmpB, EMP_TABLE_DATA_READ, Rows-2, readCallback);
- NdbSleep_SecSleep(1);
- CompareRows(EMP_TABLE_DATA, Rows-2, EMP_TABLE_DATA_READ);
-
- // Basic update
- AlterRows(EMP_TABLE_DATA, Rows-2);
- DBA_ArrayUpdateRows(EmpB, EMP_TABLE_DATA, Rows-2, updateCallback);
- NdbSleep_SecSleep(1);
- DBA_ArrayReadRows(EmpB, EMP_TABLE_DATA_READ, Rows-2, readCallback);
- NdbSleep_SecSleep(1);
- CompareRows(EMP_TABLE_DATA, Rows-2, EMP_TABLE_DATA_READ);
-
- // Basic write
- AlterRows(EMP_TABLE_DATA, Rows);
- DBA_ArrayWriteRows(EmpB, EMP_TABLE_DATA, Rows, writeCallback);
- NdbSleep_SecSleep(1);
- DBA_ArrayReadRows(EmpB, EMP_TABLE_DATA_READ, Rows, readCallback);
- NdbSleep_SecSleep(1);
- CompareRows(EMP_TABLE_DATA, Rows, EMP_TABLE_DATA_READ);
-
- // Basic delete
- DBA_ArrayDeleteRows(EmpB, EMP_TABLE_DATA, Rows, deleteCallback);
- NdbSleep_SecSleep(1);
-}
-
-static
-void Multi(){
- ndbout << "Testing multi operations" << endl;
-
- const int R2 = Rows + Rows;
-
- DBA_Binding_t * Bindings[R2];
- void * DATA[R2];
- void * DATA_READ[R2];
- for(int i = 0; i<Rows; i++){
- Bindings[2*i] = EmpB;
- Bindings[2*i+1] = AddB;
-
- DATA[2*i] = &EMP_TABLE_DATA[i];
- DATA[2*i+1] = &ADD_TABLE_DATA[i];
-
- DATA_READ[2*i] = &EMP_TABLE_DATA_READ[i];
- DATA_READ[2*i+1] = &ADD_TABLE_DATA_READ[i];
- }
-
- // Basic insert
- DBA_MultiInsertRow(Bindings, DATA, R2-4, insertCallback);
- NdbSleep_SecSleep(1);
- DBA_MultiReadRow (Bindings, DATA_READ, R2-4, readCallback);
- NdbSleep_SecSleep(1);
-
- CompareRows(EMP_TABLE_DATA, Rows-2, EMP_TABLE_DATA_READ);
- CompareRows(ADD_TABLE_DATA, Rows-2, ADD_TABLE_DATA_READ);
-
- // Basic update
- AlterRows(EMP_TABLE_DATA, Rows-2);
- AlterRows(ADD_TABLE_DATA, Rows-2);
- DBA_MultiUpdateRow(Bindings, DATA, R2-4, updateCallback);
- NdbSleep_SecSleep(1);
- DBA_MultiReadRow (Bindings, DATA_READ, R2-4, readCallback);
- NdbSleep_SecSleep(1);
- CompareRows(EMP_TABLE_DATA, Rows-2, EMP_TABLE_DATA_READ);
- CompareRows(ADD_TABLE_DATA, Rows-2, ADD_TABLE_DATA_READ);
-
- // Basic write
- AlterRows(EMP_TABLE_DATA, Rows);
- AlterRows(ADD_TABLE_DATA, Rows);
- DBA_MultiWriteRow(Bindings, DATA, R2, writeCallback);
- NdbSleep_SecSleep(1);
- DBA_MultiReadRow (Bindings, DATA_READ, R2, readCallback);
- NdbSleep_SecSleep(1);
- CompareRows(EMP_TABLE_DATA, Rows, EMP_TABLE_DATA_READ);
- CompareRows(ADD_TABLE_DATA, Rows, ADD_TABLE_DATA_READ);
-
- // Basic delete
- DBA_MultiDeleteRow(Bindings, DATA, R2, deleteCallback);
- NdbSleep_SecSleep(1);
-}
-
-static
-void BasicPtr(){
- ndbout << "Testing array of pointer operations" << endl;
- Employee_t * EmpData[Rows];
- Employee_t * EmpDataRead[Rows];
- for(int i = 0; i<Rows; i++){
- EmpData[i] = &EMP_TABLE_DATA[i];
- EmpDataRead[i] = &EMP_TABLE_DATA_READ[i];
- }
-
- void * const * EMP_TABLE_DATA2 = (void * const *)EmpData;
- void * const * EMP_TABLE_DATA_READ2 = (void * const *)EmpDataRead;
-
- // Basic insert
- DBA_InsertRows(EmpB, EMP_TABLE_DATA2, Rows-2, insertCallback);
- NdbSleep_SecSleep(1);
- DBA_ReadRows (EmpB, EMP_TABLE_DATA_READ2, Rows-2, readCallback);
- NdbSleep_SecSleep(1);
- CompareRows(EMP_TABLE_DATA, Rows-2, EMP_TABLE_DATA_READ);
-
- // Basic update
- AlterRows(EMP_TABLE_DATA, Rows-2);
- DBA_UpdateRows(EmpB, EMP_TABLE_DATA2, Rows-2, updateCallback);
- NdbSleep_SecSleep(1);
- DBA_ReadRows (EmpB, EMP_TABLE_DATA_READ2, Rows-2, readCallback);
- NdbSleep_SecSleep(1);
- CompareRows(EMP_TABLE_DATA, Rows-2, EMP_TABLE_DATA_READ);
-
- // Basic write
- AlterRows (EMP_TABLE_DATA, Rows);
- DBA_WriteRows(EmpB, EMP_TABLE_DATA2, Rows, writeCallback);
- NdbSleep_SecSleep(1);
- DBA_ReadRows (EmpB, EMP_TABLE_DATA_READ2, Rows, readCallback);
- NdbSleep_SecSleep(1);
- CompareRows(EMP_TABLE_DATA, Rows, EMP_TABLE_DATA_READ);
-
- // Basic delete
- DBA_DeleteRows(EmpB, EMP_TABLE_DATA2, Rows, deleteCallback);
- NdbSleep_SecSleep(1);
-}
-
-/*---------------------------------------------------------------------------*/
-NDB_COMMAND(newton_basic, "newton_basic",
- "newton_basic", "newton_basic", 65535){
-
- DbCreate();
- CreateBindings();
-
- BasicArray();
- BasicPtr();
- Multi();
-
- DBA_Close();
-
- return 0;
-}
-
-
-
-/**
- * callbackStatusCheck checks whether or not the operation succeeded
- */
-void
-callbackStatusCheck( DBA_Error_t status, const char* operation) {
- ndbout_c("%s: %d", operation, status);
-}
-
-void insertCallback( DBA_ReqId_t, DBA_Error_t s, DBA_ErrorCode_t ){
- callbackStatusCheck(s, "insert");
-}
-void deleteCallback( DBA_ReqId_t, DBA_Error_t s, DBA_ErrorCode_t ){
- callbackStatusCheck(s, "delete");
-}
-void updateCallback( DBA_ReqId_t, DBA_Error_t s, DBA_ErrorCode_t ){
- callbackStatusCheck(s, "update");
-}
-void readCallback ( DBA_ReqId_t, DBA_Error_t s, DBA_ErrorCode_t ){
- callbackStatusCheck(s, "read");
-}
-void writeCallback ( DBA_ReqId_t, DBA_Error_t s, DBA_ErrorCode_t ){
- callbackStatusCheck(s, "write");
-}
-
diff --git a/storage/ndb/test/newtonapi/basic_test/bulk_read/Makefile b/storage/ndb/test/newtonapi/basic_test/bulk_read/Makefile
deleted file mode 100644
index c45bbad7957..00000000000
--- a/storage/ndb/test/newtonapi/basic_test/bulk_read/Makefile
+++ /dev/null
@@ -1,14 +0,0 @@
-include .defs.mk
-
-TYPE := ndbapitest
-
-BIN_TARGET := newton_br
-BIN_TARGET_LIBS :=
-BIN_TARGET_ARCHIVES := NEWTON_BASICTEST_COMMON NEWTON_API
-SOURCES := br_test.cpp
-
-CCFLAGS_LOC := -I.. -I$(call fixpath,$(NDB_TOP)/include/util) -I$(call fixpath,$(NDB_TOP)/include/newtonapi) -I$(call fixpath,$(NDB_TOP)/include/portlib)
-
-include $(NDB_TOP)/Epilogue.mk
-
-
diff --git a/storage/ndb/test/newtonapi/basic_test/bulk_read/br_test.cpp b/storage/ndb/test/newtonapi/basic_test/bulk_read/br_test.cpp
deleted file mode 100644
index 5b5d7c96336..00000000000
--- a/storage/ndb/test/newtonapi/basic_test/bulk_read/br_test.cpp
+++ /dev/null
@@ -1,262 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-
-/****** THIS LINE IS 80 CHARACTERS WIDE - DO *NOT* EXCEED 80 CHARACTERS! ****/
-extern "C" {
-#include <dba.h>
-}
-
-#include "common.hpp"
-
-#include <NdbOut.hpp>
-#include <NdbSleep.h>
-#include <NdbMain.h>
-
-static const
-DBA_ColumnDesc_t EmpColDesc[] = {
- { "emp_no", DBA_INT, PCN_SIZE_OF( Employee, EmpNo ), PCN_TRUE },
- { "first_name", DBA_CHAR, PCN_SIZE_OF( Employee, FirstName ), PCN_FALSE },
- { "last_name", DBA_CHAR, PCN_SIZE_OF( Employee, LastName ), PCN_FALSE }
-};
-
-static const
-DBA_ColumnDesc_t AddColDesc[] = {
- { "emp_no", DBA_INT, PCN_SIZE_OF( Address, EmpNo ), PCN_TRUE },
- { "street_name", DBA_CHAR, PCN_SIZE_OF( Address, StreetName ), PCN_FALSE},
- { "street_no", DBA_INT, PCN_SIZE_OF( Address, StreetNo ), PCN_FALSE},
- { "city", DBA_CHAR, PCN_SIZE_OF( Address, City ), PCN_FALSE}
-} ;
-
-static const
-DBA_ColumnBinding_t EmpBindings[] = {
- DBA_BINDING( "emp_no", DBA_INT, Employee, EmpNo ),
- DBA_BINDING( "last_name", DBA_CHAR, Employee, LastName ),
- DBA_BINDING( "first_name", DBA_CHAR, Employee, FirstName)
-};
-
-static const
-DBA_ColumnBinding_t AddBindings[] = {
- DBA_BINDING( "emp_no", DBA_INT, Address, EmpNo ),
- DBA_BINDING( "street_name", DBA_CHAR, Address, StreetName ),
- DBA_BINDING( "street_no", DBA_INT, Address, StreetNo ),
- DBA_BINDING( "city", DBA_CHAR, Address, City )
-};
-
-static DBA_Binding_t * EmpB;
-static DBA_Binding_t * AddB;
-
-static const int Rows = 6;
-
-static
-Employee_t EMP_TABLE_DATA[] = {
- { 1242, "Joe", "Dalton" },
- { 123, "Lucky", "Luke" },
- { 456, "Averell", "Dalton" },
- { 8976, "Gaston", "Lagaffe" },
- { 1122, "Jolly", "Jumper" },
- { 3211, "Leffe", "Pagrotsky" }
-};
-
-static
-Employee_t EMP_TABLE_DATA_READ[] = {
- { 1242, "", "" },
- { 123, "", "" },
- { 456, "", "" },
- { 8976, "", "" },
- { 1122, "", "" },
- { 3211, "", "" }
-};
-
-static
-Address_t ADD_TABLE_DATA[] = {
- { 1242, "Lonesome Street", 12, "Crime Town" },
- { 123, "Pistol Road", 13, "Fort Mount" },
- { 456, "Banking Blv.", 43, "Las Vegas" },
- { 8976, "ChancylleZee", 54, "Paris" },
- { 1122, "Lucky", 111, "Wild West" },
- { 3211, "Parlament St.", 11, "Stockholm" }
-};
-
-static
-Address_t ADD_TABLE_DATA_READ[] = {
- { 1242, "", 0, "" },
- { 123, "", 0, "" },
- { 456, "", 0, "" },
- { 8976, "", 0, "" },
- { 1122, "", 0, "" },
- { 3211, "", 0, "" }
-};
-
-static const char EMP_TABLE[] = "employees";
-static const char ADD_TABLE[] = "addresses";
-
-static const int EmpNbCol = 3;
-static const int AddNbCol = 4;
-
-static
-void
-DbCreate(void){
-
- ndbout << "Opening database" << endl;
- require( DBA_Open() == DBA_NO_ERROR );
-
- ndbout << "Creating tables" << endl;
- require( DBA_CreateTable( EMP_TABLE, EmpNbCol, EmpColDesc ) == DBA_NO_ERROR );
- require( DBA_CreateTable( ADD_TABLE, AddNbCol, AddColDesc ) == DBA_NO_ERROR );
-
- ndbout << "Checking for table existance" << endl;
- require( DBA_TableExists( EMP_TABLE ) );
- require( DBA_TableExists( ADD_TABLE ) );
-}
-
-static
-void
-CreateBindings(void){
- ndbout << "Creating bindings" << endl;
-
- EmpB = DBA_CreateBinding(EMP_TABLE,
- EmpNbCol,
- EmpBindings,
- sizeof(Employee_t) );
- require(EmpB != 0);
-
- AddB = DBA_CreateBinding(ADD_TABLE,
- AddNbCol,
- AddBindings,
- sizeof(Address_t) );
- require(AddB != 0);
-}
-
-int
-CountRows(DBA_BulkReadResultSet_t * rs, int count){
- int res = 0;
- for(int i = 0; i<count; i++)
- if(rs[i].RowFoundIndicator)
- res++;
- return res;
-}
-
-extern "C" {
- static void insertCallback( DBA_ReqId_t, DBA_Error_t, DBA_ErrorCode_t );
- static void deleteCallback( DBA_ReqId_t, DBA_Error_t, DBA_ErrorCode_t );
- static void updateCallback( DBA_ReqId_t, DBA_Error_t, DBA_ErrorCode_t );
- static void readCallback ( DBA_ReqId_t, DBA_Error_t, DBA_ErrorCode_t );
- static void writeCallback ( DBA_ReqId_t, DBA_Error_t, DBA_ErrorCode_t );
-}
-
-static
-void Multi(){
- ndbout << "Testing multi operations" << endl;
-
- DBA_ArrayInsertRows(EmpB, EMP_TABLE_DATA, Rows-2, insertCallback);
- DBA_ArrayInsertRows(AddB, ADD_TABLE_DATA, Rows-2, insertCallback);
- NdbSleep_SecSleep(1);
-
- const int R2 = Rows + Rows;
-
- DBA_Binding_t * Bindings[2];
- DBA_BulkReadResultSet_t DataRead[R2];
-
- Bindings[0] = EmpB;
- Bindings[1] = AddB;
-
- for(int i = 0; i<Rows; i++)
- DataRead[i].DataPtr = &EMP_TABLE_DATA_READ[i];
-
- for(int i = 0; i<Rows; i++)
- DataRead[i+Rows].DataPtr = &ADD_TABLE_DATA_READ[i];
-
- NdbSleep_SecSleep(1);
-
- DBA_BulkMultiReadRows(Bindings, DataRead, 2, Rows, readCallback);
- NdbSleep_SecSleep(1);
- CompareRows(EMP_TABLE_DATA, Rows-2, EMP_TABLE_DATA_READ);
- CompareRows(ADD_TABLE_DATA, Rows-2, ADD_TABLE_DATA_READ);
-
- require(CountRows(DataRead, R2) == (R2-4));
-
- // Basic delete
- DBA_ArrayDeleteRows(EmpB, EMP_TABLE_DATA, Rows-2, deleteCallback);
- DBA_ArrayDeleteRows(AddB, ADD_TABLE_DATA, Rows-2, deleteCallback);
- NdbSleep_SecSleep(1);
-}
-
-static
-void BasicPtr(){
- ndbout << "Testing array of pointer operations" << endl;
-
- // Basic insert
- DBA_ArrayInsertRows(EmpB, EMP_TABLE_DATA, Rows-2, insertCallback);
- NdbSleep_SecSleep(1);
-
- DBA_BulkReadResultSet_t EmpDataRead[Rows];
- for(int i = 0; i<Rows; i++){
- EmpDataRead[i].DataPtr = &EMP_TABLE_DATA_READ[i];
- }
-
- DBA_BulkReadRows(EmpB, EmpDataRead, Rows, readCallback);
- NdbSleep_SecSleep(1);
- CompareRows(EMP_TABLE_DATA, Rows-2, EMP_TABLE_DATA_READ);
- require(CountRows(EmpDataRead, Rows) == (Rows-2));
-
- // Basic delete
- DBA_ArrayDeleteRows(EmpB, EMP_TABLE_DATA, Rows-2, deleteCallback);
- NdbSleep_SecSleep(1);
-}
-
-/*---------------------------------------------------------------------------*/
-NDB_COMMAND(newton_br, "newton_br",
- "newton_br", "newton_br", 65535){
-
- DbCreate();
- CreateBindings();
-
- BasicPtr();
- Multi();
-
- DBA_Close();
-
- return 0;
-}
-
-
-
-/**
- * callbackStatusCheck checks whether or not the operation succeeded
- */
-void
-callbackStatusCheck( DBA_Error_t status, const char* operation) {
- ndbout_c("%s: %d", operation, status);
-}
-
-void insertCallback( DBA_ReqId_t, DBA_Error_t s, DBA_ErrorCode_t ){
- callbackStatusCheck(s, "insert");
-}
-void deleteCallback( DBA_ReqId_t, DBA_Error_t s, DBA_ErrorCode_t ){
- callbackStatusCheck(s, "delete");
-}
-void updateCallback( DBA_ReqId_t, DBA_Error_t s, DBA_ErrorCode_t ){
- callbackStatusCheck(s, "update");
-}
-void readCallback ( DBA_ReqId_t, DBA_Error_t s, DBA_ErrorCode_t ){
- callbackStatusCheck(s, "read");
-}
-void writeCallback ( DBA_ReqId_t, DBA_Error_t s, DBA_ErrorCode_t ){
- callbackStatusCheck(s, "write");
-}
-
diff --git a/storage/ndb/test/newtonapi/basic_test/common.cpp b/storage/ndb/test/newtonapi/basic_test/common.cpp
deleted file mode 100644
index 81065dae79b..00000000000
--- a/storage/ndb/test/newtonapi/basic_test/common.cpp
+++ /dev/null
@@ -1,133 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-#include "common.hpp"
-
-NdbOut &
-operator << (NdbOut & out, const Employee_t & emp){
- out << emp.EmpNo << " \"" << emp.FirstName << "\" \""
- << emp.LastName << "\"";
- return out;
-}
-
-bool
-operator==(const Employee_t & e1, const Employee_t & e2){
- if(e1.EmpNo != e2.EmpNo)
- return false;
- if(strcmp(e1.FirstName, e2.FirstName) != 0)
- return false;
- return strcmp(e1.LastName, e2.LastName) == 0;
-}
-
-void
-Alter(Employee_t & emp){
- static int updown = 0;
- if(updown == 0){
- for(int i = 0; i<strlen(emp.FirstName); i++)
- toupper(emp.FirstName[i]);
-
- for(int i = 0; i<strlen(emp.LastName); i++)
- toupper(emp.LastName[i]);
- } else {
- for(int i = 0; i<strlen(emp.FirstName); i++)
- tolower(emp.FirstName[i]);
-
- for(int i = 0; i<strlen(emp.LastName); i++)
- tolower(emp.LastName[i]);
- }
- updown = 1 - updown;
-}
-
-void
-CompareRows(Employee_t * data1,
- int rows,
- Employee_t * data2){
- for(int i = 0; i<rows; i++){
- if(!(data1[i] == data2[i])){
- ndbout << data1[i] << endl
- << data2[i] << endl;
- }
- }
-}
-
-void
-AlterRows(Employee_t * data1, int rows){
- for(int i = 0; i<rows; i++){
- Alter(data1[i]);
- }
-}
-
-inline
-NdbOut &
-operator << (NdbOut & out, const Address_t & adr){
- out << adr.EmpNo << " \"" << adr.StreetName << "\" "
- << adr.StreetNo << " \"" << adr.City << "\"";
- return out;
-}
-
-inline
-bool
-operator==(const Address_t & a1, const Address_t & a2){
- if(a1.EmpNo != a2.EmpNo)
- return false;
- if(a1.StreetNo != a2.StreetNo)
- return false;
- if(strcmp(a1.StreetName, a2.StreetName) != 0)
- return false;
- return strcmp(a1.City, a2.City) == 0;
-}
-
-inline
-void
-Alter(Address_t & emp){
- static int updown = 0;
- if(updown == 0){
- for(int i = 0; i<strlen(emp.StreetName); i++)
- toupper(emp.StreetName[i]);
-
- for(int i = 0; i<strlen(emp.City); i++)
- toupper(emp.City[i]);
- } else {
- for(int i = 0; i<strlen(emp.StreetName); i++)
- tolower(emp.StreetName[i]);
-
- for(int i = 0; i<strlen(emp.City); i++)
- tolower(emp.City[i]);
- }
- emp.StreetNo *= emp.EmpNo;
- updown = 1 - updown;
-}
-
-void
-CompareRows(Address_t * data1,
- int rows,
- Address_t * data2){
- for(int i = 0; i<rows; i++){
- if(!(data1[i] == data2[i])){
- ndbout << data1[i] << endl
- << data2[i] << endl;
- }
- }
-}
-
-void
-AlterRows(Address_t * data1, int rows){
- for(int i = 0; i<rows; i++){
- Alter(data1[i]);
- }
-}
-
diff --git a/storage/ndb/test/newtonapi/basic_test/common.hpp b/storage/ndb/test/newtonapi/basic_test/common.hpp
deleted file mode 100644
index 8def1084828..00000000000
--- a/storage/ndb/test/newtonapi/basic_test/common.hpp
+++ /dev/null
@@ -1,66 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef COMMON_H
-#define COMMON_H
-
-#include <ndb_global.h>
-
-extern "C" {
-#include <dba.h>
-}
-
-#include <NdbOut.hpp>
-
-typedef struct Employee {
- UInt32_t EmpNo;
- char FirstName[24];
- char LastName[24];
-
- struct Address * EmployeeAddress;
-} Employee_t;
-
-typedef struct Address {
- UInt32_t EmpNo;
- char StreetName[24];
- UInt32_t StreetNo;
- char City[12];
-} Address_t;
-
-/**
- * Employee functions
- */
-NdbOut & operator << (NdbOut & out, const Employee_t & emp);
-bool operator==(const Employee_t & e1, const Employee_t & e2);
-void Alter(Employee_t & emp);
-void CompareRows(Employee_t * data1, int rows, Employee_t * data2);
-void AlterRows(Employee_t * data1, int rows);
-
-/**
- * Address functions
- */
-NdbOut & operator << (NdbOut & out, const Address_t & adr);
-bool operator==(const Address_t & a1, const Address_t & a2);
-void Alter(Address_t & emp);
-void CompareRows(Address_t * data1, int rows, Address_t * data2);
-void AlterRows(Address_t * data1, int rows);
-
-inline void require(bool test){
- if(!test)
- abort();
-}
-
-#endif
diff --git a/storage/ndb/test/newtonapi/basic_test/ptr_binding/Makefile b/storage/ndb/test/newtonapi/basic_test/ptr_binding/Makefile
deleted file mode 100644
index 95e87d47e62..00000000000
--- a/storage/ndb/test/newtonapi/basic_test/ptr_binding/Makefile
+++ /dev/null
@@ -1,14 +0,0 @@
-include .defs.mk
-
-TYPE := ndbapitest
-
-BIN_TARGET := newton_pb
-BIN_TARGET_LIBS :=
-BIN_TARGET_ARCHIVES := NEWTON_BASICTEST_COMMON NEWTON_API
-SOURCES := ptr_binding_test.cpp
-
-CCFLAGS_LOC := -I.. -I$(call fixpath,$(NDB_TOP)/include/util) -I$(call fixpath,$(NDB_TOP)/include/newtonapi) -I$(call fixpath,$(NDB_TOP)/include/portlib)
-
-include $(NDB_TOP)/Epilogue.mk
-
-
diff --git a/storage/ndb/test/newtonapi/basic_test/ptr_binding/ptr_binding_test.cpp b/storage/ndb/test/newtonapi/basic_test/ptr_binding/ptr_binding_test.cpp
deleted file mode 100644
index 0b22ea9e9a3..00000000000
--- a/storage/ndb/test/newtonapi/basic_test/ptr_binding/ptr_binding_test.cpp
+++ /dev/null
@@ -1,264 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-
-/****** THIS LINE IS 80 CHARACTERS WIDE - DO *NOT* EXCEED 80 CHARACTERS! ****/
-extern "C" {
-#include <dba.h>
-}
-
-#include "common.hpp"
-
-#include <NdbOut.hpp>
-#include <NdbSleep.h>
-#include <NdbMain.h>
-
-static const
-DBA_ColumnDesc_t ColDesc[] = {
- { "emp_no", DBA_INT, PCN_SIZE_OF( Employee, EmpNo ), PCN_TRUE },
- { "first_name", DBA_CHAR, PCN_SIZE_OF( Employee, FirstName ), PCN_FALSE },
- { "last_name", DBA_CHAR, PCN_SIZE_OF( Employee, LastName ), PCN_FALSE },
- { "street_name",DBA_CHAR, PCN_SIZE_OF( Address, StreetName ), PCN_FALSE },
- { "street_no", DBA_INT, PCN_SIZE_OF( Address, StreetNo ), PCN_FALSE },
- { "city", DBA_CHAR, PCN_SIZE_OF( Address, City ), PCN_FALSE }
-};
-static const int NbCol = 6;
-
-static const
-DBA_ColumnBinding_t AddBindings[] = {
- //DBA_BINDING( "emp_no", DBA_INT, Address, EmpNo ),
- DBA_BINDING( "street_name", DBA_CHAR, Address, StreetName ),
- DBA_BINDING( "street_no", DBA_INT, Address, StreetNo ),
- DBA_BINDING( "city", DBA_CHAR, Address, City )
-};
-
-static const
-int AddBindingRows = sizeof(AddBindings)/sizeof(DBA_ColumnBinding_t);
-
-static const
-DBA_ColumnBinding_t EmpBindings[] = {
- DBA_BINDING( "emp_no", DBA_INT, Employee, EmpNo ),
- DBA_BINDING( "last_name", DBA_CHAR, Employee, LastName ),
- DBA_BINDING( "first_name", DBA_CHAR, Employee, FirstName),
- DBA_BINDING_PTR(Employee, EmployeeAddress, AddBindings, AddBindingRows)
-};
-static const
-int EmpBindingRows = sizeof(EmpBindings)/sizeof(DBA_ColumnBinding_t);
-
-static DBA_Binding_t * Bind;
-
-static const int Rows = 6;
-
-static
-Address_t ADD_TABLE_DATA[] = {
- { 1242, "Lonesome Street", 12, "Crime Town" },
- { 123, "Pistol Road", 13, "Fort Mount" },
- { 456, "Banking Blv.", 43, "Las Vegas" },
- { 8976, "ChancylleZee", 54, "Paris" },
- { 1122, "Lucky", 111, "Wild West" },
- { 3211, "Parlament St.", 11, "Stockholm" }
-};
-
-static
-Address_t ADD_TABLE_DATA_READ[] = {
- { 1242, "", 0, "" },
- { 123, "", 0, "" },
- { 456, "", 0, "" },
- { 8976, "", 0, "" },
- { 1122, "", 0, "" },
- { 3211, "", 0, "" }
-};
-
-static
-Employee_t EMP_TABLE_DATA[] = {
- { 1242, "Joe", "Dalton" , &ADD_TABLE_DATA[0] },
- { 123, "Lucky", "Luke" , &ADD_TABLE_DATA[1] },
- { 456, "Averell", "Dalton" , &ADD_TABLE_DATA[2] },
- { 8976, "Gaston", "Lagaffe", &ADD_TABLE_DATA[3] },
- { 1122, "Jolly", "Jumper" , &ADD_TABLE_DATA[4] },
- { 3211, "Leffe", "Pagrotsky", &ADD_TABLE_DATA[5] },
-};
-
-static
-Employee_t EMP_TABLE_DATA_READ[] = {
- { 1242, "", "", &ADD_TABLE_DATA_READ[0] },
- { 123, "", "", &ADD_TABLE_DATA_READ[1] },
- { 456, "", "", &ADD_TABLE_DATA_READ[2] },
- { 8976, "", "", &ADD_TABLE_DATA_READ[3] },
- { 1122, "", "", &ADD_TABLE_DATA_READ[4] },
- { 3211, "", "", &ADD_TABLE_DATA_READ[5] }
-};
-
-static const char TABLE[] = "employee_address";
-
-static
-void
-DbCreate(void){
-
- ndbout << "Opening database" << endl;
- require( DBA_Open() == DBA_NO_ERROR );
-
- ndbout << "Creating tables" << endl;
- require( DBA_CreateTable( TABLE, NbCol, ColDesc ) == DBA_NO_ERROR );
-
- ndbout << "Checking for table existance" << endl;
- require( DBA_TableExists( TABLE ) );
-}
-
-static
-void
-CreateBindings(void){
- ndbout << "Creating bindings" << endl;
-
- Bind = DBA_CreateBinding(TABLE,
- EmpBindingRows,
- EmpBindings,
- sizeof(Employee_t) );
-
- require(Bind != 0);
-}
-
-extern "C" {
- static void insertCallback( DBA_ReqId_t, DBA_Error_t, DBA_ErrorCode_t );
- static void deleteCallback( DBA_ReqId_t, DBA_Error_t, DBA_ErrorCode_t );
- static void updateCallback( DBA_ReqId_t, DBA_Error_t, DBA_ErrorCode_t );
- static void readCallback ( DBA_ReqId_t, DBA_Error_t, DBA_ErrorCode_t );
- static void writeCallback ( DBA_ReqId_t, DBA_Error_t, DBA_ErrorCode_t );
-}
-
-static
-void BasicArray(){
- ndbout << "Testing basic array operations" << endl;
-
- // Basic insert
- DBA_ArrayInsertRows(Bind, EMP_TABLE_DATA, Rows-2, insertCallback);
- NdbSleep_SecSleep(1);
- DBA_ArrayReadRows (Bind, EMP_TABLE_DATA_READ, Rows-2, readCallback);
- NdbSleep_SecSleep(1);
- CompareRows(EMP_TABLE_DATA, Rows-2, EMP_TABLE_DATA_READ);
- CompareRows(ADD_TABLE_DATA, Rows-2, ADD_TABLE_DATA_READ);
-
- // Basic update
- AlterRows (EMP_TABLE_DATA, Rows-2);
- AlterRows (ADD_TABLE_DATA, Rows-2);
- DBA_ArrayUpdateRows(Bind, EMP_TABLE_DATA, Rows-2, updateCallback);
- NdbSleep_SecSleep(1);
- DBA_ArrayReadRows (Bind, EMP_TABLE_DATA_READ, Rows-2, readCallback);
- NdbSleep_SecSleep(1);
- CompareRows(EMP_TABLE_DATA, Rows-2, EMP_TABLE_DATA_READ);
- CompareRows(ADD_TABLE_DATA, Rows-2, ADD_TABLE_DATA_READ);
-
- // Basic write
- AlterRows (EMP_TABLE_DATA, Rows);
- AlterRows (ADD_TABLE_DATA, Rows);
- DBA_ArrayWriteRows(Bind, EMP_TABLE_DATA, Rows, writeCallback);
- NdbSleep_SecSleep(1);
- DBA_ArrayReadRows (Bind, EMP_TABLE_DATA_READ, Rows, readCallback);
- NdbSleep_SecSleep(1);
- CompareRows(EMP_TABLE_DATA, Rows, EMP_TABLE_DATA_READ);
- CompareRows(ADD_TABLE_DATA, Rows, ADD_TABLE_DATA_READ);
-
- // Basic delete
- DBA_ArrayDeleteRows(Bind, EMP_TABLE_DATA, Rows, deleteCallback);
- NdbSleep_SecSleep(1);
-}
-
-static
-void BasicPtr(){
- ndbout << "Testing array of pointer operations" << endl;
- Employee_t * EmpData[Rows];
- Employee_t * EmpDataRead[Rows];
- for(int i = 0; i<Rows; i++){
- EmpData[i] = &EMP_TABLE_DATA[i];
- EmpDataRead[i] = &EMP_TABLE_DATA_READ[i];
- }
-
- void * const * EMP_TABLE_DATA2 = (void * const *)EmpData;
- void * const * EMP_TABLE_DATA_READ2 = (void * const *)EmpDataRead;
-
- // Basic insert
- DBA_InsertRows(Bind, EMP_TABLE_DATA2, Rows-2, insertCallback);
- NdbSleep_SecSleep(1);
- DBA_ReadRows (Bind, EMP_TABLE_DATA_READ2, Rows-2, readCallback);
- NdbSleep_SecSleep(1);
- CompareRows(EMP_TABLE_DATA, Rows-2, EMP_TABLE_DATA_READ);
- CompareRows(ADD_TABLE_DATA, Rows-2, ADD_TABLE_DATA_READ);
-
- // Basic update
- AlterRows (ADD_TABLE_DATA, Rows-2);
- AlterRows (EMP_TABLE_DATA, Rows-2);
- DBA_UpdateRows(Bind, EMP_TABLE_DATA2, Rows-2, updateCallback);
- NdbSleep_SecSleep(1);
- DBA_ReadRows (Bind, EMP_TABLE_DATA_READ2, Rows-2, readCallback);
- NdbSleep_SecSleep(1);
- CompareRows(EMP_TABLE_DATA, Rows-2, EMP_TABLE_DATA_READ);
- CompareRows(ADD_TABLE_DATA, Rows-2, ADD_TABLE_DATA_READ);
-
- // Basic write
- AlterRows (ADD_TABLE_DATA, Rows);
- AlterRows (EMP_TABLE_DATA, Rows);
- DBA_WriteRows(Bind, EMP_TABLE_DATA2, Rows, writeCallback);
- NdbSleep_SecSleep(1);
- DBA_ReadRows (Bind, EMP_TABLE_DATA_READ2, Rows, readCallback);
- NdbSleep_SecSleep(1);
- CompareRows(EMP_TABLE_DATA, Rows, EMP_TABLE_DATA_READ);
- CompareRows(ADD_TABLE_DATA, Rows, ADD_TABLE_DATA_READ);
-
- // Basic delete
- DBA_DeleteRows(Bind, EMP_TABLE_DATA2, Rows, deleteCallback);
- NdbSleep_SecSleep(1);
-}
-
-/*---------------------------------------------------------------------------*/
-NDB_COMMAND(newton_pb, "newton_pb",
- "newton_pb", "newton_pb", 65535){
-
- DbCreate();
- CreateBindings();
-
- BasicArray();
- BasicPtr();
-
- DBA_Close();
-
- return 0;
-}
-
-/**
- * callbackStatusCheck checks whether or not the operation succeeded
- */
-void
-callbackStatusCheck( DBA_Error_t status, const char* operation) {
- ndbout_c("%s: %d", operation, status);
-}
-
-void insertCallback( DBA_ReqId_t, DBA_Error_t s, DBA_ErrorCode_t ){
- callbackStatusCheck(s, "insert");
-}
-void deleteCallback( DBA_ReqId_t, DBA_Error_t s, DBA_ErrorCode_t ){
- callbackStatusCheck(s, "delete");
-}
-void updateCallback( DBA_ReqId_t, DBA_Error_t s, DBA_ErrorCode_t ){
- callbackStatusCheck(s, "update");
-}
-void readCallback ( DBA_ReqId_t, DBA_Error_t s, DBA_ErrorCode_t ){
- callbackStatusCheck(s, "read");
-}
-void writeCallback ( DBA_ReqId_t, DBA_Error_t s, DBA_ErrorCode_t ){
- callbackStatusCheck(s, "write");
-}
-
diff --git a/storage/ndb/test/newtonapi/basic_test/too_basic.cpp b/storage/ndb/test/newtonapi/basic_test/too_basic.cpp
deleted file mode 100644
index b4edfeae609..00000000000
--- a/storage/ndb/test/newtonapi/basic_test/too_basic.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-
-/****** THIS LINE IS 80 CHARACTERS WIDE - DO *NOT* EXCEED 80 CHARACTERS! ****/
-
-#include <ndb_global.h>
-#include <NdbOut.hpp>
-
-//#include <cfg/cfg_db.h>
-//#include <init/init_start_restart.h>
-//#include "pcn_types.h"
-//#include <testing/testing.h>
-
-extern "C" {
-#include <cfg_db.h>
-}
-
-typedef struct Employee {
-
- UInt32_t EmpNo;
- char FirstName[22];
- char LastName[22];
-
-} Employee_t;
-#define CHECK_DB_CALL( Call ) \
- CheckDbCall( Call, #Call, __FILE__, __LINE__ )
-
-
-
-/* --- Exported functions --- */
-
-/*---------------------------------------------------------------------------*/
-int main() {
-
-
- char EMP_TABLE_NAME[] = "employees";
-
- Employee_t t;
-
- CFG_DbColumnDesc_t EmpColDesc[] = {
- { "first_name", CFG_DB_CHAR, PCN_SIZE_OF( Employee, FirstName ),
- PCN_FALSE },
- { "emp_no", CFG_DB_INT, PCN_SIZE_OF( Employee, EmpNo ), PCN_TRUE },
- { "last_name", CFG_DB_CHAR, PCN_SIZE_OF( Employee, LastName ),
- PCN_FALSE },
- };
-
- int EmpNbCol = 3;
-
-
-
- CFG_DbColumnBinding_t ColBindings[] = {
- CFG_DB_BINDING( "last_name", CFG_DB_CHAR, Employee, LastName ),
- CFG_DB_BINDING( "emp_no", CFG_DB_INT, Employee, EmpNo ),
- CFG_DB_BINDING( "first_name", CFG_DB_CHAR, Employee, FirstName)
- };
-
-
- Employee_t EMP_TABLE_DATA[] = {
- { 1242, "Joe", "Dalton" },
- { 123, "Lucky", "Luke" },
- { 456, "Averell", "Dalton" },
- { 8976, "Gaston", "Lagaffe" }
- };
-
-
- char* DbName;
-
- DbName = NULL;
-
-
- // On Linux: will destroy the table to start from a clean slate.
-
- CFG_DbDestroy();
- CFG_DbOpen( &DbName ) ;
- CFG_DbCreateTable( EMP_TABLE_NAME,
- EmpNbCol, EmpColDesc );
-
- CFG_DbTableExists( EMP_TABLE_NAME );
-
- //#ifndef CELLO_PLATFORM
- //CHECK_DB_CALL( CFG_DbDumpSchema( stdout ) );
- //#endif
-
- CFG_DbClose();
- // INIT_StopSystem();
-
-}
-
-
diff --git a/storage/ndb/test/newtonapi/perf_test/Makefile b/storage/ndb/test/newtonapi/perf_test/Makefile
deleted file mode 100644
index 2be004d4277..00000000000
--- a/storage/ndb/test/newtonapi/perf_test/Makefile
+++ /dev/null
@@ -1,14 +0,0 @@
-include .defs.mk
-
-TYPE := ndbapitest
-
-BIN_TARGET := newton_perf
-BIN_TARGET_LIBS :=
-BIN_TARGET_ARCHIVES := NEWTON_API
-SOURCES := perf.cpp
-
-CCFLAGS_LOC := -I$(call fixpath,$(NDB_TOP)/include/util) -I$(call fixpath,$(NDB_TOP)/include/newtonapi) -I$(call fixpath,$(NDB_TOP)/include/portlib)
-
-include $(NDB_TOP)/Epilogue.mk
-
-
diff --git a/storage/ndb/test/newtonapi/perf_test/perf.cpp b/storage/ndb/test/newtonapi/perf_test/perf.cpp
deleted file mode 100644
index d889a85ac8e..00000000000
--- a/storage/ndb/test/newtonapi/perf_test/perf.cpp
+++ /dev/null
@@ -1,647 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-#include <ndb_global.h>
-
-extern "C" {
-#include <dba.h>
-}
-
-#include <NdbOut.hpp>
-#include <NdbSleep.h>
-#include <NdbTimer.hpp>
-#include <NDBT_Stats.hpp>
-#include <NDBT_ReturnCodes.h>
-#include <NdbMain.h>
-#include <time.h>
-
-#undef min
-#undef max
-
-static const int NP_Insert = 0;
-static const int NP_Update = 1;
-static const int NP_WriteUpdate = 2;
-static const int NP_WriteInsert = 3;
-static const int NP_Delete = 4;
-static const int NP_BulkRead = 5;
-static const int NP_MAX = 5;
-
-static const char * Operations[] = {
- "Insert ",
- "Update ",
- "WriteUpd",
- "WriteIns",
- "Delete ",
- "BulkRead"
-};
-
-/**
- * Configuration variables
- */
-static int NoOfTransactions = 10000;
-static int ParallellTransactions = 1000;
-static int OperationsPerTransaction = 10;
-static int NoOfColumns = 20;
-static int BytesPerInsert = 300;
-static int BytesPerUpdate = 200;
-static int LoopCount = 10;
-
-/**
- * Global variables
- */
-static char TableName[255];
-static DBA_ColumnDesc_t * ColumnDescriptions;
-static DBA_ColumnBinding_t * InsertBindings;
-static DBA_ColumnBinding_t * UpdateBindings; static int UpdateBindingColumns;
-static DBA_ColumnBinding_t * DeleteBindings;
-
-static char * TestData;
-static DBA_Binding_t * InsertB;
-static DBA_Binding_t * UpdateB;
-static DBA_Binding_t * DeleteB;
-
-/**
- * Function prototypes
- */
-static void sequence(int loops);
-
-inline void * getPtr(int rowNo) { return TestData+rowNo*BytesPerInsert;}
-inline void setPK(int rowNo, int pk){ * (int *)getPtr(rowNo) = pk; }
-
-static void SetupTestData();
-static void CleanupTestData();
-
-static bool CreateTable();
-static bool CleanTable();
-static bool CreateBindings();
-
-static void usage();
-
-static
-void
-usage(){
- int ForceSend, Interval;
- DBA_GetParameter(0, &Interval);
- DBA_GetParameter(3, &ForceSend);
-
- ndbout << "newtonPerf" << endl
- << " -n Transactions per loop and operation ("
- << NoOfTransactions << ")" << endl
- << " -p parallell transactions (" << ParallellTransactions << ")"
- << endl
- << " -o operations per transaction (" << OperationsPerTransaction
- << ")" << endl
- << " -a no of columns (" << NoOfColumns << ")" << endl
- << " -b Table size in bytes (" << BytesPerInsert << ")" << endl
- << " -u Bytes per update (" << BytesPerUpdate << ")" << endl
- << " -l Loop count (" << LoopCount << ")" << endl
- << " -i Interval (" << Interval << "ms)" << endl
- << " -f Force send algorithm (" << ForceSend << ")" << endl
- << " -h Help" << endl;
-
-}
-
-static
-bool
-parseArgs(int argc, const char **argv){
- bool a = false, b = false, u = false;
-
- for(int i = 1; i<argc; i++){
- if(argv[i][0] != '-'){
- ndbout << "Invalid argument: " << argv[i] << endl;
- return false;
- }
-
- if(argv[i][1] == 'h')
- return false;
-
- if(i == argc-1){
- ndbout << "Expecting argument to " << argv[i] << endl;
- return false;
- }
-
- switch(argv[i][1]){
- case 'n':
- NoOfTransactions = atoi(argv[i+1]);
- break;
- case 'p':
- ParallellTransactions = atoi(argv[i+1]);
- break;
- case 'o':
- OperationsPerTransaction = atoi(argv[i+1]);
- break;
- case 'a':
- NoOfColumns = atoi(argv[i+1]);
- a = true;
- break;
- case 'b':
- BytesPerInsert = atoi(argv[i+1]);
- b = true;
- break;
- case 'u':
- BytesPerUpdate = atoi(argv[i+1]);
- u = true;
- break;
- case 'l':
- LoopCount = atoi(argv[i+1]);
- break;
- case 'f':
- {
- const int val = atoi(argv[i+1]);
- if(DBA_SetParameter(3, val) != DBA_NO_ERROR){
- ndbout << "Invalid force send algorithm: "
- << DBA_GetLatestErrorMsg()
- << "(" << DBA_GetLatestError() << ")" << endl;
- return false;
- }
- }
- break;
- case 'i':
- {
- const int val = atoi(argv[i+1]);
- if(DBA_SetParameter(0, val) != DBA_NO_ERROR){
- ndbout << "Invalid NBP interval: "
- << DBA_GetLatestErrorMsg()
- << "(" << DBA_GetLatestError() << ")" << endl;
- return false;
- }
- }
- break;
- default:
- ndbout << "Invalid option: " << argv[i] << endl;
- return false;
- }
- i++;
- }
- if(a && !b) BytesPerInsert = 15 * NoOfColumns;
- if(!a && b) NoOfColumns = ((BytesPerInsert + 14) / 15)+1;
-
- if(!u)
- BytesPerUpdate = (2 * BytesPerInsert) / 3;
-
- bool t = true;
- if(NoOfColumns < 2) t = false;
- if(BytesPerInsert < 8) t = false;
- if(BytesPerUpdate < 8) t = false;
-
- if(!t){
- ndbout << "Invalid arguments combination of -a -b -u not working out"
- << endl;
- return false;
- }
- return true;
-}
-
-NDB_COMMAND(newton_perf, "newton_perf",
- "newton_perf", "newton_perf", 65535){
-
- if(!parseArgs(argc, argv)){
- usage();
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- ndbout << "-----------" << endl;
- usage();
- ndbout << endl;
-
- SetupTestData();
-
- DBA_Open();
-
- if(!CreateTable()){
- DBA_Close();
- CleanupTestData();
- return 0;
- }
-
- if(!CreateBindings()){
- DBA_Close();
- CleanupTestData();
- return 0;
- }
-
- CleanTable();
-
- sequence(LoopCount);
-
- DBA_Close();
- CleanupTestData();
-
- DBA_DestroyBinding(InsertB);
- DBA_DestroyBinding(UpdateB);
- DBA_DestroyBinding(DeleteB);
-}
-
-static
-void
-ErrorMsg(const char * s){
- ndbout << s
- << ": " << DBA_GetLatestError() << "-" << DBA_GetLatestErrorMsg()
- << ", " << DBA_GetLatestNdbError()
- << endl;
-}
-
-static
-int
-m4(int i){
- const int j = i - (i & 3);
- return j;
-}
-
-static
-void
-SetupTestData(){
- ndbout << "Creating testdata" << endl;
-
- ColumnDescriptions = new DBA_ColumnDesc_t[NoOfColumns];
- InsertBindings = new DBA_ColumnBinding_t[NoOfColumns];
-
- const int sz = m4((BytesPerInsert - ((NoOfColumns+1)/2)*4)/(NoOfColumns/2));
- int sum = 0;
- UpdateBindingColumns = 0;
- for(int i = 0; i<NoOfColumns; i++){
- char tmp[16];
- if((i % 2) == 0){
- sprintf(tmp, "I%d", i);
- ColumnDescriptions[i].DataType = DBA_INT;
- ColumnDescriptions[i].Size = 4;
- sum += 4;
- } else {
- sprintf(tmp, "S%d", i);
- ColumnDescriptions[i].DataType = DBA_CHAR;
- ColumnDescriptions[i].Size = sz;
- sum += sz;
- }
- ColumnDescriptions[i].IsKey = 0;
- ColumnDescriptions[i].Name = strdup(tmp);
-
- InsertBindings[i].Name = strdup(tmp);
- InsertBindings[i].DataType = ColumnDescriptions[i].DataType;
- InsertBindings[i].Size = ColumnDescriptions[i].Size;
- InsertBindings[i].Offset = sum - ColumnDescriptions[i].Size;
- InsertBindings[i].Ptr = 0;
-
- if(sum <= BytesPerUpdate)
- UpdateBindingColumns++;
- }
- if(UpdateBindingColumns == 1)
- UpdateBindingColumns++;
-
- ColumnDescriptions[0].IsKey = 1;
-
- assert(sum <= BytesPerInsert);
- sprintf(TableName, "NEWTON_%d_%d", sum, NoOfColumns);
-
- UpdateBindings = new DBA_ColumnBinding_t[UpdateBindingColumns];
- memcpy(UpdateBindings, InsertBindings,
- UpdateBindingColumns*sizeof(DBA_ColumnBinding_t));
-
- DeleteBindings = new DBA_ColumnBinding_t[1];
- memcpy(DeleteBindings, InsertBindings,
- 1*sizeof(DBA_ColumnBinding_t));
-
- TestData = (char *)malloc(NoOfTransactions *
- OperationsPerTransaction * BytesPerInsert);
-
- assert(TestData != 0);
- for(int i = 0; i<NoOfTransactions; i++)
- for(int j = 0; j<OperationsPerTransaction; j++){
- const int pk = i * OperationsPerTransaction + j;
- setPK(pk, pk);
- }
-}
-
-static
-void
-CleanupTestData(){
- free(TestData);
- for(int i = 0; i<NoOfColumns; i++){
- free((char*)ColumnDescriptions[i].Name);
- free((char*)InsertBindings[i].Name);
- }
- delete [] ColumnDescriptions;
- delete [] InsertBindings;
- delete [] UpdateBindings;
- delete [] DeleteBindings;
-}
-
-
-static bool CleanReturnValue = true;
-static int CleanCallbacks = 0;
-static int CleanRows = 0;
-
-extern "C"
-void
-CleanCallback(DBA_ReqId_t reqId, DBA_Error_t error, DBA_ErrorCode_t ec){
- CleanCallbacks++;
- if(error == DBA_NO_ERROR)
- CleanRows++;
-}
-
-static
-bool
-CleanTable(){
- ndbout << "Cleaning table..." << flush;
- CleanReturnValue = true;
- CleanCallbacks = 0;
- CleanRows = 0;
- for(int i = 0; i<NoOfTransactions * OperationsPerTransaction; i++){
- DBA_ArrayDeleteRows(DeleteB,
- getPtr(i), 1,
- CleanCallback);
- while((i-CleanCallbacks)>ParallellTransactions)
- NdbSleep_MilliSleep(100);
- }
- while(CleanCallbacks != (NoOfTransactions * OperationsPerTransaction))
- NdbSleep_SecSleep(1);
-
- ndbout << CleanRows << " rows deleted" << endl;
-
- return CleanReturnValue;
-}
-
-static
-bool
-CreateBindings(){
- ndbout << "Creating bindings" << endl;
- InsertB = UpdateB = DeleteB = 0;
-
- InsertB = DBA_CreateBinding(TableName, NoOfColumns,
- InsertBindings, BytesPerInsert);
- if(InsertB == 0){
- ErrorMsg("Failed to create insert bindings");
- return false;
- }
-
- UpdateB = DBA_CreateBinding(TableName, UpdateBindingColumns,
- UpdateBindings, BytesPerInsert);
- if(UpdateB == 0){
- ErrorMsg("Failed to create update bindings");
- DBA_DestroyBinding(InsertB);
- return false;
- }
-
- DeleteB = DBA_CreateBinding(TableName, 1,
- DeleteBindings, BytesPerInsert);
- if(DeleteB == 0){
- ErrorMsg("Failed to create delete bindings");
- DBA_DestroyBinding(InsertB);
- DBA_DestroyBinding(UpdateB);
- return false;
- }
- return true;
-}
-
-static
-bool
-CreateTable(){
- ndbout << "Creating " << TableName << endl;
- return DBA_CreateTable( TableName,
- NoOfColumns,
- ColumnDescriptions ) == DBA_NO_ERROR;
-}
-
-/**
- *
- */
-static NdbTimer SequenceTimer;
-
-static int CurrentOp = NP_Insert;
-static int SequenceSent = 0;
-static int SequenceRecv = 0;
-static NDBT_Stats SequenceStats[NP_MAX][4];
-static NDBT_Stats SequenceLatency[NP_MAX];
-
-static int HashMax;
-static DBA_ReqId_t * ReqHash; // ReqId - Latency/Row
-static int * ReqHashPos; // (row in StartTime)
-
-static int SequenceLatencyPos;
-static NDB_TICKS * StartTime;
-
-static
-inline
-int
-computeHashMax(int elements){
- HashMax = 1;
- while(HashMax < elements)
- HashMax *= 2;
-
- if(HashMax < 1024)
- HashMax = 1024;
-
- return HashMax;
-}
-
-static
-inline
-int
-hash(DBA_ReqId_t request){
- int r = (request >> 2) & (HashMax-1);
- return r;
-}
-
-static
-inline
-void
-addRequest(DBA_ReqId_t request, int pos){
-
- int i = hash(request);
-
- while(ReqHash[i] != 0)
- i = ((i + 1) & (HashMax-1));
-
- ReqHash[i] = request;
- ReqHashPos[i] = pos;
-}
-
-static
-inline
-int
-getRequest(DBA_ReqId_t request){
-
- int i = hash(request);
-
- while(ReqHash[i] != request)
- i = ((i + 1) & (HashMax-1));
-
- ReqHash[i] = 0;
-
- return ReqHashPos[i];
-}
-
-extern "C"
-void
-SequenceCallback(DBA_ReqId_t reqId, DBA_Error_t error, DBA_ErrorCode_t ec){
- int p = getRequest(reqId) - 1;
-
- if(error != DBA_NO_ERROR){
- ndbout << "p = " << p << endl;
- ndbout << "DBA_GetErrorMsg(" << error << ") = "
- << DBA_GetErrorMsg(error) << endl;
- ndbout << "DBA_GetNdbErrorMsg(" << ec << ") = "
- << DBA_GetNdbErrorMsg(ec) << endl;
-
- assert(error == DBA_NO_ERROR);
- }
-
- SequenceRecv++;
- if(SequenceRecv == NoOfTransactions){
- SequenceTimer.doStop();
- }
-
- if((p & 127) == 127){
- NDB_TICKS t = NdbTick_CurrentMillisecond() - StartTime[p];
- SequenceLatency[CurrentOp].addObservation(t);
- }
-}
-
-typedef DBA_ReqId_t (* DBA_ArrayFunction)( const DBA_Binding_t* pBindings,
- const void * pData,
- int NbRows,
- DBA_AsyncCallbackFn_t CbFunc );
-
-inline
-int
-min(int a, int b){
- return a > b ? b : a;
-}
-
-static
-void
-SequenceOp(DBA_ArrayFunction func, const DBA_Binding_t* pBindings, int op){
- SequenceSent = 0;
- SequenceRecv = 0;
- SequenceLatencyPos = 1;
- CurrentOp = op;
-
- SequenceTimer.doStart();
- for(int i = 0; i<NoOfTransactions; ){
- const int l1 = ParallellTransactions - (SequenceSent - SequenceRecv);
- const int l2 = min(NoOfTransactions - i, l1);
- for(int j = 0; j<l2; j++){
- const DBA_ReqId_t r = func(pBindings,
- getPtr(i*OperationsPerTransaction),
- OperationsPerTransaction,
- SequenceCallback);
- assert(r != 0);
- SequenceSent++;
- addRequest(r, i + 1);
- i++;
-
- if((SequenceSent & 127) == 127){
- NDB_TICKS t = NdbTick_CurrentMillisecond();
- StartTime[i] = t;
- }
- }
- if(l2 == 0)
- NdbSleep_MilliSleep(10);
- }
-
- while(SequenceRecv != SequenceSent)
- NdbSleep_SecSleep(1);
-
- ndbout << "Performed " << NoOfTransactions << " " << Operations[op]
- << " in ";
-
- double p = NoOfTransactions * 1000;
- double t = SequenceTimer.elapsedTime();
- double o = p * OperationsPerTransaction;
-
- p /= t;
- o /= t;
-
- int _p = p;
- int _o = o;
-
- double b = 0;
-
- switch(op){
- case NP_Insert:
- case NP_WriteInsert:
- case NP_WriteUpdate:
- case NP_BulkRead:
- b = BytesPerInsert;
- break;
- case NP_Update:
- b = BytesPerUpdate;
- break;
- case NP_Delete:
- b = 4;
- break;
- default:
- b = 0;
- }
- b *= NoOfTransactions * OperationsPerTransaction;
- b /= t;
- int _b = b;
-
- SequenceStats[op][0].addObservation(t);
- SequenceStats[op][1].addObservation(p);
- SequenceStats[op][2].addObservation(o);
- SequenceStats[op][3].addObservation(b);
-
- int t2 = SequenceStats[op][0].getMean();
- int p2 = SequenceStats[op][1].getMean();
- int o2 = SequenceStats[op][2].getMean();
- int b2 = SequenceStats[op][3].getMean();
-
- ndbout << SequenceTimer.elapsedTime() << "(" << t2 << ")ms";
- ndbout << " -> " << _p << "(" << p2 << ") T/s - " << _o
- << "(" << o2 << ") O/s - " << _b << "(" << b2 << ") Kb/s" << endl;
-
- ndbout << " Latency (ms) Avg: " << (int)SequenceLatency[op].getMean()
- << " min: " << (int)SequenceLatency[op].getMin()
- << " max: " << (int)SequenceLatency[op].getMax()
- << " stddev: " << (int)SequenceLatency[op].getStddev()
- << " n: " << SequenceLatency[op].getCount() << endl;
-}
-
-/**
- * Sequence
- */
-static
-void
-sequence(int loops){
- computeHashMax(ParallellTransactions);
- ReqHash = new DBA_ReqId_t[HashMax];
- ReqHashPos = new int[HashMax];
- StartTime = new NDB_TICKS[NoOfTransactions];
-
- for(int i = 0; i<NP_MAX; i++){
- SequenceLatency[i].reset();
- for(int j = 0; j<4; j++)
- SequenceStats[i][j].reset();
- }
- for(int i = 0; i<loops; i++){
- ndbout << "Loop #" << (i+1) << endl;
- SequenceOp(DBA_ArrayInsertRows, InsertB, NP_Insert);
-
- // BulkRead
-
- SequenceOp(DBA_ArrayUpdateRows, UpdateB, NP_Update);
- SequenceOp(DBA_ArrayWriteRows, InsertB, NP_WriteUpdate);
- SequenceOp(DBA_ArrayDeleteRows, DeleteB, NP_Delete);
- SequenceOp(DBA_ArrayWriteRows, InsertB, NP_WriteInsert);
- SequenceOp(DBA_ArrayDeleteRows, DeleteB, NP_Delete);
- ndbout << "-------------------" << endl << endl;
- }
-
- delete [] ReqHash;
- delete [] ReqHashPos;
- delete [] StartTime;
-}
diff --git a/storage/ndb/test/odbc/SQL99_test/Makefile b/storage/ndb/test/odbc/SQL99_test/Makefile
deleted file mode 100644
index 3ac06016670..00000000000
--- a/storage/ndb/test/odbc/SQL99_test/Makefile
+++ /dev/null
@@ -1,26 +0,0 @@
-include .defs.mk
-
-TYPE = odbcdriver
-
-BIN_TARGET = SQL99_test
-
-SOURCES = SQL99_test.cpp
-
-CCFLAGS_LOC += -I/usr/local/include \
- -I$(NDB_TOP)/test/include \
- -I$(NDB_TOP)/include \
- -I$(NDB_TOP)/src/client/odbc/common
-
-
-CCFLAGS_WARNINGS += -Wno-unused
-
-LIBS_SPEC += \
- -lNDBT \
- -lodbc \
- -lodbcinst \
- -lportlib
-
-
-
-include $(NDB_TOP)/Epilogue.mk
-
diff --git a/storage/ndb/test/odbc/SQL99_test/SQL99_test.cpp b/storage/ndb/test/odbc/SQL99_test/SQL99_test.cpp
deleted file mode 100644
index 6144165a976..00000000000
--- a/storage/ndb/test/odbc/SQL99_test/SQL99_test.cpp
+++ /dev/null
@@ -1,2145 +0,0 @@
-/* Copyright (c) 2003, 2005, 2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-// ODBC.cpp : Defines the entry point for the console application.
-//
-
-#include "SQL99_test.h"
-#include <iostream> // Loose later
-
-using namespace std; //
-
-#define MAXCOL 64
-#define DEFCOL 4
-
-#define MAXROW 64
-#define DEFROW 8
-
-/*
- NDB_MAXTHREADS used to be just MAXTHREADS, which collides with a
- #define from <sys/thread.h> on AIX (IBM compiler). We explicitly
- #undef it here lest someone use it by habit and get really funny
- results. K&R says we may #undef non-existent symbols, so let's go.
-*/
-#undef MAXTHREADS
-#define NDB_MAXTHREADS 24
-#define DEFTHREADS 2
-
-#define MAXTABLES 16
-#define DEFTABLES 2
-
-#define MAXLOOPS 100000
-#define DEFLOOPS 4
-
-#define UPDATE_VALUE 7
-
-#define PKSIZE 2
-
-
-static int nNoOfThreads = 1 ;
-static int nNoOfCol = 4 ;
-static int nNoOfRows = 2 ;
-static int nNoOfLoops = 0 ;
-static int nNoOfTables = 2 ;
-static int nAPI = 0 ;
-static int tAttributeSize = sizeof(char) ;
-static attr_type AttributeType = T_CHAR ;
-static int nAggregate = 0 ;
-static int nArithmetic = 0 ;
-static int nPrint = 0 ;
-static int nColList = 0 ;
-static char szColNames[MAXCOL*MAX_COL_NAME] = { 0 } ;
-int createTables(char* szTableName, int nTables) ;
-
-
-/*************************************************
-Function: main - the entry point
-*************************************************/
-int main(int argc, char* argv[]){
-
- int nRetrunValue = NDBT_FAILED ;
- SQLRETURN rc = SQL_ERROR ;
- double dResultA = 0 ;
- double dResultB = 0 ;
- double dInput = 0 ;
- int x = 0, y = 0 ;
- int* pIntRefBuffer = NULL ;
- float* pFloatRefBuffer = NULL ;
- double* pDoubleRefBuffer = NULL ;
- char* pCharRefBuffer = NULL ;
- char szColBuffer[MAX_COL_NAME] = { 0 } ;
-
-
- ParseArguments(argc, (const char**)argv) ;
-
- PARAMS* pparams = (PARAMS*)malloc(sizeof(PARAMS)*nNoOfThreads) ;
- memset(pparams, 0, (sizeof(PARAMS)*nNoOfThreads)) ;
-
- char* szTableNames = (char*)malloc(sizeof(char)*nNoOfTables*MAX_TABLE_NAME) ;
- memset(szTableNames, 0, sizeof(char)*nNoOfTables*MAX_TABLE_NAME) ;
-
- UintPtr pThreadHandles[NDB_MAXTHREADS] = { NULL } ;
-
- AssignTableNames(szTableNames, nNoOfTables) ;
-
- if(nAPI){
- if(0 != createTables(szTableNames, nNoOfTables)){
- printf("Failed to create tables through NDB API; quitting...\n") ;
- NDBT_ProgramExit(NDBT_FAILED) ;
- return NDBT_FAILED ;
- }
- }else{
-
- //CreateDemoTables(szTableNames, nNoOfTables, DROP) ;
- rc = CreateDemoTables(szTableNames, nNoOfTables, CREATE) ;
- if(!(SQL_SUCCESS == rc || SQL_SUCCESS_WITH_INFO == rc)){
- printf("Failed to create tables, quiting now.\n") ;
- NDBT_ProgramExit(NDBT_FAILED) ;
- return NDBT_FAILED ;
- }
- }
-
- // Store column names in the buffer for use in some stmts
- int k = 0 ;
- for(;;){
- memset((char*)szColBuffer, 0, strlen(szColBuffer)) ;
- sprintf((char*)szColBuffer, "COL%d", k) ;
- strcat((char*)szColNames, (char*)szColBuffer) ;
- ++k ;
- if( k == nNoOfCol ){
- break ;
- }
- strcat((char*)szColNames, ", ") ;
- } // for
-
-
- switch(AttributeType){
- case T_INT:
- pIntRefBuffer = (int*)malloc(sizeof(int)*nNoOfRows*nNoOfCol*nNoOfThreads) ;
- memset(pIntRefBuffer, 0, sizeof(int)*nNoOfRows*nNoOfCol*nNoOfThreads) ;
- AssignRefNumValues(pIntRefBuffer, T_INT, nPrint) ;
- StartThreads(pparams, (void*)pIntRefBuffer, nNoOfTables, szTableNames, AttributeType, pThreadHandles) ;
- break ;
- case T_FLOAT:
- pFloatRefBuffer = (float*)malloc(sizeof(float)*nNoOfRows*nNoOfCol*nNoOfThreads) ;
- memset(pFloatRefBuffer, 0, sizeof(float)*nNoOfRows*nNoOfCol*nNoOfThreads) ;
- AssignRefNumValues(pFloatRefBuffer, T_FLOAT, nPrint) ;
- StartThreads(pparams, (void*)pFloatRefBuffer, nNoOfTables, szTableNames, AttributeType, pThreadHandles) ;
- break ;
-/* case T_DOUBLE:
- pDoubleRefBuffer = (double*)malloc(sizeof(double)*nNoOfRows*nNoOfCol*nNoOfThreads) ;
- memset(pDoubleRefBuffer, 0, sizeof(double)*nNoOfRows*nNoOfCol*nNoOfThreads) ;
- AssignRefNumValues(pDoubleRefBuffer, T_DOUBLE, 0) ;
- StartThreads(pparams, (void*)pDoubleRefBuffer, nNoOfTables, szTableNames, AttributeType, pThreadHandles) ;
- break ;
-*/
- case T_CHAR:
- pCharRefBuffer = (char*)malloc(sizeof(char)*nNoOfRows*nNoOfCol*nNoOfThreads*MAX_CHAR_ATTR_LEN) ;
- memset(pCharRefBuffer, 0, sizeof(char)*nNoOfRows*nNoOfCol*nNoOfThreads*MAX_CHAR_ATTR_LEN) ;
- AssignRefCharValues(pCharRefBuffer, nPrint ) ;
- StartThreads(pparams, (void*)pCharRefBuffer, nNoOfTables, szTableNames, AttributeType, pThreadHandles) ;
- break ;
- default:
- break ;
- }
-
- NdbThread_SetConcurrencyLevel(nNoOfThreads + 2) ;
-
-
- printf("\nPerforming inserts...") ;
- SetThreadOperationType(pparams, T_INSERT) ;
- if(0 < WaitForThreads(pparams)){
- printf("\t\t%d thread(s) failed\n") ;
- }else{
- printf("\t\tdone\n") ;
- }
- printf("----------------------\n\n") ;
- PrintAll(szTableNames, nNoOfTables, AttributeType) ;
-
- printf("\nVerifying inserts...") ;
- SetThreadOperationType(pparams, T_READ_VERIFY) ;
- if(0 < WaitForThreads(pparams)){
- printf("\t\t%d thread(s) failed\n") ;
- }else{
- printf("\t\tdone\n") ;
- }
- printf("----------------------\n\n") ;
-
- printf("\nPerforming updates...") ;
- SetThreadOperationType(pparams, T_UPDATE) ;
- if(0 < WaitForThreads(pparams)){
- printf("\t\t%d thread(s) failed\n") ;
- }else{
- printf("\t\tdone\n") ;
- }
- printf("----------------------\n\n") ;
- //PrintAll(szTableNames, nNoOfTables, AttributeType) ;
-
- printf("\nVerifying updates...") ;
- SetThreadOperationType(pparams, T_READ_VERIFY) ;
- if(0 < WaitForThreads(pparams)){
- printf("\t\t%d thread(s) failed\n") ;
- }else{
- printf("\t\tdone\n") ;
- }
- printf("----------------------\n\n") ;
-
- printf("\nPerforming reads...") ;
- SetThreadOperationType(pparams, T_READ) ;
- if(0 < WaitForThreads(pparams)){
- printf("\t\t%d thread(s) failed\n") ;
- }else{
- printf("\t\tdone\n") ;
- }
- printf("----------------------\n\n") ;
- PrintAll(szTableNames, nNoOfTables, AttributeType) ;
-
-
- if(T_CHAR != AttributeType && nAggregate){
- printf("\nTesting aggregate functions for each table\n\n") ;
- printf("FN\tCOLUMN\tVALUE\t\t\tTOTAL ROWS WHERE\n\t\t\t\t\tVALUE(S) > VALUE\n--------------------------------------------------------\n\n") ;
-
- for(y = 0 ; y < nNoOfTables ; ++y){
- for(x = 0; x < nNoOfCol ; ++x){
- dResultA = dResultB = 0 ;
- AggregateFn(FN_MIN, (char*)(szTableNames + MAX_TABLE_NAME*y), x, NULL, &dResultA, AttributeType) ;
- AggregateFn(FN_COUNT, (char*)(szTableNames + MAX_TABLE_NAME*y) , x, &dResultA, &dResultB, AttributeType) ;
- ATTR_TYPE_SWITCH_AGR("MIN", x, dResultA, dResultB, AttributeType) ;
- }
- }
-
- for(y = 0; y < nNoOfTables ; ++y){
- for(x = 0; x < nNoOfCol ; ++x){
- dResultA = dResultB = 0 ;
- AggregateFn(FN_MAX, (char*)(szTableNames + MAX_TABLE_NAME*y), x, NULL, &dResultA, AttributeType) ;
- AggregateFn(FN_COUNT, (char*)(szTableNames + MAX_TABLE_NAME*y), x, &dResultA, &dResultB, AttributeType) ;
- ATTR_TYPE_SWITCH_AGR("MAX", x, dResultA, dResultB, AttributeType) ;
- }
- }
-
- for(y = 0 ; y < nNoOfTables ; ++y){
- for(x = 0; x < nNoOfCol ; ++x){
- dResultA = dResultB = 0 ;
- AggregateFn(FN_AVG, (char*)(szTableNames + MAX_TABLE_NAME*y), x, NULL, &dResultA, AttributeType) ;
- AggregateFn(FN_COUNT, (char*)(szTableNames + MAX_TABLE_NAME*y), x, &dResultA, &dResultB, AttributeType) ;
- ATTR_TYPE_SWITCH_AGR("AVG", x, dResultA, dResultB, AttributeType)
- }
- }
-
- printf("--------------------------------------------------------\n\n") ;
- }
-
- if(T_CHAR != AttributeType && nArithmetic){
-
- float nVal = (rand() % 10) /1.82342 ;
-
- for(int h = 0 ; h < nNoOfTables ; ++h){
-
- printf("\nTesting arithmetic operators\nfor each column in %s:\n----------------------\n", (char*)(szTableNames + MAX_TABLE_NAME*sizeof(char)*h) ) ;
-
- printf("\nOperator [ * ]... \t\t") ;
- ArithOp((char*)(szTableNames + MAX_TABLE_NAME*sizeof(char)*h), nNoOfCol, &nVal, AttributeType, MULTI) ;
- printf("done\n") ;
-
- printf("\nOperator [ / ]... \t\t") ;
- ArithOp((char*)(szTableNames + MAX_TABLE_NAME*sizeof(char)*h), nNoOfCol, &nVal, AttributeType, DIVIDE) ;
- printf("done\n") ;
-
- printf("\nOperator [ + ]... \t\t") ;
- ArithOp((char*)(szTableNames + MAX_TABLE_NAME*sizeof(char)*h), nNoOfCol, &nVal, AttributeType, PLUS) ;
- printf("done\n") ;
-
- printf("\nOperator [ - ]... \t\t") ;
- ArithOp((char*)(szTableNames + MAX_TABLE_NAME*sizeof(char)*h), nNoOfCol, &nVal, AttributeType, MINUS) ;
- printf("done\n\n") ;
- /*
- printf("\nOperator [ % ]... \t\t") ;
- ArithOp((char*)szTableNames, nNoOfCol, &nVal, AttributeType, MODULO) ;
- printf("done\n\n") ;
- */
- }
- }
-/*
- printf("\nPerforming deletes...") ;
- SetThreadOperationType(pparams, T_DELETE) ;
- if(0 < WaitForThreads(pparams)){
- printf("\t\t%d thread(s) failed\n") ;
- }else{
- printf("\t\tdone\n") ;
- }
- printf("----------------------\n\n") ;
-
- printf("\nVerifying deletes...") ;
- SetThreadOperationType(pparams, T_DELETE_VERIFY) ;
- if(0 < WaitForThreads(pparams)){
- printf("\t\t%d thread(s) failed\n") ;
- }else{
- printf("\t\tdone\n") ;
- }
- printf("----------------------\n\n") ;
-*/
- StopThreads(pparams, pThreadHandles) ;
-
- //PrintAll(szTableNames, nNoOfTables, AttributeType) ;
-
- //CreateDemoTables(szTableNames, nNoOfTables, DROP) ;
-
- free((void*)szTableNames) ;
- free((void*)pparams) ;
- free((void*)pIntRefBuffer) ;
- free((void*)pFloatRefBuffer) ;
- free((void*)pDoubleRefBuffer) ;
- free((void*)pCharRefBuffer) ;
-
- return 0;
-}
-
-
-
-/**************************************************
-Function: ParseArguments
-***************************************************/
-void ParseArguments(int argc, const char** argv){
-
- int i = 1;
-
- while (argc > 1){
-
- if (strcmp(argv[i], "-t") == 0)
- {
- nNoOfThreads = atoi(argv[i+1]);
- if ((nNoOfThreads < 1) || (nNoOfThreads > NDB_MAXTHREADS))
- nNoOfThreads = DEFTHREADS ;
- }
- else if (strcmp(argv[i], "-c") == 0)
- {
- nNoOfCol = atoi(argv[i+1]);
- if ((nNoOfCol < 2) || (nNoOfCol > MAXCOL))
- nNoOfCol = DEFCOL ;
- }
- else if (strcmp(argv[i], "-l") == 0)
- {
- nNoOfLoops = atoi(argv[i+1]);
- if ((nNoOfLoops < 0) || (nNoOfLoops > MAXLOOPS))
- nNoOfLoops = DEFLOOPS ;
- }
- else if (strcmp(argv[i], "-r") == 0)
- {
- nNoOfRows = atoi(argv[i+1]);;
- if ((nNoOfRows < 0) || (nNoOfRows > MAXROW))
- nNoOfRows = DEFROW ;
- }
- else if (strcmp(argv[i], "-m") == 0)
- {
- nArithmetic = 1 ;
- argc++ ;
- i-- ;
- }
- else if (strcmp(argv[i], "-g") == 0)
- {
- nAggregate = 1 ;
- argc++ ;
- i-- ;
- }
- else if (strcmp(argv[i], "-n") == 0)
- {
- nAPI = 1 ;
- argc++ ;
- i-- ;
- }
- else if (strcmp(argv[i], "-v") == 0)
- {
- nPrint = 1 ;
- argc++ ;
- i-- ;
- }
- else if (strcmp(argv[i], "-a") == 0)
- {
- if(strcmp(argv[i+1], "int") == 0){
- AttributeType = T_INT ;
- tAttributeSize = 32 ;
- }else if(strcmp(argv[i+1], "float") == 0){
- AttributeType = T_FLOAT ;
- tAttributeSize = 64 ;
- }else if(strcmp(argv[i+1], "char") == 0){
- AttributeType = T_CHAR ;
- }
- }
- else
- {
- cout << "Arguments:\n";
- cout << "-n Create tables using NDB API (vs ODBC by default)" << endl;
- cout << "-t Number of threads; maximum 24, default 2\n" << endl;
- cout << "-c Number of columns per table; maximum 64, default 4\n" << endl;
- cout << "-r Number of rows; maximum 64, default 8\n" << endl;
- cout << "-a Type of attribute to use: int, double or char; default int " << endl;
- cout << "-g Test aggregate functions" << endl;
- cout << "-m Test arithmetic operators" << endl;
- cout << "-v Print executed statements" << endl;
- exit(-1);
- }
-
- argc -= 2 ;
- i = i + 2 ;
- }
-
-char *szAttrType[MAX_STR_LEN] = { 0 } ;
-switch(AttributeType){
- case T_INT:
- strcpy((char*)szAttrType, "Integer") ;
- break ;
- case T_FLOAT:
- strcpy((char*)szAttrType, "Float") ;
- break ;
-/* case T_DOUBLE:
- strcpy((char*)szAttrType, "Double") ;
- break ;
-*/
- case T_CHAR:
- strcpy((char*)szAttrType, "Character") ;
- break ;
- default:
- strcpy((char*)szAttrType, "Not defined") ;
- break ;
- }
-
-
-printf("\n\nCurrent parameters: %d thread(s), %d tables, %d rows, %d colums, attribute type: %s\n\n", nNoOfThreads, nNoOfTables, nNoOfRows, nNoOfCol, szAttrType) ;
- }
-
-
-
-
-/*************************************************
-Function: ThreadFnInt - thread function
-for int attributes
-*************************************************/
-void* ThreadFnInt(void* pparams){
-
- SQLRETURN retcode = SQL_ERROR ;
- SQLCHAR szStmtBuffer[MAX_SQL_STMT] = { 0 } ;
- SQLCHAR szValueBuffer[MAX_VALUE_LEN] = { 0 } ;
- SQLCHAR szAuxBuffer[MAX_STR_LEN] = { 0 } ;
- SQLCHAR szColBuffer[MAX_COL_NAME] = { 0 } ;
- SQLINTEGER cbInt = 0 ;
- ODBC_HANDLES stHandles ;
- memset(&stHandles, 0, sizeof(ODBC_HANDLES)) ;
-
- int r = 0, j = 0 ;
- //Get thread parameters
- PARAMS* p = (PARAMS*)pparams ;
- int* pRef = (int*)p->pThreadRef ;
-
- int* pBindBuffer = (int*)malloc(sizeof(int)*nNoOfCol) ;
-
- //printf("Thread #%d\n", p->nThreadID) ;
-
- retcode = GetHandles(&stHandles, GET, 0) ;
-
- if (SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode ) {
- p->report_status = S_STARTED ;
- }else{
- printf("Thread #%d failed to allocate handles, exiting now.\n", p->nThreadID) ;
- free((void*)pBindBuffer) ;
- p->nError = 1 ;
- p->report_status = S_EXIT ;
- return 0 ;
- }
-
- //p->report_status = S_STARTED ;
-
- //Main thread loop
- for(;;){
-
- while(S_IDLE == p->thread_status){
- NdbSleep_MilliSleep(1) ;
- }
-
- if(S_STOP == p->thread_status) {
- break ;
- }else{
- p->thread_status = S_BUSY ;
- }
-
- switch(p->op_type){
-
-
- /************************************** T_INSERT case **************************************/
- case T_INSERT:
-
- for(r = 0 ; r < nNoOfRows ; ++r){
-
- if(!nColList){
- sprintf((char*)szStmtBuffer, "INSERT INTO %s VALUES(", p->szTableName) ;
- }else{
- sprintf((char*)szStmtBuffer, "INSERT INTO %s (%s) VALUES(", p->szTableName, szColNames) ;
- }
-
- //sprintf((char*)szStmtBuffer, "INSERT INTO %s VALUES(", p->szTableName) ;
-
- for(j = 0 ;;){
- sprintf((char*)szValueBuffer,"%d", pRef[nNoOfCol*r + j]) ;
- strncat((char*)szStmtBuffer, (char*)szValueBuffer, strlen((char*)szValueBuffer)) ;
- ++j ;
- if(nNoOfCol == j) break ;
- strcat((char*)szStmtBuffer, ", ") ;
- }
- strcat((char*)szStmtBuffer, ")") ;
- if(nPrint) printf("\n> %s\n", szStmtBuffer) ;
- retcode = SQLExecDirect(stHandles.hstmt, szStmtBuffer, SQL_NTS) ;
- if(SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode){
- }else{
- p->nError = 1 ;
- printf("INSERT in thread #%d failed\n", p->nThreadID) ;
- HandleError(stHandles.hstmt, SQL_HANDLE_STMT) ;
- }
- }
- break ;
-
-
- /************************************** T_READ case **************************************/
- case T_READ:
-
- for(r = 0 ; r < nNoOfRows ; r++){
-
- sprintf((char*)szStmtBuffer, "SELECT * FROM %s WHERE COL0 = %d", p->szTableName, pRef[nNoOfCol*r]) ;
- if(nPrint) printf("\n> %s\n", szStmtBuffer) ;
- ODBC_FN(SQLExecDirect(stHandles.hstmt, (SQLCHAR*)szStmtBuffer, SQL_NTS), retcode) ;
-
- for(j = 0 ; j < nNoOfCol ; ++j){
- ODBC_FN(SQLBindCol(stHandles.hstmt, (j+1), SQL_C_SLONG, (void*)&pBindBuffer[j], sizeof(SQLINTEGER), &cbInt), retcode) ;
- }
-
- for (;;) {
- retcode = SQLFetch(stHandles.hstmt);
-
- if (SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode){
- for(int k = 0 ; k < nNoOfCol ; ++k){
- if(p->nVerifyFlag){
- if(pBindBuffer[k] != pRef[nNoOfCol*r + k])
- printf("Expected: %d Actual: %d\n", pBindBuffer[k], pRef[nNoOfCol*r + k]) ;
- }
- }
- }else if(SQL_NO_DATA == retcode){
- break ;
- }else{
- p->nError = 1 ;
- printf("READ in thread #%d failed\n", p->nThreadID) ;
- HandleError(stHandles.hstmt, SQL_HANDLE_STMT) ;
- }
- //printf("\n") ;
- }
- SQLCloseCursor(stHandles.hstmt) ;
- }
- break ;
-
-
- /************************************** T_UPDATE case **************************************/
- case T_UPDATE:
- for(r = 0 ; r < nNoOfRows ; ++r){
-
- sprintf((char*)szStmtBuffer, "UPDATE %s SET ", p->szTableName) ;
- for(j = 1 ;;){
- pRef[nNoOfCol*r + j] = pRef[nNoOfCol*r + j] + UPDATE_VALUE ;
- sprintf((char*)szColBuffer,"COL%d = %d", j, pRef[nNoOfCol*r + j]) ;
- strncat((char*)szStmtBuffer, (char*)szColBuffer, strlen((char*)szColBuffer)) ;
- ++j ;
- if(nNoOfCol == j) break ;
- strcat((char*)szStmtBuffer, ", ") ;
- }
- sprintf((char*)szAuxBuffer, " WHERE COL0 = %d ;", pRef[nNoOfCol*r]) ;
- strcat((char*)szStmtBuffer, (char*)szAuxBuffer);
- if(nPrint) printf("\n> %s\n", szStmtBuffer) ;
- retcode = SQLExecDirect(stHandles.hstmt, szStmtBuffer, SQL_NTS) ;
-
- if(SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode){
- }else{
- p->nError = 1 ;
- printf("UPDATE in thread %d failed\n", p->nThreadID) ;
- HandleError(stHandles.hstmt, SQL_HANDLE_STMT) ;
- }
- }
- break ;
-
-
- /************************************** T_DELETE case **************************************/
- case T_DELETE:
- for(r = 0 ; r < nNoOfRows ; ++r){
- sprintf((char*)szStmtBuffer, "DELETE * FROM %s WHERE COL0 = %d", p->szTableName, pRef[nNoOfCol*r]) ;
- if(nPrint) printf("\n> %s\n", szStmtBuffer) ;
- retcode = SQLExecDirect(stHandles.hstmt, szStmtBuffer, SQL_NTS) ;
- if(SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode){
- }else if( 1 == p->nVerifyFlag && SQL_NO_DATA != retcode){
- p->nError = 1 ;
- printf("\nVerification failed: the row found\n") ;
- }else{
- p->nError = 1 ;
- printf("INSERT in thread %d failed\n", p->nThreadID) ;
- HandleError(stHandles.hstmt, SQL_HANDLE_STMT) ;
- }
-
- }
- break ;
-
-
- /************************************** default case **************************************/
- default:
- break ;
- }//switch
-p->thread_status = S_IDLE ;
- } //for
-
-free((void*)pBindBuffer) ;
-GetHandles(&stHandles, FREE, 0) ;
-p->thread_status = S_EXIT ;
-return 0 ;
- };
-
-
-
-/*************************************************
-Function: ThreadFnFloat - thread function
-for float attributes
-*************************************************/
-void* ThreadFnFloat(void* pparams){
-
- SQLRETURN retcode = SQL_ERROR ;
- SQLCHAR szStmtBuffer[MAX_SQL_STMT] = { 0 } ;
- SQLCHAR szValueBuffer[MAX_VALUE_LEN] = { 0 } ;
- SQLCHAR szAuxBuffer[MAX_STR_LEN] = { 0 } ;
- SQLCHAR szColBuffer[MAX_COL_NAME] = { 0 } ;
- SQLINTEGER cbFloat = 0 ;
- ODBC_HANDLES stHandles ;
- memset(&stHandles, 0, sizeof(ODBC_HANDLES)) ;
-
- int r = 0, j = 0 ;
- //Get thread parameters
- PARAMS* p = (PARAMS*)pparams ;
-
- float* pRef = (float*)p->pThreadRef ;
- float* pBindBuffer = (float*)malloc(sizeof(float)*nNoOfCol) ;
-
- //printf("Thread #%d\n", p->nThreadID) ;
-
- retcode = GetHandles(&stHandles, GET, 0) ;
-
- if (SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode ) {
- p->report_status = S_STARTED ;
- }else{
- printf("Thread #%d failed to allocate handles, exiting now.\n", p->nThreadID) ;
- free((void*)pBindBuffer) ;
- p->nError = 1 ;
- p->report_status = S_EXIT ;
- return 0 ;
- }
-
- //p->report_status = S_STARTED ;
-
- //Main thread loop
- for(;;){
-
- while(S_IDLE == p->thread_status){
- NdbSleep_MilliSleep(1) ;
- }
-
- if(S_STOP == p->thread_status) {
- break ;
- }else{
- p->thread_status = S_BUSY ;
- }
-
- switch(p->op_type){
-
-
- /************************************** T_INSERT case **************************************/
- case T_INSERT:
-
- for(r = 0 ; r < nNoOfRows ; ++r){
-
- if(!nColList){
- sprintf((char*)szStmtBuffer, "INSERT INTO %s VALUES(", p->szTableName) ;
- }else{
- sprintf((char*)szStmtBuffer, "INSERT INTO %s (%s) VALUES(", p->szTableName, szColNames) ;
- }
-
- //sprintf((char*)szStmtBuffer, "INSERT INTO %s VALUES(", p->szTableName) ;
-
- for(j = 0 ;;){
- sprintf((char*)szValueBuffer,"%f", pRef[nNoOfCol*r + j]) ;
- strncat((char*)szStmtBuffer, (char*)szValueBuffer, strlen((const char*)szValueBuffer)) ;
- ++j ;
- if(nNoOfCol == j) break ;
- strcat((char*)szStmtBuffer, ", ") ;
- }
- strcat((char*)szStmtBuffer, ")") ;
- if(nPrint) printf("\n> %s\n", szStmtBuffer) ;
- retcode = SQLExecDirect(stHandles.hstmt, szStmtBuffer, SQL_NTS) ;
- if(SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode){
- }else{
- p->nError = 1 ;
- printf("INSERT in thread #%d failed\n", p->nThreadID) ;
- HandleError(stHandles.hstmt, SQL_HANDLE_STMT) ;
- }
- }
- break ;
-
-
- /************************************** T_READ case **************************************/
- case T_READ:
-
- for(r = 0 ; r < nNoOfRows ; ++r){
-
- sprintf((char*)szStmtBuffer, "SELECT * FROM %s WHERE COL0 = %f", p->szTableName, pRef[nNoOfCol*r]) ;
- if(nPrint) printf("\n> %s\n", szStmtBuffer) ;
- ODBC_FN(SQLExecDirect(stHandles.hstmt, (SQLCHAR*)szStmtBuffer, SQL_NTS), retcode) ;
-
- for(j = 0 ; j < nNoOfCol ; ++j){
- ODBC_FN(SQLBindCol(stHandles.hstmt, (j+1), SQL_C_FLOAT, (void*)&pBindBuffer[j], sizeof(SQLFLOAT), &cbFloat), retcode) ;
- }
-
- for (;;) {
- retcode = SQLFetch(stHandles.hstmt);
-
- if (SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode){
- for(int k = 0 ; k < nNoOfCol ; ++k){
- if(p->nVerifyFlag){
- if(abs(pBindBuffer[k] - pRef[nNoOfCol*r + k]) > FLTDEV )
- printf("Expected: %f Actual: %f\n", pBindBuffer[k], pRef[nNoOfCol*r + k]) ;
- }
- }
- }else if(SQL_NO_DATA == retcode){
- break ;
- }else{
- p->nError = 1 ;
- printf("READ in thread #%d failed\n", p->nThreadID) ;
- HandleError(stHandles.hstmt, SQL_HANDLE_STMT) ;
- }
- //printf("\n") ;
- }
- SQLCloseCursor(stHandles.hstmt) ;
- }
- break ;
-
-
- /************************************** T_UPDATE case **************************************/
- case T_UPDATE:
- for(r = 0 ; r < nNoOfRows ; ++r){
-
- sprintf((char*)szStmtBuffer, "UPDATE %s SET ", p->szTableName) ;
- for(j = 1 ;;){
- pRef[nNoOfCol*r + j] = pRef[nNoOfCol*r + j] + UPDATE_VALUE ;
- sprintf((char*)szColBuffer,"COL%d = %f", j, pRef[nNoOfCol*r + j]) ;
- strncat((char*)szStmtBuffer, (char*)szColBuffer, strlen((char*)szColBuffer)) ;
- ++j ;
- if(nNoOfCol == j) break ;
- strcat((char*)szStmtBuffer, ", ") ;
- }
- sprintf((char*)szAuxBuffer, " WHERE COL0 = %f ;", pRef[nNoOfCol*r]) ;
- strcat((char*)szStmtBuffer, (char*)szAuxBuffer);
- if(nPrint) printf("\n> %s\n", szStmtBuffer) ;
- retcode = SQLExecDirect(stHandles.hstmt, szStmtBuffer, SQL_NTS) ;
- if(SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode){
- }else{
- p->nError = 1 ;
- printf("UPDATE in thread #%d failed\n", p->nThreadID) ;
- HandleError(stHandles.hstmt, SQL_HANDLE_STMT) ;
- }
- }
- break ;
-
-
- /************************************** T_DELETE case **************************************/
- case T_DELETE:
- for(r = 0 ; r < nNoOfRows ; ++r){
- sprintf((char*)szStmtBuffer, "DELETE * FROM %s WHERE COL0 = %f", p->szTableName, pRef[nNoOfCol*r]) ;
- if(nPrint) printf("\n> %s\n", szStmtBuffer) ;
- retcode = SQLExecDirect(stHandles.hstmt, (SQLCHAR*)szStmtBuffer, SQL_NTS) ;
- if(SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode){
- }else if( 1 == p->nVerifyFlag && SQL_NO_DATA != retcode){
- p->nError = 1 ;
- printf("\nVerification failed: still row exists\n") ;
- }else{
- p->nError = 1 ;
- printf("DELETE in thread #%d failed\n", p->nThreadID) ;
- HandleError(stHandles.hstmt, SQL_HANDLE_STMT) ;
- }
- }
- break ;
-
-
- /************************************** default case **************************************/
- default:
- break ;
- }//switch
-p->thread_status = S_IDLE ;
- } //for
-
-free((void*)pBindBuffer) ;
-GetHandles(&stHandles, FREE, 0) ;
-p->thread_status = S_EXIT ;
-return 0 ;
- };
-
-
-
-/*************************************************
-Function: ThreadFnDouble - thread function
-for double attributes
-*************************************************/
-/*
-void* ThreadFnDouble(void* pparams){
-
- SQLRETURN retcode = SQL_ERROR ;
- SQLCHAR szStmtBuffer[MAX_SQL_STMT] = { 0 } ;
- SQLCHAR szValueBuffer[MAX_VALUE_LEN] = { 0 } ;
- SQLCHAR szAuxBuffer[MAX_STR_LEN] = { 0 } ;
- SQLCHAR szColBuffer[MAX_COL_NAME] = { 0 } ;
- SQLINTEGER cbDouble = 0 ;
- ODBC_HANDLES stHandles ;
- memset(&stHandles, 0, sizeof(ODBC_HANDLES)) ;
- int r = 0, j = 0 ;
-
- //Get thread parameters
- PARAMS* p = (PARAMS*)pparams ;
- double* pRef = (double*)p->pThreadRef ;
-
- double* pBindBuffer = (double*)malloc(sizeof(double)*nNoOfCol) ;
-
- //printf("Thread #%d\n", p->nThreadID) ;
-
- retcode = GetHandles(&stHandles, GET, 0) ;
-
- if (SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode ) {
- p->report_status = S_STARTED ;
- }else{
- printf("Thread #%d failed to allocate handles, exiting now.\n", p->nThreadID) ;
- free((void*)pBindBuffer) ;
- p->report_status = S_EXIT ;
- return 0 ;
- }
- //p->report_status = S_STARTED ;
-
- //Main thread loop
- for(;;){
-
- while(S_IDLE == p->thread_status){
- NdbSleep_MilliSleep(1) ;
- }
-
- if(S_STOP == p->thread_status) {
- break ;
- }else{
- p->thread_status = S_BUSY ;
- }
-
- switch(p->op_type){
-
-
- /************************************** T_INSERT case **************************************/
- /* case T_INSERT:
-
- for(r = 0 ; r < nNoOfRows ; ++r){
- sprintf((char*)szStmtBuffer, "INSERT INTO %s VALUES(", p->szTableName) ;
- for(j = 0 ;;){
- sprintf((char*)szValueBuffer,"%.9f", pRef[nNoOfCol*r + j]) ;
- strncat((char*)szStmtBuffer, (char*)szValueBuffer, strlen((const char*)szValueBuffer)) ;
- ++j ;
- if(nNoOfCol == j) break ;
- strcat((char*)szStmtBuffer, ", ") ;
- }
- strcat((char*)szStmtBuffer, ")") ;
- ODBC_FN(SQLExecDirect(stHandles.hstmt, szStmtBuffer, SQL_NTS), retcode) ;
- }
-
- break ;
-
-
- /************************************** T_READ case **************************************/
- /* case T_READ:
-
- for(r = 0 ; r < nNoOfRows ; ++r){
- sprintf((char*)szStmtBuffer, "SELECT * FROM %s WHERE COL0 = %.9f", p->szTableName, pRef[nNoOfCol*r]) ;
- ODBC_FN(SQLExecDirect(stHandles.hstmt, (SQLCHAR*)szStmtBuffer, SQL_NTS), retcode) ;
- for(j = 0 ; j < nNoOfCol ; ++j){
- ODBC_FN(SQLBindCol(stHandles.hstmt, (j+1), SQL_C_DOUBLE, (void*)&pBindBuffer[j], sizeof(SQLDOUBLE), &cbDouble), retcode) ;
- }
- for (;;) {
- retcode = SQLFetch(stHandles.hstmt);
-
- if (SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode){
- for(int k = 0 ; k < nNoOfCol ; ++k){
- if(p->nVerifyFlag){
- if(abs(pBindBuffer[k] - pRef[nNoOfCol*r + k]) > DBLDEV)
- printf("Expected: %.9f Actual: %.9f\n", pBindBuffer[k], pRef[nNoOfCol*r + k]) ;
- }
- }
- }else if(SQL_NO_DATA == retcode){
- break ;
- }else{
- HandleError(stHandles.hstmt, SQL_HANDLE_STMT) ;
- }
- //printf("\n") ;
- }
- SQLCloseCursor(stHandles.hstmt) ;
- }
- break ;
-
-
- /************************************** T_UPDATE case **************************************/
- /* case T_UPDATE:
- for(r = 0 ; r < nNoOfRows ; ++r){
-
- sprintf((char*)szStmtBuffer, "UPDATE %s SET ", p->szTableName) ;
- for(j = 1 ;;){
- pRef[nNoOfCol*r + j] = pRef[nNoOfCol*r + j] + UPDATE_VALUE ;
- sprintf((char*)szColBuffer,"COL%d = %.9f", j, pRef[nNoOfCol*r + j]) ;
- strncat((char*)szStmtBuffer, (char*)szColBuffer, strlen((char*)szColBuffer)) ;
- ++j ;
- if(nNoOfCol == j) break ;
- strcat((char*)szStmtBuffer, ", ") ;
- }
- sprintf((char*)szAuxBuffer, " WHERE COL0 = %.9f ;", pRef[nNoOfCol*r]) ;
- strcat((char*)szStmtBuffer, (char*)szAuxBuffer);
- ODBC_FN(SQLExecDirect(stHandles.hstmt, szStmtBuffer, SQL_NTS), retcode) ;
- }
- break ;
-
-
- /************************************** T_DELETE case **************************************/
- /* case T_DELETE:
- for(r = 0 ; r < nNoOfRows ; ++r){
- sprintf((char*)szStmtBuffer, "DELETE FROM %s WHERE COL0 = %.9f", p->szTableName, pRef[nNoOfCol*r]) ;
- retcode = SQLExecDirect(stHandles.hstmt, (SQLCHAR*)szStmtBuffer, SQL_NTS) ;
- if( 1 == p->nVerifyFlag && SQL_NO_DATA != retcode ){
- printf("\nVerification failed: still row exists\n") ;
- }
- }
- break ;
-
-
- /************************************** default case **************************************/
- /* default:
- break ;
- }//switch
-p->thread_status = S_IDLE ;
- } //for
-
-free((void*)pBindBuffer) ;
-GetHandles(&stHandles, FREE, 0) ;
-p->thread_status = S_EXIT ;
-return 0 ;
- };
-
-
-
-/*************************************************
-Function: ThreadFnChar - thread function
-for character attributes
-*************************************************/
-void* ThreadFnChar(void* pparams){
-
- SQLRETURN retcode = SQL_ERROR ;
- SQLCHAR szStmtBuffer[MAX_SQL_STMT] = { 0 } ;
- SQLCHAR szValueBuffer[MAX_VALUE_LEN] = { 0 } ;
- SQLCHAR szAuxBuffer[MAX_STR_LEN] = { 0 } ;
- SQLCHAR szColBuffer[MAX_COL_NAME] = { 0 } ;
- SQLINTEGER cbChar = 0 ;
- ODBC_HANDLES stHandles ;
- memset(&stHandles, 0, sizeof(ODBC_HANDLES)) ;
- int r = 0, j = 0 ;
-
- //Get thread parameters
- PARAMS* p = (PARAMS*)pparams ;
- char* pRef = (char*)p->pThreadRef ;
- char* pBindBuffer = (char*)malloc(sizeof(char)*nNoOfCol*MAX_CHAR_ATTR_LEN) ;
-
- //printf("Thread #%d\n", p->nThreadID) ;
-
- retcode = GetHandles(&stHandles, GET, 0) ;
-
- if (SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode ) {
- p->report_status = S_STARTED ;
- }else{
- printf("Thread #%d failed to allocate handles, retcode = %d, exiting now.\n", p->nThreadID, retcode) ;
- p->nError = 1 ;
- free((void*)pBindBuffer) ;
- p->report_status = S_EXIT ;
- return 0 ;
- }
-
- //Main thread loop
- for(;;){
-
- while(S_IDLE == p->thread_status){
- NdbSleep_MilliSleep(1) ;
- }
-
- if(S_STOP == p->thread_status) {
- break ;
- }else{
- p->thread_status = S_BUSY ;
- }
-
- switch(p->op_type){
-
-
- /************************************** T_INSERT case **************************************/
- case T_INSERT:
-
- for(r = 0 ; r < nNoOfRows ; ++r){
- memset(szStmtBuffer, 0, strlen(szStmtBuffer)) ;
- if(!nColList){
- sprintf((char*)szStmtBuffer, "INSERT INTO %s VALUES(", p->szTableName) ;
- }else{
- sprintf((char*)szStmtBuffer, "INSERT INTO %s (%s) VALUES(", p->szTableName, szColNames) ;
- }
-
- for(j = 0 ;;){
- sprintf((char*)szValueBuffer,"'%s'", (char*)(pRef + nNoOfCol*r*MAX_CHAR_ATTR_LEN*sizeof(char) + j*MAX_CHAR_ATTR_LEN*sizeof(char))) ;
- strncat((char*)szStmtBuffer, (char*)szValueBuffer, strlen((const char*)szValueBuffer)) ;
- ++j ;
- if(nNoOfCol == j) break ;
- strcat((char*)szStmtBuffer, ", ") ;
- }
- strcat((char*)szStmtBuffer, ")") ;
-
- if(nPrint) printf("\n> %s\n", szStmtBuffer) ;
- retcode = SQLExecDirect(stHandles.hstmt, szStmtBuffer, SQL_NTS) ;
- if(SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode){
- }else{
- p->nError = 1 ;
- printf("INSERT in thread #%d failed\n", p->nThreadID) ;
- HandleError(stHandles.hstmt, SQL_HANDLE_STMT) ;
- }
- }
-
- break ;
-
-
- /************************************** T_READ case **************************************/
- case T_READ:
-
- for(r = 0 ; r < nNoOfRows ; ++r){
- sprintf((char*)szStmtBuffer, "SELECT * FROM %s WHERE COL0 = '%s'", p->szTableName, (char*)(pRef + nNoOfCol*r*MAX_CHAR_ATTR_LEN*sizeof(char))) ;
- if(nPrint) printf("\n> %s\n", szStmtBuffer) ;
- ODBC_FN(SQLExecDirect(stHandles.hstmt, (SQLCHAR*)szStmtBuffer, SQL_NTS), retcode) ;
- for(j = 0 ; j < nNoOfCol ; ++j){
- ODBC_FN(SQLBindCol(stHandles.hstmt, (j+1), SQL_C_CHAR, (void*)(pBindBuffer+j*MAX_CHAR_ATTR_LEN*sizeof(char)), MAX_CHAR_ATTR_LEN, &cbChar), retcode) ;
- }
- for (;;) {
- retcode = SQLFetch(stHandles.hstmt);
-
- if (SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode){
- for(int k = 0 ; k < nNoOfCol ; ++k){
- if(p->nVerifyFlag){
- if(!strcmp((char*)(pBindBuffer + k*MAX_CHAR_ATTR_LEN*sizeof(char)), (char*)(pRef + nNoOfCol*r*MAX_CHAR_ATTR_LEN*sizeof(char) + k*MAX_CHAR_ATTR_LEN*sizeof(char))))
- printf("Expected: %s Actual: %s\n", (char*)(pBindBuffer + k*MAX_CHAR_ATTR_LEN*sizeof(char)), (char*)(pRef + nNoOfCol*r*MAX_CHAR_ATTR_LEN*sizeof(char) + k*MAX_CHAR_ATTR_LEN*sizeof(char))) ;
- }
- }
- }else if(SQL_NO_DATA == retcode){
- break ;
- }else{
- p->nError = 1 ;
- printf("READ in thread #%d failed\n", p->nThreadID) ;
- HandleError(stHandles.hstmt, SQL_HANDLE_STMT) ;
- }
- //printf("\n") ;
- }
- SQLCloseCursor(stHandles.hstmt) ;
- }
- break ;
-
-
- /************************************** T_UPDATE case **************************************/
- case T_UPDATE:
- for(r = 0 ; r < nNoOfRows ; ++r){
- sprintf((char*)szStmtBuffer, "UPDATE %s SET ", p->szTableName) ;
- for(j = 1 ;;){
- swab((char*)(pRef + nNoOfCol*r*MAX_CHAR_ATTR_LEN*sizeof(char) + j*MAX_CHAR_ATTR_LEN*sizeof(char)), (char*)szColBuffer, MAX_CHAR_ATTR_LEN*sizeof(char)) ;
- memcpy((void*)(pRef + nNoOfCol*r*MAX_CHAR_ATTR_LEN*sizeof(char) + j*MAX_CHAR_ATTR_LEN*sizeof(char)), (void*)szColBuffer, MAX_CHAR_ATTR_LEN*sizeof(char)) ;
- sprintf((char*)szColBuffer,"COL%d = '%s'", j, (char*)(pRef + nNoOfCol*r*MAX_CHAR_ATTR_LEN*sizeof(char) + j*MAX_CHAR_ATTR_LEN*sizeof(char))) ;
- strncat((char*)szStmtBuffer, (char*)szColBuffer, strlen((char*)szColBuffer)) ;
- ++j ;
- if(nNoOfCol == j) break ;
- strcat((char*)szStmtBuffer, ", ") ;
- }
- sprintf( (char*)szAuxBuffer, " WHERE COL0 = '%s';", (char*)(pRef + nNoOfCol*r*MAX_CHAR_ATTR_LEN*sizeof(char)) ) ;
- strcat((char*)szStmtBuffer, (char*)szAuxBuffer) ;
- if(nPrint) printf("\n> %s\n", szStmtBuffer) ;
- retcode = SQLExecDirect(stHandles.hstmt, szStmtBuffer, SQL_NTS) ;
- if(SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode){
- }else{
- p->nError = 1 ;
- printf("UPDATE in thread #%d failed\n", p->nThreadID) ;
- HandleError(stHandles.hstmt, SQL_HANDLE_STMT) ;
- }
- }
- break ;
-
-
- /************************************** T_DELETE case **************************************/
- case T_DELETE:
- for(r = 0 ; r < nNoOfRows ; ++r){
- sprintf((char*)szStmtBuffer, "DELETE FROM %s WHERE COL0 = '%s\'", p->szTableName, (char*)(pRef + nNoOfCol*r*MAX_CHAR_ATTR_LEN*sizeof(char))) ;
- if(nPrint) printf("\n> %s\n", szStmtBuffer) ;
- retcode = SQLExecDirect(stHandles.hstmt, szStmtBuffer, SQL_NTS) ;
- if(SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode){
- }else if(1 == p->nVerifyFlag && SQL_NO_DATA != retcode){
- p->nError = 1 ;
- printf("\nVerification failed: still row exists\n") ;
- }else{
- p->nError = 1 ;
- printf("INSERT in thread #%d failed\n", p->nThreadID) ;
- HandleError(stHandles.hstmt, SQL_HANDLE_STMT) ;
- }
- }
- break ;
-
-
- /************************************** default case **************************************/
- default:
- break ;
- }//switch
- p->thread_status = S_IDLE ;
- } //for
-
- free((void*)pBindBuffer) ;
- GetHandles(&stHandles, FREE, 0) ;
- p->thread_status = S_EXIT ;
- return 0 ;
-};
-
-
-
-/*************************************************
-Function: CreateDemoTable
-*************************************************/
-SQLRETURN CreateDemoTables(char* szTableName, int nTables, table_opt op){
-
- SQLRETURN retcode = SQL_ERROR ;
- SQLCHAR szStmtBuffer[MAX_SQL_STMT] = { 0 } ;
- SQLCHAR szColBuffer[MAX_COL_NAME] = { 0 } ;
- SQLCHAR szAuxBuffer[32] = { 0 } ;
- ODBC_HANDLES stHandles ;
- memset(&stHandles, 0, sizeof(ODBC_HANDLES)) ;
- int c = 0 ;
-
- GetHandles(&stHandles, GET, 0) ;
-
- if(CREATE == op){
-
- for(c = 0; c < nTables ; ++c){
- sprintf((char*)szStmtBuffer, "CREATE TABLE %s (", (char*)(szTableName+MAX_TABLE_NAME*c)) ;
- int j = 0 ;
- for(;;){
- sprintf((char*)szColBuffer, "COL%d ", j) ;
- strcat((char*)szStmtBuffer, (char*)szColBuffer) ;
- ++j ;
-
- switch(AttributeType){
- case T_INT:
- strcat((char*)szStmtBuffer, "INTEGER") ;
- break ;
- case T_FLOAT:
- strcat((char*)szStmtBuffer, "FLOAT") ;
- break ;
-
-/* case T_DOUBLE:
- strcat((char*)szStmtBuffer, "DOUBLE") ;
- break ;
-*/
- case T_CHAR:
- sprintf((char*)szAuxBuffer, "CHAR(%d)", MAX_CHAR_ATTR_LEN) ;
- strcat((char*)szStmtBuffer, (char*)szAuxBuffer) ;
- break ;
- default:
- break ;
- }
-
- if(nNoOfCol <= j){
- strcat((char*)szStmtBuffer, ")") ;
- break ;
- }
- strcat((char*)szStmtBuffer, ", ") ;
- } //for(;;)
-
-
- if(nPrint) printf("\n> %s\n", szStmtBuffer) ;
- ODBC_FN(SQLExecDirect(stHandles.hstmt, szStmtBuffer, SQL_NTS), retcode) ;
- if(SQL_SUCCESS != retcode) HandleError(stHandles.hstmt , SQL_HANDLE_STMT) ;
-
-
- }// for()
-
- }else{
-
- for(c = 0 ; c < nTables ; ++c){
- sprintf((char*)szStmtBuffer, "DROP TABLE %s ", (char*)(szTableName + MAX_TABLE_NAME*c)) ;
- //ODBC_FN(SQLExecDirect(stHandles.hstmt, szStmtBuffer, SQL_NTS), retcode) ;
- if(nPrint) printf("\n> %s\n", szStmtBuffer) ;
- retcode = SQLExecDirect(stHandles.hstmt, szStmtBuffer, SQL_NTS) ;
- }
-
- }
-
- GetHandles(&stHandles, FREE, 0) ;
-
- return retcode ;
-}
-
-
-
-/*************************************************
-Function: AssignTableNames()
-*************************************************/
-inline void AssignTableNames(char* szBuffer, int nTables){
- for(int c = 0 ; c < nTables ; ++c){
- sprintf((char*)(szBuffer + MAX_TABLE_NAME*sizeof(char)*c), "TAB%d", c) ;
- }
-return ;
- }
-
-
-
-
-/*************************************************
-Function: StartThreads()
-*************************************************/
-
-inline void StartThreads(PARAMS* p, void* pRef, int nTables, char* szTables, attr_type attrType, UintPtr* pHandles) {
-
- int* pInt = NULL ;
- float* pFloat = NULL ;
- double* pDouble = NULL ;
- char* pChar = NULL ;
- UintPtr pTmpThread = NULL ;
-
- bool bFlap = 1 ;
- for(int f = 0 ; f < nNoOfThreads ; ++f){
- p[f].nThreadID = f ;
- p[f].nError = 0 ;
- p[f].thread_status = S_IDLE ;
- p[f].op_type = T_WAIT ;
- if(bFlap){
- strncpy((char*)p[f].szTableName, (char*)szTables, MAX_TABLE_NAME) ;
- }else{
- strncpy((char*)p[f].szTableName, (char*)(szTables + MAX_TABLE_NAME*sizeof(char)), MAX_TABLE_NAME) ;
- }
- bFlap = !bFlap ;
- //pTmpThread = pHandles[ ;
-
- switch(attrType){
- case T_INT:
- pInt = (int*)pRef ;
- p[f].pThreadRef = (void*)&pInt[nNoOfRows*nNoOfCol*f] ;
- pHandles[f] = (UintPtr)NdbThread_Create(ThreadFnInt, (void**)&p[f], 32768, "SQL99_test", NDB_THREAD_PRIO_MEAN) ;
- break ;
- case T_FLOAT:
- pFloat = (float*)pRef ;
- p[f].pThreadRef = (void*)&pFloat[nNoOfRows*nNoOfCol*f] ;
- pHandles[f] = (UintPtr)NdbThread_Create(ThreadFnFloat, (void**)&p[f], 32768, "SQL99_test", NDB_THREAD_PRIO_MEAN) ;
- break ;
- /*
- case T_DOUBLE:
- pDouble = (double*)pRef ;
- p[f].pThreadRef = (void*)&pDouble[nNoOfRows*nNoOfCol*f] ;
- pHandles[f] = (UintPtr)NdbThread_Create(ThreadFnDouble, (void**)&p[f], 32768, "SQL99_test", NDB_THREAD_PRIO_MEAN) ;
- break ;
- */
- case T_CHAR:
- pChar = (char*)pRef ;
- p[f].pThreadRef = (void*)&pChar[nNoOfRows*nNoOfCol*f*MAX_CHAR_ATTR_LEN] ;
- pHandles[f] = (UintPtr)NdbThread_Create(ThreadFnChar, (void**)&p[f], 32768, "SQL99_test", NDB_THREAD_PRIO_MEAN) ;
- default:
- break ;
- }
- while(!(S_STARTED != p[f].report_status || S_EXIT != p[f].report_status)){
- NdbSleep_MilliSleep(1) ;
- }
- }
- return ;
-}
-
-
-
-/*************************************************
-Function: SetThreadOperationType()
-*************************************************/
-inline void SetThreadOperationType(PARAMS* p, type op){
-
- for(int e = 0 ; e < nNoOfThreads ; ++e){
- p[e].nVerifyFlag = 0 ;
- if(T_READ_VERIFY == op){
- p[e].nVerifyFlag = 1 ;
- p[e].op_type = T_READ ;
- }else if(T_DELETE_VERIFY == op){
- p[e].nVerifyFlag = 1 ;
- p[e].op_type = T_DELETE ;
- }else{
- p[e].op_type = op ;
- }
- p[e].thread_status = S_GET_BUSY ;
- }
-return ;
- }
-
-
-
-/*************************************************
-Function: WaitForThreads()
-*************************************************/
-inline int WaitForThreads(PARAMS* p) {
-
- int ret_value = 0 ;
- for(int w = 0 ; w < nNoOfThreads ; ++w){
- while(!(S_IDLE != p[w].thread_status || S_EXIT != p[w].report_status)) {
- NdbSleep_MilliSleep(1) ;
- }
- ret_value += p[w].nError ;
- }
- return ret_value ;
-}
-
-
-
-/*************************************************
-Function: StopThreads()
-*************************************************/
-inline void StopThreads(PARAMS* p, UintPtr* pHandles) {
-
- for(int k = 0 ; k < nNoOfThreads ; ++k){
- while(!(S_IDLE != p[k].thread_status || S_EXIT != p[k].report_status)){
- NdbSleep_MilliSleep(1) ;
- }
- p[k].thread_status = S_STOP ;
- while(!(S_EXIT != p[k].thread_status || S_EXIT != p[k].report_status)){
- NdbSleep_MilliSleep(1) ;
- }
- NdbThread_Destroy((NdbThread**)&pHandles[k]) ;
- }
-
- return ;
-}
-
-
-
-/*************************************************
-Function: PrintAll()
-*************************************************/
-inline void PrintAll(char* szTableName, int nTables, attr_type attrType){
-
- SQLRETURN retcode = SQL_ERROR ;
- SQLCHAR* szStmt[MAX_SQL_STMT] = { 0 } ;
- ODBC_HANDLES stHandles ;
- memset(&stHandles, 0, sizeof(ODBC_HANDLES)) ;
- double* pDoubleBuffer = NULL ;
- char* pCharBuffer = NULL ;
-
- if(T_CHAR != attrType){
- pDoubleBuffer = (double*)malloc(sizeof(double)*nNoOfCol) ;
- }else{
- pCharBuffer = (char*)malloc(sizeof(char)*nNoOfCol*MAX_CHAR_ATTR_LEN) ;
- }
-
- SQLINTEGER cbLen = 0 ;
-
- GetHandles(&stHandles, GET, 0) ;
-
- for(int c = 0 ; c < nTables ; ++c){
-
- int nCol = 0, nRows = 0 ;
-
- printf("Table: \"%s\":\n------------------\n", (char*)(szTableName + MAX_TABLE_NAME*c*sizeof(char))) ;
-
- sprintf((char*)szStmt, "SELECT * FROM %s", (char*)(szTableName + MAX_TABLE_NAME*c*sizeof(char))) ;
- if(nPrint) printf("\n> %s\n", szStmt) ;
- ODBC_FN(SQLExecDirect(stHandles.hstmt, (SQLCHAR*)szStmt, SQL_NTS), retcode) ;
-
- for(int i = 0 ; i < nNoOfCol ; ++i){
-
- if(T_CHAR != attrType){
- ODBC_FN(SQLBindCol(stHandles.hstmt, (i+1), SQL_C_DOUBLE, (void*)&pDoubleBuffer[i], sizeof(SQLDOUBLE), &cbLen), retcode) ;
- }else{
- ODBC_FN(SQLBindCol(stHandles.hstmt, (i+1), SQL_C_CHAR, (void*)(pCharBuffer + i*MAX_CHAR_ATTR_LEN*sizeof(char)), MAX_CHAR_ATTR_LEN*sizeof(char), &cbLen), retcode) ;
- }
- nCol++ ;
-
- }
-
- int k = 0 ; //out of the <for> loop
- for (;;) {
-
- retcode = SQLFetch(stHandles.hstmt);
- if (SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode ){
- for(k = 0 ; k < nNoOfCol ; ++k){
- if(T_CHAR != attrType){
- ATTR_TYPE_SWITCH_T(pDoubleBuffer[k], AttributeType) ;
- }else{
- printf("%s\t", (char*)(pCharBuffer + k*MAX_CHAR_ATTR_LEN)) ;
- }
- }
- }else if(SQL_NO_DATA == retcode){
- if(0 == k){
- printf("<empty>\n") ;
- break ;
- }else{
- break ;
- }
- }else{
- HandleError(stHandles.hstmt, SQL_HANDLE_STMT) ;
- }
-
- ++nRows ;
- printf("\n") ;
- }
-
- SQLCloseCursor(stHandles.hstmt) ;
-
- printf("------------------\n") ;
- printf("Rows: %d Columns: %d\n\n", nRows, nCol) ;
-
- }
-
- free((void*)pDoubleBuffer) ;
- free((void*)pCharBuffer) ;
- GetHandles(&stHandles, FREE, 0) ;
-
- return ;
-}
-
-
-
-/*************************************************
-Function: AssignRefCharValues()
-*************************************************/
-void AssignRefCharValues(char* pRef, bool bVerbose) {
-
- int count = 0, rows = 0, nThreadOffset = 0, nRowOffset = 0 ;
- char szStrBuffer[MAX_CHAR_ATTR_LEN] = { 0 } ;
- int char_count = sizeof(szANSI)/sizeof(char) ;
-
- for(int c = 0 ; c < nNoOfThreads ; ++c){
- nThreadOffset = nNoOfRows*nNoOfCol*c*MAX_CHAR_ATTR_LEN*sizeof(char) ;
- for(int d = 0 ; d < nNoOfRows ; ++d){
- nRowOffset = nNoOfCol*d*MAX_CHAR_ATTR_LEN*sizeof(char) ; ++rows ;
- for(int i = 0 ; i < nNoOfCol ; ++i){
- for(int j = 0 ; j < (MAX_CHAR_ATTR_LEN - 2) ; ++j){
- int h = (char)(rand() % (char_count-1)) ;
- szStrBuffer[j] = szANSI[h] ;
- }
- szStrBuffer[MAX_CHAR_ATTR_LEN - 1] = '\0' ;
-
- strcpy((char*)(pRef + nThreadOffset + nRowOffset + i*MAX_CHAR_ATTR_LEN*sizeof(char)), (char*)szStrBuffer) ;
- count++ ;
- if(bVerbose){
- printf(" %s ", (char*)(pRef + nThreadOffset + nRowOffset + i*MAX_CHAR_ATTR_LEN*sizeof(char))) ;
- }
- }
- if(bVerbose) {
- printf("\n") ;
- NdbSleep_MilliSleep(10) ;
- }
- }
- }
-
-if(bVerbose){
- printf("_____________________") ;
- printf("\nRows: %d Values: %d\n\n", rows, count) ;
- }
-
-return ;
- }
-
-
-/*
-
-
-sprintf((char*)szStmtBuffer, "INSERT INTO %s VALUES(", p->szTableName) ;
-for(j = 0 ;;){
-strcat((char*)szStmtBuffer, "?") ;
-++j ;
-if(nNoOfCol == j) break ;
-strcat((char*)szStmtBuffer, ", ") ;
-}
-strcat((char*)szStmtBuffer, ")") ;
-
-ODBC_FN(SQLPrepare(stHandles.hstmt, szStmtBuffer, SQL_NTS), retcode) ;
-
-for(j = 0 ; j < nNoOfCol ; ++j){
-ODBC_FN(SQLBindParameter(stHandles.hstmt, (j+1), SQL_PARAM_INPUT, SQL_C_FLOAT, SQL_FLOAT, 0, 0, (void*)&pBindBuffer[j], 0, &cbFloat), retcode) ;
-HandleError(stHandles.hstmt, SQL_HANDLE_STMT) ;
-}
-
-for(r = 0 ; r < nNoOfRows ; ++r){
-for(j = 0 ; j < nNoOfCol ; ++j){
-pBindBuffer[j] = pRef[nNoOfCol*r + j] ;
-}
-ODBC_FN(SQLExecute(stHandles.hstmt), retcode) ;
-HandleError(stHandles.hstmt, SQL_HANDLE_STMT) ;
-}
-
-*/
-
-
-
-
-/*************************************************
-Function: HandleError
-*************************************************/
-
-void HandleError(void* handle, SQLSMALLINT HandleType){
-
- SQLCHAR szError[MAX_STR_LEN], szSqlState[32] ;
- SQLINTEGER nError = 0 ;
- SQLSMALLINT nHandleType = HandleType ;
- SQLSMALLINT nLength = 0 ;
- SQLHANDLE SQLHandle = handle ;
- SQLGetDiagRec(nHandleType, SQLHandle, 1, szSqlState, &nError, szError, 128, &nLength) ;
- printf("Error: %s\nSqlState: %s\n", szError, szSqlState) ;
-
- return ;
- }
-
-
-
-/*************************************************
-Function: ReportError
-*************************************************/
-
-void ReportError(char* szFn, char* szBuffer, char* szFile, int iLine){
-
- printf("%s %s\nFile: %s\nLine: %d\n", szFn, szBuffer, szFile, iLine) ;
-
- return ;
-}
-
-
-
-/*************************************************
-Function: GetHandles()
-*************************************************/
-
-SQLRETURN GetHandles(ODBC_HANDLES* pHandles, handle_op op, bool bDriverInfo){
-
- SQLRETURN retcode = SQL_ERROR ;
-
- if(GET == op){
-
- retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &pHandles->henv);
-
- if (SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode ) {
- retcode = SQLSetEnvAttr(pHandles->henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC2, 0);
-
- if (SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode) {
- retcode = SQLAllocHandle(SQL_HANDLE_DBC, pHandles->henv, &pHandles->hdbc);
-
- if (SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode) {
-
- //SQLSetConnectAttr(pHandles->hdbc, SQL_LOGIN_TIMEOUT, (void*)5, 0);
-
- retcode = SQLConnect(pHandles->hdbc, (SQLCHAR*)"", SQL_NTS, (SQLCHAR*)"", SQL_NTS, (SQLCHAR*)"", SQL_NTS ) ;
-
- SQL_SUCCESS == SQLSetConnectAttr(pHandles->hdbc, SQL_ATTR_AUTOCOMMIT, (void*)SQL_AUTOCOMMIT_ON, 0) ;
- //printf("AUTOCOMMIT is on\n") ;
-
- if (SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode) {
- // retcode still holds the value returned by SQLConnect
- retcode = SQLAllocHandle(SQL_HANDLE_STMT, pHandles->hdbc, &pHandles->hstmt) ;
- if (SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode) {
- if(bDriverInfo) GetDriverAndSourceInfo(pHandles->hdbc) ;
- // printf("All handles allocated OK\n", retcode);
- }else{ // SQLAllocHandle()
- REPORTERROR((char*)"SQLAllocHandle()", (char*)"failed") ;
- HandleError(pHandles->hdbc, SQL_HANDLE_DBC) ;
- ODBC_FN(SQLDisconnect(pHandles->hdbc), retcode) ;
- ODBC_FN(SQLFreeHandle(SQL_HANDLE_DBC, pHandles->hdbc), retcode) ;
- ODBC_FN(SQLFreeHandle(SQL_HANDLE_ENV, pHandles->henv), retcode) ;
- retcode = SQL_ERROR ;
- }
- }else{ // SQLConnect()
- REPORTERROR((char*)"SQLConnect()", (char*)"failed" ) ;
- HandleError(pHandles->hdbc, SQL_HANDLE_DBC) ;
- ODBC_FN(SQLFreeHandle(SQL_HANDLE_DBC, pHandles->hdbc), retcode) ;
- ODBC_FN(SQLFreeHandle(SQL_HANDLE_ENV, pHandles->henv), retcode) ;
- retcode = SQL_ERROR ;
- }
- }else{ // SQLAllocHandle()
- REPORTERROR((char*)"SQLAllocHandle()", "failed" ) ;
- HandleError(pHandles->hdbc, SQL_HANDLE_DBC) ;
- ODBC_FN(SQLFreeHandle(SQL_HANDLE_ENV, pHandles->henv), retcode) ;
- retcode = SQL_ERROR ;
- }
- }else{ // SQLSetEnvAttr()
- REPORTERROR((char*)"SQLSetEnvAttr()", "failed" ) ;
- HandleError(pHandles->henv, SQL_HANDLE_ENV) ;
- ODBC_FN(SQLFreeHandle(SQL_HANDLE_ENV, pHandles->henv), retcode) ;
- retcode = SQL_ERROR ;
- }
- }else{ // SQLAllocHandle()
- REPORTERROR((char*)"SQLAllocHandle()", "failed" ) ;
- HandleError(pHandles->henv, SQL_HANDLE_ENV) ;
- retcode = SQL_ERROR ;
- }
- }else{
- ODBC_FN(SQLFreeHandle(SQL_HANDLE_STMT, pHandles->hstmt), retcode) ;
- ODBC_FN(SQLDisconnect(pHandles->hdbc), retcode) ;
- ODBC_FN(SQLFreeHandle(SQL_HANDLE_DBC, pHandles->hdbc), retcode) ;
- ODBC_FN(SQLFreeHandle(SQL_HANDLE_ENV, pHandles->henv), retcode) ;
- }
-
- return retcode ;
-}
-
-
-
-/*************************************************
-Function: AggretateFn():
-<aggr_fn fn> - name of the aggregate function to use
-<char* szTableName> - name of the table
-<int nCol> - number of the column
-<double* pdIn> - pointer to double containing the value to be used in a call to COUNT; used only by this function
-<double* pdOut> - pointer to double that will recieve the result
-<attr_type attrType> - type of the attribute
-*************************************************/
-SQLRETURN AggregateFn(aggr_fn fn, char* szTableName, int nCol, double* pdIn, double* pdOut, attr_type attrType){
-
- SQLRETURN retcode = SQL_ERROR ;
- SQLCHAR* szStmt[MAX_SQL_STMT] = { 0 } ;
- SQLCHAR szValueBuffer[MAX_VALUE_LEN] = { 0 } ;
- SQLCHAR szAuxBuffer[MAX_STR_LEN] = { 0 } ;
- SQLCHAR szColBuffer[MAX_COL_NAME] = { 0 } ;
- ODBC_HANDLES stHandles ;
- memset(&stHandles, 0, sizeof(ODBC_HANDLES)) ;
- SQLINTEGER cbDouble = 0 ;
-
- GetHandles(&stHandles, GET, 0) ;
-
- switch(fn){
- case FN_COUNT:
- switch(attrType){
- case T_INT:
- sprintf((char*)szStmt, "SELECT COUNT(*) FROM %s WHERE COL%d > %d", szTableName, nCol, (int)*pdIn) ;
- break ;
- case T_FLOAT:
- sprintf((char*)szStmt, "SELECT COUNT(*) FROM %s WHERE COL%d > %f", szTableName, nCol, (float)*pdIn) ;
- break ;
-/* case T_DOUBLE:
- sprintf((char*)szStmt, "SELECT COUNT(*) FROM %s WHERE COL%d > %.15f", szTableName, nCol, *pdIn) ;
- break ;
-*/
- default:
- break ;
- }
- break ;
- case FN_SUM:
- sprintf((char*)szStmt, "SELECT SUM(COL%d) FROM %s", nCol, szTableName) ;
- break ;
- case FN_AVG:
- sprintf((char*)szStmt, "SELECT AVG(COL%d) FROM %s", nCol, szTableName) ;
- break ;
- case FN_MAX:
- sprintf((char*)szStmt, "SELECT MAX(COL%d) FROM %s", nCol, szTableName) ;
- break ;
- case FN_MIN:
- sprintf((char*)szStmt, "SELECT MIN(COL%d) FROM %s", nCol, szTableName) ;
- break ;
- case FN_VARIANCE: // not implemented
- //sprintf((char*)szStmt, "SELECT VARIANCE(COL%d) FROM %s;", nCol, szTableName) ;
- break ;
- case FN_STDDEV: // not implemented
- //sprintf((char*)szStmt, "SELECT STDDEV(COL%d) FROM %s;", nCol, szTableName) ;
- break ;
- default:
- break ;
- }
-//printf("%s\n", szStmt) ;
-
-retcode = SQLExecDirect(stHandles.hstmt, (SQLCHAR*)szStmt, SQL_NTS) ;
-if (SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode ){
- retcode = SQLBindCol(stHandles.hstmt, 1, SQL_C_DOUBLE, (void*)pdOut, sizeof(SQLDOUBLE), &cbDouble) ;
- if (SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode ){
- retcode = SQLFetch(stHandles.hstmt) ;
- }
- }
-
-if(SQL_SUCCESS != retcode && SQL_SUCCESS_WITH_INFO != retcode){
- HandleError(stHandles.hstmt, SQL_HANDLE_STMT) ;
- }
-
-SQLCloseCursor(stHandles.hstmt) ;
-
-GetHandles(&stHandles, FREE, 0) ;
-
-return retcode ;
-
- };
-
-
-
-/*************************************************
-Function: GetDriverAndSourceInfo()
-*************************************************/
-SQLRETURN GetDriverAndSourceInfo(SQLHDBC hdbc){
-
- SQLRETURN retcode = SQL_ERROR ;
-
- SQLCHAR buffer[255] ;
- SQLUSMALLINT snValue = 0 ;
- SQLSMALLINT outlen = 0 ;
-
- printf( "-------------------------------------------\n" ) ;
-
- retcode = SQLGetInfo( hdbc, SQL_DATA_SOURCE_NAME, buffer, 255, &outlen ) ;
-
- printf( "Connected to Server: %s\n", buffer ) ;
-
- retcode = SQLGetInfo( hdbc, SQL_DATABASE_NAME, buffer, 255, &outlen ) ;
- printf( " Database name: %s\n", buffer ) ;
-
- retcode = SQLGetInfo( hdbc, SQL_SERVER_NAME, buffer, 255, &outlen ) ;
- printf( " Instance name: %s\n", buffer ) ;
-
- retcode = SQLGetInfo( hdbc, SQL_DBMS_NAME, buffer, 255, &outlen ) ;
- printf( " DBMS name: %s\n", buffer ) ;
-
- retcode = SQLGetInfo( hdbc, SQL_DBMS_VER, buffer, 255, &outlen ) ;
- printf( " DBMS version: %s\n", buffer ) ;
-
- retcode = SQLGetInfo( hdbc, SQL_ODBC_VER, buffer, 255, &outlen ) ;
- printf( " ODBC version: %s\n", buffer ) ;
-
- retcode = SQLGetInfo( hdbc, SQL_DRIVER_NAME, buffer, 255, &outlen ) ;
- printf( " Driver name: %s\n", buffer ) ;
-
- retcode = SQLGetInfo( hdbc, SQL_DRIVER_VER, buffer, 255, &outlen ) ;
- printf( " Driver version: %s\n", buffer ) ;
-
- retcode = SQLGetInfo( hdbc, SQL_MAX_DRIVER_CONNECTIONS, &snValue, sizeof(SQLSMALLINT), &outlen ) ;
- printf( " Max connections: %d\n", snValue ) ;
-
- retcode = SQLGetInfo( hdbc, SQL_CURSOR_COMMIT_BEHAVIOR, &snValue, sizeof(SQLSMALLINT), &outlen ) ;
- printf( "Autocommit behavior:") ;
-
- switch(snValue){
- case SQL_CB_DELETE:
- printf(" SQL_CB_DELETE\n") ;
- break ;
- case SQL_CB_CLOSE:
- printf(" SQL_CB_CLOSE\n") ;
- break ;
- case SQL_CB_PRESERVE:
- printf(" SQL_CB_PRESERVE\n") ;
- break ;
- default:
- printf(" undefined\n") ;
- break ;
- }
-
- printf( "-------------------------------------------\n" ) ;
-
- return retcode ;
-
-}
-
-
-
-/*************************************************
-Function: ArithOp()
-*************************************************/
-
-int ArithOp(char* szTable, int nTotalCols, float* pValue, attr_type attrType, arth_op op){
-
- SQLRETURN retcode = SQL_ERROR ;
- int nVerRet = -1 ;
- SQLCHAR szStmt[MAX_SQL_STMT] = { 0 } ;
- SQLCHAR szEndBuffer[MAX_STR_LEN] = { 0 } ;
- SQLCHAR szColBuffer[MAX_COL_NAME] = { 0 } ;
- SQLCHAR szAuxBuffer[MAX_STR_LEN] = { 0 } ;
- ODBC_HANDLES stHandles ;
- memset(&stHandles, 0, sizeof(ODBC_HANDLES)) ;
-
- void* pBuffer = NULL ;
- SQLINTEGER BindInt = 0, IntResult = 0, RefIntResult = 0 ;
- SQLFLOAT BindFloat = 0, FloatResult = 0, RefFloatResult = 0 ;
- SQLDOUBLE BindDouble = 0, DoubleResult = 0, RefDoubleResult = 0 ;
- SQLINTEGER cbSize = 0 ;
- SQLINTEGER cbLen = 0 ;
- SQLSMALLINT cbTarget = 0 ;
-
- GetHandles(&stHandles, GET, 0) ;
-
- for(int c = 0 ; c < nTotalCols ; ++c){
-
- sprintf((char*)szStmt, "SELECT COL%d, (COL%d", c, c) ;
- switch(op){
- case MINUS:
- strcat((char*)szStmt, " - ") ;
- break ;
- case PLUS:
- strcat((char*)szStmt, " + ") ;
- break ;
- case MULTI:
- strcat((char*)szStmt, " * ") ;
- break ;
- case DIVIDE:
- strcat((char*)szStmt, " / ") ;
- break ;
- case MODULO:
- //strcat((char*)szStmt, " % ") ; Not implemented
- GetHandles(&stHandles, FREE, 0) ;
- return -1 ; //Close handles and return
- break ;
- default:
- break ;
- }
-
- sprintf((char*)(szAuxBuffer),"%.9f) ", *((float*)(pValue))) ;
- strcat((char*)szStmt, (char*)szAuxBuffer) ;
- sprintf((char*)szEndBuffer, "FROM %s", szTable) ;
- strcat((char*)szStmt, (char*)szEndBuffer) ;
-
- ODBC_FN(SQLExecDirect(stHandles.hstmt, (SQLCHAR*)szStmt, SQL_NTS), retcode) ;
- if(retcode == SQL_ERROR){
- HandleError(stHandles.hstmt, SQL_HANDLE_STMT) ;
- printf("\n%s\n", szStmt) ;
- }
-
- SQLSMALLINT cbNameLen = 0, cbSqlType = 0, cbNullable = 0, cbColScale = 0 ;
- SQLINTEGER cbColSize = 0 ;
- SQLDescribeCol(stHandles.hstmt, 2, szColBuffer, MAX_COL_NAME-1, &cbNameLen, &cbSqlType, (unsigned long*)&cbColSize, &cbColScale, &cbNullable) ;
-
- switch(cbSqlType){
- case SQL_NUMERIC:
- pBuffer = &IntResult ;
- cbSize = sizeof(SQLINTEGER) ;
- cbTarget = SQL_C_ULONG ;
- case SQL_INTEGER:
- pBuffer = &IntResult ;
- cbSize = sizeof(SQLINTEGER) ;
- cbTarget = SQL_C_LONG ;
- break ;
- case SQL_FLOAT:
- pBuffer = &FloatResult ;
- cbSize = sizeof(SQLFLOAT) ;
- cbTarget = SQL_C_FLOAT ;
- break ;
- case SQL_DOUBLE:
- pBuffer = &DoubleResult ;
- cbSize = sizeof(SQLDOUBLE) ;
- cbTarget = SQL_C_DOUBLE ;
- break ;
- default:
- printf("\nUndefined result type: %d\n", cbSqlType) ;
- break ;
- }
-
- switch(attrType){
- case T_INT:
- ODBC_FN(SQLBindCol(stHandles.hstmt, 1, SQL_C_SLONG, (void*)&BindInt, sizeof(SQLINTEGER), &cbLen), retcode) ;
- break ;
- case T_FLOAT:
- ODBC_FN(SQLBindCol(stHandles.hstmt, 1, SQL_C_FLOAT, (void*)&BindFloat, sizeof(SQLFLOAT), &cbLen), retcode) ;
- break ;
- /* case T_DOUBLE:
- ODBC_FN(SQLBindCol(stHandles.hstmt, 1, SQL_C_DOUBLE, (void*)&BindDouble, sizeof(SQLDOUBLE), &cbLen), retcode) ;
- break ;
- */
- default:
- break ;
- }
-
- ODBC_FN(SQLBindCol(stHandles.hstmt, 2, cbTarget, pBuffer, cbSize, &cbLen), retcode) ;
-
- retcode = SQLFetch(stHandles.hstmt) ;
-
- if (SQL_SUCCESS == retcode || SQL_SUCCESS_WITH_INFO == retcode){
- switch(attrType){
- case T_INT:
- switch(cbSqlType){
- case SQL_INTEGER:
- nVerRet = VerifyArthOp((int*)&BindInt, pValue, (int*)pBuffer, op) ;
- break ;
- case SQL_FLOAT:
- nVerRet = VerifyArthOp((int*)&BindInt, pValue, (float*)pBuffer, op) ;
- break ;
- case SQL_DOUBLE:
- nVerRet = VerifyArthOp((int*)&BindInt, pValue, (double*)pBuffer, op) ;
- break ;
- case SQL_NUMERIC:
- nVerRet = VerifyArthOp((int*)&BindInt, pValue, (int*)pBuffer, op) ;
- break ;
- default:
- break ;
- }
- break ;
-
- case T_FLOAT:
- switch(cbSqlType){
- case SQL_INTEGER:
- nVerRet = VerifyArthOp((float*)&BindFloat, pValue, (int*)pBuffer, op) ;
- break ;
- case SQL_FLOAT:
- nVerRet = VerifyArthOp((float*)&BindFloat, pValue, (float*)pBuffer, op) ;
- break ;
- case SQL_DOUBLE:
- nVerRet = VerifyArthOp((float*)&BindFloat, pValue, (double*)pBuffer, op) ;
- break ;
- default:
- break ;
- }
- break ;
- /* case T_DOUBLE:
- switch(cbSqlType){
- case SQL_INTEGER:
- nVerRet = VerifyArthOp((double*)&BindDouble, pValue, (int*)pBuffer, op) ;
- break ;
- case SQL_FLOAT:
- nVerRet = VerifyArthOp((double*)&BindDouble, pValue, (float*)pBuffer, op) ;
- break ;
- case SQL_DOUBLE:
- nVerRet = VerifyArthOp((double*)&BindDouble, pValue, (double*)pBuffer, op) ;
- break ;
- default:
- break ;
- }
- break ;
- */
- default:
- break ;
- }
- if(-1 == nVerRet){
- printf("\nVerification failed.\n") ;
- return nVerRet ;
- }else if(SQL_NO_DATA == retcode){
- break ;
- }
- }else{
-
- HandleError(stHandles.hstmt, SQL_HANDLE_STMT) ;
- }
-
- SQLCloseCursor(stHandles.hstmt) ;
- }
-
- GetHandles(&stHandles, FREE, 0) ;
-
- return nVerRet ;
-}
-
-
-
-
-/*************************************************
-Function: Join()
-*************************************************/
-SQLRETURN Join(char* szTable, int nTables, int nCol, join_type joinType){
-
- SQLRETURN retcode = SQL_ERROR ;
- SQLCHAR szStmt[MAX_SQL_STMT] = { 0 } ;
- SQLCHAR szEndBuffer[MAX_STR_LEN] = { 0 } ;
- SQLCHAR szColBuffer[MAX_COL_NAME] = { 0 } ;
- SQLCHAR szAuxBuffer[MAX_STR_LEN] = { 0 } ;
-
- ODBC_HANDLES stHandles ;
- memset(&stHandles, 0, sizeof(ODBC_HANDLES)) ;
-
- int c = 0, t = 0 ;
-
- GetHandles(&stHandles, GET, 0) ;
-
- for(c = 0 ; c < nCol ; ++c) {
-
- switch(joinType){
- case ITSELF:
- sprintf((char*)szStmt, "SELECT * FROM %s, %s", (char*)szTable, (char*)szTable) ;
- break ;
- case EQUI:
- break ;
- case NON_EQUI:
- break ;
- case INNER:
- break ;
- case OUTTER:
- break ;
- default:
- break ;
- }
- }
-
-GetHandles(&stHandles, FREE, 0) ;
-
-return retcode ;
-
-}
-
-
-
-SQLRETURN GetResults(SQLHSTMT){
-
- SQLRETURN retcode = SQL_ERROR ;
-
- return retcode ;
-}
-
-/*
-
-int createTables(char* szTableName, int nTables){
-
- for (int i = 0; i < nNoOfCol; i++){
- snprintf(attrName[i], MAXSTRLEN, "COL%d", i) ;
- }
-
- for (int i = 0; i < nTables; i++){
- snprintf(tableName[i], MAXSTRLEN, "TAB%d", i) ;
- }
-
- for(unsigned i = 0; i < nTables; i++){
-
- ndbout << "Creating " << szTableName[i] << "... " ;
-
- NDBT_Table tmpTable(szTableName[i]) ;
-
- tmpTable.setStoredTable(!theTempTable) ;
-
- tmpTable.addAttribute(NDBT_Attribute(attrName[0],
- UnSigned,
- 4, // 4 Bytes
- TupleKey));
- }
-
-
- for (int j = 1 ; j < nNoOfCol ; j++)
- tmpTable.addAttribute(NDBT_Attribute(attrName[j], UnSigned, 4*tAttributeSize)) ;
-
- if(tmpTable.createTableInDb(pMyNdb) == -1){
- return -1 ;
- }
-
- ndbout << "done" << endl ;
-
- return 0;
-}
-*/
-
-/*************************************************
-Function: createTables()
-Uses NDB API to create tables for the tests
-*************************************************/
-
-int createTables(char* szTableName, int nTables){
-
- Ndb * pNdb = new Ndb("TEST_DB") ;
- pNdb->init();
-
- ndbout << "Waiting for ndb to become ready..." <<endl;
- if (pNdb->waitUntilReady(10000) != 0){
- ndbout << "NDB is not ready" << endl;
- ndbout << "Benchmark failed!" << endl;
- delete pNdb ;
- return -1 ;
- }
-
- NdbSchemaCon *MySchemaTransaction = NULL ;
- NdbSchemaOp *MySchemaOp = NULL ;
- int check = -1 ;
- char szColNameBuffer[MAX_COL_NAME] = { 0 } ;
- int tLoadFactor = 80 ;
-
- for(int i=0 ; i < nTables ; ++i) {
-
- ndbout << "Creating " << (char*)(szTableName+MAX_TABLE_NAME*i) << "..." << endl ;
-
- MySchemaTransaction = pNdb->startSchemaTransaction() ;
- //printf("MySchemaTransaction - OK\n") ;
- if(MySchemaTransaction == NULL){
- printf("MySchemaTransaction is NULL\n") ;
- delete pNdb ;
- return -1 ;
- }
-
- MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
- //printf("MySchemaTransaction->getNdb... - OK\n") ;
- if(MySchemaOp == NULL){
- printf("MySchemaOp is NULL\n") ;
- delete pNdb ;
- return -1 ;
- }
-
- check = MySchemaOp->createTable( (const char*)(szTableName+MAX_TABLE_NAME*i)
- ,8 // Table Size
- ,TupleKey // Key Type
- ,40 // Nr of Pages
- ,All
- ,6
- ,(tLoadFactor - 5)
- ,(tLoadFactor)
- ,1
- ,0
- );
-
- if (check == -1){
- printf("MySchemaOp->createTable failed\n") ;
- delete pNdb ;
- return -1 ;
- }
-
- snprintf(szColNameBuffer, MAX_COL_NAME, "COL%d", 0) ;
- check = MySchemaOp->createAttribute( szColNameBuffer,
- TupleKey,
- 32,
- PKSIZE,
- UnSigned,
- MMBased,
- NotNullAttribute );
-
- if (check == -1){
- printf("MySchemaOp->createAttribute() #1 failed\n") ;
- delete pNdb ;
- return -1 ;
- }
-
- for (int j = 1; j < nNoOfCol ; j++){
- snprintf(szColNameBuffer, MAX_COL_NAME, "COL%d", j) ;
- check = MySchemaOp->createAttribute(szColNameBuffer,
- NoKey,
- 32,
- tAttributeSize,
- UnSigned,
- MMBased,
- NotNullAttribute );
-
- if (check == -1){
- printf("MySchemaOp->createAttribute() #2 failed\n") ;
- delete pNdb ;
- return -1;
- }
- }
-
- if (MySchemaTransaction->execute() == -1){
- printf("MySchemaTransaction->execute() failed\n") ;
- printf("%s\n", MySchemaTransaction->getNdbError().message) ;
- return -1 ;
- delete pNdb ;
- }
-
- pNdb->closeSchemaTransaction(MySchemaTransaction);
- }
-
- return 0;
-}
-
-
-
diff --git a/storage/ndb/test/odbc/SQL99_test/SQL99_test.h b/storage/ndb/test/odbc/SQL99_test/SQL99_test.h
deleted file mode 100644
index db2f7eb8e5b..00000000000
--- a/storage/ndb/test/odbc/SQL99_test/SQL99_test.h
+++ /dev/null
@@ -1,261 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-#include <ndb_types.h>
-#include <NdbThread.h>
-#include <NdbOut.hpp>
-#include <NdbSleep.h>
-#include <NDBT.hpp>
-#include <sqlext.h>
-#include <stdio.h>
-//#include <stdlib.h>
-#include <unistd.h>
-//#include <windows.h>
-//#include <process.h>
-
-#define MAX_STR_LEN 128
-#define MAX_TABLE_NAME 32
-#define MAX_COL_NAME 32
-#define MAX_SQL_STMT 2048
-#define MAX_VALUE_LEN 32
-#define MAX_CHAR_ATTR_LEN 24
-#define NUM_COL_ARITHM 2
-#define FLTDEV 0.0001
-//#define DBLDEV 0.000000001
-
-#define REPORTERROR(fn, str) ReportError(fn, str, __FILE__, __LINE__)
-#define REPORT(str) printf((str))
-
-#define ATTR_TYPE_SWITCH(buffer, ptr, attr) switch(attr){ \
- case T_INT:\
- sprintf((char*)(buffer),"%d", (int)(ptr)) ;\
- break ;\
- case T_FLOAT:\
- sprintf((char*)(buffer),"%f", (float)(ptr)) ;\
- break ;\
- default:\
- break ;\
- }
-
-#define ATTR_TYPE_SWITCH_T(value, attr) switch(attr){ \
- case T_INT:\
- printf("%d \t", (int)(value)) ;\
- break ;\
- case T_FLOAT:\
- printf("%f \t", (float)(value)) ;\
- break ;\
- default:\
- break ;\
- }
-
-#define ATTR_TYPE_SWITCH_AGR(str, value_A, value_B, value_C, attr) switch(attr){ \
- case T_INT:\
- printf("%s\t%d %d\t\t\t%d\n\n", str, value_A, (int)value_B, (int)value_C) ; break ;\
- case T_FLOAT:\
- printf("%s\t%d %f\t\t\t%d\n\n", str, value_A, value_B, (int)value_C) ; break ;\
- default:\
- break ;\
- }
-
-
-#define ODBC_FN(fn, rc) rc = ((((fn)))) ; if(SQL_SUCCESS == rc || SQL_SUCCESS_WITH_INFO == rc){;}else ReportError("ODBC function", "failed in ", __FILE__, __LINE__)
-
-
-typedef enum attr_type_tag {
- T_INT,
- T_FLOAT,
-// T_DOUBLE,
- T_CHAR
-} attr_type ;
-
-typedef enum aggr_fn_tag {
- FN_COUNT,
- FN_SUM,
- FN_AVG,
- FN_MAX,
- FN_MIN,
- FN_VARIANCE,
- FN_STDDEV
-} aggr_fn ;
-
-typedef enum join_type_tag {
- ITSELF,
- EQUI,
- NON_EQUI,
- INNER,
- OUTTER
-} join_type ;
-
-typedef enum arth_op_tag {
- MINUS,
- PLUS,
- MULTI,
- DIVIDE,
- MODULO
-} arth_op ;
-
-typedef struct ODBC_HANDLES_tag{
- SQLHENV henv ;
- SQLHDBC hdbc ;
- SQLHSTMT hstmt ;
-} ODBC_HANDLES ;
-
-typedef enum handle_op_tag{
- GET,
- FREE
-} handle_op ;
-
-typedef enum test_case_tag {
- NUMERIC_DATA_TYPES,
- CHAR_DATA_TYPES,
- IDENTIFIERS,
- BASIC_QUERY,
- PREDICATE_SEARCH,
- DATA_MANIPULATION,
- NULL_SUPPORT,
- BASIC_CONSTRAINTS,
- TRANSACTION,
- SET_FUNCTIONS,
- BASIC_SCHEMA,
- JOINED_TABLE,
- ALL
-} test_case ;
-
-typedef enum status_tag{
- S_STOP,
- S_IDLE,
- S_STARTED,
- S_GET_BUSY,
- S_BUSY,
- S_EXIT
-} status ;
-
-typedef enum type_tag {
- T_INSERT,
- T_READ,
- T_UPDATE,
- T_DELETE,
- T_READ_VERIFY,
- T_DELETE_VERIFY,
- T_WAIT
-} type ;
-
-typedef struct PARAMS_tag {
- int nThreadID ;
- int nError ;
- int nVerifyFlag ;
- status thread_status ;
- status report_status ;
- type op_type ;
- void* pThreadRef ;
- char szTableName[MAX_TABLE_NAME] ;
-} PARAMS ;
-
-typedef enum table_opt_tag {
- CREATE,
- DROP
-} table_opt ;
-
-static char szANSI[] ="0123456789ABCEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ;
-
-void ReportError(char* szFn, char* szBuffer, char* szFile, int iLine) ;
-void HandleError(void*, SQLSMALLINT) ;
-SQLRETURN GetHandles(ODBC_HANDLES*, handle_op, bool) ;
-SQLRETURN AggregateFn(aggr_fn, char*, int, double*, double*, attr_type) ;
-SQLRETURN GetDriverAndSourceInfo(SQLHDBC) ;
-SQLRETURN Join(char*, join_type) ;
-SQLRETURN GetResults(SQLHSTMT) ;
-int ArithOp(char*, int, float*, attr_type, arth_op) ;
-void ParseArguments(int argc, const char** argv) ;
-void* ThreadFnInt(void*) ;
-void* ThreadFnFloat(void*) ;
-//void* ThreadFnDouble(void*) ;
-void* ThreadFnChar(void*) ;
-inline void AssignTableNames(char* szBuffer, int nTables) ;
-SQLRETURN CreateDemoTables(char*, int, table_opt) ;
-inline void StartThreads(PARAMS*, void*, int, char*, attr_type, UintPtr*) ;
-inline void SetThreadOperationType(PARAMS*, type) ;
-inline int WaitForThreads(PARAMS*) ;
-inline void StopThreads(PARAMS*, UintPtr*) ;
-inline void PrintAll(char* szTableName, int, attr_type) ;
-void AssignRefCharValues(char*, bool) ;
-
-template <class T, class V>
-int VerifyArthOp(V* tValue, float* tOperand, T* tRes, arth_op op){
-
- int nResult = 0 ;
- int nValue = 0, nOperand = 0 ;
-
- switch(op){
- case MINUS:
- if(FLTDEV < abs((*tValue - *tOperand) - *tRes))
- nResult = -1 ;
- break ;
- case PLUS:
- if(FLTDEV < abs((*tValue + *tOperand) - *tRes))
- nResult = -1 ;
- break ;
- case MULTI:
- if(FLTDEV < abs((*tValue * *tOperand) - *tRes))
- nResult = -1 ;
- break ;
- case DIVIDE:
- if(FLTDEV < abs((*tValue / *tOperand) - *tRes))
- nResult = -1 ;
- break ;
- case MODULO:
- nValue = *tValue ;
- nOperand = *tOperand ;
- if(*tRes != (nValue % nOperand))
- nResult = -1 ;
- break ;
- }
-
- return nResult ;
-}
-
-template <class P> void AssignRefNumValues(P* pRef, attr_type attrType, bool bVerbose) {
-
- int count = 0, rows = 0, nThreadOffset = 0, nRowOffset = 0 ;
- P* p = (P*)pRef ;
-
- float fRandomBase = (rand()*rand()) % 100;
- for(int c = 0 ; c < nNoOfThreads ; ++c){
- nThreadOffset = nNoOfRows*nNoOfCol*c ;
- for(int d = 0 ; d < nNoOfRows ; ++d){
- nRowOffset = nNoOfCol*d ; ++rows ;
- for(int i = 0 ; i < nNoOfCol ; ++i){
- (p[nThreadOffset + nRowOffset + i]) = (fRandomBase*(c+1) + (d+3)*7 + i)/1.1034093201 ;
- ++count ;
- if(bVerbose){
- ATTR_TYPE_SWITCH_T(p[nThreadOffset + nRowOffset + i], AttributeType) ;
- }
- }
- if(bVerbose) { printf("\n") ; NdbSleep_MilliSleep(10) ;
- }
- }
- }
-
- if(bVerbose){
- printf("_____________________") ;
- printf("\nRows: %d Values: %d\n\n", rows, count) ;
- }
-
- return ;
-}
-
-
diff --git a/storage/ndb/test/odbc/client/Makefile b/storage/ndb/test/odbc/client/Makefile
deleted file mode 100644
index 4b962f5b65a..00000000000
--- a/storage/ndb/test/odbc/client/Makefile
+++ /dev/null
@@ -1,95 +0,0 @@
-include .defs.mk
-
-TYPE := odbcclient
-#TYPE := odbcdriver
-
-BIN_TARGET := testOdbcClient
-#BIN_TARGET := testodbc2
-
-
-# Source files of non-templated classes (.C files)
-SOURCES = main.cpp \
- SQLFetchTest.cpp \
- SQLDisconnectTest.cpp \
- SQLTablesTest.cpp \
- SQLGetInfoTest.cpp \
- SQLGetTypeInfoTest.cpp \
- SQLGetFunctionsTest.cpp \
- SQLGetDataTest.cpp \
- SQLCancelTest.cpp \
- SQLTransactTest.cpp \
- SQLGetCursorNameTest.cpp \
- SQLSetCursorNameTest.cpp \
- SQLRowCountTest.cpp \
- SQLNumResultColsTest.cpp \
- SQLDescribeColTest.cpp \
- SQLExecDirectTest.cpp \
- SQLColAttributeTest.cpp \
- SQLColAttributeTest1.cpp \
- SQLColAttributeTest2.cpp \
- SQLColAttributeTest3.cpp \
- SQLBindColTest.cpp \
- SQLDriverConnectTest.cpp \
- SQLPrepareTest.cpp \
- SQLGetDiagRecSimpleTest.cpp \
- SQLConnectTest.cpp
-
-XSOURCES = testodbc2.cpp
-XSOURCES = \
- main.cpp \
- SQLDriverConnectTest.cpp \
- SQLPrepareTest.cpp \
- SQLMoreResultsTest.cpp \
- SQLGetStmtAttrTest.cpp \
- SQLGetEnvAttrTest.cpp \
- SQLGetConnectAttrTest.cpp \
- SQLExecuteTest.cpp \
- SQLExecDirectTest.cpp \
- SQLDisconnectTest.cpp \
- SQLCloseCursorTest.cpp \
- SQLCancelTest.cpp \
- SQLBindColTest.cpp \
- SQLDescribeColTest.cpp \
- SQLGetTypeInfoTest.cpp \
- SQLGetFunctionsTest.cpp \
- SQLNumResultColsTest.cpp \
- SQLSetDescFieldTest.cpp \
- SQLGetDescRecTest.cpp \
- SQLEndTranTest.cpp \
- SQLGetInfoTest.cpp \
- SQLConnectTest.cpp \
- SQLAllocHandleTest.cpp \
- SQLAllocEnvTest.cpp \
- SQLRowCountTest.cpp \
- SQLFetchScrollTest.cpp \
- SQLFetchTest.cpp \
- SQLGetDescFieldTest.cpp \
- SQLSetDescRecTest.cpp \
- SQLFreeHandleTest.cpp
-
-ifeq ($(TYPE),odbcdriver)
-LIBS_SPEC += \
- -lodbcdriver_pic \
- -lodbchandles_pic \
- -lodbccodegen_pic \
- -lodbccompiler_pic \
- -lodbcexecutor_pic \
- -lodbccommon_pic \
- -lodbcdictionary_pic \
- -lNDBT \
- -lportlib
-endif
-
-ifeq ($(TYPE),odbcclient)
-LIBS_SPEC += \
- -lportlib \
- -lNDBT
-endif
-
-CCFLAGS_LOC += -I/usr/local/include \
- -I$(NDB_TOP)/include/ndbapi \
- -I$(NDB_TOP)/test/include
-
-include $(NDB_TOP)/Epilogue.mk
-#LIBS_LOC += -L/usr/local/opt/iODBC/lib
-#LIBS_SPEC = -liodbc -lNDBT -lportlib
diff --git a/storage/ndb/test/odbc/client/NDBT_ALLOCHANDLE.cpp b/storage/ndb/test/odbc/client/NDBT_ALLOCHANDLE.cpp
deleted file mode 100644
index 6e6c7cfdb0e..00000000000
--- a/storage/ndb/test/odbc/client/NDBT_ALLOCHANDLE.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include "common.h"
-#include <NdbTest.hpp>
-#include <NdbMain.h>
-
-SQLRETURN SQLHENV_check, SQLHENV_FREE_check;
-
-int NDBT_ALLOCHANDLE()
-{
- /*****************************HENV Handle*****************************/
-
- SQLHENV henv;
- SQLHENV_check = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
-
- if (SQLHENV_check == -1) {
- return(-1);
- //return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- if (SQLHENV_check == 0) {
- return 0;
- }
-
- SQLHENV_FREE_check = SQLFreeHandle(SQL_HANDLE_ENV, henv);
-
- if (SQLHENV_FREE_check == -1) {
- // Deallocate any allocated memory, if it exists
- return(-1);
- //return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- if (SQLHENV_FREE_check == 0) {
- return 0;
- }
-
- return 0;
-}
-
diff --git a/storage/ndb/test/odbc/client/NDBT_ALLOCHANDLE_HDBC.cpp b/storage/ndb/test/odbc/client/NDBT_ALLOCHANDLE_HDBC.cpp
deleted file mode 100644
index 8bcefffaaed..00000000000
--- a/storage/ndb/test/odbc/client/NDBT_ALLOCHANDLE_HDBC.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include "common.h"
-#include <NdbTest.hpp>
-#include <NdbMain.h>
-
-SQLRETURN SQLHENVFREE_check, SQLHDBC_check;
-
-
-// NDB_COMMAND(SQLTest1, ......., 65535)
-int NDBT_ALLOCHANDLE_HDBC()
-{
-
- SQLHENV henv;
- SQLHDBC hdbc;
-
- /*****************************HDBC Handle*****************************/
- SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
-
- SQLHDBC_check = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
-
- if (SQLHDBC_check == -1) {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- if (SQLHDBC_check == 0) {
- return 0;
- }
-
- SQLHENVFREE_check = SQLFreeHandle(SQL_HANDLE_ENV, henv);
-
- if (SQLHENVFREE_check == -1) {
- // Deallocate any allocated memory, if it exists
- return(-1);
- //return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- if (SQLHENVFREE_check == 0) {
- return 0;
- }
-}
-
-
-
-
diff --git a/storage/ndb/test/odbc/client/NDBT_SQLConnect.cpp b/storage/ndb/test/odbc/client/NDBT_SQLConnect.cpp
deleted file mode 100644
index 9cb4b87143c..00000000000
--- a/storage/ndb/test/odbc/client/NDBT_SQLConnect.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include "common.h"
-#include <NdbTest.hpp>
-#include <NdbMain.h>
-
-SQLRETURN retcode, SQLSTATEs;
-SQLHENV henv;
-SQLHDBC hdbc;
-
-void NDBT_Connect_DisplayError(SQLSMALLINT HandleType, SQLHSTMT InputHandle);
-
-int NDBT_SQLConnect()
-{
-
- /*****************************SQLConnect AutoTest*****************************/
-
- // Allocate An Environment Handle
- SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
-
- // This part does not include in sqlcli.h, it is only in ODBC
- // Set the ODBC application Version to 3.x
- // SQLSetEnvattr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTERGER);
-
- // Allocate A Connection Handle
- SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
-
- // Connect to NDB
- retcode = SQLConnect(hdbc,
- (SQLCHAR*) "Sales",
- 5,
- (SQLCHAR*) "JohnS",
- 5,
- (SQLCHAR*) "Sesame",
- 6);
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_DBC, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
- else
- { if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- NDBT_Connect_DisplayError(SQL_HANDLE_DBC, hdbc);}
-
- // Free the Connection Handle
- SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
-
- // Free the Environment Handle
- SQLFreeHandle(SQL_HANDLE_ENV, henv);
-
- return 0;
-}
-
-
-void NDBT_Connect_DisplayError(SQLSMALLINT HandleType, SQLHDBC InputHandle)
-{
- SQLRETURN Sqlstate;
- int i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
-
-}
diff --git a/storage/ndb/test/odbc/client/NDBT_SQLPrepare.cpp b/storage/ndb/test/odbc/client/NDBT_SQLPrepare.cpp
deleted file mode 100644
index a35a108becc..00000000000
--- a/storage/ndb/test/odbc/client/NDBT_SQLPrepare.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NdbOut.hpp>
-#include <sqlext.h>
-#include <stdio.h>
-
-#include <NdbTest.hpp>
-#include <NdbMain.h>
-
-using namespace std;
-
-SQLHDBC hdbc;
-SQLHSTMT hstmt;
-SQLHENV henv;
-SQLHDESC hdesc;
-SQLRETURN SQLPrepare_retcode, SQLAllocHandl_retcode, SQLSTATEs;
-
-SQLCHAR Sqlstate[5];
-
-SQLINTEGER NativeError;
-SQLSMALLINT i, MsgLen;
-SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
-
-void NDBT_SQLPrepare_DisplayError(SQLSMALLINT HandleType, SQLHSTMT InputHandle);
-
- // Execute a statement to retrieve rows from the Customers table. We can
- // create the table and inside rows into NDB by invoking SQLExecute() or
- // another program called TestDirectSQL
-
-int NDBT_SQLPrepare()
-{
- // Allocate An Environment Handle
- SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
-
- // Allocate A Connection Handle
- SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
-
- // Allocate A Connection Handle
- SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
-
- // Connecte to database
- SQLConnect(hdbc, (SQLCHAR*) "Sales", 5, (SQLCHAR*) "JohnS", 5, (SQLCHAR*) "Sesame", 6);
-
- // Allocate A Statement Handle
- SQLAllocHandl_retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
-
- /* We can change the SQL statement in the SQLPrepare() function according to the requirement of Johnny. */
- /* The order of the SQL statement could be CREATE, INSERT, UPDATE, SELECT, DELETE or another special SQL */
-
- if (SQLAllocHandl_retcode == SQL_SUCCESS){
- SQLPrepare_retcode = SQLPrepare(hstmt, (SQLCHAR*)"SELECT CustID, Name, Address, Phone FROM Customers", 56);
-
- if (SQLPrepare_retcode == SQL_INVALID_HANDLE)
-ndbout << "Handle Type is SQL_HANDLE_STMT, but string SQL_INVALID_HANDLE and SQL_SUCCESS still appeared. Please check programm" << endl;
-
- if (SQLPrepare_retcode == SQL_ERROR || SQLPrepare_retcode == SQL_SUCCESS_WITH_INFO)
- NDBT_SQLPrepare_DisplayError(SQL_HANDLE_STMT, hstmt);
-
- SQLExecute(hstmt);
-
- SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
- }
-
- // Disconnect from the database before free Connection Handle and Environment Handle
- SQLDisconnect(hdbc);
-
- // Free the Connection Handle
- SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
-
- // Free the Environment Handle
- SQLFreeHandle(SQL_HANDLE_ENV, henv);
-
- return 0;
-
- }
-
-
-void NDBT_SQLPrepare_DisplayError(SQLSMALLINT HandleType, SQLHSTMT InputHandle)
-{
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
-
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLAllocEnvTest.cpp b/storage/ndb/test/odbc/client/SQLAllocEnvTest.cpp
deleted file mode 100644
index fbabc334fd2..00000000000
--- a/storage/ndb/test/odbc/client/SQLAllocEnvTest.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include "common.h"
-#define SQL_MAXIMUM_MESSAGE_LENGTH 200
-
-using namespace std;
-
-SQLHDBC hdbc;
-SQLHENV henv;
-SQLRETURN retcode, SQLSTATEs;
-
-SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
-SQLCHAR Sqlstate[5];
-
-SQLINTEGER NativeError;
-SQLSMALLINT i, MsgLen;
-
-void sqlallocenv_deal_with_HENV(SQLSMALLINT HandleType, SQLHENV InputHandle);
-void sqlallocenv_deal_with_HDBC(SQLSMALLINT HandleType, SQLHDBC InputHandle);
-
-void DisplayError_HDBC_free(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHDBC InputHandle);
-void DisplayError_HENV_free(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHENV InputHandle);
-
-
-int SQLAllocEnvTest()
-{
-
-/* Environment test for SQLAllocEnv() */
-ndbout << "Environment test for SQLAllocEnv()" << endl;
-//SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
-
-sqlallocenv_deal_with_HENV(SQL_HANDLE_ENV, henv);
-
-//SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
-//SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
-sqlallocenv_deal_with_HDBC(SQL_HANDLE_DBC, hdbc);
-
-return 0;
-
-}
-
-void sqlallocenv_deal_with_HDBC(SQLSMALLINT HandleType, SQLHDBC InputHandle)
-{
- SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
- retcode = SQLAllocHandle(HandleType, henv, &InputHandle);
-
- ndbout << "the HandleType is : " << HandleType << endl;
- ndbout << "the InputHandle is SQLHDBC:" << InputHandle << endl;
- ndbout << "retcode = " << retcode << endl;
-
- /* ***
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
- DisplayError_HDBC_free(Sqlstate, HandleType, InputHandle);
-
- i ++;
- }
- }
- *** */
-}
-
-void sqlallocenv_deal_with_HENV(SQLSMALLINT HandleType, SQLHENV InputHandle)
-{
- retcode = SQLAllocEnv(&InputHandle);
-
- ndbout << "the HandleType is : " << HandleType << endl;
- ndbout << "the InputHandle is SQLHENV:" << InputHandle << endl;
- ndbout << "retcode = " << retcode << endl;
- /*
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- DisplayError_HENV_free(Sqlstate, HandleType, InputHandle);
-
- i ++;
- }
- }
- */
- }
-
-
-void DisplayError_HENV_free(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHENV InputHandle)
-{
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-}
-
-void DisplayError_HDBC_free(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHDBC InputHandle)
-{
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-}
-
diff --git a/storage/ndb/test/odbc/client/SQLAllocHandleTest.cpp b/storage/ndb/test/odbc/client/SQLAllocHandleTest.cpp
deleted file mode 100644
index 206edb8216f..00000000000
--- a/storage/ndb/test/odbc/client/SQLAllocHandleTest.cpp
+++ /dev/null
@@ -1,314 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include "common.h"
-
-using namespace std;
-
-#define SQL_MAXIMUM_MESSAGE_LENGTH 200
-
-SQLHDBC hdbc;
-SQLHSTMT hstmt;
-SQLHENV henv;
-SQLHDESC hdesc;
-SQLRETURN retcode, SQLSTATEs;
-
-SQLCHAR Sqlstate[5];
-
-SQLINTEGER NativeError;
-SQLSMALLINT i, MsgLen;
-long strangehandle;
-
-void handle_deal_with_HSTMT(SQLSMALLINT HandleType, SQLHSTMT InputHandle);
-void handle_deal_with_HENV(SQLSMALLINT HandleType, SQLHENV InputHandle);
-void handle_deal_with_HDESC(SQLSMALLINT HandleType, SQLHDESC InputHandle);
-void handle_deal_with_HDBC(SQLSMALLINT HandleType, SQLHDBC InputHandle);
-//void handle_deal_with_int(SQLSMALLINT HandleType, long InputHandle);
-
-void DisplayError_HDBC(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHDBC InputHandle);
-void DisplayError_HSTMT(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHSTMT InputHandle);
-void DisplayError_HENV(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHENV InputHandle);
-void DisplayError_HDESC(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHDESC InputHandle);
-//void DisplayError_int(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, int InputHandle);
-
-int SQLAllocHandleTest()
-{
-
-strangehandle = 6;
-
-/*Allocate environment handle */
-
-//retcode = SQLFreeHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE);
-
-/* ENV */
-ndbout << endl;
-ndbout << "The HandleType: Allocate Environment handle" << endl;
-ndbout << endl;
-
-handle_deal_with_HENV(SQL_HANDLE_ENV, SQL_NULL_HANDLE);
-
-handle_deal_with_HENV(SQL_HANDLE_ENV, henv);
-
-handle_deal_with_HDBC(SQL_HANDLE_ENV, hdbc);
-
-handle_deal_with_HSTMT(SQL_HANDLE_ENV, hstmt);
-
-handle_deal_with_HDESC(SQL_HANDLE_ENV, hdesc);
-
-//handle_deal_with_int(SQL_HANDLE_ENV, strangehandle);
-
-/* DBC */
-ndbout << endl;
-ndbout << "The HandleType: Allocate Connection handle" << endl;
-ndbout << endl;
-
-handle_deal_with_HDBC(SQL_HANDLE_DBC, SQL_NULL_HANDLE);
-
-handle_deal_with_HENV(SQL_HANDLE_DBC, henv);
-
-handle_deal_with_HDBC(SQL_HANDLE_DBC, hdbc);
-
-handle_deal_with_HSTMT(SQL_HANDLE_DBC, hstmt);
-
-handle_deal_with_HDESC(SQL_HANDLE_DBC, hdesc);
-
-//handle_deal_with_int(SQL_HANDLE_DBC, strangehandle);
-
-/* STMT */
-ndbout << endl;
-ndbout << "The HandleType: Allocate Statement handle" << endl;
-ndbout << endl;
-
-handle_deal_with_HSTMT(SQL_HANDLE_STMT, SQL_NULL_HANDLE);
-
-handle_deal_with_HENV(SQL_HANDLE_STMT, henv);
-
-handle_deal_with_HDBC(SQL_HANDLE_STMT, hdbc);
-
-handle_deal_with_HSTMT(SQL_HANDLE_STMT, hstmt);
-
-handle_deal_with_HDESC(SQL_HANDLE_STMT, hdesc);
-
-//handle_deal_with_int(SQL_HANDLE_STMT, strangehandle);
-
-
-/* DESC */
-ndbout << endl;
-ndbout << "The HandType: Allocate Descriptor handle" << endl;
-ndbout << endl;
-
-handle_deal_with_HDESC(SQL_HANDLE_DESC, SQL_NULL_HANDLE);
-
-handle_deal_with_HENV(SQL_HANDLE_DESC, henv);
-
-handle_deal_with_HDBC(SQL_HANDLE_DESC, hdbc);
-
-handle_deal_with_HSTMT(SQL_HANDLE_DESC, hstmt);
-
-handle_deal_with_HDESC(SQL_HANDLE_DESC, hdesc);
-
-//handle_deal_with_int(SQL_HANDLE_DESC, strangehandle);
-
-
-/* strangehandle */
-ndbout << endl;
-ndbout << "The HandType: strangehandle" << endl;
-ndbout << endl;
-
-//handle_deal_with_int(strangehandle, SQL_NULL_HANDLE);
-
-handle_deal_with_HENV(strangehandle, henv);
-
-handle_deal_with_HDBC(strangehandle, hdbc);
-
-handle_deal_with_HSTMT(strangehandle, hstmt);
-
-handle_deal_with_HDESC(strangehandle, hdesc);
-
-// handle_deal_with_int(strangehandle, strangehandle);
-
-return 0;
-
-}
-
-void handle_deal_with_HDBC(SQLSMALLINT HandleType, SQLHDBC InputHandle)
-{
- SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
- retcode = SQLAllocHandle(HandleType, InputHandle, &hdbc);
-
- ndbout << "the HandleType is : " << HandleType << endl;
-
- ndbout << "the InputHandle is SQLHDBC:" << InputHandle << endl;
-
- ndbout << "return &hdbc: " << (long)&hdbc << endl;
- ndbout << "the retcode state is:" << retcode << endl;
- ndbout << endl;
-
- /*
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
- DisplayError_HDBC(Sqlstate, HandleType, InputHandle);
- i ++;
- }
- }
- */
- }
-
-
-void handle_deal_with_HSTMT(SQLSMALLINT HandleType, SQLHSTMT InputHandle)
-{
- SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
- retcode = SQLAllocHandle(HandleType, InputHandle, &hstmt);
-
- ndbout << "the HandleType is : " << HandleType << endl;
-
- ndbout << "the InputHandle is SQLHSTMT:" << InputHandle << endl;
-
- ndbout << "return &hstmt: " << (long)&hstmt << endl;
- ndbout << "the output retcode is:" << retcode << endl;
- ndbout << endl;
- /*
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
- DisplayError_HSTMT(Sqlstate, HandleType, InputHandle);
- i ++;
- }
- }
- */
- }
-
-void handle_deal_with_HENV(SQLSMALLINT HandleType, SQLHENV InputHandle)
-{
- SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
- retcode = SQLAllocHandle(HandleType, InputHandle, &henv);
-
- ndbout << "the HandleType is : " << HandleType << endl;
-
- ndbout << "the InputHandle is SQLHENV:" << InputHandle << endl;
-
- ndbout << "return &henv: " << (long)&henv << endl;
- ndbout << "the output retcode is:" << retcode << endl;
- ndbout << endl;
- /*
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- DisplayError_HENV(Sqlstate, HandleType, InputHandle);
- i ++;
- }
- }
- */
- }
-
-void handle_deal_with_HDESC(SQLSMALLINT HandleType, SQLHDESC InputHandle)
-{
- SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
- retcode = SQLAllocHandle(HandleType, InputHandle, &hdesc);
-
- ndbout << "the HandleType is : " << HandleType << endl;
-
- ndbout << "the InputHandle is SQLHDESC:" << InputHandle << endl;
-
- ndbout << "return &hdesc: " << (long)&hdesc << endl;
- ndbout << "the output retcode is:" << retcode << endl;
- ndbout << endl;
- /*
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- DisplayError_HDESC(Sqlstate, HandleType, InputHandle);
- i ++;
- }
- }
- */
- }
-
-
-//void handle_deal_with_int(SQLSMALLINT HandleType, long InputHandle)
-//{
-// SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
-// retcode = SQLAllocHandle(HandleType, InputHandle, &InputHandle);
-//
-// ndbout << "the HandleType is: " << HandleType << endl;
-//
-// ndbout << "the InputHandle is stranghandle:" << InputHandle << endl;
-//
-// ndbout << "return &InputHandle: " << (long)&InputHandle << endl;
-// ndbout << "the output retcode is:" << retcode << endl;
-// ndbout << endl;
-// /*
-// if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
-// i = 1;
-// while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
-// Sqlstate, &NativeError, Msg, sizeof(Msg),
-// &MsgLen)) != SQL_NO_DATA) {
-//
-// DisplayError_int(Sqlstate, HandleType, InputHandle);
-//
-// i ++;
-// }
-// }
-// */
-// }
-
-
-void DisplayError_HENV(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHENV InputHandle)
-{
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-}
-
-
-void DisplayError_HDBC(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHDBC InputHandle)
-{
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-}
-
-void DisplayError_HSTMT(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHSTMT InputHandle)
-{
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-}
-
-void DisplayError_HDESC(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHDESC InputHandle)
-{
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-}
-
-//void DisplayError_int(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, int InputHandle)
-//{
-// ndbout << "the HandleType is:" << HandleType << endl;
-// ndbout << "the InputHandle is :" << InputHandle << endl;
-// ndbout << "the output state is:" << (char *)Sqlstate << endl;
-//}
diff --git a/storage/ndb/test/odbc/client/SQLAllocHandleTest_bf.cpp b/storage/ndb/test/odbc/client/SQLAllocHandleTest_bf.cpp
deleted file mode 100644
index dfc8fe6260a..00000000000
--- a/storage/ndb/test/odbc/client/SQLAllocHandleTest_bf.cpp
+++ /dev/null
@@ -1,259 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include sqlcli.h;
-#include stdio.h;
-
-#define SQL_MAX_MESSAGE_LENGTH 200;
-
-SQLHDBC hdbc;
-SQLHSTMT hstmt;
-SQLHENV henv;
-SQLHDESC hdesc;
-SQLRETURN retcode, SQLSTATEs;
-
-SQLCHAR SqlState[6], SQLStmt[100], Msg[SQL_MAX_MESSAGE_LENGTH];
-SQLINTEGER NativeError;
-SQLSMALLINT i, MsgLen;
-
-struct handle_set
-{
-SQLHDBC hdbc_varible;
-SQLHSTMT hstmt_varible;
-SQLHENV henv_varible;
-SQLHDESC hdesc_varible;
-INTEGER strangehandle;
-}
-
-static int
-check(
- SQLSMALLINT HandleType,
- SQLHANDLE inputhandle,
- SQLHANDLE *outputhandle,
- SQLRETURN wantret,
- char *wantSqlstate)
-{
- SQLRETURN ret;
- SQLCHAR Sqlstate[20];
-
- ret = SQLAllocHandle(handletype, inputhandle, outputhandle);
- if (ret != wantret) {
- // report error
- return -1;
- }
- if (ret == SQL_INVALID_HANDLE) {
- // cannot get diag
- return 0;
- }
- // TODO
- ret = SQLGetDiagRec(HandleType, InputHandle, 1, Sqlstate, &NativeError, Msg, sizeof(Msg), &MsgLen);
- if (strcmp(Sqlstate, wantSqlstate) != 0) {
- // report error;
- return -1;
- }
- return 0;
-}
-
-int
-Test_SQLAllocHandle()
-{
- SQLRETURN ret;
- SQLHENV henv;
- SQLDBC dbc;
- int i;
-
- // env
- check(SQL_HANDLE_ENV, SQL_NULL_HANDLE, 0, SQL_ERROR, "HY009");
- for (i = 0; i < 1000; i++) {
- if (i != SQL_NULL_HANDLE)
- check(SQL_HANDLE_ENV, i, &henv, SQL_INVALID_HANDLE, 0);
- }
- if (check(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv, SQL_SUCCESS, "00000") < 0)
- return -1;
-
- // dbc
- check(SQL_HANDLE_DBC, henv, 0, SQL_ERROR, "HY009");
- for (i = 0; i < 1000; i++) {
- if (i != henv)
- check(SQL_HANDLE_DBC, i, &dbc, SQL_INVALID_HANDLE, 0);
- }
- if (check(SQL_HANDLE_DBC, henv, &dbc, SQL_SUCCESS, "00000") < 0)
- return -1;
-
- //??
- check(SQL_HANDLE_ENV, dbc, 0, SQL_ERROR, "HY092");
-
- // TODO
- // stmt
-
- return 0;
-}
-
-
-handle_set handlevalue;
-
-handlevalue.hdbc_varible = hdbc;
-handlevalue.hstmt_varible = hstmt;
-handlevalue.henv_varible = henv;
-handlevalue.hdesc_varible = hdesc;
-handlevalue.stranghandle = 67;
-
- /*Allocate environment handle */
-//retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
-
-while (int j = 0; j++; j < 6) {
- if ( j = 0 )
- handle_deal_with(SQL_HANDLE_ENV, SQL_NULL_HANDLE, );
-
- else if ( j = 1 )
- handle_deal_with(SQL_HANDLE_ENV, handlevalue.henv_varible, );
-
- else if ( j = 2 )
- handle_deal_with(SQL_HANDLE_ENV, handlevalue.hdbc_varible, );
-
- else if ( j = 3 )
- handle_deal_with(SQL_HANDLE_ENV, handlevalue.hstmt_varible, );
-
- else if ( j = 4 )
- handle_deal_with(SQL_HANDLE_ENV, handlevalue.hdesc_varible, );
-
- else
- handle_deal_with(SQL_HANDLE_ENV, handlevalue.stranghandle, );
-
- }
-
- while (int j = 0; j++; j < 6) {
- if ( j = 0 )
- handle_deal_with(SQL_HANDLE_DBC, SQL_NULL_HANDLE, );
-
- else if ( j = 1 )
- handle_deal_with(SQL_HANDLE_DBC, handlevalue.henv_varible, );
-
- else if ( j = 2 )
- handle_deal_with(SQL_HANDLE_DBC, handlevalue.hdbc_varible, );
-
- else if ( j = 3 )
- handle_deal_with(SQL_HANDLE_DBC, handlevalue.hstmt_varible, );
-
- else if ( j = 4 )
- handle_deal_with(SQL_HANDLE_DBC, handlevalue.hdesc_varible, );
-
- else
- handle_deal_with(SQL_HANDLE_DBC, handlevalue.stranghandle, );
-
- }
-
-
- while (int j = 0; j++; j < 6) {
- if ( j = 0 )
- handle_deal_with(SQL_HANDLE_STMT, SQL_NULL_HANDLE, );
-
- else if ( j = 1 )
- handle_deal_with(SQL_HANDLE_STMT, handlevalue.henv_varible, );
-
- else if ( j = 2 )
- handle_deal_with(SQL_HANDLE_STMT, handlevalue.hdbc_varible, );
-
- else if ( j = 3 )
- handle_deal_with(SQL_HANDLE_STMT, handlevalue.hstmt_varible, );
-
- else if ( j = 4 )
- handle_deal_with(SQL_HANDLE_STMT, handlevalue.hdesc_varible, );
-
- else
- handle_deal_with(SQL_HANDLE_STMT, handlevalue.stranghandle, );
-
- }
-
-
-
- while (int j = 0; j++; j < 6) {
- if ( j = 0 )
- handle_deal_with(SQL_HANDLE_DESC, SQL_NULL_HANDLE, );
-
- else if ( j = 1 )
- handle_deal_with(SQL_HANDLE_DESC, handlevalue.henv_varible, );
-
- else if ( j = 2 )
- handle_deal_with(SQL_HANDLE_DESC, handlevalue.hdbc_varible, );
-
- else if ( j = 3 )
- handle_deal_with(SQL_HANDLE_DESC, handlevalue.hstmt_varible, );
-
- else if ( j = 4 )
- handle_deal_with(SQL_HANDLE_DESC, handlevalue.hdesc_varible, );
-
- else
- handle_deal_with(SQL_HANDLE_DESC, handlevalue.stranghandle, );
-
- }
-
- while (int j = 0; j++; j < 6) {
- if ( j = 0 )
- handle_deal_with(handlevalue.stranghandle, SQL_NULL_HANDLE, );
-
- else if ( j = 1 )
- handle_deal_with(handlevalue.stranghandle, handlevalue.henv_varible, );
-
- else if ( j = 2 )
- handle_deal_with(handlevalue.stranghandle, handlevalue.hdbc_varible, );
-
- else if ( j = 3 )
- handle_deal_with(handlevalue.stranghandle, handlevalue.hstmt_varible, );
-
- else if ( j = 4 )
- handle_deal_with(handlevalue.stranghandle handlevalue.hdesc_varible, );
-
- else
- handle_deal_with(handlevalue.stranghandle, handlevalue.stranghandle, );
-
- }
-
-
-}
-
-
-void DisplayError(SQLCHAR SqlState[6], string SQLSTATE, string flag, SQLSMALLINT HandleType, SQLHANDLE InputHandle)
-{
-cout << "the operation is: " << flag << endl;
-cout << "the HandleType is:" << HandleType << endl;
-cout << "the InputHandle is :"<< InputHandle <<endl;
-cout << "the correct state is:" << SQLSTATE << endl;
-cout << "the output state is:" << Sqlstate << endl;
-}
-
-}
-
-
-void handle_deal_with(SQLSMALLINT HandleType, SQLHANDLE InputHandle, string SQLSTATE)
-{
- retcode = SQLAllocHandle(HandleType, InputHandle, OutputHandlePtr);
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATE) {
-
- if (SQLSTATE = Sqlstate )
- DisplayError(SqlState, SQLSTATE, 'OK');
-
- else
- DisplayError(SqlState, SQLSTATE, 'failure');
-
- i ++;
- }
- }
- }
diff --git a/storage/ndb/test/odbc/client/SQLBindColTest.cpp b/storage/ndb/test/odbc/client/SQLBindColTest.cpp
deleted file mode 100644
index 3bddf14152d..00000000000
--- a/storage/ndb/test/odbc/client/SQLBindColTest.cpp
+++ /dev/null
@@ -1,537 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
- /**
- * @file SQLBindColTest.cpp
- */
-#include <common.hpp>
-using namespace std;
-
-#define BindCol_NAME_LEN 10
-#define BindCol_PHONE_LEN 10
-#define BindCol_ADDRESS_LEN 10
-#define BindCol_Price_LEN 10
-#define BindCol_Weight_LEN 10
-#define BindCol_Tax_LEN 10
-
-#define BindCol_SQL_MAXIMUM_MESSAGE_LENGTH 200
-
-//SQLHDBC BindCol_hdbc;
-//SQLHSTMT BindCol_hstmt;
-//SQLHENV BindCol_henv;
-//SQLHDESC BindCol_hdesc;
-//SQLRETURN BCret;
-
-//SQLCHAR BindCol_Name[BindCol_NAME_LEN], BindCol_Phone[BindCol_PHONE_LEN];
-//SQLCHAR BindCol_Address[BindCol_ADDRESS_LEN];
-//SQLINTEGER NativeError;
-//unsigned long BindCol_CustID;
-
-void BindCol_DisplayError(SQLSMALLINT BindCol_HandleType,
- SQLHSTMT BindCol_InputHandle);
-
-/**
- * Test setting column to bind
- * for a column in a result
- *
- * -# Bind columns 1
- * -# Bind columns 2
- * -# Bind columns 3
- * -# Bind columns 4
- * -# Bind columns 5
- * -# Bind columns 6
- * -# Bind columns 7
- * @return Zero, if test succeeded
- */
-
-int SQLBindColTest()
-{
-
- SQLHDBC BindCol_hdbc;
- SQLHSTMT BindCol_hstmt;
- SQLHENV BindCol_henv;
- SQLHDESC BindCol_hdesc;
-
- SQLCHAR SQLStmt1 [240];
- SQLCHAR SQLStmt2 [240];
- SQLCHAR SQLStmt3 [120];
-
- SQLRETURN BCret;
-
- unsigned long BindCol_CustID;
- SQLCHAR BindCol_Name[BindCol_NAME_LEN];
- short BindCol_Account;
- unsigned short BindCol_Phone;
- long BindCol_Price;
- float BindCol_Weight;
- double BindCol_Tax;
-
- ndbout << endl << "Start SQLBindCol Testing" << endl;
-
- //*******************************************************************
- //** hstmt
- //** Execute a statement to retrieve rows from the Customers table **
- //** We can create the table and insert rows into Customers **
- //*******************************************************************
-
- //************************************
- //** Allocate An Environment Handle **
- //************************************
- BCret = SQLAllocHandle(SQL_HANDLE_ENV,
- SQL_NULL_HANDLE,
- &BindCol_henv);
-
-if (BCret == SQL_SUCCESS || BCret == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated an environment Handle!" << endl;
-
- //*********************************************
- //** Set the ODBC application Version to 3.x **
- //*********************************************
- BCret = SQLSetEnvAttr(BindCol_henv,
- SQL_ATTR_ODBC_VERSION,
- (SQLPOINTER) SQL_OV_ODBC3,
- SQL_IS_UINTEGER);
-
-if (BCret == SQL_SUCCESS || BCret == SQL_SUCCESS_WITH_INFO)
- ndbout << "Set the ODBC application Version to 3.x!" << endl;
-
-//**********************************
-//** Allocate A Connection Handle **
-//**********************************
-
- BCret = SQLAllocHandle(SQL_HANDLE_DBC,
- BindCol_henv,
- &BindCol_hdbc);
-
- if (BCret == SQL_SUCCESS || BCret == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a connection Handle!" << endl;
-
- // *******************
- // ** Connect to DB **
- // *******************
- BCret = SQLConnect(BindCol_hdbc,
- (SQLCHAR *) connectString(),
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS);
-
- if (BCret == SQL_SUCCESS || BCret == SQL_SUCCESS_WITH_INFO)
- ndbout << "Connected to DB : OK!" << endl;
- else
- {
- ndbout << "Failure to Connect DB!" << endl;
- return NDBT_FAILED;
- }
-
- //*******************************
- //** Allocate statement handle **
- //*******************************
-
- BCret = SQLAllocHandle(SQL_HANDLE_STMT,
- BindCol_hdbc,
- &BindCol_hstmt);
- if(BCret == SQL_SUCCESS || BCret == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a statement handle!" << endl;
-
- //************************
- //** Define a statement **
- //************************
-
- /* Primary key is Integer and Char */
- strcpy((char *) SQLStmt1, "CREATE TABLE Customer1(CustID Integer, Name Char(12), Account Char(12), Phone Char(12), Price Char(6), Weight Char(6), Tax Char(6), Primary Key(CustID, Name))");
-
- strcpy((char *) SQLStmt2, "INSERT INTO Customer1 (CustID, Name, Account, Phone, Price, Weight, Tax) VALUES(588, 'peter','6808','7190890', '5.68', '1.58', '0.88')");
-
- strcpy((char *) SQLStmt3, "SELECT * FROM Customer1");
-
- //************************************************
- //** Prepare and Execute CREATE TABLE statement **
- //************************************************
- ndbout << endl << "Prepare and Execute CREATE TABLE statement ......" << endl;
- ndbout << ">>>>" << (char*)SQLStmt1 << "<<<<" << endl;
- BCret = SQLExecDirect(BindCol_hstmt,
- SQLStmt1,
- SQL_NTS);
- if (BCret == SQL_SUCCESS)
- ndbout << "Prepare and Execute CREATE TABLE statement OK!"
- << endl<< endl;
-
- if (BCret == SQL_ERROR || BCret == SQL_SUCCESS_WITH_INFO)
- BindCol_DisplayError(SQL_HANDLE_STMT, BindCol_hstmt);
-
- if (BCret == -2)
- {
- ndbout << "BCret = SQLExexDirect()=" << BCret << endl;
- BindCol_DisplayError(SQL_HANDLE_STMT, BindCol_hstmt);
- }
-
- //*******************************************************
- //** Prepare and Execute INSERT statement with prepare **
- //*******************************************************
- ndbout << "Prepare and Execute INSERT statement ......" << endl;
- ndbout << ">>>>" << (char*)SQLStmt2 << "<<<<" << endl;
- BCret = SQLExecDirect(BindCol_hstmt,
- SQLStmt2,
- SQL_NTS);
-
- if (BCret == SQL_SUCCESS)
- ndbout << "Prepare and Execute INSERT statement OK!"
- << endl << endl;
-
- if (BCret == SQL_ERROR || BCret == SQL_SUCCESS_WITH_INFO)
- BindCol_DisplayError(SQL_HANDLE_STMT, BindCol_hstmt);
-
- if (BCret == -2)
- {
- ndbout << "BCret = SQLExexDirect()=" << BCret << endl;
- BindCol_DisplayError(SQL_HANDLE_STMT, BindCol_hstmt);
- }
-
- //******************************************
- //** Prepare and EXECUTE SELECT statement **
- //******************************************
- ndbout << "Prepare and Execute SELECT statement ......" << endl;
- ndbout << ">>>>" << (char*)SQLStmt3 << "<<<<" << endl;
- BCret = SQLExecDirect(BindCol_hstmt,
- SQLStmt3,
- SQL_NTS);
-
- if (BCret == SQL_SUCCESS)
- ndbout << "Prepare and Execute SELECT statement OK!"
- << endl << endl;
-
- if (BCret == SQL_ERROR || BCret == SQL_SUCCESS_WITH_INFO)
- BindCol_DisplayError(SQL_HANDLE_STMT, BindCol_hstmt);
-
- if (BCret == -2)
- {
- ndbout << "BCret = SQLExexDirect()=" << BCret << endl;
- BindCol_DisplayError(SQL_HANDLE_STMT, BindCol_hstmt);
- }
-
- //*******************************
- //** Execute SELECT statement **
- //*******************************
- // BCret = SQLExecute(BindCol_hstmt);
- // if (BCret == SQL_ERROR || BCret == SQL_SUCCESS_WITH_INFO)
- // {
- // ndbout << "BCret = " << BCret << endl;
- // BindCol_DisplayError(SQL_HANDLE_STMT, BindCol_hstmt);
- // }
- // else
- // {
-
- if (BCret == SQL_SUCCESS)
- ndbout << "Execute INSERT statement OK!" << endl;
-
- //*********************
- //** Test1 **
- //** Bind columns 1 **
- //*********************
-
- BCret =SQLBindCol(BindCol_hstmt,
- 1,
- SQL_C_ULONG,
- &BindCol_CustID,
- sizeof(BindCol_CustID),
- NULL);
-
- if (BCret == SQL_SUCCESS)
- {
- ndbout << endl << "Bind col 1 OK!" << endl;
- }
- else if (BCret == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "Bind Col 1 OK but with INFO" << endl;
- BindCol_DisplayError(SQL_HANDLE_STMT, BindCol_hstmt);
- }
- else if (BCret == SQL_ERROR)
- {
- ndbout << "Bind Col 1 Failed!" << endl;
- BindCol_DisplayError(SQL_HANDLE_STMT, BindCol_hstmt);
- return NDBT_FAILED;
- }
- else
- ndbout << endl;
-
- //*********************
- //** Test2 **
- //** Bind columns 2 **
- //*********************
-
- BCret =SQLBindCol(BindCol_hstmt,
- 2,
- SQL_C_CHAR,
- &BindCol_Name,
- BindCol_NAME_LEN,
- NULL);
-
- if (BCret == SQL_SUCCESS)
- {
- ndbout << "Bind col 2 OK!" << endl;
- }
- else if (BCret == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "Bind Col 2 OK but with INFO" << endl;
- BindCol_DisplayError(SQL_HANDLE_STMT, BindCol_hstmt);
- }
- else if (BCret == SQL_ERROR)
- {
- ndbout << "Bind Col 2 Failed!" << endl;
- BindCol_DisplayError(SQL_HANDLE_STMT, BindCol_hstmt);
- return NDBT_FAILED;
- }
- else
- ndbout << endl;
-
- //*********************
- //** Test3 **
- //** Bind columns 3 **
- //*********************
-
- BCret = SQLBindCol(BindCol_hstmt,
- 3,
- SQL_C_USHORT,
- &BindCol_Account,
- sizeof(BindCol_Account),
- NULL);
-
- if (BCret == SQL_ERROR)
- {
- ndbout << "Bind Col 3 Failed!" << endl;
- BindCol_DisplayError(SQL_HANDLE_STMT, BindCol_hstmt);
- return NDBT_FAILED;
- }
- else if (BCret == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "Bind Col 3 OK but with INFO" << endl;
- BindCol_DisplayError(SQL_HANDLE_STMT, BindCol_hstmt);
- }
- else if (BCret == SQL_SUCCESS)
- {
- ndbout << "Bind col 3 OK!" << endl;
- }
- else
- ndbout << endl;
-
- //*********************
- //** Test4 **
- //** Bind columns 4 **
- //*********************
-
- BCret = SQLBindCol(BindCol_hstmt,
- 4,
- SQL_C_USHORT,
- &BindCol_Phone,
- sizeof(BindCol_Phone),
- NULL);
-
- if (BCret == SQL_ERROR)
- {
- ndbout << "Bind Col 4 Failed!" << endl;
- BindCol_DisplayError(SQL_HANDLE_STMT, BindCol_hstmt);
- return NDBT_FAILED;
- }
- else if (BCret == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "Bind Col 4 OK but with INFO" << endl;
- BindCol_DisplayError(SQL_HANDLE_STMT, BindCol_hstmt);
- }
- else if (BCret == SQL_SUCCESS)
- {
- ndbout << "Bind col 4 OK!" << endl;
- }
- else
- ndbout << endl;
-
- //*********************
- //** Test5 **
- //** Bind columns 5 **
- //*********************
-
- BCret = SQLBindCol(BindCol_hstmt,
- 5,
- SQL_C_SLONG,
- &BindCol_Price,
- sizeof(BindCol_Price),
- NULL);
-
- if (BCret == SQL_ERROR)
- {
- ndbout << "Bind Col 5 Failed!" << endl;
- BindCol_DisplayError(SQL_HANDLE_STMT, BindCol_hstmt);
- return NDBT_FAILED;
- }
- else if (BCret == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "Bind Col 5 OK but with INFO" << endl;
- BindCol_DisplayError(SQL_HANDLE_STMT, BindCol_hstmt);
- }
- else if (BCret == SQL_SUCCESS)
- {
- ndbout << "Bind col 5 OK!" << endl;
- }
- else
- ndbout << endl;
-
- //*********************
- //** Test6 **
- //** Bind columns 6 **
- //*********************
-
- BCret = SQLBindCol(BindCol_hstmt,
- 6,
- SQL_C_FLOAT,
- &BindCol_Weight,
- sizeof(BindCol_Weight),
- NULL);
-
- if (BCret == SQL_ERROR)
- {
- ndbout << "Bind Col 6 Failed!" << endl;
- BindCol_DisplayError(SQL_HANDLE_STMT, BindCol_hstmt);
- return NDBT_FAILED;
- }
- else if (BCret == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "Bind Col 6 OK but with INFO" << endl;
- BindCol_DisplayError(SQL_HANDLE_STMT, BindCol_hstmt);
- }
- else if (BCret == SQL_SUCCESS)
- {
- ndbout << "Bind col 6 OK!" << endl;
- }
- else
- ndbout << endl;
-
- //*********************
- //** Test7 **
- //** Bind columns 7 **
- //*********************
-
- BCret = SQLBindCol(BindCol_hstmt,
- 7,
- SQL_C_DOUBLE,
- &BindCol_Tax,
- sizeof(BindCol_Tax),
- NULL);
-
- if (BCret == SQL_ERROR)
- {
- ndbout << "Bind Col 7 Failed!" << endl;
- BindCol_DisplayError(SQL_HANDLE_STMT, BindCol_hstmt);
- return NDBT_FAILED;
- }
- else if (BCret == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "Bind Col 7 OK but with INFO" << endl;
- BindCol_DisplayError(SQL_HANDLE_STMT, BindCol_hstmt);
- }
- else if (BCret == SQL_SUCCESS)
- {
- ndbout << "Bind col 7 OK!" << endl;
- }
- else
- ndbout << endl;
-
- //}
-
-//*****************************************
-//* Fetch and print each row of data. On **
-//* an error, display a message and exit **
-//*****************************************
-
-BCret = SQLFetch(BindCol_hstmt);
-
- ndbout << endl << "BCret = SQLFetch(BindCol_hstmt) = "
- << BCret << endl;
-
-if (BCret == SQL_ERROR)
-{
- BindCol_DisplayError(SQL_HANDLE_STMT, BindCol_hstmt);
- return NDBT_FAILED;
-}
-else if (BCret == SQL_SUCCESS_WITH_INFO)
-{
- ndbout << "CustID = " << (int)BindCol_CustID << endl;
- ndbout << "Name = " << (char *)BindCol_Name << endl;
- ndbout << "Account = " << (int)BindCol_Account << endl;
- ndbout << "Phone = " << (int)BindCol_Phone << endl;
- ndbout << "Price = " << (int)BindCol_Price << endl;
- ndbout << "Weight = " << (int)BindCol_Weight << endl;
- ndbout << "Tax = " << (int)BindCol_Tax << endl;
- BindCol_DisplayError(SQL_HANDLE_STMT, BindCol_hstmt);
-}
-else
-{
- ndbout << "CustID = " << (int)BindCol_CustID << endl;
- ndbout << "Name = " << (char *)BindCol_Name << endl;
- ndbout << "Account = " << (int)BindCol_Account << endl;
- ndbout << "Phone = " << (int)BindCol_Phone << endl;
- ndbout << "Price = " << (int)BindCol_Price << endl;
- ndbout << "Weight = " << (int)BindCol_Weight << endl;
- ndbout << "Tax = " << (int)BindCol_Tax << endl;
-}
-
-// *********************************
-// ** Disconnect and Free Handles **
-// *********************************
-SQLDisconnect(BindCol_hdbc);
-SQLFreeHandle(SQL_HANDLE_STMT, BindCol_hstmt);
-SQLFreeHandle(SQL_HANDLE_DBC, BindCol_hdbc);
-SQLFreeHandle(SQL_HANDLE_ENV, BindCol_henv);
-
-return NDBT_OK;
-
-}
-
-void BindCol_DisplayError(SQLSMALLINT BindCol_HandleType,
- SQLHSTMT BindCol_InputHandle)
-{
- SQLSMALLINT BindCol_i = 1;
- SQLRETURN BindCol__SQLSTATEs;
- SQLCHAR BindCol_Sqlstate[5];
- SQLCHAR BindCol_Msg[BindCol_SQL_MAXIMUM_MESSAGE_LENGTH];
- SQLSMALLINT BindCol_MsgLen;
- SQLINTEGER NativeError;
-
- ndbout << "-------------------------------------------------" << endl;
- ndbout << "Error diagnostics:" << endl;
-
- while ((BindCol__SQLSTATEs = SQLGetDiagRec(BindCol_HandleType,
- BindCol_InputHandle,
- BindCol_i,
- BindCol_Sqlstate,
- &NativeError,
- BindCol_Msg,
- sizeof(BindCol_Msg),
- &BindCol_MsgLen)
- ) != SQL_NO_DATA)
- {
-
- ndbout << "the HandleType is:" << BindCol_HandleType << endl;
- ndbout << "the InputHandle is :" << (long)BindCol_InputHandle << endl;
- ndbout << "the BindCol_Msg is: " << (char *) BindCol_Msg << endl;
- ndbout << "the output state is:" << (char *)BindCol_Sqlstate << endl;
-
- BindCol_i ++;
- break;
- }
- ndbout << "-------------------------------------------------" << endl;
-}
-
diff --git a/storage/ndb/test/odbc/client/SQLBindParameterTest.cpp b/storage/ndb/test/odbc/client/SQLBindParameterTest.cpp
deleted file mode 100644
index 8cda7accc97..00000000000
--- a/storage/ndb/test/odbc/client/SQLBindParameterTest.cpp
+++ /dev/null
@@ -1,219 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NdbOut.hpp>
-#include <sqlcli.h>
-#include <stdio.h>
-
-using namespace std;
-
-#define NAME_LEN 50
-#define PHONE_LEN 10
-#define SALES_PERSON_LEN 10
-#define STATUS_LEN 6
-
-SQLHSTMT hstmt;
-
-SQLSMALLINT sOrderID;
-SQLSMALLINT sCustID;
-DATE_STRUCT dsOpenDate;
-SQLCHAR szSalesPerson[SALES_PERSON_LEN];
-
-SQLCHAR szStatus[STATUS_LEN],Sqlstate[5], Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
-SQLINTEGER cbOrderID = 0, cbCustID = 0, cbOpenDate = 0, cbSalesPerson = SQL_NTS, cbStatus = SQL_NTS, NativeError;
-SQLRETURN retcode, SQLSTATEs;
-
-SQLSMALLINT i, MsgLen;
-
-void DisplayError(SQLSMALLINT HandleType, SQLHSTMT InputHandle);
-
-int SQLBindParameterTest ()
-{
-
- /* hstmt */
- //** Execute a statement to retrieve rows from the Customers table.
- //** We can create the table and inside rows in
- //** NDB by another program TestDirectSQL.
- //** In this test program(SQLBindParameterTest),we only have three rows in
- //** table ORDERS
-
- //************************
- //** Define a statement **
- //************************
- strcpy( (char *) SQLStmt,
- "INSERT INTO Customers (CUSTID, Name, Address, Phone) VALUES (2, 'paul, 'Alzato', '468719989');
-
-/* Prepare the SQL statement with parameter markers. */
-retcode = SQLPrepare(hstmt, SQLStmt, SQL_NTS);
-
-/* Specify data types and buffers for OrderID, CustID, OpenDate, SalesPerson, */
-/* Status parameter data. */
-
-if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
-
- /* ParameterNumber is less than 1 */
-retcode = SQLBindParameter(hstmt,
- 0,
- SQL_PARAM_INPUT,
- SQL_C_SSHORT,
- SQL_INTEGER,
- 0,
- 0,
- &sOrderID,
- 0,
- &cbOrderID);
-if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- DisplayError(SQL_HANDLE_STMT, hstmt);
-
- /* InputOutputMode is not one of the code values in Table 11 */
-retcode = SQLBindParameter(hstmt,
- 1,
- 3,
- SQL_C_SSHORT,
- SQL_INTEGER,
- 0,
- 0,
- &sOrderID,
- 0,
- &cbOrderID);
-if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- DisplayError(SQL_HANDLE_STMT, hstmt);
-
- /* ParameterType is not one of the code values in Table 37 */
-retcode = SQLBindParameter(hstmt,
- 1,
- 3,
- SQL_C_SSHORT,
- 114,
- 0,
- 0,
- &sOrderID,
- 0,
- &cbOrderID);
-if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- DisplayError(SQL_HANDLE_STMT, hstmt);
-
-SQLBindParameter(hstmt,
- 1,
- SQL_PARAM_INPUT,
- SQL_C_SSHORT,
- SQL_INTEGER,
- 0,
- 0,
- &sOrderID,
- 0,
- &cbOrderID);
-if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- DisplayError(SQL_HANDLE_STMT, hstmt);
-
-
-SQLBindParameter(hstmt,
- 2,
- SQL_PARAM_INPUT,
- SQL_C_SSHORT,
- SQL_INTEGER,
- 0,
- 0,
- &sCustID,
- 0,
- &cbCustID);
-
-SQLBindParameter(hstmt,
- 3,
- SQL_PARAM_INPUT,
- SQL_C_TYPE_DATE,
- SQL_TYPE_DATE,
- 0,
- 0,
- &dsOpenDate,
- 0,
- &cbOpenDate);
-
-SQLBindParameter(hstmt,
- 4,
- SQL_PARAM_INPUT,
- SQL_C_CHAR,
- SQL_CHAR,
- SALES_PERSON_LEN,
- 0,
- szSalesPerson,
- 0,
- &cbSalesPerson);
-
-SQLBindParameter(hstmt,
- 5,
- SQL_PARAM_INPUT,
- SQL_C_CHAR,
- SQL_CHAR,
- STATUS_LEN,
- 0,
- szStatus,
- 0,
- &cbStatus);
-
-/*
-
-/* Specify first row of parameter data. */
-sOrderID = 1001;
-sCustID = 298;
-dsOpenDate.year = 1996;
-dsOpenDate.month = 3;
-dsOpenDate.day = 8;
-strcpy(szSalesPerson, "Johnson");
-strcpy(szStatus, "Closed");
-
-/* Execute statement with first row. */
-retcode = SQLExecute(hstmt);
-
-/* Specify second row of parameter data. */
-sOrderID = 1002;
-sCustID = 501;
-dsOpenDate.year = 1996;
-dsOpenDate.month = 3;
-dsOpenDate.day = 9;
-strcpy(szSalesPerson, "Bailey");
-strcpy(szStatus, "Open");
-
-/* Execute statement with second row. */
-retcode = SQLExecute(hstmt);
-
-*/
-
-}
-
- return 0;
-
- }
-
-
-void DisplayError(SQLSMALLINT HandleType, SQLHSTMT InputHandle)
-{
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
-
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLCancelTest.cpp b/storage/ndb/test/odbc/client/SQLCancelTest.cpp
deleted file mode 100644
index a0f252e34d1..00000000000
--- a/storage/ndb/test/odbc/client/SQLCancelTest.cpp
+++ /dev/null
@@ -1,254 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
- /**
- * @file SQLCancelTest.cpp
- */
-
-#include <common.hpp>
-#define Cancel_MESSAGE_LENGTH 200
-
-using namespace std;
-
-SQLHDBC CC_hdbc;
-SQLHSTMT CC_hstmt;
-SQLHENV CC_henv;
-SQLHDESC CC_hdesc;
-
-void Cancel_DisplayError(SQLSMALLINT Cancel_HandleType,
- SQLHSTMT Cancel_InputHandle);
-/**
- * Test to terminate SQL statement precessing
- *
- * Tests:
- * -# normal case test with correct hstmt handle
- * -# SQL_STILL_EXECUTING case test with hstmt handle
- * -# abnormal case test with incorrect hdbc, henv and hdesc handle
- * @return Zero, if test succeeded
- */
-
-int SQLCancelTest()
-{
-
- SQLRETURN retcode;
- SQLCHAR SQLStmt [120];
-
- ndbout << endl << "Start SQLCancel Testing" << endl;
-
- //************************************
- //** Allocate An Environment Handle **
- //************************************
- retcode = SQLAllocHandle(SQL_HANDLE_ENV,
- SQL_NULL_HANDLE,
- &CC_henv);
-
- if(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated an environment Handle!" << endl;
-
- //*********************************************
- //** Set the ODBC application Version to 3.x **
- //*********************************************
- retcode = SQLSetEnvAttr(CC_henv,
- SQL_ATTR_ODBC_VERSION,
- (SQLPOINTER) SQL_OV_ODBC3,
- SQL_IS_UINTEGER);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Set the ODBC application Version to 3.x!" << endl;
-
- //**********************************
- //** Allocate A Connection Handle **
- //**********************************
- retcode = SQLAllocHandle(SQL_HANDLE_DBC, CC_henv, &CC_hdbc);
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a connection Handle!" << endl;
-
- // *******************
- // ** Connect to DB **
- // *******************
- retcode = SQLConnect(CC_hdbc,
- (SQLCHAR *) connectString(),
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Connected to DB : OK!" << endl;
- else
- ndbout << "Failure to Connect DB!" << endl;
-
- //*******************************
- //** Allocate statement handle **
- //*******************************
-
- retcode = SQLAllocHandle(SQL_HANDLE_STMT, CC_hdbc, &CC_hstmt);
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a statement handle!" << endl;
-
- //************************
- //** Define a statement **
- //************************
-
- strcpy((char *) SQLStmt,
- "select * FROM Customers");
-
- //*************************
- //** Prepare a statement **
- //*************************
-
- retcode = SQLPrepare(CC_hstmt,
- SQLStmt,
- SQL_NTS);
-
- //***********************
- //** Execute statement **
- //***********************
-
- retcode = SQLExecute(CC_hstmt);
-
- //************************************************
- //** Test 1 **
- //** Input correct hstmt handle for normal test **
- //************************************************
-
- retcode = SQLCancel(CC_hstmt);
-
- if (retcode == SQL_INVALID_HANDLE)
- {
- ndbout << "Test 1" << endl;
- ndbout << "Handle Type is SQL_HANDLE_STMT, but SQL_INVALID_HANDLE"
- << "still appeared. Please check program" << endl;
- }
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "Test 1" << endl;
- Cancel_DisplayError(SQL_HANDLE_STMT, CC_hstmt);
- }
- //************************************************
- //** Test 2 **
- //** SQL_STILL_EXECUTING is not defined **
- //************************************************
-
- if (retcode == SQL_STILL_EXECUTING)
- {
- ndbout << "Test 2" << endl;
- ndbout << "The function is still processing." << endl;
- }
-
- if (retcode == SQL_ERROR)
- {
- ndbout << "Test 2" << endl;
- ndbout << "The Asynchronous processing was successfully canceled!"
- << endl;
- }
- //*********************************
- //** Test 3 **
- //** Input incorrect henv handle **
- //*********************************
-
- retcode = SQLCancel(CC_henv);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS)
- {
- ndbout << "Test 3" << endl;
- ndbout << "Handle Type is SQL_HANDLE_ENV, but SQL_SUCCESS_WITH_INFO"
- << " still appeared. Please check program" << endl;
- Cancel_DisplayError(SQL_HANDLE_ENV, CC_henv);
- }
-
- //*********************************
- //** Test 4 **
- //** Input incorrect hdbc handle **
- //*********************************
-
- retcode = SQLCancel(CC_hdbc);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS)
- {
- ndbout << "Test 4" << endl;
- ndbout << "Handle Type is SQL_HANDLE_DBC, but SQL_SUCCESS_WITH_INFO"
- << "still appeared. Please check programm" << endl;
- Cancel_DisplayError(SQL_HANDLE_DBC, CC_hdbc);
- }
-
- //**********************************
- //** Test 5 **
- //** Input incorrect handle hdesc **
- //**********************************
-
- retcode = SQLCancel(CC_hdesc);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS)
- {
- ndbout << endl
- << "Handle Type is SQL_HANDLE_DESC, but SQL_SUCCESS_WITH_INFO"
- << "still appeared. Please check program" << endl;
- ndbout << "Test 5" << endl;
- Cancel_DisplayError(SQL_HANDLE_DESC, CC_hdesc);
- }
-
- // *********************************
- // ** Disconnect and Free Handles **
- // *********************************
- SQLDisconnect(CC_hdbc);
- SQLFreeHandle(SQL_HANDLE_STMT, CC_hstmt);
- SQLFreeHandle(SQL_HANDLE_DBC, CC_hdbc);
- SQLFreeHandle(SQL_HANDLE_ENV, CC_henv);
-
- return NDBT_OK;
-
- }
-
-void Cancel_DisplayError(SQLSMALLINT Cancel_HandleType,
- SQLHSTMT Cancel_InputHandle)
-{
- SQLCHAR Sqlstate[5];
- SQLRETURN SQLSTATEs;
- SQLINTEGER NativeError;
- SQLSMALLINT i, MsgLen;
- SQLCHAR Msg[Cancel_MESSAGE_LENGTH];
- i = 1;
-
- ndbout << "-------------------------------------------------" << endl;
- ndbout << "Error diagnostics:" << endl;
-
- while ((SQLSTATEs = SQLGetDiagRec(Cancel_HandleType,
- Cancel_InputHandle,
- i,
- Sqlstate,
- &NativeError,
- Msg,
- sizeof(Msg),
- &MsgLen))
- != SQL_NO_DATA)
- {
-
- ndbout << "the HandleType is:" << Cancel_HandleType << endl;
- ndbout << "the InputHandle is :" << (long)Cancel_InputHandle << endl;
- ndbout << "the Msg is: " << (char *) Msg << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- break;
- }
- ndbout << "-------------------------------------------------" << endl;
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLCloseCursorTest.cpp b/storage/ndb/test/odbc/client/SQLCloseCursorTest.cpp
deleted file mode 100644
index 320703cdcb8..00000000000
--- a/storage/ndb/test/odbc/client/SQLCloseCursorTest.cpp
+++ /dev/null
@@ -1,92 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <common.h>
-#define SQL_MAXIMUM_MESSAGE_LENGTH 200
-
-using namespace std;
-
-SQLHDBC hdbc;
-SQLHSTMT hstmt;
-SQLHENV henv;
-SQLHDESC hdesc;
-SQLRETURN retcode, SQLSTATEs;
-
-SQLCHAR Sqlstate[5];
-
-SQLINTEGER NativeError;
-SQLSMALLINT i, MsgLen;
-SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
-
-void CloseCursor_DisplayError(SQLSMALLINT HandleType, SQLHSTMT InputHandle);
-
-int SQLCloseCursorTest()
-{
- /* "If there is no open cursor associated with S, then an exception is raised: invalid cursor state" How to test this case */
-
- /* hstmt */
- retcode = SQLCloseCursor(hstmt);
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_STMT, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- CloseCursor_DisplayError(SQL_HANDLE_STMT, hstmt);
-
- /* henv */
- retcode = SQLCloseCursor(henv);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS)
- ndbout << "Handle Type is SQL_HANDLE_ENV, but string SQL_SUCCESS_WITH_INFO still appeared. Please check programm" << endl;
- // CloseCursor_DisplayError(SQL_HANDLE_ENV, henv);
-
- /* hdbc */
- retcode = SQLCloseCursor(hdbc);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS)
- ndbout << "Handle Type is SQL_HANDLE_DBC, but string SQL_SUCCESS_WITH_INFO still appeared. Please check programm" << endl;
- // CloseCursor_DisplayError(SQL_HANDLE_DBC, hdbc);
-
- /* hdesc */
- retcode = SQLCloseCursor(hdesc);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS)
- ndbout << "Handle Type is SQL_HANDLE_DESC, but string SQL_SUCCESS_WITH_INFO still appeared. Please check programm" << endl;
- // CloseCursor_DisplayError(SQL_HANDLE_DESC, hdesc);
-
- return 0;
-
- }
-
-
-void CloseCursor_DisplayError(SQLSMALLINT HandleType, SQLHSTMT InputHandle)
-{
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
-
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLColAttributeTest.cpp b/storage/ndb/test/odbc/client/SQLColAttributeTest.cpp
deleted file mode 100644
index 8e8fcd1526d..00000000000
--- a/storage/ndb/test/odbc/client/SQLColAttributeTest.cpp
+++ /dev/null
@@ -1,328 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-/**
- * @file SQLColAttributeTest.cpp
- */
-
-#include <common.hpp>
-using namespace std;
-
-#define MAXIMUM_MESSAGE_LENGTH_Test 200
-#define BufferLengthTest 156
-
-SQLHSTMT ColAtt_hstmt;
-SQLHSTMT ColAtt_hdbc;
-SQLHENV ColAtt_henv;
-SQLHDESC ColAtt_hdesc;
-
-SQLCHAR CharacterAttributePtr;
-SQLINTEGER NumericAttributePtr;
-SQLSMALLINT StringLengthPtr;
-
-SQLRETURN ColAtt_ret;
-
-void ColAtt_DisplayError(SQLSMALLINT ColAtt_HandleType,
- SQLHSTMT ColAtt_InputHandle);
-
-/**
- * Test returning descriptor information
- *
- * Tests:
- * -# Call SQLColAttribute, without preceeding SQLPrepare
- * -# ???
- *
- * @return Zero, if test succeeded
- */
-int SQLColAttributeTest()
-{
- ndbout << endl << "Start SQLColAttribute Testing" << endl;
-
- SQLCHAR SQLStmt [120];
-
- /********************************************************************
- ** Test 1: **
- ** **
- ** Checks to execute SQLColAttribute, when there is no **
- ** prepared or executed statement associated with StatementHandle **
- ** **
- ** Intended result: SQL_ERROR ??? **
- ********************************************************************/
- ColAtt_ret = SQLColAttribute(ColAtt_hstmt,
- 1,
- SQL_DESC_AUTO_UNIQUE_VALUE,
- &CharacterAttributePtr,
- BufferLengthTest,
- &StringLengthPtr,
- &NumericAttributePtr);
-
- if (ColAtt_ret == SQL_ERROR)
- {
- ndbout << "ColAtt_ret = " << ColAtt_ret << endl;
- ndbout << endl << "There is no prepared or executed" << endl
- << " statement associated with StatementHandle" << endl;
- ColAtt_DisplayError(SQL_HANDLE_STMT, ColAtt_hstmt);
- }
- else if (ColAtt_ret == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "ColAtt_ret = " << ColAtt_ret << endl;
- ndbout << endl << "There is no prepared or executed" << endl
- << " statement associated with StatementHandle" << endl;
- ColAtt_DisplayError(SQL_HANDLE_STMT, ColAtt_hstmt);
- }
- else if (ColAtt_ret == SQL_SUCCESS)
- {
- ndbout << "ColAtt_ret = " << ColAtt_ret << endl;
- ndbout << endl << "There is no prepared or executed" << endl
- << " statement associated with StatementHandle" << endl;
- ColAtt_DisplayError(SQL_HANDLE_STMT, ColAtt_hstmt);
- }
- else if (ColAtt_ret == -2)
- {
- ndbout << "ColAtt_ret = " << ColAtt_ret << endl;
- ndbout << endl << "There is no prepared or executed" << endl
- << " statement associated with StatementHandle" << endl;
- ColAtt_DisplayError(SQL_HANDLE_STMT, ColAtt_hstmt);
- }
- else
- {
- ndbout << "ColAtt_ret = " << ColAtt_ret << endl;
- ndbout << endl << "There is no prepared or executed" << endl
- << " statement associated with StatementHandle" << endl;
- ColAtt_DisplayError(SQL_HANDLE_STMT, ColAtt_hstmt);
- }
-
- //*******************************************************************
- //** Test 2: **
- //** **
- //** hstmt **
- //** Execute a statement to retrieve rows from the Customers table **
- //** We can create the table and insert rows into Mysql **
- //** **
- //** Intended result: ??? **
- //*******************************************************************
-
- //************************************
- //** Allocate An Environment Handle **
- //************************************
- ColAtt_ret = SQLAllocHandle(SQL_HANDLE_ENV,
- SQL_NULL_HANDLE,
- &ColAtt_henv);
-
- if (ColAtt_ret == SQL_SUCCESS || ColAtt_ret == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated an environment Handle!" << endl;
-
- //*********************************************
- //** Set the ODBC application Version to 2.x **
- //*********************************************
- ColAtt_ret = SQLSetEnvAttr(ColAtt_henv,
- SQL_ATTR_ODBC_VERSION,
- (SQLPOINTER) SQL_OV_ODBC2,
- SQL_IS_UINTEGER);
-
- if (ColAtt_ret == SQL_SUCCESS || ColAtt_ret == SQL_SUCCESS_WITH_INFO)
- ndbout << "Set the ODBC application Version to 2.x!" << endl;
-
- //**********************************
- //** Allocate A Connection Handle **
- //**********************************
-
- ColAtt_ret = SQLAllocHandle(SQL_HANDLE_DBC,
- ColAtt_henv,
- &ColAtt_hdbc);
-
- if (ColAtt_ret == SQL_SUCCESS || ColAtt_ret == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a connection Handle!" << endl;
-
- // *******************
- // ** Connect to DB **
- // *******************
- ColAtt_ret = SQLConnect(ColAtt_hdbc,
- (SQLCHAR *) connectString(),
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS);
-
- if (ColAtt_ret == SQL_SUCCESS || ColAtt_ret == SQL_SUCCESS_WITH_INFO)
- ndbout << "Connected to DB : OK!" << endl;
- else
- {
- ndbout << "Failure to Connect DB!" << endl;
- return NDBT_FAILED;
- }
- //*******************************
- //** Allocate statement handle **
- //*******************************
-
- ColAtt_ret = SQLAllocHandle(SQL_HANDLE_STMT,
- ColAtt_hdbc,
- &ColAtt_hstmt);
- if(ColAtt_ret == SQL_SUCCESS || ColAtt_ret == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a statement handle!" << endl;
-
- //************************
- //** Define a statement **
- //************************
-
- /*
- strcpy((char *) SQLStmt,
- "DELETE FROM Customers WHERE CustID = 6");
- */
-
- strcpy((char *) SQLStmt,
- "INSERT INTO Customers (CustID, Name, Address, Phone) VALUES (6, 'Jan', 'LM vag 8', '969696')");
-
- /*
- strcpy((char *) SQLStmt,
- "INSERT INTO Customers (CustID, Name, Address, Phone) VALUES (?, ?, ?, ?)");
- */
-
- //********************************
- //** Prepare SQL statement **
- //********************************
- ColAtt_ret = SQLPrepare(ColAtt_hstmt,
- SQLStmt,
- SQL_NTS);
-
- if (ColAtt_ret == SQL_SUCCESS || ColAtt_ret == SQL_SUCCESS_WITH_INFO)
- {
- //**************************************************************
- //** FieldIdentifer is not one of the code valuess in Table 20,
- //** "Codes used for descriptor fields"
- //**************************************************************
- ColAtt_ret = SQLColAttribute(ColAtt_hstmt,
- 2,
- 9999,
- &CharacterAttributePtr,
- BufferLengthTest,
- &StringLengthPtr,
- &NumericAttributePtr);
-
- if (ColAtt_ret == SQL_ERROR || ColAtt_ret == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << endl << "FieldIdentifer is not one of the" << endl;
- ndbout << "code valuess in Table 20, Codes used for" << endl;
- ndbout << "descriptor fields" <<endl;
- ColAtt_DisplayError(SQL_HANDLE_STMT, ColAtt_hstmt);
- }
-
- //****************************************************************
- //** Let TYPE is 'ITEM' in Table 20, ColumnNumber is less than one
- //****************************************************************
- ColAtt_ret = SQLColAttribute(ColAtt_hstmt,
- -1,
- SQL_DESC_BASE_COLUMN_NAME,
- &CharacterAttributePtr,
- BufferLengthTest,
- &StringLengthPtr,
- &NumericAttributePtr);
-
- if (ColAtt_ret == SQL_ERROR || ColAtt_ret == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "Let TYPE is 'ITEM' in Table 20,ColumnNumber"
- << "is less than one" << endl;
- ColAtt_DisplayError(SQL_HANDLE_STMT, ColAtt_hstmt);
- }
-
- //*********************************************************
- //** Let TYPE is 'ITEM' in Table 20, FieldIdentifer is zero
- //*********************************************************
- ColAtt_ret = SQLColAttribute(ColAtt_hstmt,
- 1018,
- 0,
- &CharacterAttributePtr,
- BufferLengthTest,
- &StringLengthPtr,
- &NumericAttributePtr);
-
- if (ColAtt_ret == SQL_ERROR || ColAtt_ret == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "Let TYPE is 'ITEM' in Table 20, FieldIdentifer"
- << " is zero" <<endl;
- ColAtt_DisplayError(SQL_HANDLE_STMT, ColAtt_hstmt);
- }
-
- //**********************************************************
- //** Let TYPE is 'ITEM' in Table 20, ColumnNumber is greater
- //** than TOP_LEVEL_COUNT(1044)
- //*********************************************************
- ColAtt_ret = SQLColAttribute(ColAtt_hstmt,
- 1045,
- SQL_DESC_BASE_COLUMN_NAME,
- &CharacterAttributePtr,
- BufferLengthTest,
- &StringLengthPtr,
- &NumericAttributePtr);
-
- if (ColAtt_ret == SQL_ERROR || ColAtt_ret == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "Let TYPE is 'ITEM' in Table 20, ColumnNumber" << endl
- << "is greater than TOP_LEVEL_COUNT(1044)" << endl;
- ColAtt_DisplayError(SQL_HANDLE_STMT, ColAtt_hstmt);
- }
-
- }
-
- // *********************************
- // ** Disconnect and Free Handles **
- // *********************************
- SQLDisconnect(ColAtt_hdbc);
- SQLFreeHandle(SQL_HANDLE_STMT, ColAtt_hstmt);
- SQLFreeHandle(SQL_HANDLE_DBC, ColAtt_hdbc);
- SQLFreeHandle(SQL_HANDLE_ENV, ColAtt_henv);
-
- return NDBT_OK;
-}
-
-void ColAtt_DisplayError(SQLSMALLINT ColAtt_HandleType,
- SQLHSTMT ColAtt_InputHandle)
-{
- SQLSMALLINT ColAtt_i = 1;
- SQLRETURN ColAtt_SQLSTATEs;
- SQLCHAR ColAtt_Sqlstate[5];
- SQLCHAR ColAtt_Msg[MAXIMUM_MESSAGE_LENGTH_Test];
- SQLSMALLINT ColAtt_MsgLen;
- SQLINTEGER ColAtt_NativeError;
-
- ndbout << "-------------------------------------------------" << endl;
- ndbout << "Error diagnostics:" << endl;
-
- while ((ColAtt_SQLSTATEs = SQLGetDiagRec(ColAtt_HandleType,
- ColAtt_InputHandle,
- ColAtt_i,
- ColAtt_Sqlstate,
- &ColAtt_NativeError,
- ColAtt_Msg,
- sizeof(ColAtt_Msg),
- &ColAtt_MsgLen))
- != SQL_NO_DATA)
- {
-
- ndbout << "the HandleType is:" << ColAtt_HandleType << endl;
- ndbout << "the InputHandle is :" << (long)ColAtt_InputHandle << endl;
- ndbout << "the ColAtt_Msg is: " << (char *) ColAtt_Msg << endl;
- ndbout << "the output state is:" << (char *)ColAtt_Sqlstate << endl;
-
- ColAtt_i ++;
- break;
- }
- ndbout << "-------------------------------------------------" << endl;
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLColAttributeTest1.cpp b/storage/ndb/test/odbc/client/SQLColAttributeTest1.cpp
deleted file mode 100644
index a182427c3d7..00000000000
--- a/storage/ndb/test/odbc/client/SQLColAttributeTest1.cpp
+++ /dev/null
@@ -1,143 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-/**
- * @file SQLColAttributeTest1.cpp
- */
-
-#include <common.hpp>
-using namespace std;
-
-#define MAXIMUM_MESSAGE_LENGTH_Test1 200
-#define BufferLenghTest1 156
-
-SQLHSTMT ColAtt_hstmtTest1;
-SQLHSTMT ColAtt_hdbcTest1;
-SQLHENV ColAtt_henvTest1;
-SQLHDESC ColAtt_hdescTest1;
-
-SQLCHAR CharacterAttributePtrTest1;
-SQLINTEGER NumericAttributePtrTest1;
-SQLSMALLINT StringLengthPtrTest1;
-
-SQLRETURN ColAtt_retTest1;
-
-void ColAtt_DisplayErrorTest1(SQLSMALLINT ColAtt_HandleType,
- SQLHSTMT ColAtt_InputHandle);
-
-/**
- * Test returning descriptor information
- *
- * Tests:
- * -# Execute SQLColAttribute without prepared or executed statement
- *
- * @return Zero, if test succeeded
- */
-int SQLColAttributeTest1()
-{
- ndbout << endl << "Start SQLColAttribute Testing1" << endl;
- /********************************************************************
- ** Test : **
- ** **
- ** Checks to execute SQLColAttribute, when there is no **
- ** prepared or executed statement associated with StatementHandle **
- ** **
- ** Intended result:CLI-specific condition-function sequence error **
- ********************************************************************/
- ColAtt_retTest1 = SQLColAttribute(ColAtt_hstmtTest1,
- 1,
- SQL_DESC_AUTO_UNIQUE_VALUE,
- &CharacterAttributePtrTest1,
- BufferLenghTest1,
- &StringLengthPtrTest1,
- &NumericAttributePtrTest1);
-
- if (ColAtt_retTest1 == SQL_ERROR)
- {
- ndbout << "ColAtt_ret = " << ColAtt_retTest1 << endl;
- ndbout << endl << "There is no prepared or executed" << endl
- << " statement associated with StatementHandle" << endl;
- ColAtt_DisplayErrorTest1(SQL_HANDLE_STMT, ColAtt_hstmtTest1);
- }
- else if (ColAtt_retTest1 == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "ColAtt_ret = " << ColAtt_retTest1 << endl;
- ndbout << endl << "There is no prepared or executed" << endl
- << " statement associated with StatementHandle" << endl;
- ColAtt_DisplayErrorTest1(SQL_HANDLE_STMT, ColAtt_hstmtTest1);
- }
- else if (ColAtt_retTest1 == SQL_SUCCESS)
- {
- ndbout << "ColAtt_ret = " << ColAtt_retTest1 << endl;
- ndbout << endl << "There is no prepared or executed" << endl
- << " statement associated with StatementHandle" << endl;
- ColAtt_DisplayErrorTest1(SQL_HANDLE_STMT, ColAtt_hstmtTest1);
- }
- else if (ColAtt_retTest1 == -2)
- {
- ndbout << "ColAtt_ret = " << ColAtt_retTest1 << endl;
- ndbout << endl << "There is no prepared or executed" << endl
- << " statement associated with StatementHandle" << endl;
- ColAtt_DisplayErrorTest1(SQL_HANDLE_STMT, ColAtt_hstmtTest1);
- }
- else
- {
- ndbout << "ColAtt_ret = " << ColAtt_retTest1 << endl;
- ndbout << endl << "There is no prepared or executed" << endl
- << " statement associated with StatementHandle" << endl;
- ColAtt_DisplayErrorTest1(SQL_HANDLE_STMT, ColAtt_hstmtTest1);
- }
-
- return NDBT_OK;
-}
-
-void ColAtt_DisplayErrorTest1(SQLSMALLINT ColAtt_HandleType,
- SQLHSTMT ColAtt_InputHandle)
-{
- SQLSMALLINT ColAtt_i = 1;
- SQLRETURN ColAtt_SQLSTATEs;
- SQLCHAR ColAtt_Sqlstate[5];
- SQLCHAR ColAtt_Msg[MAXIMUM_MESSAGE_LENGTH_Test1];
- SQLSMALLINT ColAtt_MsgLen;
- SQLINTEGER ColAtt_NativeError;
-
- ndbout << "-------------------------------------------------" << endl;
- ndbout << "Error diagnostics:" << endl;
-
- while ((ColAtt_SQLSTATEs = SQLGetDiagRec(ColAtt_HandleType,
- ColAtt_InputHandle,
- ColAtt_i,
- ColAtt_Sqlstate,
- &ColAtt_NativeError,
- ColAtt_Msg,
- sizeof(ColAtt_Msg),
- &ColAtt_MsgLen))
- != SQL_NO_DATA)
- {
-
- ndbout << "the HandleType is:" << ColAtt_HandleType << endl;
- ndbout << "the InputHandle is :" << (long)ColAtt_InputHandle << endl;
- ndbout << "the ColAtt_Msg is: " << (char *) ColAtt_Msg << endl;
- ndbout << "the output state is:" << (char *)ColAtt_Sqlstate << endl;
-
- ColAtt_i ++;
- break;
- }
- ndbout << "-------------------------------------------------" << endl;
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLColAttributeTest2.cpp b/storage/ndb/test/odbc/client/SQLColAttributeTest2.cpp
deleted file mode 100644
index 706e1917cf0..00000000000
--- a/storage/ndb/test/odbc/client/SQLColAttributeTest2.cpp
+++ /dev/null
@@ -1,277 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
- /**
- * @file SQLColAttributeTest2.cpp
- */
-
-#include <common.hpp>
-using namespace std;
-
-#define MAXIMUM_MESSAGE_LENGTH_Test2 200
-#define BufferLengthTest2 156
-
-SQLHSTMT ColAtt_hstmtTest2;
-SQLHSTMT ColAtt_hdbcTest2;
-SQLHENV ColAtt_henvTest2;
-SQLHDESC ColAtt_hdescTest2;
-
-SQLCHAR CharacterAttributePtrTest2;
-SQLINTEGER NumericAttributePtrTest2;
-SQLSMALLINT StringLengthPtrTest2;
-
-SQLRETURN ColAtt_retTest2;
-
-void ColAtt_DisplayErrorTest2(SQLSMALLINT ColAttTest2_HandleType,
- SQLHSTMT ColAttTest2_InputHandle);
-
-/**
- * Test returning descriptor information
- *
- * Test:
- * -# Call SQLColAttribute without preceeding SQLExecute
- * -# Let TYPE is 'ITEM' in Table 20, FieldIdentifer is zero
- * -# Let TYPE is 'ITEM' in Table 20, ColumnNumber is less than one
- * -# FieldIdentifer is not one of the code valuess in Table 20
- * -# Let TYPE is 'ITEM' in Table 20, ColumnNumber is greater than 1044
- *
- * @return Zero, if test succeeded
- */
-int SQLColAttributeTest2()
-{
- ndbout << endl << "Start SQLColAttribute Testing2" << endl;
-
- SQLCHAR SQLStmt [120];
-
- //*******************************************************************
- //** Test **
- //** **
- //** hstmt **
- //** Prepare a statement without executing the statement **
- //** **
- //** Intended result: table Customer should not have new row **
- //*******************************************************************
-
- //************************************
- //** Allocate An Environment Handle **
- //************************************
- ColAtt_retTest2 = SQLAllocHandle(SQL_HANDLE_ENV,
- SQL_NULL_HANDLE,
- &ColAtt_henvTest2);
-
- if (ColAtt_retTest2 == SQL_SUCCESS || ColAtt_retTest2 == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated an environment Handle!" << endl;
-
- //*********************************************
- //** Set the ODBC application Version to 3.x **
- //*********************************************
- ColAtt_retTest2 = SQLSetEnvAttr(ColAtt_henvTest2,
- SQL_ATTR_ODBC_VERSION,
- (SQLPOINTER) SQL_OV_ODBC3,
- SQL_IS_UINTEGER);
-
- if (ColAtt_retTest2 == SQL_SUCCESS || ColAtt_retTest2 == SQL_SUCCESS_WITH_INFO)
- ndbout << "Set the ODBC application Version to 2.x!" << endl;
-
- //**********************************
- //** Allocate A Connection Handle **
- //**********************************
-
- ColAtt_retTest2 = SQLAllocHandle(SQL_HANDLE_DBC,
- ColAtt_henvTest2,
- &ColAtt_hdbcTest2);
-
- if (ColAtt_retTest2 == SQL_SUCCESS || ColAtt_retTest2 == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a connection Handle!" << endl;
-
- // *******************
- // ** Connect to DB **
- // *******************
- ColAtt_retTest2 = SQLConnect(ColAtt_hdbcTest2,
- (SQLCHAR *) connectString(),
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS);
-
- if (ColAtt_retTest2 == SQL_SUCCESS || ColAtt_retTest2 == SQL_SUCCESS_WITH_INFO)
- ndbout << "Connected to DB : OK!" << endl;
- else
- {
- ndbout << "Failure to Connect DB!" << endl;
- return NDBT_FAILED;
- }
-
- //*******************************
- //** Allocate statement handle **
- //*******************************
-
- ColAtt_retTest2 = SQLAllocHandle(SQL_HANDLE_STMT,
- ColAtt_hdbcTest2,
- &ColAtt_hstmtTest2);
- if(ColAtt_retTest2 == SQL_SUCCESS || ColAtt_retTest2 == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a statement handle!" << endl;
-
- //************************
- //** Define a statement **
- //************************
-
- /*
- strcpy((char *) SQLStmt,
- "DELETE FROM Customers WHERE CustID = 6");
- */
-
- strcpy((char *) SQLStmt,
- "INSERT INTO Customers (CustID, Name, Address, Phone) VALUES (6, 'Jan', 'LM vag 8', '969696')");
-
- /*
- strcpy((char *) SQLStmt,
- "INSERT INTO Customers (CustID, Name, Address, Phone) VALUES (?, ?, ?, ?)");
- */
-
- //********************************
- //** Prepare SQL statement **
- //********************************
- ColAtt_retTest2 = SQLPrepare(ColAtt_hstmtTest2,
- SQLStmt,
- SQL_NTS);
-
- if (ColAtt_retTest2 == SQL_SUCCESS || ColAtt_retTest2 == SQL_SUCCESS_WITH_INFO)
- {
- //**************************************************************
- //** FieldIdentifer is not one of the code valuess in Table 20,
- //** "Codes used for descriptor fields"
- //**************************************************************
- ColAtt_retTest2 = SQLColAttribute(ColAtt_hstmtTest2,
- 2,
- 9999,
- &CharacterAttributePtrTest2,
- BufferLengthTest2,
- &StringLengthPtrTest2,
- &NumericAttributePtrTest2);
-
- if (ColAtt_retTest2 == SQL_ERROR || ColAtt_retTest2 == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << endl << "FieldIdentifer is not one of the" << endl;
- ndbout << "code valuess in Table 20, Codes used for" << endl;
- ndbout << "descriptor fields" <<endl;
- ColAtt_DisplayErrorTest2(SQL_HANDLE_STMT, ColAtt_hstmtTest2);
- }
-
- //****************************************************************
- //** Let TYPE is 'ITEM' in Table 20, ColumnNumber is less than one
- //****************************************************************
- ColAtt_retTest2 = SQLColAttribute(ColAtt_hstmtTest2,
- -1,
- SQL_DESC_BASE_COLUMN_NAME,
- &CharacterAttributePtrTest2,
- BufferLengthTest2,
- &StringLengthPtrTest2,
- &NumericAttributePtrTest2);
-
- if (ColAtt_retTest2 == SQL_ERROR || ColAtt_retTest2 == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "Let TYPE is 'ITEM' in Table 20,ColumnNumber"
- << "is less than one" << endl;
- ColAtt_DisplayErrorTest2(SQL_HANDLE_STMT, ColAtt_hstmtTest2);
- }
-
- //*********************************************************
- //** Let TYPE is 'ITEM' in Table 20, FieldIdentifer is zero
- //*********************************************************
- ColAtt_retTest2 = SQLColAttribute(ColAtt_hstmtTest2,
- 1018,
- 0,
- &CharacterAttributePtrTest2,
- BufferLengthTest2,
- &StringLengthPtrTest2,
- &NumericAttributePtrTest2);
-
- if (ColAtt_retTest2 == SQL_ERROR || ColAtt_retTest2 == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "Let TYPE is 'ITEM' in Table 20, FieldIdentifer"
- << " is zero" <<endl;
- ColAtt_DisplayErrorTest2(SQL_HANDLE_STMT, ColAtt_hstmtTest2);
- }
-
- //**********************************************************
- //** Let TYPE is 'ITEM' in Table 20, ColumnNumber is greater
- //** than TOP_LEVEL_COUNT(1044)
- //*********************************************************
- ColAtt_retTest2 = SQLColAttribute(ColAtt_hstmtTest2,
- 1045,
- SQL_DESC_BASE_COLUMN_NAME,
- &CharacterAttributePtrTest2,
- BufferLengthTest2,
- &StringLengthPtrTest2,
- &NumericAttributePtrTest2);
-
- if (ColAtt_retTest2 == SQL_ERROR || ColAtt_retTest2 == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "Let TYPE is 'ITEM' in Table 20, ColumnNumber" << endl
- << "is greater than TOP_LEVEL_COUNT(1044)" << endl;
- ColAtt_DisplayErrorTest2(SQL_HANDLE_STMT, ColAtt_hstmtTest2);
- }
-
- }
-
- // *********************************
- // ** Disconnect and Free Handles **
- // *********************************
- SQLDisconnect(ColAtt_hdbcTest2);
- SQLFreeHandle(SQL_HANDLE_STMT, ColAtt_hstmtTest2);
- SQLFreeHandle(SQL_HANDLE_DBC, ColAtt_hdbcTest2);
- SQLFreeHandle(SQL_HANDLE_ENV, ColAtt_henvTest2);
-
- return NDBT_OK;
-}
-
-
-void ColAtt_DisplayErrorTest2(SQLSMALLINT ColAttTest2_HandleType,
- SQLHSTMT ColAttTest2_InputHandle)
-{
- SQLSMALLINT ColAtt_i = 1;
- SQLRETURN ColAtt_SQLSTATEs;
- SQLCHAR ColAtt_Sqlstate[5];
- SQLCHAR ColAtt_Msg[MAXIMUM_MESSAGE_LENGTH_Test2];
- SQLSMALLINT ColAtt_MsgLen;
- SQLINTEGER ColAtt_NativeError;
-
- ndbout << "-------------------------------------------------" << endl;
- ndbout << "Error diagnostics:" << endl;
-
- while ((ColAtt_SQLSTATEs = SQLGetDiagRec(ColAttTest2_HandleType,
- ColAttTest2_InputHandle,
- ColAtt_i,
- ColAtt_Sqlstate,
- &ColAtt_NativeError,
- ColAtt_Msg,
- sizeof(ColAtt_Msg),
- &ColAtt_MsgLen))
- != SQL_NO_DATA)
- {
-
- ndbout << "the HandleType is:" << ColAttTest2_HandleType << endl;
- ndbout << "the InputHandle is :" << (long)ColAttTest2_InputHandle << endl;
- ndbout << "the ColAtt_Msg is: " << (char *) ColAtt_Msg << endl;
- ndbout << "the output state is:" << (char *)ColAtt_Sqlstate << endl;
-
- ColAtt_i ++;
- break;
- }
- ndbout << "-------------------------------------------------" << endl;
-}
diff --git a/storage/ndb/test/odbc/client/SQLColAttributeTest3.cpp b/storage/ndb/test/odbc/client/SQLColAttributeTest3.cpp
deleted file mode 100644
index bb7e322be8c..00000000000
--- a/storage/ndb/test/odbc/client/SQLColAttributeTest3.cpp
+++ /dev/null
@@ -1,275 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
- /**
- * @file SQLColAttributeTest3.cpp
- */
-
-#include <common.hpp>
-using namespace std;
-
-#define MAXIMUM_MESSAGE_LENGTH_Test3 200
-#define BufferLengthTest3 156
-
-SQLHSTMT ColAtt_hstmtTest3;
-SQLHSTMT ColAtt_hdbcTest3;
-SQLHENV ColAtt_henvTest3;
-SQLHDESC ColAtt_hdescTest3;
-
-SQLCHAR TypeName[18];
-SQLSMALLINT TypeNameLen;
-
-SQLRETURN ColAtt_retTest3;
-
-void ColAtt_DisplayErrorTest3(SQLSMALLINT ColAttTest3_HandleType,
- SQLHSTMT ColAttTest3_InputHandle);
-
-/**
- * Test returning descriptor information
- *
- * Test:
- * -# Print out column name without executing statement
- *
- * @return Zero, if test succeeded
- */
-
-int SQLColAttributeTest3()
-{
- ndbout << endl << "Start SQLColAttribute Testing3" << endl;
-
- SQLCHAR SQLStmt [120];
-
- //********************************************************************
- //** Test 3: **
- //** **
- //** Prepare a statement without executing the statement **
- //** We want to print out the Type Name of each column in the table **
- //** Customers **
- //** **
- //** Intended result: Only display column name, but there is no new **
- //** row in table Customers **
- //********************************************************************
-
- //************************************
- //** Allocate An Environment Handle **
- //************************************
- ColAtt_retTest3 = SQLAllocHandle(SQL_HANDLE_ENV,
- SQL_NULL_HANDLE,
- &ColAtt_henvTest3);
-
- if (ColAtt_retTest3 == SQL_SUCCESS || ColAtt_retTest3 == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated an environment Handle!" << endl;
-
- //*********************************************
- //** Set the ODBC application Version to 3.x **
- //*********************************************
- ColAtt_retTest3 = SQLSetEnvAttr(ColAtt_henvTest3,
- SQL_ATTR_ODBC_VERSION,
- (SQLPOINTER) SQL_OV_ODBC3,
- SQL_IS_UINTEGER);
-
- if (ColAtt_retTest3 == SQL_SUCCESS || ColAtt_retTest3 == SQL_SUCCESS_WITH_INFO)
- ndbout << "Set the ODBC application Version to 3.x!" << endl;
-
- //**********************************
- //** Allocate A Connection Handle **
- //**********************************
-
- ColAtt_retTest3 = SQLAllocHandle(SQL_HANDLE_DBC,
- ColAtt_henvTest3,
- &ColAtt_hdbcTest3);
-
- if (ColAtt_retTest3 == SQL_SUCCESS || ColAtt_retTest3 == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a connection Handle!" << endl;
-
- // *******************
- // ** Connect to DB **
- // *******************
- ColAtt_retTest3 = SQLConnect(ColAtt_hdbcTest3,
- (SQLCHAR *) connectString(),
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS);
-
- if (ColAtt_retTest3 == SQL_SUCCESS || ColAtt_retTest3 == SQL_SUCCESS_WITH_INFO)
- ndbout << "Connected to DB : OK!" << endl;
- else
- {
- ndbout << "Failure to Connect DB!" << endl;
- return NDBT_FAILED;
- }
-
- //*******************************
- //** Allocate statement handle **
- //*******************************
-
- ColAtt_retTest3 = SQLAllocHandle(SQL_HANDLE_STMT,
- ColAtt_hdbcTest3,
- &ColAtt_hstmtTest3);
- if(ColAtt_retTest3 == SQL_SUCCESS || ColAtt_retTest3 == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a statement handle!" << endl;
-
- //************************
- //** Define a statement **
- //************************
-
- /*
- strcpy((char *) SQLStmt,
- "DELETE FROM Customers WHERE CustID = 6");
- */
-
- strcpy((char *) SQLStmt,
- "INSERT INTO Customers (CustID, Name, Address, Phone) VALUES (6, 'Jan', 'LM vag 8', '969696')");
-
- /*
- strcpy((char *) SQLStmt,
- "INSERT INTO Customers (CustID, Name, Address, Phone) VALUES (?, ?, ?, ?)");
- */
-
- //*****************************
- //** Prepare SQL statement **
- //*****************************
- ColAtt_retTest3 = SQLPrepare(ColAtt_hstmtTest3,
- SQLStmt,
- SQL_NTS);
-
- if (ColAtt_retTest3 == SQL_SUCCESS || ColAtt_retTest3 == SQL_SUCCESS_WITH_INFO)
- {
- //************************************
- //** Display the name of column one **
- //************************************
- ColAtt_retTest3 = SQLColAttribute(ColAtt_hstmtTest3,
- 1,
- SQL_COLUMN_TYPE_NAME,
- TypeName,
- sizeof(TypeName),
- &TypeNameLen,
- NULL);
-
- if (ColAtt_retTest3 == SQL_ERROR || ColAtt_retTest3 == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << endl << "ColAtt_retTest3 = " << ColAtt_retTest3 << endl;
- ndbout << endl << "Name of column 1 is:"
- << (char *)TypeName <<endl;
- ColAtt_DisplayErrorTest3(SQL_HANDLE_STMT, ColAtt_hstmtTest3);
- }
-
- //************************************
- //** Display the name of column two **
- //************************************
- ColAtt_retTest3 = SQLColAttribute(ColAtt_hstmtTest3,
- 2,
- SQL_DESC_BASE_COLUMN_NAME,
- TypeName,
- sizeof(TypeName),
- &TypeNameLen,
- NULL);
-
- if (ColAtt_retTest3 == SQL_ERROR || ColAtt_retTest3 == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << endl << "ColAtt_retTest3 = " << ColAtt_retTest3 << endl;
- ndbout << endl << "Name of column 2 is:"
- << (char *)TypeName <<endl;
- ColAtt_DisplayErrorTest3(SQL_HANDLE_STMT, ColAtt_hstmtTest3);
- }
-
- //***************************************
- //** Display the name of column three **
- //***************************************
- ColAtt_retTest3 = SQLColAttribute(ColAtt_hstmtTest3,
- 3,
- SQL_DESC_BASE_COLUMN_NAME,
- TypeName,
- sizeof(TypeName),
- &TypeNameLen,
- NULL);
-
- if (ColAtt_retTest3 == SQL_ERROR || ColAtt_retTest3 == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "ColAtt_retTest3 = " << ColAtt_retTest3 << endl;
- ndbout << endl << "Name of column 3 is:"
- << (char *)TypeName <<endl;
- ColAtt_DisplayErrorTest3(SQL_HANDLE_STMT, ColAtt_hstmtTest3);
- }
-
- //**************************************
- //** Display the name of column four **
- //**************************************
- ColAtt_retTest3 = SQLColAttribute(ColAtt_hstmtTest3,
- 4,
- SQL_DESC_BASE_COLUMN_NAME,
- TypeName,
- sizeof(TypeName),
- &TypeNameLen,
- NULL);
-
- if (ColAtt_retTest3 == SQL_ERROR || ColAtt_retTest3 == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "ColAtt_retTest3 = " << ColAtt_retTest3 << endl;
- ndbout << endl << "Name of column 4 is:"
- << (char *)TypeName <<endl;
- ColAtt_DisplayErrorTest3(SQL_HANDLE_STMT, ColAtt_hstmtTest3);
- }
-
- }
-
- // *********************************
- // ** Disconnect and Free Handles **
- // *********************************
- SQLDisconnect(ColAtt_hdbcTest3);
- SQLFreeHandle(SQL_HANDLE_STMT, ColAtt_hstmtTest3);
- SQLFreeHandle(SQL_HANDLE_DBC, ColAtt_hdbcTest3);
- SQLFreeHandle(SQL_HANDLE_ENV, ColAtt_henvTest3);
-
- return NDBT_OK;
-}
-
-void ColAtt_DisplayErrorTest3(SQLSMALLINT ColAttTest3_HandleType,
- SQLHSTMT ColAttTest3_InputHandle)
-{
- SQLSMALLINT ColAtt_i = 1;
- SQLRETURN ColAtt_SQLSTATEs;
- SQLCHAR ColAtt_Sqlstate[5];
- SQLCHAR ColAtt_Msg[MAXIMUM_MESSAGE_LENGTH_Test3];
- SQLSMALLINT ColAtt_MsgLen;
- SQLINTEGER ColAtt_NativeError;
-
- ndbout << "-------------------------------------------------" << endl;
- ndbout << "Error diagnostics:" << endl;
-
- while ((ColAtt_SQLSTATEs = SQLGetDiagRec(ColAttTest3_HandleType,
- ColAttTest3_InputHandle,
- ColAtt_i,
- ColAtt_Sqlstate,
- &ColAtt_NativeError,
- ColAtt_Msg,
- sizeof(ColAtt_Msg),
- &ColAtt_MsgLen))
- != SQL_NO_DATA)
- {
-
- ndbout << "the HandleType is:" << ColAttTest3_HandleType << endl;
- ndbout << "the InputHandle is :" << (long)ColAttTest3_InputHandle << endl;
- ndbout << "the ColAtt_Msg is: " << (char *) ColAtt_Msg << endl;
- ndbout << "the output state is:" << (char *)ColAtt_Sqlstate << endl;
-
- ColAtt_i ++;
- break;
- }
- ndbout << "-------------------------------------------------" << endl;
-}
diff --git a/storage/ndb/test/odbc/client/SQLConnectTest.cpp b/storage/ndb/test/odbc/client/SQLConnectTest.cpp
deleted file mode 100644
index ba89ebc5f13..00000000000
--- a/storage/ndb/test/odbc/client/SQLConnectTest.cpp
+++ /dev/null
@@ -1,165 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
- /**
- * @file SQLConnectTest.cpp
- */
-#include <common.hpp>
-using namespace std;
-
-SQLHDBC conn_hdbc;
-SQLHSTMT conn_hstmt;
-SQLHENV conn_henv;
-SQLHDESC conn_hdesc;
-SQLRETURN conn_retcode;
-
-#define conn_SQL_MAXIMUM_MESSAGE_LENGTH 200
-SQLCHAR conn_Sqlstate[5];
-
-SQLINTEGER conn_NativeError;
-SQLSMALLINT conn_MsgLen;
-SQLCHAR conn_Msg[conn_SQL_MAXIMUM_MESSAGE_LENGTH];
-
-void SQLConnectTest_DisplayError_HDBC(SQLSMALLINT conn_HandleType,
- SQLHDBC conn_InputHandle);
-
-/**
- * -# Test to make a connection to an ODBC data source
- *
- * @return Zero, if test succeeded
- */
-int SQLConnectTest()
-{
- ndbout << endl << "Start SQLConnect Testing" << endl;
-
- // ************************************
- // ** Allocate an environment handle **
- // ************************************
- conn_retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &conn_henv);
- //conn_retcode = SQLAllocEnv(&conn_henv);
- if(conn_retcode == SQL_SUCCESS || conn_retcode == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "Allocated an environment handle!" << endl;
- }
- else
- {
- ndbout << "Failed to allocate environment handle!" << endl;
- return NDBT_FAILED;
- }
-
- // *********************************************
- // ** Set the ODBC application Version to 3.x **
- // *********************************************
- conn_retcode = SQLSetEnvAttr(conn_henv,
- SQL_ATTR_ODBC_VERSION,
- (SQLPOINTER) SQL_OV_ODBC3,
- SQL_IS_UINTEGER);
- if (conn_retcode == SQL_SUCCESS || conn_retcode == SQL_SUCCESS_WITH_INFO) {
- ndbout << "Set ODBC application version to 3.x" << endl;
- } else {
- ndbout << "Failed to set application version!" << endl;
- return NDBT_FAILED;
- }
-
- // **********************************
- // ** Allocate a connection handle **
- // **********************************
- conn_retcode = SQLAllocHandle(SQL_HANDLE_DBC, conn_henv, &conn_hdbc);
- // retcode = SQLAllocConnect(conn_henv, &conn_hdbc);
- if (conn_retcode == SQL_SUCCESS || conn_retcode == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "Allocated a connection handle!" << endl;
- }
- else
- {
- ndbout << "Failed to allocate connection handle!" << endl;
- return NDBT_FAILED;
- }
-
- // *******************
- // ** Connect to DB **
- // *******************
- conn_retcode = SQLConnect(conn_hdbc,
- (SQLCHAR *) connectString(),
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS);
- ndbout << "conn_retcode = " << conn_retcode << endl;
- if (conn_retcode == SQL_SUCCESS)
- {
- ndbout << "Connected to DB!" << endl;
- }
- else if (conn_retcode == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "Connected to DB, but SQL_SUCCESS_WITH_INFO!" << endl;
- SQLConnectTest_DisplayError_HDBC(SQL_HANDLE_DBC, conn_hdbc);
- }
- else if (conn_retcode == SQL_INVALID_HANDLE)
- {
- ndbout << "SQL_INVALID_HANDLE appeared. Please check program." << endl;
- return NDBT_FAILED;
- }
- else if (conn_retcode == SQL_ERROR)
- {
- ndbout << "Failed to connect!" << endl;
- SQLConnectTest_DisplayError_HDBC(SQL_HANDLE_DBC, conn_hdbc);
- return NDBT_FAILED;
- }
- else
- ;
-
- // ******************
- // ** Free Handles **
- // ******************
- SQLDisconnect(conn_hdbc);
- SQLFreeHandle(SQL_HANDLE_STMT, conn_hstmt);
- SQLFreeHandle(SQL_HANDLE_DBC, conn_hdbc);
- SQLFreeHandle(SQL_HANDLE_ENV, conn_henv);
- return NDBT_OK;
-}
-
-
-void SQLConnectTest_DisplayError_HDBC(SQLSMALLINT conn_HandleType,
- SQLHDBC conn_InputHandle) {
- SQLSMALLINT conn_i = 1;
- SQLRETURN conn_SQLSTATE;
-
- ndbout << "-------------------------------------------------" << endl;
- ndbout << "Error diagnostics:" << endl;
-
- while ((conn_SQLSTATE = SQLGetDiagRec(conn_HandleType,
- conn_InputHandle,
- conn_i,
- conn_Sqlstate,
- &conn_NativeError,
- conn_Msg,
- sizeof(conn_Msg),
- &conn_MsgLen)
- ) != SQL_NO_DATA)
- {
- ndbout << "SQLSTATE = " << conn_SQLSTATE << endl;
- ndbout << "the HandleType is: " << conn_HandleType << endl;
- ndbout << "the InputHandle is :" << (long)conn_InputHandle << endl;
- ndbout << "the conn_Msg is: " << (char *) conn_Msg << endl;
- ndbout << "the output state is:" << (char *)conn_Sqlstate << endl;
-
- conn_i ++;
- break;
- }
- ndbout << "-------------------------------------------------" << endl;
-}
diff --git a/storage/ndb/test/odbc/client/SQLCopyDescTest.cpp b/storage/ndb/test/odbc/client/SQLCopyDescTest.cpp
deleted file mode 100644
index 2fa80986359..00000000000
--- a/storage/ndb/test/odbc/client/SQLCopyDescTest.cpp
+++ /dev/null
@@ -1,140 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NdbOut.hpp>
-#include <sqlcli.h>
-#include <stdio.h>
-
-using namespace std;
-
-#define NAME_LEN 50
-#define PHONE_LEN 10
-#define SALES_PERSON_LEN 10
-#define STATUS_LEN 6
-
-#define ROWS 100
-#define DESC_LEN 50
-
-
-// Template for a row
-typedef struct {
- SQLINTEGER sPartID;
- SQLINTEGER cbPartID;
- SQLUCHAR szDescription[DESC_LENGTH];
- SQLINTEGER cbDescription;
- REAL sPrice;
- SQLINTEGER cbPrice;
-} PartsSource;
-
-PartsSource rget[ROWS]; // rowset buffer
-SQLUSMALLINT sts_ptr[ROWS]; // status pointer
-SQLHSTMT hstmt0, hstmt1;
-SQLHDESC hArd0, hIrd0, hApd1, hIpd1;
-
-
-SQLHSTMT hstmt;
-SQLHDESC hdesc;
-
-SQLSMALLINT RecNumber;
-SQLCHAR szSalesPerson[SALES_PERSON_LEN];
-
-SQLCHAR Sqlstate[5], Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
-SQLINTEGER NativeError;
-SQLRETURN retcode, SQLSTATEs;
-
-SQLINTEGER ValuePtr1;
-SQLCHAR ValuePtr2;
-SQLSMALLINT ValuePtr3;
-
-
-SQLINTEGER StringLengthPtr;
-
-SQLSMALLINT i, MsgLen;
-
-void DisplayError(SQLSMALLINT HandleType, SQLHDESC InputHandle);
-
-int SQLCopyDescTest ()
-{
-
-
- // We can create the table and insert rows in NDB by program TestDirectSQL.
- // In this test program(SQLGetCopyRecTest),we only have three rows in table ORDERS
-
-
-// ARD and IRD of hstmt0
-SQLGetStmtAttr(hstmt0, SQL_ATTR_APP_ROW_DESC, &hArd0, 0, NULL);
-SQLGetStmtAttr(hstmt0, SQL_ATTR_IMP_ROW_DESC, &hIrd0, 0, NULL);
-
-// APD and IPD of hstmt1
-SQLGetStmtAttr(hstmt1, SQL_ATTR_APP_PARAM_DESC, &hApd1, 0, NULL);
-SQLGetStmtAttr(hstmt1, SQL_ATTR_IMP_PARAM_DESC, &hIpd1, 0, NULL);
-
-// Use row-wise binding on hstmt0 to fetch rows
-SQLSetStmtAttr(hstmt0, SQL_ATTR_ROW_BIND_TYPE, (SQLPOINTER) sizeof(PartsSource), 0);
-
-// Set rowset size for hstmt0
-SQLSetStmtAttr(hstmt0, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER) ROWS, 0);
-
-// Execute a select statement
-SQLExecDirect(hstmt0, "SELECT PARTID, DESCRIPTION, PRICE FROM PARTS ORDER BY 3, 1, 2"",
- SQL_NTS);
-
-// Bind
-SQLBindCol(hstmt0, 1, SQL_C_SLONG, rget[0].sPartID, 0,
- &rget[0].cbPartID);
-SQLBindCol(hstmt0, 2, SQL_C_CHAR, &rget[0].szDescription, DESC_LEN,
- &rget[0].cbDescription);
-SQLBindCol(hstmt0, 3, SQL_C_FLOAT, rget[0].sPrice,
- 0, &rget[0].cbPrice);
-
- // Perform parameter bindings on hstmt1.
- /* If SourceDeschandle does not identify an allocated CLI descriptor area */
- retcode1 = SQLCopyDesc(hArd0, hApd1);
- retcode2 = SQLCopyDesc(hIrd0, hIpd1);
-
-if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- DisplayError(SQL_HANDLE_DESC, hdesc);
-
-
- /* If TargetDeschandle does not identify an allocated CLI descriptor area */
- retcode = SQLCopyDesc(hdesc, );
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- DisplayError(SQL_HANDLE_DESC, hdesc);
-
-
- return 0;
-
- }
-
-
-void DisplayError(SQLSMALLINT HandleType, SQLHDESC InputHandle)
-{
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
-
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLDescribeColTest.cpp b/storage/ndb/test/odbc/client/SQLDescribeColTest.cpp
deleted file mode 100644
index 7957d200806..00000000000
--- a/storage/ndb/test/odbc/client/SQLDescribeColTest.cpp
+++ /dev/null
@@ -1,260 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
- /**
- * @file SQLDescribeColTest.cpp
- */
-#include <common.hpp>
-
-using namespace std;
-
-#define DC_Column_NAME_LEN 50
-#define DC_MESSAGE_LENGTH 200
-
-SQLHSTMT DC_hstmt;
-SQLHDBC DC_hdbc;
-SQLHENV DC_henv;
-SQLHDESC DC_hdesc;
-
-void DescribeCol_DisplayError(SQLSMALLINT DC_HandleType,
- SQLHSTMT DC_InputHandle);
-
-/**
- * Test to retrieve basic result data set metadata information
- * (specifically, column name, SQL data type, column size, decimal
- * precision, and nullability) for a specified column in a result
- * data set
- * -# No prepared or executed statement when executing
- * -# ColumnNumber is less than 1
- * -# ColumnNumber is greater than the value of the TOP_LEVEL_COUNT field of IRD
- * @return Zero, if test succeeded
- */
-
-int SQLDescribeColTest()
-{
- SQLCHAR SQLStmt [120];
- SQLRETURN retcode;
- SQLCHAR ColumnName[DC_Column_NAME_LEN];
- SQLSMALLINT NameLength, DataTypePtr, DecimalDigitsPtr, NullablePtr;
- SQLUINTEGER ColumnSizePtr;
-
- ndbout << "Start SQLDescribeCol Test " << endl;
- //******************************************************************
- //** Test1 **
- //** There is no prepared or executed statement associated with **
- //** StatementHandle **
- //******************************************************************
-
- retcode = SQLDescribeCol(DC_hstmt,
- (SQLUSMALLINT)1,
- ColumnName,
- sizeof(ColumnName),
- &NameLength,
- &DataTypePtr,
- &ColumnSizePtr,
- &DecimalDigitsPtr,
- &NullablePtr);
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- DescribeCol_DisplayError(SQL_HANDLE_STMT, DC_hstmt);
-
-
- //************************************
- //** Allocate An Environment Handle **
- //************************************
- retcode = SQLAllocHandle(SQL_HANDLE_ENV,
- SQL_NULL_HANDLE,
- &DC_henv);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated an environment Handle!" << endl;
-
- //*********************************************
- //** Set the ODBC application Version to 3.x **
- //*********************************************
- retcode = SQLSetEnvAttr(DC_henv,
- SQL_ATTR_ODBC_VERSION,
- (SQLPOINTER) SQL_OV_ODBC3,
- SQL_IS_UINTEGER);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Set the ODBC application Version to 3.x!" << endl;
-
- //**********************************
- //** Allocate A Connection Handle **
- //**********************************
-
- retcode = SQLAllocHandle(SQL_HANDLE_DBC,
- DC_henv,
- &DC_hdbc);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a connection Handle!" << endl;
-
- // *******************
- // ** Connect to DB **
- // *******************
- retcode = SQLConnect(DC_hdbc,
- (SQLCHAR *) connectString(),
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Connected to DB : OK!" << endl;
- else
- {
- ndbout << "Failure to Connect DB!" << endl;
- return NDBT_FAILED;
- }
- //*******************************
- //** Allocate statement handle **
- //*******************************
-
- retcode = SQLAllocHandle(SQL_HANDLE_STMT,
- DC_hdbc,
- &DC_hstmt);
- if(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a statement handle!" << endl;
-
- //************************
- //** Define a statement **
- //************************
-
- strcpy((char *) SQLStmt,
- "SELECT * FROM Customers");
-
- //***********************************************
- //** Prepare and Execute the SQL statement **
- //***********************************************
-
- retcode = SQLExecDirect(DC_hstmt,
- SQLStmt,
- SQL_NTS);
-
-if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
-
- //*********************************
- //** ColumnNumber is from 1 to 4 **
- //*********************************
- ndbout << endl << "ColumnNumber is from 1 to 4" << endl;
-
- for (int ii = 1; ii <= 4; ii++)
- {
- retcode = SQLDescribeCol(DC_hstmt,
- ii,
- ColumnName,
- sizeof(ColumnName),
- &NameLength,
- &DataTypePtr,
- &ColumnSizePtr,
- &DecimalDigitsPtr,
- &NullablePtr);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Column Name = " << (char *)ColumnName << endl;
-
- }
-
- //*********************************
- //** Test2 **
- //** ColumnNumber is less than 1 **
- //*********************************
-
- retcode = SQLDescribeCol(DC_hstmt,
- (SQLUSMALLINT)-1,
- ColumnName,
- sizeof(ColumnName),
- &NameLength,
- &DataTypePtr,
- &ColumnSizePtr,
- &DecimalDigitsPtr,
- &NullablePtr);
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << endl << "ColumnNumber is less than 1" << endl;
- DescribeCol_DisplayError(SQL_HANDLE_STMT, DC_hstmt);
-
- //*********************************************************************
- //** Test3 **
- //** ColumnNumber is greater than N(the value of the TOP_LEVEL_COUNT **
- //** field of IRD) **
- //*********************************************************************
-
- ndbout << endl <<"ColumnNumber is greater than N(the value"
- << "of the TOP_LEVEL_COUNTfield of IRD)" << endl;
-
- retcode = SQLDescribeCol(DC_hstmt,
- (SQLUSMALLINT)1045,
- ColumnName,
- sizeof(ColumnName),
- &NameLength,
- &DataTypePtr,
- &ColumnSizePtr,
- &DecimalDigitsPtr,
- &NullablePtr);
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- DescribeCol_DisplayError(SQL_HANDLE_STMT, DC_hstmt);
-
-}
-
- // *********************************
- // ** Disconnect and Free Handles **
- // *********************************
- SQLDisconnect(DC_hdbc);
- SQLFreeHandle(SQL_HANDLE_STMT, DC_hstmt);
- SQLFreeHandle(SQL_HANDLE_DBC, DC_hdbc);
- SQLFreeHandle(SQL_HANDLE_ENV, DC_henv);
-
- return NDBT_OK;
-}
-
-void DescribeCol_DisplayError(SQLSMALLINT DC_HandleType,
- SQLHSTMT DC_InputHandle)
-{
- SQLCHAR Sqlstate[5], Msg[DC_MESSAGE_LENGTH];
- SQLINTEGER NativeError;
- SQLSMALLINT DC_i, MsgLen;
- SQLRETURN SQLSTATEs;
-
- DC_i = 1;
-
- while ((SQLSTATEs = SQLGetDiagRec(DC_HandleType,
- DC_InputHandle,
- DC_i,
- Sqlstate,
- &NativeError,
- Msg,
- sizeof(Msg),
- &MsgLen))
- != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << DC_HandleType << endl;
- ndbout << "the InputHandle is :" << (long)DC_InputHandle << endl;
- ndbout << "the return message is:" << (char *)Msg << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- DC_i ++;
- break;
- }
-
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLDisconnectTest.cpp b/storage/ndb/test/odbc/client/SQLDisconnectTest.cpp
deleted file mode 100644
index 5b9d1740fb5..00000000000
--- a/storage/ndb/test/odbc/client/SQLDisconnectTest.cpp
+++ /dev/null
@@ -1,155 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
- /**
- * @file SQLDisconnectTest.cpp
- */
-
-#include <common.hpp>
-#define disc_SQL_MAXIMUM_MESSAGE_LENGTH 200
-
-using namespace std;
-
-SQLHDBC disc_hdbc;
-SQLHSTMT disc_hstmt;
-SQLHENV disc_henv;
-SQLHDESC disc_hdesc;
-
-void Disconnect_DisplayError_HDBC(SQLSMALLINT disc_HandleType,
- SQLHDBC disc_InputHandle);
-/**
- * Test to close the data source connection associated with
- * a specific connection handle
- *
- * -# Normal case testing
- * @return Zero, if test succeeded
- */
-
-int SQLDisconnectTest()
-{
- SQLRETURN disc_retcode;
- ndbout << endl << "Start SQLDisconnect Testing" << endl;
-
- // ************************************
- // ** Allocate an environment handle **
- // ************************************
- disc_retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &disc_henv);
-
- if(disc_retcode == SQL_SUCCESS || disc_retcode == SQL_SUCCESS_WITH_INFO) {
- ndbout << "Allocated an environment handle!" << endl;
- } else {
- ndbout << "Failed to allocate environment handle!" << endl;
- return NDBT_FAILED;
- }
-
- // *********************************************
- // ** Set the ODBC application Version to 3.x **
- // *********************************************
- disc_retcode = SQLSetEnvAttr(disc_henv,
- SQL_ATTR_ODBC_VERSION,
- (SQLPOINTER) SQL_OV_ODBC3,
- SQL_IS_UINTEGER);
- if (disc_retcode == SQL_SUCCESS || disc_retcode == SQL_SUCCESS_WITH_INFO) {
- ndbout << "Set ODBC application version to 3.x" << endl;
- } else {
- ndbout << "Failed to set application version!" << endl;
- return NDBT_FAILED;
- }
-
- // **********************************
- // ** Allocate a connection handle **
- // **********************************
- disc_retcode = SQLAllocHandle(SQL_HANDLE_DBC, disc_henv, &disc_hdbc);
-
- if (disc_retcode == SQL_SUCCESS || disc_retcode == SQL_SUCCESS_WITH_INFO) {
- ndbout << "Allocated a connection handle!" << endl;
- } else {
- ndbout << "Failed to allocate connection handle!" << endl;
- return NDBT_FAILED;
- }
-
- // *******************
- // ** connect to DB **
- // *******************
- disc_retcode = SQLConnect(disc_hdbc,
- (SQLCHAR *) connectString(),
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS);
-
- // **********************
- // ** Disconnect to DB **
- // **********************
- disc_retcode = SQLDisconnect(disc_hdbc);
-
- if (disc_retcode == SQL_INVALID_HANDLE)
-{
- ndbout << "Handle Type is SQL_HANDLE_DBC, but string SQL_INVALID_HANDLE"
- << " still appeared. Please check program" << endl;
- Disconnect_DisplayError_HDBC(SQL_HANDLE_DBC, disc_hdbc);
-}
-
- if (disc_retcode == SQL_ERROR || disc_retcode == SQL_SUCCESS_WITH_INFO)
-{
- ndbout << "disconnect retcode = " << disc_retcode << endl;
- Disconnect_DisplayError_HDBC(SQL_HANDLE_DBC, disc_hdbc);
-}
- // ******************
- // ** Free Handles **
- // ******************
- SQLFreeHandle(SQL_HANDLE_STMT, disc_hstmt);
- SQLFreeHandle(SQL_HANDLE_DBC, disc_hdbc);
- SQLFreeHandle(SQL_HANDLE_ENV, disc_henv);
-
- return NDBT_OK;
-
- }
-
-void Disconnect_DisplayError_HDBC(SQLSMALLINT disc_HandleType,
- SQLHDBC disc_InputHandle)
-{
- SQLCHAR disc_Msg[disc_SQL_MAXIMUM_MESSAGE_LENGTH];
- SQLSMALLINT disc_i, disc_MsgLen;
- SQLINTEGER disc_NativeError;
- SQLRETURN disc_SQLSTATEs;
- disc_i = 1;
- SQLCHAR disc_Sqlstate[5];
-
- while ((disc_SQLSTATEs = SQLGetDiagRec(disc_HandleType,
- disc_InputHandle,
- disc_i,
- disc_Sqlstate,
- &disc_NativeError,
- disc_Msg,
- sizeof(disc_Msg),
- &disc_MsgLen))
- != SQL_NO_DATA)
- {
-
- ndbout << "the HandleType is:" << disc_HandleType << endl;
- ndbout << "the InputHandle is :" <<(long)disc_InputHandle << endl;
- ndbout << "the output state is:" << (char *)disc_Sqlstate << endl;
-
- disc_i ++;
- break;
- }
-
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLDriverConnectTest.cpp b/storage/ndb/test/odbc/client/SQLDriverConnectTest.cpp
deleted file mode 100644
index 861fe0a87a2..00000000000
--- a/storage/ndb/test/odbc/client/SQLDriverConnectTest.cpp
+++ /dev/null
@@ -1,96 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <common.hpp>
-#include <string.h>
-
-using namespace std;
-
-SQLHDBC driconn_hdbc;
-SQLHSTMT driconn_hstmt;
-SQLHENV driconn_henv;
-SQLHDESC driconn_hdesc;
-SQLRETURN driconn_retcode, driconn_SQLSTATEs;
-
-#define driconn_SQL_MAXIMUM_MESSAGE_LENGTH 200
-SQLCHAR driconn_Sqlstate[5];
-
-SQLINTEGER driconn_NativeError;
-SQLSMALLINT driconn_i, driconn_MsgLen;
-SQLCHAR driconn_Msg[driconn_SQL_MAXIMUM_MESSAGE_LENGTH], driconn_ConnectIn[30];
-
-void SQLDriverConnectTest_DisplayError_HDBC(SQLSMALLINT driconn_HandleType, SQLHDBC driconn_InputHandle);
-
-int SQLDriverConnectTest()
-{
- ndbout << endl << "Start SQLDriverConnect Testing" << endl;
- // Allocate An Environment Handle
- driconn_retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &driconn_henv);
-
- // Set the ODBC application Version to 3.x
- driconn_retcode = SQLSetEnvAttr(driconn_henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER);
-
- if (driconn_retcode == SQL_SUCCESS || driconn_retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Set the ODBC application Version to 3.x" << endl;
-
- // Allocate A Connection Handle
- driconn_retcode = SQLAllocHandle(SQL_HANDLE_DBC, driconn_henv, &driconn_hdbc);
-
- if (driconn_retcode == SQL_SUCCESS || driconn_retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocation A Connection Handle" << endl;
-
- // Build A Connection String
- strcpy((char*) driconn_ConnectIn, "DSN=ndb;UID=x;PWD=y");
-
- // Connect to NDB
- driconn_retcode = SQLDriverConnect(driconn_hdbc, NULL, driconn_ConnectIn, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT);
- ndbout << "retcode = " << driconn_retcode << endl;
- ndbout << "Before pringing out information about connection, we print out retcode = " << driconn_retcode << endl;
-
- if (driconn_retcode == SQL_SUCCESS || driconn_retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Connected to NDB" << endl;
-
- if (driconn_retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_DBC, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- else
- { if (driconn_retcode == SQL_ERROR || driconn_retcode == SQL_SUCCESS_WITH_INFO)
- SQLDriverConnectTest_DisplayError_HDBC(SQL_HANDLE_DBC, driconn_hdbc);}
-
- // Free the Connection Handle
- SQLFreeHandle(SQL_HANDLE_DBC, driconn_hdbc);
-
- // Free the Environment Handle
- SQLFreeHandle(SQL_HANDLE_ENV, driconn_henv);
-
- return 0;
- }
-
-void SQLDriverConnectTest_DisplayError_HDBC(SQLSMALLINT driconn_HandleType, SQLHDBC driconn_InputHandle)
-{
- driconn_i = 1;
- while ((driconn_SQLSTATEs = SQLGetDiagRec(driconn_HandleType, driconn_InputHandle, driconn_i,
- driconn_Sqlstate, &driconn_NativeError, driconn_Msg, sizeof(driconn_Msg),
- &driconn_MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << driconn_HandleType << endl;
- ndbout << "the InputHandle is :" << (long)driconn_InputHandle << endl;
- ndbout << "the output state is:" << (char *)driconn_Sqlstate << endl;
-
- driconn_i ++;
- }
-
-}
diff --git a/storage/ndb/test/odbc/client/SQLEndTranTest.cpp b/storage/ndb/test/odbc/client/SQLEndTranTest.cpp
deleted file mode 100644
index 3c2f03d8569..00000000000
--- a/storage/ndb/test/odbc/client/SQLEndTranTest.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <common.h>
-
-using namespace std;
-
-#define SQL_MAXIMUM_MESSAGE_LENGTH 200
-
-SQLHDBC hdbc;
-SQLHSTMT hstmt;
-SQLHENV henv;
-SQLHDESC hdesc;
-SQLINTEGER strangehandle;
-SQLRETURN retcode, retcodeprepare, SQLSTATEs;
-SQLCHAR Sqlstate[5];
-
-SQLINTEGER NativeError;
-SQLSMALLINT i, MsgLen;
-SQLSMALLINT Not_In_Table13;
-
-SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
-
-
-void SQLEndTran_DisplayError(SQLSMALLINT HandleType, SQLHSTMT InputHandle);
-
-int SQLEndTranTest()
-{
-
- strangehandle = 67;
- /* hstmt */
- // Execute a statement to retrieve rows from the Customers table. We can create the table and
- // inside rows into NDB by program TestDirectSQL
- // retcode = SQLPrepare(hstmt, (SQLCHAR*)"SELECT CustID, Name, Address, Phone FROM Customers", 56);
-
- retcodeprepare = SQLPrepare(hstmt, (SQLCHAR*)"SELECT CustID, Name, Address, Phone FROM Customers", SQL_NTS);
-
- if (retcodeprepare == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS) {
- retcode = SQLExecute(hstmt);
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS) {
-
- /* HandleType is not in Table 13 */
- Not_In_Table13 = 67;
- SQLSTATEs = SQLEndTran(Not_In_Table13, (void*)strangehandle , SQL_COMMIT);
- if (SQLSTATEs == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(67, 67, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:67" << endl;
- ndbout << "the InputHandle is :67" << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
-
- }
-
- /* HandleType is STATEMENT HANDLE, if the value of Handle does not identity an allocated SQL_statement */
- SQLSTATEs = SQLEndTran(SQL_HANDLE_STMT, hdbc, SQL_COMMIT);
- if (SQLSTATEs == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SQLEndTran_DisplayError(SQL_HANDLE_STMT, hstmt);
-
- /* The value of CompletionType is not in Table 14 */
- SQLSTATEs = SQLEndTran(SQL_HANDLE_STMT, hstmt, 8888);
- if (SQLSTATEs == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SQLEndTran_DisplayError(SQL_HANDLE_STMT, hstmt);
-
- }
-
- }
- return 0;
-
- }
-
-
-void SQLEndTran_DisplayError(SQLSMALLINT HandleType, SQLHSTMT InputHandle)
-{
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
-
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLErrorTest.cpp b/storage/ndb/test/odbc/client/SQLErrorTest.cpp
deleted file mode 100644
index 17fbf1577b7..00000000000
--- a/storage/ndb/test/odbc/client/SQLErrorTest.cpp
+++ /dev/null
@@ -1,107 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#if 0
-
-#include <NdbOut.hpp>
-#include <sqlcli.h>
-#include <stdio.h>
-
-using namespace std;
-
-#define NAME_LEN 50
-#define PHONE_LEN 10
-
-SQLHDBC hdbc;
-SQLHSTMT hstmt;
-SQLHENV henv;
-SQLHDESC hdesc;
-SQLRETURN retcode, SQLSTATEs;
-
-SQLCHAR Sqlstate[5];
-
-SQLSMALLINT i, MsgLen;
-SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
-
-SQLCHAR szName[NAME_LEN], szPhone[PHONE_LEN];
-SQLINTEGER sCustID, cbName, cbCustID, cbPhone, NativeError;
-
-void DisplayError(SQLSMALLINT HandleType, SQLHSTMT InputHandle);
-
-int SQLBindColTest ()
-{
-
- /* hstmt */
- // Execute a statement to retrieve rows from the Customers table. We can create the table and inside rows in
- // NDB by another program TestDirectSQL. In this test program(SQLBindColTest),we only have three rows in
- // table CUSTOMERS
-
-retcode = SQLExecDirect(hstmt, (SQLCHAR*)"SELECT CUSTID, NAME, PHONE FROM CUSTOMERS ORDER BY 2, 1, 3", SQL_NTS);
-if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
-
-SQLBindCol(hstmt, 0, SQL_C_ULONG, &sCustID, 0, &cbCustID);
-while (TRUE) {
-retcode = SQLFetch(hstmt);
-if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- DisplayError(SQL_HANDLE_STMT, hstmt);
-
- }
-
-
-SQLBindCol(hstmt, 4, SQL_C_ULONG, &sCustID, 0, &cbCustID);
-while (TRUE) {
-retcode = SQLFetch(hstmt);
-if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- DisplayError(SQL_HANDLE_STMT, hstmt);
-
- }
-
-/* Bind columns 1, 2, and 3 */
-SQLBindCol(hstmt, 1, SQL_C_ULONG, &sCustID, 0, &cbCustID);
-SQLBindCol(hstmt, 2, SQL_C_CHAR, szName, NAME_LEN, &cbName);
-SQLBindCol(hstmt, 3, SQL_C_CHAR, szPhone, PHONE_LEN, &cbPhone);
-/* Fetch and print each row of data. On */
-/* an error, display a message and exit. */
-while (TRUE) {
-retcode = SQLFetch(hstmt);
-if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- DisplayError(SQL_HANDLE_STMT, hstmt);
-
- }
- }
-
- return 0;
-
- }
-
-
-void DisplayError(SQLSMALLINT HandleType, SQLHSTMT InputHandle)
-{
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
-
-}
-
-#endif
diff --git a/storage/ndb/test/odbc/client/SQLExecDirectTest.cpp b/storage/ndb/test/odbc/client/SQLExecDirectTest.cpp
deleted file mode 100644
index 1a057f85260..00000000000
--- a/storage/ndb/test/odbc/client/SQLExecDirectTest.cpp
+++ /dev/null
@@ -1,353 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
- /**
- * @file SQLExecDirectTest.cpp
- */
-#include <common.hpp>
-#define EXD_MESSAGE_LENGTH 200
-#define EXD_NAME_LEN 10
-#define EXD_PHONE_LEN 10
-#define EXD_ADDRESS_LEN 10
-using namespace std;
-
-SQLHDBC EXD_hdbc;
-SQLHSTMT EXD_hstmt;
-SQLHENV EXD_henv;
-SQLHDESC EXD_hdesc;
-SQLRETURN EXD_ret, SQLSTATEs;
-
-void ExecDirect_DisplayError(SQLSMALLINT EXD_HandleType,
- SQLHSTMT EXD_InputHandle);
-
-int EXD_Display_Result(SQLHSTMT EXDR_InputHandle);
-
-/**
- * Test to execute a prepared ststement
- *
- * -# Normal case: Prepare and Execute a prepared statement
- * -# Prepare and Execute an empty statement
- * -# Prepare and Execute a statement with wrong henv handle
- * -# Prepare and Execute a statement with wrong hdbc handle
- * -# Prepare and Execute a statement with wrong hdesc handle
- * @return Zero, if test succeeded
- */
-
-int SQLExecDirectTest()
-{
- ndbout << endl << "Start ExecDirect Testing" << endl;
-
- //************************************
- //** Allocate An Environment Handle **
- //************************************
- EXD_ret = SQLAllocHandle(SQL_HANDLE_ENV,
- SQL_NULL_HANDLE,
- &EXD_henv);
-
-if (EXD_ret == SQL_SUCCESS || EXD_ret == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated an environment Handle!" << endl;
-
- //*********************************************
- //** Set the ODBC application Version to 3.x **
- //*********************************************
- EXD_ret = SQLSetEnvAttr(EXD_henv,
- SQL_ATTR_ODBC_VERSION,
- (SQLPOINTER) SQL_OV_ODBC3,
- SQL_IS_UINTEGER);
-
-if (EXD_ret == SQL_SUCCESS || EXD_ret == SQL_SUCCESS_WITH_INFO)
- ndbout << "Set the ODBC application Version to 3.x!" << endl;
-
- //**********************************
- //** Allocate A Connection Handle **
- //**********************************
-
- EXD_ret = SQLAllocHandle(SQL_HANDLE_DBC,
- EXD_henv,
- &EXD_hdbc);
-
-if (EXD_ret == SQL_SUCCESS || EXD_ret == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a connection Handle!" << endl;
-
- // *******************
- // ** Connect to DB **
- // *******************
- EXD_ret = SQLConnect(EXD_hdbc,
- (SQLCHAR *) connectString(),
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS);
-
-if (EXD_ret == SQL_SUCCESS || EXD_ret == SQL_SUCCESS_WITH_INFO)
- ndbout << "Connected to DB : OK!" << endl;
- else
- {
- ndbout << "Failure to Connect DB!" << endl;
- return NDBT_FAILED;
- }
-
- //*******************************
- //** Allocate statement handle **
- //*******************************
-
- EXD_ret = SQLAllocHandle(SQL_HANDLE_STMT,
- EXD_hdbc,
- &EXD_hstmt);
-if(EXD_ret == SQL_SUCCESS || EXD_ret == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a statement handle!" << endl;
-
- //**********************************************
- //** Test1 **
- //** Prepare and Execute a prepared statement **
- //**********************************************
- EXD_ret = SQLExecDirect(EXD_hstmt,
- (SQLCHAR*)"SELECT * FROM Customers",
- SQL_NTS);
-
- if (EXD_ret == SQL_INVALID_HANDLE)
- {
- ndbout << "Handle Type is SQL_HANDLE_STMT, but SQL_INVALID_HANDLE" << endl;
- ndbout << "still appeared. Please check program" << endl;
- }
-
- if (EXD_ret == SQL_ERROR || EXD_ret == SQL_SUCCESS_WITH_INFO)
- ExecDirect_DisplayError(SQL_HANDLE_STMT, EXD_hstmt);
-
- //*************************
- //** Display the results **
- //*************************
-
- EXD_Display_Result(EXD_hstmt);
-
- //*******************************************
- //** Test2 **
- //** Prepare and Execute an empty statement**
- //** in order to see what will happen **
- //*******************************************
- EXD_ret = SQLExecDirect(EXD_hstmt,
- (SQLCHAR*)" ",
- SQL_NTS);
-
- if (EXD_ret == SQL_ERROR || EXD_ret == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "Prepare and Execute an empty statement," << endl;
- ndbout << "The following case happened!" << endl;
- ExecDirect_DisplayError(SQL_HANDLE_STMT, EXD_hstmt);
- }
-
- //***************************************************************
- //** Test3 **
- //** Prepare and Execute a statement with wrong henv handle **
- //** in order to see what will happen **
- //***************************************************************
- EXD_ret = SQLExecDirect(EXD_henv,
- (SQLCHAR*)"SELECT * FROM Customers",
- SQL_NTS);
-
- if (EXD_ret == SQL_SUCCESS_WITH_INFO || EXD_ret == SQL_SUCCESS)
- { ndbout << "Handle Type is SQL_HANDLE_HENV, but SQL_INVALID_HANDLE" << endl;
- ndbout << "still appeared. Please check programm" << endl;
- ExecDirect_DisplayError(SQL_HANDLE_ENV, EXD_henv);
- }
-
- //******************************************************************
- //** Test4 **
- //** Prepare and Execute a statement with wrong hdbc handle **
- //** in order to see what will happen **
- //******************************************************************
-
- EXD_ret = SQLExecDirect(EXD_hdbc,
- (SQLCHAR*)"SELECT * FROM Customers",
- SQL_NTS);
-
- if (EXD_ret == SQL_SUCCESS_WITH_INFO || EXD_ret == SQL_SUCCESS)
- ExecDirect_DisplayError(SQL_HANDLE_DBC, EXD_hdbc);
-
- //*******************************************************************
- //** Test5 **
- //** Prepare and Execute a statement with wrong hdesc handle **
- //** in order to see what will happen **
- //*******************************************************************
-
- EXD_ret = SQLExecDirect(EXD_hdesc,
- (SQLCHAR*)"SELECT * FROM Customers",
- SQL_NTS);
-
- if (EXD_ret == SQL_SUCCESS_WITH_INFO || EXD_ret == SQL_SUCCESS)
- {
- ndbout << "Handle Type is SQL_HANDLE_DESC, but SQL_SUCCESS_WITH_INFO" <<endl;
- ndbout << "appeared. Please check program" << endl;
- ExecDirect_DisplayError(SQL_HANDLE_DESC, EXD_hdesc);
- }
-
- // *********************************
- // ** Disconnect and Free Handles **
- // *********************************
- SQLDisconnect(EXD_hdbc);
- SQLFreeHandle(SQL_HANDLE_STMT, EXD_hstmt);
- SQLFreeHandle(SQL_HANDLE_DBC, EXD_hdbc);
- SQLFreeHandle(SQL_HANDLE_ENV, EXD_henv);
-
- return NDBT_OK;
-
- }
-
-
-void ExecDirect_DisplayError(SQLSMALLINT EXD_HandleType,
- SQLHSTMT EXD_InputHandle)
-{
- SQLCHAR EXD_Sqlstate[5];
- SQLINTEGER EXD_NativeError;
- SQLSMALLINT EXD_i, EXD_MsgLen;
- SQLCHAR EXD_Msg[EXD_MESSAGE_LENGTH];
- SQLRETURN SQLSTATEs;
- EXD_i = 1;
-
- ndbout << "-------------------------------------------------" << endl;
- ndbout << "Error diagnostics:" << endl;
-
- while ((SQLSTATEs = SQLGetDiagRec(EXD_HandleType,
- EXD_InputHandle,
- EXD_i,
- EXD_Sqlstate,
- &EXD_NativeError,
- EXD_Msg,
- sizeof(EXD_Msg),
- &EXD_MsgLen))
- != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << EXD_HandleType << endl;
- ndbout << "the InputHandle is :" << (long)EXD_InputHandle << endl;
- ndbout << "the ColAtt_Msg is: " << (char *) EXD_Msg << endl;
- ndbout << "the output state is:" << (char *)EXD_Sqlstate << endl;
-
- EXD_i ++;
- // break;
- }
- ndbout << "-------------------------------------------------" << endl;
-}
-
-int EXD_Display_Result(SQLHSTMT EXDR_InputHandle)
-{
- SQLRETURN EXD_retcode;
- unsigned long EXD_CustID;
- SQLCHAR EXD_Name[EXD_NAME_LEN], EXD_Phone[EXD_PHONE_LEN];
- SQLCHAR EXD_Address[EXD_ADDRESS_LEN];
-
- //*********************
- //** Bind columns 1 **
- //*********************
- EXD_retcode =SQLBindCol(EXDR_InputHandle,
- 1,
- SQL_C_ULONG,
- &EXD_CustID,
- sizeof(EXD_CustID),
- NULL);
- if (EXD_retcode == SQL_ERROR)
- {
- ndbout << "Executing SQLBindCol, SQL_ERROR happened!" << endl;
- ExecDirect_DisplayError(SQL_HANDLE_STMT, EXDR_InputHandle);
- return NDBT_FAILED;
- }
- //*********************
- //** Bind columns 2 **
- //*********************
-
- EXD_retcode =SQLBindCol(EXDR_InputHandle,
- 2,
- SQL_C_CHAR,
- &EXD_Name,
- EXD_NAME_LEN,
- NULL);
- if (EXD_retcode == SQL_ERROR)
- {
- ndbout << "Executing SQLBindCol, SQL_ERROR happened!" << endl;
- ExecDirect_DisplayError(SQL_HANDLE_STMT, EXDR_InputHandle);
- return NDBT_FAILED;
- }
-
- //*********************
- //** Bind columns 3 **
- //*********************
-
- EXD_retcode = SQLBindCol(EXDR_InputHandle,
- 3,
- SQL_C_CHAR,
- &EXD_Address,
- EXD_ADDRESS_LEN,
- NULL);
-
- if (EXD_retcode == SQL_ERROR)
- {
- ndbout << "Executing SQLBindCol, SQL_ERROR happened!" << endl;
- ExecDirect_DisplayError(SQL_HANDLE_STMT, EXDR_InputHandle);
- return NDBT_FAILED;
- }
-
- //*********************
- //** Bind columns 4 **
- //*********************
-
- EXD_retcode = SQLBindCol(EXDR_InputHandle,
- 4,
- SQL_C_CHAR,
- &EXD_Phone,
- EXD_PHONE_LEN,
- NULL);
-
- if (EXD_retcode == SQL_ERROR)
- {
- ndbout << "Executing SQLBindCol, SQL_ERROR happened!" << endl;
- ExecDirect_DisplayError(SQL_HANDLE_STMT, EXDR_InputHandle);
- return NDBT_FAILED;
- }
-
- //*****************************************
- //* Fetch and print each row of data. On **
- //* an error, display a message and exit **
- //*****************************************
-
- if (EXD_retcode != SQL_ERROR)
- EXD_retcode = SQLFetch(EXDR_InputHandle);
-
- ndbout << endl << "EXD_retcode = SQLFetch(EXDR_InputHandle) = "
- << EXD_retcode << endl;
-
- if (EXD_retcode == SQL_ERROR)
- {
- ndbout << "Executing SQLFetch, SQL_ERROR happened!" << endl;
- ExecDirect_DisplayError(SQL_HANDLE_STMT, EXDR_InputHandle);
- return NDBT_FAILED;
- }
- else if (EXD_retcode == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "CustID = " << (int)EXD_CustID << endl;
- ndbout << "Name = " << (char *)EXD_Name << endl;
- ndbout << "Address = " << (char *)EXD_Address << endl;
- ndbout << "Phone = " << (char *)EXD_Phone << endl;
- ExecDirect_DisplayError(SQL_HANDLE_STMT, EXDR_InputHandle);
- }
- else
- {
- ndbout << "CustID = " << (int)EXD_CustID << endl;
- ndbout << "Name = " << (char *)EXD_Name << endl;
- ndbout << "Address = " << (char *)EXD_Address << endl;
- ndbout << "Phone = " << (char *)EXD_Phone << endl;
- }
- return 0;
-}
diff --git a/storage/ndb/test/odbc/client/SQLExecuteTest.cpp b/storage/ndb/test/odbc/client/SQLExecuteTest.cpp
deleted file mode 100644
index a3250e280e6..00000000000
--- a/storage/ndb/test/odbc/client/SQLExecuteTest.cpp
+++ /dev/null
@@ -1,122 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
- /**
- * @file SQLExecuteTest.cpp
- */
-
-#include <common.hpp>
-#define ESQL_MAXIMUM_MESSAGE_LENGTH 200
-
-using namespace std;
-
-SQLHDBC Ehdbc;
-SQLHSTMT Ehstmt;
-SQLHENV Ehenv;
-SQLHDESC Ehdesc;
-
-void Execute_DisplayError(SQLSMALLINT EHandleType,
- SQLHSTMT EInputHandle);
-
-/**
- * Test to execute a SQL statement in a data result set
- *
- * Tests:
- * -# Test1 There is no executed statement
- * @return Zero, if test succeeded
- */
-int SQLExecuteTest()
-{
-
- SQLRETURN retcode;
- /* hstmt */
- retcode = SQLExecute(Ehstmt);
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_STMT, but SQL_INVALID_HANDLE" << endl;
- ndbout << "still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- Execute_DisplayError(SQL_HANDLE_STMT, Ehstmt);
-
- /* henv */
- retcode = SQLExecute(Ehenv);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS)
- ndbout << "Handle Type is SQL_HANDLE_ENV, but SQL_SUCCESS_WITH_INFO"
- << "still appeared. Please check programm" << endl;
- // Execute_DisplayError(SQL_HANDLE_ENV, Ehenv);
-
- /* hdbc */
- retcode = SQLExecute(Ehdbc);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS)
- ndbout << "Handle Type is SQL_HANDLE_DBC, but SQL_SUCCESS_WITH_INFO"
- <<"still appeared. Please check programm" << endl;
- // Execute_DisplayError(SQL_HANDLE_DBC, Ehdbc);
-
- /* hdesc */
- retcode = SQLExecute(Ehdesc);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS)
- ndbout << "Handle Type is SQL_HANDLE_DESC, but SQL_SUCCESS_WITH_INFO"
- << "still appeared. Please check programm" << endl;
- // Execute_DisplayError(SQL_HANDLE_DESC, Ehdesc);
-
- return NDBT_OK;
-
- }
-
-
-void Execute_DisplayError(SQLSMALLINT EHandleType,
- SQLHSTMT EInputHandle)
-{
- SQLCHAR Sqlstate[5];
-
- SQLINTEGER NativeError;
- SQLSMALLINT i, MsgLen;
- SQLCHAR Msg[ESQL_MAXIMUM_MESSAGE_LENGTH];
- SQLRETURN SQLSTATEs;
- i = 1;
-
- ndbout << "-------------------------------------------------" << endl;
- ndbout << "Error diagnostics:" << endl;
-
- while ((SQLSTATEs = SQLGetDiagRec(EHandleType,
- EInputHandle,
- i,
- Sqlstate,
- &NativeError,
- Msg,
- sizeof(Msg),
- &MsgLen))
- != SQL_NO_DATA)
- {
-
- ndbout << "the HandleType is:" << EHandleType << endl;
- ndbout << "the InputHandle is :" << EInputHandle << endl;
- ndbout << "the Msg is :" << (char *)Msg << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- break;
-
- }
- ndbout << "-------------------------------------------------" << endl;
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLFetchScrollTest.cpp b/storage/ndb/test/odbc/client/SQLFetchScrollTest.cpp
deleted file mode 100644
index 5a5446ca372..00000000000
--- a/storage/ndb/test/odbc/client/SQLFetchScrollTest.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NdbOut.hpp>
-#include <stdio.h>
-#include <sqlext.h>
-
-using namespace std;
-
-#define NAME_LEN 50
-#define PHONE_LEN 10
-#define SALES_PERSON_LEN 10
-#define STATUS_LEN 6
-#define SQL_MAXIMUM_MESSAGE_LENGTH 200
-
-SQLHSTMT hstmt;
-SQLSMALLINT RecNumber;
-SQLCHAR szSalesPerson[SALES_PERSON_LEN];
-
-SQLCHAR Sqlstate[5], Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
-SQLINTEGER NativeError;
-SQLRETURN retcode, SQLSTATEs;
-
-SQLINTEGER ValuePtr1;
-SQLCHAR ValuePtr2;
-SQLSMALLINT ValuePtr3;
-SQLSMALLINT i, MsgLen;
-
-void SFCT_DisplayError(SQLSMALLINT HandleType, SQLHDESC InputHandle);
-
-int SQLFetchScrollTest ()
-{
-
- // FetchScroll a statement to retrieve rows from the Customers table. We can
- // create the table and insert rows in NDB by program TestDirectSQL
-
- /* There is no executed statement associated with the allocated SQL-statement identified by StatementHandle */
-retcode = SQLFetchScroll(hstmt, SQL_FETCH_NEXT, 1);
-if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SFCT_DisplayError(SQL_HANDLE_DESC, hstmt);
-
- /* FetchOrientation is not one of the code values in Table24 */
-retcode = SQLFetchScroll(hstmt, SQL_FETCH_NEXT, 8);
-if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SFCT_DisplayError(SQL_HANDLE_DESC, hstmt);
-
- return 0;
-
- }
-
-
-void SFCT_DisplayError(SQLSMALLINT HandleType, SQLHSTMT InputHandle)
-{
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
-
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLFetchTest.cpp b/storage/ndb/test/odbc/client/SQLFetchTest.cpp
deleted file mode 100644
index 525d37377d3..00000000000
--- a/storage/ndb/test/odbc/client/SQLFetchTest.cpp
+++ /dev/null
@@ -1,438 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
- /**
- * @file SQLFetchTest.cpp
- */
-
-#include <common.hpp>
-#define F_MESSAGE_LENGTH 200
-using namespace std;
-
-#define F_NAME_LEN 20
-#define F_PHONE_LEN 20
-#define F_ADDRESS_LEN 20
-
-SQLHSTMT F_hstmt;
-SQLHDESC F_hdbc;
-SQLHENV F_henv;
-SQLHDESC F_hdesc;
-
-void SQLFetchTest_DisplayError(SQLSMALLINT F_HandleType,
- SQLHDESC F_InputHandle);
-
-/**
- * Test to advance a cursor to the next row of data in a data result set
- * and to retrieve data from any bound columns that exist for that row
- * into their associated application variables
- *
- * Tests:
- * _# Test1 Execute statements and display the results
- * -# Test2 There is no executed statement
- * @return Zero, if test succeeded
- */
-int SQLFetchTest()
-{
- SQLRETURN retcode;
- SQLCHAR SQLStmt[120];
- SQLCHAR SQLStmt1[120];
- SQLCHAR SQLStmt2[120];
- SQLCHAR SQLStmt3[120];
- SQLCHAR SQLStmt4[120];
-
- SQLCHAR F_CustID[20];
- SQLCHAR F_Name[F_NAME_LEN], F_Phone[F_PHONE_LEN];
- SQLCHAR F_Address[F_ADDRESS_LEN];
-
- ndbout << "Start SQLFetch Testing!" << endl;
-
- //************************************
- //** Allocate An Environment Handle **
- //************************************
- retcode = SQLAllocHandle(SQL_HANDLE_ENV,
- SQL_NULL_HANDLE,
- &F_henv);
-
-if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated an environment Handle!" << endl;
-
- //*********************************************
- //** Set the ODBC application Version to 3.x **
- //*********************************************
- retcode = SQLSetEnvAttr(F_henv,
- SQL_ATTR_ODBC_VERSION,
- (SQLPOINTER) SQL_OV_ODBC3,
- SQL_IS_UINTEGER);
-
-if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Set the ODBC application Version to 3.x!" << endl;
-
- //**********************************
- //** Allocate A Connection Handle **
- //**********************************
-
- retcode = SQLAllocHandle(SQL_HANDLE_DBC,
- F_henv,
- &F_hdbc);
-
-if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a connection Handle!" << endl;
-
- // *******************
- // ** Connect to DB **
- // *******************
- retcode = SQLConnect(F_hdbc,
- (SQLCHAR *) connectString(),
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS);
-
-if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Connected to DB : OK!" << endl;
- else
- {
- ndbout << "Failure to Connect DB!" << endl;
- return NDBT_FAILED;
- }
-
- //*******************************
- //** Allocate statement handle **
- //*******************************
-
- retcode = SQLAllocHandle(SQL_HANDLE_STMT,
- F_hdbc,
- &F_hstmt);
-if(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a statement handle!" << endl;
-
- //************************
- //** Define a statement **
- //************************
-
- /* *** CustID is Integer *** */
- strcpy((char *) SQLStmt1, "CREATE TABLE Customers (CustID Integer, Name Char(12), Address Char(12), Phone Char(12), Primary Key(CustID, Name))");
-
- /* *** the primary key is alone *** */
-// strcpy((char *) SQLStmt1, "CREATE TABLE Customers (CustID Integer, Name Char(12), Address Char(12), Phone Char(12), Primary Key(CustID))");
-
- strcpy((char *) SQLStmt2, "INSERT INTO Customers (CustID, Name, Address,Phone) VALUES(188, 'peter','LM Vag8','7190890')");
-
- /* *** CustID is Float *** */
-// strcpy((char *) SQLStmt1,
-// "CREATE TABLE Customers (CustID float, Name Char(12), Address Char(12), Phone Char(12), Primary Key(CustID))");
-// strcpy((char *) SQLStmt2, "INSERT INTO Customers (CustID, Name, Address,Phone) VALUES(1.1516, 'peter','LM Vag8','7190890')");
-
- /* *** CustID is Char *** */
- // strcpy((char *) SQLStmt1, "CREATE TABLE Customers (CustID char(6), Name Char(12), Address Char(12), Phone Char(12), Primary Key(CustID))");
-
- // strcpy((char *) SQLStmt2, "INSERT INTO Customers (CustID, Name, Address,Phone) VALUES('000001', 'peter','LM Vag8','7190890')");
-
- /* The UPDATE statements */
- // strcpy((char *) SQLStmt3, "UPDATE Customers SET Phone = '98998' WHERE CustID = 1.1516");
-
- // strcpy((char *) SQLStmt3, "UPDATE Customers SET Phone = '98998' WHERE CustID = '000001'");
-
- // strcpy((char *) SQLStmt3, "UPDATE Customers SET Phone = '98998' WHERE CustID = 188");
-
- strcpy((char *) SQLStmt3, "UPDATE Customers SET Phone = '98998' WHERE CustID = 188 AND Name = 'peter'");
-
- // DELETE statements
-
- // DELETE all records
- // strcpy((char *) SQLStmt4, "DELETE FROM Customers");
-
- // DELETE One record
- // strcpy((char *) SQLStmt4, "DELETE FROM Customers WHERE CustID = 1.1516");
- // strcpy((char *) SQLStmt4, "DELETE FROM Customers WHERE CustID = '000001'");
- // strcpy((char *) SQLStmt4, "DELETE FROM Customers WHERE CustID = 188 AND Name = 'peter'");
- // strcpy((char *) SQLStmt4, "DELETE FROM Customers WHERE CustID = 188");
-
- strcpy((char *) SQLStmt4, "DELETE FROM Customers WHERE CustID = 188 AND Name = 'peter'");
-
- //SELECT statements
- strcpy((char *) SQLStmt, "SELECT * FROM Customers");
-
- //********************************
- //** Prepare CREATE statements **
- //********************************
-
- ndbout << ">>>>" << (char*)SQLStmt1 << "<<<<" << endl;
- retcode = SQLPrepare(F_hstmt,
- SQLStmt1,
- SQL_NTS);
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SQLFetchTest_DisplayError(SQL_HANDLE_STMT, F_hstmt);
-
- //******************************************************************
- //** There is no executed statement associated with the allocated **
- //** SQL-statement identified by StatementHandle **
- //******************************************************************
-
- //This function is correct after testing. We don't test again.
- /*
- retcode = SQLFetch(F_hstmt);
- ndbout << endl << "retcode = SQLFetch(F_hstmt) = " << retcode << endl;
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "There is no executed statement associated with" << endl;
- ndbout << "the allocated SQL-statement" << endl;
- SQLFetchTest_DisplayError(SQL_HANDLE_DESC, F_hstmt);
-
- }
- */
-
- //*******************************
- //** Execute CREATE statement **
- //*******************************
-
- retcode = SQLExecute(F_hstmt);
-
- if (retcode == 0)
- ndbout << endl << "Execute CREATE TABLE Statement OK!" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SQLFetchTest_DisplayError(SQL_HANDLE_STMT, F_hstmt);
-
- //********************************
- //** Prepare INSERT statements **
- //********************************
-
- ndbout << ">>>>" << (char*)SQLStmt2 << "<<<<" << endl;
- retcode = SQLPrepare(F_hstmt,
- SQLStmt2,
- SQL_NTS);
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SQLFetchTest_DisplayError(SQL_HANDLE_STMT, F_hstmt);
-
-
- //******************************
- //** Execute INSERT statement **
- //******************************
- retcode = SQLExecute(F_hstmt);
-
- if (retcode == 0)
- ndbout << endl <<"Execute INSERT Statement OK!" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SQLFetchTest_DisplayError(SQL_HANDLE_STMT, F_hstmt);
-
- //********************************
- //** Prepare UPDATE statements **
- //********************************
-
- ndbout << ">>>>" << (char*)SQLStmt3 << "<<<<" << endl;
- retcode = SQLPrepare(F_hstmt,
- SQLStmt3,
- SQL_NTS);
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SQLFetchTest_DisplayError(SQL_HANDLE_STMT, F_hstmt);
-
- //******************************
- //** Execute UPDATE statement **
- //******************************
- retcode = SQLExecute(F_hstmt);
-
- if (retcode == 0)
- ndbout << endl <<"Execute UPDATE Statement OK!" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SQLFetchTest_DisplayError(SQL_HANDLE_STMT, F_hstmt);
-
- //********************************
- //** Prepare DELETE statements **
- //********************************
- ndbout << ">>>>" << (char*)SQLStmt4 << "<<<<" << endl;
- retcode = SQLPrepare(F_hstmt,
- SQLStmt4,
- SQL_NTS);
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << endl << "Preparing DELETE Statement failure!" << endl;
- SQLFetchTest_DisplayError(SQL_HANDLE_STMT, F_hstmt);
- }
-
- //******************************
- //** Execute DELETE statement **
- //******************************
-
- retcode = SQLExecute(F_hstmt);
-
- if (retcode == 0)
- ndbout << endl <<"Execute DELETE Statement OK!" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "DELETE Statement executing failure!" << endl;
- SQLFetchTest_DisplayError(SQL_HANDLE_STMT, F_hstmt);
- }
- //********************************
- //** Prepare SELECT statements **
- //********************************
- ndbout << ">>>>" << (char*)SQLStmt << "<<<<" << endl;
- retcode = SQLPrepare(F_hstmt,
- SQLStmt,
- SQL_NTS);
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SQLFetchTest_DisplayError(SQL_HANDLE_STMT, F_hstmt);
-
- /*
- //******************************
- //** Execute SELECT statement **
- //******************************
-
- retcode = SQLExecute(F_hstmt);
-
- if (retcode == 0)
- ndbout << endl <<"Execute SELECT Statement OK!" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SQLFetchTest_DisplayError(SQL_HANDLE_STMT, F_hstmt);
- */
-
- //********************
- //** Bind columns **
- //********************
-
- retcode =SQLBindCol(F_hstmt,
- 1,
- SQL_C_CHAR,
- F_CustID,
- sizeof(F_CustID),
- NULL);
- ndbout << endl << "Bind Col1 retcode = " << retcode << " OK!" << endl;
-
- retcode =SQLBindCol(F_hstmt,
- 2,
- SQL_C_CHAR,
- F_Name,
- F_NAME_LEN,
- NULL);
-
- ndbout << "Bind Col2 retcode = " << retcode << " OK!" << endl;
-
- retcode = SQLBindCol(F_hstmt,
- 3,
- SQL_C_CHAR,
- F_Address,
- F_ADDRESS_LEN,
- NULL);
-
- ndbout << "Bind Col3 retcode = " << retcode << " OK!" << endl;
-
- retcode = SQLBindCol(F_hstmt,
- 4,
- SQL_C_CHAR,
- F_Phone,
- F_PHONE_LEN,
- NULL);
-
- ndbout << "Bind Col4 retcode = " << retcode << " OK!" << endl;
-
- //******************************
- //** Execute SELECT statement **
- //******************************
-
- retcode = SQLExecute(F_hstmt);
-
- if (retcode == 0)
- ndbout << endl <<"Execute SELECT Statement OK!" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SQLFetchTest_DisplayError(SQL_HANDLE_STMT, F_hstmt);
-
- //***************
- //* Fetch data **
- //***************
- ndbout << endl <<"Executing Fetch SELECT Statement ......" << endl;
-
- retcode = SQLFetch(F_hstmt);
-
- if (retcode == 100)
- ndbout << endl <<"Execute Fetch SELECT Statement, But No DATA!" << endl;
-
- if (retcode == 0)
- ndbout << endl <<"Execute Fetch SELECT Statement OK!" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SQLFetchTest_DisplayError(SQL_HANDLE_STMT, F_hstmt);
-
- //*******************
- //* Display result **
- //*******************
- ndbout << endl << "The results is : " << endl;
- ndbout << "CustID = " << (char *)F_CustID << endl;
- ndbout << "Name = " << (char *)F_Name << endl;
- ndbout << "Address = " << (char *)F_Address << endl;
- ndbout << "Phone = " << (char *)F_Phone << endl;
-
-
- // *********************************
- // ** Disconnect and Free Handles **
- // *********************************
- SQLDisconnect(F_hdbc);
- SQLFreeHandle(SQL_HANDLE_STMT, F_hstmt);
- SQLFreeHandle(SQL_HANDLE_DBC, F_hdbc);
- SQLFreeHandle(SQL_HANDLE_ENV, F_henv);
-
- return NDBT_OK;
-
- }
-
-
-void SQLFetchTest_DisplayError(SQLSMALLINT F_HandleType,
- SQLHSTMT F_InputHandle)
-{
- SQLCHAR Sqlstate[50], Msg[F_MESSAGE_LENGTH];
- SQLRETURN SQLSTATEs;
- SQLINTEGER NativeError;
- SQLSMALLINT i, MsgLen;
- Msg[0] = 0;
- i = 1;
-
- ndbout << "-------------------------------------------------" << endl;
- ndbout << "Error diagnostics:" << endl;
-
- while ((SQLSTATEs = SQLGetDiagRec(F_HandleType,
- F_InputHandle,
- i,
- Sqlstate,
- &NativeError,
- Msg,
- sizeof(Msg),
- &MsgLen))
- != SQL_NO_DATA)
-{
-
- ndbout << "the HandleType is:" << F_HandleType << endl;
- ndbout << "the InputHandle is :" <<(long)F_InputHandle << endl;
- ndbout << "the Msg is :" << (char *)Msg << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- break;
-}
- ndbout << "-------------------------------------------------" << endl;
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLFreeHandleTest.cpp b/storage/ndb/test/odbc/client/SQLFreeHandleTest.cpp
deleted file mode 100644
index 8e43d12318b..00000000000
--- a/storage/ndb/test/odbc/client/SQLFreeHandleTest.cpp
+++ /dev/null
@@ -1,195 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include "common.h"
-#define SQL_MAXIMUM_MESSAGE_LENGTH 200
-
-using namespace std;
-
-SQLHDBC hdbc;
-SQLHSTMT hstmt;
-SQLHENV henv;
-SQLHDESC hdesc;
-SQLRETURN retcode, SQLSTATEs;
-int strangehandle;
-
-SQLCHAR Sqlstate[5];
-
-SQLINTEGER NativeError;
-SQLSMALLINT i, MsgLen;
-
-
-void freehandle_deal_with_HSTMT(SQLSMALLINT HandleType, SQLHSTMT InputHandle);
-void freehandle_deal_with_HENV(SQLSMALLINT HandleType, SQLHENV InputHandle);
-void freehandle_deal_with_HDESC(SQLSMALLINT HandleType, SQLHDESC InputHandle);
-void freehandle_deal_with_HDBC(SQLSMALLINT HandleType, SQLHDBC InputHandle);
-
-void freehandle_DisplayError_HDBC(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHDBC InputHandle);
-void freehandle_DisplayError_HSTMT(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHSTMT InputHandle);
-void freehandle_DisplayError_HENV(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHENV InputHandle);
-void freehandle_DisplayError_HDESC(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHDESC InputHandle);
-
-int SQLFreeHandleTest ()
-{
-
-strangehandle = 67;
-
-/* ENV */
-ndbout << "Environment Handle" << endl;
-SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
-freehandle_deal_with_HENV(SQL_HANDLE_ENV, henv);
-
-/* DBC */
-ndbout << "Connection Handle" << endl;
-SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
-SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
-freehandle_deal_with_HDBC(SQL_HANDLE_DBC, hdbc);
-
-/* STMT */
-ndbout << "Statement Handle" << endl;
-SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
-SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
-freehandle_deal_with_HSTMT(SQL_HANDLE_STMT, hstmt);
-
-/* DESC */
-ndbout << "Descriptor Handle" << endl;
-SQLAllocHandle(SQL_HANDLE_DESC, hdbc, &hdesc);
-freehandle_deal_with_HDESC(SQL_HANDLE_DESC, hdesc);
-
-return 0;
-
-}
-
-
-void freehandle_deal_with_HDBC(SQLSMALLINT HandleType, SQLHDBC InputHandle)
-{
- SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
- retcode = SQLFreeHandle(HandleType, InputHandle);
-
- ndbout << "the HandleType is : " << HandleType << endl;
- ndbout << "the InputHandle is SQLHDBC:" << InputHandle << endl;
- ndbout << "retcode = " << retcode << endl;
- /*
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
- DisplayError_HDBC_free(Sqlstate, HandleType, InputHandle);
-
- i ++;
- }
- }
- */
- }
-
-
-void freehandle_deal_with_HSTMT(SQLSMALLINT HandleType, SQLHSTMT InputHandle)
-{
- SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
- retcode = SQLFreeHandle(HandleType, InputHandle);
-
- ndbout << "the HandleType is : " << HandleType << endl;
- ndbout << "the InputHandle is SQLHSTMT:" << InputHandle << endl;
- ndbout << "retcode = " << retcode << endl;
- /*
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
- DisplayError_HSTMT_free(Sqlstate, HandleType, InputHandle);
-
- i ++;
- }
- }
- */
- }
-
-void freehandle_deal_with_HENV(SQLSMALLINT HandleType, SQLHENV InputHandle)
-{
- SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
- retcode = SQLFreeHandle(HandleType, InputHandle);
-
- ndbout << "the HandleType is : " << HandleType << endl;
- ndbout << "the InputHandle is SQLHENV:" << InputHandle << endl;
- ndbout << "retcode = " << retcode << endl;
- /*
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- DisplayError_HENV_free(Sqlstate, HandleType, InputHandle);
-
- i ++;
- }
- }
- */
- }
-
-void freehandle_deal_with_HDESC(SQLSMALLINT HandleType, SQLHDESC InputHandle)
-{
- SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
- retcode = SQLFreeHandle(HandleType, InputHandle);
-
- ndbout << "the HandleType is : " << HandleType << endl;
- ndbout << "the InputHandle is SQLHDESC:" << InputHandle << endl;
- ndbout << "retcode = " << retcode << endl;
- /*
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- DisplayError_HDESC_free(Sqlstate, HandleType, InputHandle);
-
- i ++;
- }
- }
- */
- }
-
-
-void freehandle_DisplayError_HENV(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHENV InputHandle)
-{
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-}
-
-void freehandle_DisplayError_HDBC(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHDBC InputHandle)
-{
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-}
-
-void freehandle_DisplayError_HSTMT(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHSTMT InputHandle)
-{
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-}
-
-void freehandle_DisplayError_HDESC(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHDESC InputHandle)
-{
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-}
diff --git a/storage/ndb/test/odbc/client/SQLFreeStmtTest.cpp b/storage/ndb/test/odbc/client/SQLFreeStmtTest.cpp
deleted file mode 100644
index 771a35de2b0..00000000000
--- a/storage/ndb/test/odbc/client/SQLFreeStmtTest.cpp
+++ /dev/null
@@ -1,182 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <common.h>
-#define SQL_MAXIMUM_MESSAGE_LENGTH 200
-
-using namespace std;
-
-SQLHDBC hdbc;
-SQLHSTMT hstmt;
-SQLHENV henv;
-SQLHDESC hdesc;
-SQLRETURN retcode, SQLSTATEs;
-int strange_handle;
-
-SQLCHAR Sqlstate[5];
-
-SQLINTEGER NativeError;
-SQLSMALLINT i, MsgLen;
-
-struct handle_set
-{
-SQLHDBC hdbc_varible;
-SQLHSTMT hstmt_varible;
-SQLHENV henv_varible;
-SQLHDESC hdesc_varible;
-int strangehandle;
-};
-handle_set handlevalue;
-
-void handle_deal_with_HSTMT(SQLSMALLINT HandleType, SQLHSTMT InputHandle);
-void handle_deal_with_HENV(SQLSMALLINT HandleType, SQLHENV InputHandle);
-void handle_deal_with_HDESC(SQLSMALLINT HandleType, SQLHDESC InputHandle);
-void handle_deal_with_HDBC(SQLSMALLINT HandleType, SQLHDBC InputHandle);
-
-void DisplayError_HDBC(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHDBC InputHandle);
-void DisplayError_HSTMT(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHSTMT InputHandle);
-void DisplayError_HENV(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHENV InputHandle);
-void DisplayError_HDESC(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHDESC InputHandle);
-
-int SQLFreeStmtTest ()
-{
-
-handlevalue.hdbc_varible = hdbc;
-handlevalue.hstmt_varible = hstmt;
-handlevalue.henv_varible = henv;
-handlevalue.hdesc_varible = hdesc;
-handlevalue.strangehandle = 67;
-
-
-/* ENV */
-handle_deal_with_HENV(SQL_HANDLE_ENV, SQL_NULL_HANDLE);
-
-/* DBC */
-handle_deal_with_HDBC(SQL_HANDLE_DBC, SQL_NULL_HANDLE);
-
-/* STMT */
-handle_deal_with_HSTMT(SQL_HANDLE_STMT, SQL_NULL_HANDLE);
-
-/* DESC */
-handle_deal_with_HDESC(SQL_HANDLE_DESC, SQL_NULL_HANDLE);
-
-return 0;
-
-}
-
-
-void handle_deal_with_HDBC(SQLSMALLINT HandleType, SQLHDBC InputHandle)
-{
- SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
- retcode = SQLFreeHandle(HandleType, InputHandle);
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
- DisplayError_HDBC(Sqlstate, HandleType, InputHandle);
-
- i ++;
- }
- }
- }
-
-
-void handle_deal_with_HSTMT(SQLSMALLINT HandleType, SQLHSTMT InputHandle)
-{
- SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
- retcode = SQLFreeHandle(HandleType, InputHandle);
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
- DisplayError_HSTMT(Sqlstate, HandleType, InputHandle);
-
- i ++;
- }
- }
- }
-
-void handle_deal_with_HENV(SQLSMALLINT HandleType, SQLHENV InputHandle)
-{
- SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
- retcode = SQLFreeHandle(HandleType, InputHandle);
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- DisplayError_HENV(Sqlstate, HandleType, InputHandle);
-
- i ++;
- }
- }
- }
-
-void handle_deal_with_HDESC(SQLSMALLINT HandleType, SQLHDESC InputHandle)
-{
- SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
- retcode = SQLFreeHandle(HandleType, InputHandle);
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- DisplayError_HDESC(Sqlstate, HandleType, InputHandle);
-
- i ++;
- }
- }
- }
-
-
-void DisplayError_HENV(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHENV InputHandle)
-{
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-}
-
-
-void DisplayError_HDBC(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHDBC InputHandle)
-{
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-}
-
-void DisplayError_HSTMT(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHSTMT InputHandle)
-{
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-}
-
-void DisplayError_HDESC(SQLCHAR Sqlstate[6], SQLSMALLINT HandleType, SQLHDESC InputHandle)
-{
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-}
-
-
diff --git a/storage/ndb/test/odbc/client/SQLGetConnectAttrTest.cpp b/storage/ndb/test/odbc/client/SQLGetConnectAttrTest.cpp
deleted file mode 100644
index d62d782b201..00000000000
--- a/storage/ndb/test/odbc/client/SQLGetConnectAttrTest.cpp
+++ /dev/null
@@ -1,131 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <common.h>
-#define SQL_MAXIMUM_MESSAGE_LENGTH 200
-
-using namespace std;
-
-SQLHDBC hdbc;
-SQLHSTMT hstmt;
-SQLHENV henv;
-SQLHDESC hdesc;
-SQLRETURN retcode, SQLSTATEs;
-
-SQLPOINTER ValuePtr;
-SQLINTEGER GetConnectAttr_StringLengthPtr;
-
-SQLCHAR Sqlstate[5];
-
-SQLINTEGER NativeError;
-SQLSMALLINT i, MsgLen;
-SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
-
-void GetConnectAttr_DisplayError(SQLSMALLINT HandleType, SQLHENV InputHandle);
-
-int SQLGetConnectAttrTest()
-{
- /* SQL/CLI attributes */
- // char PtrValue1[2] = {'SQL_TRUE', 'SQL_FALSE'};
- // for (i=0; i < 2; i++) {
- retcode = SQLGetConnectAttr(hdbc, SQL_ATTR_AUTO_IPD, ValuePtr, 36, &GetConnectAttr_StringLengthPtr);
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_DBC, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- GetConnectAttr_DisplayError(SQL_HANDLE_DBC, hdbc); // }
-
- /* ODBC attributes */
- /*
- char PtrValue1[3] = {'SQL_MODE_READ_ONLY', 'SQL_MODE_READ_WRITE'};
- for (i=0; i < 3; i++) {
- retcode = SQLGetConnectAttr(hdbc, SQL_ATTR_ACCESS_MODE, (void*)PtrValue1[i], sizeof(PtrValue1[i]));
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_DBC, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- GetConnectAttr_DisplayError(SQL_HANDLE_DBC, hdbc);}
-
-
- char PtrValue2[2] = {'SQL_ASYNC_ENABLE_OFF', 'SQL_ASYNC_ENABLE_ON'};
- for (i=0; i < 2; i++) {
- retcode = SQLSetConnectAttr(hdbc, SQL_ATTR_ASYNC_ENABLE, (void*)PtrValue2[i], sizeof(PtrValue2[i]));
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_DBC, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- GetConnectAttr_DisplayError(SQL_HANDLE_DBC, hdbc);}
-
-
- char PtrValue4[2] = {'SQL_AUTOCOMMIT_OFF', 'SQL_AUTOCOMMIT_ON'};
- for (i=0; i < 2; i++) {
- retcode = SQLGetConnectAttr(hdbc, SQL_ATTR_AUTOCOMMIT, (void*)PtrValue4[i], sizeof(PtrValue4[i]));
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_DBC, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- GetConnectAttr_DisplayError(SQL_HANDLE_DBC, hdbc);}
-
- char PtrValue5[2] = {'SQL_CD_TRUE', 'SQL_CD_FALSE'};
- for (i=0; i < 2; i++) {
- retcode = SQLGetConnectAttr(hdbc, SQL_ATTR_CONNECTION_DEAD, (void*)PtrValue4[i], sizeof(PtrValue5[i]));
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_DBC, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- GetConnectAttr_DisplayError(SQL_HANDLE_DBC, hdbc);}
-
-
- char PtrValue5[2] = {'SQL_CD_TRUE', 'SQL_CD_FALSE'};
- for (i=0; i < 2; i++) {
- retcode = SQLGetConnectAttr(hdbc, SQL_ATTR_CONNECTION_TIMEOUT, (void*)PtrValue4[i], sizeof(PtrValue5[i]));
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_DBC, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- GetConnectAttr_DisplayError(SQL_HANDLE_DBC, hdbc);}
-
- */
-
- return 0;
-
- }
-
-
-void GetConnectAttr_DisplayError(SQLSMALLINT HandleType, SQLHENV InputHandle)
-{
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
-
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLGetCursorNameTest.cpp b/storage/ndb/test/odbc/client/SQLGetCursorNameTest.cpp
deleted file mode 100644
index efd3d1d370b..00000000000
--- a/storage/ndb/test/odbc/client/SQLGetCursorNameTest.cpp
+++ /dev/null
@@ -1,221 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
- /**
- * @file SQLGetCursorNameTest.cpp
- */
-
-#include <common.hpp>
-using namespace std;
-
-#define GCN_MESSAGE_LENGTH 50
-
-SQLHSTMT GCN_hstmt;
-SQLHDESC GCN_hdesc;
-SQLHENV GCN_henv;
-SQLHDBC GCN_hdbc;
-
-void GCN_DisplayError(SQLSMALLINT GCN_HandleType,
- SQLHDESC GCN_InputHandle);
-
-/**
- * Test to assign a user-defined name to a cursor that is
- * associated with an active SQL statement handle
- *
- * Tests:
- * -# if there is no user-defined cursor name, then try to
- * get user-definedcursor name
- * -# get cursor name in normal case
- *
- * @return Zero, if test succeeded
- */
-
-int SQLGetCursorNameTest()
-{
- SQLRETURN retcode;
- SQLCHAR SQLStmt [120];
- SQLCHAR CursorName [80];
- SQLSMALLINT CNameSize;
-
- ndbout << endl << "Start SQLGetCursorName Testing" << endl;
-
- //************************************
- //** Allocate An Environment Handle **
- //************************************
- retcode = SQLAllocHandle(SQL_HANDLE_ENV,
- SQL_NULL_HANDLE,
- &GCN_henv);
-
-if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated an environment Handle!" << endl;
-
- //*********************************************
- //** Set the ODBC application Version to 3.x **
- //*********************************************
- retcode = SQLSetEnvAttr(GCN_henv,
- SQL_ATTR_ODBC_VERSION,
- (SQLPOINTER) SQL_OV_ODBC3,
- SQL_IS_UINTEGER);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Set the ODBC application Version to 3.x!" << endl;
-
- //**********************************
- //** Allocate A Connection Handle **
- //**********************************
-
- retcode = SQLAllocHandle(SQL_HANDLE_DBC,
- GCN_henv,
- &GCN_hdbc);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a connection Handle!" << endl;
-
- // *******************
- // ** Connect to DB **
- // *******************
- retcode = SQLConnect(GCN_hdbc,
- (SQLCHAR *) connectString(),
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Connected to DB : OK!" << endl;
- else
- {
- ndbout << "Failure to Connect DB!" << endl;
- return NDBT_FAILED;
- }
- //*******************************
- //** Allocate statement handle **
- //*******************************
-
- retcode = SQLAllocHandle(SQL_HANDLE_STMT,
- GCN_hdbc,
- &GCN_hstmt);
-
- if(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a statement handle!" << endl;
-
- //************************
- //** Define a statement **
- //************************
-
- strcpy((char *) SQLStmt,
- "SELECT * FROM Customers WHERE Address = 'LM Vag 8'");
-
- //*************************
- //** Prepare a statement **
- //*************************
-
- retcode = SQLPrepare(GCN_hstmt,
- SQLStmt,
- SQL_NTS);
-
- //*************************************************************************
- //** if there is no user-defined cursor name, try to get the cursor name **
- //*************************************************************************
- retcode = SQLGetCursorName(GCN_hstmt,
- CursorName,
- sizeof(CursorName),
- &CNameSize);
-
- if (retcode != SQL_SUCCESS)
- {
- ndbout << endl << "retcode =" << retcode << endl;
- GCN_DisplayError(SQL_HANDLE_STMT, GCN_hstmt);
- }
- else
- ndbout << endl << "The cursor name is : " << (char *) CursorName << endl;
-
- //*************************
- //** Set the cursor name **
- //*************************
- retcode = SQLSetCursorName(GCN_hstmt,
- (char *)"Customer_CURSOR",
- SQL_NTS);
-
- //***************************
- //** Execute the statement **
- //***************************
- retcode = SQLExecute(GCN_hstmt);
-
- //**********************************************
- //** retrieve and display the new cursor name **
- //**********************************************
- retcode = SQLGetCursorName(GCN_hstmt,
- CursorName,
- sizeof(CursorName),
- &CNameSize);
-
- if (retcode != SQL_SUCCESS)
- {
- ndbout << endl << "retcode =" << retcode << endl;
- GCN_DisplayError(SQL_HANDLE_STMT, GCN_hstmt);
- }
- else
- ndbout << endl << "The cursor name is : " << (char *) CursorName << endl;
-
- //****************
- // Free Handles **
- //****************
- SQLDisconnect(GCN_hdbc);
- SQLFreeHandle(SQL_HANDLE_STMT, GCN_hstmt);
- SQLFreeHandle(SQL_HANDLE_DBC, GCN_hdbc);
- SQLFreeHandle(SQL_HANDLE_ENV, GCN_henv);
-
- return NDBT_OK;
-
- }
-
-
-void GCN_DisplayError(SQLSMALLINT GCN_HandleType, SQLHDESC GCN_InputHandle)
-{
-
- SQLINTEGER NativeError;
- SQLCHAR Sqlstate[5], Msg[GCN_MESSAGE_LENGTH];
- SQLRETURN SQLSTATEs;
- SQLSMALLINT i, MsgLen;
- i = 1;
-
- ndbout << "-------------------------------------------------" << endl;
- ndbout << "Error diagnostics:" << endl;
-
- while ((SQLSTATEs = SQLGetDiagRec(GCN_HandleType,
- GCN_InputHandle, i,
- Sqlstate,
- &NativeError,
- Msg,
- sizeof(Msg),
- &MsgLen))
- != SQL_NO_DATA)
- {
-
- ndbout << "the HandleType is:" << GCN_HandleType << endl;
- ndbout << "the InputHandle is :" << (long)GCN_InputHandle << endl;
- ndbout << "the Msg is: " << (char *) Msg << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
- ndbout << "-------------------------------------------------" << endl;
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLGetDataTest.cpp b/storage/ndb/test/odbc/client/SQLGetDataTest.cpp
deleted file mode 100644
index 1ab32e383e2..00000000000
--- a/storage/ndb/test/odbc/client/SQLGetDataTest.cpp
+++ /dev/null
@@ -1,358 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
- /**
- * @file SQLGetDataTest.cpp
- */
-
-#include <common.hpp>
-using namespace std;
-
-#define GD_MESSAGE_LENGTH 200
-
-SQLHSTMT GD_hstmt;
-SQLHENV GD_henv;
-SQLHDBC GD_hdbc;
-SQLHDESC GD_hdesc;
-
-void GetData_DisplayError(SQLSMALLINT GD_HandleType, SQLHSTMT GD_InputHandle);
-
-/**
- * Test to retrieve data for a single unbound column
- * in the current row of a result data set
- *
- * Tests:
- * -# Test1 There is no fetched rowset associated with S
- * -# Test2 column number is less than zero
- * -# Test3 fetched rowset is empty
- * @return Zero, if test succeeded
- */
-
-int SQLGetDataTest()
-{
- SQLRETURN retcode;
- SQLCHAR ColumnName;
- SQLINTEGER CustID;
- // SQLCHAR Name, Address, Phone;
- SQLCHAR SQLStmt [120];
- SQLCHAR SQLStmt1 [120];
-
- //************************************
- //** Allocate An Environment Handle **
- //************************************
- retcode = SQLAllocHandle(SQL_HANDLE_ENV,
- SQL_NULL_HANDLE,
- &GD_henv);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated an environment Handle!" << endl;
-
- //*********************************************
- //** Set the ODBC application Version to 3.x **
- //*********************************************
- retcode = SQLSetEnvAttr(GD_henv,
- SQL_ATTR_ODBC_VERSION,
- (SQLPOINTER) SQL_OV_ODBC3,
- SQL_IS_UINTEGER);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Set the ODBC application Version to 3.X!" << endl;
-
- //**********************************
- //** Allocate A Connection Handle **
- //**********************************
-
- retcode = SQLAllocHandle(SQL_HANDLE_DBC,
- GD_henv,
- &GD_hdbc);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a connection Handle!" << endl;
-
- // *******************
- // ** Connect to DB **
- // *******************
- retcode = SQLConnect(GD_hdbc,
- (SQLCHAR *) connectString(),
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Connected to DB : OK!" << endl;
- else
- {
- ndbout << "Failure to Connect DB!" << endl;
- return NDBT_FAILED;
- }
-
- //*******************************
- //** Allocate statement handle **
- //*******************************
-
- retcode = SQLAllocHandle(SQL_HANDLE_STMT,
- GD_hdbc,
- &GD_hstmt);
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a statement handle!" << endl;
-
- //*****************************
- //** Define SELECT statement **
- //*****************************
-
- strcpy((char *) SQLStmt, "SELECT * FROM Customers");
-
-
- //***********************************
- //** Prepare SELECT SQL statement **
- //***********************************
-
- retcode = SQLPrepare(GD_hstmt,
- SQLStmt,
- SQL_NTS);
- ndbout << endl << "Preparing SELECT, retcode = SQLprepare()= "
- << retcode << endl;
-
- //*********************************
- //** Execute prepared statement **
- //*********************************
-
- // if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- //{
-
- retcode = SQLExecute(GD_hstmt);
-
- ndbout << "Exexuting SELECT, retcode = SQLExecute()= "
- << retcode << endl;
-
- // if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- // {
-
- //*****************************************************************
- //** Test1 **
- //** There is no fetched rowset associated with S(SQL-statement) **
- //*****************************************************************
-
- retcode = SQLGetData(GD_hstmt,
- 1,
- SQL_C_SLONG,
- &CustID,
- sizeof(CustID),
- NULL);
- ndbout << "retcode = SQLGetData()= " << retcode << endl;
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << endl << "Test 1:" << endl;
- ndbout << "There is no fetched rowset associated with SQL"
- << " statement. But system reported SUCCESS or"
- << " SUCCESS_WITH_INFO. Please check the function!" << endl;
- GetData_DisplayError(SQL_HANDLE_STMT, GD_hstmt);
- }
- else if (retcode == SQL_ERROR)
- {
- ndbout << endl << "Test 1:" << endl;
- ndbout << "There is no fetched rowset associated with SQL"
- << " statement. The system reported ERROR "
- << " The function is OK!" << endl;
- }
- else
- ndbout << endl;
-
- //*******************************
- //** Fetch Data from database **
- //*******************************
-
- retcode = SQLFetch(GD_hstmt);
-
- ndbout << endl
- << "Fetching after Executing SELECT, retcode = SQLFetch()= "
- << retcode << endl;
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- {
-
- //**************************************
- //** Test2 **
- //** column number is less than zero **
- //**************************************
-
- retcode = SQLGetData(GD_hstmt,
- 0,
- SQL_C_ULONG,
- &CustID,
- sizeof(CustID),
- NULL);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "Test 2:" <<"Column number is less than zero"
- << " The system reported SUCCESS or SUCCESS_WITH_INFO."
- << " Check the function, please!" <<endl;
- GetData_DisplayError(SQL_HANDLE_STMT, GD_hstmt);
- }
- else if (retcode == SQL_ERROR)
- {
- ndbout << "Test 2:" << "Column number is less than zero."
- << " The system reported SQL_ERROR."
- << " The function is OK!" << endl;
- }
- else
- ndbout << endl;
- }
- // }
-
- // }
-
- //*****************************
- //** Define DELETE statement **
- //*****************************
-
- // strcpy((char *) SQLStmt1, "DELETE FROM Customers");
- strcpy((char *) SQLStmt1, "DELETE FROM Customers WHERE CustID = 568 AND Name = 'Hans Peter'");
-
- //***********************************
- //** Prepare DELETE SQL statement **
- //***********************************
-
- retcode = SQLPrepare(GD_hstmt,
- SQLStmt1,
- SQL_NTS);
- ndbout << endl << "Preparing DELETE, retcode = SQLPrepare()= "
- << retcode << endl;
-
- //****************************************
- //** Execute prepared DELETE statement **
- //****************************************
-
- // if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- // {
-
- retcode = SQLExecute(GD_hstmt);
-
- ndbout << "Executing DELETE, retcode = SQLExecute()= "
- << retcode << endl;
-
- // if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- // {
-
- retcode = SQLFetch(GD_hstmt);
-
- ndbout << "Fetching after Executing DELETE, retcode = SQLExecute()= "
- << retcode << endl;
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- {
-
- //******************************************************
- //** Test3 **
- //** If the fetched rowset associated with **
- //** Statement is empty, condition is raised: NO DATA **
- //** We can delete all rows in table Customers for **
- //** this case **
- //******************************************************
-
- retcode = SQLGetData(GD_hstmt,
- 1,
- SQL_C_ULONG,
- &CustID,
- sizeof(CustID),
- NULL);
-
- if (retcode == SQL_ERROR)
- {
- ndbout << "Test 3:" << endl;
- ndbout << "The fetched rowset associated"
- << "with Statementhandle is empty. The system"
- << " reported SQL_ERROR. Check the function!" << endl;
- GetData_DisplayError(SQL_HANDLE_STMT, GD_hstmt);
- }
- else if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "Test 3:" << endl;
- ndbout << "The fetched rowset associated"
- << "with Statementhandle is empty. The system"
- << " reported SUCCESS. Check the function!" << endl;
- GetData_DisplayError(SQL_HANDLE_STMT, GD_hstmt);
- }
- else if (retcode == 100)
- {
- ndbout << "Test 3:" << endl;
- ndbout << "The fetched rowset associated"
- << "with Statementhandle is empty. The system"
- << " reported SQL_NO_DATA. The function is OK!" << endl;
- }
- }
- else if (retcode == SQL_ERROR)
- {
- ndbout << "Test 3 falied!" << endl;
- GetData_DisplayError(SQL_HANDLE_STMT, GD_hstmt);
- }
- else
- ndbout << " " << endl;
-
- // }
- // }
-
- // *********************************
- // ** Disconnect and Free Handles **
- // *********************************
- SQLDisconnect(GD_hdbc);
- SQLFreeHandle(SQL_HANDLE_STMT, GD_hstmt);
- SQLFreeHandle(SQL_HANDLE_DBC, GD_hdbc);
- SQLFreeHandle(SQL_HANDLE_ENV, GD_henv);
-
- return NDBT_OK;
-}
-
-void GetData_DisplayError(SQLSMALLINT GD_HandleType, SQLHSTMT GD_InputHandle)
-{
-
- SQLSMALLINT i, MsgLen;
- SQLRETURN SQLSTATEs;
- SQLCHAR Sqlstate[5], Msg[GD_MESSAGE_LENGTH];
- SQLINTEGER NativeError;
- i = 1;
-
- ndbout << "-------------------------------------------------" << endl;
- ndbout << "Error diagnostics:" << endl;
-
- while ((SQLSTATEs = SQLGetDiagRec(GD_HandleType,
- GD_InputHandle,
- i,
- Sqlstate,
- &NativeError,
- Msg,
- sizeof(Msg),
- &MsgLen))
- != SQL_NO_DATA)
- {
-
- ndbout << "the HandleType is:" << GD_HandleType << endl;
- ndbout << "the InputHandle is :" << (long)GD_InputHandle << endl;
- ndbout << "Phone = " << (char *)Msg << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- break;
- }
- ndbout << "-------------------------------------------------" << endl;
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLGetDescFieldTest.cpp b/storage/ndb/test/odbc/client/SQLGetDescFieldTest.cpp
deleted file mode 100644
index 1072cd0fbb0..00000000000
--- a/storage/ndb/test/odbc/client/SQLGetDescFieldTest.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NdbOut.hpp>
-#include <sqlext.h>
-#include <stdio.h>
-
-using namespace std;
-
-#define NAME_LEN 50
-#define PHONE_LEN 10
-#define SALES_PERSON_LEN 10
-#define STATUS_LEN 6
-#define SQL_MAXIMUM_MESSAGE_LENGTH 200
-
-SQLHSTMT hstmt;
-SQLHDESC hdesc;
-
-SQLSMALLINT RecNumber;
-SQLCHAR szSalesPerson[SALES_PERSON_LEN];
-
-SQLCHAR Sqlstate[5], Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
-SQLINTEGER NativeError;
-SQLRETURN retcode, SQLSTATEs;
-
-SQLINTEGER ValuePtr1;
-SQLCHAR ValuePtr2;
-SQLSMALLINT ValuePtr3;
-
-
-
-SQLINTEGER StringLengthPtr;
-
-SQLSMALLINT i, MsgLen;
-
-void SQLGetDescFieldTest_DisplayError(SQLSMALLINT HandleType, SQLHDESC InputHandle);
-
-int SQLGetDescFieldTest()
-{
-
- /* If MBR is 'PS' and there is no prepared or execute statement associated with S*/
-retcode = SQLGetDescField(hdesc, 1, SQL_DESC_ARRAY_SIZE, &ValuePtr1, 128, &StringLengthPtr);
-if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SQLGetDescFieldTest_DisplayError(SQL_HANDLE_DESC, hdesc);
-
- /* hstmt */
- // SQLPrepare a statement to select rows from the ORDERS Table. We can create the
- // table and inside rows in NDB by another program TestDirectSQL. In this test
- // program(SQLGetDescRecTest),we only have three rows in table ORDERS
-
-/* Prepare the SQL statement with parameter markers. */
-retcode = SQLPrepare(hstmt, (SQLCHAR *)"SELECT ORDERID, CUSTID, OPENDATE, SALESPERSON, STATUS FROM ORDERS)", SQL_NTS);
-
-/* SELECT OrderID, CustID, OpenDate, SalesPerson from Table ORDERS */
-
-if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
-
-
- /* If FI(FieldIdentifer) is not one of the code values in Table 20 */
-retcode = SQLGetDescField(hdesc, 1, 9999, &ValuePtr1, 128, &StringLengthPtr);
-if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SQLGetDescFieldTest_DisplayError(SQL_HANDLE_DESC, hdesc);
-
-
- /* RecoderNumber is less than 1 */
-retcode = SQLGetDescField(hdesc, -1, SQL_DESC_ARRAY_SIZE, &ValuePtr1, 128, &StringLengthPtr);
-if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SQLGetDescFieldTest_DisplayError(SQL_HANDLE_DESC, hdesc);
-
- /* RecoderNumber is greater than N, N be the value of the COUNT field of D, D be the allocated CLI */
- /* descriptor area identified by DescriptorHandle */
-retcode = SQLGetDescField(hdesc, 4, SQL_DESC_ARRAY_SIZE, &ValuePtr1, 128, &StringLengthPtr);
-if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SQLGetDescFieldTest_DisplayError(SQL_HANDLE_DESC, hdesc);
-
-}
-
- return 0;
-
- }
-
-
-void SQLGetDescFieldTest_DisplayError(SQLSMALLINT HandleType, SQLHDESC InputHandle)
-{
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
-
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLGetDescRecTest.cpp b/storage/ndb/test/odbc/client/SQLGetDescRecTest.cpp
deleted file mode 100644
index f442100139a..00000000000
--- a/storage/ndb/test/odbc/client/SQLGetDescRecTest.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <common.h>
-
-using namespace std;
-
-#define NAME_LEN 50
-#define PHONE_LEN 10
-#define SALES_PERSON_LEN 10
-#define STATUS_LEN 6
-#define SQL_MAXIMUM_MESSAGE_LENGTH 200
-
-SQLHSTMT hstmt;
-SQLHDESC hdesc;
-
-SQLSMALLINT RecNumber;
-SQLCHAR szSalesPerson[SALES_PERSON_LEN];
-
-SQLCHAR Sqlstate[5], Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
-SQLINTEGER NativeError;
-SQLRETURN retcode, SQLSTATEs;
-
-SQLCHAR Name;
-SQLINTEGER LengthPtr;
-SQLSMALLINT SGDR_StringLengthPtr, TypePtr, SubTypePtr, PrecisionPtr, ScalePtr, NullablePtr;
-
-SQLSMALLINT i, MsgLen;
-
-void SQLGetDescRec_DisplayError(SQLSMALLINT HandleType, SQLHDESC InputHandle);
-
-int SQLGetDescRecTest()
-{
-
- /* hstmt */
- // SQLPrepare a statement to select rows from the ORDERS Table. We can create the table and inside rows in
- // NDB by another program TestDirectSQL. In this test program(SQLGetDescRecTest),we only have three rows in
- // table ORDERS
-
-/* Prepare the SQL statement with parameter markers. */
-retcode = SQLPrepare(hstmt, (SQLCHAR *)"SELECT ORDERID, CUSTID, OPENDATE, SALESPERSON, STATUS FROM ORDERS)", SQL_NTS);
-
-/* SELECT OrderID, CustID, OpenDate, SalesPerson from Table ORDERS */
-
-if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
-
- /* RecoderNumber is less than 1 */
-retcode = SQLGetDescRec(hdesc, -1, &Name, sizeof(Name), &SGDR_StringLengthPtr, &TypePtr, &SubTypePtr, &LengthPtr, &PrecisionPtr, &ScalePtr, &NullablePtr);
-if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SQLGetDescRec_DisplayError(SQL_HANDLE_DESC, hdesc);
-
- /* RecoderNumber is greater than N, N be the value of the COUNT field of D, D be the allocated CLI */
- /* descriptor area identified by DescriptorHandle */
-retcode = SQLGetDescRec(hdesc, 4, &Name, sizeof(Name), &SGDR_StringLengthPtr, &TypePtr, &SubTypePtr, &LengthPtr, &PrecisionPtr, &ScalePtr, &NullablePtr);
-if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SQLGetDescRec_DisplayError(SQL_HANDLE_DESC, hdesc);
-
-}
-
- return 0;
-
- }
-
-
-void SQLGetDescRec_DisplayError(SQLSMALLINT HandleType, SQLHDESC InputHandle)
-{
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
-
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLGetDiagFieldTest.cpp b/storage/ndb/test/odbc/client/SQLGetDiagFieldTest.cpp
deleted file mode 100644
index 9038cc83a2d..00000000000
--- a/storage/ndb/test/odbc/client/SQLGetDiagFieldTest.cpp
+++ /dev/null
@@ -1,236 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NdbOut.hpp>
-#include <sqlcli.h>
-#include <stdio.h>
-
-using namespace std;
-
-SQLHDBC hdbc;
-SQLHSTMT hstmt;
-SQLHENV henv;
-SQLHDESC hdesc;
-SQLINTEGER strangehandle;
-SQLRETURN retcode, SQLSTATEs;
-
-SQLCHAR Sqlstate[5];
-
-SQLINTEGER NativeError;
-SQLSMALLINT i, MsgLen;
-SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
-
-SQLSMALLINT StringLengthPtr;
-SQLINTEGER DiagInfoPtr1;
-SQLCHAR DiagInfoPtr2;
-SQLRETURN DiagInfoPtr3;
-
-void DisplayError(SQLSMALLINT HandleType, SQLHSTMT InputHandle);
-
-int SQLGetDiagFieldTest ()
-{
-
- strangehandle = 67;
- /* hstmt */
- // Execute a statement to retrieve rows from the Customers table. We can create the table and inside rows in
- // NDB by another program TestDirectSQL
- // const SQLCHAR *StatementText = "SELECT CustID, Name, Address, Phone FROM Customers";
- // retcode = SQLPrepare(hstmt, (SQLCHAR*)"SELECT CustID, Name, Address, Phone FROM Customers", 56);
-
- retcode = SQLPrepare(hstmt, (SQLCHAR*)"SELECT CustID, Name, Address, Phone FROM Customers", SQL_NTS);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS) {
- i = 1;
-while ((SQLSTATEs = SQLGetDiagField(67, 67, i, SQL_DIAG_CURSOR_ROW_COUNT, &DiagInfoPtr1, 128, &StringLengthPtr)) != SQL_NO_DATA) {
- if (SQLSTATEs == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
- }
- i ++;
- }
- }
-
-
- /* HandleType indicates ENVIRNMENT HANDLE and Handle does not identify an allocated SQL_environment */
-
- retcode = SQLPrepare(hstmt, (SQLCHAR*)"SELECT CustID, Name, Address, Phone FROM Customers", SQL_NTS);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS) {
- i = 1;
-while ((SQLSTATEs = SQLGetDiagField(SQL_HANDLE_ENV, hdbc, i, SQL_DIAG_CURSOR_ROW_COUNT, &DiagInfoPtr1, 128, &StringLengthPtr)) != SQL_NO_DATA) {
- if (SQLSTATEs == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
- }
- i ++;
- }
- }
-
-
- /* HandleType indicates CONNECTION HANDLE and Handle does not identify an allocated SQL_connection */
-
- retcode = SQLPrepare(hstmt, (SQLCHAR*)"SELECT CustID, Name, Address, Phone FROM Customers", SQL_NTS);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS) {
- i = 1;
-while ((SQLSTATEs = SQLGetDiagField(SQL_HANDLE_DBC, henv, i, SQL_DIAG_CURSOR_ROW_COUNT, &DiagInfoPtr1, 128, &StringLengthPtr)) != SQL_NO_DATA) {
- if (SQLSTATEs == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
- }
- i ++;
- }
- }
-
- /* HandleType indicates STATEMENT HANDLE and Handle does not identify an allocated SQL_statement */
-
- retcode = SQLPrepare(hstmt, (SQLCHAR*)"SELECT CustID, Name, Address, Phone FROM Customers", SQL_NTS);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS) {
- i = 1;
-while ((SQLSTATEs = SQLGetDiagField(SQL_HANDLE_STMT, hdbc, i, SQL_DIAG_CURSOR_ROW_COUNT, &DiagInfoPtr1, 128, &StringLengthPtr)) != SQL_NO_DATA) {
- if (SQLSTATEs == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
- }
- i ++;
- }
- }
-
- /* HandleType indicates DESCRIPTOR HANDLE and Handle does not identify an allocated SQL_descriptor */
-
- retcode = SQLPrepare(hstmt, (SQLCHAR*)"SELECT CustID, Name, Address, Phone FROM Customers", SQL_NTS);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS) {
- i = 1;
-while ((SQLSTATEs = SQLGetDiagField(SQL_HANDLE_DESC, hdbc, i, SQL_DIAG_CURSOR_ROW_COUNT, &DiagInfoPtr1, 128, &StringLengthPtr)) != SQL_NO_DATA) {
- if (SQLSTATEs == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
- }
- i ++;
- }
- }
-
- /* DiagIdentifer is not one of the code values in Table12 */
-
- retcode = SQLPrepare(hstmt, (SQLCHAR*)"SELECT CustID, Name, Address, Phone FROM Customers", SQL_NTS);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS) {
-
-where ((SQLSTATEs = SQLGetDiagField(SQL_HANDLE_DBC, hdbc, -1, 99, &DiagInfoPtr1, 128, &StringLengthPtr)) != SQL_NO_DATA) {
-
- if (SQLSTATEs == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
- }
- i ++;
- }
- }
- /* If TYPE is 'STATUS' and RN is greater than N */
-
- retcode = SQLPrepare(hstmt, (SQLCHAR*)"SELECT CustID, Name, Address, Phone FROM Customers", SQL_NTS);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS) {
-
-where ((SQLSTATEs = SQLGetDiagField(SQL_HANDLE_DBC, hdbc, 9999, 8, &DiagInfoPtr2, 128, &StringLengthPtr)) != SQL_NO_DATA) {
-
- if (SQLSTATEs == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
- }
- i ++;
- }
- }
-
-
- /* If TYPE is 'STATUS' and RN is less than 1 */
-
- retcode = SQLPrepare(hstmt, (SQLCHAR*)"SELECT CustID, Name, Address, Phone FROM Customers", SQL_NTS);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS) {
-
- where ((SQLSTATEs = SQLGetDiagField(SQL_HANDLE_DBC, hdbc, -1, 8, &DiagInfoPtr2, 128, &StringLengthPtr)) != SQL_NO_DATA) {
-
- if (SQLSTATEs == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
- }
- i ++;
- }
- }
-
- /* If DI indicates ROW_COUNT and R is neither Execute nor ExecDirect, then an exception condition is raised */
-
- retcode = SQLPrepare(hstmt, (SQLCHAR*)"SELECT CustID, Name, Address, Phone FROM Customers", SQL_NTS);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS) {
-
-where ((SQLSTATEs = SQLGetDiagField(SQL_HANDLE_DBC, hdbc, i, SQL_DIAG_ROW_COUNT, &DiagInfoPtr1, 128, &StringLengthPtr)) != SQL_NO_DATA) {
-
- if (SQLSTATEs == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
- }
- i ++;
- }
- }
-
-
- return 0;
-
- }
-
-
-
-
-
-void DisplayError(SQLSMALLINT HandleType, SQLHSTMT InputHandle)
-{
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
-
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLGetDiagRecSimpleTest.cpp b/storage/ndb/test/odbc/client/SQLGetDiagRecSimpleTest.cpp
deleted file mode 100644
index 003524b72af..00000000000
--- a/storage/ndb/test/odbc/client/SQLGetDiagRecSimpleTest.cpp
+++ /dev/null
@@ -1,167 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
- /**
- * @file SQLGetDiagRecSimpleTest.cpp
- */
-#include <common.hpp>
-#include <string.h>
-
-using namespace std;
-
-SQLHDBC GDS_hdbc;
-SQLHSTMT GDS_hstmt;
-SQLHENV GDS_henv;
-SQLHDESC GDS_hdesc;
-SQLRETURN GDS_retcode, GDS_RETURN;
-
-#define GDS_SQL_MAXIMUM_MESSAGE_LENGTH 255
-SQLCHAR GDS_Sqlstate[5];
-
-SQLINTEGER GDS_NativeError;
-SQLSMALLINT GDS_i = 1, GDS_MsgLen;
-SQLCHAR GDS_Msg[GDS_SQL_MAXIMUM_MESSAGE_LENGTH], GDS_ConnectIn[30];
-
-/**
- * Test SQLGetDiagRec return value
- *
- * -#Simply test Msg when return is SQL_NO_DATA
- * -#Simply test Msg when return is SQL_SUCCESS
- * -#Simply test Msg when return is SQL_SUCCESS_WITH_INFO
- * -#Simply test Msg when return is SQL_INVALID_HANDLE
- * -#Simply test Msg when return is SQL_ERROR
- *
- * @return Zero, if test succeeded
- */
-
-int SQLGetDiagRecSimpleTest()
-{
- ndbout << endl << "Start SQLGetDiagRec Simple Testing" << endl;
-
- //************************************
- //** Allocate An Environment Handle **
- //************************************
-
- GDS_retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &GDS_henv);
- if (GDS_retcode == SQL_SUCCESS || GDS_retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated An Environment Handle!" << endl;
-
- //*********************************************
- //** Set the ODBC application Version to 3.x **
- //*********************************************
-
- GDS_retcode = SQLSetEnvAttr(GDS_henv,
- SQL_ATTR_ODBC_VERSION,
- (SQLPOINTER) SQL_OV_ODBC3,
- SQL_IS_UINTEGER);
-
- if (GDS_retcode == SQL_SUCCESS || GDS_retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Set the ODBC application Version to 3.x!" << endl;
-
- //**********************************
- //** Allocate A Connection Handle **
- //**********************************
-
- GDS_retcode = SQLAllocHandle(SQL_HANDLE_DBC, GDS_henv, &GDS_hdbc);
-
- if (GDS_retcode == SQL_SUCCESS || GDS_retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated A Connection Handle!" << endl;
-
- // *******************
- // ** Connect to DB **
- // *******************
-
- GDS_retcode = SQLConnect(GDS_hdbc,
- (SQLCHAR *) connectString(),
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS);
-
- if (GDS_retcode == SQL_SUCCESS || GDS_retcode == SQL_SUCCESS_WITH_INFO){
- ndbout << "Success connection to DB!" << endl;
- ndbout << "GDS_retcode = " << GDS_retcode << endl;
- ndbout << "SQL_SUCCESS = " << SQL_SUCCESS << endl;
- ndbout << "SQL_SUCCESS_WITH_INFO = " << SQL_SUCCESS_WITH_INFO << endl;}
-
- ndbout << endl;
-
- ndbout << "-------------------------------------------------" << endl;
- ndbout << "Error diagnostics:" << endl;
-
- if (GDS_retcode != SQL_SUCCESS || GDS_retcode != SQL_SUCCESS_WITH_INFO){
- ndbout << "GDS_retcode = " << GDS_retcode << endl;
- ndbout << "SQL_SUCCESS = " << SQL_SUCCESS << endl;
- ndbout << "SQL_SUCCESS_WITH_INFO = " << SQL_SUCCESS_WITH_INFO << endl;
-
- GDS_RETURN = SQLGetDiagRec(SQL_HANDLE_DBC,
- GDS_hdbc,
- GDS_i,
- GDS_Sqlstate,
- &GDS_NativeError,
- GDS_Msg,
- sizeof(GDS_Msg),
- &GDS_MsgLen);
-
- if (GDS_RETURN == SQL_NO_DATA){
- ndbout << "GDS_SQLSTATES = SQL_NO_DATA" << endl;
- ndbout << "the HandleType is:" << SQL_HANDLE_DBC << endl;
- ndbout << "the Handle is :" << (long)GDS_hdbc << endl;
- ndbout << "the GDS_Msg is :" << (char *)GDS_Msg << endl;
- ndbout << "the sqlstate is:" << (char *)GDS_Sqlstate << endl;}
-
- else if (GDS_RETURN == SQL_SUCCESS){
- ndbout << "GDS_SQLSTATES = SQL_SUCCESS" << endl;
- ndbout << "the HandleType is:" << SQL_HANDLE_DBC << endl;
- ndbout << "the Handle is :" << (long)GDS_hdbc << endl;
- ndbout << "the GDS_Msg is :" << (char *)GDS_Msg << endl;
- ndbout << "the sqlstate is:" << (char *)GDS_Sqlstate << endl;}
-
- else if (GDS_RETURN == SQL_SUCCESS_WITH_INFO){
- ndbout << "GDS_SQLSTATES = SQL_SUCCESS_WITH_INFO" << endl;
- ndbout << "the HandleType is:" << SQL_HANDLE_DBC << endl;
- ndbout << "the Handle is :" << (long)GDS_hdbc << endl;
- ndbout << "the GDS_Msg is :" << (char *)GDS_Msg << endl;
- ndbout << "the sqlstate is:" << (char *)GDS_Sqlstate << endl;}
-
- else if (GDS_RETURN == SQL_INVALID_HANDLE){
- ndbout << "GDS_SQLSTATES = SQL_INVALID_HANDLE" << endl;
- ndbout << "the HandleType is:" << SQL_HANDLE_DBC << endl;
- ndbout << "the Handle is :" << (long)GDS_hdbc << endl;
- ndbout << "the GDS_Msg is :" << (char *)GDS_Msg << endl;
- ndbout << "the sqlstate is:" << (char *)GDS_Sqlstate << endl;}
-
- else{
- ndbout << "GDS_RETURN = SQL_ERROR" << endl;
- ndbout << "the HandleType is:" << SQL_HANDLE_DBC << endl;
- ndbout << "the Handle is :" << (long)GDS_hdbc << endl;
- ndbout << "the GDS_Msg is :" << (char *)GDS_Msg << endl;
- ndbout << "the sqlstate is:" << (char *)GDS_Sqlstate << endl;
- }
- }
- ndbout << "-------------------------------------------------" << endl;
-
- //******************
- //** Free Handles **
- //******************
- SQLDisconnect(GDS_hdbc);
- SQLFreeHandle(SQL_HANDLE_STMT, GDS_hstmt);
- SQLFreeHandle(SQL_HANDLE_DBC, GDS_hdbc);
- SQLFreeHandle(SQL_HANDLE_ENV, GDS_henv);
- return NDBT_OK;
- }
-
diff --git a/storage/ndb/test/odbc/client/SQLGetDiagRecTest.cpp b/storage/ndb/test/odbc/client/SQLGetDiagRecTest.cpp
deleted file mode 100644
index 7c2c1c21bef..00000000000
--- a/storage/ndb/test/odbc/client/SQLGetDiagRecTest.cpp
+++ /dev/null
@@ -1,207 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NdbOut.hpp>
-#include <sqlcli.h>
-#include <stdio.h>
-
-using namespace std;
-
-SQLHDBC hdbc;
-SQLHSTMT hstmt;
-SQLHENV henv;
-SQLHDESC hdesc;
-SQLINTEGER strangehandle;
-SQLRETURN retcode, SQLSTATEs;
-
-SQLCHAR Sqlstate[5];
-
-SQLINTEGER NativeError;
-SQLSMALLINT i, MsgLen;
-SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
-
-void DisplayError(SQLSMALLINT HandleType, SQLHSTMT InputHandle);
-
-int SQLGetDiagRecTest()
-{
-
- strangehandle = 67;
- /* hstmt */
- // Execute a statement to retrieve rows from the Customers table. We can create the table and inside rows in
- // NDB by another program TestDirectSQL
- // const SQLCHAR *StatementText = "SELECT CustID, Name, Address, Phone FROM Customers";
-
- // retcode = SQLPrepare(hstmt, (SQLCHAR*)"SELECT CustID, Name, Address, Phone FROM Customers", 56);
-
- retcode = SQLPrepare(hstmt, (SQLCHAR*)"SELECT CustID, Name, Address, Phone FROM Customers", SQL_NTS);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS) {
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(67, 67, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
- if (SQLSTATEs == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
- }
- i ++;
- }
- }
-
-
- /* HandleType indicates ENVIRNMENT HANDLE and Handle does not identify an allocated SQL_environment */
-
- retcode = SQLPrepare(hstmt, (SQLCHAR*)"SELECT CustID, Name, Address, Phone FROM Customers", SQL_NTS);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS) {
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(SQL_HANDLE_ENV, hdbc, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
- if (SQLSTATEs == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
- }
- i ++;
- }
- }
-
-
- /* HandleType indicates CONNECTION HANDLE and Handle does not identify an allocated SQL_connection */
-
- retcode = SQLPrepare(hstmt, (SQLCHAR*)"SELECT CustID, Name, Address, Phone FROM Customers", SQL_NTS);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS) {
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(SQL_HANDLE_DBC, henv, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
- if (SQLSTATEs == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
- }
- i ++;
- }
- }
-
- /* HandleType indicates STATEMENT HANDLE and Handle does not identify an allocated SQL_statement */
-
- retcode = SQLPrepare(hstmt, (SQLCHAR*)"SELECT CustID, Name, Address, Phone FROM Customers", SQL_NTS);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS) {
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(SQL_HANDLE_STMT, hdbc, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
- if (SQLSTATEs == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
- }
- i ++;
- }
- }
-
- /* HandleType indicates DESCRIPTOR HANDLE and Handle does not identify an allocated SQL_descriptor */
-
- retcode = SQLPrepare(hstmt, (SQLCHAR*)"SELECT CustID, Name, Address, Phone FROM Customers", SQL_NTS);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS) {
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(SQL_HANDLE_DESC, hdbc, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
- if (SQLSTATEs == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
- }
- i ++;
- }
- }
-
-
- /* RecordNumber is less than one */
-
- retcode = SQLPrepare(hstmt, (SQLCHAR*)"SELECT CustID, Name, Address, Phone FROM Customers", SQL_NTS);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS) {
-
- where ((SQLSTATEs = SQLGetDiagRec(SQL_HANDLE_DBC, hdbc, -1,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- if (SQLSTATEs == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
- }
- i ++;
- }
- }
- /* RecordNumber is greater than N */
-
- retcode = SQLPrepare(hstmt, (SQLCHAR*)"SELECT CustID, Name, Address, Phone FROM Customers", SQL_NTS);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS) {
-
- where ((SQLSTATEs = SQLGetDiagRec(SQL_HANDLE_DBC, hdbc, 9999,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- if (SQLSTATEs == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
- }
- i ++;
- }
- }
-
-
- return 0;
-
- }
-
-
-void DisplayError(SQLSMALLINT HandleType, SQLHSTMT InputHandle)
-{
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
-
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLGetEnvAttrTest.cpp b/storage/ndb/test/odbc/client/SQLGetEnvAttrTest.cpp
deleted file mode 100644
index 6a0ca9656bd..00000000000
--- a/storage/ndb/test/odbc/client/SQLGetEnvAttrTest.cpp
+++ /dev/null
@@ -1,110 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <common.h>
-#define SQL_MAXIMUM_MESSAGE_LENGTH 200
-
-using namespace std;
-
-SQLHDBC hdbc;
-SQLHSTMT hstmt;
-SQLHENV henv;
-SQLHDESC hdesc;
-SQLRETURN retcode, SQLSTATEs;
-
-SQLPOINTER ValuePtr;
-SQLINTEGER GetEnvAttr_StringLengthPtr;
-
-SQLCHAR Sqlstate[5];
-
-SQLINTEGER NativeError;
-SQLSMALLINT i, MsgLen;
-SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
-
-void GetEnvAttr_DisplayError(SQLSMALLINT HandleType, SQLHENV InputHandle);
-
-int SQLGetEnvAttrTest()
-{
- /* ODBC attributres */
-
- /*
- // char PtrValue1[3] = {'SQL_CP_OFF', 'SQL_CP_ONE_DRIVER', 'SQL_CP_ONE_PER_HENV'};
- // for (i=0; i < 3; i++) {
- retcode = SQLGetEnvAttr(henv, SQL_ATTR_CONNECTION_POOLING, ValuePtr, 36, &GetEnvAttr_StringLengthPtr);
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_ENV, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- GetEnvAttr_DisplayError(SQL_HANDLE_ENV, henv); // }
-
-
- // char PtrValue2[2] = {'SQL_CP_STRICT_MATCH', 'SQL_CP_RELAXED_MATCH'};
- // for (i=0; i < 2; i++) {
- retcode = SQLGetEnvAttr(henv, SQL_ATTR_CP_MATCH, ValuePtr, 36, &GetEnvAttr_StringLengthPtr);
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_ENV, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- GetEnvAttr_DisplayError(SQL_HANDLE_ENV, henv); // }
-
-
- // char PtrValue3[2] = {'SQL_OV_ODBC3', 'SQL_OV_ODBC2'};
- // for (i=0; i < 2; i++) {
- retcode = SQLGetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, ValuePtr, 36, &GetEnvAttr_StringLengthPtr );
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_ENV, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- GetEnvAttr_DisplayError(SQL_HANDLE_ENV, henv); // }
-
- */
-
- // char PtrValue4[2] = {'SQL_TRUE', 'SQL_FALSE'};
- // for (i=0; i < 2; i++) {
- retcode = SQLGetEnvAttr(henv, SQL_ATTR_OUTPUT_NTS, ValuePtr, 36, &GetEnvAttr_StringLengthPtr);
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_ENV, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- GetEnvAttr_DisplayError(SQL_HANDLE_ENV, henv); // }
-
- return 0;
-
- }
-
-
-void GetEnvAttr_DisplayError(SQLSMALLINT HandleType, SQLHENV InputHandle)
-{
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
-
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLGetFunctionsTest.cpp b/storage/ndb/test/odbc/client/SQLGetFunctionsTest.cpp
deleted file mode 100644
index 58181a0caa9..00000000000
--- a/storage/ndb/test/odbc/client/SQLGetFunctionsTest.cpp
+++ /dev/null
@@ -1,284 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
- /**
- * @file SQLGetFunctionsTest.cpp
- */
-
-
-#include <common.hpp>
-#define GF_MESSAGE_LENGTH 200
-
-using namespace std;
-
-SQLHDBC GF_hdbc;
-SQLHSTMT GF_hstmt;
-SQLHENV GF_henv;
-
-void SQLGetFunctions_DisplayError(SQLSMALLINT GF_HandleType,
- SQLHDBC GF_InputHandle);
-
-/**
- * Test whether a specific ODBC API function is supported by
- * the driver an application is currently connected to.
- *
- * In this test program, we can change ODBC function values in order to
- * know different which fuction is supported by ODBC drivers
- * Tests:
- * -# Test1 There is no established SQL-connection
- * -# Test2 ConnectionHandle does not identify an allocated SQL-connection
- * -# Test3 The value of FunctionId is not in table 27
- * -# Test4 Normal case test
- * @return Zero, if test succeeded
- */
-
-int SQLGetFunctionsTest()
-{
- SQLUSMALLINT TableExists, Supported;
- SQLCHAR SQLStmt [120];
- SQLRETURN retcode;
-
- ndbout << endl << "Start SQLGetFunctions Testing" << endl;
-
- //**********************************************************
- //** Test 1 **
- //** If there is no established SQL-connection associated **
- //** with allocated SQL-connection **
- //**********************************************************
-
- retcode = SQLGetFunctions(GF_hdbc, SQL_API_SQLTABLES, &TableExists);
- if (retcode == -2)
-{
- ndbout << endl << "Test 1" << endl;
- ndbout << "retcode = " << retcode << endl;
- ndbout << endl << "There is no established SQL-connection" << endl;
- ndbout << "associated with allocated SQL_connection" << endl;
- SQLGetFunctions_DisplayError(SQL_HANDLE_STMT, GF_hstmt);
-}
- else if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
-{
- ndbout << endl << "Test 1" << endl;
- ndbout << "retcode = " << retcode << endl;
- ndbout << endl << "There is no established SQL-connection" << endl;
- ndbout << "associated with allocated SQL_connection" << endl;
- SQLGetFunctions_DisplayError(SQL_HANDLE_STMT, GF_hstmt);
-}
- else
-{
- ndbout << endl << "Test 1" << endl;
- ndbout << "retcode = " << retcode << endl;
- ndbout << endl << "There is no established SQL-connection" << endl;
- ndbout << "associated with allocated SQL_connection" << endl;
- SQLGetFunctions_DisplayError(SQL_HANDLE_STMT, GF_hstmt);
-}
-
- //************************************
- //** Allocate An Environment Handle **
- //************************************
- retcode = SQLAllocHandle(SQL_HANDLE_ENV,
- SQL_NULL_HANDLE,
- &GF_henv);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated an environment Handle!" << endl;
-
- //*********************************************
- //** Set the ODBC application Version to 3.x **
- //*********************************************
- retcode = SQLSetEnvAttr(GF_henv,
- SQL_ATTR_ODBC_VERSION,
- (SQLPOINTER) SQL_OV_ODBC3,
- SQL_IS_UINTEGER);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Set the ODBC application Version to 3.X!" << endl;
-
- //**********************************
- //** Allocate A Connection Handle **
- //**********************************
-
- retcode = SQLAllocHandle(SQL_HANDLE_DBC,
- GF_henv,
- &GF_hdbc);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a connection Handle!" << endl;
-
- // *******************
- // ** Connect to DB **
- // *******************
- retcode = SQLConnect(GF_hdbc,
- (SQLCHAR*) connectString(),
- SQL_NTS,
- (SQLCHAR*) "",
- SQL_NTS,
- (SQLCHAR*) "",
- SQL_NTS);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
-{
-
- //*************************************************************
- //** Test 2 **
- //** If ConnectionHandle does not identify an allocated **
- //** SQL-connection, then an exception condition is raised **
- //*************************************************************
- retcode = SQLGetFunctions(GF_hdbc, SQL_API_SQLTABLES, &TableExists);
- if (retcode == -2)
-{
- ndbout << endl << "Test 2" << endl;
- ndbout << "retcode = " << retcode << endl;
- ndbout << "If ConnectionHandle does not identify an allocated" << endl;
- ndbout << "SQL-connection,an exception condition is raised" << endl;
- SQLGetFunctions_DisplayError(SQL_HANDLE_STMT, GF_hstmt);
-}
- else if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
-{
- ndbout << endl << "Test 2" << endl;
- ndbout << "retcode = " << retcode << endl;
- ndbout << "If ConnectionHandle does not identify an allocated" << endl;
- ndbout << "SQL-connection,an exception condition is raised" << endl;
- SQLGetFunctions_DisplayError(SQL_HANDLE_STMT, GF_hstmt);
-}
- else
-{
- ndbout << endl << "Test 2 :" << endl;
- ndbout << "retcode = " << retcode << endl;
- ndbout << "If ConnectionHandle does not identify an allocated" << endl;
- ndbout << "SQL-connection,an exception condition is raised" << endl;
- SQLGetFunctions_DisplayError(SQL_HANDLE_STMT, GF_hstmt);
-}
-
- //*************************************************************
- //** Test 3 **
- //** If the value of FunctionId is not in table 27, "Codes **
- //** used to identify SQL/CLI routines" **
- //*************************************************************
-
- retcode = SQLGetFunctions(GF_hdbc, 88888, &TableExists);
- ndbout<< "TableExists = " << TableExists << endl;
- if (retcode == -2)
-{
- ndbout << "retcode = " << retcode << endl;
- ndbout << "Test 3 : The value of FunctionId is not in table 27" << endl;
- SQLGetFunctions_DisplayError(SQL_HANDLE_STMT, GF_hstmt);
-}
- else if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
-{
- ndbout << "retcode = " << retcode << endl;
- ndbout << "Test 3 : The value of FunctionId is not in table 27" << endl;
- SQLGetFunctions_DisplayError(SQL_HANDLE_STMT, GF_hstmt);
-}
- else
-{
- ndbout << "retcode = " << retcode << endl;
- ndbout << "Test 3 : The value of FunctionId is not in table 27" << endl;
- SQLGetFunctions_DisplayError(SQL_HANDLE_STMT, GF_hstmt);
-}
-
- //******************
- //** Test 4 **
- //** Normal case **
- //******************
- ndbout << "Test 4:" << endl;
- retcode = SQLGetFunctions(GF_hdbc, SQL_API_SQLBROWSECONNECT, &Supported);
- ndbout << "retcode = " << retcode << endl;
- if (Supported == TRUE)
-{
- ndbout << "Supported = " << Supported << endl;
- ndbout << "SQLBrowseConnect is supported by the current data source"
- << endl;
-}
- else
-{
- ndbout << "Supported = " << Supported << endl;
- ndbout << "SQLBrowseConnect isn't supported by the current data source"
- << endl;
-}
-
-
- //******************
- //** Test 5 **
- //** Normal case **
- //******************
- ndbout << endl << "Test 5:" << endl;
- retcode = SQLGetFunctions(GF_hdbc, SQL_API_SQLFETCH, &Supported);
- ndbout << "retcode = " << retcode << endl;
- if (Supported == TRUE)
-{
- ndbout << "Supported = " << Supported << endl;
- ndbout << "SQLFETCH is supported by the current data source" << endl;
-}
- else
-{
- ndbout << "Supported = " << Supported << endl;
- ndbout << "SQLFETCH isn't supported by the current data source" << endl;
-}
-
-}
-
- // *********************************
- // ** Disconnect and Free Handles **
- // *********************************
- SQLDisconnect(GF_hdbc);
- SQLFreeHandle(SQL_HANDLE_STMT, GF_hstmt);
- SQLFreeHandle(SQL_HANDLE_DBC, GF_hdbc);
- SQLFreeHandle(SQL_HANDLE_ENV, GF_henv);
-
- return NDBT_OK;
-
-}
-
-
-void SQLGetFunctions_DisplayError(SQLSMALLINT GF_HandleType,
- SQLHDBC GF_InputHandle)
-{
- SQLRETURN SQLSTATEs;
- SQLCHAR Sqlstate[50];
- SQLINTEGER NativeError;
- SQLSMALLINT i, MsgLen;
- SQLCHAR Msg[GF_MESSAGE_LENGTH];
- i = 1;
-
- ndbout << "-------------------------------------------------" << endl;
- ndbout << "Error diagnostics:" << endl;
-
- Msg[0] = 0;
- while ((SQLSTATEs = SQLGetDiagRec(GF_HandleType,
- GF_InputHandle,
- i,
- Sqlstate,
- &NativeError,
- Msg,
- sizeof(Msg),
- &MsgLen))
- != SQL_NO_DATA)
- {
-
- ndbout << "the HandleType is:" << GF_HandleType << endl;
- ndbout << "the InputHandle is :" << (long)GF_InputHandle << endl;
- ndbout << "the Msg is :" << (char *) Msg << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- Msg[0] = 0;
- break;
- }
- ndbout << "-------------------------------------------------" << endl;
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLGetInfoTest.cpp b/storage/ndb/test/odbc/client/SQLGetInfoTest.cpp
deleted file mode 100644
index 1f0141c1759..00000000000
--- a/storage/ndb/test/odbc/client/SQLGetInfoTest.cpp
+++ /dev/null
@@ -1,215 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
- /**
- * @file SQLGetInfoTest.cpp
- */
-
-#include <common.hpp>
-
-using namespace std;
-
-SQLHDBC GI_hdbc;
-SQLHSTMT GI_hstmt;
-SQLHENV GI_henv;
-
-#define GI_MESSAGE_LENGTH 200
-
-SQLCHAR Msg[GI_MESSAGE_LENGTH];
-
-void SQLGetInfoTest_DisplayError(SQLSMALLINT GI_HandleType,
- SQLHDBC GI_InputHandle);
-
-/**
- * Test to retrieve general information about the driver and
- * the data source an application is currently connected to.
- *
- * Tests:
- * -# Test The value of FunctionId is not in table 27
- * @return Zero, if test succeeded
- */
-
-int SQLGetInfoTest()
-{
- SQLRETURN retcode;
- SQLINTEGER InfoValuePtr;
- SQLSMALLINT SLPStringLengthPtr;
-
- ndbout << endl << "Start SQLGetInfo Testing" << endl;
-
- //******************************************************
- //** The value of FunctionId is not in Table 27, then **
- //** an exception condition is raised **
- //******************************************************
-
- //************************************
- //** Allocate An Environment Handle **
- //************************************
- retcode = SQLAllocHandle(SQL_HANDLE_ENV,
- SQL_NULL_HANDLE,
- &GI_henv);
-
-if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated an environment Handle!" << endl;
-
- //*********************************************
- //** Set the ODBC application Version to 3.x **
- //*********************************************
- retcode = SQLSetEnvAttr(GI_henv,
- SQL_ATTR_ODBC_VERSION,
- (SQLPOINTER) SQL_OV_ODBC3,
- SQL_IS_UINTEGER);
-
-if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Set the ODBC application Version to 3.x!" << endl;
-
- //**********************************
- //** Allocate A Connection Handle **
- //**********************************
-
- retcode = SQLAllocHandle(SQL_HANDLE_DBC,
- GI_henv,
- &GI_hdbc);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a connection Handle!" << endl;
-
- // *******************
- // ** Connect to DB **
- // *******************
- retcode = SQLConnect(GI_hdbc,
- (SQLCHAR *) connectString(),
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS);
-
-
- // **********************
- // ** GET INFO FROM DB **
- // *********************
-
- retcode = SQLGetInfo(GI_hdbc,
- SQL_DATABASE_NAME,
- &InfoValuePtr,
- sizeof(InfoValuePtr),
- &SLPStringLengthPtr);
-
- if (retcode == SQL_SUCCESS)
- ndbout << endl << "Database Name:" << InfoValuePtr << endl;
- else
- {
- ndbout << endl << "retcode = SQLGetInfo() = " << retcode <<endl;
- SQLGetInfoTest_DisplayError(SQL_HANDLE_STMT, GI_hstmt);
- }
-
- retcode = SQLGetInfo(GI_hdbc,
- SQL_DRIVER_NAME,
- &InfoValuePtr,
- sizeof(InfoValuePtr),
- &SLPStringLengthPtr);
-
- if (retcode == SQL_SUCCESS)
- ndbout << endl << "Driver Name:" << InfoValuePtr << endl;
- else
- {
- ndbout << endl << "retcode = SQLGetInfo() = " << retcode <<endl;
- SQLGetInfoTest_DisplayError(SQL_HANDLE_STMT, GI_hstmt);
- }
-
- // **************************
- // ** INPUT WRONG InfoType **
- // **************************
- retcode = SQLGetInfo(GI_hdbc,
- 8888,
- &InfoValuePtr,
- sizeof(InfoValuePtr),
- &SLPStringLengthPtr);
- if (retcode == -2)
- {
- ndbout << endl <<"retcode = " << retcode << endl;
- ndbout << "System reported -2. Please check your test programme"
- << " about the connectionhandle." << endl;
- SQLGetInfoTest_DisplayError(SQL_HANDLE_STMT, GI_hstmt);
- }
- else if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << endl << "retcode = " << retcode << endl;
- ndbout << "The information of InfoType is not in Table 28,"
- << " but SQLGetInfo() executeed succeddfully."
- << " Check the function!" <<endl;
- SQLGetInfoTest_DisplayError(SQL_HANDLE_STMT, GI_hstmt);
- }
- else if (retcode == SQL_ERROR)
- {
- ndbout << endl << "retcode = " << retcode << endl;
- ndbout << "Input a wrong InfoType. The system found the"
- << " information of InfoType is not in Table 28."
- << " Test successful!" << endl;
- }
- else
- ndbout << endl;
- // *********************************
- // ** Disconnect and Free Handles **
- // *********************************
- SQLDisconnect(GI_hdbc);
- SQLFreeHandle(SQL_HANDLE_STMT, GI_hstmt);
- SQLFreeHandle(SQL_HANDLE_DBC, GI_hdbc);
- SQLFreeHandle(SQL_HANDLE_ENV, GI_henv);
-
- return NDBT_OK;
-
- }
-
-
-void SQLGetInfoTest_DisplayError(SQLSMALLINT GI_HandleType,
- SQLHDBC GI_InputHandle)
-{
- SQLRETURN SQLSTATEs;
- SQLINTEGER NativeError;
- SQLCHAR Sqlstate[50];
- SQLSMALLINT i, MsgLen;
- i = 1;
-
- ndbout << "-------------------------------------------------" << endl;
- ndbout << "Error diagnostics:" << endl;
-
-
- while ((SQLSTATEs = SQLGetDiagRec(GI_HandleType,
- GI_InputHandle,
- i,
- Sqlstate,
- &NativeError,
- Msg,
- sizeof(Msg),
- &MsgLen))
- != SQL_NO_DATA)
-{
-
- ndbout << "the GI_HandleType is:" << GI_HandleType << endl;
- ndbout << "the GI_InputHandle is :" << (long)GI_InputHandle << endl;
- ndbout << "the Msg is :" << (char *) Msg << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- break;
- }
- ndbout << "-------------------------------------------------" << endl;
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLGetStmtAttrTest.cpp b/storage/ndb/test/odbc/client/SQLGetStmtAttrTest.cpp
deleted file mode 100644
index c17d3e6209c..00000000000
--- a/storage/ndb/test/odbc/client/SQLGetStmtAttrTest.cpp
+++ /dev/null
@@ -1,155 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <common.h>
-#define SQL_MAXIMUM_MESSAGE_LENGTH 200
-
-using namespace std;
-
-SQLHDBC hdbc;
-SQLHSTMT hstmt;
-SQLHENV henv;
-SQLHDESC hdesc;
-SQLRETURN retcode, SQLSTATEs;
-
-SQLPOINTER ValuePtr;
-SQLINTEGER GetStmtAttr_StringLengthPtr;
-
-SQLCHAR Sqlstate[5];
-
-SQLINTEGER NativeError;
-SQLSMALLINT i, MsgLen;
-SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
-
-void GetStmtAttr_DisplayError(SQLSMALLINT HandleType, SQLHENV InputHandle);
-
-int SQLGetStmtAttrTest()
-{
- /* SQL/CLI attributes */
- /* SQL_ATTR_APP_PARAM_DESC */
- // char PtrValue1[1] = {'SQL_NULL_DESC'};
- // for (i=0; i < 1; i++) {
- retcode = SQLGetStmtAttr(hstmt, SQL_ATTR_APP_PARAM_DESC, ValuePtr, 36, &GetStmtAttr_StringLengthPtr);
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_STMT, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- GetStmtAttr_DisplayError(SQL_HANDLE_STMT, hstmt);//}
-
- /* SQL_ATTR_APP_ROW_DESC */
- // char PtrValue2[1] = {'SQL_NULL_DESC'}; /* ? */
- // for (i=0; i < 2; i++) {
- retcode = SQLGetStmtAttr(hstmt, SQL_ATTR_APP_ROW_DESC, ValuePtr, 36, &GetStmtAttr_StringLengthPtr);
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_STMT, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- GetStmtAttr_DisplayError(SQL_HANDLE_STMT, hstmt);//}
-
- /* SQL_ATTR_CURSOR_SCROLLABLE */
- // char PtrValue3[2] = {'SQL_NONSCROLLABLE', 'SQL_SCROLLABLE'}; /* ? */
- // for (i=0; i < 2; i++) {
- retcode = SQLGetStmtAttr(hstmt, SQL_ATTR_CURSOR_SCROLLABLE, ValuePtr, 36, &GetStmtAttr_StringLengthPtr);
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_STMT, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- GetStmtAttr_DisplayError(SQL_HANDLE_STMT, hstmt);//}
-
- /* SQL_ATTR_CURSOR_SENSITIVITY */
- // char PtrValue4[3] = {'SQL_UNSPECIFIED', 'SQL_INSENSITIVE', 'SQL_SENSITIVE'}; /* ? */
- // for (i=0; i < 3; i++) {
- retcode = SQLGetStmtAttr(hstmt, SQL_ATTR_CURSOR_SENSITIVITY, ValuePtr, 36, &GetStmtAttr_StringLengthPtr);
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_STMT, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- GetStmtAttr_DisplayError(SQL_HANDLE_STMT, hstmt);//}
-
- /* SQL_ATTR_METADATA_ID */
- // char PtrValue5[2] = {'SQL_TRUE', 'SQL_FALSE'}; /* ? */
- // for (i=0; i < 2; i++) {
- retcode = SQLGetStmtAttr(hstmt, SQL_ATTR_METADATA_ID, ValuePtr, 36, &GetStmtAttr_StringLengthPtr);
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_STMT, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- GetStmtAttr_DisplayError(SQL_HANDLE_STMT, hstmt);//}
-
- /* SQL_ATTR_IMP_ROW_DESC */
- // char PtrValue6[2] = {'TRUE', 'FALSE'}; /* ? */
- // for (i=0; i < 2; i++) {
- retcode = SQLGetStmtAttr(hstmt, SQL_ATTR_IMP_ROW_DESC, ValuePtr, 36, &GetStmtAttr_StringLengthPtr);
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_STMT, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- GetStmtAttr_DisplayError(SQL_HANDLE_STMT, hstmt);//}
-
-
- /* SQL_ATTR_IMP_PARAM_DESC */
- // char PtrValue6[2] = {'TRUE', 'FALSE'}; /* ? */
- // for (i=0; i < 2; i++) {
- retcode = SQLGetStmtAttr(hstmt, SQL_ATTR_IMP_PARAM_DESC, ValuePtr, 36, &GetStmtAttr_StringLengthPtr);
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_STMT, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- GetStmtAttr_DisplayError(SQL_HANDLE_STMT, hstmt);//}
-
-
- /* SQL_ATTR_METADATA_ID */
- // char PtrValue6[2] = {'TRUE', 'FALSE'}; /* ? */
- // for (i=0; i < 2; i++) {
- retcode = SQLGetStmtAttr(hstmt, SQL_ATTR_METADATA_ID, ValuePtr, 36, &GetStmtAttr_StringLengthPtr);
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_STMT, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- GetStmtAttr_DisplayError(SQL_HANDLE_STMT, hstmt);//}
-
- return 0;
-
-
- }
-
-
-void GetStmtAttr_DisplayError(SQLSMALLINT HandleType, SQLHENV InputHandle)
-{
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
-
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLGetTypeInfoTest.cpp b/storage/ndb/test/odbc/client/SQLGetTypeInfoTest.cpp
deleted file mode 100644
index 358e56c1d28..00000000000
--- a/storage/ndb/test/odbc/client/SQLGetTypeInfoTest.cpp
+++ /dev/null
@@ -1,202 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
- /**
- * @file SQLGetTypeInfoTest.cpp
- */
-
-#include <common.hpp>
-#define GT_MESSAGE_LENGTH 200
-
-using namespace std;
-
-SQLHDBC GT_hdbc;
-SQLHSTMT GT_hstmt;
-SQLHENV GT_henv;
-
-void SQLGetTypeInfoTest_DisplayError(SQLSMALLINT GT_HandleType,
- SQLHDBC GT_InputHandle);
-
-/**
- * Test to retrieve general information about the data types
- * supported by the data source an application is currently connected to.
- *
- * Tests:
- * -# Test The value of FunctionId is not in table 37
- * @return Zero, if test succeeded
- */
-int SQLGetTypeInfoTest()
-{
- SQLRETURN retcode;
- SQLSMALLINT ColumnSize;
- unsigned long TypeName;
- // SQLCHAR TypeName[128];
-
- ndbout << endl << "Start SQLGetTypeInfo Testing" << endl;
-
- //************************************
- //** Allocate An Environment Handle **
- //************************************
- retcode = SQLAllocHandle(SQL_HANDLE_ENV,
- SQL_NULL_HANDLE,
- &GT_henv);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated an environment Handle!" << endl;
-
- //*********************************************
- //** Set the ODBC application Version to 3.x **
- //*********************************************
- retcode = SQLSetEnvAttr(GT_henv,
- SQL_ATTR_ODBC_VERSION,
- (SQLPOINTER) SQL_OV_ODBC3,
- SQL_IS_UINTEGER);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Set the ODBC application Version to 3.X!" << endl;
-
- //**********************************
- //** Allocate A Connection Handle **
- //**********************************
-
- retcode = SQLAllocHandle(SQL_HANDLE_DBC,
- GT_henv,
- &GT_hdbc);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a connection Handle!" << endl;
-
- // *******************
- // ** Connect to DB **
- // *******************
- retcode = SQLConnect(GT_hdbc,
- (SQLCHAR *) connectString(),
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS);
-
-
- //*******************************
- //** Allocate statement handle **
- //*******************************
-
- retcode = SQLAllocHandle(SQL_HANDLE_STMT,
- GT_hdbc,
- &GT_hstmt);
-
-
- //***********************************************
- //** Get DataType From the Current Application **
- //***********************************************
- retcode = SQLGetTypeInfo(GT_hstmt, SQL_CHAR);
- ndbout << "retcode =SQLGetTypeInfo()= " << retcode << endl;
- if (retcode == SQL_SUCCESS)
- {
- retcode =SQLBindCol(GT_hstmt,
- 2,
- SQL_C_ULONG,
- TypeName,
- sizeof(TypeName),
- NULL);
- ndbout << "retcode = SQLBindCol()= " << retcode << endl;
-
- // retcode =SQLBindCol(GT_hstmt,
- // 1,
- // SQL_C_DEFAULT,
- // ColumnSize,
- // sizeof(ColumnSize),
- // NULL);
-
- retcode = SQLFetch(GT_hstmt);
- ndbout << "retcode = SQLFETCH()=" << retcode << endl;
- ndbout << "DataType = " << TypeName << endl;
-
- }
-
- //*******************************************************
- //** If the Value of DataType is not in Table 37, then **
- //** an exception condition is raised **
- //*******************************************************
- retcode = SQLGetTypeInfo(GT_hstmt, 8888888);
- if (retcode == -2)
- {
- ndbout << "retcode = " << retcode << endl;
- ndbout << "The value of DataType is not in table 37" << endl;
- SQLGetTypeInfoTest_DisplayError(SQL_HANDLE_STMT, GT_hstmt);
- }
- else if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "retcode = " << retcode << endl;
- ndbout << endl << "The value of DataType is not in Table 37" << endl;
- SQLGetTypeInfoTest_DisplayError(SQL_HANDLE_STMT, GT_hstmt);
- }
- else
- {
- ndbout << "retcode = " << retcode << endl;
- ndbout << endl << "The value of DataType is not in Table 37" << endl;
- SQLGetTypeInfoTest_DisplayError(SQL_HANDLE_STMT, GT_hstmt);
- }
- // *********************************
- // ** Disconnect and Free Handles **
- // *********************************
- SQLDisconnect(GT_hdbc);
- SQLFreeHandle(SQL_HANDLE_STMT, GT_hstmt);
- SQLFreeHandle(SQL_HANDLE_DBC, GT_hdbc);
- SQLFreeHandle(SQL_HANDLE_ENV, GT_henv);
-
- return NDBT_OK;
-
- }
-
-void SQLGetTypeInfoTest_DisplayError(SQLSMALLINT GT_HandleType,
- SQLHDBC GT_InputHandle)
-{
- SQLINTEGER NativeError;
- SQLSMALLINT i, MsgLen;
- SQLCHAR Msg[GT_MESSAGE_LENGTH];
- SQLRETURN SQLSTATEs;
- SQLCHAR Sqlstate[50];
- i = 1;
-
- ndbout << "-------------------------------------------------" << endl;
- ndbout << "Error diagnostics:" << endl;
-
- while ((SQLSTATEs = SQLGetDiagRec(GT_HandleType,
- GT_InputHandle,
- i,
- Sqlstate,
- &NativeError,
- Msg,
- sizeof(Msg),
- &MsgLen))
- != SQL_NO_DATA)
-{
-
- ndbout << "the HandleType is:" << GT_HandleType << endl;
- ndbout << "the InputHandle is :" << (long)GT_InputHandle << endl;
- ndbout << "the Msg is :" << (char *) Msg << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- break;
- }
- ndbout << "-------------------------------------------------" << endl;
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLMoreResultsTest.cpp b/storage/ndb/test/odbc/client/SQLMoreResultsTest.cpp
deleted file mode 100644
index 7b9a7afc551..00000000000
--- a/storage/ndb/test/odbc/client/SQLMoreResultsTest.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <common.h>
-#define SQL_MAXIMUM_MESSAGE_LENGTH 200
-
-using namespace std;
-
-SQLHDBC hdbc;
-SQLHSTMT hstmt;
-SQLHENV henv;
-SQLHDESC hdesc;
-SQLRETURN retcode, SQLSTATEs;
-
-SQLCHAR Sqlstate[5];
-
-SQLINTEGER NativeError;
-SQLSMALLINT i, MsgLen;
-SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
-
-void SQLMoreResults_DisplayError(SQLSMALLINT HandleType, SQLHSTMT InputHandle);
-
-int SQLMoreResultsTest()
-{
-
- /* hstmt */
- retcode = SQLMoreResults(hstmt);
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_STMT, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SQLMoreResults_DisplayError(SQL_HANDLE_STMT, hstmt);
-
- /* henv */
- retcode = SQLMoreResults(henv);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS)
- ndbout << "Handle Type is SQL_HANDLE_ENV, but string SQL_SUCCESS_WITH_INFO still appeared. Please check programm" << endl;
- // SQLMoreResults_DisplayError(SQL_HANDLE_ENV, henv);
-
- /* hdbc */
- retcode = SQLMoreResults(hdbc);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS)
- ndbout << "Handle Type is SQL_HANDLE_DBC, but string SQL_SUCCESS_WITH_INFO still appeared. Please check programm" << endl;
- // SQLMoreResults_DisplayError(SQL_HANDLE_DBC, hdbc);
-
- /* hdesc */
- retcode = SQLMoreResults(hdesc);
-
- if (retcode == SQL_SUCCESS_WITH_INFO || retcode == SQL_SUCCESS)
- ndbout << "Handle Type is SQL_HANDLE_DESC, but string SQL_SUCCESS_WITH_INFO still appeared. Please check programm" << endl;
- // SQLMoreResults_DisplayError(SQL_HANDLE_DESC, hdesc);
-
- return 0;
-
- }
-
-
-void SQLMoreResults_DisplayError(SQLSMALLINT HandleType, SQLHSTMT InputHandle)
-{
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
-
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLNumResultColsTest.cpp b/storage/ndb/test/odbc/client/SQLNumResultColsTest.cpp
deleted file mode 100644
index 9b7983380f1..00000000000
--- a/storage/ndb/test/odbc/client/SQLNumResultColsTest.cpp
+++ /dev/null
@@ -1,202 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
- /**
- * @file SQLNumResultColsTest.cpp
- */
-#include <common.hpp>
-using namespace std;
-
-#define NRC_MESSAGE_LENGTH 200
-
-SQLHSTMT NRC_hstmt;
-SQLHSTMT NRC_hdbc;
-SQLHENV NRC_henv;
-SQLHDESC NRC_hdesc;
-
-void SQLNumResultColsTest_DisplayError(SQLSMALLINT NRC_HandleType,
- SQLHSTMT NRC_InputHandle);
-
-/**
- * Test returning descriptor information
- *
- * Tests:
- * -# Testing how many columns exist in the result data set
- *
- * @return Zero, if test succeeded
- */
-
-int SQLNumResultColsTest()
-{
- SQLRETURN retcode;
- SQLSMALLINT NumColumns;
- SQLCHAR SQLStmt[NRC_MESSAGE_LENGTH];
-
- ndbout << endl << "Start SQLNumResultCols Testing" << endl << endl;
-
- //**************************************************************
- //** If there is no prepared or executed statement associated **
- //** with SQL-statement **
- //**************************************************************
-
- retcode = SQLNumResultCols(NRC_hstmt, &NumColumns);
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- {
-
- SQLNumResultColsTest_DisplayError(SQL_HANDLE_STMT, NRC_hstmt);
- }
-
- //************************************
- //** Allocate An Environment Handle **
- //************************************
- retcode = SQLAllocHandle(SQL_HANDLE_ENV,
- SQL_NULL_HANDLE,
- &NRC_henv);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated an environment Handle!" << endl;
-
- //*********************************************
- //** Set the ODBC application Version to 3.x **
- //*********************************************
- retcode = SQLSetEnvAttr(NRC_henv,
- SQL_ATTR_ODBC_VERSION,
- (SQLPOINTER) SQL_OV_ODBC3,
- SQL_IS_UINTEGER);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Set the ODBC application Version to 3.x!" << endl;
-
- //**********************************
- //** Allocate A Connection Handle **
- //**********************************
-
- retcode = SQLAllocHandle(SQL_HANDLE_DBC,
- NRC_henv,
- &NRC_hdbc);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a connection Handle!" << endl;
-
- // *******************
- // ** Connect to DB **
- // *******************
- retcode = SQLConnect(NRC_hdbc,
- (SQLCHAR *) connectString(),
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Connected to DB : OK!" << endl;
- else
- {
- ndbout << "Failure to Connect DB!" << endl;
- return NDBT_FAILED;
- }
- //*******************************
- //** Allocate statement handle **
- //*******************************
-
- retcode = SQLAllocHandle(SQL_HANDLE_STMT,
- NRC_hdbc,
- &NRC_hstmt);
- if(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a statement handle!" << endl;
-
- //************************
- //** Define a statement **
- //************************
-
- strcpy((char *) SQLStmt, "SELECT * FROM Customers");
-
- // strcpy((char *) SQLStmt,
- // "INSERT INTO Customers (CustID, Name, Address, Phone) VALUES (7, 'pet', 'LM vag 8', '88888')");
-
- //*******************************************
- //** Prepare and Execute the SQL statement **
- //*******************************************
-
- retcode = SQLExecDirect(NRC_hstmt,
- SQLStmt,
- SQL_NTS);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
-
- //*****************************************************
- //** Only general error test. It is not in test rule **
- //*****************************************************
-
- retcode = SQLNumResultCols(NRC_hstmt, &NumColumns);
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << endl << "Number of columns in the result data set" << endl;
- ndbout << NumColumns << endl;
- }
- else
- SQLNumResultColsTest_DisplayError(SQL_HANDLE_STMT, NRC_hstmt);
- }
-
- // *********************************
- // ** Disconnect and Free Handles **
- // *********************************
- SQLDisconnect(NRC_hdbc);
- SQLFreeHandle(SQL_HANDLE_STMT, NRC_hstmt);
- SQLFreeHandle(SQL_HANDLE_DBC, NRC_hdbc);
- SQLFreeHandle(SQL_HANDLE_ENV, NRC_henv);
-
- return NDBT_OK;
-
-}
-
-void SQLNumResultColsTest_DisplayError(SQLSMALLINT NRC_HandleType,
- SQLHSTMT NRC_InputHandle)
-{
- SQLRETURN SQLSTATEs;
- SQLINTEGER NativeError;
- SQLSMALLINT i, MsgLen;
- SQLCHAR Msg[NRC_MESSAGE_LENGTH],Sqlstate[5];
- i = 1;
-
- ndbout << "-------------------------------------------------" << endl;
- ndbout << "Error diagnostics:" << endl;
-
- while ((SQLSTATEs = SQLGetDiagRec(NRC_HandleType,
- NRC_InputHandle,
- i,
- Sqlstate,
- &NativeError,
- Msg,
- sizeof(Msg),
- &MsgLen))
- != SQL_NO_DATA)
- {
-
- ndbout << "the HandleType is:" << NRC_HandleType << endl;
- ndbout << "the InputHandle is :" << (long)NRC_InputHandle << endl;
- ndbout << "the Msg is: " << (char *)Msg << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- break;
- }
- ndbout << "-------------------------------------------------" << endl;
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLParamDataTest.cpp b/storage/ndb/test/odbc/client/SQLParamDataTest.cpp
deleted file mode 100644
index e566e55a417..00000000000
--- a/storage/ndb/test/odbc/client/SQLParamDataTest.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NdbOut.hpp>
-#include <sqlcli.h>
-#include <stdio.h>
-
-using namespace std;
-
-#define NAME_LEN 50
-#define PHONE_LEN 10
-#define SALES_PERSON_LEN 10
-#define STATUS_LEN 6
-
-#define NAME_LEN 50
-#define PHONE_LEN 50
-
-SQLCHAR szName[NAME_LEN], szPhone[PHONE_LEN];
-SQLINTEGER sCustID, cbName, cbAge, cbBirthday;
-
-SQLHSTMT hstmt;
-SQLHENV henv;
-
-SQLCHAR szSalesPerson[SALES_PERSON_LEN];
-
-SQLCHAR szStatus[STATUS_LEN], Sqlstate[5], Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
-SQLINTEGER cbOrderID = 0, cbCustID = 0, cbOpenDate = 0, cbSalesPerson = SQL_NTS, cbStatus = SQL_NTS, NativeError;
-SQLRETURN retcode, SQLSTATEs;
-
-SQLSMALLINT sOrderID;
-
-SQLSMALLINT i, MsgLen;
-
-SQLCHAR ColumnName;
-SQLSMALLINT TargetValuePtr;
-SQLINTEGER StrLen_or_IndPtr;
-SQLPOINTER ValuePtrPtr;
-
-void DisplayError(SQLSMALLINT HandleType, SQLHSTMT InputHandle);
-
-int SQLParamDataTest()
-{
-
- /* hstmt */
- // We can create the table ORDERS and insert rows into ORDERS
- // NDB by program TestDirectSQL. In this test program, We only have three rows in table ORDERS
-
-/* Prepare the SQL statement with parameter markers. */
-retcode = SQLPrepare(hstmt, (SQLCHAR *)"SELECT ORDERID, CUSTID, OPENDATE, SALESPERSON, STATUS FROM ORDERS", SQL_NTS);
-
-if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
- retcode = SQLExecute(hstmt);
-
-if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
- retcode = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_SSHORT, SQL_INTEGER, 16, 0, &sOrderID, 16, &cbOrderID);
-
-if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
-
-while (retcode == SQL_NEED_DATA) {
- retcode = SQLParamData(hstmt, &ValuePtrPtr);
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO){
- DisplayError(SQL_HANDLE_STMT, hstmt);
- }
- }
-
-
- }
-}
-}
- return 0;
-
- }
-
-
-void DisplayError(SQLSMALLINT HandleType, SQLHSTMT InputHandle)
-{
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
-
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLPrepareTest.cpp b/storage/ndb/test/odbc/client/SQLPrepareTest.cpp
deleted file mode 100644
index 96c6fff2cfd..00000000000
--- a/storage/ndb/test/odbc/client/SQLPrepareTest.cpp
+++ /dev/null
@@ -1,285 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
- /**
- * @file SQLprepareTest.cpp
- */
-#include <common.hpp>
-#define pare_SQL_MAXIMUM_MESSAGE_LENGTH 200
-
-using namespace std;
-
-SQLHDBC pare_hdbc;
-SQLHSTMT pare_hstmt;
-SQLHENV pare_henv;
-SQLHDESC pare_hdesc;
-SQLRETURN pare_retcode, pare_SQLSTATEs;
-
-SQLCHAR pare_Sqlstate[5];
-
-SQLINTEGER pare_NativeError;
-SQLSMALLINT pare_i, pare_MsgLen;
-SQLCHAR pare_Msg[pare_SQL_MAXIMUM_MESSAGE_LENGTH];
-
-void Prepare_DisplayError(SQLSMALLINT pare_HandleType,
- SQLHSTMT pare_InputHandle);
-
-/**
- * Test to prepare a statement with different handles
- *
- * -# Input correct hstmt handle
- * -# Input incorrect henv handle
- * -# Input incorrect hdbc handle
- * -# Input incorrect handle hdesc
- *
- * @return Zero, if test succeeded
- */
-int SQLPrepareTest()
-{
- SQLCHAR SQLStmt [120];
- ndbout << endl << "Start SQLPrepare Testing" << endl;
- ndbout << endl << "Test 1" << endl;
- //*********************************
- //** Test1 **
- //** Input correct hstmt handle **
- //*********************************
-
- //************************************
- //** Allocate An Environment Handle **
- //************************************
- pare_retcode = SQLAllocHandle(SQL_HANDLE_ENV,
- SQL_NULL_HANDLE,
- &pare_henv);
-
- if(pare_retcode == SQL_SUCCESS || pare_retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated an environment Handle!" << endl;
-
- //*********************************************
- //** Set the ODBC application Version to 3.x **
- //*********************************************
- pare_retcode = SQLSetEnvAttr(pare_henv,
- SQL_ATTR_ODBC_VERSION,
- (SQLPOINTER) SQL_OV_ODBC3,
- SQL_IS_UINTEGER);
-
- if (pare_retcode == SQL_SUCCESS || pare_retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Set the ODBC application Version to 3.x!" << endl;
-
- //**********************************
- //** Allocate A Connection Handle **
- //**********************************
- pare_retcode = SQLAllocHandle(SQL_HANDLE_DBC, pare_henv, &pare_hdbc);
- if (pare_retcode == SQL_SUCCESS || pare_retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a connection Handle!" << endl;
-
- // *******************
- // ** Connect to DB **
- // *******************
- pare_retcode = SQLConnect(pare_hdbc,
- (SQLCHAR *) connectString(),
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS);
-
- if (pare_retcode == SQL_SUCCESS || pare_retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Connected to DB : OK!" << endl;
- else
- ndbout << "Failure to Connect DB!" << endl;
-
- //*******************************
- //** Allocate statement handle **
- //*******************************
- pare_retcode = SQLAllocHandle(SQL_HANDLE_STMT, pare_hdbc, &pare_hstmt);
- if (pare_retcode == SQL_SUCCESS || pare_retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a statement handle!" << endl;
-
- //************************
- //** Define a statement **
- //************************
-
- strcpy( (char *) SQLStmt, "INSERT INTO Customers (CustID, Name, Address, Phone) VALUES(2, 'Hans Peter', 'LM Vag8', '468719000')");
-
- pare_retcode = SQLPrepare(pare_hstmt,
- SQLStmt,
- SQL_NTS);
-
- if (pare_retcode == SQL_INVALID_HANDLE)
- {
- ndbout << "pare_retcode = " << pare_retcode << endl;
- ndbout << "HandleType is SQL_HANDLE_STMT, but SQL_INVALID_HANDLE"
- << endl;
- ndbout << "appeared. Please check program!" << endl;
- }
- else if (pare_retcode == SQL_ERROR || pare_retcode == SQL_SUCCESS_WITH_INFO)
- {
- Prepare_DisplayError(SQL_HANDLE_STMT, pare_hstmt);
- }
- else
- {
- //***********************
- //** Execute statement **
- //***********************
- pare_retcode = SQLExecute(pare_hstmt);
- if (pare_retcode != SQL_SUCCESS)
- {
- ndbout << "pare_retcode = " << pare_retcode << endl;
- Prepare_DisplayError(SQL_HANDLE_STMT, pare_hstmt);
- }
- else
- ndbout << endl << "Test 1:Input correct HSTMT handle. OK!" << endl;
- }
-
- //*********************************
- //** Test2 **
- //** Input incorrect henv handle **
- //*********************************
-
- strcpy( (char *) SQLStmt, "INSERT INTO Customers (CustID, Name, Address, Phone) VALUES(3, 'Hans', 'LM8', '51888')");
-
- pare_retcode = SQLPrepare(pare_henv,
- SQLStmt,
- SQL_NTS);
-
- ndbout << endl << "Test 2" << endl;
- if (pare_retcode == SQL_SUCCESS_WITH_INFO || pare_retcode == SQL_SUCCESS)
- {
- FAILURE("Wrong SQL_HANDLE_HENV, but success returned. Check it!");
- }
- else if (pare_retcode == SQL_INVALID_HANDLE)
- {
- ndbout << "Wrong SQL_HANDLE_HENV input and -2 appeared. OK!" << endl ;
- }
- else
- ;
- /*
- {
- ndbout << "Input wrong SQL_HANDLE_ENV, but SQL_SUCCESS_W_I" << endl;
- ndbout << "and SQL_SUCCESS appeared. Please check program!" << endl;
- return NDBT_FAILED;
- }
- */
-
- //*********************************
- //** Test3 **
- //** Input incorrect hdbc handle **
- //*********************************
-
- strcpy( (char *) SQLStmt, "INSERT INTO Customers (CustID, Name, Address, Phone) VALUES(4, 'HP', 'VÄG8', '90888')");
-
- pare_retcode = SQLPrepare(pare_hdbc,
- SQLStmt,
- SQL_NTS);
-
- ndbout << endl << "Test 3" << endl;
- if (pare_retcode == SQL_SUCCESS_WITH_INFO || pare_retcode == SQL_SUCCESS)
- {
- FAILURE("Wrong SQL_HANDLE_HDBC, but success returned. Check it!");
- }
- else if (pare_retcode == SQL_INVALID_HANDLE)
- {
- ndbout << "Wrong SQL_HANDLE_HDBC input and -2 appeared. OK!" << endl ;
- }
- else
- ;
-
- /*
- {
- ndbout << "Input wrong statement handle SQL_HANDLE_DBC" << endl;
- ndbout << "but SQL_SUCCESS_WITH_INFO" << endl;
- ndbout << "and SQL_SUCCESS still appeared. Please check program" << endl;
- return NDBT_FAILED;
- }
-
- */
- //**********************************
- //** Test4 **
- //** Input incorrect handle hdesc **
- //**********************************
-
- strcpy( (char *) SQLStmt, "INSERT INTO Customers (CustID, Name, Address, Phone) VALUES(5, 'Richard', 'VÄG8', '56888')");
-
- pare_retcode = SQLPrepare(pare_hdesc,
- SQLStmt,
- SQL_NTS);
-
- ndbout << endl << "Test 4" << endl;
- if (pare_retcode == SQL_SUCCESS_WITH_INFO || pare_retcode == SQL_SUCCESS)
- {
- FAILURE("Wrong SQL_HANDLE_DESC, but success returned");
- }
- else if (pare_retcode == SQL_INVALID_HANDLE)
- {
- ndbout << "Wrong SQL_HANDLE_DESC input and -2 appeared. OK!" << endl ;
- }
- else
- ndbout << endl;
-
- /*
- {
- ndbout << "TEST FAILURE: Input wrong SQL_HANDLE_DESC, "
- << "but SQL_SUCCESS_WITH_INFO or SQL_SUCCESS was returned."
- << endl;
- return NDBT_FAILED;
- }
- */
-
- //****************
- // Free Handles **
- //****************
- SQLDisconnect(pare_hdbc);
- SQLFreeHandle(SQL_HANDLE_STMT, pare_hstmt);
- SQLFreeHandle(SQL_HANDLE_DBC, pare_hdbc);
- SQLFreeHandle(SQL_HANDLE_ENV, pare_henv);
-
- return NDBT_OK;
-
-}
-
-void Prepare_DisplayError(SQLSMALLINT pare_HandleType,
- SQLHSTMT pare_InputHandle)
-{
- SQLSMALLINT pare_i = 1;
- SQLRETURN pare_SQLSTATEs;
-
- ndbout << "-------------------------------------------------" << endl;
- ndbout << "Error diagnostics:" << endl;
-
- while ((pare_SQLSTATEs = SQLGetDiagRec(pare_HandleType,
- pare_InputHandle,
- pare_i,
- pare_Sqlstate,
- &pare_NativeError,
- pare_Msg,
- sizeof(pare_Msg),
- &pare_MsgLen)
- ) != SQL_NO_DATA)
- {
- ndbout << "SQLSTATE = " << pare_SQLSTATEs << endl;
- ndbout << "the HandleType is:" << pare_HandleType << endl;
- ndbout << "the Handle is :" << (long)pare_InputHandle << endl;
- ndbout << "the conn_Msg is: " << (char *) pare_Msg << endl;
- ndbout << "the output state is:" << (char *)pare_Sqlstate << endl;
-
- pare_i ++;
- break;
- }
- ndbout << "-------------------------------------------------" << endl;
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLPutDataTest.cpp b/storage/ndb/test/odbc/client/SQLPutDataTest.cpp
deleted file mode 100644
index 7d3ce432b93..00000000000
--- a/storage/ndb/test/odbc/client/SQLPutDataTest.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NdbOut.hpp>
-#include <sqlcli.h>
-#include <stdio.h>
-
-using namespace std;
-
-#define NAME_LEN 50
-#define PHONE_LEN 10
-#define SALES_PERSON_LEN 10
-#define STATUS_LEN 6
-
-#define NAME_LEN 50
-#define PHONE_LEN 50
-
-SQLCHAR szName[NAME_LEN], szPhone[PHONE_LEN];
-SQLINTEGER sCustID, cbName, cbAge, cbBirthday;
-
-SQLHSTMT hstmt;
-SQLHENV henv;
-
-SQLCHAR szSalesPerson[SALES_PERSON_LEN];
-
-SQLCHAR szStatus[STATUS_LEN], Sqlstate[5], Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
-SQLINTEGER cbOrderID = 0, cbCustID = 0, cbOpenDate = 0, cbSalesPerson = SQL_NTS, cbStatus = SQL_NTS, NativeError;
-SQLRETURN retcode, SQLSTATEs;
-
-SQLSMALLINT sOrderID;
-
-SQLSMALLINT i, MsgLen;
-
-SQLCHAR ColumnName;
-SQLSMALLINT TargetValuePtr;
-SQLINTEGER StrLen_or_Ind, DataPtr;
-SQLPOINTER ValuePtrPtr;
-
-void DisplayError(SQLSMALLINT HandleType, SQLHSTMT InputHandle);
-
-int SQLPutDataTest()
-{
-
- /* hstmt */
- // We can create the table ORDERS and insert rows into ORDERS
- // NDB by program TestDirectSQL. In this test program, We only have three rows in table ORDERS
-
-/* Prepare the SQL statement with parameter markers. */
-retcode = SQLPrepare(hstmt, (SQLCHAR *)"SELECT ORDERID, CUSTID, OPENDATE, SALESPERSON, STATUS FROM ORDERS", SQL_NTS);
-
-if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
- retcode = SQLExecute(hstmt);
-
-if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
- retcode = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_SSHORT, SQL_INTEGER, 16, 0, &sOrderID, 16, &cbOrderID);
-
-if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
-
-while (retcode == SQL_NEED_DATA) {
- retcode = SQLParamData(hstmt, &ValuePtrPtr);
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO){
- retcode = SQLPutData(hstmt, &DataPtr, StrLen_or_Ind);
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO){
- DisplayError(SQL_HANDLE_STMT, hstmt);
- }
- }
- }
-
-
- }
-}
-}
- return 0;
-
- }
-
-
-void DisplayError(SQLSMALLINT HandleType, SQLHSTMT InputHandle)
-{
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
-
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLRowCountTest.cpp b/storage/ndb/test/odbc/client/SQLRowCountTest.cpp
deleted file mode 100644
index 0adaf671446..00000000000
--- a/storage/ndb/test/odbc/client/SQLRowCountTest.cpp
+++ /dev/null
@@ -1,203 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
- /**
- * @file SQLRowCountTest.cpp
- */
-
-#include <common.hpp>
-using namespace std;
-
-#define NAME_LEN 50
-#define PHONE_LEN 10
-#define SALES_PERSON_LEN 10
-#define STATUS_LEN 6
-#define RC_MESSAGE_LENGTH 200
-
-SQLHSTMT RC_hstmt;
-SQLHDBC RC_hdbc;
-SQLHENV RC_henv;
-SQLHDESC RC_hdesc;
-
-void SQLRowCountTest_DisplayError(SQLSMALLINT RC_HandleType,
- SQLHSTMT RC_InputHandle);
-
-/**
- * Test to obtain a count of the number of rows
- * in a table
- *
- * -# Call SQLRowCount without executed statement
- * -# Call SQLRowCount with normal case
- *
- * @return Zero, if test succeeded
- */
-
-int SQLRowCountTest()
-{
- SQLRETURN retcode;
- unsigned long RowCount;
- SQLCHAR SQLStmt [120];
-
- ndbout << endl << "Start SQLRowCount Testing" << endl;
-
- //************************************************************************
- //* If there is no executed statement, an execption condotion is raised **
- //************************************************************************
-
- retcode = SQLRowCount(RC_hstmt, &RowCount);
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- {
-
- SQLRowCountTest_DisplayError(SQL_HANDLE_STMT, RC_hstmt);
- }
-
- //************************************
- //** Allocate An Environment Handle **
- //************************************
- retcode = SQLAllocHandle(SQL_HANDLE_ENV,
- SQL_NULL_HANDLE,
- &RC_henv);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated an environment Handle!" << endl;
-
- //*********************************************
- //** Set the ODBC application Version to 3.x **
- //*********************************************
- retcode = SQLSetEnvAttr(RC_henv,
- SQL_ATTR_ODBC_VERSION,
- (SQLPOINTER) SQL_OV_ODBC3,
- SQL_IS_UINTEGER);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Set the ODBC application Version to 3.x!" << endl;
-
- //**********************************
- //** Allocate A Connection Handle **
- //**********************************
-
- retcode = SQLAllocHandle(SQL_HANDLE_DBC,
- RC_henv,
- &RC_hdbc);
-
-if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a connection Handle!" << endl;
-
- // *******************
- // ** Connect to DB **
- // *******************
- retcode = SQLConnect(RC_hdbc,
- (SQLCHAR *) connectString(),
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Connected to DB : OK!" << endl;
- else
- {
- ndbout << "Failure to Connect DB!" << endl;
- return NDBT_FAILED;
- }
-
- //*******************************
- //** Allocate statement handle **
- //*******************************
-
- retcode = SQLAllocHandle(SQL_HANDLE_STMT,
- RC_hdbc,
- &RC_hstmt);
- if(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a statement handle!" << endl;
-
- //************************
- //** Define a statement **
- //************************
- strcpy((char *) SQLStmt, "INSERT INTO Customers (CustID, Name, Address,Phone) VALUES(588, 'HeYong','LM888','919888')");
-
- //*******************************
- //* Prepare the SQL statement **
- //*******************************
-
- retcode = SQLPrepare(RC_hstmt,
- SQLStmt,
- SQL_NTS);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
-
- //******************************
- //* Execute the SQL statement **
- //******************************
- retcode = SQLExecute(RC_hstmt);
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
-
- //***************
- // Normal test **
- //***************
- retcode = SQLRowCount(RC_hstmt, &RowCount);
- if (retcode == SQL_ERROR )
- SQLRowCountTest_DisplayError(SQL_HANDLE_STMT, RC_hstmt);
- else
- ndbout << endl << "Number of the rows in the table Customers: "
- << (int)RowCount << endl;
- }
- }
-
- // *********************************
- // ** Disconnect and Free Handles **
- // *********************************
- SQLDisconnect(RC_hdbc);
- SQLFreeHandle(SQL_HANDLE_STMT, RC_hstmt);
- SQLFreeHandle(SQL_HANDLE_DBC, RC_hdbc);
- SQLFreeHandle(SQL_HANDLE_ENV, RC_henv);
-
- return NDBT_OK;
-
-}
-
-void SQLRowCountTest_DisplayError(SQLSMALLINT RC_HandleType,
- SQLHSTMT RC_InputHandle)
-{
- SQLRETURN SQLSTATEs;
- SQLSMALLINT i, MsgLen;
- SQLCHAR Sqlstate[5], Msg[RC_MESSAGE_LENGTH];
- SQLINTEGER NativeError;
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(RC_HandleType,
- RC_InputHandle,
- i,
- Sqlstate,
- &NativeError,
- Msg,
- sizeof(Msg),
- &MsgLen))
- != SQL_NO_DATA)
-{
-
- ndbout << "the HandleType is:" << RC_HandleType << endl;
- ndbout << "the InputHandle is :" << (long)RC_InputHandle << endl;
- ndbout << "the Msg:" << (char *)Msg << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
-}
-
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLSetConnectAttrTest.cpp b/storage/ndb/test/odbc/client/SQLSetConnectAttrTest.cpp
deleted file mode 100644
index 19e38eef63f..00000000000
--- a/storage/ndb/test/odbc/client/SQLSetConnectAttrTest.cpp
+++ /dev/null
@@ -1,131 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <common.h>
-#define SQL_MAXIMUM_MESSAGE_LENGTH 200
-
-using namespace std;
-
-SQLHDBC hdbc;
-SQLHSTMT hstmt;
-SQLHENV henv;
-SQLHDESC hdesc;
-SQLRETURN retcode, SQLSTATEs;
-
-SQLPOINTER ValuePtr;
-//SQLINTEGER StringLength;
-
-SQLCHAR Sqlstate[5];
-
-SQLINTEGER NativeError;
-SQLSMALLINT i, MsgLen;
-SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
-
-void SetConnectAttr_DisplayError(SQLSMALLINT HandleType, SQLHENV InputHandle);
-
-int SQLSetConnectAttrTest ()
-{
- /* SQL/CLI attributes */
- char PtrValue1[2] = {'SQL_TRUE', 'SQL_FALSE'};
- for (i=0; i < 2; i++) {
- retcode = SQLSetConnectAttr(hdbc, SQL_ATTR_AUTO_IPD, (void*)PtrValue1[i], sizeof(PtrValue1[i]));
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_DBC, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SetConnectAttr_DisplayError(SQL_HANDLE_DBC, hdbc);}
-
- /* ODBC attributes */
- /*
- char PtrValue1[3] = {'SQL_MODE_READ_ONLY', 'SQL_MODE_READ_WRITE'};
- for (i=0; i < 3; i++) {
- retcode = SQLSetConnectAttr(hdbc, SQL_ATTR_ACCESS_MODE, (void*)PtrValue1[i], sizeof(PtrValue1[i]));
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_DBC, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SetConnectAttr_DisplayError(SQL_HANDLE_DBC, hdbc);}
-
-
- char PtrValue2[2] = {'SQL_ASYNC_ENABLE_OFF', 'SQL_ASYNC_ENABLE_ON'};
- for (i=0; i < 2; i++) {
- retcode = SQLSetConnectAttr(hdbc, SQL_ATTR_ASYNC_ENABLE, (void*)PtrValue2[i], sizeof(PtrValue2[i]));
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_DBC, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SetConnectAttr_DisplayError(SQL_HANDLE_DBC, hdbc);}
-
-
- char PtrValue4[2] = {'SQL_AUTOCOMMIT_OFF', 'SQL_AUTOCOMMIT_ON'};
- for (i=0; i < 2; i++) {
- retcode = SQLSetConnectAttr(hdbc, SQL_ATTR_AUTOCOMMIT, (void*)PtrValue4[i], sizeof(PtrValue4[i]));
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_DBC, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SetConnectAttr_DisplayError(SQL_HANDLE_DBC, hdbc);}
-
- char PtrValue5[2] = {'SQL_CD_TRUE', 'SQL_CD_FALSE'};
- for (i=0; i < 2; i++) {
- retcode = SQLSetConnectAttr(hdbc, SQL_ATTR_CONNECTION_DEAD, (void*)PtrValue4[i], sizeof(PtrValue5[i]));
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_DBC, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SetConnectAttr_DisplayError(SQL_HANDLE_DBC, hdbc);}
-
-
- char PtrValue5[2] = {'SQL_CD_TRUE', 'SQL_CD_FALSE'};
- for (i=0; i < 2; i++) {
- retcode = SQLSetConnectAttr(hdbc, SQL_ATTR_CONNECTION_TIMEOUT, (void*)PtrValue4[i], sizeof(PtrValue5[i]));
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_DBC, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SetConnectAttr_DisplayError(SQL_HANDLE_DBC, hdbc);}
-
- */
-
- return 0;
-
- }
-
-
-void SetConnectAttr_DisplayError(SQLSMALLINT HandleType, SQLHENV InputHandle)
-{
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
-
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLSetCursorNameTest.cpp b/storage/ndb/test/odbc/client/SQLSetCursorNameTest.cpp
deleted file mode 100644
index 3c5a8124ce9..00000000000
--- a/storage/ndb/test/odbc/client/SQLSetCursorNameTest.cpp
+++ /dev/null
@@ -1,215 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
- /**
- * @file SQLSetCursorNameTest.cpp
- */
-#include <common.hpp>
-using namespace std;
-
-#define SCN_MESSAGE_LENGTH 50
-
-SQLHSTMT SCN_hstmt;
-SQLHDESC SCN_hdesc;
-SQLHENV SCN_henv;
-SQLHDBC SCN_hdbc;
-
-void SCN_DisplayError(SQLSMALLINT SCN_HandleType,
- SQLHDESC SCN_InputHandle);
-
-/**
- * Test to assign a user-defined name to a cursor that is
- * associated with an active SQL statement handle
- *
- * Tests:
- * -# set user-defined cursor name to zero
- * -# set user-defined cursor name in normal case
- *
- * @return Zero, if test succeeded
- */
-
-int SQLSetCursorNameTest()
-{
- SQLRETURN retcode;
- SQLCHAR SQLStmt [120];
- SQLCHAR CursorName [80];
- SQLSMALLINT CNameSize;
-
- ndbout << endl << "Start SQLSetCursorName Testing" << endl;
-
- //************************************
- //** Allocate An Environment Handle **
- //************************************
- retcode = SQLAllocHandle(SQL_HANDLE_ENV,
- SQL_NULL_HANDLE,
- &SCN_henv);
-
-if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated an environment Handle!" << endl;
-
- //*********************************************
- //** Set the ODBC application Version to 3.x **
- //*********************************************
- retcode = SQLSetEnvAttr(SCN_henv,
- SQL_ATTR_ODBC_VERSION,
- (SQLPOINTER) SQL_OV_ODBC3,
- SQL_IS_UINTEGER);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Set the ODBC application Version to 3.x!" << endl;
-
- //**********************************
- //** Allocate A Connection Handle **
- //**********************************
-
- retcode = SQLAllocHandle(SQL_HANDLE_DBC,
- SCN_henv,
- &SCN_hdbc);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a connection Handle!" << endl;
-
- // *******************
- // ** Connect to DB **
- // *******************
- retcode = SQLConnect(SCN_hdbc,
- (SQLCHAR *) connectString(),
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS);
-
- if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Connected to DB : OK!" << endl;
- else
- {
- ndbout << "Failure to Connect DB!" << endl;
- return NDBT_FAILED;
- }
- //*******************************
- //** Allocate statement handle **
- //*******************************
-
- retcode = SQLAllocHandle(SQL_HANDLE_STMT,
- SCN_hdbc,
- &SCN_hstmt);
-
- if(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a statement handle!" << endl;
-
- //************************
- //** Define a statement **
- //************************
-
- strcpy((char *) SQLStmt,
- "SELECT * FROM Customers WHERE Address = 'LM Vag 8'");
-
- //*************************
- //** Prepare a statement **
- //*************************
-
- retcode = SQLPrepare(SCN_hstmt,
- SQLStmt,
- SQL_NTS);
-
- //**********************************
- //** Set the cursor name with zero**
- //**********************************
- retcode = SQLSetCursorName(SCN_hstmt,
- (char *)"",
- SQL_NTS);
-
- if (retcode != SQL_SUCCESS)
- {
- ndbout << endl << "retcode =" << retcode << endl;
- SCN_DisplayError(SQL_HANDLE_STMT, SCN_hstmt);
- }
-
- //*************************
- //** Set the cursor name **
- //*************************
- retcode = SQLSetCursorName(SCN_hstmt,
- (char *)"Customer_CURSOR",
- SQL_NTS);
-
- if (retcode != SQL_SUCCESS)
- {
- ndbout << endl << "retcode =" << retcode << endl;
- SCN_DisplayError(SQL_HANDLE_STMT, SCN_hstmt);
- }
- //***************************
- //** Execute the statement **
- //***************************
- retcode = SQLExecute(SCN_hstmt);
-
- //**********************************************
- //** retrieve and display the new cursor name **
- //**********************************************
- retcode = SQLGetCursorName(SCN_hstmt,
- CursorName,
- sizeof(CursorName),
- &CNameSize);
-
- ndbout << endl << "The cursor name is : " << (char *) CursorName << endl;
-
- //****************
- // Free Handles **
- //****************
- SQLDisconnect(SCN_hdbc);
- SQLFreeHandle(SQL_HANDLE_STMT, SCN_hstmt);
- SQLFreeHandle(SQL_HANDLE_DBC, SCN_hdbc);
- SQLFreeHandle(SQL_HANDLE_ENV, SCN_henv);
-
- return NDBT_OK;
-
- }
-
-
-void SCN_DisplayError(SQLSMALLINT SCN_HandleType, SQLHDESC SCN_InputHandle)
-{
-
- SQLINTEGER NativeError;
- SQLCHAR Sqlstate[5], Msg[SCN_MESSAGE_LENGTH];
- SQLRETURN SQLSTATEs;
- SQLSMALLINT i, MsgLen;
- i = 1;
-
- ndbout << "-------------------------------------------------" << endl;
- ndbout << "Error diagnostics:" << endl;
-
- while ((SQLSTATEs = SQLGetDiagRec(SCN_HandleType,
- SCN_InputHandle, i,
- Sqlstate,
- &NativeError,
- Msg,
- sizeof(Msg),
- &MsgLen))
- != SQL_NO_DATA)
- {
-
- ndbout << "the HandleType is:" << SCN_HandleType << endl;
- ndbout << "the InputHandle is :" << (long)SCN_InputHandle << endl;
- ndbout << "the Msg is: " << (char *) Msg << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
- ndbout << "-------------------------------------------------" << endl;
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLSetDescFieldTest.cpp b/storage/ndb/test/odbc/client/SQLSetDescFieldTest.cpp
deleted file mode 100644
index da40b93caa8..00000000000
--- a/storage/ndb/test/odbc/client/SQLSetDescFieldTest.cpp
+++ /dev/null
@@ -1,100 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <common.h>
-
-using namespace std;
-
-#define NAME_LEN 50
-#define PHONE_LEN 10
-#define SALES_PERSON_LEN 10
-#define STATUS_LEN 6
-#define SQL_MAXIMUM_MESSAGE_LENGTH 200
-
-SQLHSTMT hstmt;
-SQLHDESC hdesc;
-
-SQLSMALLINT RecNumber;
-SQLCHAR szSalesPerson[SALES_PERSON_LEN];
-
-SQLCHAR Sqlstate[5], Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
-SQLINTEGER NativeError;
-SQLRETURN retcode, SQLSTATEs;
-
-SQLINTEGER ValuePtr1;
-SQLCHAR ValuePtr2;
-SQLSMALLINT ValuePtr3;
-
-SQLSMALLINT i, MsgLen;
-
-void SQLSetDescFieldTest_DisplayError(SQLSMALLINT HandleType, SQLHDESC InputHandle);
-
-int SQLSetDescFieldTest()
-{
-
- /* hstmt */
- // SQLPrepare a statement to select rows from the ORDERS Table. We can create the table and inside rows in
- // NDB by another program TestDirectSQL. In this test program(SQLGetDescRecTest),we only have three rows in
- // table ORDERS
-
-/* Prepare the SQL statement with parameter markers. */
-retcode = SQLPrepare(hstmt, (SQLCHAR *)"SELECT ORDERID, CUSTID, OPENDATE, SALESPERSON, STATUS FROM ORDERS)", SQL_NTS);
-
-/* SELECT OrderID, CustID, OpenDate, SalesPerson from Table ORDERS */
-
-if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
- retcode = SQLExecute(hstmt);
-if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
-
- /* If FI(FieldIdentifer) is not one of the code values in Table 20 */
-retcode = SQLSetDescField(hdesc, 1, 9999, &ValuePtr1, 128);
-if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SQLSetDescFieldTest_DisplayError(SQL_HANDLE_DESC, hdesc);
-
-
- /* RecoderNumber is less than 1 and the value of the Type column in the Table is ITEM */
-retcode = SQLSetDescField(hdesc, -1, SQL_DESC_LENGTH, &ValuePtr1, 128);
-if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SQLSetDescFieldTest_DisplayError(SQL_HANDLE_DESC, hdesc);
-
-
-}
-
-}
-
- return 0;
-
- }
-
-
-void SQLSetDescFieldTest_DisplayError(SQLSMALLINT HandleType, SQLHDESC InputHandle)
-{
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
-
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLSetDescRecTest.cpp b/storage/ndb/test/odbc/client/SQLSetDescRecTest.cpp
deleted file mode 100644
index e251d60b455..00000000000
--- a/storage/ndb/test/odbc/client/SQLSetDescRecTest.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NdbOut.hpp>
-#include <sqlext.h>
-#include <stdio.h>
-
-using namespace std;
-
-#define NAME_LEN 50
-#define PHONE_LEN 10
-#define SALES_PERSON_LEN 10
-#define STATUS_LEN 6
-#define SQL_MAXIMUM_MESSAGE_LENGTH 200
-
-SQLHSTMT hstmt;
-SQLHDESC hdesc;
-
-SQLSMALLINT RecNumber;
-SQLCHAR szSalesPerson[SALES_PERSON_LEN];
-
-SQLCHAR Sqlstate[5], Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
-SQLINTEGER NativeError;
-SQLRETURN retcode, SQLSTATEs;
-
-SQLCHAR Name;
-SQLINTEGER LengthPtr;
-
-SQLSMALLINT i, MsgLen;
-
-SQLINTEGER StringLengthPtr, IndicatorPtr;
-SQLPOINTER DataPtr;
-
-void SQLSetDescRecTest_DisplayError(SQLSMALLINT HandleType, SQLHDESC InputHandle);
-
-int SQLSetDescRecTest()
-{
-
- /* hstmt */
- // SQLPrepare a statement to select rows from the ORDERS Table. We can create the table and inside rows in
- // NDB by program TestDirectSQL. In this test program(SQLSetDescRecTest),we only have three rows in
- // table ORDERS
-
-/* Prepare the SQL statement with parameter markers. */
-retcode = SQLPrepare(hstmt, (SQLCHAR *)"SELECT ORDERID, CUSTID, OPENDATE, SALESPERSON, STATUS FROM ORDERS)", SQL_NTS);
-
-/* SELECT OrderID, CustID, OpenDate, SalesPerson from Table ORDERS */
-
-if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
-
- /* RecoderNumber is less than 1 */
-retcode = SQLSetDescRec(hdesc, -1, 1002, 1007, 1013, 1005, 1006, (void *)DataPtr, &StringLengthPtr, &IndicatorPtr);
-if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SQLSetDescRecTest_DisplayError(SQL_HANDLE_DESC, hdesc);
-
- /* RecoderNumber is greater than N, N be the value of the COUNT field of D, D be the allocated CLI */
- /* descriptor area identified by DescriptorHandle */
-retcode = SQLSetDescRec(hdesc, 4, 1002, 1007, 1013, 1005, 1006, (void *)DataPtr, &StringLengthPtr, &IndicatorPtr);
-if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SQLSetDescRecTest_DisplayError(SQL_HANDLE_DESC, hdesc);
-
-}
-
- return 0;
-
- }
-
-
-void SQLSetDescRecTest_DisplayError(SQLSMALLINT HandleType, SQLHDESC InputHandle)
-{
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
-
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLSetEnvAttrTest.cpp b/storage/ndb/test/odbc/client/SQLSetEnvAttrTest.cpp
deleted file mode 100644
index a9900202906..00000000000
--- a/storage/ndb/test/odbc/client/SQLSetEnvAttrTest.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <common.h>
-#define SQL_MAXIMUM_MESSAGE_LENGTH 200
-
-using namespace std;
-
-SQLHDBC hdbc;
-SQLHSTMT hstmt;
-SQLHENV henv;
-SQLHDESC hdesc;
-SQLRETURN retcode, SQLSTATEs;
-
-SQLPOINTER ValuePtr;
-SQLINTEGER SetEnvAttr_StringLength;
-
-SQLCHAR Sqlstate[5];
-
-SQLINTEGER NativeError;
-SQLSMALLINT i, MsgLen;
-SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
-
-void SetEnvAttr_DisplayError(SQLSMALLINT HandleType, SQLHENV InputHandle);
-
-int SQLSetEnvAttrTest()
-{
- /* ODBC attributes */
- /*
- char PtrValue1[3] = {'SQL_CP_OFF', 'SQL_CP_ONE_DRIVER', 'SQL_CP_ONE_PER_HENV'};
- for (i=0; i < 3; i++) {
- retcode = SQLSetEnvAttr(henv, SQL_ATTR_CONNECTION_POOLING, (void*)PtrValue1[i], sizeof(PtrValue1[i]));
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_ENV, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SetEnvAttr_DisplayError(SQL_HANDLE_ENV, henv);}
-
-
- char PtrValue2[2] = {'SQL_CP_STRICT_MATCH', 'SQL_CP_RELAXED_MATCH'};
- for (i=0; i < 2; i++) {
- retcode = SQLSetEnvAttr(henv, SQL_ATTR_CP_MATCH, (void*)PtrValue2[i], sizeof(PtrValue2[i]));
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_ENV, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SetEnvAttr_DisplayError(SQL_HANDLE_ENV, henv);}
-
-
- char PtrValue3[2] = {'SQL_OV_ODBC3', 'SQL_OV_ODBC2'};
- for (i=0; i < 2; i++) {
- retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)PtrValue3[i], sizeof(PtrValue3[i]));
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_ENV, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SetEnvAttr_DisplayError(SQL_HANDLE_ENV, henv);}
- */
-
- char PtrValue4[2] = {'SQL_TRUE', 'SQL_FALSE'};
- for (i=0; i < 2; i++) {
- retcode = SQLSetEnvAttr(henv, SQL_ATTR_OUTPUT_NTS, (void*)PtrValue4[i], sizeof(PtrValue4[i]));
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_ENV, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SetEnvAttr_DisplayError(SQL_HANDLE_ENV, henv);}
-
- return 0;
-
- }
-
-
-void SetEnvAttr_DisplayError(SQLSMALLINT HandleType, SQLHENV InputHandle)
-{
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
-
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLSetStmtAttrTest.cpp b/storage/ndb/test/odbc/client/SQLSetStmtAttrTest.cpp
deleted file mode 100644
index 4bebc33681f..00000000000
--- a/storage/ndb/test/odbc/client/SQLSetStmtAttrTest.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <common.h>
-#define SQL_MAXIMUM_MESSAGE_LENGTH 200
-
-using namespace std;
-
-SQLHDBC hdbc;
-SQLHSTMT hstmt;
-SQLHENV henv;
-SQLHDESC hdesc;
-SQLRETURN retcode, SQLSTATEs;
-
-SQLPOINTER ValuePtr;
-//SQLINTEGER StringLength;
-
-SQLCHAR Sqlstate[5];
-
-SQLINTEGER NativeError;
-SQLSMALLINT i, MsgLen;
-SQLCHAR Msg[SQL_MAXIMUM_MESSAGE_LENGTH];
-
-void SetStmtAttr_DisplayError(SQLSMALLINT HandleType, SQLHENV InputHandle);
-
-int SQLSetStmtAttrTest()
-{
- /* SQL/CLI attributes */
- /* SQL_ATTR_APP_PARAM_DESC */
- char PtrValue1[13] = {'SQL_NULL_DESC'};
- for (i=0; i < 1; i++) {
- retcode = SQLSetStmtAttr(hstmt, SQL_ATTR_APP_PARAM_DESC, (void*)PtrValue1[i], sizeof(PtrValue1[i]));
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_STMT, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SetStmtAttr_DisplayError(SQL_HANDLE_STMT, hstmt);}
-
- /* SQL_ATTR_APP_ROW_DESC */
- char PtrValue2[1] = {'SQL_NULL_DESC'}; /* ? */
- for (i=0; i < 2; i++) {
- retcode = SQLSetStmtAttr(hstmt, SQL_ATTR_APP_ROW_DESC, (void*)PtrValue2[i], sizeof(PtrValue2[i]));
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_STMT, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SetStmtAttr_DisplayError(SQL_HANDLE_STMT, hstmt);}
-
- /* SQL_ATTR_CURSOR_SCROLLABLE */
- char PtrValue3[2] = {'SQL_NONSCROLLABLE', 'SQL_SCROLLABLE'}; /* ? */
- for (i=0; i < 2; i++) {
- retcode = SQLSetStmtAttr(hstmt, SQL_ATTR_CURSOR_SCROLLABLE, (void*)PtrValue3[i], sizeof(PtrValue3[i]));
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_STMT, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SetStmtAttr_DisplayError(SQL_HANDLE_STMT, hstmt);}
-
- /* SQL_ATTR_CURSOR_SENSITIVITY */
- char PtrValue4[3] = {'SQL_UNSPECIFIED', 'SQL_INSENSITIVE', 'SQL_SENSITIVE'}; /* ? */
- for (i=0; i < 3; i++) {
- retcode = SQLSetStmtAttr(hstmt, SQL_ATTR_CURSOR_SENSITIVITY, (void*)PtrValue4[i], sizeof(PtrValue4[i]));
-
- if (retcode == SQL_INVALID_HANDLE)
- ndbout << "Handle Type is SQL_HANDLE_STMT, but string SQL_INVALID_HANDLE still appeared. Please check programm" << endl;
-
- if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
- SetStmtAttr_DisplayError(SQL_HANDLE_STMT, hstmt);}
-
- return 0;
-
- }
-
-
-void SetStmtAttr_DisplayError(SQLSMALLINT HandleType, SQLHENV InputHandle)
-{
- i = 1;
- while ((SQLSTATEs = SQLGetDiagRec(HandleType, InputHandle, i,
- Sqlstate, &NativeError, Msg, sizeof(Msg),
- &MsgLen)) != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << HandleType << endl;
- ndbout << "the InputHandle is :" << InputHandle << endl;
- ndbout << "the output state is:" << (char *)Sqlstate << endl;
-
- i ++;
- }
-
-}
-
-
-
diff --git a/storage/ndb/test/odbc/client/SQLTablesTest.cpp b/storage/ndb/test/odbc/client/SQLTablesTest.cpp
deleted file mode 100644
index d9d8e386fcf..00000000000
--- a/storage/ndb/test/odbc/client/SQLTablesTest.cpp
+++ /dev/null
@@ -1,227 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
- /**
- * @file SQLTablesTest.cpp
- */
-#include <common.hpp>
-using namespace std;
-
-#define Tables_NAME_LEN 12
-#define Tables_PHONE_LEN 12
-#define Tables_ADDRESS_LEN 12
-#define Tables_SQL_MAXIMUM_MESSAGE_LENGTH 200
-
-SQLHDBC Tables_hdbc;
-SQLHSTMT Tables_hstmt;
-SQLHENV Tables_henv;
-SQLHDESC Tables_hdesc;
-
-void Tables_DisplayError(SQLSMALLINT Tables_HandleType,
- SQLHSTMT Tables_InputHandle);
-
-/**
- * Test to retrieve a list of table names stored in aspecified
- * data source's system
- *
- * -# Normal case test: print out the table name in the data result set
- * @return Zero, if test succeeded
- */
-
-int SQLTablesTest()
-{
- SQLRETURN Tables_retcode;
- SQLCHAR Tables_Name[Tables_NAME_LEN], Tables_Phone[Tables_PHONE_LEN];
- SQLCHAR Tables_Address[Tables_ADDRESS_LEN];
- SQLINTEGER Tables_CustID;
-
- ndbout << endl << "Start SQLTables Testing" << endl;
-
- //*******************************************************************
- //** hstmt
- //** Execute a statement to retrieve rows from the Customers table **
- //** We can create the table and insert rows into Customers **
- //*******************************************************************
-
- //************************************
- //** Allocate An Environment Handle **
- //************************************
- Tables_retcode = SQLAllocHandle(SQL_HANDLE_ENV,
- SQL_NULL_HANDLE,
- &Tables_henv);
-
-if (Tables_retcode == SQL_SUCCESS || Tables_retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated an environment Handle!" << endl;
-
- //*********************************************
- //** Set the ODBC application Version to 3.x **
- //*********************************************
- Tables_retcode = SQLSetEnvAttr(Tables_henv,
- SQL_ATTR_ODBC_VERSION,
- (SQLPOINTER) SQL_OV_ODBC3,
- SQL_IS_UINTEGER);
-
-if (Tables_retcode == SQL_SUCCESS || Tables_retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Set the ODBC application Version to 3.x!" << endl;
-
- //**********************************
- //** Allocate A Connection Handle **
- //**********************************
-
- Tables_retcode = SQLAllocHandle(SQL_HANDLE_DBC,
- Tables_henv,
- &Tables_hdbc);
-
-if (Tables_retcode == SQL_SUCCESS || Tables_retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a connection Handle!" << endl;
-
- // *******************
- // ** Connect to DB **
- // *******************
- Tables_retcode = SQLConnect(Tables_hdbc,
- (SQLCHAR *) connectString(),
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS);
-
-if (Tables_retcode == SQL_SUCCESS || Tables_retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Connected to DB : OK!" << endl;
- else
- {
- ndbout << "Failure to Connect DB!" << endl;
- return NDBT_FAILED;
- }
-
- //*******************************
- //** Allocate statement handle **
- //*******************************
-
- Tables_retcode = SQLAllocHandle(SQL_HANDLE_STMT,
- Tables_hdbc,
- &Tables_hstmt);
-
-if (Tables_retcode == SQL_SUCCESS || Tables_retcode == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a statement handle!" << endl;
-
- //**************************************************************
- //** Retrieve information about the tables in the data source **
- //**************************************************************
- Tables_retcode = SQLTables(Tables_hstmt,
- NULL,
- 0,
- NULL,
- 0,
- (SQLCHAR *)"%",
- 128,
- (SQLCHAR *)"TABLES",
- 128);
-
- ndbout <<"Tables_retcode = SQLTables() =" << Tables_retcode;
-
- if (Tables_retcode == SQL_ERROR)
- Tables_DisplayError(SQL_HANDLE_STMT, Tables_hstmt);
- //*******************************************
- //** Bind columns 3 in the result data set **
- //*******************************************
-
- Tables_retcode = SQLBindCol(Tables_hstmt,
- 3,
- SQL_C_CHAR,
- &Tables_Name,
- Tables_NAME_LEN,
- NULL);
-
- ndbout <<"Tables_retcode = SQLBindCol() =" << Tables_retcode;
-
- //**********************************************
- //* Fetch and print out data in the result On **
- //* an error, display a message and exit **
- //**********************************************
-
- Tables_retcode = SQLFetch(Tables_hstmt);
-
-
- ndbout <<"Tables_retcode = SQLFetch() =" << Tables_retcode;
-
- ndbout << endl << "Tables_retcode = SQLFetch(Tables_hstmt) = "
- << Tables_retcode << endl;
-
- if (Tables_retcode == SQL_ERROR)
- {
- Tables_DisplayError(SQL_HANDLE_STMT, Tables_hstmt);
- return NDBT_FAILED;
- }
- else if (Tables_retcode == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "Table Name = " << (char *)Tables_Name << endl;
- Tables_DisplayError(SQL_HANDLE_STMT, Tables_hstmt);
- }
- else if (Tables_retcode == SQL_NO_DATA)
- Tables_DisplayError(SQL_HANDLE_STMT, Tables_hstmt);
- else
- {
- ndbout << "TableName = " << (char *)Tables_Name << endl;
- Tables_DisplayError(SQL_HANDLE_STMT, Tables_hstmt);
- }
-
- // *********************************
- // ** Disconnect and Free Handles **
- // *********************************
- SQLDisconnect(Tables_hdbc);
- SQLFreeHandle(SQL_HANDLE_STMT, Tables_hstmt);
- SQLFreeHandle(SQL_HANDLE_DBC, Tables_hdbc);
- SQLFreeHandle(SQL_HANDLE_ENV, Tables_henv);
-
- return NDBT_OK;
-}
-
-void Tables_DisplayError(SQLSMALLINT Tables_HandleType,
- SQLHSTMT Tables_InputHandle)
-{
- SQLINTEGER NativeError;
- SQLSMALLINT Tables_i = 1;
- SQLRETURN Tables__SQLSTATEs;
- SQLCHAR Tables_Sqlstate[5];
- SQLCHAR Tables_Msg[Tables_SQL_MAXIMUM_MESSAGE_LENGTH];
- SQLSMALLINT Tables_MsgLen;
-
- ndbout << "-------------------------------------------------" << endl;
- ndbout << "Error diagnostics:" << endl;
-
- while ((Tables__SQLSTATEs = SQLGetDiagRec(Tables_HandleType,
- Tables_InputHandle,
- Tables_i,
- Tables_Sqlstate,
- &NativeError,
- Tables_Msg,
- sizeof(Tables_Msg),
- &Tables_MsgLen)
- ) != SQL_NO_DATA)
- {
-
- ndbout << "the HandleType is:" << Tables_HandleType << endl;
- ndbout << "the InputHandle is :" << (long)Tables_InputHandle << endl;
- ndbout << "the Tables_Msg is: " << (char *) Tables_Msg << endl;
- ndbout << "the output state is:" << (char *)Tables_Sqlstate << endl;
-
- Tables_i ++;
- break;
- }
- ndbout << "-------------------------------------------------" << endl;
-}
-
diff --git a/storage/ndb/test/odbc/client/SQLTransactTest.cpp b/storage/ndb/test/odbc/client/SQLTransactTest.cpp
deleted file mode 100644
index 50346b658c6..00000000000
--- a/storage/ndb/test/odbc/client/SQLTransactTest.cpp
+++ /dev/null
@@ -1,305 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
- /**
- * @file SQLTransactTest.cpp
- */
-#include <common.hpp>
-#define STR_MESSAGE_LENGTH 200
-#define STR_NAME_LEN 20
-#define STR_PHONE_LEN 20
-#define STR_ADDRESS_LEN 20
-using namespace std;
-
-SQLHDBC STR_hdbc;
-SQLHSTMT STR_hstmt;
-SQLHENV STR_henv;
-SQLHDESC STR_hdesc;
-
-void Transact_DisplayError(SQLSMALLINT STR_HandleType,
- SQLHSTMT STR_InputHandle);
-
-int STR_Display_Result(SQLHSTMT EXDR_InputHandle);
-
-/**
- * Test:
- * -#Test to request a commit or a rollback operation for
- * all active transactions associated with a specific
- * environment or connection handle
- *
- * @return Zero, if test succeeded
- */
-
-int SQLTransactTest()
-{
- SQLRETURN STR_ret;
-
- ndbout << endl << "Start SQLTransact Testing" << endl;
-
- //************************************
- //** Allocate An Environment Handle **
- //************************************
- STR_ret = SQLAllocHandle(SQL_HANDLE_ENV,
- SQL_NULL_HANDLE,
- &STR_henv);
-
- if (STR_ret == SQL_SUCCESS || STR_ret == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated an environment Handle!" << endl;
-
- //*********************************************
- //** Set the ODBC application Version to 3.x **
- //*********************************************
- STR_ret = SQLSetEnvAttr(STR_henv,
- SQL_ATTR_ODBC_VERSION,
- (SQLPOINTER) SQL_OV_ODBC3,
- SQL_IS_UINTEGER);
-
- if (STR_ret == SQL_SUCCESS || STR_ret == SQL_SUCCESS_WITH_INFO)
- ndbout << "Set the ODBC application Version to 3.x!" << endl;
-
- //**********************************
- //** Allocate A Connection Handle **
- //**********************************
-
- STR_ret = SQLAllocHandle(SQL_HANDLE_DBC,
- STR_henv,
- &STR_hdbc);
-
- if (STR_ret == SQL_SUCCESS || STR_ret == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a connection Handle!" << endl;
-
- // *******************
- // ** Connect to DB **
- // *******************
- STR_ret = SQLConnect(STR_hdbc,
- (SQLCHAR *) connectString(),
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS,
- (SQLCHAR *) "",
- SQL_NTS);
-
- if (STR_ret == SQL_SUCCESS || STR_ret == SQL_SUCCESS_WITH_INFO)
- ndbout << "Connected to DB : OK!" << endl;
- else
- {
- ndbout << "Failure to Connect DB!" << endl;
- return NDBT_FAILED;
- }
-
- //*******************************
- //** Allocate statement handle **
- //*******************************
-
- STR_ret = SQLAllocHandle(SQL_HANDLE_STMT,
- STR_hdbc,
- &STR_hstmt);
- if(STR_ret == SQL_SUCCESS || STR_ret == SQL_SUCCESS_WITH_INFO)
- ndbout << "Allocated a statement handle!" << endl;
-
- //********************************
- //** Turn Manual-Commit Mode On **
- //********************************
- STR_ret = SQLSetConnectOption(STR_hdbc,
- SQL_AUTOCOMMIT,
- (UDWORD) SQL_AUTOCOMMIT_OFF);
-
- //**********************************************
- //** Prepare and Execute a prepared statement **
- //**********************************************
- STR_ret = SQLExecDirect(STR_hstmt,
- (SQLCHAR*)"SELECT * FROM Customers",
- SQL_NTS);
-
- if (STR_ret == SQL_INVALID_HANDLE)
- {
- ndbout << "Handle Type is SQL_HANDLE_STMT, but SQL_INVALID_HANDLE"
- << endl;
- ndbout << "still appeared. Please check program" << endl;
- }
-
- if (STR_ret == SQL_ERROR || STR_ret == SQL_SUCCESS_WITH_INFO)
- Transact_DisplayError(SQL_HANDLE_STMT, STR_hstmt);
-
- //*************************
- //** Display the results **
- //*************************
-
- STR_Display_Result(STR_hstmt);
-
- //****************************
- //** Commit the transaction **
- //****************************
- STR_ret = SQLTransact(STR_henv,
- STR_hdbc,
- SQL_COMMIT);
-
- //****************
- // Free Handles **
- //****************
- SQLDisconnect(STR_hdbc);
- SQLFreeHandle(SQL_HANDLE_STMT, STR_hstmt);
- SQLFreeHandle(SQL_HANDLE_DBC, STR_hdbc);
- SQLFreeHandle(SQL_HANDLE_ENV, STR_henv);
-
- return NDBT_OK;
-
- }
-
-void Transact_DisplayError(SQLSMALLINT STR_HandleType,
- SQLHSTMT STR_InputHandle)
-{
- SQLCHAR STR_Sqlstate[5];
- SQLINTEGER STR_NativeError;
- SQLSMALLINT STR_i, STR_MsgLen;
- SQLCHAR STR_Msg[STR_MESSAGE_LENGTH];
- SQLRETURN SQLSTATEs;
- STR_i = 1;
-
- ndbout << "-------------------------------------------------" << endl;
- ndbout << "Error diagnostics:" << endl;
-
- while ((SQLSTATEs = SQLGetDiagRec(STR_HandleType,
- STR_InputHandle,
- STR_i,
- STR_Sqlstate,
- &STR_NativeError,
- STR_Msg,
- sizeof(STR_Msg),
- &STR_MsgLen))
- != SQL_NO_DATA) {
-
- ndbout << "the HandleType is:" << STR_HandleType << endl;
- ndbout << "the InputHandle is :" << (long)STR_InputHandle << endl;
- ndbout << "the STR_Msg is: " << (char *) STR_Msg << endl;
- ndbout << "the output state is:" << (char *)STR_Sqlstate << endl;
-
- STR_i ++;
- // break;
- }
- ndbout << "-------------------------------------------------" << endl;
-}
-
-int STR_Display_Result(SQLHSTMT STR_InputHandle)
-{
- SQLRETURN STR_retcode;
- unsigned long STR_CustID;
- SQLCHAR STR_Name[STR_NAME_LEN], STR_Phone[STR_PHONE_LEN];
- SQLCHAR STR_Address[STR_ADDRESS_LEN];
-
- //*********************
- //** Bind columns 1 **
- //*********************
- STR_retcode =SQLBindCol(STR_InputHandle,
- 1,
- SQL_C_ULONG,
- &STR_CustID,
- sizeof(STR_CustID),
- NULL);
- if (STR_retcode == SQL_ERROR)
- {
- ndbout << "Executing SQLBindCol, SQL_ERROR happened!" << endl;
- Transact_DisplayError(SQL_HANDLE_STMT, STR_InputHandle);
- return NDBT_FAILED;
- }
-
- //*********************
- //** Bind columns 2 **
- //*********************
-
- STR_retcode =SQLBindCol(STR_InputHandle,
- 2,
- SQL_C_CHAR,
- &STR_Name,
- STR_NAME_LEN,
- NULL);
- if (STR_retcode == SQL_ERROR)
- {
- ndbout << "Executing SQLBindCol, SQL_ERROR happened!" << endl;
- Transact_DisplayError(SQL_HANDLE_STMT, STR_InputHandle);
- return NDBT_FAILED;
- }
-
- //*********************
- //** Bind columns 3 **
- //*********************
-
- STR_retcode = SQLBindCol(STR_InputHandle,
- 3,
- SQL_C_CHAR,
- &STR_Address,
- STR_ADDRESS_LEN,
- NULL);
-
- if (STR_retcode == SQL_ERROR)
- {
- ndbout << "Executing SQLBindCol, SQL_ERROR happened!" << endl;
- Transact_DisplayError(SQL_HANDLE_STMT, STR_InputHandle);
- return NDBT_FAILED;
- }
-
- //*********************
- //** Bind columns 4 **
- //*********************
-
- STR_retcode = SQLBindCol(STR_InputHandle,
- 4,
- SQL_C_CHAR,
- &STR_Phone,
- STR_PHONE_LEN,
- NULL);
-
- if (STR_retcode == SQL_ERROR)
- {
- ndbout << "Executing SQLBindCol, SQL_ERROR happened!" << endl;
- Transact_DisplayError(SQL_HANDLE_STMT, STR_InputHandle);
- return NDBT_FAILED;
- }
-
- //*****************************************
- //* Fetch and print each row of data. On **
- //* an error, display a message and exit **
- //*****************************************
-
- if (STR_retcode != SQL_ERROR)
- STR_retcode = SQLFetch(STR_InputHandle);
-
- ndbout << endl << "STR_retcode = SQLFetch(STR_InputHandle) = "
- << STR_retcode << endl;
-
- if (STR_retcode == SQL_ERROR)
- {
- ndbout << "Executing SQLFetch, SQL_ERROR happened!" << endl;
- Transact_DisplayError(SQL_HANDLE_STMT, STR_InputHandle);
- return NDBT_FAILED;
- }
- else if (STR_retcode == SQL_SUCCESS_WITH_INFO)
- {
- ndbout << "CustID = " << (int)STR_CustID << endl;
- ndbout << "Name = " << (char *)STR_Name << endl;
- ndbout << "Address = " << (char *)STR_Address << endl;
- ndbout << "Phone = " << (char *)STR_Phone << endl;
- Transact_DisplayError(SQL_HANDLE_STMT, STR_InputHandle);
- }
- else
- {
- ndbout << "CustID = " << (int)STR_CustID << endl;
- ndbout << "Name = " << (char *)STR_Name << endl;
- ndbout << "Address = " << (char *)STR_Address << endl;
- ndbout << "Phone = " << (char *)STR_Phone << endl;
- }
- return 0;
-}
diff --git a/storage/ndb/test/odbc/client/common.hpp b/storage/ndb/test/odbc/client/common.hpp
deleted file mode 100644
index def7a8721fb..00000000000
--- a/storage/ndb/test/odbc/client/common.hpp
+++ /dev/null
@@ -1,81 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NdbOut.hpp>
-#include <NDBT.hpp>
-#include <sqlext.h>
-#include <stdio.h>
-#include <string.h>
-#define FAILURE(msg) { ndbout << "TEST FAILURE: " << msg << endl \
- << "-- File: " << __FILE__ << ", Line: " << __LINE__ << endl; \
- return NDBT_FAILED; }
-
-char* connectString();
-
-int SQLFetchTest();
-int SQLDisconnectTest();
-int SQLTablesTest();
-int SQLBindColTest();
-int SQLGetInfoTest();
-int SQLGetTypeInfoTest();
-int SQLGetDataTest();
-int SQLGetFunctionsTest();
-int SQLColAttributeTest();
-int SQLColAttributeTest1();
-int SQLColAttributeTest2();
-int SQLColAttributeTest3();
-int SQLGetDiagRecSimpleTest();
-int SQLDriverConnectTest();
-int SQLAllocEnvTest();
-int SQLFreeHandleTest();
-int SQLFetchScrollTest();
-int SQLFetchTest();
-int SQLGetDescRecTest();
-int SQLSetDescFieldTest();
-int SQLGetDescFieldTest();
-int SQLSetDescRecTest();
-int SQLSetCursorNameTest();
-int SQLGetCursorNameTest();
-int SQLRowCountTest();
-int SQLGetInfoTest();
-int SQLTransactTest();
-int SQLEndTranTest();
-int SQLNumResultColsTest();
-int SQLGetTypeInfoTest();
-int SQLGetFunctionsTest();
-int SQLDescribeColTest();
-int SQLAllocHandleTest();
-int SQLCancelTest();
-int SQLCloseCursorTest();
-int SQLConnectTest();
-int SQLDisconnectTest();
-int SQLExecDirectTest();
-int SQLExecuteTest();
-int SQLFreeHandleTest();
-int SQLFreeStmtTest();
-int SQLGetConnectAttrTest();
-int SQLGetEnvAttrTest();
-int SQLGetStmtAttrTest();
-int SQLMoreResultsTest();
-int SQLPrepareTest();
-int SQLSetConnectAttrTest();
-int SQLSetEnvAttrTest();
-int SQLSetStmtAttrTest();
-
-// int NDBT_ALLOCHANDLE();
-// int NDBT_ALLOCHANDLE_HDBC();
-// int NDBT_SQLPrepare();
-// int NDBT_SQLConnect();
diff --git a/storage/ndb/test/odbc/client/main.cpp b/storage/ndb/test/odbc/client/main.cpp
deleted file mode 100644
index 8748faede06..00000000000
--- a/storage/ndb/test/odbc/client/main.cpp
+++ /dev/null
@@ -1,158 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
- /**
- * @file main.cpp
- */
-
-#include <common.hpp>
-
-/**
- * main ODBC Tests
- *
- * Tests main ODBC functions.
- */
-
-#include <common.hpp>
-
-int check = NDBT_OK;
-static char* myConnectString;
-
-char* connectString()
-{
- return myConnectString;
-}
-
-int main(int argc, char** argv)
-{
-
- if (argc != 3) {
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
- myConnectString = argv[1];
-
- if ( strcmp(argv[2], "help") == 0 )
- {
- ndbout << "Number of Testing Program " << " Name of Testing Program" << endl;
- ndbout << " 1 SQLGetDataTest()" << endl;
- ndbout << " 2 SQLTablesTest()" << endl;
- ndbout << " 3 SQLGetFunctionsTest()" << endl;
- ndbout << " 4 SQLGetInfoTest()" << endl;
- ndbout << " 5 SQLGetTypeInfoTest()" << endl;
- ndbout << " 6 SQLDisconnectTest()" << endl;
- ndbout << " 7 SQLFetchTest()" << endl;
- ndbout << " 8 SQLRowCountTest()" << endl;
- ndbout << " 9 SQLGetCursorNameTest()" << endl;
- ndbout << " 10 SQLCancelTest()" << endl;
- ndbout << " 11 SQLTransactTest()" << endl;
- ndbout << " 12 SQLSetCursorNameTest()" << endl;
- ndbout << " 13 SQLNumResultColsTest()" << endl;
- ndbout << " 14 SQLDescribeColTest()" << endl;
- ndbout << " 15 SQLExecDirectTest()" << endl;
- ndbout << " 16 SQLColAttributeTest3()" << endl;
- ndbout << " 17 SQLColAttributeTest2()" << endl;
- ndbout << " 18 SQLColAttributeTest1()" << endl;
- ndbout << " 19 SQLColAttributeTest()" << endl;
- ndbout << " 20 SQLBindColTest()" << endl;
- ndbout << " 21 SQLGetDiagRecSimpleTest()" << endl;
- ndbout << " 22 SQLConnectTest()" << endl;
- ndbout << " 23 SQLPrepareTest()" << endl;
- }
- else
- {
-
- ndbout << endl << "Executing Files Name = " << argv[0] << endl;
- ndbout << "The Number of testing program = " << argv[2] << endl;
-
- int i = atoi(argv[2]);
- switch (i) {
- case 1:
- if (check == NDBT_OK) check = SQLGetDataTest();
- break;
- case 2:
- if (check == NDBT_OK) check = SQLTablesTest();
- break;
- case 3:
- if (check == NDBT_OK) check = SQLGetFunctionsTest();
- break;
- case 4:
- if (check == NDBT_OK) check = SQLGetInfoTest();
- break;
- case 5:
- if (check == NDBT_OK) check = SQLGetTypeInfoTest();
- break;
- case 6:
- if (check == NDBT_OK) check = SQLDisconnectTest();
- break;
- case 7:
- if (check == NDBT_OK) check = SQLFetchTest();
- break;
- case 8:
- if (check == NDBT_OK) check = SQLRowCountTest();
- break;
- case 9:
- if (check == NDBT_OK) check = SQLGetCursorNameTest();
- break;
- case 10:
- if (check == NDBT_OK) check = SQLCancelTest();
- break;
- case 11:
- if (check == NDBT_OK) check = SQLTransactTest();
- break;
- case 12:
- if (check == NDBT_OK) check = SQLSetCursorNameTest();
- break;
- case 13:
- if (check == NDBT_OK) check = SQLNumResultColsTest();
- break;
- case 14:
- if (check == NDBT_OK) check = SQLDescribeColTest();
- break;
- case 15:
- if (check == NDBT_OK) check = SQLExecDirectTest();
- break;
- case 16:
- if (check == NDBT_OK) check = SQLColAttributeTest3();
- break;
- case 17:
- if (check == NDBT_OK) check = SQLColAttributeTest2();
- break;
- case 18:
- if (check == NDBT_OK) check = SQLColAttributeTest1();
- break;
- case 19:
- if (check == NDBT_OK) check = SQLColAttributeTest();
- break;
- case 20:
- if (check == NDBT_OK) check = SQLBindColTest();
- break;
- case 21:
- if (check == NDBT_OK) check = SQLGetDiagRecSimpleTest();
- break;
- case 22:
- if (check == NDBT_OK) check = SQLConnectTest();
- break;
- case 23:
- if (check == NDBT_OK) check = SQLPrepareTest();
- break;
- }
- }
-
- return NDBT_ProgramExit(check);
-}
-
-
-
diff --git a/storage/ndb/test/odbc/dm-iodbc/Makefile b/storage/ndb/test/odbc/dm-iodbc/Makefile
deleted file mode 100644
index ad0f0d39f5f..00000000000
--- a/storage/ndb/test/odbc/dm-iodbc/Makefile
+++ /dev/null
@@ -1,38 +0,0 @@
-include .defs.mk
-
-TYPE = *
-
-BIN_TARGET = testOdbcDMi
-
-SOURCES = testOdbcDMi.cpp
-
-CCFLAGS_LOC += \
- -I$(NDB_TOP)/include \
- -I$(NDB_TOP)/include/ndbapi \
- -I$(NDB_TOP)/include/portlib \
- -I$(NDB_TOP)/include/util \
- -I$(NDB_TOP)/test/include
-
-CCFLAGS_WARNINGS += -Wno-unused -Wno-sign-compare
-
-CCFLAGS_TOP += -DHAVE_LONG_LONG -DiODBC
-
-BIN_TARGET_LIBS = NDBT general portlib
-
-ifeq ($(NDB_OS),SOLARIS)
-CCFLAGS_TOP += -DDMALLOC
-LIBS_LOC += -L/usr/local/opt/iODBC/lib
-LIBS_LOC += -R/usr/local/opt/iODBC/lib
-BIN_TARGET_LIBS += iodbc
-BIN_TARGET_LIBS += dmallocthcxx
-endif
-
-ifeq ($(NDB_OS),LINUX)
-BIN_TARGET_LIBS_DIRS += /usr/local/opt/iODBC/lib
-BIN_TARGET_LIBS += iodbc
-endif
-
-include $(NDB_TOP)/Epilogue.mk
-
-testOdbcDMi.cpp:
- ln -s ../driver/testOdbcDriver.cpp $@
diff --git a/storage/ndb/test/odbc/dm-unixodbc/Makefile b/storage/ndb/test/odbc/dm-unixodbc/Makefile
deleted file mode 100644
index 50d8e3b5e05..00000000000
--- a/storage/ndb/test/odbc/dm-unixodbc/Makefile
+++ /dev/null
@@ -1,39 +0,0 @@
-include .defs.mk
-
-TYPE = *
-
-BIN_TARGET = testOdbcDMu
-
-SOURCES = testOdbcDMu.cpp
-
-CCFLAGS_LOC += \
- -I$(NDB_TOP)/include \
- -I$(NDB_TOP)/include/ndbapi \
- -I$(NDB_TOP)/include/portlib \
- -I$(NDB_TOP)/include/util \
- -I$(NDB_TOP)/test/include
-
-CCFLAGS_WARNINGS += -Wno-unused -Wno-sign-compare
-
-CCFLAGS_TOP += -DHAVE_LONG_LONG -DunixODBC
-
-BIN_TARGET_LIBS = NDBT general portlib
-
-ifeq ($(NDB_OS),SOLARIS)
-CCFLAGS_TOP += -DDMALLOC
-LIBS_LOC += -L/usr/local/lib
-BIN_TARGET_LIBS += odbc odbcinst
-BIN_TARGET_LIBS += dmallocthcxx
-endif
-
-ifeq ($(NDB_OS),LINUX)
-BIN_TARGET_LIBS += odbc odbcinst
-BIN_TARGET_LIBS_DIRS += .
-dummy := $(shell [ ! -f /usr/lib/libodbc.so ] || ln -sf /usr/lib/libodbc.so.1 libodbc.so)
-dummy := $(shell [ ! -f /usr/lib/libodbcinst.so ] || ln -sf /usr/lib/libodbcinst.so.1 libodbcinst.so)
-endif
-
-include $(NDB_TOP)/Epilogue.mk
-
-testOdbcDMu.cpp:
- ln -s ../driver/testOdbcDriver.cpp $@
diff --git a/storage/ndb/test/odbc/driver/Makefile b/storage/ndb/test/odbc/driver/Makefile
deleted file mode 100644
index 5cf83d73106..00000000000
--- a/storage/ndb/test/odbc/driver/Makefile
+++ /dev/null
@@ -1,30 +0,0 @@
-include .defs.mk
-
-TYPE = *
-
-BIN_TARGET = testOdbcDriver
-
-SOURCES = testOdbcDriver.cpp
-
-CCFLAGS_LOC += \
- -I$(NDB_TOP)/include \
- -I$(NDB_TOP)/include/ndbapi \
- -I$(NDB_TOP)/include/portlib \
- -I$(NDB_TOP)/include/util \
- -I$(NDB_TOP)/test/include \
- -I/usr/local/include
-
-CCFLAGS_WARNINGS += -Wno-unused -Wno-sign-compare -Wformat
-
-CCFLAGS_TOP += -DHAVE_LONG_LONG -DndbODBC
-
-BIN_TARGET_LIBS = NDBT NDB_ODBC
-
-ifeq ($(NDB_OS),SOLARIS)
-BIN_TARGET_LIBS += dmallocthcxx
-CCFLAGS_TOP += -DDMALLOC
-endif
-
-include $(NDB_TOP)/Epilogue.mk
-
-$(BIN_DIR)$(BIN_TARGET): Makefile
diff --git a/storage/ndb/test/odbc/driver/testOdbcDriver.cpp b/storage/ndb/test/odbc/driver/testOdbcDriver.cpp
deleted file mode 100644
index d58755440ac..00000000000
--- a/storage/ndb/test/odbc/driver/testOdbcDriver.cpp
+++ /dev/null
@@ -1,4948 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-/*
- * testOdbcDriver
- *
- * Test of ODBC and SQL using a fixed set of tables.
- */
-
-#include <ndb_global.h>
-#undef test
-#include <ndb_version.h>
-#include <kernel/ndb_limits.h>
-#include <Bitmask.hpp>
-#include <kernel/AttributeList.hpp>
-#ifdef ndbODBC
-#include <NdbApi.hpp>
-#endif
-#include <sqlext.h>
-
-#undef BOOL
-
-#include <NdbMain.h>
-#include <NdbOut.hpp>
-#include <NdbThread.h>
-#include <NdbMutex.h>
-#include <NdbCondition.h>
-#include <NdbTick.h>
-#include <NdbSleep.h>
-
-#ifdef ndbODBC
-#include <NdbTest.hpp>
-#else
-#define NDBT_OK 0
-#define NDBT_FAILED 1
-#define NDBT_WRONGARGS 2
-static int
-NDBT_ProgramExit(int rcode)
-{
- const char* rtext = "Unknown";
- switch (rcode) {
- case NDBT_OK:
- rtext = "OK";
- break;
- case NDBT_FAILED:
- rtext = "Failed";
- break;
- case NDBT_WRONGARGS:
- rtext = "Wrong arguments";
- break;
- };
- ndbout_c("\nNDBT_ProgramExit: %d - %s\n", rcode, rtext);
- return rcode;
-}
-#endif
-
-#ifdef DMALLOC
-#include <dmalloc.h>
-#endif
-
-#define arraySize(x) (sizeof(x)/sizeof(x[0]))
-
-#define SQL_ATTR_NDB_TUPLES_FETCHED 66601
-
-// options
-
-#define MAX_THR 128 // max threads
-
-struct Opt {
- const char* m_name[100];
- unsigned m_namecnt;
- bool m_core;
- unsigned m_depth;
- const char* m_dsn;
- unsigned m_errs;
- const char* m_fragtype;
- unsigned m_frob;
- const char* m_home;
- unsigned m_loop;
- bool m_nogetd;
- bool m_noputd;
- bool m_nosort;
- unsigned m_scale;
- bool m_serial;
- const char* m_skip[100];
- unsigned m_skipcnt;
- unsigned m_subloop;
- const char* m_table;
- unsigned m_threads;
- unsigned m_trace;
- unsigned m_v;
- Opt() :
- m_namecnt(0),
- m_core(false),
- m_depth(5),
- m_dsn("NDB"),
- m_errs(0),
- m_fragtype(0),
- m_frob(0),
- m_home(0),
- m_loop(1),
- m_nogetd(false),
- m_noputd(false),
- m_nosort(false),
- m_scale(100),
- m_serial(false),
- m_skipcnt(0),
- m_subloop(1),
- m_table(0),
- m_threads(1),
- m_trace(0),
- m_v(1) {
- for (unsigned i = 0; i < arraySize(m_name); i++)
- m_name[i] = 0;
- for (unsigned i = 0; i < arraySize(m_skip); i++)
- m_skip[i] = 0;
- }
-};
-
-static Opt opt;
-
-static void listCases();
-static void listTables();
-static void printusage()
-{
- Opt d;
- ndbout
- << "usage: testOdbcDriver [options]" << endl
- << "-case name run only named tests (substring match - can be repeated)" << endl
- << "-core dump core on failure" << endl
- << "-depth N join depth - default " << d.m_depth << endl
- << "-dsn string data source name - default " << d.m_dsn << endl
- << "-errs N allow N errors before quitting - default " << d.m_errs << endl
- << "-fragtype t fragment type single/small/medium/large" << d.m_errs << endl
- << "-frob X case-dependent tweak (number)" << endl
- << "-home dir set NDB_HOME (contains Ndb.cfg)" << endl
- << "-loop N loop N times (0 = forever) - default " << d.m_loop << endl
- << "-nogetd do not use SQLGetData - default " << d.m_nogetd << endl
- << "-noputd do not use SQLPutData - default " << d.m_noputd << endl
- << "-nosort no order-by in verify scan (checks non-Pk values only)" << endl
- << "-scale N row count etc - default " << d.m_scale << endl
- << "-serial run multi-threaded test cases one at a time" << endl
- << "-skip name skip named tests (substring match - can be repeated)" << endl
- << "-subloop N loop count per case (same threads) - default " << d.m_subloop << endl
- << "-table T do only table T (table name on built-in list)" << endl
- << "-threads N number of threads (max " << MAX_THR << ") - default " << d.m_threads << endl
- << "-trace N trace in NDB ODBC driver - default " << d.m_trace << endl
- << "-v N verbosity - default " << d.m_v << endl
- ;
- listCases();
- listTables();
-}
-
-static void
-fatal(const char* fmt, ...)
-{
- va_list ap;
- char buf[200];
- va_start(ap, fmt);
- vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
- ndbout << buf << endl;
- if (opt.m_errs != 0) {
- opt.m_errs--;
- return;
- }
- if (opt.m_core)
- abort();
- NDBT_ProgramExit(NDBT_FAILED);
- exit(1);
-}
-
-static void
-cleanprint(const char* s, unsigned n)
-{
- for (unsigned i = 0; i < n; i++) {
- char b[10];
- if (0x20 < s[i] && s[i] <= 0x7e)
- sprintf(b, "%c", s[i]);
- else
- sprintf(b, "\\%02x", (unsigned)s[i]);
- ndbout << b;
- }
-}
-
-// global mutex
-static NdbMutex my_mutex = NDB_MUTEX_INITIALIZER;
-static void lock_mutex() { NdbMutex_Lock(&my_mutex); }
-static void unlock_mutex() { NdbMutex_Unlock(&my_mutex); }
-
-// semaphore zeroed before each call to a test routine
-static unsigned my_sema = 0;
-
-// print mutex
-static NdbMutex out_mutex = NDB_MUTEX_INITIALIZER;
-static NdbOut& lock(NdbOut& out) { NdbMutex_Lock(&out_mutex); return out; }
-static NdbOut& unlock(NdbOut& out) { NdbMutex_Unlock(&out_mutex); return out; }
-
-static unsigned
-urandom(unsigned n)
-{
- assert(n != 0);
- unsigned i = random();
- return i % n;
-}
-
-// test cases
-
-struct Test;
-
-struct Case {
- enum Mode {
- Single = 1, // single thread
- Serial = 2, // all threads but one at a time
- Thread = 3 // all threads in parallel
- };
- const char* m_name;
- void (*m_func)(Test& test);
- Mode m_mode;
- unsigned m_stuff;
- const char* m_desc;
- Case(const char* name, void (*func)(Test& test), Mode mode, unsigned stuff, const char* desc) :
- m_name(name),
- m_func(func),
- m_mode(mode),
- m_stuff(stuff),
- m_desc(desc) {
- }
- const char* modename() const {
- const char* s = "?";
- if (m_mode == Case::Single)
- return "Single";
- if (m_mode == Case::Serial)
- return "Serial";
- if (m_mode == Case::Thread)
- return "Thread";
- return "?";
- }
- bool matchcase() const {
- if (opt.m_namecnt == 0)
- return ! skipcase();
- for (unsigned i = 0; i < opt.m_namecnt; i++) {
- if (strstr(m_name, opt.m_name[i]) != 0)
- return ! skipcase();
- }
- return false;
- }
-private:
- bool skipcase() const {
- for (unsigned i = 0; i < opt.m_skipcnt; i++) {
- if (strstr(m_name, opt.m_skip[i]) != 0)
- return true;
- }
- return false;
- }
-};
-
-// calculate values
-
-struct Calc {
- enum { m_mul = 1000000 };
- unsigned m_no;
- unsigned m_base;
- unsigned m_salt; // modifies non-PK values
- bool m_const; // base non-PK values on PK of row 0
- Calc(unsigned no) :
- m_no(no),
- m_salt(0),
- m_const(false) {
- m_base = m_no * m_mul;
- }
- void calcPk(unsigned rownum, char* v, unsigned n) const {
- char b[10];
- sprintf(b, "%08x", m_base + rownum);
- for (unsigned i = 0; i < n; i++) {
- char c = i < n - 1 ? b[i % 8] : 0;
- v[i] = c;
- }
- }
- void calcPk(unsigned rownum, long* v) const {
- *v = m_base + rownum;
- }
- void hashPk(unsigned* hash, const char* v, unsigned n) const {
- for (unsigned i = 0; i < n; i++) {
- *hash ^= (v[i] << i);
- }
- }
- void hashPk(unsigned* hash, long v) const {
- *hash ^= v;
- }
- void calcNk(unsigned hash, char* v, unsigned n, SQLINTEGER* ind, bool null) const {
- unsigned m = hash % n;
- for (unsigned i = 0; i < n; i++) {
- char c = i < m ? 'a' + (hash + i) % ('z' - 'a' + 1) : i < n - 1 ? ' ' : 0;
- v[i] = c;
- }
- *ind = null && hash % 9 == 0 ? SQL_NULL_DATA : SQL_NTS;
- }
- void calcNk(unsigned hash, long* v, SQLINTEGER* ind, bool null) const {
- *v = long(hash);
- *ind = null && hash % 7 == 0 ? SQL_NULL_DATA : 0;
- }
- void calcNk(unsigned hash, double* v, SQLINTEGER* ind, bool null) const {
- *v = long(hash) / 1000.0;
- *ind = null && hash % 5 == 0 ? SQL_NULL_DATA : 0;
- }
- bool verify(const char* v1, SQLINTEGER ind1, const char* v2, SQLINTEGER ind2, unsigned n) {
- if (ind1 == SQL_NULL_DATA && ind2 == SQL_NULL_DATA)
- return true;
- if (ind1 != SQL_NULL_DATA && ind2 != SQL_NULL_DATA)
- if (memcmp(v1, v2, n) == 0)
- return true;
- if (ind1 == SQL_NULL_DATA)
- v1 = "NULL";
- if (ind2 == SQL_NULL_DATA)
- v2 = "NULL";
- ndbout << "verify failed: got ";
- if (ind1 == SQL_NULL_DATA)
- ndbout << "NULL";
- else
- cleanprint(v1, n);
- ndbout << " != ";
- if (ind2 == SQL_NULL_DATA)
- ndbout << "NULL";
- else
- cleanprint(v2, n);
- ndbout << endl;
- return false;
- }
- bool verify(long v1, SQLINTEGER ind1, long v2, SQLINTEGER ind2) {
- char buf1[40], buf2[40];
- if (ind1 == SQL_NULL_DATA && ind2 == SQL_NULL_DATA)
- return true;
- if (ind1 != SQL_NULL_DATA && ind2 != SQL_NULL_DATA)
- if (v1 == v2)
- return true;
- if (ind1 == SQL_NULL_DATA)
- strcpy(buf1, "NULL");
- else
- sprintf(buf1, "%ld", v1);
- if (ind2 == SQL_NULL_DATA)
- strcpy(buf2, "NULL");
- else
- sprintf(buf2, "%ld", v2);
- ndbout << "verify failed: got " << buf1 << " != " << buf2 << endl;
- return false;
- }
- bool verify(double v1, SQLINTEGER ind1, double v2, SQLINTEGER ind2) {
- char buf1[40], buf2[40];
- if (ind1 == SQL_NULL_DATA && ind2 == SQL_NULL_DATA)
- return true;
- if (ind1 != SQL_NULL_DATA && ind2 != SQL_NULL_DATA)
- if (fabs(v1 - v2) < 1) // XXX
- return true;
- if (ind1 == SQL_NULL_DATA)
- strcpy(buf1, "NULL");
- else
- sprintf(buf1, "%.10f", v1);
- if (ind2 == SQL_NULL_DATA)
- strcpy(buf2, "NULL");
- else
- sprintf(buf2, "%.10f", v2);
- ndbout << "verify failed: got " << buf1 << " != " << buf2 << endl;
- return false;
- }
-};
-
-#if defined(NDB_SOLARIS) || defined(NDB_LINUX) || defined(NDB_MACOSX)
-#define HAVE_SBRK
-#else
-#undef HAVE_SBRK
-#endif
-
-struct Timer {
- Timer() :
- m_cnt(0),
- m_calls(0),
- m_on(0),
- m_msec(0)
-#ifndef NDB_WIN32
- ,
- m_brk(0),
- m_incr(0)
-#endif
- {
- }
- void timerOn() {
- m_cnt = 0;
- m_calls = 0;
- m_on = NdbTick_CurrentMillisecond();
-#ifdef HAVE_SBRK
- m_brk = (int)sbrk(0);
-#endif
- }
- void timerOff() {
- m_msec = NdbTick_CurrentMillisecond() - m_on;
- if (m_msec <= 0)
- m_msec = 1;
-#ifdef HAVE_SBRK
- m_incr = (int)sbrk(0) - m_brk;
- if (m_incr < 0)
- m_incr = 0;
-#endif
- }
- void timerCnt(unsigned cnt) {
- m_cnt += cnt;
- }
- void timerCnt(const Timer& timer) {
- m_cnt += timer.m_cnt;
- m_calls += timer.m_calls;
- }
- friend NdbOut& operator<<(NdbOut& out, const Timer& timer) {
- out << timer.m_cnt << " ( " << 1000 * timer.m_cnt / timer.m_msec << "/sec )";
-#ifdef HAVE_SBRK
- out << " - " << timer.m_incr << " sbrk";
- if (opt.m_namecnt != 0) { // per case meaningless if many cases
- if (timer.m_cnt > 0)
- out << " ( " << timer.m_incr / timer.m_cnt << "/cnt )";
- }
-#endif
- out << " - " << timer.m_calls << " calls";
- return out;
- }
-protected:
- unsigned m_cnt; // count rows or whatever
- unsigned m_calls; // count ODBC function calls
- NDB_TICKS m_on;
- unsigned m_msec;
-#ifdef HAVE_SBRK
- int m_brk;
- int m_incr;
-#endif
-};
-
-#define MAX_MESSAGE 500
-#define MAX_DIAG 20
-
-struct Diag {
- char m_state[5+1];
- SQLINTEGER m_native;
- char m_message[MAX_MESSAGE];
- unsigned m_flag; // temp use
- Diag() {
- strcpy(m_state, "00000");
- m_native = 0;
- memset(m_message, 0, sizeof(m_message));
- m_flag = 0;
- }
- const char* text() {
- snprintf(m_buf, sizeof(m_buf), "%s %d '%s'", m_state, (int)m_native, m_message);
- return m_buf;
- }
- void getDiag(SQLSMALLINT type, SQLHANDLE handle, unsigned k, unsigned count) {
- int ret;
- SQLSMALLINT length = -1;
- memset(m_message, 0, MAX_MESSAGE);
- ret = SQLGetDiagRec(type, handle, k, (SQLCHAR*)m_state, &m_native, (SQLCHAR*)m_message, MAX_MESSAGE, &length);
- if (k <= count && ret != SQL_SUCCESS)
- fatal("SQLGetDiagRec %d of %d: return %d != SQL_SUCCESS", k, count, (int)ret);
- if (k <= count && strlen(m_message) != length)
- fatal("SQLGetDiagRec %d of %d: message length %d != %d", k, count, strlen(m_message), length);
- if (k > count && ret != SQL_NO_DATA)
- fatal("SQLGetDiagRec %d of %d: return %d != SQL_NO_DATA", k, count, (int)ret);
- m_flag = 0;
- }
-private:
- char m_buf[MAX_MESSAGE];
-};
-
-struct Diags {
- Diag m_diag[MAX_DIAG];
- SQLINTEGER m_diagCount;
- SQLINTEGER m_rowCount;
- SQLINTEGER m_functionCode;
- void getDiags(SQLSMALLINT type, SQLHANDLE handle) {
- int ret;
- m_diagCount = -1;
- ret = SQLGetDiagField(type, handle, 0, SQL_DIAG_NUMBER, &m_diagCount, SQL_IS_INTEGER, 0);
- if (ret == SQL_INVALID_HANDLE)
- return;
- if (ret != SQL_SUCCESS)
- fatal("SQLGetDiagField: return %d != SQL_SUCCESS", (int)ret);
- if (m_diagCount < 0 || m_diagCount > MAX_DIAG)
- fatal("SQLGetDiagField: count %d", (int)m_diagCount);
- for (unsigned k = 0; k < MAX_DIAG; k++) {
- m_diag[k].getDiag(type, handle, k + 1, m_diagCount);
- if (k == m_diagCount + 1)
- break;
- }
- m_rowCount = -1;
- m_functionCode = SQL_DIAG_UNKNOWN_STATEMENT;
- if (type == SQL_HANDLE_STMT) {
- ret = SQLGetDiagField(type, handle, 0, SQL_DIAG_ROW_COUNT, &m_rowCount, SQL_IS_INTEGER, 0);
-#ifndef iODBC
- if (ret != SQL_SUCCESS)
- fatal("SQLGetDiagField: return %d != SQL_SUCCESS", (int)ret);
-#endif
- ret = SQLGetDiagField(type, handle, 0, SQL_DIAG_DYNAMIC_FUNCTION_CODE, &m_functionCode, SQL_IS_INTEGER, 0);
- }
- }
- void showDiags() {
- for (unsigned k = 0; 0 <= m_diagCount && k < m_diagCount; k++) {
- Diag& diag = m_diag[k];
- ndbout << "diag " << k + 1;
- ndbout << (diag.m_flag ? " [*]" : " [ ]");
- ndbout << " " << diag.text() << endl;
- if (k > 10)
- abort();
- }
- }
-};
-
-struct Exp {
- int m_ret;
- const char* m_state;
- SQLINTEGER m_native;
- Exp() : m_ret(SQL_SUCCESS), m_state(""), m_native(0) {}
- Exp(int ret, const char* state) : m_ret(ret), m_state(state) {}
-};
-
-struct Test : Calc, Timer, Diags {
- Test(unsigned no, unsigned loop) :
- Calc(no),
- m_loop(loop),
- m_stuff(0),
- m_perf(false),
- ccp(0) {
- exp(SQL_SUCCESS, 0, 0, true);
- }
- unsigned m_loop; // current loop
- Exp m_expList[20]; // expected results
- unsigned m_expCount;
- int m_ret; // actual return code
- int m_stuff; // the stuff of abuse
- bool m_perf; // check no diags on success
- const Case* ccp; // current case
- void exp(int ret, const char* state, SQLINTEGER native, bool reset) {
- if (reset)
- m_expCount = 0;
- unsigned i = m_expCount++;
- assert(i < arraySize(m_expList) - 1);
- m_expList[i].m_ret = ret;
- m_expList[i].m_state = state == 0 ? "" : state;
- m_expList[i].m_native = native;
- }
- void runCase(const Case& cc) {
- ccp = &cc;
- if (opt.m_v >= 3)
- ndbout << cc.m_name << ": start" << endl;
- m_rowCount = -1;
- NDB_TICKS m_ms1 = NdbTick_CurrentMillisecond();
- m_salt = m_loop | (16 << cc.m_stuff);
- m_const = cc.m_stuff == 0;
- m_stuff = cc.m_stuff;
- (*cc.m_func)(*this);
- NDB_TICKS m_ms2 = NdbTick_CurrentMillisecond();
- }
- void run(SQLSMALLINT type, SQLHANDLE handle, int line, int ret) {
- m_calls++;
- m_ret = ret;
- if (m_perf && (m_ret == SQL_SUCCESS))
- return;
- m_diagCount = 0;
- if (handle != SQL_NULL_HANDLE)
- getDiags(type, handle);
- if (m_diagCount <= 0 && (ret != SQL_SUCCESS && ret != SQL_INVALID_HANDLE && ret != SQL_NEED_DATA && ret != SQL_NO_DATA)) {
- fatal("%s: thr %d line %d: ret=%d but no diag records", ccp->m_name, m_no, line, ret);
- }
- for (unsigned k = 0; 0 <= m_diagCount && k < m_diagCount; k++) {
- Diag& diag = m_diag[k];
- bool match = false;
- for (unsigned i = 0; i < m_expCount; i++) {
- if (strcmp(diag.m_state, m_expList[i].m_state) == 0 && (diag.m_native % 10000 == m_expList[i].m_native % 10000 || m_expList[i].m_native == -1)) {
- match = true;
- diag.m_flag = 0;
- continue;
- }
- diag.m_flag = 1; // mark unexpected
- }
- if (! match) {
- showDiags();
- fatal("%s: thr %d line %d: unexpected diag [*] ret=%d cnt=%d", ccp->m_name, m_no, line, (int)ret, (int)m_diagCount);
- }
- }
- bool match = false;
- for (unsigned i = 0; i < m_expCount; i++) {
- if (ret == m_expList[i].m_ret) {
- match = true;
- break;
- }
- }
- if (! match) {
- showDiags();
- fatal("%s: thr %d line %d: ret=%d not expected", ccp->m_name, m_no, line, ret);
- }
- // reset expected to success
- exp(SQL_SUCCESS, 0, 0, true);
- }
- void chk(SQLSMALLINT type, SQLHANDLE handle, int line, bool match, const char* fmt, ...) {
- if (match)
- return;
- va_list ap;
- va_start(ap, fmt);
- char buf[500];
- vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
- fatal("%s: thr %d line %d: check failed - %s", ccp->m_name, m_no, line, buf);
- }
-};
-
-#define HNull 0, SQL_NULL_HANDLE, __LINE__
-#define HEnv(h) SQL_HANDLE_ENV, h, __LINE__
-#define HDbc(h) SQL_HANDLE_DBC, h, __LINE__
-#define HStmt(h) SQL_HANDLE_STMT, h, __LINE__
-#define HDesc(h) SQL_HANDLE_DESC, h, __LINE__
-
-// string support
-
-#define MAX_SQL 20000
-
-static void
-scopy(char*& ptr, const char* fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- vsprintf(ptr, fmt, ap);
- va_end(ap);
- ptr += strlen(ptr);
-}
-
-static bool
-blankeq(const char* s1, const char* s2, bool caseSensitive = false)
-{
- unsigned n1 = strlen(s1);
- unsigned n2 = strlen(s2);
- unsigned i = 0;
- char c1 = 0;
- char c2 = 0;
- while (i < n1 || i < n2) {
- c1 = i < n1 ? s1[i] : 0x20;
- if (! caseSensitive && 'a' <= c1 && c1 <= 'z')
- c1 -= 'a' - 'A';
- c2 = i < n2 ? s2[i] : 0x20;
- if (! caseSensitive && 'a' <= c2 && c2 <= 'z')
- c2 -= 'a' - 'A';
- if (c1 != c2)
- break;
- i++;
- }
- return c1 == c2;
-}
-
-// columns and tables
-
-struct Col {
- enum Type {
- Char = SQL_CHAR,
- Varchar = SQL_VARCHAR,
- Int = SQL_INTEGER,
- Bigint = SQL_BIGINT,
- Real = SQL_REAL,
- Double = SQL_DOUBLE
- };
- enum CType {
- CChar = SQL_C_CHAR,
- CLong = SQL_C_SLONG,
- CDouble = SQL_C_DOUBLE
- };
- enum Cons {
- Null, // nullable
- NotNull, // not nullable
- Pk // part of primary key
- };
- const char* m_name;
- Type m_type;
- unsigned m_length;
- Cons m_cons;
- CType m_ctype;
- Col() :
- m_type((Type)999) {
- }
- Col(const char* name, Type type, unsigned length, Cons cons, CType ctype) :
- m_name(name),
- m_type(type),
- m_length(length),
- m_cons(cons),
- m_ctype(ctype) {
- }
- unsigned size() const {
- switch (m_type) {
- case Char:
- case Varchar:
- return m_length;
- case Int:
- return 4;
- case Bigint:
- return 8;
- case Real:
- return 4;
- case Double:
- return 8;
- }
- assert(false);
- return 0;
- }
- unsigned csize() const { // size as char plus terminating null
- switch (m_ctype) {
- case CChar:
- return m_length + 1;
- case CLong:
- return 12;
- case CDouble:
- return 24;
- }
- assert(false);
- return 0;
- }
- void typespec(char*& ptr) const {
- switch (m_type) {
- case Char:
- scopy(ptr, "char(%d)", m_length);
- return;
- case Varchar:
- scopy(ptr, "varchar(%d)", m_length);
- return;
- case Int:
- scopy(ptr, "int");
- return;
- case Bigint:
- scopy(ptr, "bigint");
- return;
- case Real:
- scopy(ptr, "real");
- return;
- case Double:
- scopy(ptr, "float");
- return;
- }
- assert(false);
- }
- SQLSMALLINT type() const {
- return (SQLSMALLINT)m_type;
- }
- SQLSMALLINT ctype() const {
- return (SQLSMALLINT)m_ctype;
- }
- void create(char*& ptr, bool pk) const {
- scopy(ptr, "%s", m_name);
- scopy(ptr, " ");
- typespec(ptr);
- if (m_cons == Pk && pk) {
- scopy(ptr, " primary key");
- }
- if (m_cons == NotNull) {
- scopy(ptr, " not null");
- }
- }
-};
-
-static Col ColUndef;
-
-struct Tab {
- const char* m_name;
- const Col* m_colList;
- unsigned m_colCount;
- unsigned m_pkCount;
- unsigned* m_pkIndex;
- unsigned m_nkCount;
- unsigned* m_nkIndex;
- char m_upperName[20];
- Tab(const char* name, const Col* colList, unsigned colCount) :
- m_name(name),
- m_colList(colList),
- m_colCount(colCount) {
- m_pkCount = 0;
- m_nkCount = 0;
- for (unsigned i = 0; i < m_colCount; i++) {
- const Col& col = m_colList[i];
- if (col.m_cons == Col::Pk)
- m_pkCount++;
- else
- m_nkCount++;
- }
- m_pkIndex = new unsigned[m_pkCount];
- m_nkIndex = new unsigned[m_nkCount];
- unsigned pk = 0;
- unsigned nk = 0;
- for (unsigned i = 0; i < m_colCount; i++) {
- const Col& col = m_colList[i];
- if (col.m_cons == Col::Pk)
- m_pkIndex[pk++] = i;
- else
- m_nkIndex[nk++] = i;
- }
- assert(pk == m_pkCount && nk == m_nkCount);
- strcpy(m_upperName, m_name);
- for (char* p = m_upperName; *p != 0; p++) {
- if ('a' <= *p && *p <= 'z')
- *p -= 'a' - 'A';
- }
- }
- ~Tab() {
- delete[] m_pkIndex;
- delete[] m_nkIndex;
- }
- void drop(char*& ptr) const {
- scopy(ptr, "drop table %s", m_name);
- }
- void create(char*& ptr) const {
- scopy(ptr, "create table %s (", m_name);
- for (unsigned i = 0; i < m_colCount; i++) {
- if (i > 0)
- scopy(ptr, ", ");
- const Col& col = m_colList[i];
- col.create(ptr, m_pkCount == 1);
- }
- if (m_pkCount != 1) {
- scopy(ptr, ", primary key (");
- for (unsigned i = 0; i < m_pkCount; i++) {
- const Col& col = m_colList[m_pkIndex[i]];
- if (i > 0)
- scopy(ptr, ", ");
- scopy(ptr, "%s", col.m_name);
- }
- scopy(ptr, ")");
- }
- scopy(ptr, ")");
- }
- void wherePk(char*& ptr) const {
- scopy(ptr, " where");
- for (unsigned i = 0; i < m_pkCount; i++) {
- const Col& col = m_colList[m_pkIndex[i]];
- if (i > 0)
- scopy(ptr, " and");
- scopy(ptr, " %s = ?", col.m_name);
- }
- }
- void whereRange(char*& ptr) const {
- scopy(ptr, " where");
- for (unsigned i = 0; i < m_pkCount; i++) {
- const Col& col = m_colList[m_pkIndex[i]];
- if (i > 0)
- scopy(ptr, " and");
- scopy(ptr, " ? <= %s", col.m_name);
- scopy(ptr, " and ");
- scopy(ptr, "%s < ?", col.m_name);
- }
- }
- void orderPk(char*& ptr) const {
- scopy(ptr, " order by");
- for (unsigned i = 0; i < m_pkCount; i++) {
- const Col& col = m_colList[m_pkIndex[i]];
- if (i > 0)
- scopy(ptr, ", ");
- else
- scopy(ptr, " ");
- scopy(ptr, "%s", col.m_name);
- }
- }
- void selectPk(char*& ptr) const {
- scopy(ptr, "select * from %s", m_name);
- wherePk(ptr);
- }
- void selectAll(char*& ptr) const {
- scopy(ptr, "select * from %s", m_name);
- }
- void selectRange(char*& ptr, bool sort) const {
- selectAll(ptr);
- whereRange(ptr);
- if (sort)
- orderPk(ptr);
- }
- void selectCount(char*& ptr) const {
- scopy(ptr, "select count(*) from %s", m_name);
- }
- void insertAll(char*& ptr) const {
- scopy(ptr, "insert into %s values (", m_name);
- for (unsigned i = 0; i < m_colCount; i++) {
- if (i > 0)
- scopy(ptr, ", ");
- scopy(ptr, "?");
- }
- scopy(ptr, ")");
- }
- void updatePk(char*& ptr) const {
- scopy(ptr, "update %s set", m_name);
- for (unsigned i = 0; i < m_nkCount; i++) {
- const Col& col = m_colList[m_nkIndex[i]];
- if (i > 0)
- scopy(ptr, ", ");
- else
- scopy(ptr, " ");
- scopy(ptr, "%s = ?", col.m_name);
- }
- wherePk(ptr);
- }
- void updateRange(char*& ptr) const {
- scopy(ptr, "update %s set", m_name);
- for (unsigned i = 0; i < m_nkCount; i++) {
- const Col& col = m_colList[m_nkIndex[i]];
- if (i > 0)
- scopy(ptr, ", ");
- else
- scopy(ptr, " ");
- scopy(ptr, "%s = ?", col.m_name); // XXX constant for now
- }
- whereRange(ptr);
- }
- void deleteAll(char*& ptr) const {
- scopy(ptr, "delete from %s", m_name);
- }
- void deletePk(char*& ptr) const {
- scopy(ptr, "delete from %s", m_name);
- wherePk(ptr);
- }
- void deleteRange(char*& ptr) const {
- scopy(ptr, "delete from %s", m_name);
- whereRange(ptr);
- }
- // simple
- void insertDirect(char*& ptr, unsigned n) const {
- scopy(ptr, "insert into %s values (", m_name);
- for (unsigned i = 0; i < m_colCount; i++) {
- const Col& col = m_colList[i];
- if (i > 0)
- scopy(ptr, ", ");
- if (col.m_type == Col::Char || col.m_type == Col::Varchar) {
- scopy(ptr, "'");
- for (unsigned i = 0; i <= n % col.m_length; i++)
- scopy(ptr, "%c", 'a' + (n + i) % 26);
- scopy(ptr, "'");
- } else if (col.m_type == Col::Int || col.m_type == Col::Bigint) {
- scopy(ptr, "%u", n);
- } else if (col.m_type == Col::Real || col.m_type == Col::Double) {
- scopy(ptr, "%.3f", n * 0.001);
- } else {
- assert(false);
- }
- }
- scopy(ptr, ")");
- }
- void whereDirect(char*& ptr, unsigned n) const {
- scopy(ptr, " where");
- for (unsigned i = 0; i < m_pkCount; i++) {
- const Col& col = m_colList[m_pkIndex[i]];
- if (i > 0)
- scopy(ptr, ", ");
- else
- scopy(ptr, " ");
- scopy(ptr, "%s = ", col.m_name);
- if (col.m_type == Col::Char || col.m_type == Col::Varchar) {
- scopy(ptr, "'");
- for (unsigned i = 0; i <= n % col.m_length; i++)
- scopy(ptr, "%c", 'a' + (n + i) % 26);
- scopy(ptr, "'");
- } else if (col.m_type == Col::Int || col.m_type == Col::Bigint) {
- scopy(ptr, "%u", n);
- } else {
- assert(false);
- }
- }
- }
- void countDirect(char*& ptr, unsigned n) const {
- scopy(ptr, "select count(*) from %s", m_name);
- whereDirect(ptr, n);
- }
- void deleteDirect(char*& ptr, unsigned n) const {
- scopy(ptr, "delete from %s", m_name);
- whereDirect(ptr, n);
- }
- // joins
- void selectCart(char*& ptr, unsigned cnt) const {
- scopy(ptr, "select count(*) from");
- for (unsigned j = 0; j < cnt; j++) {
- if (j > 0)
- scopy(ptr, ",");
- scopy(ptr, " %s", m_name);
- scopy(ptr, " t%u", j);
- }
- }
- void selectJoin(char*& ptr, unsigned cnt) const {
- scopy(ptr, "select * from");
- for (unsigned j = 0; j < cnt; j++) {
- if (j > 0)
- scopy(ptr, ",");
- scopy(ptr, " %s", m_name);
- scopy(ptr, " t%u", j);
- }
- for (unsigned i = 0; i < m_pkCount; i++) {
- const Col& col = m_colList[m_pkIndex[i]];
- for (unsigned j = 0; j < cnt - 1; j++) {
- if (i == 0 && j == 0)
- scopy(ptr, " where");
- else
- scopy(ptr, " and");
- scopy(ptr, " t%u.%s = t%u.%s", j, col.m_name, j + 1, col.m_name);
- }
- }
- }
- // check if selected on command line
- bool optok() const {
- return opt.m_table == 0 || strcasecmp(m_name, opt.m_table) == 0;
- }
-};
-
-// the test tables
-
-static Col col0[] = {
- Col( "a", Col::Bigint, 0, Col::Pk, Col::CLong ),
- Col( "b", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c", Col::Char, 4, Col::NotNull, Col::CChar ),
- Col( "d", Col::Double, 0, Col::Null, Col::CDouble ),
- Col( "e", Col::Char, 40, Col::Null, Col::CChar ),
- Col( "f", Col::Char, 10, Col::Null, Col::CChar )
-};
-
-static Col col1[] = {
- Col( "c0", Col::Int, 0, Col::Pk, Col::CLong ),
- Col( "c1", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c2", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c3", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c4", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c5", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c6", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c7", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c8", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c9", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c10", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c11", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c12", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c13", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c14", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c15", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c16", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c17", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c18", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c19", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c20", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c21", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c22", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c23", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c24", Col::Int, 0, Col::NotNull, Col::CLong ),
- Col( "c25", Col::Int, 0, Col::NotNull, Col::CLong )
-};
-
-static Col col2[] = {
- Col( "a", Col::Int, 0, Col::Pk, Col::CLong ),
- Col( "c", Col::Char, 8000, Col::NotNull, Col::CChar )
-};
-
-static Col col3[] = {
- Col( "a", Col::Int, 0, Col::Pk, Col::CLong ),
- Col( "c1", Col::Varchar, 1, Col::Null, Col::CChar ),
- Col( "c2", Col::Varchar, 2, Col::Null, Col::CChar ),
- Col( "c3", Col::Varchar, 3, Col::Null, Col::CChar ),
- Col( "c4", Col::Varchar, 4, Col::Null, Col::CChar ),
- Col( "c5", Col::Varchar, 10, Col::Null, Col::CChar ),
- Col( "c6", Col::Varchar, 40, Col::Null, Col::CChar ),
- Col( "c7", Col::Varchar, 255, Col::Null, Col::CChar ),
- Col( "c8", Col::Varchar, 4000, Col::Null, Col::CChar )
-};
-
-static Col col4[] = {
- Col( "a", Col::Char, 8, Col::Pk, Col::CChar ),
- Col( "b", Col::Char, 8, Col::NotNull, Col::CChar ),
-};
-
-static Tab tabList[] = {
-#define colList(x) x, arraySize(x)
- Tab( "tt00", colList(col0) ),
- Tab( "tt01", colList(col1) ), // fläskbench special
- Tab( "tt02", colList(col2) ),
- Tab( "tt03", colList(col3) ),
- Tab( "tt04", colList(col4) )
-#undef colList
-};
-
-static const unsigned tabCount = arraySize(tabList);
-static const unsigned maxColCount = 100; // per table - keep up to date
-
-static bool
-findTable()
-{
- for (unsigned i = 0; i < tabCount; i++) {
- const Tab& tab = tabList[i];
- if (tab.optok())
- return true;
- }
- return false;
-}
-
-static void
-listTables()
-{
- ndbout << "tables:" << endl;
- for (unsigned i = 0; i < tabCount; i++) {
- const Tab& tab = tabList[i];
- if (i > 0)
- ndbout << " ";
- ndbout << tab.m_name;
- }
- ndbout << endl;
-}
-
-// data fields and rows
-
-struct Fld {
- const Col& m_col;
- union {
- char* m_char;
- long m_long;
- double m_double;
- };
- SQLINTEGER m_ind;
- SQLINTEGER m_need; // constant
- Fld() :
- m_col(ColUndef),
- m_need(0) {
- }
- Fld(const Col& col) :
- m_col(col),
- m_need(SQL_LEN_DATA_AT_EXEC(0)) {
- switch (m_col.m_ctype) {
- case Col::CChar:
- m_char = new char[m_col.csize()];
- memset(m_char, 0, m_col.csize());
- break;
- case Col::CLong:
- m_long = 0;
- break;
- case Col::CDouble:
- m_double = 0.0;
- break;
- }
- m_ind = -1;
- }
- ~Fld() {
- switch (m_col.m_ctype) {
- case Col::CChar:
- delete[] m_char;
- break;
- case Col::CLong:
- break;
- case Col::CDouble:
- break;
- }
- }
- void zero() {
- switch (m_col.m_ctype) {
- case Col::CChar:
- memset(m_char, 0x1f, m_col.csize());
- break;
- case Col::CLong:
- m_long = 0x1f1f1f1f;
- break;
- case Col::CDouble:
- m_double = 1111111.1111111;
- break;
- }
- m_ind = -1;
- }
- // copy values from another field
- void copy(const Fld& fld) {
- assert(&m_col == &fld.m_col);
- switch (m_col.m_ctype) {
- case Col::CChar:
- memcpy(m_char, fld.m_char, m_col.csize());
- break;
- case Col::CLong:
- m_long = fld.m_long;
- break;
- case Col::CDouble:
- m_double = fld.m_double;
- break;
- default:
- assert(false);
- break;
- }
- m_ind = fld.m_ind;
- }
- SQLPOINTER caddr() {
- switch (m_col.m_ctype) {
- case Col::CChar:
- return (SQLPOINTER)m_char;
- case Col::CLong:
- return (SQLPOINTER)&m_long;
- case Col::CDouble:
- return (SQLPOINTER)&m_double;
- }
- assert(false);
- return 0;
- }
- SQLINTEGER* ind() {
- return &m_ind;
- }
- SQLINTEGER* need() {
- m_need = SQL_LEN_DATA_AT_EXEC(0);
- return &m_need;
- }
- void calcPk(const Test& test, unsigned rownum) {
- switch (m_col.m_ctype) {
- case Col::CChar:
- test.calcPk(rownum, m_char, m_col.csize());
- m_ind = SQL_NTS;
- return;
- case Col::CLong:
- test.calcPk(rownum, &m_long);
- m_ind = 0;
- return;
- case Col::CDouble:
- assert(false);
- return;
- }
- assert(false);
- }
- void hashPk(const Test& test, unsigned* hash) const {
- switch (m_col.m_ctype) {
- case Col::CChar:
- test.hashPk(hash, m_char, m_col.csize());
- return;
- case Col::CLong:
- test.hashPk(hash, m_long);
- return;
- case Col::CDouble:
- assert(false);
- return;
- }
- assert(false);
- }
- void calcNk(const Test& test, unsigned hash) {
- bool null = m_col.m_cons == Col::Null;
- switch (m_col.m_ctype) {
- case Col::CChar:
- test.calcNk(hash, m_char, m_col.csize(), &m_ind, null);
- return;
- case Col::CLong:
- test.calcNk(hash, &m_long, &m_ind, null);
- return;
- case Col::CDouble:
- test.calcNk(hash, &m_double, &m_ind, null);
- return;
- }
- assert(false);
- }
- bool verify(Test& test, const Fld& fld) {
- assert(&m_col == &fld.m_col);
- switch (m_col.m_ctype) {
- case Col::CChar:
- return test.verify(m_char, m_ind, fld.m_char, fld.m_ind, m_col.csize());
- case Col::CLong:
- return test.verify(m_long, m_ind, fld.m_long, fld.m_ind);
- case Col::CDouble:
- return test.verify(m_double, m_ind, fld.m_double, fld.m_ind);
- }
- assert(false);
- return false;
- }
- // debug
- void print() const {
- if (m_ind == SQL_NULL_DATA)
- ndbout << "NULL";
- else {
- switch (m_col.m_ctype) {
- case Col::CChar:
- ndbout << m_char;
- break;
- case Col::CLong:
- ndbout << (int)m_long;
- break;
- case Col::CDouble:
- ndbout << m_double;
- break;
- }
- }
- }
-};
-
-struct Row {
- const Tab& m_tab;
- Fld* m_fldList;
- Row(const Tab& tab) :
- m_tab(tab) {
- m_fldList = new Fld[m_tab.m_colCount];
- for (unsigned i = 0; i < m_tab.m_colCount; i++) {
- const Col& col = m_tab.m_colList[i];
- void* place = &m_fldList[i];
- new (place) Fld(col);
- }
- }
- ~Row() {
- delete[] m_fldList;
- }
- // copy values from another row
- void copy(const Row& row) {
- assert(&m_tab == &row.m_tab);
- for (unsigned i = 0; i < m_tab.m_colCount; i++) {
- Fld& fld = m_fldList[i];
- fld.copy(row.m_fldList[i]);
- }
- }
- // primary key value is determined by row number
- void calcPk(Test& test, unsigned rownum) {
- for (unsigned i = 0; i < m_tab.m_pkCount; i++) {
- Fld& fld = m_fldList[m_tab.m_pkIndex[i]];
- fld.calcPk(test, rownum);
- }
- }
- // other fields are determined by primary key value
- void calcNk(Test& test) {
- unsigned hash = test.m_salt;
- for (unsigned i = 0; i < m_tab.m_pkCount; i++) {
- Fld& fld = m_fldList[m_tab.m_pkIndex[i]];
- fld.hashPk(test, &hash);
- }
- for (unsigned i = 0; i < m_tab.m_colCount; i++) {
- const Col& col = m_tab.m_colList[i];
- if (col.m_cons == Col::Pk)
- continue;
- Fld& fld = m_fldList[i];
- fld.calcNk(test, hash);
- }
- }
- // verify against another row
- bool verifyPk(Test& test, const Row& row) const {
- assert(&m_tab == &row.m_tab);
- for (unsigned i = 0; i < m_tab.m_pkCount; i++) {
- Fld& fld = m_fldList[m_tab.m_pkIndex[i]];
- if (! fld.verify(test, row.m_fldList[m_tab.m_pkIndex[i]])) {
- ndbout << "verify failed: tab=" << m_tab.m_name << " col=" << fld.m_col.m_name << endl;
- return false;
- }
- }
- return true;
- }
- bool verifyNk(Test& test, const Row& row) const {
- assert(&m_tab == &row.m_tab);
- for (unsigned i = 0; i < m_tab.m_nkCount; i++) {
- Fld& fld = m_fldList[m_tab.m_nkIndex[i]];
- if (! fld.verify(test, row.m_fldList[m_tab.m_nkIndex[i]])) {
- ndbout << "verify failed: tab=" << m_tab.m_name << " col=" << fld.m_col.m_name << endl;
- return false;
- }
- }
- return true;
- }
- bool verify(Test& test, const Row& row) const {
- return verifyPk(test, row) && verifyNk(test, row);
- }
- // debug
- void print() const {
- ndbout << "row";
- for (unsigned i = 0; i < m_tab.m_colCount; i++) {
- ndbout << " " << i << "=";
- Fld& fld = m_fldList[i];
- fld.print();
- }
- ndbout << endl;
- }
-};
-
-// set ODBC version - required
-
-static void
-setVersion(Test& test, SQLHANDLE hEnv)
-{
- test.run(HEnv(hEnv), SQLSetEnvAttr(hEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER));
-}
-
-// set autocommit
-
-static void
-setAutocommit(Test& test, SQLHANDLE hDbc, bool on)
-{
- SQLUINTEGER value = on ? SQL_AUTOCOMMIT_ON : SQL_AUTOCOMMIT_OFF;
- test.run(HDbc(hDbc), SQLSetConnectAttr(hDbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)value, SQL_IS_UINTEGER));
- SQLUINTEGER value2 = (SQLUINTEGER)-1;
- test.run(HDbc(hDbc), SQLGetConnectAttr(hDbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)&value2, SQL_IS_UINTEGER, 0));
- test.chk(HDbc(hDbc), value2 == value, "got %u != %u", (unsigned)value2, (unsigned)value);
-}
-
-// subroutines - migrate simple common routines here
-
-static void
-allocEnv(Test& test, SQLHANDLE& hEnv)
-{
- test.run(HNull, SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hEnv));
- setVersion(test, hEnv);
-}
-
-static void
-allocDbc(Test& test, SQLHANDLE hEnv, SQLHANDLE& hDbc)
-{
- test.run(HEnv(hEnv), SQLAllocHandle(SQL_HANDLE_DBC, hEnv, &hDbc));
-}
-
-static void
-allocConn(Test& test, SQLHANDLE hEnv, SQLHANDLE& hDbc)
-{
- allocDbc(test, hEnv, hDbc);
-#ifdef unixODBC
- test.exp(SQL_SUCCESS_WITH_INFO, "IM003", 0, false); // unicode??
- test.exp(SQL_SUCCESS_WITH_INFO, "01000", 0, false); // version??
-#endif
- test.run(HDbc(hDbc), SQLConnect(hDbc, (SQLCHAR*)opt.m_dsn, SQL_NTS, (SQLCHAR*)"user", SQL_NTS, (SQLCHAR*)"pass", SQL_NTS));
-}
-
-static void
-allocStmt(Test& test, SQLHANDLE hDbc, SQLHANDLE& hStmt)
-{
- test.run(HDbc(hDbc), SQLAllocHandle(SQL_HANDLE_STMT, hDbc, &hStmt));
-}
-
-static void
-allocAll(Test& test, SQLHANDLE& hEnv, SQLHANDLE& hDbc, SQLHANDLE& hStmt)
-{
- allocEnv(test, hEnv);
- allocConn(test, hEnv, hDbc);
- allocStmt(test, hDbc, hStmt);
-}
-
-static void
-allocAll(Test& test, SQLHANDLE& hEnv, SQLHANDLE& hDbc, SQLHANDLE* hStmtList, unsigned nStmt)
-{
- allocEnv(test, hEnv);
- allocConn(test, hEnv, hDbc);
- for (unsigned i = 0; i < nStmt; i++)
- allocStmt(test, hDbc, hStmtList[i]);
-}
-
-static void
-freeEnv(Test& test, SQLHANDLE hEnv)
-{
- test.run(HNull, SQLFreeHandle(SQL_HANDLE_ENV, hEnv));
-}
-
-static void
-freeDbc(Test& test, SQLHANDLE hEnv, SQLHANDLE hDbc)
-{
- test.run(HEnv(hEnv), SQLFreeHandle(SQL_HANDLE_DBC, hDbc));
-}
-
-static void
-freeConn(Test& test, SQLHANDLE hEnv, SQLHANDLE hDbc)
-{
- test.run(HDbc(hDbc), SQLDisconnect(hDbc));
- test.run(HEnv(hEnv), SQLFreeHandle(SQL_HANDLE_DBC, hDbc));
-}
-
-static void
-freeStmt(Test& test, SQLHANDLE hDbc, SQLHANDLE hStmt)
-{
- test.run(HDbc(hDbc), SQLFreeHandle(SQL_HANDLE_STMT, hStmt));
-}
-
-static void
-freeAll(Test& test, SQLHANDLE hEnv, SQLHANDLE hDbc, SQLHANDLE hStmt)
-{
- freeStmt(test, hDbc, hStmt);
- freeConn(test, hEnv, hDbc);
- freeEnv(test, hEnv);
-}
-
-static void
-freeAll(Test& test, SQLHANDLE hEnv, SQLHANDLE hDbc, SQLHANDLE* hStmtList, unsigned nStmt)
-{
- for (unsigned i = 0; i < nStmt; i++)
- freeStmt(test, hDbc, hStmtList[i]);
- freeConn(test, hEnv, hDbc);
- freeEnv(test, hEnv);
-}
-
-#define chkTuplesFetched(/*Test&*/ _test, /*SQLHANDLE*/ _hStmt, /*SQLUINTEGER*/ _countExp) \
-do { \
- SQLUINTEGER _count = (SQLUINTEGER)-1; \
- getTuplesFetched(_test, _hStmt, &_count); \
- test.chk(HStmt(_hStmt), _count == _countExp, "tuples: got %ld != %ld", (long)_count, (long)_countExp); \
-} while (0)
-
-static void
-getTuplesFetched(Test& test, SQLHANDLE hStmt, SQLUINTEGER* count)
-{
- *count = (SQLUINTEGER)-1;
- test.run(HStmt(hStmt), SQLGetStmtAttr(hStmt, SQL_ATTR_NDB_TUPLES_FETCHED, count, SQL_IS_POINTER, 0));
-}
-
-static void
-selectCount(Test& test, SQLHANDLE hStmt, const char* sql, long* count)
-{
- if (opt.m_v >= 3)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLPrepare(hStmt, (SQLCHAR*)sql, SQL_NTS));
- SQLINTEGER ind;
- test.run(HStmt(hStmt), SQLBindCol(hStmt, 1, SQL_C_SLONG, count, 0, &ind));
- ind = -1;
- *count = -1;
- test.run(HStmt(hStmt), SQLExecute(hStmt));
- unsigned k = 0;
- while (1) {
- if (k == 1)
- test.exp(SQL_NO_DATA, 0, 0, true);
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- if (k == 1)
- break;
- k++;
- }
- test.chk(HStmt(hStmt), ind == sizeof(long), "got %d != %d", (int)ind, (int)sizeof(long));
- test.chk(HStmt(hStmt), *count >= 0, "got %ld < 0", *count);
- chkTuplesFetched(test, hStmt, *count);
-#ifndef iODBC
- //
- test.run(HStmt(hStmt), SQLCloseCursor(hStmt));
-#else
- test.run(HStmt(hStmt), SQLFreeStmt(hStmt, SQL_CLOSE));
-#endif
-}
-
-static void
-selectCount(Test& test, SQLHANDLE hStmt, const Tab& tab, long* count)
-{
- static char sql[MAX_SQL], *sqlptr; // XXX static or core
- tab.selectCount(sqlptr = sql);
- selectCount(test, hStmt, sql, count);
-}
-
-static void
-verifyCount(Test& test, SQLHANDLE hStmt, const Tab& tab, long countExp)
-{
- long count = -1;
- selectCount(test, hStmt, tab, &count);
- test.chk(HStmt(hStmt), count == countExp, "got %ld != %ld", count, countExp);
-}
-
-#define chkRowCount(/*Test&*/ _test, /*SQLHANDLE*/ _hStmt, /*SQLINTEGER*/ _countExp) \
-do { \
- SQLINTEGER _count = -1; \
- getRowCount(_test, _hStmt, &_count); \
- test.chk(HStmt(_hStmt), _count == _countExp, "rowcount: got %ld != %ld", (long)_count, (long)_countExp); \
-} while (0)
-
-static void
-getRowCount(Test& test, SQLHANDLE hStmt, SQLINTEGER* count)
-{
- *count = -1;
- test.run(HStmt(hStmt), SQLRowCount(hStmt, count));
-}
-
-// handle allocation
-
-static void
-testAlloc(Test& test)
-{
- const unsigned n1 = (opt.m_scale >> 8) & 0xf; // default 500 = 0x1f4
- const unsigned n2 = (opt.m_scale >> 4) & 0xf;
- const unsigned n3 = (opt.m_scale >> 0) & 0xf;
- const unsigned count = n1 + n1 * n2 + n1 * n2 * n3;
- SQLHANDLE hEnvList[0xf];
- SQLHANDLE hDbcList[0xf][0xf];
- SQLHANDLE hStmtList[0xf][0xf][0xf];
- for (unsigned i1 = 0; i1 < n1; i1++) {
- SQLHANDLE& hEnv = hEnvList[i1];
- test.run(HNull, SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hEnv));
- test.run(HEnv(hEnv), SQLSetEnvAttr(hEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER));
- for (unsigned i2 = 0; i2 < n2; i2++) {
- SQLHANDLE& hDbc = hDbcList[i1][i2];
- test.run(HEnv(hEnv), SQLAllocHandle(SQL_HANDLE_DBC, hEnv, &hDbc));
-#ifdef unixODBC
- test.exp(SQL_SUCCESS_WITH_INFO, "IM003", 0, false); // unicode??
- test.exp(SQL_SUCCESS_WITH_INFO, "01000", 0, false); // version??
-#endif
- test.run(HDbc(hDbc), SQLConnect(hDbc, (SQLCHAR*)opt.m_dsn, SQL_NTS, (SQLCHAR*)"user", SQL_NTS, (SQLCHAR*)"pass", SQL_NTS));
- // some attributes
- test.exp(SQL_ERROR, "HY092", -1, true); // read-only attribute
- test.run(HDbc(hDbc), SQLSetConnectAttr(hDbc, SQL_ATTR_AUTO_IPD, (SQLPOINTER)SQL_TRUE, SQL_IS_UINTEGER));
- test.exp(SQL_ERROR, "HYC00", -1, true); // not supported
- test.run(HDbc(hDbc), SQLSetConnectAttr(hDbc, SQL_ATTR_TXN_ISOLATION, (SQLPOINTER)SQL_TXN_SERIALIZABLE, SQL_IS_UINTEGER));
- test.run(HDbc(hDbc), SQLSetConnectAttr(hDbc, SQL_ATTR_CURRENT_CATALOG, (SQLPOINTER)"DEFAULT", strlen("DEFAULT")));
- for (unsigned i3 = 0; i3 < n3; i3++) {
- SQLHANDLE& hStmt = hStmtList[i1][i2][i3];
- test.run(HDbc(hDbc), SQLAllocHandle(SQL_HANDLE_STMT, hDbc, &hStmt));
- SQLHANDLE ipd0, ipd1;
- SQLHANDLE ird0, ird1;
- SQLHANDLE apd0, apd1, apd2;
- SQLHANDLE ard0, ard1, ard2;
- // get
- ipd0 = ird0 = apd0 = ard0 = 0;
- test.run(HStmt(hStmt), SQLGetStmtAttr(hStmt, SQL_ATTR_IMP_PARAM_DESC, &ipd0, SQL_IS_POINTER, 0));
- test.run(HStmt(hStmt), SQLGetStmtAttr(hStmt, SQL_ATTR_IMP_ROW_DESC, &ird0, SQL_IS_POINTER, 0));
- test.run(HStmt(hStmt), SQLGetStmtAttr(hStmt, SQL_ATTR_APP_PARAM_DESC, &apd0, SQL_IS_POINTER, 0));
- test.run(HStmt(hStmt), SQLGetStmtAttr(hStmt, SQL_ATTR_APP_ROW_DESC, &ard0, SQL_IS_POINTER, 0));
-#ifndef unixODBC
- test.chk(HStmt(hStmt), ipd0 != 0, "got 0");
- test.chk(HStmt(hStmt), ird0 != 0, "got 0");
- test.chk(HStmt(hStmt), apd0 != 0, "got 0");
- test.chk(HStmt(hStmt), ard0 != 0, "got 0");
-#endif
- // alloc
- ipd1 = ird1 = apd1 = ard1 = 0;
- test.run(HDbc(hDbc), SQLAllocHandle(SQL_HANDLE_DESC, hDbc, &ipd1));
- test.run(HDbc(hDbc), SQLAllocHandle(SQL_HANDLE_DESC, hDbc, &ird1));
- test.run(HDbc(hDbc), SQLAllocHandle(SQL_HANDLE_DESC, hDbc, &apd1));
- test.run(HDbc(hDbc), SQLAllocHandle(SQL_HANDLE_DESC, hDbc, &ard1));
- test.chk(HDbc(hDbc), ipd1 != 0 && ird1 != 0 && apd1 != 0 && ard1 != 0, "got null");
- // set
- test.exp(SQL_ERROR, "HY092", -1, true); // read-only attribute
- test.run(HStmt(hStmt), SQLSetStmtAttr(hStmt, SQL_ATTR_IMP_PARAM_DESC, ipd1, SQL_IS_POINTER));
- test.exp(SQL_ERROR, "HY092", -1, true); // read-only attribute
- test.run(HStmt(hStmt), SQLSetStmtAttr(hStmt, SQL_ATTR_IMP_ROW_DESC, ird1, SQL_IS_POINTER));
- test.run(HStmt(hStmt), SQLSetStmtAttr(hStmt, SQL_ATTR_APP_PARAM_DESC, apd1, SQL_IS_POINTER));
- test.run(HStmt(hStmt), SQLSetStmtAttr(hStmt, SQL_ATTR_APP_ROW_DESC, ard1, SQL_IS_POINTER));
- // get
-
- apd2 = ard2 = 0;
- test.run(HStmt(hStmt), SQLGetStmtAttr(hStmt, SQL_ATTR_APP_PARAM_DESC, &apd2, SQL_IS_POINTER, 0));
- test.run(HStmt(hStmt), SQLGetStmtAttr(hStmt, SQL_ATTR_APP_ROW_DESC, &ard2, SQL_IS_POINTER, 0));
- test.chk(HStmt(hStmt), apd2 == apd1, "got %x != %x", (unsigned)apd2, (unsigned)apd1);
- test.chk(HStmt(hStmt), ard2 == ard1, "got %x != %x", (unsigned)ard2, (unsigned)ard1);
- // free
- test.run(HDbc(hDbc), SQLFreeHandle(SQL_HANDLE_DESC, ipd1));
- test.run(HDbc(hDbc), SQLFreeHandle(SQL_HANDLE_DESC, ird1));
- test.run(HDbc(hDbc), SQLFreeHandle(SQL_HANDLE_DESC, apd1));
- test.run(HDbc(hDbc), SQLFreeHandle(SQL_HANDLE_DESC, ard1));
- }
- }
- }
- test.timerCnt(count);
- if (opt.m_v >= 3)
- ndbout << "allocated " << count << endl;
- for (unsigned i1 = 0; i1 < n1; i1++) {
- SQLHANDLE& hEnv = hEnvList[i1];
- for (unsigned i2 = 0; i2 < n2; i2++) {
- SQLHANDLE& hDbc = hDbcList[i1][i2];
- if (i2 % 2 == 0) {
- for (unsigned i3 = 0; i3 < n3; i3++) {
- SQLHANDLE& hStmt = hStmtList[i1][i2][i3];
- test.run(HDbc(hDbc), SQLFreeHandle(SQL_HANDLE_STMT, hStmt));
- }
- } else {
- // cleaned up by SQLDisconnect
- }
- test.run(HDbc(hDbc), SQLDisconnect(hDbc));
- test.run(HEnv(hEnv), SQLFreeHandle(SQL_HANDLE_DBC, hDbc));
- }
- test.run(HNull, SQLFreeHandle(SQL_HANDLE_ENV, hEnv));
- }
- test.timerCnt(count);
- if (opt.m_v >= 3)
- ndbout << "freed " << count << endl;
-}
-
-// create tables
-
-static void
-testCreate(Test& test)
-{
- SQLHANDLE hEnv, hDbc, hStmt;
- allocAll(test, hEnv, hDbc, hStmt);
- char sql[MAX_SQL], *sqlptr;
- for (unsigned i = 0; i < tabCount; i++) {
- Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- // drop
- tab.drop(sqlptr = sql);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLPrepare(hStmt, (SQLCHAR*)sql, SQL_NTS));
- test.exp(SQL_ERROR, "IM000", 2040709, false);
- test.run(HStmt(hStmt), SQLExecute(hStmt));
- if (test.m_ret == SQL_SUCCESS)
- test.chk(HStmt(hStmt), test.m_functionCode == SQL_DIAG_DROP_TABLE, "got %d != %d", test.m_functionCode, SQL_DIAG_DROP_TABLE);
- if (test.m_ret == SQL_SUCCESS && opt.m_v >= 2)
- ndbout << "table " << tab.m_name << " dropped" << endl;
- if (test.m_ret != SQL_SUCCESS && opt.m_v >= 2)
- ndbout << "table " << tab.m_name << " does not exist" << endl;
- test.timerCnt(1);
- // create
- tab.create(sqlptr = sql);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLPrepare(hStmt, (SQLCHAR*)sql, SQL_NTS));
- test.exp(SQL_ERROR, "IM000", 2040721, false);
- test.run(HStmt(hStmt), SQLExecute(hStmt));
- if (test.m_ret == SQL_SUCCESS)
- test.chk(HStmt(hStmt), test.m_functionCode == SQL_DIAG_CREATE_TABLE, "got %d != %d", test.m_functionCode, SQL_DIAG_CREATE_TABLE);
- if (test.m_ret == SQL_SUCCESS && opt.m_v >= 2)
- ndbout << "table " << tab.m_name << " created" << endl;
- if (test.m_ret != SQL_SUCCESS && opt.m_v >= 2)
- ndbout << "table " << tab.m_name << " already exists" << endl;
- test.timerCnt(1);
- }
- freeAll(test, hEnv, hDbc, hStmt);
-}
-
-// prepare without execute
-
-static void
-testPrepare(Test& test)
-{
- SQLHANDLE hEnv, hDbc, hStmt;
- allocAll(test, hEnv, hDbc, hStmt);
- char sql[MAX_SQL], *sqlptr;
- for (unsigned cnt = opt.m_depth; cnt <= opt.m_depth; cnt++) {
- for (unsigned i = 0; i < tabCount; i++) {
- Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- tab.selectJoin(sqlptr = sql, cnt);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLPrepare(hStmt, (SQLCHAR*)sql, SQL_NTS));
- SQLSMALLINT colCount = -1;
- SQLSMALLINT colExp = cnt * tab.m_colCount;
- test.run(HStmt(hStmt), SQLNumResultCols(hStmt, &colCount));
- test.chk(HStmt(hStmt), colCount == colExp, "got %d != %d", (int)colCount, (int)colExp);
- test.timerCnt(1);
- }
- }
- freeAll(test, hEnv, hDbc, hStmt);
-}
-
-// catalog functions
-
-static void
-testCatalog(Test& test)
-{
- SQLHANDLE hEnv, hDbc, hStmt;
- allocAll(test, hEnv, hDbc, hStmt);
- odbc_typeinfo: {
- long type[] = {
- SQL_CHAR, SQL_VARCHAR, SQL_SMALLINT, SQL_INTEGER, SQL_BIGINT, SQL_REAL, SQL_DOUBLE
- };
- unsigned rows[] = {
- 1, 1, 2, 2, 2, 1, 1 // 2 for signed and unsigned
- };
- for (unsigned i = 0; i < arraySize(type); i++) {
- test.run(HStmt(hStmt), SQLGetTypeInfo(hStmt, type[i]));
- long dataType = 0;
- test.run(HStmt(hStmt), SQLBindCol(hStmt, 2, SQL_C_SLONG, &dataType, 0, 0));
- unsigned k = 0;
- while (1) {
- if (k == rows[i])
- test.exp(SQL_NO_DATA, 0, 0, true);
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- if (k == rows[i])
- break;
- test.chk(HStmt(hStmt), dataType == type[i], "got %ld != %ld", dataType, type[i]);
- test.timerCnt(1);
- k++;
- }
-#ifndef iODBC
- test.run(HStmt(hStmt), SQLCloseCursor(hStmt));
-#else
- freeStmt(test, hDbc, hStmt);
- allocStmt(test, hDbc, hStmt);
-#endif
- }
- if (opt.m_v >= 2)
- ndbout << "found " << (UintPtr)arraySize(type) << " data types" << endl;
- test.run(HStmt(hStmt), SQLFreeStmt(hStmt, SQL_UNBIND));
- }
- odbc_tables: {
- unsigned found[tabCount];
- for (unsigned i = 0; i < tabCount; i++)
- found[i] = 0;
- test.run(HStmt(hStmt), SQLTables(hStmt, (SQLCHAR*)0, 0, (SQLCHAR*)0, 0, (SQLCHAR*)0, 0, (SQLCHAR*)0, 0));
- char tableName[200] = "";
- char tableType[200] = "";
- test.run(HStmt(hStmt), SQLBindCol(hStmt, 3, SQL_C_CHAR, tableName, sizeof(tableName), 0));
- test.run(HStmt(hStmt), SQLBindCol(hStmt, 4, SQL_C_CHAR, tableType, sizeof(tableType), 0));
- unsigned cnt = 0;
- while (1) {
- test.exp(SQL_NO_DATA, 0, 0, false);
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- if (test.m_ret == SQL_NO_DATA)
- break;
- test.timerCnt(1);
- cnt++;
- if (! blankeq(tableType, "TABLE"))
- continue;
- for (unsigned i = 0; i < tabCount; i++) {
- const Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- if (! blankeq(tab.m_name, tableName))
- continue;
- test.chk(HStmt(hStmt), found[i] == 0, "duplicate table %s", tab.m_name);
- found[i]++;
- }
- }
-#ifndef iODBC
- test.run(HStmt(hStmt), SQLCloseCursor(hStmt));
-#else
- freeStmt(test, hDbc, hStmt);
- allocStmt(test, hDbc, hStmt);
-#endif
- for (unsigned i = 0; i < tabCount; i++) {
- const Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- test.chk(HStmt(hStmt), found[i] == 1, "table %s not found", tab.m_name);
- }
- if (opt.m_v >= 2)
- ndbout << "found " << cnt << " tables" << endl;
- test.run(HStmt(hStmt), SQLFreeStmt(hStmt, SQL_UNBIND));
- }
- odbc_columns: {
- unsigned found[tabCount][maxColCount];
- for (unsigned i = 0; i < tabCount; i++) {
- for (unsigned j = 0; j < maxColCount; j++)
- found[i][j] = 0;
- }
- test.run(HStmt(hStmt), SQLColumns(hStmt, (SQLCHAR*)0, 0, (SQLCHAR*)0, 0, (SQLCHAR*)0, 0, (SQLCHAR*)0, 0));
- char tableName[200] = "";
- char columnName[200] = "";
- long dataType = 0;
- test.run(HStmt(hStmt), SQLBindCol(hStmt, 3, SQL_C_CHAR, tableName, sizeof(tableName), 0));
- test.run(HStmt(hStmt), SQLBindCol(hStmt, 4, SQL_C_CHAR, columnName, sizeof(columnName), 0));
- test.run(HStmt(hStmt), SQLBindCol(hStmt, 5, SQL_C_SLONG, &dataType, 0, 0));
- unsigned cnt = 0;
- while (1) {
- test.exp(SQL_NO_DATA, 0, 0, false);
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- if (test.m_ret == SQL_NO_DATA)
- break;
- test.timerCnt(1);
- cnt++;
- for (unsigned i = 0; i < tabCount; i++) {
- const Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- if (! blankeq(tab.m_name, tableName))
- continue;
- bool columnFound = false;
- for (unsigned j = 0; j < tab.m_colCount; j++) {
- const Col& col = tab.m_colList[j];
- if (! blankeq(col.m_name, columnName))
- continue;
- test.chk(HStmt(hStmt), found[i][j] == 0, "duplicate column %s.%s", tableName, columnName);
- found[i][j]++;
- columnFound = true;
- }
- test.chk(HStmt(hStmt), columnFound, "unknown column %s.%s", tableName, columnName);
- }
- }
-#ifndef iODBC
- test.run(HStmt(hStmt), SQLCloseCursor(hStmt));
-#else
- freeStmt(test, hDbc, hStmt);
- allocStmt(test, hDbc, hStmt);
-#endif
- for (unsigned i = 0; i < tabCount; i++) {
- const Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- for (unsigned j = 0; j < tab.m_colCount; j++) {
- const Col& col = tab.m_colList[j];
- test.chk(HStmt(hStmt), found[i][j] == 1, "column %s.%s not found", tab.m_name, col.m_name);
- }
- }
- if (opt.m_v >= 2)
- ndbout << "found " << cnt << " columns" << endl;
- test.run(HStmt(hStmt), SQLFreeStmt(hStmt, SQL_UNBIND));
- }
- odbc_primarykeys: {
- // table patterns are no allowed
- for (unsigned i = 0; i < tabCount; i++) {
- const Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- char tmp[200]; // p.i.t.a
- strcpy(tmp, tab.m_name);
- for (char* a = tmp; *a != 0; a++) {
- if ('a' <= *a && *a <= 'z')
- *a -= 'a' - 'A';
- }
- test.run(HStmt(hStmt), SQLPrimaryKeys(hStmt, (SQLCHAR*)0, 0, (SQLCHAR*)0, 0, (SQLCHAR*)tmp, SQL_NTS));
- char tableName[200] = "";
- char columnName[200] = "";
- long keySeq = -1;
- test.run(HStmt(hStmt), SQLBindCol(hStmt, 3, SQL_C_CHAR, tableName, sizeof(tableName), 0));
- test.run(HStmt(hStmt), SQLBindCol(hStmt, 4, SQL_C_CHAR, columnName, sizeof(columnName), 0));
- test.run(HStmt(hStmt), SQLBindCol(hStmt, 5, SQL_C_SLONG, &keySeq, 0, 0));
- unsigned cnt = 0;
- while (1) {
- if (cnt == tab.m_pkCount)
- test.exp(SQL_NO_DATA, 0, 0, true);
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- if (test.m_ret == SQL_NO_DATA)
- break;
- test.chk(HStmt(hStmt), keySeq == 1 + cnt, "got %ld != %u", keySeq, 1 + cnt);
- const Col& col = tab.m_colList[tab.m_pkIndex[keySeq - 1]];
- test.chk(HStmt(hStmt), blankeq(columnName, col.m_name), "got %s != %s", columnName, col.m_name);
- test.timerCnt(1);
- cnt++;
- }
-#ifndef iODBC
- test.run(HStmt(hStmt), SQLCloseCursor(hStmt));
-#else
- freeStmt(test, hDbc, hStmt);
- allocStmt(test, hDbc, hStmt);
-#endif
- }
- test.run(HStmt(hStmt), SQLFreeStmt(hStmt, SQL_UNBIND));
- }
- freeAll(test, hEnv, hDbc, hStmt);
-}
-
-// insert
-
-static void
-testInsert(Test& test)
-{
- SQLHANDLE hEnv, hDbc, hStmtList[tabCount];
- allocAll(test, hEnv, hDbc, hStmtList, tabCount);
- char sql[MAX_SQL], *sqlptr;
- for (unsigned i = 0; i < tabCount; i++) {
- SQLHANDLE& hStmt = hStmtList[i];
- const Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- // prepare
- tab.insertAll(sqlptr = sql);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLPrepare(hStmt, (SQLCHAR*)sql, SQL_NTS));
- SQLSMALLINT parCount = -1;
- test.run(HStmt(hStmt), SQLNumParams(hStmt, &parCount));
- test.chk(HStmt(hStmt), parCount == tab.m_colCount, "got %d != %d", (int)parCount, (int)tab.m_colCount);
- // bind parameters
- Row row(tab);
- for (unsigned j = 0; j < tab.m_colCount; j++) {
- Fld& fld = row.m_fldList[j];
- const Col& col = fld.m_col;
- // every other at-exec
- SQLPOINTER caddr;
- SQLINTEGER* ind;
- if (opt.m_noputd || j % 2 == 0) {
- caddr = fld.caddr();
- ind = fld.ind();
- } else {
- caddr = (SQLPOINTER)j;
- ind = fld.need();
- }
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 1 + j, SQL_PARAM_INPUT, col.ctype(), col.type(), col.size(), 0, caddr, col.csize(), ind));
- }
- // bind columns (none)
- SQLSMALLINT colCount = -1;
- test.run(HStmt(hStmt), SQLNumResultCols(hStmt, &colCount));
- test.chk(HStmt(hStmt), colCount == 0, "got %d != 0", (int)colCount);
- // execute
- for (unsigned k = 0; k < opt.m_scale; k++) {
- if (k % 5 == 0) {
- // rebind
- unsigned j = 0;
- Fld& fld = row.m_fldList[j];
- const Col& col = fld.m_col;
- // every other at-exec
- SQLPOINTER caddr;
- SQLINTEGER* ind;
- if (opt.m_noputd || j % 2 == 0) {
- caddr = fld.caddr();
- ind = fld.ind();
- } else {
- caddr = (SQLPOINTER)j;
- ind = fld.need();
- }
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 1 + j, SQL_PARAM_INPUT, col.ctype(), col.type(), col.size(), 0, caddr, col.csize(), ind));
- }
- row.calcPk(test, k);
- row.calcNk(test);
- unsigned needData = opt.m_noputd ? 0 : tab.m_colCount / 2;
- if (needData)
- test.exp(SQL_NEED_DATA, 0, 0, true);
- test.run(HStmt(hStmt), SQLExecute(hStmt));
- test.chk(HStmt(hStmt), test.m_functionCode == SQL_DIAG_INSERT, "got %d != %d", test.m_functionCode, SQL_DIAG_INSERT);
- if (needData) {
- while (1) {
- SQLPOINTER jPtr = (SQLPOINTER)999;
- if (needData)
- test.exp(SQL_NEED_DATA, 0, 0, true);
- // completes SQLExecute on success
- test.run(HStmt(hStmt), SQLParamData(hStmt, &jPtr));
- if (! needData)
- break;
- unsigned j = (unsigned)jPtr;
- test.chk(HStmt(hStmt), j < tab.m_colCount && j % 2 != 0, "got %u 0x%x", j, j);
- Fld& fld = row.m_fldList[j];
- const Col& col = fld.m_col;
- SQLSMALLINT ctype = col.ctype();
- if (k % 2 == 0 || ctype != Col::CChar)
- test.run(HStmt(hStmt), SQLPutData(hStmt, fld.caddr(), *fld.ind()));
- else {
- // put in pieces
- unsigned size = col.csize() - 1; // omit null terminator
- char* caddr = (char*)(fld.caddr());
- unsigned off = 0;
- while (off < size) {
- unsigned m = size / 7; // bytes to put
- if (m == 0)
- m = 1;
- if (m > size - off)
- m = size - off;
- bool putNull = (*fld.ind() == SQL_NULL_DATA);
- // no null terminator
- SQLINTEGER len = putNull ? SQL_NULL_DATA : (int)m;
- test.run(HStmt(hStmt), SQLPutData(hStmt, caddr + off, len));
- if (putNull)
- break;
- off += m;
- }
- }
- needData--;
- }
- }
- chkRowCount(test, hStmt, 1);
- chkTuplesFetched(test, hStmt, 0);
- }
- test.timerCnt(opt.m_scale);
- if (opt.m_v >= 3)
- ndbout << "inserted " << opt.m_scale << " into " << tab.m_name << endl;
- }
- freeAll(test, hEnv, hDbc, hStmtList, tabCount);
-}
-
-// count
-
-static void
-testCount(Test& test)
-{
- SQLHANDLE hEnv, hDbc, hStmtList[tabCount];
- allocAll(test, hEnv, hDbc, hStmtList, tabCount);
- for (unsigned i = 0; i < tabCount; i++) {
- SQLHANDLE& hStmt = hStmtList[i];
- const Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- long count = -1;
- selectCount(test, hStmt, tab, &count);
- test.chk(HStmt(hStmt), count == opt.m_scale * opt.m_threads, "got %ld != %u", count, opt.m_scale * opt.m_threads);
- test.timerCnt(count);
- if (opt.m_v >= 3)
- ndbout << "counted " << (int)count << " rows in " << tab.m_name << endl;
- }
- // scan all at same time
- char sql[MAX_SQL], *sqlptr;
- for (unsigned i = 0; i < tabCount; i++) {
- SQLHANDLE& hStmt = hStmtList[i];
- const Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- tab.selectAll(sqlptr = sql);
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- }
- unsigned k = 0;
- while (1) {
- for (unsigned i = 0; i < tabCount; i++) {
- SQLHANDLE& hStmt = hStmtList[i];
- const Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- if (k == opt.m_scale * opt.m_threads)
- test.exp(SQL_NO_DATA, 0, 0, true);
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- if (k != opt.m_scale * opt.m_threads) {
- chkTuplesFetched(test, hStmt, k + 1);
- test.timerCnt(1);
- } else {
- chkTuplesFetched(test, hStmt, k);
- test.exp(SQL_NO_DATA, 0, 0, true);
- test.run(HStmt(hStmt), SQLMoreResults(hStmt));
- }
- }
- if (k == opt.m_scale * opt.m_threads)
- break;
- k++;
- }
- if (opt.m_v >= 3)
- ndbout << "scanned " << opt.m_scale << " rows from each table" << endl;
- freeAll(test, hEnv, hDbc, hStmtList, tabCount);
-}
-
-// update
-
-static void
-testUpdatePk(Test& test)
-{
- SQLHANDLE hEnv, hDbc, hStmtList[tabCount];
- allocAll(test, hEnv, hDbc, hStmtList, tabCount);
- char sql[MAX_SQL], *sqlptr;
- for (unsigned i = 0; i < tabCount; i++) {
- SQLHANDLE& hStmt = hStmtList[i];
- const Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- // prepare
- tab.updatePk(sqlptr = sql);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLPrepare(hStmt, (SQLCHAR*)sql, SQL_NTS));
- // bind parameters
- Row row(tab);
- SQLSMALLINT parCount = -1;
- test.run(HStmt(hStmt), SQLNumParams(hStmt, &parCount));
- test.chk(HStmt(hStmt), parCount == tab.m_colCount, "got %d != %d", (int)parCount, (int)tab.m_colCount);
- for (unsigned j = 0; j < tab.m_nkCount; j++) {
- Fld& fld = row.m_fldList[tab.m_nkIndex[j]];
- const Col& col = fld.m_col;
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 1 + j, SQL_PARAM_INPUT, col.ctype(), col.type(), col.size(), 0, fld.caddr(), col.csize(), fld.ind()));
- }
- for (unsigned j = 0; j < tab.m_pkCount; j++) {
- Fld& fld = row.m_fldList[tab.m_pkIndex[j]];
- const Col& col = fld.m_col;
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 1 + tab.m_nkCount + j, SQL_PARAM_INPUT, col.ctype(), col.type(), col.size(), 0, fld.caddr(), col.csize(), fld.ind()));
- }
- // bind columns (none)
- SQLSMALLINT colCount = -1;
- test.run(HStmt(hStmt), SQLNumResultCols(hStmt, &colCount));
- test.chk(HStmt(hStmt), colCount == 0, "got %d != 0", (int)colCount);
- // execute
- for (unsigned k = 0; k < opt.m_scale; k++) {
- if (k % 5 == 0) {
- unsigned j = 0;
- Fld& fld = row.m_fldList[tab.m_nkIndex[j]];
- const Col& col = fld.m_col;
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 1 + j, SQL_PARAM_INPUT, col.ctype(), col.type(), col.size(), 0, fld.caddr(), col.csize(), fld.ind()));
- }
- row.calcPk(test, k);
- row.calcNk(test);
- test.run(HStmt(hStmt), SQLExecute(hStmt));
- test.chk(HStmt(hStmt), test.m_functionCode == SQL_DIAG_UPDATE_WHERE, "got %d != %d", test.m_functionCode, SQL_DIAG_UPDATE_WHERE);
- chkRowCount(test, hStmt, 1);
- // direct update, no read has been necessary
- chkTuplesFetched(test, hStmt, 0);
- }
- test.timerCnt(opt.m_scale);
- if (opt.m_v >= 3)
- ndbout << "updated " << opt.m_scale << " in " << tab.m_name << endl;
- }
- freeAll(test, hEnv, hDbc, hStmtList, tabCount);
-}
-
-static void
-testUpdateScan(Test& test)
-{
- SQLHANDLE hEnv, hDbc, hStmtList[tabCount];
- allocAll(test, hEnv, hDbc, hStmtList, tabCount);
- char sql[MAX_SQL], *sqlptr;
- for (unsigned i = 0; i < tabCount; i++) {
- SQLHANDLE& hStmt = hStmtList[i];
- const Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- // prepare
- tab.updateRange(sqlptr = sql);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLPrepare(hStmt, (SQLCHAR*)sql, SQL_NTS));
- // bind parameters
- Row row(tab); // for set clause
- Row rowlo(tab); // for pk ranges
- Row rowhi(tab);
- SQLSMALLINT parCount = -1;
- test.run(HStmt(hStmt), SQLNumParams(hStmt, &parCount));
- test.chk(HStmt(hStmt), parCount == tab.m_nkCount + 2 * tab.m_pkCount, "got %d != %d", (int)parCount, (int)tab.m_nkCount + 2 * (int)tab.m_pkCount);
- for (unsigned j = 0; j < tab.m_nkCount; j++) {
- const Col& col = tab.m_colList[tab.m_nkIndex[j]];
- Fld& fld = row.m_fldList[tab.m_nkIndex[j]];
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 1 + j, SQL_PARAM_INPUT, col.ctype(), col.type(), col.size(), 0, fld.caddr(), col.csize(), fld.ind()));
- }
- bool canInterp = true;
- for (unsigned j = 0; j < tab.m_pkCount; j++) {
- const Col& col = tab.m_colList[tab.m_pkIndex[j]];
- Fld& fldlo = rowlo.m_fldList[tab.m_pkIndex[j]];
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 1 + tab.m_nkCount + 2 * j + 0, SQL_PARAM_INPUT, col.ctype(), col.type(), col.size(), 0, fldlo.caddr(), col.csize(), fldlo.ind()));
- Fld& fldhi = rowhi.m_fldList[tab.m_pkIndex[j]];
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 1 + tab.m_nkCount + 2 * j + 1, SQL_PARAM_INPUT, col.ctype(), col.type(), col.size(), 0, fldhi.caddr(), col.csize(), fldhi.ind()));
- if (col.m_type != Col::Char)
- canInterp = false; // XXX no unsigned yet
- }
- // execute
- row.calcPk(test, 0);
- row.calcNk(test);
- rowlo.calcPk(test, 0);
- rowhi.calcPk(test, test.m_mul); // sucks
- test.run(HStmt(hStmt), SQLExecute(hStmt));
- test.chk(HStmt(hStmt), test.m_functionCode == SQL_DIAG_UPDATE_WHERE, "got %d != %d", test.m_functionCode, SQL_DIAG_UPDATE_WHERE);
- chkRowCount(test, hStmt, opt.m_scale);
- chkTuplesFetched(test, hStmt, canInterp ? opt.m_scale : opt.m_scale * opt.m_threads);
- test.timerCnt(opt.m_scale);
- if (opt.m_v >= 3)
- ndbout << "updated " << opt.m_scale << " in " << tab.m_name << endl;
- }
- freeAll(test, hEnv, hDbc, hStmtList, tabCount);
-}
-
-// verify
-
-static void
-testVerifyPk(Test& test)
-{
- SQLHANDLE hEnv, hDbc, hStmtList[tabCount];
- allocAll(test, hEnv, hDbc, hStmtList, tabCount);
- char sql[MAX_SQL], *sqlptr;
- for (unsigned i = 0; i < tabCount; i++) {
- SQLHANDLE& hStmt = hStmtList[i];
- const Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- // prepare
- tab.selectPk(sqlptr = sql);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLPrepare(hStmt, (SQLCHAR*)sql, SQL_NTS));
- // use same row for input and output
- Row row(tab);
- // bind parameters
- SQLSMALLINT parCount = -1;
- test.run(HStmt(hStmt), SQLNumParams(hStmt, &parCount));
- test.chk(HStmt(hStmt), parCount == tab.m_pkCount, "got %d != %d", (int)parCount, (int)tab.m_pkCount);
- for (unsigned j = 0; j < tab.m_pkCount; j++) {
- Fld& fld = row.m_fldList[tab.m_pkIndex[j]];
- const Col& col = fld.m_col;
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 1 + j, SQL_PARAM_INPUT, col.ctype(), col.type(), col.size(), 0, fld.caddr(), col.csize(), fld.ind()));
- }
- // bind columns
- SQLSMALLINT colCount = -1;
- test.run(HStmt(hStmt), SQLNumResultCols(hStmt, &colCount));
- test.chk(HStmt(hStmt), colCount == tab.m_colCount, "got %d != %d", (int)colCount, (int)tab.m_colCount);
- for (unsigned j = 0; j < tab.m_colCount; j++) {
- Fld& fld = row.m_fldList[j];
- const Col& col = fld.m_col;
- test.run(HStmt(hStmt), SQLBindCol(hStmt, 1 + j, col.ctype(), fld.caddr(), col.csize(), fld.ind()));
- }
- // row for SQLGetData
- Row rowGet(tab);
- // reference row
- Row rowRef(tab);
- // execute
- for (unsigned k = 0; k < opt.m_scale; k++) {
- if (k % 5 == 0) {
- // rebind
- unsigned j = 0;
- Fld& fld = row.m_fldList[tab.m_pkIndex[j]];
- const Col& col = fld.m_col;
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 1 + j, SQL_PARAM_INPUT, col.ctype(), col.type(), col.size(), 0, fld.caddr(), col.csize(), fld.ind()));
- }
- row.calcPk(test, k);
- test.run(HStmt(hStmt), SQLExecute(hStmt));
- test.chk(HStmt(hStmt), test.m_functionCode == SQL_DIAG_SELECT_CURSOR, "got %d != %d", test.m_functionCode, SQL_DIAG_SELECT_CURSOR);
- // fetch
- for (unsigned k2 = 0; ; k2++) {
- if (k2 == 1)
- test.exp(SQL_NO_DATA, 0, 0, true);
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- chkTuplesFetched(test, hStmt, 1);
- if (k2 == 1)
- break;
- rowRef.calcPk(test, k);
- test.chk(HStmt(hStmt), row.verifyPk(test, rowRef), "verify row=%d", k);
- if (test.m_const)
- rowRef.calcPk(test, 0);
- rowRef.calcNk(test);
- test.chk(HStmt(hStmt), row.verifyNk(test, rowRef), "verify row=%d", k);
- // SQLGetData is supported independent of SQLBindCol
- if (opt.m_nogetd)
- continue;
- for (unsigned j = 0; j < tab.m_colCount; j++) {
- Fld& fld = rowGet.m_fldList[j];
- fld.zero();
- const Col& col = fld.m_col;
- // test both variants
- SQLSMALLINT ctype = k % 2 == 0 ? col.ctype() : SQL_ARD_TYPE;
- if (ctype != Col::CChar)
- test.run(HStmt(hStmt), SQLGetData(hStmt, 1 + j, ctype, fld.caddr(), col.csize(), fld.ind()));
- else {
- // get in pieces
- unsigned size = col.csize() - 1; // omit null terminator
- char* caddr = (char*)(fld.caddr());
- unsigned off = 0;
- while (off < size) {
- unsigned m = size / 3; // bytes to get
- if (m == 0)
- m = 1;
- if (m > size - off)
- m = size - off;
- bool getNull = (rowRef.m_fldList[j].m_ind == SQL_NULL_DATA);
- if (off + m < size && ! getNull)
- test.exp(SQL_SUCCESS_WITH_INFO, "01004", -1, true);
- // include null terminator in buffer size
- test.run(HStmt(hStmt), SQLGetData(hStmt, 1 + j, ctype, caddr + off, m + 1, fld.ind()));
- int ind = *fld.ind();
- if (getNull) {
- test.chk(HStmt(hStmt), ind == SQL_NULL_DATA, "got %d", ind);
- break;
- }
- test.chk(HStmt(hStmt), ind == size - off, "got %d != %u", ind, size - off);
- off += m;
- }
- }
- }
- rowRef.calcPk(test, k);
- test.chk(HStmt(hStmt), rowGet.verifyPk(test, rowRef), "verify row=%d", k);
- if (test.m_const)
- rowRef.calcPk(test, 0);
- rowRef.calcNk(test);
- test.chk(HStmt(hStmt), rowGet.verifyNk(test, rowRef), "verify row=%d", k);
- // SQLGetData again
- for (unsigned j = 0; j < tab.m_colCount; j++) {
- Fld& fld = rowGet.m_fldList[j];
- const Col& col = fld.m_col;
- // test both variants
- SQLSMALLINT ctype = k % 2 == 0 ? col.ctype() : SQL_ARD_TYPE;
- // expect no more data
- test.exp(SQL_NO_DATA, 0, 0, true);
- test.run(HStmt(hStmt), SQLGetData(hStmt, 1 + j, ctype, fld.caddr(), col.csize(), fld.ind()));
- }
- }
- test.run(HStmt(hStmt), SQLCloseCursor(hStmt));
- }
- test.timerCnt(opt.m_scale);
- if (opt.m_v >= 3)
- ndbout << "verified " << opt.m_scale << " from " << tab.m_name << endl;
- }
- freeAll(test, hEnv, hDbc, hStmtList, tabCount);
-}
-
-static void
-testVerifyScan(Test& test)
-{
- SQLHANDLE hEnv, hDbc, hStmtList[tabCount];
- allocAll(test, hEnv, hDbc, hStmtList, tabCount);
- char sql[MAX_SQL], *sqlptr;
- for (unsigned i = 0; i < tabCount; i++) {
- SQLHANDLE& hStmt = hStmtList[i];
- const Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- // prepare
- tab.selectRange(sqlptr = sql, ! opt.m_nosort);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLPrepare(hStmt, (SQLCHAR*)sql, SQL_NTS));
- // bind parameters
- Row rowlo(tab); // use available PK fields..
- Row rowhi(tab); // since we have no other way for now
- SQLSMALLINT parCount = -1;
- test.run(HStmt(hStmt), SQLNumParams(hStmt, &parCount));
- test.chk(HStmt(hStmt), parCount == 2 * tab.m_pkCount, "got %d != %d", (int)parCount, 2 * (int)tab.m_pkCount);
- for (unsigned j = 0; j < tab.m_pkCount; j++) {
- const Col& col = tab.m_colList[tab.m_pkIndex[j]];
- Fld& fldlo = rowlo.m_fldList[tab.m_pkIndex[j]];
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 1 + 2 * j + 0, SQL_PARAM_INPUT, col.ctype(), col.type(), col.size(), 0, fldlo.caddr(), col.csize(), fldlo.ind()));
- Fld& fldhi = rowhi.m_fldList[tab.m_pkIndex[j]];
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 1 + 2 * j + 1, SQL_PARAM_INPUT, col.ctype(), col.type(), col.size(), 0, fldhi.caddr(), col.csize(), fldhi.ind()));
- }
- // bind columns
- Row row(tab);
- SQLSMALLINT colCount = -1;
- test.run(HStmt(hStmt), SQLNumResultCols(hStmt, &colCount));
- test.chk(HStmt(hStmt), colCount == tab.m_colCount, "got %d != %d", (int)colCount, (int)tab.m_colCount);
- for (unsigned j = 0; j < tab.m_colCount; j++) {
- Fld& fld = row.m_fldList[j];
- const Col& col = fld.m_col;
- test.run(HStmt(hStmt), SQLBindCol(hStmt, 1 + j, col.ctype(), fld.caddr(), col.csize(), fld.ind()));
- }
- // execute
- rowlo.calcPk(test, 0);
- rowhi.calcPk(test, test.m_mul); // sucks
- test.run(HStmt(hStmt), SQLExecute(hStmt));
- test.chk(HStmt(hStmt), test.m_functionCode == SQL_DIAG_SELECT_CURSOR, "got %d != %d", test.m_functionCode, SQL_DIAG_SELECT_CURSOR);
- // reference row
- Row rowRef(tab);
- // fetch
- unsigned k = 0;
- SQLUINTEGER rowCount1 = (SQLUINTEGER)-1;
- test.run(HStmt(hStmt), SQLSetStmtAttr(hStmt, SQL_ATTR_ROWS_FETCHED_PTR, &rowCount1, SQL_IS_POINTER));
- while (1) {
- unsigned countExp;
- if (k == opt.m_scale) {
- countExp = k;
- test.exp(SQL_NO_DATA, 0, 0, true);
- } else {
- countExp = k + 1;
- }
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- // let me count the ways..
- chkRowCount(test, hStmt, countExp);
- test.chk(HStmt(hStmt), rowCount1 == countExp, "got %lu != %u", rowCount1, countExp);
- SQLUINTEGER rowCount2 = (SQLUINTEGER)-1;
- test.run(HStmt(hStmt), SQLGetStmtAttr(hStmt, SQL_ATTR_ROW_NUMBER, &rowCount2, SQL_IS_POINTER, 0));
- test.chk(HStmt(hStmt), rowCount2 == countExp, "got %lu != %u", rowCount2, countExp);
- if (k == opt.m_scale)
- break;
- if (! opt.m_nosort) {
- // expecting k-th row
- rowRef.calcPk(test, k);
- test.chk(HStmt(hStmt), row.verifyPk(test, rowRef), "verify row=%d", k);
- if (test.m_const)
- rowRef.calcPk(test, 0);
- rowRef.calcNk(test);
- test.chk(HStmt(hStmt), row.verifyNk(test, rowRef), "verify row=%d", k);
- } else {
- // expecting random row
- rowRef.copy(row);
- test.chk(HStmt(hStmt), row.verifyNk(test, rowRef), "verify row=%d", k);
- }
- k++;
- }
- test.timerCnt(opt.m_scale);
- if (opt.m_v >= 3)
- ndbout << "verified " << opt.m_scale << " from " << tab.m_name << endl;
- }
- freeAll(test, hEnv, hDbc, hStmtList, tabCount);
-}
-
-// self-join (scan followed by pk lookups)
-
-static void
-testJoin(Test& test)
-{
- SQLHANDLE hEnv, hDbc, hStmtList[tabCount];
- allocAll(test, hEnv, hDbc, hStmtList, tabCount);
- char sql[MAX_SQL], *sqlptr;
- for (unsigned cnt = opt.m_depth; cnt <= opt.m_depth; cnt++) {
- for (unsigned i = 0; i < tabCount; i++) {
- SQLHANDLE& hStmt = hStmtList[i];
- Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- tab.selectJoin(sqlptr = sql, cnt);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- }
- unsigned k = 0;
- while (1) {
- for (unsigned i = 0; i < tabCount; i++) {
- SQLHANDLE& hStmt = hStmtList[i];
- const Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- if (k == opt.m_scale * opt.m_threads)
- test.exp(SQL_NO_DATA, 0, 0, true);
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- if (k == opt.m_scale * opt.m_threads) {
- chkTuplesFetched(test, hStmt, k * opt.m_depth);
- test.run(HStmt(hStmt), SQLCloseCursor(hStmt));
- } else {
- chkTuplesFetched(test, hStmt, (k + 1) * opt.m_depth);
- test.timerCnt(1);
- }
- }
- if (k == opt.m_scale * opt.m_threads)
- break;
- k++;
- }
- }
- freeAll(test, hEnv, hDbc, hStmtList, tabCount);
-}
-
-// cartesian join (multiple nested scans)
-
-static void
-testCart(Test& test)
-{
- SQLHANDLE hEnv, hDbc, hStmtList[tabCount];
- allocAll(test, hEnv, hDbc, hStmtList, tabCount);
- char sql[MAX_SQL], *sqlptr;
- for (unsigned cnt = 2; cnt <= 2; cnt++) {
- unsigned rows = 1;
- //for (unsigned k = 0; k < opt.m_depth; k++) {
- //rows *= opt.m_scale * opt.m_threads;
- //}
- for (unsigned i = 0; i < tabCount; i++) {
- SQLHANDLE& hStmt = hStmtList[i];
- Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- tab.selectCart(sqlptr = sql, cnt);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- }
- unsigned k = 0;
- while (1) {
- for (unsigned i = 0; i < tabCount; i++) {
- SQLHANDLE& hStmt = hStmtList[i];
- const Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- if (k == rows)
- test.exp(SQL_NO_DATA, 0, 0, true);
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- if (k == rows) {
- //chkTuplesFetched(test, hStmt, k);
- test.run(HStmt(hStmt), SQLCloseCursor(hStmt));
- } else {
- //chkTuplesFetched(test, hStmt, k + 1);
- test.timerCnt(1);
- }
- }
- if (k == rows)
- break;
- k++;
- }
- }
- freeAll(test, hEnv, hDbc, hStmtList, tabCount);
-}
-
-// delete
-
-static void
-testDeleteAll(Test& test)
-{
- SQLHANDLE hEnv, hDbc, hStmtList[tabCount];
- allocAll(test, hEnv, hDbc, hStmtList, tabCount);
- char sql[MAX_SQL], *sqlptr;
- for (unsigned i = 0; i < tabCount; i++) {
- SQLHANDLE& hStmt = hStmtList[i];
- Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- long count0 = -1;
- selectCount(test, hStmt, tab, &count0);
- tab.deleteAll(sqlptr = sql);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLPrepare(hStmt, (SQLCHAR*)sql, SQL_NTS));
- if (count0 == 0)
- test.exp(SQL_NO_DATA, 0, 0, true);
- test.run(HStmt(hStmt), SQLExecute(hStmt));
-#ifndef iODBC
- test.chk(HStmt(hStmt), test.m_functionCode == SQL_DIAG_DELETE_WHERE, "got %d != %d", test.m_functionCode, SQL_DIAG_DELETE_WHERE);
-#endif
- SQLINTEGER rowCount = -1;
- getRowCount(test, hStmt, &rowCount);
- test.timerCnt(rowCount);
- test.chk(HStmt(hStmt), rowCount == count0, "got %d != %ld", (int)rowCount, count0);
- chkTuplesFetched(test, hStmt, rowCount);
- if (opt.m_v >= 3)
- ndbout << "deleted " << (int)rowCount << " from " << tab.m_name << endl;
- long count = -1;
- selectCount(test, hStmt, tab, &count);
- test.chk(HStmt(hStmt), count == 0, "got %ld != 0", count);
- }
- freeAll(test, hEnv, hDbc, hStmtList, tabCount);
-}
-
-static void
-testDeletePk(Test& test)
-{
- SQLHANDLE hEnv, hDbc, hStmtList[tabCount];
- allocAll(test, hEnv, hDbc, hStmtList, tabCount);
- char sql[MAX_SQL], *sqlptr;
- for (unsigned i = 0; i < tabCount; i++) {
- SQLHANDLE& hStmt = hStmtList[i];
- const Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- // prepare
- tab.deletePk(sqlptr = sql);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLPrepare(hStmt, (SQLCHAR*)sql, SQL_NTS));
- // bind parameters
- Row row(tab);
- SQLSMALLINT parCount = -1;
- test.run(HStmt(hStmt), SQLNumParams(hStmt, &parCount));
- test.chk(HStmt(hStmt), parCount == tab.m_pkCount, "got %d != %d", (int)parCount, (int)tab.m_colCount);
- for (unsigned j = 0; j < tab.m_pkCount; j++) {
- Fld& fld = row.m_fldList[tab.m_pkIndex[j]];
- const Col& col = fld.m_col;
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 1 + j, SQL_PARAM_INPUT, col.ctype(), col.type(), col.size(), 0, fld.caddr(), col.csize(), fld.ind()));
- }
- // bind columns (none)
- SQLSMALLINT colCount = -1;
- test.run(HStmt(hStmt), SQLNumResultCols(hStmt, &colCount));
- test.chk(HStmt(hStmt), colCount == 0, "got %d != 0", (int)colCount);
- // execute
- for (unsigned k = 0; k < opt.m_scale; k++) {
- row.calcPk(test, k);
- test.run(HStmt(hStmt), SQLExecute(hStmt));
- test.chk(HStmt(hStmt), test.m_functionCode == SQL_DIAG_DELETE_WHERE, "got %d != %d", test.m_functionCode, SQL_DIAG_DELETE_WHERE);
- chkRowCount(test, hStmt, 1);
- // direct delete, no fetch required
- chkTuplesFetched(test, hStmt, 0);
- }
- test.timerCnt(opt.m_scale);
- if (opt.m_v >= 3)
- ndbout << "updated " << opt.m_scale << " in " << tab.m_name << endl;
- }
- freeAll(test, hEnv, hDbc, hStmtList, tabCount);
-}
-
-static void
-testTrans(Test& test)
-{
-#ifdef unixODBC
- if (opt.m_v >= 1)
- ndbout << "unixODBC does not support transactions - test skipped" << endl;
-#else
- SQLHANDLE hEnv, hDbc, hStmtList[tabCount];
- allocAll(test, hEnv, hDbc, hStmtList, tabCount);
- char sql[MAX_SQL], *sqlptr;
- // delete all
- for (unsigned i = 0; i < tabCount; i++) {
- SQLHANDLE& hStmt = hStmtList[i];
- const Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- tab.deleteAll(sqlptr = sql);
- test.exp(SQL_NO_DATA, 0, 0, false);
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- SQLINTEGER rowCount = -1;
- getRowCount(test, hStmt, &rowCount);
- if (opt.m_v >= 3)
- ndbout << "deleted " << (int)rowCount << " from " << tab.m_name << endl;
- }
- setAutocommit(test, hDbc, false);
- if (opt.m_v >= 2)
- ndbout << "set autocommit OFF" << endl;
- for (int commit = 0; commit < opt.m_scale; commit += 1) {
- bool rollback = (commit % 2 == 0);
- // XXX delete with no data leaves trans in error state for 2nd table
- if (commit > 0 && rollback) { // previous case was commit
- for (unsigned i = 0; i < tabCount; i++) {
- SQLHANDLE& hStmt = hStmtList[i];
- const Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- tab.deleteDirect(sqlptr = sql, 0);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.exp(SQL_NO_DATA, 0, 0, false);
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- }
- test.run(HDbc(hDbc), SQLEndTran(SQL_HANDLE_DBC, hDbc, SQL_COMMIT));
- }
- // insert
- for (unsigned i = 0; i < tabCount; i++) {
- SQLHANDLE& hStmt = hStmtList[i];
- const Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- tab.insertDirect(sqlptr = sql, 0);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- if (opt.m_v >= 2)
- ndbout << tab.m_name << ": inserted 1 row" << endl;
- }
- // count them via pk
- for (unsigned i = 0; i < tabCount; i++) {
- SQLHANDLE& hStmt = hStmtList[i];
- const Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- tab.countDirect(sqlptr = sql, 0);
- long count = -1;
- long countExp = 1;
- selectCount(test, hStmt, sql, &count);
- test.chk(HStmt(hStmt), count == countExp, "got %ld != %ld", count, countExp);
- }
- // count them via scan
- for (unsigned i = 0; i < tabCount; i++) {
- // XXX hupp no work
- break;
- SQLHANDLE& hStmt = hStmtList[i];
- const Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- long count = -1;
- long countExp = 1;
- selectCount(test, hStmt, tab, &count);
- test.chk(HStmt(hStmt), count == countExp, "got %ld != %ld", count, countExp);
- }
- // rollback or commit
- if (rollback) {
- if (opt.m_v >= 2)
- ndbout << "end trans ROLLBACK" << endl;
- test.run(HDbc(hDbc), SQLEndTran(SQL_HANDLE_DBC, hDbc, SQL_ROLLBACK));
- } else {
- if (opt.m_v >= 2)
- ndbout << "end trans COMMIT" << endl;
- test.run(HDbc(hDbc), SQLEndTran(SQL_HANDLE_DBC, hDbc, SQL_COMMIT));
- }
- // count them via pk again
- for (unsigned i = 0; i < tabCount; i++) {
- SQLHANDLE& hStmt = hStmtList[i];
- const Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- tab.countDirect(sqlptr = sql, 0);
- long count = -1;
- long countExp = rollback ? 0 : 1;
- selectCount(test, hStmt, sql, &count);
- test.chk(HStmt(hStmt), count == countExp, "got %ld != %ld", count, countExp);
- }
- // count them via scan again
- for (unsigned i = 0; i < tabCount; i++) {
- // XXX hupp no work
- break;
- SQLHANDLE& hStmt = hStmtList[i];
- const Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- long count = -1;
- long countExp = rollback ? 0 : 1;
- selectCount(test, hStmt, tab, &count);
- test.chk(HStmt(hStmt), count == countExp, "got %ld != %ld", count, countExp);
- }
- }
- freeAll(test, hEnv, hDbc, hStmtList, tabCount);
-#endif
-}
-
-static void
-testConcur(Test& test)
-{
- SQLHANDLE hEnv, hDbc, hStmtList[tabCount];
- allocAll(test, hEnv, hDbc, hStmtList, tabCount);
- char sql[MAX_SQL], *sqlptr;
- for (unsigned i = 0; i < tabCount; i++) {
- SQLHANDLE& hStmt = hStmtList[i];
- const Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- // delete all
- tab.deleteAll(sqlptr = sql);
- test.exp(SQL_NO_DATA, 0, 0, false);
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- // insert some
- unsigned rowcount = 10;
- for (unsigned n = 0; n < rowcount; n++) {
- tab.insertDirect(sqlptr = sql, n);
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- }
- verifyCount(test, hStmt, tab, rowcount);
- // start query scan followed by pk lookups
- tab.selectJoin(sqlptr = sql, 2);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- // start fetch
- unsigned k = 0;
- while (1) {
- if (k > 0)
- test.exp(SQL_ERROR, "24000", -1, true); // commit closed cursor
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- if (k > 0)
- break;
- // delete some random row
- tab.deleteDirect(sqlptr = sql, k);
- // try using same statement
- test.exp(SQL_ERROR, "24000", -1, true); // cursor is open
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- // try using different statement
- SQLHANDLE hStmt2;
- allocStmt(test, hDbc, hStmt2);
- test.run(HStmt(hStmt2), SQLExecDirect(hStmt2, (SQLCHAR*)sql, SQL_NTS));
- k++;
- }
- test.exp(SQL_ERROR, "24000", -1, true); // cursor is not open
- test.run(HStmt(hStmt), SQLCloseCursor(hStmt));
- test.timerCnt(rowcount);
- }
- freeAll(test, hEnv, hDbc, hStmtList, tabCount);
-}
-
-static void
-testReadcom(Test& test)
-{
- testDeleteAll(test);
- testInsert(test);
- const unsigned nc = 3;
- SQLHANDLE hEnv[nc], hDbc[nc], hStmt[nc];
- char sql[MAX_SQL], *sqlptr;
- for (unsigned j = 0; j < nc; j++)
- allocAll(test, hEnv[j], hDbc[j], hStmt[j]);
- for (unsigned i = 0; i < tabCount; i++) {
- Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- long count;
- // check count
- count = -1;
- selectCount(test, hStmt[0], tab, &count);
- test.chk(HStmt(hStmt[0]), count == opt.m_scale, "got %d != %d", (int)count, (int)opt.m_scale);
- // scan delete uncommitted with handle 0
- setAutocommit(test, hDbc[0], false);
- tab.deleteAll(sqlptr = sql);
- if (opt.m_scale == 0)
- test.exp(SQL_NO_DATA, 0, 0, false);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt[0]), SQLExecDirect(hStmt[0], (SQLCHAR*)sql, SQL_NTS));
- // scan via other tx should not hang and see all rows
- for (unsigned j = 0; j < nc; j++) {
- count = -1;
- int want = j == 0 ? 0 : opt.m_scale;
- selectCount(test, hStmt[j], tab, &count);
- test.chk(HStmt(hStmt[j]), count == want, "tx %u: got %d != %d", j, (int)count, want);
- if (opt.m_v >= 2)
- ndbout << "tx " << j << " ok !" << endl;
- }
- // setting autocommit on commits the delete
- setAutocommit(test, hDbc[0], true);
- // check count
- count = -1;
- selectCount(test, hStmt[0], tab, &count);
- test.chk(HStmt(hStmt[0]), count == 0, "got %d != 0", (int)count);
- }
- for (unsigned j = 0; j < nc; j++)
- freeAll(test, hEnv[j], hDbc[j], hStmt[j]);
-}
-
-static void
-testPerf(Test& test)
-{
- if (test.m_stuff == 0) {
- SQLHANDLE hEnv, hDbc, hStmt;
- allocAll(test, hEnv, hDbc, hStmt);
- char sql[MAX_SQL], *sqlptr;
- for (unsigned i = 0; i < tabCount; i++) {
- Tab& tab = tabList[i];
- if (! tab.optok())
- continue;
- test.exp(SQL_NO_DATA, 0, 0, false);
- tab.deleteAll(sqlptr = sql);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- long count0 = -1;
- // XXX triggers SEGV somewhere
- //selectCount(test, hStmt, tab, &count0);
- //test.chk(HStmt(hStmt), count0 == 0, "got %d != 0", (int)count0);
- }
- freeAll(test, hEnv, hDbc, hStmt);
- return;
- }
- assert(test.m_stuff == 1 || test.m_stuff == 2);
- bool ndbapi = (test.m_stuff == 1);
- tt01: {
- const unsigned OFF = 1000000;
- const unsigned N = 25;
- Tab& tab = tabList[1];
- if (! tab.optok())
- goto out;
- if (ndbapi) {
-#ifndef ndbODBC
- if (opt.m_v >= 1)
- ndbout << "running via DM - test skipped" << endl;
-#else
- Ndb* ndb = new Ndb("TEST_DB");
- ndb->init();
- if (ndb->waitUntilReady() != 0) {
- ndbout << ndb->getNdbError() << endl;
- fatal("waitUntilReady");
- }
- Uint32 val[1+N];
- // insert
- for (unsigned k = 1; k <= opt.m_scale; k++) {
- NdbConnection* con = ndb->startTransaction();
- if (con == 0) {
- ndbout << ndb->getNdbError() << endl;
- fatal("startTransaction");
- }
- NdbOperation* op = con->getNdbOperation(tab.m_upperName);
- if (op == 0) {
- ndbout << con->getNdbError() << endl;
- fatal("getNdbOperation");
- }
- if (op->insertTuple() == -1) {
- ndbout << op->getNdbError() << endl;
- fatal("insertTuple");
- }
- for (unsigned j = 0; j <= N; j++) {
- val[j] = (j == 0 ? k + test.m_no * OFF : k * j);
- if (j == 0) {
- if (op->equal(j, val[j]) == -1) {
- ndbout << op->getNdbError() << endl;
- fatal("equal");
- }
- } else {
- if (op->setValue(j, val[j]) == -1) {
- ndbout << op->getNdbError() << endl;
- fatal("setValue");
- }
- }
- }
- if (con->execute(Commit) == -1) {
- ndbout << con->getNdbError() << endl;
- fatal("execute");
- }
- ndb->closeTransaction(con);
- }
- test.timerCnt(opt.m_scale);
- // select PK
- for (unsigned k = 1; k <= opt.m_scale; k++) {
- NdbConnection* con = ndb->startTransaction();
- if (con == 0) {
- ndbout << ndb->getNdbError() << endl;
- fatal("startTransaction");
- }
- NdbOperation* op = con->getNdbOperation(tab.m_upperName);
- if (op == 0) {
- ndbout << con->getNdbError() << endl;
- fatal("getNdbOperation");
- }
- if (op->readTuple() == -1) {
- ndbout << op->getNdbError() << endl;
- fatal("insertTuple");
- }
- for (unsigned j = 0; j <= N; j++) {
- val[j] = (j == 0 ? k + test.m_no * OFF : 0);
- if (j == 0) {
- if (op->equal(j, val[j]) == -1) {
- ndbout << op->getNdbError() << endl;
- fatal("equal");
- }
- } else {
- if (op->getValue(j, (char*)&val[j]) == 0) {
- ndbout << op->getNdbError() << endl;
- fatal("getValue");
- }
- }
- }
- if (con->execute(Commit) == -1) {
- ndbout << con->getNdbError() << endl;
- fatal("execute");
- }
- for (unsigned j = 1; j <= N; j++) {
- assert(val[j] == k * j);
- }
- ndb->closeTransaction(con);
- }
- test.timerCnt(opt.m_scale);
- // delete PK
- for (unsigned k = 1; k <= opt.m_scale; k++) {
- NdbConnection* con = ndb->startTransaction();
- if (con == 0) {
- ndbout << ndb->getNdbError() << endl;
- fatal("startTransaction");
- }
- NdbOperation* op = con->getNdbOperation(tab.m_upperName);
- if (op == 0) {
- ndbout << con->getNdbError() << endl;
- fatal("getNdbOperation");
- }
- if (op->deleteTuple() == -1) {
- ndbout << op->getNdbError() << endl;
- fatal("deleteTuple");
- }
- unsigned j = 0;
- val[j] = k + test.m_no * OFF;
- if (op->equal(j, val[j]) == -1) {
- ndbout << op->getNdbError() << endl;
- fatal("equal");
- }
- if (con->execute(Commit) == -1) {
- ndbout << con->getNdbError() << endl;
- fatal("execute");
- }
- ndb->closeTransaction(con);
- }
- test.timerCnt(opt.m_scale);
- delete ndb;
-#endif
- } else {
- SQLHANDLE hEnv, hDbc, hStmt;
- allocAll(test, hEnv, hDbc, hStmt);
- long val[1+N];
- char sql[MAX_SQL], *sqlptr;
- // insert
- tab.insertAll(sqlptr = sql);
- test.run(HStmt(hStmt), SQLPrepare(hStmt, (SQLCHAR*)sql, SQL_NTS));
- for (unsigned j = 0; j <= N; j++) {
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 1 + j, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &val[j], 0, 0));
- }
- test.m_perf = true;
- for (unsigned k = 1; k <= opt.m_scale; k++) {
- for (unsigned j = 0; j <= N; j++) {
- val[j] = (j == 0 ? k + test.m_no * OFF : k * j);
- }
- test.run(HStmt(hStmt), SQLExecute(hStmt));
- }
- test.m_perf = false;
- test.timerCnt(opt.m_scale);
- // select PK
- tab.selectPk(sqlptr = sql);
- test.run(HStmt(hStmt), SQLPrepare(hStmt, (SQLCHAR*)sql, SQL_NTS));
- for (unsigned j = 0; j <= N; j++) {
- test.run(HStmt(hStmt), SQLBindCol(hStmt, 1 + j, SQL_C_SLONG, &val[j], 0, 0));
- }
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 1 + N + 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &val[0], 0, 0));
- test.m_perf = true;
- for (unsigned k = 1; k <= opt.m_scale; k++) {
- val[0] = k + test.m_no * OFF;
- test.run(HStmt(hStmt), SQLExecute(hStmt));
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- for (unsigned j = 1; j <= N; j++) {
- assert(val[j] == k * j);
- }
- test.run(HStmt(hStmt), SQLCloseCursor(hStmt));
- }
- test.m_perf = false;
- test.timerCnt(opt.m_scale);
- // delete PK
- tab.deletePk(sqlptr = sql);
- test.run(HStmt(hStmt), SQLPrepare(hStmt, (SQLCHAR*)sql, SQL_NTS));
- unsigned j = 0;
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 1 + j, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &val[j], 0, 0));
- test.m_perf = true;
- for (unsigned k = 1; k <= opt.m_scale; k++) {
- val[j] = k + test.m_no * OFF;
- test.run(HStmt(hStmt), SQLExecute(hStmt));
- }
- test.m_perf = false;
- test.timerCnt(opt.m_scale);
- freeAll(test, hEnv, hDbc, hStmt);
- }
- out:
- ;
- }
-}
-
-struct Sql {
- const char* m_sql;
- int m_functionCode;
- int m_rowCount;
- int m_tuplesFetched;
- long m_lastValue;
- unsigned long m_bindValue;
- int m_ret;
- const char* m_state;
- SQLINTEGER m_native;
- bool m_reset;
- // run this function instead
- typedef void (*TestFunc)(Test& test);
- TestFunc m_testFunc;
- Sql() :
- m_sql(0) {
- }
- Sql(const char* do_cmd) :
- m_sql(do_cmd) {
- }
- Sql(const char* sql, int functionCode, int rowCount, int tuplesFetched, long lastValue, long bindValue) :
- m_sql(sql),
- m_functionCode(functionCode),
- m_rowCount(rowCount),
- m_tuplesFetched(tuplesFetched),
- m_lastValue(lastValue),
- m_bindValue(bindValue),
- m_ret(SQL_SUCCESS),
- m_state(0),
- m_native(0),
- m_reset(true),
- m_testFunc(0) {
- }
- // the 4 numbers after SQL_DIAG... rowCount tuplesFetched lastValue bindValue
- Sql(const char* sql, int functionCode, int rowCount, int tuplesFetched, long lastValue, long bindValue, int ret, const char* state, SQLINTEGER native, bool reset) :
- m_sql(sql),
- m_functionCode(functionCode),
- m_rowCount(rowCount),
- m_tuplesFetched(tuplesFetched),
- m_lastValue(lastValue),
- m_bindValue(bindValue),
- m_ret(ret),
- m_state(state),
- m_native(native),
- m_reset(reset),
- m_testFunc(0) {
- }
- Sql(const char* text, TestFunc testFunc) :
- m_sql(text),
- m_testFunc(testFunc) {
- }
- static const char* set_autocommit_on() {
- return "set autocommit on";
- }
- static const char* set_autocommit_off() {
- return "set autocommit off";
- }
- static const char* do_commit() {
- return "commit";
- }
- static const char* do_rollback() {
- return "rollback";
- }
-};
-
-// 90
-
-static const Sql
-miscSql90[] = {
- Sql("select * from dual",
- SQL_DIAG_SELECT_CURSOR, 1, 0, -1, -1),
- Sql("drop table tt90a",
- SQL_DIAG_DROP_TABLE, -1, 0, -1, -1,
- SQL_ERROR, "IM000", 2040709, false),
- Sql("create table tt90a (a int, b int, c int, primary key(b, c)) storage(large) logging",
- SQL_DIAG_CREATE_TABLE, -1, 0, -1, -1),
- Sql()
-};
-
-// 91
-
-static const Sql
-miscSql91[] = {
- Sql("drop table tt91a",
- SQL_DIAG_DROP_TABLE, -1, 0, -1, -1,
- SQL_ERROR, "IM000", 2040709, false),
- Sql("create table tt91a (a bigint unsigned primary key, b bigint unsigned not null, c varchar(10))",
- SQL_DIAG_CREATE_TABLE, -1, 0, -1, -1),
- Sql("insert into tt91a values (1, 111, 'aaa')",
- SQL_DIAG_INSERT, 1, 0, -1, -1),
- // fails
- Sql("insert into tt91a values (2, null, 'ccc')",
- SQL_DIAG_INSERT, -1, 0, -1, -1,
- SQL_ERROR, "IM000", 2014203, true),
- Sql("update tt91a set b = 222 where a = 2",
- SQL_DIAG_UPDATE_WHERE, 0, 0, -1, -1,
- SQL_NO_DATA, 0, 0, true),
- // two more
- Sql("insert into tt91a values (2, 222, 'ccc')",
- SQL_DIAG_INSERT, 1, 0, -1, -1),
- Sql("insert into tt91a values (3, 333, 'bbb')",
- SQL_DIAG_INSERT, 1, 0, -1, -1),
- // direct update
- Sql("update tt91a set b = 112 where a = 1",
- SQL_DIAG_UPDATE_WHERE, 1, 0, -1, -1),
- Sql("update tt91a set b = 113 where a = 1 and b > 111",
- SQL_DIAG_UPDATE_WHERE, 1, 1, -1, -1),
- // update and delete with interpreted scan
- Sql("update tt91a set b = 114 where b < 114",
- SQL_DIAG_UPDATE_WHERE, 1, 1, -1, -1),
- Sql("delete from tt91a where b < 115",
- SQL_DIAG_DELETE_WHERE, 1, 1, -1, -1),
- Sql("insert into tt91a values (1, 111, 'aaa')",
- SQL_DIAG_INSERT, 1, 0, -1, -1),
- // check rows: 1,111,aaa + 2,222,ccc + 3,333,bbb
- Sql("select * from tt91a order by c",
- SQL_DIAG_SELECT_CURSOR, 3, 3, 2, -1),
- Sql("select * from tt91a order by c desc",
- SQL_DIAG_SELECT_CURSOR, 3, 3, 1, -1),
- Sql("select * from tt91a where a = 2",
- SQL_DIAG_SELECT_CURSOR, 1, 1, -1, -1),
- Sql("select * from tt91a where a + b = 224",
- SQL_DIAG_SELECT_CURSOR, 1, 3, -1, -1),
- Sql("select * from tt91a where a = 4",
- SQL_DIAG_SELECT_CURSOR, 0, 0, -1, -1),
- Sql("select b-a from tt91a order by a-b",
- SQL_DIAG_SELECT_CURSOR, 3, 3, 110, -1),
- Sql("select sum(a+b) from tt91a",
- SQL_DIAG_SELECT_CURSOR, 1, 3, 672, -1),
- Sql("select x.b, y.b, z.b from tt91a x, tt91a y, tt91a z where x.b <= y.b and y.b < z.b order by x.b",
- SQL_DIAG_SELECT_CURSOR, 4, 13, 222, -1),
- Sql("select x.b, y.b, z.b from tt91a x, tt91a y, tt91a z where x.b + y.b = z.b order by x.b",
- SQL_DIAG_SELECT_CURSOR, 3, 15, 222, -1),
- // tmp index
- Sql("create unique hash index xx91a on tt91a(b)",
- SQL_DIAG_CREATE_INDEX, -1, -1, -1, -1),
- Sql("select x.b, y.b, z.b from tt91a x, tt91a y, tt91a z where x.b + y.b = z.b order by x.b",
- SQL_DIAG_SELECT_CURSOR, 3, 15, 222, -1),
- Sql("drop index xx91a on tt91a",
- SQL_DIAG_DROP_INDEX, -1, -1, -1, -1),
- // add some duplicates
- Sql("insert into tt91a values (4, 222, 'ccc')",
- SQL_DIAG_INSERT, 1, -1, -1, -1),
- Sql("insert into tt91a values (5, 333, 'bbb')",
- SQL_DIAG_INSERT, 1, -1, -1, -1),
- Sql("insert into tt91a values (6, 333, 'bbb')",
- SQL_DIAG_INSERT, 1, -1, -1, -1),
- // check rows: 1,111,aaa + 2 * 2,222,ccc + 3 * 3,333,bbb
- Sql("select count(*) from tt91a",
- SQL_DIAG_SELECT_CURSOR, 1, -1, 6, -1),
- Sql("select a+b from tt91a where (b = 111 or b = 222 ) and (b = 222 or b = 333) and a > 1 and a < 3",
- SQL_DIAG_SELECT_CURSOR, 1, -1, 224, -1),
- Sql("select sum(a) from tt91a having min(a) = 1 and max(a) = 6",
- SQL_DIAG_SELECT_CURSOR, 1, -1, 21, -1),
- Sql("select sum(a) from tt91a where a = 2 or a = 4 having min(a) = 2 and max(a) = 4",
- SQL_DIAG_SELECT_CURSOR, 1, -1, 6, -1),
- Sql("select sum(a) from tt91a having min(a) = 1 and max(a) = 5",
- SQL_DIAG_SELECT_CURSOR, 0, -1, -1, -1),
- Sql("select sum(a), b from tt91a group by b order by b",
- SQL_DIAG_SELECT_CURSOR, 3, -1, 14, -1),
- Sql("select sum(a), b, c from tt91a group by b, c order by c",
- SQL_DIAG_SELECT_CURSOR, 3, -1, 6, -1),
- Sql("select b, sum(a) from tt91a group by b having b = 37 * sum(a)",
- SQL_DIAG_SELECT_CURSOR, 1, -1, 222, -1),
- // simple varchar vs interpreter test
- Sql("select count(*) from tt91a where c = 'ccc'",
- SQL_DIAG_SELECT_CURSOR, 1, 2, 2, -1),
- Sql("select count(*) from tt91a where c like '%b%'",
- SQL_DIAG_SELECT_CURSOR, 1, 3, 3, -1),
- // interpreter limits (crashes in api on v211)
-#if NDB_VERSION_MAJOR >= 3
- Sql("select count(*) from tt91a where a in (99,98,97,96,95,94,93,92,91,90,89,88,87,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,99,98,97,96,95,94,93,92,91,90,89,88,87,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,99,98,97,96,95,94,93,92,91,90,89,88,87,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,99,98,97,96,95,94,93,92,91,90,89,88,87,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,99,98,97,96,95,94,93,92,91,90,89,88,87,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,99,98,97,96,95,94,93,92,91,90,89,88,87,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2)",
- SQL_DIAG_SELECT_CURSOR, 1, 5, 5, -1),
- Sql("select count(*) from tt91a where c in ('xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','bbb','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy','zzzzz','xxxxx','yyyyy')",
- SQL_DIAG_SELECT_CURSOR, 1, 3, 3, -1),
-#endif
- // distinct
- Sql("select distinct b from tt91a order by b",
- SQL_DIAG_SELECT_CURSOR, 3, -1, 333, -1),
- // some illegal groupings
- Sql("select a from tt91a group by b",
- -1, -1, -1, -1, -1,
- SQL_ERROR, "IM000", -1, -1),
- Sql("select sum(a) from tt91a group by b having a = 2",
- -1, -1, -1, -1, -1,
- SQL_ERROR, "IM000", -1, -1),
- Sql("select sum(a) from tt91a group by b order by a",
- -1, -1, -1, -1, -1,
- SQL_ERROR, "IM000", -1, -1),
- // string functions
- Sql("insert into tt91a (c, b, a) values ('abcdef', 999, 9)",
- SQL_DIAG_INSERT, 1, -1, -1, -1),
- Sql("select count(*) from tt91a where left(c, 2) = 'ab' and substr(c, 3, 2) = 'cd' and right(c, 2) = 'ef'",
- SQL_DIAG_SELECT_CURSOR, 1, -1, 1, -1),
- // nulls
- Sql("update tt91a set c = null where a > 8",
- SQL_DIAG_UPDATE_WHERE, 1, -1, -1, -1),
- Sql("select a from tt91a where c is null and b is not null order by a",
- SQL_DIAG_SELECT_CURSOR, 1, -1, 9, -1),
- Sql("select a from tt91a where not (c is not null or b is null) order by a",
- SQL_DIAG_SELECT_CURSOR, 1, -1, 9, -1),
- // null value guard in interpreter
- Sql("select count(*) from tt91a where c < 'x' or c > 'x' or c != 'x' or c = 'x'",
- SQL_DIAG_SELECT_CURSOR, 1, 6, 6, -1),
- Sql("delete from tt91a where c is null",
- SQL_DIAG_DELETE_WHERE, 1, -1, -1, -1),
- // indexes
- Sql("update tt91a set b = a + 5",
- SQL_DIAG_UPDATE_WHERE, 6, 6, -1, -1),
- Sql("create unique hash index xx91a on tt91a(b)",
- SQL_DIAG_CREATE_INDEX, -1, -1, -1, -1),
- // scan y primary key x
- Sql("select x.b from tt91a x, tt91a y where x.a = y.b + 0",
- SQL_DIAG_SELECT_CURSOR, 1, 7, 11, -1),
- // scan x index y
- Sql("select x.b from tt91a x, tt91a y where x.a + 0 = y.b",
- SQL_DIAG_SELECT_CURSOR, 1, -1, 11, -1),
- // scan x scan y
- Sql("select x.b from tt91a x, tt91a y where x.a + 0 = y.b + 0",
- SQL_DIAG_SELECT_CURSOR, 1, -1, 11, -1),
- // dml ops
- Sql("delete from tt91a where b = 11 and a > 999",
- SQL_DIAG_DELETE_WHERE, 0, 1, -1, -1,
- SQL_NO_DATA, 0, 0, true),
- Sql("delete from tt91a where b = 11",
- SQL_DIAG_DELETE_WHERE, 1, 0, -1, -1),
- Sql("delete from tt91a where b = 11",
- SQL_DIAG_DELETE_WHERE, 0, 0, -1, -1,
- SQL_NO_DATA, 0, 0, true),
- Sql("update tt91a set b = 10*10 where b = 10",
- SQL_DIAG_UPDATE_WHERE, 1, 0, -1, -1),
- Sql("update tt91a set b = 10 where b = 10*10",
- SQL_DIAG_UPDATE_WHERE, 1, 0, -1, -1),
- Sql("update tt91a set b = 10*10 where b = 10 and b >= 10",
- SQL_DIAG_UPDATE_WHERE, 1, 1, -1, -1),
- Sql("update tt91a set b = 10 where b = 10*10 and b >= 10*10",
- SQL_DIAG_UPDATE_WHERE, 1, 1, -1, -1),
- // char vs varchar
- Sql("drop table tt91b",
- SQL_DIAG_DROP_TABLE, -1, -1, -1, -1,
- SQL_ERROR, "IM000", 2040709, false),
- Sql("create table tt91b (a int primary key, b char(5), c varchar(5))",
- SQL_DIAG_CREATE_TABLE, -1, -1, -1, -1),
- Sql("insert into tt91b values (1, 'abc', 'abc')",
- SQL_DIAG_INSERT, 1, -1, -1, -1),
- Sql("insert into tt91b values (2, 'xyz', 'xyz')",
- SQL_DIAG_INSERT, 1, -1, -1, -1),
- Sql("insert into tt91b values (3, 'xyz', 'xyz ')",
- SQL_DIAG_INSERT, 1, -1, -1, -1),
- // char = char strips blanks
- Sql("select count(*) from tt91b x where (x.b = 'abc') or x.a = x.a+1",
- SQL_DIAG_SELECT_CURSOR, 1, 3, 1, -1),
- Sql("select count(*) from tt91b x where (x.b = 'abc')",
- SQL_DIAG_SELECT_CURSOR, 1, 1, 1, -1),
- Sql("select count(*) from tt91b x where (x.b = 'abc ') or x.a = x.a+1",
- SQL_DIAG_SELECT_CURSOR, 1, 3, 1, -1),
- Sql("select count(*) from tt91b x where (x.b = 'abc ')",
- SQL_DIAG_SELECT_CURSOR, 1, 1, 1, -1),
- // varchar = char
- Sql("select count(*) from tt91b x where (x.c = 'abc') or x.a = x.a+1",
- SQL_DIAG_SELECT_CURSOR, 1, 3, 1, -1),
- Sql("select count(*) from tt91b x where (x.c = 'abc')",
- SQL_DIAG_SELECT_CURSOR, 1, 1, 1, -1),
- Sql("select count(*) from tt91b x where (x.c = 'abc ') or x.a = x.a+1",
- SQL_DIAG_SELECT_CURSOR, 1, 3, 0, -1),
- Sql("select count(*) from tt91b x where (x.c = 'abc ')",
- SQL_DIAG_SELECT_CURSOR, 1, 0, 0, -1),
- // char = varchar
- Sql("select count(*) from tt91b x, tt91b y where (x.b = y.c) or x.a = x.a+1 or y.a = y.a+1",
- SQL_DIAG_SELECT_CURSOR, 1, -1, 2, -1),
- Sql("select count(*) from tt91b x, tt91b y where (x.b = y.c)",
- SQL_DIAG_SELECT_CURSOR, 1, -1, 2, -1),
- // varchar = varchar
- Sql("select count(*) from tt91b x, tt91b y where (x.c = y.c) or x.a = x.a+1 or y.a = y.a+1",
- SQL_DIAG_SELECT_CURSOR, 1, -1, 3, -1),
- Sql("select count(*) from tt91b x, tt91b y where (x.c = y.c)",
- SQL_DIAG_SELECT_CURSOR, 1, -1, 3, -1),
- // less
- Sql("select 10 * x.a + y.a from tt91b x, tt91b y where (x.b < y.b) or x.a = x.a+1 or y.a = y.a+1 order by x.a, y.a",
- SQL_DIAG_SELECT_CURSOR, 2, -1, 13, -1),
- Sql("select 10 * x.a + y.a from tt91b x, tt91b y where (x.b < y.b) order by x.a, y.a",
- SQL_DIAG_SELECT_CURSOR, 2, -1, 13, -1),
- Sql("select 10 * x.a + y.a from tt91b x, tt91b y where (x.c < y.c) or x.a = x.a+1 or y.a = y.a+1 order by x.a, y.a",
- SQL_DIAG_SELECT_CURSOR, 3, -1, 23, -1),
- Sql("select 10 * x.a + y.a from tt91b x, tt91b y where (x.c < y.c) order by x.a, y.a",
- SQL_DIAG_SELECT_CURSOR, 3, -1, 23, -1),
- // like
- Sql("select count(*) from tt91b x where (x.b like 'a%') or x.a = x.a+1",
- SQL_DIAG_SELECT_CURSOR, 1, 3, 1, -1),
- Sql("select count(*) from tt91b x where (x.b like 'a%')",
- SQL_DIAG_SELECT_CURSOR, 1, 1, 1, -1),
- Sql("select count(*) from tt91b x where (x.b like 'x%z') or x.a = x.a+1",
- SQL_DIAG_SELECT_CURSOR, 1, 3, 0, -1),
- Sql("select count(*) from tt91b x where (x.b like 'x%z')",
- SQL_DIAG_SELECT_CURSOR, 1, 0, 0, -1),
- Sql("select count(*) from tt91b x where (x.a+0 = 2 and x.c like 'x%z') or x.a = x.a+1",
- SQL_DIAG_SELECT_CURSOR, 1, 3, 1, -1),
- Sql("select count(*) from tt91b x where (x.a+0 = 2 and x.c like 'x%z')",
- SQL_DIAG_SELECT_CURSOR, 1, 1, 1, -1),
- Sql("select count(*) from tt91b x where (x.a+0 = 3 and x.c like 'x%z ') or x.a = x.a+1",
- SQL_DIAG_SELECT_CURSOR, 1, 3, 1, -1),
- Sql("select count(*) from tt91b x where (x.a+0 = 3 and x.c like 'x%z ')",
- SQL_DIAG_SELECT_CURSOR, 1, 1, 1, -1),
- Sql()
-};
-
-// 92
-
-static void
-testMisc92a(Test& test)
-{
- SQLHANDLE hEnv, hDbc, hStmt;
- allocAll(test, hEnv, hDbc, hStmt);
- char sql[MAX_SQL];
- char tname[20];
- sprintf(tname, "tt92%c", 0140 + test.m_no);
- if (test.m_loop == 1) {
- lock_mutex();
- sprintf(sql, "drop table %s", tname);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.exp(SQL_ERROR, "IM000", 2040709, false);
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- sprintf(sql, "create table %s (a int unsigned primary key, b int unsigned not null)", tname);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- unlock_mutex();
- } else {
- sprintf(sql, "delete from %s", tname);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.exp(SQL_NO_DATA, 0, 0, false);
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- test.run(HStmt(hStmt), SQLEndTran(SQL_HANDLE_DBC, hDbc, SQL_COMMIT));
- }
- for (int on = true; on >= false; on--) {
- if (opt.m_v >= 2)
- ndbout << "set autocommit " << (on ? "ON" : "OFF") << endl;
- setAutocommit(test, hDbc, on);
- // insert rows
- if (opt.m_v >= 2)
- ndbout << "SQL: insert into " << tname << " ..." << opt.m_scale << endl;
- for (unsigned k = 0; k < opt.m_scale; k++) {
- sprintf(sql, "insert into %s values (%u, %u)", tname, k, 10 * k);
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- }
- // commit always
- test.run(HStmt(hStmt), SQLEndTran(SQL_HANDLE_DBC, hDbc, SQL_COMMIT));
- // scan delete
- sprintf(sql, "delete from %s", tname);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- // rollback or commit
- test.run(HStmt(hStmt), SQLEndTran(SQL_HANDLE_DBC, hDbc, on ? SQL_COMMIT : SQL_ROLLBACK));
- // count
- long count = -1;
- sprintf(sql, "select count(*) from %s", tname);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- selectCount(test, hStmt, sql, &count);
- test.chk(HStmt(hStmt), count == on ? 0 : opt.m_scale, "%s: got %d != %d", tname, (int)count, (int)opt.m_scale);
- }
- freeAll(test, hEnv, hDbc, hStmt);
-}
-
-static const Sql
-miscSql92[] = {
- // create in C func
- Sql("testMisc92a", testMisc92a),
- Sql()
-};
-
-// 93
-
-static void
-testMisc93a(Test& test)
-{
- SQLHANDLE hEnv[2], hDbc[2], hStmt[2];
- allocAll(test, hEnv[0], hDbc[0], hStmt[0]);
- allocAll(test, hEnv[1], hDbc[1], hStmt[1]);
- char sql[MAX_SQL];
- // select via primary key
- setAutocommit(test, hDbc[0], false);
- sprintf(sql, "select c1 from tt93a where c0 = 1");
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt[0]), SQLExecDirect(hStmt[0], (SQLCHAR*)sql, SQL_NTS));
- // update via another trans must time out
- sprintf(sql, "update tt93a set c1 = 'b' where c0 = 1");
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt[1]), SQLExecDirect(hStmt[1], (SQLCHAR*)sql, SQL_NTS));
- freeAll(test, hEnv[0], hDbc[0], hStmt[0]);
- freeAll(test, hEnv[1], hDbc[1], hStmt[1]);
-}
-
-static const Sql
-miscSql93[] = {
- // create in C func
- Sql("drop table tt93a",
- SQL_DIAG_DROP_TABLE, -1, 0, -1, -1,
- SQL_ERROR, "IM000", 2040709, false),
- Sql("create table tt93a (c0 int primary key, c1 char(10))",
- SQL_DIAG_CREATE_TABLE, -1, 0, -1, -1),
- Sql("insert into tt93a values(1, 'a')",
- SQL_DIAG_INSERT, 1, 0, -1, -1),
- Sql("testMisc93a", testMisc93a),
- Sql()
-};
-
-// 95
-
-static const Sql
-miscSql95[] = {
- Sql("drop table tt95a",
- SQL_DIAG_DROP_TABLE, -1, 0, -1, -1,
- SQL_ERROR, "IM000", 2040709, false),
- Sql("create table tt95a (a int not null, b char(10) not null, c int not null, d char(10), primary key(a, b)) storage(small)",
- SQL_DIAG_CREATE_TABLE, -1, 0, -1, -1),
- // ordered index create and drop
- Sql("create index xx95a on tt95a (c, d) nologging",
- SQL_DIAG_CREATE_INDEX, -1, -1, -1, -1),
- Sql("drop index xx95a on tt95a",
- SQL_DIAG_DROP_INDEX, -1, -1, -1, -1),
- Sql("create index xx95a on tt95a (c) nologging",
- SQL_DIAG_CREATE_INDEX, -1, -1, -1, -1),
- Sql("insert into tt95a values(1, 'a', 10, 'b')",
- SQL_DIAG_INSERT, 1, -1, -1, -1),
- Sql("insert into tt95a values(2, 'a', 20, 'b')",
- SQL_DIAG_INSERT, 1, -1, -1, -1),
- Sql("insert into tt95a values(3, 'a', 30, 'b')",
- SQL_DIAG_INSERT, 1, -1, -1, -1),
- Sql("select a from tt95a where c = 20",
- SQL_DIAG_SELECT_CURSOR, 1, 1, 2, -1),
- Sql("delete from tt95a where c = 10",
- SQL_DIAG_DELETE_WHERE, 1, 1, -1, -1),
- Sql("update tt95a set c = 300 where c = 30",
- SQL_DIAG_UPDATE_WHERE, 1, 1, -1, -1),
- Sql("delete from tt95a where c = 300",
- SQL_DIAG_DELETE_WHERE, 1, 1, -1, -1),
- Sql("delete from tt95a",
- SQL_DIAG_DELETE_WHERE, 1, 1, -1, -1),
- // simple insert and rollback
- Sql("-- simple insert and rollback"),
- Sql(Sql::set_autocommit_off()),
- Sql("insert into tt95a values(1, 'a', 10, 'b')",
- SQL_DIAG_INSERT, 1, -1, -1, -1),
- Sql("select count(*) from tt95a",
- SQL_DIAG_SELECT_CURSOR, 1, 1, 1, -1),
- Sql("select count(*) from tt95a where c = 10",
- SQL_DIAG_SELECT_CURSOR, 1, 1, 1, -1),
- Sql(Sql::do_rollback()),
- Sql(Sql::set_autocommit_on()),
- Sql("select count(*) from tt95a",
- SQL_DIAG_SELECT_CURSOR, 1, 0, 0, -1),
- // simple update and rollback
- Sql("-- simple update and rollback"),
- Sql("insert into tt95a values(1, 'a', 10, 'b')",
- SQL_DIAG_INSERT, 1, -1, -1, -1),
- Sql(Sql::set_autocommit_off()),
- Sql("update tt95a set c = 20 where c = 10",
- SQL_DIAG_UPDATE_WHERE, 1, 1, -1, -1),
- Sql("select count(*) from tt95a",
- SQL_DIAG_SELECT_CURSOR, 1, 1, 1, -1),
- Sql("select count(*) from tt95a where c = 20",
- SQL_DIAG_SELECT_CURSOR, 1, 1, 1, -1),
- Sql(Sql::do_rollback()),
- Sql(Sql::set_autocommit_on()),
- Sql("select count(*) from tt95a where c = 10",
- SQL_DIAG_SELECT_CURSOR, 1, 1, 1, -1),
- // simple delete and rollback
- Sql("-- simple delete and rollback"),
- Sql(Sql::set_autocommit_off()),
- Sql("delete from tt95a where c = 10",
- SQL_DIAG_DELETE_WHERE, 1, 1, -1, -1),
- Sql("select count(*) from tt95a",
- SQL_DIAG_SELECT_CURSOR, 0, 0, 0, -1),
- Sql("select count(*) from tt95a where c = 10",
- SQL_DIAG_SELECT_CURSOR, 0, 0, 0, -1),
- Sql(Sql::do_rollback()),
- Sql(Sql::set_autocommit_on()),
- Sql("select count(*) from tt95a where c = 10",
- SQL_DIAG_SELECT_CURSOR, 1, 1, 1, -1),
- // multiple update
- Sql("-- multiple update and rollback"),
- Sql(Sql::set_autocommit_off()),
- Sql("update tt95a set c = 20 where c = 10",
- SQL_DIAG_UPDATE_WHERE, 1, 1, -1, -1),
- Sql("select count(*) from tt95a where c = 20",
- SQL_DIAG_SELECT_CURSOR, 1, 1, 1, -1),
- Sql("update tt95a set c = 30 where c = 20",
- SQL_DIAG_UPDATE_WHERE, 1, 1, -1, -1),
- Sql("select count(*) from tt95a where c = 30",
- SQL_DIAG_SELECT_CURSOR, 1, 1, 1, -1),
- Sql("update tt95a set c = 40 where c = 30",
- SQL_DIAG_UPDATE_WHERE, 1, 1, -1, -1),
- Sql("select count(*) from tt95a where c = 40",
- SQL_DIAG_SELECT_CURSOR, 1, 1, 1, -1),
- Sql("update tt95a set c = 50 where c = 40",
- SQL_DIAG_UPDATE_WHERE, 1, 1, -1, -1),
- Sql("select count(*) from tt95a where c = 50",
- SQL_DIAG_SELECT_CURSOR, 1, 1, 1, -1),
- Sql(Sql::do_rollback()),
- Sql(Sql::set_autocommit_on()),
- Sql("select count(*) from tt95a where c = 10",
- SQL_DIAG_SELECT_CURSOR, 1, 1, 1, -1),
- // another variant which found no tuple via index (aligment issue)
- Sql("drop table tt95b",
- SQL_DIAG_DROP_TABLE, -1, 0, -1, -1,
- SQL_ERROR, "IM000", 2040709, false),
- Sql("create table tt95b (a int primary key, b char(10) not null, c int not null)",
- SQL_DIAG_CREATE_TABLE, -1, 0, -1, -1),
- Sql("create index xx95b on tt95b (b, c) nologging",
- SQL_DIAG_CREATE_INDEX, -1, -1, -1, -1),
- Sql("insert into tt95b values(0,'0123456789',1)",
- SQL_DIAG_INSERT, 1, -1, -1, -1),
- Sql("select a from tt95b where b='0123456789'",
- SQL_DIAG_SELECT_CURSOR, 1, 1, 0, -1),
- // update index key to different value
- Sql("update tt95b set b = '9876543210' where b = '0123456789'",
- SQL_DIAG_UPDATE_WHERE, 1, 1, -1, -1),
- // same value goes nuts...
- Sql("update tt95b set b = '9876543210'",
- SQL_DIAG_UPDATE_WHERE, 1, 1, -1, -1),
-#if 0
- // ...if done via index key (variant of halloween problem)
- Sql("update tt95b set b = '9876543210' where b = '9876543210'",
- SQL_DIAG_UPDATE_WHERE, 1, 1, -1, -1),
-#endif
- Sql()
-};
-
-// 96
-
-static void
-testMisc96a(Test& test)
-{
- // single thread
- if (test.m_no != 1)
- return;
- SQLHANDLE hEnv, hDbc, hStmt;
- allocAll(test, hEnv, hDbc, hStmt);
- char sql[MAX_SQL], *sqlptr;
- char tname[20];
- strcpy(tname, "tt96a");
- // drop table
- scopy(sqlptr = sql, "drop table %s", tname);
- test.exp(SQL_ERROR, "IM000", 2040709, false);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- // create table with many attributes
- unsigned attrs = 1 + opt.m_scale;
- if (attrs > MAX_ATTRIBUTES_IN_TABLE)
- attrs = MAX_ATTRIBUTES_IN_TABLE;
- if (attrs > 64)
- attrs = 64;
- scopy(sqlptr = sql, "create table %s (c0 int primary key", tname);
- for (unsigned j = 1; j < attrs; j++) {
- if (j % 2 == 0)
- scopy(sqlptr, ", c%d int unsigned not null", j);
- else
- scopy(sqlptr, ", c%d char(10) not null", j);
- }
- scopy(sqlptr, ")");
- if (opt.m_fragtype != 0)
- scopy(sqlptr, " storage(%s)", opt.m_fragtype);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- // create or drop indexes
- const unsigned seed = 1000037 * test.m_loop + 1000039 * opt.m_scale;
- srandom(seed);
- const unsigned imax = opt.m_scale < 20 ? opt.m_scale : 20;
- AttributeMask* imasks = new AttributeMask[imax];
- unsigned ccnt = 0;
- unsigned dcnt = 0;
- for (unsigned n = 0; n < imax; n++)
- imasks[n].clear();
- while (ccnt + dcnt < opt.m_scale) {
- char iname[20];
- unsigned n = urandom(imax);
- sprintf(iname, "xx96a%02d", n);
- AttributeMask& imask = imasks[n];
- unsigned sel = urandom(10);
- if (imask.isclear()) {
- // create one
- unsigned ncol = 0;
- unsigned cols[MAX_ATTRIBUTES_IN_INDEX];
- unsigned cnum = urandom(attrs);
- cols[ncol++] = cnum;
- while (ncol < MAX_ATTRIBUTES_IN_INDEX) {
- unsigned sel2 = urandom(10);
- if (sel2 < 2)
- break;
- unsigned cnum2 = urandom(attrs);
- if (sel2 < 9 && cnum2 == 0)
- continue;
- unsigned j;
- for (j = 0; j < ncol; j++) {
- if (cols[j] == cnum2)
- break;
- }
- if (j == ncol)
- cols[ncol++] = cnum2;
- }
- if (sel < 3) {
- scopy(sqlptr = sql, "create unique hash index %s on %s (", iname, tname);
- for (unsigned j = 0; j < ncol; j++)
- scopy(sqlptr, "%sc%d", j == 0 ? "" : ", ", cols[j]);
- scopy(sqlptr, ")");
- } else {
- scopy(sqlptr = sql, "create index %s on %s (", iname, tname);
- for (unsigned j = 0; j < ncol; j++)
- scopy(sqlptr, "%sc%d", j == 0 ? "" : ", ", cols[j]);
- scopy(sqlptr, ") nologging");
- }
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- for (unsigned j = 0; j < ncol; j++)
- imask.set(cols[j]);
- ccnt++;
- } else if (sel < 5 && ccnt > dcnt + 1) {
- scopy(sqlptr = sql, "drop index %s on %s", iname, tname);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- imask.clear();
- dcnt++;
- }
- }
- // insert unique data
- unsigned rows = opt.m_scale;
- unsigned* uval = new unsigned[rows];
- for (unsigned i = 0; i < rows; i++) {
- uval[i] = urandom(4);
- scopy(sqlptr = sql, "insert into %s values(", tname);
- for (unsigned j = 0; j < attrs; j++) {
- if (j != 0)
- scopy(sqlptr, ",");
- unsigned v = (i << 10) | (j << 2) | uval[i];
- if (j == 0)
- scopy(sqlptr, "%u", i);
- else if (j % 2 == 0)
- scopy(sqlptr, "%u", v);
- else
- scopy(sqlptr, "'%010u'", v);
- }
- scopy(sqlptr, ")");
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- }
- // update each row via random index
- for (unsigned i = 0; i < rows; i++) {
- unsigned uold = uval[i];
- uval[i] = 3 - uval[i];
- AttributeMask imask;
- do {
- unsigned j = urandom(imax);
- imask = imasks[j];
- } while (imask.isclear());
- scopy(sqlptr = sql, "update %s set", tname);
- for (unsigned j = 1; j < attrs; j++) {
- if (j != 1)
- scopy(sqlptr, ",");
- /*
- * Equality update is just barely doable before savepoints
- * provided we change value of keys in every index.
- */
- unsigned v = (i << 10) | (j << 2) | uval[i];
- if (j == 0)
- ;
- else if (j % 2 == 0)
- scopy(sqlptr, " c%d=%u", j, v);
- else
- scopy(sqlptr, " c%d='%010u'", j, v);
- }
- scopy(sqlptr, " where 1=1");
- while (! imask.isclear()) {
- unsigned j = urandom(attrs);
- if (imask.get(j)) {
- unsigned v = (i << 10) | (j << 2) | uold;
- scopy(sqlptr, " and c%d=", j);
- if (j == 0)
- scopy(sqlptr, "%u", i);
- else if (j % 2 == 0)
- scopy(sqlptr, "%u", v);
- else
- scopy(sqlptr, "'%010u'", v);
- imask.clear(j);
- }
- }
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- chkRowCount(test, hStmt, 1);
- }
- // delete all
- scopy(sqlptr = sql, "delete from %s", tname);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- //
- if (opt.m_v >= 2)
- ndbout << tname << ": creates " << ccnt << " drops " << dcnt << endl;
- delete [] imasks;
- delete [] uval;
- freeAll(test, hEnv, hDbc, hStmt);
-}
-
-static const Sql
-miscSql96[] = {
- Sql("testMisc96a", testMisc96a),
- Sql()
-};
-
-// 97
-
-static void
-testMisc97a(Test& test)
-{
- SQLHANDLE hEnv, hDbc, hStmt;
- allocAll(test, hEnv, hDbc, hStmt);
- const char* tname = "TT97A";
- const char* iname = "XX97A";
- char sql[MAX_SQL];
- // create in some thread
- lock_mutex();
- if (my_sema == 0) {
- if (opt.m_v >= 1)
- ndbout << "thread " << test.m_no << " does setup" << endl;
- sprintf(sql, "drop table %s", tname);
- if (opt.m_v >= 2)
- ndbout << "SQL[" << test.m_no << "]: " << sql << endl;
- test.exp(SQL_ERROR, "IM000", 2040709, false);
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- // a-pk b-index c-counter
- sprintf(sql, "create table %s (a int primary key, b int, c int) storage(small)", tname);
- if (opt.m_v >= 2)
- ndbout << "SQL[" << test.m_no << "]: " << sql << endl;
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- for (unsigned i = 0; i < opt.m_scale; i++) {
- sprintf(sql, "insert into %s values (%d, %d, %d)", tname, i, 10 * i, 0);
- if (opt.m_v >= 3)
- ndbout << "SQL[" << test.m_no << "]: " << sql << endl;
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- }
- sprintf(sql, "create index %s on %s (b) nologging", iname, tname);
- if (opt.m_v >= 2)
- ndbout << "SQL[" << test.m_no << "]: " << sql << endl;
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- my_sema = 1;
- }
- unlock_mutex();
- assert(my_sema == 1);
- // parallel run - default rotating pk, ts, is
- // frob: low 3 hex digits give alt sequence e.g. 0x311 = pk, pk, is
- // frob: 4-th hex digit non-zero says use NDB API e.g. 0x1000
- unsigned typelist[3] = { 1, 2, 3 };
- for (unsigned i = 0; i < 3; i++) {
- unsigned t = (opt.m_frob >> (i * 4)) & 0xf;
- if (t != 0)
- typelist[i] = t;
- }
- unsigned type = typelist[(test.m_no - 1) % 3];
- if ((opt.m_frob & 0xf000) == 0) {
- for (unsigned i = 0; i < opt.m_scale; i++) {
- if (type == 1) {
- // pk update
- sprintf(sql, "update %s set c = c + 1 where a = %d", tname, i % opt.m_scale);
- if (opt.m_v >= 3)
- ndbout << lock << "SQL[" << test.m_no << "]: " << sql << endl << unlock;
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- }
- if (type == 2) {
- // table scan update
- sprintf(sql, "update %s set c = c + 1 where b + 0 = %d", tname, 10 * i);
- if (opt.m_v >= 3)
- ndbout << lock << "SQL[" << test.m_no << "]: " << sql << endl << unlock;
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- }
- if (type == 3) {
- // index scan update
- sprintf(sql, "update %s set c = c + 1 where b = %d", tname, 10 * i);
- if (opt.m_v >= 3)
- ndbout << lock << "SQL[" << test.m_no << "]: " << sql << endl << unlock;
- test.exp(SQL_NO_DATA, 0, 0, false);
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- }
- }
- } else {
-#ifdef ndbODBC
-#define CHK(o, x) do { if (! (x)) { fatal("line %d: %d %s", __LINE__, o->getNdbError().code, o->getNdbError().message); } } while (0)
- Ndb* ndb = new Ndb("TEST_DB");
- ndb->init();
- CHK(ndb, ndb->waitUntilReady() == 0);
- Int32 a, b, c;
- for (unsigned i = 0; i < opt.m_scale; i++) {
- if (type == 1) {
- // pk update with exclusive read
- NdbConnection* con;
- NdbOperation* op;
- CHK(ndb, (con = ndb->startTransaction()) != 0);
- a = i;
- c = -1;
- CHK(con, (op = con->getNdbOperation(tname)) != 0);
- CHK(op, op->readTupleExclusive() == 0);
- CHK(op, op->equal((unsigned)0, (char*)&a, 0) == 0);
- CHK(op, op->getValue(2, (char*)&c) != 0);
- CHK(con, con->execute(NoCommit) == 0);
- c = c + 1;
- CHK(con, (op = con->getNdbOperation(tname)) != 0);
- CHK(op, op->updateTuple() == 0);
- CHK(op, op->equal((unsigned)0, (char*)&a, 0) == 0);
- CHK(op, op->setValue(2, (char*)&c) == 0);
- CHK(con, con->execute(Commit) == 0);
- ndb->closeTransaction(con);
- if (opt.m_v >= 3)
- ndbout << lock << "thr " << test.m_no << " pk a=" << i << " c=" << c << endl << unlock;
- }
- if (type == 2) {
- // table scan update
- NdbConnection* con;
- NdbOperation* op;
- CHK(ndb, (con = ndb->startTransaction()) != 0);
- CHK(con, (op = con->getNdbOperation(tname)) != 0);
- CHK(con, op->openScanExclusive(240) == 0);
- CHK(op, op->getValue((unsigned)0, (char*)&a) != 0);
- CHK(op, op->getValue(2, (char*)&c) != 0);
- CHK(con, con->executeScan() == 0);
- unsigned rows = 0;
- unsigned updates = 0;
- while (1) {
- int ret;
- a = -1;
- c = -1;
- CHK(con, (ret = con->nextScanResult()) == 0 || ret == 1);
- if (ret == 1)
- break;
- rows++;
- if (a == i) {
- NdbConnection* con2;
- NdbOperation* op2;
- CHK(ndb, (con2 = ndb->startTransaction()) != 0);
- CHK(op, (op2 = op->takeOverForUpdate(con2)) != 0);
- c = c + 1;
- CHK(op2, op2->setValue(2, (char*)&c) == 0);
- CHK(con2, con2->execute(Commit) == 0);
- ndb->closeTransaction(con2);
- updates++;
- if (opt.m_v >= 3)
- ndbout << lock << "thr " << test.m_no << " ts rows=" << rows << " a=" << i << " c=" << c << endl << unlock;
- // test stop scan too
- CHK(con, con->stopScan() == 0);
- break;
- }
- }
- ndb->closeTransaction(con);
- test.chk(HStmt(hStmt), updates == 1, "got %u != 1", updates);
- }
- if (type == 3) {
- // index scan update
- NdbConnection* con;
- NdbOperation* op;
- CHK(ndb, (con = ndb->startTransaction()) != 0);
- CHK(con, (op = con->getNdbOperation(iname, tname)) != 0);
- CHK(con, op->openScanExclusive(240) == 0);
- b = 10 * i;
- CHK(con, op->setBound((unsigned)0, 4, &b, sizeof(b)) == 0);
- CHK(op, op->getValue((unsigned)0, (char*)&a) != 0);
- CHK(op, op->getValue(2, (char*)&c) != 0);
- CHK(con, con->executeScan() == 0);
- unsigned rows = 0;
- unsigned updates = 0;
- while (1) {
- int ret;
- a = -1;
- c = -1;
- CHK(con, (ret = con->nextScanResult()) == 0 || ret == 1);
- if (ret == 1)
- break;
- rows++;
- if (a == i) {
- NdbConnection* con2;
- NdbOperation* op2;
- CHK(ndb, (con2 = ndb->startTransaction()) != 0);
- CHK(op, (op2 = op->takeOverForUpdate(con2)) != 0);
- c = c + 1;
- CHK(op2, op2->setValue(2, (char*)&c) == 0);
- CHK(con2, con2->execute(Commit) == 0);
- ndb->closeTransaction(con2);
- updates++;
- if (opt.m_v >= 3)
- ndbout << lock << "thr " << test.m_no << " is rows=" << rows << " a=" << i << " c=" << c << endl << unlock;
- // test stop scan too
- CHK(con, con->stopScan() == 0);
- break;
- }
- }
- ndb->closeTransaction(con);
- test.chk(HStmt(hStmt), rows == 1, "got %u != 1", rows);
- test.chk(HStmt(hStmt), updates == 1, "got %u != 1", updates);
- }
- }
- delete ndb;
-#undef CHK
-#endif
- }
- // verify result
- lock_mutex();
- if (++my_sema == 1 + opt.m_threads) {
- if (opt.m_v >= 1)
- ndbout << "thread " << test.m_no << " does verification" << endl;
- sprintf(sql, "select * from %s order by a", tname);
- if (opt.m_v >= 2)
- ndbout << "SQL[" << test.m_no << "]: " << sql << endl;
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- long a, b, c;
- test.run(HStmt(hStmt), SQLBindCol(hStmt, 1, SQL_C_SLONG, &a, 0, 0));
- test.run(HStmt(hStmt), SQLBindCol(hStmt, 2, SQL_C_SLONG, &b, 0, 0));
- test.run(HStmt(hStmt), SQLBindCol(hStmt, 3, SQL_C_SLONG, &c, 0, 0));
- for (unsigned i = 0; i < opt.m_scale; i++) {
- a = b = c = -1;
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- test.chk(HStmt(hStmt), a == i, "a: got %ld != %u", a, i);
- test.chk(HStmt(hStmt), b == 10 * i, "b: got %ld != %u", b, 10 * i);
- test.chk(HStmt(hStmt), c == opt.m_threads, "c: got %ld != %u", c, opt.m_threads);
- if (opt.m_v >= 4)
- ndbout << "verified " << i << endl;
- }
- test.exp(SQL_NO_DATA, 0, 0, true);
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- if (opt.m_v >= 2)
- ndbout << "thr " << test.m_no << " verified " << opt.m_scale << " rows" << endl;
- my_sema = 0;
- }
- unlock_mutex();
- freeAll(test, hEnv, hDbc, hStmt);
-}
-
-static const Sql
-miscSql97[] = {
- Sql("testMisc97a", testMisc97a),
- Sql()
-};
-
-// 99
-
-static void
-testMisc99a(Test& test)
-{
- SQLHANDLE hEnv, hDbc, hStmt;
- allocAll(test, hEnv, hDbc, hStmt);
- // bad
- const char* sqlInsertBad = "insert into tt99a values(?, ?, ?, ?, ?)";
- test.exp(SQL_ERROR, "21S01", -1, true);
- test.run(HStmt(hStmt), SQLPrepare(hStmt, (SQLCHAR*)sqlInsertBad, SQL_NTS));
- // good
- const char* sqlInsert = "insert into tt99a (col1, col2, col3, col4, col5) values(?, ?, ?, ?, ?)";
- test.run(HStmt(hStmt), SQLPrepare(hStmt, (SQLCHAR*)sqlInsert, SQL_NTS));
- unsigned long value;
- for (unsigned i = 1; i <= 5; i++) {
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, i, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 0, 0, &value, 0, 0));
- }
- const unsigned long base = 1000000000;
- const unsigned long scale = 10;
- for (value = base; value < base + scale; value++) {
- test.run(HStmt(hStmt), SQLExecute(hStmt));
- }
- // bug1: re-analyze of converted expression...
- const char* sqlSelect = "select col5 from tt99a where col2 + 0 = ?";
- unsigned long output;
- test.run(HStmt(hStmt), SQLBindCol(hStmt, 1, SQL_C_ULONG, &output, 0, 0));
- test.run(HStmt(hStmt), SQLPrepare(hStmt, (SQLCHAR*)sqlSelect, SQL_NTS));
- // bug2: previous bind must survive a new SQLPrepare
- if (0) {
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 0, 0, &value, 0, 0));
- }
- for (value = base; value < base + scale; value++) {
- if (value > base + 4) {
- // bug1: ...when IPD changed by JDBC
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 0, 0, &value, 0, 0));
- }
- test.run(HStmt(hStmt), SQLExecute(hStmt));
- output = (unsigned long)-1;
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- test.chk(HStmt(hStmt), output == value, "got %lu != %lu", output, value);
- test.exp(SQL_NO_DATA, 0, 0, true);
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- test.run(HStmt(hStmt), SQLCloseCursor(hStmt));
- test.timerCnt(1);
- }
- freeAll(test, hEnv, hDbc, hStmt);
-}
-
-static void
-testMisc99c(Test& test)
-{
- SQLHANDLE hEnv, hDbc, hStmt;
- allocAll(test, hEnv, hDbc, hStmt);
- const char* sql = "select b from tt99c where a = ?";
- const unsigned long c1 = 2100000000U;
- const unsigned long c2 = 4100000000U;
- test.run(HStmt(hStmt), SQLPrepare(hStmt, (SQLCHAR*)sql, SQL_NTS));
- unsigned long aval, bval;
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 0, 0, &aval, 0, 0));
- test.run(HStmt(hStmt), SQLBindCol(hStmt, 1, SQL_C_ULONG, &bval, 0, 0));
- // uno
- for (unsigned i = 0; i < opt.m_scale; i++) {
- aval = c1;
- bval = (unsigned long)-1;
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << " [?=" << (Uint64)aval << "]" << endl;
- test.run(HStmt(hStmt), SQLExecute(hStmt));
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- test.chk(HStmt(hStmt), bval == c2, "got %lu != %lu", bval, c2);
- //test.exp(SQL_NO_DATA, 0, 0, true);
- //test.run(HStmt(hStmt), SQLFetch(hStmt));
- test.run(HStmt(hStmt), SQLCloseCursor(hStmt));
- }
- // dos
- for (unsigned i = 0; i < opt.m_scale; i++) {
- break; // XXX not yet, hangs in NDB ?!?
- aval = c2;
- bval = (unsigned long)-1;
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << " [?=" << (Uint64)aval << "]" << endl;
- test.run(HStmt(hStmt), SQLExecute(hStmt));
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- test.chk(HStmt(hStmt), bval == c1, "got %lu != %lu", bval, c2);
- //test.exp(SQL_NO_DATA, 0, 0, true);
- //test.run(HStmt(hStmt), SQLFetch(hStmt));
- test.run(HStmt(hStmt), SQLCloseCursor(hStmt));
- }
- freeAll(test, hEnv, hDbc, hStmt);
-}
-
-static void
-testMisc99d(Test& test)
-{
- SQLHANDLE hEnv, hDbc, hStmt;
- allocAll(test, hEnv, hDbc, hStmt);
- const char* tname = "TT99D";
- char sql[MAX_SQL];
- sprintf(sql, "drop table %s", tname);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.exp(SQL_ERROR, "IM000", 2040709, false);
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- sprintf(sql, "create table %s (a bigint unsigned, b bigint, primary key (a))", tname);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLExecDirect(hStmt, (SQLCHAR*)sql, SQL_NTS));
- sprintf(sql, "insert into %s values (?, ?)", tname);
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql << endl;
- test.run(HStmt(hStmt), SQLPrepare(hStmt, (SQLCHAR*)sql, SQL_NTS));
- // XXX replace by 100 when signed vs unsigned resolved
- const unsigned num = 78;
- SQLUBIGINT aval;
- SQLBIGINT bval;
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 1, SQL_PARAM_INPUT, SQL_C_UBIGINT, SQL_BIGINT, 0, 0, &aval, 0, 0));
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 2, SQL_PARAM_INPUT, SQL_C_SBIGINT, SQL_BIGINT, 0, 0, &bval, 0, 0));
- for (SQLBIGINT i = 0; i < num; i++) {
- if (opt.m_v >= 3)
- ndbout << "insert " << i << endl;
- aval = i * i * i * i * i * i * i * i * i * i; // 10
- bval = -aval;
- test.run(HStmt(hStmt), SQLExecute(hStmt));
- }
- sprintf(sql, "select a, b from tt99d where a = ?");
- test.run(HStmt(hStmt), SQLPrepare(hStmt, (SQLCHAR*)sql, SQL_NTS));
- SQLUBIGINT kval;
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 1, SQL_PARAM_INPUT, SQL_C_UBIGINT, SQL_BIGINT, 0, 0, &kval, 0, 0));
- test.run(HStmt(hStmt), SQLBindCol(hStmt, 1, SQL_C_UBIGINT, &aval, 0, 0));
- test.run(HStmt(hStmt), SQLBindCol(hStmt, 2, SQL_C_SBIGINT, &bval, 0, 0));
- for (SQLBIGINT i = 0; i < num; i++) {
- kval = i * i * i * i * i * i * i * i * i * i; // 10
- if (opt.m_v >= 3)
- ndbout << "fetch " << i << " key " << kval << endl;
- test.run(HStmt(hStmt), SQLExecute(hStmt));
- aval = bval = 0;
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- test.chk(HStmt(hStmt), aval == kval && bval == -kval, "got %llu, %lld != %llu, %lld", aval, bval, kval, -kval);
- test.exp(SQL_NO_DATA, 0, 0, true);
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- test.run(HStmt(hStmt), SQLCloseCursor(hStmt));
- }
- freeAll(test, hEnv, hDbc, hStmt);
-}
-
-static void
-testMiscC2(Test& test)
-{
- SQLHANDLE hEnv, hDbc, hStmt;
- allocAll(test, hEnv, hDbc, hStmt);
-#if 0
- {
- char POP[255];
- char PORT[255];
- char ACCESSNODE[255];
-
- const char* sqlSelect = "select PORT from AAA where POP=? and ACCESSNODE=?";
-
- test.run(HStmt(hStmt), SQLPrepare(hStmt, (SQLCHAR*)sqlSelect, SQL_NTS));
-
- for (int j=0; j<5; j++) {
- printf("Loop %u\n", j);
- printf("LINE %u\n", __LINE__);
-
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 255, 0, POP, 255, 0));
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 255, 0, ACCESSNODE, 255, 0));
- test.run(HStmt(hStmt), SQLBindCol(hStmt, 1, SQL_C_CHAR, PORT, 255, 0));
-
- sprintf(POP, "a");
- sprintf(ACCESSNODE, "b");
-
- test.run(HStmt(hStmt), SQLExecute(hStmt));
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- printf("got %s\n", PORT);
- printf("LINE %u\n", __LINE__);
- test.exp(SQL_NO_DATA, 0, 0, true);
- printf("LINE %u\n", __LINE__);
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- printf("LINE %u\n", __LINE__);
- test.run(HStmt(hStmt), SQLCloseCursor(hStmt));
- printf("LINE %u\n", __LINE__);
- }
- }
- return;
-#endif
-
- char POP[255];
- char PORT[255];
- char ACCESSNODE[255];
- unsigned long VLAN = 0;
- unsigned long SNMP_INDEX = 0;
- unsigned long PORT_STATE = 0;
- unsigned long STATIC_PORT = 0;
- unsigned long COMMENT = 0;
-
- const char* sqlSelect = "select PORT, PORT_STATE from PORTS where POP=? and ACCESSNODE=?";
-
- test.run(HStmt(hStmt), SQLPrepare(hStmt, (SQLCHAR*)sqlSelect, SQL_NTS));
-
- for (int j=0; j<5; j++) {
- printf("Loop %u\n", j);
- printf("LINE %u\n", __LINE__);
-
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 255, 0, POP, 255, 0));
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 255, 0, ACCESSNODE, 255, 0));
- test.run(HStmt(hStmt), SQLBindCol(hStmt, 1, SQL_C_CHAR, PORT, 255, 0));
- test.run(HStmt(hStmt), SQLBindCol(hStmt, 2, SQL_C_ULONG, &PORT_STATE, 0, 0));
-
- sprintf(POP, "row%u.i%u.bredband.com", 2, 3);
- sprintf(ACCESSNODE, "as%u", 2);
-
- test.run(HStmt(hStmt), SQLExecute(hStmt));
- for (int i=0; i < 3; i++) {
- PORT_STATE=0;
- sprintf(PORT, "XXXXXXXXXXXXXXXXXXXXX");
-
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- printf("got %s %lu\n", PORT, PORT_STATE);
- // test.chk(HStmt(hStmt), false, "got %s != %s", "xxx", PORT);
- }
- printf("LINE %u\n", __LINE__);
- test.exp(SQL_NO_DATA, 0, 0, true);
- printf("LINE %u\n", __LINE__);
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- printf("LINE %u\n", __LINE__);
- test.run(HStmt(hStmt), SQLCloseCursor(hStmt));
- printf("LINE %u\n", __LINE__);
- }
-}
-
-static const Sql
-miscSqlC2[] = {
- Sql("drop table PORTS",
- SQL_DIAG_DROP_TABLE, -1, 0, -1, -1,
- SQL_ERROR, "IM000", 2040709, false),
- Sql("create table PORTS (POP varchar(200) not null, ACCESSNODE varchar(200) not null, PORT varchar(200) not null, VLAN int unsigned, SNMP_INDEX int unsigned, PORT_STATE int unsigned, STATIC_PORT int unsigned, COMMENT int unsigned, primary key (POP,ACCESSNODE,PORT))",
- SQL_DIAG_CREATE_TABLE, -1, 0, -1, -1),
- Sql("create index xxPORTS on PORTS (POP, ACCESSNODE) nologging",
- SQL_DIAG_CREATE_INDEX, -1, -1, -1, -1),
- Sql("insert into PORTS values ('row2.i3.bredband.com','as2','Fa0/0',0,1,2,3,4)",
- SQL_DIAG_INSERT, 1, 0, -1, -1),
- Sql("insert into PORTS values ('row2.i3.bredband.com','as2','Fa0/1',1,2,3,4,5)",
- SQL_DIAG_INSERT, 1, 0, -1, -1),
- Sql("insert into PORTS values ('row2.i3.bredband.com','as2','Fa0/2',2,3,4,5,6)",
- SQL_DIAG_INSERT, 1, 0, -1, -1),
- Sql("select PORT, PORT_STATE from PORTS where POP='row2.i3.bredband.com' and ACCESSNODE='as2'",
- SQL_DIAG_SELECT_CURSOR, 3, 3, -1, -1),
-
- Sql("drop table AAA",
- SQL_DIAG_DROP_TABLE, -1, 0, -1, -1,
- SQL_ERROR, "IM000", 2040709, false),
- Sql("create table AAA (POP varchar(200), ACCESSNODE varchar(200) not null, PORT varchar(200) not null, primary key (POP,ACCESSNODE,PORT))",
- SQL_DIAG_CREATE_TABLE, -1, 0, -1, -1),
- Sql("create index xxAAA on AAA (POP, ACCESSNODE) nologging",
- SQL_DIAG_CREATE_INDEX, -1, -1, -1, -1),
- Sql("insert into AAA values ('a','b','A')",
- SQL_DIAG_INSERT, 1, 0, -1, -1),
-
- Sql("testMiscC2", testMiscC2),
- Sql()
-};
-
-/*
-> SELECT PORT, PORT_STATE FROM PORTS where pop=? and accessnode=?
-> SELECT VLAN, SNMP_INDEX, PORT_STATE, STATIC_PORT, COMMENT FROM PORTS WHERE POP=? AND ACCESSNODE=? AND PORT=?
-> select count(*) from ports
-> select snmp_index from ports where pop='row2.i3.bredband.com' and accessnode='as2' and port='Fa0/2'
-
-> SELECT MAC, MAC_EXPIRE, IP, IP_EXPIRE, HOSTNAME, DETECTED, STATUS, STATIC_DNS, BLOCKED, NUM_REQUESTS, ACCESSTYPE, OS_TYPE, GATE_WAY, DIRTY_FLAG, LOCKED_IP FROM CLIENTS WHERE PORT=? AND ACCESSNODE=? AND POP=?
-> SELECT SERVICES.ACCESSTYPE, SERVICES.NUM_IP, SERVICES.TEXPIRE, SERVICES.CUSTOMER_ID, SERVICES.LEASED_NUM_IP, SERVICES.PROVIDER, SERVICES.LOCKED_IP, SERVICES.STATIC_DNS, SERVICES.SUSPENDED_SERVICE FROM SERVICES , ACCESSTYPES WHERE SERVICES.PORT = ? AND SERVICES.ACCESSNODE = ? AND SERVICES.POP = ? AND SERVICES.ACCESSTYPE=ACCESSTYPES.ACCESSTYPE
-*/
-
-static const Sql
-miscSql99[] = {
- Sql("drop table tt99a",
- SQL_DIAG_DROP_TABLE, -1, 0, -1, -1,
- SQL_ERROR, "IM000", 2040709, false),
- Sql("create table tt99a (col1 int unsigned primary key, col2 int unsigned, col3 int unsigned, col4 int unsigned, col5 int unsigned, col6 varchar(7) default 'abc123')",
- SQL_DIAG_CREATE_TABLE, -1, 0, -1, -1),
- // inserts 10 rows, all same, start value 1000000000
- Sql("testMisc99a", testMisc99a),
- // interpreted scan plus bind parameter
- Sql("select col1 from tt99a where col2 = ?",
- SQL_DIAG_SELECT_CURSOR, 1, 1, 1000000004, 1000000004),
- Sql("select col1 from tt99a where col2 = 1000000000 + ?",
- SQL_DIAG_SELECT_CURSOR, 1, 1, 1000000004, 4),
- Sql("select col1 from tt99a where col2 = ? + 1000000000",
- SQL_DIAG_SELECT_CURSOR, 1, 1, 1000000004, 4),
- // same not interpreted, tuple count 10
- Sql("select col1 from tt99a where col2 + 0 = 1000000000 + ?",
- SQL_DIAG_SELECT_CURSOR, 1, 10, 1000000004, 4),
- // varchar variations
- Sql("select count(*) from tt99a where col6 = 'abc123'",
- SQL_DIAG_SELECT_CURSOR, 1, 10, 10, -1),
- Sql("select count(*) from tt99a where left(col6, ?) = 'abc1'",
- SQL_DIAG_SELECT_CURSOR, 1, 10, 10, 4),
- Sql("select count(*) from tt99a where left(col6, ?) = 'abc1'",
- SQL_DIAG_SELECT_CURSOR, 1, 10, 0, 3),
- // tpc-b inspired, wrong optimization to direct update
- Sql("drop table tt99b",
- SQL_DIAG_DROP_TABLE, -1, 0, -1, -1,
- SQL_ERROR, "IM000", 2040709, false),
- Sql("create table tt99b(a int primary key, b int not null, c double precision)",
- SQL_DIAG_CREATE_TABLE, -1, 0, -1, -1),
- Sql("insert into tt99b values(1, 10, 100.0)",
- SQL_DIAG_INSERT, 1, 0, -1, -1),
- Sql("insert into tt99b values(9, 90, 900.0)",
- SQL_DIAG_INSERT, 1, 0, -1, -1),
- Sql("create unique hash index tt99y on tt99b (b)",
- SQL_DIAG_CREATE_INDEX, -1, 0, -1, -1),
- // first scan update..
- Sql("update tt99b set c = c + ? where a+0 = 1",
- SQL_DIAG_UPDATE_WHERE, 1, 2, -1, 10),
- Sql("update tt99b set c = c + ? where b+0 = 10",
- SQL_DIAG_UPDATE_WHERE, 1, 2, -1, 10),
- // then optimized..
- Sql("update tt99b set c = c + ? where a = 1",
- SQL_DIAG_UPDATE_WHERE, 1, 1, -1, 10),
- Sql("update tt99b set c = c + ? where b = 10",
- SQL_DIAG_UPDATE_WHERE, 1, 1, -1, 10),
- // verify..
- Sql("select count(*) from tt99b where 100-1 < c and c < 140-1",
- SQL_DIAG_SELECT_CURSOR, 1, 2, 0, -1),
- Sql("select count(*) from tt99b where 140-.001 < c and c < 140+.001",
- SQL_DIAG_SELECT_CURSOR, 1, 2, 1, -1),
- // unsigned test
- Sql("drop table tt99c",
- SQL_DIAG_DROP_TABLE, -1, 0, -1, -1,
- SQL_ERROR, "IM000", 2040709, false),
- Sql("create table tt99c(a int unsigned primary key, b int unsigned)",
- SQL_DIAG_CREATE_TABLE, -1, 0, -1, -1),
- Sql("insert into tt99c values(2100000000, 4100000000)",
- SQL_DIAG_INSERT, 1, 0, -1, -1),
- Sql("insert into tt99c (a, b) select b, a from tt99c",
- SQL_DIAG_INSERT, 1, 1, -1, -1),
- Sql("testMisc99c", testMisc99c),
- // new external type SQL_C_[SU]BIGINT
- Sql("testMisc99d", testMisc99d),
- Sql()
-};
-
-static const struct { const Sql* sql; int minscale; }
-miscSql[11] = {
- { miscSql90, 0 },
- { miscSql91, 0 },
- { miscSql92, 0 },
- { miscSql93, 0 },
- { 0, 0 }, // 94
- { miscSql95, 0 },
- { miscSql96, 0 },
- { miscSql97, 0 },
- { 0, 0 }, // 98
- { miscSql99, 0 },
- { miscSqlC2, 0 }
-};
-
-static void
-testSql(Test& test)
-{
- const unsigned salt = test.m_stuff; // mess
- if (opt.m_scale < miscSql[salt].minscale) {
- if (opt.m_v >= 1)
- ndbout << "skip - requires scale >= " << miscSql[salt].minscale << endl;
- return;
- }
- assert(0 <= salt && salt < 11 && miscSql[salt].sql != 0);
- SQLHANDLE hEnv, hDbc, hStmt;
- allocAll(test, hEnv, hDbc, hStmt);
- for (unsigned i = 0; ; i++) {
- const Sql& sql = miscSql[salt].sql[i];
- if (sql.m_sql == 0)
- break;
- if (opt.m_v >= 2)
- ndbout << "SQL: " << sql.m_sql << endl;
- if (sql.m_testFunc != 0) {
- (*sql.m_testFunc)(test);
- continue;
- }
- if (strncmp(sql.m_sql, "--", 2) == 0) {
- continue;
- }
- if (strcmp(sql.m_sql, Sql::set_autocommit_on()) == 0) {
- setAutocommit(test, hDbc, true);
- continue;
- }
- if (strcmp(sql.m_sql, Sql::set_autocommit_off()) == 0) {
- setAutocommit(test, hDbc, false);
- continue;
- }
- if (strcmp(sql.m_sql, Sql::do_commit()) == 0) {
- test.run(HDbc(hDbc), SQLEndTran(SQL_HANDLE_DBC, hDbc, SQL_COMMIT));
- continue;
- }
- if (strcmp(sql.m_sql, Sql::do_rollback()) == 0) {
- test.run(HDbc(hDbc), SQLEndTran(SQL_HANDLE_DBC, hDbc, SQL_ROLLBACK));
- continue;
- }
- if (opt.m_v >= 3) {
- ndbout << "expect:";
- ndbout << " ret=" << sql.m_ret;
- ndbout << " rows=" << sql.m_rowCount;
- ndbout << " tuples=" << sql.m_tuplesFetched;
- ndbout << endl;
- }
- test.run(HStmt(hStmt), SQLFreeStmt(hStmt, SQL_UNBIND));
- test.run(HStmt(hStmt), SQLFreeStmt(hStmt, SQL_RESET_PARAMS));
- // prep
- test.exp(sql.m_ret, sql.m_state, sql.m_native, false);
- test.run(HStmt(hStmt), SQLPrepare(hStmt, (SQLCHAR*)sql.m_sql, SQL_NTS));
- if (test.m_ret != SQL_SUCCESS)
- continue;
- // bind between prep and exec like JDBC
- unsigned long bindValue = sql.m_bindValue;
- for (int k = 0; k <= 1; k++) {
- if (bindValue != -1) {
- assert(strchr(sql.m_sql, '?') != 0);
- test.run(HStmt(hStmt), SQLBindParameter(hStmt, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 0, 0, &bindValue, 0, 0));
- }
- if (k == 0) {
- if (bindValue != -1) {
- test.run(HStmt(hStmt), SQLFreeStmt(hStmt, SQL_RESET_PARAMS));
- // exec with unbound parameter
- test.exp(SQL_ERROR, "HY010", -1, true);
- test.run(HStmt(hStmt), SQLExecute(hStmt));
- test.chk(HStmt(hStmt), test.m_functionCode == sql.m_functionCode || sql.m_functionCode == -1, "func: got %d != %d", (int)test.m_functionCode, (int)sql.m_functionCode);
- }
- } else {
- // exec
- test.exp(sql.m_ret, sql.m_state, sql.m_native, sql.m_reset);
- test.run(HStmt(hStmt), SQLExecute(hStmt));
- test.chk(HStmt(hStmt), test.m_functionCode == sql.m_functionCode || sql.m_functionCode == -1, "func: got %d != %d", (int)test.m_functionCode, (int)sql.m_functionCode);
- }
- }
- if (sql.m_rowCount != -1) {
- if (sql.m_functionCode == SQL_DIAG_SELECT_CURSOR) {
- long lastValue;
- if (sql.m_lastValue != -1)
- test.run(HStmt(hStmt), SQLBindCol(hStmt, 1, SQL_C_SLONG, &lastValue, 0, 0));
- unsigned k = 0;
- do {
- int rowCount = 0;
- lastValue = -1;
- while (1) {
- test.exp(SQL_NO_DATA, 0, 0, false);
- test.run(HStmt(hStmt), SQLFetch(hStmt));
- if (test.m_ret == SQL_NO_DATA)
- break;
- rowCount++;
- }
- test.chk(HStmt(hStmt), rowCount == sql.m_rowCount, "rowCount: got %d != %d", (int)rowCount, (int)sql.m_rowCount);
- if (sql.m_tuplesFetched != -1)
- chkTuplesFetched(test, hStmt, sql.m_tuplesFetched);
- if (rowCount > 0 && sql.m_lastValue != -1)
- test.chk(HStmt(hStmt), lastValue == sql.m_lastValue, "lastValue: got %ld != %ld", (long)lastValue, (long)sql.m_lastValue);
- test.run(HStmt(hStmt), SQLCloseCursor(hStmt));
- if (++k >= opt.m_scale)
- break;
- test.run(HStmt(hStmt), SQLExecute(hStmt));
- } while (1);
- test.timerCnt(opt.m_scale);
- } else {
- assert(sql.m_lastValue == -1);
- chkRowCount(test, hStmt, sql.m_rowCount);
- if (sql.m_tuplesFetched != -1)
- chkTuplesFetched(test, hStmt, sql.m_tuplesFetched);
- test.timerCnt(1);
- }
- }
- }
- freeAll(test, hEnv, hDbc, hStmt);
-}
-
-// name, function, runmode, salt (0=const or n/a), description
-static const Case caseList[] = {
- Case( "00alloc", testAlloc, Case::Thread, 0, "allocate handles" ),
- Case( "01create", testCreate, Case::Single, 0, "create tables for the test" ),
- Case( "02prepare", testPrepare, Case::Thread, 0, "prepare without execute" ),
- Case( "03catalog", testCatalog, Case::Thread, 0, "catalog functions" ),
- Case( "10insert", testInsert, Case::Thread, 1, "insert computed rows" ),
- Case( "11delall", testDeleteAll, Case::Single, 0, "delete all rows via scan" ),
- Case( "12insert", testInsert, Case::Thread, 1, "insert computed rows again" ),
- Case( "13count", testCount, Case::Single, 0, "count rows" ),
- Case( "14verpk", testVerifyPk, Case::Thread, 1, "verify via primary key" ),
- Case( "15verscan", testVerifyScan, Case::Serial, 1, "verify via range scans" ),
- Case( "16join", testJoin, Case::Single, 0, "multiple self-join" ),
- Case( "17cart", testCart, Case::Single, 0, "cartesian join" ),
- Case( "20updpk", testUpdatePk, Case::Thread, 2, "update via primary key" ),
- Case( "21verpk", testVerifyPk, Case::Thread, 2, "verify via primary key" ),
- Case( "22verscan", testVerifyScan, Case::Serial, 2, "verify via range scans" ),
- Case( "23updscan", testUpdateScan, Case::Serial, 0, "update via scan" ),
- Case( "24verpk", testVerifyPk, Case::Thread, 0, "verify via primary key" ),
- Case( "25verscan", testVerifyScan, Case::Serial, 0, "verify via range scans" ),
- Case( "26delpk", testDeletePk, Case::Thread, 0, "delete via primary key" ),
- Case( "30trans", testTrans, Case::Single, 3, "rollback and commit" ),
- Case( "31concur", testConcur, Case::Single, 0, "commit across open cursor" ),
- Case( "32readcom", testReadcom, Case::Single, 0, "read committed" ),
- Case( "40perf", testPerf, Case::Single, 0, "perf test prepare" ),
- Case( "41perf", testPerf, Case::Thread, 1, "perf test NDB API" ),
- Case( "42perf", testPerf, Case::Thread, 2, "perf test NDB ODBC" ),
- Case( "90sql", testSql, Case::Single, 0, "misc SQL: metadata" ),
- Case( "91sql", testSql, Case::Single, 1, "misc SQL: misc" ),
- Case( "92sql", testSql, Case::Thread, 2, "misc SQL: scan rollback" ),
- Case( "93sql", testSql, Case::Single, 3, "misc SQL: locking" ),
- Case( "95sql", testSql, Case::Single, 5, "misc SQL: indexes (simple)" ),
- Case( "96sql", testSql, Case::Single, 6, "misc SQL: indexes" ),
- Case( "97sql", testSql, Case::Thread, 7, "misc SQL: indexes" ),
- Case( "99sql", testSql, Case::Single, 9, "misc SQL: bug du jour" ),
- Case( "C2", testSql, Case::Single, 10, "misc SQL: C2" )
-};
-
-static const unsigned caseCount = arraySize(caseList);
-
-static bool
-findCase(const char* name)
-{
- for (unsigned i = 0; i < caseCount; i++) {
- const Case& cc = caseList[i];
- if (strstr(cc.m_name, name) != 0)
- return true;
- }
- return false;
-}
-
-static void
-listCases()
-{
- ndbout << "cases:" << endl;
- unsigned m = 0;
- for (unsigned i = 0; i < caseCount; i++) {
- const Case& cc = caseList[i];
- if (m < strlen(cc.m_name))
- m = strlen(cc.m_name);
- }
- for (unsigned i = 0; i < caseCount; i++) {
- const Case& cc = caseList[i];
- char buf[200];
- sprintf(buf, "%-*s [%-6s] %s", m, cc.m_name, cc.modename(), cc.m_desc);
- ndbout << buf << endl;
- }
-}
-
-// threads
-
-extern "C" { static void* testThr(void* arg); }
-
-struct Thr {
- enum State {
- Wait = 1, // wait for test case
- Run = 2, // run the test case
- Done = 3, // done with the case
- Exit = 4 // exit thread
- };
- unsigned m_no; // thread number 1 .. max
- NdbThread* m_thr; // thread id etc
- const Case* m_case; // current case
- State m_state; // condition variable
- NdbMutex* m_mutex; // condition guard
- NdbCondition* m_cond;
- void* m_status; // exit status (not used)
- Test m_test; // test runner
- Thr(unsigned no, unsigned loop) :
- m_no(no),
- m_thr(0),
- m_case(0),
- m_state(Wait),
- m_mutex(NdbMutex_Create()),
- m_cond(NdbCondition_Create()),
- m_status(0),
- m_test(no, loop) {
- }
- ~Thr() {
- destroy();
- NdbCondition_Destroy(m_cond);
- NdbMutex_Destroy(m_mutex);
- }
- void create() {
- assert(m_thr == 0);
- m_thr = NdbThread_Create(testThr, (void**)this, 64*1024, "test", NDB_THREAD_PRIO_LOW);
- }
- void destroy() {
- if (m_thr != 0)
- NdbThread_Destroy(&m_thr);
- m_thr = 0;
- }
- void lock() {
- NdbMutex_Lock(m_mutex);
- }
- void unlock() {
- NdbMutex_Unlock(m_mutex);
- }
- void wait() {
- NdbCondition_Wait(m_cond, m_mutex);
- }
- void signal() {
- NdbCondition_Signal(m_cond);
- }
- void join() {
- NdbThread_WaitFor(m_thr, &m_status);
- m_thr = 0;
- }
- // called from main
- void mainStart(const Case& cc) {
- lock();
- m_case = &cc;
- m_state = Run;
- signal();
- unlock();
- }
- void mainStop() {
- lock();
- while (m_state != Done) {
- if (opt.m_v >= 4)
- ndbout << ::lock << "thr " << m_no << " [main] wait state=" << m_state << endl << ::unlock;
- wait();
- }
- if (opt.m_v >= 4)
- ndbout << ::lock << "thr " << m_no << " [main] done" << endl << ::unlock;
- m_state = Wait;
- unlock();
- }
- // run in thread
- void testSelf() {
- while (1) {
- lock();
- while (m_state != Run && m_state != Exit) {
- if (opt.m_v >= 4)
- ndbout << ::lock << "thr " << m_no << " [self] wait state=" << m_state << endl << ::unlock;
- wait();
- }
- if (m_state == Run) {
- if (opt.m_v >= 4)
- ndbout << ::lock << "thr " << m_no << " [self] run" << endl << ::unlock;
- assert(m_case != 0);
- m_test.timerOn();
- m_test.runCase(*m_case);
- m_test.timerOff();
- m_state = Done;
- if (opt.m_v >= 4)
- ndbout << ::lock << "thr " << m_no << " [self] done" << endl << ::unlock;
- signal();
- unlock();
- } else if (m_state == Exit) {
- unlock();
- break;
- } else {
- assert(false);
- }
- }
- if (opt.m_v >= 4)
- ndbout << ::lock << "thr " << m_no << " [self] exit" << endl << ::unlock;
- }
-};
-
-static void*
-testThr(void* arg)
-{
- Thr& thr = *(Thr*)arg;
- thr.testSelf();
- return 0;
-}
-
-#ifdef DMALLOC
-extern "C" {
-
-static int malloc_bytes = 0;
-static int free_bytes = 0;
-
-static void
-malloc_track(const char *file, const unsigned int line, const int func_id, const DMALLOC_SIZE byte_size, const DMALLOC_SIZE alignment, const DMALLOC_PNT old_addr, const DMALLOC_PNT new_addr)
-{
- if (func_id == DMALLOC_FUNC_MALLOC) {
- malloc_bytes += byte_size;
- return;
- }
- if (func_id == DMALLOC_FUNC_FREE) {
- DMALLOC_SIZE size = 0;
- dmalloc_examine(old_addr, &size, 0, 0, 0);
- free_bytes += size;
- // XXX useless - byte_size and size are 0
- return;
- }
-}
-
-}
-#endif /* DMALLOC */
-
-static void
-testMain()
-{
-#ifndef NDB_LINUX /* valgrind-1.0.3 does not support */
- NdbThread_SetConcurrencyLevel(opt.m_threads + 2);
-#endif
-#ifdef DMALLOC
- dmalloc_track(malloc_track);
-#endif
- Test test(0, 0);
-#ifdef ndbODBC
- Ndb* ndb = 0;
- if (1) { // pre-alloc one Ndb object
- ndb = new Ndb("TEST_DB");
- ndb->init();
- if (ndb->waitUntilReady() != 0) {
- ndbout << ndb->getNdbError() << endl;
- fatal("waitUntilReady");
- }
- }
-#endif
- for (unsigned loop = 1; opt.m_loop == 0 || loop <= opt.m_loop; loop++) {
- if (opt.m_v >= 2)
- ndbout << "loop " << loop << endl;
- // create new set of threads in each loop
- Thr** thrList = new Thr* [1 + opt.m_threads];
- for (unsigned n = 1; n <= opt.m_threads; n++) {
- Thr& thr = *(thrList[n] = new Thr(n, loop));
- thr.create();
- if (opt.m_v >= 4)
- ndbout << "thr " << n << " [main] created" << endl;
- }
-#ifdef DMALLOC
- malloc_bytes = free_bytes = 0;
-#endif
- for (unsigned i = 0; i < caseCount; i++) {
- const Case& cc = caseList[i];
- if (! cc.matchcase())
- continue;
- if (opt.m_v >= 2)
- ndbout << "RUN: " << cc.m_name << " - " << cc.m_desc << endl;
- test.timerOn();
- for (unsigned subloop = 1; subloop <= opt.m_subloop; subloop++) {
- my_sema = 0;
- if (opt.m_v >= 3)
- ndbout << "subloop " << subloop << endl;
- if (cc.m_mode == Case::Single) {
- Thr& thr = *thrList[1];
- thr.mainStart(cc);
- thr.mainStop();
- test.timerCnt(thr.m_test);
- } else if (cc.m_mode == Case::Serial) {
- for (unsigned n = 1; n <= opt.m_threads; n++) {
- Thr& thr = *thrList[n];
- thr.mainStart(cc);
- thr.mainStop();
- test.timerCnt(thr.m_test);
- }
- } else if (cc.m_mode == Case::Thread) {
- for (unsigned n = 1; n <= opt.m_threads; n++) {
- Thr& thr = *thrList[n];
- thr.mainStart(cc);
- }
- for (unsigned n = 1; n <= opt.m_threads; n++) {
- Thr& thr = *thrList[n];
- thr.mainStop();
- test.timerCnt(thr.m_test);
- }
- } else {
- assert(false);
- }
- }
- test.timerOff();
- if (opt.m_v >= 1)
- ndbout << cc.m_name << " total " << test << endl;
- }
-#ifdef DMALLOC
- if (opt.m_v >= 9) // XXX useless now
- ndbout << "malloc " << malloc_bytes << " free " << free_bytes << " lost " << malloc_bytes - free_bytes << endl;
-#endif
- // tell threads to exit
- for (unsigned n = 1; n <= opt.m_threads; n++) {
- Thr& thr = *thrList[n];
- thr.lock();
- thr.m_state = Thr::Exit;
- thr.signal();
- thr.unlock();
- if (opt.m_v >= 4)
- ndbout << "thr " << n << " [main] told to exit" << endl;
- }
- for (unsigned n = 1; n <= opt.m_threads; n++) {
- Thr& thr = *thrList[n];
- thr.join();
- if (opt.m_v >= 4)
- ndbout << "thr " << n << " [main] joined" << endl;
- delete &thr;
- }
- delete[] thrList;
- }
-#ifdef ndbODBC
- delete ndb;
-#endif
-}
-
-static bool
-str2num(const char* arg, const char* str, unsigned* num, unsigned lo = 0, unsigned hi = 0)
-{
- char* end = 0;
- long n = strtol(str, &end, 0);
- if (end == 0 || *end != 0 || n < 0) {
- ndbout << arg << " " << str << " is invalid number" << endl;
- return false;
- }
- if (lo != 0 && n < lo) {
- ndbout << arg << " " << str << " is too small min = " << lo << endl;
- return false;
- }
- if (hi != 0 && n > hi) {
- ndbout << arg << " " << str << " is too large max = " << hi << endl;
- return false;
- }
- *num = n;
- return true;
-}
-
-NDB_COMMAND(testOdbcDriver, "testOdbcDriver", "testOdbcDriver", "testOdbcDriver", 65535)
-{
- while (++argv, --argc > 0) {
- const char* arg = argv[0];
- if (strcmp(arg, "-case") == 0) {
- if (++argv, --argc > 0) {
- assert(opt.m_namecnt < arraySize(opt.m_name));
- opt.m_name[opt.m_namecnt++] = argv[0];
- if (findCase(argv[0]))
- continue;
- }
- }
- if (strcmp(arg, "-core") == 0) {
- opt.m_core = true;
- continue;
- }
- if (strcmp(arg, "-depth") == 0) {
- if (++argv, --argc > 0) {
- if (str2num(arg, argv[0], &opt.m_depth))
- continue;
- }
- }
- if (strcmp(arg, "-dsn") == 0) {
- if (++argv, --argc > 0) {
- opt.m_dsn = argv[0];
- continue;
- }
- }
- if (strcmp(arg, "-frob") == 0) {
- if (++argv, --argc > 0) {
- if (str2num(arg, argv[0], &opt.m_frob))
- continue;
- }
- }
- if (strcmp(arg, "-errs") == 0) {
- if (++argv, --argc > 0) {
- if (str2num(arg, argv[0], &opt.m_errs))
- continue;
- }
- }
- if (strcmp(arg, "-fragtype") == 0) {
- if (++argv, --argc > 0) {
- opt.m_fragtype = argv[0];
- continue;
- }
- }
- if (strcmp(arg, "-home") == 0) {
- if (++argv, --argc > 0) {
- opt.m_home = argv[0];
- continue;
- }
- }
- if (strcmp(arg, "-loop") == 0) {
- if (++argv, --argc > 0) {
- if (str2num(arg, argv[0], &opt.m_loop))
- continue;
- }
- }
- if (strcmp(arg, "-nogetd") == 0) {
- opt.m_nogetd = true;
- continue;
- }
- if (strcmp(arg, "-noputd") == 0) {
- opt.m_noputd = true;
- continue;
- }
- if (strcmp(arg, "-nosort") == 0) {
- opt.m_nosort = true;
- continue;
- }
- if (strcmp(arg, "-scale") == 0) {
- if (++argv, --argc > 0) {
- if (str2num(arg, argv[0], &opt.m_scale))
- continue;
- }
- }
- if (strcmp(arg, "-serial") == 0) {
- opt.m_serial = true;
- continue;
- }
- if (strcmp(arg, "-skip") == 0) {
- if (++argv, --argc > 0) {
- assert(opt.m_skipcnt < arraySize(opt.m_skip));
- opt.m_skip[opt.m_skipcnt++] = argv[0];
- if (findCase(argv[0]))
- continue;
- }
- }
- if (strcmp(arg, "-subloop") == 0) {
- if (++argv, --argc > 0) {
- if (str2num(arg, argv[0], &opt.m_subloop))
- continue;
- }
- }
- if (strcmp(arg, "-table") == 0) {
- if (++argv, --argc > 0) {
- opt.m_table = argv[0];
- if (findTable())
- continue;
- }
- }
- if (strcmp(arg, "-threads") == 0) {
- if (++argv, --argc > 0) {
- if (str2num(arg, argv[0], &opt.m_threads, 1, MAX_THR))
- continue;
- }
- }
- if (strcmp(arg, "-trace") == 0) {
- if (++argv, --argc > 0) {
- if (str2num(arg, argv[0], &opt.m_trace))
- continue;
- }
- }
- if (strcmp(arg, "-v") == 0) {
- if (++argv, --argc > 0) {
- if (str2num(arg, argv[0], &opt.m_v))
- continue;
- }
- }
- if (strncmp(arg, "-v", 2) == 0 && isdigit(arg[2])) {
- if (str2num(arg, &arg[2], &opt.m_v))
- continue;
- }
- printusage();
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
- homeEnv: {
- static char env[1000];
- if (opt.m_home != 0) {
- sprintf(env, "NDB_HOME=%s", opt.m_home);
- putenv(env);
- }
- }
- traceEnv: {
- static char env[40];
- sprintf(env, "NDB_ODBC_TRACE=%u", opt.m_trace);
- putenv(env);
- }
- debugEnv: {
- static char env[40];
- sprintf(env, "NDB_ODBC_DEBUG=%d", 1);
- putenv(env);
- }
- testMain();
- return NDBT_ProgramExit(NDBT_OK);
-}
-
-// vim: set sw=4:
diff --git a/storage/ndb/test/odbc/test_compiler/Makefile b/storage/ndb/test/odbc/test_compiler/Makefile
deleted file mode 100644
index 34819f21171..00000000000
--- a/storage/ndb/test/odbc/test_compiler/Makefile
+++ /dev/null
@@ -1,21 +0,0 @@
-include .defs.mk
-
-TYPE = odbcdriver
-
-BIN_TARGET = test_compiler
-
-SOURCES = test_compiler.cpp
-
-CCFLAGS_LOC += \
- -I$(NDB_TOP)/src/client/odbc/common \
- -I$(NDB_TOP)/src/client/odbc/dictionary \
- -I$(NDB_TOP)/src/client/odbc/compiler
-
-CCFLAGS_WARNINGS += -Wno-unused
-
-LIBS_SPEC += \
- -lodbccompiler_pic
-
-
-include $(NDB_TOP)/Epilogue.mk
-
diff --git a/storage/ndb/test/odbc/test_compiler/test_compiler.cpp b/storage/ndb/test/odbc/test_compiler/test_compiler.cpp
deleted file mode 100644
index d09b738dbb8..00000000000
--- a/storage/ndb/test/odbc/test_compiler/test_compiler.cpp
+++ /dev/null
@@ -1,233 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-/**********************************************************************************
- test_compiler.cpp
- Tests the code tree generated
- by the compiler
-***********************************************************************************/
-#include <stdio.h>
-#include <memory.h>
-#include "SQL_compiler.hpp"
-#include "SQL_code_tree.hpp"
-
-typedef struct stSTMT_REF_tag {
- char* szTestStmt ;
- SQL_compiler* pC ;
- SQL_code_tree* pRefTree ;
- int nFlag ; /* indicate if the struct haa a code tree and compiler and should be processed */
-} stSTMT_REF ;
-
-int compare_trees(SQL_code_tree* pCompilerOutput, SQL_code_tree* pReference) ;
-
-/* Assign statements to szTestStmt and NULL to pTestRef */
-
-static stSTMT_REF stTestRef[] = {
-/* 0 */ {"create table foo (pk integer primary key, a integer, b varchar(20), check (a is not null))", NULL, NULL, 0},
-/* 1 */ {"insert into foo (pk, a, b) values (1, 10, 'ett')", NULL, NULL, 0},
-/* 2 */ {"insert into foo values (2, 20)", NULL, NULL, 0},
-/* 3 */ {"delete from foo", NULL, NULL, 1},
-/* 4 */ {"delete from foo where pk=5", NULL, NULL, 0},
-/* 5 */ {"delete from foo where a<10 or b='test'", NULL, NULL, 0},
-/* 6 */ {"update foo set a=100, b=null", NULL, NULL, 0},
-/* 7 */ {"update foo set a=0 where pk=1", NULL, NULL, 0},
-/* 8 */ {"update foo set a=a+pk where b is null", NULL, NULL, 0},
-/* 9 */ {"select * from foo", NULL, NULL, 0},
-/* 10 */ {"select pk, a, b from foo where pk=1", NULL, NULL, 0},
-/* 11 */ {"select * from foo order by a", NULL, NULL, 0},
-/* 12 */ {"select * from foo A, foo B where A.pk=B.a and A.a<2*B.a", NULL, NULL, 0}
-} ;
-
-
-int main(int argc, char* argv[]){
-
- int retcode = 0 ;
- int nTests = sizeof(stTestRef)/sizeof(stSTMT_REF) ;
-
- for(int c = 0 ; c < nTests ; c++) {
- if(stTestRef[c].nFlag){
- stTestRef[c].pC = new SQL_compiler() ;
- stTestRef[c].pRefTree = new SQL_code_tree() ;
- }
- }
-
- /* Create reference code trees */
-
- /*
- Statement: 0 "create table foo (pk integer primary key, a integer, b varchar(20), check (a is not null))"
- */
-
-
- /*
- Statement: 1
- */
-
-
-
- /*
- Statement: 2
- */
-
-
-
- /*
- Statement: 3 "delete from foo"
- */
-
- stTestRef[3].pRefTree->shift('N') ;
- stTestRef[3].pRefTree->shift('D') ;
- stTestRef[3].pRefTree->shift('B') ;
- stTestRef[3].pRefTree->reduce(0x2050400e, 3) ;
- stTestRef[3].pRefTree->shift('F') ;
- stTestRef[3].pRefTree->shift('O') ;
- stTestRef[3].pRefTree->shift('O') ;
- stTestRef[3].pRefTree->reduce(0x20502003, 3) ;
- stTestRef[3].pRefTree->reduce(0x2050400f, 1) ;
- stTestRef[3].pRefTree->reduce(0x20504007, 2) ;
- stTestRef[3].pRefTree->reduce(0x21407003, 1) ;
- stTestRef[3].pRefTree->shift(0x205021ca) ;
- stTestRef[3].pRefTree->reduce(0x20630001, 1) ;
- stTestRef[3].pRefTree->reduce(0x20815001, 1) ;
- stTestRef[3].pRefTree->shift(0x21407002) ;
- stTestRef[3].pRefTree->reduce(0x21407004, 3) ;
- stTestRef[3].pRefTree->shift(0x21407002) ;
- stTestRef[3].pRefTree->reduce(0x21407005, 1) ;
- stTestRef[3].pRefTree->shift(0x21414001) ;
- stTestRef[3].pRefTree->shift(0x21414002) ;
- stTestRef[3].pRefTree->reduce(0x21407001, 4) ;
- stTestRef[3].pRefTree->reduce(0x51506004, 1) ;
- stTestRef[3].pRefTree->reduce(0x51506003, 1) ;
-
- /*
- Statement: 4
- */
-
-
-
- /*
- Statement: 5
- */
-
-
-
-
- /*
- Statement: 6
- */
-
-
-
-
- /*
- Statement: 7
- */
-
-
-
- /*
- Statement: 8
- */
-
-
-
- /*
- Statement: 9
- */
-
-
-
- /*
- Statement: 10
- */
-
-
-
- /*
- Statement: 11
- */
-
-
-
- /*
- Statement: 12
- */
-
-
-
- for(int i = 0 ; i < nTests ; i++){
- /* Check to see if the statement has an associated code tree and compiler */
- if(stTestRef[i].nFlag){
- stTestRef[i].pC->prepare( stTestRef[i].szTestStmt, strlen(stTestRef[i].szTestStmt)) ;
- if( 0 != compare_trees(&stTestRef[i].pC->m_code_tree, stTestRef[i].pRefTree) ){
- printf("\nCompiler generated tree for statement #%d: \"%s\"\ndeviates from its reference\n", i, stTestRef[i].szTestStmt) ;
- retcode = -1 ;
- break ;
- }else{
- printf("\nTrees for statement #%d: \"%s\" match nicely -- OK\n", i, stTestRef[i].szTestStmt) ;
- retcode = 0 ;
- }
- }
- }
-
- for(int d = 0 ; d < nTests ; d++) {
- if(stTestRef[d].nFlag){
- delete stTestRef[d].pC ;
- delete stTestRef[d].pRefTree ;
- }
- }
-
- return retcode ;
-
-}
-
-
-
-
-int compare_trees(SQL_code_tree* pCompilerOutput, SQL_code_tree* pReference){
-
- int nTop = -1 ;
-
- if(pCompilerOutput->top()== pReference->top()){
-
- nTop = pReference->top() ;
-
- }else{
- printf("\npCompilerOutput->top() = %d;\tpReference->top() = %d\n", pCompilerOutput->top(), pReference->top()) ;
- return -1 ;
- }
-
- pCompilerOutput->beginPostfix() ;
- pReference->beginPostfix() ;
-
- for(int r = 0 ; r < nTop ; r++){
- if(pCompilerOutput->symbol() != pReference->symbol()){
-
- printf("Deviation found in position %d\n", r) ;
- printf("pCompilerOutput->symbol() = 0x%X;\tpReference->symbol() = 0x%X\n", pCompilerOutput->symbol(), pReference->symbol()) ;
- return -1 ;
-
- }else{
-
- pCompilerOutput->nextPostfix() ;
- pReference->nextPostfix() ;
-
- }
- }
-
- return 0 ;
-
-}
-
diff --git a/storage/ndb/test/run-test/16node-tests.txt b/storage/ndb/test/run-test/16node-tests.txt
deleted file mode 100644
index 74592eecb22..00000000000
--- a/storage/ndb/test/run-test/16node-tests.txt
+++ /dev/null
@@ -1,749 +0,0 @@
-# Copyright (C) 2005 MySQL AB
-# Use is subject to license terms
-#
-# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-# BASIC FUNCTIONALITY
-max-time: 500
-cmd: testBasic
-args: -n PkRead
-
-max-time: 500
-cmd: testBasic
-args: -n PkUpdate
-
-max-time: 500
-cmd: testBasic
-args: -n PkDelete
-
-max-time: 500
-cmd: testBasic
-args: -n PkInsert
-
-max-time: 600
-cmd: testBasic
-args: -n UpdateAndRead
-
-max-time: 500
-cmd: testBasic
-args: -n PkReadAndLocker T6
-
-max-time: 500
-cmd: testBasic
-args: -n PkReadAndLocker2 T6
-
-max-time: 500
-cmd: testBasic
-args: -n PkReadUpdateAndLocker T6
-
-max-time: 500
-cmd: testBasic
-args: -n ReadWithLocksAndInserts T6
-
-max-time: 500
-cmd: testBasic
-args: -n PkInsertTwice T1 T6 T10
-
-max-time: 1500
-cmd: testBasic
-args: -n Fill T13
-
-max-time: 1500
-cmd: testBasic
-args: -n Fill T6
-
-max-time: 500
-cmd: testBasic
-args: -n NoCommitSleep T6
-
-max-time: 500
-cmd: testBasic
-args: -n NoCommit626 T6
-
-max-time: 500
-cmd: testBasic
-args: -n NoCommitAndClose T6
-
-max-time: 500
-cmd: testBasic
-args: -n Commit626 T6
-
-max-time: 500
-cmd: testBasic
-args: -n CommitTry626 T6
-
-max-time: 500
-cmd: testBasic
-args: -n CommitAsMuch626 T6
-
-max-time: 500
-cmd: testBasic
-args: -n NoCommit626 T6
-
-max-time: 500
-cmd: testBasic
-args: -n NoCommitRollback626 T1 T6
-
-max-time: 500
-cmd: testBasic
-args: -n Commit630 T1 T6
-
-max-time: 500
-cmd: testBasic
-args: -n CommitTry630 T1 T6
-
-max-time: 500
-cmd: testBasic
-args: -n CommitAsMuch630 T1 T6
-
-max-time: 500
-cmd: testBasic
-args: -n NoCommit630 T1 T6
-
-max-time: 500
-cmd: testBasic
-args: -n NoCommitRollback630 T1 T6
-
-max-time: 500
-cmd: testBasic
-args: -n NoCommitAndClose T1 T6
-
-max-time: 500
-cmd: testBasic
-args: -n RollbackUpdate T1 T6
-
-max-time: 500
-cmd: testBasic
-args: -n RollbackDeleteMultiple T1 T6
-
-max-time: 500
-cmd: testBasic
-args: -n ImplicitRollbackDelete T1 T6
-
-max-time: 500
-cmd: testBasic
-args: -n CommitDelete T1 T6
-
-max-time: 500
-cmd: testBasic
-args: -n RollbackNothing T1 T6
-
-max-time: 500
-cmd: testBasicAsynch
-args: -n PkInsertAsynch
-
-max-time: 500
-cmd: testBasicAsynch
-args: -n PkReadAsynch
-
-max-time: 500
-cmd: testBasicAsynch
-args: -n PkUpdateAsynch
-
-max-time: 500
-cmd: testBasicAsynch
-args: -n PkDeleteAsynch
-
-max-time: 500
-cmd: testBasic
-args: -n MassiveRollback T1 T6 T13
-
-max-time: 500
-cmd: testBasic
-args: -n MassiveRollback2 T1 T6 T13
-
-max-time: 500
-cmd: testTimeout
-args: T1
-
-# SCAN TESTS
-#
-max-time: 500
-cmd: testScan
-args: -n ScanRead16
-
-max-time: 500
-cmd: testScan
-args: -n ScanRead240
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadCommitted240
-
-max-time: 500
-cmd: testScan
-args: -n ScanUpdate
-
-max-time: 500
-cmd: testScan
-args: -n ScanUpdate2 T6
-
-max-time: 500
-cmd: testScan
-args: -n ScanDelete
-
-max-time: 500
-cmd: testScan
-args: -n ScanDelete2 T10
-
-max-time: 500
-cmd: testScan
-args: -n ScanUpdateAndScanRead T6
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadAndLocker T6
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadAndPkRead T6
-
-max-time: 500
-cmd: testScan
-args: -n ScanRead488 -l 10 T6
-
-max-time: 500
-cmd: testScan
-args: -n ScanRead488O -l 10 T6
-
-max-time: 1000
-cmd: testScan
-args: -n ScanRead488_Mixed -l 10 T6
-
-max-time: 500
-cmd: testScan
-args: -n ScanRead488Timeout -l 10 T6
-
-max-time: 600
-cmd: testScan
-args: -n ScanRead40 -l 100 T2
-
-max-time: 1800
-cmd: testScan
-args: -n ScanRead100 -l 100 T1
-
-max-time: 600
-cmd: testScan
-args: -n ScanRead40 -l 100 T1
-
-max-time: 1800
-cmd: testScan
-args: -n ScanRead40RandomTable -l 100 T1
-
-max-time: 500
-cmd: testScan
-args: -n ScanWithLocksAndInserts T6
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadAbort T6
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadAbort15 T6
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadAbort240 T6
-
-max-time: 500
-cmd: testScan
-args: -n ScanUpdateAbort16 T6
-
-max-time: 3600
-cmd: testScan
-args: -n ScanReadRestart T1 T6 T13
-
-max-time: 500
-cmd: testScan
-args: -n ScanUpdateRestart T6
-
-max-time: 500
-cmd: testScan
-args: -n CheckGetValue T6
-
-max-time: 500
-cmd: testScan
-args: -n CloseWithoutStop T6
-
-max-time: 500
-cmd: testScan
-args: -n NextScanWhenNoMore T6
-
-max-time: 500
-cmd: testScan
-args: -n ExecuteScanWithoutOpenScan T6
-
-max-time: 500
-cmd: testScan
-args: -n OnlyOpenScanOnce T6
-
-max-time: 500
-cmd: testScan
-args: -n OnlyOneOpInScanTrans T6
-
-max-time: 500
-cmd: testScan
-args: -n OnlyOneOpBeforeOpenScan T6
-
-max-time: 500
-cmd: testScan
-args: -n OnlyOneScanPerTrans T6
-
-max-time: 500
-cmd: testScan
-args: -n NoCloseTransaction T6
-
-max-time: 500
-cmd: testScan
-args: -n CheckInactivityTimeOut T6
-
-max-time: 500
-cmd: testScan
-args: -n CheckInactivityBeforeClose T6
-
-max-time: 500
-cmd: testScan
-args: -n CheckAfterTerror T6
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadError5021 T1
-
-max-time: 500
-cmd: testScan
-args: -n ScanReaderror5022 T1
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadError5023 T1
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadError5024 T1
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadError5025 T1
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadError5030 T1
-
-max-time: 500
-cmd: testScan
-args: -n InsertDelete T1 T6
-
-max-time: 500
-cmd: testScan
-args: -n CheckAfterTerror T1
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadWhileNodeIsDown T1
-
-max-time: 500
-cmd: testScan
-args: -n ScanRestart T1
-
-max-time: 500
-cmd: testScan
-args: -n ScanParallelism
-
-#
-# DICT TESTS
-max-time: 1500
-cmd: testDict
-args: -n CreateAndDrop
-
-max-time: 1500
-cmd: testDict
-args: -n CreateAndDropWithData
-
-max-time: 1500
-cmd: testDict
-args: -n CreateAndDropDuring T6 T10
-
-max-time: 1500
-cmd: testDict
-args: -n CreateInvalidTables
-
-max-time: 1500
-cmd: testDict
-args: -n CreateTableWhenDbIsFull T6
-
-max-time: 1500
-cmd: testDict
-args: -n CreateMaxTables T6
-
-max-time: 500
-cmd: testDict
-args: -n FragmentTypeSingle T1
-
-max-time: 1500
-cmd: testDict
-args: -n FragmentTypeAllSmall T1 T6 T7 T8
-
-max-time: 1500
-cmd: testDict
-args: -n FragmentTypeAllLarge T1 T6 T7 T8
-
-max-time: 1500
-cmd: testDict
-args: -n TemporaryTables T1 T6 T7 T8
-
-#
-# TEST NDBAPI
-#
-max-time: 500
-cmd: testDataBuffers
-args:
-
-# Testsuite: testNdbApi
-# Number of tests: 5
-max-time: 500
-cmd: testNdbApi
-args: -n MaxNdb T6
-
-max-time: 500
-cmd: testNdbApi
-args: -n MaxTransactions T1 T6 T7 T8 T13
-
-max-time: 500
-cmd: testNdbApi
-args: -n MaxOperations T1 T6 T7 T8 T13
-
-max-time: 500
-cmd: testNdbApi
-args: -n MaxGetValue T1 T6 T7 T8 T13
-
-max-time: 500
-cmd: testNdbApi
-args: -n MaxEqual
-
-max-time: 500
-cmd: testNdbApi
-args: -n DeleteNdb T1 T6
-
-max-time: 500
-cmd: testNdbApi
-args: -n WaitUntilReady T1 T6 T7 T8 T13
-
-max-time: 500
-cmd: testNdbApi
-args: -n GetOperationNoTab T6
-
-max-time: 500
-cmd: testNdbApi
-args: -n NdbErrorOperation T6
-
-max-time: 500
-cmd: testNdbApi
-args: -n MissingOperation T6
-
-max-time: 500
-cmd: testNdbApi
-args: -n GetValueInUpdate T6
-
-max-time: 500
-cmd: testNdbApi
-args: -n UpdateWithoutKeys T6
-
-max-time: 500
-cmd: testNdbApi
-args: -n UpdateWithoutValues T6
-
-#max-time: 500
-#cmd: testInterpreter
-#args: T1
-#
-max-time: 150000
-cmd: testOperations
-args:
-
-max-time: 15000
-cmd: testTransactions
-args:
-
-max-time: 1500
-cmd: testRestartGci
-args: T6
-
-max-time: 600
-cmd: testBlobs
-args:
-
-max-time: 5000
-cmd: testOIBasic
-args:
-
-max-time: 2500
-cmd: testBitfield
-args:
-
-max-time: 2500
-cmd: testPartitioning
-args:
-
-max-time: 25000
-cmd: atrt-mysql-test-run
-args: --force
-
-#
-# INDEX
-#
-max-time: 1500
-cmd: testIndex
-args: -n CreateAll T1 T6 T13
-
-#-m 7200 1: testIndex -n InsertDeleteGentle T7
-max-time: 3600
-cmd: testIndex
-args: -n InsertDelete T1 T10
-
-#-m 3600 1: testIndex -n CreateLoadDropGentle T7
-max-time: 3600
-cmd: testIndex
-args: -n CreateLoadDrop T1 T10
-
-#
-# BACKUP
-#
-max-time: 600
-cmd: atrt-testBackup
-args: -n BackupOne T1 T6 T3 I3
-
-#
-#
-# SYSTEM RESTARTS
-#
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR3 T6
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR4 T6
-
-#
-# NODE RESTARTS
-#
-max-time: 2500
-cmd: testNodeRestart
-args: -n NoLoad T6
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n MixedPkRead T6 T8 T13
-
-max-time: 2500
-cmd: testNodeRestart
-args: -l 1 -n MixedPkReadPkUpdate
-
-max-time: 2500
-cmd: testNodeRestart
-args: -l 1 -n MixedReadUpdateScan
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n CommittedRead T1
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n FullDb T6 T13
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n RestartRandomNode T6 T13
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n RestartRandomNodeError T6 T13
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n RestartRandomNodeInitial T6 T13
-
-max-time: 3600
-cmd: testNodeRestart
-args: -l 1 -n RestartNFDuringNR T6 T13
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n RestartMasterNodeError T6 T8 T13
-
-max-time: 3600
-cmd: testNodeRestart
-args: -n RestartNodeDuringLCP T6
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n TwoNodeFailure T6 T8 T13
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n TwoMasterNodeFailure T6 T8 T13
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n FiftyPercentFail T6 T8 T13
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n RestartAllNodes T6 T8 T13
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n RestartAllNodesAbort T6 T8 T13
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n RestartAllNodesError9999 T6 T8 T13
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n FiftyPercentStopAndWait T6 T8 T13
-
-#max-time: 500
-#cmd: testNodeRestart
-#args: -n StopOnError T1
-#
-#
-max-time: 2500
-cmd: testIndex
-args: -n NFNR1 T6 T13
-
-max-time: 2500
-cmd: testIndex
-args: -n NFNR2 T6 T13
-
-max-time: 2500
-cmd: testIndex
-args: -n NFNR3 T6 T13
-
-max-time: 2500
-cmd: testIndex
-args: -n BuildDuring T6
-
-max-time: 2500
-cmd: testIndex
-args: -l 2 -n SR1 T6 T13
-
-max-time: 2500
-cmd: testIndex
-args: -n NFNR1_O T6 T13
-
-max-time: 2500
-cmd: testIndex
-args: -n NFNR2_O T6 T13
-
-max-time: 2500
-cmd: testIndex
-args: -n NFNR3_O T6 T13
-
-max-time: 2500
-cmd: testIndex
-args: -n BuildDuring_O T6
-
-max-time: 2500
-cmd: testIndex
-args: -l 2 -n SR1_O T6 T13
-
-max-time: 500
-cmd: testIndex
-args: -n MixedTransaction T1
-
-max-time: 2500
-cmd: testDict
-args: -n NF1 T1 T6 T13
-
-#
-max-time: 1500
-cmd: testSystemRestart
-args: -l 1 -n SR6 T1
-
-max-time: 1500
-cmd: testSystemRestart
-args: -l 1 -n SR7 T1
-
-max-time: 1500
-cmd: testSystemRestart
-args: -l 1 -n SR8 T1
-
-max-time: 1500
-cmd: testSystemRestart
-args: -l 1 -n SR9 T1
-
-#
-max-time: 2500
-cmd: test_event
-args: -n BasicEventOperation T1 T6
-
-#
-#
-# SYSTEM RESTARTS
-#
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR1 T1
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR1 T6
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR1 T7
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR1 T8
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR2 T1
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR2 T6
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR2 T7
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_UNDO T1
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_UNDO T6
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_UNDO T7
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_UNDO T8
-
-# OLD FLEX
-max-time: 500
-cmd: flexBench
-args: -c 25 -t 10
-
-max-time: 500
-cmd: flexHammer
-args: -r 5 -t 32
-
diff --git a/storage/ndb/test/run-test/ATRT_SETUP_README.txt b/storage/ndb/test/run-test/ATRT_SETUP_README.txt
deleted file mode 100644
index adef464e5f6..00000000000
--- a/storage/ndb/test/run-test/ATRT_SETUP_README.txt
+++ /dev/null
@@ -1,292 +0,0 @@
-ATRT_SETUP_README.txt
-Author: Serge Kozlov, MySQL
-Date: 03/23/2006
-
-Contents
-
-1. Overview
-2. Setup
-3. Preparing for testing
-4. CPCD. Command line and configuration options
-5. d.tmp. Examples
-6. Test Case File format. Examples
-
-Note: how to run ATRT tests please look ATRT_USAGE_README.txt
-
-
- 1.Overview
- ==========
-
- Auto Test Run Test (ATRT) is a home made test frame work. This frame work can
-start and stop processes on different Linux hosts through another executable
-called Cluster Process Control Daemon (CPCD) running on the other hosts.
-It uses for testing cluster configurations located on different machines.
-ATRT isn't replacement for mysqltest. In fact, ATRT can invoke mysql-test as
-samples blow show. This framework has been designed to run most any test
-(mysqltest testcases, stress tests, any applications) in cluster and detects
-all errors and issues which happened in any node. In addition, ATRT starts
-applications that are defined as test with arguments and will analyze log files
-from all nodes that are produced.
-
-
- 2.Setup
- =======
-
- Following steps described how to setup ATRT framework on a cluster:
-* You need to have cloned source tree (e.g mysql-5.1-new) on machine where you
- plan to use ATRT.
-* Compile and install build (e.g. for Linux/x86 can use
- BUILD/compile-pentium-max --prefix=/path/to/installation).
-* Copy $MYSQL_DIR on all machines and on same path which you plan to use as
- nodes (you can use scp utility or ask JonathanMiller about distribution on
- ndbXX servers).
-* Compile and install ATRT:
- * Go to $TREE_ROOT/storage/ndb/test
- * do make
- * do make install
- * Make sure that $MYSQL_DIR/bin now contains files like that: testBasic,
- testBlobs, testDict and so on
- * Make sure that $MYSQL_DIR/mysql-test/ndb now contains files like that: atrt,
- atrt-analyze-result.sh, atrt-setup.sh, make-config.sh and so on
- * Add $MYSQL_DIR/mysql-test/ndb to PATH and make sure that you can call atrt
- from any place on disk.
-* Configure CPCD processes on all machines. Repeat following steps for each
- node:
- * Create $VAR_DIR/run/ndb_cpcd directory
- * Create /etc/ndb_cpcd.cnf file. It will configuration file ndb_cpcd daemon.
- It strongly recommended instead command line options because more simply.
- More option for configuration can fe found in this document in section CPCD
- * Add to file following text:
-
- [ndb_cpcd]
- work-dir= $VAR_DIR/run/ndb_cpcd # e.g. /mysql/builds/5.1/var/run/ndb_cpcd
- logfile= $VAR_DIR/run/ndb_cpcd/log.txt # e.g. /mysql/builds/5.1/var/run/ndb_cpcd/log.txt
- debug= 1
- user= ndbdev
-
- * Register ndb_cpcd in etc/initab. Hint: you can use more simply way if use
- Linux - add following line to /etc/rc.d/rc.local file
-
- $MYSQL_DIR/libexec/ndb_cpcd > /dev/null 2>&1 &
-
- * Start ndb_cpcd
-
- $MYSQL_DIR/libexec/ndb_cpcd > /dev/null 2>&1 &
-
- * Open log file and make sure that ndb_cpcd process started properly. Ususal mistakes are: wrong definition of paths and ndb_cpcd process already running. You can test ndb_cpcd from any ndb system by using the command line below. If nothing is returned the process is up and running. Otherwise you will see Failed to connect to node:1234:
-
- $MYSQL_DIR/libexec/ndb_cpcc node
-
-Now ATRT Setup done. After accomplishment all steps above you should be have
-following:
-* Each node contains fresh build
-* Each node has configured and started ndb_cpcd process.
-* The node that will used for starting ATRT has installed atrt binaries/scripts
- and some tests.
-
-
- 3.Preparing for testing
- =======================
-
-* Create new empty directory where you plan to use for testing. Note: if you
- plan to test different cluster configuration you need to create own directory
- for each cluster configuration. Do not use same directory.
-* Create d.tmp file for your cluster configuration. See details in this
- document in section d.tmp.
-* Run make-config.sh ./d.tmp. It will create necessary directories and files for
- ATRT.
-* Create ATRT testcase file(s) (e.g. test1.atrt). See details in this document
- in section Test Case File format. Examples.
-* Put your test application into $MYSQL_DIR/bin directory. If your application
- requires another directory (e.g. mysql-test-run.pl) create redirect script
- such as example below:
-
- #!/bin/sh
-
- set -x
- cd $MYSQL_BASE_DIR/mysql-test
- ./mysql-test-run.pl --with-ndbcluster --ndb-connectstring=$*
-
-Now preparing for testing done.
-
-
- 4.CPCD.
- =======
-
- The CPCD process needs to be running on each host contacts CPCD to tell it
-what process to execute. In other word for testing each node should have to
-running ndb_cpcd. Usually ndb_cpcd can be found in storage/ndb/src/cw/cpcd for
-source tree or in libexec/ndb_cpcd for binary distribution. ndb_cpcd uses
-configuration file /etc/ndb_cpcd.cnf but all options from one can be replaced
-by command line. Names of options in command line are same as from
-configuration file except some some commands have short notation (-X).
-
-ndb_cpcd command line options
-
--w, --work-dir=name
- Work directory. Should be exist before starting ndb_cpcd. Usually it's
- $VARDIR/run/ndb_cpcd
--p, --port=#
- TCP port to listen on. By default 1234
--S, --syslog
- Log events to syslog
--L, --logfile=name
- File to log events to. Usually it's $VARDIR/run/ndb_cpcd/logfile.txt
--D, --debug
- Enable debug mode.
--u, --user=name
- Run as user
-
-
- 5.d.tmp
- =======
-
- The d.tmp file is used to create the d.txt file (configuration file for ATRT)
-and the config.ini file (configuration file for MySQL Cluster). This file does
-not have to be called d.tmp, it can be called by any name. The file will be feed
-to make-config.sh. All options in the file separated by two parts:
-* Original options. They are located before '-- cluster config'. Description of
-all these options are below.
-* Options for config.ini. They are located after '-- cluster config'. All
-options, sections and values completely coincide with config.ini.
-
-d.tmp options
-
-baseport
- Port used for communicating to the cluster on.
-basedir
- basedir has to point to the root of the mysql install. Note that ATRT will
- create a run directory under the base directory. All test directories and
- files created will be copied to all hosts in the test under the basedir/run directory.
-mgm
- Host to NDB Cluster manager on. Put hostnames separated by blanks.
-ndb
- Host(s) to run NDB Data Nodes on. Put hostnames separated by blanks.
-api
- Host(s) that NDB API should be ran on. Put hostnames separated by blanks.
-mysqld
- Host(s) that mysqld processes should be started on. Put hostnames separated by blanks.
-mysql
- Host(s) that mysql processes should be started on. Put hostnames separated
- by blanks.
-
-Example d.tmp for cluster configuration: 1 ndb node, 1 replica, 1 mgm, 1 api,
-1 mysql, 1 mysqld. Available hosts for nodes: ndb16, ndb17
-
-baseport: 14000
-basedir: /home/ndbdev/skozlov/builds
-mgm: ndb16
-ndb: ndb17
-api: ndb16
-mysqld ndb16
-mysql ndb16
--- cluster config
-[DB DEFAULT]
-NoOfReplicas: 1
-
-[MGM DEFAULT]
-PortNumber: 14000
-ArbitrationRank: 1
-
-Example d.tmp for cluster configuration: 2 ndb nodes, 2 replicas, 1 mgm, 1 api,
-1 mysql, 1 mysqld. Available hosts for nodes: ndb16, ndb17, ndb18
-
-baseport: 14000
-basedir: /home/ndbdev/skozlov/builds
-mgm: ndb16
-ndb: ndb17 ndb18
-api: ndb16
-mysqld ndb16
-mysql ndb16
--- cluster config
-[DB DEFAULT]
-NoOfReplicas: 2
-
-[MGM DEFAULT]
-PortNumber: 14000
-ArbitrationRank: 1
-
-Example d.tmp for cluster configuration: 4 ndb nodes, 4 replicas, 1 mgm, 3 api,
-2 mysql, 1 mysqld. Available hosts for nodes: ndb14, ndb15, ndb16, ndb17, ndb18
-
-baseport: 14000
-basedir: /home/ndbdev/skozlov/builds
-mgm: ndb16
-ndb: ndb17 ndb18 ndb15 ndb14
-api: ndb16 ndb17 ndb18
-mysqld ndb16
-mysql ndb16 ndb17
--- cluster config
-[DB DEFAULT]
-NoOfReplicas: 4
-
-[MGM DEFAULT]
-PortNumber: 14000
-ArbitrationRank: 1
-
-
- 6.Test Case File Format. Examples.
- ==================================
-
- A test file consists of a list of test cases. Each test case is ended by an
-empty/blank line. Each test case is described by a set of name value pairs.
-ATRT looks for tests executables, shell and Perl scripts in the basedir/bin
-directory.
-
-Test Case File options:
-
-max-time
- This value is in seconds. Test ATRT how long to allow the test to run before
- marking the test a failure and moving on to the next test. If the test
- finishes before max-time, it will move on to the next test.
-cmd
- Tells ATRT which test or script to run from the bin directory
-args
- These are the command-line arguments to be passed to the test or script
- that is being executed.
-type
- Currently only bench. See ATRT Command-line parameters for details.
-run-all
- will start the same command for each defined api/mysql (normally it only
- started in 1 instance)
-
-Example 1.
-ATRT starts test $MYSQL_DIR/bin/testBlobs without arguments and sets time for
-execution as 10 min. testBlobs is binary application
-
-max-time: 600
-cmd: testBlobs
-args:
-
-Example 2.
-ATRT starts test $MYSQL_DIR/bin/testRead -n PkRead and sets time for execution
-as 20 min. testRead is binary application
-
-max-time: 1200
-cmd: testRead
-args: -n PkRead
-
-Example 3.
-ATRT starts test $MYSQL_DIR/bin/atrt-mysql-test-run -force and sets time for
-execution as one hour. atrt-mysql-test-run is bash script and it points to
-$MYSQL_DIR/mysql-test/mysql-test-run. In fact this test will start
-mysql-test-run --force that means the execution all mysqltest testcases in
-mysql-test/t directory.
-
-max-time: 3600
-cmd: atrt-mysql-test-run
-args: --force
-
-Example 4.
-ATRT starts test $MYSQL_DIR/bin/MyTest1 -n and sets time for execution as 2 min.
-Then starts $MYSQL_DIR/bin/MyTest2 for each defined mysql/api node and set
-timeout 3 min.
-
-max-time: 120
-cmd: MyTest1
-args: -n
-
-max-time: 180
-cmd: MyTest2
-run-all: yes
-
diff --git a/storage/ndb/test/run-test/ATRT_USAGE_README.txt b/storage/ndb/test/run-test/ATRT_USAGE_README.txt
deleted file mode 100644
index b745a735761..00000000000
--- a/storage/ndb/test/run-test/ATRT_USAGE_README.txt
+++ /dev/null
@@ -1,224 +0,0 @@
-ATRT_USAGE_README.txt
-Author: Serge Kozlov, MySQL
-Date: 03/23/2006
-
-Contents
-
-1. How to run
-2. Results
-3. ATRT Command Line Options
-
-Note: how to setup ATRT please look ATRT_SETUP_README.txt
-
- 1.How to run.
- =============
-
-Simple way to start atrt:
-
- atrt --testcase-file=atrt_test_case_file
-
-Command line above doesn't produce any log files. Better use following :
-
- atrt --log-file=log.txt --testcase-file=atrt_test_case_file
-
-Now we can look log.txt for investigation any issues. If it is insufficiently
-then add one or more -v arguments:
-
- atrt -v -v --log-file=log.txt --testcase-file=atrt_test_case_file
-
-If the test case file contains two or more test we can add -r options for
-preventing stopping testing if one test fails (like --force for mysql-test-run)
-
- atrt -v -v -r --log-file=log.txt --testcase-file=atrt_test_case_file
-
-The line below is optimal solution for testing:
-
- atrt -v -v -r -R --log-file=log.txt --testcase-file=atrt_test_case_file
-
-All additional command line arguments and description of used in exampes above
-available in this document in section atrt command line options
-
- 2.Results.
- ==========
-
- Unlike mysql-test-run frame work atrt doesn't inform to console passed/failed
-status of tests. You need to use --log-file option and look into log file for
-getting information about status of tests. When atrt finished you can look into
-log file defined --log-file option. It's main source of information about how
-were performed atrt tests. Below added the examples of content of log-file for
-different failures (except example 1 for passed test). Examples include
-probable cases with reasons and recommended solutions and cover not test issues
-only but mistakes of atrt configuration or cluster settings. As ATRT testcase
-file used simple test included in MySQL installation:
-
- max-time: 600
- cmd: testBasic
- args: -n PkRead? T1
-
-
-Of course these examples don't cover all possible failures but at least most
-probable and often appearing.
-Note: Before start atrt I recommend try to run selected cluster configuration
-by manual and make sure that it can work: enough to run mgmd, ndbd, mysqld and
-look via mgm to status of these nodes
-
-Example 1. Test passed
-
-2006-03-02 15:36:51 [ndb_atrt] INFO -- Setup path not specified, using /home/ndbdev/skozlov/asetup
-2006-03-02 15:36:51 [ndb_atrt] INFO -- Starting...
-2006-03-02 15:36:51 [ndb_atrt] INFO -- Connecting to hosts
-2006-03-02 15:36:51 [ndb_atrt] DEBUG -- Connected to node1:1234
-2006-03-02 15:36:51 [ndb_atrt] DEBUG -- Connected to node2:1234
-2006-03-02 15:36:51 [ndb_atrt] DEBUG -- Connected to node3:1234
-2006-03-02 15:36:55 [ndb_atrt] INFO -- (Re)starting ndb processes
-2006-03-02 15:37:11 [ndb_atrt] INFO -- Ndb start completed
-2006-03-02 15:37:11 [ndb_atrt] INFO -- #1 - testBasic -n PkRead? T1
-2006-03-02 16:37:16 [ndb_atrt] INFO -- #1 OK (0)
-
-Example 2. Test failed.
-Reason: ATRT not started properly. d.txt not found. Probably necessary folders
-and d.txt file don't exist.
-Solution: run make-config.sh d.tmp and try again.
-
-2006-03-02 18:32:08 [ndb_atrt] INFO -- Setup path not specified, using /home/ndbdev/skozlov/asetup
-2006-03-02 18:32:08 [ndb_atrt] INFO -- Starting...
-2006-03-02 18:32:08 [ndb_atrt] CRITICAL -- Failed to open process config file: d.txt
-
-Example 3. Test failed.
-Reason: ATRT not started properly. Necessary folders were removed but d.txt file
-exists.
-Solution: run make-config.sh d.tmp and try again.
-
-2006-03-02 18:30:54 [ndb_atrt] INFO -- Setup path not specified, using /home/ndbdev/skozlov/asetup
-2006-03-02 18:30:54 [ndb_atrt] INFO -- Starting...
-2006-03-02 18:30:54 [ndb_atrt] INFO -- Connecting to hosts
-2006-03-02 18:30:54 [ndb_atrt] DEBUG -- Connected to node1:1234
-2006-03-02 18:30:54 [ndb_atrt] DEBUG -- Connected to node2:1234
-2006-03-02 18:30:54 [ndb_atrt] DEBUG -- Connected to node3:1234
-2006-03-02 18:30:58 [ndb_atrt] INFO -- (Re)starting ndb processes
-2006-03-02 18:31:00 [ndb_atrt] CRITICAL -- Failed to setup process
-
-Example 4. Test failed.
-Reason: ATRT not started properly. node2 hasn't running ndb_cpcd process.
-Solution: log into node2 and starts ndb_cpcd process.
-
-2006-03-02 18:15:05 [ndb_atrt] INFO -- Setup path not specified, using /home/ndbdev/skozlov/asetup
-2006-03-02 18:15:05 [ndb_atrt] INFO -- Starting...
-2006-03-02 18:15:05 [ndb_atrt] INFO -- Connecting to hosts
-2006-03-02 18:15:05 [ndb_atrt] DEBUG -- Connected to node1:1234
-2006-03-02 18:15:05 [ndb_atrt] ERROR -- Unable to connect to cpc node2:1234
-
-Example 5. Test failed.
-Reason: ATRT not started properly. baseport option isn't defined in d.tmp or
-baseport and PortNumber are different.
-Solution: correct d.tmp, run make-config.sh d.tmp and try again.
-
-2006-03-02 18:25:31 [ndb_atrt] INFO -- Setup path not specified, using /home/ndbdev/skozlov/asetup
-2006-03-02 18:25:31 [ndb_atrt] INFO -- Starting...
-2006-03-02 18:25:31 [ndb_atrt] INFO -- Connecting to hosts
-2006-03-02 18:25:31 [ndb_atrt] DEBUG -- Connected to node1:1234
-2006-03-02 18:25:31 [ndb_atrt] DEBUG -- Connected to node2:1234
-2006-03-02 18:25:31 [ndb_atrt] DEBUG -- Connected to node3:1234
-2006-03-02 18:25:36 [ndb_atrt] INFO -- (Re)starting ndb processes
-2006-03-02 18:26:08 [ndb_atrt] CRITICAL -- Unable to connect to ndb mgm node1:0
-
-Example 6. Test failed.
-Reason: ATRT not started properly. basedir option points to wrong path.
-Solution: correct basedir, run make-config.sh d.tmp and try again.
-
-2006-03-02 18:40:10 [ndb_atrt] INFO -- Setup path not specified, using /home/ndbdev/skozlov/asetup
-2006-03-02 18:40:10 [ndb_atrt] INFO -- Starting...
-2006-03-02 18:40:10 [ndb_atrt] INFO -- Connecting to hosts
-2006-03-02 18:40:10 [ndb_atrt] DEBUG -- Connected to node1:1234
-2006-03-02 18:40:10 [ndb_atrt] DEBUG -- Connected to node2:1234
-2006-03-02 18:40:10 [ndb_atrt] DEBUG -- Connected to node3:1234
-2006-03-02 18:40:14 [ndb_atrt] INFO -- (Re)starting ndb processes
-2006-03-02 18:40:16 [ndb_atrt] ERROR -- Unable to start process: Failed to start
-
-Example 7. Test failed.
-Reason: ndb nodes have problems on starting.
-Solution: Check configuration of ndb nodes.
-
-2006-03-02 18:46:44 [ndb_atrt] INFO -- Setup path not specified, using /home/ndbdev/skozlov/asetup
-2006-03-02 18:46:44 [ndb_atrt] INFO -- Starting...
-2006-03-02 18:46:44 [ndb_atrt] INFO -- Connecting to hosts
-2006-03-02 18:46:44 [ndb_atrt] DEBUG -- Connected to node1:1234
-2006-03-02 18:46:44 [ndb_atrt] DEBUG -- Connected to node2:1234
-2006-03-02 18:46:44 [ndb_atrt] DEBUG -- Connected to node3:1234
-2006-03-02 18:46:50 [ndb_atrt] INFO -- (Re)starting ndb processes
-2006-03-02 18:52:59 [ndb_atrt] CRITICAL -- wait ndb timed out 3 3 4
-2006-03-02 18:58:59 [ndb_atrt] CRITICAL -- wait ndb timed out 3 3 4
-
-Example 8. Test failed.
-Reason: test application not found.
-Solution: Correct file name in ATRT test case file and make sure that the file
-exists in $MYSQL_DIR/bin directory.
-
-2006-03-02 20:21:54 [ndb_atrt] INFO -- Starting...
-2006-03-02 20:21:54 [ndb_atrt] INFO -- Connecting to hosts
-2006-03-02 20:21:54 [ndb_atrt] DEBUG -- Connected to node1:1234
-2006-03-02 20:21:54 [ndb_atrt] DEBUG -- Connected to node2:1234
-2006-03-02 20:21:54 [ndb_atrt] DEBUG -- Connected to node3:1234
-2006-03-02 20:21:57 [ndb_atrt] INFO -- (Re)starting ndb processes
-2006-03-02 20:22:12 [ndb_atrt] INFO -- Ndb start completed
-2006-03-02 20:22:12 [ndb_atrt] INFO -- #1 - testBasic123 -n PkRead? T2
-2006-03-02 20:22:13 [ndb_atrt] ERROR -- Unable to start process: Failed to start
-
-Example 9. Test failed.
-Probable reasons:
-* wrong arguments for test application
-* itself test failed
-* timeout reached
-Solution: Since mgmd/ndbd nodes started properly in such case then try to
-investigate log files in result/X.api/, result/X.mysqld, result/X.mysql
-directories.
-
-2006-03-02 19:59:35 [ndb_atrt] INFO -- Setup path not specified, using /home/ndbdev/skozlov/asetup
-2006-03-02 19:59:35 [ndb_atrt] INFO -- Starting...
-2006-03-02 19:59:35 [ndb_atrt] INFO -- Connecting to hosts
-2006-03-02 19:59:35 [ndb_atrt] DEBUG -- Connected to node1:1234
-2006-03-02 19:59:35 [ndb_atrt] DEBUG -- Connected to node2:1234
-2006-03-02 19:59:35 [ndb_atrt] DEBUG -- Connected to node3:1234
-2006-03-02 20:00:49 [ndb_atrt] INFO -- (Re)starting ndb processes
-2006-03-02 20:01:05 [ndb_atrt] INFO -- Ndb start completed
-2006-03-02 20:01:05 [ndb_atrt] INFO -- #1 - testBasic -n PkRead? T1
-2006-03-02 20:01:38 [ndb_atrt] INFO -- #1 FAILED(256)
-
-
- 3.ATRT Command Line Options.
- ============================
-
---process-config=string
- Specify ATRT configuration file. If not specified, ATRT will look in local
- directory for the d.txt file.
-
---setup-path=string
- This path points to place where necessary directories (created by
- make-config) can be found. Note: d.txt should be in same directory where
- you start atrt!
-
--v (verbose)
-
- * without the option: atrt prints only [CRITICAL] events
- * one -v: atrt prints [CRITICAL], [INFO] events
- * two -v: atrt prints [CRITICAL], [INFO], [DEBUG] events
-
---log-file=string
- Used to specify file to log ATRT's results on starting application and
- running tests.
-
---testcase-file=string -f
- Used to feed ATRT test cases in a text file.
-
---report-file=string
- File to record test results
-
--i, --interactive
- ATRT terminates on first test failure
-
--r, --regression
- Continues even on test failures
-
--b, --bench
- Always produce report
-
diff --git a/storage/ndb/test/run-test/Makefile.am b/storage/ndb/test/run-test/Makefile.am
deleted file mode 100644
index de3896bf79c..00000000000
--- a/storage/ndb/test/run-test/Makefile.am
+++ /dev/null
@@ -1,55 +0,0 @@
-# Copyright (C) 2004-2006 MySQL AB
-# Use is subject to license terms
-#
-# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-testroot=$(prefix)
-testdir=$(testroot)/mysql-test/ndb
-
-include $(top_srcdir)/storage/ndb/config/common.mk.am
-include $(top_srcdir)/storage/ndb/config/type_util.mk.am
-include $(top_srcdir)/storage/ndb/config/type_mgmapiclient.mk.am
-include $(top_srcdir)/storage/ndb/config/type_ndbapitools.mk.am
-
-test_PROGRAMS = atrt
-test_DATA=daily-basic-tests.txt daily-devel-tests.txt 16node-tests.txt \
- conf-ndbmaster.cnf \
- conf-dl145a.cnf test-tests.txt conf-test.cnf
-
-test_SCRIPTS=atrt-analyze-result.sh atrt-gather-result.sh atrt-setup.sh \
- atrt-clear-result.sh autotest-run.sh
-
-atrt_SOURCES = main.cpp setup.cpp files.cpp
-
-INCLUDES_LOC = -I$(top_srcdir)/storage/ndb/test/include
-LDADD_LOC = $(top_builddir)/storage/ndb/test/src/libNDBT.a \
- $(top_builddir)/storage/ndb/src/libndbclient.la \
- $(top_builddir)/dbug/libdbug.a \
- $(top_builddir)/mysys/libmysys.a \
- $(top_builddir)/strings/libmystrings.a @NDB_SCI_LIBS@
-
-atrt_CXXFLAGS = -I$(top_srcdir)/ndb/src/mgmapi \
- -I$(top_srcdir)/ndb/src/mgmsrv \
- -I$(top_srcdir)/ndb/include/mgmcommon \
- -DMYSQLCLUSTERDIR="\"\"" \
- -DDEFAULT_PREFIX="\"$(prefix)\""
-
-atrt_LDFLAGS = -static @ndb_bin_am_ldflags@
-
-wrappersdir=$(prefix)/bin
-wrappers_SCRIPTS=atrt-testBackup atrt-mysql-test-run
-
-EXTRA_DIST = $(test_DATA) $(test_SCRIPTS) $(wrappers_SCRIPTS) README.ATRT atrt.hpp
-
-windoze-dsp:
diff --git a/storage/ndb/test/run-test/README b/storage/ndb/test/run-test/README
deleted file mode 100644
index 57f085711ce..00000000000
--- a/storage/ndb/test/run-test/README
+++ /dev/null
@@ -1,43 +0,0 @@
-run-test/README
-
-This document describes how atrt works and how to use it.
-
-atrt is a test program driver.
-atrt supports fully distributed test and utilizes ndb_cpcd.
-
-=================================
-atrt has the following main loop:
-
-/**
- * Pseudo code for atrt
- */
- read config file (default d.txt)
- contact each ndb_cpcd
- start each ndb_mgmd
- connect to each ndb_mgmd
- for each read(test case)
- do
- if previous test failed (or is first test)
- stop each ndbd
- start each ndbd
- wait for ndbd to get started
-
- start each mysqld
-
- start each test prg
-
- wait while all is running and max time not elapsed
-
- stop each mysqld
-
- stop each test prg
-
- gather result
-
- done
-/**
- * End of pseudo code
- */
-
-=================================
-
diff --git a/storage/ndb/test/run-test/README.ATRT b/storage/ndb/test/run-test/README.ATRT
deleted file mode 100644
index 7fe04ccdac4..00000000000
--- a/storage/ndb/test/run-test/README.ATRT
+++ /dev/null
@@ -1,34 +0,0 @@
-
-!-- install ndb_cpcd
-!-- many steps? future RPM
-
-!-- deploy binaries and libraries to hosts, rsync
-% export DEPLOY_DST="mc05:/space/tomas/keso"
-% ssh mc05 mkdir /space/tomas/keso
-% export RSYNC_RSH=ssh
-% make
-
-% mkdir -p /tmp/atrt-run-2-node
-% cd /tmp/atrt-run-2-node
-% cat > d.txt
-baseport: 9321
-basedir: /space/tomas/keso
-mgm: localhost
-ndb: localhost localhost
-api: localhost
-% cat > default.txt
-[DB DEFAULT]
-NoOfReplicas: 2
-% bin/make-config.sh -m d.txt -t default.txt -d .
-
-% atrt -v -v
-test_event -r 5 T1
-
-
-!-- check output
-% tail -f /space/tomas/keso/run/4.ndb_api/log.out
-
-
-!-- check processes
-% export NDB_CPCC_HOSTS="mc05"
-% ndb_cpcc
diff --git a/storage/ndb/test/run-test/atrt-analyze-result.sh b/storage/ndb/test/run-test/atrt-analyze-result.sh
deleted file mode 100755
index 87f5e622b5e..00000000000
--- a/storage/ndb/test/run-test/atrt-analyze-result.sh
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/sh
-
-# Copyright (c) 2004, 2005 MySQL AB
-# Use is subject to license terms
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Library 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
-# Library General Public License for more details.
-#
-# You should have received a copy of the GNU Library General Public
-# License along with this library; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301, USA
-
-f=`find result -name 'log.out' | xargs grep "NDBT_ProgramExit: " | grep -c "Failed"`
-o=`find result -name 'log.out' | xargs grep "NDBT_ProgramExit: " | grep -c "OK"`
-
-if [ $o -gt 0 -a $f -eq 0 ]
-then
- exit 0
-fi
-
-exit 1
-
diff --git a/storage/ndb/test/run-test/atrt-clear-result.sh b/storage/ndb/test/run-test/atrt-clear-result.sh
deleted file mode 100755
index f4cb3b22d13..00000000000
--- a/storage/ndb/test/run-test/atrt-clear-result.sh
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/sh
-
-# Copyright (c) 2004, 2005 MySQL AB
-# Use is subject to license terms
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Library 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
-# Library General Public License for more details.
-#
-# You should have received a copy of the GNU Library General Public
-# License along with this library; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301, USA
-
-set -e
-rm -rf result
diff --git a/storage/ndb/test/run-test/atrt-example.tgz b/storage/ndb/test/run-test/atrt-example.tgz
deleted file mode 100644
index 8455b2eb00d..00000000000
--- a/storage/ndb/test/run-test/atrt-example.tgz
+++ /dev/null
Binary files differ
diff --git a/storage/ndb/test/run-test/atrt-gather-result.sh b/storage/ndb/test/run-test/atrt-gather-result.sh
deleted file mode 100755
index acc58bcbca3..00000000000
--- a/storage/ndb/test/run-test/atrt-gather-result.sh
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/bin/sh
-
-# Copyright (c) 2004, 2005, 2007 MySQL AB
-# Use is subject to license terms
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Library 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
-# Library General Public License for more details.
-#
-# You should have received a copy of the GNU Library General Public
-# License along with this library; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301, USA
-
-set -e
-
-mkdir -p result
-cd result
-rm -rf *
-
-while [ $# -gt 0 ]
-do
- rsync -a --exclude='BACKUP' --exclude='ndb_*_fs' "$1" .
- shift
-done
-
-
-
diff --git a/storage/ndb/test/run-test/atrt-mysql-test-run b/storage/ndb/test/run-test/atrt-mysql-test-run
deleted file mode 100755
index 518f2a417e8..00000000000
--- a/storage/ndb/test/run-test/atrt-mysql-test-run
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/sh
-
-# Copyright (C) 2004, 2005 MySQL AB
-# Use is subject to license terms
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Library 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
-# Library General Public License for more details.
-#
-# You should have received a copy of the GNU Library General Public
-# License along with this library; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301, USA
-
-set -x
-p=`pwd`
-cd $MYSQL_BASE_DIR/mysql-test
-./mysql-test-run --with-ndbcluster --ndb-connectstring=$NDB_CONNECTSTRING $* | tee $p/output.txt
-
-f=`grep -c '\[ fail \]' $p/output.txt`
-o=`grep -c '\[ pass \]' $p/output.txt`
-
-if [ $o -gt 0 -a $f -eq 0 ]
-then
- echo "NDBT_ProgramExit: OK"
- exit 0
-fi
-
-echo "NDBT_ProgramExit: Failed"
-exit 1
diff --git a/storage/ndb/test/run-test/atrt-setup.sh b/storage/ndb/test/run-test/atrt-setup.sh
deleted file mode 100755
index d419022fd25..00000000000
--- a/storage/ndb/test/run-test/atrt-setup.sh
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/sh
-
-# Copyright (c) 2004, 2005 MySQL AB
-# Use is subject to license terms
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Library 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
-# Library General Public License for more details.
-#
-# You should have received a copy of the GNU Library General Public
-# License along with this library; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301, USA
-
-set -e
-
-ssh $1 mkdir -p $3
-rsync -a --delete --force --ignore-errors $2 $1:$3
diff --git a/storage/ndb/test/run-test/atrt-testBackup b/storage/ndb/test/run-test/atrt-testBackup
deleted file mode 100755
index b756c98e7df..00000000000
--- a/storage/ndb/test/run-test/atrt-testBackup
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/sh
-
-# Copyright (c) 2004, 2005 MySQL AB
-# Use is subject to license terms
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Library 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
-# Library General Public License for more details.
-#
-# You should have received a copy of the GNU Library General Public
-# License along with this library; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301, USA
-
-PATH=$PATH:$MYSQL_BASE_DIR/bin
-export PATH
-
-testBackup $*
diff --git a/storage/ndb/test/run-test/atrt.hpp b/storage/ndb/test/run-test/atrt.hpp
deleted file mode 100644
index a6dd75b460e..00000000000
--- a/storage/ndb/test/run-test/atrt.hpp
+++ /dev/null
@@ -1,161 +0,0 @@
-/* Copyright (c) 2003-2005, 2007 MySQL AB, 2008 Sun Microsystems, Inc.
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#ifndef atrt_config_hpp
-#define atrt_config_hpp
-
-#include <ndb_global.h>
-#include <Vector.hpp>
-#include <BaseString.hpp>
-#include <Logger.hpp>
-#include <mgmapi.h>
-#include <CpcClient.hpp>
-#include <Properties.hpp>
-
-enum ErrorCodes
-{
- ERR_OK = 0,
- ERR_NDB_FAILED = 101,
- ERR_SERVERS_FAILED = 102,
- ERR_MAX_TIME_ELAPSED = 103
-};
-
-struct atrt_host
-{
- size_t m_index;
- BaseString m_user;
- BaseString m_basedir;
- BaseString m_hostname;
- SimpleCpcClient * m_cpcd;
- Vector<struct atrt_process*> m_processes;
-};
-
-struct atrt_options
-{
- enum Feature {
- AO_REPLICATION = 1,
- AO_NDBCLUSTER = 2
- };
-
- int m_features;
- Properties m_loaded;
- Properties m_generated;
-};
-
-struct atrt_process
-{
- size_t m_index;
- struct atrt_host * m_host;
- struct atrt_cluster * m_cluster;
-
- enum Type {
- AP_ALL = 255
- ,AP_NDBD = 1
- ,AP_NDB_API = 2
- ,AP_NDB_MGMD = 4
- ,AP_MYSQLD = 16
- ,AP_CLIENT = 32
- ,AP_CLUSTER = 256 // Used for options parsing for "cluster" options
- } m_type;
-
- SimpleCpcClient::Process m_proc;
-
- NdbMgmHandle m_ndb_mgm_handle; // if type == ndb_mgm
- atrt_process * m_mysqld; // if type == client
- atrt_process * m_rep_src; // if type == mysqld
- Vector<atrt_process*> m_rep_dst; // if type == mysqld
-
- atrt_options m_options;
-};
-
-struct atrt_cluster
-{
- BaseString m_name;
- BaseString m_dir;
- Vector<atrt_process*> m_processes;
- atrt_options m_options;
-};
-
-struct atrt_config
-{
- bool m_generated;
- BaseString m_key;
- BaseString m_replication;
- Vector<atrt_host*> m_hosts;
- Vector<atrt_cluster*> m_clusters;
- Vector<atrt_process*> m_processes;
-};
-
-struct atrt_testcase
-{
- bool m_report;
- bool m_run_all;
- time_t m_max_time;
- BaseString m_command;
- BaseString m_args;
- BaseString m_name;
-};
-
-extern Logger g_logger;
-
-void require(bool x);
-bool parse_args(int argc, char** argv);
-bool setup_config(atrt_config&);
-bool configure(atrt_config&, int setup);
-bool setup_directories(atrt_config&, int setup);
-bool setup_files(atrt_config&, int setup, int sshx);
-
-bool deploy(atrt_config&);
-bool sshx(atrt_config&, unsigned procmask);
-bool start(atrt_config&, unsigned procmask);
-
-bool remove_dir(const char *, bool incl = true);
-bool connect_hosts(atrt_config&);
-bool connect_ndb_mgm(atrt_config&);
-bool wait_ndb(atrt_config&, int ndb_mgm_node_status);
-bool start_processes(atrt_config&, int);
-bool stop_processes(atrt_config&, int);
-bool update_status(atrt_config&, int);
-int is_running(atrt_config&, int);
-bool gather_result(atrt_config&, int * result);
-
-bool read_test_case(FILE *, atrt_testcase&, int& line);
-bool setup_test_case(atrt_config&, const atrt_testcase&);
-
-bool setup_hosts(atrt_config&);
-
-/**
- * Global variables...
- */
-extern Logger g_logger;
-extern atrt_config g_config;
-
-extern const char * g_cwd;
-extern const char * g_my_cnf;
-extern const char * g_user;
-extern const char * g_basedir;
-extern const char * g_prefix;
-extern int g_baseport;
-extern int g_fqpn;
-extern int g_default_ports;
-
-extern const char * g_clusters;
-
-extern const char *save_file;
-extern const char *save_group_suffix;
-extern char *save_extra_file;
-
-#endif
diff --git a/storage/ndb/test/run-test/autotest-boot.sh b/storage/ndb/test/run-test/autotest-boot.sh
deleted file mode 100644
index f1f8aea2519..00000000000
--- a/storage/ndb/test/run-test/autotest-boot.sh
+++ /dev/null
@@ -1,205 +0,0 @@
-#!/bin/sh
-
-# Copyright (c) 2007 MySQL AB
-# Use is subject to license terms.
-#
-# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-#############################################################
-# This script created by Jonas does the following #
-# Cleans up clones and pevious builds, pulls new clones, #
-# builds, deploys, configures the tests and launches ATRT #
-#############################################################
-
-###############
-#Script setup #
-##############
-
-save_args=$*
-VERSION="autotest-boot.sh version 1.00"
-
-DATE=`date '+%Y-%m-%d'`
-HOST=`hostname -s`
-export DATE HOST
-
-set -e
-
-echo "`date` starting: $*"
-
-verbose=0
-do_clone=yes
-build=yes
-
-tag=
-conf=
-extra_args=
-extra_clone=
-LOCK=$HOME/.autotest-lock
-
-############################
-# Read command line entries#
-############################
-
-while [ "$1" ]
-do
- case "$1" in
- --no-clone) do_clone="";;
- --no-build) build="";;
- --verbose) verbose=`expr $verbose + 1`;;
- --clone=*) clone=`echo $1 | sed s/--clone=//`;;
- --version) echo $VERSION; exit;;
- --conf=*) conf=`echo $1 | sed s/--conf=//`;;
- --tag=*) tag=`echo $1 | sed s/--tag=//`;;
- --*) echo "Unknown arg: $1";;
- *) RUN=$*;;
- esac
- shift
-done
-
-#################################
-#Make sure the configfile exists#
-#if it does not exit. if it does#
-# (.) load it #
-#################################
-if [ -z "$conf" ]
-then
- if [ -f "`pwd`/autotest.conf" ]
- then
- conf="`pwd`/autotest.conf"
- elif [ -f "$HOME/autotest.conf" ]
- then
- conf="$HOME/autotest.conf"
- fi
-fi
-
-if [ -f $conf ]
-then
- . $conf
-else
- echo "Can't find config file: >$conf<"
- exit
-fi
-
-###############################
-# Validate that all interesting
-# variables where set in conf
-###############################
-vars="src_clone_base install_dir build_dir"
-for i in $vars
-do
- t=`echo echo \\$$i`
- if [ -z "`eval $t`" ]
- then
- echo "Invalid config: $conf, variable $i is not set"
- exit
- fi
-done
-
-###############################
-#Print out the enviroment vars#
-###############################
-
-if [ $verbose -gt 0 ]
-then
- env
-fi
-
-####################################
-# Setup the lock file name and path#
-# Setup the clone source location #
-####################################
-
-src_clone=${src_clone_base}${clone}
-
-#######################################
-# Check to see if the lock file exists#
-# If it does exit. #
-#######################################
-
-if [ -f $LOCK ]
-then
- echo "Lock file exists: $LOCK"
- exit 1
-fi
-
-#######################################
-# If the lock file does not exist then#
-# create it with date and run info #
-#######################################
-
-echo "$DATE $RUN" > $LOCK
-
-#############################
-#If any errors here down, we#
-# trap them, and remove the #
-# Lock file before exit #
-#############################
-if [ `uname -s` != "SunOS" ]
-then
- trap "rm -f $LOCK" ERR
-fi
-
-# You can add more to this path#
-################################
-
-if [ -z "$tag" ]
-then
- dst_place=${build_dir}/clone-$clone-$DATE.$$
-else
- dst_place=${build_dir}/clone-$tag-$DATE.$$
- extra_args="$extra_args --clone=$tag"
- extra_clone="-r$tag"
-fi
-
-#########################################
-# Delete source and pull down the latest#
-#########################################
-
-if [ "$do_clone" ]
-then
- rm -rf $dst_place
- if [ `echo $src_clone | grep -c 'file:\/\/'` = 1 ]
- then
- bk clone -l $extra_clone $src_clone $dst_place
- else
- bk clone $extra_clone $src_clone $dst_place
- fi
-fi
-
-##########################################
-# Build the source, make installs, and #
-# create the database to be rsynced #
-##########################################
-
-if [ "$build" ]
-then
- cd $dst_place
- rm -rf $install_dir
- BUILD/compile-ndb-autotest --prefix=$install_dir
- make install
-fi
-
-
-################################
-# Start run script #
-################################
-
-script=$install_dir/mysql-test/ndb/autotest-run.sh
-sh -x $script $save_args --conf=$conf --install-dir=$install_dir --suite=$RUN --nolock $extra_args
-
-if [ "$build" ]
-then
- rm -rf $dst_place
-fi
-rm -f $LOCK
diff --git a/storage/ndb/test/run-test/autotest-run.sh b/storage/ndb/test/run-test/autotest-run.sh
deleted file mode 100644
index 0c9c6aee215..00000000000
--- a/storage/ndb/test/run-test/autotest-run.sh
+++ /dev/null
@@ -1,287 +0,0 @@
-#!/bin/sh
-
-# Copyright (c) 2007 MySQL AB
-# Use is subject to license terms.
-#
-# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-#############################################################
-# This script created by Jonas does the following #
-# Cleans up clones and pevious builds, pulls new clones, #
-# builds, deploys, configures the tests and launches ATRT #
-#############################################################
-
-###############
-#Script setup #
-##############
-
-save_args=$*
-VERSION="autotest-run.sh version 1.00"
-
-DATE=`date '+%Y-%m-%d'`
-HOST=`hostname -s`
-export DATE HOST
-
-set -e
-ulimit -Sc unlimited
-
-echo "`date` starting: $*"
-
-RSYNC_RSH=ssh
-export RSYNC_RSH
-
-verbose=0
-report=yes
-nolock=
-RUN="daily-basic"
-conf=autotest.conf
-LOCK=$HOME/.autotest-lock
-
-############################
-# Read command line entries#
-############################
-
-while [ "$1" ]
-do
- case "$1" in
- --verbose) verbose=`expr $verbose + 1`;;
- --conf=*) conf=`echo $1 | sed s/--conf=//`;;
- --version) echo $VERSION; exit;;
- --suite=*) RUN=`echo $1 | sed s/--suite=//`;;
- --install-dir=*) install_dir=`echo $1 | sed s/--install-dir=//`;;
- --clone=*) clone=`echo $1 | sed s/--clone=//`;;
- --nolock) nolock=true;;
- esac
- shift
-done
-
-#################################
-#Make sure the configfile exists#
-#if it does not exit. if it does#
-# (.) load it #
-#################################
-
-install_dir_save=$install_dir
-if [ -f $conf ]
-then
- . $conf
-else
- echo "Can't find config file: $conf"
- exit
-fi
-install_dir=$install_dir_save
-
-###############################
-# Validate that all interesting
-# variables where set in conf
-###############################
-vars="target base_dir install_dir hosts"
-if [ "$report" ]
-then
- vars="$vars result_host result_path"
-fi
-for i in $vars
-do
- t=`echo echo \\$$i`
- if [ -z "`eval $t`" ]
- then
- echo "Invalid config: $conf, variable $i is not set"
- exit
- fi
-done
-
-###############################
-#Print out the enviroment vars#
-###############################
-
-if [ $verbose -gt 0 ]
-then
- env
-fi
-
-#######################################
-# Check to see if the lock file exists#
-# If it does exit. #
-#######################################
-
-if [ -z "$nolock" ]
-then
- if [ -f $LOCK ]
- then
- echo "Lock file exists: $LOCK"
- exit 1
- fi
- echo "$DATE $RUN" > $LOCK
-fi
-
-#############################
-#If any errors here down, we#
-# trap them, and remove the #
-# Lock file before exit #
-#############################
-if [ `uname -s` != "SunOS" ]
-then
- trap "rm -f $LOCK" ERR
-fi
-
-
-###############################################
-# Check that all interesting files are present#
-###############################################
-
-test_dir=$install_dir/mysql-test/ndb
-atrt=$test_dir/atrt
-test_file=$test_dir/$RUN-tests.txt
-
-if [ ! -f "$test_file" ]
-then
- echo "Cant find testfile: $test_file"
- exit 1
-fi
-
-if [ ! -x "$atrt" ]
-then
- echo "Cant find atrt binary at $atrt"
- exit 1
-fi
-
-############################
-# check ndb_cpcc fail hosts#
-############################
-failed=`ndb_cpcc $hosts | awk '{ if($1=="Failed"){ print;}}'`
-if [ "$failed" ]
-then
- echo "Cant contact cpcd on $failed, exiting"
- exit 1
-fi
-
-#############################
-# Function for replacing the#
-# choose host with real host#
-# names. Note $$ = PID #
-#############################
-choose(){
- SRC=$1
- TMP1=/tmp/choose.$$
- TMP2=/tmp/choose.$$.$$
- shift
-
- cp $SRC $TMP1
- i=1
- while [ $# -gt 0 ]
- do
- sed -e s,"CHOOSE_host$i",$1,g < $TMP1 > $TMP2
- mv $TMP2 $TMP1
- shift
- i=`expr $i + 1`
- done
- cat $TMP1
- rm -f $TMP1
-}
-
-choose_conf(){
- if [ -f $test_dir/conf-$1-$HOST.cnf ]
- then
- echo "$test_dir/conf-$1-$HOST.cnf"
- elif [ -f $test_dir/conf-$1.cnf ]
- then
- echo "$test_dir/conf-$1.cnf"
- elif [ -f $test_dir/conf-$HOST.cnf ]
- then
- echo "$test_dir/conf-$HOST.cnf"
- else
- echo "Unable to find conf file looked for" 1>&2
- echo "$test_dir/conf-$1-$HOST.cnf and" 1>&2
- echo "$test_dir/conf-$HOST.cnf" 1>&2
- echo "$test_dir/conf-$1.cnf" 1>&2
- exit
- fi
-}
-
-#########################################
-# Count how many computers we have ready#
-#########################################
-
-count_hosts(){
- cnt=`grep "CHOOSE_host" $1 | awk '{for(i=1; i<=NF;i++) \
- if(index($i, "CHOOSE_host") > 0) print $i;}' | sort | uniq | wc -l`
- echo $cnt
-}
-
-conf=`choose_conf $RUN`
-count=`count_hosts $conf`
-avail=`echo $hosts | wc -w`
-if [ $count -gt $avail ]
- then
- echo "Not enough hosts"
- echo "Needs: $count available: $avail ($avail_hosts)"
- exit 1
-fi
-
-###
-# Make directories needed
-
-p=`pwd`
-run_dir=$install_dir/run-$RUN-$clone-$target
-res_dir=$base_dir/result-$RUN-$clone-$target/$DATE
-tar_dir=$base_dir/saved-results
-
-mkdir -p $run_dir $res_dir $tar_dir
-rm -rf $res_dir/* $run_dir/*
-
-
-###
-#
-# Do sed substitiutions
-#
-cd $run_dir
-choose $conf $hosts > d.tmp.$$
-sed -e s,CHOOSE_dir,"$run_dir/run",g < d.tmp.$$ > my.cnf
-
-# Setup configuration
-$atrt Cdq my.cnf
-
-# Start...
-$atrt --report-file=report.txt --log-file=log.txt --testcase-file=$test_dir/$RUN-tests.txt my.cnf
-
-# Make tar-ball
-[ -f log.txt ] && mv log.txt $res_dir
-[ -f report.txt ] && mv report.txt $res_dir
-[ "`find . -name 'result*'`" ] && mv result* $res_dir
-cd $res_dir
-
-echo "date=$DATE" > info.txt
-echo "suite=$RUN" >> info.txt
-echo "clone=$clone" >> info.txt
-echo "arch=$target" >> info.txt
-find . | xargs chmod ugo+r
-
-cd ..
-p2=`pwd`
-cd ..
-tarfile=res.$RUN.$clone.$target.$DATE.$HOST.$$.tgz
-tar cfz $tar_dir/$tarfile `basename $p2`/$DATE
-
-if [ "$report" ]
-then
- scp $tar_dir/$tarfile $result_host:$result_path/
-fi
-
-cd $p
-rm -rf $res_dir $run_dir
-
-if [ -z "$nolock" ]
-then
- rm -f $LOCK
-fi
diff --git a/storage/ndb/test/run-test/basic.txt b/storage/ndb/test/run-test/basic.txt
deleted file mode 100644
index 80e2bec41b2..00000000000
--- a/storage/ndb/test/run-test/basic.txt
+++ /dev/null
@@ -1,779 +0,0 @@
-# Copyright (C) 2004, 2005 MySQL AB
-# Use is subject to license terms
-#
-# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-# BASIC FUNCTIONALITY
-max-time: 500
-cmd: testBasic
-args: -n PkRead
-
-max-time: 500
-cmd: testBasic
-args: -n PkUpdate
-
-max-time: 500
-cmd: testBasic
-args: -n PkDelete
-
-max-time: 500
-cmd: testBasic
-args: -n PkInsert
-
-max-time: 600
-cmd: testBasic
-args: -n UpdateAndRead
-
-max-time: 500
-cmd: testBasic
-args: -n PkReadAndLocker T6
-
-max-time: 500
-cmd: testBasic
-args: -n PkReadAndLocker2 T6
-
-max-time: 500
-cmd: testBasic
-args: -n PkReadUpdateAndLocker T6
-
-max-time: 500
-cmd: testBasic
-args: -n ReadWithLocksAndInserts T6
-
-max-time: 500
-cmd: testBasic
-args: -n PkInsertTwice T1 T6 T10
-
-max-time: 1500
-cmd: testBasic
-args: -n Fill T1
-
-max-time: 1500
-cmd: testBasic
-args: -n Fill T6
-
-max-time: 500
-cmd: testBasic
-args: -n NoCommitSleep T6
-
-max-time: 500
-cmd: testBasic
-args: -n NoCommit626 T6
-
-max-time: 500
-cmd: testBasic
-args: -n NoCommitAndClose T6
-
-max-time: 500
-cmd: testBasic
-args: -n Commit626 T6
-
-max-time: 500
-cmd: testBasic
-args: -n CommitTry626 T6
-
-max-time: 500
-cmd: testBasic
-args: -n CommitAsMuch626 T6
-
-max-time: 500
-cmd: testBasic
-args: -n NoCommit626 T6
-
-max-time: 500
-cmd: testBasic
-args: -n NoCommitRollback626 T1 T6
-
-max-time: 500
-cmd: testBasic
-args: -n Commit630 T1 T6
-
-max-time: 500
-cmd: testBasic
-args: -n CommitTry630 T1 T6
-
-max-time: 500
-cmd: testBasic
-args: -n CommitAsMuch630 T1 T6
-
-max-time: 500
-cmd: testBasic
-args: -n NoCommit630 T1 T6
-
-max-time: 500
-cmd: testBasic
-args: -n NoCommitRollback630 T1 T6
-
-max-time: 500
-cmd: testBasic
-args: -n NoCommitAndClose T1 T6
-
-max-time: 500
-cmd: testBasic
-args: -n RollbackUpdate T1 T6
-
-max-time: 500
-cmd: testBasic
-args: -n RollbackDeleteMultiple T1 T6
-
-max-time: 500
-cmd: testBasic
-args: -n ImplicitRollbackDelete T1 T6
-
-max-time: 500
-cmd: testBasic
-args: -n CommitDelete T1 T6
-
-max-time: 500
-cmd: testBasic
-args: -n RollbackNothing T1 T6
-
-max-time: 500
-cmd: testBasicAsynch
-args: -n PkInsertAsynch
-
-max-time: 500
-cmd: testBasicAsynch
-args: -n PkReadAsynch
-
-max-time: 500
-cmd: testBasicAsynch
-args: -n PkUpdateAsynch
-
-max-time: 500
-cmd: testBasicAsynch
-args: -n PkDeleteAsynch
-
-max-time: 500
-cmd: testBasic
-args: -n MassiveRollback T1 T6 T13
-
-max-time: 500
-cmd: testBasic
-args: -n MassiveRollback2 T1 T6 T13
-
-#-m 500 1: testBasic -n ReadConsistency T6
-cmd: testTimeout
-args: -n DontTimeoutTransaction T1
-
-cmd: testTimeout
-args: -n DontTimeoutTransaction5 T1
-
-cmd: testTimeout
-args: -n TimeoutTransaction T1
-
-cmd: testTimeout
-args: -n TimeoutTransaction5 T1
-
-cmd: testTimeout
-args: -n BuddyTransNoTimeout T1
-
-cmd: testTimeout
-args: -n BuddyTransNoTimeout5 T1
-
-#
-# SCAN TESTS
-#
-max-time: 500
-cmd: testScan
-args: -n ScanRead16
-
-max-time: 500
-cmd: testScan
-args: -n ScanRead240
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadCommitted240
-
-max-time: 500
-cmd: testScan
-args: -n ScanUpdate
-
-max-time: 500
-cmd: testScan
-args: -n ScanUpdate2 T6
-
-max-time: 500
-cmd: testScan
-args: -n ScanDelete
-
-max-time: 500
-cmd: testScan
-args: -n ScanDelete2 T10
-
-max-time: 500
-cmd: testScan
-args: -n ScanUpdateAndScanRead T6
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadAndLocker T6
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadAndPkRead T6
-
-max-time: 500
-cmd: testScan
-args: -n ScanRead488 -l 10 T6
-
-max-time: 600
-cmd: testScan
-args: -n ScanRead40 -l 100 T2
-
-max-time: 1800
-cmd: testScan
-args: -n ScanRead100 -l 100 T1
-
-max-time: 600
-cmd: testScan
-args: -n ScanRead40 -l 100 T1
-
-max-time: 1800
-cmd: testScan
-args: -n ScanRead40RandomTable -l 100 T1
-
-max-time: 3600
-cmd: testScan
-args: -n ScanRead40RandomTable -l 1000 T2
-
-max-time: 500
-cmd: testScan
-args: -n ScanWithLocksAndInserts T6
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadAbort T6
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadAbort15 T6
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadAbort240 T6
-
-max-time: 500
-cmd: testScan
-args: -n ScanUpdateAbort16 T6
-
-max-time: 3600
-cmd: testScan
-args: -n ScanReadRestart T1 T6 T13
-
-max-time: 500
-cmd: testScan
-args: -n ScanUpdateRestart T6
-
-max-time: 500
-cmd: testScan
-args: -n CheckGetValue T6
-
-max-time: 500
-cmd: testScan
-args: -n CloseWithoutStop T6
-
-max-time: 500
-cmd: testScan
-args: -n NextScanWhenNoMore T6
-
-max-time: 500
-cmd: testScan
-args: -n ExecuteScanWithoutOpenScan T6
-
-max-time: 500
-cmd: testScan
-args: -n OnlyOpenScanOnce T6
-
-max-time: 500
-cmd: testScan
-args: -n OnlyOneOpInScanTrans T6
-
-max-time: 500
-cmd: testScan
-args: -n OnlyOneOpBeforeOpenScan T6
-
-max-time: 500
-cmd: testScan
-args: -n OnlyOneScanPerTrans T6
-
-max-time: 500
-cmd: testScan
-args: -n NoCloseTransaction T6
-
-max-time: 500
-cmd: testScan
-args: -n CheckInactivityTimeOut T6
-
-max-time: 500
-cmd: testScan
-args: -n CheckInactivityBeforeClose T6
-
-max-time: 500
-cmd: testScan
-args: -n CheckAfterTerror T6
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadError5021 T1
-
-max-time: 500
-cmd: testScan
-args: -n ScanReaderror5022 T1
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadError5023 T1
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadError5024 T1
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadError5025 T1
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadError5030 T1
-
-# OLD FLEX
-max-time: 500
-cmd: flexBench
-args: -c 25 -t 10
-
-max-time: 500
-cmd: flexHammer
-args: -r 5 -t 32
-
-#
-# DICT TESTS
-max-time: 1500
-cmd: testDict
-args: -n CreateAndDrop
-
-max-time: 1500
-cmd: testDict
-args: -n CreateAndDropWithData
-
-max-time: 1500
-cmd: testDict
-args: -n CreateAndDropDuring T6 T10
-
-max-time: 1500
-cmd: testDict
-args: -n CreateInvalidTables
-
-max-time: 1500
-cmd: testDict
-args: -n CreateTableWhenDbIsFull T6
-
-max-time: 1500
-cmd: testDict
-args: -n CreateMaxTables T6
-
-max-time: 500
-cmd: testDict
-args: -n FragmentTypeSingle T1
-
-max-time: 1500
-cmd: testDict
-args: -n FragmentTypeAllSmall T1 T6 T7 T8
-
-max-time: 1500
-cmd: testDict
-args: -n FragmentTypeAllLarge T1 T6 T7 T8
-
-max-time: 1500
-cmd: testDict
-args: -n TemporaryTables T1 T6 T7 T8
-
-#
-# TEST NDBAPI
-#
-max-time: 500
-cmd: testDataBuffers
-args:
-
-# Testsuite: testNdbApi
-# Number of tests: 5
-max-time: 500
-cmd: testNdbApi
-args: -n MaxNdb T6
-
-max-time: 500
-cmd: testNdbApi
-args: -n MaxTransactions T1 T6 T7 T8 T13
-
-max-time: 500
-cmd: testNdbApi
-args: -n MaxOperations T1 T6 T7 T8 T13
-
-max-time: 500
-cmd: testNdbApi
-args: -n MaxGetValue T1 T6 T7 T8 T13
-
-max-time: 500
-cmd: testNdbApi
-args: -n MaxEqual
-
-max-time: 500
-cmd: testNdbApi
-args: -n DeleteNdb T1 T6
-
-max-time: 500
-cmd: testNdbApi
-args: -n WaitUntilReady T1 T6 T7 T8 T13
-
-max-time: 500
-cmd: testNdbApi
-args: -n GetOperationNoTab T6
-
-max-time: 500
-cmd: testNdbApi
-args: -n NdbErrorOperation T6
-
-max-time: 500
-cmd: testNdbApi
-args: -n MissingOperation T6
-
-max-time: 500
-cmd: testNdbApi
-args: -n GetValueInUpdate T6
-
-max-time: 500
-cmd: testNdbApi
-args: -n UpdateWithoutKeys T6
-
-max-time: 500
-cmd: testNdbApi
-args: -n UpdateWithoutValues T6
-
-max-time: 500
-cmd: testInterpreter
-args: T1
-
-max-time: 1500
-cmd: testOperations
-args: -n ReadRead
-
-max-time: 1500
-cmd: testOperations
-args: -n ReadReadEx
-
-max-time: 1500
-cmd: testOperations
-args: -n ReadInsert
-
-max-time: 1500
-cmd: testOperations
-args: -n ReadUpdate
-
-max-time: 1500
-cmd: testOperations
-args: -n ReadDelete
-
-max-time: 1500
-cmd: testOperations
-args: -n FReadRead
-
-max-time: 1500
-cmd: testOperations
-args: -n FReadReadEx
-
-max-time: 1500
-cmd: testOperations
-args: -n FReadInsert
-
-max-time: 1500
-cmd: testOperations
-args: -n FReadUpdate
-
-max-time: 1500
-cmd: testOperations
-args: -n FReadDelete
-
-max-time: 1500
-cmd: testOperations
-args: -n ReadExRead
-
-max-time: 1500
-cmd: testOperations
-args: -n ReadExReadEx
-
-max-time: 1500
-cmd: testOperations
-args: -n ReadExInsert
-
-max-time: 1500
-cmd: testOperations
-args: -n ReadExUpdate
-
-max-time: 1500
-cmd: testOperations
-args: -n ReadExDelete
-
-max-time: 1500
-cmd: testOperations
-args: -n InsertRead
-
-max-time: 1500
-cmd: testOperations
-args: -n InsertReadEx
-
-max-time: 1500
-cmd: testOperations
-args: -n InsertInsert
-
-max-time: 1500
-cmd: testOperations
-args: -n InsertUpdate
-
-max-time: 1500
-cmd: testOperations
-args: -n InsertDelete
-
-max-time: 1500
-cmd: testOperations
-args: -n UpdateRead
-
-max-time: 1500
-cmd: testOperations
-args: -n UpdateReadEx
-
-max-time: 1500
-cmd: testOperations
-args: -n UpdateInsert
-
-max-time: 1500
-cmd: testOperations
-args: -n UpdateUpdate
-
-max-time: 1500
-cmd: testOperations
-args: -n UpdateDelete
-
-max-time: 1500
-cmd: testOperations
-args: -n DeleteRead
-
-max-time: 1500
-cmd: testOperations
-args: -n DeleteReadEx
-
-max-time: 1500
-cmd: testOperations
-args: -n DeleteInsert
-
-max-time: 1500
-cmd: testOperations
-args: -n DeleteUpdate
-
-max-time: 1500
-cmd: testOperations
-args: -n DeleteDelete
-
-max-time: 1500
-cmd: testOperations
-args: -n ReadSimpleRead
-
-max-time: 1500
-cmd: testOperations
-args: -n ReadDirtyRead
-
-max-time: 1500
-cmd: testOperations
-args: -n FReadSimpleRead
-
-max-time: 1500
-cmd: testOperations
-args: -n FReadDirtyRead
-
-max-time: 1500
-cmd: testOperations
-args: -n ReadExSimpleRead
-
-max-time: 1500
-cmd: testOperations
-args: -n ReadExDirtyRead
-
-max-time: 1500
-cmd: testOperations
-args: -n InsertSimpleRead
-
-max-time: 1500
-cmd: testOperations
-args: -n InsertDirtyRead
-
-max-time: 1500
-cmd: testOperations
-args: -n UpdateSimpleRead
-
-max-time: 1500
-cmd: testOperations
-args: -n UpdateDirtyRead
-
-max-time: 1500
-cmd: testOperations
-args: -n DeleteSimpleRead
-
-max-time: 1500
-cmd: testOperations
-args: -n DeleteDirtyRead
-
-max-time: 1500
-cmd: testTransactions
-args: -n ReadRead
-
-max-time: 1500
-cmd: testTransactions
-args: -n ReadReadEx
-
-max-time: 1500
-cmd: testTransactions
-args: -n ReadInsert
-
-max-time: 1500
-cmd: testTransactions
-args: -n ReadUpdate
-
-max-time: 1500
-cmd: testTransactions
-args: -n ReadDelete
-
-max-time: 1500
-cmd: testTransactions
-args: -n ReadExRead
-
-max-time: 1500
-cmd: testTransactions
-args: -n ReadExReadEx
-
-max-time: 1500
-cmd: testTransactions
-args: -n ReadExInsert
-
-max-time: 1500
-cmd: testTransactions
-args: -n ReadExUpdate
-
-max-time: 1500
-cmd: testTransactions
-args: -n ReadExDelete
-
-max-time: 1500
-cmd: testTransactions
-args: -n InsertRead
-
-max-time: 1500
-cmd: testTransactions
-args: -n InsertReadEx
-
-max-time: 1500
-cmd: testTransactions
-args: -n InsertInsert
-
-max-time: 1500
-cmd: testTransactions
-args: -n InsertUpdate
-
-max-time: 1500
-cmd: testTransactions
-args: -n InsertDelete
-
-max-time: 1500
-cmd: testTransactions
-args: -n UpdateRead
-
-max-time: 1500
-cmd: testTransactions
-args: -n UpdateReadEx
-
-max-time: 1500
-cmd: testTransactions
-args: -n UpdateInsert
-
-max-time: 1500
-cmd: testTransactions
-args: -n UpdateUpdate
-
-max-time: 1500
-cmd: testTransactions
-args: -n UpdateDelete
-
-max-time: 1500
-cmd: testTransactions
-args: -n DeleteRead
-
-max-time: 1500
-cmd: testTransactions
-args: -n DeleteReadEx
-
-max-time: 1500
-cmd: testTransactions
-args: -n DeleteInsert
-
-max-time: 1500
-cmd: testTransactions
-args: -n DeleteUpdate
-
-max-time: 1500
-cmd: testTransactions
-args: -n DeleteDelete
-
-max-time: 1500
-cmd: testTransactions
-args: -n ReadSimpleRead
-
-max-time: 1500
-cmd: testTransactions
-args: -n ReadDirtyRead
-
-max-time: 1500
-cmd: testTransactions
-args: -n ReadExSimpleRead
-
-max-time: 1500
-cmd: testTransactions
-args: -n ReadExDirtyRead
-
-max-time: 1500
-cmd: testTransactions
-args: -n InsertSimpleRead
-
-max-time: 1500
-cmd: testTransactions
-args: -n InsertDirtyRead
-
-max-time: 1500
-cmd: testTransactions
-args: -n UpdateSimpleRead
-
-max-time: 1500
-cmd: testTransactions
-args: -n UpdateDirtyRead
-
-max-time: 1500
-cmd: testTransactions
-args: -n DeleteSimpleRead
-
-max-time: 1500
-cmd: testTransactions
-args: -n DeleteDirtyRead
-
-max-time: 1500
-cmd: testRestartGci
-args: T6
-
diff --git a/storage/ndb/test/run-test/conf-dl145a.cnf b/storage/ndb/test/run-test/conf-dl145a.cnf
deleted file mode 100644
index 5f61bee755d..00000000000
--- a/storage/ndb/test/run-test/conf-dl145a.cnf
+++ /dev/null
@@ -1,26 +0,0 @@
-[atrt]
-basedir = CHOOSE_dir
-baseport = 14000
-clusters = .2node
-
-[ndb_mgmd]
-
-[mysqld]
-skip-innodb
-skip-bdb
-
-[cluster_config.2node]
-ndb_mgmd = CHOOSE_host1
-ndbd = CHOOSE_host2,CHOOSE_host3
-ndbapi= CHOOSE_host1,CHOOSE_host1,CHOOSE_host1
-
-NoOfReplicas = 2
-IndexMemory = 100M
-DataMemory = 300M
-BackupMemory = 64M
-MaxNoOfConcurrentScans = 100
-MaxNoOfSavedMessages= 1000
-SendBufferMemory = 2M
-NoOfFragmentLogFiles = 4
-FragmentLogFileSize = 64M
-
diff --git a/storage/ndb/test/run-test/conf-ndbmaster.cnf b/storage/ndb/test/run-test/conf-ndbmaster.cnf
deleted file mode 100644
index 417e2988d0d..00000000000
--- a/storage/ndb/test/run-test/conf-ndbmaster.cnf
+++ /dev/null
@@ -1,23 +0,0 @@
-[atrt]
-basedir = CHOOSE_dir
-baseport = 14000
-clusters = .4node
-
-[ndb_mgmd]
-
-[mysqld]
-skip-innodb
-skip-bdb
-
-[cluster_config.4node]
-ndb_mgmd = CHOOSE_host1
-ndbd = CHOOSE_host2,CHOOSE_host3,CHOOSE_host2,CHOOSE_host3
-ndbapi= CHOOSE_host1,CHOOSE_host1,CHOOSE_host1
-
-NoOfReplicas = 2
-IndexMemory = 100M
-DataMemory = 300M
-BackupMemory = 64M
-MaxNoOfConcurrentScans = 100
-MaxNoOfSavedMessages= 1000
-SendBufferMemory = 2M
diff --git a/storage/ndb/test/run-test/conf-repl.cnf b/storage/ndb/test/run-test/conf-repl.cnf
deleted file mode 100644
index 57eb2ee413e..00000000000
--- a/storage/ndb/test/run-test/conf-repl.cnf
+++ /dev/null
@@ -1,28 +0,0 @@
-[atrt]
-basedir=CHOOSE_dir
-baseport=15000
-clusters= .master,.slave
-replicate= 1.master:1.slave
-
-[ndb_mgmd]
-
-[mysqld]
-skip-innodb
-skip-bdb
-
-[cluster_config]
-MaxNoOfSavedMessages= 1000
-DataMemory = 100M
-
-[cluster_config.master]
-NoOfReplicas = 2
-ndb_mgmd = CHOOSE_host1
-ndbd = CHOOSE_host2,CHOOSE_host3
-mysqld = CHOOSE_host1
-ndbapi= CHOOSE_host1
-
-[cluster_config.slave]
-NoOfReplicas = 1
-ndb_mgmd = CHOOSE_host4
-ndbd = CHOOSE_host4
-mysqld = CHOOSE_host4
diff --git a/storage/ndb/test/run-test/conf-test.cnf b/storage/ndb/test/run-test/conf-test.cnf
deleted file mode 100644
index e528eeb1d8b..00000000000
--- a/storage/ndb/test/run-test/conf-test.cnf
+++ /dev/null
@@ -1,26 +0,0 @@
-[atrt]
-basedir = CHOOSE_dir
-baseport = 14000
-clusters = .2node
-
-[ndb_mgmd]
-
-[mysqld]
-skip-innodb
-skip-bdb
-
-[cluster_config.2node]
-ndb_mgmd = CHOOSE_host1
-ndbd = CHOOSE_host2,CHOOSE_host3
-ndbapi= CHOOSE_host1,CHOOSE_host1,CHOOSE_host1
-
-NoOfReplicas = 2
-IndexMemory = 25M
-DataMemory = 100M
-BackupMemory = 64M
-MaxNoOfConcurrentScans = 100
-MaxNoOfSavedMessages= 1000
-SendBufferMemory = 2M
-NoOfFragmentLogFiles = 4
-FragmentLogFileSize = 64M
-
diff --git a/storage/ndb/test/run-test/daily-basic-tests.txt b/storage/ndb/test/run-test/daily-basic-tests.txt
deleted file mode 100644
index ec6fcde0879..00000000000
--- a/storage/ndb/test/run-test/daily-basic-tests.txt
+++ /dev/null
@@ -1,1072 +0,0 @@
-# Copyright (C) 2004-2008 MySQL AB
-# Use is subject to license terms
-#
-# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-max-time: 600
-cmd: atrt-testBackup
-args: -n NFMaster T1
-
-max-time: 600
-cmd: testBasic
-args: -n PkRead T1
-
-max-time: 600
-cmd: atrt-testBackup
-args: -n NFMasterAsSlave T1
-
-max-time: 600
-cmd: testBasic
-args: -n PkRead T1
-
-max-time: 600
-cmd: atrt-testBackup
-args: -n NFSlave T1
-
-max-time: 600
-cmd: testBasic
-args: -n PkRead T1
-
-max-time: 600
-cmd: atrt-testBackup
-args: -n FailMaster T1
-
-max-time: 600
-cmd: testBasic
-args: -n PkRead T1
-
-max-time: 600
-cmd: atrt-testBackup
-args: -n FailMasterAsSlave T1
-
-max-time: 600
-cmd: testBasic
-args: -n PkRead T1
-
-max-time: 600
-cmd: atrt-testBackup
-args: -n FailSlave T1
-
-max-time: 600
-cmd: testBasic
-args: -n PkRead T1
-
-max-time: 600
-cmd: atrt-testBackup
-args: -n BackupOne T1 T6 T3 I3
-
-max-time: 600
-cmd: atrt-testBackup
-args: -n BackupDDL T1
-
-# BASIC FUNCTIONALITY
-max-time: 500
-cmd: testBasic
-args: -n PkRead
-
-max-time: 500
-cmd: testBasic
-args: -n PkSimpleRead
-
-max-time: 500
-cmd: testBasic
-args: -n PkDirtyRead
-
-max-time: 500
-cmd: testBasic
-args: -n PkUpdate
-
-max-time: 500
-cmd: testBasic
-args: -n PkDelete
-
-max-time: 500
-cmd: testBasic
-args: -n PkInsert
-
-max-time: 660
-cmd: testBasic
-args: -n UpdateAndRead
-
-max-time: 500
-cmd: testBasic
-args: -n DeleteRead
-
-max-time: 500
-cmd: testBasic
-args: -n PkReadAndLocker T6 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n PkReadAndLocker2 T6 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n PkReadUpdateAndLocker T6 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n ReadWithLocksAndInserts T6 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n PkInsertTwice T1 T6 T10 D1 D2
-
-max-time: 1500
-cmd: testBasic
-args: -n Fill T13
-
-max-time: 1500
-cmd: testBasic
-args: -n Fill T6
-
-max-time: 500
-cmd: testBasic
-args: -n NoCommitSleep T6 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n NoCommit626 T6 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n NoCommitAndClose T6 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n Commit626 T6 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n CommitTry626 T6 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n CommitAsMuch626 T6 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n NoCommit626 T6 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n NoCommitRollback626 T1 T6 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n Commit630 T1 T6 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n CommitTry630 T1 T6 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n CommitAsMuch630 T1 T6 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n NoCommit630 T1 T6 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n NoCommitRollback630 T1 T6 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n NoCommitAndClose T1 T6 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n RollbackUpdate T1 T6 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n RollbackDeleteMultiple T1 T6 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n ImplicitRollbackDelete T1 T6 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n CommitDelete T1 T6 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n RollbackNothing T1 T6 D1 D2
-
-max-time: 500
-cmd: testBasicAsynch
-args: -n PkInsertAsynch
-
-max-time: 500
-cmd: testBasicAsynch
-args: -n PkReadAsynch
-
-max-time: 500
-cmd: testBasicAsynch
-args: -n PkUpdateAsynch
-
-max-time: 500
-cmd: testBasicAsynch
-args: -n PkDeleteAsynch
-
-max-time: 1000
-cmd: testBasic
-args: -n MassiveRollback T1 T7 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n MassiveRollback2 T1 T7 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n MassiveRollback3 T1 T7 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n MassiveRollback4 T1 T7 D1 D2
-
-max-time: 500
-cmd: testBasic
-args: -n TupError
-
-max-time: 500
-cmd: testBasic
-args: -n InsertError T1
-
-max-time: 500
-cmd: testBasic
-args: -n InsertError2 T1
-
-max-time: 500
-cmd: testTimeout
-args: T1
-
-max-time: 500
-cmd: testBasic
-args: -n Bug25090 T1
-
-max-time: 1000
-cmd: testBasic
-args: -n Bug27756
-
-max-time: 500
-cmd: testBasic
-args: -n Bug28073
-
-max-time: 500
-cmd: testBasic
-args: -n Bug20535
-
-max-time: 500
-cmd: testIndex
-args: -n Bug25059 -r 3000 T1
-
-# SCAN TESTS
-#
-max-time: 500
-cmd: testScan
-args: -n ScanRead16
-
-max-time: 500
-cmd: testScan
-args: -n ScanRead240
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadCommitted240
-
-max-time: 500
-cmd: testScan
-args: -n ScanUpdate
-
-max-time: 500
-cmd: testScan
-args: -n ScanUpdate2 T6 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n ScanDelete
-
-max-time: 500
-cmd: testScan
-args: -n ScanDelete2 T10 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n ScanUpdateAndScanRead T6 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadAndLocker T6 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadAndPkRead T6 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n ScanRead488 -l 10 T6 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n ScanRead488O -l 10 T6 D1 D2
-
-max-time: 1000
-cmd: testScan
-args: -n ScanRead488T -l 10 T6 D1 D2
-
-max-time: 1000
-cmd: testScan
-args: -n ScanRead488_Mixed -l 10 T6 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n ScanRead488Timeout -l 10 T6 D1 D2
-
-max-time: 600
-cmd: testScan
-args: -n ScanRead40 -l 100 T2 D1 D2
-
-max-time: 1800
-cmd: testScan
-args: -n ScanRead100 -l 100 T1 D1 D2
-
-max-time: 600
-cmd: testScan
-args: -n ScanRead40 -l 100 T1 D1 D2
-
-max-time: 1800
-cmd: testScan
-args: -n ScanRead40RandomTable -l 100 T1
-
-max-time: 3600
-cmd: testScan
-args: -n ScanRead40RandomTable -l 1000 T2
-
-max-time: 500
-cmd: testScan
-args: -n ScanWithLocksAndInserts T6 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadAbort T6 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadAbort15 T6 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadAbort240 T6 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n ScanUpdateAbort16 T6 D1 D2
-
-max-time: 3600
-cmd: testScan
-args: -n ScanReadRestart T1 T6 T13
-
-max-time: 3600
-cmd: testScan
-args: -n ScanReadRestart D1 D2
-
-max-time: 1200
-cmd: testScan
-args: -n ScanUpdateRestart T6
-
-max-time: 1200
-cmd: testScan
-args: -n ScanUpdateRestart D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n CheckGetValue T6 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n CloseWithoutStop T6 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n NextScanWhenNoMore T6 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n ExecuteScanWithoutOpenScan T6 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n OnlyOpenScanOnce T6 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n OnlyOneOpInScanTrans T6 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n OnlyOneOpBeforeOpenScan T6 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n OnlyOneScanPerTrans T6 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n NoCloseTransaction T6 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n CheckInactivityTimeOut T6 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n CheckInactivityBeforeClose T6 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n CheckAfterTerror T6 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadError5021 T1 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n ScanReaderror5022 T1 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadError5023 T1 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadError5024 T1 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadError5025 T1 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n ScanReadError5030 T1 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n InsertDelete T1 T6 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n CheckAfterTerror T1 D1 D2
-
-max-time: 1200
-cmd: testScan
-args: -n ScanReadWhileNodeIsDown T1
-
-max-time: 1200
-cmd: testScan
-args: -n ScanReadWhileNodeIsDown D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n ScanRestart T1 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -l 100 -n Scan-bug8262 T7 D1 D2
-
-max-time: 500
-cmd: testScan
-args: -n ScanParallelism
-
-max-time: 500
-cmd: testScan
-args: -n Bug24447 T1
-
-max-time: 1000
-cmd: testScan
-args: -n ScanVariants
-
-max-time: 1000
-cmd: testNodeRestart
-args: -n Bug27003 T1
-
-max-time: 300
-cmd: testSystemRestart
-args: -n Bug29167 T1
-
-max-time: 300
-cmd: testSystemRestart
-args: -l 2 -n Bug28770 T1
-
-max-time: 1000
-cmd: testNodeRestart
-args: -n Bug27283 T1
-
-max-time: 500
-cmd: testNodeRestart
-args: -n Bug15587 T1
-
-max-time: 500
-cmd: testNodeRestart
-args: -n Bug15632 T1
-
-max-time: 500
-cmd: testNodeRestart
-args: -n Bug15685 T1
-
-max-time: 500
-cmd: testNodeRestart
-args: -n Bug16772 T1
-
-#max-time: 500
-#cmd: testSystemRestart
-#args: -n Bug18385 T1
-#
-max-time: 1000
-cmd: testNodeRestart
-args: -n Bug18414 T1
-
-max-time: 1000
-cmd: testNodeRestart
-args: -n Bug18612 T1
-
-max-time: 1000
-cmd: testNodeRestart
-args: -n Bug18612SR T1
-
-max-time: 1000
-cmd: testNodeRestart
-args: -n Bug20185 T1
-
-max-time: 1000
-cmd: testNodeRestart
-args: -n Bug21271 T6
-
-max-time: 1000
-cmd: testIndex
-args: -n Bug21384
-
-max-time: 1000
-cmd: testNodeRestart
-args: -n Bug24717 T1
-
-max-time: 1000
-cmd: testNodeRestart
-args: -n Bug25364 T1
-
-max-time: 1000
-cmd: testNodeRestart
-args: -n Bug25554 T1
-
-max-time: 3000
-cmd: testNodeRestart
-args: -n Bug25984 T1
-
-max-time: 1000
-cmd: testNodeRestart
-args: -n Bug26457 T1
-
-max-time: 1000
-cmd: testNodeRestart
-args: -n Bug26481 T1
-
-max-time: 1000
-cmd: testNodeRestart
-args: -n Bug28023 T7 D2
-
-max-time: 1000
-cmd: testNodeRestart
-args: -n Bug29364 T1
-
-max-time: 300
-cmd: testNodeRestart
-args: -n Bug32160 T1
-
-#
-# DICT TESTS
-max-time: 500
-cmd: testDict
-args: -n Bug29501 T1
-
-max-time: 500
-cmd: testDict
-args: -n testDropDDObjects T1
-
-max-time: 1500
-cmd: testDict
-args: -n CreateAndDrop
-
-max-time: 1000
-cmd: testNodeRestart
-args: -n Bug28717 T1
-
-max-time: 1500
-cmd: testDict
-args: -n CreateAndDropAtRandom -l 200 T1
-
-max-time: 1500
-cmd: testDict
-args: -n CreateAndDropWithData
-
-max-time: 1500
-cmd: testDict
-args: -n CreateAndDropDuring T6 T10 D1 D2
-
-max-time: 1500
-cmd: testDict
-args: -n CreateInvalidTables
-
-max-time: 1500
-cmd: testDict
-args: -n CreateTableWhenDbIsFull T6
-
-max-time: 1500
-cmd: testDict
-args: -n CreateMaxTables T6
-
-max-time: 500
-cmd: testDict
-args: -n FragmentTypeSingle T1
-
-max-time: 1500
-cmd: testDict
-args: -n FragmentTypeAllSmall T1 T6 T7 T8
-
-max-time: 1500
-cmd: testDict
-args: -n FragmentTypeAllLarge T1 T6 T7 T8
-
-max-time: 1500
-cmd: testDict
-args: -n TemporaryTables T1 T6 T7 T8
-
-max-time: 1500
-cmd: testDict
-args: -n Restart_NR2 T1 I3
-
-max-time: 500
-cmd: testDict
-args: -n Bug21755 T1
-
-max-time: 1500
-cmd: testDict
-args: -l 25 -n DictRestart T1
-
-max-time: 500
-cmd: testDict
-args: -n Bug24631 T1
-
-#
-# TEST NDBAPI
-#
-max-time: 500
-cmd: testDataBuffers
-args:
-
-# Testsuite: testNdbApi
-# Number of tests: 5
-max-time: 500
-cmd: testNdbApi
-args: -n MaxNdb T6
-
-max-time: 500
-cmd: testNdbApi
-args: -n MaxTransactions T1 T6 T7 T8 T13
-
-max-time: 500
-cmd: testNdbApi
-args: -n MaxOperations T1 T6 T7 T8 T13
-
-max-time: 500
-cmd: testNdbApi
-args: -n MaxGetValue T1 T6 T7 T8 T13
-
-max-time: 500
-cmd: testNdbApi
-args: -n MaxEqual
-
-max-time: 500
-cmd: testNdbApi
-args: -n DeleteNdb T1 T6
-
-max-time: 500
-cmd: testNdbApi
-args: -n WaitUntilReady T1 T6 T7 T8 T13
-
-max-time: 500
-cmd: testNdbApi
-args: -n GetOperationNoTab T6
-
-max-time: 500
-cmd: testNdbApi
-args: -n NdbErrorOperation T6
-
-max-time: 500
-cmd: testNdbApi
-args: -n MissingOperation T6
-
-max-time: 500
-cmd: testNdbApi
-args: -n GetValueInUpdate T6
-
-max-time: 500
-cmd: testNdbApi
-args: -n UpdateWithoutKeys T6 D1 D2
-
-max-time: 500
-cmd: testNdbApi
-args: -n UpdateWithoutValues T6 D1 D2
-
-max-time: 500
-cmd: testNdbApi
-args: -n ReadWithoutGetValue D1 D2
-
-max-time: 500
-cmd: testNdbApi
-args: -n Bug_11133 T1 D1 D2
-
-max-time: 500
-cmd: testNdbApi
-args: -n Scan_4006 T1 D1 D2
-
-max-time: 500
-cmd: testNdbApi
-args: -n Bug_WritePartialIgnoreError T1
-
-max-time: 500
-cmd: testNdbApi
-args: -n ExecuteAsynch T1
-
-max-time: 1000
-cmd: testNdbApi
-args: -n Bug28443
-
-max-time: 500
-cmd: testInterpreter
-args: T1
-
-max-time: 150000
-cmd: testOperations
-args:
-
-max-time: 15000
-cmd: testTransactions
-args:
-
-max-time: 1500
-cmd: testRestartGci
-args: T6
-
-max-time: 1500
-cmd: testBlobs
-args:
-
-max-time: 600
-cmd: testBlobs
-args: -bug 27018
-
-max-time: 600
-cmd: testBlobs
-args: -bug 27370
-
-max-time: 5000
-cmd: testOIBasic
-args: -case abcdefz
-
-max-time: 2000
-cmd: testOIBasic
-args: -case gz
-
-max-time: 2000
-cmd: testOIBasic
-args: -case hz
-
-max-time: 2500
-cmd: testBitfield
-args:
-
-max-time: 2500
-cmd: testPartitioning
-args:
-
-#
-#
-# SYSTEM RESTARTS
-#
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR1 T1
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR1 T6
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR1 T7
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR1 T8
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR1 D1
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR1 D2
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR2 T1
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR2 T6
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR2 T7
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR2 D1
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR2 D2
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_UNDO T1
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_UNDO T6
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_UNDO T7
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_UNDO T8
-
-max-time: 1000
-cmd: testSRBank
-args: -n SR -l 300 -r 15 T1
-
-max-time: 1000
-cmd: testSRBank
-args: -n NR -l 300 -r 15 T1
-
-max-time: 1000
-cmd: testSRBank
-args: -n Mix -l 300 -r 15 T1
-
-max-time: 300
-cmd: testNodeRestart
-args: -n Bug24543 T1
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n Bug24664
-
-max-time: 1000
-cmd: testNodeRestart
-args: -n Bug25468 T1
-
-max-time: 1000
-cmd: testNodeRestart
-args: -n Bug27466 T1
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n Bug27434 T1
-
-max-time: 1000
-cmd: test_event
-args: -l 10 -n Bug27169 T1
-
-# OLD FLEX
-max-time: 500
-cmd: flexBench
-args: -c 25 -t 10
-
-max-time: 500
-cmd: flexHammer
-args: -r 5 -t 32
-
-max-time: 300
-cmd: DbCreate
-args:
-
-max-time: 180
-cmd: DbAsyncGenerator
-args: -time 60 -p 1
-type: bench
-
-max-time: 180
-cmd: DbAsyncGenerator
-args: -time 60 -p 25
-type: bench
-
-max-time: 180
-cmd: DbAsyncGenerator
-args: -time 60 -p 100
-type: bench
-
-max-time: 180
-cmd: DbAsyncGenerator
-args: -time 60 -p 200
-type: bench
-
-max-time: 180
-cmd: DbAsyncGenerator
-args: -time 60 -p 1 -proc 25
-type: bench
-
-max-time: 120
-cmd: testMgm
-args: -n ApiSessionFailure T1
-
-max-time: 15
-cmd: testMgm
-args: -n ApiConnectTimeout T1
-
-max-time: 120
-cmd: testMgm
-args: -n ApiTimeoutBasic T1
-
-max-time: 120
-cmd: testMgm
-args: -n ApiSessionFailure T1
-
-max-time: 120
-cmd: testMgm
-args: -n ApiGetStatusTimeout T1
-
-max-time: 120
-cmd: testMgm
-args: -n ApiGetConfigTimeout T1
-
-max-time: 120
-cmd: testMgm
-args: -n ApiMgmEventTimeout T1
-
-max-time: 120
-cmd: testMgm
-args: -n ApiMgmStructEventTimeout T1
-
-max-time: 180
-cmd: testIndex
-args: -n Bug28804 T1 T3
-
-max-time: 180
-cmd: testIndex
-args: -n Bug28804_ATTRINFO T1 T3
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_DD_1 D1
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_DD_1b D1
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_DD_1 D2
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_DD_1b D2
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_DD_1_LCP D1
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_DD_1b_LCP D1
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_DD_1_LCP D2
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_DD_1b_LCP D2
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_DD_2 D1
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_DD_2b D1
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_DD_2 D2
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_DD_2b D2
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_DD_2_LCP D1
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_DD_2b_LCP D1
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_DD_2_LCP D2
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_DD_2b_LCP D2
-
-max-time: 600
-cmd: testNodeRestart
-args: -n Bug31525 T1
-
-max-time: 300
-cmd: test_event
-args: -n Bug31701 T1
-
-max-time: 300
-cmd: testSystemRestart
-args: -n Bug22696 T1
-
-max-time: 300
-cmd: test_event
-args: -n Bug33793 T1
-
-max-time: 1200
-cmd: testNodeRestart
-args: -n Bug34216 -l 10 T1 I3 D2
-
-max-time: 1200
-cmd: testNodeRestart
-args: -n mixedmultiop -l 10 T1 I2 I3 D2
-
diff --git a/storage/ndb/test/run-test/daily-devel-tests.txt b/storage/ndb/test/run-test/daily-devel-tests.txt
deleted file mode 100644
index 95fe82d1796..00000000000
--- a/storage/ndb/test/run-test/daily-devel-tests.txt
+++ /dev/null
@@ -1,260 +0,0 @@
-# Copyright (C) 2004, 2005 MySQL AB
-# Use is subject to license terms
-#
-# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-#
-# INDEX
-#
-max-time: 1500
-cmd: testIndex
-args: -n CreateAll T1 T6 T13
-
-#-m 7200 1: testIndex -n InsertDeleteGentle T7
-max-time: 3600
-cmd: testIndex
-args: -n InsertDelete T1 T10
-
-#-m 3600 1: testIndex -n CreateLoadDropGentle T7
-max-time: 3600
-cmd: testIndex
-args: -n CreateLoadDrop T1 T10
-
-#
-# BACKUP
-#
-max-time: 1000
-cmd: atrt-testBackup
-args: -n BackupBank T6
-
-#
-# MGMAPI AND MGSRV
-#
-max-time: 1800
-cmd: testMgm
-args: -n SingleUserMode T1
-
-#
-#
-# SYSTEM RESTARTS
-#
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR3 T6
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR4 T6
-
-#
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR_FULLDB T6
-
-#
-# NODE RESTARTS
-#
-max-time: 2500
-cmd: testNodeRestart
-args: -n NoLoad T6
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n MixedPkRead T6 T8 T13
-
-max-time: 2500
-cmd: testNodeRestart
-args: -l 1 -n MixedPkReadPkUpdate
-
-max-time: 2500
-cmd: testNodeRestart
-args: -l 1 -n MixedReadUpdateScan
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n CommittedRead T1
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n LateCommit T1
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n Terror T6 T13
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n FullDb T6 T13
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n RestartRandomNode T6 T13
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n RestartRandomNodeError T6 T13
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n RestartRandomNodeInitial T6 T13
-
-max-time: 3600
-cmd: testNodeRestart
-args: -l 1 -n RestartNFDuringNR T6 T13
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n RestartMasterNodeError T6 T8 T13
-
-max-time: 3600
-cmd: testNodeRestart
-args: -n RestartNodeDuringLCP T6
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n TwoNodeFailure T6 T8 T13
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n TwoMasterNodeFailure T6 T8 T13
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n FiftyPercentFail T6 T8 T13
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n RestartAllNodes T6 T8 T13
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n RestartAllNodesAbort T6 T8 T13
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n RestartAllNodesError9999 T6 T8 T13
-
-max-time: 2500
-cmd: testNodeRestart
-args: -n FiftyPercentStopAndWait T6 T8 T13
-
-#max-time: 500
-#cmd: testNodeRestart
-#args: -n StopOnError T1
-#
-#
-max-time: 2500
-cmd: testIndex
-args: -n NFNR1 T6 T13
-
-max-time: 2500
-cmd: testIndex
-args: -n NFNR2 T6 T13
-
-max-time: 2500
-cmd: testIndex
-args: -n NFNR3 T6 T13
-
-max-time: 2500
-cmd: testIndex
-args: -n BuildDuring T6
-
-max-time: 2500
-cmd: testIndex
-args: -l 2 -n SR1 T6 T13
-
-max-time: 2500
-cmd: testIndex
-args: -n NFNR1_O T6 T13
-
-max-time: 2500
-cmd: testIndex
-args: -n NFNR2_O T6 T13
-
-max-time: 2500
-cmd: testIndex
-args: -n NFNR3_O T6 T13
-
-max-time: 2500
-cmd: testIndex
-args: -n BuildDuring_O T6
-
-max-time: 2500
-cmd: testIndex
-args: -l 2 -n SR1_O T6 T13
-
-max-time: 500
-cmd: testIndex
-args: -n MixedTransaction T1
-
-max-time: 2500
-cmd: testDict
-args: -n NF1 T1 T6 T13
-
-#
-max-time: 1500
-cmd: testSystemRestart
-args: -l 1 -n SR6 T1
-
-max-time: 1500
-cmd: testSystemRestart
-args: -l 1 -n SR7 T1
-
-max-time: 1500
-cmd: testSystemRestart
-args: -l 1 -n SR8 T1
-
-max-time: 1500
-cmd: testSystemRestart
-args: -l 1 -n SR9 T1
-
-#
-max-time: 3600
-cmd: test_event
-args: -n EventOperationApplier -l 2
-
-#
-max-time: 3600
-cmd: test_event
-args: -n EventOperationApplier_NR -l 2
-
-#
-max-time: 3600
-cmd: test_event
-args: -n MergeEventOperationApplier_NR -l 2
-
-#
-max-time: 2500
-cmd: test_event
-args: -n Multi
-
-#
-max-time: 3600
-cmd: test_event
-args: -n CreateDropNR -l 1
-
-#
-max-time: 600
-cmd: test_event_merge
-args: --no-implicit-nulls --separate-events --maxops 10000
-
-#
-max-time: 600
-cmd: test_event_merge
-args: --no-implicit-nulls --no-multiops
-
-max-time: 600
-cmd: testBasic
-args: -n PkRead T1
-
diff --git a/storage/ndb/test/run-test/example-my.cnf b/storage/ndb/test/run-test/example-my.cnf
deleted file mode 100644
index 99e1ce9f75b..00000000000
--- a/storage/ndb/test/run-test/example-my.cnf
+++ /dev/null
@@ -1,116 +0,0 @@
-[atrt]
-basedir=/home/jonas/atrt
-baseport=10000
-clusters = .master
-clusters= .master,.slave
-replicate = 1.master:1.slave
-replicate = 2.master:2.slave
-
-[cluster_config]
-NoOfReplicas= 2
-IndexMemory= 10M
-DataMemory= 50M
-MaxNoOfConcurrentScans= 100
-Diskless = 1
-
-[cluster_config.master]
-ndb_mgmd = local1
-ndbd = local1,local1
-mysqld = local1,local1
-ndbapi= local1
-NoOfReplicas= 2
-
-[cluster_config.slave]
-ndb_mgmd = local1
-ndbd = local1
-ndbapi= local1
-mysqld = local1,local1
-NoOfReplicas= 1
-
-[mysqld]
-skip-innodb
-skip-bdb
-
-#
-# Generated by atrt
-# Mon May 29 23:27:49 2006
-
-[mysql_cluster.master]
-ndb-connectstring= local1:10000
-
-[cluster_config.ndb_mgmd.1.master]
-PortNumber= 10000
-
-[cluster_config.ndbd.1.master]
-FileSystemPath= /home/jonas/atrt/cluster.master/ndbd.1
-
-[cluster_config.ndbd.2.master]
-FileSystemPath= /home/jonas/atrt/cluster.master/ndbd.2
-
-[mysqld.1.master]
-datadir= /home/jonas/atrt/cluster.master/mysqld.1
-socket= /home/jonas/atrt/cluster.master/mysqld.1/mysql.sock
-port= 10001
-server-id= 1
-log-bin
-ndb-connectstring= local1:10000
-ndbcluster
-
-[client.1.master]
-socket= /home/jonas/atrt/cluster.master/mysqld.1/mysql.sock
-port= 10001
-
-[mysqld.2.master]
-datadir= /home/jonas/atrt/cluster.master/mysqld.2
-socket= /home/jonas/atrt/cluster.master/mysqld.2/mysql.sock
-port= 10002
-server-id= 2
-log-bin
-ndb-connectstring= local1:10000
-ndbcluster
-
-[client.2.master]
-socket= /home/jonas/atrt/cluster.master/mysqld.2/mysql.sock
-port= 10002
-
-[mysql_cluster.slave]
-ndb-connectstring= local1:10003
-
-[cluster_config.ndb_mgmd.1.slave]
-PortNumber= 10003
-
-[cluster_config.ndbd.1.slave]
-FileSystemPath= /home/jonas/atrt/cluster.slave/ndbd.1
-
-[mysqld.1.slave]
-datadir= /home/jonas/atrt/cluster.slave/mysqld.1
-socket= /home/jonas/atrt/cluster.slave/mysqld.1/mysql.sock
-port= 10004
-server-id= 3
-master-host= local1
-master-port= 10001
-master-user= root
-master-password= ""
-ndb-connectstring= local1:10003
-ndbcluster
-
-[client.1.slave]
-socket= /home/jonas/atrt/cluster.slave/mysqld.1/mysql.sock
-port= 10004
-
-[mysqld.2.slave]
-datadir= /home/jonas/atrt/cluster.slave/mysqld.2
-socket= /home/jonas/atrt/cluster.slave/mysqld.2/mysql.sock
-port= 10005
-server-id= 4
-master-host= local1
-master-port= 10002
-master-user= root
-master-password= ""
-ndb-connectstring= local1:10003
-ndbcluster
-
-[client.2.slave]
-socket= /home/jonas/atrt/cluster.slave/mysqld.2/mysql.sock
-port= 10005
-
diff --git a/storage/ndb/test/run-test/example.conf b/storage/ndb/test/run-test/example.conf
deleted file mode 100644
index 1e152da332d..00000000000
--- a/storage/ndb/test/run-test/example.conf
+++ /dev/null
@@ -1,10 +0,0 @@
-target=pc-linux-i686
-base_dir=/ndb
-src_clone_base=mysqldev@bk-internal.mysql.com:/home/bk/mysql
-run_dir=/space/autotest
-build_dir=/ndb
-hosts="ndb01 ndb02 ndb03 ndb04 ndb05 ndb06 ndb07 ndb08 ndb09 ndb10 ndb11 ndb12"
-result_host="ndb.mysql.com"
-result_path="public_html"
-configure='CC=gcc CXX=gcc CFLAGS="-Wall -pedantic -Wno-long-long" CXXFLAGS="-Wall -pedantic -Wno-long-long" ./configure --with-ndbcluster --with-ndb-test --with-ndbcc-flags="-g -DERROR_INSERT"'
-
diff --git a/storage/ndb/test/run-test/files.cpp b/storage/ndb/test/run-test/files.cpp
deleted file mode 100644
index 294d0aca56e..00000000000
--- a/storage/ndb/test/run-test/files.cpp
+++ /dev/null
@@ -1,402 +0,0 @@
-/*
- Copyright (c) 2007 MySQL AB
- Use is subject to license terms.
-
- 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-#include "atrt.hpp"
-#include <sys/types.h>
-#include <dirent.h>
-
-static bool create_directory(const char * path);
-
-bool
-setup_directories(atrt_config& config, int setup)
-{
- /**
- * 0 = validate
- * 1 = setup
- * 2 = setup+clean
- */
- for (size_t i = 0; i < config.m_clusters.size(); i++)
- {
- atrt_cluster& cluster = *config.m_clusters[i];
- for (size_t j = 0; j<cluster.m_processes.size(); j++)
- {
- atrt_process& proc = *cluster.m_processes[j];
- const char * dir = proc.m_proc.m_cwd.c_str();
- struct stat sbuf;
- int exists = 0;
- if (lstat(dir, &sbuf) == 0)
- {
- if (S_ISDIR(sbuf.st_mode))
- exists = 1;
- else
- exists = -1;
- }
-
- switch(setup){
- case 0:
- switch(exists){
- case 0:
- g_logger.error("Could not find directory: %s", dir);
- return false;
- case -1:
- g_logger.error("%s is not a directory!", dir);
- return false;
- }
- break;
- case 1:
- if (exists == -1)
- {
- g_logger.error("%s is not a directory!", dir);
- return false;
- }
- break;
- case 2:
- if (exists == 1)
- {
- if (!remove_dir(dir))
- {
- g_logger.error("Failed to remove %s!", dir);
- return false;
- }
- exists = 0;
- break;
- }
- else if (exists == -1)
- {
- if (!unlink(dir))
- {
- g_logger.error("Failed to remove %s!", dir);
- return false;
- }
- exists = 0;
- }
- }
- if (exists != 1)
- {
- if (!create_directory(dir))
- {
- return false;
- }
- }
- }
- }
- return true;
-}
-
-static
-void
-printfile(FILE* out, Properties& props, const char * section, ...)
-{
- Properties::Iterator it (&props);
- const char * name = it.first();
- if (name)
- {
- va_list ap;
- va_start(ap, section);
- /* const int ret = */ vfprintf(out, section, ap);
- va_end(ap);
- fprintf(out, "\n");
-
- for (; name; name = it.next())
- {
- const char* val;
- props.get(name, &val);
- fprintf(out, "%s %s\n", name + 2, val);
- }
- fprintf(out, "\n");
- }
- fflush(out);
-}
-
-bool
-setup_files(atrt_config& config, int setup, int sshx)
-{
- /**
- * 0 = validate
- * 1 = setup
- * 2 = setup+clean
- */
- BaseString mycnf;
- mycnf.assfmt("%s/my.cnf", g_basedir);
-
- if (mycnf != g_my_cnf)
- {
- struct stat sbuf;
- int ret = lstat(mycnf.c_str(), &sbuf);
-
- if (ret == 0)
- {
- if (unlink(mycnf.c_str()) != 0)
- {
- g_logger.error("Failed to remove %s", mycnf.c_str());
- return false;
- }
- }
-
- BaseString cp = "cp ";
- cp.appfmt("%s %s", g_my_cnf, mycnf.c_str());
- if (system(cp.c_str()) != 0)
- {
- g_logger.error("Failed to '%s'", cp.c_str());
- return false;
- }
- }
-
- if (setup == 2 || config.m_generated)
- {
- /**
- * Do mysql_install_db
- */
- for (size_t i = 0; i < config.m_clusters.size(); i++)
- {
- atrt_cluster& cluster = *config.m_clusters[i];
- for (size_t j = 0; j<cluster.m_processes.size(); j++)
- {
- atrt_process& proc = *cluster.m_processes[j];
- if (proc.m_type == atrt_process::AP_MYSQLD)
- {
- const char * val;
- require(proc.m_options.m_loaded.get("--datadir=", &val));
- BaseString tmp;
- tmp.assfmt("%s/bin/mysql_install_db --defaults-file=%s/my.cnf --datadir=%s > /dev/null 2>&1",
- g_prefix, g_basedir, val);
- if (system(tmp.c_str()) != 0)
- {
- g_logger.error("Failed to mysql_install_db for %s, cmd: >%s<",
- proc.m_proc.m_cwd.c_str(),
- tmp.c_str());
- }
- else
- {
- g_logger.info("mysql_install_db for %s",
- proc.m_proc.m_cwd.c_str());
- }
- }
- }
- }
- }
-
- FILE * out = NULL;
- if (config.m_generated == false)
- {
- g_logger.info("Nothing configured...");
- }
- else
- {
- out = fopen(mycnf.c_str(), "a+");
- if (out == 0)
- {
- g_logger.error("Failed to open %s for append", mycnf.c_str());
- return false;
- }
- time_t now = time(0);
- fprintf(out, "#\n# Generated by atrt\n");
- fprintf(out, "# %s\n", ctime(&now));
- }
-
- for (size_t i = 0; i < config.m_clusters.size(); i++)
- {
- atrt_cluster& cluster = *config.m_clusters[i];
- if (out)
- {
- Properties::Iterator it(&cluster.m_options.m_generated);
- printfile(out, cluster.m_options.m_generated,
- "[mysql_cluster%s]", cluster.m_name.c_str());
- }
-
- for (size_t j = 0; j<cluster.m_processes.size(); j++)
- {
- atrt_process& proc = *cluster.m_processes[j];
-
- if (out)
- {
- switch(proc.m_type){
- case atrt_process::AP_NDB_MGMD:
- printfile(out, proc.m_options.m_generated,
- "[cluster_config.ndb_mgmd.%d%s]",
- proc.m_index, proc.m_cluster->m_name.c_str());
- break;
- case atrt_process::AP_NDBD:
- printfile(out, proc.m_options.m_generated,
- "[cluster_config.ndbd.%d%s]",
- proc.m_index, proc.m_cluster->m_name.c_str());
- break;
- case atrt_process::AP_MYSQLD:
- printfile(out, proc.m_options.m_generated,
- "[mysqld.%d%s]",
- proc.m_index, proc.m_cluster->m_name.c_str());
- break;
- case atrt_process::AP_NDB_API:
- break;
- case atrt_process::AP_CLIENT:
- printfile(out, proc.m_options.m_generated,
- "[client.%d%s]",
- proc.m_index, proc.m_cluster->m_name.c_str());
- break;
- case atrt_process::AP_ALL:
- case atrt_process::AP_CLUSTER:
- abort();
- }
- }
-
- /**
- * Create env.sh
- */
- BaseString tmp;
- tmp.assfmt("%s/env.sh", proc.m_proc.m_cwd.c_str());
- char **env = BaseString::argify(0, proc.m_proc.m_env.c_str());
- if (env[0])
- {
- Vector<BaseString> keys;
- FILE *fenv = fopen(tmp.c_str(), "w+");
- if (fenv == 0)
- {
- g_logger.error("Failed to open %s for writing", tmp.c_str());
- return false;
- }
- for (size_t k = 0; env[k]; k++)
- {
- tmp = env[k];
- int pos = tmp.indexOf('=');
- require(pos > 0);
- env[k][pos] = 0;
- fprintf(fenv, "%s=\"%s\"\n", env[k], env[k]+pos+1);
- keys.push_back(env[k]);
- free(env[k]);
- }
- fprintf(fenv, "PATH=%s/bin:%s/libexec:$PATH\n", g_prefix, g_prefix);
- keys.push_back("PATH");
- for (size_t k = 0; k<keys.size(); k++)
- fprintf(fenv, "export %s\n", keys[k].c_str());
- fflush(fenv);
- fclose(fenv);
- }
- free(env);
-
- tmp.assfmt("%s/ssh-login.sh", proc.m_proc.m_cwd.c_str());
- FILE* fenv = fopen(tmp.c_str(), "w+");
- if (fenv == 0)
- {
- g_logger.error("Failed to open %s for writing", tmp.c_str());
- return false;
- }
- fprintf(fenv, "#!/bin/sh\n");
- fprintf(fenv, "cd %s\n", proc.m_proc.m_cwd.c_str());
- fprintf(fenv, "[ -f /etc/profile ] && . /etc/profile\n");
- fprintf(fenv, ". env.sh\n");
- fprintf(fenv, "ulimit -Sc unlimited\n");
- fprintf(fenv, "bash -i");
- fflush(fenv);
- fclose(fenv);
- }
- }
-
- if (out)
- {
- fflush(out);
- fclose(out);
- }
-
- return true;
-}
-
-static
-bool
-create_directory(const char * path)
-{
- BaseString tmp(path);
- Vector<BaseString> list;
- if (tmp.split(list, "/") == 0)
- {
- g_logger.error("Failed to create directory: %s", tmp.c_str());
- return false;
- }
-
- BaseString cwd = "/";
- for (size_t i = 0; i < list.size(); i++)
- {
- cwd.append(list[i].c_str());
- cwd.append("/");
- mkdir(cwd.c_str(), S_IRUSR | S_IWUSR | S_IXUSR | S_IXGRP | S_IRGRP);
- }
-
- struct stat sbuf;
- if (lstat(path, &sbuf) != 0 ||
- !S_ISDIR(sbuf.st_mode))
- {
- g_logger.error("Failed to create directory: %s (%s)",
- tmp.c_str(),
- cwd.c_str());
- return false;
- }
-
- return true;
-}
-
-bool
-remove_dir(const char * path, bool inclusive)
-{
- DIR* dirp = opendir(path);
-
- if (dirp == 0)
- {
- if(errno != ENOENT)
- {
- g_logger.error("Failed to remove >%s< errno: %d %s",
- path, errno, strerror(errno));
- return false;
- }
- return true;
- }
-
- struct dirent * dp;
- BaseString name = path;
- name.append("/");
- while ((dp = readdir(dirp)) != NULL)
- {
- if ((strcmp(".", dp->d_name) != 0) && (strcmp("..", dp->d_name) != 0))
- {
- BaseString tmp = name;
- tmp.append(dp->d_name);
-
- if (remove(tmp.c_str()) == 0)
- {
- continue;
- }
-
- if (!remove_dir(tmp.c_str()))
- {
- closedir(dirp);
- return false;
- }
- }
- }
-
- closedir(dirp);
- if (inclusive)
- {
- if (rmdir(path) != 0)
- {
- g_logger.error("Failed to remove >%s< errno: %d %s",
- path, errno, strerror(errno));
- return false;
- }
- }
- return true;
-}
-
diff --git a/storage/ndb/test/run-test/main.cpp b/storage/ndb/test/run-test/main.cpp
deleted file mode 100644
index 8618081bac7..00000000000
--- a/storage/ndb/test/run-test/main.cpp
+++ /dev/null
@@ -1,1249 +0,0 @@
-/* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-#include "atrt.hpp"
-#include <my_sys.h>
-#include <my_getopt.h>
-
-#include <NdbOut.hpp>
-#include <NdbAutoPtr.hpp>
-
-#include <SysLogHandler.hpp>
-#include <FileLogHandler.hpp>
-
-#include <NdbSleep.h>
-
-#define PATH_SEPARATOR "/"
-
-/** Global variables */
-static const char progname[] = "ndb_atrt";
-static const char * g_gather_progname = "atrt-gather-result.sh";
-static const char * g_analyze_progname = "atrt-analyze-result.sh";
-static const char * g_clear_progname = "atrt-clear-result.sh";
-static const char * g_setup_progname = "atrt-setup.sh";
-
-static const char * g_log_filename = 0;
-static const char * g_test_case_filename = 0;
-static const char * g_report_filename = 0;
-
-static int g_do_setup = 0;
-static int g_do_deploy = 0;
-static int g_do_sshx = 0;
-static int g_do_start = 0;
-static int g_do_quit = 0;
-
-static int g_help = 0;
-static int g_verbosity = 1;
-static FILE * g_report_file = 0;
-static FILE * g_test_case_file = stdin;
-static int g_mode = 0;
-
-Logger g_logger;
-atrt_config g_config;
-const char * g_user = 0;
-int g_baseport = 10000;
-int g_fqpn = 0;
-int g_default_ports = 0;
-
-const char * g_cwd = 0;
-const char * g_basedir = 0;
-const char * g_my_cnf = 0;
-const char * g_prefix = 0;
-const char * g_clusters = 0;
-BaseString g_replicate;
-const char *save_file = 0;
-char *save_extra_file = 0;
-const char *save_group_suffix = 0;
-const char * g_dummy;
-char * g_env_path = 0;
-
-/** Dummy, extern declared in ndb_opts.h */
-int g_print_full_config = 0, opt_ndb_shm;
-my_bool opt_core;
-
-static struct my_option g_options[] =
-{
- { "help", '?', "Display this help and exit.",
- &g_help, &g_help,
- 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
- { "version", 'V', "Output version information and exit.", 0, 0, 0,
- GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 },
- { "clusters", 256, "Cluster",
- &g_clusters, &g_clusters,
- 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
- { "replicate", 1024, "replicate",
- &g_dummy, &g_dummy,
- 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
- { "log-file", 256, "log-file",
- &g_log_filename, &g_log_filename,
- 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
- { "testcase-file", 'f', "testcase-file",
- &g_test_case_filename, &g_test_case_filename,
- 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
- { "report-file", 'r', "report-file",
- &g_report_filename, &g_report_filename,
- 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
- { "basedir", 256, "Base path",
- &g_basedir, &g_basedir,
- 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
- { "baseport", 256, "Base port",
- &g_baseport, &g_baseport,
- 0, GET_INT, REQUIRED_ARG, g_baseport, 0, 0, 0, 0, 0},
- { "prefix", 256, "mysql install dir",
- &g_prefix, &g_prefix,
- 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
- { "verbose", 'v', "Verbosity",
- &g_verbosity, &g_verbosity,
- 0, GET_INT, REQUIRED_ARG, g_verbosity, 0, 0, 0, 0, 0},
- { "configure", 256, "configure",
- &g_do_setup, &g_do_setup,
- 0, GET_INT, REQUIRED_ARG, g_do_setup, 0, 0, 0, 0, 0 },
- { "deploy", 256, "deploy",
- &g_do_deploy, &g_do_deploy,
- 0, GET_INT, REQUIRED_ARG, g_do_deploy, 0, 0, 0, 0, 0 },
- { "sshx", 256, "sshx",
- &g_do_sshx, &g_do_sshx,
- 0, GET_INT, REQUIRED_ARG, g_do_sshx, 0, 0, 0, 0, 0 },
- { "start", 256, "start",
- &g_do_start, &g_do_start,
- 0, GET_INT, REQUIRED_ARG, g_do_start, 0, 0, 0, 0, 0 },
- { "fqpn", 256, "Fully qualified path-names ",
- &g_fqpn, &g_fqpn,
- 0, GET_INT, REQUIRED_ARG, g_fqpn, 0, 0, 0, 0, 0 },
- { "default-ports", 256, "Use default ports when possible",
- &g_default_ports, &g_default_ports,
- 0, GET_INT, REQUIRED_ARG, g_default_ports, 0, 0, 0, 0, 0 },
- { "mode", 256, "Mode 0=interactive 1=regression 2=bench",
- &g_mode, &g_mode,
- 0, GET_INT, REQUIRED_ARG, g_mode, 0, 0, 0, 0, 0 },
- { "quit", 256, "Quit before starting tests",
- &g_mode, &g_do_quit,
- 0, GET_BOOL, NO_ARG, g_do_quit, 0, 0, 0, 0, 0 },
- { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
-};
-
-const int p_ndb = atrt_process::AP_NDB_MGMD | atrt_process::AP_NDBD;
-const int p_servers = atrt_process::AP_MYSQLD;
-const int p_clients = atrt_process::AP_CLIENT | atrt_process::AP_NDB_API;
-
-int
-main(int argc, char ** argv)
-{
- ndb_init();
-
- bool restart = true;
- int lineno = 1;
- int test_no = 1;
- int return_code = 1;
-
- g_logger.setCategory(progname);
- g_logger.enable(Logger::LL_ALL);
- g_logger.createConsoleHandler();
-
- if(!parse_args(argc, argv))
- goto end;
-
- g_logger.info("Starting...");
- g_config.m_generated = false;
- g_config.m_replication = g_replicate;
- if (!setup_config(g_config))
- goto end;
-
- if (!configure(g_config, g_do_setup))
- goto end;
-
- g_logger.info("Setting up directories");
- if (!setup_directories(g_config, g_do_setup))
- goto end;
-
- if (g_do_setup)
- {
- g_logger.info("Setting up files");
- if (!setup_files(g_config, g_do_setup, g_do_sshx))
- goto end;
- }
-
- if (g_do_deploy)
- {
- if (!deploy(g_config))
- goto end;
- }
-
- if (g_do_quit)
- {
- return_code = 0;
- goto end;
- }
-
- if(!setup_hosts(g_config))
- goto end;
-
- if (g_do_sshx)
- {
- g_logger.info("Starting xterm-ssh");
- if (!sshx(g_config, g_do_sshx))
- goto end;
-
- g_logger.info("Done...sleeping");
- while(true)
- {
- NdbSleep_SecSleep(1);
- }
- return_code = 0;
- goto end;
- }
-
- g_logger.info("Connecting to hosts");
- if(!connect_hosts(g_config))
- goto end;
-
- if (g_do_start && !g_test_case_filename)
- {
- g_logger.info("Starting server processes: %x", g_do_start);
- if (!start(g_config, g_do_start))
- goto end;
-
- g_logger.info("Done...sleeping");
- while(true)
- {
- NdbSleep_SecSleep(1);
- }
- return_code = 0;
- goto end;
- }
-
- return_code = 0;
-
- /**
- * Main loop
- */
- while(!feof(g_test_case_file)){
- /**
- * Do we need to restart ndb
- */
- if(restart){
- g_logger.info("(Re)starting server processes processes");
- if(!stop_processes(g_config, ~0))
- goto end;
-
- if (!setup_directories(g_config, 2))
- goto end;
-
- if (!setup_files(g_config, 2, 1))
- goto end;
-
- if(!setup_hosts(g_config))
- goto end;
-
- if (!start(g_config, p_ndb | p_servers))
- goto end;
- g_logger.info("All servers start completed");
- }
-
- // const int start_line = lineno;
- atrt_testcase test_case;
- if(!read_test_case(g_test_case_file, test_case, lineno))
- goto end;
-
- g_logger.info("#%d - %s %s",
- test_no,
- test_case.m_command.c_str(), test_case.m_args.c_str());
-
- // Assign processes to programs
- if(!setup_test_case(g_config, test_case))
- goto end;
-
- if(!start_processes(g_config, p_clients))
- goto end;
-
- int result = 0;
-
- const time_t start = time(0);
- time_t now = start;
- do {
- if(!update_status(g_config, atrt_process::AP_ALL))
- goto end;
-
- int count = 0;
-
- if((count = is_running(g_config, p_ndb)) != 2){
- result = ERR_NDB_FAILED;
- break;
- }
-
- if((count = is_running(g_config, p_servers)) != 2){
- result = ERR_SERVERS_FAILED;
- break;
- }
-
- if((count = is_running(g_config, p_clients)) == 0){
- break;
- }
-
- now = time(0);
- if(now > (start + test_case.m_max_time)){
- result = ERR_MAX_TIME_ELAPSED;
- break;
- }
- NdbSleep_SecSleep(1);
- } while(true);
-
- const time_t elapsed = time(0) - start;
-
- if(!stop_processes(g_config, p_clients))
- goto end;
-
- int tmp, *rp = result ? &tmp : &result;
- if(!gather_result(g_config, rp))
- goto end;
-
- g_logger.info("#%d %s(%d)",
- test_no,
- (result == 0 ? "OK" : "FAILED"), result);
-
- if(g_report_file != 0){
- fprintf(g_report_file, "%s ; %d ; %d ; %ld\n",
- test_case.m_name.c_str(), test_no, result, elapsed);
- fflush(g_report_file);
- }
-
- if(g_mode == 0 && result){
- g_logger.info
- ("Encountered failed test in interactive mode - terminating");
- break;
- }
-
- BaseString resdir;
- resdir.assfmt("result.%d", test_no);
- remove_dir(resdir.c_str(), true);
-
- if(test_case.m_report || g_mode == 2 || (g_mode && result))
- {
- if(rename("result", resdir.c_str()) != 0)
- {
- g_logger.critical("Failed to rename %s as %s",
- "result", resdir.c_str());
- goto end;
- }
- }
- else
- {
- remove_dir("result", true);
- }
-
- if(result != 0){
- restart = true;
- } else {
- restart = false;
- }
- test_no++;
- }
-
- end:
- if(g_report_file != 0){
- fclose(g_report_file);
- g_report_file = 0;
- }
-
- if(g_test_case_file != 0 && g_test_case_file != stdin){
- fclose(g_test_case_file);
- g_test_case_file = 0;
- }
-
- stop_processes(g_config, atrt_process::AP_ALL);
- return return_code;
-}
-
-static
-my_bool
-get_one_option(int arg, const struct my_option * opt, char * value)
-{
- if (arg == 1024)
- {
- if (g_replicate.length())
- g_replicate.append(";");
- g_replicate.append(value);
- return 1;
- }
- return 0;
-}
-
-bool
-parse_args(int argc, char** argv)
-{
- char buf[2048];
- if (getcwd(buf, sizeof(buf)) == 0)
- {
- g_logger.error("Unable to get current working directory");
- return false;
- }
- g_cwd = strdup(buf);
-
- struct stat sbuf;
- BaseString mycnf;
- if (argc > 1 && lstat(argv[argc-1], &sbuf) == 0)
- {
- mycnf.append(g_cwd);
- mycnf.append(PATH_SEPARATOR);
- mycnf.append(argv[argc-1]);
- }
- else
- {
- mycnf.append(g_cwd);
- mycnf.append(PATH_SEPARATOR);
- mycnf.append("my.cnf");
- if (lstat(mycnf.c_str(), &sbuf) != 0)
- {
- g_logger.error("Unable to stat %s", mycnf.c_str());
- return false;
- }
- }
-
- g_logger.info("Bootstrapping using %s", mycnf.c_str());
-
- const char *groups[] = { "atrt", 0 };
- int ret = load_defaults(mycnf.c_str(), groups, &argc, &argv);
-
- save_file = my_defaults_file;
- save_extra_file = my_defaults_extra_file;
- save_group_suffix = my_defaults_group_suffix;
-
- if (save_extra_file)
- {
- g_logger.error("--defaults-extra-file(%s) is not supported...",
- save_extra_file);
- return false;
- }
-
- if (ret || handle_options(&argc, &argv, g_options, get_one_option))
- {
- g_logger.error("Failed to load defaults/handle_options");
- return false;
- }
-
- if (argc >= 2)
- {
- const char * arg = argv[argc-2];
- while(* arg)
- {
- switch(* arg){
- case 'c':
- g_do_setup = (g_do_setup == 0) ? 1 : g_do_setup;
- break;
- case 'C':
- g_do_setup = 2;
- break;
- case 'd':
- g_do_deploy = 1;
- break;
- case 'x':
- g_do_sshx = atrt_process::AP_CLIENT | atrt_process::AP_NDB_API;
- break;
- case 'X':
- g_do_sshx = atrt_process::AP_ALL;
- break;
- case 's':
- g_do_start = p_ndb;
- break;
- case 'S':
- g_do_start = p_ndb | p_servers;
- break;
- case 'f':
- g_fqpn = 1;
- break;
- case 'q':
- g_do_quit = 1;
- break;
- default:
- g_logger.error("Unknown switch '%c'", *arg);
- return false;
- }
- arg++;
- }
- }
-
- if(g_log_filename != 0)
- {
- g_logger.removeConsoleHandler();
- g_logger.addHandler(new FileLogHandler(g_log_filename));
- }
-
- {
- int tmp = Logger::LL_WARNING - g_verbosity;
- tmp = (tmp < Logger::LL_DEBUG ? Logger::LL_DEBUG : tmp);
- g_logger.disable(Logger::LL_ALL);
- g_logger.enable(Logger::LL_ON);
- g_logger.enable((Logger::LoggerLevel)tmp, Logger::LL_ALERT);
- }
-
- if(!g_basedir)
- {
- g_basedir = g_cwd;
- g_logger.info("basedir not specified, using %s", g_basedir);
- }
-
- if (!g_prefix)
- {
- g_prefix = DEFAULT_PREFIX;
- }
-
- /**
- * Add path to atrt-*.sh
- */
- {
- BaseString tmp;
- const char* env = getenv("PATH");
- if (env && strlen(env))
- {
- tmp.assfmt("PATH=%s:%s/mysql-test/ndb",
- env, g_prefix);
- }
- else
- {
- tmp.assfmt("PATH=%s/mysql-test/ndb", g_prefix);
- }
- g_env_path = strdup(tmp.c_str());
- putenv(g_env_path);
- }
-
- if (g_help)
- {
- my_print_help(g_options);
- my_print_variables(g_options);
- return 0;
- }
-
- if(g_test_case_filename)
- {
- g_test_case_file = fopen(g_test_case_filename, "r");
- if(g_test_case_file == 0)
- {
- g_logger.critical("Unable to open file: %s", g_test_case_filename);
- return false;
- }
- if (g_do_setup == 0)
- g_do_setup = 2;
-
- if (g_do_start == 0)
- g_do_start = p_ndb | p_servers;
-
- if (g_mode == 0)
- g_mode = 1;
-
- if (g_do_sshx)
- {
- g_logger.critical("ssx specified...not possible with testfile");
- return false;
- }
- }
-
- if (g_do_setup == 0)
- {
- BaseString tmp;
- tmp.append(g_basedir);
- tmp.append(PATH_SEPARATOR);
- tmp.append("my.cnf");
- if (lstat(tmp.c_str(), &sbuf) != 0)
- {
- g_logger.error("Unable to stat %s", tmp.c_str());
- return false;
- }
-
- if (!S_ISREG(sbuf.st_mode))
- {
- g_logger.error("%s is not a regular file", tmp.c_str());
- return false;
- }
-
- g_my_cnf = strdup(tmp.c_str());
- g_logger.info("Using %s", tmp.c_str());
- }
- else
- {
- g_my_cnf = strdup(mycnf.c_str());
- }
-
- g_logger.info("Using --prefix=\"%s\"", g_prefix);
-
- if(g_report_filename)
- {
- g_report_file = fopen(g_report_filename, "w");
- if(g_report_file == 0)
- {
- g_logger.critical("Unable to create report file: %s", g_report_filename);
- return false;
- }
- }
-
- if (g_clusters == 0)
- {
- g_logger.critical("No clusters specified");
- return false;
- }
-
- g_user = strdup(getenv("LOGNAME"));
-
- return true;
-}
-
-bool
-connect_hosts(atrt_config& config){
- for(size_t i = 0; i<config.m_hosts.size(); i++){
- if(config.m_hosts[i]->m_cpcd->connect() != 0){
- g_logger.error("Unable to connect to cpc %s:%d",
- config.m_hosts[i]->m_cpcd->getHost(),
- config.m_hosts[i]->m_cpcd->getPort());
- return false;
- }
- g_logger.debug("Connected to %s:%d",
- config.m_hosts[i]->m_cpcd->getHost(),
- config.m_hosts[i]->m_cpcd->getPort());
- }
-
- return true;
-}
-
-bool
-connect_ndb_mgm(atrt_process & proc){
- NdbMgmHandle handle = ndb_mgm_create_handle();
- if(handle == 0){
- g_logger.critical("Unable to create mgm handle");
- return false;
- }
- BaseString tmp = proc.m_host->m_hostname;
- const char * val;
- proc.m_options.m_loaded.get("--PortNumber=", &val);
- tmp.appfmt(":%s", val);
-
- if (ndb_mgm_set_connectstring(handle,tmp.c_str()))
- {
- g_logger.critical("Unable to create parse connectstring");
- return false;
- }
-
- if(ndb_mgm_connect(handle, 30, 1, 0) != -1)
- {
- proc.m_ndb_mgm_handle = handle;
- return true;
- }
-
- g_logger.critical("Unable to connect to ndb mgm %s", tmp.c_str());
- return false;
-}
-
-bool
-connect_ndb_mgm(atrt_config& config){
- for(size_t i = 0; i<config.m_processes.size(); i++){
- atrt_process & proc = *config.m_processes[i];
- if((proc.m_type & atrt_process::AP_NDB_MGMD) != 0){
- if(!connect_ndb_mgm(proc)){
- return false;
- }
- }
- }
-
- return true;
-}
-
-static int remap(int i){
- if(i == NDB_MGM_NODE_STATUS_NO_CONTACT) return NDB_MGM_NODE_STATUS_UNKNOWN;
- if(i == NDB_MGM_NODE_STATUS_UNKNOWN) return NDB_MGM_NODE_STATUS_NO_CONTACT;
- return i;
-}
-
-bool
-wait_ndb(atrt_config& config, int goal){
-
- goal = remap(goal);
-
- size_t cnt = 0;
- for (size_t i = 0; i<config.m_clusters.size(); i++)
- {
- atrt_cluster* cluster = config.m_clusters[i];
- /**
- * Get mgm handle for cluster
- */
- NdbMgmHandle handle = 0;
- for(size_t j = 0; j<cluster->m_processes.size(); j++){
- atrt_process & proc = *cluster->m_processes[j];
- if((proc.m_type & atrt_process::AP_NDB_MGMD) != 0){
- handle = proc.m_ndb_mgm_handle;
- break;
- }
- }
-
- if(handle == 0){
- g_logger.critical("Unable to find mgm handle");
- return false;
- }
-
- if(goal == NDB_MGM_NODE_STATUS_STARTED){
- /**
- * 1) wait NOT_STARTED
- * 2) send start
- * 3) wait STARTED
- */
- if(!wait_ndb(config, NDB_MGM_NODE_STATUS_NOT_STARTED))
- return false;
-
- ndb_mgm_start(handle, 0, 0);
- }
-
- struct ndb_mgm_cluster_state * state;
-
- time_t now = time(0);
- time_t end = now + 360;
- int min = remap(NDB_MGM_NODE_STATUS_NO_CONTACT);
- int min2 = goal;
-
- while(now < end){
- /**
- * 1) retreive current state
- */
- state = 0;
- do {
- state = ndb_mgm_get_status(handle);
- if(state == 0){
- const int err = ndb_mgm_get_latest_error(handle);
- g_logger.error("Unable to poll db state: %d %s %s",
- ndb_mgm_get_latest_error(handle),
- ndb_mgm_get_latest_error_msg(handle),
- ndb_mgm_get_latest_error_desc(handle));
- if(err == NDB_MGM_SERVER_NOT_CONNECTED && connect_ndb_mgm(config)){
- g_logger.error("Reconnected...");
- continue;
- }
- return false;
- }
- } while(state == 0);
- NdbAutoPtr<void> tmp(state);
-
- min2 = goal;
- for(int j = 0; j<state->no_of_nodes; j++){
- if(state->node_states[j].node_type == NDB_MGM_NODE_TYPE_NDB){
- const int s = remap(state->node_states[j].node_status);
- min2 = (min2 < s ? min2 : s );
-
- if(s < remap(NDB_MGM_NODE_STATUS_NO_CONTACT) ||
- s > NDB_MGM_NODE_STATUS_STARTED){
- g_logger.critical("Strange DB status during start: %d %d",
- j, min2);
- return false;
- }
-
- if(min2 < min){
- g_logger.critical("wait ndb failed node: %d %d %d %d",
- state->node_states[j].node_id, min, min2, goal);
- }
- }
- }
-
- if(min2 < min){
- g_logger.critical("wait ndb failed %d %d %d", min, min2, goal);
- return false;
- }
-
- if(min2 == goal){
- cnt++;
- goto next;
- }
-
- min = min2;
- now = time(0);
- }
-
- g_logger.critical("wait ndb timed out %d %d %d", min, min2, goal);
- break;
-
-next:
- ;
- }
-
- return cnt == config.m_clusters.size();
-}
-
-bool
-start_process(atrt_process & proc){
- if(proc.m_proc.m_id != -1){
- g_logger.critical("starting already started process: %d", proc.m_index);
- return false;
- }
-
- BaseString tmp = g_setup_progname;
- tmp.appfmt(" %s %s/ %s",
- proc.m_host->m_hostname.c_str(),
- proc.m_proc.m_cwd.c_str(),
- proc.m_proc.m_cwd.c_str());
-
- g_logger.debug("system(%s)", tmp.c_str());
- const int r1 = system(tmp.c_str());
- if(r1 != 0){
- g_logger.critical("Failed to setup process");
- return false;
- }
-
- {
- Properties reply;
- if(proc.m_host->m_cpcd->define_process(proc.m_proc, reply) != 0){
- BaseString msg;
- reply.get("errormessage", msg);
- g_logger.error("Unable to define process: %s", msg.c_str());
- return false;
- }
- }
- {
- Properties reply;
- if(proc.m_host->m_cpcd->start_process(proc.m_proc.m_id, reply) != 0){
- BaseString msg;
- reply.get("errormessage", msg);
- g_logger.error("Unable to start process: %s", msg.c_str());
- return false;
- }
- }
- return true;
-}
-
-bool
-start_processes(atrt_config& config, int types){
- for(size_t i = 0; i<config.m_processes.size(); i++){
- atrt_process & proc = *config.m_processes[i];
- if((types & proc.m_type) != 0 && proc.m_proc.m_path != ""){
- if(!start_process(proc)){
- return false;
- }
- }
- }
- return true;
-}
-
-bool
-stop_process(atrt_process & proc){
- if(proc.m_proc.m_id == -1){
- return true;
- }
-
- {
- Properties reply;
- if(proc.m_host->m_cpcd->stop_process(proc.m_proc.m_id, reply) != 0){
- Uint32 status;
- reply.get("status", &status);
- if(status != 4){
- BaseString msg;
- reply.get("errormessage", msg);
- g_logger.error("Unable to stop process: %s(%d)", msg.c_str(), status);
- return false;
- }
- }
- }
- {
- Properties reply;
- if(proc.m_host->m_cpcd->undefine_process(proc.m_proc.m_id, reply) != 0){
- BaseString msg;
- reply.get("errormessage", msg);
- g_logger.error("Unable to undefine process: %s", msg.c_str());
- return false;
- }
- proc.m_proc.m_id = -1;
- }
- return true;
-}
-
-bool
-stop_processes(atrt_config& config, int types){
- for(size_t i = 0; i<config.m_processes.size(); i++){
- atrt_process & proc = *config.m_processes[i];
- if((types & proc.m_type) != 0){
- if(!stop_process(proc)){
- return false;
- }
- }
- }
- return true;
-}
-
-bool
-update_status(atrt_config& config, int){
-
- Vector<Vector<SimpleCpcClient::Process> > m_procs;
-
- Vector<SimpleCpcClient::Process> dummy;
- m_procs.fill(config.m_hosts.size(), dummy);
- for(size_t i = 0; i<config.m_hosts.size(); i++){
- Properties p;
- config.m_hosts[i]->m_cpcd->list_processes(m_procs[i], p);
- }
-
- for(size_t i = 0; i<config.m_processes.size(); i++){
- atrt_process & proc = *config.m_processes[i];
- if(proc.m_proc.m_id != -1){
- Vector<SimpleCpcClient::Process> &h_procs= m_procs[proc.m_host->m_index];
- bool found = false;
- for(size_t j = 0; j<h_procs.size(); j++){
- if(proc.m_proc.m_id == h_procs[j].m_id){
- found = true;
- proc.m_proc.m_status = h_procs[j].m_status;
- break;
- }
- }
- if(!found){
- g_logger.error("update_status: not found");
- g_logger.error("id: %d host: %s cmd: %s",
- proc.m_proc.m_id,
- proc.m_host->m_hostname.c_str(),
- proc.m_proc.m_path.c_str());
- for(size_t j = 0; j<h_procs.size(); j++){
- g_logger.error("found: %d %s", h_procs[j].m_id,
- h_procs[j].m_path.c_str());
- }
- return false;
- }
- }
- }
- return true;
-}
-
-int
-is_running(atrt_config& config, int types){
- int found = 0, running = 0;
- for(size_t i = 0; i<config.m_processes.size(); i++){
- atrt_process & proc = *config.m_processes[i];
- if((types & proc.m_type) != 0){
- found++;
- if(proc.m_proc.m_status == "running")
- running++;
- }
- }
-
- if(found == running)
- return 2;
- if(running == 0)
- return 0;
- return 1;
-}
-
-
-int
-insert(const char * pair, Properties & p){
- BaseString tmp(pair);
-
- tmp.trim(" \t\n\r");
-
- Vector<BaseString> split;
- tmp.split(split, ":=", 2);
-
- if(split.size() != 2)
- return -1;
-
- p.put(split[0].trim().c_str(), split[1].trim().c_str());
-
- return 0;
-}
-
-bool
-read_test_case(FILE * file, atrt_testcase& tc, int& line){
-
- Properties p;
- int elements = 0;
- char buf[1024];
- while(!feof(file)){
- if(!fgets(buf, 1024, file))
- break;
-
- line++;
- BaseString tmp = buf;
-
- if(tmp.length() > 0 && tmp.c_str()[0] == '#')
- continue;
-
- if(insert(tmp.c_str(), p) != 0)
- break;
-
- elements++;
- }
-
- if(elements == 0){
- if(file == stdin){
- BaseString tmp(buf);
- tmp.trim(" \t\n\r");
- Vector<BaseString> split;
- tmp.split(split, " ", 2);
- tc.m_command = split[0];
- if(split.size() == 2)
- tc.m_args = split[1];
- else
- tc.m_args = "";
- tc.m_max_time = 60000;
- return true;
- }
- return false;
- }
-
- if(!p.get("cmd", tc.m_command)){
- g_logger.critical("Invalid test file: cmd is missing near line: %d", line);
- return false;
- }
-
- if(!p.get("args", tc.m_args))
- tc.m_args = "";
-
- const char * mt = 0;
- if(!p.get("max-time", &mt))
- tc.m_max_time = 60000;
- else
- tc.m_max_time = atoi(mt);
-
- if(p.get("type", &mt) && strcmp(mt, "bench") == 0)
- tc.m_report= true;
- else
- tc.m_report= false;
-
- if(p.get("run-all", &mt) && strcmp(mt, "yes") == 0)
- tc.m_run_all= true;
- else
- tc.m_run_all= false;
-
- if (!p.get("name", &mt))
- {
- tc.m_name.assfmt("%s %s",
- tc.m_command.c_str(),
- tc.m_args.c_str());
- }
- else
- {
- tc.m_name.assign(mt);
- }
-
- return true;
-}
-
-bool
-setup_test_case(atrt_config& config, const atrt_testcase& tc){
- g_logger.debug("system(%s)", g_clear_progname);
- const int r1 = system(g_clear_progname);
- if(r1 != 0){
- g_logger.critical("Failed to clear result");
- return false;
- }
-
- size_t i = 0;
- for(; i<config.m_processes.size(); i++)
- {
- atrt_process & proc = *config.m_processes[i];
- if(proc.m_type == atrt_process::AP_NDB_API || proc.m_type == atrt_process::AP_CLIENT){
- proc.m_proc.m_path = "";
- if (tc.m_command.c_str()[0] != '/')
- {
- proc.m_proc.m_path.appfmt("%s/bin/", g_prefix);
- }
- proc.m_proc.m_path.append(tc.m_command.c_str());
- proc.m_proc.m_args.assign(tc.m_args);
- if(!tc.m_run_all)
- break;
- }
- }
- for(i++; i<config.m_processes.size(); i++){
- atrt_process & proc = *config.m_processes[i];
- if(proc.m_type == atrt_process::AP_NDB_API || proc.m_type == atrt_process::AP_CLIENT){
- proc.m_proc.m_path.assign("");
- proc.m_proc.m_args.assign("");
- }
- }
- return true;
-}
-
-bool
-gather_result(atrt_config& config, int * result){
- BaseString tmp = g_gather_progname;
-
- for(size_t i = 0; i<config.m_hosts.size(); i++)
- {
- tmp.appfmt(" %s:%s/*",
- config.m_hosts[i]->m_hostname.c_str(),
- config.m_hosts[i]->m_basedir.c_str());
- }
-
- g_logger.debug("system(%s)", tmp.c_str());
- const int r1 = system(tmp.c_str());
- if(r1 != 0)
- {
- g_logger.critical("Failed to gather result!");
- return false;
- }
-
- g_logger.debug("system(%s)", g_analyze_progname);
- const int r2 = system(g_analyze_progname);
-
- if(r2 == -1 || r2 == (127 << 8))
- {
- g_logger.critical("Failed to analyze results");
- return false;
- }
-
- * result = r2 ;
- return true;
-}
-
-bool
-setup_hosts(atrt_config& config){
- g_logger.debug("system(%s)", g_clear_progname);
- const int r1 = system(g_clear_progname);
- if(r1 != 0){
- g_logger.critical("Failed to clear result");
- return false;
- }
-
- for(size_t i = 0; i<config.m_hosts.size(); i++){
- BaseString tmp = g_setup_progname;
- tmp.appfmt(" %s %s/ %s/",
- config.m_hosts[i]->m_hostname.c_str(),
- g_basedir,
- config.m_hosts[i]->m_basedir.c_str());
-
- g_logger.debug("system(%s)", tmp.c_str());
- const int r1 = system(tmp.c_str());
- if(r1 != 0){
- g_logger.critical("Failed to setup %s",
- config.m_hosts[i]->m_hostname.c_str());
- return false;
- }
- }
- return true;
-}
-
-bool
-deploy(atrt_config & config)
-{
- for (size_t i = 0; i<config.m_hosts.size(); i++)
- {
- BaseString tmp = g_setup_progname;
- tmp.appfmt(" %s %s/ %s",
- config.m_hosts[i]->m_hostname.c_str(),
- g_prefix,
- g_prefix);
-
- g_logger.info("rsyncing %s to %s", g_prefix,
- config.m_hosts[i]->m_hostname.c_str());
- g_logger.debug("system(%s)", tmp.c_str());
- const int r1 = system(tmp.c_str());
- if(r1 != 0)
- {
- g_logger.critical("Failed to rsync %s to %s",
- g_prefix,
- config.m_hosts[i]->m_hostname.c_str());
- return false;
- }
- }
-
- return true;
-}
-
-bool
-sshx(atrt_config & config, unsigned mask)
-{
- for (size_t i = 0; i<config.m_processes.size(); i++)
- {
- atrt_process & proc = *config.m_processes[i];
-
- BaseString tmp;
- const char * type = 0;
- switch(proc.m_type){
- case atrt_process::AP_NDB_MGMD:
- type = (mask & proc.m_type) ? "ndb_mgmd" : 0;
- break;
- case atrt_process::AP_NDBD:
- type = (mask & proc.m_type) ? "ndbd" : 0;
- break;
- case atrt_process::AP_MYSQLD:
- type = (mask & proc.m_type) ? "mysqld" : 0;
- break;
- case atrt_process::AP_NDB_API:
- type = (mask & proc.m_type) ? "ndbapi" : 0;
- break;
- case atrt_process::AP_CLIENT:
- type = (mask & proc.m_type) ? "client" : 0;
- break;
- default:
- type = "<unknown>";
- }
-
- if (type == 0)
- continue;
-
- tmp.appfmt("xterm -fg black -title \"%s(%s) on %s\""
- " -e 'ssh -t -X %s sh %s/ssh-login.sh' &",
- type,
- proc.m_cluster->m_name.c_str(),
- proc.m_host->m_hostname.c_str(),
- proc.m_host->m_hostname.c_str(),
- proc.m_proc.m_cwd.c_str());
-
- g_logger.debug("system(%s)", tmp.c_str());
- const int r1 = system(tmp.c_str());
- if(r1 != 0)
- {
- g_logger.critical("Failed sshx (%s)",
- tmp.c_str());
- return false;
- }
- NdbSleep_MilliSleep(300); // To prevent xlock problem
- }
-
- return true;
-}
-
-bool
-start(atrt_config & config, unsigned proc_mask)
-{
- if (proc_mask & atrt_process::AP_NDB_MGMD)
- if(!start_processes(g_config, atrt_process::AP_NDB_MGMD))
- return false;
-
- if (proc_mask & atrt_process::AP_NDBD)
- {
- if(!connect_ndb_mgm(g_config)){
- return false;
- }
-
- if(!start_processes(g_config, atrt_process::AP_NDBD))
- return false;
-
- if(!wait_ndb(g_config, NDB_MGM_NODE_STATUS_NOT_STARTED))
- return false;
-
- for(Uint32 i = 0; i<3; i++)
- if(wait_ndb(g_config, NDB_MGM_NODE_STATUS_STARTED))
- goto started;
- return false;
- }
-
-started:
- if(!start_processes(g_config, p_servers & proc_mask))
- return false;
-
- return true;
-}
-
-void
-require(bool x)
-{
- if (!x)
- abort();
-}
-
-template class Vector<Vector<SimpleCpcClient::Process> >;
-template class Vector<atrt_host*>;
-template class Vector<atrt_cluster*>;
-template class Vector<atrt_process*>;
diff --git a/storage/ndb/test/run-test/make-config.sh b/storage/ndb/test/run-test/make-config.sh
deleted file mode 100755
index 8a7c0694c84..00000000000
--- a/storage/ndb/test/run-test/make-config.sh
+++ /dev/null
@@ -1,119 +0,0 @@
-#!/bin/sh
-
-# Copyright (C) 2004, 2005 MySQL AB
-# Use is subject to license terms
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Library 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
-# Library General Public License for more details.
-#
-# You should have received a copy of the GNU Library General Public
-# License along with this library; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301, USA
-
-baseport=""
-basedir=""
-proc_no=1
-node_id=1
-
-d_file=/tmp/d.$$
-dir_file=/tmp/dirs.$$
-config_file=/tmp/config.$$
-cluster_file=/tmp/cluster.$$
-
-add_procs(){
- type=$1; shift
- while [ $# -ne 0 ]
- do
- add_proc $type $1
- shift
- done
-}
-
-add_proc (){
- case $type in
- mgm)
- echo "$proc_no.ndb_mgmd" >> $dir_file
- echo "[ndb_mgmd]" >> $config_file
- echo "Id: $node_id" >> $config_file
- echo "HostName: $2" >> $config_file
- node_id=`expr $node_id + 1`
- ;;
- api)
- echo "$proc_no.ndb_api" >> $dir_file
- echo "[api]" >> $config_file
- echo "Id: $node_id" >> $config_file
- echo "HostName: $2" >> $config_file
- node_id=`expr $node_id + 1`
- ;;
- ndb)
- echo "$proc_no.ndbd" >> $dir_file
- echo "[ndbd]" >> $config_file
- echo "Id: $node_id" >> $config_file
- echo "HostName: $2" >> $config_file
- node_id=`expr $node_id + 1`
- ;;
- mysqld)
- echo "$proc_no.mysqld" >> $dir_file
- echo "[mysqld]" >> $config_file
- echo "Id: $node_id" >> $config_file
- echo "HostName: $2" >> $config_file
- node_id=`expr $node_id + 1`
- ;;
- mysql)
- echo "$proc_no.mysql" >> $dir_file
- ;;
- esac
- proc_no=`expr $proc_no + 1`
-}
-
-
-cnf=/dev/null
-cat $1 | while read line
-do
- case $line in
- baseport:*) baseport=`echo $line | sed 's/baseport[ ]*:[ ]*//g'`;;
- basedir:*) basedir=`echo $line | sed 's/basedir[ ]*:[ ]*//g'`;;
- mgm:*) add_procs mgm `echo $line | sed 's/mgm[ ]*:[ ]*//g'`;;
- api:*) add_procs api `echo $line | sed 's/api[ ]*:[ ]*//g'`;;
- ndb:*) add_procs ndb `echo $line | sed 's/ndb[ ]*:[ ]*//g'`;;
- mysqld:*) add_procs mysqld `echo $line | sed 's/mysqld[ ]*:[ ]*//g'`;;
- mysql:*) add_procs mysql `echo $line | sed 's/mysql[ ]*:[ ]*//g'`;;
- "-- cluster config")
- if [ "$cnf" = "/dev/null" ]
- then
- cnf=$cluster_file
- else
- cnf=/dev/null
- fi
- line="";;
- *) echo $line >> $cnf; line="";;
- esac
- if [ "$line" ]
- then
- echo $line >> $d_file
- fi
-done
-
-cat $dir_file | xargs mkdir -p
-
-if [ -f $cluster_file ]
- then
- cat $cluster_file $config_file >> /tmp/config2.$$
- mv /tmp/config2.$$ $config_file
-fi
-
-for i in `find . -type d -name '*.ndb_mgmd'`
- do
- cp $config_file $i/config.ini
-done
-
-mv $d_file d.txt
-rm -f $config_file $dir_file $cluster_file
diff --git a/storage/ndb/test/run-test/make-html-reports.sh b/storage/ndb/test/run-test/make-html-reports.sh
deleted file mode 100755
index c78034ed609..00000000000
--- a/storage/ndb/test/run-test/make-html-reports.sh
+++ /dev/null
@@ -1,210 +0,0 @@
-#!/bin/sh
-
-# Copyright (C) 2004, 2005 MySQL AB
-# Use is subject to license terms
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Library 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
-# Library General Public License for more details.
-#
-# You should have received a copy of the GNU Library General Public
-# License along with this library; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301, USA
-
-src_dir=$1
-run=$2
-date=$3
-src_file=$src_dir/report.txt
-
-if [ ! -f $src_dir/report.txt ]
-then
- echo "$src_dir/report.txt is missing"
- exit 1
-fi
-
-###
-#
-# General html functions
-trim(){
- echo $*
-}
-
-header(){
- cat <<EOF
-<html><head><title>$*</title></head>
-<body>
-EOF
-}
-
-footer(){
- cat <<EOF
-</body></html>
-EOF
-}
-
-heading(){
- h=$1; shift
- cat <<EOF
-<h$h>$*</h$h>
-EOF
-}
-
-table(){
- echo "<table $*>"
-}
-
-end_table(){
- echo "</table>"
-}
-
-row(){
- echo "<tr>"
-}
-
-end_row(){
- echo "</tr>"
-}
-
-c_column(){
- cat <<EOF
-<td valign=center align=center>$*</td>
-EOF
-}
-
-bold(){
- cat <<EOF
-<b>$*</b>
-EOF
-}
-column(){
- cat <<EOF
-<td valign=center align=left>$*</td>
-EOF
-}
-
-para(){
- cat <<EOF
-<p></p>
-EOF
-}
-
-hr(){
- cat <<EOF
-<hr>
-EOF
-}
-
-# -- Verify
-time_spec(){
- # $1 - secs
- _ts_tmp=$1
-
- _ts_s=`expr $_ts_tmp % 60`
- _ts_tmp=`expr $_ts_tmp / 60`
-
- _ts_m=`expr $_ts_tmp % 60`
- if [ $_ts_tmp -ge 60 ]
- then
- _ts_tmp=`expr $_ts_tmp / 60`
- else
- _ts_tmp=0
- fi
-
- a=3
- _ts_h=$_ts_tmp
-
- if [ $_ts_h -gt 0 ]
- then
- ret="${_ts_h}h"
- fi
-
- [ $_ts_m -gt 0 ] || [ $_ts_h -gt 0 ] && ret="$ret${_ts_m}m"
-
- ret="$ret${_ts_s}s"
- echo $ret
-}
-
-### Main
-
-report_file=$src_dir/report.html
-summary_file=$src_dir/summary.html
-
-passed=0
-failed=0
-total=0
-
-pass(){
- passed=`expr $passed + 1`
-}
-
-fail(){
- failed=`expr $failed + 1`
-}
-
-(
- header Report $run $date
- table "border=1"
- row
- column `bold Test case`
- column `bold Result`
- column `bold Elapsed`
- column `bold Log`
- end_row
-) > $report_file
-
-cat $src_file | while read line
-do
- eval `echo $line | awk -F";" '{ printf("prg=\"%s\"; no=\"%s\"; res=\"%s\"; time=\"%s\"", $1, $2, $3, $4); }'`
-
- prg=`trim $prg`
- no=`trim $no`
- res=`trim $res`
- time=`trim $time`
- res_dir="<a href=\"result.$no/\">log</a>"
-
- ts=`time_spec $time`
- res_txt=""
- case $res in
- 0) pass; res_txt="PASSED";;
- *) fail; res_txt="FAILED";;
- esac
-
- if [ ! -d "$src_dir/result.$no" ]; then res_dir="&nbsp;"; fi
-
- total=`expr $total + $time`
-
- (
- row
- column $prg
- column $res_txt
- column $ts
- column $res_dir
- end_row
- ) >> $report_file
-
- (
- row
- column $run
- column $date
- column $passed
- column $failed
- column `time_spec $total`
- column "<a href=\"result-$run/$date/report.html\">report</a>"
- column "<a href=\"result-$run/$date/log.txt\">log.txt</a>"
- end_row
- ) > $summary_file
-done
-
-(
- end_table
- footer
-) >> $report_file
-
-exit 0
diff --git a/storage/ndb/test/run-test/make-index.sh b/storage/ndb/test/run-test/make-index.sh
deleted file mode 100755
index d1b4d125c95..00000000000
--- a/storage/ndb/test/run-test/make-index.sh
+++ /dev/null
@@ -1,261 +0,0 @@
-#!/bin/sh
-
-# Copyright (c) 2004, 2005 MySQL AB
-# Use is subject to license terms
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Library 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
-# Library General Public License for more details.
-#
-# You should have received a copy of the GNU Library General Public
-# License along with this library; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301, USA
-
-# NAME
-# make-index.sh
-#
-# SYNOPSIS
-# make-index.sh [ -d <dir> ]
-#
-# DESCRIPTION
-#
-# OPTIONS
-#
-# EXAMPLES
-#
-#
-# ENVIRONMENT
-# NDB_PROJ_HOME Home dir for ndb
-#
-# FILES
-# $NDB_PROJ_HOME/lib/funcs.sh general shell script functions
-#
-#
-# SEE ALSO
-#
-# DIAGNOSTICTS
-#
-# VERSION
-# 1.0
-#
-# AUTHOR
-# Jonas Oreland
-#
-
-progname=`basename $0`
-synopsis="make-index.sh [ -d <dir> ]"
-
-: ${NDB_PROJ_HOME:?} # If undefined, exit with error message
-
-: ${NDB_LOCAL_BUILD_OPTIONS:=--} # If undef, set to --. Keeps getopts happy.
- # You may have to experiment a bit
- # to get quoting right (if you need it).
-
-
-. $NDB_PROJ_HOME/lib/funcs.sh # Load some good stuff
-
-# defaults for options related variables
-#
-
-dst_dir=/home/autotest/html
-report_date=`date '+%Y-%m-%d'`
-uniq_id=$$.$$
-verbose=yes
-
-# used if error when parsing the options environment variable
-#
-env_opterr="options environment variable: <<$options>>"
-
-# Option parsing, for the options variable as well as the command line.
-#
-# We want to be able to set options in an environment variable,
-# as well as on the command line. In order not to have to repeat
-# the same getopts information twice, we loop two times over the
-# getopts while loop. The first time, we process options from
-# the options environment variable, the second time we process
-# options from the command line.
-#
-# The things to change are the actual options and what they do.
-#
-#
-
-for optstring in "$options" "" # 1. options variable 2. cmd line
-do
-
- while getopts q:s:R:d: i $optstring # optstring empty => no arg => cmd line
- do
- case $i in
-
- q) verbose="";; # echo important things
- d) dst_dir=$OPTARG;; # Destination directory
- \?) syndie $env_opterr;; # print synopsis and exit
-
- esac
- done
-
- [ -n "$optstring" ] && OPTIND=1 # Reset for round 2, cmdline options
-
- env_opterr= # Round 2 should not use the value
-
-done
-shift `expr $OPTIND - 1`
-
-dst_dir=`abspath $dst_dir`
-
-###
-#
-# General html functions
-header(){
- cat <<EOF
-<html><head><title>$*</title></head>
-<body>
-EOF
-}
-
-footer(){
- cat <<EOF
-</body></html>
-EOF
-}
-
-heading(){
- h=$1; shift
- cat <<EOF
-<h$h>$*</h$h>
-EOF
-}
-
-table(){
- echo "<table $*>"
-}
-
-end_table(){
- echo "</table>"
-}
-
-row(){
- echo "<tr>"
-}
-
-end_row(){
- echo "</tr>"
-}
-
-c_column(){
- cat <<EOF
-<td valign=center align=center>$*</td>
-EOF
-}
-
-bold(){
- cat <<EOF
-<b>$*</b>
-EOF
-}
-column(){
- cat <<EOF
-<td valign=center align=left>$*</td>
-EOF
-}
-
-para(){
- cat <<EOF
-<p></p>
-EOF
-}
-
-hr(){
- cat <<EOF
-<hr>
-EOF
-}
-
-inc_summary() {
- grep -v 'html>' $2 | grep -v body | sed 's/href="/href="'$1'\//g'
-}
-
-# --- option parsing done ---
-
-
-
-# -- Verify
-trace "Verifying arguments"
-
-# --- option verifying done ---
-
-### Main
-
-# Re creating index
-trace "Creating index"
-(
- header "Autotest super-duper index"
- heading 1 "<center>Autotest super-duper index</center>"
- cat -E README.autotest | sed 's/\$/<BR>/g'
- echo "<br>"
- echo "Current <a href="crontab.current">crontab</a> installed on mc01 running [" `uname -a` "]"
- hr
-
- dirs=`find $dst_dir -name 'summary.*.html' -type f -maxdepth 2 -exec dirname {} \; | sort -u`
-
- dates=`find $dst_dir -name 'summary.*.html' -type f -maxdepth 2 -exec basename {} \; | sed 's/summary\.\(.*\)\.html/\1/g' | sort -u | sort -r`
-
- echo "<p align=center>"
-
-#inline 5 latest reports
- r_count=5
- for d in $dates
- do
- for o in $dirs
- do
- o=`basename $o`
- if [ -r $dst_dir/$o/summary.$d.html ]
- then
- inc_summary $o $dst_dir/$o/summary.$d.html
- hr
-
- r_count=`expr $r_count - 1`
- if [ $r_count -eq 0 ]
- then
- break 2
- fi
- fi
- done
- done
-
- table "border=1"
- row
- for i in $dirs
- do
- i=`basename $i`
- column `bold $i`
- done
- end_row
-
-
- for d in $dates
- do
- row
- for o in $dirs
- do
- o=`basename $o`
- if [ -r $dst_dir/$o/summary.$d.html ]
- then
- column "<a href=$o/summary.$d.html>$d</a>"
- else
- column ""
- fi
- done
- end_row
- done
- end_table
- footer
-) > $dst_dir/index.html
-
-exit 0
diff --git a/storage/ndb/test/run-test/ndb-autotest.sh b/storage/ndb/test/run-test/ndb-autotest.sh
deleted file mode 100755
index a8a009eeaf3..00000000000
--- a/storage/ndb/test/run-test/ndb-autotest.sh
+++ /dev/null
@@ -1,424 +0,0 @@
-#!/bin/sh
-
-# Copyright (C) 2005, 2006 MySQL AB
-# Use is subject to license terms
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Library 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
-# Library General Public License for more details.
-#
-# You should have received a copy of the GNU Library General Public
-# License along with this library; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301, USA
-
-#############################################################
-# This script created by Jonas does the following #
-# Cleans up clones and pevious builds, pulls new clones, #
-# builds, deploys, configures the tests and launches ATRT #
-#############################################################
-
-###############
-#Script setup #
-##############
-
-save_args=$*
-VERSION="ndb-autotest.sh version 1.04"
-
-DATE=`date '+%Y-%m-%d'`
-HOST=`hostname -s`
-export DATE HOST
-
-set -e
-ulimit -Sc unlimited
-
-echo "`date` starting: $*"
-
-RSYNC_RSH=ssh
-export RSYNC_RSH
-
-verbose=0
-do_clone=yes
-build=yes
-deploy=yes
-run_test=yes
-config=yes
-report=yes
-
-clone=5.0-ndb
-RUN="daily-basic daily-devel"
-conf=autotest.conf
-LOCK=$HOME/.autotest-lock
-
-############################
-# Read command line entries#
-############################
-
-while [ "$1" ]
-do
- case "$1" in
- --no-clone) do_clone="";;
- --no-build) build="";;
- --no-deploy) deploy="";;
- --no-test) run_test="";;
- --no-config) config="";;
- --no-report) report="";;
- --verbose) verbose=`expr $verbose + 1`;;
- --clone=*) clone=`echo $1 | sed s/--clone=//`;;
- --conf=*) conf=`echo $1 | sed s/--conf=//`;;
- --version) echo $VERSION; exit;;
- *) RUN=$*;;
- esac
- shift
-done
-
-#################################
-#Make sure the configfile exists#
-#if it does not exit. if it does#
-# (.) load it #
-#################################
-
-if [ -f $conf ]
-then
- . $conf
-else
- echo "Can't find config file: $conf"
- exit
-fi
-
-###############################
-# Validate that all interesting
-# variables where set in conf
-###############################
-vars="target base_dir src_clone_base install_dir build_dir hosts configure"
-if [ "$report" ]
-then
- vars="$vars result_host result_path"
-fi
-for i in $vars
-do
- t=`echo echo \\$$i`
- if [ -z "`eval $t`" ]
- then
- echo "Invalid config: $conf, variable $i is not set"
- exit
- fi
-done
-
-###############################
-#Print out the enviroment vars#
-###############################
-
-if [ $verbose -gt 0 ]
-then
- env
-fi
-
-####################################
-# Setup the lock file name and path#
-# Setup the clone source location #
-####################################
-
-src_clone=$src_clone_base-$clone
-
-#######################################
-# Check to see if the lock file exists#
-# If it does exit. #
-#######################################
-
-if [ -f $LOCK ]
-then
- echo "Lock file exists: $LOCK"
- exit 1
-fi
-
-#######################################
-# If the lock file does not exist then#
-# create it with date and run info #
-#######################################
-
-echo "$DATE $RUN" > $LOCK
-
-#############################
-#If any errors here down, we#
-# trap them, and remove the #
-# Lock file before exit #
-#############################
-if [ `uname -s` != "SunOS" ]
-then
- trap "rm -f $LOCK" ERR
-fi
-
-# You can add more to this path#
-################################
-
-dst_place=${build_dir}/clone-mysql-$clone-$DATE
-
-#########################################
-# Delete source and pull down the latest#
-#########################################
-
-if [ "$do_clone" ]
-then
- rm -rf $dst_place
- bk clone $src_clone $dst_place
-fi
-
-##########################################
-# Build the source, make installs, and #
-# create the database to be rsynced #
-##########################################
-
-if [ "$build" ]
-then
- cd $dst_place
- rm -rf $install_dir/*
- if [ -x BUILD/autorun.sh ]
- then
- ./BUILD/autorun.sh
- else
- aclocal; autoheader; autoconf; automake
- if [ -d storage ]
- then
- (cd storage/innobase; aclocal; autoheader; autoconf; automake)
- else
- (cd innobase; aclocal; autoheader; autoconf; automake)
- fi
- fi
- eval $configure --prefix=$install_dir
- make
- make install
- (cd $install_dir; ./bin/mysql_install_db) # This will be rsynced to all
-fi
-
-################################
-# check script version. If the #
-# version is old, replace it #
-# and restart #
-################################
-
-script=$install_dir/mysql-test/ndb/ndb-autotest.sh
-if [ -x $script ]
-then
- $script --version > /tmp/version.$$
-else
- echo $VERSION > /tmp/version.$$
-fi
-match=`grep -c "$VERSION" /tmp/version.$$ | xargs echo`
-rm -f /tmp/version.$$
-if [ $match -eq 0 ]
-then
- echo "Incorrect script version...restarting"
- cp $install_dir/mysql-test/ndb/ndb-autotest.sh /tmp/at.$$.sh
- rm -rf $install_dir $dst_place
- sh /tmp/at.$$.sh $save_args
- exit
-fi
-
-###############################################
-# Check that all interesting files are present#
-###############################################
-
-test_dir=$install_dir/mysql-test/ndb
-atrt=$test_dir/atrt
-html=$test_dir/make-html-reports.sh
-mkconfig=$install_dir/mysql-test/ndb/make-config.sh
-
-##########################
-#Setup bin and test paths#
-##########################
-
-PATH=$install_dir/bin:$test_dir:$PATH
-export PATH
-
-###########################
-# This will filter out all#
-# the host that did not #
-# respond. Called below #
-###########################
-
-filter(){
- neg=$1
- shift
- while [ $# -gt 0 ]
- do
- if [ `grep -c $1 $neg | xargs echo` -eq 0 ] ; then echo $1; fi
- shift
- done
-}
-
-############################
-# check ndb_cpcc fail hosts#
-############################
-ndb_cpcc $hosts | awk '{ if($1=="Failed"){ print;}}' > /tmp/failed.$DATE
-filter /tmp/failed.$DATE $hosts > /tmp/hosts.$DATE
-hosts=`cat /tmp/hosts.$DATE`
-
-#############################
-# Push bin and test to hosts#
-#############################
-
-if [ "$deploy" ]
-then
- for i in $hosts
- do
- rsync -a --delete --force --ignore-errors $install_dir/ $i:$install_dir
- ok=$?
- if [ $ok -ne 0 ]
- then
- echo "$i failed during rsync, excluding"
- echo $i >> /tmp/failed.$DATE
- fi
- done
-fi
-
-###
-# handle scp failed hosts
-#
-filter /tmp/failed.$DATE $hosts > /tmp/hosts.$DATE
-hosts=`cat /tmp/hosts.$DATE`
-cat /tmp/failed.$DATE > /tmp/filter_hosts.$$
-
-#############################
-# Function for replacing the#
-# choose host with real host#
-# names. Note $$ = PID #
-#############################
-choose(){
- SRC=$1
- TMP1=/tmp/choose.$$
- TMP2=/tmp/choose.$$.$$
- shift
-
- cp $SRC $TMP1
- i=1
- while [ $# -gt 0 ]
- do
- sed -e s,"CHOOSE_host$i",$1,g < $TMP1 > $TMP2
- mv $TMP2 $TMP1
- shift
- i=`expr $i + 1`
- done
- cat $TMP1
- rm -f $TMP1
-}
-
-choose_conf(){
- if [ -f $test_dir/conf-$1-$HOST.txt ]
- then
- echo "$test_dir/conf-$1-$HOST.txt"
- elif [ -f $test_dir/conf-$1.txt ]
- then
- echo "$test_dir/conf-$1.txt"
- elif [ -f $test_dir/conf-$HOST.txt ]
- echo "$test_dir/conf-$HOST.txt"
- else
- echo "Unable to find conf file looked for" 1>&2
- echo "$test_dir/conf-$1-$HOST.txt and" 1>&2
- echo "$test_dir/conf-$HOST.txt" 1>&2
- echo "$test_dir/conf-$1.txt" 1>&2
- exit
- fi
-}
-######################################
-# Starts ATRT and gives it the right #
-# command line options. after it #
-# Gathers results and moves them #
-######################################
-start(){
- rm -rf report.txt result* log.txt
- $atrt -v -v -r -R --log-file=log.txt --testcase-file=$test_dir/$2-tests.txt &
- pid=$!
- echo $pid > run.pid
- wait $pid
- rm run.pid
- [ -f log.txt ] && mv log.txt $3
- [ -f report.txt ] && mv report.txt $3
- [ "`find . -name 'result*'`" ] && mv result* $3
- cd $3
- sh $html . $1 $DATE
- cd ..
- p2=`pwd`
- cd ..
- if [ "$report" ]
- then
- tar cfz /tmp/res.$2.$$.tgz `basename $p2`/$DATE
- scp /tmp/res.$2.$$.tgz \
- $result_host:$result_path/res.$DATE.$HOST.$2.$$.tgz
- if [ $? -eq 0 ]
- then
- rm -f /tmp/res.$2.$$.tgz
- fi
- fi
-}
-
-#########################################
-# Count how many computers we have ready#
-#########################################
-
-count_hosts(){
- cnt=`grep "CHOOSE_host" $1 | awk '{for(i=1; i<=NF;i++) \
- if(index($i, "CHOOSE_host") > 0) print $i;}' | sort | uniq | wc -l`
- echo $cnt
-}
-#######################################################
-# Calls: Choose #
-# Choose_host #
-# Count_host #
-# start #
-# for each directory in the $RUN variable #
-#######################################################
-
-p=`pwd`
-for dir in $RUN
-do
- echo "Fixing hosts for $dir"
-
- run_dir=$base_dir/run-$dir-mysql-$clone-$target
- res_dir=$base_dir/result-$dir-mysql-$clone-$target/$DATE
-
- mkdir -p $run_dir $res_dir
- rm -rf $res_dir/*
- cd $run_dir
-
- if [ "$config" ]
- then
- rm -rf $run_dir/*
-
- conf=`choose_conf $dir`
- count=`count_hosts $conf`
- avail_hosts=`filter /tmp/filter_hosts.$$ $hosts`
- avail=`echo $avail_hosts | wc -w`
- if [ $count -gt $avail ]
- then
- echo "Not enough hosts"
- echo "Needs: $count available: $avail ($avail_hosts)"
- break;
- fi
-
- run_hosts=`echo $avail_hosts| \
- awk '{for(i=1;i<='$count';i++)print $i;}'`
- echo $run_hosts >> /tmp/filter_hosts.$$
-
- choose $conf $run_hosts > d.tmp.$$
- sed -e s,CHOOSE_dir,"$install_dir",g < d.tmp.$$ > d.tmp
- $mkconfig d.tmp
- fi
-
- if [ "$run_test" ]
- then
- start $dir-mysql-$clone-$target $dir $res_dir &
- fi
-done
-cd $p
-rm /tmp/filter_hosts.$$
-
-wait
-
-rm -f $LOCK
diff --git a/storage/ndb/test/run-test/setup.cpp b/storage/ndb/test/run-test/setup.cpp
deleted file mode 100644
index 52fbe5a8e8e..00000000000
--- a/storage/ndb/test/run-test/setup.cpp
+++ /dev/null
@@ -1,990 +0,0 @@
-/*
- Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
-
- 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-#include "atrt.hpp"
-#include <ndb_global.h>
-#include <my_sys.h>
-#include <my_getopt.h>
-#include <NdbOut.hpp>
-
-static NdbOut& operator<<(NdbOut& out, const atrt_process& proc);
-static atrt_host * find(const char * hostname, Vector<atrt_host*>&);
-static bool load_process(atrt_config&, atrt_cluster&, atrt_process::Type,
- size_t idx, const char * hostname);
-static bool load_options(int argc, char** argv, int type, atrt_options&);
-
-enum {
- PO_NDB = atrt_options::AO_NDBCLUSTER
-
- ,PO_REP_SLAVE = 256
- ,PO_REP_MASTER = 512
- ,PO_REP = (atrt_options::AO_REPLICATION | PO_REP_SLAVE | PO_REP_MASTER)
-};
-
-struct proc_option
-{
- const char * name;
- int type;
- int options;
-};
-
-static
-struct proc_option f_options[] = {
- { "--FileSystemPath=", atrt_process::AP_NDBD, 0 }
- ,{ "--PortNumber=", atrt_process::AP_NDB_MGMD, 0 }
- ,{ "--datadir=", atrt_process::AP_MYSQLD, 0 }
- ,{ "--socket=", atrt_process::AP_MYSQLD | atrt_process::AP_CLIENT, 0 }
- ,{ "--port=", atrt_process::AP_MYSQLD | atrt_process::AP_CLIENT, 0 }
- ,{ "--server-id=", atrt_process::AP_MYSQLD, PO_REP }
- ,{ "--log-bin", atrt_process::AP_MYSQLD, PO_REP_MASTER }
- ,{ "--master-host=", atrt_process::AP_MYSQLD, PO_REP_SLAVE }
- ,{ "--master-port=", atrt_process::AP_MYSQLD, PO_REP_SLAVE }
- ,{ "--master-user=", atrt_process::AP_MYSQLD, PO_REP_SLAVE }
- ,{ "--master-password=", atrt_process::AP_MYSQLD, PO_REP_SLAVE }
- ,{ "--ndb-connectstring=", atrt_process::AP_MYSQLD | atrt_process::AP_CLUSTER
- ,PO_NDB }
- ,{ "--ndbcluster", atrt_process::AP_MYSQLD, PO_NDB }
- ,{ 0, 0, 0 }
-};
-const char * ndbcs = "--ndb-connectstring=";
-
-bool
-setup_config(atrt_config& config)
-{
- BaseString tmp(g_clusters);
- Vector<BaseString> clusters;
- tmp.split(clusters, ",");
-
- bool fqpn = clusters.size() > 1 || g_fqpn;
-
- size_t j,k;
- for (size_t i = 0; i<clusters.size(); i++)
- {
- struct atrt_cluster *cluster = new atrt_cluster;
- config.m_clusters.push_back(cluster);
-
- cluster->m_name = clusters[i];
- if (fqpn)
- {
- cluster->m_dir.assfmt("cluster%s/", cluster->m_name.c_str());
- }
- else
- {
- cluster->m_dir = "";
- }
-
- int argc = 1;
- const char * argv[] = { "atrt", 0, 0 };
-
- BaseString buf;
- buf.assfmt("--defaults-group-suffix=%s", clusters[i].c_str());
- argv[argc++] = buf.c_str();
- char ** tmp = (char**)argv;
- const char *groups[] = { "cluster_config", 0 };
- int ret = load_defaults(g_my_cnf, groups, &argc, &tmp);
- if (ret)
- {
- g_logger.error("Unable to load defaults for cluster: %s",
- clusters[i].c_str());
- return false;
- }
-
- struct
- {
- atrt_process::Type type;
- const char * name;
- const char * value;
- } proc_args[] = {
- { atrt_process::AP_NDB_MGMD, "--ndb_mgmd=", 0 },
- { atrt_process::AP_NDBD, "--ndbd=", 0 },
- { atrt_process::AP_NDB_API, "--ndbapi=", 0 },
- { atrt_process::AP_NDB_API, "--api=", 0 },
- { atrt_process::AP_MYSQLD, "--mysqld=", 0 },
- { atrt_process::AP_ALL, 0, 0}
- };
-
- /**
- * Find all processes...
- */
- for (j = 0; j<(size_t)argc; j++)
- {
- if (my_getopt_is_args_separator(tmp[j])) /* skip arguments separator */
- continue;
- for (k = 0; proc_args[k].name; k++)
- {
- if (!strncmp(tmp[j], proc_args[k].name, strlen(proc_args[k].name)))
- {
- proc_args[k].value = tmp[j] + strlen(proc_args[k].name);
- break;
- }
- }
- }
-
- /**
- * Load each process
- */
- for (j = 0; proc_args[j].name; j++)
- {
- if (proc_args[j].value)
- {
- BaseString tmp(proc_args[j].value);
- Vector<BaseString> list;
- tmp.split(list, ",");
- for (k = 0; k<list.size(); k++)
- if (!load_process(config, *cluster, proc_args[j].type,
- k + 1, list[k].c_str()))
- return false;
- }
- }
-
- {
- /**
- * Load cluster options
- */
-
- argc = 1;
- argv[argc++] = buf.c_str();
- const char *groups[] = { "mysql_cluster", 0 };
- ret = load_defaults(g_my_cnf, groups, &argc, &tmp);
-
- if (ret)
- {
- g_logger.error("Unable to load defaults for cluster: %s",
- clusters[i].c_str());
- return false;
- }
-
- load_options(argc, tmp, atrt_process::AP_CLUSTER, cluster->m_options);
- }
- }
- return true;
-}
-
-static
-atrt_host *
-find(const char * hostname, Vector<atrt_host*> & hosts){
- for (size_t i = 0; i<hosts.size(); i++){
- if (hosts[i]->m_hostname == hostname){
- return hosts[i];
- }
- }
-
- atrt_host* host = new atrt_host;
- host->m_index = hosts.size();
- host->m_cpcd = new SimpleCpcClient(hostname, 1234);
- host->m_basedir = g_basedir;
- host->m_user = g_user;
- host->m_hostname = hostname;
- hosts.push_back(host);
- return host;
-}
-
-static
-bool
-load_process(atrt_config& config, atrt_cluster& cluster,
- atrt_process::Type type,
- size_t idx,
- const char * hostname)
-{
- atrt_host * host_ptr = find(hostname, config.m_hosts);
- atrt_process *proc_ptr = new atrt_process;
-
- config.m_processes.push_back(proc_ptr);
- host_ptr->m_processes.push_back(proc_ptr);
- cluster.m_processes.push_back(proc_ptr);
-
- atrt_process& proc = *proc_ptr;
-
- const size_t proc_no = config.m_processes.size();
- proc.m_index = idx;
- proc.m_type = type;
- proc.m_host = host_ptr;
- proc.m_cluster = &cluster;
- proc.m_options.m_features = 0;
- proc.m_rep_src = 0;
- proc.m_proc.m_id = -1;
- proc.m_proc.m_type = "temporary";
- proc.m_proc.m_owner = "atrt";
- proc.m_proc.m_group = cluster.m_name.c_str();
- proc.m_proc.m_stdout = "log.out";
- proc.m_proc.m_stderr = "2>&1";
- proc.m_proc.m_runas = proc.m_host->m_user;
- proc.m_proc.m_ulimit = "c:unlimited";
- proc.m_proc.m_env.assfmt("MYSQL_BASE_DIR=%s", g_prefix);
- proc.m_proc.m_env.appfmt(" MYSQL_HOME=%s", g_basedir);
- proc.m_proc.m_shutdown_options = "";
-
- int argc = 1;
- const char * argv[] = { "atrt", 0, 0 };
-
- BaseString buf[10];
- char ** tmp = (char**)argv;
- const char *groups[] = { 0, 0, 0, 0 };
- switch(type){
- case atrt_process::AP_NDB_MGMD:
- groups[0] = "cluster_config";
- buf[1].assfmt("cluster_config.ndb_mgmd.%d", idx);
- groups[1] = buf[1].c_str();
- buf[0].assfmt("--defaults-group-suffix=%s", cluster.m_name.c_str());
- argv[argc++] = buf[0].c_str();
- break;
- case atrt_process::AP_NDBD:
- groups[0] = "cluster_config";
- buf[1].assfmt("cluster_config.ndbd.%d", idx);
- groups[1] = buf[1].c_str();
- buf[0].assfmt("--defaults-group-suffix=%s", cluster.m_name.c_str());
- argv[argc++] = buf[0].c_str();
- break;
- case atrt_process::AP_MYSQLD:
- groups[0] = "mysqld";
- groups[1] = "mysql_cluster";
- buf[0].assfmt("--defaults-group-suffix=.%d%s",idx,cluster.m_name.c_str());
- argv[argc++] = buf[0].c_str();
- break;
- case atrt_process::AP_CLIENT:
- buf[0].assfmt("client.%d%s", idx, cluster.m_name.c_str());
- groups[0] = buf[0].c_str();
- break;
- case atrt_process::AP_NDB_API:
- break;
- default:
- g_logger.critical("Unhandled process type: %d", type);
- return false;
- }
-
- int ret = load_defaults(g_my_cnf, groups, &argc, &tmp);
- if (ret)
- {
- g_logger.error("Unable to load defaults for cluster: %s",
- cluster.m_name.c_str());
- return false;
- }
-
- load_options(argc, tmp, type, proc.m_options);
-
- BaseString dir;
- dir.assfmt("%s/%s",
- proc.m_host->m_basedir.c_str(),
- cluster.m_dir.c_str());
-
- switch(type){
- case atrt_process::AP_NDB_MGMD:
- {
- proc.m_proc.m_name.assfmt("%d-%s", proc_no, "ndb_mgmd");
- proc.m_proc.m_path.assign(g_prefix).append("/libexec/ndb_mgmd");
- proc.m_proc.m_args.assfmt("--defaults-file=%s/my.cnf",
- proc.m_host->m_basedir.c_str());
- proc.m_proc.m_args.appfmt(" --defaults-group-suffix=%s",
- cluster.m_name.c_str());
- proc.m_proc.m_args.append(" --nodaemon --mycnf");
- proc.m_proc.m_cwd.assfmt("%sndb_mgmd.%d", dir.c_str(), proc.m_index);
- proc.m_proc.m_env.appfmt(" MYSQL_GROUP_SUFFIX=%s",
- cluster.m_name.c_str());
- break;
- }
- case atrt_process::AP_NDBD:
- {
- proc.m_proc.m_name.assfmt("%d-%s", proc_no, "ndbd");
- proc.m_proc.m_path.assign(g_prefix).append("/libexec/ndbd");
- proc.m_proc.m_args.assfmt("--defaults-file=%s/my.cnf",
- proc.m_host->m_basedir.c_str());
- proc.m_proc.m_args.appfmt(" --defaults-group-suffix=%s",
- cluster.m_name.c_str());
- proc.m_proc.m_args.append(" --nodaemon -n");
- proc.m_proc.m_cwd.assfmt("%sndbd.%d", dir.c_str(), proc.m_index);
- proc.m_proc.m_env.appfmt(" MYSQL_GROUP_SUFFIX=%s",
- cluster.m_name.c_str());
- break;
- }
- case atrt_process::AP_MYSQLD:
- {
- proc.m_proc.m_name.assfmt("%d-%s", proc_no, "mysqld");
- proc.m_proc.m_path.assign(g_prefix).append("/libexec/mysqld");
- proc.m_proc.m_args.assfmt("--defaults-file=%s/my.cnf",
- proc.m_host->m_basedir.c_str());
- proc.m_proc.m_args.appfmt(" --defaults-group-suffix=.%d%s",
- proc.m_index,
- cluster.m_name.c_str());
- proc.m_proc.m_args.append(" --core-file");
- proc.m_proc.m_cwd.appfmt("%smysqld.%d", dir.c_str(), proc.m_index);
- proc.m_proc.m_shutdown_options = "SIGKILL"; // not nice
- proc.m_proc.m_env.appfmt(" MYSQL_GROUP_SUFFIX=.%d%s",
- proc.m_index,
- cluster.m_name.c_str());
- break;
- }
- case atrt_process::AP_NDB_API:
- {
- proc.m_proc.m_name.assfmt("%d-%s", proc_no, "ndb_api");
- proc.m_proc.m_path = "";
- proc.m_proc.m_args = "";
- proc.m_proc.m_cwd.appfmt("%sndb_api.%d", dir.c_str(), proc.m_index);
- proc.m_proc.m_env.appfmt(" MYSQL_GROUP_SUFFIX=%s",
- cluster.m_name.c_str());
- break;
- }
- case atrt_process::AP_CLIENT:
- {
- proc.m_proc.m_name.assfmt("%d-%s", proc_no, "mysql");
- proc.m_proc.m_path = "";
- proc.m_proc.m_args = "";
- proc.m_proc.m_cwd.appfmt("%s/client.%d", dir.c_str(), proc.m_index);
- proc.m_proc.m_env.appfmt(" MYSQL_GROUP_SUFFIX=.%d%s",
- proc.m_index,
- cluster.m_name.c_str());
- break;
- }
- case atrt_process::AP_ALL:
- case atrt_process::AP_CLUSTER:
- g_logger.critical("Unhandled process type: %d", proc.m_type);
- return false;
- }
-
- if (proc.m_proc.m_path.length())
- {
- proc.m_proc.m_env.appfmt(" CMD=\"%s", proc.m_proc.m_path.c_str());
- if (proc.m_proc.m_args.length())
- proc.m_proc.m_env.append(" ");
- proc.m_proc.m_env.append(proc.m_proc.m_args);
- proc.m_proc.m_env.append("\" ");
- }
-
- if (type == atrt_process::AP_MYSQLD)
- {
- /**
- * Add a client for each mysqld
- */
- if (!load_process(config, cluster, atrt_process::AP_CLIENT, idx, hostname))
- {
- return false;
- }
- }
-
- if (type == atrt_process::AP_CLIENT)
- {
- proc.m_mysqld = cluster.m_processes[cluster.m_processes.size()-2];
- }
-
- return true;
-}
-
-static
-bool
-load_options(int argc, char** argv, int type, atrt_options& opts)
-{
- for (size_t i = 0; i<(size_t)argc; i++)
- {
- /**
- * Skip the separator for arguments from config file and command
- * line
- */
- if (my_getopt_is_args_separator(argv[i]))
- continue;
- for (size_t j = 0; f_options[j].name; j++)
- {
- const char * name = f_options[j].name;
- const size_t len = strlen(name);
-
- if ((f_options[j].type & type) && strncmp(argv[i], name, len) == 0)
- {
- opts.m_loaded.put(name, argv[i]+len, true);
- break;
- }
- }
- }
- return true;
-}
-
-struct proc_rule_ctx
-{
- int m_setup;
- atrt_config* m_config;
- atrt_host * m_host;
- atrt_cluster* m_cluster;
- atrt_process* m_process;
-};
-
-struct proc_rule
-{
- int type;
- bool (* func)(Properties& prop, proc_rule_ctx&, int extra);
- int extra;
-};
-
-static bool pr_check_replication(Properties&, proc_rule_ctx&, int);
-static bool pr_check_features(Properties&, proc_rule_ctx&, int);
-static bool pr_fix_client(Properties&, proc_rule_ctx&, int);
-static bool pr_proc_options(Properties&, proc_rule_ctx&, int);
-static bool pr_fix_ndb_connectstring(Properties&, proc_rule_ctx&, int);
-static bool pr_set_ndb_connectstring(Properties&, proc_rule_ctx&, int);
-static bool pr_check_proc(Properties&, proc_rule_ctx&, int);
-
-static
-proc_rule f_rules[] =
-{
- { atrt_process::AP_CLUSTER, pr_check_features, 0 }
- ,{ atrt_process::AP_MYSQLD, pr_check_replication, 0 }
- ,{ (atrt_process::AP_ALL & ~atrt_process::AP_CLIENT), pr_proc_options,
- ~(PO_REP | PO_NDB) }
- ,{ (atrt_process::AP_ALL & ~atrt_process::AP_CLIENT), pr_proc_options, PO_REP }
- ,{ atrt_process::AP_CLIENT, pr_fix_client, 0 }
- ,{ atrt_process::AP_CLUSTER, pr_fix_ndb_connectstring, 0 }
- ,{ atrt_process::AP_MYSQLD, pr_set_ndb_connectstring, 0 }
- ,{ atrt_process::AP_ALL, pr_check_proc, 0 }
- ,{ 0, 0, 0 }
-};
-
-bool
-configure(atrt_config& config, int setup)
-{
- Properties props;
-
- for (size_t i = 0; f_rules[i].func; i++)
- {
- bool ok = true;
- proc_rule_ctx ctx;
- bzero(&ctx, sizeof(ctx));
- ctx.m_setup = setup;
- ctx.m_config = &config;
-
- for (size_t j = 0; j < config.m_clusters.size(); j++)
- {
- ctx.m_cluster = config.m_clusters[j];
-
- if (f_rules[i].type & atrt_process::AP_CLUSTER)
- {
- g_logger.debug("applying rule %d to cluster %s", i,
- ctx.m_cluster->m_name.c_str());
- if (! (* f_rules[i].func)(props, ctx, f_rules[i].extra))
- ok = false;
- }
- else
- {
- atrt_cluster& cluster = *config.m_clusters[j];
- for (size_t k = 0; k<cluster.m_processes.size(); k++)
- {
- atrt_process& proc = *cluster.m_processes[k];
- ctx.m_process = cluster.m_processes[k];
- if (proc.m_type & f_rules[i].type)
- {
- g_logger.debug("applying rule %d to %s", i,
- proc.m_proc.m_cwd.c_str());
- if (! (* f_rules[i].func)(props, ctx, f_rules[i].extra))
- ok = false;
- }
- }
- }
- }
-
- if (!ok)
- {
- return false;
- }
- }
-
- return true;
-}
-
-static
-atrt_process*
-find(atrt_config& config, int type, const char * name)
-{
- BaseString tmp(name);
- Vector<BaseString> src;
- Vector<BaseString> dst;
- tmp.split(src, ".");
-
- if (src.size() != 2)
- {
- return 0;
- }
- atrt_cluster* cluster = 0;
- BaseString cl;
- cl.appfmt(".%s", src[1].c_str());
- for (size_t i = 0; i<config.m_clusters.size(); i++)
- {
- if (config.m_clusters[i]->m_name == cl)
- {
- cluster = config.m_clusters[i];
- break;
- }
- }
-
- if (cluster == 0)
- {
- return 0;
- }
-
- int idx = atoi(src[0].c_str()) - 1;
- for (size_t i = 0; i<cluster->m_processes.size(); i++)
- {
- if (cluster->m_processes[i]->m_type & type)
- {
- if (idx == 0)
- return cluster->m_processes[i];
- else
- idx --;
- }
- }
-
- return 0;
-}
-
-static
-bool
-pr_check_replication(Properties& props, proc_rule_ctx& ctx, int)
-{
- if (! (ctx.m_config->m_replication == ""))
- {
- Vector<BaseString> list;
- ctx.m_config->m_replication.split(list, ";");
- atrt_config& config = *ctx.m_config;
-
- ctx.m_config->m_replication = "";
-
- const char * msg = "Invalid replication specification";
- for (size_t i = 0; i<list.size(); i++)
- {
- Vector<BaseString> rep;
- list[i].split(rep, ":");
- if (rep.size() != 2)
- {
- g_logger.error("%s: %s (split: %d)", msg, list[i].c_str(), rep.size());
- return false;
- }
-
- atrt_process* src = find(config, atrt_process::AP_MYSQLD,rep[0].c_str());
- atrt_process* dst = find(config, atrt_process::AP_MYSQLD,rep[1].c_str());
-
- if (src == 0 || dst == 0)
- {
- g_logger.error("%s: %s (%d %d)",
- msg, list[i].c_str(), src != 0, dst != 0);
- return false;
- }
-
-
- if (dst->m_rep_src != 0)
- {
- g_logger.error("%s: %s : %s already has replication src (%s)",
- msg,
- list[i].c_str(),
- dst->m_proc.m_cwd.c_str(),
- dst->m_rep_src->m_proc.m_cwd.c_str());
- return false;
- }
-
- dst->m_rep_src = src;
- src->m_rep_dst.push_back(dst);
-
- src->m_options.m_features |= PO_REP_MASTER;
- dst->m_options.m_features |= PO_REP_SLAVE;
- }
- }
- return true;
-}
-
-static
-bool
-pr_check_features(Properties& props, proc_rule_ctx& ctx, int)
-{
- int features = 0;
- atrt_cluster& cluster = *ctx.m_cluster;
- for (size_t i = 0; i<cluster.m_processes.size(); i++)
- {
- if (cluster.m_processes[i]->m_type == atrt_process::AP_NDB_MGMD ||
- cluster.m_processes[i]->m_type == atrt_process::AP_NDB_API ||
- cluster.m_processes[i]->m_type == atrt_process::AP_NDBD)
- {
- features |= atrt_options::AO_NDBCLUSTER;
- break;
- }
- }
-
- if (features)
- {
- cluster.m_options.m_features |= features;
- for (size_t i = 0; i<cluster.m_processes.size(); i++)
- {
- cluster.m_processes[i]->m_options.m_features |= features;
- }
- }
- return true;
-}
-
-static
-bool
-pr_fix_client(Properties& props, proc_rule_ctx& ctx, int)
-{
- for (size_t i = 0; f_options[i].name; i++)
- {
- proc_option& opt = f_options[i];
- const char * name = opt.name;
- if (opt.type & atrt_process::AP_CLIENT)
- {
- const char * val;
- atrt_process& proc = *ctx.m_process;
- if (!proc.m_options.m_loaded.get(name, &val))
- {
- require(proc.m_mysqld->m_options.m_loaded.get(name, &val));
- proc.m_options.m_loaded.put(name, val);
- proc.m_options.m_generated.put(name, val);
- }
- }
- }
-
- return true;
-}
-
-static
-Uint32
-try_default_port(atrt_process& proc, const char * name)
-{
- Uint32 port =
- strcmp(name, "--port=") == 0 ? 3306 :
- strcmp(name, "--PortNumber=") == 0 ? 1186 :
- 0;
-
- atrt_host * host = proc.m_host;
- for (size_t i = 0; i<host->m_processes.size(); i++)
- {
- const char * val;
- if (host->m_processes[i]->m_options.m_loaded.get(name, &val))
- {
- if ((Uint32)atoi(val) == port)
- return 0;
- }
- }
- return port;
-}
-
-static
-bool
-generate(atrt_process& proc, const char * name, Properties& props)
-{
- atrt_options& opts = proc.m_options;
- if (strcmp(name, "--port=") == 0 ||
- strcmp(name, "--PortNumber=") == 0)
- {
- Uint32 val;
- if (g_default_ports == 0 || (val = try_default_port(proc, name)) == 0)
- {
- val = g_baseport;
- props.get("--PortNumber=", &val);
- props.put("--PortNumber=", (val + 1), true);
- }
-
- char buf[255];
- snprintf(buf, sizeof(buf), "%u", val);
- opts.m_loaded.put(name, buf);
- opts.m_generated.put(name, buf);
- return true;
- }
- else if (strcmp(name, "--datadir=") == 0)
- {
- opts.m_loaded.put(name, proc.m_proc.m_cwd.c_str());
- opts.m_generated.put(name, proc.m_proc.m_cwd.c_str());
- return true;
- }
- else if (strcmp(name, "--FileSystemPath=") == 0)
- {
- BaseString dir;
- dir.append(proc.m_host->m_basedir);
- dir.append("/");
- dir.append(proc.m_cluster->m_dir);
- opts.m_loaded.put(name, dir.c_str());
- opts.m_generated.put(name, dir.c_str());
- return true;
- }
- else if (strcmp(name, "--socket=") == 0)
- {
- const char * sock = 0;
- if (g_default_ports)
- {
- sock = "/tmp/mysql.sock";
- atrt_host * host = proc.m_host;
- for (size_t i = 0; i<host->m_processes.size(); i++)
- {
- const char * val;
- if (host->m_processes[i]->m_options.m_loaded.get(name, &val))
- {
- if (strcmp(sock, val) == 0)
- {
- sock = 0;
- break;
- }
- }
- }
- }
-
- BaseString tmp;
- if (sock == 0)
- {
- tmp.assfmt("%s/mysql.sock", proc.m_proc.m_cwd.c_str());
- sock = tmp.c_str();
- }
-
- opts.m_loaded.put(name, sock);
- opts.m_generated.put(name, sock);
- return true;
- }
- else if (strcmp(name, "--server-id=") == 0)
- {
- Uint32 val = 1;
- props.get(name, &val);
- char buf[255];
- snprintf(buf, sizeof(buf), "%u", val);
- opts.m_loaded.put(name, buf);
- opts.m_generated.put(name, buf);
- props.put(name, (val + 1), true);
- return true;
- }
- else if (strcmp(name, "--log-bin") == 0)
- {
- opts.m_loaded.put(name, "");
- opts.m_generated.put(name, "");
- return true;
- }
- else if (strcmp(name, "--master-host=") == 0)
- {
- require(proc.m_rep_src != 0);
- opts.m_loaded.put(name, proc.m_rep_src->m_host->m_hostname.c_str());
- opts.m_generated.put(name, proc.m_rep_src->m_host->m_hostname.c_str());
- return true;
- }
- else if (strcmp(name, "--master-port=") == 0)
- {
- const char* val;
- require(proc.m_rep_src->m_options.m_loaded.get("--port=", &val));
- opts.m_loaded.put(name, val);
- opts.m_generated.put(name, val);
- return true;
- }
- else if (strcmp(name, "--master-user=") == 0)
- {
- opts.m_loaded.put(name, "root");
- opts.m_generated.put(name, "root");
- return true;
- }
- else if (strcmp(name, "--master-password=") == 0)
- {
- opts.m_loaded.put(name, "\"\"");
- opts.m_generated.put(name, "\"\"");
- return true;
- }
-
- g_logger.warning("Unknown parameter: %s", name);
- return true;
-}
-
-static
-bool
-pr_proc_options(Properties& props, proc_rule_ctx& ctx, int extra)
-{
- for (size_t i = 0; f_options[i].name; i++)
- {
- proc_option& opt = f_options[i];
- atrt_process& proc = *ctx.m_process;
- const char * name = opt.name;
- if (opt.type & proc.m_type)
- {
- if (opt.options == 0 ||
- (opt.options & extra & proc.m_options.m_features))
- {
- const char * val;
- if (!proc.m_options.m_loaded.get(name, &val))
- {
- generate(proc, name, props);
- }
- }
- }
- }
- return true;
-}
-
-static
-bool
-pr_fix_ndb_connectstring(Properties& props, proc_rule_ctx& ctx, int)
-{
- const char * val;
- atrt_cluster& cluster = *ctx.m_cluster;
-
- if (cluster.m_options.m_features & atrt_options::AO_NDBCLUSTER)
- {
- if (!cluster.m_options.m_loaded.get(ndbcs, &val))
- {
- /**
- * Construct connect string for this cluster
- */
- BaseString str;
- for (size_t i = 0; i<cluster.m_processes.size(); i++)
- {
- atrt_process* tmp = cluster.m_processes[i];
- if (tmp->m_type == atrt_process::AP_NDB_MGMD)
- {
- if (str.length())
- {
- str.append(";");
- }
- const char * port;
- require(tmp->m_options.m_loaded.get("--PortNumber=", &port));
- str.appfmt("%s:%s", tmp->m_host->m_hostname.c_str(), port);
- }
- }
- cluster.m_options.m_loaded.put(ndbcs, str.c_str());
- cluster.m_options.m_generated.put(ndbcs, str.c_str());
- cluster.m_options.m_loaded.get(ndbcs, &val);
- }
-
- for (size_t i = 0; i<cluster.m_processes.size(); i++)
- {
- cluster.m_processes[i]->m_proc.m_env.appfmt(" NDB_CONNECTSTRING=%s",
- val);
- }
- }
- return true;
-}
-
-static
-bool
-pr_set_ndb_connectstring(Properties& props, proc_rule_ctx& ctx, int)
-{
- const char * val;
-
- atrt_process& proc = *ctx.m_process;
- if (proc.m_options.m_features & atrt_options::AO_NDBCLUSTER)
- {
- if (!proc.m_options.m_loaded.get(ndbcs, &val))
- {
- require(proc.m_cluster->m_options.m_loaded.get(ndbcs, &val));
- proc.m_options.m_loaded.put(ndbcs, val);
- proc.m_options.m_generated.put(ndbcs, val);
- }
-
- if (!proc.m_options.m_loaded.get("--ndbcluster", &val))
- {
- proc.m_options.m_loaded.put("--ndbcluster", "");
- proc.m_options.m_generated.put("--ndbcluster", "");
- }
- }
- return true;
-}
-
-static
-bool
-pr_check_proc(Properties& props, proc_rule_ctx& ctx, int)
-{
- bool ok = true;
- bool generated = false;
- const int setup = ctx.m_setup;
- atrt_process& proc = *ctx.m_process;
- for (size_t i = 0; f_options[i].name; i++)
- {
- proc_option& opt = f_options[i];
- const char * name = opt.name;
- if ((ctx.m_process->m_type & opt.type) &&
- (opt.options == 0 || (ctx.m_process->m_options.m_features & opt.options)))
- {
- const char * val;
- if (!proc.m_options.m_loaded.get(name, &val))
- {
- ok = false;
- g_logger.warning("Missing paramter: %s for %s",
- name, proc.m_proc.m_cwd.c_str());
- }
- else if (proc.m_options.m_generated.get(name, &val))
- {
- if (setup == 0)
- {
- ok = false;
- g_logger.warning("Missing paramter: %s for %s",
- name, proc.m_proc.m_cwd.c_str());
- }
- else
- {
- generated = true;
- }
- }
- }
- }
-
- if (generated)
- {
- ctx.m_config->m_generated = true;
- }
-
- //ndbout << proc << endl;
-
- return ok;
-}
-
-
-NdbOut&
-operator<<(NdbOut& out, const atrt_process& proc)
-{
- out << "[ atrt_process: ";
- switch(proc.m_type){
- case atrt_process::AP_NDB_MGMD:
- out << "ndb_mgmd";
- break;
- case atrt_process::AP_NDBD:
- out << "ndbd";
- break;
- case atrt_process::AP_MYSQLD:
- out << "mysqld";
- break;
- case atrt_process::AP_NDB_API:
- out << "ndbapi";
- break;
- case atrt_process::AP_CLIENT:
- out << "client";
- break;
- default:
- out << "<unknown: " << (int)proc.m_type << " >";
- }
-
- out << " cluster: " << proc.m_cluster->m_name.c_str()
- << " host: " << proc.m_host->m_hostname.c_str()
- << endl << " cwd: " << proc.m_proc.m_cwd.c_str()
- << endl << " path: " << proc.m_proc.m_path.c_str()
- << endl << " args: " << proc.m_proc.m_args.c_str()
- << endl << " env: " << proc.m_proc.m_env.c_str() << endl;
-
- proc.m_options.m_generated.print(stdout, "generated: ");
-
- out << " ]";
-
-#if 0
- proc.m_index = 0; //idx;
- proc.m_host = host_ptr;
- proc.m_cluster = cluster;
- proc.m_proc.m_id = -1;
- proc.m_proc.m_type = "temporary";
- proc.m_proc.m_owner = "atrt";
- proc.m_proc.m_group = cluster->m_name.c_str();
- proc.m_proc.m_cwd.assign(dir).append("/atrt/").append(cluster->m_dir);
- proc.m_proc.m_stdout = "log.out";
- proc.m_proc.m_stderr = "2>&1";
- proc.m_proc.m_runas = proc.m_host->m_user;
- proc.m_proc.m_ulimit = "c:unlimited";
- proc.m_proc.m_env.assfmt("MYSQL_BASE_DIR=%s", dir);
- proc.m_proc.m_shutdown_options = "";
-#endif
-
- return out;
-}
-
diff --git a/storage/ndb/test/run-test/test-tests.txt b/storage/ndb/test/run-test/test-tests.txt
deleted file mode 100644
index b57023fc0c1..00000000000
--- a/storage/ndb/test/run-test/test-tests.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-max-time: 600
-cmd: testBasic
-args: -n PkRead T1
-
-max-time: 1800
-cmd: testMgm
-args: -n SingleUserMode T1
-
-#
-#
-# SYSTEM RESTARTS
-#
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR3 T6
-
-max-time: 1500
-cmd: testSystemRestart
-args: -n SR4 T6
-
-max-time: 600
-cmd: testBasic
-args: -n PkRead T1
-
diff --git a/storage/ndb/test/run-test/upgrade-boot.sh b/storage/ndb/test/run-test/upgrade-boot.sh
deleted file mode 100644
index 745418dbb7c..00000000000
--- a/storage/ndb/test/run-test/upgrade-boot.sh
+++ /dev/null
@@ -1,235 +0,0 @@
-#!/bin/sh
-
-# Copyright (c) 2007 MySQL AB
-# Use is subject to license terms.
-#
-# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-#############################################################
-# This script created by Jonas does the following #
-# Cleans up clones and pevious builds, pulls new clones, #
-# builds, deploys, configures the tests and launches ATRT #
-#############################################################
-
-###############
-#Script setup #
-##############
-
-save_args=$*
-VERSION="upgrade-boot.sh version 1.00"
-
-DATE=`date '+%Y-%m-%d'`
-HOST=`hostname -s`
-export DATE HOST
-
-set -e
-
-echo "`date` starting: $*"
-
-verbose=0
-do_clone=yes
-build=yes
-
-tag0=
-tag1=
-conf=
-extra_args=
-extra_clone=
-LOCK=$HOME/.autotest-lock
-
-############################
-# Read command line entries#
-############################
-
-while [ "$1" ]
-do
- case "$1" in
- --no-clone) do_clone="";;
- --no-build) build="";;
- --verbose) verbose=`expr $verbose + 1`;;
- --clone=*) clone0=`echo $1 | sed s/--clone=//`;;
- --clone0=*) clone0=`echo $1 | sed s/--clone0=//`;;
- --clone1=*) clone1=`echo $1 | sed s/--clone1=//`;;
- --version) echo $VERSION; exit;;
- --conf=*) conf=`echo $1 | sed s/--conf=//`;;
- --tag=*) tag0=`echo $1 | sed s/--tag=//`;;
- --tag0=*) tag0=`echo $1 | sed s/--tag0=//`;;
- --tag1=*) tag1=`echo $1 | sed s/--tag1=//`;;
- --*) echo "Unknown arg: $1";;
- *) RUN=$*;;
- esac
- shift
-done
-
-if [ -z "$clone1" ]
-then
- clone1=$clone0
-fi
-
-if [ -z "$tag0" ]
-then
- echo "No tag0 specified"
- exit
-fi
-
-if [ -z "$tag1" ]
-then
- echo "No tag1 specified"
- exit
-fi
-
-#################################
-#Make sure the configfile exists#
-#if it does not exit. if it does#
-# (.) load it #
-#################################
-if [ -z "$conf" ]
-then
- if [ -f "`pwd`/autotest.conf" ]
- then
- conf="`pwd`/autotest.conf"
- elif [ -f "$HOME/autotest.conf" ]
- then
- conf="$HOME/autotest.conf"
- fi
-fi
-
-if [ -f $conf ]
-then
- . $conf
-else
- echo "Can't find config file: >$conf<"
- exit
-fi
-
-###############################
-# Validate that all interesting
-# variables where set in conf
-###############################
-vars="src_clone_base install_dir build_dir"
-for i in $vars
-do
- t=`echo echo \\$$i`
- if [ -z "`eval $t`" ]
- then
- echo "Invalid config: $conf, variable $i is not set"
- exit
- fi
-done
-
-###############################
-#Print out the enviroment vars#
-###############################
-
-if [ $verbose -gt 0 ]
-then
- env
-fi
-
-####################################
-# Setup the lock file name and path#
-# Setup the clone source location #
-####################################
-
-src_clone0=${src_clone_base}${clone0}
-src_clone1=${src_clone_base}${clone1}
-
-#######################################
-# Check to see if the lock file exists#
-# If it does exit. #
-#######################################
-
-if [ -f $LOCK ]
-then
- echo "Lock file exists: $LOCK"
- exit 1
-fi
-
-#######################################
-# If the lock file does not exist then#
-# create it with date and run info #
-#######################################
-
-echo "$DATE $RUN" > $LOCK
-
-#############################
-#If any errors here down, we#
-# trap them, and remove the #
-# Lock file before exit #
-#############################
-if [ `uname -s` != "SunOS" ]
-then
- trap "rm -f $LOCK" ERR
-fi
-
-# You can add more to this path#
-################################
-
-dst_place0=${build_dir}/clone-$tag0-$DATE.$$
-dst_place1=${build_dir}/clone-$tag1-$DATE.$$
-
-#########################################
-# Delete source and pull down the latest#
-#########################################
-
-if [ "$do_clone" ]
-then
- rm -rf $dst_place0 $dst_place1
- if [ `echo $src_clone0 | grep -c 'file:\/\/'` = 1 ]
- then
- bk clone -l -r$tag0 $src_clone0 $dst_place0
- else
- bk clone -r$tag0 $src_clone0 $dst_place0
- fi
-
- if [ `echo $src_clone1 | grep -c 'file:\/\/'` = 1 ]
- then
- bk clone -l -r$tag1 $src_clone1 $dst_place1
- else
- bk clone -r$tag1 $src_clone1 $dst_place1
- fi
-fi
-
-##########################################
-# Build the source, make installs, and #
-# create the database to be rsynced #
-##########################################
-install_dir0=$install_dir/$tag0
-install_dir1=$install_dir/$tag1
-if [ "$build" ]
-then
- cd $dst_place0
- rm -rf $install_dir0
- BUILD/compile-ndb-autotest --prefix=$install_dir0
- make install
-
- cd $dst_place1
- rm -rf $install_dir1
- BUILD/compile-ndb-autotest --prefix=$install_dir1
- make install
-fi
-
-
-################################
-# Start run script #
-################################
-
-script=$install_dir1/mysql-test/ndb/upgrade-run.sh
-$script $save_args --conf=$conf --install-dir=$install_dir --suite=$RUN --nolock $extra_args
-
-if [ "$build" ]
-then
- rm -rf $dst_place0 $dst_place1
-fi
-rm -f $LOCK
diff --git a/storage/ndb/test/src/AtrtClient.cpp b/storage/ndb/test/src/AtrtClient.cpp
deleted file mode 100644
index a42f0fa8eb0..00000000000
--- a/storage/ndb/test/src/AtrtClient.cpp
+++ /dev/null
@@ -1,216 +0,0 @@
-/* Copyright (C) 2008 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <AtrtClient.hpp>
-#include <NDBT_Output.hpp>
-#include <NdbSleep.h>
-
-AtrtClient::AtrtClient(const char* _user,
- const char* _password,
- const char* _group_suffix)
- : DbUtil(_user, _password, _group_suffix)
-{
-}
-
-
-AtrtClient::AtrtClient(MYSQL* mysql)
- : DbUtil(mysql)
-{
-}
-
-
-AtrtClient::~AtrtClient(){
-}
-
-
-int
-AtrtClient::writeCommand(AtrtCommandType _type,
- const Properties& args){
- if (!isConnected())
- return false;
-
- BaseString sql;
- sql.assfmt("INSERT command ( ");
-
- const char* name;
- {
- Properties::Iterator iter(&args);
- while((name= iter.next())){
- sql.appfmt("%s, ", name);
- }
- }
-
- sql.appfmt(" state, cmd) VALUES (");
-
- {
- Properties::Iterator iter(&args);
- while((name= iter.next())){
- PropertiesType t;
- Uint32 val_i;
- BaseString val_s;
- args.getTypeOf(name, &t);
- switch(t) {
- case PropertiesType_Uint32:
- args.get(name, &val_i);
- sql.appfmt("%d, ", val_i);
- break;
- case PropertiesType_char:
- args.get(name, val_s);
- sql.appfmt("'%s', ", val_s.c_str());
- break;
- default:
- assert(false);
- break;
- }
- }
- }
-
- sql.appfmt("'new', %d)", _type);
- if (!doQuery(sql)){
- return -1;
- }
-
- return mysql_insert_id(m_mysql);
-}
-
-
-bool
-AtrtClient::readCommand(uint command_id,
- SqlResultSet& result){
- Properties args;
- args.put("0", command_id);
- return runQuery("SELECT * FROM command WHERE id = ?",
- args,
- result);
-}
-
-
-bool
-AtrtClient::doCommand(AtrtCommandType type,
- const Properties& args){
-
- int running_timeout= 10;
- int total_timeout= 120;
- int commandId= writeCommand(type,
- args);
- if (commandId == -1){
- g_err << "Failed to write command" << endl;
- return false;
- }
-
- while (true){
-
- SqlResultSet result;
- if (!readCommand(commandId, result))
- {
- result.print();
- g_err << "Failed to read command "<< commandId << endl;
- return false;
- }
-
- // Get first row
- result.next();
-
- // Check if command has completed
- BaseString state(result.column("state"));
- if (state == "done") {
- return true;
- }
-
- if (state == "new"){
- if (!running_timeout--){
- g_err << "Timeout while waiting for command "
- << commandId << " to start run" << endl;
- return false;
- }
- }
- else if (!total_timeout--){
- g_err << "Timeout while waiting for result of command "
- << commandId << endl;
- return false;
- }
-
-
- NdbSleep_SecSleep(1);
- }
-
- return false;
-}
-
-
-bool
-AtrtClient::changeVersion(int process_id,
- const char* process_args){
- Properties args;
- args.put("process_id", process_id);
- args.put("process_args", process_args);
- return doCommand(ATCT_CHANGE_VERSION, args);
-}
-
-
-bool
-AtrtClient::resetProc(int process_id){
- Properties args;
- args.put("process_id", process_id);
- return doCommand(ATCT_RESET_PROC, args);
-}
-
-
-bool
-AtrtClient::getConnectString(int cluster_id, SqlResultSet& result){
- Properties args;
- args.put("0", cluster_id);
- return doQuery("SELECT value as connectstring " \
- "FROM cluster c, process p, host h, options o " \
- "WHERE c.id=p.cluster_id AND p.host_id=h.id AND " \
- "p.id=o.process_id AND c.id=? AND " \
- "o.name='--ndb-connectstring=' AND type='ndb_mgmd'",
- args,
- result);
-}
-
-
-bool
-AtrtClient::getClusters(SqlResultSet& result){
- Properties args;
- return runQuery("SELECT id, name FROM cluster WHERE name != '.atrt'",
- args,
- result);
-}
-
-
-bool
-AtrtClient::getMgmds(int cluster_id, SqlResultSet& result){
- Properties args;
- args.put("0", cluster_id);
- return runQuery("SELECT * FROM process WHERE cluster_id=? and type='ndb_mgmd'",
- args,
- result);
-}
-
-bool
-AtrtClient::getNdbds(int cluster_id, SqlResultSet& result){
- Properties args;
- args.put("0", cluster_id);
- return runQuery("SELECT * FROM process WHERE cluster_id=? and type='ndbd'",
- args,
- result);
-}
-
-
-
-
-
diff --git a/storage/ndb/test/src/CpcClient.cpp b/storage/ndb/test/src/CpcClient.cpp
deleted file mode 100644
index 9133815ada4..00000000000
--- a/storage/ndb/test/src/CpcClient.cpp
+++ /dev/null
@@ -1,552 +0,0 @@
-/* Copyright (c) 2003-2005, 2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-
-#include <NdbOut.hpp>
-#include <NdbTCP.h>
-#include "CpcClient.hpp"
-
-#define CPC_CMD(name, value, desc) \
- { (name), \
- 0, \
- ParserRow_t::Cmd, \
- ParserRow_t::String, \
- ParserRow_t::Optional, \
- ParserRow_t::IgnoreMinMax, \
- 0, 0, \
- 0, \
- (desc), \
- (value) }
-
-#define CPC_ARG(name, type, opt, desc) \
- { (name), \
- 0, \
- ParserRow_t::Arg, \
- ParserRow_t::type, \
- ParserRow_t::opt, \
- ParserRow_t::IgnoreMinMax, \
- 0, 0, \
- 0, \
- (desc), 0 }
-
-#define CPC_END() \
- { 0, \
- 0, \
- ParserRow_t::Arg, \
- ParserRow_t::Int, \
- ParserRow_t::Optional, \
- ParserRow_t::IgnoreMinMax, \
- 0, 0, \
- 0, \
- 0, 0 }
-
-#ifdef DEBUG_PRINT_PROPERTIES
-static void printprop(const Properties &p) {
- Properties::Iterator iter(&p);
- const char *name;
- while((name = iter.next()) != NULL) {
- PropertiesType t;
- Uint32 val_i;
- BaseString val_s;
-
- p.getTypeOf(name, &t);
- switch(t) {
- case PropertiesType_Uint32:
- p.get(name, &val_i);
- ndbout << name << " (Uint32): " << val_i << endl;
- break;
- case PropertiesType_char:
- p.get(name, val_s);
- ndbout << name << " (string): " << val_s << endl;
- break;
- default:
- ndbout << "Unknown type " << t << endl;
- break;
- }
- }
-}
-#endif
-
-void
-SimpleCpcClient::cmd_stop(char *arg) {
- Properties p;
- Vector<Process> proc_list;
-
- list_processes(proc_list, p);
- bool stopped = false;
-
- for(size_t i = 0; i < proc_list.size(); i++) {
- if(strcmp(proc_list[i].m_name.c_str(), arg) == 0) {
- stopped = true;
- Properties reply;
- stop_process(proc_list[i].m_id, reply);
-
- Uint32 status;
- reply.get("status", &status);
- if(status != 0) {
- BaseString msg;
- reply.get("errormessage", msg);
- ndbout << "Stop failed: " << msg << endl;
- }
- }
- }
-
- if(!stopped)
- ndbout << "No such process" << endl;
-}
-
-int
-SimpleCpcClient::stop_process(Uint32 id, Properties& reply){
- const ParserRow_t stop_reply[] = {
- CPC_CMD("stop process", NULL, ""),
- CPC_ARG("status", Int, Mandatory, ""),
- CPC_ARG("id", Int, Optional, ""),
- CPC_ARG("errormessage", String, Optional, ""),
-
- CPC_END()
- };
-
- Properties args;
- args.put("id", id);
-
- const Properties* ret = cpc_call("stop process", args, stop_reply);
- if(ret == 0){
- reply.put("status", (Uint32)0);
- reply.put("errormessage", "unknown error");
- return -1;
- }
-
- Uint32 status = 0;
- ret->get("status", &status);
- reply.put("status", status);
- if(status != 0) {
- BaseString msg;
- ret->get("errormessage", msg);
- reply.put("errormessage", msg.c_str());
- }
-
- return status;
-}
-
-void
-SimpleCpcClient::cmd_start(char *arg) {
- Properties p;
- Vector<Process> proc_list;
- list_processes(proc_list, p);
- bool startped = false;
-
- for(size_t i = 0; i < proc_list.size(); i++) {
- if(strcmp(proc_list[i].m_name.c_str(), arg) == 0) {
- startped = true;
-
- Properties reply;
- start_process(proc_list[i].m_id, reply);
-
- Uint32 status;
- reply.get("status", &status);
- if(status != 0) {
- BaseString msg;
- reply.get("errormessage", msg);
- ndbout << "Start failed: " << msg << endl;
- }
- }
- }
-
- if(!startped)
- ndbout << "No such process" << endl;
-}
-
-int
-SimpleCpcClient::start_process(Uint32 id, Properties& reply){
- const ParserRow_t start_reply[] = {
- CPC_CMD("start process", NULL, ""),
- CPC_ARG("status", Int, Mandatory, ""),
- CPC_ARG("id", Int, Optional, ""),
- CPC_ARG("errormessage", String, Optional, ""),
-
- CPC_END()
- };
-
- Properties args;
- args.put("id", id);
-
- const Properties* ret = cpc_call("start process", args, start_reply);
- if(ret == 0){
- reply.put("status", (Uint32)0);
- reply.put("errormessage", "unknown error");
- return -1;
- }
-
- Uint32 status = 0;
- ret->get("status", &status);
- reply.put("status", status);
- if(status != 0) {
- BaseString msg;
- ret->get("errormessage", msg);
- reply.put("errormessage", msg.c_str());
- }
-
- return status;
-}
-
-int
-SimpleCpcClient::undefine_process(Uint32 id, Properties& reply){
- const ParserRow_t stop_reply[] = {
- CPC_CMD("undefine process", NULL, ""),
- CPC_ARG("status", Int, Mandatory, ""),
- CPC_ARG("id", Int, Optional, ""),
- CPC_ARG("errormessage", String, Optional, ""),
-
- CPC_END()
- };
-
- Properties args;
- args.put("id", id);
-
- const Properties* ret = cpc_call("undefine process", args, stop_reply);
- if(ret == 0){
- reply.put("status", (Uint32)0);
- reply.put("errormessage", "unknown error");
- return -1;
- }
-
- Uint32 status = 0;
- ret->get("status", &status);
- reply.put("status", status);
- if(status != 0) {
- BaseString msg;
- ret->get("errormessage", msg);
- reply.put("errormessage", msg.c_str());
- }
-
- return status;
-}
-
-static void
-printproc(SimpleCpcClient::Process & p) {
- ndbout.println("Name: %s", p.m_name.c_str());
- ndbout.println("Id: %d", p.m_id);
- ndbout.println("Type: %s", p.m_type.c_str());
- ndbout.println("Group: %s", p.m_group.c_str());
- ndbout.println("Program path: %s", p.m_path.c_str());
- ndbout.println("Arguments: %s", p.m_args.c_str());
- ndbout.println("Environment: %s", p.m_env.c_str());
- ndbout.println("Working directory: %s", p.m_cwd.c_str());
- ndbout.println("Owner: %s", p.m_owner.c_str());
- ndbout.println("Runas: %s", p.m_runas.c_str());
- ndbout.println("Ulimit: %s", p.m_ulimit.c_str());
- ndbout.println("");
-}
-
-void
-SimpleCpcClient::cmd_list(char *arg) {
- Properties p;
- Vector<Process> proc_list;
- list_processes(proc_list, p);
-
- for(size_t i = 0; i < proc_list.size(); i++) {
- printproc(proc_list[i]);
- }
-}
-
-static int
-convert(const Properties & src, SimpleCpcClient::Process & dst){
- bool b = true;
- b &= src.get("id", (Uint32*)&dst.m_id);
- b &= src.get("name", dst.m_name);
- b &= src.get("type", dst.m_type);
- b &= src.get("status", dst.m_status);
- b &= src.get("owner", dst.m_owner);
- b &= src.get("group", dst.m_group);
- b &= src.get("path", dst.m_path);
- b &= src.get("args", dst.m_args);
- b &= src.get("env", dst.m_env);
- b &= src.get("cwd", dst.m_cwd);
- b &= src.get("runas", dst.m_runas);
-
- b &= src.get("stdin", dst.m_stdin);
- b &= src.get("stdout", dst.m_stdout);
- b &= src.get("stderr", dst.m_stderr);
- b &= src.get("ulimit", dst.m_ulimit);
- b &= src.get("shutdown", dst.m_shutdown_options);
-
- return b;
-}
-
-static int
-convert(const SimpleCpcClient::Process & src, Properties & dst ){
- bool b = true;
- //b &= dst.put("id", (Uint32)src.m_id);
- b &= dst.put("name", src.m_name.c_str());
- b &= dst.put("type", src.m_type.c_str());
- //b &= dst.put("status", src.m_status.c_str());
- b &= dst.put("owner", src.m_owner.c_str());
- b &= dst.put("group", src.m_group.c_str());
- b &= dst.put("path", src.m_path.c_str());
- b &= dst.put("args", src.m_args.c_str());
- b &= dst.put("env", src.m_env.c_str());
- b &= dst.put("cwd", src.m_cwd.c_str());
- b &= dst.put("runas", src.m_runas.c_str());
-
- b &= dst.put("stdin", src.m_stdin.c_str());
- b &= dst.put("stdout", src.m_stdout.c_str());
- b &= dst.put("stderr", src.m_stderr.c_str());
- b &= dst.put("ulimit", src.m_ulimit.c_str());
- b &= dst.put("shutdown", src.m_shutdown_options.c_str());
-
- return b;
-}
-
-int
-SimpleCpcClient::define_process(Process & p, Properties& reply){
- const ParserRow_t define_reply[] = {
- CPC_CMD("define process", NULL, ""),
- CPC_ARG("status", Int, Mandatory, ""),
- CPC_ARG("id", Int, Optional, ""),
- CPC_ARG("errormessage", String, Optional, ""),
-
- CPC_END()
- };
-
- Properties args;
- convert(p, args);
-
- const Properties* ret = cpc_call("define process", args, define_reply);
- if(ret == 0){
- reply.put("status", (Uint32)0);
- reply.put("errormessage", "unknown error");
- return -1;
- }
-
- Uint32 status = 0;
- ret->get("status", &status);
- reply.put("status", status);
- if(status != 0) {
- BaseString msg;
- ret->get("errormessage", msg);
- reply.put("errormessage", msg.c_str());
- }
-
- Uint32 id;
- if(!ret->get("id", &id)){
- return -1;
- }
-
- p.m_id = id;
-
- return status;
-}
-
-int
-SimpleCpcClient::list_processes(Vector<Process> &procs, Properties& reply) {
- int start, end, entry;
- const ParserRow_t list_reply[] = {
- CPC_CMD("start processes", &start, ""),
- CPC_CMD("end processes", &end, ""),
-
- CPC_CMD("process", &entry, ""),
- CPC_ARG("id", Int, Mandatory, "Id of process."),
- CPC_ARG("name", String, Mandatory, "Name of process"),
- CPC_ARG("group", String, Mandatory, "Group of process"),
- CPC_ARG("env", String, Mandatory, "Environment variables for process"),
- CPC_ARG("path", String, Mandatory, "Path to binary"),
- CPC_ARG("args", String, Mandatory, "Arguments to process"),
- CPC_ARG("type", String, Mandatory, "Type of process"),
- CPC_ARG("cwd", String, Mandatory, "Working directory of process"),
- CPC_ARG("owner", String, Mandatory, "Owner of process"),
- CPC_ARG("status",String, Mandatory, "Status of process"),
- CPC_ARG("runas", String, Mandatory, "Run as user"),
- CPC_ARG("stdin", String, Mandatory, "Redirect stdin"),
- CPC_ARG("stdout",String, Mandatory, "Redirect stdout"),
- CPC_ARG("stderr",String, Mandatory, "Redirect stderr"),
- CPC_ARG("ulimit",String, Mandatory, "ulimit"),
- CPC_ARG("shutdown",String, Mandatory, "shutdown"),
-
- CPC_END()
- };
-
- reply.clear();
-
- const Properties args;
-
- cpc_send("list processes", args);
-
- bool done = false;
- while(!done) {
- const Properties *proc;
- void *p;
- cpc_recv(list_reply, &proc, &p);
-
- if(p == &start)
- {
- /* do nothing */
- }
- else if(p == &end)
- {
- done = true;
- }
- else if(p == &entry)
- {
- if(proc != NULL){
- Process p;
- convert(* proc, p);
- procs.push_back(p);
- }
- }
- else
- {
- ndbout_c("internal error: %d", __LINE__);
- return -1;
- }
- }
- return 0;
-}
-
-void
-SimpleCpcClient::cmd_help(char *arg) {
- ndbout
- << "HELP Print help text" << endl
- << "LIST List processes" << endl
- << "START Start process" << endl
- << "STOP Stop process" << endl;
-}
-
-SimpleCpcClient::SimpleCpcClient(const char *_host, int _port) {
- host = strdup(_host);
- port = _port;
- cpc_sock = -1;
-}
-
-SimpleCpcClient::~SimpleCpcClient() {
- if(host != NULL) {
- free(host);
- host = NULL;
- }
-
- port = 0;
-
- if(cpc_sock == -1) {
- close(cpc_sock);
- cpc_sock = -1;
- }
-}
-
-int
-SimpleCpcClient::connect() {
- struct sockaddr_in sa;
- struct hostent *hp;
-
- /* Create socket */
- cpc_sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- if(cpc_sock < 0)
- return -1;
-
- /* Connect socket */
- sa.sin_family = AF_INET;
- hp = gethostbyname(host);
- if(hp == NULL) {
- errno = ENOENT;
- return -1;
- }
-
- memcpy(&sa.sin_addr, hp->h_addr, hp->h_length);
- sa.sin_port = htons(port);
- if (::connect(cpc_sock, (struct sockaddr*) &sa, sizeof(sa)) < 0)
- return -1;
-
- return 0;
-}
-
-int
-SimpleCpcClient::cpc_send(const char *cmd,
- const Properties &args) {
- SocketOutputStream cpc_out(cpc_sock);
-
- cpc_out.println(cmd);
-
- Properties::Iterator iter(&args);
- const char *name;
- while((name = iter.next()) != NULL) {
- PropertiesType t;
- Uint32 val_i;
- BaseString val_s;
-
- args.getTypeOf(name, &t);
- switch(t) {
- case PropertiesType_Uint32:
- args.get(name, &val_i);
- cpc_out.println("%s: %d", name, val_i);
- break;
- case PropertiesType_char:
- args.get(name, val_s);
- cpc_out.println("%s: %s", name, val_s.c_str());
- break;
- default:
- /* Silently ignore */
- break;
- }
- }
- cpc_out.println("");
-
- return 0;
-}
-
-/**
- * Receive a response from the CPCD. The argument reply will point
- * to a Properties object describing the reply. Note that the caller
- * is responsible for deleting the Properties object returned.
- */
-SimpleCpcClient::Parser_t::ParserStatus
-SimpleCpcClient::cpc_recv(const ParserRow_t *syntax,
- const Properties **reply,
- void **user_value) {
- SocketInputStream cpc_in(cpc_sock);
-
- Parser_t::Context ctx;
- ParserDummy session(cpc_sock);
- Parser_t parser(syntax, cpc_in, true, true, true);
- *reply = parser.parse(ctx, session);
- if(user_value != NULL)
- *user_value = ctx.m_currentCmd->user_value;
- return ctx.m_status;
-}
-
-const Properties *
-SimpleCpcClient::cpc_call(const char *cmd,
- const Properties &args,
- const ParserRow_t *reply_syntax) {
- cpc_send(cmd, args);
-
-#if 0
- Parser_t::Context ctx;
- ParserDummy session(cpc_sock);
- Parser_t parser(reply_syntax, *cpc_in, true, true, true);
- const Properties *ret = parser.parse(ctx, session);
- return ret;
-#endif
- const Properties *ret;
- cpc_recv(reply_syntax, &ret);
- return ret;
-}
-
-
-SimpleCpcClient::ParserDummy::ParserDummy(NDB_SOCKET_TYPE sock)
- : SocketServer::Session(sock) {
-}
-
-template class Vector<SimpleCpcClient::Process>;
-template class Vector<ParserRow<SimpleCpcClient::ParserDummy> const*>;
diff --git a/storage/ndb/test/src/DbUtil.cpp b/storage/ndb/test/src/DbUtil.cpp
deleted file mode 100755
index 5c77f32a018..00000000000
--- a/storage/ndb/test/src/DbUtil.cpp
+++ /dev/null
@@ -1,678 +0,0 @@
-/* Copyright (c) 2007, 2008 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-/* DbUtil.cpp: implementation of the database utilities class.*/
-
-#include "DbUtil.hpp"
-#include <NdbSleep.h>
-
-
-/* Constructors */
-
-DbUtil::DbUtil(const char* _dbname,
- const char* _user,
- const char* _password,
- const char* _suffix):
- m_connected(false),
- m_dbname(_dbname),
- m_mysql(NULL),
- m_free_mysql(true)
-{
- const char* env= getenv("MYSQL_HOME");
- if (env && strlen(env))
- {
- m_default_file.assfmt("%s/my.cnf", env);
- }
-
- if (_suffix != NULL){
- m_default_group.assfmt("client%s", _suffix);
- }
- else {
- m_default_group.assign("client.1.master");
- }
-
- ndbout << "default_file: " << m_default_file.c_str() << endl;
- ndbout << "default_group: " << m_default_group.c_str() << endl;
-
- m_user.assign(_user);
- m_pass.assign(_password);
-}
-
-
-
-DbUtil::DbUtil(MYSQL* mysql):
- m_connected(true),
- m_mysql(mysql),
- m_free_mysql(false)
-{
-}
-
-
-bool
-DbUtil::isConnected(){
- if (m_connected == true)
- {
- assert(m_mysql);
- return true;
- }
- return connect() == 0;
-}
-
-
-bool
-DbUtil::waitConnected(int timeout) {
- timeout*= 10;
- while(!isConnected()){
- if (timeout-- == 0)
- return false;
- NdbSleep_MilliSleep(100);
- }
- return true;
-}
-
-
-void
-DbUtil::disconnect(){
- if (m_mysql != NULL){
- if (m_free_mysql)
- mysql_close(m_mysql);
- m_mysql= NULL;
- }
- m_connected = false;
-}
-
-
-/* Destructor */
-
-DbUtil::~DbUtil()
-{
- disconnect();
-}
-
-/* Database Login */
-
-void
-DbUtil::databaseLogin(const char* system, const char* usr,
- const char* password, unsigned int portIn,
- const char* sockIn, bool transactional)
-{
- if (!(m_mysql = mysql_init(NULL)))
- {
- myerror("DB Login-> mysql_init() failed");
- exit(DBU_FAILED);
- }
- setUser(usr);
- setHost(system);
- setPassword(password);
- setPort(portIn);
- setSocket(sockIn);
-
- if (!(mysql_real_connect(m_mysql,
- m_host.c_str(),
- m_user.c_str(),
- m_pass.c_str(),
- "test",
- m_port,
- m_socket.c_str(), 0)))
- {
- myerror("connection failed");
- mysql_close(m_mysql);
- exit(DBU_FAILED);
- }
-
- m_mysql->reconnect = TRUE;
-
- /* set AUTOCOMMIT */
- if(!transactional)
- mysql_autocommit(m_mysql, TRUE);
- else
- mysql_autocommit(m_mysql, FALSE);
-
- #ifdef DEBUG
- printf("\n\tConnected to MySQL server version: %s (%lu)\n\n",
- mysql_get_server_info(m_mysql),
- (unsigned long) mysql_get_server_version(m_mysql));
- #endif
- selectDb();
-}
-
-/* Database Connect */
-
-int
-DbUtil::connect()
-{
- if (!(m_mysql = mysql_init(NULL)))
- {
- myerror("DB connect-> mysql_init() failed");
- return DBU_FAILED;
- }
-
- /* Load connection parameters file and group */
- if (mysql_options(m_mysql, MYSQL_READ_DEFAULT_FILE, m_default_file.c_str()) ||
- mysql_options(m_mysql, MYSQL_READ_DEFAULT_GROUP, m_default_group.c_str()))
- {
- myerror("DB Connect -> mysql_options failed");
- return DBU_FAILED;
- }
-
- /*
- Connect, read settings from my.cnf
- NOTE! user and password can be stored there as well
- */
-
- if (mysql_real_connect(m_mysql, NULL, "root","", m_dbname.c_str(),
- 0, NULL, 0) == NULL)
- {
- myerror("connection failed");
- mysql_close(m_mysql);
- return DBU_FAILED;
- }
- selectDb();
- m_connected = true;
- return DBU_OK;
-}
-
-
-/* Database Logout */
-
-void
-DbUtil::databaseLogout()
-{
- if (m_mysql){
- #ifdef DEBUG
- printf("\n\tClosing the MySQL database connection ...\n\n");
- #endif
- mysql_close(m_mysql);
- }
-}
-
-/* Prepare MySQL Statements Cont */
-
-MYSQL_STMT *STDCALL
-DbUtil::mysqlSimplePrepare(const char *query)
-{
- #ifdef DEBUG
- printf("Inside DbUtil::mysqlSimplePrepare\n");
- #endif
- int m_res = DBU_OK;
-
- MYSQL_STMT *my_stmt= mysql_stmt_init(this->getMysql());
- if (my_stmt && (m_res = mysql_stmt_prepare(my_stmt, query, strlen(query)))){
- this->printStError(my_stmt,"Prepare Statement Failed");
- mysql_stmt_close(my_stmt);
- exit(DBU_FAILED);
- }
- return my_stmt;
-}
-
-/* Close MySQL Statements Handle */
-
-void
-DbUtil::mysqlCloseStmHandle(MYSQL_STMT *my_stmt)
-{
- mysql_stmt_close(my_stmt);
-}
-
-/* Error Printing */
-
-void
-DbUtil::printError(const char *msg)
-{
- if (m_mysql && mysql_errno(m_mysql))
- {
- if (m_mysql->server_version)
- printf("\n [MySQL-%s]", m_mysql->server_version);
- else
- printf("\n [MySQL]");
- printf("[%d] %s\n", getErrorNumber(), getError());
- }
- else if (msg)
- printf(" [MySQL] %s\n", msg);
-}
-
-void
-DbUtil::printStError(MYSQL_STMT *stmt, const char *msg)
-{
- if (stmt && mysql_stmt_errno(stmt))
- {
- if (m_mysql && m_mysql->server_version)
- printf("\n [MySQL-%s]", m_mysql->server_version);
- else
- printf("\n [MySQL]");
-
- printf("[%d] %s\n", mysql_stmt_errno(stmt),
- mysql_stmt_error(stmt));
- }
- else if (msg)
- printf("[MySQL] %s\n", msg);
-}
-
-/* Select which database to use */
-
-int
-DbUtil::selectDb()
-{
- if ((getDbName()) != NULL)
- {
- if(mysql_select_db(m_mysql, this->getDbName()))
- {
- printError("mysql_select_db failed");
- return DBU_FAILED;
- }
- return DBU_OK;
- }
- printError("getDbName() == NULL");
- return DBU_FAILED;
-}
-
-int
-DbUtil::selectDb(const char * m_db)
-{
- {
- if(mysql_select_db(m_mysql, m_db))
- {
- printError("mysql_select_db failed");
- return DBU_FAILED;
- }
- return DBU_OK;
- }
-}
-
-int
-DbUtil::createDb(BaseString& m_db)
-{
- BaseString stm;
- {
- if(mysql_select_db(m_mysql, m_db.c_str()) == DBU_OK)
- {
- stm.assfmt("DROP DATABASE %s", m_db.c_str());
- if(doQuery(m_db.c_str()) == DBU_FAILED)
- return DBU_FAILED;
- }
- stm.assfmt("CREATE DATABASE %s", m_db.c_str());
- if(doQuery(m_db.c_str()) == DBU_FAILED)
- return DBU_FAILED;
- return DBU_OK;
- }
-}
-
-
-/* Count Table Rows */
-
-unsigned long
-DbUtil::selectCountTable(const char * table)
-{
- BaseString query;
- SqlResultSet result;
-
- query.assfmt("select count(*) as count from %s", table);
- if (!doQuery(query, result)) {
- printError("select count(*) failed");
- return -1;
- }
- return result.columnAsInt("count");
-}
-
-
-/* Run Simple Queries */
-
-
-static bool is_int_type(enum_field_types type){
- switch(type){
- case MYSQL_TYPE_TINY:
- case MYSQL_TYPE_SHORT:
- case MYSQL_TYPE_LONGLONG:
- case MYSQL_TYPE_INT24:
- case MYSQL_TYPE_LONG:
- case MYSQL_TYPE_ENUM:
- return true;
- default:
- return false;
- }
- return false;
-}
-
-
-bool
-DbUtil::runQuery(const char* sql,
- const Properties& args,
- SqlResultSet& rows){
-
- rows.clear();
- if (!isConnected())
- return false;
-
- g_debug << "runQuery: " << endl
- << " sql: '" << sql << "'" << endl;
-
-
- MYSQL_STMT *stmt= mysql_stmt_init(m_mysql);
- if (mysql_stmt_prepare(stmt, sql, strlen(sql)))
- {
- g_err << "Failed to prepare: " << mysql_error(m_mysql) << endl;
- return false;
- }
-
- uint params= mysql_stmt_param_count(stmt);
- MYSQL_BIND bind_param[params];
- bzero(bind_param, sizeof(bind_param));
-
- for(uint i= 0; i < mysql_stmt_param_count(stmt); i++)
- {
- BaseString name;
- name.assfmt("%d", i);
- // Parameters are named 0, 1, 2...
- if (!args.contains(name.c_str()))
- {
- g_err << "param " << i << " missing" << endl;
- assert(false);
- }
- PropertiesType t;
- Uint32 val_i;
- const char* val_s;
- args.getTypeOf(name.c_str(), &t);
- switch(t) {
- case PropertiesType_Uint32:
- args.get(name.c_str(), &val_i);
- bind_param[i].buffer_type= MYSQL_TYPE_LONG;
- bind_param[i].buffer= (char*)&val_i;
- g_debug << " param" << name.c_str() << ": " << val_i << endl;
- break;
- case PropertiesType_char:
- args.get(name.c_str(), &val_s);
- bind_param[i].buffer_type= MYSQL_TYPE_STRING;
- bind_param[i].buffer= (char*)val_s;
- bind_param[i].buffer_length= strlen(val_s);
- g_debug << " param" << name.c_str() << ": " << val_s << endl;
- break;
- default:
- assert(false);
- break;
- }
- }
- if (mysql_stmt_bind_param(stmt, bind_param))
- {
- g_err << "Failed to bind param: " << mysql_error(m_mysql) << endl;
- mysql_stmt_close(stmt);
- return false;
- }
-
- if (mysql_stmt_execute(stmt))
- {
- g_err << "Failed to execute: " << mysql_error(m_mysql) << endl;
- mysql_stmt_close(stmt);
- return false;
- }
-
- /*
- Update max_length, making it possible to know how big
- buffers to allocate
- */
- my_bool one= 1;
- mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (void*) &one);
-
- if (mysql_stmt_store_result(stmt))
- {
- g_err << "Failed to store result: " << mysql_error(m_mysql) << endl;
- mysql_stmt_close(stmt);
- return false;
- }
-
- uint row= 0;
- MYSQL_RES* res= mysql_stmt_result_metadata(stmt);
- if (res != NULL)
- {
- MYSQL_FIELD *fields= mysql_fetch_fields(res);
- uint num_fields= mysql_num_fields(res);
- MYSQL_BIND bind_result[num_fields];
- bzero(bind_result, sizeof(bind_result));
-
- for (uint i= 0; i < num_fields; i++)
- {
- if (is_int_type(fields[i].type)){
- bind_result[i].buffer_type= MYSQL_TYPE_LONG;
- bind_result[i].buffer= malloc(sizeof(int));
- }
- else
- {
- uint max_length= fields[i].max_length + 1;
- bind_result[i].buffer_type= MYSQL_TYPE_STRING;
- bind_result[i].buffer= malloc(max_length);
- bind_result[i].buffer_length= max_length;
- }
- }
-
- if (mysql_stmt_bind_result(stmt, bind_result)){
- g_err << "Failed to bind result: " << mysql_error(m_mysql) << endl;
- mysql_stmt_close(stmt);
- return false;
- }
-
- while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA)
- {
- Properties curr(true);
- for (uint i= 0; i < num_fields; i++){
- if (is_int_type(fields[i].type))
- curr.put(fields[i].name, *(int*)bind_result[i].buffer);
- else
- curr.put(fields[i].name, (char*)bind_result[i].buffer);
- }
- rows.put("row", row++, &curr);
- }
-
- mysql_free_result(res);
-
- for (uint i= 0; i < num_fields; i++)
- free(bind_result[i].buffer);
-
- }
-
- // Save stats in result set
- rows.put("rows", row);
- rows.put("affected_rows", mysql_affected_rows(m_mysql));
- rows.put("mysql_errno", mysql_errno(m_mysql));
- rows.put("mysql_error", mysql_error(m_mysql));
- rows.put("mysql_sqlstate", mysql_sqlstate(m_mysql));
- rows.put("insert_id", mysql_insert_id(m_mysql));
-
- mysql_stmt_close(stmt);
- return true;
-}
-
-
-bool
-DbUtil::doQuery(const char* query){
- const Properties args;
- SqlResultSet result;
- return doQuery(query, args, result);
-}
-
-
-bool
-DbUtil::doQuery(const char* query, SqlResultSet& result){
- Properties args;
- return doQuery(query, args, result);
-}
-
-
-bool
-DbUtil::doQuery(const char* query, const Properties& args,
- SqlResultSet& result){
- if (!runQuery(query, args, result))
- return false;
- result.get_row(0); // Load first row
- return true;
-}
-
-
-bool
-DbUtil::doQuery(BaseString& str){
- return doQuery(str.c_str());
-}
-
-
-bool
-DbUtil::doQuery(BaseString& str, SqlResultSet& result){
- return doQuery(str.c_str(), result);
-}
-
-
-bool
-DbUtil::doQuery(BaseString& str, const Properties& args,
- SqlResultSet& result){
- return doQuery(str.c_str(), args, result);
-}
-
-
-/* Return MySQL Error String */
-
-const char *
-DbUtil::getError()
-{
- return mysql_error(this->getMysql());
-}
-
-/* Return MySQL Error Number */
-
-int
-DbUtil::getErrorNumber()
-{
- return mysql_errno(this->getMysql());
-}
-
-/* DIE */
-
-void
-DbUtil::die(const char *file, int line, const char *expr)
-{
- printf("%s:%d: check failed: '%s'\n", file, line, expr);
- abort();
-}
-
-
-/* SqlResultSet */
-
-bool
-SqlResultSet::get_row(int row_num){
- if(!get("row", row_num, &m_curr_row)){
- return false;
- }
- return true;
-}
-
-
-bool
-SqlResultSet::next(void){
- return get_row(++m_curr_row_num);
-}
-
-
-// Reset iterator
-void SqlResultSet::reset(void){
- m_curr_row_num= -1;
- m_curr_row= 0;
-}
-
-
-// Remove row from resultset
-void SqlResultSet::remove(){
- BaseString row_name;
- row_name.assfmt("row_%d", m_curr_row_num);
- Properties::remove(row_name.c_str());
-}
-
-
-SqlResultSet::SqlResultSet(): m_curr_row(0), m_curr_row_num(-1){
-}
-
-
-SqlResultSet::~SqlResultSet(){
-}
-
-
-const char* SqlResultSet::column(const char* col_name){
- const char* value;
- if (!m_curr_row){
- g_err << "ERROR: SqlResultSet::column("<< col_name << ")" << endl
- << "There is no row loaded, call next() before "
- << "acessing the column values" << endl;
- assert(m_curr_row);
- }
- if (!m_curr_row->get(col_name, &value))
- return NULL;
- return value;
-}
-
-
-uint SqlResultSet::columnAsInt(const char* col_name){
- uint value;
- if (!m_curr_row){
- g_err << "ERROR: SqlResultSet::columnAsInt("<< col_name << ")" << endl
- << "There is no row loaded, call next() before "
- << "acessing the column values" << endl;
- assert(m_curr_row);
- }
- if (!m_curr_row->get(col_name, &value))
- return (uint)-1;
- return value;
-}
-
-
-uint SqlResultSet::insertId(){
- return get_int("insert_id");
-}
-
-
-uint SqlResultSet::affectedRows(){
- return get_int("affected_rows");
-}
-
-
-uint SqlResultSet::numRows(void){
- return get_int("rows");
-}
-
-
-uint SqlResultSet::mysqlErrno(void){
- return get_int("mysql_errno");
-}
-
-
-const char* SqlResultSet::mysqlError(void){
- return get_string("mysql_error");
-}
-
-
-const char* SqlResultSet::mysqlSqlstate(void){
- return get_string("mysql_sqlstate");
-}
-
-
-uint SqlResultSet::get_int(const char* name){
- uint value;
- get(name, &value);
- return value;
-}
-
-
-const char* SqlResultSet::get_string(const char* name){
- const char* value;
- get(name, &value);
- return value;
-}
-
-/* EOF */
-
diff --git a/storage/ndb/test/src/HugoAsynchTransactions.cpp b/storage/ndb/test/src/HugoAsynchTransactions.cpp
deleted file mode 100644
index 4ee3c322f6e..00000000000
--- a/storage/ndb/test/src/HugoAsynchTransactions.cpp
+++ /dev/null
@@ -1,486 +0,0 @@
-/* Copyright (c) 2003-2005, 2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NdbSleep.h>
-#include <HugoAsynchTransactions.hpp>
-
-HugoAsynchTransactions::HugoAsynchTransactions(const NdbDictionary::Table& _t)
- : HugoTransactions(_t),
- transactionsCompleted(0),
- numTransactions(0),
- transactions(NULL)
-{
-}
-
-HugoAsynchTransactions::~HugoAsynchTransactions(){
- deallocTransactions();
-}
-
-void asynchCallback(int result, NdbConnection* pTrans,
- void* anObject) {
- HugoAsynchTransactions* pHugo = (HugoAsynchTransactions*) anObject;
-
- pHugo->transactionCompleted();
-
- if (result == -1) {
- const NdbError err = pTrans->getNdbError();
- switch(err.status) {
- case NdbError::Success:
- ERR(err);
- g_info << "ERROR: NdbError reports success when transcaction failed"
- << endl;
- break;
-
- case NdbError::TemporaryError:
- ERR(err);
- break;
-
-#if 0
- case 626: // Tuple did not exist
- g_info << (unsigned int)pHugo->getTransactionsCompleted() << ": "
- << err.code << " " << err.message << endl;
- break;
-#endif
-
- case NdbError::UnknownResult:
- ERR(err);
- break;
-
- case NdbError::PermanentError:
- switch (err.classification) {
- case NdbError::ConstraintViolation:
- // Tuple already existed, OK in this application,
- // but should be reported
- g_info << (unsigned int)pHugo->getTransactionsCompleted()
- << ": " << err.code << " " << err.message << endl;
- break;
- default:
- ERR(err);
- break;
- }
- break;
- }
- } else {// if (result == -1)
- /*
- ndbout << (unsigned int)pHugo->getTransactionsCompleted() << " completed"
- << endl;
- */
- }
-}
-
-int
-HugoAsynchTransactions::loadTableAsynch(Ndb* pNdb,
- int records,
- int batch,
- int trans,
- int operations){
-
- int result = executeAsynchOperation(pNdb, records, batch, trans, operations,
- NO_INSERT);
- g_info << (unsigned int)transactionsCompleted * operations
- << "|- inserted..." << endl;
-
- return result;
-}
-
-void
-HugoAsynchTransactions::transactionCompleted() {
- transactionsCompleted++;
-}
-
-long
-HugoAsynchTransactions::getTransactionsCompleted() {
- return transactionsCompleted;
-}
-
-int
-HugoAsynchTransactions::pkDelRecordsAsynch(Ndb* pNdb,
- int records,
- int batch,
- int trans,
- int operations) {
-
- g_info << "|- Deleting records asynchronous..." << endl;
-
- int result = executeAsynchOperation(pNdb, records, batch, trans,
- operations,
- NO_DELETE);
- g_info << "|- " << (unsigned int)transactionsCompleted * operations
- << " deleted..." << endl;
-
- return result;
-}
-
-int
-HugoAsynchTransactions::pkReadRecordsAsynch(Ndb* pNdb,
- int records,
- int batch,
- int trans,
- int operations) {
-
- g_info << "|- Reading records asynchronous..." << endl;
-
- allocRows(trans*operations);
- int result = executeAsynchOperation(pNdb, records, batch, trans, operations,
- NO_READ);
-
- g_info << "|- " << (unsigned int)transactionsCompleted * operations
- << " read..."
- << endl;
-
- deallocRows();
-
- return result;
-}
-
-int
-HugoAsynchTransactions::pkUpdateRecordsAsynch(Ndb* pNdb,
- int records,
- int batch,
- int trans,
- int operations) {
-
- g_info << "|- Updating records asynchronous..." << endl;
-
- int check = 0;
- int cTrans = 0;
- int cReadRecords = 0;
- int cReadIndex = 0;
- int cRecords = 0;
- int cIndex = 0;
-
- transactionsCompleted = 0;
-
- allocRows(trans*operations);
- allocTransactions(trans);
- int a, t, r;
-
- for (int i = 0; i < batch; i++) { // For each batch
- while (cRecords < records*batch) {
- cTrans = 0;
- cReadIndex = 0;
- for (t = 0; t < trans; t++) { // For each transaction
- transactions[t] = pNdb->startTransaction();
- if (transactions[t] == NULL) {
- ERR(pNdb->getNdbError());
- return NDBT_FAILED;
- }
- for (int k = 0; k < operations; k++) { // For each operation
- NdbOperation* pOp = transactions[t]->getNdbOperation(tab.getName());
- if (pOp == NULL) {
- ERR(transactions[t]->getNdbError());
- pNdb->closeTransaction(transactions[t]);
- return NDBT_FAILED;
- }
-
- // Read
- // Define primary keys
- check = pOp->readTupleExclusive();
- if (equalForRow(pOp, cReadRecords) != 0)
- {
- ERR(transactions[t]->getNdbError());
- pNdb->closeTransaction(transactions[t]);
- return NDBT_FAILED;
- }
- // Define attributes to read
- for (a = 0; a < tab.getNoOfColumns(); a++) {
- if ((rows[cReadIndex]->attributeStore(a) =
- pOp->getValue(tab.getColumn(a)->getName())) == 0) {
- ERR(transactions[t]->getNdbError());
- pNdb->closeTransaction(transactions[t]);
- return NDBT_FAILED;
- }
- }
- cReadIndex++;
- cReadRecords++;
-
- } // For each operation
-
- // Let's prepare...
- transactions[t]->executeAsynchPrepare(NoCommit, &asynchCallback,
- this);
- cTrans++;
-
- if (cReadRecords >= records) {
- // No more transactions needed
- break;
- }
- } // For each transaction
-
- // Wait for all outstanding transactions
- pNdb->sendPollNdb(3000, 0, 0);
-
- // Verify the data!
- for (r = 0; r < trans*operations; r++) {
- if (calc.verifyRowValues(rows[r]) != 0) {
- g_info << "|- Verify failed..." << endl;
- // Close all transactions
- for (int t = 0; t < cTrans; t++) {
- pNdb->closeTransaction(transactions[t]);
- }
- return NDBT_FAILED;
- }
- }
-
- // Update
- cTrans = 0;
- cIndex = 0;
- for (t = 0; t < trans; t++) { // For each transaction
- for (int k = 0; k < operations; k++) { // For each operation
- NdbOperation* pOp = transactions[t]->getNdbOperation(tab.getName());
- if (pOp == NULL) {
- ERR(transactions[t]->getNdbError());
- pNdb->closeTransaction(transactions[t]);
- return NDBT_FAILED;
- }
-
- int updates = calc.getUpdatesValue(rows[cIndex]) + 1;
-
- check = pOp->updateTuple();
- if (check == -1) {
- ERR(transactions[t]->getNdbError());
- pNdb->closeTransaction(transactions[t]);
- return NDBT_FAILED;
- }
-
- // Set search condition for the record
- if (equalForRow(pOp, cReadRecords) != 0)
- {
- ERR(transactions[t]->getNdbError());
- pNdb->closeTransaction(transactions[t]);
- return NDBT_FAILED;
- }
-
- // Update the record
- for (a = 0; a < tab.getNoOfColumns(); a++) {
- if (tab.getColumn(a)->getPrimaryKey() == false) {
- if (setValueForAttr(pOp, a, cRecords, updates) != 0) {
- ERR(transactions[t]->getNdbError());
- pNdb->closeTransaction(transactions[t]);
- return NDBT_FAILED;
- }
- }
- }
- cIndex++;
- cRecords++;
-
- } // For each operation
-
- // Let's prepare...
- transactions[t]->executeAsynchPrepare(Commit, &asynchCallback,
- this);
- cTrans++;
-
- if (cRecords >= records) {
- // No more transactions needed
- break;
- }
- } // For each transaction
-
- // Wait for all outstanding transactions
- pNdb->sendPollNdb(3000, 0, 0);
-
- // Close all transactions
- for (t = 0; t < cTrans; t++) {
- pNdb->closeTransaction(transactions[t]);
- }
-
- } // while (cRecords < records*batch)
-
- } // For each batch
-
- deallocTransactions();
- deallocRows();
-
- g_info << "|- " << ((unsigned int)transactionsCompleted * operations)/2
- << " updated..." << endl;
- return NDBT_OK;
-}
-
-void
-HugoAsynchTransactions::allocTransactions(int trans) {
- if (transactions != NULL) {
- deallocTransactions();
- }
- numTransactions = trans;
- transactions = new NdbConnection*[numTransactions];
-}
-
-void
-HugoAsynchTransactions::deallocTransactions() {
- if (transactions != NULL){
- delete[] transactions;
- }
- transactions = NULL;
-}
-
-int
-HugoAsynchTransactions::executeAsynchOperation(Ndb* pNdb,
- int records,
- int batch,
- int trans,
- int operations,
- NDB_OPERATION theOperation,
- ExecType theType) {
-
- int check = 0;
- // int retryAttempt = 0; // Not used at the moment
- // int retryMax = 5; // Not used at the moment
- int cTrans = 0;
- int cRecords = 0;
- int cIndex = 0;
- int a,t,r;
-
- transactionsCompleted = 0;
- allocTransactions(trans);
-
- for (int i = 0; i < batch; i++) { // For each batch
- while (cRecords < records*batch) {
- cTrans = 0;
- cIndex = 0;
- for (t = 0; t < trans; t++) { // For each transaction
- transactions[t] = pNdb->startTransaction();
- if (transactions[t] == NULL) {
- ERR(pNdb->getNdbError());
- return NDBT_FAILED;
- }
- for (int k = 0; k < operations; k++) { // For each operation
- NdbOperation* pOp = transactions[t]->getNdbOperation(tab.getName());
- if (pOp == NULL) {
- ERR(transactions[t]->getNdbError());
- pNdb->closeTransaction(transactions[t]);
- return NDBT_FAILED;
- }
-
- switch (theOperation) {
- case NO_INSERT:
- // Insert
- check = pOp->insertTuple();
- if (check == -1) {
- ERR(transactions[t]->getNdbError());
- pNdb->closeTransaction(transactions[t]);
- return NDBT_FAILED;
- }
-
- // Set a calculated value for each attribute in this table
- for (a = 0; a < tab.getNoOfColumns(); a++) {
- if (setValueForAttr(pOp, a, cRecords, 0 ) != 0) {
- ERR(transactions[t]->getNdbError());
- pNdb->closeTransaction(transactions[t]);
- return NDBT_FAILED;
- }
- } // For each attribute
- break;
- case NO_UPDATE:
- // This is a special case and is handled in the calling client...
- break;
- break;
- case NO_READ:
- // Define primary keys
- check = pOp->readTuple();
- if (equalForRow(pOp, cRecords) != 0)
- {
- ERR(transactions[t]->getNdbError());
- pNdb->closeTransaction(transactions[t]);
- return NDBT_FAILED;
- }
- // Define attributes to read
- for (a = 0; a < tab.getNoOfColumns(); a++) {
- if ((rows[cIndex]->attributeStore(a) =
- pOp->getValue(tab.getColumn(a)->getName())) == 0) {
- ERR(transactions[t]->getNdbError());
- pNdb->closeTransaction(transactions[t]);
- return NDBT_FAILED;
- }
- }
- break;
- case NO_DELETE:
- // Delete
- check = pOp->deleteTuple();
- if (check == -1) {
- ERR(transactions[t]->getNdbError());
- pNdb->closeTransaction(transactions[t]);
- return NDBT_FAILED;
- }
-
- // Define primary keys
- if (equalForRow(pOp, cRecords) != 0)
- {
- ERR(transactions[t]->getNdbError());
- pNdb->closeTransaction(transactions[t]);
- return NDBT_FAILED;
- }
- break;
- default:
- // Should not happen...
- pNdb->closeTransaction(transactions[t]);
- return NDBT_FAILED;
- }
-
- cIndex++;
- cRecords++;
-
- } // For each operation
-
- // Let's prepare...
- transactions[t]->executeAsynchPrepare(theType, &asynchCallback,
- this);
- cTrans++;
-
- if (cRecords >= records) {
- // No more transactions needed
- break;
- }
- } // For each transaction
-
- // Wait for all outstanding transactions
- pNdb->sendPollNdb(3000, 0, 0);
-
- // ugly... it's starts to resemble flexXXX ...:(
- switch (theOperation) {
- case NO_READ:
- // Verify the data!
- for (r = 0; r < trans*operations; r++) {
- if (calc.verifyRowValues(rows[r]) != 0) {
- g_info << "|- Verify failed..." << endl;
- // Close all transactions
- for (int t = 0; t < cTrans; t++) {
- pNdb->closeTransaction(transactions[t]);
- }
- return NDBT_FAILED;
- }
- }
- break;
- case NO_INSERT:
- case NO_UPDATE:
- case NO_DELETE:
- break;
- }
-
- // Close all transactions
- for (t = 0; t < cTrans; t++) {
- pNdb->closeTransaction(transactions[t]);
- }
-
- } // while (cRecords < records*batch)
-
- } // For each batch
-
- deallocTransactions();
-
- return NDBT_OK;
-
-}
diff --git a/storage/ndb/test/src/HugoCalculator.cpp b/storage/ndb/test/src/HugoCalculator.cpp
deleted file mode 100644
index d0c01ea2bf9..00000000000
--- a/storage/ndb/test/src/HugoCalculator.cpp
+++ /dev/null
@@ -1,314 +0,0 @@
-/* Copyright (c) 2003-2005, 2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-#include "HugoCalculator.hpp"
-#include <NDBT.hpp>
-
-static
-Uint32
-myRand(Uint64 * seed)
-{
- const Uint64 mul= 0x5deece66dull;
- const Uint64 add= 0xb;
- Uint64 loc_result = *seed * mul + add;
-
- * seed= loc_result;
- return loc_result >> 1;
-}
-
-static char base64_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "abcdefghijklmnopqrstuvwxyz"
- "0123456789+/";
-
-/* *************************************************************
- * HugoCalculator
- *
- * Comon class for the Hugo test suite, provides the functions
- * that is used for calculating values to load in to table and
- * also knows how to verify a row that's been read from db
- *
- * ************************************************************/
-HugoCalculator::HugoCalculator(const NdbDictionary::Table& tab) : m_tab(tab) {
-
- // The "id" column of this table is found in the first integer column
- int i;
- for (i=0; i<m_tab.getNoOfColumns(); i++){
- const NdbDictionary::Column* attr = m_tab.getColumn(i);
- if (attr->getType() == NdbDictionary::Column::Unsigned){
- m_idCol = i;
- break;
- }
- }
-
- // The "number of updates" column for this table is found in the last column
- for (i=m_tab.getNoOfColumns()-1; i>=0; i--){
- const NdbDictionary::Column* attr = m_tab.getColumn(i);
- if (attr->getType() == NdbDictionary::Column::Unsigned &&
- !attr->getPrimaryKey()){
- m_updatesCol = i;
- break;
- }
- }
-#if 0
- ndbout << "idCol = " << m_idCol << endl;
- ndbout << "updatesCol = " << m_updatesCol << endl;
-#endif
- // Check that idCol is not conflicting with updatesCol
- assert(m_idCol != m_updatesCol && m_idCol != -1 && m_updatesCol != -1);
-}
-
-Int32
-HugoCalculator::calcValue(int record,
- int attrib,
- int updates) const {
-
- Int32 i;
- Uint32 j;
- calcValue(record, attrib, updates, (char*)&i, sizeof(i), &j);
-
- return i;
-}
-#if 0
-HugoCalculator::U_Int32 calcValue(int record, int attrib, int updates) const;
-HugoCalculator::U_Int64 calcValue(int record, int attrib, int updates) const;
-HugoCalculator::Int64 calcValue(int record, int attrib, int updates) const;
-HugoCalculator::float calcValue(int record, int attrib, int updates) const;
-HugoCalculator::double calcValue(int record, int attrib, int updates) const;
-#endif
-
-static
-Uint32
-calc_len(Uint32 rvalue, int maxlen)
-{
- Uint32 minlen = 25;
-
- if ((rvalue >> 16) < 4096)
- minlen = 15;
- else if ((rvalue >> 16) < 8192)
- minlen = 25;
- else if ((rvalue >> 16) < 16384)
- minlen = 35;
- else
- minlen = 64;
-
- if (maxlen <= minlen)
- return maxlen;
-
- return minlen + (rvalue % (maxlen - minlen));
-}
-
-const char*
-HugoCalculator::calcValue(int record,
- int attrib,
- int updates,
- char* buf,
- int len,
- Uint32 *outlen) const {
- Uint64 seed;
- const NdbDictionary::Column* attr = m_tab.getColumn(attrib);
- Uint32 val;
- * outlen = len;
- do
- {
- if (attrib == m_idCol)
- {
- val= record;
- memcpy(buf, &val, 4);
- return buf;
- }
-
- // If this is the update column
- if (attrib == m_updatesCol)
- {
- val= updates;
- memcpy(buf, &val, 4);
- return buf;
- }
-
- if (attr->getPrimaryKey())
- {
- seed = record + attrib;
- }
- else
- {
- seed = record + attrib + updates;
- }
- } while (0);
-
- val = myRand(&seed);
-
- if(attr->getNullable() && (((val >> 16) & 255) > 220))
- {
- * outlen = 0;
- return NULL;
- }
-
- int pos= 0;
- char* dst= buf;
- switch(attr->getType()){
- case NdbDictionary::Column::Tinyint:
- case NdbDictionary::Column::Tinyunsigned:
- case NdbDictionary::Column::Smallint:
- case NdbDictionary::Column::Smallunsigned:
- case NdbDictionary::Column::Mediumint:
- case NdbDictionary::Column::Mediumunsigned:
- case NdbDictionary::Column::Int:
- case NdbDictionary::Column::Unsigned:
- case NdbDictionary::Column::Bigint:
- case NdbDictionary::Column::Bigunsigned:
- case NdbDictionary::Column::Float:
- case NdbDictionary::Column::Double:
- case NdbDictionary::Column::Olddecimal:
- case NdbDictionary::Column::Olddecimalunsigned:
- case NdbDictionary::Column::Decimal:
- case NdbDictionary::Column::Decimalunsigned:
- case NdbDictionary::Column::Binary:
- case NdbDictionary::Column::Datetime:
- case NdbDictionary::Column::Time:
- case NdbDictionary::Column::Date:
- case NdbDictionary::Column::Bit:
- while (len > 4)
- {
- memcpy(buf+pos, &val, 4);
- pos += 4;
- len -= 4;
- val= myRand(&seed);
- }
-
- memcpy(buf+pos, &val, len);
- if(attr->getType() == NdbDictionary::Column::Bit)
- {
- Uint32 bits= attr->getLength();
- Uint32 tmp = bits >> 5;
- Uint32 size = bits & 31;
- ((Uint32*)buf)[tmp] &= ((1 << size) - 1);
- }
- break;
- case NdbDictionary::Column::Varbinary:
- case NdbDictionary::Column::Varchar:
- len = calc_len(myRand(&seed), len - 1);
- assert(len < 256);
- * outlen = len + 1;
- * buf = len;
- dst++;
- goto write_char;
- case NdbDictionary::Column::Longvarchar:
- case NdbDictionary::Column::Longvarbinary:
- len = calc_len(myRand(&seed), len - 2);
- assert(len < 65536);
- * outlen = len + 2;
- int2store(buf, len);
- dst += 2;
-write_char:
- case NdbDictionary::Column::Char:
- {
- char* ptr= (char*)&val;
- while(len >= 4)
- {
- len -= 4;
- dst[pos++] = base64_table[ptr[0] & 0x3f];
- dst[pos++] = base64_table[ptr[1] & 0x3f];
- dst[pos++] = base64_table[ptr[2] & 0x3f];
- dst[pos++] = base64_table[ptr[3] & 0x3f];
- val= myRand(&seed);
- }
-
- for(; len; len--, pos++)
- dst[pos] = base64_table[ptr[len] & 0x3f];
-
- pos--;
- break;
- }
- case NdbDictionary::Column::Blob:
- case NdbDictionary::Column::Undefined:
- case NdbDictionary::Column::Text:
- abort();
- break;
- }
-
- return buf;
-}
-
-int
-HugoCalculator::verifyRowValues(NDBT_ResultRow* const pRow) const{
- int id, updates;
-
- id = pRow->attributeStore(m_idCol)->u_32_value();
- updates = pRow->attributeStore(m_updatesCol)->u_32_value();
- int result = 0;
-
- // Check the values of each column
- for (int i = 0; i<m_tab.getNoOfColumns(); i++){
- if (i != m_updatesCol && id != m_idCol) {
- const NdbDictionary::Column* attr = m_tab.getColumn(i);
- Uint32 len = attr->getSizeInBytes(), real_len;
- char buf[8000];
- const char* res = calcValue(id, i, updates, buf, len, &real_len);
- if (res == NULL){
- if (!pRow->attributeStore(i)->isNULL()){
- g_err << "|- NULL ERROR: expected a NULL but the column was not null" << endl;
- g_err << "|- The row: \"" << (*pRow) << "\"" << endl;
- result = -1;
- }
- } else{
- if (real_len != pRow->attributeStore(i)->get_size_in_bytes())
- {
- g_err << "|- Invalid data found in attribute " << i << ": \""
- << "Length of expected=" << real_len << endl
- << "Lenght of read="
- << pRow->attributeStore(i)->get_size_in_bytes() << endl;
- result= -1;
- }
- else if (memcmp(res, pRow->attributeStore(i)->aRef(), real_len) != 0)
- {
- g_err << "Column: " << attr->getName() << endl;
- const char* buf2 = pRow->attributeStore(i)->aRef();
- for (Uint32 j = 0; j < len; j++)
- {
- g_err << j << ":" << hex << (Uint32)(Uint8)buf[j] << "[" << hex << (Uint32)(Uint8)buf2[j] << "]";
- if (buf[j] != buf2[j])
- {
- g_err << "==>Match failed!";
- }
- g_err << endl;
- }
- g_err << endl;
- g_err << "|- Invalid data found in attribute " << i << ": \""
- << pRow->attributeStore(i)->aRef()
- << "\" != \"" << res << "\"" << endl
- << "Length of expected=" << (unsigned)strlen(res) << endl
- << "Lenght of read="
- << pRow->attributeStore(i)->get_size_in_bytes() << endl;
- g_err << "|- The row: \"" << (* pRow) << "\"" << endl;
- result = -1;
- }
- }
- }
- }
- return result;
-}
-
-int
-HugoCalculator::getIdValue(NDBT_ResultRow* const pRow) const {
- return pRow->attributeStore(m_idCol)->u_32_value();
-}
-
-int
-HugoCalculator::getUpdatesValue(NDBT_ResultRow* const pRow) const {
- return pRow->attributeStore(m_updatesCol)->u_32_value();
-}
-
diff --git a/storage/ndb/test/src/HugoOperations.cpp b/storage/ndb/test/src/HugoOperations.cpp
deleted file mode 100644
index 35a85dce56f..00000000000
--- a/storage/ndb/test/src/HugoOperations.cpp
+++ /dev/null
@@ -1,753 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <HugoOperations.hpp>
-
-int HugoOperations::startTransaction(Ndb* pNdb,
- const NdbDictionary::Table *table,
- const char *keyData, Uint32 keyLen){
-
- if (pTrans != NULL){
- ndbout << "HugoOperations::startTransaction, pTrans != NULL" << endl;
- return NDBT_FAILED;
- }
- pTrans = pNdb->startTransaction(table, keyData, keyLen);
- if (pTrans == NULL) {
- const NdbError err = pNdb->getNdbError();
- ERR(err);
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int HugoOperations::setTransaction(NdbTransaction* new_trans, bool not_null_ok){
-
- if (pTrans != NULL && !not_null_ok){
- ndbout << "HugoOperations::startTransaction, pTrans != NULL" << endl;
- return NDBT_FAILED;
- }
- pTrans = new_trans;
- if (pTrans == NULL) {
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-void
-HugoOperations::setTransactionId(Uint64 id){
- if (pTrans != NULL){
- pTrans->setTransactionId(id);
- }
-}
-
-int HugoOperations::closeTransaction(Ndb* pNdb){
-
- UtilTransactions::closeTransaction(pNdb);
-
- m_result_sets.clear();
- m_executed_result_sets.clear();
-
- return NDBT_OK;
-}
-
-NdbConnection* HugoOperations::getTransaction(){
- return pTrans;
-}
-
-int HugoOperations::pkReadRecord(Ndb* pNdb,
- int recordNo,
- int numRecords,
- NdbOperation::LockMode lm){
- int a;
- allocRows(numRecords);
- int check;
-
- NdbOperation* pOp = 0;
- pIndexScanOp = 0;
-
- for(int r=0; r < numRecords; r++){
-
- if(pOp == 0)
- {
- pOp = getOperation(pTrans, NdbOperation::ReadRequest);
- }
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
-rand_lock_mode:
- switch(lm){
- case NdbOperation::LM_Read:
- case NdbOperation::LM_Exclusive:
- case NdbOperation::LM_CommittedRead:
- case NdbOperation::LM_SimpleRead:
- if(idx && idx->getType() == NdbDictionary::Index::OrderedIndex &&
- pIndexScanOp == 0)
- {
- pIndexScanOp = ((NdbIndexScanOperation*)pOp);
- check = pIndexScanOp->readTuples(lm);
- }
- else
- check = pOp->readTuple(lm);
- break;
- default:
- lm = (NdbOperation::LockMode)((rand() >> 16) & 3);
- goto rand_lock_mode;
- }
-
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- // Define primary keys
- if (equalForRow(pOp, r+recordNo) != 0)
- return NDBT_FAILED;
-
- if(pIndexScanOp)
- pIndexScanOp->end_of_bound(r);
-
- if(r == 0 || pIndexScanOp == 0)
- {
- // Define attributes to read
- for(a = 0; a<tab.getNoOfColumns(); a++){
- if((rows[r]->attributeStore(a) =
- pOp->getValue(tab.getColumn(a)->getName())) == 0) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
- }
- }
- pOp = pIndexScanOp;
- }
- return NDBT_OK;
-}
-
-int HugoOperations::pkUpdateRecord(Ndb* pNdb,
- int recordNo,
- int numRecords,
- int updatesValue){
- allocRows(numRecords);
- int check;
- for(int r=0; r < numRecords; r++){
- NdbOperation* pOp = getOperation(pTrans, NdbOperation::UpdateRequest);
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp->updateTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- if(setValues(pOp, r+recordNo, updatesValue) != NDBT_OK)
- {
- return NDBT_FAILED;
- }
- }
- return NDBT_OK;
-}
-
-int
-HugoOperations::setValues(NdbOperation* pOp, int rowId, int updateId)
-{
- // Define primary keys
- int a;
- if (equalForRow(pOp, rowId) != 0)
- return NDBT_FAILED;
-
- for(a = 0; a<tab.getNoOfColumns(); a++){
- if (tab.getColumn(a)->getPrimaryKey() == false){
- if(setValueForAttr(pOp, a, rowId, updateId ) != 0){
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
- }
- }
-
- return NDBT_OK;
-}
-
-int HugoOperations::pkInsertRecord(Ndb* pNdb,
- int recordNo,
- int numRecords,
- int updatesValue){
-
- int check;
- for(int r=0; r < numRecords; r++){
- NdbOperation* pOp = getOperation(pTrans, NdbOperation::InsertRequest);
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp->insertTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- if(setValues(pOp, r+recordNo, updatesValue) != NDBT_OK)
- {
- return NDBT_FAILED;
- }
- }
- return NDBT_OK;
-}
-
-int HugoOperations::pkWriteRecord(Ndb* pNdb,
- int recordNo,
- int numRecords,
- int updatesValue){
-
- int a, check;
- for(int r=0; r < numRecords; r++){
- NdbOperation* pOp = pTrans->getNdbOperation(tab.getName());
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp->writeTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- // Define primary keys
- if (equalForRow(pOp, r+recordNo) != 0)
- return NDBT_FAILED;
-
- // Define attributes to update
- for(a = 0; a<tab.getNoOfColumns(); a++){
- if (tab.getColumn(a)->getPrimaryKey() == false){
- if(setValueForAttr(pOp, a, recordNo+r, updatesValue ) != 0){
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
- }
- }
- }
- return NDBT_OK;
-}
-
-int HugoOperations::pkWritePartialRecord(Ndb* pNdb,
- int recordNo,
- int numRecords){
-
- int check;
- for(int r=0; r < numRecords; r++){
- NdbOperation* pOp = pTrans->getNdbOperation(tab.getName());
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp->writeTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- // Define primary keys
- if (equalForRow(pOp, r+recordNo) != 0)
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int HugoOperations::pkDeleteRecord(Ndb* pNdb,
- int recordNo,
- int numRecords){
-
- int check;
- for(int r=0; r < numRecords; r++){
- NdbOperation* pOp = getOperation(pTrans, NdbOperation::DeleteRequest);
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp->deleteTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- // Define primary keys
- if (equalForRow(pOp, r+recordNo) != 0)
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-int HugoOperations::execute_Commit(Ndb* pNdb,
- AbortOption eao){
-
- int check = 0;
- check = pTrans->execute(Commit, eao);
-
- const NdbError err = pTrans->getNdbError();
- if( check == -1 || err.code) {
- ERR(err);
- NdbOperation* pOp = pTrans->getNdbErrorOperation();
- if (pOp != NULL){
- const NdbError err2 = pOp->getNdbError();
- ERR(err2);
- }
- if (err.code == 0)
- return NDBT_FAILED;
- return err.code;
- }
-
- for(int i = 0; i<m_result_sets.size(); i++){
- m_executed_result_sets.push_back(m_result_sets[i]);
-
- int rows = m_result_sets[i].records;
- NdbScanOperation* rs = m_result_sets[i].m_result_set;
- int res = rs->nextResult();
- switch(res){
- case 1:
- return 626;
- case -1:
- const NdbError err = pTrans->getNdbError();
- ERR(err);
- return (err.code > 0 ? err.code : NDBT_FAILED);
- }
-
- // A row found
-
- switch(rows){
- case 0:
- return 4000;
- default:
- m_result_sets[i].records--;
- break;
- }
- }
-
- m_result_sets.clear();
-
- return NDBT_OK;
-}
-
-int HugoOperations::execute_NoCommit(Ndb* pNdb, AbortOption eao){
-
- int check;
- check = pTrans->execute(NoCommit, eao);
-
- const NdbError err = pTrans->getNdbError();
- if( check == -1 || err.code) {
- ERR(err);
- const NdbOperation* pOp = pTrans->getNdbErrorOperation();
- while (pOp != NULL)
- {
- const NdbError err2 = pOp->getNdbError();
- if (err2.code)
- ERR(err2);
- pOp = pTrans->getNextCompletedOperation(pOp);
- }
- if (err.code == 0)
- return NDBT_FAILED;
- return err.code;
- }
-
- for(int i = 0; i<m_result_sets.size(); i++){
- m_executed_result_sets.push_back(m_result_sets[i]);
-
- int rows = m_result_sets[i].records;
- NdbScanOperation* rs = m_result_sets[i].m_result_set;
- int res = rs->nextResult();
- switch(res){
- case 1:
- return 626;
- case -1:
- const NdbError err = pTrans->getNdbError();
- ERR(err);
- return (err.code > 0 ? err.code : NDBT_FAILED);
- }
-
- // A row found
-
- switch(rows){
- case 0:
- return 4000;
- default:
- case 1:
- break;
- }
- }
-
- m_result_sets.clear();
-
- return NDBT_OK;
-}
-
-int HugoOperations::execute_Rollback(Ndb* pNdb){
- int check;
- check = pTrans->execute(Rollback);
- if( check == -1 ) {
- const NdbError err = pTrans->getNdbError();
- ERR(err);
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-void
-HugoOperations_async_callback(int res, NdbTransaction* pCon, void* ho)
-{
- ((HugoOperations*)ho)->callback(res, pCon);
-}
-
-void
-HugoOperations::callback(int res, NdbTransaction* pCon)
-{
- assert(pCon == pTrans);
- m_async_reply= 1;
- if(res)
- {
- m_async_return = pCon->getNdbError().code;
- }
- else
- {
- m_async_return = 0;
- }
-}
-
-int
-HugoOperations::execute_async(Ndb* pNdb, NdbTransaction::ExecType et,
- NdbOperation::AbortOption eao){
-
- m_async_reply= 0;
- pTrans->executeAsynchPrepare(et,
- HugoOperations_async_callback,
- this,
- eao);
-
- pNdb->sendPreparedTransactions();
-
- return NDBT_OK;
-}
-
-int
-HugoOperations::execute_async_prepare(Ndb* pNdb, NdbTransaction::ExecType et,
- NdbOperation::AbortOption eao){
-
- m_async_reply= 0;
- pTrans->executeAsynchPrepare(et,
- HugoOperations_async_callback,
- this,
- eao);
-
- return NDBT_OK;
-}
-
-int
-HugoOperations::wait_async(Ndb* pNdb, int timeout)
-{
- volatile int * wait = &m_async_reply;
- while (!* wait)
- {
- pNdb->sendPollNdb(1000);
-
- if(* wait)
- {
- if(m_async_return)
- ndbout << "ERROR: " << pNdb->getNdbError(m_async_return) << endl;
- return m_async_return;
- }
- }
- ndbout_c("wait returned nothing...");
- return -1;
-}
-
-HugoOperations::HugoOperations(const NdbDictionary::Table& _tab,
- const NdbDictionary::Index* idx):
- UtilTransactions(_tab, idx),
- calc(_tab)
-{
-}
-
-HugoOperations::~HugoOperations(){
- deallocRows();
- if (pTrans != NULL)
- {
- pTrans->close();
- pTrans = NULL;
- }
-}
-
-int
-HugoOperations::equalForRow(NdbOperation* pOp, int row)
-{
- for(int a = 0; a<tab.getNoOfColumns(); a++)
- {
- if (tab.getColumn(a)->getPrimaryKey() == true)
- {
- if(equalForAttr(pOp, a, row) != 0)
- {
- ERR(pOp->getNdbError());
- return NDBT_FAILED;
- }
- }
- }
- return NDBT_OK;
-}
-
-int HugoOperations::equalForAttr(NdbOperation* pOp,
- int attrId,
- int rowId){
- int check = -1;
- const NdbDictionary::Column* attr = tab.getColumn(attrId);
- if (attr->getPrimaryKey() == false){
- g_info << "Can't call equalForAttr on non PK attribute" << endl;
- return NDBT_FAILED;
- }
-
- int len = attr->getSizeInBytes();
- char buf[8000];
- memset(buf, 0, sizeof(buf));
- Uint32 real_len;
- const char * value = calc.calcValue(rowId, attrId, 0, buf, len, &real_len);
- return pOp->equal( attr->getName(), value, real_len);
-}
-
-int HugoOperations::setValueForAttr(NdbOperation* pOp,
- int attrId,
- int rowId,
- int updateId){
- int check = -1;
- const NdbDictionary::Column* attr = tab.getColumn(attrId);
-
- int len = attr->getSizeInBytes();
- char buf[8000];
- memset(buf, 0, sizeof(buf));
- Uint32 real_len;
- const char * value = calc.calcValue(rowId, attrId,
- updateId, buf, len, &real_len);
- return pOp->setValue( attr->getName(), value, real_len);
-}
-
-int
-HugoOperations::verifyUpdatesValue(int updatesValue, int _numRows){
- _numRows = (_numRows == 0 ? rows.size() : _numRows);
-
- int result = NDBT_OK;
-
- for(int i = 0; i<_numRows; i++){
- if(calc.verifyRowValues(rows[i]) != NDBT_OK){
- g_err << "Inconsistent row"
- << endl << "\t" << rows[i]->c_str().c_str() << endl;
- result = NDBT_FAILED;
- continue;
- }
-
- if(calc.getUpdatesValue(rows[i]) != updatesValue){
- result = NDBT_FAILED;
- g_err << "Invalid updates value for row " << i << endl
- << " updatesValue: " << updatesValue << endl
- << " calc.getUpdatesValue: " << calc.getUpdatesValue(rows[i]) << endl
- << rows[i]->c_str().c_str() << endl;
- continue;
- }
- }
-
- if(_numRows == 0){
- g_err << "No rows -> Invalid updates value" << endl;
- return NDBT_FAILED;
- }
-
- return result;
-}
-
-void HugoOperations::allocRows(int _numRows){
- if(_numRows <= 0){
- g_info << "Illegal value for num rows : " << _numRows << endl;
- abort();
- }
-
- for(int b=rows.size(); b<_numRows; b++){
- rows.push_back(new NDBT_ResultRow(tab));
- }
-}
-
-void HugoOperations::deallocRows(){
- while(rows.size() > 0){
- delete rows.back();
- rows.erase(rows.size() - 1);
- }
-}
-
-int HugoOperations::saveCopyOfRecord(int numRecords ){
-
- if (numRecords > (int)rows.size())
- return NDBT_FAILED;
-
- for (int i = 0; i < numRecords; i++){
- savedRecords.push_back(rows[i]->c_str());
- }
- return NDBT_OK;
-}
-
-BaseString HugoOperations::getRecordStr(int recordNum){
- if (recordNum > (int)rows.size())
- return NULL;
- return rows[recordNum]->c_str();
-}
-
-int HugoOperations::getRecordGci(int recordNum){
- return pTrans->getGCI();
-}
-
-
-int HugoOperations::compareRecordToCopy(int numRecords ){
- if (numRecords > (int)rows.size())
- return NDBT_FAILED;
- if ((unsigned)numRecords > savedRecords.size())
- return NDBT_FAILED;
-
- int result = NDBT_OK;
- for (int i = 0; i < numRecords; i++){
- BaseString str = rows[i]->c_str();
- ndbout << "row["<<i<<"]: " << str << endl;
- ndbout << "sav["<<i<<"]: " << savedRecords[i] << endl;
- if (savedRecords[i] == str){
- ;
- } else {
- result = NDBT_FAILED;
- }
- }
- return result;
-}
-
-void
-HugoOperations::refresh() {
- NdbTransaction * t = getTransaction();
- if(t)
- t->refresh();
-}
-
-int HugoOperations::indexReadRecords(Ndb*, const char * idxName, int recordNo,
- bool exclusive,
- int numRecords){
-
- int a;
- allocRows(numRecords);
- int check;
- for(int r=0; r < numRecords; r++){
- NdbOperation* pOp = pTrans->getNdbIndexOperation(idxName, tab.getName());
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- if (exclusive == true)
- check = pOp->readTupleExclusive();
- else
- check = pOp->readTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- // Define primary keys
- if (equalForRow(pOp, r+recordNo) != 0)
- return NDBT_FAILED;
-
- // Define attributes to read
- for(a = 0; a<tab.getNoOfColumns(); a++){
- if((rows[r]->attributeStore(a) =
- pOp->getValue(tab.getColumn(a)->getName())) == 0) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
- }
- }
- return NDBT_OK;
-}
-
-int
-HugoOperations::indexUpdateRecord(Ndb*,
- const char * idxName,
- int recordNo,
- int numRecords,
- int updatesValue){
- int a;
- allocRows(numRecords);
- int check;
- for(int r=0; r < numRecords; r++){
- NdbOperation* pOp = pTrans->getNdbIndexOperation(idxName, tab.getName());
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pOp->updateTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- // Define primary keys
- if (equalForRow(pOp, r+recordNo) != 0)
- return NDBT_FAILED;
-
- // Define attributes to update
- for(a = 0; a<tab.getNoOfColumns(); a++){
- if (tab.getColumn(a)->getPrimaryKey() == false){
- if(setValueForAttr(pOp, a, recordNo+r, updatesValue ) != 0){
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
- }
- }
- }
- return NDBT_OK;
-}
-
-int
-HugoOperations::scanReadRecords(Ndb* pNdb, NdbScanOperation::LockMode lm,
- int records){
-
- allocRows(records);
- NdbScanOperation * pOp = pTrans->getNdbScanOperation(tab.getName());
-
- if(!pOp)
- return -1;
-
- if(pOp->readTuples(lm, 0, 1)){
- return -1;
- }
-
- for(int a = 0; a<tab.getNoOfColumns(); a++){
- if((rows[0]->attributeStore(a) =
- pOp->getValue(tab.getColumn(a)->getName())) == 0) {
- ERR(pTrans->getNdbError());
- return NDBT_FAILED;
- }
- }
-
- RsPair p = {pOp, records};
- m_result_sets.push_back(p);
-
- return 0;
-}
-
-template class Vector<HugoOperations::RsPair>;
diff --git a/storage/ndb/test/src/HugoTransactions.cpp b/storage/ndb/test/src/HugoTransactions.cpp
deleted file mode 100644
index 67e42ec072e..00000000000
--- a/storage/ndb/test/src/HugoTransactions.cpp
+++ /dev/null
@@ -1,1864 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include "HugoTransactions.hpp"
-#include <NDBT_Stats.hpp>
-#include <NdbSleep.h>
-#include <NdbTick.h>
-
-HugoTransactions::HugoTransactions(const NdbDictionary::Table& _tab,
- const NdbDictionary::Index* idx):
- HugoOperations(_tab, idx),
- row(_tab){
-
- m_defaultScanUpdateMethod = 3;
- setRetryMax();
- m_stats_latency = 0;
-
- m_thr_count = 0;
- m_thr_no = -1;
-}
-
-HugoTransactions::~HugoTransactions(){
- deallocRows();
-}
-
-int
-HugoTransactions::scanReadRecords(Ndb* pNdb,
- int records,
- int abortPercent,
- int parallelism,
- NdbOperation::LockMode lm,
- int scan_flags)
-{
-
- int retryAttempt = 0;
- int check, a;
- NdbScanOperation *pOp;
-
- while (true){
-
- if (retryAttempt >= m_retryMax){
- g_err << "ERROR: has retried this operation " << retryAttempt
- << " times, failing!" << endl;
- return NDBT_FAILED;
- }
-
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- const NdbError err = pNdb->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- return NDBT_FAILED;
- }
-
- pOp = getScanOperation(pTrans);
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- if( pOp ->readTuples(lm, scan_flags, parallelism) ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- check = pOp->interpret_exit_ok();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- for(a = 0; a<tab.getNoOfColumns(); a++){
- if((row.attributeStore(a) =
- pOp->getValue(tab.getColumn(a)->getName())) == 0) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- }
-
- check = pTrans->execute(NoCommit, AbortOnError);
- if( check == -1 ) {
- const NdbError err = pTrans->getNdbError();
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- // Abort after 1-100 or 1-records rows
- int ranVal = rand();
- int abortCount = ranVal % (records == 0 ? 100 : records);
- bool abortTrans = false;
- if (abort > 0){
- // Abort if abortCount is less then abortPercent
- if (abortCount < abortPercent)
- abortTrans = true;
- }
-
- int eof;
- int rows = 0;
- while((eof = pOp->nextResult(true)) == 0){
- rows++;
- if (calc.verifyRowValues(&row) != 0){
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- if (abortCount == rows && abortTrans == true){
- ndbout << "Scan is aborted" << endl;
- g_info << "Scan is aborted" << endl;
- pOp->close();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- closeTransaction(pNdb);
- return NDBT_OK;
- }
- }
- if (eof == -1) {
- const NdbError err = pTrans->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR_INFO(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- switch (err.code){
- case 488:
- case 245:
- case 490:
- // Too many active scans, no limit on number of retry attempts
- break;
- default:
- retryAttempt++;
- }
- continue;
- }
- ERR(err);
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- closeTransaction(pNdb);
-
- g_info << rows << " rows have been read" << endl;
- if (records != 0 && rows != records){
- g_err << "Check expected number of records failed" << endl
- << " expected=" << records <<", " << endl
- << " read=" << rows << endl;
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
- }
- return NDBT_FAILED;
-}
-
-int
-HugoTransactions::scanReadRecords(Ndb* pNdb,
- const NdbDictionary::Index * pIdx,
- int records,
- int abortPercent,
- int parallelism,
- NdbOperation::LockMode lm,
- int scan_flags)
-{
-
- int retryAttempt = 0;
- int check, a;
- NdbIndexScanOperation *pOp;
-
- while (true){
-
- if (retryAttempt >= m_retryMax){
- g_err << "ERROR: has retried this operation " << retryAttempt
- << " times, failing!" << endl;
- return NDBT_FAILED;
- }
-
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- const NdbError err = pNdb->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- return NDBT_FAILED;
- }
-
- pOp = pTrans->getNdbIndexScanOperation(pIdx->getName(), tab.getName());
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- if( pOp ->readTuples(lm, scan_flags, parallelism) ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- check = pOp->interpret_exit_ok();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- for(a = 0; a<tab.getNoOfColumns(); a++){
- if((row.attributeStore(a) =
- pOp->getValue(tab.getColumn(a)->getName())) == 0) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- }
-
- check = pTrans->execute(NoCommit, AbortOnError);
- if( check == -1 ) {
- const NdbError err = pTrans->getNdbError();
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- // Abort after 1-100 or 1-records rows
- int ranVal = rand();
- int abortCount = ranVal % (records == 0 ? 100 : records);
- bool abortTrans = false;
- if (abort > 0){
- // Abort if abortCount is less then abortPercent
- if (abortCount < abortPercent)
- abortTrans = true;
- }
-
- int eof;
- int rows = 0;
- while((eof = pOp->nextResult(true)) == 0){
- rows++;
- if (calc.verifyRowValues(&row) != 0){
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- if (abortCount == rows && abortTrans == true){
- ndbout << "Scan is aborted" << endl;
- g_info << "Scan is aborted" << endl;
- pOp->close();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- closeTransaction(pNdb);
- return NDBT_OK;
- }
- }
- if (eof == -1) {
- const NdbError err = pTrans->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR_INFO(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- switch (err.code){
- case 488:
- case 245:
- case 490:
- // Too many active scans, no limit on number of retry attempts
- break;
- default:
- retryAttempt++;
- }
- continue;
- }
- ERR(err);
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- closeTransaction(pNdb);
-
- g_info << rows << " rows have been read" << endl;
- if (records != 0 && rows != records){
- g_err << "Check expected number of records failed" << endl
- << " expected=" << records <<", " << endl
- << " read=" << rows << endl;
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
- }
- return NDBT_FAILED;
-}
-
-
-#define RESTART_SCAN 99
-
-int
-HugoTransactions::scanUpdateRecords(Ndb* pNdb,
- NdbScanOperation::ScanFlag flags,
- int records,
- int abortPercent,
- int parallelism){
- int retryAttempt = 0;
- int check, a;
- NdbScanOperation *pOp;
-
- while (true){
-restart:
- if (retryAttempt++ >= m_retryMax){
- g_info << "ERROR: has retried this operation " << retryAttempt
- << " times, failing!" << endl;
- return NDBT_FAILED;
- }
-
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- const NdbError err = pNdb->getNdbError();
- ERR(err);
- if (err.status == NdbError::TemporaryError){
- NdbSleep_MilliSleep(50);
- continue;
- }
- return NDBT_FAILED;
- }
-
- pOp = getScanOperation(pTrans);
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- if( pOp->readTuples(NdbOperation::LM_Exclusive, flags,
- parallelism))
- {
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- // Read all attributes from this table
- for(a=0; a<tab.getNoOfColumns(); a++){
- if((row.attributeStore(a) = pOp->getValue(tab.getColumn(a)->getName())) == NULL){
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- }
-
- check = pTrans->execute(NoCommit, AbortOnError);
- if( check == -1 ) {
- const NdbError err = pTrans->getNdbError();
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- // Abort after 1-100 or 1-records rows
- int ranVal = rand();
- int abortCount = ranVal % (records == 0 ? 100 : records);
- bool abortTrans = false;
- if (abort > 0){
- // Abort if abortCount is less then abortPercent
- if (abortCount < abortPercent)
- abortTrans = true;
- }
-
- int eof;
- int rows = 0;
- while((eof = pOp->nextResult(true)) == 0){
- rows++;
- if (calc.verifyRowValues(&row) != 0){
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- if (abortCount == rows && abortTrans == true){
- ndbout << "Scan is aborted" << endl;
- g_info << "Scan is aborted" << endl;
- pOp->close();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- closeTransaction(pNdb);
- return NDBT_OK;
- }
- }
- if (eof == -1) {
- const NdbError err = pTrans->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR_INFO(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- switch (err.code){
- case 488:
- case 245:
- case 490:
- // Too many active scans, no limit on number of retry attempts
- break;
- default:
- retryAttempt++;
- }
- continue;
- }
- ERR(err);
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- closeTransaction(pNdb);
-
- g_info << rows << " rows have been read" << endl;
- if (records != 0 && rows != records){
- g_err << "Check expected number of records failed" << endl
- << " expected=" << records <<", " << endl
- << " read=" << rows << endl;
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
- }
- return NDBT_FAILED;
-}
-
-int
-HugoTransactions::scanUpdateRecords(Ndb* pNdb,
- int records,
- int abortPercent,
- int parallelism){
-
- return scanUpdateRecords(pNdb,
- (NdbScanOperation::ScanFlag)0,
- records, abortPercent, parallelism);
-}
-
-// Scan all records exclusive and update
-// them one by one
-int
-HugoTransactions::scanUpdateRecords1(Ndb* pNdb,
- int records,
- int abortPercent,
- int parallelism){
- return scanUpdateRecords(pNdb,
- (NdbScanOperation::ScanFlag)0,
- records, abortPercent, 1);
-}
-
-// Scan all records exclusive and update
-// them batched by asking nextScanResult to
-// give us all cached records before fetching new
-// records from db
-int
-HugoTransactions::scanUpdateRecords2(Ndb* pNdb,
- int records,
- int abortPercent,
- int parallelism){
- return scanUpdateRecords(pNdb, (NdbScanOperation::ScanFlag)0,
- records, abortPercent, parallelism);
-}
-
-int
-HugoTransactions::scanUpdateRecords3(Ndb* pNdb,
- int records,
- int abortPercent,
- int parallelism)
-{
- return scanUpdateRecords(pNdb, (NdbScanOperation::ScanFlag)0,
- records, abortPercent, parallelism);
-}
-
-int
-HugoTransactions::loadTable(Ndb* pNdb,
- int records,
- int batch,
- bool allowConstraintViolation,
- int doSleep,
- bool oneTrans,
- int value,
- bool abort)
-{
- return loadTableStartFrom(pNdb, 0, records, batch, allowConstraintViolation,
- doSleep, oneTrans, value, abort);
-}
-
-int
-HugoTransactions::loadTableStartFrom(Ndb* pNdb,
- int startFrom,
- int records,
- int batch,
- bool allowConstraintViolation,
- int doSleep,
- bool oneTrans,
- int value,
- bool abort){
- int check;
- int retryAttempt = 0;
- int retryMax = 5;
- bool first_batch = true;
-
- const int org = batch;
- const int cols = tab.getNoOfColumns();
- const int brow = tab.getRowSizeInBytes();
- const int bytes = 12 + brow + 4 * cols;
- batch = (batch * 256); // -> 512 -> 65536k per commit
- batch = batch/bytes; //
- batch = batch == 0 ? 1 : batch;
-
- if(batch != org){
- g_info << "batch = " << org << " rowsize = " << bytes
- << " -> rows/commit = " << batch << endl;
- }
-
- Uint32 orgbatch = batch;
- g_info << "|- Inserting records..." << endl;
- for (int c=0 ; c<records; ){
- bool closeTrans = true;
-
- if(c + batch > records)
- batch = records - c;
-
- if (retryAttempt >= retryMax){
- g_info << "Record " << c << " could not be inserted, has retried "
- << retryAttempt << " times " << endl;
- // Reset retry counters and continue with next record
- retryAttempt = 0;
- c++;
- }
- if (doSleep > 0)
- NdbSleep_MilliSleep(doSleep);
-
- // if (first_batch || !oneTrans) {
- if (first_batch || !pTrans) {
- first_batch = false;
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- const NdbError err = pNdb->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- return NDBT_FAILED;
- }
- }
-
- if(pkInsertRecord(pNdb, c + startFrom, batch, value) != NDBT_OK)
- {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- // Execute the transaction and insert the record
- if (!oneTrans || (c + batch) >= records) {
- // closeTrans = true;
- closeTrans = false;
- if (!abort)
- {
- check = pTrans->execute(Commit, AbortOnError);
- if(check != -1)
- m_latest_gci = pTrans->getGCI();
- pTrans->restart();
- }
- else
- {
- check = pTrans->execute(NoCommit, AbortOnError);
- if (check != -1)
- {
- check = pTrans->execute( Rollback );
- closeTransaction(pNdb);
- }
- }
- } else {
- closeTrans = false;
- check = pTrans->execute(NoCommit, AbortOnError);
- }
- if(check == -1 ) {
- const NdbError err = pTrans->getNdbError();
- closeTransaction(pNdb);
- pTrans= 0;
- switch(err.status){
- case NdbError::Success:
- ERR(err);
- g_info << "ERROR: NdbError reports success when transcaction failed"
- << endl;
- return NDBT_FAILED;
- break;
-
- case NdbError::TemporaryError:
- ERR(err);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- batch = 1;
- continue;
- break;
-
- case NdbError::UnknownResult:
- ERR(err);
- return NDBT_FAILED;
- break;
-
- case NdbError::PermanentError:
- if (allowConstraintViolation == true){
- switch (err.classification){
- case NdbError::ConstraintViolation:
- // Tuple already existed, OK but should be reported
- g_info << c << ": " << err.code << " " << err.message << endl;
- c++;
- continue;
- break;
- default:
- break;
- }
- }
- ERR(err);
- return err.code;
- break;
- }
- }
- else{
- if (closeTrans) {
- closeTransaction(pNdb);
- pTrans= 0;
- }
- }
-
- // Step to next record
- c = c+batch;
- retryAttempt = 0;
- }
-
- if(pTrans)
- closeTransaction(pNdb);
- return NDBT_OK;
-}
-
-int
-HugoTransactions::fillTable(Ndb* pNdb,
- int batch){
- return fillTableStartFrom(pNdb, 0, batch);
-}
-
-int
-HugoTransactions::fillTableStartFrom(Ndb* pNdb,
- int startFrom,
- int batch){
- int check;
- int retryAttempt = 0;
- int retryMax = 5;
-
- const int org = batch;
- const int cols = tab.getNoOfColumns();
- const int brow = tab.getRowSizeInBytes();
- const int bytes = 12 + brow + 4 * cols;
- batch = (batch * 256); // -> 512 -> 65536k per commit
- batch = batch/bytes; //
- batch = batch == 0 ? 1 : batch;
-
- if(batch != org){
- g_info << "batch = " << org << " rowsize = " << bytes
- << " -> rows/commit = " << batch << endl;
- }
-
- for (int c=startFrom ; ; ){
-
- if (retryAttempt >= retryMax){
- g_info << "Record " << c << " could not be inserted, has retried "
- << retryAttempt << " times " << endl;
- // Reset retry counters and continue with next record
- retryAttempt = 0;
- c++;
- }
-
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- const NdbError err = pNdb->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- return NDBT_FAILED;
- }
-
- if(pkInsertRecord(pNdb, c, batch) != NDBT_OK)
- {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- // Execute the transaction and insert the record
- check = pTrans->execute(Commit, CommitAsMuchAsPossible);
- if(check == -1 ) {
- const NdbError err = pTrans->getNdbError();
- closeTransaction(pNdb);
-
- switch(err.status){
- case NdbError::Success:
- ERR(err);
- g_info << "ERROR: NdbError reports success when transcaction failed"
- << endl;
- return NDBT_FAILED;
- break;
-
- case NdbError::TemporaryError:
- ERR(err);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- break;
-
- case NdbError::UnknownResult:
- ERR(err);
- return NDBT_FAILED;
- break;
-
- case NdbError::PermanentError:
- // if (allowConstraintViolation == true){
- // switch (err.classification){
- // case NdbError::ConstraintViolation:
- // // Tuple already existed, OK but should be reported
- // g_info << c << ": " << err.code << " " << err.message << endl;
- // c++;
- // continue;
- // break;
- // default:
- // break;es
- // }
- // }
-
- // Check if this is the "db full" error
- if (err.classification==NdbError::InsufficientSpace){
- ERR(err);
- return NDBT_OK;
- }
-
- if (err.classification == NdbError::ConstraintViolation){
- ERR(err);
- break;
- }
- ERR(err);
- return NDBT_FAILED;
- break;
- }
- }
- else{
- m_latest_gci = pTrans->getGCI();
- closeTransaction(pNdb);
- }
-
- // Step to next record
- c = c+batch;
- retryAttempt = 0;
- }
- return NDBT_OK;
-}
-
-int
-HugoTransactions::pkReadRecords(Ndb* pNdb,
- int records,
- int batch,
- NdbOperation::LockMode lm){
- int reads = 0;
- int r = 0;
- int retryAttempt = 0;
- int check;
-
- if (batch == 0) {
- g_info << "ERROR: Argument batch == 0 in pkReadRecords(). Not allowed." << endl;
- return NDBT_FAILED;
- }
-
- while (r < records){
- if(r + batch > records)
- batch = records - r;
-
- if (retryAttempt >= m_retryMax){
- g_info << "ERROR: has retried this operation " << retryAttempt
- << " times, failing!" << endl;
- return NDBT_FAILED;
- }
-
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- const NdbError err = pNdb->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- return NDBT_FAILED;
- }
-
- MicroSecondTimer timer_start;
- MicroSecondTimer timer_stop;
- bool timer_active =
- m_stats_latency != 0 &&
- r >= batch && // first batch is "warmup"
- r + batch != records; // last batch is usually partial
-
- if (timer_active)
- NdbTick_getMicroTimer(&timer_start);
-
- if(pkReadRecord(pNdb, r, batch, lm) != NDBT_OK)
- {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- check = pTrans->execute(Commit, AbortOnError);
- if( check == -1 ) {
- const NdbError err = pTrans->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- switch(err.code){
- case 626: // Tuple did not exist
- g_info << r << ": " << err.code << " " << err.message << endl;
- r++;
- break;
-
- default:
- ERR(err);
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- } else {
-
- if(pIndexScanOp)
- {
- int rows_found = 0;
- while((check = pIndexScanOp->nextResult()) == 0)
- {
- rows_found++;
- if (calc.verifyRowValues(rows[0]) != 0){
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- }
- if(check != 1 || rows_found > batch)
- {
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- else if(rows_found < batch)
- {
- if(batch == 1){
- g_info << r << ": not found" << endl; abort(); }
- else
- g_info << "Found " << rows_found << " of "
- << batch << " rows" << endl;
- }
- r += batch;
- reads += rows_found;
- }
- else
- {
- for (int b=0; (b<batch) && (r+b<records); b++){
- if (calc.verifyRowValues(rows[b]) != 0){
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- reads++;
- r++;
- }
- }
- }
-
- closeTransaction(pNdb);
-
- if (timer_active) {
- NdbTick_getMicroTimer(&timer_stop);
- NDB_TICKS ticks = NdbTick_getMicrosPassed(timer_start, timer_stop);
- m_stats_latency->addObservation((double)ticks);
- }
- }
- deallocRows();
- g_info << reads << " records read" << endl;
- return NDBT_OK;
-}
-
-
-
-int
-HugoTransactions::pkUpdateRecords(Ndb* pNdb,
- int records,
- int batch,
- int doSleep){
- int updated = 0;
- int r = 0;
- int retryAttempt = 0;
- int check, b;
-
- allocRows(batch);
-
- g_info << "|- Updating records (batch=" << batch << ")..." << endl;
- int batch_no = 0;
- while (r < records){
- if(r + batch > records)
- batch = records - r;
-
- if (m_thr_count != 0 && m_thr_no != batch_no % m_thr_count)
- {
- r += batch;
- batch_no++;
- continue;
- }
-
- if (retryAttempt >= m_retryMax){
- g_info << "ERROR: has retried this operation " << retryAttempt
- << " times, failing!" << endl;
- return NDBT_FAILED;
- }
-
- if (doSleep > 0)
- NdbSleep_MilliSleep(doSleep);
-
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- const NdbError err = pNdb->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- return NDBT_FAILED;
- }
-
- if(pkReadRecord(pNdb, r, batch, NdbOperation::LM_Exclusive) != NDBT_OK)
- {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- check = pTrans->execute(NoCommit, AbortOnError);
- if( check == -1 ) {
- const NdbError err = pTrans->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- MicroSecondTimer timer_start;
- MicroSecondTimer timer_stop;
- bool timer_active =
- m_stats_latency != 0 &&
- r >= batch && // first batch is "warmup"
- r + batch != records; // last batch is usually partial
-
- if (timer_active)
- NdbTick_getMicroTimer(&timer_start);
-
- if(pIndexScanOp)
- {
- int rows_found = 0;
- while((check = pIndexScanOp->nextResult(true)) == 0)
- {
- do {
-
- if (calc.verifyRowValues(rows[0]) != 0){
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- int updates = calc.getUpdatesValue(rows[0]) + 1;
-
- if(pkUpdateRecord(pNdb, r+rows_found, 1, updates) != NDBT_OK)
- {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- rows_found++;
- } while((check = pIndexScanOp->nextResult(false)) == 0);
-
- if(check != 2)
- break;
- if((check = pTrans->execute(NoCommit, AbortOnError)) != 0)
- break;
- }
- if(check != 1 || rows_found != batch)
- {
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- }
- else
- {
- for(b = 0; b<batch && (b+r)<records; b++)
- {
- if (calc.verifyRowValues(rows[b]) != 0)
- {
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- int updates = calc.getUpdatesValue(rows[b]) + 1;
-
- if(pkUpdateRecord(pNdb, r+b, 1, updates) != NDBT_OK)
- {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- }
- check = pTrans->execute(Commit, AbortOnError);
- }
- if( check == -1 ) {
- const NdbError err = pTrans->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- ndbout << "r = " << r << endl;
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- else{
- updated += batch;
- m_latest_gci = pTrans->getGCI();
- }
-
- closeTransaction(pNdb);
-
- if (timer_active) {
- NdbTick_getMicroTimer(&timer_stop);
- NDB_TICKS ticks = NdbTick_getMicrosPassed(timer_start, timer_stop);
- m_stats_latency->addObservation((double)ticks);
- }
-
- r += batch; // Read next record
- batch_no++;
- }
-
- deallocRows();
- g_info << "|- " << updated << " records updated" << endl;
- return NDBT_OK;
-}
-
-int
-HugoTransactions::pkInterpretedUpdateRecords(Ndb* pNdb,
- int records,
- int batch){
- int updated = 0;
- int r = 0;
- int retryAttempt = 0;
- int check, a;
-
- while (r < records){
-
- if (retryAttempt >= m_retryMax){
- g_info << "ERROR: has retried this operation " << retryAttempt
- << " times, failing!" << endl;
- return NDBT_FAILED;
- }
-
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- const NdbError err = pNdb->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- return NDBT_FAILED;
- }
-
- NdbOperation* pOp = pTrans->getNdbOperation(tab.getName());
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- check = pOp->readTupleExclusive();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- // Define primary keys
- if (equalForRow(pOp, r) != 0)
- {
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- // Read update value
- for(a = 0; a<tab.getNoOfColumns(); a++){
- if (calc.isUpdateCol(a) == true){
- if((row.attributeStore(a) =
- pOp->getValue(tab.getColumn(a)->getName())) == 0) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- }
- }
-
- check = pTrans->execute(NoCommit, AbortOnError);
- if( check == -1 ) {
- const NdbError err = pTrans->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- int updates = calc.getUpdatesValue(&row) + 1;
-
- NdbOperation* pUpdOp;
- pUpdOp = pTrans->getNdbOperation(tab.getName());
- if (pUpdOp == NULL) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- check = pUpdOp->interpretedUpdateTuple();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- // PKs
- if (equalForRow(pUpdOp, r) != 0)
- {
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- // Update col
- for(a = 0; a<tab.getNoOfColumns(); a++){
- if ((tab.getColumn(a)->getPrimaryKey() == false) &&
- (calc.isUpdateCol(a) == true)){
-
- // TODO switch for 32/64 bit
- const NdbDictionary::Column* attr = tab.getColumn(a);
- Uint32 valToIncWith = 1;
- check = pUpdOp->incValue(attr->getName(), valToIncWith);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- }
- }
-
- // Remaining attributes
- for(a = 0; a<tab.getNoOfColumns(); a++){
- if ((tab.getColumn(a)->getPrimaryKey() == false) &&
- (calc.isUpdateCol(a) == false)){
- if(setValueForAttr(pUpdOp, a, r, updates ) != 0){
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- }
- }
-
-
-
- check = pTrans->execute(Commit, AbortOnError);
- if( check == -1 ) {
- const NdbError err = pTrans->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- ndbout << "r = " << r << endl;
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- else{
- updated++;
- m_latest_gci = pTrans->getGCI();
- }
-
-
- closeTransaction(pNdb);
-
- r++; // Read next record
-
- }
-
- g_info << "|- " << updated << " records updated" << endl;
- return NDBT_OK;
-}
-
-int
-HugoTransactions::pkDelRecords(Ndb* pNdb,
- int records,
- int batch,
- bool allowConstraintViolation,
- int doSleep){
- // TODO Batch is not implemented
- int deleted = 0;
- int r = 0;
- int retryAttempt = 0;
- int check;
-
- g_info << "|- Deleting records..." << endl;
- int batch_no = 0;
- while (r < records){
- if(r + batch > records)
- batch = records - r;
-
- if (m_thr_count != 0 && m_thr_no != batch_no % m_thr_count)
- {
- r += batch;
- batch_no++;
- continue;
- }
-
- if (retryAttempt >= m_retryMax){
- g_info << "ERROR: has retried this operation " << retryAttempt
- << " times, failing!" << endl;
- return NDBT_FAILED;
- }
-
- if (doSleep > 0)
- NdbSleep_MilliSleep(doSleep);
-
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- const NdbError err = pNdb->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- return NDBT_FAILED;
- }
-
- MicroSecondTimer timer_start;
- MicroSecondTimer timer_stop;
- bool timer_active =
- m_stats_latency != 0 &&
- r >= batch && // first batch is "warmup"
- r + batch != records; // last batch is usually partial
-
- if (timer_active)
- NdbTick_getMicroTimer(&timer_start);
-
- if(pkDeleteRecord(pNdb, r, batch) != NDBT_OK)
- {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- check = pTrans->execute(Commit, AbortOnError);
- if( check == -1) {
- const NdbError err = pTrans->getNdbError();
-
- switch(err.status){
- case NdbError::TemporaryError:
- ERR(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- break;
-
- case NdbError::PermanentError:
- if (allowConstraintViolation == true){
- switch (err.classification){
- case NdbError::ConstraintViolation:
- // Tuple did not exist, OK but should be reported
- g_info << r << ": " << err.code << " " << err.message << endl;
- continue;
- break;
- default:
- break;
- }
- }
- ERR(err);
- closeTransaction(pNdb);
- return NDBT_FAILED;
- break;
-
- default:
- ERR(err);
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- }
- else {
- deleted += batch;
- m_latest_gci = pTrans->getGCI();
- }
- closeTransaction(pNdb);
-
- if (timer_active) {
- NdbTick_getMicroTimer(&timer_stop);
- NDB_TICKS ticks = NdbTick_getMicrosPassed(timer_start, timer_stop);
- m_stats_latency->addObservation((double)ticks);
- }
-
- r += batch; // Read next record
- batch_no++;
- }
-
- g_info << "|- " << deleted << " records deleted" << endl;
- return NDBT_OK;
-}
-
-
-int
-HugoTransactions::lockRecords(Ndb* pNdb,
- int records,
- int percentToLock,
- int lockTime){
- // Place a lock on percentToLock% of the records in the Db
- // Keep the locks for lockTime ms, commit operation
- // and lock som other records
- int r = 0;
- int retryAttempt = 0;
- int check;
- NdbOperation::LockMode lm = NdbOperation::LM_Exclusive;
-
- // Calculate how many records to lock in each batch
- if (percentToLock <= 0)
- percentToLock = 1;
- double percentVal = (double)percentToLock / 100;
- int lockBatch = (int)(records * percentVal);
- if (lockBatch <= 0)
- lockBatch = 1;
-
- allocRows(lockBatch);
-
- while (r < records){
- if(r + lockBatch > records)
- lockBatch = records - r;
-
- g_info << "|- Locking " << lockBatch << " records..." << endl;
-
- if (retryAttempt >= m_retryMax){
- g_info << "ERROR: has retried this operation " << retryAttempt
- << " times, failing!" << endl;
- return NDBT_FAILED;
- }
-
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- const NdbError err = pNdb->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- return NDBT_FAILED;
- }
-
- if(pkReadRecord(pNdb, r, lockBatch, lm) != NDBT_OK)
- {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- // NoCommit lockTime times with 100 millis interval
- int sleepInterval = 50;
- int lockCount = lockTime / sleepInterval;
- int commitCount = 0;
- do {
- check = pTrans->execute(NoCommit, AbortOnError);
- if( check == -1) {
- const NdbError err = pTrans->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- for (int b=0; (b<lockBatch) && (r+b<records); b++){
- if (calc.verifyRowValues(rows[b]) != 0){
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- }
- commitCount++;
- NdbSleep_MilliSleep(sleepInterval);
- } while (commitCount < lockCount);
-
- // Really commit the trans, puuh!
- check = pTrans->execute(Commit, AbortOnError);
- if( check == -1) {
- const NdbError err = pTrans->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- else{
- for (int b=0; (b<lockBatch) && (r<records); b++){
- if (calc.verifyRowValues(rows[b]) != 0){
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- r++; // Read next record
- }
- }
-
- closeTransaction(pNdb);
-
- }
- deallocRows();
- g_info << "|- Record locking completed" << endl;
- return NDBT_OK;
-}
-
-int
-HugoTransactions::indexReadRecords(Ndb* pNdb,
- const char * idxName,
- int records,
- int batch){
- int reads = 0;
- int r = 0;
- int retryAttempt = 0;
- int check, a;
- NdbOperation *pOp;
- NdbIndexScanOperation *sOp;
-
- const NdbDictionary::Index* pIndex
- = pNdb->getDictionary()->getIndex(idxName, tab.getName());
-
- const bool ordered = (pIndex->getType()==NdbDictionary::Index::OrderedIndex);
-
- if (batch == 0) {
- g_info << "ERROR: Argument batch == 0 in indexReadRecords(). "
- << "Not allowed." << endl;
- return NDBT_FAILED;
- }
-
- if (ordered) {
- batch = 1;
- }
-
- allocRows(batch);
-
- while (r < records){
- if (retryAttempt >= m_retryMax){
- g_info << "ERROR: has retried this operation " << retryAttempt
- << " times, failing!" << endl;
- return NDBT_FAILED;
- }
-
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- const NdbError err = pNdb->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- return NDBT_FAILED;
- }
-
- for(int b=0; (b<batch) && (r+b < records); b++){
- if(!ordered){
- pOp = pTrans->getNdbIndexOperation(idxName, tab.getName());
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- check = pOp->readTuple();
- } else {
- pOp = sOp = pTrans->getNdbIndexScanOperation(idxName, tab.getName());
- if (sOp == NULL) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- check = sOp->readTuples();
- }
-
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- // Define primary keys
- if (equalForRow(pOp, r+b) != 0)
- {
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- // Define attributes to read
- for(a = 0; a<tab.getNoOfColumns(); a++){
- if((rows[b]->attributeStore(a) =
- pOp->getValue(tab.getColumn(a)->getName())) == 0) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- }
- }
-
- check = pTrans->execute(Commit, AbortOnError);
- check = (check == -1 ? -1 : !ordered ? check : sOp->nextResult(true));
- if( check == -1 ) {
- const NdbError err = pTrans->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- switch(err.code){
- case 626: // Tuple did not exist
- g_info << r << ": " << err.code << " " << err.message << endl;
- r++;
- break;
-
- default:
- ERR(err);
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- } else{
- for (int b=0; (b<batch) && (r+b<records); b++){
- if (calc.verifyRowValues(rows[b]) != 0){
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- reads++;
- r++;
- }
- if(ordered && sOp->nextResult(true) == 0){
- ndbout << "Error when comparing records "
- << " - index op next_result to many" << endl;
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- }
- closeTransaction(pNdb);
- }
- deallocRows();
- g_info << reads << " records read" << endl;
- return NDBT_OK;
-}
-
-
-
-int
-HugoTransactions::indexUpdateRecords(Ndb* pNdb,
- const char * idxName,
- int records,
- int batch){
-
- int updated = 0;
- int r = 0;
- int retryAttempt = 0;
- int check, a, b;
- NdbOperation *pOp;
- NdbScanOperation * sOp;
-
- const NdbDictionary::Index* pIndex
- = pNdb->getDictionary()->getIndex(idxName, tab.getName());
-
- const bool ordered = (pIndex->getType()==NdbDictionary::Index::OrderedIndex);
- if (ordered){
- batch = 1;
- }
-
- allocRows(batch);
-
- while (r < records){
- if (retryAttempt >= m_retryMax){
- g_info << "ERROR: has retried this operation " << retryAttempt
- << " times, failing!" << endl;
- return NDBT_FAILED;
- }
-
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- const NdbError err = pNdb->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- return NDBT_FAILED;
- }
-
- for(b = 0; b<batch && (b+r)<records; b++){
- if(!ordered){
- pOp = pTrans->getNdbIndexOperation(idxName, tab.getName());
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- check = pOp->readTupleExclusive();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- } else {
- pOp = sOp = pTrans->getNdbIndexScanOperation(idxName, tab.getName());
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- check = 0;
- sOp->readTuplesExclusive();
- }
-
- // Define primary keys
- if (equalForRow(pOp, r+b) != 0)
- {
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- // Define attributes to read
- for(a = 0; a<tab.getNoOfColumns(); a++){
- if((rows[b]->attributeStore(a) =
- pOp->getValue(tab.getColumn(a)->getName())) == 0) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- }
- }
-
- check = pTrans->execute(NoCommit, AbortOnError);
- check = (check == -1 ? -1 : !ordered ? check : sOp->nextResult(true));
- if( check == -1 ) {
- const NdbError err = pTrans->getNdbError();
- ERR(err);
- closeTransaction(pNdb);
-
- if (err.status == NdbError::TemporaryError){
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- return NDBT_FAILED;
- }
-
- if(ordered && check != 0){
- g_err << check << " - Row: " << r << " not found!!" << endl;
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- for(b = 0; b<batch && (b+r)<records; b++){
- if (calc.verifyRowValues(rows[b]) != 0){
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- int updates = calc.getUpdatesValue(rows[b]) + 1;
-
- NdbOperation* pUpdOp;
- if(!ordered){
- pUpdOp = pTrans->getNdbIndexOperation(idxName, tab.getName());
- check = (pUpdOp == 0 ? -1 : pUpdOp->updateTuple());
- } else {
- pUpdOp = sOp->updateCurrentTuple();
- }
-
- if (pUpdOp == NULL) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- if(!ordered)
- {
- if (equalForRow(pUpdOp, r+b) != 0)
- {
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- }
-
- for(a = 0; a<tab.getNoOfColumns(); a++){
- if (tab.getColumn(a)->getPrimaryKey() == false){
- if(setValueForAttr(pUpdOp, a, r+b, updates ) != 0){
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- }
- }
- }
-
- check = pTrans->execute(Commit, AbortOnError);
- if( check == -1 ) {
- const NdbError err = pTrans->getNdbError();
- ERR(err);
- closeTransaction(pNdb);
-
- if (err.status == NdbError::TemporaryError){
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ndbout << "r = " << r << endl;
- return NDBT_FAILED;
- } else {
- updated += batch;
- m_latest_gci = pTrans->getGCI();
- }
-
- closeTransaction(pNdb);
-
- r+= batch; // Read next record
- }
-
- g_info << "|- " << updated << " records updated" << endl;
- return NDBT_OK;
-}
-
-template class Vector<NDBT_ResultRow*>;
diff --git a/storage/ndb/test/src/Makefile.am b/storage/ndb/test/src/Makefile.am
deleted file mode 100644
index 8fdfa0df669..00000000000
--- a/storage/ndb/test/src/Makefile.am
+++ /dev/null
@@ -1,47 +0,0 @@
-# Copyright (C) 2004 MySQL AB
-# Use is subject to license terms
-#
-# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-noinst_LIBRARIES = libNDBT.a
-
-libNDBT_a_SOURCES = \
- NDBT_ReturnCodes.cpp \
- NDBT_Error.cpp NDBT_Tables.cpp NDBT_ResultRow.cpp \
- NDBT_Test.cpp HugoCalculator.cpp \
- HugoOperations.cpp HugoTransactions.cpp \
- HugoAsynchTransactions.cpp UtilTransactions.cpp \
- NdbRestarter.cpp NdbRestarts.cpp NDBT_Output.cpp \
- NdbBackup.cpp NdbConfig.cpp NdbGrep.cpp NDBT_Table.cpp \
- NdbSchemaCon.cpp NdbSchemaOp.cpp getarg.c AtrtClient.cpp \
- CpcClient.cpp NdbMixRestarter.cpp NDBT_Thread.cpp DbUtil.cpp
-
-INCLUDES_LOC = -I$(top_srcdir)/storage/ndb/src/common/mgmcommon -I$(top_srcdir)/storage/ndb/include/mgmcommon -I$(top_srcdir)/storage/ndb/include/kernel -I$(top_srcdir)/storage/ndb/src/mgmapi -I$(top_srcdir)/include
-
-include $(top_srcdir)/storage/ndb/config/common.mk.am
-include $(top_srcdir)/storage/ndb/config/type_ndbapitest.mk.am
-
-windoze-dsp: libNDBT.dsp
-
-libNDBT.dsp: Makefile \
- $(top_srcdir)/storage/ndb/config/win-lib.am \
- $(top_srcdir)/storage/ndb/config/win-name \
- $(top_srcdir)/storage/ndb/config/win-includes \
- $(top_srcdir)/storage/ndb/config/win-sources \
- $(top_srcdir)/storage/ndb/config/win-libraries
- cat $(top_srcdir)/storage/ndb/config/win-lib.am > $@
- @$(top_srcdir)/storage/ndb/config/win-name $@ $(noinst_LIBRARIES)
- @$(top_srcdir)/storage/ndb/config/win-includes $@ $(INCLUDES)
- @$(top_srcdir)/storage/ndb/config/win-sources $@ $(libNDBT_a_SOURCES)
- @$(top_srcdir)/storage/ndb/config/win-libraries $@ LIB
diff --git a/storage/ndb/test/src/NDBT_Error.cpp b/storage/ndb/test/src/NDBT_Error.cpp
deleted file mode 100644
index 99391274451..00000000000
--- a/storage/ndb/test/src/NDBT_Error.cpp
+++ /dev/null
@@ -1,283 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-/* NDBT_Error.cpp */
-/* This program deals with error handling */
-
-#include <ndb_global.h>
-#include <NdbMain.h>
-#include <NdbOut.hpp>
-#include <NdbTest.hpp>
-#include <NDBT_Error.hpp>
-#include <NdbSleep.h>
-
-
-ErrorData::ErrorData()
-{
- errorCountArray = new Uint32[6000];
- resetErrorCounters();
-
- key_error = false;
- temporary_resource_error = true;
- insufficient_space_error = false;
- node_recovery_error = true;
- overload_error = true;
- timeout_error = true;
- internal_error = true;
- user_error = true;
- application_error = false;
-}
-
-ErrorData::~ErrorData()
-{
- delete [] errorCountArray;
-}
-
-
-//-------------------------------------------------------------------
-// Error Handling routines
-//-------------------------------------------------------------------
-
-int ErrorData::handleErrorCommon(const NdbError & error)
-{
- int retValue = 1;
- if (error.code > 6000) {
- if (user_error == true) {
- retValue = 0;
- }//if
- return retValue;
- }//if
- errorCountArray[error.code]++;
- switch(error.classification){
- case NdbError::NoDataFound:
- case NdbError::ConstraintViolation:
- if (key_error == true) {
- retValue = 0;
- }//if
- break;
- case NdbError::TemporaryResourceError:
- if (temporary_resource_error == true) {
- retValue = 0;
- }//if
- break;
- case NdbError::InsufficientSpace:
- if (insufficient_space_error == true) {
- retValue = 0;
- }//if
- break;
- case NdbError::NodeRecoveryError:
- if (node_recovery_error == true) {
- retValue = 0;
- }//if
- break;
-
- case NdbError::UnknownResultError:
- if(error.code == 4012){
- retValue = 0;
- }
- if(error.code == 4115){
- retValue = 2;
- }
- if(error.code == 4007 && node_recovery_error == true){
- retValue = 3;
- }
- break;
- case NdbError::OverloadError:
- if (overload_error == true) {
- NdbSleep_MilliSleep(50);
- retValue = 0;
- }//if
- break;
- case NdbError::TimeoutExpired:
- if (timeout_error == true) {
- retValue = 0;
- }//if
- break;
- case NdbError::InternalError:
- if (internal_error == true) {
- retValue = 0;
- }//if
- break;
- case NdbError::ApplicationError:
- if (application_error == true) {
- retValue = 0;
- }//if
- break;
- case NdbError::UserDefinedError:
- if (user_error == true) {
- retValue = 0;
- }//if
- break;
- default:
- break;
- }//switch
- if(error.status == NdbError::TemporaryError)
- retValue = 0;
-
- return retValue;
-}//handleErrorCommon()
-
-
-void ErrorData::printErrorCounters(NdbOut & out) const
-{
- int localLoop;
- for (localLoop = 0; localLoop < 6000; localLoop++) {
- int errCount = (int)errorCountArray[localLoop];
- if (errCount > 0) {
- out << "NDBT: ErrorCode = " << localLoop << " occurred ";
- out << errCount << " times" << endl;
- }//if
- }//for
-}//printErrorCounters()
-
-
-void ErrorData::printSettings(NdbOut & out)
-{
- out << "Key Errors are ";
- if (key_error == false) {
- out << "disallowed" << endl;
- } else {
- out << "allowed" << endl;
- }//if
- out << "Temporary Resource Errors are ";
- if (temporary_resource_error == false) {
- out << "disallowed" << endl;
- } else {
- out << "allowed" << endl;
- }//if
- if (internal_error == true) {
- out << "Insufficient Space Errors are ";
- }
- if (insufficient_space_error == false) {
- out << "disallowed" << endl;
- } else {
- out << "allowed" << endl;
- }//if
- out << "Node Recovery Errors are ";
- if (node_recovery_error == false) {
- out << "disallowed" << endl;
- } else {
- out << "allowed" << endl;
- }//if
- out << "Overload Errors are ";
- if (overload_error == false) {
- out << "disallowed" << endl;
- } else {
- out << "allowed" << endl;
- }//if
- out << "Timeout Errors are ";
- if (timeout_error == false) {
- out << "disallowed" << endl;
- } else {
- out << "allowed" << endl;
- }//if
- out << "Internal NDB Errors are ";
- if (internal_error == false) {
- out << "disallowed" << endl;
- } else {
- out << "allowed" << endl;
- }//if
- out << "User logic reported Errors are ";
- if (user_error == false) {
- out << "disallowed" << endl;
- } else {
- out << "allowed" << endl;
- }//if
- out << "Application Errors are ";
- if (application_error == false) {
- out << "disallowed" << endl;
- } else {
- out << "allowed" << endl;
- }//if
-}//printSettings
-
-
-void ErrorData::printCmdLineArgs(NdbOut & out)
-{
- out << " -key_err Allow key errors" << endl;
- out << " -no_key_err Disallow key errors (default)" << endl;
- out << " -temp_res_err Allow temporary resource errors (default)";
- out << endl;
- out << " -no_temp_res_err Disallow temporary resource errors" << endl;
- out << " -ins_space_err Allow insufficient space errors" << endl;
- out << " -no_ins_space_err Disallow insufficient space errors (default)";
- out << endl;
- out << " -noderec_err Allow Node Recovery errors (default)" << endl;
- out << " -no_noderec_err Disallow Node Recovery errors" << endl;
- out << " -overload_err Allow Overload errors (default)" << endl;
- out << " -no_overload_err Disallow Overload errors" << endl;
- out << " -timeout_err Allow Time-out errors (default)" << endl;
- out << " -no_timeout_err Disallow Time-out errors" << endl;
- out << " -internal_err Allow Internal NDB errors" << endl;
- out << " -no_internal_err Disallow Internal NDB errors (default)";
- out << " -user_err Allow user logic reported errors (default)";
- out << endl;
- out << " -no_user_err Disallow user logic reported errors";
- out << endl;
-
-}//printCmdLineArgs()
-
-
-bool ErrorData::parseCmdLineArg(const char** argv, int & i)
-{
- bool ret_Value = true;
- if (strcmp(argv[i], "-key_err") == 0){
- key_error = true;
- } else if (strcmp(argv[i], "-no_key_err") == 0){
- key_error = false;
- } else if (strcmp(argv[i], "-temp_res_err") == 0){
- temporary_resource_error = true;
- } else if (strcmp(argv[i], "-no_temp_res_err") == 0){
- temporary_resource_error = false;
- } else if (strcmp(argv[i], "-ins_space_err") == 0){
- insufficient_space_error = true;
- } else if (strcmp(argv[i], "-no_ins_space_err") == 0){
- insufficient_space_error = false;
- } else if (strcmp(argv[i], "-noderec_err") == 0){
- node_recovery_error = true;
- } else if (strcmp(argv[i], "-no_noderec_err") == 0){
- node_recovery_error = false;
- } else if (strcmp(argv[i], "-overload_err") == 0){
- overload_error = true;
- } else if (strcmp(argv[i], "-no_overload_err") == 0){
- overload_error = false;
- } else if (strcmp(argv[i], "-timeout_err") == 0){
- timeout_error = true;
- } else if (strcmp(argv[i], "-no_timeout_err") == 0){
- timeout_error = false;
- } else if (strcmp(argv[i], "-internal_err") == 0){
- internal_error = true;
- } else if (strcmp(argv[i], "-no_internal_err") == 0){
- internal_error = false;
- } else if (strcmp(argv[i], "-user_err") == 0){
- user_error = true;
- } else if (strcmp(argv[i], "-no_user_err") == 0){
- user_error = false;
- } else {
- ret_Value = false;
- }//if
- return ret_Value;
-}//bool parseCmdline
-
-void ErrorData::resetErrorCounters()
-{
- for (int i = 0; i < 6000; i++){
- errorCountArray[i] = 0 ;
- }
-}
-
-
-
diff --git a/storage/ndb/test/src/NDBT_Output.cpp b/storage/ndb/test/src/NDBT_Output.cpp
deleted file mode 100644
index cffdd177b4a..00000000000
--- a/storage/ndb/test/src/NDBT_Output.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-/* Copyright (c) 2003, 2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-#include "NDBT_Output.hpp"
-
-FileOutputStream gerr_fileoutputstream(stderr);
-FileOutputStream gwarning_fileoutputstream(stderr);
-FileOutputStream ginfo_fileoutputstream(stdout);
-FileOutputStream gdebug_fileoutputstream(stdout);
-
-FilteredNdbOut g_err(gerr_fileoutputstream, 0, 2);
-FilteredNdbOut g_warning(gwarning_fileoutputstream, 1, 2);
-FilteredNdbOut g_info(ginfo_fileoutputstream, 2, 2);
-FilteredNdbOut g_debug(gdebug_fileoutputstream, 3, 2);
-
-void
-setOutputLevel(int i){
- g_err.setLevel(i);
- g_warning.setLevel(i);
- g_info.setLevel(i);
- g_debug.setLevel(i);
-}
diff --git a/storage/ndb/test/src/NDBT_ResultRow.cpp b/storage/ndb/test/src/NDBT_ResultRow.cpp
deleted file mode 100644
index a4f71f869f2..00000000000
--- a/storage/ndb/test/src/NDBT_ResultRow.cpp
+++ /dev/null
@@ -1,156 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-#include "NDBT_ResultRow.hpp"
-#include <NdbOut.hpp>
-#include <NdbSchemaCon.hpp>
-
-NDBT_ResultRow::NDBT_ResultRow(const NdbDictionary::Table& tab,
- char attrib_delimiter)
- : m_table(tab)
-{
- assert(tab.getObjectStatus() == NdbDictionary::Object::Retrieved);
-
- cols = tab.getNoOfColumns();
- names = new char * [cols];
- data = new NdbRecAttr * [cols];
-
- for(int i = 0; i<cols; i++){
- names[i] = new char[255];
- strcpy(names[i], tab.getColumn(i)->getName());
- }
-
- ad[0] = attrib_delimiter;
- ad[1] = 0;
- m_ownData = false;
-}
-
-NDBT_ResultRow::~NDBT_ResultRow(){
- for(int i = 0; i<cols; i++){
- delete [] names[i];
- }
- delete [] names;
-
- if(m_ownData){
- for(int i = 0; i<cols; i++)
- delete data[i];
- }
- delete [] data;
-}
-
-NdbRecAttr* &
-NDBT_ResultRow::attributeStore(int i){
-
- return data[i];
-}
-
-const NdbRecAttr*
-NDBT_ResultRow::attributeStore(int i) const {
- return data[i];
-}
-
-const
-NdbRecAttr *
-NDBT_ResultRow::attributeStore(const char* name) const {
- for(int i = 0; i<cols; i++){
- if (strcmp(names[i], name) == 0)
- return data[i];
- }
- assert(false);
- return 0;
-}
-
-NdbOut &
-NDBT_ResultRow::header (NdbOut & out) const {
- for(int i = 0; i<cols; i++){
- out << names[i];
- if (i < cols-1)
- out << ad;
- }
- return out;
-}
-
-BaseString NDBT_ResultRow::c_str() const {
-
- BaseString str;
-
- char buf[10];
- for(int i = 0; i<cols; i++){
- if(data[i]->isNULL()){
- sprintf(buf, "NULL");
- str.append(buf);
- }else{
- Uint32* p = (Uint32*)data[i]->aRef();
- Uint32 sizeInBytes = data[i]->get_size_in_bytes();
- for (Uint32 j = 0; j < sizeInBytes; j+=(sizeof(Uint32))){
- str.append("H'");
- if (j + 4 < sizeInBytes)
- {
- sprintf(buf, "%.8x", *p);
- }
- else
- {
- Uint32 tmp = 0;
- memcpy(&tmp, p, sizeInBytes - j);
- sprintf(buf, "%.8x", tmp);
- }
- p++;
- str.append(buf);
- if ((j + sizeof(Uint32)) < sizeInBytes)
- str.append(", ");
- }
- }
- str.append("\n");
- }
- str.append("*");
-
- //ndbout << "NDBT_ResultRow::c_str() = " << str.c_str() << endl;
-
- return str;
-}
-
-NdbOut &
-operator << (NdbOut& ndbout, const NDBT_ResultRow & res)
-{
- if (res.cols != 0)
- {
- ndbout << *(res.data[0]);
- for(int i = 1; i<res.cols; i++)
- ndbout << res.ad << *(res.data[i]);
- }
- return ndbout;
-}
-
-NDBT_ResultRow *
-NDBT_ResultRow::clone () const {
-
- NDBT_ResultRow * row = new NDBT_ResultRow(m_table, ad[0]);
- row->m_ownData = true;
- Uint32 noOfColumns = m_table.getNoOfColumns();
- for(Uint32 i = 0; i < noOfColumns; i++){
- row->data[i] = data[i]->clone();
- }
-
- return row;
-}
-
-bool
-NDBT_ResultRow::operator==(const NDBT_ResultRow& other) const
-{
- // quick and dirty
- return c_str() == other.c_str();
-}
diff --git a/storage/ndb/test/src/NDBT_ReturnCodes.cpp b/storage/ndb/test/src/NDBT_ReturnCodes.cpp
deleted file mode 100644
index 4017dc5ca59..00000000000
--- a/storage/ndb/test/src/NDBT_ReturnCodes.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-/* System include files */
-#include <ndb_global.h>
-
-#include "NDBT_ReturnCodes.h"
-
-/* Ndb include files */
-#include <NdbOut.hpp>
-
-const char* rcodeToChar(int rcode){
- switch (rcode){
- case NDBT_OK:
- return "OK";
- break;
- case NDBT_FAILED:
- return "Failed";
- break;
- case NDBT_WRONGARGS:
- return "Wrong arguments";
- break;
- case NDBT_TEMPORARY:
- return "Temporary error";
- break;
-
- default:
- return "Unknown";
- break;
- }
-}
-
-int NDBT_ProgramExit(int rcode){
- ndbout_c("\nNDBT_ProgramExit: %d - %s\n", rcode, rcodeToChar(rcode));
- // exit(rcode);
- return rcode;
-}
diff --git a/storage/ndb/test/src/NDBT_Table.cpp b/storage/ndb/test/src/NDBT_Table.cpp
deleted file mode 100644
index bc6261cd915..00000000000
--- a/storage/ndb/test/src/NDBT_Table.cpp
+++ /dev/null
@@ -1,92 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT_Table.hpp>
-#include <NdbTimer.hpp>
-#include <NDBT.hpp>
-
-class NdbOut&
-operator <<(class NdbOut& ndbout, const NDBT_Table & tab)
-{
- ndbout << "-- " << tab.getName() << " --" << endl;
-
- ndbout << "Version: " << tab.getObjectVersion() << endl;
- ndbout << "Fragment type: " << (unsigned) tab.getFragmentType() << endl;
- ndbout << "K Value: " << tab.getKValue()<< endl;
- ndbout << "Min load factor: " << tab.getMinLoadFactor()<< endl;
- ndbout << "Max load factor: " << tab.getMaxLoadFactor()<< endl;
- ndbout << "Temporary table: " << (tab.getStoredTable() ? "no" : "yes") << endl;
- ndbout << "Number of attributes: " << tab.getNoOfColumns() << endl;
- ndbout << "Number of primary keys: " << tab.getNoOfPrimaryKeys() << endl;
- ndbout << "Length of frm data: " << tab.getFrmLength() << endl;
- ndbout << "Row Checksum: " << tab.getRowChecksumIndicator() << endl;
- ndbout << "Row GCI: " << tab.getRowGCIIndicator() << endl;
- ndbout << "SingleUserMode: " << (Uint32) tab.getSingleUserMode() << endl;
- ndbout << "ForceVarPart: " << tab.getForceVarPart() << endl;
-
- //<< ((tab.getTupleKey() == TupleId) ? " tupleid" : "") <<endl;
- ndbout << "TableStatus: ";
- switch(tab.getObjectStatus()){
- case NdbDictionary::Object::New:
- ndbout << "New" << endl;
- break;
- case NdbDictionary::Object::Changed:
- ndbout << "Changed" << endl;
- break;
- case NdbDictionary::Object::Retrieved:
- ndbout << "Retrieved" << endl;
- break;
- default:
- ndbout << "Unknown(" << (unsigned) tab.getObjectStatus() << ")" << endl;
- }
-
- ndbout << "-- Attributes -- " << endl;
- int noOfAttributes = tab.getNoOfColumns();
- for(int i = 0; i<noOfAttributes; i++){
- ndbout << (* (const NDBT_Attribute*)tab.getColumn(i)) << endl;
- }
-
- return ndbout;
-}
-
-class NdbOut& operator <<(class NdbOut&, const NdbDictionary::Index & idx)
-{
- ndbout << idx.getName();
- ndbout << "(";
- for (unsigned i=0; i < idx.getNoOfColumns(); i++)
- {
- const NdbDictionary::Column *col = idx.getColumn(i);
- ndbout << col->getName();
- if (i < idx.getNoOfColumns()-1)
- ndbout << ", ";
- }
- ndbout << ")";
-
- ndbout << " - ";
- switch (idx.getType()) {
- case NdbDictionary::Object::UniqueHashIndex:
- ndbout << "UniqueHashIndex";
- break;
- case NdbDictionary::Object::OrderedIndex:
- ndbout << "OrderedIndex";
- break;
- default:
- ndbout << "Type " << (unsigned) idx.getType();
- break;
- }
- return ndbout;
-}
-
diff --git a/storage/ndb/test/src/NDBT_Tables.cpp b/storage/ndb/test/src/NDBT_Tables.cpp
deleted file mode 100644
index 2aaf6a778df..00000000000
--- a/storage/ndb/test/src/NDBT_Tables.cpp
+++ /dev/null
@@ -1,1116 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NDBT.hpp>
-#include <NDBT_Table.hpp>
-#include <NDBT_Tables.hpp>
-
-/* ******************************************************* */
-// Define Ndb standard tables
-//
-// USE ONLY UPPERLETTERS IN TAB AND COLUMN NAMES
-/* ******************************************************* */
-
-/*
- * These are our "official" test tables
- *
- */
-/* T1 */
-static
-const
-NDBT_Attribute T1Attribs[] = {
- NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned),
-};
-static
-const
-NDBT_Table T1("T1", sizeof(T1Attribs)/sizeof(NDBT_Attribute), T1Attribs);
-
-/* T2 */
-static
-const
-NDBT_Attribute T2Attribs[] = {
- NDBT_Attribute("KOL1", NdbDictionary::Column::Bigunsigned, 1, true),
- NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL3", NdbDictionary::Column::Bit, 23),
- NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned,
- 1, false, true), // Nullable
- NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned)
-};
-static
-const
-NDBT_Table T2("T2", sizeof(T2Attribs)/sizeof(NDBT_Attribute), T2Attribs);
-
-/* T3 */
-static
-const
-NDBT_Attribute T3Attribs[] = {
- NDBT_Attribute("ID", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("PERSNR", NdbDictionary::Column::Char, 10),
- NDBT_Attribute("NAME", NdbDictionary::Column::Char, 25),
- NDBT_Attribute("ADRESS", NdbDictionary::Column::Char, 50),
- NDBT_Attribute("ADRESS2", NdbDictionary::Column::Char,
- 30, false, true), // Nullable
- NDBT_Attribute("FÖDELSEÅR", NdbDictionary::Column::Unsigned)
-};
-static
-const
-NDBT_Table T3("T3", sizeof(T3Attribs)/sizeof(NDBT_Attribute), T3Attribs);
-
-/* T4 */
-static
-const
-NDBT_Attribute T4Attribs[] = {
- NDBT_Attribute("REGNR", NdbDictionary::Column::Char, 6, true),
- NDBT_Attribute("YEAR", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("OWNER", NdbDictionary::Column::Char, 25),
- NDBT_Attribute("ADRESS", NdbDictionary::Column::Char, 50),
- NDBT_Attribute("ADRESS2", NdbDictionary::Column::Char,
- 30, false, true), // Nullable
- NDBT_Attribute("OWNERID", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("CHECKDATE", NdbDictionary::Column::Unsigned)
-};
-static
-const
-NDBT_Table T4("T4", sizeof(T4Attribs)/sizeof(NDBT_Attribute), T4Attribs);
-
-/* T5 */
-static
-const
-NDBT_Attribute T5Attribs[] = {
- NDBT_Attribute("OWNERID", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("REGNR", NdbDictionary::Column::Char, 6, true),
- NDBT_Attribute("CREATEDDATE", NdbDictionary::Column::Unsigned)
-};
-static
-const
-NDBT_Table T5("T5", sizeof(T5Attribs)/sizeof(NDBT_Attribute), T5Attribs);
-
-/* T6 */
-static
-const
-NDBT_Attribute T6Attribs[] = {
- NDBT_Attribute("PK1", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("ATTR1", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR2", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR3", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR4", NdbDictionary::Column::Char,
- 47, false, true),// Nullable
- NDBT_Attribute("ATTR5", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR6", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR7", NdbDictionary::Column::Char,
- 48, false, true),// Nullable
- NDBT_Attribute("ATTR8", NdbDictionary::Column::Char,
- 50, false, true), // Nullable
- NDBT_Attribute("ATTR9", NdbDictionary::Column::Int),
- NDBT_Attribute("ATTR10", NdbDictionary::Column::Float),
- NDBT_Attribute("ATTR11", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR12", NdbDictionary::Column::Char, 49),
- NDBT_Attribute("ATTR13", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR14", NdbDictionary::Column::Char, 50),
- NDBT_Attribute("ATTR15", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR16", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR17", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR18", NdbDictionary::Column::Char, 257),
- NDBT_Attribute("ATTR19", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR20", NdbDictionary::Column::Unsigned),
-};
-static
-const
-NDBT_Table T6("T6", sizeof(T6Attribs)/sizeof(NDBT_Attribute), T6Attribs);
-
-/* T7 */
-static
-const
-NDBT_Attribute T7Attribs[] = {
- NDBT_Attribute("PK1", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("PK2", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("PK3", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("PK4", NdbDictionary::Column::Varbinary, 123, true),
- NDBT_Attribute("ATTR1", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR2", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR3", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR4", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR5", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR6", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR7", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR8", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR9", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR10", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR11", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR12", NdbDictionary::Column::Char, 259),
- NDBT_Attribute("ATTR13", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR14", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR15", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR16", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR17", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR18", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR19", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ATTR20", NdbDictionary::Column::Unsigned),
-};
-static
-const
-NDBT_Table T7("T7", sizeof(T7Attribs)/sizeof(NDBT_Attribute), T7Attribs);
-
-/* T8 */
-static
-const
-NDBT_Attribute T8Attribs[] = {
- NDBT_Attribute("PERSON_ID", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("NAME", NdbDictionary::Column::Varbinary, 255),
- NDBT_Attribute("ADRESS", NdbDictionary::Column::Longvarbinary, 513),
- NDBT_Attribute("POSTADRESS", NdbDictionary::Column::Char, 1173),
- NDBT_Attribute("VALUE", NdbDictionary::Column::Unsigned),
-
-};
-static
-const
-NDBT_Table T8("T8", sizeof(T8Attribs)/sizeof(NDBT_Attribute), T8Attribs);
-
-/* T9 */
-static
-const
-NDBT_Attribute T9Attribs[] = {
- NDBT_Attribute("KF_SKAPAD", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("PLATS_ID", NdbDictionary::Column::Char, 2, true),
- NDBT_Attribute("TNR_SKAPAD", NdbDictionary::Column::Char, 12, true),
- NDBT_Attribute("DELG_MOT", NdbDictionary::Column::Char, 1, true),
- NDBT_Attribute("VALUE", NdbDictionary::Column::Unsigned),
-};
-static
-const
-NDBT_Table T9("T9", sizeof(T9Attribs)/sizeof(NDBT_Attribute), T9Attribs);
-
-/* T10 - Long key table */
-static
-const
-NDBT_Attribute T10Attribs[] = {
- NDBT_Attribute("KOL1", NdbDictionary::Column::Char, 256, true),
- NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL3", NdbDictionary::Column::Char, 257),
- NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned),
-};
-static
-const
-NDBT_Table T10("T10", sizeof(T10Attribs)/sizeof(NDBT_Attribute), T10Attribs);
-
-
-/* T11 - Primary key is not first attribute */
-static
-const
-NDBT_Attribute T11Attribs[] = {
- NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL4", NdbDictionary::Column::Char, 111),
- NDBT_Attribute("KOL5", NdbDictionary::Column::Char, 113)
-};
-
-static
-const
-NDBT_Table T11("T11", sizeof(T11Attribs)/sizeof(NDBT_Attribute), T11Attribs);
-
-/* T12 - 16 primary keys */
-static
-const
-NDBT_Attribute T12Attribs[] = {
- NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL6", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL7", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL8", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL9", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL10", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL11", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL12", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL13", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL14", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL15", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL16", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL20", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL30", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL40", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL50", NdbDictionary::Column::Unsigned)
-};
-
-static
-const
-NDBT_Table T12("T12", sizeof(T12Attribs)/sizeof(NDBT_Attribute), T12Attribs);
-
-/* T13 - Long key table */
-static
-const
-NDBT_Attribute T13Attribs[] = {
- NDBT_Attribute("KOL1", NdbDictionary::Column::Char, 257, true),
- NDBT_Attribute("KOL2", NdbDictionary::Column::Char, 259, true),
- NDBT_Attribute("KOL3", NdbDictionary::Column::Char, 113, true),
- NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL6", NdbDictionary::Column::Unsigned),
-};
-static
-const
-NDBT_Table T13("T13", sizeof(T13Attribs)/sizeof(NDBT_Attribute), T13Attribs);
-
-/* T14 - 5 primary keys */
-static
-const
-NDBT_Attribute T14Attribs[] = {
- NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL3", NdbDictionary::Column::Char, 4, true),
- NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL20", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL30", NdbDictionary::Column::Int),
- NDBT_Attribute("KOL40", NdbDictionary::Column::Float),
- NDBT_Attribute("KOL50", NdbDictionary::Column::Char, 200)
-};
-
-
-static
-const
-NDBT_Table T14("T14", sizeof(T14Attribs)/sizeof(NDBT_Attribute), T14Attribs);
-
-/*
- C2 DHCP TABLES, MAYBE THESE SHOULD BE MOVED TO THE UTIL_TABLES?
-*/
-static
-const
-NDBT_Attribute I1_Cols[] = {
- NDBT_Attribute("ID", NdbDictionary::Column::Unsigned, true),
- NDBT_Attribute("PORT", NdbDictionary::Column::Char, 16, true),
- NDBT_Attribute("ACCESSNODE", NdbDictionary::Column::Char, 16, true),
- NDBT_Attribute("POP", NdbDictionary::Column::Char, 64, true),
- NDBT_Attribute("VLAN", NdbDictionary::Column::Char, 16),
- NDBT_Attribute("COMMENT", NdbDictionary::Column::Char, 128),
- NDBT_Attribute("SNMPINDEX", NdbDictionary::Column::Int),
- NDBT_Attribute("PORTSTATE", NdbDictionary::Column::Int),
- NDBT_Attribute("UPDATES", NdbDictionary::Column::Unsigned)
-};
-
-static
-const
-char* I1_Indexes[] = {
- "UNIQUE", "ID", "PORT", "ACCESSNODE", "POP", "PORTSTATE", 0,
- 0
-};
-
-static
-NDBT_Table I1("I1", sizeof(I1_Cols)/sizeof(NDBT_Attribute), I1_Cols
- );// ,I1_Indexes);
-
-static
-const
-NDBT_Attribute I2_Cols[] = {
- NDBT_Attribute("ID", NdbDictionary::Column::Unsigned, true),
- NDBT_Attribute("PORT", NdbDictionary::Column::Char, 16, true),
- NDBT_Attribute("ACCESSNODE", NdbDictionary::Column::Char, 16, true),
- NDBT_Attribute("POP", NdbDictionary::Column::Char, 64, true),
- NDBT_Attribute("ACCESSTYPE", NdbDictionary::Column::Int, true),
- NDBT_Attribute("CUSTOMER_ID", NdbDictionary::Column::Int),
- NDBT_Attribute("PROVIDER", NdbDictionary::Column::Int),
- NDBT_Attribute("TEXPIRE", NdbDictionary::Column::Int),
- NDBT_Attribute("NUM_IP", NdbDictionary::Column::Int),
- NDBT_Attribute("LEASED_NUM_IP", NdbDictionary::Column::Int),
- NDBT_Attribute("LOCKED_IP", NdbDictionary::Column::Int),
- NDBT_Attribute("STATIC_DNS", NdbDictionary::Column::Int),
- NDBT_Attribute("SUSPENDED_SERVICES", NdbDictionary::Column::Int),
- NDBT_Attribute("UPDATES", NdbDictionary::Column::Unsigned)
-};
-
-const
-char* I2_Indexes[] = {
- "ORDERED", "CUSTOMER_ID", 0,
- "ORDERED", "NUM_IP", 0,
- 0
-};
-
-static
-NDBT_Table I2("I2", sizeof(I2_Cols)/sizeof(NDBT_Attribute), I2_Cols
- );//, I2_Indexes);
-
-static
-const
-NDBT_Attribute I3_Cols[] = {
- NDBT_Attribute("ID", NdbDictionary::Column::Unsigned, true),
- NDBT_Attribute("PORT", NdbDictionary::Column::Char, 16), // SI2
- NDBT_Attribute("ACCESSNODE", NdbDictionary::Column::Char, 16), // SI2
- NDBT_Attribute("POP", NdbDictionary::Column::Char, 64), // SI2
- NDBT_Attribute("MAC", NdbDictionary::Column::Char, 12, true),
- NDBT_Attribute("MAC_EXPIRE", NdbDictionary::Column::Int, 1),
- NDBT_Attribute("IIP", NdbDictionary::Column::Int), // SI1
- NDBT_Attribute("P_EXPIRE", NdbDictionary::Column::Int),
- NDBT_Attribute("HOSTNAME", NdbDictionary::Column::Char, 32),
- NDBT_Attribute("DETECTED", NdbDictionary::Column::Int),
- NDBT_Attribute("STATUS", NdbDictionary::Column::Int),
- NDBT_Attribute("NUM_REQUESTS", NdbDictionary::Column::Int),
- NDBT_Attribute("ACCESSTYPE", NdbDictionary::Column::Int),
- NDBT_Attribute("OS_TYPE", NdbDictionary::Column::Int),
- NDBT_Attribute("GW", NdbDictionary::Column::Int),
- NDBT_Attribute("UPDATES", NdbDictionary::Column::Unsigned)
-};
-
-const
-char* I3_Indexes[] = {
- "UNIQUE", "ID", 0,
- "ORDERED", "MAC", 0,
- "ORDERED", "GW", 0,
- 0
-};
-
-static
-NDBT_Table I3("I3", sizeof(I3_Cols)/sizeof(NDBT_Attribute), I3_Cols
- ); // ,I3_Indexes);
-
-/* D1 */
-static
-const
-NDBT_Attribute D1Attribs[] = {
- NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned, 1, false, false, 0, NdbDictionary::Column::StorageTypeDisk),
- NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL4", NdbDictionary::Column::Char, 233, false, true, 0, NdbDictionary::Column::StorageTypeDisk),
- NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned),
-};
-static
-const
-NDBT_Table D1("D1", sizeof(D1Attribs)/sizeof(NDBT_Attribute), D1Attribs);
-
-static
-const
-NDBT_Attribute D2Attribs[] = {
- NDBT_Attribute("KOL1", NdbDictionary::Column::Varbinary, 127, true),
- NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned, 1, false, false, 0, NdbDictionary::Column::StorageTypeDisk),
- NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL4", NdbDictionary::Column::Varbinary, 133),
- NDBT_Attribute("KOL5", NdbDictionary::Column::Char, 199, false, true, 0, NdbDictionary::Column::StorageTypeDisk),
- NDBT_Attribute("KOL6", NdbDictionary::Column::Bit, 21, false, false, 0, NdbDictionary::Column::StorageTypeDisk),
-};
-static
-const
-NDBT_Table D2("D2", sizeof(D2Attribs)/sizeof(NDBT_Attribute), D2Attribs);
-
-
-// Define array with pointer to all tables
-static
-const
-NDBT_Table *test_tables[]=
-{
- &T1,
- &T2,
- &T3,
- &T4,
- &T5,
- &T6,
- &T7,
- &T8,
- &T9,
- &T10,
- &T11,
- &T12,
- &T13,
- &T14,
- &I1,
- &I2,
- &I3,
- &D1, &D2
-};
-
-struct NDBT_IndexList {
- const char * m_table;
- const char ** m_indexes;
-};
-
-static
-const
-NDBT_IndexList indexes[] = {
- "I1", I1_Indexes,
- "I2", I2_Indexes,
- "I3", I3_Indexes,
- 0, 0
-};
-
-static
-const
-int numTestTables = sizeof(test_tables)/sizeof(NDBT_Table*);
-
-
-/**
- * Define tables we should not be able to create
- */
-
-/* F1
- *
- * Error: PK and column with same name
- */
-static
-const
-NDBT_Attribute F1Attribs[] = {
- NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned)
-};
-
-static
-const
-NDBT_Table F1("F1", sizeof(F1Attribs)/sizeof(NDBT_Attribute), F1Attribs);
-
-/* F2
- *
- * Error: Two columns with same name
- */
-static
-const
-NDBT_Attribute F2Attribs[] = {
- NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned)
-};
-
-static
-const
-NDBT_Table F2("F2", sizeof(F2Attribs)/sizeof(NDBT_Attribute), F2Attribs);
-
-/* F3
- *
- * Error: Too many primary keys defined, 32 is max
- */
-static
-const
-NDBT_Attribute F3Attribs[] = {
- NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL6", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL7", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL8", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL9", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL10", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL11", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL12", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL13", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL14", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL15", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL16", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL17", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL18", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL19", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL20", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL21", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL22", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL23", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL24", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL25", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL26", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL27", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL28", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL29", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL30", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL31", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL32", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL33", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("KOL40", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL50", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL60", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL70", NdbDictionary::Column::Unsigned)
-};
-
-static
-const
-NDBT_Table F3("F3", sizeof(F3Attribs)/sizeof(NDBT_Attribute), F3Attribs);
-
-/* F4
- *
- * Error: Too long key
- */
-static
-const
-NDBT_Attribute F4Attribs[] = {
- NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned, 9999999, true),
- NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned)
-};
-
-static
-const
-NDBT_Table F4("F4", sizeof(F4Attribs)/sizeof(NDBT_Attribute), F4Attribs);
-
-/* F5
- *
- * Error: Too long attr name
- */
-static
-const
-NDBT_Attribute F5Attribs[] = {
- NDBT_Attribute("KOL1WITHVERRYLONGNAME_ISITTOLONG", NdbDictionary::Column::Unsigned, true),
- NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned)
-};
-
-static
-const
-NDBT_Table F5("F5", sizeof(F5Attribs)/sizeof(NDBT_Attribute), F5Attribs);
-
-/* F6
- *
- * Error: Zero length of pk attribute
- */
-static
-const
-NDBT_Attribute F6Attribs[] = {
- NDBT_Attribute("KOL1", NdbDictionary::Column::Char, 0, true, false),
- NDBT_Attribute("KOL2", NdbDictionary::Column::Char, 256),
-};
-
-static
-const
-NDBT_Table F6("F6", sizeof(F6Attribs)/sizeof(NDBT_Attribute), F6Attribs);
-
-/* F7
- *
- * Error: Table without primary key
- */
-static
-const
-NDBT_Attribute F7Attribs[] = {
- NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned)
-};
-
-NDBT_Table F7("F7", sizeof(F7Attribs)/sizeof(NDBT_Attribute), F7Attribs);
-
-/* F8
- *
- * Error: Table without nullable primary key
- */
-static
-const
-NDBT_Attribute F8Attribs[] = {
- NDBT_Attribute("KOL3", NdbDictionary::Column::Int, 1, true, true),
- NDBT_Attribute("KOL4", NdbDictionary::Column::Int),
- NDBT_Attribute("KOL5", NdbDictionary::Column::Int)
-};
-
-NDBT_Table F8("F8", sizeof(F8Attribs)/sizeof(NDBT_Attribute), F8Attribs);
-
-
-/* F15 - 2-node crash in v20x */
-static
-const
-NDBT_Attribute F15Attribs[] = {
- NDBT_Attribute("KOL1", NdbDictionary::Column::Char, 40, true)
-};
-static
-const
-NDBT_Table F15("F15", sizeof(F15Attribs)/sizeof(NDBT_Attribute), F15Attribs);
-
-// Define array with pointer to tables that we should not be able to create
-static
-const
-NDBT_Table *fail_tables[]=
-{
- &F1,
- &F2,
- &F3,
- &F4,
- &F5,
- &F6,
- &F7,
- &F8,
- &F15
-};
-
-static
-const
-int numFailTables = sizeof(fail_tables)/sizeof(NDBT_Table*);
-
-
-/**
- * Define util tables that we may create
- */
-
-
-/* GL
- * General ledger table for bank application
- */
-static
-const
-NDBT_Attribute GL_Attribs[] = {
- NDBT_Attribute("TIME", NdbDictionary::Column::Bigunsigned, 1, true),
- NDBT_Attribute("ACCOUNT_TYPE", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("BALANCE", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("DEPOSIT_COUNT", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("DEPOSIT_SUM", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("WITHDRAWAL_COUNT", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("WITHDRAWAL_SUM", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("PURGED", NdbDictionary::Column::Unsigned)
-};
-
-static
-NDBT_Table GL("GL", sizeof(GL_Attribs)/sizeof(NDBT_Attribute), GL_Attribs);
-
-/* ACCOUNT
- * Account table for bank application
- */
-static
-const
-NDBT_Attribute ACCOUNT_Attribs[] = {
- NDBT_Attribute("ACCOUNT_ID", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("OWNER", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("BALANCE", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("ACCOUNT_TYPE", NdbDictionary::Column::Unsigned),
-};
-
-static
-NDBT_Table ACCOUNT("ACCOUNT", sizeof(ACCOUNT_Attribs)/sizeof(NDBT_Attribute), ACCOUNT_Attribs);
-
-/* TRANSACTION
- * Transaction table for bank application
- */
-static
-const
-NDBT_Attribute TRANSACTION_Attribs[] = {
- NDBT_Attribute("TRANSACTION_ID", NdbDictionary::Column::Bigunsigned, 1, true),
- NDBT_Attribute("ACCOUNT", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("ACCOUNT_TYPE", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("OTHER_ACCOUNT", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("TRANSACTION_TYPE", NdbDictionary::Column::Unsigned),
- NDBT_Attribute("TIME", NdbDictionary::Column::Bigunsigned),
- NDBT_Attribute("AMOUNT", NdbDictionary::Column::Unsigned),
-};
-
-static
-NDBT_Table TRANSACTION("TRANSACTION", sizeof(TRANSACTION_Attribs)/sizeof(NDBT_Attribute), TRANSACTION_Attribs);
-
-/* SYSTEM_VALUES
- * System values table for bank application
- */
-static
-const
-NDBT_Attribute SYSTEM_VALUES_Attribs[] = {
- NDBT_Attribute("SYSTEM_VALUES_ID", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("VALUE", NdbDictionary::Column::Bigunsigned)
-};
-
-static
-NDBT_Table SYSTEM_VALUES("SYSTEM_VALUES", sizeof(SYSTEM_VALUES_Attribs)/sizeof(NDBT_Attribute), SYSTEM_VALUES_Attribs);
-
-/* ACCOUNT_TYPES
- * Account types table for bank application
- */
-static
-const
-NDBT_Attribute ACCOUNT_TYPES_Attribs[] = {
- NDBT_Attribute("ACCOUNT_TYPE_ID", NdbDictionary::Column::Unsigned, 1, true),
- NDBT_Attribute("DESCRIPTION", NdbDictionary::Column::Char, 64, false, false, &my_charset_latin1_bin)
-};
-
-static
-NDBT_Table ACCOUNT_TYPES("ACCOUNT_TYPE", sizeof(ACCOUNT_TYPES_Attribs)/sizeof(NDBT_Attribute), ACCOUNT_TYPES_Attribs);
-
-
-// Define array with pointer to util tables
-static
-const
-NDBT_Table *util_tables[]=
-{
- &GL,
- &ACCOUNT,
- &TRANSACTION,
- &SYSTEM_VALUES,
- &ACCOUNT_TYPES
-};
-
-static
-const
-int numUtilTables = sizeof(util_tables)/sizeof(NDBT_Table*);
-
-
-const
-NdbDictionary::Table*
-NDBT_Tables::getTable(const char* _nam){
- // Search tables list to find a table
- NDBT_Table* tab = NULL;
- int i;
- for (i=0; i<numTestTables; i++){
- if (strcmp(test_tables[i]->getName(), _nam) == 0){
- return test_tables[i];
- }
- }
- for (i=0; i<numFailTables; i++){
- if (strcmp(fail_tables[i]->getName(), _nam) == 0){
- return fail_tables[i];
- }
- }
- for (i=0; i<numUtilTables; i++){
- if (strcmp(util_tables[i]->getName(), _nam) == 0){
- return util_tables[i];
- }
- }
- // TPK_no tables
- // Dynamcially create table vith primary key size
- // set to no
- // Useful for testing key sizes 1 - max
- int pkSizeOfTable;
- if(sscanf(_nam, "TPK_%d", &pkSizeOfTable) == 1){
- return tableWithPkSize(_nam, pkSizeOfTable);
- }
- return tab;
-}
-
-const NdbDictionary::Table*
-NDBT_Tables::tableWithPkSize(const char* _nam, Uint32 pkSize){
- NdbDictionary::Table* tab = new NdbDictionary::Table(_nam);
-
- // Add one PK of the desired length
- tab->addColumn(NDBT_Attribute("PK1",
- NdbDictionary::Column::Char,
- pkSize,
- true));
-
- // Add 4 attributes
- tab->addColumn(NDBT_Attribute("ATTR1",
- NdbDictionary::Column::Char,
- 21));
-
- tab->addColumn(NDBT_Attribute("ATTR2",
- NdbDictionary::Column::Char,
- 124));
-
- tab->addColumn(NDBT_Attribute("ATTR3",
- NdbDictionary::Column::Unsigned));
-
- tab->addColumn(NDBT_Attribute("ATTR4",
- NdbDictionary::Column::Unsigned));
-
- return tab;
-}
-
-const NdbDictionary::Table*
-NDBT_Tables::getTable(int _num){
- // Get table at pos _num
- assert(_num < numTestTables);
- return test_tables[_num];
-}
-
-int
-NDBT_Tables::getNumTables(){
- return numTestTables;
-}
-
-const char**
-NDBT_Tables::getIndexes(const char* table)
-{
- Uint32 i = 0;
- for (i = 0; indexes[i].m_table != 0; i++) {
- if (strcmp(indexes[i].m_table, table) == 0)
- return indexes[i].m_indexes;
- }
- return 0;
-}
-
-int
-NDBT_Tables::createAllTables(Ndb* pNdb, bool _temp, bool existsOk){
-
- for (int i=0; i < NDBT_Tables::getNumTables(); i++){
- pNdb->getDictionary()->dropTable(NDBT_Tables::getTable(i)->getName());
- int ret= createTable(pNdb,
- NDBT_Tables::getTable(i)->getName(), _temp, existsOk);
- if(ret){
- return ret;
- }
- }
- return NDBT_OK;
-}
-
-int
-NDBT_Tables::createAllTables(Ndb* pNdb){
- return createAllTables(pNdb, false);
-}
-
-int
-NDBT_Tables::create_default_tablespace(Ndb* pNdb)
-{
- NdbDictionary::Dictionary* pDict = pNdb->getDictionary();
-
- int res;
- NdbDictionary::LogfileGroup lg = pDict->getLogfileGroup("DEFAULT-LG");
- if (strcmp(lg.getName(), "DEFAULT-LG") != 0)
- {
- lg.setName("DEFAULT-LG");
- lg.setUndoBufferSize(8*1024*1024);
- res = pDict->createLogfileGroup(lg);
- if(res != 0){
- g_err << "Failed to create logfilegroup:"
- << endl << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
- }
- {
- NdbDictionary::Undofile uf = pDict->getUndofile(0, "undofile01.dat");
- if (strcmp(uf.getPath(), "undofile01.dat") != 0)
- {
- uf.setPath("undofile01.dat");
- uf.setSize(32*1024*1024);
- uf.setLogfileGroup("DEFAULT-LG");
-
- res = pDict->createUndofile(uf, true);
- if(res != 0){
- g_err << "Failed to create undofile:"
- << endl << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
- }
- }
- {
- NdbDictionary::Undofile uf = pDict->getUndofile(0, "undofile02.dat");
- if (strcmp(uf.getPath(), "undofile02.dat") != 0)
- {
- uf.setPath("undofile02.dat");
- uf.setSize(32*1024*1024);
- uf.setLogfileGroup("DEFAULT-LG");
-
- res = pDict->createUndofile(uf, true);
- if(res != 0){
- g_err << "Failed to create undofile:"
- << endl << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
- }
- }
- NdbDictionary::Tablespace ts = pDict->getTablespace("DEFAULT-TS");
- if (strcmp(ts.getName(), "DEFAULT-TS") != 0)
- {
- ts.setName("DEFAULT-TS");
- ts.setExtentSize(1024*1024);
- ts.setDefaultLogfileGroup("DEFAULT-LG");
-
- res = pDict->createTablespace(ts);
- if(res != 0){
- g_err << "Failed to create tablespace:"
- << endl << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
- }
-
- {
- NdbDictionary::Datafile df = pDict->getDatafile(0, "datafile01.dat");
- if (strcmp(df.getPath(), "datafile01.dat") != 0)
- {
- df.setPath("datafile01.dat");
- df.setSize(64*1024*1024);
- df.setTablespace("DEFAULT-TS");
-
- res = pDict->createDatafile(df, true);
- if(res != 0){
- g_err << "Failed to create datafile:"
- << endl << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
- }
- }
-
- {
- NdbDictionary::Datafile df = pDict->getDatafile(0, "datafile02.dat");
- if (strcmp(df.getPath(), "datafile02.dat") != 0)
- {
- df.setPath("datafile02.dat");
- df.setSize(64*1024*1024);
- df.setTablespace("DEFAULT-TS");
-
- res = pDict->createDatafile(df, true);
- if(res != 0){
- g_err << "Failed to create datafile:"
- << endl << pDict->getNdbError() << endl;
- return NDBT_FAILED;
- }
- }
- }
-
- return NDBT_OK;
-}
-
-int
-NDBT_Tables::createTable(Ndb* pNdb, const char* _name, bool _temp,
- bool existsOk, NDBT_CreateTableHook f, void* arg)
-{
- const NdbDictionary::Table* tab = NDBT_Tables::getTable(_name);
- if (tab == NULL){
- ndbout << "Could not create table " << _name
- << ", it doesn't exist in list of tables "\
- "that NDBT_Tables can create!" << endl;
- return NDBT_WRONGARGS;
- }
-
- Uint32 sum = 0;
- for (Uint32 i = 0; i<strlen(_name); i++)
- sum += 33 * sum + (Uint32)_name[i];
-
- bool forceVarPart = (sum & 1);
-
- int r = 0;
- do {
- NdbDictionary::Table tmpTab(* tab);
- tmpTab.setStoredTable(_temp ? 0 : 1);
- tmpTab.setForceVarPart(forceVarPart);
-
- {
- NdbError error;
- int ret = tmpTab.validate(error);
- assert(ret == 0);
- }
- if(f != 0 && f(pNdb, tmpTab, 0, arg))
- {
- ndbout << "Failed to create table" << endl;
- return NDBT_FAILED;
- }
-loop:
- r = pNdb->getDictionary()->createTable(tmpTab);
- if(r == -1){
- if(pNdb->getDictionary()->getNdbError().code == 755)
- {
- if (create_default_tablespace(pNdb) == 0)
- {
- goto loop;
- }
- }
- if(!existsOk){
- ndbout << "Error0: " << pNdb->getDictionary()->getNdbError() << endl;
-
- break;
- }
- if(pNdb->getDictionary()->getNdbError().code != 721){
- ndbout << "Error: " << pNdb->getDictionary()->getNdbError() << endl;
- break;
- }
-
- r = 0;
- }
-
- Uint32 i = 0;
- for(i = 0; indexes[i].m_table != 0; i++){
- if(strcmp(indexes[i].m_table, _name) != 0)
- continue;
- Uint32 j = 0;
- while(indexes[i].m_indexes[j] != 0){
- NdbDictionary::Index tmpIndx;
- BaseString name;
- name.assfmt("%s$NDBT_IDX%d", _name, j);
- tmpIndx.setName(name.c_str());
- tmpIndx.setTable(_name);
- bool logging = !_temp;
- if(strcmp(indexes[i].m_indexes[j], "ORDERED") == 0){
- logging = false;
- tmpIndx.setType(NdbDictionary::Index::OrderedIndex);
- } else if(strcmp(indexes[i].m_indexes[j], "UNIQUE") == 0){
- tmpIndx.setType(NdbDictionary::Index::UniqueHashIndex);
- } else {
- ndbout << "Unknown index type";
- abort();
- }
- tmpIndx.setLogging(logging);
-
- j++;
- while(indexes[i].m_indexes[j] != 0){
- tmpIndx.addIndexColumn(indexes[i].m_indexes[j]);
- j++;
- }
- j++;
- if (tmpTab.getTemporary())
- {
- tmpIndx.setTemporary(true);
- tmpIndx.setLogging(false);
- }
- if(pNdb->getDictionary()->createIndex(tmpIndx) != 0){
- ndbout << pNdb->getDictionary()->getNdbError() << endl;
- return NDBT_FAILED;
- }
- }
- }
- if(f != 0 && f(pNdb, tmpTab, 1, arg))
- {
- ndbout << "Failed to create table" << endl;
- return NDBT_FAILED;
- }
- } while(false);
-
- return r;
-}
-
-int
-NDBT_Tables::dropAllTables(Ndb* pNdb){
-
- for (int i=0; i < NDBT_Tables::getNumTables(); i++){
-
- const NdbDictionary::Table* tab = NDBT_Tables::getTable(i);
- if (tab == NULL){
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- if(pNdb->getDictionary()->dropTable(tab->getName()) == -1){
- return NDBT_FAILED;
- }
- }
- return NDBT_OK;
-}
-
-
-int
-NDBT_Tables::print(const char * _name){
-
- const NDBT_Table * tab = (const NDBT_Table*)NDBT_Tables::getTable(_name);
- if (tab == NULL){
- ndbout << "Could not print table " << _name
- << ", it doesn't exist in list of tables "
- << "that NDBT_Tables can create!" << endl;
- return NDBT_WRONGARGS;
- }
- ndbout << (* tab) << endl;
- return NDBT_OK;
-}
-
-int
-NDBT_Tables::printAll(){
-
- for (int i=0; i < getNumTables(); i++){
-
- const NdbDictionary::Table* tab = getTable(i);
- if (tab == NULL){
- abort();
- }
- ndbout << (* (NDBT_Table*)tab) << endl;
- }
-
- return NDBT_OK;
-}
diff --git a/storage/ndb/test/src/NDBT_Test.cpp b/storage/ndb/test/src/NDBT_Test.cpp
deleted file mode 100644
index 891c0d91ae1..00000000000
--- a/storage/ndb/test/src/NDBT_Test.cpp
+++ /dev/null
@@ -1,1525 +0,0 @@
-/* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-//#define NDB_OPTS_SKIP_USAGE
-#include <ndb_opts.h>
-#include <my_pthread.h>
-
-#include "NDBT.hpp"
-#include "NDBT_Test.hpp"
-
-#include <PortDefs.h>
-
-#include <time.h>
-
-// No verbose outxput
-
-NDBT_Context::NDBT_Context(Ndb_cluster_connection& con)
- : m_cluster_connection(con)
-{
- suite = NULL;
- testcase = NULL;
- ndb = NULL;
- records = 1;
- loops = 1;
- stopped = false;
- remote_mgm ="";
- propertyMutexPtr = NdbMutex_Create();
- propertyCondPtr = NdbCondition_Create();
-}
-
-
-char * NDBT_Context::getRemoteMgm() const {
- return remote_mgm;
-}
-void NDBT_Context::setRemoteMgm(char * mgm) {
- remote_mgm = strdup(mgm);
-}
-
-
-NDBT_Context::~NDBT_Context(){
- NdbCondition_Destroy(propertyCondPtr);
- NdbMutex_Destroy(propertyMutexPtr);
-}
-
-const NdbDictionary::Table* NDBT_Context::getTab(){
- assert(tables.size());
- return tables[0];
-}
-
-NDBT_TestSuite* NDBT_Context::getSuite(){
- assert(suite != NULL);
- return suite;
-}
-
-NDBT_TestCase* NDBT_Context::getCase(){
- assert(testcase != NULL);
- return testcase;
-}
-
-const char* NDBT_Context::getTableName(int n) const
-{
- assert(suite != NULL);
- return suite->m_tables_in_test[n].c_str();
-}
-
-int NDBT_Context::getNumTables() const
-{
- assert(suite != NULL);
- return suite->m_tables_in_test.size();
-}
-
-int NDBT_Context::getNumRecords() const{
- return records;
-}
-
-int NDBT_Context::getNumLoops() const{
- return loops;
-}
-
-int NDBT_Context::getNoOfRunningSteps() const {
- return testcase->getNoOfRunningSteps();
-
-}
-int NDBT_Context::getNoOfCompletedSteps() const {
- return testcase->getNoOfCompletedSteps();
-}
-
-
-Uint32 NDBT_Context::getProperty(const char* _name, Uint32 _default){
- Uint32 val;
- NdbMutex_Lock(propertyMutexPtr);
- if(!props.get(_name, &val))
- val = _default;
- NdbMutex_Unlock(propertyMutexPtr);
- return val;
-}
-
-bool NDBT_Context::getPropertyWait(const char* _name, Uint32 _waitVal){
- bool result;
- NdbMutex_Lock(propertyMutexPtr);
- Uint32 val =! _waitVal;
-
- while((!props.get(_name, &val) || (props.get(_name, &val) && val != _waitVal)) &&
- !stopped)
- NdbCondition_Wait(propertyCondPtr,
- propertyMutexPtr);
- result = (val == _waitVal);
- NdbMutex_Unlock(propertyMutexPtr);
- return stopped;
-}
-
-const char* NDBT_Context::getProperty(const char* _name, const char* _default){
- const char* val;
- NdbMutex_Lock(propertyMutexPtr);
- if(!props.get(_name, &val))
- val = _default;
- NdbMutex_Unlock(propertyMutexPtr);
- return val;
-}
-
-const char* NDBT_Context::getPropertyWait(const char* _name, const char* _waitVal){
- const char* val;
- NdbMutex_Lock(propertyMutexPtr);
- while(!props.get(_name, &val) && (strcmp(val, _waitVal)==0))
- NdbCondition_Wait(propertyCondPtr,
- propertyMutexPtr);
-
- NdbMutex_Unlock(propertyMutexPtr);
- return val;
-}
-
-void NDBT_Context::setProperty(const char* _name, Uint32 _val){
- NdbMutex_Lock(propertyMutexPtr);
- const bool b = props.put(_name, _val, true);
- assert(b == true);
- NdbCondition_Broadcast(propertyCondPtr);
- NdbMutex_Unlock(propertyMutexPtr);
-}
-
-void
-NDBT_Context::decProperty(const char * name){
- NdbMutex_Lock(propertyMutexPtr);
- Uint32 val = 0;
- if(props.get(name, &val)){
- assert(val > 0);
- props.put(name, (val - 1), true);
- }
- NdbCondition_Broadcast(propertyCondPtr);
- NdbMutex_Unlock(propertyMutexPtr);
-}
-
-void
-NDBT_Context::incProperty(const char * name){
- NdbMutex_Lock(propertyMutexPtr);
- Uint32 val = 0;
- props.get(name, &val);
- props.put(name, (val + 1), true);
- NdbCondition_Broadcast(propertyCondPtr);
- NdbMutex_Unlock(propertyMutexPtr);
-}
-
-void NDBT_Context::setProperty(const char* _name, const char* _val){
- NdbMutex_Lock(propertyMutexPtr);
- const bool b = props.put(_name, _val);
- assert(b == true);
- NdbCondition_Broadcast(propertyCondPtr);
- NdbMutex_Unlock(propertyMutexPtr);
-}
-
-void NDBT_Context::stopTest(){
- NdbMutex_Lock(propertyMutexPtr);
- g_info << "|- stopTest called" << endl;
- stopped = true;
- NdbCondition_Broadcast(propertyCondPtr);
- NdbMutex_Unlock(propertyMutexPtr);
-}
-
-bool NDBT_Context::isTestStopped(){
- NdbMutex_Lock(propertyMutexPtr);
- bool val = stopped;
- NdbMutex_Unlock(propertyMutexPtr);
- return val;
-}
-
-void NDBT_Context::wait(){
- NdbMutex_Lock(propertyMutexPtr);
- NdbCondition_Wait(propertyCondPtr,
- propertyMutexPtr);
- NdbMutex_Unlock(propertyMutexPtr);
-}
-
-void NDBT_Context::wait_timeout(int msec){
- NdbMutex_Lock(propertyMutexPtr);
- NdbCondition_WaitTimeout(propertyCondPtr,
- propertyMutexPtr,
- msec);
- NdbMutex_Unlock(propertyMutexPtr);
-}
-
-void NDBT_Context::broadcast(){
- NdbMutex_Lock(propertyMutexPtr);
- NdbCondition_Broadcast(propertyCondPtr);
- NdbMutex_Unlock(propertyMutexPtr);
-}
-
-Uint32 NDBT_Context::getDbProperty(const char*){
- abort();
- return 0;
-}
-
-bool NDBT_Context::setDbProperty(const char*, Uint32){
- abort();
- return true;
-}
-
-void NDBT_Context::setTab(const NdbDictionary::Table* ptab){
- tables.clear();
- tables.push_back(ptab);
- tables.push_back(0);
-}
-
-void NDBT_Context::addTab(const NdbDictionary::Table* ptab){
- if(tables.size())
- tables.back() = ptab;
- else
- tables.push_back(ptab);
-
- tables.push_back(0);
-}
-
-
-const NdbDictionary::Table**
-NDBT_Context::getTables()
-{
- return tables.getBase();
-}
-
-void NDBT_Context::setSuite(NDBT_TestSuite* psuite){
- assert(psuite != NULL);
- suite = psuite;
-}
-
-void NDBT_Context::setCase(NDBT_TestCase* pcase){
- assert(pcase != NULL);
- testcase = pcase;
-}
-
-void NDBT_Context::setNumRecords(int _records){
- records = _records;
-
-}
-
-void NDBT_Context::setNumLoops(int _loops){
- loops = _loops;
-}
-
-NDBT_Step::NDBT_Step(NDBT_TestCase* ptest, const char* pname,
- NDBT_TESTFUNC* pfunc): name(pname){
- assert(pfunc != NULL);
- func = pfunc;
- testcase = ptest;
- step_no = -1;
-}
-
-int NDBT_Step::execute(NDBT_Context* ctx) {
- assert(ctx != NULL);
-
- int result;
-
- g_info << " |- " << name << " started [" << ctx->suite->getDate() << "]"
- << endl;
-
- result = setUp(ctx->m_cluster_connection);
- if (result != NDBT_OK){
- return result;
- }
-
- result = func(ctx, this);
-
- if (result != NDBT_OK) {
- g_err << " |- " << name << " FAILED [" << ctx->suite->getDate()
- << "]" << endl;
- }
- else {
- g_info << " |- " << name << " PASSED [" << ctx->suite->getDate() << "]"
- << endl;
- }
-
- tearDown();
-
- return result;
-}
-
-void NDBT_Step::setContext(NDBT_Context* pctx){
- assert(pctx != NULL);
- m_ctx = pctx;
-}
-
-NDBT_Context* NDBT_Step::getContext(){
- assert(m_ctx != NULL);
- return m_ctx;
-}
-
-NDBT_NdbApiStep::NDBT_NdbApiStep(NDBT_TestCase* ptest,
- const char* pname,
- NDBT_TESTFUNC* pfunc)
- : NDBT_Step(ptest, pname, pfunc),
- ndb(NULL) {
-}
-
-
-int
-NDBT_NdbApiStep::setUp(Ndb_cluster_connection& con){
- ndb = new Ndb(&con, "TEST_DB" );
- ndb->init(1024);
-
- int result = ndb->waitUntilReady(300); // 5 minutes
- if (result != 0){
- g_err << name << ": Ndb was not ready" << endl;
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-void
-NDBT_NdbApiStep::tearDown(){
- delete ndb;
- ndb = NULL;
-}
-
-Ndb* NDBT_NdbApiStep::getNdb(){
- assert(ndb != NULL);
- return ndb;
-}
-
-
-NDBT_ParallelStep::NDBT_ParallelStep(NDBT_TestCase* ptest,
- const char* pname,
- NDBT_TESTFUNC* pfunc)
- : NDBT_NdbApiStep(ptest, pname, pfunc) {
-}
-NDBT_Verifier::NDBT_Verifier(NDBT_TestCase* ptest,
- const char* pname,
- NDBT_TESTFUNC* pfunc)
- : NDBT_NdbApiStep(ptest, pname, pfunc) {
-}
-NDBT_Initializer::NDBT_Initializer(NDBT_TestCase* ptest,
- const char* pname,
- NDBT_TESTFUNC* pfunc)
- : NDBT_NdbApiStep(ptest, pname, pfunc) {
-}
-NDBT_Finalizer::NDBT_Finalizer(NDBT_TestCase* ptest,
- const char* pname,
- NDBT_TESTFUNC* pfunc)
- : NDBT_NdbApiStep(ptest, pname, pfunc) {
-}
-
-NDBT_TestCase::NDBT_TestCase(NDBT_TestSuite* psuite,
- const char* pname,
- const char* pcomment) :
- name(strdup(pname)) ,
- comment(strdup(pcomment)),
- suite(psuite)
-{
- _name.assign(pname);
- _comment.assign(pcomment);
- name= _name.c_str();
- comment= _comment.c_str();
- assert(suite != NULL);
-
- m_all_tables = false;
- m_has_run = false;
-}
-
-NDBT_TestCaseImpl1::NDBT_TestCaseImpl1(NDBT_TestSuite* psuite,
- const char* pname,
- const char* pcomment) :
- NDBT_TestCase(psuite, pname, pcomment){
-
- numStepsOk = 0;
- numStepsFail = 0;
- numStepsCompleted = 0;
- waitThreadsMutexPtr = NdbMutex_Create();
- waitThreadsCondPtr = NdbCondition_Create();
-}
-
-NDBT_TestCaseImpl1::~NDBT_TestCaseImpl1(){
- NdbCondition_Destroy(waitThreadsCondPtr);
- NdbMutex_Destroy(waitThreadsMutexPtr);
- size_t i;
- for(i = 0; i < initializers.size(); i++)
- delete initializers[i];
- initializers.clear();
- for(i = 0; i < verifiers.size(); i++)
- delete verifiers[i];
- verifiers.clear();
- for(i = 0; i < finalizers.size(); i++)
- delete finalizers[i];
- finalizers.clear();
- for(i = 0; i < steps.size(); i++)
- delete steps[i];
- steps.clear();
- results.clear();
- for(i = 0; i < testTables.size(); i++)
- delete testTables[i];
- testTables.clear();
- for(i = 0; i < testResults.size(); i++)
- delete testResults[i];
- testResults.clear();
-
-}
-
-int NDBT_TestCaseImpl1::addStep(NDBT_Step* pStep){
- assert(pStep != NULL);
- steps.push_back(pStep);
- pStep->setStepNo(steps.size());
- int res = NORESULT;
- results.push_back(res);
- return 0;
-}
-
-int NDBT_TestCaseImpl1::addVerifier(NDBT_Verifier* pVerifier){
- assert(pVerifier != NULL);
- verifiers.push_back(pVerifier);
- return 0;
-}
-
-int NDBT_TestCaseImpl1::addInitializer(NDBT_Initializer* pInitializer){
- assert(pInitializer != NULL);
- initializers.push_back(pInitializer);
- return 0;
-}
-
-int NDBT_TestCaseImpl1::addFinalizer(NDBT_Finalizer* pFinalizer){
- assert(pFinalizer != NULL);
- finalizers.push_back(pFinalizer);
- return 0;
-}
-
-void NDBT_TestCaseImpl1::addTable(const char* tableName, bool isVerify) {
- assert(tableName != NULL);
- const NdbDictionary::Table* pTable = NDBT_Tables::getTable(tableName);
- assert(pTable != NULL);
- testTables.push_back(pTable);
- isVerifyTables = isVerify;
-}
-
-bool NDBT_TestCaseImpl1::tableExists(NdbDictionary::Table* aTable) {
- for (unsigned i = 0; i < testTables.size(); i++) {
- if (strcasecmp(testTables[i]->getName(), aTable->getName()) == 0) {
- return true;
- }
- }
- return false;
-}
-
-bool NDBT_TestCaseImpl1::isVerify(const NdbDictionary::Table* aTable) {
- if (testTables.size() > 0) {
- int found = false;
- // OK, we either exclude or include this table in the actual test
- for (unsigned i = 0; i < testTables.size(); i++) {
- if (strcasecmp(testTables[i]->getName(), aTable->getName()) == 0) {
- // Found one!
- if (isVerifyTables) {
- // Found one to test
- found = true;
- } else {
- // Skip this one!
- found = false;
- }
- }
- } // for
- return found;
- } else {
- // No included or excluded test tables, i.e., all tables should be
- // tested
- return true;
- }
- return true;
-}
-
-void NDBT_TestCase::setProperty(const char* _name, Uint32 _val){
- const bool b = props.put(_name, _val);
- assert(b == true);
-}
-
-void NDBT_TestCase::setProperty(const char* _name, const char* _val){
- const bool b = props.put(_name, _val);
- assert(b == true);
-}
-
-
-void *
-runStep(void * s){
- assert(s != NULL);
- NDBT_Step* pStep = (NDBT_Step*)s;
- NDBT_Context* ctx = pStep->getContext();
- assert(ctx != NULL);
- // Execute function
- int res = pStep->execute(ctx);
- if(res != NDBT_OK){
- ctx->stopTest();
- }
- // Report
- NDBT_TestCaseImpl1* pCase = (NDBT_TestCaseImpl1*)ctx->getCase();
- assert(pCase != NULL);
- pCase->reportStepResult(pStep, res);
- return NULL;
-}
-
-extern "C"
-void *
-runStep_C(void * s)
-{
- runStep(s);
- return NULL;
-}
-
-
-void NDBT_TestCaseImpl1::startStepInThread(int stepNo, NDBT_Context* ctx){
- NDBT_Step* pStep = steps[stepNo];
- pStep->setContext(ctx);
- char buf[16];
- BaseString::snprintf(buf, sizeof(buf), "step_%d", stepNo);
- NdbThread* pThread = NdbThread_Create(runStep_C,
- (void**)pStep,
- 65535,
- buf,
- NDB_THREAD_PRIO_LOW);
- threads.push_back(pThread);
-}
-
-void NDBT_TestCaseImpl1::waitSteps(){
- NdbMutex_Lock(waitThreadsMutexPtr);
- while(numStepsCompleted != steps.size())
- NdbCondition_Wait(waitThreadsCondPtr,
- waitThreadsMutexPtr);
-
- unsigned completedSteps = 0;
- unsigned i;
- for(i=0; i<steps.size(); i++){
- if (results[i] != NORESULT){
- completedSteps++;
- if (results[i] == NDBT_OK)
- numStepsOk++;
- else
- numStepsFail++;
- }
- }
- assert(completedSteps == steps.size());
- assert(completedSteps == numStepsCompleted);
-
- NdbMutex_Unlock(waitThreadsMutexPtr);
- void *status;
- for(i=0; i<steps.size();i++){
- NdbThread_WaitFor(threads[i], &status);
- NdbThread_Destroy(&threads[i]);
- }
- threads.clear();
-}
-
-
-int
-NDBT_TestCaseImpl1::getNoOfRunningSteps() const {
- return steps.size() - getNoOfCompletedSteps();
-}
-
-int
-NDBT_TestCaseImpl1::getNoOfCompletedSteps() const {
- return numStepsCompleted;
-}
-
-void NDBT_TestCaseImpl1::reportStepResult(const NDBT_Step* pStep, int result){
- NdbMutex_Lock(waitThreadsMutexPtr);
- assert(pStep != NULL);
- for (unsigned i = 0; i < steps.size(); i++){
- if(steps[i] != NULL && steps[i] == pStep){
- results[i] = result;
- numStepsCompleted++;
- }
- }
- if(numStepsCompleted == steps.size()){
- NdbCondition_Signal(waitThreadsCondPtr);
- }
- NdbMutex_Unlock(waitThreadsMutexPtr);
-}
-
-
-int NDBT_TestCase::execute(NDBT_Context* ctx){
- int res;
-
- ndbout << "- " << name << " started [" << ctx->suite->getDate()
- << "]" << endl;
-
- ctx->setCase(this);
-
- // Copy test case properties to ctx
- Properties::Iterator it(&props);
- for(const char * key = it.first(); key != 0; key = it.next()){
-
- PropertiesType pt;
- const bool b = props.getTypeOf(key, &pt);
- assert(b == true);
- switch(pt){
- case PropertiesType_Uint32:{
- Uint32 val;
- props.get(key, &val);
- ctx->setProperty(key, val);
- break;
- }
- case PropertiesType_char:{
- const char * val;
- props.get(key, &val);
- ctx->setProperty(key, val);
- break;
- }
- default:
- abort();
- }
- }
-
- // start timer so that we get a time even if
- // test case consist only of initializer
- startTimer(ctx);
-
- if ((res = runInit(ctx)) == NDBT_OK){
- // If initialiser is ok, run steps
-
- res = runSteps(ctx);
- if (res == NDBT_OK){
- // If steps is ok, run verifier
- res = runVerifier(ctx);
- }
-
- }
-
- stopTimer(ctx);
- printTimer(ctx);
-
- // Always run finalizer to clean up db
- runFinal(ctx);
-
- if (res == NDBT_OK) {
- ndbout << "- " << name << " PASSED [" << ctx->suite->getDate() << "]"
- << endl;
- }
- else {
- ndbout << "- " << name << " FAILED [" << ctx->suite->getDate() << "]"
- << endl;
- }
- return res;
-}
-
-void NDBT_TestCase::startTimer(NDBT_Context* ctx){
- timer.doStart();
-}
-
-void NDBT_TestCase::stopTimer(NDBT_Context* ctx){
- timer.doStop();
-}
-
-void NDBT_TestCase::printTimer(NDBT_Context* ctx){
- if (suite->timerIsOn()){
- g_info << endl;
- timer.printTestTimer(ctx->getNumLoops(), ctx->getNumRecords());
- }
-}
-
-int NDBT_TestCaseImpl1::runInit(NDBT_Context* ctx){
- int res = NDBT_OK;
- for (unsigned i = 0; i < initializers.size(); i++){
- initializers[i]->setContext(ctx);
- res = initializers[i]->execute(ctx);
- if (res != NDBT_OK)
- break;
- }
- return res;
-}
-
-int NDBT_TestCaseImpl1::runSteps(NDBT_Context* ctx){
- int res = NDBT_OK;
-
- // Reset variables
- numStepsOk = 0;
- numStepsFail = 0;
- numStepsCompleted = 0;
- unsigned i;
- for (i = 0; i < steps.size(); i++)
- startStepInThread(i, ctx);
- waitSteps();
-
- for(i = 0; i < steps.size(); i++)
- if (results[i] != NDBT_OK)
- res = NDBT_FAILED;
- return res;
-}
-
-int NDBT_TestCaseImpl1::runVerifier(NDBT_Context* ctx){
- int res = NDBT_OK;
- for (unsigned i = 0; i < verifiers.size(); i++){
- verifiers[i]->setContext(ctx);
- res = verifiers[i]->execute(ctx);
- if (res != NDBT_OK)
- break;
- }
- return res;
-}
-
-int NDBT_TestCaseImpl1::runFinal(NDBT_Context* ctx){
- int res = NDBT_OK;
- for (unsigned i = 0; i < finalizers.size(); i++){
- finalizers[i]->setContext(ctx);
- res = finalizers[i]->execute(ctx);
- if (res != NDBT_OK)
- break;
- }
- return res;
-}
-
-
-void NDBT_TestCaseImpl1::saveTestResult(const NdbDictionary::Table* ptab,
- int result){
- testResults.push_back(new NDBT_TestCaseResult(ptab->getName(),
- result,
- timer.elapsedTime()));
-}
-
-void NDBT_TestCaseImpl1::printTestResult(){
-
- char buf[255];
- ndbout << name<<endl;
-
- for (unsigned i = 0; i < testResults.size(); i++){
- NDBT_TestCaseResult* tcr = testResults[i];
- const char* res;
- if (tcr->getResult() == NDBT_OK)
- res = "OK";
- else if (tcr->getResult() == NDBT_FAILED)
- res = "FAIL";
- else if (tcr->getResult() == FAILED_TO_CREATE)
- res = "FAILED TO CREATE TABLE";
- else if (tcr->getResult() == FAILED_TO_DISCOVER)
- res = "FAILED TO DISCOVER TABLE";
- BaseString::snprintf(buf, 255," %-10s %-5s %-20s", tcr->getName(), res, tcr->getTimeStr());
- ndbout << buf<<endl;
- }
-}
-
-
-
-
-
-NDBT_TestSuite::NDBT_TestSuite(const char* pname):name(pname){
- numTestsOk = 0;
- numTestsFail = 0;
- numTestsExecuted = 0;
- records = 0;
- loops = 0;
- createTable = true;
- diskbased = false;
- tsname = NULL;
- createAllTables = false;
- temporaryTables = false;
-}
-
-
-NDBT_TestSuite::~NDBT_TestSuite(){
- for(unsigned i=0; i<tests.size(); i++){
- delete tests[i];
- }
- tests.clear();
-}
-
-void NDBT_TestSuite::setCreateTable(bool _flag){
- createTable = _flag;
-}
-
-void NDBT_TestSuite::setRunAllTables(bool _flag){
- runonce = _flag;
-}
-void NDBT_TestSuite::setCreateAllTables(bool _flag){
- createAllTables = _flag;
-}
-
-void NDBT_TestSuite::setTemporaryTables(bool val){
- temporaryTables = val;
-}
-
-bool NDBT_TestSuite::getTemporaryTables() const {
- return temporaryTables;
-}
-
-bool NDBT_TestSuite::timerIsOn(){
- return (timer != 0);
-}
-
-int NDBT_TestSuite::addTest(NDBT_TestCase* pTest){
- assert(pTest != NULL);
- tests.push_back(pTest);
- return 0;
-}
-
-static int
-g_create_hook(Ndb* ndb, NdbDictionary::Table& tab, int when, void* arg)
-{
- NDBT_TestSuite* ts = (NDBT_TestSuite*)arg;
-
- return ts->createHook(ndb, tab, when);
-}
-
-
-int NDBT_TestSuite::executeAll(Ndb_cluster_connection& con,
- const char* _testname){
-
- if(tests.size() == 0)
- return NDBT_FAILED;
- Ndb ndb(&con, "TEST_DB");
- ndb.init(1024);
-
- int result = ndb.waitUntilReady(500); // 5 minutes
- if (result != 0){
- g_err << name <<": Ndb was not ready" << endl;
- return NDBT_FAILED;
- }
-
- ndbout << name << " started [" << getDate() << "]" << endl;
-
-
- if(!runonce)
- {
- testSuiteTimer.doStart();
- for (int t=0; t < NDBT_Tables::getNumTables(); t++){
- const NdbDictionary::Table* ptab = NDBT_Tables::getTable(t);
- ndbout << "|- " << ptab->getName() << endl;
- execute(con, &ndb, ptab, _testname);
- }
- testSuiteTimer.doStop();
- }
- else
- {
- NdbDictionary::Dictionary* pDict= ndb.getDictionary();
- for (unsigned i = 0; i < tests.size(); i++){
- if (_testname != NULL && strcasecmp(tests[i]->getName(), _testname) != 0)
- continue;
-
-
- tests[i]->initBeforeTest();
- ctx = new NDBT_Context(con);
-
- Uint32 t;
- for (t=0; t < (Uint32)NDBT_Tables::getNumTables(); t++)
- {
- const NdbDictionary::Table* pTab = NDBT_Tables::getTable(t);
- const NdbDictionary::Table* pTab2 = pDict->getTable(pTab->getName());
-
- if(pTab2 != 0 && pDict->dropTable(pTab->getName()) != 0)
- {
- numTestsFail++;
- numTestsExecuted++;
- g_err << "ERROR0: Failed to drop table " << pTab->getName() << endl;
- tests[i]->saveTestResult(pTab, FAILED_TO_CREATE);
- continue;
- }
-
- if (NDBT_Tables::createTable(&ndb, pTab->getName(), false, false,
- g_create_hook, this) != 0) {
- numTestsFail++;
- numTestsExecuted++;
- g_err << "ERROR1: Failed to create table " << pTab->getName()
- << pDict->getNdbError() << endl;
- tests[i]->saveTestResult(pTab, FAILED_TO_CREATE);
- continue;
- }
- pTab2 = pDict->getTable(pTab->getName());
-
- ctx->addTab(pTab2);
- }
-
- ctx->setNumRecords(records);
- ctx->setNumLoops(loops);
- if(remote_mgm != NULL)
- ctx->setRemoteMgm(remote_mgm);
- ctx->setSuite(this);
-
- const NdbDictionary::Table** tables= ctx->getTables();
-
- result = tests[i]->execute(ctx);
- tests[i]->saveTestResult(tables[0], result);
- if (result != NDBT_OK)
- numTestsFail++;
- else
- numTestsOk++;
- numTestsExecuted++;
-
- if(result == NDBT_OK)
- {
- for(t = 0; tables[t] != 0; t++)
- {
- pDict->dropTable(tables[t]->getName());
- }
- }
-
- delete ctx;
- }
- }
- return reportAllTables(_testname);
-}
-
-int
-NDBT_TestSuite::executeOne(Ndb_cluster_connection& con,
- const char* _tabname, const char* _testname){
-
- if(tests.size() == 0)
- return NDBT_FAILED;
- Ndb ndb(&con, "TEST_DB");
- ndb.init(1024);
-
- int result = ndb.waitUntilReady(300); // 5 minutes
- if (result != 0){
- g_err << name <<": Ndb was not ready" << endl;
- return NDBT_FAILED;
- }
-
- ndbout << name << " started [" << getDate() << "]" << endl;
-
- const NdbDictionary::Table* ptab = NDBT_Tables::getTable(_tabname);
- if (ptab == NULL)
- return NDBT_FAILED;
-
- ndbout << "|- " << ptab->getName() << endl;
-
- execute(con, &ndb, ptab, _testname);
-
- if (numTestsFail > 0){
- return NDBT_FAILED;
- }else{
- return NDBT_OK;
- }
-}
-
-int
-NDBT_TestSuite::executeOneCtx(Ndb_cluster_connection& con,
- const NdbDictionary::Table *ptab, const char* _testname){
-
- testSuiteTimer.doStart();
-
- do{
- if(tests.size() == 0)
- break;
-
- Ndb ndb(&con, "TEST_DB");
- ndb.init(1024);
-
- int result = ndb.waitUntilReady(300); // 5 minutes
- if (result != 0){
- g_err << name <<": Ndb was not ready" << endl;
- break;
- }
-
- ndbout << name << " started [" << getDate() << "]" << endl;
- ndbout << "|- " << ptab->getName() << endl;
-
- for (unsigned t = 0; t < tests.size(); t++){
-
- if (_testname != NULL &&
- strcasecmp(tests[t]->getName(), _testname) != 0)
- continue;
-
- tests[t]->initBeforeTest();
-
- ctx = new NDBT_Context(con);
- ctx->setTab(ptab);
- ctx->setNumRecords(records);
- ctx->setNumLoops(loops);
- if(remote_mgm != NULL)
- ctx->setRemoteMgm(remote_mgm);
- ctx->setSuite(this);
-
- result = tests[t]->execute(ctx);
- if (result != NDBT_OK)
- numTestsFail++;
- else
- numTestsOk++;
- numTestsExecuted++;
-
- delete ctx;
- }
-
- if (numTestsFail > 0)
- break;
- }while(0);
-
- testSuiteTimer.doStop();
- int res = report(_testname);
- return NDBT_ProgramExit(res);
-}
-
-int
-NDBT_TestSuite::createHook(Ndb* ndb, NdbDictionary::Table& tab, int when)
-{
- if (when == 0) {
- if (diskbased)
- {
- for (int i = 0; i < tab.getNoOfColumns(); i++)
- {
- NdbDictionary::Column* col = tab.getColumn(i);
- if (! col->getPrimaryKey())
- {
- col->setStorageType(NdbDictionary::Column::StorageTypeDisk);
- }
- }
- }
- else if (temporaryTables)
- {
- tab.setTemporary(true);
- tab.setLogging(false);
- }
-
- if (tsname != NULL) {
- tab.setTablespaceName(tsname);
- }
- }
- return 0;
-}
-
-void NDBT_TestSuite::execute(Ndb_cluster_connection& con,
- Ndb* ndb, const NdbDictionary::Table* pTab,
- const char* _testname){
- int result;
-
- for (unsigned t = 0; t < tests.size(); t++){
-
- if (_testname != NULL &&
- strcasecmp(tests[t]->getName(), _testname) != 0)
- continue;
-
- if (tests[t]->m_all_tables && tests[t]->m_has_run)
- {
- continue;
- }
-
- if (tests[t]->isVerify(pTab) == false) {
- continue;
- }
-
- tests[t]->initBeforeTest();
-
- NdbDictionary::Dictionary* pDict = ndb->getDictionary();
- const NdbDictionary::Table* pTab2 = pDict->getTable(pTab->getName());
- if (createTable == true){
-
- if(pTab2 != 0 && pDict->dropTable(pTab->getName()) != 0){
- numTestsFail++;
- numTestsExecuted++;
- g_err << "ERROR0: Failed to drop table " << pTab->getName() << endl;
- tests[t]->saveTestResult(pTab, FAILED_TO_CREATE);
- continue;
- }
-
- if (NDBT_Tables::createTable(ndb, pTab->getName(), false, false,
- g_create_hook, this) != 0) {
- numTestsFail++;
- numTestsExecuted++;
- g_err << "ERROR1: Failed to create table " << pTab->getName()
- << pDict->getNdbError() << endl;
- tests[t]->saveTestResult(pTab, FAILED_TO_CREATE);
- continue;
- }
- pTab2 = pDict->getTable(pTab->getName());
- } else if(!pTab2) {
- pTab2 = pTab;
- }
-
- ctx = new NDBT_Context(con);
- ctx->setTab(pTab2);
- ctx->setNumRecords(records);
- ctx->setNumLoops(loops);
- if(remote_mgm != NULL)
- ctx->setRemoteMgm(remote_mgm);
- ctx->setSuite(this);
-
- result = tests[t]->execute(ctx);
- tests[t]->saveTestResult(pTab, result);
- if (result != NDBT_OK)
- numTestsFail++;
- else
- numTestsOk++;
- numTestsExecuted++;
-
- if (result == NDBT_OK && createTable == true && createAllTables == false){
- pDict->dropTable(pTab->getName());
- }
-
- tests[t]->m_has_run = true;
-
- delete ctx;
- }
-}
-
-
-
-
-int
-NDBT_TestSuite::report(const char* _tcname){
- int result;
- ndbout << "Completed " << name << " [" << getDate() << "]" << endl;
- printTestCaseSummary(_tcname);
- ndbout << numTestsExecuted << " test(s) executed" << endl;
- ndbout << numTestsOk << " test(s) OK"
- << endl;
- if(numTestsFail > 0)
- ndbout << numTestsFail << " test(s) failed"
- << endl;
- testSuiteTimer.printTotalTime();
- if (numTestsFail > 0 || numTestsExecuted == 0){
- result = NDBT_FAILED;
- }else{
- result = NDBT_OK;
- }
- return result;
-}
-
-void NDBT_TestSuite::printTestCaseSummary(const char* _tcname){
- ndbout << "= SUMMARY OF TEST EXECUTION ==============" << endl;
- for (unsigned t = 0; t < tests.size(); t++){
- if (_tcname != NULL &&
- strcasecmp(tests[t]->getName(), _tcname) != 0)
- continue;
-
- tests[t]->printTestResult();
- }
- ndbout << "==========================================" << endl;
-}
-
-int NDBT_TestSuite::reportAllTables(const char* _testname){
- int result;
- ndbout << "Completed running test [" << getDate() << "]" << endl;
- const int totalNumTests = numTestsExecuted;
- printTestCaseSummary(_testname);
- ndbout << numTestsExecuted<< " test(s) executed" << endl;
- ndbout << numTestsOk << " test(s) OK("
- <<(int)(((float)numTestsOk/totalNumTests)*100.0) <<"%)"
- << endl;
- if(numTestsFail > 0)
- ndbout << numTestsFail << " test(s) failed("
- <<(int)(((float)numTestsFail/totalNumTests)*100.0) <<"%)"
- << endl;
- testSuiteTimer.printTotalTime();
- if (numTestsExecuted > 0){
- if (numTestsFail > 0){
- result = NDBT_FAILED;
- }else{
- result = NDBT_OK;
- }
- } else {
- result = NDBT_FAILED;
- }
- return result;
-}
-
-enum test_options {
- OPT_INTERACTIVE = NDB_STD_OPTIONS_LAST,
- OPT_PRINT,
- OPT_PRINT_HTML,
- OPT_PRINT_CASES
-
-};
-NDB_STD_OPTS_VARS;
-
-static int opt_print = false;
-static int opt_print_html = false;
-static int opt_print_cases = false;
-static int opt_records;
-static int opt_loops;
-static int opt_timer;
-static char * opt_remote_mgm = NULL;
-static char * opt_testname = NULL;
-static int opt_verbose;
-static int opt_seed = 0;
-
-static struct my_option my_long_options[] =
-{
- NDB_STD_OPTS(""),
- { "print", OPT_PRINT, "Print execution tree",
- &opt_print, &opt_print, 0,
- GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
- { "print_html", OPT_PRINT_HTML, "Print execution tree in html table format",
- &opt_print_html, &opt_print_html, 0,
- GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
- { "print_cases", OPT_PRINT_CASES, "Print list of test cases",
- &opt_print_cases, &opt_print_cases, 0,
- GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
- { "records", 'r', "Number of records",
- &opt_records, &opt_records, 0,
- GET_INT, REQUIRED_ARG, 1000, 0, 0, 0, 0, 0 },
- { "loops", 'l', "Number of loops",
- &opt_loops, &opt_loops, 0,
- GET_INT, REQUIRED_ARG, 5, 0, 0, 0, 0, 0 },
- { "seed", 1024, "Random seed",
- &opt_seed, &opt_seed, 0,
- GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
- { "testname", 'n', "Name of test to run",
- &opt_testname, &opt_testname, 0,
- GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
- { "remote_mgm", 'm',
- "host:port to mgmsrv of remote cluster",
- &opt_remote_mgm, &opt_remote_mgm, 0,
- GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
- { "timer", 't', "Print execution time",
- &opt_timer, &opt_timer, 0,
- GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
- { "verbose", 'v', "Print verbose status",
- &opt_verbose, &opt_verbose, 0,
- GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
- { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
-};
-
-extern int global_flag_skip_invalidate_cache;
-
-static void usage()
-{
- ndb_std_print_version();
- printf("Usage: %s [OPTIONS] [tabname1 tabname2 ... tabnameN]\n", my_progname);
- my_print_help(my_long_options);
- my_print_variables(my_long_options);
-}
-
-int NDBT_TestSuite::execute(int argc, const char** argv){
- int res = NDBT_FAILED;
- /* Arguments:
- Run only a subset of tests
- -n testname Which test to run
- Recommendations to test functions:
- --records Number of records to use(default: 10000)
- --loops Number of loops to execute in the test(default: 100)
-
- Other parameters should:
- * be calculated from the above two parameters
- * be divided into different test cases, ex. one testcase runs
- with FragmentType = Single and another perfoms the same
- test with FragmentType = Large
- * let the test case iterate over all/subset of appropriate parameters
- ex. iterate over FragmentType = Single to FragmentType = AllLarge
-
- Remeber that the intention is that it should be _easy_ to run
- a complete test suite without any greater knowledge of what
- should be tested ie. keep arguments at a minimum
- */
-
- char **_argv= (char **)argv;
-
- if (!my_progname)
- my_progname= _argv[0];
-
- const char *load_default_groups[]= { "mysql_cluster",0 };
- load_defaults("my",load_default_groups,&argc,&_argv);
-
- int ho_error;
-#ifndef DBUG_OFF
- opt_debug= "d:t:i:F:L";
-#endif
- if ((ho_error=handle_options(&argc, &_argv, my_long_options,
- ndb_std_get_one_option)))
- {
- usage();
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- if (opt_print == true){
- printExecutionTree();
- return 0;
- }
-
- if (opt_print_html == true){
- printExecutionTreeHTML();
- return 0;
- }
-
- if (opt_print_cases == true){
- printCases();
- return 0;
- }
-
- if (opt_verbose)
- setOutputLevel(2); // Show g_info
- else
- setOutputLevel(0); // Show only g_err ?
-
- remote_mgm = opt_remote_mgm;
- records = opt_records;
- loops = opt_loops;
- timer = opt_timer;
-
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1))
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- if (opt_seed == 0)
- {
- opt_seed = NdbTick_CurrentMillisecond();
- }
- ndbout_c("random seed: %u", opt_seed);
- srand(opt_seed);
- srandom(opt_seed);
-
- global_flag_skip_invalidate_cache = 1;
-
- {
- Ndb ndb(&con, "TEST_DB");
- ndb.init(1024);
- if (ndb.waitUntilReady(500)){
- g_err << "Ndb was not ready" << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- NdbDictionary::Dictionary* pDict = ndb.getDictionary();
-
- int num_tables= argc;
- if (argc == 0)
- num_tables = NDBT_Tables::getNumTables();
-
- for(int i = 0; i<num_tables; i++)
- {
- if (argc == 0)
- m_tables_in_test.push_back(NDBT_Tables::getTable(i)->getName());
- else
- m_tables_in_test.push_back(_argv[i]);
- if (createAllTables == true)
- {
- const char *tab_name= m_tables_in_test[i].c_str();
- const NdbDictionary::Table* pTab = pDict->getTable(tab_name);
- if (pTab && pDict->dropTable(tab_name) != 0)
- {
- g_err << "ERROR0: Failed to drop table " << tab_name
- << pDict->getNdbError() << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- if(NDBT_Tables::createTable(&ndb, tab_name) != 0)
- {
- g_err << "ERROR1: Failed to create table " << tab_name
- << pDict->getNdbError() << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- }
- }
- }
-
- if(argc == 0){
- // No table specified
- res = executeAll(con, opt_testname);
- } else {
- testSuiteTimer.doStart();
- for(int i = 0; i<argc; i++){
- executeOne(con, _argv[i], opt_testname);
- }
- testSuiteTimer.doStop();
- res = report(opt_testname);
- }
-
- if (res == NDBT_OK && createAllTables == true)
- {
- Ndb ndb(&con, "TEST_DB");
- ndb.init(1024);
- if (ndb.waitUntilReady(500)){
- g_err << "Ndb was not ready" << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- NdbDictionary::Dictionary* pDict = ndb.getDictionary();
- for(unsigned i = 0; i<m_tables_in_test.size(); i++)
- {
- pDict->dropTable(m_tables_in_test[i].c_str());
- }
- }
-
- return NDBT_ProgramExit(res);
-}
-
-
-
-void NDBT_TestSuite::printExecutionTree(){
- ndbout << "Testsuite: " << name << endl;
- for (unsigned t = 0; t < tests.size(); t++){
- tests[t]->print();
- ndbout << endl;
- }
-}
-
-void NDBT_TestSuite::printExecutionTreeHTML(){
- ndbout << "<tr>" << endl;
- ndbout << "<td><h3>" << name << "</h3></td>" << endl;
- ndbout << "</tr>" << endl;
- for (unsigned t = 0; t < tests.size(); t++){
- tests[t]->printHTML();
- ndbout << endl;
- }
-
-}
-
-void NDBT_TestSuite::printCases(){
- ndbout << "# Testsuite: " << name << endl;
- ndbout << "# Number of tests: " << tests.size() << endl;
- for (unsigned t = 0; t < tests.size(); t++){
- ndbout << name << " -n " << tests[t]->getName() << endl;
- }
-}
-
-const char* NDBT_TestSuite::getDate(){
- static char theTime[128];
- struct tm* tm_now;
- time_t now;
- now = time((time_t*)NULL);
-#ifdef NDB_WIN32
- tm_now = localtime(&now);
-#else
- tm_now = gmtime(&now);
-#endif
-
- BaseString::snprintf(theTime, 128,
- "%d-%.2d-%.2d %.2d:%.2d:%.2d",
- tm_now->tm_year + 1900,
- tm_now->tm_mon + 1,
- tm_now->tm_mday,
- tm_now->tm_hour,
- tm_now->tm_min,
- tm_now->tm_sec);
-
- return theTime;
-}
-
-void NDBT_TestCaseImpl1::printHTML(){
-
- ndbout << "<tr><td>&nbsp;</td>" << endl;
- ndbout << "<td name=tc>" << endl << name << "</td><td width=70%>"
- << comment << "</td></tr>" << endl;
-}
-
-void NDBT_TestCaseImpl1::print(){
- ndbout << "Test case: " << name << endl;
- ndbout << "Description: "<< comment << endl;
-
- ndbout << "Parameters: " << endl;
-
- Properties::Iterator it(&props);
- for(const char * key = it.first(); key != 0; key = it.next()){
- PropertiesType pt;
- const bool b = props.getTypeOf(key, &pt);
- assert(b == true);
- switch(pt){
- case PropertiesType_Uint32:{
- Uint32 val;
- props.get(key, &val);
- ndbout << " " << key << ": " << val << endl;
- break;
- }
- case PropertiesType_char:{
- const char * val;
- props.get(key, &val);
- ndbout << " " << key << ": " << val << endl;
- break;
- }
- default:
- abort();
- }
- }
- unsigned i;
- for(i=0; i<initializers.size(); i++){
- ndbout << "Initializers[" << i << "]: " << endl;
- initializers[i]->print();
- }
- for(i=0; i<steps.size(); i++){
- ndbout << "Step[" << i << "]: " << endl;
- steps[i]->print();
- }
- for(i=0; i<verifiers.size(); i++){
- ndbout << "Verifier[" << i << "]: " << endl;
- verifiers[i]->print();
- }
- for(i=0; i<finalizers.size(); i++){
- ndbout << "Finalizer[" << i << "]: " << endl;
- finalizers[i]->print();
- }
-
-}
-
-void NDBT_Step::print(){
- ndbout << " "<< name << endl;
-
-}
-
-void
-NDBT_Context::sync_down(const char * key){
- Uint32 threads = getProperty(key, (unsigned)0);
- if(threads){
- decProperty(key);
- }
-}
-
-void
-NDBT_Context::sync_up_and_wait(const char * key, Uint32 value){
- setProperty(key, value);
- getPropertyWait(key, (unsigned)0);
-}
-
-template class Vector<NDBT_TestCase*>;
-template class Vector<NDBT_TestCaseResult*>;
-template class Vector<NDBT_Step*>;
-template class Vector<NdbThread*>;
-template class Vector<NDBT_Verifier*>;
-template class Vector<NDBT_Initializer*>;
-template class Vector<NDBT_Finalizer*>;
-template class Vector<const NdbDictionary::Table*>;
diff --git a/storage/ndb/test/src/NDBT_Thread.cpp b/storage/ndb/test/src/NDBT_Thread.cpp
deleted file mode 100644
index 1f4d46aeb1b..00000000000
--- a/storage/ndb/test/src/NDBT_Thread.cpp
+++ /dev/null
@@ -1,284 +0,0 @@
-/* Copyright (c) 2003, 2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-#include <NDBT_Thread.hpp>
-#include <NdbApi.hpp>
-
-NDBT_Thread::NDBT_Thread()
-{
- create(0, -1);
-}
-
-NDBT_Thread::NDBT_Thread(NDBT_ThreadSet* thread_set, int thread_no)
-{
- create(thread_set, thread_no);
-}
-
-void
-NDBT_Thread::create(NDBT_ThreadSet* thread_set, int thread_no)
-{
- m_magic = NDBT_Thread::Magic;
-
- m_state = Wait;
- m_thread_set = thread_set;
- m_thread_no = thread_no;
- m_func = 0;
- m_input = 0;
- m_output = 0;
- m_ndb = 0;
- m_err = 0;
-
- m_mutex = NdbMutex_Create();
- assert(m_mutex != 0);
- m_cond = NdbCondition_Create();
- assert(m_cond != 0);
-
- char buf[20];
- sprintf(buf, "NDBT_%04u");
- const char* name = strdup(buf);
- assert(name != 0);
-
- unsigned stacksize = 512 * 1024;
- NDB_THREAD_PRIO prio = NDB_THREAD_PRIO_LOW;
- m_thread = NdbThread_Create(NDBT_Thread_run,
- (void**)this, stacksize, name, prio);
- assert(m_thread != 0);
-}
-
-NDBT_Thread::~NDBT_Thread()
-{
- if (m_thread != 0) {
- NdbThread_Destroy(&m_thread);
- m_thread = 0;
- }
- if (m_cond != 0) {
- NdbCondition_Destroy(m_cond);
- m_cond = 0;
- }
- if (m_mutex != 0) {
- NdbMutex_Destroy(m_mutex);
- m_mutex = 0;
- }
-}
-
-static void*
-NDBT_Thread_run(void* arg)
-{
- assert(arg != 0);
- NDBT_Thread& thr = *(NDBT_Thread*)arg;
- assert(thr.m_magic == NDBT_Thread::Magic);
- thr.run();
- return 0;
-}
-
-void
-NDBT_Thread::run()
-{
- while (1) {
- lock();
- while (m_state != Start && m_state != Exit) {
- wait();
- }
- if (m_state == Exit) {
- unlock();
- break;
- }
- (*m_func)(*this);
- m_state = Stop;
- signal();
- unlock();
- }
-}
-
-// methods for main process
-
-void
-NDBT_Thread::start()
-{
- lock();
- m_state = Start;
- signal();
- unlock();
-}
-
-void
-NDBT_Thread::stop()
-{
- lock();
- while (m_state != Stop)
- wait();
- m_state = Wait;
- unlock();
-}
-
-void
-NDBT_Thread::exit()
-{
- lock();
- m_state = Exit;
- signal();
- unlock();
-}
-
-void
-NDBT_Thread::join()
-{
- NdbThread_WaitFor(m_thread, &m_status);
- m_thread = 0;
-}
-
-int
-NDBT_Thread::connect(class Ndb_cluster_connection* ncc, const char* db)
-{
- m_ndb = new Ndb(ncc, db);
- if (m_ndb->init() == -1 ||
- m_ndb->waitUntilReady() == -1) {
- m_err = m_ndb->getNdbError().code;
- return -1;
- }
- return 0;
-}
-
-void
-NDBT_Thread::disconnect()
-{
- delete m_ndb;
- m_ndb = 0;
-}
-
-// set of threads
-
-NDBT_ThreadSet::NDBT_ThreadSet(int count)
-{
- m_count = count;
- m_thread = new NDBT_Thread* [count];
- for (int n = 0; n < count; n++) {
- m_thread[n] = new NDBT_Thread(this, n);
- }
-}
-
-NDBT_ThreadSet::~NDBT_ThreadSet()
-{
- delete_output();
- for (int n = 0; n < m_count; n++) {
- delete m_thread[n];
- m_thread[n] = 0;
- }
- delete [] m_thread;
-}
-
-void
-NDBT_ThreadSet::start()
-{
- for (int n = 0; n < m_count; n++) {
- NDBT_Thread& thr = *m_thread[n];
- thr.start();
- }
-}
-
-void
-NDBT_ThreadSet::stop()
-{
- for (int n = 0; n < m_count; n++) {
- NDBT_Thread& thr = *m_thread[n];
- thr.stop();
- }
-}
-
-void
-NDBT_ThreadSet::exit()
-{
- for (int n = 0; n < m_count; n++) {
- NDBT_Thread& thr = *m_thread[n];
- thr.exit();
- }
-}
-
-void
-NDBT_ThreadSet::join()
-{
- for (int n = 0; n < m_count; n++) {
- NDBT_Thread& thr = *m_thread[n];
- thr.join();
- }
-}
-
-void
-NDBT_ThreadSet::set_func(NDBT_ThreadFunc* func)
-{
- for (int n = 0; n < m_count; n++) {
- NDBT_Thread& thr = *m_thread[n];
- thr.set_func(func);
- }
-}
-
-void
-NDBT_ThreadSet::set_input(const void* input)
-{
- for (int n = 0; n < m_count; n++) {
- NDBT_Thread& thr = *m_thread[n];
- thr.set_input(input);
- }
-}
-
-void
-NDBT_ThreadSet::delete_output()
-{
- for (int n = 0; n < m_count; n++) {
- if (m_thread[n] != 0) {
- NDBT_Thread& thr = *m_thread[n];
- thr.delete_output();
- }
- }
-}
-
-int
-NDBT_ThreadSet::connect(class Ndb_cluster_connection* ncc, const char* db)
-{
- for (int n = 0; n < m_count; n++) {
- assert(m_thread[n] != 0);
- NDBT_Thread& thr = *m_thread[n];
- if (thr.connect(ncc, db) == -1)
- return -1;
- }
- return 0;
-}
-
-void
-NDBT_ThreadSet::disconnect()
-{
- for (int n = 0; n < m_count; n++) {
- if (m_thread[n] != 0) {
- NDBT_Thread& thr = *m_thread[n];
- thr.disconnect();
- }
- }
-}
-
-int
-NDBT_ThreadSet::get_err() const
-{
- for (int n = 0; n < m_count; n++) {
- if (m_thread[n] != 0) {
- NDBT_Thread& thr = *m_thread[n];
- int err = thr.get_err();
- if (err != 0)
- return err;
- }
- }
- return 0;
-}
diff --git a/storage/ndb/test/src/NdbBackup.cpp b/storage/ndb/test/src/NdbBackup.cpp
deleted file mode 100644
index 98048c5df77..00000000000
--- a/storage/ndb/test/src/NdbBackup.cpp
+++ /dev/null
@@ -1,452 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <signaldata/DumpStateOrd.hpp>
-#include <NdbBackup.hpp>
-#include <NdbOut.hpp>
-#include <NDBT_Output.hpp>
-#include <NdbConfig.h>
-#include <ndb_version.h>
-#include <NDBT.hpp>
-#include <NdbSleep.h>
-#include <random.h>
-#include <NdbTick.h>
-
-#define CHECK(b, m) { int _xx = b; if (!(_xx)) { \
- ndbout << "ERR: "<< m \
- << " " << "File: " << __FILE__ \
- << " (Line: " << __LINE__ << ")" << "- " << _xx << endl; \
- return NDBT_FAILED; } }
-
-#include <ConfigRetriever.hpp>
-#include <mgmapi.h>
-#include <mgmapi_config_parameters.h>
-#include <mgmapi_configuration.hpp>
-
-int
-NdbBackup::start(unsigned int & _backup_id){
-
-
- if (!isConnected())
- return -1;
-
- ndb_mgm_reply reply;
- reply.return_code = 0;
-
- if (ndb_mgm_start_backup(handle,
- 2, // wait until completed
- &_backup_id,
- &reply) == -1) {
- g_err << "Error: " << ndb_mgm_get_latest_error(handle) << endl;
- g_err << "Error msg: " << ndb_mgm_get_latest_error_msg(handle) << endl;
- g_err << "Error desc: " << ndb_mgm_get_latest_error_desc(handle) << endl;
- return -1;
- }
-
- if(reply.return_code != 0){
- g_err << "PLEASE CHECK CODE NdbBackup.cpp line=" << __LINE__ << endl;
- g_err << "Error: " << ndb_mgm_get_latest_error(handle) << endl;
- g_err << "Error msg: " << ndb_mgm_get_latest_error_msg(handle) << endl;
- g_err << "Error desc: " << ndb_mgm_get_latest_error_desc(handle) << endl;
- return reply.return_code;
- }
- return 0;
-}
-
-
-const char *
-NdbBackup::getBackupDataDirForNode(int _node_id){
-
- /**
- * Fetch configuration from management server
- */
- ndb_mgm_configuration *p;
- if (connect())
- return NULL;
-
- if ((p = ndb_mgm_get_configuration(handle, 0)) == 0)
- {
- const char * s= ndb_mgm_get_latest_error_msg(handle);
- if(s == 0)
- s = "No error given!";
-
- ndbout << "Could not fetch configuration" << endl;
- ndbout << s << endl;
- return NULL;
- }
-
- /**
- * Setup cluster configuration data
- */
- ndb_mgm_configuration_iterator iter(* p, CFG_SECTION_NODE);
- if (iter.find(CFG_NODE_ID, _node_id)){
- ndbout << "Invalid configuration fetched, DB missing" << endl;
- return NULL;
- }
-
- unsigned int type = NODE_TYPE_DB + 1;
- if(iter.get(CFG_TYPE_OF_SECTION, &type) || type != NODE_TYPE_DB){
- ndbout <<"type = " << type << endl;
- ndbout <<"Invalid configuration fetched, I'm wrong type of node" << endl;
- return NULL;
- }
-
- const char * path;
- if (iter.get(CFG_DB_BACKUP_DATADIR, &path)){
- ndbout << "BackupDataDir not found" << endl;
- return NULL;
- }
-
- return path;
-
-}
-
-int
-NdbBackup::execRestore(bool _restore_data,
- bool _restore_meta,
- int _node_id,
- unsigned _backup_id){
- const int buf_len = 1000;
- char buf[buf_len];
-
- ndbout << "getBackupDataDir "<< _node_id <<endl;
-
- const char* path = getBackupDataDirForNode(_node_id);
- if (path == NULL)
- return -1;
-
- ndbout << "getHostName "<< _node_id <<endl;
- const char *host;
- if (!getHostName(_node_id, &host)){
- return -1;
- }
-
- /*
- * Copy backup files to local dir
- */
-
- BaseString::snprintf(buf, buf_len,
- "scp %s:%s/BACKUP/BACKUP-%d/BACKUP-%d*.%d.* .",
- host, path,
- _backup_id,
- _backup_id,
- _node_id);
-
- ndbout << "buf: "<< buf <<endl;
- int res = system(buf);
-
- ndbout << "scp res: " << res << endl;
-
- BaseString::snprintf(buf, 255, "%sndb_restore -c \"%s:%d\" -n %d -b %d %s %s .",
-#if 1
- "",
-#else
- "valgrind --leak-check=yes -v "
-#endif
- ndb_mgm_get_connected_host(handle),
- ndb_mgm_get_connected_port(handle),
- _node_id,
- _backup_id,
- _restore_data?"-r":"",
- _restore_meta?"-m":"");
-
- ndbout << "buf: "<< buf <<endl;
- res = system(buf);
-
- ndbout << "ndb_restore res: " << res << endl;
-
- return res;
-
-}
-
-int
-NdbBackup::restore(unsigned _backup_id){
-
- if (!isConnected())
- return -1;
-
- if (getStatus() != 0)
- return -1;
-
- int res;
-
- // restore metadata first and data for first node
- res = execRestore(true, true, ndbNodes[0].node_id, _backup_id);
-
- // Restore data once for each node
- for(size_t i = 1; i < ndbNodes.size(); i++){
- res = execRestore(true, false, ndbNodes[i].node_id, _backup_id);
- }
-
- return 0;
-}
-
-// Master failure
-int
-NFDuringBackupM_codes[] = {
- 10003,
- 10004,
- 10007,
- 10008,
- 10009,
- 10010,
- 10012,
- 10013
-};
-
-// Slave failure
-int
-NFDuringBackupS_codes[] = {
- 10014,
- 10015,
- 10016,
- 10017,
- 10018,
- 10020
-};
-
-// Master takeover etc...
-int
-NFDuringBackupSL_codes[] = {
- 10001,
- 10002,
- 10021
-};
-
-int
-NdbBackup::NFMaster(NdbRestarter& _restarter){
- const int sz = sizeof(NFDuringBackupM_codes)/sizeof(NFDuringBackupM_codes[0]);
- return NF(_restarter, NFDuringBackupM_codes, sz, true);
-}
-
-int
-NdbBackup::NFMasterAsSlave(NdbRestarter& _restarter){
- const int sz = sizeof(NFDuringBackupS_codes)/sizeof(NFDuringBackupS_codes[0]);
- return NF(_restarter, NFDuringBackupS_codes, sz, true);
-}
-
-int
-NdbBackup::NFSlave(NdbRestarter& _restarter){
- const int sz = sizeof(NFDuringBackupS_codes)/sizeof(NFDuringBackupS_codes[0]);
- return NF(_restarter, NFDuringBackupS_codes, sz, false);
-}
-
-int
-NdbBackup::NF(NdbRestarter& _restarter, int *NFDuringBackup_codes, const int sz, bool onMaster){
- int nNodes = _restarter.getNumDbNodes();
- {
- if(nNodes == 1)
- return NDBT_OK;
-
- int nodeId = _restarter.getMasterNodeId();
-
- CHECK(_restarter.restartOneDbNode(nodeId, false, true, true) == 0,
- "Could not restart node "<< nodeId);
-
- CHECK(_restarter.waitNodesNoStart(&nodeId, 1) == 0,
- "waitNodesNoStart failed");
-
- CHECK(_restarter.startNodes(&nodeId, 1) == 0,
- "failed to start node");
- }
-
- CHECK(_restarter.waitClusterStarted() == 0,
- "waitClusterStarted failed");
-
- myRandom48Init(NdbTick_CurrentMillisecond());
-
- for(int i = 0; i<sz; i++){
-
- int error = NFDuringBackup_codes[i];
- unsigned int backupId;
-
- const int masterNodeId = _restarter.getMasterNodeId();
- CHECK(masterNodeId > 0, "getMasterNodeId failed");
- int nodeId;
-
- nodeId = masterNodeId;
- if (!onMaster) {
- int randomId;
- while (nodeId == masterNodeId) {
- randomId = myRandom48(nNodes);
- nodeId = _restarter.getDbNodeId(randomId);
- }
- }
-
- g_err << "NdbBackup::NF node = " << nodeId
- << " error code = " << error << " masterNodeId = "
- << masterNodeId << endl;
-
-
- int val[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
- CHECK(_restarter.dumpStateOneNode(nodeId, val, 2) == 0,
- "failed to set RestartOnErrorInsert");
- CHECK(_restarter.insertErrorInNode(nodeId, error) == 0,
- "failed to set error insert");
-
- g_info << "error inserted" << endl;
- NdbSleep_SecSleep(1);
-
- g_info << "starting backup" << endl;
- int r = start(backupId);
- g_info << "r = " << r
- << " (which should fail) started with id = " << backupId << endl;
- if (r == 0) {
- g_err << "Backup should have failed on error_insertion " << error << endl
- << "Master = " << masterNodeId << "Node = " << nodeId << endl;
- return NDBT_FAILED;
- }
-
- CHECK(_restarter.waitNodesNoStart(&nodeId, 1) == 0,
- "waitNodesNoStart failed");
-
- g_info << "number of nodes running " << _restarter.getNumDbNodes() << endl;
-
- if (_restarter.getNumDbNodes() != nNodes) {
- g_err << "Failure: cluster not up" << endl;
- return NDBT_FAILED;
- }
-
- g_info << "starting new backup" << endl;
- CHECK(start(backupId) == 0,
- "failed to start backup");
- g_info << "(which should succeed) started with id = " << backupId << endl;
-
- g_info << "starting node" << endl;
- CHECK(_restarter.startNodes(&nodeId, 1) == 0,
- "failed to start node");
-
- CHECK(_restarter.waitClusterStarted() == 0,
- "waitClusterStarted failed");
- g_info << "node started" << endl;
-
- int val2[] = { 24, 2424 };
- CHECK(_restarter.dumpStateAllNodes(val2, 2) == 0,
- "failed to check backup resources RestartOnErrorInsert");
-
- CHECK(_restarter.insertErrorInNode(nodeId, 10099) == 0,
- "failed to set error insert");
-
- NdbSleep_SecSleep(1);
- }
-
- return NDBT_OK;
-}
-
-int
-FailS_codes[] = {
- 10025,
- 10027,
- 10033,
- 10035,
- 10036
-};
-
-int
-FailM_codes[] = {
- 10023,
- 10024,
- 10025,
- 10026,
- 10027,
- 10028,
- 10031,
- 10033,
- 10035
-};
-
-int
-NdbBackup::FailMaster(NdbRestarter& _restarter){
- const int sz = sizeof(FailM_codes)/sizeof(FailM_codes[0]);
- return Fail(_restarter, FailM_codes, sz, true);
-}
-
-int
-NdbBackup::FailMasterAsSlave(NdbRestarter& _restarter){
- const int sz = sizeof(FailS_codes)/sizeof(FailS_codes[0]);
- return Fail(_restarter, FailS_codes, sz, true);
-}
-
-int
-NdbBackup::FailSlave(NdbRestarter& _restarter){
- const int sz = sizeof(FailS_codes)/sizeof(FailS_codes[0]);
- return Fail(_restarter, FailS_codes, sz, false);
-}
-
-int
-NdbBackup::Fail(NdbRestarter& _restarter, int *Fail_codes, const int sz, bool onMaster){
-
- CHECK(_restarter.waitClusterStarted() == 0,
- "waitClusterStarted failed");
-
- int nNodes = _restarter.getNumDbNodes();
-
- myRandom48Init(NdbTick_CurrentMillisecond());
-
- for(int i = 0; i<sz; i++){
- int error = Fail_codes[i];
- unsigned int backupId;
-
- const int masterNodeId = _restarter.getMasterNodeId();
- CHECK(masterNodeId > 0, "getMasterNodeId failed");
- int nodeId;
-
- nodeId = masterNodeId;
- if (!onMaster) {
- int randomId;
- while (nodeId == masterNodeId) {
- randomId = myRandom48(nNodes);
- nodeId = _restarter.getDbNodeId(randomId);
- }
- }
-
- g_err << "NdbBackup::Fail node = " << nodeId
- << " error code = " << error << " masterNodeId = "
- << masterNodeId << endl;
-
- CHECK(_restarter.insertErrorInNode(nodeId, error) == 0,
- "failed to set error insert");
-
- g_info << "error inserted" << endl;
- g_info << "waiting some before starting backup" << endl;
-
- g_info << "starting backup" << endl;
- int r = start(backupId);
- g_info << "r = " << r
- << " (which should fail) started with id = " << backupId << endl;
- if (r == 0) {
- g_err << "Backup should have failed on error_insertion " << error << endl
- << "Master = " << masterNodeId << "Node = " << nodeId << endl;
- return NDBT_FAILED;
- }
-
- CHECK(_restarter.waitClusterStarted() == 0,
- "waitClusterStarted failed");
-
- CHECK(_restarter.insertErrorInNode(nodeId, 10099) == 0,
- "failed to set error insert");
-
- NdbSleep_SecSleep(5);
-
- int val2[] = { 24, 2424 };
- CHECK(_restarter.dumpStateAllNodes(val2, 2) == 0,
- "failed to check backup resources RestartOnErrorInsert");
-
- }
-
- return NDBT_OK;
-}
-
diff --git a/storage/ndb/test/src/NdbConfig.cpp b/storage/ndb/test/src/NdbConfig.cpp
deleted file mode 100644
index 5743896ef64..00000000000
--- a/storage/ndb/test/src/NdbConfig.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include "NdbConfig.hpp"
-#include <NdbOut.hpp>
-#include <NDBT_Output.hpp>
-#include <assert.h>
-#include <NdbConfig.h>
-#include <ConfigRetriever.hpp>
-#include <ndb_version.h>
-#include <mgmapi.h>
-#include <mgmapi_config_parameters.h>
-#include <mgmapi_configuration.hpp>
-
-bool
-NdbConfig::getHostName(unsigned int node_id, const char ** hostname) {
-
- ndb_mgm_configuration * p = getConfig();
- if(p == 0){
- return false;
- }
-
- /**
- * Setup cluster configuration data
- */
- ndb_mgm_configuration_iterator iter(* p, CFG_SECTION_NODE);
- if (iter.find(CFG_NODE_ID, node_id)){
- ndbout << "Invalid configuration fetched, DB missing" << endl;
- return false;
- }
-
- if (iter.get(CFG_NODE_HOST, hostname)){
- ndbout << "Host not found" << endl;
- return false;
- }
-
- return true;
-}
-
-bool
-NdbConfig::getProperty(unsigned nodeid,
- unsigned type, unsigned key, Uint32 * val){
- ndb_mgm_configuration * p = getConfig();
- if(p == 0){
- return false;
- }
-
- /**
- * Setup cluster configuration data
- */
- ndb_mgm_configuration_iterator iter(* p, CFG_SECTION_NODE);
- if (iter.find(CFG_NODE_ID, nodeid)){
- ndbout << "Invalid configuration fetched, DB missing" << endl;
- return false;
- }
-
- unsigned _type;
- if (iter.get(CFG_TYPE_OF_SECTION, &_type) || type != _type){
- ndbout << "No such node in configuration" << endl;
- return false;
- }
-
- if (iter.get(key, val)){
- ndbout << "No such key: " << key << " in configuration" << endl;
- return false;
- }
-
- return true;
-}
-
diff --git a/storage/ndb/test/src/NdbGrep.cpp b/storage/ndb/test/src/NdbGrep.cpp
deleted file mode 100644
index 3ae82728bc5..00000000000
--- a/storage/ndb/test/src/NdbGrep.cpp
+++ /dev/null
@@ -1,333 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <signaldata/DumpStateOrd.hpp>
-#include <NdbGrep.hpp>
-#include <NdbOut.hpp>
-#include <NDBT_Output.hpp>
-#include <NdbConfig.h>
-#include <ConfigRetriever.hpp>
-#include <ndb_version.h>
-#include <NDBT.hpp>
-#include <NdbSleep.h>
-#include <random.h>
-#include <NdbTick.h>
-
-#define CHECK(b, m) { int _xx = b; if (!(_xx)) { \
- ndbout << "ERR: "<< m \
- << " " << "File: " << __FILE__ \
- << " (Line: " << __LINE__ << ")" << "- " << _xx << endl; \
- return NDBT_FAILED; } }
-
-
-int
-NdbGrep::start(){
-
- return 1;
-}
-
-int
-NdbGrep::stop(){
-
- return 1;
-}
-
-
-int
-NdbGrep::query(){
-
- return 1;
-}
-
-
-int
-NdbGrep::verify(NDBT_Context * ctx){
-
- if (!isConnected())
- return -1;
-
- char cheat_table[255];
- BaseString::snprintf(cheat_table, 255, "TEST_DB/def/%s",ctx->getTab()->getName());
-
- char buf[255];
- BaseString::snprintf(buf, 255, "testGrepVerify -c \"nodeid=%d;host=%s\" -t %s -r %d",
- 4, //cheat. Hardcoded nodeid....
- ctx->getRemoteMgm(),
- cheat_table,
- ctx->getNumRecords());
-
-
- ndbout << "buf: "<< buf <<endl;
- int res = system(buf);
-
- ndbout << "res: " << res << endl;
-
- return res;
-
-
-
-
-}
-
-
-// Master failure
-int
-NFDuringGrepM_codes[] = {
- 10003,
- 10004,
- 10005,
- 10007,
- 10008,
- 10009,
- 10010,
- 10012,
- 10013
-};
-
-// Slave failure
-int
-NFDuringGrepS_codes[] = {
- 10014,
- 10015,
- 10016,
- 10017,
- 10018,
- 10020
-};
-
-// Master takeover etc...
-int
-NFDuringGrepSL_codes[] = {
- 10001,
- 10002,
- 10021
-};
-
-int
-NdbGrep::NFMaster(NdbRestarter& _restarter){
- const int sz = sizeof(NFDuringGrepM_codes)/sizeof(NFDuringGrepM_codes[0]);
- return NF(_restarter, NFDuringGrepM_codes, sz, true);
-}
-
-int
-NdbGrep::NFMasterAsSlave(NdbRestarter& _restarter){
- const int sz = sizeof(NFDuringGrepS_codes)/sizeof(NFDuringGrepS_codes[0]);
- return NF(_restarter, NFDuringGrepS_codes, sz, true);
-}
-
-int
-NdbGrep::NFSlave(NdbRestarter& _restarter){
- const int sz = sizeof(NFDuringGrepS_codes)/sizeof(NFDuringGrepS_codes[0]);
- return NF(_restarter, NFDuringGrepS_codes, sz, false);
-}
-
-int
-NdbGrep::NF(NdbRestarter& _restarter, int *NFDuringGrep_codes, const int sz, bool onMaster){
- {
- int nodeId = _restarter.getMasterNodeId();
-
- CHECK(_restarter.restartOneDbNode(nodeId, false, true, true) == 0,
- "Could not restart node "<< nodeId);
-
- CHECK(_restarter.waitNodesNoStart(&nodeId, 1) == 0,
- "waitNodesNoStart failed");
-
- CHECK(_restarter.startNodes(&nodeId, 1) == 0,
- "failed to start node");
-
- NdbSleep_SecSleep(10);
- }
-
- CHECK(_restarter.waitClusterStarted() == 0,
- "waitClusterStarted failed");
-
- int nNodes = _restarter.getNumDbNodes();
-
- myRandom48Init(NdbTick_CurrentMillisecond());
-
- for(int i = 0; i<sz; i++){
-
- int error = NFDuringGrep_codes[i];
- unsigned int backupId;
-
- const int masterNodeId = _restarter.getMasterNodeId();
- CHECK(masterNodeId > 0, "getMasterNodeId failed");
- int nodeId;
-
- nodeId = masterNodeId;
- if (!onMaster) {
- int randomId;
- while (nodeId == masterNodeId) {
- randomId = myRandom48(nNodes);
- nodeId = _restarter.getDbNodeId(randomId);
- }
- }
-
- g_err << "NdbGrep::NF node = " << nodeId
- << " error code = " << error << " masterNodeId = "
- << masterNodeId << endl;
-
-
- int val = DumpStateOrd::CmvmiSetRestartOnErrorInsert;
- CHECK(_restarter.dumpStateOneNode(nodeId, &val, 1) == 0,
- "failed to set RestartOnErrorInsert");
- CHECK(_restarter.insertErrorInNode(nodeId, error) == 0,
- "failed to set error insert");
-
- g_info << "error inserted" << endl;
-
- g_info << "starting backup" << endl;
- int r = start();
- g_info << "r = " << r
- << " (which should fail) started with id = " << backupId << endl;
- if (r == 0) {
- g_err << "Grep should have failed on error_insertion " << error << endl
- << "Master = " << masterNodeId << "Node = " << nodeId << endl;
- }
-
- CHECK(_restarter.waitNodesNoStart(&nodeId, 1) == 0,
- "waitNodesNoStart failed");
-
- g_info << "number of nodes running " << _restarter.getNumDbNodes() << endl;
-
- if (_restarter.getNumDbNodes() != nNodes) {
- g_err << "Failure: cluster not up" << endl;
- return NDBT_FAILED;
- }
-
- NdbSleep_SecSleep(1);
-
- g_info << "starting new backup" << endl;
- CHECK(start() == 0,
- "failed to start backup");
- g_info << "(which should succeed) started with id = " << backupId << endl;
-
- g_info << "starting node" << endl;
- CHECK(_restarter.startNodes(&nodeId, 1) == 0,
- "failed to start node");
-
- CHECK(_restarter.waitClusterStarted() == 0,
- "waitClusterStarted failed");
- g_info << "node started" << endl;
-
- CHECK(_restarter.insertErrorInNode(nodeId, 10099) == 0,
- "failed to set error insert");
- }
-
- return NDBT_OK;
-}
-
-int
-FailS_codes[] = {
- 10023,
- 10024,
- 10025,
- 10026,
- 10027,
- 10028,
- 10029,
- 10030,
- 10031
-};
-
-int
-FailM_codes[] = {
- 10023,
- 10024,
- 10025,
- 10026,
- 10027,
- 10028,
- 10029,
- 10030,
- 10031
-};
-
-int
-NdbGrep::FailMaster(NdbRestarter& _restarter){
- const int sz = sizeof(FailM_codes)/sizeof(FailM_codes[0]);
- return Fail(_restarter, FailM_codes, sz, true);
-}
-
-int
-NdbGrep::FailMasterAsSlave(NdbRestarter& _restarter){
- const int sz = sizeof(FailS_codes)/sizeof(FailS_codes[0]);
- return Fail(_restarter, FailS_codes, sz, true);
-}
-
-int
-NdbGrep::FailSlave(NdbRestarter& _restarter){
- const int sz = sizeof(FailS_codes)/sizeof(FailS_codes[0]);
- return Fail(_restarter, FailS_codes, sz, false);
-}
-
-int
-NdbGrep::Fail(NdbRestarter& _restarter, int *Fail_codes, const int sz, bool onMaster){
-
- CHECK(_restarter.waitClusterStarted() == 0,
- "waitClusterStarted failed");
-
- int nNodes = _restarter.getNumDbNodes();
-
- myRandom48Init(NdbTick_CurrentMillisecond());
-
- for(int i = 0; i<sz; i++){
- int error = Fail_codes[i];
- unsigned int backupId;
-
- const int masterNodeId = _restarter.getMasterNodeId();
- CHECK(masterNodeId > 0, "getMasterNodeId failed");
- int nodeId;
-
- nodeId = masterNodeId;
- if (!onMaster) {
- int randomId;
- while (nodeId == masterNodeId) {
- randomId = myRandom48(nNodes);
- nodeId = _restarter.getDbNodeId(randomId);
- }
- }
-
- g_err << "NdbGrep::Fail node = " << nodeId
- << " error code = " << error << " masterNodeId = "
- << masterNodeId << endl;
-
- CHECK(_restarter.insertErrorInNode(nodeId, error) == 0,
- "failed to set error insert");
-
- g_info << "error inserted" << endl;
- g_info << "waiting some before starting backup" << endl;
-
- g_info << "starting backup" << endl;
- int r = start();
- g_info << "r = " << r
- << " (which should fail) started with id = " << backupId << endl;
- if (r == 0) {
- g_err << "Grep should have failed on error_insertion " << error << endl
- << "Master = " << masterNodeId << "Node = " << nodeId << endl;
- }
-
- CHECK(_restarter.waitClusterStarted() == 0,
- "waitClusterStarted failed");
-
- CHECK(_restarter.insertErrorInNode(nodeId, 10099) == 0,
- "failed to set error insert");
- }
-
- return NDBT_OK;
-}
-
-
diff --git a/storage/ndb/test/src/NdbMixRestarter.cpp b/storage/ndb/test/src/NdbMixRestarter.cpp
deleted file mode 100644
index 236ba491a00..00000000000
--- a/storage/ndb/test/src/NdbMixRestarter.cpp
+++ /dev/null
@@ -1,313 +0,0 @@
-/* Copyright (c) 2003, 2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include "NdbMixRestarter.hpp"
-
-NdbMixRestarter::NdbMixRestarter(const char* _addr) :
- NdbRestarter(_addr),
- m_mask(~(Uint32)0)
-{
-}
-
-NdbMixRestarter::~NdbMixRestarter()
-{
-
-}
-
-#define CHECK(b) if (!(b)) { \
- ndbout << "ERR: "<< step->getName() \
- << " failed on line " << __LINE__ << endl; \
- result = NDBT_FAILED; \
- continue; }
-
-int
-NdbMixRestarter::restart_cluster(NDBT_Context* ctx,
- NDBT_Step* step,
- bool stopabort)
-{
- int timeout = 180;
- int result = NDBT_OK;
-
- do
- {
- ctx->setProperty(NMR_SR_THREADS_STOPPED, (Uint32)0);
- ctx->setProperty(NMR_SR_VALIDATE_THREADS_DONE, (Uint32)0);
-
- ndbout << " -- Shutting down " << endl;
- ctx->setProperty(NMR_SR, NdbMixRestarter::SR_STOPPING);
- CHECK(restartAll(false, true, stopabort) == 0);
- ctx->setProperty(NMR_SR, NdbMixRestarter::SR_STOPPED);
- CHECK(waitClusterNoStart(timeout) == 0);
-
- Uint32 cnt = ctx->getProperty(NMR_SR_THREADS);
- Uint32 curr= ctx->getProperty(NMR_SR_THREADS_STOPPED);
- while(curr != cnt && !ctx->isTestStopped())
- {
- if (curr > cnt)
- {
- ndbout_c("stopping: curr: %d cnt: %d", curr, cnt);
- abort();
- }
-
- NdbSleep_MilliSleep(100);
- curr= ctx->getProperty(NMR_SR_THREADS_STOPPED);
- }
-
- CHECK(ctx->isTestStopped() == false);
- CHECK(startAll() == 0);
- CHECK(waitClusterStarted(timeout) == 0);
-
- cnt = ctx->getProperty(NMR_SR_VALIDATE_THREADS);
- if (cnt)
- {
- ndbout << " -- Validating starts " << endl;
- ctx->setProperty(NMR_SR_VALIDATE_THREADS_DONE, (Uint32)0);
- ctx->setProperty(NMR_SR, NdbMixRestarter::SR_VALIDATING);
- curr = ctx->getProperty(NMR_SR_VALIDATE_THREADS_DONE);
- while (curr != cnt && !ctx->isTestStopped())
- {
- if (curr > cnt)
- {
- ndbout_c("validating: curr: %d cnt: %d", curr, cnt);
- abort();
- }
-
- NdbSleep_MilliSleep(100);
- curr = ctx->getProperty(NMR_SR_VALIDATE_THREADS_DONE);
- }
- ndbout << " -- Validating complete " << endl;
- }
- CHECK(ctx->isTestStopped() == false);
- ctx->setProperty(NMR_SR, NdbMixRestarter::SR_RUNNING);
-
- } while(0);
-
- return result;
-}
-
-static
-ndb_mgm_node_state*
-select_node_to_stop(Vector<ndb_mgm_node_state>& nodes)
-{
- Uint32 i, j;
- Vector<ndb_mgm_node_state*> alive_nodes;
- for(i = 0; i<nodes.size(); i++)
- {
- ndb_mgm_node_state* node = &nodes[i];
- if (node->node_status == NDB_MGM_NODE_STATUS_STARTED)
- alive_nodes.push_back(node);
- }
-
- Vector<ndb_mgm_node_state*> victims;
- // Remove those with one in node group
- for(i = 0; i<alive_nodes.size(); i++)
- {
- int group = alive_nodes[i]->node_group;
- for(j = 0; j<alive_nodes.size(); j++)
- {
- if (i != j && alive_nodes[j]->node_group == group)
- {
- victims.push_back(alive_nodes[i]);
- break;
- }
- }
- }
-
- if (victims.size())
- {
- int victim = rand() % victims.size();
- return victims[victim];
- }
- else
- {
- return 0;
- }
-}
-
-static
-ndb_mgm_node_state*
-select_node_to_start(Vector<ndb_mgm_node_state>& nodes)
-{
- Uint32 i;
- Vector<ndb_mgm_node_state*> victims;
- for(i = 0; i<nodes.size(); i++)
- {
- ndb_mgm_node_state* node = &nodes[i];
- if (node->node_status == NDB_MGM_NODE_STATUS_NOT_STARTED)
- victims.push_back(node);
- }
-
- if (victims.size())
- {
- int victim = rand() % victims.size();
- return victims[victim];
- }
- else
- {
- return 0;
- }
-}
-
-void
-NdbMixRestarter::setRestartTypeMask(Uint32 mask)
-{
- m_mask = mask;
-}
-
-int
-NdbMixRestarter::runUntilStopped(NDBT_Context* ctx,
- NDBT_Step* step,
- Uint32 freq)
-{
- if (init(ctx, step))
- return NDBT_FAILED;
-
- while (!ctx->isTestStopped())
- {
- if (dostep(ctx, step))
- return NDBT_FAILED;
- NdbSleep_SecSleep(freq);
- }
-
- if (!finish(ctx, step))
- return NDBT_FAILED;
-
- return NDBT_OK;
-}
-
-int
-NdbMixRestarter::runPeriod(NDBT_Context* ctx,
- NDBT_Step* step,
- Uint32 period, Uint32 freq)
-{
- if (init(ctx, step))
- return NDBT_FAILED;
-
- Uint32 stop = time(0) + period;
- while (!ctx->isTestStopped() && (time(0) < stop))
- {
- if (dostep(ctx, step))
- {
- return NDBT_FAILED;
- }
- NdbSleep_SecSleep(freq);
- }
-
- if (finish(ctx, step))
- {
- return NDBT_FAILED;
- }
-
- ctx->stopTest();
- return NDBT_OK;
-}
-
-int
-NdbMixRestarter::init(NDBT_Context* ctx, NDBT_Step* step)
-{
- waitClusterStarted();
- m_nodes = ndbNodes;
- return 0;
-}
-
-int
-NdbMixRestarter::dostep(NDBT_Context* ctx, NDBT_Step* step)
-{
- ndb_mgm_node_state* node = 0;
- int action;
-loop:
- while(((action = (1 << (rand() % RTM_COUNT))) & m_mask) == 0);
- switch(action){
- case RTM_RestartCluster:
- if (restart_cluster(ctx, step))
- return NDBT_FAILED;
- for (Uint32 i = 0; i<m_nodes.size(); i++)
- m_nodes[i].node_status = NDB_MGM_NODE_STATUS_STARTED;
- break;
- case RTM_RestartNode:
- case RTM_RestartNodeInitial:
- case RTM_StopNode:
- case RTM_StopNodeInitial:
- {
- if ((node = select_node_to_stop(m_nodes)) == 0)
- goto loop;
-
- if (action == RTM_RestartNode || action == RTM_RestartNodeInitial)
- ndbout << "Restarting " << node->node_id;
- else
- ndbout << "Stopping " << node->node_id;
-
- bool initial =
- action == RTM_RestartNodeInitial || action == RTM_StopNodeInitial;
-
- if (initial)
- ndbout << " inital";
- ndbout << endl;
-
- if (restartOneDbNode(node->node_id, initial, true, true))
- return NDBT_FAILED;
-
- if (waitNodesNoStart(&node->node_id, 1))
- return NDBT_FAILED;
-
- node->node_status = NDB_MGM_NODE_STATUS_NOT_STARTED;
-
- if (action == RTM_StopNode || action == RTM_StopNodeInitial)
- break;
- else
- goto start;
- }
- case RTM_StartNode:
- if ((node = select_node_to_start(m_nodes)) == 0)
- goto loop;
-start:
- ndbout << "Starting " << node->node_id << endl;
- if (startNodes(&node->node_id, 1))
- return NDBT_FAILED;
- if (waitNodesStarted(&node->node_id, 1))
- return NDBT_FAILED;
-
- node->node_status = NDB_MGM_NODE_STATUS_STARTED;
- break;
- }
- return NDBT_OK;
-}
-
-int
-NdbMixRestarter::finish(NDBT_Context* ctx, NDBT_Step* step)
-{
- Vector<int> not_started;
- {
- ndb_mgm_node_state* node = 0;
- while((node = select_node_to_start(m_nodes)))
- {
- not_started.push_back(node->node_id);
- node->node_status = NDB_MGM_NODE_STATUS_STARTED;
- }
- }
-
- if (not_started.size())
- {
- ndbout << "Starting stopped nodes " << endl;
- if (startNodes(not_started.getBase(), not_started.size()))
- return NDBT_FAILED;
- if (waitClusterStarted())
- return NDBT_FAILED;
- }
- return NDBT_OK;
-}
-
-template class Vector<ndb_mgm_node_state*>;
diff --git a/storage/ndb/test/src/NdbRestarter.cpp b/storage/ndb/test/src/NdbRestarter.cpp
deleted file mode 100644
index 0f8a3a46605..00000000000
--- a/storage/ndb/test/src/NdbRestarter.cpp
+++ /dev/null
@@ -1,751 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NdbRestarter.hpp>
-#include <NdbOut.hpp>
-#include <NdbSleep.h>
-#include <NdbTick.h>
-#include <mgmapi_debug.h>
-#include <NDBT_Output.hpp>
-#include <random.h>
-#include <kernel/ndb_limits.h>
-#include <ndb_version.h>
-
-#define MGMERR(h) \
- ndbout << "latest_error="<<ndb_mgm_get_latest_error(h) \
- << ", line="<<ndb_mgm_get_latest_error_line(h) \
- << ", mesg="<<ndb_mgm_get_latest_error_msg(h) \
- << ", desc="<<ndb_mgm_get_latest_error_desc(h) \
- << endl;
-
-
-NdbRestarter::NdbRestarter(const char* _addr):
- connected(false),
- handle(NULL),
- m_config(0)
-{
- if (_addr == NULL){
- addr.assign("");
- } else {
- addr.assign(_addr);
- }
-}
-
-NdbRestarter::~NdbRestarter(){
- disconnect();
-}
-
-int NdbRestarter::getDbNodeId(int _i){
- if (!isConnected())
- return -1;
-
- if (getStatus() != 0)
- return -1;
-
- for(size_t i = 0; i < ndbNodes.size(); i++){
- if (i == (unsigned)_i){
- return ndbNodes[i].node_id;
- }
- }
- return -1;
-}
-
-
-int
-NdbRestarter::restartOneDbNode(int _nodeId,
- bool inital,
- bool nostart,
- bool abort){
- if (!isConnected())
- return -1;
-
- int ret = 0;
-
- if ((ret = ndb_mgm_restart2(handle, 1, &_nodeId,
- inital, nostart, abort)) <= 0) {
- /**
- * ndb_mgm_restart2 returned error, one reason could
- * be that the node have not stopped fast enough!
- * Check status of the node to see if it's on the
- * way down. If that's the case ignore the error
- */
-
- if (getStatus() != 0)
- return -1;
-
- g_info << "ndb_mgm_restart2 returned with error, checking node state" << endl;
-
- for(size_t i = 0; i < ndbNodes.size(); i++){
- if(ndbNodes[i].node_id == _nodeId){
- g_info <<_nodeId<<": status="<<ndbNodes[i].node_status<<endl;
- /* Node found check state */
- switch(ndbNodes[i].node_status){
- case NDB_MGM_NODE_STATUS_RESTARTING:
- case NDB_MGM_NODE_STATUS_SHUTTING_DOWN:
- return 0;
- default:
- break;
- }
- }
- }
-
- MGMERR(handle);
- g_err << "Could not stop node with id = "<< _nodeId << endl;
- return -1;
- }
-
- return 0;
-}
-
-int
-NdbRestarter::getMasterNodeId(){
- if (!isConnected())
- return -1;
-
- if (getStatus() != 0)
- return -1;
-
- int min = 0;
- int node = -1;
- for(size_t i = 0; i < ndbNodes.size(); i++){
- if(min == 0 || ndbNodes[i].dynamic_id < min){
- min = ndbNodes[i].dynamic_id;
- node = ndbNodes[i].node_id;
- }
- }
-
- return node;
-}
-
-int
-NdbRestarter::getNodeGroup(int nodeId){
- if (!isConnected())
- return -1;
-
- if (getStatus() != 0)
- return -1;
-
- for(size_t i = 0; i < ndbNodes.size(); i++)
- {
- if(ndbNodes[i].node_id == nodeId)
- {
- return ndbNodes[i].node_group;
- }
- }
-
- return -1;
-}
-
-int
-NdbRestarter::getNextMasterNodeId(int nodeId){
- if (!isConnected())
- return -1;
-
- if (getStatus() != 0)
- return -1;
-
- size_t i;
- for(i = 0; i < ndbNodes.size(); i++)
- {
- if(ndbNodes[i].node_id == nodeId)
- {
- break;
- }
- }
- assert(i < ndbNodes.size());
- if (i == ndbNodes.size())
- return -1;
-
- int dynid = ndbNodes[i].dynamic_id;
- int minid = dynid;
- for (i = 0; i<ndbNodes.size(); i++)
- if (ndbNodes[i].dynamic_id > minid)
- minid = ndbNodes[i].dynamic_id;
-
- for (i = 0; i<ndbNodes.size(); i++)
- if (ndbNodes[i].dynamic_id > dynid &&
- ndbNodes[i].dynamic_id < minid)
- {
- minid = ndbNodes[i].dynamic_id;
- }
-
- if (minid != ~0)
- {
- for (i = 0; i<ndbNodes.size(); i++)
- if (ndbNodes[i].dynamic_id == minid)
- return ndbNodes[i].node_id;
- }
-
- return getMasterNodeId();
-}
-
-int
-NdbRestarter::getRandomNotMasterNodeId(int rand){
- int master = getMasterNodeId();
- if(master == -1)
- return -1;
-
- Uint32 counter = 0;
- rand = rand % ndbNodes.size();
- while(counter++ < ndbNodes.size() && ndbNodes[rand].node_id == master)
- rand = (rand + 1) % ndbNodes.size();
-
- if(ndbNodes[rand].node_id != master)
- return ndbNodes[rand].node_id;
- return -1;
-}
-
-int
-NdbRestarter::getRandomNodeOtherNodeGroup(int nodeId, int rand){
- if (!isConnected())
- return -1;
-
- if (getStatus() != 0)
- return -1;
-
- int node_group = -1;
- for(size_t i = 0; i < ndbNodes.size(); i++){
- if(ndbNodes[i].node_id == nodeId){
- node_group = ndbNodes[i].node_group;
- break;
- }
- }
- if(node_group == -1){
- return -1;
- }
-
- Uint32 counter = 0;
- rand = rand % ndbNodes.size();
- while(counter++ < ndbNodes.size() && ndbNodes[rand].node_group == node_group)
- rand = (rand + 1) % ndbNodes.size();
-
- if(ndbNodes[rand].node_group != node_group)
- return ndbNodes[rand].node_id;
-
- return -1;
-}
-
-int
-NdbRestarter::getRandomNodeSameNodeGroup(int nodeId, int rand){
- if (!isConnected())
- return -1;
-
- if (getStatus() != 0)
- return -1;
-
- int node_group = -1;
- for(size_t i = 0; i < ndbNodes.size(); i++){
- if(ndbNodes[i].node_id == nodeId){
- node_group = ndbNodes[i].node_group;
- break;
- }
- }
- if(node_group == -1){
- return -1;
- }
-
- Uint32 counter = 0;
- rand = rand % ndbNodes.size();
- while(counter++ < ndbNodes.size() &&
- (ndbNodes[rand].node_id == nodeId ||
- ndbNodes[rand].node_group != node_group))
- rand = (rand + 1) % ndbNodes.size();
-
- if(ndbNodes[rand].node_group == node_group &&
- ndbNodes[rand].node_id != nodeId)
- return ndbNodes[rand].node_id;
-
- return -1;
-}
-
-int
-NdbRestarter::waitClusterStarted(unsigned int _timeout){
- return waitClusterState(NDB_MGM_NODE_STATUS_STARTED, _timeout);
-}
-
-int
-NdbRestarter::waitClusterStartPhase(int _startphase, unsigned int _timeout){
- return waitClusterState(NDB_MGM_NODE_STATUS_STARTING, _timeout, _startphase);
-}
-
-int
-NdbRestarter::waitClusterSingleUser(unsigned int _timeout){
- return waitClusterState(NDB_MGM_NODE_STATUS_SINGLEUSER, _timeout);
-}
-
-int
-NdbRestarter::waitClusterNoStart(unsigned int _timeout){
- return waitClusterState(NDB_MGM_NODE_STATUS_NOT_STARTED, _timeout);
-}
-
-int
-NdbRestarter::waitClusterState(ndb_mgm_node_status _status,
- unsigned int _timeout,
- int _startphase){
-
- int nodes[MAX_NDB_NODES];
- int numNodes = 0;
-
- if (getStatus() != 0)
- return -1;
-
- // Collect all nodes into nodes
- for (size_t i = 0; i < ndbNodes.size(); i++){
- nodes[i] = ndbNodes[i].node_id;
- numNodes++;
- }
-
- return waitNodesState(nodes, numNodes, _status, _timeout, _startphase);
-}
-
-
-int
-NdbRestarter::waitNodesState(const int * _nodes, int _num_nodes,
- ndb_mgm_node_status _status,
- unsigned int _timeout,
- int _startphase){
-
- if (!isConnected()){
- g_err << "!isConnected"<<endl;
- return -1;
- }
-
- unsigned int attempts = 0;
- unsigned int resetAttempts = 0;
- const unsigned int MAX_RESET_ATTEMPTS = 10;
- bool allInState = false;
- while (allInState == false){
- if (_timeout > 0 && attempts > _timeout){
- /**
- * Timeout has expired waiting for the nodes to enter
- * the state we want
- */
- bool waitMore = false;
- /**
- * Make special check if we are waiting for
- * cluster to become started
- */
- if(_status == NDB_MGM_NODE_STATUS_STARTED){
- waitMore = true;
- /**
- * First check if any node is not starting
- * then it's no idea to wait anymore
- */
- for (size_t n = 0; n < ndbNodes.size(); n++){
- if (ndbNodes[n].node_status != NDB_MGM_NODE_STATUS_STARTED &&
- ndbNodes[n].node_status != NDB_MGM_NODE_STATUS_STARTING)
- waitMore = false;
-
- }
- }
-
- if (!waitMore || resetAttempts > MAX_RESET_ATTEMPTS){
- g_err << "waitNodeState("
- << ndb_mgm_get_node_status_string(_status)
- <<", "<<_startphase<<")"
- << " timeout after " << attempts <<" attemps" << endl;
- return -1;
- }
-
- g_err << "waitNodeState("
- << ndb_mgm_get_node_status_string(_status)
- <<", "<<_startphase<<")"
- << " resetting number of attempts "
- << resetAttempts << endl;
- attempts = 0;
- resetAttempts++;
-
- }
-
- allInState = true;
- if (getStatus() != 0){
- g_err << "getStatus != 0" << endl;
- return -1;
- }
-
- // ndbout << "waitNodeState; _num_nodes = " << _num_nodes << endl;
- // for (int i = 0; i < _num_nodes; i++)
- // ndbout << " node["<<i<<"] =" <<_nodes[i] << endl;
-
- for (int i = 0; i < _num_nodes; i++){
- ndb_mgm_node_state* ndbNode = NULL;
- for (size_t n = 0; n < ndbNodes.size(); n++){
- if (ndbNodes[n].node_id == _nodes[i])
- ndbNode = &ndbNodes[n];
- }
-
- if(ndbNode == NULL){
- allInState = false;
- continue;
- }
-
- g_info << "State node " << ndbNode->node_id << " "
- << ndb_mgm_get_node_status_string(ndbNode->node_status);
- if (ndbNode->node_status == NDB_MGM_NODE_STATUS_STARTING)
- g_info<< ", start_phase=" << ndbNode->start_phase;
- g_info << endl;
-
- assert(ndbNode != NULL);
-
- if(_status == NDB_MGM_NODE_STATUS_STARTING &&
- ((ndbNode->node_status == NDB_MGM_NODE_STATUS_STARTING &&
- ndbNode->start_phase >= _startphase) ||
- (ndbNode->node_status == NDB_MGM_NODE_STATUS_STARTED)))
- continue;
-
- if (_status == NDB_MGM_NODE_STATUS_STARTING){
- g_info << "status = "
- << ndb_mgm_get_node_status_string(ndbNode->node_status)
- <<", start_phase="<<ndbNode->start_phase<<endl;
- if (ndbNode->node_status != _status) {
- if (ndbNode->node_status < _status)
- allInState = false;
- else
- g_info << "node_status(" << ndbNode->node_status
- <<") != _status("<<_status<<")"<<endl;
- } else if (ndbNode->start_phase < _startphase)
- allInState = false;
- } else {
- if (ndbNode->node_status != _status)
- allInState = false;
- }
- }
- g_info << "Waiting for cluster enter state"
- << ndb_mgm_get_node_status_string(_status)<< endl;
- NdbSleep_SecSleep(1);
- attempts++;
- }
- return 0;
-}
-
-int NdbRestarter::waitNodesStarted(const int * _nodes, int _num_nodes,
- unsigned int _timeout){
- return waitNodesState(_nodes, _num_nodes,
- NDB_MGM_NODE_STATUS_STARTED, _timeout);
-}
-
-int NdbRestarter::waitNodesStartPhase(const int * _nodes, int _num_nodes,
- int _startphase, unsigned int _timeout){
- return waitNodesState(_nodes, _num_nodes,
- NDB_MGM_NODE_STATUS_STARTING, _timeout,
- _startphase);
-}
-
-int NdbRestarter::waitNodesNoStart(const int * _nodes, int _num_nodes,
- unsigned int _timeout){
- return waitNodesState(_nodes, _num_nodes,
- NDB_MGM_NODE_STATUS_NOT_STARTED, _timeout);
-}
-
-bool
-NdbRestarter::isConnected(){
- if (connected == true)
- return true;
- return connect() == 0;
-}
-
-int
-NdbRestarter::connect(){
- disconnect();
- handle = ndb_mgm_create_handle();
- if (handle == NULL){
- g_err << "handle == NULL" << endl;
- return -1;
- }
- g_info << "Connecting to mgmsrv at " << addr.c_str() << endl;
- if (ndb_mgm_set_connectstring(handle,addr.c_str()))
- {
- MGMERR(handle);
- g_err << "Connection to " << addr.c_str() << " failed" << endl;
- return -1;
- }
-
- if (ndb_mgm_connect(handle, 0, 0, 0) == -1)
- {
- MGMERR(handle);
- g_err << "Connection to " << addr.c_str() << " failed" << endl;
- return -1;
- }
-
- connected = true;
- return 0;
-}
-
-void
-NdbRestarter::disconnect(){
- if (handle != NULL){
- ndb_mgm_disconnect(handle);
- ndb_mgm_destroy_handle(&handle);
- }
- connected = false;
-}
-
-int
-NdbRestarter::getStatus(){
- int retries = 0;
- struct ndb_mgm_cluster_state * status;
- struct ndb_mgm_node_state * node;
-
- ndbNodes.clear();
- mgmNodes.clear();
- apiNodes.clear();
-
- if (!isConnected())
- return -1;
-
- while(retries < 10){
- status = ndb_mgm_get_status(handle);
- if (status == NULL){
- ndbout << "status==NULL, retries="<<retries<<endl;
- MGMERR(handle);
- retries++;
- continue;
- }
- for (int i = 0; i < status->no_of_nodes; i++){
- node = &status->node_states[i];
- switch(node->node_type){
- case NDB_MGM_NODE_TYPE_NDB:
- ndbNodes.push_back(*node);
- break;
- case NDB_MGM_NODE_TYPE_MGM:
- mgmNodes.push_back(*node);
- break;
- case NDB_MGM_NODE_TYPE_API:
- apiNodes.push_back(*node);
- break;
- default:
- if(node->node_status == NDB_MGM_NODE_STATUS_UNKNOWN ||
- node->node_status == NDB_MGM_NODE_STATUS_NO_CONTACT){
- retries++;
- ndbNodes.clear();
- mgmNodes.clear();
- apiNodes.clear();
- free(status);
- status = NULL;
- i = status->no_of_nodes;
-
- ndbout << "kalle"<< endl;
- break;
- }
- abort();
- break;
- }
- }
- if(status == 0){
- ndbout << "status == 0" << endl;
- continue;
- }
- free(status);
- return 0;
- }
-
- g_err << "getStatus failed" << endl;
- return -1;
-}
-
-
-int NdbRestarter::getNumDbNodes(){
- if (!isConnected())
- return -1;
-
- if (getStatus() != 0)
- return -1;
-
- return ndbNodes.size();
-}
-
-int NdbRestarter::restartAll(bool initial,
- bool nostart,
- bool abort){
-
- if (!isConnected())
- return -1;
-
- if (ndb_mgm_restart2(handle, 0, NULL, initial, 1, abort) == -1) {
- MGMERR(handle);
- g_err << "Could not restart(stop) all nodes " << endl;
- // return -1; Continue anyway - Magnus
- }
-
- if (waitClusterNoStart(60) != 0){
- g_err << "Cluster didnt enter STATUS_NOT_STARTED within 60s" << endl;
- return -1;
- }
-
- if(nostart){
- g_debug << "restartAll: nostart == true" << endl;
- return 0;
- }
-
- if (ndb_mgm_start(handle, 0, NULL) == -1) {
- MGMERR(handle);
- g_err << "Could not restart(start) all nodes " << endl;
- return -1;
- }
-
- return 0;
-}
-
-int NdbRestarter::startAll(){
- if (!isConnected())
- return -1;
-
- if (ndb_mgm_start(handle, 0, NULL) == -1) {
- MGMERR(handle);
- g_err << "Could not start all nodes " << endl;
- return -1;
- }
-
- return 0;
-
-}
-
-int NdbRestarter::startNodes(const int * nodes, int num_nodes){
- if (!isConnected())
- return -1;
-
- if (ndb_mgm_start(handle, num_nodes, nodes) != num_nodes) {
- MGMERR(handle);
- g_err << "Could not start all nodes " << endl;
- return -1;
- }
-
- return 0;
-}
-
-int NdbRestarter::insertErrorInNode(int _nodeId, int _error){
- if (!isConnected())
- return -1;
-
- ndb_mgm_reply reply;
- reply.return_code = 0;
-
- if (ndb_mgm_insert_error(handle, _nodeId, _error, &reply) == -1){
- MGMERR(handle);
- g_err << "Could not insert error in node with id = "<< _nodeId << endl;
- }
- if(reply.return_code != 0){
- g_err << "Error: " << reply.message << endl;
- }
- return 0;
-}
-
-int NdbRestarter::insertErrorInAllNodes(int _error){
- if (!isConnected())
- return -1;
-
- if (getStatus() != 0)
- return -1;
-
- int result = 0;
-
- for(size_t i = 0; i < ndbNodes.size(); i++){
- g_debug << "inserting error in node " << ndbNodes[i].node_id << endl;
- if (insertErrorInNode(ndbNodes[i].node_id, _error) == -1)
- result = -1;
- }
- return result;
-
-}
-
-
-
-int NdbRestarter::dumpStateOneNode(int _nodeId, const int * _args, int _num_args){
- if (!isConnected())
- return -1;
-
- ndb_mgm_reply reply;
- reply.return_code = 0;
-
- if (ndb_mgm_dump_state(handle, _nodeId, _args, _num_args, &reply) == -1){
- MGMERR(handle);
- g_err << "Could not dump state in node with id = "<< _nodeId << endl;
- }
-
- if(reply.return_code != 0){
- g_err << "Error: " << reply.message << endl;
- }
- return reply.return_code;
-}
-
-int NdbRestarter::dumpStateAllNodes(const int * _args, int _num_args){
- if (!isConnected())
- return -1;
-
- if (getStatus() != 0)
- return -1;
-
- int result = 0;
-
- for(size_t i = 0; i < ndbNodes.size(); i++){
- g_debug << "dumping state in node " << ndbNodes[i].node_id << endl;
- if (dumpStateOneNode(ndbNodes[i].node_id, _args, _num_args) == -1)
- result = -1;
- }
- return result;
-
-}
-
-
-int NdbRestarter::enterSingleUserMode(int _nodeId){
- if (!isConnected())
- return -1;
-
- ndb_mgm_reply reply;
- reply.return_code = 0;
-
- if (ndb_mgm_enter_single_user(handle, _nodeId, &reply) == -1){
- MGMERR(handle);
- g_err << "Could not enter single user mode api node = "<< _nodeId << endl;
- }
-
- if(reply.return_code != 0){
- g_err << "Error: " << reply.message << endl;
- }
-
- return reply.return_code;
-}
-
-
-int NdbRestarter::exitSingleUserMode(){
- if (!isConnected())
- return -1;
-
- ndb_mgm_reply reply;
- reply.return_code = 0;
-
- if (ndb_mgm_exit_single_user(handle, &reply) == -1){
- MGMERR(handle);
- g_err << "Could not exit single user mode " << endl;
- }
-
- if(reply.return_code != 0){
- g_err << "Error: " << reply.message << endl;
- }
- return reply.return_code;
-}
-
-ndb_mgm_configuration*
-NdbRestarter::getConfig(){
- if(m_config) return m_config;
-
- if (!isConnected())
- return 0;
- m_config = ndb_mgm_get_configuration(handle, 0);
- return m_config;
-}
-
-template class Vector<ndb_mgm_node_state>;
diff --git a/storage/ndb/test/src/NdbRestarts.cpp b/storage/ndb/test/src/NdbRestarts.cpp
deleted file mode 100644
index 5dd26dd98b1..00000000000
--- a/storage/ndb/test/src/NdbRestarts.cpp
+++ /dev/null
@@ -1,875 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <NdbRestarts.hpp>
-#include <NDBT.hpp>
-#include <string.h>
-#include <NdbSleep.h>
-#include <kernel/ndb_limits.h>
-#include <signaldata/DumpStateOrd.hpp>
-#include <NdbEnv.h>
-
-
-int restartRandomNodeGraceful(NdbRestarter&, const NdbRestarts::NdbRestart*);
-int restartRandomNodeAbort(NdbRestarter&, const NdbRestarts::NdbRestart*);
-int restartRandomNodeError(NdbRestarter&, const NdbRestarts::NdbRestart*);
-int restartRandomNodeInitial(NdbRestarter&, const NdbRestarts::NdbRestart*);
-int restartNFDuringNR(NdbRestarter&, const NdbRestarts::NdbRestart*);
-int restartMasterNodeError(NdbRestarter&, const NdbRestarts::NdbRestart*);
-int twoNodeFailure(NdbRestarter&, const NdbRestarts::NdbRestart*);
-int fiftyPercentFail(NdbRestarter&, const NdbRestarts::NdbRestart*);
-int twoMasterNodeFailure(NdbRestarter&, const NdbRestarts::NdbRestart*);
-int restartAllNodesGracfeul(NdbRestarter&, const NdbRestarts::NdbRestart*);
-int restartAllNodesAbort(NdbRestarter&, const NdbRestarts::NdbRestart*);
-int restartAllNodesError9999(NdbRestarter&, const NdbRestarts::NdbRestart*);
-int fiftyPercentStopAndWait(NdbRestarter&, const NdbRestarts::NdbRestart*);
-int restartNodeDuringLCP(NdbRestarter& _restarter,
- const NdbRestarts::NdbRestart* _restart);
-int stopOnError(NdbRestarter&, const NdbRestarts::NdbRestart*);
-int getRandomNodeId(NdbRestarter& _restarter);
-
-/**
- * Define list of restarts
- * - name of restart
- * - function perfoming the restart
- * - required number of nodes
- * - ...
- * - arg1, used depending of restart
- * - arg2, used depending of restart
- */
-
-const NdbRestarts::NdbRestart NdbRestarts::m_restarts[] = {
- /*********************************************************
- *
- * NODE RESTARTS with 1 node restarted
- *
- *********************************************************/
- /**
- * Restart a randomly selected node
- * with graceful shutdown
- */
- NdbRestart("RestartRandomNode",
- NODE_RESTART,
- restartRandomNodeGraceful,
- 2),
- /**
- * Restart a randomly selected node
- * with immediate(abort) shutdown
- */
- NdbRestart("RestartRandomNodeAbort",
- NODE_RESTART,
- restartRandomNodeAbort,
- 2),
- /**
- * Restart a randomly selected node
- * with error insert
- *
- */
- NdbRestart("RestartRandomNodeError",
- NODE_RESTART,
- restartRandomNodeError,
- 2),
- /**
- * Restart the master node
- * with error insert
- */
- NdbRestart("RestartMasterNodeError",
- NODE_RESTART,
- restartMasterNodeError,
- 2),
- /**
- * Restart a randomly selected node without fileystem
- *
- */
- NdbRestart("RestartRandomNodeInitial",
- NODE_RESTART,
- restartRandomNodeInitial,
- 2),
- /**
- * Restart a randomly selected node and then
- * crash it while restarting
- *
- */
- NdbRestart("RestartNFDuringNR",
- NODE_RESTART,
- restartNFDuringNR,
- 2),
-
- /**
- * Set StopOnError and crash the node by sending
- * SYSTEM_ERROR to it
- *
- */
- NdbRestart("StopOnError",
- NODE_RESTART,
- stopOnError,
- 1),
-
- /*********************************************************
- *
- * MULTIPLE NODE RESTARTS with more than 1 node
- *
- *********************************************************/
- /**
- * 2 nodes restart, select nodes to restart randomly and restart
- * with a small random delay between restarts
- */
- NdbRestart("TwoNodeFailure",
- MULTIPLE_NODE_RESTART,
- twoNodeFailure,
- 4),
- /**
- * 2 nodes restart, select master nodes and restart with
- * a small random delay between restarts
- */
-
- NdbRestart("TwoMasterNodeFailure",
- MULTIPLE_NODE_RESTART,
- twoMasterNodeFailure,
- 4),
-
- NdbRestart("FiftyPercentFail",
- MULTIPLE_NODE_RESTART,
- fiftyPercentFail,
- 2),
-
- /*********************************************************
- *
- * SYSTEM RESTARTS
- *
- *********************************************************/
- /**
- * Restart all nodes with graceful shutdown
- *
- */
-
- NdbRestart("RestartAllNodes",
- SYSTEM_RESTART,
- restartAllNodesGracfeul,
- 1),
- /**
- * Restart all nodes immediately without
- * graful shutdown
- */
- NdbRestart("RestartAllNodesAbort",
- SYSTEM_RESTART,
- restartAllNodesAbort,
- 1),
- /**
- * Restart all nodes with error insert 9999
- * TODO! We can later add more errors like 9998, 9997 etc.
- */
- NdbRestart("RestartAllNodesError9999",
- SYSTEM_RESTART,
- restartAllNodesError9999,
- 1),
- /**
- * Stop 50% of all nodes with error insert 9999
- * Wait for a random number of minutes
- * Stop the rest of the nodes and then start all again
- */
- NdbRestart("FiftyPercentStopAndWait",
- SYSTEM_RESTART,
- fiftyPercentStopAndWait,
- 2),
- /**
- * Restart a master node during LCP with error inserts.
- */
- NdbRestart("RestartNodeDuringLCP",
- NODE_RESTART,
- restartNodeDuringLCP,
- 2),
-};
-
-const int NdbRestarts::m_NoOfRestarts = sizeof(m_restarts) / sizeof(NdbRestart);
-
-
-const NdbRestarts::NdbErrorInsert NdbRestarts::m_errors[] = {
- NdbErrorInsert("Error9999", 9999)
-};
-
-const int NdbRestarts::m_NoOfErrors = sizeof(m_errors) / sizeof(NdbErrorInsert);
-
-NdbRestarts::NdbRestart::NdbRestart(const char* _name,
- NdbRestartType _type,
- restartFunc* _func,
- int _requiredNodes,
- int _arg1){
- m_name = _name;
- m_type = _type;
- m_restartFunc = _func;
- m_numRequiredNodes = _requiredNodes;
- // m_arg1 = arg1;
-}
-
-
-int NdbRestarts::getNumRestarts(){
- return m_NoOfRestarts;
-}
-
-const NdbRestarts::NdbRestart* NdbRestarts::getRestart(int _num){
- if (_num >= m_NoOfRestarts)
- return NULL;
-
- return &m_restarts[_num];
-}
-
-const NdbRestarts::NdbRestart* NdbRestarts::getRestart(const char* _name){
- for(int i = 0; i < m_NoOfRestarts; i++){
- if (strcmp(m_restarts[i].m_name, _name) == 0){
- return &m_restarts[i];
- }
- }
- g_err << "The restart \""<< _name << "\" not found in NdbRestarts" << endl;
- return NULL;
-}
-
-
-int NdbRestarts::executeRestart(const NdbRestarts::NdbRestart* _restart,
- unsigned int _timeout){
- // Check that there are enough nodes in the cluster
- // for this test
- NdbRestarter restarter;
- if (_restart->m_numRequiredNodes > restarter.getNumDbNodes()){
- g_err << "This test requires " << _restart->m_numRequiredNodes << " nodes "
- << "there are only "<< restarter.getNumDbNodes() <<" nodes in cluster"
- << endl;
- return NDBT_OK;
- }
- if (restarter.waitClusterStarted(120) != 0){
- // If cluster is not started when we shall peform restart
- // the restart can not be executed and the test fails
- return NDBT_FAILED;
- }
-
- int res = _restart->m_restartFunc(restarter, _restart);
-
- // Sleep a little waiting for nodes to react to command
- NdbSleep_SecSleep(2);
-
- if (_timeout == 0){
- // If timeout == 0 wait for ever
- while(restarter.waitClusterStarted(60) != 0)
- g_err << "Cluster is not started after restart. Waiting 60s more..."
- << endl;
- } else {
- if (restarter.waitClusterStarted(_timeout) != 0){
- g_err<<"Cluster failed to start" << endl;
- res = NDBT_FAILED;
- }
- }
-
- return res;
-}
-
-int NdbRestarts::executeRestart(int _num,
- unsigned int _timeout){
- const NdbRestarts::NdbRestart* r = getRestart(_num);
- if (r == NULL)
- return NDBT_FAILED;
-
- int res = executeRestart(r, _timeout);
- return res;
-}
-
-int NdbRestarts::executeRestart(const char* _name,
- unsigned int _timeout){
- const NdbRestarts::NdbRestart* r = getRestart(_name);
- if (r == NULL)
- return NDBT_FAILED;
-
- int res = executeRestart(r, _timeout);
- return res;
-}
-
-void NdbRestarts::listRestarts(NdbRestartType _type){
- for(int i = 0; i < m_NoOfRestarts; i++){
- if (m_restarts[i].m_type == _type)
- ndbout << " " << m_restarts[i].m_name << ", min "
- << m_restarts[i].m_numRequiredNodes
- << " nodes"<< endl;
- }
-}
-
-void NdbRestarts::listRestarts(){
- ndbout << "NODE RESTARTS" << endl;
- listRestarts(NODE_RESTART);
- ndbout << "MULTIPLE NODE RESTARTS" << endl;
- listRestarts(MULTIPLE_NODE_RESTART);
- ndbout << "SYSTEM RESTARTS" << endl;
- listRestarts(SYSTEM_RESTART);
-}
-
-NdbRestarts::NdbErrorInsert::NdbErrorInsert(const char* _name,
- int _errorNo){
-
- m_name = _name;
- m_errorNo = _errorNo;
-}
-
-int NdbRestarts::getNumErrorInserts(){
- return m_NoOfErrors;
-}
-
-const NdbRestarts::NdbErrorInsert* NdbRestarts::getError(int _num){
- if (_num >= m_NoOfErrors)
- return NULL;
- return &m_errors[_num];
-}
-
-const NdbRestarts::NdbErrorInsert* NdbRestarts::getRandomError(){
- int randomId = myRandom48(m_NoOfErrors);
- return &m_errors[randomId];
-}
-
-
-
-/**
- *
- * IMPLEMENTATION OF THE DIFFERENT RESTARTS
- * Each function should perform it's action
- * and the returned NDBT_OK or NDBT_FAILED
- *
- */
-
-
-#define CHECK(b, m) { int _xx = b; if (!(_xx)) { \
- ndbout << "ERR: "<< m \
- << " " << "File: " << __FILE__ \
- << " (Line: " << __LINE__ << ")" << "- " << _xx << endl; \
- return NDBT_FAILED; } }
-
-
-
-int restartRandomNodeGraceful(NdbRestarter& _restarter,
- const NdbRestarts::NdbRestart* _restart){
-
- myRandom48Init(NdbTick_CurrentMillisecond());
- int randomId = myRandom48(_restarter.getNumDbNodes());
- int nodeId = _restarter.getDbNodeId(randomId);
-
- g_info << _restart->m_name << ": node = "<<nodeId << endl;
-
- CHECK(_restarter.restartOneDbNode(nodeId) == 0,
- "Could not restart node "<<nodeId);
-
- return NDBT_OK;
-}
-
-int restartRandomNodeAbort(NdbRestarter& _restarter,
- const NdbRestarts::NdbRestart* _restart){
-
- myRandom48Init(NdbTick_CurrentMillisecond());
- int randomId = myRandom48(_restarter.getNumDbNodes());
- int nodeId = _restarter.getDbNodeId(randomId);
-
- g_info << _restart->m_name << ": node = "<<nodeId << endl;
-
- CHECK(_restarter.restartOneDbNode(nodeId, false, false, true) == 0,
- "Could not restart node "<<nodeId);
-
- return NDBT_OK;
-}
-
-int restartRandomNodeError(NdbRestarter& _restarter,
- const NdbRestarts::NdbRestart* _restart){
-
- myRandom48Init(NdbTick_CurrentMillisecond());
- int randomId = myRandom48(_restarter.getNumDbNodes());
- int nodeId = _restarter.getDbNodeId(randomId);
-
- ndbout << _restart->m_name << ": node = "<<nodeId << endl;
-
- CHECK(_restarter.insertErrorInNode(nodeId, 9999) == 0,
- "Could not restart node "<<nodeId);
-
- return NDBT_OK;
-}
-
-int restartMasterNodeError(NdbRestarter& _restarter,
- const NdbRestarts::NdbRestart* _restart){
-
- int nodeId = _restarter.getDbNodeId(0);
-
- g_info << _restart->m_name << ": node = "<<nodeId << endl;
-
- CHECK(_restarter.insertErrorInNode(nodeId, 39999) == 0,
- "Could not restart node "<<nodeId);
-
- return NDBT_OK;
-}
-
-int restartRandomNodeInitial(NdbRestarter& _restarter,
- const NdbRestarts::NdbRestart* _restart){
-
- myRandom48Init(NdbTick_CurrentMillisecond());
- int randomId = myRandom48(_restarter.getNumDbNodes());
- int nodeId = _restarter.getDbNodeId(randomId);
-
- g_info << _restart->m_name << ": node = "<<nodeId << endl;
-
- CHECK(_restarter.restartOneDbNode(nodeId, true) == 0,
- "Could not restart node "<<nodeId);
-
- return NDBT_OK;
-}
-
-int twoNodeFailure(NdbRestarter& _restarter,
- const NdbRestarts::NdbRestart* _restart){
-
- myRandom48Init(NdbTick_CurrentMillisecond());
- int randomId = myRandom48(_restarter.getNumDbNodes());
- int nodeId = _restarter.getDbNodeId(randomId);
- g_info << _restart->m_name << ": node = "<< nodeId << endl;
-
- CHECK(_restarter.insertErrorInNode(nodeId, 9999) == 0,
- "Could not restart node "<< nodeId);
-
- // Create random value, max 10 secs
- int max = 10;
- int seconds = (myRandom48(max)) + 1;
- g_info << "Waiting for " << seconds << "(" << max
- << ") secs " << endl;
- NdbSleep_SecSleep(seconds);
-
- nodeId = _restarter.getRandomNodeOtherNodeGroup(nodeId, rand());
- g_info << _restart->m_name << ": node = "<< nodeId << endl;
-
- CHECK(_restarter.insertErrorInNode(nodeId, 9999) == 0,
- "Could not restart node "<< nodeId);
-
- return NDBT_OK;
-}
-
-int twoMasterNodeFailure(NdbRestarter& _restarter,
- const NdbRestarts::NdbRestart* _restart){
-
- int nodeId = _restarter.getDbNodeId(0);
- g_info << _restart->m_name << ": node = "<< nodeId << endl;
-
- CHECK(_restarter.insertErrorInNode(nodeId, 39999) == 0,
- "Could not restart node "<< nodeId);
-
- // Create random value, max 10 secs
- int max = 10;
- int seconds = (myRandom48(max)) + 1;
- g_info << "Waiting for " << seconds << "(" << max
- << ") secs " << endl;
- NdbSleep_SecSleep(seconds);
-
- nodeId = _restarter.getDbNodeId(0);
- g_info << _restart->m_name << ": node = "<< nodeId << endl;
-
- CHECK(_restarter.insertErrorInNode(nodeId, 39999) == 0,
- "Could not restart node "<< nodeId);
-
- return NDBT_OK;
-}
-
-int get50PercentOfNodes(NdbRestarter& restarter,
- int * _nodes){
- // For now simply return all nodes with even node id
- // TODO Check nodegroup and return one node from each
-
- int num50Percent = restarter.getNumDbNodes() / 2;
- assert(num50Percent <= MAX_NDB_NODES);
-
- // Calculate which nodes to stop, select all even nodes
- for (int i = 0; i < num50Percent; i++){
- _nodes[i] = restarter.getDbNodeId(i*2);
- }
- return num50Percent;
-}
-
-int fiftyPercentFail(NdbRestarter& _restarter,
- const NdbRestarts::NdbRestart* _restart){
-
-
- int nodes[MAX_NDB_NODES];
-
- int numNodes = get50PercentOfNodes(_restarter, nodes);
-
- // Stop the nodes, with nostart and abort
- for (int i = 0; i < numNodes; i++){
- g_info << "Stopping node "<< nodes[i] << endl;
- int res = _restarter.restartOneDbNode(nodes[i], false, true, true);
- CHECK(res == 0, "Could not stop node: "<< nodes[i]);
- }
-
- CHECK(_restarter.waitNodesNoStart(nodes, numNodes) == 0,
- "waitNodesNoStart");
-
- // Order all nodes to start
- ndbout << "Starting all nodes" << endl;
- CHECK(_restarter.startAll() == 0,
- "Could not start all nodes");
-
- return NDBT_OK;
-}
-
-
-int restartAllNodesGracfeul(NdbRestarter& _restarter,
- const NdbRestarts::NdbRestart* _restart){
-
- g_info << _restart->m_name << endl;
-
- // Restart graceful
- CHECK(_restarter.restartAll() == 0,
- "Could not restart all nodes");
-
- return NDBT_OK;
-
-}
-
-int restartAllNodesAbort(NdbRestarter& _restarter,
- const NdbRestarts::NdbRestart* _restart){
-
- g_info << _restart->m_name << endl;
-
- // Restart abort
- CHECK(_restarter.restartAll(false, false, true) == 0,
- "Could not restart all nodes");
-
- return NDBT_OK;
-}
-
-int restartAllNodesError9999(NdbRestarter& _restarter,
- const NdbRestarts::NdbRestart* _restart){
-
- g_info << _restart->m_name << endl;
-
- // Restart with error insert
- CHECK(_restarter.insertErrorInAllNodes(9999) == 0,
- "Could not restart all nodes ");
-
- return NDBT_OK;
-}
-
-int fiftyPercentStopAndWait(NdbRestarter& _restarter,
- const NdbRestarts::NdbRestart* _restart){
-
- int nodes[MAX_NDB_NODES];
- int numNodes = get50PercentOfNodes(_restarter, nodes);
-
- // Stop the nodes, with nostart and abort
- for (int i = 0; i < numNodes; i++){
- g_info << "Stopping node "<<nodes[i] << endl;
- int res = _restarter.restartOneDbNode(nodes[i], false, true, true);
- CHECK(res == 0, "Could not stop node: "<< nodes[i]);
- }
-
- CHECK(_restarter.waitNodesNoStart(nodes, numNodes) == 0,
- "waitNodesNoStart");
-
- // Create random value, max 120 secs
- int max = 120;
- int seconds = (myRandom48(max)) + 1;
- g_info << "Waiting for " << seconds << "(" << max
- << ") secs " << endl;
- NdbSleep_SecSleep(seconds);
-
-
- // Restart graceful
- CHECK(_restarter.restartAll() == 0,
- "Could not restart all nodes");
-
- g_info << _restart->m_name << endl;
-
- return NDBT_OK;
-}
-
-int
-NFDuringNR_codes[] = {
- 7121,
- 5027,
- 7172,
- 6000,
- 6001,
- 6002,
- 7171,
- 7130,
- 7133,
- 7138,
- 7154,
- 7144,
- 5026,
- 7139,
- 7132,
- 5045,
-
- //LCP
- 8000,
- 8001,
- 5010,
- 7022,
- 7024,
- 7016,
- 7017,
- 5002
-};
-
-int restartNFDuringNR(NdbRestarter& _restarter,
- const NdbRestarts::NdbRestart* _restart){
-
- myRandom48Init(NdbTick_CurrentMillisecond());
- int i;
- const int sz = sizeof(NFDuringNR_codes)/sizeof(NFDuringNR_codes[0]);
- for(i = 0; i<sz; i++){
- int randomId = myRandom48(_restarter.getNumDbNodes());
- int nodeId = _restarter.getDbNodeId(randomId);
- int error = NFDuringNR_codes[i];
-
- g_err << _restart->m_name << ": node = " << nodeId
- << " error code = " << error << endl;
-
- CHECK(_restarter.restartOneDbNode(nodeId, false, true, true) == 0,
- "Could not restart node "<< nodeId);
-
- CHECK(_restarter.waitNodesNoStart(&nodeId, 1) == 0,
- "waitNodesNoStart failed");
-
- int val[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 } ;
- CHECK(_restarter.dumpStateOneNode(nodeId, val, 2) == 0,
- "failed to set RestartOnErrorInsert");
-
- CHECK(_restarter.insertErrorInNode(nodeId, error) == 0,
- "failed to set error insert");
-
- CHECK(_restarter.startNodes(&nodeId, 1) == 0,
- "failed to start node");
-
- NdbSleep_SecSleep(3);
-
- //CHECK(_restarter.waitNodesNoStart(&nodeId, 1) == 0,
- // "waitNodesNoStart failed");
- _restarter.waitNodesNoStart(&nodeId, 1);
-
- CHECK(_restarter.startNodes(&nodeId, 1) == 0,
- "failed to start node");
-
- CHECK(_restarter.waitNodesStarted(&nodeId, 1) == 0,
- "waitNodesStarted failed");
- }
-
- return NDBT_OK;
-
- if(_restarter.getNumDbNodes() < 4)
- return NDBT_OK;
-
- char buf[256];
- if(NdbEnv_GetEnv("USER", buf, 256) == 0 || strcmp(buf, "ejonore") != 0)
- return NDBT_OK;
-
- for(i = 0; i<sz; i++){
- const int randomId = myRandom48(_restarter.getNumDbNodes());
- int nodeId = _restarter.getDbNodeId(randomId);
- const int error = NFDuringNR_codes[i];
-
- const int masterNodeId = _restarter.getMasterNodeId();
- CHECK(masterNodeId > 0, "getMasterNodeId failed");
- int crashNodeId = 0;
- do {
- int rand = myRandom48(1000);
- crashNodeId = _restarter.getRandomNodeOtherNodeGroup(nodeId, rand);
- } while(crashNodeId == masterNodeId);
-
- CHECK(crashNodeId > 0, "getMasterNodeId failed");
-
- g_info << _restart->m_name << " restarting node = " << nodeId
- << " error code = " << error
- << " crash node = " << crashNodeId << endl;
-
- CHECK(_restarter.restartOneDbNode(nodeId, false, true, true) == 0,
- "Could not restart node "<< nodeId);
-
- CHECK(_restarter.waitNodesNoStart(&nodeId, 1) == 0,
- "waitNodesNoStart failed");
-
- int val[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
- CHECK(_restarter.dumpStateOneNode(crashNodeId, val, 2) == 0,
- "failed to set RestartOnErrorInsert");
-
- CHECK(_restarter.insertErrorInNode(crashNodeId, error) == 0,
- "failed to set error insert");
-
- CHECK(_restarter.startNodes(&nodeId, 1) == 0,
- "failed to start node");
-
- CHECK(_restarter.waitClusterStarted() == 0,
- "waitClusterStarted failed");
- }
-
- return NDBT_OK;
-}
-
-int
-NRDuringLCP_Master_codes[] = {
- 7009, // Insert system error in master when local checkpoint is idle.
- 7010, // Insert system error in master when local checkpoint is in the
- // state clcpStatus = CALCULATE_KEEP_GCI.
- 7013, // Insert system error in master when local checkpoint is in the
- // state clcpStatus = COPY_GCI before sending COPY_GCIREQ.
- 7014, // Insert system error in master when local checkpoint is in the
- // state clcpStatus = TC_CLOPSIZE before sending TC_CLOPSIZEREQ.
- 7015, // Insert system error in master when local checkpoint is in the
- // state clcpStatus = START_LCP_ROUND before sending START_LCP_ROUND.
- 7019, // Insert system error in master when local checkpoint is in the
- // state clcpStatus = IDLE before sending CONTINUEB(ZCHECK_TC_COUNTER).
- 7075, // Master. Don't send any LCP_FRAG_ORD(last=true)
- // And crash when all have "not" been sent
- 7021, // Crash in master when receiving START_LCP_REQ
- 7023, // Crash in master when sending START_LCP_CONF
- 7025, // Crash in master when receiving LCP_FRAG_REP
- 7026, // Crash in master when changing state to LCP_TAB_COMPLETED
- 7027 // Crash in master when changing state to LCP_TAB_SAVED
-};
-
-int
-NRDuringLCP_NonMaster_codes[] = {
- 7020, // Insert system error in local checkpoint participant at reception
- // of COPY_GCIREQ.
- 8000, // Crash particpant when receiving TCGETOPSIZEREQ
- 8001, // Crash particpant when receiving TC_CLOPSIZEREQ
- 5010, // Crash any when receiving LCP_FRAGORD
- 7022, // Crash in !master when receiving START_LCP_REQ
- 7024, // Crash in !master when sending START_LCP_CONF
- 7016, // Crash in !master when receiving LCP_FRAG_REP
- 7017, // Crash in !master when changing state to LCP_TAB_COMPLETED
- 7018 // Crash in !master when changing state to LCP_TAB_SAVED
-};
-
-int restartNodeDuringLCP(NdbRestarter& _restarter,
- const NdbRestarts::NdbRestart* _restart) {
- int i;
- // Master
- int val = DumpStateOrd::DihMinTimeBetweenLCP;
- CHECK(_restarter.dumpStateAllNodes(&val, 1) == 0,
- "Failed to set LCP to min value"); // Set LCP to min val
- int sz = sizeof(NRDuringLCP_Master_codes)/
- sizeof(NRDuringLCP_Master_codes[0]);
- for(i = 0; i<sz; i++) {
-
- int error = NRDuringLCP_Master_codes[i];
- int masterNodeId = _restarter.getMasterNodeId();
-
- CHECK(masterNodeId > 0, "getMasterNodeId failed");
-
- ndbout << _restart->m_name << " restarting master node = " << masterNodeId
- << " error code = " << error << endl;
-
- {
- int val[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
- CHECK(_restarter.dumpStateAllNodes(val, 2) == 0,
- "failed to set RestartOnErrorInsert");
- }
-
- CHECK(_restarter.insertErrorInNode(masterNodeId, error) == 0,
- "failed to set error insert");
-
- CHECK(_restarter.waitNodesNoStart(&masterNodeId, 1, 300) == 0,
- "failed to wait no start");
-
- CHECK(_restarter.startNodes(&masterNodeId, 1) == 0,
- "failed to start node");
-
- CHECK(_restarter.waitClusterStarted(300) == 0,
- "waitClusterStarted failed");
-
- {
- int val = DumpStateOrd::DihMinTimeBetweenLCP;
- CHECK(_restarter.dumpStateOneNode(masterNodeId, &val, 1) == 0,
- "failed to set error insert");
- }
- }
-
- // NON-Master
- sz = sizeof(NRDuringLCP_NonMaster_codes)/
- sizeof(NRDuringLCP_NonMaster_codes[0]);
- for(i = 0; i<sz; i++) {
-
- int error = NRDuringLCP_NonMaster_codes[i];
- int nodeId = getRandomNodeId(_restarter);
- int masterNodeId = _restarter.getMasterNodeId();
- CHECK(masterNodeId > 0, "getMasterNodeId failed");
-
- while (nodeId == masterNodeId) {
- nodeId = getRandomNodeId(_restarter);
- }
-
- ndbout << _restart->m_name << " restarting non-master node = " << nodeId
- << " error code = " << error << endl;
-
- int val[] = { DumpStateOrd::CmvmiSetRestartOnErrorInsert, 1 };
- CHECK(_restarter.dumpStateAllNodes(val, 2) == 0,
- "failed to set RestartOnErrorInsert");
-
- CHECK(_restarter.insertErrorInNode(nodeId, error) == 0,
- "failed to set error insert");
-
- CHECK(_restarter.waitNodesNoStart(&nodeId, 1, 300) == 0,
- "failed to wait no start");
-
- CHECK(_restarter.startNodes(&nodeId, 1) == 0,
- "failed to start node");
-
- CHECK(_restarter.waitClusterStarted(300) == 0,
- "waitClusterStarted failed");
-
- {
- int val = DumpStateOrd::DihMinTimeBetweenLCP;
- CHECK(_restarter.dumpStateOneNode(nodeId, &val, 1) == 0,
- "failed to set error insert");
- }
- }
-
- return NDBT_OK;
-}
-
-int stopOnError(NdbRestarter& _restarter,
- const NdbRestarts::NdbRestart* _restart){
-
- myRandom48Init(NdbTick_CurrentMillisecond());
-
- int randomId = myRandom48(_restarter.getNumDbNodes());
- int nodeId = _restarter.getDbNodeId(randomId);
-
- do {
- g_info << _restart->m_name << ": node = " << nodeId
- << endl;
-
- CHECK(_restarter.waitClusterStarted(300) == 0,
- "waitClusterStarted failed");
-
- int val = DumpStateOrd::NdbcntrTestStopOnError;
- CHECK(_restarter.dumpStateOneNode(nodeId, &val, 1) == 0,
- "failed to set NdbcntrTestStopOnError");
-
- NdbSleep_SecSleep(3);
-
- CHECK(_restarter.waitClusterStarted(300) == 0,
- "waitClusterStarted failed");
- } while (false);
-
- return NDBT_OK;
-}
-
-int getRandomNodeId(NdbRestarter& _restarter) {
- myRandom48Init(NdbTick_CurrentMillisecond());
- int randomId = myRandom48(_restarter.getNumDbNodes());
- int nodeId = _restarter.getDbNodeId(randomId);
-
- return nodeId;
-}
diff --git a/storage/ndb/test/src/NdbSchemaCon.cpp b/storage/ndb/test/src/NdbSchemaCon.cpp
deleted file mode 100644
index 37e077ec661..00000000000
--- a/storage/ndb/test/src/NdbSchemaCon.cpp
+++ /dev/null
@@ -1,169 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-
-/*********************************************************************
-Name: NdbSchemaCon.cpp
-Include:
-Link:
-Author: UABMNST Mona Natterkvist UAB/B/SD
- EMIKRON Mikael Ronstrom
-Date: 020826
-Version: 3.0
-Description: Old Interface between application and NDB
-Documentation:
-Adjust: 980126 UABMNST First version.
- 020826 EMIKRON New version adapted to new DICT version
- 040524 Magnus Svensson - Adapted to not be included in public NdbApi
- unless the user wants to use it.
-
- NOTE: This file is only used as a compatibility layer for old test programs,
- New programs should use NdbDictionary.hpp
-*********************************************************************/
-
-#include <ndb_global.h>
-#include <NdbApi.hpp>
-#include <NdbSchemaCon.hpp>
-#include <NdbSchemaOp.hpp>
-
-
-/*********************************************************************
-NdbSchemaCon(Ndb* aNdb);
-
-Parameters: aNdb: Pointers to the Ndb object
-Remark: Creates a schemacon object.
-************************************************************************************************/
-NdbSchemaCon::NdbSchemaCon( Ndb* aNdb ) :
- theNdb(aNdb),
- theFirstSchemaOpInList(NULL),
- theMagicNumber(0x75318642)
-{
- theError.code = 0;
-}//NdbSchemaCon::NdbSchemaCon()
-
-/*********************************************************************
-~NdbSchemaCon();
-
-Remark: Deletes the connection object.
-************************************************************************************************/
-NdbSchemaCon::~NdbSchemaCon()
-{
-}//NdbSchemaCon::~NdbSchemaCon()
-
-/*********************************************************************
-NdbSchemaOp* getNdbSchemaOp();
-
-Return Value Return a pointer to a NdbSchemaOp object if getNdbSchemaOp was sussesful.
- Return NULL: In all other case.
-Parameters: tableId : Id of the database table beeing deleted.
-************************************************************************************************/
-NdbSchemaOp*
-NdbSchemaCon::getNdbSchemaOp()
-{
- NdbSchemaOp* tSchemaOp;
- if (theFirstSchemaOpInList != NULL) {
- theError.code = 4401; // Only support one add table per transaction
- return NULL;
- }//if
- tSchemaOp = new NdbSchemaOp(theNdb);
- if ( tSchemaOp == NULL ) {
- theError.code = 4000; // Could not allocate schema operation
- return NULL;
- }//if
- theFirstSchemaOpInList = tSchemaOp;
- int retValue = tSchemaOp->init(this);
- if (retValue == -1) {
- release();
- theError.code = 4000; // Could not allocate buffer in schema operation
- return NULL;
- }//if
- return tSchemaOp;
-}//NdbSchemaCon::getNdbSchemaOp()
-
-/*********************************************************************
-int execute();
-
-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
-NdbSchemaCon::execute()
-{
- if(theError.code != 0) {
- return -1;
- }//if
-
- NdbSchemaOp* tSchemaOp;
-
- tSchemaOp = theFirstSchemaOpInList;
- if (tSchemaOp == NULL) {
- theError.code = 4402;
- return -1;
- }//if
-
- if ((tSchemaOp->sendRec() == -1) || (theError.code != 0)) {
- // Error Code already set in other place
- return -1;
- }//if
-
- return 0;
-}//NdbSchemaCon::execute()
-
-/*********************************************************************
-void release();
-
-Remark: Release all schemaop.
-************************************************************************************************/
-void
-NdbSchemaCon::release()
-{
- NdbSchemaOp* tSchemaOp;
- tSchemaOp = theFirstSchemaOpInList;
- if (tSchemaOp != NULL) {
- tSchemaOp->release();
- delete tSchemaOp;
- }//if
- theFirstSchemaOpInList = NULL;
- return;
-}//NdbSchemaCon::release()
-
-#include <NdbError.hpp>
-
-static void
-update(const NdbError & _err){
- NdbError & error = (NdbError &) _err;
- ndberror_struct ndberror = (ndberror_struct)error;
- ndberror_update(&ndberror);
- error = NdbError(ndberror);
-}
-
-const
-NdbError &
-NdbSchemaCon::getNdbError() const {
- update(theError);
- return theError;
-}
-
-
-
-
-
-
-
-
diff --git a/storage/ndb/test/src/NdbSchemaOp.cpp b/storage/ndb/test/src/NdbSchemaOp.cpp
deleted file mode 100644
index b713bedf0df..00000000000
--- a/storage/ndb/test/src/NdbSchemaOp.cpp
+++ /dev/null
@@ -1,219 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-/*****************************************************************************
-Name: NdbSchemaOp.cpp
-Include:
-Link:
-Author: UABMNST Mona Natterkvist UAB/B/SD
- EMIKRON Mikael Ronstrom
-Date: 040524
-Version: 3.0
-Description: Interface between application and NDB
-Documentation: Handles createTable and createAttribute calls
-
-Adjust: 980125 UABMNST First version.
- 020826 EMIKRON New version for new DICT
- 040524 Magnus Svensson - Adapted to not be included in public NdbApi
- unless the user wants to use it.
-
- NOTE: This file is only used as a compatibility layer for old test programs,
- New programs should use NdbDictionary.hpp
-*****************************************************************************/
-
-#include <ndb_global.h>
-#include <NdbApi.hpp>
-#include <NdbSchemaOp.hpp>
-#include <NdbSchemaCon.hpp>
-
-
-/*****************************************************************************
-NdbSchemaOp(Ndb* aNdb, Table* aTable);
-
-Return Value: None
-Parameters: aNdb: Pointers to the Ndb object.
- aTable: Pointers to the Table object
-Remark: Creat an object of NdbSchemaOp.
-*****************************************************************************/
-NdbSchemaOp::NdbSchemaOp(Ndb* aNdb) :
- theNdb(aNdb),
- theSchemaCon(NULL),
- m_currentTable(NULL)
-{
-}//NdbSchemaOp::NdbSchemaOp()
-
-/*****************************************************************************
-~NdbSchemaOp();
-
-Remark: Delete tables for connection pointers (id).
-*****************************************************************************/
-NdbSchemaOp::~NdbSchemaOp( )
-{
-}//~NdbSchemaOp::NdbSchemaOp()
-
-/*****************************************************************************
-int createTable( const char* tableName )
-*****************************************************************************/
-int
-NdbSchemaOp::createTable(const char* aTableName,
- Uint32 aTableSize,
- KeyType aTupleKey,
- int aNrOfPages,
- FragmentType aFragmentType,
- int aKValue,
- int aMinLoadFactor,
- int aMaxLoadFactor,
- int aMemoryType,
- bool aStoredTable)
-{
- if(m_currentTable != 0){
- return -1;
- }
-
- m_currentTable = new NdbDictionary::Table(aTableName);
- m_currentTable->setKValue(aKValue);
- m_currentTable->setMinLoadFactor(aMinLoadFactor);
- m_currentTable->setMaxLoadFactor(aMaxLoadFactor);
- m_currentTable->setLogging(aStoredTable);
- m_currentTable->setFragmentType(NdbDictionary::Object::FragAllMedium);
- return 0;
-}//NdbSchemaOp::createTable()
-
-/******************************************************************************
-int createAttribute( const char* anAttrName,
- KeyType aTupleyKey,
- int anAttrSize,
- int anArraySize,
- AttrType anAttrType,
- SafeType aSafeType,
- StorageMode aStorageMode,
- int aNullAttr,
- int aStorageAttr );
-
-******************************************************************************/
-int
-NdbSchemaOp::createAttribute( const char* anAttrName,
- KeyType aTupleKey,
- int anAttrSize,
- int anArraySize,
- AttrType anAttrType,
- StorageMode aStorageMode,
- bool nullable,
- int aStorageAttr,
- int aDistributionKeyFlag,
- int aDistributionGroupFlag,
- int aDistributionGroupNoOfBits,
- bool aAutoIncrement,
- const char* aDefaultValue)
-{
- if (m_currentTable == 0){
- return -1;
- }//if
-
- NdbDictionary::Column col(anAttrName);
- switch(anAttrType){
- case Signed:
- if(anAttrSize == 64)
- col.setType(NdbDictionary::Column::Bigint);
- else
- col.setType(NdbDictionary::Column::Int);
- break;
- case UnSigned:
- if(anAttrSize == 64)
- col.setType(NdbDictionary::Column::Bigunsigned);
- else
- col.setType(NdbDictionary::Column::Unsigned);
- break;
- case Float:
- if(anAttrSize == 64)
- col.setType(NdbDictionary::Column::Double);
- else
- col.setType(NdbDictionary::Column::Float);
- break;
- case String:
- col.setType(NdbDictionary::Column::Char);
- break;
- case NoAttrTypeDef:
- abort();
- }
- col.setLength(anArraySize);
- col.setNullable(nullable);
- if(aTupleKey != NoKey)
- col.setPrimaryKey(true);
- else
- col.setPrimaryKey(false);
-
- col.setDistributionKey(aDistributionKeyFlag);
- col.setAutoIncrement(aAutoIncrement);
- col.setDefaultValue(aDefaultValue != 0 ? aDefaultValue : "");
-
- m_currentTable->addColumn(col);
- return 0;
-}
-
-/******************************************************************************
-void release();
-
-Remark: Release all objects connected to the schemaop object.
-******************************************************************************/
-void
-NdbSchemaOp::release(){
-}//NdbSchemaOp::release()
-
-/******************************************************************************
-int sendRec()
-
-Return Value: Return 0 : send was succesful.
- Return -1: In all other case.
-Parameters:
-Remark: Send and receive signals for schema transaction based on state
-******************************************************************************/
-int
-NdbSchemaOp::sendRec(){
- int retVal = 0;
- if(m_currentTable == 0){
- retVal = -1;
- } else {
- retVal = theNdb->getDictionary()->createTable(* m_currentTable);
- delete m_currentTable;
- theSchemaCon->theError.code = theNdb->getDictionary()->getNdbError().code;
- }
-
- return retVal;
-}//NdbSchemaOp::sendRec()
-
-/******************************************************************************
-int init();
-
-Return Value: Return 0 : init was successful.
- Return -1: In all other case.
-Remark: Initiates SchemaOp record after allocation.
-******************************************************************************/
-int
-NdbSchemaOp::init(NdbSchemaCon* aSchemaCon)
-{
- theSchemaCon = aSchemaCon;
- return 0;
-}//NdbSchemaOp::init()
-
-
-const NdbError &
-NdbSchemaOp::getNdbError() const
-{
- return theSchemaCon->getNdbError();
-}
-
diff --git a/storage/ndb/test/src/UtilTransactions.cpp b/storage/ndb/test/src/UtilTransactions.cpp
deleted file mode 100644
index 5e4edb3585d..00000000000
--- a/storage/ndb/test/src/UtilTransactions.cpp
+++ /dev/null
@@ -1,1472 +0,0 @@
-/* Copyright (c) 2003-2005, 2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include "UtilTransactions.hpp"
-#include <NdbSleep.h>
-#include <NdbScanFilter.hpp>
-
-#define VERBOSE 0
-
-UtilTransactions::UtilTransactions(const NdbDictionary::Table& _tab,
- const NdbDictionary::Index* _idx):
- tab(_tab), idx(_idx), pTrans(0)
-{
- m_defaultClearMethod = 3;
-}
-
-UtilTransactions::UtilTransactions(Ndb* ndb,
- const char * name,
- const char * index) :
- tab(* ndb->getDictionary()->getTable(name)),
- idx(index ? ndb->getDictionary()->getIndex(index, name) : 0),
- pTrans(0)
-{
- m_defaultClearMethod = 3;
-}
-
-#define RESTART_SCAN 99
-
-#define RETURN_FAIL(err) return (err.code != 0 ? err.code : NDBT_FAILED)
-
-int
-UtilTransactions::clearTable(Ndb* pNdb,
- NdbScanOperation::ScanFlag flags,
- int records,
- int parallelism){
- // Scan all records exclusive and delete
- // them one by one
- int retryAttempt = 0;
- const int retryMax = 10;
- int deletedRows = 0;
- int check;
- NdbScanOperation *pOp;
- NdbError err;
-
- int par = parallelism;
- while (true){
- restart:
- if (retryAttempt++ >= retryMax){
- g_info << "ERROR: has retried this operation " << retryAttempt
- << " times, failing!" << endl;
- return NDBT_FAILED;
- }
-
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- err = pNdb->getNdbError();
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- NdbSleep_MilliSleep(50);
- continue;
- }
- goto failed;
- }
-
- pOp = getScanOperation(pTrans);
- if (pOp == NULL) {
- err = pTrans->getNdbError();
- if(err.status == NdbError::TemporaryError){
- ERR(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- par = 1;
- goto restart;
- }
- goto failed;
- }
-
- if( pOp->readTuples(NdbOperation::LM_Exclusive, flags, par) ) {
- err = pTrans->getNdbError();
- goto failed;
- }
-
- if(pTrans->execute(NoCommit, AbortOnError) != 0){
- err = pTrans->getNdbError();
- if(err.status == NdbError::TemporaryError){
- ERR(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- continue;
- }
- goto failed;
- }
-
- while((check = pOp->nextResult(true)) == 0){
- do {
- if (pOp->deleteCurrentTuple() != 0){
- goto failed;
- }
- deletedRows++;
- } while((check = pOp->nextResult(false)) == 0);
-
- if(check != -1){
- check = pTrans->execute(Commit, AbortOnError);
- pTrans->restart();
- }
-
- err = pTrans->getNdbError();
- if(check == -1){
- if(err.status == NdbError::TemporaryError){
- ERR(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- par = 1;
- goto restart;
- }
- goto failed;
- }
- }
- if(check == -1){
- err = pTrans->getNdbError();
- if(err.status == NdbError::TemporaryError){
- ERR(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- par = 1;
- goto restart;
- }
- goto failed;
- }
- closeTransaction(pNdb);
- return NDBT_OK;
- }
- return NDBT_FAILED;
-
- failed:
- if(pTrans != 0) closeTransaction(pNdb);
- ERR(err);
- return (err.code != 0 ? err.code : NDBT_FAILED);
-}
-
-int
-UtilTransactions::clearTable(Ndb* pNdb,
- int records,
- int parallelism){
-
- return clearTable(pNdb, (NdbScanOperation::ScanFlag)0,
- records, parallelism);
-}
-
-
-int
-UtilTransactions::clearTable1(Ndb* pNdb,
- int records,
- int parallelism)
-{
- return clearTable(pNdb, (NdbScanOperation::ScanFlag)0,
- records, 1);
-}
-
-int
-UtilTransactions::clearTable2(Ndb* pNdb,
- int records,
- int parallelism)
-{
- return clearTable(pNdb, (NdbScanOperation::ScanFlag)0,
- records, parallelism);
-}
-
-int
-UtilTransactions::clearTable3(Ndb* pNdb,
- int records,
- int parallelism)
-{
- return clearTable(pNdb, (NdbScanOperation::ScanFlag)0,
- records, parallelism);
-}
-
-int
-UtilTransactions::copyTableData(Ndb* pNdb,
- const char* destName){
- // Scan all records and copy
- // them to destName table
- int retryAttempt = 0;
- const int retryMax = 10;
- int insertedRows = 0;
- int parallelism = 240;
- int check;
- NdbScanOperation *pOp;
- NDBT_ResultRow row(tab);
-
- while (true){
-
- if (retryAttempt >= retryMax){
- g_info << "ERROR: has retried this operation " << retryAttempt
- << " times, failing!" << endl;
- return NDBT_FAILED;
- }
-
-
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- const NdbError err = pNdb->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- return NDBT_FAILED;
- }
-
- pOp = pTrans->getNdbScanOperation(tab.getName());
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- if( pOp->readTuples(NdbScanOperation::LM_Read, parallelism) ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- check = pOp->interpret_exit_ok();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- // Read all attributes
- for (int a = 0; a < tab.getNoOfColumns(); a++){
- if ((row.attributeStore(a) =
- pOp->getValue(tab.getColumn(a)->getName())) == 0) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- }
-
- check = pTrans->execute(NoCommit, AbortOnError);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- int eof;
- while((eof = pOp->nextResult(true)) == 0){
- do {
- insertedRows++;
- if (addRowToInsert(pNdb, pTrans, row, destName) != 0){
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- } while((eof = pOp->nextResult(false)) == 0);
-
- check = pTrans->execute(Commit, AbortOnError);
- pTrans->restart();
- if( check == -1 ) {
- const NdbError err = pTrans->getNdbError();
- ERR(err);
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- }
- if (eof == -1) {
- const NdbError err = pTrans->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- // If error = 488 there should be no limit on number of retry attempts
- if (err.code != 488)
- retryAttempt++;
- continue;
- }
- ERR(err);
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- closeTransaction(pNdb);
-
- g_info << insertedRows << " rows copied" << endl;
-
- return NDBT_OK;
- }
- return NDBT_FAILED;
-}
-
-int
-UtilTransactions::addRowToInsert(Ndb* pNdb,
- NdbConnection* pInsTrans,
- NDBT_ResultRow & row,
- const char *insertTabName){
-
- int check;
- NdbOperation* pInsOp;
-
- pInsOp = pInsTrans->getNdbOperation(insertTabName);
- if (pInsOp == NULL) {
- ERR(pInsTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- check = pInsOp->insertTuple();
- if( check == -1 ) {
- ERR(pInsTrans->getNdbError());
- return NDBT_FAILED;
- }
-
- // Set all attributes
- for (int a = 0; a < tab.getNoOfColumns(); a++){
- NdbRecAttr* r = row.attributeStore(a);
- int sz = r->get_size_in_bytes();
- if (pInsOp->setValue(tab.getColumn(a)->getName(),
- r->aRef(),
- sz) != 0) {
- ERR(pInsTrans->getNdbError());
- return NDBT_FAILED;
- }
- }
-
- return NDBT_OK;
-}
-
-
-int
-UtilTransactions::scanReadRecords(Ndb* pNdb,
- int parallelism,
- NdbOperation::LockMode lm,
- int records,
- int noAttribs,
- int *attrib_list,
- ReadCallBackFn* fn){
-
- int retryAttempt = 0;
- const int retryMax = 100;
- int check;
- NdbScanOperation *pOp;
- NDBT_ResultRow row(tab);
-
- while (true){
-
- if (retryAttempt >= retryMax){
- g_info << "ERROR: has retried this operation " << retryAttempt
- << " times, failing!" << endl;
- return NDBT_FAILED;
- }
-
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- const NdbError err = pNdb->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- return NDBT_FAILED;
- }
-
- pOp = getScanOperation(pTrans);
- if (pOp == NULL) {
- const NdbError err = pNdb->getNdbError();
- closeTransaction(pNdb);
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- return NDBT_FAILED;
- }
-
- if( pOp->readTuples(lm, 0, parallelism) ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- check = pOp->interpret_exit_ok();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- // Call getValue for all the attributes supplied in attrib_list
- // ************************************************
- for (int a = 0; a < noAttribs; a++){
- if (attrib_list[a] < tab.getNoOfColumns()){
- g_info << "getValue(" << attrib_list[a] << ")" << endl;
- if ((row.attributeStore(attrib_list[a]) =
- pOp->getValue(tab.getColumn(attrib_list[a])->getName())) == 0) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- }
- }
- // *************************************************
-
- check = pTrans->execute(NoCommit, AbortOnError);
- if( check == -1 ) {
- const NdbError err = pTrans->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- int eof;
- int rows = 0;
-
-
- while((eof = pOp->nextResult()) == 0){
- rows++;
-
- // Call callback for each record returned
- if(fn != NULL)
- fn(&row);
- }
- if (eof == -1) {
- const NdbError err = pTrans->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- closeTransaction(pNdb);
- g_info << rows << " rows have been read" << endl;
- if (records != 0 && rows != records){
- g_info << "Check expected number of records failed" << endl
- << " expected=" << records <<", " << endl
- << " read=" << rows << endl;
- return NDBT_FAILED;
- }
-
- return NDBT_OK;
- }
- return NDBT_FAILED;
-}
-
-int
-UtilTransactions::selectCount(Ndb* pNdb,
- int parallelism,
- int* count_rows,
- NdbOperation::LockMode lm,
- NdbConnection* pTrans){
-
- int retryAttempt = 0;
- const int retryMax = 100;
- int check;
- NdbScanOperation *pOp;
-
- if(!pTrans)
- pTrans = pNdb->startTransaction();
-
- while (true){
-
- if (retryAttempt >= retryMax){
- g_info << "ERROR: has retried this operation " << retryAttempt
- << " times, failing!" << endl;
- return NDBT_FAILED;
- }
- pOp = getScanOperation(pTrans);
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- if( pOp->readTuples(lm) ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- if(0){
- NdbScanFilter sf(pOp);
- sf.begin(NdbScanFilter::OR);
- sf.eq(2, (Uint32)30);
- sf.end();
- } else {
- check = pOp->interpret_exit_ok();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- }
-
-
- check = pTrans->execute(NoCommit, AbortOnError);
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- int eof;
- int rows = 0;
-
-
- while((eof = pOp->nextResult()) == 0){
- rows++;
- }
- if (eof == -1) {
- const NdbError err = pTrans->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- closeTransaction(pNdb);
-
- if (count_rows != NULL){
- *count_rows = rows;
- }
-
- return NDBT_OK;
- }
- return NDBT_FAILED;
-}
-
-int
-UtilTransactions::verifyIndex(Ndb* pNdb,
- const char* indexName,
- int parallelism,
- bool transactional){
-
-
- const NdbDictionary::Index* pIndex
- = pNdb->getDictionary()->getIndex(indexName, tab.getName());
- if (pIndex == 0){
- ndbout << " Index " << indexName << " does not exist!" << endl;
- return NDBT_FAILED;
- }
-
- switch (pIndex->getType()){
- case NdbDictionary::Index::UniqueHashIndex:
- return verifyUniqueIndex(pNdb, pIndex, parallelism, transactional);
- case NdbDictionary::Index::OrderedIndex:
- return verifyOrderedIndex(pNdb, pIndex, parallelism, transactional);
- break;
- default:
- ndbout << "Unknown index type" << endl;
- break;
- }
-
- return NDBT_FAILED;
-}
-
-int
-UtilTransactions::verifyUniqueIndex(Ndb* pNdb,
- const NdbDictionary::Index * pIndex,
- int parallelism,
- bool transactional){
-
- /**
- * Scan all rows in TABLE and for each found row make one read in
- * TABLE and one using INDEX_TABLE. Then compare the two returned
- * rows. They should be equal!
- *
- */
-
- if (scanAndCompareUniqueIndex(pNdb,
- pIndex,
- parallelism,
- transactional) != NDBT_OK){
- return NDBT_FAILED;
- }
-
-
- return NDBT_OK;
-
-}
-
-
-int
-UtilTransactions::scanAndCompareUniqueIndex(Ndb* pNdb,
- const NdbDictionary::Index* pIndex,
- int parallelism,
- bool transactional){
-
- int retryAttempt = 0;
- const int retryMax = 100;
- int check;
- NdbScanOperation *pOp;
- NDBT_ResultRow row(tab);
-
- parallelism = 1;
-
- while (true){
-restart:
- if (retryAttempt >= retryMax){
- g_info << "ERROR: has retried this operation " << retryAttempt
- << " times, failing!" << endl;
- return NDBT_FAILED;
- }
-
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- const NdbError err = pNdb->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- return NDBT_FAILED;
- }
-
- pOp = pTrans->getNdbScanOperation(tab.getName());
- if (pOp == NULL) {
- const NdbError err = pNdb->getNdbError();
- closeTransaction(pNdb);
- ERR(err);
-
- if (err.status == NdbError::TemporaryError){
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- return NDBT_FAILED;
- }
-
- int rs;
- if(transactional){
- rs = pOp->readTuples(NdbScanOperation::LM_Read, 0, parallelism);
- } else {
- rs = pOp->readTuples(NdbScanOperation::LM_CommittedRead, 0, parallelism);
- }
-
- if( rs != 0 ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- check = pOp->interpret_exit_ok();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- // Read all attributes
- for (int a = 0; a < tab.getNoOfColumns(); a++){
- if ((row.attributeStore(a) =
- pOp->getValue(tab.getColumn(a)->getName())) == 0) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- }
-
- check = pTrans->execute(NoCommit, AbortOnError);
- if( check == -1 ) {
- const NdbError err = pTrans->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- int eof;
- int rows = 0;
-
-
- while((eof = pOp->nextResult()) == 0){
- rows++;
-
- // ndbout << row.c_str().c_str() << endl;
-
- if (readRowFromTableAndIndex(pNdb,
- pTrans,
- pIndex,
- row) != NDBT_OK){
-
- while((eof= pOp->nextResult(false)) == 0);
- if(eof == 2)
- eof = pOp->nextResult(true); // this should give -1
- if(eof == -1)
- {
- const NdbError err = pTrans->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- goto restart;
- }
- }
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- }
- if (eof == -1) {
- const NdbError err = pTrans->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- closeTransaction(pNdb);
-
- return NDBT_OK;
- }
- return NDBT_FAILED;
-}
-int
-UtilTransactions::readRowFromTableAndIndex(Ndb* pNdb,
- NdbConnection* scanTrans,
- const NdbDictionary::Index* pIndex,
- NDBT_ResultRow& row ){
-
-
- NdbDictionary::Index::Type indexType= pIndex->getType();
- int retryAttempt = 0;
- const int retryMax = 100;
- int check, a;
- NdbConnection *pTrans1=NULL;
- NdbOperation *pOp;
-
- int return_code= NDBT_FAILED;
-
- // Allocate place to store the result
- NDBT_ResultRow tabRow(tab);
- NDBT_ResultRow indexRow(tab);
- const char * indexName = pIndex->getName();
-
- while (true){
- if(retryAttempt)
- ndbout_c("retryAttempt %d", retryAttempt);
- if (retryAttempt >= retryMax){
- g_info << "ERROR: has retried this operation " << retryAttempt
- << " times, failing!" << endl;
- goto close_all;
- }
-
- pTrans1 = pNdb->hupp(scanTrans); //startTransaction();
- if (pTrans1 == NULL) {
- const NdbError err = pNdb->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
-
- if(err.code == 0){
- return_code = NDBT_OK;
- goto close_all;
- }
- ERR(err);
- goto close_all;
- }
-
- /**
- * Read the record from TABLE
- */
- pOp = pTrans1->getNdbOperation(tab.getName());
- if (pOp == NULL) {
- ERR(pTrans1->getNdbError());
- goto close_all;
- }
-
- check = pOp->readTuple();
- if( check == -1 ) {
- ERR(pTrans1->getNdbError());
- goto close_all;
- }
-
- // Define primary keys
-#if VERBOSE
- printf("PK: ");
-#endif
- for(a = 0; a<tab.getNoOfColumns(); a++){
- const NdbDictionary::Column* attr = tab.getColumn(a);
- if (attr->getPrimaryKey() == true){
- if (pOp->equal(attr->getName(), row.attributeStore(a)->aRef()) != 0){
- ERR(pTrans1->getNdbError());
- goto close_all;
- }
-#if VERBOSE
- printf("%s = %d: ", attr->getName(), row.attributeStore(a)->aRef());
-#endif
- }
- }
-#if VERBOSE
- printf("\n");
-#endif
- // Read all attributes
-#if VERBOSE
- printf("Reading %u attributes: ", tab.getNoOfColumns());
-#endif
- for(a = 0; a<tab.getNoOfColumns(); a++){
- if((tabRow.attributeStore(a) =
- pOp->getValue(tab.getColumn(a)->getName())) == 0) {
- ERR(pTrans1->getNdbError());
- goto close_all;
- }
-#if VERBOSE
- printf("%s ", tab.getColumn(a)->getName());
-#endif
- }
-#if VERBOSE
- printf("\n");
-#endif
-
- /**
- * Read the record from INDEX_TABLE
- */
- NdbIndexOperation* pIndexOp= NULL;
- NdbIndexScanOperation *pScanOp= NULL;
- NdbOperation *pIOp= 0;
-
- bool null_found= false;
- for(a = 0; a<(int)pIndex->getNoOfColumns(); a++){
- const NdbDictionary::Column * col = pIndex->getColumn(a);
-
- if (row.attributeStore(col->getName())->isNULL())
- {
- null_found= true;
- break;
- }
- }
-
- const char * tabName= tab.getName();
- if(!null_found)
- {
- if (indexType == NdbDictionary::Index::UniqueHashIndex) {
- pIOp= pIndexOp= pTrans1->getNdbIndexOperation(indexName, tabName);
- } else {
- pIOp= pScanOp= pTrans1->getNdbIndexScanOperation(indexName, tabName);
- }
-
- if (pIOp == NULL) {
- ERR(pTrans1->getNdbError());
- goto close_all;
- }
-
- {
- bool not_ok;
- if (pIndexOp) {
- not_ok = pIndexOp->readTuple() == -1;
- } else {
- not_ok = pScanOp->readTuples();
- }
-
- if( not_ok ) {
- ERR(pTrans1->getNdbError());
- goto close_all;
- }
- }
-
- // Define primary keys for index
-#if VERBOSE
- printf("SI: ");
-#endif
- for(a = 0; a<(int)pIndex->getNoOfColumns(); a++){
- const NdbDictionary::Column * col = pIndex->getColumn(a);
-
- int r;
- if ( !row.attributeStore(col->getName())->isNULL() ) {
- if(pIOp->equal(col->getName(),
- row.attributeStore(col->getName())->aRef()) != 0){
- ERR(pTrans1->getNdbError());
- goto close_all;
- }
- }
-#if VERBOSE
- printf("%s = %d: ", col->getName(), row.attributeStore(a)->aRef());
-#endif
- }
-#if VERBOSE
- printf("\n");
-#endif
-
- // Read all attributes
-#if VERBOSE
- printf("Reading %u attributes: ", tab.getNoOfColumns());
-#endif
- for(a = 0; a<tab.getNoOfColumns(); a++){
- void* pCheck;
-
- pCheck= indexRow.attributeStore(a)=
- pIOp->getValue(tab.getColumn(a)->getName());
-
- if(pCheck == NULL) {
- ERR(pTrans1->getNdbError());
- goto close_all;
- }
-#if VERBOSE
- printf("%s ", tab.getColumn(a)->getName());
-#endif
- }
- }
-#if VERBOSE
- printf("\n");
-#endif
- scanTrans->refresh();
- check = pTrans1->execute(Commit, AbortOnError);
- if( check == -1 ) {
- const NdbError err = pTrans1->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- pNdb->closeTransaction(pTrans1);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ndbout << "Error when comparing records - normal op" << endl;
- ERR(err);
- ndbout << "row: " << row.c_str().c_str() << endl;
- goto close_all;
- }
-
- /**
- * Compare the two rows
- */
- if(!null_found){
- if (pScanOp) {
- if (pScanOp->nextResult() != 0){
- const NdbError err = pTrans1->getNdbError();
- ERR(err);
- ndbout << "Error when comparing records - index op next_result missing" << endl;
- ndbout << "row: " << row.c_str().c_str() << endl;
- goto close_all;
- }
- }
- if (!(tabRow.c_str() == indexRow.c_str())){
- ndbout << "Error when comapring records" << endl;
- ndbout << " tabRow: \n" << tabRow.c_str().c_str() << endl;
- ndbout << " indexRow: \n" << indexRow.c_str().c_str() << endl;
- goto close_all;
- }
- if (pScanOp) {
- if (pScanOp->nextResult() == 0){
- ndbout << "Error when comparing records - index op next_result to many" << endl;
- ndbout << "row: " << row.c_str().c_str() << endl;
- goto close_all;
- }
- }
- }
- return_code= NDBT_OK;
- goto close_all;
- }
-
-close_all:
- if (pTrans1)
- pNdb->closeTransaction(pTrans1);
-
- return return_code;
-}
-
-int
-UtilTransactions::verifyOrderedIndex(Ndb* pNdb,
- const NdbDictionary::Index* pIndex,
- int parallelism,
- bool transactional){
-
- int retryAttempt = 0;
- const int retryMax = 100;
- int check;
- NdbScanOperation *pOp;
- NdbIndexScanOperation * iop = 0;
-
- NDBT_ResultRow scanRow(tab);
- NDBT_ResultRow pkRow(tab);
- NDBT_ResultRow indexRow(tab);
- const char * indexName = pIndex->getName();
-
- int res;
- parallelism = 1;
-
- while (true){
-
- if (retryAttempt >= retryMax){
- g_info << "ERROR: has retried this operation " << retryAttempt
- << " times, failing!" << endl;
- return NDBT_FAILED;
- }
-
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- const NdbError err = pNdb->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- return NDBT_FAILED;
- }
-
- pOp = pTrans->getNdbScanOperation(tab.getName());
- if (pOp == NULL) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- if( pOp->readTuples(NdbScanOperation::LM_Read, 0, parallelism) ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- check = pOp->interpret_exit_ok();
- if( check == -1 ) {
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- if(get_values(pOp, scanRow))
- {
- abort();
- }
-
- check = pTrans->execute(NoCommit, AbortOnError);
- if( check == -1 ) {
- const NdbError err = pTrans->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- continue;
- }
- ERR(err);
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- int eof;
- int rows = 0;
- while(check == 0 && (eof = pOp->nextResult()) == 0){
- rows++;
-
- bool null_found= false;
- for(int a = 0; a<(int)pIndex->getNoOfColumns(); a++){
- const NdbDictionary::Column * col = pIndex->getColumn(a);
- if (scanRow.attributeStore(col->getName())->isNULL())
- {
- null_found= true;
- break;
- }
- }
-
- // Do pk lookup
- NdbOperation * pk = pTrans->getNdbOperation(tab.getName());
- if(!pk || pk->readTuple())
- goto error;
- if(equal(&tab, pk, scanRow) || get_values(pk, pkRow))
- goto error;
-
- if(!null_found)
- {
- if(!iop && (iop= pTrans->getNdbIndexScanOperation(indexName,
- tab.getName())))
- {
- if(iop->readTuples(NdbScanOperation::LM_CommittedRead,
- parallelism))
- goto error;
- iop->interpret_exit_ok();
- if(get_values(iop, indexRow))
- goto error;
- }
- else if(!iop || iop->reset_bounds())
- {
- goto error;
- }
-
- if(equal(pIndex, iop, scanRow))
- goto error;
- }
-
- check = pTrans->execute(NoCommit, AbortOnError);
- if(check)
- goto error;
-
- if(scanRow.c_str() != pkRow.c_str()){
- g_err << "Error when comapring records" << endl;
- g_err << " scanRow: \n" << scanRow.c_str().c_str() << endl;
- g_err << " pkRow: \n" << pkRow.c_str().c_str() << endl;
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- if(!null_found)
- {
-
- if((res= iop->nextResult()) != 0){
- g_err << "Failed to find row using index: " << res << endl;
- ERR(pTrans->getNdbError());
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- if(scanRow.c_str() != indexRow.c_str()){
- g_err << "Error when comapring records" << endl;
- g_err << " scanRow: \n" << scanRow.c_str().c_str() << endl;
- g_err << " indexRow: \n" << indexRow.c_str().c_str() << endl;
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- if(iop->nextResult() == 0){
- g_err << "Found extra row!!" << endl;
- g_err << " indexRow: \n" << indexRow.c_str().c_str() << endl;
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
- }
- }
-
- if (eof == -1 || check == -1) {
- error:
- const NdbError err = pTrans->getNdbError();
-
- if (err.status == NdbError::TemporaryError){
- ERR(err);
- iop = 0;
- closeTransaction(pNdb);
- NdbSleep_MilliSleep(50);
- retryAttempt++;
- rows--;
- continue;
- }
- ERR(err);
- closeTransaction(pNdb);
- return NDBT_FAILED;
- }
-
- closeTransaction(pNdb);
-
- return NDBT_OK;
- }
- return NDBT_FAILED;
-}
-
-int
-UtilTransactions::get_values(NdbOperation* op, NDBT_ResultRow& dst)
-{
- for (int a = 0; a < tab.getNoOfColumns(); a++){
- NdbRecAttr*& ref= dst.attributeStore(a);
- if ((ref= op->getValue(a)) == 0)
- {
- return NDBT_FAILED;
- }
- }
- return 0;
-}
-
-int
-UtilTransactions::equal(const NdbDictionary::Index* pIndex,
- NdbOperation* op, const NDBT_ResultRow& src)
-{
- for(Uint32 a = 0; a<pIndex->getNoOfColumns(); a++){
- const NdbDictionary::Column * col = pIndex->getColumn(a);
- if(op->equal(col->getName(),
- src.attributeStore(col->getName())->aRef()) != 0){
- return NDBT_FAILED;
- }
- }
- return 0;
-}
-
-int
-UtilTransactions::equal(const NdbDictionary::Table* pTable,
- NdbOperation* op, const NDBT_ResultRow& src)
-{
- for(Uint32 a = 0; a<tab.getNoOfColumns(); a++){
- const NdbDictionary::Column* attr = tab.getColumn(a);
- if (attr->getPrimaryKey() == true){
- if (op->equal(attr->getName(), src.attributeStore(a)->aRef()) != 0){
- return NDBT_FAILED;
- }
- }
- }
- return 0;
-}
-
-NdbScanOperation*
-UtilTransactions::getScanOperation(NdbConnection* pTrans)
-{
- return (NdbScanOperation*)
- getOperation(pTrans, NdbOperation::OpenScanRequest);
-}
-
-NdbOperation*
-UtilTransactions::getOperation(NdbConnection* pTrans,
- NdbOperation::OperationType type)
-{
- switch(type){
- case NdbOperation::ReadRequest:
- case NdbOperation::ReadExclusive:
- if(idx)
- {
- switch(idx->getType()){
- case NdbDictionary::Index::UniqueHashIndex:
- return pTrans->getNdbIndexOperation(idx->getName(), tab.getName());
- case NdbDictionary::Index::OrderedIndex:
- return pTrans->getNdbIndexScanOperation(idx->getName(), tab.getName());
- }
- }
- case NdbOperation::InsertRequest:
- case NdbOperation::WriteRequest:
- return pTrans->getNdbOperation(tab.getName());
- case NdbOperation::UpdateRequest:
- case NdbOperation::DeleteRequest:
- if(idx)
- {
- switch(idx->getType()){
- case NdbDictionary::Index::UniqueHashIndex:
- return pTrans->getNdbIndexOperation(idx->getName(), tab.getName());
- }
- }
- return pTrans->getNdbOperation(tab.getName());
- case NdbOperation::OpenScanRequest:
- if(idx)
- {
- switch(idx->getType()){
- case NdbDictionary::Index::OrderedIndex:
- return pTrans->getNdbIndexScanOperation(idx->getName(), tab.getName());
- }
- }
- return pTrans->getNdbScanOperation(tab.getName());
- case NdbOperation::OpenRangeScanRequest:
- if(idx)
- {
- switch(idx->getType()){
- case NdbDictionary::Index::OrderedIndex:
- return pTrans->getNdbIndexScanOperation(idx->getName(), tab.getName());
- }
- }
- return 0;
- }
-}
-
-#include <HugoOperations.hpp>
-
-int
-UtilTransactions::closeTransaction(Ndb* pNdb)
-{
- if (pTrans != NULL){
- pNdb->closeTransaction(pTrans);
- pTrans = NULL;
- }
- return 0;
-}
-
-int
-UtilTransactions::compare(Ndb* pNdb, const char* tab_name2, int flags){
-
-
- NdbError err;
- int return_code= 0, row_count= 0;
- int retryAttempt = 0, retryMax = 10;
-
- HugoCalculator calc(tab);
- NDBT_ResultRow row(tab);
- const NdbDictionary::Table* tmp= pNdb->getDictionary()->getTable(tab_name2);
- if(tmp == 0)
- {
- g_err << "Unable to lookup table: " << tab_name2
- << endl << pNdb->getDictionary()->getNdbError() << endl;
- return -1;
- }
- const NdbDictionary::Table& tab2= *tmp;
-
- HugoOperations cmp(tab2);
- UtilTransactions count(tab2);
-
- while (true){
-loop:
- if (retryAttempt++ >= retryMax){
- g_err << "ERROR: compare has retried this operation " << retryAttempt
- << " times, failing!" << endl;
- return -1;
- }
-
- NdbScanOperation *pOp= 0;
- pTrans = pNdb->startTransaction();
- if (pTrans == NULL) {
- err = pNdb->getNdbError();
- goto error;
- }
-
- pOp= pTrans->getNdbScanOperation(tab.getName());
- if (pOp == NULL) {
- ERR(err= pTrans->getNdbError());
- goto error;
- }
-
- if( pOp->readTuples(NdbScanOperation::LM_Read) ) {
- ERR(err= pTrans->getNdbError());
- goto error;
- }
-
- if( pOp->interpret_exit_ok() == -1 ) {
- ERR(err= pTrans->getNdbError());
- goto error;
- }
-
- // Read all attributes
- {
- for (int a = 0; a < tab.getNoOfColumns(); a++){
- if ((row.attributeStore(a) =
- pOp->getValue(tab.getColumn(a)->getName())) == 0) {
- ERR(err= pTrans->getNdbError());
- goto error;
- }
- }
- }
-
- if( pTrans->execute(NoCommit, AbortOnError) == -1 ) {
- ERR(err= pTrans->getNdbError());
- goto error;
- }
-
- row_count= 0;
- {
- int eof;
- while((eof = pOp->nextResult(true)) == 0)
- {
- do {
- row_count++;
- if(cmp.startTransaction(pNdb) != NDBT_OK)
- {
- ERR(err= pNdb->getNdbError());
- goto error;
- }
- int rowNo= calc.getIdValue(&row);
- if(cmp.pkReadRecord(pNdb, rowNo, 1) != NDBT_OK)
- {
- ERR(err= cmp.getTransaction()->getNdbError());
- goto error;
- }
- if(cmp.execute_Commit(pNdb) != NDBT_OK ||
- cmp.getTransaction()->getNdbError().code)
- {
- ERR(err= cmp.getTransaction()->getNdbError());
- goto error;
- }
- if(row != cmp.get_row(0))
- {
- g_err << "COMPARE FAILED" << endl;
- g_err << row << endl;
- g_err << cmp.get_row(0) << endl;
- return_code++;
- }
- retryAttempt= 0;
- cmp.closeTransaction(pNdb);
- } while((eof = pOp->nextResult(false)) == 0);
- }
- if (eof == -1)
- {
- err = pTrans->getNdbError();
- goto error;
- }
- }
-
- closeTransaction(pNdb);
-
- g_info << row_count << " rows compared" << endl;
- {
- int row_count2;
- if(count.selectCount(pNdb, 0, &row_count2) != NDBT_OK)
- {
- g_err << "Failed to count rows in tab_name2" << endl;
- return -1;
- }
-
- g_info << row_count2 << " rows in tab_name2 - failed " << return_code
- << endl;
- return (row_count == row_count2 ? return_code : 1);
- }
-error:
- if(err.status == NdbError::TemporaryError)
- {
- g_err << err << endl;
- NdbSleep_MilliSleep(50);
- closeTransaction(pNdb);
- if(cmp.getTransaction())
- cmp.closeTransaction(pNdb);
-
- goto loop;
- }
- g_err << "ERROR" << endl;
- g_err << err << endl;
-
- break;
- }
-
-close:
- closeTransaction(pNdb);
-
- return return_code;
-}
-
diff --git a/storage/ndb/test/src/getarg.c b/storage/ndb/test/src/getarg.c
deleted file mode 100644
index 5b67eb6343d..00000000000
--- a/storage/ndb/test/src/getarg.c
+++ /dev/null
@@ -1,608 +0,0 @@
-/* -*- c-basic-offset: 4; -*- */
-/*
- * Copyright (c) 1997 - 2000 Kungliga Tekniska Högskolan
- * (Royal Institute of Technology, Stockholm, Sweden).
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <ndb_global.h>
-
-#include "getarg.h"
-#include <basestring_vsnprintf.h>
-
-#ifndef HAVE_STRLCPY
-static size_t
-strlcpy (char *dst, const char *src, size_t dst_sz)
-{
- size_t n;
- char *p;
- for (p = dst, n = 0;
- n + 1 < dst_sz && *src != '\0';
- ++p, ++src, ++n)
- *p = *src;
- *p = '\0';
- if (*src == '\0')
- return n;
- else
- return n + strlen (src);
-}
-#endif
-#ifndef HAVE_STRLCAT
-static size_t
-strlcat (char *dst, const char *src, size_t dst_sz)
-{
- size_t len = strlen(dst);
- return len + strlcpy (dst + len, src, dst_sz - len);
-}
-#endif
-
-#define ISFLAG(X) ((X).type == arg_flag || (X).type == arg_negative_flag)
-
-#ifndef max
-#define max(a, b) (a) > (b) ? (a) : (b)
-#endif
-
-#ifdef HAVE___PROGNAME
-extern char *__progname;
-#endif
-
-#ifndef TRUE
-#define TRUE 1
-#endif
-
-#ifndef FALSE
-#define FALSE 0
-#endif
-
-char *
-strupr(char *str)
-{
- char *s;
-
- for(s = str; *s; s++)
- *s = toupper(*s);
- return str;
-}
-
-static size_t
-print_arg (char *string, size_t len, int mdoc, int longp, struct getargs *arg)
-{
- const char *s;
-
- *string = '\0';
-
- if (ISFLAG(*arg) || (!longp && arg->type == arg_counter))
- return 0;
-
- if(mdoc){
- if(longp)
- strlcat(string, "= Ns", len);
- strlcat(string, " Ar ", len);
- }else
- if (longp)
- strlcat (string, "=", len);
- else
- strlcat (string, " ", len);
-
- if (arg->arg_help)
- s = arg->arg_help;
- else if (arg->type == arg_integer || arg->type == arg_counter)
- s = "integer";
- else if (arg->type == arg_string)
- s = "string";
- else if (arg->type == arg_double)
- s = "float";
- else
- s = "<undefined>";
-
- strlcat(string, s, len);
- return 1 + strlen(s);
-}
-
-#ifdef GETARGMANDOC
-static void
-mandoc_template(struct getargs *args,
- size_t num_args,
- const char *progname,
- const char *extra_string)
-{
- size_t i;
- char timestr[64], cmd[64];
- char buf[128];
- const char *p;
- time_t t;
-
- printf(".\\\" Things to fix:\n");
- printf(".\\\" * correct section, and operating system\n");
- printf(".\\\" * remove Op from mandatory flags\n");
- printf(".\\\" * use better macros for arguments (like .Pa for files)\n");
- printf(".\\\"\n");
- t = time(NULL);
- strftime(timestr, sizeof(timestr), "%B %e, %Y", localtime(&t));
- printf(".Dd %s\n", timestr);
- p = strrchr(progname, '/');
- if(p) p++; else p = progname;
- strlcpy(cmd, p, sizeof(cmd));
- strupr(cmd);
-
- printf(".Dt %s SECTION\n", cmd);
- printf(".Os OPERATING_SYSTEM\n");
- printf(".Sh NAME\n");
- printf(".Nm %s\n", p);
- printf(".Nd\n");
- printf("in search of a description\n");
- printf(".Sh SYNOPSIS\n");
- printf(".Nm\n");
- for(i = 0; i < num_args; i++){
- /* we seem to hit a limit on number of arguments if doing
- short and long flags with arguments -- split on two lines */
- if(ISFLAG(args[i]) ||
- args[i].short_name == 0 || args[i].long_name == NULL) {
- printf(".Op ");
-
- if(args[i].short_name) {
- print_arg(buf, sizeof(buf), 1, 0, args + i);
- printf("Fl %c%s", args[i].short_name, buf);
- if(args[i].long_name)
- printf(" | ");
- }
- if(args[i].long_name) {
- print_arg(buf, sizeof(buf), 1, 1, args + i);
- printf("Fl -%s%s%s",
- args[i].type == arg_negative_flag ? "no-" : "",
- args[i].long_name, buf);
- }
- printf("\n");
- } else {
- print_arg(buf, sizeof(buf), 1, 0, args + i);
- printf(".Oo Fl %c%s \\*(Ba Xo\n", args[i].short_name, buf);
- print_arg(buf, sizeof(buf), 1, 1, args + i);
- printf(".Fl -%s%s Oc\n.Xc\n", args[i].long_name, buf);
- }
- /*
- if(args[i].type == arg_strings)
- fprintf (stderr, "...");
- */
- }
- if (extra_string && *extra_string)
- printf (".Ar %s\n", extra_string);
- printf(".Sh DESCRIPTION\n");
- printf("Supported options:\n");
- printf(".Bl -tag -width Ds\n");
- for(i = 0; i < num_args; i++){
- printf(".It Xo\n");
- if(args[i].short_name){
- printf(".Fl %c", args[i].short_name);
- print_arg(buf, sizeof(buf), 1, 0, args + i);
- printf("%s", buf);
- if(args[i].long_name)
- printf(" Ns ,");
- printf("\n");
- }
- if(args[i].long_name){
- printf(".Fl -%s%s",
- args[i].type == arg_negative_flag ? "no-" : "",
- args[i].long_name);
- print_arg(buf, sizeof(buf), 1, 1, args + i);
- printf("%s\n", buf);
- }
- printf(".Xc\n");
- if(args[i].help)
- printf("%s\n", args[i].help);
- /*
- if(args[i].type == arg_strings)
- fprintf (stderr, "...");
- */
- }
- printf(".El\n");
- printf(".\\\".Sh ENVIRONMENT\n");
- printf(".\\\".Sh FILES\n");
- printf(".\\\".Sh EXAMPLES\n");
- printf(".\\\".Sh DIAGNOSTICS\n");
- printf(".\\\".Sh SEE ALSO\n");
- printf(".\\\".Sh STANDARDS\n");
- printf(".\\\".Sh HISTORY\n");
- printf(".\\\".Sh AUTHORS\n");
- printf(".\\\".Sh BUGS\n");
-}
-#endif /* GETARGMANDOC */
-
-static int
-check_column(FILE *f, int col, int len, int columns)
-{
- if(col + len > columns) {
- fprintf(f, "\n");
- col = fprintf(f, " ");
- }
- return col;
-}
-
-void
-arg_printusage (struct getargs *args,
- size_t num_args,
- const char *progname,
- const char *extra_string)
-{
- unsigned int i;
- size_t max_len = 0;
- char buf[128];
- int col = 0, columns;
-
-#ifdef HAVE___PROGNAME
- if (progname == NULL)
- progname = __progname;
-#endif
- if (progname == NULL)
- progname = "";
-
-#ifdef GETARGMANDOC
- if(getenv("GETARGMANDOC")){
- mandoc_template(args, num_args, progname, extra_string);
- return;
- }
-#endif
-
- columns = 80; /* Always assume that the window is 80 chars wide */
- col = 0;
- col += fprintf (stderr, "Usage: %s", progname);
- for (i = 0; i < num_args; ++i) {
- size_t len = 0;
-
- if (args[i].long_name) {
- buf[0] = '\0';
- strlcat(buf, "[--", sizeof(buf));
- len += 2;
- if(args[i].type == arg_negative_flag) {
- strlcat(buf, "no-", sizeof(buf));
- len += 3;
- }
- strlcat(buf, args[i].long_name, sizeof(buf));
- len += strlen(args[i].long_name);
- len += print_arg(buf + strlen(buf), sizeof(buf) - strlen(buf),
- 0, 1, &args[i]);
- strlcat(buf, "]", sizeof(buf));
- if(args[i].type == arg_strings)
- strlcat(buf, "...", sizeof(buf));
- col = check_column(stderr, col, strlen(buf) + 1, columns);
- col += fprintf(stderr, " %s", buf);
- }
- if (args[i].short_name) {
- basestring_snprintf(buf, sizeof(buf), "[-%c", args[i].short_name);
- len += 2;
- len += print_arg(buf + strlen(buf), sizeof(buf) - strlen(buf),
- 0, 0, &args[i]);
- strlcat(buf, "]", sizeof(buf));
- if(args[i].type == arg_strings)
- strlcat(buf, "...", sizeof(buf));
- col = check_column(stderr, col, strlen(buf) + 1, columns);
- col += fprintf(stderr, " %s", buf);
- }
- if (args[i].long_name && args[i].short_name)
- len += 2; /* ", " */
- max_len = max(max_len, len);
- }
- if (extra_string) {
- col = check_column(stderr, col, strlen(extra_string) + 1, columns);
- fprintf (stderr, " %s\n", extra_string);
- } else
- fprintf (stderr, "\n");
- for (i = 0; i < num_args; ++i) {
- if (args[i].help) {
- size_t count = 0;
-
- if (args[i].short_name) {
- count += fprintf (stderr, "-%c", args[i].short_name);
- print_arg (buf, sizeof(buf), 0, 0, &args[i]);
- count += fprintf(stderr, "%s", buf);
- }
- if (args[i].short_name && args[i].long_name)
- count += fprintf (stderr, ", ");
- if (args[i].long_name) {
- count += fprintf (stderr, "--");
- if (args[i].type == arg_negative_flag)
- count += fprintf (stderr, "no-");
- count += fprintf (stderr, "%s", args[i].long_name);
- print_arg (buf, sizeof(buf), 0, 1, &args[i]);
- count += fprintf(stderr, "%s", buf);
- }
- while(count++ <= max_len)
- putc (' ', stderr);
- fprintf (stderr, "%s\n", args[i].help);
- }
- }
-}
-
-static void
-add_string(getarg_strings *s, char *value)
-{
- s->strings = realloc(s->strings, (s->num_strings + 1) * sizeof(*s->strings));
- s->strings[s->num_strings] = value;
- s->num_strings++;
-}
-
-static int
-arg_match_long(struct getargs *args, size_t num_args,
- char *argv, int argc, const char **rargv, int *optind)
-{
- unsigned int i;
- const char *optarg = NULL;
- int negate = 0;
- int partial_match = 0;
- struct getargs *partial = NULL;
- struct getargs *current = NULL;
- int argv_len;
- char *p;
-
- argv_len = strlen(argv);
- p = strchr (argv, '=');
- if (p != NULL)
- argv_len = p - argv;
-
- for (i = 0; i < num_args; ++i) {
- if(args[i].long_name) {
- int len = strlen(args[i].long_name);
- char *p = argv;
- int p_len = argv_len;
- negate = 0;
-
- for (;;) {
- if (strncmp (args[i].long_name, p, p_len) == 0) {
- if(p_len == len)
- current = &args[i];
- else {
- ++partial_match;
- partial = &args[i];
- }
- optarg = p + p_len;
- } else if (ISFLAG(args[i]) && strncmp (p, "no-", 3) == 0) {
- negate = !negate;
- p += 3;
- p_len -= 3;
- continue;
- }
- break;
- }
- if (current)
- break;
- }
- }
- if (current == NULL) {
- if (partial_match == 1)
- current = partial;
- else
- return ARG_ERR_NO_MATCH;
- }
-
- if(*optarg == '\0'
- && !ISFLAG(*current)
- && current->type != arg_collect
- && current->type != arg_counter)
- return ARG_ERR_NO_MATCH;
- switch(current->type){
- case arg_integer:
- {
- int tmp;
- if(sscanf(optarg + 1, "%d", &tmp) != 1)
- return ARG_ERR_BAD_ARG;
- *(int*)current->value = tmp;
- return 0;
- }
- case arg_string:
- {
- *(char**)current->value = (char*)optarg + 1;
- return 0;
- }
- case arg_strings:
- {
- add_string((getarg_strings*)current->value, (char*)optarg + 1);
- return 0;
- }
- case arg_flag:
- case arg_negative_flag:
- {
- int *flag = current->value;
- if(*optarg == '\0' ||
- strcmp(optarg + 1, "yes") == 0 ||
- strcmp(optarg + 1, "true") == 0){
- *flag = !negate;
- return 0;
- } else if (*optarg && strcmp(optarg + 1, "maybe") == 0) {
- *flag = rand() & 1;
- } else {
- *flag = negate;
- return 0;
- }
- return ARG_ERR_BAD_ARG;
- }
- case arg_counter :
- {
- int val;
-
- if (*optarg == '\0')
- val = 1;
- else {
- char *endstr;
-
- val = strtol (optarg, &endstr, 0);
- if (endstr == optarg)
- return ARG_ERR_BAD_ARG;
- }
- *(int *)current->value += val;
- return 0;
- }
- case arg_double:
- {
- double tmp;
- if(sscanf(optarg + 1, "%lf", &tmp) != 1)
- return ARG_ERR_BAD_ARG;
- *(double*)current->value = tmp;
- return 0;
- }
- case arg_collect:{
- struct getarg_collect_info *c = current->value;
- int o = argv - rargv[*optind];
- return (*c->func)(FALSE, argc, rargv, optind, &o, c->data);
- }
-
- default:
- abort ();
- }
-}
-
-static int
-arg_match_short (struct getargs *args, size_t num_args,
- char *argv, int argc, const char **rargv, int *optind)
-{
- int j, k;
-
- for(j = 1; j > 0 && j < (int)strlen(rargv[*optind]); j++) {
- for(k = 0; k < (int)num_args; k++) {
- char *optarg;
-
- if(args[k].short_name == 0)
- continue;
- if(argv[j] == args[k].short_name) {
- if(args[k].type == arg_flag) {
- *(int*)args[k].value = 1;
- break;
- }
- if(args[k].type == arg_negative_flag) {
- *(int*)args[k].value = 0;
- break;
- }
- if(args[k].type == arg_counter) {
- ++*(int *)args[k].value;
- break;
- }
- if(args[k].type == arg_collect) {
- struct getarg_collect_info *c = args[k].value;
-
- if((*c->func)(TRUE, argc, rargv, optind, &j, c->data))
- return ARG_ERR_BAD_ARG;
- break;
- }
-
- if(argv[j + 1])
- optarg = &argv[j + 1];
- else {
- ++*optind;
- optarg = (char *) rargv[*optind];
- }
- if(optarg == NULL) {
- --*optind;
- return ARG_ERR_NO_ARG;
- }
- if(args[k].type == arg_integer) {
- int tmp;
- if(sscanf(optarg, "%d", &tmp) != 1)
- return ARG_ERR_BAD_ARG;
- *(int*)args[k].value = tmp;
- return 0;
- } else if(args[k].type == arg_string) {
- *(char**)args[k].value = optarg;
- return 0;
- } else if(args[k].type == arg_strings) {
- add_string((getarg_strings*)args[k].value, optarg);
- return 0;
- } else if(args[k].type == arg_double) {
- double tmp;
- if(sscanf(optarg, "%lf", &tmp) != 1)
- return ARG_ERR_BAD_ARG;
- *(double*)args[k].value = tmp;
- return 0;
- }
- return ARG_ERR_BAD_ARG;
- }
- }
- if (k == (int)num_args)
- return ARG_ERR_NO_MATCH;
- }
- return 0;
-}
-
-int
-getarg(struct getargs *args, size_t num_args,
- int argc, const char **argv, int *optind)
-{
- int i;
- int ret = 0;
-
- srand (time(NULL));
- (*optind)++;
- for(i = *optind; i < argc; i++) {
- if(argv[i][0] != '-')
- break;
- if(argv[i][1] == '-'){
- if(argv[i][2] == 0){
- i++;
- break;
- }
- ret = arg_match_long (args, num_args, (char *) argv[i] + 2,
- argc, argv, &i);
- } else {
- ret = arg_match_short (args, num_args, (char *) argv[i],
- argc, argv, &i);
- }
- if(ret)
- break;
- }
- *optind = i;
- return ret;
-}
-
-
-#if TEST
-int foo_flag = 2;
-int flag1 = 0;
-int flag2 = 0;
-int bar_int;
-char *baz_string;
-
-struct getargs args[] = {
- { NULL, '1', arg_flag, &flag1, "one", NULL },
- { NULL, '2', arg_flag, &flag2, "two", NULL },
- { "foo", 'f', arg_negative_flag, &foo_flag, "foo", NULL },
- { "bar", 'b', arg_integer, &bar_int, "bar", "seconds"},
- { "baz", 'x', arg_string, &baz_string, "baz", "name" },
-};
-
-int main(int argc, char **argv)
-{
- int optind = 0;
- while(getarg(args, 5, argc, argv, &optind))
- printf("Bad arg: %s\n", argv[optind]);
- printf("flag1 = %d\n", flag1);
- printf("flag2 = %d\n", flag2);
- printf("foo_flag = %d\n", foo_flag);
- printf("bar_int = %d\n", bar_int);
- printf("baz_flag = %s\n", baz_string);
- arg_printusage (args, 5, argv[0], "nothing here");
-}
-#endif
diff --git a/storage/ndb/test/tools/Makefile.am b/storage/ndb/test/tools/Makefile.am
deleted file mode 100644
index 33117ea8a54..00000000000
--- a/storage/ndb/test/tools/Makefile.am
+++ /dev/null
@@ -1,47 +0,0 @@
-# Copyright (C) 2004-2005 MySQL AB
-# Use is subject to license terms
-#
-# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-ndbtest_PROGRAMS = hugoLoad hugoFill hugoLockRecords hugoPkDelete hugoPkRead hugoPkReadRecord hugoPkUpdate hugoScanRead hugoScanUpdate restart verify_index copy_tab create_index ndb_cpcc listen_event eventlog rep_latency ndb_connect
-
-# transproxy
-
-hugoFill_SOURCES = hugoFill.cpp
-hugoLoad_SOURCES = hugoLoad.cpp
-hugoLockRecords_SOURCES = hugoLockRecords.cpp
-hugoPkDelete_SOURCES = hugoPkDelete.cpp
-hugoPkRead_SOURCES = hugoPkRead.cpp
-hugoPkReadRecord_SOURCES = hugoPkReadRecord.cpp
-hugoPkUpdate_SOURCES = hugoPkUpdate.cpp
-hugoScanRead_SOURCES = hugoScanRead.cpp
-hugoScanUpdate_SOURCES = hugoScanUpdate.cpp
-restart_SOURCES = restart.cpp
-# transproxy_SOURCES = transproxy.cpp
-verify_index_SOURCES = verify_index.cpp
-copy_tab_SOURCES = copy_tab.cpp
-create_index_SOURCES = create_index.cpp
-ndb_cpcc_SOURCES = cpcc.cpp
-listen_event_SOURCES = listen.cpp
-eventlog_SOURCES = log_listner.cpp
-rep_latency_SOURCES = rep_latency.cpp
-ndb_connect_SOURCES = connect.cpp
-
-include $(top_srcdir)/storage/ndb/config/common.mk.am
-include $(top_srcdir)/storage/ndb/config/type_ndbapitest.mk.am
-
-ndb_cpcc_LDADD = $(LDADD)
-ndb_cpcc_LDFLAGS = -static
-
-windoze-dsp:
diff --git a/storage/ndb/test/tools/connect.cpp b/storage/ndb/test/tools/connect.cpp
deleted file mode 100644
index 947cca95d46..00000000000
--- a/storage/ndb/test/tools/connect.cpp
+++ /dev/null
@@ -1,151 +0,0 @@
-/* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-#include <ndb_opts.h>
-#include <NDBT.hpp>
-#include <NdbApi.hpp>
-#include <NdbSleep.h>
-
-NDB_STD_OPTS_VARS;
-
-static int _loop = 25;
-static int _sleep = 25;
-static int _drop = 1;
-
-typedef uchar* gptr;
-
-static struct my_option my_long_options[] =
-{
- NDB_STD_OPTS("ndb_desc"),
- { "loop", 'l', "loops",
- &_loop, &_loop, 0,
- GET_INT, REQUIRED_ARG, _loop, 0, 0, 0, 0, 0 },
- { "sleep", 's', "Sleep (ms) between connection attempt",
- &_sleep, &_sleep, 0,
- GET_INT, REQUIRED_ARG, _sleep, 0, 0, 0, 0, 0 },
- { "drop", 'd',
- "Drop event operations before disconnect (0 = no, 1 = yes, else rand",
- &_drop, &_drop, 0,
- GET_INT, REQUIRED_ARG, _drop, 0, 0, 0, 0, 0 },
- { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
-};
-
-static void usage()
-{
- char desc[] = "This program connects to ndbd, and then disconnects\n";
- ndb_std_print_version();
- my_print_help(my_long_options);
- my_print_variables(my_long_options);
-}
-
-int main(int argc, char** argv){
- NDB_INIT(argv[0]);
-
- const char *load_default_groups[]= { "mysql_cluster",0 };
- load_defaults("my",load_default_groups,&argc,&argv);
- int ho_error;
-#ifndef DBUG_OFF
- opt_debug= "d:t:O,/tmp/ndb_desc.trace";
-#endif
- if ((ho_error=handle_options(&argc, &argv, my_long_options,
- ndb_std_get_one_option)))
- return NDBT_ProgramExit(NDBT_WRONGARGS);
-
- for (int i = 0; i<_loop; i++)
- {
- Ndb_cluster_connection con(opt_connect_str);
- if(con.connect(12, 5, 1) != 0)
- {
- ndbout << "Unable to connect to management server." << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- if (con.wait_until_ready(30,30) != 0)
- {
- ndbout << "Cluster nodes not ready in 30 seconds." << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- Ndb MyNdb(&con, "TEST_DB");
- if(MyNdb.init() != 0){
- ERR(MyNdb.getNdbError());
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- Vector<NdbEventOperation*> ops;
- const NdbDictionary::Dictionary * dict= MyNdb.getDictionary();
- for (int j = 0; j < argc; j++)
- {
- const NdbDictionary::Table * pTab = dict->getTable(argv[j]);
- if (pTab == 0)
- {
- ndbout_c("Failed to retreive table: \"%s\"", argv[j]);
- }
-
- BaseString tmp;
- tmp.appfmt("EV-%s", argv[j]);
- NdbEventOperation* pOp = MyNdb.createEventOperation(tmp.c_str());
- if ( pOp == NULL )
- {
- ndbout << "Event operation creation failed: " <<
- MyNdb.getNdbError() << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- for (int a = 0; a < pTab->getNoOfColumns(); a++)
- {
- pOp->getValue(pTab->getColumn(a)->getName());
- pOp->getPreValue(pTab->getColumn(a)->getName());
- }
-
- if (pOp->execute())
- {
- ndbout << "operation execution failed: " << pOp->getNdbError()
- << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- ops.push_back(pOp);
- }
-
- if (_sleep)
- {
- NdbSleep_MilliSleep(10 + rand() % _sleep);
- }
-
- for (Uint32 i = 0; i<ops.size(); i++)
- {
- switch(_drop){
- case 0:
- break;
- do_drop:
- case 1:
- if (MyNdb.dropEventOperation(ops[i]))
- {
- ndbout << "drop event operation failed "
- << MyNdb.getNdbError() << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- break;
- default:
- if ((rand() % 100) > 50)
- goto do_drop;
- }
- }
- }
-
- return NDBT_ProgramExit(NDBT_OK);
-}
-
-template class Vector<NdbEventOperation*>;
diff --git a/storage/ndb/test/tools/copy_tab.cpp b/storage/ndb/test/tools/copy_tab.cpp
deleted file mode 100644
index fe54b4c9c41..00000000000
--- a/storage/ndb/test/tools/copy_tab.cpp
+++ /dev/null
@@ -1,103 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-
-#include <NdbOut.hpp>
-#include <NdbApi.hpp>
-#include <NDBT.hpp>
-#include "UtilTransactions.hpp"
-
-#include <getarg.h>
-
-int main(int argc, const char** argv){
- ndb_init();
-
- const char* _tabname = NULL;
- const char* _to_tabname = NULL;
- const char* _dbname = "TEST_DB";
- const char* _connectstr = NULL;
- int _copy_data = true;
- int _help = 0;
-
- struct getargs args[] = {
- { "database", 'd', arg_string, &_dbname, "dbname",
- "Name of database table is in"},
- { "connstr", 'c', arg_string, &_connectstr, "connect string",
- "How to connect to NDB"},
- { "copy-data", '\0', arg_negative_flag, &_copy_data, "Don't copy data to new table",
- "How to connect to NDB"},
- { "usage", '?', arg_flag, &_help, "Print help", "" }
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "srctab desttab\n"\
- "This program will copy one table in Ndb\n";
-
- if(getarg(args, num_args, argc, argv, &optind) ||
- argv[optind] == NULL || argv[optind + 1] == NULL || _help){
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
- _tabname = argv[optind];
- _to_tabname = argv[optind+1];
-
- Ndb_cluster_connection con(_connectstr);
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- Ndb MyNdb(&con,_dbname);
- if(MyNdb.init() != 0){
- ERR(MyNdb.getNdbError());
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- while(MyNdb.waitUntilReady() != 0)
- ndbout << "Waiting for ndb to become ready..." << endl;
-
- ndbout << "Copying table " << _tabname << " to " << _to_tabname << "...";
- const NdbDictionary::Table* ptab = MyNdb.getDictionary()->getTable(_tabname);
- if (ptab){
- NdbDictionary::Table tab2(*ptab);
- tab2.setName(_to_tabname);
- if (MyNdb.getDictionary()->createTable(tab2) != 0){
- ndbout << endl << MyNdb.getDictionary()->getNdbError() << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- } else {
- ndbout << endl << MyNdb.getDictionary()->getNdbError() << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- ndbout << "OK" << endl;
- if (_copy_data){
- ndbout << "Copying data..."<<endl;
- const NdbDictionary::Table * tab3 =
- NDBT_Table::discoverTableFromDb(&MyNdb,
- _tabname);
- // if (!tab3)
-
- UtilTransactions util(*tab3);
-
- if(util.copyTableData(&MyNdb,
- _to_tabname) != NDBT_OK){
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- ndbout << "OK" << endl;
- }
- return NDBT_ProgramExit(NDBT_OK);
-}
diff --git a/storage/ndb/test/tools/cpcc.cpp b/storage/ndb/test/tools/cpcc.cpp
deleted file mode 100644
index 8cd7f5f8f61..00000000000
--- a/storage/ndb/test/tools/cpcc.cpp
+++ /dev/null
@@ -1,352 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-#include <ndb_global.h>
-#include <getarg.h>
-#include "CpcClient.hpp"
-#include <NdbEnv.h>
-
-#define DEFAULT_PORT 1234
-#define ENV_HOSTS "NDB_CPCC_HOSTS"
-
-struct settings {
- int m_longl;
- short m_port;
-} g_settings = { 0 , DEFAULT_PORT };
-
-Vector<SimpleCpcClient*> g_hosts;
-int connect(Vector<SimpleCpcClient*>&);
-
-class Expression {
-public:
- virtual bool evaluate(SimpleCpcClient*, const SimpleCpcClient::Process &)= 0;
-};
-
-int for_each(Vector<SimpleCpcClient*>& list, Expression &);
-int start_stop(const char * cmd, Vector<SimpleCpcClient*>& list,
- Vector<Vector<Uint32> >& procs);
-
-class True : public Expression {
-public:
- virtual bool evaluate(SimpleCpcClient*, const SimpleCpcClient::Process & p){
- return true;
- }
-};
-
-class FieldEQ : public Expression {
- BaseString m_field;
- BaseString m_value;
-public:
- FieldEQ(const BaseString & field, const BaseString & value){
- m_field = field;
- m_value = value;
- }
- virtual ~FieldEQ(){}
-
- virtual bool evaluate(SimpleCpcClient*, const SimpleCpcClient::Process & p){
- BaseString v;
- if(m_field == "name") v = p.m_name;
-
- if(m_field == "type") v = p.m_type;
- if(m_field == "status") v = p.m_status;
- if(m_field == "owner") v = p.m_owner;
- if(m_field == "group") v = p.m_group;
- if(m_field == "path") v = p.m_path;
- if(m_field == "args") v = p.m_args;
- if(m_field == "env") v = p.m_env;
- if(m_field == "cwd") v = p.m_cwd;
-
- if(m_field == "stdin") v = p.m_stdin;
- if(m_field == "stdout") v = p.m_stdout;
- if(m_field == "stderr") v = p.m_stderr;
-
- return v == m_value;
- }
-};
-
-class Match : public Expression {
- Expression & m_cond;
- Expression & m_apply;
-public:
- Match(Expression& condition, Expression & rule)
- : m_cond(condition), m_apply(rule) {
- }
- virtual ~Match(){}
-
- virtual bool evaluate(SimpleCpcClient* c,const SimpleCpcClient::Process & p){
- if(m_cond.evaluate(c, p))
- return m_apply.evaluate(c, p);
- return false;
- }
-};
-
-class Operate : public Expression {
- const char * cmd;
- SimpleCpcClient * host;
- settings & sets;
-public:
- Operate(const char * c, settings & s) : sets(s) {
- cmd = c;
- host = 0;
- }
-
- virtual bool evaluate(SimpleCpcClient*, const SimpleCpcClient::Process & p);
-};
-
-class ProcEQ : public Expression {
- SimpleCpcClient * host;
- Uint32 id;
-public:
- ProcEQ(SimpleCpcClient* h, Uint32 i){
- host = h; id = i;
- }
-
- virtual bool evaluate(SimpleCpcClient* c,const SimpleCpcClient::Process & p){
- return p.m_id == (int)id && c == host;
- }
-};
-
-class OrExpr : public Expression {
- Expression * m_rule;
- Vector<Expression *> m_cond;
- bool on_empty;
-public:
- OrExpr(Expression * rule, bool onEmp = true){
- m_rule = rule;
- on_empty = onEmp;
- }
-
- virtual ~OrExpr(){}
-
- virtual bool evaluate(SimpleCpcClient* c, const SimpleCpcClient::Process & p){
- bool run = on_empty;
- for(size_t i = 0; i<m_cond.size(); i++){
- if(m_cond[i]->evaluate(c, p)){
- run = true;
- break;
- }
- }
- if(run)
- return m_rule->evaluate(c, p);
- return false;
- }
-
- void push_back(Expression * expr){
- m_cond.push_back(expr);
- }
-};
-
-void
-add_host(Vector<SimpleCpcClient*> & hosts, BaseString tmp){
- Vector<BaseString> split;
- tmp.split(split, ":");
-
- short port = g_settings.m_port;
- if(split.size() > 1)
- port = atoi(split[1].c_str());
-
- hosts.push_back(new SimpleCpcClient(split[0].c_str(), port));
-}
-
-void
-add_hosts(Vector<SimpleCpcClient*> & hosts, BaseString list){
- Vector<BaseString> split;
- list.split(split);
- for(size_t i = 0; i<split.size(); i++){
- add_host(hosts, split[i]);
- }
-}
-
-int
-main(int argc, const char** argv){
- ndb_init();
- int help = 0;
- const char *cmd=0, *name=0, *group=0, *owner=0;
- int list = 0, start = 0, stop = 0, rm = 0;
- struct getargs args[] = {
- { "cmd", 'c', arg_string, &cmd, "command", "command to run (default ls)" }
- ,{ "name", 'n', arg_string, &name,
- "apply command for all processes with name" }
- ,{ "group", 'g', arg_string, &group,
- "apply command for all processes in group" }
- ,{ "owner", 'g', arg_string, &owner,
- "apply command for all processes with owner" }
- ,{ "long", 'l', arg_flag, &g_settings.m_longl, "long", "long listing"}
- ,{ "usage", '?', arg_flag, &help, "Print help", "" }
- ,{ "ls", 0, arg_flag, &list, "-c list", "list process(es)" }
- ,{ "start", 0, arg_flag, &start, "-c start", "start process(es)" }
- ,{ "stop", 0, arg_flag, &stop, "-c stop", "stop process(es)" }
- ,{ "rm", 0, arg_flag, &rm, "-c rm", "undefine process(es)" }
- };
- const int num_args = 10;
- int i;
- int optind = 0;
- char desc[] = "[host:[port]]\n";
-
- if(getarg(args, num_args, argc, argv, &optind) || help) {
- arg_printusage(args, num_args, argv[0], desc);
- return 1;
- }
-
- if(list + start + stop + rm > 1){
- ndbout_c("Can only specify one command");
- arg_printusage(args, num_args, argv[0], desc);
- return 1;
- }
-
- if(list) cmd = "list";
- if(start) cmd = "start";
- if(stop) cmd = "stop";
- if(rm) cmd = "rm";
- if(!cmd) cmd = "list";
-
- Expression * m_expr = 0;
-
- for(i = optind; i<argc; i++){
- add_host(g_hosts, argv[i]);
- }
-
- OrExpr * orE = new OrExpr(new Operate(cmd, g_settings), true);
- m_expr = orE;
- for(i = optind; i<argc; i++){
- BaseString tmp(argv[i]);
- Vector<BaseString> split;
- tmp.split(split, ":");
-
- if(split.size() > 2){
- Uint32 id = atoi(split[2].c_str());
- orE->push_back(new ProcEQ(g_hosts[i-optind], id));
- }
- }
-
- if(g_hosts.size() == 0){
- char buf[1024];
- if(NdbEnv_GetEnv(ENV_HOSTS, buf, sizeof(buf))){
- add_hosts(g_hosts, BaseString(buf));
- }
- }
-
- if(g_hosts.size() == 0){
- g_hosts.push_back(new SimpleCpcClient("localhost", g_settings.m_port));
- }
-
- if(group != 0){
- Expression * tmp = new FieldEQ("group", group);
- m_expr = new Match(* tmp, * m_expr);
- }
-
- if(name != 0){
- Expression * tmp = new FieldEQ("name", name);
- m_expr = new Match(* tmp, * m_expr);
- }
-
- if(owner != 0){
- Expression * tmp = new FieldEQ("owner", owner);
- m_expr = new Match(* tmp, * m_expr);
- }
-
- connect(g_hosts);
- for_each(g_hosts, * m_expr);
-
- return 0;
-}
-
-int
-connect(Vector<SimpleCpcClient*>& list){
- for(size_t i = 0; i<list.size(); i++){
- if(list[i]->connect() != 0){
- ndbout_c("Failed to connect to %s:%d",
- list[i]->getHost(), list[i]->getPort());
- delete list[i]; list[i] = 0;
- }
- }
- return 0;
-}
-
-int
-for_each(Vector<SimpleCpcClient*>& list, Expression & expr){
- for(size_t i = 0; i<list.size(); i++){
- if(list[i] == 0)
- continue;
- Properties p;
- Vector<SimpleCpcClient::Process> procs;
- if(list[i]->list_processes(procs, p) != 0){
- ndbout << "Failed to list processes on "
- << list[i]->getHost() << ":" << list[i]->getPort() << endl;
- }
- for(size_t j = 0; j<procs.size(); j++)
- expr.evaluate(list[i], procs[j]);
- }
- return 0;
-}
-
-bool
-Operate::evaluate(SimpleCpcClient* c, const SimpleCpcClient::Process & pp){
- Uint32 id = pp.m_id;
- Properties p;
- int res;
-
- if(strcasecmp(cmd, "start") == 0)
- res = c->start_process(id, p);
- else if(strcasecmp(cmd, "stop") == 0)
- res = c->stop_process(id, p);
- else if(strcasecmp(cmd, "rm") == 0)
- res = c->undefine_process(id, p);
- else if(strcasecmp(cmd, "list") == 0){
- if(!sets.m_longl){
- if(host != c){
- ndbout_c("--- %s:%d", c->getHost(), c->getPort());
- host = c;
- }
- }
-
- char s = 0;
- const char * status = pp.m_status.c_str();
- if(strcmp(status, "stopped") == 0) s = '-';
- if(strcmp(status, "starting") == 0) s = 's';
- if(strcmp(status, "running") == 0) s = 'r';
- if(strcmp(status, "stopping") == 0) s = 'k';
- if(s == 0) s = '?';
-
- if(!sets.m_longl){
- ndbout_c("%c%c\t%d\t%s\t%s\t%s(%s)",
- s,
- pp.m_type.c_str()[0], id, pp.m_owner.c_str(),
- pp.m_group.c_str(), pp.m_name.c_str(), pp.m_path.c_str());
- } else {
- ndbout_c("%c%c %s:%d:%d %s %s %s(%s)",
- s, pp.m_type.c_str()[0], c->getHost(), c->getPort(),
- id, pp.m_owner.c_str(), pp.m_group.c_str(),
- pp.m_name.c_str(), pp.m_path.c_str());
- }
- return true;
- }
-
- if(res != 0){
- BaseString msg;
- p.get("errormessage", msg);
- ndbout_c("Failed to %s %d on %s:%d - %s",
- cmd, id,
- c->getHost(), c->getPort(), msg.c_str());
- return false;
- }
-
- return true;
-}
-
-template class Vector<Expression*>;
-template class Vector<SimpleCpcClient*>;
diff --git a/storage/ndb/test/tools/create_index.cpp b/storage/ndb/test/tools/create_index.cpp
deleted file mode 100644
index 992034a5085..00000000000
--- a/storage/ndb/test/tools/create_index.cpp
+++ /dev/null
@@ -1,111 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-
-#include <NdbOut.hpp>
-#include <NdbApi.hpp>
-#include <NDBT.hpp>
-
-#include <getarg.h>
-
-
-
-int
-main(int argc, const char** argv){
- ndb_init();
-
- const char* _dbname = "TEST_DB";
- int _help = 0;
- int _ordered = 0, _pk = 1;
-
- struct getargs args[] = {
- { "database", 'd', arg_string, &_dbname, "dbname",
- "Name of database table is in"},
- { "ordered", 'o', arg_flag, &_ordered, "Create ordered index", "" },
- { "pk", 'p', arg_flag, &_pk, "Create index on primary key", "" },
- { "usage", '?', arg_flag, &_help, "Print help", "" }
- };
-
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "<tabname>+\n"\
- "This program will create one unique hash index named ind_<tabname> "
- " for each table. The index will contain all columns in the table";
-
- if(getarg(args, num_args, argc, argv, &optind) || _help ||
- argv[optind] == NULL){
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- Ndb MyNdb(&con, _dbname);
- if(MyNdb.init() != 0){
- ERR(MyNdb.getNdbError());
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- while(MyNdb.waitUntilReady() != 0)
- ndbout << "Waiting for ndb to become ready..." << endl;
-
- NdbDictionary::Dictionary * dict = MyNdb.getDictionary();
-
- for(int i = optind; i<argc; i++){
- const NdbDictionary::Table * tab = dict->getTable(argv[i]);
- if(tab == 0){
- g_err << "Unknown table: " << argv[i] << endl;
- continue;
- }
-
- if(tab->getNoOfColumns() > 16){
- g_err << "Table " << argv[i] << " has more than 16 columns" << endl;
- }
-
- NdbDictionary::Index ind;
- if(_ordered){
- ind.setType(NdbDictionary::Index::OrderedIndex);
- ind.setLogging(false);
- } else {
- ind.setType(NdbDictionary::Index::UniqueHashIndex);
- }
- char buf[512];
- sprintf(buf, "IND_%s_%s_%c",
- argv[i], (_pk ? "PK" : "FULL"), (_ordered ? 'O' : 'U'));
- ind.setName(buf);
- ind.setTable(argv[i]);
- for(int c = 0; c<tab->getNoOfColumns(); c++){
- if(!_pk || tab->getColumn(c)->getPrimaryKey())
- ind.addIndexColumn(tab->getColumn(c)->getName());
- }
- ndbout << "creating index " << buf << " on table " << argv[i] << "...";
- const int res = dict->createIndex(ind);
- if(res != 0)
- ndbout << endl << dict->getNdbError() << endl;
- else
- ndbout << "OK" << endl;
- }
-
- return NDBT_ProgramExit(NDBT_OK);
-}
-
-
diff --git a/storage/ndb/test/tools/hugoCalculator.cpp b/storage/ndb/test/tools/hugoCalculator.cpp
deleted file mode 100644
index 964e898f6ed..00000000000
--- a/storage/ndb/test/tools/hugoCalculator.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-#include <ndb_global.h>
-
-#include <NdbOut.hpp>
-#include <NdbSleep.h>
-#include <NDBT_Tables.hpp>
-#include <getarg.h>
-#include <NDBT.hpp>
-#include <HugoCalculator.hpp>
-
-//extern NdbOut g_info;
-
-int main(int argc, const char** argv)
-{
- ndb_init();
- int _row = 0;
- int _column = 0;
- int _updates = 0;
- const char* _tableName = NULL;
-
- struct getargs args[] = {
- { "row", 'r', arg_integer, &_row, "The row number", "row" },
- { "column", 'c', arg_integer, &_column, "The column id", "column" },
- { "updates", 'u', arg_integer, &_updates, "# of updates", "updates" }
- };
-
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
-
- if(getarg(args, num_args, argc, argv, &optind) || argv[optind] == NULL) {
- arg_printusage(args, num_args, argv[0], "table name\n");
- return NDBT_WRONGARGS;
- }
- // Check if table name is supplied
- if (argv[optind] != NULL)
- _tableName = argv[optind];
-
-
- const NdbDictionary::Table* table = NDBT_Tables::getTable(_tableName);
- const NdbDictionary::Column * attribute = table->getColumn(_column);
-
- g_info << "Table " << _tableName << endl
- << "Row: " << _row << ", "
- << "Column(" << attribute->getName() << ")"
- << "[" << attribute->getType() << "]"
- << ", Updates: " << _updates
- << endl;
-
- HugoCalculator calc(*table);
- char buf[8000];
- g_info << "Value: " << calc.calcValue(_row, _column, _updates, buf)
- << endl;
-
- return 0;
-}
diff --git a/storage/ndb/test/tools/hugoFill.cpp b/storage/ndb/test/tools/hugoFill.cpp
deleted file mode 100644
index 420014ef33b..00000000000
--- a/storage/ndb/test/tools/hugoFill.cpp
+++ /dev/null
@@ -1,86 +0,0 @@
-/* Copyright (c) 2003-2005, 2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-
-#include <NdbOut.hpp>
-#include <NdbApi.hpp>
-#include <NdbSleep.h>
-#include <NDBT.hpp>
-#include <HugoTransactions.hpp>
-#include <getarg.h>
-
-
-int main(int argc, const char** argv){
- ndb_init();
-
- int _records = 0;
- const char* _tabname = NULL;
- int _help = 0;
- int _batch = 512;
- const char* db = "TEST_DB";
-
- struct getargs args[] = {
- { "batch", 'b', arg_integer, &_batch, "Number of operations in each transaction", "batch" },
- { "database", 'd', arg_string, &db, "Database", "" },
- { "usage", '?', arg_flag, &_help, "Print help", "" }
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "tabname\n"\
- "This program will load one table in Ndb with calculated data \n"\
- "until the database is full. \n";
-
- if(getarg(args, num_args, argc, argv, &optind) ||
- argv[optind] == NULL || _help) {
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
- _tabname = argv[optind];
-
- // Connect to Ndb
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- Ndb MyNdb(&con, db);
-
- if(MyNdb.init() != 0){
- ERR(MyNdb.getNdbError());
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- // Connect to Ndb and wait for it to become ready
- while(MyNdb.waitUntilReady() != 0)
- ndbout << "Waiting for ndb to become ready..." << endl;
-
- // Check if table exists in db
- const NdbDictionary::Table* pTab = NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
- if(pTab == NULL){
- ndbout << " Table " << _tabname << " does not exist!" << endl;
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- HugoTransactions hugoTrans(*pTab);
- if (hugoTrans.fillTable(&MyNdb,
- _batch) != 0){
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- return NDBT_ProgramExit(NDBT_OK);
-}
diff --git a/storage/ndb/test/tools/hugoLoad.cpp b/storage/ndb/test/tools/hugoLoad.cpp
deleted file mode 100644
index a31a3013e16..00000000000
--- a/storage/ndb/test/tools/hugoLoad.cpp
+++ /dev/null
@@ -1,120 +0,0 @@
-/* Copyright (c) 2003-2006 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-#include <NdbOut.hpp>
-#include <NdbApi.hpp>
-#include <NdbSleep.h>
-#include <NDBT.hpp>
-#include <HugoTransactions.hpp>
-#include <getarg.h>
-
-
-int main(int argc, const char** argv){
- ndb_init();
-
- int _records = 0;
- int _help = 0;
- int _batch = 512;
- int _loops = -1;
- int _rand = 0;
- int _onetrans = 0;
- int _abort = 0;
- const char* db = 0;
-
- struct getargs args[] = {
- { "records", 'r', arg_integer, &_records, "Number of records", "recs" },
- { "batch", 'b', arg_integer, &_batch, "Number of operations in each transaction", "batch" },
- { "loops", 'l', arg_integer, &_loops, "Number of loops", "" },
- { "database", 'd', arg_string, &db, "Database", "" },
- { "usage", '?', arg_flag, &_help, "Print help", "" },
- { "rnd-rows", 0, arg_flag, &_rand, "Rand number of records", "recs" },
- { "one-trans", 0, arg_flag, &_onetrans, "Insert as 1 trans", "" },
- { "abort", 0, arg_integer, &_abort, "Abort probability", "" }
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "tabname\n"\
- "This program will load one table in Ndb with calculated data. \n"\
- "This means that it is possible to check the validity of the data \n"\
- "at a later time. The last column in each table is used as an update \n"\
- "counter, it's initialised to zero and should be incremented for each \n"\
- "update of the record. \n";
-
- if(getarg(args, num_args, argc, argv, &optind) ||
- argv[optind] == NULL || _records == 0 || _help) {
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
-
- // Connect to Ndb
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- if (con.wait_until_ready(30,0) < 0)
- {
- ndbout << "Cluster nodes not ready in 30 seconds." << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- Ndb MyNdb( &con, db ? db : "TEST_DB" );
-
- if(MyNdb.init() != 0){
- ERR(MyNdb.getNdbError());
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- for(Uint32 i = optind; i<argc; i++)
- {
- const char* _tabname = argv[i];
- // Check if table exists in db
- const NdbDictionary::Table* pTab =
- NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
- if(pTab == NULL){
- ndbout << " Table " << _tabname << " does not exist!" << endl;
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- HugoTransactions hugoTrans(*pTab);
-loop:
- int rows = (_rand ? rand() % _records : _records);
- int abort = (rand() % 100) < _abort ? 1 : 0;
- if (abort)
- ndbout << "load+abort" << endl;
- if (hugoTrans.loadTable(&MyNdb,
- rows,
- _batch,
- true, 0, _onetrans, _loops, abort) != 0){
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- if(_loops > 0)
- {
- ndbout << "clearing..." << endl;
- hugoTrans.clearTable(&MyNdb);
- //hugoTrans.pkDelRecords(&MyNdb, _records);
- _loops--;
- goto loop;
- }
- }
-
- return NDBT_ProgramExit(NDBT_OK);
-}
diff --git a/storage/ndb/test/tools/hugoLockRecords.cpp b/storage/ndb/test/tools/hugoLockRecords.cpp
deleted file mode 100644
index 4dd47bf904e..00000000000
--- a/storage/ndb/test/tools/hugoLockRecords.cpp
+++ /dev/null
@@ -1,96 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-
-#include <NdbOut.hpp>
-
-#include <NdbApi.hpp>
-#include <NdbMain.h>
-#include <NDBT.hpp>
-#include <NdbSleep.h>
-#include <getarg.h>
-
-#include <HugoTransactions.hpp>
-
-int main(int argc, const char** argv){
- ndb_init();
-
- int _records = 0;
- int _loops = 1;
- int _percentVal = 1;
- int _lockTime = 1000;
- const char* _tabname = NULL;
- int _help = 0;
-
- struct getargs args[] = {
- { "loops", 'l', arg_integer, &_loops, "number of times to run this program(0=infinite loop)", "loops" },
- { "records", 'r', arg_integer, &_records, "Number of records", "recs" },
- { "locktime", 't', arg_integer, &_lockTime, "Time in ms to hold lock(default=1000)", "ms" },
- { "percent", 'p', arg_integer, &_percentVal, "Percent of records to lock(default=1%)", "%" },
- { "usage", '?', arg_flag, &_help, "Print help", "" }
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "tabname\n"\
- "This program will lock p% of the records in the table for x milliseconds\n"\
- "then it will lock the next 1% and continue to do so until it has locked \n"\
- "all records in the table\n";
-
- if(getarg(args, num_args, argc, argv, &optind) ||
- argv[optind] == NULL || _records == 0 || _help) {
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
- _tabname = argv[optind];
-
- // Connect to Ndb
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- Ndb MyNdb(&con, "TEST_DB" );
-
- if(MyNdb.init() != 0){
- ERR(MyNdb.getNdbError());
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- while(MyNdb.waitUntilReady() != 0)
- ndbout << "Waiting for ndb to become ready..." << endl;
-
- // Check if table exists in db
- const NdbDictionary::Table * pTab = NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
- if(pTab == NULL){
- ndbout << " Table " << _tabname << " does not exist!" << endl;
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- HugoTransactions hugoTrans(*pTab);
- int i = 0;
- while (i<_loops || _loops==0) {
- ndbout << i << ": ";
- if (hugoTrans.lockRecords(&MyNdb, _records, _percentVal, _lockTime) != 0){
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- i++;
- }
-
- return NDBT_ProgramExit(NDBT_OK);
-}
-
diff --git a/storage/ndb/test/tools/hugoPkDelete.cpp b/storage/ndb/test/tools/hugoPkDelete.cpp
deleted file mode 100644
index fd73e381224..00000000000
--- a/storage/ndb/test/tools/hugoPkDelete.cpp
+++ /dev/null
@@ -1,181 +0,0 @@
-/* Copyright (c) 2003-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-
-#include <NdbOut.hpp>
-
-#include <NdbApi.hpp>
-#include <NdbMain.h>
-#include <NDBT.hpp>
-#include <NDBT_Thread.hpp>
-#include <NDBT_Stats.hpp>
-#include <NdbSleep.h>
-#include <getarg.h>
-
-#include <HugoTransactions.hpp>
-
-static NDBT_ThreadFunc hugoPkDelete;
-
-struct ThrInput {
- const NdbDictionary::Table* pTab;
- int records;
- int batch;
- int stats;
-};
-
-struct ThrOutput {
- NDBT_Stats latency;
-};
-
-int main(int argc, const char** argv){
- ndb_init();
-
- int _records = 0;
- int _loops = 1;
- int _threads = 1;
- int _stats = 0;
- int _batch = 1;
- const char* _tabname = NULL;
- int _help = 0;
-
- struct getargs args[] = {
- { "loops", 'l', arg_integer, &_loops, "number of times to run this program(0=infinite loop)", "loops" },
- { "threads", 't', arg_integer, &_threads, "number of threads (default 1)", "threads" },
- { "stats", 's', arg_flag, &_stats, "report latency per batch", "stats" },
- // { "batch", 'b', arg_integer, &_batch, "batch value", "batch" },
- { "records", 'r', arg_integer, &_records, "Number of records", "records" },
- { "usage", '?', arg_flag, &_help, "Print help", "" }
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "tabname\n"\
- "This program will delete all records in a table using PK \n";
-
- if(getarg(args, num_args, argc, argv, &optind) ||
- argv[optind] == NULL || _records == 0 || _help) {
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
- _tabname = argv[optind];
-
- // Connect to Ndb
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- if (con.wait_until_ready(30,0) < 0)
- {
- ndbout << "Cluster nodes not ready in 30 seconds." << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
-
- Ndb MyNdb(&con, "TEST_DB" );
-
- if(MyNdb.init() != 0){
- ERR(MyNdb.getNdbError());
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- // Check if table exists in db
- const NdbDictionary::Table * pTab = NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
- if(pTab == NULL){
- ndbout << " Table " << _tabname << " does not exist!" << endl;
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- // threads
- NDBT_ThreadSet ths(_threads);
-
- // create Ndb object for each thread
- if (ths.connect(&con, "TEST_DB") == -1) {
- ndbout << "connect failed: err=" << ths.get_err() << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- // input is options
- ThrInput input;
- ths.set_input(&input);
- input.pTab = pTab;
- input.records = _records;
- input.batch = _batch;
- input.stats = _stats;
-
- // output is stats
- ThrOutput output;
- ths.set_output<ThrOutput>();
-
- int i = 0;
- while (i < _loops || _loops == 0) {
- ndbout << i << ": ";
-
- ths.set_func(hugoPkDelete);
- ths.start();
- ths.stop();
-
- if (ths.get_err())
- NDBT_ProgramExit(NDBT_FAILED);
-
- if (_stats) {
- NDBT_Stats latency;
-
- // add stats from each thread
- int n;
- for (n = 0; n < ths.get_count(); n++) {
- NDBT_Thread& thr = ths.get_thread(n);
- ThrOutput* output = (ThrOutput*)thr.get_output();
- latency += output->latency;
- }
-
- ndbout
- << "latency per batch (us): "
- << " samples=" << latency.getCount()
- << " min=" << (int)latency.getMin()
- << " max=" << (int)latency.getMax()
- << " mean=" << (int)latency.getMean()
- << " stddev=" << (int)latency.getStddev()
- << endl;
- }
- i++;
- }
-
- return NDBT_ProgramExit(NDBT_OK);
-}
-
-static void hugoPkDelete(NDBT_Thread& thr)
-{
- const ThrInput* input = (const ThrInput*)thr.get_input();
- ThrOutput* output = (ThrOutput*)thr.get_output();
-
- HugoTransactions hugoTrans(*input->pTab);
- output->latency.reset();
- if (input->stats)
- hugoTrans.setStatsLatency(&output->latency);
-
- NDBT_ThreadSet& ths = thr.get_thread_set();
- hugoTrans.setThrInfo(ths.get_count(), thr.get_thread_no());
-
- int ret;
- ret = hugoTrans.pkDelRecords(thr.get_ndb(),
- input->records,
- input->batch);
- if (ret != 0)
- thr.set_err(ret);
-}
diff --git a/storage/ndb/test/tools/hugoPkRead.cpp b/storage/ndb/test/tools/hugoPkRead.cpp
deleted file mode 100644
index a5d7474c7c5..00000000000
--- a/storage/ndb/test/tools/hugoPkRead.cpp
+++ /dev/null
@@ -1,178 +0,0 @@
-/* Copyright (c) 2003-2005, 2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-
-#include <NdbOut.hpp>
-
-#include <NdbApi.hpp>
-#include <NdbMain.h>
-#include <NDBT.hpp>
-#include <NDBT_Thread.hpp>
-#include <NDBT_Stats.hpp>
-#include <NdbSleep.h>
-#include <getarg.h>
-
-#include <HugoTransactions.hpp>
-
-static NDBT_ThreadFunc hugoPkRead;
-
-struct ThrInput {
- const NdbDictionary::Table* pTab;
- int records;
- int batch;
- int stats;
-};
-
-struct ThrOutput {
- NDBT_Stats latency;
-};
-
-int main(int argc, const char** argv){
- ndb_init();
-
- int _records = 0;
- int _loops = 1;
- int _threads = 1;
- int _stats = 0;
- int _abort = 0;
- int _batch = 1;
- const char* _tabname = NULL;
- int _help = 0;
-
- struct getargs args[] = {
- { "aborts", 'a', arg_integer, &_abort, "percent of transactions that are aborted", "abort%" },
- { "loops", 'l', arg_integer, &_loops, "number of times to run this program(0=infinite loop)", "loops" },
- { "threads", 't', arg_integer, &_threads, "number of threads (default 1)", "threads" },
- { "stats", 's', arg_flag, &_stats, "report latency per batch", "stats" },
- { "batch", 'b', arg_integer, &_batch, "batch value(not 0)", "batch" },
- { "records", 'r', arg_integer, &_records, "Number of records", "records" },
- { "usage", '?', arg_flag, &_help, "Print help", "" }
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "tabname\n"\
- "This program will read 'r' records from one table in Ndb. \n"\
- "It will verify every column read by calculating the expected value.\n";
-
- if(getarg(args, num_args, argc, argv, &optind) ||
- argv[optind] == NULL || _records == 0 || _batch == 0 || _help) {
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
- _tabname = argv[optind];
-
-
- // Connect to Ndb
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- Ndb MyNdb(&con, "TEST_DB" );
-
- if(MyNdb.init() != 0){
- ERR(MyNdb.getNdbError());
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- while(MyNdb.waitUntilReady() != 0)
- ndbout << "Waiting for ndb to become ready..." << endl;
-
- // Check if table exists in db
- const NdbDictionary::Table * pTab = NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
- if(pTab == NULL){
- ndbout << " Table " << _tabname << " does not exist!" << endl;
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- // threads
- NDBT_ThreadSet ths(_threads);
-
- // create Ndb object for each thread
- if (ths.connect(&con, "TEST_DB") == -1) {
- ndbout << "connect failed: err=" << ths.get_err() << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- // input is options
- ThrInput input;
- ths.set_input(&input);
- input.pTab = pTab;
- input.records = _records;
- input.batch = _batch;
- input.stats = _stats;
-
- // output is stats
- ThrOutput output;
- ths.set_output<ThrOutput>();
-
- int i = 0;
- while (i < _loops || _loops == 0) {
- ndbout << i << ": ";
-
- ths.set_func(hugoPkRead);
- ths.start();
- ths.stop();
-
- if (ths.get_err())
- NDBT_ProgramExit(NDBT_FAILED);
-
- if (_stats) {
- NDBT_Stats latency;
-
- // add stats from each thread
- int n;
- for (n = 0; n < ths.get_count(); n++) {
- NDBT_Thread& thr = ths.get_thread(n);
- ThrOutput* output = (ThrOutput*)thr.get_output();
- latency += output->latency;
- }
-
- ndbout
- << "latency per batch (us): "
- << " samples=" << latency.getCount()
- << " min=" << (int)latency.getMin()
- << " max=" << (int)latency.getMax()
- << " mean=" << (int)latency.getMean()
- << " stddev=" << (int)latency.getStddev()
- << endl;
- }
- i++;
- }
-
- return NDBT_ProgramExit(NDBT_OK);
-}
-
-static void hugoPkRead(NDBT_Thread& thr)
-{
- const ThrInput* input = (const ThrInput*)thr.get_input();
- ThrOutput* output = (ThrOutput*)thr.get_output();
-
- HugoTransactions hugoTrans(*input->pTab);
- output->latency.reset();
- if (input->stats)
- hugoTrans.setStatsLatency(&output->latency);
-
- int ret;
- ret = hugoTrans.pkReadRecords(thr.get_ndb(),
- input->records,
- input->batch);
- if (ret != 0)
- thr.set_err(ret);
-}
diff --git a/storage/ndb/test/tools/hugoPkReadRecord.cpp b/storage/ndb/test/tools/hugoPkReadRecord.cpp
deleted file mode 100644
index d2c31d56794..00000000000
--- a/storage/ndb/test/tools/hugoPkReadRecord.cpp
+++ /dev/null
@@ -1,146 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-
-#include <NdbOut.hpp>
-#include <NdbSleep.h>
-#include <NDBT_Tables.hpp>
-#include <getarg.h>
-#include <NDBT.hpp>
-#include <Ndb.hpp>
-#include <NdbDictionary.hpp>
-
-//extern NdbOut g_info;
-
-int main(int argc, const char** argv)
-{
- ndb_init();
- int _row = 0;
- int _hex = 0;
- int _primaryKey = 0;
- const char* _tableName = NULL;
-
- struct getargs args[] = {
- { "row", 'r',
- arg_integer, &_row, "The row number", "row" },
- { "primarykey", 'p',
- arg_integer, &_primaryKey, "The primary key", "primarykey" },
- { "hex", 'h',
- arg_flag, &_hex, "Print hex", "hex" }
- };
-
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0, i;
-
- if(getarg(args, num_args, argc, argv, &optind) || argv[optind] == NULL) {
- arg_printusage(args, num_args, argv[0], "table name\n");
- return NDBT_WRONGARGS;
- }
- // Check if table name is supplied
- if (argv[optind] != NULL)
- _tableName = argv[optind];
-
-
- const NdbDictionary::Table* table = NDBT_Tables::getTable(_tableName);
- // const NDBT_Attribute* attribute = table->getAttribute(_column);
-
- g_info << "Table " << _tableName << endl
- << "Row: " << _row << ", PrimaryKey: " << _primaryKey
- << endl;
-
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- Ndb* ndb = new Ndb(&con, "TEST_DB");
- if (ndb->init() == 0 && ndb->waitUntilReady(30) == 0)
- {
- NdbConnection* conn = ndb->startTransaction();
- if (conn == NULL)
- {
- g_info << "ERROR: " << ndb->getNdbError() << endl;
- delete ndb;
- return -1;
- }
- NdbOperation* op = conn->getNdbOperation(_tableName);
- if (op == NULL)
- {
- g_info << "ERROR: " << conn->getNdbError() << endl;
- delete ndb;
- return -1;
- }
- op->readTuple();
- NdbRecAttr** data = new NdbRecAttr*[table->getNoOfColumns()];
- for (i = 0; i < table->getNoOfColumns(); i++)
- {
- const NdbDictionary::Column* c = table->getColumn(i);
- if (c->getPrimaryKey())
- {
- op->equal(c->getName(), _primaryKey);
- data[i] = op->getValue(c->getName(), NULL);
- }
- else
- {
- data[i] = op->getValue(c->getName(), NULL);
- }
- }
- if (conn->execute(Commit) == 0)
- {
- // Print column names
- for (i = 0; i < table->getNoOfColumns(); i++)
- {
- const NdbDictionary::Column* c = table->getColumn(i);
-
- g_info
- << c->getName()
- << "[" << c->getType() << "] ";
- }
- g_info << endl;
-
- if (_hex)
- {
- g_info << hex;
- }
- for (i = 0; i < table->getNoOfColumns(); i++)
- {
- NdbRecAttr* a = data[i];
- ndbout << (* a) << " ";
- } // for
- g_info << endl;
- } // if (conn
- else
- {
- g_info << "Failed to commit read transaction... "
- << conn->getNdbError()
- << ", commitStatus = " << conn->commitStatus()
- << endl;
- }
-
- delete[] data;
-
- ndb->closeTransaction(conn);
- } // if (ndb.init
- else
- {
- g_info << "ERROR: Unable to connect to NDB, "
- << ndb->getNdbError() << endl;
- }
- delete ndb;
-
- return 0;
-}
diff --git a/storage/ndb/test/tools/hugoPkUpdate.cpp b/storage/ndb/test/tools/hugoPkUpdate.cpp
deleted file mode 100644
index b8cf6dfe5ea..00000000000
--- a/storage/ndb/test/tools/hugoPkUpdate.cpp
+++ /dev/null
@@ -1,183 +0,0 @@
-/* Copyright (c) 2003-2008 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-
-#include <NdbOut.hpp>
-
-#include <NdbApi.hpp>
-#include <NdbMain.h>
-#include <NDBT.hpp>
-#include <NDBT_Thread.hpp>
-#include <NDBT_Stats.hpp>
-#include <NdbSleep.h>
-#include <getarg.h>
-
-#include <HugoTransactions.hpp>
-
-static NDBT_ThreadFunc hugoPkUpdate;
-
-struct ThrInput {
- const NdbDictionary::Table* pTab;
- int records;
- int batch;
- int stats;
-};
-
-struct ThrOutput {
- NDBT_Stats latency;
-};
-
-int main(int argc, const char** argv){
- ndb_init();
-
- int _records = 0;
- int _loops = 1;
- int _threads = 1;
- int _stats = 0;
- int _abort = 0;
- int _batch = 1;
- const char* _tabname = NULL, *db = 0;
- int _help = 0;
-
- struct getargs args[] = {
- { "aborts", 'a', arg_integer, &_abort, "percent of transactions that are aborted", "abort%" },
- { "loops", 'l', arg_integer, &_loops, "number of times to run this program(0=infinite loop)", "loops" },
- { "threads", 't', arg_integer, &_threads, "number of threads (default 1)", "threads" },
- { "stats", 's', arg_flag, &_stats, "report latency per batch", "stats" },
- // { "batch", 'b', arg_integer, &_batch, "batch value", "batch" },
- { "records", 'r', arg_integer, &_records, "Number of records", "records" },
- { "usage", '?', arg_flag, &_help, "Print help", "" },
- { "database", 'd', arg_string, &db, "Database", "" }
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "tabname\n"\
- "This program will update all records in a table using PK\n";
-
- if(getarg(args, num_args, argc, argv, &optind) ||
- argv[optind] == NULL || _records == 0 || _help) {
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
- _tabname = argv[optind];
-
- // Connect to Ndb
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- if (con.wait_until_ready(30,0) < 0)
- {
- ndbout << "Cluster nodes not ready in 30 seconds." << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- Ndb MyNdb( &con, db ? db : "TEST_DB" );
-
- if(MyNdb.init() != 0){
- ERR(MyNdb.getNdbError());
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- // Check if table exists in db
- const NdbDictionary::Table * pTab = NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
- if(pTab == NULL){
- ndbout << " Table " << _tabname << " does not exist!" << endl;
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- // threads
- NDBT_ThreadSet ths(_threads);
-
- // create Ndb object for each thread
- if (ths.connect(&con, db ? db : "TEST_DB") == -1) {
- ndbout << "connect failed: err=" << ths.get_err() << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- // input is options
- ThrInput input;
- ths.set_input(&input);
- input.pTab = pTab;
- input.records = _records;
- input.batch = _batch;
- input.stats = _stats;
-
- // output is stats
- ThrOutput output;
- ths.set_output<ThrOutput>();
-
- int i = 0;
- while (i < _loops || _loops == 0) {
- ndbout << i << ": ";
-
- ths.set_func(hugoPkUpdate);
- ths.start();
- ths.stop();
-
- if (ths.get_err())
- NDBT_ProgramExit(NDBT_FAILED);
-
- if (_stats) {
- NDBT_Stats latency;
-
- // add stats from each thread
- int n;
- for (n = 0; n < ths.get_count(); n++) {
- NDBT_Thread& thr = ths.get_thread(n);
- ThrOutput* output = (ThrOutput*)thr.get_output();
- latency += output->latency;
- }
-
- ndbout
- << "latency per batch (us): "
- << " samples=" << latency.getCount()
- << " min=" << (int)latency.getMin()
- << " max=" << (int)latency.getMax()
- << " mean=" << (int)latency.getMean()
- << " stddev=" << (int)latency.getStddev()
- << endl;
- }
- i++;
- }
-
- return NDBT_ProgramExit(NDBT_OK);
-}
-
-static void hugoPkUpdate(NDBT_Thread& thr)
-{
- const ThrInput* input = (const ThrInput*)thr.get_input();
- ThrOutput* output = (ThrOutput*)thr.get_output();
-
- HugoTransactions hugoTrans(*input->pTab);
- output->latency.reset();
- if (input->stats)
- hugoTrans.setStatsLatency(&output->latency);
-
- NDBT_ThreadSet& ths = thr.get_thread_set();
- hugoTrans.setThrInfo(ths.get_count(), thr.get_thread_no());
-
- int ret;
- ret = hugoTrans.pkUpdateRecords(thr.get_ndb(),
- input->records,
- input->batch);
- if (ret != 0)
- thr.set_err(ret);
-}
diff --git a/storage/ndb/test/tools/hugoScanRead.cpp b/storage/ndb/test/tools/hugoScanRead.cpp
deleted file mode 100644
index 7a23c789d19..00000000000
--- a/storage/ndb/test/tools/hugoScanRead.cpp
+++ /dev/null
@@ -1,132 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-
-#include <NdbOut.hpp>
-
-#include <NdbApi.hpp>
-#include <NdbMain.h>
-#include <NDBT.hpp>
-#include <NdbSleep.h>
-#include <getarg.h>
-
-#include <HugoTransactions.hpp>
-
-int main(int argc, const char** argv){
- ndb_init();
-
- int _records = 0;
- int _loops = 1;
- int _abort = 0;
- int _parallelism = 1;
- const char* _tabname = NULL, *db = 0;
- int _help = 0;
- int lock = NdbOperation::LM_Read;
- int sorted = 0;
-
- struct getargs args[] = {
- { "aborts", 'a', arg_integer, &_abort, "percent of transactions that are aborted", "abort%" },
- { "loops", 'l', arg_integer, &_loops, "number of times to run this program(0=infinite loop)", "loops" },
- { "parallelism", 'p', arg_integer, &_parallelism, "parallelism(1-240)", "para" },
- { "records", 'r', arg_integer, &_records, "Number of records", "recs" },
- { "usage", '?', arg_flag, &_help, "Print help", "" },
- { "lock", 'm', arg_integer, &lock, "lock mode", "" },
- { "sorted", 's', arg_flag, &sorted, "sorted", "" },
- { "database", 'd', arg_string, &db, "Database", "" }
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- " tabname\n"\
- "This program will scan read all records in one table in Ndb.\n"\
- "It will verify every column read by calculating the expected value.\n";
-
- if(getarg(args, num_args, argc, argv, &optind) || argv[optind] == NULL || _help) {
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
- _tabname = argv[optind];
-
- // Connect to Ndb
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- Ndb MyNdb( &con, db ? db : "TEST_DB" );
-
- if(MyNdb.init() != 0){
- ERR(MyNdb.getNdbError());
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- while(MyNdb.waitUntilReady() != 0)
- ndbout << "Waiting for ndb to become ready..." << endl;
-
- // Check if table exists in db
- const NdbDictionary::Table * pTab = NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
- if(pTab == NULL){
- ndbout << " Table " << _tabname << " does not exist!" << endl;
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- const NdbDictionary::Index * pIdx = 0;
- if(optind+1 < argc)
- {
- pIdx = MyNdb.getDictionary()->getIndex(argv[optind+1], _tabname);
- if(!pIdx)
- ndbout << " Index " << argv[optind+1] << " not found" << endl;
- else
- if(pIdx->getType() != NdbDictionary::Index::OrderedIndex)
- {
- ndbout << " Index " << argv[optind+1] << " is not scannable" << endl;
- pIdx = 0;
- }
- }
-
- HugoTransactions hugoTrans(*pTab);
- int i = 0;
- while (i<_loops || _loops==0) {
- ndbout << i << ": ";
- if(!pIdx)
- {
- if(hugoTrans.scanReadRecords(&MyNdb,
- 0,
- _abort,
- _parallelism,
- (NdbOperation::LockMode)lock) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- }
- else
- {
- if(hugoTrans.scanReadRecords(&MyNdb, pIdx,
- 0,
- _abort,
- _parallelism,
- (NdbOperation::LockMode)lock,
- sorted) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- }
- i++;
- }
-
- return NDBT_ProgramExit(NDBT_OK);
-}
diff --git a/storage/ndb/test/tools/hugoScanUpdate.cpp b/storage/ndb/test/tools/hugoScanUpdate.cpp
deleted file mode 100644
index dd7da2f5f1a..00000000000
--- a/storage/ndb/test/tools/hugoScanUpdate.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-/* Copyright (c) 2003-2006 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-
-#include <NdbOut.hpp>
-
-#include <NdbApi.hpp>
-#include <NdbMain.h>
-#include <NDBT.hpp>
-#include <NdbSleep.h>
-#include <getarg.h>
-
-#include <HugoTransactions.hpp>
-
-int main(int argc, const char** argv){
- ndb_init();
-
- int _records = 0;
- int _loops = 1;
- int _parallelism = 1;
- int _ver2 = 0;
- const char* _tabname = NULL, *db = 0;
- int _help = 0;
- int abort= 0;
-
- struct getargs args[] = {
- { "loops", 'l', arg_integer, &_loops, "number of times to run this program(0=infinite loop)", "loops" },
- { "parallelism", 'p', arg_integer, &_parallelism, "parallelism(1-240)", "para" },
- { "records", 'r', arg_integer, &_records, "Number of records", "recs" },
- { "ver2", '2', arg_flag, &_ver2, "Use version 2 of scanUpdateRecords", "" },
- { "ver2", '1', arg_negative_flag, &_ver2, "Use version 1 of scanUpdateRecords (default)", "" },
- { "abort", 'a', arg_integer, &abort, "Abort probability", "" },
- { "usage", '?', arg_flag, &_help, "Print help", "" },
- { "database", 'd', arg_string, &db, "Database", "" }
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "tabname\n"\
- "This program will scan update all records in one table in Ndb\n";
-
- if(getarg(args, num_args, argc, argv, &optind) ||
- argv[optind] == NULL || _help) {
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
- _tabname = argv[optind];
-
- // Connect to Ndb
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- if (con.wait_until_ready(30,0) < 0)
- {
- ndbout << "Cluster nodes not ready in 30 seconds." << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- Ndb MyNdb( &con, db ? db : "TEST_DB" );
-
- if(MyNdb.init() != 0){
- ERR(MyNdb.getNdbError());
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- // Check if table exists in db
- const NdbDictionary::Table * pTab = NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
- if(pTab == NULL){
- ndbout << " Table " << _tabname << " does not exist!" << endl;
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- HugoTransactions hugoTrans(*pTab);
- int i = 0;
- int res = NDBT_FAILED;
- while (i<_loops || _loops==0) {
- ndbout << i << ": ";
- if (_ver2 == 0){
- res = hugoTrans.scanUpdateRecords(&MyNdb,
- _records,
- abort % 101,
- _parallelism);
- } else{
- res = hugoTrans.scanUpdateRecords2(&MyNdb,
- _records,
- abort % 101,
- _parallelism);
- }
- if (res != NDBT_OK ){
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- i++;
- //NdbSleep_MilliSleep(300);
- }
-
- return NDBT_ProgramExit(NDBT_OK);
-}
diff --git a/storage/ndb/test/tools/listen.cpp b/storage/ndb/test/tools/listen.cpp
deleted file mode 100644
index 09c867117ba..00000000000
--- a/storage/ndb/test/tools/listen.cpp
+++ /dev/null
@@ -1,375 +0,0 @@
-/* Copyright (c) 2003, 2005-2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-#include <NdbOut.hpp>
-#include <NdbApi.hpp>
-#include <NdbSleep.h>
-#include <NDBT.hpp>
-#include <HugoTransactions.hpp>
-#include <getarg.h>
-
-
-#define BATCH_SIZE 128
-struct Table_info
-{
- Uint32 id;
-};
-
-struct Trans_arg
-{
- Ndb *ndb;
- NdbTransaction *trans;
- Uint32 bytes_batched;
-};
-
-Vector< Vector<NdbRecAttr*> > event_values;
-Vector< Vector<NdbRecAttr*> > event_pre_values;
-Vector<struct Table_info> table_infos;
-
-static void do_begin(Ndb *ndb, struct Trans_arg &trans_arg)
-{
- trans_arg.ndb = ndb;
- trans_arg.trans = ndb->startTransaction();
- trans_arg.bytes_batched = 0;
-}
-
-static void do_equal(NdbOperation *op,
- NdbEventOperation *pOp)
-{
- struct Table_info *ti = (struct Table_info *)pOp->getCustomData();
- Vector<NdbRecAttr*> &ev = event_values[ti->id];
- const NdbDictionary::Table *tab= pOp->getTable();
- unsigned i, n_columns = tab->getNoOfColumns();
- for (i= 0; i < n_columns; i++)
- {
- if (tab->getColumn(i)->getPrimaryKey() &&
- op->equal(i, ev[i]->aRef()))
- {
- abort();
- }
- }
-}
-
-static void do_set_value(NdbOperation *op,
- NdbEventOperation *pOp)
-{
- struct Table_info *ti = (struct Table_info *)pOp->getCustomData();
- Vector<NdbRecAttr*> &ev = event_values[ti->id];
- const NdbDictionary::Table *tab= pOp->getTable();
- unsigned i, n_columns = tab->getNoOfColumns();
- for (i= 0; i < n_columns; i++)
- {
- if (!tab->getColumn(i)->getPrimaryKey() &&
- op->setValue(i, ev[i]->aRef()))
- {
- abort();
- }
- }
-}
-
-static void do_insert(struct Trans_arg &trans_arg, NdbEventOperation *pOp)
-{
- if (!trans_arg.trans)
- return;
-
- NdbOperation *op =
- trans_arg.trans->getNdbOperation(pOp->getEvent()->getTableName());
- op->writeTuple();
-
- do_equal(op, pOp);
- do_set_value(op, pOp);
-
- trans_arg.bytes_batched++;
- if (trans_arg.bytes_batched > BATCH_SIZE)
- {
- trans_arg.trans->execute(NdbTransaction::NoCommit);
- trans_arg.bytes_batched = 0;
- }
-}
-static void do_update(struct Trans_arg &trans_arg, NdbEventOperation *pOp)
-{
- if (!trans_arg.trans)
- return;
-
- NdbOperation *op =
- trans_arg.trans->getNdbOperation(pOp->getEvent()->getTableName());
- op->writeTuple();
-
- do_equal(op, pOp);
- do_set_value(op, pOp);
-
- trans_arg.bytes_batched++;
- if (trans_arg.bytes_batched > BATCH_SIZE)
- {
- trans_arg.trans->execute(NdbTransaction::NoCommit);
- trans_arg.bytes_batched = 0;
- }
-}
-static void do_delete(struct Trans_arg &trans_arg, NdbEventOperation *pOp)
-{
- if (!trans_arg.trans)
- return;
-
- NdbOperation *op =
- trans_arg.trans->getNdbOperation(pOp->getEvent()->getTableName());
- op->deleteTuple();
-
- do_equal(op, pOp);
-
- trans_arg.bytes_batched++;
- if (trans_arg.bytes_batched > BATCH_SIZE)
- {
- trans_arg.trans->execute(NdbTransaction::NoCommit);
- trans_arg.bytes_batched = 0;
- }
-}
-static void do_commit(struct Trans_arg &trans_arg)
-{
- if (!trans_arg.trans)
- return;
- trans_arg.trans->execute(NdbTransaction::Commit);
- trans_arg.ndb->closeTransaction(trans_arg.trans);
-}
-
-int
-main(int argc, const char** argv){
- ndb_init();
-
-
- int _help = 0;
- const char* db = 0;
- const char* connectstring1 = 0;
- const char* connectstring2 = 0;
-
- struct getargs args[] = {
- { "connectstring1", 'c',
- arg_string, &connectstring1, "connectstring1", "" },
- { "connectstring2", 'C',
- arg_string, &connectstring2, "connectstring2", "" },
- { "database", 'd', arg_string, &db, "Database", "" },
- { "usage", '?', arg_flag, &_help, "Print help", "" }
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0, i;
- char desc[] =
- "<tabname>+ \nThis program listen to events on specified tables\n";
-
- if(getarg(args, num_args, argc, argv, &optind) ||
- argv[optind] == NULL || _help) {
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
-
- // Connect to Ndb
- Ndb_cluster_connection con(connectstring1);
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- Ndb MyNdb( &con, db ? db : "TEST_DB" );
-
- if(MyNdb.init() != 0){
- ERR(MyNdb.getNdbError());
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- // Connect to Ndb and wait for it to become ready
- while(MyNdb.waitUntilReady() != 0)
- ndbout << "Waiting for ndb to become ready..." << endl;
-
- Ndb_cluster_connection *con2 = NULL;
- Ndb *ndb2 = NULL;
- if (connectstring2)
- {
- con2 = new Ndb_cluster_connection(connectstring2);
-
- if(con2->connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- ndb2 = new Ndb( con2, db ? db : "TEST_DB" );
-
- if(ndb2->init() != 0){
- ERR(ndb2->getNdbError());
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- // Connect to Ndb and wait for it to become ready
- while(ndb2->waitUntilReady() != 0)
- ndbout << "Waiting for ndb to become ready..." << endl;
- }
-
- int result = 0;
-
- NdbDictionary::Dictionary *myDict = MyNdb.getDictionary();
- Vector<NdbDictionary::Event*> events;
- Vector<NdbEventOperation*> event_ops;
- int sz = 0;
- for(i= optind; i<argc; i++)
- {
- const NdbDictionary::Table* table= myDict->getTable(argv[i]);
- if(!table)
- {
- ndbout_c("Could not find table: %s, skipping", argv[i]);
- continue;
- }
-
- BaseString name;
- name.appfmt("EV-%s", argv[i]);
- NdbDictionary::Event *myEvent= new NdbDictionary::Event(name.c_str());
- myEvent->setTable(table->getName());
- myEvent->addTableEvent(NdbDictionary::Event::TE_ALL);
- for(int a = 0; a < table->getNoOfColumns(); a++){
- myEvent->addEventColumn(a);
- }
-
- if (myDict->createEvent(* myEvent))
- {
- if(myDict->getNdbError().classification == NdbError::SchemaObjectExists)
- {
- g_info << "Event creation failed event exists. Removing...\n";
- if (myDict->dropEvent(name.c_str()))
- {
- g_err << "Failed to drop event: " << myDict->getNdbError() << endl;
- result = 1;
- goto end;
- }
- // try again
- if (myDict->createEvent(* myEvent))
- {
- g_err << "Failed to create event: " << myDict->getNdbError() << endl;
- result = 1;
- goto end;
- }
- }
- else
- {
- g_err << "Failed to create event: " << myDict->getNdbError() << endl;
- result = 1;
- goto end;
- }
- }
-
- events.push_back(myEvent);
-
- NdbEventOperation* pOp = MyNdb.createEventOperation(name.c_str());
- if ( pOp == NULL ) {
- g_err << "Event operation creation failed" << endl;
- result = 1;
- goto end;
- }
-
- event_values.push_back(Vector<NdbRecAttr *>());
- event_pre_values.push_back(Vector<NdbRecAttr *>());
- for (int a = 0; a < table->getNoOfColumns(); a++)
- {
- event_values[sz].
- push_back(pOp->getValue(table->getColumn(a)->getName()));
- event_pre_values[sz].
- push_back(pOp->getPreValue(table->getColumn(a)->getName()));
- }
- event_ops.push_back(pOp);
- {
- struct Table_info ti;
- ti.id = sz;
- table_infos.push_back(ti);
- }
- pOp->setCustomData((void *)&table_infos[sz]);
- sz++;
- }
-
- for(i= 0; i<(int)event_ops.size(); i++)
- {
- if (event_ops[i]->execute())
- {
- g_err << "operation execution failed: " << event_ops[i]->getNdbError()
- << endl;
- result = 1;
- goto end;
- }
- }
-
- struct Trans_arg trans_arg;
- while(true)
- {
- while(MyNdb.pollEvents(100) == 0);
-
- NdbEventOperation* pOp= MyNdb.nextEvent();
- while(pOp)
- {
- Uint64 gci= pOp->getGCI();
- Uint64 cnt_i= 0, cnt_u= 0, cnt_d= 0;
- if (ndb2)
- do_begin(ndb2, trans_arg);
- do
- {
- switch(pOp->getEventType())
- {
- case NdbDictionary::Event::TE_INSERT:
- cnt_i++;
- if (ndb2)
- do_insert(trans_arg, pOp);
- break;
- case NdbDictionary::Event::TE_DELETE:
- cnt_d++;
- if (ndb2)
- do_delete(trans_arg, pOp);
- break;
- case NdbDictionary::Event::TE_UPDATE:
- cnt_u++;
- if (ndb2)
- do_update(trans_arg, pOp);
- break;
- case NdbDictionary::Event::TE_CLUSTER_FAILURE:
- break;
- case NdbDictionary::Event::TE_ALTER:
- break;
- case NdbDictionary::Event::TE_DROP:
- break;
- case NdbDictionary::Event::TE_NODE_FAILURE:
- break;
- case NdbDictionary::Event::TE_SUBSCRIBE:
- case NdbDictionary::Event::TE_UNSUBSCRIBE:
- break;
- default:
- /* We should REALLY never get here. */
- ndbout_c("Error: unknown event type: %u",
- (Uint32)pOp->getEventType());
- abort();
- }
- } while ((pOp= MyNdb.nextEvent()) && gci == pOp->getGCI());
- if (ndb2)
- do_commit(trans_arg);
- ndbout_c("GCI: %lld events: %lld(I) %lld(U) %lld(D)", gci, cnt_i, cnt_u, cnt_d);
- }
- }
-end:
- for(i= 0; i<(int)event_ops.size(); i++)
- MyNdb.dropEventOperation(event_ops[i]);
-
- if (ndb2)
- delete ndb2;
- if (con2)
- delete con2;
- return NDBT_ProgramExit(NDBT_OK);
-}
-
-template class Vector<struct Table_info>;
-template class Vector<NdbRecAttr*>;
-template class Vector< Vector<NdbRecAttr*> >;
-template class Vector<NdbDictionary::Event*>;
-template class Vector<NdbEventOperation*>;
diff --git a/storage/ndb/test/tools/log_listner.cpp b/storage/ndb/test/tools/log_listner.cpp
deleted file mode 100644
index a0a03f1319a..00000000000
--- a/storage/ndb/test/tools/log_listner.cpp
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- Copyright (c) 2007 MySQL AB
- Use is subject to license terms.
-
- 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-#include <mgmapi.h>
-#include <ndb_global.h>
-#include <ndb_opts.h>
-#include <NDBT.hpp>
-
-NDB_STD_OPTS_VARS;
-
-static struct my_option my_long_options[] =
-{
- NDB_STD_OPTS("ndb_logevent_listen"),
- { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
-};
-static void usage()
-{
- char desc[] =
- "tabname\n"\
- "This program list all properties of table(s) in NDB Cluster.\n"\
- " ex: desc T1 T2 T4\n";
- ndb_std_print_version();
- my_print_help(my_long_options);
- my_print_variables(my_long_options);
-}
-
-int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_BACKUP,
- 15, NDB_MGM_EVENT_CATEGORY_CONNECTION,
- 15, NDB_MGM_EVENT_CATEGORY_NODE_RESTART,
- 15, NDB_MGM_EVENT_CATEGORY_STARTUP,
- 15, NDB_MGM_EVENT_CATEGORY_SHUTDOWN,
- 15, NDB_MGM_EVENT_CATEGORY_STATISTIC,
- 15, NDB_MGM_EVENT_CATEGORY_ERROR,
- 15, NDB_MGM_EVENT_CATEGORY_CHECKPOINT,
- 15, NDB_MGM_EVENT_CATEGORY_CONGESTION,
- 0 };
-
-int
-main(int argc, char** argv)
-{
- NDB_INIT(argv[0]);
- const char *load_default_groups[]= { "mysql_cluster",0 };
- load_defaults("my",load_default_groups,&argc,&argv);
- int ho_error;
-#ifndef DBUG_OFF
- opt_debug= "d:t:O,/tmp/ndb_desc.trace";
-#endif
- if ((ho_error=handle_options(&argc, &argv, my_long_options,
- ndb_std_get_one_option)))
- return NDBT_ProgramExit(NDBT_WRONGARGS);
-
- NdbMgmHandle handle= ndb_mgm_create_handle();
- ndb_mgm_set_connectstring(handle, opt_connect_str);
-
- while (true)
- {
- if (ndb_mgm_connect(handle,0,0,0) == -1)
- {
- ndbout_c("Failed to connect");
- exit(0);
- }
-
- NdbLogEventHandle le = ndb_mgm_create_logevent_handle(handle, filter);
- if (le == 0)
- {
- ndbout_c("Failed to create logevent handle");
- exit(0);
- }
-
- struct ndb_logevent event;
- while (true)
- {
- int r= ndb_logevent_get_next(le, &event,5000);
- if (r < 0)
- {
- ndbout_c("Error while getting next event");
- break;
- }
- if (r == 0)
- {
- continue;
- }
- ndbout_c("Got event: %d", event.type);
- }
-
- ndb_mgm_destroy_logevent_handle(&le);
- ndb_mgm_disconnect(handle);
- }
-
- return 0;
-}
diff --git a/storage/ndb/test/tools/rep_latency.cpp b/storage/ndb/test/tools/rep_latency.cpp
deleted file mode 100644
index 6a5bba4f348..00000000000
--- a/storage/ndb/test/tools/rep_latency.cpp
+++ /dev/null
@@ -1,305 +0,0 @@
-/* Copyright (c) 2003, 2007 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-/*
- * Update on master wait for update on slave
- *
- */
-
-#include <NdbApi.hpp>
-#include <NdbSleep.h>
-#include <sys/time.h>
-#include <NdbOut.hpp>
-#include <NDBT.hpp>
-
-struct Xxx
-{
- Ndb *ndb;
- const NdbDictionary::Table *table;
- Uint32 pk_col;
- Uint32 col;
-};
-
-struct XxxR
-{
- Uint32 pk_val;
- Uint32 val;
- struct timeval start_time;
- Uint32 latency;
-};
-
-static int
-prepare_master_or_slave(Ndb &myNdb,
- const char* table,
- const char* pk,
- Uint32 pk_val,
- const char* col,
- struct Xxx &xxx,
- struct XxxR &xxxr);
-static void
-run_master_update(struct Xxx &xxx, struct XxxR &xxxr);
-static void
-run_slave_wait(struct Xxx &xxx, struct XxxR &xxxr);
-
-#define PRINT_ERROR(code,msg) \
- g_err << "Error in " << __FILE__ << ", line: " << __LINE__ \
- << ", code: " << code \
- << ", msg: " << msg << ".\n"
-#define APIERROR(error) { \
- PRINT_ERROR((error).code, (error).message); \
- exit(-1); }
-
-int main(int argc, char** argv)
-{
- if (argc != 8)
- {
- ndbout << "Arguments are <connect_string cluster 1> <connect_string cluster 2> <database> <table name> <primary key> <value of primary key> <attribute to update>.\n";
- exit(-1);
- }
- // ndb_init must be called first
- ndb_init();
- {
- const char *opt_connectstring1 = argv[1];
- const char *opt_connectstring2 = argv[2];
- const char *opt_db = argv[3];
- const char *opt_table = argv[4];
- const char *opt_pk = argv[5];
- const Uint32 opt_pk_val = atoi(argv[6]);
- const char *opt_col = argv[7];
-
- // Object representing the cluster 1
- Ndb_cluster_connection cluster1_connection(opt_connectstring1);
- // Object representing the cluster 2
- Ndb_cluster_connection cluster2_connection(opt_connectstring2);
-
- // connect cluster 1 and run application
- // Connect to cluster 1 management server (ndb_mgmd)
- if (cluster1_connection.connect(4 /* retries */,
- 5 /* delay between retries */,
- 1 /* verbose */))
- {
- g_err << "Cluster 1 management server was not ready within 30 secs.\n";
- exit(-1);
- }
- // Optionally connect and wait for the storage nodes (ndbd's)
- if (cluster1_connection.wait_until_ready(30,0) < 0)
- {
- g_err << "Cluster 1 was not ready within 30 secs.\n";
- exit(-1);
- }
- // connect cluster 2 and run application
- // Connect to cluster management server (ndb_mgmd)
- if (cluster2_connection.connect(4 /* retries */,
- 5 /* delay between retries */,
- 1 /* verbose */))
- {
- g_err << "Cluster 2 management server was not ready within 30 secs.\n";
- exit(-1);
- }
- // Optionally connect and wait for the storage nodes (ndbd's)
- if (cluster2_connection.wait_until_ready(30,0) < 0)
- {
- g_err << "Cluster 2 was not ready within 30 secs.\n";
- exit(-1);
- }
- // Object representing the database
- Ndb myNdb1(&cluster1_connection, opt_db);
- Ndb myNdb2(&cluster2_connection, opt_db);
- //
- struct Xxx xxx1;
- struct Xxx xxx2;
- struct XxxR xxxr;
- prepare_master_or_slave(myNdb1, opt_table, opt_pk, opt_pk_val, opt_col,
- xxx1, xxxr);
- prepare_master_or_slave(myNdb2, opt_table, opt_pk, opt_pk_val, opt_col,
- xxx2, xxxr);
- while (1)
- {
- // run the application code
- run_master_update(xxx1, xxxr);
- run_slave_wait(xxx2, xxxr);
- ndbout << "latency: " << xxxr.latency << endl;
- }
- }
- // Note: all connections must have been destroyed before calling ndb_end()
- ndb_end(0);
-
- return 0;
-}
-
-static int
-prepare_master_or_slave(Ndb &myNdb,
- const char* table,
- const char* pk,
- Uint32 pk_val,
- const char* col,
- struct Xxx &xxx,
- struct XxxR &xxxr)
-{
- if (myNdb.init())
- APIERROR(myNdb.getNdbError());
- const NdbDictionary::Dictionary* myDict = myNdb.getDictionary();
- const NdbDictionary::Table *myTable = myDict->getTable(table);
- if (myTable == NULL)
- APIERROR(myDict->getNdbError());
- const NdbDictionary::Column *myPkCol = myTable->getColumn(pk);
- if (myPkCol == NULL)
- APIERROR(myDict->getNdbError());
- if (myPkCol->getType() != NdbDictionary::Column::Unsigned)
- {
- PRINT_ERROR(0, "Primary key column not of type unsigned");
- exit(-1);
- }
- const NdbDictionary::Column *myCol = myTable->getColumn(col);
- if (myCol == NULL)
- APIERROR(myDict->getNdbError());
- if (myCol->getType() != NdbDictionary::Column::Unsigned)
- {
- PRINT_ERROR(0, "Update column not of type unsigned");
- exit(-1);
- }
-
- xxx.ndb = &myNdb;
- xxx.table = myTable;
- xxx.pk_col = myPkCol->getColumnNo();
- xxx.col = myCol->getColumnNo();
-
- xxxr.pk_val = pk_val;
-
- return 0;
-}
-
-static void run_master_update(struct Xxx &xxx, struct XxxR &xxxr)
-{
- Ndb *ndb = xxx.ndb;
- const NdbDictionary::Table *myTable = xxx.table;
- int retry_sleep= 10; /* 10 milliseconds */
- int retries= 100;
- while (1)
- {
- Uint32 val;
- NdbTransaction *trans = ndb->startTransaction();
- if (trans == NULL)
- goto err;
- {
- NdbOperation *op = trans->getNdbOperation(myTable);
- if (op == NULL)
- APIERROR(trans->getNdbError());
- op->readTupleExclusive();
- op->equal(xxx.pk_col, xxxr.pk_val);
- op->getValue(xxx.col, (char *)&val);
- }
- if (trans->execute(NdbTransaction::NoCommit))
- goto err;
- //fprintf(stderr, "read %u\n", val);
- xxxr.val = val + 1;
- {
- NdbOperation *op = trans->getNdbOperation(myTable);
- if (op == NULL)
- APIERROR(trans->getNdbError());
- op->updateTuple();
- op->equal(xxx.pk_col, xxxr.pk_val);
- op->setValue(xxx.col, xxxr.val);
- }
- if (trans->execute(NdbTransaction::Commit))
- goto err;
- ndb->closeTransaction(trans);
- //fprintf(stderr, "updated to %u\n", xxxr.val);
- break;
-err:
- const NdbError this_error= trans ?
- trans->getNdbError() : ndb->getNdbError();
- if (this_error.status == NdbError::TemporaryError)
- {
- if (retries--)
- {
- if (trans)
- ndb->closeTransaction(trans);
- NdbSleep_MilliSleep(retry_sleep);
- continue; // retry
- }
- }
- if (trans)
- ndb->closeTransaction(trans);
- APIERROR(this_error);
- }
- /* update done start timer */
- gettimeofday(&xxxr.start_time, 0);
-}
-
-static void run_slave_wait(struct Xxx &xxx, struct XxxR &xxxr)
-{
- struct timeval old_end_time = xxxr.start_time, end_time;
- Ndb *ndb = xxx.ndb;
- const NdbDictionary::Table *myTable = xxx.table;
- int retry_sleep= 10; /* 10 milliseconds */
- int retries= 100;
- while (1)
- {
- Uint32 val;
- NdbTransaction *trans = ndb->startTransaction();
- if (trans == NULL)
- goto err;
- {
- NdbOperation *op = trans->getNdbOperation(myTable);
- if (op == NULL)
- APIERROR(trans->getNdbError());
- op->readTuple();
- op->equal(xxx.pk_col, xxxr.pk_val);
- op->getValue(xxx.col, (char *)&val);
- if (trans->execute(NdbTransaction::Commit))
- goto err;
- }
- /* read done, check time of read */
- gettimeofday(&end_time, 0);
- ndb->closeTransaction(trans);
- //fprintf(stderr, "read %u waiting for %u\n", val, xxxr.val);
- if (xxxr.val != val)
- {
- /* expected value not received yet */
- retries = 100;
- NdbSleep_MilliSleep(retry_sleep);
- old_end_time = end_time;
- continue;
- }
- break;
-err:
- const NdbError this_error= trans ?
- trans->getNdbError() : ndb->getNdbError();
- if (this_error.status == NdbError::TemporaryError)
- {
- if (retries--)
- {
- if (trans)
- ndb->closeTransaction(trans);
- NdbSleep_MilliSleep(retry_sleep);
- continue; // retry
- }
- }
- if (trans)
- ndb->closeTransaction(trans);
- APIERROR(this_error);
- }
-
- Int64 elapsed_usec1 =
- ((Int64)end_time.tv_sec - (Int64)xxxr.start_time.tv_sec)*1000*1000 +
- ((Int64)end_time.tv_usec - (Int64)xxxr.start_time.tv_usec);
- Int64 elapsed_usec2 =
- ((Int64)end_time.tv_sec - (Int64)old_end_time.tv_sec)*1000*1000 +
- ((Int64)end_time.tv_usec - (Int64)old_end_time.tv_usec);
- xxxr.latency =
- ((elapsed_usec1 - elapsed_usec2/2)+999)/1000;
-}
diff --git a/storage/ndb/test/tools/restart.cpp b/storage/ndb/test/tools/restart.cpp
deleted file mode 100644
index 59414ecc70b..00000000000
--- a/storage/ndb/test/tools/restart.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-
-#include <ndb_global.h>
-
-#include <NdbMain.h>
-#include <OutputStream.hpp>
-#include <NdbOut.hpp>
-#include <NdbSleep.h>
-#include <getarg.h>
-
-#include <NdbRestarter.hpp>
-#include <NDBT.hpp>
-
-int main(int argc, const char** argv){
- ndb_init();
-
- const char* _hostName = NULL;
- int _initial = 0;
- int _help = 0;
- int _wait = 1;
-
-
- struct getargs args[] = {
- { "initial", 'i', arg_flag, &_initial, "Do initial restart"},
- { "wait", '\0', arg_negative_flag, &_wait, "Wait until restarted(default=true)"},
- { "usage", '?', arg_flag, &_help, "Print help", "" }
-
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "hostname:port\n"\
- "This program will connect to the mgmsrv of a NDB cluster\n"\
- " and restart the cluster. \n";
-
- if(getarg(args, num_args, argc, argv, &optind) || _help) {
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
- _hostName = argv[optind];
-
- NdbRestarter restarter(_hostName);
- setOutputLevel(1); // Show only g_err
- int result = NDBT_OK;
- if (_initial){
- ndbout << "Restarting cluster with initial restart" << endl;
- if (restarter.restartAll(true, false, false) != 0)
- result = NDBT_FAILED;
- } else {
- ndbout << "Restarting cluster " << endl;
- if (restarter.restartAll() != 0)
- result = NDBT_FAILED;
- }
- if (result == NDBT_FAILED){
- g_err << "Failed to restart cluster" << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- if (_wait == 1){
- ndbout << "Waiting for cluster to start" << endl;
- if ( restarter.waitClusterStarted(120) != 0){
- ndbout << "Failed waiting for restart of cluster" << endl;
- result = NDBT_FAILED;
- }
- }
- ndbout << "Cluster restarted" << endl;
-
- return NDBT_ProgramExit(result);
-}
diff --git a/storage/ndb/test/tools/transproxy.cpp b/storage/ndb/test/tools/transproxy.cpp
deleted file mode 100644
index 5420071237b..00000000000
--- a/storage/ndb/test/tools/transproxy.cpp
+++ /dev/null
@@ -1,361 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-
-#include <NdbTCP.h>
-#include <NdbOut.hpp>
-#include <NdbThread.h>
-#include <NdbSleep.h>
-#include <Properties.hpp>
-#include <LocalConfig.hpp>
-#include <Config.hpp>
-#include <InitConfigFileParser.hpp>
-#include <IPCConfig.hpp>
-
-static void
-fatal(char const* fmt, ...)
-{
- va_list ap;
- char buf[200];
- va_start(ap, fmt);
- BaseString::vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
- ndbout << "FATAL: " << buf << endl;
- sleep(1);
- exit(1);
-}
-
-static void
-debug(char const* fmt, ...)
-{
- va_list ap;
- char buf[200];
- va_start(ap, fmt);
- BaseString::vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
- ndbout << buf << endl;
-}
-
-// node
-struct Node {
- enum Type { MGM = 1, DB = 2, API = 3 };
- Type type;
- unsigned id; // node id
- static Node* list;
- static unsigned count;
- static Node* find(unsigned n) {
- for (unsigned i = 0; i < count; i++) {
- if (list[i].id == n)
- return &list[i];
- }
- return 0;
- }
-};
-
-unsigned Node::count = 0;
-Node* Node::list = 0;
-
-struct Copy {
- int rfd; // read from
- int wfd; // write to
- unsigned char* buf;
- unsigned bufsiz;
- NdbThread* thread;
- void run();
- char info[20];
-};
-
-// connection between nodes 0-server side 1-client side
-// we are client to 0 and server to 1
-struct Conn {
- Node* node[2]; // the nodes
- unsigned port; // server port
- unsigned proxy; // proxy port
- static unsigned count;
- static unsigned proxycount;
- static Conn* list;
- NdbThread* thread; // thread handling this connection
- void run(); // run the connection
- int sockfd[2]; // socket 0-on server side 1-client side
- void conn0(); // connect to side 0
- void conn1(); // connect to side 0
- char info[20];
- Copy copy[2]; // 0-to-1 and 1-to-0
-};
-
-unsigned Conn::count = 0;
-unsigned Conn::proxycount = 0;
-Conn* Conn::list = 0;
-
-// global data
-static char* hostname = 0;
-static struct sockaddr_in hostaddr;
-static char* localcfgfile = 0;
-static char* initcfgfile = 0;
-static unsigned ownnodeid = 0;
-
-static void
-properr(const Properties* props, const char* name, int i = -1)
-{
- if (i < 0) {
- fatal("get %s failed: errno = %d", name, props->getPropertiesErrno());
- } else {
- fatal("get %s_%d failed: errno = %d", name, i, props->getPropertiesErrno());
- }
-}
-
-// read config and load it into our structs
-static void
-getcfg()
-{
- LocalConfig lcfg;
- if (! lcfg.read(localcfgfile)) {
- fatal("read %s failed", localcfgfile);
- }
- ownnodeid = lcfg._ownNodeId;
- debug("ownnodeid = %d", ownnodeid);
- InitConfigFileParser pars(initcfgfile);
- Config icfg;
- if (! pars.getConfig(icfg)) {
- fatal("parse %s failed", initcfgfile);
- }
- Properties* ccfg = icfg.getConfig(ownnodeid);
- if (ccfg == 0) {
- const char* err = "unknown error";
- fatal("getConfig: %s", err);
- }
- ccfg->put("NodeId", ownnodeid);
- ccfg->put("NodeType", "MGM");
- if (! ccfg->get("NoOfNodes", &Node::count)) {
- properr(ccfg, "NoOfNodes", -1);
- }
- debug("Node::count = %d", Node::count);
- Node::list = new Node[Node::count];
- for (unsigned i = 0; i < Node::count; i++) {
- Node& node = Node::list[i];
- const Properties* nodecfg;
- if (! ccfg->get("Node", 1+i, &nodecfg)) {
- properr(ccfg, "Node", 1+i);
- }
- const char* type;
- if (! nodecfg->get("Type", &type)) {
- properr(nodecfg, "Type");
- }
- if (strcmp(type, "MGM") == 0) {
- node.type = Node::MGM;
- } else if (strcmp(type, "DB") == 0) {
- node.type = Node::DB;
- } else if (strcmp(type, "API") == 0) {
- node.type = Node::API;
- } else {
- fatal("prop %s_%d bad Type = %s", "Node", 1+i, type);
- }
- if (! nodecfg->get("NodeId", &node.id)) {
- properr(nodecfg, "NodeId");
- }
- debug("node id=%d type=%d", node.id, node.type);
- }
- IPCConfig ipccfg(ccfg);
- if (ipccfg.init() != 0) {
- fatal("ipccfg init failed");
- }
- if (! ccfg->get("NoOfConnections", &Conn::count)) {
- properr(ccfg, "NoOfConnections");
- }
- debug("Conn::count = %d", Conn::count);
- Conn::list = new Conn[Conn::count];
- for (unsigned i = 0; i < Conn::count; i++) {
- Conn& conn = Conn::list[i];
- const Properties* conncfg;
- if (! ccfg->get("Connection", i, &conncfg)) {
- properr(ccfg, "Connection", i);
- }
- unsigned n;
- if (! conncfg->get("NodeId1", &n)) {
- properr(conncfg, "NodeId1");
- }
- if ((conn.node[0] = Node::find(n)) == 0) {
- fatal("node %d not found", n);
- }
- if (! conncfg->get("NodeId2", &n)) {
- properr(conncfg, "NodeId2");
- }
- if ((conn.node[1] = Node::find(n)) == 0) {
- fatal("node %d not found", n);
- }
- if (! conncfg->get("PortNumber", &conn.port)) {
- properr(conncfg, "PortNumber");
- }
- conn.proxy = 0;
- const char* proxy;
- if (conncfg->get("Proxy", &proxy)) {
- conn.proxy = atoi(proxy);
- if (conn.proxy > 0) {
- Conn::proxycount++;
- }
- }
- sprintf(conn.info, "conn %d-%d", conn.node[0]->id, conn.node[1]->id);
- }
-}
-
-void
-Conn::conn0()
-{
- int fd;
- while (1) {
- if ((fd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
- fatal("%s: create client socket failed: %s", info, strerror(errno));
- }
- struct sockaddr_in servaddr;
- memset(&servaddr, 0, sizeof(servaddr));
- servaddr.sin_family = AF_INET;
- servaddr.sin_port = htons(port);
- servaddr.sin_addr = hostaddr.sin_addr;
-#if 0 // coredump
- if (Ndb_getInAddr(&servaddr.sin_addr, hostname) != 0) {
- fatal("%s: hostname %s lookup failed", info, hostname);
- }
-#endif
- if (connect(fd, (struct sockaddr*)&servaddr, sizeof(servaddr)) == 0)
- break;
- if (errno != ECONNREFUSED) {
- fatal("%s: connect failed: %s", info, strerror(errno));
- }
- close(fd);
- NdbSleep_MilliSleep(100);
- }
- sockfd[0] = fd;
- debug("%s: side 0 connected", info);
-}
-
-void
-Conn::conn1()
-{
- int servfd;
- if ((servfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
- fatal("%s: create server socket failed: %s", info, strerror(errno));
- }
- struct sockaddr_in servaddr;
- memset(&servaddr, 0, sizeof(servaddr));
- servaddr.sin_family = AF_INET;
- servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
- servaddr.sin_port = htons(proxy);
- const int on = 1;
- setsockopt(servfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on));
- if (bind(servfd, (struct sockaddr*) &servaddr, sizeof(servaddr)) == -1) {
- fatal("%s: bind %d failed: %s", info, proxy, strerror(errno));
- }
- if (listen(servfd, 1) == -1) {
- fatal("%s: listen %d failed: %s", info, proxy, strerror(errno));
- }
- int fd;
- if ((fd = accept(servfd, 0, 0)) == -1) {
- fatal("%s: accept failed: %s", info, strerror(errno));
- }
- sockfd[1] = fd;
- close(servfd);
- debug("%s: side 1 connected", info);
-}
-
-void
-Copy::run()
-{
- debug("%s: start", info);
- int n, m;
- while (1) {
- n = read(rfd, buf, sizeof(buf));
- if (n < 0)
- fatal("read error: %s", strerror(errno));
- m = write(wfd, buf, n);
- if (m != n)
- fatal("write error: %s", strerror(errno));
- }
- debug("%s: stop", info);
-}
-
-extern "C" void*
-copyrun_C(void* copy)
-{
- ((Copy*) copy)->run();
- return 0;
-}
-
-void
-Conn::run()
-{
- debug("%s: start", info);
- conn1();
- conn0();
- const unsigned siz = 32 * 1024;
- for (int i = 0; i < 2; i++) {
- Copy& copy = this->copy[i];
- copy.rfd = sockfd[i];
- copy.wfd = sockfd[1-i];
- copy.buf = new unsigned char[siz];
- copy.bufsiz = siz;
- sprintf(copy.info, "copy %d-%d", this->node[i]->id, this->node[1-i]->id);
- copy.thread = NdbThread_Create(copyrun_C, (void**)&copy,
- 8192, "copyrun", NDB_THREAD_PRIO_LOW);
- if (copy.thread == 0) {
- fatal("%s: create thread %d failed errno=%d", i, errno);
- }
- }
- debug("%s: stop", info);
-}
-
-extern "C" void*
-connrun_C(void* conn)
-{
- ((Conn*) conn)->run();
- return 0;
-}
-
-static void
-start()
-{
- NdbThread_SetConcurrencyLevel(3 * Conn::proxycount + 2);
- for (unsigned i = 0; i < Conn::count; i++) {
- Conn& conn = Conn::list[i];
- if (! conn.proxy)
- continue;
- conn.thread = NdbThread_Create(connrun_C, (void**)&conn,
- 8192, "connrun", NDB_THREAD_PRIO_LOW);
- if (conn.thread == 0) {
- fatal("create thread %d failed errno=%d", i, errno);
- }
- }
- sleep(3600);
-}
-
-int
-main(int av, char** ac)
-{
- ndb_init();
- debug("start");
- hostname = "ndb-srv7";
- if (Ndb_getInAddr(&hostaddr.sin_addr, hostname) != 0) {
- fatal("hostname %s lookup failed", hostname);
- }
- localcfgfile = "Ndb.cfg";
- initcfgfile = "config.txt";
- getcfg();
- start();
- debug("done");
- return 0;
-}
-
-// vim: set sw=4 noet:
diff --git a/storage/ndb/test/tools/verify_index.cpp b/storage/ndb/test/tools/verify_index.cpp
deleted file mode 100644
index 68206df538a..00000000000
--- a/storage/ndb/test/tools/verify_index.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-/* Copyright (c) 2003-2005 MySQL AB
- Use is subject to license terms
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
-
-#include <ndb_global.h>
-
-#include <NdbOut.hpp>
-
-#include <NdbApi.hpp>
-#include <NdbMain.h>
-#include <NDBT.hpp>
-#include <NdbSleep.h>
-#include <getarg.h>
-#include <UtilTransactions.hpp>
-
-
-int main(int argc, const char** argv){
- ndb_init();
- int _parallelism = 240;
- const char* _tabname = NULL;
- const char* _indexname = NULL;
- int _help = 0;
-
- struct getargs args[] = {
- { "parallelism", 's', arg_integer, &_parallelism, "parallelism", "parallelism" },
- { "usage", '?', arg_flag, &_help, "Print help", "" }
- };
- int num_args = sizeof(args) / sizeof(args[0]);
- int optind = 0;
- char desc[] =
- "tabname indexname\n"\
- "This program will verify the index [indexname] and compare it to data\n"
- "in table [tablename]\n";
-
- if(getarg(args, num_args, argc, argv, &optind) ||
- argv[optind] == NULL || argv[optind+1] == NULL || _help) {
- arg_printusage(args, num_args, argv[0], desc);
- return NDBT_ProgramExit(NDBT_WRONGARGS);
- }
- _tabname = argv[optind];
- _indexname = argv[optind+1];
-
- // Connect to Ndb
- Ndb_cluster_connection con;
- if(con.connect(12, 5, 1) != 0)
- {
- return NDBT_ProgramExit(NDBT_FAILED);
- }
- Ndb MyNdb(&con, "TEST_DB" );
-
- if(MyNdb.init() != 0){
- ERR(MyNdb.getNdbError());
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- // Connect to Ndb and wait for it to become ready
- while(MyNdb.waitUntilReady() != 0)
- ndbout << "Waiting for ndb to become ready..." << endl;
-
- // Check if table exists in db
- const NdbDictionary::Table * pTab = NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
- if(pTab == NULL){
- ndbout << " Table " << _tabname << " does not exist!" << endl;
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- int rows = 0;
- UtilTransactions utilTrans(*pTab);
- if (utilTrans.verifyIndex(&MyNdb,
- _indexname,
- _parallelism) != 0){
- return NDBT_ProgramExit(NDBT_FAILED);
- }
-
- return NDBT_ProgramExit(NDBT_OK);
-}
-
-
-