Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Indexed Disk Cache
    • Labels:
      None

      Description

      I'm using JCS cache in UPDATE mode and I found that disk cache may grow when adding the cache entries with the same key but larger value.

      For example,
      cache.put("key", "value");
      cache.put("key", "value1");
      cache.put("key", "value12");

      After that I see that *.data file contains all 3 entries. And the cache is not optimized at shutdown even when isShutdownOptimizationEnabled is set to true.

      I found a workaround for this - delete the key before writing.

        Activity

        Hide
        Aaron Smuts added a comment -

        I fixed the same key issue. It will be in 1.3.3.3-RC

        Show
        Aaron Smuts added a comment - I fixed the same key issue. It will be in 1.3.3.3-RC
        Hide
        Aaron Smuts added a comment -

        I wrote a test to verify the bug. I fixed it.

        /**

        • Verify that the old slot gets in the recycle bin.
        • <p>
        • @throws IOException
          */
          public void testProcessUpdate_SameKeyBiggerSize()
          throws IOException { // SETUP String cacheName = "testProcessUpdate_SameKeyBiggerSize"; IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes(); cattr.setCacheName( cacheName ); cattr.setMaxKeySize( 100 ); cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" ); IndexedDiskCache diskCache = new IndexedDiskCache( cattr ); String key = "myKey"; String value = "myValue"; String value2 = "myValue2"; ICacheElement ce1 = new CacheElement( cacheName, key, value ); // DO WORK diskCache.processUpdate( ce1 ); long fileSize1 = diskCache.getDataFileSize(); // DO WORK ICacheElement ce2 = new CacheElement( cacheName, key, value2 ); diskCache.processUpdate( ce2 ); ICacheElement result = diskCache.processGet( key ); // VERIFY assertNotNull( "Should have a result", result ); long fileSize2 = diskCache.getDataFileSize(); assertTrue( "File should be greater.", fileSize1 < fileSize2 ); int binSize = diskCache.getRecyleBinSize(); assertEquals( "Should be one in the bin.", 1, binSize ); }
        Show
        Aaron Smuts added a comment - I wrote a test to verify the bug. I fixed it. /** Verify that the old slot gets in the recycle bin. <p> @throws IOException */ public void testProcessUpdate_SameKeyBiggerSize() throws IOException { // SETUP String cacheName = "testProcessUpdate_SameKeyBiggerSize"; IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes(); cattr.setCacheName( cacheName ); cattr.setMaxKeySize( 100 ); cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" ); IndexedDiskCache diskCache = new IndexedDiskCache( cattr ); String key = "myKey"; String value = "myValue"; String value2 = "myValue2"; ICacheElement ce1 = new CacheElement( cacheName, key, value ); // DO WORK diskCache.processUpdate( ce1 ); long fileSize1 = diskCache.getDataFileSize(); // DO WORK ICacheElement ce2 = new CacheElement( cacheName, key, value2 ); diskCache.processUpdate( ce2 ); ICacheElement result = diskCache.processGet( key ); // VERIFY assertNotNull( "Should have a result", result ); long fileSize2 = diskCache.getDataFileSize(); assertTrue( "File should be greater.", fileSize1 < fileSize2 ); int binSize = diskCache.getRecyleBinSize(); assertEquals( "Should be one in the bin.", 1, binSize ); }
        Hide
        Aaron Smuts added a comment -

        It looks like it's not making it into the recycle bin.

        Show
        Aaron Smuts added a comment - It looks like it's not making it into the recycle bin.
        Hide
        Aaron Smuts added a comment -

        It would be a bug if the old spots don't make it into the recycle bin.

        If there are no free bytes recorded, the disk cache will not try to optimize on shutdown.

        Show
        Aaron Smuts added a comment - It would be a bug if the old spots don't make it into the recycle bin. If there are no free bytes recorded, the disk cache will not try to optimize on shutdown.
        Hide
        Aaron Smuts added a comment -

        The first is not a bug. Items are not removed from disk, they are merely removed from the key map. The old slots are added to the recycle bin. They will be used on the next put for an item that will fit in the spot.

        I'm not sure about optimization. Perhaps you didn't shutdown orderly.

        Show
        Aaron Smuts added a comment - The first is not a bug. Items are not removed from disk, they are merely removed from the key map. The old slots are added to the recycle bin. They will be used on the next put for an item that will fit in the spot. I'm not sure about optimization. Perhaps you didn't shutdown orderly.

          People

          • Assignee:
            Aaron Smuts
            Reporter:
            Alexander Sofronov
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development