diff options
author | Blake Oler <blake.oler@mongodb.com> | 2019-04-09 18:08:53 -0400 |
---|---|---|
committer | Blake Oler <blake.oler@mongodb.com> | 2019-04-16 15:57:30 -0400 |
commit | 29ef1a415c74c883746325f13a8eaaa1831f8102 (patch) | |
tree | 13ce885258c58747b604a226215bdaca535361a5 /src/mongo/db | |
parent | e984f9781d2947e3b1fc10ae8535d630c49b5e94 (diff) | |
download | mongo-29ef1a415c74c883746325f13a8eaaa1831f8102.tar.gz |
SERVER-40346 Use AlternativeSessionRegion to insert config documents as retryable write
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/ops/write_ops_parsers.h | 6 | ||||
-rw-r--r-- | src/mongo/db/s/config/initial_split_policy.cpp | 11 | ||||
-rw-r--r-- | src/mongo/db/s/config/initial_split_policy.h | 10 | ||||
-rw-r--r-- | src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp | 13 | ||||
-rw-r--r-- | src/mongo/db/s/shardsvr_shard_collection.cpp | 18 |
5 files changed, 34 insertions, 24 deletions
diff --git a/src/mongo/db/ops/write_ops_parsers.h b/src/mongo/db/ops/write_ops_parsers.h index 77ccb46eded..f116b79b63e 100644 --- a/src/mongo/db/ops/write_ops_parsers.h +++ b/src/mongo/db/ops/write_ops_parsers.h @@ -40,7 +40,7 @@ namespace write_ops { // Conservative per array element overhead. This value was calculated as 1 byte (element type) + 5 // bytes (max string encoding of the array index encoded as string and the maximum key is 99999) + 1 // byte (zero terminator) = 7 bytes -constexpr int kBSONArrayPerElementOverheadBytes = 7; +constexpr int kWriteCommandBSONArrayPerElementOverheadBytes = 7; /** * Parses the 'limit' property of a delete entry, which has inverted meaning from the 'multi' @@ -90,10 +90,10 @@ public: int size = 0; std::for_each(_pipeline->begin(), _pipeline->end(), [&size](const BSONObj& obj) { - size += obj.objsize() + kBSONArrayPerElementOverheadBytes; + size += obj.objsize() + kWriteCommandBSONArrayPerElementOverheadBytes; }); - return size + kBSONArrayPerElementOverheadBytes; + return size + kWriteCommandBSONArrayPerElementOverheadBytes; } Type type() const { diff --git a/src/mongo/db/s/config/initial_split_policy.cpp b/src/mongo/db/s/config/initial_split_policy.cpp index 61baebf030f..bd8ec905907 100644 --- a/src/mongo/db/s/config/initial_split_policy.cpp +++ b/src/mongo/db/s/config/initial_split_policy.cpp @@ -382,17 +382,6 @@ InitialSplitPolicy::ShardCollectionConfig InitialSplitPolicy::createFirstChunks( return initialChunks; } -void InitialSplitPolicy::writeFirstChunksToConfig( - OperationContext* opCtx, const InitialSplitPolicy::ShardCollectionConfig& initialChunks) { - for (const auto& chunk : initialChunks.chunks) { - uassertStatusOK(Grid::get(opCtx)->catalogClient()->insertConfigDocument( - opCtx, - ChunkType::ConfigNS, - chunk.toConfigBSON(), - ShardingCatalogClient::kMajorityWriteConcern)); - } -} - boost::optional<CollectionType> InitialSplitPolicy::checkIfCollectionAlreadyShardedWithSameOptions( OperationContext* opCtx, const NamespaceString& nss, diff --git a/src/mongo/db/s/config/initial_split_policy.h b/src/mongo/db/s/config/initial_split_policy.h index ab44a85216c..feeb2ca2902 100644 --- a/src/mongo/db/s/config/initial_split_policy.h +++ b/src/mongo/db/s/config/initial_split_policy.h @@ -136,16 +136,10 @@ public: int numContiguousChunksPerShard = 1); /** - * Writes to the config server the first chunks for a newly sharded collection. - */ - static void writeFirstChunksToConfig( - OperationContext* opCtx, const InitialSplitPolicy::ShardCollectionConfig& initialChunks); - - /** * Throws an exception if the collection is already sharded with different options. * - * If the collection is already sharded with the same options, returns the existing collection's - * full spec, else returns boost::none. + * If the collection is already sharded with the same options, returns the existing + * collection's full spec, else returns boost::none. */ static boost::optional<CollectionType> checkIfCollectionAlreadyShardedWithSameOptions( OperationContext* opCtx, diff --git a/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp index ddc0b54f29a..b1220cee3fc 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp @@ -128,6 +128,17 @@ boost::optional<UUID> checkCollectionOptions(OperationContext* opCtx, return uassertStatusOK(UUID::parse(collectionInfo["uuid"])); } +void writeFirstChunksForShardCollection( + OperationContext* opCtx, const InitialSplitPolicy::ShardCollectionConfig& initialChunks) { + for (const auto& chunk : initialChunks.chunks) { + uassertStatusOK(Grid::get(opCtx)->catalogClient()->insertConfigDocument( + opCtx, + ChunkType::ConfigNS, + chunk.toConfigBSON(), + ShardingCatalogClient::kMajorityWriteConcern)); + } +} + } // namespace void checkForExistingChunks(OperationContext* opCtx, const NamespaceString& nss) { @@ -414,7 +425,7 @@ void ShardingCatalogManager::shardCollection(OperationContext* opCtx, treatAsNoZonesDefined, treatAsEmpty); - InitialSplitPolicy::writeFirstChunksToConfig(opCtx, initialChunks); + writeFirstChunksForShardCollection(opCtx, initialChunks); { CollectionType coll; diff --git a/src/mongo/db/s/shardsvr_shard_collection.cpp b/src/mongo/db/s/shardsvr_shard_collection.cpp index 48b48dc7532..f8d4877b58c 100644 --- a/src/mongo/db/s/shardsvr_shard_collection.cpp +++ b/src/mongo/db/s/shardsvr_shard_collection.cpp @@ -415,6 +415,22 @@ void checkForExistingChunks(OperationContext* opCtx, const NamespaceString& nss) numChunks == 0); } +void writeFirstChunksToConfig(OperationContext* opCtx, + const InitialSplitPolicy::ShardCollectionConfig& initialChunks) { + + std::vector<BSONObj> chunkObjs; + chunkObjs.reserve(initialChunks.chunks.size()); + for (const auto& chunk : initialChunks.chunks) { + chunkObjs.push_back(chunk.toConfigBSON()); + } + + Grid::get(opCtx)->catalogClient()->insertConfigDocumentsAsRetryableWrite( + opCtx, + ChunkType::ConfigNS, + std::move(chunkObjs), + ShardingCatalogClient::kMajorityWriteConcern); +} + void shardCollection(OperationContext* opCtx, const NamespaceString& nss, const boost::optional<UUID> uuid, @@ -522,7 +538,7 @@ void shardCollection(OperationContext* opCtx, } // Insert chunk documents to config.chunks on the config server. - InitialSplitPolicy::writeFirstChunksToConfig(opCtx, initialChunks); + writeFirstChunksToConfig(opCtx, initialChunks); { CollectionType coll; |