Skip to content

Commit 35b5ef2

Browse files
author
zhuchao-hit
committed
chassis_plugin_config in proxy-plugin.c
1 parent 722006d commit 35b5ef2

3 files changed

Lines changed: 47 additions & 47 deletions

File tree

plugins/proxy/proxy-plugin.c

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,45 @@ SQL_LOG_TYPE sql_log_type = OFF;
193193

194194
char* charset[64] = {NULL, "big5", NULL, NULL, NULL, NULL, NULL, NULL, "latin1", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "gb2312", NULL, NULL, NULL, "gbk", NULL, NULL, NULL, NULL, "utf8", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "binary"};
195195

196+
struct chassis_plugin_config {
197+
gchar *address; /**< listening address of the proxy */
198+
199+
gchar **backend_addresses; /**< read-write backends */
200+
gchar **read_only_backend_addresses; /**< read-only backends */
201+
202+
gint fix_bug_25371; /**< suppress the second ERR packet of bug #25371 */
203+
204+
gint profiling; /**< skips the execution of the read_query() function */
205+
206+
gchar *lua_script; /**< script to load at the start the connection */
207+
208+
gint pool_change_user; /**< don't reset the connection, when a connection is taken from the pool
209+
- this safes a round-trip, but we also don't cleanup the connection
210+
- another name could be "fast-pool-connect", but that's too friendly
211+
*/
212+
213+
gint start_proxy;
214+
215+
gchar **client_ips;
216+
GHashTable *ip_table;
217+
218+
gchar **lvs_ips;
219+
GHashTable *lvs_table;
220+
221+
gchar **tables;
222+
GHashTable *dt_table;
223+
224+
gchar **pwds;
225+
GHashTable *pwd_table;
226+
227+
network_mysqld_con *listen_con;
228+
229+
FILE *sql_log;
230+
gchar *sql_log_type;
231+
232+
gchar *charset;
233+
};
234+
196235
chassis_plugin_config *config = NULL;
197236

198237
guint get_table_index(GPtrArray* tokens, gint* d, gint* t) {
@@ -1374,16 +1413,16 @@ NETWORK_MYSQLD_PLUGIN_PROTO(proxy_read_query) {
13741413
if (!con->is_in_transaction && !con->is_not_autocommit && g_hash_table_size(con->locks) == 0) {
13751414
if (type == COM_QUERY) {
13761415
backend_ndx = rw_split(tokens, con);
1377-
send_sock = network_connection_pool_lua_swap(con, backend_ndx, config);
1416+
send_sock = network_connection_pool_lua_swap(con, backend_ndx, config->pwd_table);
13781417
} else if (type == COM_INIT_DB || type == COM_SET_OPTION) {
13791418
backend_ndx = wrr_ro(con);
1380-
send_sock = network_connection_pool_lua_swap(con, backend_ndx, config);
1419+
send_sock = network_connection_pool_lua_swap(con, backend_ndx, config->pwd_table);
13811420
}
13821421
}
13831422

13841423
if (send_sock == NULL) {
13851424
backend_ndx = idle_rw(con);
1386-
send_sock = network_connection_pool_lua_swap(con, backend_ndx, config);
1425+
send_sock = network_connection_pool_lua_swap(con, backend_ndx, config->pwd_table);
13871426
}
13881427
con->server = send_sock;
13891428
}

src/network-conn-pool-lua.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ int network_connection_pool_lua_add_connection(network_mysqld_con *con) {
135135
return 0;
136136
}
137137

138-
network_socket *self_connect(network_mysqld_con *con, network_backend_t *backend, chassis_plugin_config *config) {
138+
network_socket *self_connect(network_mysqld_con *con, network_backend_t *backend, GHashTable *pwd_table) {
139139
//1. connect DB
140140
network_socket *sock = network_socket_new();
141141
network_address_copy(sock->dst, backend->addr);
@@ -188,7 +188,7 @@ network_socket *self_connect(network_mysqld_con *con, network_backend_t *backend
188188

189189
//3. 生成response
190190
GString *response = g_string_sized_new(20);
191-
GString *hashed_password = g_hash_table_lookup(config->pwd_table, con->client->response->username->str);
191+
GString *hashed_password = g_hash_table_lookup(pwd_table, con->client->response->username->str);
192192
if (hashed_password) {
193193
network_mysqld_proto_password_scramble(response, S(challenge->challenge), S(hashed_password));
194194
} else {
@@ -280,7 +280,7 @@ network_socket *self_connect(network_mysqld_con *con, network_backend_t *backend
280280
* @return NULL if swapping failed
281281
* the new backend on success
282282
*/
283-
network_socket *network_connection_pool_lua_swap(network_mysqld_con *con, int backend_ndx, chassis_plugin_config *config) {
283+
network_socket *network_connection_pool_lua_swap(network_mysqld_con *con, int backend_ndx, GHashTable *pwd_table) {
284284
network_backend_t *backend = NULL;
285285
network_socket *send_sock;
286286
network_mysqld_con_lua_t *st = con->plugin_con_state;
@@ -309,7 +309,7 @@ network_socket *network_connection_pool_lua_swap(network_mysqld_con *con, int ba
309309
/**
310310
* no connections in the pool
311311
*/
312-
if (NULL == (send_sock = self_connect(con, backend, config))) {
312+
if (NULL == (send_sock = self_connect(con, backend, pwd_table))) {
313313
st->backend_ndx = -1;
314314
return NULL;
315315
}

src/network-conn-pool-lua.h

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,48 +27,9 @@
2727

2828
#include "network-exports.h"
2929

30-
struct chassis_plugin_config {
31-
gchar *address; /**< listening address of the proxy */
32-
33-
gchar **backend_addresses; /**< read-write backends */
34-
gchar **read_only_backend_addresses; /**< read-only backends */
35-
36-
gint fix_bug_25371; /**< suppress the second ERR packet of bug #25371 */
37-
38-
gint profiling; /**< skips the execution of the read_query() function */
39-
40-
gchar *lua_script; /**< script to load at the start the connection */
41-
42-
gint pool_change_user; /**< don't reset the connection, when a connection is taken from the pool
43-
- this safes a round-trip, but we also don't cleanup the connection
44-
- another name could be "fast-pool-connect", but that's too friendly
45-
*/
46-
47-
gint start_proxy;
48-
49-
gchar **client_ips;
50-
GHashTable *ip_table;
51-
52-
gchar **lvs_ips;
53-
GHashTable *lvs_table;
54-
55-
gchar **tables;
56-
GHashTable *dt_table;
57-
58-
gchar **pwds;
59-
GHashTable *pwd_table;
60-
61-
network_mysqld_con *listen_con;
62-
63-
FILE *sql_log;
64-
gchar *sql_log_type;
65-
66-
gchar *charset;
67-
};
68-
6930
NETWORK_API int network_connection_pool_getmetatable(lua_State *L);
7031

7132
NETWORK_API int network_connection_pool_lua_add_connection(network_mysqld_con *con);
72-
NETWORK_API network_socket *network_connection_pool_lua_swap(network_mysqld_con *con, int backend_ndx, chassis_plugin_config *config);
33+
NETWORK_API network_socket *network_connection_pool_lua_swap(network_mysqld_con *con, int backend_ndx, GHashTable *pwd_table);
7334

7435
#endif

0 commit comments

Comments
 (0)