You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by 一路向北 <29...@qq.com> on 2018/06/06 12:32:43 UTC

transaction does not work

I found some problems when I tried to use ignite transactions.
I expected that the transaction would commit alfter tx.commit();
but when I debugged my code step by step , changes had been already in effect before tx.commit();。 
I also tried reading some source code of ignite transactions, but found no answer。
I guess I must make a stupid mistake.


Here is my code.


 public static void withTransaction(Execute execute) throws Exception {
        try (Transaction tx = Ignition.ignite().transactions().txStart()) {
            execute.call();
            tx.commit();
        }
    }


public void call() throws Exception {
                    Area area = new Area();
                    area.cityId = 1l;
                    area.name = "test";
                    …
                    cache.put(entity.id, entity);
                    …
}

Re: transaction does not work

Posted by "WALL.E" <29...@qq.com>.
I tried 
cache = Ignition.ignite().getOrCreateCache(new
CacheConfiguration<>("cache_name").setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL));
and 
cache = Ignition.ignite().cache("cache_name");
but neither of them worked.



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

Re: transaction does not work

Posted by Kuznetsov Aleksey <al...@gmail.com>.
Do cache instance retrieved from the same ignite instance ?

If not, fix it, cache must be retrieved this way : 
Ignition.ignite().cache("your_cache_name")


06.06.2018 15:32, 一路向北 пишет:
> I found some problems when I tried to use ignite transactions.
> I expected that the transaction would commit alfter tx.commit();
> but when I debugged my code step by step , changes had been already in 
> effect before tx.commit();。
> I also tried reading some source code of ignite transactions, but 
> found no answer。
> I guess I must make a stupid mistake.
>
> Here is my code.
>
>  public static void withTransaction(Execute execute) throws Exception {
>         try (Transaction tx = 
> Ignition.ignite().transactions().txStart()) {
>             execute.call();
>             tx.commit();
>         }
>     }
>
> public void call() throws Exception {
>                     Area area = new Area();
>                     area.cityId = 1l;
>                     area.name = "test";
>                     …
>                     cache.put(entity.id, entity);
>                     …
> }
>


Re: transaction does not work

Posted by "WALL.E" <29...@qq.com>.
Problem has been resolved.
The cache had already been initialized by the other thread.
But in that thread, CacheConfiguration did not call
setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
So the current thread use the initialized cache, although it calls
setAtomicityMode.It seems not work.



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