I've found that if CacheEntryProcessor is invoked on a transactional cache,
it will run right away when invoke is called, and then again when the
transaction is committed. If during the commit, there is an error, it looks
like the error is suppressed silently and the changes are lost. Test below
(I'm just simulating the error in the test, a more realistic use case is if
another thread has changed the value in between invoke and commit that would
cause the processor to fail).

Is it possible to have the commit fail when the processor fails?


>         CacheConfiguration
> <
> String, Integer
> >
>  testCacheConfiguration = new CacheConfiguration<>("testcache");
>        
> testCacheConfiguration.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
>         IgniteCache
> &lt;
> String, Integer
> &gt;
>  testCache = ignite.getOrCreateCache(testCacheConfiguration);
>         testCache.put("key", 5);
> 
>         System.out.println("before processor: " + testCache.get("key"));
> 
>         AtomicBoolean simulateFail = new AtomicBoolean(false);
>         try (Transaction tx = ignite.transactions().txStart()) {
>             testCache.invoke("key", (entry, args) -> {
>                 AtomicBoolean processorFail = (AtomicBoolean) args[0];
>                 Integer val = entry.getValue();
> 
>                 if (processorFail.get()) {
>                     System.out.println("processor fail");
>                     throw new EntryProcessorException();
>                 }
> 
>                 entry.setValue(val + 1);
> 
>                 System.out.println("processor success");
> 
>                 return null;
>             }, simulateFail);
>             System.out.println("before commit: " + testCache.get("key"));
>             simulateFail.set(true);
>             tx.commit();
>         }
>         System.out.println("after commit: " + testCache.get("key"));

Output:
before processor: 5
processor success
processor success
before commit: 6
processor fail
after commit: 5



--
View this message in context: 
http://apache-ignite-users.70518.x6.nabble.com/CacheEntryProcessor-failing-on-transactional-cache-tp1501.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Reply via email to