summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/config
diff options
context:
space:
mode:
authorSergi Mateo Bellido <sergi.mateo-bellido@mongodb.com>2021-01-20 13:31:30 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-01-21 13:56:22 +0000
commitefa6daec5a21e0ff396723a2f66ca5c1820d1fb5 (patch)
treef81e5c058e3845c873954922cddcee454b51619d /src/mongo/db/s/config
parent73252c4c0f184f1c81ffb478f66b6028ad7c72b9 (diff)
downloadmongo-efa6daec5a21e0ff396723a2f66ca5c1820d1fb5.tar.gz
SERVER-53867 Add/Remove timestamp to docs on config.chunks when upgrading/downgrading
Diffstat (limited to 'src/mongo/db/s/config')
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager.cpp50
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager.h38
2 files changed, 47 insertions, 41 deletions
diff --git a/src/mongo/db/s/config/sharding_catalog_manager.cpp b/src/mongo/db/s/config/sharding_catalog_manager.cpp
index a39995903b3..9bdb508247e 100644
--- a/src/mongo/db/s/config/sharding_catalog_manager.cpp
+++ b/src/mongo/db/s/config/sharding_catalog_manager.cpp
@@ -651,8 +651,10 @@ void ShardingCatalogManager::_upgradeCollectionsAndChunksMetadataFor49(Operation
const auto nss = coll.getNss();
auto updateCollectionAndChunksFn = [&](OperationContext* opCtx, TxnNumber txnNumber) {
- _createChunkCollUuidFor49InTxn(opCtx, nss, uuid, txnNumber);
- _createCollectionTimestampFor49InTxn(opCtx, nss, txnNumber);
+ const auto now = VectorClock::get(opCtx)->getTime();
+ const auto newTimestamp = now.clusterTime().asTimestamp();
+ _addTimestampAndUUIDToConfigChunksFor49InTxn(opCtx, nss, uuid, txnNumber, newTimestamp);
+ _addTimestampToConfigCollectionsFor49InTxn(opCtx, nss, txnNumber, newTimestamp);
};
withTransaction(opCtx, nss, updateCollectionAndChunksFn);
@@ -689,8 +691,8 @@ void ShardingCatalogManager::_downgradeCollectionsAndChunksMetadataToPre49(
const auto nss = coll.getNss();
auto updateCollectionAndChunksFn = [&](OperationContext* opCtx, TxnNumber txnNumber) {
- _deleteConfigCollectionsTimestampInTxn(opCtx, nss, txnNumber);
- _deleteChunkCollUuidInTxn(opCtx, nss, txnNumber);
+ _deleteTimestampFromConfigCollectionsInTxn(opCtx, nss, txnNumber);
+ _deleteTimestampAndUUIDFromConfigChunksInTxn(opCtx, nss, txnNumber);
};
withTransaction(opCtx, nss, updateCollectionAndChunksFn);
@@ -700,19 +702,18 @@ void ShardingCatalogManager::_downgradeCollectionsAndChunksMetadataToPre49(
LOGV2(5276703, "Successfully downgraded config.collections and config.chunks");
}
-void ShardingCatalogManager::_createCollectionTimestampFor49InTxn(OperationContext* opCtx,
- const NamespaceString& nss,
- TxnNumber txnNumber) {
- auto now = VectorClock::get(opCtx)->getTime();
- auto clusterTime = now.clusterTime().asTimestamp();
-
+void ShardingCatalogManager::_addTimestampToConfigCollectionsFor49InTxn(
+ OperationContext* opCtx,
+ const NamespaceString& nss,
+ TxnNumber txnNumber,
+ const Timestamp& newTimestamp) {
try {
writeToConfigDocumentInTxn(
opCtx,
CollectionType::ConfigNS,
buildUpdateOp(CollectionType::ConfigNS,
BSON(CollectionType::kNssFieldName << nss.ns()),
- BSON("$set" << BSON(CollectionType::kTimestampFieldName << clusterTime)),
+ BSON("$set" << BSON(CollectionType::kTimestampFieldName << newTimestamp)),
false, /* upsert */
false /* multi */
),
@@ -724,9 +725,9 @@ void ShardingCatalogManager::_createCollectionTimestampFor49InTxn(OperationConte
}
}
-void ShardingCatalogManager::_deleteConfigCollectionsTimestampInTxn(OperationContext* opCtx,
- const NamespaceString& nss,
- TxnNumber txnNumber) {
+void ShardingCatalogManager::_deleteTimestampFromConfigCollectionsInTxn(OperationContext* opCtx,
+ const NamespaceString& nss,
+ TxnNumber txnNumber) {
try {
writeToConfigDocumentInTxn(
opCtx,
@@ -745,10 +746,12 @@ void ShardingCatalogManager::_deleteConfigCollectionsTimestampInTxn(OperationCon
}
}
-void ShardingCatalogManager::_createChunkCollUuidFor49InTxn(OperationContext* opCtx,
- const NamespaceString& nss,
- const mongo::UUID& collectionUuid,
- TxnNumber txnNumber) {
+void ShardingCatalogManager::_addTimestampAndUUIDToConfigChunksFor49InTxn(
+ OperationContext* opCtx,
+ const NamespaceString& nss,
+ const mongo::UUID& collectionUuid,
+ TxnNumber txnNumber,
+ const Timestamp& newTimestamp) {
try {
writeToConfigDocumentInTxn(
opCtx,
@@ -756,7 +759,8 @@ void ShardingCatalogManager::_createChunkCollUuidFor49InTxn(OperationContext* op
buildUpdateOp(
ChunkType::ConfigNS,
BSON(ChunkType::ns(nss.ns())),
- BSON("$set" << BSON(ChunkType::collectionUUID(collectionUuid.toString()))),
+ BSON("$set" << BSON(ChunkType::timestamp(newTimestamp)
+ << ChunkType::collectionUUID(collectionUuid.toString()))),
false, /* upsert */
true /* multi */
),
@@ -768,16 +772,16 @@ void ShardingCatalogManager::_createChunkCollUuidFor49InTxn(OperationContext* op
}
}
-void ShardingCatalogManager::_deleteChunkCollUuidInTxn(OperationContext* opCtx,
- const NamespaceString& nss,
- TxnNumber txnNumber) {
+void ShardingCatalogManager::_deleteTimestampAndUUIDFromConfigChunksInTxn(
+ OperationContext* opCtx, const NamespaceString& nss, TxnNumber txnNumber) {
try {
writeToConfigDocumentInTxn(
opCtx,
ChunkType::ConfigNS,
buildUpdateOp(ChunkType::ConfigNS,
BSON(ChunkType::ns(nss.ns())),
- BSON("$unset" << BSON(ChunkType::collectionUUID(""))),
+ BSON("$unset" << BSON(ChunkType::timestamp.name()
+ << "" << ChunkType::collectionUUID(""))),
false, /* upsert */
true /* multi */
),
diff --git a/src/mongo/db/s/config/sharding_catalog_manager.h b/src/mongo/db/s/config/sharding_catalog_manager.h
index e9f0a69269a..85e6b6f9158 100644
--- a/src/mongo/db/s/config/sharding_catalog_manager.h
+++ b/src/mongo/db/s/config/sharding_catalog_manager.h
@@ -618,44 +618,46 @@ private:
void _downgradeCollectionsAndChunksMetadataToPre49(OperationContext* opCtx);
/**
- * Creates a 'timestamp' field for the entry matching nss in config.collections, in a
+ * Sets the 'timestamp' field for the entry matching nss in config.collections, in a
* transaction.
*
* TODO SERVER-53283: Remove once 5.0 has been released.
*/
- void _createCollectionTimestampFor49InTxn(OperationContext* opCtx,
- const NamespaceString& nss,
- TxnNumber txnNumber);
+ void _addTimestampToConfigCollectionsFor49InTxn(OperationContext* opCtx,
+ const NamespaceString& nss,
+ TxnNumber txnNumber,
+ const Timestamp& newTimestamp);
/**
* Deletes the 'timestamp' from the entry in config.collections matching nss, in a transaction.
*
* TODO SERVER-53283: Remove once 5.0 has been released.
*/
- void _deleteConfigCollectionsTimestampInTxn(OperationContext* opCtx,
- const NamespaceString& nss,
- TxnNumber txnNumber);
+ void _deleteTimestampFromConfigCollectionsInTxn(OperationContext* opCtx,
+ const NamespaceString& nss,
+ TxnNumber txnNumber);
/**
- * Sets the 'collectionUuid' field for the entries matching nss in config.chunks, in a
- * transaction.
+ * Sets the 'timestamp' and the 'collectionUuid' fields for the entries matching nss in
+ * config.chunks, in a transaction.
*
* TODO SERVER-53283: Remove once 5.0 has been released.
*/
- void _createChunkCollUuidFor49InTxn(OperationContext* opCtx,
- const NamespaceString& nss,
- const mongo::UUID& collectionUuid,
- TxnNumber txnNumber);
+ void _addTimestampAndUUIDToConfigChunksFor49InTxn(OperationContext* opCtx,
+ const NamespaceString& nss,
+ const mongo::UUID& collectionUuid,
+ TxnNumber txnNumber,
+ const Timestamp& newTimestamp);
/**
- * Deletes the 'collectionUuid' field for the entries matching nss in config.chunks, in a
- * transaction.
+ * Deletes the 'timestamp' and 'collectionUuid' field for the entries matching nss in
+ * config.chunks, in a transaction.
*
* TODO SERVER-53283: Remove once 5.0 has been released.
*/
- void _deleteChunkCollUuidInTxn(OperationContext* opCtx,
- const NamespaceString& nss,
- TxnNumber txnNumber);
+ void _deleteTimestampAndUUIDFromConfigChunksInTxn(OperationContext* opCtx,
+ const NamespaceString& nss,
+ TxnNumber txnNumber);
// The owning service context
ServiceContext* const _serviceContext;