Mongodb
MongoDB Shard - 禁用游標超時
我正在使用帶有 java 應用程序的分片集群(Mongo 版本 2.4.1)。在特定時間(10 分鐘或更長時間)後,我得到以下異常:
com.mongodb.MongoException$Network: Read operation to server cs-mongo-mongo-west-t:3306 failed on database mdb at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:253) at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:216) at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:288) at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:273) at com.mongodb.DBCursor._check(DBCursor.java:368) at com.mongodb.DBCursor._hasNext(DBCursor.java:459) at com.mongodb.DBCursor._fill(DBCursor.java:518) at com.mongodb.DBCursor.toArray(DBCursor.java:553) at com.mongodb.DBCursor.toArray(DBCursor.java:542) at com.pribas.messagesdb.impl.GetMessagesDBHandlerImpl.handleRequest(GetMessagesDBHandlerImpl.java:86) at com.pribas.messagesdb.impl.MessagesDBHandlerImpl.handleRequest(MessagesDBHandlerImpl.java:37) at com.pribas.messagesdb.service.MessageServlet.processRequest(MessageServlet.java:161) at com.pribas.messagesdb.service.MessageServlet.doPost(MessageServlet.java:86) at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)
有沒有辦法在分片集群或配置文件中禁用游標超時?目前這個問題只能通過重新啟動應用程序來解決,這樣它就會建立一個新的連接。
非常感謝,丹尼爾
非活動游標有 10 分鐘的超時時間,它可以被覆蓋,但要小心:如果隨著時間的推移在伺服器上積累了足夠多的游標,“不朽”游標可能會成為問題。因此,最好不時正確地關閉游標並儘可能避免這種情況。您還應該確保實際上是游標超時在這裡傷害了您(而不是 TCP 超時)。
關閉超時的選項基本上涉及設置noTimeout 標誌。在 Java 中,這意味著
addOption
在游標上使用並設置QUERYOPTION_NOTIMEOUT
.