Ehcache复制的缓存在启动时未同步 [英] Ehcache Replicated Cache not synchronizing at startup

查看:218
本文介绍了Ehcache复制的缓存在启动时未同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在两台计算机之间复制了一个ehcache缓存。对等端正确地找到对方并在两个对等端都启动后进行复制。但是,如果第一个对等方首先启动并接收多个元素,然后第二个对等方之后启动...,则第二个对等方将永远不会看到添加的元素,而该元素还没有处于活动状态。

I have an ehcache Cache replicated across two machines. The peers correctly find each other and replicate once both peers are started. However, if the 1st peer starts first, and receives several elements, and then the 2nd peer starts later... the 2nd peer never sees the elements that were added while it was not yet alive.

以下是确切的顺序:


  1. 缓存A已启动

  2. 向缓存A添加 1234

  3. 缓存B已启动

  4. 从缓存B中获取 1234-> 未找到

  1. Cache A is started
  2. Add "1234" to Cache A
  3. Cache B is started
  4. get "1234" from Cache B -> NOT FOUND

我的期望:如果复制了2个缓存,则获取一个现有元素将返回相同的值对于任一缓存。

My expectation: If 2 caches are replicated, then getting an existing element returns the same value for either cache.

我的缓存元素只是原始的String / Integer类型。

My cache Elements are just primitive String/Integer types.

在GitHub上的示例如下: https://github.com/HamletDRC/EhcachePOC

An example is in GitHub here: https://github.com/HamletDRC/EhcachePOC

Ehcache配置在这里: https://github.com/HamletDRC/EhcachePOC / tree / master / src / main / resources

Ehcache configurations are here: https://github.com/HamletDRC/EhcachePOC/tree/master/src/main/resources

在示例项目中,为ehcache类启用了log4j,以便您可以看到对等节点互相查找并进行复制,但仅复制自对等组开始以来添加的元素,而不复制以前存在的元素。

In the sample project, log4j is enabled for the ehcache classes so that you can see that the peers do find each other and do replicate, but only elements that were added since the peer group started, not elements that existed previously.

您只需要安装JDK和Maven即可构建它。

You only need a JDK and Maven installed to build it.

要重现:


  • 运行ReplicatedCacheWriter

  • 等待6秒钟,以便编写器创建元素[1、2、3、4、5、6]

  • 运行ReplicatedCacheListener

  • 侦听器发现所有在放行之前都放入的元素,但是找不到在放行之前放入的所有元素。

  • Run ReplicatedCacheWriter
  • Wait 6 seconds for the writer to create elements [1, 2, 3, 4, 5, 6]
  • Run ReplicatedCacheListener
  • The listener finds all elements that were "put" after it came alive, but no elements "put" before it came alive.

这是ehcache.xml

Here is the ehcache.xml

<cacheManagerPeerProviderFactory
        class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
        properties="peerDiscovery=automatic, multicastGroupAddress=231.0.0.1,
                  multicastGroupPort=4446, timeToLive=32"/>

<cacheManagerPeerListenerFactory
        class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
        properties="port=40002, socketTimeoutMillis=2000"/>

...

<cacheEventListenerFactory
            class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
            properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true,
                    replicateUpdatesViaCopy=false, replicateRemovals=true "/>

(显然,两个节点之间的侦听器端口不同)

(Obviously, the Listener Port is different between the two nodes)

如何在启动时使缓存同步?

How can I get the caches to synchronize at startup?

推荐答案

您需要 bootstrapCacheLoaderFactory 在您的 ehcache_listener.xml 中。例如:

You need a bootstrapCacheLoaderFactory in your ehcache_listener.xml. For example:

<cache name="myCache" ...>
   ...
   <bootstrapCacheLoaderFactory
            class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"
            properties="bootstrapAsynchronously=true"
            propertySeparator="," />    
</cache>

这篇关于Ehcache复制的缓存在启动时未同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆