You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by "haotian.chen" <ha...@blackrock.com> on 2018/06/05 18:56:27 UTC

IgniteCache invoke CacheEntryProcessor, not throw EntryProcessorException

Hi Developers,

I am not sure if I understand the IgniteCache invoke method API correctly
here: 
https://ignite.apache.org/releases/latest/javadoc/org/apache/ignite/IgniteCache.html#invoke-K-org.apache.ignite.cache.CacheEntryProcessor-java.lang.Object...-
<https://ignite.apache.org/releases/latest/javadoc/org/apache/ignite/IgniteCache.html#invoke-K-org.apache.ignite.cache.CacheEntryProcessor-java.lang.Object...->  
.

I wrote a CacheEntryProcessor. In CacheEntryProcessor's process method, it
will detect any IllegalArgumentException of input and wrap the exception as
EntryProcessorException, and then throw it. 

However, when a client invokes such CacheEntryProcessor and expects an
exception to be thrown, ignite silently ignores the exception and proceeds. 

I am under ATOMIC and PARTITION mode. 

Is this behavior expected? 
Could I make sure that the client get an exception if the CacheEntryProssor
fails?



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

Re: IgniteCache invoke CacheEntryProcessor, not throw EntryProcessorException

Posted by Andrey Mashenkov <an...@gmail.com>.
Hi,

Yes, but no.
You will observe lower latency per operation on client and you will be able
to utilize more server resources with less number of threads.
But operation logic will be the same, no steps will be omit (backups will
be updated as well)... so, maximal performance that can be achieved will be
the same.


On Thu, Jun 7, 2018 at 7:05 PM, haotian.chen <ha...@blackrock.com>
wrote:

> Awesome, that's super clear!
> One last question, will full_async have better performance over the other
> two usually?
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>



-- 
Best regards,
Andrey V. Mashenkov

Re: IgniteCache invoke CacheEntryProcessor, not throw EntryProcessorException

Posted by "haotian.chen" <ha...@blackrock.com>.
Awesome, that's super clear! 
One last question, will full_async have better performance over the other
two usually?



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

Re: IgniteCache invoke CacheEntryProcessor, not throw EntryProcessorException

Posted by Andrey Mashenkov <an...@gmail.com>.
Hi,

Looks like it is ok.

Ignite have next sync modes full_sync, primary_sync, full_Async.
You can detect failure from user thread if it happens on synchronous phase.

FULL_SYNC: cache operation return control to user thread after operation
has been applied on primary and all backups.
All exceptions occurs during operation will be propagated to user.

With primary_sync, cache operation return control to user thread after
operation has been applied on primary. Backups will be updated in async way.
Only exceptions which occurs during primary operation will be propagated to
user. Exceptions from backups will be ignored as nobody waits for backup
operation results.

With full_Ascync, cache operation return control to user thread immediately
after request has been sent to primary. All, Primary and backup will be
updates in async way.
Only exceptions, which occurs during sending request to primary node, will
be propagated to user. Others will be ignored as nobody waits for backup
operation results.



On Wed, Jun 6, 2018 at 7:24 PM, haotian.chen <ha...@blackrock.com>
wrote:

> Hi Andrew,
>
> Thanks a lot for the response!
>
> While reproducing the case, I found that: If I set
> CacheWriteSynchronizatoinMode to FULL_ASYNC, EntryProcessorException is
> ignored. But if I set it PRIMARY_SYNC, then the EntryProcessorException
> will
> be thrown.
>
> Is it intentional that under FULL_ASYNC the exception will be ignored?
> Should it be that Exception will be thrown when the CacheEntryProcessor
> eventually ran?
>
> Here is the sample code:
>
>
> import org.apache.ignite.Ignite;
> import org.apache.ignite.IgniteCache;
> import org.apache.ignite.Ignition;
> import org.apache.ignite.cache.*;
> import org.apache.ignite.configuration.CacheConfiguration;
> import org.apache.ignite.configuration.IgniteConfiguration;
>
> import javax.cache.processor.EntryProcessorException;
> import javax.cache.processor.MutableEntry;
>
> public class Main {
>     public static void main(String[] args) {
>
>         class IncrementOddEntryProcessor implements
> CacheEntryProcessor<String, Integer, Object> {
>
>             public Object process(MutableEntry<String, Integer> entry,
> Object... arguments) throws EntryProcessorException {
>                 Integer value = entry.getValue();
>                 if (value % 2 == 0) {
>                     throw new EntryProcessorException("can't operates on
> even number");
>                 } else {
>                     entry.setValue(value + 1);
>                     return null;
>                 }
>             }
>
>         }
>
>         IgniteConfiguration igniteCfg = new IgniteConfiguration()
>                 .setGridLogger(new Slf4jLogger())
>                 .setIgniteInstanceName("testinstance");
>
>         Ignite ignite = Ignition.getOrStart(igniteCfg);
>
>         try {
>             CacheConfiguration<String, Integer> cacheCfg = new
> CacheConfiguration<String, Integer>()
>                     .setName("testcache")
>                     .setAtomicityMode(CacheAtomicityMode.ATOMIC)
>                     .setRebalanceMode(CacheRebalanceMode.ASYNC)
>
> .setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_ASYNC)
>
> .setPartitionLossPolicy(PartitionLossPolicy.READ_WRITE_SAFE);
>
>             IgniteCache<String, Integer> cache =
> ignite.createCache(cacheCfg);
>
>             cache.put("1", 1);
>             cache.put("2", 2);
>
>             cache.invoke("1", new IncrementOddEntryProcessor());
>             cache.invoke("2", new IncrementOddEntryProcessor());
>
>             System.out.println(cache.get("1"));
>             System.out.println(cache.get("2"));
>         } finally {
>             ignite.close();
>         }
>
>
>     }
> }
>
>
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>



-- 
Best regards,
Andrey V. Mashenkov

Re: IgniteCache invoke CacheEntryProcessor, not throw EntryProcessorException

Posted by "haotian.chen" <ha...@blackrock.com>.
Hi Andrew,

Thanks a lot for the response!

While reproducing the case, I found that: If I set
CacheWriteSynchronizatoinMode to FULL_ASYNC, EntryProcessorException is
ignored. But if I set it PRIMARY_SYNC, then the EntryProcessorException will
be thrown.

Is it intentional that under FULL_ASYNC the exception will be ignored?
Should it be that Exception will be thrown when the CacheEntryProcessor
eventually ran? 

Here is the sample code:


import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.Ignition;
import org.apache.ignite.cache.*;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;

import javax.cache.processor.EntryProcessorException;
import javax.cache.processor.MutableEntry;

public class Main {
    public static void main(String[] args) {

        class IncrementOddEntryProcessor implements
CacheEntryProcessor<String, Integer, Object> {

            public Object process(MutableEntry<String, Integer> entry,
Object... arguments) throws EntryProcessorException {
                Integer value = entry.getValue();
                if (value % 2 == 0) {
                    throw new EntryProcessorException("can't operates on
even number");
                } else {
                    entry.setValue(value + 1);
                    return null;
                }
            }

        }

        IgniteConfiguration igniteCfg = new IgniteConfiguration()
                .setGridLogger(new Slf4jLogger())
                .setIgniteInstanceName("testinstance");

        Ignite ignite = Ignition.getOrStart(igniteCfg);

        try {
            CacheConfiguration<String, Integer> cacheCfg = new
CacheConfiguration<String, Integer>()
                    .setName("testcache")
                    .setAtomicityMode(CacheAtomicityMode.ATOMIC)
                    .setRebalanceMode(CacheRebalanceMode.ASYNC)
                   
.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_ASYNC)
                   
.setPartitionLossPolicy(PartitionLossPolicy.READ_WRITE_SAFE);

            IgniteCache<String, Integer> cache =
ignite.createCache(cacheCfg);

            cache.put("1", 1);
            cache.put("2", 2);

            cache.invoke("1", new IncrementOddEntryProcessor());
            cache.invoke("2", new IncrementOddEntryProcessor());

            System.out.println(cache.get("1"));
            System.out.println(cache.get("2"));
        } finally {
            ignite.close();
        }


    }
}





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

Re: IgniteCache invoke CacheEntryProcessor, not throw EntryProcessorException

Posted by Andrey Mashenkov <an...@gmail.com>.
Hi,

Would you please share a full config? or reproducer if possible?


On Tue, Jun 5, 2018 at 9:56 PM, haotian.chen <ha...@blackrock.com>
wrote:

> Hi Developers,
>
> I am not sure if I understand the IgniteCache invoke method API correctly
> here:
> https://ignite.apache.org/releases/latest/javadoc/org/
> apache/ignite/IgniteCache.html#invoke-K-org.apache.ignite.cache.
> CacheEntryProcessor-java.lang.Object...-
> <https://ignite.apache.org/releases/latest/javadoc/org/
> apache/ignite/IgniteCache.html#invoke-K-org.apache.ignite.cache.
> CacheEntryProcessor-java.lang.Object...->
> .
>
> I wrote a CacheEntryProcessor. In CacheEntryProcessor's process method, it
> will detect any IllegalArgumentException of input and wrap the exception as
> EntryProcessorException, and then throw it.
>
> However, when a client invokes such CacheEntryProcessor and expects an
> exception to be thrown, ignite silently ignores the exception and
> proceeds.
>
> I am under ATOMIC and PARTITION mode.
>
> Is this behavior expected?
> Could I make sure that the client get an exception if the CacheEntryProssor
> fails?
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>



-- 
Best regards,
Andrey V. Mashenkov