From f5f79f01a2bd94b35ece9f0cf9ecd209888b457c Mon Sep 17 00:00:00 2001 From: Cheng Chang Date: Thu, 6 Feb 2020 10:14:19 -0800 Subject: [PATCH] Be able to read compatible leveldb sst files (#6370) Summary: In `DBSSTTest.SSTsWithLdbSuffixHandling`, some sst files are renamed to ldb files, the original intention of the test is to test that the ldb files can be loaded along with the sst files. The original test checks this by `ASSERT_NE("NOT_FOUND", Get(Key(k)))`, but the problem is `Get(Key(k))` returns IO error due to path not found instead of NOT_FOUND, so the success of ASSERT_NE does not mean the key can be retrieved. This PR updates the test to make sure Get(Key(k)) returns the original value. Pull Request resolved: https://github.com/facebook/rocksdb/pull/6370 Test Plan: make db_sst_test && ./db_sst_test Differential Revision: D19726278 Pulled By: cheng-chang fbshipit-source-id: 993127f56457b315e669af4eeb92d6f956b7a4b7 --- db/db_sst_test.cc | 10 +++++++++- db/table_cache.cc | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/db/db_sst_test.cc b/db/db_sst_test.cc index 478a6bdab..589a5915b 100644 --- a/db/db_sst_test.cc +++ b/db/db_sst_test.cc @@ -102,6 +102,14 @@ TEST_F(DBSSTTest, SSTsWithLdbSuffixHandling) { int const num_files = GetSstFileCount(dbname_); ASSERT_GT(num_files, 0); + Reopen(options); + std::vector values; + values.reserve(key_id); + for (int k = 0; k < key_id; ++k) { + values.push_back(Get(Key(k))); + } + Close(); + std::vector filenames; GetSstFiles(env_, dbname_, &filenames); int num_ldb_files = 0; @@ -119,7 +127,7 @@ TEST_F(DBSSTTest, SSTsWithLdbSuffixHandling) { Reopen(options); for (int k = 0; k < key_id; ++k) { - ASSERT_NE("NOT_FOUND", Get(Key(k))); + ASSERT_EQ(values[k], Get(Key(k))); } Destroy(options); } diff --git a/db/table_cache.cc b/db/table_cache.cc index 8a8a80ba3..12bd90230 100644 --- a/db/table_cache.cc +++ b/db/table_cache.cc @@ -100,8 +100,13 @@ Status TableCache::GetTableReader( std::unique_ptr file; Status s = ioptions_.fs->NewRandomAccessFile(fname, file_options, &file, nullptr); - RecordTick(ioptions_.statistics, NO_FILE_OPENS); + if (s.IsPathNotFound()) { + fname = Rocks2LevelTableFileName(fname); + s = ioptions_.fs->NewRandomAccessFile(fname, file_options, &file, nullptr); + RecordTick(ioptions_.statistics, NO_FILE_OPENS); + } + if (s.ok()) { if (!sequential_mode && ioptions_.advise_random_on_open) { file->Hint(FSRandomAccessFile::kRandom);