Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 8DA02200D2E for ; Tue, 31 Oct 2017 16:06:05 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 8C1A4160BF9; Tue, 31 Oct 2017 15:06:05 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B36A21609EB for ; Tue, 31 Oct 2017 16:06:04 +0100 (CET) Received: (qmail 13976 invoked by uid 500); 31 Oct 2017 15:06:03 -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 13966 invoked by uid 99); 31 Oct 2017 15:06:03 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 31 Oct 2017 15:06:03 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 1938C1A3666 for ; Tue, 31 Oct 2017 15:06:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.202 X-Spam-Level: X-Spam-Status: No, score=-99.202 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id oSotqqTvUaGb for ; Tue, 31 Oct 2017 15:06:01 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 0FA1161119 for ; Tue, 31 Oct 2017 15:06:01 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 7E202E0F4E for ; Tue, 31 Oct 2017 15:06:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 3E458212FA for ; Tue, 31 Oct 2017 15:06:00 +0000 (UTC) Date: Tue, 31 Oct 2017 15:06:00 +0000 (UTC) From: "Brett Bergquist (JIRA)" To: derby-dev@db.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (DERBY-6975) Bug in SequenceUpdater.getCurrentValueAndAdvance - break used instead of continue MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Tue, 31 Oct 2017 15:06:05 -0000 [ https://issues.apache.org/jira/browse/DERBY-6975?page=3Dcom.atlassian= .jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D1622= 6948#comment-16226948 ]=20 Brett Bergquist commented on DERBY-6975: ---------------------------------------- I thought this was the same issue that I was seeing earlier last month but = I see it is slightly different so I removed my comment but I will still rev= iew this code and proposed fix. > Bug in SequenceUpdater.getCurrentValueAndAdvance - break used instead of = continue > -------------------------------------------------------------------------= -------- > > Key: DERBY-6975 > URL: https://issues.apache.org/jira/browse/DERBY-6975 > Project: Derby > Issue Type: Bug > Components: SQL > Affects Versions: 10.14.1.0 > Reporter: David Sitsky > Attachments: fix.patch > > > I have an application that sporadically gets this exception when insertin= g a lot of rows using a sequence generator. > {noformat} > Caused by: ERROR 40XL1: A lock could not be obtained within the time requ= ested=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 at org.apache.derby.iapi.error= .StandardException.newException(StandardException.java)=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 at org.apache.derby.iapi.error= .StandardException.newException(StandardException.java)=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 at org.apache.derby.impl.sql.c= atalog.SequenceUpdater.tooMuchContentionException(SequenceUpdater.java)=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 at org.apache.derby.impl.sql.c= atalog.SequenceUpdater.getCurrentValueAndAdvance(SequenceUpdater.java)=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 at org.apache.derby.impl.sql.c= atalog.DataDictionaryImpl.getCurrentValueAndAdvance(DataDictionaryImpl.java= )=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 at org.apache.derby.impl.sql.e= xecute.BaseActivation.getCurrentValueAndAdvance(BaseActivation.java)=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 at org.apache.derby.impl.sql.e= xecute.InsertResultSet.getSetAutoincrementValue(InsertResultSet.java)=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 at org.apache.derby.impl.sql.e= xecute.BaseActivation.getSetAutoincrementValue(BaseActivation.java)=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 at org.apache.derby.exe.ac5607= 40aax015fx6bc1x68cax000002339e626a.e0(ac560740aax015fx6bc1x68cax000002339e6= 26a.java)=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 at org.apache.derby.impl.servi= ces.reflect.DirectCall.invoke(DirectCall.java)=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 at org.apache.derby.impl.sql.e= xecute.RowResultSet.getNextRowCore(RowResultSet.java)=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 at org.apache.derby.impl.sql.e= xecute.NormalizeResultSet.getNextRowCore(NormalizeResultSet.java)=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 at org.apache.derby.impl.sql.e= xecute.DMLWriteResultSet.getNextRowCore(DMLWriteResultSet.java)=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 at org.apache.derby.impl.sql.e= xecute.InsertResultSet.getNextRowCore(InsertResultSet.java)=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 at org.apache.derby.impl.sql.e= xecute.InsertResultSet.open(InsertResultSet.java)=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 at org.apache.derby.impl.sql.G= enericPreparedStatement.executeStmt(GenericPreparedStatement.java)=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 at org.apache.derby.impl.sql.G= enericPreparedStatement.execute(GenericPreparedStatement.java)=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ... 25 more=20 > {noformat} > When I look at the code in question, it comes down to this method: > {code} > /** > *

> * Get the next sequence number managed by this generator and advance= the number. Could raise an > * exception if the legal range is exhausted and wrap-around is not a= llowed. > * Only one thread at a time is allowed through here. We do not want = a race between the > * two calls to the sequence generator: getCurrentValueAndAdvance() a= nd allocateNewRange(). > *

> * > * @param returnValue This value is stuffed with the new sequence num= ber. > */ > public synchronized void getCurrentValueAndAdvance > ( NumberDataValue returnValue ) throws StandardException > { > // > // We may have to try to get a value from the Sequence Generator = twice. > // The first attempt may fail because we need to pre-allocate a n= ew chunk > // of values. > // > for ( int i =3D 0; i < 2; i++ ) > { > // > // We try to get a sequence number. The SequenceGenerator met= hod is synchronized > // so only one writer should be in there at a time. Lock cont= ention is possible if > // someone has selected from SYSSEQUENCES contrary to our adv= ice. In that case, > // we raise a TOO MUCH CONTENTION exception. > // > long[] cvaa =3D _sequenceGenerator.getCurrentValueAndAdvance(= ); > =20 > int status =3D (int) cvaa[ SequenceGenerator.CVAA_STATUS ]; > long currentValue =3D cvaa[ SequenceGenerator.CVAA_CURRENT_VA= LUE ]; > long lastAllocatedValue =3D cvaa[ SequenceGenerator.CVAA_LAST= _ALLOCATED_VALUE ]; > long numberOfValuesAllocated =3D cvaa[ SequenceGenerator.CVAA= _NUMBER_OF_VALUES_ALLOCATED ]; > =20 > switch ( status ) > { > case SequenceGenerator.RET_OK: > returnValue.setValue( currentValue ); > return; > =20 > case SequenceGenerator.RET_MARK_EXHAUSTED: > updateCurrentValueOnDisk( currentValue, null ); > returnValue.setValue( currentValue ); > return; > =20 > case SequenceGenerator.RET_ALLOCATE_NEW_VALUES: > =20 > if ( updateCurrentValueOnDisk( currentValue, lastAllocate= dValue ) ) > { > _sequenceGenerator.allocateNewRange( currentValue, nu= mberOfValuesAllocated ); > } > break; > =20 > default: > throw unimplementedFeature(); > } > } > // > // If we get here, then we failed to allocate a new sequence numb= er range. > // > throw tooMuchContentionException(); > } > {code} > If I understand the intent of this code, in the SequenceGenerator.RET_ALL= OCATE_NEW_VALUES case, we allocate a new sequence generator range and then = we are meant to re-execute the loop again to use it, however since "break" = is used we break out of the for loop and throw the exception. > It seems if we replace "break" with 'continue" this will work as expected= ? -- This message was sent by Atlassian JIRA (v6.4.14#64029)