Getting "not master" exception when secondary is switching to primary node

220 views
Skip to first unread message

Saurabh Gupta

unread,
Nov 29, 2011, 5:24:23 AM11/29/11
to mongodb-user
Hi,

I am using 2 ubuntu machines (one is primary node, second has
secondary and arbiter nodes). I am inserting documents using java
program through mongodb java driver. Following is the configuration:

String url =
"192.168.2.26:27017,192.168.2.25:27017,192.168.2.26:40001";
ArrayList<ServerAddress> addr = new
ArrayList<ServerAddress>();
for (String s: url.split(",")) {
try {
addr.add(new ServerAddress(s));
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
Mongo mongo = new Mongo(addr);
mongo.setWriteConcern(WriteConcern.SAFE);
MongoOptions mo = mongo.getMongoOptions();
mo.autoConnectRetry = true;
mo.socketKeepAlive = true;

I took my primary node down so that secondary can act as primary node.
Java program waits for some time and saying "Master is switching from
192.168.2.25:27017 to 192.168.2.26:27017". But after some time I am
getting the following exception:

com.mongodb.MongoException: not master
at com.mongodb.CommandResult.getException(CommandResult.java:87)
at com.mongodb.CommandResult.throwOnError(CommandResult.java:121)
at com.mongodb.DBTCPConnector._checkWriteError(DBTCPConnector.java:
131)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:155)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:138)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:261)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:211)
at com.mongodb.DBCollection.insert(DBCollection.java:57)
at com.mongodb.DBCollection.insert(DBCollection.java:102)
at cdi.hi.MongodbDriver.AppTest.testApp(AppTest.java:91)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:
130)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:
38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:
467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:
683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:
390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:
197)

My replica set configuration is

{
"_id" : "hi",
"version" : 4,
"members" : [
{
"_id" : 0,
"host" : "192.168.2.26:27017"
},
{
"_id" : 1,
"host" : "192.168.2.26:40001",
"arbiterOnly" : true
},
{
"_id" : 2,
"host" : "192.168.2.25:27017"
}
]
}

Please help!

Nat

unread,
Nov 29, 2011, 5:27:14 AM11/29/11
to mongod...@googlegroups.com
It's normal that you would receive such message during switchover.
--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.

Saurabh Gupta

unread,
Nov 29, 2011, 5:28:58 AM11/29/11
to mongodb-user
But it also terminates my java program which is an issue.

Nat

unread,
Nov 29, 2011, 6:55:28 AM11/29/11
to mongod...@googlegroups.com
You should catch and handle it.
Reply all
Reply to author
Forward
0 new messages