Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

leemz avatar image
leemz asked Erick Ramirez commented

关于datastax java驱动的问题

我有一个三节点的集群,在同一个机架和数据中心内。第一台和第二台为种子节点,第三台为普通节点,我现在使用datastax-java的驱动想测试一种场景,多线程持续写入,在写入过程中突然停掉其中一台服务,模拟运行中的异常情况。

我使用如下的代码进行配置三个联系点,三台机器IP不同,端口相同

.addContactPoint(new InetSocketAddress(host1, port))
.addContactPoint(new InetSocketAddress(host2, port))
.addContactPoint(new InetSocketAddress(host3, port))

但是当我测试的时候,只要我停掉其中一个节点,程序就会报错,连接被重置。程序被挂起。无法继续执行了。我理解的cassandra不是分布式的吗?我三台节点,挂掉其中一个应该还有两个可以正常服务的,为什么程序会报错挂起无法运行了呢?请问我该怎么配置客户端才能实现某一节点挂掉不影响程序正常运行呢

java driver
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered Erick Ramirez commented

The "connection reset" error is expected since the Java driver opens a single connection to all nodes in the DC. However, it isn't normal for the application to hang.

If you provide the full error message and full stack trace, it will provide us clues on what is going on with the driver. Cheers!

2 comments Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

抱歉,是我没说清楚,程序挂起是因为我测试程序写的不规范,没有做try catch处理,导致出了异常后session未关闭。至于一个节点宕机无法自动切换可用节点的原因我也找到了,因为我使用了CqlSession去执行cql字符串语句,没有使用驱动的构建器,所以导致驱动程序内部获取这个查询是否是幂等时获取到的结果为null,被判定为非幂等操作。我看驱动文档有解释:非幂等操作是不会自动寻找可用节点重试的。之后我使用构建器的驱动包,用构建器来构建要执行的Cql语句,我也打印了是否幂等的返回值。当使用构建器后,是否幂等返回了true,这时停掉一个节点程序不会报错是会继续执行的。

谢谢您!

0 Likes 0 ·
I'm glad to hear that you figured it out. Well done!
0 Likes 0 ·