简体   繁体   English

使用Wildfly 11复制了infinispan缓存

[英]Replicated infinispan cache with Wildfly 11

I'm developing a web application distributed on multi nodes with java 8 and java ee7 on wildfly-11.0.0.Final, and i used infinispan cache for share data. 我正在使用Wildfly-11.0.0.Final上的java 8和java ee7开发分布在多节点上的Web应用程序,并且我使用了infinispan缓存来共享数据。 This is the configuration of cache: 这是缓存的配置:

<cache-container name="mycache-container" default-cache="my-cache" jndi-name="infinispan/mycache-container">
    <transport lock-timeout="60000"/>
    <replicated-cache name="my-cache" jndi-name="infinispan/mycache-container/my-cache" mode="ASYNC">
        <locking isolation="READ_COMMITTED"/>
        <transaction locking="OPTIMISTIC" mode="NON_XA"/>
        <eviction strategy="NONE"/>
    </replicated-cache>
</cache-container>

And this is the configuration of jgroups subsystem used for replicated cache: 这是用于复制缓存的jgroups子系统的配置:

<subsystem xmlns="urn:jboss:domain:jgroups:5.0">
        <channels default="ee">
            <channel name="ee" stack="tcpping" cluster="ejb"/>
        </channels>
        <stacks>
            <stack name="tcpping">
                <transport type="TCP" socket-binding="jgroups-tcp"/>
                <protocol type="org.jgroups.protocols.TCPPING">
                    <property name="initial_hosts">
                        node1[7600], node2[7600]
                    </property>
                </protocol>
                <protocol type="MERGE3"/>
                <protocol type="FD_SOCK"/>
                <protocol type="FD_ALL"/>
                <protocol type="VERIFY_SUSPECT"/>
                <protocol type="pbcast.NAKACK2"/>
                <protocol type="UNICAST3"/>
                <protocol type="pbcast.STABLE"/>
                <protocol type="pbcast.GMS"/>
                <protocol type="MFC"/>
                <protocol type="FRAG2"/>
            </stack>
        </stacks>
    </subsystem>

On the application's startup i load all entity from database and put in the cache. 在应用程序启动时,我从数据库加载所有实体,然后放入缓存中。 If i inject cache through container in this way: 如果我以这种方式通过容器注入缓存:

@Resource(lookup="java:jboss/infinispan/mycache-container") 
EmbeddedCacheManager container;

@PostConstruct
public void init(){
    Cache mycache = container.getCache();
}

the app start and load all objects in cache without problem, but in the other nodes these objects are not replicated also that jgroups cluster is created wihout errors. 该应用程序启动并加载缓存中的所有对象都没有问题,但是在其他节点中,这些对象也不会被复制,即使创建jgroups群集也不会出错。 Instead if i inject cache directly in this way: 相反,如果我以这种方式直接注入缓存:

@Resource(lookup="java:jboss/infinispan/mycache-container/my-cache") 
Cache myCache;

the app in startup give me this error: "WFLYCTL0348: Timeout after [300] seconds waiting for service container stability. Operation will roll back. Step that first updated the service; and the server not start" 该应用程序在启动时给我以下错误:“ WFLYCTL0348:等待[300]秒后超时,等待服务容器的稳定性。操作将回滚。首先更新该服务的步骤;服务器未启动”

How should I use the cache to prevent timeout on startup and be able to replicate that objects on all nodes? 如何使用缓存来防止启动时超时,并能够在所有节点上复制该对象?

Thank you. 谢谢。

The reason the 1st approach doesn't work as expected is because you've done nothing to insure that the requisite cache configuration is installed before your call to EmbeddedCacheManager.getCache(). 第一种方法无法按预期工作的原因是,在调用EmbeddedCacheManager.getCache()之前,您没有做任何事情来确保已安装必需的缓存配置。

To ensure the requisite cache configuration is installed, you can either: 为确保已安装必需的缓存配置,您可以:

  1. Inject the cache directly (as you've done in your 2nd approach) 直接注入缓存(如您在第二种方法中所做的那样)
  2. Add a dependency on the requisite cache configuration to your application, via @Resource or resource-ref. 通过@Resource或resource-ref向您的应用程序添加对必需的缓存配置的依赖关系。

I always recommend #1, as it is more intuitive, less verbose, and the cache lifecycle is handled by the container. 我总是建议#1,因为它更直观,更简洁,并且缓存生命周期由容器处理。

As to the cause of the "Timeout [...] waiting for container stability", I can't say for sure without seeing the code that loads objects into you cache as well as the relevant stack trace. 关于“等待容器稳定的超时”的原因,我不能肯定地说,除非看到将对象加载到缓存中的代码以及相关的堆栈跟踪。 Just a guess - are you sure you the transaction mode to be NON_XA? 只是一个猜测-您确定交易模式为NON_XA吗? This means that cache operations are committed via a Synchronization to an active UserTransaction. 这意味着缓存操作是通过同步提交给活动的UserTransaction的。 This isn't a common requirement. 这不是常见的要求。 If you're loading your cache in a @PostConstruct method, and aren't handling transactions correctly, this could prevent your component from starting (leading to a timeout waiting for container stability). 如果您正在使用@PostConstruct方法加载缓存,并且未正确处理事务,则这可能会阻止您的组件启动(导致等待容器稳定的超时)。

On an unrelated note, I would recommend using the non-deprecated TCPPING configuration. 与此无关的是,我建议使用不建议使用的TCPPING配置。 eg 例如

<socket-discovery-protocol type="TCPPING" socket-bindings="node0 node1"/>

... where the socket-bindings reference configured outbound-socket-bindings. ...其中套接字绑定参考配置了出站套接字绑定。 eg 例如

<outbound-socket-binding name="node0">
    <remote-destination host="node0" port="7600"/>
</outbound-socket-binding>
<outbound-socket-binding name="node1">
    <remote-destination host="node1" port="7600"/>
</outbound-socket-binding>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM