[jboss-user] [JBossCache] - Optimistic locking behaviour not consistent with pessimistic
rworsnop
do-not-reply at jboss.com
Sun Mar 11 14:30:45 EDT 2007
JBoss Cache version: 1.4.1.SP2
This relates to an issue I am having with Hibernate:
http://forum.hibernate.org/viewtopic.php?p=2343598
When I'm using pessimistic locking, the following code will work:
public static void main(String[] args) throws Exception {
| UserTransaction tx= new DummyUserTransaction(DummyTransactionManager.getInstance());
| TreeCache tree = new TreeCache();
| PropertyConfigurator config = new PropertyConfigurator();
| config.configure(tree, "treecache.xml");
| tree.startService(); // kick start tree cache
|
| try {
| tx.begin();
| tree.put (fqn("/parent/child"), "item", 1 ,option(true));
| tree.remove(fqn("/parent"), option(false));
| tree.remove (fqn("/parent/child"), option(false));
| tx.commit();
| }
| catch(Throwable ex) {
| ex.printStackTrace();
| try { tx.rollback(); } catch(Throwable t) {}
| } finally{
| tree.stopService();
| }
| }
|
| private static Fqn fqn(String s){
| return Fqn.fromString(s);
| }
|
| private static Option option(boolean failSilently){
| Option option = new Option();
| option.setFailSilently( failSilently );
| option.setDataVersion(new DataVersion(){
|
| public boolean newerThan(DataVersion arg0) {
| return false;
| }} );
| return option;
| }
But with optimistic locking, the last remove call will cause the following exception:
org.jboss.cache.CacheException: Unable to find parent node with Fqn /parent
| at org.jboss.cache.interceptors.OptimisticNodeInterceptor.removeNode(OptimisticNodeInterceptor.java:218)
| at org.jboss.cache.interceptors.OptimisticNodeInterceptor.invoke(OptimisticNodeInterceptor.java:110)
| at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:68)
| at org.jboss.cache.interceptors.EvictionInterceptor.invoke(EvictionInterceptor.java:88)
| at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:68)
| at org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor.invoke(OptimisticCreateIfNotExistsInterceptor.java:69)
| at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:68)
| at org.jboss.cache.interceptors.OptimisticValidatorInterceptor.invoke(OptimisticValidatorInterceptor.java:84)
| at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:68)
| at org.jboss.cache.interceptors.OptimisticLockingInterceptor.invoke(OptimisticLockingInterceptor.java:126)
| at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:68)
| at org.jboss.cache.interceptors.TxInterceptor.handleNonTxMethod(TxInterceptor.java:365)
| at org.jboss.cache.interceptors.TxInterceptor.invoke(TxInterceptor.java:160)
| at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:68)
| at org.jboss.cache.interceptors.CacheMgmtInterceptor.invoke(CacheMgmtInterceptor.java:183)
| at org.jboss.cache.TreeCache.invokeMethod(TreeCache.java:5776)
| at org.jboss.cache.TreeCache.remove(TreeCache.java:3855)
| at org.jboss.cache.TreeCache.remove(TreeCache.java:3438)
| at com.medq.test.TestTreeCache.main(TestTreeCache.java:48)
|
Is it just a fluke that it works with pessimistic locking, or is optimistic locking not behaving as it should?
Note: The code above reproduces what Hibernate does when it evicts entities.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4026973#4026973
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4026973
More information about the jboss-user
mailing list