diff options
author | Eric Milkie <milkie@10gen.com> | 2015-05-12 11:38:13 -0400 |
---|---|---|
committer | Eric Milkie <milkie@10gen.com> | 2015-05-18 15:10:22 -0400 |
commit | a029932768cdc12dd86a0afee4a7411065230c5a (patch) | |
tree | e0b8e0524634a31c71fcf820eeb8edfc3481dfc9 | |
parent | eff5684b59b2bcf104c3003ba04aa4fb847429ed (diff) | |
download | mongo-a029932768cdc12dd86a0afee4a7411065230c5a.tar.gz |
SERVER-16348 prohibit renaming a collection with bg indexes in progress
-rw-r--r-- | src/mongo/db/commands/rename_collection.cpp | 38 | ||||
-rw-r--r-- | src/mongo/db/storage/extent_manager.cpp | 2 |
2 files changed, 4 insertions, 36 deletions
diff --git a/src/mongo/db/commands/rename_collection.cpp b/src/mongo/db/commands/rename_collection.cpp index 8fe0e17c5b1..b695b88b023 100644 --- a/src/mongo/db/commands/rename_collection.cpp +++ b/src/mongo/db/commands/rename_collection.cpp @@ -29,6 +29,7 @@ */ #include "mongo/client/dbclientcursor.h" +#include "mongo/db/background.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/index_catalog.h" #include "mongo/db/commands.h" @@ -66,34 +67,6 @@ namespace mongo { help << " example: { renameCollection: foo.a, to: bar.b }"; } - virtual std::vector<BSONObj> stopIndexBuilds(Database* db, - const BSONObj& cmdObj) { - string source = cmdObj.getStringField( name.c_str() ); - string target = cmdObj.getStringField( "to" ); - - IndexCatalog::IndexKillCriteria criteria; - criteria.ns = source; - std::vector<BSONObj> prelim = - IndexBuilder::killMatchingIndexBuilds(db->getCollection(source), criteria); - - std::vector<BSONObj> indexes; - - for (int i = 0; i < static_cast<int>(prelim.size()); i++) { - // Change the ns - BSONObj stripped = prelim[i].removeField("ns"); - BSONObjBuilder builder; - builder.appendElements(stripped); - builder.append("ns", target); - indexes.push_back(builder.obj()); - } - - return indexes; - } - - virtual void restoreIndexBuildsOnSource(std::vector<BSONObj> indexesInProg, std::string source) { - IndexBuilder::restoreIndexes( indexesInProg ); - } - virtual bool run(const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { string source = cmdObj.getStringField( name.c_str() ); string target = cmdObj.getStringField( "to" ); @@ -121,6 +94,8 @@ namespace mongo { } } + BackgroundOperation::assertNoBgOpInProgForNs( source ); + string sourceDB = nsToDatabase(source); string targetDB = nsToDatabase(target); @@ -163,7 +138,6 @@ namespace mongo { { const NamespaceDetails *nsd = nsdetails( source ); - indexesInProg = stopIndexBuilds( srcCtx.db(), cmdObj ); capped = nsd->isCapped(); if ( capped ) for( DiskLoc i = nsd->firstExtent(); !i.isNull(); i = i.ext()->xnext ) @@ -185,7 +159,6 @@ namespace mongo { Status s = cc().database()->dropCollection( target ); if ( !s.isOK() ) { errmsg = s.toString(); - restoreIndexBuildsOnSource( indexesInProg, source ); return false; } } @@ -197,7 +170,6 @@ namespace mongo { cmdObj["stayTemp"].trueValue() ); if ( !s.isOK() ) { errmsg = s.toString(); - restoreIndexBuildsOnSource( indexesInProg, source ); return false; } return true; @@ -224,7 +196,6 @@ namespace mongo { } if ( !targetColl ) { errmsg = "Failed to create target collection."; - restoreIndexBuildsOnSource( indexesInProg, source ); return false; } } @@ -268,7 +239,6 @@ namespace mongo { Status s = ctx.db()->dropCollection( target ); if ( !s.isOK() ) errmsg = s.toString(); - restoreIndexBuildsOnSource( indexesInProg, source ); return false; } @@ -322,7 +292,6 @@ namespace mongo { Status s = ctx.db()->dropCollection( target ); if ( !s.isOK() ) errmsg = s.toString(); - restoreIndexBuildsOnSource( indexesInProg, source ); return false; } } @@ -333,7 +302,6 @@ namespace mongo { Status s = srcCtx.db()->dropCollection( source ); if ( !s.isOK() ) { errmsg = s.toString(); - restoreIndexBuildsOnSource( indexesInProg, source ); return false; } } diff --git a/src/mongo/db/storage/extent_manager.cpp b/src/mongo/db/storage/extent_manager.cpp index 89a8829d98b..ac9f10da144 100644 --- a/src/mongo/db/storage/extent_manager.cpp +++ b/src/mongo/db/storage/extent_manager.cpp @@ -105,7 +105,7 @@ namespace mongo { verify(this); DEV Lock::assertAtLeastReadLocked( _dbname ); if ( n < 0 || n >= static_cast<int>(_files.size()) ) - log() << "uh oh: " << n; + severe() << "unable to open file number " << n; verify( n >= 0 && n < static_cast<int>(_files.size()) ); return _files[n]; } |