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

rajeev gandhi edited comment on IGNITE-6380 at 10/25/17 7:13 PM:
-----------------------------------------------------------------

One more deadlock scenario:
private void start2() {
        Ignite ignite = null;           
        try{            
                ignite = Ignition.start("ignite-deadlock.xml");         
                IgniteCache<Object, Object> cache1 = 
ignite.getOrCreateCache(getConfig("cache1"));              
                IgniteCache<Object, Object> cache2 = 
ignite.getOrCreateCache(getConfig("cache2"));
//              ignite.l
                
                CountDownLatch latch1 = new CountDownLatch(1);
                CountDownLatch latch2 = new CountDownLatch(1);
                
                Thread t = new Thread(() -> {
                        Lock lock = cache2.lock("fake");                        
                        try{
                                lock.lock();
                                System.out.println("Locked");  
                                latch1.countDown();
                                latch2.await();
                                cache1.clear();                         
                        }catch(InterruptedException e){
                                Thread.currentThread().interrupt();
                                e.printStackTrace();
                                throw new RuntimeException(e);                  
        
                        }catch(Exception e){                            
                                e.printStackTrace();
                                throw new RuntimeException(e);                  
        
                        }finally{
                                lock.unlock();
                        }               
                });
                t.start();  
                latch1.await();
                
                ignite.reentrantLock("blah", true, true, true);
                latch2.countDown();
                try{
                        System.out.println("No deadlock");
                }finally{
                
                }               
                t.join();
                
        }catch(InterruptedException e){
                        Thread.currentThread().interrupt();
                        e.printStackTrace();
                        throw new RuntimeException(e);                          
                }finally{
                        if(ignite!=null) ignite.close();
                }
                
        }


was (Author: rajivgandhi):
One more deadlock scenario:
private void start2() {
        Ignite ignite = null;           
        try{            
                ignite = Ignition.start("ignite-deadlock.xml");         
                IgniteCache<Object, Object> cache1 = 
ignite.getOrCreateCache(getConfig("cache1"));              
                IgniteCache<Object, Object> cache2 = 
ignite.getOrCreateCache(getConfig("cache2"));
//              ignite.l
                
                CountDownLatch latch1 = new CountDownLatch(1);
                CountDownLatch latch2 = new CountDownLatch(1);
                
                Thread t = new Thread(() -> {
                        Lock lock = cache2.lock("fake");                        
                        try{
                                lock.lock();
                                System.out.println("Locked");  
                                latch1.countDown();
                                latch2.await();
                                cache1.clear();                         
                        }catch(InterruptedException e){
                                Thread.currentThread().interrupt();
                                e.printStackTrace();
                                throw new RuntimeException(e);                  
        
                        }catch(Exception e){                            
                                e.printStackTrace();
                                throw new RuntimeException(e);                  
        
                        }finally{
                                lock.unlock();
                        }               
                });
                t.start();  
                latch1.await();
                Lock lock = cache2.lock("fake2");
//              lock.lock();
                latch2.countDown();
                try{
                        System.out.println("No deadlock");
                }finally{
                        lock.unlock();
                }               
                t.join();
                
        }catch(InterruptedException e){
                        Thread.currentThread().interrupt();
                        e.printStackTrace();
                        throw new RuntimeException(e);                          
                }finally{
                        if(ignite!=null) ignite.close();
                }
                
        }

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

Reply via email to