Github user mikemccand commented on a diff in the pull request:
https://github.com/apache/lucene-solr/pull/502#discussion_r235148814
--- Diff: lucene/core/src/java/org/apache/lucene/index/IndexWriter.java ---
@@ -4398,42 +4426,41 @@ private int mergeMiddle(MergePolicy.OneMerge merge,
MergePolicy mergePolicy) thr
// Let the merge wrap readers
List<CodecReader> mergeReaders = new ArrayList<>();
- int softDeleteCount = 0;
+ Counter softDeleteCount = Counter.newCounter(false);
for (int r = 0; r < merge.readers.size(); r++) {
SegmentReader reader = merge.readers.get(r);
CodecReader wrappedReader = merge.wrapForMerge(reader);
validateMergeReader(wrappedReader);
if (softDeletesEnabled) {
+
if (reader != wrappedReader) { // if we don't have a wrapped
reader we won't preserve any soft-deletes
Bits hardLiveDocs = merge.hardLiveDocs.get(r);
- Bits wrappedLiveDocs = wrappedReader.getLiveDocs();
- int hardDeleteCount = 0;
- DocIdSetIterator softDeletedDocs =
DocValuesFieldExistsQuery.getDocValuesDocIdSetIterator(config.getSoftDeletesField(),
wrappedReader);
- if (softDeletedDocs != null) {
- int docId;
- while ((docId = softDeletedDocs.nextDoc()) !=
DocIdSetIterator.NO_MORE_DOCS) {
- if (wrappedLiveDocs == null || wrappedLiveDocs.get(docId))
{
- if (hardLiveDocs == null || hardLiveDocs.get(docId)) {
- softDeleteCount++;
- } else {
- hardDeleteCount++;
+ if (hardLiveDocs != null) { // we only need to do this
accounting if we have mixed deletes
+ Bits wrappedLiveDocs = wrappedReader.getLiveDocs();
+ int hardDeleteCount = countSoftDeletes(wrappedReader,
wrappedLiveDocs, hardLiveDocs, softDeleteCount);
+ // Wrap the wrapped reader again if we have excluded some
hard-deleted docs
+ if (hardLiveDocs != null && hardDeleteCount > 0) {
+ Bits liveDocs = wrappedLiveDocs == null ? hardLiveDocs :
new Bits() {
+ @Override
+ public boolean get(int index) {
+ return hardLiveDocs.get(index) &&
wrappedLiveDocs.get(index);
}
- }
+
+ @Override
+ public int length() {
+ return hardLiveDocs.length();
+ }
+ };
+ wrappedReader =
FilterCodecReader.wrapLiveDocs(wrappedReader, liveDocs, wrappedReader.numDocs()
- hardDeleteCount);
}
- }
- // Wrap the wrapped reader again if we have excluded some
hard-deleted docs
- if (hardLiveDocs != null && hardDeleteCount > 0) {
- Bits liveDocs = wrappedLiveDocs == null ? hardLiveDocs : new
Bits() {
- @Override
- public boolean get(int index) {
- return hardLiveDocs.get(index) &&
wrappedLiveDocs.get(index);
- }
- @Override
- public int length() {
- return hardLiveDocs.length();
- }
- };
- wrappedReader =
FilterCodecReader.wrapLiveDocs(wrappedReader, liveDocs, wrappedReader.numDocs()
- hardDeleteCount);
+ } else {
+ int carryOverSoftDeletes =
reader.getSegmentInfo().getSoftDelCount() - wrappedReader.numDeletedDocs();
+ if (carryOverSoftDeletes < 0) {
+ throw new IllegalStateException("carry-over soft-deletes
must be positive");
--- End diff --
`AssertionError` instead? This means we have a bug right?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]