Commit a481c4aa authored by tomas@mc05.(none)'s avatar tomas@mc05.(none)

merge

parents 3ac197b3 9711b3c3
......@@ -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
......
SUBDIRS = src test tools . include
SUBDIRS = src tools . include $(ndb_opt_test_subdirs)
EXTRA_DIST = config
include $(top_srcdir)/ndb/config/common.mk.am
......
LDADD += $(top_builddir)/ndb/test/src/libNDBT.a \
$(top_builddir)/ndb/src/libndbclient.la
LDADD += $(top_builddir)/ndb/src/libndbclient.la
INCLUDES += -I$(srcdir) -I$(top_srcdir)/include \
-I$(top_srcdir)/ndb/include \
......
......@@ -14,5 +14,5 @@ libndbclient_la_LIBADD = \
common/mgmcommon/libmgmsrvcommon.la \
mgmapi/libmgmapi.la \
common/logger/liblogger.la \
common/portlib/unix/libportlib.la \
common/portlib/libportlib.la \
common/util/libgeneral.la
......@@ -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
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
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.%
......@@ -51,7 +51,7 @@ LDADD += \
$(top_builddir)/ndb/src/common/logger/liblogger.la \
$(top_builddir)/ndb/src/common/mgmcommon/libmgmsrvcommon.la \
$(top_builddir)/ndb/src/mgmapi/libmgmapi.la \
$(top_builddir)/ndb/src/common/portlib/unix/libportlib.la \
$(top_builddir)/ndb/src/common/portlib/libportlib.la \
$(top_builddir)/ndb/src/common/util/libgeneral.la
# Don't update the files from bitkeeper
......
SUBDIRS = src $(ndb_opt_test_subdirs)
DIST_SUBDIRS = src tools ndbapi run-test
SUBDIRS = src tools ndbapi run-test
EXTRA_DIST = include
......
......@@ -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
......
......@@ -23,19 +23,16 @@
#include <getarg.h>
#include <UtilTransactions.hpp>
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);
}
......@@ -26,6 +26,12 @@
#include <getarg.h>
#include <UtilTransactions.hpp>
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;
}
......@@ -15,17 +15,19 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "mgmapi.h"
#include <mgmapi.h>
#include <string.h>
#include <NdbMain.h>
#include <NdbOut.hpp>
#include <NdbSleep.h>
#include <getarg.h>
#include <kernel/ndb_limits.h>
#include <NdbRestarter.hpp>
#include <NDBT.hpp>
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="<<ndb_mgm_get_latest_error(h) \
<< ", line="<<ndb_mgm_get_latest_error_line(h) \
<< endl;
NdbMgmHandle handle= NULL;
Vector<ndb_mgm_node_state> ndbNodes;
Vector<ndb_mgm_node_state> mgmNodes;
Vector<ndb_mgm_node_state> apiNodes;
int
getStatus(){
int retries = 0;
struct ndb_mgm_cluster_state * status;
struct ndb_mgm_node_state * node;
ndbNodes.clear();
mgmNodes.clear();
apiNodes.clear();
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
waitClusterStarted(const char* _addr, unsigned int _timeout)
{
ndb_mgm_node_status _status = NDB_MGM_NODE_STATUS_STARTED;
int _startphase = -1;
int _nodes[MAX_NDB_NODES];
int _num_nodes = 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;
_num_nodes++;
}
handle = ndb_mgm_create_handle();
if (handle == NULL){
g_err << "handle == NULL" << endl;
return -1;
}
g_info << "Connecting to mgmsrv at " << _addr << endl;
if (ndb_mgm_connect(handle, _addr) == -1) {
MGMERR(handle);
g_err << "Connection to " << _addr << " failed" << 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)<< 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;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment