diff options
author | Gregory Wlodarek <gregory.wlodarek@mongodb.com> | 2019-06-20 08:38:10 -0400 |
---|---|---|
committer | Gregory Wlodarek <gregory.wlodarek@mongodb.com> | 2019-06-21 20:32:16 -0400 |
commit | 45dc520352849b4b1c958e11f5cec322fb67e8f2 (patch) | |
tree | f56c693957ebb6ac06037e3344d8452ffe770081 | |
parent | 1db8f38916334ba5a47cc1820e5f04f15c369807 (diff) | |
download | mongo-45dc520352849b4b1c958e11f5cec322fb67e8f2.tar.gz |
SERVER-41695 Remove NamespaceString::checkLengthForRename() since there are no more index name length limitations
-rw-r--r-- | src/mongo/db/catalog/rename_collection.cpp | 63 | ||||
-rw-r--r-- | src/mongo/db/catalog/rename_collection_test.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/namespace_string.cpp | 15 | ||||
-rw-r--r-- | src/mongo/db/namespace_string.h | 6 |
4 files changed, 5 insertions, 91 deletions
diff --git a/src/mongo/db/catalog/rename_collection.cpp b/src/mongo/db/catalog/rename_collection.cpp index 6e4d33f5fbf..e339e7876c7 100644 --- a/src/mongo/db/catalog/rename_collection.cpp +++ b/src/mongo/db/catalog/rename_collection.cpp @@ -77,49 +77,6 @@ bool isCollectionSharded(OperationContext* opCtx, const NamespaceString& nss) { return metadata->isSharded(); } -Status checkAllIndexesCanBeRecreatedInNewNS(OperationContext* opCtx, - Collection* coll, - const NamespaceString& newNss) { - const auto checkIndexNamespace = - serverGlobalParams.featureCompatibility.isVersionInitialized() && - serverGlobalParams.featureCompatibility.getVersion() != - ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo42; - std::string::size_type longestIndexNameLength = - checkIndexNamespace ? coll->getIndexCatalog()->getLongestIndexNameLength(opCtx) : 0; - return newNss.checkLengthForRename(longestIndexNameLength); -} - -void dropIndexesThatWillBeTooLongAfterDropPendingRename(OperationContext* opCtx, Collection* coll) { - // Compile a list of any indexes that would become too long following the - // drop-pending rename. In the case that this collection drop gets rolled back, this - // will incur a performance hit, since those indexes will have to be rebuilt from - // scratch, but data integrity is maintained. - std::vector<const IndexDescriptor*> indexesToDrop; - auto indexIter = coll->getIndexCatalog()->getIndexIterator(opCtx, true); - - // Determine which index names are too long. Since we don't have the collection - // rename optime at this time, use the maximum optime to check the index names. - auto longDpns = coll->ns().makeDropPendingNamespace(repl::OpTime::max()); - while (indexIter->more()) { - auto index = indexIter->next()->descriptor(); - auto status = longDpns.checkLengthForRename(index->indexName().size()); - if (!status.isOK()) { - indexesToDrop.push_back(index); - } - } - - // Drop the offending indexes. - auto opObserver = opCtx->getServiceContext()->getOpObserver(); - for (auto&& index : indexesToDrop) { - log() << "Collection " << coll->ns() << " contains an index name '" << index->indexName() - << "' that would be too long after drop-pending rename. Dropping index " - "immediately."; - fassert(50941, coll->getIndexCatalog()->dropIndex(opCtx, index)); - opObserver->onDropIndex( - opCtx, coll->ns(), coll->uuid(), index->indexName(), index->infoObj()); - } -} - // From a replicated to an unreplicated collection or vice versa. bool isReplicatedChanged(OperationContext* opCtx, const NamespaceString& source, @@ -166,10 +123,6 @@ Status checkSourceAndTargetNamespaces(OperationContext* opCtx, return Status(ErrorCodes::NamespaceNotFound, "source namespace does not exist"); } - auto status = checkAllIndexesCanBeRecreatedInNewNS(opCtx, sourceColl, target); - if (!status.isOK()) - return status; - BackgroundOperation::assertNoBgOpInProgForNs(source.ns()); IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgForCollection( sourceColl->uuid().get()); @@ -285,7 +238,6 @@ Status renameCollectionAndDropTarget(OperationContext* opCtx, if (!isOplogDisabledForNamespace) { invariant(opCtx->writesAreReplicated()); invariant(renameOpTimeFromApplyOps.isNull()); - dropIndexesThatWillBeTooLongAfterDropPendingRename(opCtx, targetColl); } auto numRecords = targetColl->numRecords(opCtx); @@ -503,10 +455,6 @@ Status renameBetweenDBs(OperationContext* opCtx, return {ErrorCodes::IllegalOperation, "Cannot rename collections between a replicated and an unreplicated database"}; - auto status = checkAllIndexesCanBeRecreatedInNewNS(opCtx, sourceColl, target); - if (!status.isOK()) - return status; - BackgroundOperation::assertNoBgOpInProgForNs(source.ns()); IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgForCollection( sourceColl->uuid().get()); @@ -554,11 +502,6 @@ Status renameBetweenDBs(OperationContext* opCtx, log() << "Attempting to create temporary collection: " << tmpName << " with the contents of collection: " << source; - // Check if all the source collection's indexes can be recreated in the temporary collection. - status = checkAllIndexesCanBeRecreatedInNewNS(opCtx, sourceColl, tmpName); - if (!status.isOK()) - return status; - Collection* tmpColl = nullptr; { auto collectionOptions = @@ -629,7 +572,7 @@ Status renameBetweenDBs(OperationContext* opCtx, // allows us to add and commit the index within a single WriteUnitOfWork and avoids the // possibility of seeing the index in an unfinished state. For more information on assigning // timestamps to multiple index builds, please see SERVER-35780 and SERVER-35070. - status = writeConflictRetry(opCtx, "renameCollection", tmpName.ns(), [&] { + Status status = writeConflictRetry(opCtx, "renameCollection", tmpName.ns(), [&] { WriteUnitOfWork wunit(opCtx); auto tmpIndexCatalog = tmpColl->getIndexCatalog(); auto opObserver = opCtx->getServiceContext()->getOpObserver(); @@ -683,7 +626,7 @@ Status renameBetweenDBs(OperationContext* opCtx, opCtx->checkForInterrupt(); // Cursor is left one past the end of the batch inside writeConflictRetry. auto beginBatchId = record->id; - status = writeConflictRetry(opCtx, "renameCollection", tmpName.ns(), [&] { + Status status = writeConflictRetry(opCtx, "renameCollection", tmpName.ns(), [&] { WriteUnitOfWork wunit(opCtx); // Need to reset cursor if it gets a WCE midway through. if (!record || (beginBatchId != record->id)) { @@ -720,7 +663,7 @@ Status renameBetweenDBs(OperationContext* opCtx, // Getting here means we successfully built the target copy. We now do the final // in-place rename and remove the source collection. invariant(tmpName.db() == target.db()); - status = renameCollectionWithinDB(opCtx, tmpName, target, options); + Status status = renameCollectionWithinDB(opCtx, tmpName, target, options); if (!status.isOK()) return status; diff --git a/src/mongo/db/catalog/rename_collection_test.cpp b/src/mongo/db/catalog/rename_collection_test.cpp index 539c80f08f6..578a2f5fe43 100644 --- a/src/mongo/db/catalog/rename_collection_test.cpp +++ b/src/mongo/db/catalog/rename_collection_test.cpp @@ -490,21 +490,17 @@ TEST_F(RenameCollectionTest, RenameCollectionReturnsNotMasterIfNotPrimary) { renameCollection(_opCtx.get(), _sourceNss, _targetNss, {})); } -TEST_F(RenameCollectionTest, TargetCollectionNameTooLong) { +TEST_F(RenameCollectionTest, TargetCollectionNameLong) { _createCollection(_opCtx.get(), _sourceNss); const std::string targetCollectionName(NamespaceString::MaxNsCollectionLen, 'a'); NamespaceString longTargetNss(_sourceNss.db(), targetCollectionName); - ASSERT_EQUALS(ErrorCodes::InvalidLength, - renameCollection(_opCtx.get(), _sourceNss, longTargetNss, {})); + ASSERT_OK(renameCollection(_opCtx.get(), _sourceNss, longTargetNss, {})); } TEST_F(RenameCollectionTest, LongIndexNameAllowedForTargetCollection) { ASSERT_GREATER_THAN(_targetNssDifferentDb.size(), _sourceNss.size()); std::size_t longestIndexNameAllowedForSource = NamespaceString::MaxNsLen - 2U /*strlen(".$")*/ - _sourceNss.size(); - ASSERT_OK(_sourceNss.checkLengthForRename(longestIndexNameAllowedForSource)); - ASSERT_EQUALS(ErrorCodes::InvalidLength, - _targetNssDifferentDb.checkLengthForRename(longestIndexNameAllowedForSource)); _createCollection(_opCtx.get(), _sourceNss); const std::string indexName(longestIndexNameAllowedForSource, 'a'); @@ -516,14 +512,10 @@ TEST_F(RenameCollectionTest, LongIndexNameAllowedForTemporaryCollectionForRename ASSERT_GREATER_THAN(_targetNssDifferentDb.size(), _sourceNss.size()); std::size_t longestIndexNameAllowedForTarget = NamespaceString::MaxNsLen - 2U /*strlen(".$")*/ - _targetNssDifferentDb.size(); - ASSERT_OK(_sourceNss.checkLengthForRename(longestIndexNameAllowedForTarget)); - ASSERT_OK(_targetNssDifferentDb.checkLengthForRename(longestIndexNameAllowedForTarget)); // Using XXXXX to check namespace length. Each 'X' will be replaced by a random character in // renameCollection(). const NamespaceString tempNss(_targetNssDifferentDb.getSisterNS("tmpXXXXX.renameCollection")); - ASSERT_EQUALS(ErrorCodes::InvalidLength, - tempNss.checkLengthForRename(longestIndexNameAllowedForTarget)); _createCollection(_opCtx.get(), _sourceNss); const std::string indexName(longestIndexNameAllowedForTarget, 'a'); diff --git a/src/mongo/db/namespace_string.cpp b/src/mongo/db/namespace_string.cpp index ca4f26f0d04..37ffc965c08 100644 --- a/src/mongo/db/namespace_string.cpp +++ b/src/mongo/db/namespace_string.cpp @@ -201,21 +201,6 @@ StatusWith<repl::OpTime> NamespaceString::getDropPendingNamespaceOpTime() const return repl::OpTime(Timestamp(Seconds(seconds), increment), term); } -Status NamespaceString::checkLengthForRename( - const std::string::size_type longestIndexNameLength) const { - auto longestAllowed = - std::min(std::string::size_type(NamespaceString::MaxNsCollectionLen), - std::string::size_type(NamespaceString::MaxNsLen - 2U /*strlen(".$")*/ - - longestIndexNameLength)); - if (size() > longestAllowed) { - StringBuilder sb; - sb << "collection name length of " << size() << " exceeds maximum length of " - << longestAllowed << ", allowing for index names"; - return Status(ErrorCodes::InvalidLength, sb.str()); - } - return Status::OK(); -} - bool NamespaceString::isReplicated() const { if (isLocal()) { return false; diff --git a/src/mongo/db/namespace_string.h b/src/mongo/db/namespace_string.h index f94c51a3ac7..de41e5a5d1d 100644 --- a/src/mongo/db/namespace_string.h +++ b/src/mongo/db/namespace_string.h @@ -319,12 +319,6 @@ public: StatusWith<repl::OpTime> getDropPendingNamespaceOpTime() const; /** - * Checks if this namespace is valid as a target namespace for a rename operation, given - * the length of the longest index name in the source collection. - */ - Status checkLengthForRename(const std::string::size_type longestIndexNameLength) const; - - /** * Returns true if the namespace is valid. Special namespaces for internal use are considered as * valid. */ |