简体   繁体   English

Cassandra Java驱动程序连接错误

[英]Cassandra java driver connection error

TL;DR - So i'm having a connection issues from DataStax java cassandra driver to a DataStax cassandra cluster. TL; DR-所以我遇到了从DataStax Java cassandra驱动程序到DataStax cassandra群集的连接问题。 It initially connects and performs well, then suddenly at some point it looses connection and does not reconnect - at this point all the queries fail. 它最初连接并运行良好,然后突然在某个点上失去了连接并且没有重新连接-此时所有查询都失败了。

More info - 更多信息 -

So i'm running DataStax cassandra 2.1 cluster of 3 nodes on CentOS, I'm using DataStax cassandra driver 3.0.0. 所以我在CentOS上运行3个节点的DataStax cassandra 2.1集群,我在使用DataStax cassandra驱动程序3.0.0。 Everything worked great in the past few months, recently iv'e deployed a some code changes that included some schema changes (namely, adding columns to an existing table) and an increase in the number of queries made. 在过去的几个月中,一切工作都很好,最近我进行了一些代码更改,其中包括一些架构更改(即向现有表中添加列),并增加了查询数量。 Disconnections started at this point. 此时断开连接。

So when my app goes up it connects to the cluster and holds a single cluster (and session) object as shown in the code snippet below, at this point everything goes well. 因此,当我的应用启动时,它连接到集群并持有一个集群(和会话)对象,如下面的代码片段所示,此时一切正常。 After a few hours i start receiving NoHostAvailableException for every query performed. 几个小时后,我开始为执行的每个查询接收NoHostAvailableException At this point i have other servers performing well with the same cassandra cluster so i know there's nothing wrong with the cluster itself. 在这一点上,我有其他服务器在相同的cassandra群集上运行良好,因此我知道群集本身没有任何问题。 When i restart my server everything works good again. 重新启动服务器后,一切恢复正常。

After investigating a little more, when the issue start occurring, i see that there's no active connection to neither node. 经过更多调查后,当问题开始发生时,我看到两个节点都没有活动连接。 Iv'e set up the driver to log on DEBUG level into a dedicated log file and waited for the issue to reoccur. 设置驱动程序以将DEBUG级别登录到专用日志文件中,然后等待问题再次发生。 A few hours later the issue occurred again, at some point the log file shows this message: 几个小时后,问题再次发生,日志文件有时显示以下消息:

Connection[/10.4.116.91:9042-1, inFlight=2, closed=false] connection error
io.netty.handler.codec.DecoderException: com.datastax.driver.core.exceptions.DriverInternalError: Adjusted frame length exceeds 268435456: 326843398 - discarded
        at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:418)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:245)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:292)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:278)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:962)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:528)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:485)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:399)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:371)
        at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
        at java.lang.Thread.run(Thread.java:745)
Caused by: com.datastax.driver.core.exceptions.DriverInternalError: Adjusted frame length exceeds 268435456: 326843398 - discarded
        at com.datastax.driver.core.Frame$Decoder$DecoderForStreamIdSize.decode(Frame.java:239)
        at com.datastax.driver.core.Frame$Decoder.decode(Frame.java:205)
        at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:387)
        ... 11 common frames omitted

And right after that you see this: 然后,您会看到以下内容:

Connection[/10.4.116.91:9042-1, inFlight=2, closed=false] connection error
io.netty.handler.codec.DecoderException: com.datastax.driver.core.exceptions.DriverInternalError: Adjusted frame length exceeds 268435456: 326843398 - discarded
        at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:418)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:245)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:292)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:278)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:962)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:528)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:485)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:399)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:371)
        at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
        at java.lang.Thread.run(Thread.java:745)
Caused by: com.datastax.driver.core.exceptions.DriverInternalError: Adjusted frame length exceeds 268435456: 326843398 - discarded
        at com.datastax.driver.core.Frame$Decoder$DecoderForStreamIdSize.decode(Frame.java:239)
        at com.datastax.driver.core.Frame$Decoder.decode(Frame.java:205)
        at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:387)
        ... 11 common frames omitted

From this point on you see only timeouts and retries but the connection doesn't get reestablished. 从这一点开始,您只会看到超时和重试,但不会重新建立连接。

// CREATION OF CASSANDRA SESSION
PoolingOptions poolingOptions = new PoolingOptions();
poolingOptions
    .setPoolTimeoutMillis(0)
    .setMaxRequestsPerConnection(HostDistance.LOCAL, 32768)
    .setMaxRequestsPerConnection(HostDistance.REMOTE, 2000);
cluster = builder.withPoolingOptions(poolingOptions).build();
cluster.getConfiguration().getCodecRegistry().register(new EnumNameCodec<>(OnBoardingSlide.Type.class));
session = cluster.connect(Global.getServerConfig().CASSANDRA_KEYSPACE_NAME);

This might be a bug in java driver 这可能是Java驱动程序中的错误

If a cassandra node is configured with native_transport_max_frame_size_in_mb > 256 and the driver reads a frame larger than 256mb it throws an exception: This breaks the drivers ability to read subsequent packets since the Decoder for parsing frames is static 如果将Cassandra节点配置为native_transport_max_frame_size_in_mb> 256,并且驱动程序读取的帧大于256mb,则会引发异常:由于解析帧的解码器是静态的,因此这会破坏驱动程序读取后续数据包的能力。

This has been fixed in a in 3.0.4, Here is the link for the details. 此问题已在3.0.4中的修复,这是详细信息的链接。

https://datastax-oss.atlassian.net/browse/JAVA-1292 https://datastax-oss.atlassian.net/browse/JAVA-1292

Can you try upgrading your driver ? 您可以尝试升级驱动程序吗?

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

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