Skip to content
/ server Public

Commit 8d5d027

Browse files
committed
MDEV-31956 SSD based InnoDB buffer pool extension
Code cleanup
1 parent f8fbb14 commit 8d5d027

File tree

10 files changed

+75
-102
lines changed

10 files changed

+75
-102
lines changed

mysql-test/suite/innodb/t/ext_buf_pool.test

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ START TRANSACTION WITH CONSISTENT SNAPSHOT;
2525

2626
--let $DATADIR = `select @@datadir`
2727

28-
#--let $restart_parameters=--innodb-extended-buffer-pool-size=10M
29-
#--source include/restart_mysqld.inc
30-
31-
# Set ext buffer pool file size and check it was created, check it's size
32-
#--list_files $DATADIR ext_buffer_pool
33-
3428
--disable_query_log
3529
--error 0,ER_UNKNOWN_SYSTEM_VARIABLE
3630
SET @old_innodb_limit_optimistic_insert_debug = @@innodb_limit_optimistic_insert_debug;
@@ -169,13 +163,3 @@ SET GLOBAL innodb_limit_optimistic_insert_debug = @old_innodb_limit_optimistic_i
169163

170164
--disconnect prevent_purge
171165
--source include/wait_until_count_sessions.inc
172-
173-
174-
# Restart server with different buffer pool size, check the size is changed
175-
176-
# Restart server with different ext buffer pool location, check it was created
177-
178-
# Restart server with some impossible ext buffer pool location, check on error
179-
180-
# Check extended buffer pool file is not copied during backup and created
181-
# during backup restoring

storage/innobase/buf/buf0buf.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,6 @@ void buf_pool_t::close() noexcept
16511651
page_hash.free();
16521652

16531653
io_buf.close();
1654-
16551654
aligned_free(const_cast<byte*>(field_ref_zero));
16561655
field_ref_zero= nullptr;
16571656
}
@@ -3744,11 +3743,8 @@ dberr_t buf_page_t::read_complete(const fil_node_t &node,
37443743
ut_ad(f > READ_FIX);
37453744
ut_ad(f < WRITE_FIX);
37463745
}
3747-
else
3748-
{
3749-
if (!recv_recover_page(node.space, this))
3750-
return DB_PAGE_CORRUPTED;
3751-
}
3746+
else if (!recv_recover_page(node.space, this))
3747+
return DB_PAGE_CORRUPTED;
37523748

37533749
if (UNIV_UNLIKELY(MONITOR_IS_ON(MONITOR_MODULE_BUF_PAGE)))
37543750
buf_page_monitor(*this, true);

storage/innobase/buf/buf0flu.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ ATTRIBUTE_COLD void buf_pool_t::release_freed_page(buf_page_t *bpage) noexcept
762762

763763
/** Write a flushable page to a file or free a freeable block.
764764
@param space tablespace
765-
@param to_ext_buf wherher to write the page to external buffer pull file
765+
@param to_ext_buf whether to write the page to external buffer pull file
766766
@return whether a page write was initiated and buf_pool.mutex released */
767767
bool buf_page_t::flush(fil_space_t *space, bool to_ext_buf) noexcept
768768
{
@@ -2987,6 +2987,7 @@ void buf_flush_sync() noexcept
29872987
thd_wait_begin(nullptr, THD_WAIT_DISKIO);
29882988
tpool::tpool_wait_begin();
29892989
log_sys.latch.wr_lock(SRW_LOCK_CALL);
2990+
29902991
for (lsn_t lsn= log_sys.get_lsn();;)
29912992
{
29922993
log_sys.latch.wr_unlock();
@@ -2997,7 +2998,6 @@ void buf_flush_sync() noexcept
29972998
while (buf_flush_sync_lsn)
29982999
my_cond_wait(&buf_pool.done_flush_list,
29993000
&buf_pool.flush_list_mutex.m_mutex);
3000-
30013001
--buf_pool.done_flush_list_waiters_count;
30023002
mysql_mutex_unlock(&buf_pool.flush_list_mutex);
30033003
log_sys.latch.wr_lock(SRW_LOCK_CALL);

storage/innobase/buf/buf0rea.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ struct page_init_result {
6666
read from from exretnal buffer pool file */
6767
};
6868

69-
7069
/** Initialize a page for read to the buffer buf_pool. If the page is
7170
(1) already in buf_pool, or
7271
(2) if the tablespace has been or is being deleted,

storage/innobase/fil/fil0fil.cc

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,14 +1754,6 @@ fil_space_t *fil_space_t::drop(uint32_t id, pfs_os_file_t *detached_handle)
17541754
return space;
17551755
}
17561756

1757-
void fil_space_t::remove_file_low()
1758-
{
1759-
fil_node_t *node= chain.start;
1760-
ut_ad(node);
1761-
ut_ad(!node->is_open());
1762-
os_file_delete(innodb_data_file_key, node->name);
1763-
}
1764-
17651757
/** Close a single-table tablespace on failed IMPORT TABLESPACE.
17661758
The tablespace must be cached in the memory cache.
17671759
Free all pages used by the tablespace. */
@@ -2916,8 +2908,8 @@ fil_io_t fil_space_t::io(const IORequest &type, os_offset_t offset, size_t len,
29162908
goto release_sync_write;
29172909
} else {
29182910
/* Queue the aio request */
2919-
err = os_aio(IORequest{bpage, type.slot, node, type.type}, buf,
2920-
offset, len);
2911+
err = os_aio(IORequest{bpage, type.slot, node, type.type},
2912+
buf, offset, len);
29212913
}
29222914

29232915
if (!type.is_async()) {
@@ -2937,11 +2929,11 @@ fil_io_t fil_space_t::io(const IORequest &type, os_offset_t offset, size_t len,
29372929
return {err, node};
29382930
}
29392931

2940-
bool fil_system_t::create_ext_file() {
2932+
bool fil_system_t::create_ext_file() noexcept {
29412933
bool ret;
29422934
ext_bp_file= pfs_create_temp_file(
29432935
ext_bp_path ? ext_bp_path : fil_path_to_mysql_datadir,
2944-
"/Extended buffer pool file", "ext_buf_", 0);
2936+
"/Extended buffer pool file", "ext_buf_");
29452937
if (ext_bp_file == OS_FILE_CLOSED)
29462938
{
29472939
sql_print_error("Cannot open/create extended buffer pool file");
@@ -3067,8 +3059,12 @@ void IORequest::read_complete(int io_error) const noexcept
30673059
{
30683060
sql_print_error("InnoDB: Read error %d of page " UINT32PF " in file %s",
30693061
io_error, id.page_no(),
3070-
ext_buf() ? "of external buffer pool" : node_ptr->name);
3071-
if (!ext_buf())
3062+
ext_buf() ? "of external buffer pool, external buffer "
3063+
"pool is disabled"
3064+
: node_ptr->name);
3065+
if (ext_buf())
3066+
fil_system.ext_buf_pool_disable();
3067+
else
30723068
recv_sys.free_corrupted_page(id, *node_ptr);
30733069
buf_pool.corrupted_evict(buf_page, buf_page_t::READ_FIX + 1);
30743070
corrupted:
@@ -3455,13 +3451,8 @@ fil_space_t *fil_space_t::prev_in_unflushed_spaces() noexcept
34553451

34563452
#endif
34573453

3458-
/** Create temporary merge files in the given paramater path, and if
3459-
UNIV_PFS_IO defined, register the file descriptor with Performance Schema.
3460-
@param[in] path location for creating temporary merge files, or NULL
3461-
@return File descriptor */
3462-
pfs_os_file_t pfs_create_temp_file(const char *path,
3463-
const char *label, const char *prefix,
3464-
int mode)
3454+
pfs_os_file_t pfs_create_temp_file(const char *path, const char *label,
3455+
const char *prefix)
34653456
{
34663457
if (!path)
34673458
{

storage/innobase/handler/ha_innodb.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3671,6 +3671,9 @@ static void innodb_force_LRU_eviction_set(THD *, st_mysql_sys_var *, void *,
36713671
buf_pool.force_LRU_eviction_to_ebp= *static_cast<const my_bool *>(save);
36723672
if (buf_pool.force_LRU_eviction_to_ebp)
36733673
{
3674+
/* Wake up page cleaner twice, the first one is to flush dirty pages to
3675+
data files, the second one is to flush clean pages to external buffer pool.
3676+
*/
36743677
mysql_mutex_lock(&buf_pool.flush_list_mutex);
36753678
buf_pool.page_cleaner_wakeup(true);
36763679
my_cond_wait(&buf_pool.done_flush_list,

storage/innobase/include/buf0buf.h

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -866,24 +866,6 @@ class buf_page_t : public buf_page_base_t
866866
unsigned is_accessed() const noexcept
867867
{ ut_ad(in_file()); return access_time; }
868868
};
869-
/* TODO: offsetof() doesn't work on non-standard classes
870-
static_assert(offsetof(ext_buf_page_t, id) == offsetof(buf_page_t, id_), "");
871-
static_assert(offsetof(ext_buf_page_t, hash) == offsetof(buf_page_t, hash),
872-
"");
873-
static_assert(offsetof(ext_buf_page_t, frame) == offsetof(buf_page_t, frame),
874-
"");
875-
#ifdef UNIV_DEBUG
876-
static_assert(offsetof(ext_buf_page_t, in_LRU_list) ==
877-
offsetof(buf_page_t, in_LRU_list),
878-
"");
879-
static_assert(offsetof(ext_buf_page_t, in_page_hash) ==
880-
offsetof(buf_page_t, in_page_hash),
881-
"");
882-
static_assert(offsetof(ext_buf_page_t, in_free_list) ==
883-
offsetof(buf_page_t, in_free_list),
884-
"");
885-
#endif
886-
*/
887869

888870
/** The buffer control block structure */
889871

@@ -1191,6 +1173,8 @@ class buf_pool_t
11911173
ext_buf_pages_array */
11921174
size_t extended_pages;
11931175
#ifdef UNIV_DEBUG
1176+
/** Shows if force LRU eviction to external buffer poll is currently on.
1177+
Debug only. */
11941178
my_bool force_LRU_eviction_to_ebp;
11951179
#endif
11961180
/** Hash cell chain in page_hash_table */

storage/innobase/include/fil0fil.h

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,6 @@ struct fil_space_t final
524524
another concurrent thread */
525525
static fil_space_t *drop(uint32_t id, pfs_os_file_t *detached_handle);
526526

527-
void remove_file_low();
528-
529527
private:
530528
MY_ATTRIBUTE((warn_unused_result))
531529
/** Try to acquire a tablespace reference (increment referenced()).
@@ -1420,6 +1418,9 @@ struct fil_system_t
14201418
#ifdef __linux__
14211419
/** available block devices that reside on non-rotational storage */
14221420
std::vector<dev_t> ssd;
1421+
1422+
/** External buffer pool file handler */
1423+
pfs_os_file_t ext_bp_file;
14231424
public:
14241425
/** @return whether a file system device is on non-rotational storage */
14251426
bool is_ssd(dev_t dev) const noexcept
@@ -1445,9 +1446,6 @@ struct fil_system_t
14451446
mysql_mutex_t mutex;
14461447
fil_space_t* sys_space; /*!< The innodb_system tablespace */
14471448
fil_space_t* temp_space; /*!< The innodb_temporary tablespace */
1448-
private:
1449-
pfs_os_file_t ext_bp_file;
1450-
14511449
public:
14521450

14531451
/** Extended buffer pool file path */
@@ -1457,14 +1455,6 @@ struct fil_system_t
14571455
not used. */
14581456
size_t ext_bp_size;
14591457

1460-
/** Create external buffer pool file.
1461-
@return whether the creation failed */
1462-
bool create_ext_file();
1463-
dberr_t ext_bp_io(buf_page_t &bpage, ext_buf_page_t &ext_buf_page,
1464-
IORequest::Type io_request_type, buf_tmp_buffer_t *slot,
1465-
size_t len, void *buf) noexcept;
1466-
bool ext_buf_pool_enabled() const { return ext_bp_size; }
1467-
void ext_buf_pool_disable() { ext_bp_size= 0; }
14681458
/** Map of fil_space_t::id to fil_space_t* */
14691459
hash_table_t spaces;
14701460

@@ -1522,6 +1512,33 @@ struct fil_system_t
15221512
potential space_id reuse */
15231513
bool space_id_reuse_warned;
15241514

1515+
/** Create external buffer pool file.
1516+
@return whether the creation failed */
1517+
bool create_ext_file() noexcept;
1518+
1519+
/** External bufer pool os_aio() wrapper.
1520+
@param bpage buffer pool page for read/write
1521+
@param ext_buf_page external buffer pool page which will be freed on read
1522+
completion and replace bpage in buffer pool on write
1523+
completion
1524+
@param io_request_type IORequest::WRITE_ASYNC, IORequest::READ_SYNC or
1525+
IORequest::READ_ASYNC
1526+
@param slot memory to be used for encrypted or page_compressed
1527+
pages
1528+
@param len length to read/write
1529+
@param buf buffer
1530+
@retval DB_SUCCESS if request was queued successfully
1531+
@retval DB_IO_ERROR on I/O error */
1532+
dberr_t ext_bp_io(buf_page_t &bpage, ext_buf_page_t &ext_buf_page,
1533+
IORequest::Type io_request_type, buf_tmp_buffer_t *slot,
1534+
size_t len, void *buf) noexcept;
1535+
1536+
/** Returns if external buffer pool is enabled. */
1537+
bool ext_buf_pool_enabled() const { return ext_bp_size; }
1538+
1539+
/** Disable external boffer pool */
1540+
void ext_buf_pool_disable() { ext_bp_size= 0; }
1541+
15251542
/** Add the file to the end of opened spaces list in
15261543
fil_system.space_list, so that fil_space_t::try_to_close() should close
15271544
it as a last resort.
@@ -1858,7 +1875,12 @@ ulint fil_space_get_block_size(const fil_space_t* space, unsigned offset)
18581875
bool fil_crypt_check(fil_space_crypt_t *crypt_data, const char *f_name)
18591876
noexcept;
18601877

1878+
/** Create temporary files in the given paramater path, and if
1879+
UNIV_PFS_IO defined, register the file descriptor with Performance Schema.
1880+
@param path location for creating temporary merge files, or NULL
1881+
@param label label for registration in Performance Schema if path == nullptr
1882+
@param prefix temporary file name prefix
1883+
@return File descriptor */
18611884
pfs_os_file_t pfs_create_temp_file(const char *path, const char *label,
1862-
const char *prefix, int mode);
1863-
1885+
const char *prefix);
18641886
#endif /* UNIV_INNOCHECKSUM */

storage/innobase/os/os0file.cc

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3347,21 +3347,22 @@ dberr_t os_aio(const IORequest &type, void *buf, os_offset_t offset,
33473347
}
33483348

33493349
/** Request a read or write.
3350-
@param type I/O request
3351-
@param buf buffer
3352-
@param offset file offset
3353-
@param n number of bytes
3350+
@param type I/O request
3351+
@param buf buffer
3352+
@param offset file offset
3353+
@param n number of bytes
33543354
@retval DB_SUCCESS if request was queued successfully
33553355
@retval DB_IO_ERROR on I/O error */
3356-
dberr_t os_aio(const IORequest &type, void *buf, os_offset_t offset, size_t n)
3357-
noexcept {
3358-
ut_ad(type.node());
3359-
ut_ad(type.node()->is_open());
3360-
dberr_t err = os_aio(type, buf, offset, n, type.node()->handle,
3361-
type.node()->name);
3362-
if (err == DB_IO_ERROR)
3363-
type.node()->space->release();
3364-
return err;
3356+
dberr_t os_aio(const IORequest &type, void *buf, os_offset_t offset,
3357+
size_t n) noexcept
3358+
{
3359+
ut_ad(type.node());
3360+
ut_ad(type.node()->is_open());
3361+
dberr_t err=
3362+
os_aio(type, buf, offset, n, type.node()->handle, type.node()->name);
3363+
if (err == DB_IO_ERROR)
3364+
type.node()->space->release();
3365+
return err;
33653366
}
33663367

33673368
void os_aio_print(FILE *file) noexcept

storage/innobase/row/row0merge.cc

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4347,9 +4347,8 @@ void row_merge_drop_temp_indexes()
43474347
@return File descriptor */
43484348
pfs_os_file_t row_merge_file_create_low(const char *path)
43494349
{
4350-
auto fd=
4351-
pfs_create_temp_file(path, merge_temp_file_label, merge_temp_file_prefix,
4352-
O_BINARY | O_SEQUENTIAL);
4350+
auto fd= pfs_create_temp_file(path, merge_temp_file_label,
4351+
merge_temp_file_prefix);
43534352
if (fd == OS_FILE_CLOSED)
43544353
{
43554354
ib::error() << "Cannot create temporary merge file";
@@ -4371,13 +4370,7 @@ row_merge_file_create(
43714370
merge_file->fd =
43724371
pfs_create_temp_file(path,
43734372
merge_temp_file_label,
4374-
merge_temp_file_prefix,
4375-
#if !defined _WIN32 && defined O_DIRECT
4376-
srv_disable_sort_file_cache
4377-
? O_DIRECT | O_BINARY | O_SEQUENTIAL
4378-
:
4379-
#endif
4380-
O_BINARY | O_SEQUENTIAL);
4373+
merge_temp_file_prefix);
43814374
if (merge_file->fd == OS_FILE_CLOSED)
43824375
{
43834376
ib::error() << "Cannot create temporary merge file";

0 commit comments

Comments
 (0)