db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r1068529 - in /db/derby/code/branches/10.6: ./ java/engine/org/apache/derby/iapi/sql/conn/ java/engine/org/apache/derby/iapi/sql/dictionary/ java/engine/org/apache/derby/impl/sql/conn/
Date Tue, 08 Feb 2011 19:10:41 GMT
Author: kmarsden
Date: Tue Feb  8 19:10:41 2011
New Revision: 1068529

URL: http://svn.apache.org/viewvc?rev=1068529&view=rev
Log:
DERBY-4895 Thread local TableDescriptor#referencedColumnMap is not removed from
app threads when Derby is shut down

port from trunk revision 1033485 with some manual merge.
Fix Contributed by Dag H. Wanvik


Modified:
    db/derby/code/branches/10.6/   (props changed)
    db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/sql/conn/LanguageConnectionContext.java
    db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java
    db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java

Propchange: db/derby/code/branches/10.6/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Feb  8 19:10:41 2011
@@ -1,2 +1,2 @@
-/db/derby/code/trunk:938547,938796,938959,939231,940462,940469,941627,942031,942286,942476,942480,942587,944152,946794,948045,948069,951346,951366,952138,952237,952581,954344,954421,954544,954748,955001,955540,955634,956075,956234,956445,956569,956659,957260,957902,958163,958257,958264,958508,958522,958555,958618,958939,959550,961892,962716,963206,963705,964115,964402,965647,967304,980684,986689,986834,987539,989099,990292,997325,998170,999119,1002291,1002682,1002853,1021426,1025795,1028716,1030043,1033864,1038514,1040658,1053724,1055169,1062096,1063809,1065061,1067250
+/db/derby/code/trunk:938547,938796,938959,939231,940462,940469,941627,942031,942286,942476,942480,942587,944152,946794,948045,948069,951346,951366,952138,952237,952581,954344,954421,954544,954748,955001,955540,955634,956075,956234,956445,956569,956659,957260,957902,958163,958257,958264,958508,958522,958555,958618,958939,959550,961892,962716,963206,963705,964115,964402,965647,967304,980684,986689,986834,987539,989099,990292,997325,998170,999119,1002291,1002682,1002853,1021426,1025795,1028716,1030043,1033485,1033864,1038514,1040658,1053724,1055169,1062096,1063809,1065061,1067250
 /db/derby/docs/trunk:954344

Modified: db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/sql/conn/LanguageConnectionContext.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/sql/conn/LanguageConnectionContext.java?rev=1068529&r1=1068528&r2=1068529&view=diff
==============================================================================
--- db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/sql/conn/LanguageConnectionContext.java
(original)
+++ db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/sql/conn/LanguageConnectionContext.java
Tue Feb  8 19:10:41 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;
@@ -1258,4 +1259,20 @@ public interface LanguageConnectionConte
      */
     public ASTVisitor getASTVisitor( );
     
+
+    /**
+     * 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.6/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java?rev=1068529&r1=1068528&r2=1068529&view=diff
==============================================================================
--- db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java
(original)
+++ db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/sql/dictionary/TableDescriptor.java
Tue Feb  8 19:10:41 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;
@@ -34,6 +34,7 @@ import org.apache.derby.iapi.reference.S
 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.conn.LanguageConnectionContext;
 import org.apache.derby.iapi.sql.depend.DependencyManager;
@@ -113,43 +114,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.6/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java?rev=1068529&r1=1068528&r2=1068529&view=diff
==============================================================================
--- db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
(original)
+++ db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
Tue Feb  8 19:10:41 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;
@@ -85,6 +86,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.AbstractMap;
 import java.util.IdentityHashMap;
+import java.util.WeakHashMap;
 import java.util.Iterator;
 import java.util.Map;
 
@@ -293,7 +295,14 @@ public class GenericLanguageConnectionCo
 
     // User-written inspector to print out query tree
     private ASTVisitor astWalker;
-    
+
+    /**
+     * Connection local state for cached {@code TableDescriptor}s used
+     * for keeping track of referenced columns for a table during DDL
+     * operations.
+     */
+    private WeakHashMap referencedColumnMap;
+
 	/*
 	   constructor
 	*/
@@ -372,6 +381,7 @@ public class GenericLanguageConnectionCo
 
 
 		setDefaultSchema(initDefaultSchemaDescriptor());
+		referencedColumnMap = new WeakHashMap();
 	}
 
 	/**
@@ -745,6 +755,7 @@ public class GenericLanguageConnectionCo
 
 		// Reset the current role
 		getCurrentSQLSessionContext().setRole(null);
+		referencedColumnMap = new WeakHashMap();
 	}
 
     // debug methods
@@ -3648,4 +3659,13 @@ public class GenericLanguageConnectionCo
         return astWalker;
     }
 
+
+    public FormatableBitSet getReferencedColumnMap(TableDescriptor td) {
+        return (FormatableBitSet)referencedColumnMap.get(td);
+    }
+
+    public void setReferencedColumnMap(TableDescriptor td,
+                                       FormatableBitSet map) {
+        referencedColumnMap.put(td, map);
+    }
 }



Mime
View raw message