These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Dirty reads problem with L2 cache asynch strategies
PostPosted: Thu Jun 11, 2009 6:04 am 
Newbie

Joined: Thu Jun 11, 2009 4:31 am
Posts: 2
Hibernate version : 3.3.0.SP1

Hello all !

I think there is a problem with asynchronous L2 cache strategies when putting data from load, as done by CacheConcurrencyStrategy.put() / EntityRegionAccessStrategy.putFromLoad() :

These methods are called immediately after the select, so that the object passed can contain uncommitted modifications. If we put it in the cache at this time (as NonstrictReadWriteCache does), and the modification is rollbacked, our cache then contains stale data.

This will happen for example if a transaction modifies database data using hql / sql, and then retrieves the data it just modified using session.load().


I was wondering if such a problem was known, and how it was supposed to be dealt with...?


Please find my suggestions below. If the solution is already well known, please ignore them :)

It seems to me that a solution would be to only 'putFromLoad' after transaction completes, with an afterPutFromLoad method. Then :
- No uncommitted data is put into the cache, which solves the dirty reads problem
- The transaction that did the modifications will use the first level cache, so we won't have performance issues.

That would be consistent with general asynchronous strategies behavior, which is to never put modified data into the cache until after the transaction completes.

The only problem is that the afterPutFromLoad method could override changes made by afterUpdate methods : to prevent this, we can, instead of just remove data entries invalidated by afterUpdate, put a (empty) cache entry that contains the invalidation time. Then, if putFromLoad transaction timestamp is before invalidation time, we don't do it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.