]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
librbd: introduce new context type at RO
authorshangdehao1 <dehao.shang@intel.com>
Thu, 18 Apr 2019 22:29:58 +0000 (06:29 +0800)
committerJason Dillaman <dillaman@redhat.com>
Mon, 24 Jun 2019 21:35:40 +0000 (17:35 -0400)
 - CacheGenContextURef is wrapper GenContextURef
 - use make_gen_lambda_context to create context.
 - smart pointer unique_ptr to auto release object.

Signed-off-by: Dehao Shang <dehao.shang@intel.com>
src/librbd/cache/SharedReadOnlyObjectDispatch.cc
src/test/immutable_object_cache/MockCacheDaemon.h
src/test/immutable_object_cache/test_DomainSocket.cc
src/test/immutable_object_cache/test_multi_session.cc
src/test/librbd/cache/test_mock_ParentImageCache.cc
src/tools/immutable_object_cache/CacheClient.cc
src/tools/immutable_object_cache/CacheClient.h
src/tools/immutable_object_cache/SocketCommon.h
src/tools/immutable_object_cache/Types.h

index d7887192b3d46070ed9b6b2eaf1d8bb784b3cc4e..c4b6ca6c5bf8504f86f20dca70caabc6f026d62f 100644 (file)
@@ -98,10 +98,10 @@ bool SharedReadOnlyObjectDispatch<I, C>::read(
     return true;
   }
 
-  auto ctx = new LambdaGenContext<std::function<void(ObjectCacheRequest*)>,
-      ObjectCacheRequest*>([this, snap_id, read_data, dispatch_result, on_dispatched,
+  CacheGenContextURef ctx = make_gen_lambda_context<ObjectCacheRequest*,
+                                     std::function<void(ObjectCacheRequest*)>>
+   ([this, snap_id, read_data, dispatch_result, on_dispatched,
       oid, object_off, object_len](ObjectCacheRequest* ack) {
-
     if (ack->type == RBDSC_READ_REPLY) {
       std::string file_path = ((ObjectCacheReadReplyData*)ack)->cache_path;
       ceph_assert(file_path != "");
@@ -118,7 +118,7 @@ bool SharedReadOnlyObjectDispatch<I, C>::read(
 
     m_cache_client->lookup_object(m_image_ctx->data_ctx.get_namespace(),
                                   m_image_ctx->data_ctx.get_id(),
-                                  (uint64_t)snap_id, oid, ctx);
+                                  (uint64_t)snap_id, oid, std::move(ctx));
   }
   return true;
 }
index b5c934e244802ce19b8d453120b85a12f985b667..c189dd127de477d5769becc8cdc467efee9a7cb5 100644 (file)
@@ -23,10 +23,14 @@ class MockCacheClient {
   MOCK_METHOD0(close, void());
   MOCK_METHOD0(stop, void());
   MOCK_METHOD0(connect, int());
-  MOCK_METHOD5(lookup_object, void(std::string pool_nspace,
+  void lookup_object(std::string pool_nspace, uint64_t pool_id, uint64_t snap_id,
+              std::string oid, CacheGenContextURef&& on_finish) {
+    // gmock don't support move
+    internal_lookup(pool_nspace, pool_id, snap_id, oid);
+  };
+  MOCK_METHOD4(internal_lookup, void(std::string pool_nspace,
                 uint64_t pool_id, uint64_t snap_id, 
-                std::string oid,
-                GenContext<ObjectCacheRequest*>* on_finish));
+                std::string oid));
   MOCK_METHOD1(register_client, int(Context*));
 };
 
index dd9ad3bfd53e8d54db44a329dafb267f6b2735b5..89a0fa6c4493ac31908a3ab86c2834472b1719dc 100644 (file)
@@ -106,8 +106,8 @@ public:
     m_send_request_index.store(0);
     m_recv_ack_index.store(0);
     for (uint64_t index = 0; index < times; index++) {
-      auto ctx = new LambdaGenContext<std::function<void(ObjectCacheRequest*)>,
-       ObjectCacheRequest*>([this, thinking, times](ObjectCacheRequest* ack){
+      auto ctx = make_gen_lambda_context<ObjectCacheRequest*, std::function<void(ObjectCacheRequest*)>>
+       ([this, thinking, times](ObjectCacheRequest* ack){
          if (thinking != 0) {
            usleep(thinking); // handling message
          }
@@ -122,7 +122,7 @@ public:
         usleep(1);
       }
 
-      m_cache_client->lookup_object("pool_nspace", 1, 2, "object_name", ctx);
+      m_cache_client->lookup_object("pool_nspace", 1, 2, "object_name", std::move(ctx));
       m_send_request_index++;
     }
     m_wait_event.wait();
@@ -130,12 +130,14 @@ public:
 
   bool startup_lookupobject_testing(std::string pool_nspace, std::string object_id) {
     bool hit;
-    auto ctx = new LambdaGenContext<std::function<void(ObjectCacheRequest*)>,
-        ObjectCacheRequest*>([this, &hit](ObjectCacheRequest* ack){
+    //auto ctx = new LambdaGenContext<std::function<void(ObjectCacheRequest*)>,
+    //    ObjectCacheRequest*>([this, &hit](ObjectCacheRequest* ack){
+    auto ctx = make_gen_lambda_context<ObjectCacheRequest*, std::function<void(ObjectCacheRequest*)>>
+       ([this, &hit](ObjectCacheRequest* ack){
        hit = ack->type == RBDSC_READ_REPLY;
        m_wait_event.signal();
     });
-    m_cache_client->lookup_object(pool_nspace, 1, 2, object_id, ctx);
+    m_cache_client->lookup_object(pool_nspace, 1, 2, object_id, std::move(ctx));
     m_wait_event.wait();
     return hit;
   }
index cdbb17fb16b60607a25094e9602a8bf6bb7d9a13..f00e5149ef652dc449142fbaf0ba834806da6527 100644 (file)
@@ -120,13 +120,13 @@ public:
                           uint64_t request_num, bool is_last) {
 
     for (uint64_t i = 0; i < request_num; i++) {
-      auto ctx = new LambdaGenContext<std::function<void(ObjectCacheRequest*)>,
-        ObjectCacheRequest*>([this](ObjectCacheRequest* ack) {
+      auto ctx = make_gen_lambda_context<ObjectCacheRequest*,
+            std::function<void(ObjectCacheRequest*)>>([this](ObjectCacheRequest* ack) {
         m_recv_ack_index++;
       });
       m_send_request_index++;
       // here just for concurrently testing register + lookup, so fix object id.
-      m_cache_client_vec[index]->lookup_object(pool_nspace, 1, 2, "1234", ctx);
+      m_cache_client_vec[index]->lookup_object(pool_nspace, 1, 2, "1234", std::move(ctx));
     }
 
     if (is_last) {
index 1566bc5a1544ed866de07230c1d4e41f67d0765f..f26383cabafa5c90100ae7f0c5ccc067cb4870d1 100644 (file)
@@ -78,12 +78,12 @@ class TestMockParentImageCache : public TestMockFixture {
 
   void expect_cache_lookup_object(MockParentImageCache& mparent_image_cache,
                                   Context* on_finish) {
-    auto& expect = EXPECT_CALL(*(mparent_image_cache.m_cache_client), lookup_object(
-                     _, _, _, _, _));
+    auto& expect = EXPECT_CALL(*(mparent_image_cache.m_cache_client),
+                               internal_lookup(_, _, _, _));
 
-     expect.WillOnce(WithArg<4>(Invoke([on_finish](GenContext<ObjectCacheRequest*>* ctx) {
-        on_finish->complete(0);
-      })));
+     expect.WillOnce(WithArg<3>(Invoke([on_finish](std::string oid) {
+       on_finish->complete(0);
+     })));
   }
 
   void expect_cache_close(MockParentImageCache& mparent_image_cache, int ret_val) {
index 02606b81e0cfd931f06e33de4d180471207190de..fa533029efa92210e101efea60c9ce3a329410e0 100644 (file)
@@ -86,11 +86,11 @@ namespace immutable_obj_cache {
 
   void CacheClient::lookup_object(std::string pool_nspace, uint64_t pool_id,
                                   uint64_t snap_id, std::string oid,
-                                  GenContext<ObjectCacheRequest*>* on_finish) {
+                                  CacheGenContextURef&& on_finish) {
     ObjectCacheRequest* req = new ObjectCacheReadData(RBDSC_READ,
                                     ++m_sequence_id, 0, 0,
                                     pool_id, snap_id, oid, pool_nspace);
-    req->process_msg = on_finish;
+    req->process_msg = std::move(on_finish);
     req->encode();
 
     {
@@ -250,8 +250,8 @@ namespace immutable_obj_cache {
          // dedicated thrad to execute this context.
        }
        current_request->process_msg->complete(reply);
-       delete current_request;
-       delete reply;
+       //delete current_request;
+       //delete reply;
     });
 
     if (m_worker_thread_num != 0) {
index 54a35dec761b5ead3eecacc67e16afee0a65b0d6..f4003cc518ede2cc583c296833622ec75025a007 100644 (file)
@@ -33,7 +33,7 @@ class CacheClient {
   int connect();
   void lookup_object(std::string pool_nspace, uint64_t pool_id,
                      uint64_t snap_id, std::string oid,
-                     GenContext<ObjectCacheRequest*>* on_finish);
+                     CacheGenContextURef&& on_finish);
   int register_client(Context* on_finish);
 
  private:
index 341550a5ff309b90c893c065044dff7e67ec29db..99acf360904126a592d88ad76a20a22dd4135846 100644 (file)
@@ -22,6 +22,8 @@ static const int ASIO_ERROR_MSG_INCOMPLETE = 0X05;
 class ObjectCacheRequest;
 class CacheSession;
 
+typedef GenContextURef<ObjectCacheRequest*> CacheGenContextURef;
+
 typedef std::function<void(CacheSession*, ObjectCacheRequest*)> ProcessMsg;
 
 }  // namespace immutable_obj_cache
index d08cdfedcf8e58abeddb706fd5c5401442ec82df..30324d5e898d10a669094269c612003e952226bc 100644 (file)
@@ -35,7 +35,7 @@ class ObjectCacheRequest {
 
   bufferlist payload;
 
-  GenContext<ObjectCacheRequest*>* process_msg;
+  CacheGenContextURef process_msg;
 
   ObjectCacheRequest();
   ObjectCacheRequest(uint16_t type, uint64_t seq);