diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 007d35b3666..14b4961ea97 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -314,14 +314,7 @@ Bug fixes * LUCENE-8595: Fix interleaved DV update and reset. Interleaved update and reset value to the same doc in the same updates package looses an update if the reset comes before - the update as well as loosing the reset if the update comes frist. (Simon Willnauer, Adrien Grand) - -* LUCENE-8592: Fix index sorting corruption due to numeric overflow. The merge of sorted segments - can produce an invalid sort if the sort field is an Integer/Long that uses reverse order and contains - values equal to Integer/Long#MIN_VALUE. These values are always sorted first during a merge - (instead of last because of the reverse order) due to this bug. Indices affected by the bug can be - detected by running the CheckIndex command on a distribution that contains the fix (7.6+). - (Jim Ferenczi, Adrien Grand, Mike McCandless, Simon Willnauer) + the update as well as loosing the reset if the update comes frist. (Simon Willnauer, Adrien Grant) New Features diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java b/lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java index 44911dbcc0d..6f287978605 100644 --- a/lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java +++ b/lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java @@ -1717,33 +1717,6 @@ public class TestBackwardsCompatibility extends LuceneTestCase { dir.close(); } } - - /** - * Tests that {@link CheckIndex} can detect invalid sort on sorted indices created - * before https://issues.apache.org/jira/browse/LUCENE-8592. - */ - public void testSortedIndexWithInvalidSort() throws Exception { - Path path = createTempDir("sorted"); - String name = "sorted-invalid.7.5.0.zip"; - InputStream resource = TestBackwardsCompatibility.class.getResourceAsStream(name); - assertNotNull("Sorted index index " + name + " not found", resource); - TestUtil.unzip(resource, path); - - Directory dir = FSDirectory.open(path); - - DirectoryReader reader = DirectoryReader.open(dir); - assertEquals(1, reader.leaves().size()); - Sort sort = reader.leaves().get(0).reader().getMetaData().getSort(); - assertNotNull(sort); - assertEquals("! missingValue=-9223372036854775808", sort.toString()); - reader.close(); - CheckIndex.Status status = TestUtil.checkIndex(dir); - assertEquals(1, status.segmentInfos.size()); - assertNotNull(status.segmentInfos.get(0).indexSortStatus.error); - assertEquals(status.segmentInfos.get(0).indexSortStatus.error.getMessage(), - "segment has indexSort=! missingValue=-9223372036854775808 but docID=4 sorts after docID=5"); - dir.close(); - } static long getValue(BinaryDocValues bdv) throws IOException { BytesRef term = bdv.binaryValue(); diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/index/sorted-invalid.7.5.0.zip b/lucene/backward-codecs/src/test/org/apache/lucene/index/sorted-invalid.7.5.0.zip deleted file mode 100644 index 30c68a37a95..00000000000 Binary files a/lucene/backward-codecs/src/test/org/apache/lucene/index/sorted-invalid.7.5.0.zip and /dev/null differ diff --git a/lucene/core/src/java/org/apache/lucene/index/MultiSorter.java b/lucene/core/src/java/org/apache/lucene/index/MultiSorter.java index d81ac75b759..b484228bfc4 100644 --- a/lucene/core/src/java/org/apache/lucene/index/MultiSorter.java +++ b/lucene/core/src/java/org/apache/lucene/index/MultiSorter.java @@ -42,18 +42,17 @@ final class MultiSorter { SortField fields[] = sort.getSort(); final ComparableProvider[][] comparables = new ComparableProvider[fields.length][]; - final int[] reverseMuls = new int[fields.length]; for(int i=0;i queue = new PriorityQueue(leafCount) { @Override public boolean lessThan(LeafAndDocID a, LeafAndDocID b) { for(int i=0;i readers, SortField sortField) throws IOException { ComparableProvider[] providers = new ComparableProvider[readers.size()]; + final int reverseMul = sortField.getReverse() ? -1 : 1; final SortField.Type sortType = Sorter.getSortFieldType(sortField); switch(sortType) { @@ -169,9 +169,9 @@ final class MultiSorter { OrdinalMap ordinalMap = OrdinalMap.build(null, values, PackedInts.DEFAULT); final int missingOrd; if (sortField.getMissingValue() == SortField.STRING_LAST) { - missingOrd = Integer.MAX_VALUE; + missingOrd = sortField.getReverse() ? Integer.MIN_VALUE : Integer.MAX_VALUE; } else { - missingOrd = Integer.MIN_VALUE; + missingOrd = sortField.getReverse() ? Integer.MAX_VALUE : Integer.MIN_VALUE; } for(int readerIndex=0;readerIndex