History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: CACHE-145
Type: Improvement Improvement
Status: Open Open
Priority: Major Major
Assignee: Andres March
Reporter: Michael Greer
Votes: 6
Watchers: 5
Operations

If you were logged in you would be able to see more operations.
OSCache

Allow clustered cached to send update notices when a cached object is modified

Created: 23/Feb/05 11:26 AM   Updated: 21/Jan/07 01:55 PM
Component/s: Cluster
Affects Version/s: 2.1.1
Fix Version/s: 3.0

File Attachments: 1. Java Source File Cache.java (34 kb)
2. Java Source File OSCache.java (4 kb)
3. Java Source File OSCacheProvider.java (2 kb)
4. Java Source File UpdatingJavaGroupsListener.java (2 kb)

Environment: Hibernate2+3


 Description  « Hide
When using OSCache as the cache provider for Hibernate, the caches are not kept in sync in a cluster. This is because if an object is modified on one node, no notification is sent to the other nodes to update their cache for that object. They therefore maintain the old object in their cache, which is out of sync with the database. This can be very dangerous for data.
In order to correct this, I have extended JavaGroupsListener:
1) Add anew Event type: REMOVE_KEY
2) Send out REMOVE_KEY when a cache is updated locally (not added). Currently it does nothing on update.
3) On receiving a REMOVE_KEY notice, it removes the keyed cache entry. This requires a modification of Cache in OSCache to make removeEntry public instead of protected.

Removal of the entry, rather than flushing, is necessary to keep the nodes from sending an update event to the cluster when they reload the flushed entry, which leads to endless propogation of the update and undermines the purpose of a cache. Removing the entry avoids this, as the nodes do an add, and not update, on the next load of the entry. Adds are not broadcast, as they are of only local interest.

I also modified the Hibernate3 OSCache and OSCacheProvider sources to implement regions, as stated on the wiki for Hibernate 2.1 I will submit those changes on their JIRA.

 All   Comments   Change History      Sort Order:
Michael Greer - [23/Feb/05 11:28 AM ]
My class that extends JavaGroupsBroadcastingListener to send REMOVE_KEY notices to the cluster when a cache entry is updated locally.
Also, the Cache class with the 2 removeEntry methods made public, so the above class can work.

Michael Greer - [23/Feb/05 11:29 AM ]
HIbernate3 cache provider. Some extra logging needs to be removed before I submit it to their JIRA.

Michael Greer - [23/Feb/05 11:43 AM ]
There is one issue that needs to be addressed for this (it needs testing!).
Since the current OSCache does not provide a public removeEntry() method, the Hibernate3 OSCache I modified calls flush(key) on remove(key). This will lead all the caches to flush that entry, and then send unnecessary updates. I think it should actually get removed, for instance if an object is deleted.
If as I suggested removeEntry is made public, I can change OSCache to call removeEntry instead of flush, which will solve this issue.
What is the current rationale for make ing removeEntry protected?

Andres March - [12/Mar/05 01:10 AM ]
Please let me know if you are still looking at this. I am going to look at your code now. The remove can probably be public but I need to go over all the use cases. I cannot commit any of it until I have full unit tests, so it might take me a while if I'm witing them. Thanks for the contributions!

Michael Greer - [12/Mar/05 08:05 AM ]
Yes I am still watching this, and in fact it is a good week for me to contemplate this again. Of course unit tests take a long time: if there is any help I can give, please tell me.

Andres March - [13/Mar/05 03:03 PM ]
I am going to try and get this in 2.2. The first thing I'd like to do is make removeEntry public and add your listener as an option for people to use. Hopefully, other people will take interest and we can see more clearly the impact of this functionality.

Michael Greer - [14/Mar/05 09:57 AM ]
That sounds like a great idea. Let me know what I can do. I should submit a new Hibernate OSCache file that uses the remove, for one.

Andres March - [14/Mar/05 10:57 AM ]
Cool. I should be able to do something on this by week end but this is targeted for the 2.2 release.

Andres March - [17/Mar/05 02:27 PM ]
removeEntry(String key) has been made public and exposed in the GeneralCacheAdministrator. This is in CVS HEAD.

John Zhang - [17/May/05 09:09 AM ]
Could you also make public for the removeEntry(String, String)? In the UpdatingJavaGroupsListener.java, it needs to call: cache.removeEntry(((String) message.getData()),CLUSTER_ORIGIN );

John Zhang - [17/May/05 09:18 AM ]
Also, if you could integrate the code from UpdatingJavaGroupsListener.java to the super class, it would be perfect. Then I don't need to write subclasses.

Serge Huber - [29/Sep/05 02:56 AM ]
I think this patch is really important as more and more users are using Hibernate in conjunction with OSCache. Without this patch, Hibernate does not work in clustering environments with OSCache. Would it be possible to include this for 2.2 final ?