You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by John Holman <j....@qmul.ac.uk> on 2002/12/04 14:23:07 UTC

OJB not robust against database or network failures

If the database or network goes down when OJB already has connections in 
the underlying pool, I've found that OJB does not recover when the 
database comes back up. I think this is because after an operation fails 
the invalid connection is returned to the pool rather than being 
destroyed and a new one created.

Using the built-in connection pool ConnectionFactoryConPooledImpl I 
tried setting "testOnBorrow" to true in the connection-pool element of 
jdbc-connection-descriptor, but this did not help. Looking at the code, 
ConnectionFactoryConPooledImpl.validateObject() just calls 
java.sql.Connection.isClosed(), and this does not seem to detect that 
the connection is invalid, at least for the JDBC drivers for Postgresql 
and Oracle that I'm using.

Then, I noticed that the current CVS version (0.9.8) offers a 
ConnectionFactoryDBCPImpl option in OJB.properties. Using the Jakarta 
DBCP connection pool directly in another application, I've found that 
you can get robust behaviour by setting testOnBorrow to true and setting 
a suitable validation query (e.g. select 0 from dual for Oracle). 
However, it seems that OJB sets the validation query to null. (A comment 
suggests this is because a suitable validation query would vary between 
database platforms). And there does not seem to be a configuration 
option to set/override the validation query ...

I'd be grateful for any suggestions.

John.


Re: OJB not robust against database or network failures

Posted by Thomas Mahler <th...@apache.org>.
Hi all,

<snip>
>>
>>I'm not an expert either! But perhaps a hard coded default query from
>>Platform which can be overridden by the user by a validationQuery
>>attribute in jdbc-connection-descriptor or connection-pool?
> 
> 
> Thanks, attribute in connection-pool seems to be a good solution,
> because
> we only need this feature when using pooled connectins. If not set we
> only
> do a isClosed() validation.
> 

I think we should also provide a default validationQuery. I suggest to 
use a simple "SELECT COUNT(*) FROM OJB_SEQ", as the ojb sequencemanager 
table will be used in about 95% of all OJB scenarios.

This an urgently needed feature!

cheers,
Thomas



Re: OJB not robust against database or network failures

Posted by Armin Waibel <ar...@code-au-lait.de>.
Hi again,

----- Original Message -----
From: "John Holman" <j....@qmul.ac.uk>
To: "OJB Users List" <oj...@jakarta.apache.org>
Sent: Wednesday, December 04, 2002 2:56 PM
Subject: Re: OJB not robust against database or network failures


> Hi Armin
>
>  > Yes, you are right I checked in this version a few days ago. I'm
not a
>  > DB-expert,
>  > so I don't now what's the best solution to get the
'validationQuery'
>  > from.
>  > 1. Use a hard-coded query from the Platform implementation class
>  > 2. Allow user to set the query within the
jdbc-connection-descriptor
>  > in the repository file.
>  >
>
> I'm not an expert either! But perhaps a hard coded default query from
> Platform which can be overridden by the user by a validationQuery
> attribute in jdbc-connection-descriptor or connection-pool?

Thanks, attribute in connection-pool seems to be a good solution,
because
we only need this feature when using pooled connectins. If not set we
only
do a isClosed() validation.

>
> In the meantime is there a way of getting hold of the
> PoolableConnectionFactory and setting the validation query directly in
> the application?

Should be possible. Extend ConnectionFactoryConPooledImpl.java
and override #createObjectFactory. Then you could use your own
implementation of BasePoolableObjectFactory. See source code
for more detail.
Change OJB.properties to use your own ConnectionFactory implementation.

regards,
Armin

>
> Thanks, John
>
>
> Armin Waibel wrote:
> > Hi John,
> >
> >
> > ----- Original Message -----
> > From: "John Holman" <j....@qmul.ac.uk>
> > To: <oj...@jakarta.apache.org>
> > Sent: Wednesday, December 04, 2002 2:23 PM
> > Subject: OJB not robust against database or network failures
> >
> >
> >
> >>If the database or network goes down when OJB already has
connections
> >
> > in
> >
> >>the underlying pool, I've found that OJB does not recover when the
> >>database comes back up. I think this is because after an operation
> >
> > fails
> >
> >>the invalid connection is returned to the pool rather than being
> >>destroyed and a new one created.
> >>
> >>Using the built-in connection pool ConnectionFactoryConPooledImpl I
> >>tried setting "testOnBorrow" to true in the connection-pool element
of
> >>jdbc-connection-descriptor, but this did not help. Looking at the
> >
> > code,
> >
> >>ConnectionFactoryConPooledImpl.validateObject() just calls
> >>java.sql.Connection.isClosed(), and this does not seem to detect
that
> >>the connection is invalid, at least for the JDBC drivers for
> >
> > Postgresql
> >
> >>and Oracle that I'm using.
> >>
> >>Then, I noticed that the current CVS version (0.9.8) offers a
> >>ConnectionFactoryDBCPImpl option in OJB.properties. Using the
Jakarta
> >>DBCP connection pool directly in another application, I've found
that
> >>you can get robust behaviour by setting testOnBorrow to true and
> >
> > setting
> >
> >>a suitable validation query (e.g. select 0 from dual for Oracle).
> >>However, it seems that OJB sets the validation query to null. (A
> >
> > comment
> >
> >>suggests this is because a suitable validation query would vary
> >
> > between
> >
> >>database platforms). And there does not seem to be a configuration
> >>option to set/override the validation query ...
> >
> >
> > Yes, you are right I checked in this version a few days ago. I'm not
a
> > DB-expert,
> > so I don't now what's the best solution to get the 'validationQuery'
> > from.
> > 1. Use a hard-coded query from the Platform implementation class
> > 2. Allow user to set the query within the jdbc-connection-descriptor
> > in the repository file.
> >
> > Any comments welcome.
> >
> > regards,
> > Armin
> >
> >
> >>I'd be grateful for any suggestions.
> >>
> >>John.
> >>
> >>
> >>--
> >>To unsubscribe, e-mail:
> >
> > <ma...@jakarta.apache.org>
> >
> >>For additional commands, e-mail:
> >
> > <ma...@jakarta.apache.org>
> >
> >>
> >>
> >
> >
> > --
> > To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> > For additional commands, e-mail:
<ma...@jakarta.apache.org>
> >
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>
>


Re: OJB not robust against database or network failures

Posted by John Holman <j....@qmul.ac.uk>.
Hi Armin

 > Yes, you are right I checked in this version a few days ago. I'm not a
 > DB-expert,
 > so I don't now what's the best solution to get the 'validationQuery'
 > from.
 > 1. Use a hard-coded query from the Platform implementation class
 > 2. Allow user to set the query within the jdbc-connection-descriptor
 > in the repository file.
 >

I'm not an expert either! But perhaps a hard coded default query from 
Platform which can be overridden by the user by a validationQuery 
attribute in jdbc-connection-descriptor or connection-pool?

In the meantime is there a way of getting hold of the 
PoolableConnectionFactory and setting the validation query directly in 
the application?

Thanks, John


Armin Waibel wrote:
> Hi John,
> 
> 
> ----- Original Message -----
> From: "John Holman" <j....@qmul.ac.uk>
> To: <oj...@jakarta.apache.org>
> Sent: Wednesday, December 04, 2002 2:23 PM
> Subject: OJB not robust against database or network failures
> 
> 
> 
>>If the database or network goes down when OJB already has connections
> 
> in
> 
>>the underlying pool, I've found that OJB does not recover when the
>>database comes back up. I think this is because after an operation
> 
> fails
> 
>>the invalid connection is returned to the pool rather than being
>>destroyed and a new one created.
>>
>>Using the built-in connection pool ConnectionFactoryConPooledImpl I
>>tried setting "testOnBorrow" to true in the connection-pool element of
>>jdbc-connection-descriptor, but this did not help. Looking at the
> 
> code,
> 
>>ConnectionFactoryConPooledImpl.validateObject() just calls
>>java.sql.Connection.isClosed(), and this does not seem to detect that
>>the connection is invalid, at least for the JDBC drivers for
> 
> Postgresql
> 
>>and Oracle that I'm using.
>>
>>Then, I noticed that the current CVS version (0.9.8) offers a
>>ConnectionFactoryDBCPImpl option in OJB.properties. Using the Jakarta
>>DBCP connection pool directly in another application, I've found that
>>you can get robust behaviour by setting testOnBorrow to true and
> 
> setting
> 
>>a suitable validation query (e.g. select 0 from dual for Oracle).
>>However, it seems that OJB sets the validation query to null. (A
> 
> comment
> 
>>suggests this is because a suitable validation query would vary
> 
> between
> 
>>database platforms). And there does not seem to be a configuration
>>option to set/override the validation query ...
> 
> 
> Yes, you are right I checked in this version a few days ago. I'm not a
> DB-expert,
> so I don't now what's the best solution to get the 'validationQuery'
> from.
> 1. Use a hard-coded query from the Platform implementation class
> 2. Allow user to set the query within the jdbc-connection-descriptor
> in the repository file.
> 
> Any comments welcome.
> 
> regards,
> Armin
> 
> 
>>I'd be grateful for any suggestions.
>>
>>John.
>>
>>
>>--
>>To unsubscribe, e-mail:
> 
> <ma...@jakarta.apache.org>
> 
>>For additional commands, e-mail:
> 
> <ma...@jakarta.apache.org>
> 
>>
>>
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 



Re: OJB not robust against database or network failures

Posted by Armin Waibel <ar...@code-au-lait.de>.
Hi John,


----- Original Message -----
From: "John Holman" <j....@qmul.ac.uk>
To: <oj...@jakarta.apache.org>
Sent: Wednesday, December 04, 2002 2:23 PM
Subject: OJB not robust against database or network failures


> If the database or network goes down when OJB already has connections
in
> the underlying pool, I've found that OJB does not recover when the
> database comes back up. I think this is because after an operation
fails
> the invalid connection is returned to the pool rather than being
> destroyed and a new one created.
>
> Using the built-in connection pool ConnectionFactoryConPooledImpl I
> tried setting "testOnBorrow" to true in the connection-pool element of
> jdbc-connection-descriptor, but this did not help. Looking at the
code,
> ConnectionFactoryConPooledImpl.validateObject() just calls
> java.sql.Connection.isClosed(), and this does not seem to detect that
> the connection is invalid, at least for the JDBC drivers for
Postgresql
> and Oracle that I'm using.
>
> Then, I noticed that the current CVS version (0.9.8) offers a
> ConnectionFactoryDBCPImpl option in OJB.properties. Using the Jakarta
> DBCP connection pool directly in another application, I've found that
> you can get robust behaviour by setting testOnBorrow to true and
setting
> a suitable validation query (e.g. select 0 from dual for Oracle).
> However, it seems that OJB sets the validation query to null. (A
comment
> suggests this is because a suitable validation query would vary
between
> database platforms). And there does not seem to be a configuration
> option to set/override the validation query ...

Yes, you are right I checked in this version a few days ago. I'm not a
DB-expert,
so I don't now what's the best solution to get the 'validationQuery'
from.
1. Use a hard-coded query from the Platform implementation class
2. Allow user to set the query within the jdbc-connection-descriptor
in the repository file.

Any comments welcome.

regards,
Armin

>
> I'd be grateful for any suggestions.
>
> John.
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>
>