diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-03-02 15:24:21 -0500 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-03-02 15:24:21 -0500 |
commit | 221e9a82b87e4f3297b4b057820c90820bf0d009 (patch) | |
tree | 81e81b7672327e0e61ed079605716e89fba289e7 | |
parent | 7e6ff30639d758104ce64ffac5b6ac588ae3d976 (diff) | |
download | mongo-221e9a82b87e4f3297b4b057820c90820bf0d009.tar.gz |
SERVER-16348 renameCollection should skip in-progress index builds
-rw-r--r-- | src/mongo/db/catalog/database.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/mongo/db/catalog/database.cpp b/src/mongo/db/catalog/database.cpp index c4f4bcd272b..387bee2a082 100644 --- a/src/mongo/db/catalog/database.cpp +++ b/src/mongo/db/catalog/database.cpp @@ -515,18 +515,26 @@ namespace mongo { audit::logRenameCollection( currentClient.get(), fromNS, toNS ); // move index namespaces - BSONObj oldIndexSpec; - while( Helpers::findOne( _indexesName, BSON( "ns" << fromNS ), oldIndexSpec ) ) { - oldIndexSpec = oldIndexSpec.getOwned(); + BSONObj indexSpec; + while (Helpers::findOne(_indexesName, BSON("ns" << fromNS), indexSpec)) { + const BSONObj oldIndexSpec = indexSpec.getOwned(); + int indexI = details->_catalogFindIndexByName(oldIndexSpec.getStringField("name")); + + // Return value of -1 means the index was not found. That can only happen if it is an + // in-progress index. We skip those, because the restart call after rename will kick + // them off again on the new namespace. + if (indexI == -1) { + continue; + } BSONObj newIndexSpec; { BSONObjBuilder b; - BSONObjIterator i( oldIndexSpec ); - while( i.more() ) { + BSONObjIterator i(oldIndexSpec); + while (i.more()) { BSONElement e = i.next(); - if ( strcmp( e.fieldName(), "ns" ) != 0 ) - b.append( e ); + if (strcmp(e.fieldName(), "ns") != 0) + b.append(e); else b << "ns" << toNS; } @@ -538,7 +546,6 @@ namespace mongo { if ( !newIndexSpecLoc.isOK() ) return newIndexSpecLoc.getStatus(); - int indexI = details->_catalogFindIndexByName( oldIndexSpec.getStringField( "name" ) ); IndexDetails &indexDetails = details->idx(indexI); string oldIndexNs = indexDetails.indexNamespace(); indexDetails.info = newIndexSpecLoc.getValue(); |