Invoke OnTableFileCreated for empty SSTs (#4307)

Summary:
The API comment on `OnTableFileCreationStarted` (b6280d01f9/include/rocksdb/listener.h (L331-L333)) led users to believe a call to `OnTableFileCreationStarted` will always be matched with a call to `OnTableFileCreated`. However, we were skipping the `OnTableFileCreated` call in one case: no error happens but also no file is generated since there's no data.

This PR adds the call to `OnTableFileCreated` for that case. The filename will be "(nil)" and the size will be zero.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4307

Differential Revision: D9485201

Pulled By: ajkr

fbshipit-source-id: 2f077ec7913f128487aae2624c69a50762394df6
main
Andrew Kryczka 6 years ago committed by Facebook Github Bot
parent cf7150ac2e
commit ee234e83e3
  1. 2
      HISTORY.md
  2. 4
      db/compaction_job.cc
  3. 12
      tools/db_stress.cc

@ -1,6 +1,8 @@
# Rocksdb Change Log # Rocksdb Change Log
## Unreleased ## Unreleased
### Public API Change ### Public API Change
* `OnTableFileCreated` will now be called for empty files generated during compaction. In that case, `TableFileCreationInfo::file_path` will be "(nil)" and `TableFileCreationInfo::file_size` will be zero.
### New Features ### New Features
### Bug Fixes ### Bug Fixes

@ -1308,9 +1308,7 @@ Status CompactionJob::FinishCompactionOutputFile(
// VersionEdit. // VersionEdit.
assert(!sub_compact->outputs.empty()); assert(!sub_compact->outputs.empty());
sub_compact->outputs.pop_back(); sub_compact->outputs.pop_back();
sub_compact->builder.reset(); meta = nullptr;
sub_compact->current_output_file_size = 0;
return s;
} }
if (s.ok() && (current_entries > 0 || tp.num_range_deletions > 0)) { if (s.ok() && (current_entries > 0 || tp.num_range_deletions > 0)) {

@ -1221,7 +1221,9 @@ class DbStressListener : public EventListener {
const std::vector<ColumnFamilyDescriptor>& column_families) const std::vector<ColumnFamilyDescriptor>& column_families)
: db_name_(db_name), db_paths_(db_paths), : db_name_(db_name), db_paths_(db_paths),
column_families_(column_families) {} column_families_(column_families) {}
virtual ~DbStressListener() {} virtual ~DbStressListener() {
assert(num_pending_file_creations_ == 0);
}
#ifndef ROCKSDB_LITE #ifndef ROCKSDB_LITE
virtual void OnFlushCompleted(DB* /*db*/, const FlushJobInfo& info) override { virtual void OnFlushCompleted(DB* /*db*/, const FlushJobInfo& info) override {
assert(IsValidColumnFamilyName(info.cf_name)); assert(IsValidColumnFamilyName(info.cf_name));
@ -1246,16 +1248,23 @@ class DbStressListener : public EventListener {
std::chrono::microseconds(Random::GetTLSInstance()->Uniform(5000))); std::chrono::microseconds(Random::GetTLSInstance()->Uniform(5000)));
} }
virtual void OnTableFileCreationStarted(
const TableFileCreationBriefInfo& /*info*/) {
++num_pending_file_creations_;
}
virtual void OnTableFileCreated(const TableFileCreationInfo& info) override { virtual void OnTableFileCreated(const TableFileCreationInfo& info) override {
assert(info.db_name == db_name_); assert(info.db_name == db_name_);
assert(IsValidColumnFamilyName(info.cf_name)); assert(IsValidColumnFamilyName(info.cf_name));
if (info.file_size) {
VerifyFilePath(info.file_path); VerifyFilePath(info.file_path);
}
assert(info.job_id > 0 || FLAGS_compact_files_one_in > 0); assert(info.job_id > 0 || FLAGS_compact_files_one_in > 0);
if (info.status.ok() && info.file_size > 0) { if (info.status.ok() && info.file_size > 0) {
assert(info.table_properties.data_size > 0); assert(info.table_properties.data_size > 0);
assert(info.table_properties.raw_key_size > 0); assert(info.table_properties.raw_key_size > 0);
assert(info.table_properties.num_entries > 0); assert(info.table_properties.num_entries > 0);
} }
--num_pending_file_creations_;
} }
protected: protected:
@ -1328,6 +1337,7 @@ class DbStressListener : public EventListener {
std::string db_name_; std::string db_name_;
std::vector<DbPath> db_paths_; std::vector<DbPath> db_paths_;
std::vector<ColumnFamilyDescriptor> column_families_; std::vector<ColumnFamilyDescriptor> column_families_;
std::atomic<int> num_pending_file_creations_;
}; };
} // namespace } // namespace

Loading…
Cancel
Save