]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: Use refactored log backing tools
authorAdam C. Emerson <aemerson@redhat.com>
Sat, 21 Nov 2020 20:45:12 +0000 (15:45 -0500)
committerAdam C. Emerson <aemerson@redhat.com>
Mon, 29 Mar 2021 16:25:58 +0000 (12:25 -0400)
Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/common/options.cc
src/rgw/rgw_datalog.cc
src/rgw/rgw_datalog.h

index 56186d4385dfa9f85f12ce5ff1ccf6092ab16b1f..13d70e37db7f72ae2fb477500c58ecf1525327a0 100644 (file)
@@ -7409,17 +7409,15 @@ std::vector<Option> get_rgw_options() {
     .add_see_also("rgw_dmclock_metadata_res")
     .add_see_also("rgw_dmclock_metadata_wgt"),
 
-   Option("rgw_data_log_backing", Option::TYPE_STR, Option::LEVEL_ADVANCED)
-    .set_default("auto")
-    .set_enum_allowed( { "auto", "fifo", "omap" } )
-    .set_description("Backing store for the RGW data sync log")
+   Option("rgw_default_data_log_backing", Option::TYPE_STR, Option::LEVEL_ADVANCED)
+    .set_default("fifo")
+    .set_enum_allowed( { "fifo", "omap" } )
+    .set_description("Default backing store for the RGW data sync log")
     .set_long_description(
         "Whether to use the older OMAP backing store or the high performance "
-       "FIFO based backing store. Auto uses whatever already exists "
-       "but will default to FIFO if there isn't an existing log. Either of "
-       "the explicit options will cause startup to fail if the other log is "
-       "still around."),
-   
+       "FIFO based backing store by default. This only covers the creation of "
+       "the log on startup if none exists."),
+
    Option("rgw_luarocks_location", Option::TYPE_STR, Option::LEVEL_ADVANCED)
      .set_flag(Option::FLAG_STARTUP)
 #ifdef WITH_RADOSGW_LUA_PACKAGES
index 6af1ff8084ac14caf881909fc197e2a464867a46..900f73814eeac1cead828d206fde4160461bd5e6 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "cls_fifo_legacy.h"
 #include "rgw_datalog.h"
+#include "rgw_log_backing.h"
 #include "rgw_tools.h"
 
 #define dout_context g_ceph_context
@@ -67,38 +68,6 @@ void rgw_data_change_log_entry::decode_json(JSONObj *obj) {
   JSONDecoder::decode_json("entry", entry, obj);
 }
 
-int RGWDataChangesBE::remove(CephContext* cct, librados::Rados* rados,
-                            const rgw_pool& log_pool)
-{
-  auto num_shards = cct->_conf->rgw_data_log_num_shards;
-  librados::IoCtx ioctx;
-  auto r = rgw_init_ioctx(rados, log_pool.name, ioctx,
-                         false, false);
-  if (r < 0) {
-    if (r == -ENOENT) {
-      return 0;
-    } else {
-      lderr(cct) << __PRETTY_FUNCTION__
-                << ": rgw_init_ioctx failed: " << log_pool.name
-                << ": " << cpp_strerror(-r) << dendl;
-      return r;
-    }
-  }
-  for (auto i = 0; i < num_shards; ++i) {
-    auto oid = get_oid(cct, i);
-    librados::ObjectWriteOperation op;
-    op.remove();
-    auto r = rgw_rados_operate(ioctx, oid, &op, null_yield);
-    if (r < 0 && r != -ENOENT) {
-      lderr(cct) << __PRETTY_FUNCTION__
-                << ": remove failed: " << log_pool.name << "/" << oid
-                << ": " << cpp_strerror(-r) << dendl;
-    }
-  }
-  return 0;
-}
-
-
 class RGWDataChangesOmap final : public RGWDataChangesBE {
   using centries = std::list<cls_log_entry>;
   RGWSI_Cls& cls;
@@ -113,44 +82,6 @@ public:
     }
   }
   ~RGWDataChangesOmap() override = default;
-  static int exists(CephContext* cct, RGWSI_Cls& cls, bool* exists,
-                   bool* has_entries) {
-    auto num_shards = cct->_conf->rgw_data_log_num_shards;
-    std::string out_marker;
-    bool truncated = false;
-    std::list<cls_log_entry> log_entries;
-    const cls_log_header empty_info;
-    *exists = false;
-    *has_entries = false;
-    for (auto i = 0; i < num_shards; ++i) {
-      cls_log_header info;
-      auto oid = get_oid(cct, i);
-      auto r = cls.timelog.info(oid, &info, null_yield);
-      if (r < 0 && r != -ENOENT) {
-       lderr(cct) << __PRETTY_FUNCTION__
-                  << ": failed to get info " << oid << ": " << cpp_strerror(-r)
-                  << dendl;
-       return r;
-      } else if ((r == -ENOENT) || (info == empty_info)) {
-       continue;
-      }
-      *exists = true;
-      r = cls.timelog.list(oid, {}, {}, 100, log_entries, "", &out_marker,
-                          &truncated, null_yield);
-      if (r < 0) {
-       lderr(cct) << __PRETTY_FUNCTION__
-                  << ": failed to list " << oid << ": " << cpp_strerror(-r)
-                  << dendl;
-       return r;
-      } else if (!log_entries.empty()) {
-       *has_entries = true;
-       break; // No reason to continue, once we have both existence
-              // AND non-emptiness
-      }
-    }
-    return 0;
-  }
-
   void prepare(ceph::real_time ut, const std::string& key,
               ceph::buffer::list&& entry, entries& out) override {
     if (!std::holds_alternative<centries>(out)) {
@@ -294,54 +225,6 @@ public:
                             }));
   }
   ~RGWDataChangesFIFO() override = default;
-  static int exists(CephContext* cct, librados::Rados* rados,
-                   const rgw_pool& log_pool, bool* exists, bool* has_entries) {
-    auto num_shards = cct->_conf->rgw_data_log_num_shards;
-    librados::IoCtx ioctx;
-    auto r = rgw_init_ioctx(rados, log_pool.name, ioctx,
-                           false, false);
-    if (r < 0) {
-      if (r == -ENOENT) {
-       return 0;
-      } else {
-       lderr(cct) << __PRETTY_FUNCTION__
-                  << ": rgw_init_ioctx failed: " << log_pool.name
-                  << ": " << cpp_strerror(-r) << dendl;
-       return r;
-      }
-    }
-    *exists = false;
-    *has_entries = false;
-    for (auto i = 0; i < num_shards; ++i) {
-      std::unique_ptr<rgw::cls::fifo::FIFO> fifo;
-      auto oid = get_oid(cct, i);
-      std::vector<rgw::cls::fifo::list_entry> log_entries;
-      bool more = false;
-      auto r = rgw::cls::fifo::FIFO::open(ioctx, oid,
-                                         &fifo, null_yield,
-                                         std::nullopt, true);
-      if (r == -ENOENT || r == -ENODATA) {
-       continue;
-      } else if (r < 0) {
-       lderr(cct) << __PRETTY_FUNCTION__
-                  << ": unable to open FIFO: " << log_pool << "/" << oid
-                  << ": " << cpp_strerror(-r) << dendl;
-       return r;
-      }
-      *exists = true;
-      r = fifo->list(1, nullopt, &log_entries, &more,
-                    null_yield);
-      if (r < 0) {
-       lderr(cct) << __PRETTY_FUNCTION__
-                  << ": unable to list entries: " << log_pool << "/" << oid
-                  << ": " << cpp_strerror(-r) << dendl;
-      } else if (!log_entries.empty()) {
-       *has_entries = true;
-       break;
-      }
-    }
-    return 0;
-  }
   void prepare(ceph::real_time, const std::string&,
               ceph::buffer::list&& entry, entries& out) override {
     if (!std::holds_alternative<centries>(out)) {
@@ -490,83 +373,38 @@ int RGWDataChangesLog::start(const RGWZone* _zone,
                             RGWSI_Cls *cls, librados::Rados* lr)
 {
   zone = _zone;
-  assert(zone);
-  auto backing = cct->_conf.get_val<std::string>("rgw_data_log_backing");
+  ceph_assert(zone);
+  auto defbacking = to_log_type(
+    cct->_conf.get_val<std::string>("rgw_default_data_log_backing"));
   // Should be guaranteed by `set_enum_allowed`
-  ceph_assert(backing == "auto" || backing == "fifo" || backing == "omap");
+  ceph_assert(defbacking);
   auto log_pool = zoneparams.log_pool;
-  bool omapexists = false, omaphasentries = false;
-  auto r = RGWDataChangesOmap::exists(cct, *cls, &omapexists, &omaphasentries);
+  auto r = rgw_init_ioctx(lr, log_pool, ioctx, true, false);
   if (r < 0) {
     lderr(cct) << __PRETTY_FUNCTION__
-              << ": Error when checking for existing Omap datalog backend: "
-              << cpp_strerror(-r) << dendl;
+              << ": Failed to initialized ioctx, r=" << r
+              << ", pool=" << log_pool << dendl;
+    return -r;
   }
-  bool fifoexists = false, fifohasentries = false;
-  r = RGWDataChangesFIFO::exists(cct, lr, log_pool, &fifoexists, &fifohasentries);
-  if (r < 0) {
-    lderr(cct) << __PRETTY_FUNCTION__
-              << ": Error when checking for existing FIFO datalog backend: "
-              << cpp_strerror(-r) << dendl;
-  }
-  bool has_entries = omaphasentries || fifohasentries;
-  bool remove = false;
+  auto found = log_backing_type(ioctx, *defbacking, num_shards,
+                                  [this](int i) {
+                                    return RGWDataChangesBE::get_oid(cct, i);
+                                  },
+                                  null_yield);
 
-  if (omapexists && fifoexists) {
-    if (has_entries) {
-      lderr(cct) << __PRETTY_FUNCTION__
-                << ": Both Omap and FIFO backends exist, cannot continue."
-                << dendl;
-      return -EINVAL;
-    }
-    ldout(cct, 0)
-      << __PRETTY_FUNCTION__
-      << ": Both Omap and FIFO backends exist, but are empty. Will remove."
-      << dendl;
-    remove = true;
-  }
-  if (backing == "omap" && fifoexists) {
-    if (has_entries) {
-      lderr(cct) << __PRETTY_FUNCTION__
-                << ": Omap requested, but FIFO backend exists, cannot continue."
-                << dendl;
-      return -EINVAL;
-    }
-    ldout(cct, 0) << __PRETTY_FUNCTION__
-                 << ": Omap requested, FIFO exists, but is empty. Deleting."
-                 << dendl;
-    remove = true;
-  }
-  if (backing == "fifo" && omapexists) {
-    if (has_entries) {
-      lderr(cct) << __PRETTY_FUNCTION__
-                << ": FIFO requested, but Omap backend exists, cannot continue."
-                << dendl;
-      return -EINVAL;
-    }
-    ldout(cct, 0) << __PRETTY_FUNCTION__
-                 << ": FIFO requested, Omap exists, but is empty. Deleting."
-                 << dendl;
-    remove = true;
-  }
-
-  if (remove) {
-    r = RGWDataChangesBE::remove(cct, lr, log_pool);
-    if (r < 0) {
-      lderr(cct) << __PRETTY_FUNCTION__
-                << ": remove failed, cannot continue."
-                << dendl;
-      return r;
-    }
-    omapexists = false;
-    fifoexists = false;
+  if (!found) {
+    lderr(cct) << __PRETTY_FUNCTION__
+              << ": Error when checking log type: "
+              << found.error().message() << dendl;
   }
-
   try {
-    if (backing == "omap" || (backing == "auto" && omapexists)) {
+    switch (*found) {
+    case log_type::omap:
       be = std::make_unique<RGWDataChangesOmap>(cct, *cls);
-    } else if (backing != "omap") {
+      break;
+    case log_type::fifo:
       be = std::make_unique<RGWDataChangesFIFO>(cct, lr, log_pool);
+      break;
     }
   } catch (bs::system_error& e) {
     lderr(cct) << __PRETTY_FUNCTION__
index 1524a957ec2c827ed2ed0b9ae8c93668cdd228e5..1c9f8d837edaa2707ade51e3460b94d94c2c26d4 100644 (file)
@@ -142,10 +142,6 @@ public:
   std::string get_oid(int i) {
     return fmt::format("{}.{}", prefix, i);
   }
-  static int remove(CephContext* cct, librados::Rados* rados,
-                   const rgw_pool& log_pool);
-
-
   virtual void prepare(ceph::real_time now,
                       const std::string& key,
                       ceph::buffer::list&& entry,
@@ -167,6 +163,7 @@ public:
 
 class RGWDataChangesLog {
   CephContext *cct;
+  librados::IoCtx ioctx;
   rgw::BucketChangeObserver *observer = nullptr;
   const RGWZone* zone;
   std::unique_ptr<RGWDataChangesBE> be;