The world's most popular open source database
#include "mysql_priv.h"#include "sql_repl.h"#include "rpl_filter.h"#include <my_dir.h>#include <stdarg.h>#include <m_ctype.h>#include <mysql/plugin.h>Include dependency graph for log.cc:

Go to the source code of this file.
Classes | |
| struct | binlog_trx_data |
Defines | |
| #define | MAX_LOG_BUFFER_SIZE 1024 |
| #define | MAX_USER_HOST_SIZE 512 |
| #define | MAX_TIME_SIZE 32 |
| #define | TC_LOG_BINLOG MYSQL_BIN_LOG |
Functions | |
| static bool | test_if_number (const char *str, long *res, bool allow_wildcards) |
| static int | binlog_init () |
| static int | binlog_close_connection (THD *thd) |
| static int | binlog_savepoint_set (THD *thd, void *sv) |
| static int | binlog_savepoint_rollback (THD *thd, void *sv) |
| static int | binlog_commit (THD *thd, bool all) |
| static int | binlog_rollback (THD *thd, bool all) |
| static int | binlog_prepare (THD *thd, bool all) |
| char * | make_default_log_name (char *buff, const char *log_ext) |
| static int | binlog_end_trans (THD *thd, binlog_trx_data *trx_data, Log_event *end_ev) |
| int | check_binlog_magic (IO_CACHE *log, const char **errmsg) |
| File | open_binlog (IO_CACHE *log, const char *log_file_name, const char **errmsg) |
| static int | find_uniq_filename (char *name) |
| static bool | copy_up_file_and_fill (IO_CACHE *index_file, my_off_t offset) |
| int | error_log_print (enum loglevel level, const char *format, va_list args) |
| bool | slow_log_print (THD *thd, const char *query, uint query_length, time_t query_start_arg) |
| bool | general_log_print (THD *thd, enum enum_server_command command, const char *format,...) |
| static bool | test_if_number (register const char *str, long *res, bool allow_wildcards) |
| void | print_buffer_to_file (enum loglevel level, const char *buffer) |
| void | sql_perror (const char *message) |
| bool | flush_error_log () |
| int | vprint_msg_to_log (enum loglevel level, const char *format, va_list args) |
| void | sql_print_error (const char *format,...) |
| void | sql_print_warning (const char *format,...) |
| void | sql_print_information (const char *format,...) |
| mysql_declare_plugin (binlog) | |
Variables | |
| LOGGER | logger |
| MYSQL_BIN_LOG | mysql_bin_log |
| ulong | sync_binlog_counter = 0 |
| static Muted_query_log_event | invisible_commit |
| sql_print_message_func | sql_print_message_handlers [3] |
| handlerton | binlog_hton |
| ulong | tc_log_page_waits = 0 |
| TC_LOG * | tc_log |
| TC_LOG_DUMMY | tc_log_dummy |
| TC_LOG_MMAP | tc_log_mmap |
| st_mysql_storage_engine | binlog_storage_engine |
| mysql_declare_plugin_end | |
| #define MAX_LOG_BUFFER_SIZE 1024 |
| #define MAX_TIME_SIZE 32 |
| #define MAX_USER_HOST_SIZE 512 |
Definition at line 37 of file log.cc.
Referenced by LOGGER::general_log_print(), and LOGGER::slow_log_print().
| #define TC_LOG_BINLOG MYSQL_BIN_LOG |
| static int binlog_close_connection | ( | THD * | thd | ) | [static] |
Definition at line 1174 of file log.cc.
References binlog_hton, close_cached_file(), DBUG_ASSERT, binlog_trx_data::empty(), MYSQL_LOG::is_open(), my_free, MYF, mysql_bin_log, handlerton::slot, and binlog_trx_data::trans_log.
Referenced by binlog_init().
01175 { 01176 binlog_trx_data *const trx_data= 01177 (binlog_trx_data*) thd->ha_data[binlog_hton.slot]; 01178 IO_CACHE *trans_log= &trx_data->trans_log; 01179 DBUG_ASSERT(mysql_bin_log.is_open() && trx_data->empty()); 01180 close_cached_file(trans_log); 01181 thd->ha_data[binlog_hton.slot]= 0; 01182 my_free((gptr)trx_data, MYF(0)); 01183 return 0; 01184 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static int binlog_commit | ( | THD * | thd, | |
| bool | all | |||
| ) | [static] |
Definition at line 1252 of file log.cc.
References binlog_end_trans(), binlog_hton, DBUG_ASSERT, DBUG_ENTER, DBUG_RETURN, binlog_trx_data::empty(), Query_log_event::error_code, FALSE, invisible_commit, MYSQL_LOG::is_open(), mysql_bin_log, OPTION_BEGIN, OPTION_NOT_AUTOCOMMIT, handlerton::slot, STRING_WITH_LEN, binlog_trx_data::trans_log, and TRUE.
Referenced by binlog_init().
01253 { 01254 DBUG_ENTER("binlog_commit"); 01255 binlog_trx_data *const trx_data= 01256 (binlog_trx_data*) thd->ha_data[binlog_hton.slot]; 01257 IO_CACHE *trans_log= &trx_data->trans_log; 01258 DBUG_ASSERT(mysql_bin_log.is_open() && 01259 (all || !(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))); 01260 01261 if (trx_data->empty()) 01262 { 01263 // we're here because trans_log was flushed in MYSQL_BIN_LOG::log() 01264 DBUG_RETURN(0); 01265 } 01266 if (all) 01267 { 01268 Query_log_event qev(thd, STRING_WITH_LEN("COMMIT"), TRUE, FALSE); 01269 qev.error_code= 0; // see comment in MYSQL_LOG::write(THD, IO_CACHE) 01270 DBUG_RETURN(binlog_end_trans(thd, trx_data, &qev)); 01271 } 01272 else 01273 DBUG_RETURN(binlog_end_trans(thd, trx_data, &invisible_commit)); 01274 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static int binlog_end_trans | ( | THD * | thd, | |
| binlog_trx_data * | trx_data, | |||
| Log_event * | end_ev | |||
| ) | [static] |
Definition at line 1187 of file log.cc.
References binlog_cache_disk_use, binlog_cache_use, DBUG_ENTER, DBUG_RETURN, st_io_cache::disk_writes, st_io_cache::end_of_file, error, LOCK_status, max_binlog_cache_size, mysql_bin_log, NULL, reinit_io_cache(), statistic_increment, binlog_trx_data::trans_log, TRUE, MYSQL_BIN_LOG::update_table_map_version(), MYSQL_BIN_LOG::write(), and WRITE_CACHE.
Referenced by binlog_commit(), and binlog_rollback().
01188 { 01189 DBUG_ENTER("binlog_end_trans"); 01190 int error=0; 01191 IO_CACHE *trans_log= &trx_data->trans_log; 01192 01193 01194 /* NULL denotes ROLLBACK with nothing to replicate */ 01195 if (end_ev != NULL) 01196 { 01197 /* 01198 We can always end the statement when ending a transaction since 01199 transactions are not allowed inside stored functions. If they 01200 were, we would have to ensure that we're not ending a statement 01201 inside a stored function. 01202 */ 01203 #ifdef HAVE_ROW_BASED_REPLICATION 01204 thd->binlog_flush_pending_rows_event(TRUE); 01205 #endif 01206 error= mysql_bin_log.write(thd, trans_log, end_ev); 01207 } 01208 #ifdef HAVE_ROW_BASED_REPLICATION 01209 else 01210 { 01211 #ifdef HAVE_ROW_BASED_REPLICATION 01212 thd->binlog_delete_pending_rows_event(); 01213 #endif 01214 } 01215 01216 /* 01217 We need to step the table map version both after writing the 01218 entire transaction to the log file and after rolling back the 01219 transaction. 01220 01221 We need to step the table map version after writing the 01222 transaction cache to disk. In addition, we need to step the table 01223 map version on a rollback to ensure that a new table map event is 01224 generated instead of the one that was written to the thrown-away 01225 transaction cache. 01226 */ 01227 mysql_bin_log.update_table_map_version(); 01228 #endif 01229 01230 statistic_increment(binlog_cache_use, &LOCK_status); 01231 if (trans_log->disk_writes != 0) 01232 { 01233 statistic_increment(binlog_cache_disk_use, &LOCK_status); 01234 trans_log->disk_writes= 0; 01235 } 01236 reinit_io_cache(trans_log, WRITE_CACHE, (my_off_t) 0, 0, 1); // cannot fail 01237 trans_log->end_of_file= max_binlog_cache_size; 01238 DBUG_RETURN(error); 01239 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int binlog_init | ( | ) | [static] |
Definition at line 1158 of file log.cc.
References binlog_close_connection(), binlog_commit(), binlog_hton, binlog_prepare(), binlog_rollback(), binlog_savepoint_rollback(), binlog_savepoint_set(), handlerton::close_connection, handlerton::commit, handlerton::db_type, DB_TYPE_BINLOG, handlerton::flags, HTON_HIDDEN, HTON_NOT_USER_SELECTABLE, opt_bin_log, handlerton::prepare, handlerton::rollback, handlerton::savepoint_offset, handlerton::savepoint_rollback, handlerton::savepoint_set, SHOW_OPTION_NO, SHOW_OPTION_YES, and handlerton::state.
Referenced by mysql_declare_plugin().
01159 { 01160 01161 binlog_hton.state=opt_bin_log ? SHOW_OPTION_YES : SHOW_OPTION_NO; 01162 binlog_hton.db_type=DB_TYPE_BINLOG; 01163 binlog_hton.savepoint_offset= sizeof(my_off_t); 01164 binlog_hton.close_connection= binlog_close_connection; 01165 binlog_hton.savepoint_set= binlog_savepoint_set; 01166 binlog_hton.savepoint_rollback= binlog_savepoint_rollback; 01167 binlog_hton.commit= binlog_commit; 01168 binlog_hton.rollback= binlog_rollback; 01169 binlog_hton.prepare= binlog_prepare; 01170 binlog_hton.flags= HTON_NOT_USER_SELECTABLE | HTON_HIDDEN; 01171 return 0; 01172 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static int binlog_prepare | ( | THD * | thd, | |
| bool | all | |||
| ) | [static] |
Definition at line 1241 of file log.cc.
Referenced by binlog_init().
01242 { 01243 /* 01244 do nothing. 01245 just pretend we can do 2pc, so that MySQL won't 01246 switch to 1pc. 01247 real work will be done in MYSQL_BIN_LOG::log() 01248 */ 01249 return 0; 01250 }
Here is the caller graph for this function:

| static int binlog_rollback | ( | THD * | thd, | |
| bool | all | |||
| ) | [static] |
Definition at line 1276 of file log.cc.
References binlog_end_trans(), binlog_hton, DBUG_ASSERT, DBUG_ENTER, DBUG_RETURN, binlog_trx_data::empty(), error, Query_log_event::error_code, FALSE, MYSQL_LOG::is_open(), mysql_bin_log, OPTION_BEGIN, OPTION_KEEP_LOG, OPTION_NOT_AUTOCOMMIT, OPTION_STATUS_NO_TRANS_UPDATE, handlerton::slot, STRING_WITH_LEN, binlog_trx_data::trans_log, TRUE, and unlikely.
Referenced by binlog_init().
01277 { 01278 DBUG_ENTER("binlog_rollback"); 01279 int error=0; 01280 binlog_trx_data *const trx_data= 01281 (binlog_trx_data*) thd->ha_data[binlog_hton.slot]; 01282 IO_CACHE *trans_log= &trx_data->trans_log; 01283 /* 01284 First assert is guaranteed - see trans_register_ha() call below. 01285 The second must be true. If it is not, we're registering 01286 unnecessary, doing extra work. The cause should be found and eliminated 01287 */ 01288 DBUG_ASSERT(all || !(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))); 01289 DBUG_ASSERT(mysql_bin_log.is_open() && !trx_data->empty()); 01290 /* 01291 Update the binary log with a BEGIN/ROLLBACK block if we have 01292 cached some queries and we updated some non-transactional 01293 table. Such cases should be rare (updating a 01294 non-transactional table inside a transaction...) 01295 */ 01296 if (unlikely(thd->options & (OPTION_STATUS_NO_TRANS_UPDATE | 01297 OPTION_KEEP_LOG))) 01298 { 01299 Query_log_event qev(thd, STRING_WITH_LEN("ROLLBACK"), TRUE, FALSE); 01300 qev.error_code= 0; // see comment in MYSQL_LOG::write(THD, IO_CACHE) 01301 error= binlog_end_trans(thd, trx_data, &qev); 01302 } 01303 else 01304 error= binlog_end_trans(thd, trx_data, 0); 01305 DBUG_RETURN(error); 01306 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static int binlog_savepoint_rollback | ( | THD * | thd, | |
| void * | sv | |||
| ) | [static] |
Definition at line 1345 of file log.cc.
References binlog_hton, DBUG_ASSERT, DBUG_ENTER, DBUG_RETURN, error, FALSE, MYSQL_LOG::is_open(), my_b_tell, mysql_bin_log, OPTION_KEEP_LOG, OPTION_STATUS_NO_TRANS_UPDATE, reinit_io_cache(), handlerton::slot, binlog_trx_data::trans_log, TRUE, unlikely, and WRITE_CACHE.
Referenced by binlog_init().
01346 { 01347 DBUG_ENTER("binlog_savepoint_rollback"); 01348 binlog_trx_data *const trx_data= 01349 (binlog_trx_data*) thd->ha_data[binlog_hton.slot]; 01350 IO_CACHE *trans_log= &trx_data->trans_log; 01351 DBUG_ASSERT(mysql_bin_log.is_open() && my_b_tell(trans_log)); 01352 01353 /* 01354 Write ROLLBACK TO SAVEPOINT to the binlog cache if we have updated some 01355 non-transactional table. Otherwise, truncate the binlog cache starting 01356 from the SAVEPOINT command. 01357 */ 01358 if (unlikely(thd->options & 01359 (OPTION_STATUS_NO_TRANS_UPDATE | OPTION_KEEP_LOG))) 01360 { 01361 int const error= 01362 thd->binlog_query(THD::STMT_QUERY_TYPE, 01363 thd->query, thd->query_length, TRUE, FALSE); 01364 DBUG_RETURN(error); 01365 } 01366 reinit_io_cache(trans_log, WRITE_CACHE, *(my_off_t *)sv, 0, 0); 01367 DBUG_RETURN(0); 01368 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static int binlog_savepoint_set | ( | THD * | thd, | |
| void * | sv | |||
| ) | [static] |
Definition at line 1329 of file log.cc.
References binlog_hton, DBUG_ASSERT, DBUG_ENTER, DBUG_RETURN, error, FALSE, MYSQL_LOG::is_open(), my_b_tell, mysql_bin_log, handlerton::slot, binlog_trx_data::trans_log, and TRUE.
Referenced by binlog_init().
01330 { 01331 DBUG_ENTER("binlog_savepoint_set"); 01332 binlog_trx_data *const trx_data= 01333 (binlog_trx_data*) thd->ha_data[binlog_hton.slot]; 01334 DBUG_ASSERT(mysql_bin_log.is_open() && my_b_tell(&trx_data->trans_log)); 01335 01336 *(my_off_t *)sv= my_b_tell(&trx_data->trans_log); 01337 /* Write it to the binary log */ 01338 01339 int const error= 01340 thd->binlog_query(THD::STMT_QUERY_TYPE, 01341 thd->query, thd->query_length, TRUE, FALSE); 01342 DBUG_RETURN(error); 01343 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int check_binlog_magic | ( | IO_CACHE * | log, | |
| const char ** | errmsg | |||
| ) |
Definition at line 1370 of file log.cc.
References BINLOG_MAGIC, DBUG_ASSERT, log(), memcmp(), my_b_read, my_b_tell, my_errno, and sql_print_error().
Referenced by open_binlog().
01371 { 01372 char magic[4]; 01373 DBUG_ASSERT(my_b_tell(log) == 0); 01374 01375 if (my_b_read(log, (byte*) magic, sizeof(magic))) 01376 { 01377 *errmsg = "I/O error reading the header from the binary log"; 01378 sql_print_error("%s, errno=%d, io cache code=%d", *errmsg, my_errno, 01379 log->error); 01380 return 1; 01381 } 01382 if (memcmp(magic, BINLOG_MAGIC, sizeof(magic))) 01383 { 01384 *errmsg = "Binlog has bad magic number; It's not a binary log file that can be used by this version of MySQL"; 01385 return 1; 01386 } 01387 return 0; 01388 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2292 of file log.cc.
References DBUG_ENTER, DBUG_RETURN, err, st_io_cache::file, IO_SIZE, my_chsize(), MY_NABP, my_read, my_seek(), MY_SEEK_SET, my_sync(), MY_WME, my_write, MYF, READ_CACHE, and reinit_io_cache().
02293 { 02294 int bytes_read; 02295 my_off_t init_offset= offset; 02296 File file= index_file->file; 02297 byte io_buf[IO_SIZE*2]; 02298 DBUG_ENTER("copy_up_file_and_fill"); 02299 02300 for (;; offset+= bytes_read) 02301 { 02302 (void) my_seek(file, offset, MY_SEEK_SET, MYF(0)); 02303 if ((bytes_read= (int) my_read(file, io_buf, sizeof(io_buf), MYF(MY_WME))) 02304 < 0) 02305 goto err; 02306 if (!bytes_read) 02307 break; // end of file 02308 (void) my_seek(file, offset-init_offset, MY_SEEK_SET, MYF(0)); 02309 if (my_write(file, (byte*) io_buf, bytes_read, MYF(MY_WME | MY_NABP))) 02310 goto err; 02311 } 02312 /* The following will either truncate the file or fill the end with \n' */ 02313 if (my_chsize(file, offset - init_offset, '\n', MYF(MY_WME)) || 02314 my_sync(file, MYF(MY_WME))) 02315 goto err; 02316 02317 /* Reset data in old index cache */ 02318 reinit_io_cache(index_file, READ_CACHE, (my_off_t) 0, 0, 1); 02319 DBUG_RETURN(0); 02320 02321 err: 02322 DBUG_RETURN(1); 02323 }
Here is the call graph for this function:

| int error_log_print | ( | enum loglevel | level, | |
| const char * | format, | |||
| va_list | args | |||
| ) |
Definition at line 3454 of file log.cc.
References LOGGER::error_log_print(), and logger.
03456 { 03457 return logger.error_log_print(level, format, args); 03458 }
Here is the call graph for this function:

| static int find_uniq_filename | ( | char * | name | ) | [static] |
Definition at line 1468 of file log.cc.
References bcmp, DBUG_ENTER, DBUG_RETURN, st_my_dir::dir_entry, dirname_part(), FN_REFLEN, my_dir(), my_dirend(), MY_DONT_SORT, MYF, fileinfo::name, st_my_dir::number_off_files, reg1, set_if_bigger, start(), strend(), strmov(), and test_if_number().
Referenced by MYSQL_LOG::generate_new_name().
01469 { 01470 long number; 01471 uint i; 01472 char buff[FN_REFLEN]; 01473 struct st_my_dir *dir_info; 01474 reg1 struct fileinfo *file_info; 01475 ulong max_found=0; 01476 01477 DBUG_ENTER("find_uniq_filename"); 01478 01479 uint length = dirname_part(buff,name); 01480 char *start = name + length; 01481 char *end = strend(start); 01482 01483 *end='.'; 01484 length= (uint) (end-start+1); 01485 01486 if (!(dir_info = my_dir(buff,MYF(MY_DONT_SORT)))) 01487 { // This shouldn't happen 01488 strmov(end,".1"); // use name+1 01489 DBUG_RETURN(0); 01490 } 01491 file_info= dir_info->dir_entry; 01492 for (i=dir_info->number_off_files ; i-- ; file_info++) 01493 { 01494 if (bcmp(file_info->name,start,length) == 0 && 01495 test_if_number(file_info->name+length, &number,0)) 01496 { 01497 set_if_bigger(max_found,(ulong) number); 01498 } 01499 } 01500 my_dirend(dir_info); 01501 01502 *end++='.'; 01503 sprintf(end,"%06ld",max_found+1); 01504 DBUG_RETURN(0); 01505 }
Here is the call graph for this function:

Here is the caller graph for this function:

| bool flush_error_log | ( | ) |
Definition at line 3841 of file log.cc.
References buf, FN_REFLEN, IO_SIZE, LOCK_error_log, log_error_file, my_close(), my_delete(), my_fwrite(), my_open(), my_read, my_rename(), MYF, NullS, opt_error_log, pthread_mutex_lock, pthread_mutex_unlock, strmake(), strmov(), strxmov(), and VOID.
Referenced by reload_acl_and_cache().
03842 { 03843 bool result=0; 03844 if (opt_error_log) 03845 { 03846 char err_renamed[FN_REFLEN], *end; 03847 end= strmake(err_renamed,log_error_file,FN_REFLEN-4); 03848 strmov(end, "-old"); 03849 VOID(pthread_mutex_lock(&LOCK_error_log)); 03850 #ifdef __WIN__ 03851 char err_temp[FN_REFLEN+4]; 03852 /* 03853 On Windows is necessary a temporary file for to rename 03854 the current error file. 03855 */ 03856 strxmov(err_temp, err_renamed,"-tmp",NullS); 03857 (void) my_delete(err_temp, MYF(0)); 03858 if (freopen(err_temp,"a+",stdout)) 03859 { 03860 freopen(err_temp,"a+",stderr); 03861 (void) my_delete(err_renamed, MYF(0)); 03862 my_rename(log_error_file,err_renamed,MYF(0)); 03863 if (freopen(log_error_file,"a+",stdout)) 03864 freopen(log_error_file,"a+",stderr); 03865 int fd, bytes; 03866 char buf[IO_SIZE]; 03867 if ((fd = my_open(err_temp, O_RDONLY, MYF(0))) >= 0) 03868 { 03869 while ((bytes = (int) my_read(fd, (byte*) buf, IO_SIZE, MYF(0))) > 0) 03870 my_fwrite(stderr, (byte*) buf, bytes, MYF(0)); 03871 my_close(fd, MYF(0)); 03872 } 03873 (void) my_delete(err_temp, MYF(0)); 03874 } 03875 else 03876 result= 1; 03877 #else 03878 my_rename(log_error_file,err_renamed,MYF(0)); 03879 if (freopen(log_error_file,"a+",stdout)) 03880 freopen(log_error_file,"a+",stderr); 03881 else 03882 result= 1; 03883 #endif 03884 VOID(pthread_mutex_unlock(&LOCK_error_log)); 03885 } 03886 return result; 03887 }
Here is the call graph for this function:

Here is the caller graph for this function:

| bool general_log_print | ( | THD * | thd, | |
| enum enum_server_command | command, | |||
| const char * | format, | |||
| ... | ||||
| ) |
Definition at line 3468 of file log.cc.
References args, LOGGER::general_log_print(), and logger.
03470 { 03471 va_list args; 03472 uint error= 0; 03473 03474 va_start(args, format); 03475 error= logger.general_log_print(thd, command, format, args); 03476 va_end(args); 03477 03478 return error; 03479 }
Here is the call graph for this function:


