Impetus / kundera

A JPA 2.1 compliant Polyglot Object-Datastore Mapping Library for NoSQL Datastores.Please subscribe to:
http://groups.google.com/group/kundera-discuss/subscribe
Apache License 2.0
903 stars 233 forks source link

Connection in the pool was not renewed after Cassandra db restarted. #657

Open jamesxukun opened 10 years ago

jamesxukun commented 10 years ago

I have a connection pool set up with com.impetus.client.cassandra.thrift.ThriftClientFactory client. After I restart Cassandra database, the connection in the pool was not renewed, so I kept getting following network exception:

Caused by: org.apache.thrift.transport.TTransportException at org.apache.thrift.transport.TIOStreamTransport.read(TIOStreamTransport.java:132)

Could you let me know how to solve the issue, I am in 2.11 version.

chhavigangwal commented 10 years ago

@jamesxukun

Can you share further details on how have you set up this connection and pool and how do you use the same ? Also, please take a look at the following to check if it helps :

https://github.com/impetus-opensource/Kundera/wiki/Using-multiple-node-support-and-load-balancing-policy-in-Kundera

Chhavi

jamesxukun commented 10 years ago

Thanks for your quick reply.

Here is my persistence.xml file:

<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
             http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0">
    <persistence-unit name="cassandra">
        <provider>com.impetus.kundera.KunderaPersistence</provider>
        <properties>
            <property name="kundera.dialect" value="cassandra"/>
            <property name="cql.version" value="3.0.0"/>
            <property name="kundera.client.lookup.class" value="com.impetus.client.cassandra.thrift.ThriftClientFactory"/>
            <!-- other deployment specific parameters should be provided in a separate properties file  -->
            <property name="kundera.keyspace" value="cls_new"/>
            <property name="kundera.nodes" value="localhost"/>
            <property name="kundera.port" value="9160"/>            
            <property name="kundera.username" value="ucontrol"/>
            <property name="kundera.password" value="test"/>
            <property name="kundera.pool.size.min.idle" value="5" />
            <property name="kundera.pool.size.max.active" value="50" />
            <property name="kundera.pool.size.max.total" value="100" />
            <property name="kundera.ddl.auto.prepare" value="validate"/>
            <property name="kundera.client.property" value="kunderaLoadConfig.xml" />
        </properties>
    </persistence-unit>
</persistence>

And the kunderaLoadConfig.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<clientProperties>
  <datastores>
   <dataStore>
    <name>cassandra</name>
    <connection>
     <servers>
     </servers>
     <!-- Load balancing specific configuration -->
    <properties>
    <property name="loadbalancing.policy" value="roundrobin"></property>
        <property name="retry" value="true"></property>
        <property name="retry.delay" value="1"></property>
        <property name="max.wait" value="3000"></property> 
        <property name="testonborrow" value="true"></property>
         <property name="testwhileidle" value="true"></property>
         <property name="testonconnect" value="true"></property>
         <property name="testonreturn" value="true"></property>
         <property name="failover.policy" value="on.fail.try.one.next.available"></property>
    </properties>
    </connection>
</dataStore>
</datastores>
</clientProperties>

But, every time, after the cassandra db is restarted, I always get thrift exception, looks like the testonborrow or retry settings don't work.

jamesxukun commented 10 years ago

Properties defined in persistence.xml:

<properties>
            <property name="kundera.dialect" value="cassandra"/>
            <property name="cql.version" value="3.0.0"/>
            <property name="kundera.client.lookup.class" value="com.impetus.client.cassandra.thrift.ThriftClientFactory"/>
            <!-- other deployment specific parameters should be provided in a separate properties file  -->
            <property name="kundera.keyspace" value="cls_new"/>
            <property name="kundera.nodes" value="localhost"/>
            <property name="kundera.port" value="9160"/>            
            <property name="kundera.username" value="ucontrol"/>
            <property name="kundera.password" value="test"/>
            <property name="kundera.pool.size.min.idle" value="5" />
            <property name="kundera.pool.size.max.active" value="50" />
            <property name="kundera.pool.size.max.total" value="100" />
            <property name="kundera.ddl.auto.prepare" value="validate"/>
            <property name="kundera.client.property" value="kunderaLoadConfig.xml" />
        </properties>

And properties in kunderaLoadConfig.xml:

 <properties>
    <property name="loadbalancing.policy" value="roundrobin"></property>
        <property name="retry" value="true"></property>
        <property name="retry.delay" value="1"></property>
        <property name="max.wait" value="3000"></property> 
        <property name="testonborrow" value="true"></property>
         <property name="testwhileidle" value="true"></property>
         <property name="testonconnect" value="true"></property>
         <property name="testonreturn" value="true"></property>
         <property name="failover.policy" value="on.fail.try.one.next.available"></property>
    </properties>
    </connection>
jamesxukun commented 10 years ago

Properties defined in persistence.xml:

property name="kundera.keyspace" value="cls_new"/> property name="kundera.nodes" value="localhost"/> property name="kundera.port" value="9160"/>
property name="kundera.username" value="ucontrol"/> property name="kundera.password" value="test"/> property name="kundera.pool.size.min.idle" value="5" /> property name="kundera.pool.size.max.active" value="50" /> property name="kundera.pool.size.max.total" value="100" /> property name="kundera.ddl.auto.prepare" value="validate"/> property name="kundera.client.property" value="kunderaLoadConfig.xml" />

And properties in kunderaLoadConfig.xml: properties> property name="loadbalancing.policy" value="roundrobin"> property name="retry" value="true"> property name="retry.delay" value="1"> property name="max.wait" value="3000"> property name="testonborrow" value="true"> property name="testwhileidle" value="true"> property name="testonconnect" value="true"> property name="testonreturn" value="true"> property name="failover.policy" value="on.fail.try.one.next.available">/property> /properties> /connection>

-->

chhavigangwal commented 10 years ago

@jamesxukun

Please try upgrading Kundera to 2.11.1 or to latest version as a fix for same has been added. Please check the following issue for reference #554

Chhavi

jamesxukun commented 10 years ago

Thanks, I will try it. A general question, is the load balancer configuration taken by Thrift client? For me, seems not, how I can confirm that the configuration works as defined?

chhavigangwal commented 10 years ago

You can test your configuration testing by obtaining CassandraHostConfiguration as done in

https://github.com/impetus-opensource/Kundera/blob/aca0912c4115e055d8b0c0647ba217c7177da5d4/src/kundera-cassandra/cassandra-core/src/test/java/com/impetus/client/cassandra/config/CassandraPropertySetterTest.java#L216

Hope that Helps ! Chhavi