Skip to content

Add an integration test to verify DirectIO is used for at least one case #128370

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 1 commit into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
@@ -0,0 +1,85 @@
/*
* 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.store;

import org.apache.logging.log4j.Level;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.search.vectors.KnnSearchBuilder;
import org.elasticsearch.search.vectors.VectorData;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.InternalSettingsPlugin;
import org.elasticsearch.test.MockLog;
import org.elasticsearch.test.junit.annotations.TestLogging;

import java.util.Collection;
import java.util.List;
import java.util.stream.IntStream;

@LuceneTestCase.SuppressCodecs("*") // only use our own codecs
public class DirectIOIT extends ESIntegTestCase {

@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return List.of(InternalSettingsPlugin.class);
}

private void indexVectors() {
internalCluster().startNode();
prepareCreate("vectors").setSettings(Settings.builder().put(InternalSettingsPlugin.USE_COMPOUND_FILE.getKey(), false))
.setMapping("""
{
"properties": {
"vector": {
"type": "dense_vector",
"dims": 64,
"element_type": "float",
"index": true,
"similarity": "l2_norm",
"index_options": {
"type": "bbq_flat"
}
}
}
}
""")
.get();
ensureGreen("vectors");

for (int i = 0; i < 1000; i++) {
indexDoc("vectors", Integer.toString(i), "vector", IntStream.range(0, 64).mapToDouble(d -> randomFloat()).toArray());
}
}

@TestLogging(value = "org.elasticsearch.index.store.FsDirectoryFactory:DEBUG", reason = "to capture trace logging for direct IO")
public void testDirectIOUsed() {
try (MockLog mockLog = MockLog.capture(FsDirectoryFactory.class)) {
// we're just looking for some evidence direct IO is used
mockLog.addExpectation(
new MockLog.PatternSeenEventExpectation(
"Direct IO used",
FsDirectoryFactory.class.getCanonicalName(),
Level.DEBUG,
"Opening .*\\.vec with direct IO"
)
);

indexVectors();

// do a search
prepareSearch("vectors").setKnnSearch(
List.of(new KnnSearchBuilder("vector", new VectorData(null, new byte[64]), 10, 20, null, null))
).get();

mockLog.assertAllExpectationsMatched();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public IndexInput openInput(String name, IOContext context) throws IOException {
if (directIODelegate != null && context.hints().contains(DirectIOHint.INSTANCE)) {
ensureOpen();
ensureCanRead(name);
Log.debug("Opening {} with direct IO", name);
return directIODelegate.openInput(name, context);
} else if (useDelegate(name, context)) {
// we need to do these checks on the outer directory since the inner doesn't know about pending deletes
Expand Down