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
This commit is contained in:
parent
f53c95f81b
commit
2fbc59a348
@ -3502,6 +3502,9 @@ Status DBImpl::AddFile(ColumnFamilyHandle* column_family,
|
||||
auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(column_family);
|
||||
ColumnFamilyData* cfd = cfh->cfd();
|
||||
|
||||
if (file_info->num_entries == 0) {
|
||||
return Status::InvalidArgument("File contain no entries");
|
||||
}
|
||||
if (file_info->version != 1) {
|
||||
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.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);
|
||||
// Add file using file path
|
||||
s = db_->AddFile(file1);
|
||||
|
@ -163,6 +163,9 @@ Status SstFileWriter::Finish(ExternalSstFileInfo* file_info) {
|
||||
if (!r->builder) {
|
||||
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();
|
||||
if (s.ok()) {
|
||||
|
Loading…
Reference in New Issue
Block a user