Skip to content

Commit

Permalink
SERVER-8278 Change replicatedTo to writtenTo and add primary to list
Browse files Browse the repository at this point in the history
  • Loading branch information
kchodorow committed Feb 7, 2013
1 parent 2862a34 commit 1ea4039
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
12 changes: 8 additions & 4 deletions jstests/replsets/majority.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ print("should still be able to write to a majority");
var result = testInsert();
assert.eq(result.err, null);
// majority should be primary + 2 secondaries
assert.eq(result.replicatedTo.length, 2);
assert.eq(result.writtenTo.length, 3);
assert.contains(config.members[0], result);
assert.contains(config.members[1], result);
assert.contains(config.members[2], result);

Expand Down Expand Up @@ -78,7 +79,8 @@ replTest.awaitReplication();
print("makes sure majority works");
result = testInsert();
assert.eq(result.err, null);
assert.eq(result.replicatedTo.length, 2);
assert.eq(result.writtenTo.length, 3);
assert.contains(config.members[0], result);
assert.contains(config.members[1], result);
assert.contains(config.members[2], result);

Expand All @@ -95,7 +97,8 @@ print("make sure majority doesn't work");
master = replTest.getMaster();
result = testInsert();
assert.eq(result.err, "timeout");
assert.eq(result.replicatedTo.length, 1);
assert.eq(result.writtenTo.length, 2);
assert.contains(config.members[0], result);
assert.contains(config.members[1], result);

print("bring set back together");
Expand All @@ -108,7 +111,8 @@ master = replTest.getMaster();
print("make sure majority works");
result = testInsert();
assert.eq(result.err, null);
assert.eq(result.replicatedTo.length, 2);
assert.eq(result.writtenTo.length, 3);
assert.contains(config.members[0], result);
assert.contains(config.members[1], result);
assert.contains(config.members[2], result);

Expand Down
4 changes: 2 additions & 2 deletions src/mongo/db/dbcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ namespace mongo {
result.append( "wtimeout" , true );
errmsg = "timed out waiting for slaves";
result.append( "waited" , timer.millis() );
result.append("replicatedTo", getHostsReplicatedTo(op));
result.append("writtenTo", getHostsWrittenTo(op));
result.append( "err" , "timeout" );
return true;
}
Expand All @@ -257,7 +257,7 @@ namespace mongo {
killCurrentOp.checkForInterrupt();
}

result.append("replicatedTo", getHostsReplicatedTo(op));
result.append("writtenTo", getHostsWrittenTo(op));
int myMillis = timer.recordMillis();
result.appendNumber( "wtime" , myMillis );
}
Expand Down
9 changes: 6 additions & 3 deletions src/mongo/db/repl_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,11 @@ namespace mongo {
return numSlaves <= 0;
}

std::vector<BSONObj> getSlavesAtOp(OpTime& op) {
std::vector<BSONObj> getHostsAtOp(OpTime& op) {
std::vector<BSONObj> result;
if (theReplSet) {
result.push_back(theReplSet->myConfig().asBson());
}

scoped_lock mylk(_mutex);
for (map<Ident,OpTime>::iterator i = _slaves.begin(); i != _slaves.end(); i++) {
Expand Down Expand Up @@ -282,8 +285,8 @@ namespace mongo {
return slaveTracking.waitForReplication( op, w, maxSecondsToWait );
}

vector<BSONObj> getHostsReplicatedTo(OpTime& op) {
return slaveTracking.getSlavesAtOp(op);
vector<BSONObj> getHostsWrittenTo(OpTime& op) {
return slaveTracking.getHostsAtOp(op);
}

void resetSlaveCache() {
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/repl_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace mongo {

bool waitForReplication( OpTime op , int w , int maxSecondsToWait );

std::vector<BSONObj> getHostsReplicatedTo(OpTime& op);
std::vector<BSONObj> getHostsWrittenTo(OpTime& op);

void resetSlaveCache();
unsigned getSlaveCount();
Expand Down

0 comments on commit 1ea4039

Please sign in to comment.