quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.82k stars 2.69k forks source link

[Feature Request] Infinispan as Hibernate second-level cache provider #42582

Open cthiebault opened 3 months ago

cthiebault commented 3 months ago

Description

Following https://github.com/quarkusio/quarkus/issues/42541

Quarkus + Hibernate works great!
Quarkus + Infinispan works great!
Hibernate + Infinispan works great!

As Quarkus is microservices-oriented, we usually have multiple instances of the application so, it would be nice to have a distributed cache like Infinispan as Hibernate second-level cache provider :-)

Implementation ideas

No response

quarkus-bot[bot] commented 3 months ago

/cc @gsmet (hibernate-orm), @gwenneg (cache), @karesti (infinispan), @wburns (infinispan), @yrodiere (hibernate-orm)

yrodiere commented 2 months ago

cc @Sanne , you're probably interested in this :)

Sanne commented 2 months ago

I agree with the sentiment! But there's quite some novel work to be done. Let me clarify:

Quarkus + Hibernate works great!

Right, thanks :)

Quarkus + Infinispan works great!

Right again, but the cache extension is using Infinispan in "remote" mode: it's a real problem for a fast-starting microservices oriented framework to form a cluster or join an existing cluster. It's technically possible to do this, but I wouldn't recommend this architecture.

Hibernate + Infinispan works great!

Right again, but the Hibernate / Infinispan 2nd level cache integration is strongly coupled with Infinispan Embedded; this is both restricted to API differences of embedded/remote but also other more fundamental differences.

I know the WildFly clustering team has been exploring the idea of creating an Hibernate 2LC implementation based on Infinispan Remote - but we should check with them how that idea is proceeding?

cc/ @pferraro @karesti @wburns

wburns commented 2 months ago

@Sanne has hit it right on the nose. Currently, Infinispan can only be used as a 2LC when using embedded mode, while Quarkus currently only officially supports the remote client. Embedded was removed from Quarkus in its infancy, due to what Sanne mentioned with trying to quickly scale up microservices, since they would have to join an existing cluster.

Much of the work of getting embedded Infinispan to work in Quarkus, more specifically to be compiled into a native binary, is done; However, we haven't tested any of the 2LC code with Quarkus. This was originally done to support a natively compiled Infinispan server, which has a dependency on embedded.

https://github.com/infinispan/infinispan/tree/main/graalvm https://github.com/infinispan/infinispan/tree/main/quarkus

I don't know how far the Wildfly team has gotten with Infinispan remote as a 2LC, but I worry it will have different transactional semantics than embedded, which may or may not be a deal breaker.

karesti commented 2 months ago

@Sanne @wburns there are several community people asking for embedded infinispan for a while now. I've been considering to put it back into the roadmap for some time now. I think it's worth to discuss it again

Sanne commented 2 months ago

@karesti I agree we should talk about it. I'm just very skeptical in allowing "traditional" discovery protocols, but if there's some form of cloud orchestrator injecting the expected topology, that might fit well the Quarkus model.

Sanne commented 2 months ago

P.S. if we could do Hibernate 2LC over remote Infinispan that would be certainly my preference.

It could also offer some consideration for reference data which doesn't require strong consistency to be locally cached but still benefit from an async distributed invalidation failsafe: today with the Caffeine based local-only cache we address the "reference data" use case but honestly not having any ability to ever invalidate the state on other nodes makes me uncomfortable.