Skip to content

Commit ee2e11d

Browse files
committed
SERVER-11643: remove many nsdetails calls
1 parent db847f1 commit ee2e11d

File tree

9 files changed

+69
-60
lines changed

9 files changed

+69
-60
lines changed

src/mongo/db/catalog/index_catalog.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,9 +1094,13 @@ namespace mongo {
10941094
}
10951095

10961096
const IndexAccessMethod* IndexCatalog::getIndex( const IndexDescriptor* desc ) const {
1097+
return getEntry( desc )->accessMethod();
1098+
}
1099+
1100+
const IndexCatalogEntry* IndexCatalog::getEntry( const IndexDescriptor* desc ) const {
10971101
const IndexCatalogEntry* entry = _entries.find( desc );
10981102
massert( 17357, "cannot find index entry", entry );
1099-
return entry->accessMethod();
1103+
return entry;
11001104
}
11011105

11021106
IndexAccessMethod* IndexCatalog::_createAccessMethod( const IndexDescriptor* desc,

src/mongo/db/catalog/index_catalog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ namespace mongo {
103103
bool includeUnfinishedIndexes = false ) const;
104104

105105
// never returns NULL
106+
const IndexCatalogEntry* getEntry( const IndexDescriptor* desc ) const;
107+
106108
IndexAccessMethod* getIndex( const IndexDescriptor* desc );
107109
const IndexAccessMethod* getIndex( const IndexDescriptor* desc ) const;
108110

src/mongo/db/commands/index_stats.cpp

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@
3030
#include "mongo/db/auth/action_set.h"
3131
#include "mongo/db/auth/action_type.h"
3232
#include "mongo/db/auth/privilege.h"
33-
#include "mongo/db/structure/btree/btree.h"
33+
#include "mongo/db/catalog/index_catalog.h"
34+
#include "mongo/db/catalog/index_catalog_entry.h"
3435
#include "mongo/db/commands.h"
3536
#include "mongo/db/db.h"
36-
#include "mongo/db/structure/catalog/index_details.h"
3737
#include "mongo/db/jsobj.h"
38+
#include "mongo/db/index/index_descriptor.h"
3839
#include "mongo/db/kill_current_op.h"
39-
#include "mongo/db/structure/catalog/namespace_details.h"
40+
#include "mongo/db/structure/btree/btree.h"
4041
#include "mongo/util/descriptive_stats.h"
4142

4243
namespace mongo {
@@ -353,41 +354,35 @@ namespace mongo {
353354
*
354355
* @return true on success, false otherwise
355356
*/
356-
bool runInternal(const NamespaceDetails* nsd, IndexStatsParams params, string& errmsg,
357+
bool runInternal(const Collection* collection, IndexStatsParams params, string& errmsg,
357358
BSONObjBuilder& result) {
358359

359-
const IndexDetails* details = NULL;
360+
const IndexCatalog* indexCatalog = collection->getIndexCatalog();
360361

361-
// casting away const, we are not going to modify NamespaceDetails
362-
// but ii() is not marked const, see SERVER-7619
363-
for (NamespaceDetails::IndexIterator it = const_cast<NamespaceDetails*>(nsd)->ii();
364-
it.more();) {
365-
IndexDetails& cur = it.next();
366-
if (cur.indexName() == params.indexName) details = &cur;
367-
}
362+
IndexDescriptor* descriptor = indexCatalog->findIndexByName( params.indexName );
368363

369-
if (details == NULL) {
364+
if (descriptor == NULL) {
370365
errmsg = "the requested index does not exist";
371366
return false;
372367
}
373368

374-
result << "index" << details->indexName()
375-
<< "version" << details->version()
376-
<< "isIdIndex" << details->isIdIndex()
377-
<< "keyPattern" << details->keyPattern()
378-
<< "storageNs" << details->indexNamespace();
369+
result << "index" << descriptor->indexName()
370+
<< "version" << descriptor->version()
371+
<< "isIdIndex" << descriptor->isIdIndex()
372+
<< "keyPattern" << descriptor->keyPattern()
373+
<< "storageNs" << descriptor->indexNamespace();
379374

380375
scoped_ptr<BtreeInspector> inspector(NULL);
381-
switch (details->version()) {
376+
switch (descriptor->version()) {
382377
case 1: inspector.reset(new BtreeInspectorV1(params.expandNodes)); break;
383378
case 0: inspector.reset(new BtreeInspectorV0(params.expandNodes)); break;
384379
default:
385-
errmsg = str::stream() << "index version " << details->version() << " is "
380+
errmsg = str::stream() << "index version " << descriptor->version() << " is "
386381
<< "not supported";
387382
return false;
388383
}
389384

390-
inspector->inspect(details->head);
385+
inspector->inspect( indexCatalog->getEntry( descriptor )->head() );
391386

392387
inspector->stats().appendTo(result);
393388

@@ -498,12 +493,13 @@ namespace mongo {
498493
bool run(const string& dbname, BSONObj& cmdObj, int, string& errmsg,
499494
BSONObjBuilder& result, bool fromRepl) {
500495

501-
string ns = dbname + "." + cmdObj.firstElement().valuestrsafe();
502-
const NamespaceDetails* nsd = nsdetails(ns);
496+
NamespaceString nss( dbname, cmdObj.firstElement().valuestrsafe() );
503497
if (!serverGlobalParams.quiet) {
504-
MONGO_TLOG(0) << "CMD: indexStats " << ns << endl;
498+
MONGO_TLOG(0) << "CMD: indexStats " << nss;
505499
}
506-
if (!nsd) {
500+
501+
const Collection* collection = cc().database()->getCollection( nss.ns() );
502+
if (!collection) {
507503
errmsg = "ns not found";
508504
return false;
509505
}
@@ -535,7 +531,7 @@ namespace mongo {
535531
}
536532

537533
BSONObjBuilder resultBuilder;
538-
if (!runInternal(nsd, params, errmsg, resultBuilder))
534+
if (!runInternal(collection, params, errmsg, resultBuilder))
539535
return false;
540536
result.appendElements(resultBuilder.obj());
541537
return true;

src/mongo/db/commands/rename_collection.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ namespace mongo {
162162
}
163163

164164
{
165-
const NamespaceDetails *nsd = nsdetails( source );
165+
166166
indexesInProg = stopIndexBuilds( srcCtx.db(), cmdObj );
167-
capped = nsd->isCapped();
168-
if ( capped )
169-
for( DiskLoc i = nsd->firstExtent(); !i.isNull(); i = i.ext()->xnext )
170-
size += i.ext()->length;
167+
capped = sourceColl->isCapped();
168+
if ( capped ) {
169+
size = sourceColl->storageSize();
170+
}
171171
}
172172
}
173173

src/mongo/db/commands/test_commands.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,30 +129,31 @@ namespace mongo {
129129
public:
130130
CapTrunc() : Command( "captrunc" ) {}
131131
virtual bool slaveOk() const { return false; }
132-
virtual LockType locktype() const { return WRITE; }
132+
virtual LockType locktype() const { return NONE; }
133133
// No auth needed because it only works when enabled via command line.
134134
virtual void addRequiredPrivileges(const std::string& dbname,
135135
const BSONObj& cmdObj,
136136
std::vector<Privilege>* out) {}
137137
virtual bool run(const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) {
138138
string coll = cmdObj[ "captrunc" ].valuestrsafe();
139139
uassert( 13416, "captrunc must specify a collection", !coll.empty() );
140-
string ns = dbname + "." + coll;
140+
NamespaceString nss( dbname, coll );
141141
int n = cmdObj.getIntField( "n" );
142+
bool inc = cmdObj.getBoolField( "inc" ); // inclusive range?
142143

143-
// inclusive range?
144-
bool inc = cmdObj.getBoolField( "inc" );
145-
NamespaceDetails *nsd = nsdetails( ns );
146-
massert( 13417, "captrunc collection not found or empty", nsd);
144+
Client::WriteContext ctx( nss.ns() );
145+
Collection* collection = ctx.ctx().db()->getCollection( nss.ns() );
146+
massert( 13417, "captrunc collection not found or empty", collection);
147147

148-
boost::scoped_ptr<Runner> runner(InternalPlanner::collectionScan(ns, InternalPlanner::BACKWARD));
148+
boost::scoped_ptr<Runner> runner(InternalPlanner::collectionScan(nss.ns(),
149+
InternalPlanner::BACKWARD));
149150
DiskLoc end;
150151
// We remove 'n' elements so the start is one past that
151152
for( int i = 0; i < n + 1; ++i ) {
152153
Runner::RunnerState state = runner->getNext(NULL, &end);
153154
massert( 13418, "captrunc invalid n", Runner::RUNNER_ADVANCED == state);
154155
}
155-
nsd->cappedTruncateAfter( ns.c_str(), end, inc );
156+
collection->details()->cappedTruncateAfter( nss.ns().c_str(), end, inc );
156157
return true;
157158
}
158159
};
@@ -162,7 +163,7 @@ namespace mongo {
162163
public:
163164
EmptyCapped() : Command( "emptycapped" ) {}
164165
virtual bool slaveOk() const { return false; }
165-
virtual LockType locktype() const { return WRITE; }
166+
virtual LockType locktype() const { return NONE; }
166167
virtual bool logTheOp() { return true; }
167168
// No auth needed because it only works when enabled via command line.
168169
virtual void addRequiredPrivileges(const std::string& dbname,
@@ -182,13 +183,15 @@ namespace mongo {
182183
virtual bool run(const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) {
183184
string coll = cmdObj[ "emptycapped" ].valuestrsafe();
184185
uassert( 13428, "emptycapped must specify a collection", !coll.empty() );
185-
string ns = dbname + "." + coll;
186-
NamespaceDetails *nsd = nsdetails( ns );
187-
massert( 13429, "emptycapped no such collection", nsd );
186+
NamespaceString nss( dbname, coll );
187+
188+
Client::WriteContext ctx( nss.ns() );
189+
Collection* collection = ctx.ctx().db()->getCollection( nss.ns() );
190+
massert( 13429, "emptycapped no such collection", collection );
188191

189192
std::vector<BSONObj> indexes = stopIndexBuilds(cc().database(), cmdObj);
190193

191-
nsd->emptyCappedCollection( ns.c_str() );
194+
collection->details()->emptyCappedCollection( nss.ns().c_str() );
192195

193196
IndexBuilder::restoreIndexes(indexes);
194197

src/mongo/db/commands/touch.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,18 @@
3535
#include <string>
3636
#include <vector>
3737

38-
#include "mongo/db/kill_current_op.h"
3938
#include "mongo/db/auth/action_set.h"
4039
#include "mongo/db/auth/action_type.h"
4140
#include "mongo/db/auth/authorization_manager.h"
4241
#include "mongo/db/auth/privilege.h"
42+
#include "mongo/db/catalog/collection.h"
4343
#include "mongo/db/commands.h"
44-
#include "mongo/db/d_concurrency.h"
4544
#include "mongo/db/curop-inl.h"
46-
#include "mongo/db/structure/catalog/namespace_details.h"
47-
#include "mongo/db/structure/catalog/index_details.h"
45+
#include "mongo/db/d_concurrency.h"
46+
#include "mongo/db/index/index_descriptor.h"
4847
#include "mongo/db/jsobj.h"
48+
#include "mongo/db/kill_current_op.h"
4949
#include "mongo/db/pdfile.h"
50-
#include "mongo/db/catalog/collection.h"
5150
#include "mongo/util/timer.h"
5251
#include "mongo/util/touch_pages.h"
5352

@@ -169,13 +168,15 @@ namespace mongo {
169168
std::vector< std::string > indexes;
170169
{
171170
Client::ReadContext ctx(ns);
172-
NamespaceDetails *nsd = nsdetails(ns);
173-
massert( 16153, "namespace does not exist", nsd );
171+
Collection* collection = ctx.ctx().db()->getCollection( ns );
172+
massert( 16153, "namespace does not exist", collection );
173+
174+
IndexCatalog::IndexIterator ii =
175+
collection->getIndexCatalog()->getIndexIterator( false );
174176

175-
NamespaceDetails::IndexIterator ii = nsd->ii();
176177
while ( ii.more() ) {
177-
IndexDetails& idx = ii.next();
178-
indexes.push_back( idx.indexNamespace() );
178+
IndexDescriptor* desc = ii.next();
179+
indexes.push_back( desc->indexNamespace() );
179180
}
180181
}
181182

src/mongo/db/exec/collection_scan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace mongo {
7575

7676
CollectionScanParams _params;
7777

78-
// True if nsdetails(_ns) == NULL on our first call to work.
78+
// True if Database::getCollection(_ns) == NULL on our first call to work.
7979
bool _nsDropped;
8080

8181
// If we want to return a DiskLoc and it points at something that's not in memory, we return

src/mongo/db/exec/oplogstart.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@
2828

2929
#include "mongo/db/exec/oplogstart.h"
3030

31-
#include "mongo/db/pdfile.h"
31+
#include "mongo/db/catalog/collection.h"
32+
#include "mongo/db/catalog/database.h"
33+
#include "mongo/db/client.h"
3234
#include "mongo/db/storage/extent.h"
35+
#include "mongo/db/storage/record.h"
36+
#include "mongo/db/structure/catalog/namespace_details.h"
3337

3438
namespace mongo {
3539

@@ -52,7 +56,8 @@ namespace mongo {
5256
params.ns = _ns;
5357
params.direction = CollectionScanParams::BACKWARD;
5458
_cs.reset(new CollectionScan(params, _workingSet, NULL));
55-
_nsd = nsdetails(_ns.c_str());
59+
Collection* collection = cc().database()->getCollection( _ns );
60+
_nsd = collection->details();
5661
_needInit = false;
5762
_backwardsScanning = true;
5863
_timer.reset();

src/mongo/db/structure/catalog/cap.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ namespace mongo {
330330
}
331331

332332
void NamespaceDetails::cappedTruncateAfter(const char *ns, DiskLoc end, bool inclusive) {
333-
DEV verify( this == nsdetails(ns) );
334333
verify( cappedLastDelRecLastExtent().isValid() );
335334

336335
// We iteratively remove the newest document until the newest document
@@ -425,7 +424,6 @@ namespace mongo {
425424
}
426425

427426
void NamespaceDetails::emptyCappedCollection( const char *ns ) {
428-
DEV verify( this == nsdetails(ns) );
429427
massert( 13424, "collection must be capped", isCapped() );
430428
massert( 13425, "background index build in progress", !_indexBuildsInProgress );
431429

0 commit comments

Comments
 (0)