Skip to content

Commit 07503c0

Browse files
authored
Merge branch 'main' into fix-sampletests
2 parents f7f9878 + 7872e84 commit 07503c0

File tree

6 files changed

+72
-12
lines changed

6 files changed

+72
-12
lines changed

docs/changelog/127921.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 127921
2+
summary: "[9.x] Revert \"Enable madvise by default for all builds\""
3+
area: Vector Search
4+
type: bug
5+
issues: []

muted-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,9 @@ tests:
462462
- class: org.elasticsearch.indices.stats.IndexStatsIT
463463
method: testThrottleStats
464464
issue: https://github.com/elastic/elasticsearch/issues/126359
465+
- class: org.elasticsearch.search.vectors.IVFKnnFloatVectorQueryTests
466+
method: testRandomWithFilter
467+
issue: https://github.com/elastic/elasticsearch/issues/127963
465468

466469
# Examples:
467470
#

server/src/main/java/org/elasticsearch/index/store/FsDirectoryFactory.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
import org.apache.lucene.store.MMapDirectory;
2121
import org.apache.lucene.store.NIOFSDirectory;
2222
import org.apache.lucene.store.NativeFSLockFactory;
23+
import org.apache.lucene.store.ReadAdvice;
2324
import org.apache.lucene.store.SimpleFSLockFactory;
2425
import org.elasticsearch.common.settings.Setting;
2526
import org.elasticsearch.common.settings.Setting.Property;
27+
import org.elasticsearch.common.util.FeatureFlag;
2628
import org.elasticsearch.core.IOUtils;
2729
import org.elasticsearch.index.IndexModule;
2830
import org.elasticsearch.index.IndexSettings;
@@ -43,6 +45,7 @@
4345
public class FsDirectoryFactory implements IndexStorePlugin.DirectoryFactory {
4446

4547
private static final Logger Log = LogManager.getLogger(FsDirectoryFactory.class);
48+
private static final FeatureFlag MADV_RANDOM_FEATURE_FLAG = new FeatureFlag("madv_random");
4649

4750
public static final Setting<LockFactory> INDEX_LOCK_FACTOR_SETTING = new Setting<>("index.store.fs.fs_lock", "native", (s) -> {
4851
return switch (s) {
@@ -75,12 +78,20 @@ protected Directory newFSDirectory(Path location, LockFactory lockFactory, Index
7578
// Use Lucene defaults
7679
final FSDirectory primaryDirectory = FSDirectory.open(location, lockFactory);
7780
if (primaryDirectory instanceof MMapDirectory mMapDirectory) {
78-
return new HybridDirectory(lockFactory, setPreload(mMapDirectory, preLoadExtensions));
81+
Directory dir = new HybridDirectory(lockFactory, setPreload(mMapDirectory, preLoadExtensions));
82+
if (MADV_RANDOM_FEATURE_FLAG.isEnabled() == false) {
83+
dir = disableRandomAdvice(dir);
84+
}
85+
return dir;
7986
} else {
8087
return primaryDirectory;
8188
}
8289
case MMAPFS:
83-
return setPreload(new MMapDirectory(location, lockFactory), preLoadExtensions);
90+
Directory dir = setPreload(new MMapDirectory(location, lockFactory), preLoadExtensions);
91+
if (MADV_RANDOM_FEATURE_FLAG.isEnabled() == false) {
92+
dir = disableRandomAdvice(dir);
93+
}
94+
return dir;
8495
case SIMPLEFS:
8596
case NIOFS:
8697
return new NIOFSDirectory(location, lockFactory);
@@ -108,6 +119,23 @@ static BiPredicate<String, IOContext> getPreloadFunc(Set<String> preLoadExtensio
108119
return MMapDirectory.NO_FILES;
109120
}
110121

122+
/**
123+
* Return a {@link FilterDirectory} around the provided {@link Directory} that forcefully disables {@link IOContext#readAdvice random
124+
* access}.
125+
*/
126+
static Directory disableRandomAdvice(Directory dir) {
127+
return new FilterDirectory(dir) {
128+
@Override
129+
public IndexInput openInput(String name, IOContext context) throws IOException {
130+
if (context.readAdvice() == ReadAdvice.RANDOM) {
131+
context = context.withReadAdvice(ReadAdvice.NORMAL);
132+
}
133+
assert context.readAdvice() != ReadAdvice.RANDOM;
134+
return super.openInput(name, context);
135+
}
136+
};
137+
}
138+
111139
/**
112140
* Returns true iff the directory is a hybrid fs directory
113141
*/

server/src/test/java/org/elasticsearch/index/store/FsDirectoryFactoryTests.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99
package org.elasticsearch.index.store;
1010

1111
import org.apache.lucene.store.AlreadyClosedException;
12+
import org.apache.lucene.store.ByteBuffersDirectory;
1213
import org.apache.lucene.store.Directory;
1314
import org.apache.lucene.store.FilterDirectory;
1415
import org.apache.lucene.store.IOContext;
16+
import org.apache.lucene.store.IndexInput;
17+
import org.apache.lucene.store.IndexOutput;
1518
import org.apache.lucene.store.MMapDirectory;
1619
import org.apache.lucene.store.NIOFSDirectory;
1720
import org.apache.lucene.store.NoLockFactory;
21+
import org.apache.lucene.store.ReadAdvice;
1822
import org.apache.lucene.store.SleepingLockWrapper;
1923
import org.apache.lucene.util.Constants;
2024
import org.elasticsearch.cluster.metadata.IndexMetadata;
@@ -34,6 +38,7 @@
3438
import java.nio.file.Path;
3539
import java.util.Arrays;
3640
import java.util.HashMap;
41+
import java.util.List;
3742
import java.util.Locale;
3843
import java.util.Map;
3944
import java.util.Set;
@@ -74,6 +79,29 @@ public void testPreload() throws IOException {
7479
}
7580
}
7681

82+
public void testDisableRandomAdvice() throws IOException {
83+
Directory dir = new FilterDirectory(new ByteBuffersDirectory()) {
84+
@Override
85+
public IndexInput openInput(String name, IOContext context) throws IOException {
86+
assertFalse(context.readAdvice() == ReadAdvice.RANDOM);
87+
return super.openInput(name, context);
88+
}
89+
};
90+
Directory noRandomAccessDir = FsDirectoryFactory.disableRandomAdvice(dir);
91+
try (IndexOutput out = noRandomAccessDir.createOutput("foo", IOContext.DEFAULT)) {
92+
out.writeInt(42);
93+
}
94+
// Test the tester
95+
expectThrows(AssertionError.class, () -> dir.openInput("foo", IOContext.DEFAULT.withReadAdvice(ReadAdvice.RANDOM)));
96+
97+
// The wrapped directory shouldn't fail regardless of the IOContext
98+
for (IOContext context : List.of(IOContext.DEFAULT, IOContext.READONCE, IOContext.DEFAULT.withReadAdvice(ReadAdvice.RANDOM))) {
99+
try (IndexInput in = noRandomAccessDir.openInput("foo", context)) {
100+
assertEquals(42, in.readInt());
101+
}
102+
}
103+
}
104+
77105
private Directory newDirectory(Settings settings) throws IOException {
78106
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("foo", settings);
79107
Path tempDir = createTempDir().resolve(idxSettings.getUUID()).resolve("0");

x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/search/SearchApplication.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
import org.elasticsearch.TransportVersions;
1313
import org.elasticsearch.common.Strings;
1414
import org.elasticsearch.common.bytes.BytesReference;
15-
import org.elasticsearch.common.io.stream.ReleasableBytesStreamOutput;
15+
import org.elasticsearch.common.io.stream.BytesStreamOutput;
1616
import org.elasticsearch.common.io.stream.StreamInput;
1717
import org.elasticsearch.common.io.stream.StreamOutput;
1818
import org.elasticsearch.common.io.stream.Writeable;
19-
import org.elasticsearch.common.util.BigArrays;
2019
import org.elasticsearch.common.xcontent.XContentHelper;
2120
import org.elasticsearch.core.Nullable;
2221
import org.elasticsearch.core.Tuple;
@@ -282,15 +281,13 @@ public String toString() {
282281
* Returns the merged {@link SearchApplication} from the current state and the provided {@param update}.
283282
* This function returns the current instance if the update is a noop.
284283
*
285-
* @param update The source of the update represented in bytes.
284+
* @param update The source of the update represented in bytes.
286285
* @param xContentType The format of the bytes.
287-
* @param bigArrays The {@link BigArrays} to use to recycle bytes array.
288-
*
289286
* @return The merged {@link SearchApplication}.
290287
*/
291-
SearchApplication merge(BytesReference update, XContentType xContentType, BigArrays bigArrays) throws IOException {
288+
SearchApplication merge(BytesReference update, XContentType xContentType) throws IOException {
292289
final Tuple<XContentType, Map<String, Object>> sourceAndContent;
293-
try (ReleasableBytesStreamOutput sourceBuffer = new ReleasableBytesStreamOutput(0, bigArrays.withCircuitBreaking())) {
290+
try (BytesStreamOutput sourceBuffer = new BytesStreamOutput()) {
294291
try (XContentBuilder builder = XContentFactory.jsonBuilder(sourceBuffer)) {
295292
toXContent(builder, EMPTY_PARAMS);
296293
}
@@ -305,7 +302,7 @@ SearchApplication merge(BytesReference update, XContentType xContentType, BigArr
305302
return this;
306303
}
307304

308-
try (ReleasableBytesStreamOutput newSourceBuffer = new ReleasableBytesStreamOutput(0, bigArrays.withCircuitBreaking())) {
305+
try (BytesStreamOutput newSourceBuffer = new BytesStreamOutput()) {
309306
try (XContentBuilder builder = XContentFactory.jsonBuilder(newSourceBuffer)) {
310307
builder.value(newSourceAsMap);
311308
}

x-pack/plugin/ent-search/src/test/java/org/elasticsearch/xpack/application/search/SearchApplicationTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
1717
import org.elasticsearch.common.io.stream.StreamInput;
1818
import org.elasticsearch.common.settings.Settings;
19-
import org.elasticsearch.common.util.BigArrays;
2019
import org.elasticsearch.common.xcontent.XContentHelper;
2120
import org.elasticsearch.search.SearchModule;
2221
import org.elasticsearch.test.ESTestCase;
@@ -111,7 +110,7 @@ public void testMerge() throws IOException {
111110
"updated_at_millis": 12345
112111
}""";
113112
SearchApplication app = SearchApplication.fromXContentBytes("my_search_app", new BytesArray(content), XContentType.JSON);
114-
SearchApplication updatedApp = app.merge(new BytesArray(update), XContentType.JSON, BigArrays.NON_RECYCLING_INSTANCE);
113+
SearchApplication updatedApp = app.merge(new BytesArray(update), XContentType.JSON);
115114
assertNotSame(app, updatedApp);
116115
assertThat(updatedApp.indices(), equalTo(new String[] { "my_index", "my_index_2" }));
117116
assertThat(updatedApp.analyticsCollectionName(), equalTo("my_search_app_analytics"));

0 commit comments

Comments
 (0)