From c573b5dc5f468b77b2db2b5d65a47e8d59a32af8 Mon Sep 17 00:00:00 2001 From: Manuel Ung Date: Thu, 15 Feb 2018 08:38:12 -0800 Subject: [PATCH] Fix crashes in autoincrement code paths (#794) (#794) Summary: There are two issues related to autoincrement that can lead to crashes: 1. The max value for double/float type for autoincrement was not implemented in MyRocks, and can lead to assertions. The fix is to add them in. 2. If we try to set auto_increment via alter table on a table without an auto_increment column defined, we segfault because there is no index from which to read the last value. The fix is to perform a check to see if autoincrement exists before reading from index (similar to code ha_rocksdb::open). Fixes https://github.com/facebook/mysql-5.6/issues/792 Closes https://github.com/facebook/mysql-5.6/pull/794 Differential Revision: D6995096 Pulled By: lth --- mysql-test/suite/rocksdb/r/autoinc_vars.result | 10 ++++++++++ mysql-test/suite/rocksdb/t/autoinc_vars.test | 13 +++++++++++++ storage/rocksdb/ha_rocksdb.cc | 10 +++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/rocksdb/r/autoinc_vars.result b/mysql-test/suite/rocksdb/r/autoinc_vars.result index 848d362f9e11..fe8533a3d995 100644 --- a/mysql-test/suite/rocksdb/r/autoinc_vars.result +++ b/mysql-test/suite/rocksdb/r/autoinc_vars.result @@ -141,3 +141,13 @@ SELECT * FROM t1; a b 18446744073709551613 a DROP TABLE t1; +#---------------------------------- +# Issue #792 Crash in autoincrement +#---------------------------------- +CREATE TABLE t1(C1 DOUBLE AUTO_INCREMENT KEY,C2 CHAR) ENGINE=ROCKSDB; +INSERT INTO t1 VALUES(2177,0); +DROP TABLE t1; +CREATE TABLE t0(c0 BLOB) ENGINE=ROCKSDB; +INSERT INTO t0 VALUES(0); +ALTER TABLE t0 AUTO_INCREMENT=0; +DROP TABLE t0; diff --git a/mysql-test/suite/rocksdb/t/autoinc_vars.test b/mysql-test/suite/rocksdb/t/autoinc_vars.test index e8f343bd876e..5de6de404325 100644 --- a/mysql-test/suite/rocksdb/t/autoinc_vars.test +++ b/mysql-test/suite/rocksdb/t/autoinc_vars.test @@ -101,3 +101,16 @@ SHOW CREATE TABLE t1; INSERT INTO t1 VALUES (NULL, 'c'); SELECT * FROM t1; DROP TABLE t1; + +--echo #---------------------------------- +--echo # Issue #792 Crash in autoincrement +--echo #---------------------------------- + +CREATE TABLE t1(C1 DOUBLE AUTO_INCREMENT KEY,C2 CHAR) ENGINE=ROCKSDB; +INSERT INTO t1 VALUES(2177,0); +DROP TABLE t1; + +CREATE TABLE t0(c0 BLOB) ENGINE=ROCKSDB; +INSERT INTO t0 VALUES(0); +ALTER TABLE t0 AUTO_INCREMENT=0; +DROP TABLE t0; diff --git a/storage/rocksdb/ha_rocksdb.cc b/storage/rocksdb/ha_rocksdb.cc index 14ee3c662c98..5f9058ef71d6 100644 --- a/storage/rocksdb/ha_rocksdb.cc +++ b/storage/rocksdb/ha_rocksdb.cc @@ -4730,6 +4730,12 @@ static ulonglong rdb_get_int_col_max_value(const Field *field) { case HA_KEYTYPE_LONGLONG: max_value = 0x7FFFFFFFFFFFFFFFULL; break; + case HA_KEYTYPE_FLOAT: + max_value = 0x1000000ULL; + break; + case HA_KEYTYPE_DOUBLE: + max_value = 0x20000000000000ULL; + break; default: abort(); } @@ -11205,7 +11211,9 @@ bool ha_rocksdb::prepare_inplace_alter_table( if (!new_tdef) { new_tdef = m_tbl_def; } - max_auto_incr = load_auto_incr_value_from_index(); + if (table->found_next_number_field) { + max_auto_incr = load_auto_incr_value_from_index(); + } } ha_alter_info->handler_ctx = new Rdb_inplace_alter_ctx(