Spring数据支持和mongodb出现无休止的复制集连接错误

发布于 2024-11-07 20:17:13 字数 1780 浏览 0 评论 0原文

我正在使用带有副本集的 mongodb 的应用程序。

在我的复制集中,我有 2 个数据库服务器和 1 个仲裁器。我正在创建我的 mongo 对象,如下所示

List<ServerAddress> servers = new ArrayList<ServerAddress>();
servers.add( new ServerAddress( "192.168.1.42", 27017 ) );
servers.add( new ServerAddress( "192.168.1.187", 27017 ) );
servers.add( new ServerAddress( "192.168.1.189", 27017 ) ); //Arbiter

MongoOptions mongoOptions = new MongoOptions();
mongoOptions.autoConnectRetry = true;
mongo = new Mongo(servers, mongoOptions);
mongo.slaveOk();

当所有服务器都启动时,就没有问题了,但是当任何一台服务器出现故障时,系统就会开始出现如下所示的无尽错误消息,

May 17, 2011 11:24:19 AM com.mongodb.ReplicaSetStatus$Node update
SEVERE: can't update node: 192.168.1.42:27017
java.io.IOException: couldn't connect to [/192.168.1.42:27017] bc:java.net.ConnectException: Connection refused: connect
    at com.mongodb.DBPort._open(DBPort.java:206)
    at com.mongodb.DBPort.go(DBPort.java:94)
    at com.mongodb.DBPort.go(DBPort.java:75)
    at com.mongodb.DBPort.findOne(DBPort.java:129)
    at com.mongodb.DBPort.runCommand(DBPort.java:138)
    at com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:149)
    at com.mongodb.ReplicaSetStatus.updateAll(ReplicaSetStatus.java:314)
    at com.mongodb.ReplicaSetStatus$Updater.run(ReplicaSetStatus.java:263)

您能帮我解决这个问题吗?

由于我使用的是副本集,如果一台服务器关闭,是否应该使用新的主服务器并忽略旧的主服务器?

请通过下图查看副本集状态

所有服务器均已启动,192.168.1.42为主服务器 在此处输入图像描述

192.168.1.42 已关闭(手动终止),192.168.1.187 是新的主节点(现在发生错误) 在此处输入图像描述

192.168.1.42 再次启动并充当辅助服务器(错误消失) 在此处输入图像描述

更新: 即使记录了错误消息,数据库也能正常工作。是否有一种机制可以减少/抑制错误消息?

I'm working in a apps where I'm using mongodb with replicaset.

In my replicaset I've 2 db servers and 1 arbiter. I'm creating my mongo object as follows

List<ServerAddress> servers = new ArrayList<ServerAddress>();
servers.add( new ServerAddress( "192.168.1.42", 27017 ) );
servers.add( new ServerAddress( "192.168.1.187", 27017 ) );
servers.add( new ServerAddress( "192.168.1.189", 27017 ) ); //Arbiter

MongoOptions mongoOptions = new MongoOptions();
mongoOptions.autoConnectRetry = true;
mongo = new Mongo(servers, mongoOptions);
mongo.slaveOk();

When all the servers are up then there are no problems but when any one of the server goes down the system starts to through endless error messages as shown below

May 17, 2011 11:24:19 AM com.mongodb.ReplicaSetStatus$Node update
SEVERE: can't update node: 192.168.1.42:27017
java.io.IOException: couldn't connect to [/192.168.1.42:27017] bc:java.net.ConnectException: Connection refused: connect
    at com.mongodb.DBPort._open(DBPort.java:206)
    at com.mongodb.DBPort.go(DBPort.java:94)
    at com.mongodb.DBPort.go(DBPort.java:75)
    at com.mongodb.DBPort.findOne(DBPort.java:129)
    at com.mongodb.DBPort.runCommand(DBPort.java:138)
    at com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:149)
    at com.mongodb.ReplicaSetStatus.updateAll(ReplicaSetStatus.java:314)
    at com.mongodb.ReplicaSetStatus$Updater.run(ReplicaSetStatus.java:263)

Can you help me to resolve this?

Since I'm using a replica set, if one server is down isn't suppose to use the new primary and ignore the older primary?

Please find the below images to check the replica set status

All servers up and 192.168.1.42 is the primary server
enter image description here

192.168.1.42 is down(manually teminated) and 192.168.1.187 is the new primary(The errors happens now)
enter image description here

192.168.1.42 is up again and actings as a secondary server(error goes off)
enter image description here

UPDATED:
The database works even if the error messages get logged. Is there a mechanism to reduce/suppress the error messages?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

这是一个日志记录问题。现在它是一个警告,而不是一个错误。

2.6 驱动程序(将于本周晚些时候发布)的日志记录将不再那么冗长。这不是一个错误,而只是一个警告,表明当后台线程检查复制集成员的状态时该节点已关闭。如果您想立即测试,可以使用 master 中的当前版本: http://github.com/ mongodb/mongo-java-driver

http://github.com/ mongodb/mongo-java-driver/commit/ee7543a4f7cc26618cf78eab2a18bd33b3e101cc

This is a logging issue. It is now a warning, instead of an error.

The 2.6 driver (due out later this week) will be less verbose with logging for this. This is not an error but just a warning that that node is down when the background thread checks on the status of the replicaset members. You can use the current version in master if you want to test now: http://github.com/mongodb/mongo-java-driver

http://github.com/mongodb/mongo-java-driver/commit/ee7543a4f7cc26618cf78eab2a18bd33b3e101cc

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文