From: Samuel Just Date: Thu, 10 Oct 2013 23:12:10 +0000 (-0700) Subject: ReplicatedBackend: implement RPGTransaction X-Git-Tag: v0.78~286^2~37 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5732f0c99dc4a6556235879a7188bba6b9543f5f;p=ceph.git ReplicatedBackend: implement RPGTransaction RPGTransaction is essentially a wrapped ObjectStore::Transaction. The coll_t argument is elided, tempness is instead encoded in the hobject. RPGTransaction tracks which temp objects are created and cleared so we can update the ReplicatedBackend tracking and possibly create the temp collection as needed. Signed-off-by: Samuel Just --- diff --git a/src/osd/ReplicatedBackend.cc b/src/osd/ReplicatedBackend.cc index f66a58eee6d..6d893b4e3e8 100644 --- a/src/osd/ReplicatedBackend.cc +++ b/src/osd/ReplicatedBackend.cc @@ -300,3 +300,201 @@ int ReplicatedBackend::objects_get_attr( } return r; } + + +class RPGTransaction : public PGBackend::PGTransaction { + coll_t coll; + coll_t temp_coll; + set temp_added; + set temp_cleared; + ObjectStore::Transaction *t; + const coll_t &get_coll_ct(const hobject_t &hoid) { + if (hoid.is_temp()) { + temp_cleared.erase(hoid); + temp_added.insert(hoid); + } + return get_coll(hoid); + } + const coll_t &get_coll_rm(const hobject_t &hoid) { + if (hoid.is_temp()) { + temp_added.erase(hoid); + temp_cleared.insert(hoid); + } + return get_coll(hoid); + } + const coll_t &get_coll(const hobject_t &hoid) { + if (hoid.is_temp()) + return temp_coll; + else + return coll; + } +public: + RPGTransaction(coll_t coll, coll_t temp_coll) + : coll(coll), temp_coll(temp_coll), t(new ObjectStore::Transaction) + {} + + /// Yields ownership of contained transaction + ObjectStore::Transaction *get_transaction() { + ObjectStore::Transaction *_t = t; + t = 0; + return _t; + } + const set &get_temp_added() { + return temp_added; + } + const set &get_temp_cleared() { + return temp_cleared; + } + + void write( + const hobject_t &hoid, + uint64_t off, + uint64_t len, + bufferlist &bl + ) { + t->write(get_coll_ct(hoid), hoid, off, len, bl); + } + void remove( + const hobject_t &hoid + ) { + t->remove(get_coll_rm(hoid), hoid); + } + void stash( + const hobject_t &hoid, + version_t former_version) { + t->collection_move_rename( + coll, hoid, coll, + ghobject_t(hoid, former_version, 0)); + } + void setattrs( + const hobject_t &hoid, + map &attrs + ) { + t->setattrs(get_coll(hoid), hoid, attrs); + } + void setattr( + const hobject_t &hoid, + const string &attrname, + bufferlist &bl + ) { + t->setattr(get_coll(hoid), hoid, attrname, bl); + } + void rmattr( + const hobject_t &hoid, + const string &attrname + ) { + t->rmattr(get_coll(hoid), hoid, attrname); + } + void omap_setkeys( + const hobject_t &hoid, + map &keys + ) { + return t->omap_setkeys(get_coll(hoid), hoid, keys); + } + void omap_rmkeys( + const hobject_t &hoid, + set &keys + ) { + t->omap_rmkeys(get_coll(hoid), hoid, keys); + } + void omap_clear( + const hobject_t &hoid + ) { + t->omap_clear(get_coll(hoid), hoid); + } + void omap_setheader( + const hobject_t &hoid, + bufferlist &header + ) { + t->omap_setheader(get_coll(hoid), hoid, header); + } + void clone_range( + const hobject_t &from, + const hobject_t &to, + uint64_t fromoff, + uint64_t len, + uint64_t tooff + ) { + assert(get_coll(from) == get_coll_ct(to) && get_coll(from) == coll); + t->clone_range(coll, from, to, fromoff, len, tooff); + } + void clone( + const hobject_t &from, + const hobject_t &to + ) { + assert(get_coll(from) == get_coll_ct(to) && get_coll(from) == coll); + t->clone(coll, from, to); + } + void rename( + const hobject_t &from, + const hobject_t &to + ) { + t->collection_move_rename( + get_coll_rm(from), + from, + get_coll_ct(to), + to); + } + + void touch( + const hobject_t &hoid + ) { + t->touch(get_coll_ct(hoid), hoid); + } + + void truncate( + const hobject_t &hoid, + uint64_t off + ) { + t->truncate(get_coll(hoid), hoid, off); + } + void zero( + const hobject_t &hoid, + uint64_t off, + uint64_t len + ) { + t->zero(get_coll(hoid), hoid, off, len); + } + + void append( + PGTransaction *_to_append + ) { + RPGTransaction *to_append = dynamic_cast(_to_append); + t->append(*(to_append->t)); + for (set::iterator i = to_append->temp_added.begin(); + i != to_append->temp_added.end(); + ++i) { + temp_cleared.erase(*i); + temp_added.insert(*i); + } + for (set::iterator i = to_append->temp_cleared.begin(); + i != to_append->temp_cleared.end(); + ++i) { + temp_added.erase(*i); + temp_cleared.insert(*i); + } + } + void nop() { + t->nop(); + } + bool empty() const { + return t->empty(); + } + ~RPGTransaction() { delete t; } +}; + +PGBackend::PGTransaction *ReplicatedBackend::get_transaction() +{ + return new RPGTransaction(coll, get_temp_coll()); +} + +void ReplicatedBackend::submit_transaction( + PGTransaction *_t, + vector &log_entries, + Context *on_all_acked, + Context *on_all_commit, + tid_t tid) +{ + //RPGTransaction *t = dynamic_cast(_t); + return; +} diff --git a/src/osd/ReplicatedBackend.h b/src/osd/ReplicatedBackend.h index 0c03a7abb3e..6960d223e2a 100644 --- a/src/osd/ReplicatedBackend.h +++ b/src/osd/ReplicatedBackend.h @@ -171,6 +171,19 @@ public: const hobject_t &hoid, const string &attr, bufferlist *out); + + /** + * Client IO + */ + PGTransaction *get_transaction(); + void submit_transaction( + PGTransaction *t, + vector &log_entries, + Context *on_all_acked, + Context *on_all_commit, + tid_t tid + ); + private: // push struct PushInfo {