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; }
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 main(int argc, char** argv) { NDB_INIT(argv[0]); const char *load_default_groups[]= { "mysql_cluster",0 }; ndb_load_defaults(NULL,load_default_groups,&argc,&argv); int ho_error; #ifndef DBUG_OFF opt_debug= "d:t:O,/tmp/eventlog.trace"; #endif #ifndef _WIN32 // Catching signal to allow testing of EINTR safeness // with "while killall -USR1 eventlog; do true; done" signal(SIGUSR1, catch_signal); #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_ndb_connectstring); 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; }
int ndb_logevent_get_next(const NdbLogEventHandle h, struct ndb_logevent *dst, unsigned timeout_in_milliseconds) { if (timeout_in_milliseconds == 0) { int res; while ((res = ndb_logevent_get_next(h, dst, 60000))==0); return res; } SocketInputStream in(h->socket, timeout_in_milliseconds); Properties p; char buf[256]; /* header */ while (1) { if (in.gets(buf,sizeof(buf)) == 0) { h->m_error= NDB_LEH_READ_ERROR; return -1; } if ( buf[0] == 0 ) { // timed out return 0; } if ( strcmp("log event reply\n", buf) == 0 ) break; if ( strcmp("<PING>\n", buf) ) ndbout_c("skipped: %s", buf); if(in.timedout()) return 0; } /* read name-value pairs into properties object */ while (1) { if (in.gets(buf,sizeof(buf)) == 0) { h->m_error= NDB_LEH_READ_ERROR; return -1; } if (in.timedout()) return 0; if ( buf[0] == '\n' ) { break; } if (insert_row(buf,p)) { h->m_error= NDB_LEH_READ_ERROR; return -1; } } int i; const char *val; dst->type= (enum Ndb_logevent_type)-1; /* fill in header info from p*/ for (i= 0; ndb_logevent_header[i].token; i++) { if ( p.get(ndb_logevent_header[i].token, &val) == 0 ) { ndbout_c("missing: %s\n", ndb_logevent_header[i].token); h->m_error= NDB_LEH_MISSING_EVENT_SPECIFIER; return -1; } if ( memcpy_atoi((char *)dst+ndb_logevent_header[i].offset, val, ndb_logevent_header[i].size) ) { h->m_error= NDB_LEH_INTERNAL_ERROR; return -1; } } Uint32 level; LogLevel::EventCategory category; Logger::LoggerLevel severity; EventLoggerBase::EventTextFunction text_fn; /* fill in rest of header info event_lookup */ if (EventLoggerBase::event_lookup(dst->type,category,level,severity,text_fn)) { ndbout_c("unknown type: %d\n", dst->type); h->m_error= NDB_LEH_UNKNOWN_EVENT_TYPE; return -1; } dst->category= (enum ndb_mgm_event_category)category; dst->severity= (enum ndb_mgm_event_severity)severity; dst->level= level; /* fill in header info from p */ for (i= 0; ndb_logevent_body[i].token; i++) { if ( ndb_logevent_body[i].type != dst->type ) continue; if ( p.get(ndb_logevent_body[i].token, &val) == 0 ) { h->m_error= NDB_LEH_UNKNOWN_EVENT_VARIABLE; return -1; } if ( memcpy_atoi((char *)dst+ndb_logevent_body[i].offset, val, ndb_logevent_body[i].size) ) { h->m_error= NDB_LEH_INTERNAL_ERROR; return -1; } } return 1; }
int ndb_logevent_get_next(const NdbLogEventHandle h, struct ndb_logevent *dst, unsigned timeout_in_milliseconds) { if (timeout_in_milliseconds == 0) { int res; while ((res = ndb_logevent_get_next(h, dst, 60000))==0); return res; } SocketInputStream in(h->socket, timeout_in_milliseconds); /* Read log event header until header received or timeout expired. The MGM server will continusly send <PING>'s that should be ignored. */ char buf[1024]; NDB_TICKS start = NdbTick_CurrentMillisecond(); while(1) { if (in.gets(buf,sizeof(buf)) == 0) { h->m_error= NDB_LEH_READ_ERROR; return -1; } if ( buf[0] == 0 ) { // timed out return 0; } if ( strcmp("log event reply\n", buf) == 0 ) break; if ( strcmp("<PING>\n", buf) ) ndbout_c("skipped: %s", buf); if(in.timedout()) return 0; if ((NdbTick_CurrentMillisecond() - start) > timeout_in_milliseconds) return 0; }; /* Read name-value pairs until empty new line */ Properties p; while (1) { if (in.gets(buf,sizeof(buf)) == 0) { h->m_error= NDB_LEH_READ_ERROR; return -1; } if (in.timedout()) return 0; if ( buf[0] == '\n' ) { break; } if (insert_row(buf,p)) { h->m_error= NDB_LEH_READ_ERROR; return -1; } } int i; const char *val; dst->type= (enum Ndb_logevent_type)-1; /* fill in header info from p*/ for (i= 0; ndb_logevent_header[i].token; i++) { if ( p.get(ndb_logevent_header[i].token, &val) == 0 ) { ndbout_c("missing: %s\n", ndb_logevent_header[i].token); h->m_error= NDB_LEH_MISSING_EVENT_SPECIFIER; return -1; } if ( memcpy_atoi((char *)dst+ndb_logevent_header[i].offset, val, ndb_logevent_header[i].size) ) { h->m_error= NDB_LEH_INTERNAL_ERROR; return -1; } } Uint32 level; LogLevel::EventCategory category; Logger::LoggerLevel severity; EventLoggerBase::EventTextFunction text_fn; /* fill in rest of header info event_lookup */ if (EventLoggerBase::event_lookup(dst->type,category,level,severity,text_fn)) { ndbout_c("unknown type: %d\n", dst->type); h->m_error= NDB_LEH_UNKNOWN_EVENT_TYPE; return -1; } dst->category= (enum ndb_mgm_event_category)category; dst->severity= (enum ndb_mgm_event_severity)severity; dst->level= level; /* fill in header info from p */ for (i= 0; ndb_logevent_body[i].token; i++) { if ( ndb_logevent_body[i].type == dst->type ) break; } if (ndb_logevent_body[i].token) { do { if ( p.get(ndb_logevent_body[i].token, &val) == 0 ) { h->m_error= NDB_LEH_UNKNOWN_EVENT_VARIABLE; return -1; } if ( memcpy_atoi((char *)dst+ndb_logevent_body[i].offset, val, ndb_logevent_body[i].size) ) { h->m_error= NDB_LEH_INTERNAL_ERROR; return -1; } } while (ndb_logevent_body[++i].type == dst->type); } else { if (!p.get("data", &val)) { h->m_error= NDB_LEH_UNKNOWN_EVENT_VARIABLE; return -1; } BaseString tmp(val); Vector<BaseString> list; tmp.split(list); for (size_t j = 0; j<list.size(); j++) { dst->Data[j] = atoi(list[j].c_str()); } } return 1; }