mirror of https://github.com/apache/lucene.git
SOLR-9310: fixing concurrency issue and taking care of negative versions
This commit is contained in:
parent
80f9167807
commit
37ae065591
|
@ -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<Long,IndexFingerprint> maxVersionFingerprintCache = new HashMap<>();
|
||||
private final Object fingerprintLock = new Object();
|
||||
private final Map<Long, IndexFingerprint> 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;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -952,7 +952,7 @@ public class UpdateLog implements PluginInfoInitialized {
|
|||
|
||||
for (List<Update> 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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue