~percona-core/percona-server/5.5

« back to all changes in this revision

Viewing changes to Percona-Server/storage/innobase/btr/btr0sea.c

  • Committer: Laurynas Biveinis
  • Date: 2013-09-06 13:24:59 UTC
  • mfrom: (558.8.3 5.5)
  • Revision ID: laurynas.biveinis@percona.com-20130906132459-jfaquw8dbwluzbsl
MergeĀ lp:~akopytov/percona-server/ahi-fixes-5.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
cache line as btr_search_latch */
70
70
UNIV_INTERN byte                btr_sea_pad1[64];
71
71
 
72
 
/** The latch protecting the adaptive search system: this latch protects the
73
 
(1) positions of records on those pages where a hash index has been built.
74
 
NOTE: It does not protect values of non-ordering fields within a record from
 
72
/** Array of latches protecting individual AHI partitions. The latches
 
73
protect: (1) positions of records on those pages where a hash index from the
 
74
corresponding AHI partition has been built.
 
75
NOTE: They do not protect values of non-ordering fields within a record from
75
76
being updated in-place! We can use fact (1) to perform unique searches to
76
77
indexes. */
77
78
 
78
 
/* We will allocate the latch from dynamic memory to get it to the
79
 
same DRAM page as other hotspot semaphores */
80
 
//UNIV_INTERN rw_lock_t*                btr_search_latch_temp;
81
 
 
82
 
UNIV_INTERN rw_lock_t**         btr_search_latch_part;
 
79
UNIV_INTERN rw_lock_t*          btr_search_latch_arr;
83
80
 
84
81
/** padding to prevent other memory update hotspots from residing on
85
82
the same memory cache line */
133
130
void
134
131
btr_search_check_free_space_in_heap(
135
132
/*=====================================*/
136
 
        index_id_t      key)
 
133
        dict_index_t*   index)
137
134
{
138
135
        hash_table_t*   table;
139
136
        mem_heap_t*     heap;
140
137
 
141
138
#ifdef UNIV_SYNC_DEBUG
142
 
        ut_ad(!rw_lock_own(btr_search_get_latch(key), RW_LOCK_SHARED));
143
 
        ut_ad(!rw_lock_own(btr_search_get_latch(key), RW_LOCK_EX));
 
139
        ut_ad(!rw_lock_own(btr_search_get_latch(index), RW_LOCK_SHARED));
 
140
        ut_ad(!rw_lock_own(btr_search_get_latch(index), RW_LOCK_EX));
144
141
#endif /* UNIV_SYNC_DEBUG */
145
142
 
146
 
        table = btr_search_get_hash_index(key);
 
143
        table = btr_search_get_hash_table(index);
147
144
 
148
145
        heap = table->heap;
149
146
 
154
151
        if (heap->free_block == NULL) {
155
152
                buf_block_t*    block = buf_block_alloc(NULL);
156
153
 
157
 
                rw_lock_x_lock(btr_search_get_latch(key));
 
154
                rw_lock_x_lock(btr_search_get_latch(index));
158
155
 
159
156
                if (heap->free_block == NULL) {
160
157
                        heap->free_block = block;
162
159
                        buf_block_free(block);
163
160
                }
164
161
 
165
 
                rw_lock_x_unlock(btr_search_get_latch(key));
 
162
                rw_lock_x_unlock(btr_search_get_latch(index));
166
163
        }
167
164
}
168
165
 
194
191
 
195
192
        btr_search_sys = mem_alloc(sizeof(btr_search_sys_t));
196
193
 
197
 
        /* btr_search_index_num should be <= 32. (bits of trx->has_search_latch) */
198
 
        btr_search_latch_part = mem_alloc(sizeof(rw_lock_t*) * btr_search_index_num);
199
 
        btr_search_sys->hash_index = mem_alloc(sizeof(hash_table_t*) * btr_search_index_num);
 
194
        /* btr_search_index_num is constrained to machine word size for
 
195
        historical reasons. This limitation can be easily removed later. */
 
196
 
 
197
        btr_search_latch_arr = mem_alloc(sizeof(rw_lock_t) *
 
198
                                         btr_search_index_num);
 
199
        btr_search_sys->hash_tables = mem_alloc(sizeof(hash_table_t *) *
 
200
                                                btr_search_index_num);
200
201
        for (i = 0; i < btr_search_index_num; i++) {
201
 
                btr_search_latch_part[i] = mem_alloc(sizeof(rw_lock_t));
202
202
 
203
203
                rw_lock_create(btr_search_latch_key,
204
 
                                btr_search_latch_part[i], SYNC_SEARCH_SYS);
 
204
                                &btr_search_latch_arr[i], SYNC_SEARCH_SYS);
205
205
 
206
 
                btr_search_sys->hash_index[i] = ha_create(hash_size, 0, 0);
 
206
                btr_search_sys->hash_tables[i] = ha_create(hash_size, 0, 0);
207
207
        }
208
208
}
209
209
 
217
217
        ulint i;
218
218
 
219
219
        for (i = 0; i < btr_search_index_num; i++) {
220
 
                mem_heap_free(btr_search_sys->hash_index[i]->heap);
221
 
                hash_table_free(btr_search_sys->hash_index[i]);
222
 
 
223
 
                rw_lock_free(btr_search_latch_part[i]);
224
 
 
225
 
                mem_free(btr_search_latch_part[i]);
 
220
                mem_heap_free(btr_search_sys->hash_tables[i]->heap);
 
221
                hash_table_free(btr_search_sys->hash_tables[i]);
 
222
 
 
223
                rw_lock_free(&btr_search_latch_arr[i]);
226
224
        }
227
 
        mem_free(btr_search_sys->hash_index);
228
 
        mem_free(btr_search_latch_part);
 
225
        mem_free(btr_search_sys->hash_tables);
 
226
        mem_free(btr_search_latch_arr);
229
227
 
230
228
        //rw_lock_free(&btr_search_latch);
231
229
        //mem_free(btr_search_latch_temp);
270
268
 
271
269
        /* Clear the adaptive hash index. */
272
270
        for (i = 0; i < btr_search_index_num; i++) {
273
 
                hash_table_clear(btr_search_sys->hash_index[i]);
274
 
                mem_heap_empty(btr_search_sys->hash_index[i]->heap);
 
271
                hash_table_clear(btr_search_sys->hash_tables[i]);
 
272
                mem_heap_empty(btr_search_sys->hash_tables[i]->heap);
275
273
        }
276
274
 
277
275
        btr_search_x_unlock_all();
334
332
 
335
333
/*****************************************************************//**
336
334
Returns the value of ref_count. The value is protected by
337
 
btr_search_latch.
 
335
the latch of the AHI partition corresponding to this index.
338
336
@return ref_count value. */
339
337
UNIV_INTERN
340
338
ulint
341
339
btr_search_info_get_ref_count(
342
340
/*==========================*/
343
341
        btr_search_t*   info,   /*!< in: search info. */
344
 
        index_id_t      key)
 
342
        dict_index_t*   index)  /*!< in: index */
345
343
{
346
344
        ulint ret;
347
345
 
348
346
        ut_ad(info);
349
347
 
350
348
#ifdef UNIV_SYNC_DEBUG
351
 
        ut_ad(!rw_lock_own(btr_search_get_latch(key), RW_LOCK_SHARED));
352
 
        ut_ad(!rw_lock_own(btr_search_get_latch(key), RW_LOCK_EX));
 
349
        ut_ad(!rw_lock_own(btr_search_get_latch(index), RW_LOCK_SHARED));
 
350
        ut_ad(!rw_lock_own(btr_search_get_latch(index), RW_LOCK_EX));
353
351
#endif /* UNIV_SYNC_DEBUG */
354
352
 
355
 
        rw_lock_s_lock(btr_search_get_latch(key));
 
353
        rw_lock_s_lock(btr_search_get_latch(index));
356
354
        ret = info->ref_count;
357
 
        rw_lock_s_unlock(btr_search_get_latch(key));
 
355
        rw_lock_s_unlock(btr_search_get_latch(index));
358
356
 
359
357
        return(ret);
360
358
}
375
373
        int             cmp;
376
374
 
377
375
#ifdef UNIV_SYNC_DEBUG
378
 
        ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index->id), RW_LOCK_SHARED));
379
 
        ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index->id), RW_LOCK_EX));
 
376
        ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index), RW_LOCK_SHARED));
 
377
        ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index), RW_LOCK_EX));
380
378
#endif /* UNIV_SYNC_DEBUG */
381
379
 
382
380
        index = cursor->index;
494
492
                                /*!< in: cursor */
495
493
{
496
494
#ifdef UNIV_SYNC_DEBUG
497
 
        ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index->id), RW_LOCK_SHARED));
498
 
        ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index->id), RW_LOCK_EX));
 
495
        ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index), RW_LOCK_SHARED));
 
496
        ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index), RW_LOCK_EX));
499
497
        ut_ad(rw_lock_own(&block->lock, RW_LOCK_SHARED)
500
498
              || rw_lock_own(&block->lock, RW_LOCK_EX));
501
499
#endif /* UNIV_SYNC_DEBUG */
579
577
 
580
578
        ut_ad(cursor->flag == BTR_CUR_HASH_FAIL);
581
579
#ifdef UNIV_SYNC_DEBUG
582
 
        ut_ad(rw_lock_own(btr_search_get_latch(cursor->index->id), RW_LOCK_EX));
 
580
        ut_ad(rw_lock_own(btr_search_get_latch(cursor->index), RW_LOCK_EX));
583
581
        ut_ad(rw_lock_own(&(block->lock), RW_LOCK_SHARED)
584
582
              || rw_lock_own(&(block->lock), RW_LOCK_EX));
585
583
#endif /* UNIV_SYNC_DEBUG */
620
618
                        mem_heap_free(heap);
621
619
                }
622
620
#ifdef UNIV_SYNC_DEBUG
623
 
                ut_ad(rw_lock_own(btr_search_get_latch(cursor->index->id), RW_LOCK_EX));
 
621
                ut_ad(rw_lock_own(btr_search_get_latch(cursor->index),
 
622
                                  RW_LOCK_EX));
624
623
#endif /* UNIV_SYNC_DEBUG */
625
624
 
626
 
                ha_insert_for_fold(btr_search_get_hash_index(cursor->index->id), fold,
627
 
                                   block, rec);
 
625
                ha_insert_for_fold(btr_search_get_hash_table(cursor->index),
 
626
                                   fold, block, rec);
628
627
        }
629
628
}
630
629
 
643
642
        ulint*          params2;
644
643
 
645
644
#ifdef UNIV_SYNC_DEBUG
646
 
        ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index->id), RW_LOCK_SHARED));
647
 
        ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index->id), RW_LOCK_EX));
 
645
        ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index), RW_LOCK_SHARED));
 
646
        ut_ad(!rw_lock_own(btr_search_get_latch(cursor->index), RW_LOCK_EX));
648
647
#endif /* UNIV_SYNC_DEBUG */
649
648
 
650
649
        block = btr_cur_get_block(cursor);
662
661
 
663
662
        if (build_index || (cursor->flag == BTR_CUR_HASH_FAIL)) {
664
663
 
665
 
                btr_search_check_free_space_in_heap(cursor->index->id);
 
664
                btr_search_check_free_space_in_heap(cursor->index);
666
665
        }
667
666
 
668
667
        if (cursor->flag == BTR_CUR_HASH_FAIL) {
672
671
                btr_search_n_hash_fail++;
673
672
#endif /* UNIV_SEARCH_PERF_STAT */
674
673
 
675
 
                rw_lock_x_lock(btr_search_get_latch(cursor->index->id));
 
674
                rw_lock_x_lock(btr_search_get_latch(cursor->index));
676
675
 
677
676
                btr_search_update_hash_ref(info, block, cursor);
678
677
 
679
 
                rw_lock_x_unlock(btr_search_get_latch(cursor->index->id));
 
678
                rw_lock_x_unlock(btr_search_get_latch(cursor->index));
680
679
        }
681
680
 
682
681
        if (build_index) {
921
920
        cursor->flag = BTR_CUR_HASH;
922
921
 
923
922
        if (UNIV_LIKELY(!has_search_latch)) {
924
 
                rw_lock_s_lock(btr_search_get_latch(index_id));
 
923
                rw_lock_s_lock(btr_search_get_latch(index));
925
924
 
926
925
                if (UNIV_UNLIKELY(!btr_search_enabled)) {
927
926
                        goto failure_unlock;
928
927
                }
929
928
        }
930
929
 
931
 
        ut_ad(rw_lock_get_writer(btr_search_get_latch(index_id)) != RW_LOCK_EX);
932
 
        ut_ad(rw_lock_get_reader_count(btr_search_get_latch(index_id)) > 0);
 
930
        ut_ad(rw_lock_get_writer(btr_search_get_latch(index)) != RW_LOCK_EX);
 
931
        ut_ad(rw_lock_get_reader_count(btr_search_get_latch(index)) > 0);
933
932
 
934
 
        rec = ha_search_and_get_data(btr_search_get_hash_index(index_id), fold);
 
933
        rec = ha_search_and_get_data(btr_search_get_hash_table(index), fold);
935
934
 
936
935
        if (UNIV_UNLIKELY(!rec)) {
937
936
                goto failure_unlock;
949
948
                        goto failure_unlock;
950
949
                }
951
950
 
952
 
                rw_lock_s_unlock(btr_search_get_latch(index_id));
 
951
                rw_lock_s_unlock(btr_search_get_latch(index));
953
952
 
954
953
                buf_block_dbg_add_level(block, SYNC_TREE_NODE_FROM_HASH);
955
954
        }
1046
1045
        /*-------------------------------------------*/
1047
1046
failure_unlock:
1048
1047
        if (UNIV_LIKELY(!has_search_latch)) {
1049
 
                rw_lock_s_unlock(btr_search_get_latch(index_id));
 
1048
                rw_lock_s_unlock(btr_search_get_latch(index));
1050
1049
        }
1051
1050
failure:
1052
1051
        cursor->flag = BTR_CUR_HASH_FAIL;
1091
1090
        ulint*                  offsets;
1092
1091
 
1093
1092
retry:
1094
 
        if (btr_search_index_num > 1) {
1095
 
                rw_lock_t*      btr_search_latch;
1096
 
 
1097
 
                /* FIXME: This may be optimistic implementation still. */
1098
 
                btr_search_latch = (rw_lock_t*)(block->btr_search_latch);
1099
 
                if (UNIV_LIKELY(!btr_search_latch)) {
1100
 
                        if (block->index) {
1101
 
                                goto retry;
1102
 
                        }
1103
 
                        return;
1104
 
                }
1105
 
                rw_lock_s_lock(btr_search_latch);
1106
 
                if (UNIV_LIKELY(btr_search_latch != block->btr_search_latch)) {
1107
 
                        rw_lock_s_unlock(btr_search_latch);
1108
 
                        goto retry;
1109
 
                }
1110
 
                if (UNIV_LIKELY(!block->index)) {
1111
 
                        rw_lock_s_unlock(btr_search_latch);
1112
 
                        goto retry;
1113
 
                }
1114
 
                index = block->index;
1115
 
                ut_a(btr_search_latch == btr_search_get_latch(index->id));
1116
 
        } else {
1117
 
                /* btr_search_index_num == 1 */
1118
 
                /* btr_search_latch is only one and able to obtain
1119
 
                   before evaluating block->index. */
1120
 
                rw_lock_s_lock(btr_search_latch_part[0]);
1121
 
                if (UNIV_LIKELY(!block->index)) {
1122
 
                        rw_lock_s_unlock(btr_search_latch_part[0]);
1123
 
                        return;
1124
 
                }
1125
 
                index = block->index;
1126
 
        }
1127
 
 
1128
 
        if (UNIV_LIKELY(!index)) {
1129
 
 
1130
 
                rw_lock_s_unlock(btr_search_get_latch(index->id));
 
1093
        /* Do a dirty check on block->index, return if the block is not in the
 
1094
        adaptive hash index. This is to avoid acquiring an AHI latch for
 
1095
        performance considerations. */
 
1096
 
 
1097
        index = block->index;
 
1098
        if (!index) {
1131
1099
 
1132
1100
                return;
1133
1101
        }
1134
1102
 
1135
 
        table = btr_search_get_hash_index(index->id);
 
1103
        rw_lock_s_lock(btr_search_get_latch(index));
 
1104
 
 
1105
        if (UNIV_UNLIKELY(index != block->index)) {
 
1106
 
 
1107
                rw_lock_s_unlock(btr_search_get_latch(index));
 
1108
 
 
1109
                goto retry;
 
1110
        }
 
1111
 
 
1112
        table = btr_search_get_hash_table(index);
1136
1113
 
1137
1114
#ifdef UNIV_SYNC_DEBUG
1138
1115
        ut_ad(rw_lock_own(&(block->lock), RW_LOCK_SHARED)
1149
1126
        releasing btr_search_latch, as the index page might only
1150
1127
        be s-latched! */
1151
1128
 
1152
 
        rw_lock_s_unlock(btr_search_get_latch(index->id));
 
1129
        rw_lock_s_unlock(btr_search_get_latch(index));
1153
1130
 
1154
1131
        ut_a(n_fields + n_bytes > 0);
1155
1132
 
1200
1177
                mem_heap_free(heap);
1201
1178
        }
1202
1179
 
1203
 
        rw_lock_x_lock(btr_search_get_latch(index->id));
 
1180
        rw_lock_x_lock(btr_search_get_latch(index));
1204
1181
 
1205
1182
        if (UNIV_UNLIKELY(!block->index)) {
1206
1183
                /* Someone else has meanwhile dropped the hash index */
1216
1193
                /* Someone else has meanwhile built a new hash index on the
1217
1194
                page, with different parameters */
1218
1195
 
1219
 
                rw_lock_x_unlock(btr_search_get_latch(index->id));
 
1196
                rw_lock_x_unlock(btr_search_get_latch(index));
1220
1197
 
1221
1198
                mem_free(folds);
1222
1199
                goto retry;
1231
1208
        index->search_info->ref_count--;
1232
1209
 
1233
1210
        block->index = NULL;
1234
 
        block->btr_search_latch = NULL;
1235
1211
 
1236
1212
cleanup:
1237
1213
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
1244
1220
                        "InnoDB: the hash index to a page of %s,"
1245
1221
                        " still %lu hash nodes remain.\n",
1246
1222
                        index->name, (ulong) block->n_pointers);
1247
 
                rw_lock_x_unlock(btr_search_get_latch(index->id));
 
1223
                rw_lock_x_unlock(btr_search_get_latch(index));
1248
1224
 
1249
1225
                ut_ad(btr_search_validate());
1250
1226
        } else {
1251
 
                rw_lock_x_unlock(btr_search_get_latch(index->id));
 
1227
                rw_lock_x_unlock(btr_search_get_latch(index));
1252
1228
        }
1253
1229
#else /* UNIV_AHI_DEBUG || UNIV_DEBUG */
1254
 
        rw_lock_x_unlock(btr_search_get_latch(index->id));
 
1230
        rw_lock_x_unlock(btr_search_get_latch(index));
1255
1231
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
1256
1232
 
1257
1233
        mem_free(folds);
1283
1259
        ulint*          offsets;
1284
1260
        ibool           released_search_latch;
1285
1261
 
1286
 
        rw_lock_s_lock(btr_search_get_latch(index->id));
 
1262
        rw_lock_s_lock(btr_search_get_latch(index));
1287
1263
 
1288
 
        table = btr_search_get_hash_index(index->id);
 
1264
        table = btr_search_get_hash_table(index);
1289
1265
 
1290
1266
        for (j = 0; j < srv_buf_pool_instances; j++) {
1291
1267
                buf_pool_t*     buf_pool;
1319
1295
 
1320
1296
 
1321
1297
                                        /* keeping latch order */
1322
 
                                        rw_lock_s_unlock(btr_search_get_latch(index->id));
 
1298
                                        rw_lock_s_unlock(
 
1299
                                                btr_search_get_latch(index));
1323
1300
                                        released_search_latch = TRUE;
1324
1301
                                        rw_lock_x_lock(&block->lock);
1325
1302
 
1371
1348
                                                mem_heap_empty(heap);
1372
1349
                                        }
1373
1350
 
1374
 
                                        rw_lock_x_lock(btr_search_get_latch(index->id));
 
1351
                                        rw_lock_x_lock(
 
1352
                                                btr_search_get_latch(index));
1375
1353
 
1376
1354
                                        if (UNIV_UNLIKELY(!block->index)) {
1377
1355
                                                goto cleanup;
1381
1359
 
1382
1360
                                        if (UNIV_UNLIKELY(block->curr_n_fields != n_fields)
1383
1361
                                            || UNIV_UNLIKELY(block->curr_n_bytes != n_bytes)) {
1384
 
                                                rw_lock_x_unlock(btr_search_get_latch(index->id));
 
1362
                                                rw_lock_x_unlock(
 
1363
                                                        btr_search_get_latch(index));
1385
1364
                                                rw_lock_x_unlock(&block->lock);
1386
1365
 
1387
1366
                                                mem_free(folds);
1388
1367
 
1389
 
                                                rw_lock_s_lock(btr_search_get_latch(index->id));
 
1368
                                                rw_lock_s_lock(
 
1369
                                                        btr_search_get_latch(index));
1390
1370
                                                goto retry;
1391
1371
                                        }
1392
1372
 
1399
1379
                                        index->search_info->ref_count--;
1400
1380
 
1401
1381
                                        block->index = NULL;
1402
 
                                        block->btr_search_latch = NULL;
1403
1382
 
1404
1383
cleanup:
1405
1384
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
1412
1391
                                                        index->name, (ulong) block->n_pointers);
1413
1392
                                        }
1414
1393
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
1415
 
                                        rw_lock_x_unlock(btr_search_get_latch(index->id));
 
1394
                                        rw_lock_x_unlock(
 
1395
                                                btr_search_get_latch(index));
1416
1396
                                        rw_lock_x_unlock(&block->lock);
1417
1397
 
1418
1398
                                        mem_free(folds);
1419
1399
 
1420
 
                                        rw_lock_s_lock(btr_search_get_latch(index->id));
 
1400
                                        rw_lock_s_lock(
 
1401
                                                btr_search_get_latch(index));
1421
1402
                                }
1422
1403
                        }
1423
1404
                } while (released_search_latch);
1424
1405
        }
1425
1406
 
1426
 
        rw_lock_s_unlock(btr_search_get_latch(index->id));
 
1407
        rw_lock_s_unlock(btr_search_get_latch(index));
1427
1408
 
1428
1409
        if (UNIV_LIKELY_NULL(heap)) {
1429
1410
                mem_heap_free(heap);
1502
1483
        ut_ad(index);
1503
1484
        ut_a(!dict_index_is_ibuf(index));
1504
1485
 
1505
 
        table = btr_search_get_hash_index(index->id);
 
1486
        table = btr_search_get_hash_table(index);
1506
1487
        page = buf_block_get_frame(block);
1507
1488
 
1508
1489
#ifdef UNIV_SYNC_DEBUG
1511
1492
              || rw_lock_own(&(block->lock), RW_LOCK_EX));
1512
1493
#endif /* UNIV_SYNC_DEBUG */
1513
1494
 
1514
 
        rw_lock_s_lock(btr_search_get_latch(index->id));
 
1495
        rw_lock_s_lock(btr_search_get_latch(index));
1515
1496
 
1516
1497
        if (block->index && ((block->curr_n_fields != n_fields)
1517
1498
                                 || (block->curr_n_bytes != n_bytes)
1518
1499
                                 || (block->curr_left_side != left_side))) {
1519
1500
 
1520
 
                rw_lock_s_unlock(btr_search_get_latch(index->id));
 
1501
                rw_lock_s_unlock(btr_search_get_latch(index));
1521
1502
 
1522
1503
                btr_search_drop_page_hash_index(block);
1523
1504
        } else {
1524
 
                rw_lock_s_unlock(btr_search_get_latch(index->id));
 
1505
                rw_lock_s_unlock(btr_search_get_latch(index));
1525
1506
        }
1526
1507
 
1527
1508
        n_recs = page_get_n_recs(page);
1615
1596
                fold = next_fold;
1616
1597
        }
1617
1598
 
1618
 
        btr_search_check_free_space_in_heap(index->id);
 
1599
        btr_search_check_free_space_in_heap(index);
1619
1600
 
1620
 
        rw_lock_x_lock(btr_search_get_latch(index->id));
 
1601
        rw_lock_x_lock(btr_search_get_latch(index));
1621
1602
 
1622
1603
        if (UNIV_UNLIKELY(!btr_search_enabled)) {
1623
1604
                goto exit_func;
1644
1625
        block->curr_n_bytes = n_bytes;
1645
1626
        block->curr_left_side = left_side;
1646
1627
        block->index = index;
1647
 
        block->btr_search_latch = btr_search_get_latch(index->id);
1648
1628
 
1649
1629
        for (i = 0; i < n_cached; i++) {
1650
1630
 
1652
1632
        }
1653
1633
 
1654
1634
exit_func:
1655
 
        rw_lock_x_unlock(btr_search_get_latch(index->id));
 
1635
        rw_lock_x_unlock(btr_search_get_latch(index));
1656
1636
 
1657
1637
        mem_free(folds);
1658
1638
        mem_free(recs);
1687
1667
        ut_ad(rw_lock_own(&(new_block->lock), RW_LOCK_EX));
1688
1668
#endif /* UNIV_SYNC_DEBUG */
1689
1669
 
1690
 
        rw_lock_s_lock(btr_search_get_latch(index->id));
 
1670
        rw_lock_s_lock(btr_search_get_latch(index));
1691
1671
 
1692
1672
        ut_a(!new_block->index || new_block->index == index);
1693
1673
        ut_a(!block->index || block->index == index);
1696
1676
 
1697
1677
        if (new_block->index) {
1698
1678
 
1699
 
                rw_lock_s_unlock(btr_search_get_latch(index->id));
 
1679
                rw_lock_s_unlock(btr_search_get_latch(index));
1700
1680
 
1701
1681
                btr_search_drop_page_hash_index(block);
1702
1682
 
1713
1693
                new_block->n_bytes = block->curr_n_bytes;
1714
1694
                new_block->left_side = left_side;
1715
1695
 
1716
 
                rw_lock_s_unlock(btr_search_get_latch(index->id));
 
1696
                rw_lock_s_unlock(btr_search_get_latch(index));
1717
1697
 
1718
1698
                ut_a(n_fields + n_bytes > 0);
1719
1699
 
1725
1705
                return;
1726
1706
        }
1727
1707
 
1728
 
        rw_lock_s_unlock(btr_search_get_latch(index->id));
 
1708
        rw_lock_s_unlock(btr_search_get_latch(index));
1729
1709
}
1730
1710
 
1731
1711
/********************************************************************//**
1764
1744
        ut_a(block->curr_n_fields + block->curr_n_bytes > 0);
1765
1745
        ut_a(!dict_index_is_ibuf(index));
1766
1746
 
1767
 
        table = btr_search_get_hash_index(cursor->index->id);
 
1747
        table = btr_search_get_hash_table(cursor->index);
1768
1748
 
1769
1749
        rec = btr_cur_get_rec(cursor);
1770
1750
 
1775
1755
                mem_heap_free(heap);
1776
1756
        }
1777
1757
 
1778
 
        rw_lock_x_lock(btr_search_get_latch(cursor->index->id));
 
1758
        rw_lock_x_lock(btr_search_get_latch(cursor->index));
1779
1759
 
1780
1760
        if (block->index) {
1781
1761
                ut_a(block->index == index);
1783
1763
                ha_search_and_delete_if_found(table, fold, rec);
1784
1764
        }
1785
1765
 
1786
 
        rw_lock_x_unlock(btr_search_get_latch(cursor->index->id));
 
1766
        rw_lock_x_unlock(btr_search_get_latch(cursor->index));
1787
1767
}
1788
1768
 
1789
1769
/********************************************************************//**
1820
1800
        ut_a(cursor->index == index);
1821
1801
        ut_a(!dict_index_is_ibuf(index));
1822
1802
 
1823
 
        rw_lock_x_lock(btr_search_get_latch(cursor->index->id));
 
1803
        rw_lock_x_lock(btr_search_get_latch(cursor->index));
1824
1804
 
1825
1805
        if (!block->index) {
1826
1806
 
1834
1814
            && (cursor->n_bytes == block->curr_n_bytes)
1835
1815
            && !block->curr_left_side) {
1836
1816
 
1837
 
                table = btr_search_get_hash_index(cursor->index->id);
 
1817
                table = btr_search_get_hash_table(cursor->index);
1838
1818
 
1839
1819
                ha_search_and_update_if_found(table, cursor->fold, rec,
1840
1820
                                              block, page_rec_get_next(rec));
1841
1821
 
1842
1822
func_exit:
1843
 
                rw_lock_x_unlock(btr_search_get_latch(cursor->index->id));
 
1823
                rw_lock_x_unlock(btr_search_get_latch(cursor->index));
1844
1824
        } else {
1845
 
                rw_lock_x_unlock(btr_search_get_latch(cursor->index->id));
 
1825
                rw_lock_x_unlock(btr_search_get_latch(cursor->index));
1846
1826
 
1847
1827
                btr_search_update_hash_on_insert(cursor);
1848
1828
        }
1877
1857
        ulint*          offsets         = offsets_;
1878
1858
        rec_offs_init(offsets_);
1879
1859
 
1880
 
        table = btr_search_get_hash_index(cursor->index->id);
 
1860
        table = btr_search_get_hash_table(cursor->index);
1881
1861
 
1882
 
        btr_search_check_free_space_in_heap(cursor->index->id);
 
1862
        btr_search_check_free_space_in_heap(cursor->index);
1883
1863
 
1884
1864
        rec = btr_cur_get_rec(cursor);
1885
1865
 
1924
1904
        } else {
1925
1905
                if (left_side) {
1926
1906
 
1927
 
                        rw_lock_x_lock(btr_search_get_latch(index->id));
 
1907
                        rw_lock_x_lock(btr_search_get_latch(index));
1928
1908
 
1929
1909
                        locked = TRUE;
1930
1910
 
1942
1922
 
1943
1923
                if (!locked) {
1944
1924
 
1945
 
                        rw_lock_x_lock(btr_search_get_latch(index->id));
 
1925
                        rw_lock_x_lock(btr_search_get_latch(index));
1946
1926
 
1947
1927
                        locked = TRUE;
1948
1928
 
1964
1944
                if (!left_side) {
1965
1945
 
1966
1946
                        if (!locked) {
1967
 
                                rw_lock_x_lock(btr_search_get_latch(index->id));
 
1947
                                rw_lock_x_lock(btr_search_get_latch(index));
1968
1948
 
1969
1949
                                locked = TRUE;
1970
1950
 
1983
1963
 
1984
1964
                if (!locked) {
1985
1965
 
1986
 
                        rw_lock_x_lock(btr_search_get_latch(index->id));
 
1966
                        rw_lock_x_lock(btr_search_get_latch(index));
1987
1967
 
1988
1968
                        locked = TRUE;
1989
1969
 
2010
1990
                mem_heap_free(heap);
2011
1991
        }
2012
1992
        if (locked) {
2013
 
                rw_lock_x_unlock(btr_search_get_latch(index->id));
 
1993
                rw_lock_x_unlock(btr_search_get_latch(index));
2014
1994
        }
2015
1995
}
2016
1996
 
2043
2023
 
2044
2024
        for (j = 0; j < btr_search_index_num; j++) {
2045
2025
 
2046
 
        cell_count = hash_get_n_cells(btr_search_sys->hash_index[j]);
 
2026
        cell_count = hash_get_n_cells(btr_search_sys->hash_tables[j]);
2047
2027
 
2048
2028
        for (i = 0; i < cell_count; i++) {
2049
2029
                /* We release btr_search_latch every once in a while to
2056
2036
                        buf_pool_page_hash_x_lock_all();
2057
2037
                }
2058
2038
 
2059
 
                node = hash_get_nth_cell(btr_search_sys->hash_index[j], i)->node;
 
2039
                node = hash_get_nth_cell(btr_search_sys->hash_tables[j], i)->node;
2060
2040
 
2061
2041
                for (; node != NULL; node = node->next) {
2062
2042
                        const buf_block_t*      block
2171
2151
                        buf_pool_page_hash_x_lock_all();
2172
2152
                }
2173
2153
 
2174
 
                if (!ha_validate(btr_search_sys->hash_index[j], i, end_index)) {
 
2154
                if (!ha_validate(btr_search_sys->hash_tables[j], i, end_index)) {
2175
2155
                        ok = FALSE;
2176
2156
                }
2177
2157
        }