1
by brian
clean slate |
1 |
/******************************************************
|
2 |
The database buffer pool flush algorithm
|
|
3 |
||
4 |
(c) 1995 Innobase Oy
|
|
5 |
||
6 |
Created 11/5/1995 Heikki Tuuri
|
|
7 |
*******************************************************/
|
|
8 |
||
9 |
#include "buf0buf.h" |
|
10 |
#include "mtr0mtr.h" |
|
11 |
||
12 |
/************************************************************************
|
|
13 |
Inserts a modified block into the flush list. */
|
|
14 |
||
15 |
void
|
|
16 |
buf_flush_insert_into_flush_list( |
|
17 |
/*=============================*/
|
|
18 |
buf_block_t* block); /* in: block which is modified */ |
|
19 |
/************************************************************************
|
|
20 |
Inserts a modified block into the flush list in the right sorted position.
|
|
21 |
This function is used by recovery, because there the modifications do not
|
|
22 |
necessarily come in the order of lsn's. */
|
|
23 |
||
24 |
void
|
|
25 |
buf_flush_insert_sorted_into_flush_list( |
|
26 |
/*====================================*/
|
|
27 |
buf_block_t* block); /* in: block which is modified */ |
|
28 |
||
29 |
/************************************************************************
|
|
30 |
This function should be called at a mini-transaction commit, if a page was
|
|
31 |
modified in it. Puts the block to the list of modified blocks, if it is not
|
|
32 |
already in it. */
|
|
33 |
UNIV_INLINE
|
|
34 |
void
|
|
35 |
buf_flush_note_modification( |
|
36 |
/*========================*/
|
|
37 |
buf_block_t* block, /* in: block which is modified */ |
|
38 |
mtr_t* mtr) /* in: mtr */ |
|
39 |
{
|
|
40 |
ut_ad(block); |
|
41 |
ut_ad(block->state == BUF_BLOCK_FILE_PAGE); |
|
42 |
ut_ad(block->buf_fix_count > 0); |
|
43 |
#ifdef UNIV_SYNC_DEBUG
|
|
44 |
ut_ad(rw_lock_own(&(block->lock), RW_LOCK_EX)); |
|
45 |
#endif /* UNIV_SYNC_DEBUG */ |
|
46 |
ut_ad(mutex_own(&(buf_pool->mutex))); |
|
47 |
||
48 |
ut_ad(ut_dulint_cmp(mtr->start_lsn, ut_dulint_zero) != 0); |
|
49 |
ut_ad(mtr->modifications); |
|
50 |
ut_ad(ut_dulint_cmp(block->newest_modification, mtr->end_lsn) <= 0); |
|
51 |
||
52 |
block->newest_modification = mtr->end_lsn; |
|
53 |
||
54 |
if (ut_dulint_is_zero(block->oldest_modification)) { |
|
55 |
||
56 |
block->oldest_modification = mtr->start_lsn; |
|
57 |
ut_ad(!ut_dulint_is_zero(block->oldest_modification)); |
|
58 |
||
59 |
buf_flush_insert_into_flush_list(block); |
|
60 |
} else { |
|
61 |
ut_ad(ut_dulint_cmp(block->oldest_modification, |
|
62 |
mtr->start_lsn) <= 0); |
|
63 |
}
|
|
64 |
||
65 |
++srv_buf_pool_write_requests; |
|
66 |
}
|
|
67 |
||
68 |
/************************************************************************
|
|
69 |
This function should be called when recovery has modified a buffer page. */
|
|
70 |
UNIV_INLINE
|
|
71 |
void
|
|
72 |
buf_flush_recv_note_modification( |
|
73 |
/*=============================*/
|
|
74 |
buf_block_t* block, /* in: block which is modified */ |
|
75 |
dulint start_lsn, /* in: start lsn of the first mtr in a |
|
76 |
set of mtr's */
|
|
77 |
dulint end_lsn) /* in: end lsn of the last mtr in the |
|
78 |
set of mtr's */
|
|
79 |
{
|
|
80 |
ut_ad(block); |
|
81 |
ut_ad(block->state == BUF_BLOCK_FILE_PAGE); |
|
82 |
ut_ad(block->buf_fix_count > 0); |
|
83 |
#ifdef UNIV_SYNC_DEBUG
|
|
84 |
ut_ad(rw_lock_own(&(block->lock), RW_LOCK_EX)); |
|
85 |
#endif /* UNIV_SYNC_DEBUG */ |
|
86 |
||
87 |
mutex_enter(&(buf_pool->mutex)); |
|
88 |
||
89 |
ut_ad(ut_dulint_cmp(block->newest_modification, end_lsn) <= 0); |
|
90 |
||
91 |
block->newest_modification = end_lsn; |
|
92 |
||
93 |
if (ut_dulint_is_zero(block->oldest_modification)) { |
|
94 |
||
95 |
block->oldest_modification = start_lsn; |
|
96 |
||
97 |
ut_ad(!ut_dulint_is_zero(block->oldest_modification)); |
|
98 |
||
99 |
buf_flush_insert_sorted_into_flush_list(block); |
|
100 |
} else { |
|
101 |
ut_ad(ut_dulint_cmp(block->oldest_modification, |
|
102 |
start_lsn) <= 0); |
|
103 |
}
|
|
104 |
||
105 |
mutex_exit(&(buf_pool->mutex)); |
|
106 |
}
|