Skip to content

Copy Lucene99FlatVectorsReader allowing direct IO to be specified directly #125921

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

Merged
merged 24 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a9be5ea
Copy Lucene99FlatVectorsReader allowing direct IO to be specified dir…
thecoop Mar 31, 2025
359fe69
Merge branch 'main' into modified-flat-vector-direct-io
thecoop Mar 31, 2025
991dd6d
Use DirectIODirectory implementation
thecoop Mar 31, 2025
a2ed4c8
Add entitlement
thecoop Mar 31, 2025
08d2a76
Sometimes DirectIO is not available
thecoop Mar 31, 2025
9294c04
Allow for subpaths
thecoop Mar 31, 2025
e2f3693
Specify buffer size
thecoop Apr 4, 2025
446caf8
Merge branch 'main' into modified-flat-vector-direct-io
thecoop Apr 8, 2025
b0325ce
Only use direct IO in searches
thecoop Apr 14, 2025
dd3300f
Merge branch 'main' into modified-flat-vector-direct-io
thecoop Apr 14, 2025
00682ca
Update copyright year and comments
thecoop Apr 14, 2025
b51548b
Update comment
thecoop Apr 15, 2025
30092c8
Merge remote-tracking branch 'upstream/main' into modified-flat-vecto…
thecoop Apr 15, 2025
9c86a05
Merge branch 'main' into modified-flat-vector-direct-io
thecoop Apr 16, 2025
22f740d
Use a system property to turn off direct IO if needed
thecoop Apr 16, 2025
e258015
Merge branch 'main' into modified-flat-vector-direct-io
thecoop Apr 16, 2025
2b8d4fd
Merge branch 'main' into modified-flat-vector-direct-io
thecoop Apr 17, 2025
c7149ff
Tweak the names
thecoop Apr 17, 2025
94dbac0
Add comment
thecoop Apr 17, 2025
521245e
Merge remote-tracking branch 'upstream/main' into modified-flat-vecto…
thecoop Apr 17, 2025
b8b714a
Merge branch 'main' into modified-flat-vector-direct-io
thecoop Apr 23, 2025
93a9bdb
Merge branch 'main' into modified-flat-vector-direct-io
thecoop Apr 23, 2025
27c96b3
Merge branch 'main' into modified-flat-vector-direct-io
thecoop Apr 24, 2025
3f90ea5
Add conditions for new reader
thecoop Apr 24, 2025
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 @@ -279,7 +279,10 @@ private static PolicyManager createPolicyManager() {
new FilesEntitlement(List.of(FileData.ofBaseDirPath(CONFIG, READ), FileData.ofBaseDirPath(DATA, READ_WRITE)))
)
),
new Scope("org.apache.lucene.misc", List.of(new FilesEntitlement(List.of(FileData.ofBaseDirPath(DATA, READ_WRITE))))),
new Scope(
"org.apache.lucene.misc",
List.of(new FilesEntitlement(List.of(FileData.ofBaseDirPath(DATA, READ_WRITE))), new ReadStoreAttributesEntitlement())
),
new Scope(
"org.apache.logging.log4j.core",
List.of(new ManageThreadsEntitlement(), new FilesEntitlement(List.of(FileData.ofBaseDirPath(LOGS, READ_WRITE))))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

package org.elasticsearch.index.codec.vectors.es818;

import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;

import java.io.IOException;

/**
* A hook for {@link DirectIOLucene99FlatVectorsReader} to specify the input should be opened using DirectIO.
* Remove when IOContext allows more extensible payloads to be specified.
*/
public interface DirectIOIndexInputSupplier {
IndexInput openInputDirect(String name, IOContext context) throws IOException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* @notice
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Modifications copyright (C) 2024 Elasticsearch B.V.
*/
package org.elasticsearch.index.codec.vectors.es818;

import org.apache.lucene.codecs.hnsw.FlatVectorsFormat;
import org.apache.lucene.codecs.hnsw.FlatVectorsReader;
import org.apache.lucene.codecs.hnsw.FlatVectorsScorer;
import org.apache.lucene.codecs.hnsw.FlatVectorsWriter;
import org.apache.lucene.codecs.lucene99.Lucene99FlatVectorsWriter;
import org.apache.lucene.index.SegmentReadState;
import org.apache.lucene.index.SegmentWriteState;

import java.io.IOException;

/**
* Copied from Lucene99FlatVectorsFormat in Lucene 10.1
*
* This is copied to change the implementation of {@link #fieldsReader} only.
* The codec format itself is not changed, so we keep the original {@link #NAME}
*/
public class DirectIOLucene99FlatVectorsFormat extends FlatVectorsFormat {

static final String NAME = "Lucene99FlatVectorsFormat";
static final String META_CODEC_NAME = "Lucene99FlatVectorsFormatMeta";
static final String VECTOR_DATA_CODEC_NAME = "Lucene99FlatVectorsFormatData";
static final String META_EXTENSION = "vemf";
static final String VECTOR_DATA_EXTENSION = "vec";

public static final int VERSION_START = 0;
public static final int VERSION_CURRENT = VERSION_START;

static final int DIRECT_MONOTONIC_BLOCK_SHIFT = 16;
private final FlatVectorsScorer vectorsScorer;

/** Constructs a format */
public DirectIOLucene99FlatVectorsFormat(FlatVectorsScorer vectorsScorer) {
super(NAME);
this.vectorsScorer = vectorsScorer;
}

@Override
public FlatVectorsWriter fieldsWriter(SegmentWriteState state) throws IOException {
return new Lucene99FlatVectorsWriter(state, vectorsScorer);
}

@Override
public FlatVectorsReader fieldsReader(SegmentReadState state) throws IOException {
return new DirectIOLucene99FlatVectorsReader(state, vectorsScorer);
}

@Override
public String toString() {
return "ES818FlatVectorsFormat(" + "vectorsScorer=" + vectorsScorer + ')';
}
}
Loading