【发布时间】:2017-08-14 11:04:10
【问题描述】:
看起来尽管配置中设置了过期时间,但数据并未从 Ignite 缓存中清除。我注意到这个问题发生在当我使用 SQL 将数据插入缓存表时。
emplCache.query(new SqlFieldsQuery(
"CREATE TABLE Employee (id LONG PRIMARY KEY, firstName VARCHAR, lastName VARCHAR,
salary DECIMAL, gender VARCHAR)")).getAll();
SqlFieldsQuery insertqry = new SqlFieldsQuery("INSERT INTO Employee (id, firstName,
lastName, salary, gender) values (?, ?, ?, ?, ?)");
emplCache.query(insertqry.setArgs(Long.toString(count), words[1], words[2],
words[3], words[4])).getAll();
这就是我配置过期的方式:
CacheConfiguration<?, ?> cfg = new CacheConfiguration<>(cacheName);
cfg.setCacheMode(CacheMode.PARTITIONED);
cfg.setName(cacheName);
cfg.setSqlSchema("PUBLIC");
cfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
cfg.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(SECONDS, 1)));
但是,如果我使用 dataStreamer 插入数据,我看不到这个问题。
IgniteDataStreamer<Integer, Employee> stmr = ignite.dataStreamer(cfg.getName())
stmr.addData(id, emp);
我错过了一些配置设置吗?
[PS] 在 Evgenii 的回答之后尝试了以下操作:
// This is a util method that returns a cache config for the given cache name and the expiry time in seconds
CacheConfiguration<?, ?> cfg = CacheConfig.getCacheConfig("emplCache", 1);
IgniteCache<?, ?> emplCache = ignite.getOrCreateCache(cfg);
emplCache.query(new SqlFieldsQuery(
"CREATE TABLE Employee (id LONG PRIMARY KEY, firstName VARCHAR, lastName VARCHAR, salary DECIMAL, gender VARCHAR)"
+ "WITH \"template=emplCache\" ")).getAll();
现在我得到这个缓存不存在的异常。但我试图在创建缓存后创建表:
Exception in thread "main" javax.cache.CacheException: class org.apache.ignite.internal.processors.query.IgniteSQLException: Cache doesn't exist: emplCache
at org.apache.ignite.internal.processors.cache.IgniteCacheProxy.query(IgniteCacheProxy.java:807)
at org.apache.ignite.internal.processors.cache.IgniteCacheProxy.query(IgniteCacheProxy.java:765)
at com.demo.ignite.svc.CsvStreamer.main(CsvStreamer.java:33)
Caused by: class org.apache.ignite.internal.processors.query.IgniteSQLException: Cache doesn't exist: emplCache
at org.apache.ignite.internal.processors.query.h2.ddl.DdlStatementsProcessor.convert(DdlStatementsProcessor.java:277)
at org.apache.ignite.internal.processors.query.h2.ddl.DdlStatementsProcessor.runDdlStatement(DdlStatementsProcessor.java:221)
at org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.queryDistributedSqlFields(IgniteH2Indexing.java:1331)
at org.apache.ignite.internal.processors.query.GridQueryProcessor$5.applyx(GridQueryProcessor.java:1815)
at org.apache.ignite.internal.processors.query.GridQueryProcessor$5.applyx(GridQueryProcessor.java:1813)
at org.apache.ignite.internal.util.lang.IgniteOutClosureX.apply(IgniteOutClosureX.java:36)
at org.apache.ignite.internal.processors.query.GridQueryProcessor.executeQuery(GridQueryProcessor.java:2293)
at org.apache.ignite.internal.processors.query.GridQueryProcessor.querySqlFields(GridQueryProcessor.java:1820)
at org.apache.ignite.internal.processors.cache.IgniteCacheProxy.query(IgniteCacheProxy.java:795)
【问题讨论】:
-
请分享您配置 EvictionPolicy 的缓存配置
-
编辑了我的问题以包含我在代码中设置的确切配置。除此之外,我没有做任何更多的配置。我假设 ExpiryPolicy 与 EvictionPolicy 相同。还是我错了?
标签: ignite