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 <drizzled/common.h>
24
#include <mysys/iocache.h>
25
#include <drizzled/xid.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 */
28
19
class Relay_log_info;
30
21
class Format_description_log_event;
202
196
friend class Log_event;
205
class DRIZZLE_BIN_LOG: public TC_LOG, private DRIZZLE_LOG
199
class MYSQL_QUERY_LOG: public MYSQL_LOG
202
MYSQL_QUERY_LOG() : last_time(0) {}
204
bool write(time_t event_time, const char *user_host,
205
uint user_host_len, int thread_id,
206
const char *command_type, uint command_type_len,
207
const char *sql_text, uint sql_text_len);
208
bool write(THD *thd, time_t current_time, time_t query_start_arg,
209
const char *user_host, uint user_host_len,
210
uint64_t query_utime, uint64_t lock_utime, bool is_command,
211
const char *sql_text, uint sql_text_len);
212
bool open_slow_log(const char *log_name)
215
return open(generate_name(log_name, "-slow.log", 0, buf), LOG_NORMAL, 0,
218
bool open_query_log(const char *log_name)
221
return open(generate_name(log_name, ".log", 0, buf), LOG_NORMAL, 0,
229
class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG
208
232
/* LOCK_log and LOCK_index are inited by init_pthread_objects() */
264
288
Format_description_log_event *description_event_for_exec,
265
289
*description_event_for_queue;
269
note that there's no destructor ~DRIZZLE_BIN_LOG() !
293
note that there's no destructor ~MYSQL_BIN_LOG() !
270
294
The reason is that we don't want it to be automatically called
271
295
on exit() - but only during the correct shutdown process
274
298
int open(const char *opt_name);
276
int log_xid(Session *session, my_xid xid);
300
int log_xid(THD *thd, my_xid xid);
277
301
void unlog(ulong cookie, my_xid xid);
278
302
int recover(IO_CACHE *log, Format_description_log_event *fdle);
279
bool is_table_mapped(Table *table) const;
303
#if !defined(MYSQL_CLIENT)
304
bool is_table_mapped(TABLE *table) const
306
return table->s->table_map_version == table_map_version();
281
309
uint64_t table_map_version() const { return m_table_map_version; }
282
310
void update_table_map_version() { ++m_table_map_version; }
284
int flush_and_set_pending_rows_event(Session *session, Rows_log_event* event);
312
int flush_and_set_pending_rows_event(THD *thd, Rows_log_event* event);
314
#endif /* !defined(MYSQL_CLIENT) */
286
315
void reset_bytes_written()
288
317
bytes_written = 0;
315
344
bool write(Log_event* event_info); // binary log write
316
bool write(Session *session, IO_CACHE *cache, Log_event *commit_event);
345
bool write(THD *thd, IO_CACHE *cache, Log_event *commit_event);
318
347
int write_cache(IO_CACHE *cache, bool lock_log, bool flush_and_sync);
320
void start_union_events(Session *session, query_id_t query_id_param);
321
void stop_union_events(Session *session);
322
bool is_query_in_union(Session *session, query_id_t query_id_param);
349
void start_union_events(THD *thd, query_id_t query_id_param);
350
void stop_union_events(THD *thd);
351
bool is_query_in_union(THD *thd, query_id_t query_id_param);
325
354
v stands for vector
326
355
invoked as appendv(buf1,len1,buf2,len2,...,bufn,lenn,0)
328
bool appendv(const char* buf,uint32_t len,...);
357
bool appendv(const char* buf,uint len,...);
329
358
bool append(Log_event* ev);
331
360
void make_log_name(char* buf, const char* log_ident);
332
361
bool is_active(const char* log_file_name);
333
362
int update_log_index(LOG_INFO* linfo, bool need_update_threads);
334
void rotate_and_purge(uint32_t flags);
363
void rotate_and_purge(uint flags);
335
364
bool flush_and_sync();
336
365
int purge_logs(const char *to_log, bool included,
337
366
bool need_mutex, bool need_update_threads,
338
367
uint64_t *decrease_log_space);
339
368
int purge_logs_before_date(time_t purge_time);
340
369
int purge_first_log(Relay_log_info* rli, bool included);
341
bool reset_logs(Session* session);
342
void close(uint32_t exiting);
370
bool reset_logs(THD* thd);
371
void close(uint exiting);
344
373
// iterating through the log index file
345
374
int find_log_pos(LOG_INFO* linfo, const char* log_name,
372
396
virtual bool init()= 0;
373
397
virtual void cleanup()= 0;
399
virtual bool log_slow(THD *thd, time_t current_time,
400
time_t query_start_arg, const char *user_host,
401
uint user_host_len, uint64_t query_utime,
402
uint64_t lock_utime, bool is_command,
403
const char *sql_text, uint sql_text_len)= 0;
375
404
virtual bool log_error(enum loglevel level, const char *format,
376
405
va_list args)= 0;
406
virtual bool log_general(THD *thd, time_t event_time, const char *user_host,
407
uint user_host_len, int thread_id,
408
const char *command_type, uint command_type_len,
409
const char *sql_text, uint sql_text_len,
410
CHARSET_INFO *client_cs)= 0;
377
411
virtual ~Log_event_handler() {}
415
/* type of the log table */
416
#define QUERY_LOG_SLOW 1
417
#define QUERY_LOG_GENERAL 2
419
class Log_to_file_event_handler: public Log_event_handler
421
MYSQL_QUERY_LOG mysql_log;
422
MYSQL_QUERY_LOG mysql_slow_log;
425
Log_to_file_event_handler(): is_initialized(false)
428
virtual void cleanup();
430
virtual bool log_slow(THD *thd, time_t current_time,
431
time_t query_start_arg, const char *user_host,
432
uint user_host_len, uint64_t query_utime,
433
uint64_t lock_utime, bool is_command,
434
const char *sql_text, uint sql_text_len);
435
virtual bool log_error(enum loglevel level, const char *format,
437
virtual bool log_general(THD *thd, time_t event_time, const char *user_host,
438
uint user_host_len, int thread_id,
439
const char *command_type, uint command_type_len,
440
const char *sql_text, uint sql_text_len,
441
CHARSET_INFO *client_cs);
443
void init_pthread_objects();
444
MYSQL_QUERY_LOG *get_mysql_slow_log() { return &mysql_slow_log; }
445
MYSQL_QUERY_LOG *get_mysql_log() { return &mysql_log; }
449
/* Class which manages slow, general and error log event handlers */
452
rw_lock_t LOCK_logger;
453
/* flag to check whether logger mutex is initialized */
456
/* available log handlers */
457
Log_to_file_event_handler *file_log_handler;
459
/* NULL-terminated arrays of log handlers */
460
Log_event_handler *error_log_handler_list[MAX_LOG_HANDLERS_NUM + 1];
461
Log_event_handler *slow_log_handler_list[MAX_LOG_HANDLERS_NUM + 1];
462
Log_event_handler *general_log_handler_list[MAX_LOG_HANDLERS_NUM + 1];
466
LOGGER() : inited(0), file_log_handler(NULL)
468
void lock_shared() { rw_rdlock(&LOCK_logger); }
469
void lock_exclusive() { rw_wrlock(&LOCK_logger); }
470
void unlock() { rw_unlock(&LOCK_logger); }
471
bool log_command(THD *thd, enum enum_server_command command);
474
We want to initialize all log mutexes as soon as possible,
475
but we cannot do it in constructor, as safe_mutex relies on
476
initialization, performed by MY_INIT(). This why this is done in
480
bool flush_logs(THD *thd);
481
/* Perform basic logger cleanup. this will leave e.g. error log open. */
483
/* Free memory. Nothing could be logged after this function is called */
485
bool error_log_print(enum loglevel level, const char *format,
487
bool slow_log_print(THD *thd, const char *query, uint query_length,
488
uint64_t current_utime);
489
bool general_log_print(THD *thd,enum enum_server_command command,
490
const char *format, va_list args);
491
bool general_log_write(THD *thd, enum enum_server_command command,
492
const char *query, uint query_length);
494
/* we use this function to setup all enabled log event handlers */
495
int set_handlers(uint error_log_printer,
496
uint slow_log_printer,
497
uint general_log_printer);
498
void init_error_log(uint error_log_printer);
499
void init_slow_log(uint slow_log_printer);
500
void init_general_log(uint general_log_printer);
501
void deactivate_log_handler(THD* thd, uint log_type);
502
bool activate_log_handler(THD* thd, uint log_type);
503
MYSQL_QUERY_LOG *get_slow_log_file_handler()
505
if (file_log_handler)
506
return file_log_handler->get_mysql_slow_log();
509
MYSQL_QUERY_LOG *get_log_file_handler()
511
if (file_log_handler)
512
return file_log_handler->get_mysql_log();
517
enum enum_binlog_format {
519
statement-based except for cases where only row-based can work (UUID()
522
BINLOG_FORMAT_MIXED= 0,
523
BINLOG_FORMAT_STMT= 1, // statement-based
524
BINLOG_FORMAT_ROW= 2, // row_based
526
This value is last, after the end of binlog_format_typelib: it has no
527
corresponding cell in this typelib. We use this value to be able to know if
528
the user has explicitely specified a binlog format at startup or not.
530
BINLOG_FORMAT_UNSPEC= 3
380
532
extern TYPELIB binlog_format_typelib;
382
void sql_print_error(const char *format, ...) __attribute__((format(printf, 1, 2)));
383
void sql_print_warning(const char *format, ...) __attribute__((format(printf, 1, 2)));
384
void sql_print_information(const char *format, ...)
385
__attribute__((format(printf, 1, 2)));
386
typedef void (*sql_print_message_func)(const char *format, ...)
387
__attribute__((format(printf, 1, 2)));
388
extern sql_print_message_func sql_print_message_handlers[];
390
void sql_perror(const char *message);
393
#endif /* DRIZZLE_SERVER_LOG_H */