summaryrefslogtreecommitdiff
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
parent73252c4c0f184f1c81ffb478f66b6028ad7c72b9 (diff)
downloadmongo-efa6daec5a21e0ff396723a2f66ca5c1820d1fb5.tar.gz
SERVER-53867 Add/Remove timestamp to docs on config.chunks when upgrading/downgrading
-rw-r--r--jstests/multiVersion/upgrade_downgrade_sharded_cluster.js18
-rw-r--r--jstests/sharding/coll_timestamp_test.js25
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager.cpp50
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager.h38
4 files changed, 78 insertions, 53 deletions
diff --git a/jstests/multiVersion/upgrade_downgrade_sharded_cluster.js b/jstests/multiVersion/upgrade_downgrade_sharded_cluster.js
index cbfb381bb76..46323021e73 100644
--- a/jstests/multiVersion/upgrade_downgrade_sharded_cluster.js
+++ b/jstests/multiVersion/upgrade_downgrade_sharded_cluster.js
@@ -99,6 +99,10 @@ function testAllowedMigrationsFieldChecksAfterFCVDowngrade() {
function testTimestampFieldSetup() {
assert.commandWorked(
st.s.adminCommand({shardCollection: 'sharded.test3_created_before_upgrade', key: {x: 1}}));
+ assert.commandWorked(
+ st.s.adminCommand({split: 'sharded.test3_created_before_upgrade', middle: {x: 10}}));
+ assert.commandWorked(
+ st.s.adminCommand({split: 'sharded.test3_created_before_upgrade', middle: {x: -10}}));
}
function testTimestampFieldChecksAfterUpgrade() {
@@ -127,6 +131,13 @@ function testTimestampFieldChecksAfterUpgrade() {
// TODO: After SERVER-52587, check that the timestamp in the shardsvr config.cache.collection
// exists and matches collTimestampInConfigSvr
+
+ // Check that 'timestamp' has been created in config.chunks
+ var cursor = st.config.chunks.find({ns: 'sharded.test3_created_before_upgrade'});
+ assert(cursor.hasNext());
+ do {
+ assert.eq(collTimestampInConfigSvr, cursor.next().lastmodTimestamp);
+ } while (cursor.hasNext());
}
function testTimestampFieldSetupBeforeDowngrade() {
@@ -158,6 +169,13 @@ function testTimestampFieldChecksAfterFCVDowngrade() {
.timestamp;
assert.eq(null, timestampInShard);
+ // Check that the 'timestamp' has been removed from config.chunks
+ var cursor = st.config.chunks.find({ns: 'sharded.test3_created_before_upgrade'});
+ assert(cursor.hasNext());
+ do {
+ assert.eq(null, cursor.next().lastmodTimestamp);
+ } while (cursor.hasNext());
+
// TODO: After SERVER-52587, this is no longer needed as we can just check with
// test3_created_before_upgrade.
timestampInShard = primaryShard.getDB('config')
diff --git a/jstests/sharding/coll_timestamp_test.js b/jstests/sharding/coll_timestamp_test.js
index 7bf7914c1cb..7467fa81222 100644
--- a/jstests/sharding/coll_timestamp_test.js
+++ b/jstests/sharding/coll_timestamp_test.js
@@ -6,22 +6,23 @@
* The test can only run when the featureFlagShardingFullDDLSupportTimestampedVersion feature flag
* is enabled. Tagging as multiversion_incompatible until SERVER-52588 is done.
*
- * @tags: [requires_fcv_47, multiversion_incompatible,
- * featureFlagShardingFullDDLSupportTimestampedVersion]
+ * @tags: [multiversion_incompatible, featureFlagShardingFullDDLSupportTimestampedVersion]
*/
(function() {
'use strict';
-function checkConfigSvrAndShardCollectionTimestampConsistent(nss) {
- let csrs_config_db = st.configRS.getPrimary().getDB('config');
- coll = csrs_config_db.collections.findOne({_id: nss});
- let timestampInConfigSvr = coll.timestamp;
- assert.neq(null, timestampInConfigSvr);
+function checkTimestampConsistencyInPersistentMetadata(nss, timestampInConfig) {
+ // Checking consistency on local shard collection: config.cache.collections
let timestampInShard =
- st.shard0.getDB('config').cache.collections.findOne({_id: kNs}).timestamp;
+ st.shard0.getDB('config').cache.collections.findOne({_id: nss}).timestamp;
assert.neq(null, timestampInShard);
- assert.eq(timestampCmp(timestampInShard, timestampInConfigSvr), 0);
+ assert.eq(timestampCmp(timestampInConfig, timestampInShard), 0);
+
+ // Checking consistency on config server collection: config.chunks
+ var cursor = st.config.chunks.find({ns: nss});
+ assert(cursor.hasNext());
+ assert.eq(timestampInConfig, cursor.next().lastmodTimestamp);
}
const kDbName = 'testdb';
@@ -51,7 +52,7 @@ assert.commandWorked(st.s.adminCommand({shardCollection: kNs, key: {x: 1}}));
let coll = csrs_config_db.collections.findOne({_id: kNs});
assert.neq(null, coll.timestamp);
let timestampAfterCreate = coll.timestamp;
-checkConfigSvrAndShardCollectionTimestampConsistent(kNs);
+checkTimestampConsistencyInPersistentMetadata(kNs, timestampAfterCreate);
// Drop the collection and create it again. Collection timestamp should then be updated.
st.s.getDB(kDbName).coll.drop();
@@ -60,7 +61,7 @@ coll = csrs_config_db.collections.findOne({_id: kNs});
assert.neq(null, coll.timestamp);
let timestampAfterDropCreate = coll.timestamp;
assert.eq(timestampCmp(timestampAfterDropCreate, timestampAfterCreate), 1);
-checkConfigSvrAndShardCollectionTimestampConsistent(kNs);
+checkTimestampConsistencyInPersistentMetadata(kNs, timestampAfterDropCreate);
// Refine sharding key. Collection timestamp should then be updated.
assert.commandWorked(st.s.getCollection(kNs).createIndex({x: 1, y: 1}));
@@ -69,7 +70,7 @@ coll = csrs_config_db.collections.findOne({_id: kNs});
assert.neq(null, coll.timestamp);
let timestampAfterRefine = coll.timestamp;
assert.eq(timestampCmp(timestampAfterRefine, timestampAfterDropCreate), 1);
-checkConfigSvrAndShardCollectionTimestampConsistent(kNs);
+checkTimestampConsistencyInPersistentMetadata(kNs, timestampAfterRefine);
st.stop();
})();
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;