Shorten getOrdinal synchronized loop ()

This commit is contained in:
Stefan Vodita 2023-12-08 00:27:49 +00:00 committed by GitHub
parent 5e1e6c9e68
commit ad9eff3c27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 15 deletions
lucene
CHANGES.txt
facet/src/java/org/apache/lucene/facet/taxonomy/directory

View File

@ -171,7 +171,8 @@ New Features
Improvements
---------------------
(No changes)
* GITHUB#12870: Tighten synchronized loop in DirectoryTaxonomyReader#getOrdinal. (Stefan Vodita)
Optimizations
---------------------

View File

@ -279,21 +279,22 @@ public class DirectoryTaxonomyReader extends TaxonomyReader implements Accountab
}
// First try to find the answer in the LRU cache:
Integer res;
synchronized (ordinalCache) {
Integer res = ordinalCache.get(cp);
if (res != null) {
if (res < indexReader.maxDoc()) {
// Since the cache is shared with DTR instances allocated from
// doOpenIfChanged, we need to ensure that the ordinal is one that
// this DTR instance recognizes.
return res;
} else {
// if we get here, it means that the category was found in the cache,
// but is not recognized by this TR instance. Therefore, there's no
// need to continue search for the path on disk, because we won't find
// it there too.
return TaxonomyReader.INVALID_ORDINAL;
}
res = ordinalCache.get(cp);
}
if (res != null) {
if (res < indexReader.maxDoc()) {
// Since the cache is shared with DTR instances allocated from
// doOpenIfChanged, we need to ensure that the ordinal is one that
// this DTR instance recognizes.
return res;
} else {
// if we get here, it means that the category was found in the cache,
// but is not recognized by this TR instance. Therefore, there's no
// need to continue search for the path on disk, because we won't find
// it there too.
return TaxonomyReader.INVALID_ORDINAL;
}
}