summaryrefslogtreecommitdiff
path: root/storage/innobase/fil
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2017-06-12 17:43:07 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2017-06-12 17:43:07 +0300
commita78476d342969caece14ee4fc3f5ac4a58b0721a (patch)
treecb36c20c39a372911c5b7a4d0c63275f751733d5 /storage/innobase/fil
parent7a12894de11ab04b93c9e96359008386b3b41cbb (diff)
parent3976ec1e83d7ae1079b4afa4c12b4ec533d665f6 (diff)
downloadmariadb-git-a78476d342969caece14ee4fc3f5ac4a58b0721a.tar.gz
Merge 10.1 into 10.2
Diffstat (limited to 'storage/innobase/fil')
-rw-r--r--storage/innobase/fil/fil0crypt.cc50
-rw-r--r--storage/innobase/fil/fil0fil.cc26
2 files changed, 54 insertions, 22 deletions
diff --git a/storage/innobase/fil/fil0crypt.cc b/storage/innobase/fil/fil0crypt.cc
index 5cfacc5bcd8..7917cbb528b 100644
--- a/storage/innobase/fil/fil0crypt.cc
+++ b/storage/innobase/fil/fil0crypt.cc
@@ -922,6 +922,34 @@ fil_crypt_needs_rotation(
return false;
}
+/** Read page 0 and possible crypt data from there.
+@param[in,out] space Tablespace */
+static inline
+void
+fil_crypt_read_crypt_data(fil_space_t* space)
+{
+ 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;
+ }
+
+ const page_size_t page_size(space->flags);
+ mtr_t mtr;
+ mtr.start();
+ if (buf_block_t* block = buf_page_get(page_id_t(space->id, 0),
+ page_size, RW_S_LATCH, &mtr)) {
+ mutex_enter(&fil_system->mutex);
+ if (!space->crypt_data) {
+ space->crypt_data = fil_space_read_crypt_data(
+ page_size, block->frame);
+ }
+ mutex_exit(&fil_system->mutex);
+ }
+ mtr.commit();
+}
+
/***********************************************************************
Start encrypting a space
@param[in,out] space Tablespace
@@ -932,6 +960,7 @@ fil_crypt_start_encrypting_space(
fil_space_t* space)
{
bool recheck = false;
+
mutex_enter(&fil_crypt_threads_mutex);
fil_space_crypt_t *crypt_data = space->crypt_data;
@@ -1428,6 +1457,13 @@ 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);
+ }
+
if (fil_crypt_space_needs_rotation(state, key_state, recheck)) {
ut_ad(key_state->key_id);
/* init state->min_key_version_found before
@@ -2129,8 +2165,10 @@ DECLARE_THREAD(fil_crypt_thread)(
while (!thr.should_shutdown() &&
fil_crypt_find_page_to_rotate(&new_state, &thr)) {
- /* rotate a (set) of pages */
- fil_crypt_rotate_pages(&new_state, &thr);
+ if (!thr.space->is_stopping()) {
+ /* rotate a (set) of pages */
+ fil_crypt_rotate_pages(&new_state, &thr);
+ }
/* If space is marked as stopping, release
space and stop rotation. */
@@ -2357,6 +2395,14 @@ 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;
status->space = space->id;
diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc
index 72358e7628b..2cbc863102c 100644
--- a/storage/innobase/fil/fil0fil.cc
+++ b/storage/innobase/fil/fil0fil.cc
@@ -655,12 +655,8 @@ retry:
FSP_HEADER_OFFSET + FSP_FREE + page);
/* Try to read crypt_data from page 0 if it is not yet
- read. FIXME: Remove page_0_crypt_read, and simply ensure in
- fil_space_t object creation that node->size==0 if and only
- if the crypt_data is not known and must be read. */
- if (!space->page_0_crypt_read) {
- space->page_0_crypt_read = true;
- ut_ad(space->crypt_data == NULL);
+ read. */
+ if (!space->crypt_data) {
space->crypt_data = fil_space_read_crypt_data(
page_size_t(space->flags), page);
}
@@ -1591,7 +1587,6 @@ Error messages are issued to the server log.
@param[in] flags tablespace flags
@param[in] purpose tablespace purpose
@param[in,out] crypt_data encryption information
-@param[in] create_table whether this is CREATE TABLE
@param[in] mode encryption mode
@return pointer to created tablespace, to be filled in with fil_node_create()
@retval NULL on failure (such as when the same tablespace exists) */
@@ -1602,7 +1597,6 @@ fil_space_create(
ulint flags,
fil_type_t purpose,
fil_space_crypt_t* crypt_data,
- bool create_table,
fil_encryption_t mode)
{
fil_space_t* space;
@@ -1667,16 +1661,8 @@ fil_space_create(
space->magic_n = FIL_SPACE_MAGIC_N;
space->crypt_data = crypt_data;
- /* In create table we write page 0 so we have already
- "read" it and for system tablespaces we have read
- crypt data at startup. */
- if (create_table || crypt_data != NULL) {
- space->page_0_crypt_read = true;
- }
-
DBUG_LOG("tablespace",
- "Tablespace for space " << id << " name " << name
- << (create_table ? " created" : " opened"));
+ "Created metadata for " << id << " name " << name);
if (crypt_data) {
DBUG_LOG("crypt",
"Tablespace " << id << " name " << name
@@ -4004,7 +3990,7 @@ fil_ibd_create(
}
space = fil_space_create(name, space_id, flags, FIL_TYPE_TABLESPACE,
- crypt_data, true, mode);
+ crypt_data, mode);
fil_node_t* node = NULL;
@@ -4372,7 +4358,7 @@ skip_validate:
space_name, id, flags, purpose,
df_remote.is_open() ? df_remote.get_crypt_info() :
df_dict.is_open() ? df_dict.get_crypt_info() :
- df_default.get_crypt_info(), false);
+ df_default.get_crypt_info());
/* We do not measure the size of the file, that is why
we pass the 0 below */
@@ -4692,7 +4678,7 @@ fil_ibd_load(
space = fil_space_create(
file.name(), space_id, flags, FIL_TYPE_TABLESPACE,
- file.get_crypt_info(), false);
+ file.get_crypt_info());
if (space == NULL) {
return(FIL_LOAD_INVALID);