Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C0CA1200BA7 for ; Fri, 21 Oct 2016 18:02:39 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id BDA55160AE8; Fri, 21 Oct 2016 16:02:39 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B31FF160ADE for ; Fri, 21 Oct 2016 18:02:38 +0200 (CEST) Received: (qmail 4978 invoked by uid 500); 21 Oct 2016 16:02:37 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 4969 invoked by uid 99); 21 Oct 2016 16:02:37 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 Oct 2016 16:02:37 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 6E342C0118 for ; Fri, 21 Oct 2016 16:02:37 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -1.999 X-Spam-Level: X-Spam-Status: No, score=-1.999 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id Wsbn71_I0K55 for ; Fri, 21 Oct 2016 16:02:35 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 4075D60D9B for ; Fri, 21 Oct 2016 16:02:31 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 70268E031B for ; Fri, 21 Oct 2016 16:02:29 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 707113A0B5F for ; Fri, 21 Oct 2016 16:02:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1766058 - in /commons/proper/jcs/trunk/commons-jcs-core/src: main/java/org/apache/commons/jcs/auxiliary/disk/indexed/ main/java/org/apache/commons/jcs/utils/struct/ test/java/org/apache/commons/jcs/utils/struct/ Date: Fri, 21 Oct 2016 16:02:29 -0000 To: commits@commons.apache.org From: tv@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20161021160229.707113A0B5F@svn01-us-west.apache.org> archived-at: Fri, 21 Oct 2016 16:02:39 -0000 Author: tv Date: Fri Oct 21 16:02:29 2016 New Revision: 1766058 URL: http://svn.apache.org/viewvc?rev=1766058&view=rev Log: Replace SortedPreferentialArray with JDK ConcurrentSkipListSet Removed: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/struct/SortedPreferentialArray.java commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/struct/SortedPrefArrayUnitTest.java Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexedDiskCache.java Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexedDiskCache.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexedDiskCache.java?rev=1766058&r1=1766057&r2=1766058&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexedDiskCache.java (original) +++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexedDiskCache.java Fri Oct 21 16:02:29 2016 @@ -33,6 +33,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.locks.ReentrantReadWriteLock; @@ -53,7 +54,6 @@ import org.apache.commons.jcs.engine.sta import org.apache.commons.jcs.engine.stats.behavior.IStats; import org.apache.commons.jcs.utils.struct.AbstractLRUMap; import org.apache.commons.jcs.utils.struct.LRUMap; -import org.apache.commons.jcs.utils.struct.SortedPreferentialArray; import org.apache.commons.jcs.utils.timing.ElapsedTimer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -114,10 +114,11 @@ public class IndexedDiskCache exte private boolean queueInput = false; /** list where puts made during optimization are made */ - private final LinkedList queuedPutList = new LinkedList(); + private final ConcurrentSkipListSet queuedPutList = + new ConcurrentSkipListSet(new PositionComparator()); /** RECYLCE BIN -- array of empty spots */ - private SortedPreferentialArray recycle; + private ConcurrentSkipListSet recycle; /** User configurable parameters */ private final IndexedDiskCacheAttributes cattr; @@ -198,7 +199,7 @@ public class IndexedDiskCache exte doOptimizeRealTime(); } } - catch (Exception e) + catch (IOException e) { log.error( logCacheName + "Failure initializing for fileName: " + fileName + " and directory: " @@ -229,9 +230,8 @@ public class IndexedDiskCache exte * * @param cattr * @throws IOException - * @throws InterruptedException */ - private void initializeKeysAndData(IndexedDiskCacheAttributes cattr) throws IOException, InterruptedException + private void initializeKeysAndData(IndexedDiskCacheAttributes cattr) throws IOException { this.dataFile = new IndexedDisk(new File(rafDir, fileName + ".data"), getElementSerializer()); this.keyFile = new IndexedDisk(new File(rafDir, fileName + ".key"), getElementSerializer()); @@ -279,10 +279,9 @@ public class IndexedDiskCache exte * files are cleared. *

* - * @throws InterruptedException * @throws IOException */ - private void initializeStoreFromPersistedData() throws InterruptedException, IOException + private void initializeStoreFromPersistedData() throws IOException { loadKeys(); @@ -313,11 +312,8 @@ public class IndexedDiskCache exte /** * Loads the keys from the .key file. The keys are stored in a HashMap on disk. This is * converted into a LRUMap. - *

- * - * @throws InterruptedException */ - protected void loadKeys() throws InterruptedException + protected void loadKeys() { if (log.isDebugEnabled()) { @@ -331,8 +327,8 @@ public class IndexedDiskCache exte // create a key map to use. initializeKeyMap(); - HashMap keys = keyFile.readObject(new IndexedDiskElementDescriptor(0, (int) keyFile - .length() - IndexedDisk.HEADER_SIZE_BYTES)); + HashMap keys = keyFile.readObject( + new IndexedDiskElementDescriptor(0, (int) keyFile.length() - IndexedDisk.HEADER_SIZE_BYTES)); if (keys != null) { @@ -406,7 +402,7 @@ public class IndexedDiskCache exte isOk = checkForDedOverlaps(createPositionSortedDescriptorList()); } } - catch (Exception e) + catch (IOException e) { log.error(e); isOk = false; @@ -484,7 +480,7 @@ public class IndexedDiskCache exte log.info(logCacheName + "Finished saving keys."); } } - catch (Exception e) + catch (IOException e) { log.error(logCacheName + "Problem storing keys.", e); } @@ -543,9 +539,11 @@ public class IndexedDiskCache exte if (doRecycle) { - IndexedDiskElementDescriptor rep = recycle.takeNearestLargerOrEqual(ded); + IndexedDiskElementDescriptor rep = recycle.ceiling(ded); if (rep != null) { + // remove element from recycle bin + recycle.remove(rep); ded = rep; ded.len = data.length; recycleCnt++; @@ -600,7 +598,7 @@ public class IndexedDiskCache exte log.debug(logCacheName + "Caught ConcurrentModificationException." + cme); } } - catch (Exception e) + catch (IOException e) { log.error(logCacheName + "Failure updating element, key: " + ce.getKey() + " old: " + old, e); } @@ -651,10 +649,6 @@ public class IndexedDiskCache exte log.error(logCacheName + "Failure getting from disk, key = " + key, ioe); reset(); } - catch (Exception e) - { - log.error(logCacheName + "Failure getting from disk, key = " + key, e); - } return object; } @@ -670,34 +664,27 @@ public class IndexedDiskCache exte public Map> processGetMatching(String pattern) { Map> elements = new HashMap>(); + Set keyArray = null; + storageLock.readLock().lock(); try { - Set keyArray = null; - storageLock.readLock().lock(); - try - { - keyArray = new HashSet(keyHash.keySet()); - } - finally - { - storageLock.readLock().unlock(); - } + keyArray = new HashSet(keyHash.keySet()); + } + finally + { + storageLock.readLock().unlock(); + } - Set matchingKeys = getKeyMatcher().getMatchingKeysFromArray(pattern, keyArray); + Set matchingKeys = getKeyMatcher().getMatchingKeysFromArray(pattern, keyArray); - for (K key : matchingKeys) + for (K key : matchingKeys) + { + ICacheElement element = processGet(key); + if (element != null) { - ICacheElement element = processGet(key); - if (element != null) - { - elements.put(key, element); - } + elements.put(key, element); } } - catch (Exception e) - { - log.error(logCacheName + "Failure getting matching from disk, pattern = " + pattern, e); - } return elements; } @@ -808,11 +795,6 @@ public class IndexedDiskCache exte removed = performSingleKeyRemoval(key); } } - catch (Exception e) - { - log.error(logCacheName + "Problem removing element.", e); - reset = true; - } finally { storageLock.writeLock().unlock(); @@ -945,11 +927,6 @@ public class IndexedDiskCache exte { reset(); } - catch (Exception e) - { - log.error(logCacheName + "Problem removing all.", e); - reset(); - } finally { logICacheEvent(cacheEvent); @@ -957,7 +934,7 @@ public class IndexedDiskCache exte } /** - * Reset effectively clears the disk cache, creating new files, recyclebins, and keymaps. + * Reset effectively clears the disk cache, creating new files, recycle bins, and keymaps. *

* It can be used to handle errors by last resort, force content update, or removeall. */ @@ -965,7 +942,7 @@ public class IndexedDiskCache exte { if (log.isWarnEnabled()) { - log.warn(logCacheName + "Reseting cache"); + log.warn(logCacheName + "Resetting cache"); } try @@ -1017,12 +994,7 @@ public class IndexedDiskCache exte */ private void initializeRecycleBin() { - int recycleBinSize = cattr.getMaxRecycleBinSize() >= 0 ? cattr.getMaxRecycleBinSize() : 0; - recycle = new SortedPreferentialArray(recycleBinSize); - if (log.isDebugEnabled()) - { - log.debug(logCacheName + "Set recycle max Size to MaxRecycleBinSize: '" + recycleBinSize + "'"); - } + recycle = new ConcurrentSkipListSet(); } /** @@ -1165,8 +1137,6 @@ public class IndexedDiskCache exte * (2) When an item on disk is updated with a value that will not fit in the previous slot. (3) When the max key size is * reached, the freed slot will be added. *

- * The recylebin is not a set. If a slot it added twice, it will result in the wrong data being returned. - *

* * @param ded */ @@ -1306,10 +1276,7 @@ public class IndexedDiskCache exte { if (!queuedPutList.isEmpty()) { - // This is perhaps unnecessary, but the list might not be as sorted as we think. - defragList = new IndexedDiskElementDescriptor[queuedPutList.size()]; - queuedPutList.toArray(defragList); - Arrays.sort(defragList, new PositionComparator()); + defragList = queuedPutList.toArray(new IndexedDiskElementDescriptor[queuedPutList.size()]); // pack them at the end expectedNextPos = defragFile(defragList, expectedNextPos); @@ -1317,7 +1284,7 @@ public class IndexedDiskCache exte // TRUNCATE THE FILE dataFile.truncate(expectedNextPos); } - catch (Exception e) + catch (IOException e) { log.error(logCacheName + "Error optimizing queued puts.", e); } @@ -1441,7 +1408,7 @@ public class IndexedDiskCache exte } /** - * Returns the size of the recyclebin in number of elements. + * Returns the size of the recycle bin in number of elements. *

* * @return The number of items in the bin. @@ -1576,21 +1543,8 @@ public class IndexedDiskCache exte } /** - * Gets basic stats for the disk cache. - *

- * - * @return String - */ - @Override - public String getStats() - { - return getStatistics().toString(); - } - - /** * Returns info about the disk cache. *

- * (non-Javadoc) * * @see org.apache.commons.jcs.auxiliary.AuxiliaryCache#getStatistics() */ @@ -1609,7 +1563,7 @@ public class IndexedDiskCache exte elems .add(new StatElement("Data File Length", Long.valueOf(this.dataFile != null ? this.dataFile.length() : -1L))); } - catch (Exception e) + catch (IOException e) { log.error(e); }