diff options
author | Pierlauro Sciarelli <pierlauro.sciarelli@mongodb.com> | 2021-01-27 11:17:38 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-01-27 18:06:22 +0000 |
commit | 699c25860f4811d661a32ffab56f17b4797cd16e (patch) | |
tree | d0105497a46d3cfaa6f2f9f9c03eb404245bfcfa /src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp | |
parent | 1cbf4fff902fbc1f62563877ce0bb02bcadfa68d (diff) | |
download | mongo-699c25860f4811d661a32ffab56f17b4797cd16e.tar.gz |
SERVER-54071 Deduplicate `BatchedCommandRequest build*Op` methods in the codebase
Diffstat (limited to 'src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp')
-rw-r--r-- | src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp | 69 |
1 files changed, 15 insertions, 54 deletions
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 5959c4c8788..4409a112d74 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 @@ -139,48 +139,6 @@ boost::optional<UUID> checkCollectionOptions(OperationContext* opCtx, return uassertStatusOK(UUID::parse(collectionInfo["uuid"])); } -BatchedCommandRequest buildUpdateOp(const NamespaceString& nss, - const BSONObj& query, - const BSONObj& update, - bool upsert, - bool multi) { - BatchedCommandRequest request([&] { - write_ops::Update updateOp(nss); - updateOp.setUpdates({[&] { - write_ops::UpdateOpEntry entry; - entry.setQ(query); - entry.setU(write_ops::UpdateModification::parseFromClassicUpdate(update)); - entry.setUpsert(upsert); - entry.setMulti(multi); - return entry; - }()}); - return updateOp; - }()); - - return request; -} - -BatchedCommandRequest buildPipelineUpdateOp(const NamespaceString& nss, - const BSONObj& query, - const std::vector<BSONObj>& updates, - bool upsert, - bool useMultiUpdate) { - BatchedCommandRequest request([&] { - write_ops::Update updateOp(nss); - updateOp.setUpdates({[&] { - write_ops::UpdateOpEntry entry; - entry.setQ(query); - entry.setU(write_ops::UpdateModification(updates)); - entry.setUpsert(upsert); - entry.setMulti(useMultiUpdate); - return entry; - }()}); - return updateOp; - }()); - - return request; -} - void triggerFireAndForgetShardRefreshes(OperationContext* opCtx, const NamespaceString& nss) { const auto shardRegistry = Grid::get(opCtx)->shardRegistry(); const auto allShards = uassertStatusOK(Grid::get(opCtx)->catalogClient()->getAllShards( @@ -591,15 +549,16 @@ void ShardingCatalogManager::refineCollectionShardKey(OperationContext* opCtx, // to the newly-generated objectid, (ii) their bounds for each new field in the refined // key to MinKey (except for the global max chunk where the max bounds are set to // MaxKey), and unsetting (iii) their jumbo field. - writeToConfigDocumentInTxn(opCtx, - ChunkType::ConfigNS, - buildPipelineUpdateOp(ChunkType::ConfigNS, + writeToConfigDocumentInTxn( + opCtx, + ChunkType::ConfigNS, + BatchedCommandRequest::buildPipelineUpdateOp(ChunkType::ConfigNS, BSON("ns" << nss.ns()), chunkUpdates, false, // upsert true // useMultiUpdate ), - txnNumber); + txnNumber); LOGV2(21935, "refineCollectionShardKey: updated chunk entries for {namespace}: took " @@ -613,15 +572,16 @@ void ShardingCatalogManager::refineCollectionShardKey(OperationContext* opCtx, // Update all config.tags entries for the given namespace by setting their bounds for // each new field in the refined key to MinKey (except for the global max tag where the // max bounds are set to MaxKey). - writeToConfigDocumentInTxn(opCtx, - TagsType::ConfigNS, - buildPipelineUpdateOp(TagsType::ConfigNS, + writeToConfigDocumentInTxn( + opCtx, + TagsType::ConfigNS, + BatchedCommandRequest::buildPipelineUpdateOp(TagsType::ConfigNS, BSON("ns" << nss.ns()), tagUpdates, false, // upsert true // useMultiUpdate ), - txnNumber); + txnNumber); LOGV2(21936, @@ -668,15 +628,16 @@ void ShardingCatalogManager::updateShardingCatalogEntryForCollectionInTxn( const bool upsert, TxnNumber txnNumber) { try { - writeToConfigDocumentInTxn(opCtx, - CollectionType::ConfigNS, - buildUpdateOp(CollectionType::ConfigNS, + writeToConfigDocumentInTxn( + opCtx, + CollectionType::ConfigNS, + BatchedCommandRequest::buildUpdateOp(CollectionType::ConfigNS, BSON(CollectionType::kNssFieldName << nss.ns()), coll.toBSON(), upsert, false /* multi */ ), - txnNumber); + txnNumber); } catch (DBException& e) { e.addContext("Collection metadata write failed"); throw; |