2727import org .apache .lucene .codecs .lucene99 .Lucene99FlatVectorsWriter ;
2828import org .apache .lucene .index .SegmentReadState ;
2929import org .apache .lucene .index .SegmentWriteState ;
30- import org .apache .lucene .store .IOContext .FileOpenHint ;
30+ import org .apache .lucene .store .FlushInfo ;
31+ import org .apache .lucene .store .IOContext ;
32+ import org .apache .lucene .store .MergeInfo ;
3133
3234import java .io .IOException ;
35+ import java .util .Set ;
36+ import java .util .stream .Collectors ;
3337import java .util .stream .Stream ;
3438
3539/**
@@ -65,12 +69,11 @@ public FlatVectorsWriter fieldsWriter(SegmentWriteState state) throws IOExceptio
6569
6670 @ Override
6771 public FlatVectorsReader fieldsReader (SegmentReadState state ) throws IOException {
68- var newHints = Stream .concat (state .context .hints ().stream (), Stream .of (DirectIOHint .INSTANCE )).toArray (FileOpenHint []::new );
6972 SegmentReadState directIOState = new SegmentReadState (
7073 state .directory ,
7174 state .segmentInfo ,
7275 state .fieldInfos ,
73- state .context . withHints ( newHints ),
76+ new DirectIOContext ( state .context ),
7477 state .segmentSuffix
7578 );
7679 // Use mmap for merges and direct I/O for searches.
@@ -85,4 +88,40 @@ public FlatVectorsReader fieldsReader(SegmentReadState state) throws IOException
8588 public String toString () {
8689 return "Lucene99FlatVectorsFormat(" + "vectorsScorer=" + vectorsScorer + ')' ;
8790 }
91+
92+ static class DirectIOContext implements IOContext {
93+
94+ final IOContext delegate ;
95+ final Set <FileOpenHint > hints ;
96+
97+ DirectIOContext (IOContext delegate ) {
98+ this .delegate = delegate ;
99+ hints = Stream .concat (delegate .hints ().stream (), Stream .of (DirectIOHint .INSTANCE )).collect (Collectors .toSet ());
100+ }
101+
102+ @ Override
103+ public Context context () {
104+ return delegate .context ();
105+ }
106+
107+ @ Override
108+ public MergeInfo mergeInfo () {
109+ return delegate .mergeInfo ();
110+ }
111+
112+ @ Override
113+ public FlushInfo flushInfo () {
114+ return delegate .flushInfo ();
115+ }
116+
117+ @ Override
118+ public Set <FileOpenHint > hints () {
119+ return hints ;
120+ }
121+
122+ @ Override
123+ public IOContext withHints (FileOpenHint ... hints ) {
124+ return delegate .withHints (hints ); // TODO: keep the directIO or drop it ?
125+ }
126+ }
88127}
0 commit comments