gpt4 book ai didi

java - 从 Spring 应用程序连接到 Cassandra 池的问题

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:35:30 26 4
gpt4 key购买 nike

我希望有人真的能够提供帮助,因为我目前一直在尝试使用 Cassandra ATM。

我的设置:对于开发,我有一个最小的 Cassandra 3.0.4 集群,它有两个节点(一个在我的工作机器上,一个在 VM 中)。通常只有本地的启动并运行。我使用最新的 Java 驱动程序版本 3.0.0 连接到池。

我的cassandra.yaml 包含rpc_addresslisten_address 到每个节点的IP。种子是我的主要工作机器。

我的问题:从 cqlsh(在任何时候)以及当两个节点都在运行时(从 Java),一切都运行良好。但是一旦我在 VM 中停止那个,我的基于 Spring 的应用程序就会在启动期间抛出错误:

2016-03-29 09:05:33.515 | INFO  | main                 | com.datastax.driver.core.NettyUtil                          :83    | Did not find Netty's native epoll transport in the classpath, defaulting to NIO.
2016-03-29 09:05:34.147 | INFO | main | com.datastax.driver.core.policies.DCAwareRoundRobinPolicy :95 | Using data-center name 'datacenter1' for DCAwareRoundRobinPolicy (if this is incorrect, please provide the correct datacenter name with DCAwareRoundRobinPolicy constructor)
2016-03-29 09:05:34.149 | INFO | main | com.datastax.driver.core.Cluster$Manager :1475 | New Cassandra host /10.20.30.74:9042 added
2016-03-29 09:05:34.149 | INFO | main | com.datastax.driver.core.Cluster$Manager :1475 | New Cassandra host /10.20.30.77:9042 added
2016-03-29 09:05:34.150 | INFO | main | my_company.cassandra.dao.impl.CassandraDaoImpl :55 | Connected to cluster: TestCaseCluster
2016-03-29 09:05:34.151 | INFO | main | my_company.cassandra.dao.impl.CassandraDaoImpl :57 | Datacenter: datacenter1; Host: /10.20.30.74; Rack: rack1, State: UP|true
2016-03-29 09:05:34.151 | INFO | main | my_company.cassandra.dao.impl.CassandraDaoImpl :57 | Datacenter: datacenter1; Host: /10.20.30.77; Rack: rack1, State: UP|true
2016-03-29 09:05:34.220 | WARN | luster1-nio-worker-2 | com.datastax.driver.core.SessionManager$7 :378 | Error creating pool to /10.20.30.77:9042
com.datastax.driver.core.exceptions.ConnectionException: [/10.20.30.77] Pool was closed during initialization
at com.datastax.driver.core.HostConnectionPool$2.onSuccess(HostConnectionPool.java:149) [cassandra-driver-core-3.0.0.jar:?]
at com.datastax.driver.core.HostConnectionPool$2.onSuccess(HostConnectionPool.java:135) [cassandra-driver-core-3.0.0.jar:?]
at com.google.common.util.concurrent.Futures$4.run(Futures.java:1181) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:297) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.ExecutionList.executeListener(ExecutionList.java:156) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.ExecutionList.execute(ExecutionList.java:145) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:185) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.Futures$CombinedFuture.setOneValue(Futures.java:1626) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.Futures$CombinedFuture.access$400(Futures.java:1470) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.Futures$CombinedFuture$2.run(Futures.java:1548) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:297) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.ExecutionList.executeListener(ExecutionList.java:156) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.ExecutionList.execute(ExecutionList.java:145) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:185) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.Futures$FallbackFuture$1$1.onSuccess(Futures.java:475) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.Futures$4.run(Futures.java:1181) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:297) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.Futures$ImmediateFuture.addListener(Futures.java:102) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.Futures.addCallback(Futures.java:1184) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.Futures$FallbackFuture$1.onFailure(Futures.java:472) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.Futures$4.run(Futures.java:1172) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:297) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.ExecutionList.executeListener(ExecutionList.java:156) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.ExecutionList.execute(ExecutionList.java:145) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:202) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.Futures$FallbackFuture$1$1.onFailure(Futures.java:483) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.Futures$4.run(Futures.java:1172) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:297) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.ExecutionList.executeListener(ExecutionList.java:156) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.ExecutionList.add(ExecutionList.java:101) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.AbstractFuture.addListener(AbstractFuture.java:170) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.Futures.addCallback(Futures.java:1184) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.Futures$FallbackFuture$1.onFailure(Futures.java:472) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.Futures$4.run(Futures.java:1172) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:297) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.ExecutionList.executeListener(ExecutionList.java:156) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.ExecutionList.execute(ExecutionList.java:145) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:202) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.Futures$ChainingListenableFuture.run(Futures.java:857) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:297) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.ExecutionList.executeListener(ExecutionList.java:156) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.ExecutionList.execute(ExecutionList.java:145) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:202) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.SettableFuture.setException(SettableFuture.java:68) [guava-16.0.1.jar:?]
at com.datastax.driver.core.Connection$1.operationComplete(Connection.java:157) [cassandra-driver-core-3.0.0.jar:?]
at com.datastax.driver.core.Connection$1.operationComplete(Connection.java:140) [cassandra-driver-core-3.0.0.jar:?]
at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:680) [netty-common-4.0.33.Final.jar:4.0.33.Final]
at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:603) [netty-common-4.0.33.Final.jar:4.0.33.Final]
at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:563) [netty-common-4.0.33.Final.jar:4.0.33.Final]
at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:424) [netty-common-4.0.33.Final.jar:4.0.33.Final]
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.fulfillConnectPromise(AbstractNioChannel.java:276) [netty-transport-4.0.33.Final.jar:4.0.33.Final]
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:292) [netty-transport-4.0.33.Final.jar:4.0.33.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:528) [netty-transport-4.0.33.Final.jar:4.0.33.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468) [netty-transport-4.0.33.Final.jar:4.0.33.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382) [netty-transport-4.0.33.Final.jar:4.0.33.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354) [netty-transport-4.0.33.Final.jar:4.0.33.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112) [netty-common-4.0.33.Final.jar:4.0.33.Final]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_74]

在这个例子中,我发现下面一行很有趣:

Datacenter: datacenter1; Host: /10.20.30.77; Rack: rack1, State: UP|true

因为这是提到的 VM,所以它实际上已关闭:

Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
DN 10.20.30.77 89.12 KB 256 100.0% 197f6f0f-b820-4ab8-b7ef-bcc8773a345c rack1
UN 10.20.30.74 96.26 KB 256 100.0% db7d053b-f8d1-4a59-9cb2-3abf54b24687 rack1

根据 nodetools status 的摘录,DN 应该表示“关闭”和“正常”。据我所知,Java 驱动程序不会将第二个节点识别为已关闭,但仍会尝试连接到它,因为它在(可用)节点列表中。

因为驱动程序版本和 Cassandra 版本的组合,这是一个不兼容问题吗?但我认为,它们是兼容的: DataStax Java-Driver documentation on GitHub

如果您需要更多信息,请询问。我将相应地更新此文本。

感谢和问候。

丹尼尔

edit1:我已经用复制类 SimpleStrategy 和因子 3 初始化了一个 Keyspace - 我读到一些,该数字不应超过节点数(我猜它在文档中的某个地方,但是我没有链接了)...这是一个原因吗?

最佳答案

可惜,这种问题好像没人知道。经过几次尝试和在 Internet 上搜索(在这个特定问题上我几乎找不到任何东西)之后,我几乎放弃了这个想法。

但是。

然后有两件事引起了我的注意:

  1. 我的测试键空间的复制因子是 3,而我只有两个节点。不是很明智。
  2. 如果我仔细查看异常,就会发现这是一个警告,而不是 fatal error 。

那又怎样?

我仍然能够连接到集群并实际查询它,但总是因为这个异常而过早放弃。

几乎“无事生非”

到目前为止一切正常,我可以进一步开发我的应用程序。以及了解很多关于这种高可用性 NoSQL 数据库的知识,以及它与“经典”关系数据库的不同之处,即使查询语言有很多相似之处。非常精彩!

所以:抱歉打扰了!

干杯,丹尼尔

关于java - 从 Spring 应用程序连接到 Cassandra 池的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36278321/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com