Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CB88771FF for ; Thu, 22 Sep 2011 18:02:19 +0000 (UTC) Received: (qmail 61770 invoked by uid 500); 22 Sep 2011 18:02:19 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 61711 invoked by uid 500); 22 Sep 2011 18:02:19 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 61702 invoked by uid 99); 22 Sep 2011 18:02:19 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Sep 2011 18:02:19 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Sep 2011 18:02:16 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 012E923889E3; Thu, 22 Sep 2011 18:01:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1174290 - in /db/derby/code/trunk/java/engine/org/apache/derby: impl/sql/catalog/SequenceUpdater.java loc/messages.xml Date: Thu, 22 Sep 2011 18:01:54 -0000 To: derby-commits@db.apache.org From: rhillegas@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20110922180155.012E923889E3@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: rhillegas Date: Thu Sep 22 18:01:54 2011 New Revision: 1174290 URL: http://svn.apache.org/viewvc?rev=1174290&view=rev Log: DERBY-5426: Improve error message for too much contention on a sequence/identity. Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java?rev=1174290&r1=1174289&r2=1174290&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java Thu Sep 22 18:01:54 2011 @@ -155,7 +155,7 @@ public abstract class SequenceUpdater im /////////////////////////////////////////////////////////////////////////////////// // - // ABSTRACT BEHAVIOR TO BE IMPLEMENTED BY CHILDREN + // ABSTRACT OR OVERRIDABLE BEHAVIOR TO BE IMPLEMENTED BY CHILDREN // /////////////////////////////////////////////////////////////////////////////////// @@ -187,6 +187,19 @@ public abstract class SequenceUpdater im */ abstract protected boolean updateCurrentValueOnDisk( TransactionController tc, Long oldValue, Long newValue, boolean wait ) throws StandardException; + /** + *

+ * Create an exception to state that there is too much contention on the generator. + * For backward compatibility reasons, different messages are needed by sequences + * and identities. See DERBY-5426. + *

+ */ + protected StandardException tooMuchContentionException() + { + return StandardException.newException + ( SQLState.LANG_TOO_MUCH_CONTENTION_ON_SEQUENCE, _sequenceGenerator.getName() ); + } + /////////////////////////////////////////////////////////////////////////////////// // // Cacheable BEHAVIOR @@ -322,10 +335,10 @@ public abstract class SequenceUpdater im ( NumberDataValue returnValue ) throws StandardException { Long startTime = null; - + // - // We try to get a sequence number. We try a couple times in case we find - // ourselves in a race with another session which is draining numbers from + // We try to get a sequence number. We try until we've exceeded the lock timeout + // in case we find ourselves in a race with another session which is draining numbers from // the same sequence generator. // while ( true ) @@ -377,18 +390,16 @@ public abstract class SequenceUpdater im ( (System.currentTimeMillis() - startTime.longValue()) > _lockTimeoutInMillis ) ) { - break; + // + // If we get here, then we exhausted our retry attempts. This might be a sign + // that we need to increase the number of sequence numbers which we + // allocate. There's an opportunity for Derby to tune itself here. + // + throw tooMuchContentionException(); } } // end of retry loop - // - // If we get here, then we exhausted our retry attempts. This might be a sign - // that we need to increase the number of sequence numbers which we - // allocate. There's an opportunity for Derby to tune itself here. - // - throw StandardException.newException - ( SQLState.LANG_TOO_MUCH_CONTENTION_ON_SEQUENCE, _sequenceGenerator.getName() ); } /** @@ -595,6 +606,17 @@ public abstract class SequenceUpdater im { return _dd.updateCurrentIdentityValue( tc, _sequenceRowLocation, wait, oldValue, newValue ); } + + /** + * Wrap the "too much contention" exception in a "lock timeout" exception in + * order to preserve the old error behavior of identity columns. See DERBY-5426. + */ + protected StandardException tooMuchContentionException() + { + StandardException tooMuchContention = super.tooMuchContentionException(); + + return StandardException.newException( SQLState.LOCK_TIMEOUT, tooMuchContention ); + } } /** Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml?rev=1174290&r1=1174289&r2=1174290&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml Thu Sep 22 18:01:54 2011 @@ -3441,7 +3441,7 @@ Guide. X0Y84.S - Too much contention on sequence {0}. + Too much contention on sequence {0}. To avoid this error, try adjusting derby.locks.waitTimeout and/or derby.language.sequence.preallocator. See the Derby Reference Manual for more information on these properties. sequenceName