Merge lp:~akopytov/percona-server/ahi-fixes-5.6 into lp:percona-server/5.6

Proposed by Alexey Kopytov
Status: Merged
Approved by: Laurynas Biveinis
Approved revision: no longer in the source branch.
Merged at revision: 421
Proposed branch: lp:~akopytov/percona-server/ahi-fixes-5.6
Merge into: lp:percona-server/5.6
Diff against target: 1957 lines (+482/-381)
25 files modified
Percona-Server/mysql-test/r/percona_bug1218330.result (+14/-0)
Percona-Server/mysql-test/t/percona_bug1218330-master.opt (+1/-0)
Percona-Server/mysql-test/t/percona_bug1218330.test (+72/-0)
Percona-Server/storage/innobase/btr/btr0cur.cc (+7/-7)
Percona-Server/storage/innobase/btr/btr0sea.cc (+109/-132)
Percona-Server/storage/innobase/buf/buf0buf.cc (+0/-2)
Percona-Server/storage/innobase/dict/dict0boot.cc (+6/-0)
Percona-Server/storage/innobase/dict/dict0dict.cc (+5/-3)
Percona-Server/storage/innobase/dict/dict0load.cc (+1/-0)
Percona-Server/storage/innobase/ha/ha0ha.cc (+2/-2)
Percona-Server/storage/innobase/handler/ha_innodb.cc (+21/-19)
Percona-Server/storage/innobase/handler/xtradb_i_s.cc (+35/-33)
Percona-Server/storage/innobase/ibuf/ibuf0ibuf.cc (+2/-0)
Percona-Server/storage/innobase/include/btr0sea.h (+35/-9)
Percona-Server/storage/innobase/include/btr0sea.ic (+66/-11)
Percona-Server/storage/innobase/include/btr0types.h (+7/-6)
Percona-Server/storage/innobase/include/buf0buf.h (+0/-2)
Percona-Server/storage/innobase/include/dict0mem.h (+4/-0)
Percona-Server/storage/innobase/include/trx0trx.h (+7/-5)
Percona-Server/storage/innobase/include/trx0trx.ic (+5/-12)
Percona-Server/storage/innobase/row/row0ftsort.cc (+3/-0)
Percona-Server/storage/innobase/row/row0sel.cc (+32/-91)
Percona-Server/storage/innobase/srv/srv0srv.cc (+42/-44)
Percona-Server/storage/innobase/sync/sync0sync.cc (+3/-3)
Percona-Server/storage/innobase/trx/trx0trx.cc (+3/-0)
To merge this branch: bzr merge lp:~akopytov/percona-server/ahi-fixes-5.6
Reviewer Review Type Date Requested Status
Laurynas Biveinis (community) Approve
Review via email: mp+183473@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Laurynas Biveinis (laurynas-biveinis) wrote :

    - Same comments as for the 5.5 MP.
    - Diff line 182--185: missing arg comment, and, uhm, why add more
      "=====" ?
    - Diff line 385--391 drops MONITOR_INC call.

review: Needs Fixing
Revision history for this message
Alexey Kopytov (akopytov) wrote :

Hi Laurynas,

On Wed, 04 Sep 2013 15:00:11 -0000, Laurynas Biveinis wrote:
> Review: Needs Fixing
>
> - Same comments as for the 5.5 MP.
> - Diff line 182--185: missing arg comment, and, uhm, why add more
> "=====" ?

Oh noes :)

> - Diff line 385--391 drops MONITOR_INC call.
>

This is a good catch, will fix.

Revision history for this message
Alexey Kopytov (akopytov) wrote :

Hi Laurynas,

On Wed, 04 Sep 2013 15:00:11 -0000, Laurynas Biveinis wrote:
> Review: Needs Fixing
>
> - Same comments as for the 5.5 MP.
> - Diff line 182--185: missing arg comment, and, uhm, why add more
> "=====" ?

Actually, this is how the diff looks in my tree:

@@ -133,17 +130,17 @@
  void
  btr_search_check_free_space_in_heap(
  /*=====================================*/
- index_id_t key)
+ dict_index_t* index)

I.e. it doesn't touch the comment part. But will fix anyway.

Revision history for this message
Alexey Kopytov (akopytov) wrote :

Hi Laurynas,

On Wed, 04 Sep 2013 15:00:11 -0000, Laurynas Biveinis wrote:
> - Diff line 385--391 drops MONITOR_INC call.
>

Same here. It appears to be some bogus change. This is how rev. diff
looks in my tree:

  #ifdef UNIV_SYNC_DEBUG
- ut_ad(rw_lock_own(btr_search_get_latch(cursor->index->id), RW_LOCK_EX));
+ ut_ad(rw_lock_own(btr_search_get_latch(cursor->index),
+ RW_LOCK_EX));
  #endif /* UNIV_SYNC_DEBUG */

- ha_insert_for_fold(btr_search_get_hash_index(cursor->index->id), fold,
- block, rec);
+ ha_insert_for_fold(btr_search_get_hash_table(cursor->index),
+ fold, block, rec);
   }
  }

I.e. there was simply no MONITOR_INC call. Not sure whom to blame here,
bzr or LP diff viewer.

Revision history for this message
Laurynas Biveinis (laurynas-biveinis) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'Percona-Server/mysql-test/r/percona_bug1218330.result'
--- Percona-Server/mysql-test/r/percona_bug1218330.result 1970-01-01 00:00:00 +0000
+++ Percona-Server/mysql-test/r/percona_bug1218330.result 2013-09-02 14:08:46 +0000
@@ -0,0 +1,14 @@
1CREATE TABLE t1 (
2a INT PRIMARY KEY, b INT,
3c CHAR(200),
4UNIQUE INDEX b(b)) ENGINE=InnoDB;
5INSERT INTO t1 VALUES (1, 1, REPEAT("a", 200));
6should_be_1
71
8should_be_1
91
10should_be_1
111
12should_be_1
131
14DROP TABLE t1;
015
=== added file 'Percona-Server/mysql-test/t/percona_bug1218330-master.opt'
--- Percona-Server/mysql-test/t/percona_bug1218330-master.opt 1970-01-01 00:00:00 +0000
+++ Percona-Server/mysql-test/t/percona_bug1218330-master.opt 2013-09-02 14:08:46 +0000
@@ -0,0 +1,1 @@
1--innodb-adaptive-hash-index-partitions=32
02
=== added file 'Percona-Server/mysql-test/t/percona_bug1218330.test'
--- Percona-Server/mysql-test/t/percona_bug1218330.test 1970-01-01 00:00:00 +0000
+++ Percona-Server/mysql-test/t/percona_bug1218330.test 2013-09-02 14:08:46 +0000
@@ -0,0 +1,72 @@
1############################################################################
2# Bug #1218330: Adaptive hash index memory is incorrectly calculated in SHOW
3# ENGINE INNODB STATUS and I_S
4############################################################################
5
6--source include/have_innodb.inc
7
8let $adaptive_hash_mem_1=`SELECT VARIABLE_VALUE FROM
9 INFORMATION_SCHEMA.GLOBAL_STATUS WHERE
10 VARIABLE_NAME='Innodb_mem_adaptive_hash'`;
11
12let $is_adaptive_hash_mem_constant_1=`SELECT CONSTANT_MEMORY FROM
13 INFORMATION_SCHEMA.XTRADB_INTERNAL_HASH_TABLES WHERE
14 INTERNAL_HASH_TABLE_NAME='Adaptive hash index'`;
15
16let $is_adaptive_hash_mem_variable_1=`SELECT VARIABLE_MEMORY FROM
17 INFORMATION_SCHEMA.XTRADB_INTERNAL_HASH_TABLES WHERE
18 INTERNAL_HASH_TABLE_NAME='Adaptive hash index'`;
19
20let $is_adaptive_hash_mem_total_1=`SELECT TOTAL_MEMORY FROM
21 INFORMATION_SCHEMA.XTRADB_INTERNAL_HASH_TABLES WHERE
22 INTERNAL_HASH_TABLE_NAME='Adaptive hash index'`;
23
24CREATE TABLE t1 (
25 a INT PRIMARY KEY, b INT,
26 c CHAR(200),
27 UNIQUE INDEX b(b)) ENGINE=InnoDB;
28
29INSERT INTO t1 VALUES (1, 1, REPEAT("a", 200));
30
31--disable_query_log
32
33--let $i=200
34--disable_result_log
35while ($i)
36{
37 SELECT a FROM t1 WHERE a=1;
38 SELECT b FROM t1 WHERE b=1;
39 --dec $i
40}
41--enable_result_log
42
43let $adaptive_hash_mem_2=`SELECT VARIABLE_VALUE FROM
44 INFORMATION_SCHEMA.GLOBAL_STATUS WHERE
45 VARIABLE_NAME='Innodb_mem_adaptive_hash'`;
46
47let $is_adaptive_hash_mem_constant_2=`SELECT CONSTANT_MEMORY FROM
48 INFORMATION_SCHEMA.XTRADB_INTERNAL_HASH_TABLES WHERE
49 INTERNAL_HASH_TABLE_NAME='Adaptive hash index'`;
50
51let $is_adaptive_hash_mem_variable_2=`SELECT VARIABLE_MEMORY FROM
52 INFORMATION_SCHEMA.XTRADB_INTERNAL_HASH_TABLES WHERE
53 INTERNAL_HASH_TABLE_NAME='Adaptive hash index'`;
54
55let $is_adaptive_hash_mem_total_2=`SELECT TOTAL_MEMORY FROM
56 INFORMATION_SCHEMA.XTRADB_INTERNAL_HASH_TABLES WHERE
57 INTERNAL_HASH_TABLE_NAME='Adaptive hash index'`;
58
59# The original implementation would should identical values in
60# adaptive_hash_mem_1 and adaptive_hash_mem_2
61
62--eval SELECT $adaptive_hash_mem_1 != $adaptive_hash_mem_2 as should_be_1
63
64# Should show identical constant, but different variable parts
65
66--eval SELECT $is_adaptive_hash_mem_total_1 != $is_adaptive_hash_mem_total_2 as should_be_1
67--eval SELECT $is_adaptive_hash_mem_constant_1 = $is_adaptive_hash_mem_constant_2 as should_be_1
68--eval SELECT $is_adaptive_hash_mem_variable_1 != $is_adaptive_hash_mem_variable_2 as should_be_1
69
70--enable_query_log
71
72DROP TABLE t1;
073
=== modified file 'Percona-Server/storage/innobase/btr/btr0cur.cc'
--- Percona-Server/storage/innobase/btr/btr0cur.cc 2013-08-29 17:05:40 +0000
+++ Percona-Server/storage/innobase/btr/btr0cur.cc 2013-09-02 14:08:46 +0000
@@ -535,9 +535,9 @@
535535
536# ifdef UNIV_SEARCH_PERF_STAT536# ifdef UNIV_SEARCH_PERF_STAT
537 info->n_searches++;537 info->n_searches++;
538# endif538#endif
539 if ((rw_lock_get_writer(btr_search_get_latch(cursor->index->id))539 if (rw_lock_get_writer(btr_search_get_latch(cursor->index)) ==
540 == RW_LOCK_NOT_LOCKED)540 RW_LOCK_NOT_LOCKED
541 && latch_mode <= BTR_MODIFY_LEAF541 && latch_mode <= BTR_MODIFY_LEAF
542 && info->last_hash_succ542 && info->last_hash_succ
543 && !estimate543 && !estimate
@@ -573,7 +573,7 @@
573573
574 if (has_search_latch) {574 if (has_search_latch) {
575 /* Release possible search latch to obey latching order */575 /* Release possible search latch to obey latching order */
576 rw_lock_s_unlock(btr_search_get_latch(cursor->index->id));576 rw_lock_s_unlock(btr_search_get_latch(cursor->index));
577 }577 }
578578
579 /* Store the position of the tree latch we push to mtr so that we579 /* Store the position of the tree latch we push to mtr so that we
@@ -896,7 +896,7 @@
896896
897 if (has_search_latch) {897 if (has_search_latch) {
898898
899 rw_lock_s_lock(btr_search_get_latch(cursor->index->id));899 rw_lock_s_lock(btr_search_get_latch(cursor->index));
900 }900 }
901}901}
902902
@@ -2163,13 +2163,13 @@
2163 btr_search_update_hash_on_delete(cursor);2163 btr_search_update_hash_on_delete(cursor);
2164 }2164 }
21652165
2166 rw_lock_x_lock(btr_search_get_latch(cursor->index->id));2166 rw_lock_x_lock(btr_search_get_latch(cursor->index));
2167 }2167 }
21682168
2169 row_upd_rec_in_place(rec, index, offsets, update, page_zip);2169 row_upd_rec_in_place(rec, index, offsets, update, page_zip);
21702170
2171 if (is_hashed) {2171 if (is_hashed) {
2172 rw_lock_x_unlock(btr_search_get_latch(cursor->index->id));2172 rw_lock_x_unlock(btr_search_get_latch(cursor->index));
2173 }2173 }
21742174
2175 btr_cur_update_in_place_log(flags, rec, index, update,2175 btr_cur_update_in_place_log(flags, rec, index, update,
21762176
=== modified file 'Percona-Server/storage/innobase/btr/btr0sea.cc'
--- Percona-Server/storage/innobase/btr/btr0sea.cc 2013-08-29 17:05:40 +0000
+++ Percona-Server/storage/innobase/btr/btr0sea.cc 2013-09-02 14:08:46 +0000
@@ -65,15 +65,14 @@
65cache line as btr_search_latch */65cache line as btr_search_latch */
66UNIV_INTERN byte btr_sea_pad1[64];66UNIV_INTERN byte btr_sea_pad1[64];
6767
68/** The latch protecting the adaptive search system: this latch protects the68/** Array of latches protecting individual AHI partitions. The latches
69(1) positions of records on those pages where a hash index has been built.69protect: (1) positions of records on those pages where a hash index from the
70NOTE: It does not protect values of non-ordering fields within a record from70corresponding AHI partition has been built.
71NOTE: They do not protect values of non-ordering fields within a record from
71being updated in-place! We can use fact (1) to perform unique searches to72being updated in-place! We can use fact (1) to perform unique searches to
72indexes. */73indexes. */
7374
74/* We will allocate the latches from dynamic memory to get them to the75UNIV_INTERN rw_lock_t* btr_search_latch_arr;
75same DRAM page as other hotspot semaphores */
76UNIV_INTERN rw_lock_t** btr_search_latch_arr;
7776
78/** padding to prevent other memory update hotspots from residing on77/** padding to prevent other memory update hotspots from residing on
79the same memory cache line */78the same memory cache line */
@@ -126,18 +125,18 @@
126static125static
127void126void
128btr_search_check_free_space_in_heap(127btr_search_check_free_space_in_heap(
129/*================================*/128/*=====================================*/
130 index_id_t key) /*!<in: id of the hashed index tree */129 dict_index_t* index)
131{130{
132 hash_table_t* table;131 hash_table_t* table;
133 mem_heap_t* heap;132 mem_heap_t* heap;
134133
135#ifdef UNIV_SYNC_DEBUG134#ifdef UNIV_SYNC_DEBUG
136 ut_ad(!rw_lock_own(btr_search_get_latch(key), RW_LOCK_SHARED));135 ut_ad(!rw_lock_own(btr_search_get_latch(index), RW_LOCK_SHARED));
137 ut_ad(!rw_lock_own(btr_search_get_latch(key), RW_LOCK_EX));136 ut_ad(!rw_lock_own(btr_search_get_latch(index), RW_LOCK_EX));
138#endif /* UNIV_SYNC_DEBUG */137#endif /* UNIV_SYNC_DEBUG */
139138
140 table = btr_search_get_hash_index(key);139 table = btr_search_get_hash_table(index);
141140
142 heap = table->heap;141 heap = table->heap;
143142
@@ -148,7 +147,7 @@
148 if (heap->free_block == NULL) {147 if (heap->free_block == NULL) {
149 buf_block_t* block = buf_block_alloc(NULL);148 buf_block_t* block = buf_block_alloc(NULL);
150149
151 rw_lock_x_lock(btr_search_get_latch(key));150 rw_lock_x_lock(btr_search_get_latch(index));
152151
153 if (heap->free_block == NULL) {152 if (heap->free_block == NULL) {
154 heap->free_block = block;153 heap->free_block = block;
@@ -156,7 +155,7 @@
156 buf_block_free(block);155 buf_block_free(block);
157 }156 }
158157
159 rw_lock_x_unlock(btr_search_get_latch(key));158 rw_lock_x_unlock(btr_search_get_latch(index));
160 }159 }
161}160}
162161
@@ -182,31 +181,28 @@
182 /* We allocate the search latch from dynamic memory:181 /* We allocate the search latch from dynamic memory:
183 see above at the global variable definition */182 see above at the global variable definition */
184183
185 /* btr_search_index_num should be no greater than bits of184 /* btr_search_index_num is constrained to machine word size for
186 trx->has_search_latch, which is ulint. */185 historical reasons. This limitation can be easily removed later. */
187 ut_ad(btr_search_index_num <= sizeof(ulint));
188186
189 btr_search_latch_arr = (rw_lock_t**)187 btr_search_latch_arr = (rw_lock_t *)
190 mem_alloc(sizeof(rw_lock_t *) * btr_search_index_num);188 mem_alloc(sizeof(rw_lock_t) * btr_search_index_num);
191189
192 btr_search_sys = (btr_search_sys_t*)190 btr_search_sys = (btr_search_sys_t*)
193 mem_alloc(sizeof(btr_search_sys_t));191 mem_alloc(sizeof(btr_search_sys_t));
194192
195 btr_search_sys->hash_index = (hash_table_t **)193 btr_search_sys->hash_tables = (hash_table_t **)
196 mem_alloc(sizeof(hash_table_t *) * btr_search_index_num);194 mem_alloc(sizeof(hash_table_t *) * btr_search_index_num);
197195
198 for (i = 0; i < btr_search_index_num; i++) {196 for (i = 0; i < btr_search_index_num; i++) {
199 btr_search_latch_arr[i] = (rw_lock_t *)197
200 mem_alloc(sizeof(rw_lock_t));198 rw_lock_create(btr_search_latch_key,
201199 &btr_search_latch_arr[i], SYNC_SEARCH_SYS);
202 rw_lock_create(btr_search_latch_key, btr_search_latch_arr[i],200
203 SYNC_SEARCH_SYS);201 btr_search_sys->hash_tables[i]
204
205 btr_search_sys->hash_index[i]
206 = ha_create(hash_size, 0, MEM_HEAP_FOR_BTR_SEARCH, 0);202 = ha_create(hash_size, 0, MEM_HEAP_FOR_BTR_SEARCH, 0);
207203
208#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG204#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
209 btr_search_sys->hash_index[i]->adaptive = TRUE;205 btr_search_sys->hash_tables[i]->adaptive = TRUE;
210#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */206#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
211 }207 }
212}208}
@@ -222,20 +218,18 @@
222218
223 for (i = 0; i < btr_search_index_num; i++) {219 for (i = 0; i < btr_search_index_num; i++) {
224220
225 rw_lock_free(btr_search_latch_arr[i]);221 rw_lock_free(&btr_search_latch_arr[i]);
226222
227 mem_free(btr_search_latch_arr[i]);223 mem_heap_free(btr_search_sys->hash_tables[i]->heap);
228224
229 mem_heap_free(btr_search_sys->hash_index[i]->heap);225 hash_table_free(btr_search_sys->hash_tables[i]);
230
231 hash_table_free(btr_search_sys->hash_index[i]);
232226
233 }227 }
234228
235 mem_free(btr_search_latch_arr);229 mem_free(btr_search_latch_arr);
236 btr_search_latch_arr = NULL;230 btr_search_latch_arr = NULL;
237231
238 mem_free(btr_search_sys->hash_index);232 mem_free(btr_search_sys->hash_tables);
239233
240 mem_free(btr_search_sys);234 mem_free(btr_search_sys);
241 btr_search_sys = NULL;235 btr_search_sys = NULL;
@@ -257,7 +251,7 @@
257 index = dict_table_get_next_index(index)) {251 index = dict_table_get_next_index(index)) {
258252
259#ifdef UNIV_SYNC_DEBUG253#ifdef UNIV_SYNC_DEBUG
260 ut_ad(rw_lock_own(btr_search_get_latch(index->id),254 ut_ad(rw_lock_own(btr_search_get_latch(index),
261 RW_LOCK_EX));255 RW_LOCK_EX));
262#endif /* UNIV_SYNC_DEBUG */256#endif /* UNIV_SYNC_DEBUG */
263 index->search_info->ref_count = 0;257 index->search_info->ref_count = 0;
@@ -300,8 +294,8 @@
300294
301 /* Clear the adaptive hash index. */295 /* Clear the adaptive hash index. */
302 for (i = 0; i < btr_search_index_num; i++) {296 for (i = 0; i < btr_search_index_num; i++) {
303 hash_table_clear(btr_search_sys->hash_index[i]);297 hash_table_clear(btr_search_sys->hash_tables[i]);
304 mem_heap_empty(btr_search_sys->hash_index[i]->heap);298 mem_heap_empty(btr_search_sys->hash_tables[i]->heap);
305 }299 }
306300
307 btr_search_x_unlock_all();301 btr_search_x_unlock_all();
@@ -364,27 +358,27 @@
364358
365/*****************************************************************//**359/*****************************************************************//**
366Returns the value of ref_count. The value is protected by360Returns the value of ref_count. The value is protected by
367btr_search_latch.361the .
368@return ref_count value. */362@return ref_count value. */
369UNIV_INTERN363UNIV_INTERN
370ulint364ulint
371btr_search_info_get_ref_count(365btr_search_info_get_ref_count(
372/*==========================*/366/*==========================*/
373 btr_search_t* info, /*!< in: search info. */367 btr_search_t* info, /*!< in: search info. */
374 index_id_t key) /*!< in: id of the index owning search info */368 dict_index_t* index) /*!< in: index */
375{369{
376 ulint ret;370 ulint ret;
377371
378 ut_ad(info);372 ut_ad(info);
379373
380#ifdef UNIV_SYNC_DEBUG374#ifdef UNIV_SYNC_DEBUG
381 ut_ad(!rw_lock_own(btr_search_get_latch(key), RW_LOCK_SHARED));375 ut_ad(!rw_lock_own(btr_search_get_latch(index), RW_LOCK_SHARED));
382 ut_ad(!rw_lock_own(btr_search_get_latch(key), RW_LOCK_EX));376 ut_ad(!rw_lock_own(btr_search_get_latch(index), RW_LOCK_EX));
383#endif /* UNIV_SYNC_DEBUG */377#endif /* UNIV_SYNC_DEBUG */
384378
385 rw_lock_s_lock(btr_search_get_latch(key));379 rw_lock_s_lock(btr_search_get_latch(index));
386 ret = info->ref_count;380 ret = info->ref_count;
387 rw_lock_s_unlock(btr_search_get_latch(key));381 rw_lock_s_unlock(btr_search_get_latch(index));
388382
389 return(ret);383 return(ret);
390}384}
@@ -405,8 +399,8 @@
405 int cmp;399 int cmp;
406400
407#ifdef UNIV_SYNC_DEBUG401#ifdef UNIV_SYNC_DEBUG
408 ut_ad(!rw_lock_own(btr_search_get_latch(index->id), RW_LOCK_SHARED));402 ut_ad(!rw_lock_own(btr_search_get_latch(index), RW_LOCK_SHARED));
409 ut_ad(!rw_lock_own(btr_search_get_latch(index->id), RW_LOCK_EX));403 ut_ad(!rw_lock_own(btr_search_get_latch(index), RW_LOCK_EX));
410#endif /* UNIV_SYNC_DEBUG */404#endif /* UNIV_SYNC_DEBUG */
411405
412 if (dict_index_is_ibuf(index)) {406 if (dict_index_is_ibuf(index)) {
@@ -522,9 +516,9 @@
522 /*!< in: cursor */516 /*!< in: cursor */
523{517{
524#ifdef UNIV_SYNC_DEBUG518#ifdef UNIV_SYNC_DEBUG
525 ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index->id),519 ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index),
526 RW_LOCK_SHARED));520 RW_LOCK_SHARED));
527 ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index->id),521 ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index),
528 RW_LOCK_EX));522 RW_LOCK_EX));
529 ut_ad(rw_lock_own(&block->lock, RW_LOCK_SHARED)523 ut_ad(rw_lock_own(&block->lock, RW_LOCK_SHARED)
530 || rw_lock_own(&block->lock, RW_LOCK_EX));524 || rw_lock_own(&block->lock, RW_LOCK_EX));
@@ -609,7 +603,7 @@
609603
610 ut_ad(cursor->flag == BTR_CUR_HASH_FAIL);604 ut_ad(cursor->flag == BTR_CUR_HASH_FAIL);
611#ifdef UNIV_SYNC_DEBUG605#ifdef UNIV_SYNC_DEBUG
612 ut_ad(rw_lock_own(btr_search_get_latch(cursor->index->id),606 ut_ad(rw_lock_own(btr_search_get_latch(cursor->index),
613 RW_LOCK_EX));607 RW_LOCK_EX));
614 ut_ad(rw_lock_own(&(block->lock), RW_LOCK_SHARED)608 ut_ad(rw_lock_own(&(block->lock), RW_LOCK_SHARED)
615 || rw_lock_own(&(block->lock), RW_LOCK_EX));609 || rw_lock_own(&(block->lock), RW_LOCK_EX));
@@ -651,15 +645,12 @@
651 mem_heap_free(heap);645 mem_heap_free(heap);
652 }646 }
653#ifdef UNIV_SYNC_DEBUG647#ifdef UNIV_SYNC_DEBUG
654 ut_ad(rw_lock_own(btr_search_get_latch(cursor->index->id),648 ut_ad(rw_lock_own(btr_search_get_latch(cursor->index),
655 RW_LOCK_EX));649 RW_LOCK_EX));
656#endif /* UNIV_SYNC_DEBUG */650#endif /* UNIV_SYNC_DEBUG */
657651
658 ha_insert_for_fold(652 ha_insert_for_fold(btr_search_get_hash_table(cursor->index),
659 btr_search_get_hash_index(cursor->index->id), fold,653 fold, block, rec);
660 block, rec);
661
662 MONITOR_INC(MONITOR_ADAPTIVE_HASH_ROW_ADDED);
663 }654 }
664}655}
665656
@@ -678,9 +669,9 @@
678 ulint* params2;669 ulint* params2;
679670
680#ifdef UNIV_SYNC_DEBUG671#ifdef UNIV_SYNC_DEBUG
681 ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index->id),672 ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index),
682 RW_LOCK_SHARED));673 RW_LOCK_SHARED));
683 ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index->id),674 ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index),
684 RW_LOCK_EX));675 RW_LOCK_EX));
685#endif /* UNIV_SYNC_DEBUG */676#endif /* UNIV_SYNC_DEBUG */
686677
@@ -699,7 +690,7 @@
699690
700 if (build_index || (cursor->flag == BTR_CUR_HASH_FAIL)) {691 if (build_index || (cursor->flag == BTR_CUR_HASH_FAIL)) {
701692
702 btr_search_check_free_space_in_heap(cursor->index->id);693 btr_search_check_free_space_in_heap(cursor->index);
703 }694 }
704695
705 if (cursor->flag == BTR_CUR_HASH_FAIL) {696 if (cursor->flag == BTR_CUR_HASH_FAIL) {
@@ -709,11 +700,11 @@
709 btr_search_n_hash_fail++;700 btr_search_n_hash_fail++;
710#endif /* UNIV_SEARCH_PERF_STAT */701#endif /* UNIV_SEARCH_PERF_STAT */
711702
712 rw_lock_x_lock(btr_search_get_latch(cursor->index->id));703 rw_lock_x_lock(btr_search_get_latch(cursor->index));
713704
714 btr_search_update_hash_ref(info, block, cursor);705 btr_search_update_hash_ref(info, block, cursor);
715706
716 rw_lock_x_unlock(btr_search_get_latch(cursor->index->id));707 rw_lock_x_unlock(btr_search_get_latch(cursor->index));
717 }708 }
718709
719 if (build_index) {710 if (build_index) {
@@ -958,19 +949,18 @@
958 cursor->flag = BTR_CUR_HASH;949 cursor->flag = BTR_CUR_HASH;
959950
960 if (UNIV_LIKELY(!has_search_latch)) {951 if (UNIV_LIKELY(!has_search_latch)) {
961 rw_lock_s_lock(btr_search_get_latch(index_id));952 rw_lock_s_lock(btr_search_get_latch(index));
962953
963 if (UNIV_UNLIKELY(!btr_search_enabled)) {954 if (UNIV_UNLIKELY(!btr_search_enabled)) {
964 goto failure_unlock;955 goto failure_unlock;
965 }956 }
966 }957 }
967958
968 ut_ad(rw_lock_get_writer(btr_search_get_latch(index_id))959 ut_ad(rw_lock_get_writer(btr_search_get_latch(index)) != RW_LOCK_EX);
969 != RW_LOCK_EX);960 ut_ad(rw_lock_get_reader_count(btr_search_get_latch(index)) > 0);
970 ut_ad(rw_lock_get_reader_count(btr_search_get_latch(index_id)) > 0);
971961
972 rec = (rec_t*) ha_search_and_get_data(962 rec = (rec_t*) ha_search_and_get_data(
973 btr_search_get_hash_index(index_id), fold);963 btr_search_get_hash_table(index), fold);
974964
975 if (UNIV_UNLIKELY(!rec)) {965 if (UNIV_UNLIKELY(!rec)) {
976 goto failure_unlock;966 goto failure_unlock;
@@ -988,7 +978,7 @@
988 goto failure_unlock;978 goto failure_unlock;
989 }979 }
990980
991 rw_lock_s_unlock(btr_search_get_latch(index_id));981 rw_lock_s_unlock(btr_search_get_latch(index));
992982
993 buf_block_dbg_add_level(block, SYNC_TREE_NODE_FROM_HASH);983 buf_block_dbg_add_level(block, SYNC_TREE_NODE_FROM_HASH);
994 }984 }
@@ -1085,7 +1075,7 @@
1085 /*-------------------------------------------*/1075 /*-------------------------------------------*/
1086failure_unlock:1076failure_unlock:
1087 if (UNIV_LIKELY(!has_search_latch)) {1077 if (UNIV_LIKELY(!has_search_latch)) {
1088 rw_lock_s_unlock(btr_search_get_latch(index_id));1078 rw_lock_s_unlock(btr_search_get_latch(index));
1089 }1079 }
1090failure:1080failure:
1091 cursor->flag = BTR_CUR_HASH_FAIL;1081 cursor->flag = BTR_CUR_HASH_FAIL;
@@ -1133,41 +1123,31 @@
1133 const dict_index_t* index;1123 const dict_index_t* index;
1134 ulint* offsets;1124 ulint* offsets;
1135 btr_search_t* info;1125 btr_search_t* info;
1136 rw_lock_t* btr_search_latch;
11371126
1138retry:1127retry:
1139 /* Do a dirty check on block->index, return if the block is1128 /* Do a dirty check on block->index, return if the block is not in the
1140 not in the adaptive hash index. This is to avoid acquiring1129 adaptive hash index. This is to avoid acquiring an AHI latch for
1141 shared btr_search_latch for performance consideration. */1130 performance considerations. */
1142 if (!block->index) {1131
1143 return;1132 index = block->index;
1144 }1133 if (!index) {
11451134
1146 btr_search_latch = block->btr_search_latch;
1147
1148 if (UNIV_UNLIKELY(!btr_search_latch)) {
1149 return;1135 return;
1150 }1136 }
11511137
1152#ifdef UNIV_SYNC_DEBUG1138#ifdef UNIV_SYNC_DEBUG
1153 ut_ad(!rw_lock_own(btr_search_latch, RW_LOCK_SHARED));1139 ut_ad(!rw_lock_own(btr_search_get_latch(index), RW_LOCK_SHARED));
1154 ut_ad(!rw_lock_own(btr_search_latch, RW_LOCK_EX));1140 ut_ad(!rw_lock_own(btr_search_get_latch(index), RW_LOCK_EX));
1155#endif /* UNIV_SYNC_DEBUG */1141#endif /* UNIV_SYNC_DEBUG */
11561142 rw_lock_s_lock(btr_search_get_latch(index));
1157 rw_lock_s_lock(btr_search_latch);1143
1158 if (UNIV_UNLIKELY(btr_search_latch != block->btr_search_latch)) {1144 if (UNIV_UNLIKELY(index != block->index)) {
1159 rw_lock_s_unlock(btr_search_latch);1145
1146 rw_lock_s_unlock(btr_search_get_latch(index));
1147
1160 goto retry;1148 goto retry;
1161 }1149 }
11621150
1163 index = block->index;
1164 if (UNIV_UNLIKELY(!index)) {
1165 rw_lock_s_unlock(btr_search_latch);
1166 return;
1167 }
1168
1169 ut_ad(btr_search_latch == btr_search_get_latch(index->id));
1170
1171 ut_a(!dict_index_is_ibuf(index));1151 ut_a(!dict_index_is_ibuf(index));
1172#ifdef UNIV_DEBUG1152#ifdef UNIV_DEBUG
1173 switch (dict_index_get_online_status(index)) {1153 switch (dict_index_get_online_status(index)) {
@@ -1190,7 +1170,7 @@
1190 }1170 }
1191#endif /* UNIV_DEBUG */1171#endif /* UNIV_DEBUG */
11921172
1193 table = btr_search_get_hash_index(index->id);1173 table = btr_search_get_hash_table(index);
11941174
1195#ifdef UNIV_SYNC_DEBUG1175#ifdef UNIV_SYNC_DEBUG
1196 ut_ad(rw_lock_own(&(block->lock), RW_LOCK_SHARED)1176 ut_ad(rw_lock_own(&(block->lock), RW_LOCK_SHARED)
@@ -1206,7 +1186,7 @@
1206 releasing btr_search_latch, as the index page might only1186 releasing btr_search_latch, as the index page might only
1207 be s-latched! */1187 be s-latched! */
12081188
1209 rw_lock_s_unlock(btr_search_latch);1189 rw_lock_s_unlock(btr_search_get_latch(index));
12101190
1211 ut_a(n_fields + n_bytes > 0);1191 ut_a(n_fields + n_bytes > 0);
12121192
@@ -1257,7 +1237,7 @@
1257 mem_heap_free(heap);1237 mem_heap_free(heap);
1258 }1238 }
12591239
1260 rw_lock_x_lock(btr_search_get_latch(index->id));1240 rw_lock_x_lock(btr_search_get_latch(index));
12611241
1262 if (UNIV_UNLIKELY(!block->index)) {1242 if (UNIV_UNLIKELY(!block->index)) {
1263 /* Someone else has meanwhile dropped the hash index */1243 /* Someone else has meanwhile dropped the hash index */
@@ -1273,7 +1253,7 @@
1273 /* Someone else has meanwhile built a new hash index on the1253 /* Someone else has meanwhile built a new hash index on the
1274 page, with different parameters */1254 page, with different parameters */
12751255
1276 rw_lock_x_unlock(btr_search_get_latch(index->id));1256 rw_lock_x_unlock(btr_search_get_latch(index));
12771257
1278 mem_free(folds);1258 mem_free(folds);
1279 goto retry;1259 goto retry;
@@ -1289,7 +1269,6 @@
1289 info->ref_count--;1269 info->ref_count--;
12901270
1291 block->index = NULL;1271 block->index = NULL;
1292 block->btr_search_latch = NULL;
12931272
1294 MONITOR_INC(MONITOR_ADAPTIVE_HASH_PAGE_REMOVED);1273 MONITOR_INC(MONITOR_ADAPTIVE_HASH_PAGE_REMOVED);
1295 MONITOR_INC_VALUE(MONITOR_ADAPTIVE_HASH_ROW_REMOVED, n_cached);1274 MONITOR_INC_VALUE(MONITOR_ADAPTIVE_HASH_ROW_REMOVED, n_cached);
@@ -1305,14 +1284,14 @@
1305 "InnoDB: the hash index to a page of %s,"1284 "InnoDB: the hash index to a page of %s,"
1306 " still %lu hash nodes remain.\n",1285 " still %lu hash nodes remain.\n",
1307 index->name, (ulong) block->n_pointers);1286 index->name, (ulong) block->n_pointers);
1308 rw_lock_x_unlock(btr_search_get_latch(index->id));1287 rw_lock_x_unlock(btr_search_get_latch(index));
13091288
1310 ut_ad(btr_search_validate());1289 ut_ad(btr_search_validate());
1311 } else {1290 } else {
1312 rw_lock_x_unlock(btr_search_get_latch(index->id));1291 rw_lock_x_unlock(btr_search_get_latch(index));
1313 }1292 }
1314#else /* UNIV_AHI_DEBUG || UNIV_DEBUG */1293#else /* UNIV_AHI_DEBUG || UNIV_DEBUG */
1315 rw_lock_x_unlock(btr_search_get_latch(index->id));1294 rw_lock_x_unlock(btr_search_get_latch(index));
1316#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */1295#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
13171296
1318 mem_free(folds);1297 mem_free(folds);
@@ -1391,30 +1370,30 @@
1391 ut_a(!dict_index_is_ibuf(index));1370 ut_a(!dict_index_is_ibuf(index));
13921371
1393#ifdef UNIV_SYNC_DEBUG1372#ifdef UNIV_SYNC_DEBUG
1394 ut_ad(!rw_lock_own(btr_search_get_latch(index->id), RW_LOCK_EX));1373 ut_ad(!rw_lock_own(btr_search_get_latch(index), RW_LOCK_EX));
1395 ut_ad(rw_lock_own(&(block->lock), RW_LOCK_SHARED)1374 ut_ad(rw_lock_own(&(block->lock), RW_LOCK_SHARED)
1396 || rw_lock_own(&(block->lock), RW_LOCK_EX));1375 || rw_lock_own(&(block->lock), RW_LOCK_EX));
1397#endif /* UNIV_SYNC_DEBUG */1376#endif /* UNIV_SYNC_DEBUG */
13981377
1399 rw_lock_s_lock(btr_search_get_latch(index->id));1378 rw_lock_s_lock(btr_search_get_latch(index));
14001379
1401 if (!btr_search_enabled) {1380 if (!btr_search_enabled) {
1402 rw_lock_s_unlock(btr_search_get_latch(index->id));1381 rw_lock_s_unlock(btr_search_get_latch(index));
1403 return;1382 return;
1404 }1383 }
14051384
1406 table = btr_search_get_hash_index(index->id);1385 table = btr_search_get_hash_table(index);
1407 page = buf_block_get_frame(block);1386 page = buf_block_get_frame(block);
14081387
1409 if (block->index && ((block->curr_n_fields != n_fields)1388 if (block->index && ((block->curr_n_fields != n_fields)
1410 || (block->curr_n_bytes != n_bytes)1389 || (block->curr_n_bytes != n_bytes)
1411 || (block->curr_left_side != left_side))) {1390 || (block->curr_left_side != left_side))) {
14121391
1413 rw_lock_s_unlock(btr_search_get_latch(index->id));1392 rw_lock_s_unlock(btr_search_get_latch(index));
14141393
1415 btr_search_drop_page_hash_index(block);1394 btr_search_drop_page_hash_index(block);
1416 } else {1395 } else {
1417 rw_lock_s_unlock(btr_search_get_latch(index->id));1396 rw_lock_s_unlock(btr_search_get_latch(index));
1418 }1397 }
14191398
1420 n_recs = page_get_n_recs(page);1399 n_recs = page_get_n_recs(page);
@@ -1508,9 +1487,9 @@
1508 fold = next_fold;1487 fold = next_fold;
1509 }1488 }
15101489
1511 btr_search_check_free_space_in_heap(index->id);1490 btr_search_check_free_space_in_heap(index);
15121491
1513 rw_lock_x_lock(btr_search_get_latch(index->id));1492 rw_lock_x_lock(btr_search_get_latch(index));
15141493
1515 if (UNIV_UNLIKELY(!btr_search_enabled)) {1494 if (UNIV_UNLIKELY(!btr_search_enabled)) {
1516 goto exit_func;1495 goto exit_func;
@@ -1537,7 +1516,6 @@
1537 block->curr_n_bytes = n_bytes;1516 block->curr_n_bytes = n_bytes;
1538 block->curr_left_side = left_side;1517 block->curr_left_side = left_side;
1539 block->index = index;1518 block->index = index;
1540 block->btr_search_latch = btr_search_get_latch(index->id);
15411519
1542 for (i = 0; i < n_cached; i++) {1520 for (i = 0; i < n_cached; i++) {
15431521
@@ -1547,7 +1525,7 @@
1547 MONITOR_INC(MONITOR_ADAPTIVE_HASH_PAGE_ADDED);1525 MONITOR_INC(MONITOR_ADAPTIVE_HASH_PAGE_ADDED);
1548 MONITOR_INC_VALUE(MONITOR_ADAPTIVE_HASH_ROW_ADDED, n_cached);1526 MONITOR_INC_VALUE(MONITOR_ADAPTIVE_HASH_ROW_ADDED, n_cached);
1549exit_func:1527exit_func:
1550 rw_lock_x_unlock(btr_search_get_latch(index->id));1528 rw_lock_x_unlock(btr_search_get_latch(index));
15511529
1552 mem_free(folds);1530 mem_free(folds);
1553 mem_free(recs);1531 mem_free(recs);
@@ -1582,7 +1560,7 @@
1582 ut_ad(rw_lock_own(&(new_block->lock), RW_LOCK_EX));1560 ut_ad(rw_lock_own(&(new_block->lock), RW_LOCK_EX));
1583#endif /* UNIV_SYNC_DEBUG */1561#endif /* UNIV_SYNC_DEBUG */
15841562
1585 rw_lock_s_lock(btr_search_get_latch(index->id));1563 rw_lock_s_lock(btr_search_get_latch(index));
15861564
1587 ut_a(!new_block->index || new_block->index == index);1565 ut_a(!new_block->index || new_block->index == index);
1588 ut_a(!block->index || block->index == index);1566 ut_a(!block->index || block->index == index);
@@ -1591,7 +1569,7 @@
15911569
1592 if (new_block->index) {1570 if (new_block->index) {
15931571
1594 rw_lock_s_unlock(btr_search_get_latch(index->id));1572 rw_lock_s_unlock(btr_search_get_latch(index));
15951573
1596 btr_search_drop_page_hash_index(block);1574 btr_search_drop_page_hash_index(block);
15971575
@@ -1608,7 +1586,7 @@
1608 new_block->n_bytes = block->curr_n_bytes;1586 new_block->n_bytes = block->curr_n_bytes;
1609 new_block->left_side = left_side;1587 new_block->left_side = left_side;
16101588
1611 rw_lock_s_unlock(btr_search_get_latch(index->id));1589 rw_lock_s_unlock(btr_search_get_latch(index));
16121590
1613 ut_a(n_fields + n_bytes > 0);1591 ut_a(n_fields + n_bytes > 0);
16141592
@@ -1620,7 +1598,7 @@
1620 return;1598 return;
1621 }1599 }
16221600
1623 rw_lock_s_unlock(btr_search_get_latch(index->id));1601 rw_lock_s_unlock(btr_search_get_latch(index));
1624}1602}
16251603
1626/********************************************************************//**1604/********************************************************************//**
@@ -1659,7 +1637,7 @@
1659 ut_a(block->curr_n_fields + block->curr_n_bytes > 0);1637 ut_a(block->curr_n_fields + block->curr_n_bytes > 0);
1660 ut_a(!dict_index_is_ibuf(index));1638 ut_a(!dict_index_is_ibuf(index));
16611639
1662 table = btr_search_get_hash_index(cursor->index->id);1640 table = btr_search_get_hash_table(cursor->index);
16631641
1664 rec = btr_cur_get_rec(cursor);1642 rec = btr_cur_get_rec(cursor);
16651643
@@ -1670,7 +1648,7 @@
1670 mem_heap_free(heap);1648 mem_heap_free(heap);
1671 }1649 }
16721650
1673 rw_lock_x_lock(btr_search_get_latch(cursor->index->id));1651 rw_lock_x_lock(btr_search_get_latch(cursor->index));
16741652
1675 if (block->index) {1653 if (block->index) {
1676 ut_a(block->index == index);1654 ut_a(block->index == index);
@@ -1683,7 +1661,7 @@
1683 }1661 }
1684 }1662 }
16851663
1686 rw_lock_x_unlock(btr_search_get_latch(cursor->index->id));1664 rw_lock_x_unlock(btr_search_get_latch(cursor->index));
1687}1665}
16881666
1689/********************************************************************//**1667/********************************************************************//**
@@ -1720,7 +1698,7 @@
1720 ut_a(cursor->index == index);1698 ut_a(cursor->index == index);
1721 ut_a(!dict_index_is_ibuf(index));1699 ut_a(!dict_index_is_ibuf(index));
17221700
1723 rw_lock_x_lock(btr_search_get_latch(cursor->index->id));1701 rw_lock_x_lock(btr_search_get_latch(cursor->index));
17241702
1725 if (!block->index) {1703 if (!block->index) {
17261704
@@ -1734,7 +1712,7 @@
1734 && (cursor->n_bytes == block->curr_n_bytes)1712 && (cursor->n_bytes == block->curr_n_bytes)
1735 && !block->curr_left_side) {1713 && !block->curr_left_side) {
17361714
1737 table = btr_search_get_hash_index(cursor->index->id);1715 table = btr_search_get_hash_table(cursor->index);
17381716
1739 if (ha_search_and_update_if_found(1717 if (ha_search_and_update_if_found(
1740 table, cursor->fold, rec, block,1718 table, cursor->fold, rec, block,
@@ -1743,9 +1721,9 @@
1743 }1721 }
17441722
1745func_exit:1723func_exit:
1746 rw_lock_x_unlock(btr_search_get_latch(cursor->index->id));1724 rw_lock_x_unlock(btr_search_get_latch(cursor->index));
1747 } else {1725 } else {
1748 rw_lock_x_unlock(btr_search_get_latch(cursor->index->id));1726 rw_lock_x_unlock(btr_search_get_latch(cursor->index));
17491727
1750 btr_search_update_hash_on_insert(cursor);1728 btr_search_update_hash_on_insert(cursor);
1751 }1729 }
@@ -1793,9 +1771,9 @@
1793 return;1771 return;
1794 }1772 }
17951773
1796 btr_search_check_free_space_in_heap(cursor->index->id);1774 btr_search_check_free_space_in_heap(cursor->index);
17971775
1798 table = btr_search_get_hash_index(cursor->index->id);1776 table = btr_search_get_hash_table(cursor->index);
17991777
1800 rec = btr_cur_get_rec(cursor);1778 rec = btr_cur_get_rec(cursor);
18011779
@@ -1827,7 +1805,7 @@
1827 } else {1805 } else {
1828 if (left_side) {1806 if (left_side) {
18291807
1830 rw_lock_x_lock(btr_search_get_latch(index->id));1808 rw_lock_x_lock(btr_search_get_latch(index));
18311809
1832 locked = TRUE;1810 locked = TRUE;
18331811
@@ -1845,7 +1823,7 @@
18451823
1846 if (!locked) {1824 if (!locked) {
18471825
1848 rw_lock_x_lock(btr_search_get_latch(index->id));1826 rw_lock_x_lock(btr_search_get_latch(index));
18491827
1850 locked = TRUE;1828 locked = TRUE;
18511829
@@ -1867,8 +1845,7 @@
1867 if (!left_side) {1845 if (!left_side) {
18681846
1869 if (!locked) {1847 if (!locked) {
1870 rw_lock_x_lock(btr_search_get_latch(1848 rw_lock_x_lock(btr_search_get_latch(index));
1871 index->id));
18721849
1873 locked = TRUE;1850 locked = TRUE;
18741851
@@ -1887,7 +1864,7 @@
18871864
1888 if (!locked) {1865 if (!locked) {
18891866
1890 rw_lock_x_lock(btr_search_get_latch(index->id));1867 rw_lock_x_lock(btr_search_get_latch(index));
18911868
1892 locked = TRUE;1869 locked = TRUE;
18931870
@@ -1914,7 +1891,7 @@
1914 mem_heap_free(heap);1891 mem_heap_free(heap);
1915 }1892 }
1916 if (locked) {1893 if (locked) {
1917 rw_lock_x_unlock(btr_search_get_latch(index->id));1894 rw_lock_x_unlock(btr_search_get_latch(index));
1918 }1895 }
1919}1896}
19201897
@@ -1945,7 +1922,7 @@
19451922
1946 buf_pool_mutex_enter_all();1923 buf_pool_mutex_enter_all();
19471924
1948 cell_count = hash_get_n_cells(btr_search_sys->hash_index[t]);1925 cell_count = hash_get_n_cells(btr_search_sys->hash_tables[t]);
19491926
1950 for (i = 0; i < cell_count; i++) {1927 for (i = 0; i < cell_count; i++) {
1951 /* We release btr_search_latch every once in a while to1928 /* We release btr_search_latch every once in a while to
@@ -1959,7 +1936,7 @@
1959 }1936 }
19601937
1961 node = (ha_node_t*)1938 node = (ha_node_t*)
1962 hash_get_nth_cell(btr_search_sys->hash_index[t],1939 hash_get_nth_cell(btr_search_sys->hash_tables[t],
1963 i)->node;1940 i)->node;
19641941
1965 for (; node != NULL; node = node->next) {1942 for (; node != NULL; node = node->next) {
@@ -2075,7 +2052,7 @@
2075 buf_pool_mutex_enter_all();2052 buf_pool_mutex_enter_all();
2076 }2053 }
20772054
2078 if (!ha_validate(btr_search_sys->hash_index[t], i,2055 if (!ha_validate(btr_search_sys->hash_tables[t], i,
2079 end_index)) {2056 end_index)) {
2080 ok = FALSE;2057 ok = FALSE;
2081 }2058 }
20822059
=== modified file 'Percona-Server/storage/innobase/buf/buf0buf.cc'
--- Percona-Server/storage/innobase/buf/buf0buf.cc 2013-08-29 17:46:30 +0000
+++ Percona-Server/storage/innobase/buf/buf0buf.cc 2013-09-02 14:08:46 +0000
@@ -1013,7 +1013,6 @@
10131013
1014 block->check_index_page_at_flush = FALSE;1014 block->check_index_page_at_flush = FALSE;
1015 block->index = NULL;1015 block->index = NULL;
1016 block->btr_search_latch = NULL;
10171016
1018#ifdef UNIV_DEBUG1017#ifdef UNIV_DEBUG
1019 block->page.in_page_hash = FALSE;1018 block->page.in_page_hash = FALSE;
@@ -2209,7 +2208,6 @@
2209{2208{
2210 block->check_index_page_at_flush = FALSE;2209 block->check_index_page_at_flush = FALSE;
2211 block->index = NULL;2210 block->index = NULL;
2212 block->btr_search_latch = NULL;
22132211
2214 block->n_hash_helps = 0;2212 block->n_hash_helps = 0;
2215 block->n_fields = 1;2213 block->n_fields = 1;
22162214
=== modified file 'Percona-Server/storage/innobase/dict/dict0boot.cc'
--- Percona-Server/storage/innobase/dict/dict0boot.cc 2013-08-06 15:16:34 +0000
+++ Percona-Server/storage/innobase/dict/dict0boot.cc 2013-09-02 14:08:46 +0000
@@ -31,6 +31,7 @@
3131
32#include "dict0crea.h"32#include "dict0crea.h"
33#include "btr0btr.h"33#include "btr0btr.h"
34#include "btr0sea.h"
34#include "dict0load.h"35#include "dict0load.h"
35#include "trx0trx.h"36#include "trx0trx.h"
36#include "srv0srv.h"37#include "srv0srv.h"
@@ -331,6 +332,7 @@
331 dict_mem_index_add_field(index, "NAME", 0);332 dict_mem_index_add_field(index, "NAME", 0);
332333
333 index->id = DICT_TABLES_ID;334 index->id = DICT_TABLES_ID;
335 btr_search_index_init(index);
334336
335 error = dict_index_add_to_cache(table, index,337 error = dict_index_add_to_cache(table, index,
336 mtr_read_ulint(dict_hdr338 mtr_read_ulint(dict_hdr
@@ -345,6 +347,7 @@
345 dict_mem_index_add_field(index, "ID", 0);347 dict_mem_index_add_field(index, "ID", 0);
346348
347 index->id = DICT_TABLE_IDS_ID;349 index->id = DICT_TABLE_IDS_ID;
350 btr_search_index_init(index);
348 error = dict_index_add_to_cache(table, index,351 error = dict_index_add_to_cache(table, index,
349 mtr_read_ulint(dict_hdr352 mtr_read_ulint(dict_hdr
350 + DICT_HDR_TABLE_IDS,353 + DICT_HDR_TABLE_IDS,
@@ -377,6 +380,7 @@
377 dict_mem_index_add_field(index, "POS", 0);380 dict_mem_index_add_field(index, "POS", 0);
378381
379 index->id = DICT_COLUMNS_ID;382 index->id = DICT_COLUMNS_ID;
383 btr_search_index_init(index);
380 error = dict_index_add_to_cache(table, index,384 error = dict_index_add_to_cache(table, index,
381 mtr_read_ulint(dict_hdr385 mtr_read_ulint(dict_hdr
382 + DICT_HDR_COLUMNS,386 + DICT_HDR_COLUMNS,
@@ -409,6 +413,7 @@
409 dict_mem_index_add_field(index, "ID", 0);413 dict_mem_index_add_field(index, "ID", 0);
410414
411 index->id = DICT_INDEXES_ID;415 index->id = DICT_INDEXES_ID;
416 btr_search_index_init(index);
412 error = dict_index_add_to_cache(table, index,417 error = dict_index_add_to_cache(table, index,
413 mtr_read_ulint(dict_hdr418 mtr_read_ulint(dict_hdr
414 + DICT_HDR_INDEXES,419 + DICT_HDR_INDEXES,
@@ -437,6 +442,7 @@
437 dict_mem_index_add_field(index, "POS", 0);442 dict_mem_index_add_field(index, "POS", 0);
438443
439 index->id = DICT_FIELDS_ID;444 index->id = DICT_FIELDS_ID;
445 btr_search_index_init(index);
440 error = dict_index_add_to_cache(table, index,446 error = dict_index_add_to_cache(table, index,
441 mtr_read_ulint(dict_hdr447 mtr_read_ulint(dict_hdr
442 + DICT_HDR_FIELDS,448 + DICT_HDR_FIELDS,
443449
=== modified file 'Percona-Server/storage/innobase/dict/dict0dict.cc'
--- Percona-Server/storage/innobase/dict/dict0dict.cc 2013-08-29 17:05:40 +0000
+++ Percona-Server/storage/innobase/dict/dict0dict.cc 2013-09-02 14:08:46 +0000
@@ -1208,8 +1208,7 @@
12081208
1209 See also: dict_index_remove_from_cache_low() */1209 See also: dict_index_remove_from_cache_low() */
12101210
1211 if (btr_search_info_get_ref_count(info, index->id)1211 if (btr_search_info_get_ref_count(info, index) > 0) {
1212 > 0) {
1213 return(FALSE);1212 return(FALSE);
1214 }1213 }
1215 }1214 }
@@ -2485,7 +2484,7 @@
24852484
2486 do {2485 do {
2487 ulint ref_count = btr_search_info_get_ref_count(info,2486 ulint ref_count = btr_search_info_get_ref_count(info,
2488 index->id);2487 index);
24892488
2490 if (ref_count == 0) {2489 if (ref_count == 0) {
2491 break;2490 break;
@@ -2777,6 +2776,7 @@
2777 new_index->n_user_defined_cols = index->n_fields;2776 new_index->n_user_defined_cols = index->n_fields;
27782777
2779 new_index->id = index->id;2778 new_index->id = index->id;
2779 btr_search_index_init(new_index);
27802780
2781 /* Copy the fields of index */2781 /* Copy the fields of index */
2782 dict_index_copy(new_index, index, table, 0, index->n_fields);2782 dict_index_copy(new_index, index, table, 0, index->n_fields);
@@ -2948,6 +2948,7 @@
2948 new_index->n_user_defined_cols = index->n_fields;2948 new_index->n_user_defined_cols = index->n_fields;
29492949
2950 new_index->id = index->id;2950 new_index->id = index->id;
2951 btr_search_index_init(new_index);
29512952
2952 /* Copy fields from index to new_index */2953 /* Copy fields from index to new_index */
2953 dict_index_copy(new_index, index, table, 0, index->n_fields);2954 dict_index_copy(new_index, index, table, 0, index->n_fields);
@@ -3031,6 +3032,7 @@
3031 new_index->n_user_defined_cols = index->n_fields;3032 new_index->n_user_defined_cols = index->n_fields;
30323033
3033 new_index->id = index->id;3034 new_index->id = index->id;
3035 btr_search_index_init(new_index);
30343036
3035 /* Copy fields from index to new_index */3037 /* Copy fields from index to new_index */
3036 dict_index_copy(new_index, index, table, 0, index->n_fields);3038 dict_index_copy(new_index, index, table, 0, index->n_fields);
30373039
=== modified file 'Percona-Server/storage/innobase/dict/dict0load.cc'
--- Percona-Server/storage/innobase/dict/dict0load.cc 2013-08-14 03:57:21 +0000
+++ Percona-Server/storage/innobase/dict/dict0load.cc 2013-09-02 14:08:46 +0000
@@ -1748,6 +1748,7 @@
17481748
1749 (*index)->id = id;1749 (*index)->id = id;
1750 (*index)->page = mach_read_from_4(field);1750 (*index)->page = mach_read_from_4(field);
1751 btr_search_index_init(*index);
1751 ut_ad((*index)->page);1752 ut_ad((*index)->page);
17521753
1753 return(NULL);1754 return(NULL);
17541755
=== modified file 'Percona-Server/storage/innobase/ha/ha0ha.cc'
--- Percona-Server/storage/innobase/ha/ha0ha.cc 2013-08-29 17:05:40 +0000
+++ Percona-Server/storage/innobase/ha/ha0ha.cc 2013-09-02 14:08:46 +0000
@@ -113,13 +113,13 @@
113 ut_ad(table->adaptive);113 ut_ad(table->adaptive);
114114
115 for (i = 0; i < btr_search_index_num; i++) {115 for (i = 0; i < btr_search_index_num; i++) {
116 if (btr_search_sys->hash_index[i] == table) {116 if (btr_search_sys->hash_tables[i] == table) {
117 break;117 break;
118 }118 }
119 }119 }
120120
121 ut_ad(i < btr_search_index_num);121 ut_ad(i < btr_search_index_num);
122 ut_ad(rw_lock_own(btr_search_latch_arr[i], RW_LOCK_EX));122 ut_ad(rw_lock_own(&btr_search_latch_arr[i], RW_LOCK_EX));
123123
124 return(true);124 return(true);
125}125}
126126
=== modified file 'Percona-Server/storage/innobase/handler/ha_innodb.cc'
--- Percona-Server/storage/innobase/handler/ha_innodb.cc 2013-08-29 17:46:30 +0000
+++ Percona-Server/storage/innobase/handler/ha_innodb.cc 2013-09-02 14:08:46 +0000
@@ -1473,20 +1473,21 @@
1473}1473}
14741474
1475/********************************************************************//**1475/********************************************************************//**
1476Call this function when mysqld passes control to the client. That is to1476In XtraDB it is impossible for a transaction to own a search latch outside of
1477avoid deadlocks on the adaptive hash S-latch possibly held by thd. For more1477InnoDB code, so there is nothing to release on demand. We keep this function to
1478documentation, see handler.cc.1478simplify maintenance.
1479@return 0 */1479@return 0 */
1480static1480static
1481int1481int
1482innobase_release_temporary_latches(1482innobase_release_temporary_latches(
1483/*===============================*/1483/*===============================*/
1484 handlerton* hton, /*!< in: handlerton */1484 handlerton* hton __attribute__((unused)), /*!< in: handlerton */
1485 THD* thd) /*!< in: MySQL thread */1485 THD* thd __attribute__((unused))) /*!< in: MySQL thread */
1486{1486{
1487#ifdef UNIV_DEBUG
1487 DBUG_ASSERT(hton == innodb_hton_ptr);1488 DBUG_ASSERT(hton == innodb_hton_ptr);
14881489
1489 if (!innodb_inited) {1490 if (!innodb_inited || thd == NULL) {
14901491
1491 return(0);1492 return(0);
1492 }1493 }
@@ -1494,8 +1495,12 @@
1494 trx_t* trx = thd_to_trx(thd);1495 trx_t* trx = thd_to_trx(thd);
14951496
1496 if (trx != NULL) {1497 if (trx != NULL) {
1498#ifdef UNIV_SYNC_DEBUG
1499 ut_ad(!btr_search_own_any());
1500#endif
1497 trx_search_latch_release_if_reserved(trx);1501 trx_search_latch_release_if_reserved(trx);
1498 }1502 }
1503#endif
14991504
1500 return(0);1505 return(0);
1501}1506}
@@ -3772,9 +3777,8 @@
3772 /* Since we will reserve the trx_sys->mutex, we have to release3777 /* Since we will reserve the trx_sys->mutex, we have to release
3773 the search system latch first to obey the latching order. */3778 the search system latch first to obey the latching order. */
37743779
3775 if (trx->has_search_latch) {3780 /* No-op in XtraDB */
3776 trx_search_latch_release_if_reserved(trx);3781 trx_search_latch_release_if_reserved(trx);
3777 }
37783782
3779 if (trx->fake_changes &&3783 if (trx->fake_changes &&
3780 (commit_trx ||3784 (commit_trx ||
@@ -4972,12 +4976,8 @@
49724976
4973 thd = ha_thd();4977 thd = ha_thd();
49744978
4975 /* Under some cases MySQL seems to call this function while4979 /* No-op in XtraDB */
4976 holding btr_search_latch. This breaks the latching order as4980 innobase_release_temporary_latches(ht, thd);
4977 we acquire dict_sys->mutex below and leads to a deadlock. */
4978 if (thd != NULL) {
4979 innobase_release_temporary_latches(ht, thd);
4980 }
49814981
4982 normalize_table_name(norm_name, name);4982 normalize_table_name(norm_name, name);
49834983
@@ -5398,9 +5398,9 @@
5398 DBUG_ENTER("ha_innobase::close");5398 DBUG_ENTER("ha_innobase::close");
53995399
5400 thd = ha_thd();5400 thd = ha_thd();
5401 if (thd != NULL) {5401
5402 innobase_release_temporary_latches(ht, thd);5402 /* No-op in XtraDB */
5403 }5403 innobase_release_temporary_latches(ht, thd);
54045404
5405 row_prebuilt_free(prebuilt, FALSE);5405 row_prebuilt_free(prebuilt, FALSE);
54065406
@@ -16398,6 +16398,8 @@
16398 "Disable with --skip-innodb-adaptive-hash-index.",16398 "Disable with --skip-innodb-adaptive-hash-index.",
16399 NULL, innodb_adaptive_hash_index_update, TRUE);16399 NULL, innodb_adaptive_hash_index_update, TRUE);
1640016400
16401/* btr_search_index_num is constrained to machine word size for historical
16402reasons. This limitation can be easily removed later. */
16401static MYSQL_SYSVAR_ULONG(adaptive_hash_index_partitions, btr_search_index_num,16403static MYSQL_SYSVAR_ULONG(adaptive_hash_index_partitions, btr_search_index_num,
16402 PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,16404 PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
16403 "Number of InnoDB adaptive hash index partitions (default 1: disable "16405 "Number of InnoDB adaptive hash index partitions (default 1: disable "
1640416406
=== modified file 'Percona-Server/storage/innobase/handler/xtradb_i_s.cc'
--- Percona-Server/storage/innobase/handler/xtradb_i_s.cc 2013-08-29 17:05:40 +0000
+++ Percona-Server/storage/innobase/handler/xtradb_i_s.cc 2013-09-02 14:08:46 +0000
@@ -309,9 +309,11 @@
309309
310static int xtradb_internal_hash_tables_fill_table(THD* thd, TABLE_LIST* tables, Item*)310static int xtradb_internal_hash_tables_fill_table(THD* thd, TABLE_LIST* tables, Item*)
311{311{
312 const char* table_name;312 const char* table_name;
313 Field** fields;313 Field** fields;
314 TABLE* table;314 TABLE* table;
315 ulong btr_search_sys_constant;
316 ulong btr_search_sys_variable;
315317
316 DBUG_ENTER("xtradb_internal_hash_tables_fill_table");318 DBUG_ENTER("xtradb_internal_hash_tables_fill_table");
317319
@@ -327,38 +329,38 @@
327329
328 RETURN_IF_INNODB_NOT_STARTED(table_name);330 RETURN_IF_INNODB_NOT_STARTED(table_name);
329331
330 if (btr_search_sys)332 /* Calculate AHI constant and variable memory allocations */
331 {333
332 ulint btr_search_sys_subtotal;334 btr_search_sys_constant = 0;
333 const hash_table_t* hash_index_0335 btr_search_sys_variable = 0;
334 = btr_search_sys->hash_index[0];336
335337 ut_ad(btr_search_sys->hash_tables);
336 if (hash_index_0->heap) {338
337 btr_search_sys_subtotal339 for (ulint i = 0; i < btr_search_index_num; i++) {
338 = mem_heap_get_size(hash_index_0->heap);340 hash_table_t* ht = btr_search_sys->hash_tables[i];
339 } else {341
340 for (ulint i = 0; i < hash_index_0->n_sync_obj; i++) {342 ut_ad(ht);
341 btr_search_sys_subtotal343 ut_ad(ht->heap);
342 += mem_heap_get_size(hash_index_0344
343 ->heaps[i]);345 /* Multiple mutexes/heaps are currently never used for adaptive
344 }346 hash index tables. */
345 }347 ut_ad(!ht->n_sync_obj);
346 btr_search_sys_subtotal *= btr_search_index_num;348 ut_ad(!ht->heaps);
347349
348 OK(field_store_string(fields[INT_HASH_TABLES_NAME],350 btr_search_sys_variable += mem_heap_get_size(ht->heap);
349 "Adaptive hash index"));351 btr_search_sys_constant += ht->n_cells * sizeof(hash_cell_t);
350 OK(field_store_ulint(fields[INT_HASH_TABLES_TOTAL],
351 btr_search_sys_subtotal
352 + (hash_index_0->n_cells
353 * sizeof(hash_cell_t))));
354 OK(field_store_ulint(fields[INT_HASH_TABLES_CONSTANT],
355 (hash_index_0->n_cells
356 * sizeof(hash_cell_t))));
357 OK(field_store_ulint(fields[INT_HASH_TABLES_VARIABLE],
358 btr_search_sys_subtotal));
359 OK(schema_table_store_record(thd, table));
360 }352 }
361353
354 OK(field_store_string(fields[INT_HASH_TABLES_NAME],
355 "Adaptive hash index"));
356 OK(field_store_ulint(fields[INT_HASH_TABLES_TOTAL],
357 btr_search_sys_variable + btr_search_sys_constant));
358 OK(field_store_ulint(fields[INT_HASH_TABLES_CONSTANT],
359 btr_search_sys_constant));
360 OK(field_store_ulint(fields[INT_HASH_TABLES_VARIABLE],
361 btr_search_sys_variable));
362 OK(schema_table_store_record(thd, table));
363
362 {364 {
363 OK(field_store_string(fields[INT_HASH_TABLES_NAME],365 OK(field_store_string(fields[INT_HASH_TABLES_NAME],
364 "Page hash (buffer pool 0 only)"));366 "Page hash (buffer pool 0 only)"));
365367
=== modified file 'Percona-Server/storage/innobase/ibuf/ibuf0ibuf.cc'
--- Percona-Server/storage/innobase/ibuf/ibuf0ibuf.cc 2013-08-14 03:57:21 +0000
+++ Percona-Server/storage/innobase/ibuf/ibuf0ibuf.cc 2013-09-02 14:08:46 +0000
@@ -52,6 +52,7 @@
52#include "btr0cur.h"52#include "btr0cur.h"
53#include "btr0pcur.h"53#include "btr0pcur.h"
54#include "btr0btr.h"54#include "btr0btr.h"
55#include "btr0sea.h"
55#include "row0upd.h"56#include "row0upd.h"
56#include "sync0sync.h"57#include "sync0sync.h"
57#include "dict0boot.h"58#include "dict0boot.h"
@@ -626,6 +627,7 @@
626 dict_mem_index_add_field(index, "DUMMY_COLUMN", 0);627 dict_mem_index_add_field(index, "DUMMY_COLUMN", 0);
627628
628 index->id = DICT_IBUF_ID_MIN + IBUF_SPACE_ID;629 index->id = DICT_IBUF_ID_MIN + IBUF_SPACE_ID;
630 btr_search_index_init(index);
629631
630 error = dict_index_add_to_cache(table, index,632 error = dict_index_add_to_cache(table, index,
631 FSP_IBUF_TREE_ROOT_PAGE_NO, FALSE);633 FSP_IBUF_TREE_ROOT_PAGE_NO, FALSE);
632634
=== modified file 'Percona-Server/storage/innobase/include/btr0sea.h'
--- Percona-Server/storage/innobase/include/btr0sea.h 2013-08-29 17:05:40 +0000
+++ Percona-Server/storage/innobase/include/btr0sea.h 2013-09-02 14:08:46 +0000
@@ -87,7 +87,7 @@
87btr_search_info_get_ref_count(87btr_search_info_get_ref_count(
88/*==========================*/88/*==========================*/
89 btr_search_t* info, /*!< in: search info. */89 btr_search_t* info, /*!< in: search info. */
90 index_id_t key); /*!< in: id of the index owning search info */90 dict_index_t* index); /*!< in: index */
91/*********************************************************************//**91/*********************************************************************//**
92Updates the search info. */92Updates the search info. */
93UNIV_INLINE93UNIV_INLINE
@@ -199,9 +199,9 @@
199@return the adaptive hash index table for a given index key */199@return the adaptive hash index table for a given index key */
200UNIV_INLINE200UNIV_INLINE
201hash_table_t*201hash_table_t*
202btr_search_get_hash_index(202btr_search_get_hash_table(
203/*======================*/203/*======================*/
204 index_id_t key) /*!< in: index key */204 const dict_index_t* index) /*!< in: index */
205 __attribute__((pure,warn_unused_result));205 __attribute__((pure,warn_unused_result));
206206
207/********************************************************************//**207/********************************************************************//**
@@ -211,8 +211,26 @@
211rw_lock_t*211rw_lock_t*
212btr_search_get_latch(212btr_search_get_latch(
213/*=================*/213/*=================*/
214 index_id_t key) /*!< in: index key */214 const dict_index_t* index) /*!< in: index */
215 __attribute__((pure,warn_unused_result));215 __attribute__((pure,warn_unused_result));
216
217/*********************************************************************//**
218Returns the AHI partition number corresponding to a give index ID. */
219UNIV_INLINE
220ulint
221btr_search_get_key(
222/*===============*/
223 index_id_t index_id) /*!< in: index ID */
224 __attribute__((pure,warn_unused_result));
225
226/*********************************************************************//**
227Initializes AHI-related fields in a newly created index. */
228UNIV_INLINE
229void
230btr_search_index_init(
231/*===============*/
232 dict_index_t* index) /*!< in: index */
233 __attribute__((nonnull));
216234
217/********************************************************************//**235/********************************************************************//**
218Latches all adaptive hash index latches in exclusive mode. */236Latches all adaptive hash index latches in exclusive mode. */
@@ -241,7 +259,15 @@
241/*===============*/259/*===============*/
242 ulint lock_type)260 ulint lock_type)
243 __attribute__((warn_unused_result));261 __attribute__((warn_unused_result));
244#endif /* UNIV_SYNC_DEBUG */262/********************************************************************//**
263Checks if the thread owns any adaptive hash latches in either S or X mode.
264@return true if the thread owns at least one latch in any mode. */
265UNIV_INLINE
266bool
267btr_search_own_any(void)
268/*=====================*/
269 __attribute__((warn_unused_result));
270#endif
245271
246/** The search info struct in an index */272/** The search info struct in an index */
247struct btr_search_t{273struct btr_search_t{
@@ -300,9 +326,9 @@
300326
301/** The hash index system */327/** The hash index system */
302struct btr_search_sys_t{328struct btr_search_sys_t{
303 hash_table_t** hash_index; /*!< the adaptive hash index,329 hash_table_t** hash_tables; /*!< the array of adaptive hash index
304 mapping dtuple_fold values330 tables, mapping dtuple_fold values to
305 to rec_t pointers on index pages */331 rec_t pointers on index pages */
306};332};
307333
308/** The adaptive hash index */334/** The adaptive hash index */
309335
=== modified file 'Percona-Server/storage/innobase/include/btr0sea.ic'
--- Percona-Server/storage/innobase/include/btr0sea.ic 2013-08-29 17:05:40 +0000
+++ Percona-Server/storage/innobase/include/btr0sea.ic 2013-09-02 14:08:46 +0000
@@ -60,8 +60,8 @@
60 btr_search_t* info;60 btr_search_t* info;
6161
62#ifdef UNIV_SYNC_DEBUG62#ifdef UNIV_SYNC_DEBUG
63 ut_ad(!rw_lock_own(btr_search_get_latch(index->id), RW_LOCK_SHARED));63 ut_ad(!rw_lock_own(btr_search_get_latch(index), RW_LOCK_SHARED));
64 ut_ad(!rw_lock_own(btr_search_get_latch(index->id), RW_LOCK_EX));64 ut_ad(!rw_lock_own(btr_search_get_latch(index), RW_LOCK_EX));
65#endif /* UNIV_SYNC_DEBUG */65#endif /* UNIV_SYNC_DEBUG */
6666
67 info = btr_search_get_info(index);67 info = btr_search_get_info(index);
@@ -86,11 +86,14 @@
86@return the adaptive hash index table for a given index key */86@return the adaptive hash index table for a given index key */
87UNIV_INLINE87UNIV_INLINE
88hash_table_t*88hash_table_t*
89btr_search_get_hash_index(89btr_search_get_hash_table(
90/*======================*/90/*======================*/
91 index_id_t key) /*!< in: index key */91 const dict_index_t* index) /*!< in: index */
92{92{
93 return(btr_search_sys->hash_index[key % btr_search_index_num]);93 ut_ad(index);
94 ut_ad(index->search_table);
95
96 return(index->search_table);
94}97}
9598
96/********************************************************************//**99/********************************************************************//**
@@ -100,9 +103,41 @@
100rw_lock_t*103rw_lock_t*
101btr_search_get_latch(104btr_search_get_latch(
102/*=================*/105/*=================*/
103 index_id_t key) /*!< in: index key */106 const dict_index_t* index) /*!< in: index */
104{107{
105 return(btr_search_latch_arr[key % btr_search_index_num]);108 ut_ad(index);
109 ut_ad(index->search_latch >= btr_search_latch_arr &&
110 index->search_latch < btr_search_latch_arr +
111 btr_search_index_num);
112
113 return(index->search_latch);
114}
115
116/*********************************************************************//**
117Returns the AHI partition number corresponding to a give index ID. */
118UNIV_INLINE
119ulint
120btr_search_get_key(
121/*===============*/
122 index_id_t index_id) /*!< in: index ID */
123{
124 return(index_id % btr_search_index_num);
125}
126
127/*********************************************************************//**
128Initializes AHI-related fields in a newly created index. */
129UNIV_INLINE
130void
131btr_search_index_init(
132/*===============*/
133 dict_index_t* index) /*!< in: index */
134{
135 ut_ad(index);
136
137 index->search_latch =
138 &btr_search_latch_arr[btr_search_get_key(index->id)];
139 index->search_table =
140 btr_search_sys->hash_tables[btr_search_get_key(index->id)];
106}141}
107142
108/********************************************************************//**143/********************************************************************//**
@@ -115,7 +150,7 @@
115 ulint i;150 ulint i;
116151
117 for (i = 0; i < btr_search_index_num; i++) {152 for (i = 0; i < btr_search_index_num; i++) {
118 rw_lock_x_lock(btr_search_latch_arr[i]);153 rw_lock_x_lock(&btr_search_latch_arr[i]);
119 }154 }
120}155}
121156
@@ -129,7 +164,7 @@
129 ulint i;164 ulint i;
130165
131 for (i = 0; i < btr_search_index_num; i++) {166 for (i = 0; i < btr_search_index_num; i++) {
132 rw_lock_x_unlock(btr_search_latch_arr[i]);167 rw_lock_x_unlock(&btr_search_latch_arr[i]);
133 }168 }
134}169}
135170
@@ -149,11 +184,31 @@
149 ulint i;184 ulint i;
150185
151 for (i = 0; i < btr_search_index_num; i++) {186 for (i = 0; i < btr_search_index_num; i++) {
152 if (!rw_lock_own(btr_search_latch_arr[i], lock_type)) {187 if (!rw_lock_own(&btr_search_latch_arr[i], lock_type)) {
153 return(false);188 return(false);
154 }189 }
155 }190 }
156191
157 return(true);192 return(true);
158}193}
194
195/********************************************************************//**
196Checks if the thread owns any adaptive hash latches in either S or X mode.
197@return true if the thread owns at least one latch in any mode. */
198UNIV_INLINE
199bool
200btr_search_own_any(void)
201/*====================*/
202{
203 ulint i;
204
205 for (i = 0; i < btr_search_index_num; i++) {
206 if (rw_lock_own(&btr_search_latch_arr[i], RW_LOCK_SHARED) ||
207 rw_lock_own(&btr_search_latch_arr[i], RW_LOCK_EX)) {
208 return(true);
209 }
210 }
211
212 return(false);
213}
159#endif /* UNIV_SYNC_DEBUG */214#endif /* UNIV_SYNC_DEBUG */
160215
=== modified file 'Percona-Server/storage/innobase/include/btr0types.h'
--- Percona-Server/storage/innobase/include/btr0types.h 2013-08-29 17:05:40 +0000
+++ Percona-Server/storage/innobase/include/btr0types.h 2013-09-02 14:08:46 +0000
@@ -41,20 +41,21 @@
4141
42#ifndef UNIV_HOTBACKUP42#ifndef UNIV_HOTBACKUP
4343
44/** @brief The latch protecting the adaptive search system44/** @brief The array of latches protecting the adaptive search partitions
4545
46This latch protects the46These latch protect the
47(1) hash index;47(1) hash index from the corresponding AHI partition;
48(2) columns of a record to which we have a pointer in the hash index;48(2) columns of a record to which we have a pointer in the hash index;
4949
50but does NOT protect:50but do NOT protect:
5151
52(3) next record offset field in a record;52(3) next record offset field in a record;
53(4) next or previous records on the same page.53(4) next or previous records on the same page.
5454
55Bear in mind (3) and (4) when using the hash index.55Bear in mind (3) and (4) when using the hash indexes.
56*/56*/
57extern rw_lock_t** btr_search_latch_arr;57
58extern rw_lock_t* btr_search_latch_arr;
5859
59#endif /* UNIV_HOTBACKUP */60#endif /* UNIV_HOTBACKUP */
6061
6162
=== modified file 'Percona-Server/storage/innobase/include/buf0buf.h'
--- Percona-Server/storage/innobase/include/buf0buf.h 2013-08-29 17:46:30 +0000
+++ Percona-Server/storage/innobase/include/buf0buf.h 2013-09-02 14:08:46 +0000
@@ -1700,8 +1700,6 @@
1700 complete, though: there may1700 complete, though: there may
1701 have been hash collisions,1701 have been hash collisions,
1702 record deletions, etc. */1702 record deletions, etc. */
1703 rw_lock_t* btr_search_latch;/*!< Adaptive hash index latch for the
1704 index this block belongs to or NULL */
1705 /* @} */1703 /* @} */
1706# ifdef UNIV_SYNC_DEBUG1704# ifdef UNIV_SYNC_DEBUG
1707 /** @name Debug fields */1705 /** @name Debug fields */
17081706
=== modified file 'Percona-Server/storage/innobase/include/dict0mem.h'
--- Percona-Server/storage/innobase/include/dict0mem.h 2013-08-14 03:57:21 +0000
+++ Percona-Server/storage/innobase/include/dict0mem.h 2013-09-02 14:08:46 +0000
@@ -544,6 +544,10 @@
544initialized to 0, NULL or FALSE in dict_mem_index_create(). */544initialized to 0, NULL or FALSE in dict_mem_index_create(). */
545struct dict_index_t{545struct dict_index_t{
546 index_id_t id; /*!< id of the index */546 index_id_t id; /*!< id of the index */
547 rw_lock_t* search_latch; /*!< latch protecting the AHI partition
548 corresponding to this index */
549 hash_table_t* search_table; /*!< hash table protected by
550 search_latch */
547 mem_heap_t* heap; /*!< memory heap */551 mem_heap_t* heap; /*!< memory heap */
548 const char* name; /*!< index name */552 const char* name; /*!< index name */
549 const char* table_name;/*!< table name */553 const char* table_name;/*!< table name */
550554
=== modified file 'Percona-Server/storage/innobase/include/trx0trx.h'
--- Percona-Server/storage/innobase/include/trx0trx.h 2013-08-29 17:05:40 +0000
+++ Percona-Server/storage/innobase/include/trx0trx.h 2013-09-02 14:08:46 +0000
@@ -44,12 +44,14 @@
44extern sess_t* trx_dummy_sess;44extern sess_t* trx_dummy_sess;
4545
46/********************************************************************//**46/********************************************************************//**
47Releases the search latch if trx has reserved it. */47In XtraDB it is impossible for a transaction to own a search latch outside of
48InnoDB code, so there is nothing to release on demand. We keep this function to
49simplify maintenance.*/
48UNIV_INLINE50UNIV_INLINE
49void51void
50trx_search_latch_release_if_reserved(52trx_search_latch_release_if_reserved(
51/*=================================*/53/*=================================*/
52 trx_t* trx); /*!< in: transaction */54 trx_t* trx __attribute__((unused))); /*!< in: transaction */
53/******************************************************************//**55/******************************************************************//**
54Set detailed error message for the transaction. */56Set detailed error message for the transaction. */
55UNIV_INTERN57UNIV_INTERN
@@ -815,8 +817,8 @@
815 flush the log in817 flush the log in
816 trx_commit_complete_for_mysql() */818 trx_commit_complete_for_mysql() */
817 ulint duplicates; /*!< TRX_DUP_IGNORE | TRX_DUP_REPLACE */819 ulint duplicates; /*!< TRX_DUP_IGNORE | TRX_DUP_REPLACE */
818 ulint has_search_latch;820 bool has_search_latch;
819 /*!< TRUE if this trx has latched the821 /*!< true if this trx has latched any
820 search system latch in S-mode */822 search system latch in S-mode */
821 ulint search_latch_timeout;823 ulint search_latch_timeout;
822 /*!< If we notice that someone is824 /*!< If we notice that someone is
@@ -1136,7 +1138,7 @@
11361138
1137Bear in mind (3) and (4) when using the hash index.1139Bear in mind (3) and (4) when using the hash index.
1138*/1140*/
1139extern rw_lock_t** btr_search_latch_arr;1141extern rw_lock_t* btr_search_latch_arr;
11401142
1141#ifndef UNIV_NONINL1143#ifndef UNIV_NONINL
1142#include "trx0trx.ic"1144#include "trx0trx.ic"
11431145
=== modified file 'Percona-Server/storage/innobase/include/trx0trx.ic'
--- Percona-Server/storage/innobase/include/trx0trx.ic 2013-08-29 17:05:40 +0000
+++ Percona-Server/storage/innobase/include/trx0trx.ic 2013-09-02 14:08:46 +0000
@@ -164,21 +164,14 @@
164}164}
165165
166/********************************************************************//**166/********************************************************************//**
167Releases the search latches if trx has reserved them. */167In XtraDB it is impossible for a transaction to own a search latch outside of
168InnoDB code, so there is nothing to release on demand. We keep this function to
169simplify maintenance.*/
168UNIV_INLINE170UNIV_INLINE
169void171void
170trx_search_latch_release_if_reserved(172trx_search_latch_release_if_reserved(
171/*=================================*/173/*=================================*/
172 trx_t* trx) /*!< in: transaction */174 trx_t* trx __attribute__((unused))) /*!< in: transaction */
173{175{
174 ulint i;176 ut_ad(!trx->has_search_latch);
175
176 for (i = 0; i < btr_search_index_num; i++) {
177 if (trx->has_search_latch & (1UL << i)) {
178 rw_lock_s_unlock(btr_search_latch_arr[i]);
179 }
180 }
181
182 trx->has_search_latch = 0;
183}177}
184
185178
=== modified file 'Percona-Server/storage/innobase/row/row0ftsort.cc'
--- Percona-Server/storage/innobase/row/row0ftsort.cc 2013-02-12 07:47:19 +0000
+++ Percona-Server/storage/innobase/row/row0ftsort.cc 2013-09-02 14:08:46 +0000
@@ -30,6 +30,7 @@
30#include "row0merge.h"30#include "row0merge.h"
31#include "row0row.h"31#include "row0row.h"
32#include "btr0cur.h"32#include "btr0cur.h"
33#include "btr0sea.h"
3334
34/** Read the next record to buffer N.35/** Read the next record to buffer N.
35@param N index into array of merge info structure */36@param N index into array of merge info structure */
@@ -87,6 +88,8 @@
87 new_index->n_def = FTS_NUM_FIELDS_SORT;88 new_index->n_def = FTS_NUM_FIELDS_SORT;
88 new_index->cached = TRUE;89 new_index->cached = TRUE;
8990
91 btr_search_index_init(new_index);
92
90 idx_field = dict_index_get_nth_field(index, 0);93 idx_field = dict_index_get_nth_field(index, 0);
91 charset = fts_index_get_charset(index);94 charset = fts_index_get_charset(index);
9295
9396
=== modified file 'Percona-Server/storage/innobase/row/row0sel.cc'
--- Percona-Server/storage/innobase/row/row0sel.cc 2013-08-29 17:05:40 +0000
+++ Percona-Server/storage/innobase/row/row0sel.cc 2013-09-02 14:08:46 +0000
@@ -1233,7 +1233,7 @@
1233 ut_ad(!plan->must_get_clust);1233 ut_ad(!plan->must_get_clust);
1234#ifdef UNIV_SYNC_DEBUG1234#ifdef UNIV_SYNC_DEBUG
1235 if (search_latch_locked) {1235 if (search_latch_locked) {
1236 ut_ad(rw_lock_own(btr_search_get_latch(index->id),1236 ut_ad(rw_lock_own(btr_search_get_latch(index),
1237 RW_LOCK_SHARED));1237 RW_LOCK_SHARED));
1238 }1238 }
1239#endif /* UNIV_SYNC_DEBUG */1239#endif /* UNIV_SYNC_DEBUG */
@@ -1406,10 +1406,10 @@
1406 && !plan->must_get_clust1406 && !plan->must_get_clust
1407 && !plan->table->big_rows) {1407 && !plan->table->big_rows) {
1408 if (!search_latch_locked) {1408 if (!search_latch_locked) {
1409 rw_lock_s_lock(btr_search_get_latch(index->id));1409 rw_lock_s_lock(btr_search_get_latch(index));
14101410
1411 search_latch_locked = TRUE;1411 search_latch_locked = TRUE;
1412 } else if (rw_lock_get_writer(btr_search_get_latch(index->id))1412 } else if (rw_lock_get_writer(btr_search_get_latch(index))
1413 == RW_LOCK_WAIT_EX) {1413 == RW_LOCK_WAIT_EX) {
14141414
1415 /* There is an x-latch request waiting: release the1415 /* There is an x-latch request waiting: release the
@@ -1419,8 +1419,8 @@
1419 from acquiring an s-latch for a long time, lowering1419 from acquiring an s-latch for a long time, lowering
1420 performance significantly in multiprocessors. */1420 performance significantly in multiprocessors. */
14211421
1422 rw_lock_s_unlock(btr_search_get_latch(index->id));1422 rw_lock_s_unlock(btr_search_get_latch(index));
1423 rw_lock_s_lock(btr_search_get_latch(index->id));1423 rw_lock_s_lock(btr_search_get_latch(index));
1424 }1424 }
14251425
1426 found_flag = row_sel_try_search_shortcut(node, plan,1426 found_flag = row_sel_try_search_shortcut(node, plan,
@@ -1445,7 +1445,7 @@
1445 }1445 }
14461446
1447 if (search_latch_locked) {1447 if (search_latch_locked) {
1448 rw_lock_s_unlock(btr_search_get_latch(index->id));1448 rw_lock_s_unlock(btr_search_get_latch(index));
14491449
1450 search_latch_locked = FALSE;1450 search_latch_locked = FALSE;
1451 }1451 }
@@ -2021,7 +2021,7 @@
20212021
2022func_exit:2022func_exit:
2023 if (search_latch_locked) {2023 if (search_latch_locked) {
2024 rw_lock_s_unlock(btr_search_get_latch(index->id));2024 rw_lock_s_unlock(btr_search_get_latch(index));
2025 }2025 }
2026 if (UNIV_LIKELY_NULL(heap)) {2026 if (UNIV_LIKELY_NULL(heap)) {
2027 mem_heap_free(heap);2027 mem_heap_free(heap);
@@ -2796,6 +2796,9 @@
2796 /* Copy an externally stored field to a temporary heap */2796 /* Copy an externally stored field to a temporary heap */
27972797
2798 ut_a(!prebuilt->trx->has_search_latch);2798 ut_a(!prebuilt->trx->has_search_latch);
2799#ifdef UNIV_SYNC_DEBUG
2800 ut_ad(!btr_search_own_any());
2801#endif
2799 ut_ad(field_no == templ->clust_rec_field_no);2802 ut_ad(field_no == templ->clust_rec_field_no);
28002803
2801 if (UNIV_UNLIKELY(templ->type == DATA_BLOB)) {2804 if (UNIV_UNLIKELY(templ->type == DATA_BLOB)) {
@@ -3468,11 +3471,11 @@
3468 ut_ad(!prebuilt->templ_contains_blob);3471 ut_ad(!prebuilt->templ_contains_blob);
34693472
3470#ifndef UNIV_SEARCH_DEBUG3473#ifndef UNIV_SEARCH_DEBUG
3474 ut_ad(trx->has_search_latch);
3475
3471 btr_pcur_open_with_no_init(index, search_tuple, PAGE_CUR_GE,3476 btr_pcur_open_with_no_init(index, search_tuple, PAGE_CUR_GE,
3472 BTR_SEARCH_LEAF, pcur,3477 BTR_SEARCH_LEAF, pcur,
3473 (trx->has_search_latch)3478 RW_S_LATCH,
3474 ? RW_S_LATCH
3475 : 0,
3476 mtr);3479 mtr);
3477#else /* UNIV_SEARCH_DEBUG */3480#else /* UNIV_SEARCH_DEBUG */
3478 btr_pcur_open_with_no_init(index, search_tuple, PAGE_CUR_GE,3481 btr_pcur_open_with_no_init(index, search_tuple, PAGE_CUR_GE,
@@ -3599,47 +3602,6 @@
3599}3602}
36003603
3601/********************************************************************//**3604/********************************************************************//**
3602Acquires an S latch for the adaptive hash index for a given index tree if is
3603not acquired already. If the current transaction already owns a latch with
3604a higher index in the latch array, release all the already-held S latches
3605and reacquire them together with the desired latch to honor the latching
3606order. */
3607static
3608void
3609trx_search_latch_lock(
3610/*==================*/
3611 trx_t* trx, /*!< in: latching transcation */
3612 ulint index_id) /*!< in: index to latch AHI for */
3613{
3614 ulint latch_mask = 1UL << (index_id % btr_search_index_num);
3615
3616 if (!(trx->has_search_latch & latch_mask)) {
3617
3618 if (trx->has_search_latch < latch_mask) {
3619
3620 rw_lock_s_lock(btr_search_get_latch(index_id));
3621 trx->has_search_latch |= latch_mask;
3622 } else {
3623
3624 ulint taken_latches = trx->has_search_latch;
3625
3626 trx_search_latch_release_if_reserved(trx);
3627
3628 trx->has_search_latch = taken_latches | latch_mask;
3629
3630 for (ulint i = 0; i < btr_search_index_num; i++) {
3631 if (trx->has_search_latch & (1UL << i)) {
3632
3633 rw_lock_s_lock(
3634 btr_search_latch_arr[i]);
3635 }
3636 }
3637 }
3638 }
3639}
3640
3641
3642/********************************************************************//**
3643Searches for rows in the database. This is used in the interface to3605Searches for rows in the database. This is used in the interface to
3644MySQL. This function opens a cursor, and also implements fetch next3606MySQL. This function opens a cursor, and also implements fetch next
3645and fetch prev. NOTE that if we do a search with a full key value3607and fetch prev. NOTE that if we do a search with a full key value
@@ -3701,7 +3663,6 @@
3701 ulint* offsets = offsets_;3663 ulint* offsets = offsets_;
3702 ibool table_lock_waited = FALSE;3664 ibool table_lock_waited = FALSE;
3703 byte* next_buf = 0;3665 byte* next_buf = 0;
3704 bool should_release;
37053666
3706 rec_offs_init(offsets_);3667 rec_offs_init(offsets_);
37073668
@@ -3715,7 +3676,9 @@
3715 return(DB_END_OF_INDEX);3676 return(DB_END_OF_INDEX);
3716 }3677 }
37173678
3679 ut_ad(!trx->has_search_latch);
3718#ifdef UNIV_SYNC_DEBUG3680#ifdef UNIV_SYNC_DEBUG
3681 ut_ad(!btr_search_own_any());
3719 ut_ad(!sync_thread_levels_nonempty_trx(trx->has_search_latch));3682 ut_ad(!sync_thread_levels_nonempty_trx(trx->has_search_latch));
3720#endif /* UNIV_SYNC_DEBUG */3683#endif /* UNIV_SYNC_DEBUG */
37213684
@@ -3776,33 +3739,6 @@
3776 fprintf(stderr, "N tables locked %lu\n",3739 fprintf(stderr, "N tables locked %lu\n",
3777 (ulong) trx->mysql_n_tables_locked);3740 (ulong) trx->mysql_n_tables_locked);
3778#endif3741#endif
3779 /*-------------------------------------------------------------*/
3780 /* PHASE 0: Release possible latches we are holding on the
3781 adaptive hash index latches if there is someone waiting behind */
3782
3783 should_release = false;
3784 for (ulint i = 0; i < btr_search_index_num; i++) {
3785 /* we should check all latches (fix Bug#791030) */
3786 if (UNIV_UNLIKELY(rw_lock_get_writer(btr_search_latch_arr[i])
3787 != RW_LOCK_NOT_LOCKED)) {
3788 should_release = true;
3789 break;
3790 }
3791 }
3792
3793 if (UNIV_UNLIKELY(should_release)) {
3794
3795 /* There is an x-latch request on the adaptive hash index:
3796 release the s-latch to reduce starvation and wait for
3797 BTR_SEA_TIMEOUT rounds before trying to keep it again over
3798 calls from MySQL */
3799
3800 /* We should release all s-latches (fix Bug#791030) */
3801 trx_search_latch_release_if_reserved(trx);
3802
3803 trx->search_latch_timeout = BTR_SEA_TIMEOUT;
3804 }
3805
3806 /* Reset the new record lock info if srv_locks_unsafe_for_binlog3742 /* Reset the new record lock info if srv_locks_unsafe_for_binlog
3807 is set or session is using a READ COMMITED isolation level. Then3743 is set or session is using a READ COMMITED isolation level. Then
3808 we are able to remove the record locks set here on an individual3744 we are able to remove the record locks set here on an individual
@@ -3949,7 +3885,9 @@
3949 hash index semaphore! */3885 hash index semaphore! */
39503886
3951#ifndef UNIV_SEARCH_DEBUG3887#ifndef UNIV_SEARCH_DEBUG
3952 trx_search_latch_lock(trx, index->id);3888 ut_ad(!trx->has_search_latch);
3889 rw_lock_s_lock(btr_search_get_latch(index));
3890 trx->has_search_latch = TRUE;
3953#endif3891#endif
3954 switch (row_sel_try_search_shortcut_for_mysql(3892 switch (row_sel_try_search_shortcut_for_mysql(
3955 &rec, prebuilt, &offsets, &heap,3893 &rec, prebuilt, &offsets, &heap,
@@ -4003,7 +3941,7 @@
4003 fputs(" shortcut\n", stderr); */3941 fputs(" shortcut\n", stderr); */
40043942
4005 err = DB_SUCCESS;3943 err = DB_SUCCESS;
4006 goto release_search_latch_if_needed;3944 goto release_search_latch;
40073945
4008 case SEL_EXHAUSTED:3946 case SEL_EXHAUSTED:
4009 shortcut_mismatch:3947 shortcut_mismatch:
@@ -4013,15 +3951,10 @@
4013 fputs(" record not found 2\n", stderr); */3951 fputs(" record not found 2\n", stderr); */
40143952
4015 err = DB_RECORD_NOT_FOUND;3953 err = DB_RECORD_NOT_FOUND;
4016release_search_latch_if_needed:3954release_search_latch:
4017 if (trx->search_latch_timeout > 03955 rw_lock_s_unlock(
4018 && trx->has_search_latch) {3956 btr_search_get_latch(index));
40193957 trx->has_search_latch = FALSE;
4020 trx->search_latch_timeout--;
4021
4022 trx_search_latch_release_if_reserved(
4023 trx);
4024 }
40253958
4026 /* NOTE that we do NOT store the cursor3959 /* NOTE that we do NOT store the cursor
4027 position */3960 position */
@@ -4036,13 +3969,19 @@
40363969
4037 mtr_commit(&mtr);3970 mtr_commit(&mtr);
4038 mtr_start(&mtr);3971 mtr_start(&mtr);
3972
3973 rw_lock_s_unlock(btr_search_get_latch(index));
3974 trx->has_search_latch = FALSE;
4039 }3975 }
4040 }3976 }
40413977
4042 /*-------------------------------------------------------------*/3978 /*-------------------------------------------------------------*/
4043 /* PHASE 3: Open or restore index cursor position */3979 /* PHASE 3: Open or restore index cursor position */
40443980
4045 trx_search_latch_release_if_reserved(trx);3981 ut_ad(!trx->has_search_latch);
3982#ifdef UNIV_SYNC_DEBUG
3983 ut_ad(!btr_search_own_any());
3984#endif
40463985
4047 /* The state of a running trx can only be changed by the3986 /* The state of a running trx can only be changed by the
4048 thread that is currently serving the transaction. Because we3987 thread that is currently serving the transaction. Because we
@@ -5184,7 +5123,9 @@
5184 }5123 }
5185 }5124 }
51865125
5126 ut_ad(!trx->has_search_latch);
5187#ifdef UNIV_SYNC_DEBUG5127#ifdef UNIV_SYNC_DEBUG
5128 ut_ad(!btr_search_own_any());
5188 ut_ad(!sync_thread_levels_nonempty_trx(trx->has_search_latch));5129 ut_ad(!sync_thread_levels_nonempty_trx(trx->has_search_latch));
5189#endif /* UNIV_SYNC_DEBUG */5130#endif /* UNIV_SYNC_DEBUG */
51905131
51915132
=== modified file 'Percona-Server/storage/innobase/srv/srv0srv.cc'
--- Percona-Server/storage/innobase/srv/srv0srv.cc 2013-08-29 17:05:40 +0000
+++ Percona-Server/storage/innobase/srv/srv0srv.cc 2013-09-02 14:08:46 +0000
@@ -1182,7 +1182,8 @@
1182 ulint n_reserved;1182 ulint n_reserved;
1183 ibool ret;1183 ibool ret;
11841184
1185 ulint btr_search_sys_subtotal;1185 ulong btr_search_sys_constant;
1186 ulong btr_search_sys_variable;
1186 ulint lock_sys_subtotal;1187 ulint lock_sys_subtotal;
1187 ulint recv_sys_subtotal;1188 ulint recv_sys_subtotal;
11881189
@@ -1307,21 +1308,27 @@
1307 "Total memory allocated by read views " ULINTPF "\n",1308 "Total memory allocated by read views " ULINTPF "\n",
1308 os_atomic_increment_lint(&srv_read_views_memory, 0));1309 os_atomic_increment_lint(&srv_read_views_memory, 0));
13091310
1310 /* Calculate reserved memories */1311 /* Calculate AHI constant and variable memory allocations */
1311 if (btr_search_sys && btr_search_sys->hash_index[0]->heap) {1312
1312 btr_search_sys_subtotal1313 btr_search_sys_constant = 0;
1313 = mem_heap_get_size(btr_search_sys->hash_index[0]1314 btr_search_sys_variable = 0;
1314 ->heap);1315
1315 } else {1316 ut_ad(btr_search_sys->hash_tables);
1316 btr_search_sys_subtotal = 0;1317
1317 for (i=0; i < btr_search_sys->hash_index[0]->n_sync_obj; i++) {1318 for (i = 0; i < btr_search_index_num; i++) {
1318 btr_search_sys_subtotal1319 hash_table_t* ht = btr_search_sys->hash_tables[i];
1319 += mem_heap_get_size(1320
1320 btr_search_sys->hash_index[0]1321 ut_ad(ht);
1321 ->heaps[i]);1322 ut_ad(ht->heap);
1322 }1323
1324 /* Multiple mutexes/heaps are currently never used for adaptive
1325 hash index tables. */
1326 ut_ad(!ht->n_sync_obj);
1327 ut_ad(!ht->heaps);
1328
1329 btr_search_sys_variable += mem_heap_get_size(ht->heap);
1330 btr_search_sys_constant += ht->n_cells * sizeof(hash_cell_t);
1323 }1331 }
1324 btr_search_sys_subtotal *= btr_search_index_num;
13251332
1326 lock_sys_subtotal = 0;1333 lock_sys_subtotal = 0;
1327 if (trx_sys) {1334 if (trx_sys) {
@@ -1349,18 +1356,9 @@
1349 " Lock system %lu \t(%lu + " ULINTPF ")\n"1356 " Lock system %lu \t(%lu + " ULINTPF ")\n"
1350 " Recovery system %lu \t(%lu + " ULINTPF ")\n",1357 " Recovery system %lu \t(%lu + " ULINTPF ")\n",
13511358
1352 (ulong) (btr_search_sys1359 btr_search_sys_constant + btr_search_sys_variable,
1353 ? (btr_search_sys->hash_index[0]->n_cells1360 btr_search_sys_constant,
1354 * sizeof(hash_cell_t)1361 btr_search_sys_variable,
1355 * btr_search_index_num)
1356 : 0)
1357 + btr_search_sys_subtotal,
1358 (ulong) (btr_search_sys
1359 ? (btr_search_sys->hash_index[0]->n_cells
1360 * sizeof(hash_cell_t)
1361 * btr_search_index_num)
1362 : 0),
1363 btr_search_sys_subtotal,
13641362
1365 (ulong) (buf_pool_from_array(0)->page_hash->n_cells * sizeof(hash_cell_t)),1363 (ulong) (buf_pool_from_array(0)->page_hash->n_cells * sizeof(hash_cell_t)),
13661364
@@ -1509,23 +1507,23 @@
1509 buf_get_total_list_len(&LRU_len, &free_len, &flush_list_len);1507 buf_get_total_list_len(&LRU_len, &free_len, &flush_list_len);
1510 buf_get_total_list_size_in_bytes(&buf_pools_list_size);1508 buf_get_total_list_size_in_bytes(&buf_pools_list_size);
15111509
1512 if (btr_search_sys && btr_search_sys->hash_index[0]->heap) {1510 mem_adaptive_hash = 0;
1513 mem_adaptive_hash1511
1514 = mem_heap_get_size(btr_search_sys1512 ut_ad(btr_search_sys->hash_tables);
1515 ->hash_index[0]->heap);1513
1516 } else {1514 for (i = 0; i < btr_search_index_num; i++) {
1517 mem_adaptive_hash = 0;1515 hash_table_t* ht = btr_search_sys->hash_tables[i];
1518 for (i=0; i < btr_search_sys->hash_index[0]->n_sync_obj; i++) {1516
1519 mem_adaptive_hash1517 ut_ad(ht);
1520 += mem_heap_get_size1518 ut_ad(ht->heap);
1521 (btr_search_sys->hash_index[0]->heaps[i]);1519 /* Multiple mutexes/heaps are currently never used for adaptive
1522 }1520 hash index tables. */
1523 }1521 ut_ad(!ht->n_sync_obj);
1524 if (btr_search_sys) {1522 ut_ad(!ht->heaps);
1525 mem_adaptive_hash += (btr_search_sys->hash_index[0]->n_cells1523
1526 * sizeof(hash_cell_t));1524 mem_adaptive_hash += mem_heap_get_size(ht->heap);
1527 }1525 mem_adaptive_hash += ht->n_cells * sizeof(hash_cell_t);
1528 mem_adaptive_hash *= btr_search_index_num;1526 }
15291527
1530 mem_dictionary = (dict_sys ? ((dict_sys->table_hash->n_cells1528 mem_dictionary = (dict_sys ? ((dict_sys->table_hash->n_cells
1531 + dict_sys->table_id_hash->n_cells1529 + dict_sys->table_id_hash->n_cells
15321530
=== modified file 'Percona-Server/storage/innobase/sync/sync0sync.cc'
--- Percona-Server/storage/innobase/sync/sync0sync.cc 2013-08-29 17:05:40 +0000
+++ Percona-Server/storage/innobase/sync/sync0sync.cc 2013-09-02 14:08:46 +0000
@@ -1187,12 +1187,12 @@
1187 array */1187 array */
1188 bool found_current = false;1188 bool found_current = false;
1189 for (ulint i = 0; i < btr_search_index_num; i++) {1189 for (ulint i = 0; i < btr_search_index_num; i++) {
1190 if (btr_search_latch_arr[i] == latch) {1190 if (&btr_search_latch_arr[i] == latch) {
1191 found_current = true;1191 found_current = true;
1192 } else if (found_current) {1192 } else if (found_current) {
1193 ut_ad(!rw_lock_own(btr_search_latch_arr[i],1193 ut_ad(!rw_lock_own(&btr_search_latch_arr[i],
1194 RW_LOCK_SHARED));1194 RW_LOCK_SHARED));
1195 ut_ad(!rw_lock_own(btr_search_latch_arr[i],1195 ut_ad(!rw_lock_own(&btr_search_latch_arr[i],
1196 RW_LOCK_EX));1196 RW_LOCK_EX));
1197 }1197 }
1198 }1198 }
11991199
=== modified file 'Percona-Server/storage/innobase/trx/trx0trx.cc'
--- Percona-Server/storage/innobase/trx/trx0trx.cc 2013-08-29 17:05:40 +0000
+++ Percona-Server/storage/innobase/trx/trx0trx.cc 2013-09-02 14:08:46 +0000
@@ -360,6 +360,9 @@
360 ut_a(trx->lock.wait_thr == NULL);360 ut_a(trx->lock.wait_thr == NULL);
361361
362 ut_a(!trx->has_search_latch);362 ut_a(!trx->has_search_latch);
363#ifdef UNIV_SYNC_DEBUG
364 ut_ad(!btr_search_own_any());
365#endif
363366
364 ut_a(trx->dict_operation_lock_mode == 0);367 ut_a(trx->dict_operation_lock_mode == 0);
365368

Subscribers

People subscribed via source and target branches