|
35 | 35 | import org.apache.lucene.index.KnnVectorValues; |
36 | 36 | import org.apache.lucene.index.LeafReader; |
37 | 37 | import org.apache.lucene.index.VectorSimilarityFunction; |
| 38 | +import org.apache.lucene.misc.store.DirectIODirectory; |
38 | 39 | import org.apache.lucene.search.IndexSearcher; |
39 | 40 | import org.apache.lucene.search.KnnFloatVectorQuery; |
40 | 41 | import org.apache.lucene.search.Query; |
41 | 42 | import org.apache.lucene.search.TopDocs; |
42 | 43 | import org.apache.lucene.search.TotalHits; |
43 | 44 | import org.apache.lucene.store.Directory; |
| 45 | +import org.apache.lucene.store.FSDirectory; |
| 46 | +import org.apache.lucene.store.IOContext; |
| 47 | +import org.apache.lucene.store.IndexOutput; |
44 | 48 | import org.apache.lucene.store.MMapDirectory; |
45 | 49 | import org.apache.lucene.tests.index.BaseKnnVectorsFormatTestCase; |
46 | 50 | import org.apache.lucene.tests.store.MockDirectoryWrapper; |
|
61 | 65 | import java.nio.file.Files; |
62 | 66 | import java.nio.file.Path; |
63 | 67 | import java.util.Locale; |
| 68 | +import java.util.OptionalLong; |
64 | 69 |
|
65 | 70 | import static java.lang.String.format; |
66 | 71 | import static org.apache.lucene.index.VectorSimilarityFunction.DOT_PRODUCT; |
@@ -200,6 +205,7 @@ public void testSimpleOffHeapSize() throws IOException { |
200 | 205 | } |
201 | 206 |
|
202 | 207 | public void testSimpleOffHeapSizeFSDir() throws IOException { |
| 208 | + checkDirectIOSupported(); |
203 | 209 | var config = newIndexWriterConfig().setUseCompoundFile(false); // avoid compound files to allow directIO |
204 | 210 | try (Directory dir = newFSDirectory()) { |
205 | 211 | testSimpleOffHeapSizeImpl(dir, config, false); |
@@ -260,4 +266,22 @@ private Directory newFSDirectory() throws IOException { |
260 | 266 | } |
261 | 267 | return dir; |
262 | 268 | } |
| 269 | + |
| 270 | + static void checkDirectIOSupported() { |
| 271 | + Path path = createTempDir("directIOProbe"); |
| 272 | + try (Directory dir = open(path); IndexOutput out = dir.createOutput("out", IOContext.DEFAULT)) { |
| 273 | + out.writeString("test"); |
| 274 | + } catch (IOException e) { |
| 275 | + assumeNoException("test requires a filesystem that supports Direct IO", e); |
| 276 | + } |
| 277 | + } |
| 278 | + |
| 279 | + static DirectIODirectory open(Path path) throws IOException { |
| 280 | + return new DirectIODirectory(FSDirectory.open(path)) { |
| 281 | + @Override |
| 282 | + protected boolean useDirectIO(String name, IOContext context, OptionalLong fileLength) { |
| 283 | + return true; |
| 284 | + } |
| 285 | + }; |
| 286 | + } |
263 | 287 | } |
0 commit comments