From 31b7937bae578d60559f41f2b225206d7fa90e0f Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Wed, 22 Jan 2014 17:56:30 -0800 Subject: [PATCH] PGBackend/ReplicatedBackend: move temp handling into PGBackend Temp handling is also the same in ReplicatedBackend as in ECBackend. Signed-off-by: Samuel Just --- src/osd/PGBackend.cc | 27 +++++++++++++++ src/osd/PGBackend.h | 64 +++++++++++++++++++++++++++++++----- src/osd/ReplicatedBackend.cc | 31 +++-------------- src/osd/ReplicatedBackend.h | 41 +---------------------- 4 files changed, 87 insertions(+), 76 deletions(-) diff --git a/src/osd/PGBackend.cc b/src/osd/PGBackend.cc index 1dddd928ada2b..99e191c45c147 100644 --- a/src/osd/PGBackend.cc +++ b/src/osd/PGBackend.cc @@ -73,6 +73,33 @@ void PGBackend::rollback( } +void PGBackend::on_change(ObjectStore::Transaction *t) +{ + dout(10) << __func__ << dendl; + // clear temp + for (set::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, diff --git a/src/osd/PGBackend.h b/src/osd/PGBackend.h index c6215525b9c5b..3d6ad7da33569 100644 --- a/src/osd/PGBackend.h +++ b/src/osd/PGBackend.h @@ -38,6 +38,10 @@ * 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 @@ -148,7 +152,11 @@ }; 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(); } @@ -225,25 +233,63 @@ * 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 *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 *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 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 &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 &oids) { + for (set::const_iterator i = oids.begin(); + i != oids.end(); + ++i) { + temp_contents.erase(*i); + } + } virtual ~PGBackend() {} diff --git a/src/osd/ReplicatedBackend.cc b/src/osd/ReplicatedBackend.cc index 7e36c5961a3fc..f624901fe1d1c 100644 --- a/src/osd/ReplicatedBackend.cc +++ b/src/osd/ReplicatedBackend.cc @@ -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::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::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::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); diff --git a/src/osd/ReplicatedBackend.h b/src/osd/ReplicatedBackend.h index 611b9bfaa43b5..7ec0b88d788c5 100644 --- a/src/osd/ReplicatedBackend.h +++ b/src/osd/ReplicatedBackend.h @@ -27,18 +27,7 @@ class ReplicatedBackend : public PGBackend { map > 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 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 *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 pulling; // Reverse mapping from osd peer to objects beging pulled from that peer -- 2.39.5