Cassandra datastax驱动程序连接突然终止

时间:2016-01-26 18:30:27

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

我正在使用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节点都正常工作并接受连接。一些驱动程序似乎是如何随意关闭连接。无法在任何地方找到类似的问题。任何帮助将受到高度赞赏。感谢。

2 个答案:

答案 0 :(得分:2)

在2.1.8和2.1.9之间有一个较小的本机协议版本增加 - 通过使用带有2.1.11服务器的2.1.7驱动程序,您有一个由服务器提供的本机原型版本号,&#39;没有得到客户的认可。

鉴于堆栈跟踪(以及这些行中的驱动程序中的代码 - 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版本来排除这种情况。

答案 1 :(得分:0)

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

问题结果是在@OlivierMichallat指出的这个初始化中。似乎有多个集群被创建,可能是因为帮助程序类被多次从spark worker加载。这违反了DataStax建议的一个规则,即use one Cluster instance per physical cluster。同步此初始化为我们解决了问题。谢谢你的指示。