Skip to content

Commit

Permalink
Added test for oplog timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
kchodorow committed Jan 22, 2013
1 parent e351361 commit 6b0e623
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
56 changes: 56 additions & 0 deletions jstests/slowWeekly/server6733.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Test that the oplog reader times out after 30 seconds with no response

print("Bring up three members");
var replSet = new ReplSetTest({name: 'testSet', nodes: 3});
replSet.startSet();
replSet.initiate(
{
_id:'testSet',
members:
[
{_id: 0, host: getHostName()+":"+replSet.ports[0]},
{_id: 1, host: getHostName()+":"+replSet.ports[1], priority: 0},
{_id: 2, host: getHostName()+":"+replSet.ports[2], priority: 0}
]
}
);

// Do an initial write
var master = replSet.getMaster();
master.getDB("foo").bar.insert({x:1});
replSet.awaitReplication();

var primary = master.getDB("foo");
replSet.nodes[1].setSlaveOk();
replSet.nodes[2].setSlaveOk();
var A = replSet.nodes[1].getDB("admin");
var B = replSet.nodes[2].getDB("admin");
var primaryAddress = getHostName()+":"+replSet.ports[0];
var bAddress = getHostName()+":"+replSet.ports[2];

print("Force A to sync from B");
A.runCommand({replSetSyncFrom : bAddress});
assert.soon(
function() {
return A.runCommand({replSetGetStatus : 1}).syncingTo == bAddress;
}
);

print("Black-hole B");
B.runCommand({configureFailPoint: 'rsStopGetMore', mode: 'alwaysOn'});

print("Check that A switches sync targets after 30 seconds");
sleep(30000);

assert.soon(
function() {
return A.runCommand({replSetGetStatus : 1}).syncingTo == primaryAddress;
}
);

print("Un-black-hole B and make sure nothing stupid happens");
B.runCommand({configureFailPoint: 'rsStopGetMore', mode: 'off'});

sleep(10000);

replSet.stopSet();
7 changes: 7 additions & 0 deletions src/mongo/db/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "mongo/db/stats/counters.h"
#include "mongo/s/d_logic.h"
#include "mongo/s/stale_exception.h" // for SendStaleConfigException
#include "mongo/util/fail_point_service.h"
#include "mongo/util/file_allocator.h"
#include "mongo/util/goodies.h"
#include "mongo/util/mongoutils/str.h"
Expand Down Expand Up @@ -87,6 +88,8 @@ namespace mongo {
HANDLE lockFileHandle;
#endif

MONGO_FP_DECLARE(rsStopGetMore);

/*static*/ OpTime OpTime::_now() {
OpTime result;
unsigned t = (unsigned) time(0);
Expand Down Expand Up @@ -675,6 +678,10 @@ namespace mongo {
uassert(16543, status.reason(), status.isOK());

if (str::startsWith(ns, "local.oplog.")){
while (MONGO_FAIL_POINT(rsStopGetMore)) {
sleepmillis(0);
}

if (pass == 0) {
mutex::scoped_lock lk(OpTime::m);
last = OpTime::getLast(lk);
Expand Down

0 comments on commit 6b0e623

Please sign in to comment.