-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Catch up DLS with recent Lucene changes. #133966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4fe2fad
Catch up DLS with recent Lucene changes.
jpountz 30307a0
Merge branch 'main' into modernize_dls
jpountz 99e9e96
Merge branch 'main' into modernize_dls
jpountz f0e7083
Merge branch 'main' into modernize_dls
joegallo 02237f3
Consistently use WINDOW_SIZE rather than bitSet.length().
jpountz 23198a1
Merge branch 'main' into modernize_dls
joegallo c5b561e
[CI] Update transport version definitions
184d49e
Merge branch 'main' into modernize_dls
joegallo 770a0df
Merge branch 'main' into modernize_dls
joegallo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
server/src/main/java/org/elasticsearch/common/lucene/search/BitsIterator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.common.lucene.search; | ||
|
|
||
| import org.apache.lucene.search.DocIdSetIterator; | ||
| import org.apache.lucene.util.Bits; | ||
| import org.apache.lucene.util.FixedBitSet; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * A {@link DocIdSetIterator} over set bits of a {@link Bits} instance. | ||
| */ | ||
| public final class BitsIterator extends DocIdSetIterator { | ||
|
|
||
| private static final int WINDOW_SIZE = 1024; | ||
|
|
||
| private final Bits bits; | ||
|
|
||
| private int doc = -1; | ||
| private final FixedBitSet bitSet; | ||
| private int from = 0; | ||
| private int to = 0; | ||
|
|
||
| public BitsIterator(Bits bits) { | ||
| this.bits = Objects.requireNonNull(bits); | ||
| // 1024 bits may sound heavy at first sight but it's only a long[16] under the hood | ||
| bitSet = new FixedBitSet(WINDOW_SIZE); | ||
| } | ||
|
|
||
| @Override | ||
| public int docID() { | ||
| return doc; | ||
| } | ||
|
|
||
| @Override | ||
| public int nextDoc() { | ||
| return advance(docID() + 1); | ||
| } | ||
|
|
||
| @Override | ||
| public int advance(int target) { | ||
| for (;;) { | ||
| if (target >= to) { | ||
| if (target >= bits.length()) { | ||
| return doc = NO_MORE_DOCS; | ||
| } | ||
| refill(target); | ||
| } | ||
|
|
||
| int next = bitSet.nextSetBit(target - from); | ||
| if (next != NO_MORE_DOCS) { | ||
| return doc = from + next; | ||
| } else { | ||
| target = to; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void refill(int target) { | ||
| assert target >= to; | ||
| from = target; | ||
| bitSet.set(0, bitSet.length()); | ||
| if (bits.length() - from < WINDOW_SIZE) { | ||
| to = bits.length(); | ||
| bitSet.clear(to - from, bitSet.length()); | ||
| } else { | ||
| to = from + WINDOW_SIZE; | ||
| } | ||
| bits.applyMask(bitSet, from); | ||
| } | ||
|
|
||
| @Override | ||
| public long cost() { | ||
| // We have no better estimate | ||
| return bits.length(); | ||
| } | ||
| } | ||
127 changes: 0 additions & 127 deletions
127
server/src/main/java/org/elasticsearch/lucene/util/CombinedBitSet.java
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
server/src/main/java/org/elasticsearch/lucene/util/CombinedBits.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.lucene.util; | ||
|
|
||
| import org.apache.lucene.util.Bits; | ||
| import org.apache.lucene.util.FixedBitSet; | ||
|
|
||
| /** | ||
| * A {@link Bits} implementation that combines two {@link Bits} instances by and-ing them to provide a single merged view. | ||
| */ | ||
| public final class CombinedBits implements Bits { | ||
| private final Bits first; | ||
| private final Bits second; | ||
| private final int length; | ||
|
|
||
| public CombinedBits(Bits first, Bits second) { | ||
| if (first.length() != second.length()) { | ||
| throw new IllegalArgumentException("Provided bits have different lengths: " + first.length() + " != " + second.length()); | ||
| } | ||
| this.first = first; | ||
| this.second = second; | ||
| this.length = first.length(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean get(int index) { | ||
| return first.get(index) && second.get(index); | ||
| } | ||
|
|
||
| @Override | ||
| public int length() { | ||
| return length; | ||
| } | ||
|
|
||
| @Override | ||
| public void applyMask(FixedBitSet bitSet, int offset) { | ||
| first.applyMask(bitSet, offset); | ||
| second.applyMask(bitSet, offset); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
server/src/test/java/org/elasticsearch/common/lucene/search/BitsIteratorTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.common.lucene.search; | ||
|
|
||
| import org.apache.lucene.search.DocIdSetIterator; | ||
| import org.apache.lucene.util.Bits; | ||
| import org.apache.lucene.util.FixedBitSet; | ||
| import org.elasticsearch.test.ESTestCase; | ||
|
|
||
| public class BitsIteratorTests extends ESTestCase { | ||
|
|
||
| public void testEmpty() { | ||
| Bits bits = new Bits.MatchNoBits(10_000); | ||
| BitsIterator iterator = new BitsIterator((bits)); | ||
| assertEquals(DocIdSetIterator.NO_MORE_DOCS, iterator.nextDoc()); | ||
| } | ||
|
|
||
| public void testSingleBit() { | ||
| FixedBitSet bits = new FixedBitSet(10_000); | ||
| bits.set(5000); | ||
|
|
||
| BitsIterator iterator = new BitsIterator((bits)); | ||
| assertEquals(5000, iterator.nextDoc()); | ||
| assertEquals(DocIdSetIterator.NO_MORE_DOCS, iterator.nextDoc()); | ||
|
|
||
| iterator = new BitsIterator((bits)); | ||
| assertEquals(5000, iterator.advance(5000)); | ||
|
|
||
| iterator = new BitsIterator((bits)); | ||
| assertEquals(DocIdSetIterator.NO_MORE_DOCS, iterator.advance(5001)); | ||
| } | ||
|
|
||
| public void testEverySecondBit() { | ||
| FixedBitSet bits = new FixedBitSet(10_000); | ||
| for (int i = 0; i < bits.length(); i += 2) { | ||
| bits.set(i); | ||
| } | ||
| BitsIterator iterator = new BitsIterator((bits)); | ||
| for (int i = 0; i < bits.length(); i += 2) { | ||
| assertEquals(i, iterator.nextDoc()); | ||
| } | ||
| assertEquals(DocIdSetIterator.NO_MORE_DOCS, iterator.nextDoc()); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason we use a mix of
WINDOW_SIZEandbitSet.length()?They should be the same, and it looks like the code relies on them being the same, but perhaps you had a deeper for reason mixing them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason! Let me use WINDOW_SIZE everywhere.