mon: fix full ratio updates

- update them independently
- only if we are leader
- fix type for nearfull_ratio

Signed-off-by: Sage Weil <sage@newdream.net>
This commit is contained in:
Sage Weil 2011-12-30 08:06:55 -08:00
parent f2e4109796
commit 66170633ff
2 changed files with 40 additions and 16 deletions

View File

@ -57,7 +57,8 @@ public:
virtual ~RatioMonitor() {}
virtual const char **get_tracked_conf_keys() const {
static const char *KEYS[] = { "mon_osd_full_ratio",
"mon_osd_nearfull_ratio", NULL };
"mon_osd_nearfull_ratio",
NULL };
return KEYS;
}
virtual void handle_conf_change(const md_config_t *conf,
@ -69,7 +70,9 @@ public:
PGMonitor::PGMonitor(Monitor *mn, Paxos *p)
: PaxosService(mn, p),
ratio_lock("PGMonitor::ratio_lock"), need_ratio_update(false),
ratio_lock("PGMonitor::ratio_lock"),
need_full_ratio_update(false),
need_nearfull_ratio_update(false)
{
ratio_monitor = new RatioMonitor(this);
g_conf->add_observer(ratio_monitor);
@ -134,6 +137,20 @@ void PGMonitor::update_logger()
mon->cluster_logger->set(l_cluster_num_kb, pg_map.pg_sum.stats.sum.num_kb);
}
void PGMonitor::update_full_ratios(float full_ratio, float nearfull_ratio)
{
Mutex::Locker l(ratio_lock);
dout(10) << "update_full_ratios full " << full_ratio << " nearfull " << nearfull_ratio << dendl;
if (full_ratio != 0) {
new_full_ratio = full_ratio;
need_full_ratio_update = true;
}
if (nearfull_ratio != 0) {
new_nearfull_ratio = nearfull_ratio;
need_nearfull_ratio_update = true;
}
}
void PGMonitor::tick()
{
if (!paxos->is_active()) return;
@ -143,13 +160,27 @@ void PGMonitor::tick()
if (mon->is_leader()) {
ratio_lock.Lock();
if (need_ratio_update) {
need_ratio_update = false;
pending_inc.full_ratio = new_full_ratio;
pending_inc.nearfull_ratio = new_nearfull_ratio;
propose_pending();
bool propose = false;
if (need_full_ratio_update) {
dout(10) << "tick need full ratio update " << new_full_ratio << dendl;
need_full_ratio_update = false;
if (pg_map.full_ratio != new_full_ratio) {
pending_inc.full_ratio = new_full_ratio;
propose = true;
}
}
if (need_nearfull_ratio_update) {
dout(10) << "tick need nearfull ratio update " << new_nearfull_ratio << dendl;
need_nearfull_ratio_update = false;
if (pg_map.nearfull_ratio != new_nearfull_ratio) {
pending_inc.nearfull_ratio = new_nearfull_ratio;
propose = true;
}
}
ratio_lock.Unlock();
if (propose) {
propose_pending();
}
}
dout(10) << pg_map << dendl;

View File

@ -44,7 +44,7 @@ public:
PGMap pg_map;
Mutex ratio_lock;
bool need_ratio_update;
bool need_full_ratio_update, need_nearfull_ratio_update;
float new_full_ratio, new_nearfull_ratio;
private:
@ -66,14 +66,7 @@ private:
bool prepare_pg_stats(MPGStats *stats);
void _updated_stats(MPGStats *req, MPGStatsAck *ack);
void update_full_ratios(float full_ratio, int nearfull_ratio) {
Mutex::Locker l(ratio_lock);
if (full_ratio != 0)
new_full_ratio = full_ratio;
if (nearfull_ratio != 0)
new_nearfull_ratio = nearfull_ratio;
need_ratio_update = true;
}
void update_full_ratios(float full_ratio, float nearfull_ratio);
struct C_Stats : public Context {
PGMonitor *pgmon;