]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/ReplicatedPG: set whiteout in cache pool on delete
authorSage Weil <sage@inktank.com>
Wed, 23 Oct 2013 00:21:27 +0000 (17:21 -0700)
committerSage Weil <sage@inktank.com>
Sat, 14 Dec 2013 00:35:53 +0000 (16:35 -0800)
If we delete an object in the cache pool, set the whiteout flag instead of
removing the on-disk object.

Signed-off-by: Sage Weil <sage@inktank.com>
src/osd/ReplicatedPG.cc
src/test/librados/tier.cc

index c9656c935ac4feeefc1e1dc4c921509179473e7b..f761d50f2265e9447ca45ff8b853b3cadd8946ea 100644 (file)
@@ -3803,22 +3803,30 @@ inline int ReplicatedPG::_delete_head(OpContext *ctx)
   if (!obs.exists || obs.oi.is_whiteout())
     return -ENOENT;
   
-  t.remove(coll, soid);
-
   if (oi.size > 0) {
     interval_set<uint64_t> ch;
     ch.insert(0, oi.size);
     ctx->modified_ranges.union_of(ch);
   }
 
-  ctx->delta_stats.num_objects--;
+  ctx->delta_stats.num_wr++;
   ctx->delta_stats.num_bytes -= oi.size;
-
   oi.size = 0;
+
+  // cache: writeback: set whiteout on delete?
+  if (pool.info.cache_mode == pg_pool_t::CACHEMODE_WRITEBACK) {
+    dout(20) << __func__ << " setting whiteout on " << soid << dendl;
+    oi.set_flag(object_info_t::FLAG_WHITEOUT);
+    t.truncate(coll, soid, 0);
+    t.omap_clear(coll, soid);
+    t.rmattrs(coll, soid);
+    return 0;
+  }
+
+  t.remove(coll, soid);
+  ctx->delta_stats.num_objects--;
   snapset.head_exists = false;
   obs.exists = false;
-
-  ctx->delta_stats.num_wr++;
   return 0;
 }
 
index 70d4f0739a416638e79736d544594ece3e462128..2ca38600ed1035f776210a85166a474b1a2181ab 100644 (file)
@@ -173,6 +173,15 @@ TEST(LibRadosTier, Whiteout) {
   IoCtx base_ioctx;
   ASSERT_EQ(0, cluster.ioctx_create(base_pool_name.c_str(), base_ioctx));
 
+  // create object
+  {
+    bufferlist bl;
+    bl.append("hi there");
+    ObjectWriteOperation op;
+    op.write_full(bl);
+    ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+  }
+
   // configure cache
   bufferlist inbl;
   ASSERT_EQ(0, cluster.mon_command(
@@ -192,9 +201,9 @@ TEST(LibRadosTier, Whiteout) {
   cluster.wait_for_latest_osdmap();
 
   // create some whiteouts, verify they behave
-  ASSERT_EQ(-ENOENT, base_ioctx.remove("foo"));
+  ASSERT_EQ(0, base_ioctx.remove("foo"));
+
   ASSERT_EQ(-ENOENT, base_ioctx.remove("bar"));
-  ASSERT_EQ(-ENOENT, base_ioctx.remove("foo"));
   ASSERT_EQ(-ENOENT, base_ioctx.remove("bar"));
 
   // verify the whiteouts are there in the cache tier
@@ -208,6 +217,8 @@ TEST(LibRadosTier, Whiteout) {
     ASSERT_TRUE(it == cache_ioctx.objects_end());
   }
 
+  ASSERT_EQ(-ENOENT, base_ioctx.remove("foo"));
+
   // tear down tiers
   ASSERT_EQ(0, cluster.mon_command(
     "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + base_pool_name +