You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by rw...@apache.org on 2015/10/20 09:42:49 UTC
svn commit: r1709524 - in
/stanbol/trunk/enhancement-engines/lucenefstlinking/src/main/java/org/apache/stanbol/enhancer/engines/lucenefstlinking:
IndexConfiguration.java cache/FastLRUCacheManager.java
Author: rwesten
Date: Tue Oct 20 07:42:49 2015
New Revision: 1709524
URL: http://svn.apache.org/viewvc?rev=1709524&view=rev
Log:
STANBOL-1443: merged fix from 0.12.1 to trunk
Modified:
stanbol/trunk/enhancement-engines/lucenefstlinking/src/main/java/org/apache/stanbol/enhancer/engines/lucenefstlinking/IndexConfiguration.java
stanbol/trunk/enhancement-engines/lucenefstlinking/src/main/java/org/apache/stanbol/enhancer/engines/lucenefstlinking/cache/FastLRUCacheManager.java
Modified: stanbol/trunk/enhancement-engines/lucenefstlinking/src/main/java/org/apache/stanbol/enhancer/engines/lucenefstlinking/IndexConfiguration.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/lucenefstlinking/src/main/java/org/apache/stanbol/enhancer/engines/lucenefstlinking/IndexConfiguration.java?rev=1709524&r1=1709523&r2=1709524&view=diff
==============================================================================
--- stanbol/trunk/enhancement-engines/lucenefstlinking/src/main/java/org/apache/stanbol/enhancer/engines/lucenefstlinking/IndexConfiguration.java (original)
+++ stanbol/trunk/enhancement-engines/lucenefstlinking/src/main/java/org/apache/stanbol/enhancer/engines/lucenefstlinking/IndexConfiguration.java Tue Oct 20 07:42:49 2015
@@ -413,7 +413,7 @@ public class IndexConfiguration {
*/
public boolean activate() {
active = true;
- RefCounted<SolrIndexSearcher> searcherRef = index.getSearcher(true, true, null);
+ RefCounted<SolrIndexSearcher> searcherRef = index.getSearcher();
try {
return processFstConfig(searcherRef.get().getAtomicReader());
}catch (RuntimeException e) { //in case of any excpetion
Modified: stanbol/trunk/enhancement-engines/lucenefstlinking/src/main/java/org/apache/stanbol/enhancer/engines/lucenefstlinking/cache/FastLRUCacheManager.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/lucenefstlinking/src/main/java/org/apache/stanbol/enhancer/engines/lucenefstlinking/cache/FastLRUCacheManager.java?rev=1709524&r1=1709523&r2=1709524&view=diff
==============================================================================
--- stanbol/trunk/enhancement-engines/lucenefstlinking/src/main/java/org/apache/stanbol/enhancer/engines/lucenefstlinking/cache/FastLRUCacheManager.java (original)
+++ stanbol/trunk/enhancement-engines/lucenefstlinking/src/main/java/org/apache/stanbol/enhancer/engines/lucenefstlinking/cache/FastLRUCacheManager.java Tue Oct 20 07:42:49 2015
@@ -19,6 +19,8 @@ package org.apache.stanbol.enhancer.engi
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.apache.lucene.document.Document;
import org.apache.solr.search.CacheRegenerator;
@@ -42,6 +44,8 @@ public class FastLRUCacheManager impleme
RefCounted<EntityCache> current;
private final CacheRegenerator regenerator;
private final Map<String,String> config;
+ private ReadWriteLock lock = new ReentrantReadWriteLock();
+
/**
* Creates a cache manager instance with the parsed maximum size and no
@@ -77,36 +81,63 @@ public class FastLRUCacheManager impleme
@Override
public RefCounted<EntityCache> getCache(Object version) {
- if(current == null || !current.get().getVersion().equals(version)){
- if(current != null){
- log.debug(" > invalidate EntityCache for version {}", current.get().getVersion());
- //remove the reference to the old instance. This will allow to
- //destroy the old cache as soon as it is no longer used
- current.decref();
- log.debug(" ... {} remaining users for invalidated Cache", current.getRefcount());
- current = null;
+ lock.readLock().lock();
+ try {
+ if(current != null && current.get().getVersion().equals(version)){
+ current.incref(); //this increase is for the holder of the returned instance
+ log.debug(" > increase RefCount for EntityCache for version {} to {}",
+ version, current.getRefcount());
+ return current;
+ }
+ } finally {
+ lock.readLock().unlock();
+ }
+ //still here ... looks like we need to build a new one
+ lock.writeLock().lock();
+ try {
+ //check again ... an other thread might have already built the cache
+ //for the requested version
+ if(current == null || !current.get().getVersion().equals(version)){
+ if(current != null){
+ log.debug(" > invalidate EntityCache for version {}", current.get().getVersion());
+ //remove the reference to the old instance. This will allow to
+ //destroy the old cache as soon as it is no longer used
+ current.decref();
+ log.debug(" ... {} remaining users for invalidated Cache", current.getRefcount());
+ current = null;
+ }
+ //create a new cache
+ log.debug(" > create EntityCache for version {}", version);
+ SolrCache<Integer,Document> cache = new FastLRUCache<Integer,Document>();
+ cache.init(config, null, regenerator);
+ current = new RefCountedImpl(new SolrEntityCache(version, cache));
+ //add a reference to the new cache by this class. This will be removed
+ //as soon as the instance is outdated
+ current.incref();
}
- //create a new cache
- log.debug(" > create EntityCache for version {}", version);
- SolrCache<Integer,Document> cache = new FastLRUCache<Integer,Document>();
- cache.init(config, null, regenerator);
- current = new RefCountedImpl(new SolrEntityCache(version, cache));
- //add a reference to the new cache by this class. This will be removed
- //as soon as the instance is outdated
- current.incref();
+ current.incref(); //this increase is for the holder of the returned instance
+ log.debug(" > increase RefCount for EntityCache for version {} to {}",
+ version, current.getRefcount());
+ return current;
+ } finally {
+ lock.writeLock().unlock();
}
- current.incref(); //this increase is for the holder of the returned instance
- log.debug(" > increase RefCount for EntityCache for version {} to {}",
- version, current.getRefcount());
- return current;
}
@Override
public void close() {
- if(current != null){
- current.decref();
- current = null;
- }
+ lock.writeLock().lock();
+ try {
+ if(current != null){
+ Object version = log.isDebugEnabled() ? current.get().getVersion() : null;
+ current.decref();
+ log.debug(" > close EntityCache for version {} (remaining refCount: {})",
+ version , current.getRefcount());
+ current = null;
+ }
+ } finally{
+ lock.writeLock().unlock();
+ }
}
@Override