Skip to content

Commit 65c4251

Browse files
stefanvoditagsmiller
authored andcommitted
Shorten getOrdinal synchronized loop (#12870)
1 parent 0aff413 commit 65c4251

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

lucene/CHANGES.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ New Features
1616

1717
Improvements
1818
---------------------
19-
(No changes)
19+
20+
* GITHUB#12870: Tighten synchronized loop in DirectoryTaxonomyReader#getOrdinal. (Stefan Vodita)
2021

2122
Optimizations
2223
---------------------

lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyReader.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -280,21 +280,22 @@ public int getOrdinal(FacetLabel cp) throws IOException {
280280
}
281281

282282
// First try to find the answer in the LRU cache:
283+
Integer res;
283284
synchronized (ordinalCache) {
284-
Integer res = ordinalCache.get(cp);
285-
if (res != null) {
286-
if (res < indexReader.maxDoc()) {
287-
// Since the cache is shared with DTR instances allocated from
288-
// doOpenIfChanged, we need to ensure that the ordinal is one that
289-
// this DTR instance recognizes.
290-
return res;
291-
} else {
292-
// if we get here, it means that the category was found in the cache,
293-
// but is not recognized by this TR instance. Therefore, there's no
294-
// need to continue search for the path on disk, because we won't find
295-
// it there too.
296-
return TaxonomyReader.INVALID_ORDINAL;
297-
}
285+
res = ordinalCache.get(cp);
286+
}
287+
if (res != null) {
288+
if (res < indexReader.maxDoc()) {
289+
// Since the cache is shared with DTR instances allocated from
290+
// doOpenIfChanged, we need to ensure that the ordinal is one that
291+
// this DTR instance recognizes.
292+
return res;
293+
} else {
294+
// if we get here, it means that the category was found in the cache,
295+
// but is not recognized by this TR instance. Therefore, there's no
296+
// need to continue search for the path on disk, because we won't find
297+
// it there too.
298+
return TaxonomyReader.INVALID_ORDINAL;
298299
}
299300
}
300301

0 commit comments

Comments
 (0)