~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/buf/buf0rea.c

  • Committer: Monty Taylor
  • Date: 2008-12-18 07:24:54 UTC
  • mto: This revision was merged to the branch mainline in revision 714.
  • Revision ID: monty@bitters-20081218072454-8pnep622damjgqli
Fixed one more my_time thing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (C) 1995, 2010, Innobase Oy. All Rights Reserved.
4
 
 
5
 
This program is free software; you can redistribute it and/or modify it under
6
 
the terms of the GNU General Public License as published by the Free Software
7
 
Foundation; version 2 of the License.
8
 
 
9
 
This program is distributed in the hope that it will be useful, but WITHOUT
10
 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
 
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
 
 
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., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/**************************************************//**
20
 
@file buf/buf0rea.c
 
1
/******************************************************
21
2
The database buffer read
22
3
 
 
4
(c) 1995 Innobase Oy
 
5
 
23
6
Created 11/5/1995 Heikki Tuuri
24
7
*******************************************************/
25
8
 
38
21
#include "srv0start.h"
39
22
#include "srv0srv.h"
40
23
 
41
 
/** The linear read-ahead area size */
 
24
/* The size in blocks of the area where the random read-ahead algorithm counts
 
25
the accessed pages when deciding whether to read-ahead */
 
26
#define BUF_READ_AHEAD_RANDOM_AREA      BUF_READ_AHEAD_AREA
 
27
 
 
28
/* There must be at least this many pages in buf_pool in the area to start
 
29
a random read-ahead */
 
30
#define BUF_READ_AHEAD_RANDOM_THRESHOLD (5 + buf_read_ahead_random_area / 8)
 
31
 
 
32
/* The linear read-ahead area size */
42
33
#define BUF_READ_AHEAD_LINEAR_AREA      BUF_READ_AHEAD_AREA
43
34
 
44
 
/** If there are buf_pool->curr_size per the number below pending reads, then
 
35
/* The linear read-ahead threshold */
 
36
#define LINEAR_AREA_THRESHOLD_COEF      5 / 8
 
37
 
 
38
/* If there are buf_pool->curr_size per the number below pending reads, then
45
39
read-ahead is not done: this is to prevent flooding the buffer pool with
46
40
i/o-fixed buffer blocks */
47
41
#define BUF_READ_AHEAD_PEND_LIMIT       2
48
42
 
49
 
/********************************************************************//**
 
43
/************************************************************************
50
44
Low-level function which reads a page asynchronously from a file to the
51
45
buffer buf_pool if it is not already there, in which case does nothing.
52
46
Sets the io_fix flag and sets an exclusive lock on the buffer frame. The
53
 
flag is cleared and the x-lock released by an i/o-handler thread.
54
 
@return 1 if a read request was queued, 0 if the page already resided
55
 
in buf_pool, or if the page is in the doublewrite buffer blocks in
56
 
which case it is never read into the pool, or if the tablespace does
57
 
not exist or is being dropped 
58
 
@return 1 if read request is issued. 0 if it is not */
 
47
flag is cleared and the x-lock released by an i/o-handler thread. */
59
48
static
60
49
ulint
61
50
buf_read_page_low(
62
51
/*==============*/
63
 
        ulint*  err,    /*!< out: DB_SUCCESS or DB_TABLESPACE_DELETED if we are
 
52
                        /* out: 1 if a read request was queued, 0 if the page
 
53
                        already resided in buf_pool, or if the page is in
 
54
                        the doublewrite buffer blocks in which case it is never
 
55
                        read into the pool, or if the tablespace does not
 
56
                        exist or is being dropped */
 
57
        ulint*  err,    /* out: DB_SUCCESS or DB_TABLESPACE_DELETED if we are
64
58
                        trying to read from a non-existent tablespace, or a
65
59
                        tablespace which is just now being dropped */
66
 
        ibool   sync,   /*!< in: TRUE if synchronous aio is desired */
67
 
        ulint   mode,   /*!< in: BUF_READ_IBUF_PAGES_ONLY, ...,
 
60
        ibool   sync,   /* in: TRUE if synchronous aio is desired */
 
61
        ulint   mode,   /* in: BUF_READ_IBUF_PAGES_ONLY, ...,
68
62
                        ORed to OS_AIO_SIMULATED_WAKE_LATER (see below
69
63
                        at read-ahead functions) */
70
 
        ulint   space,  /*!< in: space id */
71
 
        ulint   zip_size,/*!< in: compressed page size, or 0 */
72
 
        ibool   unzip,  /*!< in: TRUE=request uncompressed page */
73
 
        ib_int64_t tablespace_version, /*!< in: if the space memory object has
 
64
        ulint   space,  /* in: space id */
 
65
        ulint   zip_size,/* in: compressed page size, or 0 */
 
66
        ibool   unzip,  /* in: TRUE=request uncompressed page */
 
67
        ib_int64_t tablespace_version, /* in: if the space memory object has
74
68
                        this timestamp different from what we are giving here,
75
69
                        treat the tablespace as dropped; this is a timestamp we
76
70
                        use to stop dangling page reads from a tablespace
77
71
                        which we have DISCARDed + IMPORTed back */
78
 
        ulint   offset) /*!< in: page number */
 
72
        ulint   offset) /* in: page number */
79
73
{
80
74
        buf_page_t*     bpage;
81
75
        ulint           wake_later;
157
151
        return(1);
158
152
}
159
153
 
160
 
/********************************************************************//**
 
154
/************************************************************************
 
155
Applies a random read-ahead in buf_pool if there are at least a threshold
 
156
value of accessed pages from the random read-ahead area. Does not read any
 
157
page, not even the one at the position (space, offset), if the read-ahead
 
158
mechanism is not activated. NOTE 1: the calling thread may own latches on
 
159
pages: to avoid deadlocks this function must be written such that it cannot
 
160
end up waiting for these latches! NOTE 2: the calling thread must want
 
161
access to the page given: this rule is set to prevent unintended read-aheads
 
162
performed by ibuf routines, a situation which could result in a deadlock if
 
163
the OS does not support asynchronous i/o. */
 
164
static
 
165
ulint
 
166
buf_read_ahead_random(
 
167
/*==================*/
 
168
                        /* out: number of page read requests issued; NOTE
 
169
                        that if we read ibuf pages, it may happen that
 
170
                        the page at the given page number does not get
 
171
                        read even if we return a value > 0! */
 
172
        ulint   space,  /* in: space id */
 
173
        ulint   zip_size,/* in: compressed page size in bytes, or 0 */
 
174
        ulint   offset) /* in: page number of a page which the current thread
 
175
                        wants to access */
 
176
{
 
177
        ib_int64_t      tablespace_version;
 
178
        ulint           recent_blocks   = 0;
 
179
        ulint           count;
 
180
        ulint           LRU_recent_limit;
 
181
        ulint           ibuf_mode;
 
182
        ulint           low, high;
 
183
        ulint           err;
 
184
        ulint           i;
 
185
        ulint           buf_read_ahead_random_area;
 
186
 
 
187
        if (srv_startup_is_before_trx_rollback_phase) {
 
188
                /* No read-ahead to avoid thread deadlocks */
 
189
                return(0);
 
190
        }
 
191
 
 
192
        if (ibuf_bitmap_page(zip_size, offset)
 
193
            || trx_sys_hdr_page(space, offset)) {
 
194
 
 
195
                /* If it is an ibuf bitmap page or trx sys hdr, we do
 
196
                no read-ahead, as that could break the ibuf page access
 
197
                order */
 
198
 
 
199
                return(0);
 
200
        }
 
201
 
 
202
        /* Remember the tablespace version before we ask te tablespace size
 
203
        below: if DISCARD + IMPORT changes the actual .ibd file meanwhile, we
 
204
        do not try to read outside the bounds of the tablespace! */
 
205
 
 
206
        tablespace_version = fil_space_get_version(space);
 
207
 
 
208
        buf_read_ahead_random_area = BUF_READ_AHEAD_RANDOM_AREA;
 
209
 
 
210
        low  = (offset / buf_read_ahead_random_area)
 
211
                * buf_read_ahead_random_area;
 
212
        high = (offset / buf_read_ahead_random_area + 1)
 
213
                * buf_read_ahead_random_area;
 
214
        if (high > fil_space_get_size(space)) {
 
215
 
 
216
                high = fil_space_get_size(space);
 
217
        }
 
218
 
 
219
        /* Get the minimum LRU_position field value for an initial segment
 
220
        of the LRU list, to determine which blocks have recently been added
 
221
        to the start of the list. */
 
222
 
 
223
        LRU_recent_limit = buf_LRU_get_recent_limit();
 
224
 
 
225
        buf_pool_mutex_enter();
 
226
 
 
227
        if (buf_pool->n_pend_reads
 
228
            > buf_pool->curr_size / BUF_READ_AHEAD_PEND_LIMIT) {
 
229
                buf_pool_mutex_exit();
 
230
 
 
231
                return(0);
 
232
        }
 
233
 
 
234
        /* Count how many blocks in the area have been recently accessed,
 
235
        that is, reside near the start of the LRU list. */
 
236
 
 
237
        for (i = low; i < high; i++) {
 
238
                const buf_page_t*       bpage = buf_page_hash_get(space, i);
 
239
 
 
240
                if (bpage
 
241
                    && buf_page_is_accessed(bpage)
 
242
                    && (buf_page_get_LRU_position(bpage) > LRU_recent_limit)) {
 
243
 
 
244
                        recent_blocks++;
 
245
 
 
246
                        if (recent_blocks >= BUF_READ_AHEAD_RANDOM_THRESHOLD) {
 
247
 
 
248
                                buf_pool_mutex_exit();
 
249
                                goto read_ahead;
 
250
                        }
 
251
                }
 
252
        }
 
253
 
 
254
        buf_pool_mutex_exit();
 
255
        /* Do nothing */
 
256
        return(0);
 
257
 
 
258
read_ahead:
 
259
        /* Read all the suitable blocks within the area */
 
260
 
 
261
        if (ibuf_inside()) {
 
262
                ibuf_mode = BUF_READ_IBUF_PAGES_ONLY;
 
263
        } else {
 
264
                ibuf_mode = BUF_READ_ANY_PAGE;
 
265
        }
 
266
 
 
267
        count = 0;
 
268
 
 
269
        for (i = low; i < high; i++) {
 
270
                /* It is only sensible to do read-ahead in the non-sync aio
 
271
                mode: hence FALSE as the first parameter */
 
272
 
 
273
                if (!ibuf_bitmap_page(zip_size, i)) {
 
274
                        count += buf_read_page_low(
 
275
                                &err, FALSE,
 
276
                                ibuf_mode | OS_AIO_SIMULATED_WAKE_LATER,
 
277
                                space, zip_size, FALSE,
 
278
                                tablespace_version, i);
 
279
                        if (err == DB_TABLESPACE_DELETED) {
 
280
                                ut_print_timestamp(stderr);
 
281
                                fprintf(stderr,
 
282
                                        "  InnoDB: Warning: in random"
 
283
                                        " readahead trying to access\n"
 
284
                                        "InnoDB: tablespace %lu page %lu,\n"
 
285
                                        "InnoDB: but the tablespace does not"
 
286
                                        " exist or is just being dropped.\n",
 
287
                                        (ulong) space, (ulong) i);
 
288
                        }
 
289
                }
 
290
        }
 
291
 
 
292
        /* In simulated aio we wake the aio handler threads only after
 
293
        queuing all aio requests, in native aio the following call does
 
294
        nothing: */
 
295
 
 
296
        os_aio_simulated_wake_handler_threads();
 
297
 
 
298
#ifdef UNIV_DEBUG
 
299
        if (buf_debug_prints && (count > 0)) {
 
300
                fprintf(stderr,
 
301
                        "Random read-ahead space %lu offset %lu pages %lu\n",
 
302
                        (ulong) space, (ulong) offset,
 
303
                        (ulong) count);
 
304
        }
 
305
#endif /* UNIV_DEBUG */
 
306
 
 
307
        ++srv_read_ahead_rnd;
 
308
        return(count);
 
309
}
 
310
 
 
311
/************************************************************************
161
312
High-level function which reads a page asynchronously from a file to the
162
313
buffer buf_pool if it is not already there. Sets the io_fix flag and sets
163
314
an exclusive lock on the buffer frame. The flag is cleared and the x-lock
164
 
released by the i/o-handler thread.
165
 
@return TRUE if page has been read in, FALSE in case of failure */
 
315
released by the i/o-handler thread. Does a random read-ahead if it seems
 
316
sensible. */
166
317
UNIV_INTERN
167
 
ibool
 
318
ulint
168
319
buf_read_page(
169
320
/*==========*/
170
 
        ulint   space,  /*!< in: space id */
171
 
        ulint   zip_size,/*!< in: compressed page size in bytes, or 0 */
172
 
        ulint   offset) /*!< in: page number */
 
321
                        /* out: number of page read requests issued: this can
 
322
                        be > 1 if read-ahead occurred */
 
323
        ulint   space,  /* in: space id */
 
324
        ulint   zip_size,/* in: compressed page size in bytes, or 0 */
 
325
        ulint   offset) /* in: page number */
173
326
{
174
 
        buf_pool_t*     buf_pool = buf_pool_get(space, offset);
175
327
        ib_int64_t      tablespace_version;
176
328
        ulint           count;
 
329
        ulint           count2;
177
330
        ulint           err;
178
331
 
179
332
        tablespace_version = fil_space_get_version(space);
180
333
 
 
334
        count = buf_read_ahead_random(space, zip_size, offset);
 
335
 
181
336
        /* We do the i/o in the synchronous aio mode to save thread
182
337
        switches: hence TRUE */
183
338
 
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;
 
339
        count2 = buf_read_page_low(&err, TRUE, BUF_READ_ANY_PAGE, space,
 
340
                                   zip_size, FALSE,
 
341
                                   tablespace_version, offset);
 
342
        srv_buf_pool_reads+= count2;
188
343
        if (err == DB_TABLESPACE_DELETED) {
189
344
                ut_print_timestamp(stderr);
190
345
                fprintf(stderr,
196
351
        }
197
352
 
198
353
        /* Flush pages from the end of the LRU list if necessary */
199
 
        buf_flush_free_margin(buf_pool);
 
354
        buf_flush_free_margin();
200
355
 
201
356
        /* Increment number of I/O operations used for LRU policy. */
202
357
        buf_LRU_stat_inc_io();
203
358
 
204
 
        return(count);
 
359
        return(count + count2);
205
360
}
206
361
 
207
 
/********************************************************************//**
 
362
/************************************************************************
208
363
Applies linear read-ahead if in the buf_pool the page is a border page of
209
364
a linear read-ahead area and all the pages in the area have been accessed.
210
365
Does not read any page if the read-ahead mechanism is not activated. Note
226
381
latches!
227
382
NOTE 3: the calling thread must want access to the page given: this rule is
228
383
set to prevent unintended read-aheads performed by ibuf routines, a situation
229
 
which could result in a deadlock if the OS does not support asynchronous io.
230
 
@return number of page read requests issued */
 
384
which could result in a deadlock if the OS does not support asynchronous io. */
231
385
UNIV_INTERN
232
386
ulint
233
387
buf_read_ahead_linear(
234
388
/*==================*/
235
 
        ulint   space,  /*!< in: space id */
236
 
        ulint   zip_size,/*!< in: compressed page size in bytes, or 0 */
237
 
        ulint   offset) /*!< in: page number of a page; NOTE: the current thread
 
389
                        /* out: number of page read requests issued */
 
390
        ulint   space,  /* in: space id */
 
391
        ulint   zip_size,/* in: compressed page size in bytes, or 0 */
 
392
        ulint   offset) /* in: page number of a page; NOTE: the current thread
238
393
                        must want access to this page (see NOTE 3 above) */
239
394
{
240
 
        buf_pool_t*     buf_pool = buf_pool_get(space, offset);
241
395
        ib_int64_t      tablespace_version;
242
396
        buf_page_t*     bpage;
243
397
        buf_frame_t*    frame;
253
407
        ulint           err;
254
408
        ulint           i;
255
409
        const ulint     buf_read_ahead_linear_area
256
 
                = BUF_READ_AHEAD_LINEAR_AREA(buf_pool);
257
 
        ulint           threshold;
 
410
                = BUF_READ_AHEAD_LINEAR_AREA;
258
411
 
259
412
        if (UNIV_UNLIKELY(srv_startup_is_before_trx_rollback_phase)) {
260
413
                /* No read-ahead to avoid thread deadlocks */
288
441
 
289
442
        tablespace_version = fil_space_get_version(space);
290
443
 
291
 
        buf_pool_mutex_enter(buf_pool);
 
444
        buf_pool_mutex_enter();
292
445
 
293
446
        if (high > fil_space_get_size(space)) {
294
 
                buf_pool_mutex_exit(buf_pool);
 
447
                buf_pool_mutex_exit();
295
448
                /* The area is not whole, return */
296
449
 
297
450
                return(0);
299
452
 
300
453
        if (buf_pool->n_pend_reads
301
454
            > buf_pool->curr_size / BUF_READ_AHEAD_PEND_LIMIT) {
302
 
                buf_pool_mutex_exit(buf_pool);
 
455
                buf_pool_mutex_exit();
303
456
 
304
457
                return(0);
305
458
        }
314
467
                asc_or_desc = -1;
315
468
        }
316
469
 
317
 
        /* How many out of order accessed pages can we ignore
318
 
        when working out the access pattern for linear readahead */
319
 
        threshold = ut_min((64 - srv_read_ahead_threshold),
320
 
                           BUF_READ_AHEAD_AREA(buf_pool));
321
 
 
322
470
        fail_count = 0;
323
471
 
324
472
        for (i = low; i < high; i++) {
325
 
                bpage = buf_page_hash_get(buf_pool, space, i);
 
473
                bpage = buf_page_hash_get(space, i);
326
474
 
327
 
                if (bpage == NULL || !buf_page_is_accessed(bpage)) {
 
475
                if ((bpage == NULL) || !buf_page_is_accessed(bpage)) {
328
476
                        /* Not accessed */
329
477
                        fail_count++;
330
478
 
331
 
                } else if (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));
 
479
                } else if (pred_bpage
 
480
                           && (ut_ulint_cmp(
 
481
                                       buf_page_get_LRU_position(bpage),
 
482
                                       buf_page_get_LRU_position(pred_bpage))
 
483
                               != asc_or_desc)) {
343
484
                        /* Accesses not in the right order */
344
 
                        if (res != 0 && res != asc_or_desc) {
345
 
                                fail_count++;
346
 
                        }
347
 
                }
348
 
 
349
 
                if (fail_count > threshold) {
350
 
                        /* Too many failures: return */
351
 
                        buf_pool_mutex_exit(buf_pool);
352
 
                        return(0);
353
 
                }
354
 
 
355
 
                if (bpage && buf_page_is_accessed(bpage)) {
 
485
 
 
486
                        fail_count++;
356
487
                        pred_bpage = bpage;
357
488
                }
358
489
        }
359
490
 
 
491
        if (fail_count > buf_read_ahead_linear_area
 
492
            * LINEAR_AREA_THRESHOLD_COEF) {
 
493
                /* Too many failures: return */
 
494
 
 
495
                buf_pool_mutex_exit();
 
496
 
 
497
                return(0);
 
498
        }
 
499
 
360
500
        /* If we got this far, we know that enough pages in the area have
361
501
        been accessed in the right order: linear read-ahead can be sensible */
362
502
 
363
 
        bpage = buf_page_hash_get(buf_pool, space, offset);
 
503
        bpage = buf_page_hash_get(space, offset);
364
504
 
365
505
        if (bpage == NULL) {
366
 
                buf_pool_mutex_exit(buf_pool);
 
506
                buf_pool_mutex_exit();
367
507
 
368
508
                return(0);
369
509
        }
389
529
        pred_offset = fil_page_get_prev(frame);
390
530
        succ_offset = fil_page_get_next(frame);
391
531
 
392
 
        buf_pool_mutex_exit(buf_pool);
 
532
        buf_pool_mutex_exit();
393
533
 
394
534
        if ((offset == low) && (succ_offset == offset + 1)) {
395
535
 
468
608
        os_aio_simulated_wake_handler_threads();
469
609
 
470
610
        /* Flush pages from the end of the LRU list if necessary */
471
 
        buf_flush_free_margin(buf_pool);
 
611
        buf_flush_free_margin();
472
612
 
473
613
#ifdef UNIV_DEBUG
474
614
        if (buf_debug_prints && (count > 0)) {
482
622
        LRU policy decision. */
483
623
        buf_LRU_stat_inc_io();
484
624
 
485
 
        buf_pool->stat.n_ra_pages_read += count;
 
625
        ++srv_read_ahead_seq;
486
626
        return(count);
487
627
}
488
628
 
489
 
/********************************************************************//**
 
629
/************************************************************************
490
630
Issues read requests for pages which the ibuf module wants to read in, in
491
631
order to contract the insert buffer tree. Technically, this function is like
492
632
a read-ahead function. */
494
634
void
495
635
buf_read_ibuf_merge_pages(
496
636
/*======================*/
497
 
        ibool           sync,           /*!< in: TRUE if the caller
 
637
        ibool           sync,           /* in: TRUE if the caller
498
638
                                        wants this function to wait
499
639
                                        for the highest address page
500
640
                                        to get read in, before this
501
641
                                        function returns */
502
 
        const ulint*    space_ids,      /*!< in: array of space ids */
503
 
        const ib_int64_t* space_versions,/*!< in: the spaces must have
 
642
        const ulint*    space_ids,      /* in: array of space ids */
 
643
        const ib_int64_t* space_versions,/* in: the spaces must have
504
644
                                        this version number
505
645
                                        (timestamp), otherwise we
506
646
                                        discard the read; we use this
507
647
                                        to cancel reads if DISCARD +
508
648
                                        IMPORT may have changed the
509
649
                                        tablespace size */
510
 
        const ulint*    page_nos,       /*!< in: array of page numbers
 
650
        const ulint*    page_nos,       /* in: array of page numbers
511
651
                                        to read, with the highest page
512
652
                                        number the last in the
513
653
                                        array */
514
 
        ulint           n_stored)       /*!< in: number of elements
 
654
        ulint           n_stored)       /* in: number of elements
515
655
                                        in the arrays */
516
656
{
517
657
        ulint   i;
520
660
#ifdef UNIV_IBUF_DEBUG
521
661
        ut_a(n_stored < UNIV_PAGE_SIZE);
522
662
#endif
 
663
        while (buf_pool->n_pend_reads
 
664
               > buf_pool->curr_size / BUF_READ_AHEAD_PEND_LIMIT) {
 
665
                os_thread_sleep(500000);
 
666
        }
523
667
 
524
668
        for (i = 0; i < n_stored; i++) {
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
 
                }
 
669
                ulint   zip_size = fil_space_get_zip_size(space_ids[i]);
 
670
                ulint   err;
535
671
 
536
672
                if (UNIV_UNLIKELY(zip_size == ULINT_UNDEFINED)) {
537
673
 
556
692
 
557
693
        os_aio_simulated_wake_handler_threads();
558
694
 
559
 
        /* Flush pages from the end of all the LRU lists if necessary */
560
 
        buf_flush_free_margins();
 
695
        /* Flush pages from the end of the LRU list if necessary */
 
696
        buf_flush_free_margin();
561
697
 
562
698
#ifdef UNIV_DEBUG
563
699
        if (buf_debug_prints) {
568
704
#endif /* UNIV_DEBUG */
569
705
}
570
706
 
571
 
/********************************************************************//**
 
707
/************************************************************************
572
708
Issues read requests for pages which recovery wants to read in. */
573
709
UNIV_INTERN
574
710
void
575
711
buf_read_recv_pages(
576
712
/*================*/
577
 
        ibool           sync,           /*!< in: TRUE if the caller
 
713
        ibool           sync,           /* in: TRUE if the caller
578
714
                                        wants this function to wait
579
715
                                        for the highest address page
580
716
                                        to get read in, before this
581
717
                                        function returns */
582
 
        ulint           space,          /*!< in: space id */
583
 
        ulint           zip_size,       /*!< in: compressed page size in
 
718
        ulint           space,          /* in: space id */
 
719
        ulint           zip_size,       /* in: compressed page size in
584
720
                                        bytes, or 0 */
585
 
        const ulint*    page_nos,       /*!< in: array of page numbers
 
721
        const ulint*    page_nos,       /* in: array of page numbers
586
722
                                        to read, with the highest page
587
723
                                        number the last in the
588
724
                                        array */
589
 
        ulint           n_stored)       /*!< in: number of page numbers
 
725
        ulint           n_stored)       /* in: number of page numbers
590
726
                                        in the array */
591
727
{
592
728
        ib_int64_t      tablespace_version;
595
731
        ulint           i;
596
732
 
597
733
        zip_size = fil_space_get_zip_size(space);
598
 
 
599
 
        if (UNIV_UNLIKELY(zip_size == ULINT_UNDEFINED)) {
600
 
                /* It is a single table tablespace and the .ibd file is
601
 
                missing: do nothing */
602
 
 
603
 
                return;
604
 
        }
605
 
 
606
734
        tablespace_version = fil_space_get_version(space);
607
735
 
608
736
        for (i = 0; i < n_stored; i++) {
609
 
                buf_pool_t*     buf_pool;
610
737
 
611
738
                count = 0;
612
739
 
613
740
                os_aio_print_debug = FALSE;
614
 
                buf_pool = buf_pool_get(space, page_nos[i]);
 
741
 
615
742
                while (buf_pool->n_pend_reads >= recv_n_pool_free_frames / 2) {
616
743
 
617
744
                        os_aio_simulated_wake_handler_threads();
618
 
                        os_thread_sleep(10000);
 
745
                        os_thread_sleep(500000);
619
746
 
620
747
                        count++;
621
748
 
622
 
                        if (count > 1000) {
 
749
                        if (count > 100) {
623
750
                                fprintf(stderr,
624
751
                                        "InnoDB: Error: InnoDB has waited for"
625
 
                                        " 10 seconds for pending\n"
 
752
                                        " 50 seconds for pending\n"
626
753
                                        "InnoDB: reads to the buffer pool to"
627
754
                                        " be finished.\n"
628
755
                                        "InnoDB: Number of pending reads %lu,"
650
777
 
651
778
        os_aio_simulated_wake_handler_threads();
652
779
 
653
 
        /* Flush pages from the end of all the LRU lists if necessary */
654
 
        buf_flush_free_margins();
 
780
        /* Flush pages from the end of the LRU list if necessary */
 
781
        buf_flush_free_margin();
655
782
 
656
783
#ifdef UNIV_DEBUG
657
784
        if (buf_debug_prints) {