]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
PGBackend,ReplicatedBackend: add support for rolling back log entries
authorSamuel Just <sam.just@inktank.com>
Wed, 4 Dec 2013 00:25:07 +0000 (16:25 -0800)
committerSamuel Just <sam.just@inktank.com>
Wed, 22 Jan 2014 22:39:16 +0000 (14:39 -0800)
Signed-off-by: Samuel Just <sam.just@inktank.com>
src/osd/Makefile.am
src/osd/PGBackend.cc [new file with mode: 0644]
src/osd/PGBackend.h
src/osd/ReplicatedBackend.h

index 9076062fc86680ee882555e68c73048ffb574ff2..9bbc7e4616e0c592d77f14df1ed0197af809c62e 100644 (file)
@@ -10,6 +10,7 @@ libosd_la_SOURCES = \
        osd/PGLog.cc \
        osd/ReplicatedPG.cc \
        osd/ReplicatedBackend.cc \
+       osd/PGBackend.cc \
        osd/Ager.cc \
        osd/HitSet.cc \
        osd/OSD.cc \
diff --git a/src/osd/PGBackend.cc b/src/osd/PGBackend.cc
new file mode 100644 (file)
index 0000000..11c29cd
--- /dev/null
@@ -0,0 +1,66 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2013 Inktank Storage, Inc.
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+
+#include "PGBackend.h"
+
+// -- ObjectModDesc --
+struct RollbackVisitor : public ObjectModDesc::Visitor {
+  const hobject_t &hoid;
+  PGBackend *pg;
+  ObjectStore::Transaction t;
+  RollbackVisitor(
+    const hobject_t &hoid,
+    PGBackend *pg) : hoid(hoid), pg(pg) {}
+  void append(uint64_t old_size) {
+    ObjectStore::Transaction temp;
+    pg->rollback_append(hoid, old_size, &temp);
+    temp.append(t);
+    temp.swap(t);
+  }
+  void setattrs(map<string, boost::optional<bufferlist> > &attrs) {
+    ObjectStore::Transaction temp;
+    pg->rollback_setattrs(hoid, attrs, &temp);
+    temp.append(t);
+    temp.swap(t);
+  }
+  void rmobject(version_t old_version) {
+    ObjectStore::Transaction temp;
+    pg->rollback_unstash(hoid, old_version, &temp);
+    temp.append(t);
+    temp.swap(t);
+  }
+  void create() {
+    ObjectStore::Transaction temp;
+    pg->rollback_create(hoid, &temp);
+    temp.append(t);
+    temp.swap(t);
+  }
+  void update_snaps(set<snapid_t> &snaps) {
+    // pass
+  }
+};
+
+void PGBackend::rollback(
+  const hobject_t &hoid,
+  const ObjectModDesc &desc,
+  ObjectStore::Transaction *t)
+{
+  assert(desc.can_rollback());
+  RollbackVisitor vis(hoid, this);
+  desc.visit(&vis);
+  t->append(vis.t);
+}
+
+
index 1d7a682fdac9d3be703a756e8f4abd422d67868b..fd2339ee39b65e97ffc6093f82b8481f55907601 100644 (file)
 #ifndef PGBACKEND_H
 #define PGBACKEND_H
 
+#include "OSDMap.h"
+#include "PGLog.h"
+#include "osd_types.h"
+#include "common/WorkQueue.h"
 #include "osd_types.h"
 #include "include/Context.h"
+#include "os/ObjectStore.h"
 #include <string>
 
  /**
      OpRequestRef op                      ///< [in] op
      ) = 0;
 
+
+   void rollback(
+     const hobject_t &hoid,
+     const ObjectModDesc &desc,
+     ObjectStore::Transaction *t);
+
+   /// Rollback reset attrs
+   virtual void rollback_setattrs(
+     const hobject_t &hoid,
+     map<string, boost::optional<bufferlist> > &old_attrs,
+     ObjectStore::Transaction *t) { assert(0); }
+
+   /// Rollback truncate
+   virtual void rollback_append(
+     const hobject_t &hoid,
+     uint64_t old_size,
+     ObjectStore::Transaction *t) { assert(0); }
+
+   /// Rollback unstash
+   virtual void rollback_unstash(
+     const hobject_t &hoid,
+     version_t old_version,
+     ObjectStore::Transaction *t) { assert(0); }
+
+   /// Rollback create
+   virtual void rollback_create(
+     const hobject_t &hoid,
+     ObjectStore::Transaction *t) { assert(0); }
+
+   /// Trim object stashed at stashed_version
+   virtual void trim_stashed_object(
+     const hobject_t &hoid,
+     version_t stashed_version) { assert(0); }
+
    /// List objects in collection
    virtual int objects_list_partial(
      const hobject_t &begin,
index 166826251e3445e2dfd5d28029c526b098e838d0..f0514711018595ff13e3e735f639483b7f4d3584 100644 (file)
@@ -368,6 +368,49 @@ public:
     osd_reqid_t reqid,
     OpRequestRef op
     );
+
+  void rollback_setattrs(
+    const hobject_t &hoid,
+    map<string, boost::optional<bufferlist> > &old_attrs,
+    ObjectStore::Transaction *t) {
+    map<string, bufferlist> to_set;
+    set<string> to_remove;
+    for (map<string, boost::optional<bufferlist> >::iterator i = old_attrs.begin();
+        i != old_attrs.end();
+        ++i) {
+      if (i->second) {
+       to_set[i->first] = i->second.get();
+      } else {
+       t->rmattr(coll, hoid, i->first);
+      }
+    }
+    t->setattrs(coll, hoid, to_set);
+  }
+
+  void rollback_append(
+    const hobject_t &hoid,
+    uint64_t old_size,
+    ObjectStore::Transaction *t) {
+    t->truncate(coll, hoid, old_size);
+  }
+
+  void rollback_unstash(
+    const hobject_t &hoid,
+    version_t old_version,
+    ObjectStore::Transaction *t) {
+    t->remove(coll, hoid);
+    t->collection_move_rename(
+      coll,
+      ghobject_t(hoid, old_version, ghobject_t::NO_SHARD),
+      coll,
+      hoid);
+  }
+
+  void rollback_create(
+    const hobject_t &hoid,
+    ObjectStore::Transaction *t) {
+    t->remove(coll, hoid);
+  }
 private:
   void issue_op(
     const hobject_t &soid,