db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r901165 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/StreamFileContainer.java
Date Wed, 20 Jan 2010 12:34:26 GMT
Author: kristwaa
Date: Wed Jan 20 12:34:26 2010
New Revision: 901165

URL: http://svn.apache.org/viewvc?rev=901165&view=rev
Log:
DERBY-4519: Infinite loop in StreamFileContainer.writeColumn
Fixed two issues;
 - swapped offset and length arguments (removed them for the read-case)
 - bounded the transfer buffer size, becuause InputStream.available() can
   return both zero and a very high value. Size bounded by [64, 8192].

Patch file: derby-4519-2a-infinite_loop_fixes.diff


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/StreamFileContainer.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/StreamFileContainer.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/StreamFileContainer.java?rev=901165&r1=901164&r2=901165&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/StreamFileContainer.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/StreamFileContainer.java
Wed Jan 20 12:34:26 2010
@@ -731,16 +731,24 @@
 		if (column instanceof InputStream) 
         {
 			InputStream inColumn = (InputStream) column;
-			int bufferLen = inColumn.available();
+            // Set a reasonable buffer size.
+            // To avoid extremely inefficient reads, and an infinite loop when
+            // InputStream.available() returns zero, a lower limit is set on
+            // the buffer size. To avoid using too much memory (especially in
+            // multi-user environments) an upper limit is set as well.
+            // The limits can be tuned, but note that using a too high default
+            // or lower limit can put unnecessary pressure on the memory sub-
+            // system and the GC process.
+            int bufferLen = Math.min(Math.max(inColumn.available(), 64), 8192);
 			byte[] bufData = new byte[bufferLen];
 
 			do 
             {
-				int lenRead = inColumn.read(bufData, bufferLen, 0);
+                int lenRead = inColumn.read(bufData);
 				if (lenRead != -1) 
                 {
 					fieldDataLength += lenRead;
-					out.write(bufData, lenRead, 0);
+                    out.write(bufData, 0, lenRead);
 				} 
                 else
                 {



Mime
View raw message