~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Andrew Hutchings
  • Date: 2011-01-21 11:23:19 UTC
  • mto: (2100.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 2101.
  • Revision ID: andrew@linuxjedi.co.uk-20110121112319-nj1cvg0yt3nnf2rr
Add errors page to drizzle client docs
Add link to specific error in migration docs
Minor changes to migration docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
 
3
Copyright (C) 1995, 2010, Innobase Oy. All Rights Reserved.
4
4
 
5
5
This program is free software; you can redistribute it and/or modify it under
6
6
the terms of the GNU General Public License as published by the Free Software
11
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
12
 
13
13
You should have received a copy of the GNU General Public License along with
14
 
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15
 
Place, Suite 330, Boston, MA 02111-1307 USA
 
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
 
15
St, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
*****************************************************************************/
18
18
 
38
38
#include "srv0start.h"
39
39
#include "srv0srv.h"
40
40
 
41
 
/** The size in blocks of the area where the random read-ahead algorithm counts
42
 
the accessed pages when deciding whether to read-ahead */
43
 
#define BUF_READ_AHEAD_RANDOM_AREA      BUF_READ_AHEAD_AREA
44
 
 
45
 
/** There must be at least this many pages in buf_pool in the area to start
46
 
a random read-ahead */
47
 
#define BUF_READ_AHEAD_RANDOM_THRESHOLD (1 + BUF_READ_AHEAD_RANDOM_AREA / 2)
48
 
 
49
41
/** The linear read-ahead area size */
50
42
#define BUF_READ_AHEAD_LINEAR_AREA      BUF_READ_AHEAD_AREA
51
43
 
62
54
@return 1 if a read request was queued, 0 if the page already resided
63
55
in buf_pool, or if the page is in the doublewrite buffer blocks in
64
56
which case it is never read into the pool, or if the tablespace does
65
 
not exist or is being dropped */
 
57
not exist or is being dropped 
 
58
@return 1 if read request is issued. 0 if it is not */
66
59
static
67
60
ulint
68
61
buf_read_page_low(
165
158
}
166
159
 
167
160
/********************************************************************//**
168
 
Applies a random read-ahead in buf_pool if there are at least a threshold
169
 
value of accessed pages from the random read-ahead area. Does not read any
170
 
page, not even the one at the position (space, offset), if the read-ahead
171
 
mechanism is not activated. NOTE 1: the calling thread may own latches on
172
 
pages: to avoid deadlocks this function must be written such that it cannot
173
 
end up waiting for these latches! NOTE 2: the calling thread must want
174
 
access to the page given: this rule is set to prevent unintended read-aheads
175
 
performed by ibuf routines, a situation which could result in a deadlock if
176
 
the OS does not support asynchronous i/o.
177
 
@return number of page read requests issued; NOTE that if we read ibuf
178
 
pages, it may happen that the page at the given page number does not
179
 
get read even if we return a positive value! */
180
 
static
181
 
ulint
182
 
buf_read_ahead_random(
183
 
/*==================*/
184
 
        ulint   space,  /*!< in: space id */
185
 
        ulint   zip_size,/*!< in: compressed page size in bytes, or 0 */
186
 
        ulint   offset) /*!< in: page number of a page which the current thread
187
 
                        wants to access */
188
 
{
189
 
        (void)space;
190
 
        (void)zip_size;
191
 
        (void)offset;
192
 
        /* We have currently disabled random readahead */
193
 
        return(0);
194
 
 
195
 
}
196
 
 
197
 
/********************************************************************//**
198
161
High-level function which reads a page asynchronously from a file to the
199
162
buffer buf_pool if it is not already there. Sets the io_fix flag and sets
200
163
an exclusive lock on the buffer frame. The flag is cleared and the x-lock
201
 
released by the i/o-handler thread. Does a random read-ahead if it seems
202
 
sensible.
203
 
@return number of page read requests issued: this can be greater than
204
 
1 if read-ahead occurred */
 
164
released by the i/o-handler thread.
 
165
@return TRUE if page has been read in, FALSE in case of failure */
205
166
UNIV_INTERN
206
 
ulint
 
167
ibool
207
168
buf_read_page(
208
169
/*==========*/
209
170
        ulint   space,  /*!< in: space id */
210
171
        ulint   zip_size,/*!< in: compressed page size in bytes, or 0 */
211
172
        ulint   offset) /*!< in: page number */
212
173
{
 
174
        buf_pool_t*     buf_pool = buf_pool_get(space, offset);
213
175
        ib_int64_t      tablespace_version;
214
176
        ulint           count;
215
 
        ulint           count2;
216
177
        ulint           err;
217
178
 
218
179
        tablespace_version = fil_space_get_version(space);
219
180
 
220
 
        count = buf_read_ahead_random(space, zip_size, offset);
221
 
 
222
181
        /* We do the i/o in the synchronous aio mode to save thread
223
182
        switches: hence TRUE */
224
183
 
225
 
        count2 = buf_read_page_low(&err, TRUE, BUF_READ_ANY_PAGE, space,
226
 
                                   zip_size, FALSE,
227
 
                                   tablespace_version, offset);
228
 
        srv_buf_pool_reads+= count2;
 
184
        count = buf_read_page_low(&err, TRUE, BUF_READ_ANY_PAGE, space,
 
185
                                  zip_size, FALSE,
 
186
                                  tablespace_version, offset);
 
187
        srv_buf_pool_reads += count;
229
188
        if (err == DB_TABLESPACE_DELETED) {
230
189
                ut_print_timestamp(stderr);
231
190
                fprintf(stderr,
237
196
        }
238
197
 
239
198
        /* Flush pages from the end of the LRU list if necessary */
240
 
        buf_flush_free_margin();
 
199
        buf_flush_free_margin(buf_pool);
241
200
 
242
201
        /* Increment number of I/O operations used for LRU policy. */
243
202
        buf_LRU_stat_inc_io();
244
203
 
245
 
        return(count + count2);
 
204
        return(count);
246
205
}
247
206
 
248
207
/********************************************************************//**
278
237
        ulint   offset) /*!< in: page number of a page; NOTE: the current thread
279
238
                        must want access to this page (see NOTE 3 above) */
280
239
{
 
240
        buf_pool_t*     buf_pool = buf_pool_get(space, offset);
281
241
        ib_int64_t      tablespace_version;
282
242
        buf_page_t*     bpage;
283
243
        buf_frame_t*    frame;
293
253
        ulint           err;
294
254
        ulint           i;
295
255
        const ulint     buf_read_ahead_linear_area
296
 
                = BUF_READ_AHEAD_LINEAR_AREA;
 
256
                = BUF_READ_AHEAD_LINEAR_AREA(buf_pool);
297
257
        ulint           threshold;
298
258
 
299
259
        if (UNIV_UNLIKELY(srv_startup_is_before_trx_rollback_phase)) {
328
288
 
329
289
        tablespace_version = fil_space_get_version(space);
330
290
 
331
 
        buf_pool_mutex_enter();
 
291
        buf_pool_mutex_enter(buf_pool);
332
292
 
333
293
        if (high > fil_space_get_size(space)) {
334
 
                buf_pool_mutex_exit();
 
294
                buf_pool_mutex_exit(buf_pool);
335
295
                /* The area is not whole, return */
336
296
 
337
297
                return(0);
339
299
 
340
300
        if (buf_pool->n_pend_reads
341
301
            > buf_pool->curr_size / BUF_READ_AHEAD_PEND_LIMIT) {
342
 
                buf_pool_mutex_exit();
 
302
                buf_pool_mutex_exit(buf_pool);
343
303
 
344
304
                return(0);
345
305
        }
357
317
        /* How many out of order accessed pages can we ignore
358
318
        when working out the access pattern for linear readahead */
359
319
        threshold = ut_min((64 - srv_read_ahead_threshold),
360
 
                           BUF_READ_AHEAD_AREA);
 
320
                           BUF_READ_AHEAD_AREA(buf_pool));
361
321
 
362
322
        fail_count = 0;
363
323
 
364
324
        for (i = low; i < high; i++) {
365
 
                bpage = buf_page_hash_get(space, i);
 
325
                bpage = buf_page_hash_get(buf_pool, space, i);
366
326
 
367
 
                if ((bpage == NULL) || !buf_page_is_accessed(bpage)) {
 
327
                if (bpage == NULL || !buf_page_is_accessed(bpage)) {
368
328
                        /* Not accessed */
369
329
                        fail_count++;
370
330
 
371
331
                } else if (pred_bpage) {
372
 
                        int res = (ut_ulint_cmp(
373
 
                                       buf_page_get_LRU_position(bpage),
374
 
                                       buf_page_get_LRU_position(pred_bpage)));
 
332
                       /* Note that buf_page_is_accessed() returns
 
333
                       the time of the first access.  If some blocks
 
334
                       of the extent existed in the buffer pool at
 
335
                       the time of a linear access pattern, the first
 
336
                       access times may be nonmonotonic, even though
 
337
                       the latest access times were linear.  The
 
338
                       threshold (srv_read_ahead_factor) should help
 
339
                       a little against this. */
 
340
                       int res = ut_ulint_cmp(
 
341
                               buf_page_is_accessed(bpage),
 
342
                               buf_page_is_accessed(pred_bpage));
375
343
                        /* Accesses not in the right order */
376
344
                        if (res != 0 && res != asc_or_desc) {
377
345
                                fail_count++;
380
348
 
381
349
                if (fail_count > threshold) {
382
350
                        /* Too many failures: return */
383
 
                        buf_pool_mutex_exit();
 
351
                        buf_pool_mutex_exit(buf_pool);
384
352
                        return(0);
385
353
                }
386
354
 
392
360
        /* If we got this far, we know that enough pages in the area have
393
361
        been accessed in the right order: linear read-ahead can be sensible */
394
362
 
395
 
        bpage = buf_page_hash_get(space, offset);
 
363
        bpage = buf_page_hash_get(buf_pool, space, offset);
396
364
 
397
365
        if (bpage == NULL) {
398
 
                buf_pool_mutex_exit();
 
366
                buf_pool_mutex_exit(buf_pool);
399
367
 
400
368
                return(0);
401
369
        }
421
389
        pred_offset = fil_page_get_prev(frame);
422
390
        succ_offset = fil_page_get_next(frame);
423
391
 
424
 
        buf_pool_mutex_exit();
 
392
        buf_pool_mutex_exit(buf_pool);
425
393
 
426
394
        if ((offset == low) && (succ_offset == offset + 1)) {
427
395
 
500
468
        os_aio_simulated_wake_handler_threads();
501
469
 
502
470
        /* Flush pages from the end of the LRU list if necessary */
503
 
        buf_flush_free_margin();
 
471
        buf_flush_free_margin(buf_pool);
504
472
 
505
473
#ifdef UNIV_DEBUG
506
474
        if (buf_debug_prints && (count > 0)) {
514
482
        LRU policy decision. */
515
483
        buf_LRU_stat_inc_io();
516
484
 
517
 
        ++srv_read_ahead_seq;
 
485
        buf_pool->stat.n_ra_pages_read += count;
518
486
        return(count);
519
487
}
520
488
 
552
520
#ifdef UNIV_IBUF_DEBUG
553
521
        ut_a(n_stored < UNIV_PAGE_SIZE);
554
522
#endif
555
 
        while (buf_pool->n_pend_reads
556
 
               > buf_pool->curr_size / BUF_READ_AHEAD_PEND_LIMIT) {
557
 
                os_thread_sleep(500000);
558
 
        }
559
523
 
560
524
        for (i = 0; i < n_stored; i++) {
561
 
                ulint   zip_size = fil_space_get_zip_size(space_ids[i]);
562
 
                ulint   err;
 
525
                ulint           err;
 
526
                buf_pool_t*     buf_pool;
 
527
                ulint           zip_size = fil_space_get_zip_size(space_ids[i]);
 
528
 
 
529
                buf_pool = buf_pool_get(space_ids[i], space_versions[i]);
 
530
 
 
531
                while (buf_pool->n_pend_reads
 
532
                       > buf_pool->curr_size / BUF_READ_AHEAD_PEND_LIMIT) {
 
533
                        os_thread_sleep(500000);
 
534
                }
563
535
 
564
536
                if (UNIV_UNLIKELY(zip_size == ULINT_UNDEFINED)) {
565
537
 
584
556
 
585
557
        os_aio_simulated_wake_handler_threads();
586
558
 
587
 
        /* Flush pages from the end of the LRU list if necessary */
588
 
        buf_flush_free_margin();
 
559
        /* Flush pages from the end of all the LRU lists if necessary */
 
560
        buf_flush_free_margins();
589
561
 
590
562
#ifdef UNIV_DEBUG
591
563
        if (buf_debug_prints) {
634
606
        tablespace_version = fil_space_get_version(space);
635
607
 
636
608
        for (i = 0; i < n_stored; i++) {
 
609
                buf_pool_t*     buf_pool;
637
610
 
638
611
                count = 0;
639
612
 
640
613
                os_aio_print_debug = FALSE;
641
 
 
 
614
                buf_pool = buf_pool_get(space, page_nos[i]);
642
615
                while (buf_pool->n_pend_reads >= recv_n_pool_free_frames / 2) {
643
616
 
644
617
                        os_aio_simulated_wake_handler_threads();
645
 
                        os_thread_sleep(500000);
 
618
                        os_thread_sleep(10000);
646
619
 
647
620
                        count++;
648
621
 
649
 
                        if (count > 100) {
 
622
                        if (count > 1000) {
650
623
                                fprintf(stderr,
651
624
                                        "InnoDB: Error: InnoDB has waited for"
652
 
                                        " 50 seconds for pending\n"
 
625
                                        " 10 seconds for pending\n"
653
626
                                        "InnoDB: reads to the buffer pool to"
654
627
                                        " be finished.\n"
655
628
                                        "InnoDB: Number of pending reads %lu,"
677
650
 
678
651
        os_aio_simulated_wake_handler_threads();
679
652
 
680
 
        /* Flush pages from the end of the LRU list if necessary */
681
 
        buf_flush_free_margin();
 
653
        /* Flush pages from the end of all the LRU lists if necessary */
 
654
        buf_flush_free_margins();
682
655
 
683
656
#ifdef UNIV_DEBUG
684
657
        if (buf_debug_prints) {