Skip to content
Merged
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 @@ -17,11 +17,16 @@
package org.apache.solr.update;

import java.io.IOException;
import java.util.stream.IntStream;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.document.StringField;
import org.apache.lucene.index.FilterLeafReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.LeafReader;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.core.SolrCore;
import org.apache.solr.util.RefCounted;
import org.junit.BeforeClass;
import org.junit.Test;

Expand All @@ -38,13 +43,23 @@ public void testSequentialVsParallelFingerprint() throws Exception {
SolrCore core = h.getCore();

int numDocs = RANDOM_MULTIPLIER == 1 ? 3 : 500;
// Create a set of many segments (to catch race conditions, i.e. SOLR-17863)
IntStream.range(0, numDocs)
.forEach(
i -> {
assertU(adoc("id", "" + i));
assertU(commit());
});
// Create a set of many segments (to catch race conditions, i.e. SOLR-17863).
// Write directly to the IndexWriter and flush after each doc to create one segment per doc,
// avoiding the overhead of opening a new searcher on every Solr commit.
RefCounted<IndexWriter> iwRef = core.getSolrCoreState().getIndexWriter(core);
try {
IndexWriter writer = iwRef.get();
for (int i = 0; i < numDocs; i++) {
Comment on lines +51 to +52
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
IndexWriter writer = iwRef.get();
for (int i = 0; i < numDocs; i++) {
IndexWriter writer = iwRef.get();
writer.getConfig().setMergePolicy(NoMergePolicy.INSTANCE);;
for (int i = 0; i < numDocs; i++) {

Should we add this NoMergePolicy? I know we used solrconfig-nomergepolicyfactory.xml for config but does this bypass that? I trust you that this probably still creates the segments without it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It respects it since we are still getting the IW from the core:

image

Document doc = new Document();
doc.add(new StringField("id", Integer.toString(i), Field.Store.YES));
doc.add(new NumericDocValuesField("_version_", i + 1));
writer.addDocument(doc);
writer.flush();
}
} finally {
iwRef.decref();
}
assertU(commit("openSearcher", "true"));

try (var searcher = core.getSearcher().get()) {
// Compute fingerprint sequentially to compare with parallel computation
Expand Down
Loading