You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by oy...@apache.org on 2008/04/04 18:19:28 UTC

svn commit: r644755 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java

Author: oysteing
Date: Fri Apr  4 09:19:19 2008
New Revision: 644755

URL: http://svn.apache.org/viewvc?rev=644755&view=rev
Log:
DERBY-3354:  Select from large lob table with embedded gives OutOfMemoryError
Contributed by Anurag.

This patch introduces a new WeakHashMap in EmbedConnection. EmbedBlob and EmbedClob objects references are stored in this
map (objects as key and null as value). Adding entry to locater map is
differed till the first call of getLocater.
This ensures that there is entry of LOB objects in locater map if they are invoked in embedded mode.
As the keys of WeakHashMap doesn't prevents the objects from being
garbage collected, once the lob objects are unreferenced lob objects will
be garbage collected releasing the memory.

During commit/rollback or Connection.close, free is invoked on all the lob
objects from WeakHashMap and the map is cleared.

Modified files
java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
Added a new attribute lobRefrences of type WeakHashMap.
Added a new method addLOBReference to make an entry in new
 hash map.
Modified clearLOBMapping to use lobRefrences to fetch and invoke free on lob objects instead of lobHashMap.

java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java
java/engine/org/apache/derby/impl/jdbc/EmbedClob.java

Modified constructs to call connection.lobRefrences instead of conn.addLOBMapping.
Modified getLocater method to check if the locater value is non zero
before returning and if its zero calling conn.addLOBMapping to make
entry of lob objects and getting locater value.
Calling removeLOBMapping in free method.


Cleanup of temporary file is already being taken care by the finalizer of
LOBStreamControl so I haven't added any new cleanup code for
finalizer.


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java?rev=644755&r1=644754&r2=644755&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java Fri Apr  4 09:19:19 2008
@@ -75,7 +75,7 @@
     private InputStream     myStream;
     
     // locator key for lob. used by Network Server.
-    private final int             locator;
+    private int             locator;
     
     /*
      * Length of the BLOB if known. Set to -1 if
@@ -117,7 +117,7 @@
              materialized = true;
              //add entry in connection so it can be cleared 
              //when transaction is not valid
-             locator = con.addLOBMapping (this);
+             con.addLOBReference (this);
          }
          catch (IOException e) {
              throw Util.setStreamFailure (e);
@@ -193,7 +193,7 @@
         pos = 0;
         //add entry in connection so it can be cleared 
         //when transaction is not valid
-        this.locator = con.addLOBMapping (this);
+        con.addLOBReference (this);
     }
 
 
@@ -906,6 +906,8 @@
         //valid
         isValid = false;
         
+        //remove entry from connection
+        localConn.removeLOBMapping(locator);
         //initialialize length to default value -1
         myLength = -1;
         
@@ -1000,6 +1002,9 @@
      * @return The locator identifying this lob.
      */
     public int getLocator() {
+        if (locator == 0) {
+            locator = localConn.addLOBMapping(this);
+        }
         return locator;
     }
 }