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
81
82
83
84
85
86
87
88
89
90
91
92
|
/**
* Test that the shard merge is resilient to WriteConflict exception thrown while importing
* collections. We will get WriteConflict exception if we try to import the files with timestamp
* older than the stable timestamp.
*
* @tags: [
* does_not_support_encrypted_storage_engine,
* featureFlagShardMerge,
* incompatible_with_macos,
* incompatible_with_windows_tls,
* requires_fcv_52,
* requires_journaling,
* requires_replication,
* requires_persistence,
* requires_wiredtiger,
* serverless,
* ]
*/
(function() {
"use strict";
load("jstests/libs/uuid_util.js");
load("jstests/replsets/libs/tenant_migration_test.js");
load("jstests/libs/fail_point_util.js");
const migrationId = UUID();
const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()});
const donorPrimary = tenantMigrationTest.getDonorPrimary();
const recipientPrimary = tenantMigrationTest.getRecipientPrimary();
if (!TenantMigrationUtil.isShardMergeEnabled(recipientPrimary.getDB("admin"))) {
tenantMigrationTest.stop();
jsTestLog("Skipping Shard Merge-specific test");
return;
}
const kDataDir =
`${recipientPrimary.dbpath}/migrationTmpFiles.${extractUUIDFromObject(migrationId)}`;
assert.eq(runNonMongoProgram("mkdir", "-p", kDataDir), 0);
const dbName = "myDatabase";
(function() {
jsTestLog("Generate test data");
const db = donorPrimary.getDB(dbName);
const collection = db["myCollection"];
const capped = db["myCappedCollection"];
assert.commandWorked(db.createCollection("myCappedCollection", {capped: true, size: 100}));
for (let c of [collection, capped]) {
c.insertMany([{_id: 0}, {_id: 1}, {_id: 2}], {writeConcern: {w: "majority"}});
}
assert.commandWorked(db.runCommand({
createIndexes: "myCollection",
indexes: [{key: {a: 1}, name: "a_1"}],
writeConcern: {w: "majority"}
}));
})();
// Enable Failpoints to simulate WriteConflict exception while importing donor files.
configureFailPoint(
recipientPrimary, "WTWriteConflictExceptionForImportCollection", {} /* data */, {times: 1});
configureFailPoint(
recipientPrimary, "WTWriteConflictExceptionForImportIndex", {} /* data */, {times: 1});
jsTestLog("Run migration");
// The old multitenant migrations won't copy myDatabase since it doesn't start with testTenantId,
// but shard merge copies everything so we still expect myDatabase on the recipient, below.
const kTenantId = "testTenantId";
const migrationOpts = {
migrationIdString: extractUUIDFromObject(migrationId),
tenantId: kTenantId,
};
TenantMigrationTest.assertCommitted(
tenantMigrationTest.runMigration(migrationOpts, {enableDonorStartMigrationFsync: true}));
tenantMigrationTest.getRecipientRst().nodes.forEach(node => {
for (let collectionName of ["myCollection", "myCappedCollection"]) {
jsTestLog(`Checking ${dbName}.${collectionName} on ${node}`);
// Use "countDocuments" to check actual docs, "count" to check sizeStorer data.
assert.eq(donorPrimary.getDB(dbName)[collectionName].countDocuments({}),
node.getDB(dbName)[collectionName].countDocuments({}),
"countDocuments");
assert.eq(donorPrimary.getDB(dbName)[collectionName].count(),
node.getDB(dbName)[collectionName].count(),
"count");
}
});
tenantMigrationTest.stop();
})();
|