Apache Ignite - 启用本机持久性时过期策略不起作用
Apache Ignite - Expiry Policy not working when Native Persistence Enabled
我在持久存储模式下使用 Apache Ignite 和 Spring 数据(ignite 版本 2.9.1 和 spring 数据 2.2)。当我设置过期策略时,我注意到对象不会自动删除。它在我关闭本机持久性时起作用。
我错过了什么线索吗?
这里是GridGain的规范Link
更新 1:如果您已经有一个现有的本地 ignite DB,它看起来像是依赖,即当我从 Ignite DB 中删除所有文件时,它正在工作.但是如果我随后尝试更改策略,则在我重新启动 Ignite 集群时无法识别它。当数据库文件第一次创建时,它仍然继续使用以前的策略。
有什么想法吗?
配置Class
@Bean
public IgniteConfiguration igniteConfig() {
IgniteConfiguration igniteConfiguration = new IgniteConfiguration();
// Enabling peer-class loading feature.
igniteConfiguration.setPeerClassLoadingEnabled(true);
igniteConfiguration.setClientMode(false);
// Data Storage
DataStorageConfiguration dataStorageConfiguration = new DataStorageConfiguration();
dataStorageConfiguration.setPageSize(4 * 1024);
// Data Region
DataRegionConfiguration dataRegionConfiguration = new DataRegionConfiguration();
dataRegionConfiguration.setName(DATA_CONFIG_NAME);
dataRegionConfiguration.setInitialSize(100 * 1000 * 1000);
dataRegionConfiguration.setMaxSize(200 * 1000 * 1000);
/// enabling natvie persisten <-- After enabling the expiry policy is not Working !!!
dataRegionConfiguration.setPersistenceEnabled(true);
dataStorageConfiguration.setDataRegionConfigurations(dataRegionConfiguration);
igniteConfiguration.setDataStorageConfiguration(dataStorageConfiguration);
igniteConfiguration.setConsistentId("ItemFileSystem");
CacheConfiguration<Long,Item> itemCache=new CacheConfiguration<Long,Item>();
itemCache.setCopyOnRead(false);
// as we have one node for now
itemCache.setBackups(1);
itemCache.setAtomicityMode(CacheAtomicityMode.ATOMIC);
itemCache.setName(Item.cacheName);
itemCache.setDataRegionName(DATA_CONFIG_NAME);
itemCache.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
itemCache.setIndexedTypes(Long.class,Item.class);
// setting up the Expiry Policy
itemCache.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, 30)));
itemCache.setEagerTtl(true);
igniteConfiguration.setCacheConfiguration(itemCache);
return igniteConfiguration;
}
@Bean(name = "igniteInstance",destroyMethod = "close")
public Ignite ignite(IgniteConfiguration igniteConfiguration) throws IgniteException {
final Ignite ignite = Ignition.start(igniteConfiguration);
ignite.cluster().state(ClusterState.ACTIVE);
return ignite;
}
主程序
@Autowired
private ItemIgniteRepository itemRepo;
@Override
public void run(String... args) throws Exception {
log.info("XXXXXXXXXXX application started... XXXXXXXXXXX");
// delete everything in memory and native persistence
itemRepo.deleteAll();
Item item = new Item("AIX-1","Advanced Xtra Item");
itemRepo.save(item.getId(),item);
// start a thread which will print every 10s the items from cache
ListItemsThread target = new ListItemsThread();
Thread t = new Thread(target);
t.start();
log.info("waiting for shutdown...");
System.in.read();
target.keepRunning = false;
log.info("XXXXXXXXXXX application finished... XXXXXXXXXXX");
applicationContext.close();
}
class ListItemsThread implements Runnable {
public boolean keepRunning = true;
@Override
public void run() {
while(keepRunning) {
Long itemsCount = itemRepo.count();
log.info("Number of Items: {}", itemsCount);
Iterable<Item>items = itemRepo.findAll();
for(Item item : items) {
log.info("item: {}", item);
}
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
缓存定义(包括过期策略)是固定的table,创建后无法更改。对于纯内存集群,当您重新启动集群时会发生这种情况。有了持久性,您必须删除并重新创建 table.
我在持久存储模式下使用 Apache Ignite 和 Spring 数据(ignite 版本 2.9.1 和 spring 数据 2.2)。当我设置过期策略时,我注意到对象不会自动删除。它在我关闭本机持久性时起作用。
我错过了什么线索吗?
这里是GridGain的规范Link
更新 1:如果您已经有一个现有的本地 ignite DB,它看起来像是依赖,即当我从 Ignite DB 中删除所有文件时,它正在工作.但是如果我随后尝试更改策略,则在我重新启动 Ignite 集群时无法识别它。当数据库文件第一次创建时,它仍然继续使用以前的策略。
有什么想法吗?
配置Class
@Bean
public IgniteConfiguration igniteConfig() {
IgniteConfiguration igniteConfiguration = new IgniteConfiguration();
// Enabling peer-class loading feature.
igniteConfiguration.setPeerClassLoadingEnabled(true);
igniteConfiguration.setClientMode(false);
// Data Storage
DataStorageConfiguration dataStorageConfiguration = new DataStorageConfiguration();
dataStorageConfiguration.setPageSize(4 * 1024);
// Data Region
DataRegionConfiguration dataRegionConfiguration = new DataRegionConfiguration();
dataRegionConfiguration.setName(DATA_CONFIG_NAME);
dataRegionConfiguration.setInitialSize(100 * 1000 * 1000);
dataRegionConfiguration.setMaxSize(200 * 1000 * 1000);
/// enabling natvie persisten <-- After enabling the expiry policy is not Working !!!
dataRegionConfiguration.setPersistenceEnabled(true);
dataStorageConfiguration.setDataRegionConfigurations(dataRegionConfiguration);
igniteConfiguration.setDataStorageConfiguration(dataStorageConfiguration);
igniteConfiguration.setConsistentId("ItemFileSystem");
CacheConfiguration<Long,Item> itemCache=new CacheConfiguration<Long,Item>();
itemCache.setCopyOnRead(false);
// as we have one node for now
itemCache.setBackups(1);
itemCache.setAtomicityMode(CacheAtomicityMode.ATOMIC);
itemCache.setName(Item.cacheName);
itemCache.setDataRegionName(DATA_CONFIG_NAME);
itemCache.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
itemCache.setIndexedTypes(Long.class,Item.class);
// setting up the Expiry Policy
itemCache.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, 30)));
itemCache.setEagerTtl(true);
igniteConfiguration.setCacheConfiguration(itemCache);
return igniteConfiguration;
}
@Bean(name = "igniteInstance",destroyMethod = "close")
public Ignite ignite(IgniteConfiguration igniteConfiguration) throws IgniteException {
final Ignite ignite = Ignition.start(igniteConfiguration);
ignite.cluster().state(ClusterState.ACTIVE);
return ignite;
}
主程序
@Autowired
private ItemIgniteRepository itemRepo;
@Override
public void run(String... args) throws Exception {
log.info("XXXXXXXXXXX application started... XXXXXXXXXXX");
// delete everything in memory and native persistence
itemRepo.deleteAll();
Item item = new Item("AIX-1","Advanced Xtra Item");
itemRepo.save(item.getId(),item);
// start a thread which will print every 10s the items from cache
ListItemsThread target = new ListItemsThread();
Thread t = new Thread(target);
t.start();
log.info("waiting for shutdown...");
System.in.read();
target.keepRunning = false;
log.info("XXXXXXXXXXX application finished... XXXXXXXXXXX");
applicationContext.close();
}
class ListItemsThread implements Runnable {
public boolean keepRunning = true;
@Override
public void run() {
while(keepRunning) {
Long itemsCount = itemRepo.count();
log.info("Number of Items: {}", itemsCount);
Iterable<Item>items = itemRepo.findAll();
for(Item item : items) {
log.info("item: {}", item);
}
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
缓存定义(包括过期策略)是固定的table,创建后无法更改。对于纯内存集群,当您重新启动集群时会发生这种情况。有了持久性,您必须删除并重新创建 table.