#undef dout_prefix
#define dout_prefix _prefix(*_dout, whoami, osdmap)
-static ostream& _prefix(std::ostream* _dout, int whoami, OSDMap *osdmap) {
+static ostream& _prefix(std::ostream* _dout, int whoami, OSDMapRef osdmap) {
return *_dout << "osd." << whoami << " " << (osdmap ? osdmap->get_epoch():0) << " ";
}
stat_lock("OSD::stat_lock"),
finished_lock("OSD::finished_lock"),
op_wq(this, g_conf->osd_op_thread_timeout, &op_tp),
- osdmap(NULL),
map_lock("OSD::map_lock"),
peer_map_epoch_lock("OSD::peer_map_epoch_lock"),
map_cache_lock("OSD::map_cache_lock"),
map_in_progress_cond = new Cond();
- osdmap = 0;
-
pending_ops = 0;
waiting_for_no_ops = false;
}
delete watch;
clear_map_cache();
- osdmap = 0;
-
return r;
}
dout(15) << "calc_priors_during " << pgid << " [" << start << "," << end << ")" << dendl;
for (epoch_t e = start; e < end; e++) {
- OSDMap *oldmap = get_map(e);
+ OSDMapRef oldmap = get_map(e);
vector<int> acting;
oldmap->pg_to_acting_osds(pgid, acting);
dout(20) << " " << pgid << " in epoch " << e << " was " << acting << dendl;
e > from;
e--) {
// verify during intermediate epoch (e-1)
- OSDMap *oldmap = get_map(e-1);
+ OSDMapRef oldmap = get_map(e-1);
vector<int> up, acting;
oldmap->pg_to_up_acting_osds(pgid, up, acting);
OSDMap *o = new OSDMap;
if (e > 1) {
bufferlist obl;
- OSDMap *prev = get_map(e - 1);
+ OSDMapRef prev = get_map(e - 1);
prev->encode(obl);
o->decode(obl);
}
// check for cluster snapshot
string cluster_snap;
for (epoch_t cur = start; cur <= last && cluster_snap.length() == 0; cur++) {
- OSDMap *newmap = get_map(cur);
+ OSDMapRef newmap = get_map(cur);
cluster_snap = newmap->get_cluster_snapshot();
}
for (epoch_t cur = start; cur <= superblock.newest_map; cur++) {
dout(10) << " advance to epoch " << cur << " (<= newest " << superblock.newest_map << ")" << dendl;
- OSDMap *newmap = get_map(cur);
+ OSDMapRef newmap = get_map(cur);
assert(newmap); // we just cached it above!
// kill connections to newly down osds
}
// if we skipped a discontinuity and are the first epoch, we won't have a previous map.
- OSDMap *lastmap = NULL;
+ OSDMapRef lastmap;
if (osdmap->get_epoch() > superblock.oldest_map)
lastmap = get_map(osdmap->get_epoch() - 1);
return store->read(coll_t::META_COLL, get_inc_osdmap_pobject_name(e), 0, 0, bl) >= 0;
}
-void OSD::add_map(OSDMap *o)
+OSDMapRef OSD::add_map(OSDMap *o)
{
Mutex::Locker l(map_cache_lock);
epoch_t e = o->get_epoch();
if (map_cache.count(e) == 0) {
dout(10) << "add_map " << e << " " << o << dendl;
- map_cache[e] = o;
+ map_cache.insert(make_pair(e, OSDMapRef(o)));
} else {
dout(10) << "add_map " << e << " already have it" << dendl;
}
+ return map_cache[e];
}
void OSD::add_map_bl(epoch_t e, bufferlist& bl)
map_inc_bl[e] = bl;
}
-OSDMap *OSD::get_map(epoch_t epoch)
+OSDMapRef OSD::get_map(epoch_t epoch)
{
{
Mutex::Locker l(map_cache_lock);
- map<epoch_t,OSDMap*>::iterator p = map_cache.find(epoch);
+ map<epoch_t,OSDMapRef>::iterator p = map_cache.find(epoch);
if (p != map_cache.end()) {
dout(30) << "get_map " << epoch << " - cached " << p->second << dendl;
return p->second;
} else {
dout(20) << "get_map " << epoch << " - return initial " << map << dendl;
}
- add_map(map);
- return map;
+ return add_map(map);
}
void OSD::trim_map_bl_cache(epoch_t oldest)
(map_cache.begin()->first < oldest ||
(int)map_cache.size() > g_conf->osd_map_cache_max)) {
epoch_t e = map_cache.begin()->first;
- OSDMap *o = map_cache.begin()->second;
+ OSDMapRef o = map_cache.begin()->second;
dout(10) << "trim_map_cache " << e << " " << o << dendl;
- delete o;
map_cache.erase(map_cache.begin());
}
}
void OSD::clear_map_cache()
{
while (!map_cache.empty()) {
- OSDMap *o = map_cache.begin()->second;
- delete o;
map_cache.erase(map_cache.begin());
}
}
#include <map>
#include <memory>
+#include <tr1/memory>
using namespace std;
#include <ext/hash_map>
protected:
// -- osd map --
- OSDMap *osdmap;
+ OSDMapRef osdmap;
utime_t had_map_since;
RWLock map_lock;
list<Message*> waiting_for_osdmap;
void activate_map(ObjectStore::Transaction& t, list<Context*>& tfin);
// osd map cache (past osd maps)
- map<epoch_t,OSDMap*> map_cache;
+ map<epoch_t,OSDMapRef > map_cache;
map<epoch_t,bufferlist> map_inc_bl;
map<epoch_t,bufferlist> map_bl;
Mutex map_cache_lock;
- OSDMap* get_map(epoch_t e);
- void add_map(OSDMap *o);
+ OSDMapRef get_map(epoch_t e);
+ OSDMapRef add_map(OSDMap *o);
void add_map_bl(epoch_t e, bufferlist& bl);
void add_map_inc_bl(epoch_t e, bufferlist& bl);
void trim_map_cache(epoch_t oldest);
#include <list>
#include <set>
#include <map>
+#include <tr1/memory>
using namespace std;
#include <ext/hash_set>
};
+typedef std::tr1::shared_ptr<OSDMap> OSDMapRef;
+
inline ostream& operator<<(ostream& out, const OSDMap& m) {
m.print_summary(out);
return out;
dout(10) << __func__ << " over epochs " << stop << "-" << last_epoch << dendl;
- OSDMap *nextmap = osd->get_map(last_epoch);
+ OSDMapRef nextmap = osd->get_map(last_epoch);
for (;
last_epoch >= stop;
last_epoch = first_epoch - 1) {
- OSDMap *lastmap = nextmap;
+ OSDMapRef lastmap = nextmap;
vector<int> tup, tacting;
lastmap->pg_to_up_acting_osds(get_pgid(), tup, tacting);
}
-bool PG::adjust_need_up_thru(const OSDMap *osdmap)
+bool PG::adjust_need_up_thru(const OSDMapRef osdmap)
{
epoch_t up_thru = osd->osdmap->get_up_thru(osd->whoami);
if (need_up_thru &&
/*
* Returns true unless there is a non-lost OSD in might_have_unfound.
*/
-bool PG::all_unfound_are_queried_or_lost(const OSDMap* osdmap) const
+bool PG::all_unfound_are_queried_or_lost(const OSDMapRef osdmap) const
{
assert(is_primary());
// true if all OSDs in prior intervals may have crashed, and we need to replay
// false positives are okay, false negatives are not.
-bool PG::may_need_replay(const OSDMap *osdmap) const
+bool PG::may_need_replay(const OSDMapRef osdmap) const
{
bool crashed = false;
}
/* Called before initializing peering during advance_map */
-void PG::start_peering_interval(const OSDMap *lastmap,
+void PG::start_peering_interval(const OSDMapRef lastmap,
const vector<int>& newup,
const vector<int>& newacting)
{
- const OSDMap *osdmap = osd->osdmap;
+ const OSDMapRef osdmap = osd->osdmap;
// -- there was a change! --
kick();
PG::RecoveryState::Primary::react(const AdvMap& advmap)
{
PG *pg = context< RecoveryMachine >().pg;
- OSDMap *osdmap = advmap.osdmap;
+ OSDMapRef osdmap = advmap.osdmap;
// Remove any downed osds from peer_info
map<int,PG::Info>::iterator p = pg->peer_info.begin();
end_handle();
}
-void PG::RecoveryState::handle_advance_map(OSDMap *osdmap, OSDMap *lastmap,
+void PG::RecoveryState::handle_advance_map(OSDMapRef osdmap, OSDMapRef lastmap,
vector<int>& newup, vector<int>& newacting,
RecoveryCtx *rctx)
{
}
// true if the given map affects the prior set
-bool PG::PriorSet::affected_by_map(const OSDMap *osdmap, const PG *debug_pg) const
+bool PG::PriorSet::affected_by_map(const OSDMapRef osdmap, const PG *debug_pg) const
{
for (set<int>::iterator p = probe.begin();
p != probe.end();
const Info &info,
const PG *debug_pg=NULL);
- bool affected_by_map(const OSDMap *osdmap, const PG *debug_pg=0) const;
+ bool affected_by_map(const OSDMapRef osdmap, const PG *debug_pg=0) const;
};
friend std::ostream& operator<<(std::ostream& oss,
const struct PriorSet &prior);
- bool may_need_replay(const OSDMap *osdmap) const;
+ bool may_need_replay(const OSDMapRef osdmap) const;
public:
};
struct AdvMap : boost::statechart::event< AdvMap > {
- OSDMap *osdmap;
- OSDMap *lastmap;
+ OSDMapRef osdmap;
+ OSDMapRef lastmap;
vector<int> newup, newacting;
- AdvMap(OSDMap *osdmap, OSDMap *lastmap, vector<int>& newup, vector<int>& newacting):
+ AdvMap(OSDMapRef osdmap, OSDMapRef lastmap, vector<int>& newup, vector<int>& newacting):
osdmap(osdmap), lastmap(lastmap), newup(newup), newacting(newacting) {}
};
void handle_query(int from, const PG::Query& q,
epoch_t query_epoch,
RecoveryCtx *ctx);
- void handle_advance_map(OSDMap *osdmap, OSDMap *lastmap,
+ void handle_advance_map(OSDMapRef osdmap, OSDMapRef lastmap,
vector<int>& newup, vector<int>& newacting,
RecoveryCtx *ctx);
void handle_activate_map(RecoveryCtx *ctx);
void build_prior(std::auto_ptr<PriorSet> &prior_set);
void clear_prior();
- bool adjust_need_up_thru(const OSDMap *osdmap);
+ bool adjust_need_up_thru(const OSDMapRef osdmap);
- bool all_unfound_are_queried_or_lost(const OSDMap* osdmap) const;
+ bool all_unfound_are_queried_or_lost(const OSDMapRef osdmap) const;
virtual void mark_all_unfound_lost(int how) = 0;
bool calc_min_last_complete_ondisk() {
void clear_recovery_state();
virtual void _clear_recovery_state() = 0;
void defer_recovery();
- virtual void check_recovery_op_pulls(const OSDMap *newmap) = 0;
+ virtual void check_recovery_op_pulls(const OSDMapRef newmap) = 0;
void start_recovery_op(const hobject_t& soid);
void finish_recovery_op(const hobject_t& soid, bool dequeue=false);
/// share new pg log entries after a pg is active
void share_pg_log();
- void start_peering_interval(const OSDMap *lastmap,
+ void start_peering_interval(const OSDMapRef lastmap,
const vector<int>& newup,
const vector<int>& newacting);
void set_last_peering_reset();
RecoveryCtx *rctx) {
recovery_state.handle_query(from, q, query_epoch, rctx);
}
- void handle_advance_map(OSDMap *osdmap, OSDMap *lastmap,
+ void handle_advance_map(OSDMapRef osdmap, OSDMapRef lastmap,
vector<int>& newup, vector<int>& newacting,
RecoveryCtx *rctx) {
recovery_state.handle_advance_map(osdmap, lastmap, newup, newacting, rctx);
#define DOUT_PREFIX_ARGS this, osd->whoami, osd->osdmap
#undef dout_prefix
#define dout_prefix _prefix(_dout, this, osd->whoami, osd->osdmap)
-static ostream& _prefix(std::ostream *_dout, PG *pg, int whoami, OSDMap *osdmap) {
+static ostream& _prefix(std::ostream *_dout, PG *pg, int whoami, OSDMapRef osdmap) {
return *_dout << "osd." << whoami
<< " " << (osdmap ? osdmap->get_epoch():0) << " " << *pg << " ";
}
pull_from_peer.clear();
}
-void ReplicatedPG::check_recovery_op_pulls(const OSDMap *osdmap)
+void ReplicatedPG::check_recovery_op_pulls(const OSDMapRef osdmap)
{
for (map<int, set<hobject_t> >::iterator j = pull_from_peer.begin();
j != pull_from_peer.end();
void send_push_op_blank(const hobject_t& soid, int peer);
// Cancels/resets pulls from peer
- void check_recovery_op_pulls(const OSDMap *map);
+ void check_recovery_op_pulls(const OSDMapRef map);
int pull(const hobject_t& oid, eversion_t v);
void send_pull_op(const hobject_t& soid, eversion_t v, bool first, const interval_set<uint64_t>& data_subset, int fromosd);