Bug 463737 - *URGENT* Too many org.eclipse.persistence.internal.queries.AttributeItem in memory *URGENT*
Summary: *URGENT* Too many org.eclipse.persistence.internal.queries.AttributeItem in m...
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows NT
: P3 blocker with 6 votes (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords: performance
: 461873 463089 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-04-01 19:30 EDT by Dyego Carmo CLA
Modified: 2022-06-09 10:33 EDT (History)
7 users (show)

See Also:


Attachments
Patch for the ConcurrentException (193.16 KB, patch)
2017-06-27 08:17 EDT, Valentin Iancu CLA
no flags Details | Diff
Patch for the ConcurrentException (32.92 KB, patch)
2017-06-27 08:23 EDT, Valentin Iancu CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dyego Carmo CLA 2015-04-01 19:30:00 EDT
My application run whith GlassFish 4.1 and start's very fast, but if you call many searchs the speed decrase to very slow quickly...

The HEAPDUMP showme the class org.eclipse.persistence.internal.queries.AttributeItem and class org.eclipse.persistence.internal.helper.NonSynchronizedVector increase to stratospheric number, see:


440596 instances of class org.eclipse.persistence.internal.queries.AttributeItem 

322771 instances of class org.eclipse.persistence.internal.helper.NonSynchronizedVector 

248445 instances of class org.eclipse.persistence.internal.helper.DatabaseField 

230745 instances of class org.eclipse.persistence.internal.descriptors.PersistenceObjectAttributeAccessor 

184137 instances of class org.eclipse.persistence.mappings.DirectToFieldMapping 

I'm using EclipseLink with Multitenant feature :

@Entity
@Table(name = "asdasd", catalog = "aaaa", schema = "")
@XmlRootElement
@Multitenant(MultitenantType.TABLE_PER_TENANT)
@TenantTableDiscriminator(contextProperty = "tenant.code", type = TenantTableDiscriminatorType.SUFFIX)

What the function of this class ? Why have so many instantiated and they are not released ?

Tnks in advance !
Comment 1 Dyego Carmo CLA 2015-04-01 19:47:35 EDT
in my persistence.xml i disabled the cache:

<persistence-unit name="xxx-ejbPU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/xxxx</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <shared-cache-mode>NONE</shared-cache-mode> 
    <validation-mode>NONE</validation-mode>
    <properties>
      <property name="javax.persistence.validation.group.pre-persist" value="javax.validation.groups.Default"/>
      <property name="javax.persistence.validation.group.pre-update" value="javax.validation.groups.Default"/>
      <property name="eclipselink.logging.level.sql" value="FINE"/>
      <property name="eclipselink.logging.parameters" value="true"/> 
      <property name="eclipselink.multitenant.tenants-share-cache" value="false"/>
      <property name="eclipselink.multitenant.tenants-share-emf" value="false"/>
      <property name="eclipselink.target-database" value="MySQL"/>
      <property name="eclipselink.cache.shared.default" value="false"/> 
    </properties>
  </persistence-unit>
Comment 2 Dyego Carmo CLA 2015-04-01 19:51:47 EDT
one more detail, glassfish stops by OutOfmemory error
Comment 3 Dyego Carmo CLA 2015-04-01 20:49:25 EDT
One more info:

i not set tenant.code in persistence.xml

EVERY EntityManager.createQuery i set the tenant.code manually like this:

EntityManager em = getEntityInternalManager();
em.setProperty("tenant.code", idTenacidade);
Query qr = em.createQuery....





If I disable support for multi tenant the bug disappears....
Comment 4 Dyego Carmo CLA 2015-04-02 19:56:43 EDT
This is very important blocker issue for MultiTenant Users
Comment 5 Dyego Carmo CLA 2015-04-05 19:03:27 EDT
*** Bug 461873 has been marked as a duplicate of this bug. ***
Comment 6 Dyego Carmo CLA 2015-04-05 19:03:44 EDT
*** Bug 463089 has been marked as a duplicate of this bug. ***
Comment 7 Dyego Carmo CLA 2015-04-08 12:49:31 EDT
Hello ?
Comment 8 Dyego Carmo CLA 2015-04-24 15:22:42 EDT
In 2.6.0 ocurs too.
Comment 9 Roque Possamai CLA 2016-05-23 17:00:02 EDT
I'm facing a similar problem in my project.
We have a multitenant app with MultitenantTableDiscriminator by schema. Sometimes, after some use of the application, we catch this error. See this stack:

(...)
java.util.ConcurrentModificationException
 	at java.util.HashMap$HashIterator.nextNode(HashMap.java:1429)
 	at java.util.HashMap$KeyIterator.next(HashMap.java:1453)
 	at org.eclipse.persistence.descriptors.ClassDescriptor.notifyReferencingDescriptorsOfIsolation(ClassDescriptor.java:3952)
 	at org.eclipse.persistence.descriptors.CachePolicy.postInitialize(CachePolicy.java:192)
 	at org.eclipse.persistence.descriptors.ClassDescriptor.postInitialize(ClassDescriptor.java:3940)
 	at org.eclipse.persistence.internal.sessions.AbstractSession.updateTablePerTenantDescriptors(AbstractSession.java:1454)
(...)

This is similar at your previous issue <a href='https://bugs.eclipse.org/bugs/show_bug.cgi?id=463089'>463089</a> (that was closed now).

Don't you think that sincronyzing the field "ClassDescritor.referencingClasses" should resolve this problem?
The real question is, could we sincronyze this part of the code?

The modified code should look like this in "ClassDescritor.java":

    public void notifyReferencingDescriptorsOfIsolation(AbstractSession session) {
        //Must be sincronyzed to avoid ConcurrentModificationException on the referencingClasses
        synchronized(this.referencingClasses) { //THIS IS NEW!
            for (ClassDescriptor descriptor : this.referencingClasses) {
                if (descriptor.getCachePolicy().getCacheIsolation() == null || descriptor.getCachePolicy().getCacheIsolation() == CacheIsolationType.SHARED) {
                    descriptor.getCachePolicy().setCacheIsolation(CacheIsolationType.PROTECTED);
                    descriptor.getCachePolicy().postInitialize(descriptor, session);
                    for (DatabaseMapping mapping : descriptor.getMappings()) {
                        if (mapping.isAggregateMapping() && (mapping.getReferenceDescriptor() != null)) {
                            mapping.getReferenceDescriptor().getCachePolicy().setCacheIsolation(CacheIsolationType.PROTECTED);
                        }
                    }
                }
            }
        } //NEW
    }
Comment 10 Pieter van Onselen CLA 2016-08-05 05:11:21 EDT
We have the same problem with MultiTenant setup with Eclipselink 2.6.3

Any progress on this issue
Comment 11 Valentin Iancu CLA 2017-06-27 08:17:22 EDT
Created attachment 269072 [details]
Patch for the ConcurrentException

Fixed the issues (against 2.6 branch) - mainly ClassDescriptor clone&synchronized
 ManagedTypeImpl.init 

For ManagedTypeImpl, if many threads are creating entity managers,
ConcurrentModificationException related to members appears (the second
thread reaches the if (null != this.members) and exits - it will access
members that are in construction, leading to exceptions and invalid
results.

All the tenant client session will clone the classdescriptor from the
client session (same client session). If there are multiple tenant
client sessions started, the notifyReferencingDescriptorsOfIsolation is
called for other entity manager, while referencedDescriptors are added
from the initialize method.

The tests were done with a multitenant & rich data model with 100 parallel
threads doing create an EntityManager (with tenant id), start a
transaction, commit the transaction.
Comment 12 Valentin Iancu CLA 2017-06-27 08:23:56 EDT
Created attachment 269073 [details]
Patch for the ConcurrentException

Re-attached the patch with less new line issues.
Comment 13 Lukas Jungmann CLA 2017-07-25 18:02:53 EDT
Can some test-case be added to this, please? Or at least some detailed description of the setup and entities for which this can be reproduced?
Thanks!
Comment 14 Raul Mederos CLA 2017-11-20 13:54:27 EST
Hello,
I'm having the same problem, I downloaded the 2.6.5 version, but the problem is still there. Do you know if the updated version was checked into the repository?

Thanks!!
Comment 15 Eclipse Webmaster CLA 2022-06-09 10:33:21 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink