summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/waiting_threads.h5
-rw-r--r--mysys/waiting_threads.c10
-rw-r--r--sql/mysqld.cc4
-rw-r--r--sql/sql_class.cc9
-rw-r--r--sql/sql_class.h2
-rw-r--r--storage/maria/ha_maria.cc4
-rw-r--r--storage/maria/ma_commit.c4
-rw-r--r--storage/maria/ma_write.c4
-rw-r--r--storage/maria/maria_def.h3
-rw-r--r--storage/maria/trnman.c35
-rw-r--r--storage/maria/trnman.h7
-rw-r--r--storage/maria/trnman_public.h5
-rw-r--r--storage/maria/unittest/trnman-t.c32
13 files changed, 61 insertions, 63 deletions
diff --git a/include/waiting_threads.h b/include/waiting_threads.h
index 6355a83b13d..cf55e586d48 100644
--- a/include/waiting_threads.h
+++ b/include/waiting_threads.h
@@ -18,6 +18,9 @@
#include <my_global.h>
#include <my_sys.h>
+
+C_MODE_START
+
#include <lf.h>
typedef struct st_wt_resource_id WT_RESOURCE_ID;
@@ -155,4 +158,6 @@ void wt_thd_release(WT_THD *, WT_RESOURCE_ID *);
#define wt_thd_release_all(THD) wt_thd_release((THD), 0)
int wt_resource_id_memcmp(void *, void *);
+C_MODE_END
+
#endif
diff --git a/mysys/waiting_threads.c b/mysys/waiting_threads.c
index 491e7c3a726..55f65be2811 100644
--- a/mysys/waiting_threads.c
+++ b/mysys/waiting_threads.c
@@ -208,6 +208,9 @@ void wt_thd_destroy(WT_THD *thd)
{
DBUG_ENTER("wt_thd_destroy");
+ if (thd->my_resources.buffer == 0)
+ DBUG_VOID_RETURN; /* nothing to do */
+
DBUG_ASSERT(thd->my_resources.elements == 0);
delete_dynamic(&thd->my_resources);
lf_hash_put_pins(thd->pins);
@@ -447,6 +450,9 @@ int wt_thd_will_wait_for(WT_THD *thd, WT_THD *blocker, WT_RESOURCE_ID *resid)
DBUG_PRINT("wt", ("enter: thd=%s, blocker=%s, resid=%llu",
thd->name, blocker->name, resid->value.num));
+ if (unlikely(thd->my_resources.buffer == 0))
+ wt_thd_init(thd);
+
if (thd->waiting_for == 0)
{
uint keylen;
@@ -647,8 +653,8 @@ void wt_thd_release(WT_THD *thd, WT_RESOURCE_ID *resid)
}
}
}
- DBUG_ASSERT(!resid);
- reset_dynamic(&thd->my_resources);
+ if (!resid)
+ reset_dynamic(&thd->my_resources);
DBUG_VOID_RETURN;
}
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 3a48f9eadd0..5362dcad938 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -26,6 +26,7 @@
#include "mysqld_suffix.h"
#include "mysys_err.h"
#include "events.h"
+#include <waiting_threads.h>
#include "../storage/myisam/ha_myisam.h"
@@ -1240,6 +1241,7 @@ void clean_up(bool print_message)
if (tc_log)
tc_log->close();
xid_cache_free();
+ wt_end();
delete_elements(&key_caches, (void (*)(const char*, uchar*)) free_key_cache);
multi_keycache_free();
free_status_vars();
@@ -3665,6 +3667,8 @@ static int init_server_components()
if (table_cache_init() | table_def_init() | hostname_cache_init())
unireg_abort(1);
+ wt_init();
+
query_cache_result_size_limit(query_cache_limit);
query_cache_set_min_res_unit(query_cache_min_res_unit);
query_cache_init();
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 4e8be66cfca..9f20ab242b3 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -829,6 +829,7 @@ void THD::cleanup(void)
lock=locked_tables; locked_tables=0;
close_thread_tables(this);
}
+ wt_thd_destroy(&transaction.wt);
mysql_ha_cleanup(this);
delete_dynamic(&user_var_events);
hash_free(&user_vars);
@@ -836,7 +837,7 @@ void THD::cleanup(void)
my_free((char*) variables.time_format, MYF(MY_ALLOW_ZERO_PTR));
my_free((char*) variables.date_format, MYF(MY_ALLOW_ZERO_PTR));
my_free((char*) variables.datetime_format, MYF(MY_ALLOW_ZERO_PTR));
-
+
sp_cache_clear(&sp_proc_cache);
sp_cache_clear(&sp_func_cache);
@@ -874,12 +875,12 @@ THD::~THD()
#endif
stmt_map.reset(); /* close all prepared statements */
DBUG_ASSERT(lock_info.n_cursors == 0);
- if (!cleanup_done)
- cleanup();
-
ha_close_connection(this);
plugin_thdvar_cleanup(this);
+ if (!cleanup_done)
+ cleanup();
+
DBUG_PRINT("info", ("freeing security context"));
main_security_ctx.destroy();
safeFree(db);
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 5d18d7f108a..a17e7152655 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -22,6 +22,7 @@
#include "log.h"
#include "rpl_tblmap.h"
+#include <waiting_threads.h>
class Relay_log_info;
@@ -1327,6 +1328,7 @@ public:
THD_TRANS stmt; // Trans for current statement
bool on; // see ha_enable_transaction()
XID_STATE xid_state;
+ WT_THD wt;
Rows_log_event *m_pending_rows_event;
/*
diff --git a/storage/maria/ha_maria.cc b/storage/maria/ha_maria.cc
index 4cffabaa059..001aa1262ce 100644
--- a/storage/maria/ha_maria.cc
+++ b/storage/maria/ha_maria.cc
@@ -2267,7 +2267,7 @@ int ha_maria::external_lock(THD *thd, int lock_type)
/* Start of new statement */
if (!trn) /* no transaction yet - open it now */
{
- trn= trnman_new_trn(& thd->mysys_var->mutex, & thd->mysys_var->suspend);
+ trn= trnman_new_trn(& thd->transaction.wt);
if (unlikely(!trn))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
THD_TRN= trn;
@@ -2457,7 +2457,7 @@ int ha_maria::implicit_commit(THD *thd, bool new_trn)
tables may be under LOCK TABLES, and so they will start the next
statement assuming they have a trn (see ha_maria::start_stmt()).
*/
- trn= trnman_new_trn(& thd->mysys_var->mutex, & thd->mysys_var->suspend);
+ trn= trnman_new_trn(& thd->transaction.wt);
/* This is just a commit, tables stay locked if they were: */
trnman_reset_locked_tables(trn, locked_tables);
THD_TRN= trn;
diff --git a/storage/maria/ma_commit.c b/storage/maria/ma_commit.c
index 02a07fe5f15..a4c50d9f8d6 100644
--- a/storage/maria/ma_commit.c
+++ b/storage/maria/ma_commit.c
@@ -106,9 +106,7 @@ int maria_begin(MARIA_HA *info)
if (info->s->now_transactional)
{
- TRN *trn;
- struct st_my_thread_var *mysys_var= my_thread_var;
- trn= trnman_new_trn(&mysys_var->mutex, &mysys_var->suspend);
+ TRN *trn= trnman_new_trn(0);
if (unlikely(!trn))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
diff --git a/storage/maria/ma_write.c b/storage/maria/ma_write.c
index 53a0e08a793..09391ad829c 100644
--- a/storage/maria/ma_write.c
+++ b/storage/maria/ma_write.c
@@ -221,13 +221,13 @@ int maria_write(MARIA_HA *info, uchar *record)
rc.type= &ma_rc_dup_unique;
rc.value.ptr= blocker; /* TODO savepoint id when we'll have them */
- res= wt_thd_will_wait_for(& info->trn->wt, & blocker->wt, & rc);
+ res= wt_thd_will_wait_for(info->trn->wt, blocker->wt, & rc);
if (res != WT_OK)
{
pthread_mutex_unlock(& blocker->state_lock);
goto err;
}
- res=wt_thd_cond_timedwait(& info->trn->wt, & blocker->state_lock);
+ res=wt_thd_cond_timedwait(info->trn->wt, & blocker->state_lock);
pthread_mutex_unlock(& blocker->state_lock);
if (res != WT_OK)
goto err;
diff --git a/storage/maria/maria_def.h b/storage/maria/maria_def.h
index 3d633355729..060432c4696 100644
--- a/storage/maria/maria_def.h
+++ b/storage/maria/maria_def.h
@@ -462,7 +462,7 @@ typedef struct st_maria_block_scan
struct st_maria_handler
{
MARIA_SHARE *s; /* Shared between open:s */
- struct st_transaction *trn; /* Pointer to active transaction */
+ struct st_ma_transaction *trn; /* Pointer to active transaction */
MARIA_STATUS_INFO *state, state_save;
MARIA_STATUS_INFO *state_start; /* State at start of transaction */
MARIA_ROW cur_row; /* The active row that we just read */
@@ -761,7 +761,6 @@ extern char *maria_data_root;
extern uchar maria_zero_string[];
extern my_bool maria_inited, maria_in_ha_maria;
extern HASH maria_stored_state;
-extern WT_RESOURCE_TYPE ma_rc_dup_unique;
/* This is used by _ma_calc_xxx_key_length och _ma_store_key */
typedef struct st_maria_s_param
diff --git a/storage/maria/trnman.c b/storage/maria/trnman.c
index c232442b904..42c32db3cab 100644
--- a/storage/maria/trnman.c
+++ b/storage/maria/trnman.c
@@ -81,6 +81,16 @@ void trnman_reset_locked_tables(TRN *trn, uint locked_tables)
trn->locked_tables= locked_tables;
}
+static void wt_thd_release_self(TRN *trn)
+{
+ if (trn->wt)
+ {
+ WT_RESOURCE_ID rc;
+ rc.type= &ma_rc_dup_unique;
+ rc.value.ptr= trn;
+ wt_thd_release(trn->wt, & rc);
+ }
+}
static my_bool
default_trnman_end_trans_hook(TRN *trn __attribute__ ((unused)),
@@ -114,8 +124,6 @@ int trnman_init(TrID initial_trid)
{
DBUG_ENTER("trnman_init");
- wt_init(); /* FIXME this should be done in the server, not in the engine! */
-
short_trid_to_active_trn= (TRN **)my_malloc(SHORT_TRID_MAX*sizeof(TRN*),
MYF(MY_WME|MY_ZEROFILL));
if (unlikely(!short_trid_to_active_trn))
@@ -182,7 +190,6 @@ void trnman_destroy()
TRN *trn= pool;
pool= pool->next;
pthread_mutex_destroy(&trn->state_lock);
- wt_thd_destroy(&trn->wt);
my_free((void *)trn, MYF(0));
}
lf_hash_destroy(&trid_to_trn);
@@ -193,8 +200,6 @@ void trnman_destroy()
my_free((void *)(short_trid_to_active_trn+1), MYF(0));
short_trid_to_active_trn= NULL;
- wt_end();
-
DBUG_VOID_RETURN;
}
@@ -243,7 +248,7 @@ static uint get_short_trid(TRN *trn)
mutex and cond will be used for lock waits
*/
-TRN *trnman_new_trn(pthread_mutex_t *mutex, pthread_cond_t *cond)
+TRN *trnman_new_trn(WT_THD *wt)
{
int res;
TRN *trn;
@@ -291,7 +296,7 @@ TRN *trnman_new_trn(pthread_mutex_t *mutex, pthread_cond_t *cond)
}
trnman_allocated_transactions++;
pthread_mutex_init(&trn->state_lock, MY_MUTEX_INIT_FAST);
- wt_thd_init(&trn->wt);
+ trn->wt= wt;
}
trn->pins= lf_hash_get_pins(&trid_to_trn);
if (!trn->pins)
@@ -418,7 +423,7 @@ my_bool trnman_end_trn(TRN *trn, my_bool commit)
{
pthread_mutex_lock(&trn->state_lock);
trn->commit_trid= global_trid_generator;
- wt_thd_release_all(& trn->wt);
+ wt_thd_release_self(trn);
pthread_mutex_unlock(&trn->state_lock);
trn->next= &committed_list_max;
@@ -457,11 +462,6 @@ my_bool trnman_end_trn(TRN *trn, my_bool commit)
/* ignore OOM. it's harmless, and we can do nothing here anyway */
(void)lf_hash_delete(&trid_to_trn, pins, &t->trid, sizeof(TrID));
- pthread_mutex_lock(&trn->state_lock);
- trn->short_id= 0;
- wt_thd_release_all(& trn->wt);
- pthread_mutex_unlock(&trn->state_lock);
-
trnman_free_trn(t);
}
@@ -489,6 +489,13 @@ void trnman_free_trn(TRN *trn)
*/
union { TRN *trn; void *v; } tmp;
+
+ pthread_mutex_lock(&trn->state_lock);
+ trn->short_id= 0;
+ wt_thd_release_self(trn);
+ trn->wt= 0; /* just in case */
+ pthread_mutex_unlock(&trn->state_lock);
+
tmp.trn= pool;
my_atomic_rwlock_wrlock(&LOCK_pool);
@@ -759,7 +766,7 @@ TRN *trnman_recreate_trn_from_recovery(uint16 shortid, TrID longid)
TRN *trn;
DBUG_ASSERT(maria_in_recovery && !maria_multi_threaded);
global_trid_generator= longid-1; /* force a correct trid in the new trn */
- if (unlikely((trn= trnman_new_trn(NULL, NULL)) == NULL))
+ if (unlikely((trn= trnman_new_trn(NULL)) == NULL))
return NULL;
/* deallocate excessive allocations of trnman_new_trn() */
global_trid_generator= old_trid_generator;
diff --git a/storage/maria/trnman.h b/storage/maria/trnman.h
index f9f1d91d50e..97fef57e618 100644
--- a/storage/maria/trnman.h
+++ b/storage/maria/trnman.h
@@ -21,7 +21,6 @@ C_MODE_START
#include <lf.h>
#include "trnman_public.h"
#include "ma_loghandler_lsn.h"
-#include <waiting_threads.h>
/*
trid - 6 uchar transaction identifier. Assigned when a transaction
@@ -42,10 +41,10 @@ C_MODE_START
commit_trid happen under this mutex.
*/
-struct st_transaction
+struct st_ma_transaction
{
LF_PINS *pins;
- WT_THD wt;
+ WT_THD *wt;
pthread_mutex_t state_lock;
void *used_tables; /* Tables used by transaction */
TRN *next, *prev;
@@ -58,6 +57,8 @@ struct st_transaction
#define TRANSACTION_LOGGED_LONG_ID ULL(0x8000000000000000)
+extern WT_RESOURCE_TYPE ma_rc_dup_unique;
+
C_MODE_END
#endif
diff --git a/storage/maria/trnman_public.h b/storage/maria/trnman_public.h
index fe172cbbb54..b89ce23df37 100644
--- a/storage/maria/trnman_public.h
+++ b/storage/maria/trnman_public.h
@@ -24,10 +24,11 @@
#define _trnman_public_h
#include "ma_loghandler_lsn.h"
+#include <waiting_threads.h>
C_MODE_START
typedef uint64 TrID; /* our TrID is 6 bytes */
-typedef struct st_transaction TRN;
+typedef struct st_ma_transaction TRN;
#define SHORT_TRID_MAX 65535
@@ -38,7 +39,7 @@ extern my_bool (*trnman_end_trans_hook)(TRN *trn, my_bool commit,
int trnman_init(TrID);
void trnman_destroy(void);
-TRN *trnman_new_trn(pthread_mutex_t *, pthread_cond_t *);
+TRN *trnman_new_trn(WT_THD *wt);
my_bool trnman_end_trn(TRN *trn, my_bool commit);
#define trnman_commit_trn(T) trnman_end_trn(T, TRUE)
#define trnman_abort_trn(T) trnman_end_trn(T, FALSE)
diff --git a/storage/maria/unittest/trnman-t.c b/storage/maria/unittest/trnman-t.c
index 0873761c0a2..77244334351 100644
--- a/storage/maria/unittest/trnman-t.c
+++ b/storage/maria/unittest/trnman-t.c
@@ -38,25 +38,17 @@ pthread_handler_t test_trnman(void *arg)
{
uint x, y, i, n;
TRN *trn[MAX_ITER];
- pthread_mutex_t mutexes[MAX_ITER];
- pthread_cond_t conds[MAX_ITER];
int m= (*(int *)arg);
my_thread_init();
- for (i= 0; i < MAX_ITER; i++)
- {
- pthread_mutex_init(&mutexes[i], MY_MUTEX_INIT_FAST);
- pthread_cond_init(&conds[i], 0);
- }
-
for (x= ((int)(intptr)(&m)); m > 0; )
{
y= x= (x*LL(3628273133) + LL(1500450271)) % LL(9576890767); /* three prime numbers */
m-= n= x % MAX_ITER;
for (i= 0; i < n; i++)
{
- trn[i]= trnman_new_trn(&mutexes[i], &conds[i]);
+ trn[i]= trnman_new_trn(0);
if (!trn[i])
{
diag("trnman_new_trn() failed");
@@ -69,11 +61,6 @@ pthread_handler_t test_trnman(void *arg)
trnman_end_trn(trn[i], y & 1);
}
}
- for (i= 0; i < MAX_ITER; i++)
- {
- pthread_mutex_destroy(&mutexes[i]);
- pthread_cond_destroy(&conds[i]);
- }
pthread_mutex_lock(&rt_mutex);
rt_num_threads--;
pthread_mutex_unlock(&rt_mutex);
@@ -115,10 +102,10 @@ void run_test(const char *test, pthread_handler handler, int n, int m)
}
#define ok_read_from(T1, T2, RES) \
- i= trnman_can_read_from(trn[T1], trid[T2]); \
+ i= trnman_can_read_from(trn[T1], trid[T2]); \
ok(i == RES, "trn" #T1 " %s read from trn" #T2, i ? "can" : "cannot")
#define start_transaction(T) \
- trn[T]= trnman_new_trn(&mutexes[T], &conds[T]); \
+ trn[T]= trnman_new_trn(0); \
trid[T]= trn[T]->trid
#define commit(T) trnman_commit_trn(trn[T])
#define abort(T) trnman_abort_trn(trn[T])
@@ -128,16 +115,8 @@ void test_trnman_read_from()
{
TRN *trn[Ntrns];
TrID trid[Ntrns];
- pthread_mutex_t mutexes[Ntrns];
- pthread_cond_t conds[Ntrns];
int i;
- for (i= 0; i < Ntrns; i++)
- {
- pthread_mutex_init(&mutexes[i], MY_MUTEX_INIT_FAST);
- pthread_cond_init(&conds[i], 0);
- }
-
start_transaction(0); /* start trn1 */
start_transaction(1); /* start trn2 */
ok_read_from(1, 0, 0);
@@ -153,11 +132,6 @@ void test_trnman_read_from()
ok_read_from(3, 1, 0);
commit(3); /* commit trn5 */
- for (i= 0; i < Ntrns; i++)
- {
- pthread_mutex_destroy(&mutexes[i]);
- pthread_cond_destroy(&conds[i]);
- }
}
int main(int argc __attribute__((unused)), char **argv)