Commit 85cbfaef authored by Marko Mäkelä's avatar Marko Mäkelä

Merge 10.5 into 10.6

parents f169dfb4 1495f057
...@@ -3445,7 +3445,9 @@ static void xb_load_single_table_tablespace(const char *dirname, ...@@ -3445,7 +3445,9 @@ static void xb_load_single_table_tablespace(const char *dirname,
if (err == DB_SUCCESS && file->space_id() != SRV_TMP_SPACE_ID) { if (err == DB_SUCCESS && file->space_id() != SRV_TMP_SPACE_ID) {
space = fil_space_t::create( space = fil_space_t::create(
file->space_id(), file->flags(), file->space_id(), file->flags(),
FIL_TYPE_TABLESPACE, NULL/* TODO: crypt_data */); FIL_TYPE_TABLESPACE, nullptr/* TODO: crypt_data */,
FIL_ENCRYPTION_DEFAULT,
file->handle() != OS_FILE_CLOSED);
ut_a(space != NULL); ut_a(space != NULL);
fil_node_t* node= space->add( fil_node_t* node= space->add(
...@@ -5312,7 +5314,8 @@ xb_delta_open_matching_space( ...@@ -5312,7 +5314,8 @@ xb_delta_open_matching_space(
ut_ad(fil_space_t::physical_size(flags) == info.page_size); ut_ad(fil_space_t::physical_size(flags) == info.page_size);
if (fil_space_t::create(info.space_id, flags, if (fil_space_t::create(info.space_id, flags,
FIL_TYPE_TABLESPACE, 0)) { FIL_TYPE_TABLESPACE, 0, FIL_ENCRYPTION_DEFAULT,
true)) {
*success = xb_space_create_file(real_name, info.space_id, *success = xb_space_create_file(real_name, info.space_id,
flags, &file); flags, &file);
} else { } else {
......
...@@ -31,8 +31,10 @@ insert into t8 values (1, 'publicmessage'); ...@@ -31,8 +31,10 @@ insert into t8 values (1, 'publicmessage');
insert into t9 values (1, 'pugliccompressedaaaaaaaaabbbbbbbbbbbbbbccccccccccccccc'); insert into t9 values (1, 'pugliccompressedaaaaaaaaabbbbbbbbbbbbbbccccccccccccccc');
--echo # should list tables t1-t6 --echo # should list tables t1-t6
--sorted_result
SELECT NAME,ENCRYPTION_SCHEME,CURRENT_KEY_ID FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0 AND NAME LIKE 'enctests%'; SELECT NAME,ENCRYPTION_SCHEME,CURRENT_KEY_ID FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION <> 0 AND NAME LIKE 'enctests%';
--echo # should list tables t7-t9 --echo # should list tables t7-t9
--sorted_result
SELECT NAME,ENCRYPTION_SCHEME,CURRENT_KEY_ID FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0 and NAME LIKE 'enctests%'; SELECT NAME,ENCRYPTION_SCHEME,CURRENT_KEY_ID FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0 and NAME LIKE 'enctests%';
--let $MYSQLD_DATADIR=`select @@datadir` --let $MYSQLD_DATADIR=`select @@datadir`
......
...@@ -9,6 +9,7 @@ INSERT INTO t2 VALUES ('foobar'); ...@@ -9,6 +9,7 @@ INSERT INTO t2 VALUES ('foobar');
# #
# MDEV-9640: Add used key_id to INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION # MDEV-9640: Add used key_id to INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION
# #
--sorted_result
SELECT NAME, ENCRYPTION_SCHEME, MIN_KEY_VERSION, CURRENT_KEY_VERSION, SELECT NAME, ENCRYPTION_SCHEME, MIN_KEY_VERSION, CURRENT_KEY_VERSION,
CURRENT_KEY_ID CURRENT_KEY_ID
FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION
......
...@@ -122,6 +122,9 @@ bool fil_space_t::try_to_close(bool print_info) ...@@ -122,6 +122,9 @@ bool fil_space_t::try_to_close(bool print_info)
} }
node->close(); node->close();
fil_system.move_closed_last_to_space_list(node->space);
return true; return true;
} }
...@@ -392,13 +395,7 @@ static bool fil_node_open_file_low(fil_node_t *node) ...@@ -392,13 +395,7 @@ static bool fil_node_open_file_low(fil_node_t *node)
ut_ad(node->is_open()); ut_ad(node->is_open());
if (UNIV_LIKELY(!fil_system.freeze_space_list)) fil_system.move_opened_last_to_space_list(node->space);
{
/* Move the file last in fil_system.space_list, so that
fil_space_t::try_to_close() should close it as a last resort. */
fil_system.space_list.erase(space_list_t::iterator(node->space));
fil_system.space_list.push_back(*node->space);
}
fil_system.n_open++; fil_system.n_open++;
return true; return true;
...@@ -795,7 +792,17 @@ pfs_os_file_t fil_system_t::detach(fil_space_t *space, bool detach_handle) ...@@ -795,7 +792,17 @@ pfs_os_file_t fil_system_t::detach(fil_space_t *space, bool detach_handle)
space->is_in_default_encrypt= false; space->is_in_default_encrypt= false;
default_encrypt_tables.remove(*space); default_encrypt_tables.remove(*space);
} }
space_list.erase(space_list_t::iterator(space));
{
space_list_t::iterator s= space_list_t::iterator(space);
if (space_list_last_opened == space)
{
space_list_t::iterator prev= s;
space_list_last_opened= &*--prev;
}
space_list.erase(s);
}
if (space == sys_space) if (space == sys_space)
sys_space= nullptr; sys_space= nullptr;
else if (space == temp_space) else if (space == temp_space)
...@@ -913,12 +920,14 @@ fil_space_free( ...@@ -913,12 +920,14 @@ fil_space_free(
@param purpose tablespace purpose @param purpose tablespace purpose
@param crypt_data encryption information @param crypt_data encryption information
@param mode encryption mode @param mode encryption mode
@param opened true if space files are opened
@return pointer to created tablespace, to be filled in with add() @return pointer to created tablespace, to be filled in with add()
@retval nullptr on failure (such as when the same tablespace exists) */ @retval nullptr on failure (such as when the same tablespace exists) */
fil_space_t *fil_space_t::create(ulint id, ulint flags, fil_space_t *fil_space_t::create(ulint id, ulint flags,
fil_type_t purpose, fil_type_t purpose,
fil_space_crypt_t *crypt_data, fil_space_crypt_t *crypt_data,
fil_encryption_t mode) fil_encryption_t mode,
bool opened)
{ {
fil_space_t* space; fil_space_t* space;
...@@ -971,7 +980,10 @@ fil_space_t *fil_space_t::create(ulint id, ulint flags, ...@@ -971,7 +980,10 @@ fil_space_t *fil_space_t::create(ulint id, ulint flags,
HASH_INSERT(fil_space_t, hash, &fil_system.spaces, id, space); HASH_INSERT(fil_space_t, hash, &fil_system.spaces, id, space);
fil_system.space_list.push_back(*space); if (opened)
fil_system.add_opened_last_to_space_list(space);
else
fil_system.space_list.push_back(*space);
switch (id) { switch (id) {
case 0: case 0:
...@@ -1296,6 +1308,15 @@ void fil_system_t::close() ...@@ -1296,6 +1308,15 @@ void fil_system_t::close()
#endif /* __linux__ */ #endif /* __linux__ */
} }
void fil_system_t::add_opened_last_to_space_list(fil_space_t *space)
{
if (UNIV_LIKELY(space_list_last_opened != nullptr))
space_list.insert(space_list_t::iterator(space_list_last_opened), *space);
else
space_list.push_back(*space);
space_list_last_opened= space;
}
/** Extend all open data files to the recovered size */ /** Extend all open data files to the recovered size */
ATTRIBUTE_COLD void fil_system_t::extend_to_recv_size() ATTRIBUTE_COLD void fil_system_t::extend_to_recv_size()
{ {
...@@ -1963,7 +1984,7 @@ fil_ibd_create( ...@@ -1963,7 +1984,7 @@ fil_ibd_create(
if (fil_space_t* space = fil_space_t::create(space_id, flags, if (fil_space_t* space = fil_space_t::create(space_id, flags,
FIL_TYPE_TABLESPACE, FIL_TYPE_TABLESPACE,
crypt_data, mode)) { crypt_data, mode, true)) {
fil_node_t* node = space->add(path, file, size, false, true); fil_node_t* node = space->add(path, file, size, false, true);
IF_WIN(node->find_metadata(), node->find_metadata(file, true)); IF_WIN(node->find_metadata(), node->find_metadata(file, true));
mtr.start(); mtr.start();
......
...@@ -958,11 +958,13 @@ struct fil_space_t final ...@@ -958,11 +958,13 @@ struct fil_space_t final
@param purpose tablespace purpose @param purpose tablespace purpose
@param crypt_data encryption information @param crypt_data encryption information
@param mode encryption mode @param mode encryption mode
@param opened true if space files are opened
@return pointer to created tablespace, to be filled in with add() @return pointer to created tablespace, to be filled in with add()
@retval nullptr on failure (such as when the same tablespace exists) */ @retval nullptr on failure (such as when the same tablespace exists) */
static fil_space_t *create(ulint id, ulint flags, static fil_space_t *create(ulint id, ulint flags,
fil_type_t purpose, fil_space_crypt_t *crypt_data, fil_type_t purpose, fil_space_crypt_t *crypt_data,
fil_encryption_t mode= FIL_ENCRYPTION_DEFAULT); fil_encryption_t mode= FIL_ENCRYPTION_DEFAULT,
bool opened= false);
MY_ATTRIBUTE((warn_unused_result)) MY_ATTRIBUTE((warn_unused_result))
/** Acquire a tablespace reference. /** Acquire a tablespace reference.
...@@ -1447,6 +1449,11 @@ struct fil_system_t { ...@@ -1447,6 +1449,11 @@ struct fil_system_t {
private: private:
bool m_initialised; bool m_initialised;
/** Points to the last opened space in space_list. Protected with
fil_system.mutex. */
fil_space_t *space_list_last_opened= nullptr;
#ifdef __linux__ #ifdef __linux__
/** available block devices that reside on non-rotational storage */ /** available block devices that reside on non-rotational storage */
std::vector<dev_t> ssd; std::vector<dev_t> ssd;
...@@ -1492,8 +1499,10 @@ struct fil_system_t { ...@@ -1492,8 +1499,10 @@ struct fil_system_t {
/** nonzero if fil_node_open_file_low() should avoid moving the tablespace /** nonzero if fil_node_open_file_low() should avoid moving the tablespace
to the end of space_list, for FIFO policy of try_to_close() */ to the end of space_list, for FIFO policy of try_to_close() */
ulint freeze_space_list; ulint freeze_space_list;
/** List of all file spaces, opened spaces should be at the top of the list
to optimize try_to_close() execution. Protected with fil_system.mutex. */
ilist<fil_space_t, space_list_tag_t> space_list; ilist<fil_space_t, space_list_tag_t> space_list;
/*!< list of all file spaces */
ilist<fil_space_t, named_spaces_tag_t> named_spaces; ilist<fil_space_t, named_spaces_tag_t> named_spaces;
/*!< list of all file spaces /*!< list of all file spaces
for which a FILE_MODIFY for which a FILE_MODIFY
...@@ -1509,6 +1518,49 @@ struct fil_system_t { ...@@ -1509,6 +1518,49 @@ struct fil_system_t {
has issued a warning about has issued a warning about
potential space_id reuse */ potential space_id reuse */
/** Add the file to the end of opened spaces list in
fil_system.space_list, so that fil_space_t::try_to_close() should close
it as a last resort.
@param space space to add */
void add_opened_last_to_space_list(fil_space_t *space);
/** Move the file to the end of opened spaces list in
fil_system.space_list, so that fil_space_t::try_to_close() should close
it as a last resort.
@param space space to move */
inline void move_opened_last_to_space_list(fil_space_t *space)
{
/* In the case when several files of the same space are added in a
row, there is no need to remove and add a space to the same position
in space_list. It can be for system or temporary tablespaces. */
if (freeze_space_list || space_list_last_opened == space)
return;
space_list.erase(space_list_t::iterator(space));
add_opened_last_to_space_list(space);
}
/** Move closed file last in fil_system.space_list, so that
fil_space_t::try_to_close() iterates opened files first in FIFO order,
i.e. first opened, first closed.
@param space space to move */
void move_closed_last_to_space_list(fil_space_t *space)
{
if (UNIV_UNLIKELY(freeze_space_list))
return;
space_list_t::iterator s= space_list_t::iterator(space);
if (space_list_last_opened == space)
{
space_list_t::iterator prev= s;
space_list_last_opened= &*--prev;
}
space_list.erase(s);
space_list.push_back(*space);
}
/** Return the next tablespace from default_encrypt_tables list. /** Return the next tablespace from default_encrypt_tables list.
@param space previous tablespace (nullptr to start from the start) @param space previous tablespace (nullptr to start from the start)
@param recheck whether the removal condition needs to be rechecked after @param recheck whether the removal condition needs to be rechecked after
......
...@@ -556,7 +556,8 @@ static ulint srv_undo_tablespace_open(bool create, const char* name, ulint i) ...@@ -556,7 +556,8 @@ static ulint srv_undo_tablespace_open(bool create, const char* name, ulint i)
fil_set_max_space_id_if_bigger(space_id); fil_set_max_space_id_if_bigger(space_id);
fil_space_t *space= fil_space_t::create(space_id, fsp_flags, fil_space_t *space= fil_space_t::create(space_id, fsp_flags,
FIL_TYPE_TABLESPACE, NULL); FIL_TYPE_TABLESPACE, nullptr,
FIL_ENCRYPTION_DEFAULT, true);
ut_a(fil_validate()); ut_a(fil_validate());
ut_a(space); ut_a(space);
...@@ -905,9 +906,7 @@ static lsn_t srv_prepare_to_delete_redo_log_file(bool old_exists) ...@@ -905,9 +906,7 @@ static lsn_t srv_prepare_to_delete_redo_log_file(bool old_exists)
{ {
DBUG_ENTER("srv_prepare_to_delete_redo_log_file"); DBUG_ENTER("srv_prepare_to_delete_redo_log_file");
/* Disable checkpoints in the page cleaner. */ ut_ad(recv_sys.recovery_on);
ut_ad(!recv_sys.recovery_on);
recv_sys.recovery_on= true;
/* Clean the buffer pool. */ /* Clean the buffer pool. */
buf_flush_sync(); buf_flush_sync();
...@@ -1589,10 +1588,10 @@ dberr_t srv_start(bool create_new_db) ...@@ -1589,10 +1588,10 @@ dberr_t srv_start(bool create_new_db)
} }
} }
recv_sys.debug_free();
if (srv_operation == SRV_OPERATION_RESTORE if (srv_operation == SRV_OPERATION_RESTORE
|| srv_operation == SRV_OPERATION_RESTORE_EXPORT) { || srv_operation == SRV_OPERATION_RESTORE_EXPORT) {
buf_flush_sync();
recv_sys.debug_free();
/* After applying the redo log from /* After applying the redo log from
SRV_OPERATION_BACKUP, flush the changes SRV_OPERATION_BACKUP, flush the changes
to the data files and truncate or delete the log. to the data files and truncate or delete the log.
...@@ -1684,6 +1683,8 @@ dberr_t srv_start(bool create_new_db) ...@@ -1684,6 +1683,8 @@ dberr_t srv_start(bool create_new_db)
return(srv_init_abort(err)); return(srv_init_abort(err));
} }
} }
recv_sys.debug_free();
} }
ut_ad(err == DB_SUCCESS); ut_ad(err == DB_SUCCESS);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment