diff options
author | Mathias Stearn <mathias@10gen.com> | 2013-02-28 13:13:47 -0500 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2013-02-28 19:39:39 -0500 |
commit | c909370ff97ccf17d340ab3c337269f8c181af92 (patch) | |
tree | 76a83e3ebf5cae964ea006d4eb2ccba7c7976cf6 | |
parent | 6ea3fb90c6a90cad47501c4581c7206545f5e3f3 (diff) | |
download | mongo-c909370ff97ccf17d340ab3c337269f8c181af92.tar.gz |
SERVER-8594 fix clearTmpCollections for collections with indexes
-rw-r--r-- | jstests/slowNightly/temp_namespace.js | 8 | ||||
-rw-r--r-- | src/mongo/db/database.cpp | 25 |
2 files changed, 24 insertions, 9 deletions
diff --git a/jstests/slowNightly/temp_namespace.js b/jstests/slowNightly/temp_namespace.js index bd96e2fdb63..54ee3bfa4f2 100644 --- a/jstests/slowNightly/temp_namespace.js +++ b/jstests/slowNightly/temp_namespace.js @@ -6,18 +6,22 @@ path = '/data/db/'+testname conn = startMongodEmpty("--port", 30000, "--dbpath", path, "--smallfiles", "--noprealloc", "--nopreallocj"); d = conn.getDB('test') d.runCommand({create: testname+'temp1', temp: true}); +d[testname+'temp1'].ensureIndex({x:1}); d.runCommand({create: testname+'temp2', temp: 1}); +d[testname+'temp2'].ensureIndex({x:1}); d.runCommand({create: testname+'keep1', temp: false}); d.runCommand({create: testname+'keep2', temp: 0}); d.runCommand({create: testname+'keep3'}); d[testname+'keep4'].insert({}); -assert.eq(d.system.namespaces.count({name: /temp\d$/}) , 2) +assert.eq(d.system.namespaces.count({name: /temp\d$/}) , 2) // collections +assert.eq(d.system.namespaces.count({name: /temp\d\.\$.*$/}) , 4) //indexes (2 _id + 2 x) assert.eq(d.system.namespaces.count({name: /keep\d$/}) , 4) stopMongod(30000); conn = startMongodNoReset("--port", 30000, "--dbpath", path, "--smallfiles", "--noprealloc", "--nopreallocj"); d = conn.getDB('test') -assert.eq(d.system.namespaces.count({name: /temp\d$/}) , 0) +assert.eq(d.system.namespaces.count({name: /temp\d$/}) , 0) // collections +assert.eq(d.system.namespaces.count({name: /temp\d\.\$.*$/}) , 0) //indexes assert.eq(d.system.namespaces.count({name: /keep\d$/}) , 4) stopMongod(30000); diff --git a/src/mongo/db/database.cpp b/src/mongo/db/database.cpp index dbb6249535d..76a2055ab80 100644 --- a/src/mongo/db/database.cpp +++ b/src/mongo/db/database.cpp @@ -236,30 +236,41 @@ namespace mongo { Lock::assertWriteLocked( name ); Client::Context ctx( name ); - shared_ptr<Cursor> cursor = theDataFileMgr.findAll( name + ".system.namespaces" ); + string systemNamespaces = name + ".system.namespaces"; + + // Note: we build up a toDelete vector rather than dropping the collection inside the loop + // to avoid modifying the system.namespaces collection while iterating over it since that + // would corrupt the cursor. + vector<string> toDelete; + shared_ptr<Cursor> cursor = theDataFileMgr.findAll(systemNamespaces); while ( cursor && cursor->ok() ) { - BSONObj x = cursor->current(); + BSONObj nsObj = cursor->current(); cursor->advance(); - BSONElement e = x.getFieldDotted( "options.temp" ); + BSONElement e = nsObj.getFieldDotted( "options.temp" ); if ( !e.trueValue() ) continue; - string ns = x["name"].String(); + string ns = nsObj["name"].String(); // Do not attempt to drop indexes if ( !NamespaceString::normal(ns.c_str()) ) continue; + toDelete.push_back(ns); + } + + for (size_t i=0; i < toDelete.size(); i++) { + const string& ns = toDelete[i]; + string errmsg; BSONObjBuilder result; - dropCollection( ns, errmsg, result ); + dropCollection(ns, errmsg, result); if ( errmsg.size() > 0 ) { - warning() << "could not delete temp collection: " << x + warning() << "could not delete temp collection: " << ns << " because of: " << errmsg << endl; } - } } |