Skip to content

TRUNK-6302: Setup Infinispan backend for Hibernate/Spring caching #5027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rkorytkowski
Copy link
Member

@rkorytkowski rkorytkowski commented May 9, 2025

Description of what I changed

Issue I worked on

see https://issues.openmrs.org/browse/TRUNK-6302

Checklist: I completed these to help reviewers :)

  • My IDE is configured to follow the code style of this project.

    No? Unsure? -> configure your IDE, format the code and add the changes with git add . && git commit --amend

  • I have added tests to cover my changes. (If you refactored
    existing code that was well tested you do not have to add tests)

    No? -> write tests and add them to this commit git add . && git commit --amend

  • I ran mvn clean package right before creating this pull request and
    added all formatting changes to my commit.

    No? -> execute above command

  • All new and existing tests passed.

    No? -> figure out why and add the fix to your commit. It is your responsibility to make sure your code works.

  • My pull request is based on the latest changes of the master branch.

    No? Unsure? -> execute command git pull --rebase upstream master

@dkayiwa
Copy link
Member

dkayiwa commented May 10, 2025

@rkorytkowski do you also get these build failures locally?

@rkorytkowski
Copy link
Member Author

rkorytkowski commented May 12, 2025 via email

@dkayiwa
Copy link
Member

dkayiwa commented May 12, 2025

Looking forward to it!

@rkorytkowski rkorytkowski force-pushed the TRUNK-6302 branch 4 times, most recently from 69157d0 to 1ba6bec Compare May 14, 2025 11:45
@rkorytkowski
Copy link
Member Author

rkorytkowski commented May 14, 2025

I'm a bit blocked on these failures... I cannot reproduce them locally for some reason... @dkayiwa could you please run it locally and see if it fails for you? If so I'll ask you to run it with logging set to DEBUG for org.hibernate and org.infinispan in src/test/resources/log4j2.xml. Ideally run a single failing test.

@rkorytkowski
Copy link
Member Author

rkorytkowski commented May 14, 2025

I see there's also an issue with Java 24...

Caused by: org.infinispan.commons.CacheConfigurationException: Error starting component org.infinispan.container.versioning.VersionGenerator
	at org.infinispan.factories.impl.BasicComponentRegistryImpl.startWrapper(BasicComponentRegistryImpl.java:585)
	at org.infinispan.factories.impl.BasicComponentRegistryImpl.access$700(BasicComponentRegistryImpl.java:30)
	at org.infinispan.factories.impl.BasicComponentRegistryImpl$ComponentWrapper.running(BasicComponentRegistryImpl.java:808)
	at org.infinispan.factories.impl.BasicComponentRegistryImpl.startDependencies(BasicComponentRegistryImpl.java:635)
	at org.infinispan.factories.impl.BasicComponentRegistryImpl.doStartWrapper(BasicComponentRegistryImpl.java:599)
	at org.infinispan.factories.impl.BasicComponentRegistryImpl.startWrapper(BasicComponentRegistryImpl.java:577)
	at org.infinispan.factories.impl.BasicComponentRegistryImpl.access$700(BasicComponentRegistryImpl.java:30)
	at org.infinispan.factories.impl.BasicComponentRegistryImpl$ComponentWrapper.running(BasicComponentRegistryImpl.java:808)
	at org.infinispan.factories.impl.BasicComponentRegistryImpl.startDependencies(BasicComponentRegistryImpl.java:635)
	at org.infinispan.factories.impl.BasicComponentRegistryImpl.doStartWrapper(BasicComponentRegistryImpl.java:599)
	at org.infinispan.factories.impl.BasicComponentRegistryImpl.startWrapper(BasicComponentRegistryImpl.java:577)
	at org.infinispan.factories.impl.BasicComponentRegistryImpl.access$700(BasicComponentRegistryImpl.java:30)
	at org.infinispan.factories.impl.BasicComponentRegistryImpl$ComponentWrapper.running(BasicComponentRegistryImpl.java:808)
	at org.infinispan.factories.AbstractComponentRegistry.internalStart(AbstractComponentRegistry.java:354)
	at org.infinispan.factories.AbstractComponentRegistry.start(AbstractComponentRegistry.java:250)
	at org.infinispan.factories.ComponentRegistry.start(ComponentRegistry.java:216)
	at org.infinispan.cache.impl.CacheImpl.start(CacheImpl.java:1014)
	at org.infinispan.cache.impl.AbstractDelegatingCache.start(AbstractDelegatingCache.java:512)
	at org.infinispan.manager.DefaultCacheManager.wireAndStartCache(DefaultCacheManager.java:714)
	at org.infinispan.manager.DefaultCacheManager.createCache(DefaultCacheManager.java:660)
	at org.infinispan.manager.DefaultCacheManager.internalGetCache(DefaultCacheManager.java:549)
	at org.infinispan.manager.DefaultCacheManager.getCache(DefaultCacheManager.java:517)
	at org.infinispan.security.actions.GetCacheAction.run(GetCacheAction.java:26)
	at org.infinispan.security.actions.GetCacheAction.run(GetCacheAction.java:14)
	at org.infinispan.security.Security.doPrivileged(Security.java:56)
	at org.infinispan.globalstate.impl.SecurityActions.doPrivileged(SecurityActions.java:30)
	at org.infinispan.globalstate.impl.SecurityActions.getCache(SecurityActions.java:39)
	at org.infinispan.globalstate.impl.GlobalConfigurationManagerImpl.start(GlobalConfigurationManagerImpl.java:104)
	at org.infinispan.globalstate.impl.CorePackageImpl$2.start(CorePackageImpl.java:60)
	at org.infinispan.globalstate.impl.CorePackageImpl$2.start(CorePackageImpl.java:48)
	at org.infinispan.factories.impl.BasicComponentRegistryImpl.invokeStart(BasicComponentRegistryImpl.java:617)
	at org.infinispan.factories.impl.BasicComponentRegistryImpl.doStartWrapper(BasicComponentRegistryImpl.java:608)
	at org.infinispan.factories.impl.BasicComponentRegistryImpl.startWrapper(BasicComponentRegistryImpl.java:577)
	at org.infinispan.factories.impl.BasicComponentRegistryImpl.access$700(BasicComponentRegistryImpl.java:30)
	at org.infinispan.factories.impl.BasicComponentRegistryImpl$ComponentWrapper.running(BasicComponentRegistryImpl.java:808)
	at org.infinispan.factories.AbstractComponentRegistry.internalStart(AbstractComponentRegistry.java:354)
	at org.infinispan.factories.AbstractComponentRegistry.start(AbstractComponentRegistry.java:250)
	at org.infinispan.manager.DefaultCacheManager.internalStart(DefaultCacheManager.java:766)
	... 87 more
Caused by: java.lang.UnsupportedOperationException: getSubject is not supported
	at java.base/javax.security.auth.Subject.getSubject(Subject.java:277)
	at org.infinispan.security.Security.getSubject(Security.java:189)
	at org.infinispan.notifications.impl.AbstractListenerImpl.validateAndAddListenerInvocations(AbstractListenerImpl.java:213)
	at org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifierImpl.addListenerAsync(CacheManagerNotifierImpl.java:190)
	at org.infinispan.notifications.Listenable.addListener(Listenable.java:27)
	at org.infinispan.container.versioning.NumericVersionGenerator.start(NumericVersionGenerator.java:55)
	at org.infinispan.container.versioning.CorePackageImpl$2.start(CorePackageImpl.java:51)
	at org.infinispan.container.versioning.CorePackageImpl$2.start(CorePackageImpl.java:43)
	at org.infinispan.factories.impl.BasicComponentRegistryImpl.invokeStart(BasicComponentRegistryImpl.java:617)
	at org.infinispan.factories.impl.BasicComponentRegistryImpl.doStartWrapper(BasicComponentRegistryImpl.java:608)
	at org.infinispan.factories.impl.BasicComponentRegistryImpl.startWrapper(BasicComponentRegistryImpl.java:577)
	... 124 more

Not sure if it can be fixed without upgrading infinispan, which would necessitate upgrading Hibernate...

@wikumChamith any quick ideas?

@wikumChamith
Copy link
Member

infinispan

This was deprecated in Java 23+. You might be able to work around it by passing some JVM arguments to allow the security manager however, that won't be a proper fix.

https://docs.oracle.com/en/java/javase/23/security/migrating-deprecated-removal-methods-subject-getsubject-and-subject-doas-subject-current-and-s.html

@dkayiwa
Copy link
Member

dkayiwa commented May 14, 2025

The failures are a bit random. In one instance i got this: https://pastebin.com/wAyvaFsu and details: https://pastebin.com/tdygXL49
On another run i got this: https://pastebin.com/uac23qhM and details: https://pastebin.com/a51YekRq
And the same test does not fail when run alone.

@dkayiwa
Copy link
Member

dkayiwa commented May 14, 2025

When i run a single test like this from the api folder: mvn clean install -Dtest='ContextTest' it sometimes passes and fails at other times as you can see here: https://pastebin.com/fSRv9fdm

@dkayiwa
Copy link
Member

dkayiwa commented May 14, 2025

This is the failure log with <Logger name="org.infinispan" level="DEBUG" /> : https://pastebin.com/mqsLjM0W

@dkayiwa
Copy link
Member

dkayiwa commented May 14, 2025

This is the log with <Logger name="org.hibernate" level="DEBUG" />:
DEBUG.txt

@dkayiwa
Copy link
Member

dkayiwa commented May 14, 2025

And this is the log when both hibernate and infinispan and turned to DEBUG:
DEBUG-BOTH.txt

@rkorytkowski
Copy link
Member Author

Thanks @dkayiwa! Which JDK you use? Maybe I'll be able to reproduce using the same one. Meanwhile I'll dig through the logs.

@dkayiwa
Copy link
Member

dkayiwa commented May 15, 2025

This is the output of my mvn -v:

Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63) Maven home: /Users/danielkayiwa/Libraries/apache-maven-3.8.6 Java version: 21.0.6, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home Default locale: en_UG, platform encoding: UTF-8 OS name: "mac os x", version: "15.4.1", arch: "aarch64", family: "mac"

@rkorytkowski
Copy link
Member Author

Okay it's Oracle... I'll try that. I'm using Temurin which is theoretically same as on GHA, but tests do not fail for me at all...

The issue is very strange... in your logs I see Adding entity to second-level cache: [org.openmrs.PersonName#8] and hibernate stats show that cache is being populated and used... with cache hits.

@dkayiwa
Copy link
Member

dkayiwa commented May 15, 2025

The test failure also happens on Temurin

danielkayiwa@Daniels-MacBook-Pro core % mvn -v Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63) Maven home: /Users/danielkayiwa/Libraries/apache-maven-3.8.6 Java version: 1.8.0_352, vendor: Temurin, runtime: /Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home/jre Default locale: en_UG, platform encoding: UTF-8 OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"

@rkorytkowski rkorytkowski force-pushed the TRUNK-6302 branch 2 times, most recently from 858f6dc to 7224b06 Compare May 15, 2025 12:31
Context.getPersonService().getPersonName(PERSON_NAME_ID_2);
assertThat(sf.getStatistics().getSecondLevelCacheHitCount(), is(hitCount));
Context.getPersonService().getPersonName(PERSON_NAME_ID_8);
assertThat(sf.getStatistics().getSecondLevelCacheHitCount(), is(greaterThan(hitCount)));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewritten the test to not use sf.getCache() as it doesn't seem to reflect reliably all changes happening behind the scenes with Hibernate + Infinispan.

log.error(ex.getMessage(), ex);
}
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Infinispan caches should be properly shutdown by Spring and Hibernate shutdown methods...

@rkorytkowski
Copy link
Member Author

rkorytkowski commented May 15, 2025

Interestingly when I switched from Java 8 to 21 Temurin it started to fail for me as well. The issue was that SessionFactory#getCache was not reliably showing the current state of the cache... It seemed like some sort of not synchronized view in multi-threaded execution. Relying on hibernate stats instead fixed the test.

@dkayiwa
Copy link
Member

dkayiwa commented May 15, 2025

Relying on hibernate stats instead fixed the test.

Oh i see!

@rkorytkowski
Copy link
Member Author

Windows fails... fun continues :/

@dkayiwa
Copy link
Member

dkayiwa commented May 15, 2025

Windows fails... fun continues :/

At first i thought that probably GitHub just forgot to rerun it after your fix. 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants