]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test_filestore_idempotent_sequence: put txn object in each collection
authorSage Weil <sage@redhat.com>
Fri, 16 Feb 2018 22:50:04 +0000 (16:50 -0600)
committerSage Weil <sage@redhat.com>
Fri, 16 Feb 2018 22:50:04 +0000 (16:50 -0600)
The transactions are idependent in each collection/sequencer, so we
can't record to a single txn object with racing transactions.  Fix
it by doing one in each collection, and when reading the latest op,
use the highest txn value we see.

Signed-off-by: Sage Weil <sage@redhat.com>
src/test/objectstore/DeterministicOpSequence.cc
src/test/objectstore/DeterministicOpSequence.h
src/test/objectstore/test_idempotent_sequence.cc

index e501712e167eb157f126837578fa0f10cdd7f27c..91390a6db29185fce7477672c818fcd0664c6234 100644 (file)
@@ -39,8 +39,6 @@ DeterministicOpSequence::DeterministicOpSequence(ObjectStore *store,
   : TestObjectStoreState(store),
     txn(0)
 {
-  txn_object = hobject_t(sobject_t("txn", CEPH_NOSNAP));
-
   if (!status.empty())
     m_status.open(status.c_str());
 }
@@ -130,12 +128,14 @@ int DeterministicOpSequence::_gen_obj_id(rngen_t& gen)
   return obj_rng(gen);
 }
 
-void DeterministicOpSequence::note_txn(ObjectStore::Transaction *t)
+void DeterministicOpSequence::note_txn(coll_entry_t *entry,
+                                      ObjectStore::Transaction *t)
 {
   bufferlist bl;
   encode(txn, bl);
-  t->truncate(txn_coll, ghobject_t(txn_object), 0);
-  t->write(txn_coll, ghobject_t(txn_object), 0, bl.length(), bl);
+  ghobject_t oid = get_txn_object(entry->m_cid);
+  t->truncate(entry->m_cid, oid, 0);
+  t->write(entry->m_cid, oid, 0, bl.length(), bl);
   dout(10) << __func__ << " " << txn << dendl;
 }
 
@@ -395,8 +395,8 @@ bool DeterministicOpSequence::do_coll_create(rngen_t& gen)
 void DeterministicOpSequence::_do_coll_create(coll_entry_t *entry, uint32_t pg_num, uint64_t num_objs)
 {
   ObjectStore::Transaction t;
-  note_txn(&t);
   t.create_collection(entry->m_cid, 32);
+  note_txn(entry, &t);
   bufferlist hint;
   encode(pg_num, hint);
   encode(num_objs, hint);
@@ -411,7 +411,7 @@ void DeterministicOpSequence::_do_coll_create(coll_entry_t *entry, uint32_t pg_n
 void DeterministicOpSequence::_do_touch(coll_entry_t *entry, hobject_t& obj)
 {
   ObjectStore::Transaction t;
-  note_txn(&t);
+  note_txn(entry, &t);
   t.touch(entry->m_cid, ghobject_t(obj));
   m_store->queue_transaction(entry->m_ch, std::move(t));
 }
@@ -419,7 +419,7 @@ void DeterministicOpSequence::_do_touch(coll_entry_t *entry, hobject_t& obj)
 void DeterministicOpSequence::_do_remove(coll_entry_t *entry, hobject_t& obj)
 {
   ObjectStore::Transaction t;
-  note_txn(&t);
+  note_txn(entry, &t);
   t.remove(entry->m_cid, ghobject_t(obj));
   m_store->queue_transaction(entry->m_ch, std::move(t));
 }
@@ -429,7 +429,7 @@ void DeterministicOpSequence::_do_set_attrs(coll_entry_t *entry,
                                            const map<string, bufferlist> &attrs)
 {
   ObjectStore::Transaction t;
-  note_txn(&t);
+  note_txn(entry, &t);
   t.omap_setkeys(entry->m_cid, ghobject_t(obj), attrs);
   m_store->queue_transaction(entry->m_ch, std::move(t));
 }
@@ -438,7 +438,7 @@ void DeterministicOpSequence::_do_write(coll_entry_t *entry, hobject_t& obj,
                                        uint64_t off, uint64_t len, const bufferlist& data)
 {
   ObjectStore::Transaction t;
-  note_txn(&t);
+  note_txn(entry, &t);
   t.write(entry->m_cid, ghobject_t(obj), off, len, data);
   m_store->queue_transaction(entry->m_ch, std::move(t));
 }
@@ -447,7 +447,7 @@ void DeterministicOpSequence::_do_clone(coll_entry_t *entry, hobject_t& orig_obj
                                        hobject_t& new_obj)
 {
   ObjectStore::Transaction t;
-  note_txn(&t);
+  note_txn(entry, &t);
   t.clone(entry->m_cid, ghobject_t(orig_obj), ghobject_t(new_obj));
   m_store->queue_transaction(entry->m_ch, std::move(t));
 }
@@ -457,7 +457,7 @@ void DeterministicOpSequence::_do_clone_range(coll_entry_t *entry,
                                              uint64_t srclen, uint64_t dstoff)
 {
   ObjectStore::Transaction t;
-  note_txn(&t);
+  note_txn(entry, &t);
   t.clone_range(entry->m_cid, ghobject_t(orig_obj), ghobject_t(new_obj),
                srcoff, srclen, dstoff);
   m_store->queue_transaction(entry->m_ch, std::move(t));
@@ -472,7 +472,7 @@ void DeterministicOpSequence::_do_write_and_clone_range(coll_entry_t *entry,
                                                         bufferlist& bl)
 {
   ObjectStore::Transaction t;
-  note_txn(&t);
+  note_txn(entry, &t);
   t.write(entry->m_cid, ghobject_t(orig_obj), srcoff, bl.length(), bl);
   t.clone_range(entry->m_cid, ghobject_t(orig_obj), ghobject_t(new_obj),
                srcoff, srclen, dstoff);
@@ -484,7 +484,7 @@ void DeterministicOpSequence::_do_coll_move(coll_entry_t *entry,
                                            hobject_t& new_obj)
 {
   ObjectStore::Transaction t;
-  note_txn(&t);
+  note_txn(entry, &t);
   t.remove(entry->m_cid, ghobject_t(new_obj));
   t.collection_move_rename(entry->m_cid, ghobject_t(orig_obj),
                           entry->m_cid, ghobject_t(new_obj));
index 5f45922432583199ac378636ceca1198f3e305c3..5a5a6ad93ce5d8ac1668456ef12a3cf164d22e3a 100644 (file)
@@ -27,12 +27,23 @@ typedef boost::mt11213b rngen_t;
 
 class DeterministicOpSequence : public TestObjectStoreState {
  public:
-  DeterministicOpSequence(ObjectStore *store, std::string status = std::string());
+  DeterministicOpSequence(ObjectStore *store,
+                         std::string status = std::string());
   virtual ~DeterministicOpSequence();
 
   virtual void generate(int seed, int num_txs);
 
- protected:
+  static ghobject_t get_txn_object(coll_t cid) {
+    ghobject_t oid(hobject_t(sobject_t("txn", CEPH_NOSNAP)));
+    spg_t pgid;
+    bool r = cid.is_pg(&pgid);
+    if (r) {
+      oid.hobj.set_hash(pgid.ps());
+    }
+    return oid;
+  }
+
+protected:
   enum {
     DSOP_TOUCH = 0,
     DSOP_WRITE = 1,
@@ -49,15 +60,12 @@ class DeterministicOpSequence : public TestObjectStoreState {
 
   int32_t txn;
 
-  coll_t txn_coll;
-  hobject_t txn_object;
-
   ObjectStore::CollectionHandle m_ch;
   std::ofstream m_status;
 
   bool run_one_op(int op, rngen_t& gen);
 
-  void note_txn(ObjectStore::Transaction *t);
+  void note_txn(coll_entry_t *entry, ObjectStore::Transaction *t);
   bool do_touch(rngen_t& gen);
   bool do_remove(rngen_t& gen);
   bool do_write(rngen_t& gen);
index 451fa51f8efb127c80b7ea108825a46500a8c961..f168a62959df4f0b0ba23a4e5e65c5c5afca1a74 100644 (file)
@@ -111,15 +111,23 @@ int run_get_last_op(std::string& filestore_path, std::string& journal_path)
     return err;
   }
 
-  coll_t txn_coll;
-  ghobject_t txn_object(hobject_t(sobject_t("txn", CEPH_NOSNAP)));
-  bufferlist bl;
-  auto ch = store->open_collection(txn_coll);
-  store->read(ch, txn_object, 0, 100, bl);
+  vector<coll_t> cls;
+  store->list_collections(cls);
+
   int32_t txn = 0;
-  if (bl.length()) {
-    bufferlist::iterator p = bl.begin();
-    decode(txn, p);
+  for (auto cid : cls) {
+    ghobject_t txn_object = DeterministicOpSequence::get_txn_object(cid);
+    bufferlist bl;
+    auto ch = store->open_collection(cid);
+    store->read(ch, txn_object, 0, 100, bl);
+    int32_t t = 0;
+    if (bl.length()) {
+      bufferlist::iterator p = bl.begin();
+      decode(t, p);
+    }
+    if (t > txn) {
+      txn = t;
+    }
   }
 
   store->umount();