~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/ibuf0ibuf.ic

  • Committer: Monty Taylor
  • Date: 2008-09-15 17:24:04 UTC
  • Revision ID: monty@inaugust.com-20080915172404-ygh6hiyu0q7qpa9x
Removed strndup calls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
#include "buf0lru.h"
10
10
#include "page0page.h"
11
 
#include "page0zip.h"
12
11
 
13
12
extern ulint    ibuf_flush_count;
14
13
 
55
54
mini-transaction, hence this operation does not restrict further work to only
56
55
ibuf bitmap operations, which would result if the latch to the bitmap page
57
56
were kept. */
58
 
UNIV_INTERN
 
57
 
59
58
void
60
 
ibuf_set_free_bits_func(
61
 
/*====================*/
62
 
        buf_block_t*    block,  /* in: index page of a non-clustered index;
63
 
                                free bit is reset if page level is 0 */
64
 
#ifdef UNIV_IBUF_DEBUG
65
 
        ulint           max_val,/* in: ULINT_UNDEFINED or a maximum
66
 
                                value which the bits must have before
67
 
                                setting; this is for debugging */
68
 
#endif /* UNIV_IBUF_DEBUG */
69
 
        ulint           val);   /* in: value to set: < 4 */
70
 
#ifdef UNIV_IBUF_DEBUG
71
 
# define ibuf_set_free_bits(b,v,max) ibuf_set_free_bits_func(b,max,v)
72
 
#else /* UNIV_IBUF_DEBUG */
73
 
# define ibuf_set_free_bits(b,v,max) ibuf_set_free_bits_func(b,v)
74
 
#endif /* UNIV_IBUF_DEBUG */
 
59
ibuf_set_free_bits(
 
60
/*===============*/
 
61
        ulint   type,   /* in: index type */
 
62
        page_t* page,   /* in: index page; free bit is reset if the index is
 
63
                        a non-clustered non-unique, and page level is 0 */
 
64
        ulint   val,    /* in: value to set: < 4 */
 
65
        ulint   max_val);/* in: ULINT_UNDEFINED or a maximum value which
 
66
                        the bits must have before setting; this is for
 
67
                        debugging */
75
68
 
76
69
/**************************************************************************
77
70
A basic partial test if an insert to the insert buffer could be possible and
86
79
                                                a secondary index when we
87
80
                                                decide */
88
81
{
89
 
        if (!dict_index_is_clust(index)
90
 
            && (ignore_sec_unique || !dict_index_is_unique(index))) {
 
82
        if (!(index->type & DICT_CLUSTERED)
 
83
            && (ignore_sec_unique || !(index->type & DICT_UNIQUE))) {
91
84
 
92
85
                ibuf_flush_count++;
93
86
 
109
102
ibuf_bitmap_page(
110
103
/*=============*/
111
104
                        /* out: TRUE if a bitmap page */
112
 
        ulint   zip_size,/* in: compressed page size in bytes;
113
 
                        0 for uncompressed pages */
114
105
        ulint   page_no)/* in: page number */
115
106
{
116
 
        ut_ad(ut_is_2pow(zip_size));
 
107
        if (page_no % XDES_DESCRIBED_PER_PAGE == FSP_IBUF_BITMAP_OFFSET) {
117
108
 
118
 
        if (!zip_size) {
119
 
                return(UNIV_UNLIKELY((page_no & (UNIV_PAGE_SIZE - 1))
120
 
                                     == FSP_IBUF_BITMAP_OFFSET));
 
109
                return(TRUE);
121
110
        }
122
111
 
123
 
        return(UNIV_UNLIKELY((page_no & (zip_size - 1))
124
 
                             == FSP_IBUF_BITMAP_OFFSET));
 
112
        return(FALSE);
125
113
}
126
114
 
127
115
/*************************************************************************
131
119
ibuf_index_page_calc_free_bits(
132
120
/*===========================*/
133
121
                                /* out: value for ibuf bitmap bits */
134
 
        ulint   zip_size,       /* in: compressed page size in bytes;
135
 
                                0 for uncompressed pages */
136
122
        ulint   max_ins_size)   /* in: maximum insert size after reorganize
137
123
                                for the page */
138
124
{
139
125
        ulint   n;
140
 
        ut_ad(ut_is_2pow(zip_size));
141
 
        ut_ad(!zip_size || zip_size > IBUF_PAGE_SIZE_PER_FREE_SPACE);
142
 
        ut_ad(zip_size <= UNIV_PAGE_SIZE);
143
126
 
144
 
        if (zip_size) {
145
 
                n = max_ins_size
146
 
                        / (zip_size / IBUF_PAGE_SIZE_PER_FREE_SPACE);
147
 
        } else {
148
 
                n = max_ins_size
149
 
                        / (UNIV_PAGE_SIZE / IBUF_PAGE_SIZE_PER_FREE_SPACE);
150
 
        }
 
127
        n = max_ins_size / (UNIV_PAGE_SIZE / IBUF_PAGE_SIZE_PER_FREE_SPACE);
151
128
 
152
129
        if (n == 3) {
153
130
                n = 2;
168
145
/*================================*/
169
146
                        /* out: maximum insert size after reorganize for the
170
147
                        page */
171
 
        ulint   zip_size,/* in: compressed page size in bytes;
172
 
                        0 for uncompressed pages */
173
148
        ulint   bits)   /* in: value for ibuf bitmap bits */
174
149
{
175
150
        ut_ad(bits < 4);
176
 
        ut_ad(ut_is_2pow(zip_size));
177
 
        ut_ad(!zip_size || zip_size > IBUF_PAGE_SIZE_PER_FREE_SPACE);
178
 
        ut_ad(zip_size <= UNIV_PAGE_SIZE);
179
 
 
180
 
        if (zip_size) {
181
 
                if (bits == 3) {
182
 
                        return(4 * zip_size / IBUF_PAGE_SIZE_PER_FREE_SPACE);
183
 
                }
184
 
 
185
 
                return(bits * zip_size / IBUF_PAGE_SIZE_PER_FREE_SPACE);
186
 
        }
187
151
 
188
152
        if (bits == 3) {
189
153
                return(4 * UNIV_PAGE_SIZE / IBUF_PAGE_SIZE_PER_FREE_SPACE);
190
154
        }
191
155
 
192
 
        return(bits * (UNIV_PAGE_SIZE / IBUF_PAGE_SIZE_PER_FREE_SPACE));
193
 
}
194
 
 
195
 
/*************************************************************************
196
 
Translates the free space on a compressed page to a value in the ibuf bitmap.*/
197
 
UNIV_INLINE
198
 
ulint
199
 
ibuf_index_page_calc_free_zip(
200
 
/*==========================*/
201
 
                                        /* out: value for ibuf bitmap bits */
202
 
        ulint                   zip_size,
203
 
                                        /* in: compressed page size in bytes */
204
 
        const buf_block_t*      block)  /* in: buffer block */
205
 
{
206
 
        ulint                   max_ins_size;
207
 
        const page_zip_des_t*   page_zip;
208
 
        lint                    zip_max_ins;
209
 
 
210
 
        ut_ad(zip_size == buf_block_get_zip_size(block));
211
 
        ut_ad(zip_size);
212
 
 
213
 
        max_ins_size = page_get_max_insert_size_after_reorganize(
214
 
                buf_block_get_frame(block), 1);
215
 
 
216
 
        page_zip = buf_block_get_page_zip(block);
217
 
        zip_max_ins = page_zip_max_ins_size(page_zip,
218
 
                                            FALSE/* not clustered */);
219
 
 
220
 
        if (UNIV_UNLIKELY(zip_max_ins < 0)) {
221
 
                return(0);
222
 
        } else if (UNIV_LIKELY(max_ins_size > (ulint) zip_max_ins)) {
223
 
                max_ins_size = (ulint) zip_max_ins;
224
 
        }
225
 
 
226
 
        return(ibuf_index_page_calc_free_bits(zip_size, max_ins_size));
 
156
        return(bits * UNIV_PAGE_SIZE / IBUF_PAGE_SIZE_PER_FREE_SPACE);
227
157
}
228
158
 
229
159
/*************************************************************************
232
162
ulint
233
163
ibuf_index_page_calc_free(
234
164
/*======================*/
235
 
                                        /* out: value for ibuf bitmap bits */
236
 
        ulint                   zip_size,/* in: compressed page size in bytes;
237
 
                                        0 for uncompressed pages */
238
 
        const buf_block_t*      block)  /* in: buffer block */
 
165
                        /* out: value for ibuf bitmap bits */
 
166
        page_t* page)   /* in: non-unique secondary index page */
239
167
{
240
 
        ut_ad(zip_size == buf_block_get_zip_size(block));
241
 
 
242
 
        if (!zip_size) {
243
 
                ulint   max_ins_size;
244
 
 
245
 
                max_ins_size = page_get_max_insert_size_after_reorganize(
246
 
                        buf_block_get_frame(block), 1);
247
 
 
248
 
                return(ibuf_index_page_calc_free_bits(0, max_ins_size));
249
 
        } else {
250
 
                return(ibuf_index_page_calc_free_zip(zip_size, block));
251
 
        }
 
168
        return(ibuf_index_page_calc_free_bits(
 
169
                       page_get_max_insert_size_after_reorganize(page, 1)));
252
170
}
253
171
 
254
172
/****************************************************************************
255
 
Updates the free bits of an uncompressed page in the ibuf bitmap if
256
 
there is not enough free on the page any more. This is done in a
257
 
separate mini-transaction, hence this operation does not restrict
258
 
further work to only ibuf bitmap operations, which would result if the
259
 
latch to the bitmap page were kept. */
 
173
Updates the free bits of the page in the ibuf bitmap if there is not enough
 
174
free on the page any more. This is done in a separate mini-transaction, hence
 
175
this operation does not restrict further work to only ibuf bitmap operations,
 
176
which would result if the latch to the bitmap page were kept. */
260
177
UNIV_INLINE
261
178
void
262
179
ibuf_update_free_bits_if_full(
263
180
/*==========================*/
264
 
        buf_block_t*    block,  /* in: index page to which we have added new
 
181
        dict_index_t*   index,  /* in: index */
 
182
        page_t*         page,   /* in: index page to which we have added new
265
183
                                records; the free bits are updated if the
266
184
                                index is non-clustered and non-unique and
267
185
                                the page level is 0, and the page becomes
276
194
        ulint   before;
277
195
        ulint   after;
278
196
 
279
 
        ut_ad(!buf_block_get_page_zip(block));
280
 
 
281
 
        before = ibuf_index_page_calc_free_bits(0, max_ins_size);
 
197
        before = ibuf_index_page_calc_free_bits(max_ins_size);
282
198
 
283
199
        if (max_ins_size >= increase) {
284
200
#if ULINT32_UNDEFINED <= UNIV_PAGE_SIZE
285
201
# error "ULINT32_UNDEFINED <= UNIV_PAGE_SIZE"
286
202
#endif
287
 
                after = ibuf_index_page_calc_free_bits(0, max_ins_size
 
203
                after = ibuf_index_page_calc_free_bits(max_ins_size
288
204
                                                       - increase);
289
205
#ifdef UNIV_IBUF_DEBUG
290
 
                ut_a(after <= ibuf_index_page_calc_free(0, block));
 
206
                ut_a(after <= ibuf_index_page_calc_free(page));
291
207
#endif
292
208
        } else {
293
 
                after = ibuf_index_page_calc_free(0, block);
 
209
                after = ibuf_index_page_calc_free(page);
294
210
        }
295
211
 
296
212
        if (after == 0) {
299
215
                cannot make inserts using the insert buffer from slipping
300
216
                out of the buffer pool */
301
217
 
302
 
                buf_page_make_young(&block->page);
 
218
                buf_page_make_young(page);
303
219
        }
304
220
 
305
221
        if (before > after) {
306
 
                ibuf_set_free_bits(block, after, before);
 
222
                ibuf_set_free_bits(index->type, page, after, before);
307
223
        }
308
224
}