简体   繁体   English

告诉Datastax Java Cassandra驱动程序超时集群连接

[英]Tell Datastax Java Cassandra driver to timeout cluster connection

How do you tell the Datastax Java Cassandra driver to time-out when it attempts to connect to your cluster? 在尝试连接到群集时,如何告诉Datastax Java Cassandra驱动程序超时?

I'm particularly interested in the case when the hosts are reachable, but the Cassandra ports are blocked or the Cassandra daemons are not running. 我对主机可以访问的情况特别感兴趣,但是Cassandra端口被阻塞或者Cassandra守护进程没有运行。 I'm writing a command-line client that ought to exit and report a suitable error message if it can not connect in a reasonable time. 我正在编写一个命令行客户端,如果它无法在合理的时间内连接,它应该退出并报告合适的错误消息。 At present it seems that the driver will wait forever for a contact point to response, if the contact point is reachable. 目前看来,如果联系点可以到达,驱动程序将永远等待接触点响应。

That is, I want Cluster.build() to throw a NoHostAvailableException if the driver can not communicate with the Cassandra daemon of any of the contact points within a given maximum time. 也就是说,如果驱动程序无法在给定的最大时间内与任何联系点的Cassandra守护进程通信,我希望Cluster.build()抛出NoHostAvailableException

  • Creating my own RetryPolicy won't work: that is for retrying queries, and I want the timeout to apply before we are ready to run queries. 创建我自己的RetryPolicy将不起作用:那是为了重试查询,我希望我们准备运行查询之前应用超时。
  • Creating my own ReconnectinoPolicy initially looked promising, but the contract for the interface gives no means for indicating "consider this node to be dead forever more" 创建我自己的ReconnectinoPolicy最初看起来很有希望,但是接口的合同没有办法表明“认为这个节点永远死了”

That is, I want Cluster.build() to throw a NoHostAvailableException if the driver can not communicate with the Cassandra daemon of any of the contact points within a given maximum time. 也就是说,如果驱动程序无法在给定的最大时间内与任何联系点的Cassandra守护进程通信,我希望Cluster.build()抛出NoHostAvailableException。

This is supposed to be the case. 应该是这种情况。 The driver will try to connect to each of the contact points and throw an exception if it fails to connect to any. 驱动程序将尝试连接到每个联系点,如果无法连接到任何联系点,则抛出异常。 You can control the maximum time the driver will try connecting (to each node) through SocketOptions.setConnectTimeoutMillis() (the default is 5 seconds). 您可以通过SocketOptions.setConnectTimeoutMillis()控制驱动程序尝试连接(到每个节点)的最长时间(默认值为5秒)。

My experience is that Cluster.build() does return an exception if no node can be connected to, but if your experience differs, you might want to report it as a bug (but a bit more detail on how you reproduce this would help). 我的经验是,如果没有节点可以连接,Cluster.build()确实会返回异常,但如果您的体验不同,您可能希望将其报告为错误(但有关如何重现这一点的更多细节会有所帮助) 。

That being said: 话虽如此:

  • The timeout above is per host. 上面的超时是每个主机。 So if you pass a list of 100 contact points, you could in theory have to wait 500 seconds (by default) before getting the NoHostAvailableException. 因此,如果您传递100个联系点的列表,理论上您必须等待500秒(默认情况下)才能获得NoHostAvailableException。 But there is no real point in providing that many contact points, and in practice, if Cassandra is not running on the node tried, the connection attempt will usually fail right away (you won't wait the timeout). 但是提供那么多接触点没有任何意义,实际上,如果Cassandra没有在尝试的节点上运行,连接尝试通常会立即失败(你不会等待超时)。
  • There is currently no real query timeout on the driver side. 目前在驱动程序端没有真正的查询超时。 Which mean that if the driver does connect to a node (which means that some process is listening on that port and accept the connection), but get no answer to his initial messages, then it can indeed hold forever. 这意味着如果驱动程序确实连接到一个节点(这意味着某些进程正在侦听该端口并接受连接),但是没有得到他的初始消息的答案,那么它确实可以永久保留。 That should probably be fixed, and I encourage you to open a ticket for that on https://datastax-oss.atlassian.net/browse/JAVA . 这应该是固定的,我鼓励你在https://datastax-oss.atlassian.net/browse/JAVA上打开一张票。 However, this doesn't seem to be the case you are describing, since if "Cassandra ports are blocked or the Cassandra daemons are not running" then the driver shouldn't be able to connect in the first place. 但是,这似乎不是您所描述的情况,因为如果“Cassandra端口被阻止或Cassandra守护程序未运行”,则驱动程序应该无法首先连接。

暂无
暂无

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

相关问题 java cassandra connection java.lang.ClassNotFoundException:com.datastax.driver.core.Cluster - java cassandra connection java.lang.ClassNotFoundException: com.datastax.driver.core.Cluster Cassandra Datastax驱动程序 - 连接池 - Cassandra Datastax Driver - Connection Pool cassandra datastax 驱动程序抛出的写入超时 - Write timeout thrown by cassandra datastax driver Cassandra-com.datastax.driver.core.exceptions.DriverException:尝试获取可用连接时超时 - Cassandra - com.datastax.driver.core.exceptions.DriverException: Timeout while trying to acquire available connection NoHostAvailableException使用Cassandra和DataStax Java驱动程序如果是大ResultSet - NoHostAvailableException With Cassandra & DataStax Java Driver If Large ResultSet 带分页的Datastax Cassandra Java驱动程序RetryPolicy - Datastax Cassandra java driver RetryPolicy for Statement with paging 绑定Java datastax驱动程序中的cassandra多列 - cassandra multi column in binding java datastax driver Cassandra对象使用Datastax Java驱动程序映射注释 - Cassandra object mapping annotations with Datastax Java driver Datastax Java驱动程序关闭前一个主机后,Cassandra重新连接尝试下一个主机 - Cassandra Re-Connection attempt to next host after previous host is down by Datastax Java Driver 如何使用Datastax Java驱动程序在属性文件中提供Cassandra的连接详细信息 - How to give connection details for cassandra in properties file using datastax java driver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM