Mongdb replica set (i), Springboot link MONGO replica set

Source: Internet
Author: User
Tags mongodb

An online program connection between the previous two days MONGO a sudden occurrence of the following error,

Org.springframework.dao.DataAccessResourceFailureException:Timed out after 30000 Ms while waiting for a-server that match Es writableserverselector. Client view of cluster state is {type=replica_set, servers=[{address=127.0.0.1:27017, Type=replica_set_secondary, roundtriptime=1.3 MS, state=connected}]; Nested exception is com.mongodb.MongoTimeoutException:Timed out over 30000 Ms while waiting for a server that matches Wr Itableserverselector. Client view of cluster state is {type=replica_set, servers=[{address=127.0.0.1:27017, Type=replica_set_secondary, roundtriptime=1.3 MS, state=connected}] at Org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible ( mongoexceptiontranslator.java:77) at Org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException (mongotemplate.java:2135 ) at Org.springframework.data.mongodb.core.MongoTemplate.execute (mongotemplate.java:481) at Org.springframework.da Ta.mongodb.core.MongoTemplAte.savedbobject (mongotemplate.java:1101) at Org.springframework.data.mongodb.core.MongoTemplate.doSave ( mongotemplate.java:1034) at Org.springframework.data.mongodb.core.MongoTemplate.save (mongotemplate.java:981) at or G.springframework.data.mongodb.core.mongotemplate.save (mongotemplate.java:969) at Com.eju.ess.MongoTest.test1 ( Mongotest.java:43 in Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native method) at Sun.reflect.NativeMethodAcces Sorimpl.invoke (nativemethodaccessorimpl.java:62) at Sun.reflect.DelegatingMethodAccessorImpl.invoke ( delegatingmethodaccessorimpl.java:43) at Java.lang.reflect.Method.invoke (method.java:498) at Org.junit.runners.mod El. Frameworkmethod$1.runreflectivecall (FRAMEWORKMETHOD.JAVA:50) at Org.junit.internal.runners.model.ReflectiveCallable.run (Reflectivecallable.java:12) at Org.junit.runners.model.FrameworkMethod.invokeExplosively (frameworkmethod.java:47) at Org.junit.internal.runners.statements.InvokeMethod.evaluAte (invokemethod.java:17) at Org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate ( RUNBEFORETESTMETHODCALLBACKS.JAVA:75) at Org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate ( runaftertestmethodcallbacks.java:86) at Org.springframework.test.context.junit4.statements.SpringRepeat.evaluate (springrepeat.java:84) at the Org.junit.runners.ParentRunner.runLeaf (parentrunner.java:325) at org.springframework.tes T.context.junit4.springjunit4classrunner.runchild (springjunit4classrunner.java:252) at Org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild (springjunit4classrunner.java:94) at Org.junit.runners.parentrunner$3.run (parentrunner.java:290) at Org.junit.runners.parentrunner$1.schedule ( parentrunner.java:71) at Org.junit.runners.ParentRunner.runChildren (parentrunner.java:288) at Org.junit.runners.Pa rentrunner.access$000 (parentrunner.java:58) at Org.junit.runners.ParEntrunner$2.evaluate (parentrunner.java:268) at Org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate ( RUNBEFORETESTCLASSCALLBACKS.JAVA:61) at Org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate ( RUNAFTERTESTCLASSCALLBACKS.JAVA:70) at Org.junit.runners.ParentRunner.run (parentrunner.java:363) at Org.springfram Ework.test.context.junit4.SpringJUnit4ClassRunner.run (springjunit4classrunner.java:191) at Org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run (junit4testreference.java:86) at Org.eclipse.jdt.internal.junit.runner.TestExecution.run (testexecution.java:38) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (remotetestrunner.java:459) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (remotetestrunner.java:678) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run (remotetestrunner.java:382) at Org.eclipse.jdt.internal.junit.runner.rEmotetestrunner.main (remotetestrunner.java:192) caused by:com.mongodb.MongoTimeoutException:Timed out 30000 ms While waiting for a server, that matches writableserverselector. Client view of cluster state is {type=replica_set, servers=[{address=127.0.0.1:27017, Type=replica_set_secondary, roundtriptime=1.3 MS, state=connected}] at Com.mongodb.connection.BaseCluster.createTimeoutException ( basecluster.java:377) at Com.mongodb.connection.BaseCluster.selectServer (basecluster.java:104) at Com.mongodb.bind Ing. Clusterbinding$clusterbindingconnectionsource.<init> (clusterbinding.java:75) at Com.mongodb.binding.clusterbinding$clusterbindingconnectionsource.<init> (ClusterBinding.java:71) at Com.mongodb.binding.ClusterBinding.getWriteConnectionSource (clusterbinding.java:68) at Com.mongodb.operation.OperationHelper.withConnection (operationhelper.java:411) at Com.mongodb.operation.BaseWriteOperation.execute (basewriteoperation.java:133) at Com.mongodB.operation.basewriteoperation.execute (basewriteoperation.java:60) at Com.mongodb.Mongo.execute (mongo.java:845) A T Com.mongodb.mongo$2.execute (mongo.java:828) at Com.mongodb.DBCollection.executeWriteOperation (Dbcollection.java : 342) at Com.mongodb.DBCollection.insert (dbcollection.java:337) at Com.mongodb.DBCollection.insert (Dbcollection.ja va:328) at Com.mongodb.DBCollection.insert (dbcollection.java:298) at Com.mongodb.DBCollection.insert (dbcollection. java:264) at Com.mongodb.DBCollection.insert (dbcollection.java:186) at Com.mongodb.DBCollection.save (dbcollection. java:407) at Com.mongodb.DBCollection.save (dbcollection.java:382) at Org.springframework.data.mongodb.core.MongoTe Mplate$11.doincollection (mongotemplate.java:1106) at Org.springframework.data.mongodb.core.MongoTemplate.execute (mongotemplate.java:479) ...

 More

One of the words is that

{address=127.0.0.1:27017, type=replica_set_secondary, roundtriptime=1.3 MS, state=connected}

It means 127.0.0.1:27017. This server is a Secondary,mongo driver that cannot write data to the secondary node, suspected MONGO primary and secondary switching.

Later the login MONGO server found that there was indeed a primary and secondary switch.

And then back to the program found that the colleague link MONGO code as follows,

Spring.data.mongodb.uri=mongodb://127.0.0.1:27017/quezon

I rub, only linked to a MONGO, happened to be online when the node happens to be primary node, now occurred primary and secondary, so the error, adjusted MONGO link string below,

Spring.data.mongodb.uri=mongodb://127.0.0.1:27017,127.0.0.1:27018,127.0.0.1:27019/quezon?replcaset=spock

Where Replcaset specifies the name of the replica set, reboot, OK.

Reference articles:

Http://www.runoob.com/mongodb/mongodb-connections.html

Http://xiaoqiangge.com/aritcle/1506320282052.html

Http://xiaoqiangge.com/aritcle/1506325361041.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.