From: Samuel Just Date: Wed, 4 Dec 2013 00:25:07 +0000 (-0800) Subject: PGBackend,ReplicatedBackend: add support for rolling back log entries X-Git-Tag: v0.78~286^2~28 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=155b4b069f3627098fab0922aa256c9140d3df0d;p=ceph.git PGBackend,ReplicatedBackend: add support for rolling back log entries Signed-off-by: Samuel Just --- diff --git a/src/osd/Makefile.am b/src/osd/Makefile.am index 9076062fc866..9bbc7e4616e0 100644 --- a/src/osd/Makefile.am +++ b/src/osd/Makefile.am @@ -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 index 000000000000..11c29cd8733c --- /dev/null +++ b/src/osd/PGBackend.cc @@ -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 > &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 &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); +} + + diff --git a/src/osd/PGBackend.h b/src/osd/PGBackend.h index 1d7a682fdac9..fd2339ee39b6 100644 --- a/src/osd/PGBackend.h +++ b/src/osd/PGBackend.h @@ -15,8 +15,13 @@ #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 /** @@ -353,6 +358,40 @@ 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 > &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, diff --git a/src/osd/ReplicatedBackend.h b/src/osd/ReplicatedBackend.h index 166826251e34..f05147110185 100644 --- a/src/osd/ReplicatedBackend.h +++ b/src/osd/ReplicatedBackend.h @@ -368,6 +368,49 @@ public: osd_reqid_t reqid, OpRequestRef op ); + + void rollback_setattrs( + const hobject_t &hoid, + map > &old_attrs, + ObjectStore::Transaction *t) { + map to_set; + set to_remove; + for (map >::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,