使用谓词加载缓存

时间:2017-01-30 02:11:18

标签: ignite

我有一个包含许多类型的缓存。我正在运行纯Java节点。我在部署服务之前在启动时加载缓存。缓存由CacheJdbcPojoStore支持。我正在使用Ignite 1.8。

当我使用null谓词加载时,一切正常。所有类型及其实例都加载到内存中。但是,当我加载谓词时,我收到以下错误。奇怪的是,在Windows上,错误不会发生,谓词工作正常。但是在Linux上,它失败了。这可能会出现什么问题?

缓存加载代码。 ServiceStatus和ServiceMetric只是我的数据库支持的两种pojo类型。

        log.info("Local load cache started.");
        cache.localLoadCache(new IgniteBiPredicate() {
            @Override
            public boolean apply(Object key, Object value) {
                // include by default, exclude explicitly

                // no service status before today
                if (value instanceof ServiceStatus) {
                    if (((ServiceStatus)value).getLastUpdated().before(Timestamp.valueOf(LocalDate.now().atStartOfDay()))){
                        return false;
                    }
                }

                // no service metrics before today
                if (value instanceof ServiceMetric) {
                    if (((ServiceMetric)value).getLastUpdated().before(Timestamp.valueOf(LocalDate.now().atStartOfDay()))){
                        return false;
                    }
                }

                return true;
            }
        }, null);
        log.info("Local load cache finished.");

错误。

[ERROR] 2017-01-30 13:01:28.913 [main] ServiceGrid - 异常失败。 javax.cache.integration.CacheLoaderException:无法加载缓存:D9Cache         在org.apache.ignite.cache.store.jdbc.CacheAbstractJdbcStore.loadCache(CacheAbstractJdbcStore.java:847)〜[ignite-core-1.8.0.jar:1.8.0]         在org.apache.ignite.internal.processors.cache.store.GridCacheStoreManagerAdapter.loadCache(GridCacheStoreManagerAdapter.java:512)〜[ignite-core-1.8.0.jar:1.8.0]         在org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter.localLoadCache(GridDhtCacheAdapter.java:497)〜[ignite-core-1.8.0.jar:1.8.0]         在org.apache.ignite.internal.processors.cache.IgniteCacheProxy.localLoadCache(IgniteCacheProxy.java:413)〜[ignite-core-1.8.0.jar:1.8.0]         在com.nmf.model.persistence.CacheUtil.loadCache(CacheUtil.java:87)〜[shared-data-model-1.0-SNAPSHOT.jar:?]         在com.nmf.grid.ServiceGrid.main(ServiceGrid.java:75)[dragon9-service-grid-1.0-SNAPSHOT.jar:?] 引起:org.apache.ignite.binary.BinaryObjectException:ID的解析类失败:292145121         在org.apache.ignite.internal.binary.BinaryContext.descriptorForTypeId(BinaryContext.java:696)〜[ignite-core-1.8.0.jar:1.8.0]         在org.apache.ignite.internal.binary.BinaryReaderExImpl.deserialize0(BinaryReaderExImpl.java:1491)〜[ignite-core-1.8.0.jar:1.8.0]         在org.apache.ignite.internal.binary.BinaryReaderExImpl.deserialize(BinaryReaderExImpl.java:1450)〜[ignite-core-1.8.0.jar:1.8.0]         在org.apache.ignite.internal.binary.BinaryObjectImpl.deserializeValue(BinaryObjectImpl.java:637)〜[ignite-core-1.8.0.jar:1.8.0]         在org.apache.ignite.internal.binary.BinaryObjectImpl.value(BinaryObjectImpl.java:142)〜[ignite-core-1.8.0.jar:1.8.0]         at org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter.loadEntry(GridDhtCacheAdapter.java:528)~ [ignite-core-1.8.0.jar:1.8.0]         在org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter.access $ 300(GridDhtCacheAdapter.java:94)〜[ignite-core-1.8.0.jar:1.8.0]         at org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter $ 4.apply(GridDhtCacheAdapter.java:501)~ [ignite-core-1.8.0.jar:1.8.0]         在org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter $ 4.apply(GridDhtCacheAdapter.java:497)〜[ignite-core-1.8.0.jar:1.8.0]         在org.apache.ignite.internal.processors.cache.store.GridCacheStoreManagerAdapter $ 3.apply(GridCacheStoreManagerAdapter.java:528)~ [ignite-core-1.8.0.jar:1.8.0]         在org.apache.ignite.cache.store.jdbc.CacheAbstractJdbcStore $ 1.call(CacheAbstractJdbcStore.java:462)〜[ignite-core-1.8.0.jar:1.8.0]         在org.apache.ignite.cache.store.jdbc.CacheAbstractJdbcStore $ 1.call(CacheAbstractJdbcStore.java:429)〜[ignite-core-1.8.0.jar:1.8.0]         在java.util.concurrent.FutureTask.run(FutureTask.java:266)〜[?:1.8.0_111]         在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)〜[?:1.8.0_111]         在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)〜[?:1.8.0_111]         在java.lang.Thread.run(Thread.java:745)〜[?:1.8.0_111] 引起:org.apache.ignite.IgniteCheckedException:在marshaller缓存和本地文件中找不到类定义。 [id = 292145121,file = / tmp / ignite / work / marshaller / 292145121.classname]         在org.apache.ignite.internal.MarshallerContextImpl.className(MarshallerContextImpl.java:218)〜[ignite-core-1.8.0.jar:1.8.0]         在org.apache.ignite.internal.MarshallerContextAdapter.getClass(MarshallerContextAdapter.java:174)〜[ignite-core-1.8.0.jar:1.8.0]         在org.apache.ignite.internal.binary.BinaryContext.descriptorForTypeId(BinaryContext.java:680)〜[ignite-core-1.8.0.jar:1.8.0]         在org.apache.ignite.internal.binary.BinaryReaderExImpl.deserialize0(BinaryReaderExImpl.java:1491)〜[ignite-core-1.8.0.jar:1.8.0]         在org.apache.ignite.internal.binary.BinaryReaderExImpl.deserialize(BinaryReaderExImpl.java:1450)〜[ignite-core-1.8.0.jar:1.8.0]         在org.apache.ignite.internal.binary.BinaryObjectImpl.deserializeValue(BinaryObjectImpl.java:637)〜[ignite-core-1.8.0.jar:1.8.0]         在org.apache.ignite.internal.binary.BinaryObjectImpl.value(BinaryObjectImpl.java:142)〜[ignite-core-1.8.0.jar:1.8.0]         at org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter.loadEntry(GridDhtCacheAdapter.java:528)~ [ignite-core-1.8.0.jar:1.8.0]         在org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter.access $ 300(GridDhtCacheAdapter.java:94)〜[ignite-core-1.8.0.jar:1.8.0]         at org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter $ 4.apply(GridDhtCacheAdapter.java:501)~ [ignite-core-1.8.0.jar:1.8.0]         在org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter $ 4.apply(GridDhtCacheAdapter.java:497)〜[ignite-core-1.8.0.jar:1.8.0]         在org.apache.ignite.internal.processors.cache.store.GridCacheStoreManagerAdapter $ 3.apply(GridCacheStoreManagerAdapter.java:528)~ [ignite-core-1.8.0.jar:1.8.0]         在org.apache.ignite.cache.store.jdbc.CacheAbstractJdbcStore $ 1.call(CacheAbstractJdbcStore.java:462)〜[ignite-core-1.8.0.jar:1.8.0]         在org.apache.ignite.cache.store.jdbc.CacheAbstractJdbcStore $ 1.call(CacheAbstractJdbcStore.java:429)〜[ignite-core-1.8.0.jar:1.8.0]         在java.util.concurrent.FutureTask.run(FutureTask.java:266)〜[?:1.8.0_111]         在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)〜[?:1.8.0_111]         在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)〜[?:1.8.0_111]         在java.lang.Thread.run(Thread.java:745)〜[?:1.8.0_111]

2 个答案:

答案 0 :(得分:1)

如果没有其他信息,很难提供建议,但您可以使用cache.withKeepBinary()检查它是否可重现。此外,尝试弹回整个群集。奇怪的是,该案例仅适用于Linux。

答案 1 :(得分:0)

我也看到过这个问题(为了时间的利益)导致我完全没有使用谓词。在使用谓词时加载缓存时,我会有时收到您在上面提到的异常。我在Linux和Windows上观察到了这一点,但它并不一致。有时缓存会加载,有时不加载。正如我所说,我被推了一段时间,所以假设这是一个竞争条件,在Ignite代码的某个地方运行谓词并解决了这个问题。

如果任何Ignite专家能够进一步阐明问题的潜在根源,我将很乐意尽可能提供帮助。

- 更新 - 在尝试从后备存储中加载日期之前,我已经通过“加热”二进制编组来解决了这个问题(导致文件找不到错误)

所以我所做的就是以下几行:

 IgniteCache cache = ignite.getOrCreateCache("my-cache");
 warmBinaryMarshaller(cache);
 cache.localLoadCache(cache, new MyPredicate(), (Object[])null);

...

private static void warmBinaryMarshaller(IgniteCache cache) throws Exception
{
    final IgniteCache transientCache = cache.withSkipStore();
    try{
        CacheKey key = new CacheKey();
        CacheEntity entity = CacheEntity(); 
        key.setId(0);
        entity.setId(0);
        transientCache.put(key, entity);
        transientCache.remove(key);
     } catch (Exception e) {
         log.error(e.getMessage(), e);
     }
}

...

然后我可以成功加载数据库中的对象