diff options
author | Mathias Stearn <mathias@10gen.com> | 2015-05-18 18:01:38 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2015-06-09 16:33:22 -0400 |
commit | 3b731debe162706cbbfabd9578bbb57ab5a7a7d8 (patch) | |
tree | 7b26f5541e5de0060bf75f5563b37cae5a246ee8 /src/mongo/dbtests | |
parent | f50d1d0b7df924926855badd3cd700653f75f0f8 (diff) | |
download | mongo-3b731debe162706cbbfabd9578bbb57ab5a7a7d8.tar.gz |
SERVER-16444 New API for navigating RecordStores
Diffstat (limited to 'src/mongo/dbtests')
-rw-r--r-- | src/mongo/dbtests/query_stage_and.cpp | 9 | ||||
-rw-r--r-- | src/mongo/dbtests/query_stage_fetch.cpp | 8 | ||||
-rw-r--r-- | src/mongo/dbtests/query_stage_keep.cpp | 13 | ||||
-rw-r--r-- | src/mongo/dbtests/query_stage_merge_sort.cpp | 8 | ||||
-rw-r--r-- | src/mongo/dbtests/query_stage_sort.cpp | 8 | ||||
-rw-r--r-- | src/mongo/dbtests/querytests.cpp | 23 | ||||
-rw-r--r-- | src/mongo/dbtests/repltests.cpp | 36 | ||||
-rw-r--r-- | src/mongo/dbtests/rollbacktests.cpp | 15 |
8 files changed, 62 insertions, 58 deletions
diff --git a/src/mongo/dbtests/query_stage_and.cpp b/src/mongo/dbtests/query_stage_and.cpp index 2b43feb3b32..29db2eaf104 100644 --- a/src/mongo/dbtests/query_stage_and.cpp +++ b/src/mongo/dbtests/query_stage_and.cpp @@ -82,13 +82,10 @@ namespace QueryStageAnd { } void getLocs(set<RecordId>* out, Collection* coll) { - RecordIterator* it = coll->getIterator(&_txn, RecordId(), - CollectionScanParams::FORWARD); - while (!it->isEOF()) { - RecordId nextLoc = it->getNext(); - out->insert(nextLoc); + auto cursor = coll->getCursor(&_txn); + while (auto record = cursor->next()) { + out->insert(record->id); } - delete it; } void insert(const BSONObj& obj) { diff --git a/src/mongo/dbtests/query_stage_fetch.cpp b/src/mongo/dbtests/query_stage_fetch.cpp index c8617a59acf..e33d9b08420 100644 --- a/src/mongo/dbtests/query_stage_fetch.cpp +++ b/src/mongo/dbtests/query_stage_fetch.cpp @@ -62,12 +62,10 @@ namespace QueryStageFetch { } void getLocs(set<RecordId>* out, Collection* coll) { - RecordIterator* it = coll->getIterator(&_txn); - while (!it->isEOF()) { - RecordId nextLoc = it->getNext(); - out->insert(nextLoc); + auto cursor = coll->getCursor(&_txn); + while (auto record = cursor->next()) { + out->insert(record->id); } - delete it; } void insert(const BSONObj& obj) { diff --git a/src/mongo/dbtests/query_stage_keep.cpp b/src/mongo/dbtests/query_stage_keep.cpp index f78a2977300..743d1f7bdd2 100644 --- a/src/mongo/dbtests/query_stage_keep.cpp +++ b/src/mongo/dbtests/query_stage_keep.cpp @@ -66,12 +66,10 @@ namespace QueryStageKeep { } void getLocs(set<RecordId>* out, Collection* coll) { - RecordIterator* it = coll->getIterator(&_txn); - while (!it->isEOF()) { - RecordId nextLoc = it->getNext(); - out->insert(nextLoc); + auto cursor = coll->getCursor(&_txn); + while (auto record = cursor->next()) { + out->insert(record->id); } - delete it; } void insert(const BSONObj& obj) { @@ -154,7 +152,10 @@ namespace QueryStageKeep { ASSERT_EQUALS(member->obj.value()["x"].numberInt(), 1); } - ASSERT(cs->isEOF()); + { + WorkingSetID out; + ASSERT_EQ(cs->work(&out), PlanStage::IS_EOF); + } // Flagged results *must* be at the end. for (size_t i = 0; i < 10; ++i) { diff --git a/src/mongo/dbtests/query_stage_merge_sort.cpp b/src/mongo/dbtests/query_stage_merge_sort.cpp index 4685c53b084..0c3813e5a37 100644 --- a/src/mongo/dbtests/query_stage_merge_sort.cpp +++ b/src/mongo/dbtests/query_stage_merge_sort.cpp @@ -78,12 +78,10 @@ namespace QueryStageMergeSortTests { } void getLocs(set<RecordId>* out, Collection* coll) { - RecordIterator* it = coll->getIterator(&_txn); - while (!it->isEOF()) { - RecordId nextLoc = it->getNext(); - out->insert(nextLoc); + auto cursor = coll->getCursor(&_txn); + while (auto record = cursor->next()) { + out->insert(record->id); } - delete it; } BSONObj objWithMinKey(int start) { diff --git a/src/mongo/dbtests/query_stage_sort.cpp b/src/mongo/dbtests/query_stage_sort.cpp index e398b696339..dc267b9a8b1 100644 --- a/src/mongo/dbtests/query_stage_sort.cpp +++ b/src/mongo/dbtests/query_stage_sort.cpp @@ -70,12 +70,10 @@ namespace QueryStageSortTests { } void getLocs(set<RecordId>* out, Collection* coll) { - RecordIterator* it = coll->getIterator(&_txn); - while (!it->isEOF()) { - RecordId nextLoc = it->getNext(); - out->insert(nextLoc); + auto cursor = coll->getCursor(&_txn); + while (auto record = cursor->next()) { + out->insert(record->id); } - delete it; } /** diff --git a/src/mongo/dbtests/querytests.cpp b/src/mongo/dbtests/querytests.cpp index d13ad632970..d668cb8e2d4 100644 --- a/src/mongo/dbtests/querytests.cpp +++ b/src/mongo/dbtests/querytests.cpp @@ -1518,10 +1518,25 @@ namespace QueryTests { for( int i = 0; i < 5; ++i ) { insert( ns(), BSONObj() ); } - auto_ptr<DBClientCursor> c = _client.query( ns(), Query(), 5 ); - ASSERT( c->more() ); - // With five results and a batch size of 5, no cursor is created. - ASSERT_EQUALS( 0, c->getCursorId() ); + { + // With five results and a batch size of 5, a cursor is created since we don't know + // there are no more results. + std::auto_ptr<DBClientCursor> c = _client.query( ns(), Query(), 5 ); + ASSERT(c->more()); + ASSERT_NE(0, c->getCursorId()); + for (int i = 0; i < 5; ++i) { + ASSERT(c->more()); + c->next(); + } + ASSERT(!c->more()); + } + { + // With a batchsize of 6 we know there are no more results so we don't create a + // cursor. + std::auto_ptr<DBClientCursor> c = _client.query( ns(), Query(), 6 ); + ASSERT(c->more()); + ASSERT_EQ(0, c->getCursorId()); + } } }; diff --git a/src/mongo/dbtests/repltests.cpp b/src/mongo/dbtests/repltests.cpp index d79495cdd34..74c250fc098 100644 --- a/src/mongo/dbtests/repltests.cpp +++ b/src/mongo/dbtests/repltests.cpp @@ -149,11 +149,10 @@ namespace ReplTests { } int count = 0; - RecordIterator* it = coll->getIterator(&_txn); - for ( ; !it->isEOF(); it->getNext() ) { + auto cursor = coll->getCursor(&_txn); + while (auto record = cursor->next()) { ++count; } - delete it; return count; } int opCount() { @@ -170,11 +169,10 @@ namespace ReplTests { } int count = 0; - RecordIterator* it = coll->getIterator(&_txn); - for ( ; !it->isEOF(); it->getNext() ) { + auto cursor = coll->getCursor(&_txn); + while (auto record = cursor->next()) { ++count; } - delete it; return count; } void applyAllOperations() { @@ -186,12 +184,10 @@ namespace ReplTests { Database* db = ctx.db(); Collection* coll = db->getCollection( cllNS() ); - RecordIterator* it = coll->getIterator(&_txn); - while ( !it->isEOF() ) { - RecordId currLoc = it->getNext(); - ops.push_back(coll->docFor(&_txn, currLoc).value()); + auto cursor = coll->getCursor(&_txn); + while (auto record = cursor->next()) { + ops.push_back(record->data.releaseToBson().getOwned()); } - delete it; } { OldClientContext ctx(&_txn, ns() ); @@ -222,13 +218,11 @@ namespace ReplTests { wunit.commit(); } - RecordIterator* it = coll->getIterator(&_txn); + auto cursor = coll->getCursor(&_txn); ::mongo::log() << "all for " << ns << endl; - while ( !it->isEOF() ) { - RecordId currLoc = it->getNext(); - ::mongo::log() << coll->docFor(&_txn, currLoc).value().toString() << endl; + while (auto record = cursor->next()) { + ::mongo::log() << record->data.releaseToBson() << endl; } - delete it; } // These deletes don't get logged. void deleteAll( const char *ns ) const { @@ -243,11 +237,13 @@ namespace ReplTests { } vector< RecordId > toDelete; - RecordIterator* it = coll->getIterator(&_txn); - while ( !it->isEOF() ) { - toDelete.push_back( it->getNext() ); + { + auto cursor = coll->getCursor(&_txn); + while (auto record = cursor->next()) { + toDelete.push_back(record->id); + } } - delete it; + for( vector< RecordId >::iterator i = toDelete.begin(); i != toDelete.end(); ++i ) { _txn.setReplicatedWrites(false); coll->deleteDocument( &_txn, *i, true ); diff --git a/src/mongo/dbtests/rollbacktests.cpp b/src/mongo/dbtests/rollbacktests.cpp index f742fb68b00..74078abf1b1 100644 --- a/src/mongo/dbtests/rollbacktests.cpp +++ b/src/mongo/dbtests/rollbacktests.cpp @@ -99,16 +99,17 @@ namespace { const NamespaceString& nss, const BSONObj& data ) { Collection* coll = dbHolder().get( txn, nss.db() )->getCollection(nss.ns() ); - scoped_ptr<RecordIterator> iter( coll->getIterator( txn ) ); - ASSERT( !iter->isEOF() ); - RecordId loc = iter->getNext(); - ASSERT( iter->isEOF() ); - ASSERT_EQ( data, coll->docFor( txn, loc ).value() ); + auto cursor = coll->getCursor(txn); + + auto record = cursor->next(); + ASSERT(record); + ASSERT_EQ(data, record->data.releaseToBson()); + + ASSERT(!cursor->next()); } void assertEmpty( OperationContext* txn, const NamespaceString& nss ) { Collection* coll = dbHolder().get( txn, nss.db() )->getCollection(nss.ns() ); - scoped_ptr<RecordIterator> iter( coll->getIterator( txn ) ); - ASSERT( iter->isEOF() ); + ASSERT(!coll->getCursor(txn)->next()); } bool indexExists( OperationContext* txn, const NamespaceString& nss, const string& idxName ) { Collection* coll = dbHolder().get( txn, nss.db() )->getCollection(nss.ns() ); |