61 virtual int open(
const char *opt_name)=0;
62 virtual void close()=0;
77 virtual enum_result
commit(THD *thd,
bool all) = 0;
93 virtual int rollback(THD *thd,
bool all) = 0;
104 virtual int prepare(THD *thd,
bool all) = 0;
112 int open(
const char *opt_name) {
return 0; }
115 return ha_commit_low(thd, all) ? RESULT_ABORTED : RESULT_SUCCESS;
118 return ha_rollback_low(thd, all);
121 return ha_prepare_low(thd, all);
126 class TC_LOG_MMAP:
public TC_LOG
136 typedef struct st_page {
137 struct st_page *next;
147 char logname[FN_REFLEN];
149 my_off_t file_length;
152 struct st_page *pages, *syncing, *active, *pool, *pool_last;
163 TC_LOG_MMAP(): inited(0) {}
164 int open(
const char *opt_name);
166 enum_result
commit(THD *thd,
bool all);
167 int rollback(THD *thd,
bool all) {
return ha_rollback_low(thd, all); }
168 int prepare(THD *thd,
bool all) {
return ha_prepare_low(thd, all); }
172 int log_xid(THD *thd, my_xid xid);
173 int unlog(ulong cookie, my_xid xid);
174 void get_active_from_pool();
179 #define TC_LOG_MMAP TC_LOG_DUMMY
183 extern TC_LOG_MMAP tc_log_mmap;
187 #define LOG_INFO_EOF -1
188 #define LOG_INFO_IO -2
189 #define LOG_INFO_INVALID -3
190 #define LOG_INFO_SEEK -4
191 #define LOG_INFO_MEM -6
192 #define LOG_INFO_FATAL -7
193 #define LOG_INFO_IN_USE -8
194 #define LOG_INFO_EMFILE -9
198 #define LOG_CLOSE_INDEX 1
199 #define LOG_CLOSE_TO_BE_OPENED 2
200 #define LOG_CLOSE_STOP_EVENT 4
207 #define MAX_LOG_UNIQUE_FN_EXT 0x7FFFFFFF
213 #define LOG_WARN_UNIQUE_FN_EXT_LEFT 1000
215 #ifdef HAVE_PSI_INTERFACE
216 extern PSI_mutex_key key_LOG_INFO_lock;
226 char log_file_name[FN_REFLEN];
227 my_off_t index_file_offset, index_file_start_offset;
233 : index_file_offset(0), index_file_start_offset(0),
234 pos(0), fatal(0), entry_index(0)
236 log_file_name[0] =
'\0';
246 #define MAX_LOG_HANDLERS_NUM 3
253 enum enum_log_type { LOG_UNKNOWN, LOG_NORMAL, LOG_BIN };
254 enum enum_log_state { LOG_OPENED, LOG_CLOSED, LOG_TO_BE_OPENED };
265 void init_pthread_objects();
268 #ifdef HAVE_PSI_INTERFACE
269 PSI_file_key log_file_key,
271 const char *log_name,
272 enum_log_type log_type,
273 const char *new_name,
274 enum cache_type io_cache_type_arg);
275 bool init_and_set_log_file_name(
const char *log_name,
276 const char *new_name,
277 enum_log_type log_type_arg,
278 enum cache_type io_cache_type_arg);
279 void init(enum_log_type log_type_arg,
280 enum cache_type io_cache_type_arg);
281 void close(uint exiting);
282 inline bool is_open() {
return log_state != LOG_CLOSED; }
283 const char *
generate_name(
const char *log_name,
const char *suffix,
284 bool strip_ext,
char *buff);
285 int generate_new_name(
char *new_name,
const char *log_name);
290 char log_file_name[FN_REFLEN];
291 char time_buff[20], db[NAME_LEN + 1];
292 bool write_error, inited;
294 enum_log_type log_type;
295 volatile enum_log_state log_state;
296 enum cache_type io_cache_type;
298 #ifdef HAVE_PSI_INTERFACE
300 PSI_file_key m_log_file_key;
302 PSI_mutex_key m_key_LOCK_log;
307 enum enum_general_log_table_field
309 GLT_FIELD_EVENT_TIME = 0,
313 GLT_FIELD_COMMAND_TYPE,
319 enum enum_slow_query_log_table_field
321 SQLT_FIELD_START_TIME = 0,
322 SQLT_FIELD_USER_HOST,
323 SQLT_FIELD_QUERY_TIME,
324 SQLT_FIELD_LOCK_TIME,
325 SQLT_FIELD_ROWS_SENT,
326 SQLT_FIELD_ROWS_EXAMINED,
328 SQLT_FIELD_LAST_INSERT_ID,
329 SQLT_FIELD_INSERT_ID,
330 SQLT_FIELD_SERVER_ID,
332 SQLT_FIELD_THREAD_ID,
342 bool write(time_t event_time,
const char *user_host,
343 uint user_host_len, my_thread_id thread_id,
344 const char *command_type, uint command_type_len,
345 const char *sql_text, uint sql_text_len);
346 bool write(THD *thd, time_t current_time, time_t query_start_arg,
347 const char *user_host, uint user_host_len,
348 ulonglong query_utime, ulonglong lock_utime,
bool is_command,
349 const char *sql_text, uint sql_text_len);
350 bool open_slow_log(
const char *log_name)
354 #ifdef HAVE_PSI_INTERFACE
358 LOG_NORMAL, 0, WRITE_CACHE);
360 bool open_query_log(
const char *log_name)
364 #ifdef HAVE_PSI_INTERFACE
368 LOG_NORMAL, 0, WRITE_CACHE);
379 virtual bool init()= 0;
380 virtual void cleanup()= 0;
382 virtual bool log_slow(THD *thd, time_t current_time,
383 time_t query_start_arg,
const char *user_host,
384 uint user_host_len, ulonglong query_utime,
385 ulonglong lock_utime,
bool is_command,
386 const char *sql_text, uint sql_text_len)= 0;
387 virtual bool log_error(
enum loglevel
level,
const char *format,
389 virtual bool log_general(THD *thd, time_t event_time,
const char *user_host,
390 uint user_host_len, my_thread_id thread_id,
391 const char *command_type, uint command_type_len,
392 const char *sql_text, uint sql_text_len,
398 int check_if_log_table(
size_t db_len,
const char *db,
size_t table_name_len,
399 const char *
table_name,
bool check_if_opened);
407 virtual void cleanup();
409 virtual bool log_slow(THD *thd, time_t current_time,
410 time_t query_start_arg,
const char *user_host,
411 uint user_host_len, ulonglong query_utime,
412 ulonglong lock_utime,
bool is_command,
413 const char *sql_text, uint sql_text_len);
414 virtual bool log_error(
enum loglevel
level,
const char *format,
416 virtual bool log_general(THD *thd, time_t event_time,
const char *user_host,
417 uint user_host_len, my_thread_id thread_id,
418 const char *command_type, uint command_type_len,
419 const char *sql_text, uint sql_text_len,
422 int activate_log(THD *thd, uint log_type);
427 #define QUERY_LOG_SLOW 1
428 #define QUERY_LOG_GENERAL 2
439 virtual void cleanup();
441 virtual bool log_slow(THD *thd, time_t current_time,
442 time_t query_start_arg,
const char *user_host,
443 uint user_host_len, ulonglong query_utime,
444 ulonglong lock_utime,
bool is_command,
445 const char *sql_text, uint sql_text_len);
446 virtual bool log_error(
enum loglevel
level,
const char *format,
448 virtual bool log_general(THD *thd, time_t event_time,
const char *user_host,
449 uint user_host_len, my_thread_id thread_id,
450 const char *command_type, uint command_type_len,
451 const char *sql_text, uint sql_text_len,
454 void init_pthread_objects();
478 bool is_log_tables_initialized;
480 LOGGER() : inited(0), table_log_handler(NULL),
481 file_log_handler(NULL), is_log_tables_initialized(FALSE)
486 bool is_log_table_enabled(uint log_table_type);
487 bool log_command(THD *thd,
enum enum_server_command command);
496 void init_log_tables();
497 bool flush_logs(THD *thd);
504 bool error_log_print(
enum loglevel
level,
const char *format,
506 bool slow_log_print(THD *thd,
const char *
query, uint query_length);
507 bool general_log_print(THD *thd,
enum enum_server_command command,
508 const char *format, va_list args);
509 bool general_log_write(THD *thd,
enum enum_server_command command,
510 const char *query, uint query_length);
513 int set_handlers(uint error_log_printer,
514 uint slow_log_printer,
515 uint general_log_printer);
516 void init_error_log(uint error_log_printer);
517 void init_slow_log(uint slow_log_printer);
518 void init_general_log(uint general_log_printer);
519 void deactivate_log_handler(THD* thd, uint log_type);
520 bool activate_log_handler(THD* thd, uint log_type);
523 if (file_log_handler)
524 return file_log_handler->get_mysql_slow_log();
529 if (file_log_handler)
530 return file_log_handler->get_mysql_log();
535 enum enum_binlog_row_image {
537 BINLOG_ROW_IMAGE_MINIMAL= 0,
539 BINLOG_ROW_IMAGE_NOBLOB= 1,
541 BINLOG_ROW_IMAGE_FULL= 2
544 enum enum_binlog_format {
545 BINLOG_FORMAT_MIXED= 0,
546 BINLOG_FORMAT_STMT= 1,
547 BINLOG_FORMAT_ROW= 2,
548 BINLOG_FORMAT_UNSPEC=3
551 int query_error_code(THD *thd,
bool not_killed);
555 void sql_print_error(
const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
556 void sql_print_warning(const
char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
557 void sql_print_information(const
char *format, ...)
558 ATTRIBUTE_FORMAT(printf, 1, 2);
559 typedef
void (*sql_print_message_func)(const
char *format, ...)
560 ATTRIBUTE_FORMAT_FPTR(printf, 1, 2);
561 extern sql_print_message_func sql_print_message_handlers[];
563 int error_log_print(enum loglevel
level, const
char *format,
566 bool slow_log_print(THD *thd, const
char *
query, uint query_length);
568 bool general_log_print(THD *thd, enum enum_server_command command,
569 const
char *format,...);
571 bool general_log_write(THD *thd, enum enum_server_command command,
572 const
char *query, uint query_length);
574 void sql_perror(const
char *
message);
575 bool flush_error_log();