Merge lp:~fallenpegasus/drizzle/logbugfix into lp:~drizzle-trunk/drizzle/development
- logbugfix
- Merge into development
Proposed by
Mark Atwood
Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~fallenpegasus/drizzle/logbugfix |
Merge into: | lp:~drizzle-trunk/drizzle/development |
Diff against target: | None lines |
To merge this branch: | bzr merge lp:~fallenpegasus/drizzle/logbugfix |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Brian Aker | Needs Information | ||
Review via email: mp+6837@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Mark Atwood (fallenpegasus) wrote : | # |
Revision history for this message
Brian Aker (brianaker) wrote : | # |
Hi!
One of your comments mentions "unloading". Plugins unload during deinit, so you can fix the cleanup issue there.
Also, when is the file descriptor closed? You removed that during the deinit.
Cheers,
-Brian
review:
Needs Information
- 1046. By Mark Atwood
-
merge from main
- 1047. By Mark Atwood
-
add destructor to logging_query, to close filehandle and clean up PCRE stuff
Revision history for this message
Mark Atwood (fallenpegasus) wrote : | # |
Done. The deinit calls the destructor, and the destructore closes the file descriptor and cleans up the PCRE allocation.s
- 1048. By Mark Atwood
-
make logging_syslog be more C++'ish
- 1049. By Mark Atwood
-
make logging_gearman plugin be more C++'ish
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'drizzled/logging.cc' |
2 | --- drizzled/logging.cc 2009-05-11 17:50:22 +0000 |
3 | +++ drizzled/logging.cc 2009-05-27 20:05:51 +0000 |
4 | @@ -112,7 +112,7 @@ |
5 | /* Use find_if instead of foreach so that we can collect return codes */ |
6 | vector<Logging_handler *>::iterator iter= |
7 | find_if(all_loggers.begin(), all_loggers.end(), |
8 | - LoggingPreIterate(session)); |
9 | + LoggingPostIterate(session)); |
10 | /* If iter is == end() here, that means that all of the plugins returned |
11 | * false, which in this case means they all succeeded. Since we want to |
12 | * return false on success, we return the value of the two being != |
13 | |
14 | === modified file 'plugin/logging_gearman/logging_gearman.cc' |
15 | --- plugin/logging_gearman/logging_gearman.cc 2009-05-11 17:50:22 +0000 |
16 | +++ plugin/logging_gearman/logging_gearman.cc 2009-05-27 20:41:17 +0000 |
17 | @@ -202,7 +202,8 @@ |
18 | msgbuf_len= |
19 | snprintf(msgbuf, MAX_MSG_LEN, |
20 | "%"PRIu64",%"PRIu64",%"PRIu64",\"%.*s\",\"%s\",\"%.*s\"," |
21 | - "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64"", |
22 | + "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64 |
23 | + "%"PRIu32",%"PRIu32"", |
24 | t_mark, |
25 | session->thread_id, |
26 | session->query_id, |
27 | @@ -220,7 +221,9 @@ |
28 | (t_mark - session->start_utime), |
29 | (t_mark - session->utime_after_lock), |
30 | session->sent_row_count, |
31 | - session->examined_row_count); |
32 | + session->examined_row_count, |
33 | + session->tmp_table, |
34 | + session->total_warn_count); |
35 | |
36 | char job_handle[GEARMAN_JOB_HANDLE_SIZE]; |
37 | |
38 | |
39 | === modified file 'plugin/logging_query/logging_query.cc' |
40 | --- plugin/logging_query/logging_query.cc 2009-05-11 17:50:22 +0000 |
41 | +++ plugin/logging_query/logging_query.cc 2009-05-27 23:16:02 +0000 |
42 | @@ -21,19 +21,19 @@ |
43 | #include <drizzled/plugin/logging_handler.h> |
44 | #include <drizzled/gettext.h> |
45 | #include <drizzled/session.h> |
46 | +#include <pcre.h> |
47 | |
48 | /* TODO make this dynamic as needed */ |
49 | static const int MAX_MSG_LEN= 32*1024; |
50 | |
51 | static bool sysvar_logging_query_enable= false; |
52 | static char* sysvar_logging_query_filename= NULL; |
53 | -/* TODO fix these to not be unsigned long one we have sensible sys_var system */ |
54 | +static char* sysvar_logging_query_pcre= NULL; |
55 | +/* TODO fix these to not be unsigned long once we have sensible sys_var system */ |
56 | static unsigned long sysvar_logging_query_threshold_slow= 0; |
57 | static unsigned long sysvar_logging_query_threshold_big_resultset= 0; |
58 | static unsigned long sysvar_logging_query_threshold_big_examined= 0; |
59 | |
60 | -static int fd= -1; |
61 | - |
62 | /* stolen from mysys/my_getsystime |
63 | until the Session has a good utime "now" we can use |
64 | will have to use this instead */ |
65 | @@ -164,17 +164,50 @@ |
66 | return dst; |
67 | } |
68 | |
69 | +/* TODO, write a matcng destructor. But since plugins are never unlaoded, necessary? */ |
70 | |
71 | -/* we could just not have a pre entrypoint at all, |
72 | - and have logging_pre == NULL |
73 | - but we have this here for the sake of being an example */ |
74 | class Logging_query: public Logging_handler |
75 | { |
76 | + int fd; |
77 | + pcre *re; |
78 | + pcre_extra *pe; |
79 | + |
80 | public: |
81 | - Logging_query() : Logging_handler("Logging_query") {} |
82 | + |
83 | + Logging_query() : Logging_handler("Logging_query"), fd(-1), re(NULL), pe(NULL) |
84 | + { |
85 | + |
86 | + /* if there is no destination filename, dont bother doing anything */ |
87 | + if (sysvar_logging_query_filename == NULL) |
88 | + return; |
89 | + |
90 | + fd= open(sysvar_logging_query_filename, |
91 | + O_WRONLY | O_APPEND | O_CREAT, |
92 | + S_IRUSR|S_IWUSR); |
93 | + if (fd < 0) |
94 | + { |
95 | + errmsg_printf(ERRMSG_LVL_ERROR, _("fail open() fn=%s er=%s\n"), |
96 | + sysvar_logging_query_filename, |
97 | + strerror(errno)); |
98 | + return; |
99 | + } |
100 | + |
101 | + if (sysvar_logging_query_pcre != NULL) |
102 | + { |
103 | + const char *this_pcre_error; |
104 | + int this_pcre_erroffset; |
105 | + re= pcre_compile(sysvar_logging_query_pcre, 0, &this_pcre_error, |
106 | + &this_pcre_erroffset, NULL); |
107 | + pe= pcre_study(re, 0, &this_pcre_error); |
108 | + /* TODO emit error messages if there is a problem */ |
109 | + } |
110 | + } |
111 | |
112 | virtual bool pre (Session *) |
113 | { |
114 | + /* we could just not have a pre entrypoint at all, |
115 | + and have logging_pre == NULL |
116 | + but we have this here for the sake of being an example */ |
117 | return false; |
118 | } |
119 | |
120 | @@ -215,7 +248,15 @@ |
121 | |
122 | if ((t_mark - session->start_utime) < (sysvar_logging_query_threshold_slow)) |
123 | return false; |
124 | - |
125 | + |
126 | + if (re) |
127 | + { |
128 | + int this_pcre_rc; |
129 | + this_pcre_rc = pcre_exec(re, pe, session->query, session->query_length, 0, 0, NULL, 0); |
130 | + if (this_pcre_rc < 0) |
131 | + return false; |
132 | + } |
133 | + |
134 | // buffer to quotify the query |
135 | unsigned char qs[255]; |
136 | |
137 | @@ -228,7 +269,8 @@ |
138 | msgbuf_len= |
139 | snprintf(msgbuf, MAX_MSG_LEN, |
140 | "%"PRIu64",%"PRIu64",%"PRIu64",\"%.*s\",\"%s\",\"%.*s\"," |
141 | - "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64"\n", |
142 | + "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64 |
143 | + "%"PRIu32",%"PRIu32"\n", |
144 | t_mark, |
145 | session->thread_id, |
146 | session->query_id, |
147 | @@ -246,8 +288,9 @@ |
148 | (t_mark - session->start_utime), |
149 | (t_mark - session->utime_after_lock), |
150 | session->sent_row_count, |
151 | - session->examined_row_count); |
152 | - |
153 | + session->examined_row_count, |
154 | + session->tmp_table, |
155 | + session->total_warn_count); |
156 | |
157 | // a single write has a kernel thread lock, thus no need mutex guard this |
158 | wrv= write(fd, msgbuf, msgbuf_len); |
159 | @@ -261,34 +304,6 @@ |
160 | |
161 | static int logging_query_plugin_init(PluginRegistry ®istry) |
162 | { |
163 | - |
164 | - if (sysvar_logging_query_filename == NULL) |
165 | - { |
166 | - /* no destination filename was specified via system variables |
167 | - return now, dont set the callback pointers |
168 | - */ |
169 | - return 0; |
170 | - } |
171 | - |
172 | - fd= open(sysvar_logging_query_filename, |
173 | - O_WRONLY | O_APPEND | O_CREAT, |
174 | - S_IRUSR|S_IWUSR); |
175 | - if (fd < 0) |
176 | - { |
177 | - errmsg_printf(ERRMSG_LVL_ERROR, _("fail open() fn=%s er=%s\n"), |
178 | - sysvar_logging_query_filename, |
179 | - strerror(errno)); |
180 | - |
181 | - /* TODO |
182 | - we should return an error here, so the plugin doesnt load |
183 | - but this causes Drizzle to crash |
184 | - so until that is fixed, |
185 | - just return a success, |
186 | - but leave the function pointers as NULL and the fd as -1 |
187 | - */ |
188 | - return 0; |
189 | - } |
190 | - |
191 | handler= new Logging_query(); |
192 | registry.add(handler); |
193 | |
194 | @@ -297,13 +312,6 @@ |
195 | |
196 | static int logging_query_plugin_deinit(PluginRegistry ®istry) |
197 | { |
198 | - |
199 | - if (fd >= 0) |
200 | - { |
201 | - close(fd); |
202 | - fd= -1; |
203 | - } |
204 | - |
205 | registry.remove(handler); |
206 | delete handler; |
207 | |
208 | @@ -328,6 +336,15 @@ |
209 | NULL, /* update func*/ |
210 | NULL /* default */); |
211 | |
212 | +static DRIZZLE_SYSVAR_STR( |
213 | + pcre, |
214 | + sysvar_logging_query_pcre, |
215 | + PLUGIN_VAR_READONLY, |
216 | + N_("PCRE to match the query against"), |
217 | + NULL, /* check func */ |
218 | + NULL, /* update func*/ |
219 | + NULL /* default */); |
220 | + |
221 | static DRIZZLE_SYSVAR_ULONG( |
222 | threshold_slow, |
223 | sysvar_logging_query_threshold_slow, |
224 | @@ -367,6 +384,7 @@ |
225 | static struct st_mysql_sys_var* logging_query_system_variables[]= { |
226 | DRIZZLE_SYSVAR(enable), |
227 | DRIZZLE_SYSVAR(filename), |
228 | + DRIZZLE_SYSVAR(pcre), |
229 | DRIZZLE_SYSVAR(threshold_slow), |
230 | DRIZZLE_SYSVAR(threshold_big_resultset), |
231 | DRIZZLE_SYSVAR(threshold_big_examined), |
232 | |
233 | === modified file 'plugin/logging_syslog/logging_syslog.cc' |
234 | --- plugin/logging_syslog/logging_syslog.cc 2009-05-11 17:50:22 +0000 |
235 | +++ plugin/logging_syslog/logging_syslog.cc 2009-05-27 20:56:47 +0000 |
236 | @@ -110,7 +110,8 @@ |
237 | " query=\"%.*s\"" |
238 | " command=\"%.*s\"" |
239 | " t_connect=%lld t_start=%lld t_lock=%lld" |
240 | - " rows_sent=%ld rows_examined=%ld\n", |
241 | + " rows_sent=%ld rows_examined=%ld" |
242 | + " tmp_table=%ld total_warn_count=%ld\n", |
243 | (unsigned long) session->thread_id, |
244 | (unsigned long) session->query_id, |
245 | dbl, dbs, |
246 | @@ -121,30 +122,9 @@ |
247 | (unsigned long long) (t_mark - session->start_utime), |
248 | (unsigned long long) (t_mark - session->utime_after_lock), |
249 | (unsigned long) session->sent_row_count, |
250 | - (unsigned long) session->examined_row_count); |
251 | - |
252 | -#if 0 |
253 | - syslog(syslog_priority, |
254 | - "thread_id=%ld query_id=%ld" |
255 | - " db=\"%.*s\"" |
256 | - " query=\".*%s\"" |
257 | - " command=%.*s" |
258 | - " t_connect=%lld t_start=%lld t_lock=%lld" |
259 | - " rows_sent=%ld rows_examined=%ld\n", |
260 | - (unsigned long) session->thread_id, |
261 | - (unsigned long) session->query_id, |
262 | - session->db_length, session->db, |
263 | - // dont need to quote the query, because syslog does it itself |
264 | - session->query_length, session->query, |
265 | - (int) command_name[session->command].length, |
266 | - command_name[session->command].str, |
267 | - (unsigned long long) (t_mark - session->connect_utime), |
268 | - (unsigned long long) (t_mark - session->start_utime), |
269 | - (unsigned long long) (t_mark - session->utime_after_lock), |
270 | - (unsigned long) session->sent_row_count, |
271 | - (unsigned long) session->examined_row_count); |
272 | - |
273 | -#endif |
274 | + (unsigned long) session->examined_row_count, |
275 | + (unsigned long) session->tmp_table, |
276 | + (unsigned long) session->total_warn_count); |
277 | |
278 | return false; |
279 | } |
fixes a logging bug
added PCRE matching to log-to-file
makes the log-to-file plugin be more C++'ish