Skip to content

Commit d32eb09

Browse files
Luis Donosofacebook-github-bot
authored andcommitted
MyRocks crash when inserting into table with unique key and TTL (#1192)
Summary: **Problem:** This execution: ``` CREATE TABLE t1 ( `id` int NOT NULL AUTO_INCREMENT, `username` varchar(64) NOT NULL, `date` date NOT NULL, `hour` tinyint unsigned NOT NULL, `ipv4` varchar(15) NOT NULL, `ipv6` varchar(39) NOT NULL, `acctinputoctets` bigint DEFAULT NULL, `acctoutputoctets` bigint DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `username_day_hour` (`username`,`date`,`hour`) ) ENGINE=ROCKSDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1 COMMENT='ttl_duration=604800;'; INSERT INTO t1 (`username`, `date`, `hour`, `ipv4`, `ipv6`, `acctinputoctets`, `acctoutputoctets`) VALUES ('100002992184', '2022-06-08', '10', '192.168.1.70', '', '1', '2'); ``` causes the following crash: ``` 13:12:26 UTC - mysqld got signal 11 ; Most likely, you have hit a bug, but this error can also be caused by malfunctioning hardware. Thread pointer: 0x7fb21ec0b7c0 Attempting backtrace. You can use the following information to find out where mysqld died. If you see no messages after this, something went terribly wrong... stack_bottom = 7fb24fb67f08 thread_stack 0x46000 /home/ldonoso/src/fb-mysql-bld/runtime_output_directory/mysqld(my_print_stacktrace(unsigned char const*, unsigned long)+0x42) [0x726eaa2] /home/ldonoso/src/fb-mysql-bld/runtime_output_directory/mysqld(handle_fatal_signal+0x232) [0x5fa7132] /lib/x86_64-linux-gnu/libpthread.so.0(+0x14420) [0x7fb25ead0420] /home/ldonoso/src/fb-mysql-bld/runtime_output_directory/mysqld(rocksdb::Slice::data() const+0xc) [0x7c4fa7c] /home/ldonoso/src/fb-mysql-bld/runtime_output_directory/mysqld(myrocks::Rdb_string_reader::Rdb_string_reader(rocksdb::Slice const*)+0x21) [0x7c4f4f1] /home/ldonoso/src/fb-mysql-bld/runtime_output_directory/mysqld(myrocks::rdb_should_hide_ttl_rec(myrocks::Rdb_key_def const&, rocksdb::Slice const&, myrocks::Rdb_transaction*)+0x101) [0x7c0d6f1] /home/ldonoso/src/fb-mysql-bld/runtime_output_directory/mysqld(myrocks::Rdb_iterator_base::get(rocksdb::Slice const*, rocksdb::PinnableSlice*, myrocks::Rdb_lock_type, bool, bool)+0x32b) [0x83e4ffb] /home/ldonoso/src/fb-mysql-bld/runtime_output_directory/mysqld(myrocks::ha_rocksdb::check_and_lock_sk(unsigned int, myrocks::ha_rocksdb::update_row_info const&, bool*, bool)+0x61a) [0x7c1ac7a] /home/ldonoso/src/fb-mysql-bld/runtime_output_directory/mysqld(myrocks::ha_rocksdb::check_uniqueness_and_lock(myrocks::ha_rocksdb::update_row_info const&, bool, bool)+0x190) [0x7c1b140] /home/ldonoso/src/fb-mysql-bld/runtime_output_directory/mysqld(myrocks::ha_rocksdb::update_write_row(unsigned char const*, unsigned char const*, bool)+0x271) [0x7c19941] /home/ldonoso/src/fb-mysql-bld/runtime_output_directory/mysqld(myrocks::ha_rocksdb::write_row(unsigned char*)+0x2e5) [0x7c195d5] ``` **Solution**: If `all_parts_used` is `false` we can skip the check of the ttl of the row. It is not a problem if the record is stale since, next, `iter.seek` is called and `iter.seek` checks the TTL. Pull Request resolved: #1192 Reviewed By: Pushapgl Differential Revision: D37142201 Pulled By: hermanlee fbshipit-source-id: 66792d75db4d4d8f9f236d3faab593cf13c02e36
1 parent ec8d307 commit d32eb09

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
CREATE TABLE t1 (
2+
`id` int NOT NULL AUTO_INCREMENT,
3+
`username` varchar(64) NOT NULL,
4+
`date` date NOT NULL,
5+
`hour` tinyint unsigned NOT NULL,
6+
`ipv4` varchar(15) NOT NULL,
7+
`ipv6` varchar(39) NOT NULL,
8+
`acctinputoctets` bigint DEFAULT NULL,
9+
`acctoutputoctets` bigint DEFAULT NULL,
10+
PRIMARY KEY (`id`),
11+
UNIQUE KEY `username_day_hour` (`username`,`date`,`hour`)
12+
) ENGINE=ROCKSDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1 COMMENT='ttl_duration=604800;';
13+
INSERT INTO t1 (`username`, `date`, `hour`, `ipv4`, `ipv6`, `acctinputoctets`, `acctoutputoctets`)
14+
VALUES ('100002992184', '2022-06-08', '10', '192.168.1.70', '', '1', '2');
15+
SELECT * from t1;
16+
id username date hour ipv4 ipv6 acctinputoctets acctoutputoctets
17+
1 100002992184 2022-06-08 10 192.168.1.70 1 2
18+
drop table t1;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--source include/have_rocksdb.inc
2+
3+
CREATE TABLE t1 (
4+
`id` int NOT NULL AUTO_INCREMENT,
5+
`username` varchar(64) NOT NULL,
6+
`date` date NOT NULL,
7+
`hour` tinyint unsigned NOT NULL,
8+
`ipv4` varchar(15) NOT NULL,
9+
`ipv6` varchar(39) NOT NULL,
10+
`acctinputoctets` bigint DEFAULT NULL,
11+
`acctoutputoctets` bigint DEFAULT NULL,
12+
PRIMARY KEY (`id`),
13+
UNIQUE KEY `username_day_hour` (`username`,`date`,`hour`)
14+
) ENGINE=ROCKSDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1 COMMENT='ttl_duration=604800;';
15+
16+
INSERT INTO t1 (`username`, `date`, `hour`, `ipv4`, `ipv6`, `acctinputoctets`, `acctoutputoctets`)
17+
VALUES ('100002992184', '2022-06-08', '10', '192.168.1.70', '', '1', '2');
18+
19+
SELECT * from t1;
20+
21+
drop table t1;

storage/rocksdb/ha_rocksdb.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10856,8 +10856,9 @@ int ha_rocksdb::check_and_lock_sk(
1085610856
guarantee SK uniqueness. We could optimize this by calling non-locking
1085710857
get instead.
1085810858
*/
10859+
bool skip_ttl_check = !all_parts_used;
1085910860
rc = iter.get(&new_slice, all_parts_used ? &m_retrieved_record : nullptr,
10860-
m_lock_rows);
10861+
m_lock_rows, skip_ttl_check);
1086110862
if (rc && rc != HA_ERR_KEY_NOT_FOUND) {
1086210863
return rc;
1086310864
}

0 commit comments

Comments
 (0)