]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd:reads larger than cache size hang. 6031/head
authorLu Shi <shi.lu@h3c.com>
Thu, 24 Sep 2015 08:02:41 +0000 (16:02 +0800)
committerLu Shi <shi.lu@h3c.com>
Thu, 24 Sep 2015 08:06:52 +0000 (16:06 +0800)
Fixes:#13164

Signed-off-by: Lu Shi <shi.lu@h3c.com>
src/osdc/ObjectCacher.cc
src/test/librbd/test_librbd.cc

index daff1052020bef0ca87f2407943acc52e2ca5b3a..d1f80209c79448acfc80af3ab83016c18b2a31b6 100644 (file)
@@ -1163,7 +1163,7 @@ int ObjectCacher::_readx(OSDRead *rd, ObjectSet *oset, Context *onfinish,
        uint64_t rx_bytes = static_cast<uint64_t>(
          stat_rx + bh_it->second->length());
         bytes_not_in_cache += bh_it->second->length();
-       if (!waitfor_read.empty() || rx_bytes > max_size) {
+       if (!waitfor_read.empty() || (stat_rx > 0 && rx_bytes > max_size)) {
          // cache is full with concurrent reads -- wait for rx's to complete
          // to constrain memory growth (especially during copy-ups)
          if (success) {
index 99d272a0d3d3404ec9b1e16f1f7e3a74b80b4cef..5dc5c66da471bca12c0c8afa2cc14187361baa56 100644 (file)
@@ -2570,7 +2570,7 @@ TEST_F(TestLibRBD, LargeCacheRead)
   rados_ioctx_t ioctx;
   rados_ioctx_create(_cluster, m_pool_name.c_str(), &ioctx);
 
-  uint32_t new_cache_size = 16777216;
+  uint32_t new_cache_size = 1 << 20;
   std::string orig_cache_size;
   ASSERT_EQ(0, _rados.conf_get("rbd_cache_size", orig_cache_size));
   ASSERT_EQ(0, _rados.conf_set("rbd_cache_size",
@@ -2582,24 +2582,22 @@ TEST_F(TestLibRBD, LargeCacheRead)
   } BOOST_SCOPE_EXIT_END;
 
   rbd_image_t image;
-  int order = 0;
-  const char *name = "testimg";
-  uint64_t size = new_cache_size + 1;
+  int order = 21;
+  std::string name = get_temp_image_name();
+  uint64_t size = 1 << order;
 
-  ASSERT_EQ(0, create_image(ioctx, name, size, &order));
-  ASSERT_EQ(0, rbd_open(ioctx, name, &image, NULL));
+  ASSERT_EQ(0, create_image(ioctx, name.c_str(), size, &order));
+  ASSERT_EQ(0, rbd_open(ioctx, name.c_str(), &image, NULL));
 
   std::string buffer(1 << order, '1');
-  for (size_t offs = 0; offs < size; offs += buffer.size()) {
-    size_t len = std::min<uint64_t>(buffer.size(), size - offs);
-    ASSERT_EQ(static_cast<ssize_t>(len),
-             rbd_write(image, offs, len, buffer.c_str()));
-  }
+  ASSERT_EQ(static_cast<ssize_t>(buffer.size()),
+           rbd_write(image, 0, buffer.size(), buffer.c_str()));
 
   ASSERT_EQ(0, rbd_invalidate_cache(image));
 
-  buffer.resize(size);
-  ASSERT_EQ(static_cast<ssize_t>(size-1024), rbd_read(image, 1024, size, &buffer[0]));
+  ASSERT_EQ(static_cast<ssize_t>(buffer.size()), 
+           rbd_read(image, 0, buffer.size(), &buffer[0]));
 
   ASSERT_EQ(0, rbd_close(image));