]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commitdiff
Remove FactoryFunc from LoadXXXObject (#11203)
authormrambacher <mrambach@gmail.com>
Fri, 17 Feb 2023 20:54:07 +0000 (12:54 -0800)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Fri, 17 Feb 2023 20:54:07 +0000 (12:54 -0800)
Summary:
The primary purpose of the FactoryFunc was to support LITE mode where the ObjectRegistry was not available.  With the removal of LITE mode, the function was no longer required.

Note that the MergeOperator had some private classes defined in header files.  To gain access to their constructors (and name methods), the class definitions were moved into header files.

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

Reviewed By: cbi42

Differential Revision: D43160255

Pulled By: pdillinger

fbshipit-source-id: f3a465fd5d1a7049b73ecf31e4b8c3762f6dae6c

23 files changed:
HISTORY.md
cache/cache.cc
db/compaction/sst_partitioner.cc
db/event_helpers.cc
env/env.cc
env/env_encryption.cc
env/file_system.cc
include/rocksdb/utilities/customizable_util.h
monitoring/statistics.cc
options/customizable_test.cc
table/block_based/flush_block_policy.cc
table/table_factory.cc
util/file_checksum_helper.cc
utilities/compaction_filters.cc
utilities/merge_operators.cc
utilities/merge_operators/max.cc
utilities/merge_operators/max_operator.h [new file with mode: 0644]
utilities/merge_operators/put.cc
utilities/merge_operators/put_operator.h [new file with mode: 0644]
utilities/merge_operators/uint64add.cc
utilities/merge_operators/uint64add.h [new file with mode: 0644]
utilities/table_properties_collectors/compact_on_deletion_collector.cc
utilities/wal_filter.cc

index d041b3fe9947e4a176486b4fd3c0af0ef4a21735..a300611b5ca16d384d9aa69f4159b6b03c1bf70b 100644 (file)
@@ -21,6 +21,7 @@
 * Remove deprecated Env::LoadEnv(). Use Env::CreateFromString() instead.
 * Remove deprecated FileSystem::Load(). Use FileSystem::CreateFromString() instead.
 * Removed the deprecated version of these utility functions and the corresponding Java bindings: `LoadOptionsFromFile`, `LoadLatestOptions`, `CheckOptionsCompatibility`.
+* Remove the FactoryFunc from the LoadObject method from the Customizable helper methods.
 
 ### Public API Changes
 * Moved rarely-needed Cache class definition to new advanced_cache.h, and added a CacheWrapper class to advanced_cache.h. Minor changes to SimCache API definitions.
index 8b02354f658578e07258ad2949785810e489b5c6..68536856645b58cd37a4d87e9c8b8408ec122a08 100644 (file)
@@ -87,8 +87,7 @@ Status SecondaryCache::CreateFromString(
     }
     return status;
   } else {
-    return LoadSharedObject<SecondaryCache>(config_options, value, nullptr,
-                                            result);
+    return LoadSharedObject<SecondaryCache>(config_options, value, result);
   }
 }
 
index 1067191d5300dff9c3d3259b944e57b3f92e00ad..2f4d879357247f8252f1fd5b97e3b8c9160cf163 100644 (file)
@@ -78,7 +78,6 @@ Status SstPartitionerFactory::CreateFromString(
   std::call_once(once, [&]() {
     RegisterSstPartitionerFactories(*(ObjectLibrary::Default().get()), "");
   });
-  return LoadSharedObject<SstPartitionerFactory>(options, value, nullptr,
-                                                 result);
+  return LoadSharedObject<SstPartitionerFactory>(options, value, result);
 }
 }  // namespace ROCKSDB_NAMESPACE
index 0a53f4a1afe3050563e372e3f46466287a0a7880..4360144ece458d15550003084278f3269148a34a 100644 (file)
@@ -13,7 +13,7 @@ namespace ROCKSDB_NAMESPACE {
 Status EventListener::CreateFromString(const ConfigOptions& config_options,
                                        const std::string& id,
                                        std::shared_ptr<EventListener>* result) {
-  return LoadSharedObject<EventListener>(config_options, id, nullptr, result);
+  return LoadSharedObject<EventListener>(config_options, id, result);
 }
 
 namespace {
index f673ac57dc4d34cc8e8daa2bcaa74b8ac937c521..2137738c7b7f0f142d882b72ca93ad2bdbd9047b 100644 (file)
@@ -641,7 +641,7 @@ Status Env::CreateFromString(const ConfigOptions& config_options,
   } else {
     RegisterSystemEnvs();
     Env* env = *result;
-    Status s = LoadStaticObject<Env>(config_options, value, nullptr, &env);
+    Status s = LoadStaticObject<Env>(config_options, value, &env);
     if (s.ok()) {
       *result = env;
     }
@@ -1227,8 +1227,7 @@ Status SystemClock::CreateFromString(const ConfigOptions& config_options,
     std::call_once(once, [&]() {
       RegisterBuiltinSystemClocks(*(ObjectLibrary::Default().get()), "");
     });
-    return LoadSharedObject<SystemClock>(config_options, value, nullptr,
-                                         result);
+    return LoadSharedObject<SystemClock>(config_options, value, result);
   }
 }
 }  // namespace ROCKSDB_NAMESPACE
index 602c4be09cb9c9d3023cfb53cdc3124caa0dc5d4..beb31a9cf997c4fda168b163db97a8df6d1d6129 100644 (file)
@@ -1332,15 +1332,14 @@ Status BlockCipher::CreateFromString(const ConfigOptions& config_options,
                                      const std::string& value,
                                      std::shared_ptr<BlockCipher>* result) {
   RegisterEncryptionBuiltins();
-  return LoadSharedObject<BlockCipher>(config_options, value, nullptr, result);
+  return LoadSharedObject<BlockCipher>(config_options, value, result);
 }
 
 Status EncryptionProvider::CreateFromString(
     const ConfigOptions& config_options, const std::string& value,
     std::shared_ptr<EncryptionProvider>* result) {
   RegisterEncryptionBuiltins();
-  return LoadSharedObject<EncryptionProvider>(config_options, value, nullptr,
-                                              result);
+  return LoadSharedObject<EncryptionProvider>(config_options, value, result);
 }
 
 
index f166fd8a00b1ad4897822110ab1e0799d0530657..71fb4d5bc74cb54baa84aa468e1670d885bbf831 100644 (file)
@@ -91,7 +91,7 @@ Status FileSystem::CreateFromString(const ConfigOptions& config_options,
     std::call_once(once, [&]() {
       RegisterBuiltinFileSystems(*(ObjectLibrary::Default().get()), "");
     });
-    return LoadSharedObject<FileSystem>(config_options, value, nullptr, result);
+    return LoadSharedObject<FileSystem>(config_options, value, result);
   }
 }
 
index b530eba6e5af6b7ecbbca00bb297b0ead48a862d..adf25405407937649eb0a1bafc79b583469a59b2 100644 (file)
@@ -13,7 +13,6 @@
 // for more information on how to develop and use customizable objects
 
 #pragma once
-#include <functional>
 #include <memory>
 #include <unordered_map>
 
 #include "rocksdb/utilities/object_registry.h"
 
 namespace ROCKSDB_NAMESPACE {
-// The FactoryFunc functions are used to create a new customizable object
-// without going through the ObjectRegistry.  This methodology is especially
-// useful in LITE mode, where there is no ObjectRegistry.  The methods take
-// in an ID of the object to create and a pointer to store the created object.
-// If the factory successfully recognized the input ID, the method should return
-// success; otherwise false should be returned.  On success, the object
-// parameter contains the new object.
-template <typename T>
-using SharedFactoryFunc =
-    std::function<bool(const std::string&, std::shared_ptr<T>*)>;
-
-template <typename T>
-using UniqueFactoryFunc =
-    std::function<bool(const std::string&, std::unique_ptr<T>*)>;
-
-template <typename T>
-using StaticFactoryFunc = std::function<bool(const std::string&, T**)>;
-
 // Creates a new shared customizable instance object based on the
 // input parameters using the object registry.
 //
@@ -156,12 +137,10 @@ static Status NewManagedObject(
 // handled
 // @param value Either the simple name of the instance to create, or a set of
 // name-value pairs to create and initailize the object
-// @param func  Optional function to call to attempt to create an instance
 // @param result The newly created instance.
 template <typename T>
 static Status LoadSharedObject(const ConfigOptions& config_options,
                                const std::string& value,
-                               const SharedFactoryFunc<T>& func,
                                std::shared_ptr<T>* result) {
   std::string id;
   std::unordered_map<std::string, std::string> opt_map;
@@ -170,12 +149,8 @@ static Status LoadSharedObject(const ConfigOptions& config_options,
                                               value, &id, &opt_map);
   if (!status.ok()) {  // GetOptionsMap failed
     return status;
-  } else if (func == nullptr ||
-             !func(id, result)) {  // No factory, or it failed
-    return NewSharedObject(config_options, id, opt_map, result);
   } else {
-    return Customizable::ConfigureNewObject(config_options, result->get(),
-                                            opt_map);
+    return NewSharedObject(config_options, id, opt_map, result);
   }
 }
 
@@ -204,7 +179,6 @@ static Status LoadSharedObject(const ConfigOptions& config_options,
 // handled
 // @param value Either the simple name of the instance to create, or a set of
 // name-value pairs to create and initailize the object
-// @param func  Optional function to call to attempt to create an instance
 // @param result The newly created instance.
 template <typename T>
 static Status LoadManagedObject(const ConfigOptions& config_options,
@@ -270,12 +244,10 @@ static Status NewUniqueObject(
 // handled
 // @param value Either the simple name of the instance to create, or a set of
 // name-value pairs to create and initailize the object
-// @param func  Optional function to call to attempt to create an instance
 // @param result The newly created instance.
 template <typename T>
 static Status LoadUniqueObject(const ConfigOptions& config_options,
                                const std::string& value,
-                               const UniqueFactoryFunc<T>& func,
                                std::unique_ptr<T>* result) {
   std::string id;
   std::unordered_map<std::string, std::string> opt_map;
@@ -283,12 +255,8 @@ static Status LoadUniqueObject(const ConfigOptions& config_options,
                                               value, &id, &opt_map);
   if (!status.ok()) {  // GetOptionsMap failed
     return status;
-  } else if (func == nullptr ||
-             !func(id, result)) {  // No factory, or it failed
-    return NewUniqueObject(config_options, id, opt_map, result);
   } else {
-    return Customizable::ConfigureNewObject(config_options, result->get(),
-                                            opt_map);
+    return NewUniqueObject(config_options, id, opt_map, result);
   }
 }
 
@@ -337,23 +305,18 @@ static Status NewStaticObject(
 // handled
 // @param value Either the simple name of the instance to create, or a set of
 // name-value pairs to create and initailize the object
-// @param func  Optional function to call to attempt to create an instance
 // @param result The newly created instance.
 template <typename T>
 static Status LoadStaticObject(const ConfigOptions& config_options,
-                               const std::string& value,
-                               const StaticFactoryFunc<T>& func, T** result) {
+                               const std::string& value, T** result) {
   std::string id;
   std::unordered_map<std::string, std::string> opt_map;
   Status status = Customizable::GetOptionsMap(config_options, *result, value,
                                               &id, &opt_map);
   if (!status.ok()) {  // GetOptionsMap failed
     return status;
-  } else if (func == nullptr ||
-             !func(id, result)) {  // No factory, or it failed
-    return NewStaticObject(config_options, id, opt_map, result);
   } else {
-    return Customizable::ConfigureNewObject(config_options, *result, opt_map);
+    return NewStaticObject(config_options, id, opt_map, result);
   }
 }
 }  // namespace ROCKSDB_NAMESPACE
index 4864a07ac5bf78c13934a8bb8acfc4ef35ef2936..f6dd616514f00016ac2c3cdfc6ef0fb0d813f97b 100644 (file)
@@ -300,7 +300,7 @@ Status Statistics::CreateFromString(const ConfigOptions& config_options,
   } else if (id == kNullptrString) {
     result->reset();
   } else {
-    s = LoadSharedObject<Statistics>(config_options, id, nullptr, result);
+    s = LoadSharedObject<Statistics>(config_options, id, result);
   }
   return s;
 }
index 4de5bfaefe22689c2e825b5df31a368c2888c799..2f4f34ee948a8276898860635d4850c0b6f310ee 100644 (file)
@@ -160,19 +160,6 @@ class BCustomizable : public TestCustomizable {
   BOptions opts_;
 };
 
-static bool LoadSharedB(const std::string& id,
-                        std::shared_ptr<TestCustomizable>* result) {
-  if (id == "B") {
-    result->reset(new BCustomizable(id));
-    return true;
-  } else if (id.empty()) {
-    result->reset();
-    return true;
-  } else {
-    return false;
-  }
-}
-
 static int A_count = 0;
 static int RegisterCustomTestObjects(ObjectLibrary& library,
                                      const std::string& /*arg*/) {
@@ -184,6 +171,12 @@ static int RegisterCustomTestObjects(ObjectLibrary& library,
         A_count++;
         return guard->get();
       });
+  library.AddFactory<TestCustomizable>(
+      "B", [](const std::string& name, std::unique_ptr<TestCustomizable>* guard,
+              std::string* /* msg */) {
+        guard->reset(new BCustomizable(name));
+        return guard->get();
+      });
 
   library.AddFactory<TestCustomizable>(
       "S", [](const std::string& name,
@@ -252,46 +245,19 @@ static void GetMapFromProperties(
 Status TestCustomizable::CreateFromString(
     const ConfigOptions& config_options, const std::string& value,
     std::shared_ptr<TestCustomizable>* result) {
-  return LoadSharedObject<TestCustomizable>(config_options, value, LoadSharedB,
-                                            result);
+  return LoadSharedObject<TestCustomizable>(config_options, value, result);
 }
 
 Status TestCustomizable::CreateFromString(
     const ConfigOptions& config_options, const std::string& value,
     std::unique_ptr<TestCustomizable>* result) {
-  return LoadUniqueObject<TestCustomizable>(
-      config_options, value,
-      [](const std::string& id, std::unique_ptr<TestCustomizable>* u) {
-        if (id == "B") {
-          u->reset(new BCustomizable(id));
-          return true;
-        } else if (id.empty()) {
-          u->reset();
-          return true;
-        } else {
-          return false;
-        }
-      },
-      result);
+  return LoadUniqueObject<TestCustomizable>(config_options, value, result);
 }
 
 Status TestCustomizable::CreateFromString(const ConfigOptions& config_options,
                                           const std::string& value,
                                           TestCustomizable** result) {
-  return LoadStaticObject<TestCustomizable>(
-      config_options, value,
-      [](const std::string& id, TestCustomizable** ptr) {
-        if (id == "B") {
-          *ptr = new BCustomizable(id);
-          return true;
-        } else if (id.empty()) {
-          *ptr = nullptr;
-          return true;
-        } else {
-          return false;
-        }
-      },
-      result);
+  return LoadStaticObject<TestCustomizable>(config_options, value, result);
 }
 
 class CustomizableTest : public testing::Test {
@@ -980,70 +946,34 @@ TEST_F(CustomizableTest, IgnoreUnknownObjects) {
   std::unique_ptr<TestCustomizable> unique;
   TestCustomizable* pointer = nullptr;
   ignore.ignore_unsupported_options = false;
-  ASSERT_NOK(
-      LoadSharedObject<TestCustomizable>(ignore, "Unknown", nullptr, &shared));
-  ASSERT_NOK(
-      LoadUniqueObject<TestCustomizable>(ignore, "Unknown", nullptr, &unique));
-  ASSERT_NOK(
-      LoadStaticObject<TestCustomizable>(ignore, "Unknown", nullptr, &pointer));
+  ASSERT_NOK(LoadSharedObject<TestCustomizable>(ignore, "Unknown", &shared));
+  ASSERT_NOK(LoadUniqueObject<TestCustomizable>(ignore, "Unknown", &unique));
+  ASSERT_NOK(LoadStaticObject<TestCustomizable>(ignore, "Unknown", &pointer));
   ASSERT_EQ(shared.get(), nullptr);
   ASSERT_EQ(unique.get(), nullptr);
   ASSERT_EQ(pointer, nullptr);
   ignore.ignore_unsupported_options = true;
-  ASSERT_OK(
-      LoadSharedObject<TestCustomizable>(ignore, "Unknown", nullptr, &shared));
-  ASSERT_OK(
-      LoadUniqueObject<TestCustomizable>(ignore, "Unknown", nullptr, &unique));
-  ASSERT_OK(
-      LoadStaticObject<TestCustomizable>(ignore, "Unknown", nullptr, &pointer));
+  ASSERT_OK(LoadSharedObject<TestCustomizable>(ignore, "Unknown", &shared));
+  ASSERT_OK(LoadUniqueObject<TestCustomizable>(ignore, "Unknown", &unique));
+  ASSERT_OK(LoadStaticObject<TestCustomizable>(ignore, "Unknown", &pointer));
   ASSERT_EQ(shared.get(), nullptr);
   ASSERT_EQ(unique.get(), nullptr);
   ASSERT_EQ(pointer, nullptr);
-  ASSERT_OK(LoadSharedObject<TestCustomizable>(ignore, "id=Unknown", nullptr,
-                                               &shared));
-  ASSERT_OK(LoadUniqueObject<TestCustomizable>(ignore, "id=Unknown", nullptr,
-                                               &unique));
-  ASSERT_OK(LoadStaticObject<TestCustomizable>(ignore, "id=Unknown", nullptr,
-                                               &pointer));
+  ASSERT_OK(LoadSharedObject<TestCustomizable>(ignore, "id=Unknown", &shared));
+  ASSERT_OK(LoadUniqueObject<TestCustomizable>(ignore, "id=Unknown", &unique));
+  ASSERT_OK(LoadStaticObject<TestCustomizable>(ignore, "id=Unknown", &pointer));
   ASSERT_EQ(shared.get(), nullptr);
   ASSERT_EQ(unique.get(), nullptr);
   ASSERT_EQ(pointer, nullptr);
   ASSERT_OK(LoadSharedObject<TestCustomizable>(ignore, "id=Unknown;option=bad",
-                                               nullptr, &shared));
+                                               &shared));
   ASSERT_OK(LoadUniqueObject<TestCustomizable>(ignore, "id=Unknown;option=bad",
-                                               nullptr, &unique));
+                                               &unique));
   ASSERT_OK(LoadStaticObject<TestCustomizable>(ignore, "id=Unknown;option=bad",
-                                               nullptr, &pointer));
-  ASSERT_EQ(shared.get(), nullptr);
-  ASSERT_EQ(unique.get(), nullptr);
-  ASSERT_EQ(pointer, nullptr);
-}
-
-TEST_F(CustomizableTest, FactoryFunctionTest) {
-  std::shared_ptr<TestCustomizable> shared;
-  std::unique_ptr<TestCustomizable> unique;
-  TestCustomizable* pointer = nullptr;
-  ConfigOptions ignore = config_options_;
-  ignore.ignore_unsupported_options = false;
-  ASSERT_OK(TestCustomizable::CreateFromString(ignore, "B", &shared));
-  ASSERT_OK(TestCustomizable::CreateFromString(ignore, "B", &unique));
-  ASSERT_OK(TestCustomizable::CreateFromString(ignore, "B", &pointer));
-  ASSERT_NE(shared.get(), nullptr);
-  ASSERT_NE(unique.get(), nullptr);
-  ASSERT_NE(pointer, nullptr);
-  delete pointer;
-  pointer = nullptr;
-  ASSERT_OK(TestCustomizable::CreateFromString(ignore, "id=", &shared));
-  ASSERT_OK(TestCustomizable::CreateFromString(ignore, "id=", &unique));
-  ASSERT_OK(TestCustomizable::CreateFromString(ignore, "id=", &pointer));
+                                               &pointer));
   ASSERT_EQ(shared.get(), nullptr);
   ASSERT_EQ(unique.get(), nullptr);
   ASSERT_EQ(pointer, nullptr);
-  ASSERT_NOK(TestCustomizable::CreateFromString(ignore, "option=bad", &shared));
-  ASSERT_NOK(TestCustomizable::CreateFromString(ignore, "option=bad", &unique));
-  ASSERT_NOK(
-      TestCustomizable::CreateFromString(ignore, "option=bad", &pointer));
-  ASSERT_EQ(pointer, nullptr);
 }
 
 TEST_F(CustomizableTest, URLFactoryTest) {
index 76fe85b1ada6edc2bee18e59f1be7c58cd6ddfbf..baac21e21483be0fc2ef94abc2f2b42ab604655b 100644 (file)
@@ -110,16 +110,6 @@ static int RegisterFlushBlockPolicyFactories(ObjectLibrary& library,
   return 2;
 }
 
-static bool LoadFlushPolicyFactory(
-    const std::string& id, std::shared_ptr<FlushBlockPolicyFactory>* result) {
-  if (id.empty()) {
-    result->reset(new FlushBlockBySizePolicyFactory());
-  } else {
-    return false;
-  }
-  return true;
-}
-
 FlushBlockBySizePolicyFactory::FlushBlockBySizePolicyFactory()
     : FlushBlockPolicyFactory() {}
 
@@ -130,7 +120,13 @@ Status FlushBlockPolicyFactory::CreateFromString(
   std::call_once(once, [&]() {
     RegisterFlushBlockPolicyFactories(*(ObjectLibrary::Default().get()), "");
   });
-  return LoadSharedObject<FlushBlockPolicyFactory>(
-      config_options, value, LoadFlushPolicyFactory, factory);
+
+  if (value.empty()) {
+    factory->reset(new FlushBlockBySizePolicyFactory());
+    return Status::OK();
+  } else {
+    return LoadSharedObject<FlushBlockPolicyFactory>(config_options, value,
+                                                     factory);
+  }
 }
 }  // namespace ROCKSDB_NAMESPACE
index ef44fe38250cd3592de634307f6a4fe624b7c736..29b6c89f81c517879aacc3fe03d765947e25350c 100644 (file)
@@ -43,21 +43,10 @@ static void RegisterTableFactories(const std::string& /*arg*/) {
   });
 }
 
-static bool LoadFactory(const std::string& name,
-                        std::shared_ptr<TableFactory>* factory) {
-  if (name == TableFactory::kBlockBasedTableName()) {
-    factory->reset(new BlockBasedTableFactory());
-    return true;
-  } else {
-    return false;
-  }
-}
-
 Status TableFactory::CreateFromString(const ConfigOptions& config_options,
                                       const std::string& value,
                                       std::shared_ptr<TableFactory>* factory) {
   RegisterTableFactories("");
-  return LoadSharedObject<TableFactory>(config_options, value, LoadFactory,
-                                        factory);
+  return LoadSharedObject<TableFactory>(config_options, value, factory);
 }
 }  // namespace ROCKSDB_NAMESPACE
index b35d3abb9153c56560c4162ffabc89ec306ecc59..0c072e1e328059028ededb450321b373580b7968 100644 (file)
@@ -160,8 +160,7 @@ Status FileChecksumGenFactory::CreateFromString(
     *result = GetFileChecksumGenCrc32cFactory();
     return Status::OK();
   } else {
-    Status s = LoadSharedObject<FileChecksumGenFactory>(options, value, nullptr,
-                                                        result);
+    Status s = LoadSharedObject<FileChecksumGenFactory>(options, value, result);
     return s;
   }
 }
index cb14c48d9ad6d69f0960c58bda19bc9e13c42952..999f723651f08bf483851f511f737c02230e920f 100644 (file)
@@ -32,8 +32,8 @@ Status CompactionFilter::CreateFromString(const ConfigOptions& config_options,
     RegisterBuiltinCompactionFilters(*(ObjectLibrary::Default().get()), "");
   });
   CompactionFilter* filter = const_cast<CompactionFilter*>(*result);
-  Status status = LoadStaticObject<CompactionFilter>(config_options, value,
-                                                     nullptr, &filter);
+  Status status =
+      LoadStaticObject<CompactionFilter>(config_options, value, &filter);
   if (status.ok()) {
     *result = const_cast<CompactionFilter*>(filter);
   }
@@ -45,8 +45,8 @@ Status CompactionFilterFactory::CreateFromString(
     std::shared_ptr<CompactionFilterFactory>* result) {
   // Currently there are no builtin CompactionFilterFactories.
   // If any are introduced, they need to be registered here.
-  Status status = LoadSharedObject<CompactionFilterFactory>(
-      config_options, value, nullptr, result);
+  Status status =
+      LoadSharedObject<CompactionFilterFactory>(config_options, value, result);
   return status;
 }
 }  // namespace ROCKSDB_NAMESPACE
index 16e361ed4fc9efde21b73d29b384055d269860fb..020064d0924ae84a67729273a2e0b07069f439bf 100644 (file)
 #include "rocksdb/utilities/customizable_util.h"
 #include "rocksdb/utilities/object_registry.h"
 #include "utilities/merge_operators/bytesxor.h"
+#include "utilities/merge_operators/max_operator.h"
+#include "utilities/merge_operators/put_operator.h"
 #include "utilities/merge_operators/sortlist.h"
 #include "utilities/merge_operators/string_append/stringappend.h"
 #include "utilities/merge_operators/string_append/stringappend2.h"
+#include "utilities/merge_operators/uint64add.h"
 
 namespace ROCKSDB_NAMESPACE {
-static bool LoadMergeOperator(const std::string& id,
-                              std::shared_ptr<MergeOperator>* result) {
-  bool success = true;
-  // TODO: Hook the "name" up to the actual Name() of the MergeOperators?
-  // Requires these classes be moved into a header file...
-  if (id == "put" || id == "PutOperator") {
-    *result = MergeOperators::CreatePutOperator();
-  } else if (id == "put_v1") {
-    *result = MergeOperators::CreateDeprecatedPutOperator();
-  } else if (id == "uint64add" || id == "UInt64AddOperator") {
-    *result = MergeOperators::CreateUInt64AddOperator();
-  } else if (id == "max" || id == "MaxOperator") {
-    *result = MergeOperators::CreateMaxOperator();
-  } else {
-    success = false;
-  }
-  return success;
-}
-
 static int RegisterBuiltinMergeOperators(ObjectLibrary& library,
                                          const std::string& /*arg*/) {
   size_t num_types;
@@ -71,6 +55,37 @@ static int RegisterBuiltinMergeOperators(ObjectLibrary& library,
         guard->reset(new BytesXOROperator());
         return guard->get();
       });
+  library.AddFactory<MergeOperator>(
+      ObjectLibrary::PatternEntry(UInt64AddOperator::kClassName())
+          .AnotherName(UInt64AddOperator::kNickName()),
+      [](const std::string& /*uri*/, std::unique_ptr<MergeOperator>* guard,
+         std::string* /*errmsg*/) {
+        guard->reset(new UInt64AddOperator());
+        return guard->get();
+      });
+  library.AddFactory<MergeOperator>(
+      ObjectLibrary::PatternEntry(MaxOperator::kClassName())
+          .AnotherName(MaxOperator::kNickName()),
+      [](const std::string& /*uri*/, std::unique_ptr<MergeOperator>* guard,
+         std::string* /*errmsg*/) {
+        guard->reset(new MaxOperator());
+        return guard->get();
+      });
+  library.AddFactory<MergeOperator>(
+      ObjectLibrary::PatternEntry(PutOperatorV2::kClassName())
+          .AnotherName(PutOperatorV2::kNickName()),
+      [](const std::string& /*uri*/, std::unique_ptr<MergeOperator>* guard,
+         std::string* /*errmsg*/) {
+        guard->reset(new PutOperatorV2());
+        return guard->get();
+      });
+  library.AddFactory<MergeOperator>(
+      ObjectLibrary::PatternEntry(PutOperator::kNickName()),
+      [](const std::string& /*uri*/, std::unique_ptr<MergeOperator>* guard,
+         std::string* /*errmsg*/) {
+        guard->reset(new PutOperator());
+        return guard->get();
+      });
 
   return static_cast<int>(library.GetFactoryCount(&num_types));
 }
@@ -82,8 +97,7 @@ Status MergeOperator::CreateFromString(const ConfigOptions& config_options,
   std::call_once(once, [&]() {
     RegisterBuiltinMergeOperators(*(ObjectLibrary::Default().get()), "");
   });
-  return LoadSharedObject<MergeOperator>(config_options, value,
-                                         LoadMergeOperator, result);
+  return LoadSharedObject<MergeOperator>(config_options, value, result);
 }
 
 std::shared_ptr<MergeOperator> MergeOperators::CreateFromStringId(
index de4abfa6fa7d28a5ba321ebb979a1c92511562aa..ff854cca347c3ce10b7fe81e96055346fae2e7f8 100644 (file)
@@ -8,71 +8,55 @@
 #include "rocksdb/merge_operator.h"
 #include "rocksdb/slice.h"
 #include "utilities/merge_operators.h"
+#include "utilities/merge_operators/max_operator.h"
 
-using ROCKSDB_NAMESPACE::Logger;
-using ROCKSDB_NAMESPACE::MergeOperator;
-using ROCKSDB_NAMESPACE::Slice;
-
-namespace {  // anonymous namespace
-
-// Merge operator that picks the maximum operand, Comparison is based on
-// Slice::compare
-class MaxOperator : public MergeOperator {
- public:
-  bool FullMergeV2(const MergeOperationInput& merge_in,
-                   MergeOperationOutput* merge_out) const override {
-    Slice& max = merge_out->existing_operand;
-    if (merge_in.existing_value) {
-      max = Slice(merge_in.existing_value->data(),
-                  merge_in.existing_value->size());
-    } else if (max.data() == nullptr) {
-      max = Slice();
-    }
-
-    for (const auto& op : merge_in.operand_list) {
-      if (max.compare(op) < 0) {
-        max = op;
-      }
-    }
+namespace ROCKSDB_NAMESPACE {
 
-    return true;
+bool MaxOperator::FullMergeV2(const MergeOperationInput& merge_in,
+                              MergeOperationOutput* merge_out) const {
+  Slice& max = merge_out->existing_operand;
+  if (merge_in.existing_value) {
+    max =
+        Slice(merge_in.existing_value->data(), merge_in.existing_value->size());
+  } else if (max.data() == nullptr) {
+    max = Slice();
   }
 
-  bool PartialMerge(const Slice& /*key*/, const Slice& left_operand,
-                    const Slice& right_operand, std::string* new_value,
-                    Logger* /*logger*/) const override {
-    if (left_operand.compare(right_operand) >= 0) {
-      new_value->assign(left_operand.data(), left_operand.size());
-    } else {
-      new_value->assign(right_operand.data(), right_operand.size());
+  for (const auto& op : merge_in.operand_list) {
+    if (max.compare(op) < 0) {
+      max = op;
     }
-    return true;
   }
 
-  bool PartialMergeMulti(const Slice& /*key*/,
-                         const std::deque<Slice>& operand_list,
-                         std::string* new_value,
-                         Logger* /*logger*/) const override {
-    Slice max;
-    for (const auto& operand : operand_list) {
-      if (max.compare(operand) < 0) {
-        max = operand;
-      }
-    }
+  return true;
+}
 
-    new_value->assign(max.data(), max.size());
-    return true;
+bool MaxOperator::PartialMerge(const Slice& /*key*/, const Slice& left_operand,
+                               const Slice& right_operand,
+                               std::string* new_value,
+                               Logger* /*logger*/) const {
+  if (left_operand.compare(right_operand) >= 0) {
+    new_value->assign(left_operand.data(), left_operand.size());
+  } else {
+    new_value->assign(right_operand.data(), right_operand.size());
   }
+  return true;
+}
 
-  static const char* kClassName() { return "MaxOperator"; }
-  static const char* kNickName() { return "max"; }
-  const char* Name() const override { return kClassName(); }
-  const char* NickName() const override { return kNickName(); }
-};
-
-}  // end of anonymous namespace
+bool MaxOperator::PartialMergeMulti(const Slice& /*key*/,
+                                    const std::deque<Slice>& operand_list,
+                                    std::string* new_value,
+                                    Logger* /*logger*/) const {
+  Slice max;
+  for (const auto& operand : operand_list) {
+    if (max.compare(operand) < 0) {
+      max = operand;
+    }
+  }
 
-namespace ROCKSDB_NAMESPACE {
+  new_value->assign(max.data(), max.size());
+  return true;
+}
 
 std::shared_ptr<MergeOperator> MergeOperators::CreateMaxOperator() {
   return std::make_shared<MaxOperator>();
diff --git a/utilities/merge_operators/max_operator.h b/utilities/merge_operators/max_operator.h
new file mode 100644 (file)
index 0000000..4c8e98d
--- /dev/null
@@ -0,0 +1,35 @@
+//  Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
+//  This source code is licensed under both the GPLv2 (found in the
+//  COPYING file in the root directory) and Apache 2.0 License
+//  (found in the LICENSE.Apache file in the root directory).
+//
+// Merge operator that picks the maximum operand, Comparison is based on
+// Slice::compare
+
+#pragma once
+
+#include "rocksdb/merge_operator.h"
+
+namespace ROCKSDB_NAMESPACE {
+class Logger;
+class Slice;
+
+class MaxOperator : public MergeOperator {
+ public:
+  static const char* kClassName() { return "MaxOperator"; }
+  static const char* kNickName() { return "max"; }
+  const char* Name() const override { return kClassName(); }
+  const char* NickName() const override { return kNickName(); }
+
+  bool FullMergeV2(const MergeOperationInput& merge_in,
+                   MergeOperationOutput* merge_out) const override;
+  bool PartialMerge(const Slice& /*key*/, const Slice& left_operand,
+                    const Slice& right_operand, std::string* new_value,
+                    Logger* /*logger*/) const override;
+  bool PartialMergeMulti(const Slice& /*key*/,
+                         const std::deque<Slice>& operand_list,
+                         std::string* new_value,
+                         Logger* /*logger*/) const override;
+};
+
+}  // namespace ROCKSDB_NAMESPACE
index ccf9ff21f19089babe89aa9eb7d2b0aae707c25c..79468c6b787980492c1dfc6ff79f4ac7bc88d58b 100644 (file)
@@ -8,12 +8,9 @@
 #include "rocksdb/merge_operator.h"
 #include "rocksdb/slice.h"
 #include "utilities/merge_operators.h"
+#include "utilities/merge_operators/put_operator.h"
 
-namespace {  // anonymous namespace
-
-using ROCKSDB_NAMESPACE::Logger;
-using ROCKSDB_NAMESPACE::MergeOperator;
-using ROCKSDB_NAMESPACE::Slice;
+namespace ROCKSDB_NAMESPACE {
 
 // A merge operator that mimics Put semantics
 // Since this merge-operator will not be used in production,
@@ -23,64 +20,49 @@ using ROCKSDB_NAMESPACE::Slice;
 // which would be simpler in this case).
 //
 // From the client-perspective, semantics are the same.
-class PutOperator : public MergeOperator {
- public:
-  bool FullMerge(const Slice& /*key*/, const Slice* /*existing_value*/,
-                 const std::deque<std::string>& operand_sequence,
-                 std::string* new_value, Logger* /*logger*/) const override {
-    // Put basically only looks at the current/latest value
-    assert(!operand_sequence.empty());
-    assert(new_value != nullptr);
-    new_value->assign(operand_sequence.back());
-    return true;
-  }
-
-  bool PartialMerge(const Slice& /*key*/, const Slice& /*left_operand*/,
-                    const Slice& right_operand, std::string* new_value,
-                    Logger* /*logger*/) const override {
-    new_value->assign(right_operand.data(), right_operand.size());
-    return true;
-  }
-
-  using MergeOperator::PartialMergeMulti;
-  bool PartialMergeMulti(const Slice& /*key*/,
-                         const std::deque<Slice>& operand_list,
-                         std::string* new_value,
-                         Logger* /*logger*/) const override {
-    new_value->assign(operand_list.back().data(), operand_list.back().size());
-    return true;
-  }
-
-  static const char* kClassName() { return "PutOperator"; }
-  static const char* kNickName() { return "put_v1"; }
-  const char* Name() const override { return kClassName(); }
-  const char* NickName() const override { return kNickName(); }
-};
-
-class PutOperatorV2 : public PutOperator {
-  bool FullMerge(const Slice& /*key*/, const Slice* /*existing_value*/,
-                 const std::deque<std::string>& /*operand_sequence*/,
-                 std::string* /*new_value*/,
-                 Logger* /*logger*/) const override {
-    assert(false);
-    return false;
-  }
+bool PutOperator::FullMerge(const Slice& /*key*/,
+                            const Slice* /*existing_value*/,
+                            const std::deque<std::string>& operand_sequence,
+                            std::string* new_value, Logger* /*logger*/) const {
+  // Put basically only looks at the current/latest value
+  assert(!operand_sequence.empty());
+  assert(new_value != nullptr);
+  new_value->assign(operand_sequence.back());
+  return true;
+}
 
-  bool FullMergeV2(const MergeOperationInput& merge_in,
-                   MergeOperationOutput* merge_out) const override {
-    // Put basically only looks at the current/latest value
-    assert(!merge_in.operand_list.empty());
-    merge_out->existing_operand = merge_in.operand_list.back();
-    return true;
-  }
+bool PutOperator::PartialMerge(const Slice& /*key*/,
+                               const Slice& /*left_operand*/,
+                               const Slice& right_operand,
+                               std::string* new_value,
+                               Logger* /*logger*/) const {
+  new_value->assign(right_operand.data(), right_operand.size());
+  return true;
+}
 
-  static const char* kNickName() { return "put"; }
-  const char* NickName() const override { return kNickName(); }
-};
+bool PutOperator::PartialMergeMulti(const Slice& /*key*/,
+                                    const std::deque<Slice>& operand_list,
+                                    std::string* new_value,
+                                    Logger* /*logger*/) const {
+  new_value->assign(operand_list.back().data(), operand_list.back().size());
+  return true;
+}
 
-}  // end of anonymous namespace
+bool PutOperatorV2::FullMerge(
+    const Slice& /*key*/, const Slice* /*existing_value*/,
+    const std::deque<std::string>& /*operand_sequence*/,
+    std::string* /*new_value*/, Logger* /*logger*/) const {
+  assert(false);
+  return false;
+}
 
-namespace ROCKSDB_NAMESPACE {
+bool PutOperatorV2::FullMergeV2(const MergeOperationInput& merge_in,
+                                MergeOperationOutput* merge_out) const {
+  // Put basically only looks at the current/latest value
+  assert(!merge_in.operand_list.empty());
+  merge_out->existing_operand = merge_in.operand_list.back();
+  return true;
+}
 
 std::shared_ptr<MergeOperator> MergeOperators::CreateDeprecatedPutOperator() {
   return std::make_shared<PutOperator>();
diff --git a/utilities/merge_operators/put_operator.h b/utilities/merge_operators/put_operator.h
new file mode 100644 (file)
index 0000000..7529da7
--- /dev/null
@@ -0,0 +1,56 @@
+//  Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
+//  This source code is licensed under both the GPLv2 (found in the
+//  COPYING file in the root directory) and Apache 2.0 License
+//  (found in the LICENSE.Apache file in the root directory).
+//
+// A merge operator that mimics Put semantics
+// Since this merge-operator will not be used in production,
+// it is implemented as a non-associative merge operator to illustrate the
+// new interface and for testing purposes. (That is, we inherit from
+// the MergeOperator class rather than the AssociativeMergeOperator
+// which would be simpler in this case).
+//
+// From the client-perspective, semantics are the same.
+
+#pragma once
+
+#include "rocksdb/merge_operator.h"
+
+namespace ROCKSDB_NAMESPACE {
+class Logger;
+class Slice;
+
+class PutOperator : public MergeOperator {
+ public:
+  static const char* kClassName() { return "PutOperator"; }
+  static const char* kNickName() { return "put_v1"; }
+  const char* Name() const override { return kClassName(); }
+  const char* NickName() const override { return kNickName(); }
+
+  bool FullMerge(const Slice& /*key*/, const Slice* /*existing_value*/,
+                 const std::deque<std::string>& operand_sequence,
+                 std::string* new_value, Logger* /*logger*/) const override;
+  bool PartialMerge(const Slice& /*key*/, const Slice& left_operand,
+                    const Slice& right_operand, std::string* new_value,
+                    Logger* /*logger*/) const override;
+  using MergeOperator::PartialMergeMulti;
+  bool PartialMergeMulti(const Slice& /*key*/,
+                         const std::deque<Slice>& operand_list,
+                         std::string* new_value,
+                         Logger* /*logger*/) const override;
+};
+
+class PutOperatorV2 : public PutOperator {
+ public:
+  static const char* kNickName() { return "put"; }
+  const char* NickName() const override { return kNickName(); }
+
+  bool FullMerge(const Slice& /*key*/, const Slice* /*existing_value*/,
+                 const std::deque<std::string>& /*operand_sequence*/,
+                 std::string* /*new_value*/, Logger* /*logger*/) const override;
+
+  bool FullMergeV2(const MergeOperationInput& merge_in,
+                   MergeOperationOutput* merge_out) const override;
+};
+
+}  // namespace ROCKSDB_NAMESPACE
index 5be2f56411a19d1745266a1aa6f666231b8af318..72957761b60a04c1bed9ba8046f9dad146f886d7 100644 (file)
@@ -3,6 +3,8 @@
 //  COPYING file in the root directory) and Apache 2.0 License
 //  (found in the LICENSE.Apache file in the root directory).
 
+#include "utilities/merge_operators/uint64add.h"
+
 #include <memory>
 
 #include "logging/logging.h"
 #include "util/coding.h"
 #include "utilities/merge_operators.h"
 
-namespace {  // anonymous namespace
-
-using ROCKSDB_NAMESPACE::AssociativeMergeOperator;
-using ROCKSDB_NAMESPACE::InfoLogLevel;
-using ROCKSDB_NAMESPACE::Logger;
-using ROCKSDB_NAMESPACE::Slice;
-
-// A 'model' merge operator with uint64 addition semantics
-// Implemented as an AssociativeMergeOperator for simplicity and example.
-class UInt64AddOperator : public AssociativeMergeOperator {
- public:
-  bool Merge(const Slice& /*key*/, const Slice* existing_value,
-             const Slice& value, std::string* new_value,
-             Logger* logger) const override {
-    uint64_t orig_value = 0;
-    if (existing_value) {
-      orig_value = DecodeInteger(*existing_value, logger);
-    }
-    uint64_t operand = DecodeInteger(value, logger);
-
-    assert(new_value);
-    new_value->clear();
-    ROCKSDB_NAMESPACE::PutFixed64(new_value, orig_value + operand);
+namespace ROCKSDB_NAMESPACE {  // anonymous namespace
 
-    return true;  // Return true always since corruption will be treated as 0
+bool UInt64AddOperator::Merge(const Slice& /*key*/, const Slice* existing_value,
+                              const Slice& value, std::string* new_value,
+                              Logger* logger) const {
+  uint64_t orig_value = 0;
+  if (existing_value) {
+    orig_value = DecodeInteger(*existing_value, logger);
   }
+  uint64_t operand = DecodeInteger(value, logger);
 
-  static const char* kClassName() { return "UInt64AddOperator"; }
-  static const char* kNickName() { return "uint64add"; }
-  const char* Name() const override { return kClassName(); }
-  const char* NickName() const override { return kNickName(); }
+  assert(new_value);
+  new_value->clear();
+  PutFixed64(new_value, orig_value + operand);
 
- private:
-  // Takes the string and decodes it into a uint64_t
-  // On error, prints a message and returns 0
-  uint64_t DecodeInteger(const Slice& value, Logger* logger) const {
-    uint64_t result = 0;
-
-    if (value.size() == sizeof(uint64_t)) {
-      result = ROCKSDB_NAMESPACE::DecodeFixed64(value.data());
-    } else if (logger != nullptr) {
-      // If value is corrupted, treat it as 0
-      ROCKS_LOG_ERROR(logger,
-                      "uint64 value corruption, size: %" ROCKSDB_PRIszt
-                      " > %" ROCKSDB_PRIszt,
-                      value.size(), sizeof(uint64_t));
-    }
+  return true;  // Return true always since corruption will be treated as 0
+}
 
-    return result;
+uint64_t UInt64AddOperator::DecodeInteger(const Slice& value,
+                                          Logger* logger) const {
+  uint64_t result = 0;
+
+  if (value.size() == sizeof(uint64_t)) {
+    result = DecodeFixed64(value.data());
+  } else if (logger != nullptr) {
+    // If value is corrupted, treat it as 0
+    ROCKS_LOG_ERROR(logger,
+                    "uint64 value corruption, size: %" ROCKSDB_PRIszt
+                    " > %" ROCKSDB_PRIszt,
+                    value.size(), sizeof(uint64_t));
   }
-};
 
-}  // anonymous namespace
-
-namespace ROCKSDB_NAMESPACE {
+  return result;
+}
 
 std::shared_ptr<MergeOperator> MergeOperators::CreateUInt64AddOperator() {
   return std::make_shared<UInt64AddOperator>();
diff --git a/utilities/merge_operators/uint64add.h b/utilities/merge_operators/uint64add.h
new file mode 100644 (file)
index 0000000..7e23267
--- /dev/null
@@ -0,0 +1,35 @@
+//  Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
+//  This source code is licensed under both the GPLv2 (found in the
+//  COPYING file in the root directory) and Apache 2.0 License
+//  (found in the LICENSE.Apache file in the root directory).
+//
+// A 'model' merge operator with uint64 addition semantics
+// Implemented as an AssociativeMergeOperator for simplicity and example.
+
+#pragma once
+
+#include "rocksdb/merge_operator.h"
+#include "utilities/merge_operators.h"
+
+namespace ROCKSDB_NAMESPACE {
+class Logger;
+class Slice;
+
+class UInt64AddOperator : public AssociativeMergeOperator {
+ public:
+  static const char* kClassName() { return "UInt64AddOperator"; }
+  static const char* kNickName() { return "uint64add"; }
+  const char* Name() const override { return kClassName(); }
+  const char* NickName() const override { return kNickName(); }
+
+  bool Merge(const Slice& /*key*/, const Slice* existing_value,
+             const Slice& value, std::string* new_value,
+             Logger* logger) const override;
+
+ private:
+  // Takes the string and decodes it into a uint64_t
+  // On error, prints a message and returns 0
+  uint64_t DecodeInteger(const Slice& value, Logger* logger) const;
+};
+
+}  // namespace ROCKSDB_NAMESPACE
index 95dea67edc31891a6d94570ea30574090b3fa6a5..a3b5189da03c54636b574ff7f7ff403300466004 100644 (file)
@@ -215,7 +215,7 @@ Status TablePropertiesCollectorFactory::CreateFromString(
                                               "");
   });
   return LoadSharedObject<TablePropertiesCollectorFactory>(options, value,
-                                                           nullptr, result);
+                                                           result);
 }
 
 }  // namespace ROCKSDB_NAMESPACE
index 98bba361003a3f3967f7af9a26eb93b849ae6f72..9fa36bf27221c41c54379d8130313e833937b33a 100644 (file)
@@ -15,8 +15,7 @@ namespace ROCKSDB_NAMESPACE {
 Status WalFilter::CreateFromString(const ConfigOptions& config_options,
                                    const std::string& value,
                                    WalFilter** filter) {
-  Status s =
-      LoadStaticObject<WalFilter>(config_options, value, nullptr, filter);
+  Status s = LoadStaticObject<WalFilter>(config_options, value, filter);
   return s;
 }