From: Zhiqiang Wang Date: Tue, 13 Jan 2015 03:55:31 +0000 (+0800) Subject: osd/ReplicatedPG: add helper function check_for_promote X-Git-Tag: v9.1.0~345^2~20 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7e27e6152652e44168dcdb814717253b6c5b146a;p=ceph.git osd/ReplicatedPG: add helper function check_for_promote This function is used to check if we need to initiate a promotion in maybe_handle_cache. Signed-off-by: Zhiqiang Wang Conflicts: src/osd/ReplicatedPG.cc --- diff --git a/src/osd/ReplicatedPG.cc b/src/osd/ReplicatedPG.cc index 5c2c2d908c7a..9047d8bac0ed 100644 --- a/src/osd/ReplicatedPG.cc +++ b/src/osd/ReplicatedPG.cc @@ -1855,35 +1855,9 @@ bool ReplicatedPG::maybe_handle_cache(OpRequestRef op, do_proxy_write(op, missing_oid); // Promote too? - switch (pool.info.min_write_recency_for_promote) { - case 0: - promote_object(obc, missing_oid, oloc, OpRequestRef()); - break; - case 1: - // Check if in the current hit set - if (in_hit_set) { - promote_object(obc, missing_oid, oloc, OpRequestRef()); - } - break; - default: - if (in_hit_set) { - promote_object(obc, missing_oid, oloc, OpRequestRef()); - } else { - // Check if in other hit sets - map::iterator itor; - bool in_other_hit_sets = false; - for (itor = agent_state->hit_set_map.begin(); itor != agent_state->hit_set_map.end(); ++itor) { - if (itor->second->contains(missing_oid)) { - in_other_hit_sets = true; - break; - } - } - if (in_other_hit_sets) { - promote_object(obc, missing_oid, oloc, OpRequestRef()); - } - } - break; - } + maybe_promote(obc, missing_oid, oloc, in_hit_set, + pool.info.min_write_recency_for_promote, + OpRequestRef()); } else { if (can_proxy_read) do_proxy_read(op); @@ -1899,44 +1873,12 @@ bool ReplicatedPG::maybe_handle_cache(OpRequestRef op, } // Promote too? - switch (pool.info.min_read_recency_for_promote) { - case 0: - promote_object(obc, missing_oid, oloc, promote_op); - break; - case 1: - // Check if in the current hit set - if (in_hit_set) { - promote_object(obc, missing_oid, oloc, promote_op); - } else if (!can_proxy_read) { - do_cache_redirect(op); - } - break; - default: - if (in_hit_set) { - promote_object(obc, missing_oid, oloc, promote_op); - } else { - // Check if in other hit sets - map::iterator itor; - bool in_other_hit_sets = false; - for (itor = agent_state->hit_set_map.begin(); itor != agent_state->hit_set_map.end(); ++itor) { - if (obc.get()) { - if (obc->obs.oi.soid != hobject_t() && itor->second->contains(obc->obs.oi.soid)) { - in_other_hit_sets = true; - break; - } - } else { - if (missing_oid != hobject_t() && itor->second->contains(missing_oid)) { - in_other_hit_sets = true; - break; - } - } - } - if (in_other_hit_sets) { - promote_object(obc, missing_oid, oloc, promote_op); - } else if (!can_proxy_read) { - do_cache_redirect(op); - } - } + bool promoted = maybe_promote(obc, missing_oid, oloc, in_hit_set, + pool.info.min_read_recency_for_promote, + promote_op); + if (!promoted && !can_proxy_read) { + // redirect the op if it's not proxied and not promoting + do_cache_redirect(op); } } return true; @@ -1999,6 +1941,62 @@ bool ReplicatedPG::maybe_handle_cache(OpRequestRef op, return false; } +bool ReplicatedPG::maybe_promote(ObjectContextRef obc, + const hobject_t& missing_oid, + const object_locator_t& oloc, + bool in_hit_set, + uint32_t recency, + OpRequestRef promote_op) +{ + dout(20) << __func__ << " missing_oid " << missing_oid + << " in_hit_set " << in_hit_set << dendl; + + switch (recency) { + case 0: + promote_object(obc, missing_oid, oloc, promote_op); + break; + case 1: + // Check if in the current hit set + if (in_hit_set) { + promote_object(obc, missing_oid, oloc, promote_op); + } else { + // not promoting + return false; + } + break; + default: + if (in_hit_set) { + promote_object(obc, missing_oid, oloc, promote_op); + } else { + // Check if in other hit sets + map::iterator itor; + bool in_other_hit_sets = false; + for (itor = agent_state->hit_set_map.begin(); itor != agent_state->hit_set_map.end(); ++itor) { + if (obc.get()) { + if (obc->obs.oi.soid != hobject_t() && itor->second->contains(obc->obs.oi.soid)) { + in_other_hit_sets = true; + break; + } + } else { + if (missing_oid != hobject_t() && itor->second->contains(missing_oid)) { + in_other_hit_sets = true; + break; + } + } + } + if (in_other_hit_sets) { + promote_object(obc, missing_oid, oloc, promote_op); + } else { + // not promoting + return false; + } + } + break; + } + + return true; +} + void ReplicatedPG::do_cache_redirect(OpRequestRef op) { MOSDOp *m = static_cast(op->get_req()); diff --git a/src/osd/ReplicatedPG.h b/src/osd/ReplicatedPG.h index 8f04e43b174f..ec64b21a4a6b 100644 --- a/src/osd/ReplicatedPG.h +++ b/src/osd/ReplicatedPG.h @@ -1209,6 +1209,15 @@ protected: const hobject_t& missing_oid, bool must_promote, bool in_hit_set = false); + /** + * This helper function checks if a promotion is needed. + */ + bool maybe_promote(ObjectContextRef obc, + const hobject_t& missing_oid, + const object_locator_t& oloc, + bool in_hit_set, + uint32_t recency, + OpRequestRef promote_op); /** * This helper function tells the client to redirect their request elsewhere. */