1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
20
#ifndef DRIZZLE_SERVER_LOG_H
21
#define DRIZZLE_SERVER_LOG_H
23
#include <mysys/iocache.h>
1
/* Copyright (C) 2005 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
25
19
class Relay_log_info;
201
193
friend class Log_event;
204
class DRIZZLE_BIN_LOG: public TC_LOG, private DRIZZLE_LOG
196
class MYSQL_QUERY_LOG: public MYSQL_LOG
199
MYSQL_QUERY_LOG() : last_time(0) {}
201
bool write(time_t event_time, const char *user_host,
202
uint user_host_len, int thread_id,
203
const char *command_type, uint command_type_len,
204
const char *sql_text, uint sql_text_len);
205
bool write(THD *thd, time_t current_time, time_t query_start_arg,
206
const char *user_host, uint user_host_len,
207
ulonglong query_utime, ulonglong lock_utime, bool is_command,
208
const char *sql_text, uint sql_text_len);
209
bool open_slow_log(const char *log_name)
212
return open(generate_name(log_name, "-slow.log", 0, buf), LOG_NORMAL, 0,
215
bool open_query_log(const char *log_name)
218
return open(generate_name(log_name, ".log", 0, buf), LOG_NORMAL, 0,
226
class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG
207
229
/* LOCK_log and LOCK_index are inited by init_pthread_objects() */
263
285
Format_description_log_event *description_event_for_exec,
264
286
*description_event_for_queue;
268
note that there's no destructor ~DRIZZLE_BIN_LOG() !
290
note that there's no destructor ~MYSQL_BIN_LOG() !
269
291
The reason is that we don't want it to be automatically called
270
292
on exit() - but only during the correct shutdown process
273
295
int open(const char *opt_name);
275
int log_xid(Session *session, my_xid xid);
297
int log_xid(THD *thd, my_xid xid);
276
298
void unlog(ulong cookie, my_xid xid);
277
299
int recover(IO_CACHE *log, Format_description_log_event *fdle);
278
bool is_table_mapped(Table *table) const
300
#if !defined(MYSQL_CLIENT)
301
bool is_table_mapped(TABLE *table) const
280
303
return table->s->table_map_version == table_map_version();
283
uint64_t table_map_version() const { return m_table_map_version; }
306
ulonglong table_map_version() const { return m_table_map_version; }
284
307
void update_table_map_version() { ++m_table_map_version; }
286
int flush_and_set_pending_rows_event(Session *session, Rows_log_event* event);
309
int flush_and_set_pending_rows_event(THD *thd, Rows_log_event* event);
311
#endif /* !defined(MYSQL_CLIENT) */
288
312
void reset_bytes_written()
290
314
bytes_written = 0;
292
void harvest_bytes_written(uint64_t* counter)
316
void harvest_bytes_written(ulonglong* counter)
319
char buf1[22],buf2[22];
321
DBUG_ENTER("harvest_bytes_written");
294
322
(*counter)+=bytes_written;
323
DBUG_PRINT("info",("counter: %s bytes_written: %s", llstr(*counter,buf1),
324
llstr(bytes_written,buf2)));
298
328
void set_max_size(ulong max_size_arg);
299
329
void signal_update();
300
void wait_for_update_relay_log(Session* session);
301
int wait_for_update_bin_log(Session* session, const struct timespec * timeout);
330
void wait_for_update_relay_log(THD* thd);
331
int wait_for_update_bin_log(THD* thd, const struct timespec * timeout);
302
332
void set_need_start_event() { need_start_event = 1; }
303
333
void init(bool no_auto_events_arg, ulong max_size);
304
334
void init_pthread_objects();
317
347
bool write(Log_event* event_info); // binary log write
318
bool write(Session *session, IO_CACHE *cache, Log_event *commit_event);
348
bool write(THD *thd, IO_CACHE *cache, Log_event *commit_event);
320
350
int write_cache(IO_CACHE *cache, bool lock_log, bool flush_and_sync);
322
void start_union_events(Session *session, query_id_t query_id_param);
323
void stop_union_events(Session *session);
324
bool is_query_in_union(Session *session, query_id_t query_id_param);
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);
327
357
v stands for vector
328
358
invoked as appendv(buf1,len1,buf2,len2,...,bufn,lenn,0)
330
bool appendv(const char* buf,uint32_t len,...);
360
bool appendv(const char* buf,uint len,...);
331
361
bool append(Log_event* ev);
333
363
void make_log_name(char* buf, const char* log_ident);
334
364
bool is_active(const char* log_file_name);
335
365
int update_log_index(LOG_INFO* linfo, bool need_update_threads);
336
void rotate_and_purge(uint32_t flags);
366
void rotate_and_purge(uint flags);
337
367
bool flush_and_sync();
338
368
int purge_logs(const char *to_log, bool included,
339
369
bool need_mutex, bool need_update_threads,
340
uint64_t *decrease_log_space);
370
ulonglong *decrease_log_space);
341
371
int purge_logs_before_date(time_t purge_time);
342
372
int purge_first_log(Relay_log_info* rli, bool included);
343
bool reset_logs(Session* session);
344
void close(uint32_t exiting);
373
bool reset_logs(THD* thd);
374
void close(uint exiting);
346
376
// iterating through the log index file
347
377
int find_log_pos(LOG_INFO* linfo, const char* log_name,
369
399
virtual bool init()= 0;
370
400
virtual void cleanup()= 0;
402
virtual bool log_slow(THD *thd, time_t current_time,
403
time_t query_start_arg, const char *user_host,
404
uint user_host_len, ulonglong query_utime,
405
ulonglong lock_utime, bool is_command,
406
const char *sql_text, uint sql_text_len)= 0;
372
407
virtual bool log_error(enum loglevel level, const char *format,
373
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,
413
CHARSET_INFO *client_cs)= 0;
374
414
virtual ~Log_event_handler() {}
418
/* type of the log table */
419
#define QUERY_LOG_SLOW 1
420
#define QUERY_LOG_GENERAL 2
422
class Log_to_file_event_handler: public Log_event_handler
424
MYSQL_QUERY_LOG mysql_log;
425
MYSQL_QUERY_LOG mysql_slow_log;
428
Log_to_file_event_handler(): is_initialized(FALSE)
431
virtual void cleanup();
433
virtual bool log_slow(THD *thd, time_t current_time,
434
time_t query_start_arg, const char *user_host,
435
uint user_host_len, ulonglong query_utime,
436
ulonglong lock_utime, bool is_command,
437
const char *sql_text, uint sql_text_len);
438
virtual bool log_error(enum loglevel level, const char *format,
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,
444
CHARSET_INFO *client_cs);
446
void init_pthread_objects();
447
MYSQL_QUERY_LOG *get_mysql_slow_log() { return &mysql_slow_log; }
448
MYSQL_QUERY_LOG *get_mysql_log() { return &mysql_log; }
378
452
/* Class which manages slow, general and error log event handlers */
381
455
rw_lock_t LOCK_logger;
382
456
/* flag to check whether logger mutex is initialized */
459
/* available log handlers */
460
Log_to_file_event_handler *file_log_handler;
385
462
/* NULL-terminated arrays of log handlers */
386
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];
469
LOGGER() : inited(0), file_log_handler(NULL)
392
471
void lock_shared() { rw_rdlock(&LOCK_logger); }
393
472
void lock_exclusive() { rw_wrlock(&LOCK_logger); }
394
473
void unlock() { rw_unlock(&LOCK_logger); }
395
bool log_command(Session *session, enum enum_server_command command);
474
bool is_log_table_enabled(uint log_table_type);
475
bool log_command(THD *thd, enum enum_server_command command);
398
478
We want to initialize all log mutexes as soon as possible,
403
483
void init_base();
404
bool flush_logs(Session *session);
484
bool flush_logs(THD *thd);
405
485
/* Perform basic logger cleanup. this will leave e.g. error log open. */
406
486
void cleanup_base();
407
487
/* Free memory. Nothing could be logged after this function is called */
408
488
void cleanup_end();
409
489
bool error_log_print(enum loglevel level, const char *format,
491
bool slow_log_print(THD *thd, const char *query, uint query_length,
492
ulonglong current_utime);
493
bool general_log_print(THD *thd,enum enum_server_command command,
494
const char *format, va_list args);
495
bool general_log_write(THD *thd, enum enum_server_command command,
496
const char *query, uint query_length);
411
498
/* we use this function to setup all enabled log event handlers */
412
int set_handlers(uint32_t error_log_printer);
413
void init_error_log(uint32_t error_log_printer);
499
int set_handlers(uint error_log_printer,
500
uint slow_log_printer,
501
uint general_log_printer);
502
void init_error_log(uint error_log_printer);
503
void init_slow_log(uint slow_log_printer);
504
void init_general_log(uint general_log_printer);
505
void deactivate_log_handler(THD* thd, uint log_type);
506
bool activate_log_handler(THD* thd, uint log_type);
507
MYSQL_QUERY_LOG *get_slow_log_file_handler()
509
if (file_log_handler)
510
return file_log_handler->get_mysql_slow_log();
513
MYSQL_QUERY_LOG *get_log_file_handler()
515
if (file_log_handler)
516
return file_log_handler->get_mysql_log();
416
521
enum enum_binlog_format {
431
536
extern TYPELIB binlog_format_typelib;
433
int vprint_msg_to_log(enum loglevel level, const char *format, va_list args);
434
void sql_print_error(const char *format, ...) __attribute__((format(printf, 1, 2)));
435
void sql_print_warning(const char *format, ...) __attribute__((format(printf, 1, 2)));
436
void sql_print_information(const char *format, ...)
437
__attribute__((format(printf, 1, 2)));
438
typedef void (*sql_print_message_func)(const char *format, ...)
439
__attribute__((format(printf, 1, 2)));
440
extern sql_print_message_func sql_print_message_handlers[];
442
int error_log_print(enum loglevel level, const char *format,
445
void sql_perror(const char *message);
448
#endif /* DRIZZLE_SERVER_LOG_H */