Uploaded image for project: 'Commons JCS'
  1. Commons JCS
  2. JCS-88

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

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • jcs-1.3
    • jcs-2.0-beta-1
    • None
    • None

    Description

      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.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            tv Thomas Vandahl
            diego.rivera.cr@gmail.com Diego Rivera
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment