【问题标题】:Why class-based cache entries gone after GridGain node stopped?为什么 GridGain 节点停止后基于类的缓存条目消失了?
【发布时间】:2014-07-06 10:09:21
【问题描述】:

Code:

public static class Oya {
    String name;

    public Oya(String name) {
        super();
        this.name = name;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return "Oya [name=" + name + "]";
    }

}

public static void main(String[] args) throws GridException {
    try (Grid grid = GridGain.start(
            System.getProperty("user.home") + "/gridgain-platform-os-6.1.9-nix/examples/config/example-cache.xml")) {
        GridCache<Integer, Oya> cache = grid.cache("partitioned");
        boolean success2 = cache.putxIfAbsent(3, new Oya("3"));
        log.info("Current 3 value = {}", cache.get(3));
        cache.transform(3, (it) -> new Oya(it.name + "-transformed"));
        log.info("Transformed 3 value = {}", cache.get(3));
    }
}
  1. 启动另一个 GridGain 节点。
  2. 运行代码。它应该打印:3-transformed
  3. 评论putxIfAbsent()代码。
  4. 运行代码。我希望它打印:3-transformed,但得到了null

如果我将缓存值更改为 String(如 GridGain Basic Operations video)或 Java 内置值,代码将起作用,但不适用于我自己的自定义类。

【问题讨论】:

  • 我怀疑这与peerClassLoadingEnabled 和/或deployment modes 有关?
  • 解决方法:&lt;property name="deploymentMode" value="CONTINUOUS"/&gt; 但我仍然不明白为什么默认的SHARED 在我的情况下不起作用(这与示例视频非常相似)?

标签: caching gridgain jcache


【解决方案1】:

数据网格的对等部署是一项仅限开发的功能。共享模式的约定是,每当具有原始类定义的最后一个节点离开时,所有类都将被取消部署。对于数据网格,这意味着缓存将被清除。这对于更改类定义的情况很有用。

在 CONTINUOUS 模式下,缓存类永远不会取消部署,但在这种情况下,您必须注意不要在不重新启动网格节点的情况下更改类的定义。

有关更多信息,请参阅Deployment Modes 文档。

【讨论】:

    猜你喜欢
    • 2020-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多