void MultiPlanRunner::restoreState() { if (_killed) { return; } if (NULL != _bestPlan) { _bestPlan->restoreState(); } else { unyieldAllPlans(); } }
bool MultiPlanRunner::pickBestPlan(size_t* out) { static const int timesEachPlanIsWorked = 100; static const int yieldInterval = 10; // Run each plan some number of times. for (int i = 0; i < timesEachPlanIsWorked; ++i) { bool moreToDo = workAllPlans(); if (!moreToDo) { break; } if (0 == ((i + 1) % yieldInterval)) { yieldAllPlans(); // TODO: Actually yield... unyieldAllPlans(); } } if (_failure) { return false; } size_t bestChild = PlanRanker::pickBestPlan(_candidates, NULL); // Run the best plan. Store it. _bestPlanRunner.reset(new SimplePlanRunner(_candidates[bestChild].ws, _candidates[bestChild].root)); _alreadyProduced = _candidates[bestChild].results; // TODO: Normally we'd hand this to the cache, who would own it. delete _candidates[bestChild].solution; // Store the choice we just made in the cache. // QueryPlanCache* cache = PlanCache::get(somenamespace); // cache->add(_query, *_candidates[bestChild]->solution, decision->bestPlanStats); // delete decision; // Clear out the candidate plans as we're all done w/them. for (size_t i = 0; i < _candidates.size(); ++i) { if (i == bestChild) { continue; } delete _candidates[i].solution; delete _candidates[i].root; // ws must die after the root. delete _candidates[i].ws; } _candidates.clear(); if (NULL != out) { *out = bestChild; } return true; }