首页 文章

使用谓词加载缓存

提问于
浏览
0

我有一个包含许多类型的缓存 . 我正在运行纯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.");

错误 .

[错误] 2017-01-30 13:01:28.913 [main] ServiceGrid - 异常失败 . javax.cache.integration.CacheLoaderException:无法加载缓存:org.apache.ignite.cache.store.jdbc.CacheAbstractJdbcStore.loadCache中的D9Cache(CacheAbstractJdbcStore.java:847)〜[ignite-core-1.8.0.jar:1.8 .0] atg.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] at org.apache.ignite.internal.processors.cache . IgniteCacheProxy.localLoadCache(IgniteCacheProxy.java:413)〜[ignite-core-1.8.0.jar:1.8.0] at 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:org.apache.ignite.internal中ID为292145121的解析类失败.binary.BinaryContext.descriptorForTypeId(BinaryContext.java:696)〜[ignite-core-1.8.0.jar:1.8.0] at 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] atg.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.appl y(GridDhtCacheAdapter.java:501)〜[ignite-core-1.8.0.jar:1.8.0] at 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] at org.apache.ignite.cache.store.jdbc.CacheAbstractJdbcStore $ 1.call(CacheAbstractJdbcStore.java:429)〜[ignite-core-1.8.0.jar:1.8.0] at java.util.concurrent.FutureTask.run (FutureTask.java:266)〜[?:1.8.0_111] java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)〜[?:1.8.0_111] at 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.Ignit eCheckedException:在marshaller缓存和本地文件中找不到类定义 . org.apache.ignite.internal.MarshallerContextImpl.className(MarshallerContextImpl.java:218)〜[ignite-core-1.8.0.jar] [id = 292145121,file = / tmp / ignite / work / marshaller / 292145121.classname] :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 orB.apache.ignite.internal.binary.BinaryReaderExImpl.deserialize0(BinaryReaderExImpl.java:1491)〜[[] ignite-core-1.8.0.jar:1.8.0] atorg.apache.ignite.internal.binary.BialObject.lite.deserializeVal (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] at 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 . org.apache.ignite.internal上的apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter $ 4.apply(GridDhtCacheAdapter.java:501)~ [ignite-core-1.8.0.jar:1.8.0] . servers.cache.distributed.dht.GridDhtCacheAdapter $ 4.apply(GridDhtCacheAdapter.java:497)〜[ignite-core-1.8.0.jar:1.8.0] org.apache.i org.apache.ignite.cache.store.jdbc中的gnite.internal.processors.cache.store.GridCacheStoreManagerAdapter $ 3.apply(GridCacheStoreManagerAdapter.java:528)~ [ignite-core-1.8.0.jar:1.8.0] . CacheAbstractJdbcStore $ 1.call(CacheAbstractJdbcStore.java:462)〜[ignite-core-1.8.0.jar:1.8.0] at 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] at java.lang.Thread .run(Thread.java:745)〜[?:1.8.0_111]

2 回答

  • 1

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

  • 0

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

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

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

    所以我做的是沿着以下几点:

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

    ...

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

相关问题