Commit 6d267551 authored by stewart@willster.(none)'s avatar stewart@willster.(none)

Merge willster.(none):/home/stewart/Documents/MySQL/5.1/ndb

into  willster.(none):/home/stewart/Documents/MySQL/5.1/bug25567
parents 9a85d74e dbaab7f4
......@@ -676,6 +676,8 @@ class ha_ndbcluster: public handler
bool get_error_message(int error, String *buf);
ha_rows records();
ha_rows estimate_rows_upper_bound()
{ return HA_POS_ERROR; }
int info(uint);
void get_dynamic_partition_info(PARTITION_INFO *stat_info, uint part_id);
int extra(enum ha_extra_function operation);
......
......@@ -2197,7 +2197,7 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables, COND *conds,
s->key_dependent= 0;
if (tables->schema_table)
table->file->stats.records= 2;
table->quick_condition_rows= table->file->records();
table->quick_condition_rows= table->file->stats.records;
s->on_expr_ref= &tables->on_expr;
if (*s->on_expr_ref)
......
......@@ -544,6 +544,16 @@ extern "C" {
*/
const char *ndb_mgm_get_connectstring(NdbMgmHandle handle, char *buf, int buf_sz);
/**
* Sets the number of seconds to wait for connect(2) during ndb_mgm_connect
* Default is no timeout
*
* @param handle NdbMgmHandle
* @param seconds number of seconds
* @return non-zero on success
*/
int ndb_mgm_set_connect_timeout(NdbMgmHandle handle, unsigned int seconds);
/**
* Connects to a management server. Connectstring is set by
* ndb_mgm_set_connectstring().
......
......@@ -23,6 +23,7 @@ class SocketClient
{
NDB_SOCKET_TYPE m_sockfd;
struct sockaddr_in m_servaddr;
unsigned int m_connect_timeout_sec;
unsigned short m_port;
char *m_server_name;
SocketAuthenticator *m_auth;
......@@ -34,6 +35,9 @@ public:
m_port = port;
m_servaddr.sin_port = htons(m_port);
};
void set_connect_timeout(unsigned int s) {
m_connect_timeout_sec= s;
}
unsigned short get_port() { return m_port; };
char *get_server_name() { return m_server_name; };
int bind(const char* toaddress, unsigned short toport);
......
......@@ -79,9 +79,13 @@ Transporter::Transporter(TransporterRegistry &t_reg,
if (isServer)
m_socket_client= 0;
else
{
m_socket_client= new SocketClient(remoteHostName, s_port,
new SocketAuthSimple("ndbd",
"ndbd passwd"));
m_socket_client->set_connect_timeout((m_timeOutMillis+999)/1000);
}
DBUG_VOID_RETURN;
}
......
......@@ -26,6 +26,7 @@ SocketClient::SocketClient(const char *server_name, unsigned short port, SocketA
m_port= port;
m_server_name= server_name ? strdup(server_name) : 0;
m_sockfd= NDB_INVALID_SOCKET;
m_connect_timeout_sec= 0;
}
SocketClient::~SocketClient()
......@@ -104,6 +105,13 @@ SocketClient::bind(const char* bindaddress, unsigned short localport)
NDB_SOCKET_TYPE
SocketClient::connect(const char *toaddress, unsigned short toport)
{
fd_set rset, wset;
struct timeval tval;
int r;
bool use_timeout;
socklen_t len;
int flags;
if (m_sockfd == NDB_INVALID_SOCKET)
{
if (!init()) {
......@@ -128,13 +136,57 @@ SocketClient::connect(const char *toaddress, unsigned short toport)
return NDB_INVALID_SOCKET;
}
const int r = ::connect(m_sockfd, (struct sockaddr*) &m_servaddr, sizeof(m_servaddr));
if (r == -1) {
flags= fcntl(m_sockfd, F_GETFL, 0);
fcntl(m_sockfd, F_SETFL, flags | O_NONBLOCK);
r= ::connect(m_sockfd, (struct sockaddr*) &m_servaddr, sizeof(m_servaddr));
if (r == 0)
goto done; // connected immediately.
if (r < 0 && (errno != EINPROGRESS)) {
NDB_CLOSE_SOCKET(m_sockfd);
m_sockfd= NDB_INVALID_SOCKET;
return NDB_INVALID_SOCKET;
}
FD_ZERO(&rset);
FD_SET(m_sockfd, &rset);
wset= rset;
tval.tv_sec= m_connect_timeout_sec;
tval.tv_usec= 0;
use_timeout= m_connect_timeout_sec;
if ((r= select(m_sockfd+1, &rset, &wset, NULL,
use_timeout? &tval : NULL)) == 0)
{
NDB_CLOSE_SOCKET(m_sockfd);
m_sockfd= NDB_INVALID_SOCKET;
return NDB_INVALID_SOCKET;
}
if (FD_ISSET(m_sockfd, &rset) || FD_ISSET(m_sockfd, &wset))
{
len= sizeof(r);
if (getsockopt(m_sockfd, SOL_SOCKET, SO_ERROR, &r, &len) < 0)
{
// Solaris got an error... different than others
NDB_CLOSE_SOCKET(m_sockfd);
m_sockfd= NDB_INVALID_SOCKET;
return NDB_INVALID_SOCKET;
}
}
else
{
// select error, probably m_sockfd not set.
NDB_CLOSE_SOCKET(m_sockfd);
m_sockfd= NDB_INVALID_SOCKET;
return NDB_INVALID_SOCKET;
}
done:
fcntl(m_sockfd, F_SETFL, flags);
if (m_auth) {
if (!m_auth->client_authenticate(m_sockfd))
{
......
......@@ -93,6 +93,7 @@ struct ndb_mgm_handle {
char last_error_desc[NDB_MGM_MAX_ERR_DESC_SIZE];
int read_timeout;
int write_timeout;
unsigned int connect_timeout;
NDB_SOCKET_TYPE socket;
......@@ -165,6 +166,7 @@ ndb_mgm_create_handle()
h->socket = NDB_INVALID_SOCKET;
h->read_timeout = 50000;
h->write_timeout = 100;
h->connect_timeout = 0;
h->cfg_i = -1;
h->errstream = stdout;
h->m_name = 0;
......@@ -432,6 +434,16 @@ int ndb_mgm_is_connected(NdbMgmHandle handle)
return handle->connected;
}
extern "C"
int ndb_mgm_set_connect_timeout(NdbMgmHandle handle, unsigned int seconds)
{
if(!handle)
return -1;
handle->connect_timeout= seconds;
return 0;
}
/**
* Connect to a management server
*/
......@@ -462,6 +474,7 @@ ndb_mgm_connect(NdbMgmHandle handle, int no_retries,
Uint32 i;
int binderror = 0;
SocketClient s(0, 0);
s.set_connect_timeout(handle->connect_timeout);
if (!s.init())
{
fprintf(handle->errstream,
......
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