330
323
buf_flush_list_mutex_enter(buf_pool);
332
/* The field in_LRU_list is protected by buf_pool->mutex, which
325
/* The field in_LRU_list is protected by buf_pool_mutex, which
333
326
we are not holding. However, while a block is in the flush
334
327
list, it is dirty and cannot be discarded, not from the
335
328
page_hash or from the LRU list. At most, the uncompressed
1010
1003
case FIL_PAGE_TYPE_ZBLOB:
1011
1004
case FIL_PAGE_TYPE_ZBLOB2:
1012
1005
case FIL_PAGE_INDEX:
1013
mach_write_to_8(page_zip->data
1014
+ FIL_PAGE_LSN, newest_lsn);
1006
mach_write_ull(page_zip->data
1007
+ FIL_PAGE_LSN, newest_lsn);
1015
1008
memset(page_zip->data + FIL_PAGE_FILE_FLUSH_LSN, 0, 8);
1016
1009
mach_write_to_4(page_zip->data
1017
1010
+ FIL_PAGE_SPACE_OR_CHKSUM,
1035
1028
/* Write the newest modification lsn to the page header and trailer */
1036
mach_write_to_8(page + FIL_PAGE_LSN, newest_lsn);
1029
mach_write_ull(page + FIL_PAGE_LSN, newest_lsn);
1038
mach_write_to_8(page + UNIV_PAGE_SIZE - FIL_PAGE_END_LSN_OLD_CHKSUM,
1031
mach_write_ull(page + UNIV_PAGE_SIZE - FIL_PAGE_END_LSN_OLD_CHKSUM,
1041
1034
/* Store the new formula checksum */
1124
1117
ut_a(mach_read_from_4(frame + FIL_PAGE_SPACE_OR_CHKSUM)
1125
1118
== page_zip_calc_checksum(frame, zip_size));
1127
mach_write_to_8(frame + FIL_PAGE_LSN,
1128
bpage->newest_modification);
1120
mach_write_ull(frame + FIL_PAGE_LSN,
1121
bpage->newest_modification);
1129
1122
memset(frame + FIL_PAGE_FILE_FLUSH_LSN, 0, 8);
1131
1124
case BUF_BLOCK_FILE_PAGE:
1155
# if defined UNIV_DEBUG || defined UNIV_IBUF_DEBUG
1156
/********************************************************************//**
1157
Writes a flushable page asynchronously from the buffer pool to a file.
1158
NOTE: buf_pool->mutex and block->mutex must be held upon entering this
1159
function, and they will be released by this function after flushing.
1160
This is loosely based on buf_flush_batch() and buf_flush_page().
1161
@return TRUE if the page was flushed and the mutexes released */
1166
buf_pool_t* buf_pool, /*!< in/out: buffer pool instance */
1167
buf_block_t* block) /*!< in/out: buffer control block */
1169
ut_ad(buf_pool_mutex_own(buf_pool));
1170
ut_ad(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
1171
ut_ad(mutex_own(&block->mutex));
1173
if (!buf_flush_ready_for_flush(&block->page, BUF_FLUSH_LRU)) {
1177
if (buf_pool->n_flush[BUF_FLUSH_LRU] > 0
1178
|| buf_pool->init_flush[BUF_FLUSH_LRU]) {
1179
/* There is already a flush batch of the same type running */
1183
buf_pool->init_flush[BUF_FLUSH_LRU] = TRUE;
1185
buf_page_set_io_fix(&block->page, BUF_IO_WRITE);
1187
buf_page_set_flush_type(&block->page, BUF_FLUSH_LRU);
1189
if (buf_pool->n_flush[BUF_FLUSH_LRU]++ == 0) {
1191
os_event_reset(buf_pool->no_flush[BUF_FLUSH_LRU]);
1195
Because any thread may call the LRU flush, even when owning
1196
locks on pages, to avoid deadlocks, we must make sure that the
1197
s-lock is acquired on the page without waiting: this is
1198
accomplished because buf_flush_ready_for_flush() must hold,
1199
and that requires the page not to be bufferfixed. */
1201
rw_lock_s_lock_gen(&block->lock, BUF_IO_WRITE);
1203
/* Note that the s-latch is acquired before releasing the
1204
buf_pool mutex: this ensures that the latch is acquired
1207
mutex_exit(&block->mutex);
1208
buf_pool_mutex_exit(buf_pool);
1210
/* Even though block is not protected by any mutex at this
1211
point, it is safe to access block, because it is io_fixed and
1212
oldest_modification != 0. Thus, it cannot be relocated in the
1213
buffer pool or removed from flush_list or LRU_list. */
1215
buf_flush_write_block_low(&block->page);
1217
buf_pool_mutex_enter(buf_pool);
1218
buf_pool->init_flush[BUF_FLUSH_LRU] = FALSE;
1220
if (buf_pool->n_flush[BUF_FLUSH_LRU] == 0) {
1221
/* The running flush batch has ended */
1222
os_event_set(buf_pool->no_flush[BUF_FLUSH_LRU]);
1225
buf_pool_mutex_exit(buf_pool);
1226
buf_flush_buffered_writes();
1230
# endif /* UNIV_DEBUG || UNIV_IBUF_DEBUG */
1232
1148
/********************************************************************//**
1233
1149
Writes a flushable page asynchronously from the buffer pool to a file.
1234
1150
NOTE: in simulated aio we must call
1353
1269
/*====================*/
1354
1270
ulint space, /*!< in: space id */
1355
1271
ulint offset, /*!< in: page offset */
1356
enum buf_flush flush_type, /*!< in: BUF_FLUSH_LRU or
1272
enum buf_flush flush_type) /*!< in: BUF_FLUSH_LRU or
1357
1273
BUF_FLUSH_LIST */
1358
ulint n_flushed, /*!< in: number of pages
1359
flushed so far in this batch */
1360
ulint n_to_flush) /*!< in: maximum number of pages
1361
we are allowed to flush */
1400
1312
buf_page_t* bpage;
1402
if ((count + n_flushed) >= n_to_flush) {
1404
/* We have already flushed enough pages and
1405
should call it a day. There is, however, one
1406
exception. If the page whose neighbors we
1407
are flushing has not been flushed yet then
1408
we'll try to flush the victim that we
1409
selected originally. */
1417
1314
buf_pool = buf_pool_get(space, i);
1419
1316
buf_pool_mutex_enter(buf_pool);
2208
2101
ut_ad(bpage->in_flush_list);
2210
/* A page in buf_pool->flush_list can be in
2211
BUF_BLOCK_REMOVE_HASH state. This happens when a page
2212
is in the middle of being relocated. In that case the
2213
original descriptor can have this state and still be
2214
in the flush list waiting to acquire the
2215
buf_pool->flush_list_mutex to complete the relocation. */
2103
/* A page in flush_list can be in BUF_BLOCK_REMOVE_HASH
2104
state. This happens when a page is in the middle of
2105
being relocated. In that case the original descriptor
2106
can have this state and still be in the flush list
2107
waiting to acquire the flush_list_mutex to complete
2216
2109
ut_a(buf_page_in_file(bpage)
2217
2110
|| buf_page_get_state(bpage) == BUF_BLOCK_REMOVE_HASH);
2220
2113
if (UNIV_LIKELY_NULL(buf_pool->flush_rbt)) {
2221
buf_page_t** prpage;
2224
prpage = rbt_value(buf_page_t*, rnode);
2117
rpage = *rbt_value(buf_page_t*, rnode);
2227
ut_a(*prpage == bpage);
2120
ut_a(rpage == bpage);
2228
2121
rnode = rbt_next(buf_pool->flush_rbt, rnode);