[JAVA-162] Unable to connection to a set of slave servers Created: 07/Sep/10  Updated: 10/Oct/10  Resolved: 10/Oct/10

Status: Closed
Project: Java Driver
Component/s: Cluster Management
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Joseph Wang Assignee: Eliot Horowitz (Inactive)
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

If you pass in a list of servers, one must be master. If you just want to connect to a slave, do "new Mongo(new ServerAddress(ip))".

On Tue, Sep 7, 2010 at 10:46 AM, Joseph Wang <josephykwang@yahoo.com> wrote:

String[] servers = server_list.split(",");
ArrayList<ServerAddress> addr = new ArrayList<ServerAddress>();
int serverCount = 0;
for (int i = 0; i < servers.length; ++i) {
String[] serverInfo = servers[i].split(":");

try {
if (serverInfo.length == SERVER_INFORMATION_FIELD_SIZE)

{ System.out.println("MongoConnnection: add server " + serverInfo[SERVER_NAME_FIELD] + " at port " + serverInfo[SERVER_PORT_FIELD]); ServerAddress host = new ServerAddress( serverInfo[SERVER_NAME_FIELD], Integer.parseInt(serverInfo[SERVER_PORT_FIELD])); addr.add(host); serverCount++; }

} catch (Exception ex) {

}
}

if (serverCount > 0)

{ m = new Mongo(addr, opt); }

From: Kristina Chodorow <kristina@10gen.com>
To: mongodb-user@googlegroups.com
Sent: Tue, September 7, 2010 7:16:19 AM
Subject: Re: [mongodb-user] Java Driver Failed to Connect to Slaves

What does your code look like? Are you calling "new Mongo(ip1, ip2)"? If you're connecting to a slave, you should just say "new Mongo(ip1)".

On Tue, Sep 7, 2010 at 1:01 AM, Joseph Wang <josephykwang@yahoo.com> wrote:

MongoConnnection: add server ip-10-160-86-4 at port 10000
MongoConnnection: add server ip-10-161-50-230 at port 10000
...

SEVERE: switched to: ip-10-160-86-4:10000 but isn't master
Sep 7, 2010 12:58:04 AM com.mongodb.DBTCPConnector _pickInitial
SEVERE: can't pick initial master, using random one
com.mongodb.MongoException: can't find master
at com.mongodb.DBTCPConnector._pickInitial(DBTCPConnector.java:422)
at com.mongodb.Mongo.<init>(Mongo.java:177)



 Comments   
Comment by Eliot Horowitz (Inactive) [ 10/Oct/10 ]

This doesn't make sense in the context of replica sets.
With slaveOk and replica sets you just give all hosts and it'll route to slaves

Comment by Joseph Wang [ 28/Sep/10 ]

Connections to two regular slaves.

Comment by Eliot Horowitz (Inactive) [ 27/Sep/10 ]

Do you mean a list of regular slaves or in a repclia set?
A bit confused

Generated at Thu Feb 08 08:51:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.