Skip to content

Commit 2e90d6d

Browse files
authored
Merge branch 'elastic:main' into bugfix/highlighting-for-constant_keyword-field-type
2 parents a4c7b5f + fe9167c commit 2e90d6d

File tree

1,001 files changed

+21780
-5298
lines changed

Some content is hidden

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

1,001 files changed

+21780
-5298
lines changed

benchmarks/src/main/java/org/elasticsearch/benchmark/index/mapper/MapperServiceFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static MapperService create(String mappings) {
5252

5353
SimilarityService similarityService = new SimilarityService(indexSettings, null, Map.of());
5454
MapperService mapperService = new MapperService(
55-
() -> TransportVersion.CURRENT,
55+
() -> TransportVersion.current(),
5656
indexSettings,
5757
IndexAnalyzers.of(
5858
Map.of("default", new NamedAnalyzer("default", AnalyzerScope.INDEX, new StandardAnalyzer())),

benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/AllocationBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public void setUp() throws Exception {
144144
for (int i = 1; i <= numNodes; i++) {
145145
String id = "node" + i;
146146
nb.add(Allocators.newNode(id, Collections.singletonMap("tag", "tag_" + (i % numTags))));
147-
transportVersions.put(id, TransportVersion.CURRENT);
147+
transportVersions.put(id, TransportVersion.current());
148148
}
149149
initialClusterState = ClusterState.builder(ClusterName.DEFAULT)
150150
.metadata(metadata)

benchmarks/src/main/java/org/elasticsearch/benchmark/script/ScriptScoreBenchmark.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
import org.apache.lucene.store.Directory;
2323
import org.apache.lucene.store.MMapDirectory;
2424
import org.apache.lucene.util.IOUtils;
25-
import org.elasticsearch.Version;
2625
import org.elasticsearch.common.lucene.search.function.ScriptScoreQuery;
2726
import org.elasticsearch.common.settings.Settings;
27+
import org.elasticsearch.index.IndexVersion;
2828
import org.elasticsearch.index.fielddata.FieldDataContext;
2929
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
3030
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
@@ -148,7 +148,7 @@ public TopDocs benchmark() throws IOException {
148148

149149
private Query scriptScoreQuery(ScoreScript.Factory factory) {
150150
ScoreScript.LeafFactory leafFactory = factory.newFactory(Map.of(), lookup);
151-
return new ScriptScoreQuery(new MatchAllDocsQuery(), null, leafFactory, lookup, null, "test", 0, Version.CURRENT);
151+
return new ScriptScoreQuery(new MatchAllDocsQuery(), null, leafFactory, lookup, null, "test", 0, IndexVersion.CURRENT);
152152
}
153153

154154
private ScoreScript.Factory bareMetalScript() {

benchmarks/src/main/java/org/elasticsearch/benchmark/search/QueryParserHelperBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ protected final MapperService createMapperService(String mappings) {
170170

171171
SimilarityService similarityService = new SimilarityService(indexSettings, null, Map.of());
172172
MapperService mapperService = new MapperService(
173-
() -> TransportVersion.CURRENT,
173+
() -> TransportVersion.current(),
174174
indexSettings,
175175
(type, name) -> Lucene.STANDARD_ANALYZER,
176176
XContentParserConfiguration.EMPTY.withRegistry(new NamedXContentRegistry(ClusterModule.getNamedXWriteables()))
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
* This project is based on a modification of https://github.com/tdunning/t-digest which is licensed under the Apache 2.0 License.
20+
*/
21+
22+
package org.elasticsearch.benchmark.tdigest;
23+
24+
import org.elasticsearch.tdigest.Sort;
25+
import org.openjdk.jmh.annotations.Benchmark;
26+
import org.openjdk.jmh.annotations.BenchmarkMode;
27+
import org.openjdk.jmh.annotations.Fork;
28+
import org.openjdk.jmh.annotations.Measurement;
29+
import org.openjdk.jmh.annotations.Mode;
30+
import org.openjdk.jmh.annotations.OutputTimeUnit;
31+
import org.openjdk.jmh.annotations.Param;
32+
import org.openjdk.jmh.annotations.Scope;
33+
import org.openjdk.jmh.annotations.Setup;
34+
import org.openjdk.jmh.annotations.State;
35+
import org.openjdk.jmh.annotations.Threads;
36+
import org.openjdk.jmh.annotations.Warmup;
37+
38+
import java.util.Arrays;
39+
import java.util.Random;
40+
import java.util.concurrent.TimeUnit;
41+
42+
/** Explores the performance of Sort on pathological input data. */
43+
@BenchmarkMode(Mode.AverageTime)
44+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
45+
@Warmup(iterations = 10, time = 3, timeUnit = TimeUnit.SECONDS)
46+
@Measurement(iterations = 20, time = 2, timeUnit = TimeUnit.SECONDS)
47+
@Fork(1)
48+
@Threads(1)
49+
@State(Scope.Thread)
50+
public class SortBench {
51+
private final int size = 100000;
52+
private final double[] values = new double[size];
53+
54+
@Param({ "0", "1", "-1" })
55+
public int sortDirection;
56+
57+
@Setup
58+
public void setup() {
59+
Random prng = new Random(999983);
60+
for (int i = 0; i < size; i++) {
61+
values[i] = prng.nextDouble();
62+
}
63+
if (sortDirection > 0) {
64+
Arrays.sort(values);
65+
} else if (sortDirection < 0) {
66+
Arrays.sort(values);
67+
Sort.reverse(values, 0, values.length);
68+
}
69+
}
70+
71+
@Benchmark
72+
public void quicksort() {
73+
int[] order = new int[size];
74+
for (int i = 0; i < size; i++) {
75+
order[i] = i;
76+
}
77+
Sort.sort(order, values, null, values.length);
78+
}
79+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
* This project is based on a modification of https://github.com/tdunning/t-digest which is licensed under the Apache 2.0 License.
20+
*/
21+
22+
package org.elasticsearch.benchmark.tdigest;
23+
24+
import org.elasticsearch.tdigest.AVLTreeDigest;
25+
import org.elasticsearch.tdigest.MergingDigest;
26+
import org.elasticsearch.tdigest.TDigest;
27+
import org.openjdk.jmh.annotations.Benchmark;
28+
import org.openjdk.jmh.annotations.BenchmarkMode;
29+
import org.openjdk.jmh.annotations.Fork;
30+
import org.openjdk.jmh.annotations.Measurement;
31+
import org.openjdk.jmh.annotations.Mode;
32+
import org.openjdk.jmh.annotations.OutputTimeUnit;
33+
import org.openjdk.jmh.annotations.Param;
34+
import org.openjdk.jmh.annotations.Scope;
35+
import org.openjdk.jmh.annotations.Setup;
36+
import org.openjdk.jmh.annotations.State;
37+
import org.openjdk.jmh.annotations.Threads;
38+
import org.openjdk.jmh.annotations.Warmup;
39+
import org.openjdk.jmh.profile.GCProfiler;
40+
import org.openjdk.jmh.profile.StackProfiler;
41+
import org.openjdk.jmh.runner.Runner;
42+
import org.openjdk.jmh.runner.RunnerException;
43+
import org.openjdk.jmh.runner.options.Options;
44+
import org.openjdk.jmh.runner.options.OptionsBuilder;
45+
46+
import java.util.Random;
47+
import java.util.concurrent.ThreadLocalRandom;
48+
import java.util.concurrent.TimeUnit;
49+
import java.util.function.Supplier;
50+
51+
@BenchmarkMode(Mode.AverageTime)
52+
@OutputTimeUnit(TimeUnit.NANOSECONDS)
53+
@Warmup(iterations = 3, time = 3, timeUnit = TimeUnit.SECONDS)
54+
@Measurement(iterations = 5, time = 2, timeUnit = TimeUnit.SECONDS)
55+
@Fork(1)
56+
@Threads(1)
57+
@State(Scope.Thread)
58+
public class TDigestBench {
59+
60+
public enum TDigestFactory {
61+
MERGE {
62+
@Override
63+
TDigest create(double compression) {
64+
return new MergingDigest(compression, (int) (10 * compression));
65+
}
66+
},
67+
AVL_TREE {
68+
@Override
69+
TDigest create(double compression) {
70+
return new AVLTreeDigest(compression);
71+
}
72+
};
73+
74+
abstract TDigest create(double compression);
75+
}
76+
77+
@Param({ "100", "300" })
78+
double compression;
79+
80+
@Param({ "MERGE", "AVL_TREE" })
81+
TDigestFactory tdigestFactory;
82+
83+
@Param({ "NORMAL", "GAUSSIAN" })
84+
String distribution;
85+
86+
Random random;
87+
TDigest tdigest;
88+
89+
double[] data = new double[1000000];
90+
91+
@Setup
92+
public void setUp() {
93+
random = ThreadLocalRandom.current();
94+
tdigest = tdigestFactory.create(compression);
95+
96+
Supplier<Double> nextRandom = () -> distribution.equals("GAUSSIAN") ? random.nextGaussian() : random.nextDouble();
97+
for (int i = 0; i < 10000; ++i) {
98+
tdigest.add(nextRandom.get());
99+
}
100+
101+
for (int i = 0; i < data.length; ++i) {
102+
data[i] = nextRandom.get();
103+
}
104+
}
105+
106+
@State(Scope.Thread)
107+
public static class ThreadState {
108+
int index = 0;
109+
}
110+
111+
@Benchmark
112+
@BenchmarkMode(Mode.AverageTime)
113+
@OutputTimeUnit(TimeUnit.MICROSECONDS)
114+
public void add(ThreadState state) {
115+
if (state.index >= data.length) {
116+
state.index = 0;
117+
}
118+
tdigest.add(data[state.index++]);
119+
}
120+
121+
public static void main(String[] args) throws RunnerException {
122+
Options opt = new OptionsBuilder().include(".*" + TDigestBench.class.getSimpleName() + ".*")
123+
.warmupIterations(5)
124+
.measurementIterations(5)
125+
.addProfiler(GCProfiler.class)
126+
.addProfiler(StackProfiler.class)
127+
.build();
128+
129+
new Runner(opt).run();
130+
}
131+
}

benchmarks/src/main/java/org/elasticsearch/benchmark/vector/DistanceFunctionBenchmark.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
package org.elasticsearch.benchmark.vector;
1010

1111
import org.apache.lucene.util.BytesRef;
12-
import org.elasticsearch.Version;
12+
import org.elasticsearch.index.IndexVersion;
1313
import org.elasticsearch.script.field.vectors.BinaryDenseVector;
1414
import org.elasticsearch.script.field.vectors.ByteBinaryDenseVector;
1515
import org.elasticsearch.script.field.vectors.ByteKnnDenseVector;
@@ -242,7 +242,7 @@ private DotBinaryFloatBenchmarkFunction(int dims) {
242242

243243
@Override
244244
public void execute(Consumer<Object> consumer) {
245-
new BinaryDenseVector(docFloatVector, docVector, dims, Version.CURRENT).dotProduct(queryVector);
245+
new BinaryDenseVector(docFloatVector, docVector, dims, IndexVersion.CURRENT).dotProduct(queryVector);
246246
}
247247
}
248248

@@ -290,7 +290,7 @@ private CosineBinaryFloatBenchmarkFunction(int dims) {
290290

291291
@Override
292292
public void execute(Consumer<Object> consumer) {
293-
new BinaryDenseVector(docFloatVector, docVector, dims, Version.CURRENT).cosineSimilarity(queryVector, false);
293+
new BinaryDenseVector(docFloatVector, docVector, dims, IndexVersion.CURRENT).cosineSimilarity(queryVector, false);
294294
}
295295
}
296296

@@ -338,7 +338,7 @@ private L1BinaryFloatBenchmarkFunction(int dims) {
338338

339339
@Override
340340
public void execute(Consumer<Object> consumer) {
341-
new BinaryDenseVector(docFloatVector, docVector, dims, Version.CURRENT).l1Norm(queryVector);
341+
new BinaryDenseVector(docFloatVector, docVector, dims, IndexVersion.CURRENT).l1Norm(queryVector);
342342
}
343343
}
344344

@@ -386,7 +386,7 @@ private L2BinaryFloatBenchmarkFunction(int dims) {
386386

387387
@Override
388388
public void execute(Consumer<Object> consumer) {
389-
new BinaryDenseVector(docFloatVector, docVector, dims, Version.CURRENT).l1Norm(queryVector);
389+
new BinaryDenseVector(docFloatVector, docVector, dims, IndexVersion.CURRENT).l1Norm(queryVector);
390390
}
391391
}
392392

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/DependenciesInfoTask.java

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,13 @@ public void setCompileOnlyConfiguration(Configuration compileOnlyConfiguration)
8080
*/
8181
@Optional
8282
@InputDirectory
83-
public DirectoryProperty getLicensesDir() {
84-
return licensesDir;
83+
public File getLicensesDir() {
84+
File asFile = licensesDir.get().getAsFile();
85+
if (asFile.exists()) {
86+
return asFile;
87+
}
88+
89+
return null;
8590
}
8691

8792
public void setLicensesDir(File licensesDir) {
@@ -110,10 +115,7 @@ public void setOutputFile(File outputFile) {
110115
@Inject
111116
public DependenciesInfoTask(ProjectLayout projectLayout, ObjectFactory objectFactory, ProviderFactory providerFactory) {
112117
this.licensesDir = objectFactory.directoryProperty();
113-
this.licensesDir.convention(
114-
providerFactory.provider(() -> projectLayout.getProjectDirectory().dir("licenses"))
115-
.map(dir -> dir.getAsFile().exists() ? dir : null)
116-
);
118+
this.licensesDir.convention(providerFactory.provider(() -> projectLayout.getProjectDirectory().dir("licenses")));
117119
this.outputFile = projectLayout.getBuildDirectory().dir("reports/dependencies").get().file("dependencies.csv").getAsFile();
118120
setDescription("Create a CSV file with dependencies information.");
119121
}
@@ -140,7 +142,7 @@ public void generateDependenciesInfo() throws IOException {
140142
}
141143

142144
// only external dependencies are checked
143-
if (dep instanceof ProjectDependency) {
145+
if (dep instanceof ProjectDependency || dep.getGroup().startsWith("org.elasticsearch")) {
144146
continue;
145147
}
146148

@@ -214,27 +216,22 @@ protected String getLicenseType(final String group, final String name) throws IO
214216
return licenseType;
215217
}
216218

219+
private IllegalStateException missingInfo(String group, String name, String infoFileSuffix, String reason) {
220+
return new IllegalStateException("Unable to find " + infoFileSuffix + " file for dependency " + group + ":" + name + " " + reason);
221+
}
222+
217223
protected File getDependencyInfoFile(final String group, final String name, final String infoFileSuffix) {
218-
java.util.Optional<File> license = licensesDir.map(
219-
licenseDir -> Arrays.stream(
220-
licenseDir.getAsFile().listFiles((dir, fileName) -> Pattern.matches(".*-" + infoFileSuffix + ".*", fileName))
221-
).filter(file -> {
222-
String prefix = file.getName().split("-" + infoFileSuffix + ".*")[0];
223-
return group.contains(prefix) || name.contains(prefix);
224-
}).findFirst()
225-
).get();
226-
227-
return license.orElseThrow(
228-
() -> new IllegalStateException(
229-
"Unable to find "
230-
+ infoFileSuffix
231-
+ " file for dependency "
232-
+ group
233-
+ ":"
234-
+ name
235-
+ " in "
236-
+ licensesDir.getAsFile().getOrNull()
237-
)
238-
);
224+
File dir = getLicensesDir();
225+
if (dir == null) {
226+
throw missingInfo(group, name, infoFileSuffix, " because license dir is missing at " + licensesDir.getAsFile().get());
227+
}
228+
java.util.Optional<File> license = Arrays.stream(
229+
dir.listFiles((d, fileName) -> Pattern.matches(".*-" + infoFileSuffix + ".*", fileName))
230+
).filter(file -> {
231+
String prefix = file.getName().split("-" + infoFileSuffix + ".*")[0];
232+
return group.contains(prefix) || name.contains(prefix);
233+
}).findFirst();
234+
235+
return license.orElseThrow(() -> missingInfo(group, name, infoFileSuffix, " in " + dir));
239236
}
240237
}

0 commit comments

Comments
 (0)