Hi Francesco,

Normally if you have one EMF per tenant there is no leak between them since
the cache instance is stored in the EMF - used that approach in TomEE.
You can check it
in org.apache.openjpa.datacache.DataCacheManagerImpl#initialize of each emf
which should be different.

So overall if there is a leak it is likely that it leaks accross
transactions or some spring cache level.

Side note: the datasource routing pattern is useless if you have an entity
manager routing pattern and only use JPA to do database work, both will
more easily conflict than help.

If you still want to plug the datacase (query cache) configuration in the
jpa properties can take a custom fully qualified name too.

Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://rmannibucau.metawerx.net/> | Old Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Book
<https://www.packtpub.com/application-development/java-ee-8-high-performance>


Le lun. 8 janv. 2024 à 17:14, Francesco Chicchiriccò <ilgro...@apache.org>
a écrit :

> Hi there,
> at Syncope we have been implementing multi-tenancy by relying on something
> like:
>
> * 1 data source per tenant
> * 1 entity manager factory per tenant
> * 1 transaction manager per tenant
> * etc
>
> So far so good.
>
> Now I am experimenting a different approach similar to [1], e.g.
>
> * 1 low-level data source per tenant
> * 1 data source extending Spring's AbstractRoutingDataSource using the
> value of a ThreadLocal variable as lookup key
> * 1 single entity manager factory configured with the routing data source
> * 1 single transaction manager
> * etc
>
> It mostly works but I am having caching issues with concurrent operations
> working on different tenants, so I was wondering: how can I extend the
> various OpenJPA (query, data, L1, L2, every one) caches to hold back
> different actual instances per tenant and to use the appropriate one
> depending on the same ThreadLocal value I have already used above for data
> sources?
>
> Thanks in advance.
> Regards.
>
> [1] https://github.com/Cepr0/sb-multitenant-db-demo
>
> --
> Francesco Chicchiriccò
>
> Tirasa - Open Source Excellence
> http://www.tirasa.net/
>
> Member at The Apache Software Foundation
> Syncope, Cocoon, Olingo, CXF, OpenJPA, PonyMail
> http://home.apache.org/~ilgrosso/
>
>

Reply via email to