Java ApacheIgnite:复制模式,计数似乎不一致
我已经创建了一个包含200条记录的Apache Ignite V2.7复制缓存。我运行了这段代码的两个实例。打印cache.localSizeLong时,它不会在两个节点上打印200。它在节点1中打印120,在节点2中打印80。当我重新运行时,数字会有所不同。看起来它正在创建分区缓存 初始化缓存的代码:Java ApacheIgnite:复制模式,计数似乎不一致,java,ignite,Java,Ignite,我已经创建了一个包含200条记录的Apache Ignite V2.7复制缓存。我运行了这段代码的两个实例。打印cache.localSizeLong时,它不会在两个节点上打印200。它在节点1中打印120,在节点2中打印80。当我重新运行时,数字会有所不同。看起来它正在创建分区缓存 初始化缓存的代码: private void initCache() { IgniteConfiguration configuration = new IgniteConfiguration();
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.localSizeLongCachePeekMode.ALL来计算主实体和备份实体 谢谢你的澄清。当运行在3台包含500个条目的服务器上时,分布看起来是这样的。allSize=500,primarySize=127,backupSize=373。nearysize=0 Svr1 allSize=500,primarySize=161,backupSize=339。nearysize=0 Svr2 allSize=500,primarySize=212,backupSize=288。nearSize=0 Svr3