diff options
author | Eliot Horowitz <eliot@10gen.com> | 2013-10-23 07:32:08 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2013-10-23 07:32:08 -0400 |
commit | a942dd1d88c1c6dddb68f85a02f72434c2999f9e (patch) | |
tree | 39f1193e26591cd6cf1c10ba17cd1e1cce64bc7b /src/mongo/dbtests | |
parent | 483df488c35c0058e5eea1e9af90ecde77d57a29 (diff) | |
download | mongo-a942dd1d88c1c6dddb68f85a02f72434c2999f9e.tar.gz |
SERVER-11178: Introduce IndexCatalog and requirements
IndexCatalog will be the only place to get information about indexes, and modify them
still a lot of work left, but a lot of the logic is now shifted
Diffstat (limited to 'src/mongo/dbtests')
-rw-r--r-- | src/mongo/dbtests/btreebuildertests.cpp | 14 | ||||
-rw-r--r-- | src/mongo/dbtests/btreetests.inl | 1 | ||||
-rw-r--r-- | src/mongo/dbtests/indexupdatetests.cpp | 53 |
3 files changed, 40 insertions, 28 deletions
diff --git a/src/mongo/dbtests/btreebuildertests.cpp b/src/mongo/dbtests/btreebuildertests.cpp index ac448b73857..a8bcc64730f 100644 --- a/src/mongo/dbtests/btreebuildertests.cpp +++ b/src/mongo/dbtests/btreebuildertests.cpp @@ -19,7 +19,9 @@ #include "mongo/db/btreebuilder.h" #include "mongo/db/btreecursor.h" +#include "mongo/db/catalog/index_catalog.h" #include "mongo/db/pdfile.h" +#include "mongo/db/structure/collection.h" #include "mongo/platform/cstdint.h" #include "mongo/dbtests/dbtests.h" @@ -60,10 +62,14 @@ namespace BtreeBuilderTests { lenWHdr ) ); memcpy( infoRecord->data(), indexInfo.objdata(), indexInfo.objsize() ); addRecordToRecListInExtent( infoRecord, infoLoc ); - IndexDetails& id = nsdetails( _ns )->getNextIndexDetails( _ns ); - nsdetails( _ns )->addIndex(); - id.info.writing() = infoLoc; - return id; + + Collection* collection = _ctx.ctx().db()->getCollection( _ns ); + verify( collection ); + + IndexCatalog::IndexBuildBlock blk( collection->getIndexCatalog(), "a_1", infoLoc ); + IndexDetails* id = blk.indexDetails(); + blk.success(); + return *id; } private: Client::WriteContext _ctx; diff --git a/src/mongo/dbtests/btreetests.inl b/src/mongo/dbtests/btreetests.inl index 718ea5aad1b..d06b8c7b12a 100644 --- a/src/mongo/dbtests/btreetests.inl +++ b/src/mongo/dbtests/btreetests.inl @@ -54,6 +54,7 @@ IndexDetails& id() { NamespaceDetails *nsd = nsdetails( ns() ); verify( nsd ); + verify( nsd->getTotalIndexCount() >= 2 ); return nsd->idx( 1 ); } void checkValid( int nKeys ) { diff --git a/src/mongo/dbtests/indexupdatetests.cpp b/src/mongo/dbtests/indexupdatetests.cpp index ed660fb6576..6e3783f8cda 100644 --- a/src/mongo/dbtests/indexupdatetests.cpp +++ b/src/mongo/dbtests/indexupdatetests.cpp @@ -20,11 +20,13 @@ #include "mongo/db/btree.h" #include "mongo/db/btreecursor.h" +#include "mongo/db/catalog/index_catalog.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/index/btree_based_builder.h" #include "mongo/db/kill_current_op.h" #include "mongo/db/pdfile.h" #include "mongo/db/sort_phase_one.h" +#include "mongo/db/structure/collection.h" #include "mongo/platform/cstdint.h" #include "mongo/dbtests/dbtests.h" @@ -67,12 +69,16 @@ namespace IndexUpdateTests { lenWHdr ) ); memcpy( infoRecord->data(), indexInfo.objdata(), indexInfo.objsize() ); addRecordToRecListInExtent( infoRecord, infoLoc ); - IndexDetails& id = nsdetails( _ns )->getNextIndexDetails( _ns ); - nsdetails( _ns )->addIndex(); - id.info.writing() = infoLoc; - return id; + + Collection* collection = _ctx.ctx().db()->getCollection( _ns ); + verify( collection ); + + IndexCatalog::IndexBuildBlock blk( collection->getIndexCatalog(), "a_1", infoLoc ); + IndexDetails* id = blk.indexDetails(); + blk.success(); + return *id; } - private: + Client::WriteContext _ctx; }; @@ -526,37 +532,37 @@ namespace IndexUpdateTests { class IndexBuildInProgressTest : public IndexBuildBase { public: void run() { + + NamespaceDetails* nsd = nsdetails( _ns ); + // _id_ is at 0, so nIndexes == 1 - NamespaceDetails::IndexBuildBlock* a = halfAddIndex("a"); - NamespaceDetails::IndexBuildBlock* b = halfAddIndex("b"); - NamespaceDetails::IndexBuildBlock* c = halfAddIndex("c"); - NamespaceDetails::IndexBuildBlock* d = halfAddIndex("d"); - int offset = IndexBuildsInProgress::get(_ns, "b_1"); + IndexCatalog::IndexBuildBlock* a = halfAddIndex("a"); + IndexCatalog::IndexBuildBlock* b = halfAddIndex("b"); + IndexCatalog::IndexBuildBlock* c = halfAddIndex("c"); + IndexCatalog::IndexBuildBlock* d = halfAddIndex("d"); + int offset = nsd->findIndexByName( "b_1", true ); ASSERT_EQUALS(2, offset); - IndexBuildsInProgress::remove(_ns, offset); delete b; - ASSERT_EQUALS(2, IndexBuildsInProgress::get(_ns, "c_1")); - ASSERT_EQUALS(3, IndexBuildsInProgress::get(_ns, "d_1")); + ASSERT_EQUALS(2, nsd->findIndexByName( "c_1", true ) ); + ASSERT_EQUALS(3, nsd->findIndexByName( "d_1", true ) ); - offset = IndexBuildsInProgress::get(_ns, "d_1"); - IndexBuildsInProgress::remove(_ns, offset); + offset = nsd->findIndexByName( "d_1", true ); delete d; - ASSERT_EQUALS(2, IndexBuildsInProgress::get(_ns, "c_1")); - ASSERT_THROWS(IndexBuildsInProgress::get(_ns, "d_1"), MsgAssertionException); + ASSERT_EQUALS(2, nsd->findIndexByName( "c_1", true ) ); + ASSERT( nsd->findIndexByName( "d_1", true ) < 0 ); - offset = IndexBuildsInProgress::get(_ns, "a_1"); - IndexBuildsInProgress::remove(_ns, offset); + offset = nsd->findIndexByName( "a_1", true ); delete a; - ASSERT_EQUALS(1, IndexBuildsInProgress::get(_ns, "c_1")); + ASSERT_EQUALS(1, nsd->findIndexByName( "c_1", true )); delete c; } private: - NamespaceDetails::IndexBuildBlock* halfAddIndex(const std::string& key) { + IndexCatalog::IndexBuildBlock* halfAddIndex(const std::string& key) { string name = key + "_1"; BSONObj indexInfo = BSON( "v" << 1 << "key" << BSON( key << 1 ) << @@ -572,9 +578,8 @@ namespace IndexUpdateTests { lenWHdr ) ); memcpy( infoRecord->data(), indexInfo.objdata(), indexInfo.objsize() ); addRecordToRecListInExtent( infoRecord, infoLoc ); - IndexDetails& id = nsdetails( _ns )->getNextIndexDetails( _ns ); - id.info = infoLoc; - return new NamespaceDetails::IndexBuildBlock( _ns, name ); + + return new IndexCatalog::IndexBuildBlock( _ctx.ctx().db()->getCollection( _ns )->getIndexCatalog(), name, infoLoc ); } }; |