Merge lp:~jan-kneschke/mysql-proxy/threaded-io into lp:mysql-proxy

Proposed by Jan Kneschke
Status: Merged
Merged at revision: 662
Proposed branch: lp:~jan-kneschke/mysql-proxy/threaded-io
Merge into: lp:mysql-proxy
Diff against target: None lines
To merge this branch: bzr merge lp:~jan-kneschke/mysql-proxy/threaded-io
Reviewer Review Type Date Requested Status
Jan Kneschke (community) Approve
Review via email: mp+6773@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Jan Kneschke (jan-kneschke) wrote :

merge the initial threaded-io code into trunk for the 0.8 work

Revision history for this message
Jan Kneschke (jan-kneschke) wrote :

* rebased to the 0.7.1 changes
* make check passes

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Makefile.am'
--- src/Makefile.am 2009-05-12 19:20:06 +0000
+++ src/Makefile.am 2009-05-25 08:57:34 +0000
@@ -67,14 +67,15 @@
67 chassis-plugin.c \67 chassis-plugin.c \
68 chassis-log.c \68 chassis-log.c \
69 chassis-mainloop.c \69 chassis-mainloop.c \
70 chassis-event-thread.c \
70 chassis-keyfile.c \71 chassis-keyfile.c \
71 chassis-path.c \72 chassis-path.c \
72 chassis-stats.c73 chassis-stats.c
7374
7475
75libmysql_chassis_la_LDFLAGS = -export-dynamic -no-undefined -dynamic76libmysql_chassis_la_LDFLAGS = -export-dynamic -no-undefined -dynamic
76libmysql_chassis_la_CPPFLAGS = $(MYSQL_CFLAGS) $(EVENT_CFLAGS) $(GLIB_CFLAGS) $(LUA_CFLAGS) $(GMODULE_CFLAGS)77libmysql_chassis_la_CPPFLAGS = $(MYSQL_CFLAGS) $(EVENT_CFLAGS) $(GLIB_CFLAGS) $(LUA_CFLAGS) $(GMODULE_CFLAGS) $(GTHREAD_CFLAGS)
77libmysql_chassis_la_LIBADD = $(EVENT_LIBS) $(GLIB_LIBS) $(LUA_LIBS) $(GMODULE_LIBS)78libmysql_chassis_la_LIBADD = $(EVENT_LIBS) $(GLIB_LIBS) $(LUA_LIBS) $(GMODULE_LIBS) $(GTHREAD_LIBS)
7879
7980
80noinst_HEADERS=\81noinst_HEADERS=\
@@ -96,6 +97,7 @@
96 chassis-keyfile.h \97 chassis-keyfile.h \
97 chassis-mainloop.h \98 chassis-mainloop.h \
98 chassis-path.h \99 chassis-path.h \
100 chassis-event-thread.h \
99 glib-ext.h \101 glib-ext.h \
100 lua-load-factory.h \102 lua-load-factory.h \
101 lua-scope.h \103 lua-scope.h \
102104
=== added file 'src/chassis-event-thread.c'
--- src/chassis-event-thread.c 1970-01-01 00:00:00 +0000
+++ src/chassis-event-thread.c 2009-05-25 08:57:34 +0000
@@ -0,0 +1,287 @@
1/* $%BEGINLICENSE%$
2 Copyright (C) 2007-2008 MySQL AB, 2008 Sun Microsystems, Inc
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
17 $%ENDLICENSE%$ */
18
19#include <glib.h>
20#include <errno.h>
21
22#ifdef HAVE_CONFIG_H
23#include "config.h"
24#endif
25
26#ifdef HAVE_UNISTD_H
27#include <unistd.h> /* for write() */
28#endif
29
30#include "chassis-event-thread.h"
31
32#define C(x) x, sizeof(x) - 1
33
34chassis_event_op_t *chassis_event_op_new() {
35 chassis_event_op_t *e;
36
37 e = g_new0(chassis_event_op_t, 1);
38
39 return e;
40}
41
42void chassis_event_op_free(chassis_event_op_t *e) {
43 if (!e) return;
44
45 g_free(e);
46}
47
48/**
49 * execute a event-op on a event-base
50 *
51 * @see: chassis_event_add_local(), chassis_threaded_event_op()
52 */
53void chassis_event_op_apply(chassis_event_op_t *op, struct event_base *event_base) {
54 switch (op->type) {
55 case CHASSIS_EVENT_OP_ADD:
56 event_base_set(event_base, op->ev);
57 event_add(op->ev, NULL);
58 break;
59 case CHASSIS_EVENT_OP_UNSET:
60 g_assert_not_reached();
61 break;
62 }
63}
64
65/**
66 * add a event asynchronously
67 *
68 * the event is added to the global event-queue and a fd-notification is sent allowing any
69 * of the event-threads to handle it
70 *
71 * @see network_mysqld_con_handle()
72 */
73void chassis_event_add(chassis *chas, struct event *ev) {
74 chassis_event_op_t *op = chassis_event_op_new();
75
76 op->type = CHASSIS_EVENT_OP_ADD;
77 op->ev = ev;
78 g_async_queue_push(chas->threads->event_queue, op);
79
80 write(chas->threads->event_notify_fds[1], C(".")); /* ping the event handler */
81}
82
83GPrivate *tls_event_base_key = NULL;
84
85/**
86 * add a event to the current thread
87 *
88 * needs event-base stored in the thread local storage
89 *
90 * @see network_connection_pool_lua_add_connection()
91 */
92void chassis_event_add_local(chassis G_GNUC_UNUSED *chas, struct event *ev) {
93 struct event_base *event_base = ev->ev_base;
94 chassis_event_op_t *op;
95
96 if (!event_base) event_base = g_private_get(tls_event_base_key);
97
98 g_assert(event_base); /* the thread-local event-base has to be initialized */
99
100 op = chassis_event_op_new();
101
102 op->type = CHASSIS_EVENT_OP_ADD;
103 op->ev = ev;
104
105 chassis_event_op_apply(op, event_base);
106
107 chassis_event_op_free(op);
108}
109
110/**
111 * handled events sent through the global event-queue
112 *
113 * each event-thread has its own listener on the event-queue and
114 * calls chassis_event_handle() with its own event-base
115 *
116 * @see chassis_event_add()
117 */
118void chassis_event_handle(int G_GNUC_UNUSED event_fd, short G_GNUC_UNUSED events, void *user_data) {
119 chassis_event_thread_t *event_thread = user_data;
120 struct event_base *event_base = event_thread->event_base;
121 chassis *chas = event_thread->chas;
122 chassis_event_op_t *op;
123 char ping[1024];
124
125 /* flush the pipe */
126 while (read(event_thread->notify_fd, ping, sizeof(ping)) > 0);
127
128 while ((op = g_async_queue_try_pop(chas->threads->event_queue))) {
129 chassis_event_op_apply(op, event_base);
130
131 chassis_event_op_free(op);
132 }
133}
134
135chassis_event_thread_t *chassis_event_thread_new() {
136 chassis_event_thread_t *event_thread;
137
138 event_thread = g_new0(chassis_event_thread_t, 1);
139
140 return event_thread;
141}
142
143void chassis_event_thread_free(chassis_event_thread_t *event_thread) {
144 gboolean is_thread = (event_thread->thr != NULL);
145
146 if (!event_thread) return;
147
148 if (event_thread->thr) g_thread_join(event_thread->thr);
149
150 if (event_thread->notify_fd != -1) {
151 event_del(&(event_thread->notify_fd_event));
152 close(event_thread->notify_fd);
153 }
154
155 /* we don't want to free the global event-base */
156 if (is_thread && event_thread->event_base) event_base_free(event_thread->event_base);
157
158 g_free(event_thread);
159}
160
161/**
162 * set the event-based for the current event-thread
163 *
164 * @see chassis_event_add_local()
165 */
166void chassis_event_thread_set_event_base(chassis_event_thread_t G_GNUC_UNUSED *e, struct event_base *event_base) {
167 tls_event_base_key = g_private_new(NULL);
168
169 g_private_set(tls_event_base_key, event_base);
170}
171
172chassis_event_threads_t *chassis_event_threads_new() {
173 chassis_event_threads_t *threads;
174
175 threads = g_new0(chassis_event_threads_t, 1);
176
177 /* create the ping-fds
178 *
179 * the event-thread write a byte to the ping-pipe to trigger a fd-event when
180 * something is available in the event-async-queues
181 */
182 if (0 != pipe(threads->event_notify_fds)) {
183 g_error("%s: pipe() failed: %s (%d)",
184 G_STRLOC,
185 g_strerror(errno),
186 errno);
187 }
188
189 threads->event_threads = g_ptr_array_new();
190 threads->event_queue = g_async_queue_new();
191
192 return threads;
193}
194
195void chassis_event_threads_free(chassis_event_threads_t *threads) {
196 guint i;
197
198 if (!threads) return;
199
200 /* all threads are running, now wait until they are down again */
201 for (i = 0; i < threads->event_threads->len; i++) {
202 chassis_event_thread_t *event_thread = threads->event_threads->pdata[i];
203
204 chassis_event_thread_free(event_thread);
205 }
206
207 g_ptr_array_free(threads->event_threads, TRUE);
208 g_async_queue_unref(threads->event_queue);
209
210 g_free(threads);
211}
212
213void chassis_event_threads_add(chassis_event_threads_t *threads, chassis_event_thread_t *thread) {
214 g_ptr_array_add(threads->event_threads, thread);
215}
216
217
218/**
219 * setup the notification-fd of a event-thread
220 *
221 * all event-threads listen on the same notification pipe
222 *
223 * @see chassis_event_handle()
224 */
225int chassis_event_threads_init_thread(chassis_event_threads_t *threads, chassis_event_thread_t *event_thread, chassis *chas) {
226 event_thread->event_base = event_base_new();
227 event_thread->chas = chas;
228
229 event_thread->notify_fd = dup(threads->event_notify_fds[0]);
230
231 evutil_make_socket_nonblocking(event_thread->notify_fd);
232
233 event_set(&(event_thread->notify_fd_event), event_thread->notify_fd, EV_READ | EV_PERSIST, chassis_event_handle, event_thread);
234 event_base_set(event_thread->event_base, &(event_thread->notify_fd_event));
235 event_add(&(event_thread->notify_fd_event), NULL);
236
237 return 0;
238}
239
240/**
241 * event-handler thread
242 *
243 */
244void *chassis_event_thread_loop(chassis_event_thread_t *event_thread) {
245 chassis_event_thread_set_event_base(event_thread, event_thread->event_base);
246
247 /**
248 * check once a second if we shall shutdown the proxy
249 */
250 while (!chassis_is_shutdown()) {
251 struct timeval timeout;
252 int r;
253
254 timeout.tv_sec = 1;
255 timeout.tv_usec = 0;
256
257 g_assert(event_base_loopexit(event_thread->event_base, &timeout) == 0);
258
259 r = event_base_dispatch(event_thread->event_base);
260
261 if (r == -1) {
262 if (errno == EINTR) continue;
263
264 break;
265 }
266 }
267
268 return NULL;
269}
270
271void chassis_event_threads_start(chassis_event_threads_t *threads) {
272 guint i;
273
274 for (i = 1; i < threads->event_threads->len; i++) { /* the 1st is the main-thread and already set up */
275 chassis_event_thread_t *event_thread = threads->event_threads->pdata[i];
276 GError *gerr = NULL;
277
278 event_thread->thr = g_thread_create((GThreadFunc)chassis_event_thread_loop, event_thread, TRUE, &gerr);
279
280 if (gerr) {
281 g_error_free(gerr);
282 gerr = NULL;
283 }
284 }
285}
286
287
0288
=== added file 'src/chassis-event-thread.h'
--- src/chassis-event-thread.h 1970-01-01 00:00:00 +0000
+++ src/chassis-event-thread.h 2009-05-25 08:57:34 +0000
@@ -0,0 +1,81 @@
1/* $%BEGINLICENSE%$
2 Copyright (C) 2007-2008 MySQL AB, 2008 Sun Microsystems, Inc
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
17 $%ENDLICENSE%$ */
18
19
20#ifndef _CHASSIS_EVENT_THREAD_H_
21#define _CHASSIS_EVENT_THREAD_H_
22
23#include <glib.h> /* GPtrArray */
24
25#include "chassis-exports.h"
26#include "chassis-mainloop.h"
27
28/**
29 * event operations
30 *
31 * event-ops are sent through the async-queues
32 */
33
34typedef struct {
35 enum {
36 CHASSIS_EVENT_OP_UNSET,
37 CHASSIS_EVENT_OP_ADD
38 } type;
39
40 struct event *ev;
41} chassis_event_op_t;
42
43CHASSIS_API chassis_event_op_t *chassis_event_op_new();
44CHASSIS_API void chassis_event_op_free(chassis_event_op_t *e);
45CHASSIS_API void chassis_event_add(chassis *chas, struct event *ev);
46CHASSIS_API void chassis_event_add_local(chassis *chas, struct event *ev);
47
48/**
49 * a event-thread
50 */
51typedef struct {
52 chassis *chas;
53
54 int notify_fd;
55 struct event notify_fd_event;
56
57 GThread *thr;
58
59 struct event_base *event_base;
60} chassis_event_thread_t;
61
62CHASSIS_API chassis_event_thread_t *chassis_event_thread_new();
63CHASSIS_API void chassis_event_thread_free(chassis_event_thread_t *e);
64CHASSIS_API void chassis_event_handle(int event_fd, short events, void *user_data);
65CHASSIS_API void chassis_event_thread_set_event_base(chassis_event_thread_t *e, struct event_base *event_base);
66CHASSIS_API void *chassis_event_thread_loop(chassis_event_thread_t *);
67
68struct chassis_event_threads_t {
69 GPtrArray *event_threads;
70
71 GAsyncQueue *event_queue;
72 int event_notify_fds[2];
73};
74
75CHASSIS_API chassis_event_threads_t *chassis_event_threads_new();
76CHASSIS_API void chassis_event_threads_free(chassis_event_threads_t *threads);
77CHASSIS_API int chassis_event_threads_init_thread(chassis_event_threads_t *threads, chassis_event_thread_t *event_thread, chassis *chas);
78CHASSIS_API void chassis_event_threads_add(chassis_event_threads_t *threads, chassis_event_thread_t *thread);
79CHASSIS_API void chassis_event_threads_start(chassis_event_threads_t *threads);
80
81#endif
082
=== modified file 'src/chassis-mainloop.c'
--- src/chassis-mainloop.c 2009-02-23 23:13:09 +0000
+++ src/chassis-mainloop.c 2009-05-25 08:57:34 +0000
@@ -42,6 +42,7 @@
42#include <glib.h>42#include <glib.h>
43#include "chassis-plugin.h"43#include "chassis-plugin.h"
44#include "chassis-mainloop.h"44#include "chassis-mainloop.h"
45#include "chassis-event-thread.h"
45#include "chassis-log.h"46#include "chassis-log.h"
46#include "chassis-stats.h"47#include "chassis-stats.h"
4748
@@ -68,6 +69,8 @@
68 69
69 chas->stats = chassis_stats_new();70 chas->stats = chassis_stats_new();
7071
72 chas->threads = chassis_event_threads_new();
73
71 return chas;74 return chas;
72}75}
7376
@@ -120,6 +123,8 @@
120 123
121 if (chas->stats) chassis_stats_free(chas->stats);124 if (chas->stats) chassis_stats_free(chas->stats);
122125
126 if (chas->threads) chassis_event_threads_free(chas->threads);
127
123 g_free(chas);128 g_free(chas);
124}129}
125130
@@ -192,23 +197,12 @@
192 g_log(G_LOG_DOMAIN, glib_log_level, "(libevent) %s", msg);197 g_log(G_LOG_DOMAIN, glib_log_level, "(libevent) %s", msg);
193}198}
194199
195/**
196 * init libevent
197 *
198 * kqueue has to be called after the fork() of daemonize
199 *
200 * @param m global context
201 */
202static void chassis_init_libevent(chassis *chas) {
203 chas->event_base = event_init();
204
205 event_set_log_callback(event_log_use_glib);
206}
207200
208int chassis_mainloop(void *_chas) {201int chassis_mainloop(void *_chas) {
209 chassis *chas = _chas;202 chassis *chas = _chas;
210 guint i;203 guint i;
211 struct event ev_sigterm, ev_sigint, ev_sighup;204 struct event ev_sigterm, ev_sigint, ev_sighup;
205 chassis_event_thread_t *mainloop_thread;
212206
213#ifdef _WIN32207#ifdef _WIN32
214 WORD wVersionRequested;208 WORD wVersionRequested;
@@ -224,8 +218,19 @@
224 return err; /* err is positive */218 return err; /* err is positive */
225 }219 }
226#endif220#endif
227 /* init the event-handlers */221 /* redirect logging from libevent to glib */
228 chassis_init_libevent(chas);222 event_set_log_callback(event_log_use_glib);
223
224
225 /* add a event-handler for the "main" events */
226 mainloop_thread = chassis_event_thread_new();
227 chassis_event_threads_init_thread(chas->threads, mainloop_thread, chas);
228 chassis_event_threads_add(chas->threads, mainloop_thread);
229
230 chas->event_base = mainloop_thread->event_base; /* all global events go to the 1st thread */
231
232 g_assert(chas->event_base);
233
229234
230 /* setup all plugins all plugins */235 /* setup all plugins all plugins */
231 for (i = 0; i < chas->modules->len; i++) {236 for (i = 0; i < chas->modules->len; i++) {
@@ -293,28 +298,32 @@
293 }298 }
294#endif299#endif
295300
301 if (chas->event_thread_count < 1) chas->event_thread_count = 0;
302
303 /* create the event-threads
304 *
305 * - dup the async-queue-ping-fds
306 * - setup the events notification
307 * */
308 for (i = 0; i < chas->event_thread_count; i++) {
309 chassis_event_thread_t *event_thread;
310
311 event_thread = chassis_event_thread_new();
312 chassis_event_threads_init_thread(chas->threads, event_thread, chas);
313 chassis_event_threads_add(chas->threads, event_thread);
314 }
315
316 /* start the event threads */
317 if (chas->event_thread_count > 0) {
318 chassis_event_threads_start(chas->threads);
319 }
320
296 /**321 /**
297 * check once a second if we shall shutdown the proxy322 * handle signals and all basic events into the main-thread
323 *
324 * block until we are asked to shutdown
298 */325 */
299 while (!chassis_is_shutdown()) {326 chassis_event_thread_loop(mainloop_thread);
300 struct timeval timeout;
301 int r;
302
303 timeout.tv_sec = 1;
304 timeout.tv_usec = 0;
305
306 g_assert(event_base_loopexit(chas->event_base, &timeout) == 0);
307
308 r = event_base_dispatch(chas->event_base);
309
310 if (r == -1) {
311 if (errno == EINTR) continue;
312
313 g_critical("%s: event_base_dispatch() failed: %s (%d)",
314 G_STRLOC, g_strerror(errno), errno);
315 break;
316 }
317 }
318327
319 signal_del(&ev_sigterm);328 signal_del(&ev_sigterm);
320 signal_del(&ev_sigint);329 signal_del(&ev_sigint);
321330
=== modified file 'src/chassis-mainloop.h'
--- src/chassis-mainloop.h 2009-02-23 23:13:09 +0000
+++ src/chassis-mainloop.h 2009-05-25 08:57:34 +0000
@@ -43,6 +43,7 @@
4343
44typedef struct chassis_private chassis_private;44typedef struct chassis_private chassis_private;
45typedef struct chassis chassis;45typedef struct chassis chassis;
46typedef struct chassis_event_threads_t chassis_event_threads_t;
4647
47struct chassis {48struct chassis {
48 struct event_base *event_base;49 struct event_base *event_base;
@@ -59,6 +60,11 @@
59 chassis_log *log;60 chassis_log *log;
60 61
61 chassis_stats_t *stats; /**< the overall chassis stats, includes lua and glib allocation stats */62 chassis_stats_t *stats; /**< the overall chassis stats, includes lua and glib allocation stats */
63
64 /* network-io threads */
65 gint event_thread_count;
66
67 chassis_event_threads_t *threads;
62};68};
6369
64CHASSIS_API chassis *chassis_init(void) G_GNUC_DEPRECATED;70CHASSIS_API chassis *chassis_init(void) G_GNUC_DEPRECATED;
6571
=== modified file 'src/chassis.c'
--- src/chassis.c 2009-05-15 14:23:58 +0000
+++ src/chassis.c 2009-05-25 08:57:34 +0000
@@ -395,6 +395,7 @@
395 guint invoke_dbg_on_crash = 0;395 guint invoke_dbg_on_crash = 0;
396 guint auto_restart = 0;396 guint auto_restart = 0;
397 guint max_files_number = 8192;397 guint max_files_number = 8192;
398 gint event_thread_count = 0;
398#ifndef _WIN32399#ifndef _WIN32
399 struct rlimit max_files_rlimit;400 struct rlimit max_files_rlimit;
400#endif401#endif
@@ -431,6 +432,7 @@
431 { "log-backtrace-on-crash", 0, 0, G_OPTION_ARG_NONE, NULL, "try to invoke debugger on crash", NULL },432 { "log-backtrace-on-crash", 0, 0, G_OPTION_ARG_NONE, NULL, "try to invoke debugger on crash", NULL },
432 { "keepalive", 0, 0, G_OPTION_ARG_NONE, NULL, "try to restart the proxy if it crashed", NULL },433 { "keepalive", 0, 0, G_OPTION_ARG_NONE, NULL, "try to restart the proxy if it crashed", NULL },
433 { "max-open-files", 0, 0, G_OPTION_ARG_INT, NULL, "maximum number of open files (ulimit -n)", NULL},434 { "max-open-files", 0, 0, G_OPTION_ARG_INT, NULL, "maximum number of open files (ulimit -n)", NULL},
435 { "event-threads", 0, 0, G_OPTION_ARG_INT, NULL, "number of event-handling threads", NULL},
434 436
435 { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }437 { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
436 };438 };
@@ -501,6 +503,7 @@
501 main_entries[i++].arg_data = &(invoke_dbg_on_crash);503 main_entries[i++].arg_data = &(invoke_dbg_on_crash);
502 main_entries[i++].arg_data = &(auto_restart);504 main_entries[i++].arg_data = &(auto_restart);
503 main_entries[i++].arg_data = &(max_files_number);505 main_entries[i++].arg_data = &(max_files_number);
506 main_entries[i++].arg_data = &(srv->event_thread_count);
504507
505 option_ctx = g_option_context_new("- MySQL App Shell");508 option_ctx = g_option_context_new("- MySQL App Shell");
506 g_option_context_add_main_entries(option_ctx, base_main_entries, GETTEXT_PACKAGE);509 g_option_context_add_main_entries(option_ctx, base_main_entries, GETTEXT_PACKAGE);
@@ -888,6 +891,16 @@
888 exit_code = EXIT_FAILURE;891 exit_code = EXIT_FAILURE;
889 goto exit_nicely;892 goto exit_nicely;
890 }893 }
894
895 /* make sure that he max-thread-count isn't negative */
896 if (event_thread_count < 0) {
897 g_critical("unknown option: %s", argv[1]);
898
899 exit_code = EXIT_FAILURE;
900 goto exit_nicely;
901 }
902
903 srv->event_thread_count = event_thread_count;
891 904
892#ifndef _WIN32 905#ifndef _WIN32
893 signal(SIGPIPE, SIG_IGN);906 signal(SIGPIPE, SIG_IGN);
@@ -988,7 +1001,6 @@
988 }1001 }
989 }1002 }
990#endif1003#endif
991
992 if (chassis_mainloop(srv)) {1004 if (chassis_mainloop(srv)) {
993 /* looks like we failed */1005 /* looks like we failed */
9941006
9951007
=== modified file 'src/network-conn-pool-lua.c'
--- src/network-conn-pool-lua.c 2009-02-24 00:20:29 +0000
+++ src/network-conn-pool-lua.c 2009-05-25 08:57:34 +0000
@@ -43,6 +43,7 @@
4343
44#include "network-mysqld.h"44#include "network-mysqld.h"
45#include "network-mysqld-packet.h"45#include "network-mysqld-packet.h"
46#include "chassis-event-thread.h"
46#include "network-mysqld-lua.h"47#include "network-mysqld-lua.h"
4748
48#include "network-conn-pool.h"49#include "network-conn-pool.h"
@@ -201,7 +202,6 @@
201 * proxy from its backend 202 * proxy from its backend
202 */203 */
203int network_connection_pool_lua_add_connection(network_mysqld_con *con) {204int network_connection_pool_lua_add_connection(network_mysqld_con *con) {
204 chassis *srv = con->srv;
205 network_connection_pool_entry *pool_entry = NULL;205 network_connection_pool_entry *pool_entry = NULL;
206 network_mysqld_con_lua_t *st = con->plugin_con_state;206 network_mysqld_con_lua_t *st = con->plugin_con_state;
207207
@@ -215,8 +215,7 @@
215 pool_entry = network_connection_pool_add(st->backend->pool, con->server);215 pool_entry = network_connection_pool_add(st->backend->pool, con->server);
216216
217 event_set(&(con->server->event), con->server->fd, EV_READ, network_mysqld_con_idle_handle, pool_entry);217 event_set(&(con->server->event), con->server->fd, EV_READ, network_mysqld_con_idle_handle, pool_entry);
218 event_base_set(srv->event_base, &(con->server->event));218 chassis_event_add_local(con->srv, &(con->server->event)); /* add a event, but stay in the same thread */
219 event_add(&(con->server->event), NULL);
220 219
221 st->backend->connected_clients--;220 st->backend->connected_clients--;
222 st->backend = NULL;221 st->backend = NULL;
223222
=== modified file 'src/network-mysqld.c'
--- src/network-mysqld.c 2009-02-21 14:09:48 +0000
+++ src/network-mysqld.c 2009-05-25 08:57:34 +0000
@@ -179,6 +179,7 @@
179#include "network-mysqld-packet.h"179#include "network-mysqld-packet.h"
180#include "network-conn-pool.h"180#include "network-conn-pool.h"
181#include "chassis-mainloop.h"181#include "chassis-mainloop.h"
182#include "chassis-event-thread.h"
182#include "lua-scope.h"183#include "lua-scope.h"
183#include "glib-ext.h"184#include "glib-ext.h"
184185
@@ -761,8 +762,7 @@
761762
762#define WAIT_FOR_EVENT(ev_struct, ev_type, timeout) \763#define WAIT_FOR_EVENT(ev_struct, ev_type, timeout) \
763 event_set(&(ev_struct->event), ev_struct->fd, ev_type, network_mysqld_con_handle, user_data); \764 event_set(&(ev_struct->event), ev_struct->fd, ev_type, network_mysqld_con_handle, user_data); \
764 event_base_set(srv->event_base, &(ev_struct->event));\765 chassis_event_add(srv, &(ev_struct->event));
765 event_add(&(ev_struct->event), timeout);
766766
767 /**767 /**
768 * loop on the same connection as long as we don't end up in a stable state768 * loop on the same connection as long as we don't end up in a stable state
769769
=== modified file 'tests/unit/Makefile.am'
--- tests/unit/Makefile.am 2009-04-02 22:10:21 +0000
+++ tests/unit/Makefile.am 2009-05-25 08:57:34 +0000
@@ -74,10 +74,11 @@
74 check_chassis_path.c \74 check_chassis_path.c \
75 $(top_srcdir)/src/chassis-log.c \75 $(top_srcdir)/src/chassis-log.c \
76 $(top_srcdir)/src/chassis-mainloop.c \76 $(top_srcdir)/src/chassis-mainloop.c \
77 $(top_srcdir)/src/chassis-event-thread.c \
77 $(top_srcdir)/src/chassis-plugin.c \78 $(top_srcdir)/src/chassis-plugin.c \
78 $(top_srcdir)/src/chassis-stats.c79 $(top_srcdir)/src/chassis-stats.c
79check_chassis_path_CPPFLAGS = -I$(top_srcdir)/src $(GLIB_CFLAGS) $(MYSQL_CFLAGS) $(GMODULE_CFLAGS)80check_chassis_path_CPPFLAGS = -I$(top_srcdir)/src $(GLIB_CFLAGS) $(MYSQL_CFLAGS) $(GMODULE_CFLAGS)
80check_chassis_path_LDADD = $(GLIB_LIBS) $(GMODULE_LIBS) $(EVENT_LIBS)81check_chassis_path_LDADD = $(GLIB_LIBS) $(GMODULE_LIBS) $(EVENT_LIBS) $(GTHREAD_LIBS)
8182
82t_network_backend_SOURCES = \83t_network_backend_SOURCES = \
83 t_network_backend.c \84 t_network_backend.c \
8485
=== modified file 'tests/unit/check_chassis_path.c'
--- tests/unit/check_chassis_path.c 2009-02-23 23:13:09 +0000
+++ tests/unit/check_chassis_path.c 2009-05-25 08:57:34 +0000
@@ -95,6 +95,8 @@
95/*@}*/95/*@}*/
9696
97int main(int argc, char **argv) {97int main(int argc, char **argv) {
98 g_thread_init(NULL);
99
98 g_test_init(&argc, &argv, NULL);100 g_test_init(&argc, &argv, NULL);
99 g_test_bug_base("http://bugs.mysql.com/");101 g_test_bug_base("http://bugs.mysql.com/");
100 102

Subscribers

People subscribed via source and target branches