Skip to content

Commit 3d2d9fd

Browse files
committed
wl#9819 Version 2. Patch #7: mysqld
1 parent 5c1ca07 commit 3d2d9fd

File tree

1 file changed

+59
-17
lines changed

1 file changed

+59
-17
lines changed

sql/ha_ndbcluster_connection.cc

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -138,25 +138,30 @@ bool parse_pool_nodeids(const char* opt_str,
138138
/* Get the port number for processinfo.
139139
NDB is being initialized before server networking, so mysqld_port
140140
may not yet have been set, and we are forced to duplicate some
141-
code from mysqld.cc here to calculate the port number.
141+
code from set_ports() in mysqld.cc here to calculate the port number.
142142
*/
143143
static int
144144
get_processinfo_port()
145145
{
146-
int port = mysqld_port;
147-
if(port == 0)
146+
int port = 0;
147+
148+
if(! opt_disable_networking)
148149
{
149-
const char * env = getenv("MYSQL_TCP_PORT");
150-
if(MYSQL_PORT_DEFAULT == 0)
150+
port = mysqld_port;
151+
if(port == 0)
151152
{
152-
struct servent *serv_ptr = getservbyname("mysql", "tcp");
153-
if (serv_ptr)
154-
port = ntohs((u_short) serv_ptr->s_port); /* purecov: inspected */
153+
const char * env = getenv("MYSQL_TCP_PORT");
154+
if(MYSQL_PORT_DEFAULT == 0)
155+
{
156+
struct servent *serv_ptr = getservbyname("mysql", "tcp");
157+
if (serv_ptr)
158+
port = ntohs((u_short) serv_ptr->s_port); /* purecov: inspected */
159+
}
160+
else if(env)
161+
port = atoi(env);
162+
else
163+
port = MYSQL_PORT;
155164
}
156-
else if(env)
157-
port = atoi(env);
158-
else
159-
port = MYSQL_PORT;
160165
}
161166
return port;
162167
}
@@ -174,6 +179,30 @@ get_processinfo_host()
174179
return host;
175180
}
176181

182+
/* Like get_processinfo_port(), this code must be duplicated from
183+
set_ports() in mysqld.cc.
184+
*/
185+
#ifdef _WIN32
186+
#define URI_PATH_SOCKET MYSQL_NAMEDPIPE;
187+
#else
188+
#define URI_PATH_SOCKET MYSQL_UNIX_ADDR;
189+
#endif
190+
191+
static const char *
192+
get_processinfo_path()
193+
{
194+
const char * uri_path = mysqld_unix_port;
195+
char * env;
196+
if (!uri_path)
197+
{
198+
if ((env = getenv("MYSQL_UNIX_PORT")))
199+
uri_path= env; /* purecov: inspected */
200+
else
201+
uri_path= (char*) URI_PATH_SOCKET;
202+
}
203+
return uri_path;
204+
}
205+
177206
/*
178207
Global flag in ndbapi to specify if api should wait to connect
179208
until dict cache is clean.
@@ -199,13 +228,22 @@ ndbcluster_connect(int (*connect_callback)(void),
199228
#else
200229
const char mysqld_name[]= "libmysqld";
201230
#endif
202-
const int processinfo_port = get_processinfo_port();
203-
const char * processinfo_host = get_processinfo_host();
204231
int res;
205232
DBUG_ENTER("ndbcluster_connect");
206233
DBUG_PRINT("enter", ("connect_string: %s, force_nodeid: %d",
207234
connect_string, force_nodeid));
208235

236+
/* For Service URI in ndbinfo */
237+
const int processinfo_port = get_processinfo_port();
238+
const char * processinfo_host = get_processinfo_host();
239+
const char * processinfo_path = processinfo_port ? "" : get_processinfo_path();
240+
char server_id_string[64];
241+
if(server_id > 0)
242+
my_snprintf(server_id_string, sizeof(server_id_string), "?server-id=%lu",
243+
server_id);
244+
else
245+
server_id_string[0] = '\0';
246+
209247
// Parse the --ndb-cluster-connection-pool-nodeids=nodeid[,nodeidN]
210248
// comma separated list of nodeids to use for the pool
211249
Vector<uint> nodeids;
@@ -241,9 +279,10 @@ ndbcluster_connect(int (*connect_callback)(void),
241279
my_snprintf(buf, sizeof(buf), "%s --server-id=%lu",
242280
mysqld_name, server_id);
243281
g_ndb_cluster_connection->set_name(buf);
244-
g_ndb_cluster_connection->set_application_address(processinfo_host, processinfo_port);
282+
my_snprintf(buf, sizeof(buf), "%s%s", processinfo_path, server_id_string);
283+
g_ndb_cluster_connection->set_service_uri("mysql", processinfo_host,
284+
processinfo_port, buf);
245285
}
246-
247286
g_ndb_cluster_connection->set_optimized_node_selection(optimized_node_select);
248287
g_ndb_cluster_connection->set_recv_thread_activation_threshold(
249288
recv_thread_activation_threshold);
@@ -315,7 +354,10 @@ ndbcluster_connect(int (*connect_callback)(void),
315354
my_snprintf(buf, sizeof(buf), "%s --server-id=%lu (connection %u)",
316355
mysqld_name, server_id, i+1);
317356
g_pool[i]->set_name(buf);
318-
g_pool[i]->set_application_address(processinfo_host, processinfo_port);
357+
const char * uri_sep = server_id ? ";" : "?";
358+
my_snprintf(buf, sizeof(buf), "%s%s%sconnection=%u",
359+
processinfo_path, server_id_string, uri_sep, i+1);
360+
g_pool[i]->set_service_uri("mysql", processinfo_host, processinfo_port, buf);
319361
}
320362
g_pool[i]->set_optimized_node_selection(optimized_node_select);
321363
g_pool[i]->set_recv_thread_activation_threshold(recv_thread_activation_threshold);

0 commit comments

Comments
 (0)