thecoop commented on code in PR #16905:
URL: https://github.com/apache/lucene/pull/16905#discussion_r4376499650
##########
lucene/core/src/java/org/apache/lucene/codecs/lucene99/Lucene99FlatVectorsReader.java:
##########
@@ -212,40 +215,44 @@ public void checkIntegrity(MergePolicy.OneMerge merge)
throws IOException {
@Override
public FlatVectorsReader getMergeInstance() throws IOException {
- IndexInput data = original.sequentialVectorData();
+ IndexInput data =
original.vectorDataFor(IOContext.merge().withHints(sequentialHints()));
return data == vectorData ? this : new Lucene99FlatVectorsReader(this,
data.clone());
}
- /** Returns the input for sequential reads, opening the data file again if
needed. */
- private synchronized IndexInput sequentialVectorData() throws IOException {
+ /** Returns an input efficient for {@code context}, opening the data file
again if none is. */
+ private synchronized IndexInput vectorDataFor(IOContext context) throws
IOException {
assert original == this;
if (closed) {
throw new AlreadyClosedException("this reader is closed");
}
- if (sequentialVectorData == null) {
- IOContext sequential = sequentialContext();
- if (vectorData.isEfficientFor(sequential)) {
- sequentialVectorData = vectorData;
- } else {
- try {
- sequentialVectorData = directory.openInput(vectorDataFN, sequential);
- } catch (FileNotFoundException | NoSuchFileException _) {
- // an open reader outlives its files, so read through the input it
already holds
- sequentialVectorData = vectorData;
- }
+ if (vectorData.isEfficientFor(context)) {
+ return vectorData;
+ }
+ IndexInput data = otherVectorData.get(context);
+ if (data != null) {
+ return data;
+ }
+ for (IndexInput other : otherVectorData.values()) {
+ if (other.isEfficientFor(context)) {
+ return other;
}
}
- return sequentialVectorData;
+ try {
+ data = directory.openInput(vectorDataFN, context);
+ } catch (FileNotFoundException | NoSuchFileException _) {
+ // an open reader outlives its files, so read through the input it
already holds
+ data = vectorData;
+ }
+ otherVectorData.put(context, data);
+ return data;
}
- /** Returns the context of the data file with sequential access. */
- private IOContext sequentialContext() {
- return dataContext.withHints(
- Stream.concat(
- dataContext.hints().stream()
- .filter(hint -> hint instanceof DataAccessHint == false),
- Stream.of(DataAccessHint.SEQUENTIAL))
- .toArray(IOContext.FileOpenHint[]::new));
+ /** Returns the hints of the data file with sequential access. */
+ private IOContext.FileOpenHint[] sequentialHints() {
+ return Stream.concat(
+ dataContext.hints().stream().filter(hint -> hint instanceof
DataAccessHint == false),
Review Comment:
You can use the new method on `IOContext` here
--
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]