From 83d749c1371b47fd9fe2ce0910523983cb316463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Swen=20Th=C3=BCmmler?= Date: Tue, 20 Apr 2010 16:06:19 +0200 Subject: [PATCH] fix pair connect for multi-homed hosts pair connect could fail to find the master, when the client used a different connection string than the paired servers (e.g. the server uses the machine name and the client the fully qualified domain name). This is fixed by actually querying the server. --- src/main/com/mongodb/DBTCPConnector.java | 20 +++++++++++--------- 1 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/com/mongodb/DBTCPConnector.java b/src/main/com/mongodb/DBTCPConnector.java index 55233ad..2ede482 100644 --- a/src/main/com/mongodb/DBTCPConnector.java +++ b/src/main/com/mongodb/DBTCPConnector.java @@ -304,7 +304,6 @@ class DBTCPConnector implements DBConnector { _pickCurrent(); try { - System.out.println( _curAddress ); DBCollection collection = _mongo.getDB( "admin" ).getCollection( "$cmd" ); Iterator i = collection.find( _isMaster , null , 0 , 1 , 0 ); if ( i == null || ! i.hasNext() ) @@ -317,17 +316,20 @@ class DBTCPConnector implements DBConnector { if ( 1 == ismaster ) return; - if ( res.get( "remote" ) == null ) - throw new MongoException( "remote not sent back!" ); - - String remote = res.get( "remote" ).toString(); synchronized ( _allHosts ){ for ( ServerAddress a : _allHosts ){ - if ( ! a.sameHost( remote ) ) - continue; - System.out.println( "remote [" + remote + "] -> [" + a + "]" ); _set( a ); - return; + collection = _mongo.getDB( "admin" ).getCollection( "$cmd" ); + i = collection.find( _isMaster , null , 0 , 1 , 0 ); + if ( i == null || ! i.hasNext() ) + throw new MongoException( "no result for ismaster query?" ); + res = i.next(); + if ( i.hasNext() ) + throw new MongoException( "what's going on" ); + + ismaster = ((Number)res.get( "ismaster" )).intValue(); + if ( 1 == ismaster ) + return; } } } -- 1.7.0.5