1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/**
* This test checks that the timestamp in config server's config.collections and in shards
* config.cache.collections are updated when sharding a collection, dropping and creating a
* collection, or refining the sharding key.
*
* The test can only run when the featureFlagShardingFullDDLSupportTimestampedVersion feature flag
* is enabled. Tagging as multiversion_incompatible until SERVER-52588 is done.
*
* @tags: [multiversion_incompatible, featureFlagShardingFullDDLSupportTimestampedVersion]
*/
(function() {
'use strict';
load("jstests/sharding/libs/find_chunks_util.js");
function checkTimestampConsistencyInPersistentMetadata(nss, timestampInConfig) {
// Checking consistency on local shard collection: config.cache.collections
st.shard0.adminCommand({_flushRoutingTableCacheUpdates: nss, syncFromConfig: true});
let timestampInShard =
st.shard0.getDB('config').cache.collections.findOne({_id: nss}).timestamp;
assert.neq(null, timestampInShard);
assert.eq(timestampCmp(timestampInConfig, timestampInShard), 0);
// Checking consistency on config server collection: config.chunks
var cursor = findChunksUtil.findChunksByNs(st.config, nss);
assert(cursor.hasNext());
assert.eq(timestampInConfig, cursor.next().lastmodTimestamp);
}
const kDbName = 'testdb';
const kCollName = 'coll';
const kNs = kDbName + '.' + kCollName;
var st = new ShardingTest({shards: 1, mongos: 1});
const featureFlagParam = assert.commandWorked(st.configRS.getPrimary().adminCommand(
{getParameter: 1, featureFlagShardingFullDDLSupportTimestampedVersion: 1}));
if (!featureFlagParam.featureFlagShardingFullDDLSupportTimestampedVersion.value) {
jsTest.log(
'Skipping test because featureFlagShardingFullDDLSupportTimestampedVersion feature flag is not enabled');
st.stop();
return;
}
let csrs_config_db = st.configRS.getPrimary().getDB('config');
assert.commandWorked(st.s.adminCommand({enableSharding: kDbName}));
// Create a sharded collection
assert.commandWorked(st.s.adminCommand({shardCollection: kNs, key: {x: 1}}));
// Check that timestamp is created in ConfigSvr and propagated to the shards.
let coll = csrs_config_db.collections.findOne({_id: kNs});
assert.neq(null, coll.timestamp);
let timestampAfterCreate = coll.timestamp;
checkTimestampConsistencyInPersistentMetadata(kNs, timestampAfterCreate);
// Drop the collection and create it again. Collection timestamp should then be updated.
st.s.getDB(kDbName).coll.drop();
assert.commandWorked(st.s.adminCommand({shardCollection: kNs, key: {x: 1}}));
coll = csrs_config_db.collections.findOne({_id: kNs});
assert.neq(null, coll.timestamp);
let timestampAfterDropCreate = coll.timestamp;
assert.eq(timestampCmp(timestampAfterDropCreate, timestampAfterCreate), 1);
checkTimestampConsistencyInPersistentMetadata(kNs, timestampAfterDropCreate);
// Refine sharding key. Collection timestamp should then be updated.
assert.commandWorked(st.s.getCollection(kNs).createIndex({x: 1, y: 1}));
assert.commandWorked(st.s.adminCommand({refineCollectionShardKey: kNs, key: {x: 1, y: 1}}));
coll = csrs_config_db.collections.findOne({_id: kNs});
assert.neq(null, coll.timestamp);
let timestampAfterRefine = coll.timestamp;
assert.eq(timestampCmp(timestampAfterRefine, timestampAfterDropCreate), 1);
checkTimestampConsistencyInPersistentMetadata(kNs, timestampAfterRefine);
st.stop();
})();
|