summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2014-08-25 17:25:39 -0400
committerEliot Horowitz <eliot@10gen.com>2014-08-25 18:08:37 -0400
commitf0bb5123f50bb617eb9499539f01779c6e9f5e95 (patch)
tree98cc4abf3c89881691158345435523c5dd6ae37f /src/mongo/db/catalog
parentcb3f5cfa43d9565675d2f36c4b0f7cecbad47a49 (diff)
downloadmongo-f0bb5123f50bb617eb9499539f01779c6e9f5e95.tar.gz
SERVER-13635: OperationContext on read paths
Diffstat (limited to 'src/mongo/db/catalog')
-rw-r--r--src/mongo/db/catalog/collection.cpp40
-rw-r--r--src/mongo/db/catalog/collection.h12
-rw-r--r--src/mongo/db/catalog/collection_catalog_entry.h19
-rw-r--r--src/mongo/db/catalog/collection_compact.cpp4
-rw-r--r--src/mongo/db/catalog/collection_info_cache.cpp4
-rw-r--r--src/mongo/db/catalog/collection_info_cache.h6
-rw-r--r--src/mongo/db/catalog/database.cpp12
-rw-r--r--src/mongo/db/catalog/head_manager.h2
-rw-r--r--src/mongo/db/catalog/index_catalog.cpp106
-rw-r--r--src/mongo/db/catalog/index_catalog.h37
-rw-r--r--src/mongo/db/catalog/index_catalog_entry.cpp40
-rw-r--r--src/mongo/db/catalog/index_catalog_entry.h15
-rw-r--r--src/mongo/db/catalog/index_create.cpp4
13 files changed, 163 insertions, 138 deletions
diff --git a/src/mongo/db/catalog/collection.cpp b/src/mongo/db/catalog/collection.cpp
index 3966ccae972..614841758bd 100644
--- a/src/mongo/db/catalog/collection.cpp
+++ b/src/mongo/db/catalog/collection.cpp
@@ -149,7 +149,7 @@ namespace mongo {
int64_t count = 0;
while ( !iterator->isEOF() ) {
DiskLoc loc = iterator->getNext();
- BSONObj obj = docFor( loc );
+ BSONObj obj = docFor( txn, loc );
if ( expression->matchesBSON( obj ) )
count++;
}
@@ -157,14 +157,14 @@ namespace mongo {
return count;
}
- BSONObj Collection::docFor(const DiskLoc& loc) const {
- return _recordStore->dataFor( loc ).toBson();
+ BSONObj Collection::docFor(OperationContext* txn, const DiskLoc& loc) const {
+ return _recordStore->dataFor( txn, loc ).toBson();
}
StatusWith<DiskLoc> Collection::insertDocument( OperationContext* txn,
const DocWriter* doc,
bool enforceQuota ) {
- verify( _indexCatalog.numIndexesTotal() == 0 ); // eventually can implement, just not done
+ verify( _indexCatalog.numIndexesTotal( txn ) == 0 ); // eventually can implement, just not done
StatusWith<DiskLoc> loc = _recordStore->insertRecord( txn,
doc,
@@ -178,7 +178,7 @@ namespace mongo {
StatusWith<DiskLoc> Collection::insertDocument( OperationContext* txn,
const BSONObj& docToInsert,
bool enforceQuota ) {
- if ( _indexCatalog.findIdIndex() ) {
+ if ( _indexCatalog.findIdIndex( txn ) ) {
if ( docToInsert["_id"].eoo() ) {
return StatusWith<DiskLoc>( ErrorCodes::InternalError,
str::stream() << "Collection::insertDocument got "
@@ -255,7 +255,7 @@ namespace mongo {
Status Collection::aboutToDeleteCapped( OperationContext* txn, const DiskLoc& loc ) {
- BSONObj doc = docFor( loc );
+ BSONObj doc = docFor( txn, loc );
/* check if any cursors point to us. if so, advance them. */
_cursorCache.invalidateDocument(loc, INVALIDATION_DELETION);
@@ -276,7 +276,7 @@ namespace mongo {
return;
}
- BSONObj doc = docFor( loc );
+ BSONObj doc = docFor( txn, loc );
if ( deletedId ) {
BSONElement e = doc["_id"];
@@ -304,7 +304,7 @@ namespace mongo {
bool enforceQuota,
OpDebug* debug ) {
- BSONObj objOld = _recordStore->dataFor( oldLocation ).toBson();
+ BSONObj objOld = _recordStore->dataFor( txn, oldLocation ).toBson();
if ( objOld.hasElement( "_id" ) ) {
BSONElement oldId = objOld["_id"];
@@ -327,7 +327,7 @@ namespace mongo {
below. that is suboptimal, but it's pretty complicated to do it the other way without rollbacks...
*/
OwnedPointerMap<IndexDescriptor*,UpdateTicket> updateTickets;
- IndexCatalog::IndexIterator ii = _indexCatalog.getIndexIterator( true );
+ IndexCatalog::IndexIterator ii = _indexCatalog.getIndexIterator( txn, true );
while ( ii.more() ) {
IndexDescriptor* descriptor = ii.next();
IndexAccessMethod* iam = _indexCatalog.getIndex( descriptor );
@@ -376,7 +376,7 @@ namespace mongo {
if ( debug )
debug->keyUpdates = 0;
- ii = _indexCatalog.getIndexIterator( true );
+ ii = _indexCatalog.getIndexIterator( txn, true );
while ( ii.more() ) {
IndexDescriptor* descriptor = ii.next();
IndexAccessMethod* iam = _indexCatalog.getIndex( descriptor );
@@ -438,12 +438,12 @@ namespace mongo {
return _recordStore->isCapped();
}
- uint64_t Collection::numRecords() const {
- return _recordStore->numRecords();
+ uint64_t Collection::numRecords( OperationContext* txn ) const {
+ return _recordStore->numRecords( txn );
}
- uint64_t Collection::dataSize() const {
- return _recordStore->dataSize();
+ uint64_t Collection::dataSize( OperationContext* txn ) const {
+ return _recordStore->dataSize( txn );
}
/**
@@ -454,12 +454,12 @@ namespace mongo {
* 4) re-write indexes
*/
Status Collection::truncate(OperationContext* txn) {
- massert( 17445, "index build in progress", _indexCatalog.numIndexesInProgress() == 0 );
+ massert( 17445, "index build in progress", _indexCatalog.numIndexesInProgress( txn ) == 0 );
// 1) store index specs
vector<BSONObj> indexSpecs;
{
- IndexCatalog::IndexIterator ii = _indexCatalog.getIndexIterator( false );
+ IndexCatalog::IndexIterator ii = _indexCatalog.getIndexIterator( txn, false );
while ( ii.more() ) {
const IndexDescriptor* idx = ii.next();
indexSpecs.push_back( idx->infoObj().getOwned() );
@@ -522,11 +522,11 @@ namespace mongo {
return status;
{ // indexes
- output->append("nIndexes", _indexCatalog.numIndexesReady() );
+ output->append("nIndexes", _indexCatalog.numIndexesReady( txn ) );
int idxn = 0;
try {
BSONObjBuilder indexes; // not using subObjStart to be exception safe
- IndexCatalog::IndexIterator i = _indexCatalog.getIndexIterator(false);
+ IndexCatalog::IndexIterator i = _indexCatalog.getIndexIterator(txn, false);
while( i.more() ) {
const IndexDescriptor* descriptor = i.next();
log(LogComponent::kIndexing) << "validating index " << descriptor->indexNamespace() << endl;
@@ -567,7 +567,7 @@ namespace mongo {
if ( touchIndexes ) {
Timer t;
- IndexCatalog::IndexIterator ii = _indexCatalog.getIndexIterator( false );
+ IndexCatalog::IndexIterator ii = _indexCatalog.getIndexIterator( txn, false );
while ( ii.more() ) {
const IndexDescriptor* desc = ii.next();
const IndexAccessMethod* iam = _indexCatalog.getIndex( desc );
@@ -576,7 +576,7 @@ namespace mongo {
return status;
}
- output->append( "indexes", BSON( "num" << _indexCatalog.numIndexesTotal() <<
+ output->append( "indexes", BSON( "num" << _indexCatalog.numIndexesTotal( txn ) <<
"millis" << t.millis() ) );
}
diff --git a/src/mongo/db/catalog/collection.h b/src/mongo/db/catalog/collection.h
index 9ca4c76e97b..bfc9add1235 100644
--- a/src/mongo/db/catalog/collection.h
+++ b/src/mongo/db/catalog/collection.h
@@ -128,7 +128,7 @@ namespace mongo {
bool requiresIdIndex() const;
- BSONObj docFor(const DiskLoc& loc) const;
+ BSONObj docFor(OperationContext* txn, const DiskLoc& loc) const;
// ---- things that should move to a CollectionAccessMethod like thing
/**
@@ -246,15 +246,15 @@ namespace mongo {
bool isCapped() const;
- uint64_t numRecords() const;
+ uint64_t numRecords( OperationContext* txn ) const;
- uint64_t dataSize() const;
+ uint64_t dataSize( OperationContext* txn ) const;
- int averageObjectSize() const {
- uint64_t n = numRecords();
+ int averageObjectSize( OperationContext* txn ) const {
+ uint64_t n = numRecords( txn );
if ( n == 0 )
return 5;
- return static_cast<int>( dataSize() / n );
+ return static_cast<int>( dataSize( txn ) / n );
}
// --- end suspect things
diff --git a/src/mongo/db/catalog/collection_catalog_entry.h b/src/mongo/db/catalog/collection_catalog_entry.h
index 1b0175b59c8..d537df5d223 100644
--- a/src/mongo/db/catalog/collection_catalog_entry.h
+++ b/src/mongo/db/catalog/collection_catalog_entry.h
@@ -53,29 +53,34 @@ namespace mongo {
virtual CollectionOptions getCollectionOptions( OperationContext* txn ) const = 0;
- virtual int getTotalIndexCount() const = 0;
+ virtual int getTotalIndexCount( OperationContext* txn ) const = 0;
- virtual int getCompletedIndexCount() const = 0;
+ virtual int getCompletedIndexCount( OperationContext* txn ) const = 0;
virtual int getMaxAllowedIndexes() const = 0;
- virtual void getAllIndexes( std::vector<std::string>* names ) const = 0;
+ virtual void getAllIndexes( OperationContext* txn,
+ std::vector<std::string>* names ) const = 0;
- virtual BSONObj getIndexSpec( const StringData& idxName ) const = 0;
+ virtual BSONObj getIndexSpec( OperationContext* txn,
+ const StringData& idxName ) const = 0;
- virtual bool isIndexMultikey( const StringData& indexName) const = 0;
+ virtual bool isIndexMultikey( OperationContext* txn,
+ const StringData& indexName) const = 0;
virtual bool setIndexIsMultikey(OperationContext* txn,
const StringData& indexName,
bool multikey = true) = 0;
- virtual DiskLoc getIndexHead( const StringData& indexName ) const = 0;
+ virtual DiskLoc getIndexHead( OperationContext* txn,
+ const StringData& indexName ) const = 0;
virtual void setIndexHead( OperationContext* txn,
const StringData& indexName,
const DiskLoc& newHead ) = 0;
- virtual bool isIndexReady( const StringData& indexName ) const = 0;
+ virtual bool isIndexReady( OperationContext* txn,
+ const StringData& indexName ) const = 0;
virtual Status removeIndex( OperationContext* txn,
const StringData& indexName ) = 0;
diff --git a/src/mongo/db/catalog/collection_compact.cpp b/src/mongo/db/catalog/collection_compact.cpp
index b1d0594ee2e..06c20a8030a 100644
--- a/src/mongo/db/catalog/collection_compact.cpp
+++ b/src/mongo/db/catalog/collection_compact.cpp
@@ -104,7 +104,7 @@ namespace mongo {
"cannot compact collection with record store: " <<
_recordStore->name() );
- if ( _indexCatalog.numIndexesInProgress() )
+ if ( _indexCatalog.numIndexesInProgress( txn ) )
return StatusWith<CompactStats>( ErrorCodes::BadValue,
"cannot compact when indexes in progress" );
@@ -114,7 +114,7 @@ namespace mongo {
vector<BSONObj> indexSpecs;
{
- IndexCatalog::IndexIterator ii( _indexCatalog.getIndexIterator( false ) );
+ IndexCatalog::IndexIterator ii( _indexCatalog.getIndexIterator( txn, false ) );
while ( ii.more() ) {
IndexDescriptor* descriptor = ii.next();
diff --git a/src/mongo/db/catalog/collection_info_cache.cpp b/src/mongo/db/catalog/collection_info_cache.cpp
index f0482cad178..d9783b6db07 100644
--- a/src/mongo/db/catalog/collection_info_cache.cpp
+++ b/src/mongo/db/catalog/collection_info_cache.cpp
@@ -60,10 +60,10 @@ namespace mongo {
// index filters should persist throughout life of collection
}
- void CollectionInfoCache::computeIndexKeys() {
+ void CollectionInfoCache::computeIndexKeys( OperationContext* txn ) {
_indexedPaths.clear();
- IndexCatalog::IndexIterator i = _collection->getIndexCatalog()->getIndexIterator(true);
+ IndexCatalog::IndexIterator i = _collection->getIndexCatalog()->getIndexIterator(txn, true);
while (i.more()) {
IndexDescriptor* descriptor = i.next();
diff --git a/src/mongo/db/catalog/collection_info_cache.h b/src/mongo/db/catalog/collection_info_cache.h
index 3948c55e5c0..092d436b2c7 100644
--- a/src/mongo/db/catalog/collection_info_cache.h
+++ b/src/mongo/db/catalog/collection_info_cache.h
@@ -73,9 +73,9 @@ namespace mongo {
/* get set of index keys for this namespace. handy to quickly check if a given
field is indexed (Note it might be a secondary component of a compound index.)
*/
- const UpdateIndexData& indexKeys() {
+ const UpdateIndexData& indexKeys( OperationContext* txn ) {
if ( !_keysComputed )
- computeIndexKeys();
+ computeIndexKeys( txn );
return _indexedPaths;
}
@@ -109,7 +109,7 @@ namespace mongo {
/**
* Must be called under exclusive DB lock.
*/
- void computeIndexKeys();
+ void computeIndexKeys( OperationContext* txn );
};
} // namespace mongo
diff --git a/src/mongo/db/catalog/database.cpp b/src/mongo/db/catalog/database.cpp
index e0a4e02f259..34c7186e782 100644
--- a/src/mongo/db/catalog/database.cpp
+++ b/src/mongo/db/catalog/database.cpp
@@ -253,7 +253,7 @@ namespace mongo {
IndexCatalog* idxCatalog = coll->getIndexCatalog();
- IndexCatalog::IndexIterator ii = idxCatalog->getIndexIterator( true );
+ IndexCatalog::IndexIterator ii = idxCatalog->getIndexIterator( opCtx, true );
long long totalSize = 0;
@@ -292,14 +292,14 @@ namespace mongo {
continue;
ncollections += 1;
- objects += collection->numRecords();
- size += collection->dataSize();
+ objects += collection->numRecords(opCtx);
+ size += collection->dataSize(opCtx);
BSONObjBuilder temp;
storageSize += collection->getRecordStore()->storageSize( opCtx, &temp );
numExtents += temp.obj()["numExtents"].numberInt(); // XXX
- indexes += collection->getIndexCatalog()->numIndexesTotal();
+ indexes += collection->getIndexCatalog()->numIndexesTotal( opCtx );
indexSize += getIndexSizeForCollection(opCtx, collection);
}
@@ -364,7 +364,7 @@ namespace mongo {
return Status( ErrorCodes::InternalError, ss.str() );
}
- verify( collection->_details->getTotalIndexCount() == 0 );
+ verify( collection->_details->getTotalIndexCount( txn ) == 0 );
LOG(1) << "\t dropIndexes done" << endl;
Top::global.collectionDropped( fullns );
@@ -445,7 +445,7 @@ namespace mongo {
Collection* coll = getCollection( txn, fromNS );
if ( !coll )
return Status( ErrorCodes::NamespaceNotFound, "collection not found to rename" );
- IndexCatalog::IndexIterator ii = coll->getIndexCatalog()->getIndexIterator( true );
+ IndexCatalog::IndexIterator ii = coll->getIndexCatalog()->getIndexIterator( txn, true );
while ( ii.more() ) {
IndexDescriptor* desc = ii.next();
_clearCollectionCache( desc->indexNamespace() );
diff --git a/src/mongo/db/catalog/head_manager.h b/src/mongo/db/catalog/head_manager.h
index bdb993ee3e3..9b9ceeb84c3 100644
--- a/src/mongo/db/catalog/head_manager.h
+++ b/src/mongo/db/catalog/head_manager.h
@@ -42,7 +42,7 @@ namespace mongo {
public:
virtual ~HeadManager() { }
- virtual const DiskLoc getHead() const = 0;
+ virtual const DiskLoc getHead(OperationContext* txn) const = 0;
virtual void setHead(OperationContext* txn, const DiskLoc newHead) = 0;
};
diff --git a/src/mongo/db/catalog/index_catalog.cpp b/src/mongo/db/catalog/index_catalog.cpp
index 58f27c6a35b..48f640c0b89 100644
--- a/src/mongo/db/catalog/index_catalog.cpp
+++ b/src/mongo/db/catalog/index_catalog.cpp
@@ -88,24 +88,26 @@ namespace mongo {
Status IndexCatalog::init(OperationContext* txn) {
vector<string> indexNames;
- _collection->getCatalogEntry()->getAllIndexes( &indexNames );
+ _collection->getCatalogEntry()->getAllIndexes( txn, &indexNames );
for ( size_t i = 0; i < indexNames.size(); i++ ) {
const string& indexName = indexNames[i];
- BSONObj spec = _collection->getCatalogEntry()->getIndexSpec( indexName ).getOwned();
+ BSONObj spec = _collection->getCatalogEntry()->getIndexSpec( txn,
+ indexName ).getOwned();
- if ( !_collection->getCatalogEntry()->isIndexReady( indexName ) ) {
+ if ( !_collection->getCatalogEntry()->isIndexReady( txn, indexName ) ) {
_unfinishedIndexes.push_back( spec );
continue;
}
BSONObj keyPattern = spec.getObjectField("key");
IndexDescriptor* descriptor = new IndexDescriptor( _collection,
- _getAccessMethodName(txn, keyPattern),
+ _getAccessMethodName(txn,
+ keyPattern),
spec );
IndexCatalogEntry* entry = _setupInMemoryStructures( txn, descriptor );
- fassert( 17340, entry->isReady() );
+ fassert( 17340, entry->isReady( txn ) );
}
if ( _unfinishedIndexes.size() ) {
@@ -128,9 +130,9 @@ namespace mongo {
descriptorCleanup.release(),
_collection->infoCache() ) );
- entry->init( _collection->_database->_dbEntry->getIndex( txn,
- _collection->getCatalogEntry(),
- entry.get() ) );
+ entry->init( txn, _collection->_database->_dbEntry->getIndex( txn,
+ _collection->getCatalogEntry(),
+ entry.get() ) );
IndexCatalogEntry* save = entry.get();
_entries.add( entry.release() );
@@ -302,7 +304,7 @@ namespace {
Status IndexCatalog::createIndexOnEmptyCollection(OperationContext* txn, BSONObj spec) {
txn->lockState()->assertWriteLocked( _collection->_database->name() );
- invariant(_collection->numRecords() == 0);
+ invariant(_collection->numRecords(txn) == 0);
_checkMagic();
Status status = checkUnfinished();
@@ -345,7 +347,7 @@ namespace {
indexBuildBlock.success();
// sanity check
- invariant(_collection->getCatalogEntry()->isIndexReady(descriptor->indexName()));
+ invariant(_collection->getCatalogEntry()->isIndexReady(txn, descriptor->indexName()));
return Status::OK();
}
@@ -449,7 +451,7 @@ namespace {
_catalog->_collection->infoCache()->addedIndex();
- IndexDescriptor* desc = _catalog->findIndexByName( _indexName, true );
+ IndexDescriptor* desc = _catalog->findIndexByName( _txn, _indexName, true );
fassert( 17330, desc );
IndexCatalogEntry* entry = _catalog->_entries.find( desc );
fassert( 17331, entry && entry == _entry );
@@ -548,7 +550,7 @@ namespace {
{
// Check both existing and in-progress indexes (2nd param = true)
- const IndexDescriptor* desc = findIndexByName( name, true );
+ const IndexDescriptor* desc = findIndexByName( txn, name, true );
if ( desc ) {
// index already exists with same name
@@ -575,7 +577,7 @@ namespace {
{
// Check both existing and in-progress indexes (2nd param = true)
- const IndexDescriptor* desc = findIndexByKeyPattern(key, true);
+ const IndexDescriptor* desc = findIndexByKeyPattern(txn, key, true);
if (desc) {
LOG(2) << "index already exists with diff name " << name
<< ' ' << key << endl;
@@ -592,7 +594,7 @@ namespace {
}
}
- if ( _collection->getCatalogEntry()->getTotalIndexCount() >=
+ if ( _collection->getCatalogEntry()->getTotalIndexCount( txn ) >=
_collection->getCatalogEntry()->getMaxAllowedIndexes() ) {
string s = str::stream() << "add index fails, too many indexes for "
<< _collection->ns().ns() << " key:" << key.toString();
@@ -606,7 +608,7 @@ namespace {
if ( pluginName == IndexNames::TEXT ) {
vector<IndexDescriptor*> textIndexes;
const bool includeUnfinishedIndexes = true;
- findIndexByType( IndexNames::TEXT, textIndexes, includeUnfinishedIndexes );
+ findIndexByType( txn, IndexNames::TEXT, textIndexes, includeUnfinishedIndexes );
if ( textIndexes.size() > 0 ) {
return Status( ErrorCodes::CannotCreateIndex,
str::stream() << "only one text index per collection allowed, "
@@ -641,14 +643,14 @@ namespace {
// make sure nothing in progress
massert( 17348,
"cannot dropAllIndexes when index builds in progress",
- numIndexesTotal() == numIndexesReady() );
+ numIndexesTotal(txn) == numIndexesReady(txn) );
bool haveIdIndex = false;
vector<string> indexNamesToDrop;
{
int seen = 0;
- IndexIterator ii = getIndexIterator( true );
+ IndexIterator ii = getIndexIterator( txn, true );
while ( ii.more() ) {
seen++;
IndexDescriptor* desc = ii.next();
@@ -658,12 +660,12 @@ namespace {
}
indexNamesToDrop.push_back( desc->indexName() );
}
- invariant( seen == numIndexesTotal() );
+ invariant( seen == numIndexesTotal(txn) );
}
for ( size_t i = 0; i < indexNamesToDrop.size(); i++ ) {
string indexName = indexNamesToDrop[i];
- IndexDescriptor* desc = findIndexByName( indexName, true );
+ IndexDescriptor* desc = findIndexByName( txn, indexName, true );
invariant( desc );
LOG(1) << "\t dropAllIndexes dropping: " << desc->toString();
IndexCatalogEntry* entry = _entries.find( desc );
@@ -674,24 +676,24 @@ namespace {
// verify state is sane post cleaning
long long numIndexesInCollectionCatalogEntry =
- _collection->getCatalogEntry()->getTotalIndexCount();
+ _collection->getCatalogEntry()->getTotalIndexCount( txn );
if ( haveIdIndex ) {
- fassert( 17324, numIndexesTotal() == 1 );
- fassert( 17325, numIndexesReady() == 1 );
+ fassert( 17324, numIndexesTotal(txn) == 1 );
+ fassert( 17325, numIndexesReady(txn) == 1 );
fassert( 17326, numIndexesInCollectionCatalogEntry == 1 );
fassert( 17336, _entries.size() == 1 );
}
else {
- if ( numIndexesTotal() || numIndexesInCollectionCatalogEntry || _entries.size() ) {
+ if ( numIndexesTotal(txn) || numIndexesInCollectionCatalogEntry || _entries.size() ) {
error() << "About to fassert - "
- << " numIndexesTotal(): " << numIndexesTotal()
+ << " numIndexesTotal(): " << numIndexesTotal(txn)
<< " numSystemIndexesEntries: " << numIndexesInCollectionCatalogEntry
<< " _entries.size(): " << _entries.size()
<< " indexNamesToDrop: " << indexNamesToDrop.size()
<< " haveIdIndex: " << haveIdIndex;
}
- fassert( 17327, numIndexesTotal() == 0 );
+ fassert( 17327, numIndexesTotal(txn) == 0 );
fassert( 17328, numIndexesInCollectionCatalogEntry == 0 );
fassert( 17337, _entries.size() == 0 );
}
@@ -708,7 +710,7 @@ namespace {
if ( !entry )
return Status( ErrorCodes::InternalError, "cannot find index to delete" );
- if ( !entry->isReady() )
+ if ( !entry->isReady( txn ) )
return Status( ErrorCodes::InternalError, "cannot delete not ready index" );
BackgroundOperation::assertNoBgOpInProgForNs( _collection->ns().ns() );
@@ -808,30 +810,32 @@ namespace {
return toReturn;
}
- bool IndexCatalog::isMultikey( const IndexDescriptor* idx ) {
+ bool IndexCatalog::isMultikey( OperationContext* txn, const IndexDescriptor* idx ) {
IndexCatalogEntry* entry = _entries.find( idx );
invariant( entry );
- return entry->isMultikey();
+ return entry->isMultikey( txn );
}
// ---------------------------
- int IndexCatalog::numIndexesTotal() const {
- return _collection->getCatalogEntry()->getTotalIndexCount();
+ int IndexCatalog::numIndexesTotal( OperationContext* txn ) const {
+ return _collection->getCatalogEntry()->getTotalIndexCount( txn );
}
- int IndexCatalog::numIndexesReady() const {
- return _collection->getCatalogEntry()->getCompletedIndexCount();
+ int IndexCatalog::numIndexesReady( OperationContext* txn ) const {
+ return _collection->getCatalogEntry()->getCompletedIndexCount( txn );
}
- bool IndexCatalog::haveIdIndex() const {
- return findIdIndex() != NULL;
+ bool IndexCatalog::haveIdIndex( OperationContext* txn ) const {
+ return findIdIndex( txn ) != NULL;
}
- IndexCatalog::IndexIterator::IndexIterator( const IndexCatalog* cat,
+ IndexCatalog::IndexIterator::IndexIterator( OperationContext* txn,
+ const IndexCatalog* cat,
bool includeUnfinishedIndexes )
: _includeUnfinishedIndexes( includeUnfinishedIndexes ),
+ _txn( txn ),
_catalog( cat ),
_iterator( cat->_entries.begin() ),
_start( true ),
@@ -868,7 +872,7 @@ namespace {
++_iterator;
if ( _includeUnfinishedIndexes ||
- entry->isReady() ) {
+ entry->isReady(_txn) ) {
_next = entry;
return;
}
@@ -877,8 +881,8 @@ namespace {
}
- IndexDescriptor* IndexCatalog::findIdIndex() const {
- IndexIterator ii = getIndexIterator( false );
+ IndexDescriptor* IndexCatalog::findIdIndex( OperationContext* txn ) const {
+ IndexIterator ii = getIndexIterator( txn, false );
while ( ii.more() ) {
IndexDescriptor* desc = ii.next();
if ( desc->isIdIndex() )
@@ -887,9 +891,10 @@ namespace {
return NULL;
}
- IndexDescriptor* IndexCatalog::findIndexByName( const StringData& name,
+ IndexDescriptor* IndexCatalog::findIndexByName( OperationContext* txn,
+ const StringData& name,
bool includeUnfinishedIndexes ) const {
- IndexIterator ii = getIndexIterator( includeUnfinishedIndexes );
+ IndexIterator ii = getIndexIterator( txn, includeUnfinishedIndexes );
while ( ii.more() ) {
IndexDescriptor* desc = ii.next();
if ( desc->indexName() == name )
@@ -898,9 +903,10 @@ namespace {
return NULL;
}
- IndexDescriptor* IndexCatalog::findIndexByKeyPattern( const BSONObj& key,
+ IndexDescriptor* IndexCatalog::findIndexByKeyPattern( OperationContext* txn,
+ const BSONObj& key,
bool includeUnfinishedIndexes ) const {
- IndexIterator ii = getIndexIterator( includeUnfinishedIndexes );
+ IndexIterator ii = getIndexIterator( txn, includeUnfinishedIndexes );
while ( ii.more() ) {
IndexDescriptor* desc = ii.next();
if ( desc->keyPattern() == key )
@@ -909,18 +915,19 @@ namespace {
return NULL;
}
- IndexDescriptor* IndexCatalog::findIndexByPrefix( const BSONObj &keyPattern,
+ IndexDescriptor* IndexCatalog::findIndexByPrefix( OperationContext* txn,
+ const BSONObj &keyPattern,
bool requireSingleKey ) const {
IndexDescriptor* best = NULL;
- IndexIterator ii = getIndexIterator( false );
+ IndexIterator ii = getIndexIterator( txn, false );
while ( ii.more() ) {
IndexDescriptor* desc = ii.next();
if ( !keyPattern.isPrefixOf( desc->keyPattern() ) )
continue;
- if( !desc->isMultikey() )
+ if( !desc->isMultikey( txn ) )
return desc;
if ( !requireSingleKey )
@@ -930,9 +937,10 @@ namespace {
return best;
}
- void IndexCatalog::findIndexByType( const string& type , vector<IndexDescriptor*>& matches,
+ void IndexCatalog::findIndexByType( OperationContext* txn,
+ const string& type, vector<IndexDescriptor*>& matches,
bool includeUnfinishedIndexes ) const {
- IndexIterator ii = getIndexIterator( includeUnfinishedIndexes );
+ IndexIterator ii = getIndexIterator( txn, includeUnfinishedIndexes );
while ( ii.more() ) {
IndexDescriptor* desc = ii.next();
if ( IndexNames::findPluginName( desc->keyPattern() ) == type ) {
@@ -1051,13 +1059,13 @@ namespace {
IndexCatalogEntry* entry = *i;
// If it's a background index, we DO NOT want to log anything.
- bool logIfError = entry->isReady() ? !noWarn : false;
+ bool logIfError = entry->isReady(txn) ? !noWarn : false;
_unindexRecord(txn, entry, obj, loc, logIfError);
}
}
Status IndexCatalog::checkNoIndexConflicts( OperationContext* txn, const BSONObj &obj ) {
- IndexIterator ii = getIndexIterator( true );
+ IndexIterator ii = getIndexIterator( txn, true );
while ( ii.more() ) {
IndexDescriptor* descriptor = ii.next();
diff --git a/src/mongo/db/catalog/index_catalog.h b/src/mongo/db/catalog/index_catalog.h
index 2f4ed0b677e..a3646d9ead2 100644
--- a/src/mongo/db/catalog/index_catalog.h
+++ b/src/mongo/db/catalog/index_catalog.h
@@ -62,44 +62,50 @@ namespace mongo {
// ---- accessors -----
- int numIndexesTotal() const;
- int numIndexesReady() const;
- int numIndexesInProgress() const { return numIndexesTotal() - numIndexesReady(); }
+ int numIndexesTotal( OperationContext* txn ) const;
+ int numIndexesReady( OperationContext* txn ) const;
+ int numIndexesInProgress( OperationContext* txn ) const {
+ return numIndexesTotal(txn) - numIndexesReady(txn);
+ }
/**
* this is in "alive" until the Collection goes away
* in which case everything from this tree has to go away
*/
- bool haveIdIndex() const;
+ bool haveIdIndex( OperationContext* txn ) const;
/**
* Returns the spec for the id index to create by default for this collection.
*/
BSONObj getDefaultIdIndexSpec() const;
- IndexDescriptor* findIdIndex() const;
+ IndexDescriptor* findIdIndex( OperationContext* txn ) const;
/**
* @return null if cannot find
*/
- IndexDescriptor* findIndexByName( const StringData& name,
+ IndexDescriptor* findIndexByName( OperationContext* txn,
+ const StringData& name,
bool includeUnfinishedIndexes = false ) const;
/**
* @return null if cannot find
*/
- IndexDescriptor* findIndexByKeyPattern( const BSONObj& key,
+ IndexDescriptor* findIndexByKeyPattern( OperationContext* txn,
+ const BSONObj& key,
bool includeUnfinishedIndexes = false ) const;
/* Returns the index entry for the first index whose prefix contains
* 'keyPattern'. If 'requireSingleKey' is true, skip indices that contain
* array attributes. Otherwise, returns NULL.
*/
- IndexDescriptor* findIndexByPrefix( const BSONObj &keyPattern,
+ IndexDescriptor* findIndexByPrefix( OperationContext* txn,
+ const BSONObj &keyPattern,
bool requireSingleKey ) const;
- void findIndexByType( const std::string& type,
+ void findIndexByType( OperationContext* txn,
+ const std::string& type,
std::vector<IndexDescriptor*>& matches,
bool includeUnfinishedIndexes = false ) const;
@@ -123,11 +129,15 @@ namespace mongo {
// returns the access method for the last return IndexDescriptor
IndexAccessMethod* accessMethod( IndexDescriptor* desc );
private:
- IndexIterator( const IndexCatalog* cat, bool includeUnfinishedIndexes );
+ IndexIterator( OperationContext* txn,
+ const IndexCatalog* cat,
+ bool includeUnfinishedIndexes );
void _advance();
bool _includeUnfinishedIndexes;
+
+ OperationContext* _txn;
const IndexCatalog* _catalog;
IndexCatalogEntryContainer::const_iterator _iterator;
@@ -139,8 +149,9 @@ namespace mongo {
friend class IndexCatalog;
};
- IndexIterator getIndexIterator( bool includeUnfinishedIndexes ) const {
- return IndexIterator( this, includeUnfinishedIndexes );
+ IndexIterator getIndexIterator( OperationContext* txn,
+ bool includeUnfinishedIndexes ) const {
+ return IndexIterator( txn, this, includeUnfinishedIndexes );
};
// ---- index set modifiers ------
@@ -182,7 +193,7 @@ namespace mongo {
// ---- modify single index
- bool isMultikey( const IndexDescriptor* idex );
+ bool isMultikey( OperationContext* txn, const IndexDescriptor* idex );
// --- these probably become private?
diff --git a/src/mongo/db/catalog/index_catalog_entry.cpp b/src/mongo/db/catalog/index_catalog_entry.cpp
index 511bddf7cb0..fc0c171975c 100644
--- a/src/mongo/db/catalog/index_catalog_entry.cpp
+++ b/src/mongo/db/catalog/index_catalog_entry.cpp
@@ -49,8 +49,8 @@ namespace mongo {
HeadManagerImpl(IndexCatalogEntry* ice) : _catalogEntry(ice) { }
virtual ~HeadManagerImpl() { }
- const DiskLoc getHead() const {
- return _catalogEntry->head();
+ const DiskLoc getHead(OperationContext* txn) const {
+ return _catalogEntry->head(txn);
}
void setHead(OperationContext* txn, const DiskLoc newHead) {
@@ -85,27 +85,28 @@ namespace mongo {
delete _descriptor;
}
- void IndexCatalogEntry::init( IndexAccessMethod* accessMethod ) {
+ void IndexCatalogEntry::init( OperationContext* txn,
+ IndexAccessMethod* accessMethod ) {
verify( _accessMethod == NULL );
_accessMethod = accessMethod;
- _isReady = _catalogIsReady();
- _head = _catalogHead();
- _isMultikey = _catalogIsMultikey();
+ _isReady = _catalogIsReady( txn );
+ _head = _catalogHead( txn );
+ _isMultikey = _catalogIsMultikey( txn );
}
- const DiskLoc& IndexCatalogEntry::head() const {
- DEV verify( _head == _catalogHead() );
+ const DiskLoc& IndexCatalogEntry::head( OperationContext* txn ) const {
+ DEV invariant( _head == _catalogHead( txn ) );
return _head;
}
- bool IndexCatalogEntry::isReady() const {
- DEV verify( _isReady == _catalogIsReady() );
+ bool IndexCatalogEntry::isReady( OperationContext* txn ) const {
+ DEV invariant( _isReady == _catalogIsReady( txn ) );
return _isReady;
}
- bool IndexCatalogEntry::isMultikey() const {
- DEV verify( _isMultikey == _catalogIsMultikey() );
+ bool IndexCatalogEntry::isMultikey( OperationContext* txn ) const {
+ DEV invariant( _isMultikey == _catalogIsMultikey( txn ) );
return _isMultikey;
}
@@ -113,7 +114,6 @@ namespace mongo {
void IndexCatalogEntry::setIsReady( bool newIsReady ) {
_isReady = newIsReady;
- verify( isReady() == newIsReady );
}
void IndexCatalogEntry::setHead( OperationContext* txn, DiskLoc newHead ) {
@@ -124,7 +124,7 @@ namespace mongo {
}
void IndexCatalogEntry::setMultikey( OperationContext* txn ) {
- if ( isMultikey() )
+ if ( isMultikey( txn ) )
return;
if ( _collection->setIndexIsMultikey( txn,
_descriptor->indexName(),
@@ -140,16 +140,16 @@ namespace mongo {
// ----
- bool IndexCatalogEntry::_catalogIsReady() const {
- return _collection->isIndexReady( _descriptor->indexName() );
+ bool IndexCatalogEntry::_catalogIsReady( OperationContext* txn ) const {
+ return _collection->isIndexReady( txn, _descriptor->indexName() );
}
- DiskLoc IndexCatalogEntry::_catalogHead() const {
- return _collection->getIndexHead( _descriptor->indexName() );
+ DiskLoc IndexCatalogEntry::_catalogHead( OperationContext* txn ) const {
+ return _collection->getIndexHead( txn, _descriptor->indexName() );
}
- bool IndexCatalogEntry::_catalogIsMultikey() const {
- return _collection->isIndexMultikey( _descriptor->indexName() );
+ bool IndexCatalogEntry::_catalogIsMultikey( OperationContext* txn ) const {
+ return _collection->isIndexMultikey( txn, _descriptor->indexName() );
}
// ------------------
diff --git a/src/mongo/db/catalog/index_catalog_entry.h b/src/mongo/db/catalog/index_catalog_entry.h
index 77f19c8d99b..79f33f06f91 100644
--- a/src/mongo/db/catalog/index_catalog_entry.h
+++ b/src/mongo/db/catalog/index_catalog_entry.h
@@ -57,7 +57,8 @@ namespace mongo {
const string& ns() const { return _ns; }
- void init( IndexAccessMethod* accessMethod );
+ void init( OperationContext* txn,
+ IndexAccessMethod* accessMethod );
IndexDescriptor* descriptor() { return _descriptor; }
const IndexDescriptor* descriptor() const { return _descriptor; }
@@ -69,7 +70,7 @@ namespace mongo {
/// ---------------------
- const DiskLoc& head() const;
+ const DiskLoc& head( OperationContext* txn ) const;
void setHead( OperationContext* txn, DiskLoc newHead );
@@ -79,18 +80,18 @@ namespace mongo {
// --
- bool isMultikey() const;
+ bool isMultikey( OperationContext* txn ) const;
void setMultikey( OperationContext* txn );
// if this ready is ready for queries
- bool isReady() const;
+ bool isReady( OperationContext* txn ) const;
private:
- bool _catalogIsReady() const;
- DiskLoc _catalogHead() const;
- bool _catalogIsMultikey() const;
+ bool _catalogIsReady( OperationContext* txn ) const;
+ DiskLoc _catalogHead( OperationContext* txn ) const;
+ bool _catalogIsMultikey( OperationContext* txn ) const;
// -----
diff --git a/src/mongo/db/catalog/index_create.cpp b/src/mongo/db/catalog/index_create.cpp
index 86bed4182fe..07031334378 100644
--- a/src/mongo/db/catalog/index_create.cpp
+++ b/src/mongo/db/catalog/index_create.cpp
@@ -195,7 +195,7 @@ namespace mongo {
const char* curopMessage = _buildInBackground ? "Index Build (background)" : "Index Build";
ProgressMeter* progress = _txn->setMessage(curopMessage,
curopMessage,
- _collection->numRecords());
+ _collection->numRecords(_txn));
Timer t;
@@ -233,7 +233,7 @@ namespace mongo {
if (_allowInterruption)
_txn->checkForInterrupt();
- progress->setTotalWhileRunning( _collection->numRecords() );
+ progress->setTotalWhileRunning( _collection->numRecords(_txn) );
}
progress->finished();