Commit 2c40fb56 authored by Michael Widenius's avatar Michael Widenius

Automatic merge

parents 615d51b6 d8986fd6
...@@ -70,52 +70,34 @@ Success ...@@ -70,52 +70,34 @@ Success
TRUNCATE TABLE performance_schema.events_waits_history_long; TRUNCATE TABLE performance_schema.events_waits_history_long;
TRUNCATE TABLE performance_schema.events_waits_history; TRUNCATE TABLE performance_schema.events_waits_history;
TRUNCATE TABLE performance_schema.events_waits_current; TRUNCATE TABLE performance_schema.events_waits_current;
SELECT * FROM t1 WHERE id = 1; show variables like "%not_found%";
id b Variable_name Value
1 initial value
SET @before_count = (SELECT SUM(TIMER_WAIT) SET @before_count = (SELECT SUM(TIMER_WAIT)
FROM performance_schema.events_waits_history_long FROM performance_schema.events_waits_history_long
WHERE (EVENT_NAME = 'wait/synch/rwlock/sql/LOCK_grant')); WHERE (EVENT_NAME = 'wait/synch/rwlock/sql/LOCK_system_variables_hash'));
SELECT * FROM t1; show variables like "%not_found%";
id b Variable_name Value
1 initial value
2 initial value
3 initial value
4 initial value
5 initial value
6 initial value
7 initial value
8 initial value
SET @after_count = (SELECT SUM(TIMER_WAIT) SET @after_count = (SELECT SUM(TIMER_WAIT)
FROM performance_schema.events_waits_history_long FROM performance_schema.events_waits_history_long
WHERE (EVENT_NAME = 'wait/synch/rwlock/sql/LOCK_grant')); WHERE (EVENT_NAME = 'wait/synch/rwlock/sql/LOCK_system_variables_hash'));
SELECT IF((@after_count - @before_count) > 0, 'Success', 'Failure') test_fm1_rw_timed; SELECT IF((@after_count - @before_count) > 0, 'Success', 'Failure') test_fm1_rw_timed;
test_fm1_rw_timed test_fm1_rw_timed
Success Success
UPDATE performance_schema.setup_instruments SET enabled = 'NO' UPDATE performance_schema.setup_instruments SET enabled = 'NO'
WHERE NAME = 'wait/synch/rwlock/sql/LOCK_grant'; WHERE NAME = 'wait/synch/rwlock/sql/LOCK_system_variables_hash';
TRUNCATE TABLE performance_schema.events_waits_history_long; TRUNCATE TABLE performance_schema.events_waits_history_long;
TRUNCATE TABLE performance_schema.events_waits_history; TRUNCATE TABLE performance_schema.events_waits_history;
TRUNCATE TABLE performance_schema.events_waits_current; TRUNCATE TABLE performance_schema.events_waits_current;
SELECT * FROM t1 WHERE id = 1; show variables like "%not_found%";
id b Variable_name Value
1 initial value
SET @before_count = (SELECT SUM(TIMER_WAIT) SET @before_count = (SELECT SUM(TIMER_WAIT)
FROM performance_schema.events_waits_history_long FROM performance_schema.events_waits_history_long
WHERE (EVENT_NAME = 'wait/synch/rwlock/sql/LOCK_grant')); WHERE (EVENT_NAME = 'wait/synch/rwlock/sql/LOCK_system_variables_hash'));
SELECT * FROM t1; show variables like "%not_found%";
id b Variable_name Value
1 initial value
2 initial value
3 initial value
4 initial value
5 initial value
6 initial value
7 initial value
8 initial value
SET @after_count = (SELECT SUM(TIMER_WAIT) SET @after_count = (SELECT SUM(TIMER_WAIT)
FROM performance_schema.events_waits_history_long FROM performance_schema.events_waits_history_long
WHERE (EVENT_NAME = 'wait/synch/rwlock/sql/LOCK_grant')); WHERE (EVENT_NAME = 'LOCK_system_variables_hash'));
SELECT IF((COALESCE(@after_count, 0) - COALESCE(@before_count, 0)) = 0, 'Success', 'Failure') test_fm2_rw_timed; SELECT IF((COALESCE(@after_count, 0) - COALESCE(@before_count, 0)) = 0, 'Success', 'Failure') test_fm2_rw_timed;
test_fm2_rw_timed test_fm2_rw_timed
Success Success
......
...@@ -87,38 +87,38 @@ TRUNCATE TABLE performance_schema.events_waits_history_long; ...@@ -87,38 +87,38 @@ TRUNCATE TABLE performance_schema.events_waits_history_long;
TRUNCATE TABLE performance_schema.events_waits_history; TRUNCATE TABLE performance_schema.events_waits_history;
TRUNCATE TABLE performance_schema.events_waits_current; TRUNCATE TABLE performance_schema.events_waits_current;
SELECT * FROM t1 WHERE id = 1; show variables like "%not_found%";
SET @before_count = (SELECT SUM(TIMER_WAIT) SET @before_count = (SELECT SUM(TIMER_WAIT)
FROM performance_schema.events_waits_history_long FROM performance_schema.events_waits_history_long
WHERE (EVENT_NAME = 'wait/synch/rwlock/sql/LOCK_grant')); WHERE (EVENT_NAME = 'wait/synch/rwlock/sql/LOCK_system_variables_hash'));
SELECT * FROM t1; show variables like "%not_found%";
SET @after_count = (SELECT SUM(TIMER_WAIT) SET @after_count = (SELECT SUM(TIMER_WAIT)
FROM performance_schema.events_waits_history_long FROM performance_schema.events_waits_history_long
WHERE (EVENT_NAME = 'wait/synch/rwlock/sql/LOCK_grant')); WHERE (EVENT_NAME = 'wait/synch/rwlock/sql/LOCK_system_variables_hash'));
SELECT IF((@after_count - @before_count) > 0, 'Success', 'Failure') test_fm1_rw_timed; SELECT IF((@after_count - @before_count) > 0, 'Success', 'Failure') test_fm1_rw_timed;
UPDATE performance_schema.setup_instruments SET enabled = 'NO' UPDATE performance_schema.setup_instruments SET enabled = 'NO'
WHERE NAME = 'wait/synch/rwlock/sql/LOCK_grant'; WHERE NAME = 'wait/synch/rwlock/sql/LOCK_system_variables_hash';
TRUNCATE TABLE performance_schema.events_waits_history_long; TRUNCATE TABLE performance_schema.events_waits_history_long;
TRUNCATE TABLE performance_schema.events_waits_history; TRUNCATE TABLE performance_schema.events_waits_history;
TRUNCATE TABLE performance_schema.events_waits_current; TRUNCATE TABLE performance_schema.events_waits_current;
SELECT * FROM t1 WHERE id = 1; show variables like "%not_found%";
SET @before_count = (SELECT SUM(TIMER_WAIT) SET @before_count = (SELECT SUM(TIMER_WAIT)
FROM performance_schema.events_waits_history_long FROM performance_schema.events_waits_history_long
WHERE (EVENT_NAME = 'wait/synch/rwlock/sql/LOCK_grant')); WHERE (EVENT_NAME = 'wait/synch/rwlock/sql/LOCK_system_variables_hash'));
SELECT * FROM t1; show variables like "%not_found%";
SET @after_count = (SELECT SUM(TIMER_WAIT) SET @after_count = (SELECT SUM(TIMER_WAIT)
FROM performance_schema.events_waits_history_long FROM performance_schema.events_waits_history_long
WHERE (EVENT_NAME = 'wait/synch/rwlock/sql/LOCK_grant')); WHERE (EVENT_NAME = 'LOCK_system_variables_hash'));
SELECT IF((COALESCE(@after_count, 0) - COALESCE(@before_count, 0)) = 0, 'Success', 'Failure') test_fm2_rw_timed; SELECT IF((COALESCE(@after_count, 0) - COALESCE(@before_count, 0)) = 0, 'Success', 'Failure') test_fm2_rw_timed;
......
...@@ -87,13 +87,17 @@ my_bool my_gethwaddr(uchar *to) ...@@ -87,13 +87,17 @@ my_bool my_gethwaddr(uchar *to)
int fd, res= 1; int fd, res= 1;
struct ifreq ifr[32]; struct ifreq ifr[32];
struct ifconf ifc; struct ifconf ifc;
DBUG_ENTER("my_gethwaddr");
ifc.ifc_req= ifr; ifc.ifc_req= ifr;
ifc.ifc_len= sizeof(ifr); ifc.ifc_len= sizeof(ifr);
fd = socket(AF_INET, SOCK_DGRAM, 0); fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) if (fd < 0)
{
DBUG_PRINT("error", ("socket() call failed with %d", errno));
goto err; goto err;
}
if (ioctl(fd, SIOCGIFCONF, (char*)&ifc) >= 0) if (ioctl(fd, SIOCGIFCONF, (char*)&ifc) >= 0)
{ {
...@@ -106,8 +110,8 @@ my_bool my_gethwaddr(uchar *to) ...@@ -106,8 +110,8 @@ my_bool my_gethwaddr(uchar *to)
ETHER_ADDR_LEN); ETHER_ADDR_LEN);
#else #else
/* /*
A bug in OpenSolaris used to prevent non-root from getting a mac address: A bug in OpenSolaris used to prevent non-root from getting a mac
{no url. Oracle killed the old OpenSolaris bug database} address: {no url. Oracle killed the old OpenSolaris bug database}
Thus, we'll use an alternative method and extract the address from the Thus, we'll use an alternative method and extract the address from the
arp table. arp table.
...@@ -124,7 +128,7 @@ my_bool my_gethwaddr(uchar *to) ...@@ -124,7 +128,7 @@ my_bool my_gethwaddr(uchar *to)
close(fd); close(fd);
err: err:
return res; DBUG_RETURN(res);
} }
#elif defined(_WIN32) #elif defined(_WIN32)
......
...@@ -2529,7 +2529,7 @@ void unlink_thd(THD *thd) ...@@ -2529,7 +2529,7 @@ void unlink_thd(THD *thd)
cache_thread() cache_thread()
NOTES NOTES
LOCK_thread_cache has to be locked LOCK_thread_cache is used to protect the cache variables
RETURN RETURN
0 Thread was not put in cache 0 Thread was not put in cache
...@@ -2542,7 +2542,7 @@ static bool cache_thread() ...@@ -2542,7 +2542,7 @@ static bool cache_thread()
{ {
DBUG_ENTER("cache_thread"); DBUG_ENTER("cache_thread");
mysql_mutex_assert_owner(&LOCK_thread_cache); mysql_mutex_lock(&LOCK_thread_cache);
if (cached_thread_count < thread_cache_size && if (cached_thread_count < thread_cache_size &&
! abort_loop && !kill_cached_threads) ! abort_loop && !kill_cached_threads)
{ {
...@@ -2569,6 +2569,8 @@ static bool cache_thread() ...@@ -2569,6 +2569,8 @@ static bool cache_thread()
THD *thd; THD *thd;
wake_thread--; wake_thread--;
thd= thread_cache.get(); thd= thread_cache.get();
mysql_mutex_unlock(&LOCK_thread_cache);
thd->thread_stack= (char*) &thd; // For store_globals thd->thread_stack= (char*) &thd; // For store_globals
(void) thd->store_globals(); (void) thd->store_globals();
...@@ -2594,10 +2596,15 @@ static bool cache_thread() ...@@ -2594,10 +2596,15 @@ static bool cache_thread()
thd->mysys_var->abort= 0; thd->mysys_var->abort= 0;
thd->thr_create_utime= microsecond_interval_timer(); thd->thr_create_utime= microsecond_interval_timer();
thd->start_utime= thd->thr_create_utime; thd->start_utime= thd->thr_create_utime;
/* Link thd into list of all active threads (THD's) */
mysql_mutex_lock(&LOCK_thread_count);
threads.append(thd); threads.append(thd);
mysql_mutex_unlock(&LOCK_thread_count);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
} }
mysql_mutex_unlock(&LOCK_thread_cache);
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -2627,14 +2634,8 @@ bool one_thread_per_connection_end(THD *thd, bool put_in_cache) ...@@ -2627,14 +2634,8 @@ bool one_thread_per_connection_end(THD *thd, bool put_in_cache)
unlink_thd(thd); unlink_thd(thd);
/* Mark that current_thd is not valid anymore */ /* Mark that current_thd is not valid anymore */
set_current_thd(0); set_current_thd(0);
if (put_in_cache) if (put_in_cache && cache_thread())
{ DBUG_RETURN(0); // Thread is reused
mysql_mutex_lock(&LOCK_thread_cache);
put_in_cache= cache_thread();
mysql_mutex_unlock(&LOCK_thread_cache);
if (put_in_cache)
DBUG_RETURN(0); // Thread is reused
}
/* /*
It's safe to check for thread_count outside of the mutex It's safe to check for thread_count outside of the mutex
......
...@@ -450,7 +450,7 @@ inline query_id_t next_query_id() ...@@ -450,7 +450,7 @@ inline query_id_t next_query_id()
my_atomic_rwlock_wrlock(&global_query_id_lock); my_atomic_rwlock_wrlock(&global_query_id_lock);
id= my_atomic_add64(&global_query_id, 1); id= my_atomic_add64(&global_query_id, 1);
my_atomic_rwlock_wrunlock(&global_query_id_lock); my_atomic_rwlock_wrunlock(&global_query_id_lock);
return (id+1); return (id);
} }
inline query_id_t get_query_id() inline query_id_t get_query_id()
......
...@@ -4530,12 +4530,16 @@ my_bool grant_reload(THD *thd) ...@@ -4530,12 +4530,16 @@ my_bool grant_reload(THD *thd)
@see check_access @see check_access
@see check_table_access @see check_table_access
@note This functions assumes that either number of tables to be inspected @note
This functions assumes that either number of tables to be inspected
by it is limited explicitly (i.e. is is not UINT_MAX) or table list by it is limited explicitly (i.e. is is not UINT_MAX) or table list
used and thd->lex->query_tables_own_last value correspond to each used and thd->lex->query_tables_own_last value correspond to each
other (the latter should be either 0 or point to next_global member other (the latter should be either 0 or point to next_global member
of one of elements of this table list). of one of elements of this table list).
We delay locking of LOCK_grant until we really need it as we assume that
most privileges be resolved with user or db level accesses.
@return Access status @return Access status
@retval FALSE Access granted; But column privileges might need to be @retval FALSE Access granted; But column privileges might need to be
checked. checked.
...@@ -4552,6 +4556,8 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables, ...@@ -4552,6 +4556,8 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables,
Security_context *sctx= thd->security_ctx; Security_context *sctx= thd->security_ctx;
uint i; uint i;
ulong orig_want_access= want_access; ulong orig_want_access= want_access;
my_bool locked= 0;
GRANT_TABLE *grant_table;
DBUG_ENTER("check_grant"); DBUG_ENTER("check_grant");
DBUG_ASSERT(number > 0); DBUG_ASSERT(number > 0);
...@@ -4575,11 +4581,9 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables, ...@@ -4575,11 +4581,9 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables,
*/ */
tl->grant.orig_want_privilege= (want_access & ~SHOW_VIEW_ACL); tl->grant.orig_want_privilege= (want_access & ~SHOW_VIEW_ACL);
} }
number= i;
mysql_rwlock_rdlock(&LOCK_grant); for (tl= tables; number-- ; tl= tl->next_global)
for (tl= tables;
tl && number-- && tl != first_not_own_table;
tl= tl->next_global)
{ {
sctx = test(tl->security_ctx) ? tl->security_ctx : thd->security_ctx; sctx = test(tl->security_ctx) ? tl->security_ctx : thd->security_ctx;
...@@ -4632,13 +4636,18 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables, ...@@ -4632,13 +4636,18 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables,
} }
continue; continue;
} }
GRANT_TABLE *grant_table= table_hash_search(sctx->host, sctx->ip,
tl->get_db_name(),
sctx->priv_user,
tl->get_table_name(),
FALSE);
if (!grant_table) if (!locked)
{
locked= 1;
mysql_rwlock_rdlock(&LOCK_grant);
}
if (!(grant_table= table_hash_search(sctx->host, sctx->ip,
tl->get_db_name(),
sctx->priv_user,
tl->get_table_name(),
FALSE)))
{ {
want_access &= ~tl->grant.privilege; want_access &= ~tl->grant.privilege;
goto err; // No grants goto err; // No grants
...@@ -4665,11 +4674,13 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables, ...@@ -4665,11 +4674,13 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables,
goto err; // impossible goto err; // impossible
} }
} }
mysql_rwlock_unlock(&LOCK_grant); if (locked)
mysql_rwlock_unlock(&LOCK_grant);
DBUG_RETURN(FALSE); DBUG_RETURN(FALSE);
err: err:
mysql_rwlock_unlock(&LOCK_grant); if (locked)
mysql_rwlock_unlock(&LOCK_grant);
if (!no_errors) // Not a silent skip of table if (!no_errors) // Not a silent skip of table
{ {
char command[128]; char command[128];
......
...@@ -4326,17 +4326,8 @@ void THD::set_query_and_id(char *query_arg, uint32 query_length_arg, ...@@ -4326,17 +4326,8 @@ void THD::set_query_and_id(char *query_arg, uint32 query_length_arg,
{ {
mysql_mutex_lock(&LOCK_thd_data); mysql_mutex_lock(&LOCK_thd_data);
set_query_inner(query_arg, query_length_arg, cs); set_query_inner(query_arg, query_length_arg, cs);
query_id= new_query_id;
mysql_mutex_unlock(&LOCK_thd_data); mysql_mutex_unlock(&LOCK_thd_data);
}
/** Assign a new value to thd->query_id. */
void THD::set_query_id(query_id_t new_query_id)
{
mysql_mutex_lock(&LOCK_thd_data);
query_id= new_query_id; query_id= new_query_id;
mysql_mutex_unlock(&LOCK_thd_data);
} }
/** Assign a new value to thd->mysys_var. */ /** Assign a new value to thd->mysys_var. */
......
...@@ -3076,7 +3076,10 @@ class THD :public Statement, ...@@ -3076,7 +3076,10 @@ class THD :public Statement,
{ set_query(CSET_STRING()); } { set_query(CSET_STRING()); }
void set_query_and_id(char *query_arg, uint32 query_length_arg, void set_query_and_id(char *query_arg, uint32 query_length_arg,
CHARSET_INFO *cs, query_id_t new_query_id); CHARSET_INFO *cs, query_id_t new_query_id);
void set_query_id(query_id_t new_query_id); void set_query_id(query_id_t new_query_id)
{
query_id= new_query_id;
}
void set_open_tables(TABLE *open_tables_arg) void set_open_tables(TABLE *open_tables_arg)
{ {
mysql_mutex_lock(&LOCK_thd_data); mysql_mutex_lock(&LOCK_thd_data);
......
...@@ -931,9 +931,16 @@ bool dispatch_command(enum enum_server_command command, THD *thd, ...@@ -931,9 +931,16 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
thd->query_plan_flags= QPLAN_INIT; thd->query_plan_flags= QPLAN_INIT;
thd->lex->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */ thd->lex->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
thd->set_time(); thd->set_time();
thd->set_query_id(get_query_id());
if (!(server_command_flags[command] & CF_SKIP_QUERY_ID)) if (!(server_command_flags[command] & CF_SKIP_QUERY_ID))
next_query_id(); thd->set_query_id(next_query_id());
else
{
/*
ping, get statistics or similar stateless command.
No reason to increase query id here.
*/
thd->set_query_id(get_query_id());
}
inc_thread_running(); inc_thread_running();
if (!(server_command_flags[command] & CF_SKIP_QUESTIONS)) if (!(server_command_flags[command] & CF_SKIP_QUESTIONS))
...@@ -5022,6 +5029,10 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, ...@@ -5022,6 +5029,10 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv,
if ((db != NULL) && (db != any_db)) if ((db != NULL) && (db != any_db))
{ {
/*
Check if this is reserved database, like information schema or
performance schema
*/
const ACL_internal_schema_access *access; const ACL_internal_schema_access *access;
access= get_cached_schema_access(grant_internal_info, db); access= get_cached_schema_access(grant_internal_info, db);
if (access) if (access)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment