You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by James Johnson <jm...@hotmail.com> on 2006/04/19 23:28:40 UTC

cacheModel - Database Down and external app flush

I have a few questions regarding iBatis cacheModel. All help is greatly appreciated.

1) When the iBatis cacheModel is used, a connection to the database server appears to be still required. The data has been cached, so I'm not sure why the database server needs to be up after caching the data. 

For exapmle, I have test code that basically returns the same row of data n times. As expected, the data is cached and remains unchanged desipte making updates using the database command line client (i.e. outside of my program). During the ith (1<i<=n) try, I shutdown the database server. I would expect iBatis to just use the cache results and not require the database server to be up. However, instead I get the following error when I bring the database server down: 

Exception in thread "main" org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: 

** BEGIN NESTED EXCEPTION ** 

java.net.SocketException

MESSAGE: java.net.ConnectException: Connection refused: connect


I would like to have mechanism that allows the application to use cached data in the event the database server is down as it does when the database server is up. Is the cachModel capable of providing this functionality? Why does the database server need to be up when iBatis is using cached results?

2) By specifying the flushOnExecute, iBatis will flush the cache when a certian statement(s) is executed. Is there a way for iBatis to flush the cache when anything (i.e. another application) makes an update, insert or delete?

Re: cacheModel - Database Down and external app flush

Posted by Sven Boden <li...@pandora.be>.
For the programmatic flushing... on the SqlMapClient you have a methods 
called flushDataCache() that either flush all caches or a named cache.

For your exception:
- get the last version of iBATIS from SVN, and activate debugging... 
logging for caching was put in there a couple of weeks ago.
- if you put "Pool.PingEnabled" to false in the SqlMapConfig 
transactionManager section
- you should also have caching enabled of course.

Also be aware that caching in iBATIS does not use object identity: 
ResultSets are cached, not indivual objects (but the debugging should 
make that more clear). If you want to have advanced caching it's 
probably best to roll your own in the DAO layer.

Regards,
Sven

James Johnson wrote:

> Thanks Sven for the quick response. I am a beginner to iBatis, so I
> apologize in advance if I don't know some of the answers to your 
> questions.
> I'll try my best.
>
> In regards to 2), I figured that was the case by the same reasoning. I 
> just
> wanted to make sure with someone who had more experience with iBatis. 
> However, is it possible one iBatis application receive notifications 
> from another iBatis application to flush cache?
>
> In regards to 1), the full stack trace is below. Thanks for looking at 
> this.
> Also, how would I deactivate the ping query?
>
> Exception in thread "main" 
> org.springframework.jdbc.CannotGetJdbcConnectionException: Could not 
> get JDBC Connection; nested exception is 
> com.mysql.jdbc.CommunicationsException: Communications link failure 
> due to underlying exception:
>
>
>
> ** BEGIN NESTED EXCEPTION **
>
>
>
> java.net.SocketException
>
> MESSAGE: java.net.ConnectException: Connection refused: connect
>
>
>
> STACKTRACE:
>
>
>
> java.net.SocketException: java.net.ConnectException: Connection 
> refused: connect
>
>      at 
> com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156) 
>
>
>      at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:284)
>
>      at com.mysql.jdbc.Connection.createNewIO(Connection.java:2555)
>
>      at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
>
>      at 
> com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266) 
>
>
>      at 
> org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37) 
>
>
>      at 
> org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290) 
>
>
>      at 
> org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:771) 
>
>
>      at 
> org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:95) 
>
>
>      at 
> org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540) 
>
>
>      at 
> org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111) 
>
>
>      at 
> org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77) 
>
>
>      at 
> org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:178) 
>
>
>      at 
> org.springframework.orm.ibatis.SqlMapClientTemplate.executeWithListResult(SqlMapClientTemplate.java:204) 
>
>
>      at 
> org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClientTemplate.java:243) 
>
>
>      at data.SqlMapClientTestDao.getAll(SqlMapClientTestDao.java:25)
>
>      at service.Main.run(Main.java:37)
>
>      at service.Main.main(Main.java:55)
>
>
>
>
>
> ** END NESTED EXCEPTION **
>
>
>
>
>
>
>
> Last packet sent to the server was 0 ms ago.
>
> com.mysql.jdbc.CommunicationsException: Communications link failure 
> due to underlying exception:
>
>
>
> ** BEGIN NESTED EXCEPTION **
>
>
>
> java.net.SocketException
>
> MESSAGE: java.net.ConnectException: Connection refused: connect
>
>
>
> STACKTRACE:
>
>
>
> java.net.SocketException: java.net.ConnectException: Connection 
> refused: connect
>
>      at 
> com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156) 
>
>
>      at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:284)
>
>      at com.mysql.jdbc.Connection.createNewIO(Connection.java:2555)
>
>      at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
>
>      at 
> com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266) 
>
>
>      at 
> org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37) 
>
>
>      at 
> org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290) 
>
>
>      at 
> org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:771) 
>
>
>      at 
> org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:95) 
>
>
>      at 
> org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540) 
>
>
>      at 
> org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111) 
>
>
>      at 
> org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77) 
>
>
>      at 
> org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:178) 
>
>
>      at 
> org.springframework.orm.ibatis.SqlMapClientTemplate.executeWithListResult(SqlMapClientTemplate.java:204) 
>
>
>      at 
> org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClientTemplate.java:243) 
>
>
>      at data.SqlMapClientTestDao.getAll(SqlMapClientTestDao.java:25)
>
>      at service.Main.run(Main.java:37)
>
>      at service.Main.main(Main.java:55)
>
>
>
>
>
> ** END NESTED EXCEPTION **
>
>
>
>
>
>
>
> Last packet sent to the server was 0 ms ago.
>
>      at com.mysql.jdbc.Connection.createNewIO(Connection.java:2621)
>
>      at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
>
>      at 
> com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266) 
>
>
>      at 
> org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37) 
>
>
>      at 
> org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290) 
>
>
>      at 
> org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:771) 
>
>
>      at 
> org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:95) 
>
>
>      at 
> org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540) 
>
>
>      at 
> org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111) 
>
>
>      at 
> org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77) 
>
>
>      at 
> org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:178) 
>
>
>      at 
> org.springframework.orm.ibatis.SqlMapClientTemplate.executeWithListResult(SqlMapClientTemplate.java:204) 
>
>
>      at 
> org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClientTemplate.java:243) 
>
>
>      at data.SqlMapClientTestDao.getAll(SqlMapClientTestDao.java:25)
>
>      at service.Main.run(Main.java:37)
>
>      at service.Main.main(Main.java:55)
>
>
>
> ----- Original Message ----- From: "Sven Boden" <li...@pandora.be>
> To: <us...@ibatis.apache.org>
> Sent: Wednesday, April 19, 2006 4:48 PM
> Subject: Re: cacheModel - Database Down and external app flush
>
>
>>
>> For 1):
>> do you have the full nested stacktrace? Did you deactivate the ping 
>> query? and are you sure the exception originates in iBATIS (we'll see 
>> from the full stacktrace). The intention of a cache is to speed 
>> things up, it's not the intention to have a complete in-core database.
>>
>> For 2)
>> There's no way for iBATIS to be automatically aware of updates by 
>> other applications. This is a problem for every database application, 
>> not just iBATIS. If you would develop an application without iBATIS 
>> (with your own developed caching), how would you know in your 
>> application whether another application updated your database?
>>
>> Regards,
>> Sven
>>
>> James Johnson wrote:
>>
>>> I have a few questions regarding iBatis cacheModel. All help is 
>>> greatly appreciated.
>>>
>>> 1) When the iBatis cacheModel is used, a connection to the database 
>>> server appears to be still required. The data has been cached, so 
>>> I'm not sure why the database server needs to be up after caching 
>>> the data.
>>> For exapmle, I have test code that basically returns the same row of 
>>> data n times. As expected, the data is cached and remains unchanged 
>>> desipte making updates using the database command line client (i.e. 
>>> outside of my program). During the ith (1<i<=n) try, I shutdown the 
>>> database server. I would expect iBatis to just use the cache results 
>>> and not require the database server to be up. However, instead I get 
>>> the following error when I bring the database server down:
>>> Exception in thread "main" 
>>> org.springframework.jdbc.CannotGetJdbcConnectionException: Could not 
>>> get JDBC Connection; nested exception is 
>>> com.mysql.jdbc.CommunicationsException: Communications link failure 
>>> due to underlying exception:
>>> ** BEGIN NESTED EXCEPTION **
>>> java.net.SocketException
>>>
>>> MESSAGE: java.net.ConnectException: Connection refused: connect
>>>
>>>
>>> I would like to have mechanism that allows the application to use 
>>> cached data in the event the database server is down as it does when 
>>> the database server is up. Is the cachModel capable of providing 
>>> this functionality? Why does the database server need to be up when 
>>> iBatis is using cached results?
>>>
>>> 2) By specifying the flushOnExecute, iBatis will flush the cache 
>>> when a certian statement(s) is executed. Is there a way for iBatis 
>>> to flush the cache when anything (i.e. another application) makes an 
>>> update, insert or delete?
>>>
>>>
>>
>>
>
>


Re: cacheModel - Database Down and external app flush

Posted by James Johnson <jm...@hotmail.com>.
Thanks Sven for the quick response. I am a beginner to iBatis, so I
apologize in advance if I don't know some of the answers to your questions.
I'll try my best.

In regards to 2), I figured that was the case by the same reasoning. I just
wanted to make sure with someone who had more experience with iBatis. 
However, is it possible one iBatis application receive notifications from 
another iBatis application to flush cache?

In regards to 1), the full stack trace is below. Thanks for looking at this.
Also, how would I deactivate the ping query?

Exception in thread "main" 
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get 
JDBC Connection; nested exception is com.mysql.jdbc.CommunicationsException: 
Communications link failure due to underlying exception:



** BEGIN NESTED EXCEPTION **



java.net.SocketException

MESSAGE: java.net.ConnectException: Connection refused: connect



STACKTRACE:



java.net.SocketException: java.net.ConnectException: Connection refused: 
connect

      at 
com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156)

      at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:284)

      at com.mysql.jdbc.Connection.createNewIO(Connection.java:2555)

      at com.mysql.jdbc.Connection.<init>(Connection.java:1485)

      at 
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)

      at 
org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37)

      at 
org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290)

      at 
org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:771)

      at 
org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:95)

      at 
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)

      at 
org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)

      at 
org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)

      at 
org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:178)

      at 
org.springframework.orm.ibatis.SqlMapClientTemplate.executeWithListResult(SqlMapClientTemplate.java:204)

      at 
org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClientTemplate.java:243)

      at data.SqlMapClientTestDao.getAll(SqlMapClientTestDao.java:25)

      at service.Main.run(Main.java:37)

      at service.Main.main(Main.java:55)





** END NESTED EXCEPTION **







Last packet sent to the server was 0 ms ago.

com.mysql.jdbc.CommunicationsException: Communications link failure due to 
underlying exception:



** BEGIN NESTED EXCEPTION **



java.net.SocketException

MESSAGE: java.net.ConnectException: Connection refused: connect



STACKTRACE:



java.net.SocketException: java.net.ConnectException: Connection refused: 
connect

      at 
com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156)

      at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:284)

      at com.mysql.jdbc.Connection.createNewIO(Connection.java:2555)

      at com.mysql.jdbc.Connection.<init>(Connection.java:1485)

      at 
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)

      at 
org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37)

      at 
org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290)

      at 
org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:771)

      at 
org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:95)

      at 
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)

      at 
org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)

      at 
org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)

      at 
org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:178)

      at 
org.springframework.orm.ibatis.SqlMapClientTemplate.executeWithListResult(SqlMapClientTemplate.java:204)

      at 
org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClientTemplate.java:243)

      at data.SqlMapClientTestDao.getAll(SqlMapClientTestDao.java:25)

      at service.Main.run(Main.java:37)

      at service.Main.main(Main.java:55)





** END NESTED EXCEPTION **







Last packet sent to the server was 0 ms ago.

      at com.mysql.jdbc.Connection.createNewIO(Connection.java:2621)

      at com.mysql.jdbc.Connection.<init>(Connection.java:1485)

      at 
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)

      at 
org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37)

      at 
org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290)

      at 
org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:771)

      at 
org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:95)

      at 
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)

      at 
org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)

      at 
org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)

      at 
org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:178)

      at 
org.springframework.orm.ibatis.SqlMapClientTemplate.executeWithListResult(SqlMapClientTemplate.java:204)

      at 
org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClientTemplate.java:243)

      at data.SqlMapClientTestDao.getAll(SqlMapClientTestDao.java:25)

      at service.Main.run(Main.java:37)

      at service.Main.main(Main.java:55)



----- Original Message ----- 
From: "Sven Boden" <li...@pandora.be>
To: <us...@ibatis.apache.org>
Sent: Wednesday, April 19, 2006 4:48 PM
Subject: Re: cacheModel - Database Down and external app flush


>
> For 1):
> do you have the full nested stacktrace? Did you deactivate the ping query? 
> and are you sure the exception originates in iBATIS (we'll see from the 
> full stacktrace). The intention of a cache is to speed things up, it's not 
> the intention to have a complete in-core database.
>
> For 2)
> There's no way for iBATIS to be automatically aware of updates by other 
> applications. This is a problem for every database application, not just 
> iBATIS. If you would develop an application without iBATIS (with your own 
> developed caching), how would you know in your application whether another 
> application updated your database?
>
> Regards,
> Sven
>
> James Johnson wrote:
>
>>I have a few questions regarding iBatis cacheModel. All help is greatly 
>>appreciated.
>>
>>1) When the iBatis cacheModel is used, a connection to the database server 
>>appears to be still required. The data has been cached, so I'm not sure 
>>why the database server needs to be up after caching the data.
>>For exapmle, I have test code that basically returns the same row of data 
>>n times. As expected, the data is cached and remains unchanged desipte 
>>making updates using the database command line client (i.e. outside of my 
>>program). During the ith (1<i<=n) try, I shutdown the database server. I 
>>would expect iBatis to just use the cache results and not require the 
>>database server to be up. However, instead I get the following error when 
>>I bring the database server down:
>>Exception in thread "main" 
>>org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get 
>>JDBC Connection; nested exception is 
>>com.mysql.jdbc.CommunicationsException: Communications link failure due to 
>>underlying exception:
>>** BEGIN NESTED EXCEPTION **
>>java.net.SocketException
>>
>>MESSAGE: java.net.ConnectException: Connection refused: connect
>>
>>
>>I would like to have mechanism that allows the application to use cached 
>>data in the event the database server is down as it does when the database 
>>server is up. Is the cachModel capable of providing this functionality? 
>>Why does the database server need to be up when iBatis is using cached 
>>results?
>>
>>2) By specifying the flushOnExecute, iBatis will flush the cache when a 
>>certian statement(s) is executed. Is there a way for iBatis to flush the 
>>cache when anything (i.e. another application) makes an update, insert or 
>>delete?
>>
>>
>
> 

Re: cacheModel - Database Down and external app flush

Posted by Sven Boden <li...@pandora.be>.
For 1):
do you have the full nested stacktrace? Did you deactivate the ping 
query? and are you sure the exception originates in iBATIS (we'll see 
from the full stacktrace). The intention of a cache is to speed things 
up, it's not the intention to have a complete in-core database.

For 2)
There's no way for iBATIS to be automatically aware of updates by other 
applications. This is a problem for every database application, not just 
iBATIS. If you would develop an application without iBATIS (with your 
own developed caching), how would you know in your application whether 
another application updated your database?

Regards,
Sven

James Johnson wrote:

>I have a few questions regarding iBatis cacheModel. All help is greatly appreciated.
>
>1) When the iBatis cacheModel is used, a connection to the database server appears to be still required. The data has been cached, so I'm not sure why the database server needs to be up after caching the data. 
>
>For exapmle, I have test code that basically returns the same row of data n times. As expected, the data is cached and remains unchanged desipte making updates using the database command line client (i.e. outside of my program). During the ith (1<i<=n) try, I shutdown the database server. I would expect iBatis to just use the cache results and not require the database server to be up. However, instead I get the following error when I bring the database server down: 
>
>Exception in thread "main" org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: 
>
>** BEGIN NESTED EXCEPTION ** 
>
>java.net.SocketException
>
>MESSAGE: java.net.ConnectException: Connection refused: connect
>
>
>I would like to have mechanism that allows the application to use cached data in the event the database server is down as it does when the database server is up. Is the cachModel capable of providing this functionality? Why does the database server need to be up when iBatis is using cached results?
>
>2) By specifying the flushOnExecute, iBatis will flush the cache when a certian statement(s) is executed. Is there a way for iBatis to flush the cache when anything (i.e. another application) makes an update, insert or delete?
>
>  
>