fixed error in test result

    added extra calls to retrieve connectstring used
    reengineered connect somewhat to make retries etc explicit
parent d365446f
......@@ -77,8 +77,10 @@ a b c
3 NULL NULL
select * from t1 use index (bc) where b IS NULL and c IS NULL order by a;
a b c
3 NULL NULL
select * from t1 use index (bc) where b IS NULL and c = 2 order by a;
a b c
2 NULL 2
select * from t1 use index (bc) where b < 4 order by a;
a b c
1 1 1
......
......@@ -375,6 +375,7 @@ extern "C" {
int ndb_mgm_get_configuration_nodeid(NdbMgmHandle handle);
int ndb_mgm_get_connected_port(NdbMgmHandle handle);
const char *ndb_mgm_get_connected_host(NdbMgmHandle handle);
const char *ndb_mgm_get_connectstring(NdbMgmHandle handle, char *buf, int buf_sz);
/**
* Destroy a management server handle
......
......@@ -72,6 +72,7 @@ public:
Uint32 get_mgmd_port() const;
const char *get_mgmd_host() const;
const char *get_connectstring(char *buf, int buf_sz) const;
Uint32 get_configuration_nodeid() const;
private:
......
......@@ -30,12 +30,14 @@ class Ndb_cluster_connection {
public:
Ndb_cluster_connection(const char * connect_string = 0);
~Ndb_cluster_connection();
int connect(int reconnect= 0);
int connect(int no_retries, int retry_delay_in_seconds, int verbose);
int start_connect_thread(int (*connect_callback)(void)= 0);
const char *get_connectstring(char *buf, int buf_sz) const;
int get_connected_port() const;
const char *get_connected_host() const;
private:
friend void* run_ndb_cluster_connection_connect_thread(void*);
void connect_thread();
char *m_connect_string;
TransporterFacade *m_facade;
ConfigRetriever *m_config_retriever;
NdbThread *m_connect_thread;
......
......@@ -90,6 +90,11 @@ const char *ConfigRetriever::get_mgmd_host() const
return ndb_mgm_get_connected_host(m_handle);
}
const char *ConfigRetriever::get_connectstring(char *buf, int buf_sz) const
{
return ndb_mgm_get_connectstring(m_handle, buf, buf_sz);
}
//****************************************************************************
//****************************************************************************
......
......@@ -84,7 +84,6 @@ typedef Parser<ParserDummy> Parser_t;
#define NDB_MGM_MAX_ERR_DESC_SIZE 256
struct ndb_mgm_handle {
char * connectstring;
int cfg_i;
int connected;
......@@ -1677,6 +1676,12 @@ const char *ndb_mgm_get_connected_host(NdbMgmHandle handle)
return handle->cfg.ids[handle->cfg_i].name.c_str();
}
extern "C"
const char *ndb_mgm_get_connectstring(NdbMgmHandle handle, char *buf, int buf_sz)
{
return handle->cfg.makeConnectString(buf,buf_sz);
}
extern "C"
int
ndb_mgm_alloc_nodeid(NdbMgmHandle handle, unsigned int version, int nodetype)
......
......@@ -516,6 +516,12 @@ CommandInterpreter::execute_impl(const char *_line)
executeConnect(allAfterFirstToken);
DBUG_RETURN(true);
}
else if((strcasecmp(firstToken, "QUIT") == 0 ||
strcasecmp(firstToken, "EXIT") == 0 ||
strcasecmp(firstToken, "BYE") == 0) &&
allAfterFirstToken == NULL){
DBUG_RETURN(false);
}
if (!connect())
DBUG_RETURN(true);
......@@ -571,12 +577,6 @@ CommandInterpreter::execute_impl(const char *_line)
}
else if (strcasecmp(firstToken, "ALL") == 0) {
analyseAfterFirstToken(-1, allAfterFirstToken);
}
else if((strcasecmp(firstToken, "QUIT") == 0 ||
strcasecmp(firstToken, "EXIT") == 0 ||
strcasecmp(firstToken, "BYE") == 0) &&
allAfterFirstToken == NULL){
DBUG_RETURN(false);
} else {
/**
* First token should be a digit, node ID
......
......@@ -58,7 +58,7 @@ Ndb::Ndb( const char* aDataBase , const char* aSchema) {
theNoOfNdbObjects++;
if (global_ndb_cluster_connection == 0) {
global_ndb_cluster_connection= new Ndb_cluster_connection(ndbConnectString);
global_ndb_cluster_connection->connect();
global_ndb_cluster_connection->connect(12,5,1);
}
setup(global_ndb_cluster_connection, aDataBase, aSchema);
DBUG_VOID_RETURN;
......
......@@ -40,10 +40,7 @@ Ndb_cluster_connection::Ndb_cluster_connection(const char *connect_string)
DBUG_ENTER("Ndb_cluster_connection");
DBUG_PRINT("enter",("Ndb_cluster_connection this=0x%x", this));
m_facade= TransporterFacade::theFacadeInstance= new TransporterFacade();
if (connect_string)
m_connect_string= my_strdup(connect_string,MYF(MY_WME));
else
m_connect_string= 0;
m_config_retriever= 0;
m_connect_thread= 0;
m_connect_callback= 0;
......@@ -58,9 +55,39 @@ Ndb_cluster_connection::Ndb_cluster_connection(const char *connect_string)
ndb_print_state_mutex= NdbMutex_Create();
}
#endif
m_config_retriever=
new ConfigRetriever(connect_string, NDB_VERSION, NODE_TYPE_API);
if (m_config_retriever->hasError())
{
printf("Could not connect initialize handle to management server: %s",
m_config_retriever->getErrorString());
delete m_config_retriever;
m_config_retriever= 0;
}
DBUG_VOID_RETURN;
}
int Ndb_cluster_connection::get_connected_port() const
{
if (m_config_retriever)
return m_config_retriever->get_mgmd_port();
return -1;
}
const char *Ndb_cluster_connection::get_connected_host() const
{
if (m_config_retriever)
return m_config_retriever->get_mgmd_host();
return 0;
}
const char *Ndb_cluster_connection::get_connectstring(char *buf, int buf_sz) const
{
if (m_config_retriever)
return m_config_retriever->get_connectstring(buf,buf_sz);
return 0;
}
extern "C" pthread_handler_decl(run_ndb_cluster_connection_connect_thread, me)
{
my_thread_init();
......@@ -77,7 +104,7 @@ void Ndb_cluster_connection::connect_thread()
int r;
do {
NdbSleep_SecSleep(1);
if ((r = connect(1)) == 0)
if ((r = connect(0,0,0)) == 0)
break;
if (r == -1) {
printf("Ndb_cluster_connection::connect_thread error\n");
......@@ -98,7 +125,7 @@ int Ndb_cluster_connection::start_connect_thread(int (*connect_callback)(void))
int r;
DBUG_ENTER("Ndb_cluster_connection::start_connect_thread");
m_connect_callback= connect_callback;
if ((r = connect(1)) == 1)
if ((r = connect(0,0,0)) == 1)
{
DBUG_PRINT("info",("starting thread"));
m_connect_thread=
......@@ -117,36 +144,15 @@ int Ndb_cluster_connection::start_connect_thread(int (*connect_callback)(void))
DBUG_RETURN(0);
}
int Ndb_cluster_connection::connect(int reconnect)
int Ndb_cluster_connection::connect(int no_retries, int retry_delay_in_seconds, int verbose)
{
DBUG_ENTER("Ndb_cluster_connection::connect");
const char* error = 0;
do {
if (m_config_retriever == 0)
{
m_config_retriever=
new ConfigRetriever(m_connect_string, NDB_VERSION, NODE_TYPE_API);
if (m_config_retriever->hasError())
{
printf("Could not connect initialize handle to management server: %s",
m_config_retriever->getErrorString());
DBUG_RETURN(-1);
}
}
else
if (reconnect == 0)
DBUG_RETURN(0);
if (reconnect)
{
int r= m_config_retriever->do_connect(0,0,0);
if (r == 1)
DBUG_RETURN(1); // mgmt server not up yet
if (r == -1)
break;
}
else
if(m_config_retriever->do_connect(12,5,1) == -1)
break;
DBUG_RETURN(-1);
if (m_config_retriever->do_connect(no_retries,retry_delay_in_seconds,verbose))
DBUG_RETURN(1); // mgmt server not up yet
Uint32 nodeId = m_config_retriever->allocNodeId(4/*retries*/,3/*delay*/);
if(nodeId == 0)
......@@ -189,7 +195,6 @@ Ndb_cluster_connection::~Ndb_cluster_connection()
abort();
TransporterFacade::theFacadeInstance= 0;
}
my_free(m_connect_string,MYF(MY_ALLOW_ZERO_PTR));
if (m_config_retriever)
delete m_config_retriever;
DBUG_VOID_RETURN;
......
......@@ -228,10 +228,11 @@ int main(int argc, char** argv){
_tabname = argv[0];
ndb_cluster_connection = new Ndb_cluster_connection(opt_connect_str);
if (ndb_cluster_connection->connect(12,5,1))
fatal("unable to connect");
ndb = new Ndb(ndb_cluster_connection, _dbname);
if (ndb->init() != 0)
fatal("init");
ndb_cluster_connection->connect();
if (ndb->waitUntilReady(30) < 0)
fatal("waitUntilReady");
dic = ndb->getDictionary();
......
......@@ -4231,7 +4231,7 @@ bool ndbcluster_init()
new Ndb_cluster_connection(ndbcluster_connectstring)) == 0)
{
DBUG_PRINT("error",("Ndb_cluster_connection(%s)",ndbcluster_connectstring));
DBUG_RETURN(TRUE);
goto ndbcluster_init_error;
}
// Create a Ndb object to open the connection to NDB
......@@ -4240,25 +4240,33 @@ bool ndbcluster_init()
if (g_ndb->init() != 0)
{
ERR_PRINT (g_ndb->getNdbError());
DBUG_RETURN(TRUE);
goto ndbcluster_init_error;
}
if ((res= g_ndb_cluster_connection->connect(1)) == 0)
if ((res= g_ndb_cluster_connection->connect(0,0,0)) == 0)
{
DBUG_PRINT("info",("NDBCLUSTER storage engine at %s on port %d",
g_ndb_cluster_connection->get_connected_host(),
g_ndb_cluster_connection->get_connected_port()));
g_ndb->waitUntilReady(10);
}
else if(res == 1)
{
if (g_ndb_cluster_connection->start_connect_thread()) {
DBUG_PRINT("error", ("g_ndb_cluster_connection->start_connect_thread()"));
DBUG_RETURN(TRUE);
goto ndbcluster_init_error;
}
{
char buf[1024];
DBUG_PRINT("info",("NDBCLUSTER storage engine not started, will connect using %s",
g_ndb_cluster_connection->get_connectstring(buf,sizeof(buf))));
}
}
else
{
DBUG_ASSERT(res == -1);
DBUG_PRINT("error", ("permanent error"));
DBUG_RETURN(TRUE);
goto ndbcluster_init_error;
}
(void) hash_init(&ndbcluster_open_tables,system_charset_info,32,0,0,
......@@ -4268,9 +4276,12 @@ bool ndbcluster_init()
ndbcluster_inited= 1;
#ifdef USE_DISCOVER_ON_STARTUP
if (ndb_discover_tables() != 0)
DBUG_RETURN(TRUE);
goto ndbcluster_init_error;
#endif
DBUG_RETURN(FALSE);
ndbcluster_init_error:
ndbcluster_end();
DBUG_RETURN(TRUE);
}
......
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