]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: some abstraction around log sync module
authorYehuda Sadeh <yehuda@redhat.com>
Tue, 16 Aug 2016 09:01:24 +0000 (02:01 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 7 Oct 2016 17:31:19 +0000 (10:31 -0700)
Moving code that fetches remote object meta to its own classes.

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_sync_module.cc

index 16c11450c910321b7d4a5c9ea8f72e2fe0818518..845238cd66c33e050f815a744c46861afbe077e6 100644 (file)
@@ -7,7 +7,8 @@
 
 #define dout_subsys ceph_subsys_rgw
 
-class RGWLogStatRemoteObjCR : public RGWCoroutine {
+class RGWStatRemoteObjCBCR : public RGWCoroutine {
+protected:
   RGWDataSyncEnv *sync_env;
 
   RGWBucketInfo bucket_info;
@@ -16,16 +17,41 @@ class RGWLogStatRemoteObjCR : public RGWCoroutine {
   ceph::real_time mtime;
   uint64_t size;
   map<string, bufferlist> attrs;
+public:
+  RGWStatRemoteObjCBCR(RGWDataSyncEnv *_sync_env,
+                       RGWBucketInfo& _bucket_info, rgw_obj_key& _key) : RGWCoroutine(_sync_env->cct),
+                                                          sync_env(_sync_env),
+                                                          bucket_info(_bucket_info), key(_key) {}
+  virtual ~RGWStatRemoteObjCBCR() {}
+
+  void set_result(ceph::real_time& _mtime,
+                  uint64_t _size,
+                  map<string, bufferlist>& _attrs) {
+    mtime = _mtime;
+    size = _size;
+    attrs = std::move(_attrs);
+  }
+};
 
+class RGWCallStatRemoteObjCR : public RGWCoroutine {
+  ceph::real_time mtime;
+  uint64_t size{0};
+  map<string, bufferlist> attrs;
+
+protected:
+  RGWDataSyncEnv *sync_env;
+
+  RGWBucketInfo bucket_info;
+  rgw_obj_key key;
 
 public:
-  RGWLogStatRemoteObjCR(RGWDataSyncEnv *_sync_env,
-                        RGWBucketInfo& _bucket_info, rgw_obj_key& _key) : RGWCoroutine(_sync_env->cct),
-                                                                          sync_env(_sync_env),
-                                                                          bucket_info(_bucket_info), key(_key) {
+  RGWCallStatRemoteObjCR(RGWDataSyncEnv *_sync_env,
+                     RGWBucketInfo& _bucket_info, rgw_obj_key& _key) : RGWCoroutine(_sync_env->cct),
+                                          sync_env(_sync_env),
+                                          bucket_info(_bucket_info), key(_key) {
   }
 
-  ~RGWLogStatRemoteObjCR() {}
+  virtual ~RGWCallStatRemoteObjCR() {}
 
   int operate() {
     reenter(this) {
@@ -38,13 +64,54 @@ public:
         ldout(sync_env->cct, 0) << "RGWStatRemoteObjCR() returned " << retcode << dendl;
         return set_cr_error(retcode);
       }
-      ldout(sync_env->cct, 0) << "stat of remote obj: z=" << sync_env->source_zone
+      ldout(sync_env->cct, 20) << "stat of remote obj: z=" << sync_env->source_zone
                               << " b=" << bucket_info.bucket << " k=" << key << " size=" << size << " mtime=" << mtime
                               << " attrs=" << attrs << dendl;
+      yield {
+        RGWStatRemoteObjCBCR *cb = allocate_callback();
+        if (cb) {
+          cb->set_result(mtime, size, attrs);
+          call(cb);
+        }
+      }
+      if (retcode < 0) {
+        ldout(sync_env->cct, 0) << "RGWStatRemoteObjCR() callback returned " << retcode << dendl;
+        return set_cr_error(retcode);
+      }
       return set_cr_done();
     }
     return 0;
   }
+
+  virtual RGWStatRemoteObjCBCR *allocate_callback() {
+    return nullptr;
+  }
+};
+
+class RGWLogStatRemoteObjCBCR : public RGWStatRemoteObjCBCR {
+public:
+  RGWLogStatRemoteObjCBCR(RGWDataSyncEnv *_sync_env,
+                          RGWBucketInfo& _bucket_info, rgw_obj_key& _key) : RGWStatRemoteObjCBCR(sync_env, bucket_info, key) {}
+  int operate() override {
+    ldout(sync_env->cct, 0) << "SYNC_LOG: stat of remote obj: z=" << sync_env->source_zone
+                            << " b=" << bucket_info.bucket << " k=" << key << " size=" << size << " mtime=" << mtime
+                            << " attrs=" << attrs << dendl;
+    return set_cr_done();
+  }
+
+};
+
+class RGWLogStatRemoteObjCR : public RGWCallStatRemoteObjCR {
+public:
+  RGWLogStatRemoteObjCR(RGWDataSyncEnv *_sync_env,
+                        RGWBucketInfo& _bucket_info, rgw_obj_key& _key) : RGWCallStatRemoteObjCR(_sync_env, _bucket_info, _key) {
+  }
+
+  ~RGWLogStatRemoteObjCR() {}
+
+  RGWStatRemoteObjCBCR *allocate_callback() override {
+    return new RGWLogStatRemoteObjCBCR(sync_env, bucket_info, key);
+  }
 };
 
 class RGWLogDataSyncModule : public RGWDataSyncModule {