24
24
Abort logging when we get an error in reading or writing log files
27
#include <drizzled/server_includes.h>
27
#include "mysql_priv.h"
28
28
#include "sql_repl.h"
29
29
#include "rpl_filter.h"
30
30
#include "rpl_rli.h"
32
#include <mysys/my_dir.h>
33
33
#include <stdarg.h>
34
#include <m_ctype.h> // For test_if_number
35
#include <drizzled/plugin.h>
36
#include <drizzled/error.h>
37
#include <drizzled/gettext.h>
36
#include <mysql/plugin.h>
39
38
/* max size of the log message */
39
#define MAX_LOG_BUFFER_SIZE 1024
40
#define MAX_USER_HOST_SIZE 512
41
#define MAX_TIME_SIZE 32
40
42
#define MY_OFF_T_UNDEF (~(my_off_t)0UL)
44
#define FLAGSTR(V,F) ((V)&(F)?#F" ":"")
44
DRIZZLE_BIN_LOG mysql_bin_log;
48
MYSQL_BIN_LOG mysql_bin_log;
45
49
ulong sync_binlog_counter= 0;
47
51
static bool test_if_number(const char *str,
48
52
long *res, bool allow_wildcards);
49
53
static int binlog_init(void *p);
50
static int binlog_close_connection(handlerton *hton, Session *session);
51
static int binlog_savepoint_set(handlerton *hton, Session *session, void *sv);
52
static int binlog_savepoint_rollback(handlerton *hton, Session *session, void *sv);
53
static int binlog_commit(handlerton *hton, Session *session, bool all);
54
static int binlog_rollback(handlerton *hton, Session *session, bool all);
55
static int binlog_prepare(handlerton *hton, Session *session, bool all);
54
static int binlog_close_connection(handlerton *hton, THD *thd);
55
static int binlog_savepoint_set(handlerton *hton, THD *thd, void *sv);
56
static int binlog_savepoint_rollback(handlerton *hton, THD *thd, void *sv);
57
static int binlog_commit(handlerton *hton, THD *thd, bool all);
58
static int binlog_rollback(handlerton *hton, THD *thd, bool all);
59
static int binlog_prepare(handlerton *hton, THD *thd, bool all);
62
Silence all errors and warnings reported when performing a write
64
Errors and warnings are not reported to the client or SQL exception
65
handlers, so that the presence of logging does not interfere and affect
66
the logic of an application.
68
class Silence_log_table_errors : public Internal_error_handler
70
char m_message[MYSQL_ERRMSG_SIZE];
72
Silence_log_table_errors()
77
virtual ~Silence_log_table_errors() {}
79
virtual bool handle_error(uint sql_errno, const char *message,
80
MYSQL_ERROR::enum_warning_level level,
82
const char *message() const { return m_message; }
86
Silence_log_table_errors::handle_error(uint /* sql_errno */,
87
const char *message_arg,
88
MYSQL_ERROR::enum_warning_level /* level */,
91
strmake(m_message, message_arg, sizeof(m_message)-1);
58
96
sql_print_message_func sql_print_message_handlers[3] =
201
243
/* Check if a given table is opened log table */
202
int check_if_log_table(uint32_t db_len __attribute__((unused)),
203
const char *db __attribute__((unused)),
204
uint32_t table_name_len __attribute__((unused)),
205
const char *table_name __attribute__((unused)),
206
uint32_t check_if_opened __attribute__((unused)))
244
int check_if_log_table(uint db_len __attribute__((__unused__)),
245
const char *db __attribute__((__unused__)),
246
uint table_name_len __attribute__((__unused__)),
247
const char *table_name __attribute__((__unused__)),
248
uint check_if_opened __attribute__((__unused__)))
253
/* log event handlers */
255
bool Log_to_file_event_handler::
256
log_error(enum loglevel level, const char *format,
259
return vprint_msg_to_log(level, format, args);
262
void Log_to_file_event_handler::init_pthread_objects()
264
mysql_log.init_pthread_objects();
265
mysql_slow_log.init_pthread_objects();
269
/** Wrapper around MYSQL_LOG::write() for slow log. */
271
bool Log_to_file_event_handler::
272
log_slow(THD *thd, time_t current_time, time_t query_start_arg,
273
const char *user_host, uint user_host_len,
274
ulonglong query_utime, ulonglong lock_utime, bool is_command,
275
const char *sql_text, uint sql_text_len)
277
return mysql_slow_log.write(thd, current_time, query_start_arg,
278
user_host, user_host_len,
279
query_utime, lock_utime, is_command,
280
sql_text, sql_text_len);
285
Wrapper around MYSQL_LOG::write() for general log. We need it since we
286
want all log event handlers to have the same signature.
289
bool Log_to_file_event_handler::
290
log_general(THD *thd __attribute__((__unused__)),
291
time_t event_time, const char *user_host,
292
uint user_host_len, int thread_id,
293
const char *command_type, uint command_type_len,
294
const char *sql_text, uint sql_text_len,
295
CHARSET_INFO *client_cs __attribute__((__unused__)))
297
return mysql_log.write(event_time, user_host, user_host_len,
298
thread_id, command_type, command_type_len,
299
sql_text, sql_text_len);
303
bool Log_to_file_event_handler::init()
308
mysql_slow_log.open_slow_log(sys_var_slow_log_path.value);
311
mysql_log.open_query_log(sys_var_general_log_path.value);
313
is_initialized= TRUE;
320
void Log_to_file_event_handler::cleanup()
323
mysql_slow_log.cleanup();
326
void Log_to_file_event_handler::flush()
328
/* reopen log files */
330
mysql_log.reopen_file();
332
mysql_slow_log.reopen_file();
212
336
Log error with all enabled log event handlers
278
415
logger.lock_exclusive();
417
/* reopen log files */
418
file_log_handler->flush();
280
420
/* end of log flush */
285
void LOGGER::init_error_log(uint32_t error_log_printer)
427
Log slow query with all enabled log event handlers
432
thd THD of the query being logged
433
query The query being logged
434
query_length The length of the query string
435
current_utime Current time in microseconds (from undefined start)
442
bool LOGGER::slow_log_print(THD *thd, const char *query, uint query_length,
443
ulonglong current_utime)
447
Log_event_handler **current_handler;
448
bool is_command= FALSE;
449
char user_host_buff[MAX_USER_HOST_SIZE];
450
Security_context *sctx= thd->security_ctx;
451
uint user_host_len= 0;
452
ulonglong query_utime, lock_utime;
455
Print the message to the buffer if we have slow log enabled
458
if (*slow_log_handler_list)
462
/* do not log slow queries from replication threads */
463
if (thd->slave_thread && !opt_log_slow_slave_statements)
473
/* fill in user_host value: the format is "%s[%s] @ %s [%s]" */
474
user_host_len= (strxnmov(user_host_buff, MAX_USER_HOST_SIZE,
475
sctx->priv_user ? sctx->priv_user : "", "[",
476
sctx->user ? sctx->user : "", "] @ ",
477
sctx->host ? sctx->host : "", " [",
478
sctx->ip ? sctx->ip : "", "]", NullS) -
481
current_time= my_time_possible_from_micro(current_utime);
482
if (thd->start_utime)
484
query_utime= (current_utime - thd->start_utime);
485
lock_utime= (thd->utime_after_lock - thd->start_utime);
489
query_utime= lock_utime= 0;
495
query= command_name[thd->command].str;
496
query_length= command_name[thd->command].length;
499
for (current_handler= slow_log_handler_list; *current_handler ;)
500
error= (*current_handler++)->log_slow(thd, current_time, thd->start_time,
501
user_host_buff, user_host_len,
502
query_utime, lock_utime, is_command,
503
query, query_length) || error;
510
bool LOGGER::general_log_write(THD *thd, enum enum_server_command command,
511
const char *query, uint query_length)
514
Log_event_handler **current_handler= general_log_handler_list;
515
char user_host_buff[MAX_USER_HOST_SIZE];
516
Security_context *sctx= thd->security_ctx;
518
uint user_host_len= 0;
522
id= thd->thread_id; /* Normal thread */
524
id= 0; /* Log from connect handler */
532
user_host_len= strxnmov(user_host_buff, MAX_USER_HOST_SIZE,
533
sctx->priv_user ? sctx->priv_user : "", "[",
534
sctx->user ? sctx->user : "", "] @ ",
535
sctx->host ? sctx->host : "", " [",
536
sctx->ip ? sctx->ip : "", "]", NullS) -
539
current_time= my_time(0);
541
while (*current_handler)
542
error|= (*current_handler++)->
543
log_general(thd, current_time, user_host_buff,
545
command_name[(uint) command].str,
546
command_name[(uint) command].length,
548
thd->variables.character_set_client) || error;
554
bool LOGGER::general_log_print(THD *thd, enum enum_server_command command,
555
const char *format, va_list args)
557
uint message_buff_len= 0;
558
char message_buff[MAX_LOG_BUFFER_SIZE];
560
/* prepare message */
562
message_buff_len= vsnprintf(message_buff, sizeof(message_buff),
565
message_buff[0]= '\0';
567
return general_log_write(thd, command, message_buff, message_buff_len);
570
void LOGGER::init_error_log(uint error_log_printer)
287
572
if (error_log_printer & LOG_NONE)
295
int LOGGER::set_handlers(uint32_t error_log_printer)
578
switch (error_log_printer) {
580
error_log_handler_list[0]= file_log_handler;
581
error_log_handler_list[1]= 0;
583
/* these two are disabled for now */
587
case LOG_TABLE|LOG_FILE:
593
void LOGGER::init_slow_log(uint slow_log_printer)
595
if (slow_log_printer & LOG_NONE)
597
slow_log_handler_list[0]= 0;
601
slow_log_handler_list[0]= file_log_handler;
602
slow_log_handler_list[1]= 0;
605
void LOGGER::init_general_log(uint general_log_printer)
607
if (general_log_printer & LOG_NONE)
609
general_log_handler_list[0]= 0;
613
general_log_handler_list[0]= file_log_handler;
614
general_log_handler_list[1]= 0;
618
bool LOGGER::activate_log_handler(THD* thd __attribute__((__unused__)),
621
MYSQL_QUERY_LOG *file_log;
628
file_log= file_log_handler->get_mysql_slow_log();
630
file_log->open_slow_log(sys_var_slow_log_path.value);
631
init_slow_log(log_output_options);
635
case QUERY_LOG_GENERAL:
638
file_log= file_log_handler->get_mysql_log();
640
file_log->open_query_log(sys_var_general_log_path.value);
641
init_general_log(log_output_options);
653
void LOGGER::deactivate_log_handler(THD *thd __attribute__((__unused__)),
661
tmp_opt= &opt_slow_log;
662
file_log= file_log_handler->get_mysql_slow_log();
664
case QUERY_LOG_GENERAL:
666
file_log= file_log_handler->get_mysql_log();
669
assert(0); // Impossible
681
int LOGGER::set_handlers(uint error_log_printer,
682
uint slow_log_printer,
683
uint general_log_printer)
297
685
/* error log table is not supported yet */
686
DBUG_ASSERT(error_log_printer < LOG_TABLE);
298
688
lock_exclusive();
300
690
init_error_log(error_log_printer);
691
init_slow_log(slow_log_printer);
692
init_general_log(general_log_printer);
680
1099
that case there is no need to have it in the binlog).
683
static int binlog_savepoint_set(handlerton *hton __attribute__((unused)),
684
Session *session, void *sv)
1102
static int binlog_savepoint_set(handlerton *hton __attribute__((__unused__)),
686
binlog_trans_log_savepos(session, (my_off_t*) sv);
1105
DBUG_ENTER("binlog_savepoint_set");
1107
binlog_trans_log_savepos(thd, (my_off_t*) sv);
687
1108
/* Write it to the binary log */
689
1110
int const error=
690
session->binlog_query(Session::STMT_QUERY_TYPE,
691
session->query, session->query_length, true, false);
1111
thd->binlog_query(THD::STMT_QUERY_TYPE,
1112
thd->query, thd->query_length, TRUE, FALSE);
695
static int binlog_savepoint_rollback(handlerton *hton __attribute__((unused)),
696
Session *session, void *sv)
1116
static int binlog_savepoint_rollback(handlerton *hton __attribute__((__unused__)),
1119
DBUG_ENTER("binlog_savepoint_rollback");
699
1122
Write ROLLBACK TO SAVEPOINT to the binlog cache if we have updated some
700
1123
non-transactional table. Otherwise, truncate the binlog cache starting
701
1124
from the SAVEPOINT command.
703
if (unlikely(session->transaction.all.modified_non_trans_table ||
704
(session->options & OPTION_KEEP_LOG)))
1126
if (unlikely(thd->transaction.all.modified_non_trans_table ||
1127
(thd->options & OPTION_KEEP_LOG)))
707
session->binlog_query(Session::STMT_QUERY_TYPE,
708
session->query, session->query_length, true, false);
1130
thd->binlog_query(THD::STMT_QUERY_TYPE,
1131
thd->query, thd->query_length, TRUE, FALSE);
711
binlog_trans_log_truncate(session, *(my_off_t*)sv);
1134
binlog_trans_log_truncate(thd, *(my_off_t*)sv);
716
1139
int check_binlog_magic(IO_CACHE* log, const char** errmsg)
719
assert(my_b_tell(log) == 0);
1142
DBUG_ASSERT(my_b_tell(log) == 0);
721
if (my_b_read(log, (unsigned char*) magic, sizeof(magic)))
1144
if (my_b_read(log, (uchar*) magic, sizeof(magic)))
723
*errmsg = _("I/O error reading the header from the binary log");
1146
*errmsg = "I/O error reading the header from the binary log";
724
1147
sql_print_error("%s, errno=%d, io cache code=%d", *errmsg, my_errno,
728
1151
if (memcmp(magic, BINLOG_MAGIC, sizeof(magic)))
730
*errmsg = _("Binlog has bad magic number; It's not a binary log file "
731
"that can be used by this version of Drizzle");
1153
*errmsg = "Binlog has bad magic number; It's not a binary log file that can be used by this version of MySQL";
891
1319
int len=snprintf(buff, sizeof(buff), "%s, Version: %s (%s). "
892
1320
"started with:\nTCP Port: %d, Named Pipe: %s\n",
893
my_progname, server_version, COMPILATION_COMMENT,
1321
my_progname, server_version, MYSQL_COMPILATION_COMMENT,
896
end= my_stpncpy(buff + len, "Time Id Command Argument\n",
1324
end= strnmov(buff + len, "Time Id Command Argument\n",
897
1325
sizeof(buff) - len);
898
if (my_b_write(&log_file, (unsigned char*) buff, (uint) (end-buff)) ||
1326
if (my_b_write(&log_file, (uchar*) buff, (uint) (end-buff)) ||
899
1327
flush_io_cache(&log_file))
903
1331
log_state= LOG_OPENED;
907
sql_print_error(_("Could not use %s for logging (error %d). "
908
"Turning logging off for the whole duration of the "
909
"Drizzle server process. "
910
"To turn it on again: fix the cause, "
911
"shutdown the Drizzle server and restart it."),
1335
sql_print_error("Could not use %s for logging (error %d). \
1336
Turning logging off for the whole duration of the MySQL server process. \
1337
To turn it on again: fix the cause, \
1338
shutdown the MySQL server and restart it.", name, errno);
914
1340
my_close(file, MYF(0));
915
1341
end_io_cache(&log_file);
921
1343
log_state= LOG_CLOSED;
925
DRIZZLE_LOG::DRIZZLE_LOG()
926
: name(0), write_error(false), inited(false), log_type(LOG_UNKNOWN),
1347
MYSQL_LOG::MYSQL_LOG()
1348
: name(0), write_error(FALSE), inited(FALSE), log_type(LOG_UNKNOWN),
927
1349
log_state(LOG_CLOSED)
1447
Reopen the log file. The method is used during FLUSH LOGS
1448
and locks LOCK_log mutex
1452
void MYSQL_QUERY_LOG::reopen_file()
1456
DBUG_ENTER("MYSQL_LOG::reopen_file");
1459
DBUG_PRINT("info",("log is closed"));
1463
pthread_mutex_lock(&LOCK_log);
1466
name= 0; // Don't free name
1467
close(LOG_CLOSE_TO_BE_OPENED);
1470
Note that at this point, log_state != LOG_CLOSED (important for is_open()).
1473
open(save_name, log_type, 0, io_cache_type);
1474
my_free(save_name, MYF(0));
1476
pthread_mutex_unlock(&LOCK_log);
1483
Write a command to traditional general log file
1488
event_time command start timestamp
1489
user_host the pointer to the string with user@host info
1490
user_host_len length of the user_host string. this is computed once
1491
and passed to all general log event handlers
1492
thread_id Id of the thread, issued a query
1493
command_type the type of the command being logged
1494
command_type_len the length of the string above
1495
sql_text the very text of the query being executed
1496
sql_text_len the length of sql_text string
1500
Log given command to to normal (not rotable) log file
1504
TRUE - error occured
1507
bool MYSQL_QUERY_LOG::write(time_t event_time,
1508
const char *user_host __attribute__((__unused__)),
1509
uint user_host_len __attribute__((__unused__)),
1511
const char *command_type, uint command_type_len,
1512
const char *sql_text, uint sql_text_len)
1516
char local_time_buff[MAX_TIME_SIZE];
1518
uint time_buff_len= 0;
1520
(void) pthread_mutex_lock(&LOCK_log);
1522
/* Test if someone closed between the is_open test and lock */
1525
/* Note that my_b_write() assumes it knows the length for this */
1526
if (event_time != last_time)
1528
last_time= event_time;
1530
localtime_r(&event_time, &start);
1532
time_buff_len= snprintf(local_time_buff, MAX_TIME_SIZE,
1533
"%02d%02d%02d %2d:%02d:%02d",
1534
start.tm_year % 100, start.tm_mon + 1,
1535
start.tm_mday, start.tm_hour,
1536
start.tm_min, start.tm_sec);
1538
if (my_b_write(&log_file, (uchar*) local_time_buff, time_buff_len))
1542
if (my_b_write(&log_file, (uchar*) "\t\t" ,2) < 0)
1545
/* command_type, thread_id */
1546
length= snprintf(buff, 32, "%5ld ", (long) thread_id);
1548
if (my_b_write(&log_file, (uchar*) buff, length))
1551
if (my_b_write(&log_file, (uchar*) command_type, command_type_len))
1554
if (my_b_write(&log_file, (uchar*) "\t", 1))
1558
if (my_b_write(&log_file, (uchar*) sql_text, sql_text_len))
1561
if (my_b_write(&log_file, (uchar*) "\n", 1) ||
1562
flush_io_cache(&log_file))
1566
(void) pthread_mutex_unlock(&LOCK_log);
1573
sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno);
1575
(void) pthread_mutex_unlock(&LOCK_log);
1581
Log a query to the traditional slow log file
1586
thd THD of the query
1587
current_time current timestamp
1588
query_start_arg command start timestamp
1589
user_host the pointer to the string with user@host info
1590
user_host_len length of the user_host string. this is computed once
1591
and passed to all general log event handlers
1592
query_utime Amount of time the query took to execute (in microseconds)
1593
lock_utime Amount of time the query was locked (in microseconds)
1594
is_command The flag, which determines, whether the sql_text is a
1595
query or an administrator command.
1596
sql_text the very text of the query or administrator command
1598
sql_text_len the length of sql_text string
1602
Log a query to the slow log file.
1606
TRUE - error occured
1609
bool MYSQL_QUERY_LOG::write(THD *thd, time_t current_time,
1610
time_t query_start_arg __attribute__((__unused__)),
1611
const char *user_host,
1612
uint user_host_len, ulonglong query_utime,
1613
ulonglong lock_utime, bool is_command,
1614
const char *sql_text, uint sql_text_len)
1617
DBUG_ENTER("MYSQL_QUERY_LOG::write");
1619
(void) pthread_mutex_lock(&LOCK_log);
1623
(void) pthread_mutex_unlock(&LOCK_log);
1628
{ // Safety agains reopen
1630
char buff[80], *end;
1631
char query_time_buff[22+7], lock_time_buff[22+7];
1635
if (!(specialflag & SPECIAL_SHORT_LOG_FORMAT))
1637
if (current_time != last_time)
1639
last_time= current_time;
1641
localtime_r(¤t_time, &start);
1643
buff_len= snprintf(buff, sizeof buff,
1644
"# Time: %02d%02d%02d %2d:%02d:%02d\n",
1645
start.tm_year % 100, start.tm_mon + 1,
1646
start.tm_mday, start.tm_hour,
1647
start.tm_min, start.tm_sec);
1649
/* Note that my_b_write() assumes it knows the length for this */
1650
if (my_b_write(&log_file, (uchar*) buff, buff_len))
1653
const uchar uh[]= "# User@Host: ";
1654
if (my_b_write(&log_file, uh, sizeof(uh) - 1))
1656
if (my_b_write(&log_file, (uchar*) user_host, user_host_len))
1658
if (my_b_write(&log_file, (uchar*) "\n", 1))
1661
/* For slow query log */
1662
sprintf(query_time_buff, "%.6f", ulonglong2double(query_utime)/1000000.0);
1663
sprintf(lock_time_buff, "%.6f", ulonglong2double(lock_utime)/1000000.0);
1664
if (my_b_printf(&log_file,
1665
"# Query_time: %s Lock_time: %s"
1666
" Rows_sent: %lu Rows_examined: %lu\n",
1667
query_time_buff, lock_time_buff,
1668
(ulong) thd->sent_row_count,
1669
(ulong) thd->examined_row_count) == (uint) -1)
1671
if (thd->db && strcmp(thd->db, db))
1672
{ // Database changed
1673
if (my_b_printf(&log_file,"use %s;\n",thd->db) == (uint) -1)
1677
if (thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt)
1679
end=strmov(end, ",last_insert_id=");
1680
end=longlong10_to_str((longlong)
1681
thd->first_successful_insert_id_in_prev_stmt_for_binlog,
1684
// Save value if we do an insert.
1685
if (thd->auto_inc_intervals_in_cur_stmt_for_binlog.nb_elements() > 0)
1687
if (!(specialflag & SPECIAL_SHORT_LOG_FORMAT))
1689
end=strmov(end,",insert_id=");
1690
end=longlong10_to_str((longlong)
1691
thd->auto_inc_intervals_in_cur_stmt_for_binlog.minimum(),
1697
This info used to show up randomly, depending on whether the query
1698
checked the query start time or not. now we always write current
1699
timestamp to the slow log
1701
end= strmov(end, ",timestamp=");
1702
end= int10_to_str((long) current_time, end, 10);
1708
if (my_b_write(&log_file, (uchar*) "SET ", 4) ||
1709
my_b_write(&log_file, (uchar*) buff + 1, (uint) (end-buff)))
1714
end= strxmov(buff, "# administrator command: ", NullS);
1715
buff_len= (ulong) (end - buff);
1716
my_b_write(&log_file, (uchar*) buff, buff_len);
1718
if (my_b_write(&log_file, (uchar*) sql_text, sql_text_len) ||
1719
my_b_write(&log_file, (uchar*) ";\n",2) ||
1720
flush_io_cache(&log_file))
1728
sql_print_error(ER(ER_ERROR_ON_WRITE), name, error);
1732
(void) pthread_mutex_unlock(&LOCK_log);
1021
1739
The following should be using fn_format(); We just need to
1022
1740
first change fn_format() to cut the file name if it's too long.
1024
const char *DRIZZLE_LOG::generate_name(const char *log_name,
1742
const char *MYSQL_LOG::generate_name(const char *log_name,
1025
1743
const char *suffix,
1026
1744
bool strip_ext, char *buff)
2267
3017
We only update the saved position if the old one was undefined,
2268
3018
the reason is that there are some cases (e.g., for CREATE-SELECT)
2269
3019
where the position is saved twice (e.g., both in
2270
select_create::prepare() and Session::binlog_write_table_map()) , but
3020
select_create::prepare() and THD::binlog_write_table_map()) , but
2271
3021
we should use the first. This means that calls to this function
2272
3022
can be used to start the statement before the first table map
2273
3023
event, to include some extra events.
2277
Session::binlog_start_trans_and_stmt()
3027
THD::binlog_start_trans_and_stmt()
2279
binlog_trx_data *trx_data= (binlog_trx_data*) session_get_ha_data(this, binlog_hton);
3029
binlog_trx_data *trx_data= (binlog_trx_data*) thd_get_ha_data(this, binlog_hton);
3030
DBUG_ENTER("binlog_start_trans_and_stmt");
3031
DBUG_PRINT("enter", ("trx_data: 0x%lx trx_data->before_stmt_pos: %lu",
3033
(trx_data ? (ulong) trx_data->before_stmt_pos :
2281
3036
if (trx_data == NULL ||
2282
3037
trx_data->before_stmt_pos == MY_OFF_T_UNDEF)
2284
3039
this->binlog_set_stmt_begin();
2285
3040
if (options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
2286
trans_register_ha(this, true, binlog_hton);
2287
trans_register_ha(this, false, binlog_hton);
3041
trans_register_ha(this, TRUE, binlog_hton);
3042
trans_register_ha(this, FALSE, binlog_hton);
2289
3044
Mark statement transaction as read/write. We never start
2290
3045
a binary log transaction and keep it read-only,
2559
3327
If row-based binlogging, Insert_id, Rand and other kind of "setting
2560
3328
context" events are not needed.
2564
if (!session->current_stmt_binlog_row_based)
3332
if (!thd->current_stmt_binlog_row_based)
2566
if (session->stmt_depends_on_first_successful_insert_id_in_prev_stmt)
3334
if (thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt)
2568
Intvar_log_event e(session,(unsigned char) LAST_INSERT_ID_EVENT,
2569
session->first_successful_insert_id_in_prev_stmt_for_binlog);
3336
Intvar_log_event e(thd,(uchar) LAST_INSERT_ID_EVENT,
3337
thd->first_successful_insert_id_in_prev_stmt_for_binlog);
2570
3338
if (e.write(file))
2573
if (session->auto_inc_intervals_in_cur_stmt_for_binlog.nb_elements() > 0)
3341
if (thd->auto_inc_intervals_in_cur_stmt_for_binlog.nb_elements() > 0)
3343
DBUG_PRINT("info",("number of auto_inc intervals: %u",
3344
thd->auto_inc_intervals_in_cur_stmt_for_binlog.
2576
3347
If the auto_increment was second in a table's index (possible with
2577
3348
MyISAM or BDB) (table->next_number_keypart != 0), such event is
2578
3349
in fact not necessary. We could avoid logging it.
2580
Intvar_log_event e(session, (unsigned char) INSERT_ID_EVENT,
2581
session->auto_inc_intervals_in_cur_stmt_for_binlog.
3351
Intvar_log_event e(thd, (uchar) INSERT_ID_EVENT,
3352
thd->auto_inc_intervals_in_cur_stmt_for_binlog.
2583
3354
if (e.write(file))
2586
if (session->rand_used)
2588
Rand_log_event e(session,session->rand_saved_seed1,session->rand_saved_seed2);
3359
Rand_log_event e(thd,thd->rand_saved_seed1,thd->rand_saved_seed2);
2589
3360
if (e.write(file))
2592
if (session->user_var_events.elements)
3363
if (thd->user_var_events.elements)
2594
for (uint32_t i= 0; i < session->user_var_events.elements; i++)
3365
for (uint i= 0; i < thd->user_var_events.elements; i++)
2596
3367
BINLOG_USER_VAR_EVENT *user_var_event;
2597
get_dynamic(&session->user_var_events,(unsigned char*) &user_var_event, i);
2598
User_var_log_event e(session, user_var_event->user_var_event->name.str,
3368
get_dynamic(&thd->user_var_events,(uchar*) &user_var_event, i);
3369
User_var_log_event e(thd, user_var_event->user_var_event->name.str,
2599
3370
user_var_event->user_var_event->name.length,
2600
3371
user_var_event->value,
2601
3372
user_var_event->length,
3131
3979
char err_renamed[FN_REFLEN], *end;
3132
3980
end= strmake(err_renamed,log_error_file,FN_REFLEN-4);
3133
my_stpcpy(end, "-old");
3134
pthread_mutex_lock(&LOCK_error_log);
3981
strmov(end, "-old");
3982
VOID(pthread_mutex_lock(&LOCK_error_log));
3135
3983
char err_temp[FN_REFLEN+4];
3137
3985
On Windows is necessary a temporary file for to rename
3138
3986
the current error file.
3140
strxmov(err_temp, err_renamed,"-tmp",NULL);
3988
strxmov(err_temp, err_renamed,"-tmp",NullS);
3141
3989
(void) my_delete(err_temp, MYF(0));
3142
3990
if (freopen(err_temp,"a+",stdout))
3146
unsigned char buf[IO_SIZE];
3148
if(freopen(err_temp,"a+",stderr)==NULL)
3996
freopen(err_temp,"a+",stderr);
3150
3997
(void) my_delete(err_renamed, MYF(0));
3151
3998
my_rename(log_error_file,err_renamed,MYF(0));
3152
if (freopen(log_error_file,"a+",stdout)==NULL)
3155
if(freopen(log_error_file,"a+",stderr)==NULL)
3999
if (freopen(log_error_file,"a+",stdout))
4000
freopen(log_error_file,"a+",stderr);
3158
4002
if ((fd = my_open(err_temp, O_RDONLY, MYF(0))) >= 0)