2021-01-28 15:45:38 +00:00
|
|
|
// Test that a delayed secondary in a replica set still succeeds as a sync source.
|
|
|
|
|
// First, we disconnect the primary from the non-delayed secondary. Next, we issue
|
|
|
|
|
// a write to the primary and ensure this write propagates
|
|
|
|
|
// to the disconnected node via the delayed secondary.
|
|
|
|
|
//
|
2021-05-19 20:10:31 +00:00
|
|
|
// @tags: [
|
|
|
|
|
// ]
|
2024-08-20 17:54:15 -04:00
|
|
|
import {ReplSetTest} from "jstests/libs/replsettest.js";
|
2012-03-05 10:31:34 -05:00
|
|
|
import {syncFrom, waitForAllMembers} from "jstests/replsets/rslib.js";
|
|
|
|
|
|
2025-08-28 15:11:44 -04:00
|
|
|
let replTest = new ReplSetTest({nodes: 3, useBridge: true});
|
|
|
|
|
let nodes = replTest.startSet();
|
|
|
|
|
let config = replTest.getReplSetConfig();
|
2012-03-07 11:47:49 -05:00
|
|
|
// ensure member 0 is primary
|
|
|
|
|
config.members[0].priority = 2;
|
2012-03-05 10:31:34 -05:00
|
|
|
config.members[1].priority = 0;
|
2021-08-11 21:08:31 +00:00
|
|
|
config.members[1].secondaryDelaySecs = 5;
|
2014-12-02 15:43:13 -05:00
|
|
|
config.members[2].priority = 0;
|
2012-03-05 10:31:34 -05:00
|
|
|
|
|
|
|
|
replTest.initiate(config);
|
2025-08-28 15:11:44 -04:00
|
|
|
let primary = replTest.getPrimary().getDB(jsTestName());
|
2021-04-29 01:19:06 +00:00
|
|
|
// The default WC is majority and stopServerReplication could prevent satisfying any majority
|
|
|
|
|
// writes.
|
2025-08-21 10:17:44 -07:00
|
|
|
assert.commandWorked(
|
|
|
|
|
primary.adminCommand({setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}}),
|
|
|
|
|
);
|
2021-04-29 01:19:06 +00:00
|
|
|
|
|
|
|
|
replTest.awaitReplication();
|
2012-03-05 10:31:34 -05:00
|
|
|
|
2025-08-28 15:11:44 -04:00
|
|
|
let secondaryConns = replTest.getSecondaries();
|
|
|
|
|
let secondaries = [];
|
|
|
|
|
for (let i in secondaryConns) {
|
|
|
|
|
let d = secondaryConns[i].getDB(jsTestName());
|
2020-08-27 14:07:45 -04:00
|
|
|
d.getMongo().setSecondaryOk();
|
2020-08-26 11:28:13 -04:00
|
|
|
secondaries.push(d);
|
2015-05-22 10:17:26 -04:00
|
|
|
}
|
2012-03-05 10:31:34 -05:00
|
|
|
|
2020-08-26 11:28:13 -04:00
|
|
|
waitForAllMembers(primary);
|
2012-03-05 10:31:34 -05:00
|
|
|
|
2015-11-06 13:40:59 -05:00
|
|
|
nodes[0].disconnect(nodes[2]);
|
2012-03-05 10:31:34 -05:00
|
|
|
|
2020-08-26 11:28:13 -04:00
|
|
|
primary.foo.insert({x: 1});
|
2012-03-05 10:31:34 -05:00
|
|
|
|
2017-03-08 17:14:26 -05:00
|
|
|
syncFrom(nodes[1], nodes[0], replTest);
|
2015-05-22 10:17:26 -04:00
|
|
|
|
2020-08-26 11:28:13 -04:00
|
|
|
// make sure the record still appears in the remote secondary
|
2025-08-21 10:17:44 -07:00
|
|
|
assert.soon(function () {
|
2020-08-26 11:28:13 -04:00
|
|
|
return secondaries[1].foo.findOne() != null;
|
2016-03-09 12:17:50 -05:00
|
|
|
});
|
2012-03-05 10:31:34 -05:00
|
|
|
|
2014-12-02 15:43:13 -05:00
|
|
|
replTest.stopSet();
|