summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/plan_yield_policy.h
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2014-10-21 10:24:24 -0400
committerDavid Storch <david.storch@10gen.com>2014-10-21 10:32:59 -0400
commit011dde7e6eac3b73cb1d2a7f004feee9bed99c46 (patch)
tree32b20bc3224627c93e5781ba72abb45a1f825b37 /src/mongo/db/query/plan_yield_policy.h
parent0bee61d26e44e26c2678d550990a57ce488f222d (diff)
downloadmongo-011dde7e6eac3b73cb1d2a7f004feee9bed99c46.tar.gz
SERVER-15541 SERVER-15652 implement timing-based yielding
Diffstat (limited to 'src/mongo/db/query/plan_yield_policy.h')
-rw-r--r--src/mongo/db/query/plan_yield_policy.h29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/mongo/db/query/plan_yield_policy.h b/src/mongo/db/query/plan_yield_policy.h
index cb6d1a0a9ec..50aff9656f9 100644
--- a/src/mongo/db/query/plan_yield_policy.h
+++ b/src/mongo/db/query/plan_yield_policy.h
@@ -29,26 +29,43 @@
#pragma once
#include "mongo/db/catalog/collection.h"
+#include "mongo/db/query/plan_executor.h"
#include "mongo/util/elapsed_tracker.h"
namespace mongo {
class PlanYieldPolicy {
public:
- PlanYieldPolicy();
- ~PlanYieldPolicy();
+ explicit PlanYieldPolicy(PlanExecutor* exec);
+
+ /**
+ * Used by AUTO_YIELD plan executors in order to check whether it is time to yield.
+ * PlanExecutors give up their locks periodically in order to be fair to other
+ * threads.
+ */
+ bool shouldYield();
/**
- * Yield the provided runner, registering and deregistering it appropriately. Deal with
- * deletion during a yield by setting _planYielding to ensure deregistration.
+ * Used to cause a plan executor to give up locks and go to sleep. The PlanExecutor
+ * must *not* be in saved state. Handles calls to save/restore state internally.
*
- * Provided plan executor MUST be YIELD_MANUAL.
+ * By default, assumes that the PlanExecutor is already registered. If 'registerPlan'
+ * is explicitly set to true, then the executor will get automatically registered and
+ * deregistered here.
+ *
+ * Returns true if the executor was restored successfully and is still alive. Returns false
+ * if the executor got killed during yield.
*/
- bool yieldAndCheckIfOK(PlanExecutor* plan);
+ bool yield(bool registerPlan = false);
private:
+ // Default constructor disallowed in order to ensure initialization of '_planYielding'.
+ PlanYieldPolicy();
+
ElapsedTracker _elapsedTracker;
+ // The plan executor which this yield policy is responsible for yielding. Must
+ // not outlive the plan executor.
PlanExecutor* _planYielding;
};