我使用的是Apache Ignite 2.4.0,其中包含了我身边的小变化的官方示例(下面的代码)。我测试了以下场景:
启动了https://github.com/apache/ignite/blob/master/examples/src/main/java/org/apache/ignite/examples/ExampleNodeStartup.java的三个实例(在我的本地笔记本电脑上)
启动了一个客户端并创建了一个带有1个备份的缓存
public static void main(String[] args) throws IgniteException {
Ignition.setClientMode(true);
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
CacheConfiguration cfg = new CacheConfiguration();
cfg.setName(CACHE_NAME)
.setAtomicityMode(CacheAtomicityMode.ATOMIC)
.setCacheMode(CacheMode.PARTITIONED)
.setBackups(1)
.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC)
.setReadFromBackup(true);
try (IgniteCache<Integer, String> cache = ignite.getOrCreateCache(cfg)) {
putGet(cache);
}
}
}
使用客户端,我使用putGet方法进行写入和读取:
private static void putGet(IgniteCache<Integer, String> cache) throws IgniteException {
System.out.println(">>> Cache put-get example started.");
// Store keys in cache.
for (int i = 0; i < 100; i++)
cache.put(i, Integer.toString(i));
System.out.println(">>> Stored values in cache.");
int size = 0;
for (int i = 0; i < 100; i++) {
if (cache.get(i) != null)
size++;
}
System.out.println("Cache size:" + size);
}
当我第一次执行putGet方法时,输出当然是:
>>> Cache put-get example started.
>>> Stored values in cache.
Cache size:100
[01:35:21] Ignite node stopped OK [uptime=00:00:00.744]
然后我停止一个节点并再次执行putGet方法(这次只是读取部分)。结果是:
>>> Cache put-get example started.
>>> Stored values in cache.
Cache size:48
[01:38:25] Ignite node stopped OK [uptime=00:00:00.406]
集群是否能够从其他两个节点上的备份中恢复驻留在崩溃节点上的数据?备份的行为更准确是什么?是否需要持久性模式?