summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2010-04-01 10:19:38 -0400
committerEliot Horowitz <eliot@10gen.com>2010-04-01 10:20:10 -0400
commitda5872874f2285ef3c1eb3a45810f73f4b6ae6af (patch)
treea2484e54d32c405e4f73b520fd9f23938c08182a
parent7109c020a33dc721acc75f184cba444cfce15dc8 (diff)
downloadmongo-da5872874f2285ef3c1eb3a45810f73f4b6ae6af.tar.gz
getIndexSizeForCollection shouldn't use DBDIrectClient SERVER-860
-rw-r--r--db/dbcommands.cpp33
1 files changed, 20 insertions, 13 deletions
diff --git a/db/dbcommands.cpp b/db/dbcommands.cpp
index 6d1aa5a80eb..46c2e4d5e75 100644
--- a/db/dbcommands.cpp
+++ b/db/dbcommands.cpp
@@ -1020,19 +1020,26 @@ namespace mongo {
namespace {
long long getIndexSizeForCollection(string db, string ns, BSONObjBuilder* details=NULL, int scale = 1 ){
- DBDirectClient client;
- auto_ptr<DBClientCursor> indexes =
- client.query(db + ".system.indexes", QUERY( "ns" << ns));
-
- long long totalSize = 0;
- while (indexes->more()){
- BSONObj index = indexes->nextSafe();
- NamespaceDetails * nsd = nsdetails( (ns + ".$" + index["name"].valuestrsafe()).c_str() );
- if (!nsd)
- continue; // nothing to do here
- totalSize += nsd->datasize;
- if (details)
- details->appendNumber(index["name"].valuestrsafe(), nsd->datasize / scale );
+ dbMutex.assertAtLeastReadLocked();
+
+ NamespaceDetails * nsd = nsdetails( ns.c_str() );
+ if ( ! nsd )
+ return 0;
+
+ long long totalSize = 0;
+
+ NamespaceDetails::IndexIterator ii = nsd->ii();
+ while ( ii.more() ){
+ IndexDetails& d = ii.next();
+ string collNS = d.indexNamespace();
+ NamespaceDetails * mine = nsdetails( collNS.c_str() );
+ if ( ! mine ){
+ log() << "error: have index [" << collNS << "] but no NamespaceDetails" << endl;
+ continue;
+ }
+ totalSize += mine->datasize;
+ if ( details )
+ details->appendNumber( d.indexName() , mine->datasize / scale );
}
return totalSize;
}