allowing CompactFiles to return new file names

Summary:
This is a small API extension to allow the CompactFiles method to return the names of files that were created during the compaction.
Closes https://github.com/facebook/rocksdb/pull/3608

Differential Revision: D7275789

Pulled By: siying

fbshipit-source-id: 1ec0c3954a0f10cd877efb5f29f9be6c7b59e9ba
This commit is contained in:
Niv Dayan 2018-03-15 11:46:16 -07:00 committed by Facebook Github Bot
parent cc118b0e6f
commit da82aab126
6 changed files with 31 additions and 10 deletions

View File

@ -185,7 +185,9 @@ class DBImpl : public DB {
ColumnFamilyHandle* column_family,
const std::vector<std::string>& input_file_names,
const int output_level,
const int output_path_id = -1) override;
const int output_path_id = -1,
std::vector<std::string>* const output_file_names
= nullptr) override;
virtual Status PauseBackgroundWork() override;
virtual Status ContinueBackgroundWork() override;
@ -881,6 +883,7 @@ class DBImpl : public DB {
Status CompactFilesImpl(const CompactionOptions& compact_options,
ColumnFamilyData* cfd, Version* version,
const std::vector<std::string>& input_file_names,
std::vector<std::string>* const output_file_names,
const int output_level, int output_path_id,
JobContext* job_context, LogBuffer* log_buffer);

View File

@ -461,7 +461,8 @@ Status DBImpl::CompactFiles(
const CompactionOptions& compact_options,
ColumnFamilyHandle* column_family,
const std::vector<std::string>& input_file_names,
const int output_level, const int output_path_id) {
const int output_level, const int output_path_id,
std::vector<std::string>* const output_file_names) {
#ifdef ROCKSDB_LITE
// not supported in lite version
return Status::NotSupported("Not supported in ROCKSDB LITE");
@ -488,7 +489,7 @@ Status DBImpl::CompactFiles(
WaitForIngestFile();
s = CompactFilesImpl(compact_options, cfd, sv->current,
input_file_names, output_level,
input_file_names, output_file_names, output_level,
output_path_id, &job_context, &log_buffer);
}
if (sv->Unref()) {
@ -532,6 +533,7 @@ Status DBImpl::CompactFiles(
Status DBImpl::CompactFilesImpl(
const CompactionOptions& compact_options, ColumnFamilyData* cfd,
Version* version, const std::vector<std::string>& input_file_names,
std::vector<std::string>* const output_file_names,
const int output_level, int output_path_id, JobContext* job_context,
LogBuffer* log_buffer) {
mutex_.AssertHeld();
@ -680,6 +682,14 @@ Status DBImpl::CompactFilesImpl(
}
}
if (output_file_names != nullptr) {
for (const auto newf : c->edit()->GetNewFiles()) {
(*output_file_names).push_back(TableFileName(
immutable_db_options_.db_paths, newf.second.fd.GetNumber(),
newf.second.fd.GetPathId()) );
}
}
c.reset();
bg_compaction_scheduled_--;

View File

@ -76,7 +76,9 @@ class DBImplReadOnly : public DBImpl {
const CompactionOptions& /*compact_options*/,
ColumnFamilyHandle* /*column_family*/,
const std::vector<std::string>& /*input_file_names*/,
const int /*output_level*/, const int /*output_path_id*/ = -1) override {
const int /*output_level*/, const int /*output_path_id*/ = -1,
std::vector<std::string>* const /*output_file_names*/ = nullptr
) override {
return Status::NotSupported("Not supported operation in read only mode.");
}

View File

@ -2411,7 +2411,9 @@ class ModelDB : public DB {
const CompactionOptions& /*compact_options*/,
ColumnFamilyHandle* /*column_family*/,
const std::vector<std::string>& /*input_file_names*/,
const int /*output_level*/, const int /*output_path_id*/ = -1) override {
const int /*output_level*/, const int /*output_path_id*/ = -1,
std::vector<std::string>* const /*output_file_names*/ = nullptr
) override {
return Status::NotSupported("Not supported operation.");
}

View File

@ -814,14 +814,17 @@ class DB {
const CompactionOptions& compact_options,
ColumnFamilyHandle* column_family,
const std::vector<std::string>& input_file_names,
const int output_level, const int output_path_id = -1) = 0;
const int output_level, const int output_path_id = -1,
std::vector<std::string>* const output_file_names = nullptr) = 0;
virtual Status CompactFiles(
const CompactionOptions& compact_options,
const std::vector<std::string>& input_file_names,
const int output_level, const int output_path_id = -1) {
const int output_level, const int output_path_id = -1,
std::vector<std::string>* const output_file_names = nullptr) {
return CompactFiles(compact_options, DefaultColumnFamily(),
input_file_names, output_level, output_path_id);
input_file_names, output_level, output_path_id,
output_file_names);
}
// This function will wait until all currently running background processes

View File

@ -219,10 +219,11 @@ class StackableDB : public DB {
const CompactionOptions& compact_options,
ColumnFamilyHandle* column_family,
const std::vector<std::string>& input_file_names,
const int output_level, const int output_path_id = -1) override {
const int output_level, const int output_path_id = -1,
std::vector<std::string>* const output_file_names = nullptr) override {
return db_->CompactFiles(
compact_options, column_family, input_file_names,
output_level, output_path_id);
output_level, output_path_id, output_file_names);
}
virtual Status PauseBackgroundWork() override {