|
|
|
Frederic_Bellier
|
I need to have a specific tangosol cache per entity - (or at least per group of entity): I am trying to use the annotation @DataCache to make this happen - unfortunately it does not work. openjpa always uses the tangosol cache define din the persistence xml file - basically the default cache. I tried to set the @DataCache annotation to: @DataCache(enabled = true, name = "tangosol(TangosolCacheName=b,TangosolCacheType=named,ClearOnClose=false)", timeout = -1) I also tried @DataCache(enabled = true, name = "b", timeout = -1) But none format worked. Again - all entities are currently going to the default Tangosol cache. It is a must for our project to be able to cache our entities in specific cache (We are using Tangosol). Using one cache only for all entities in the system almost removes all the benefit of the cache all together - and we might as well not have one. How can I accomplish that? Should I implement our own RemoteCommitProvider? (This seems complicated becuase I do not know all the internal of openjpa) Can I use the entity callback method to talk to the cache myself? (This seems easy) - but in order to use it I need to be sure all entity callback methods will be called even when I save a top level object in the graph - I mean I need all the other entities related to the parent one to have teir callback fired if they get saved too. Please help - this is a huge issue for us. Thank you, Frederic |
||||||||||||||||
|
Kevin Sutter
|
Frederic,
I'm not an expert with the Tangosol plugin, but in general, the OpenJPA DataCache plugin is on a per-EntityManager basis. So, if configured, all Entities associated with a given PersistenceContext (EntityManager) could be cached. You then have the ability to designate certain Entities as being non-cached. Or, you could go in reverse and designate only those Entities that you do wish to cache. If your question is more specific to the Tangosol plugin, then you'll have to ask the development team that developed that plugin. BEA? Tangosol? Not sure. The OpenJPA code only supports the DataCache plugin capabilities (and the built-in DataCache implementation). The other cache plugins (ie, Tangosol, ObjectGrid, etc) are supported by other development organizations. Thanks, Kevin On Thu, Mar 27, 2008 at 1:00 PM, <[hidden email]> wrote: > > I need to have a specific tangosol cache per entity - (or at least per > group of entity): > > I am trying to use the annotation @DataCache to make this happen - > unfortunately it does not work. openjpa always uses the tangosol cache > define din the persistence xml file - basically the default cache. > > I tried to set the @DataCache annotation to: > @DataCache(enabled = true, name = > > "tangosol(TangosolCacheName=b,TangosolCacheType=named,ClearOnClose=false)", > timeout = -1) > > I also tried > @DataCache(enabled = true, name = "b", timeout = -1) > > But none format worked. Again - all entities are currently going to the > default Tangosol cache. > > It is a must for our project to be able to cache our entities in specific > cache (We are using Tangosol). Using one cache only for all entities in > the > system almost removes all the benefit of the cache all together - and we > might as well not have one. > > How can I accomplish that? > Should I implement our own RemoteCommitProvider? (This seems complicated > becuase I do not know all the internal of openjpa) > Can I use the entity callback method to talk to the cache myself? (This > seems easy) - but in order to use it I need to be sure all entity callback > methods will be called even when I save a top level object in the graph - > I > mean I need all the other entities related to the parent one to have teir > callback fired if they get saved too. > > Please help - this is a huge issue for us. > > Thank you, > > Frederic > > > |
||||||||||||||||
|
Frederic_Bellier
|
I guess I am sending the email to this list becuase some people working on
openjpa are making statement on the web - podcast - etc... that they have done for openjpa a great integration with Tangosol cache. I think his name is David Linskey or something like that - anyhow it does not matter... In any case - I am just trying to understand what is possible and what is not with openjpa as it relates to L2 cache. I think Tangosol plug in for openjpa is totally different - they are promoting the use of Tangosol first with a backing map that uses openjpa for the persistence to the DB. The problem with their approach is that I am loosing all the benift of the openjpa O/R mapping and relationship management in particular. So I am using the opnejpa approach first - which means the L2 cache is on the side. And I believe I am only using openjpa code - meaning the persistence xml defines the following: <property name="kodo.DataCache" value="tangosol(TangosolCacheName=a,TangosolCacheType=named,ClearOnClose=false)"/> This - I believe - is a regular openjpa functionality. Isn't it? So my question is why when I specify the data cache annotation - openjpa does not honor this particular cache for this particular entity? @DataCache(enabled = true, name = "tangosol(TangosolCacheName=b,TangosolCacheType=named,ClearOnClose=false)", timeout = -1) I just want to specify which L2 cache to use per entity. Becuase if I do it at the EntityManagerFactory - then all entities will have to use the same cache. Which would mean that I would need to consider all the data to be equal in terms of how it is used by the system - which of course is not correct and will remove the performance benefit of using an L2 cache (well most of them - some will remain - but for sure it would be a shame). Think about a clustered application with data being clustered and other being local only and you see what I mean by loosing pretty much all benefit from L2 cache - (welcome to serialization overhead nightmare... ;) - my performance will be terrible - plus it would be such a bad design for the application anyhow. The openjpa doc talks about specifying the L2 cache by name per enity via the DataCache annotation. I would like to understand how I can use it. Becuase it seems to be exactly what I need. Except that I can not make it work with Tangsol. I am ssuming that all entities of an object graph are stored in the L2 cache sperately - and not as one big serialized blob for the entire graph. That way when I query for an object deep in my graph I would be able to get it from the cache easily. If so then I would think that assigning each entity to a specific cache would be trivial. BTW - in your previous email I am assuming you are refering to the entityManagerFactory and not the Entitymanager because the L2 cache is at the Factory level and not the entityManager level - otherwise obviously it would not be usefull at all ;) . (Your L1 cache is - and the Tx too of course). Frederic "Kevin Sutter" <[hidden email] om> To [hidden email] cc 03/27/2008 12:32 PM Subject Re: How to set a tangosol cache per entity? Please respond to [hidden email] che.org Frederic, I'm not an expert with the Tangosol plugin, but in general, the OpenJPA DataCache plugin is on a per-EntityManager basis. So, if configured, all Entities associated with a given PersistenceContext (EntityManager) could be cached. You then have the ability to designate certain Entities as being non-cached. Or, you could go in reverse and designate only those Entities that you do wish to cache. If your question is more specific to the Tangosol plugin, then you'll have to ask the development team that developed that plugin. BEA? Tangosol? Not sure. The OpenJPA code only supports the DataCache plugin capabilities (and the built-in DataCache implementation). The other cache plugins (ie, Tangosol, ObjectGrid, etc) are supported by other development organizations. Thanks, Kevin On Thu, Mar 27, 2008 at 1:00 PM, <[hidden email]> wrote: > > I need to have a specific tangosol cache per entity - (or at least per > group of entity): > > I am trying to use the annotation @DataCache to make this happen - > unfortunately it does not work. openjpa always uses the tangosol cache > define din the persistence xml file - basically the default cache. > > I tried to set the @DataCache annotation to: > @DataCache(enabled = true, name = > > > timeout = -1) > > I also tried > @DataCache(enabled = true, name = "b", timeout = -1) > > But none format worked. Again - all entities are currently going to the > default Tangosol cache. > > It is a must for our project to be able to cache our entities in specific > cache (We are using Tangosol). Using one cache only for all entities in > the > system almost removes all the benefit of the cache all together - and we > might as well not have one. > > How can I accomplish that? > Should I implement our own RemoteCommitProvider? (This seems complicated > becuase I do not know all the internal of openjpa) > Can I use the entity callback method to talk to the cache myself? (This > seems easy) - but in order to use it I need to be sure all entity > methods will be called even when I save a top level object in the graph - > I > mean I need all the other entities related to the parent one to have teir > callback fired if they get saved too. > > Please help - this is a huge issue for us. > > Thank you, > > Frederic > > > |
||||||||||||||||
|
Pinaki Poddar
|
Firstly, out-of-the-box OpenJPA does not provide an integration with Tangosol cache. OPenJPA, however, does provide a flexible/pluggable mechanism for L2 cache of your choice. Out-of-the-box OpenJPA provides a concrete implementation which can target a particular entity to a named partition of L2 cache.
But Kodo (which was the parent and now a child of OpenJPA) does provide other L2 cache plug-ins including Tangosol. Your supplied configuration suggests that you have access to Kodo. But even with Kodo, currently, there is no mechanism to cache entities in different named partitions of Tangosols cache. All the cached entities go to a single Tangosol cache though name of that cache can be configured. However, because of plug-in architecture of OpenJPA/Kodo, it is relatively inexpensive to extend the behavior you are seeking i.e. targeting entities to different named partitions of a Tangosol cache. This extension is helped by the provision of OpenJPA that carries name of the target L2 cache partition in its internal representation of Class metadata (see ClassMetaData.getDataCacheName()).
Pinaki
|
||||
|
Frederic_Bellier
|
Hi Pinaki -
This sounds quite interesting. Assuming I want to write my own plugin for the cache. How would I go about this? For example: What interface should I implement? How can I tell openjpa to use my implementation? Which class has an implementation of that interface so I can use that as an example? Is this plugin managed by openjpa? By that I mean - I am guarranted that the plugin will be called at the appropriate time by openjpa and therefore all I would need to worry about is making the call to the cache? Yesterday - I was looking into the datacache namespace of openjpa code base. It seems to be what I am looking for. But I could not see the calls being made that would also pass along the class information of the entity - which I need to find the right cache. I only saw the oid object being passed. Do this oid object contain the extra info I would need? Thank you for pointing me in the right direction, Frederic PS: I just saw that hibernate offer the functionality I am looking for. But I already invested quite some time with openjpa - so switching to hibernate now would have a cost. Would be nice if doing the proper plugin was easy. Pinaki Poddar <[hidden email] rg> To [hidden email] cc 03/28/2008 10:57 AM Subject Re: How to set a tangosol cache per entity? Please respond to [hidden email] che.org Firstly, out-of-the-box OpenJPA does not provide an integration with Tangosol cache. OPenJPA, however, does provide a flexible/pluggable mechanism for L2 cache of your choice. Out-of-the-box OpenJPA provides a concrete implementation which can target a particular entity to a named partition of L2 cache. But Kodo (which was the parent and now a child of OpenJPA) does provide other L2 cache plug-ins including Tangosol. Your supplied configuration suggests that you have access to Kodo. But even with Kodo, currently, there is no mechanism to cache entities in different named partitions of Tangosols cache. All the cached entities go to a single Tangosol cache though name of that cache can be configured. However, because of plug-in architecture of OpenJPA/Kodo, it is relatively inexpensive to extend the behavior you are seeking i.e. targeting entities to different named partitions of a Tangosol cache. This extension is helped by the provision of OpenJPA that carries name of the target L2 cache partition in its internal representation of Class metadata (see ClassMetaData.getDataCacheName()). Frederic_Bellier wrote: > > I guess I am sending the email to this list becuase some people working on > openjpa are making statement on the web - podcast - etc... that they have > done for openjpa a great integration with Tangosol cache. I think his name > is David Linskey or something like that - anyhow it does not matter... > > In any case - I am just trying to understand what is possible and what is > not with openjpa as it relates to L2 cache. > > I think Tangosol plug in for openjpa is totally different - they are > promoting the use of Tangosol first with a backing map that uses openjpa > for the persistence to the DB. The problem with their approach is that I > am > loosing all the benift of the openjpa O/R mapping and relationship > management in particular. > So I am using the opnejpa approach first - which means the L2 cache is on > the side. And I believe I am only using openjpa code - meaning the > persistence xml defines the following: > <property name="kodo.DataCache" > > This - I believe - is a regular openjpa functionality. Isn't it? > > So my question is why when I specify the data cache annotation - openjpa > does not honor this particular cache for this particular entity? > @DataCache(enabled = true, name = > "tangosol(TangosolCacheName=b,TangosolCacheType=named,ClearOnClose=false)", > timeout = -1) > > > I just want to specify which L2 cache to use per entity. > Becuase if I do it at the EntityManagerFactory - then all entities will > have to use the same cache. Which would mean that I would need to consider > all the data to be equal in terms of how it is used by the system - which > of course is not correct and will remove the performance benefit of using > an L2 cache (well most of them - some will remain - but for sure it would > be a shame). Think about a clustered application with data being clustered > and other being local only and you see what I mean by loosing pretty much > all benefit from L2 cache - (welcome to serialization overhead > nightmare... > ;) - my performance will be terrible - plus it would be such a bad design > for the application anyhow. > > The openjpa doc talks about specifying the L2 cache by name per enity via > the DataCache annotation. I would like to understand how I can use it. > Becuase it seems to be exactly what I need. Except that I can not make it > work with Tangsol. > > I am ssuming that all entities of an object graph are stored in the L2 > cache sperately - and not as one big serialized blob for the entire > That way when I query for an object deep in my graph I would be able to > get > it from the cache easily. If so then I would think that assigning each > entity to a specific cache would be trivial. > > BTW - in your previous email I am assuming you are refering to the > entityManagerFactory and not the Entitymanager because the L2 cache is at > the Factory level and not the entityManager level - otherwise obviously it > would not be usefull at all ;) . (Your L1 cache is - and the Tx too of > course). > > Frederic > > > > > > "Kevin Sutter" > <[hidden email] > om> To > [hidden email] > cc > 03/27/2008 12:32 > PM Subject > Re: How to set a tangosol cache per > entity? > Please respond to > [hidden email] > che.org > > > > > > > > Frederic, > I'm not an expert with the Tangosol plugin, but in general, the OpenJPA > DataCache plugin is on a per-EntityManager basis. So, if configured, all > Entities associated with a given PersistenceContext (EntityManager) could > be > cached. You then have the ability to designate certain Entities as being > non-cached. Or, you could go in reverse and designate only those > that you do wish to cache. > > If your question is more specific to the Tangosol plugin, then you'll have > to ask the development team that developed that plugin. BEA? Tangosol? > Not sure. The OpenJPA code only supports the DataCache plugin > capabilities > (and the built-in DataCache implementation). The other cache plugins (ie, > Tangosol, ObjectGrid, etc) are supported by other development > organizations. > > Thanks, > Kevin > > On Thu, Mar 27, 2008 at 1:00 PM, <[hidden email]> wrote: > >> >> I need to have a specific tangosol cache per entity - (or at least per >> group of entity): >> >> I am trying to use the annotation @DataCache to make this happen - >> unfortunately it does not work. openjpa always uses the tangosol cache >> define din the persistence xml file - basically the default cache. >> >> I tried to set the @DataCache annotation to: >> @DataCache(enabled = true, name = >> >> > >> timeout = -1) >> >> I also tried >> @DataCache(enabled = true, name = "b", timeout = -1) >> >> But none format worked. Again - all entities are currently going to the >> default Tangosol cache. >> >> It is a must for our project to be able to cache our entities in specific >> cache (We are using Tangosol). Using one cache only for all entities in >> the >> system almost removes all the benefit of the cache all together - and we >> might as well not have one. >> >> How can I accomplish that? >> Should I implement our own RemoteCommitProvider? (This seems complicated >> becuase I do not know all the internal of openjpa) >> Can I use the entity callback method to talk to the cache myself? (This >> seems easy) - but in order to use it I need to be sure all entity > callback >> methods will be called even when I save a top level object in the graph >> I >> mean I need all the other entities related to the parent one to have teir >> callback fired if they get saved too. >> >> Please help - this is a huge issue for us. >> >> Thank you, >> >> Frederic >> >> >> > > > > -- View this message in context: http://www.nabble.com/How-to-set-a-tangosol-cache-per-entity--tp16336199p16357719.html Sent from the OpenJPA Users mailing list archive at Nabble.com. |
||||||||||||||||
|
Pinaki Poddar
|
> What interface should I implement?
The interface for L2 cache is org.apache.openjpa.datacache.DataCache. > How can I tell openjpa to use my implementation? In META-INF/persistence.xml <property name="openjpa.DataCache" value="acme.org.MyL2DataCache"/> > Which class has an implementation of that interface so I can use that as an example? The basic abstract implementation is available in org.apache.openjpa.datacache.AbstractDataCache. > Is this plugin managed by openjpa? By that I mean - I am guarranted that > the plugin will be called at the appropriate time by openjpa and therefore > all I would need to worry about is making the call to the cache? Yes. Access to OpenJPA internal information is available through org.apache.openjpa.conf.OpenJPAConfiguration instance. When your implementation implements org.apache.openjpa.lib.conf.Configurable (which AbstractDataCache does) -- you have access to OpenJPAConfiguration in right points of initialization life-cyle. Once you have access to configuration, you can navigate to OpenJPAConfiguration.getMetaDataRepositoryInstance() which will tell whatever you want to know of the class level meta-information. Pinaki
|
||||||||||||||||
|
Frederic_Bellier
|
Alright,
Over the weekend I started to look at what it would take me to change the behavior of openjpa to make it do what I need as it relates to the L2 Cache. I started to write a new implementation for that small layer but in order to finish this work I need to understand openjpa better. Otherwise I am writting code without knowing how the design works - which would give a terrible result I am sure ;). So please help me. In fact please help me help you. Once the code is written I could send it your way so we will all benefit from it. I've written a few questions in this email that I need answer to so I can finsih the work. It is a bit long email so please if you know anyhting about openjpa and L2 caching then read on and please respond. Otherwise no need to read further. Thank you very much, Important Reminder - I am not trying to implement an L2 cache at all - I just want to interface with other L2 cache product. My target right now is Tangosol but it should not really matter for this conversation. I am making this clear because some of my questions are related to the fact that the openjpa code I looked at to add an L2 cache plug-in seems to imply that I am implementing my own cache mechanism. First let me say thank you to Pinaki for helping me get started. The interface for L2 cache is org.apache.openjpa.datacache.DataCache So I looked into it and understand it - (good sign) but I have a few questions: - Do I really need to initialize it? It seems that I dont need this but please let me know if I am suppose to do something important in here. - why the writeLock and writeUnlock? Am I suppose to lock the full cache map in there? It seems that it is so but just want to be sure. - But then why not the writeLock(object) and unlock(object)? This methods are part of L2 cache product and obviously are more useful than locking the full cache? - OpenJPA is suppose to use optimistic Tx by default - so why should I lock the cache anyhow? - addExpirationListener() and removeExpirationListener(): I do not understand this. If I implement my own cache then I guess I need this. But an L2 cache product already provides expiration (timeout) of object. So what is this for really? - Is the DataCache implementation suppose to be some kind of a proxy to the real cache? In which case I would need to be notified of certain events - like expiration. - The rest of the interface is clear. But the real code change I have to make seems to actually be somewhere else. I found 2 property that seem quite interesting for this work: <property name="openjpa.DataCache" value="acme.org.MyL2DataCache"/> I also found <property name="openjpa.DataCacheManager" value= "com.cccc.MyL2DataCacheManagerImpl"/> - If I set the openjpa.DataCacheManager property - will it instanciate my own cache manager? - If so then why would I need to set the property openjpa.DataCache since the cache manager is the own creating the DataCache instances? - Do I need the property openjpa.DataCache only if I dont chnage the DataCacheManager? I looked into that DataCacheManager class and it actually seem to be my starting point. The current implementation has only one cache and it ignores the name value - and this is the beginning of the problem. So I already rewrote that class. - will this property instanciate my new implementation? - the one million dollar question: Will openjpa call my implementation getDataCache() method with the proper cache name defined by the @DataCache annotation of the entity? - Assuming openjpa does call the DataCacheManager.getDataCache(name) and passes the name properly - then am I guarrantee that openjpa will always make the right call to get the right cache whenever it works on a different entities? By that I mean - if I have entity A in cache a and entity B in cache b - and If A contains many B - then when I save A with cascade.persist = true - then I need to be sure that openjpa will call DataCacheManager.getDataCache(a) to put A in cache a, and then call DataCacheManager.getDataCache(b) to putAll(Bs) in cache b? - This is a critical part of course - so I am hopping very hard that openjpa will behave that way. In the unfortunate event that openjpa would not call the cache manager to get the proper cache whenever required then I suppose an alternative would be to reimplement the call to DataCache.commit(Collection additions, Collection newUpdates, Collection existingUpdates, Collection deletes). In which case I would have to let the cache manager pretend there is only one cache - and in the DataCache class I would need to dispatch all the calls to the right cache. But for this to work I need access to the entity type and in particular the entity DataCache name for all entities that the commit method deals with. This method takes DataCachePCData and ObjectIDs. - How do I get the data cache name from the DataCachePCData instances? - How do I get the data cache name from the objectIds passed? Thank you for your help in advance, Frederic Pinaki Poddar <[hidden email] rg> To [hidden email] cc 03/28/2008 01:43 PM Subject Re: How to set a tangosol cache per entity? Please respond to [hidden email] che.org > What interface should I implement? The interface for L2 cache is org.apache.openjpa.datacache.DataCache. > How can I tell openjpa to use my implementation? In META-INF/persistence.xml <property name="openjpa.DataCache" value="acme.org.MyL2DataCache"/> > Which class has an implementation of that interface so I can use that as > an example? The basic abstract implementation is available in org.apache.openjpa.datacache.AbstractDataCache. > Is this plugin managed by openjpa? By that I mean - I am guarranted that > the plugin will be called at the appropriate time by openjpa and therefore > all I would need to worry about is making the call to the cache? Yes. Access to OpenJPA internal information is available through org.apache.openjpa.conf.OpenJPAConfiguration instance. When your implementation implements org.apache.openjpa.lib.conf.Configurable (which AbstractDataCache does) -- you have access to OpenJPAConfiguration in right points of initialization life-cyle. Once you have access to configuration, you can navigate to OpenJPAConfiguration.getMetaDataRepositoryInstance() which will tell whatever you want to know of the class level meta-information. -- View this message in context: http://www.nabble.com/How-to-set-a-tangosol-cache-per-entity--tp16336199p16361757.html Sent from the OpenJPA Users mailing list archive at Nabble.com. |
||||||||||||||||
|
Pinaki Poddar
|
Hi,
The attached zip file contains the implementation of a OpenJPA DataCache plug-in for Coherence Distributed Caching Product. The plug-in honors the 'name' property value of @DataCache annotation in a persistent class X to cache instances of X to a corresponding named partition in Coherence. The plug-in is activated by the following configuration in META-INF/persistence.xml <property name="openjpa.DataCacheManager" value="coherence"/> The ProductDerivation magic wires up other appropriate plug-ins. To use it, add coherence-openjpa.jar to your classpath. This plug-in is somewhat differs in spirit from its counterpart TangosolCache (available in Kodo) in a sense that this one leaves *every* configuration of the cache to Coherence including how changes are communicated in a distributed environment i.e. OpenJPA effectively relinquishes its responsibility to broadcast changes via RemoteCommitProvider to other, possibly, remote L2 caches. This plug-in also recognizes that the instances of different classes may be cached to different Coherence partitions (Kodo version put all of them in one single named partition). The source code is provided (without any warranty or copyright). Usage is exemplified via JUnit Test cases and a simple persistence.xml configuration. The build script requires to be edited for your local environment. Good night & Good luck -- Pinaki coherence-openjpa.zip Pinaki
|
||||||||||||||||
|
Frederic_Bellier
|
Hi Pinaki -
Thank you for the sample plug in. It was very helpful and really help me get started in putting together a Tangosol plug in for kodo/openjpa. Right now we are only testing the plug in with openjpa - I will try to use it with kodo when the plug in will be finished. I spent quite some time going through the openjpa code. In particular everything that has to do with store manager - broker - datacache - configuration - etc... I am writting a plug in for Tangosol that has to be as efficient as I can make it - our focus here is code quality and performance - so this plug in as to be clean and efficient. So far it is going pretty well - basically it is working but not fully tested. But I have a few questions to make sure I did it right. I noticed that the store manager (DataCacheStoreManager) in openjpa handles the multiple cache concept very well (nice to see some good code/design - congratulation to whomever wrote it). So I am writing a DataCache plugin that will leverage the good work done in the StoreManager - that is to say allow the store manager to call the right specific cache from the DataCacheManager since it already looked up the proper cache name and in fact was coded to do this well - this code is in DataCacheStoreManager. updateCaches() method (again that is great code and it is exactly what I was hoping it will do). Your sample was leveraging the system wide datacache and do the lookup itself to find out which cache to use. So basically this was duplicating quite some work done already by the store manager and was not very efficient. Anyway - the new plugin has a new DataCacheManager - a new DataCache - a new SystemDataCache which basically is what you sent me and a new QueryCache. Here are my questions: Q: difference between datacache and systemDataCache? So I created a DataCache manager that manages multiple datacaches - one for each named cache - plus one systemWideDataCache and one systemWideQueryCache. I kept around the concept of the systemWideDataCache for now - becuase I can see the broker gets a reference to it. But I do not see it being used. Except by OpenJPAEntitymanagerFactory.getStoreCache(). What is the exact concept behind the system wide datacache? Why does the broker gets a reference to it right when it is created? Is it just a simplified way to get a proxy to all the caches in case someone needs it and does not know which cache exactly they should get? It seems to just be fullfiling this role. Q: QueryCache scope? As for the QueryCache - my undertsanding is that this cache must be shared across multiple JVMs because otherwise (when data gets removed from the L2 cache for example) the QueryCache could return wrong information. Is this correct? Code comment: The DataCacheStoreManager.transformToVersionSafePCDatas() line 261. This method should call either cache.containsAll() or cache.getAll(). The current implementation is not efficient becuase it makes one call to the cache for each element in the collection. The AbstractDataCache.putAllInternal() method suffers from the same issues. This is OK becuase I will overwrite this in the new plugin but I would think someone from the openjpa developer would want to fix that in there too. That way the base class could actually be used as a base class to write L2 cache plugins. There should be inside the openjpa.datacache namespace an AbstractDataCache class that has nothing to do with RemoteEvent and another one extending it that will also include the RemoteEvent methods. That way it will be easier to implement various L2 cache plugin on top of a clean class. OpenJPaID - The openjpaId class has a method to output a nice format key.toString() which is type+objectId. This method has been overwritten by children classes. Why is this? The overwritten method only outputs the objectId and therefore is not convenient when looking into the cache. Can this be reversed? Even the logging output is not useful with only the objectId (think about saving multiple object from a graph with same int value for PK - in such a case the output does not say which class was saved properly or not. The alternative is to use a nice String as the key for the cache but this is not efficient compare to using the hashcode of OpenJpaId. The EntitymanagerFactoryImpl.getStoreCache(String cacheName) . This method calls DataCacheManage.getDataCache(cacheName). I think it should call DataCachemanager.getDataCache(cacheName, true) to make sure if the cache does not exist it will get created. Unless of course this is the behavior specified by JPA spec. This is important becuase otherwise we get StoreCacheImpl reference with a DelegatingDataCache reference with a null cache reference inside. This generates a lot of bugs becuase it is not good practices to instanciate all the namedCache at startup since noone can know upfront whcih one will actually be used. The current DataCacheManagerImpl does not suffer from this issue becuase there is only one dataCache. But based on a DataCacheManager implementation with multiple named cache - which is what I am implementing now - then this does not work anymore. Moreover, I cannot chnage the behavior of getDataCache(String name) becuase the interface says: /** * Return the named data cache, or null if it does not exist. */ public DataCache getDataCache(String name); Frederic. PS: Is openjpa interested in incorporating this Tangosol plugin code in the product when I am finished with it? It would better for us if we dont have to maintain it in the future. I would think openjpa would like to start including plugins for various L2 cache product and Coherence would be a good start. Moreover, this plugin is faster than the one that use to be in kodo - becuase I am removing all the issues that were in there. Pinaki Poddar <[hidden email] rg> To [hidden email] cc 03/29/2008 11:11 PM Subject Re: How to write a L2 cache plug in that honors the DataCache Please respond to annotation? [hidden email] che.org Hi, The attached zip file contains the implementation of a OpenJPA DataCache plug-in for Coherence Distributed Caching Product. The plug-in honors the 'name' property value of @DataCache annotation in a persistent class X to cache instances of X to a corresponding named partition in Coherence. The plug-in is activated by the following configuration in META-INF/persistence.xml <property name="openjpa.DataCacheManager" value="coherence"/> The ProductDerivation magic wires up other appropriate plug-ins. To use it, add coherence-openjpa.jar to your classpath. This plug-in is somewhat differs in spirit from its counterpart TangosolCache (available in Kodo) in a sense that this one leaves *every* configuration of the cache to Coherence including how changes are communicated in a distributed environment i.e. OpenJPA effectively relinquishes its responsibility to broadcast changes via RemoteCommitProvider to other, possibly, remote L2 caches. This plug-in also recognizes that the instances of different classes may be cached to different Coherence partitions (Kodo version put all of them in one single named partition). The source code is provided (without any warranty or copyright). Usage is exemplified via JUnit Test cases and a simple persistence.xml configuration. The build script requires to be edited for your local environment. Good night & Good luck -- Pinaki http://www.nabble.com/file/p16378911/coherence-openjpa.zip coherence-openjpa.zip -- View this message in context: http://www.nabble.com/How-to-set-a-tangosol-cache-per-entity--tp16336199p16378911.html Sent from the OpenJPA Users mailing list archive at Nabble.com. |
||||||||||||||||
|
Drewz
|
Frederic,
How did your tangosol implementation go? I'm doing similar work, and thus would be interested to see if this plugin was contributed back to OpenJPA. We would definitely like to expand on any work already done on this. Thanks, Drew
|
||||||||||||||||
|
Kevin Sutter
|
FYI... Another example of a L2 Cache plugin for OpenJPA was done by
EhCache... http://openjpa.apache.org/2009/07/28/ehcache-plugin-available-for-openjpa.html http://ehcache.org/ http://ehcache.org/documentation/openjpa_provider.html http://ehcache.sourceforge.net/download.html On Thu, Oct 8, 2009 at 1:52 PM, Drewz <[hidden email]> wrote: > > Frederic, > > How did your tangosol implementation go? I'm doing similar work, and thus > would be interested to see if this plugin was contributed back to OpenJPA. > We would definitely like to expand on any work already done on this. > > Thanks, > > Drew > > > Frederic_Bellier wrote: > > > > Hi Pinaki - > > > > Thank you for the sample plug in. It was very helpful and really help me > > get started in putting together a Tangosol plug in for kodo/openjpa. > > Right now we are only testing the plug in with openjpa - I will try to > use > > it with kodo when the plug in will be finished. > > > > I spent quite some time going through the openjpa code. In particular > > everything that has to do with store manager - broker - datacache - > > configuration - etc... > > I am writting a plug in for Tangosol that has to be as efficient as I can > > make it - our focus here is code quality and performance - so this plug > in > > as to be clean and efficient. So far it is going pretty well - basically > > it > > is working but not fully tested. But I have a few questions to make sure > I > > did it right. > > > > I noticed that the store manager (DataCacheStoreManager) in openjpa > > handles > > the multiple cache concept very well (nice to see some good code/design - > > congratulation to whomever wrote it). So I am writing a DataCache plugin > > that will leverage the good work done in the StoreManager - that is to > say > > allow the store manager to call the right specific cache from the > > DataCacheManager since it already looked up the proper cache name and in > > fact was coded to do this well - this code is in DataCacheStoreManager. > > updateCaches() method (again that is great code and it is exactly what I > > was hoping it will do). > > Your sample was leveraging the system wide datacache and do the lookup > > itself to find out which cache to use. So basically this was duplicating > > quite some work done already by the store manager and was not very > > efficient. > > Anyway - the new plugin has a new DataCacheManager - a new DataCache - a > > new SystemDataCache which basically is what you sent me and a new > > QueryCache. > > > > Here are my questions: > > > > Q: difference between datacache and systemDataCache? > > So I created a DataCache manager that manages multiple datacaches - one > > for > > each named cache - plus one systemWideDataCache and one > > systemWideQueryCache. > > I kept around the concept of the systemWideDataCache for now - becuase I > > can see the broker gets a reference to it. But I do not see it being > used. > > Except by OpenJPAEntitymanagerFactory.getStoreCache(). > > What is the exact concept behind the system wide datacache? Why does the > > broker gets a reference to it right when it is created? > > Is it just a simplified way to get a proxy to all the caches in case > > someone needs it and does not know which cache exactly they should get? > It > > seems to just be fullfiling this role. > > > > Q: QueryCache scope? > > As for the QueryCache - my undertsanding is that this cache must be > shared > > across multiple JVMs because otherwise (when data gets removed from the > L2 > > cache for example) the QueryCache could return wrong information. Is this > > correct? > > > > Code comment: > > The DataCacheStoreManager.transformToVersionSafePCDatas() line 261. This > > method should call either cache.containsAll() or cache.getAll(). The > > current implementation is not efficient becuase it makes one call to the > > cache for each element in the collection. > > The AbstractDataCache.putAllInternal() method suffers from the same > > issues. > > This is OK becuase I will overwrite this in the new plugin but I would > > think someone from the openjpa developer would want to fix that in there > > too. That way the base class could actually be used as a base class to > > write L2 cache plugins. > > > > There should be inside the openjpa.datacache namespace an > > AbstractDataCache > > class that has nothing to do with RemoteEvent and another one extending > it > > that will also include the RemoteEvent methods. That way it will be > easier > > to implement various L2 cache plugin on top of a clean class. > > > > OpenJPaID - The openjpaId class has a method to output a nice format > > key.toString() which is type+objectId. This method has been overwritten > by > > children classes. Why is this? The overwritten method only outputs the > > objectId and therefore is not convenient when looking into the cache. Can > > this be reversed? Even the logging output is not useful with only the > > objectId (think about saving multiple object from a graph with same int > > value for PK - in such a case the output does not say which class was > > saved > > properly or not. The alternative is to use a nice String as the key for > > the > > cache but this is not efficient compare to using the hashcode of > > OpenJpaId. > > > > The EntitymanagerFactoryImpl.getStoreCache(String cacheName) . This > method > > calls DataCacheManage.getDataCache(cacheName). > > I think it should call DataCachemanager.getDataCache(cacheName, true) to > > make sure if the cache does not exist it will get created. Unless of > > course > > this is the behavior specified by JPA spec. This is important becuase > > otherwise we get StoreCacheImpl reference with a DelegatingDataCache > > reference with a null cache reference inside. This generates a lot of > bugs > > becuase it is not good practices to instanciate all the namedCache at > > startup since noone can know upfront whcih one will actually be used. The > > current DataCacheManagerImpl does not suffer from this issue becuase > there > > is only one dataCache. But based on a DataCacheManager implementation > with > > multiple named cache - which is what I am implementing now - then this > > does > > not work anymore. > > Moreover, I cannot chnage the behavior of getDataCache(String name) > > becuase > > the interface says: > > /** > > * Return the named data cache, or null if it does not exist. > > */ > > public DataCache getDataCache(String name); > > > > > > Frederic. > > > > PS: Is openjpa interested in incorporating this Tangosol plugin code in > > the > > product when I am finished with it? It would better for us if we dont > have > > to maintain it in the future. I would think openjpa would like to start > > including plugins for various L2 cache product and Coherence would be a > > good start. > > Moreover, this plugin is faster than the one that use to be in kodo - > > becuase I am removing all the issues that were in there. > > > > > > > > > > > > Pinaki Poddar > > <[hidden email] > > rg> > To > > [hidden email] > > > cc > > 03/29/2008 11:11 > > PM > Subject > > Re: How to write a L2 cache plug > in > > that honors the DataCache > > Please respond to annotation? > > [hidden email] > > che.org > > > > > > > > > > > > > > > > > > > > Hi, > > The attached zip file contains the implementation of a OpenJPA > DataCache > > plug-in for Coherence Distributed Caching Product. The plug-in honors the > > 'name' property value of @DataCache annotation in a persistent class X to > > cache instances of X to a corresponding named partition in Coherence. The > > plug-in > > is activated by the following configuration in META-INF/persistence.xml > > > > <property name="openjpa.DataCacheManager" value="coherence"/> > > > > The ProductDerivation magic wires up other appropriate plug-ins. > > > > To use it, add coherence-openjpa.jar to your classpath. > > > > This plug-in is somewhat differs in spirit from its counterpart > > TangosolCache (available in Kodo) in a sense that this one leaves *every* > > configuration of the cache to Coherence including how changes are > > communicated in a distributed environment i.e. OpenJPA effectively > > relinquishes its responsibility to broadcast changes via > > RemoteCommitProvider to other, possibly, remote L2 caches. This plug-in > > also > > recognizes that the instances of different classes may be cached to > > different Coherence partitions (Kodo version put all of them in one > single > > named partition). > > > > The source code is provided (without any warranty or copyright). Usage is > > exemplified via JUnit Test cases and a simple persistence.xml > > configuration. > > > > The build script requires to be edited for your local environment. > > > > Good night & Good luck -- > > > > Pinaki > > http://www.nabble.com/file/p16378911/coherence-openjpa.zip > > coherence-openjpa.zip > > > > > > -- > > View this message in context: > > > http://www.nabble.com/How-to-set-a-tangosol-cache-per-entity--tp16336199p16378911.html > > > > Sent from the OpenJPA Users mailing list archive at Nabble.com. > > > > > > > > > > > > -- > View this message in context: > http://n2.nabble.com/How-to-set-a-tangosol-cache-per-entity-tp210372p3790079.html > Sent from the OpenJPA Users mailing list archive at Nabble.com. > |
||||||||||||||||
|
Pinaki Poddar
|
In reply to this post
by Drewz
fyi...
http://ppoddar.blogspot.com/
|
||||||||||||||||
|
Drewz
|
Thanks Kevin and Pinaki for the responses. Plugin seems to be working with any major problems so far, performance results are looking good.
If we make any changes or improvements, I'll try to follow up and post them here. Cheers, Drew
|
||||||||||||||||
| Free Embeddable Forum Powered by Nabble | Help |