简体   繁体   English

如何为Apache Ignite缓存配置持久性存储?

[英]How to configure persistent storage for Apache Ignite cache?

I'm trying to configure persistent storage for Apache Ignite, so that my IgniteCache instance won't lose data on app restart. 我正在尝试为Apache Ignite配置持久性存储,以使我的IgniteCache实例在应用程序重启时不会丢失数据。 My setup is a local one-node cluster started from my code like this: 我的设置是一个从我的代码开始的本地单节点群集,如下所示:

IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setWorkDirectory("C:\\ignite");

// Ignite persistence configuration.
DataStorageConfiguration storageCfg = new DataStorageConfiguration();
storageCfg.setStoragePath("ignitedb/storage");
storageCfg.setWalPath("ignitedb/wal");
storageCfg.setWalArchivePath("ignitedb/wal/archive");

// Enabling the persistence.

storageCfg.getDefaultDataRegionConfiguration().setPersistenceEnabled(true);

// Applying settings.
cfg.setDataStorageConfiguration(storageCfg);

Ignite ignite = Ignition.getOrStart(cfg);
ignite.active(true);
// Get all server nodes that are already up and running.
Collection<ClusterNode> nodes = ignite.cluster().forServers().nodes();
// Set the baseline topology that is represented by these nodes.
ignite.cluster().setBaselineTopology(nodes);
return ignite;

The cache is created like this: 缓存是这样创建的:

cacheConfiguration = new CacheConfiguration<>();
cacheConfiguration.setBackups(1);
cacheConfiguration.setAtomicityMode(CacheAtomicityMode.ATOMIC);
cacheConfiguration.setName("UserCache");
cacheConfiguration.setCacheMode(CacheMode.LOCAL);
cacheConfiguration.setReadFromBackup(true);
cacheConfiguration.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
cacheConfiguration.setIndexedTypes(String.class, User.class);
IgniteCache<String, User> cache = ignite.getOrCreateCache(cacheConfiguration);

Storing User objects in the cache works. 在缓存中存储User对象的工作原理。 Ignite creates a directory structure under C:\\ignite . Ignite在C:\\ignite下创建目录结构。 But on app restart, all data is lost. 但是在应用重启时,所有数据都会丢失。 How can I configure this properly? 如何正确配置?

It seems that the root cause is LOCAL cache mode. 似乎根本原因是LOCAL缓存模式。 Try to use REPLICATED or PARTITIONED : https://apacheignite.readme.io/docs/cache-modes 尝试使用REPLICATEDPARTITIONEDhttps : //apacheignite.readme.io/docs/cache-modes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM