Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 79118 invoked from network); 14 Feb 2011 23:42:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 Feb 2011 23:42:28 -0000 Received: (qmail 57512 invoked by uid 500); 14 Feb 2011 23:42:28 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 57471 invoked by uid 500); 14 Feb 2011 23:42:27 -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 57464 invoked by uid 99); 14 Feb 2011 23:42:26 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Feb 2011 23:42:26 +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; Mon, 14 Feb 2011 23:42:25 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 7B52723888EC; Mon, 14 Feb 2011 23:42:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1070697 - in /db/derby/code/branches/10.5/java/engine/org/apache/derby: iapi/sql/conn/LanguageConnectionContext.java iapi/sql/dictionary/TableDescriptor.java impl/sql/conn/GenericLanguageConnectionContext.java Date: Mon, 14 Feb 2011 23:42:05 -0000 To: derby-commits@db.apache.org From: kmarsden@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110214234205.7B52723888EC@eris.apache.org> Author: kmarsden Date: Mon Feb 14 23:42:04 2011 New Revision: 1070697 URL: http://svn.apache.org/viewvc?rev=1070697&view=rev Log: DERBY-4895 Thread local TableDescriptor#referencedColumnMap is not removed from app threads when Derby is shut down Manual merge of revision 1068529 from 10.6 Contributed by Dag H. Wanvik Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/conn/LanguageConnectionContext.java db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/conn/LanguageConnectionContext.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/conn/LanguageConnectionContext.java?rev=1070697&r1=1070696&r2=1070697&view=diff ============================================================================== --- db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/conn/LanguageConnectionContext.java (original) +++ db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/conn/LanguageConnectionContext.java Mon Feb 14 23:42:04 2011 @@ -22,6 +22,7 @@ package org.apache.derby.iapi.sql.conn; import org.apache.derby.iapi.services.context.Context; +import org.apache.derby.iapi.services.io.FormatableBitSet; import org.apache.derby.iapi.db.Database; import org.apache.derby.iapi.error.StandardException; import org.apache.derby.iapi.sql.compile.CompilerContext; @@ -1200,4 +1201,20 @@ public interface LanguageConnectionConte */ public Object getLastQueryTree(); + + /** + * Get the referenced column map for a table + * + * @return the map + */ + public FormatableBitSet getReferencedColumnMap(TableDescriptor td); + + /** + * Set the referenced column map for a table + * + * @param td the table descriptor + * @param map the map + */ + public void setReferencedColumnMap(TableDescriptor td, + FormatableBitSet map); } Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java?rev=1070697&r1=1070696&r2=1070697&view=diff ============================================================================== --- db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java (original) +++ db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java Mon Feb 14 23:42:04 2011 @@ -24,7 +24,7 @@ package org.apache.derby.iapi.sql.dictio import java.util.Enumeration; import java.util.Iterator; import java.util.List; -import java.util.WeakHashMap; +import java.util.Map; import org.apache.derby.catalog.Dependable; import org.apache.derby.catalog.DependableFinder; @@ -33,10 +33,12 @@ import org.apache.derby.iapi.error.Stand import org.apache.derby.iapi.services.io.FormatableBitSet; import org.apache.derby.iapi.services.io.StoredFormatIds; import org.apache.derby.iapi.services.sanity.SanityManager; +import org.apache.derby.iapi.services.context.ContextService; import org.apache.derby.iapi.sql.StatementType; import org.apache.derby.iapi.sql.depend.Provider; import org.apache.derby.iapi.sql.execute.ExecRow; import org.apache.derby.iapi.types.DataValueDescriptor; +import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; /** * This class represents a table descriptor. The external interface to this @@ -108,43 +110,44 @@ public class TableDescriptor extends Tup UUID oid; int tableType; long heapConglomNumber = -1; - ColumnDescriptorList columnDescriptorList; + ColumnDescriptorList columnDescriptorList; ConglomerateDescriptorList conglomerateDescriptorList; ConstraintDescriptorList constraintDescriptorList; private GenericDescriptorList triggerDescriptorList; ViewDescriptor viewDescriptor; - /** - * referencedColumnMap is thread local (since DERBY-2861) - * - * It contains a weak hash map keyed by the the TableDescriptor - * and the value is the actual referencedColumnMap bitmap. So, - * each thread has a weak hash map it uses to find the appropriate - * referencedColumnMap for 'this' TableDescriptor. - * - * Since the hash map is weak, when the TableDescriptor is no - * longer referenced the hash entry can be garbage collected (it - * is the *key* of a weak hash map that is weak, not the value). - */ - private static ThreadLocal referencedColumnMap = new ThreadLocal() { - protected Object initialValue() { - // Key: TableDescriptor - // Value: FormatableBitSet - return new WeakHashMap(); - } - }; - private FormatableBitSet referencedColumnMapGet() { - WeakHashMap map = (WeakHashMap)(referencedColumnMap.get()); - return (FormatableBitSet) (map.get(this)); + LanguageConnectionContext lcc = + (LanguageConnectionContext)ContextService.getContextOrNull( + LanguageConnectionContext.CONTEXT_ID); + + if (SanityManager.DEBUG) { + SanityManager.ASSERT(lcc != null); + } + + return lcc.getReferencedColumnMap(this); + } private void referencedColumnMapPut (FormatableBitSet newReferencedColumnMap) { - WeakHashMap map = (WeakHashMap)(referencedColumnMap.get()); - map.put(this, newReferencedColumnMap); + LanguageConnectionContext lcc = + (LanguageConnectionContext)ContextService.getContextOrNull( + LanguageConnectionContext.CONTEXT_ID); + + if (SanityManager.DEBUG) { + SanityManager.ASSERT(lcc != null || newReferencedColumnMap == null); + } + + // This method is called with a null argument at database + // creation time when there is no lcc, cf stack trace in the + // JIRA for DERBY-4895, we can safely ignore that, as there + // exists no referencedColumnMap yet. + if (lcc != null) { + lcc.setReferencedColumnMap(this, newReferencedColumnMap); + } } /** A list of statistics pertaining to this table-- Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java?rev=1070697&r1=1070696&r2=1070697&view=diff ============================================================================== --- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java (original) +++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java Mon Feb 14 23:42:04 2011 @@ -37,6 +37,7 @@ import org.apache.derby.iapi.services.sa import org.apache.derby.iapi.services.stream.HeaderPrintWriter; import org.apache.derby.iapi.services.loader.GeneratedClass; import org.apache.derby.iapi.services.cache.Cacheable; +import org.apache.derby.iapi.services.io.FormatableBitSet; import org.apache.derby.iapi.db.Database; import org.apache.derby.iapi.error.StandardException; import org.apache.derby.iapi.sql.compile.CompilerContext; @@ -82,6 +83,7 @@ import org.apache.derby.iapi.reference.P import java.util.List; import java.util.ArrayList; import java.util.HashMap; +import java.util.WeakHashMap; import java.util.Iterator; import java.util.Map; @@ -137,7 +139,9 @@ public class GenericLanguageConnectionCo private String dbname; private Object lastQueryTree; // for debugging - + + private WeakHashMap referencedColumnMap; + /** The transaction to use within this language connection context. It may be more appropriate to have it in a separate context (LanguageTransactionContext?). @@ -346,6 +350,7 @@ public class GenericLanguageConnectionCo setDefaultSchema(initDefaultSchemaDescriptor()); + referencedColumnMap = new WeakHashMap(); } /** @@ -719,6 +724,7 @@ public class GenericLanguageConnectionCo // Reset the current role getCurrentSQLSessionContext().setRole(null); + referencedColumnMap = new WeakHashMap(); } // debug methods @@ -3550,4 +3556,13 @@ public class GenericLanguageConnectionCo getInitialDefaultSchemaDescriptor()); } + + public FormatableBitSet getReferencedColumnMap(TableDescriptor td) { + return (FormatableBitSet)referencedColumnMap.get(td); + } + + public void setReferencedColumnMap(TableDescriptor td, + FormatableBitSet map) { + referencedColumnMap.put(td, map); + } }