int fiftyPercentStopAndWait(F_ARGS){ 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; }
Uint32 ConfigRetriever::allocNodeId(int no_retries, int retry_delay_in_seconds) { int res; _ownNodeId= 0; if(m_handle != 0) { while (1) { if(!ndb_mgm_is_connected(m_handle)) if(!ndb_mgm_connect(m_handle, 0, 0, 0)) goto next; res= ndb_mgm_alloc_nodeid(m_handle, m_version, m_node_type, no_retries == 0 /* only log last retry */); if(res >= 0) return _ownNodeId= (Uint32)res; next: int error = ndb_mgm_get_latest_error(m_handle); if (no_retries == 0 || error == NDB_MGM_ALLOCID_CONFIG_MISMATCH) break; no_retries--; NdbSleep_SecSleep(retry_delay_in_seconds); } BaseString tmp(ndb_mgm_get_latest_error_msg(m_handle)); tmp.append(" : "); tmp.append(ndb_mgm_get_latest_error_desc(m_handle)); setError(CR_ERROR, tmp.c_str()); } else setError(CR_ERROR, "management server handle not initialized"); return 0; }
int stopOnError(F_ARGS){ myRandom48Init((long)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 desc_table(Ndb *myndb, char* name) { NdbDictionary::Dictionary * dict= myndb->getDictionary(); NdbDictionary::Table const* pTab; while ((pTab = dict->getTable(name)) == NULL && --_retries >= 0) NdbSleep_SecSleep(1); if (!pTab) return 0; ndbout << "-- " << pTab->getName() << " --" << endl; dict->print(ndbout, *pTab); if (_partinfo) { print_part_info(myndb, pTab); ndbout << endl; if (_blobinfo) { int noOfAttributes = pTab->getNoOfColumns(); for (int i = 0; i < noOfAttributes; i++) { const NdbDictionary::Column* column = pTab->getColumn(i); if ((column->getType() == NdbDictionary::Column::Blob) || (column->getType() == NdbDictionary::Column::Text)) { print_part_info(myndb, (NDBT_Table*) column->getBlobTable()); ndbout << endl; } } } } return 1; }
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); }
void Ndb_cluster_connection_impl::connect_thread() { DBUG_ENTER("Ndb_cluster_connection_impl::connect_thread"); int r; do { NdbSleep_SecSleep(1); if ((r = connect(0,0,0)) == 0) break; if (r == -1) { printf("Ndb_cluster_connection::connect_thread error\n"); DBUG_ASSERT(false); m_run_connect_thread= 0; } else { // Wait before making a new connect attempt NdbSleep_SecSleep(1); } } while (m_run_connect_thread); if (m_connect_callback) (*m_connect_callback)(); DBUG_VOID_RETURN; }
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); }
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, false, 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, 1 }; 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; }
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; }
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 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); }
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; }
static bool start_process(pid_t& pid, const char* path, const char* cwd, const Args& args) { #ifdef _WIN32 #else int retries = 5; pid_t tmp; while ((tmp = fork()) == -1) { fprintf(stderr, "Warning: 'fork' failed, errno: %d - ", errno); if (retries--) { fprintf(stderr, "retrying in 1 second...\n"); NdbSleep_SecSleep(1); continue; } fprintf(stderr, "giving up...\n"); return false; } if (tmp) { pid = tmp; printf("Started process: %d\n", pid); return true; } assert(tmp == 0); if (cwd && chdir(cwd) != 0) { fprintf(stderr, "Failed to change directory to '%s', errno: %d\n", cwd, errno); exit(1); } // Concatenate arguments BaseString args_str; args_str.assign(args.args(), " "); char **argv = BaseString::argify(path, args_str.c_str()); //printf("name: %s\n", path); execv(path, argv); fprintf(stderr, "execv failed, errno: %d\n", errno); exit(1); #endif }
void Cmvmi::execNDB_TAMPER(Signal* signal) { jamEntry(); SET_ERROR_INSERT_VALUE(signal->theData[0]); if(ERROR_INSERTED(9999)){ CRASH_INSERTION(9999); } if(ERROR_INSERTED(9998)){ while(true) NdbSleep_SecSleep(1); } if(ERROR_INSERTED(9997)){ ndbrequire(false); } #ifndef NDB_WIN32 if(ERROR_INSERTED(9996)){ simulate_error_during_shutdown= SIGSEGV; ndbrequire(false); } if(ERROR_INSERTED(9995)){ simulate_error_during_shutdown= SIGSEGV; kill(getpid(), SIGABRT); } #endif #ifdef ERROR_INSERT if (signal->theData[0] == 9003) { if (MAX_RECEIVED_SIGNALS < 1024) { MAX_RECEIVED_SIGNALS = 1024; } else { MAX_RECEIVED_SIGNALS = 1 + (rand() % 128); } ndbout_c("MAX_RECEIVED_SIGNALS: %d", MAX_RECEIVED_SIGNALS); CLEAR_ERROR_INSERT_VALUE; } #endif }//execNDB_TAMPER()
int desc_table(Ndb *myndb, char* name) { NdbDictionary::Dictionary * dict= myndb->getDictionary(); NDBT_Table* pTab; while ((pTab = (NDBT_Table*)dict->getTable(name)) == NULL && --_retries >= 0) NdbSleep_SecSleep(1); if (!pTab) return 0; ndbout << (* pTab) << endl; NdbDictionary::Dictionary::List list; if (dict->listIndexes(list, name) != 0){ ndbout << name << ": " << dict->getNdbError() << endl; return NDBT_ProgramExit(NDBT_FAILED); } ndbout << "-- Indexes -- " << endl; ndbout << "PRIMARY KEY("; unsigned j; for (j= 0; (int)j < pTab->getNoOfPrimaryKeys(); j++) { const NdbDictionary::Column * col= pTab->getColumn(pTab->getPrimaryKey(j)); ndbout << col->getName(); if ((int)j < pTab->getNoOfPrimaryKeys()-1) ndbout << ", "; } ndbout << ") - UniqueHashIndex" << endl; for (j= 0; j < list.count; j++) { NdbDictionary::Dictionary::List::Element& elt = list.elements[j]; const NdbDictionary::Index *pIdx = dict->getIndex(elt.name, name); if (!pIdx){ ndbout << name << ": " << dict->getNdbError() << endl; return NDBT_ProgramExit(NDBT_FAILED); } ndbout << (*pIdx) << endl; } ndbout << endl; if (_partinfo) print_part_info(myndb, pTab); return 1; }
bool CNdbThreadManager::WaitAllThreadState( const EThreadState _ThreadState, const int _TimeOutSec) const { LOG_NDB_FUNCTION(); for (int nTry = 0; _TimeOutSec > nTry; ++nTry) { if (CNdbThreadManager::CheckAllThreadState(_ThreadState)) { LogNdbDebug << "OK" << endl; return true; } NdbSleep_SecSleep(1); } LogNdbDebug << "FAIL" << endl; return false; }
int desc_index(Ndb *myndb, char* name) { NdbDictionary::Dictionary * dict= myndb->getDictionary(); NdbDictionary::Index const* pIndex; /* need to know base table */ if (_tblname == NULL) return 0; while ((pIndex = dict->getIndex(name, _tblname)) == NULL && --_retries >= 0) NdbSleep_SecSleep(1); if (pIndex == NULL) return 0; ndbout << "-- " << pIndex->getName() << " --" << endl; dict->print(ndbout, *pIndex); return 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); }
// 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; }
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 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 NdbRestarts::executeRestart(NDBT_Context* ctx, const NdbRestarts::NdbRestart* _restart, unsigned int _timeout, int safety){ // Check that there are enough nodes in the cluster // for this test NdbRestarter restarter(0, &ctx->m_cluster_connection); 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(ctx, restarter, _restart, safety); // 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 main(int argc, const char **argv){ const char * progName = argv[0]; loopCount = 100; sendBufSz = -1; recvBufSz = -1; isClient = false; isConnected = false; isStarted = false; currentPhase = 0; signalHandler(0); if(argc < 5){ usage(progName); return 0; } const char * type = argv[1]; const NodeId localNodeId = atoi(argv[2]); const char * localHostName = argv[3]; const char * remoteHost1 = argv[4]; if(argc >= 6) loopCount = atoi(argv[5]); if(argc >= 7) sendBufSz = atoi(argv[6]); if(argc >= 8) recvBufSz = atoi(argv[7]); if(localNodeId < 1 || localNodeId > 2){ ndbout << "localNodeId = " << localNodeId << endl << endl; usage(progName); return 0; } if(localNodeId == 1) ndbout << "-- ECHO CLIENT --" << endl; else ndbout << "-- ECHO SERVER --" << endl; ndbout << "localNodeId: " << localNodeId << endl; ndbout << "localHostName: " << localHostName << endl; ndbout << "remoteHost1 (node " << (localNodeId == 1?2:1) << "): " << remoteHost1 << endl; ndbout << "Loop count: " << loopCount << endl; ndbout << "-----------------" << endl; void * confTemplate = 0; CreateTransporterFunc func = 0; if(strcasecmp(type, "tcp") == 0){ func = createTCPTransporter; confTemplate = &tcpTemplate; } else if(strcasecmp(type, "sci") == 0){ func = createSCITransporter; confTemplate = &sciTemplate; } else if(strcasecmp(type, "shm") == 0){ func = createSHMTransporter; confTemplate = &shmTemplate; } else { ndbout << "Unsupported transporter type" << endl; return 0; } ndbout << "Creating transporter registry" << endl; tReg = new TransporterRegistry; tReg->init(localNodeId); switch(localNodeId){ case 1: (* func)(confTemplate, 1, 2, localHostName, remoteHost1, sendBufSz, recvBufSz); break; case 2: (* func)(confTemplate, 2, 1, localHostName, remoteHost1, sendBufSz, recvBufSz); break; } ndbout << "Doing startSending/startReceiving" << endl; tReg->startSending(); tReg->startReceiving(); ndbout << "Connecting" << endl; tReg->setPerformState(PerformConnect); tReg->checkConnections(); if(localNodeId == 1) client(2); else server(); isStarted = false; ndbout << "Sleep 3 secs" << endl; NdbSleep_SecSleep(3); ndbout << "Doing setPerformState(Disconnect)" << endl; tReg->setPerformState(PerformDisconnect); ndbout << "Doing checkConnections()" << endl; tReg->checkConnections(); ndbout << "Deleting transporter registry" << endl; delete tReg; tReg = 0; return 0; }
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; }
void MgmApiSession::getConfig(Parser_t::Context &, const class Properties &args) { Uint32 version, node = 0; args.get("version", &version); args.get("node", &node); const Config *conf = m_mgmsrv.getConfig(); if(conf == NULL) { m_output->println("get config reply"); m_output->println("result: Could not fetch configuration"); m_output->println(""); return; } if(node != 0){ bool compatible; switch (m_mgmsrv.getNodeType(node)) { case NDB_MGM_NODE_TYPE_NDB: compatible = ndbCompatible_mgmt_ndb(NDB_VERSION, version); break; case NDB_MGM_NODE_TYPE_API: case NDB_MGM_NODE_TYPE_MGM: compatible = ndbCompatible_mgmt_api(NDB_VERSION, version); break; default: m_output->println("get config"); m_output->println("result: unrecognignized node type"); m_output->println(""); return; } if (!compatible){ m_output->println("get config"); m_output->println("result: incompatible version mgmt 0x%x and node 0x%x", NDB_VERSION, version); m_output->println(""); return; } } NdbMutex_Lock(m_mgmsrv.m_configMutex); const ConfigValues * cfg = &conf->m_configValues->m_config; UtilBuffer src; cfg->pack(src); NdbMutex_Unlock(m_mgmsrv.m_configMutex); char *tmp_str = (char *) malloc(base64_needed_encoded_length(src.length())); (void) base64_encode(src.get_data(), src.length(), tmp_str); SLEEP_ERROR_INSERTED(1); m_output->println("get config reply"); m_output->println("result: Ok"); m_output->println("Content-Length: %d", strlen(tmp_str)); m_output->println("Content-Type: ndbconfig/octet-stream"); SLEEP_ERROR_INSERTED(2); m_output->println("Content-Transfer-Encoding: base64"); m_output->println(""); if(ERROR_INSERTED(3)) { int l= strlen(tmp_str); tmp_str[l/2]='\0'; m_output->println(tmp_str); NdbSleep_SecSleep(10); } m_output->println(tmp_str); free(tmp_str); return; }
int restartNFDuringNR(F_ARGS safety){ myRandom48Init((long)NdbTick_CurrentMillisecond()); int i; const int sz = sizeof(NFDuringNR_codes)/sizeof(NFDuringNR_codes[0]); for(i = 0; i<sz && !ctx->closeToTimeout(safety); 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"); 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; #ifdef NDB_USE_GET_ENV char buf[256]; if(NdbEnv_GetEnv("USER", buf, 256) == 0 || strcmp(buf, "ejonore") != 0) return NDBT_OK; for(i = 0; i<sz && !ctx->isTestStopped() && !ctx->closeToTimeout(safety);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"); } #endif 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 runRestarter(NDBT_Context* ctx, NDBT_Step* step) { int result = NDBT_OK; int loops = ctx->getNumLoops(); int waitprogress = ctx->getProperty("WaitProgress", (unsigned)0); int randnode = ctx->getProperty("RandNode", (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() > 2 ? 2 : restarter.getNumDbNodes()); if (loops < restarter.getNumDbNodes()) loops = restarter.getNumDbNodes(); NdbSleep_MilliSleep(200); Uint32 running = ctx->getProperty("Running", (Uint32)0); while (running == 0 && !ctx->isTestStopped()) { NdbSleep_MilliSleep(100); running = ctx->getProperty("Running", (Uint32)0); } if (ctx->isTestStopped()) return NDBT_FAILED; while(i<loops && result != NDBT_FAILED && !ctx->isTestStopped()){ int id = lastId % restarter.getNumDbNodes(); if (randnode == 1) { id = rand() % 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 (waitprogress) { Uint32 maxwait = 30; ndbout_c("running: 0x%.8x", running); for (Uint32 checks = 0; checks < 3 && !ctx->isTestStopped(); checks++) { ctx->setProperty("Running", (Uint32)0); for (; maxwait != 0 && !ctx->isTestStopped(); maxwait--) { if ((ctx->getProperty("Running", (Uint32)0) & running) == running) goto ok; NdbSleep_SecSleep(1); } if (ctx->isTestStopped()) { g_err << "Test stopped while waiting for progress!" << endl; return NDBT_FAILED; } g_err << "No progress made!!" << endl; return NDBT_FAILED; ok: g_err << "Progress made!! " << endl; } } 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; } if (waitprogress) { Uint32 maxwait = 30; ndbout_c("running: 0x%.8x", running); for (Uint32 checks = 0; checks < 3 && !ctx->isTestStopped(); checks++) { ctx->setProperty("Running", (Uint32)0); for (; maxwait != 0 && !ctx->isTestStopped(); maxwait--) { if ((ctx->getProperty("Running", (Uint32)0) & running) == running) goto ok2; NdbSleep_SecSleep(1); } if (ctx->isTestStopped()) { g_err << "Test stopped while waiting for progress!" << endl; return NDBT_FAILED; } g_err << "No progress made!!" << endl; return NDBT_FAILED; ok2: g_err << "Progress made!! " << endl; ctx->setProperty("Running", (Uint32)0); } } lastId++; i++; } ctx->stopTest(); return result; }
int main(int argc, const char **argv){ signalHandler(0); for(int i = 0; i<4; i++) signalReceived[i] = 0; if(argc < 5){ usage(argv[0]); return 0; } Uint32 noOfConnections = 0; const char * progName = argv[0]; const char * type = argv[1]; const NodeId localNodeId = atoi(argv[2]); const char * localHostName = argv[3]; const char * remoteHost1 = argv[4]; const char * remoteHost2 = NULL; if(argc == 5) noOfConnections = 1; else { noOfConnections = 2; remoteHost2 = argv[5]; } if(localNodeId < 1 || localNodeId > 3){ ndbout << "localNodeId = " << localNodeId << endl << endl; usage(progName); return 0; } ndbout << "-----------------" << endl; ndbout << "localNodeId: " << localNodeId << endl; ndbout << "localHostName: " << localHostName << endl; ndbout << "remoteHost1 (node " << (localNodeId == 1?2:1) << "): " << remoteHost1 << endl; if(noOfConnections == 2){ ndbout << "remoteHost2 (node " << (localNodeId == 3?2:3) << "): " << remoteHost2 << endl; } ndbout << "-----------------" << endl; void * confTemplate = 0; CreateTransporterFunc func = 0; if(strcasecmp(type, "tcp") == 0){ func = createTCPTransporter; confTemplate = &tcpTemplate; } else if(strcasecmp(type, "sci") == 0){ func = createSCITransporter; confTemplate = &sciTemplate; } else if(strcasecmp(type, "shm") == 0){ func = createSHMTransporter; confTemplate = &shmTemplate; } else { ndbout << "Unsupported transporter type" << endl; return 0; } ndbout << "Creating transporter registry" << endl; tReg = new TransporterRegistry; tReg->init(localNodeId); switch(localNodeId){ case 1: (* func)(confTemplate, 1, 2, localHostName, remoteHost1); if(noOfConnections == 2) (* func)(confTemplate, 1, 3, localHostName, remoteHost2); break; case 2: (* func)(confTemplate, 2, 1, localHostName, remoteHost1); if(noOfConnections == 2) (* func)(confTemplate, 2, 3, localHostName, remoteHost2); break; case 3: (* func)(confTemplate, 3, 1, localHostName, remoteHost1); if(noOfConnections == 2) (* func)(confTemplate, 3, 2, localHostName, remoteHost2); break; } ndbout << "Doing startSending/startReceiving" << endl; tReg->startSending(); tReg->startReceiving(); ndbout << "Connecting" << endl; tReg->setPerformState(PerformConnect); tReg->checkConnections(); unsigned sum = 0; do { sum = 0; for(int i = 0; i<4; i++) sum += signalReceived[i]; tReg->checkConnections(); tReg->external_IO(500); NdbSleep_MilliSleep(500); ndbout << "In main loop" << endl; } while(sum != 2*noOfConnections); ndbout << "Doing setPerformState(Disconnect)" << endl; tReg->setPerformState(PerformDisconnect); ndbout << "Doing checkConnections()" << endl; tReg->checkConnections(); ndbout << "Sleeping 3 secs" << endl; NdbSleep_SecSleep(3); ndbout << "Deleting transporter registry" << endl; delete tReg; tReg = 0; return 0; }
int runChangeUndoDataDuringBackup(NDBT_Context* ctx, NDBT_Step* step){ Ndb* pNdb= GETNDB(step); int records = ctx->getNumRecords(); int num = 5; if (records - 5 < 0) num = 1; HugoTransactions hugoTrans(*ctx->getTab()); //update all rows if(hugoTrans.pkUpdateRecords(pNdb, records) != 0) { g_err << "Can't update all the records" << endl; return NDBT_FAILED; } //delete first 10 rows if(hugoTrans.pkDelRecords(pNdb, num*2) != 0) { g_err << "Can't delete first 5 rows" << endl; return NDBT_FAILED; } //add 5 new rows at the first(0 ~ 4) NdbTransaction *pTransaction= pNdb->startTransaction(); if (pTransaction == NULL) { g_err << "Can't get transaction pointer" << endl; return NDBT_FAILED; } if(hugoTrans.setTransaction(pTransaction) != 0) { g_err << "Set transaction error" << endl; pNdb->closeTransaction(pTransaction); return NDBT_FAILED; } if(hugoTrans.pkInsertRecord(pNdb, 0, num, 2) != 0) { g_err << "pkInsertRecord error" << endl; pNdb->closeTransaction(pTransaction); return NDBT_FAILED; } if(pTransaction->execute(Commit ) != 0) { g_err << "Can't commit transaction delete" << endl; return NDBT_FAILED; } hugoTrans.closeTransaction(pNdb); // make sure backup have finish NdbBackup backup(GETNDB(step)->getNodeId()+1); // start log event if(backup.startLogEvent() != 0) { g_err << "Can't create log event" << endl; return NDBT_FAILED; } NdbSleep_SecSleep(15); int i = 0; while (1) { if (backup.checkBackupStatus() == 2) //complete break; else if (i == 15) { g_err << "Backup timeout" << endl; return NDBT_FAILED; } else NdbSleep_SecSleep(2); i++; } return NDBT_OK; }