Skip to content

Commit

Permalink
MDEV-9640: Add used key_id to INFORMATION_SCHEMA.INNODB_TABLESPACES_E…
Browse files Browse the repository at this point in the history
…NCRYPTION
  • Loading branch information
Jan Lindström committed Mar 18, 2016
1 parent 4aac51d commit ee768d8
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 16 deletions.
1 change: 1 addition & 0 deletions mysql-test/suite/encryption/r/innodb_encryption.result
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ MIN_KEY_VERSION int(11) unsigned NO 0
CURRENT_KEY_VERSION int(11) unsigned NO 0
KEY_ROTATION_PAGE_NUMBER bigint(21) unsigned YES NULL
KEY_ROTATION_MAX_PAGE_NUMBER bigint(21) unsigned YES NULL
CURRENT_KEY_ID int(11) unsigned NO 0
# Wait max 5 min for key encryption threads to encrypt one space
# Success!
# Wait max 10 min for key encryption threads to encrypt all space
Expand Down
14 changes: 14 additions & 0 deletions mysql-test/suite/encryption/r/innodb_encryption_is.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SET GLOBAL innodb_file_format = `Barracuda`;
SET GLOBAL innodb_file_per_table = ON;
CREATE TABLE t1 (c VARCHAR(8)) ENGINE=InnoDB ENCRYPTED=YES ENCRYPTION_KEY_ID=1;
CREATE TABLE t2 (c VARCHAR(8)) ENGINE=InnoDB ENCRYPTED=YES ENCRYPTION_KEY_ID=2;
INSERT INTO t1 VALUES ('foobar');
INSERT INTO t2 VALUES ('foobar');
SELECT NAME, ENCRYPTION_SCHEME, MIN_KEY_VERSION, CURRENT_KEY_VERSION,
CURRENT_KEY_ID
FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION
WHERE NAME LIKE '%t1' OR NAME LIKE '%t2';
NAME ENCRYPTION_SCHEME MIN_KEY_VERSION CURRENT_KEY_VERSION CURRENT_KEY_ID
test/t1 1 1 1 1
test/t2 1 1 1 2
DROP TABLE t1, t2;
1 change: 1 addition & 0 deletions mysql-test/suite/encryption/t/innodb_encryption_is.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--loose-innodb-tablespaces-encryption
31 changes: 31 additions & 0 deletions mysql-test/suite/encryption/t/innodb_encryption_is.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-- source include/have_innodb.inc
-- source include/have_file_key_management_plugin.inc

--disable_query_log
let $innodb_file_format_orig = `SELECT @@innodb_file_format`;
let $innodb_file_per_table_orig = `SELECT @@innodb_file_per_table`;
--enable_query_log

SET GLOBAL innodb_file_format = `Barracuda`;
SET GLOBAL innodb_file_per_table = ON;

CREATE TABLE t1 (c VARCHAR(8)) ENGINE=InnoDB ENCRYPTED=YES ENCRYPTION_KEY_ID=1;
CREATE TABLE t2 (c VARCHAR(8)) ENGINE=InnoDB ENCRYPTED=YES ENCRYPTION_KEY_ID=2;
INSERT INTO t1 VALUES ('foobar');
INSERT INTO t2 VALUES ('foobar');

#
# MDEV-9640: Add used key_id to INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION
#
SELECT NAME, ENCRYPTION_SCHEME, MIN_KEY_VERSION, CURRENT_KEY_VERSION,
CURRENT_KEY_ID
FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION
WHERE NAME LIKE '%t1' OR NAME LIKE '%t2';

DROP TABLE t1, t2;

# reset system
--disable_query_log
EVAL SET GLOBAL innodb_file_per_table = $innodb_file_per_table_orig;
EVAL SET GLOBAL innodb_file_format = $innodb_file_format_orig;
--enable_query_log
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ space_id page_id start_lsn end_lsn
Warnings:
Warning 1012 InnoDB: SELECTing from INFORMATION_SCHEMA.innodb_changed_pages but the InnoDB storage engine is not installed
select * from information_schema.innodb_tablespaces_encryption;
SPACE NAME ENCRYPTION_SCHEME KEYSERVER_REQUESTS MIN_KEY_VERSION CURRENT_KEY_VERSION KEY_ROTATION_PAGE_NUMBER KEY_ROTATION_MAX_PAGE_NUMBER
SPACE NAME ENCRYPTION_SCHEME KEYSERVER_REQUESTS MIN_KEY_VERSION CURRENT_KEY_VERSION KEY_ROTATION_PAGE_NUMBER KEY_ROTATION_MAX_PAGE_NUMBER CURRENT_KEY_ID
Warnings:
Warning 1012 InnoDB: SELECTing from INFORMATION_SCHEMA.innodb_tablespaces_encryption but the InnoDB storage engine is not installed
select * from information_schema.innodb_tablespaces_scrubbing;
Expand Down
3 changes: 2 additions & 1 deletion storage/innobase/fil/fil0crypt.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*****************************************************************************
Copyright (C) 2013, 2015, Google Inc. All Rights Reserved.
Copyright (C) 2014, 2015, MariaDB Corporation. All Rights Reserved.
Copyright (C) 2014, 2016, MariaDB Corporation. All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Expand Down Expand Up @@ -2522,6 +2522,7 @@ fil_space_crypt_get_status(
mutex_enter(&crypt_data->mutex);
status->keyserver_requests = crypt_data->keyserver_requests;
status->min_key_version = crypt_data->min_key_version;
status->key_id = crypt_data->key_id;

if (crypt_data->rotate_state.active_threads > 0 ||
crypt_data->rotate_state.flushing) {
Expand Down
13 changes: 12 additions & 1 deletion storage/innobase/handler/i_s.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 2007, 2015, Oracle and/or its affiliates.
Copyrigth (c) 2014, 2015, MariaDB Corporation
Copyrigth (c) 2014, 2016, MariaDB Corporation
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Expand Down Expand Up @@ -8134,6 +8134,15 @@ static ST_FIELD_INFO innodb_tablespaces_encryption_fields_info[] =
STRUCT_FLD(old_name, ""),
STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},

#define TABLESPACES_ENCRYPTION_CURRENT_KEY_ID 8
{STRUCT_FLD(field_name, "CURRENT_KEY_ID"),
STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
STRUCT_FLD(value, 0),
STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
STRUCT_FLD(old_name, ""),
STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},

END_OF_ST_FIELD_INFO
};

Expand Down Expand Up @@ -8172,6 +8181,8 @@ i_s_dict_fill_tablespaces_encryption(
status.min_key_version));
OK(fields[TABLESPACES_ENCRYPTION_CURRENT_KEY_VERSION]->store(
status.current_key_version));
OK(fields[TABLESPACES_ENCRYPTION_CURRENT_KEY_ID]->store(
status.key_id));
if (status.rotating) {
fields[TABLESPACES_ENCRYPTION_KEY_ROTATION_PAGE_NUMBER]->set_notnull();
OK(fields[TABLESPACES_ENCRYPTION_KEY_ROTATION_PAGE_NUMBER]->store(
Expand Down
1 change: 1 addition & 0 deletions storage/innobase/include/fil0crypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ struct fil_space_crypt_status_t {
uint min_key_version; /*!< min key version */
uint current_key_version;/*!< current key version */
uint keyserver_requests;/*!< no of key requests to key server */
ulint key_id; /*!< current key_id */
bool rotating; /*!< is key rotation ongoing */
bool flushing; /*!< is flush at end of rotation ongoing */
ulint rotate_next_page_number; /*!< next page if key rotating */
Expand Down
3 changes: 2 additions & 1 deletion storage/xtradb/fil/fil0crypt.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*****************************************************************************
Copyright (C) 2013, 2015, Google Inc. All Rights Reserved.
Copyright (C) 2014, 2015, MariaDB Corporation. All Rights Reserved.
Copyright (C) 2014, 2016, MariaDB Corporation. All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Expand Down Expand Up @@ -2522,6 +2522,7 @@ fil_space_crypt_get_status(
mutex_enter(&crypt_data->mutex);
status->keyserver_requests = crypt_data->keyserver_requests;
status->min_key_version = crypt_data->min_key_version;
status->key_id = crypt_data->key_id;

if (crypt_data->rotate_state.active_threads > 0 ||
crypt_data->rotate_state.flushing) {
Expand Down
21 changes: 10 additions & 11 deletions storage/xtradb/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/*****************************************************************************

Copyright (c) 2000, 2015, Oracle and/or its affiliates.
Copyright (c) 2013, 2015, MariaDB Corporation.
Copyright (c) 2013, 2016, MariaDB Corporation.
Copyright (c) 2008, 2009 Google Inc.
Copyright (c) 2009, Percona Inc.
Copyright (c) 2012, Facebook Inc.
Copyright (c) 2013, 2014 SkySQL Ab. All Rights Reserved.

Portions of this file contain modifications contributed and copyrighted by
Google, Inc. Those modifications are gratefully acknowledged and are described
Expand Down Expand Up @@ -8317,7 +8316,7 @@ ha_innobase::write_row(

if (share->ib_table != prebuilt->table) {
fprintf(stderr,
"InnoDB: Warning: share->ib_table %p prebuilt->table %p table %s is_corrupt %d.",
"InnoDB: Warning: share->ib_table %p prebuilt->table %p table %s is_corrupt %lu.",
share->ib_table, prebuilt->table, prebuilt->table->name, prebuilt->table->is_corrupt);
}

Expand Down Expand Up @@ -8670,7 +8669,7 @@ ha_innobase::write_row(

if (share->ib_table != prebuilt->table) {
fprintf(stderr,
"InnoDB: Warning: share->ib_table %p prebuilt->table %p table %s is_corrupt %d.",
"InnoDB: Warning: share->ib_table %p prebuilt->table %p table %s is_corrupt %lu.",
share->ib_table, prebuilt->table, prebuilt->table->name, prebuilt->table->is_corrupt);
}

Expand Down Expand Up @@ -9090,7 +9089,7 @@ ha_innobase::update_row(

if (share->ib_table != prebuilt->table) {
fprintf(stderr,
"InnoDB: Warning: share->ib_table %p prebuilt->table %p table %s is_corrupt %d.",
"InnoDB: Warning: share->ib_table %p prebuilt->table %p table %s is_corrupt %lu.",
share->ib_table, prebuilt->table, prebuilt->table->name, prebuilt->table->is_corrupt);
}

Expand Down Expand Up @@ -9211,7 +9210,7 @@ ha_innobase::update_row(

if (share->ib_table != prebuilt->table) {
fprintf(stderr,
"InnoDB: Warning: share->ib_table %p prebuilt->table %p table %s is_corrupt %d.",
"InnoDB: Warning: share->ib_table %p prebuilt->table %p table %s is_corrupt %lu.",
share->ib_table, prebuilt->table, prebuilt->table->name, prebuilt->table->is_corrupt);
}

Expand Down Expand Up @@ -12739,7 +12738,7 @@ ha_innobase::truncate()

if (share->ib_table != prebuilt->table) {
fprintf(stderr,
"InnoDB: Warning: share->ib_table %p prebuilt->table %p table %s is_corrupt %d.",
"InnoDB: Warning: share->ib_table %p prebuilt->table %p table %s is_corrupt %lu.",
share->ib_table, prebuilt->table, prebuilt->table->name, prebuilt->table->is_corrupt);
}

Expand All @@ -12760,7 +12759,7 @@ ha_innobase::truncate()

if (share->ib_table != prebuilt->table) {
fprintf(stderr,
"InnoDB: Warning: share->ib_table %p prebuilt->table %p table %s is_corrupt %d.",
"InnoDB: Warning: share->ib_table %p prebuilt->table %p table %s is_corrupt %lu.",
share->ib_table, prebuilt->table, prebuilt->table->name, prebuilt->table->is_corrupt);
}

Expand Down Expand Up @@ -14156,7 +14155,7 @@ ha_innobase::analyze(

if (share->ib_table != prebuilt->table) {
fprintf(stderr,
"InnoDB: Warning: share->ib_table %p prebuilt->table %p table %s is_corrupt %d.",
"InnoDB: Warning: share->ib_table %p prebuilt->table %p table %s is_corrupt %lu.",
share->ib_table, prebuilt->table, prebuilt->table->name, prebuilt->table->is_corrupt);
}

Expand All @@ -14172,7 +14171,7 @@ ha_innobase::analyze(

if (share->ib_table != prebuilt->table) {
fprintf(stderr,
"InnoDB: Warning: share->ib_table %p prebuilt->table %p table %s is_corrupt %d.",
"InnoDB: Warning: share->ib_table %p prebuilt->table %p table %s is_corrupt %lu.",
share->ib_table, prebuilt->table, prebuilt->table->name, prebuilt->table->is_corrupt);
}

Expand Down Expand Up @@ -15387,7 +15386,7 @@ ha_innobase::transactional_table_lock(

if (share->ib_table != prebuilt->table) {
fprintf(stderr,
"InnoDB: Warning: share->ib_table %p prebuilt->table %p table %s is_corrupt %d.",
"InnoDB: Warning: share->ib_table %p prebuilt->table %p table %s is_corrupt %lu.",
share->ib_table, prebuilt->table, prebuilt->table->name, prebuilt->table->is_corrupt);
}

Expand Down
13 changes: 12 additions & 1 deletion storage/xtradb/handler/i_s.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*****************************************************************************

Copyright (c) 2007, 2015, Oracle and/or its affiliates. All Rights Reserved.
Copyrigth (c) 2014, 2015, MariaDB Corporation
Copyrigth (c) 2014, 2016, MariaDB Corporation

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Expand Down Expand Up @@ -8468,6 +8468,15 @@ static ST_FIELD_INFO innodb_tablespaces_encryption_fields_info[] =
STRUCT_FLD(old_name, ""),
STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},

#define TABLESPACES_ENCRYPTION_CURRENT_KEY_ID 8
{STRUCT_FLD(field_name, "CURRENT_KEY_ID"),
STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
STRUCT_FLD(value, 0),
STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
STRUCT_FLD(old_name, ""),
STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},

END_OF_ST_FIELD_INFO
};

Expand Down Expand Up @@ -8506,6 +8515,8 @@ i_s_dict_fill_tablespaces_encryption(
status.min_key_version));
OK(fields[TABLESPACES_ENCRYPTION_CURRENT_KEY_VERSION]->store(
status.current_key_version));
OK(fields[TABLESPACES_ENCRYPTION_CURRENT_KEY_ID]->store(
status.key_id));
if (status.rotating) {
fields[TABLESPACES_ENCRYPTION_KEY_ROTATION_PAGE_NUMBER]->set_notnull();
OK(fields[TABLESPACES_ENCRYPTION_KEY_ROTATION_PAGE_NUMBER]->store(
Expand Down
1 change: 1 addition & 0 deletions storage/xtradb/include/fil0crypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ struct fil_space_crypt_status_t {
uint min_key_version; /*!< min key version */
uint current_key_version;/*!< current key version */
uint keyserver_requests;/*!< no of key requests to key server */
ulint key_id; /*!< current key_id */
bool rotating; /*!< is key rotation ongoing */
bool flushing; /*!< is flush at end of rotation ongoing */
ulint rotate_next_page_number; /*!< next page if key rotating */
Expand Down

0 comments on commit ee768d8

Please sign in to comment.