Skip to content

Commit

Permalink
Fix crashes in autoincrement code paths (facebook#794) (facebook#794)
Browse files Browse the repository at this point in the history
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#792
Closes facebook#794

Differential Revision: D6995096

Pulled By: lth
  • Loading branch information
lth authored and inikep committed May 23, 2022
1 parent c7bd670 commit 1536632
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 @@ -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;
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 @@ -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;
10 changes: 9 additions & 1 deletion storage/rocksdb/ha_rocksdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 1536632

Please sign in to comment.