#At file:///Users/malff/BZR_TREE/mysql-next-mr-wl4674/ based on revid:marc.alff@stripped
3153 Marc Alff 2010-06-16
WL#4674 PERFORMANCE SCHEMA SETUP_ACTORS
Code cleanup
modified:
include/mysql/psi/psi.h
include/mysql/psi/psi_abi_v1.h.pp
sql/sql_connect.cc
storage/perfschema/pfs.cc
storage/perfschema/unittest/pfs-t.cc
=== modified file 'include/mysql/psi/psi.h'
--- a/include/mysql/psi/psi.h 2010-05-07 10:08:23 +0000
+++ b/include/mysql/psi/psi.h 2010-06-16 16:14:32 +0000
@@ -602,7 +602,8 @@ typedef struct PSI_thread* (*get_thread_
typedef void (*set_thread_user_v1_t)(const char *user, int user_len);
-typedef void (*set_thread_host_v1_t)(const char *host, int host_len);
+typedef void (*set_thread_user_host_v1_t)(const char *user, int user_len,
+ const char *host, int host_len);
typedef void (*set_thread_db_v1_t)(const char* db, int db_len);
@@ -905,8 +906,8 @@ struct PSI_v1
get_thread_v1_t get_thread;
/** @sa set_thread_user_v1_t. */
set_thread_user_v1_t set_thread_user;
- /** @sa set_thread_host_v1_t. */
- set_thread_host_v1_t set_thread_host;
+ /** @sa set_thread_user_host_v1_t. */
+ set_thread_user_host_v1_t set_thread_user_host;
/** @sa set_thread_db_v1_t. */
set_thread_db_v1_t set_thread_db;
/** @sa set_thread_command_v1_t. */
=== modified file 'include/mysql/psi/psi_abi_v1.h.pp'
--- a/include/mysql/psi/psi_abi_v1.h.pp 2010-05-07 10:08:23 +0000
+++ b/include/mysql/psi/psi_abi_v1.h.pp 2010-06-16 16:14:32 +0000
@@ -126,7 +126,8 @@ typedef void (*set_thread_id_v1_t)(struc
unsigned long id);
typedef struct PSI_thread* (*get_thread_v1_t)(void);
typedef void (*set_thread_user_v1_t)(const char *user, int user_len);
-typedef void (*set_thread_host_v1_t)(const char *host, int host_len);
+typedef void (*set_thread_user_host_v1_t)(const char *user, int user_len,
+ const char *host, int host_len);
typedef void (*set_thread_db_v1_t)(const char* db, int db_len);
typedef void (*set_thread_command_v1_t)(int command);
typedef void (*set_thread_start_time_v1_t)(time_t start_time);
@@ -211,7 +212,7 @@ struct PSI_v1
set_thread_id_v1_t set_thread_id;
get_thread_v1_t get_thread;
set_thread_user_v1_t set_thread_user;
- set_thread_host_v1_t set_thread_host;
+ set_thread_user_host_v1_t set_thread_user_host;
set_thread_db_v1_t set_thread_db;
set_thread_command_v1_t set_thread_command;
set_thread_start_time_v1_t set_thread_start_time;
=== modified file 'sql/sql_connect.cc'
--- a/sql/sql_connect.cc 2010-05-28 07:37:58 +0000
+++ b/sql/sql_connect.cc 2010-06-16 16:14:32 +0000
@@ -506,10 +506,10 @@ check_user(THD *thd, enum enum_server_co
#ifdef HAVE_PSI_INTERFACE
if (PSI_server)
{
- PSI_server->set_thread_host(thd->main_security_ctx.host_or_ip,
- strlen(thd->main_security_ctx.host_or_ip));
- PSI_server->set_thread_user(thd->main_security_ctx.user,
- strlen(thd->main_security_ctx.user));
+ PSI_server->set_thread_user_host(thd->main_security_ctx.user,
+ strlen(thd->main_security_ctx.user),
+ thd->main_security_ctx.host_or_ip,
+ strlen(thd->main_security_ctx.host_or_ip));
}
#endif
/* Ready to handle queries */
=== modified file 'storage/perfschema/pfs.cc'
--- a/storage/perfschema/pfs.cc 2010-06-15 14:23:08 +0000
+++ b/storage/perfschema/pfs.cc 2010-06-16 16:14:32 +0000
@@ -1107,22 +1107,48 @@ static void set_thread_user_v1(const cha
pfs->m_lock.dirty_to_allocated();
}
-static void set_thread_host_v1(const char *host, int host_len)
+static void set_thread_user_host_v1(const char *user, int user_len,
+ const char *host, int host_len)
{
PFS_thread *pfs= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS);
+ DBUG_ASSERT((user != NULL) || (user_len == 0));
+ DBUG_ASSERT(user_len >= 0);
+ DBUG_ASSERT((uint) user_len <= sizeof(pfs->m_username));
DBUG_ASSERT((host != NULL) || (host_len == 0));
DBUG_ASSERT(host_len >= 0);
DBUG_ASSERT((uint) host_len <= sizeof(pfs->m_hostname));
- if (likely(pfs != NULL))
+ if (unlikely(pfs == NULL))
+ return;
+
+ pfs->m_lock.allocated_to_dirty();
+
+ if (host_len > 0)
+ memcpy(pfs->m_hostname, host, host_len);
+ pfs->m_hostname_length= host_len;
+
+ if (user_len > 0)
+ memcpy(pfs->m_username, user, user_len);
+ pfs->m_username_length= user_len;
+
+ bool enabled= false;
+ if ((pfs->m_username_length > 0) && (pfs->m_hostname_length > 0))
{
- pfs->m_lock.allocated_to_dirty();
- if (host_len > 0)
- memcpy(pfs->m_hostname, host, host_len);
- pfs->m_hostname_length= host_len;
- pfs->m_lock.dirty_to_allocated();
+ /*
+ TODO: performance improvement.
+ Once performance_schema.USERS is exposed,
+ we can use PFS_user::m_enabled instead of looking up
+ SETUP_ACTORS every time.
+ */
+ lookup_setup_actor(pfs,
+ pfs->m_username, pfs->m_username_length,
+ pfs->m_hostname, pfs->m_hostname_length,
+ &enabled);
}
+ pfs->m_enabled= enabled;
+
+ pfs->m_lock.dirty_to_allocated();
}
static void set_thread_db_v1(const char* db, int db_len)
@@ -2146,7 +2172,7 @@ PSI_v1 PFS_v1=
set_thread_id_v1,
get_thread_v1,
set_thread_user_v1,
- set_thread_host_v1,
+ set_thread_user_host_v1,
set_thread_db_v1,
set_thread_command_v1,
set_thread_start_time_v1,
=== modified file 'storage/perfschema/unittest/pfs-t.cc'
--- a/storage/perfschema/unittest/pfs-t.cc 2010-06-15 14:23:08 +0000
+++ b/storage/perfschema/unittest/pfs-t.cc 2010-06-16 16:14:32 +0000
@@ -376,7 +376,7 @@ void test_bad_registration()
ok(dummy_thread_key == 0, "zero key");
dummy_thread_key= 9999;
psi->register_thread("12345678901234567890123", bad_thread_1, 1);
- ok(dummy_thread_key == 1, "assigned key");
+ ok(dummy_thread_key == 2, "assigned key");
/*
Test that length('thread/' (7) + category + '/' (1) + name) <= 128
@@ -412,7 +412,7 @@ void test_bad_registration()
ok(dummy_thread_key == 0, "zero key");
psi->register_thread("X", bad_thread_3, 1);
- ok(dummy_thread_key == 2, "assigned key");
+ ok(dummy_thread_key == 3, "assigned key");
/*
Test that length('wait/io/file/' (13) + category + '/' (1)) < 32
Attachment: [text/bzr-bundle] bzr/marc.alff@oracle.com-20100616161432-jbxj1fazmf12nk40.bundle
| Thread |
|---|
| • bzr commit into mysql-next-mr branch (marc.alff:3153) WL#4674 | Marc Alff | 16 Jun |