Return-Path: Delivered-To: apmail-db-derby-dev-archive@www.apache.org Received: (qmail 6232 invoked from network); 10 Jun 2009 17:31:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 10 Jun 2009 17:31:20 -0000 Received: (qmail 4904 invoked by uid 500); 10 Jun 2009 17:16:34 -0000 Delivered-To: apmail-db-derby-dev-archive@db.apache.org Received: (qmail 4886 invoked by uid 500); 10 Jun 2009 17:16:34 -0000 Mailing-List: contact derby-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: Delivered-To: mailing list derby-dev@db.apache.org Received: (qmail 4878 invoked by uid 99); 10 Jun 2009 17:16:34 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Jun 2009 17:16:34 +0000 X-ASF-Spam-Status: No, hits=-4.0 required=10.0 tests=RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [192.18.6.21] (HELO gmp-eb-inf-1.sun.com) (192.18.6.21) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Jun 2009 17:16:22 +0000 Received: from fe-emea-09.sun.com (gmp-eb-lb-1-fe3.eu.sun.com [192.18.6.10]) by gmp-eb-inf-1.sun.com (8.13.7+Sun/8.12.9) with ESMTP id n5AHFo1N000633 for ; Wed, 10 Jun 2009 17:16:02 GMT MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; CHARSET=US-ASCII; format=flowed Received: from conversion-daemon.fe-emea-09.sun.com by fe-emea-09.sun.com (Sun Java(tm) System Messaging Server 7u2-7.02 64bit (built Apr 16 2009)) id <0KL10090096XPV00@fe-emea-09.sun.com> for derby-dev@db.apache.org; Wed, 10 Jun 2009 18:15:49 +0100 (BST) Received: from [192.168.10.236] ([unknown] [84.208.133.36]) by fe-emea-09.sun.com (Sun Java(tm) System Messaging Server 7u2-7.02 64bit (built Apr 16 2009)) with ESMTPSA id <0KL100DN19AAQH70@fe-emea-09.sun.com> for derby-dev@db.apache.org; Wed, 10 Jun 2009 18:15:49 +0100 (BST) Date: Wed, 10 Jun 2009 19:15:38 +0200 From: Kristian Waagan Subject: Re: [jira] Updated: (DERBY-3961) Deadlock detection fails for InternalTransaction In-reply-to: <211603562.1244651407483.JavaMail.jira@brutus> Sender: Kristian.Waagan@Sun.COM To: derby-dev@db.apache.org Message-id: <4A2FEA3A.2070209@Sun.COM> Organization: Sun Microsystems Inc. References: <211603562.1244651407483.JavaMail.jira@brutus> User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) X-Virus-Checked: Checked by ClamAV on apache.org Mike Matrigali (JIRA) wrote: > [ https://issues.apache.org/jira/browse/DERBY-3961?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] > > Mike Matrigali updated DERBY-3961: > ---------------------------------- > > > I can't be sure without a test case - just made an informed guess, > but the description and the lock table looked like a duplicat to me. > Obviously the best case would be for the original reporter to either submit his test case or to run his test > case against 10.5. If it still breaks, please do reopen this issue. > > o DERBY-2991 will result in a lock timeout vs. a deadlock, in the btree split case. This is because the lock > manager does not recognize that the internal transaction for the split and the parent transaction are the > same thread and thus should be treated as the same waiter for purpose of deadlock detection. So what > happens is that no deadlock is detected where there is one, so the threads hang around until they reach > lock timeout. > > o All row locks of the form (N, 1) will no longer be requested in 10.5 after the fix for DERBY-2991, so if one sees > a missed deadlock in versions previous to 10.5 where these are part of the deadlock cycle they should be > fixed by DERBY-2991. > Thank you for the extra information, Mike. -- Kristian > >> Deadlock detection fails for InternalTransaction >> ------------------------------------------------ >> >> Key: DERBY-3961 >> URL: https://issues.apache.org/jira/browse/DERBY-3961 >> Project: Derby >> Issue Type: Bug >> Affects Versions: 10.4.2.0 >> Environment: Windows Vista >> Reporter: Jeff Stuckman >> Fix For: 10.5.1.2 >> >> >> It is easy to cause a deadlock which is not detected by the deadlock detection algorithm. The transactions fail due to a lock timeout , possibly because a transaction of type InternalTransaction is part of the cycle. >> Resolving issue DERBY-2991 will make it more difficult to cause such deadlocks, but it will still be possible. >> My test case creates two threads and executes the following statements until they deadlock against each other: >> UPDATE urls SET jobflag=? WHERE urlid=? >> SELECT urlid,url,expectation FROM urls WHERE site=? >> The test eventually deadlocks with the following transaction and lock table contents: >> XID TYPE MODE TABLENAME LOCKNAME STATE TABLETYPE LOCKCOUNT INDEXNAME >> 2217109 ROW S URLS (13,1) GRANT T 1 FINDURLBYSITEANDJOB >> 2217114 ROW X URLS (13,1) WAIT T 0 FINDURLBYSITEANDJOB >> 2217113 ROW S URLS (15,1) GRANT T 1 FINDURLBYSITEANDJOB >> 2217113 ROW X URLS (3,132) GRANT T 3 null >> 2217109 ROW S URLS (3,132) WAIT T 0 null >> 2217109 TABLE IS URLS Tablelock GRANT T 2 null >> 2217113 TABLE IX URLS Tablelock GRANT T 4 null >> 2217114 TABLE IX URLS Tablelock GRANT T 1 null >> 2217113 ROW S URLS (6,1) GRANT T 1 SQL081111021116970 >> XID GLOBAL_XID USERNAME TYPE STATUS FIRST_INSTANT SQL_TEXT >> 2217115 null APP UserTransaction IDLE null select * from SYSCS_DIAG.TRANSACTION_TABLE >> 2217114 null APP InternalTransaction ACTIVE null UPDATE urls SET jobflag=? WHERE urlid=? >> 2217113 null APP UserTransaction ACTIVE (526,52925) UPDATE urls SET jobflag=? WHERE urlid=? >> 2069160 null null SystemTransaction IDLE null null >> 2217109 null APP UserTransaction ACTIVE null SELECT urlid,url,expectation FROM urls WHERE site=? >> Here is what I think is happening: >> 1. The SELECT statement begins to execute and the cursor is stepping through the result set. The results are derived from index FINDURLBYSITEANDJOB as expected. >> 2. The UPDATE statement begins to execute. The row to be updated is the row immediately after the SELECT statement's cursor. The row is locked and updated. >> 3. The UPDATE statement must perform index maintenance (tree rebalancing or similar?). This apparently causes an InternalTransaction to be created. It then must lock the row that the SELECT statement's cursor is currently occupying. It cannot do this, so the transaction waits. >> 4. The SELECT statement is ready to advance the cursor. However, it cannot advance the cursor because the UPDATE statement has locked the next row. The transaction waits. >> The result: Transaction 2217113 waits for the "nested transaction" 2217114 to complete. 2217114 waits for 2217109 to release its lock. 2217109 waits for 2217113 to release its lock. We have a cycle and a deadlock. The transactions time out with "A lock could not be obtained within the time requested", apparently because the dependency between transactions 2217113 and 2217114 is not detected. >> > >