简体   繁体   English

从Datastax Cassandra Java驱动程序获取“对断开的连接进行写入尝试”错误

[英]Getting “Write attempt on defunct connection” Error From Datastax Cassandra Java Driver

I have a web service application using Cassandra 2.0 and Datastax java driver 2.0.2. 我有一个使用Cassandra 2.0和Datastax Java驱动程序2.0.2的Web服务应用程序。 I sometimes get the stacktrace below when trying to write to/read from database, especially if the application has been sitting there for a while (like overnight). 在尝试写入数据库或从数据库读取数据时,有时会出现下面的stacktrace,特别是如果应用程序已经坐在那里一段时间(如通宵)。 This error usually goes away when I retry, however, sometimes it persists and I have to restart the web app to get rid of the error. 当我重试时,此错误通常会消失,但是有时它仍然存在,因此我必须重新启动Web应用程序才能消除该错误。

I wonder if this is some sort of "stale connection" issue. 我不知道这是否是某种“过时的连接”问题。 However, the Datastax java driver documentation indicates it is supposed to keep the connection alive. 但是,Datastax Java驱动程序文档指出应保持连接处于活动状态。

I did a google search on the error message and only two (!) hits were given by google. 我对错误消息进行了Google搜索,并且Google仅给出了两个(!)命中。 They are related. 它们是相关的。 This is the answer in one of the google result: 这是google结果之一的答案:

Sylvain Lebresne Apr 2 You're running into https://datastax-oss.atlassian.net/browse/JAVA-250 . Sylvain Lebresne 4月2日,您正在进入https://datastax-oss.atlassian.net/browse/JAVA-250 We'll fix it soon hopefully (I have some half-finished patch that I need to finish), but currently, if you restart a whole cluster without doing queries during the restat, it can sometimes happen that you'll get this before the cluster properly reconnect. 希望我们会尽快修复它(我需要完成一些补丁),但是目前,如果您重新启动整个集群,而在还原过程中没有执行查询,则有时可能会在群集正确重新连接。 In the meantime and as a workaround, you can always make sure to run a few trivial queries while you're doing the cluster restart to avoid it. 在此期间,作为一种变通办法,您始终可以确保在重新启动群集时避免运行一些琐碎的查询,以避免这种情况。

However this does not look like my scenario because we are not restarting the cluster at all. 但是,这看起来不像我的情况,因为我们根本没有重新启动集群。 I wonder if anyone has some insights about this error? 我想知道是否有人对此错误有见解?

Stacktrace: 堆栈跟踪:

com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: ec2-54-197-xxx-xxx.compute-1.amazonaws.com/54.197.xxx.xxx:9042 (com.datastax.driver.core.ConnectionException: [ec2-54-197-xxx-xxx.compute-1.amazonaws.com/54.197.xxx.xxx:9042] Write attempt on defunct connection))
at com.datastax.driver.core.exceptions.NoHostAvailableException.copy(NoHostAvailableException.java:65)
at com.datastax.driver.core.DefaultResultSetFuture.extractCauseFromExecutionException(DefaultResultSetFuture.java:256)
at com.datastax.driver.core.DefaultResultSetFuture.getUninterruptibly(DefaultResultSetFuture.java:172)
at com.datastax.driver.core.SessionManager.execute(SessionManager.java:92)

I have what I believe is the exact same issue (Write attempt on defunct connection) on my development machine intermittently. 我有间歇性地在开发机器上遇到完全相同的问题(在无效连接上写尝试)。

It seems to happen when my dev machine goes to sleep while the server is up. 当服务器启动时我的开发机进入睡眠状态时,似乎发生了这种情况。 Obviously there's no power management in the AWS cluster you're running, but it gives you a hint - the key is that something is breaking your control connection or intermittently preventing network connectivity between your hosts. 显然,您正在运行的AWS集群中没有电源管理,但它可以为您提供提示-关键是某些东西中断了您的控制连接或间歇性地阻止了主机之间的网络连接。

You should see the reconnection thread in your logs: 21:34:51.616 [Reconnection-1] ERROR cddriver.core.ControlConnection - [Control connection] Cannot connect to any host, scheduling retry in 2000 milliseconds 您应该在日志中看到重新连接线程:21:34:51.616 [Reconnection-1]错误cddriver.core.ControlConnection-[Control connection]无法连接到任何主机,计划在2000毫秒内重试

The next request after this will always succeed in my experience. 根据我的经验,此后的下一个请求将永远成功。

TL; TL; DR - check for networking issues or any intermittent shutdown of servers that could break the control connection. DR-检查网络问题或服务器的任何间歇性关闭(可能会断开控制连接)。 The driver should do a better job of re-establishing broken control connections, sounds like they're working on it for JAVA-250 驱动程序应该做得更好,以重新建立断开的控制连接,听起来他们正在为JAVA-250进行操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM