Skip to content
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

Validate FieldInfos count in close in Lucene tests #3006

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,13 @@ public void testExceptionOnCloseInput() throws Exception {
public void testExceptionOnOpenInput() throws Exception {
super.testExceptionOnOpenInput();
}

@Override
public void testRandom() throws Exception {
// https://github.com/FoundationDB/fdb-record-layer/issues/3005
// It may write a value that is too large, and will fail when trying to read it back out.
// Note that because we don't commit, it won't fail on the write, it will fail on the read.
TestFDBDirectory.disableFieldInfosCountCheck();
super.testRandom();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class TestFDBDirectory extends FDBDirectory {
private static final LuceneOptimizedFieldInfosFormat FIELD_INFOS_FORMAT = new LuceneOptimizedFieldInfosFormat();
private static boolean fullBufferToSurviveDeletes;
private static boolean allowAddIndexes;
private static boolean calledAddIndexes;

private static final AtomicReference<NonnullPair<String, FieldInfos>> previousFieldInfos = new AtomicReference<>();
private static final AtomicReference<NonnullPair<String, Map<Long, byte[]>>> previousStoredFields = new AtomicReference<>();
Expand All @@ -67,6 +68,7 @@ public class TestFDBDirectory extends FDBDirectory {
* indicate that {@code addIndexes} is being called.
*/
private static boolean blockAddIndexes = true;
private static boolean disableFieldInfosCountCheck;

public TestFDBDirectory() {
super(new Subspace(Tuple.from("record-test", "unit", "lucene")),
Expand Down Expand Up @@ -126,10 +128,16 @@ public static void allowAddIndexes() {
public static void reset() {
fullBufferToSurviveDeletes = false;
allowAddIndexes = false;
calledAddIndexes = false;
disableFieldInfosCountCheck = false;
previousFieldInfos.set(null);
previousStoredFields.set(null);
}

public static void disableFieldInfosCountCheck() {
disableFieldInfosCountCheck = true;
}

@Nonnull
@Override
public IndexInput openInput(@Nonnull final String name, @Nonnull final IOContext ioContext) throws IOException {
Expand Down Expand Up @@ -207,11 +215,21 @@ public void close() throws IOException {
previousStoredFields.compareAndSet(previous, null);
return indexOutput;
}
calledAddIndexes = true;
}
}
return indexOutput;
}

@Override
public void close() throws IOException {
if (!calledAddIndexes && !disableFieldInfosCountCheck) {
assertThat(asyncToSync(LuceneEvents.Waits.WAIT_LUCENE_READ_FIELD_INFOS, getFieldInfosCount()),
Matchers.lessThanOrEqualTo(1));
}
super.close();
}

private static boolean isStacktraceCopySegmentAsIs() {
return Arrays.stream(Thread.currentThread().getStackTrace()).anyMatch(element ->
element.getClassName().equals(IndexWriter.class.getName()) &&
Expand Down