diff --git a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java index de4d6bf59c2..7f155742ba5 100644 --- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java +++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java @@ -33,6 +33,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; @@ -147,8 +148,7 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrI private final String path; private boolean releaseDirectory; - private volatile Map maxVersionFingerprintCache = new HashMap<>(); - private final Object fingerprintLock = new Object(); + private final Map maxVersionFingerprintCache = new ConcurrentHashMap<>(); private static DirectoryReader getReader(SolrCore core, SolrIndexConfig config, DirectoryFactory directoryFactory, String path) throws IOException { @@ -2379,22 +2379,16 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrI * gets a cached version of the IndexFingerprint for this searcher **/ public IndexFingerprint getIndexFingerprint(long maxVersion) throws IOException { + IndexFingerprint fingerprint = maxVersionFingerprintCache.get(maxVersion); + if (fingerprint != null) return fingerprint; // possibly expensive, so prevent more than one thread from calculating it for this searcher - - // TODO what happens if updates came out of order, would cached fingerprint still be valid? - // May be caching fingerprint may lead more problems - IndexFingerprint fingerprint = maxVersionFingerprintCache.get(maxVersionFingerprintCache); - if(fingerprint == null) { - synchronized (fingerprintLock) { - if (maxVersionFingerprintCache.get(maxVersionFingerprintCache) == null) { - log.info("Fingerprint for max version: " + maxVersion + " not found in cache" ); - maxVersionFingerprintCache.put(maxVersion, IndexFingerprint.getFingerprint(this, maxVersion)); - } - fingerprint = maxVersionFingerprintCache.get(maxVersion) ; - } + synchronized (maxVersionFingerprintCache) { + fingerprint = maxVersionFingerprintCache.get(maxVersionFingerprintCache); + if (fingerprint != null) return fingerprint; + fingerprint = IndexFingerprint.getFingerprint(this, maxVersion); + maxVersionFingerprintCache.put(maxVersion, fingerprint); + return fingerprint; } - - return fingerprint; } ///////////////////////////////////////////////////////////////////// diff --git a/solr/core/src/java/org/apache/solr/update/UpdateLog.java b/solr/core/src/java/org/apache/solr/update/UpdateLog.java index ba25acfed58..0b4fc1895d2 100644 --- a/solr/core/src/java/org/apache/solr/update/UpdateLog.java +++ b/solr/core/src/java/org/apache/solr/update/UpdateLog.java @@ -952,7 +952,7 @@ public class UpdateLog implements PluginInfoInitialized { for (List singleList : updateList) { for (Update ptr : singleList) { - if(ptr.version > maxVersion) continue; + if(Math.abs(ptr.version) > Math.abs(maxVersion)) continue; ret.add(ptr.version); if (--n <= 0) return ret; }