From 1fe66b52adf6ed17deef351ecf204999344e22a8 Mon Sep 17 00:00:00 2001 From: Herman Lee Date: Wed, 28 Jan 2015 16:13:11 -0800 Subject: [PATCH] Fix server restart failure with binary log enabled Summary: During startup, the data dictionary scans through a set of keys to find the table names. These keys use the index prefix, which is 4 bytes. The scanner knows it has hit the end of the list when the key it is examining no longer matches the index prefix. However, the scanner first verifies the length of the key is larger than the index prefix before determining if the key is a data dictionary key. If this key is not a data dictionary, but is 4 bytes (like the binlog key), then it returns a failure and stops initialization. Fix is to determine if the key has the index prefix before failing it for invalid length. Test Plan: running unit tests and added a new test Reviewers: spetrunia, maykov, jonahcohen, yoshinorim Reviewed By: yoshinorim Differential Revision: https://reviews.facebook.net/D32481 --- storage/rocksdb/rdb_datadic.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/storage/rocksdb/rdb_datadic.cc b/storage/rocksdb/rdb_datadic.cc index 1e5b2157a870..0b20bfa555d8 100644 --- a/storage/rocksdb/rdb_datadic.cc +++ b/storage/rocksdb/rdb_datadic.cc @@ -938,6 +938,10 @@ bool Table_ddl_manager::init(rocksdb::DB *rdb_dict) rocksdb::Slice key= it->key(); rocksdb::Slice val= it->value(); + if (key.size() >= RDBSE_KEYDEF::INDEX_NUMBER_SIZE && + memcmp(key.data(), ddl_entry, RDBSE_KEYDEF::INDEX_NUMBER_SIZE)) + break; + if (key.size() <= RDBSE_KEYDEF::INDEX_NUMBER_SIZE) { sql_print_error("RocksDB: Table_store: key has length %d (corruption?)", @@ -945,9 +949,6 @@ bool Table_ddl_manager::init(rocksdb::DB *rdb_dict) return true; } - if (memcmp(key.data(), ddl_entry, RDBSE_KEYDEF::INDEX_NUMBER_SIZE)) - break; - RDBSE_TABLE_DEF *tdef= new RDBSE_TABLE_DEF; tdef->dbname_tablename.append(key.data() + RDBSE_KEYDEF::INDEX_NUMBER_SIZE, key.size() - RDBSE_KEYDEF::INDEX_NUMBER_SIZE);