1 diff --git a/ha_mroonga.cpp b/ha_mroonga.cpp
2 index 20d251a..2504599 100644
6 #define MRN_TEXT_SIZE (1 << 16) // 64Kbytes
7 #define MRN_LONG_TEXT_SIZE (1 << 31) // 2Gbytes
9 -#if MYSQL_VERSION_ID >= 50500
12 +#ifdef MRN_HAVE_TDC_LOCK_TABLE_SHARE
13 +# define mrn_open_mutex(share) &((share)->tdc.LOCK_table_share)
14 +# define mrn_open_mutex_lock(share) do { \
15 + TABLE_SHARE *share_ = share; \
17 + mysql_mutex_lock(mrn_open_mutex(share_)); \
20 +# define mrn_open_mutex_unlock(share) do { \
21 + TABLE_SHARE *share_ = share; \
23 + mysql_mutex_unlock(mrn_open_mutex(share_)); \
27 +# if MYSQL_VERSION_ID >= 50500
30 extern mysql_mutex_t LOCK_open;
34 mysql_mutex_t *mrn_LOCK_open;
35 -# define mrn_open_mutex_lock() mysql_mutex_lock(mrn_LOCK_open)
36 -# define mrn_open_mutex_unlock() mysql_mutex_unlock(mrn_LOCK_open)
39 +# define mrn_open_mutex_lock(share) mysql_mutex_lock(mrn_LOCK_open)
40 +# define mrn_open_mutex_unlock(share) mysql_mutex_unlock(mrn_LOCK_open)
43 extern pthread_mutex_t LOCK_open;
46 pthread_mutex_t *mrn_LOCK_open;
47 -# define mrn_open_mutex_lock()
48 -# define mrn_open_mutex_unlock()
49 +# define mrn_open_mutex_lock(share)
50 +# define mrn_open_mutex_unlock(share)
54 #if MYSQL_VERSION_ID >= 50600
55 @@ -1275,13 +1291,15 @@ static int mrn_init(void *p)
56 mrn_table_def_cache = (HASH *)GetProcAddress(current_module,
57 "?table_def_cache@@3Ust_hash@@A");
59 +# ifndef MRN_HAVE_TDC_LOCK_TABLE_SHARE
61 -# if MYSQL_VERSION_ID >= 50500
62 +# if MYSQL_VERSION_ID >= 50500
63 (mysql_mutex_t *)GetProcAddress(current_module,
64 "?LOCK_open@@3Ust_mysql_mutex@@A");
67 (pthread_mutex_t *)GetProcAddress(current_module,
68 "?LOCK_open@@3U_RTL_CRITICAL_SECTION@@A");
71 # ifdef MRN_TABLE_SHARE_HAVE_LOCK_SHARE
72 mrn_table_share_lock_share =
73 @@ -1297,7 +1315,9 @@ static int mrn_init(void *p)
74 # ifdef MRN_HAVE_TABLE_DEF_CACHE
75 mrn_table_def_cache = &table_def_cache;
77 +# ifndef MRN_HAVE_TDC_LOCK_TABLE_SHARE
78 mrn_LOCK_open = &LOCK_open;
83 @@ -3033,10 +3053,10 @@ bool ha_mroonga::storage_create_foreign_key(TABLE *table,
84 mapper.mysql_table_name(),
87 - mrn_open_mutex_lock();
88 + mrn_open_mutex_lock(table->s);
90 mrn_create_tmp_table_share(&table_list, ref_path, &error);
91 - mrn_open_mutex_unlock();
92 + mrn_open_mutex_unlock(table->s);
93 if (!tmp_ref_table_share) {
94 grn_obj_unlink(ctx, grn_table_ref);
95 error = ER_CANT_CREATE_TABLE;
96 @@ -3048,9 +3068,9 @@ bool ha_mroonga::storage_create_foreign_key(TABLE *table,
98 uint ref_pkey_nr = tmp_ref_table_share->primary_key;
99 if (ref_pkey_nr == MAX_KEY) {
100 - mrn_open_mutex_lock();
101 + mrn_open_mutex_lock(table->s);
102 mrn_free_tmp_table_share(tmp_ref_table_share);
103 - mrn_open_mutex_unlock();
104 + mrn_open_mutex_unlock(table->s);
105 grn_obj_unlink(ctx, grn_table_ref);
106 error = ER_CANT_CREATE_TABLE;
107 char err_msg[MRN_BUFFER_SIZE];
108 @@ -3062,9 +3082,9 @@ bool ha_mroonga::storage_create_foreign_key(TABLE *table,
109 KEY *ref_key_info = &tmp_ref_table_share->key_info[ref_pkey_nr];
110 uint ref_key_parts = KEY_N_KEY_PARTS(ref_key_info);
111 if (ref_key_parts > 1) {
112 - mrn_open_mutex_lock();
113 + mrn_open_mutex_lock(table->s);
114 mrn_free_tmp_table_share(tmp_ref_table_share);
115 - mrn_open_mutex_unlock();
116 + mrn_open_mutex_unlock(table->s);
117 grn_obj_unlink(ctx, grn_table_ref);
118 error = ER_CANT_CREATE_TABLE;
119 char err_msg[MRN_BUFFER_SIZE];
120 @@ -3076,9 +3096,9 @@ bool ha_mroonga::storage_create_foreign_key(TABLE *table,
122 Field *ref_field = &ref_key_info->key_part->field[0];
123 if (strcmp(ref_field->field_name, ref_field_name.str)) {
124 - mrn_open_mutex_lock();
125 + mrn_open_mutex_lock(table->s);
126 mrn_free_tmp_table_share(tmp_ref_table_share);
127 - mrn_open_mutex_unlock();
128 + mrn_open_mutex_unlock(table->s);
129 grn_obj_unlink(ctx, grn_table_ref);
130 error = ER_CANT_CREATE_TABLE;
131 char err_msg[MRN_BUFFER_SIZE];
132 @@ -3088,9 +3108,9 @@ bool ha_mroonga::storage_create_foreign_key(TABLE *table,
133 my_message(error, err_msg, MYF(0));
136 - mrn_open_mutex_lock();
137 + mrn_open_mutex_lock(table->s);
138 mrn_free_tmp_table_share(tmp_ref_table_share);
139 - mrn_open_mutex_unlock();
140 + mrn_open_mutex_unlock(table->s);
141 grn_obj_flags col_flags = GRN_OBJ_PERSISTENT;
142 column = grn_column_create(ctx, table_obj, field->field_name,
143 strlen(field->field_name),
144 @@ -4210,18 +4230,18 @@ int ha_mroonga::close()
145 table_list.init_one_table(mapper.db_name(), mapper.mysql_table_name(),
148 - mrn_open_mutex_lock();
149 + mrn_open_mutex_lock(NULL);
151 mrn_create_tmp_table_share(&table_list, share->table_name, &tmp_error);
152 - mrn_open_mutex_unlock();
153 + mrn_open_mutex_unlock(NULL);
154 if (!tmp_table_share) {
156 } else if ((tmp_error = alter_share_add(share->table_name,
159 - mrn_open_mutex_lock();
160 + mrn_open_mutex_lock(NULL);
161 mrn_free_tmp_table_share(tmp_table_share);
162 - mrn_open_mutex_unlock();
163 + mrn_open_mutex_unlock(NULL);
166 bitmap_free(&multiple_column_key_bitmap);
167 @@ -4394,9 +4414,9 @@ int ha_mroonga::delete_table(const char *name)
168 table_list.init_one_table(mapper.db_name(), mapper.mysql_table_name(),
171 - mrn_open_mutex_lock();
172 + mrn_open_mutex_lock(NULL);
173 tmp_table_share = mrn_create_tmp_table_share(&table_list, name, &error);
174 - mrn_open_mutex_unlock();
175 + mrn_open_mutex_unlock(NULL);
176 if (!tmp_table_share) {
179 @@ -4407,9 +4427,9 @@ int ha_mroonga::delete_table(const char *name)
181 if (!(tmp_share = mrn_get_share(name, &tmp_table, &error)))
183 - mrn_open_mutex_lock();
184 + mrn_open_mutex_lock(NULL);
185 mrn_free_tmp_table_share(tmp_table_share);
186 - mrn_open_mutex_unlock();
187 + mrn_open_mutex_unlock(NULL);
191 @@ -4425,9 +4445,9 @@ int ha_mroonga::delete_table(const char *name)
192 tmp_share->long_term_share = NULL;
194 mrn_free_share(tmp_share);
195 - mrn_open_mutex_lock();
196 + mrn_open_mutex_lock(NULL);
197 mrn_free_tmp_table_share(tmp_table_share);
198 - mrn_open_mutex_unlock();
199 + mrn_open_mutex_unlock(NULL);
200 if (is_temporary_table_name(name)) {
203 @@ -11885,9 +11905,9 @@ int ha_mroonga::rename_table(const char *from, const char *to)
204 from_mapper.mysql_table_name(),
207 - mrn_open_mutex_lock();
208 + mrn_open_mutex_lock(NULL);
209 tmp_table_share = mrn_create_tmp_table_share(&table_list, from, &error);
210 - mrn_open_mutex_unlock();
211 + mrn_open_mutex_unlock(NULL);
212 if (!tmp_table_share) {
215 @@ -11897,9 +11917,9 @@ int ha_mroonga::rename_table(const char *from, const char *to)
217 if (!(tmp_share = mrn_get_share(from, &tmp_table, &error)))
219 - mrn_open_mutex_lock();
220 + mrn_open_mutex_lock(NULL);
221 mrn_free_tmp_table_share(tmp_table_share);
222 - mrn_open_mutex_unlock();
223 + mrn_open_mutex_unlock(NULL);
227 @@ -11925,9 +11945,9 @@ int ha_mroonga::rename_table(const char *from, const char *to)
228 } else if (error && from_mapper.table_name()[0] == '#') {
229 alter_share_add(from, tmp_table_share);
231 - mrn_open_mutex_lock();
232 + mrn_open_mutex_lock(NULL);
233 mrn_free_tmp_table_share(tmp_table_share);
234 - mrn_open_mutex_unlock();
235 + mrn_open_mutex_unlock(NULL);
239 @@ -14482,10 +14502,10 @@ char *ha_mroonga::storage_get_foreign_key_create_info()
243 - mrn_open_mutex_lock();
244 + mrn_open_mutex_lock(table_share);
245 tmp_ref_table_share =
246 mrn_create_tmp_table_share(&table_list, ref_path, &error);
247 - mrn_open_mutex_unlock();
248 + mrn_open_mutex_unlock(table_share);
249 if (!tmp_ref_table_share) {
252 @@ -14494,9 +14514,9 @@ char *ha_mroonga::storage_get_foreign_key_create_info()
253 Field *ref_field = &ref_key_info->key_part->field[0];
254 append_identifier(ha_thd(), &create_info_str, ref_field->field_name,
255 strlen(ref_field->field_name));
256 - mrn_open_mutex_lock();
257 + mrn_open_mutex_lock(table_share);
258 mrn_free_tmp_table_share(tmp_ref_table_share);
259 - mrn_open_mutex_unlock();
260 + mrn_open_mutex_unlock(table_share);
261 if (create_info_str.reserve(39)) {
264 @@ -14694,10 +14714,10 @@ int ha_mroonga::storage_get_foreign_key_list(THD *thd,
268 - mrn_open_mutex_lock();
269 + mrn_open_mutex_lock(table_share);
270 tmp_ref_table_share =
271 mrn_create_tmp_table_share(&table_list, ref_path, &error);
272 - mrn_open_mutex_unlock();
273 + mrn_open_mutex_unlock(table_share);
274 if (!tmp_ref_table_share) {
277 @@ -14709,9 +14729,9 @@ int ha_mroonga::storage_get_foreign_key_list(THD *thd,
278 strlen(ref_field->field_name),
280 f_key_info.referenced_fields.push_back(ref_col_name);
281 - mrn_open_mutex_lock();
282 + mrn_open_mutex_lock(table_share);
283 mrn_free_tmp_table_share(tmp_ref_table_share);
284 - mrn_open_mutex_unlock();
285 + mrn_open_mutex_unlock(table_share);
286 FOREIGN_KEY_INFO *p_f_key_info =
287 (FOREIGN_KEY_INFO *) thd_memdup(thd, &f_key_info,
288 sizeof(FOREIGN_KEY_INFO));
289 diff --git a/ha_mroonga.hpp b/ha_mroonga.hpp
290 index 579210e..d200bca 100644
293 @@ -172,6 +172,10 @@ extern "C" {
294 # define MRN_HANDLER_START_BULK_INSERT_HAS_FLAGS
297 +#if (defined(MRN_MARIADB_P) && MYSQL_VERSION_ID >= 100010)
298 +# define MRN_HAVE_TDC_LOCK_TABLE_SHARE