Skip to content

Commit

Permalink
Fix crashes in autoincrement code paths
Browse files Browse the repository at this point in the history
Upstream commit ID : fb-mysql-5.6.35/997a979bf5e2f75ab88781d9d3fd22dddc1fc21f
Cherry picked directly.

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 facebook/mysql-5.6#792
Closes facebook/mysql-5.6#794

Differential Revision: D6995096

Pulled By: lth

fbshipit-source-id: 1130ce1
  • Loading branch information
lth authored and George O. Lorch III committed Feb 15, 2018
1 parent 72f27f4 commit 46b2222
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
10 changes: 10 additions & 0 deletions mysql-test/suite/rocksdb/r/autoinc_vars.result
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,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;
13 changes: 13 additions & 0 deletions mysql-test/suite/rocksdb/t/autoinc_vars.test
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,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;
10 changes: 9 additions & 1 deletion storage/rocksdb/ha_rocksdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4385,6 +4385,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_with_stack_traces();
}
Expand Down Expand Up @@ -10791,7 +10797,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(
Expand Down

0 comments on commit 46b2222

Please sign in to comment.