我创建了一个包含 200 条记录的 Apache Ignite (V2.7) 复制缓存。我运行了该代码的 2 个实例。当我打印 cache.localSizeLong
时,它不会在两个节点上打印 200。它在节点 1 中打印 120,在节点 2 中打印 80。当我重新运行时,数字会有所不同。看起来它正在创建分区缓存?
初始化缓存的代码:
private void initCache() {
IgniteConfiguration configuration = new IgniteConfiguration();
configuration.setIncludeEventTypes(EventType.EVT_CACHE_OBJECT_PUT);//Can take multiple
CacheConfiguration cacheCfg = new CacheConfiguration("myCacheConfig");
//https://apacheignite.readme.io/docs/cache-modes
cacheCfg.setCacheMode(CacheMode.REPLICATED);
System.out.println("Default cache mode:----" + cacheCfg.getCacheMode());
log.debug("Default cache mode:----" + cacheCfg.getCacheMode());
configuration.setCacheConfiguration(cacheCfg);
cacheCfg.setCopyOnRead(false);
cacheCfg.setBackups(0);
Ignite ignite = Ignition.start(configuration);
cache = ignite.getOrCreateCache("myIgniteCache");
}
最佳答案
默认情况下,cache.localSizeLong
返回节点作为主节点的多个条目。即使缓存被复制,它仍然像分区一样实现 - 每个节点都是某些数据的主节点,并保留其余数据的备份副本。
使用cache.localSizeLong(CachePeekMode.ALL)
来计算主实体和备份实体。
关于java - Apache Ignite : REPLICATION mode, 计数似乎不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54952947/