From b90584a837e8f3c15a01ef377dc0dc0dc9f841f9 Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Mon, 27 Jan 2014 13:37:08 -0800 Subject: [PATCH] osd/: instantiate the right backend based on pool Signed-off-by: Samuel Just --- src/osd/ECBackend.cc | 16 +++++++++++++++ src/osd/ECBackend.h | 8 ++------ src/osd/OSD.cc | 3 ++- src/osd/PGBackend.cc | 38 ++++++++++++++++++++++++++++++++++++ src/osd/PGBackend.h | 9 ++++++++- src/osd/ReplicatedBackend.cc | 7 +++++-- src/osd/ReplicatedBackend.h | 5 ++++- src/osd/ReplicatedPG.cc | 4 +++- 8 files changed, 78 insertions(+), 12 deletions(-) diff --git a/src/osd/ECBackend.cc b/src/osd/ECBackend.cc index 8688ad17c61e9..d430ea7d87b65 100644 --- a/src/osd/ECBackend.cc +++ b/src/osd/ECBackend.cc @@ -164,6 +164,22 @@ void ECBackend::RecoveryOp::dump(Formatter *f) const f->dump_stream("extent_requested") << extent_requested; } +ECBackend::ECBackend( + PGBackend::Listener *pg, + coll_t coll, + coll_t temp_coll, + ObjectStore *store, + CephContext *cct, + ErasureCodeInterfaceRef ec_impl, + uint64_t stripe_width) + : PGBackend(pg, store, coll, temp_coll), + cct(cct), + ec_impl(ec_impl), + sinfo(ec_impl->get_data_chunk_count(), stripe_width) { + assert((ec_impl->get_data_chunk_count() * + ec_impl->get_chunk_size(stripe_width)) == stripe_width); +} + PGBackend::RecoveryHandle *ECBackend::open_recovery_op() { return new ECRecoveryHandle; diff --git a/src/osd/ECBackend.h b/src/osd/ECBackend.h index d604093656102..784456342ed52 100644 --- a/src/osd/ECBackend.h +++ b/src/osd/ECBackend.h @@ -442,12 +442,8 @@ public: coll_t temp_coll, ObjectStore *store, CephContext *cct, - ErasureCodeInterfaceRef ec_impl) - : PGBackend(pg, store, coll, temp_coll), - cct(cct), - ec_impl(ec_impl), - stripe_width(ec_impl->get_chunk_count()), - stripe_size(4*(2<<10) /* TODO: make more flexible */) {} + ErasureCodeInterfaceRef ec_impl, + uint64_t stripe_width); /// Returns to_read replicas sufficient to reconstruct want int get_min_avail_to_read_shards( diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index b3204e6996a96..2f7dbaeecfce6 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -1785,7 +1785,8 @@ PG* OSD::_make_pg( PG *pg; hobject_t logoid = make_pg_log_oid(pgid); hobject_t infooid = make_pg_biginfo_oid(pgid); - if (createmap->get_pg_type(pgid.pgid) == pg_pool_t::TYPE_REPLICATED) + if (createmap->get_pg_type(pgid.pgid) == pg_pool_t::TYPE_REPLICATED || + createmap->get_pg_type(pgid.pgid) == pg_pool_t::TYPE_ERASURE) pg = new ReplicatedPG(&service, createmap, pool, pgid, logoid, infooid); else assert(0); diff --git a/src/osd/PGBackend.cc b/src/osd/PGBackend.cc index 1b594f2a1c7c5..3841ede95ca32 100644 --- a/src/osd/PGBackend.cc +++ b/src/osd/PGBackend.cc @@ -14,8 +14,11 @@ #include "common/errno.h" +#include "ReplicatedBackend.h" +#include "ECBackend.h" #include "PGBackend.h" #include "OSD.h" +#include "erasure-code/ErasureCodePlugin.h" #define dout_subsys ceph_subsys_osd #define DOUT_PREFIX_ARGS this @@ -253,6 +256,41 @@ void PGBackend::trim_stashed_object( coll, ghobject_t(hoid, old_version, get_parent()->whoami_shard().shard)); } +PGBackend *PGBackend::build_pg_backend( + const pg_pool_t &pool, + Listener *l, + coll_t coll, + coll_t temp_coll, + ObjectStore *store, + CephContext *cct) +{ + switch (pool.type) { + case pg_pool_t::TYPE_REPLICATED: { + return new ReplicatedBackend(l, coll, temp_coll, store, cct); + } + case pg_pool_t::TYPE_ERASURE: { + ErasureCodeInterfaceRef ec_impl; + assert(pool.properties.count("erasure-code-plugin")); + ceph::ErasureCodePluginRegistry::instance().factory( + pool.properties.find("erasure-code-plugin")->second, + pool.properties, + &ec_impl); + assert(ec_impl); + return new ECBackend( + l, + coll, + temp_coll, + store, + cct, + ec_impl, + pool.stripe_width); + } + default: + assert(0); + return NULL; + } +} + /* * pg lock may or may not be held */ diff --git a/src/osd/PGBackend.h b/src/osd/PGBackend.h index 397efbee7891c..8ea356bd83ab8 100644 --- a/src/osd/PGBackend.h +++ b/src/osd/PGBackend.h @@ -583,13 +583,20 @@ const spg_t pgid, const vector &acting, ostream &errorstream); - virtual uint64_t be_get_ondisk_size( uint64_t logical_size) { assert(0); return 0; } virtual void be_deep_scrub( const hobject_t &poid, ScrubMap::object &o, ThreadPool::TPHandle &handle) { assert(0); } + + static PGBackend *build_pg_backend( + const pg_pool_t &pool, + Listener *l, + coll_t coll, + coll_t temp_coll, + ObjectStore *store, + CephContext *cct); }; struct PG_SendMessageOnConn: public Context { diff --git a/src/osd/ReplicatedBackend.cc b/src/osd/ReplicatedBackend.cc index de550db0cbfb9..6b9e477f563cb 100644 --- a/src/osd/ReplicatedBackend.cc +++ b/src/osd/ReplicatedBackend.cc @@ -29,10 +29,13 @@ static ostream& _prefix(std::ostream *_dout, ReplicatedBackend *pgb) { } ReplicatedBackend::ReplicatedBackend( - PGBackend::Listener *pg, coll_t coll, ObjectStore *store, + PGBackend::Listener *pg, + coll_t coll, + coll_t temp_coll, + ObjectStore *store, CephContext *cct) : PGBackend(pg, store, - coll, coll_t::make_temp_coll(pg->get_info().pgid)), + coll, temp_coll), cct(cct) {} void ReplicatedBackend::run_recovery_op( diff --git a/src/osd/ReplicatedBackend.h b/src/osd/ReplicatedBackend.h index 0d29aed98f70e..ed27314cf0ad3 100644 --- a/src/osd/ReplicatedBackend.h +++ b/src/osd/ReplicatedBackend.h @@ -31,7 +31,10 @@ public: CephContext *cct; ReplicatedBackend( - PGBackend::Listener *pg, coll_t coll, ObjectStore *store, + PGBackend::Listener *pg, + coll_t coll, + coll_t temp_coll, + ObjectStore *store, CephContext *cct); /// @see PGBackend::open_recovery_op diff --git a/src/osd/ReplicatedPG.cc b/src/osd/ReplicatedPG.cc index 2ee37a3fb0c21..8bec51266f0e9 100644 --- a/src/osd/ReplicatedPG.cc +++ b/src/osd/ReplicatedPG.cc @@ -1020,7 +1020,9 @@ ReplicatedPG::ReplicatedPG(OSDService *o, OSDMapRef curmap, const PGPool &_pool, spg_t p, const hobject_t& oid, const hobject_t& ioid) : PG(o, curmap, _pool, p, oid, ioid), - pgbackend(new ReplicatedBackend(this, coll_t(p), o->store, cct)), + pgbackend( + PGBackend::build_pg_backend( + _pool.info, this, coll_t(p), coll_t::make_temp_coll(p), o->store, cct)), snapset_contexts_lock("ReplicatedPG::snapset_contexts"), temp_seq(0), snap_trimmer_machine(this) -- 2.39.5