Return-Path: X-Original-To: apmail-db-derby-user-archive@www.apache.org Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E8AF410676 for ; Fri, 7 Feb 2014 19:49:03 +0000 (UTC) Received: (qmail 31534 invoked by uid 500); 7 Feb 2014 19:49:02 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 31501 invoked by uid 500); 7 Feb 2014 19:49:02 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 31491 invoked by uid 99); 7 Feb 2014 19:49:02 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Feb 2014 19:49:02 +0000 X-ASF-Spam-Status: No, hits=-0.5 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of mikemapp1@gmail.com designates 209.85.219.50 as permitted sender) Received: from [209.85.219.50] (HELO mail-oa0-f50.google.com) (209.85.219.50) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Feb 2014 19:48:57 +0000 Received: by mail-oa0-f50.google.com with SMTP id n16so4740113oag.37 for ; Fri, 07 Feb 2014 11:48:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=IOha3uZduvkMxyTFKPMJLDJeD3/21Hz4kt+c3DFc1aQ=; b=wXbHNhkwjJRec6La7qhs5T8AJ8lmLcorQocCrwYq1uO2uwn35zWj/63PF2QIf4lkKz ROVdN51Ulb3jRS/z/2FVFbg4XOEMiyvisQUmV+VG5YuVJD3oY3RJgrXw+JiwVZf0AkXY 88EscoG9ZoSNrEtRpISP/OWIUpz+gHnctl1GX3LerFxTaZfiJxcMwTTAwg4pemegLhUA 5GQOKhTMIXOo6NNB0tGEkq4/QgXdTL5LDNqplV1ZjHJivq7a0oabqnke7n92OoyQMVA2 O5k/l1uHPu5Wj6aAAXiVeQasun8rFvlzeY2r9EdEYpp91Te9mMsox++mnf58YRdpeR5p ylbQ== X-Received: by 10.60.174.77 with SMTP id bq13mr1201804oec.0.1391802517019; Fri, 07 Feb 2014 11:48:37 -0800 (PST) Received: from [9.72.133.151] ([32.97.110.55]) by mx.google.com with ESMTPSA id tr10sm12817673obb.6.2014.02.07.11.48.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 07 Feb 2014 11:48:36 -0800 (PST) Message-ID: <52F53892.80907@gmail.com> Date: Fri, 07 Feb 2014 11:48:34 -0800 From: mike matrigali User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: Derby Discussion Subject: Re: Unexpected behavior for concurrent selection of an uncommitted record inserted in a different thread References: <82AAE9C8-94AD-408F-A8A1-CCAE368CBFE5@gmail.com> <97EB699F861AD841B5908C7CA9C9565602BB081CF52E@VSERVER1.canoga.com> In-Reply-To: <97EB699F861AD841B5908C7CA9C9565602BB081CF52E@VSERVER1.canoga.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Brett is right, please ignore my other posting. I missed that same key was being looked at. Derby uses locking to implement sql concurrency which leads to this behavior. Other products (or instances of products depending on what storage engine mysql is using), may use versioning instead which may result in different behavior. I believe the Derby behavior is within the SQL standard, but is less concurrent than a versioning scheme. /mikem On 2/7/2014 11:20 AM, Bergquist, Brett wrote: > I think this is the behavior as described in this document: > > http://docs.oracle.com/javadb/10.5.3.0/devguide/rdevconcepts8424.html > > See the table entry on read-committed and it looks like the insert statement has an exclusive lock on inserted record and as such the select by T2 for that specific record will block on the exclusive lock. > > -----Original Message----- > From: Jacopo Cappellato [mailto:jacopo.cappellato@gmail.com] > Sent: Friday, February 07, 2014 12:59 PM > To: derby-user@db.apache.org > Subject: Unexpected behavior for concurrent selection of an uncommitted record inserted in a different thread > > Hi all! > > While I was writing some unit tests for the Apache OFBiz project (that by default runs on Derby) I noticed a behavior of Derby that I didn't expect and I would love to get your opinion. > Here is my use case: > > * Derby 10.10.1.1 > * there are two concurrent transactions T1 and T2 > * isolation level is "Read Committed" > * in transaction T1 a record with primary key 123 is inserted in a table; then other long running tasks are executed (i.e. the transaction is not immediately committed) > * in the meantime T2 attempts to select from the same table the record with primary key 123 > > Behavior: T2 blocks on the select statement waiting for transaction T1 to release the write lock; this can cause a lock wait timeout Expected behavior: since T1 is not committed, T2 should not be able to select the record; I was expecting that the select statement in T2 would return an empty result set rather than blocking waiting for the lock held by T1 to be released; in fact this is what we get with MySQL and Postgres. > > What do you think? > > Thanks, > > Jacopo Cappellato >