Skip to content

Commit 1110754

Browse files
committed
check supported
1 parent 7fea847 commit 1110754

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

server/src/test/java/org/elasticsearch/index/codec/vectors/es818/ES818BinaryQuantizedVectorsFormatTests.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@
3535
import org.apache.lucene.index.KnnVectorValues;
3636
import org.apache.lucene.index.LeafReader;
3737
import org.apache.lucene.index.VectorSimilarityFunction;
38+
import org.apache.lucene.misc.store.DirectIODirectory;
3839
import org.apache.lucene.search.IndexSearcher;
3940
import org.apache.lucene.search.KnnFloatVectorQuery;
4041
import org.apache.lucene.search.Query;
4142
import org.apache.lucene.search.TopDocs;
4243
import org.apache.lucene.search.TotalHits;
4344
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;
4448
import org.apache.lucene.store.MMapDirectory;
4549
import org.apache.lucene.tests.index.BaseKnnVectorsFormatTestCase;
4650
import org.apache.lucene.tests.store.MockDirectoryWrapper;
@@ -61,6 +65,7 @@
6165
import java.nio.file.Files;
6266
import java.nio.file.Path;
6367
import java.util.Locale;
68+
import java.util.OptionalLong;
6469

6570
import static java.lang.String.format;
6671
import static org.apache.lucene.index.VectorSimilarityFunction.DOT_PRODUCT;
@@ -200,6 +205,7 @@ public void testSimpleOffHeapSize() throws IOException {
200205
}
201206

202207
public void testSimpleOffHeapSizeFSDir() throws IOException {
208+
checkDirectIOSupported();
203209
var config = newIndexWriterConfig().setUseCompoundFile(false); // avoid compound files to allow directIO
204210
try (Directory dir = newFSDirectory()) {
205211
testSimpleOffHeapSizeImpl(dir, config, false);
@@ -260,4 +266,22 @@ private Directory newFSDirectory() throws IOException {
260266
}
261267
return dir;
262268
}
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+
}
263287
}

server/src/test/java/org/elasticsearch/index/codec/vectors/es818/ES818HnswBinaryQuantizedVectorsFormatTests.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@
3636
import org.apache.lucene.index.KnnVectorValues;
3737
import org.apache.lucene.index.LeafReader;
3838
import org.apache.lucene.index.VectorSimilarityFunction;
39+
import org.apache.lucene.misc.store.DirectIODirectory;
3940
import org.apache.lucene.search.TopDocs;
4041
import org.apache.lucene.store.Directory;
42+
import org.apache.lucene.store.FSDirectory;
43+
import org.apache.lucene.store.IOContext;
44+
import org.apache.lucene.store.IndexOutput;
4145
import org.apache.lucene.store.MMapDirectory;
4246
import org.apache.lucene.tests.index.BaseKnnVectorsFormatTestCase;
4347
import org.apache.lucene.tests.store.MockDirectoryWrapper;
@@ -58,6 +62,7 @@
5862
import java.nio.file.Path;
5963
import java.util.Arrays;
6064
import java.util.Locale;
65+
import java.util.OptionalLong;
6166

6267
import static java.lang.String.format;
6368
import static org.apache.lucene.index.VectorSimilarityFunction.DOT_PRODUCT;
@@ -152,6 +157,7 @@ public void testSimpleOffHeapSize() throws IOException {
152157
}
153158

154159
public void testSimpleOffHeapSizeFSDir() throws IOException {
160+
checkDirectIOSupported();
155161
var config = newIndexWriterConfig().setUseCompoundFile(false); // avoid compound files to allow directIO
156162
try (Directory dir = newFSDirectory()) {
157163
testSimpleOffHeapSizeImpl(dir, config, false);
@@ -213,4 +219,22 @@ private Directory newFSDirectory() throws IOException {
213219
}
214220
return dir;
215221
}
222+
223+
static void checkDirectIOSupported() {
224+
Path path = createTempDir("directIOProbe");
225+
try (Directory dir = open(path); IndexOutput out = dir.createOutput("out", IOContext.DEFAULT)) {
226+
out.writeString("test");
227+
} catch (IOException e) {
228+
assumeNoException("test requires a filesystem that supports Direct IO", e);
229+
}
230+
}
231+
232+
static DirectIODirectory open(Path path) throws IOException {
233+
return new DirectIODirectory(FSDirectory.open(path)) {
234+
@Override
235+
protected boolean useDirectIO(String name, IOContext context, OptionalLong fileLength) {
236+
return true;
237+
}
238+
};
239+
}
216240
}

0 commit comments

Comments
 (0)