Astyanax不尊重配置的套接字超时

时间:2016-08-08 09:04:55

标签: java cassandra timeout astyanax

这是我的设置:

  • 4个节点Cassandra 1.2.19
  • Astyanax 1.56.49

我正在设置类似

的配置
AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
    .forCluster(service.getClusterName())
    .forKeyspace(service.getKeySpaceName())
    .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
         .setDiscoveryType(NodeDiscoveryType.NONE)
         .setCqlVersion("3.0.0")
         .setDefaultReadConsistencyLevel(consistencyLevel.getAstyanaxValue())
         .setDefaultWriteConsistencyLevel(consistencyLevel.getAstyanaxValue())
    )
    .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("b2bConnectionPool")
         .setPort(service.getPort())
         .setMaxConnsPerHost(5)
         .setSeeds(StringUtils.join(hosts, ","))
         // increase default timeout for heavy operations (milliseconds)
         .setSocketTimeout(15000)
         .setSSLConnectionContext(sslContext)
         .setAuthenticationCredentials(credentials)
    )
    .withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
    .buildKeyspace(ThriftFamilyFactory.getInstance());

现在有一个可重现的查询需要很长时间才会抛出OperationTimeoutException

com.netflix.astyanax.connectionpool.exceptions.OperationTimeoutException: OperationTimeoutException: [host=myhost(myip):13260, latency=10001(40007), attempts=4]TimedOutException()
    at com.netflix.astyanax.thrift.ThriftConverter.ToConnectionPoolException(ThriftConverter.java:171) ~[astyanax-thrift-1.56.49.jar:na]
    at com.netflix.astyanax.thrift.AbstractOperationImpl.execute(AbstractOperationImpl.java:65) ~[astyanax-thrift-1.56.49.jar:na]
    at com.netflix.astyanax.thrift.ThriftColumnFamilyQueryImpl$1$2.execute(ThriftColumnFamilyQueryImpl.java:190) ~[astyanax-thrift-1.56.49.jar:na]
    at com.netflix.astyanax.thrift.ThriftColumnFamilyQueryImpl$1$2.execute(ThriftColumnFamilyQueryImpl.java:182) ~[astyanax-thrift-1.56.49.jar:na]
    at com.netflix.astyanax.thrift.ThriftSyncConnectionFactoryImpl$ThriftConnection.execute(ThriftSyncConnectionFactoryImpl.java:151) ~[astyanax-thrift-1.56.49.jar:na]
    at com.netflix.astyanax.connectionpool.impl.AbstractExecuteWithFailoverImpl.tryOperation(AbstractExecuteWithFailoverImpl.java:119) ~[astyanax-core-1.56.49.jar:na]
    at com.netflix.astyanax.connectionpool.impl.AbstractHostPartitionConnectionPool.executeWithFailover(AbstractHostPartitionConnectionPool.java:338) ~[astyanax-core-1.56.49.jar:na]
    at com.netflix.astyanax.thrift.ThriftColumnFamilyQueryImpl$1.execute(ThriftColumnFamilyQueryImpl.java:180) ~[astyanax-thrift-1.56.49.jar:na]

异常消息显示“latency = 10001”,我认为这应该是配置为15000 ms的套接字超时,但显然不是。如何在astyanax中增加查询操作的超时?

2 个答案:

答案 0 :(得分:1)

我相信你没有遇到套接字超时,而是我认为无法通过Astyanax控制的rpc超时。在堆栈跟踪中,OperationTimeoutException内包含的异常是TimedOutException,当发生rpc超时时(默认为10秒),该异常将被抛出。如果套接字超时,将抛出SocketTimeoutException

尝试使用cqlsh执行查询,您将收到Request did not complete within rpc_timeout消息。

<cassandra_home>/conf/cassandra.yaml尝试设置中:

read_request_timeout_in_ms: 20000
rpc_timeout_in_ms: 20000

重新启动服务器并再次尝试执行查询。

答案 1 :(得分:1)

在尝试查询具有更大数据的节点时,我遇到了类似的超时异常。我在cassandra.yaml中修改了这4个值,它解决了所有超时错误。

协调员应等待读取操作完成的时间 read_request_timeout_in_ms:15000

协调员应等待seq或索引扫描完成的时间 range_request_timeout_in_ms:30000

协调员应等待写入完成的时间 write_request_timeout_in_ms:30000

协调员应等待计数器写入完成的时间 counter_write_request_timeout_in_ms:15000

注意:您需要在群集中的所有节点中执行此操作,并且还需要在所有节点中重新启动Cassandra。