2016-07-20 6 views
1

문제 : MongoDB를 오류와 함께 실패 기록 - PrimaryServerSelector 일치하는 서버를 기다리는 동안 MongoDB의 자바 클라이언트는 실패 할 때 replicaset에서 주 서버 노드 변경

은 30000 밀리 초 후 시간이 초과되었습니다. [: roundTripTime = 0.7, MS 상태} = CONNECTED 27,017, TYPE = REPLICA_SET_SECONDARY {주소 = intdb01]

이런 기본이 전환되면 클러스터 상태의 클라이언트보기 {TYPE = REPLICA_SET, 서버 =이고 intdb01 to intdb02. 클라이언트 드라이버가 여전히 intdb01 을 주 노드로 찾고있는 것 같습니다.

우리의 설치

우리는 replicaSet 3 개 MongoDB의 노드가 RS0라고합니다. 우리가 자바를 사용하여 연결하면 다음과 같이 , 우리는 연결 문자열에 3 개 서버를 제공합니다 : 하여 MongoDB를 : // intdb01 : 27017, intdb02을 : 27,017, intdb03 : 27017/replicaSet = RS0

DB를 .version -> 3.0.4

자바 드라이버 버전 : MongoDB를 드라이버-3.0.4.jar, MongoDB의 드라이버 코어-3.0.4.jar

클라이언트 연결 코드 :

if(mongoClient == null) { 
    MongoClientURI mcu = new MongoClientURI(mongoConnect); 
    mongoClient = new MongoClient(mcu); 
} 

mongoConnect에는 위에 표시된 연결 문자열이 들어 있습니다.

몽고 Replicaset 상태 정보

> rs.status() 
{ 
    "set" : "rs0", 
    "date" : ISODate("2016-07-19T21:14:03.001Z"), 
    "myState" : 1, 
    "members" : [{ 
     "_id" : 0, 
     "name" : "intdb01", 
     "health" : 1, 
     "state" : 2, 
     "stateStr" : "SECONDARY", 
     "uptime" : 439786, 
     "optime" : Timestamp(1468521291, 5), 
     "optimeDate" : ISODate("2016-07-14T18:34:51Z"), 
     "lastHeartbeat" : ISODate("2016-07-19T21:14:01.877Z"), 
     "lastHeartbeatRecv" : ISODate("2016-07-19T21:14:01.611Z"), 
     "pingMs" : 0, 
     "configVersion" : 4 
    }, 
    { 
     "_id" : 1, 
     "name" : "intdb02:27017", 
     "health" : 1, 
     "state" : 1, 
     "stateStr" : "PRIMARY", 
     "uptime" : 2948844, 
     "optime" : Timestamp(1468521291, 5), 
     "optimeDate" : ISODate("2016-07-14T18:34:51Z"), 
     "electionTime" : Timestamp(1468523057, 1), 
     "electionDate" : ISODate("2016-07-14T19:04:17Z"), 
     "configVersion" : 4, 
     "self" : true 
    }, 
    { 
     "_id" : 2, 
     "name" : "intdb03:27017", 
     "health" : 1, 
     "state" : 2, 
     "stateStr" : "SECONDARY", 
     "uptime" : 439779, 
     "optime" : Timestamp(1468521291, 5), 
     "optimeDate" : ISODate("2016-07-14T18:34:51Z"), 
     "lastHeartbeat" : ISODate("2016-07-19T21:14:01.294Z"), 
     "lastHeartbeatRecv" : ISODate("2016-07-19T21:14:01.294Z"), 
     "pingMs" : 0, 
     "configVersion" : 4 
    } 
    ], 
    "ok" : 1 
} 

나는 확인하고 문서와 코드/설정을 다시 확인해하지만 살짝 밟아 손쉽게 찾을 수있다. 기본 단계를 실행하여 시뮬레이션 할 수 있습니다. 보조 프로그램이 인계되지만 응용 프로그램 쓰기가 시작되지 않습니다. :-(

모든 포인터/팁 많은 감사!

가 스택 나는 그것이 코딩 오류 또는 구성인지 알아 내려고 노력하고 있어요

Caused by: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches PrimaryServerSelector. Client view of cluster state is {type=REPLICA_SET, servers=[{address=intdb01:27017, type=REPLICA_SET_SECONDARY, roundTripTime=0.7 ms, state=CONNECTED}] 
at com.mongodb.connection.BaseCluster.createTimeoutException(BaseCluster.java:370) 
at com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:101) 
at com.mongodb.binding.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:175) 
at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:141) 
at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:72) 
at com.mongodb.Mongo.execute(Mongo.java:747) 
at com.mongodb.Mongo$2.execute(Mongo.java:730) 
at com.mongodb.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:482) 
at com.mongodb.MongoCollectionImpl.update(MongoCollectionImpl.java:474) 
at com.mongodb.MongoCollectionImpl.updateOne(MongoCollectionImpl.java:325) 
at com.grid.core.persistence.mongodb.dao.GridEventDao.save(GridEventDao.java:69) 
... 6 more 
2016-07-19 17:05:01,882 [pool-2-thread-2] INFO org.mongodb.driver.cluster - No server chosen by PrimaryServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=SINGLE, all=[ServerDescription{address=intdb01:27017, type=REPLICA_SET_SECONDARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 0, 4]}, minWireVersion=0, maxWireVersion=3, electionId=null, maxDocumentSize=16777216, roundTripTimeNanos=724681, setName='rs0', canonicalAddress=intdb01:27017, hosts=[intdb01:27017, intdb02:27017], passives=[intdb03:27017], arbiters=[], primary='intdb02:27017', tagSet=TagSet{[]}}]}. Waiting for 30000 ms before timing out 

을 trace- 추가. 마지막 정보 메시지에서 stack trace는 connectionMode가 SINGLE이라고 말합니다.이 문제의 원인이라고 의심 되나 개발자 문서 사이트에서 이에 대한 정보를 찾을 수 없습니다.

+0

질문에 답하지 않으려면 문제를 작성하여 도움을 받으십시오. 종결 투표를하는 사람에게도 동일하게 적용됩니다. –

+0

전체 스택 추적을 제공 할 수 있습니까? – helmy

+0

스택 추적 쓰기 실패 추가. –

답변

0

오류 메시지에 모든 서버 주소가 나타납니다. 충분한, 3 개의 임의의 호스트 이름으로 무엇이 해결되지 않을지보십시오 :

 
com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches PrimaryServerSelector. Client view of cluster state is {type=REPLICA_SET, servers=[{address=xxx:27117, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: xxx}, caused by {java.net.UnknownHostException: xxx}}, {address=xxx:27118, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: xxx}, caused by {java.net.UnknownHostException: xxx}}, {address=xxx:27119, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: xxx}, caused by {java.net.UnknownHostException: xxx}}] 
    at com.mongodb.connection.BaseCluster.createTimeoutException(BaseCluster.java:370) 
    at com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:101) 
    at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.(ClusterBinding.java:75) 
    at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.(ClusterBinding.java:71) 
    at com.mongodb.binding.ClusterBinding.getWriteConnectionSource(ClusterBinding.java:68) 
    at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:175) 
    at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:106) 
    at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:58) 
    at com.mongodb.Mongo.execute(Mongo.java:747) 
    at com.mongodb.Mongo$2.execute(Mongo.java:730) 
    at com.mongodb.DBCollection.executeWriteOperation(DBCollection.java:327) 
    at com.mongodb.DBCollection.insert(DBCollection.java:323) 
    at com.mongodb.DBCollection.insert(DBCollection.java:314) 
    at com.mongodb.DBCollection.insert(DBCollection.java:284) 
    at com.mongodb.DBCollection.insert(DBCollection.java:250) 
    at com.mongodb.DBCollection.insert(DBCollection.java:187) 
    at InsertTest2.main(InsertTest2.java:26) 

3 개의 서버 주소가 모두 어떻게 나타나는지주의하십시오.이런 간단한 테스트 프로그램을 만들고 검증 한 다음 거기에서 뒤로 작업 할 것을 제안합니다. 또한 호스트 이름이 올바르게 해석되는지 확인하고 IP 주소를 시도 할 수도 있습니다.

+0

나는 그것을 시도 할 것이다. - 간단한 테스트를 만들고 거기에서 이동하십시오. 2 차가 1 차가 될 때가 아니라 모든 사용자에게 독립적으로 연결할 수 있으므로 호스트/IP 해상도가 아닙니다. 나는 나의 연결 문자열을 가지고있는 방식으로 뭔가 의심 스럽다. 어떤 난제를하면 나는 놀고 업데이트 할 것입니다. 마지막 옵션은 org.mongodb.driver.cluster에서 찾을 수 있으면 소스를 다운로드하는 것입니다. –