Commit 536112dd authored by Jan Lindström's avatar Jan Lindström

MDEV-8195: InnoDB: Error: trying to access tablespace 11262 page no. 7,...

MDEV-8195: InnoDB: Error: trying to access tablespace 11262 page no. 7, InnoDB: but the tablespace does not exist or is just being dropped.

Analysis: Problem was that we did try to read from tablespace
that was being dropped.

Fixed by introducing a new function to find a tablespace only
if it is not being dropped currently and adding this check
before trying to read pages from tablespace.
parent 8635c4b4
......@@ -1067,7 +1067,7 @@ fil_crypt_start_encrypting_space(
do
{
if (fil_crypt_is_closing(space) ||
fil_tablespace_is_being_deleted(space)) {
fil_space_found_by_id(space)) {
break;
}
......@@ -1085,7 +1085,7 @@ fil_crypt_start_encrypting_space(
&mtr);
if (fil_crypt_is_closing(space) ||
fil_tablespace_is_being_deleted(space)) {
fil_space_found_by_id(space) == NULL) {
mtr_commit(&mtr);
break;
}
......@@ -1107,7 +1107,7 @@ fil_crypt_start_encrypting_space(
mtr_commit(&mtr);
if (fil_crypt_is_closing(space) ||
fil_tablespace_is_being_deleted(space)) {
fil_space_found_by_id(space) == NULL) {
break;
}
......@@ -1129,7 +1129,7 @@ fil_crypt_start_encrypting_space(
sum_pages += n_pages;
} while (!success &&
!fil_crypt_is_closing(space) &&
!fil_tablespace_is_being_deleted(space));
!fil_space_found_by_id(space));
/* try to reacquire pending op */
if (fil_inc_pending_ops(space, true)) {
......@@ -1140,7 +1140,7 @@ fil_crypt_start_encrypting_space(
pending_op = true;
if (fil_crypt_is_closing(space) ||
fil_tablespace_is_being_deleted(space)) {
fil_space_found_by_id(space) == NULL) {
break;
}
......@@ -1219,7 +1219,10 @@ fil_crypt_space_needs_rotation(
bool* recheck) /*!< out: needs recheck ? */
{
ulint space = state->space;
if (fil_space_get_type(space) != FIL_TABLESPACE) {
/* Make sure that tablespace is found and it is normal tablespace */
if (fil_space_found_by_id(space) == NULL ||
fil_space_get_type(space) != FIL_TABLESPACE) {
return false;
}
......@@ -1553,11 +1556,6 @@ fil_crypt_start_rotate_space(
if (crypt_data->rotate_state.active_threads == 0) {
/* only first thread needs to init */
if (crypt_data->encryption == FIL_SPACE_ENCRYPTION_OFF) {
crypt_data->type = CRYPT_SCHEME_UNENCRYPTED;
} else {
crypt_data->type = CRYPT_SCHEME_1;
}
crypt_data->rotate_state.next_offset = 1; // skip page 0
/* no need to rotate beyond current max
* if space extends, it will be encrypted with newer version */
......@@ -1568,6 +1566,13 @@ fil_crypt_start_rotate_space(
key_state->key_version;
crypt_data->rotate_state.start_time = time(0);
if (crypt_data->type == CRYPT_SCHEME_UNENCRYPTED &&
crypt_data->encryption != FIL_SPACE_ENCRYPTION_OFF &&
key_state->key_version != 0) {
/* this is rotation unencrypted => encrypted */
crypt_data->type = CRYPT_SCHEME_1;
}
}
/* count active threads in space */
......@@ -1688,6 +1693,14 @@ fil_crypt_get_page_throttle_func(
return block;
}
/* Before reading from tablespace we need to make sure that
tablespace exists and is not is just being dropped. */
if (fil_crypt_is_closing(space) ||
fil_space_found_by_id(space) == NULL) {
return NULL;
}
state->crypt_stat.pages_read_from_disk++;
ullint start = ut_time_us(NULL);
......@@ -1795,7 +1808,7 @@ fil_crypt_rotate_page(
ulint sleeptime_ms = 0;
/* check if tablespace is closing before reading page */
if (fil_crypt_is_closing(space)) {
if (fil_crypt_is_closing(space) || fil_space_found_by_id(space) == NULL) {
return;
}
......@@ -1811,6 +1824,8 @@ fil_crypt_rotate_page(
offset, &mtr,
&sleeptime_ms);
if (block) {
bool modified = false;
int needs_scrubbing = BTR_SCRUB_SKIP_PAGE;
lsn_t block_lsn = block->page.newest_modification;
......@@ -1876,6 +1891,8 @@ fil_crypt_rotate_page(
&allocated,
&sleeptime_ms);
if (block) {
/* get required table/index and index-locks */
needs_scrubbing = btr_scrub_recheck_page(
&state->scrub_data, block, allocated, &mtr);
......@@ -1900,6 +1917,7 @@ fil_crypt_rotate_page(
* (mtr_commit() + mtr_start())
*/
}
}
if (needs_scrubbing != BTR_SCRUB_PAGE) {
/* if page didn't need scrubbing it might be that cleanups
......@@ -1932,6 +1950,7 @@ fil_crypt_rotate_page(
state->end_lsn = block_lsn;
}
}
}
if (sleeptime_ms) {
os_event_reset(fil_crypt_throttle_sleep_event);
......
......@@ -341,6 +341,26 @@ fil_space_get_by_id(
return(space);
}
/*******************************************************************//**
Returns the table space by a given id, NULL if not found. */
fil_space_t*
fil_space_found_by_id(
/*==================*/
ulint id) /*!< in: space id */
{
fil_space_t* space = NULL;
mutex_enter(&fil_system->mutex);
space = fil_space_get_by_id(id);
/* Not found if space is being deleted */
if (space && space->stop_new_ops) {
space = NULL;
}
mutex_exit(&fil_system->mutex);
return space;
}
/****************************************************************//**
Get space id from fil node */
ulint
......
......@@ -1252,6 +1252,13 @@ fil_system_exit(void);
/*==================*/
#ifndef UNIV_INNOCHECKSUM
/*******************************************************************//**
Returns the table space by a given id, NULL if not found. */
fil_space_t*
fil_space_found_by_id(
/*==================*/
ulint id); /*!< in: space id */
/*******************************************************************//**
Returns the table space by a given id, NULL if not found. */
fil_space_t*
......
......@@ -1067,7 +1067,7 @@ fil_crypt_start_encrypting_space(
do
{
if (fil_crypt_is_closing(space) ||
fil_tablespace_is_being_deleted(space)) {
fil_space_found_by_id(space) == NULL) {
break;
}
......@@ -1085,7 +1085,7 @@ fil_crypt_start_encrypting_space(
&mtr);
if (fil_crypt_is_closing(space) ||
fil_tablespace_is_being_deleted(space)) {
fil_space_found_by_id(space) == NULL) {
mtr_commit(&mtr);
break;
}
......@@ -1107,7 +1107,7 @@ fil_crypt_start_encrypting_space(
mtr_commit(&mtr);
if (fil_crypt_is_closing(space) ||
fil_tablespace_is_being_deleted(space)) {
fil_space_found_by_id(space) == NULL) {
break;
}
......@@ -1129,7 +1129,7 @@ fil_crypt_start_encrypting_space(
sum_pages += n_pages;
} while (!success &&
!fil_crypt_is_closing(space) &&
!fil_tablespace_is_being_deleted(space));
!fil_space_found_by_id(space));
/* try to reacquire pending op */
if (fil_inc_pending_ops(space, true)) {
......@@ -1140,7 +1140,7 @@ fil_crypt_start_encrypting_space(
pending_op = true;
if (fil_crypt_is_closing(space) ||
fil_tablespace_is_being_deleted(space)) {
fil_space_found_by_id(space) == NULL) {
break;
}
......@@ -1219,7 +1219,10 @@ fil_crypt_space_needs_rotation(
bool* recheck) /*!< out: needs recheck ? */
{
ulint space = state->space;
if (fil_space_get_type(space) != FIL_TABLESPACE) {
/* Make sure that tablespace is found and it is normal tablespace */
if (fil_space_found_by_id(space) == NULL ||
fil_space_get_type(space) != FIL_TABLESPACE) {
return false;
}
......@@ -1553,11 +1556,6 @@ fil_crypt_start_rotate_space(
if (crypt_data->rotate_state.active_threads == 0) {
/* only first thread needs to init */
if (crypt_data->encryption == FIL_SPACE_ENCRYPTION_OFF) {
crypt_data->type = CRYPT_SCHEME_UNENCRYPTED;
} else {
crypt_data->type = CRYPT_SCHEME_1;
}
crypt_data->rotate_state.next_offset = 1; // skip page 0
/* no need to rotate beyond current max
* if space extends, it will be encrypted with newer version */
......@@ -1568,6 +1566,13 @@ fil_crypt_start_rotate_space(
key_state->key_version;
crypt_data->rotate_state.start_time = time(0);
if (crypt_data->type == CRYPT_SCHEME_UNENCRYPTED &&
crypt_data->encryption != FIL_SPACE_ENCRYPTION_OFF &&
key_state->key_version != 0) {
/* this is rotation unencrypted => encrypted */
crypt_data->type = CRYPT_SCHEME_1;
}
}
/* count active threads in space */
......@@ -1688,6 +1693,14 @@ fil_crypt_get_page_throttle_func(
return block;
}
/* Before reading from tablespace we need to make sure that
tablespace exists and is not is just being dropped. */
if (fil_crypt_is_closing(space) ||
fil_space_found_by_id(space) == NULL) {
return NULL;
}
state->crypt_stat.pages_read_from_disk++;
ullint start = ut_time_us(NULL);
......@@ -1795,7 +1808,7 @@ fil_crypt_rotate_page(
ulint sleeptime_ms = 0;
/* check if tablespace is closing before reading page */
if (fil_crypt_is_closing(space)) {
if (fil_crypt_is_closing(space) || fil_space_found_by_id(space) == NULL) {
return;
}
......@@ -1811,6 +1824,8 @@ fil_crypt_rotate_page(
offset, &mtr,
&sleeptime_ms);
if (block) {
bool modified = false;
int needs_scrubbing = BTR_SCRUB_SKIP_PAGE;
lsn_t block_lsn = block->page.newest_modification;
......@@ -1876,6 +1891,8 @@ fil_crypt_rotate_page(
&allocated,
&sleeptime_ms);
if (block) {
/* get required table/index and index-locks */
needs_scrubbing = btr_scrub_recheck_page(
&state->scrub_data, block, allocated, &mtr);
......@@ -1900,6 +1917,7 @@ fil_crypt_rotate_page(
* (mtr_commit() + mtr_start())
*/
}
}
if (needs_scrubbing != BTR_SCRUB_PAGE) {
/* if page didn't need scrubbing it might be that cleanups
......@@ -1932,6 +1950,7 @@ fil_crypt_rotate_page(
state->end_lsn = block_lsn;
}
}
}
if (sleeptime_ms) {
os_event_reset(fil_crypt_throttle_sleep_event);
......
......@@ -344,6 +344,26 @@ fil_space_get_by_id(
return(space);
}
/*******************************************************************//**
Returns the table space by a given id, NULL if not found. */
fil_space_t*
fil_space_found_by_id(
/*==================*/
ulint id) /*!< in: space id */
{
fil_space_t* space = NULL;
mutex_enter(&fil_system->mutex);
space = fil_space_get_by_id(id);
/* Not found if space is being deleted */
if (space && space->stop_new_ops) {
space = NULL;
}
mutex_exit(&fil_system->mutex);
return space;
}
/****************************************************************//**
Get space id from fil node */
ulint
......
......@@ -1280,6 +1280,13 @@ fil_system_exit(void);
/*==================*/
#ifndef UNIV_INNOCHECKSUM
/*******************************************************************//**
Returns the table space by a given id, NULL if not found. */
fil_space_t*
fil_space_found_by_id(
/*==================*/
ulint id); /*!< in: space id */
/*******************************************************************//**
Returns the table space by a given id, NULL if not found. */
fil_space_t*
......
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