]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/ReplicatedPG: add helper function check_for_promote
authorZhiqiang Wang <zhiqiang.wang@intel.com>
Tue, 13 Jan 2015 03:55:31 +0000 (11:55 +0800)
committerSamuel Just <sjust@redhat.com>
Tue, 18 Aug 2015 18:25:22 +0000 (11:25 -0700)
This function is used to check if we need to initiate a promotion in
maybe_handle_cache.

Signed-off-by: Zhiqiang Wang <zhiqiang.wang@intel.com>
Conflicts:
src/osd/ReplicatedPG.cc

src/osd/ReplicatedPG.cc
src/osd/ReplicatedPG.h

index 5c2c2d908c7a32f6a000e918af66d61ab591ff26..9047d8bac0ed0d9e66235ced7284e7ddacf33044 100644 (file)
@@ -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<time_t,HitSetRef>::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<time_t,HitSetRef>::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<time_t,HitSetRef>::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<MOSDOp*>(op->get_req());
index 8f04e43b174feaae5a73c2c65fb263a8e164a23e..ec64b21a4a6b1260bbdba7576d558864925e6a1a 100644 (file)
@@ -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.
    */