From 11ef793659cefa51d8a44733b2ace9e25749e0fe Mon Sep 17 00:00:00 2001 From: Michal Jarzabek Date: Sat, 3 Sep 2016 12:33:46 +0100 Subject: [PATCH] osd/ReplicatedPG: move classes to .cc file Signed-off-by: Michal Jarzabek --- src/osd/ReplicatedPG.cc | 132 ++++++++++++++++++++++++++++++++++++++++ src/osd/ReplicatedPG.h | 119 ++++-------------------------------- 2 files changed, 143 insertions(+), 108 deletions(-) diff --git a/src/osd/ReplicatedPG.cc b/src/osd/ReplicatedPG.cc index b0aa968e3465..cd8d91f598c5 100644 --- a/src/osd/ReplicatedPG.cc +++ b/src/osd/ReplicatedPG.cc @@ -77,6 +77,103 @@ PGLSFilter::~PGLSFilter() { } +/** + * The CopyCallback class defines an interface for completions to the + * copy_start code. Users of the copy infrastructure must implement + * one and give an instance of the class to start_copy. + * + * The implementer is responsible for making sure that the CopyCallback + * can associate itself with the correct copy operation. + */ +class ReplicatedPG::CopyCallback : public GenContext { +protected: + CopyCallback() {} + /** + * results.get<0>() is the return code: 0 for success; -ECANCELED if + * the operation was cancelled by the local OSD; -errno for other issues. + * results.get<1>() is a pointer to a CopyResults object, which you are + * responsible for deleting. + */ + virtual void finish(CopyCallbackResults results_) = 0; + +public: + /// Provide the final size of the copied object to the CopyCallback + virtual ~CopyCallback() {} +}; + +template +class ReplicatedPG::BlessedGenContext : public GenContext { + ReplicatedPGRef pg; + GenContext *c; + epoch_t e; +public: + BlessedGenContext(ReplicatedPG *pg, GenContext *c, epoch_t e) + : pg(pg), c(c), e(e) {} + void finish(T t) { + pg->lock(); + if (pg->pg_has_reset_since(e)) + delete c; + else + c->complete(t); + pg->unlock(); + } +}; + +GenContext *ReplicatedPG::bless_gencontext( + GenContext *c) { + return new BlessedGenContext( + this, c, get_osdmap()->get_epoch()); +} + +class ReplicatedPG::BlessedContext : public Context { + ReplicatedPGRef pg; + Context *c; + epoch_t e; +public: + BlessedContext(ReplicatedPG *pg, Context *c, epoch_t e) + : pg(pg), c(c), e(e) {} + void finish(int r) { + pg->lock(); + if (pg->pg_has_reset_since(e)) + delete c; + else + c->complete(r); + pg->unlock(); + } +}; + + +Context *ReplicatedPG::bless_context(Context *c) { + return new BlessedContext(this, c, get_osdmap()->get_epoch()); +} + +class ReplicatedPG::C_PG_ObjectContext : public Context { + ReplicatedPGRef pg; + ObjectContext *obc; + public: + C_PG_ObjectContext(ReplicatedPG *p, ObjectContext *o) : + pg(p), obc(o) {} + void finish(int r) { + pg->object_context_destructor_callback(obc); + } +}; + +class ReplicatedPG::C_OSD_OndiskWriteUnlock : public Context { + ObjectContextRef obc, obc2, obc3; + public: + C_OSD_OndiskWriteUnlock( + ObjectContextRef o, + ObjectContextRef o2 = ObjectContextRef(), + ObjectContextRef o3 = ObjectContextRef()) : obc(o), obc2(o2), obc3(o3) {} + void finish(int r) { + obc->ondisk_write_unlock(); + if (obc2) + obc2->ondisk_write_unlock(); + if (obc3) + obc3->ondisk_write_unlock(); + } +}; + struct OnReadComplete : public Context { ReplicatedPG *pg; ReplicatedPG::OpContext *opcontext; @@ -91,6 +188,41 @@ struct OnReadComplete : public Context { ~OnReadComplete() {} }; +class ReplicatedPG::C_OSD_AppliedRecoveredObject : public Context { + ReplicatedPGRef pg; + ObjectContextRef obc; + public: + C_OSD_AppliedRecoveredObject(ReplicatedPG *p, ObjectContextRef o) : + pg(p), obc(o) {} + void finish(int r) { + pg->_applied_recovered_object(obc); + } +}; + +class ReplicatedPG::C_OSD_CommittedPushedObject : public Context { + ReplicatedPGRef pg; + epoch_t epoch; + eversion_t last_complete; + public: + C_OSD_CommittedPushedObject( + ReplicatedPG *p, epoch_t epoch, eversion_t lc) : + pg(p), epoch(epoch), last_complete(lc) { + } + void finish(int r) { + pg->_committed_pushed_object(epoch, last_complete); + } +}; + +class ReplicatedPG::C_OSD_AppliedRecoveredObjectReplica : public Context { + ReplicatedPGRef pg; + public: + explicit C_OSD_AppliedRecoveredObjectReplica(ReplicatedPG *p) : + pg(p) {} + void finish(int r) { + pg->_applied_recovered_object_replica(); + } +}; + // OpContext void ReplicatedPG::OpContext::start_async_reads(ReplicatedPG *pg) { diff --git a/src/osd/ReplicatedPG.h b/src/osd/ReplicatedPG.h index 454d596d48a1..b3b936a58ef3 100644 --- a/src/osd/ReplicatedPG.h +++ b/src/osd/ReplicatedPG.h @@ -172,21 +172,7 @@ public: * can associate itself with the correct copy operation. */ typedef boost::tuple CopyCallbackResults; - class CopyCallback : public GenContext { - protected: - CopyCallback() {} - /** - * results.get<0>() is the return code: 0 for success; -ECANCELED if - * the operation was cancelled by the local OSD; -errno for other issues. - * results.get<1>() is a pointer to a CopyResults object, which you are - * responsible for deleting. - */ - virtual void finish(CopyCallbackResults results_) = 0; - - public: - /// Provide the final size of the copied object to the CopyCallback - virtual ~CopyCallback() {} - }; + class CopyCallback; friend class CopyFromCallback; friend class PromoteCallback; @@ -275,47 +261,12 @@ public: void failed_push(pg_shard_t from, const hobject_t &soid); void cancel_pull(const hobject_t &soid); - template - class BlessedGenContext : public GenContext { - ReplicatedPGRef pg; - GenContext *c; - epoch_t e; - public: - BlessedGenContext(ReplicatedPG *pg, GenContext *c, epoch_t e) - : pg(pg), c(c), e(e) {} - void finish(T t) { - pg->lock(); - if (pg->pg_has_reset_since(e)) - delete c; - else - c->complete(t); - pg->unlock(); - } - }; - class BlessedContext : public Context { - ReplicatedPGRef pg; - Context *c; - epoch_t e; - public: - BlessedContext(ReplicatedPG *pg, Context *c, epoch_t e) - : pg(pg), c(c), e(e) {} - void finish(int r) { - pg->lock(); - if (pg->pg_has_reset_since(e)) - delete c; - else - c->complete(r); - pg->unlock(); - } - }; - Context *bless_context(Context *c) { - return new BlessedContext(this, c, get_osdmap()->get_epoch()); - } + template class BlessedGenContext; + class BlessedContext; + Context *bless_context(Context *c); + GenContext *bless_gencontext( - GenContext *c) { - return new BlessedGenContext( - this, c, get_osdmap()->get_epoch()); - } + GenContext *c); void send_message(int to_osd, Message *m) { osd->send_message_osd_cluster(to_osd, m, get_osdmap()->get_epoch()); @@ -1028,15 +979,7 @@ protected: void context_registry_on_change(); void object_context_destructor_callback(ObjectContext *obc); - struct C_PG_ObjectContext : public Context { - ReplicatedPGRef pg; - ObjectContext *obc; - C_PG_ObjectContext(ReplicatedPG *p, ObjectContext *o) : - pg(p), obc(o) {} - void finish(int r) { - pg->object_context_destructor_callback(obc); - } - }; + class C_PG_ObjectContext; int find_object_context(const hobject_t& oid, ObjectContextRef *pobc, @@ -1297,50 +1240,10 @@ protected: void send_remove_op(const hobject_t& oid, eversion_t v, pg_shard_t peer); - struct C_OSD_OndiskWriteUnlock : public Context { - ObjectContextRef obc, obc2, obc3; - C_OSD_OndiskWriteUnlock( - ObjectContextRef o, - ObjectContextRef o2 = ObjectContextRef(), - ObjectContextRef o3 = ObjectContextRef()) : obc(o), obc2(o2), obc3(o3) {} - void finish(int r) { - obc->ondisk_write_unlock(); - if (obc2) - obc2->ondisk_write_unlock(); - if (obc3) - obc3->ondisk_write_unlock(); - } - }; - struct C_OSD_AppliedRecoveredObject : public Context { - ReplicatedPGRef pg; - ObjectContextRef obc; - C_OSD_AppliedRecoveredObject(ReplicatedPG *p, ObjectContextRef o) : - pg(p), obc(o) {} - void finish(int r) { - pg->_applied_recovered_object(obc); - } - }; - struct C_OSD_CommittedPushedObject : public Context { - ReplicatedPGRef pg; - epoch_t epoch; - eversion_t last_complete; - C_OSD_CommittedPushedObject( - ReplicatedPG *p, epoch_t epoch, eversion_t lc) : - pg(p), epoch(epoch), last_complete(lc) { - } - void finish(int r) { - pg->_committed_pushed_object(epoch, last_complete); - } - }; - struct C_OSD_AppliedRecoveredObjectReplica : public Context { - ReplicatedPGRef pg; - explicit C_OSD_AppliedRecoveredObjectReplica(ReplicatedPG *p) : - pg(p) {} - void finish(int r) { - pg->_applied_recovered_object_replica(); - } - }; - + class C_OSD_OndiskWriteUnlock; + class C_OSD_AppliedRecoveredObject; + class C_OSD_CommittedPushedObject; + class C_OSD_AppliedRecoveredObjectReplica; void sub_op_remove(OpRequestRef op); void _applied_recovered_object(ObjectContextRef obc); -- 2.47.3