diff options
Diffstat (limited to 'storage/tokudb/ha_tokudb.cc')
-rw-r--r-- | storage/tokudb/ha_tokudb.cc | 139 |
1 files changed, 78 insertions, 61 deletions
diff --git a/storage/tokudb/ha_tokudb.cc b/storage/tokudb/ha_tokudb.cc index 56bebf1c3ec..cdd4adb0947 100644 --- a/storage/tokudb/ha_tokudb.cc +++ b/storage/tokudb/ha_tokudb.cc @@ -31,6 +31,8 @@ Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. #include "ha_tokudb.h" #include "sql_db.h" +pfs_key_t ha_tokudb_mutex_key; +pfs_key_t num_DBs_lock_key; #if TOKU_INCLUDE_EXTENDED_KEYS static inline uint get_ext_key_parts(const KEY *key) { @@ -187,13 +189,9 @@ const char* TOKUDB_SHARE::get_state_string(share_state_t state) { void* TOKUDB_SHARE::operator new(size_t sz) { return tokudb::memory::malloc(sz, MYF(MY_WME|MY_ZEROFILL|MY_FAE)); } -void TOKUDB_SHARE::operator delete(void* p) { - tokudb::memory::free(p); -} -TOKUDB_SHARE::TOKUDB_SHARE() : - _num_DBs_lock(), - _mutex() { -} +void TOKUDB_SHARE::operator delete(void* p) { tokudb::memory::free(p); } +TOKUDB_SHARE::TOKUDB_SHARE() + : _num_DBs_lock(num_DBs_lock_key), _mutex(ha_tokudb_mutex_key) {} void TOKUDB_SHARE::init(const char* table_name) { _use_count = 0; thr_lock_init(&_thr_lock); @@ -228,20 +226,15 @@ void TOKUDB_SHARE::destroy() { thr_lock_delete(&_thr_lock); TOKUDB_SHARE_DBUG_VOID_RETURN(); } -TOKUDB_SHARE* TOKUDB_SHARE::get_share( - const char* table_name, - TABLE_SHARE* table_share, - THR_LOCK_DATA* data, - bool create_new) { - - _open_tables_mutex.lock(); +TOKUDB_SHARE* TOKUDB_SHARE::get_share(const char* table_name, + TABLE_SHARE* table_share, + THR_LOCK_DATA* data, + bool create_new) { + mutex_t_lock(_open_tables_mutex); int error = 0; - uint length = (uint) strlen(table_name); - TOKUDB_SHARE* share = - (TOKUDB_SHARE*)my_hash_search( - &_open_tables, - (uchar*)table_name, - length); + uint length = (uint)strlen(table_name); + TOKUDB_SHARE* share = (TOKUDB_SHARE*)my_hash_search( + &_open_tables, (uchar*)table_name, length); TOKUDB_TRACE_FOR_FLAGS( TOKUDB_DEBUG_SHARE, @@ -276,28 +269,27 @@ TOKUDB_SHARE* TOKUDB_SHARE::get_share( thr_lock_data_init(&(share->_thr_lock), data, NULL); exit: - _open_tables_mutex.unlock(); + mutex_t_unlock(_open_tables_mutex); return share; } void TOKUDB_SHARE::drop_share(TOKUDB_SHARE* share) { - TOKUDB_TRACE_FOR_FLAGS( - TOKUDB_DEBUG_SHARE, - "share[%p]:file[%s]:state[%s]:use_count[%d]", - share, - share->_full_table_name.ptr(), - get_state_string(share->_state), - share->_use_count); - - _open_tables_mutex.lock(); + TOKUDB_TRACE_FOR_FLAGS(TOKUDB_DEBUG_SHARE, + "share[%p]:file[%s]:state[%s]:use_count[%d]", + share, + share->_full_table_name.ptr(), + get_state_string(share->_state), + share->_use_count); + + mutex_t_lock(_open_tables_mutex); my_hash_delete(&_open_tables, (uchar*)share); - _open_tables_mutex.unlock(); + mutex_t_unlock(_open_tables_mutex); } TOKUDB_SHARE::share_state_t TOKUDB_SHARE::addref() { TOKUDB_SHARE_TRACE_FOR_FLAGS((TOKUDB_DEBUG_ENTER & TOKUDB_DEBUG_SHARE), - "file[%s]:state[%s]:use_count[%d]", - _full_table_name.ptr(), - get_state_string(_state), - _use_count); + "file[%s]:state[%s]:use_count[%d]", + _full_table_name.ptr(), + get_state_string(_state), + _use_count); lock(); _use_count++; @@ -312,7 +304,7 @@ int TOKUDB_SHARE::release() { int error, result = 0; - _mutex.lock(); + mutex_t_lock(_mutex); assert_always(_use_count != 0); _use_count--; if (_use_count == 0 && _state == TOKUDB_SHARE::OPENED) { @@ -356,7 +348,7 @@ int TOKUDB_SHARE::release() { _state = TOKUDB_SHARE::CLOSED; } - _mutex.unlock(); + mutex_t_unlock(_mutex); TOKUDB_SHARE_DBUG_RETURN(result); } @@ -1195,8 +1187,10 @@ static int generate_row_for_put( ha_tokudb::ha_tokudb(handlerton * hton, TABLE_SHARE * table_arg):handler(hton, table_arg) { TOKUDB_HANDLER_DBUG_ENTER(""); share = NULL; - int_table_flags = HA_REC_NOT_IN_SEQ | HA_NULL_IN_KEY | HA_CAN_INDEX_BLOBS | HA_PRIMARY_KEY_IN_READ_INDEX | HA_PRIMARY_KEY_REQUIRED_FOR_POSITION | - HA_FILE_BASED | HA_AUTO_PART_KEY | HA_TABLE_SCAN_ON_INDEX | HA_CAN_WRITE_DURING_OPTIMIZE; + int_table_flags = HA_REC_NOT_IN_SEQ | HA_NULL_IN_KEY | HA_CAN_INDEX_BLOBS + | HA_PRIMARY_KEY_IN_READ_INDEX | HA_PRIMARY_KEY_REQUIRED_FOR_POSITION + | HA_FILE_BASED | HA_AUTO_PART_KEY | HA_TABLE_SCAN_ON_INDEX + | HA_CAN_WRITE_DURING_OPTIMIZE | HA_ONLINE_ANALYZE; alloc_ptr = NULL; rec_buff = NULL; rec_update_buff = NULL; @@ -3313,12 +3307,12 @@ void ha_tokudb::start_bulk_insert(ha_rows rows) { delay_updating_ai_metadata = true; ai_metadata_update_required = false; abort_loader = false; - - share->_num_DBs_lock.lock_read(); + + rwlock_t_lock_read(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; - + if ((rows == 0 || rows > 1) && share->try_table_lock) { if (tokudb::sysvars::prelock_empty(thd) && may_table_be_empty(transaction) && @@ -4030,14 +4024,13 @@ int ha_tokudb::write_row(uchar * record) { // grab reader lock on numDBs_lock // if (!num_DBs_locked_in_bulk) { - share->_num_DBs_lock.lock_read(); + rwlock_t_lock_read(share->_num_DBs_lock); num_DBs_locked = true; - } - else { + } else { lock_count++; if (lock_count >= 2000) { share->_num_DBs_lock.unlock(); - share->_num_DBs_lock.lock_read(); + rwlock_t_lock_read(share->_num_DBs_lock); lock_count = 0; } } @@ -4208,7 +4201,7 @@ int ha_tokudb::update_row(const uchar * old_row, uchar * new_row) { // bool num_DBs_locked = false; if (!num_DBs_locked_in_bulk) { - share->_num_DBs_lock.lock_read(); + rwlock_t_lock_read(share->_num_DBs_lock); num_DBs_locked = true; } curr_num_DBs = share->num_DBs; @@ -4350,7 +4343,7 @@ int ha_tokudb::delete_row(const uchar * record) { // bool num_DBs_locked = false; if (!num_DBs_locked_in_bulk) { - share->_num_DBs_lock.lock_read(); + rwlock_t_lock_read(share->_num_DBs_lock); num_DBs_locked = true; } curr_num_DBs = share->num_DBs; @@ -4641,6 +4634,9 @@ int ha_tokudb::index_init(uint keynr, bool sorted) { if (tokudb::sysvars::disable_prefetching(thd)) { cursor_flags |= DBC_DISABLE_PREFETCHING; } + if (lock.type == TL_READ_WITH_SHARED_LOCKS) { + cursor_flags |= DB_LOCKING_READ; + } if ((error = share->key_file[keynr]->cursor(share->key_file[keynr], transaction, &cursor, cursor_flags))) { @@ -6212,6 +6208,8 @@ int ha_tokudb::info(uint flag) { } if ((flag & HA_STATUS_CONST)) { stats.max_data_file_length = 9223372036854775807ULL; + } + if (flag & (HA_STATUS_VARIABLE | HA_STATUS_CONST)) { share->set_cardinality_counts_in_table(table); } @@ -6295,7 +6293,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) { - share->_num_DBs_lock.lock_read(); + rwlock_t_lock_read(share->_num_DBs_lock); } uint curr_num_DBs = share->num_DBs; if (lt == lock_read) { @@ -6651,8 +6649,9 @@ THR_LOCK_DATA* *ha_tokudb::store_lock( if (sql_command == SQLCOM_CREATE_INDEX && tokudb::sysvars::create_index_online(thd)) { // hot indexing - share->_num_DBs_lock.lock_read(); - if (share->num_DBs == (table->s->keys + tokudb_test(hidden_primary_key))) { + rwlock_t_lock_read(share->_num_DBs_lock); + if (share->num_DBs == + (table->s->keys + tokudb_test(hidden_primary_key))) { lock_type = TL_WRITE_ALLOW_WRITE; } share->_num_DBs_lock.unlock(); @@ -7225,10 +7224,28 @@ int ha_tokudb::create( const tokudb::sysvars::row_format_t row_format = (tokudb::sysvars::row_format_t)form->s->option_struct->row_format; #else - const tokudb::sysvars::row_format_t row_format = - (create_info->used_fields & HA_CREATE_USED_ROW_FORMAT) - ? row_type_to_row_format(create_info->row_type) - : tokudb::sysvars::row_format(thd); + // TDB-76 : CREATE TABLE ... LIKE ... does not use source row_format on + // target table + // Original code would only use create_info->row_type if + // create_info->used_fields & HA_CREATE_USED_ROW_FORMAT was true. This + // would cause us to skip transferring the row_format for a table created + // via CREATE TABLE tn LIKE tn. We also take on more InnoDB like behavior + // and throw a warning if we get a row_format that we can't translate into + // a known TokuDB row_format. + tokudb::sysvars::row_format_t row_format = + tokudb::sysvars::row_format(thd); + + if ((create_info->used_fields & HA_CREATE_USED_ROW_FORMAT) || + create_info->row_type != ROW_TYPE_DEFAULT) { + row_format = row_type_to_row_format(create_info->row_type); + if (row_format == tokudb::sysvars::SRV_ROW_FORMAT_DEFAULT && + create_info->row_type != ROW_TYPE_DEFAULT) { + push_warning(thd, + Sql_condition::WARN_LEVEL_WARN, + ER_ILLEGAL_HA_CREATE_OPTION, + "TokuDB: invalid ROW_FORMAT specifier."); + } + } #endif const toku_compression_method compression_method = row_format_to_toku_compression_method(row_format); @@ -8112,8 +8129,8 @@ int ha_tokudb::tokudb_add_index( } } } - - share->_num_DBs_lock.lock_write(); + + rwlock_t_lock_write(share->_num_DBs_lock); rw_lock_taken = true; // // open all the DB files and set the appropriate variables in share @@ -8223,7 +8240,7 @@ int ha_tokudb::tokudb_add_index( goto cleanup; } - share->_num_DBs_lock.lock_write(); + rwlock_t_lock_write(share->_num_DBs_lock); error = indexer->close(indexer); share->_num_DBs_lock.unlock(); if (error) { @@ -8457,7 +8474,7 @@ cleanup: if (indexer != NULL) { sprintf(status_msg, "aborting creation of indexes."); thd_proc_info(thd, status_msg); - share->_num_DBs_lock.lock_write(); + rwlock_t_lock_write(share->_num_DBs_lock); indexer->abort(indexer); share->_num_DBs_lock.unlock(); } @@ -8506,10 +8523,10 @@ void ha_tokudb::restore_add_index( // // need to restore num_DBs, and we have to do it before we close the dictionaries - // so that there is not a window + // so that there is not a window // if (incremented_numDBs) { - share->_num_DBs_lock.lock_write(); + rwlock_t_lock_write(share->_num_DBs_lock); share->num_DBs--; } if (modified_DBs) { |