You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Michael Hubbard <me...@gmail.com> on 2019/04/17 13:47:35 UTC

Can't use loadCache with IgniteBiPredicate

I'm trying to selectively initialize pieces of my IgniteCache that is
backed  by a postgres database.  When I use loadCache() with no arguments,
the entire cache loads fine.  However, the table I'm loading is very large,
and I want to use an IgniteBiPredicate to only load the pieces I care
about.  Whenever I try this, I get ClassCastExceptions.  Here is an example
of what I'm trying to do:

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

Whenever I try this, I get ClassCastExceptions on the apply method of this
bipredicate, saying that BinaryObjectImpl cannot be cast to Foo--why is
what's coming out of the cache a BinaryObjectImpl?  How am I supposed to
use the IgniteBiPredicate?

Re: Can't use loadCache with IgniteBiPredicate

Posted by Michael Hubbard <me...@gmail.com>.
This is the stacktrace for the exception:

Caused by: java.lang.ClassCastException:
org.apache.ignite.internal.binary.BinaryObjectImpl cannot be cast to
com.sms.Foo
        at
com.sms.flexnet.maintenance.data.IgniteFooDAO$3.apply(IgniteFooDAO.java:164)
        at
org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter.loadEntry(GridDhtCacheAdapter.java:639)
        at
org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter.access$600(GridDhtCacheAdapter.java:99)
        at
org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter$5.apply(GridDhtCacheAdapter.java:612)
        at
org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter$5.apply(GridDhtCacheAdapter.java:608)
        at
org.apache.ignite.internal.processors.cache.store.GridCacheStoreManagerAdapter$3.apply(GridCacheStoreManagerAdapter.java:536)
        at
org.apache.ignite.cache.store.jdbc.CacheAbstractJdbcStore$1.call(CacheAbstractJdbcStore.java:470)
        at
org.apache.ignite.cache.store.jdbc.CacheAbstractJdbcStore$1.call(CacheAbstractJdbcStore.java:434)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)


For reference, the line in IgniteFooDAO that's listed in there is the
declaration of the IgniteBiPredicate apply method:

@Override
public boolean apply(Integer integer, Foo foo){





--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Can't use loadCache with IgniteBiPredicate

Posted by 18624049226 <18...@163.com>.
hi team,

BinaryObject is not supported by key in IgniteBiPredicate of loadCache 
method.


this will throw java.lang.ClassNotFoundException: demo.model.CityKey, 
because keyType/valueType class are not exist in the server node classpath.

the cause is the line 560 of GridDhtCacheAdapter:

I think there is something wrong with the logic here.

This logic is not affected by the IgniteCache#withKeepBinary and 
CacheConfiguration#storeKeepBinary parameters.

https://ignite.apache.org/docs/latest/data-modeling/binary-marshaller#binaryobject-and-cachestore

Is the correct logic like this?

if IgniteCache#withKeepBinary or CacheConfiguration#storeKeepBinary is 
true : p.apply(BinaryObject,BinaryObject);

if IgniteCache#withKeepBinary or CacheConfiguration#storeKeepBinary is 
false : p.apply(POJO/primary type,POJO/primary type);


在 2019/4/18 22:02, Maxim.Pudov 写道:
> My assumption was that you used IgniteCache.withKeepBinary(true) in your own
> method getCache(Foo.class) method. Anyway, congrats on finding a solution.
>
>
>
> --
> Sent from:http://apache-ignite-users.70518.x6.nabble.com/

Re: Can't use loadCache with IgniteBiPredicate

Posted by "Maxim.Pudov" <pu...@gmail.com>.
My assumption was that you used IgniteCache.withKeepBinary(true) in your own
method getCache(Foo.class) method. Anyway, congrats on finding a solution.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Can't use loadCache with IgniteBiPredicate

Posted by Michael Hubbard <me...@gmail.com>.
I seem to have found the answer.  Changing the storeKeepBinary field didn't
seem to help, but I was able to change things by going to a generic
IgniteBiPredicate and casting inside the apply method.

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



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Can't use loadCache with IgniteBiPredicate

Posted by Michael Hubbard <me...@gmail.com>.
I tried setting storeKeepBinary to both "true" and "false" in my xml config
for the cache, neither made a difference.  Is this the right way to set it? 
Before this post, I wasn't setting it at all, so I'm assuming it was on
whatever the default value is.

<bean class="org.apache.ignite.configuration.CacheConfiguration>
     <property name="storeKeepBinary" value="true"/>
    ....
</bean>



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Can't use loadCache with IgniteBiPredicate

Posted by "Maxim.Pudov" <pu...@gmail.com>.
You might used the method org.apache.ignite.IgniteCache#withKeepBinary [1]
that's why your object wasn't deserialised.

[1]
https://ignite.apache.org/releases/latest/javadoc/org/apache/ignite/IgniteCache.html#withKeepBinary--

Max.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/