Commit 3005cebc authored by Marko Mäkelä's avatar Marko Mäkelä

Post-push fix for MDEV-12610 MariaDB start is slow

fil_crypt_read_crypt_data(): Remove an unnecessary
acquisition of fil_system->mutex. Remove a duplicated condition
from the callers.
parent 757339ef
......@@ -1116,40 +1116,33 @@ fil_crypt_needs_rotation(
}
/** Read page 0 and possible crypt data from there.
@param[in] space Tablespace */
@param[in,out] space Tablespace */
static inline
void
fil_crypt_read_crypt_data(fil_space_t* space)
{
mutex_enter(&fil_system->mutex);
/* If space does not contain crypt data and space size is 0
we have not yet read first page of tablespace. We need to
read it to find out tablespace current encryption status. */
if (!space->crypt_data && space->size == 0) {
mtr_t mtr;
mtr_start(&mtr);
ulint zip_size = fsp_flags_get_zip_size(space->flags);
ulint offset = fsp_header_get_crypt_offset(zip_size);
mutex_exit(&fil_system->mutex);
if (buf_block_t* block = buf_page_get(space->id, zip_size, 0,
RW_X_LATCH, &mtr)) {
byte* frame = buf_block_get_frame(block);
mutex_enter(&fil_system->mutex);
if (!space->crypt_data) {
space->crypt_data = fil_space_read_crypt_data(space->id,
frame, offset);
}
if (space->crypt_data || space->size) {
/* The encryption metadata has already been read, or
the tablespace is not encrypted and the file has been
opened already. */
return;
}
mutex_exit(&fil_system->mutex);
mtr_t mtr;
mtr_start(&mtr);
ulint zip_size = fsp_flags_get_zip_size(space->flags);
ulint offset = fsp_header_get_crypt_offset(zip_size);
if (buf_block_t* block = buf_page_get(space->id, zip_size, 0,
RW_S_LATCH, &mtr)) {
mutex_enter(&fil_system->mutex);
if (!space->crypt_data) {
space->crypt_data = fil_space_read_crypt_data(
space->id, block->frame, offset);
}
mtr_commit(&mtr);
} else {
mutex_exit(&fil_system->mutex);
}
mtr_commit(&mtr);
}
/***********************************************************************
......@@ -1656,12 +1649,7 @@ fil_crypt_find_space_to_rotate(
}
while (!state->should_shutdown() && state->space) {
/* If there is no crypt data and we have not yet read
page 0 for this tablespace, we need to read it before
we can continue. */
if (!state->space->crypt_data) {
fil_crypt_read_crypt_data(state->space);
}
fil_crypt_read_crypt_data(state->space);
if (fil_crypt_space_needs_rotation(state, key_state, recheck)) {
ut_ad(key_state->key_id);
......@@ -2589,18 +2577,10 @@ fil_space_crypt_get_status(
memset(status, 0, sizeof(*status));
ut_ad(space->n_pending_ops > 0);
/* If there is no crypt data and we have not yet read
page 0 for this tablespace, we need to read it before
we can continue. */
if (!space->crypt_data) {
fil_crypt_read_crypt_data(const_cast<fil_space_t*>(space));
}
fil_space_crypt_t* crypt_data = space->crypt_data;
fil_crypt_read_crypt_data(const_cast<fil_space_t*>(space));
status->space = space->id;
if (crypt_data != NULL) {
if (fil_space_crypt_t* crypt_data = space->crypt_data) {
mutex_enter(&crypt_data->mutex);
status->scheme = crypt_data->type;
status->keyserver_requests = crypt_data->keyserver_requests;
......
......@@ -1116,40 +1116,33 @@ fil_crypt_needs_rotation(
}
/** Read page 0 and possible crypt data from there.
@param[in] space Tablespace */
@param[in,out] space Tablespace */
static inline
void
fil_crypt_read_crypt_data(fil_space_t* space)
{
mutex_enter(&fil_system->mutex);
/* If space does not contain crypt data and space size is 0
we have not yet read first page of tablespace. We need to
read it to find out tablespace current encryption status. */
if (!space->crypt_data && space->size == 0) {
mtr_t mtr;
mtr_start(&mtr);
ulint zip_size = fsp_flags_get_zip_size(space->flags);
ulint offset = fsp_header_get_crypt_offset(zip_size);
mutex_exit(&fil_system->mutex);
if (buf_block_t* block = buf_page_get(space->id, zip_size, 0,
RW_X_LATCH, &mtr)) {
byte* frame = buf_block_get_frame(block);
mutex_enter(&fil_system->mutex);
if (!space->crypt_data) {
space->crypt_data = fil_space_read_crypt_data(space->id,
frame, offset);
}
if (space->crypt_data || space->size) {
/* The encryption metadata has already been read, or
the tablespace is not encrypted and the file has been
opened already. */
return;
}
mutex_exit(&fil_system->mutex);
mtr_t mtr;
mtr_start(&mtr);
ulint zip_size = fsp_flags_get_zip_size(space->flags);
ulint offset = fsp_header_get_crypt_offset(zip_size);
if (buf_block_t* block = buf_page_get(space->id, zip_size, 0,
RW_S_LATCH, &mtr)) {
mutex_enter(&fil_system->mutex);
if (!space->crypt_data) {
space->crypt_data = fil_space_read_crypt_data(
space->id, block->frame, offset);
}
mtr_commit(&mtr);
} else {
mutex_exit(&fil_system->mutex);
}
mtr_commit(&mtr);
}
/***********************************************************************
......@@ -1656,12 +1649,7 @@ fil_crypt_find_space_to_rotate(
}
while (!state->should_shutdown() && state->space) {
/* If there is no crypt data and we have not yet read
page 0 for this tablespace, we need to read it before
we can continue. */
if (!state->space->crypt_data) {
fil_crypt_read_crypt_data(state->space);
}
fil_crypt_read_crypt_data(state->space);
if (fil_crypt_space_needs_rotation(state, key_state, recheck)) {
ut_ad(key_state->key_id);
......@@ -2590,18 +2578,10 @@ fil_space_crypt_get_status(
memset(status, 0, sizeof(*status));
ut_ad(space->n_pending_ops > 0);
/* If there is no crypt data and we have not yet read
page 0 for this tablespace, we need to read it before
we can continue. */
if (!space->crypt_data) {
fil_crypt_read_crypt_data(const_cast<fil_space_t*>(space));
}
fil_space_crypt_t* crypt_data = space->crypt_data;
fil_crypt_read_crypt_data(const_cast<fil_space_t*>(space));
status->space = space->id;
if (crypt_data != NULL) {
if (fil_space_crypt_t* crypt_data = space->crypt_data) {
mutex_enter(&crypt_data->mutex);
status->scheme = crypt_data->type;
status->keyserver_requests = crypt_data->keyserver_requests;
......
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