Skip to content

Commit

Permalink
Make WalFilter, SstPartitionerFactory, FileChecksumGenFactory, and Ta…
Browse files Browse the repository at this point in the history
…bleProperties Customizable (facebook#8638)

Summary: Pull Request resolved: facebook#8638

Reviewed By: zhichao-cao

Differential Revision: D31024729

Pulled By: mrambacher

fbshipit-source-id: 954c04ccab0b8dee64050a27aadf78ed119106c0
  • Loading branch information
mrambacher authored and facebook-github-bot committed Sep 28, 2021
1 parent b88109d commit 7fd68b7
Show file tree
Hide file tree
Showing 21 changed files with 570 additions and 37 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,7 @@ set(SOURCES
utilities/transactions/write_unprepared_txn.cc
utilities/transactions/write_unprepared_txn_db.cc
utilities/ttl/db_ttl_impl.cc
utilities/wal_filter.cc
utilities/write_batch_with_index/write_batch_with_index.cc
utilities/write_batch_with_index/write_batch_with_index_internal.cc)

Expand Down
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Public API change
* Made SystemClock extend the Customizable class and added a CreateFromString method. Implementations need to be registered with the ObjectRegistry and to implement a Name() method in order to be created via this method.
* Made SliceTransform extend the Customizable class and added a CreateFromString method. Implementations need to be registered with the ObjectRegistry and to implement a Name() method in order to be created via this method. The Capped and Prefixed transform classes return a short name (no length); use GetId for the fully qualified name.
* Made FileChecksumGenFactory, SstPartitionerFactory, TablePropertiesCollectorFactory, and WalFilter extend the Customizable class and added a CreateFromString method.

## 6.25.0 (2021-09-20)
### Bug Fixes
Expand Down
2 changes: 2 additions & 0 deletions TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ cpp_library(
"utilities/transactions/write_unprepared_txn.cc",
"utilities/transactions/write_unprepared_txn_db.cc",
"utilities/ttl/db_ttl_impl.cc",
"utilities/wal_filter.cc",
"utilities/write_batch_with_index/write_batch_with_index.cc",
"utilities/write_batch_with_index/write_batch_with_index_internal.cc",
],
Expand Down Expand Up @@ -757,6 +758,7 @@ cpp_library(
"utilities/transactions/write_unprepared_txn.cc",
"utilities/transactions/write_unprepared_txn_db.cc",
"utilities/ttl/db_ttl_impl.cc",
"utilities/wal_filter.cc",
"utilities/write_batch_with_index/write_batch_with_index.cc",
"utilities/write_batch_with_index/write_batch_with_index_internal.cc",
],
Expand Down
46 changes: 46 additions & 0 deletions db/compaction/sst_partitioner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,24 @@

#include <algorithm>

#include "rocksdb/utilities/customizable_util.h"
#include "rocksdb/utilities/object_registry.h"
#include "rocksdb/utilities/options_type.h"

namespace ROCKSDB_NAMESPACE {
static std::unordered_map<std::string, OptionTypeInfo>
sst_fixed_prefix_type_info = {
#ifndef ROCKSDB_LITE
{"length",
{0, OptionType::kSizeT, OptionVerificationType::kNormal,
OptionTypeFlags::kNone}},
#endif // ROCKSDB_LITE
};

SstPartitionerFixedPrefixFactory::SstPartitionerFixedPrefixFactory(size_t len)
: len_(len) {
RegisterOptions("Length", &len_, &sst_fixed_prefix_type_info);
}

PartitionerResult SstPartitionerFixedPrefix::ShouldPartition(
const PartitionerRequest& request) {
Expand Down Expand Up @@ -41,4 +58,33 @@ std::shared_ptr<SstPartitionerFactory> NewSstPartitionerFixedPrefixFactory(
return std::make_shared<SstPartitionerFixedPrefixFactory>(prefix_len);
}

#ifndef ROCKSDB_LITE
namespace {
static int RegisterSstPartitionerFactories(ObjectLibrary& library,
const std::string& /*arg*/) {
library.Register<SstPartitionerFactory>(
SstPartitionerFixedPrefixFactory::kClassName(),
[](const std::string& /*uri*/,
std::unique_ptr<SstPartitionerFactory>* guard,
std::string* /* errmsg */) {
guard->reset(new SstPartitionerFixedPrefixFactory(0));
return guard->get();
});
return 1;
}
} // namespace
#endif // ROCKSDB_LITE

Status SstPartitionerFactory::CreateFromString(
const ConfigOptions& options, const std::string& value,
std::shared_ptr<SstPartitionerFactory>* result) {
#ifndef ROCKSDB_LITE
static std::once_flag once;
std::call_once(once, [&]() {
RegisterSstPartitionerFactories(*(ObjectLibrary::Default().get()), "");
});
#endif // ROCKSDB_LITE
return LoadSharedObject<SstPartitionerFactory>(options, value, nullptr,
result);
}
} // namespace ROCKSDB_NAMESPACE
31 changes: 31 additions & 0 deletions db/db_table_properties_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,37 @@ TEST_F(DBTablePropertiesTest, GetPropertiesOfAllTablesTest) {
VerifyTableProperties(db_, 10 + 11 + 12 + 13);
}

TEST_F(DBTablePropertiesTest, CreateOnDeletionCollectorFactory) {
ConfigOptions options;
options.ignore_unsupported_options = false;

std::shared_ptr<TablePropertiesCollectorFactory> factory;
std::string id = CompactOnDeletionCollectorFactory::kClassName();
ASSERT_OK(
TablePropertiesCollectorFactory::CreateFromString(options, id, &factory));
auto del_factory = factory->CheckedCast<CompactOnDeletionCollectorFactory>();
ASSERT_NE(del_factory, nullptr);
ASSERT_EQ(0U, del_factory->GetWindowSize());
ASSERT_EQ(0U, del_factory->GetDeletionTrigger());
ASSERT_EQ(0.0, del_factory->GetDeletionRatio());
ASSERT_OK(TablePropertiesCollectorFactory::CreateFromString(
options, "window_size=100; deletion_trigger=90; id=" + id, &factory));
del_factory = factory->CheckedCast<CompactOnDeletionCollectorFactory>();
ASSERT_NE(del_factory, nullptr);
ASSERT_EQ(100U, del_factory->GetWindowSize());
ASSERT_EQ(90U, del_factory->GetDeletionTrigger());
ASSERT_EQ(0.0, del_factory->GetDeletionRatio());
ASSERT_OK(TablePropertiesCollectorFactory::CreateFromString(
options,
"window_size=100; deletion_trigger=90; deletion_ratio=0.5; id=" + id,
&factory));
del_factory = factory->CheckedCast<CompactOnDeletionCollectorFactory>();
ASSERT_NE(del_factory, nullptr);
ASSERT_EQ(100U, del_factory->GetWindowSize());
ASSERT_EQ(90U, del_factory->GetDeletionTrigger());
ASSERT_EQ(0.5, del_factory->GetDeletionRatio());
}

TablePropertiesCollection
DBTablePropertiesTest::TestGetPropertiesOfTablesInRange(
std::vector<Range> ranges, std::size_t* num_properties,
Expand Down
7 changes: 5 additions & 2 deletions include/rocksdb/concurrent_task_limiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

#pragma once

#include "rocksdb/env.h"
#include "rocksdb/statistics.h"
#include <stdint.h>

#include <string>

#include "rocksdb/rocksdb_namespace.h"

namespace ROCKSDB_NAMESPACE {

Expand Down
1 change: 0 additions & 1 deletion include/rocksdb/configurable.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ class Configurable {
virtual Status ValidateOptions(const DBOptions& db_opts,
const ColumnFamilyOptions& cf_opts) const;


// Splits the input opt_value into the ID field and the remaining options.
// The input opt_value can be in the form of "name" or "name=value
// [;name=value]". The first form uses the "name" as an id with no options The
Expand Down
7 changes: 6 additions & 1 deletion include/rocksdb/file_checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <string>
#include <vector>

#include "rocksdb/customizable.h"
#include "rocksdb/status.h"

namespace ROCKSDB_NAMESPACE {
Expand Down Expand Up @@ -63,9 +64,13 @@ class FileChecksumGenerator {
};

// Create the FileChecksumGenerator object for each SST file.
class FileChecksumGenFactory {
class FileChecksumGenFactory : public Customizable {
public:
virtual ~FileChecksumGenFactory() {}
static const char* Type() { return "FileChecksumGenFactory"; }
static Status CreateFromString(
const ConfigOptions& options, const std::string& value,
std::shared_ptr<FileChecksumGenFactory>* result);

// Create a new FileChecksumGenerator.
virtual std::unique_ptr<FileChecksumGenerator> CreateFileChecksumGenerator(
Expand Down
14 changes: 9 additions & 5 deletions include/rocksdb/sst_partitioner.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <memory>
#include <string>

#include "rocksdb/customizable.h"
#include "rocksdb/rocksdb_namespace.h"
#include "rocksdb/slice.h"

Expand Down Expand Up @@ -77,9 +78,13 @@ class SstPartitioner {
};
};

class SstPartitionerFactory {
class SstPartitionerFactory : public Customizable {
public:
virtual ~SstPartitionerFactory() {}
static const char* Type() { return "SstPartitionerFactory"; }
static Status CreateFromString(
const ConfigOptions& options, const std::string& value,
std::shared_ptr<SstPartitionerFactory>* result);

virtual std::unique_ptr<SstPartitioner> CreatePartitioner(
const SstPartitioner::Context& context) const = 0;
Expand Down Expand Up @@ -114,13 +119,12 @@ class SstPartitionerFixedPrefix : public SstPartitioner {
*/
class SstPartitionerFixedPrefixFactory : public SstPartitionerFactory {
public:
explicit SstPartitionerFixedPrefixFactory(size_t len) : len_(len) {}
explicit SstPartitionerFixedPrefixFactory(size_t len);

virtual ~SstPartitionerFixedPrefixFactory() {}

const char* Name() const override {
return "SstPartitionerFixedPrefixFactory";
}
static const char* kClassName() { return "SstPartitionerFixedPrefixFactory"; }
const char* Name() const override { return kClassName(); }

std::unique_ptr<SstPartitioner> CreatePartitioner(
const SstPartitioner::Context& /* context */) const override;
Expand Down
11 changes: 10 additions & 1 deletion include/rocksdb/table_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
#pragma once

#include <stdint.h>

#include <map>
#include <memory>
#include <string>

#include "rocksdb/customizable.h"
#include "rocksdb/status.h"
#include "rocksdb/types.h"

Expand Down Expand Up @@ -129,14 +133,19 @@ class TablePropertiesCollector {

// Constructs TablePropertiesCollector. Internals create a new
// TablePropertiesCollector for each new table
class TablePropertiesCollectorFactory {
class TablePropertiesCollectorFactory : public Customizable {
public:
struct Context {
uint32_t column_family_id;
static const uint32_t kUnknownColumnFamily;
};

virtual ~TablePropertiesCollectorFactory() {}
static const char* Type() { return "TablePropertiesCollectorFactory"; }
static Status CreateFromString(
const ConfigOptions& options, const std::string& value,
std::shared_ptr<TablePropertiesCollectorFactory>* result);

// has to be thread-safe
virtual TablePropertiesCollector* CreateTablePropertiesCollector(
TablePropertiesCollectorFactory::Context context) = 0;
Expand Down
41 changes: 18 additions & 23 deletions include/rocksdb/utilities/table_properties_collectors.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ namespace ROCKSDB_NAMESPACE {
class CompactOnDeletionCollectorFactory
: public TablePropertiesCollectorFactory {
public:
// A factory of a table property collector that marks a SST
// file as need-compaction when it observe at least "D" deletion
// entries in any "N" consecutive entries, or the ratio of tombstone
// entries >= deletion_ratio.
//
// @param sliding_window_size "N"
// @param deletion_trigger "D"
// @param deletion_ratio, if <= 0 or > 1, disable triggering compaction
// based on deletion ratio.
CompactOnDeletionCollectorFactory(size_t sliding_window_size,
size_t deletion_trigger,
double deletion_ratio);

~CompactOnDeletionCollectorFactory() {}

TablePropertiesCollector* CreateTablePropertiesCollector(
Expand All @@ -29,46 +42,28 @@ class CompactOnDeletionCollectorFactory
void SetWindowSize(size_t sliding_window_size) {
sliding_window_size_.store(sliding_window_size);
}
size_t GetWindowSize() const { return sliding_window_size_.load(); }

// Change the value of deletion_trigger "D"
void SetDeletionTrigger(size_t deletion_trigger) {
deletion_trigger_.store(deletion_trigger);
}

size_t GetDeletionTrigger() const { return deletion_trigger_.load(); }
// Change deletion ratio.
// @param deletion_ratio, if <= 0 or > 1, disable triggering compaction
// based on deletion ratio.
void SetDeletionRatio(double deletion_ratio) {
deletion_ratio_.store(deletion_ratio);
}

const char* Name() const override {
return "CompactOnDeletionCollector";
}
double GetDeletionRatio() const { return deletion_ratio_.load(); }
static const char* kClassName() { return "CompactOnDeletionCollector"; }
const char* Name() const override { return kClassName(); }

std::string ToString() const override;

private:
friend std::shared_ptr<CompactOnDeletionCollectorFactory>
NewCompactOnDeletionCollectorFactory(size_t sliding_window_size,
size_t deletion_trigger,
double deletion_ratio);
// A factory of a table property collector that marks a SST
// file as need-compaction when it observe at least "D" deletion
// entries in any "N" consecutive entries, or the ratio of tombstone
// entries >= deletion_ratio.
//
// @param sliding_window_size "N"
// @param deletion_trigger "D"
// @param deletion_ratio, if <= 0 or > 1, disable triggering compaction
// based on deletion ratio.
CompactOnDeletionCollectorFactory(size_t sliding_window_size,
size_t deletion_trigger,
double deletion_ratio)
: sliding_window_size_(sliding_window_size),
deletion_trigger_(deletion_trigger),
deletion_ratio_(deletion_ratio) {}

std::atomic<size_t> sliding_window_size_;
std::atomic<size_t> deletion_trigger_;
std::atomic<double> deletion_ratio_;
Expand Down
7 changes: 6 additions & 1 deletion include/rocksdb/wal_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@
#include <map>
#include <string>

#include "rocksdb/customizable.h"
#include "rocksdb/rocksdb_namespace.h"

namespace ROCKSDB_NAMESPACE {

class WriteBatch;
struct ConfigOptions;

// WALFilter allows an application to inspect write-ahead-log (WAL)
// records or modify their processing on recovery.
// Please see the details below.
class WalFilter {
class WalFilter : public Customizable {
public:
static const char* Type() { return "WalFilter"; }
static Status CreateFromString(const ConfigOptions& options,
const std::string& value, WalFilter** result);
enum class WalProcessingOption {
// Continue processing as usual
kContinueProcessing = 0,
Expand Down
12 changes: 12 additions & 0 deletions options/cf_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,14 @@ static std::unordered_map<std::string, OptionTypeInfo>
return Status::NotFound("Mismatched table option: ", name);
}
}}},
{"table_properties_collectors",
OptionTypeInfo::Vector<
std::shared_ptr<TablePropertiesCollectorFactory>>(
offset_of(
&ImmutableCFOptions::table_properties_collector_factories),
OptionVerificationType::kByName, OptionTypeFlags::kNone,
OptionTypeInfo::AsCustomSharedPtr<TablePropertiesCollectorFactory>(
0, OptionVerificationType::kByName, OptionTypeFlags::kNone))},
{"compaction_filter",
OptionTypeInfo::AsCustomRawPtr<const CompactionFilter>(
offset_of(&ImmutableCFOptions::compaction_filter),
Expand All @@ -694,6 +702,10 @@ static std::unordered_map<std::string, OptionTypeInfo>
{offset_of(&ImmutableCFOptions::compaction_pri),
OptionType::kCompactionPri, OptionVerificationType::kNormal,
OptionTypeFlags::kNone}},
{"sst_partitioner_factory",
OptionTypeInfo::AsCustomSharedPtr<SstPartitionerFactory>(
offset_of(&ImmutableCFOptions::sst_partitioner_factory),
OptionVerificationType::kByName, OptionTypeFlags::kAllowNull)},
};

const std::string OptionsHelper::kCFOptionsName = "ColumnFamilyOptions";
Expand Down
Loading

0 comments on commit 7fd68b7

Please sign in to comment.