我尝试在添加一些调试代码后在集群(2个节点)上运行org.apache.ignite.examples.datastructures.IgniteSetExample。它的一些源代码如下:
CollectionConfiguration setCfg = new CollectionConfiguration();
setCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
setCfg.setCacheMode(CacheMode.PARTITIONED);
// Initialize new set.
IgniteSet<String> set = ignite.set(setName, setCfg);
System.out.println("Set size before initializing: " + set.size()); //added by myslef
// Initialize set items.
for (int i = 0; i < 10; i++){
set.add(Integer.toString(i));
System.out.println("Set: " + Arrays.toString(set.toArray())); //added by myslef
}
System.out.println("Set size after initializing: " + set.size());
在我看来,在添加数据之后,点燃集的大小应该 10 但我得到的数字大于10且通常为15.我发现有一些重复数字被添加到集合。日志在这里:
[19:53:16] Topology snapshot [ver=29, servers=2, clients=0, CPUs=8, heap=3.4GB]
Sep 21, 2017 7:53:16 PM org.apache.ignite.logger.java.JavaLogger info
Info: Topology snapshot [ver=29, servers=2, clients=0, CPUs=8, heap=3.4GB]
>>> Ignite set example started.
Set size before initializing: 0
Set: [0]
Set: [1, 1, 0]
Set: [2, 1, 2, 1, 0]
Set: [2, 1, 3, 2, 1, 0, 3]
Set: [2, 1, 3, 2, 1, 0, 4, 3]
Set: [2, 1, 3, 2, 1, 0, 5, 4, 3]
Set: [2, 1, 3, 2, 1, 0, 6, 5, 4, 3]
Set: [7, 2, 1, 3, 7, 2, 1, 0, 6, 5, 4, 3]
Set: [7, 2, 1, 3, 8, 7, 2, 1, 0, 6, 5, 4, 3]
Set: [7, 2, 1, 3, 9, 8, 7, 2, 1, 0, 6, 5, 4, 3]
Set size after initializing: 14
Sep 21, 2017 7:53:16 PM org.apache.ignite.logger.java.JavaLogger info
Info: Class locally deployed: class org.apache.ignite.examples.datastructures.IgniteSetExample$SetClosure
Sep 21, 2017 7:53:16 PM org.apache.ignite.logger.java.JavaLogger info
Info: Class locally deployed: class org.apache.ignite.configuration.CollectionConfiguration
Sep 21, 2017 7:53:16 PM org.apache.ignite.logger.java.JavaLogger info
Info: Class locally deployed: class org.apache.ignite.cache.CacheAtomicityMode
Sep 21, 2017 7:53:16 PM org.apache.ignite.logger.java.JavaLogger info
Info: Class locally deployed: class org.apache.ignite.cache.CacheMode
Set item has been added: 7aa983e1-c358-4876-b58f-4f3b7bfa65f3_0
Set item has been added: 7aa983e1-c358-4876-b58f-4f3b7bfa65f3_1
Set item has been added: 7aa983e1-c358-4876-b58f-4f3b7bfa65f3_2
Set item has been added: 7aa983e1-c358-4876-b58f-4f3b7bfa65f3_3
Set item has been added: 7aa983e1-c358-4876-b58f-4f3b7bfa65f3_4
Set size after writing [expected=20, actual=30]
Iterate over set.
Set item: 292c99a6-137b-433c-97d9-40ce0f8c0abc_1
Set item: 7aa983e1-c358-4876-b58f-4f3b7bfa65f3_3
Set item: 292c99a6-137b-433c-97d9-40ce0f8c0abc_3
Set item: 7
Set item: 292c99a6-137b-433c-97d9-40ce0f8c0abc_4
Set item: 2
Set item: 1
Set item: 7aa983e1-c358-4876-b58f-4f3b7bfa65f3_1
Set item: 3
Set item: 7aa983e1-c358-4876-b58f-4f3b7bfa65f3_2
Set item: 7aa983e1-c358-4876-b58f-4f3b7bfa65f3_3
Set item: 7aa983e1-c358-4876-b58f-4f3b7bfa65f3_4
Set item: 2
Set item: 1
Set item: 0
Set item: 6
Set item: 5
Set item: 7aa983e1-c358-4876-b58f-4f3b7bfa65f3_0
Set item: 4
Set item: 7aa983e1-c358-4876-b58f-4f3b7bfa65f3_1
Set item: 3
Set item: 7aa983e1-c358-4876-b58f-4f3b7bfa65f3_2
Set item: 292c99a6-137b-433c-97d9-40ce0f8c0abc_1
Set item: 9
Set item: 292c99a6-137b-433c-97d9-40ce0f8c0abc_2
Set item: 8
Set item: 292c99a6-137b-433c-97d9-40ce0f8c0abc_3
Set item: 7
Set item: 292c99a6-137b-433c-97d9-40ce0f8c0abc_4
Set item: 292c99a6-137b-433c-97d9-40ce0f8c0abc_0
Set size before clearing: 30
Set size after clearing: 0
Set was removed: true
Expected exception - Set has been removed from cache: GridCacheSetImpl [cache=GridDhtAtomicCache [defRes=org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache$1@482d776b, near=null, super=GridDhtCacheAdapter [multiTxHolder=java.lang.ThreadLocal@186978a6, stopping=false, super=GridDistributedCacheAdapter [super=GridCacheAdapter [locMxBean=org.apache.ignite.internal.processors.cache.CacheLocalMetricsMXBeanImpl@631e06ab, clusterMxBean=org.apache.ignite.internal.processors.cache.CacheClusterMetricsMXBeanImpl@2a3591c5, aff=org.apache.ignite.internal.processors.cache.affinity.GridCacheAffinityImpl@34a75079, igfsDataCache=false, mongoDataCache=false, mongoMetaCache=false, igfsDataCacheSize=null, asyncOpsSem=java.util.concurrent.Semaphore@346a361[Permits = 500], name=datastructures_ATOMIC_PARTITIONED_0@default-ds-group, size=0]]]], name=03bbdb45-72ce-45aa-b75f-00b7b6134dc6, id=d55a844ae51-baeb6ba4-cb04-4d72-b0d8-188f21bc5ac5, collocated=false, hdrPart=961, rmvd=true, binaryMarsh=true, compute=org.apache.ignite.internal.IgniteComputeImpl@4052274f]
Sep 21, 2017 7:53:17 PM org.apache.ignite.logger.java.JavaLogger info
Info: Command protocol successfully stopped: TCP binary
Sep 21, 2017 7:53:17 PM org.apache.ignite.logger.java.JavaLogger info
Info: Stopped cache [cacheName=ignite-sys-cache]
Sep 21, 2017 7:53:17 PM org.apache.ignite.logger.java.JavaLogger info
Info: Stopped cache [cacheName=datastructures_TRANSACTIONAL_PARTITIONED_0@default-ds-group, group=default-ds-group]
Sep 21, 2017 7:53:17 PM org.apache.ignite.logger.java.JavaLogger info
Info: Stopped cache [cacheName=datastructures_ATOMIC_PARTITIONED_0@default-ds-group, group=default-ds-group]
Sep 21, 2017 7:53:17 PM org.apache.ignite.logger.java.JavaLogger info
Info: Stopped cache [cacheName=ignite-sys-atomic-cache@default-ds-group, group=default-ds-group]
Sep 21, 2017 7:53:17 PM org.apache.ignite.logger.java.JavaLogger info
Info: Removed undeployed class: GridDeployment [ts=1505994796165, depMode=SHARED, clsLdr=sun.misc.Launcher$AppClassLoader@73d16e93, clsLdrId=355a844ae51-7aa983e1-c358-4876-b58f-4f3b7bfa65f3, userVer=0, loc=true, sampleClsName=org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap, pendingUndeploy=false, undeployed=true, usage=0]
[19:53:17] Ignite node stopped OK [uptime=00:00:00:778]
Sep 21, 2017 7:53:17 PM org.apache.ignite.logger.java.JavaLogger info
Info:
>>> +---------------------------------------------------------------------------------+
>>> Ignite ver. 2.1.0#20170721-sha1:a6ca5c8a97e9a4c9d73d40ce76d1504c14ba1940 stopped OK
>>> +---------------------------------------------------------------------------------+
>>> Grid uptime: 00:00:00:778
Ignite set example finished.
当且仅当我设置&#34; 并置&#34;如果CollectionConfiguration实例为 true ,则IgniteSet的大小为10。但根据官方文档,如果IgniteSet中有大量数据,那么&#34; false&#34;建议配置&#34;并置&#34;属性。那么这里有什么不对?
答案 0 :(得分:1)
您可以通过客户端模式使用IgniteSet倾注数据,我已经过测试并证明了这一点。像这样:Ignition.setClientMode(true);
答案 1 :(得分:0)
看起来IgniteSet有一个错误。谢谢你的报告。
现在您可以直接使用缓存而不是集合。同样的例子如下所示:
public class IgniteSetExample {
static final Object DUMMY = new Object();
public static void main(String[] args) throws Exception {
Ignite ignite = Ignition.start("examples/config/example-ignite.xml");
CacheConfiguration<String, Object> cacheCfg = new CacheConfiguration<>("setCache");
cacheCfg.setAtomicityMode(TRANSACTIONAL);
cacheCfg.setCacheMode(PARTITIONED);
IgniteCache<String, Object> cache = ignite.getOrCreateCache(cacheCfg);
System.out.println("Set size before init: " + cache.size());
for (int i = 0; i < 10; i++) {
cache.put(Integer.toString(i), DUMMY);
System.out.println("Set elements: " + getKeys(cache));
}
System.out.println("Set size after init: " + cache.size());
}
static <T> List<T> getKeys(IgniteCache<T, ?> cache) {
List<T> keys = new ArrayList<>(cache.size());
for (Cache.Entry<T, ?> e : cache)
keys.add(e.getKey());
return keys;
}
}