diff --git a/mysql-test/suite/encryption/r/innodb-encr-threads.result b/mysql-test/suite/encryption/r/innodb-encr-threads.result index 0178635afb766..162d50cff2f41 100644 --- a/mysql-test/suite/encryption/r/innodb-encr-threads.result +++ b/mysql-test/suite/encryption/r/innodb-encr-threads.result @@ -5,3 +5,34 @@ insert t1 values (1); drop table t1; set global innodb_encryption_threads = 0; set global innodb_encryption_rotate_key_age = 1; +# +# MDEV-41055 innodb_encryption_threads=0 hangs indefinitely +# when rotation IOPS is zero +# +connect con1,localhost,root,,,,,; +connection default; +SET @old_encrypt_tables= @@GLOBAL.innodb_encrypt_tables; +SET @old_threads= @@GLOBAL.innodb_encryption_threads; +SET @old_iops= @@GLOBAL.innodb_encryption_rotation_iops; +SET GLOBAL innodb_encryption_threads= 0; +SET GLOBAL innodb_encrypt_tables= OFF; +CREATE TABLE t1 (a INT) ENGINE=InnoDB; +SET GLOBAL innodb_encryption_rotation_iops= 0; +SET GLOBAL innodb_encryption_threads= 1; +SET GLOBAL innodb_encrypt_tables= ON; +SELECT COUNT(*) AS rotating +FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION +WHERE ROTATING_OR_FLUSHING <> 0; +rotating +0 +connection con1; +SET GLOBAL innodb_encryption_threads= 0; +connection default; +SELECT @@GLOBAL.innodb_encryption_threads; +@@GLOBAL.innodb_encryption_threads +0 +disconnect con1; +DROP TABLE t1; +SET GLOBAL innodb_encryption_rotation_iops= @old_iops; +SET GLOBAL innodb_encrypt_tables= @old_encrypt_tables; +SET GLOBAL innodb_encryption_threads= @old_threads; diff --git a/mysql-test/suite/encryption/t/innodb-encr-threads.opt b/mysql-test/suite/encryption/t/innodb-encr-threads.opt new file mode 100644 index 0000000000000..557daf9b0b902 --- /dev/null +++ b/mysql-test/suite/encryption/t/innodb-encr-threads.opt @@ -0,0 +1 @@ +--innodb_tablespaces_encryption diff --git a/mysql-test/suite/encryption/t/innodb-encr-threads.test b/mysql-test/suite/encryption/t/innodb-encr-threads.test index 1a90a31870bc2..5039a5985fc08 100644 --- a/mysql-test/suite/encryption/t/innodb-encr-threads.test +++ b/mysql-test/suite/encryption/t/innodb-encr-threads.test @@ -12,3 +12,43 @@ drop table t1; set global innodb_encryption_threads = 0; set global innodb_encryption_rotate_key_age = 1; +--echo # +--echo # MDEV-41055 innodb_encryption_threads=0 hangs indefinitely +--echo # when rotation IOPS is zero +--echo # +--connect (con1,localhost,root,,,,,) +--connection default + +SET @old_encrypt_tables= @@GLOBAL.innodb_encrypt_tables; +SET @old_threads= @@GLOBAL.innodb_encryption_threads; +SET @old_iops= @@GLOBAL.innodb_encryption_rotation_iops; + +SET GLOBAL innodb_encryption_threads= 0; +SET GLOBAL innodb_encrypt_tables= OFF; + +CREATE TABLE t1 (a INT) ENGINE=InnoDB; + +SET GLOBAL innodb_encryption_rotation_iops= 0; +SET GLOBAL innodb_encryption_threads= 1; +SET GLOBAL innodb_encrypt_tables= ON; + +let $wait_condition= + SELECT COUNT(*) > 0 FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION + WHERE ENCRYPTION_SCHEME = 1 AND MIN_KEY_VERSION = 0; +--source include/wait_condition.inc + +SELECT COUNT(*) AS rotating + FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION + WHERE ROTATING_OR_FLUSHING <> 0; + +--connection con1 +SET GLOBAL innodb_encryption_threads= 0; + +--connection default +SELECT @@GLOBAL.innodb_encryption_threads; +--disconnect con1 + +DROP TABLE t1; +SET GLOBAL innodb_encryption_rotation_iops= @old_iops; +SET GLOBAL innodb_encrypt_tables= @old_encrypt_tables; +SET GLOBAL innodb_encryption_threads= @old_threads; diff --git a/storage/innobase/fil/fil0crypt.cc b/storage/innobase/fil/fil0crypt.cc index 881587d1f20e8..9d69c21c4f93b 100644 --- a/storage/innobase/fil/fil0crypt.cc +++ b/storage/innobase/fil/fil0crypt.cc @@ -2363,6 +2363,9 @@ void fil_crypt_set_thread_cnt(const uint new_cnt) } pthread_cond_broadcast(&fil_crypt_threads_cond); + /* Thread waiting on fil_crypt_iops_cond too. They must + be woken as well */ + pthread_cond_broadcast(&fil_crypt_iops_cond); while (srv_n_fil_crypt_threads_started != srv_n_fil_crypt_threads) { my_cond_wait(&fil_crypt_cond,