Make CompactionService derived from Customizable (#8395)

Summary:
(1)Make CompactionService derived from Customizable by defining two extra functions that are needed, as described in customizable.h comment section
(2)Revise the MyTestCompactionService class in compaction_service_test.cc to satisfy the class inheritance requirement
(3)Specify namespace of ToString() in compaction_service_test.cc to avoid function collision with CompactionService's ancestor classes

Test did:
make -j24 compaction_service_test
./compaction_service_test

Pull Request resolved: https://github.com/facebook/rocksdb/pull/8395

Reviewed By: jay-zhuang

Differential Revision: D29076068

Pulled By: hx235

fbshipit-source-id: c130100fa466939b3137e917f5fdc4b2ae8e37d4
This commit is contained in:
Hui Xiao 2021-06-14 11:40:46 -07:00 committed by Facebook GitHub Bot
parent 9047fd7766
commit dcddc1065e
2 changed files with 14 additions and 4 deletions

View File

@ -16,6 +16,10 @@ class MyTestCompactionService : public CompactionService {
std::shared_ptr<FileSystem> fs, Options& options) std::shared_ptr<FileSystem> fs, Options& options)
: db_path_(db_path), fs_(fs), options_(options) {} : db_path_(db_path), fs_(fs), options_(options) {}
static const char* kClassName() { return "MyTestCompactionService"; }
const char* Name() const override { return kClassName(); }
CompactionServiceJobStatus Start(const std::string& compaction_service_input, CompactionServiceJobStatus Start(const std::string& compaction_service_input,
int job_id) override { int job_id) override {
InstrumentedMutexLock l(&mutex_); InstrumentedMutexLock l(&mutex_);
@ -51,9 +55,9 @@ class MyTestCompactionService : public CompactionService {
options_override.table_factory = options_.table_factory; options_override.table_factory = options_.table_factory;
options_override.sst_partitioner_factory = options_.sst_partitioner_factory; options_override.sst_partitioner_factory = options_.sst_partitioner_factory;
Status s = DB::OpenAndCompact(db_path_, db_path_ + "/" + ToString(job_id), Status s = DB::OpenAndCompact(
compaction_input, compaction_service_result, db_path_, db_path_ + "/" + ROCKSDB_NAMESPACE::ToString(job_id),
options_override); compaction_input, compaction_service_result, options_override);
TEST_SYNC_POINT_CALLBACK("MyTestCompactionService::WaitForComplete::End", TEST_SYNC_POINT_CALLBACK("MyTestCompactionService::WaitForComplete::End",
compaction_service_result); compaction_service_result);
compaction_num_.fetch_add(1); compaction_num_.fetch_add(1);

View File

@ -20,6 +20,7 @@
#include "rocksdb/advanced_options.h" #include "rocksdb/advanced_options.h"
#include "rocksdb/comparator.h" #include "rocksdb/comparator.h"
#include "rocksdb/compression_type.h" #include "rocksdb/compression_type.h"
#include "rocksdb/customizable.h"
#include "rocksdb/data_structure.h" #include "rocksdb/data_structure.h"
#include "rocksdb/env.h" #include "rocksdb/env.h"
#include "rocksdb/file_checksum.h" #include "rocksdb/file_checksum.h"
@ -370,8 +371,13 @@ enum class CompactionServiceJobStatus : char {
kUseLocal, // TODO: Add support for use local compaction kUseLocal, // TODO: Add support for use local compaction
}; };
class CompactionService { class CompactionService : public Customizable {
public: public:
static const char* Type() { return "CompactionService"; }
// Returns the name of this compaction service.
virtual const char* Name() const = 0;
// Start the compaction with input information, which can be passed to // Start the compaction with input information, which can be passed to
// `DB::OpenAndCompact()`. // `DB::OpenAndCompact()`.
// job_id is pre-assigned, it will be reset after DB re-open. // job_id is pre-assigned, it will be reset after DB re-open.