]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
PGBackend/ReplicatedBackend: move temp handling into PGBackend
authorSamuel Just <sam.just@inktank.com>
Thu, 23 Jan 2014 01:56:30 +0000 (17:56 -0800)
committerSamuel Just <sam.just@inktank.com>
Tue, 18 Feb 2014 04:11:06 +0000 (20:11 -0800)
Temp handling is also the same in ReplicatedBackend as in ECBackend.

Signed-off-by: Samuel Just <sam.just@inktank.com>
src/osd/PGBackend.cc
src/osd/PGBackend.h
src/osd/ReplicatedBackend.cc
src/osd/ReplicatedBackend.h

index 1dddd928ada2b4b7ccc297645871144cfd161c0b..99e191c45c1472b4efa1efdbbd1ddbe86605ebc7 100644 (file)
@@ -73,6 +73,33 @@ void PGBackend::rollback(
 }
 
 
+void PGBackend::on_change(ObjectStore::Transaction *t)
+{
+  dout(10) << __func__ << dendl;
+  // clear temp
+  for (set<hobject_t>::iterator i = temp_contents.begin();
+       i != temp_contents.end();
+       ++i) {
+    dout(10) << __func__ << ": Removing oid "
+            << *i << " from the temp collection" << dendl;
+    t->remove(
+      get_temp_coll(t),
+      ghobject_t(*i, ghobject_t::NO_GEN, get_parent()->whoami_shard().shard));
+  }
+  temp_contents.clear();
+  _on_change(t);
+}
+
+coll_t PGBackend::get_temp_coll(ObjectStore::Transaction *t)
+{
+  if (temp_created)
+    return temp_coll;
+  if (!store->collection_exists(temp_coll))
+      t->create_collection(temp_coll);
+  temp_created = true;
+  return temp_coll;
+}
+
 int PGBackend::objects_list_partial(
   const hobject_t &begin,
   int min,
index c6215525b9c5b21036fcac1e976c3cd9a2e2abbb..3d6ad7da335697623c3e59a6621934c35b44b199 100644 (file)
   * 4) Handling scrub, deep-scrub, repair
   */
  class PGBackend {
+ protected:
+   ObjectStore *store;
+   const coll_t coll;
+   const coll_t temp_coll;
  public:       
    /**
     * Provides interfaces for PGBackend callbacks
    };
    Listener *parent;
    Listener *get_parent() const { return parent; }
-   PGBackend(Listener *l) : parent(l) {}
+   PGBackend(Listener *l, ObjectStore *store, coll_t coll, coll_t temp_coll) :
+     store(store),
+     coll(coll),
+     temp_coll(temp_coll),
+     parent(l), temp_created(false) {}
    bool is_primary() const { return get_parent()->pgb_is_primary(); }
    OSDMapRef get_osdmap() const { return get_parent()->pgb_get_osdmap(); }
    const pg_info_t &get_info() { return get_parent()->get_info(); }
     * implementation should clear itself, contexts blessed prior to on_change
     * won't be called after on_change()
     */
-   virtual void on_change(ObjectStore::Transaction *t) = 0;
+   void on_change(ObjectStore::Transaction *t);
+   virtual void _on_change(ObjectStore::Transaction *t) = 0;
    virtual void clear_state() = 0;
 
    virtual void on_flushed() = 0;
 
 
-   virtual void split_colls(
+
+   void temp_colls(list<coll_t> *out) {
+     if (temp_created)
+       out->push_back(temp_coll);
+   }
+   void split_colls(
      pg_t child,
      int split_bits,
      int seed,
-     ObjectStore::Transaction *t) = 0;
-
-   virtual void temp_colls(list<coll_t> *out) = 0;
+     ObjectStore::Transaction *t) {
+     coll_t target = coll_t::make_temp_coll(child);
+     if (!temp_created)
+       return;
+     t->create_collection(target);
+     t->split_collection(
+       temp_coll,
+       split_bits,
+       seed,
+       target);
+   }
 
    virtual void dump_recovery_info(Formatter *f) const = 0;
 
-   virtual coll_t get_temp_coll(ObjectStore::Transaction *t) = 0;
-   virtual void add_temp_obj(const hobject_t &oid) = 0;
-   virtual void clear_temp_obj(const hobject_t &oid) = 0;
+ private:
+   bool temp_created;
+   set<hobject_t> temp_contents;
+ public:
+   coll_t get_temp_coll(ObjectStore::Transaction *t);
+   coll_t get_temp_coll() const {
+    return temp_coll;
+   }
+   bool have_temp_coll() const { return temp_created; }
+
+   // Track contents of temp collection, clear on reset
+   void add_temp_obj(const hobject_t &oid) {
+     temp_contents.insert(oid);
+   }
+   void add_temp_objs(const set<hobject_t> &oids) {
+     temp_contents.insert(oids.begin(), oids.end());
+   }
+   void clear_temp_obj(const hobject_t &oid) {
+     temp_contents.erase(oid);
+   }
+   void clear_temp_objs(const set<hobject_t> &oids) {
+     for (set<hobject_t>::const_iterator i = oids.begin();
+         i != oids.end();
+         ++i) {
+       temp_contents.erase(*i);
+     }
+   }
 
    virtual ~PGBackend() {}
 
index 7e36c5961a3fcb731e798a6a78829debbfc405ff..f624901fe1d1cb9d1f370c7182c5acdbeb3cc6c1 100644 (file)
@@ -188,18 +188,8 @@ void ReplicatedBackend::clear_state()
   pull_from_peer.clear();
 }
 
-void ReplicatedBackend::on_change(ObjectStore::Transaction *t)
+void ReplicatedBackend::_on_change(ObjectStore::Transaction *t)
 {
-  dout(10) << __func__ << dendl;
-  // clear temp
-  for (set<hobject_t>::iterator i = temp_contents.begin();
-       i != temp_contents.end();
-       ++i) {
-    dout(10) << __func__ << ": Removing oid "
-            << *i << " from the temp collection" << dendl;
-    t->remove(get_temp_coll(t), *i);
-  }
-  temp_contents.clear();
   for (map<tid_t, InProgressOp>::iterator i = in_progress_ops.begin();
        i != in_progress_ops.end();
        in_progress_ops.erase(i++)) {
@@ -211,16 +201,6 @@ void ReplicatedBackend::on_change(ObjectStore::Transaction *t)
   clear_state();
 }
 
-coll_t ReplicatedBackend::get_temp_coll(ObjectStore::Transaction *t)
-{
-  if (temp_created)
-    return temp_coll;
-  if (!osd->store->collection_exists(temp_coll))
-      t->create_collection(temp_coll);
-  temp_created = true;
-  return temp_coll;
-}
-
 void ReplicatedBackend::on_flushed()
 {
   if (have_temp_coll() &&
@@ -543,13 +523,10 @@ void ReplicatedBackend::submit_transaction(
   ObjectStore::Transaction local_t;
   if (t->get_temp_added().size()) {
     get_temp_coll(&local_t);
-    temp_contents.insert(t->get_temp_added().begin(), t->get_temp_added().end());
-  }
-  for (set<hobject_t>::const_iterator i = t->get_temp_cleared().begin();
-       i != t->get_temp_cleared().end();
-       ++i) {
-    temp_contents.erase(*i);
+    add_temp_objs(t->get_temp_added());
   }
+  clear_temp_objs(t->get_temp_cleared());
+
   parent->log_operation(log_entries, trim_to, true, &local_t);
   local_t.append(*op_t);
   local_t.swap(*op_t);
index 611b9bfaa43b5086e78aedd9e74126255c67e2d5..7ec0b88d788c5685786897bd2cb3591721efa523 100644 (file)
@@ -27,18 +27,7 @@ class ReplicatedBackend : public PGBackend {
     map<int, vector<PullOp> > pulls;
   };
   friend struct C_ReplicatedBackend_OnPullComplete;
-private:
-  bool temp_created;
-  const coll_t temp_coll;
-  coll_t get_temp_coll() const {
-    return temp_coll;
-  }
-  bool have_temp_coll() const { return temp_created; }
-
-  // Track contents of temp collection, clear on reset
-  set<hobject_t> temp_contents;
 public:
-  coll_t coll;
   OSDService *osd;
   CephContext *cct;
 
@@ -76,30 +65,10 @@ public:
     OpRequestRef op
     );
 
-  void on_change(ObjectStore::Transaction *t);
+  void _on_change(ObjectStore::Transaction *t);
   void clear_state();
   void on_flushed();
 
-  void temp_colls(list<coll_t> *out) {
-    if (temp_created)
-      out->push_back(temp_coll);
-  }
-  void split_colls(
-    pg_t child,
-    int split_bits,
-    int seed,
-    ObjectStore::Transaction *t) {
-    coll_t target = coll_t::make_temp_coll(child);
-    if (!temp_created)
-      return;
-    t->create_collection(target);
-    t->split_collection(
-      temp_coll,
-      split_bits,
-      seed,
-      target);
-  }
-
   virtual void dump_recovery_info(Formatter *f) const {
     {
       f->open_array_section("pull_from_peer");
@@ -215,14 +184,6 @@ private:
     }
   };
 
-  coll_t get_temp_coll(ObjectStore::Transaction *t);
-  void add_temp_obj(const hobject_t &oid) {
-    temp_contents.insert(oid);
-  }
-  void clear_temp_obj(const hobject_t &oid) {
-    temp_contents.erase(oid);
-  }
-
   map<hobject_t, PullInfo> pulling;
 
   // Reverse mapping from osd peer to objects beging pulled from that peer