[JAVA-600] Getting com.mongodb.MongoException: can't find a master exception on AWS Created: 10/Jul/12  Updated: 11/Sep/19  Resolved: 10/Jul/12

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

Type: Task Priority: Blocker - P1
Reporter: Sankate Sharma Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: driver, replicaset
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Amazon web services


Issue Links:
Duplicate

 Description   

Hello, We are trying to deploy our app on AWS. We are running a replica set configuration with 2 data nodes and 1 arbiter. Same configuration works fine on local environment but throws following exception on AWS

com.mongodb.MongoException: can't find a master
com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:434)
com.mongodb.DBTCPConnector.call(DBTCPConnector.java:209)
com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:305)
com.mongodb.DBCollection.findOne(DBCollection.java:647)
com.mongodb.DBCollection.findOne(DBCollection.java:626)
com.mongodb.DBApiLayer$MyCollection.createIndex(DBApiLayer.java:364)
com.mongodb.DBCollection.createIndex(DBCollection.java:436)
com.mongodb.DBCollection.ensureIndex(DBCollection.java:515)
com.google.code.morphia.DatastoreImpl.ensureIndex(DatastoreImpl.java:245)
com.google.code.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:310)
com.google.code.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:279)
com.google.code.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:340)
com.google.code.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:333)
com.intuit.spark.MongoConnectionManager.<init>(MongoConnectionManager.java:37)

Here is the config of replia set
PRIMARY> rs.config()
{
"_id" : "sparkReplicaSet",
"version" : 5,
"members" : [

{ "_id" : 0, "host" : "ip-10-46-223-117:27017" }

,

{ "_id" : 1, "host" : "ip-10-46-167-177.ec2.internal:27017" }

,

{ "_id" : 2, "host" : "domU-12-31-39-04-D6-95.compute-1.internal:27017", "arbiterOnly" : true }

]
}

I have installed mongo shell on the app server(TOMCAT) host and I am able to connect to PRIMARY via the shell, that rules out networking issue.

The code which gets the connection string is as follows
List<ServerAddress> addrs = getMongoAddress();
m = new Mongo(addrs);
morphia = new Morphia();

addrs List is created using
ec2-23-22-74-137.compute-1.amazonaws.com:27017
ec2-23-23-87-249.compute-1.amazonaws.com:27017
ec2-23-22-156-48.compute-1.amazonaws.com:27017

What are we missing in all this? Same code works on 3 node replica set on local machine. Here is config from my local setup
PRIMARY> rs.config()
{
"_id" : "sparkdb",
"version" : 3,
"members" : [

{ "_id" : 0, "host" : "MPKL09407ef8d.local:27017" }

,

{ "_id" : 1, "host" : "MPKL09407ef8d.local:27088" }

,

{ "_id" : 2, "host" : "MPKL09407ef8d.local:27098" }

]
}

Thanks
Sankate



 Comments   
Comment by Kristina Chodorow (Inactive) [ 10/Jul/12 ]

Can the appserver connect to the members of the replica set using the hostnames in the config, as well? (domU-12-31-39-04-D6-95.compute-1.internal:27017, ip-10-46-167-177.ec2.internal:27017, and ip-10-46-223-117:27017?)

Comment by Sankate Sharma [ 10/Jul/12 ]

Hi Kristina

Yes, I am able to connect to all three nodes from shell. Here is the output of rs.status()

PRIMARY> rs.status()
{
"set" : "sparkReplicaSet",
"date" : ISODate("2012-07-10T21:23:30Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "ip-10-46-223-117:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"optime" :

{ "t" : 1341950670000, "i" : 1 }

,
"optimeDate" : ISODate("2012-07-10T20:04:30Z"),
"self" : true
},
{
"_id" : 1,
"name" : "ip-10-46-167-177.ec2.internal:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 132059,
"optime" :

{ "t" : 1341950670000, "i" : 1 }

,
"optimeDate" : ISODate("2012-07-10T20:04:30Z"),
"lastHeartbeat" : ISODate("2012-07-10T21:23:30Z"),
"pingMs" : 3
},
{
"_id" : 2,
"name" : "domU-12-31-39-04-D6-95.compute-1.internal:27017",
"health" : 1,
"state" : 7,
"stateStr" : "ARBITER",
"uptime" : 130936,
"optime" :

{ "t" : 0, "i" : 0 }

,
"optimeDate" : ISODate("1970-01-01T00:00:00Z"),
"lastHeartbeat" : ISODate("2012-07-10T21:23:29Z"),
"pingMs" : 0
}
],
"ok" : 1
}

Comment by Kristina Chodorow (Inactive) [ 10/Jul/12 ]

Did you try connecting with the shell using the hostnames Java's using in particular, i.e.,

$ mongo ec2-23-22-74-137.compute-1.amazonaws.com:27017/test
$ mongo ec2-23-23-87-249.compute-1.amazonaws.com:27017/test
$ mongo ec2-23-22-156-48.compute-1.amazonaws.com:27017/test

and that works?

Also, can you run rs.status() once you've started the mongo shell and send the output?

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