~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/btr/btr0sea.c

  • Committer: Lee Bieber
  • Date: 2010-10-27 18:28:56 UTC
  • mfrom: (1883.1.3 build)
  • Revision ID: kalebral@gmail.com-20101027182856-q3wqtbv1t4egkjsk
Merge Andrew - fix bug 667360: --defaults-file not processed before paths read           
Merge Andrew - fix bug 656577: Importing SQL script results in silent failure    
Merge Andrew - fix bug 667053: drizzledump minor output cleanup needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (C) 1996, 2009, Innobase Oy. All Rights Reserved.
4
 
Copyright (C) 2008, Google Inc.
 
3
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
 
4
Copyright (c) 2008, Google Inc.
5
5
 
6
6
Portions of this file contain modifications contributed and copyrighted by
7
7
Google, Inc. Those modifications are gratefully acknowledged and are described
45
45
 
46
46
/** Flag: has the search system been enabled?
47
47
Protected by btr_search_latch and btr_search_enabled_mutex. */
48
 
UNIV_INTERN bool                btr_search_enabled = TRUE;
49
 
UNIV_INTERN ibool               btr_search_fully_disabled = FALSE;
 
48
UNIV_INTERN bool                btr_search_enabled      = TRUE;
50
49
 
51
50
/** Mutex protecting btr_search_enabled */
52
51
static mutex_t                  btr_search_enabled_mutex;
83
82
/** The adaptive hash index */
84
83
UNIV_INTERN btr_search_sys_t*   btr_search_sys;
85
84
 
86
 
#ifdef UNIV_PFS_RWLOCK
87
 
/* Key to register btr_search_sys with performance schema */
88
 
UNIV_INTERN mysql_pfs_key_t     btr_search_latch_key;
89
 
#endif /* UNIV_PFS_RWLOCK */
90
 
 
91
85
/** If the number of records on the page divided by this parameter
92
86
would have been successfully accessed using a hash index, the index
93
87
is then built on the page, assuming the global limit has been reached */
146
140
        be enough free space in the hash table. */
147
141
 
148
142
        if (heap->free_block == NULL) {
149
 
                buf_block_t*    block = buf_block_alloc(NULL, 0);
 
143
                buf_block_t*    block = buf_block_alloc(0);
150
144
 
151
145
                rw_lock_x_lock(&btr_search_latch);
152
146
 
171
165
        /* We allocate the search latch from dynamic memory:
172
166
        see above at the global variable definition */
173
167
 
174
 
        btr_search_latch_temp = static_cast<rw_lock_t *>(mem_alloc(sizeof(rw_lock_t)));
175
 
 
176
 
        rw_lock_create(btr_search_latch_key, &btr_search_latch,
177
 
                       SYNC_SEARCH_SYS);
178
 
        mutex_create(btr_search_enabled_mutex_key,
179
 
                     &btr_search_enabled_mutex, SYNC_SEARCH_SYS_CONF);
180
 
 
181
 
        btr_search_sys = (btr_search_sys_t *)mem_alloc(sizeof(btr_search_sys_t));
 
168
        btr_search_latch_temp = mem_alloc(sizeof(rw_lock_t));
 
169
 
 
170
        rw_lock_create(&btr_search_latch, SYNC_SEARCH_SYS);
 
171
        mutex_create(&btr_search_enabled_mutex, SYNC_SEARCH_SYS_CONF);
 
172
 
 
173
        btr_search_sys = mem_alloc(sizeof(btr_search_sys_t));
182
174
 
183
175
        btr_search_sys->hash_index = ha_create(hash_size, 0, 0);
184
176
}
209
201
        mutex_enter(&btr_search_enabled_mutex);
210
202
        rw_lock_x_lock(&btr_search_latch);
211
203
 
212
 
        /* Disable access to hash index, also tell ha_insert_for_fold()
213
 
        stop adding new nodes to hash index, but still allow updating
214
 
        existing nodes */
215
204
        btr_search_enabled = FALSE;
216
205
 
217
206
        /* Clear all block->is_hashed flags and remove all entries
218
207
        from btr_search_sys->hash_index. */
219
208
        buf_pool_drop_hash_index();
220
209
 
221
 
        /* hash index has been cleaned up, disallow any operation to
222
 
        the hash index */
223
 
        btr_search_fully_disabled = TRUE;
224
 
 
225
210
        /* btr_search_enabled_mutex should guarantee this. */
226
211
        ut_ad(!btr_search_enabled);
227
212
 
240
225
        rw_lock_x_lock(&btr_search_latch);
241
226
 
242
227
        btr_search_enabled = TRUE;
243
 
        btr_search_fully_disabled = FALSE;
244
228
 
245
229
        rw_lock_x_unlock(&btr_search_latch);
246
230
        mutex_exit(&btr_search_enabled_mutex);
257
241
{
258
242
        btr_search_t*   info;
259
243
 
260
 
        info = (btr_search_t *)mem_heap_alloc(heap, sizeof(btr_search_t));
 
244
        info = mem_heap_alloc(heap, sizeof(btr_search_t));
261
245
 
262
246
#ifdef UNIV_DEBUG
263
247
        info->magic_n = BTR_SEARCH_MAGIC_N;
444
428
/*==============================*/
445
429
        btr_search_t*   info,   /*!< in: search info */
446
430
        buf_block_t*    block,  /*!< in: buffer block */
447
 
        btr_cur_t*      /*cursor __attribute__((unused))*/)
 
431
        btr_cur_t*      cursor __attribute__((unused)))
448
432
                                /*!< in: cursor */
449
433
{
450
434
#ifdef UNIV_SYNC_DEBUG
527
511
        buf_block_t*    block,  /*!< in: buffer block where cursor positioned */
528
512
        btr_cur_t*      cursor) /*!< in: cursor */
529
513
{
530
 
        ulint           fold;
531
 
        rec_t*          rec;
532
 
        index_id_t      index_id;
 
514
        ulint   fold;
 
515
        rec_t*  rec;
 
516
        dulint  index_id;
533
517
 
534
518
        ut_ad(cursor->flag == BTR_CUR_HASH_FAIL);
535
519
#ifdef UNIV_SYNC_DEBUG
639
623
                inside the called function. It might be that the compiler
640
624
                would optimize the call just to pass pointers to block. */
641
625
 
642
 
                params = (ulint *)mem_alloc(3 * sizeof(ulint));
 
626
                params = mem_alloc(3 * sizeof(ulint));
643
627
                params[0] = block->n_fields;
644
628
                params[1] = block->n_bytes;
645
629
                params[2] = block->left_side;
830
814
                                        RW_S_LATCH, RW_X_LATCH, or 0 */
831
815
        mtr_t*          mtr)            /*!< in: mtr */
832
816
{
833
 
        buf_pool_t*     buf_pool;
834
817
        buf_block_t*    block;
835
818
        rec_t*          rec;
836
819
        ulint           fold;
837
 
        index_id_t      index_id;
 
820
        dulint          index_id;
838
821
#ifdef notdefined
839
822
        btr_cur_t       cursor2;
840
823
        btr_pcur_t      pcur;
881
864
        ut_ad(rw_lock_get_writer(&btr_search_latch) != RW_LOCK_EX);
882
865
        ut_ad(rw_lock_get_reader_count(&btr_search_latch) > 0);
883
866
 
884
 
        rec = (rec_t *)ha_search_and_get_data(btr_search_sys->hash_index, fold);
 
867
        rec = ha_search_and_get_data(btr_search_sys->hash_index, fold);
885
868
 
886
869
        if (UNIV_UNLIKELY(!rec)) {
887
870
                goto failure_unlock;
926
909
        is positioned on. We cannot look at the next of the previous
927
910
        record to determine if our guess for the cursor position is
928
911
        right. */
929
 
        if (UNIV_UNLIKELY(index_id != btr_page_get_index_id(block->frame))
 
912
        if (UNIV_EXPECT
 
913
            (ut_dulint_cmp(index_id, btr_page_get_index_id(block->frame)), 0)
930
914
            || !btr_search_check_guess(cursor,
931
915
                                       has_search_latch,
932
916
                                       tuple, mode, mtr)) {
988
972
 
989
973
        /* Increment the page get statistics though we did not really
990
974
        fix the page: for user info only */
991
 
        buf_pool = buf_pool_from_bpage(&block->page);
 
975
 
992
976
        buf_pool->stat.n_page_gets++;
993
977
 
994
978
        return(TRUE);
1031
1015
        const rec_t*            rec;
1032
1016
        ulint                   fold;
1033
1017
        ulint                   prev_fold;
1034
 
        index_id_t              index_id;
 
1018
        dulint                  index_id;
1035
1019
        ulint                   n_cached;
1036
1020
        ulint                   n_recs;
1037
1021
        ulint*                  folds;
1082
1066
        /* Calculate and cache fold values into an array for fast deletion
1083
1067
        from the hash index */
1084
1068
 
1085
 
        folds = (ulint *)mem_alloc(n_recs * sizeof(ulint));
 
1069
        folds = mem_alloc(n_recs * sizeof(ulint));
1086
1070
 
1087
1071
        n_cached = 0;
1088
1072
 
1091
1075
 
1092
1076
        index_id = btr_page_get_index_id(page);
1093
1077
 
1094
 
        ut_a(index_id == index->id);
 
1078
        ut_a(0 == ut_dulint_cmp(index_id, index->id));
1095
1079
 
1096
1080
        prev_fold = 0;
1097
1081
 
1248
1232
        rec_t*          next_rec;
1249
1233
        ulint           fold;
1250
1234
        ulint           next_fold;
1251
 
        index_id_t      index_id;
 
1235
        dulint          index_id;
1252
1236
        ulint           n_cached;
1253
1237
        ulint           n_recs;
1254
1238
        ulint*          folds;
1307
1291
        /* Calculate and cache fold values and corresponding records into
1308
1292
        an array for fast insertion to the hash index */
1309
1293
 
1310
 
        folds = (ulint *)mem_alloc(n_recs * sizeof(ulint));
1311
 
        recs = (rec_t **)mem_alloc(n_recs * sizeof(rec_t*));
 
1294
        folds = mem_alloc(n_recs * sizeof(ulint));
 
1295
        recs = mem_alloc(n_recs * sizeof(rec_t*));
1312
1296
 
1313
1297
        n_cached = 0;
1314
1298
 
1379
1363
 
1380
1364
        rw_lock_x_lock(&btr_search_latch);
1381
1365
 
1382
 
        if (UNIV_UNLIKELY(btr_search_fully_disabled)) {
 
1366
        if (UNIV_UNLIKELY(!btr_search_enabled)) {
1383
1367
                goto exit_func;
1384
1368
        }
1385
1369
 
1501
1485
        buf_block_t*    block;
1502
1486
        rec_t*          rec;
1503
1487
        ulint           fold;
1504
 
        index_id_t      index_id;
 
1488
        dulint          index_id;
 
1489
        ibool           found;
1505
1490
        ulint           offsets_[REC_OFFS_NORMAL_SIZE];
1506
1491
        mem_heap_t*     heap            = NULL;
1507
1492
        rec_offs_init(offsets_);
1534
1519
        }
1535
1520
        rw_lock_x_lock(&btr_search_latch);
1536
1521
 
1537
 
        ha_search_and_delete_if_found(table, fold, rec);
 
1522
        found = ha_search_and_delete_if_found(table, fold, rec);
1538
1523
 
1539
1524
        rw_lock_x_unlock(&btr_search_latch);
1540
1525
}
1606
1591
        rec_t*          rec;
1607
1592
        rec_t*          ins_rec;
1608
1593
        rec_t*          next_rec;
1609
 
        index_id_t      index_id;
 
1594
        dulint          index_id;
1610
1595
        ulint           fold;
1611
1596
        ulint           ins_fold;
1612
1597
        ulint           next_fold = 0; /* remove warning (??? bug ???) */
1740
1725
        }
1741
1726
}
1742
1727
 
1743
 
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
1744
1728
/********************************************************************//**
1745
1729
Validates the search system.
1746
1730
@return TRUE if ok */
1765
1749
        rec_offs_init(offsets_);
1766
1750
 
1767
1751
        rw_lock_x_lock(&btr_search_latch);
1768
 
        buf_pool_mutex_enter_all();
 
1752
        buf_pool_mutex_enter();
1769
1753
 
1770
1754
        cell_count = hash_get_n_cells(btr_search_sys->hash_index);
1771
1755
 
1773
1757
                /* We release btr_search_latch every once in a while to
1774
1758
                give other queries a chance to run. */
1775
1759
                if ((i != 0) && ((i % chunk_size) == 0)) {
1776
 
                        buf_pool_mutex_exit_all();
 
1760
                        buf_pool_mutex_exit();
1777
1761
                        rw_lock_x_unlock(&btr_search_latch);
1778
1762
                        os_thread_yield();
1779
1763
                        rw_lock_x_lock(&btr_search_latch);
1780
 
                        buf_pool_mutex_enter_all();
 
1764
                        buf_pool_mutex_enter();
1781
1765
                }
1782
1766
 
1783
1767
                node = hash_get_nth_cell(btr_search_sys->hash_index, i)->node;
1786
1770
                        const buf_block_t*      block
1787
1771
                                = buf_block_align(node->data);
1788
1772
                        const buf_block_t*      hash_block;
1789
 
                        buf_pool_t*             buf_pool;
1790
 
                        index_id_t              page_index_id;
1791
 
 
1792
 
                        buf_pool = buf_pool_from_bpage((buf_page_t*) block);
1793
1773
 
1794
1774
                        if (UNIV_LIKELY(buf_block_get_state(block)
1795
1775
                                        == BUF_BLOCK_FILE_PAGE)) {
1800
1780
                                (BUF_BLOCK_REMOVE_HASH, see the
1801
1781
                                assertion and the comment below) */
1802
1782
                                hash_block = buf_block_hash_get(
1803
 
                                        buf_pool,
1804
1783
                                        buf_block_get_space(block),
1805
1784
                                        buf_block_get_page_no(block));
1806
1785
                        } else {
1832
1811
                                                  + (block->curr_n_bytes > 0),
1833
1812
                                                  &heap);
1834
1813
 
1835
 
                        page_index_id = btr_page_get_index_id(block->frame);
1836
 
 
1837
 
                        if (UNIV_UNLIKELY
1838
 
                            (!block->is_hashed || node->fold
1839
 
                             != rec_fold((rec_t*)(node->data),
1840
 
                                         offsets,
1841
 
                                         block->curr_n_fields,
1842
 
                                         block->curr_n_bytes,
1843
 
                                         page_index_id))) {
 
1814
                        if (!block->is_hashed || node->fold
 
1815
                            != rec_fold((rec_t*)(node->data),
 
1816
                                        offsets,
 
1817
                                        block->curr_n_fields,
 
1818
                                        block->curr_n_bytes,
 
1819
                                        btr_page_get_index_id(block->frame))) {
1844
1820
                                const page_t*   page = block->frame;
1845
1821
 
1846
1822
                                ok = FALSE;
1850
1826
                                        "  InnoDB: Error in an adaptive hash"
1851
1827
                                        " index pointer to page %lu\n"
1852
1828
                                        "InnoDB: ptr mem address %p"
1853
 
                                        " index id %llu,"
 
1829
                                        " index id %lu %lu,"
1854
1830
                                        " node fold %lu, rec fold %lu\n",
1855
1831
                                        (ulong) page_get_page_no(page),
1856
1832
                                        node->data,
1857
 
                                        (ullint) page_index_id,
 
1833
                                        (ulong) ut_dulint_get_high(
 
1834
                                                btr_page_get_index_id(page)),
 
1835
                                        (ulong) ut_dulint_get_low(
 
1836
                                                btr_page_get_index_id(page)),
1858
1837
                                        (ulong) node->fold,
1859
1838
                                        (ulong) rec_fold((rec_t*)(node->data),
1860
1839
                                                         offsets,
1861
1840
                                                         block->curr_n_fields,
1862
1841
                                                         block->curr_n_bytes,
1863
 
                                                         page_index_id));
 
1842
                                                         btr_page_get_index_id(
 
1843
                                                                 page)));
1864
1844
 
1865
1845
                                fputs("InnoDB: Record ", stderr);
1866
1846
                                rec_print_new(stderr, (rec_t*)node->data,
1888
1868
                /* We release btr_search_latch every once in a while to
1889
1869
                give other queries a chance to run. */
1890
1870
                if (i != 0) {
1891
 
                        buf_pool_mutex_exit_all();
 
1871
                        buf_pool_mutex_exit();
1892
1872
                        rw_lock_x_unlock(&btr_search_latch);
1893
1873
                        os_thread_yield();
1894
1874
                        rw_lock_x_lock(&btr_search_latch);
1895
 
                        buf_pool_mutex_enter_all();
 
1875
                        buf_pool_mutex_enter();
1896
1876
                }
1897
1877
 
1898
1878
                if (!ha_validate(btr_search_sys->hash_index, i, end_index)) {
1900
1880
                }
1901
1881
        }
1902
1882
 
1903
 
        buf_pool_mutex_exit_all();
 
1883
        buf_pool_mutex_exit();
1904
1884
        rw_lock_x_unlock(&btr_search_latch);
1905
1885
        if (UNIV_LIKELY_NULL(heap)) {
1906
1886
                mem_heap_free(heap);
1908
1888
 
1909
1889
        return(ok);
1910
1890
}
1911
 
#endif /* defined UNIV_AHI_DEBUG || defined UNIV_DEBUG */