I deployed replicated mongodb instances. I see that it is up and when
I execute re.status() in mongo console this is what I see
test1:PRIMARY> rs.status()
{
"set" : "test1",
"date" : ISODate("2011-06-13T01:55:02Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "localhost:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"optime" : {
"t" : 1307927890000,
"i" : 1
},
"optimeDate" :
ISODate("2011-06-13T01:18:10Z"),
"self" : true
},
{
"_id" : 1,
"name" : "localhost:27018",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 2204,
"optime" : {
"t" : 1307927890000,
"i" : 1
},
"optimeDate" :
ISODate("2011-06-13T01:18:10Z"),
"lastHeartbeat" :
ISODate("2011-06-13T01:55:02Z")
},
{
"_id" : 2,
"name" : "localhost:27019",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 2206,
"optime" : {
"t" : 1307927890000,
"i" : 1
},
"optimeDate" :
ISODate("2011-06-13T01:18:10Z"),
"lastHeartbeat" :
ISODate("2011-06-13T01:55:02Z")
}
],
"ok" : 1
I wrote a simple test in java which looks as follows
Mongo m;
try {
List<ServerAddress> addrs = new ArrayList<ServerAddress>();
addrs.add(new ServerAddress("Xen01.deb015.lnp31.geo-
trinity.com", 27017));
addrs.add(new ServerAddress("Xen01.deb015.lnp31.geo-
trinity.com", 27018));
addrs.add(new ServerAddress("Xen01.deb015.lnp31.geo-
trinity.com", 27019));
new WriteConcern(1, 1000);
MongoOptions mo = new MongoOptions();
mo.maxWaitTime = 10000;
mo.autoConnectRetry = true;
mo.connectTimeout = 1000;
mo.safe = true;
mo.slaveOk = true;
mo.w = 1;
mo.wtimeout = 4000;
mo.connectionsPerHost = 3;
m = new Mongo(addrs, mo);
DB db = m.getDB("test");
DBCollection coll = db.getCollection("test");
coll.setObjectClass(Score.class);
for (int i = 0; i < 10; i++) {
Score score = new Score();
score.put("guid", Integer.valueOf(i));
score.put("mid", Integer.valueOf(i));
score.put("mval", Integer.valueOf(i + 300));
score.put("cd", tm.now());
coll.insert(score);
}
}
When the statement coll.insert(score) executes I get the following
error
WARNING: Server seen up:
Xen01.deb015.lnp31.geo-trinity.com:27017
Jun 12, 2011 6:25:20 PM com.mongodb.ReplicaSetStatus$Node update
WARNING: Server seen up:
Xen01.deb015.lnp31.geo-trinity.com:27018
Jun 12, 2011 6:25:21 PM com.mongodb.ReplicaSetStatus$Node update
WARNING: Server seen up:
Xen01.deb015.lnp31.geo-trinity.com:27019
Jun 12, 2011 6:25:22 PM com.mongodb.ReplicaSetStatus$Node update
WARNING: Server seen down: localhost:27017
Jun 12, 2011 6:25:25 PM com.mongodb.ReplicaSetStatus$Node update
WARNING: Server seen down: localhost:27017
Jun 12, 2011 6:25:37 PM com.mongodb.ReplicaSetStatus$Node update
WARNING: Server seen down: localhost:27017
com.mongodb.MongoException: can't find a master
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:396)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:144)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:137)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:255)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:210)
at com.mongodb.DBCollection.insert(DBCollection.java:80)
at com.ebay.trinity.mongodb.MongodbTest.runScoreTest(MongodbTest.java:
95)
at com.ebay.trinity.mongodb.MongodbTest.main(MongodbTest.java:40)
Can you please help me with this.