Apache Ignite - 启用本机持久性时到期策略不起作用

问题描述

我在持久存储模式下将 Apache Ignite 与 Spring Data 一起使用(使用 Spring Data 2.2 点燃版本 2.9.1)。当我设置到期策略时,我注意到对象不会自动删除。当我关闭本机持久性时,它会起作用。

知道我错过了什么吗?

这里是来自 GridGain Link

的规范

更新 1:如果您已经有一个现有的本机 ignite DB,这似乎取决于是否存在,即当我从 Ignite DB 中删除所有文件时,它正在工作。但是,如果我随后尝试更改策略,则在我重新启动 Ignite 集群时无法识别该策略。第一次创建数据库文件时,它仍然继续使用以前的策略。

有什么想法吗?

配置类

    @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();
                }
             }
        }
    }



解决方法

缓存定义——包括过期策略——是不可变的,创建后不能更改。对于纯内存集群,当您重新启动集群时会发生这种情况。使用持久性,您必须删除并重新创建表。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...