MongoDB 提示 None of the hosts for replica set could be contacted

MongoDB About 2,708 words

错误信息

发生错误是在MongoDB3.2.8版本分片部署模式下。查询时得到错误码71,可能当时正在做大批量删除历史数据操作,出现了以下错误。(笔者的分片副本集名称为shard2

mongos shell中的异常。

{
    "code" : 71,
    "ok" : 0,
    "errmsg" : "None of the hosts for replica set shard2 could be contacted."
}

Java客户端中的异常。

org.springframework.data.mongodb.UncategorizedMongoDbException: None of the hosts for replica set shard2 could be contacted.; nested exception is com.mongodb.MongoException: None of the hosts for replica set shard2 could be contacted.
    at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:107)
    at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2128)
    at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1963)
    at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1769)
    at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1752)
    at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:621)
    at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:612)
    at com.wostore.flow.ssp.job.TaskQueueGenCenter.scanExecutingTask(TaskQueueGenCenter.java:219)
    at sun.reflect.GeneratedMethodAccessor130.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

错误原因

mongos无法从config service副本集获得对所有节点的网络连接

影响版本

MongoDB3.2.03.2.9

解决办法

临时方案

重启mongosmongod。(笔者是重启mongos后服务恢复正常)

升级方案

升级MongoDB3.4.0或者3.2.10

MongoDB 3.2.10中,可在所有mongosmongod节点执行以下命令。注意:这个参数不会被持久化,如果MongoDB实例重启了必须重新执行该命令。

db.adminCommand( {setParameter: 1, 'replMonitorMaxFailedChecks': 2147483647} )

参考

https://jira.mongodb.org/browse/SERVER-22971

Views: 3,975 · Posted: 2020-09-28

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh