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
93
94
95
96
97
98
99
100
101
102
|
/**
* Tests a case where the retryable write oplog pre-fetch stage does not fetch the pre/post image
* for a findAndModify operation because there is a newer txnNumber started in the same session when
* the pre-fetch stage runs. As a newer transaction has started in the same session, the tenant
* migration does not need to support retrying the findAndModify. We test that the tenant migration
* can still succeed in this case.
*
* @tags: [
* incompatible_with_eft,
* incompatible_with_macos,
* incompatible_with_windows_tls,
* requires_majority_read_concern,
* requires_persistence,
* ]
*/
(function() {
"use strict";
load("jstests/replsets/libs/tenant_migration_test.js");
load("jstests/replsets/libs/tenant_migration_util.js");
load("jstests/libs/uuid_util.js");
load("jstests/libs/fail_point_util.js"); // For configureFailPoint().
const tenantMigrationTest = new TenantMigrationTest({name: jsTestName()});
const kTenantId = "testTenantId";
const kDbName = tenantMigrationTest.tenantDB(kTenantId, "testDB");
const kCollName = "testColl";
tenantMigrationTest.insertDonorDB(kDbName, kCollName, [{x: 1}]);
const recipientPrimary = tenantMigrationTest.getRecipientPrimary();
const hangBeforeRetrievingStartOpTime =
configureFailPoint(recipientPrimary, "fpAfterComparingRecipientAndDonorFCV", {action: "hang"});
const hangAfterRetrievingStartOpTime = configureFailPoint(
recipientPrimary, "fpAfterRetrievingStartOpTimesMigrationRecipientInstance", {action: "hang"});
const migrationId = UUID();
const migrationOpts = {
migrationIdString: extractUUIDFromObject(migrationId),
tenantId: kTenantId,
};
assert.commandWorked(tenantMigrationTest.startMigration(migrationOpts));
hangBeforeRetrievingStartOpTime.wait();
const donorDB = tenantMigrationTest.getDonorPrimary().getDB(kDbName);
// Run a retryable findAndModify before the recipient gets the start fetching optime so that the
// recipient would start fetching oplog from this findAndModify's oplog entry and the post-image
// should be less than the startFetchingOpTime.
const lsid = {
id: UUID()
};
let res = assert.commandWorked(donorDB.runCommand({
findAndModify: kCollName,
query: {x: 1},
update: {$set: {y: 1}},
new: true,
txnNumber: NumberLong(0),
lsid: lsid,
writeConcern: {w: "majority"}
}));
jsTestLog("First findAndModify: " + tojson(res));
hangBeforeRetrievingStartOpTime.off();
hangAfterRetrievingStartOpTime.wait();
// Run another retryable findAndModify with a newer txnNumber using the same session before the
// recipient's retryable write pre-fetch stage. After this, the pre-fetch stage would not fetch the
// post-image of the last findAndModify because a newer txnNumber has started.
res = assert.commandWorked(donorDB.runCommand({
findAndModify: kCollName,
query: {x: 1},
update: {$set: {y: 2}},
new: true,
txnNumber: NumberLong(1),
lsid: lsid,
writeConcern: {w: "majority"}
}));
jsTestLog("Second findAndModify: " + tojson(res));
// Resume the tenant migration.
hangAfterRetrievingStartOpTime.off();
TenantMigrationTest.assertCommitted(tenantMigrationTest.waitForMigrationToComplete(migrationOpts));
res = assert.commandWorked(recipientPrimary.getDB(kDbName).runCommand({
findAndModify: kCollName,
query: {x: 1},
update: {$set: {y: 2}},
new: true,
txnNumber: NumberLong(1),
lsid: lsid,
writeConcern: {w: "majority"}
}));
jsTestLog("Retry findAndModify on recipient: " + tojson(res));
assert.eq(2, res.value.y);
tenantMigrationTest.stop();
})();
|