[英]How to configure persistent storage for Apache Ignite cache?
我正在嘗試為Apache Ignite配置持久性存儲,以使我的IgniteCache實例在應用程序重啟時不會丟失數據。 我的設置是一個從我的代碼開始的本地單節點群集,如下所示:
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;
緩存是這樣創建的:
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);
在緩存中存儲User
對象的工作原理。 Ignite在C:\\ignite
下創建目錄結構。 但是在應用重啟時,所有數據都會丟失。 如何正確配置?
似乎根本原因是LOCAL
緩存模式。 嘗試使用REPLICATED
或PARTITIONED
: https : //apacheignite.readme.io/docs/cache-modes
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.