From 460a4622c1dbbdeca68b40007231e6489bc61f02 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 1 Feb 2012 13:03:08 -0800 Subject: [PATCH] osd: PG::Query -> pg_query_t Signed-off-by: Sage Weil --- src/messages/MOSDPGQuery.h | 6 +-- src/osd/OSD.cc | 26 ++++++------ src/osd/OSD.h | 4 +- src/osd/PG.cc | 36 ++++++++--------- src/osd/PG.h | 82 ++++++-------------------------------- src/osd/osd_types.cc | 23 +++++++++++ src/osd/osd_types.h | 59 +++++++++++++++++++++++++++ 7 files changed, 131 insertions(+), 105 deletions(-) diff --git a/src/messages/MOSDPGQuery.h b/src/messages/MOSDPGQuery.h index 8e8a84b1cf130..358f439072636 100644 --- a/src/messages/MOSDPGQuery.h +++ b/src/messages/MOSDPGQuery.h @@ -27,10 +27,10 @@ class MOSDPGQuery : public Message { public: version_t get_epoch() { return epoch; } - map pg_list; + map pg_list; MOSDPGQuery() {} - MOSDPGQuery(epoch_t e, map& ls) : + MOSDPGQuery(epoch_t e, map& ls) : Message(MSG_OSD_PG_QUERY), epoch(e) { pg_list.swap(ls); @@ -42,7 +42,7 @@ public: const char *get_type_name() const { return "pg_query"; } void print(ostream& out) const { out << "pg_query("; - for (map::const_iterator p = pg_list.begin(); p != pg_list.end(); ++p) { + for (map::const_iterator p = pg_list.begin(); p != pg_list.end(); ++p) { if (p != pg_list.begin()) out << ","; out << p->first; diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 316e7ca5c13f1..b1b6f93cc8941 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -3600,7 +3600,7 @@ void OSD::activate_map(ObjectStore::Transaction& t, list& tfin) dout(7) << "activate_map version " << osdmap->get_epoch() << dendl; map< int, vector > notify_list; // primary -> list - map< int, map > query_map; // peer -> PG -> get_summary_since + map< int, map > query_map; // peer -> PG -> get_summary_since map info_map; // peer -> message int num_pg_primary = 0, num_pg_replica = 0, num_pg_stray = 0; @@ -3963,7 +3963,7 @@ bool OSD::can_create_pg(pg_t pgid) void OSD::kick_pg_split_queue() { - map< int, map > query_map; + map< int, map > query_map; map info_map; int created = 0; @@ -4161,7 +4161,7 @@ void OSD::handle_pg_create(MOSDPGCreate *m) if (!require_same_or_newer_map(m, m->epoch)) return; - map< int, map > query_map; + map< int, map > query_map; map info_map; int num_created = 0; @@ -4232,7 +4232,7 @@ void OSD::handle_pg_create(MOSDPGCreate *m) << " : querying priors " << pset << dendl; for (set::iterator p = pset.begin(); p != pset.end(); p++) if (osdmap->is_up(*p)) - query_map[*p][pgid] = PG::Query(PG::Query::INFO, history); + query_map[*p][pgid] = pg_query_t(pg_query_t::INFO, history); if (can_create_pg(pgid)) { ObjectStore::Transaction *t = new ObjectStore::Transaction; @@ -4296,9 +4296,9 @@ void OSD::do_notifies(map< int, vector >& notify_list, /** do_queries * send out pending queries for info | summaries */ -void OSD::do_queries(map< int, map >& query_map) +void OSD::do_queries(map< int, map >& query_map) { - for (map< int, map >::iterator pit = query_map.begin(); + for (map< int, map >::iterator pit = query_map.begin(); pit != query_map.end(); pit++) { int who = pit->first; @@ -4343,7 +4343,7 @@ void OSD::handle_pg_notify(MOSDPGNotify *m) if (!require_same_or_newer_map(m, m->get_epoch())) return; // look for unknown PGs i'm primary for - map< int, map > query_map; + map< int, map > query_map; map info_map; int created = 0; @@ -4413,7 +4413,7 @@ void OSD::handle_pg_log(MOSDPGLog *m) return; } - map< int, map > query_map; + map< int, map > query_map; map< int, MOSDPGInfo* > info_map; PG::RecoveryCtx rctx(&query_map, &info_map, 0, &fin->contexts, t); pg->handle_log(from, m, &rctx); @@ -4612,7 +4612,7 @@ void OSD::handle_pg_missing(MOSDPGMissing *m) if (!require_same_or_newer_map(m, m->get_epoch())) return; - map< int, map > query_map; + map< int, map > query_map; PG::Log empty_log; int created = 0; _pro-cess_pg_info(m->get_epoch(), from, m->info, //misspelling added to prevent erroneous finds @@ -4643,7 +4643,7 @@ void OSD::handle_pg_query(MOSDPGQuery *m) map< int, vector > notify_list; - for (map::iterator it = m->pg_list.begin(); + for (map::iterator it = m->pg_list.begin(); it != m->pg_list.end(); it++) { pg_t pgid = it->first; @@ -4668,8 +4668,8 @@ void OSD::handle_pg_query(MOSDPGQuery *m) assert(role != 0); dout(10) << " pg " << pgid << " dne" << dendl; pg_info_t empty(pgid); - if (it->second.type == PG::Query::LOG || - it->second.type == PG::Query::FULLLOG) { + if (it->second.type == pg_query_t::LOG || + it->second.type == pg_query_t::FULLLOG) { MOSDPGLog *mlog = new MOSDPGLog(osdmap->get_epoch(), empty, m->get_epoch()); _share_map_outgoing(osdmap->get_cluster_inst(from)); @@ -5018,7 +5018,7 @@ void OSD::do_recovery(PG *pg) * out while trying to pull. */ if (!started && pg->have_unfound()) { - map< int, map > query_map; + map< int, map > query_map; pg->discover_all_missing(query_map); if (query_map.size()) do_queries(query_map); diff --git a/src/osd/OSD.h b/src/osd/OSD.h index 5b301831b892e..1afcf65ff237e 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -581,9 +581,9 @@ protected: // -- generic pg peering -- void do_notifies(map< int, vector >& notify_list, epoch_t query_epoch); - void do_queries(map< int, map >& query_map); + void do_queries(map< int, map >& query_map); void do_infos(map& info_map); - void repeer(PG *pg, map< int, map >& query_map); + void repeer(PG *pg, map< int, map >& query_map); bool require_mon_peer(Message *m); bool require_osd_peer(Message *m); diff --git a/src/osd/PG.cc b/src/osd/PG.cc index d39171c356b25..27d4c64703c4c 100644 --- a/src/osd/PG.cc +++ b/src/osd/PG.cc @@ -573,7 +573,7 @@ bool PG::search_for_missing(const pg_info_t &oinfo, const Missing *omissing, return found_missing; } -void PG::discover_all_missing(map< int, map > &query_map) +void PG::discover_all_missing(map< int, map > &query_map) { assert(missing.have_missing()); @@ -616,7 +616,7 @@ void PG::discover_all_missing(map< int, map > &query_map) << dendl; peer_missing_requested.insert(peer); query_map[peer][info.pgid] = - PG::Query(PG::Query::MISSING, info.history); + pg_query_t(pg_query_t::MISSING, info.history); } } @@ -1169,7 +1169,7 @@ struct C_PG_ActivateCommitted : public Context { }; void PG::activate(ObjectStore::Transaction& t, list& tfin, - map< int, map >& query_map, + map< int, map >& query_map, map *activator_map) { assert(!is_active()); @@ -3117,41 +3117,41 @@ void PG::share_pg_log() } } -void PG::fulfill_info(int from, const Query &query, +void PG::fulfill_info(int from, const pg_query_t &query, pair ¬ify_info) { assert(!acting.empty()); assert(from == acting[0]); - assert(query.type == PG::Query::INFO); + assert(query.type == pg_query_t::INFO); // info dout(10) << "sending info" << dendl; notify_info = make_pair(from, info); } -void PG::fulfill_log(int from, const Query &query, epoch_t query_epoch) +void PG::fulfill_log(int from, const pg_query_t &query, epoch_t query_epoch) { assert(!acting.empty()); assert(from == acting[0]); - assert(query.type != PG::Query::INFO); + assert(query.type != pg_query_t::INFO); MOSDPGLog *mlog = new MOSDPGLog(get_osdmap()->get_epoch(), info, query_epoch); mlog->missing = missing; // primary -> other, when building master log - if (query.type == PG::Query::LOG) { + if (query.type == pg_query_t::LOG) { dout(10) << " sending info+missing+log since " << query.since << dendl; if (query.since != eversion_t() && query.since < log.tail) { - osd->clog.error() << info.pgid << " got broken Query::LOG since " << query.since + osd->clog.error() << info.pgid << " got broken pg_query_t::LOG since " << query.since << " when my log.tail is " << log.tail << ", sending full log instead\n"; mlog->log = log; // primary should not have requested this!! } else mlog->log.copy_after(log, query.since); } - else if (query.type == PG::Query::FULLLOG) { + else if (query.type == pg_query_t::FULLLOG) { dout(10) << " sending info+missing+full log" << dendl; mlog->log = log; } @@ -4047,7 +4047,7 @@ PG::RecoveryState::ReplicaActive::ReplicaActive(my_context ctx) context< RecoveryMachine >().log_enter(state_name); dout(10) << "In ReplicaActive, about to call activate" << dendl; PG *pg = context< RecoveryMachine >().pg; - map< int, map< pg_t, Query> > query_map; + map< int, map< pg_t, pg_query_t> > query_map; pg->activate(*context< RecoveryMachine >().get_cur_transaction(), *context< RecoveryMachine >().get_context_list(), query_map, NULL); @@ -4089,7 +4089,7 @@ boost::statechart::result PG::RecoveryState::ReplicaActive::react(const ActMap&) boost::statechart::result PG::RecoveryState::ReplicaActive::react(const MQuery& query) { PG *pg = context< RecoveryMachine >().pg; - assert(query.query.type == Query::MISSING); + assert(query.query.type == pg_query_t::MISSING); pg->fulfill_log(query.from, query.query, query.query_epoch); return discard_event(); } @@ -4150,7 +4150,7 @@ boost::statechart::result PG::RecoveryState::Stray::react(const MInfoRec& infoev boost::statechart::result PG::RecoveryState::Stray::react(const MQuery& query) { PG *pg = context< RecoveryMachine >().pg; - if (query.query.type == Query::INFO) { + if (query.query.type == pg_query_t::INFO) { pair notify_info; pg->fulfill_info(query.from, query.query, notify_info); context< RecoveryMachine >().send_notify(notify_info.first, notify_info.second); @@ -4217,7 +4217,7 @@ void PG::RecoveryState::GetInfo::get_infos() dout(10) << " not querying info from down osd." << peer << dendl; } else { dout(10) << " querying info from osd." << peer << dendl; - context< RecoveryMachine >().send_query(peer, Query(Query::INFO, pg->info.history)); + context< RecoveryMachine >().send_query(peer, pg_query_t(pg_query_t::INFO, pg->info.history)); peer_info_requested.insert(peer); } } @@ -4350,7 +4350,7 @@ PG::RecoveryState::GetLog::GetLog(my_context ctx) : // how much? dout(10) << " requesting log from osd." << newest_update_osd << dendl; context().send_query(newest_update_osd, - Query(Query::LOG, request_log_from, pg->info.history)); + pg_query_t(pg_query_t::LOG, request_log_from, pg->info.history)); } boost::statechart::result PG::RecoveryState::GetLog::react(const MLogRec& logevt) @@ -4489,12 +4489,12 @@ PG::RecoveryState::GetMissing::GetMissing(my_context ctx) assert(pi.last_update >= pg->info.log_tail); // or else choose_acting() did a bad thing if (pi.log_tail <= since) { dout(10) << " requesting log+missing since " << since << " from osd." << *i << dendl; - context< RecoveryMachine >().send_query(*i, Query(Query::LOG, since, pg->info.history)); + context< RecoveryMachine >().send_query(*i, pg_query_t(pg_query_t::LOG, since, pg->info.history)); } else { dout(10) << " requesting fulllog+missing from osd." << *i << " (want since " << since << " < log.tail " << pi.log_tail << ")" << dendl; - context< RecoveryMachine >().send_query(*i, Query(Query::FULLLOG, pg->info.history)); + context< RecoveryMachine >().send_query(*i, pg_query_t(pg_query_t::FULLLOG, pg->info.history)); } peer_missing_requested.insert(*i); } @@ -4623,7 +4623,7 @@ void PG::RecoveryState::handle_log(int from, end_handle(); } -void PG::RecoveryState::handle_query(int from, const PG::Query& q, +void PG::RecoveryState::handle_query(int from, const pg_query_t& q, epoch_t query_epoch, RecoveryCtx *rctx) { diff --git a/src/osd/PG.h b/src/osd/PG.h index 9d519c7ced29f..dd42f086d3999 100644 --- a/src/osd/PG.h +++ b/src/osd/PG.h @@ -160,52 +160,6 @@ public: std::string gen_prefix() const; - /** - * Query - used to ask a peer for information about a pg. - * - * note: if version=0, type=LOG, then we just provide our full log. - */ - struct Query { - enum { - INFO = 0, - LOG = 1, - MISSING = 4, - FULLLOG = 5, - }; - const char *get_type_name() const { - switch (type) { - case INFO: return "info"; - case LOG: return "log"; - case MISSING: return "missing"; - case FULLLOG: return "fulllog"; - default: return "???"; - } - } - - __s32 type; - eversion_t since; - pg_history_t history; - - Query() : type(-1) {} - Query(int t, const pg_history_t& h) : - type(t), history(h) { assert(t != LOG); } - Query(int t, eversion_t s, const pg_history_t& h) : - type(t), since(s), history(h) { assert(t == LOG); } - - void encode(bufferlist &bl) const { - ::encode(type, bl); - ::encode(since, bl); - history.encode(bl); - } - void decode(bufferlist::iterator &bl) { - ::decode(type, bl); - ::decode(since, bl); - history.decode(bl); - } - }; - WRITE_CLASS_ENCODER(Query) - - /* * Log - incremental log of recent pg changes. * serves as a recovery queue for recent changes. @@ -829,14 +783,14 @@ public: public: struct RecoveryCtx { utime_t start_time; - map< int, map > *query_map; + map< int, map > *query_map; map< int, MOSDPGInfo* > *info_map; map< int, vector > *notify_list; list< Context* > *context_list; ObjectStore::Transaction *transaction; RecoveryCtx() : query_map(0), info_map(0), notify_list(0), context_list(0), transaction(0) {} - RecoveryCtx(map< int, map > *query_map, + RecoveryCtx(map< int, map > *query_map, map< int, MOSDPGInfo* > *info_map, map< int, vector > *notify_list, list< Context* > *context_list, @@ -896,9 +850,9 @@ public: struct MQuery : boost::statechart::event< MQuery > { int from; - const Query &query; + const pg_query_t &query; epoch_t query_epoch; - MQuery(int from, const Query &query, epoch_t query_epoch): + MQuery(int from, const pg_query_t &query, epoch_t query_epoch): from(from), query(query), query_epoch(query_epoch) {} }; @@ -959,12 +913,12 @@ public: return state->rctx->transaction; } - void send_query(int to, const Query &query) { + void send_query(int to, const pg_query_t &query) { assert(state->rctx->query_map); (*state->rctx->query_map)[to][pg->info.pgid] = query; } - map > *get_query_map() { + map > *get_query_map() { assert(state->rctx->query_map); return state->rctx->query_map; } @@ -1164,7 +1118,7 @@ public: }; struct Stray : boost::statechart::state< Stray, Started >, NamedState { - map > pending_queries; + map > pending_queries; Stray(my_context ctx); void exit(); @@ -1261,7 +1215,7 @@ public: void handle_log(int from, MOSDPGLog *msg, RecoveryCtx *ctx); - void handle_query(int from, const PG::Query& q, + void handle_query(int from, const pg_query_t& q, epoch_t query_epoch, RecoveryCtx *ctx); void handle_advance_map(OSDMapRef osdmap, OSDMapRef lastmap, @@ -1446,7 +1400,7 @@ public: void check_for_lost_objects(); void forget_lost_objects(); - void discover_all_missing(std::map< int, map > &query_map); + void discover_all_missing(std::map< int, map > &query_map); void trim_write_ahead(); @@ -1456,7 +1410,7 @@ public: void build_might_have_unfound(); void replay_queued_ops(); void activate(ObjectStore::Transaction& t, list& tfin, - map< int, map >& query_map, + map< int, map >& query_map, map *activator_map=0); void _activate_committed(epoch_t e); void all_activated_and_committed(); @@ -1639,9 +1593,9 @@ public: const vector& newacting); void set_last_peering_reset(); - void fulfill_info(int from, const Query &query, + void fulfill_info(int from, const pg_query_t &query, pair ¬ify_info); - void fulfill_log(int from, const Query &query, epoch_t query_epoch); + void fulfill_log(int from, const pg_query_t &query, epoch_t query_epoch); bool acting_up_affected(const vector& newup, const vector& newacting); bool old_peering_msg(epoch_t reply_epoch, epoch_t query_epoch); @@ -1657,7 +1611,7 @@ public: RecoveryCtx *rctx) { recovery_state.handle_log(from, msg, rctx); } - void handle_query(int from, const PG::Query& q, + void handle_query(int from, const pg_query_t& q, epoch_t query_epoch, RecoveryCtx *rctx) { recovery_state.handle_query(from, q, query_epoch, rctx); @@ -1709,7 +1663,6 @@ public: utime_t expire) = 0; }; -WRITE_CLASS_ENCODER(PG::Query) WRITE_CLASS_ENCODER(PG::Missing::item) WRITE_CLASS_ENCODER(PG::Missing) WRITE_CLASS_ENCODER(PG::Log::Entry) @@ -1717,15 +1670,6 @@ WRITE_CLASS_ENCODER(PG::Log) WRITE_CLASS_ENCODER(PG::Interval) WRITE_CLASS_ENCODER(PG::OndiskLog) -inline ostream& operator<<(ostream& out, const PG::Query& q) -{ - out << "query(" << q.get_type_name() << " " << q.since; - if (q.type == PG::Query::LOG) - out << " " << q.history; - out << ")"; - return out; -} - inline ostream& operator<<(ostream& out, const PG::Log::Entry& e) { return out << e.version << " (" << e.prior_version << ") " diff --git a/src/osd/osd_types.cc b/src/osd/osd_types.cc index bc68648654500..4f9f470e3a00a 100644 --- a/src/osd/osd_types.cc +++ b/src/osd/osd_types.cc @@ -1085,6 +1085,29 @@ void pg_info_t::generate_test_instances(list& o) } +// -- pg_query_t -- + +void pg_query_t::dump(Formatter *f) const +{ + f->dump_string("type", get_type_name()); + f->dump_stream("since") << since; + f->open_object_section("history"); + history.dump(f); + f->close_section(); +} +void pg_query_t::generate_test_instances(list& o) +{ + o.push_back(new pg_query_t()); + list h; + pg_history_t::generate_test_instances(h); + o.push_back(new pg_query_t(pg_query_t::INFO, *h.back())); + o.push_back(new pg_query_t(pg_query_t::MISSING, *h.back())); + o.push_back(new pg_query_t(pg_query_t::LOG, eversion_t(4, 5), *h.back())); + o.push_back(new pg_query_t(pg_query_t::FULLLOG, *h.back())); +} + + + // -- OSDSuperblock -- void OSDSuperblock::encode(bufferlist &bl) const diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index 0d14ab52da242..0baf99f2190b6 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -959,6 +959,65 @@ inline ostream& operator<<(ostream& out, const pg_info_t& pgi) } +/** + * pg_query_t - used to ask a peer for information about a pg. + * + * note: if version=0, type=LOG, then we just provide our full log. + */ +struct pg_query_t { + enum { + INFO = 0, + LOG = 1, + MISSING = 4, + FULLLOG = 5, + }; + const char *get_type_name() const { + switch (type) { + case INFO: return "info"; + case LOG: return "log"; + case MISSING: return "missing"; + case FULLLOG: return "fulllog"; + default: return "???"; + } + } + + __s32 type; + eversion_t since; + pg_history_t history; + + pg_query_t() : type(-1) {} + pg_query_t(int t, const pg_history_t& h) + : type(t), history(h) { + assert(t != LOG); + } + pg_query_t(int t, eversion_t s, const pg_history_t& h) + : type(t), since(s), history(h) { + assert(t == LOG); + } + + void encode(bufferlist &bl) const { + ::encode(type, bl); + ::encode(since, bl); + history.encode(bl); + } + void decode(bufferlist::iterator &bl) { + ::decode(type, bl); + ::decode(since, bl); + history.decode(bl); + } + void dump(Formatter *f) const; + static void generate_test_instances(list& o); +}; +WRITE_CLASS_ENCODER(pg_query_t) + +inline ostream& operator<<(ostream& out, const pg_query_t& q) { + out << "query(" << q.get_type_name() << " " << q.since; + if (q.type == pg_query_t::LOG) + out << " " << q.history; + out << ")"; + return out; +} + struct osd_peer_stat_t { -- 2.39.5