summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod/replica_set_shard_version.js
blob: b8fe681cc06ad69de96b9723e7f37d9dc9d24070 (plain)
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
// Tests whether a Replica Set in a mongos cluster can cause versioning problems

jsTestLog("Starting sharded cluster...");

var st = new ShardingTest({shards: 1, mongos: 2, other: {rs: true}});

// Uncomment to stop the balancer, since the balancer usually initializes the shard automatically
// SERVER-4921 is otherwise hard to manifest
// st.stopBalancer()

var mongosA = st.s0;
var mongosB = st.s1;
var shard = st.shard0;

coll = mongosA.getCollection(jsTestName() + ".coll");

// Wait for primary and then initialize shard SERVER-5130
st.rs0.getPrimary();
coll.findOne();

var sadmin = shard.getDB("admin");
assert.throws(function() {
    sadmin.runCommand({replSetStepDown: 3000, force: true});
});

st.rs0.getPrimary();

mongosA.getDB("admin").runCommand({setParameter: 1, traceExceptions: true});

try {
    // This _almost_ always fails, unless the new primary is already detected.   If if fails, it
    // should
    // mark the master as bad, so mongos will reload the replica set master next request
    // TODO: Can we just retry and succeed here?
    coll.findOne();
} catch (e) {
    print("This error is expected : ");
    printjson(e);
}

jsTest.log("Running query which should succeed...");

// This should always succeed without throwing an error
coll.findOne();

mongosA.getDB("admin").runCommand({setParameter: 1, traceExceptions: false});

// now check secondary

assert.throws(function() {
    sadmin.runCommand({replSetStepDown: 3000, force: true});
});

// Can't use the mongosB - SERVER-5128
other = new Mongo(mongosA.host);
other.setSlaveOk(true);
other = other.getCollection(jsTestName() + ".coll");

print("eliot: " + tojson(other.findOne()));

st.stop();