summaryrefslogtreecommitdiff
path: root/src/mongo/dbtests/querytests.cpp
diff options
context:
space:
mode:
authorCharlie Swanson <charlie.swanson@mongodb.com>2017-04-14 16:33:41 -0400
committerCharlie Swanson <charlie.swanson@mongodb.com>2017-05-03 17:45:07 -0400
commit7759c61a35f835aa109131b8f1575f0e1879cba0 (patch)
treea7c4758f153a2f75ed908425dfeb294326112233 /src/mongo/dbtests/querytests.cpp
parent2c00a571f4549ccdfb427b1f096157290662a0f7 (diff)
downloadmongo-7759c61a35f835aa109131b8f1575f0e1879cba0.tar.gz
SERVER-28327 Revamp cursor timeout logic.
Instead of tracking the number of idle milliseconds, each ClientCursor tracks its last time of use. This also resolves related issues SERVER-28328 and SERVER-19892.
Diffstat (limited to 'src/mongo/dbtests/querytests.cpp')
-rw-r--r--src/mongo/dbtests/querytests.cpp168
1 files changed, 0 insertions, 168 deletions
diff --git a/src/mongo/dbtests/querytests.cpp b/src/mongo/dbtests/querytests.cpp
index 006bb223c72..eae94dbb7ca 100644
--- a/src/mongo/dbtests/querytests.cpp
+++ b/src/mongo/dbtests/querytests.cpp
@@ -1634,29 +1634,6 @@ public:
}
};
-class QueryCursorTimeout : public CollectionInternalBase {
-public:
- QueryCursorTimeout() : CollectionInternalBase("querycursortimeout") {}
- void run() {
- for (int i = 0; i < 150; ++i) {
- insert(ns(), BSONObj());
- }
- unique_ptr<DBClientCursor> c = _client.query(ns(), Query());
- ASSERT(c->more());
- long long cursorId = c->getCursorId();
-
- ClientCursor* clientCursor = 0;
- {
- AutoGetCollectionForReadCommand ctx(&_opCtx, NamespaceString(ns()));
- auto clientCursorPin = unittest::assertGet(
- ctx.getCollection()->getCursorManager()->pinCursor(&_opCtx, cursorId));
- clientCursor = clientCursorPin.getCursor();
- // clientCursorPointer destructor unpins the cursor.
- }
- ASSERT(clientCursor->shouldTimeout(600001));
- }
-};
-
class QueryReadsAll : public CollectionBase {
public:
QueryReadsAll() : CollectionBase("queryreadsall") {}
@@ -1686,35 +1663,6 @@ public:
}
};
-/**
- * Check that an attempt to kill a pinned cursor fails and produces an appropriate assertion.
- */
-class KillPinnedCursor : public CollectionBase {
-public:
- KillPinnedCursor() : CollectionBase("killpinnedcursor") {}
- void run() {
- _client.insert(ns(), vector<BSONObj>(3, BSONObj()));
- unique_ptr<DBClientCursor> cursor = _client.query(ns(), BSONObj(), 0, 0, 0, 0, 2);
- ASSERT_EQUALS(2, cursor->objsLeftInBatch());
- long long cursorId = cursor->getCursorId();
-
- {
- OldClientWriteContext ctx(&_opCtx, ns());
- auto pinnedCursor = unittest::assertGet(ctx.db()
- ->getCollection(&_opCtx, ns())
- ->getCursorManager()
- ->pinCursor(&_opCtx, cursorId));
- string expectedAssertion = str::stream() << "Cannot kill pinned cursor: " << cursorId;
- ASSERT_THROWS_WHAT(CursorManager::eraseCursorGlobal(&_opCtx, cursorId),
- MsgAssertionException,
- expectedAssertion);
- }
-
- // Verify that the remaining document is read from the cursor.
- ASSERT_EQUALS(3, cursor->itcount());
- }
-};
-
namespace queryobjecttests {
class names1 {
public:
@@ -1752,114 +1700,6 @@ public:
}
};
-class CursorManagerIsGloballyManagedCursorShouldReturnFalseIfLeadingBitsAreZeroes {
-public:
- void run() {
- ASSERT_FALSE(CursorManager::isGloballyManagedCursor(0x0000000000000000));
- ASSERT_FALSE(CursorManager::isGloballyManagedCursor(0x000000000FFFFFFF));
- ASSERT_FALSE(CursorManager::isGloballyManagedCursor(0x000000007FFFFFFF));
- ASSERT_FALSE(CursorManager::isGloballyManagedCursor(0x0FFFFFFFFFFFFFFF));
- ASSERT_FALSE(CursorManager::isGloballyManagedCursor(0x3FFFFFFFFFFFFFFF));
- ASSERT_FALSE(CursorManager::isGloballyManagedCursor(0x3dedbeefdeadbeef));
- }
-};
-
-class CursorManagerIsGloballyManagedCursorShouldReturnTrueIfLeadingBitsAreZeroAndOne {
-public:
- void run() {
- ASSERT_TRUE(CursorManager::isGloballyManagedCursor(0x4FFFFFFFFFFFFFFF));
- ASSERT_TRUE(CursorManager::isGloballyManagedCursor(0x5FFFFFFFFFFFFFFF));
- ASSERT_TRUE(CursorManager::isGloballyManagedCursor(0x6FFFFFFFFFFFFFFF));
- ASSERT_TRUE(CursorManager::isGloballyManagedCursor(0x7FFFFFFFFFFFFFFF));
- ASSERT_TRUE(CursorManager::isGloballyManagedCursor(0x4000000000000000));
- ASSERT_TRUE(CursorManager::isGloballyManagedCursor(0x4dedbeefdeadbeef));
- }
-};
-
-class CursorManagerIsGloballyManagedCursorShouldReturnFalseIfLeadingBitIsAOne {
-public:
- void run() {
- ASSERT_FALSE(CursorManager::isGloballyManagedCursor(~0LL));
- ASSERT_FALSE(CursorManager::isGloballyManagedCursor(0xFFFFFFFFFFFFFFFF));
- ASSERT_FALSE(CursorManager::isGloballyManagedCursor(0x8FFFFFFFFFFFFFFF));
- ASSERT_FALSE(CursorManager::isGloballyManagedCursor(0x8dedbeefdeadbeef));
- }
-};
-
-class CursorManagerTest {
-public:
- std::unique_ptr<PlanExecutor, PlanExecutor::Deleter> makeFakePlanExecutor(
- OperationContext* opCtx) {
- auto workingSet = stdx::make_unique<WorkingSet>();
- auto queuedDataStage = stdx::make_unique<QueuedDataStage>(opCtx, workingSet.get());
- return unittest::assertGet(PlanExecutor::make(opCtx,
- std::move(workingSet),
- std::move(queuedDataStage),
- NamespaceString{"test.collection"},
- PlanExecutor::YieldPolicy::NO_YIELD));
- }
-};
-
-class GlobalCursorManagerShouldReportOwnershipOfCursorsItCreated : public CursorManagerTest {
-public:
- void run() {
- auto opCtx = cc().makeOperationContext();
- for (int i = 0; i < 1000; i++) {
- auto exec = makeFakePlanExecutor(opCtx.get());
- auto cursorPin = CursorManager::getGlobalCursorManager()->registerCursor(
- opCtx.get(),
- {std::move(exec), NamespaceString{"test.collection"}, {}, false, BSONObj()});
- ASSERT_TRUE(CursorManager::isGloballyManagedCursor(cursorPin.getCursor()->cursorid()));
- cursorPin.deleteUnderlying();
- }
- }
-};
-
-class CursorsFromCollectionCursorManagerShouldNotReportBeingManagedByGlobalCursorManager
- : public CursorManagerTest {
-public:
- void run() {
- CursorManager testManager(NamespaceString{"test.collection"});
- auto opCtx = cc().makeOperationContext();
- for (int i = 0; i < 1000; i++) {
- auto exec = makeFakePlanExecutor(opCtx.get());
- auto cursorPin = testManager.registerCursor(
- opCtx.get(),
- {std::move(exec), NamespaceString{"test.collection"}, {}, false, BSONObj()});
- ASSERT_FALSE(CursorManager::isGloballyManagedCursor(cursorPin.getCursor()->cursorid()));
- cursorPin.deleteUnderlying();
- }
- }
-};
-
-class AllCursorsFromCollectionCursorManagerShouldContainIdentical32BitPrefixes
- : public CursorManagerTest {
-public:
- void run() {
- CursorManager testManager(NamespaceString{"test.collection"});
- auto opCtx = cc().makeOperationContext();
- boost::optional<uint32_t> prefix;
- for (int i = 0; i < 1000; i++) {
- auto exec = makeFakePlanExecutor(opCtx.get());
- auto cursorPin = testManager.registerCursor(
- opCtx.get(),
- {std::move(exec), NamespaceString{"test.collection"}, {}, false, BSONObj()});
- auto cursorId = cursorPin.getCursor()->cursorid();
- if (prefix) {
- ASSERT_EQ(*prefix, extractLeading32Bits(cursorId));
- } else {
- prefix = extractLeading32Bits(cursorId);
- }
- cursorPin.deleteUnderlying();
- }
- }
-
-private:
- uint32_t extractLeading32Bits(CursorId cursorId) {
- return static_cast<uint32_t>((cursorId & 0xFFFFFFFF00000000) >> 32);
- }
-};
-
class All : public Suite {
public:
All() : Suite("query") {}
@@ -1914,17 +1754,9 @@ public:
add<FindingStartStale>();
add<WhatsMyUri>();
add<Exhaust>();
- add<QueryCursorTimeout>();
add<QueryReadsAll>();
- add<KillPinnedCursor>();
add<queryobjecttests::names1>();
add<OrderingTest>();
- add<CursorManagerIsGloballyManagedCursorShouldReturnFalseIfLeadingBitsAreZeroes>();
- add<CursorManagerIsGloballyManagedCursorShouldReturnTrueIfLeadingBitsAreZeroAndOne>();
- add<CursorManagerIsGloballyManagedCursorShouldReturnFalseIfLeadingBitIsAOne>();
- add<GlobalCursorManagerShouldReportOwnershipOfCursorsItCreated>();
- add<CursorsFromCollectionCursorManagerShouldNotReportBeingManagedByGlobalCursorManager>();
- add<AllCursorsFromCollectionCursorManagerShouldContainIdentical32BitPrefixes>();
}
};