Push and pop OutputAccumulator as IntersectTermsEnumFrames are pushed and popped (#12900)

This commit is contained in:
gf2121 2023-12-12 20:26:02 +08:00 committed by GitHub
parent cf13a92950
commit 05b14e23b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 11 deletions

View File

@ -128,7 +128,6 @@ import org.apache.lucene.util.InfoStream;
import org.apache.lucene.util.Version; import org.apache.lucene.util.Version;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Ignore;
/* /*
Verify we can read previous versions' indexes, do searches Verify we can read previous versions' indexes, do searches
@ -2245,7 +2244,6 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
// #12895: test on a carefully crafted 9.8.0 index (from a small contiguous subset // #12895: test on a carefully crafted 9.8.0 index (from a small contiguous subset
// of wikibigall unique terms) that shows the read-time exception of // of wikibigall unique terms) that shows the read-time exception of
// IntersectTermsEnum (used by WildcardQuery) // IntersectTermsEnum (used by WildcardQuery)
@Ignore("re-enable once we merge #12900")
public void testWildcardQueryExceptions990() throws IOException { public void testWildcardQueryExceptions990() throws IOException {
Path path = createTempDir("12895"); Path path = createTempDir("12895");

View File

@ -120,6 +120,8 @@ final class IntersectTermsEnum extends BaseTermsEnum {
assert setSavedStartTerm(startTerm); assert setSavedStartTerm(startTerm);
currentFrame = f; currentFrame = f;
outputAccumulator.push(currentFrame.arc.output());
if (startTerm != null) { if (startTerm != null) {
seekToStartTerm(startTerm); seekToStartTerm(startTerm);
} }
@ -184,8 +186,7 @@ final class IntersectTermsEnum extends BaseTermsEnum {
int idx = currentFrame.prefix; int idx = currentFrame.prefix;
assert currentFrame.suffix > 0; assert currentFrame.suffix > 0;
outputAccumulator.reset(); int initOutputCount = outputAccumulator.outputCount();
outputAccumulator.push(arc.output());
while (idx < f.prefix) { while (idx < f.prefix) {
final int target = term.bytes[idx] & 0xff; final int target = term.bytes[idx] & 0xff;
// TODO: we could be more efficient for the next() // TODO: we could be more efficient for the next()
@ -198,9 +199,11 @@ final class IntersectTermsEnum extends BaseTermsEnum {
} }
f.arc = arc; f.arc = arc;
f.outputNum = outputAccumulator.outputCount() - initOutputCount;
assert arc.isFinal(); assert arc.isFinal();
outputAccumulator.push(arc.nextFinalOutput()); outputAccumulator.push(arc.nextFinalOutput());
f.load(outputAccumulator); f.load(outputAccumulator);
outputAccumulator.pop(arc.nextFinalOutput());
return f; return f;
} }
@ -343,6 +346,7 @@ final class IntersectTermsEnum extends BaseTermsEnum {
throw NoMoreTermsException.INSTANCE; throw NoMoreTermsException.INSTANCE;
} }
final long lastFP = currentFrame.fpOrig; final long lastFP = currentFrame.fpOrig;
outputAccumulator.pop(currentFrame.outputNum);
currentFrame = stack[currentFrame.ord - 1]; currentFrame = stack[currentFrame.ord - 1];
currentTransition = currentFrame.transition; currentTransition = currentFrame.transition;
assert currentFrame.lastSubFP == lastFP; assert currentFrame.lastSubFP == lastFP;
@ -429,6 +433,7 @@ final class IntersectTermsEnum extends BaseTermsEnum {
currentFrame = null; currentFrame = null;
return null; return null;
} }
outputAccumulator.pop(currentFrame.outputNum);
currentFrame = stack[currentFrame.ord - 1]; currentFrame = stack[currentFrame.ord - 1];
currentTransition = currentFrame.transition; currentTransition = currentFrame.transition;
isSubBlock = popPushNext(); isSubBlock = popPushNext();

View File

@ -89,6 +89,8 @@ final class IntersectTermsEnumFrame {
final ByteArrayDataInput bytesReader = new ByteArrayDataInput(); final ByteArrayDataInput bytesReader = new ByteArrayDataInput();
int outputNum;
int startBytePos; int startBytePos;
int suffix; int suffix;

View File

@ -495,7 +495,7 @@ final class SegmentTermsEnum extends BaseTermsEnum {
targetUpto = 0; targetUpto = 0;
outputAccumulator.push(arc.nextFinalOutput()); outputAccumulator.push(arc.nextFinalOutput());
currentFrame = pushFrame(arc, 0); currentFrame = pushFrame(arc, 0);
outputAccumulator.pop(); outputAccumulator.pop(arc.nextFinalOutput());
} }
// if (DEBUG) { // if (DEBUG) {
@ -569,7 +569,7 @@ final class SegmentTermsEnum extends BaseTermsEnum {
// if (DEBUG) System.out.println(" arc is final!"); // if (DEBUG) System.out.println(" arc is final!");
outputAccumulator.push(arc.nextFinalOutput()); outputAccumulator.push(arc.nextFinalOutput());
currentFrame = pushFrame(arc, targetUpto); currentFrame = pushFrame(arc, targetUpto);
outputAccumulator.pop(); outputAccumulator.pop(arc.nextFinalOutput());
// if (DEBUG) System.out.println(" curFrame.ord=" + currentFrame.ord + " hasTerms=" + // if (DEBUG) System.out.println(" curFrame.ord=" + currentFrame.ord + " hasTerms=" +
// currentFrame.hasTerms); // currentFrame.hasTerms);
} }
@ -767,7 +767,7 @@ final class SegmentTermsEnum extends BaseTermsEnum {
targetUpto = 0; targetUpto = 0;
outputAccumulator.push(arc.nextFinalOutput()); outputAccumulator.push(arc.nextFinalOutput());
currentFrame = pushFrame(arc, 0); currentFrame = pushFrame(arc, 0);
outputAccumulator.pop(); outputAccumulator.pop(arc.nextFinalOutput());
} }
// if (DEBUG) { // if (DEBUG) {
@ -841,7 +841,7 @@ final class SegmentTermsEnum extends BaseTermsEnum {
// if (DEBUG) System.out.println(" arc is final!"); // if (DEBUG) System.out.println(" arc is final!");
outputAccumulator.push(arc.nextFinalOutput()); outputAccumulator.push(arc.nextFinalOutput());
currentFrame = pushFrame(arc, targetUpto); currentFrame = pushFrame(arc, targetUpto);
outputAccumulator.pop(); outputAccumulator.pop(arc.nextFinalOutput());
// if (DEBUG) System.out.println(" curFrame.ord=" + currentFrame.ord + " hasTerms=" + // if (DEBUG) System.out.println(" curFrame.ord=" + currentFrame.ord + " hasTerms=" +
// currentFrame.hasTerms); // currentFrame.hasTerms);
} }
@ -1187,15 +1187,28 @@ final class SegmentTermsEnum extends BaseTermsEnum {
void push(BytesRef output) { void push(BytesRef output) {
if (output != Lucene90BlockTreeTermsReader.NO_OUTPUT) { if (output != Lucene90BlockTreeTermsReader.NO_OUTPUT) {
assert output.length > 0;
outputs = ArrayUtil.grow(outputs, num + 1); outputs = ArrayUtil.grow(outputs, num + 1);
outputs[num++] = output; outputs[num++] = output;
} }
} }
void pop() { void pop(BytesRef output) {
if (output != Lucene90BlockTreeTermsReader.NO_OUTPUT) {
assert num > 0; assert num > 0;
assert outputs[num - 1] == output;
num--; num--;
} }
}
void pop(int cnt) {
assert num >= cnt;
num -= cnt;
}
int outputCount() {
return num;
}
void reset() { void reset() {
num = 0; num = 0;