null+****@clear*****
null+****@clear*****
2012年 5月 7日 (月) 19:07:10 JST
Kouhei Sutou 2012-05-07 19:07:10 +0900 (Mon, 07 May 2012) New Revision: 7f3cbacb15d0b32adc040c7695bbc0c115f686c2 Log: Clean auto increment value lock code refs #1310 #1311 Added files: lib/mrn_auto_increment_value_lock.cpp lib/mrn_auto_increment_value_lock.hpp Modified files: ha_mroonga.cpp lib/libmrn_need_mysql_sources.am mrn_mysql_compat.h Modified: ha_mroonga.cpp (+3 -10) =================================================================== --- ha_mroonga.cpp 2012-05-07 18:40:49 +0900 (24cdea3) +++ ha_mroonga.cpp 2012-05-07 19:07:10 +0900 (6ab7b7f) @@ -46,6 +46,7 @@ #include <mrn_path_mapper.hpp> #include <mrn_index_table_name.hpp> #include <mrn_debug_column_access.hpp> +#include <mrn_auto_increment_value_lock.hpp> #define MRN_SHORT_TEXT_SIZE (1 << 12) // 4Kbytes #define MRN_TEXT_SIZE (1 << 16) // 64Kbytes @@ -57,8 +58,6 @@ extern mysql_mutex_t LOCK_open; # define mrn_open_mutex_unlock() mysql_mutex_unlock(&LOCK_open) #else extern pthread_mutex_t LOCK_open; -# define mysql_mutex_lock(mutex) pthread_mutex_lock(mutex) -# define mysql_mutex_unlock(mutex) pthread_mutex_unlock(mutex) # define mrn_open_mutex_lock() # define mrn_open_mutex_unlock() #endif @@ -3727,8 +3726,7 @@ void ha_mroonga::wrapper_set_keys_in_use() { uint i, j; MRN_DBUG_ENTER_METHOD(); - if (table_share->tmp_table == NO_TMP_TABLE) - mysql_mutex_lock(&table_share->LOCK_ha_data); + mrn::AutoIncrementValueLock lock_(table_share); table_share->keys_in_use.set_prefix(table_share->keys); for (i = 0; i < table_share->keys; i++) { j = share->wrap_key_nr[i]; @@ -3746,8 +3744,6 @@ void ha_mroonga::wrapper_set_keys_in_use() } table_share->keys_for_keyread.set_prefix(table_share->keys); table_share->keys_for_keyread.intersect(table_share->keys_in_use); - if (table_share->tmp_table == NO_TMP_TABLE) - mysql_mutex_unlock(&table_share->LOCK_ha_data); DBUG_VOID_RETURN; } @@ -3755,8 +3751,7 @@ void ha_mroonga::storage_set_keys_in_use() { uint i; MRN_DBUG_ENTER_METHOD(); - if (table_share->tmp_table == NO_TMP_TABLE) - mysql_mutex_lock(&table_share->LOCK_ha_data); + mrn::AutoIncrementValueLock lock_(table_share); table_share->keys_in_use.set_prefix(table_share->keys); for (i = 0; i < table_share->keys; i++) { if (i == table_share->primary_key) { @@ -3770,8 +3765,6 @@ void ha_mroonga::storage_set_keys_in_use() } table_share->keys_for_keyread.set_prefix(table_share->keys); table_share->keys_for_keyread.intersect(table_share->keys_in_use); - if (table_share->tmp_table == NO_TMP_TABLE) - mysql_mutex_unlock(&table_share->LOCK_ha_data); DBUG_VOID_RETURN; } Modified: lib/libmrn_need_mysql_sources.am (+3 -1) =================================================================== --- lib/libmrn_need_mysql_sources.am 2012-05-07 18:40:49 +0900 (126e524) +++ lib/libmrn_need_mysql_sources.am 2012-05-07 19:07:10 +0900 (8eaf981) @@ -2,4 +2,6 @@ libmrn_need_mysql_la_SOURCES = \ mrn_index_table_name.cpp \ mrn_index_table_name.hpp \ mrn_debug_column_access.cpp \ - mrn_debug_column_access.hpp + mrn_debug_column_access.hpp \ + mrn_auto_increment_value_lock.cpp \ + mrn_auto_increment_value_lock.hpp Added: lib/mrn_auto_increment_value_lock.cpp (+36 -0) 100644 =================================================================== --- /dev/null +++ lib/mrn_auto_increment_value_lock.cpp 2012-05-07 19:07:10 +0900 (0910eeb) @@ -0,0 +1,36 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2012 Kouhei Sutou <kou****@clear*****> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "mrn_auto_increment_value_lock.hpp" + +namespace mrn { + AutoIncrementValueLock::AutoIncrementValueLock(TABLE_SHARE *table_share) + : table_share_(table_share), + need_lock_(table_share_->tmp_table == NO_TMP_TABLE) { + if (need_lock_) { + mysql_mutex_lock(&table_share_->LOCK_ha_data); + } + } + + AutoIncrementValueLock::~AutoIncrementValueLock() { + if (need_lock_) { + mysql_mutex_unlock(&table_share_->LOCK_ha_data); + } + } +} Added: lib/mrn_auto_increment_value_lock.hpp (+36 -0) 100644 =================================================================== --- /dev/null +++ lib/mrn_auto_increment_value_lock.hpp 2012-05-07 19:07:10 +0900 (9bed700) @@ -0,0 +1,36 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2012 Kouhei Sutou <kou****@clear*****> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef MRN_AUTO_INCREMENT_VALUE_LOCK_HPP_ +#define MRN_AUTO_INCREMENT_VALUE_LOCK_HPP_ + +#include <mrn_mysql.h> +#include <mrn_mysql_compat.h> + +namespace mrn { + class AutoIncrementValueLock { + TABLE_SHARE *table_share_; + bool need_lock_; + public: + AutoIncrementValueLock(TABLE_SHARE *table_share); + ~AutoIncrementValueLock(); + }; +} + +#endif // MRN_AUTO_INCREMENT_VALUE_LOCK_HPP_ Modified: mrn_mysql_compat.h (+5 -0) =================================================================== --- mrn_mysql_compat.h 2012-05-07 18:40:49 +0900 (6f0eb14) +++ mrn_mysql_compat.h 2012-05-07 19:07:10 +0900 (ead0324) @@ -24,6 +24,11 @@ # define my_free(PTR, FLAG) my_free(PTR) #endif +#if MYSQL_VERSION_ID < 50500 +# define mysql_mutex_lock(mutex) pthread_mutex_lock(mutex) +# define mysql_mutex_unlock(mutex) pthread_mutex_unlock(mutex) +#endif + #ifndef HA_INPLACE_ADD_INDEX_NO_READ_WRITE # define HA_INPLACE_ADD_INDEX_NO_READ_WRITE HA_ONLINE_ADD_INDEX_NO_WRITES # define HA_INPLACE_DROP_INDEX_NO_READ_WRITE HA_ONLINE_DROP_INDEX_NO_WRITES