Commit 7e7592ad authored by Sergei Petrunia's avatar Sergei Petrunia

MDEV-16154: Server crashes in in myrocks::ha_rocksdb::load_auto_incr_value_from_index

Backport the fix from the upstream and add our testcase.
Backported cset:
commit 997a979bf5e2f75ab88781d9d3fd22dddc1fc21f
Author: Manuel Ung <mung@fb.com>
Date:   Thu Feb 15 08:38:12 2018 -0800

    Fix crashes in autoincrement code paths

    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

    fbshipit-source-id: 1130ce1
parent 6c0f3dd3
......@@ -5088,6 +5088,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();
}
......@@ -11734,8 +11740,10 @@ bool ha_rocksdb::prepare_inplace_alter_table(
if (!new_tdef) {
new_tdef = m_tbl_def;
}
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(
new_tdef, old_key_descr, new_key_descr, old_n_keys, new_n_keys,
......
......@@ -140,3 +140,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;
......@@ -89,3 +89,10 @@ CREATE TABLE t1 (i INT) ENGINE=RocksDB;
FLUSH TABLE t1 FOR EXPORT;
ERROR HY000: Storage engine ROCKSDB of the table `test`.`t1` doesn't have this option
DROP TABLE t1;
#
# MDEV-16154 Server crashes in in myrocks::ha_rocksdb::load_auto_incr_value_from_inde
#
CREATE TABLE t1 (a INT) ENGINE=RocksDB;
INSERT INTO t1 VALUES (1);
ALTER TABLE t1 AUTO_INCREMENT 10;
DROP TABLE t1;
......@@ -103,3 +103,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;
......@@ -83,3 +83,12 @@ CREATE TABLE t1 (i INT) ENGINE=RocksDB;
FLUSH TABLE t1 FOR EXPORT;
DROP TABLE t1;
--echo #
--echo # MDEV-16154 Server crashes in in myrocks::ha_rocksdb::load_auto_incr_value_from_inde
--echo #
CREATE TABLE t1 (a INT) ENGINE=RocksDB;
INSERT INTO t1 VALUES (1);
ALTER TABLE t1 AUTO_INCREMENT 10;
DROP TABLE t1;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment