Hi
Currently with the JDBCDescriptorsStore, when the database connection is
unexpectedly lost, we have to restart Tomcat to recreate the connection.
I've attached a stack trace which shows the problem.
I thought it looked easy enough to solve - just add connectIfNeeded()
before each attempt to use the connection (catching
ServiceConnectionFailedException).
But isClosed() as used in that method can't actually determine whether
the connection is invalid, so instead, i try to connect if
connection.prepareStatement throws an SLQException.
Patch is attached.
cheers,
Jason
6 months ago, Alexander Demidovich wrote:
>>Hi
>>
>>Has been Slide tested for cases when the database connection
>>was dropped unexpectedly? For example, database crash...
>>
>>I've tried and it looks not so good. I mean, I had to restart
>>the Tomcat
>>
Remy Maucherat wrote:
> Well, if there is a problem with that, it should be easy to fix, since there
> is a lot of code in there to handle that situation.
> Looking at the code, I think a reconnect should happen in all cases (but, of
> course, I could have missed something).
>
> Can you translate "it looks not so good" into a stack trace (if you got one)
> ?
>
> One problem that could be fixed is that Uri.parseUri (which will be called
> if there are some connection problems) swallows exceptions. I think I'll add
> some logging there.
>
> Remy
>
>
>
>
07 Jan 2002 13:17:22 - slidestore.reference.JDBCDescriptorsStore - ERROR
- java.sql.SQLException: Io exception: Connection reset by peer: socket
write error
java.sql.SQLException: Io exception: Connection reset by peer: socket
write error
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:210)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:323)
at oracle.jdbc.driver.OracleStatement.<init>(OracleStatement.java:417)
at oracle.jdbc.driver.OracleStatement.<init>(OracleStatement.java:432)
at
oracle.jdbc.driver.OraclePreparedStatement.<init>(OraclePreparedStatement.java:182)
at
oracle.jdbc.driver.OraclePreparedStatement.<init>(OraclePreparedStatement.java:165)
at
oracle.jdbc.driver.OracleConnection.privatePrepareStatement(OracleConnection.java:604)
at
oracle.jdbc.driver.OracleConnection.prepareStatement(OracleConnection.java:485)
at
slidestore.reference.JDBCDescriptorsStore.retrieveObject(JDBCDescriptorsStore.java:570)
at
org.apache.slide.store.StandardStore.retrieveObject(StandardStore.java:171)
at org.apache.slide.security.SecurityImpl.getPrincipal(SecurityImpl.java:765)
at wrappers.catalina.SlideRealm.getPassword(SlideRealm.java:255)
at org.apache.catalina.realm.RealmBase.authenticate(RealmBase.java:314)
at
org.apache.catalina.authenticator.BasicAuthenticator.authenticate(BasicAuthenticator.java:163)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2366)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:462)
at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at
org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1006)
at
org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1100)
at java.lang.Thread.run(Thread.java:484)
07 Jan 2002 13:17:22 - org.apache.slide.common.Domain - WARNING -
Service slidestore.reference.JDBCDescriptorsStore@5f280b access error :
Io exception: Connection reset by peer: socket write error
Index: JDBCDescriptorsStore.java
===================================================================
RCS file:
/home/cvspublic/jakarta-slide/src/stores/slidestore/reference/JDBCDescriptorsStore.java,v
retrieving revision 1.28
diff -r1.28 JDBCDescriptorsStore.java
553d552
<
568,570c567
<
< statement = connection.prepareStatement
< ("select * from objects where uri= ?");
---
> statement = prepareStatement( "select * from objects where uri= ?");
680,681c677
< statement = connection.prepareStatement
< ("select * from objects where uri= ?");
---
> statement = prepareStatement( "select * from objects where uri= ?");
771,772c767
< statement = connection.prepareStatement
< ("select * from objects where uri= ?");
---
> statement = prepareStatement( "select * from objects where uri= ?");
853,854c848
< statement = connection.prepareStatement
< ("delete from objects where uri= ?");
---
> statement = prepareStatement( "delete from objects where uri= ?");
911,913c905,906
<
< statement = connection.prepareStatement
< ("insert into permissions values(?,?,?,?,?,?)");
---
>
> statement = prepareStatement( "insert into permissions
>values(?,?,?,?,?,?)");
945a939
>
947,948c941
< statement = connection.prepareStatement
< ("delete from permissions where object= ? and subject = ? and
action = ? and revisionnumber = ? ");
---
> statement = prepareStatement( "delete from permissions where object=
>? and subject = ? and action = ? and revisionnumber = ? ");
952,953c945
< statement = connection.prepareStatement
< ("delete from permissions where object = ? and subject = ? and
action = ? and revisionnumber is NULL");
---
> statement = prepareStatement("delete from permissions where object =
>? and subject = ? and action = ? and revisionnumber is NULL");
984,985c976
< statement = connection.prepareStatement
< ("delete from permissions where object= ?");
---
> statement = prepareStatement( "delete from permissions where object= ?");
1011,1012c1002,1003
< statement = connection.prepareStatement
< ("select * from permissions where object= ?");
---
>
> statement = prepareStatement( "select * from permissions where object=
>?");
1069,1070c1060
< statement = connection.prepareStatement
< ("insert into locks values(?,?,?,?,?,?,?)");
---
> statement = prepareStatement( "insert into locks values(?,?,?,?,?,?,?)");
1114,1115c1104
< statement = connection.prepareStatement
< ("delete from locks where id=?");
---
> statement = prepareStatement( "delete from locks where id=?");
1208,1209c1197
< statement = connection.prepareStatement
< ("select * from locks where object= ?");
---
> statement = prepareStatement( "select * from locks where object= ?");
1268,1269c1256
< statement = connection.prepareStatement
< ("select * from revisions where uri= ?");
---
> statement = prepareStatement( "select * from revisions where uri= ?");
1379,1380c1366
< statement = connection.prepareStatement
< ("insert into revisions values(?,?,?)");
---
> statement = prepareStatement( "insert into revisions values(?,?,?)");
1449,1452c1435,1436
< try {
<
< statement = connection.prepareStatement
< ("delete from revisions where uri= ?");
---
> try {
> statement = prepareStatement( "delete from revisions where uri= ?");
1512,1513c1496
< statement = connection.prepareStatement
< ("select * from revision where uri= ? and xnumber = ?");
---
> statement = prepareStatement( "select * from revision where uri= ? and
>xnumber = ?");
1592,1593c1575
< statement = connection.prepareStatement
< ("insert into revision values(?, ?, ?)");
---
> statement = prepareStatement( "insert into revision values(?, ?, ?)");
1683,1686c1665,1666
< try {
<
< statement = connection.prepareStatement
< ("delete from revision where uri= ? and xnumber = ?");
---
> try {
> statement = prepareStatement( "delete from revision where uri= ? and
>xnumber = ?");
1732a1713,1714
>
> // -------------------------------------------------------- Private Methods
1733a1716,1743
> private PreparedStatement prepareStatement(String query) throws SQLException {
>
> PreparedStatement statement = null;
> try {
> statement = connection.prepareStatement(query);
> } catch (SQLException e) {
> // Assume its because the connection has been lost
> getLogger().log("prepareStatement for query '" + query + "'
>failed",LOG_CHANNEL,Logger.ERROR);
> getLogger().log(e.toString(),LOG_CHANNEL,Logger.ERROR);
> getLogger().log("Trying to re-connect to \"" + url + "\" as user \"" +
>user + "\"",LOG_CHANNEL,Logger.INFO);
> connection = DriverManager.getConnection
> (url, user, password);
> getLogger().log(".. success.",LOG_CHANNEL,Logger.INFO);
>
> // all updates must be done inside a transaction, no auto commits
> try {
> connection.setAutoCommit(false);
> } catch (SQLException e2) {
> }
>
> // we are just connected and are not enlisted
> alreadyEnlisted=false;
>
> statement = connection.prepareStatement
> (query);
> }
> return statement;
> }
1735c1745
< }
\ No newline at end of file
---
> }
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>