26
26
#include < util/Vector.hpp>
27
27
#include < util/BaseString.hpp>
28
28
29
+ extern char *my_bind_addr_str;
30
+
29
31
Ndb* g_ndb= NULL ;
30
32
Ndb_cluster_connection* g_ndb_cluster_connection= NULL ;
31
33
static Ndb_cluster_connection **g_pool= NULL ;
@@ -133,6 +135,44 @@ bool parse_pool_nodeids(const char* opt_str,
133
135
return true ;
134
136
}
135
137
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
+ }
136
176
137
177
/*
138
178
Global flag in ndbapi to specify if api should wait to connect
@@ -159,6 +199,8 @@ ndbcluster_connect(int (*connect_callback)(void),
159
199
#else
160
200
const char mysqld_name[]= " libmysqld" ;
161
201
#endif
202
+ const int processinfo_port = get_processinfo_port ();
203
+ const char * processinfo_host = get_processinfo_host ();
162
204
int res;
163
205
DBUG_ENTER (" ndbcluster_connect" );
164
206
DBUG_PRINT (" enter" , (" connect_string: %s, force_nodeid: %d" ,
@@ -199,7 +241,9 @@ ndbcluster_connect(int (*connect_callback)(void),
199
241
my_snprintf (buf, sizeof (buf), " %s --server-id=%lu" ,
200
242
mysqld_name, server_id);
201
243
g_ndb_cluster_connection->set_name (buf);
244
+ g_ndb_cluster_connection->set_application_address (processinfo_host, processinfo_port);
202
245
}
246
+
203
247
g_ndb_cluster_connection->set_optimized_node_selection (optimized_node_select);
204
248
g_ndb_cluster_connection->set_recv_thread_activation_threshold (
205
249
recv_thread_activation_threshold);
@@ -271,6 +315,7 @@ ndbcluster_connect(int (*connect_callback)(void),
271
315
my_snprintf (buf, sizeof (buf), " %s --server-id=%lu (connection %u)" ,
272
316
mysqld_name, server_id, i+1 );
273
317
g_pool[i]->set_name (buf);
318
+ g_pool[i]->set_application_address (processinfo_host, processinfo_port);
274
319
}
275
320
g_pool[i]->set_optimized_node_selection (optimized_node_select);
276
321
g_pool[i]->set_recv_thread_activation_threshold (recv_thread_activation_threshold);
0 commit comments