// The name of the filter policy used in this table.
// If no filter policy is used, `filter_policy_name` will be an empty string.
std::string filter_policy_name;
- // The name of the comparator used in this table.
- std::string comparator_name;
- // The name of the merge operator used in this table.
- // If no merge operator is used, `merge_operator_name` will be
- // an empty string.
- std::string merge_operator_name;
- // The names of the property collectors factories used in this table
- // separated by commas
- // {collector_name[1]},{collector_name[2]},{collector_name[3]} ..
- std::string property_collectors_names;
// user collected properties
UserCollectedProperties user_collected_properties;
static const std::string kFormatVersion;
static const std::string kFixedKeyLen;
static const std::string kFilterPolicy;
- static const std::string kComparator;
- static const std::string kMergeOperator;
- static const std::string kPropertyCollectors;
};
extern const std::string kPropertiesBlock;
#include "rocksdb/env.h"
#include "rocksdb/filter_policy.h"
#include "rocksdb/flush_block_policy.h"
-#include "rocksdb/merge_operator.h"
#include "rocksdb/table.h"
#include "table/block.h"
r->table_options.filter_policy->Name() : "";
r->props.index_size =
r->index_builder->EstimatedSize() + kBlockTrailerSize;
- r->props.comparator_name = r->ioptions.comparator != nullptr
- ? r->ioptions.comparator->Name()
- : "N/A";
- r->props.merge_operator_name = r->ioptions.merge_operator != nullptr
- ? r->ioptions.merge_operator->Name()
- : "N/A";
-
- std::string property_collectors_names = "";
- for (uint32_t i = 0;
- i < r->ioptions.table_properties_collector_factories.size(); ++i) {
- if (i != 0) {
- property_collectors_names += ",";
- }
- property_collectors_names +=
- r->ioptions.table_properties_collector_factories[i]->Name();
- }
- r->props.property_collectors_names = property_collectors_names;
// Add basic properties
property_block_builder.AddTableProperty(r->props);
Add(TablePropertiesNames::kFixedKeyLen, props.fixed_key_len);
if (!props.filter_policy_name.empty()) {
- Add(TablePropertiesNames::kFilterPolicy, props.filter_policy_name);
- }
-
- if (!props.comparator_name.empty()) {
- Add(TablePropertiesNames::kComparator, props.comparator_name);
- }
-
- if (!props.merge_operator_name.empty()) {
- Add(TablePropertiesNames::kMergeOperator, props.merge_operator_name);
- }
-
- if (!props.property_collectors_names.empty()) {
- Add(TablePropertiesNames::kPropertyCollectors,
- props.property_collectors_names);
+ Add(TablePropertiesNames::kFilterPolicy,
+ props.filter_policy_name);
}
}
*(pos->second) = val;
} else if (key == TablePropertiesNames::kFilterPolicy) {
new_table_properties->filter_policy_name = raw_val.ToString();
- } else if (key == TablePropertiesNames::kComparator) {
- new_table_properties->comparator_name = raw_val.ToString();
- } else if (key == TablePropertiesNames::kMergeOperator) {
- new_table_properties->merge_operator_name = raw_val.ToString();
- } else if (key == TablePropertiesNames::kPropertyCollectors) {
- new_table_properties->property_collectors_names = raw_val.ToString();
} else {
// handle user-collected properties
new_table_properties->user_collected_properties.insert(
filter_policy_name.empty() ? std::string("N/A") : filter_policy_name,
prop_delim, kv_delim);
- AppendProperty(result, "comparator name",
- comparator_name.empty() ? std::string("N/A") : comparator_name,
- prop_delim, kv_delim);
-
- AppendProperty(
- result, "merge operator name",
- merge_operator_name.empty() ? std::string("N/A") : merge_operator_name,
- prop_delim, kv_delim);
-
- AppendProperty(result, "property collectors names",
- property_collectors_names.empty() ? std::string("N/A")
- : property_collectors_names,
- prop_delim, kv_delim);
-
return result;
}
"rocksdb.format.version";
const std::string TablePropertiesNames::kFixedKeyLen =
"rocksdb.fixed.key.length";
-const std::string TablePropertiesNames::kComparator = "rocksdb.comparator";
-const std::string TablePropertiesNames::kMergeOperator =
- "rocksdb.merge.operator";
-const std::string TablePropertiesNames::kPropertyCollectors =
- "rocksdb.property.collectors";
extern const std::string kPropertiesBlock = "rocksdb.properties";
// Old property block name for backward compatibility
#include "util/testharness.h"
#include "util/testutil.h"
-#include "utilities/merge_operators.h"
-
namespace rocksdb {
extern const uint64_t kLegacyBlockBasedTableMagicNumber;
namespace {
-// DummyPropertiesCollector used to test BlockBasedTableProperties
-class DummyPropertiesCollector : public TablePropertiesCollector {
- public:
- const char* Name() const { return ""; }
-
- Status Finish(UserCollectedProperties* properties) { return Status::OK(); }
-
- Status Add(const Slice& user_key, const Slice& value) { return Status::OK(); }
-
- virtual UserCollectedProperties GetReadableProperties() const {
- return UserCollectedProperties{};
- }
-};
-
-class DummyPropertiesCollectorFactory1
- : public TablePropertiesCollectorFactory {
- public:
- virtual TablePropertiesCollector* CreateTablePropertiesCollector(
- TablePropertiesCollectorFactory::Context context) {
- return new DummyPropertiesCollector();
- }
- const char* Name() const { return "DummyPropertiesCollector1"; }
-};
-
-class DummyPropertiesCollectorFactory2
- : public TablePropertiesCollectorFactory {
- public:
- virtual TablePropertiesCollector* CreateTablePropertiesCollector(
- TablePropertiesCollectorFactory::Context context) {
- return new DummyPropertiesCollector();
- }
- const char* Name() const { return "DummyPropertiesCollector2"; }
-};
-
// Return reverse of "key".
// Used to test non-lexicographic comparators.
std::string Reverse(const Slice& key) {
ASSERT_EQ(content.size() + kBlockTrailerSize, props.data_size);
}
-TEST_F(BlockBasedTableTest, BlockBasedTableProperties2) {
- TableConstructor c(&reverse_key_comparator);
- std::vector<std::string> keys;
- stl_wrappers::KVMap kvmap;
-
- {
- Options options;
- BlockBasedTableOptions table_options;
- options.table_factory.reset(NewBlockBasedTableFactory(table_options));
-
- const ImmutableCFOptions ioptions(options);
- c.Finish(options, ioptions, table_options,
- GetPlainInternalComparator(options.comparator), &keys, &kvmap);
-
- auto& props = *c.GetTableReader()->GetTableProperties();
-
- // Default comparator
- ASSERT_EQ("leveldb.BytewiseComparator", props.comparator_name);
- // No merge operator
- ASSERT_EQ("N/A", props.merge_operator_name);
- // No property collectors
- ASSERT_EQ("", props.property_collectors_names);
- // No filter policy is used
- ASSERT_EQ("", props.filter_policy_name);
- }
-
- {
- Options options;
- BlockBasedTableOptions table_options;
- options.table_factory.reset(NewBlockBasedTableFactory(table_options));
- options.comparator = &reverse_key_comparator;
- options.merge_operator = MergeOperators::CreateUInt64AddOperator();
- options.table_properties_collector_factories.emplace_back(
- new DummyPropertiesCollectorFactory1());
- options.table_properties_collector_factories.emplace_back(
- new DummyPropertiesCollectorFactory2());
-
- const ImmutableCFOptions ioptions(options);
- c.Finish(options, ioptions, table_options,
- GetPlainInternalComparator(options.comparator), &keys, &kvmap);
-
- auto& props = *c.GetTableReader()->GetTableProperties();
-
- ASSERT_EQ("rocksdb.ReverseBytewiseComparator", props.comparator_name);
- ASSERT_EQ("UInt64AddOperator", props.merge_operator_name);
- ASSERT_EQ("DummyPropertiesCollector1,DummyPropertiesCollector2",
- props.property_collectors_names);
- ASSERT_EQ("", props.filter_policy_name); // no filter policy is used
- }
-}
-
TEST_F(BlockBasedTableTest, FilterPolicyNameProperties) {
TableConstructor c(BytewiseComparator(), true);
c.Add("a1", "val1");