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-12 08:58:32-07:00, acurtis@stripped +7 -0
Temporary commit for work in progress.
Will be collapsed at a later date.
sql/sql_class.cc@stripped, 2007-03-12 08:58:28-07:00, acurtis@stripped +3 -0
initialize/finalize logger cache structure
sql/sql_class.h@stripped, 2007-03-12 08:58:28-07:00, acurtis@stripped +1 -0
logger cache in thd
sql/sql_logger.cc@stripped, 2007-03-12 08:58:28-07:00, acurtis@stripped +90 -5
implement logger cache structure to minimize the amount of times that mutex locking
occurs.
sql/sql_logger.h@stripped, 2007-03-12 08:58:28-07:00, acurtis@stripped +15 -0
implement logger cache structure to minimize the amount of times that mutex locking
occurs.
sql/sql_parse.cc@stripped, 2007-03-12 08:58:29-07:00, acurtis@stripped +6 -0
implement logger cache to minimize the amount of times that mutex locking occurs.
sql/sql_plugin.cc@stripped, 2007-03-12 08:58:29-07:00, acurtis@stripped +62 -0
notify on delete requested callback
new functions: plugin_lockall() and plugin_unlockall()
sql/sql_plugin.h@stripped, 2007-03-12 08:58:29-07:00, acurtis@stripped +3 -0
new functions: plugin_lockall() and plugin_unlockall()
# 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.2
--- 1.315/sql/sql_class.cc 2007-03-12 08:58:47 -07:00
+++ 1.316/sql/sql_class.cc 2007-03-12 08:58:47 -07:00
@@ -220,6 +220,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;
@@ -465,6 +466,8 @@
cleanup();
ha_close_connection(this);
+
+ logger_cache_release(this);
DBUG_PRINT("info", ("freeing security context"));
main_security_ctx.destroy();
--- 1.340/sql/sql_class.h 2007-03-12 08:58:47 -07:00
+++ 1.341/sql/sql_class.h 2007-03-12 08:58:47 -07:00
@@ -865,6 +865,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.630/sql/sql_parse.cc 2007-03-12 08:58:47 -07:00
+++ 1.631/sql/sql_parse.cc 2007-03-12 08:58:47 -07:00
@@ -607,6 +607,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)
{
@@ -636,6 +639,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
--- 1.3/sql/sql_logger.cc 2007-03-12 08:58:47 -07:00
+++ 1.4/sql/sql_logger.cc 2007-03-12 08:58:47 -07:00
@@ -39,16 +39,18 @@
};
+static rw_lock_t THR_LOCK_logger;
+static uint version, version_head;
+
+
static void stderr_log(THD *thd, time_t start_time,
enum loglevel log_level,
enum enum_server_command command,
const char *format, va_list args);
-static my_bool call_log(THD *thd, st_plugin_int *plugin, void *data)
+static my_bool call_log(THD *thd, mysql_logger *logger, logger_emit_st *emit)
{
- mysql_logger *logger= (mysql_logger *) plugin->data;
- logger_emit_st *emit= (logger_emit_st *) data;
mysql_logger_func logfunc;
va_list args;
DBUG_ENTER("call_log");
@@ -66,6 +68,12 @@
}
+static my_bool call_log(THD *thd, st_plugin_int *plugin, void *data)
+{
+ return call_log(thd, (mysql_logger *) plugin->data, (logger_emit_st *) data);
+}
+
+
static my_bool flush_log(THD *thd, st_plugin_int *plugin, void *data)
{
mysql_logger *logger= (mysql_logger *) plugin->data;
@@ -94,7 +102,14 @@
data.errorbits= 0;
data.handlecount= 0;
- plugin_foreach(thd, call_log, MYSQL_LOGGING_PLUGIN, &data);
+ if (thd && thd->logger_cache.version)
+ {
+ st_plugin_int **log= thd->logger_cache.loggers, *logger;
+ while ((logger= *log++))
+ call_log(thd, (mysql_logger *)logger->data, &data);
+ }
+ else
+ plugin_foreach(thd, call_log, MYSQL_LOGGING_PLUGIN, &data);
va_end(data.args);
@@ -267,7 +282,16 @@
{
bool result= FALSE;
DBUG_ENTER("flush_error_log");
- result= plugin_foreach(thd, flush_log, MYSQL_LOGGING_PLUGIN, NULL);
+
+ if (thd && thd->logger_cache.version)
+ {
+ st_plugin_int **log= thd->logger_cache.loggers, *plugin;
+ while ((plugin= *log++))
+ flush_log(thd, plugin, NULL);
+ }
+ else
+ result= plugin_foreach(thd, flush_log, MYSQL_LOGGING_PLUGIN, NULL);
+
DBUG_RETURN(result);
}
@@ -282,6 +306,56 @@
}
+void logger_cache_prepare(THD *thd)
+{
+ rw_rdlock(&THR_LOCK_logger);
+ if (thd->logger_cache.version != version)
+ {
+ if (thd->logger_cache.version)
+ plugin_unlockall(thd->logger_cache.loggers);
+ thd->logger_cache.loggers= plugin_lockall(MYSQL_LOGGING_PLUGIN);
+ thd->logger_cache.version= version_head;
+ }
+ rw_unlock(&THR_LOCK_logger);
+}
+
+
+void logger_cache_check(THD *thd)
+{
+ if (thd->logger_cache.version != version)
+ logger_cache_release(thd);
+}
+
+
+void logger_cache_release(THD *thd)
+{
+ plugin_unlockall(thd->logger_cache.loggers);
+ thd->logger_cache.loggers= NULL;
+ thd->logger_cache.version= 0;
+}
+
+
+void logger_cache_notify(void)
+{
+ rw_wrlock(&THR_LOCK_logger);
+ version++;
+ rw_unlock(&THR_LOCK_logger);
+}
+
+void logger_cache_init(void)
+{
+ my_rwlock_init(&THR_LOCK_logger, NULL);
+ version= 0;
+ version_head= 0;
+}
+
+void logger_cache_done(void)
+{
+ rwlock_destroy(&THR_LOCK_logger);
+ version= 0;
+}
+
+
/* Plugin Initialization and finalization */
int initialize_logger(st_plugin_int *plugin)
{
@@ -305,6 +379,11 @@
}
}
+ rw_wrlock(&THR_LOCK_logger);
+ version++;
+ version_head= version;
+ rw_unlock(&THR_LOCK_logger);
+
DBUG_RETURN(0);
err:
my_free((gptr)logger, MYF(MY_ALLOW_ZERO_PTR));
@@ -323,7 +402,13 @@
{
error= plugin->plugin->deinit(logger);
my_free((gptr)logger, MYF(0));
+
+ rw_wrlock(&THR_LOCK_logger);
+ version++;
+ version_head= version;
+ rw_unlock(&THR_LOCK_logger);
}
+
DBUG_RETURN(error);
}
--- 1.2/sql/sql_logger.h 2007-03-12 08:58:47 -07:00
+++ 1.3/sql/sql_logger.h 2007-03-12 08:58:47 -07:00
@@ -28,6 +28,13 @@
my_bool (*flush_logs)(THD *thd, void *data);
};
+
+struct logger_cache
+{
+ uint version;
+ struct st_plugin_int **loggers;
+};
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -60,6 +67,14 @@
int intern_error_log(THD *thd, time_t start_time, enum loglevel log_level,
const char *format, va_list args);
+
+
+void logger_cache_prepare(THD *thd);
+void logger_cache_check(THD *thd);
+void logger_cache_release(THD *thd);
+void logger_cache_notify(void);
+void logger_cache_init(void);
+void logger_cache_done(void);
/* init/deinit used by sql_plugin.cc */
--- 1.46/sql/sql_plugin.cc 2007-03-12 08:58:47 -07:00
+++ 1.47/sql/sql_plugin.cc 2007-03-12 08:58:47 -07:00
@@ -63,6 +63,13 @@
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
static const char *plugin_interface_version_sym=
"_mysql_plugin_interface_version_";
@@ -427,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;
@@ -598,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");
@@ -951,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.13/sql/sql_plugin.h 2007-03-12 08:58:47 -07:00
+++ 1.14/sql/sql_plugin.h 2007-03-12 08:58:47 -07:00
@@ -66,6 +66,7 @@
};
typedef int (*plugin_type_init)(struct st_plugin_int *);
+typedef void (*plugin_type_notify)(void);
extern char *opt_plugin_dir_ptr;
extern char opt_plugin_dir[FN_REFLEN];
@@ -75,6 +76,8 @@
extern my_bool plugin_is_ready(const LEX_STRING *name, int type);
extern st_plugin_int *plugin_lock(const LEX_STRING *name, int type);
extern void plugin_unlock(struct st_plugin_int *plugin);
+extern st_plugin_int **plugin_lockall(int type);
+extern void plugin_unlockall(struct st_plugin_int **plugin);
extern my_bool mysql_install_plugin(THD *thd, const LEX_STRING *name, const LEX_STRING *dl);
extern my_bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name);
| Thread |
|---|
| • bk commit into 5.1 tree (acurtis:1.2469) | antony | 12 Mar |