Below is the list of changes that have just been committed into a local
5.1 repository of antony. When antony does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2007-03-23 11:47:27-07:00, acurtis@stripped +25 -0
Merge xiphis.org:/home/antony/work2/mysql-5.1-logging.4
into xiphis.org:/home/antony/work2/mysql-5.1-logging.5
Manual merge fixes
MERGE: 1.2409.96.1
libmysqld/lib_sql.cc@stripped, 2007-03-23 11:40:17-07:00, acurtis@stripped +0 -0
Auto merged
MERGE: 1.132.1.1
sql/Makefile.am@stripped, 2007-03-23 11:40:17-07:00, acurtis@stripped +0 -0
Auto merged
MERGE: 1.173.1.2
sql/event_scheduler.cc@stripped, 2007-03-23 11:40:17-07:00, acurtis@stripped +0 -0
Auto merged
MERGE: 1.31.1.2
sql/handler.cc@stripped, 2007-03-23 11:40:17-07:00, acurtis@stripped +0 -0
Auto merged
MERGE: 1.295.4.1
sql/handler.h@stripped, 2007-03-23 11:47:24-07:00, acurtis@stripped +0 -0
Manual merge
MERGE: 1.252.2.1
sql/lock.cc@stripped, 2007-03-23 11:47:24-07:00, acurtis@stripped +0 -0
Manual merge
MERGE: 1.103.1.1
sql/log.cc@stripped, 2007-03-23 11:47:24-07:00, acurtis@stripped +0 -1
Manual merge
MERGE: 1.253.5.3
sql/log.h@stripped, 2007-03-23 11:40:17-07:00, acurtis@stripped +0 -0
Auto merged
MERGE: 1.22.1.1
sql/mysql_priv.h@stripped, 2007-03-23 11:40:18-07:00, acurtis@stripped +0 -0
Auto merged
MERGE: 1.470.16.1
sql/mysqld.cc@stripped, 2007-03-23 11:40:18-07:00, acurtis@stripped +0 -0
Auto merged
MERGE: 1.601.22.1
sql/set_var.cc@stripped, 2007-03-23 11:47:24-07:00, acurtis@stripped +0 -0
Manual merge
MERGE: 1.215.2.3
sql/sp_head.cc@stripped, 2007-03-23 11:40:18-07:00, acurtis@stripped +0 -0
Auto merged
MERGE: 1.252.2.1
sql/sql_base.cc@stripped, 2007-03-23 11:40:18-07:00, acurtis@stripped +0 -0
Auto merged
MERGE: 1.378.2.1
sql/sql_class.cc@stripped, 2007-03-23 11:40:18-07:00, acurtis@stripped +0 -0
Auto merged
MERGE: 1.312.4.1
sql/sql_class.h@stripped, 2007-03-23 11:40:19-07:00, acurtis@stripped +0 -0
Auto merged
MERGE: 1.339.2.1
sql/sql_delete.cc@stripped, 2007-03-23 11:40:19-07:00, acurtis@stripped +0 -0
Auto merged
MERGE: 1.209.1.1
sql/sql_parse.cc@stripped, 2007-03-23 11:40:19-07:00, acurtis@stripped +3 -3
Auto merged
MERGE: 1.626.4.1
sql/sql_plugin.cc@stripped, 2007-03-23 11:40:19-07:00, acurtis@stripped +0 -0
Auto merged
MERGE: 1.44.1.1
sql/sql_table.cc@stripped, 2007-03-23 11:40:19-07:00, acurtis@stripped +0 -0
Auto merged
MERGE: 1.393.1.1
sql/table.cc@stripped, 2007-03-23 11:47:24-07:00, acurtis@stripped +2 -0
Manual merge
MERGE: 1.275.4.1
sql/table.h@stripped, 2007-03-23 11:47:24-07:00, acurtis@stripped +0 -0
Manual merge
MERGE: 1.158.4.1
storage/csv/ha_tina.cc@stripped, 2007-03-23 11:47:24-07:00, acurtis@stripped +0 -0
Manual merge
MERGE: 1.75.1.1
storage/csv/ha_tina.h@stripped, 2007-03-23 11:47:24-07:00, acurtis@stripped +0 -0
Manual merge
MERGE: 1.27.1.1
storage/myisam/ha_myisam.cc@stripped, 2007-03-23 11:47:24-07:00, acurtis@stripped +0 -0
Manual merge
MERGE: 1.209.3.1
storage/myisam/ha_myisam.h@stripped, 2007-03-23 11:47:24-07:00, acurtis@stripped +0 -0
Manual merge
MERGE: 1.81.2.1
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: acurtis
# Host: ltamd64.xiphis.org
# Root: /home/antony/work2/mysql-5.1-logging.5/RESYNC
--- 1.177/sql/Makefile.am 2007-03-23 11:47:42 -07:00
+++ 1.178/sql/Makefile.am 2007-03-23 11:47:42 -07:00
@@ -69,6 +69,7 @@
sql_plugin.h authors.h \
event_data_objects.h event_scheduler.h \
sql_partition.h partition_info.h partition_element.h \
+ sql_logger.h \
contributors.h sql_servers.h
mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \
item.cc item_sum.cc item_buff.cc item_func.cc \
@@ -109,6 +110,7 @@
event_queue.cc event_db_repository.cc events.cc \
sql_plugin.cc sql_binlog.cc \
sql_builtin.cc sql_tablespace.cc partition_info.cc \
+ sql_logger.cc \
sql_servers.cc
--- 1.215/storage/myisam/ha_myisam.cc 2007-03-23 11:47:42 -07:00
+++ 1.216/storage/myisam/ha_myisam.cc 2007-03-23 11:47:42 -07:00
@@ -598,39 +598,6 @@
#endif /* HAVE_REPLICATION */
-bool ha_myisam::check_if_locking_is_allowed(uint sql_command,
- ulong type, TABLE *table,
- uint count, uint current,
- uint *system_count,
- bool called_by_privileged_thread)
-{
- /*
- To be able to open and lock for reading system tables like 'mysql.proc',
- when we already have some tables opened and locked, and avoid deadlocks
- we have to disallow write-locking of these tables with any other tables.
- */
- if (table->s->system_table &&
- table->reginfo.lock_type >= TL_WRITE_ALLOW_WRITE)
- (*system_count)++;
-
- /* 'current' is an index, that's why '<=' below. */
- if (*system_count > 0 && *system_count <= current)
- {
- my_error(ER_WRONG_LOCK_OF_SYSTEM_TABLE, MYF(0));
- return FALSE;
- }
-
- /*
- Deny locking of the log tables, which is incompatible with
- concurrent insert. Unless called from a logger THD (general_log_thd
- or slow_log_thd) or by a privileged thread.
- */
- if (!called_by_privileged_thread)
- return check_if_log_table_locking_is_allowed(sql_command, type, table);
-
- return TRUE;
-}
-
/* Name is here without an extension */
int ha_myisam::open(const char *name, int mode, uint test_if_locked)
--- 1.84/storage/myisam/ha_myisam.h 2007-03-23 11:47:42 -07:00
+++ 1.85/storage/myisam/ha_myisam.h 2007-03-23 11:47:42 -07:00
@@ -60,11 +60,6 @@
uint max_supported_key_part_length() const { return MI_MAX_KEY_LENGTH; }
uint checksum() const;
- virtual bool check_if_locking_is_allowed(uint sql_command,
- ulong type, TABLE *table,
- uint count, uint current,
- uint *system_count,
- bool called_by_logger_thread);
int open(const char *name, int mode, uint test_if_locked);
int close(void);
int write_row(byte * buf);
--- 1.300/sql/handler.cc 2007-03-23 11:47:42 -07:00
+++ 1.301/sql/handler.cc 2007-03-23 11:47:42 -07:00
@@ -1475,34 +1475,6 @@
}
-bool handler::check_if_log_table_locking_is_allowed(uint sql_command,
- ulong type, TABLE *table)
-{
- /*
- Deny locking of the log tables, which is incompatible with
- concurrent insert. The routine is not called if the table is
- being locked from a logger THD (general_log_thd or slow_log_thd)
- or from a privileged thread (see log.cc for details)
- */
- if (table->s->log_table &&
- sql_command != SQLCOM_TRUNCATE &&
- sql_command != SQLCOM_ALTER_TABLE &&
- !(sql_command == SQLCOM_FLUSH &&
- type & REFRESH_LOG) &&
- (table->reginfo.lock_type >= TL_READ_NO_INSERT))
- {
- /*
- The check >= TL_READ_NO_INSERT denies all write locks
- plus the only read lock (TL_READ_NO_INSERT itself)
- */
- table->reginfo.lock_type == TL_READ_NO_INSERT ?
- my_error(ER_CANT_READ_LOCK_LOG_TABLE, MYF(0)) :
- my_error(ER_CANT_WRITE_LOCK_LOG_TABLE, MYF(0));
- return FALSE;
- }
- return TRUE;
-}
-
/** @brief
Open database-handler.
--- 1.255/sql/handler.h 2007-03-23 11:47:42 -07:00
+++ 1.256/sql/handler.h 2007-03-23 11:47:42 -07:00
@@ -979,44 +979,6 @@
{
cached_table_flags= table_flags();
}
- /*
- Check whether a handler allows to lock the table.
-
- SYNOPSIS
- check_if_locking_is_allowed()
- thd Handler of the thread, trying to lock the table
- table Table handler to check
- count Total number of tables to be locked
- current Index of the current table in the list of the tables
- to be locked.
- system_count Pointer to the counter of system tables seen thus
- far.
- called_by_privileged_thread TRUE if called from a logger THD
- (general_log_thd or slow_log_thd)
- or by a privileged thread, which
- has the right to lock log tables.
-
- DESCRIPTION
- Check whether a handler allows to lock the table. For instance,
- MyISAM does not allow to lock mysql.proc along with other tables.
- This limitation stems from the fact that MyISAM does not support
- row-level locking and we have to add this limitation to avoid
- deadlocks.
-
- RETURN
- TRUE Locking is allowed
- FALSE Locking is not allowed. The error was thrown.
- */
- virtual bool check_if_locking_is_allowed(uint sql_command,
- ulong type, TABLE *table,
- uint count, uint current,
- uint *system_count,
- bool called_by_privileged_thread)
- {
- return TRUE;
- }
- bool check_if_log_table_locking_is_allowed(uint sql_command,
- ulong type, TABLE *table);
int ha_open(TABLE *table, const char *name, int mode, int test_if_locked);
void adjust_next_insert_id_after_explicit_value(ulonglong nr);
int update_auto_increment();
--- 1.105/sql/lock.cc 2007-03-23 11:47:42 -07:00
+++ 1.106/sql/lock.cc 2007-03-23 11:47:42 -07:00
@@ -700,17 +700,6 @@
tables+=table_ptr[i]->file->lock_count();
lock_count++;
}
- /*
- Check if we can lock the table. For some tables we cannot do that
- beacause of handler-specific locking issues.
- */
- if (!table_ptr[i]-> file->
- check_if_locking_is_allowed(thd->lex->sql_command, thd->lex->type,
- table_ptr[i], count, i, &system_count,
- (thd == logger.get_general_log_thd()) ||
- (thd == logger.get_slow_log_thd()) ||
- (thd == logger.get_privileged_thread())))
- DBUG_RETURN(0);
}
/*
--- 1.270/sql/log.cc 2007-03-23 11:47:42 -07:00
+++ 1.271/sql/log.cc 2007-03-23 11:47:42 -07:00
@@ -39,8 +39,6 @@
#define FLAGSTR(V,F) ((V)&(F)?#F" ":"")
-LOGGER logger;
-
MYSQL_BIN_LOG mysql_bin_log;
ulong sync_binlog_counter= 0;
@@ -56,21 +54,8 @@
static int binlog_rollback(handlerton *hton, THD *thd, bool all);
static int binlog_prepare(handlerton *hton, THD *thd, bool all);
-sql_print_message_func sql_print_message_handlers[3] =
-{
- sql_print_information,
- sql_print_warning,
- sql_print_error
-};
-char *make_default_log_name(char *buff,const char* log_ext)
-{
- strmake(buff, pidfile_name, FN_REFLEN-5);
- return fn_format(buff, buff, mysql_data_home, log_ext,
- MYF(MY_UNPACK_FILENAME|MY_REPLACE_EXT));
-}
-
/*
Helper class to hold a mutex for the duration of the
block.
@@ -187,1151 +172,6 @@
handlerton *binlog_hton;
-/* Check if a given table is opened log table */
-int check_if_log_table(uint db_len, const char *db, uint table_name_len,
- const char *table_name, uint check_if_opened)
-{
- if (db_len == 5 &&
- !(lower_case_table_names ?
- my_strcasecmp(system_charset_info, db, "mysql") :
- strcmp(db, "mysql")))
- {
- if (table_name_len == 11 && !(lower_case_table_names ?
- my_strcasecmp(system_charset_info,
- table_name, "general_log") :
- strcmp(table_name, "general_log")) &&
- (!check_if_opened || logger.is_log_table_enabled(QUERY_LOG_GENERAL)))
- return QUERY_LOG_GENERAL;
- else
- if (table_name_len == 8 && !(lower_case_table_names ?
- my_strcasecmp(system_charset_info, table_name, "slow_log") :
- strcmp(table_name, "slow_log")) &&
- (!check_if_opened ||logger.is_log_table_enabled(QUERY_LOG_SLOW)))
- return QUERY_LOG_SLOW;
- }
- return 0;
-}
-
-
-/*
- Open log table of a given type (general or slow log)
-
- SYNOPSIS
- open_log_table()
-
- log_table_type type of the log table to open: QUERY_LOG_GENERAL
- or QUERY_LOG_SLOW
-
- DESCRIPTION
-
- The function opens a log table and marks it as such. Log tables are open
- during the whole time, while server is running. Except for the moments
- when they have to be reopened: during FLUSH LOGS and TRUNCATE. This
- function is invoked directly only once during startup. All subsequent
- calls happen through reopen_log_table(), which performs additional check.
-
- RETURN
- FALSE - OK
- TRUE - error occured
-*/
-
-bool Log_to_csv_event_handler::open_log_table(uint log_table_type)
-{
- THD *log_thd, *curr= current_thd;
- TABLE_LIST *table;
- bool error= FALSE;
- DBUG_ENTER("open_log_table");
-
- switch (log_table_type) {
- case QUERY_LOG_GENERAL:
- log_thd= general_log_thd;
- table= &general_log;
- /* clean up table before reuse/initial usage */
- bzero((char*) table, sizeof(TABLE_LIST));
- table->alias= table->table_name= (char*) "general_log";
- table->table_name_length= 11;
- break;
- case QUERY_LOG_SLOW:
- log_thd= slow_log_thd;
- table= &slow_log;
- bzero((char*) table, sizeof(TABLE_LIST));
- table->alias= table->table_name= (char*) "slow_log";
- table->table_name_length= 8;
- break;
- default:
- assert(0); // Impossible
- }
-
- /*
- This way we check that appropriate log thd was created ok during
- initialization. We cannot check "is_log_tables_initialized" var, as
- the very initialization is not finished until this function is
- completed in the very first time.
- */
- if (!log_thd)
- {
- DBUG_PRINT("error",("Cannot initialize log tables"));
- DBUG_RETURN(TRUE);
- }
-
- /*
- Set THD's thread_stack. This is needed to perform stack overrun
- check, which is done by some routines (e.g. open_table()).
- In the case we are called by thread, which already has this parameter
- set, we use this value. Otherwise we do a wild guess. This won't help
- to correctly track the stack overrun in these exceptional cases (which
- could probably happen only during startup and shutdown) but at least
- lets us to pass asserts.
- The problem stems from the fact that logger THDs are not real threads.
- */
- if (curr)
- log_thd->thread_stack= curr->thread_stack;
- else
- log_thd->thread_stack= (char*) &log_thd;
-
- log_thd->store_globals();
-
- table->lock_type= TL_WRITE_CONCURRENT_INSERT;
- table->db= log_thd->db;
- table->db_length= log_thd->db_length;
-
- if (simple_open_n_lock_tables(log_thd, table) ||
- table->table->file->extra(HA_EXTRA_MARK_AS_LOG_TABLE) ||
- table->table->file->ha_rnd_init(0))
- error= TRUE;
- else
- {
- table->table->use_all_columns();
- table->table->locked_by_logger= TRUE;
- table->table->no_replicate= TRUE;
- }
- /* restore thread settings */
- if (curr)
- curr->store_globals();
- else
- {
- my_pthread_setspecific_ptr(THR_THD, 0);
- my_pthread_setspecific_ptr(THR_MALLOC, 0);
- }
-
- /*
- After a log table was opened, we should clear privileged thread
- flag (which allows locking of a log table by a special thread, usually
- the one who closed log tables temporarily).
- */
- privileged_thread= 0;
- DBUG_RETURN(error);
-}
-
-
-Log_to_csv_event_handler::Log_to_csv_event_handler()
-{
- /* init artificial THD's */
- general_log_thd= new THD;
- /* logger thread always works with mysql database */
- general_log_thd->db= my_strdup("mysql", MYF(0));
- general_log_thd->db_length= 5;
- general_log.table= 0;
-
- slow_log_thd= new THD;
- /* logger thread always works with mysql database */
- slow_log_thd->db= my_strdup("mysql", MYF(0));;
- slow_log_thd->db_length= 5;
- slow_log.table= 0;
- /* no privileged thread exists at the moment */
- privileged_thread= 0;
-}
-
-
-Log_to_csv_event_handler::~Log_to_csv_event_handler()
-{
- /* now cleanup the tables */
- if (general_log_thd)
- {
- delete general_log_thd;
- general_log_thd= NULL;
- }
-
- if (slow_log_thd)
- {
- delete slow_log_thd;
- slow_log_thd= NULL;
- }
-}
-
-
-/*
- Reopen log table of a given type
-
- SYNOPSIS
- reopen_log_table()
-
- log_table_type type of the log table to open: QUERY_LOG_GENERAL
- or QUERY_LOG_SLOW
-
- DESCRIPTION
-
- The function is a wrapper around open_log_table(). It is used during
- FLUSH LOGS and TRUNCATE of the log tables (i.e. when we need to close
- and reopen them). The difference is in the check of the
- logger.is_log_tables_initialized var, which can't be done in
- open_log_table(), as it makes no sense during startup.
-
- NOTE: this code assumes that we have logger mutex locked
-
- RETURN
- FALSE - ok
- TRUE - open_log_table() returned an error
-*/
-
-bool Log_to_csv_event_handler::reopen_log_table(uint log_table_type)
-{
- /* don't open the log table, if it wasn't enabled during startup */
- if (!logger.is_log_tables_initialized)
- return FALSE;
- return open_log_table(log_table_type);
-}
-
-
-void Log_to_csv_event_handler::cleanup()
-{
- if (opt_log)
- close_log_table(QUERY_LOG_GENERAL, FALSE);
- if (opt_slow_log)
- close_log_table(QUERY_LOG_SLOW, FALSE);
- logger.is_log_tables_initialized= FALSE;
-}
-
-/* log event handlers */
-
-/*
- Log command to the general log table
-
- SYNOPSIS
- log_general()
-
- event_time command start timestamp
- user_host the pointer to the string with user@host info
- user_host_len length of the user_host string. this is computed once
- and passed to all general log event handlers
- thread_id Id of the thread, issued a query
- command_type the type of the command being logged
- command_type_len the length of the string above
- sql_text the very text of the query being executed
- sql_text_len the length of sql_text string
-
- DESCRIPTION
-
- Log given command to the general log table
-
- RETURN
- FALSE - OK
- TRUE - error occured
-*/
-
-bool Log_to_csv_event_handler::
- log_general(time_t event_time, const char *user_host,
- uint user_host_len, int thread_id,
- const char *command_type, uint command_type_len,
- const char *sql_text, uint sql_text_len,
- CHARSET_INFO *client_cs)
-{
- TABLE *table= general_log.table;
-
- /*
- "INSERT INTO general_log" can generate warning sometimes.
- Let's reset warnings from previous queries,
- otherwise warning list can grow too much,
- so thd->query gets spoiled as some point in time,
- and mysql_parse() receives a broken query.
- QQ: this problem needs to be studied in more details.
- Probably it's better to suppress warnings in logging INSERTs at all.
- Comment this line and run "cast.test" to see what's happening:
- */
- mysql_reset_errors(table->in_use, 1);
-
- /* below should never happen */
- if (unlikely(!logger.is_log_tables_initialized))
- return FALSE;
-
- /*
- NOTE: we do not call restore_record() here, as all fields are
- filled by the Logger (=> no need to load default ones).
- */
-
- /* Set current time. Required for CURRENT_TIMESTAMP to work */
- general_log_thd->start_time= event_time;
-
- /*
- We do not set a value for table->field[0], as it will use
- default value (which is CURRENT_TIMESTAMP).
- */
-
- /* check that all columns exist */
- if (!table->field[1] || !table->field[2] || !table->field[3] ||
- !table->field[4] || !table->field[5])
- goto err;
-
- /* do a write */
- if (table->field[1]->store(user_host, user_host_len, client_cs) ||
- table->field[2]->store((longlong) thread_id, TRUE) ||
- table->field[3]->store((longlong) server_id, TRUE) ||
- table->field[4]->store(command_type, command_type_len, client_cs) ||
- table->field[5]->store(sql_text, sql_text_len, client_cs))
- goto err;
-
- /* mark tables as not null */
- table->field[1]->set_notnull();
- table->field[2]->set_notnull();
- table->field[3]->set_notnull();
- table->field[4]->set_notnull();
- table->field[5]->set_notnull();
-
- /* log table entries are not replicated at the moment */
- tmp_disable_binlog(current_thd);
-
- table->file->ha_write_row(table->record[0]);
-
- reenable_binlog(current_thd);
-
- return FALSE;
-err:
- return TRUE;
-}
-
-
-/*
- Log a query to the slow log table
-
- SYNOPSIS
- log_slow()
- thd THD of the query
- current_time current timestamp
- query_start_arg command start timestamp
- user_host the pointer to the string with user@host info
- user_host_len length of the user_host string. this is computed once
- and passed to all general log event handlers
- query_time Amount of time the query took to execute (in seconds)
- lock_time Amount of time the query was locked (in seconds)
- is_command The flag, which determines, whether the sql_text is a
- query or an administrator command (these are treated
- differently by the old logging routines)
- sql_text the very text of the query or administrator command
- processed
- sql_text_len the length of sql_text string
-
- DESCRIPTION
-
- Log a query to the slow log table
-
- RETURN
- FALSE - OK
- TRUE - error occured
-*/
-
-bool Log_to_csv_event_handler::
- log_slow(THD *thd, time_t current_time, time_t query_start_arg,
- const char *user_host, uint user_host_len,
- longlong query_time, longlong lock_time, bool is_command,
- const char *sql_text, uint sql_text_len)
-{
- /* table variables */
- TABLE *table= slow_log.table;
- CHARSET_INFO *client_cs= thd->variables.character_set_client;
-
- DBUG_ENTER("log_slow");
-
- /* below should never happen */
- if (unlikely(!logger.is_log_tables_initialized))
- return FALSE;
-
- /*
- Set start time for CURRENT_TIMESTAMP to the start of the query.
- This will be default value for the field[0]
- */
- slow_log_thd->start_time= query_start_arg;
- restore_record(table, s->default_values); // Get empty record
-
- /*
- We do not set a value for table->field[0], as it will use
- default value.
- */
-
- if (!table->field[1] || !table->field[2] || !table->field[3] ||
- !table->field[4] || !table->field[5] || !table->field[6] ||
- !table->field[7] || !table->field[8] || !table->field[9] ||
- !table->field[10])
- goto err;
-
- /* store the value */
- if (table->field[1]->store(user_host, user_host_len, client_cs))
- goto err;
-
- if (query_start_arg)
- {
- /* fill in query_time field */
- if (table->field[2]->store(query_time, TRUE))
- goto err;
- /* lock_time */
- if (table->field[3]->store(lock_time, TRUE))
- goto err;
- /* rows_sent */
- if (table->field[4]->store((longlong) thd->sent_row_count, TRUE))
- goto err;
- /* rows_examined */
- if (table->field[5]->store((longlong) thd->examined_row_count, TRUE))
- goto err;
- }
- else
- {
- table->field[2]->set_null();
- table->field[3]->set_null();
- table->field[4]->set_null();
- table->field[5]->set_null();
- }
-
- /* fill database field */
- if (thd->db)
- {
- if (table->field[6]->store(thd->db, thd->db_length, client_cs))
- goto err;
- table->field[6]->set_notnull();
- }
-
- if (thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt)
- {
- if (table->
- field[7]->store((longlong)
- thd->first_successful_insert_id_in_prev_stmt_for_binlog,
- TRUE))
- goto err;
- table->field[7]->set_notnull();
- }
-
- /*
- Set value if we do an insert on autoincrement column. Note that for
- some engines (those for which get_auto_increment() does not leave a
- table lock until the statement ends), this is just the first value and
- the next ones used may not be contiguous to it.
- */
- if (thd->auto_inc_intervals_in_cur_stmt_for_binlog.nb_elements() > 0)
- {
- if (table->
- field[8]->store((longlong)
- thd->auto_inc_intervals_in_cur_stmt_for_binlog.minimum(), TRUE))
- goto err;
- table->field[8]->set_notnull();
- }
-
- if (table->field[9]->store((longlong) server_id, TRUE))
- goto err;
- table->field[9]->set_notnull();
-
- /* sql_text */
- if (table->field[10]->store(sql_text,sql_text_len, client_cs))
- goto err;
-
- /* log table entries are not replicated at the moment */
- tmp_disable_binlog(current_thd);
-
- /* write the row */
- table->file->ha_write_row(table->record[0]);
-
- reenable_binlog(current_thd);
-
- DBUG_RETURN(0);
-err:
- DBUG_RETURN(1);
-}
-
-bool Log_to_csv_event_handler::
- log_error(enum loglevel level, const char *format, va_list args)
-{
- /* No log table is implemented */
- DBUG_ASSERT(0);
- return FALSE;
-}
-
-bool Log_to_file_event_handler::
- log_error(enum loglevel level, const char *format,
- va_list args)
-{
- return vprint_msg_to_log(level, format, args);
-}
-
-void Log_to_file_event_handler::init_pthread_objects()
-{
- mysql_log.init_pthread_objects();
- mysql_slow_log.init_pthread_objects();
-}
-
-
-/* Wrapper around MYSQL_LOG::write() for slow log */
-
-bool Log_to_file_event_handler::
- log_slow(THD *thd, time_t current_time, time_t query_start_arg,
- const char *user_host, uint user_host_len,
- longlong query_time, longlong lock_time, bool is_command,
- const char *sql_text, uint sql_text_len)
-{
- return mysql_slow_log.write(thd, current_time, query_start_arg,
- user_host, user_host_len,
- query_time, lock_time, is_command,
- sql_text, sql_text_len);
-}
-
-
-/*
- Wrapper around MYSQL_LOG::write() for general log. We need it since we
- want all log event handlers to have the same signature.
-*/
-
-bool Log_to_file_event_handler::
- log_general(time_t event_time, const char *user_host,
- uint user_host_len, int thread_id,
- const char *command_type, uint command_type_len,
- const char *sql_text, uint sql_text_len,
- CHARSET_INFO *client_cs)
-{
- return mysql_log.write(event_time, user_host, user_host_len,
- thread_id, command_type, command_type_len,
- sql_text, sql_text_len);
-}
-
-
-bool Log_to_file_event_handler::init()
-{
- if (!is_initialized)
- {
- if (opt_slow_log)
- mysql_slow_log.open_slow_log(sys_var_slow_log_path.value);
-
- if (opt_log)
- mysql_log.open_query_log(sys_var_general_log_path.value);
-
- is_initialized= TRUE;
- }
-
- return FALSE;
-}
-
-
-void Log_to_file_event_handler::cleanup()
-{
- mysql_log.cleanup();
- mysql_slow_log.cleanup();
-}
-
-void Log_to_file_event_handler::flush()
-{
- /* reopen log files */
- if (opt_log)
- mysql_log.reopen_file();
- if (opt_slow_log)
- mysql_slow_log.reopen_file();
-}
-
-/*
- Log error with all enabled log event handlers
-
- SYNOPSIS
- error_log_print()
-
- level The level of the error significance: NOTE,
- WARNING or ERROR.
- format format string for the error message
- args list of arguments for the format string
-
- RETURN
- FALSE - OK
- TRUE - error occured
-*/
-
-bool LOGGER::error_log_print(enum loglevel level, const char *format,
- va_list args)
-{
- bool error= FALSE;
- Log_event_handler **current_handler= error_log_handler_list;
-
- /* currently we don't need locking here as there is no error_log table */
- while (*current_handler)
- error= (*current_handler++)->log_error(level, format, args) || error;
-
- return error;
-}
-
-
-void LOGGER::cleanup_base()
-{
- DBUG_ASSERT(inited == 1);
- (void) pthread_mutex_destroy(&LOCK_logger);
- if (table_log_handler)
- {
- table_log_handler->cleanup();
- delete table_log_handler;
- }
- if (file_log_handler)
- file_log_handler->cleanup();
-}
-
-
-void LOGGER::cleanup_end()
-{
- DBUG_ASSERT(inited == 1);
- if (file_log_handler)
- delete file_log_handler;
-}
-
-
-void LOGGER::close_log_table(uint log_table_type, bool lock_in_use)
-{
- table_log_handler->close_log_table(log_table_type, lock_in_use);
-}
-
-
-/*
- Perform basic log initialization: create file-based log handler and
- init error log.
-*/
-void LOGGER::init_base()
-{
- DBUG_ASSERT(inited == 0);
- inited= 1;
-
- /*
- Here we create file log handler. We don't do it for the table log handler
- here as it cannot be created so early. The reason is THD initialization,
- which depends on the system variables (parsed later).
- */
- if (!file_log_handler)
- file_log_handler= new Log_to_file_event_handler;
-
- /* by default we use traditional error log */
- init_error_log(LOG_FILE);
-
- file_log_handler->init_pthread_objects();
- (void) pthread_mutex_init(&LOCK_logger, MY_MUTEX_INIT_SLOW);
-}
-
-
-void LOGGER::init_log_tables()
-{
- if (!table_log_handler)
- table_log_handler= new Log_to_csv_event_handler;
-
- if (!is_log_tables_initialized &&
- !table_log_handler->init() && !file_log_handler->init())
- is_log_tables_initialized= TRUE;
-}
-
-
-bool LOGGER::reopen_log_table(uint log_table_type)
-{
- return table_log_handler->reopen_log_table(log_table_type);
-}
-
-bool LOGGER::reopen_log_tables()
-{
- /*
- we use | and not || here, to ensure that both reopen_log_table
- are called, even if the first one fails
- */
- if ((opt_slow_log && logger.reopen_log_table(QUERY_LOG_SLOW)) |
- (opt_log && logger.reopen_log_table(QUERY_LOG_GENERAL)))
- return TRUE;
- return FALSE;
-}
-
-
-void LOGGER::tmp_close_log_tables(THD *thd)
-{
- table_log_handler->tmp_close_log_tables(thd);
-}
-
-bool LOGGER::flush_logs(THD *thd)
-{
- int rc= 0;
-
- /*
- Now we lock logger, as nobody should be able to use logging routines while
- log tables are closed
- */
- logger.lock();
- if (logger.is_log_tables_initialized)
- table_log_handler->tmp_close_log_tables(thd); // the locking happens here
-
- /* reopen log files */
- file_log_handler->flush();
-
- /* reopen tables in the case they were enabled */
- if (logger.is_log_tables_initialized)
- {
- if (reopen_log_tables())
- rc= TRUE;
- }
- /* end of log flush */
- logger.unlock();
- return rc;
-}
-
-
-/*
- Log slow query with all enabled log event handlers
-
- SYNOPSIS
- slow_log_print()
-
- thd THD of the query being logged
- query The query being logged
- query_length The length of the query string
- query_start_arg Query start timestamp
-
- RETURN
- FALSE - OK
- TRUE - error occured
-*/
-
-bool LOGGER::slow_log_print(THD *thd, const char *query, uint query_length,
- time_t query_start_arg)
-{
- bool error= FALSE;
- Log_event_handler **current_handler= slow_log_handler_list;
- bool is_command= FALSE;
- char user_host_buff[MAX_USER_HOST_SIZE];
-
- time_t current_time;
- Security_context *sctx= thd->security_ctx;
- uint user_host_len= 0;
- longlong query_time= 0, lock_time= 0;
-
- /*
- Print the message to the buffer if we have slow log enabled
- */
-
- if (*slow_log_handler_list)
- {
- current_time= time(NULL);
-
- /* do not log slow queries from replication threads */
- if (thd->slave_thread)
- return 0;
-
- lock();
- if (!opt_slow_log)
- {
- unlock();
- return 0;
- }
-
- /* fill in user_host value: the format is "%s[%s] @ %s [%s]" */
- user_host_len= strxnmov(user_host_buff, MAX_USER_HOST_SIZE,
- sctx->priv_user ? sctx->priv_user : "", "[",
- sctx->user ? sctx->user : "", "] @ ",
- sctx->host ? sctx->host : "", " [",
- sctx->ip ? sctx->ip : "", "]", NullS) -
- user_host_buff;
-
- if (query_start_arg)
- {
- query_time= (longlong) (current_time - query_start_arg);
- lock_time= (longlong) (thd->time_after_lock - query_start_arg);
- }
-
- if (!query)
- {
- is_command= TRUE;
- query= command_name[thd->command].str;
- query_length= command_name[thd->command].length;
- }
-
- while (*current_handler)
- error= (*current_handler++)->log_slow(thd, current_time, query_start_arg,
- user_host_buff, user_host_len,
- query_time, lock_time, is_command,
- query, query_length) || error;
-
- unlock();
- }
- return error;
-}
-
-bool LOGGER::general_log_print(THD *thd, enum enum_server_command command,
- const char *format, va_list args)
-{
- bool error= FALSE;
- Log_event_handler **current_handler= general_log_handler_list;
-
- /*
- Print the message to the buffer if we have at least one log event handler
- enabled and want to log this king of commands
- */
- if (*general_log_handler_list && (what_to_log & (1L << (uint) command)))
- {
- char message_buff[MAX_LOG_BUFFER_SIZE];
- char user_host_buff[MAX_USER_HOST_SIZE];
- Security_context *sctx= thd->security_ctx;
- ulong id;
- uint message_buff_len= 0, user_host_len= 0;
-
- if (thd)
- { /* Normal thread */
- if ((thd->options & OPTION_LOG_OFF)
-#ifndef NO_EMBEDDED_ACCESS_CHECKS
- && (sctx->master_access & SUPER_ACL)
-#endif
- )
- {
- return 0; /* No logging */
- }
- id= thd->thread_id;
- }
- else
- id=0; /* Log from connect handler */
-
- lock();
- if (!opt_log)
- {
- unlock();
- return 0;
- }
- time_t current_time= time(NULL);
-
- user_host_len= strxnmov(user_host_buff, MAX_USER_HOST_SIZE,
- sctx->priv_user ? sctx->priv_user : "", "[",
- sctx->user ? sctx->user : "", "] @ ",
- sctx->host ? sctx->host : "", " [",
- sctx->ip ? sctx->ip : "", "]", NullS) -
- user_host_buff;
-
- /* prepare message */
- if (format)
- message_buff_len= my_vsnprintf(message_buff,
- sizeof(message_buff), format, args);
- else
- message_buff[0]= '\0';
-
- while (*current_handler)
- error+= (*current_handler++)->
- log_general(current_time, user_host_buff,
- user_host_len, id,
- command_name[(uint) command].str,
- command_name[(uint) command].length,
- message_buff, message_buff_len,
- thd->variables.character_set_client) || error;
- unlock();
- }
- return error;
-}
-
-void LOGGER::init_error_log(uint error_log_printer)
-{
- if (error_log_printer & LOG_NONE)
- {
- error_log_handler_list[0]= 0;
- return;
- }
-
- switch (error_log_printer) {
- case LOG_FILE:
- error_log_handler_list[0]= file_log_handler;
- error_log_handler_list[1]= 0;
- break;
- /* these two are disabled for now */
- case LOG_TABLE:
- DBUG_ASSERT(0);
- break;
- case LOG_TABLE|LOG_FILE:
- DBUG_ASSERT(0);
- break;
- }
-}
-
-void LOGGER::init_slow_log(uint slow_log_printer)
-{
- if (slow_log_printer & LOG_NONE)
- {
- slow_log_handler_list[0]= 0;
- return;
- }
-
- switch (slow_log_printer) {
- case LOG_FILE:
- slow_log_handler_list[0]= file_log_handler;
- slow_log_handler_list[1]= 0;
- break;
- case LOG_TABLE:
- slow_log_handler_list[0]= table_log_handler;
- slow_log_handler_list[1]= 0;
- break;
- case LOG_TABLE|LOG_FILE:
- slow_log_handler_list[0]= file_log_handler;
- slow_log_handler_list[1]= table_log_handler;
- slow_log_handler_list[2]= 0;
- break;
- }
-}
-
-void LOGGER::init_general_log(uint general_log_printer)
-{
- if (general_log_printer & LOG_NONE)
- {
- general_log_handler_list[0]= 0;
- return;
- }
-
- switch (general_log_printer) {
- case LOG_FILE:
- general_log_handler_list[0]= file_log_handler;
- general_log_handler_list[1]= 0;
- break;
- case LOG_TABLE:
- general_log_handler_list[0]= table_log_handler;
- general_log_handler_list[1]= 0;
- break;
- case LOG_TABLE|LOG_FILE:
- general_log_handler_list[0]= file_log_handler;
- general_log_handler_list[1]= table_log_handler;
- general_log_handler_list[2]= 0;
- break;
- }
-}
-
-
-bool LOGGER::activate_log_handler(THD* thd, uint log_type)
-{
- bool res= 0;
- lock();
- switch (log_type) {
- case QUERY_LOG_SLOW:
- if (!opt_slow_log)
- {
- if ((res= reopen_log_table(log_type)))
- goto err;
- file_log_handler->get_mysql_slow_log()->
- open_slow_log(sys_var_slow_log_path.value);
- init_slow_log(log_output_options);
- opt_slow_log= TRUE;
- }
- break;
- case QUERY_LOG_GENERAL:
- if (!opt_log)
- {
- if ((res= reopen_log_table(log_type)))
- goto err;
- file_log_handler->get_mysql_log()->
- open_query_log(sys_var_general_log_path.value);
- init_general_log(log_output_options);
- opt_log= TRUE;
- }
- break;
- default:
- DBUG_ASSERT(0);
- }
-err:
- unlock();
- return res;
-}
-
-
-void LOGGER::deactivate_log_handler(THD *thd, uint log_type)
-{
- TABLE_LIST *table_list;
- my_bool *tmp_opt= 0;
- MYSQL_LOG *file_log;
- THD *log_thd;
-
- switch (log_type) {
- case QUERY_LOG_SLOW:
- table_list= &table_log_handler->slow_log;
- tmp_opt= &opt_slow_log;
- file_log= file_log_handler->get_mysql_slow_log();
- log_thd= table_log_handler->slow_log_thd;
- break;
- case QUERY_LOG_GENERAL:
- table_list= &table_log_handler->general_log;
- tmp_opt= &opt_log;
- file_log= file_log_handler->get_mysql_log();
- log_thd= table_log_handler->general_log_thd;
- break;
- default:
- assert(0); // Impossible
- }
-
- if (!(*tmp_opt))
- return;
-
- if (is_log_tables_initialized)
- lock_and_wait_for_table_name(log_thd, table_list);
- lock();
-
- if (is_log_tables_initialized)
- {
- VOID(pthread_mutex_lock(&LOCK_open));
- close_log_table(log_type, TRUE);
- table_list->table= 0;
- query_cache_invalidate3(log_thd, table_list, 0);
- unlock_table_name(log_thd, table_list);
- VOID(pthread_mutex_unlock(&LOCK_open));
- }
- file_log->close(0);
- *tmp_opt= FALSE;
- unlock();
-}
-
-
-/*
- Close log tables temporarily. The thread which closed
- them this way can lock them in any mode it needs.
- NOTE: one should call logger.lock() before entering this
- function.
-*/
-void Log_to_csv_event_handler::tmp_close_log_tables(THD *thd)
-{
- TABLE_LIST close_slow_log, close_general_log;
-
- /* fill lists, we will need to perform operations on tables */
- bzero((char*) &close_slow_log, sizeof(TABLE_LIST));
- close_slow_log.alias= close_slow_log.table_name=(char*) "slow_log";
- close_slow_log.table_name_length= 8;
- close_slow_log.db= (char*) "mysql";
- close_slow_log.db_length= 5;
-
- bzero((char*) &close_general_log, sizeof(TABLE_LIST));
- close_general_log.alias= close_general_log.table_name=(char*) "general_log";
- close_general_log.table_name_length= 11;
- close_general_log.db= (char*) "mysql";
- close_general_log.db_length= 5;
-
- privileged_thread= thd;
-
- VOID(pthread_mutex_lock(&LOCK_open));
- /*
- NOTE: in fact, the first parameter used in query_cache_invalidate3()
- could be any non-NULL THD, as the underlying code makes certain
- assumptions about this.
- Here we use one of the logger handler THD's. Simply because it
- seems appropriate.
- */
- if (opt_log)
- {
- close_log_table(QUERY_LOG_GENERAL, TRUE);
- query_cache_invalidate3(general_log_thd, &close_general_log, 0);
- }
- if (opt_slow_log)
- {
- close_log_table(QUERY_LOG_SLOW, TRUE);
- query_cache_invalidate3(general_log_thd, &close_slow_log, 0);
- }
- VOID(pthread_mutex_unlock(&LOCK_open));
-}
-
-/* the parameters are unused for the log tables */
-bool Log_to_csv_event_handler::init()
-{
- /*
- we use | and not || here, to ensure that both open_log_table
- are called, even if the first one fails
- */
- if ((opt_log && open_log_table(QUERY_LOG_GENERAL)) |
- (opt_slow_log && open_log_table(QUERY_LOG_SLOW)))
- return 1;
- return 0;
-}
-
-int LOGGER::set_handlers(uint error_log_printer,
- uint slow_log_printer,
- uint general_log_printer)
-{
- /* error log table is not supported yet */
- DBUG_ASSERT(error_log_printer < LOG_TABLE);
-
- lock();
-
- if ((slow_log_printer & LOG_TABLE || general_log_printer & LOG_TABLE) &&
- !is_log_tables_initialized)
- {
- slow_log_printer= (slow_log_printer & ~LOG_TABLE) | LOG_FILE;
- general_log_printer= (general_log_printer & ~LOG_TABLE) | LOG_FILE;
-
- sql_print_error("Failed to initialize log tables. "
- "Falling back to the old-fashioned logs");
- }
-
- init_error_log(error_log_printer);
- init_slow_log(slow_log_printer);
- init_general_log(general_log_printer);
-
- unlock();
-
- return 0;
-}
-
-
-/*
- Close log table of a given type (general or slow log)
-
- SYNOPSIS
- close_log_table()
-
- log_table_type type of the log table to close: QUERY_LOG_GENERAL
- or QUERY_LOG_SLOW
- lock_in_use Set to TRUE if the caller owns LOCK_open. FALSE otherwise.
-
- DESCRIPTION
-
- The function closes a log table. It is invoked (1) when we need to reopen
- log tables (e.g. FLUSH LOGS or TRUNCATE on the log table is being
- executed) or (2) during shutdown.
-*/
-
-void Log_to_csv_event_handler::
- close_log_table(uint log_table_type, bool lock_in_use)
-{
- THD *log_thd, *curr= current_thd;
- TABLE_LIST *table;
-
- if (!logger.is_log_table_enabled(log_table_type))
- return; /* do nothing */
-
- switch (log_table_type) {
- case QUERY_LOG_GENERAL:
- log_thd= general_log_thd;
- table= &general_log;
- break;
- case QUERY_LOG_SLOW:
- log_thd= slow_log_thd;
- table= &slow_log;
- break;
- default:
- assert(0); // Impossible
- }
-
- /*
- Set thread stack start for the logger thread. See comment in
- open_log_table() for details.
- */
- if (curr)
- log_thd->thread_stack= curr->thread_stack;
- else
- log_thd->thread_stack= (char*) &log_thd;
-
- /* close the table */
- log_thd->store_globals();
- table->table->file->ha_rnd_end();
- /* discard logger mark before unlock*/
- table->table->locked_by_logger= FALSE;
- close_thread_tables(log_thd, lock_in_use);
-
- if (curr)
- curr->store_globals();
- else
- {
- my_pthread_setspecific_ptr(THR_THD, 0);
- my_pthread_setspecific_ptr(THR_MALLOC, 0);
- }
-}
-
-
/*
Save position of binary log transaction cache.
@@ -3842,33 +2682,6 @@
}
-int error_log_print(enum loglevel level, const char *format,
- va_list args)
-{
- return logger.error_log_print(level, format, args);
-}
-
-
-bool slow_log_print(THD *thd, const char *query, uint query_length,
- time_t query_start_arg)
-{
- return logger.slow_log_print(thd, query, query_length, query_start_arg);
-}
-
-
-bool general_log_print(THD *thd, enum enum_server_command command,
- const char *format, ...)
-{
- va_list args;
- uint error= 0;
-
- va_start(args, format);
- error= logger.general_log_print(thd, command, format, args);
- va_end(args);
-
- return error;
-}
-
void MYSQL_BIN_LOG::rotate_and_purge(uint flags)
{
if (!(flags & RP_LOCK_LOG_IS_ALREADY_LOCKED))
@@ -4216,236 +3029,10 @@
} /* test_if_number */
-void print_buffer_to_file(enum loglevel level, const char *buffer)
-{
- time_t skr;
- struct tm tm_tmp;
- struct tm *start;
- DBUG_ENTER("print_buffer_to_file");
- DBUG_PRINT("enter",("buffer: %s", buffer));
-
- VOID(pthread_mutex_lock(&LOCK_error_log));
-
- skr=time(NULL);
- localtime_r(&skr, &tm_tmp);
- start=&tm_tmp;
-
- fprintf(stderr, "%02d%02d%02d %2d:%02d:%02d [%s] %s\n",
- start->tm_year % 100,
- start->tm_mon+1,
- start->tm_mday,
- start->tm_hour,
- start->tm_min,
- start->tm_sec,
- (level == ERROR_LEVEL ? "ERROR" : level == WARNING_LEVEL ?
- "Warning" : "Note"),
- buffer);
-
- fflush(stderr);
-
- VOID(pthread_mutex_unlock(&LOCK_error_log));
- DBUG_VOID_RETURN;
-}
-
-
-void sql_perror(const char *message)
-{
-#ifdef HAVE_STRERROR
- sql_print_error("%s: %s",message, strerror(errno));
-#else
- perror(message);
-#endif
-}
-
-
-bool flush_error_log()
-{
- bool result=0;
- if (opt_error_log)
- {
- char err_renamed[FN_REFLEN], *end;
- end= strmake(err_renamed,log_error_file,FN_REFLEN-4);
- strmov(end, "-old");
- VOID(pthread_mutex_lock(&LOCK_error_log));
-#ifdef __WIN__
- char err_temp[FN_REFLEN+4];
- /*
- On Windows is necessary a temporary file for to rename
- the current error file.
- */
- strxmov(err_temp, err_renamed,"-tmp",NullS);
- (void) my_delete(err_temp, MYF(0));
- if (freopen(err_temp,"a+",stdout))
- {
- freopen(err_temp,"a+",stderr);
- (void) my_delete(err_renamed, MYF(0));
- my_rename(log_error_file,err_renamed,MYF(0));
- if (freopen(log_error_file,"a+",stdout))
- freopen(log_error_file,"a+",stderr);
- int fd, bytes;
- char buf[IO_SIZE];
- if ((fd = my_open(err_temp, O_RDONLY, MYF(0))) >= 0)
- {
- while ((bytes = (int) my_read(fd, (byte*) buf, IO_SIZE, MYF(0))) > 0)
- my_fwrite(stderr, (byte*) buf, bytes, MYF(0));
- my_close(fd, MYF(0));
- }
- (void) my_delete(err_temp, MYF(0));
- }
- else
- result= 1;
-#else
- my_rename(log_error_file,err_renamed,MYF(0));
- if (freopen(log_error_file,"a+",stdout))
- freopen(log_error_file,"a+",stderr);
- else
- result= 1;
-#endif
- VOID(pthread_mutex_unlock(&LOCK_error_log));
- }
- return result;
-}
-
void MYSQL_BIN_LOG::signal_update()
{
DBUG_ENTER("MYSQL_BIN_LOG::signal_update");
pthread_cond_broadcast(&update_cond);
- DBUG_VOID_RETURN;
-}
-
-#ifdef __NT__
-void print_buffer_to_nt_eventlog(enum loglevel level, char *buff,
- uint length, int buffLen)
-{
- HANDLE event;
- char *buffptr;
- LPCSTR *buffmsgptr;
- DBUG_ENTER("print_buffer_to_nt_eventlog");
-
- buffptr= buff;
- if (length > (uint)(buffLen-5))
- {
- char *newBuff= new char[length + 5];
- strcpy(newBuff, buff);
- buffptr= newBuff;
- }
- strmov(buffptr+length, "\r\n\r\n");
- buffmsgptr= (LPCSTR*) &buffptr; // Keep windows happy
-
- setup_windows_event_source();
- if ((event= RegisterEventSource(NULL,"MySQL")))
- {
- switch (level) {
- case ERROR_LEVEL:
- ReportEvent(event, EVENTLOG_ERROR_TYPE, 0, MSG_DEFAULT, NULL, 1, 0,
- buffmsgptr, NULL);
- break;
- case WARNING_LEVEL:
- ReportEvent(event, EVENTLOG_WARNING_TYPE, 0, MSG_DEFAULT, NULL, 1, 0,
- buffmsgptr, NULL);
- break;
- case INFORMATION_LEVEL:
- ReportEvent(event, EVENTLOG_INFORMATION_TYPE, 0, MSG_DEFAULT, NULL, 1,
- 0, buffmsgptr, NULL);
- break;
- }
- DeregisterEventSource(event);
- }
-
- /* if we created a string buffer, then delete it */
- if (buffptr != buff)
- delete[] buffptr;
-
- DBUG_VOID_RETURN;
-}
-#endif /* __NT__ */
-
-
-/*
- Prints a printf style message to the error log and, under NT, to the
- Windows event log.
-
- SYNOPSIS
- vprint_msg_to_log()
- event_type Type of event to write (Error, Warning, or Info)
- format Printf style format of message
- args va_list list of arguments for the message
-
- NOTE
-
- IMPLEMENTATION
- This function prints the message into a buffer and then sends that buffer
- to other functions to write that message to other logging sources.
-
- RETURN VALUES
- The function always returns 0. The return value is present in the
- signature to be compatible with other logging routines, which could
- return an error (e.g. logging to the log tables)
-*/
-
-#ifdef EMBEDDED_LIBRARY
-int vprint_msg_to_log(enum loglevel level __attribute__((unused)),
- const char *format __attribute__((unused)),
- va_list argsi __attribute__((unused)))
-{
- DBUG_ENTER("vprint_msg_to_log");
- DBUG_RETURN(0);
-}
-#else /*!EMBEDDED_LIBRARY*/
-int vprint_msg_to_log(enum loglevel level, const char *format, va_list args)
-{
- char buff[1024];
- uint length;
- DBUG_ENTER("vprint_msg_to_log");
-
- /* "- 5" is because of print_buffer_to_nt_eventlog() */
- length= my_vsnprintf(buff, sizeof(buff) - 5, format, args);
- print_buffer_to_file(level, buff);
-
-#ifdef __NT__
- print_buffer_to_nt_eventlog(level, buff, length, sizeof(buff));
-#endif
-
- DBUG_RETURN(0);
-}
-#endif /*EMBEDDED_LIBRARY*/
-
-
-void sql_print_error(const char *format, ...)
-{
- va_list args;
- DBUG_ENTER("sql_print_error");
-
- va_start(args, format);
- error_log_print(ERROR_LEVEL, format, args);
- va_end(args);
-
- DBUG_VOID_RETURN;
-}
-
-
-void sql_print_warning(const char *format, ...)
-{
- va_list args;
- DBUG_ENTER("sql_print_warning");
-
- va_start(args, format);
- error_log_print(WARNING_LEVEL, format, args);
- va_end(args);
-
- DBUG_VOID_RETURN;
-}
-
-
-void sql_print_information(const char *format, ...)
-{
- va_list args;
- DBUG_ENTER("sql_print_information");
-
- va_start(args, format);
- error_log_print(INFORMATION_LEVEL, format, args);
- va_end(args);
-
DBUG_VOID_RETURN;
}
--- 1.491/sql/mysql_priv.h 2007-03-23 11:47:42 -07:00
+++ 1.492/sql/mysql_priv.h 2007-03-23 11:47:42 -07:00
@@ -577,6 +577,7 @@
#include "protocol.h"
#include "sql_udf.h"
#include "sql_partition.h"
+#include "sql_logger.h"
class user_var_entry;
class Security_context;
@@ -855,7 +856,7 @@
bool do_command(THD *thd);
bool dispatch_command(enum enum_server_command command, THD *thd,
char* packet, uint packet_length);
-void log_slow_statement(THD *thd);
+void post_statement_log(THD *thd);
bool check_dup(const char *db, const char *name, TABLE_LIST *tables);
bool compare_record(TABLE *table);
bool append_file_to_dir(THD *thd, const char **filename_ptr,
@@ -1290,7 +1291,6 @@
void remove_db_from_cache(const char *db);
void flush_tables();
bool is_equal(const LEX_STRING *a, const LEX_STRING *b);
-char *make_default_log_name(char *buff,const char* log_ext);
#ifdef WITH_PARTITION_STORAGE_ENGINE
uint fast_alter_partition_table(THD *thd, TABLE *table,
@@ -1519,26 +1519,6 @@
bool init_errmessage(void);
#endif /* MYSQL_SERVER */
-void sql_perror(const char *message);
-
-
-int vprint_msg_to_log(enum loglevel level, const char *format, va_list args);
-void sql_print_error(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
-void sql_print_warning(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
-void sql_print_information(const char *format, ...)
- ATTRIBUTE_FORMAT(printf, 1, 2);
-typedef void (*sql_print_message_func)(const char *format, ...)
- ATTRIBUTE_FORMAT(printf, 1, 2);
-extern sql_print_message_func sql_print_message_handlers[];
-
-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,...);
bool fn_format_relative_to_data_home(my_string to, const char *name,
const char *dir, const char *extension);
@@ -1680,8 +1660,6 @@
extern const char *log_output_str;
extern MYSQL_BIN_LOG mysql_bin_log;
-extern LOGGER logger;
-extern TABLE_LIST general_log, slow_log;
extern FILE *bootstrap_file;
extern int bootstrap_error;
extern FILE *stderror_file;
@@ -1939,9 +1917,6 @@
LEX_STRING component);
int get_var_with_binlog(THD *thd, enum_sql_command sql_command,
LEX_STRING &name, user_var_entry **out_entry);
-/* log.cc */
-bool flush_error_log(void);
-
/* sql_list.cc */
void free_list(I_List <i_string_pair> *list);
void free_list(I_List <i_string> *list);
--- 1.622/sql/mysqld.cc 2007-03-23 11:47:42 -07:00
+++ 1.623/sql/mysqld.cc 2007-03-23 11:47:42 -07:00
@@ -1171,6 +1171,7 @@
DBUG_PRINT("quit",("done with cleanup in unireg_abort"));
wait_for_signal_thread_to_end();
clean_up_mutexes();
+ logger_cache_done();
my_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
exit(exit_code); /* purecov: inspected */
}
@@ -1183,8 +1184,6 @@
if (cleanup_done++)
return; /* purecov: inspected */
- logger.cleanup_base();
-
/*
make sure that handlers finish up
what they have that is dependent on the binlog
@@ -1239,8 +1238,6 @@
free_defaults(defaults_argv);
my_free(sys_init_connect.value, MYF(MY_ALLOW_ZERO_PTR));
my_free(sys_init_slave.value, MYF(MY_ALLOW_ZERO_PTR));
- my_free(sys_var_general_log_path.value, MYF(MY_ALLOW_ZERO_PTR));
- my_free(sys_var_slow_log_path.value, MYF(MY_ALLOW_ZERO_PTR));
free_tmpdir(&mysql_tmpdir_list);
#ifdef HAVE_REPLICATION
my_free(slave_load_tmpdir,MYF(MY_ALLOW_ZERO_PTR));
@@ -1275,7 +1272,6 @@
MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
DBUG_PRINT("quit", ("Error messages freed"));
/* Tell main we are ready */
- logger.cleanup_end();
(void) pthread_mutex_lock(&LOCK_thread_count);
DBUG_PRINT("quit", ("got thread count lock"));
ready_to_exit=1;
@@ -2484,9 +2480,6 @@
#ifdef EXTRA_DEBUG
sql_print_information("Got signal %d to shutdown mysqld",sig);
#endif
- /* switch to the old log message processing */
- logger.set_handlers(LOG_FILE, opt_slow_log ? LOG_FILE:LOG_NONE,
- opt_log ? LOG_FILE:LOG_NONE);
DBUG_PRINT("info",("Got signal: %d abort_loop: %d",sig,abort_loop));
if (!abort_loop)
{
@@ -2514,9 +2507,6 @@
REFRESH_THREADS | REFRESH_HOSTS),
(TABLE_LIST*) 0, ¬_used); // Flush logs
}
- /* reenable logs after the options were reloaded */
- logger.set_handlers(LOG_FILE, opt_slow_log ? LOG_TABLE:LOG_NONE,
- opt_log ? LOG_TABLE:LOG_NONE);
break;
#ifdef USE_ONE_SIGNAL_HAND
case THR_SERVER_ALARM:
@@ -2709,7 +2699,6 @@
static int init_common_variables(const char *conf_file_name, int argc,
char **argv, const char **groups)
{
- char buff[FN_REFLEN];
umask(((~my_umask) & 0666));
my_decimal_set_zero(&decimal_zero); // set decimal_zero constant;
tzset(); // Set tzname
@@ -2929,29 +2918,6 @@
else
sys_init_slave.value=my_strdup("",MYF(0));
- /* check log options and issue warnings if needed */
- if (opt_log && opt_logname && !(log_output_options & LOG_FILE) &&
- !(log_output_options & LOG_NONE))
- sql_print_warning("Although a path was specified for the "
- "--log option, log tables are used. "
- "To enable logging to files use the --log-output option.");
-
- if (opt_slow_log && opt_slow_logname && !(log_output_options & LOG_FILE)
- && !(log_output_options & LOG_NONE))
- sql_print_warning("Although a path was specified for the "
- "--log-slow-queries option, log tables are used. "
- "To enable logging to files use the --log-output option.");
-
- if (!opt_logname)
- opt_logname= make_default_log_name(buff, ".log");
- sys_var_general_log_path.value= my_strdup(opt_logname, MYF(0));
- sys_var_general_log_path.value_length= strlen(opt_logname);
-
- if (!opt_slow_logname)
- opt_slow_logname= make_default_log_name(buff, "-slow.log");
- sys_var_slow_log_path.value= my_strdup(opt_slow_logname, MYF(0));
- sys_var_slow_log_path.value_length= strlen(opt_slow_logname);
-
if (use_temp_pool && bitmap_init(&temp_pool,0,1024,1))
return 1;
if (my_database_names_init())
@@ -3384,44 +3350,6 @@
unireg_abort(1);
}
-#ifdef WITH_CSV_STORAGE_ENGINE
- if (opt_bootstrap)
- log_output_options= LOG_FILE;
- else
- logger.init_log_tables();
-
- if (log_output_options & LOG_NONE)
- {
- /*
- Issue a warining if there were specified additional options to the
- log-output along with NONE. Probably this wasn't what user wanted.
- */
- if ((log_output_options & LOG_NONE) && (log_output_options & ~LOG_NONE))
- sql_print_warning("There were other values specified to "
- "log-output besides NONE. Disabling slow "
- "and general logs anyway.");
- logger.set_handlers(LOG_FILE, LOG_NONE, LOG_NONE);
- }
- else
- {
- /* fall back to the log files if tables are not present */
- if (have_csv_db == SHOW_OPTION_NO)
- {
- /* purecov: begin inspected */
- sql_print_error("CSV engine is not present, falling back to the "
- "log files");
- log_output_options= (log_output_options & ~LOG_TABLE) | LOG_FILE;
- /* purecov: end */
- }
-
- logger.set_handlers(LOG_FILE, opt_slow_log ? log_output_options:LOG_NONE,
- opt_log ? log_output_options:LOG_NONE);
- }
-#else
- logger.set_handlers(LOG_FILE, opt_slow_log ? LOG_FILE:LOG_NONE,
- opt_log ? LOG_FILE:LOG_NONE);
-#endif
-
/*
Check that the default storage engine is actually available.
*/
@@ -3626,12 +3554,6 @@
MY_INIT(argv[0]); // init my_sys library & pthreads
/* nothing should come before this line ^^^ */
- /*
- Perform basic logger initialization logger. Should be called after
- MY_INIT, as it initializes mutexes. Log tables are inited later.
- */
- logger.init_base();
-
#ifdef _CUSTOMSTARTUPCONFIG_
if (_cust_check_startup())
{
@@ -3640,6 +3562,9 @@
}
#endif
+ /* Initialize error messaging */
+ logger_cache_init();
+
#ifdef __WIN__
/*
Before performing any socket operation (like retrieving hostname
@@ -3914,6 +3839,7 @@
clean_up(1);
wait_for_signal_thread_to_end();
clean_up_mutexes();
+ logger_cache_done();
my_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
exit(0);
@@ -7977,7 +7903,7 @@
{
va_list args;
va_start(args, format);
- vprint_msg_to_log(level, format, args);
+ intern_error_log(NULL, 0, level, format, args);
va_end(args);
}
--- 1.390/sql/sql_base.cc 2007-03-23 11:47:42 -07:00
+++ 1.391/sql/sql_base.cc 2007-03-23 11:47:42 -07:00
@@ -898,7 +898,7 @@
bool found=0;
for (TABLE_LIST *table= tables; table; table= table->next_local)
{
- if ((!table->table || !table->table->s->log_table) &&
+ if (!table->table &&
remove_table_from_cache(thd, table->db, table->table_name,
RTFC_OWNED_BY_THD_FLAG))
found=1;
@@ -933,8 +933,7 @@
for (uint idx=0 ; idx < open_cache.records ; idx++)
{
TABLE *table=(TABLE*) hash_element(&open_cache,idx);
- if (!table->s->log_table &&
- ((table->s->version) < refresh_version && table->db_stat))
+ if ((table->s->version) < refresh_version && table->db_stat)
{
found=1;
DBUG_PRINT("signal", ("Waiting for COND_refresh"));
@@ -2138,7 +2137,7 @@
c1: name lock t2; -- blocks
c2: open t1; -- blocks
*/
- if (table->s->version != refresh_version && !table->s->log_table)
+ if (table->s->version != refresh_version)
{
DBUG_PRINT("note",
("Found table '%s.%s' with different refresh version",
@@ -2513,7 +2512,7 @@
Reopen marked for flush. But close log tables. They are flushed only
explicitly on FLUSH LOGS
*/
- if (table->s->version != refresh_version && !table->s->log_table)
+ if (table->s->version != refresh_version)
{
found=1;
if (table->db_stat)
@@ -2560,10 +2559,10 @@
search= (TABLE*) hash_next(&open_cache, (byte*) key,
key_length, &state))
{
- DBUG_PRINT("info", ("share: 0x%lx locked_by_logger: %d "
+ DBUG_PRINT("info", ("share: 0x%lx "
"locked_by_flush: %d locked_by_name: %d "
"db_stat: %u version: %lu",
- (ulong) search->s, search->locked_by_logger,
+ (ulong) search->s,
search->locked_by_flush, search->locked_by_name,
search->db_stat,
search->s->version));
@@ -2578,8 +2577,7 @@
However we fo not wait if we encountered a table, locked by the logger.
Log tables are managed separately by logging routines.
*/
- if (!search->locked_by_logger &&
- (search->locked_by_name && wait_for_name_lock ||
+ if ((search->locked_by_name && wait_for_name_lock ||
search->locked_by_flush ||
(search->db_stat && search->s->version < refresh_version)))
DBUG_RETURN(1);
--- 1.321/sql/sql_class.cc 2007-03-23 11:47:42 -07:00
+++ 1.322/sql/sql_class.cc 2007-03-23 11:47:42 -07:00
@@ -222,6 +222,7 @@
thread_stack= 0;
db= 0;
catalog= (char*)"std"; // the only catalog we have for now
+ bzero(&logger_cache, sizeof(logger_cache));
main_security_ctx.init();
security_ctx= &main_security_ctx;
locked=some_tables_deleted=no_errors=password= 0;
@@ -502,6 +503,8 @@
cleanup();
ha_close_connection(this);
+
+ logger_cache_release(this);
DBUG_PRINT("info", ("freeing security context"));
main_security_ctx.destroy();
--- 1.349/sql/sql_class.h 2007-03-23 11:47:42 -07:00
+++ 1.350/sql/sql_class.h 2007-03-23 11:47:42 -07:00
@@ -920,6 +920,7 @@
struct system_variables variables; // Changeable local variables
struct system_status_var status_var; // Per thread statistic vars
struct system_status_var *initial_status_var; /* used by show status */
+ struct logger_cache logger_cache; // used for error log plugins
THR_LOCK_INFO lock_info; // Locking info of this thread
THR_LOCK_OWNER main_lock_id; // To use for conventional queries
THR_LOCK_OWNER *lock_id; // If not main_lock_id, points to
--- 1.211/sql/sql_delete.cc 2007-03-23 11:47:42 -07:00
+++ 1.212/sql/sql_delete.cc 2007-03-23 11:47:42 -07:00
@@ -865,9 +865,7 @@
char path[FN_REFLEN];
TABLE *table;
bool error;
- uint closed_log_tables= 0, lock_logger= 0;
uint path_length;
- uint log_type;
DBUG_ENTER("mysql_truncate");
bzero((char*) &create_info,sizeof(create_info));
@@ -919,18 +917,6 @@
DBUG_RETURN(TRUE);
}
- log_type= check_if_log_table(table_list->db_length, table_list->db,
- table_list->table_name_length,
- table_list->table_name, 1);
- /* close log tables in use */
- if (log_type)
- {
- lock_logger= 1;
- logger.lock();
- logger.close_log_table(log_type, FALSE);
- closed_log_tables= closed_log_tables | log_type;
- }
-
// Remove the .frm extension AIX 5.2 64-bit compiler bug (BUG#16155): this
// crashes, replacement works. *(path + path_length - reg_ext_length)=
// '\0';
@@ -961,14 +947,6 @@
VOID(pthread_mutex_lock(&LOCK_open));
unlock_table_name(thd, table_list);
VOID(pthread_mutex_unlock(&LOCK_open));
-
- if (opt_slow_log && (closed_log_tables & QUERY_LOG_SLOW))
- logger.reopen_log_table(QUERY_LOG_SLOW);
-
- if (opt_log && (closed_log_tables & QUERY_LOG_GENERAL))
- logger.reopen_log_table(QUERY_LOG_GENERAL);
- if (lock_logger)
- logger.unlock();
}
else if (error)
{
--- 1.648/sql/sql_parse.cc 2007-03-23 11:47:42 -07:00
+++ 1.649/sql/sql_parse.cc 2007-03-23 11:47:42 -07:00
@@ -620,6 +620,9 @@
thd->clear_error(); // Clear error message
+ /* release cache of logger plugins if neccessary before blocking */
+ logger_cache_check(thd);
+
net_new_transaction(net);
if ((packet_length=my_net_read(net)) == packet_error)
{
@@ -650,6 +653,9 @@
/* Restore read timeout value */
net_set_read_timeout(net, thd->variables.net_read_timeout);
+ /* prepare cache of logger plugins to minimize mutex locking */
+ logger_cache_prepare(thd);
+
/*
packet_length contains length of data, as it was stored in packet
header. In case of malformed header, packet_length can be zero.
@@ -907,7 +913,7 @@
close_thread_tables(thd);
ulong length= (ulong)(packet_end - next_packet);
- log_slow_statement(thd);
+ post_statement_log(thd);
/* Remove garbage at start of query */
while (my_isspace(thd->charset(), *next_packet) && length > 0)
@@ -1266,7 +1272,7 @@
if (thd->net.report_error)
net_send_error(thd);
- log_slow_statement(thd);
+ post_statement_log(thd);
thd->proc_info="cleaning up";
VOID(pthread_mutex_lock(&LOCK_thread_count)); // For process list
@@ -1282,10 +1288,11 @@
}
-void log_slow_statement(THD *thd)
+void post_statement_log(THD *thd)
{
time_t start_of_query;
- DBUG_ENTER("log_slow_statement");
+ ulong long_query_count;
+ DBUG_ENTER("post_statement_log");
/*
The following should never be true with our current code base,
@@ -1296,26 +1303,20 @@
DBUG_VOID_RETURN; // Don't set time for sub stmt
start_of_query= thd->start_time;
- thd->end_time(); // Set start time
+ long_query_count= thd->status_var.long_query_count;
+
+ mysql_suffix_log(thd, start_of_query, WARNING_LEVEL,
+ "%.*b", thd->query_length, thd->query);
+
+ thd->end_time();
/*
- Do not log administrative statements unless the appropriate option is
- set; do not log into slow log if reading from backup.
+ Ensure that even if we do have multiple slow logging, that
+ we only increment the long_query_count by one
*/
- if (thd->enable_slow_log && !thd->user_time)
- {
- thd->proc_info="logging slow query";
+ if (long_query_count != thd->status_var.long_query_count)
+ thd->status_var.long_query_count= long_query_count + 1;
- if ((ulong) (thd->start_time - thd->time_after_lock) >
- thd->variables.long_query_time ||
- ((thd->server_status &
- (SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED)) &&
- (specialflag & SPECIAL_LOG_QUERIES_NOT_USING_INDEXES)))
- {
- thd->status_var.long_query_count++;
- slow_log_print(thd, thd->query, thd->query_length, start_of_query);
- }
- }
DBUG_VOID_RETURN;
}
@@ -6101,12 +6102,9 @@
pthread_mutex_unlock(&LOCK_active_mi);
#endif
- /* flush slow and general logs */
- logger.flush_logs(thd);
-
if (ha_flush_logs(NULL))
result=1;
- if (flush_error_log())
+ if (flush_error_log(thd))
result=1;
}
#ifdef HAVE_QUERY_CACHE
--- 1.399/sql/sql_table.cc 2007-03-23 11:47:42 -07:00
+++ 1.400/sql/sql_table.cc 2007-03-23 11:47:42 -07:00
@@ -1636,15 +1636,6 @@
table->db_type= NULL;
if ((share= get_cached_table_share(table->db, table->table_name)))
table->db_type= share->db_type;
-
- /* Disable drop of enabled log tables */
- if (share && share->log_table &&
- check_if_log_table(table->db_length, table->db,
- table->table_name_length, table->table_name, 1))
- {
- my_error(ER_BAD_LOG_STATEMENT, MYF(0), "DROP");
- DBUG_RETURN(1);
- }
}
if (!drop_temporary && lock_table_names(thd, tables))
@@ -4044,7 +4035,7 @@
Item *item;
Protocol *protocol= thd->protocol;
LEX *lex= thd->lex;
- int result_code, disable_logs= 0;
+ int result_code;
DBUG_ENTER("mysql_admin_table");
if (end_active_trans(thd))
@@ -4092,22 +4083,6 @@
if (view_operator_func == NULL)
table->required_type=FRMTYPE_TABLE;
- /*
- If we want to perform an admin operation on the log table
- (E.g. rename) and lock_type >= TL_READ_NO_INSERT disable
- log tables
- */
-
- if (check_if_log_table(table->db_length, table->db,
- table->table_name_length,
- table->table_name, 1) &&
- lock_type >= TL_READ_NO_INSERT)
- {
- disable_logs= 1;
- logger.lock();
- logger.tmp_close_log_tables(thd);
- }
-
open_and_lock_tables(thd, table);
thd->no_warnings_for_error= 0;
table->next_global= save_next_global;
@@ -4195,8 +4170,7 @@
}
/* Close all instances of the table to allow repair to rename files */
- if (lock_type == TL_WRITE && table->table->s->version &&
- !table->table->s->log_table)
+ if (lock_type == TL_WRITE && table->table->s->version)
{
pthread_mutex_lock(&LOCK_open);
const char *old_message=thd->enter_cond(&COND_refresh, &LOCK_open,
@@ -4400,7 +4374,7 @@
/* in the below check we do not refresh the log tables */
if (fatal_error)
table->table->s->version=0; // Force close of table
- else if (open_for_modify && !table->table->s->log_table)
+ else if (open_for_modify)
{
if (table->table->s->tmp_table)
table->table->file->info(HA_STATUS_CONST);
@@ -4423,24 +4397,11 @@
}
send_eof(thd);
- if (disable_logs)
- {
- if (logger.reopen_log_tables())
- my_error(ER_CANT_ACTIVATE_LOG, MYF(0));
- logger.unlock();
- }
DBUG_RETURN(FALSE);
err:
ha_autocommit_or_rollback(thd, 1);
close_thread_tables(thd); // Shouldn't be needed
- /* enable logging back if needed */
- if (disable_logs)
- {
- if (logger.reopen_log_tables())
- my_error(ER_CANT_ACTIVATE_LOG, MYF(0));
- logger.unlock();
- }
if (table)
table->table=0;
DBUG_RETURN(TRUE);
@@ -5344,32 +5305,6 @@
LINT_INIT(index_drop_count);
LINT_INIT(index_add_buffer);
LINT_INIT(index_drop_buffer);
-
- if (table_list && table_list->db && table_list->table_name)
- {
- int table_kind= 0;
-
- table_kind= check_if_log_table(table_list->db_length, table_list->db,
- table_list->table_name_length,
- table_list->table_name, 0);
-
- /* Disable alter of enabled log tables */
- if (table_kind && logger.is_log_table_enabled(table_kind))
- {
- my_error(ER_BAD_LOG_STATEMENT, MYF(0), "ALTER");
- DBUG_RETURN(TRUE);
- }
-
- /* Disable alter of log tables to unsupported engine */
- if (table_kind &&
- (lex_create_info->used_fields & HA_CREATE_USED_ENGINE) &&
- (!lex_create_info->db_type || /* unknown engine */
- !(lex_create_info->db_type->flags & HTON_SUPPORT_LOG_TABLES)))
- {
- my_error(ER_UNSUPORTED_LOG_ENGINE, MYF(0));
- DBUG_RETURN(TRUE);
- }
- }
thd->proc_info="init";
if (!(create_info= copy_create_info(lex_create_info)))
--- 1.281/sql/table.cc 2007-03-23 11:47:42 -07:00
+++ 1.282/sql/table.cc 2007-03-23 11:47:42 -07:00
@@ -411,12 +411,6 @@
*/
share->system_table= is_system_table_name(share->table_name.str,
share->table_name.length);
- if (!share->system_table)
- {
- share->log_table= check_if_log_table(share->db.length, share->db.str,
- share->table_name.length,
- share->table_name.str, 0);
- }
}
error_given= 1;
}
--- 1.163/sql/table.h 2007-03-23 11:47:42 -07:00
+++ 1.164/sql/table.h 2007-03-23 11:47:42 -07:00
@@ -229,11 +229,6 @@
locking of this table for writing. FALSE - otherwise.
*/
bool system_table;
- /*
- This flag is set for the log tables. Used during FLUSH instances to skip
- log tables, while closing tables (since logs must be always available)
- */
- bool log_table;
#ifdef WITH_PARTITION_STORAGE_ENGINE
bool auto_partitioned;
const uchar *partition_info;
@@ -432,7 +427,6 @@
my_bool distinct,const_table,no_rows;
my_bool key_read, no_keyread;
my_bool locked_by_flush;
- my_bool locked_by_logger;
my_bool no_replicate;
my_bool locked_by_name;
my_bool fulltext_searched;
--- 1.37/sql/event_scheduler.cc 2007-03-23 11:47:42 -07:00
+++ 1.38/sql/event_scheduler.cc 2007-03-23 11:47:42 -07:00
@@ -96,9 +96,22 @@
err_msg.append(prefix);
err_msg.append(err->msg, strlen(err->msg), system_charset_info);
err_msg.append("]");
- DBUG_ASSERT(err->level < 3);
- (sql_print_message_handlers[err->level])("%*s", err_msg.length(),
- err_msg.c_ptr());
+ switch (err->level) {
+ case MYSQL_ERROR::WARN_LEVEL_NOTE:
+ mysql_error_log(thd, time(NULL), INFORMATION_LEVEL,
+ "%*s", err_msg.length(), err_msg.c_ptr_quick());
+ continue;
+ case MYSQL_ERROR::WARN_LEVEL_WARN:
+ mysql_error_log(thd, time(NULL), WARNING_LEVEL,
+ "%*s", err_msg.length(), err_msg.c_ptr_quick());
+ continue;
+ case MYSQL_ERROR::WARN_LEVEL_ERROR:
+ mysql_error_log(thd, time(NULL), ERROR_LEVEL,
+ "%*s", err_msg.length(), err_msg.c_ptr_quick());
+ continue;
+ default:
+ DBUG_ASSERT(0);
+ }
}
DBUG_VOID_RETURN;
}
--- 1.76/storage/csv/ha_tina.cc 2007-03-23 11:47:42 -07:00
+++ 1.77/storage/csv/ha_tina.cc 2007-03-23 11:47:42 -07:00
@@ -785,18 +785,6 @@
}
-bool ha_tina::check_if_locking_is_allowed(uint sql_command,
- ulong type, TABLE *table,
- uint count, uint current,
- uint *system_count,
- bool called_by_privileged_thread)
-{
- if (!called_by_privileged_thread)
- return check_if_log_table_locking_is_allowed(sql_command, type, table);
-
- return TRUE;
-}
-
/*
Open a database file. Keep in mind that tables are caches, so
this will not be called for every request. Any sort of positions
--- 1.28/storage/csv/ha_tina.h 2007-03-23 11:47:42 -07:00
+++ 1.29/storage/csv/ha_tina.h 2007-03-23 11:47:42 -07:00
@@ -126,11 +126,6 @@
*/
ha_rows estimate_rows_upper_bound() { return HA_POS_ERROR; }
- virtual bool check_if_locking_is_allowed(uint sql_command,
- ulong type, TABLE *table,
- uint count, uint current,
- uint *system_count,
- bool called_by_logger_thread);
int open(const char *name, int mode, uint open_options);
int close(void);
int write_row(byte * buf);
--- 1.24/sql/log.h 2007-03-23 11:47:42 -07:00
+++ 1.25/sql/log.h 2007-03-23 11:47:42 -07:00
@@ -384,223 +384,6 @@
inline uint32 get_open_count() { return open_count; }
};
-class Log_event_handler
-{
-public:
- Log_event_handler() {}
- virtual bool init()= 0;
- virtual void cleanup()= 0;
-
- virtual bool log_slow(THD *thd, time_t current_time,
- time_t query_start_arg, const char *user_host,
- uint user_host_len, longlong query_time,
- longlong lock_time, bool is_command,
- const char *sql_text, uint sql_text_len)= 0;
- virtual bool log_error(enum loglevel level, const char *format,
- va_list args)= 0;
- virtual bool log_general(time_t event_time, const char *user_host,
- uint user_host_len, int thread_id,
- const char *command_type, uint command_type_len,
- const char *sql_text, uint sql_text_len,
- CHARSET_INFO *client_cs)= 0;
- virtual ~Log_event_handler() {}
-};
-
-
-int check_if_log_table(uint db_len, const char *db, uint table_name_len,
- const char *table_name, uint check_if_opened);
-
-class Log_to_csv_event_handler: public Log_event_handler
-{
- /*
- We create artificial THD for each of the logs. This is to avoid
- locking issues: we don't want locks on the log tables reside in the
- THD's of the query. The reason is the locking order and duration.
- */
- THD *general_log_thd, *slow_log_thd;
- /*
- This is for the thread, which called tmp_close_log_tables. The thread
- will be allowed to write-lock the log tables (as it explicitly disabled
- logging). This is used for such operations as REPAIR, which require
- exclusive lock on the log tables.
- NOTE: there can be only one priviliged thread, as one should
- lock logger with logger.lock() before calling tmp_close_log_tables().
- So no other thread could get privileged status at the same time.
- */
- THD *privileged_thread;
- friend class LOGGER;
- TABLE_LIST general_log, slow_log;
-
-private:
- bool open_log_table(uint log_type);
-
-public:
- Log_to_csv_event_handler();
- ~Log_to_csv_event_handler();
- virtual bool init();
- virtual void cleanup();
-
- virtual bool log_slow(THD *thd, time_t current_time,
- time_t query_start_arg, const char *user_host,
- uint user_host_len, longlong query_time,
- longlong lock_time, bool is_command,
- const char *sql_text, uint sql_text_len);
- virtual bool log_error(enum loglevel level, const char *format,
- va_list args);
- virtual bool log_general(time_t event_time, const char *user_host,
- uint user_host_len, int thread_id,
- const char *command_type, uint command_type_len,
- const char *sql_text, uint sql_text_len,
- CHARSET_INFO *client_cs);
- void tmp_close_log_tables(THD *thd);
- void close_log_table(uint log_type, bool lock_in_use);
- bool reopen_log_table(uint log_type);
- THD* get_privileged_thread()
- {
- return privileged_thread;
- }
-};
-
-
-/* type of the log table */
-#define QUERY_LOG_SLOW 1
-#define QUERY_LOG_GENERAL 2
-
-class Log_to_file_event_handler: public Log_event_handler
-{
- MYSQL_QUERY_LOG mysql_log;
- MYSQL_QUERY_LOG mysql_slow_log;
- bool is_initialized;
-public:
- Log_to_file_event_handler(): is_initialized(FALSE)
- {}
- virtual bool init();
- virtual void cleanup();
-
- virtual bool log_slow(THD *thd, time_t current_time,
- time_t query_start_arg, const char *user_host,
- uint user_host_len, longlong query_time,
- longlong lock_time, bool is_command,
- const char *sql_text, uint sql_text_len);
- virtual bool log_error(enum loglevel level, const char *format,
- va_list args);
- virtual bool log_general(time_t event_time, const char *user_host,
- uint user_host_len, int thread_id,
- const char *command_type, uint command_type_len,
- const char *sql_text, uint sql_text_len,
- CHARSET_INFO *client_cs);
- void flush();
- void init_pthread_objects();
- MYSQL_QUERY_LOG *get_mysql_slow_log() { return &mysql_slow_log; }
- MYSQL_QUERY_LOG *get_mysql_log() { return &mysql_log; }
-};
-
-
-/* Class which manages slow, general and error log event handlers */
-class LOGGER
-{
- pthread_mutex_t LOCK_logger;
- /* flag to check whether logger mutex is initialized */
- uint inited;
-
- /* available log handlers */
- Log_to_csv_event_handler *table_log_handler;
- Log_to_file_event_handler *file_log_handler;
-
- /* NULL-terminated arrays of log handlers */
- Log_event_handler *error_log_handler_list[MAX_LOG_HANDLERS_NUM + 1];
- Log_event_handler *slow_log_handler_list[MAX_LOG_HANDLERS_NUM + 1];
- Log_event_handler *general_log_handler_list[MAX_LOG_HANDLERS_NUM + 1];
-
-public:
-
- bool is_log_tables_initialized;
-
- LOGGER() : inited(0), table_log_handler(NULL),
- file_log_handler(NULL), is_log_tables_initialized(FALSE)
- {}
- void lock() { (void) pthread_mutex_lock(&LOCK_logger); }
- void unlock() { (void) pthread_mutex_unlock(&LOCK_logger); }
- void tmp_close_log_tables(THD *thd);
- bool is_log_table_enabled(uint log_table_type)
- {
- switch (log_table_type) {
- case QUERY_LOG_SLOW:
- return table_log_handler && table_log_handler->slow_log.table != 0;
- case QUERY_LOG_GENERAL:
- return table_log_handler && table_log_handler->general_log.table != 0;
- default:
- DBUG_ASSERT(0);
- return FALSE; /* make compiler happy */
- }
- }
- /*
- We want to initialize all log mutexes as soon as possible,
- but we cannot do it in constructor, as safe_mutex relies on
- initialization, performed by MY_INIT(). This why this is done in
- this function.
- */
- void init_base();
- void init_log_tables();
- bool flush_logs(THD *thd);
- THD *get_general_log_thd()
- {
- if (table_log_handler)
- return (THD *) table_log_handler->general_log_thd;
- else
- return NULL;
- }
- THD *get_slow_log_thd()
- {
- if (table_log_handler)
- return (THD *) table_log_handler->slow_log_thd;
- else
- return NULL;
- }
- /* Perform basic logger cleanup. this will leave e.g. error log open. */
- void cleanup_base();
- /* Free memory. Nothing could be logged after this function is called */
- void cleanup_end();
- bool 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, va_list args);
-
- void close_log_table(uint log_type, bool lock_in_use);
- bool reopen_log_table(uint log_type);
- bool reopen_log_tables();
-
- /* we use this function to setup all enabled log event handlers */
- int set_handlers(uint error_log_printer,
- uint slow_log_printer,
- uint general_log_printer);
- void init_error_log(uint error_log_printer);
- void init_slow_log(uint slow_log_printer);
- void init_general_log(uint general_log_printer);
- void deactivate_log_handler(THD* thd, uint log_type);
- bool activate_log_handler(THD* thd, uint log_type);
- MYSQL_QUERY_LOG *get_slow_log_file_handler()
- {
- if (file_log_handler)
- return file_log_handler->get_mysql_slow_log();
- return NULL;
- }
- MYSQL_QUERY_LOG *get_log_file_handler()
- {
- if (file_log_handler)
- return file_log_handler->get_mysql_log();
- return NULL;
- }
- THD* get_privileged_thread()
- {
- if (table_log_handler)
- return table_log_handler->get_privileged_thread();
- else
- return NULL;
- }
-};
enum enum_binlog_format {
BINLOG_FORMAT_STMT= 0, // statement-based
--- 1.222/sql/set_var.cc 2007-03-23 11:47:42 -07:00
+++ 1.223/sql/set_var.cc 2007-03-23 11:47:42 -07:00
@@ -154,11 +154,6 @@
static byte *get_error_count(THD *thd);
static byte *get_warning_count(THD *thd);
static byte *get_tmpdir(THD *thd);
-static int sys_check_log_path(THD *thd, set_var *var);
-static bool sys_update_general_log_path(THD *thd, set_var * var);
-static void sys_default_general_log_path(THD *thd, enum_var_type type);
-static bool sys_update_slow_log_path(THD *thd, set_var * var);
-static void sys_default_slow_log_path(THD *thd, enum_var_type type);
/*
Variable definition list
@@ -685,22 +680,6 @@
sys_var_have_variable sys_have_symlink("have_symlink", &have_symlink);
/* Global read-only variable describing server license */
sys_var_const_str sys_license("license", STRINGIFY_ARG(LICENSE));
-/* Global variables which enable|disable logging */
-sys_var_log_state sys_var_general_log("general_log", &opt_log,
- QUERY_LOG_GENERAL);
-sys_var_log_state sys_var_slow_query_log("slow_query_log", &opt_slow_log,
- QUERY_LOG_SLOW);
-sys_var_str sys_var_general_log_path("general_log_file", sys_check_log_path,
- sys_update_general_log_path,
- sys_default_general_log_path,
- opt_logname);
-sys_var_str sys_var_slow_log_path("slow_query_log_file", sys_check_log_path,
- sys_update_slow_log_path,
- sys_default_slow_log_path,
- opt_slow_logname);
-sys_var_log_output sys_var_log_output_state("log_output", &log_output_options,
- &log_output_typelib, 0);
-
#ifdef HAVE_REPLICATION
static int show_slave_skip_errors(THD *thd, SHOW_VAR *var, char *buff)
{
@@ -790,8 +769,6 @@
{"ft_min_word_len", (char*) &ft_min_word_len, SHOW_LONG},
{"ft_query_expansion_limit",(char*) &ft_query_expansion_limit, SHOW_LONG},
{"ft_stopword_file", (char*) &ft_stopword_file, SHOW_CHAR_PTR},
- {sys_var_general_log.name, (char*) &opt_log, SHOW_MY_BOOL},
- {sys_var_general_log_path.name, (char*) &sys_var_general_log_path, SHOW_SYS},
{sys_group_concat_max_len.name, (char*) &sys_group_concat_max_len, SHOW_SYS},
{sys_hostname.name, (char*) &sys_hostname, SHOW_SYS},
{sys_have_compress.name, (char*) &have_compress, SHOW_HAVE},
@@ -869,7 +846,6 @@
{"log_bin", (char*) &opt_bin_log, SHOW_BOOL},
{sys_trust_function_creators.name,(char*) &sys_trust_function_creators, SHOW_SYS},
{"log_error", (char*) log_error_file, SHOW_CHAR},
- {sys_var_log_output_state.name, (char*) &sys_var_log_output_state, SHOW_SYS},
{sys_log_queries_not_using_indexes.name,
(char*) &sys_log_queries_not_using_indexes, SHOW_SYS},
#ifdef HAVE_REPLICATION
@@ -995,8 +971,6 @@
{sys_slave_trans_retries.name,(char*) &sys_slave_trans_retries, SHOW_SYS},
#endif
{sys_slow_launch_time.name, (char*) &sys_slow_launch_time, SHOW_SYS},
- {sys_var_slow_query_log.name, (char*) &opt_slow_log, SHOW_MY_BOOL},
- {sys_var_slow_log_path.name, (char*) &sys_var_slow_log_path, SHOW_SYS},
#ifdef HAVE_SYS_UN_H
{"socket", (char*) &mysqld_unix_port, SHOW_CHAR_PTR},
#endif
@@ -2531,207 +2505,6 @@
end:
pthread_mutex_unlock(&LOCK_global_system_variables);
return error;
-}
-
-
-bool sys_var_log_state::update(THD *thd, set_var *var)
-{
- bool res= 0;
- pthread_mutex_lock(&LOCK_global_system_variables);
- if (!var->save_result.ulong_value)
- logger.deactivate_log_handler(thd, log_type);
- else
- {
- if ((res= logger.activate_log_handler(thd, log_type)))
- {
- my_error(ER_CANT_ACTIVATE_LOG, MYF(0),
- log_type == QUERY_LOG_GENERAL ? "general" :
- "slow query");
- goto err;
- }
- }
-err:
- pthread_mutex_unlock(&LOCK_global_system_variables);
- return res;
-}
-
-void sys_var_log_state::set_default(THD *thd, enum_var_type type)
-{
- pthread_mutex_lock(&LOCK_global_system_variables);
- logger.deactivate_log_handler(thd, log_type);
- pthread_mutex_unlock(&LOCK_global_system_variables);
-}
-
-
-static int sys_check_log_path(THD *thd, set_var *var)
-{
- char path[FN_REFLEN];
- MY_STAT f_stat;
- const char *var_path= var->value->str_value.ptr();
- bzero(&f_stat, sizeof(MY_STAT));
-
- (void) unpack_filename(path, var_path);
- if (my_stat(path, &f_stat, MYF(0)))
- {
- /* Check if argument is a file and we have 'write' permission */
- if (!MY_S_ISREG(f_stat.st_mode) ||
- !(f_stat.st_mode & MY_S_IWRITE))
- return -1;
- }
- else
- {
- /*
- Check if directory exists and
- we have permission to create file & write to file
- */
- (void) dirname_part(path, var_path);
- if (my_access(path, (F_OK|W_OK)))
- return -1;
- }
- return 0;
-}
-
-
-bool update_sys_var_str_path(THD *thd, sys_var_str *var_str,
- set_var *var, const char *log_ext,
- bool log_state, uint log_type)
-{
- MYSQL_QUERY_LOG *file_log;
- char buff[FN_REFLEN];
- char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0);
- bool result= 0;
- uint str_length= (var ? var->value->str_value.length() : 0);
-
- switch (log_type) {
- case QUERY_LOG_SLOW:
- file_log= logger.get_slow_log_file_handler();
- break;
- case QUERY_LOG_GENERAL:
- file_log= logger.get_log_file_handler();
- break;
- default:
- assert(0); // Impossible
- }
-
- if (!old_value)
- {
- old_value= make_default_log_name(buff, log_ext);
- str_length= strlen(old_value);
- }
- if (!(res= my_strndup(old_value, str_length, MYF(MY_FAE+MY_WME))))
- {
- result= 1;
- goto err;
- }
-
- pthread_mutex_lock(&LOCK_global_system_variables);
- logger.lock();
-
- if (file_log && log_state)
- file_log->close(0);
- old_value= var_str->value;
- var_str->value= res;
- var_str->value_length= str_length;
- my_free(old_value, MYF(MY_ALLOW_ZERO_PTR));
- if (file_log && log_state)
- {
- switch (log_type) {
- case QUERY_LOG_SLOW:
- file_log->open_slow_log(sys_var_slow_log_path.value);
- break;
- case QUERY_LOG_GENERAL:
- file_log->open_query_log(sys_var_general_log_path.value);
- break;
- default:
- DBUG_ASSERT(0);
- }
- }
-
- logger.unlock();
- pthread_mutex_unlock(&LOCK_global_system_variables);
-
-err:
- return result;
-}
-
-
-static bool sys_update_general_log_path(THD *thd, set_var * var)
-{
- return update_sys_var_str_path(thd, &sys_var_general_log_path,
- var, ".log", opt_log, QUERY_LOG_GENERAL);
-}
-
-
-static void sys_default_general_log_path(THD *thd, enum_var_type type)
-{
- (void) update_sys_var_str_path(thd, &sys_var_general_log_path,
- 0, ".log", opt_log, QUERY_LOG_GENERAL);
-}
-
-
-static bool sys_update_slow_log_path(THD *thd, set_var * var)
-{
- return update_sys_var_str_path(thd, &sys_var_slow_log_path,
- var, "-slow.log", opt_slow_log,
- QUERY_LOG_SLOW);
-}
-
-
-static void sys_default_slow_log_path(THD *thd, enum_var_type type)
-{
- (void) update_sys_var_str_path(thd, &sys_var_slow_log_path,
- 0, "-slow.log", opt_slow_log,
- QUERY_LOG_SLOW);
-}
-
-
-bool sys_var_log_output::update(THD *thd, set_var *var)
-{
- pthread_mutex_lock(&LOCK_global_system_variables);
- logger.lock();
- logger.init_slow_log(var->save_result.ulong_value);
- logger.init_general_log(var->save_result.ulong_value);
- *value= var->save_result.ulong_value;
- logger.unlock();
- pthread_mutex_unlock(&LOCK_global_system_variables);
- return 0;
-}
-
-
-void sys_var_log_output::set_default(THD *thd, enum_var_type type)
-{
- pthread_mutex_lock(&LOCK_global_system_variables);
- logger.lock();
- logger.init_slow_log(LOG_TABLE);
- logger.init_general_log(LOG_TABLE);
- *value= LOG_TABLE;
- logger.unlock();
- pthread_mutex_unlock(&LOCK_global_system_variables);
-}
-
-
-byte *sys_var_log_output::value_ptr(THD *thd, enum_var_type type,
- LEX_STRING *base)
-{
- char buff[256];
- String tmp(buff, sizeof(buff), &my_charset_latin1);
- ulong length;
- ulong val= *value;
-
- tmp.length(0);
- for (uint i= 0; val; val>>= 1, i++)
- {
- if (val & 1)
- {
- tmp.append(log_output_typelib.type_names[i],
- log_output_typelib.type_lengths[i]);
- tmp.append(',');
- }
- }
-
- if ((length= tmp.length()))
- length--;
- return (byte*) thd->strmake(tmp.ptr(), length);
}
--- 1.46/sql/sql_plugin.cc 2007-03-23 11:47:42 -07:00
+++ 1.47/sql/sql_plugin.cc 2007-03-23 11:47:42 -07:00
@@ -23,16 +23,20 @@
char *opt_plugin_dir_ptr;
char opt_plugin_dir[FN_REFLEN];
/*
- When you ad a new plugin type, add both a string and make sure that the
+ When you add a new plugin type, add both a string and make sure that the
init and deinit array are correctly updated.
+ The final entry is unused and is present only to ensure that addional
+ lines may be added without requiring the previous line to be edited.
*/
-const LEX_STRING plugin_type_names[MYSQL_MAX_PLUGIN_TYPE_NUM]=
+const LEX_STRING plugin_type_names[MYSQL_MAX_PLUGIN_TYPE_NUM+1]=
{
{ C_STRING_WITH_LEN("UDF") },
{ C_STRING_WITH_LEN("STORAGE ENGINE") },
{ C_STRING_WITH_LEN("FTPARSER") },
{ C_STRING_WITH_LEN("DAEMON") },
- { C_STRING_WITH_LEN("INFORMATION SCHEMA") }
+ { C_STRING_WITH_LEN("INFORMATION SCHEMA") },
+ { C_STRING_WITH_LEN("LOGGING") },
+ { NULL, 0 }
};
extern int initialize_schema_table(st_plugin_int *plugin);
@@ -42,15 +46,28 @@
The number of elements in both plugin_type_initialize and
plugin_type_deinitialize should equal to the number of plugins
defined.
+ The final entry is unused and is present only to ensure that addional
+ lines may be added without requiring the previous line to be edited.
*/
-plugin_type_init plugin_type_initialize[MYSQL_MAX_PLUGIN_TYPE_NUM]=
+plugin_type_init plugin_type_initialize[MYSQL_MAX_PLUGIN_TYPE_NUM+1]=
{
- 0,ha_initialize_handlerton,0,0,initialize_schema_table
+ 0,ha_initialize_handlerton,0,0,initialize_schema_table,
+ initialize_logger,
+ NULL
};
-plugin_type_init plugin_type_deinitialize[MYSQL_MAX_PLUGIN_TYPE_NUM]=
+plugin_type_init plugin_type_deinitialize[MYSQL_MAX_PLUGIN_TYPE_NUM+1]=
{
- 0,ha_finalize_handlerton,0,0,finalize_schema_table
+ 0,ha_finalize_handlerton,0,0,finalize_schema_table,
+ finalize_logger,
+ NULL
+};
+
+plugin_type_notify plugin_type_notifydel[MYSQL_MAX_PLUGIN_TYPE_NUM+1]=
+{
+ 0,0,0,0,0,
+ logger_cache_notify,
+ NULL
};
#ifdef HAVE_DLOPEN
@@ -64,22 +81,28 @@
/* Note that 'int version' must be the first field of every plugin
sub-structure (plugin->info).
+ The final entry is unused and is present only to ensure that addional
+ lines may be added without requiring the previous line to be edited.
*/
-static int min_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
+static int min_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM+1]=
{
0x0000,
MYSQL_HANDLERTON_INTERFACE_VERSION,
MYSQL_FTPARSER_INTERFACE_VERSION,
MYSQL_DAEMON_INTERFACE_VERSION,
- MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION
+ MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION,
+ MYSQL_LOGGING_INTERFACE_VERSION,
+ 0
};
-static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
+static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM+1]=
{
0x0000, /* UDF: not implemented */
MYSQL_HANDLERTON_INTERFACE_VERSION,
MYSQL_FTPARSER_INTERFACE_VERSION,
MYSQL_DAEMON_INTERFACE_VERSION,
- MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION
+ MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION,
+ MYSQL_LOGGING_INTERFACE_VERSION,
+ 0
};
static DYNAMIC_ARRAY plugin_dl_array;
@@ -411,6 +434,35 @@
}
+struct st_plugin_int **plugin_lockall(int type)
+{
+ struct st_plugin_int **plugins, **list;
+ struct st_plugin_int *plugin;
+ HASH *hash= plugin_hash+ type;
+ uint idx, total;
+ DBUG_ENTER("plugin_lockall");
+ rw_wrlock(&THR_LOCK_plugin);
+ total= hash->records;
+ if ((plugins= (struct st_plugin_int **) my_malloc(sizeof(void*)*(total+1),
+ MYF(MY_WME))))
+ {
+ list= plugins;
+ for (idx= 0; idx < total; idx++)
+ {
+ plugin= (struct st_plugin_int *) hash_element(hash, idx);
+ if (plugin->state & (PLUGIN_IS_READY | PLUGIN_IS_UNINITIALIZED))
+ {
+ plugin->ref_count++;
+ *list++= plugin;
+ }
+ }
+ }
+ rw_unlock(&THR_LOCK_plugin);
+ *list= NULL;
+ DBUG_RETURN(plugins);
+}
+
+
static st_plugin_int *plugin_insert_or_reuse(struct st_plugin_int *plugin)
{
uint i;
@@ -477,6 +529,7 @@
tmp.name.length= name_len;
tmp.ref_count= 0;
tmp.state= PLUGIN_IS_UNINITIALIZED;
+ tmp.data= NULL;
if (! (tmp_plugin_ptr= plugin_insert_or_reuse(&tmp)))
goto err;
plugin_array_version++;
@@ -581,6 +634,30 @@
}
+void plugin_unlockall(struct st_plugin_int **plugins)
+{
+ struct st_plugin_int *plugin, **list;
+ DBUG_ENTER("plugin_unlockall");
+ if ((list= plugins))
+ {
+ rw_wrlock(&THR_LOCK_plugin);
+ while ((plugin= *list++))
+ {
+ DBUG_ASSERT(plugin && plugin->ref_count);
+ plugin->ref_count--;
+ if (plugin->state == PLUGIN_IS_DELETED && ! plugin->ref_count)
+ {
+ plugin_deinitialize(plugin);
+ plugin_del(plugin);
+ }
+ }
+ rw_unlock(&THR_LOCK_plugin);
+ my_free((gptr) plugins, MYF(0));
+ }
+ DBUG_VOID_RETURN;
+}
+
+
static int plugin_initialize(struct st_plugin_int *plugin)
{
DBUG_ENTER("plugin_initialize");
@@ -732,6 +809,7 @@
tmp.name.str= (char *)plugin->name;
tmp.name.length= strlen(plugin->name);
tmp.state= PLUGIN_IS_UNINITIALIZED;
+ tmp.data= NULL;
/* Cannot be unloaded */
tmp.ref_count= 1;
@@ -933,6 +1011,8 @@
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
"Plugin is busy and will be uninstalled on shutdown");
plugin->state= PLUGIN_IS_DELETED;
+ if (plugin_type_notifydel[plugin->plugin->type])
+ plugin_type_notifydel[plugin->plugin->type]();
}
else
{
--- 1.134/libmysqld/lib_sql.cc 2007-03-23 11:47:42 -07:00
+++ 1.135/libmysqld/lib_sql.cc 2007-03-23 11:47:42 -07:00
@@ -470,12 +470,6 @@
my_progname= (char *)"mysql_embedded";
- /*
- Perform basic logger initialization logger. Should be called after
- MY_INIT, as it initializes mutexes. Log tables are inited later.
- */
- logger.init_base();
-
if (init_common_variables("my", *argcp, *argvp, (const char **)groups))
{
mysql_server_end();
--- 1.261/sql/sp_head.cc 2007-03-23 11:47:42 -07:00
+++ 1.262/sql/sp_head.cc 2007-03-23 11:47:42 -07:00
@@ -2559,9 +2559,9 @@
thd->query, thd->query_length) <= 0)
{
res= m_lex_keeper.reset_lex_and_exec_core(thd, nextp, FALSE, this);
- if (!res && unlikely(thd->enable_slow_log))
- log_slow_statement(thd);
query_cache_end_of_result(thd);
+ if (!res)
+ post_statement_log(thd);
}
else
*nextp= m_ip+1;
| Thread |
|---|
| • bk commit into 5.1 tree (acurtis:1.2504) | antony | 23 Mar |