Skip to content

Commit f4fc6da

Browse files
toto-devEvergreen Agent
authored andcommitted
SERVER-58990 Resharding always write new collection timestamp
1 parent 5a3762d commit f4fc6da

File tree

3 files changed

+26
-56
lines changed

3 files changed

+26
-56
lines changed

src/mongo/db/s/resharding/resharding_coordinator_service.cpp

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -488,17 +488,11 @@ void insertChunkAndTagDocsForTempNss(OperationContext* opCtx,
488488

489489
void removeChunkAndTagsDocs(OperationContext* opCtx,
490490
const NamespaceString& ns,
491-
const boost::optional<UUID>& collUUID,
491+
const UUID& collUUID,
492492
TxnNumber txnNumber) {
493493
// Remove all chunk documents for the original nss. We do not know how many chunk docs currently
494494
// 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);
502496

503497
ShardingCatalogManager::get(opCtx)->writeToConfigDocumentInTxn(
504498
opCtx,
@@ -535,35 +529,16 @@ void removeConfigMetadataForTempNss(OperationContext* opCtx,
535529
(void)ShardingCatalogManager::get(opCtx)->writeToConfigDocumentInTxn(
536530
opCtx, CollectionType::ConfigNS, delCollEntryRequest, txnNumber);
537531

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);
542536
}
543537

544538
void updateChunkAndTagsDocsForTempNss(OperationContext* opCtx,
545539
const ReshardingCoordinatorDocument& coordinatorDoc,
546540
OID newCollectionEpoch,
547-
boost::optional<Timestamp> newCollectionTimestamp,
548541
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-
567542
auto hint = BSON("ns" << 1 << "min" << 1);
568543
auto tagsRequest = BatchedCommandRequest::buildUpdateOp(
569544
TagsType::ConfigNS,
@@ -630,7 +605,7 @@ CollectionType createTempReshardingCollectionType(
630605
void writeDecisionPersistedState(OperationContext* opCtx,
631606
const ReshardingCoordinatorDocument& coordinatorDoc,
632607
OID newCollectionEpoch,
633-
boost::optional<Timestamp> newCollectionTimestamp) {
608+
Timestamp newCollectionTimestamp) {
634609
// No need to bump originalNss version because its epoch will be changed.
635610
executeMetadataChangesInTxn(opCtx, [&](OperationContext* opCtx, TxnNumber txnNumber) {
636611
// Update the config.reshardingOperations entry
@@ -648,15 +623,9 @@ void writeDecisionPersistedState(OperationContext* opCtx,
648623
// Remove all chunk and tag documents associated with the original collection, then
649624
// update the chunk and tag docs currently associated with the temp nss to be associated
650625
// 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);
660629
});
661630
}
662631

@@ -1671,11 +1640,15 @@ Future<void> ReshardingCoordinatorService::ReshardingCoordinator::_commit(
16711640
// The new epoch and timestamp to use for the resharded collection to indicate that the
16721641
// collection is a new incarnation of the namespace
16731642
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+
}();
16761647

1677-
resharding::writeDecisionPersistedState(
1678-
opCtx.get(), updatedCoordinatorDoc, newCollectionEpoch, newCollectionTimestamp);
1648+
resharding::writeDecisionPersistedState(opCtx.get(),
1649+
updatedCoordinatorDoc,
1650+
std::move(newCollectionEpoch),
1651+
std::move(newCollectionTimestamp));
16791652

16801653
// Update the in memory state
16811654
installCoordinatorDoc(opCtx.get(), updatedCoordinatorDoc);

src/mongo/db/s/resharding/resharding_coordinator_service.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ CollectionType createTempReshardingCollectionType(
5252
void writeDecisionPersistedState(OperationContext* opCtx,
5353
const ReshardingCoordinatorDocument& coordinatorDoc,
5454
OID newCollectionEpoch,
55-
boost::optional<Timestamp> newCollectionTimestamp);
55+
Timestamp newCollectionTimestamp);
5656

5757
void insertCoordDocAndChangeOrigCollEntry(OperationContext* opCtx,
5858
const ReshardingCoordinatorDocument& coordinatorDoc);

src/mongo/db/s/resharding/resharding_coordinator_test.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,11 @@ class ReshardingCoordinatorPersistenceTest : public ConfigServerTestFixture {
418418
ASSERT(!onDiskReshardingFields.getDonorFields());
419419
}
420420

421-
void readChunkCatalogEntriesAndAssertMatchExpected(
422-
OperationContext* opCtx,
423-
const UUID& uuid,
424-
std::vector<ChunkType> expectedChunks,
425-
const OID& collEpoch,
426-
const boost::optional<Timestamp>& collTimestamp) {
421+
void readChunkCatalogEntriesAndAssertMatchExpected(OperationContext* opCtx,
422+
const UUID& uuid,
423+
std::vector<ChunkType> expectedChunks,
424+
const OID& collEpoch,
425+
const Timestamp& collTimestamp) {
427426
DBDirectClient client(opCtx);
428427
std::vector<ChunkType> foundChunks;
429428
auto cursor = client.query(ChunkType::ConfigNS, Query(BSON("uuid" << uuid)));
@@ -686,16 +685,14 @@ class ReshardingCoordinatorPersistenceTest : public ConfigServerTestFixture {
686685
NamespaceString _originalNss = NamespaceString("db.foo");
687686
UUID _originalUUID = UUID::gen();
688687
OID _originalEpoch = OID::gen();
689-
// TODO: SERVER-58990 Initialize it with a Timestamp.
690-
boost::optional<Timestamp> _originalTimestamp;
688+
Timestamp _originalTimestamp{3};
691689

692690
NamespaceString _tempNss = NamespaceString("db.system.resharding." + _originalUUID.toString());
693691
UUID _reshardingUUID = UUID::gen();
694692
OID _tempEpoch = OID::gen();
695693

696694
OID _finalEpoch = OID::gen();
697-
boost::optional<Timestamp>
698-
_finalTimestamp; // TODO: SERVER-58990 Initialize it with a Timestamp.
695+
Timestamp _finalTimestamp{6};
699696

700697
ShardKeyPattern _oldShardKey = ShardKeyPattern(BSON("oldSK" << 1));
701698
ShardKeyPattern _newShardKey = ShardKeyPattern(BSON("newSK" << 1));

0 commit comments

Comments
 (0)