diff options
author | yarai <yuta.arai@10gen.com> | 2018-09-05 10:11:46 -0400 |
---|---|---|
committer | yarai <yuta.arai@10gen.com> | 2018-09-07 17:00:21 -0400 |
commit | 5310a3a7ab70f44bd864c4738aa95d0165256945 (patch) | |
tree | 75bab39834aaa2e064fafc03ea7812128f566b95 | |
parent | 51afd8574ed503bffebd473a107d9d7fab61fdc5 (diff) | |
download | mongo-5310a3a7ab70f44bd864c4738aa95d0165256945.tar.gz |
SERVER-35576 Fixed PlanCacheClear clear time of check
-rw-r--r-- | jstests/core/plan_cache_clear.js | 2 | ||||
-rw-r--r-- | src/mongo/db/commands/plan_cache_commands.cpp | 10 |
2 files changed, 4 insertions, 8 deletions
diff --git a/jstests/core/plan_cache_clear.js b/jstests/core/plan_cache_clear.js index 24f749c24e7..a725995c725 100644 --- a/jstests/core/plan_cache_clear.js +++ b/jstests/core/plan_cache_clear.js @@ -38,7 +38,7 @@ assert.eq(1, t.find({a: 1, b: 1}).itcount(), 'unexpected document count'); // Invalid key should be a no-op. - t.runCommand('planCacheClear', {query: {unknownfield: 1}}); + assert.commandWorked(t.runCommand('planCacheClear', {query: {unknownfield: 1}})); assert.eq( 1, getShapes().length, 'removing unknown query should not affecting exisiting entries'); diff --git a/src/mongo/db/commands/plan_cache_commands.cpp b/src/mongo/db/commands/plan_cache_commands.cpp index 4c2c5a77b7f..6180c51bee9 100644 --- a/src/mongo/db/commands/plan_cache_commands.cpp +++ b/src/mongo/db/commands/plan_cache_commands.cpp @@ -308,8 +308,9 @@ Status PlanCacheClear::clear(OperationContext* opCtx, unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue()); - if (planCache->get(*cq).state == PlanCache::CacheEntryState::kNotPresent) { - // Log if asked to clear non-existent query shape. + Status result = planCache->remove(*cq); + if (!result.isOK()) { + invariant(result.code() == ErrorCodes::NoSuchKey); LOG(1) << ns << ": query shape doesn't exist in PlanCache - " << redact(cq->getQueryObj()) << "(sort: " << cq->getQueryRequest().getSort() << "; projection: " << cq->getQueryRequest().getProj() @@ -317,11 +318,6 @@ Status PlanCacheClear::clear(OperationContext* opCtx, return Status::OK(); } - Status result = planCache->remove(*cq); - if (!result.isOK()) { - return result; - } - LOG(1) << ns << ": removed plan cache entry - " << redact(cq->getQueryObj()) << "(sort: " << cq->getQueryRequest().getSort() << "; projection: " << cq->getQueryRequest().getProj() |