Bug #98537 inplace encryption resume thread doesn't update DD properly
Submitted: 10 Feb 2020 13:56 Modified: 16 Nov 2020 17:46
Reporter: Satya Bodapati (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S2 (Serious)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any
Tags: alter tablespace, encryption, innodb

[10 Feb 2020 13:56] Satya Bodapati
Description:
Kill the server when ALTER TABLESPACE ENCRYPTION='Y'/'N' in progress.
Next startup doesn't update 'encrypt_type' in dd::Table::options.

Correct State:
--------------
REATE TABLESPACE encrypt_ts_2 ADD DATAFILE 'encrypt_ts_2.ibd' ENGINE=InnoDB ENCRYPTION="N";
CREATE TABLE t3(c1 char(100)) ENGINE=InnoDB TABLESPACE encrypt_ts_2;
CREATE TABLE t4(c1 char(100)) ENGINE=InnoDB TABLESPACE encrypt_ts_2;
# encrypt_type is correctly set as 'Y' when it doesn't crash
ALTER TABLESPACE encrypt_ts_2 ENCRYPTION='Y';
SELECT name,options FROM mysql.tables WHERE NAME='t3';;
name	t3
options	avg_row_length=0;encrypt_type=Y;explicit_tablespace=1;key_block_size=0;keys_disabled=0;pack_record=0;stats_auto_recalc=0;stats_sample_pages=0;
SELECT name,options FROM mysql.tables WHERE NAME='t4';;
name	t4
options	avg_row_length=0;encrypt_type=Y;explicit_tablespace=1;key_block_size=0;keys_disabled=0;pack_record=0;stats_auto_recalc=0;stats_sample_pages=0;
SELECT name,options FROM mysql.tablespaces WHERE NAME='encrypt_ts_2';;
name	encrypt_ts_2
options	encryption=Y;

Observe that "encrypt_type=Y" is set for both table options and in tablespace options as well

Incorrect State (after crash recovery):
----------------------------------------

ELECT name,options FROM mysql.tables WHERE NAME='t1';;
name	t1
options	avg_row_length=0;encrypt_type=N;explicit_tablespace=1;key_block_size=0;keys_disabled=0;pack_record=0;stats_auto_recalc=0;stats_sample_pages=0;
SELECT name,options FROM mysql.tables WHERE NAME='t2';;
name	t2
options	avg_row_length=0;encrypt_type=N;explicit_tablespace=1;key_block_size=0;keys_disabled=0;pack_record=0;stats_auto_recalc=0;stats_sample_pages=0;
SELECT name,options FROM mysql.tablespaces WHERE NAME='encrypt_ts';;
name	encrypt_ts
options	encryption=Y;

Observe that 'encrypt_type' is still 'N' even though the tablespace encrypted.

How to repeat:
See mtr testcase
[10 Feb 2020 13:58] Satya Bodapati
mtr testcase

Attachment: tablespace_encrypt_2_dd.test (application/octet-stream, text), 4.10 KiB.

[10 Feb 2020 14:02] Satya Bodapati
This looks even serious when compared to bug#98530
[11 Feb 2020 13:05] MySQL Verification Team
Hi Satya,

Thank you for your bug report.

It looks both interesting and serious. I have  tested it and repeated the behaviour.

Verified as reported.

Thank you for your contribution.
[16 Nov 2020 17:46] Daniel Price
Posted by developer:
 
Fixed as of the upcoming 8.0.23 release, and here's the proposed changelog entry from the documentation team:

The tablespace encryption type setting was not properly updated due to a
failure during the resumption of an ALTER TABLESPACE ENCRYPTION operation
following a server failure.
[17 Nov 2020 12:09] MySQL Verification Team
Thank you, Daniel and Satya .......
[27 Jan 2022 4:08] MySQL Verification Team
Bug #101011 is marked as duplicate of this one
[27 Jan 2022 13:55] MySQL Verification Team
Thank you, Umesh.