diff options
author | Randolph Tan <randolph@10gen.com> | 2013-02-27 11:23:14 -0500 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2013-02-28 16:00:28 -0500 |
commit | 9d638fd65a8010d3d357b2cd0bb11e099a222ae8 (patch) | |
tree | 3383c960965115698cc4d624b60004231f662fbe /src | |
parent | 7471ba53b04f21157c4d6066e6e2769d856a3d3c (diff) | |
download | mongo-9d638fd65a8010d3d357b2cd0bb11e099a222ae8.tar.gz |
SERVER-8760 DBClientReplicaSet::slaveConn returns connection to primary
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/client/dbclient_rs.cpp | 2 | ||||
-rw-r--r-- | src/mongo/client/dbclient_rs_test.cpp | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/mongo/client/dbclient_rs.cpp b/src/mongo/client/dbclient_rs.cpp index 0017ada1400..90cbd5fcd58 100644 --- a/src/mongo/client/dbclient_rs.cpp +++ b/src/mongo/client/dbclient_rs.cpp @@ -1536,7 +1536,7 @@ namespace mongo { } DBClientConnection& DBClientReplicaSet::slaveConn() { - BSONArray emptyArray; + BSONArray emptyArray(BSON_ARRAY(BSONObj())); TagSet tags(emptyArray); shared_ptr<ReadPreferenceSetting> readPref(new ReadPreferenceSetting( ReadPreference_SecondaryPreferred, new TagSet(emptyArray))); diff --git a/src/mongo/client/dbclient_rs_test.cpp b/src/mongo/client/dbclient_rs_test.cpp index 97d9f6f080a..19e94a0fc9f 100644 --- a/src/mongo/client/dbclient_rs_test.cpp +++ b/src/mongo/client/dbclient_rs_test.cpp @@ -250,4 +250,20 @@ namespace mongo_test { ASSERT_NOT_EQUALS(dest, newDest); } } + + // Note: slaveConn is dangerous and should be deprecated! Also see SERVER-7801. + TEST_F(TaggedFiveMemberRS, SlaveConnReturnsSecConn) { + MockReplicaSet* replSet = getReplSet(); + vector<HostAndPort> seedList; + seedList.push_back(HostAndPort(replSet->getPrimary())); + + DBClientReplicaSet replConn(replSet->getSetName(), seedList); + + string dest; + mongo::DBClientConnection& secConn = replConn.slaveConn(); + auto_ptr<DBClientCursor> cursor = secConn.query(IdentityNS, Query()); + BSONObj doc = cursor->next(); + dest = doc[HostField.name()].str(); + ASSERT_NOT_EQUALS(dest, replSet->getPrimary()); + } } |