From 74facf71c44df55bb7ce532922d7df2bb4dd3fb5 Mon Sep 17 00:00:00 2001 From: Rik Prohaska Date: Wed, 5 Aug 2015 10:16:33 -0400 Subject: [PATCH] run tokudb on mysql 5.7.8 support JSON data enable XA Copyright (c) 2015, Rich Prohaska All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --- storage/tokudb/ha_tokudb.cc | 177 ++++++++++++++++----------- storage/tokudb/ha_tokudb.h | 12 +- storage/tokudb/ha_tokudb_admin.cc | 32 +++-- storage/tokudb/ha_tokudb_alter_56.cc | 47 +++++-- storage/tokudb/hatoku_cmp.cc | 8 ++ storage/tokudb/hatoku_defines.h | 115 +++++++++++++++-- storage/tokudb/hatoku_hton.cc | 86 ++++++++----- 7 files changed, 333 insertions(+), 144 deletions(-) diff --git a/storage/tokudb/ha_tokudb.cc b/storage/tokudb/ha_tokudb.cc index 5e8c3819..992f02fd 100644 --- a/storage/tokudb/ha_tokudb.cc +++ b/storage/tokudb/ha_tokudb.cc @@ -166,18 +166,18 @@ static void free_key_and_col_info (KEY_AND_COL_INFO* kc_info) { void TOKUDB_SHARE::init(void) { use_count = 0; thr_lock_init(&lock); - tokudb_pthread_mutex_init(&mutex, MY_MUTEX_INIT_FAST); - my_rwlock_init(&num_DBs_lock, 0); - tokudb_pthread_cond_init(&m_openclose_cond, NULL); + tokudb_mutex_init(&mutex, MY_MUTEX_INIT_FAST); + tokudb_rw_init(&num_DBs_lock); + tokudb_cond_init(&m_openclose_cond); m_state = CLOSED; } void TOKUDB_SHARE::destroy(void) { assert(m_state == CLOSED); thr_lock_delete(&lock); - tokudb_pthread_mutex_destroy(&mutex); - rwlock_destroy(&num_DBs_lock); - tokudb_pthread_cond_destroy(&m_openclose_cond); + tokudb_mutex_destroy(&mutex); + tokudb_rw_destroy(&num_DBs_lock); + tokudb_cond_destroy(&m_openclose_cond); tokudb_my_free(rec_per_key); rec_per_key = NULL; } @@ -203,8 +203,7 @@ static TOKUDB_SHARE *get_share(const char *table_name, TABLE_SHARE* table_share) share->table_name_length = length; share->table_name = tmp_name; - strmov(share->table_name, table_name); - + strcpy(share->table_name, table_name); error = my_hash_insert(&tokudb_open_tables, (uchar *) share); if (error) { free_key_and_col_info(&share->kc_info); @@ -224,11 +223,11 @@ static TOKUDB_SHARE *get_share(const char *table_name, TABLE_SHARE* table_share) static int free_share(TOKUDB_SHARE * share) { int error, result = 0; - tokudb_pthread_mutex_lock(&share->mutex); + tokudb_mutex_lock(&share->mutex); DBUG_PRINT("info", ("share->use_count %u", share->use_count)); if (!--share->use_count) { share->m_state = TOKUDB_SHARE::CLOSING; - tokudb_pthread_mutex_unlock(&share->mutex); + tokudb_mutex_unlock(&share->mutex); // // number of open DB's may not be equal to number of keys we have because add_index @@ -256,25 +255,25 @@ static int free_share(TOKUDB_SHARE * share) { free_key_and_col_info(&share->kc_info); - tokudb_pthread_mutex_lock(&tokudb_mutex); - tokudb_pthread_mutex_lock(&share->mutex); + tokudb_mutex_lock(&tokudb_mutex); + tokudb_mutex_lock(&share->mutex); share->m_state = TOKUDB_SHARE::CLOSED; if (share->use_count > 0) { - tokudb_pthread_cond_broadcast(&share->m_openclose_cond); - tokudb_pthread_mutex_unlock(&share->mutex); - tokudb_pthread_mutex_unlock(&tokudb_mutex); + tokudb_cond_broadcast(&share->m_openclose_cond); + tokudb_mutex_unlock(&share->mutex); + tokudb_mutex_unlock(&tokudb_mutex); } else { my_hash_delete(&tokudb_open_tables, (uchar *) share); - tokudb_pthread_mutex_unlock(&share->mutex); - tokudb_pthread_mutex_unlock(&tokudb_mutex); + tokudb_mutex_unlock(&share->mutex); + tokudb_mutex_unlock(&tokudb_mutex); share->destroy(); tokudb_my_free((uchar *) share); } } else { - tokudb_pthread_mutex_unlock(&share->mutex); + tokudb_mutex_unlock(&share->mutex); } return result; @@ -308,7 +307,11 @@ static inline bool is_insert_ignore (THD* thd) { // // from http://lists.mysql.com/internals/37735 // +#if (50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799) + return thd->lex->is_ignore() && thd->lex->duplicates == DUP_ERROR; +#else return thd->lex->ignore && thd->lex->duplicates == DUP_ERROR; +#endif } static inline bool is_replace_into(THD* thd) { @@ -607,14 +610,22 @@ static ulonglong retrieve_auto_increment(uint16 type, uint32 offset,const uchar /* The remaining two cases should not be used but are included for compatibility */ - case HA_KEYTYPE_FLOAT: + case HA_KEYTYPE_FLOAT: +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + float4get(&float_tmp, key); +#else float4get(float_tmp, key); /* Note: float4get is a macro */ +#endif signed_autoinc = (longlong) float_tmp; autoinc_type = signed_type; break; case HA_KEYTYPE_DOUBLE: +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + float8get(&double_tmp, key); +#else float8get(double_tmp, key); /* Note: float8get is a macro */ +#endif signed_autoinc = (longlong) double_tmp; autoinc_type = signed_type; break; @@ -1621,7 +1632,11 @@ int ha_tokudb::initialize_share(const char* name, int mode) { KEY_PART_INFO *key_part = table->key_info[primary_key].key_part; KEY_PART_INFO *end = key_part + get_key_parts(&table->key_info[primary_key]); for (; key_part != end; key_part++) { +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + ref_length += key_part->field->max_packed_col_length(); +#else ref_length += key_part->field->max_packed_col_length(key_part->length); +#endif TOKU_TYPE toku_type = mysql_to_toku_type(key_part->field); if (toku_type == toku_type_fixstring || toku_type == toku_type_varstring || @@ -1759,44 +1774,44 @@ int ha_tokudb::open(const char *name, int mode, uint test_if_locked) { } // lookup or create share - tokudb_pthread_mutex_lock(&tokudb_mutex); + tokudb_mutex_lock(&tokudb_mutex); share = get_share(name, table_share); assert(share); thr_lock_data_init(&share->lock, &lock, NULL); - tokudb_pthread_mutex_lock(&share->mutex); - tokudb_pthread_mutex_unlock(&tokudb_mutex); + tokudb_mutex_lock(&share->mutex); + tokudb_mutex_unlock(&tokudb_mutex); share->use_count++; while (share->m_state == TOKUDB_SHARE::OPENING || share->m_state == TOKUDB_SHARE::CLOSING) { - tokudb_pthread_cond_wait(&share->m_openclose_cond, &share->mutex); + tokudb_cond_wait(&share->m_openclose_cond, &share->mutex); } if (share->m_state == TOKUDB_SHARE::CLOSED) { share->m_state = TOKUDB_SHARE::OPENING; - tokudb_pthread_mutex_unlock(&share->mutex); + tokudb_mutex_unlock(&share->mutex); ret_val = allocate_key_and_col_info(table_share, &share->kc_info); if (ret_val == 0) { ret_val = initialize_share(name, mode); } - tokudb_pthread_mutex_lock(&share->mutex); + tokudb_mutex_lock(&share->mutex); if (ret_val == 0) { share->m_state = TOKUDB_SHARE::OPENED; } else { share->m_state = TOKUDB_SHARE::ERROR; share->m_error = ret_val; } - tokudb_pthread_cond_broadcast(&share->m_openclose_cond); + tokudb_cond_broadcast(&share->m_openclose_cond); } if (share->m_state == TOKUDB_SHARE::ERROR) { ret_val = share->m_error; - tokudb_pthread_mutex_unlock(&share->mutex); + tokudb_mutex_unlock(&share->mutex); free_share(share); goto exit; } else { assert(share->m_state == TOKUDB_SHARE::OPENED); - tokudb_pthread_mutex_unlock(&share->mutex); + tokudb_mutex_unlock(&share->mutex); } ref_length = share->ref_length; // If second open @@ -3165,7 +3180,7 @@ void ha_tokudb::start_bulk_insert(ha_rows rows) { ai_metadata_update_required = false; abort_loader = false; - rw_rdlock(&share->num_DBs_lock); + tokudb_rw_rdlock(&share->num_DBs_lock); uint curr_num_DBs = table->s->keys + tokudb_test(hidden_primary_key); num_DBs_locked_in_bulk = true; lock_count = 0; @@ -3212,9 +3227,9 @@ void ha_tokudb::start_bulk_insert(ha_rows rows) { } } exit_try_table_lock: - tokudb_pthread_mutex_lock(&share->mutex); + tokudb_mutex_lock(&share->mutex); share->try_table_lock = false; - tokudb_pthread_mutex_unlock(&share->mutex); + tokudb_mutex_unlock(&share->mutex); } TOKUDB_HANDLER_DBUG_VOID_RETURN; } @@ -3231,9 +3246,9 @@ int ha_tokudb::end_bulk_insert(bool abort) { tokudb_trx_data* trx = (tokudb_trx_data *) thd_get_ha_data(thd, tokudb_hton); bool using_loader = (loader != NULL); if (ai_metadata_update_required) { - tokudb_pthread_mutex_lock(&share->mutex); + tokudb_mutex_lock(&share->mutex); error = update_max_auto_inc(share->status_block, share->last_auto_increment); - tokudb_pthread_mutex_unlock(&share->mutex); + tokudb_mutex_unlock(&share->mutex); if (error) { goto cleanup; } } delay_updating_ai_metadata = false; @@ -3284,7 +3299,7 @@ int ha_tokudb::end_bulk_insert(bool abort) { cleanup: if (num_DBs_locked_in_bulk) { - rw_unlock(&share->num_DBs_lock); + tokudb_rw_unlock(&share->num_DBs_lock); } num_DBs_locked_in_bulk = false; lock_count = 0; @@ -3806,7 +3821,7 @@ int ha_tokudb::write_row(uchar * record) { // of the auto inc field. // if (share->has_auto_inc && record == table->record[0]) { - tokudb_pthread_mutex_lock(&share->mutex); + tokudb_mutex_lock(&share->mutex); ulonglong curr_auto_inc = retrieve_auto_increment( table->field[share->ai_field_index]->key_type(), field_offset(table->field[share->ai_field_index], table), record); if (curr_auto_inc > share->last_auto_increment) { @@ -3818,21 +3833,21 @@ int ha_tokudb::write_row(uchar * record) { update_max_auto_inc(share->status_block, share->last_auto_increment); } } - tokudb_pthread_mutex_unlock(&share->mutex); + tokudb_mutex_unlock(&share->mutex); } // // grab reader lock on numDBs_lock // if (!num_DBs_locked_in_bulk) { - rw_rdlock(&share->num_DBs_lock); + tokudb_rw_rdlock(&share->num_DBs_lock); num_DBs_locked = true; } else { lock_count++; if (lock_count >= 2000) { - rw_unlock(&share->num_DBs_lock); - rw_rdlock(&share->num_DBs_lock); + tokudb_rw_unlock(&share->num_DBs_lock); + tokudb_rw_rdlock(&share->num_DBs_lock); lock_count = 0; } } @@ -3918,7 +3933,7 @@ int ha_tokudb::write_row(uchar * record) { } cleanup: if (num_DBs_locked) { - rw_unlock(&share->num_DBs_lock); + tokudb_rw_unlock(&share->num_DBs_lock); } if (error == DB_KEYEXIST) { error = HA_ERR_FOUND_DUPP_KEY; @@ -3962,7 +3977,7 @@ bool ha_tokudb::key_changed(uint keynr, const uchar * old_row, const uchar * new int ha_tokudb::update_row(const uchar * old_row, uchar * new_row) { TOKUDB_HANDLER_DBUG_ENTER(""); DBT prim_key, old_prim_key, prim_row, old_prim_row; - int error; + int error = 0; bool has_null; THD* thd = ha_thd(); DB_TXN* sub_trans = NULL; @@ -3970,7 +3985,6 @@ int ha_tokudb::update_row(const uchar * old_row, uchar * new_row) { tokudb_trx_data* trx = (tokudb_trx_data *) thd_get_ha_data(thd, tokudb_hton); uint curr_num_DBs; - LINT_INIT(error); memset((void *) &prim_key, 0, sizeof(prim_key)); memset((void *) &old_prim_key, 0, sizeof(old_prim_key)); memset((void *) &prim_row, 0, sizeof(prim_row)); @@ -3989,7 +4003,7 @@ int ha_tokudb::update_row(const uchar * old_row, uchar * new_row) { // of the auto inc field. // if (share->has_auto_inc && new_row == table->record[0]) { - tokudb_pthread_mutex_lock(&share->mutex); + tokudb_mutex_lock(&share->mutex); ulonglong curr_auto_inc = retrieve_auto_increment( table->field[share->ai_field_index]->key_type(), field_offset(table->field[share->ai_field_index], table), @@ -4001,7 +4015,7 @@ int ha_tokudb::update_row(const uchar * old_row, uchar * new_row) { share->last_auto_increment = curr_auto_inc; } } - tokudb_pthread_mutex_unlock(&share->mutex); + tokudb_mutex_unlock(&share->mutex); } // @@ -4009,7 +4023,7 @@ int ha_tokudb::update_row(const uchar * old_row, uchar * new_row) { // bool num_DBs_locked = false; if (!num_DBs_locked_in_bulk) { - rw_rdlock(&share->num_DBs_lock); + tokudb_rw_rdlock(&share->num_DBs_lock); num_DBs_locked = true; } curr_num_DBs = share->num_DBs; @@ -4107,7 +4121,7 @@ int ha_tokudb::update_row(const uchar * old_row, uchar * new_row) { cleanup: if (num_DBs_locked) { - rw_unlock(&share->num_DBs_lock); + tokudb_rw_unlock(&share->num_DBs_lock); } if (error == DB_KEYEXIST) { error = HA_ERR_FOUND_DUPP_KEY; @@ -4150,7 +4164,7 @@ int ha_tokudb::delete_row(const uchar * record) { // bool num_DBs_locked = false; if (!num_DBs_locked_in_bulk) { - rw_rdlock(&share->num_DBs_lock); + tokudb_rw_rdlock(&share->num_DBs_lock); num_DBs_locked = true; } curr_num_DBs = share->num_DBs; @@ -4192,7 +4206,7 @@ int ha_tokudb::delete_row(const uchar * record) { } cleanup: if (num_DBs_locked) { - rw_unlock(&share->num_DBs_lock); + tokudb_rw_unlock(&share->num_DBs_lock); } TOKUDB_HANDLER_DBUG_RETURN(error); } @@ -5959,7 +5973,7 @@ int ha_tokudb::acquire_table_lock (DB_TXN* trans, TABLE_LOCK_TYPE lt) { TOKUDB_HANDLER_DBUG_ENTER("%p %s", trans, lt == lock_read ? "r" : "w"); int error = ENOSYS; if (!num_DBs_locked_in_bulk) { - rw_rdlock(&share->num_DBs_lock); + tokudb_rw_rdlock(&share->num_DBs_lock); } uint curr_num_DBs = share->num_DBs; if (lt == lock_read) { @@ -5986,7 +6000,7 @@ int ha_tokudb::acquire_table_lock (DB_TXN* trans, TABLE_LOCK_TYPE lt) { error = 0; cleanup: if (!num_DBs_locked_in_bulk) { - rw_unlock(&share->num_DBs_lock); + tokudb_rw_unlock(&share->num_DBs_lock); } TOKUDB_HANDLER_DBUG_RETURN(error); } @@ -6009,7 +6023,7 @@ int ha_tokudb::create_txn(THD* thd, tokudb_trx_data* trx) { /* QQQ We have to start a master transaction */ // DBUG_PRINT("trans", ("starting transaction all ")); uint32_t txn_begin_flags = toku_iso_to_txn_flag(toku_iso_level); -#if 50614 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50699 +#if 50614 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 if (thd_tx_is_read_only(thd)) { txn_begin_flags |= DB_TXN_READ_ONLY; } @@ -6021,7 +6035,11 @@ int ha_tokudb::create_txn(THD* thd, tokudb_trx_data* trx) { TOKUDB_HANDLER_TRACE("created master %p", trx->all); } trx->sp_level = trx->all; +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + trans_register_ha(thd, true, tokudb_hton, NULL); +#else trans_register_ha(thd, true, tokudb_hton); +#endif } DBUG_PRINT("trans", ("starting transaction stmt")); if (trx->stmt) { @@ -6058,7 +6076,11 @@ int ha_tokudb::create_txn(THD* thd, tokudb_trx_data* trx) { TOKUDB_HANDLER_TRACE("created stmt %p sp_level %p", trx->sp_level, trx->stmt); } reset_stmt_progress(&trx->stmt_progress); +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + trans_register_ha(thd, false, tokudb_hton, NULL); +#else trans_register_ha(thd, false, tokudb_hton); +#endif cleanup: return error; } @@ -6091,9 +6113,11 @@ int ha_tokudb::external_lock(THD * thd, int lock_type) { if (!(tokudb_debug & TOKUDB_DEBUG_ENTER) && (tokudb_debug & TOKUDB_DEBUG_LOCK)) { TOKUDB_HANDLER_TRACE("cmd %d lock %d %s %s", thd_sql_command(thd), lock_type, lock_type_str(lock_type), share->table_name); } +#if MYSQL_VERSION_ID < 50700 if (tokudb_debug & TOKUDB_DEBUG_LOCK) { TOKUDB_HANDLER_TRACE("q %s", thd->query()); } +#endif int error = 0; tokudb_trx_data *trx = (tokudb_trx_data *) thd_get_ha_data(thd, tokudb_hton); @@ -6128,7 +6152,7 @@ int ha_tokudb::external_lock(THD * thd, int lock_type) { trx->tokudb_lock_count++; } else { - tokudb_pthread_mutex_lock(&share->mutex); + tokudb_mutex_lock(&share->mutex); // hate dealing with comparison of signed vs unsigned, so doing this if (deleted_rows > added_rows && share->rows < (deleted_rows - added_rows)) { share->rows = 0; @@ -6136,7 +6160,7 @@ int ha_tokudb::external_lock(THD * thd, int lock_type) { else { share->rows += (added_rows - deleted_rows); } - tokudb_pthread_mutex_unlock(&share->mutex); + tokudb_mutex_unlock(&share->mutex); added_rows = 0; deleted_rows = 0; share->rows_from_locked_table = 0; @@ -6172,9 +6196,11 @@ int ha_tokudb::external_lock(THD * thd, int lock_type) { */ int ha_tokudb::start_stmt(THD * thd, thr_lock_type lock_type) { TOKUDB_HANDLER_DBUG_ENTER("cmd %d lock %d %s", thd_sql_command(thd), lock_type, share->table_name); +#if MYSQL_VERSION_ID < 50700 if (tokudb_debug & TOKUDB_DEBUG_LOCK) { TOKUDB_HANDLER_TRACE("q %s", thd->query()); } +#endif int error = 0; tokudb_trx_data *trx = (tokudb_trx_data *) thd_get_ha_data(thd, tokudb_hton); @@ -6210,7 +6236,11 @@ int ha_tokudb::start_stmt(THD * thd, thr_lock_type lock_type) { share->rows_from_locked_table = added_rows - deleted_rows; } transaction = trx->sub_sp_level; +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + trans_register_ha(thd, false, tokudb_hton, NULL); +#else trans_register_ha(thd, false, tokudb_hton); +#endif cleanup: TOKUDB_HANDLER_DBUG_RETURN(error); } @@ -6289,11 +6319,11 @@ THR_LOCK_DATA **ha_tokudb::store_lock(THD * thd, THR_LOCK_DATA ** to, enum thr_l if (!thd->in_lock_tables) { if (sql_command == SQLCOM_CREATE_INDEX && get_create_index_online(thd)) { // hot indexing - rw_rdlock(&share->num_DBs_lock); + tokudb_rw_rdlock(&share->num_DBs_lock); if (share->num_DBs == (table->s->keys + tokudb_test(hidden_primary_key))) { lock_type = TL_WRITE_ALLOW_WRITE; } - rw_unlock(&share->num_DBs_lock); + tokudb_rw_unlock(&share->num_DBs_lock); } else if ((lock_type >= TL_WRITE_CONCURRENT_INSERT && lock_type <= TL_WRITE) && sql_command != SQLCOM_TRUNCATE && !thd_tablespace_op(thd)) { // allow concurrent writes @@ -7361,7 +7391,7 @@ void ha_tokudb::get_auto_increment(ulonglong offset, ulonglong increment, ulongl ulonglong nr; bool over; - tokudb_pthread_mutex_lock(&share->mutex); + tokudb_mutex_lock(&share->mutex); if (share->auto_inc_create_value > share->last_auto_increment) { nr = share->auto_inc_create_value; @@ -7371,8 +7401,9 @@ void ha_tokudb::get_auto_increment(ulonglong offset, ulonglong increment, ulongl else { nr = share->last_auto_increment + increment; over = nr < share->last_auto_increment; - if (over) - nr = ULONGLONG_MAX; + if (over) { + nr = ~0ULL; // nr = ULONGLONG_MAX; + } } if (!over) { share->last_auto_increment = nr + (nb_desired_values - 1)*increment; @@ -7390,7 +7421,7 @@ void ha_tokudb::get_auto_increment(ulonglong offset, ulonglong increment, ulongl } *first_value = nr; *nb_reserved_values = nb_desired_values; - tokudb_pthread_mutex_unlock(&share->mutex); + tokudb_mutex_unlock(&share->mutex); TOKUDB_HANDLER_DBUG_VOID_RETURN; } @@ -7500,7 +7531,7 @@ int ha_tokudb::tokudb_add_index( } } - rw_wrlock(&share->num_DBs_lock); + tokudb_rw_wrlock(&share->num_DBs_lock); rw_lock_taken = true; // // open all the DB files and set the appropriate variables in share @@ -7574,7 +7605,7 @@ int ha_tokudb::tokudb_add_index( error = indexer->set_error_callback(indexer, loader_ai_err_fun, &lc); if (error) { goto cleanup; } - rw_unlock(&share->num_DBs_lock); + tokudb_rw_unlock(&share->num_DBs_lock); rw_lock_taken = false; #ifdef HA_TOKUDB_HAS_THD_PROGRESS @@ -7587,15 +7618,15 @@ int ha_tokudb::tokudb_add_index( if (error) { goto cleanup; } - rw_wrlock(&share->num_DBs_lock); + tokudb_rw_wrlock(&share->num_DBs_lock); error = indexer->close(indexer); - rw_unlock(&share->num_DBs_lock); + tokudb_rw_unlock(&share->num_DBs_lock); if (error) { goto cleanup; } indexer = NULL; } else { DBUG_ASSERT(table->mdl_ticket->get_type() >= MDL_SHARED_NO_WRITE); - rw_unlock(&share->num_DBs_lock); + tokudb_rw_unlock(&share->num_DBs_lock); rw_lock_taken = false; prelocked_right_range_size = 0; prelocked_left_range_size = 0; @@ -7747,18 +7778,18 @@ int ha_tokudb::tokudb_add_index( // We have an accurate row count, might as well update share->rows // if(!creating_hot_index) { - tokudb_pthread_mutex_lock(&share->mutex); + tokudb_mutex_lock(&share->mutex); share->rows = num_processed; - tokudb_pthread_mutex_unlock(&share->mutex); + tokudb_mutex_unlock(&share->mutex); } // // now write stuff to status.tokudb // - tokudb_pthread_mutex_lock(&share->mutex); + tokudb_mutex_lock(&share->mutex); for (uint i = 0; i < num_of_keys; i++) { write_key_name_to_status(share->status_block, key_info[i].name, txn); } - tokudb_pthread_mutex_unlock(&share->mutex); + tokudb_mutex_unlock(&share->mutex); error = 0; cleanup: @@ -7766,7 +7797,7 @@ int ha_tokudb::tokudb_add_index( thd_progress_end(thd); #endif if (rw_lock_taken) { - rw_unlock(&share->num_DBs_lock); + tokudb_rw_unlock(&share->num_DBs_lock); rw_lock_taken = false; } if (tmp_cursor) { @@ -7782,9 +7813,9 @@ int ha_tokudb::tokudb_add_index( if (indexer != NULL) { sprintf(status_msg, "aborting creation of indexes."); thd_proc_info(thd, status_msg); - rw_wrlock(&share->num_DBs_lock); + tokudb_rw_wrlock(&share->num_DBs_lock); indexer->abort(indexer); - rw_unlock(&share->num_DBs_lock); + tokudb_rw_unlock(&share->num_DBs_lock); } if (error == DB_LOCK_NOTGRANTED && ((tokudb_debug & TOKUDB_DEBUG_HIDE_DDL_LOCK_ERRORS) == 0)) { sql_print_error("Could not add indexes to table %s because \ @@ -7808,7 +7839,7 @@ void ha_tokudb::restore_add_index(TABLE* table_arg, uint num_of_keys, bool incre // so that there is not a window // if (incremented_numDBs) { - rw_wrlock(&share->num_DBs_lock); + tokudb_rw_wrlock(&share->num_DBs_lock); share->num_DBs--; } if (modified_DBs) { @@ -7829,7 +7860,7 @@ void ha_tokudb::restore_add_index(TABLE* table_arg, uint num_of_keys, bool incre } } if (incremented_numDBs) { - rw_unlock(&share->num_DBs_lock); + tokudb_rw_unlock(&share->num_DBs_lock); } } diff --git a/storage/tokudb/ha_tokudb.h b/storage/tokudb/ha_tokudb.h index e263cabb..0faf6fe0 100644 --- a/storage/tokudb/ha_tokudb.h +++ b/storage/tokudb/ha_tokudb.h @@ -84,7 +84,7 @@ class TOKUDB_SHARE { // key is hidden // DB *key_file[MAX_KEY +1]; - rw_lock_t key_file_lock; + tokudb_rw_lock_t key_file_lock; uint status, version, capabilities; uint ref_length; // @@ -112,7 +112,7 @@ class TOKUDB_SHARE { bool has_unique_keys; bool replace_into_fast; - rw_lock_t num_DBs_lock; + tokudb_rw_lock_t num_DBs_lock; uint32_t num_DBs; pthread_cond_t m_openclose_cond; @@ -540,10 +540,10 @@ class ha_tokudb : public handler { int get_status(DB_TXN* trans); void init_hidden_prim_key_info(DB_TXN *txn); inline void get_auto_primary_key(uchar * to) { - tokudb_pthread_mutex_lock(&share->mutex); + tokudb_mutex_lock(&share->mutex); share->auto_ident++; hpk_num_to_char(to, share->auto_ident); - tokudb_pthread_mutex_unlock(&share->mutex); + tokudb_mutex_unlock(&share->mutex); } virtual void get_auto_increment(ulonglong offset, ulonglong increment, ulonglong nb_desired_values, ulonglong * first_value, ulonglong * nb_reserved_values); bool is_optimize_blocking(); @@ -552,7 +552,11 @@ class ha_tokudb : public handler { uint8 table_cache_type() { return HA_CACHE_TBL_TRANSACT; } +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + bool primary_key_is_clustered() const { +#else bool primary_key_is_clustered() { +#endif return true; } bool supports_clustered_keys() { diff --git a/storage/tokudb/ha_tokudb_admin.cc b/storage/tokudb/ha_tokudb_admin.cc index 996ce49d..72774c85 100644 --- a/storage/tokudb/ha_tokudb_admin.cc +++ b/storage/tokudb/ha_tokudb_admin.cc @@ -24,6 +24,7 @@ Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. #ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved." #include "toku_time.h" +#include "my_check_opt.h" struct analyze_progress_extra { THD *thd; @@ -110,15 +111,17 @@ int ha_tokudb::analyze(THD *thd, HA_CHECK_OPT *check_opt) { (int) table_share->db.length, table_share->db.str, (int) table_share->table_name.length, table_share->table_name.str, key_name); - thd->protocol->prepare_for_resend(); - thd->protocol->store(name, namelen, system_charset_info); - thd->protocol->store("analyze", 7, system_charset_info); - thd->protocol->store("info", 4, system_charset_info); char rowmsg[256]; int rowmsglen; rowmsglen = snprintf(rowmsg, sizeof rowmsg, "rows processed %" PRIu64 " rows deleted %" PRIu64, rows, deleted_rows); - thd->protocol->store(rowmsg, rowmsglen, system_charset_info); - thd->protocol->write(); - +#if 0 + Protocol *protocol = thd->protocol; + protocol->prepare_for_resend(); + protocol->store(name, namelen, system_charset_info); + protocol->store("analyze", 7, system_charset_info); + protocol->store("info", 4, system_charset_info); + protocol->store(rowmsg, rowmsglen, system_charset_info); + protocol->write(); +#endif sql_print_information("tokudb analyze on %.*s %.*s", namelen, name, rowmsglen, rowmsg); } @@ -277,12 +280,15 @@ static void ha_tokudb_check_info(THD *thd, TABLE *table, const char *msg) { snprintf(tablename, sizeof tablename, "%.*s.%.*s", (int) table->s->db.length, table->s->db.str, (int) table->s->table_name.length, table->s->table_name.str); - thd->protocol->prepare_for_resend(); - thd->protocol->store(tablename, strlen(tablename), system_charset_info); - thd->protocol->store("check", 5, system_charset_info); - thd->protocol->store("info", 4, system_charset_info); - thd->protocol->store(msg, strlen(msg), system_charset_info); - thd->protocol->write(); +#if 0 + Protocol *protocol = thd->protocol; + protocol->prepare_for_resend(); + protocol->store(tablename, strlen(tablename), system_charset_info); + protocol->store("check", 5, system_charset_info); + protocol->store("info", 4, system_charset_info); + protocol->store(msg, strlen(msg), system_charset_info); + protocol->write(); +#endif } } diff --git a/storage/tokudb/ha_tokudb_alter_56.cc b/storage/tokudb/ha_tokudb_alter_56.cc index 724c588e..a6971e36 100644 --- a/storage/tokudb/ha_tokudb_alter_56.cc +++ b/storage/tokudb/ha_tokudb_alter_56.cc @@ -27,14 +27,12 @@ Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. #if 100000 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 100099 #define TOKU_ALTER_RENAME ALTER_RENAME -#define DYNAMIC_ARRAY_ELEMENTS_TYPE size_t -#elif (50600 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50699) || \ - (50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799) +#elif 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 +#define TOKU_ALTER_RENAME ALTER_RENAME +#elif 50600 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50699 #define TOKU_ALTER_RENAME ALTER_RENAME -#define DYNAMIC_ARRAY_ELEMENTS_TYPE int #elif 50500 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50599 #define TOKU_ALTER_RENAME ALTER_RENAME_56 -#define DYNAMIC_ARRAY_ELEMENTS_TYPE int #else #error #endif @@ -43,6 +41,26 @@ Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. #include #include +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 +template class tokudb_vector { +private: + std::vector v; +public: + T at(uint i) { return v.at(i); } + void append(T n) { v.push_back(n); } + uint elements() const { return v.size(); } +}; +#else +template class tokudb_vector { +private: + Dynamic_array v; +public: + T at(uint i) { return v.at(i); } + void append(T n) { v.append(n); } + uint elements() const { return v.elements(); } +}; +#endif + // The tokudb alter context contains the alter state that is set in the check if supported method and used // later when the alter operation is executed. class tokudb_alter_ctx : public inplace_alter_handler_ctx { @@ -78,7 +96,7 @@ class tokudb_alter_ctx : public inplace_alter_handler_ctx { bool expand_fixed_update_needed; bool expand_blob_update_needed; bool optimize_needed; - Dynamic_array changed_fields; + tokudb_vector changed_fields; KEY_AND_COL_INFO *table_kc_info; KEY_AND_COL_INFO *altered_table_kc_info; KEY_AND_COL_INFO altered_table_kc_info_base; @@ -138,12 +156,13 @@ void ha_tokudb::print_alter_info(TABLE *altered_table, Alter_inplace_info *ha_al // Given two tables with equal number of fields, find all of the fields with different types // and return the indexes of the different fields in the changed_fields array. This function ignores field // name differences. -static int find_changed_fields(TABLE *table_a, TABLE *table_b, Dynamic_array &changed_fields) { +static int find_changed_fields(TABLE *table_a, TABLE *table_b, tokudb_vector &changed_fields) { for (uint i = 0; i < table_a->s->fields; i++) { Field *field_a = table_a->field[i]; Field *field_b = table_b->field[i]; - if (!fields_are_same_type(field_a, field_b)) + if (!fields_are_same_type(field_a, field_b)) { changed_fields.append(i); + } } return changed_fields.elements(); } @@ -386,7 +405,9 @@ enum_alter_inplace_result ha_tokudb::check_if_supported_inplace_alter(TABLE *alt if (result != HA_ALTER_INPLACE_NOT_SUPPORTED && table->s->null_bytes != altered_table->s->null_bytes && (tokudb_debug & TOKUDB_DEBUG_ALTER_TABLE)) { +#if MYSQL_VERSION_ID < 50700 TOKUDB_HANDLER_TRACE("q %s", thd->query()); +#endif TOKUDB_HANDLER_TRACE("null bytes %u -> %u", table->s->null_bytes, altered_table->s->null_bytes); } @@ -857,7 +878,7 @@ static bool change_length_is_supported(TABLE *table, TABLE *altered_table, Alter return false; if (ctx->changed_fields.elements() > 1) return false; // only support one field change - for (DYNAMIC_ARRAY_ELEMENTS_TYPE ai = 0; ai < ctx->changed_fields.elements(); ai++) { + for (uint ai = 0; ai < ctx->changed_fields.elements(); ai++) { uint i = ctx->changed_fields.at(ai); Field *old_field = table->field[i]; Field *new_field = altered_table->field[i]; @@ -875,11 +896,11 @@ static bool change_length_is_supported(TABLE *table, TABLE *altered_table, Alter } // Debug function that ensures that the array is sorted -static bool is_sorted(Dynamic_array &a) { +static bool is_sorted(tokudb_vector &a) { bool r = true; if (a.elements() > 0) { uint lastelement = a.at(0); - for (DYNAMIC_ARRAY_ELEMENTS_TYPE i = 1; i < a.elements(); i++) + for (uint i = 1; i < a.elements(); i++) if (lastelement > a.at(i)) r = false; } @@ -890,7 +911,7 @@ int ha_tokudb::alter_table_expand_columns(TABLE *altered_table, Alter_inplace_in int error = 0; tokudb_alter_ctx *ctx = static_cast(ha_alter_info->handler_ctx); assert(is_sorted(ctx->changed_fields)); // since we build the changed_fields array in field order, it must be sorted - for (DYNAMIC_ARRAY_ELEMENTS_TYPE ai = 0; error == 0 && ai < ctx->changed_fields.elements(); ai++) { + for (uint ai = 0; error == 0 && ai < ctx->changed_fields.elements(); ai++) { uint expand_field_num = ctx->changed_fields.at(ai); error = alter_table_expand_one_column(altered_table, ha_alter_info, expand_field_num); } @@ -1148,7 +1169,7 @@ static bool change_type_is_supported(TABLE *table, TABLE *altered_table, Alter_i return false; if (ctx->changed_fields.elements() > 1) return false; // only support one field change - for (DYNAMIC_ARRAY_ELEMENTS_TYPE ai = 0; ai < ctx->changed_fields.elements(); ai++) { + for (uint ai = 0; ai < ctx->changed_fields.elements(); ai++) { uint i = ctx->changed_fields.at(ai); Field *old_field = table->field[i]; Field *new_field = altered_table->field[i]; diff --git a/storage/tokudb/hatoku_cmp.cc b/storage/tokudb/hatoku_cmp.cc index 9892c6f5..82133761 100644 --- a/storage/tokudb/hatoku_cmp.cc +++ b/storage/tokudb/hatoku_cmp.cc @@ -67,6 +67,7 @@ static bool field_valid_for_tokudb_table(Field* field) { case MYSQL_TYPE_MEDIUM_BLOB: case MYSQL_TYPE_BLOB: case MYSQL_TYPE_LONG_BLOB: + case MYSQL_TYPE_JSON: ret_val = true; goto exit; // @@ -232,6 +233,7 @@ static TOKU_TYPE mysql_to_toku_type (Field* field) { case MYSQL_TYPE_MEDIUM_BLOB: case MYSQL_TYPE_BLOB: case MYSQL_TYPE_LONG_BLOB: + case MYSQL_TYPE_JSON: ret_val = toku_type_blob; goto exit; // @@ -464,8 +466,13 @@ static inline int cmp_toku_double(uchar* a_buf, uchar* b_buf) { int ret_val; double a_num; double b_num; +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + doubleget(&a_num, a_buf); + doubleget(&b_num, b_buf); +#else doubleget(a_num, a_buf); doubleget(b_num, b_buf); +#endif if (a_num < b_num) { ret_val = -1; goto exit; @@ -3182,6 +3189,7 @@ static bool fields_are_same_type(Field* a, Field* b) { case MYSQL_TYPE_MEDIUM_BLOB: case MYSQL_TYPE_BLOB: case MYSQL_TYPE_LONG_BLOB: + case MYSQL_TYPE_JSON: // test the charset if (a->charset()->number != b->charset()->number) { retval = false; diff --git a/storage/tokudb/hatoku_defines.h b/storage/tokudb/hatoku_defines.h index 225d1106..56a826e5 100644 --- a/storage/tokudb/hatoku_defines.h +++ b/storage/tokudb/hatoku_defines.h @@ -56,6 +56,7 @@ Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. #define TOKU_INCLUDE_ALTER_56 1 #define TOKU_INCLUDE_ROW_TYPE_COMPRESSION 0 #define TOKU_PARTITION_WRITE_FRM_DATA 0 +#define TOKU_INCLUDE_XA 1 #else #error #endif @@ -429,43 +430,87 @@ static inline void* tokudb_my_multi_malloc(myf myFlags, ...) { return start; } -static inline void tokudb_pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) { +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 +#include +#include +typedef native_mutex_t tokudb_mutex_t; +typedef native_mutexattr_t tokudb_mutexattr_t; +typedef native_cond_t tokudb_cond_t; +#else +typedef pthread_mutex_t tokudb_mutex_t; +typedef pthread_mutexattr_t tokudb_mutexattr_t; +typedef pthread_cond_t tokudb_cond_t; +#endif + +static inline void tokudb_mutex_init(tokudb_mutex_t *mutex, const tokudb_mutexattr_t *attr) { +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + int r = native_mutex_init(mutex, attr); +#else int r = pthread_mutex_init(mutex, attr); +#endif assert(r == 0); } -static inline void tokudb_pthread_mutex_destroy(pthread_mutex_t *mutex) { +static inline void tokudb_mutex_destroy(tokudb_mutex_t *mutex) { +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + int r = native_mutex_destroy(mutex); +#else int r = pthread_mutex_destroy(mutex); +#endif assert(r == 0); } -static inline void tokudb_pthread_mutex_lock(pthread_mutex_t *mutex) { +static inline void tokudb_mutex_lock(tokudb_mutex_t *mutex) { +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + int r = native_mutex_lock(mutex); +#else int r = pthread_mutex_lock(mutex); +#endif assert(r == 0); } -static inline void tokudb_pthread_mutex_unlock(pthread_mutex_t *mutex) { +static inline void tokudb_mutex_unlock(tokudb_mutex_t *mutex) { +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + int r = native_mutex_unlock(mutex); +#else int r = pthread_mutex_unlock(mutex); +#endif assert(r == 0); } -static inline void tokudb_pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr) { - int r = pthread_cond_init(cond, attr); +static inline void tokudb_cond_init(tokudb_cond_t *cond) { +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + int r = native_cond_init(cond); +#else + int r = pthread_cond_init(cond, NULL); +#endif assert(r == 0); } -static inline void tokudb_pthread_cond_destroy(pthread_cond_t *cond) { +static inline void tokudb_cond_destroy(tokudb_cond_t *cond) { +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + int r = native_cond_destroy(cond); +#else int r = pthread_cond_destroy(cond); +#endif assert(r == 0); } -static inline void tokudb_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) { +static inline void tokudb_cond_wait(tokudb_cond_t *cond, tokudb_mutex_t *mutex) { +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + int r = native_cond_wait(cond, mutex); +#else int r = pthread_cond_wait(cond, mutex); +#endif assert(r == 0); } -static inline void tokudb_pthread_cond_broadcast(pthread_cond_t *cond) { +static inline void tokudb_cond_broadcast(tokudb_cond_t *cond) { +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + int r = native_cond_broadcast(cond); +#else int r = pthread_cond_broadcast(cond); +#endif assert(r == 0); } @@ -483,4 +528,56 @@ static uint tokudb_uint3korr(const uchar *a) { return uint3korr(b); } +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 +#include +typedef native_rw_lock_t tokudb_rw_lock_t; +#else +typedef rw_lock_t tokudb_rw_lock_t; +#endif + +static inline void tokudb_rw_init(tokudb_rw_lock_t *rwlock) { +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + int r = native_rw_init(rwlock); +#else + int r = my_rwlock_init(rwlock, 0); +#endif + assert(r == 0); +} + +static inline void tokudb_rw_destroy(tokudb_rw_lock_t *rwlock) { +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + int r = native_rw_destroy(rwlock); +#else + int r = rwlock_destroy(rwlock); +#endif + assert(r == 0); +} + +static inline void tokudb_rw_rdlock(tokudb_rw_lock_t *rwlock) { +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + int r = native_rw_rdlock(rwlock); +#else + int r = rw_rdlock(rwlock); +#endif + assert(r == 0); +} + +static inline void tokudb_rw_unlock(tokudb_rw_lock_t *rwlock) { +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + int r = native_rw_unlock(rwlock); +#else + int r = rw_unlock(rwlock); +#endif + assert(r == 0); +} + +static inline void tokudb_rw_wrlock(tokudb_rw_lock_t *rwlock) { +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + int r = native_rw_wrlock(rwlock); +#else + int r = rw_wrlock(rwlock); +#endif + assert(r == 0); +} + #endif // _TOKUDB_PORTABILITY_H diff --git a/storage/tokudb/hatoku_hton.cc b/storage/tokudb/hatoku_hton.cc index c193afd3..4e26ab4c 100644 --- a/storage/tokudb/hatoku_hton.cc +++ b/storage/tokudb/hatoku_hton.cc @@ -85,7 +85,11 @@ static handler *tokudb_create_handler(handlerton * hton, TABLE_SHARE * table, ME static void tokudb_print_error(const DB_ENV * db_env, const char *db_errpfx, const char *buffer); static void tokudb_cleanup_log_files(void); static int tokudb_end(handlerton * hton, ha_panic_function type); +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 +static bool tokudb_flush_logs(handlerton * hton, bool binlog_group_commit); +#else static bool tokudb_flush_logs(handlerton * hton); +#endif static bool tokudb_show_status(handlerton * hton, THD * thd, stat_print_fn * print, enum ha_stat_type); #if TOKU_INCLUDE_HANDLERTON_HANDLE_FATAL_SIGNAL static void tokudb_handle_fatal_signal(handlerton *hton, THD *thd, int sig); @@ -117,10 +121,11 @@ char *tokudb_data_dir; ulong tokudb_debug; DB_ENV *db_env; HASH tokudb_open_tables; -pthread_mutex_t tokudb_mutex; +tokudb_mutex_t tokudb_mutex; #if TOKU_THDVAR_MEMALLOC_BUG -static pthread_mutex_t tokudb_map_mutex; +#include +static tokudb_mutex_t tokudb_map_mutex; static TREE tokudb_map; struct tokudb_map_pair { THD *thd; @@ -222,16 +227,16 @@ extern "C" { // use constructor and destructor functions to create and destroy // the lock before and after main(), respectively. static int tokudb_hton_initialized; -static rw_lock_t tokudb_hton_initialized_lock; +static tokudb_rw_lock_t tokudb_hton_initialized_lock; static void create_tokudb_hton_intialized_lock(void) __attribute__((constructor)); static void create_tokudb_hton_intialized_lock(void) { - my_rwlock_init(&tokudb_hton_initialized_lock, 0); + tokudb_rw_init(&tokudb_hton_initialized_lock); } static void destroy_tokudb_hton_initialized_lock(void) __attribute__((destructor)); static void destroy_tokudb_hton_initialized_lock(void) { - rwlock_destroy(&tokudb_hton_initialized_lock); + tokudb_rw_destroy(&tokudb_hton_initialized_lock); } static SHOW_VAR *toku_global_status_variables = NULL; @@ -279,13 +284,16 @@ static int tokudb_set_product_name(void) { return r; } +#if TOKUDB_CHECK_JEMALLOC +#include +#endif + static int tokudb_init_func(void *p) { TOKUDB_DBUG_ENTER("%p", p); int r; // 3938: lock the handlerton's initialized status flag for writing - r = rw_wrlock(&tokudb_hton_initialized_lock); - assert(r == 0); + tokudb_rw_wrlock(&tokudb_hton_initialized_lock); db_env = NULL; tokudb_hton = (handlerton *) p; @@ -303,8 +311,12 @@ static int tokudb_init_func(void *p) { goto error; } - tokudb_pthread_mutex_init(&tokudb_mutex, MY_MUTEX_INIT_FAST); + tokudb_mutex_init(&tokudb_mutex, MY_MUTEX_INIT_FAST); +#if 50708 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + (void) my_hash_init(&tokudb_open_tables, table_alias_charset, 32, 0, 0, (my_hash_get_key) tokudb_get_key, 0, 0, 0); +#else (void) my_hash_init(&tokudb_open_tables, table_alias_charset, 32, 0, 0, (my_hash_get_key) tokudb_get_key, 0, 0); +#endif tokudb_hton->state = SHOW_OPTION_YES; // tokudb_hton->flags= HTON_CAN_RECREATE; // QQQ this came from skeleton @@ -509,13 +521,13 @@ static int tokudb_init_func(void *p) { tokudb_primary_key_bytes_inserted = create_partitioned_counter(); #if TOKU_THDVAR_MEMALLOC_BUG - tokudb_pthread_mutex_init(&tokudb_map_mutex, MY_MUTEX_INIT_FAST); + tokudb_mutex_init(&tokudb_map_mutex, MY_MUTEX_INIT_FAST); init_tree(&tokudb_map, 0, 0, 0, tokudb_map_pair_cmp, true, NULL, NULL); #endif //3938: succeeded, set the init status flag and unlock tokudb_hton_initialized = 1; - rw_unlock(&tokudb_hton_initialized_lock); + tokudb_rw_unlock(&tokudb_hton_initialized_lock); DBUG_RETURN(false); error: @@ -527,7 +539,7 @@ static int tokudb_init_func(void *p) { // 3938: failed to initialized, drop the flag and lock tokudb_hton_initialized = 0; - rw_unlock(&tokudb_hton_initialized_lock); + tokudb_rw_unlock(&tokudb_hton_initialized_lock); DBUG_RETURN(true); } @@ -538,7 +550,7 @@ static int tokudb_done_func(void *p) { tokudb_my_free(toku_global_status_rows); toku_global_status_rows = NULL; my_hash_free(&tokudb_open_tables); - tokudb_pthread_mutex_destroy(&tokudb_mutex); + tokudb_mutex_destroy(&tokudb_mutex); TOKUDB_DBUG_RETURN(0); } @@ -554,7 +566,7 @@ int tokudb_end(handlerton * hton, ha_panic_function type) { // initialized. grab a writer lock for the duration of the // call, so we can drop the flag and destroy the mutexes // in isolation. - rw_wrlock(&tokudb_hton_initialized_lock); + tokudb_rw_wrlock(&tokudb_hton_initialized_lock); assert(tokudb_hton_initialized); if (db_env) { @@ -598,13 +610,13 @@ int tokudb_end(handlerton * hton, ha_panic_function type) { } #if TOKU_THDVAR_MEMALLOC_BUG - tokudb_pthread_mutex_destroy(&tokudb_map_mutex); + tokudb_mutex_destroy(&tokudb_map_mutex); delete_tree(&tokudb_map); #endif // 3938: drop the initialized flag and unlock tokudb_hton_initialized = 0; - rw_unlock(&tokudb_hton_initialized_lock); + tokudb_rw_unlock(&tokudb_hton_initialized_lock); TOKUDB_DBUG_RETURN(error); } @@ -617,19 +629,23 @@ static int tokudb_close_connection(handlerton * hton, THD * thd) { } tokudb_my_free(trx); #if TOKU_THDVAR_MEMALLOC_BUG - tokudb_pthread_mutex_lock(&tokudb_map_mutex); + tokudb_mutex_lock(&tokudb_map_mutex); struct tokudb_map_pair key = { thd, NULL }; struct tokudb_map_pair *found_key = (struct tokudb_map_pair *) tree_search(&tokudb_map, &key, NULL); if (found_key) { tokudb_my_free(found_key->last_lock_timeout); tree_delete(&tokudb_map, found_key, sizeof *found_key, NULL); } - tokudb_pthread_mutex_unlock(&tokudb_map_mutex); + tokudb_mutex_unlock(&tokudb_map_mutex); #endif return error; } -bool tokudb_flush_logs(handlerton * hton) { +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 +static bool tokudb_flush_logs(handlerton *hton, bool binlog_group_commit) { +#else +static bool tokudb_flush_logs(handlerton *hton) { +#endif TOKUDB_DBUG_ENTER(""); int error; bool result = 0; @@ -1528,7 +1544,7 @@ static int tokudb_file_map_fill_table(THD *thd, TABLE_LIST *tables, COND *cond) int error; TABLE *table = tables->table; - rw_rdlock(&tokudb_hton_initialized_lock); + tokudb_rw_rdlock(&tokudb_hton_initialized_lock); if (!tokudb_hton_initialized) { error = ER_PLUGIN_IS_NOT_LOADED; @@ -1539,7 +1555,7 @@ static int tokudb_file_map_fill_table(THD *thd, TABLE_LIST *tables, COND *cond) my_error(ER_GET_ERRNO, MYF(0), error, tokudb_hton_name); } - rw_unlock(&tokudb_hton_initialized_lock); + tokudb_rw_unlock(&tokudb_hton_initialized_lock); TOKUDB_DBUG_RETURN(error); } @@ -1678,7 +1694,7 @@ static int tokudb_fractal_tree_info_fill_table(THD *thd, TABLE_LIST *tables, CON // 3938: Get a read lock on the status flag, since we must // read it before safely proceeding - rw_rdlock(&tokudb_hton_initialized_lock); + tokudb_rw_rdlock(&tokudb_hton_initialized_lock); if (!tokudb_hton_initialized) { error = ER_PLUGIN_IS_NOT_LOADED; @@ -1690,7 +1706,7 @@ static int tokudb_fractal_tree_info_fill_table(THD *thd, TABLE_LIST *tables, CON } //3938: unlock the status flag lock - rw_unlock(&tokudb_hton_initialized_lock); + tokudb_rw_unlock(&tokudb_hton_initialized_lock); TOKUDB_DBUG_RETURN(error); } @@ -1893,7 +1909,7 @@ static int tokudb_fractal_tree_block_map_fill_table(THD *thd, TABLE_LIST *tables // 3938: Get a read lock on the status flag, since we must // read it before safely proceeding - rw_rdlock(&tokudb_hton_initialized_lock); + tokudb_rw_rdlock(&tokudb_hton_initialized_lock); if (!tokudb_hton_initialized) { error = ER_PLUGIN_IS_NOT_LOADED; @@ -1905,7 +1921,7 @@ static int tokudb_fractal_tree_block_map_fill_table(THD *thd, TABLE_LIST *tables } //3938: unlock the status flag lock - rw_unlock(&tokudb_hton_initialized_lock); + tokudb_rw_unlock(&tokudb_hton_initialized_lock); TOKUDB_DBUG_RETURN(error); } @@ -1998,7 +2014,11 @@ static void tokudb_lock_timeout_callback(DB *db, uint64_t requesting_txnid, cons // generate a JSON document with the lock timeout info String log_str; log_str.append("{"); +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + uint64_t mysql_thread_id = thd->thread_id(); +#else uint64_t mysql_thread_id = thd->thread_id; +#endif log_str.append("\"mysql_thread_id\":"); log_str.append_ulonglong(mysql_thread_id); log_str.append(", \"dbname\":"); @@ -2030,19 +2050,21 @@ static void tokudb_lock_timeout_callback(DB *db, uint64_t requesting_txnid, cons THDVAR(thd, last_lock_timeout) = new_lock_timeout; tokudb_my_free(old_lock_timeout); #if TOKU_THDVAR_MEMALLOC_BUG - tokudb_pthread_mutex_lock(&tokudb_map_mutex); + tokudb_mutex_lock(&tokudb_map_mutex); struct tokudb_map_pair old_key = { thd, old_lock_timeout }; tree_delete(&tokudb_map, &old_key, sizeof old_key, NULL); struct tokudb_map_pair new_key = { thd, new_lock_timeout }; tree_insert(&tokudb_map, &new_key, sizeof new_key, NULL); - tokudb_pthread_mutex_unlock(&tokudb_map_mutex); + tokudb_mutex_unlock(&tokudb_map_mutex); #endif } // dump to stderr if (lock_timeout_debug & 2) { sql_print_error("%s: lock timeout %s", tokudb_hton_name, log_str.c_ptr()); +#if !(50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799) LEX_STRING *qs = thd_query_string(thd); sql_print_error("%s: requesting_thread_id:%" PRIu64 " q:%.*s", tokudb_hton_name, mysql_thread_id, (int) qs->length, qs->str); +#endif #if TOKU_INCLUDE_LOCK_TIMEOUT_QUERY_STRING uint64_t blocking_thread_id = 0; if (tokudb_txn_id_to_client_id(thd, blocking_txnid, &blocking_thread_id)) { @@ -2095,7 +2117,7 @@ static int tokudb_trx_fill_table(THD *thd, TABLE_LIST *tables, COND *cond) { TOKUDB_DBUG_ENTER(""); int error; - rw_rdlock(&tokudb_hton_initialized_lock); + tokudb_rw_rdlock(&tokudb_hton_initialized_lock); if (!tokudb_hton_initialized) { error = ER_PLUGIN_IS_NOT_LOADED; @@ -2107,7 +2129,7 @@ static int tokudb_trx_fill_table(THD *thd, TABLE_LIST *tables, COND *cond) { my_error(ER_GET_ERRNO, MYF(0), error, tokudb_hton_name); } - rw_unlock(&tokudb_hton_initialized_lock); + tokudb_rw_unlock(&tokudb_hton_initialized_lock); TOKUDB_DBUG_RETURN(error); } @@ -2182,7 +2204,7 @@ static int tokudb_lock_waits_fill_table(THD *thd, TABLE_LIST *tables, COND *cond TOKUDB_DBUG_ENTER(""); int error; - rw_rdlock(&tokudb_hton_initialized_lock); + tokudb_rw_rdlock(&tokudb_hton_initialized_lock); if (!tokudb_hton_initialized) { error = ER_PLUGIN_IS_NOT_LOADED; @@ -2194,7 +2216,7 @@ static int tokudb_lock_waits_fill_table(THD *thd, TABLE_LIST *tables, COND *cond my_error(ER_GET_ERRNO, MYF(0), error, tokudb_hton_name); } - rw_unlock(&tokudb_hton_initialized_lock); + tokudb_rw_unlock(&tokudb_hton_initialized_lock); TOKUDB_DBUG_RETURN(error); } @@ -2275,7 +2297,7 @@ static int tokudb_locks_fill_table(THD *thd, TABLE_LIST *tables, COND *cond) { TOKUDB_DBUG_ENTER(""); int error; - rw_rdlock(&tokudb_hton_initialized_lock); + tokudb_rw_rdlock(&tokudb_hton_initialized_lock); if (!tokudb_hton_initialized) { error = ER_PLUGIN_IS_NOT_LOADED; @@ -2287,7 +2309,7 @@ static int tokudb_locks_fill_table(THD *thd, TABLE_LIST *tables, COND *cond) { my_error(ER_GET_ERRNO, MYF(0), error, tokudb_hton_name); } - rw_unlock(&tokudb_hton_initialized_lock); + tokudb_rw_unlock(&tokudb_hton_initialized_lock); TOKUDB_DBUG_RETURN(error); }