~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/ibuf/ibuf0ibuf.c

  • Committer: Monty Taylor
  • Date: 2009-04-14 19:16:51 UTC
  • mto: (997.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 994.
  • Revision ID: mordred@inaugust.com-20090414191651-ltbww6hpqks8k7qk
Clarified instructions in README.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
*****************************************************************************/
18
18
 
19
 
/**************************************************//**
20
 
@file ibuf/ibuf0ibuf.c
 
19
/******************************************************
21
20
Insert buffer
22
21
 
23
22
Created 7/19/1997 Heikki Tuuri
25
24
 
26
25
#include "ibuf0ibuf.h"
27
26
 
28
 
/** Number of bits describing a single page */
29
 
#define IBUF_BITS_PER_PAGE      4
30
 
#if IBUF_BITS_PER_PAGE % 2
31
 
# error "IBUF_BITS_PER_PAGE must be an even number!"
32
 
#endif
33
 
/** The start address for an insert buffer bitmap page bitmap */
34
 
#define IBUF_BITMAP             PAGE_DATA
35
 
 
36
27
#ifdef UNIV_NONINL
37
28
#include "ibuf0ibuf.ic"
38
29
#endif
39
30
 
40
 
#ifndef UNIV_HOTBACKUP
41
 
 
42
31
#include "buf0buf.h"
43
32
#include "buf0rea.h"
44
33
#include "fsp0fsp.h"
161
150
it uses synchronous aio, it can access any pages, as long as it obeys the
162
151
access order rules. */
163
152
 
164
 
/** Buffer pool size per the maximum insert buffer size */
 
153
/* Buffer pool size per the maximum insert buffer size */
165
154
#define IBUF_POOL_SIZE_PER_MAX_SIZE     2
166
155
 
167
 
/** Table name for the insert buffer. */
 
156
/* Table name for the insert buffer. */
168
157
#define IBUF_TABLE_NAME         "SYS_IBUF_TABLE"
169
158
 
170
159
/** Operations that can currently be buffered. */
173
162
/** The insert buffer control structure */
174
163
UNIV_INTERN ibuf_t*     ibuf                    = NULL;
175
164
 
176
 
/** Counter for ibuf_should_try() */
177
165
UNIV_INTERN ulint       ibuf_flush_count        = 0;
178
166
 
179
167
#ifdef UNIV_IBUF_COUNT_DEBUG
180
 
/** Number of tablespaces in the ibuf_counts array */
 
168
/* Dimensions for the ibuf_count array */
181
169
#define IBUF_COUNT_N_SPACES     4
182
 
/** Number of pages within each tablespace in the ibuf_counts array */
183
170
#define IBUF_COUNT_N_PAGES      130000
184
171
 
185
 
/** Buffered entry counts for file pages, used in debugging */
 
172
/* Buffered entry counts for file pages, used in debugging */
186
173
static ulint    ibuf_counts[IBUF_COUNT_N_SPACES][IBUF_COUNT_N_PAGES];
187
174
 
188
 
/******************************************************************//**
 
175
/**********************************************************************
189
176
Checks that the indexes to ibuf_counts[][] are within limits. */
190
177
UNIV_INLINE
191
178
void
192
179
ibuf_count_check(
193
180
/*=============*/
194
 
        ulint   space_id,       /*!< in: space identifier */
195
 
        ulint   page_no)        /*!< in: page number */
 
181
        ulint   space_id,       /* in: space identifier */
 
182
        ulint   page_no)        /* in: page number */
196
183
{
197
184
        if (space_id < IBUF_COUNT_N_SPACES && page_no < IBUF_COUNT_N_PAGES) {
198
185
                return;
209
196
}
210
197
#endif
211
198
 
212
 
/** @name Offsets to the per-page bits in the insert buffer bitmap */
213
 
/* @{ */
214
 
#define IBUF_BITMAP_FREE        0       /*!< Bits indicating the
215
 
                                        amount of free space */
216
 
#define IBUF_BITMAP_BUFFERED    2       /*!< TRUE if there are buffered
217
 
                                        changes for the page */
218
 
#define IBUF_BITMAP_IBUF        3       /*!< TRUE if page is a part of
219
 
                                        the ibuf tree, excluding the
220
 
                                        root page, or is in the free
221
 
                                        list of the ibuf */
222
 
/* @} */
223
 
 
224
 
/** The mutex used to block pessimistic inserts to ibuf trees */
 
199
/* The start address for an insert buffer bitmap page bitmap */
 
200
#define IBUF_BITMAP             PAGE_DATA
 
201
 
 
202
/* Offsets in bits for the bits describing a single page in the bitmap */
 
203
#define IBUF_BITMAP_FREE        0
 
204
#define IBUF_BITMAP_BUFFERED    2
 
205
#define IBUF_BITMAP_IBUF        3       /* TRUE if page is a part of the ibuf
 
206
                                        tree, excluding the root page, or is
 
207
                                        in the free list of the ibuf */
 
208
 
 
209
/* Number of bits describing a single page */
 
210
#define IBUF_BITS_PER_PAGE      4
 
211
#if IBUF_BITS_PER_PAGE % 2
 
212
# error "IBUF_BITS_PER_PAGE must be an even number!"
 
213
#endif
 
214
 
 
215
/* The mutex used to block pessimistic inserts to ibuf trees */
225
216
static mutex_t  ibuf_pessimistic_insert_mutex;
226
217
 
227
 
/** The mutex protecting the insert buffer structs */
 
218
/* The mutex protecting the insert buffer structs */
228
219
static mutex_t  ibuf_mutex;
229
220
 
230
 
/** The mutex protecting the insert buffer bitmaps */
 
221
/* The mutex protecting the insert buffer bitmaps */
231
222
static mutex_t  ibuf_bitmap_mutex;
232
223
 
233
 
/** The area in pages from which contract looks for page numbers for merge */
 
224
/* The area in pages from which contract looks for page numbers for merge */
234
225
#define IBUF_MERGE_AREA                 8
235
226
 
236
 
/** Inside the merge area, pages which have at most 1 per this number less
 
227
/* Inside the merge area, pages which have at most 1 per this number less
237
228
buffered entries compared to maximum volume that can buffered for a single
238
229
page are merged along with the page whose buffer became full */
239
230
#define IBUF_MERGE_THRESHOLD            4
240
231
 
241
 
/** In ibuf_contract at most this number of pages is read to memory in one
 
232
/* In ibuf_contract at most this number of pages is read to memory in one
242
233
batch, in order to merge the entries for them in the insert buffer */
243
234
#define IBUF_MAX_N_PAGES_MERGED         IBUF_MERGE_AREA
244
235
 
245
 
/** If the combined size of the ibuf trees exceeds ibuf->max_size by this
 
236
/* If the combined size of the ibuf trees exceeds ibuf->max_size by this
246
237
many pages, we start to contract it in connection to inserts there, using
247
238
non-synchronous contract */
248
239
#define IBUF_CONTRACT_ON_INSERT_NON_SYNC        0
249
240
 
250
 
/** If the combined size of the ibuf trees exceeds ibuf->max_size by this
251
 
many pages, we start to contract it in connection to inserts there, using
252
 
synchronous contract */
 
241
/* Same as above, but use synchronous contract */
253
242
#define IBUF_CONTRACT_ON_INSERT_SYNC            5
254
243
 
255
 
/** If the combined size of the ibuf trees exceeds ibuf->max_size by
256
 
this many pages, we start to contract it synchronous contract, but do
257
 
not insert */
 
244
/* Same as above, but no insert is done, only contract is called */
258
245
#define IBUF_CONTRACT_DO_NOT_INSERT             10
259
246
 
260
247
/* TODO: how to cope with drop table if there are records in the insert
263
250
still physically like the index page even if the index would have been
264
251
dropped! So, there seems to be no problem. */
265
252
 
266
 
/******************************************************************//**
 
253
/**********************************************************************
267
254
Sets the flag in the current OS thread local storage denoting that it is
268
255
inside an insert buffer routine. */
269
256
UNIV_INLINE
280
267
        *ptr = TRUE;
281
268
}
282
269
 
283
 
/******************************************************************//**
 
270
/**********************************************************************
284
271
Sets the flag in the current OS thread local storage denoting that it is
285
272
exiting an insert buffer routine. */
286
273
UNIV_INLINE
297
284
        *ptr = FALSE;
298
285
}
299
286
 
300
 
/******************************************************************//**
 
287
/**********************************************************************
301
288
Returns TRUE if the current OS thread is performing an insert buffer
302
 
routine.
303
 
 
304
 
For instance, a read-ahead of non-ibuf pages is forbidden by threads
305
 
that are executing an insert buffer routine.
306
 
@return TRUE if inside an insert buffer routine */
 
289
routine. */
307
290
UNIV_INTERN
308
291
ibool
309
292
ibuf_inside(void)
310
293
/*=============*/
 
294
                /* out: TRUE if inside an insert buffer routine: for instance,
 
295
                a read-ahead of non-ibuf pages is then forbidden */
311
296
{
312
297
        return(*thr_local_get_in_ibuf_field());
313
298
}
314
299
 
315
 
/******************************************************************//**
316
 
Gets the ibuf header page and x-latches it.
317
 
@return insert buffer header page */
 
300
/**********************************************************************
 
301
Gets the ibuf header page and x-latches it. */
318
302
static
319
303
page_t*
320
304
ibuf_header_page_get(
321
305
/*=================*/
322
 
        mtr_t*  mtr)    /*!< in: mtr */
 
306
                        /* out: insert buffer header page */
 
307
        mtr_t*  mtr)    /* in: mtr */
323
308
{
324
309
        buf_block_t*    block;
325
310
 
332
317
        return(buf_block_get_frame(block));
333
318
}
334
319
 
335
 
/******************************************************************//**
336
 
Gets the root page and x-latches it.
337
 
@return insert buffer tree root page */
 
320
/**********************************************************************
 
321
Gets the root page and x-latches it. */
338
322
static
339
323
page_t*
340
324
ibuf_tree_root_get(
341
325
/*===============*/
342
 
        mtr_t*          mtr)    /*!< in: mtr */
 
326
                                /* out: insert buffer tree root page */
 
327
        mtr_t*          mtr)    /* in: mtr */
343
328
{
344
329
        buf_block_t*    block;
345
330
 
356
341
}
357
342
 
358
343
#ifdef UNIV_IBUF_COUNT_DEBUG
359
 
/******************************************************************//**
360
 
Gets the ibuf count for a given page.
361
 
@return number of entries in the insert buffer currently buffered for
362
 
this page */
 
344
/**********************************************************************
 
345
Gets the ibuf count for a given page. */
363
346
UNIV_INTERN
364
347
ulint
365
348
ibuf_count_get(
366
349
/*===========*/
367
 
        ulint   space,  /*!< in: space id */
368
 
        ulint   page_no)/*!< in: page number */
 
350
                        /* out: number of entries in the insert buffer
 
351
                        currently buffered for this page */
 
352
        ulint   space,  /* in: space id */
 
353
        ulint   page_no)/* in: page number */
369
354
{
370
355
        ibuf_count_check(space, page_no);
371
356
 
372
357
        return(ibuf_counts[space][page_no]);
373
358
}
374
359
 
375
 
/******************************************************************//**
 
360
/**********************************************************************
376
361
Sets the ibuf count for a given page. */
377
362
static
378
363
void
379
364
ibuf_count_set(
380
365
/*===========*/
381
 
        ulint   space,  /*!< in: space id */
382
 
        ulint   page_no,/*!< in: page number */
383
 
        ulint   val)    /*!< in: value to set */
 
366
        ulint   space,  /* in: space id */
 
367
        ulint   page_no,/* in: page number */
 
368
        ulint   val)    /* in: value to set */
384
369
{
385
370
        ibuf_count_check(space, page_no);
386
371
        ut_a(val < UNIV_PAGE_SIZE);
389
374
}
390
375
#endif
391
376
 
392
 
/******************************************************************//**
 
377
/**********************************************************************
393
378
Updates the size information of the ibuf, assuming the segment size has not
394
379
changed. */
395
380
static
396
381
void
397
382
ibuf_size_update(
398
383
/*=============*/
399
 
        const page_t*   root,   /*!< in: ibuf tree root */
400
 
        mtr_t*          mtr)    /*!< in: mtr */
 
384
        const page_t*   root,   /* in: ibuf tree root */
 
385
        mtr_t*          mtr)    /* in: mtr */
401
386
{
402
387
        ut_ad(mutex_own(&ibuf_mutex));
403
388
 
412
397
        ibuf->empty = page_get_n_recs(root) == 0;
413
398
}
414
399
 
415
 
/******************************************************************//**
 
400
/**********************************************************************
416
401
Creates the insert buffer data structure at a database startup and initializes
417
402
the data structures for the insert buffer. */
418
403
UNIV_INTERN
507
492
 
508
493
        ibuf->index = dict_table_get_first_index(table);
509
494
}
510
 
#endif /* !UNIV_HOTBACKUP */
511
 
/*********************************************************************//**
 
495
 
 
496
/*************************************************************************
512
497
Initializes an ibuf bitmap page. */
513
498
UNIV_INTERN
514
499
void
515
500
ibuf_bitmap_page_init(
516
501
/*==================*/
517
 
        buf_block_t*    block,  /*!< in: bitmap page */
518
 
        mtr_t*          mtr)    /*!< in: mtr */
 
502
        buf_block_t*    block,  /* in: bitmap page */
 
503
        mtr_t*          mtr)    /* in: mtr */
519
504
{
520
505
        page_t* page;
521
506
        ulint   byte_offset;
539
524
 
540
525
        /* The remaining area (up to the page trailer) is uninitialized. */
541
526
 
542
 
#ifndef UNIV_HOTBACKUP
543
527
        mlog_write_initial_log_record(page, MLOG_IBUF_BITMAP_INIT, mtr);
544
 
#endif /* !UNIV_HOTBACKUP */
545
528
}
546
529
 
547
 
/*********************************************************************//**
548
 
Parses a redo log record of an ibuf bitmap page init.
549
 
@return end of log record or NULL */
 
530
/*************************************************************************
 
531
Parses a redo log record of an ibuf bitmap page init. */
550
532
UNIV_INTERN
551
533
byte*
552
534
ibuf_parse_bitmap_init(
553
535
/*===================*/
554
 
        byte*           ptr,    /*!< in: buffer */
555
 
        byte*           end_ptr __attribute__((unused)), /*!< in: buffer end */
556
 
        buf_block_t*    block,  /*!< in: block or NULL */
557
 
        mtr_t*          mtr)    /*!< in: mtr or NULL */
 
536
                                /* out: end of log record or NULL */
 
537
        byte*           ptr,    /* in: buffer */
 
538
        byte*           end_ptr __attribute__((unused)), /* in: buffer end */
 
539
        buf_block_t*    block,  /* in: block or NULL */
 
540
        mtr_t*          mtr)    /* in: mtr or NULL */
558
541
{
559
542
        ut_ad(ptr && end_ptr);
560
543
 
564
547
 
565
548
        return(ptr);
566
549
}
567
 
#ifndef UNIV_HOTBACKUP
568
 
/********************************************************************//**
569
 
Gets the desired bits for a given page from a bitmap page.
570
 
@return value of bits */
 
550
 
 
551
/************************************************************************
 
552
Gets the desired bits for a given page from a bitmap page. */
571
553
UNIV_INLINE
572
554
ulint
573
555
ibuf_bitmap_page_get_bits(
574
556
/*======================*/
575
 
        const page_t*   page,   /*!< in: bitmap page */
576
 
        ulint           page_no,/*!< in: page whose bits to get */
577
 
        ulint           zip_size,/*!< in: compressed page size in bytes;
 
557
                                /* out: value of bits */
 
558
        const page_t*   page,   /* in: bitmap page */
 
559
        ulint           page_no,/* in: page whose bits to get */
 
560
        ulint           zip_size,/* in: compressed page size in bytes;
578
561
                                0 for uncompressed pages */
579
 
        ulint           bit,    /*!< in: IBUF_BITMAP_FREE,
 
562
        ulint           bit,    /* in: IBUF_BITMAP_FREE,
580
563
                                IBUF_BITMAP_BUFFERED, ... */
581
564
        mtr_t*          mtr __attribute__((unused)))
582
 
                                /*!< in: mtr containing an
 
565
                                /* in: mtr containing an
583
566
                                x-latch to the bitmap page */
584
567
{
585
568
        ulint   byte_offset;
620
603
        return(value);
621
604
}
622
605
 
623
 
/********************************************************************//**
 
606
/************************************************************************
624
607
Sets the desired bit for a given page in a bitmap page. */
625
608
static
626
609
void
627
610
ibuf_bitmap_page_set_bits(
628
611
/*======================*/
629
 
        page_t* page,   /*!< in: bitmap page */
630
 
        ulint   page_no,/*!< in: page whose bits to set */
631
 
        ulint   zip_size,/*!< in: compressed page size in bytes;
 
612
        page_t* page,   /* in: bitmap page */
 
613
        ulint   page_no,/* in: page whose bits to set */
 
614
        ulint   zip_size,/* in: compressed page size in bytes;
632
615
                        0 for uncompressed pages */
633
 
        ulint   bit,    /*!< in: IBUF_BITMAP_FREE, IBUF_BITMAP_BUFFERED, ... */
634
 
        ulint   val,    /*!< in: value to set */
635
 
        mtr_t*  mtr)    /*!< in: mtr containing an x-latch to the bitmap page */
 
616
        ulint   bit,    /* in: IBUF_BITMAP_FREE, IBUF_BITMAP_BUFFERED, ... */
 
617
        ulint   val,    /* in: value to set */
 
618
        mtr_t*  mtr)    /* in: mtr containing an x-latch to the bitmap page */
636
619
{
637
620
        ulint   byte_offset;
638
621
        ulint   bit_offset;
679
662
                         MLOG_1BYTE, mtr);
680
663
}
681
664
 
682
 
/********************************************************************//**
683
 
Calculates the bitmap page number for a given page number.
684
 
@return the bitmap page number where the file page is mapped */
 
665
/************************************************************************
 
666
Calculates the bitmap page number for a given page number. */
685
667
UNIV_INLINE
686
668
ulint
687
669
ibuf_bitmap_page_no_calc(
688
670
/*=====================*/
689
 
        ulint   zip_size,       /*!< in: compressed page size in bytes;
 
671
                                /* out: the bitmap page number where
 
672
                                the file page is mapped */
 
673
        ulint   zip_size,       /* in: compressed page size in bytes;
690
674
                                0 for uncompressed pages */
691
 
        ulint   page_no)        /*!< in: tablespace page number */
 
675
        ulint   page_no)        /* in: tablespace page number */
692
676
{
693
677
        ut_ad(ut_is_2pow(zip_size));
694
678
 
701
685
        }
702
686
}
703
687
 
704
 
/********************************************************************//**
 
688
/************************************************************************
705
689
Gets the ibuf bitmap page where the bits describing a given file page are
706
 
stored.
707
 
@return bitmap page where the file page is mapped, that is, the bitmap
708
 
page containing the descriptor bits for the file page; the bitmap page
709
 
is x-latched */
 
690
stored. */
710
691
static
711
692
page_t*
712
693
ibuf_bitmap_get_map_page(
713
694
/*=====================*/
714
 
        ulint   space,  /*!< in: space id of the file page */
715
 
        ulint   page_no,/*!< in: page number of the file page */
716
 
        ulint   zip_size,/*!< in: compressed page size in bytes;
 
695
                        /* out: bitmap page where the file page is mapped,
 
696
                        that is, the bitmap page containing the descriptor
 
697
                        bits for the file page; the bitmap page is
 
698
                        x-latched */
 
699
        ulint   space,  /* in: space id of the file page */
 
700
        ulint   page_no,/* in: page number of the file page */
 
701
        ulint   zip_size,/* in: compressed page size in bytes;
717
702
                        0 for uncompressed pages */
718
 
        mtr_t*  mtr)    /*!< in: mtr */
 
703
        mtr_t*  mtr)    /* in: mtr */
719
704
{
720
705
        buf_block_t*    block;
721
706
 
727
712
        return(buf_block_get_frame(block));
728
713
}
729
714
 
730
 
/************************************************************************//**
 
715
/****************************************************************************
731
716
Sets the free bits of the page in the ibuf bitmap. This is done in a separate
732
717
mini-transaction, hence this operation does not restrict further work to only
733
718
ibuf bitmap operations, which would result if the latch to the bitmap page
736
721
void
737
722
ibuf_set_free_bits_low(
738
723
/*===================*/
739
 
        ulint                   zip_size,/*!< in: compressed page size in bytes;
 
724
        ulint                   zip_size,/* in: compressed page size in bytes;
740
725
                                        0 for uncompressed pages */
741
 
        const buf_block_t*      block,  /*!< in: index page; free bits are set if
 
726
        const buf_block_t*      block,  /* in: index page; free bits are set if
742
727
                                        the index is non-clustered and page
743
728
                                        level is 0 */
744
 
        ulint                   val,    /*!< in: value to set: < 4 */
745
 
        mtr_t*                  mtr)    /*!< in/out: mtr */
 
729
        ulint                   val,    /* in: value to set: < 4 */
 
730
        mtr_t*                  mtr)    /* in/out: mtr */
746
731
{
747
732
        page_t* bitmap_page;
748
733
        ulint   space;
770
755
                                  IBUF_BITMAP_FREE, val, mtr);
771
756
}
772
757
 
773
 
/************************************************************************//**
 
758
/****************************************************************************
774
759
Sets the free bit of the page in the ibuf bitmap. This is done in a separate
775
760
mini-transaction, hence this operation does not restrict further work to only
776
761
ibuf bitmap operations, which would result if the latch to the bitmap page
779
764
void
780
765
ibuf_set_free_bits_func(
781
766
/*====================*/
782
 
        buf_block_t*    block,  /*!< in: index page of a non-clustered index;
 
767
        buf_block_t*    block,  /* in: index page of a non-clustered index;
783
768
                                free bit is reset if page level is 0 */
784
769
#ifdef UNIV_IBUF_DEBUG
785
 
        ulint           max_val,/*!< in: ULINT_UNDEFINED or a maximum
 
770
        ulint           max_val,/* in: ULINT_UNDEFINED or a maximum
786
771
                                value which the bits must have before
787
772
                                setting; this is for debugging */
788
773
#endif /* UNIV_IBUF_DEBUG */
789
 
        ulint           val)    /*!< in: value to set: < 4 */
 
774
        ulint           val)    /* in: value to set: < 4 */
790
775
{
791
776
        mtr_t   mtr;
792
777
        page_t* page;
840
825
        mtr_commit(&mtr);
841
826
}
842
827
 
843
 
/************************************************************************//**
 
828
/****************************************************************************
844
829
Resets the free bits of the page in the ibuf bitmap. This is done in a
845
830
separate mini-transaction, hence this operation does not restrict
846
831
further work to only ibuf bitmap operations, which would result if the
853
838
void
854
839
ibuf_reset_free_bits(
855
840
/*=================*/
856
 
        buf_block_t*    block)  /*!< in: index page; free bits are set to 0
 
841
        buf_block_t*    block)  /* in: index page; free bits are set to 0
857
842
                                if the index is a non-clustered
858
843
                                non-unique, and page level is 0 */
859
844
{
860
845
        ibuf_set_free_bits(block, 0, ULINT_UNDEFINED);
861
846
}
862
847
 
863
 
/**********************************************************************//**
 
848
/**************************************************************************
864
849
Updates the free bits for an uncompressed page to reflect the present
865
850
state.  Does this in the mtr given, which means that the latching
866
851
order rules virtually prevent any further operations for this OS
872
857
void
873
858
ibuf_update_free_bits_low(
874
859
/*======================*/
875
 
        const buf_block_t*      block,          /*!< in: index page */
876
 
        ulint                   max_ins_size,   /*!< in: value of
 
860
        const buf_block_t*      block,          /* in: index page */
 
861
        ulint                   max_ins_size,   /* in: value of
877
862
                                                maximum insert size
878
863
                                                with reorganize before
879
864
                                                the latest operation
880
865
                                                performed to the page */
881
 
        mtr_t*                  mtr)            /*!< in/out: mtr */
 
866
        mtr_t*                  mtr)            /* in/out: mtr */
882
867
{
883
868
        ulint   before;
884
869
        ulint   after;
898
883
        }
899
884
}
900
885
 
901
 
/**********************************************************************//**
 
886
/**************************************************************************
902
887
Updates the free bits for a compressed page to reflect the present
903
888
state.  Does this in the mtr given, which means that the latching
904
889
order rules virtually prevent any further operations for this OS
910
895
void
911
896
ibuf_update_free_bits_zip(
912
897
/*======================*/
913
 
        buf_block_t*    block,  /*!< in/out: index page */
914
 
        mtr_t*          mtr)    /*!< in/out: mtr */
 
898
        buf_block_t*    block,  /* in/out: index page */
 
899
        mtr_t*          mtr)    /* in/out: mtr */
915
900
{
916
901
        page_t* bitmap_page;
917
902
        ulint   space;
943
928
                                  IBUF_BITMAP_FREE, after, mtr);
944
929
}
945
930
 
946
 
/**********************************************************************//**
 
931
/**************************************************************************
947
932
Updates the free bits for the two pages to reflect the present state.
948
933
Does this in the mtr given, which means that the latching order rules
949
934
virtually prevent any further operations until mtr is committed.
954
939
void
955
940
ibuf_update_free_bits_for_two_pages_low(
956
941
/*====================================*/
957
 
        ulint           zip_size,/*!< in: compressed page size in bytes;
 
942
        ulint           zip_size,/* in: compressed page size in bytes;
958
943
                                0 for uncompressed pages */
959
 
        buf_block_t*    block1, /*!< in: index page */
960
 
        buf_block_t*    block2, /*!< in: index page */
961
 
        mtr_t*          mtr)    /*!< in: mtr */
 
944
        buf_block_t*    block1, /* in: index page */
 
945
        buf_block_t*    block2, /* in: index page */
 
946
        mtr_t*          mtr)    /* in: mtr */
962
947
{
963
948
        ulint   state;
964
949
 
979
964
        mutex_exit(&ibuf_bitmap_mutex);
980
965
}
981
966
 
982
 
/**********************************************************************//**
983
 
Returns TRUE if the page is one of the fixed address ibuf pages.
984
 
@return TRUE if a fixed address ibuf i/o page */
 
967
/**************************************************************************
 
968
Returns TRUE if the page is one of the fixed address ibuf pages. */
985
969
UNIV_INLINE
986
970
ibool
987
971
ibuf_fixed_addr_page(
988
972
/*=================*/
989
 
        ulint   space,  /*!< in: space id */
990
 
        ulint   zip_size,/*!< in: compressed page size in bytes;
 
973
                        /* out: TRUE if a fixed address ibuf i/o page */
 
974
        ulint   space,  /* in: space id */
 
975
        ulint   zip_size,/* in: compressed page size in bytes;
991
976
                        0 for uncompressed pages */
992
 
        ulint   page_no)/*!< in: page number */
 
977
        ulint   page_no)/* in: page number */
993
978
{
994
979
        return((space == IBUF_SPACE_ID && page_no == IBUF_TREE_ROOT_PAGE_NO)
995
980
               || ibuf_bitmap_page(zip_size, page_no));
996
981
}
997
982
 
998
 
/***********************************************************************//**
 
983
/***************************************************************************
999
984
Checks if a page is a level 2 or 3 page in the ibuf hierarchy of pages.
1000
 
Must not be called when recv_no_ibuf_operations==TRUE.
1001
 
@return TRUE if level 2 or level 3 page */
 
985
Must not be called when recv_no_ibuf_operations==TRUE. */
1002
986
UNIV_INTERN
1003
987
ibool
1004
988
ibuf_page(
1005
989
/*======*/
1006
 
        ulint   space,  /*!< in: space id */
1007
 
        ulint   zip_size,/*!< in: compressed page size in bytes, or 0 */
1008
 
        ulint   page_no,/*!< in: page number */
1009
 
        mtr_t*  mtr)    /*!< in: mtr which will contain an x-latch to the
 
990
                        /* out: TRUE if level 2 or level 3 page */
 
991
        ulint   space,  /* in: space id */
 
992
        ulint   zip_size,/* in: compressed page size in bytes, or 0 */
 
993
        ulint   page_no,/* in: page number */
 
994
        mtr_t*  mtr)    /* in: mtr which will contain an x-latch to the
1010
995
                        bitmap page if the page is not one of the fixed
1011
996
                        address ibuf pages, or NULL, in which case a new
1012
997
                        transaction is created. */
1044
1029
        return(ret);
1045
1030
}
1046
1031
 
1047
 
/********************************************************************//**
1048
 
Returns the page number field of an ibuf record.
1049
 
@return page number */
 
1032
/************************************************************************
 
1033
Returns the page number field of an ibuf record. */
1050
1034
static
1051
1035
ulint
1052
1036
ibuf_rec_get_page_no(
1053
1037
/*=================*/
1054
 
        const rec_t*    rec)    /*!< in: ibuf record */
 
1038
                                /* out: page number */
 
1039
        const rec_t*    rec)    /* in: ibuf record */
1055
1040
{
1056
1041
        const byte*     field;
1057
1042
        ulint           len;
1078
1063
        return(mach_read_from_4(field));
1079
1064
}
1080
1065
 
1081
 
/********************************************************************//**
 
1066
/************************************************************************
1082
1067
Returns the space id field of an ibuf record. For < 4.1.x format records
1083
 
returns 0.
1084
 
@return space id */
 
1068
returns 0. */
1085
1069
static
1086
1070
ulint
1087
1071
ibuf_rec_get_space(
1088
1072
/*===============*/
1089
 
        const rec_t*    rec)    /*!< in: ibuf record */
 
1073
                                /* out: space id */
 
1074
        const rec_t*    rec)    /* in: ibuf record */
1090
1075
{
1091
1076
        const byte*     field;
1092
1077
        ulint           len;
1112
1097
        return(0);
1113
1098
}
1114
1099
 
1115
 
/********************************************************************//**
 
1100
/************************************************************************
1116
1101
Creates a dummy index for inserting a record to a non-clustered index.
1117
 
 
1118
 
@return dummy index */
 
1102
*/
1119
1103
static
1120
1104
dict_index_t*
1121
1105
ibuf_dummy_index_create(
1122
1106
/*====================*/
1123
 
        ulint           n,      /*!< in: number of fields */
1124
 
        ibool           comp)   /*!< in: TRUE=use compact record format */
 
1107
                                /* out: dummy index */
 
1108
        ulint           n,      /* in: number of fields */
 
1109
        ibool           comp)   /* in: TRUE=use compact record format */
1125
1110
{
1126
1111
        dict_table_t*   table;
1127
1112
        dict_index_t*   index;
1140
1125
 
1141
1126
        return(index);
1142
1127
}
1143
 
/********************************************************************//**
 
1128
/************************************************************************
1144
1129
Add a column to the dummy index */
1145
1130
static
1146
1131
void
1147
1132
ibuf_dummy_index_add_col(
1148
1133
/*=====================*/
1149
 
        dict_index_t*   index,  /*!< in: dummy index */
1150
 
        const dtype_t*  type,   /*!< in: the data type of the column */
1151
 
        ulint           len)    /*!< in: length of the column */
 
1134
        dict_index_t*   index,  /* in: dummy index */
 
1135
        const dtype_t*  type,   /* in: the data type of the column */
 
1136
        ulint           len)    /* in: length of the column */
1152
1137
{
1153
1138
        ulint   i       = index->table->n_def;
1154
1139
        dict_mem_table_add_col(index->table, NULL, NULL,
1158
1143
        dict_index_add_col(index, index->table,
1159
1144
                           dict_table_get_nth_col(index->table, i), len);
1160
1145
}
1161
 
/********************************************************************//**
1162
 
Deallocates a dummy index for inserting a record to a non-clustered index. */
 
1146
/************************************************************************
 
1147
Deallocates a dummy index for inserting a record to a non-clustered index.
 
1148
*/
1163
1149
static
1164
1150
void
1165
1151
ibuf_dummy_index_free(
1166
1152
/*==================*/
1167
 
        dict_index_t*   index)  /*!< in, own: dummy index */
 
1153
        dict_index_t*   index)  /* in: dummy index */
1168
1154
{
1169
1155
        dict_table_t*   table = index->table;
1170
1156
 
1172
1158
        dict_mem_table_free(table);
1173
1159
}
1174
1160
 
1175
 
/*********************************************************************//**
 
1161
/*************************************************************************
1176
1162
Builds the entry to insert into a non-clustered index when we have the
1177
 
corresponding record in an ibuf index.
1178
 
 
1179
 
NOTE that as we copy pointers to fields in ibuf_rec, the caller must
1180
 
hold a latch to the ibuf_rec page as long as the entry is used!
1181
 
 
1182
 
@return own: entry to insert to a non-clustered index */
 
1163
corresponding record in an ibuf index. */
1183
1164
UNIV_INLINE
1184
1165
dtuple_t*
1185
1166
ibuf_build_entry_pre_4_1_x(
1186
1167
/*=======================*/
1187
 
        const rec_t*    ibuf_rec,       /*!< in: record in an insert buffer */
1188
 
        mem_heap_t*     heap,           /*!< in: heap where built */
1189
 
        dict_index_t**  pindex)         /*!< out, own: dummy index that
 
1168
                                        /* out, own: entry to insert to
 
1169
                                        a non-clustered index; NOTE that
 
1170
                                        as we copy pointers to fields in
 
1171
                                        ibuf_rec, the caller must hold a
 
1172
                                        latch to the ibuf_rec page as long
 
1173
                                        as the entry is used! */
 
1174
        const rec_t*    ibuf_rec,       /* in: record in an insert buffer */
 
1175
        mem_heap_t*     heap,           /* in: heap where built */
 
1176
        dict_index_t**  pindex)         /* out, own: dummy index that
1190
1177
                                        describes the entry */
1191
1178
{
1192
1179
        ulint           i;
1224
1211
        return(tuple);
1225
1212
}
1226
1213
 
1227
 
/*********************************************************************//**
 
1214
/*************************************************************************
1228
1215
Builds the entry to insert into a non-clustered index when we have the
1229
 
corresponding record in an ibuf index.
1230
 
 
1231
 
NOTE that as we copy pointers to fields in ibuf_rec, the caller must
1232
 
hold a latch to the ibuf_rec page as long as the entry is used!
1233
 
 
1234
 
@return own: entry to insert to a non-clustered index */
 
1216
corresponding record in an ibuf index. */
1235
1217
static
1236
1218
dtuple_t*
1237
1219
ibuf_build_entry_from_ibuf_rec(
1238
1220
/*===========================*/
1239
 
        const rec_t*    ibuf_rec,       /*!< in: record in an insert buffer */
1240
 
        mem_heap_t*     heap,           /*!< in: heap where built */
1241
 
        dict_index_t**  pindex)         /*!< out, own: dummy index that
 
1221
                                        /* out, own: entry to insert to
 
1222
                                        a non-clustered index; NOTE that
 
1223
                                        as we copy pointers to fields in
 
1224
                                        ibuf_rec, the caller must hold a
 
1225
                                        latch to the ibuf_rec page as long
 
1226
                                        as the entry is used! */
 
1227
        const rec_t*    ibuf_rec,       /* in: record in an insert buffer */
 
1228
        mem_heap_t*     heap,           /* in: heap where built */
 
1229
        dict_index_t**  pindex)         /* out, own: dummy index that
1242
1230
                                        describes the entry */
1243
1231
{
1244
1232
        dtuple_t*       tuple;
1309
1297
        return(tuple);
1310
1298
}
1311
1299
 
1312
 
/********************************************************************//**
 
1300
/************************************************************************
1313
1301
Returns the space taken by a stored non-clustered index entry if converted to
1314
 
an index record.
1315
 
@return size of index record in bytes + an upper limit of the space
1316
 
taken in the page directory */
 
1302
an index record. */
1317
1303
static
1318
1304
ulint
1319
1305
ibuf_rec_get_volume(
1320
1306
/*================*/
1321
 
        const rec_t*    ibuf_rec)/*!< in: ibuf record */
 
1307
                                /* out: size of index record in bytes
 
1308
                                + an upper limit of the space taken in the
 
1309
                                page directory */
 
1310
        const rec_t*    ibuf_rec)/* in: ibuf record */
1322
1311
{
1323
1312
        dtype_t         dtype;
1324
1313
        ibool           new_format      = FALSE;
1328
1317
        const byte*     data;
1329
1318
        ulint           len;
1330
1319
        ulint           i;
1331
 
        ulint           comp;
1332
1320
 
1333
1321
        ut_ad(ibuf_inside());
1334
1322
        ut_ad(rec_get_n_fields_old(ibuf_rec) > 2);
1346
1334
                types = rec_get_nth_field_old(ibuf_rec, 1, &len);
1347
1335
 
1348
1336
                ut_ad(len == n_fields * DATA_ORDER_NULL_TYPE_BUF_SIZE);
1349
 
                comp = 0;
1350
1337
        } else {
1351
1338
                /* >= 4.1.x format record */
1352
1339
 
1355
1342
 
1356
1343
                types = rec_get_nth_field_old(ibuf_rec, 3, &len);
1357
1344
 
1358
 
                comp = len % DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE;
1359
 
 
1360
 
                ut_a(comp <= 1);
1361
 
                if (comp) {
 
1345
                ut_a(len % DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE <= 1);
 
1346
                if (len % DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE) {
1362
1347
                        /* compact record format */
1363
1348
                        ulint           volume;
1364
1349
                        dict_index_t*   dummy_index;
1392
1377
                }
1393
1378
 
1394
1379
                if (len == UNIV_SQL_NULL) {
1395
 
                        data_size += dtype_get_sql_null_size(&dtype, comp);
 
1380
                        data_size += dtype_get_sql_null_size(&dtype);
1396
1381
                } else {
1397
1382
                        data_size += len;
1398
1383
                }
1402
1387
               + page_dir_calc_reserved_space(1));
1403
1388
}
1404
1389
 
1405
 
/*********************************************************************//**
 
1390
/*************************************************************************
1406
1391
Builds the tuple to insert to an ibuf tree when we have an entry for a
1407
 
non-clustered index.
1408
 
 
1409
 
NOTE that the original entry must be kept because we copy pointers to
1410
 
its fields.
1411
 
 
1412
 
@return own: entry to insert into an ibuf index tree */
 
1392
non-clustered index. */
1413
1393
static
1414
1394
dtuple_t*
1415
1395
ibuf_entry_build(
1416
1396
/*=============*/
1417
 
        dict_index_t*   index,  /*!< in: non-clustered index */
1418
 
        const dtuple_t* entry,  /*!< in: entry for a non-clustered index */
1419
 
        ulint           space,  /*!< in: space id */
1420
 
        ulint           page_no,/*!< in: index page number where entry should
 
1397
                                /* out, own: entry to insert into an ibuf
 
1398
                                index tree; NOTE that the original entry
 
1399
                                must be kept because we copy pointers to its
 
1400
                                fields */
 
1401
        dict_index_t*   index,  /* in: non-clustered index */
 
1402
        const dtuple_t* entry,  /* in: entry for a non-clustered index */
 
1403
        ulint           space,  /* in: space id */
 
1404
        ulint           page_no,/* in: index page number where entry should
1421
1405
                                be inserted */
1422
 
        mem_heap_t*     heap)   /*!< in: heap into which to build */
 
1406
        mem_heap_t*     heap)   /* in: heap into which to build */
1423
1407
{
1424
1408
        dtuple_t*       tuple;
1425
1409
        dfield_t*       field;
1543
1527
        return(tuple);
1544
1528
}
1545
1529
 
1546
 
/*********************************************************************//**
 
1530
/*************************************************************************
1547
1531
Builds a search tuple used to search buffered inserts for an index page.
1548
 
This is for < 4.1.x format records
1549
 
@return own: search tuple */
 
1532
This is for < 4.1.x format records */
1550
1533
static
1551
1534
dtuple_t*
1552
1535
ibuf_search_tuple_build(
1553
1536
/*====================*/
1554
 
        ulint           space,  /*!< in: space id */
1555
 
        ulint           page_no,/*!< in: index page number */
1556
 
        mem_heap_t*     heap)   /*!< in: heap into which to build */
 
1537
                                /* out, own: search tuple */
 
1538
        ulint           space,  /* in: space id */
 
1539
        ulint           page_no,/* in: index page number */
 
1540
        mem_heap_t*     heap)   /* in: heap into which to build */
1557
1541
{
1558
1542
        dtuple_t*       tuple;
1559
1543
        dfield_t*       field;
1580
1564
        return(tuple);
1581
1565
}
1582
1566
 
1583
 
/*********************************************************************//**
 
1567
/*************************************************************************
1584
1568
Builds a search tuple used to search buffered inserts for an index page.
1585
 
This is for >= 4.1.x format records.
1586
 
@return own: search tuple */
 
1569
This is for >= 4.1.x format records. */
1587
1570
static
1588
1571
dtuple_t*
1589
1572
ibuf_new_search_tuple_build(
1590
1573
/*========================*/
1591
 
        ulint           space,  /*!< in: space id */
1592
 
        ulint           page_no,/*!< in: index page number */
1593
 
        mem_heap_t*     heap)   /*!< in: heap into which to build */
 
1574
                                /* out, own: search tuple */
 
1575
        ulint           space,  /* in: space id */
 
1576
        ulint           page_no,/* in: index page number */
 
1577
        mem_heap_t*     heap)   /* in: heap into which to build */
1594
1578
{
1595
1579
        dtuple_t*       tuple;
1596
1580
        dfield_t*       field;
1635
1619
        return(tuple);
1636
1620
}
1637
1621
 
1638
 
/*********************************************************************//**
 
1622
/*************************************************************************
1639
1623
Checks if there are enough pages in the free list of the ibuf tree that we
1640
 
dare to start a pessimistic insert to the insert buffer.
1641
 
@return TRUE if enough free pages in list */
 
1624
dare to start a pessimistic insert to the insert buffer. */
1642
1625
UNIV_INLINE
1643
1626
ibool
1644
1627
ibuf_data_enough_free_for_insert(void)
1645
1628
/*==================================*/
 
1629
                                /* out: TRUE if enough free pages in list */
1646
1630
{
1647
1631
        ut_ad(mutex_own(&ibuf_mutex));
1648
1632
 
1655
1639
        return(ibuf->free_list_len >= (ibuf->size / 2) + 3 * ibuf->height);
1656
1640
}
1657
1641
 
1658
 
/*********************************************************************//**
 
1642
/*************************************************************************
1659
1643
Checks if there are enough pages in the free list of the ibuf tree that we
1660
 
should remove them and free to the file space management.
1661
 
@return TRUE if enough free pages in list */
 
1644
should remove them and free to the file space management. */
1662
1645
UNIV_INLINE
1663
1646
ibool
1664
1647
ibuf_data_too_much_free(void)
1665
1648
/*=========================*/
 
1649
                                /* out: TRUE if enough free pages in list */
1666
1650
{
1667
1651
        ut_ad(mutex_own(&ibuf_mutex));
1668
1652
 
1669
1653
        return(ibuf->free_list_len >= 3 + (ibuf->size / 2) + 3 * ibuf->height);
1670
1654
}
1671
1655
 
1672
 
/*********************************************************************//**
 
1656
/*************************************************************************
1673
1657
Allocates a new page from the ibuf file segment and adds it to the free
1674
 
list.
1675
 
@return DB_SUCCESS, or DB_STRONG_FAIL if no space left */
 
1658
list. */
1676
1659
static
1677
1660
ulint
1678
1661
ibuf_add_free_page(void)
1679
1662
/*====================*/
 
1663
                                        /* out: DB_SUCCESS, or DB_STRONG_FAIL
 
1664
                                        if no space left */
1680
1665
{
1681
1666
        mtr_t   mtr;
1682
1667
        page_t* header_page;
1763
1748
        return(DB_SUCCESS);
1764
1749
}
1765
1750
 
1766
 
/*********************************************************************//**
 
1751
/*************************************************************************
1767
1752
Removes a page from the free list and frees it to the fsp system. */
1768
1753
static
1769
1754
void
1888
1873
        ibuf_exit();
1889
1874
}
1890
1875
 
1891
 
/***********************************************************************//**
 
1876
/***************************************************************************
1892
1877
Frees excess pages from the ibuf free list. This function is called when an OS
1893
1878
thread calls fsp services to allocate a new file segment, or a new page to a
1894
1879
file segment, and the thread did not own the fsp latch before this call. */
1940
1925
        }
1941
1926
}
1942
1927
 
1943
 
/*********************************************************************//**
1944
 
Reads page numbers from a leaf in an ibuf tree.
1945
 
@return a lower limit for the combined volume of records which will be
1946
 
merged */
 
1928
/*************************************************************************
 
1929
Reads page numbers from a leaf in an ibuf tree. */
1947
1930
static
1948
1931
ulint
1949
1932
ibuf_get_merge_page_nos(
1950
1933
/*====================*/
1951
 
        ibool           contract,/*!< in: TRUE if this function is called to
 
1934
                                /* out: a lower limit for the combined volume
 
1935
                                of records which will be merged */
 
1936
        ibool           contract,/* in: TRUE if this function is called to
1952
1937
                                contract the tree, FALSE if this is called
1953
1938
                                when a single page becomes full and we look
1954
1939
                                if it pays to read also nearby pages */
1955
 
        rec_t*          rec,    /*!< in: record from which we read up and down
 
1940
        rec_t*          rec,    /* in: record from which we read up and down
1956
1941
                                in the chain of records */
1957
 
        ulint*          space_ids,/*!< in/out: space id's of the pages */
1958
 
        ib_int64_t*     space_versions,/*!< in/out: tablespace version
 
1942
        ulint*          space_ids,/* in/out: space id's of the pages */
 
1943
        ib_int64_t*     space_versions,/* in/out: tablespace version
1959
1944
                                timestamps; used to prevent reading in old
1960
1945
                                pages after DISCARD + IMPORT tablespace */
1961
 
        ulint*          page_nos,/*!< in/out: buffer for at least
 
1946
        ulint*          page_nos,/* in/out: buffer for at least
1962
1947
                                IBUF_MAX_N_PAGES_MERGED many page numbers;
1963
1948
                                the page numbers are in an ascending order */
1964
 
        ulint*          n_stored)/*!< out: number of page numbers stored to
 
1949
        ulint*          n_stored)/* out: number of page numbers stored to
1965
1950
                                page_nos in this function */
1966
1951
{
1967
1952
        ulint   prev_page_no;
2113
2098
        return(sum_volumes);
2114
2099
}
2115
2100
 
2116
 
/*********************************************************************//**
2117
 
Contracts insert buffer trees by reading pages to the buffer pool.
2118
 
@return a lower limit for the combined size in bytes of entries which
2119
 
will be merged from ibuf trees to the pages read, 0 if ibuf is
2120
 
empty */
 
2101
/*************************************************************************
 
2102
Contracts insert buffer trees by reading pages to the buffer pool. */
2121
2103
static
2122
2104
ulint
2123
2105
ibuf_contract_ext(
2124
2106
/*==============*/
2125
 
        ulint*  n_pages,/*!< out: number of pages to which merged */
2126
 
        ibool   sync)   /*!< in: TRUE if the caller wants to wait for the
 
2107
                        /* out: a lower limit for the combined size in bytes
 
2108
                        of entries which will be merged from ibuf trees to the
 
2109
                        pages read, 0 if ibuf is empty */
 
2110
        ulint*  n_pages,/* out: number of pages to which merged */
 
2111
        ibool   sync)   /* in: TRUE if the caller wants to wait for the
2127
2112
                        issued read with the highest tablespace address
2128
2113
                        to complete */
2129
2114
{
2194
2179
        return(sum_sizes + 1);
2195
2180
}
2196
2181
 
2197
 
/*********************************************************************//**
2198
 
Contracts insert buffer trees by reading pages to the buffer pool.
2199
 
@return a lower limit for the combined size in bytes of entries which
2200
 
will be merged from ibuf trees to the pages read, 0 if ibuf is
2201
 
empty */
 
2182
/*************************************************************************
 
2183
Contracts insert buffer trees by reading pages to the buffer pool. */
2202
2184
UNIV_INTERN
2203
2185
ulint
2204
2186
ibuf_contract(
2205
2187
/*==========*/
2206
 
        ibool   sync)   /*!< in: TRUE if the caller wants to wait for the
 
2188
                        /* out: a lower limit for the combined size in bytes
 
2189
                        of entries which will be merged from ibuf trees to the
 
2190
                        pages read, 0 if ibuf is empty */
 
2191
        ibool   sync)   /* in: TRUE if the caller wants to wait for the
2207
2192
                        issued read with the highest tablespace address
2208
2193
                        to complete */
2209
2194
{
2212
2197
        return(ibuf_contract_ext(&n_pages, sync));
2213
2198
}
2214
2199
 
2215
 
/*********************************************************************//**
2216
 
Contracts insert buffer trees by reading pages to the buffer pool.
2217
 
@return a lower limit for the combined size in bytes of entries which
2218
 
will be merged from ibuf trees to the pages read, 0 if ibuf is
2219
 
empty */
 
2200
/*************************************************************************
 
2201
Contracts insert buffer trees by reading pages to the buffer pool. */
2220
2202
UNIV_INTERN
2221
2203
ulint
2222
2204
ibuf_contract_for_n_pages(
2223
2205
/*======================*/
2224
 
        ibool   sync,   /*!< in: TRUE if the caller wants to wait for the
 
2206
                        /* out: a lower limit for the combined size in bytes
 
2207
                        of entries which will be merged from ibuf trees to the
 
2208
                        pages read, 0 if ibuf is empty */
 
2209
        ibool   sync,   /* in: TRUE if the caller wants to wait for the
2225
2210
                        issued read with the highest tablespace address
2226
2211
                        to complete */
2227
 
        ulint   n_pages)/*!< in: try to read at least this many pages to
 
2212
        ulint   n_pages)/* in: try to read at least this many pages to
2228
2213
                        the buffer pool and merge the ibuf contents to
2229
2214
                        them */
2230
2215
{
2247
2232
        return(sum_bytes);
2248
2233
}
2249
2234
 
2250
 
/*********************************************************************//**
 
2235
/*************************************************************************
2251
2236
Contract insert buffer trees after insert if they are too big. */
2252
2237
UNIV_INLINE
2253
2238
void
2254
2239
ibuf_contract_after_insert(
2255
2240
/*=======================*/
2256
 
        ulint   entry_size)     /*!< in: size of a record which was inserted
 
2241
        ulint   entry_size)     /* in: size of a record which was inserted
2257
2242
                                into an ibuf tree */
2258
2243
{
2259
2244
        ibool   sync;
2288
2273
        }
2289
2274
}
2290
2275
 
2291
 
/*********************************************************************//**
 
2276
/*************************************************************************
2292
2277
Gets an upper limit for the combined size of entries buffered in the insert
2293
 
buffer for a given page.
2294
 
@return upper limit for the volume of buffered inserts for the index
2295
 
page, in bytes; UNIV_PAGE_SIZE, if the entries for the index page span
2296
 
several pages in the insert buffer */
 
2278
buffer for a given page. */
2297
2279
static
2298
2280
ulint
2299
2281
ibuf_get_volume_buffered(
2300
2282
/*=====================*/
2301
 
        btr_pcur_t*     pcur,   /*!< in: pcur positioned at a place in an
 
2283
                                /* out: upper limit for the volume of
 
2284
                                buffered inserts for the index page, in bytes;
 
2285
                                we may also return UNIV_PAGE_SIZE, if the
 
2286
                                entries for the index page span on several
 
2287
                                pages in the insert buffer */
 
2288
        btr_pcur_t*     pcur,   /* in: pcur positioned at a place in an
2302
2289
                                insert buffer tree where we would insert an
2303
2290
                                entry for the index page whose number is
2304
2291
                                page_no, latch mode has to be BTR_MODIFY_PREV
2305
2292
                                or BTR_MODIFY_TREE */
2306
 
        ulint           space,  /*!< in: space id */
2307
 
        ulint           page_no,/*!< in: page number of an index page */
2308
 
        mtr_t*          mtr)    /*!< in: mtr */
 
2293
        ulint           space,  /* in: space id */
 
2294
        ulint           page_no,/* in: page number of an index page */
 
2295
        mtr_t*          mtr)    /* in: mtr */
2309
2296
{
2310
2297
        ulint   volume;
2311
2298
        rec_t*  rec;
2471
2458
        }
2472
2459
}
2473
2460
 
2474
 
/*********************************************************************//**
 
2461
/*************************************************************************
2475
2462
Reads the biggest tablespace id from the high end of the insert buffer
2476
2463
tree and updates the counter in fil_system. */
2477
2464
UNIV_INTERN
2519
2506
        fil_set_max_space_id_if_bigger(max_space_id);
2520
2507
}
2521
2508
 
2522
 
/*********************************************************************//**
 
2509
/*************************************************************************
2523
2510
Makes an index insert to the insert buffer, instead of directly to the disk
2524
 
page, if this is possible.
2525
 
@return DB_SUCCESS, DB_FAIL, DB_STRONG_FAIL */
 
2511
page, if this is possible. */
2526
2512
static
2527
2513
ulint
2528
2514
ibuf_insert_low(
2529
2515
/*============*/
2530
 
        ulint           mode,   /*!< in: BTR_MODIFY_PREV or BTR_MODIFY_TREE */
2531
 
        const dtuple_t* entry,  /*!< in: index entry to insert */
 
2516
                                /* out: DB_SUCCESS, DB_FAIL, DB_STRONG_FAIL */
 
2517
        ulint           mode,   /* in: BTR_MODIFY_PREV or BTR_MODIFY_TREE */
 
2518
        const dtuple_t* entry,  /* in: index entry to insert */
2532
2519
        ulint           entry_size,
2533
 
                                /*!< in: rec_get_converted_size(index, entry) */
2534
 
        dict_index_t*   index,  /*!< in: index where to insert; must not be
 
2520
                                /* in: rec_get_converted_size(index, entry) */
 
2521
        dict_index_t*   index,  /* in: index where to insert; must not be
2535
2522
                                unique or clustered */
2536
 
        ulint           space,  /*!< in: space id where to insert */
2537
 
        ulint           zip_size,/*!< in: compressed page size in bytes, or 0 */
2538
 
        ulint           page_no,/*!< in: page number where to insert */
2539
 
        que_thr_t*      thr)    /*!< in: query thread */
 
2523
        ulint           space,  /* in: space id where to insert */
 
2524
        ulint           zip_size,/* in: compressed page size in bytes, or 0 */
 
2525
        ulint           page_no,/* in: page number where to insert */
 
2526
        que_thr_t*      thr)    /* in: query thread */
2540
2527
{
2541
2528
        big_rec_t*      dummy_big_rec;
2542
2529
        btr_pcur_t      pcur;
2698
2685
                if (err == DB_SUCCESS) {
2699
2686
                        /* Update the page max trx id field */
2700
2687
                        page_update_max_trx_id(btr_cur_get_block(cursor), NULL,
2701
 
                                               thr_get_trx(thr)->id, &mtr);
 
2688
                                               thr_get_trx(thr)->id);
2702
2689
                }
2703
2690
        } else {
2704
2691
                ut_ad(mode == BTR_MODIFY_TREE);
2718
2705
                if (err == DB_SUCCESS) {
2719
2706
                        /* Update the page max trx id field */
2720
2707
                        page_update_max_trx_id(btr_cur_get_block(cursor), NULL,
2721
 
                                               thr_get_trx(thr)->id, &mtr);
 
2708
                                               thr_get_trx(thr)->id);
2722
2709
                }
2723
2710
 
2724
2711
                ibuf_size_update(root, &mtr);
2772
2759
        return(err);
2773
2760
}
2774
2761
 
2775
 
/*********************************************************************//**
 
2762
/*************************************************************************
2776
2763
Makes an index insert to the insert buffer, instead of directly to the disk
2777
2764
page, if this is possible. Does not do insert if the index is clustered
2778
 
or unique.
2779
 
@return TRUE if success */
 
2765
or unique. */
2780
2766
UNIV_INTERN
2781
2767
ibool
2782
2768
ibuf_insert(
2783
2769
/*========*/
2784
 
        const dtuple_t* entry,  /*!< in: index entry to insert */
2785
 
        dict_index_t*   index,  /*!< in: index where to insert */
2786
 
        ulint           space,  /*!< in: space id where to insert */
2787
 
        ulint           zip_size,/*!< in: compressed page size in bytes, or 0 */
2788
 
        ulint           page_no,/*!< in: page number where to insert */
2789
 
        que_thr_t*      thr)    /*!< in: query thread */
 
2770
                                /* out: TRUE if success */
 
2771
        const dtuple_t* entry,  /* in: index entry to insert */
 
2772
        dict_index_t*   index,  /* in: index where to insert */
 
2773
        ulint           space,  /* in: space id where to insert */
 
2774
        ulint           zip_size,/* in: compressed page size in bytes, or 0 */
 
2775
        ulint           page_no,/* in: page number where to insert */
 
2776
        que_thr_t*      thr)    /* in: query thread */
2790
2777
{
2791
2778
        ulint   err;
2792
2779
        ulint   entry_size;
2838
2825
        }
2839
2826
}
2840
2827
 
2841
 
/********************************************************************//**
 
2828
/************************************************************************
2842
2829
During merge, inserts to an index page a secondary index entry extracted
2843
2830
from the insert buffer. */
2844
2831
static
2845
2832
void
2846
2833
ibuf_insert_to_index_page(
2847
2834
/*======================*/
2848
 
        dtuple_t*       entry,  /*!< in: buffered entry to insert */
2849
 
        buf_block_t*    block,  /*!< in/out: index page where the buffered entry
 
2835
        dtuple_t*       entry,  /* in: buffered entry to insert */
 
2836
        buf_block_t*    block,  /* in/out: index page where the buffered entry
2850
2837
                                should be placed */
2851
 
        dict_index_t*   index,  /*!< in: record descriptor */
2852
 
        mtr_t*          mtr)    /*!< in: mtr */
 
2838
        dict_index_t*   index,  /* in: record descriptor */
 
2839
        mtr_t*          mtr)    /* in: mtr */
2853
2840
{
2854
2841
        page_cur_t      page_cur;
2855
2842
        ulint           low_match;
2965
2952
        }
2966
2953
}
2967
2954
 
2968
 
/*********************************************************************//**
 
2955
/*************************************************************************
2969
2956
Deletes from ibuf the record on which pcur is positioned. If we have to
2970
2957
resort to a pessimistic delete, this function commits mtr and closes
2971
 
the cursor.
2972
 
@return TRUE if mtr was committed and pcur closed in this operation */
 
2958
the cursor. */
2973
2959
static
2974
2960
ibool
2975
2961
ibuf_delete_rec(
2976
2962
/*============*/
2977
 
        ulint           space,  /*!< in: space id */
2978
 
        ulint           page_no,/*!< in: index page number where the record
 
2963
                                /* out: TRUE if mtr was committed and pcur
 
2964
                                closed in this operation */
 
2965
        ulint           space,  /* in: space id */
 
2966
        ulint           page_no,/* in: index page number where the record
2979
2967
                                should belong */
2980
 
        btr_pcur_t*     pcur,   /*!< in: pcur positioned on the record to
 
2968
        btr_pcur_t*     pcur,   /* in: pcur positioned on the record to
2981
2969
                                delete, having latch mode BTR_MODIFY_LEAF */
2982
2970
        const dtuple_t* search_tuple,
2983
 
                                /*!< in: search tuple for entries of page_no */
2984
 
        mtr_t*          mtr)    /*!< in: mtr */
 
2971
                                /* in: search tuple for entries of page_no */
 
2972
        mtr_t*          mtr)    /* in: mtr */
2985
2973
{
2986
2974
        ibool           success;
2987
2975
        page_t*         root;
3080
3068
        return(TRUE);
3081
3069
}
3082
3070
 
3083
 
/*********************************************************************//**
 
3071
/*************************************************************************
3084
3072
When an index page is read from a disk to the buffer pool, this function
3085
3073
inserts to the page the possible index entries buffered in the insert buffer.
3086
3074
The entries are deleted from the insert buffer. If the page is not read, but
3091
3079
void
3092
3080
ibuf_merge_or_delete_for_page(
3093
3081
/*==========================*/
3094
 
        buf_block_t*    block,  /*!< in: if page has been read from
 
3082
        buf_block_t*    block,  /* in: if page has been read from
3095
3083
                                disk, pointer to the page x-latched,
3096
3084
                                else NULL */
3097
 
        ulint           space,  /*!< in: space id of the index page */
3098
 
        ulint           page_no,/*!< in: page number of the index page */
3099
 
        ulint           zip_size,/*!< in: compressed page size in bytes,
 
3085
        ulint           space,  /* in: space id of the index page */
 
3086
        ulint           page_no,/* in: page number of the index page */
 
3087
        ulint           zip_size,/* in: compressed page size in bytes,
3100
3088
                                or 0 */
3101
 
        ibool           update_ibuf_bitmap)/*!< in: normally this is set
 
3089
        ibool           update_ibuf_bitmap)/* in: normally this is set
3102
3090
                                to TRUE, but if we have deleted or are
3103
3091
                                deleting the tablespace, then we
3104
3092
                                naturally do not want to update a
3319
3307
                        keep the latch to the rec page until the
3320
3308
                        insertion is finished! */
3321
3309
                        dtuple_t*       entry;
3322
 
                        trx_id_t        max_trx_id;
 
3310
                        dulint          max_trx_id;
3323
3311
                        dict_index_t*   dummy_index;
3324
3312
 
3325
3313
                        max_trx_id = page_get_max_trx_id(page_align(rec));
3326
 
                        page_update_max_trx_id(block, page_zip, max_trx_id,
3327
 
                                               &mtr);
 
3314
                        page_update_max_trx_id(block, page_zip, max_trx_id);
3328
3315
 
3329
3316
                        entry = ibuf_build_entry_from_ibuf_rec(
3330
3317
                                rec, heap, &dummy_index);
3413
3400
#endif
3414
3401
}
3415
3402
 
3416
 
/*********************************************************************//**
 
3403
/*************************************************************************
3417
3404
Deletes all entries in the insert buffer for a given space id. This is used
3418
3405
in DISCARD TABLESPACE and IMPORT TABLESPACE.
3419
3406
NOTE: this does not update the page free bitmaps in the space. The space will
3422
3409
void
3423
3410
ibuf_delete_for_discarded_space(
3424
3411
/*============================*/
3425
 
        ulint   space)  /*!< in: space id */
 
3412
        ulint   space)  /* in: space id */
3426
3413
{
3427
3414
        mem_heap_t*     heap;
3428
3415
        btr_pcur_t      pcur;
3512
3499
        mem_heap_free(heap);
3513
3500
}
3514
3501
 
3515
 
/******************************************************************//**
3516
 
Looks if the insert buffer is empty.
3517
 
@return TRUE if empty */
 
3502
/**********************************************************************
 
3503
Looks if the insert buffer is empty. */
3518
3504
UNIV_INTERN
3519
3505
ibool
3520
3506
ibuf_is_empty(void)
3521
3507
/*===============*/
 
3508
                        /* out: TRUE if empty */
3522
3509
{
3523
3510
        ibool           is_empty;
3524
3511
        const page_t*   root;
3559
3546
        return(is_empty);
3560
3547
}
3561
3548
 
3562
 
/******************************************************************//**
 
3549
/**********************************************************************
3563
3550
Prints info of ibuf. */
3564
3551
UNIV_INTERN
3565
3552
void
3566
3553
ibuf_print(
3567
3554
/*=======*/
3568
 
        FILE*   file)   /*!< in: file where to print */
 
3555
        FILE*   file)   /* in: file where to print */
3569
3556
{
3570
3557
#ifdef UNIV_IBUF_COUNT_DEBUG
3571
3558
        ulint           i;
3600
3587
 
3601
3588
        mutex_exit(&ibuf_mutex);
3602
3589
}
3603
 
#endif /* !UNIV_HOTBACKUP */