Skip to content

Commit 68c85d7

Browse files
committed
Merge branch 'main' into exception_type_header
2 parents 0bbb922 + 4b7de2f commit 68c85d7

File tree

311 files changed

+7258
-1869
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

311 files changed

+7258
-1869
lines changed

benchmarks/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import org.elasticsearch.gradle.OS
1313
apply plugin: org.elasticsearch.gradle.internal.ElasticsearchJavaBasePlugin
1414
apply plugin: 'java-library'
1515
apply plugin: 'application'
16+
apply plugin: 'elasticsearch.mrjar'
1617

1718
var os = org.gradle.internal.os.OperatingSystem.current()
1819

@@ -46,6 +47,7 @@ dependencies {
4647
api(project(':x-pack:plugin:core'))
4748
api(project(':x-pack:plugin:esql'))
4849
api(project(':x-pack:plugin:esql:compute'))
50+
implementation project(path: ':libs:native')
4951
implementation project(path: ':libs:simdvec')
5052
expression(project(path: ':modules:lang-expression', configuration: 'zip'))
5153
painless(project(path: ':modules:lang-painless', configuration: 'zip'))
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
package org.elasticsearch.benchmark.vector;
10+
11+
import org.apache.lucene.util.VectorUtil;
12+
import org.elasticsearch.common.logging.LogConfigurator;
13+
import org.elasticsearch.common.logging.NodeNamePatternConverter;
14+
import org.elasticsearch.nativeaccess.NativeAccess;
15+
import org.elasticsearch.nativeaccess.VectorSimilarityFunctions;
16+
import org.openjdk.jmh.annotations.Benchmark;
17+
import org.openjdk.jmh.annotations.BenchmarkMode;
18+
import org.openjdk.jmh.annotations.Fork;
19+
import org.openjdk.jmh.annotations.Level;
20+
import org.openjdk.jmh.annotations.Measurement;
21+
import org.openjdk.jmh.annotations.Mode;
22+
import org.openjdk.jmh.annotations.OutputTimeUnit;
23+
import org.openjdk.jmh.annotations.Param;
24+
import org.openjdk.jmh.annotations.Scope;
25+
import org.openjdk.jmh.annotations.Setup;
26+
import org.openjdk.jmh.annotations.State;
27+
import org.openjdk.jmh.annotations.TearDown;
28+
import org.openjdk.jmh.annotations.Warmup;
29+
30+
import java.lang.foreign.Arena;
31+
import java.lang.foreign.MemorySegment;
32+
import java.util.concurrent.ThreadLocalRandom;
33+
import java.util.concurrent.TimeUnit;
34+
35+
@BenchmarkMode(Mode.AverageTime)
36+
@OutputTimeUnit(TimeUnit.NANOSECONDS)
37+
@State(Scope.Benchmark)
38+
@Warmup(iterations = 3, time = 1)
39+
@Measurement(iterations = 5, time = 1)
40+
public class JDKVectorInt7uBenchmark {
41+
42+
static {
43+
NodeNamePatternConverter.setGlobalNodeName("foo");
44+
LogConfigurator.loadLog4jPlugins();
45+
LogConfigurator.configureESLogging(); // native access requires logging to be initialized
46+
}
47+
48+
byte[] byteArrayA;
49+
byte[] byteArrayB;
50+
MemorySegment heapSegA, heapSegB;
51+
MemorySegment nativeSegA, nativeSegB;
52+
53+
Arena arena;
54+
55+
@Param({ "1", "128", "207", "256", "300", "512", "702", "1024" })
56+
public int size;
57+
58+
@Setup(Level.Iteration)
59+
public void init() {
60+
byteArrayA = new byte[size];
61+
byteArrayB = new byte[size];
62+
for (int i = 0; i < size; ++i) {
63+
randomInt7BytesBetween(byteArrayA);
64+
randomInt7BytesBetween(byteArrayB);
65+
}
66+
heapSegA = MemorySegment.ofArray(byteArrayA);
67+
heapSegB = MemorySegment.ofArray(byteArrayB);
68+
69+
arena = Arena.ofConfined();
70+
nativeSegA = arena.allocate((long) byteArrayA.length);
71+
MemorySegment.copy(MemorySegment.ofArray(byteArrayA), 0L, nativeSegA, 0L, byteArrayA.length);
72+
nativeSegB = arena.allocate((long) byteArrayB.length);
73+
MemorySegment.copy(MemorySegment.ofArray(byteArrayB), 0L, nativeSegB, 0L, byteArrayB.length);
74+
}
75+
76+
@TearDown
77+
public void teardown() {
78+
arena.close();
79+
}
80+
81+
@Benchmark
82+
@Fork(value = 3, jvmArgsPrepend = { "--add-modules=jdk.incubator.vector" })
83+
public int dotProductLucene() {
84+
return VectorUtil.dotProduct(byteArrayA, byteArrayB);
85+
}
86+
87+
@Benchmark
88+
@Fork(value = 3, jvmArgsPrepend = { "--add-modules=jdk.incubator.vector" })
89+
public int dotProductNativeWithNativeSeg() {
90+
return dotProduct7u(nativeSegA, nativeSegB, size);
91+
}
92+
93+
@Benchmark
94+
@Fork(value = 3, jvmArgsPrepend = { "--add-modules=jdk.incubator.vector" })
95+
public int dotProductNativeWithHeapSeg() {
96+
return dotProduct7u(heapSegA, heapSegB, size);
97+
}
98+
99+
static final VectorSimilarityFunctions vectorSimilarityFunctions = vectorSimilarityFunctions();
100+
101+
static VectorSimilarityFunctions vectorSimilarityFunctions() {
102+
return NativeAccess.instance().getVectorSimilarityFunctions().get();
103+
}
104+
105+
int dotProduct7u(MemorySegment a, MemorySegment b, int length) {
106+
try {
107+
return (int) vectorSimilarityFunctions.dotProductHandle7u().invokeExact(a, b, length);
108+
} catch (Throwable e) {
109+
if (e instanceof Error err) {
110+
throw err;
111+
} else if (e instanceof RuntimeException re) {
112+
throw re;
113+
} else {
114+
throw new RuntimeException(e);
115+
}
116+
}
117+
}
118+
119+
// Unsigned int7 byte vectors have values in the range of 0 to 127 (inclusive).
120+
static final byte MIN_INT7_VALUE = 0;
121+
static final byte MAX_INT7_VALUE = 127;
122+
123+
static void randomInt7BytesBetween(byte[] bytes) {
124+
var random = ThreadLocalRandom.current();
125+
for (int i = 0, len = bytes.length; i < len;) {
126+
bytes[i++] = (byte) random.nextInt(MIN_INT7_VALUE, MAX_INT7_VALUE + 1);
127+
}
128+
}
129+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.benchmark.vector;
11+
12+
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
13+
14+
import org.apache.lucene.util.Constants;
15+
import org.elasticsearch.test.ESTestCase;
16+
import org.junit.BeforeClass;
17+
import org.openjdk.jmh.annotations.Param;
18+
19+
import java.util.Arrays;
20+
21+
public class JDKVectorInt7uBenchmarkTests extends ESTestCase {
22+
23+
final double delta = 1e-3;
24+
final int size;
25+
26+
public JDKVectorInt7uBenchmarkTests(int size) {
27+
this.size = size;
28+
}
29+
30+
@BeforeClass
31+
public static void skipWindows() {
32+
assumeFalse("doesn't work on windows yet", Constants.WINDOWS);
33+
}
34+
35+
static boolean supportsHeapSegments() {
36+
return Runtime.version().feature() >= 22;
37+
}
38+
39+
public void testDotProduct() {
40+
for (int i = 0; i < 100; i++) {
41+
var bench = new JDKVectorInt7uBenchmark();
42+
bench.size = size;
43+
bench.init();
44+
try {
45+
float expected = dotProductScalar(bench.byteArrayA, bench.byteArrayB);
46+
assertEquals(expected, bench.dotProductLucene(), delta);
47+
assertEquals(expected, bench.dotProductNativeWithNativeSeg(), delta);
48+
if (supportsHeapSegments()) {
49+
assertEquals(expected, bench.dotProductNativeWithHeapSeg(), delta);
50+
}
51+
} finally {
52+
bench.teardown();
53+
}
54+
}
55+
}
56+
57+
@ParametersFactory
58+
public static Iterable<Object[]> parametersFactory() {
59+
try {
60+
var params = JDKVectorInt7uBenchmark.class.getField("size").getAnnotationsByType(Param.class)[0].value();
61+
return () -> Arrays.stream(params).map(Integer::parseInt).map(i -> new Object[] { i }).iterator();
62+
} catch (NoSuchFieldException e) {
63+
throw new AssertionError(e);
64+
}
65+
}
66+
67+
/** Computes the dot product of the given vectors a and b. */
68+
static int dotProductScalar(byte[] a, byte[] b) {
69+
int res = 0;
70+
for (int i = 0; i < a.length; i++) {
71+
res += a[i] * b[i];
72+
}
73+
return res;
74+
}
75+
}

build-tools-internal/src/test/java/org/elasticsearch/gradle/internal/release/ReleaseNotesGeneratorTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Objects;
2020

2121
import static org.elasticsearch.gradle.internal.release.GenerateReleaseNotesTask.getSortedBundlesWithUniqueChangelogs;
22+
import static org.hamcrest.Matchers.arrayContaining;
2223
import static org.hamcrest.Matchers.equalTo;
2324
import static org.junit.Assert.assertFalse;
2425
import static org.junit.Assert.assertThat;
@@ -100,7 +101,10 @@ public void testTemplate(String templateFilename, String outputFilename, List<Ch
100101
writeResource(outputFile, actualOutput);
101102
assertFalse("UPDATE_EXPECTED_OUTPUT should be set back to false after updating output", UPDATE_EXPECTED_OUTPUT);
102103
} else {
103-
assertThat(actualOutput, equalTo(expectedOutput));
104+
String[] expectedLines = expectedOutput.replace("\r", "").split("\n");
105+
String[] actualLines = actualOutput.split("\n");
106+
107+
assertThat(actualLines, arrayContaining(expectedLines));
104108
}
105109
}
106110

docs/changelog/127223.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 127223
2+
summary: Wrap ES KNN queries with PatienceKNN query
3+
area: Vector Search
4+
type: feature
5+
issues: []

docs/changelog/128866.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 128866
2+
summary: Add `age_in_millis` to ILM Explain Response
3+
area: ILM+SLM
4+
type: enhancement
5+
issues:
6+
- 103659

docs/changelog/129945.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 129945
2+
summary: "Enhancement: ILM sets `indexing_complete` to true from `ReadOnly` action"
3+
area: ILM+SLM
4+
type: enhancement
5+
issues: []

docs/changelog/130221.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 130221
2+
summary: Fix incorrect accounting of semantic text indexing memory pressure
3+
area: Distributed
4+
type: bug
5+
issues: []

docs/changelog/130251.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 130251
2+
summary: Speed up (filtered) KNN queries for flat vector fields
3+
area: Vector Search
4+
type: enhancement
5+
issues: []

docs/changelog/130308.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 130308
2+
summary: Force niofs for fdt tmp file read access when flushing stored fields
3+
area: Logs
4+
type: bug
5+
issues: []

0 commit comments

Comments
 (0)