You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Diego Rivera (Created) (JIRA)" <ji...@apache.org> on 2012/01/23 21:51:41 UTC

[jira] [Created] (JCS-88) Block cache fails to validate a cache file on startup when it contains elements with more than 2 blocks.

Block cache fails to validate a cache file on startup when it contains elements with more than 2 blocks.
--------------------------------------------------------------------------------------------------------

                 Key: JCS-88
                 URL: https://issues.apache.org/jira/browse/JCS-88
             Project: Commons JCS
          Issue Type: Bug
    Affects Versions: jcs-1.3
            Reporter: Diego Rivera


The arithmetic for calculating block sizes is wrong.  The code adds a term that shouldn't be considered at that point.  For each block that needs to be written, the size of the block is currently calculated as:

int chunkSize = Math.min( totalUsed + maxChunkSize, totalBytes - totalUsed )

The term "totalUsed" should not be added to maxChunkSize, since the intent is to construct a chunk that's either as big as is allowed (maxChunkSize) or as big as the remaining bytes (totalBytes - totalUsed).  Thus, the correct calculation should be:

int chunkSize = Math.min( maxChunkSize, totalBytes - totalUsed )

The problem occurs in src/java/org/apache/jcs/auxiliary/disk/block/BlockDisk.java, line 196, inside byte[][] getBlockChunks(byte[] complete, int numBlocksNeeded).

A patch has been devised and will be submitted as a comment (since attachments aren't possible at this point).  I still need to take the time to devise a unit test for this since the existing unit test passed without issue.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (JCS-88) Block cache fails to validate a cache file on startup when it contains elements with more than 2 blocks.

Posted by "Diego Rivera (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/JCS-88?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13191596#comment-13191596 ] 

Diego Rivera commented on JCS-88:
---------------------------------

diff -ruN /home/diego/Desktop/jcs-1.3/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskUnitTest.java src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskUnitTest.java
--- /home/diego/Desktop/jcs-1.3/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskUnitTest.java     2007-05-30 12:23:53.000000000 -0600
+++ src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskUnitTest.java 2012-01-23 17:06:10.983067430 -0600
@@ -20,6 +20,7 @@
  */

 import java.io.File;
+import java.util.Random;

 import junit.framework.TestCase;

@@ -217,14 +218,20 @@
         int bytes = getBytesForBlocksOfByteArrays( disk.getBlockSizeBytes(), numBlocksPerElement );

         int numElements = 100;
+        Random r = new Random(System.currentTimeMillis());
         for ( int i = 0; i < numElements; i++ )
         {
-            int[] blocks = disk.write( new byte[bytes] );
+               byte[] src = new byte[bytes];
+               r.nextBytes(src);  // Ensure we don't just write zeros out
+            int[] blocks = disk.write( src );
             byte[] result = (byte[]) disk.read( blocks );

             // VERIFY
-            assertEquals( "Wrong item retured.", new byte[bytes].length, result.length );
+            assertEquals( "Wrong item length retured.", src.length, result.length );
             assertEquals( "Wrong number of blocks returned.", numBlocksPerElement, blocks.length );
+            for (int j = 0 ; j < src.length ; j++) {
+               assertEquals( "Mismatch at offset " + j + " in attempt # " + (i + 1), src[j], result[j] );
+            }
         }
         System.out.println( "testWriteAndReadMultipleMultiBlockElement_setSize " + disk );
         assertEquals( "Wrong number of elements.", numBlocksPerElement * numElements, disk.getNumberOfBlocks() );

                
> Block cache fails to validate a cache file on startup when it contains elements with more than 2 blocks.
> --------------------------------------------------------------------------------------------------------
>
>                 Key: JCS-88
>                 URL: https://issues.apache.org/jira/browse/JCS-88
>             Project: Commons JCS
>          Issue Type: Bug
>    Affects Versions: jcs-1.3
>            Reporter: Diego Rivera
>   Original Estimate: 0h
>  Remaining Estimate: 0h
>
> The arithmetic for calculating block sizes is wrong.  The code adds a term that shouldn't be considered at that point.  For each block that needs to be written, the size of the block is currently calculated as:
> int chunkSize = Math.min( totalUsed + maxChunkSize, totalBytes - totalUsed )
> The term "totalUsed" should not be added to maxChunkSize, since the intent is to construct a chunk that's either as big as is allowed (maxChunkSize) or as big as the remaining bytes (totalBytes - totalUsed).  Thus, the correct calculation should be:
> int chunkSize = Math.min( maxChunkSize, totalBytes - totalUsed )
> The problem occurs in src/java/org/apache/jcs/auxiliary/disk/block/BlockDisk.java, line 196, inside byte[][] getBlockChunks(byte[] complete, int numBlocksNeeded).
> A patch has been devised and will be submitted as a comment (since attachments aren't possible at this point).  I still need to take the time to devise a unit test for this since the existing unit test passed without issue.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (JCS-88) Block cache fails to validate a cache file on startup when it contains elements with more than 2 blocks.

Posted by "Thomas Vandahl (Resolved) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/JCS-88?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Thomas Vandahl resolved JCS-88.
-------------------------------

       Resolution: Fixed
    Fix Version/s: jcs-1.4-dev

Added the test contained in the patch. The problem was already fixed.
                
> Block cache fails to validate a cache file on startup when it contains elements with more than 2 blocks.
> --------------------------------------------------------------------------------------------------------
>
>                 Key: JCS-88
>                 URL: https://issues.apache.org/jira/browse/JCS-88
>             Project: Commons JCS
>          Issue Type: Bug
>    Affects Versions: jcs-1.3
>            Reporter: Diego Rivera
>            Assignee: Thomas Vandahl
>             Fix For: jcs-1.4-dev
>
>         Attachments: jcs-1.3a-JCS-87-patch.patch
>
>   Original Estimate: 0h
>  Remaining Estimate: 0h
>
> The arithmetic for calculating block sizes is wrong.  The code adds a term that shouldn't be considered at that point.  For each block that needs to be written, the size of the block is currently calculated as:
> int chunkSize = Math.min( totalUsed + maxChunkSize, totalBytes - totalUsed )
> The term "totalUsed" should not be added to maxChunkSize, since the intent is to construct a chunk that's either as big as is allowed (maxChunkSize) or as big as the remaining bytes (totalBytes - totalUsed).  Thus, the correct calculation should be:
> int chunkSize = Math.min( maxChunkSize, totalBytes - totalUsed )
> The problem occurs in src/java/org/apache/jcs/auxiliary/disk/block/BlockDisk.java, line 196, inside byte[][] getBlockChunks(byte[] complete, int numBlocksNeeded).
> A patch has been devised and will be submitted as a comment (since attachments aren't possible at this point).  I still need to take the time to devise a unit test for this since the existing unit test passed without issue.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (JCS-88) Block cache fails to validate a cache file on startup when it contains elements with more than 2 blocks.

Posted by "Diego Rivera (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/JCS-88?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Diego Rivera updated JCS-88:
----------------------------

    Attachment: jcs-1.3a-JCS-87-patch.patch

This patch applies to JCS 1.3, and fixes the issue completely.  An updated unit test is included which both exposes the problem and confirms the fix.
                
> Block cache fails to validate a cache file on startup when it contains elements with more than 2 blocks.
> --------------------------------------------------------------------------------------------------------
>
>                 Key: JCS-88
>                 URL: https://issues.apache.org/jira/browse/JCS-88
>             Project: Commons JCS
>          Issue Type: Bug
>    Affects Versions: jcs-1.3
>            Reporter: Diego Rivera
>         Attachments: jcs-1.3a-JCS-87-patch.patch
>
>   Original Estimate: 0h
>  Remaining Estimate: 0h
>
> The arithmetic for calculating block sizes is wrong.  The code adds a term that shouldn't be considered at that point.  For each block that needs to be written, the size of the block is currently calculated as:
> int chunkSize = Math.min( totalUsed + maxChunkSize, totalBytes - totalUsed )
> The term "totalUsed" should not be added to maxChunkSize, since the intent is to construct a chunk that's either as big as is allowed (maxChunkSize) or as big as the remaining bytes (totalBytes - totalUsed).  Thus, the correct calculation should be:
> int chunkSize = Math.min( maxChunkSize, totalBytes - totalUsed )
> The problem occurs in src/java/org/apache/jcs/auxiliary/disk/block/BlockDisk.java, line 196, inside byte[][] getBlockChunks(byte[] complete, int numBlocksNeeded).
> A patch has been devised and will be submitted as a comment (since attachments aren't possible at this point).  I still need to take the time to devise a unit test for this since the existing unit test passed without issue.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (JCS-88) Block cache fails to validate a cache file on startup when it contains elements with more than 2 blocks.

Posted by "Diego Rivera (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/JCS-88?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13191439#comment-13191439 ] 

Diego Rivera commented on JCS-88:
---------------------------------

diff -ruN jcs-1.3/src/java/org/apache/jcs/auxiliary/disk/block/BlockDisk.java jcs-1.3.new/src/java/org/apache/jcs/auxiliary/disk/block/BlockDisk.java
--- jcs-1.3/src/java/org/apache/jcs/auxiliary/disk/block/BlockDisk.java 2007-05-30 12:23:53.000000000 -0600
+++ jcs-1.3.new/src/java/org/apache/jcs/auxiliary/disk/block/BlockDisk.java     2012-01-23 14:33:07.437164316 -0600
@@ -193,7 +193,7 @@
             {
                 // use the max that can be written to a block or whatever is left in the original
                 // array
-                int chunkSize = Math.min( totalUsed + maxChunkSize, totalBytes - totalUsed );
+                int chunkSize = Math.min( maxChunkSize, totalBytes - totalUsed );
                 byte[] chunk = new byte[chunkSize];
                 // copy from the used position to the chunk size on the complete array to the chunk
                 // array.
                
> Block cache fails to validate a cache file on startup when it contains elements with more than 2 blocks.
> --------------------------------------------------------------------------------------------------------
>
>                 Key: JCS-88
>                 URL: https://issues.apache.org/jira/browse/JCS-88
>             Project: Commons JCS
>          Issue Type: Bug
>    Affects Versions: jcs-1.3
>            Reporter: Diego Rivera
>   Original Estimate: 0h
>  Remaining Estimate: 0h
>
> The arithmetic for calculating block sizes is wrong.  The code adds a term that shouldn't be considered at that point.  For each block that needs to be written, the size of the block is currently calculated as:
> int chunkSize = Math.min( totalUsed + maxChunkSize, totalBytes - totalUsed )
> The term "totalUsed" should not be added to maxChunkSize, since the intent is to construct a chunk that's either as big as is allowed (maxChunkSize) or as big as the remaining bytes (totalBytes - totalUsed).  Thus, the correct calculation should be:
> int chunkSize = Math.min( maxChunkSize, totalBytes - totalUsed )
> The problem occurs in src/java/org/apache/jcs/auxiliary/disk/block/BlockDisk.java, line 196, inside byte[][] getBlockChunks(byte[] complete, int numBlocksNeeded).
> A patch has been devised and will be submitted as a comment (since attachments aren't possible at this point).  I still need to take the time to devise a unit test for this since the existing unit test passed without issue.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (JCS-88) Block cache fails to validate a cache file on startup when it contains elements with more than 2 blocks.

Posted by "Diego Rivera (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/JCS-88?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Diego Rivera updated JCS-88:
----------------------------

    Comment: was deleted

(was: diff -ruN /home/diego/Desktop/jcs-1.3/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskUnitTest.java src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskUnitTest.java
--- /home/diego/Desktop/jcs-1.3/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskUnitTest.java     2007-05-30 12:23:53.000000000 -0600
+++ src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskUnitTest.java 2012-01-23 17:06:10.983067430 -0600
@@ -20,6 +20,7 @@
  */

 import java.io.File;
+import java.util.Random;

 import junit.framework.TestCase;

@@ -217,14 +218,20 @@
         int bytes = getBytesForBlocksOfByteArrays( disk.getBlockSizeBytes(), numBlocksPerElement );

         int numElements = 100;
+        Random r = new Random(System.currentTimeMillis());
         for ( int i = 0; i < numElements; i++ )
         {
-            int[] blocks = disk.write( new byte[bytes] );
+               byte[] src = new byte[bytes];
+               r.nextBytes(src);  // Ensure we don't just write zeros out
+            int[] blocks = disk.write( src );
             byte[] result = (byte[]) disk.read( blocks );

             // VERIFY
-            assertEquals( "Wrong item retured.", new byte[bytes].length, result.length );
+            assertEquals( "Wrong item length retured.", src.length, result.length );
             assertEquals( "Wrong number of blocks returned.", numBlocksPerElement, blocks.length );
+            for (int j = 0 ; j < src.length ; j++) {
+               assertEquals( "Mismatch at offset " + j + " in attempt # " + (i + 1), src[j], result[j] );
+            }
         }
         System.out.println( "testWriteAndReadMultipleMultiBlockElement_setSize " + disk );
         assertEquals( "Wrong number of elements.", numBlocksPerElement * numElements, disk.getNumberOfBlocks() );
)
    
> Block cache fails to validate a cache file on startup when it contains elements with more than 2 blocks.
> --------------------------------------------------------------------------------------------------------
>
>                 Key: JCS-88
>                 URL: https://issues.apache.org/jira/browse/JCS-88
>             Project: Commons JCS
>          Issue Type: Bug
>    Affects Versions: jcs-1.3
>            Reporter: Diego Rivera
>         Attachments: jcs-1.3a-JCS-87-patch.patch
>
>   Original Estimate: 0h
>  Remaining Estimate: 0h
>
> The arithmetic for calculating block sizes is wrong.  The code adds a term that shouldn't be considered at that point.  For each block that needs to be written, the size of the block is currently calculated as:
> int chunkSize = Math.min( totalUsed + maxChunkSize, totalBytes - totalUsed )
> The term "totalUsed" should not be added to maxChunkSize, since the intent is to construct a chunk that's either as big as is allowed (maxChunkSize) or as big as the remaining bytes (totalBytes - totalUsed).  Thus, the correct calculation should be:
> int chunkSize = Math.min( maxChunkSize, totalBytes - totalUsed )
> The problem occurs in src/java/org/apache/jcs/auxiliary/disk/block/BlockDisk.java, line 196, inside byte[][] getBlockChunks(byte[] complete, int numBlocksNeeded).
> A patch has been devised and will be submitted as a comment (since attachments aren't possible at this point).  I still need to take the time to devise a unit test for this since the existing unit test passed without issue.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (JCS-88) Block cache fails to validate a cache file on startup when it contains elements with more than 2 blocks.

Posted by "Diego Rivera (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/JCS-88?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Diego Rivera updated JCS-88:
----------------------------

    Comment: was deleted

(was: diff -ruN jcs-1.3/src/java/org/apache/jcs/auxiliary/disk/block/BlockDisk.java jcs-1.3.new/src/java/org/apache/jcs/auxiliary/disk/block/BlockDisk.java
--- jcs-1.3/src/java/org/apache/jcs/auxiliary/disk/block/BlockDisk.java 2007-05-30 12:23:53.000000000 -0600
+++ jcs-1.3.new/src/java/org/apache/jcs/auxiliary/disk/block/BlockDisk.java     2012-01-23 14:33:07.437164316 -0600
@@ -193,7 +193,7 @@
             {
                 // use the max that can be written to a block or whatever is left in the original
                 // array
-                int chunkSize = Math.min( totalUsed + maxChunkSize, totalBytes - totalUsed );
+                int chunkSize = Math.min( maxChunkSize, totalBytes - totalUsed );
                 byte[] chunk = new byte[chunkSize];
                 // copy from the used position to the chunk size on the complete array to the chunk
                 // array.)
    
> Block cache fails to validate a cache file on startup when it contains elements with more than 2 blocks.
> --------------------------------------------------------------------------------------------------------
>
>                 Key: JCS-88
>                 URL: https://issues.apache.org/jira/browse/JCS-88
>             Project: Commons JCS
>          Issue Type: Bug
>    Affects Versions: jcs-1.3
>            Reporter: Diego Rivera
>         Attachments: jcs-1.3a-JCS-87-patch.patch
>
>   Original Estimate: 0h
>  Remaining Estimate: 0h
>
> The arithmetic for calculating block sizes is wrong.  The code adds a term that shouldn't be considered at that point.  For each block that needs to be written, the size of the block is currently calculated as:
> int chunkSize = Math.min( totalUsed + maxChunkSize, totalBytes - totalUsed )
> The term "totalUsed" should not be added to maxChunkSize, since the intent is to construct a chunk that's either as big as is allowed (maxChunkSize) or as big as the remaining bytes (totalBytes - totalUsed).  Thus, the correct calculation should be:
> int chunkSize = Math.min( maxChunkSize, totalBytes - totalUsed )
> The problem occurs in src/java/org/apache/jcs/auxiliary/disk/block/BlockDisk.java, line 196, inside byte[][] getBlockChunks(byte[] complete, int numBlocksNeeded).
> A patch has been devised and will be submitted as a comment (since attachments aren't possible at this point).  I still need to take the time to devise a unit test for this since the existing unit test passed without issue.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira