From 08bb1ca320896cdeccecf24d12fb59a1f7710d73 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 21 Mar 2016 14:04:50 -0400 Subject: [PATCH] ceph_test_objectstore: add AppendWalVsTailCache test This specifically exercises a WAL overwrite racing with a subsequent append that uses the previous writes cached tail. We need to make sure the use of the cached_tail waits for the previous WAL write or else our update of tail block will be overwritten with the prior (WAL) value. Signed-off-by: Sage Weil --- src/test/objectstore/store_test.cc | 76 ++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/src/test/objectstore/store_test.cc b/src/test/objectstore/store_test.cc index 4d88561a1a4a2..59dc408124062 100644 --- a/src/test/objectstore/store_test.cc +++ b/src/test/objectstore/store_test.cc @@ -647,6 +647,82 @@ TEST_P(StoreTest, SmallSkipFront) { } } +TEST_P(StoreTest, AppendWalVsTailCache) { + ObjectStore::Sequencer osr("test"); + int r; + coll_t cid; + ghobject_t a(hobject_t(sobject_t("fooo", CEPH_NOSNAP))); + { + ObjectStore::Transaction t; + t.create_collection(cid, 0); + cerr << "Creating collection " << cid << std::endl; + r = store->apply_transaction(&osr, std::move(t)); + ASSERT_EQ(r, 0); + } + unsigned min_alloc = g_conf->bluestore_min_alloc_size; + g_conf->set_val("bluestore_inject_wal_apply_delay", "1.0"); + g_ceph_context->_conf->apply_changes(NULL); + unsigned size = min_alloc / 3; + bufferptr bpa(size); + memset(bpa.c_str(), 1, bpa.length()); + bufferlist bla; + bla.append(bpa); + { + ObjectStore::Transaction t; + t.write(cid, a, 0, bla.length(), bla, 0); + r = store->apply_transaction(&osr, std::move(t)); + ASSERT_EQ(r, 0); + } + + // force cached tail to clear ... + { + store->umount(); + int r = store->mount(); + ASSERT_EQ(0, r); + } + + bufferptr bpb(size); + memset(bpb.c_str(), 2, bpb.length()); + bufferlist blb; + blb.append(bpb); + { + ObjectStore::Transaction t; + t.write(cid, a, bla.length(), blb.length(), blb, 0); + r = store->apply_transaction(&osr, std::move(t)); + ASSERT_EQ(r, 0); + } + bufferptr bpc(size); + memset(bpc.c_str(), 3, bpc.length()); + bufferlist blc; + blc.append(bpc); + { + ObjectStore::Transaction t; + t.write(cid, a, bla.length() + blb.length(), blc.length(), blc, 0); + r = store->apply_transaction(&osr, std::move(t)); + ASSERT_EQ(r, 0); + } + bufferlist final; + final.append(bla); + final.append(blb); + final.append(blc); + bufferlist actual; + { + ASSERT_EQ((int)final.length(), + store->read(cid, a, 0, final.length(), actual)); + ASSERT_TRUE(final.contents_equal(actual)); + } + { + ObjectStore::Transaction t; + t.remove(cid, a); + t.remove_collection(cid); + cerr << "Cleaning" << std::endl; + r = store->apply_transaction(&osr, std::move(t)); + ASSERT_EQ(r, 0); + } + g_conf->set_val("bluestore_inject_wal_apply_delay", "0"); + g_ceph_context->_conf->apply_changes(NULL); +} + TEST_P(StoreTest, SmallSequentialUnaligned) { ObjectStore::Sequencer osr("test"); int r; -- 2.39.5