From ed7e4b68ed59fb7c34dc06625dfe378e71d1e8a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Tue, 19 Dec 2017 16:45:10 +0200 Subject: [PATCH] DEV-14701: install_db shows corruption for rest encryption with innodb_data_file_path=ibdata1:3M Problem was that crypt_data->min_key_version is not a reliable way to detect is tablespace encrypted and could lead that in first page of the second (page 192 and similarly for other files if more configured) system tablespace file used key_version is replaced with zero leading a corruption as in next startup page is though to be corrupted. Note that crypt_data->min_key_version is updated only after all pages from tablespace have been processed (i.e. key rotation is done) and flushed. fil_write_flushed_lsn Use crypt_data->should_encrypt() instead. --- storage/innobase/fil/fil0fil.cc | 4 +++- storage/xtradb/fil/fil0fil.cc | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index ac30f3c7a25..c9ecf3dab0b 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -2085,7 +2085,9 @@ fil_write_flushed_lsn( /* If tablespace is not encrypted, stamp flush_lsn to first page of all system tablespace datafiles to avoid unnecessary error messages on possible downgrade. */ - if (!space->crypt_data || space->crypt_data->min_key_version == 0) { + if (!space->crypt_data + || !space->crypt_data->should_encrypt()) { + fil_node_t* node; ulint sum_of_sizes = 0; diff --git a/storage/xtradb/fil/fil0fil.cc b/storage/xtradb/fil/fil0fil.cc index 00f2c44637e..9023b4446b5 100644 --- a/storage/xtradb/fil/fil0fil.cc +++ b/storage/xtradb/fil/fil0fil.cc @@ -2136,7 +2136,8 @@ fil_write_flushed_lsn( /* If tablespace is not encrypted, stamp flush_lsn to first page of all system tablespace datafiles to avoid unnecessary error messages on possible downgrade. */ - if (!space->crypt_data || space->crypt_data->min_key_version == 0) { + if (!space->crypt_data + || !space->crypt_data->should_encrypt()) { fil_node_t* node; ulint sum_of_sizes = 0;