problem with replicated servers

91 views
Skip to first unread message

redbaron

unread,
Jun 12, 2011, 10:03:10 PM6/12/11
to mongodb-user
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.

Nat

unread,
Jun 12, 2011, 11:29:43 PM6/12/11
to mongod...@googlegroups.com
If you plan to access the replicaset from remote machine, you should not use localhost when you configure the replicaset. Use real IP that can be accessed from the client instead.
Reply all
Reply to author
Forward
0 new messages