From f3a78e046d54260de01a4d1db8e104130e35cf42 Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Fri, 11 Mar 2016 17:02:15 -0800 Subject: [PATCH] store_test: improve synthetic coverage of the ec stash case Signed-off-by: Samuel Just --- src/test/objectstore/store_test.cc | 74 ++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/src/test/objectstore/store_test.cc b/src/test/objectstore/store_test.cc index f438056a05987..97e1f859fa486 100644 --- a/src/test/objectstore/store_test.cc +++ b/src/test/objectstore/store_test.cc @@ -1776,6 +1776,39 @@ public: } }; + class C_SyntheticOnStash : public Context { + public: + SyntheticWorkloadState *state; + ObjectStore::Transaction *t; + ghobject_t oid, noid; + + C_SyntheticOnStash(SyntheticWorkloadState *state, + ObjectStore::Transaction *t, ghobject_t oid, + ghobject_t noid) + : state(state), t(t), oid(oid), noid(noid) {} + + void finish(int r) { + Mutex::Locker locker(state->lock); + EnterExit ee("clone finish"); + ASSERT_TRUE(state->in_flight_objects.count(oid)); + ASSERT_EQ(r, 0); + state->in_flight_objects.erase(oid); + if (state->contents.count(noid)) + state->available_objects.insert(noid); + --(state->in_flight); + bufferlist r2; + r = state->store->read( + state->cid, noid, 0, + state->contents[noid].data.length(), r2); + if (!state->contents[noid].data.contents_equal(r2)) { + dump_bl_mismatch(state->contents[noid].data, r2); + assert(0 == " mismatch after clone"); + ASSERT_TRUE(state->contents[noid].data.contents_equal(r2)); + } + state->cond.Signal(); + } + }; + class C_SyntheticOnClone : public Context { public: SyntheticWorkloadState *state; @@ -1908,6 +1941,43 @@ public: return status; } + int stash() { + Mutex::Locker locker(lock); + EnterExit ee("stash"); + if (!can_unlink()) + return -ENOENT; + if (!can_create()) + return -ENOSPC; + wait_for_ready(); + + ghobject_t old_obj; + int max = 20; + do { + old_obj = get_uniform_random_object(); + } while (--max && !contents[old_obj].data.length()); + available_objects.erase(old_obj); + ghobject_t new_obj = old_obj; + new_obj.generation++; + available_objects.erase(new_obj); + + ObjectStore::Transaction *t = new ObjectStore::Transaction; + t->collection_move_rename(cid, old_obj, cid, new_obj); + ++in_flight; + in_flight_objects.insert(old_obj); + + // *copy* the data buffer, since we may modify it later. + contents[new_obj].attrs = contents[old_obj].attrs; + contents[new_obj].data.clear(); + contents[new_obj].data.append(contents[old_obj].data.c_str(), + contents[old_obj].data.length()); + contents.erase(old_obj); + int status = store->queue_transaction( + osr, std::move(*t), + new C_SyntheticOnStash(this, t, old_obj, new_obj)); + delete t; + return status; + } + int clone() { Mutex::Locker locker(lock); EnterExit ee("clone"); @@ -2392,6 +2462,8 @@ TEST_P(StoreTest, Synthetic) { test_obj.write(); } else if (val > 50) { test_obj.clone(); + } else if (val > 30) { + test_obj.stash(); } else if (val > 10) { test_obj.read(); } else { @@ -2431,6 +2503,8 @@ TEST_P(StoreTest, AttrSynthetic) { test_obj.setattrs(); } else if (val > 45) { test_obj.clone(); + } else if (val > 37) { + test_obj.stash(); } else if (val > 30) { test_obj.getattrs(); } else { -- 2.39.5