Skip to content

Commit a6db01a

Browse files
committed
Remove ConcurrentHnswMerger and related classes / params
1 parent 97d993c commit a6db01a

File tree

8 files changed

+9
-464
lines changed

8 files changed

+9
-464
lines changed

server/src/main/java/org/elasticsearch/index/codec/vectors/ES814HnswScalarQuantizedVectorsFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public ES814HnswScalarQuantizedVectorsFormat(int maxConn, int beamWidth, Float c
6161

6262
@Override
6363
public KnnVectorsWriter fieldsWriter(SegmentWriteState state) throws IOException {
64-
return new ES910HnswVectorsWriter(state, maxConn, beamWidth, flatVectorsFormat.fieldsWriter(state), 1, null);
64+
return new ES910HnswVectorsWriter(state, maxConn, beamWidth, flatVectorsFormat.fieldsWriter(state));
6565
}
6666

6767
@Override

server/src/main/java/org/elasticsearch/index/codec/vectors/ES815HnswBitVectorsFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public ES815HnswBitVectorsFormat(int maxConn, int beamWidth) {
5656

5757
@Override
5858
public KnnVectorsWriter fieldsWriter(SegmentWriteState state) throws IOException {
59-
return new ES910HnswVectorsWriter(state, maxConn, beamWidth, flatVectorsFormat.fieldsWriter(state), 1, null);
59+
return new ES910HnswVectorsWriter(state, maxConn, beamWidth, flatVectorsFormat.fieldsWriter(state));
6060
}
6161

6262
@Override

server/src/main/java/org/elasticsearch/index/codec/vectors/es818/ES818HnswBinaryQuantizedVectorsFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public ES818HnswBinaryQuantizedVectorsFormat(int maxConn, int beamWidth, int num
119119

120120
@Override
121121
public KnnVectorsWriter fieldsWriter(SegmentWriteState state) throws IOException {
122-
return new ES910HnswVectorsWriter(state, maxConn, beamWidth, flatVectorsFormat.fieldsWriter(state), numMergeWorkers, mergeExec);
122+
return new ES910HnswVectorsWriter(state, maxConn, beamWidth, flatVectorsFormat.fieldsWriter(state));
123123
}
124124

125125
@Override

server/src/main/java/org/elasticsearch/index/codec/vectors/es910/ES910HnswVectorsFormat.java

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,14 @@
2828
import org.apache.lucene.codecs.lucene99.Lucene99FlatVectorsFormat;
2929
import org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsFormat;
3030
import org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsReader;
31-
import org.apache.lucene.index.MergePolicy;
32-
import org.apache.lucene.index.MergeScheduler;
3331
import org.apache.lucene.index.SegmentReadState;
3432
import org.apache.lucene.index.SegmentWriteState;
35-
import org.apache.lucene.search.TaskExecutor;
3633
import org.apache.lucene.util.hnsw.HnswGraph;
3734

3835
import java.io.IOException;
39-
import java.util.concurrent.ExecutorService;
4036

4137
import static org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsFormat.DEFAULT_BEAM_WIDTH;
4238
import static org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsFormat.DEFAULT_MAX_CONN;
43-
import static org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsFormat.DEFAULT_NUM_MERGE_WORKER;
4439
import static org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsFormat.MAXIMUM_BEAM_WIDTH;
4540
import static org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsFormat.MAXIMUM_MAX_CONN;
4641

@@ -75,12 +70,9 @@ public class ES910HnswVectorsFormat extends KnnVectorsFormat {
7570
FlatVectorScorerUtil.getLucene99FlatVectorsScorer()
7671
);
7772

78-
private final int numMergeWorkers;
79-
private final TaskExecutor mergeExec;
80-
8173
/** Constructs a format using default graph construction parameters */
8274
public ES910HnswVectorsFormat() {
83-
this(DEFAULT_MAX_CONN, DEFAULT_BEAM_WIDTH, DEFAULT_NUM_MERGE_WORKER, null);
75+
this(DEFAULT_MAX_CONN, DEFAULT_BEAM_WIDTH);
8476
}
8577

8678
/**
@@ -90,21 +82,6 @@ public ES910HnswVectorsFormat() {
9082
* @param beamWidth the size of the queue maintained during graph construction.
9183
*/
9284
public ES910HnswVectorsFormat(int maxConn, int beamWidth) {
93-
this(maxConn, beamWidth, DEFAULT_NUM_MERGE_WORKER, null);
94-
}
95-
96-
/**
97-
* Constructs a format using the given graph construction parameters and scalar quantization.
98-
*
99-
* @param maxConn the maximum number of connections to a node in the HNSW graph
100-
* @param beamWidth the size of the queue maintained during graph construction.
101-
* @param numMergeWorkers number of workers (threads) that will be used when doing merge. If
102-
* larger than 1, a non-null {@link ExecutorService} must be passed as mergeExec
103-
* @param mergeExec the {@link ExecutorService} that will be used by ALL vector writers that are
104-
* generated by this format to do the merge. If null, the configured {@link
105-
* MergeScheduler#getIntraMergeExecutor(MergePolicy.OneMerge)} is used.
106-
*/
107-
public ES910HnswVectorsFormat(int maxConn, int beamWidth, int numMergeWorkers, ExecutorService mergeExec) {
10885
super(ES910HnswVectorsFormat.NAME);
10986
if (maxConn <= 0 || maxConn > MAXIMUM_MAX_CONN) {
11087
throw new IllegalArgumentException(
@@ -118,20 +95,11 @@ public ES910HnswVectorsFormat(int maxConn, int beamWidth, int numMergeWorkers, E
11895
}
11996
this.maxConn = maxConn;
12097
this.beamWidth = beamWidth;
121-
if (numMergeWorkers == 1 && mergeExec != null) {
122-
throw new IllegalArgumentException("No executor service is needed as we'll use single thread to merge");
123-
}
124-
this.numMergeWorkers = numMergeWorkers;
125-
if (mergeExec != null) {
126-
this.mergeExec = new TaskExecutor(mergeExec);
127-
} else {
128-
this.mergeExec = null;
129-
}
13098
}
13199

132100
@Override
133101
public KnnVectorsWriter fieldsWriter(SegmentWriteState state) throws IOException {
134-
return new ES910HnswVectorsWriter(state, maxConn, beamWidth, flatVectorsFormat.fieldsWriter(state), numMergeWorkers, mergeExec);
102+
return new ES910HnswVectorsWriter(state, maxConn, beamWidth, flatVectorsFormat.fieldsWriter(state));
135103
}
136104

137105
@Override

server/src/main/java/org/elasticsearch/index/codec/vectors/es910/ES910HnswVectorsWriter.java

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.apache.lucene.index.SegmentWriteState;
3737
import org.apache.lucene.index.Sorter;
3838
import org.apache.lucene.index.VectorSimilarityFunction;
39-
import org.apache.lucene.search.TaskExecutor;
4039
import org.apache.lucene.store.IndexOutput;
4140
import org.apache.lucene.util.IOUtils;
4241
import org.apache.lucene.util.InfoStream;
@@ -46,7 +45,6 @@
4645
import org.apache.lucene.util.hnsw.RandomVectorScorerSupplier;
4746
import org.apache.lucene.util.hnsw.UpdateableRandomVectorScorer;
4847
import org.apache.lucene.util.packed.DirectMonotonicWriter;
49-
import org.elasticsearch.index.codec.vectors.es910.hnsw.ConcurrentHnswMerger;
5048
import org.elasticsearch.index.codec.vectors.es910.hnsw.HnswGraph;
5149
import org.elasticsearch.index.codec.vectors.es910.hnsw.HnswGraphBuilder;
5250
import org.elasticsearch.index.codec.vectors.es910.hnsw.HnswGraphMerger;
@@ -76,25 +74,14 @@ public class ES910HnswVectorsWriter extends KnnVectorsWriter {
7674
private final int M;
7775
private final int beamWidth;
7876
private final FlatVectorsWriter flatVectorWriter;
79-
private final int numMergeWorkers;
80-
private final TaskExecutor mergeExec;
8177

8278
private final List<ES910HnswVectorsWriter.FieldWriter<?>> fields = new ArrayList<>();
8379
private boolean finished;
8480

85-
public ES910HnswVectorsWriter(
86-
SegmentWriteState state,
87-
int M,
88-
int beamWidth,
89-
FlatVectorsWriter flatVectorWriter,
90-
int numMergeWorkers,
91-
TaskExecutor mergeExec
92-
) throws IOException {
81+
public ES910HnswVectorsWriter(SegmentWriteState state, int M, int beamWidth, FlatVectorsWriter flatVectorWriter) throws IOException {
9382
this.M = M;
9483
this.flatVectorWriter = flatVectorWriter;
9584
this.beamWidth = beamWidth;
96-
this.numMergeWorkers = numMergeWorkers;
97-
this.mergeExec = mergeExec;
9885
segmentWriteState = state;
9986

10087
String metaFileName = IndexFileNames.segmentFileName(
@@ -367,12 +354,7 @@ public void mergeOneField(FieldInfo fieldInfo, MergeState mergeState) throws IOE
367354
int[][] vectorIndexNodeOffsets = null;
368355
if (scorerSupplier.totalVectorCount() > 0) {
369356
// build graph
370-
HnswGraphMerger merger = createGraphMerger(
371-
fieldInfo,
372-
scorerSupplier,
373-
mergeState.intraMergeTaskExecutor == null ? null : new TaskExecutor(mergeState.intraMergeTaskExecutor),
374-
numMergeWorkers
375-
);
357+
HnswGraphMerger merger = createGraphMerger(fieldInfo, scorerSupplier);
376358
for (int i = 0; i < mergeState.liveDocs.length; i++) {
377359
if (hasVectorValues(mergeState.fieldInfos[i], fieldInfo.name)) {
378360
merger.addReader(mergeState.knnVectorsReaders[i], mergeState.docMaps[i], mergeState.liveDocs[i]);
@@ -508,18 +490,7 @@ private void writeMeta(
508490
}
509491
}
510492

511-
private HnswGraphMerger createGraphMerger(
512-
FieldInfo fieldInfo,
513-
RandomVectorScorerSupplier scorerSupplier,
514-
TaskExecutor parallelMergeTaskExecutor,
515-
int numParallelMergeWorkers
516-
) {
517-
if (mergeExec != null) {
518-
return new ConcurrentHnswMerger(fieldInfo, scorerSupplier, M, beamWidth, mergeExec, numMergeWorkers);
519-
}
520-
if (parallelMergeTaskExecutor != null && numParallelMergeWorkers > 1) {
521-
return new ConcurrentHnswMerger(fieldInfo, scorerSupplier, M, beamWidth, parallelMergeTaskExecutor, numParallelMergeWorkers);
522-
}
493+
private HnswGraphMerger createGraphMerger(FieldInfo fieldInfo, RandomVectorScorerSupplier scorerSupplier) {
523494
return new IncrementalHnswGraphMerger(fieldInfo, scorerSupplier, M, beamWidth);
524495
}
525496

server/src/main/java/org/elasticsearch/index/codec/vectors/es910/hnsw/ConcurrentHnswMerger.java

Lines changed: 0 additions & 140 deletions
This file was deleted.

0 commit comments

Comments
 (0)