Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 在群集中使用infinispan无效缓存休眠_Hibernate_Infinispan_Cache Invalidation - Fatal编程技术网

Hibernate 在群集中使用infinispan无效缓存休眠

Hibernate 在群集中使用infinispan无效缓存休眠,hibernate,infinispan,cache-invalidation,Hibernate,Infinispan,Cache Invalidation,我正在集群环境中使用Hibernate 5.4.22和Infinispan 11.0.4。Hibernate二级缓存配置为使用JCache提供程序: hbProps.setProperty("hibernate.cache.use_minimal_puts", "false"); hbProps.setProperty("hibernate.cache.use_structured_entries", "fal

我正在集群环境中使用Hibernate 5.4.22和Infinispan 11.0.4。Hibernate二级缓存配置为使用JCache提供程序:

    hbProps.setProperty("hibernate.cache.use_minimal_puts", "false");
    hbProps.setProperty("hibernate.cache.use_structured_entries", "false");
    hbProps.setProperty("hibernate.cache.use_query_cache", "false");
    hbProps.setProperty("hibernate.cache.use_second_level_cache", "true");
    hbProps.setProperty("hibernate.cache.region.factory_class", "org.hibernate.cache.jcache.JCacheRegionFactory");
    hbProps.setProperty("hibernate.javax.cache.provider", "org.infinispan.jcache.embedded.JCachingProvider");
Infinispan配置了以下Infinispan.xml:

<infinispan
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="urn:infinispan:config:11.0 http://www.infinispan.org/schemas/infinispan-config-11.0.xsd"
      xmlns="urn:infinispan:config:11.0">
      
      <jgroups>
          <stack name="jgroups-stack">
              <TCP bind_port="7800"
                   recv_buf_size="${tcp.recv_buf_size:130k}"
                   send_buf_size="${tcp.send_buf_size:130k}"
                   max_bundle_size="64K"
                   sock_conn_timeout="300"
          
                   thread_pool.min_threads="0"
                   thread_pool.max_threads="20"
                   thread_pool.keep_alive_time="30000"/>
          
<!--              <TCPPING async_discovery="true"
                       initial_hosts="${jgroups.tcpping.initial_hosts:localhost[7800],localhost[7801]}"
                       port_range="2"/>-->
              <MPING/>
              <MERGE3  min_interval="10000"
                       max_interval="30000"/>
              <FD_SOCK/>
              <FD_ALL timeout="9000" interval="3000" />
              <VERIFY_SUSPECT timeout="1500"  />
              <BARRIER />
              <pbcast.NAKACK2 use_mcast_xmit="false"
                             discard_delivered_msgs="true"/>
              <UNICAST3 />
              <pbcast.STABLE desired_avg_gossip="50000"
                             max_bytes="4M"/>
              <pbcast.GMS print_local_addr="false" join_timeout="2000"/>
              <UFC max_credits="2M"
                   min_threshold="0.4"/>
              <MFC max_credits="2M"
                   min_threshold="0.4"/>
              <FRAG2 frag_size="60K"  />
              <!--RSVP resend_interval="2000" timeout="10000"/-->
              <pbcast.STATE_TRANSFER/>                    
          </stack>
      </jgroups> 
      
      <cache-container>
          <!-- turn off metrics -->
          <metrics gauges="false" histograms="false"/>
          <jmx enabled="true"/>
          <transport stack="jgroups-stack" cluster="infinispan-hibernate-cluster"/>
          
          <serialization marshaller="org.infinispan.commons.marshall.JavaSerializationMarshaller">
            <white-list>
              <regex>.*</regex>
            </white-list>   
          </serialization>
          
<!--          <replicated-cache name="MainCache" mode="SYNC"> 
            <memory max-count="100000"/>
            <expiration max-idle="3600000" lifespan="-1"/>
          </replicated-cache>-->

          <invalidation-cache name="MainCache" mode="SYNC">
            <memory max-count="100000"/>
            <expiration max-idle="3600000" lifespan="-1"/>
          </invalidation-cache>
      </cache-container>
</infinispan>
根据,
的组合应该是一个工作场景。在我的测试中,我有一个节点连续读取一个对象,还有一个节点更新同一个对象。我发现,为了从数据库中再次读取对象,读取节点从未收到对象已更改的通知。通过查看日志,似乎写入节点上的无效缓存没有向读取节点发送任何消息

但是,如果我将infinispan.xml更改为使用
而不是
,则读取节点将收到写入节点所做更改的通知。所以,我猜这意味着问题不在jgroup中

这是无效缓存中的问题,还是配置中缺少了什么

下面是从无效缓存读取的实例的日志文件和更新缓存的实例的日志文件


谢谢大家!

问题在于使用JCache-该表采用InfinispanRegionFactory而不是JCacheRegionFactory

Infinispan似乎没有明确支持Hibernate 5.4的模块——尽管如此,我想这应该也适用于Hibernate 5.4,因为Hibernate 5.4中的二级缓存区没有太多变化


我很惊讶2LC能在复制/分布式缓存中与JCache一起工作——我很肯定它不能“可靠地”工作(事务性的,覆盖边缘情况等)。

我尝试了InfinispanRegionFactory(infinispan-hibernate-cache-v53)11.0.4版,它能与hibernate 5.3和5.4一起工作。谢谢!
<hibernate-mapping>

  <class name="hibernatetest.Profile" table="Profiles" lazy="false">
    <cache usage="read-write" region="MainCache"/>
    <id column="id" name="id" unsaved-value="0">
      <generator class="native"/>
    </id>
    <discriminator column="type" type="string"/>
    <version name="version"/>
    <property name="name" type="string" length="100"/>
    <property name="available" type="yes_no"/>
  </class>
  
</hibernate-mapping>