mirror of https://github.com/apache/lucene.git
Various fixes and updates for index sorting on flush
* IndexWriter.validateIndexSort now throws a CorruptIndexException if a segment created by version >= 6.5.0 is not sorted (already applied in branch_6x) * Removes unneeded check in AssertingLiveDocsFormat (already applied in branch_6x) * Removes try/finally block when stored fields consumer finishes (already applied in branch_6x).
This commit is contained in:
parent
ed513fdee7
commit
1acd2ee2bb
|
@ -313,10 +313,7 @@ final class DefaultIndexingChain extends DocConsumer {
|
|||
|
||||
@Override
|
||||
public void abort() {
|
||||
try {
|
||||
storedFieldsConsumer.abort();
|
||||
} catch (Throwable t) {
|
||||
}
|
||||
storedFieldsConsumer.abort();
|
||||
|
||||
try {
|
||||
// E.g. close any open files in the term vectors writer:
|
||||
|
|
|
@ -1034,17 +1034,17 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
|
|||
|
||||
/** Confirms that the incoming index sort (if any) matches the existing index sort (if any).
|
||||
* This is unfortunately just best effort, because it could be the old index only has unsorted flushed segments built
|
||||
* before {@link Version#LUCENE_7_0_0} (flushed segments are sorted in Lucene 7.0). */
|
||||
private void validateIndexSort() {
|
||||
* before {@link Version#LUCENE_6_5_0} (flushed segments are sorted in Lucene 7.0). */
|
||||
private void validateIndexSort() throws CorruptIndexException {
|
||||
Sort indexSort = config.getIndexSort();
|
||||
if (indexSort != null) {
|
||||
for(SegmentCommitInfo info : segmentInfos) {
|
||||
Sort segmentIndexSort = info.info.getIndexSort();
|
||||
if (segmentIndexSort != null && indexSort.equals(segmentIndexSort) == false) {
|
||||
throw new IllegalArgumentException("cannot change previous indexSort=" + segmentIndexSort + " (from segment=" + info + ") to new indexSort=" + indexSort);
|
||||
} else if (segmentIndexSort == null) {
|
||||
// Flushed segments are not sorted if they were built with a version prior to 7.0
|
||||
assert info.info.getVersion().onOrAfter(Version.LUCENE_7_0_0) == false;
|
||||
} else if (segmentIndexSort == null && info.info.getVersion().onOrAfter(Version.LUCENE_6_5_0)) {
|
||||
// Flushed segments are not sorted if they were built with a version prior to 6.5.0
|
||||
throw new CorruptIndexException("segment not sorted with indexSort=" + segmentIndexSort, info.info.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ import static org.apache.lucene.search.DocIdSetIterator.NO_MORE_DOCS;
|
|||
|
||||
/**
|
||||
* An {@link org.apache.lucene.index.LeafReader} which supports sorting documents by a given
|
||||
* {@link Sort}. This is package private and is only used by Lucene fo BWC when it needs to merge
|
||||
* {@link Sort}. This is package private and is only used by Lucene for BWC when it needs to merge
|
||||
* an unsorted flushed segment built by an older version (newly flushed segments are sorted since version 7.0).
|
||||
*
|
||||
* @lucene.experimental
|
||||
|
|
|
@ -68,13 +68,8 @@ public class AssertingLiveDocsFormat extends LiveDocsFormat {
|
|||
|
||||
@Override
|
||||
public void writeLiveDocs(MutableBits bits, Directory dir, SegmentCommitInfo info, int newDelCount, IOContext context) throws IOException {
|
||||
MutableBits raw = bits;
|
||||
/**
|
||||
* bits is not necessarily an AssertingMutableBits because index sorting needs to wrap it in a sorted view.
|
||||
*/
|
||||
if (bits instanceof AssertingMutableBits) {
|
||||
raw = (MutableBits) ((AssertingMutableBits) bits).in;
|
||||
}
|
||||
assert bits instanceof AssertingMutableBits;
|
||||
MutableBits raw = (MutableBits) ((AssertingMutableBits)bits).in;
|
||||
check(raw, info.info.maxDoc(), info.getDelCount() + newDelCount);
|
||||
in.writeLiveDocs(raw, dir, info, newDelCount, context);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue