8 Replies Latest reply on May 18, 2018 8:24 AM by William Burns

    Cache with JpaStore constantly queries database

    Moritz Becker Newbie

      Hi,

       

      first of all, I am using Infinispan 9.2.2.Final and you find my cache configuration attached.

       

      I start my cache at application startup.

      When I later retrieve the cache using embeddedCacheManager.getCache("distanceCache"), I start to constantly see SQL select queries being logged from a different thread called 'persistence-thread' in my server console.

      At first I thought this is because my in-memory cache entries have not yet been populated but when I execute this code a second time, the behavior is the same.

       

      Also the queries that are being logged look quite weird.

      The first query is always a select all query, i.e. it fetches all rows in my cache table.

      Then it seems that for each row, Infinispan is again fetching the row with a by-id query.

       

      The code that is executed asynchronously in the 'persistence-thread' is in org.infinispan.persistence.util.PersistenceManagerCloseableSupplier#get and this PersistenceManagerCloseableSupplier seems to be instantiated when I call list() on my Infinispan dsl query. Here is the stack trace for it:

       

      innerIterator:616, CacheLoaderInterceptor$WrappedEntrySet (org.infinispan.interceptors.impl)

      spliterator:519, CacheLoaderInterceptor$AbstractLoaderSet (org.infinispan.interceptors.impl)

      getStream:558, CacheLoaderInterceptor$AbstractLoaderSet (org.infinispan.interceptors.impl)

      stream:549, CacheLoaderInterceptor$AbstractLoaderSet (org.infinispan.interceptors.impl)

      stream:119, WriteableCacheCollectionMapper (org.infinispan.util)

      getIterator:60, EmbeddedQuery (org.infinispan.query.dsl.embedded.impl)

      listInternal:65, BaseEmbeddedQuery (org.infinispan.query.dsl.embedded.impl)

      list:57, BaseEmbeddedQuery (org.infinispan.query.dsl.embedded.impl)

      list:102, DelegatingQuery (org.infinispan.query.dsl.embedded.impl)

      getDistancesByClientLocation:69, GeoDataAccessImpl (com.ordami.geo.service.impl.data)

      getDistancesByClientLocation$$super:-1, GeoDataAccessImpl$Proxy$_$$_WeldSubclass (com.ordami.geo.service.impl.data)

      invoke0:-1, NativeMethodAccessorImpl (sun.reflect)

      invoke:62, NativeMethodAccessorImpl (sun.reflect)

      invoke:43, DelegatingMethodAccessorImpl (sun.reflect)

      invoke:498, Method (java.lang.reflect)

      proceedInternal:49, TerminalAroundInvokeInvocationContext (org.jboss.weld.interceptor.proxy)

      proceed:77, AroundInvokeInvocationContext (org.jboss.weld.interceptor.proxy)

      invokeInNoTx:141, TransactionalInterceptorBase (com.arjuna.ats.jta.cdi.transactional)

      doIntercept:53, TransactionalInterceptorSupports (com.arjuna.ats.jta.cdi.transactional)

      intercept:79, TransactionalInterceptorBase (com.arjuna.ats.jta.cdi.transactional)

      intercept:47, TransactionalInterceptorSupports (com.arjuna.ats.jta.cdi.transactional)

      invoke:-1, GeneratedMethodAccessor1585 (sun.reflect)

      invoke:43, DelegatingMethodAccessorImpl (sun.reflect)

      invoke:498, Method (java.lang.reflect)

      invoke:73, SimpleInterceptorInvocation$SimpleMethodInvocation (org.jboss.weld.interceptor.reader)

      executeAroundInvoke:84, InterceptorMethodHandler (org.jboss.weld.interceptor.proxy)

      executeInterception:72, InterceptorMethodHandler (org.jboss.weld.interceptor.proxy)

      invoke:56, InterceptorMethodHandler (org.jboss.weld.interceptor.proxy)

      invoke:79, CombinedInterceptorAndDecoratorStackMethodHandler (org.jboss.weld.bean.proxy)

      invoke:68, CombinedInterceptorAndDecoratorStackMethodHandler (org.jboss.weld.bean.proxy)

      getDistancesByClientLocation:-1, GeoDataAccessImpl$Proxy$_$$_WeldSubclass (com.ordami.geo.service.impl.data)

      getDistancesByClientLocation:-1, GeoDataAccessImpl$Proxy$_$$_WeldClientProxy (com.ordami.geo.service.impl.data)

      getDistances:29, DistancesResourceImpl (com.ordami.geo.rest.impl.resource)

      getDistances:-1, DistancesResourceImpl$Proxy$_$$_WeldClientProxy (com.ordami.geo.rest.impl.resource)

      invoke0:-1, NativeMethodAccessorImpl (sun.reflect)

      invoke:62, NativeMethodAccessorImpl (sun.reflect)

      invoke:43, DelegatingMethodAccessorImpl (sun.reflect)

      invoke:498, Method (java.lang.reflect)

      invoke:140, MethodInjectorImpl (org.jboss.resteasy.core)

      invokeOnTarget:295, ResourceMethodInvoker (org.jboss.resteasy.core)

      invoke:249, ResourceMethodInvoker (org.jboss.resteasy.core)

      invoke:236, ResourceMethodInvoker (org.jboss.resteasy.core)

      invoke:406, SynchronousDispatcher (org.jboss.resteasy.core)

      invoke:213, SynchronousDispatcher (org.jboss.resteasy.core)

      service:228, ServletContainerDispatcher (org.jboss.resteasy.plugins.server.servlet)

      service:56, HttpServletDispatcher (org.jboss.resteasy.plugins.server.servlet)

      service:51, HttpServletDispatcher (org.jboss.resteasy.plugins.server.servlet)

      service:790, HttpServlet (javax.servlet.http)

      handleRequest:85, ServletHandler (io.undertow.servlet.handlers)

      handleRequest:62, ServletSecurityRoleHandler (io.undertow.servlet.handlers.security)

      handleRequest:36, ServletDispatchingHandler (io.undertow.servlet.handlers)

      handleRequest:78, SecurityContextAssociationHandler (org.wildfly.extension.undertow.security)

      handleRequest:43, PredicateHandler (io.undertow.server.handlers)

      handleRequest:131, SSLInformationAssociationHandler (io.undertow.servlet.handlers.security)

      handleRequest:57, ServletAuthenticationCallHandler (io.undertow.servlet.handlers.security)

      handleRequest:43, PredicateHandler (io.undertow.server.handlers)

      handleRequest:46, AbstractConfidentialityHandler (io.undertow.security.handlers)

      handleRequest:64, ServletConfidentialityConstraintHandler (io.undertow.servlet.handlers.security)

      handleRequest:60, AuthenticationMechanismsHandler (io.undertow.security.handlers)

      handleRequest:77, CachedAuthenticatedSessionHandler (io.undertow.servlet.handlers.security)

      handleRequest:50, NotificationReceiverHandler (io.undertow.security.handlers)

      handleRequest:43, AbstractSecurityContextAssociationHandler (io.undertow.security.handlers)

      handleRequest:43, PredicateHandler (io.undertow.server.handlers)

      handleRequest:61, JACCContextIdHandler (org.wildfly.extension.undertow.security.jacc)

      handleRequest:43, PredicateHandler (io.undertow.server.handlers)

      handleRequest:68, GlobalRequestControllerHandler (org.wildfly.extension.undertow.deployment)

      handleRequest:43, PredicateHandler (io.undertow.server.handlers)

      handleFirstRequest:292, ServletInitialHandler (io.undertow.servlet.handlers)

      access$100:81, ServletInitialHandler (io.undertow.servlet.handlers)

      call:138, ServletInitialHandler$2 (io.undertow.servlet.handlers)

      call:135, ServletInitialHandler$2 (io.undertow.servlet.handlers)

      call:48, ServletRequestContextThreadSetupAction$1 (io.undertow.servlet.core)

      call:43, ContextClassLoaderSetupAction$1 (io.undertow.servlet.core)

      lambda$create$0:105, SecurityContextThreadSetupAction (org.wildfly.extension.undertow.security)

      call:-1, 1432452184 (org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction$$Lambda$884)

      lambda$create$0:1508, UndertowDeploymentInfoService$UndertowThreadSetupAction (org.wildfly.extension.undertow.deployment)

      call:-1, 977270871 (org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction$$Lambda$885)

      lambda$create$0:1508, UndertowDeploymentInfoService$UndertowThreadSetupAction (org.wildfly.extension.undertow.deployment)

      call:-1, 977270871 (org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction$$Lambda$885)

      lambda$create$0:1508, UndertowDeploymentInfoService$UndertowThreadSetupAction (org.wildfly.extension.undertow.deployment)

      call:-1, 977270871 (org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction$$Lambda$885)

      lambda$create$0:1508, UndertowDeploymentInfoService$UndertowThreadSetupAction (org.wildfly.extension.undertow.deployment)

      call:-1, 977270871 (org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction$$Lambda$885)

      lambda$create$0:1508, UndertowDeploymentInfoService$UndertowThreadSetupAction (org.wildfly.extension.undertow.deployment)

      call:-1, 977270871 (org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction$$Lambda$885)

      dispatchRequest:272, ServletInitialHandler (io.undertow.servlet.handlers)

      access$000:81, ServletInitialHandler (io.undertow.servlet.handlers)

      handleRequest:104, ServletInitialHandler$1 (io.undertow.servlet.handlers)

      executeRootHandler:326, Connectors (io.undertow.server)

      run:812, HttpServerExchange$1 (io.undertow.server)

      runWorker:1149, ThreadPoolExecutor (java.util.concurrent)

      run:624, ThreadPoolExecutor$Worker (java.util.concurrent)

      run:748, Thread (java.lang)

       

      However, the SQL queries are executed as soon as I run embeddedCacheManager.getCache("distanceCache") which is before I invoke the list() method. This is one of the things I don't understand here.

       

      Anyways, my expectation is that not database queries are executed at all in this scenario since the cache should have all required entries available in memory.

       

      Thanks