【问题标题】:Cassandra datastax driver connections getting terminated abruptlyCassandra datastax 驱动程序连接突然终止
【发布时间】:2023-03-21 19:24:01
【问题描述】:

我将 com.datastax.cassandra:cassandra-driver-core:2.1.7.1 与 Cassandra 2.1.11 一起使用。抛出以下异常,它似乎指向协议版本问题,但抛出 NPE 而不是 ProtocolException。

2016-01-26 17:46:29.426 TRACE - [launch worker-1] [74120143-3dc5-466d-8a71-68edbe03620d] com.datastax.driver.core.Connection      : Connection[/192.172.2.51:9042-1, inFlight=1, closed=false] writing request
 PREPARE SELECT * FROM loops WHERE venue_id = ? AND loop_state = ?  AND covers_year = ?  AND covers_month = ?  AND covers_day = 0 
2016-01-26 17:46:29.427 DEBUG - [r2-nio-worker-1] [74120143-3dc5-466d-8a71-68edbe03620d] com.datastax.driver.core.Connection      : Connection[/192.172.1.51:9042-3, inFlight=0, closed=false] connection error
java.lang.NullPointerException
        at com.datastax.driver.core.ProtocolOptions.getProtocolVersionEnum(ProtocolOptions.java:178)
        at com.datastax.driver.core.QueryLogger.protocolVersion(QueryLogger.java:753)
        at com.datastax.driver.core.QueryLogger.parameterValueAsString(QueryLogger.java:738)
        at com.datastax.driver.core.QueryLogger.appendParameters(QueryLogger.java:709)
        at com.datastax.driver.core.QueryLogger.logQuery(QueryLogger.java:647)
        at com.datastax.driver.core.QueryLogger.maybeLogNormalQuery(QueryLogger.java:631)
        at com.datastax.driver.core.QueryLogger$ConstantThresholdQueryLogger.maybeLogNormalOrSlowQuery(QueryLogger.java:278)
        at com.datastax.driver.core.QueryLogger.update(QueryLogger.java:620)
        at com.datastax.driver.core.Cluster$Manager.reportLatency(Cluster.java:1422)
        at com.datastax.driver.core.RequestHandler$SpeculativeExecution.onSet(RequestHandler.java:607)
        at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:991)
        at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:913)
        at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
        at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:254)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:163)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787)
        at io.netty.channel.epoll.EpollSocketChannel$EpollSocketUnsafe.epollInReady(EpollSocketChannel.java:722)
        at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:326)
        at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:264)
        at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
        at java.lang.Thread.run(Thread.java:745)
2016-01-26 17:46:29.427 TRACE - [r2-nio-worker-4] [74120143-3dc5-466d-8a71-68edbe03620d] com.datastax.driver.core.Connection      : Connection[/192.172.2.51:9042-1, inFlight=1, closed=false] request sent successfully
2016-01-26 17:46:29.430 DEBUG - [r2-nio-worker-1] [74120143-3dc5-466d-8a71-68edbe03620d] com.datastax.driver.core.Connection      : Defuncting connection to /192.172.1.51:9042
com.datastax.driver.core.TransportException: [/192.172.1.51:9042] Unexpected exception triggered (java.lang.NullPointerException)
        at com.datastax.driver.core.Connection$Dispatcher.exceptionCaught(Connection.java:1028)
        at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:271)
        at io.netty.channel.AbstractChannelHandlerContext.notifyHandlerException(AbstractChannelHandlerContext.java:768)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:335)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
        at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:254)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:163)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787)
        at io.netty.channel.epoll.EpollSocketChannel$EpollSocketUnsafe.epollInReady(EpollSocketChannel.java:722)
        at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:326)
        at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:264)
        at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
        at com.datastax.driver.core.ProtocolOptions.getProtocolVersionEnum(ProtocolOptions.java:178)
        at com.datastax.driver.core.QueryLogger.protocolVersion(QueryLogger.java:753)
        at com.datastax.driver.core.QueryLogger.parameterValueAsString(QueryLogger.java:738)
        at com.datastax.driver.core.QueryLogger.appendParameters(QueryLogger.java:709)
        at com.datastax.driver.core.QueryLogger.logQuery(QueryLogger.java:647)
        at com.datastax.driver.core.QueryLogger.maybeLogNormalQuery(QueryLogger.java:631)
        at com.datastax.driver.core.QueryLogger$ConstantThresholdQueryLogger.maybeLogNormalOrSlowQuery(QueryLogger.java:278)
        at com.datastax.driver.core.QueryLogger.update(QueryLogger.java:620)
        at com.datastax.driver.core.Cluster$Manager.reportLatency(Cluster.java:1422)
        at com.datastax.driver.core.RequestHandler$SpeculativeExecution.onSet(RequestHandler.java:607)
        at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:991)
        at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:913)
        at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
        ... 16 more
2016-01-26 17:46:29.431 TRACE - [r2-nio-worker-4] [74120143-3dc5-466d-8a71-68edbe03620d] com.datastax.driver.core.Connection      : Connection[/192.172.2.51:9042-1, inFlight=1, closed=false] received: RESULT PREPARED 0xc66a551ecfc5ac34839e19fdfa0c5705 [venue_id (uuid)][loop_state (varchar)][covers_year (int)][covers_month (int)] (resultMetadata=[venue_id (uuid)][loop_state (varchar)][covers_year (int)][covers_month (int)][covers_day (int)][start (timestamp)][created_on (timestamp)][end (timestamp)][id (uuid)][iterations (int)][playlist (list<frozen<ums_qa."LoopMediaAsset">>)][slots (list<frozen<ums_qa."Slot">>)][updated_on (timestamp)])

两个 Cassandra 节点都工作正常并接受连接。一些驱动程序似乎任意关闭连接。无法在任何地方找到报告的类似问题。任何帮助将不胜感激。谢谢。

【问题讨论】:

  • 看起来驱动程序还没有初始化,但是不应该有一个打开的连接试图执行 PREPARE。你能分享一下你是如何初始化ClusterSession 对象的吗?您是否从您的代码中自己准备了该声明?你对 ProtocolOptions 做了什么特别的事情(包装它或子类化它)吗?

标签: apache-spark cassandra datastax-java-driver


【解决方案1】:

本机协议版本在 2.1.8 和 2.1.9 之间略有增加 - 通过将 2.1.7 驱动程序与 2.1.11 服务器一起使用,服务器提供的本机协议版本号无法识别客户。

鉴于堆栈跟踪(以及那些行中的驱动程序代码 - https://github.com/datastax/java-driver/blob/f4240267b3a3b829fa51242441dd219424a91347/driver-core/src/main/java/com/datastax/driver/core/ProtocolOptions.java#L168-L179),我可能会首先升级到最新的 2.1.11+ cassandra-driver 版本以排除这种情况。

【讨论】:

    【解决方案2】:

    我们从 spark 集群的节点连接到 Cassandra,并使用初始化 Cassandra ClusterSession 的辅助类。

    正如@OlivierMichallat 指出的那样,问题出在这个初始化中。似乎创建了多个集群,可能是因为从 spark 工作人员多次加载了辅助类。这违反了 DataStax 建议的规则之一,即use one Cluster instance per physical cluster。同步这个初始化为我们解决了这个问题。谢谢各位大侠指点。

    【讨论】:

      猜你喜欢
      • 2013-12-23
      • 2021-02-09
      • 2016-02-27
      • 2017-01-20
      • 2017-12-23
      • 1970-01-01
      • 2015-08-16
      • 2019-11-30
      • 2016-02-18
      相关资源
      最近更新 更多