コード例 #1
0
    bool subscribe_to_events(void)
    {
        if (!is_connected())
        {
            error("subscribe_to_events: not connected");
            return false;
        }

        int filter[] =
        {
            15, NDB_MGM_EVENT_CATEGORY_STARTUP,
            15, NDB_MGM_EVENT_CATEGORY_SHUTDOWN,
            15, NDB_MGM_EVENT_CATEGORY_STATISTIC,
            15, NDB_MGM_EVENT_CATEGORY_CHECKPOINT,
            15, NDB_MGM_EVENT_CATEGORY_NODE_RESTART,
            15, NDB_MGM_EVENT_CATEGORY_CONNECTION,
            15, NDB_MGM_EVENT_CATEGORY_BACKUP,
            15, NDB_MGM_EVENT_CATEGORY_CONGESTION,
            15, NDB_MGM_EVENT_CATEGORY_DEBUG,
            15, NDB_MGM_EVENT_CATEGORY_INFO,
            0
        };

#ifdef NDB_WIN
        m_event_socket.s = ndb_mgm_listen_event(m_handle, filter);
#else
        m_event_socket.fd = ndb_mgm_listen_event(m_handle, filter);
#endif

        return my_socket_valid(m_event_socket);
    }
コード例 #2
0
ファイル: testLcp.cpp プロジェクト: 4T-Shirt/mysql
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;
}
コード例 #3
0
static int continue_lcp(int error)
{
  int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_INFO, 0 };
  NDB_SOCKET_TYPE my_fd;
  my_socket_invalidate(&my_fd);
#ifdef NDB_WIN
  SOCKET fd;
#else
  int fd;
#endif

  if(error){
    fd = ndb_mgm_listen_event(g_restarter.handle, filter);
#ifdef NDB_WIN
    my_fd.s= fd;
#else
    my_fd.fd= fd;
#endif
    require(my_socket_valid(my_fd));
  }

  int args[] = { DumpStateOrd::LCPContinue };
  if(g_restarter.dumpStateAllNodes(args, 1) != 0)
    return -1;
  
  if(error){
    char *tmp;
    char buf[1024];
    SocketInputStream in(my_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){
	  my_socket_close(my_fd);
	  return 0;
	}
      }
    } while(count++ < 30);
    
    my_socket_close(my_fd);
  }
  return 0;
}
コード例 #4
0
ファイル: testLcp.cpp プロジェクト: 4T-Shirt/mysql
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;
}
コード例 #5
0
ファイル: testMgm.cpp プロジェクト: 4T-Shirt/mysql
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;
}