繁体   English   中英

Cassandra Java驱动程序连接错误

[英]Cassandra java driver connection error

TL; DR-所以我遇到了从DataStax Java cassandra驱动程序到DataStax cassandra群集的连接问题。 它最初连接并运行良好,然后突然在某个点上失去了连接并且没有重新连接-此时所有查询都失败了。

更多信息 -

所以我在CentOS上运行3个节点的DataStax cassandra 2.1集群,我在使用DataStax cassandra驱动程序3.0.0。 在过去的几个月中,一切工作都很好,最近我进行了一些代码更改,其中包括一些架构更改(即向现有表中添加列),并增加了查询数量。 此时断开连接。

因此,当我的应用启动时,它连接到集群并持有一个集群(和会话)对象,如下面的代码片段所示,此时一切正常。 几个小时后,我开始为执行的每个查询接收NoHostAvailableException 在这一点上,我有其他服务器在相同的cassandra群集上运行良好,因此我知道群集本身没有任何问题。 重新启动服务器后,一切恢复正常。

经过更多调查后,当问题开始发生时,我看到两个节点都没有活动连接。 设置驱动程序以将DEBUG级别登录到专用日志文件中,然后等待问题再次发生。 几个小时后,问题再次发生,日志文件有时显示以下消息:

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

然后,您会看到以下内容:

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

从这一点开始,您只会看到超时和重试,但不会重新建立连接。

// 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);

这可能是Java驱动程序中的错误

如果将Cassandra节点配置为native_transport_max_frame_size_in_mb> 256,并且驱动程序读取的帧大于256mb,则会引发异常:由于解析帧的解码器是静态的,因此这会破坏驱动程序读取后续数据包的能力。

此问题已在3.0.4中的修复,这是详细信息的链接。

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

您可以尝试升级驱动程序吗?

暂无
暂无

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

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