Disallow SstFileWriter from creating empty sst files

Summary:
SstFileWriter may create an sst file with no entries
Right now this will fail when being ingested using DB::AddFile() saying that the keys are corrupted

Test Plan: make check

Reviewers: yhchiang, rven, anthony, sdong

Reviewed By: sdong

Subscribers: dhruba

Differential Revision: https://reviews.facebook.net/D52815
main
Islam AbdelRahman 9 years ago
parent f53c95f81b
commit 2fbc59a348
  1. 3
      db/db_impl.cc
  2. 6
      db/db_test.cc
  3. 3
      table/sst_file_writer.cc

@ -3502,6 +3502,9 @@ Status DBImpl::AddFile(ColumnFamilyHandle* column_family,
auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(column_family); auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(column_family);
ColumnFamilyData* cfd = cfh->cfd(); ColumnFamilyData* cfd = cfh->cfd();
if (file_info->num_entries == 0) {
return Status::InvalidArgument("File contain no entries");
}
if (file_info->version != 1) { if (file_info->version != 1) {
return Status::InvalidArgument("Generated table version is not supported"); return Status::InvalidArgument("Generated table version is not supported");
} }

@ -8801,6 +8801,12 @@ TEST_F(DBTest, AddExternalSstFile) {
ASSERT_EQ(file5_info.smallest_key, Key(400)); ASSERT_EQ(file5_info.smallest_key, Key(400));
ASSERT_EQ(file5_info.largest_key, Key(499)); ASSERT_EQ(file5_info.largest_key, Key(499));
// Cannot create an empty sst file
std::string file_empty = sst_files_folder + "file_empty.sst";
ExternalSstFileInfo file_empty_info;
s = sst_file_writer.Finish(&file_empty_info);
ASSERT_NOK(s);
DestroyAndReopen(options); DestroyAndReopen(options);
// Add file using file path // Add file using file path
s = db_->AddFile(file1); s = db_->AddFile(file1);

@ -163,6 +163,9 @@ Status SstFileWriter::Finish(ExternalSstFileInfo* file_info) {
if (!r->builder) { if (!r->builder) {
return Status::InvalidArgument("File is not opened"); return Status::InvalidArgument("File is not opened");
} }
if (r->file_info.num_entries == 0) {
return Status::InvalidArgument("Cannot create sst file with no entries");
}
Status s = r->builder->Finish(); Status s = r->builder->Finish();
if (s.ok()) { if (s.ok()) {

Loading…
Cancel
Save