gpt4 book ai didi

java - MongoCursorNotFoundException - 查询失败,错误代码 -5

转载 作者:行者123 更新时间:2023-12-04 12:04:03 25 4
gpt4 key购买 nike

我们收到以下异常。

com.mongodb.MongoCursorNotFoundException: Query failed with error code -5 and error message 'Cursor 43249415092 not found on server xx.xx.xx.xx:27017' 
at com.mongodb.connection.GetMoreProtocol.receiveMessage(GetMoreProtocol.java:115)
at com.mongodb.connection.GetMoreProtocol.execute(GetMoreProtocol.java:68)
at com.mongodb.connection.GetMoreProtocol.execute(GetMoreProtocol.java:37)
at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:155)
at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:219)
at com.mongodb.connection.DefaultServerConnection.getMore(DefaultServerConnection.java:194)
at com.mongodb.operation.QueryBatchCursor.getMore(QueryBatchCursor.java:197)
at com.mongodb.operation.QueryBatchCursor.hasNext(QueryBatchCursor.java:93)
at com.mongodb.MongoBatchCursorAdapter.hasNext(MongoBatchCursorAdapter.java:46)
at com.mongodb.DBCursor.hasNext(DBCursor.java:152)

我们无法找到根本原因,因为我们很少收到此异常。

We also observed that the application is unable to read from cursor but no exception is thrown.



在没有抛出异常的情况下,我们进行了线程转储,发现从 mongo 读取的线程处于 RUNNABLE 状态。
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at com.mongodb.connection.SocketStream.read(SocketStream.java:85)
at com.mongodb.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:503)
at com.mongodb.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:221)
at com.mongodb.connection.UsageTrackingInternalConnection.receiveMessage(UsageTrackingInternalConnection.java:102)
at com.mongodb.connection.DefaultConnectionPool$PooledConnection.receiveMessage(DefaultConnectionPool.java:416)
at com.mongodb.connection.GetMoreProtocol.receiveMessage(GetMoreProtocol.java:112)
at com.mongodb.connection.GetMoreProtocol.execute(GetMoreProtocol.java:68)
at com.mongodb.connection.GetMoreProtocol.execute(GetMoreProtocol.java:37)
at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:155)
at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:219)
at com.mongodb.connection.DefaultServerConnection.getMore(DefaultServerConnection.java:194)
at com.mongodb.operation.QueryBatchCursor.getMore(QueryBatchCursor.java:197)
at com.mongodb.operation.QueryBatchCursor.hasNext(QueryBatchCursor.java:93)
at com.mongodb.MongoBatchCursorAdapter.hasNext(MongoBatchCursorAdapter.java:46)
at com.mongodb.DBCursor.hasNext(DBCursor.java:152)

请帮我找到这个问题的根本原因?

最佳答案

最近,我遇到了同样的问题。经过长时间的研究,我想通了。在我的场景中,我有 4 个 mongos,它们在负载平衡之后(随机返回 mongos IP 地址)。在我的连接字符串中,我使用负载均衡主机作为 mongoDB 集群的地址。
当应用程序启动时,mongoDB 驱动程序会创建一个 server带连接池。在连接池中,有来自 4 个 mongos 的混合连接。
当你查询一个大数据(比batchSize大)时,第一批数据来自mongos A,然后当下面的批请求被push时,连接 5 月 连接到 mongos B/C 或 D( source code )。他们当然找不到光标。所以,MongoCursorNotFoundException被抛出。
如何处理?
不要在连接字符串中使用 balance host。改用所有 mongos IP 地址。让 mongoDB 驱动自己来平衡请求。
错误 :mongodb://your.load.balance.host:27000/yourDB?connectTimeoutMS=60000&minPoolSize=100&maxPoolSize=100&waitqueuemultiple=20&waitqueuetimeoutms=60000 :mongodb://10.0.0.1:27017,10.0.0.2:27017,10.0.0.3:27017,10.0.0.4:27017/yourDB?connectTimeoutMS=60000&minPoolSize=100&maxPoolSize=100&waitqueuemultiple=20&waitqueuetimeoutms=60000有一个更好的解决方案:可以为每个mongos配置一个唯一的专用主机,然后修改连接字符串:用此主机替换 IP 地址。

关于java - MongoCursorNotFoundException - 查询失败,错误代码 -5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40785686/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com