不能将Ignite loadCache方法与IgniteBiPredicate一起使用

问题描述 投票:0回答:1

我正在使用Apache Ignite作为由postgres数据库支持的缓存,该数据库太大而无法一次初始化。相反,我想根据需要将选择性片段加载到我的缓存中。我想通过loadCache执行此操作(因为readThroughEnabled模式仅适用于简单的缓存操作,我无法保证我们将使用它),它接受IgniteBiPredicate作为参数。但是,每当我尝试使用IgniteBiPredicate作为过滤器时,我都会得到阻止我加载缓存的ClassCastExceptions。

这是针对我的服务器本地Ignite的单个节点。我已经尝试使用我的缓存并在其上调用“loadCache(biPredicate,null)”来尝试加载我想要的特定数据。这是我的代码示例,其中删除了一些域特定信息:

public void initFoo(int key){
  IgniteCache<Integer, Foo> myCache = getCache(Foo.class);
  if (myCache != null){
    myCache.loadCache(new IgniteBiPredicate<Integer, Foo>() {
      @Override
      public boolean apply(Integer integer, Foo foo){
        return integer == key;
      }
    }, null);
  }
}

我希望这会导致我的缓存被加载,至少是我关心这个特定条目的部分。相反,我明白了

"Failed to load cache:  Foo"
...(lots of nested exceptions eventually leading to)
...
"Caused by:  jvaa.lang.ClassCastException: 
org.apache.ignite.internal.binary.BinaryObjectImpl cannot be cast to 
com.sms.Foo"

我相信这不是我的缓存配置中的问题(至少在Java对象的级别),因为当我做一个没有参数的简单loadCache时,整个缓存加载得很好并且可用。难道我做错了什么?

postgresql ignite
1个回答
0
投票

基本上你得到的是BinaryObject而不是你的POJO对象。

你可以选择work with BinaryObject's,或者应该有一个设置来扭转这种行为。例如,在创建缓存时尝试使用cacheCfg.setStoreKeepBinary(false)。

UPD:我已经检查了它,似乎没有使用storeKeepBinary。无论如何,如果你愿意,你可以做Foo foo = binaryObject.deserialize();。我仍然不确定这是否是可配置的,或者这个闭包只是得到了什么。

© www.soinside.com 2019 - 2024. All rights reserved.