390.1.2
by Monty Taylor
Fixed copyright headers in drizzled/ |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2008 Sun Microsystems
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; version 2 of the License.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 |
*/
|
|
1
by brian
clean slate |
19 |
|
243.1.5
by Jay Pipes
* Pulled the remainder of the log and parse stuff out into |
20 |
#ifndef DRIZZLE_SERVER_LOG_H
|
21 |
#define DRIZZLE_SERVER_LOG_H
|
|
1
by brian
clean slate |
22 |
|
23 |
class Relay_log_info; |
|
24 |
||
25 |
class Format_description_log_event; |
|
26 |
||
27 |
/*
|
|
28 |
Transaction Coordinator log - a base abstract class
|
|
29 |
for two different implementations
|
|
30 |
*/
|
|
31 |
class TC_LOG |
|
32 |
{
|
|
33 |
public: |
|
34 |
int using_heuristic_recover(); |
|
35 |
TC_LOG() {} |
|
36 |
virtual ~TC_LOG() {} |
|
37 |
||
38 |
virtual int open(const char *opt_name)=0; |
|
39 |
virtual void close()=0; |
|
40 |
virtual int log_xid(THD *thd, my_xid xid)=0; |
|
41 |
virtual void unlog(ulong cookie, my_xid xid)=0; |
|
42 |
};
|
|
43 |
||
44 |
class TC_LOG_DUMMY: public TC_LOG // use it to disable the logging |
|
45 |
{
|
|
46 |
public: |
|
47 |
TC_LOG_DUMMY() {} |
|
212.3.1
by Jay Pipes
Fix for Bug#252309 "log output to tables is enabled but ineffective". |
48 |
int open(const char *opt_name __attribute__((unused))) |
53.2.32
by Monty Taylor
First large swath at getting handler stuff clean. |
49 |
{ return 0; } |
50 |
void close(void) { } |
|
212.3.1
by Jay Pipes
Fix for Bug#252309 "log output to tables is enabled but ineffective". |
51 |
int log_xid(THD *thd __attribute__((unused)), |
52 |
my_xid xid __attribute__((unused))) { return 1; } |
|
53 |
void unlog(ulong cookie __attribute__((unused)), |
|
54 |
my_xid xid __attribute__((unused))) { } |
|
1
by brian
clean slate |
55 |
};
|
56 |
||
57 |
#ifdef HAVE_MMAP
|
|
58 |
class TC_LOG_MMAP: public TC_LOG |
|
59 |
{
|
|
60 |
public: // only to keep Sun Forte on sol9x86 happy |
|
61 |
typedef enum { |
|
62 |
POOL, // page is in pool |
|
63 |
ERROR, // last sync failed |
|
64 |
DIRTY // new xids added since last sync |
|
65 |
} PAGE_STATE; |
|
66 |
||
67 |
private: |
|
68 |
typedef struct st_page { |
|
69 |
struct st_page *next; // page a linked in a fifo queue |
|
70 |
my_xid *start, *end; // usable area of a page |
|
71 |
my_xid *ptr; // next xid will be written here |
|
72 |
int size, free; // max and current number of free xid slots on the page |
|
73 |
int waiters; // number of waiters on condition |
|
74 |
PAGE_STATE state; // see above |
|
75 |
pthread_mutex_t lock; // to access page data or control structure |
|
76 |
pthread_cond_t cond; // to wait for a sync |
|
77 |
} PAGE; |
|
78 |
||
79 |
char logname[FN_REFLEN]; |
|
80 |
File fd; |
|
81 |
my_off_t file_length; |
|
82 |
uint npages, inited; |
|
83 |
uchar *data; |
|
84 |
struct st_page *pages, *syncing, *active, *pool, *pool_last; |
|
85 |
/*
|
|
86 |
note that, e.g. LOCK_active is only used to protect
|
|
87 |
'active' pointer, to protect the content of the active page
|
|
88 |
one has to use active->lock.
|
|
89 |
Same for LOCK_pool and LOCK_sync
|
|
90 |
*/
|
|
91 |
pthread_mutex_t LOCK_active, LOCK_pool, LOCK_sync; |
|
92 |
pthread_cond_t COND_pool, COND_active; |
|
93 |
||
94 |
public: |
|
95 |
TC_LOG_MMAP(): inited(0) {} |
|
96 |
int open(const char *opt_name); |
|
97 |
void close(); |
|
98 |
int log_xid(THD *thd, my_xid xid); |
|
99 |
void unlog(ulong cookie, my_xid xid); |
|
100 |
int recover(); |
|
101 |
||
102 |
private: |
|
103 |
void get_active_from_pool(); |
|
104 |
int sync(); |
|
105 |
int overflow(); |
|
106 |
};
|
|
107 |
#else
|
|
108 |
#define TC_LOG_MMAP TC_LOG_DUMMY
|
|
109 |
#endif
|
|
110 |
||
111 |
extern TC_LOG *tc_log; |
|
112 |
extern TC_LOG_MMAP tc_log_mmap; |
|
113 |
extern TC_LOG_DUMMY tc_log_dummy; |
|
114 |
||
115 |
/* log info errors */
|
|
116 |
#define LOG_INFO_EOF -1
|
|
117 |
#define LOG_INFO_IO -2
|
|
118 |
#define LOG_INFO_INVALID -3
|
|
119 |
#define LOG_INFO_SEEK -4
|
|
120 |
#define LOG_INFO_MEM -6
|
|
121 |
#define LOG_INFO_FATAL -7
|
|
122 |
#define LOG_INFO_IN_USE -8
|
|
123 |
#define LOG_INFO_EMFILE -9
|
|
124 |
||
125 |
||
126 |
/* bitmap to SQL_LOG::close() */
|
|
127 |
#define LOG_CLOSE_INDEX 1
|
|
128 |
#define LOG_CLOSE_TO_BE_OPENED 2
|
|
129 |
#define LOG_CLOSE_STOP_EVENT 4
|
|
130 |
||
131 |
class Relay_log_info; |
|
132 |
||
133 |
typedef struct st_log_info |
|
134 |
{
|
|
135 |
char log_file_name[FN_REFLEN]; |
|
136 |
my_off_t index_file_offset, index_file_start_offset; |
|
137 |
my_off_t pos; |
|
138 |
bool fatal; // if the purge happens to give us a negative offset |
|
139 |
pthread_mutex_t lock; |
|
140 |
st_log_info() |
|
141 |
: index_file_offset(0), index_file_start_offset(0), |
|
142 |
pos(0), fatal(0) |
|
143 |
{
|
|
144 |
log_file_name[0] = '\0'; |
|
145 |
pthread_mutex_init(&lock, MY_MUTEX_INIT_FAST); |
|
146 |
}
|
|
147 |
~st_log_info() { pthread_mutex_destroy(&lock);} |
|
148 |
} LOG_INFO; |
|
149 |
||
150 |
/*
|
|
151 |
Currently we have only 3 kinds of logging functions: old-fashioned
|
|
152 |
logs, stdout and csv logging routines.
|
|
153 |
*/
|
|
154 |
#define MAX_LOG_HANDLERS_NUM 3
|
|
155 |
||
156 |
/* log event handler flags */
|
|
157 |
#define LOG_NONE 1
|
|
158 |
#define LOG_FILE 2
|
|
159 |
||
160 |
class Log_event; |
|
161 |
class Rows_log_event; |
|
162 |
||
163 |
enum enum_log_type { LOG_UNKNOWN, LOG_NORMAL, LOG_BIN }; |
|
164 |
enum enum_log_state { LOG_OPENED, LOG_CLOSED, LOG_TO_BE_OPENED }; |
|
165 |
||
166 |
/*
|
|
167 |
TODO use mmap instead of IO_CACHE for binlog
|
|
168 |
(mmap+fsync is two times faster than write+fsync)
|
|
169 |
*/
|
|
170 |
||
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
171 |
class DRIZZLE_LOG |
1
by brian
clean slate |
172 |
{
|
173 |
public: |
|
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
174 |
DRIZZLE_LOG(); |
1
by brian
clean slate |
175 |
void init_pthread_objects(); |
176 |
void cleanup(); |
|
177 |
bool open(const char *log_name, |
|
178 |
enum_log_type log_type, |
|
179 |
const char *new_name, |
|
180 |
enum cache_type io_cache_type_arg); |
|
181 |
void init(enum_log_type log_type_arg, |
|
182 |
enum cache_type io_cache_type_arg); |
|
183 |
void close(uint exiting); |
|
184 |
inline bool is_open() { return log_state != LOG_CLOSED; } |
|
185 |
const char *generate_name(const char *log_name, const char *suffix, |
|
186 |
bool strip_ext, char *buff); |
|
187 |
int generate_new_name(char *new_name, const char *log_name); |
|
188 |
protected: |
|
189 |
/* LOCK_log is inited by init_pthread_objects() */
|
|
190 |
pthread_mutex_t LOCK_log; |
|
191 |
char *name; |
|
192 |
char log_file_name[FN_REFLEN]; |
|
193 |
char time_buff[20], db[NAME_LEN + 1]; |
|
194 |
bool write_error, inited; |
|
195 |
IO_CACHE log_file; |
|
196 |
enum_log_type log_type; |
|
197 |
volatile enum_log_state log_state; |
|
198 |
enum cache_type io_cache_type; |
|
199 |
friend class Log_event; |
|
200 |
};
|
|
201 |
||
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
202 |
class DRIZZLE_QUERY_LOG: public DRIZZLE_LOG |
1
by brian
clean slate |
203 |
{
|
204 |
public: |
|
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
205 |
DRIZZLE_QUERY_LOG() : last_time(0) {} |
1
by brian
clean slate |
206 |
void reopen_file(); |
207 |
bool write(time_t event_time, const char *user_host, |
|
208 |
uint user_host_len, int thread_id, |
|
209 |
const char *command_type, uint command_type_len, |
|
210 |
const char *sql_text, uint sql_text_len); |
|
211 |
bool write(THD *thd, time_t current_time, time_t query_start_arg, |
|
212 |
const char *user_host, uint user_host_len, |
|
151
by Brian Aker
Ulonglong to uint64_t |
213 |
uint64_t query_utime, uint64_t lock_utime, bool is_command, |
1
by brian
clean slate |
214 |
const char *sql_text, uint sql_text_len); |
215 |
bool open_slow_log(const char *log_name) |
|
216 |
{
|
|
217 |
char buf[FN_REFLEN]; |
|
218 |
return open(generate_name(log_name, "-slow.log", 0, buf), LOG_NORMAL, 0, |
|
219 |
WRITE_CACHE); |
|
220 |
}
|
|
221 |
bool open_query_log(const char *log_name) |
|
222 |
{
|
|
223 |
char buf[FN_REFLEN]; |
|
224 |
return open(generate_name(log_name, ".log", 0, buf), LOG_NORMAL, 0, |
|
225 |
WRITE_CACHE); |
|
226 |
}
|
|
227 |
||
228 |
private: |
|
229 |
time_t last_time; |
|
230 |
};
|
|
231 |
||
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
232 |
class DRIZZLE_BIN_LOG: public TC_LOG, private DRIZZLE_LOG |
1
by brian
clean slate |
233 |
{
|
234 |
private: |
|
235 |
/* LOCK_log and LOCK_index are inited by init_pthread_objects() */
|
|
236 |
pthread_mutex_t LOCK_index; |
|
237 |
pthread_mutex_t LOCK_prep_xids; |
|
238 |
pthread_cond_t COND_prep_xids; |
|
239 |
pthread_cond_t update_cond; |
|
151
by Brian Aker
Ulonglong to uint64_t |
240 |
uint64_t bytes_written; |
1
by brian
clean slate |
241 |
IO_CACHE index_file; |
242 |
char index_file_name[FN_REFLEN]; |
|
243 |
/*
|
|
244 |
The max size before rotation (usable only if log_type == LOG_BIN: binary
|
|
245 |
logs and relay logs).
|
|
246 |
For a binlog, max_size should be max_binlog_size.
|
|
247 |
For a relay log, it should be max_relay_log_size if this is non-zero,
|
|
248 |
max_binlog_size otherwise.
|
|
249 |
max_size is set in init(), and dynamically changed (when one does SET
|
|
250 |
GLOBAL MAX_BINLOG_SIZE|MAX_RELAY_LOG_SIZE) by fix_max_binlog_size and
|
|
251 |
fix_max_relay_log_size).
|
|
252 |
*/
|
|
253 |
ulong max_size; |
|
254 |
long prepared_xids; /* for tc log - number of xids to remember */ |
|
255 |
// current file sequence number for load data infile binary logging
|
|
256 |
uint file_id; |
|
257 |
uint open_count; // For replication |
|
258 |
int readers_count; |
|
259 |
bool need_start_event; |
|
260 |
/*
|
|
261 |
no_auto_events means we don't want any of these automatic events :
|
|
262 |
Start/Rotate/Stop. That is, in 4.x when we rotate a relay log, we don't
|
|
263 |
want a Rotate_log event to be written to the relay log. When we start a
|
|
264 |
relay log etc. So in 4.x this is 1 for relay logs, 0 for binlogs.
|
|
265 |
In 5.0 it's 0 for relay logs too!
|
|
266 |
*/
|
|
267 |
bool no_auto_events; |
|
268 |
||
151
by Brian Aker
Ulonglong to uint64_t |
269 |
uint64_t m_table_map_version; |
1
by brian
clean slate |
270 |
|
271 |
int write_to_file(IO_CACHE *cache); |
|
272 |
/*
|
|
273 |
This is used to start writing to a new log file. The difference from
|
|
274 |
new_file() is locking. new_file_without_locking() does not acquire
|
|
275 |
LOCK_log.
|
|
276 |
*/
|
|
277 |
void new_file_without_locking(); |
|
278 |
void new_file_impl(bool need_lock); |
|
279 |
||
280 |
public: |
|
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
281 |
DRIZZLE_LOG::generate_name; |
282 |
DRIZZLE_LOG::is_open; |
|
1
by brian
clean slate |
283 |
/*
|
284 |
These describe the log's format. This is used only for relay logs.
|
|
285 |
_for_exec is used by the SQL thread, _for_queue by the I/O thread. It's
|
|
286 |
necessary to have 2 distinct objects, because the I/O thread may be reading
|
|
287 |
events in a different format from what the SQL thread is reading (consider
|
|
288 |
the case of a master which has been upgraded from 5.0 to 5.1 without doing
|
|
289 |
RESET MASTER, or from 4.x to 5.0).
|
|
290 |
*/
|
|
291 |
Format_description_log_event *description_event_for_exec, |
|
292 |
*description_event_for_queue; |
|
293 |
||
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
294 |
DRIZZLE_BIN_LOG(); |
1
by brian
clean slate |
295 |
/*
|
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
296 |
note that there's no destructor ~DRIZZLE_BIN_LOG() !
|
1
by brian
clean slate |
297 |
The reason is that we don't want it to be automatically called
|
298 |
on exit() - but only during the correct shutdown process
|
|
299 |
*/
|
|
300 |
||
301 |
int open(const char *opt_name); |
|
302 |
void close(); |
|
303 |
int log_xid(THD *thd, my_xid xid); |
|
304 |
void unlog(ulong cookie, my_xid xid); |
|
305 |
int recover(IO_CACHE *log, Format_description_log_event *fdle); |
|
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
306 |
#if !defined(DRIZZLE_CLIENT)
|
327.1.5
by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h |
307 |
bool is_table_mapped(Table *table) const |
1
by brian
clean slate |
308 |
{
|
309 |
return table->s->table_map_version == table_map_version(); |
|
310 |
}
|
|
311 |
||
151
by Brian Aker
Ulonglong to uint64_t |
312 |
uint64_t table_map_version() const { return m_table_map_version; } |
1
by brian
clean slate |
313 |
void update_table_map_version() { ++m_table_map_version; } |
314 |
||
315 |
int flush_and_set_pending_rows_event(THD *thd, Rows_log_event* event); |
|
316 |
||
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
317 |
#endif /* !defined(DRIZZLE_CLIENT) */ |
1
by brian
clean slate |
318 |
void reset_bytes_written() |
319 |
{
|
|
320 |
bytes_written = 0; |
|
321 |
}
|
|
151
by Brian Aker
Ulonglong to uint64_t |
322 |
void harvest_bytes_written(uint64_t* counter) |
1
by brian
clean slate |
323 |
{
|
324 |
(*counter)+=bytes_written; |
|
325 |
bytes_written=0; |
|
51.1.30
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
326 |
return; |
1
by brian
clean slate |
327 |
}
|
328 |
void set_max_size(ulong max_size_arg); |
|
329 |
void signal_update(); |
|
330 |
void wait_for_update_relay_log(THD* thd); |
|
331 |
int wait_for_update_bin_log(THD* thd, const struct timespec * timeout); |
|
332 |
void set_need_start_event() { need_start_event = 1; } |
|
333 |
void init(bool no_auto_events_arg, ulong max_size); |
|
334 |
void init_pthread_objects(); |
|
335 |
void cleanup(); |
|
336 |
bool open(const char *log_name, |
|
337 |
enum_log_type log_type, |
|
338 |
const char *new_name, |
|
339 |
enum cache_type io_cache_type_arg, |
|
340 |
bool no_auto_events_arg, ulong max_size, |
|
341 |
bool null_created); |
|
342 |
bool open_index_file(const char *index_file_name_arg, |
|
343 |
const char *log_name); |
|
344 |
/* Use this to start writing a new log file */
|
|
345 |
void new_file(); |
|
346 |
||
347 |
bool write(Log_event* event_info); // binary log write |
|
348 |
bool write(THD *thd, IO_CACHE *cache, Log_event *commit_event); |
|
349 |
||
350 |
int write_cache(IO_CACHE *cache, bool lock_log, bool flush_and_sync); |
|
351 |
||
352 |
void start_union_events(THD *thd, query_id_t query_id_param); |
|
353 |
void stop_union_events(THD *thd); |
|
354 |
bool is_query_in_union(THD *thd, query_id_t query_id_param); |
|
355 |
||
356 |
/*
|
|
357 |
v stands for vector
|
|
358 |
invoked as appendv(buf1,len1,buf2,len2,...,bufn,lenn,0)
|
|
359 |
*/
|
|
360 |
bool appendv(const char* buf,uint len,...); |
|
361 |
bool append(Log_event* ev); |
|
362 |
||
363 |
void make_log_name(char* buf, const char* log_ident); |
|
364 |
bool is_active(const char* log_file_name); |
|
365 |
int update_log_index(LOG_INFO* linfo, bool need_update_threads); |
|
366 |
void rotate_and_purge(uint flags); |
|
367 |
bool flush_and_sync(); |
|
368 |
int purge_logs(const char *to_log, bool included, |
|
369 |
bool need_mutex, bool need_update_threads, |
|
151
by Brian Aker
Ulonglong to uint64_t |
370 |
uint64_t *decrease_log_space); |
1
by brian
clean slate |
371 |
int purge_logs_before_date(time_t purge_time); |
372 |
int purge_first_log(Relay_log_info* rli, bool included); |
|
373 |
bool reset_logs(THD* thd); |
|
374 |
void close(uint exiting); |
|
375 |
||
376 |
// iterating through the log index file
|
|
377 |
int find_log_pos(LOG_INFO* linfo, const char* log_name, |
|
378 |
bool need_mutex); |
|
379 |
int find_next_log(LOG_INFO* linfo, bool need_mutex); |
|
380 |
int get_current_log(LOG_INFO* linfo); |
|
381 |
int raw_get_current_log(LOG_INFO* linfo); |
|
382 |
uint next_file_id(); |
|
383 |
inline char* get_index_fname() { return index_file_name;} |
|
384 |
inline char* get_log_fname() { return log_file_name; } |
|
385 |
inline char* get_name() { return name; } |
|
386 |
inline pthread_mutex_t* get_log_lock() { return &LOCK_log; } |
|
387 |
inline IO_CACHE* get_log_file() { return &log_file; } |
|
388 |
||
389 |
inline void lock_index() { pthread_mutex_lock(&LOCK_index);} |
|
390 |
inline void unlock_index() { pthread_mutex_unlock(&LOCK_index);} |
|
391 |
inline IO_CACHE *get_index_file() { return &index_file;} |
|
205
by Brian Aker
uint32 -> uin32_t |
392 |
inline uint32_t get_open_count() { return open_count; } |
1
by brian
clean slate |
393 |
};
|
394 |
||
395 |
class Log_event_handler |
|
396 |
{
|
|
397 |
public: |
|
398 |
Log_event_handler() {} |
|
399 |
virtual bool init()= 0; |
|
400 |
virtual void cleanup()= 0; |
|
401 |
||
402 |
virtual bool log_slow(THD *thd, time_t current_time, |
|
403 |
time_t query_start_arg, const char *user_host, |
|
151
by Brian Aker
Ulonglong to uint64_t |
404 |
uint user_host_len, uint64_t query_utime, |
405 |
uint64_t lock_utime, bool is_command, |
|
1
by brian
clean slate |
406 |
const char *sql_text, uint sql_text_len)= 0; |
407 |
virtual bool log_error(enum loglevel level, const char *format, |
|
408 |
va_list args)= 0; |
|
409 |
virtual bool log_general(THD *thd, time_t event_time, const char *user_host, |
|
410 |
uint user_host_len, int thread_id, |
|
411 |
const char *command_type, uint command_type_len, |
|
412 |
const char *sql_text, uint sql_text_len, |
|
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
413 |
const CHARSET_INFO * const client_cs)= 0; |
1
by brian
clean slate |
414 |
virtual ~Log_event_handler() {} |
415 |
};
|
|
416 |
||
417 |
||
418 |
/* type of the log table */
|
|
419 |
#define QUERY_LOG_SLOW 1
|
|
420 |
#define QUERY_LOG_GENERAL 2
|
|
421 |
||
422 |
class Log_to_file_event_handler: public Log_event_handler |
|
423 |
{
|
|
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
424 |
DRIZZLE_QUERY_LOG mysql_log; |
425 |
DRIZZLE_QUERY_LOG mysql_slow_log; |
|
1
by brian
clean slate |
426 |
bool is_initialized; |
427 |
public: |
|
51.1.30
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
428 |
Log_to_file_event_handler(): is_initialized(false) |
1
by brian
clean slate |
429 |
{}
|
430 |
virtual bool init(); |
|
431 |
virtual void cleanup(); |
|
432 |
||
433 |
virtual bool log_slow(THD *thd, time_t current_time, |
|
434 |
time_t query_start_arg, const char *user_host, |
|
151
by Brian Aker
Ulonglong to uint64_t |
435 |
uint user_host_len, uint64_t query_utime, |
436 |
uint64_t lock_utime, bool is_command, |
|
1
by brian
clean slate |
437 |
const char *sql_text, uint sql_text_len); |
438 |
virtual bool log_error(enum loglevel level, const char *format, |
|
439 |
va_list args); |
|
440 |
virtual bool log_general(THD *thd, time_t event_time, const char *user_host, |
|
441 |
uint user_host_len, int thread_id, |
|
442 |
const char *command_type, uint command_type_len, |
|
443 |
const char *sql_text, uint sql_text_len, |
|
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
444 |
const CHARSET_INFO * const client_cs); |
1
by brian
clean slate |
445 |
void flush(); |
446 |
void init_pthread_objects(); |
|
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
447 |
DRIZZLE_QUERY_LOG *get_mysql_slow_log() { return &mysql_slow_log; } |
448 |
DRIZZLE_QUERY_LOG *get_mysql_log() { return &mysql_log; } |
|
1
by brian
clean slate |
449 |
};
|
450 |
||
451 |
||
452 |
/* Class which manages slow, general and error log event handlers */
|
|
453 |
class LOGGER |
|
454 |
{
|
|
455 |
rw_lock_t LOCK_logger; |
|
456 |
/* flag to check whether logger mutex is initialized */
|
|
457 |
uint inited; |
|
458 |
||
459 |
/* available log handlers */
|
|
460 |
Log_to_file_event_handler *file_log_handler; |
|
461 |
||
462 |
/* NULL-terminated arrays of log handlers */
|
|
463 |
Log_event_handler *error_log_handler_list[MAX_LOG_HANDLERS_NUM + 1]; |
|
464 |
Log_event_handler *slow_log_handler_list[MAX_LOG_HANDLERS_NUM + 1]; |
|
465 |
Log_event_handler *general_log_handler_list[MAX_LOG_HANDLERS_NUM + 1]; |
|
466 |
||
467 |
public: |
|
468 |
||
469 |
LOGGER() : inited(0), file_log_handler(NULL) |
|
470 |
{}
|
|
471 |
void lock_shared() { rw_rdlock(&LOCK_logger); } |
|
472 |
void lock_exclusive() { rw_wrlock(&LOCK_logger); } |
|
473 |
void unlock() { rw_unlock(&LOCK_logger); } |
|
474 |
bool log_command(THD *thd, enum enum_server_command command); |
|
475 |
||
476 |
/*
|
|
477 |
We want to initialize all log mutexes as soon as possible,
|
|
478 |
but we cannot do it in constructor, as safe_mutex relies on
|
|
479 |
initialization, performed by MY_INIT(). This why this is done in
|
|
480 |
this function.
|
|
481 |
*/
|
|
482 |
void init_base(); |
|
483 |
bool flush_logs(THD *thd); |
|
484 |
/* Perform basic logger cleanup. this will leave e.g. error log open. */
|
|
485 |
void cleanup_base(); |
|
486 |
/* Free memory. Nothing could be logged after this function is called */
|
|
487 |
void cleanup_end(); |
|
488 |
bool error_log_print(enum loglevel level, const char *format, |
|
489 |
va_list args); |
|
490 |
bool slow_log_print(THD *thd, const char *query, uint query_length, |
|
151
by Brian Aker
Ulonglong to uint64_t |
491 |
uint64_t current_utime); |
1
by brian
clean slate |
492 |
bool general_log_print(THD *thd,enum enum_server_command command, |
493 |
const char *format, va_list args); |
|
494 |
bool general_log_write(THD *thd, enum enum_server_command command, |
|
495 |
const char *query, uint query_length); |
|
496 |
||
497 |
/* we use this function to setup all enabled log event handlers */
|
|
498 |
int set_handlers(uint error_log_printer, |
|
499 |
uint slow_log_printer, |
|
500 |
uint general_log_printer); |
|
501 |
void init_error_log(uint error_log_printer); |
|
502 |
void init_slow_log(uint slow_log_printer); |
|
503 |
void init_general_log(uint general_log_printer); |
|
504 |
void deactivate_log_handler(THD* thd, uint log_type); |
|
505 |
bool activate_log_handler(THD* thd, uint log_type); |
|
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
506 |
DRIZZLE_QUERY_LOG *get_slow_log_file_handler() |
1
by brian
clean slate |
507 |
{
|
508 |
if (file_log_handler) |
|
509 |
return file_log_handler->get_mysql_slow_log(); |
|
510 |
return NULL; |
|
511 |
}
|
|
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
512 |
DRIZZLE_QUERY_LOG *get_log_file_handler() |
1
by brian
clean slate |
513 |
{
|
514 |
if (file_log_handler) |
|
515 |
return file_log_handler->get_mysql_log(); |
|
516 |
return NULL; |
|
517 |
}
|
|
518 |
};
|
|
519 |
||
520 |
enum enum_binlog_format { |
|
521 |
/*
|
|
522 |
statement-based except for cases where only row-based can work (UUID()
|
|
523 |
etc):
|
|
524 |
*/
|
|
525 |
BINLOG_FORMAT_MIXED= 0, |
|
526 |
BINLOG_FORMAT_STMT= 1, // statement-based |
|
527 |
BINLOG_FORMAT_ROW= 2, // row_based |
|
528 |
/*
|
|
529 |
This value is last, after the end of binlog_format_typelib: it has no
|
|
530 |
corresponding cell in this typelib. We use this value to be able to know if
|
|
531 |
the user has explicitely specified a binlog format at startup or not.
|
|
532 |
*/
|
|
533 |
BINLOG_FORMAT_UNSPEC= 3 |
|
534 |
};
|
|
535 |
extern TYPELIB binlog_format_typelib; |
|
536 |
||
243.1.5
by Jay Pipes
* Pulled the remainder of the log and parse stuff out into |
537 |
int vprint_msg_to_log(enum loglevel level, const char *format, va_list args); |
538 |
void sql_print_error(const char *format, ...) __attribute__((format(printf, 1, 2))); |
|
539 |
void sql_print_warning(const char *format, ...) __attribute__((format(printf, 1, 2))); |
|
540 |
void sql_print_information(const char *format, ...) |
|
541 |
__attribute__((format(printf, 1, 2))); |
|
542 |
typedef void (*sql_print_message_func)(const char *format, ...) |
|
543 |
__attribute__((format(printf, 1, 2))); |
|
544 |
extern sql_print_message_func sql_print_message_handlers[]; |
|
545 |
||
546 |
int error_log_print(enum loglevel level, const char *format, |
|
547 |
va_list args); |
|
548 |
||
549 |
bool slow_log_print(THD *thd, const char *query, uint query_length, |
|
550 |
uint64_t current_utime); |
|
551 |
||
552 |
bool general_log_print(THD *thd, enum enum_server_command command, |
|
553 |
const char *format,...); |
|
554 |
||
555 |
bool general_log_write(THD *thd, enum enum_server_command command, |
|
556 |
const char *query, uint query_length); |
|
557 |
||
558 |
#endif /* DRIZZLE_SERVER_LOG_H */ |