mroonga-4.01-mariadb-10.0.10.patch 10.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
diff --git a/ha_mroonga.cpp b/ha_mroonga.cpp
index 20d251a..2504599 100644
--- a/ha_mroonga.cpp
+++ b/ha_mroonga.cpp
@@ -101,22 +101,38 @@
 #define MRN_TEXT_SIZE       (1 << 16) // 64Kbytes
 #define MRN_LONG_TEXT_SIZE  (1 << 31) //  2Gbytes
 
-#if MYSQL_VERSION_ID >= 50500
-#  ifdef DBUG_OFF
-#    ifndef _WIN32
+#ifdef MRN_HAVE_TDC_LOCK_TABLE_SHARE
+#  define mrn_open_mutex(share) &((share)->tdc.LOCK_table_share)
+#  define mrn_open_mutex_lock(share) do {       \
+  TABLE_SHARE *share_ = share;                  \
+  if (share_) {                                 \
+    mysql_mutex_lock(mrn_open_mutex(share_));   \
+  }                                             \
+} while (0)
+#  define mrn_open_mutex_unlock(share) do {     \
+  TABLE_SHARE *share_ = share;                  \
+  if (share_) {                                 \
+    mysql_mutex_unlock(mrn_open_mutex(share_)); \
+  }                                             \
+} while (0)
+#else
+#  if MYSQL_VERSION_ID >= 50500
+#    ifdef DBUG_OFF
+#      ifndef _WIN32
 extern mysql_mutex_t LOCK_open;
+#      endif
 #    endif
-#  endif
 mysql_mutex_t *mrn_LOCK_open;
-#  define mrn_open_mutex_lock() mysql_mutex_lock(mrn_LOCK_open)
-#  define mrn_open_mutex_unlock() mysql_mutex_unlock(mrn_LOCK_open)
-#else
-#  ifndef _WIN32
+#    define mrn_open_mutex_lock(share) mysql_mutex_lock(mrn_LOCK_open)
+#    define mrn_open_mutex_unlock(share) mysql_mutex_unlock(mrn_LOCK_open)
+#  else
+#    ifndef _WIN32
 extern pthread_mutex_t LOCK_open;
-#  endif
+#    endif
 pthread_mutex_t *mrn_LOCK_open;
-#  define mrn_open_mutex_lock()
-#  define mrn_open_mutex_unlock()
+#    define mrn_open_mutex_lock(share)
+#    define mrn_open_mutex_unlock(share)
+#  endif
 #endif
 
 #if MYSQL_VERSION_ID >= 50600
@@ -1275,13 +1291,15 @@ static int mrn_init(void *p)
   mrn_table_def_cache = (HASH *)GetProcAddress(current_module,
     "?table_def_cache@@3Ust_hash@@A");
 #  endif
+#  ifndef MRN_HAVE_TDC_LOCK_TABLE_SHARE
   mrn_LOCK_open =
-#  if MYSQL_VERSION_ID >= 50500
+#    if MYSQL_VERSION_ID >= 50500
     (mysql_mutex_t *)GetProcAddress(current_module,
       "?LOCK_open@@3Ust_mysql_mutex@@A");
-#  else
+#    else
     (pthread_mutex_t *)GetProcAddress(current_module,
       "?LOCK_open@@3U_RTL_CRITICAL_SECTION@@A");
+#    endif
 #  endif
 #  ifdef MRN_TABLE_SHARE_HAVE_LOCK_SHARE
      mrn_table_share_lock_share =
@@ -1297,7 +1315,9 @@ static int mrn_init(void *p)
 #  ifdef MRN_HAVE_TABLE_DEF_CACHE
   mrn_table_def_cache = &table_def_cache;
 #  endif
+#  ifndef MRN_HAVE_TDC_LOCK_TABLE_SHARE
   mrn_LOCK_open = &LOCK_open;
+#  endif
 #endif
 
   // init groonga
@@ -3033,10 +3053,10 @@ bool ha_mroonga::storage_create_foreign_key(TABLE *table,
                               mapper.mysql_table_name(),
                               TL_WRITE);
 #endif
-    mrn_open_mutex_lock();
+    mrn_open_mutex_lock(table->s);
     tmp_ref_table_share =
       mrn_create_tmp_table_share(&table_list, ref_path, &error);
-    mrn_open_mutex_unlock();
+    mrn_open_mutex_unlock(table->s);
     if (!tmp_ref_table_share) {
       grn_obj_unlink(ctx, grn_table_ref);
       error = ER_CANT_CREATE_TABLE;
@@ -3048,9 +3068,9 @@ bool ha_mroonga::storage_create_foreign_key(TABLE *table,
     }
     uint ref_pkey_nr = tmp_ref_table_share->primary_key;
     if (ref_pkey_nr == MAX_KEY) {
-      mrn_open_mutex_lock();
+      mrn_open_mutex_lock(table->s);
       mrn_free_tmp_table_share(tmp_ref_table_share);
-      mrn_open_mutex_unlock();
+      mrn_open_mutex_unlock(table->s);
       grn_obj_unlink(ctx, grn_table_ref);
       error = ER_CANT_CREATE_TABLE;
       char err_msg[MRN_BUFFER_SIZE];
@@ -3062,9 +3082,9 @@ bool ha_mroonga::storage_create_foreign_key(TABLE *table,
     KEY *ref_key_info = &tmp_ref_table_share->key_info[ref_pkey_nr];
     uint ref_key_parts = KEY_N_KEY_PARTS(ref_key_info);
     if (ref_key_parts > 1) {
-      mrn_open_mutex_lock();
+      mrn_open_mutex_lock(table->s);
       mrn_free_tmp_table_share(tmp_ref_table_share);
-      mrn_open_mutex_unlock();
+      mrn_open_mutex_unlock(table->s);
       grn_obj_unlink(ctx, grn_table_ref);
       error = ER_CANT_CREATE_TABLE;
       char err_msg[MRN_BUFFER_SIZE];
@@ -3076,9 +3096,9 @@ bool ha_mroonga::storage_create_foreign_key(TABLE *table,
     }
     Field *ref_field = &ref_key_info->key_part->field[0];
     if (strcmp(ref_field->field_name, ref_field_name.str)) {
-      mrn_open_mutex_lock();
+      mrn_open_mutex_lock(table->s);
       mrn_free_tmp_table_share(tmp_ref_table_share);
-      mrn_open_mutex_unlock();
+      mrn_open_mutex_unlock(table->s);
       grn_obj_unlink(ctx, grn_table_ref);
       error = ER_CANT_CREATE_TABLE;
       char err_msg[MRN_BUFFER_SIZE];
@@ -3088,9 +3108,9 @@ bool ha_mroonga::storage_create_foreign_key(TABLE *table,
       my_message(error, err_msg, MYF(0));
       DBUG_RETURN(false);
     }
-    mrn_open_mutex_lock();
+    mrn_open_mutex_lock(table->s);
     mrn_free_tmp_table_share(tmp_ref_table_share);
-    mrn_open_mutex_unlock();
+    mrn_open_mutex_unlock(table->s);
     grn_obj_flags col_flags = GRN_OBJ_PERSISTENT;
     column = grn_column_create(ctx, table_obj, field->field_name,
                                strlen(field->field_name),
@@ -4210,18 +4230,18 @@ int ha_mroonga::close()
     table_list.init_one_table(mapper.db_name(), mapper.mysql_table_name(),
                               TL_WRITE);
 #endif
-    mrn_open_mutex_lock();
+    mrn_open_mutex_lock(NULL);
     tmp_table_share =
       mrn_create_tmp_table_share(&table_list, share->table_name, &tmp_error);
-    mrn_open_mutex_unlock();
+    mrn_open_mutex_unlock(NULL);
     if (!tmp_table_share) {
       error = tmp_error;
     } else if ((tmp_error = alter_share_add(share->table_name,
                                             tmp_table_share))) {
       error = tmp_error;
-      mrn_open_mutex_lock();
+      mrn_open_mutex_lock(NULL);
       mrn_free_tmp_table_share(tmp_table_share);
-      mrn_open_mutex_unlock();
+      mrn_open_mutex_unlock(NULL);
     }
   }
   bitmap_free(&multiple_column_key_bitmap);
@@ -4394,9 +4414,9 @@ int ha_mroonga::delete_table(const char *name)
     table_list.init_one_table(mapper.db_name(), mapper.mysql_table_name(),
                               TL_WRITE);
 #endif
-    mrn_open_mutex_lock();
+    mrn_open_mutex_lock(NULL);
     tmp_table_share = mrn_create_tmp_table_share(&table_list, name, &error);
-    mrn_open_mutex_unlock();
+    mrn_open_mutex_unlock(NULL);
     if (!tmp_table_share) {
       DBUG_RETURN(error);
     }
@@ -4407,9 +4427,9 @@ int ha_mroonga::delete_table(const char *name)
 #endif
   if (!(tmp_share = mrn_get_share(name, &tmp_table, &error)))
   {
-    mrn_open_mutex_lock();
+    mrn_open_mutex_lock(NULL);
     mrn_free_tmp_table_share(tmp_table_share);
-    mrn_open_mutex_unlock();
+    mrn_open_mutex_unlock(NULL);
     DBUG_RETURN(error);
   }
 
@@ -4425,9 +4445,9 @@ int ha_mroonga::delete_table(const char *name)
     tmp_share->long_term_share = NULL;
   }
   mrn_free_share(tmp_share);
-  mrn_open_mutex_lock();
+  mrn_open_mutex_lock(NULL);
   mrn_free_tmp_table_share(tmp_table_share);
-  mrn_open_mutex_unlock();
+  mrn_open_mutex_unlock(NULL);
   if (is_temporary_table_name(name)) {
     mrn_drop_db(name);
   }
@@ -11885,9 +11905,9 @@ int ha_mroonga::rename_table(const char *from, const char *to)
                             from_mapper.mysql_table_name(),
                             TL_WRITE);
 #endif
-  mrn_open_mutex_lock();
+  mrn_open_mutex_lock(NULL);
   tmp_table_share = mrn_create_tmp_table_share(&table_list, from, &error);
-  mrn_open_mutex_unlock();
+  mrn_open_mutex_unlock(NULL);
   if (!tmp_table_share) {
     DBUG_RETURN(error);
   }
@@ -11897,9 +11917,9 @@ int ha_mroonga::rename_table(const char *from, const char *to)
 #endif
   if (!(tmp_share = mrn_get_share(from, &tmp_table, &error)))
   {
-    mrn_open_mutex_lock();
+    mrn_open_mutex_lock(NULL);
     mrn_free_tmp_table_share(tmp_table_share);
-    mrn_open_mutex_unlock();
+    mrn_open_mutex_unlock(NULL);
     DBUG_RETURN(error);
   }
 
@@ -11925,9 +11945,9 @@ int ha_mroonga::rename_table(const char *from, const char *to)
   } else if (error && from_mapper.table_name()[0] == '#') {
     alter_share_add(from, tmp_table_share);
   } else {
-    mrn_open_mutex_lock();
+    mrn_open_mutex_lock(NULL);
     mrn_free_tmp_table_share(tmp_table_share);
-    mrn_open_mutex_unlock();
+    mrn_open_mutex_unlock(NULL);
   }
   DBUG_RETURN(error);
 }
@@ -14482,10 +14502,10 @@ char *ha_mroonga::storage_get_foreign_key_create_info()
                               ref_table_buff,
                               TL_WRITE);
 #endif
-    mrn_open_mutex_lock();
+    mrn_open_mutex_lock(table_share);
     tmp_ref_table_share =
       mrn_create_tmp_table_share(&table_list, ref_path, &error);
-    mrn_open_mutex_unlock();
+    mrn_open_mutex_unlock(table_share);
     if (!tmp_ref_table_share) {
       DBUG_RETURN(NULL);
     }
@@ -14494,9 +14514,9 @@ char *ha_mroonga::storage_get_foreign_key_create_info()
     Field *ref_field = &ref_key_info->key_part->field[0];
     append_identifier(ha_thd(), &create_info_str, ref_field->field_name,
                       strlen(ref_field->field_name));
-    mrn_open_mutex_lock();
+    mrn_open_mutex_lock(table_share);
     mrn_free_tmp_table_share(tmp_ref_table_share);
-    mrn_open_mutex_unlock();
+    mrn_open_mutex_unlock(table_share);
     if (create_info_str.reserve(39)) {
       DBUG_RETURN(NULL);
     }
@@ -14694,10 +14714,10 @@ int ha_mroonga::storage_get_foreign_key_list(THD *thd,
                               ref_table_buff,
                               TL_WRITE);
 #endif
-    mrn_open_mutex_lock();
+    mrn_open_mutex_lock(table_share);
     tmp_ref_table_share =
       mrn_create_tmp_table_share(&table_list, ref_path, &error);
-    mrn_open_mutex_unlock();
+    mrn_open_mutex_unlock(table_share);
     if (!tmp_ref_table_share) {
       DBUG_RETURN(error);
     }
@@ -14709,9 +14729,9 @@ int ha_mroonga::storage_get_foreign_key_list(THD *thd,
                                                    strlen(ref_field->field_name),
                                                    TRUE);
     f_key_info.referenced_fields.push_back(ref_col_name);
-    mrn_open_mutex_lock();
+    mrn_open_mutex_lock(table_share);
     mrn_free_tmp_table_share(tmp_ref_table_share);
-    mrn_open_mutex_unlock();
+    mrn_open_mutex_unlock(table_share);
     FOREIGN_KEY_INFO *p_f_key_info =
       (FOREIGN_KEY_INFO *) thd_memdup(thd, &f_key_info,
                                       sizeof(FOREIGN_KEY_INFO));
diff --git a/ha_mroonga.hpp b/ha_mroonga.hpp
index 579210e..d200bca 100644
--- a/ha_mroonga.hpp
+++ b/ha_mroonga.hpp
@@ -172,6 +172,10 @@ extern "C" {
 #  define MRN_HANDLER_START_BULK_INSERT_HAS_FLAGS
 #endif
 
+#if (defined(MRN_MARIADB_P) && MYSQL_VERSION_ID >= 100010)
+#  define MRN_HAVE_TDC_LOCK_TABLE_SHARE
+#endif
+
 class ha_mroonga;
 
 /* structs */