~stewart/drizzle/docs-improvements-1

« back to all changes in this revision

Viewing changes to plugin/innobase/buf/buf0buf.cc

merged with up to date trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (c) 1995, 2010, Innobase Oy. All Rights Reserved.
4
 
Copyright (c) 2008, Google Inc.
 
3
Copyright (C) 1995, 2010, 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
172
172
holding file pages that have been modified in the memory
173
173
but not written to disk yet. The block with the oldest modification
174
174
which has not yet been written to disk is at the end of the chain.
175
 
The access to this list is protected by flush_list_mutex.
 
175
The access to this list is protected by buf_pool->flush_list_mutex.
176
176
 
177
177
The chain of unmodified compressed blocks (buf_pool->zip_clean)
178
178
contains the control blocks (buf_page_t) of those compressed pages
246
246
/** Number of attemtps made to read in a page in the buffer pool */
247
247
static const ulint BUF_PAGE_READ_MAX_RETRIES = 100;
248
248
 
249
 
/** The buffer buf_pool of the database */
250
 
UNIV_INTERN buf_pool_t* buf_pool_ptr[MAX_BUFFER_POOLS];
 
249
/** The buffer pools of the database */
 
250
UNIV_INTERN buf_pool_t* buf_pool_ptr;
251
251
 
252
252
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
253
253
static ulint    buf_dbg_counter = 0; /*!< This is used to insert validation
858
858
 
859
859
        block->frame = frame;
860
860
 
861
 
        block->page.buf_pool = buf_pool;
 
861
        block->page.buf_pool_index = buf_pool_index(buf_pool);
862
862
        block->page.state = BUF_BLOCK_NOT_USED;
863
863
        block->page.buf_fix_count = 0;
864
864
        block->page.io_fix = BUF_IO_NONE;
941
941
 
942
942
        /* Allocate the block descriptors from
943
943
        the start of the memory block. */
944
 
        chunk->blocks = chunk->mem;
 
944
        chunk->blocks = static_cast<buf_block_struct *>(chunk->mem);
945
945
 
946
946
        /* Align a pointer to the first frame.  Note that when
947
947
        os_large_page_size is smaller than UNIV_PAGE_SIZE,
948
948
        we may allocate one fewer block than requested.  When
949
949
        it is bigger, we may allocate more blocks than requested. */
950
950
 
951
 
        frame = ut_align(chunk->mem, UNIV_PAGE_SIZE);
 
951
        frame = static_cast<unsigned char *>(ut_align(chunk->mem, UNIV_PAGE_SIZE));
952
952
        chunk->size = chunk->mem_size / UNIV_PAGE_SIZE
953
953
                - (frame != chunk->mem);
954
954
 
1213
1213
 
1214
1214
        if (buf_pool_size > 0) {
1215
1215
                buf_pool->n_chunks = 1;
1216
 
                buf_pool->chunks = chunk = mem_zalloc(sizeof *chunk);
 
1216
                void *chunk_ptr= mem_zalloc((sizeof *chunk));
 
1217
                buf_pool->chunks = chunk = static_cast<buf_chunk_t *>(chunk_ptr);
1217
1218
 
1218
1219
                UT_LIST_INIT(buf_pool->free);
1219
1220
 
1280
1281
        mem_free(buf_pool->chunks);
1281
1282
        hash_table_free(buf_pool->page_hash);
1282
1283
        hash_table_free(buf_pool->zip_hash);
1283
 
        mem_free(buf_pool);
1284
 
        buf_pool = NULL;
1285
1284
}
1286
1285
 
1287
1286
/********************************************************************//**
1294
1293
        ulint   total_size,     /*!< in: size of the total pool in bytes */
1295
1294
        ulint   n_instances)    /*!< in: number of instances */
1296
1295
{
1297
 
        ulint   i;
 
1296
        ulint           i;
 
1297
        const ulint     size    = total_size / n_instances;
 
1298
 
 
1299
        ut_ad(n_instances > 0);
 
1300
        ut_ad(n_instances <= MAX_BUFFER_POOLS);
 
1301
        ut_ad(n_instances == srv_buf_pool_instances);
1298
1302
 
1299
1303
        /* We create an extra buffer pool instance, this instance is used
1300
1304
        for flushing the flush lists, to keep track of n_flush for all
1301
1305
        the buffer pools and also used as a waiting object during flushing. */
 
1306
        void *buf_pool_void_ptr= mem_zalloc(n_instances * sizeof *buf_pool_ptr);
 
1307
        buf_pool_ptr = static_cast<buf_pool_struct *>(buf_pool_void_ptr);
 
1308
 
1302
1309
        for (i = 0; i < n_instances; i++) {
1303
 
                buf_pool_t*     ptr;
1304
 
                ulint           size;
1305
 
 
1306
 
                ptr = mem_zalloc(sizeof(*ptr));
1307
 
 
1308
 
                size = total_size / n_instances;
1309
 
 
1310
 
                buf_pool_ptr[i] = ptr;
 
1310
                buf_pool_t*     ptr     = &buf_pool_ptr[i];
1311
1311
 
1312
1312
                if (buf_pool_init_instance(ptr, size, i) != DB_SUCCESS) {
1313
1313
 
1314
 
                        mem_free(buf_pool_ptr[i]);
1315
 
 
1316
1314
                        /* Free all the instances created so far. */
1317
1315
                        buf_pool_free(i);
1318
1316
 
1341
1339
 
1342
1340
        for (i = 0; i < n_instances; i++) {
1343
1341
                buf_pool_free_instance(buf_pool_from_array(i));
1344
 
                buf_pool_ptr[i] = NULL;
1345
1342
        }
 
1343
 
 
1344
        mem_free(buf_pool_ptr);
 
1345
        buf_pool_ptr = NULL;
1346
1346
}
1347
1347
 
1348
1348
/********************************************************************//**
1657
1657
        buf_pool->old_pool_size = buf_pool->curr_pool_size;
1658
1658
 
1659
1659
        /* Rewrite buf_pool->chunks.  Copy everything but max_chunk. */
1660
 
        chunks = mem_alloc((buf_pool->n_chunks - 1) * sizeof *chunks);
 
1660
        chunks = static_cast<buf_chunk_t *>(mem_alloc((buf_pool->n_chunks - 1) * sizeof *chunks));
1661
1661
        memcpy(chunks, buf_pool->chunks,
1662
1662
               (max_chunk - buf_pool->chunks) * sizeof *chunks);
1663
1663
        memcpy(chunks + (max_chunk - buf_pool->chunks),
1882
1882
                        ut_ad(!bpage->in_page_hash);
1883
1883
                        ut_ad(bpage->buf_fix_count == 0);
1884
1884
 
1885
 
                        /* bpage is pointing to buf_pool_watch[],
1886
 
                        which is protected by buf_pool_mutex.
 
1885
                        /* bpage is pointing to buf_pool->watch[],
 
1886
                        which is protected by buf_pool->mutex.
1887
1887
                        Normally, buf_page_t objects are protected by
1888
1888
                        buf_block_t::mutex or buf_pool->zip_mutex or both. */
1889
1889
 
1942
1942
        buf_chunk_t*    chunk;
1943
1943
 
1944
1944
        buf_pool_mutex_enter(buf_pool);
1945
 
        chunks = mem_alloc((buf_pool->n_chunks + 1) * sizeof *chunks);
 
1945
        chunks = static_cast<buf_chunk_t *>(mem_alloc((buf_pool->n_chunks + 1) * sizeof *chunks));
1946
1946
 
1947
1947
        memcpy(chunks, buf_pool->chunks, buf_pool->n_chunks * sizeof *chunks);
1948
1948
 
3008
3008
        bytes. */
3009
3009
        UNIV_MEM_ASSERT_RW(&block->page, sizeof block->page);
3010
3010
#endif
 
3011
#if defined UNIV_DEBUG || defined UNIV_IBUF_DEBUG
 
3012
        if ((mode == BUF_GET_IF_IN_POOL || mode == BUF_GET_IF_IN_POOL_OR_WATCH)
 
3013
            && ibuf_debug) {
 
3014
                /* Try to evict the block from the buffer pool, to use the
 
3015
                insert buffer (change buffer) as much as possible. */
 
3016
 
 
3017
                if (buf_LRU_free_block(&block->page, TRUE, NULL)
 
3018
                    == BUF_LRU_FREED) {
 
3019
                        mutex_exit(&block->mutex);
 
3020
                        if (mode == BUF_GET_IF_IN_POOL_OR_WATCH) {
 
3021
                                /* Set the watch, as it would have
 
3022
                                been set if the page were not in the
 
3023
                                buffer pool in the first place. */
 
3024
                                block = (buf_block_t*) buf_pool_watch_set(
 
3025
                                        space, offset, fold);
 
3026
 
 
3027
                                if (UNIV_LIKELY_NULL(block)) {
 
3028
 
 
3029
                                        /* The page entered the buffer
 
3030
                                        pool for some reason. Try to
 
3031
                                        evict it again. */
 
3032
                                        goto got_block;
 
3033
                                }
 
3034
                        }
 
3035
                        buf_pool_mutex_exit(buf_pool);
 
3036
                        fprintf(stderr,
 
3037
                                "innodb_change_buffering_debug evict %u %u\n",
 
3038
                                (unsigned) space, (unsigned) offset);
 
3039
                        return(NULL);
 
3040
                } else if (buf_flush_page_try(buf_pool, block)) {
 
3041
                        fprintf(stderr,
 
3042
                                "innodb_change_buffering_debug flush %u %u\n",
 
3043
                                (unsigned) space, (unsigned) offset);
 
3044
                        guess = block;
 
3045
                        goto loop;
 
3046
                }
 
3047
 
 
3048
                /* Failed to evict the page; change it directly */
 
3049
        }
 
3050
#endif /* UNIV_DEBUG || UNIV_IBUF_DEBUG */
3011
3051
 
3012
3052
        buf_block_buf_fix_inc(block, file, line);
3013
3053
 
3619
3659
                        mutex_exit(&block->mutex);
3620
3660
                        data = buf_buddy_alloc(buf_pool, zip_size, &lru);
3621
3661
                        mutex_enter(&block->mutex);
3622
 
                        block->page.zip.data = data;
 
3662
                        block->page.zip.data = static_cast<unsigned char *>(data);
3623
3663
 
3624
3664
                        /* To maintain the invariant
3625
3665
                        block->in_unzip_LRU_list
3642
3682
                invocation of buf_buddy_relocate_block() on
3643
3683
                uninitialized data. */
3644
3684
                data = buf_buddy_alloc(buf_pool, zip_size, &lru);
3645
 
                bpage = buf_buddy_alloc(buf_pool, sizeof *bpage, &lru);
 
3685
                bpage = static_cast<buf_page_struct *>(buf_buddy_alloc(buf_pool, sizeof *bpage, &lru));
3646
3686
 
3647
3687
                /* Initialize the buf_pool pointer. */
3648
 
                bpage->buf_pool = buf_pool;
 
3688
                bpage->buf_pool_index = buf_pool_index(buf_pool);
3649
3689
 
3650
3690
                /* If buf_buddy_alloc() allocated storage from the LRU list,
3651
3691
                it released and reacquired buf_pool->mutex.  Thus, we must
3671
3711
 
3672
3712
                page_zip_des_init(&bpage->zip);
3673
3713
                page_zip_set_size(&bpage->zip, zip_size);
3674
 
                bpage->zip.data = data;
 
3714
                bpage->zip.data = static_cast<unsigned char *>(data);
3675
3715
 
3676
3716
                mutex_enter(&buf_pool->zip_mutex);
3677
3717
                UNIV_MEM_DESC(bpage->zip.data,
3825
3865
                has been added to buf_pool->LRU and buf_pool->page_hash. */
3826
3866
                data = buf_buddy_alloc(buf_pool, zip_size, &lru);
3827
3867
                mutex_enter(&block->mutex);
3828
 
                block->page.zip.data = data;
 
3868
                block->page.zip.data = static_cast<unsigned char *>(data);
3829
3869
 
3830
3870
                /* To maintain the invariant
3831
3871
                block->in_unzip_LRU_list
4137
4177
        buf_pool_t*     buf_pool)       /*!< in: buffer pool instance */
4138
4178
{
4139
4179
        ibool           freed;
4140
 
        enum buf_flush  i;
 
4180
        int     i;
4141
4181
 
4142
4182
        buf_pool_mutex_enter(buf_pool);
4143
4183
 
4156
4196
                write activity happening. */
4157
4197
                if (buf_pool->n_flush[i] > 0) {
4158
4198
                        buf_pool_mutex_exit(buf_pool);
4159
 
                        buf_flush_wait_batch_end(buf_pool, i);
 
4199
                        buf_flush_wait_batch_end(buf_pool, static_cast<buf_flush>(i));
4160
4200
                        buf_pool_mutex_enter(buf_pool);
4161
4201
                }
4162
4202
        }
4865
4905
        fprintf(file,
4866
4906
                "LRU len: %lu, unzip_LRU len: %lu\n"
4867
4907
                "I/O sum[%lu]:cur[%lu], unzip sum[%lu]:cur[%lu]\n",
4868
 
                UT_LIST_GET_LEN(buf_pool->LRU),
4869
 
                UT_LIST_GET_LEN(buf_pool->unzip_LRU),
 
4908
                static_cast<ulint>(UT_LIST_GET_LEN(buf_pool->LRU)),
 
4909
                static_cast<ulint>(UT_LIST_GET_LEN(buf_pool->unzip_LRU)),
4870
4910
                buf_LRU_stat_sum.io, buf_LRU_stat_cur.io,
4871
4911
                buf_LRU_stat_sum.unzip, buf_LRU_stat_cur.unzip);
4872
4912