xiangfu0 commented on code in PR #20072:
URL: https://github.com/apache/pinot/pull/20072#discussion_r4655683889
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/vector/HnswVectorIndexCreator.java:
##########
@@ -100,32 +155,119 @@ public void add(Object[] values, @Nullable int[]
dictIds) {
@Override
public void add(float[] document) {
+ if (_bufferedVectors != null) {
+ // Callers may reuse the array for the next row
+ _bufferedVectors.add(document.clone());
+ if (_bufferedVectors.size() <= _parallelBuildMaxDocs) {
+ return;
+ }
+ for (float[] buffered : _bufferedVectors) {
+ addDocument(buffered, _nextDocId++);
+ }
+ _bufferedVectors = null;
+ return;
+ }
+ addDocument(document, _nextDocId++);
+ }
+
+ private Document toDocument(float[] vector, int docId) {
Document docToIndex = new Document();
- XKnnFloatVectorField xKnnFloatVectorField =
- new XKnnFloatVectorField(_vectorColumn, document,
_vectorSimilarityFunction);
- docToIndex.add(xKnnFloatVectorField);
- docToIndex.add(new StoredField(VECTOR_INDEX_DOC_ID_COLUMN_NAME,
_nextDocId++));
+ docToIndex.add(new XKnnFloatVectorField(_vectorColumn, vector,
_vectorSimilarityFunction));
+ docToIndex.add(new StoredField(VECTOR_INDEX_DOC_ID_COLUMN_NAME, docId));
+ return docToIndex;
+ }
+
+ private void addDocument(float[] vector, int docId) {
try {
- _indexWriter.addDocument(docToIndex);
+ _indexWriter.addDocument(toDocument(vector, docId));
} catch (Exception e) {
throw new RuntimeException(
"Caught exception while adding a new document to the HNSW index for
column: " + _vectorColumn, e);
}
}
+ /// Indexes the buffered vectors from `_buildThreads` threads, each a
contiguous range of doc ids written by its own
+ /// IndexWriter, so each graph is also finished (flushed) on its own thread;
the per-thread indexes are then attached
+ /// to the main index as separate Lucene segments without rebuilding them.
+ private void addBufferedInParallel()
+ throws Exception {
+ int numDocs = _bufferedVectors.size();
+ int numThreads = Math.min(_buildThreads, Math.max(1, numDocs));
+ ExecutorService executor = Executors.newFixedThreadPool(numThreads);
+ Directory[] partDirectories = new Directory[numThreads];
+ File[] partDirs = new File[numThreads];
+ try {
+ List<Future<?>> futures = new ArrayList<>(numThreads);
+ for (int t = 0; t < numThreads; t++) {
+ int from = (int) ((long) numDocs * t / numThreads);
+ int to = (int) ((long) numDocs * (t + 1) / numThreads);
+ partDirs[t] = new File(_segmentIndexDir, _vectorColumn + ".hnsw.part"
+ t);
+ partDirectories[t] = FSDirectory.open(partDirs[t].toPath());
+ Directory partDirectory = partDirectories[t];
+ futures.add(executor.submit(() -> {
+ // CREATE: a part directory left by a build that crashed before
cleaning up must not add its documents
+ try (IndexWriter partWriter = new IndexWriter(partDirectory,
+
VectorIndexUtils.getIndexWriterConfig(_vectorIndexConfig).setOpenMode(OpenMode.CREATE)))
{
Review Comment:
One more consequence of the same thread-limit issue shows up after the row
buffer fills. The main writer uses its regular Lucene merge policy on the
streaming path, and the concurrent codec currently supplies its executor for
every merge. Ordinary merges can therefore consume graph workers before seal.
I’m restricting concurrent graph construction to the final forced merge and
checking the ordinary-merge writer separately.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]