@@ -488,17 +488,11 @@ void insertChunkAndTagDocsForTempNss(OperationContext* opCtx,
488
488
489
489
void removeChunkAndTagsDocs (OperationContext* opCtx,
490
490
const NamespaceString& ns,
491
- const boost::optional< UUID> & collUUID,
491
+ const UUID& collUUID,
492
492
TxnNumber txnNumber) {
493
493
// Remove all chunk documents for the original nss. We do not know how many chunk docs currently
494
494
// exist, so cannot pass a value for expectedNumModified
495
- const auto chunksQuery = [&]() {
496
- if (collUUID) {
497
- return BSON (ChunkType::collectionUUID () << *collUUID);
498
- } else {
499
- return BSON (ChunkType::ns (ns.ns ()));
500
- }
501
- }();
495
+ const auto chunksQuery = BSON (ChunkType::collectionUUID () << collUUID);
502
496
503
497
ShardingCatalogManager::get (opCtx)->writeToConfigDocumentInTxn (
504
498
opCtx,
@@ -535,35 +529,16 @@ void removeConfigMetadataForTempNss(OperationContext* opCtx,
535
529
(void )ShardingCatalogManager::get (opCtx)->writeToConfigDocumentInTxn (
536
530
opCtx, CollectionType::ConfigNS, delCollEntryRequest, txnNumber);
537
531
538
- const auto reshardingTempUUID = coordinatorDoc. getReshardingUUID ();
539
-
540
- removeChunkAndTagsDocs (
541
- opCtx, coordinatorDoc. getTempReshardingNss (), reshardingTempUUID, txnNumber);
532
+ removeChunkAndTagsDocs (opCtx,
533
+ coordinatorDoc. getTempReshardingNss (),
534
+ coordinatorDoc. getReshardingUUID (),
535
+ txnNumber);
542
536
}
543
537
544
538
void updateChunkAndTagsDocsForTempNss (OperationContext* opCtx,
545
539
const ReshardingCoordinatorDocument& coordinatorDoc,
546
540
OID newCollectionEpoch,
547
- boost::optional<Timestamp> newCollectionTimestamp,
548
541
TxnNumber txnNumber) {
549
- // If the collection entry has a timestamp, this means the metadata has been upgraded to the 5.0
550
- // format in which case chunks are indexed by UUID and do not contain Epochs. Therefore, only
551
- // the update to config.collections is sufficient.
552
- if (!newCollectionTimestamp) {
553
- auto chunksRequest = BatchedCommandRequest::buildUpdateOp (
554
- ChunkType::ConfigNS,
555
- BSON (ChunkType::ns (coordinatorDoc.getTempReshardingNss ().ns ())), // query
556
- BSON (" $set" << BSON (ChunkType::ns << coordinatorDoc.getSourceNss ().ns ()
557
- << ChunkType::epoch
558
- << newCollectionEpoch)), // update
559
- false , // upsert
560
- true // multi
561
- );
562
-
563
- auto chunksRes = ShardingCatalogManager::get (opCtx)->writeToConfigDocumentInTxn (
564
- opCtx, ChunkType::ConfigNS, chunksRequest, txnNumber);
565
- }
566
-
567
542
auto hint = BSON (" ns" << 1 << " min" << 1 );
568
543
auto tagsRequest = BatchedCommandRequest::buildUpdateOp (
569
544
TagsType::ConfigNS,
@@ -630,7 +605,7 @@ CollectionType createTempReshardingCollectionType(
630
605
void writeDecisionPersistedState (OperationContext* opCtx,
631
606
const ReshardingCoordinatorDocument& coordinatorDoc,
632
607
OID newCollectionEpoch,
633
- boost::optional< Timestamp> newCollectionTimestamp) {
608
+ Timestamp newCollectionTimestamp) {
634
609
// No need to bump originalNss version because its epoch will be changed.
635
610
executeMetadataChangesInTxn (opCtx, [&](OperationContext* opCtx, TxnNumber txnNumber) {
636
611
// Update the config.reshardingOperations entry
@@ -648,15 +623,9 @@ void writeDecisionPersistedState(OperationContext* opCtx,
648
623
// Remove all chunk and tag documents associated with the original collection, then
649
624
// update the chunk and tag docs currently associated with the temp nss to be associated
650
625
// with the original nss
651
-
652
- boost::optional<UUID> collUUID;
653
- if (newCollectionTimestamp) {
654
- collUUID = coordinatorDoc.getSourceUUID ();
655
- }
656
-
657
- removeChunkAndTagsDocs (opCtx, coordinatorDoc.getSourceNss (), collUUID, txnNumber);
658
- updateChunkAndTagsDocsForTempNss (
659
- opCtx, coordinatorDoc, newCollectionEpoch, newCollectionTimestamp, txnNumber);
626
+ removeChunkAndTagsDocs (
627
+ opCtx, coordinatorDoc.getSourceNss (), coordinatorDoc.getSourceUUID (), txnNumber);
628
+ updateChunkAndTagsDocsForTempNss (opCtx, coordinatorDoc, newCollectionEpoch, txnNumber);
660
629
});
661
630
}
662
631
@@ -1671,11 +1640,15 @@ Future<void> ReshardingCoordinatorService::ReshardingCoordinator::_commit(
1671
1640
// The new epoch and timestamp to use for the resharded collection to indicate that the
1672
1641
// collection is a new incarnation of the namespace
1673
1642
auto newCollectionEpoch = OID::gen ();
1674
- auto now = VectorClock::get (opCtx.get ())->getTime ();
1675
- const auto newCollectionTimestamp = now.clusterTime ().asTimestamp ();
1643
+ auto newCollectionTimestamp = [&] {
1644
+ const auto now = VectorClock::get (opCtx.get ())->getTime ();
1645
+ return now.clusterTime ().asTimestamp ();
1646
+ }();
1676
1647
1677
- resharding::writeDecisionPersistedState (
1678
- opCtx.get (), updatedCoordinatorDoc, newCollectionEpoch, newCollectionTimestamp);
1648
+ resharding::writeDecisionPersistedState (opCtx.get (),
1649
+ updatedCoordinatorDoc,
1650
+ std::move (newCollectionEpoch),
1651
+ std::move (newCollectionTimestamp));
1679
1652
1680
1653
// Update the in memory state
1681
1654
installCoordinatorDoc (opCtx.get (), updatedCoordinatorDoc);
0 commit comments