]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: Trim bilog with generation
authorAdam C. Emerson <aemerson@redhat.com>
Mon, 26 Apr 2021 22:45:09 +0000 (18:45 -0400)
committerAdam C. Emerson <aemerson@redhat.com>
Tue, 1 Feb 2022 19:58:29 +0000 (14:58 -0500)
From the REST interface and radosgw-admin. Assume Generation 0 if none
provided and error if it doesn't exist.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/rgw/rgw_admin.cc
src/rgw/rgw_reshard.cc
src/rgw/rgw_rest_log.cc
src/rgw/rgw_trim_bilog.cc
src/rgw/rgw_trim_bilog.h

index 58955204f9f4aa2e3fc6382a4f5863259d620da0..63fff18d6a896d6ee1b2533eb237f5624c6dc5ec 100644 (file)
@@ -9288,18 +9288,12 @@ next:
       return -ret;
     }
 
-    const auto& logs = bucket->get_info().layout.logs;
-    auto log_layout = std::reference_wrapper{logs.back()};
-    if (gen) {
-      auto i = std::find_if(logs.begin(), logs.end(), rgw::matches_gen(*gen));
-      if (i == logs.end()) {
-        cerr << "ERROR: no log layout with gen=" << *gen << std::endl;
-        return ENOENT;
-      }
-      log_layout = *i;
+    if (!gen) {
+      gen = 0;
     }
-
-    ret = static_cast<rgw::sal::RadosStore*>(store)->svc()->bilog_rados->log_trim(dpp(), bucket->get_info(), log_layout, shard_id, start_marker, end_marker);
+    ret = bilog_trim(dpp(), static_cast<rgw::sal::RadosStore*>(store),
+                    bucket->get_info(), *gen,
+                    shard_id, start_marker, end_marker);
     if (ret < 0) {
       cerr << "ERROR: trim_bi_log_entries(): " << cpp_strerror(-ret) << std::endl;
       return -ret;
index 672b4b9c8e2c15b425c25e68e9dfc88c53cff185..e4aacb44b6ea58a1b7e4ceda55e1634abb15f2fc 100644 (file)
@@ -11,6 +11,7 @@
 #include "rgw_sal_rados.h"
 #include "cls/rgw/cls_rgw_client.h"
 #include "cls/lock/cls_lock_client.h"
+#include "services/svc_bilog_rados.h"
 #include "common/errno.h"
 #include "common/ceph_json.h"
 
index 7f3302de8c88a504fc3066e50d39d35ec6f18f7f..764a1420dbb3d3cfda210ac834623c4371930c69 100644 (file)
@@ -576,11 +576,13 @@ void RGWOp_BILog_Info::send_response() {
 }
 
 void RGWOp_BILog_Delete::execute(optional_yield y) {
+  bool gen_specified = false;
   string tenant_name = s->info.args.get("tenant"),
          bucket_name = s->info.args.get("bucket"),
          start_marker = s->info.args.get("start-marker"),
          end_marker = s->info.args.get("end-marker"),
-         bucket_instance = s->info.args.get("bucket-instance");
+         bucket_instance = s->info.args.get("bucket-instance"),
+        gen_str = s->info.args.get("generation", &gen_specified);
 
   std::unique_ptr<rgw::sal::Bucket> bucket;
   rgw_bucket b(rgw_bucket_key(tenant_name, bucket_name));
@@ -588,11 +590,22 @@ void RGWOp_BILog_Delete::execute(optional_yield y) {
   op_ret = 0;
   if ((bucket_name.empty() && bucket_instance.empty()) ||
       end_marker.empty()) {
-    ldpp_dout(this, 5) << "ERROR: one of bucket and bucket instance, and also end-marker is mandatory" << dendl;
+    ldpp_dout(this, 5) << "ERROR: one of bucket or bucket instance, and also end-marker is mandatory" << dendl;
     op_ret = -EINVAL;
     return;
   }
 
+  string err;
+  uint64_t gen = 0;
+  if (gen_specified) {
+    gen = strict_strtoll(gen_str.c_str(), 10, &err);
+    if (!err.empty()) {
+      ldpp_dout(s, 5) << "Error parsing generation param " << gen_str << dendl;
+      op_ret = -EINVAL;
+      return;
+    }
+  }
+
   int shard_id;
   string bn;
   op_ret = rgw_bucket_parse_bucket_instance(bucket_instance, &bn, &bucket_instance, &shard_id);
@@ -610,23 +623,13 @@ void RGWOp_BILog_Delete::execute(optional_yield y) {
     return;
   }
 
-  const auto& logs = bucket->get_info().layout.logs;
-  auto log_layout = std::reference_wrapper{logs.back()};
-  auto gen = logs.back().gen; // TODO: remove this once gen is passed here
-  if (gen) {
-    auto i = std::find_if(logs.begin(), logs.end(), rgw::matches_gen(gen));
-    if (i == logs.end()) {
-      ldpp_dout(s, 5) << "ERROR: no log layout with gen=" << gen << dendl;
-      op_ret = -ENOENT;
-      return;
-    }
-    log_layout = *i;
-  }
-
-  op_ret = static_cast<rgw::sal::RadosStore*>(store)->svc()->bilog_rados->log_trim(s, bucket->get_info(), log_layout, shard_id, start_marker, end_marker);
+  op_ret = bilog_trim(this, static_cast<rgw::sal::RadosStore*>(store),
+                     bucket->get_info(), gen, shard_id,
+                     start_marker, end_marker);
   if (op_ret < 0) {
-    ldpp_dout(this, 5) << "ERROR: trim_bi_log_entries() " << dendl;
+    ldpp_dout(s, 5) << "bilog_trim failed with op_ret=" << op_ret << dendl;
   }
+
   return;
 }
 
index 7848d979dc331050b3ff0006010ce73280625ea1..71529b8aaa712fdd668800996a3a744b1e00f0c1 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "services/svc_zone.h"
 #include "services/svc_meta.h"
+#include "services/svc_bilog_rados.h"
 
 #include <boost/asio/yield.hpp>
 #include "include/ceph_assert.h"
@@ -1286,3 +1287,26 @@ std::ostream& BucketTrimManager::gen_prefix(std::ostream& out) const
 }
 
 } // namespace rgw
+
+int bilog_trim(const DoutPrefixProvider* p, rgw::sal::RadosStore* store,
+              RGWBucketInfo& bucket_info, uint64_t gen, int shard_id,
+              std::string_view start_marker, std::string_view end_marker)
+{
+  auto& logs = bucket_info.layout.logs;
+  auto log = std::find_if(logs.begin(), logs.end(), rgw::matches_gen(gen));
+  if (log == logs.end()) {
+    ldpp_dout(p, 5) << __PRETTY_FUNCTION__ << ":" << __LINE__
+                   << "ERROR: no log layout with gen=" << gen << dendl;
+    return -ENOENT;
+  }
+
+  auto log_layout = *log;
+
+  auto r = static_cast<rgw::sal::RadosStore*>(store)->svc()->bilog_rados
+    ->log_trim(p, bucket_info, log_layout, shard_id, start_marker, end_marker);
+  if (r < 0) {
+    ldpp_dout(p, 5) << __PRETTY_FUNCTION__ << ":" << __LINE__
+                   << "ERROR: bilog_rados->log_trim returned r=" << r << dendl;
+  }
+  return r;
+}
index 28652c95ba1d0512125dc7d2edd841d1a6a2251b..f4432eec9faa0fb27f25b0d305c68dbc94bd6cba 100644 (file)
@@ -24,6 +24,7 @@
 #include "include/encoding.h"
 #include "common/ceph_time.h"
 #include "common/dout.h"
+#include "rgw/rgw_common.h"
 
 class RGWCoroutine;
 class RGWHTTPManager;
@@ -116,4 +117,8 @@ struct BucketTrimStatus {
 
 WRITE_CLASS_ENCODER(rgw::BucketTrimStatus);
 
+int bilog_trim(const DoutPrefixProvider* p, rgw::sal::RadosStore* store,
+              RGWBucketInfo& bucket_info, uint64_t gen, int shard_id,
+              std::string_view start_marker, std::string_view end_marker);
+
 #endif // RGW_SYNC_LOG_TRIM_H