@@ -71,10 +71,11 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
71
71
return List .of (InternalSettingsPlugin .class );
72
72
}
73
73
74
- private void indexVectors () {
74
+ private String indexVectors (boolean directIO ) {
75
+ String indexName = "test-vectors-" + directIO ;
75
76
String type = randomFrom ("bbq_hnsw" , "bbq_disk" );
76
77
assertAcked (
77
- prepareCreate ("foo-vectors" ).setSettings (Settings .builder ().put (InternalSettingsPlugin .USE_COMPOUND_FILE .getKey (), false ))
78
+ prepareCreate (indexName ).setSettings (Settings .builder ().put (InternalSettingsPlugin .USE_COMPOUND_FILE .getKey (), false ))
78
79
.setMapping ("""
79
80
{
80
81
"properties": {
@@ -85,27 +86,28 @@ private void indexVectors() {
85
86
"index": true,
86
87
"similarity": "l2_norm",
87
88
"index_options": {
88
- "type": "%type% ",
89
- "on_disk_rescore": true
89
+ "type": "%s ",
90
+ "on_disk_rescore": %s
90
91
}
91
92
}
92
93
}
93
94
}
94
- """ .replace ( "% type%" , type ))
95
+ """ .formatted ( type , directIO ))
95
96
);
96
- ensureGreen ("foo-vectors" );
97
+ ensureGreen (indexName );
97
98
98
99
for (int i = 0 ; i < 1000 ; i ++) {
99
- indexDoc ("foo-vectors" , Integer .toString (i ), "fooVector" , IntStream .range (0 , 64 ).mapToDouble (d -> randomFloat ()).toArray ());
100
+ indexDoc (indexName , Integer .toString (i ), "fooVector" , IntStream .range (0 , 64 ).mapToDouble (d -> randomFloat ()).toArray ());
100
101
}
101
102
refresh ();
102
- assertBBQIndexType (type ); // test assertion to ensure that the correct index type is being used
103
+ assertBBQIndexType (indexName , type ); // test assertion to ensure that the correct index type is being used
104
+ return indexName ;
103
105
}
104
106
105
107
@ SuppressWarnings ("unchecked" )
106
- static void assertBBQIndexType (String type ) {
107
- var response = indicesAdmin ().prepareGetFieldMappings ("foo-vectors" ).setFields ("fooVector" ).get ();
108
- var map = (Map <String , Object >) response .fieldMappings ("foo-vectors" , "fooVector" ).sourceAsMap ().get ("fooVector" );
108
+ static void assertBBQIndexType (String indexName , String type ) {
109
+ var response = indicesAdmin ().prepareGetFieldMappings (indexName ).setFields ("fooVector" ).get ();
110
+ var map = (Map <String , Object >) response .fieldMappings (indexName , "fooVector" ).sourceAsMap ().get ("fooVector" );
109
111
assertThat ((String ) ((Map <String , Object >) map .get ("index_options" )).get ("type" ), is (equalTo (type )));
110
112
}
111
113
@@ -128,11 +130,39 @@ public void testDirectIOUsed() {
128
130
);
129
131
mockLog .addExpectation (expectation );
130
132
131
- indexVectors ();
133
+ String indexName = indexVectors (true );
132
134
133
135
// do a search
134
136
var knn = List .of (new KnnSearchBuilder ("fooVector" , new VectorData (null , new byte [64 ]), 10 , 20 , 10f , null , null ));
135
- assertHitCount (prepareSearch ("foo-vectors" ).setKnnSearch (knn ), 10 );
137
+ assertHitCount (prepareSearch (indexName ).setKnnSearch (knn ), 10 );
138
+ mockLog .assertAllExpectationsMatched ();
139
+ }
140
+ }
141
+
142
+ @ TestLogging (value = "org.elasticsearch.index.store.FsDirectoryFactory:DEBUG" , reason = "to capture trace logging for direct IO" )
143
+ public void testDirectIONotUsed () {
144
+ try (MockLog mockLog = MockLog .capture (FsDirectoryFactory .class )) {
145
+ // nothing about direct IO should be logged at all
146
+ MockLog .LoggingExpectation expectation = SUPPORTED
147
+ ? new MockLog .PatternNotSeenEventExpectation (
148
+ "Direct IO used" ,
149
+ FsDirectoryFactory .class .getCanonicalName (),
150
+ Level .DEBUG ,
151
+ "Opening .*\\ .vec with direct IO"
152
+ )
153
+ : new MockLog .PatternNotSeenEventExpectation (
154
+ "Direct IO not used" ,
155
+ FsDirectoryFactory .class .getCanonicalName (),
156
+ Level .DEBUG ,
157
+ "Could not open .*\\ .vec with direct IO"
158
+ );
159
+ mockLog .addExpectation (expectation );
160
+
161
+ String indexName = indexVectors (false );
162
+
163
+ // do a search
164
+ var knn = List .of (new KnnSearchBuilder ("fooVector" , new VectorData (null , new byte [64 ]), 10 , 20 , 10f , null , null ));
165
+ assertHitCount (prepareSearch (indexName ).setKnnSearch (knn ), 10 );
136
166
mockLog .assertAllExpectationsMatched ();
137
167
}
138
168
}
0 commit comments