apache ignite-expiry策略不起作用

a8jjtwal  于 2021-08-20  发布在  Java
关注(0)|答案(1)|浏览(383)

我在持久存储模式下使用apache ignite和spring数据(ignite版本2.9.1和spring数据2.2)。当我设置到期策略时,我注意到对象不会自动删除。当我关闭本机持久性时,它就会工作。
知道我错过了什么吗?
这里是gridgain链接的规范
更新1:如果您已经有或没有现有的本机ignite db,则它看起来是独立的,即当我从ignite db中删除所有文件时,它正在工作。但是,如果我随后尝试更改策略,则在重新启动ignite集群时无法识别该策略。在第一次创建db文件时,它仍然使用以前的策略。
有什么想法吗?
配置类

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

ws51t4hk1#

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

相关问题