osd/PGLog.cc \
osd/ReplicatedPG.cc \
osd/ReplicatedBackend.cc \
+ osd/PGBackend.cc \
osd/Ager.cc \
osd/HitSet.cc \
osd/OSD.cc \
--- /dev/null
+// -*- 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);
+}
+
+
#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,
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,