diff options
-rw-r--r-- | src/mongo/db/catalog/collection.cpp | 25 | ||||
-rw-r--r-- | src/mongo/db/catalog/collection.h | 4 | ||||
-rw-r--r-- | src/mongo/db/catalog/database.cpp | 30 | ||||
-rw-r--r-- | src/mongo/db/catalog/database.h | 5 | ||||
-rw-r--r-- | src/mongo/db/dbcommands.cpp | 7 |
5 files changed, 33 insertions, 38 deletions
diff --git a/src/mongo/db/catalog/collection.cpp b/src/mongo/db/catalog/collection.cpp index 6f77c33c4f2..635b1159db6 100644 --- a/src/mongo/db/catalog/collection.cpp +++ b/src/mongo/db/catalog/collection.cpp @@ -441,6 +441,31 @@ namespace mongo { return _recordStore->dataSize( txn ); } + uint64_t Collection::getIndexSize(OperationContext* opCtx, + BSONObjBuilder* details, + int scale) { + + IndexCatalog* idxCatalog = getIndexCatalog(); + + IndexCatalog::IndexIterator ii = idxCatalog->getIndexIterator(opCtx, true); + + uint64_t totalSize = 0; + + while (ii.more()) { + IndexDescriptor* d = ii.next(); + IndexAccessMethod* iam = idxCatalog->getIndex(d); + + long long ds = iam->getSpaceUsedBytes(opCtx); + + totalSize += ds; + if (details) { + details->appendNumber(d->indexName(), ds / scale); + } + } + + return totalSize; + } + /** * order will be: * 1) store index specs diff --git a/src/mongo/db/catalog/collection.h b/src/mongo/db/catalog/collection.h index bfc9add1235..3cb0b7d4816 100644 --- a/src/mongo/db/catalog/collection.h +++ b/src/mongo/db/catalog/collection.h @@ -257,6 +257,10 @@ namespace mongo { return static_cast<int>( dataSize( txn ) / n ); } + uint64_t getIndexSize(OperationContext* opCtx, + BSONObjBuilder* details = NULL, + int scale = 1); + // --- end suspect things private: diff --git a/src/mongo/db/catalog/database.cpp b/src/mongo/db/catalog/database.cpp index 75f777e2877..6f084aec8d0 100644 --- a/src/mongo/db/catalog/database.cpp +++ b/src/mongo/db/catalog/database.cpp @@ -240,34 +240,6 @@ namespace mongo { return true; } - long long Database::getIndexSizeForCollection(OperationContext* opCtx, - Collection* coll, - BSONObjBuilder* details, - int scale ) { - if ( !coll ) - return 0; - - IndexCatalog* idxCatalog = coll->getIndexCatalog(); - - IndexCatalog::IndexIterator ii = idxCatalog->getIndexIterator( opCtx, true ); - - long long totalSize = 0; - - while ( ii.more() ) { - IndexDescriptor* d = ii.next(); - IndexAccessMethod* iam = idxCatalog->getIndex( d ); - - long long ds = iam->getSpaceUsedBytes( opCtx ); - - totalSize += ds; - if ( details ) { - details->appendNumber( d->indexName(), ds / scale ); - } - } - - return totalSize; - } - void Database::getStats( OperationContext* opCtx, BSONObjBuilder* output, double scale ) { list<string> collections; _dbEntry->getCollectionNamespaces( &collections ); @@ -296,7 +268,7 @@ namespace mongo { numExtents += temp.obj()["numExtents"].numberInt(); // XXX indexes += collection->getIndexCatalog()->numIndexesTotal( opCtx ); - indexSize += getIndexSizeForCollection(opCtx, collection); + indexSize += collection->getIndexSize(opCtx); } output->append ( "db" , _name ); diff --git a/src/mongo/db/catalog/database.h b/src/mongo/db/catalog/database.h index 40c6903ea5c..230a220663f 100644 --- a/src/mongo/db/catalog/database.h +++ b/src/mongo/db/catalog/database.h @@ -91,11 +91,6 @@ namespace mongo { void getStats( OperationContext* opCtx, BSONObjBuilder* output, double scale = 1 ); - long long getIndexSizeForCollection( OperationContext* opCtx, - Collection* collections, - BSONObjBuilder* details = NULL, - int scale = 1 ); - const DatabaseCatalogEntry* getDatabaseCatalogEntry() const; Status dropCollection( OperationContext* txn, const StringData& fullns ); diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp index 134d0eeb16e..793cb492604 100644 --- a/src/mongo/db/dbcommands.cpp +++ b/src/mongo/db/dbcommands.cpp @@ -951,10 +951,9 @@ namespace mongo { collection->getRecordStore()->appendCustomStats( txn, &result, scale ); BSONObjBuilder indexSizes; - result.appendNumber( "totalIndexSize" , db->getIndexSizeForCollection(txn, - collection, - &indexSizes, - scale) / scale ); + long long indexSize = collection->getIndexSize(txn, &indexSizes, scale); + + result.appendNumber("totalIndexSize", indexSize / scale); result.append("indexSizes", indexSizes.obj()); return true; |