diff --git a/configure.in b/configure.in index 8ffab66d80a..a1d22625578 100644 --- a/configure.in +++ b/configure.in @@ -2897,7 +2897,7 @@ AC_SUBST([ndb_transporter_opt_objs]) ndb_bin_am_ldflags="-static" if test X"$have_ndb_test" = Xyes then - ndb_opt_test_subdirs="tools ndbapi run-test" + ndb_opt_test_subdirs="test" ndb_bin_am_ldflags="" fi AC_SUBST([ndb_bin_am_ldflags]) @@ -2911,7 +2911,7 @@ AC_OUTPUT(Makefile extra/Makefile mysys/Makefile isam/Makefile dnl ndb/src/Makefile ndb/src/common/Makefile dnl ndb/tools/Makefile dnl ndb/src/common/debugger/Makefile ndb/src/common/debugger/signaldata/Makefile dnl - ndb/src/common/portlib/Makefile ndb/src/common/portlib/unix/Makefile dnl + ndb/src/common/portlib/Makefile dnl ndb/src/common/util/Makefile dnl ndb/src/common/logger/Makefile dnl ndb/src/common/transporter/Makefile dnl diff --git a/ndb/Makefile.am b/ndb/Makefile.am index 6737cee5bbc..5cd52010f1d 100644 --- a/ndb/Makefile.am +++ b/ndb/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = src test tools . include +SUBDIRS = src tools . include $(ndb_opt_test_subdirs) EXTRA_DIST = config include $(top_srcdir)/ndb/config/common.mk.am diff --git a/ndb/config/type_ndbapitools.mk.am b/ndb/config/type_ndbapitools.mk.am index 1156a3174c4..19fa27895e3 100644 --- a/ndb/config/type_ndbapitools.mk.am +++ b/ndb/config/type_ndbapitools.mk.am @@ -1,6 +1,5 @@ -LDADD += $(top_srcdir)/ndb/test/src/libNDBT.a \ - $(top_srcdir)/ndb/src/libndbclient.la +LDADD += $(top_srcdir)/ndb/src/libndbclient.la INCLUDES += -I$(srcdir) -I$(top_srcdir)/include \ -I$(top_srcdir)/ndb/include \ diff --git a/ndb/src/Makefile.am b/ndb/src/Makefile.am index 69eb4f53d7f..ced6bd23d6d 100644 --- a/ndb/src/Makefile.am +++ b/ndb/src/Makefile.am @@ -14,5 +14,5 @@ libndbclient_la_LIBADD = \ $(top_srcdir)/ndb/src/common/mgmcommon/libmgmsrvcommon.la \ $(top_srcdir)/ndb/src/mgmapi/libmgmapi.la \ $(top_srcdir)/ndb/src/common/logger/liblogger.la \ - $(top_srcdir)/ndb/src/common/portlib/unix/libportlib.la \ + $(top_srcdir)/ndb/src/common/portlib/libportlib.la \ $(top_srcdir)/ndb/src/common/util/libgeneral.la diff --git a/ndb/src/common/Makefile.am b/ndb/src/common/Makefile.am index 9ccf6f4350c..7fcf2cab636 100644 --- a/ndb/src/common/Makefile.am +++ b/ndb/src/common/Makefile.am @@ -8,6 +8,6 @@ libcommon_la_LIBADD = \ debugger/libtrace.la \ debugger/signaldata/libsignaldataprint.la \ mgmcommon/libmgmsrvcommon.la \ - portlib/unix/libportlib.la \ + portlib/libportlib.la \ logger/liblogger.la \ util/libgeneral.la diff --git a/ndb/src/common/portlib/Makefile.am b/ndb/src/common/portlib/Makefile.am index f39cae194d1..e6ecb30fe04 100644 --- a/ndb/src/common/portlib/Makefile.am +++ b/ndb/src/common/portlib/Makefile.am @@ -1,5 +1,18 @@ -SUBDIRS = unix - noinst_HEADERS = gcc.cpp -EXTRA_PROGRAMS = \ No newline at end of file +noinst_LTLIBRARIES = libportlib.la + +libportlib_la_SOURCES = \ + NdbCondition.c NdbMutex.c NdbSleep.c NdbTick.c \ + NdbEnv.c NdbThread.c NdbHost.c NdbTCP.c \ + NdbDaemon.c NdbMem.c + +include $(top_srcdir)/ndb/config/common.mk.am +include $(top_srcdir)/ndb/config/type_util.mk.am + +EXTRA_PROGRAMS = memtest PortLibTest munmaptest + +PortLibTest_SOURCES = NdbPortLibTest.cpp +munmaptest_SOURCES = munmaptest.cpp + +# Don't update the files from bitkeeper diff --git a/ndb/src/common/portlib/unix/NdbCondition.c b/ndb/src/common/portlib/NdbCondition.c similarity index 100% rename from ndb/src/common/portlib/unix/NdbCondition.c rename to ndb/src/common/portlib/NdbCondition.c diff --git a/ndb/src/common/portlib/unix/NdbDaemon.c b/ndb/src/common/portlib/NdbDaemon.c similarity index 100% rename from ndb/src/common/portlib/unix/NdbDaemon.c rename to ndb/src/common/portlib/NdbDaemon.c diff --git a/ndb/src/common/portlib/unix/NdbEnv.c b/ndb/src/common/portlib/NdbEnv.c similarity index 100% rename from ndb/src/common/portlib/unix/NdbEnv.c rename to ndb/src/common/portlib/NdbEnv.c diff --git a/ndb/src/common/portlib/unix/NdbHost.c b/ndb/src/common/portlib/NdbHost.c similarity index 100% rename from ndb/src/common/portlib/unix/NdbHost.c rename to ndb/src/common/portlib/NdbHost.c diff --git a/ndb/src/common/portlib/unix/NdbMem.c b/ndb/src/common/portlib/NdbMem.c similarity index 100% rename from ndb/src/common/portlib/unix/NdbMem.c rename to ndb/src/common/portlib/NdbMem.c diff --git a/ndb/src/common/portlib/unix/NdbMutex.c b/ndb/src/common/portlib/NdbMutex.c similarity index 100% rename from ndb/src/common/portlib/unix/NdbMutex.c rename to ndb/src/common/portlib/NdbMutex.c diff --git a/ndb/src/common/portlib/test/NdbPortLibTest.cpp b/ndb/src/common/portlib/NdbPortLibTest.cpp similarity index 100% rename from ndb/src/common/portlib/test/NdbPortLibTest.cpp rename to ndb/src/common/portlib/NdbPortLibTest.cpp diff --git a/ndb/src/common/portlib/unix/NdbSleep.c b/ndb/src/common/portlib/NdbSleep.c similarity index 100% rename from ndb/src/common/portlib/unix/NdbSleep.c rename to ndb/src/common/portlib/NdbSleep.c diff --git a/ndb/src/common/portlib/unix/NdbTCP.c b/ndb/src/common/portlib/NdbTCP.c similarity index 100% rename from ndb/src/common/portlib/unix/NdbTCP.c rename to ndb/src/common/portlib/NdbTCP.c diff --git a/ndb/src/common/portlib/unix/NdbThread.c b/ndb/src/common/portlib/NdbThread.c similarity index 100% rename from ndb/src/common/portlib/unix/NdbThread.c rename to ndb/src/common/portlib/NdbThread.c diff --git a/ndb/src/common/portlib/unix/NdbTick.c b/ndb/src/common/portlib/NdbTick.c similarity index 100% rename from ndb/src/common/portlib/unix/NdbTick.c rename to ndb/src/common/portlib/NdbTick.c diff --git a/ndb/src/common/portlib/memtest/memtest.c b/ndb/src/common/portlib/memtest.c similarity index 100% rename from ndb/src/common/portlib/memtest/memtest.c rename to ndb/src/common/portlib/memtest.c diff --git a/ndb/src/common/portlib/mmstest/mmslist.cpp b/ndb/src/common/portlib/mmslist.cpp similarity index 100% rename from ndb/src/common/portlib/mmstest/mmslist.cpp rename to ndb/src/common/portlib/mmslist.cpp diff --git a/ndb/src/common/portlib/mmstest/mmstest.cpp b/ndb/src/common/portlib/mmstest.cpp similarity index 100% rename from ndb/src/common/portlib/mmstest/mmstest.cpp rename to ndb/src/common/portlib/mmstest.cpp diff --git a/ndb/src/common/portlib/memtest/munmaptest/munmaptest.cpp b/ndb/src/common/portlib/munmaptest.cpp similarity index 100% rename from ndb/src/common/portlib/memtest/munmaptest/munmaptest.cpp rename to ndb/src/common/portlib/munmaptest.cpp diff --git a/ndb/src/common/portlib/memtest/Makefile b/ndb/src/common/portlib/old_dirs/memtest/Makefile similarity index 100% rename from ndb/src/common/portlib/memtest/Makefile rename to ndb/src/common/portlib/old_dirs/memtest/Makefile diff --git a/ndb/src/common/portlib/memtest/munmaptest/Makefile b/ndb/src/common/portlib/old_dirs/memtest/munmaptest/Makefile similarity index 100% rename from ndb/src/common/portlib/memtest/munmaptest/Makefile rename to ndb/src/common/portlib/old_dirs/memtest/munmaptest/Makefile diff --git a/ndb/src/common/portlib/ose/Makefile b/ndb/src/common/portlib/old_dirs/ose/Makefile similarity index 100% rename from ndb/src/common/portlib/ose/Makefile rename to ndb/src/common/portlib/old_dirs/ose/Makefile diff --git a/ndb/src/common/portlib/ose/NdbCondition.c b/ndb/src/common/portlib/old_dirs/ose/NdbCondition.c similarity index 100% rename from ndb/src/common/portlib/ose/NdbCondition.c rename to ndb/src/common/portlib/old_dirs/ose/NdbCondition.c diff --git a/ndb/src/common/portlib/ose/NdbConditionOSE.h b/ndb/src/common/portlib/old_dirs/ose/NdbConditionOSE.h similarity index 100% rename from ndb/src/common/portlib/ose/NdbConditionOSE.h rename to ndb/src/common/portlib/old_dirs/ose/NdbConditionOSE.h diff --git a/ndb/src/common/portlib/ose/NdbEnv.c b/ndb/src/common/portlib/old_dirs/ose/NdbEnv.c similarity index 100% rename from ndb/src/common/portlib/ose/NdbEnv.c rename to ndb/src/common/portlib/old_dirs/ose/NdbEnv.c diff --git a/ndb/src/common/portlib/ose/NdbHost.c b/ndb/src/common/portlib/old_dirs/ose/NdbHost.c similarity index 100% rename from ndb/src/common/portlib/ose/NdbHost.c rename to ndb/src/common/portlib/old_dirs/ose/NdbHost.c diff --git a/ndb/src/common/portlib/ose/NdbMem.c b/ndb/src/common/portlib/old_dirs/ose/NdbMem.c similarity index 100% rename from ndb/src/common/portlib/ose/NdbMem.c rename to ndb/src/common/portlib/old_dirs/ose/NdbMem.c diff --git a/ndb/src/common/portlib/ose/NdbMem_SoftOse.cpp b/ndb/src/common/portlib/old_dirs/ose/NdbMem_SoftOse.cpp similarity index 100% rename from ndb/src/common/portlib/ose/NdbMem_SoftOse.cpp rename to ndb/src/common/portlib/old_dirs/ose/NdbMem_SoftOse.cpp diff --git a/ndb/src/common/portlib/ose/NdbMutex.c b/ndb/src/common/portlib/old_dirs/ose/NdbMutex.c similarity index 100% rename from ndb/src/common/portlib/ose/NdbMutex.c rename to ndb/src/common/portlib/old_dirs/ose/NdbMutex.c diff --git a/ndb/src/common/portlib/ose/NdbOut.cpp b/ndb/src/common/portlib/old_dirs/ose/NdbOut.cpp similarity index 100% rename from ndb/src/common/portlib/ose/NdbOut.cpp rename to ndb/src/common/portlib/old_dirs/ose/NdbOut.cpp diff --git a/ndb/src/common/portlib/ose/NdbSleep.c b/ndb/src/common/portlib/old_dirs/ose/NdbSleep.c similarity index 100% rename from ndb/src/common/portlib/ose/NdbSleep.c rename to ndb/src/common/portlib/old_dirs/ose/NdbSleep.c diff --git a/ndb/src/common/portlib/ose/NdbTCP.c b/ndb/src/common/portlib/old_dirs/ose/NdbTCP.c similarity index 100% rename from ndb/src/common/portlib/ose/NdbTCP.c rename to ndb/src/common/portlib/old_dirs/ose/NdbTCP.c diff --git a/ndb/src/common/portlib/ose/NdbThread.c b/ndb/src/common/portlib/old_dirs/ose/NdbThread.c similarity index 100% rename from ndb/src/common/portlib/ose/NdbThread.c rename to ndb/src/common/portlib/old_dirs/ose/NdbThread.c diff --git a/ndb/src/common/portlib/ose/NdbTick.c b/ndb/src/common/portlib/old_dirs/ose/NdbTick.c similarity index 100% rename from ndb/src/common/portlib/ose/NdbTick.c rename to ndb/src/common/portlib/old_dirs/ose/NdbTick.c diff --git a/ndb/src/common/portlib/test/Makefile b/ndb/src/common/portlib/old_dirs/test/Makefile similarity index 100% rename from ndb/src/common/portlib/test/Makefile rename to ndb/src/common/portlib/old_dirs/test/Makefile diff --git a/ndb/src/common/portlib/unix/Makefile_old b/ndb/src/common/portlib/old_dirs/unix/Makefile_old similarity index 100% rename from ndb/src/common/portlib/unix/Makefile_old rename to ndb/src/common/portlib/old_dirs/unix/Makefile_old diff --git a/ndb/src/common/portlib/win32/Makefile b/ndb/src/common/portlib/old_dirs/win32/Makefile similarity index 100% rename from ndb/src/common/portlib/win32/Makefile rename to ndb/src/common/portlib/old_dirs/win32/Makefile diff --git a/ndb/src/common/portlib/win32/NdbCondition.c b/ndb/src/common/portlib/old_dirs/win32/NdbCondition.c similarity index 100% rename from ndb/src/common/portlib/win32/NdbCondition.c rename to ndb/src/common/portlib/old_dirs/win32/NdbCondition.c diff --git a/ndb/src/common/portlib/win32/NdbDaemon.c b/ndb/src/common/portlib/old_dirs/win32/NdbDaemon.c similarity index 100% rename from ndb/src/common/portlib/win32/NdbDaemon.c rename to ndb/src/common/portlib/old_dirs/win32/NdbDaemon.c diff --git a/ndb/src/common/portlib/win32/NdbEnv.c b/ndb/src/common/portlib/old_dirs/win32/NdbEnv.c similarity index 100% rename from ndb/src/common/portlib/win32/NdbEnv.c rename to ndb/src/common/portlib/old_dirs/win32/NdbEnv.c diff --git a/ndb/src/common/portlib/win32/NdbHost.c b/ndb/src/common/portlib/old_dirs/win32/NdbHost.c similarity index 100% rename from ndb/src/common/portlib/win32/NdbHost.c rename to ndb/src/common/portlib/old_dirs/win32/NdbHost.c diff --git a/ndb/src/common/portlib/win32/NdbMem.c b/ndb/src/common/portlib/old_dirs/win32/NdbMem.c similarity index 100% rename from ndb/src/common/portlib/win32/NdbMem.c rename to ndb/src/common/portlib/old_dirs/win32/NdbMem.c diff --git a/ndb/src/common/portlib/win32/NdbMutex.c b/ndb/src/common/portlib/old_dirs/win32/NdbMutex.c similarity index 100% rename from ndb/src/common/portlib/win32/NdbMutex.c rename to ndb/src/common/portlib/old_dirs/win32/NdbMutex.c diff --git a/ndb/src/common/portlib/win32/NdbSleep.c b/ndb/src/common/portlib/old_dirs/win32/NdbSleep.c similarity index 100% rename from ndb/src/common/portlib/win32/NdbSleep.c rename to ndb/src/common/portlib/old_dirs/win32/NdbSleep.c diff --git a/ndb/src/common/portlib/win32/NdbTCP.c b/ndb/src/common/portlib/old_dirs/win32/NdbTCP.c similarity index 100% rename from ndb/src/common/portlib/win32/NdbTCP.c rename to ndb/src/common/portlib/old_dirs/win32/NdbTCP.c diff --git a/ndb/src/common/portlib/win32/NdbThread.c b/ndb/src/common/portlib/old_dirs/win32/NdbThread.c similarity index 100% rename from ndb/src/common/portlib/win32/NdbThread.c rename to ndb/src/common/portlib/old_dirs/win32/NdbThread.c diff --git a/ndb/src/common/portlib/win32/NdbTick.c b/ndb/src/common/portlib/old_dirs/win32/NdbTick.c similarity index 100% rename from ndb/src/common/portlib/win32/NdbTick.c rename to ndb/src/common/portlib/old_dirs/win32/NdbTick.c diff --git a/ndb/src/common/portlib/unix/Makefile.am b/ndb/src/common/portlib/unix/Makefile.am deleted file mode 100644 index f50d46c1873..00000000000 --- a/ndb/src/common/portlib/unix/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ - -noinst_LTLIBRARIES = libportlib.la - -libportlib_la_SOURCES = \ - NdbCondition.c NdbMutex.c NdbSleep.c NdbTick.c \ - NdbEnv.c NdbThread.c NdbHost.c NdbTCP.c \ - NdbDaemon.c NdbMem.c - -include $(top_srcdir)/ndb/config/common.mk.am -include $(top_srcdir)/ndb/config/type_util.mk.am - -# Don't update the files from bitkeeper -%::SCCS/s.% diff --git a/ndb/src/kernel/Makefile.am b/ndb/src/kernel/Makefile.am index 7f2f33bd8e5..485c47652c2 100644 --- a/ndb/src/kernel/Makefile.am +++ b/ndb/src/kernel/Makefile.am @@ -51,7 +51,7 @@ LDADD += \ $(top_srcdir)/ndb/src/common/logger/liblogger.la \ $(top_srcdir)/ndb/src/common/mgmcommon/libmgmsrvcommon.la \ $(top_srcdir)/ndb/src/mgmapi/libmgmapi.la \ - $(top_srcdir)/ndb/src/common/portlib/unix/libportlib.la \ + $(top_srcdir)/ndb/src/common/portlib/libportlib.la \ $(top_srcdir)/ndb/src/common/util/libgeneral.la # Don't update the files from bitkeeper diff --git a/ndb/test/Makefile.am b/ndb/test/Makefile.am index c535344ac54..2e0f30df9d4 100644 --- a/ndb/test/Makefile.am +++ b/ndb/test/Makefile.am @@ -1,5 +1,4 @@ -SUBDIRS = src $(ndb_opt_test_subdirs) -DIST_SUBDIRS = src tools ndbapi run-test +SUBDIRS = src tools ndbapi run-test EXTRA_DIST = include diff --git a/ndb/tools/Makefile.am b/ndb/tools/Makefile.am index 3ca1cf1b1da..5b131bdf94a 100644 --- a/ndb/tools/Makefile.am +++ b/ndb/tools/Makefile.am @@ -9,14 +9,16 @@ ndbtools_PROGRAMS = \ ndb_select_all \ ndb_select_count -ndb_waiter_SOURCES = waiter.cpp -ndb_delete_all_SOURCES = delete_all.cpp -ndb_desc_SOURCES = desc.cpp -ndb_drop_index_SOURCES = drop_index.cpp -ndb_drop_table_SOURCES = drop_tab.cpp -ndb_show_tables_SOURCES = listTables.cpp -ndb_select_all_SOURCES = select_all.cpp -ndb_select_count_SOURCES = select_count.cpp +tools_common_sources = ../test/src/NDBT_ReturnCodes.cpp ../test/src/NDBT_Table.cpp ../test/src/NDBT_Output.cpp + +ndb_waiter_SOURCES = waiter.cpp $(tools_common_sources) +ndb_delete_all_SOURCES = delete_all.cpp $(tools_common_sources) +ndb_desc_SOURCES = desc.cpp $(tools_common_sources) +ndb_drop_index_SOURCES = drop_index.cpp $(tools_common_sources) +ndb_drop_table_SOURCES = drop_tab.cpp $(tools_common_sources) +ndb_show_tables_SOURCES = listTables.cpp $(tools_common_sources) +ndb_select_all_SOURCES = select_all.cpp ../test/src/NDBT_ResultRow.cpp $(tools_common_sources) +ndb_select_count_SOURCES = select_count.cpp $(tools_common_sources) include $(top_srcdir)/ndb/config/common.mk.am include $(top_srcdir)/ndb/config/type_ndbapitools.mk.am diff --git a/ndb/tools/delete_all.cpp b/ndb/tools/delete_all.cpp index 9cbba503e68..dabd9a0e8fa 100644 --- a/ndb/tools/delete_all.cpp +++ b/ndb/tools/delete_all.cpp @@ -23,19 +23,16 @@ #include -#include +static int clear_table(Ndb* pNdb, const NdbDictionary::Table* pTab, int parallelism=240); int main(int argc, const char** argv){ const char* _tabname = NULL; const char* _dbname = "TEST_DB"; int _help = 0; - int _ver2 = 1; struct getargs args[] = { { "usage", '?', arg_flag, &_help, "Print help", "" }, - { "ver2", '2', arg_flag, &_ver2, "Use version 2 of clearTable (default)", "" }, - { "ver2", '1', arg_negative_flag, &_ver2, "Use version 1 of clearTable", "" }, { "database", 'd', arg_string, &_dbname, "dbname", "Name of database table is in"} }; @@ -74,20 +71,111 @@ int main(int argc, const char** argv){ } ndbout << "Deleting all from " << argv[i] << "..."; - UtilTransactions utilTrans(*pTab); - int tmp = NDBT_OK; - if (_ver2 == 0){ - if(utilTrans.clearTable(&MyNdb) == NDBT_FAILED) - tmp = NDBT_FAILED; - } else { - if(utilTrans.clearTable3(&MyNdb) == NDBT_FAILED) - tmp = NDBT_FAILED; - } - if(tmp == NDBT_FAILED){ - res = tmp; + if(clear_table(&MyNdb, pTab) == NDBT_FAILED){ + res = NDBT_FAILED; ndbout << "FAILED" << endl; } } return NDBT_ProgramExit(res); } + +int clear_table(Ndb* pNdb, const NdbDictionary::Table* pTab, int parallelism) +{ + // Scan all records exclusive and delete + // them one by one + int retryAttempt = 0; + const int retryMax = 10; + int deletedRows = 0; + int check; + NdbConnection *pTrans; + 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 = pTrans->getNdbScanOperation(pTab->getName()); + if (pOp == NULL) { + goto failed; + } + + NdbResultSet * rs = pOp->readTuplesExclusive(par); + if( rs == 0 ) { + goto failed; + } + + if(pTrans->execute(NoCommit) != 0){ + err = pTrans->getNdbError(); + if(err.status == NdbError::TemporaryError){ + ERR(err); + pNdb->closeTransaction(pTrans); + NdbSleep_MilliSleep(50); + continue; + } + goto failed; + } + + while((check = rs->nextResult(true)) == 0){ + do { + if (rs->deleteTuple() != 0){ + goto failed; + } + deletedRows++; + } while((check = rs->nextResult(false)) == 0); + + if(check != -1){ + check = pTrans->execute(Commit); + pTrans->releaseCompletedOperations(); + } + + err = pTrans->getNdbError(); + if(check == -1){ + if(err.status == NdbError::TemporaryError){ + ERR(err); + pNdb->closeTransaction(pTrans); + NdbSleep_MilliSleep(50); + par = 1; + goto restart; + } + goto failed; + } + } + if(check == -1){ + err = pTrans->getNdbError(); + if(err.status == NdbError::TemporaryError){ + ERR(err); + pNdb->closeTransaction(pTrans); + NdbSleep_MilliSleep(50); + par = 1; + goto restart; + } + goto failed; + } + pNdb->closeTransaction(pTrans); + return NDBT_OK; + } + return NDBT_FAILED; + + failed: + if(pTrans != 0) pNdb->closeTransaction(pTrans); + ERR(err); + return (err.code != 0 ? err.code : NDBT_FAILED); +} diff --git a/ndb/tools/select_count.cpp b/ndb/tools/select_count.cpp index b1513ad4135..cae91feb378 100644 --- a/ndb/tools/select_count.cpp +++ b/ndb/tools/select_count.cpp @@ -26,6 +26,12 @@ #include #include +static int +select_count(Ndb* pNdb, const NdbDictionary::Table* pTab, + int parallelism, + int* count_rows, + UtilTransactions::ScanLock lock, + NdbConnection* pBuddyTrans=0); int main(int argc, const char** argv){ const char* _dbname = "TEST_DB"; @@ -75,9 +81,8 @@ int main(int argc, const char** argv){ } int rows = 0; - UtilTransactions utilTrans(*pTab); - if (utilTrans.selectCount(&MyNdb, _parallelism, &rows, - (UtilTransactions::ScanLock)_lock) != 0){ + if (select_count(&MyNdb, pTab, _parallelism, &rows, + (UtilTransactions::ScanLock)_lock) != 0){ return NDBT_ProgramExit(NDBT_FAILED); } @@ -86,5 +91,109 @@ int main(int argc, const char** argv){ return NDBT_ProgramExit(NDBT_OK); } +int +select_count(Ndb* pNdb, const NdbDictionary::Table* pTab, + int parallelism, + int* count_rows, + UtilTransactions::ScanLock lock, + NdbConnection* pBuddyTrans){ + + int retryAttempt = 0; + const int retryMax = 100; + int check; + NdbConnection *pTrans; + NdbOperation *pOp; + + while (true){ + + if (retryAttempt >= retryMax){ + g_info << "ERROR: has retried this operation " << retryAttempt + << " times, failing!" << endl; + return NDBT_FAILED; + } + + pTrans = pNdb->hupp(pBuddyTrans); + if (pTrans == NULL) { + const NdbError err = pNdb->getNdbError(); + + if (err.status == NdbError::TemporaryError){ + NdbSleep_MilliSleep(50); + retryAttempt++; + continue; + } + ERR(err); + return NDBT_FAILED; + } + pOp = pTrans->getNdbOperation(pTab->getName()); + if (pOp == NULL) { + ERR(pTrans->getNdbError()); + pNdb->closeTransaction(pTrans); + return NDBT_FAILED; + } + + switch(lock){ + case UtilTransactions::SL_ReadHold: + check = pOp->openScanReadHoldLock(parallelism); + break; + case UtilTransactions::SL_Exclusive: + check = pOp->openScanExclusive(parallelism); + break; + case UtilTransactions::SL_Read: + default: + check = pOp->openScanRead(parallelism); + } + + 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; + } + + check = pTrans->executeScan(); + if( check == -1 ) { + ERR(pTrans->getNdbError()); + pNdb->closeTransaction(pTrans); + return NDBT_FAILED; + } + + int eof; + int rows = 0; + eof = pTrans->nextScanResult(); + + while(eof == 0){ + rows++; + eof = pTrans->nextScanResult(); + } + if (eof == -1) { + const NdbError err = pTrans->getNdbError(); + + if (err.status == NdbError::TemporaryError){ + pNdb->closeTransaction(pTrans); + NdbSleep_MilliSleep(50); + retryAttempt++; + continue; + } + ERR(err); + pNdb->closeTransaction(pTrans); + return NDBT_FAILED; + } + + pNdb->closeTransaction(pTrans); + + if (count_rows != NULL){ + *count_rows = rows; + } + + return NDBT_OK; + } + return NDBT_FAILED; +} diff --git a/ndb/tools/waiter.cpp b/ndb/tools/waiter.cpp index d57daff3aea..549e0dc1ec3 100644 --- a/ndb/tools/waiter.cpp +++ b/ndb/tools/waiter.cpp @@ -15,17 +15,19 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mgmapi.h" +#include #include #include #include #include #include +#include - -#include #include +int +waitClusterStarted(const char* _addr, unsigned int _timeout= 120); + int main(int argc, const char** argv){ const char* _hostName = NULL; @@ -47,10 +49,216 @@ int main(int argc, const char** argv){ } _hostName = argv[optind]; - NdbRestarter restarter(_hostName); + // NdbRestarter restarter(_hostName); - if (restarter.waitClusterStarted() != 0) + if (waitClusterStarted(_hostName) != 0) return NDBT_ProgramExit(NDBT_FAILED); return NDBT_ProgramExit(NDBT_OK); } + +#define MGMERR(h) \ + ndbout << "latest_error="< 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["<node_id << " " + << ndb_mgm_get_node_status_string(ndbNode->node_status)<< 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="<start_phase<node_status != _status) { + if (ndbNode->node_status < _status) + allInState = false; + else + g_info << "node_status(" << ndbNode->node_status + <<") != _status("<<_status<<")"<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; +}