Skip to content

Commit ed5dce3

Browse files
committed
wl#9819 patch #12: mysqld uses set_application_address()
1 parent ee331ba commit ed5dce3

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

sql/ha_ndbcluster_connection.cc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include <util/Vector.hpp>
2727
#include <util/BaseString.hpp>
2828

29+
extern char *my_bind_addr_str;
30+
2931
Ndb* g_ndb= NULL;
3032
Ndb_cluster_connection* g_ndb_cluster_connection= NULL;
3133
static Ndb_cluster_connection **g_pool= NULL;
@@ -133,6 +135,44 @@ bool parse_pool_nodeids(const char* opt_str,
133135
return true;
134136
}
135137

138+
/* Get the port number for processinfo.
139+
NDB is being initialized before server networking, so mysqld_port
140+
may not yet have been set, and we are forced to duplicate some
141+
code from mysqld.cc here to calculate the port number.
142+
*/
143+
static int
144+
get_processinfo_port()
145+
{
146+
int port = mysqld_port;
147+
if(port == 0)
148+
{
149+
const char * env = getenv("MYSQL_TCP_PORT");
150+
if(MYSQL_PORT_DEFAULT == 0)
151+
{
152+
struct servent *serv_ptr = getservbyname("mysql", "tcp");
153+
if (serv_ptr)
154+
port = ntohs((u_short) serv_ptr->s_port); /* purecov: inspected */
155+
}
156+
else if(env)
157+
port = atoi(env);
158+
else
159+
port = MYSQL_PORT;
160+
}
161+
return port;
162+
}
163+
164+
static const char *
165+
get_processinfo_host()
166+
{
167+
const char * host = my_bind_addr_str;
168+
if(! ( strcmp(host, "*") && // If bind_address matches any of
169+
strcmp(host, "0.0.0.0") && // these strings, let ProcessInfo
170+
strcmp(host, "::"))) // use the NDB transporter address.
171+
{
172+
host = 0;
173+
}
174+
return host;
175+
}
136176

137177
/*
138178
Global flag in ndbapi to specify if api should wait to connect
@@ -159,6 +199,8 @@ ndbcluster_connect(int (*connect_callback)(void),
159199
#else
160200
const char mysqld_name[]= "libmysqld";
161201
#endif
202+
const int processinfo_port = get_processinfo_port();
203+
const char * processinfo_host = get_processinfo_host();
162204
int res;
163205
DBUG_ENTER("ndbcluster_connect");
164206
DBUG_PRINT("enter", ("connect_string: %s, force_nodeid: %d",
@@ -199,7 +241,9 @@ ndbcluster_connect(int (*connect_callback)(void),
199241
my_snprintf(buf, sizeof(buf), "%s --server-id=%lu",
200242
mysqld_name, server_id);
201243
g_ndb_cluster_connection->set_name(buf);
244+
g_ndb_cluster_connection->set_application_address(processinfo_host, processinfo_port);
202245
}
246+
203247
g_ndb_cluster_connection->set_optimized_node_selection(optimized_node_select);
204248
g_ndb_cluster_connection->set_recv_thread_activation_threshold(
205249
recv_thread_activation_threshold);
@@ -271,6 +315,7 @@ ndbcluster_connect(int (*connect_callback)(void),
271315
my_snprintf(buf, sizeof(buf), "%s --server-id=%lu (connection %u)",
272316
mysqld_name, server_id, i+1);
273317
g_pool[i]->set_name(buf);
318+
g_pool[i]->set_application_address(processinfo_host, processinfo_port);
274319
}
275320
g_pool[i]->set_optimized_node_selection(optimized_node_select);
276321
g_pool[i]->set_recv_thread_activation_threshold(recv_thread_activation_threshold);

0 commit comments

Comments
 (0)