summaryrefslogtreecommitdiff
path: root/table
diff options
context:
space:
mode:
authormrambacher <mrambach@gmail.com>2020-12-23 16:54:05 -0800
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>2020-12-23 16:55:53 -0800
commit55e99688ccb24f62650764ed5190d38ff38981d7 (patch)
treeac1614bdfb14a6d1d655cdc6eda6eec872492608 /table
parent30a5ed9c53c4684d7853ba836aee3a51a00e407d (diff)
No elide constructors (#7798)
Summary: Added "no-elide-constructors to the ASSERT_STATUS_CHECK builds. This flag gives more errors/warnings for some of the Status checks where an inner class checks a Status and later returns it. In this case, without the elide check on, the returned status may not have been checked in the caller, thereby bypassing the checked code. Pull Request resolved: https://github.com/facebook/rocksdb/pull/7798 Reviewed By: jay-zhuang Differential Revision: D25680451 Pulled By: pdillinger fbshipit-source-id: c3f14ed9e2a13f0a8c54d839d5fb4d1fc1e93917
Diffstat (limited to 'table')
-rw-r--r--table/mock_table.cc37
-rw-r--r--table/mock_table.h4
-rw-r--r--table/sst_file_dumper.cc6
-rw-r--r--table/table_test.cc30
4 files changed, 45 insertions, 32 deletions
diff --git a/table/mock_table.cc b/table/mock_table.cc
index 117639df1..d7439c0e3 100644
--- a/table/mock_table.cc
+++ b/table/mock_table.cc
@@ -235,7 +235,11 @@ Status MockTableFactory::NewTableReader(
std::unique_ptr<RandomAccessFileReader>&& file, uint64_t /*file_size*/,
std::unique_ptr<TableReader>* table_reader,
bool /*prefetch_index_and_filter_in_cache*/) const {
- uint32_t id = GetIDFromFile(file.get());
+ uint32_t id;
+ Status s = GetIDFromFile(file.get(), &id);
+ if (!s.ok()) {
+ return s;
+ }
MutexLock lock_guard(&file_system_.mutex);
@@ -252,7 +256,9 @@ Status MockTableFactory::NewTableReader(
TableBuilder* MockTableFactory::NewTableBuilder(
const TableBuilderOptions& /*table_builder_options*/,
uint32_t /*column_family_id*/, WritableFileWriter* file) const {
- uint32_t id = GetAndWriteNextID(file);
+ uint32_t id;
+ Status s = GetAndWriteNextID(file, &id);
+ assert(s.ok());
return new MockTableBuilder(id, &file_system_, corrupt_mode_);
}
@@ -268,25 +274,30 @@ Status MockTableFactory::CreateMockTable(Env* env, const std::string& fname,
WritableFileWriter file_writer(NewLegacyWritableFileWrapper(std::move(file)),
fname, EnvOptions());
- uint32_t id = GetAndWriteNextID(&file_writer);
- file_system_.files.insert({id, std::move(file_contents)});
- return Status::OK();
+ uint32_t id;
+ s = GetAndWriteNextID(&file_writer, &id);
+ if (s.ok()) {
+ file_system_.files.insert({id, std::move(file_contents)});
+ }
+ return s;
}
-uint32_t MockTableFactory::GetAndWriteNextID(WritableFileWriter* file) const {
- uint32_t next_id = next_id_.fetch_add(1);
+Status MockTableFactory::GetAndWriteNextID(WritableFileWriter* file,
+ uint32_t* next_id) const {
+ *next_id = next_id_.fetch_add(1);
char buf[4];
- EncodeFixed32(buf, next_id);
- file->Append(Slice(buf, 4));
- return next_id;
+ EncodeFixed32(buf, *next_id);
+ return file->Append(Slice(buf, 4));
}
-uint32_t MockTableFactory::GetIDFromFile(RandomAccessFileReader* file) const {
+Status MockTableFactory::GetIDFromFile(RandomAccessFileReader* file,
+ uint32_t* id) const {
char buf[4];
Slice result;
- file->Read(IOOptions(), 0, 4, &result, buf, nullptr);
+ Status s = file->Read(IOOptions(), 0, 4, &result, buf, nullptr);
assert(result.size() == 4);
- return DecodeFixed32(buf);
+ *id = DecodeFixed32(buf);
+ return s;
}
void MockTableFactory::AssertSingleFile(const KVVector& file_contents) {
diff --git a/table/mock_table.h b/table/mock_table.h
index 4c57bee82..751fd8734 100644
--- a/table/mock_table.h
+++ b/table/mock_table.h
@@ -77,8 +77,8 @@ class MockTableFactory : public TableFactory {
void AssertLatestFile(const KVVector& file_contents);
private:
- uint32_t GetAndWriteNextID(WritableFileWriter* file) const;
- uint32_t GetIDFromFile(RandomAccessFileReader* file) const;
+ Status GetAndWriteNextID(WritableFileWriter* file, uint32_t* id) const;
+ Status GetIDFromFile(RandomAccessFileReader* file, uint32_t* id) const;
mutable MockTableFileSystem file_system_;
mutable std::atomic<uint32_t> next_id_;
diff --git a/table/sst_file_dumper.cc b/table/sst_file_dumper.cc
index 4318e0cea..c405609bc 100644
--- a/table/sst_file_dumper.cc
+++ b/table/sst_file_dumper.cc
@@ -177,8 +177,10 @@ Status SstFileDumper::VerifyChecksum() {
Status SstFileDumper::DumpTable(const std::string& out_filename) {
std::unique_ptr<WritableFile> out_file;
Env* env = options_.env;
- env->NewWritableFile(out_filename, &out_file, soptions_);
- Status s = table_reader_->DumpTable(out_file.get());
+ Status s = env->NewWritableFile(out_filename, &out_file, soptions_);
+ if (s.ok()) {
+ s = table_reader_->DumpTable(out_file.get());
+ }
if (!s.ok()) {
// close the file before return error, ignore the close error if there's any
out_file->Close().PermitUncheckedError();
diff --git a/table/table_test.cc b/table/table_test.cc
index 592493418..bfec7b79b 100644
--- a/table/table_test.cc
+++ b/table/table_test.cc
@@ -377,10 +377,10 @@ class TableConstructor : public Constructor {
} else {
builder->Add(kv.first, kv.second);
}
- EXPECT_TRUE(builder->status().ok());
+ EXPECT_OK(builder->status());
}
Status s = builder->Finish();
- file_writer_->Flush();
+ EXPECT_OK(file_writer_->Flush());
EXPECT_TRUE(s.ok()) << s.ToString();
EXPECT_EQ(TEST_GetSink()->contents().size(), builder->FileSize());
@@ -1270,15 +1270,15 @@ class FileChecksumTestHelper {
EXPECT_TRUE(table_builder_->status().ok());
}
Status s = table_builder_->Finish();
- file_writer_->Flush();
- EXPECT_TRUE(s.ok());
+ EXPECT_OK(file_writer_->Flush());
+ EXPECT_OK(s);
EXPECT_EQ(sink_->contents().size(), table_builder_->FileSize());
return s;
}
std::string GetFileChecksum() {
- file_writer_->Close();
+ EXPECT_OK(file_writer_->Close());
return table_builder_->GetFileChecksum();
}
@@ -3323,7 +3323,7 @@ TEST_P(BlockBasedTableTest, NoFileChecksum) {
f.GetFileWriter()));
ASSERT_OK(f.ResetTableBuilder(std::move(builder)));
f.AddKVtoKVMap(1000);
- f.WriteKVAndFlushTable();
+ ASSERT_OK(f.WriteKVAndFlushTable());
ASSERT_STREQ(f.GetFileChecksumFuncName(), kUnknownFileChecksumFuncName);
ASSERT_STREQ(f.GetFileChecksum().c_str(), kUnknownFileChecksum);
}
@@ -3362,7 +3362,7 @@ TEST_P(BlockBasedTableTest, Crc32cFileChecksum) {
f.GetFileWriter()));
ASSERT_OK(f.ResetTableBuilder(std::move(builder)));
f.AddKVtoKVMap(1000);
- f.WriteKVAndFlushTable();
+ ASSERT_OK(f.WriteKVAndFlushTable());
ASSERT_STREQ(f.GetFileChecksumFuncName(), "FileChecksumCrc32c");
std::unique_ptr<FileChecksumGenerator> checksum_crc32c_gen2 =
@@ -3418,7 +3418,7 @@ TEST_F(PlainTableTest, BasicPlainTableProperties) {
builder->Add(key, value);
}
ASSERT_OK(builder->Finish());
- file_writer->Flush();
+ ASSERT_OK(file_writer->Flush());
test::StringSink* ss =
ROCKSDB_NAMESPACE::test::GetStringSinkFromLegacyWriter(file_writer.get());
@@ -3468,7 +3468,7 @@ TEST_F(PlainTableTest, NoFileChecksum) {
f.GetFileWriter()));
ASSERT_OK(f.ResetTableBuilder(std::move(builder)));
f.AddKVtoKVMap(1000);
- f.WriteKVAndFlushTable();
+ ASSERT_OK(f.WriteKVAndFlushTable());
ASSERT_STREQ(f.GetFileChecksumFuncName(), kUnknownFileChecksumFuncName);
EXPECT_EQ(f.GetFileChecksum(), kUnknownFileChecksum);
}
@@ -3510,7 +3510,7 @@ TEST_F(PlainTableTest, Crc32cFileChecksum) {
f.GetFileWriter()));
ASSERT_OK(f.ResetTableBuilder(std::move(builder)));
f.AddKVtoKVMap(1000);
- f.WriteKVAndFlushTable();
+ ASSERT_OK(f.WriteKVAndFlushTable());
ASSERT_STREQ(f.GetFileChecksumFuncName(), "FileChecksumCrc32c");
std::unique_ptr<FileChecksumGenerator> checksum_crc32c_gen2 =
@@ -4022,7 +4022,7 @@ TEST_F(PrefixTest, PrefixAndWholeKeyTest) {
const std::string kDBPath = test::PerThreadDBPath("table_prefix_test");
options.table_factory.reset(NewBlockBasedTableFactory(bbto));
- DestroyDB(kDBPath, options);
+ ASSERT_OK(DestroyDB(kDBPath, options));
ROCKSDB_NAMESPACE::DB* db;
ASSERT_OK(ROCKSDB_NAMESPACE::DB::Open(options, kDBPath, &db));
@@ -4081,7 +4081,7 @@ TEST_P(BlockBasedTableTest, DISABLED_TableWithGlobalSeqno) {
builder->Add(ik.Encode(), value);
}
ASSERT_OK(builder->Finish());
- file_writer->Flush();
+ ASSERT_OK(file_writer->Flush());
test::RandomRWStringSink ss_rw(sink);
uint32_t version;
@@ -4265,7 +4265,7 @@ TEST_P(BlockBasedTableTest, BlockAlignTest) {
builder->Add(ik.Encode(), value);
}
ASSERT_OK(builder->Finish());
- file_writer->Flush();
+ ASSERT_OK(file_writer->Flush());
test::RandomRWStringSink ss_rw(sink);
std::unique_ptr<RandomAccessFileReader> file_reader(
@@ -4360,7 +4360,7 @@ TEST_P(BlockBasedTableTest, PropertiesBlockRestartPointTest) {
builder->Add(ik.Encode(), value);
}
ASSERT_OK(builder->Finish());
- file_writer->Flush();
+ ASSERT_OK(file_writer->Flush());
test::RandomRWStringSink ss_rw(sink);
std::unique_ptr<RandomAccessFileReader> file_reader(
@@ -4511,7 +4511,7 @@ TEST_P(BlockBasedTableTest, BadOptions) {
const std::string kDBPath =
test::PerThreadDBPath("block_based_table_bad_options_test");
options.table_factory.reset(NewBlockBasedTableFactory(bbto));
- DestroyDB(kDBPath, options);
+ ASSERT_OK(DestroyDB(kDBPath, options));
ROCKSDB_NAMESPACE::DB* db;
ASSERT_NOK(ROCKSDB_NAMESPACE::DB::Open(options, kDBPath, &db));