不要在重新部署时停止 WildFly (jBoss) 中的 Infinispan 缓存容器

Don's stop Infinispan cache containers in WildFly (jBoss) on redeploy

我将 WildFly 8.2 与 Immutant 2.1 一起使用(应用程序在 Clojure 中)

每次我在 WildFly 集群中重新部署我的应用程序时,它的 Infinispan Web 缓存容器都会重新启动,所有用户会话都会丢失。

是否可以不重启缓存容器,或者在重新部署之前将数据刷新到磁盘?

提前致谢

更新: 感谢 sprockets 的回答,我可以找到可以满足我需要的 Web 容器配置:

<cache-container name="web" default-cache="repl" module="org.wildfly.clustering.web.infinispan" aliases="standard-session-cache">
    <transport lock-timeout="60000"/>
    <replicated-cache name="repl" batching="true" mode="ASYNC">
       <file-store preload="true" passivation="false" purge="false" relative-to="jboss.home.dir" path="infinispan-file-store">
          <write-behind/>
       </file-store>
    </replicated-cache>
</cache-container>

问题是 Web 容器对其配置非常挑剔,如果您使用不兼容的设置,它会抛出信息量不大的异常。 所以基本上,你只需要添加

<file-store preload="true" passivation="false" purge="false" relative-to="jboss.home.dir" path="infinispan-file-store">
  <write-behind/>
</file-store>

到容器配置。

Ifninispan 提供缓存钝化和缓存激活来执行此操作: https://docs.jboss.org/author/display/ISPN/Cache+Loaders+and+Stores#CacheLoadersandStores-CachePassivation

A cache loader can be used to enforce entry passivation and activation on eviction in a cache. Cache passivation is the process of removing an object from in-memory cache and writing it to a secondary data store (e.g., file system, database) on eviction. Cache Activation is the process of restoring an object from the data store into the in-memory cache when it's needed to be used. In both cases, the configured cache loader will be used to read from the data store and write to the data store.

我们使用它来将集群休眠搜索缓存容器中的数据钝化到这样的文件存储中(在我们的独立完整 ha.xml 中):

<cache-container name="hibernate-search" jndi-name="java:jboss/infinispan/container/hibernate-search" start="EAGER">
            <transport lock-timeout="330000"/>
            <replicated-cache name="LuceneIndexesMetadata" start="EAGER" mode="SYNC" remote-timeout="330000">
                <locking striping="false" acquire-timeout="330000" concurrency-level="500"/>
                <transaction mode="NONE"/>
                <eviction strategy="NONE" max-entries="-1"/>
                <expiration max-idle="-1"/>
                <state-transfer enabled="true" timeout="480000"/>
                <file-store preload="true" passivation="false" purge="false" relative-to="jboss.home.dir" path="infinispan-file-store">
                    <write-behind/>
                </file-store>
                <indexing index="NONE"/>
            </replicated-cache>

重启节点后数据可用。

The schema for the subsystem, describing all valid elements and attributes, can be found in the Wildfly distribution, in the docs/schema directory.

另请参阅: