summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2012-11-18 16:28:55 -0500
committerDan Pasette <dan@10gen.com>2013-01-08 02:07:17 -0500
commit97df5708b95d28497e16f172e57922b02bca1ee9 (patch)
tree529d2e8454b352eb45d5277e788419ba5a802d5e
parentb7b2db71ba49e3092119869bcccf90a6d4c45df3 (diff)
downloadmongo-97df5708b95d28497e16f172e57922b02bca1ee9.tar.gz
SERVER-7704 - clean some of the equality semantics for sync and set ConnectionString
-rw-r--r--src/mongo/client/dbclient.cpp20
-rw-r--r--src/mongo/client/dbclientinterface.h6
-rw-r--r--src/mongo/s/shard.h5
-rw-r--r--src/mongo/s/shard_test.cpp13
4 files changed, 32 insertions, 12 deletions
diff --git a/src/mongo/client/dbclient.cpp b/src/mongo/client/dbclient.cpp
index 25457410344..1b64f4bf883 100644
--- a/src/mongo/client/dbclient.cpp
+++ b/src/mongo/client/dbclient.cpp
@@ -160,8 +160,6 @@ namespace mongo {
switch ( _type ) {
case INVALID:
- // both are invalid
- // I think that should be ==
return true;
case MASTER:
return _servers[0] == other._servers[0];
@@ -172,11 +170,23 @@ namespace mongo {
( _servers[0] == other._servers[1] ) &&
( _servers[1] == other._servers[0] );
case SET:
- // should this also make sure at least one host overlaps?
return _setName == other._setName;
case SYNC:
- // should this check the _servers array instead?
- return _string == other._string;
+ // The servers all have to be the same in each, but not in the same order.
+ if ( _servers.size() != other._servers.size() )
+ return false;
+ for ( unsigned i = 0; i < _servers.size(); i++ ) {
+ bool found = false;
+ for ( unsigned j = 0; j < other._servers.size(); j++ ) {
+ if ( _servers[i] == other._servers[j] ) {
+ found = true;
+ break;
+ }
+ }
+ if ( ! found )
+ return false;
+ }
+ return true;
case CUSTOM:
return _string == other._string;
}
diff --git a/src/mongo/client/dbclientinterface.h b/src/mongo/client/dbclientinterface.h
index a47625c6cff..cb0df4e1aaa 100644
--- a/src/mongo/client/dbclientinterface.h
+++ b/src/mongo/client/dbclientinterface.h
@@ -249,9 +249,9 @@ namespace mongo {
ConnectionType type() const { return _type; }
/**
- * this returns true if this and other point to the same logical entity
- * for single nodes, thats the same address
- * for replica sets, thats the same name
+ * This returns true if this and other point to the same logical entity.
+ * For single nodes, thats the same address.
+ * For replica sets, thats just the same replica set name.
*/
bool sameLogicalEndpoint( const ConnectionString& other ) const;
diff --git a/src/mongo/s/shard.h b/src/mongo/s/shard.h
index c02869e85d3..7a7e0d8fbda 100644
--- a/src/mongo/s/shard.h
+++ b/src/mongo/s/shard.h
@@ -99,8 +99,9 @@ namespace mongo {
}
bool operator==( const Shard& s ) const {
- bool n = _name == s._name;
- return n && _cs.sameLogicalEndpoint( s._cs );
+ if ( _name != s._name )
+ return false;
+ return _cs.sameLogicalEndpoint( s._cs );
}
bool operator!=( const Shard& s ) const {
diff --git a/src/mongo/s/shard_test.cpp b/src/mongo/s/shard_test.cpp
index 413f8ab6f07..cbe273cde14 100644
--- a/src/mongo/s/shard_test.cpp
+++ b/src/mongo/s/shard_test.cpp
@@ -42,7 +42,7 @@ namespace mongo {
// -----------------------------------
- TEST( Shard, Simple1 ) {
+ TEST( Shard, EqualityRs ) {
Shard a( "foo", "bar/a,b" );
Shard b( "foo", "bar/a,b" );
ASSERT_EQUALS( a, b );
@@ -51,10 +51,19 @@ namespace mongo {
ASSERT_EQUALS( a, b );
}
- TEST( Shard, Simple2 ) {
+ TEST( Shard, EqualitySingle ) {
ASSERT_EQUALS( Shard( "foo", "b.foo.com:123"), Shard( "foo", "b.foo.com:123") );
ASSERT_NOT_EQUALS( Shard( "foo", "b.foo.com:123"), Shard( "foo", "a.foo.com:123") );
ASSERT_NOT_EQUALS( Shard( "foo", "b.foo.com:123"), Shard( "foo", "b.foo.com:124") );
ASSERT_NOT_EQUALS( Shard( "foo", "b.foo.com:123"), Shard( "foa", "b.foo.com:123") );
}
+
+ TEST( Shard, EqualitySync ) {
+ ConnectionString cs( ConnectionString::SYNC, "a,b,c" );
+ ASSERT( cs.sameLogicalEndpoint( ConnectionString( ConnectionString::SYNC, "a,b,c" ) ) );
+ ASSERT( cs.sameLogicalEndpoint( ConnectionString( ConnectionString::SYNC, "c,b,a" ) ) );
+ ASSERT( cs.sameLogicalEndpoint( ConnectionString( ConnectionString::SYNC, "c,a,b" ) ) );
+
+ ASSERT( ! cs.sameLogicalEndpoint( ConnectionString( ConnectionString::SYNC, "d,a,b" ) ) );
+ }
}