summaryrefslogtreecommitdiff
path: root/storage
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2017-06-12 17:10:56 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2017-06-12 17:10:56 +0300
commit3005cebc96ef65dc54bf6caaa5e089d52d52e7ff (patch)
tree9a070a2796f1d61d78ebfa41adef3d836bdb6be3 /storage
parent757339efd0894be2c486cfeb79f61182831a050f (diff)
downloadmariadb-git-3005cebc96ef65dc54bf6caaa5e089d52d52e7ff.tar.gz
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.
Diffstat (limited to 'storage')
-rw-r--r--storage/innobase/fil/fil0crypt.cc64
-rw-r--r--storage/xtradb/fil/fil0crypt.cc64
2 files changed, 44 insertions, 84 deletions
diff --git a/storage/innobase/fil/fil0crypt.cc b/storage/innobase/fil/fil0crypt.cc
index 70d8558ede2..df5c250df90 100644
--- a/storage/innobase/fil/fil0crypt.cc
+++ b/storage/innobase/fil/fil0crypt.cc
@@ -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;
diff --git a/storage/xtradb/fil/fil0crypt.cc b/storage/xtradb/fil/fil0crypt.cc
index e24278dd102..6d3c2e98010 100644
--- a/storage/xtradb/fil/fil0crypt.cc
+++ b/storage/xtradb/fil/fil0crypt.cc
@@ -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;