From fabc6ba161b068e143d5d6db1c2d4c741766a8ba Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 22 Oct 2013 17:21:27 -0700 Subject: [PATCH] osd/ReplicatedPG: set whiteout in cache pool on delete 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 --- src/osd/ReplicatedPG.cc | 20 ++++++++++++++------ src/test/librados/tier.cc | 15 +++++++++++++-- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/osd/ReplicatedPG.cc b/src/osd/ReplicatedPG.cc index c9656c935ac4f..f761d50f2265e 100644 --- a/src/osd/ReplicatedPG.cc +++ b/src/osd/ReplicatedPG.cc @@ -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 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; } diff --git a/src/test/librados/tier.cc b/src/test/librados/tier.cc index 70d4f0739a416..2ca38600ed103 100644 --- a/src/test/librados/tier.cc +++ b/src/test/librados/tier.cc @@ -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 + -- 2.39.5