Add a UDT comparator for ReverseBytewiseComparator to object library (#11647)

Summary:
Add a built-in comparator that supports uint64_t style user-defined timestamps for ReverseBytewiseComparator.

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

Test Plan:
Added a test wrapper for retrieving this comparator from registry and used it in this test:
`./udt_util_test`

Reviewed By: ltamasi

Differential Revision: D47848303

Pulled By: jowlyzhang

fbshipit-source-id: 5af5534a8c2d9195997d0308c8e194c1c797548c
oxigraph-main
Yu Zhang 1 year ago committed by Facebook GitHub Bot
parent 63a5125a52
commit 5dd8c114bb
  1. 10
      test_util/testutil.cc
  2. 3
      test_util/testutil.h
  3. 18
      util/comparator.cc
  4. 5
      util/udt_util_test.cc

@ -150,6 +150,16 @@ const Comparator* BytewiseComparatorWithU64TsWrapper() {
return user_comparator; return user_comparator;
} }
const Comparator* ReverseBytewiseComparatorWithU64TsWrapper() {
ConfigOptions config_options;
const Comparator* user_comparator = nullptr;
Status s = Comparator::CreateFromString(
config_options, "rocksdb.ReverseBytewiseComparator.u64ts",
&user_comparator);
s.PermitUncheckedError();
return user_comparator;
}
void CorruptKeyType(InternalKey* ikey) { void CorruptKeyType(InternalKey* ikey) {
std::string keystr = ikey->Encode().ToString(); std::string keystr = ikey->Encode().ToString();
keystr[keystr.size() - 8] = kTypeLogData; keystr[keystr.size() - 8] = kTypeLogData;

@ -132,6 +132,9 @@ extern const Comparator* Uint64Comparator();
// A wrapper api for getting the ComparatorWithU64Ts<BytewiseComparator> // A wrapper api for getting the ComparatorWithU64Ts<BytewiseComparator>
extern const Comparator* BytewiseComparatorWithU64TsWrapper(); extern const Comparator* BytewiseComparatorWithU64TsWrapper();
// A wrapper api for getting the ComparatorWithU64Ts<ReverseBytewiseComparator>
extern const Comparator* ReverseBytewiseComparatorWithU64TsWrapper();
class StringSink : public FSWritableFile { class StringSink : public FSWritableFile {
public: public:
std::string contents_; std::string contents_;

@ -316,6 +316,12 @@ const Comparator* BytewiseComparatorWithU64Ts() {
return &comp_with_u64_ts; return &comp_with_u64_ts;
} }
const Comparator* ReverseBytewiseComparatorWithU64Ts() {
STATIC_AVOID_DESTRUCTION(
ComparatorWithU64TsImpl<ReverseBytewiseComparatorImpl>, comp_with_u64_ts);
return &comp_with_u64_ts;
}
static int RegisterBuiltinComparators(ObjectLibrary& library, static int RegisterBuiltinComparators(ObjectLibrary& library,
const std::string& /*arg*/) { const std::string& /*arg*/) {
library.AddFactory<const Comparator>( library.AddFactory<const Comparator>(
@ -333,7 +339,14 @@ static int RegisterBuiltinComparators(ObjectLibrary& library,
[](const std::string& /*uri*/, [](const std::string& /*uri*/,
std::unique_ptr<const Comparator>* /*guard*/, std::unique_ptr<const Comparator>* /*guard*/,
std::string* /*errmsg*/) { return BytewiseComparatorWithU64Ts(); }); std::string* /*errmsg*/) { return BytewiseComparatorWithU64Ts(); });
return 3; library.AddFactory<const Comparator>(
ComparatorWithU64TsImpl<ReverseBytewiseComparatorImpl>::kClassName(),
[](const std::string& /*uri*/,
std::unique_ptr<const Comparator>* /*guard*/,
std::string* /*errmsg*/) {
return ReverseBytewiseComparatorWithU64Ts();
});
return 4;
} }
Status Comparator::CreateFromString(const ConfigOptions& config_options, Status Comparator::CreateFromString(const ConfigOptions& config_options,
@ -357,6 +370,9 @@ Status Comparator::CreateFromString(const ConfigOptions& config_options,
} else if (id == } else if (id ==
ComparatorWithU64TsImpl<BytewiseComparatorImpl>::kClassName()) { ComparatorWithU64TsImpl<BytewiseComparatorImpl>::kClassName()) {
*result = BytewiseComparatorWithU64Ts(); *result = BytewiseComparatorWithU64Ts();
} else if (id == ComparatorWithU64TsImpl<
ReverseBytewiseComparatorImpl>::kClassName()) {
*result = ReverseBytewiseComparatorWithU64Ts();
} else if (value.empty()) { } else if (value.empty()) {
// No Id and no options. Clear the object // No Id and no options. Clear the object
*result = nullptr; *result = nullptr;

@ -356,8 +356,9 @@ TEST(ValidateUserDefinedTimestampsOptionsTest,
TEST(ValidateUserDefinedTimestampsOptionsTest, DisableUserDefinedTimestamps) { TEST(ValidateUserDefinedTimestampsOptionsTest, DisableUserDefinedTimestamps) {
bool mark_sst_files = false; bool mark_sst_files = false;
const Comparator* new_comparator = BytewiseComparator(); const Comparator* new_comparator = ReverseBytewiseComparator();
const Comparator* old_comparator = test::BytewiseComparatorWithU64TsWrapper(); const Comparator* old_comparator =
test::ReverseBytewiseComparatorWithU64TsWrapper();
ASSERT_OK(ValidateUserDefinedTimestampsOptions( ASSERT_OK(ValidateUserDefinedTimestampsOptions(
new_comparator, std::string(old_comparator->Name()), new_comparator, std::string(old_comparator->Name()),
false /*new_persist_udt*/, false /*old_persist_udt*/, &mark_sst_files)); false /*new_persist_udt*/, false /*old_persist_udt*/, &mark_sst_files));

Loading…
Cancel
Save