You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ignite.apache.org by "Anton Vinogradov (JIRA)" <ji...@apache.org> on 2017/09/20 15:12:00 UTC

[jira] [Comment Edited] (IGNITE-6380) Exception should be thrown on cache creation attempt inside transaction

    [ https://issues.apache.org/jira/browse/IGNITE-6380?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16173316#comment-16173316 ] 

Anton Vinogradov edited comment on IGNITE-6380 at 9/20/17 3:11 PM:
-------------------------------------------------------------------

[~xtern],

Simplified reproducer:
{noformat}
    public void test() throws Exception {
        Ignite ignite = startGrid();

        final IgniteCache<Object, Object> cache1 = ignite.getOrCreateCache(new CacheConfiguration<>()
            .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL)
            .setName("cache1"));

        final IgniteCache<Object, Object> cache2 = ignite.getOrCreateCache(new CacheConfiguration<>()
            .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL)
            .setName("cache2"));

        final CountDownLatch latch1 = new CountDownLatch(1);

        Thread t = new Thread(new Runnable() {
            @Override public void run() {
                Lock lock = cache2.lock("fake");

                try {
                    lock.lock();

                    System.out.println("Locked");

                    latch1.countDown();

                    Thread.sleep(1000);

                    cache1.clear();
                }
                catch (Exception e) {
                    e.printStackTrace();

                    throw new RuntimeException(e);
                }
                finally {
                    lock.unlock();
                }
            }
        });

        t.start();

        try {
            latch1.await();
        }
        catch (InterruptedException e) {
            e.printStackTrace();
        }

        ignite.getOrCreateCache(new CacheConfiguration<>()
            .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL)
            .setName("cache3"));

        System.out.println("No deadlock");
    }
{noformat}

cache.clear cause ctx.kernalContext().task().execute(...) which will be mapped to pending topology.

We should restrict such call when lock is locked and there is pending topology.

Simple addition of 
{{throw new IgniteException("")}}
imitating found locked lock
to  {{org.apache.ignite.internal.processors.task.GridTaskProcessor#execute(org.apache.ignite.compute.ComputeTask<T,R>, T, boolean, java.lang.String)}}
fixing reproducer.


was (Author: avinogradov):
[~xtern],

Simplified reproducer:
{noformat}
    public void test() throws Exception {
        Ignite ignite = startGrid();

        final IgniteCache<Object, Object> cache1 = ignite.getOrCreateCache(new CacheConfiguration<>()
            .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL)
            .setName("cache1"));

        final IgniteCache<Object, Object> cache2 = ignite.getOrCreateCache(new CacheConfiguration<>()
            .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL)
            .setName("cache2"));

        final CountDownLatch latch1 = new CountDownLatch(1);

        Thread t = new Thread(new Runnable() {
            @Override public void run() {
                Lock lock = cache2.lock("fake");

                try {
                    lock.lock();

                    System.out.println("Locked");

                    latch1.countDown();

                    Thread.sleep(1000);

                    cache1.clear();
                }
                catch (Exception e) {
                    e.printStackTrace();

                    throw new RuntimeException(e);
                }
                finally {
                    lock.unlock();
                }
            }
        });

        t.start();

        try {
            latch1.await();
        }
        catch (InterruptedException e) {
            e.printStackTrace();
        }

        ignite.getOrCreateCache(new CacheConfiguration<>()
            .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL)
            .setName("cache3"));

        System.out.println("No deadlock");
    }
{noformat}

> Exception should be thrown on cache creation attempt inside transaction
> -----------------------------------------------------------------------
>
>                 Key: IGNITE-6380
>                 URL: https://issues.apache.org/jira/browse/IGNITE-6380
>             Project: Ignite
>          Issue Type: Improvement
>            Reporter: Yakov Zhdanov
>            Assignee: Pavel Pereslegin
>              Labels: newbie, usability
>
> Exception should be thrown on cache creation attempt inside transaction to prevent deadlocks since cache start triggers exchange and exchange cannot finish until all txs are finished.
> We need to check if thread owns a tx before starting cache and if it does then IllegalStateException should be thrown.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)