Ignite 2.5.0上的TTL无法正常工作 [英] TTL on Ignite 2.5.0 not working

查看:103
本文介绍了Ignite 2.5.0上的TTL无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用2种方法为Ignite中的记录启用TTL,但似乎没有用.需要帮助以了解我是否缺少某些东西.

I tried enabling TTL for records in Ignite using 2 approaches, but didn't seems to be working. Need help to understand if I am missing something.

IgniteCache cache = ignite.getOrCreateCache(IgniteCfg.CACHE_NAME);
cache.query(new SqlFieldsQuery(
                "CREATE TABLE IF NOT EXISTS City (id LONG primary key, name varchar, region varchar)"))
                .getAll();
cache.withExpiryPolicy(new CreatedExpiryPolicy(new Duration(TimeUnit.SECONDS, 10)))
                .query(new SqlFieldsQuery(
                        "INSERT INTO City (id, name, region) VALUES (?, ?, ?)").setArgs(1, "Forest Hill1", "GLB"))
                .getAll();

所以您在上面看到了我在Cache中创建表并插入了记录TTL过期10秒钟的记录,但似乎它永不过期.

So you see above I created table in Cache and inserted record mentioning expiry TTL for 10 seconds, but seems that it never expires.

我尝试了另一种在插入记录时不设置TTL的方法,我在初始化Ignite时在CacheConfiguration中提到过,下面是代码示例

I tried another approach of rather than setting TTL while inserting the record, I mentioned in CacheConfiguration while I initialize Ignite, below is the code sample

Ignition.setClientMode(true);
IgniteConfiguration cfg = new IgniteConfiguration();

// Disabling peer-class loading feature.
cfg.setPeerClassLoadingEnabled(false);

CacheConfiguration ccfg = createCacheConfiguration();
cfg.setCacheConfiguration(ccfg);
ccfg.setEagerTtl(true);
ccfg.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, 5)));

TcpCommunicationSpi commSpi = new TcpCommunicationSpi();
cfg.setCommunicationSpi(commSpi);

TcpDiscoveryVmIpFinder tcpDiscoveryFinder = new TcpDiscoveryVmIpFinder();
String[] addresses = { "127.0.0.1" };
tcpDiscoveryFinder.setAddresses(Arrays.asList(addresses));
TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
discoSpi.setIpFinder(tcpDiscoveryFinder);
cfg.setDiscoverySpi(discoSpi);

return Ignition.start(cfg);

本地执行Ignite(而不是在内存中执行),因为我的最终目标是能够从多个应用程序实例甚至多个应用程序连接到同一Ignite.

Executing Ignite locally (not as in memory) as my final goal is to be able to connect to same Ignite from multiple instances of app or even multiple apps.

推荐答案

Ignite SQL当前不与到期策略交互,并且不更新TTL.有一个功能请求: https://issues.apache.org/jira/浏览/IGNITE-7687 .

Ignite SQL currently doesn't interact with expiry policies and doesn't update TTL. There is a Feature Request for that: https://issues.apache.org/jira/browse/IGNITE-7687.

这篇关于Ignite 2.5.0上的TTL无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆