]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ObjectStore: add queue_transactions with oncomplete
authorSamuel Just <sam.just@inktank.com>
Wed, 23 Jan 2013 19:13:28 +0000 (11:13 -0800)
committerSamuel Just <sam.just@inktank.com>
Sat, 26 Jan 2013 01:23:07 +0000 (17:23 -0800)
Signed-off-by: Samuel Just <sam.just@inktank.com>
(cherry picked from commit 4d6ba06309b80fb21de7bb5d12d5482e71de5f16)

src/os/ObjectStore.cc
src/os/ObjectStore.h

index 6087dee50f7866dfb232604bbc2e136e13868858..70e8b6ed19eac77ca973f7f6df90c433eb5297ad 100644 (file)
@@ -12,6 +12,7 @@
  * 
  */
 #include <sstream>
+#include <tr1/memory>
 #include "ObjectStore.h"
 #include "common/Formatter.h"
 
@@ -40,6 +41,43 @@ unsigned ObjectStore::apply_transactions(Sequencer *osr,
   return r;
 }
 
+template <class T>
+struct Wrapper : public Context {
+  Context *to_run;
+  T val;
+  Wrapper(Context *to_run, T val) : to_run(to_run), val(val) {}
+  void finish(int r) {
+    if (to_run)
+      to_run->complete(r);
+  }
+};
+struct RunOnDelete {
+  Context *to_run;
+  RunOnDelete(Context *to_run) : to_run(to_run) {}
+  ~RunOnDelete() {
+    if (to_run)
+      to_run->complete(0);
+  }
+};
+typedef std::tr1::shared_ptr<RunOnDelete> RunOnDeleteRef;
+int ObjectStore::queue_transactions(
+  Sequencer *osr,
+  list<Transaction*>& tls,
+  Context *onreadable,
+  Context *oncommit,
+  Context *onreadable_sync,
+  Context *oncomplete,
+  TrackedOpRef op = TrackedOpRef())
+{
+  RunOnDeleteRef _complete(new RunOnDelete(oncomplete));
+  Context *_onreadable = new Wrapper<RunOnDeleteRef>(
+    onreadable, _complete);
+  Context *_oncommit = new Wrapper<RunOnDeleteRef>(
+    oncommit, _complete);
+  return queue_transactions(osr, tls, _onreadable, _oncommit,
+                           onreadable_sync, op);
+}
+
 void ObjectStore::Transaction::dump(ceph::Formatter *f)
 {
   f->open_array_section("ops");
index 5729490ac068d3ee5448a6e27da8aee8d70b23ca..504422981f48dca2beb1990a77986c7d8b04bdf8 100644 (file)
@@ -661,6 +661,29 @@ public:
                                 Context *onreadable_sync=0,
                                 TrackedOpRef op = TrackedOpRef()) = 0;
 
+  int queue_transactions(
+    Sequencer *osr,
+    list<Transaction*>& tls,
+    Context *onreadable,
+    Context *oncommit,
+    Context *onreadable_sync,
+    Context *oncomplete,
+    TrackedOpRef op);
+
+  int queue_transaction(
+    Sequencer *osr,
+    Transaction* t,
+    Context *onreadable,
+    Context *oncommit,
+    Context *onreadable_sync,
+    Context *oncomplete,
+    TrackedOpRef op) {
+    list<Transaction*> tls;
+    tls.push_back(t);
+    return queue_transactions(
+      osr, tls, onreadable, oncommit, onreadable_sync, oncomplete, op);
+  }
+
  public:
   ObjectStore() : logger(NULL) {}
   virtual ~ObjectStore() {}