]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: Add retry_raced_bucket_write
authorAdam C. Emerson <aemerson@redhat.com>
Fri, 17 Nov 2017 20:51:42 +0000 (15:51 -0500)
committerAdam C. Emerson <aemerson@redhat.com>
Mon, 27 Nov 2017 20:57:15 +0000 (15:57 -0500)
If the OSD informs us that our bucket info is out of date when we need
to write, we should have a way to update it.

This template function allows us to wrap relevant sections of code so
they'll be retried against new bucket info on -ECANCELED.

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

index 4003bea61ff9b5bda9f812221233757b17b108c3..d0404f77fa0dcf6029e85288ca21d8021c72682c 100644 (file)
@@ -630,6 +630,37 @@ void rgw_bucket_object_pre_exec(struct req_state *s)
   dump_bucket_from_state(s);
 }
 
+// So! Now and then when we try to update bucket information, the
+// bucket has changed during the course of the operation. (Or we have
+// a cache consistency problem that Watch/Notify isn't ruling out
+// completely.)
+//
+// When this happens, we need to update the bucket info and try
+// again. We have, however, to try the right *part* again.  We can't
+// simply re-send, since that will obliterate the previous update.
+//
+// Thus, callers of this function should include everything that
+// merges information to be changed into the bucket information as
+// well as the call to set it.
+//
+// The called function must return an integer, negative on error. In
+// general, they should just return op_ret.
+namespace {
+template<typename F>
+int retry_raced_bucket_write(RGWRados* g, req_state* s, const F& f) {
+  auto r = f();
+  for (auto i = 0u; i < 15u && r == -ECANCELED; ++i) {
+    r = g->try_refresh_bucket_info(s->bucket_info, nullptr,
+                                  &s->bucket_attrs);
+    if (r >= 0) {
+      r = f();
+    }
+  }
+  return r;
+}
+}
+
+
 int RGWGetObj::verify_permission()
 {
   obj = rgw_obj(s->bucket, s->object);
index 1cb44d2c48e0c7b5c06fcb0ea737a45763bd8c83..22fe2e7ffdb081476d62631afc6a1945f68917d4 100644 (file)
@@ -120,6 +120,7 @@ protected:
   int do_aws4_auth_completion();
 
   virtual int init_quota();
+
 public:
   RGWOp()
     : s(nullptr),