diff options
| author | Marcos José Grillo Ramirez <marcos.grillo@mongodb.com> | 2021-03-26 12:51:17 +0100 |
|---|---|---|
| committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-03-29 13:39:19 +0000 |
| commit | 057657f0613e2fec34ac2e00b8d943ac05058896 (patch) | |
| tree | eece2b32e37661948035de4f5aefe59d44c8b083 /src/mongo/db/s/shard_key_util.cpp | |
| parent | 83fdf9063cfd3a69aa1c3dc2b9566142dc51d634 (diff) | |
| download | mongo-057657f0613e2fec34ac2e00b8d943ac05058896.tar.gz | |
SERVER-54587 Added resilience to the new create collection path
Diffstat (limited to 'src/mongo/db/s/shard_key_util.cpp')
| -rw-r--r-- | src/mongo/db/s/shard_key_util.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/mongo/db/s/shard_key_util.cpp b/src/mongo/db/s/shard_key_util.cpp index cb11f76831a..018164565ba 100644 --- a/src/mongo/db/s/shard_key_util.cpp +++ b/src/mongo/db/s/shard_key_util.cpp @@ -100,12 +100,12 @@ BSONObj makeCreateIndexesCmd(const NamespaceString& nss, } // namespace -void validateShardKeyIndexExistsOrCreateIfPossible(OperationContext* opCtx, - const NamespaceString& nss, - const ShardKeyPattern& shardKeyPattern, - const boost::optional<BSONObj>& defaultCollation, - bool unique, - const ShardKeyValidationBehaviors& behaviors) { +bool validShardKeyIndexExists(OperationContext* opCtx, + const NamespaceString& nss, + const ShardKeyPattern& shardKeyPattern, + const boost::optional<BSONObj>& defaultCollation, + bool unique, + const ShardKeyValidationBehaviors& behaviors) { auto indexes = behaviors.loadIndexes(nss); // 1. Verify consistency with existing unique indexes @@ -174,9 +174,23 @@ void validateShardKeyIndexExistsOrCreateIfPossible(OperationContext* opCtx, if (hasUsefulIndexForKey) { // Check 2.iii Make sure that there is a useful, non-multikey index available. behaviors.verifyUsefulNonMultiKeyIndex(nss, shardKeyPattern.toBSON()); + } + + return hasUsefulIndexForKey; +} + +void validateShardKeyIndexExistsOrCreateIfPossible(OperationContext* opCtx, + const NamespaceString& nss, + const ShardKeyPattern& shardKeyPattern, + const boost::optional<BSONObj>& defaultCollation, + bool unique, + const ShardKeyValidationBehaviors& behaviors) { + if (validShardKeyIndexExists( + opCtx, nss, shardKeyPattern, defaultCollation, unique, behaviors)) { return; } + // 4. If no useful index, verify we can create one. behaviors.verifyCanCreateShardKeyIndex(nss); |
