Skip to content

Commit 4754761

Browse files
committed
Merge branch 'master' into ccr
* master: Fix third-party audit tasks on JDK 8 Remove duplicated javadoc `fieldType` param Handle 5.6.6 and 6.1.2 release Introduce multi-release JAR Move the multi-get response tests to server Require JDK 9 for compilation (#28071) Revert "[Docs] Fix Java Api index administration usage (#28133)" Revert "[Docs] Fix base directory to include for put_mapping.asciidoc" Added multi get api to the high level rest client. [Docs] Clarify numeric datatype ranges (#28240) [Docs] Fix base directory to include for put_mapping.asciidoc Open engine should keep only starting commit (#28228)
2 parents f2093e7 + aded32f commit 4754761

File tree

42 files changed

+967
-278
lines changed

Some content is hidden

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

42 files changed

+967
-278
lines changed

CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ Contributing to the Elasticsearch codebase
9292

9393
**Repository:** [https://github.com/elastic/elasticsearch](https://github.com/elastic/elasticsearch)
9494

95+
JDK 9 is required to build Elasticsearch. You must have a JDK 9 installation
96+
with the environment variable `JAVA_HOME` referencing the path to Java home for
97+
your JDK 9 installation. By default, tests use the same runtime as `JAVA_HOME`.
98+
However, since Elasticsearch, supports JDK 8 the build supports compiling with
99+
JDK 9 and testing on a JDK 8 runtime; to do this, set `RUNTIME_JAVA_HOME`
100+
pointing to the Java home of a JDK 8 installation. Note that this mechanism can
101+
be used to test against other JDKs as well, this is not only limited to JDK 8.
102+
95103
Elasticsearch uses the Gradle wrapper for its build. You can execute Gradle
96104
using the wrapper via the `gradlew` script in the root of the repository.
97105

buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ import java.time.ZonedDateTime
5656
*/
5757
class BuildPlugin implements Plugin<Project> {
5858

59-
static final JavaVersion minimumJava = JavaVersion.VERSION_1_8
59+
static final JavaVersion minimumRuntimeVersion = JavaVersion.VERSION_1_8
60+
static final JavaVersion minimumCompilerVersion = JavaVersion.VERSION_1_9
6061

6162
@Override
6263
void apply(Project project) {
@@ -93,20 +94,26 @@ class BuildPlugin implements Plugin<Project> {
9394
/** Performs checks on the build environment and prints information about the build environment. */
9495
static void globalBuildInfo(Project project) {
9596
if (project.rootProject.ext.has('buildChecksDone') == false) {
96-
String javaHome = findJavaHome()
97+
String compilerJavaHome = findCompilerJavaHome()
98+
String runtimeJavaHome = findRuntimeJavaHome(compilerJavaHome)
9799
File gradleJavaHome = Jvm.current().javaHome
98100
String javaVendor = System.getProperty('java.vendor')
99101
String javaVersion = System.getProperty('java.version')
100102
String gradleJavaVersionDetails = "${javaVendor} ${javaVersion}" +
101103
" [${System.getProperty('java.vm.name')} ${System.getProperty('java.vm.version')}]"
102104

103-
String javaVersionDetails = gradleJavaVersionDetails
104-
JavaVersion javaVersionEnum = JavaVersion.current()
105-
if (new File(javaHome).canonicalPath != gradleJavaHome.canonicalPath) {
106-
javaVersionDetails = findJavaVersionDetails(project, javaHome)
107-
javaVersionEnum = JavaVersion.toVersion(findJavaSpecificationVersion(project, javaHome))
108-
javaVendor = findJavaVendor(project, javaHome)
109-
javaVersion = findJavaVersion(project, javaHome)
105+
String compilerJavaVersionDetails = gradleJavaVersionDetails
106+
JavaVersion compilerJavaVersionEnum = JavaVersion.current()
107+
if (new File(compilerJavaHome).canonicalPath != gradleJavaHome.canonicalPath) {
108+
compilerJavaVersionDetails = findJavaVersionDetails(project, compilerJavaHome)
109+
compilerJavaVersionEnum = JavaVersion.toVersion(findJavaSpecificationVersion(project, compilerJavaHome))
110+
}
111+
112+
String runtimeJavaVersionDetails = gradleJavaVersionDetails
113+
JavaVersion runtimeJavaVersionEnum = JavaVersion.current()
114+
if (new File(runtimeJavaHome).canonicalPath != gradleJavaHome.canonicalPath) {
115+
runtimeJavaVersionDetails = findJavaVersionDetails(project, runtimeJavaHome)
116+
runtimeJavaVersionEnum = JavaVersion.toVersion(findJavaSpecificationVersion(project, runtimeJavaHome))
110117
}
111118

112119
// Build debugging info
@@ -115,11 +122,13 @@ class BuildPlugin implements Plugin<Project> {
115122
println '======================================='
116123
println " Gradle Version : ${project.gradle.gradleVersion}"
117124
println " OS Info : ${System.getProperty('os.name')} ${System.getProperty('os.version')} (${System.getProperty('os.arch')})"
118-
if (gradleJavaVersionDetails != javaVersionDetails) {
125+
if (gradleJavaVersionDetails != compilerJavaVersionDetails || gradleJavaVersionDetails != runtimeJavaVersionDetails) {
119126
println " JDK Version (gradle) : ${gradleJavaVersionDetails}"
120127
println " JAVA_HOME (gradle) : ${gradleJavaHome}"
121-
println " JDK Version (compile) : ${javaVersionDetails}"
122-
println " JAVA_HOME (compile) : ${javaHome}"
128+
println " JDK Version (compile) : ${compilerJavaVersionDetails}"
129+
println " JAVA_HOME (compile) : ${compilerJavaHome}"
130+
println " JDK Version (runtime) : ${runtimeJavaVersionDetails}"
131+
println " JAVA_HOME (runtime) : ${runtimeJavaHome}"
123132
} else {
124133
println " JDK Version : ${gradleJavaVersionDetails}"
125134
println " JAVA_HOME : ${gradleJavaHome}"
@@ -135,54 +144,49 @@ class BuildPlugin implements Plugin<Project> {
135144
}
136145

137146
// enforce Java version
138-
if (javaVersionEnum < minimumJava) {
139-
throw new GradleException("Java ${minimumJava} or above is required to build Elasticsearch")
147+
if (compilerJavaVersionEnum < minimumCompilerVersion) {
148+
throw new GradleException("Java ${minimumCompilerVersion} or above is required to build Elasticsearch")
140149
}
141150

142-
// this block of code detecting buggy JDK 8 compiler versions can be removed when minimum Java version is incremented
143-
assert minimumJava == JavaVersion.VERSION_1_8 : "Remove JDK compiler bug detection only applicable to JDK 8"
144-
if (javaVersionEnum == JavaVersion.VERSION_1_8) {
145-
if (Objects.equals("Oracle Corporation", javaVendor)) {
146-
def matcher = javaVersion =~ /1\.8\.0(?:_(\d+))?/
147-
if (matcher.matches()) {
148-
int update;
149-
if (matcher.group(1) == null) {
150-
update = 0
151-
} else {
152-
update = matcher.group(1).toInteger()
153-
}
154-
if (update < 40) {
155-
throw new GradleException("JDK ${javaVendor} ${javaVersion} has compiler bug JDK-8052388, update your JDK to at least 8u40")
156-
}
157-
}
158-
}
151+
if (runtimeJavaVersionEnum < minimumRuntimeVersion) {
152+
throw new GradleException("Java ${minimumRuntimeVersion} or above is required to run Elasticsearch")
159153
}
160154

161-
project.rootProject.ext.javaHome = javaHome
162-
project.rootProject.ext.javaVersion = javaVersionEnum
155+
project.rootProject.ext.compilerJavaHome = compilerJavaHome
156+
project.rootProject.ext.runtimeJavaHome = runtimeJavaHome
157+
project.rootProject.ext.compilerJavaVersion = compilerJavaVersionEnum
158+
project.rootProject.ext.runtimeJavaVersion = runtimeJavaVersionEnum
163159
project.rootProject.ext.buildChecksDone = true
164160
}
165-
project.targetCompatibility = minimumJava
166-
project.sourceCompatibility = minimumJava
161+
162+
project.targetCompatibility = minimumRuntimeVersion
163+
project.sourceCompatibility = minimumRuntimeVersion
164+
167165
// set java home for each project, so they dont have to find it in the root project
168-
project.ext.javaHome = project.rootProject.ext.javaHome
169-
project.ext.javaVersion = project.rootProject.ext.javaVersion
166+
project.ext.compilerJavaHome = project.rootProject.ext.compilerJavaHome
167+
project.ext.runtimeJavaHome = project.rootProject.ext.runtimeJavaHome
168+
project.ext.compilerJavaVersion = project.rootProject.ext.compilerJavaVersion
169+
project.ext.runtimeJavaVersion = project.rootProject.ext.runtimeJavaVersion
170170
}
171171

172-
/** Finds and enforces JAVA_HOME is set */
173-
private static String findJavaHome() {
174-
String javaHome = System.getenv('JAVA_HOME')
172+
private static String findCompilerJavaHome() {
173+
final String javaHome = System.getenv('JAVA_HOME')
175174
if (javaHome == null) {
176175
if (System.getProperty("idea.active") != null || System.getProperty("eclipse.launcher") != null) {
177-
// intellij doesn't set JAVA_HOME, so we use the jdk gradle was run with
178-
javaHome = Jvm.current().javaHome
176+
// IntelliJ does not set JAVA_HOME, so we use the JDK that Gradle was run with
177+
return Jvm.current().javaHome
179178
} else {
180-
throw new GradleException('JAVA_HOME must be set to build Elasticsearch')
179+
throw new GradleException("JAVA_HOME must be set to build Elasticsearch")
181180
}
182181
}
183182
return javaHome
184183
}
185184

185+
private static String findRuntimeJavaHome(final String compilerJavaHome) {
186+
assert compilerJavaHome != null
187+
return System.getenv('RUNTIME_JAVA_HOME') ?: compilerJavaHome
188+
}
189+
186190
/** Finds printable java version of the given JAVA_HOME */
187191
private static String findJavaVersionDetails(Project project, String javaHome) {
188192
String versionInfoScript = 'print(' +
@@ -412,19 +416,19 @@ class BuildPlugin implements Plugin<Project> {
412416

413417
/** Adds compiler settings to the project */
414418
static void configureCompile(Project project) {
415-
if (project.javaVersion < JavaVersion.VERSION_1_10) {
419+
if (project.compilerJavaVersion < JavaVersion.VERSION_1_10) {
416420
project.ext.compactProfile = 'compact3'
417421
} else {
418422
project.ext.compactProfile = 'full'
419423
}
420424
project.afterEvaluate {
421425
project.tasks.withType(JavaCompile) {
422-
File gradleJavaHome = Jvm.current().javaHome
426+
final JavaVersion targetCompatibilityVersion = JavaVersion.toVersion(it.targetCompatibility)
423427
// we fork because compiling lots of different classes in a shared jvm can eventually trigger GC overhead limitations
424428
options.fork = true
425-
options.forkOptions.executable = new File(project.javaHome, 'bin/javac')
429+
options.forkOptions.javaHome = new File(project.compilerJavaHome)
426430
options.forkOptions.memoryMaximumSize = "1g"
427-
if (project.targetCompatibility >= JavaVersion.VERSION_1_8) {
431+
if (targetCompatibilityVersion == JavaVersion.VERSION_1_8) {
428432
// compile with compact 3 profile by default
429433
// NOTE: this is just a compile time check: does not replace testing with a compact3 JRE
430434
if (project.compactProfile != 'full') {
@@ -448,21 +452,18 @@ class BuildPlugin implements Plugin<Project> {
448452
options.encoding = 'UTF-8'
449453
options.incremental = true
450454

451-
if (project.javaVersion == JavaVersion.VERSION_1_9) {
452-
// hack until gradle supports java 9's new "--release" arg
453-
assert minimumJava == JavaVersion.VERSION_1_8
454-
options.compilerArgs << '--release' << '8'
455-
}
455+
// TODO: use native Gradle support for --release when available (cf. https://github.com/gradle/gradle/issues/2510)
456+
options.compilerArgs << '--release' << targetCompatibilityVersion.majorVersion
456457
}
457458
}
458459
}
459460

460461
static void configureJavadoc(Project project) {
461462
project.tasks.withType(Javadoc) {
462-
executable = new File(project.javaHome, 'bin/javadoc')
463+
executable = new File(project.compilerJavaHome, 'bin/javadoc')
463464
}
464465
configureJavadocJar(project)
465-
if (project.javaVersion == JavaVersion.VERSION_1_10) {
466+
if (project.compilerJavaVersion == JavaVersion.VERSION_1_10) {
466467
project.tasks.withType(Javadoc) { it.enabled = false }
467468
project.tasks.getByName('javadocJar').each { it.enabled = false }
468469
}
@@ -508,7 +509,7 @@ class BuildPlugin implements Plugin<Project> {
508509
'X-Compile-Lucene-Version': VersionProperties.lucene,
509510
'X-Compile-Elasticsearch-Snapshot': isSnapshot,
510511
'Build-Date': ZonedDateTime.now(ZoneOffset.UTC),
511-
'Build-Java-Version': project.javaVersion)
512+
'Build-Java-Version': project.compilerJavaVersion)
512513
if (jarTask.manifest.attributes.containsKey('Change') == false) {
513514
logger.warn('Building without git revision id.')
514515
jarTask.manifest.attributes('Change': 'Unknown')
@@ -545,7 +546,7 @@ class BuildPlugin implements Plugin<Project> {
545546
/** Returns a closure of common configuration shared by unit and integration tests. */
546547
static Closure commonTestConfig(Project project) {
547548
return {
548-
jvm "${project.javaHome}/bin/java"
549+
jvm "${project.runtimeJavaHome}/bin/java"
549550
parallelism System.getProperty('tests.jvms', 'auto')
550551
ifNoTests 'fail'
551552
onNonEmptyWorkDirectory 'wipe'

buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public class PluginBuildPlugin extends BuildPlugin {
169169
Files.copy(jarFile.resolveSibling(sourcesFileName), jarFile.resolveSibling(clientSourcesFileName),
170170
StandardCopyOption.REPLACE_EXISTING)
171171

172-
if (project.javaVersion < JavaVersion.VERSION_1_10) {
172+
if (project.compilerJavaVersion < JavaVersion.VERSION_1_10) {
173173
String javadocFileName = jarFile.fileName.toString().replace('.jar', '-javadoc.jar')
174174
String clientJavadocFileName = clientFileName.replace('.jar', '-javadoc.jar')
175175
Files.copy(jarFile.resolveSibling(javadocFileName), jarFile.resolveSibling(clientJavadocFileName),

buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/JarHellTask.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class JarHellTask extends LoggedExec {
4242
inputs.files(classpath)
4343
dependsOn(classpath)
4444
description = "Runs CheckJarHell on ${classpath}"
45-
executable = new File(project.javaHome, 'bin/java')
45+
executable = new File(project.runtimeJavaHome, 'bin/java')
4646
doFirst({
4747
/* JarHell doesn't like getting directories that don't exist but
4848
gradle isn't especially careful about that. So we have to do it

buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/LoggerUsageTask.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class LoggerUsageTask extends LoggedExec {
4444
project.afterEvaluate {
4545
dependsOn(classpath)
4646
description = "Runs LoggerUsageCheck on ${classDirectories}"
47-
executable = new File(project.javaHome, 'bin/java')
47+
executable = new File(project.runtimeJavaHome, 'bin/java')
4848
if (classDirectories == null) {
4949
// Default to main and test class files
5050
List files = []

buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/NamingConventionsTask.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public class NamingConventionsTask extends LoggedExec {
8080
FileCollection classpath = project.sourceSets.test.runtimeClasspath
8181
inputs.files(classpath)
8282
description = "Tests that test classes aren't misnamed or misplaced"
83-
executable = new File(project.javaHome, 'bin/java')
83+
executable = new File(project.runtimeJavaHome, 'bin/java')
8484
if (false == checkForTestsInMain) {
8585
/* This task is created by default for all subprojects with this
8686
* setting and there is no point in running it if the files don't

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ class ClusterFormationTasks {
655655
String pid = node.pidFile.getText('UTF-8')
656656
ByteArrayOutputStream output = new ByteArrayOutputStream()
657657
project.exec {
658-
commandLine = ["${project.javaHome}/bin/jstack", pid]
658+
commandLine = ["${project.runtimeJavaHome}/bin/jstack", pid]
659659
standardOutput = output
660660
}
661661
output.toString('UTF-8').eachLine { line -> logger.error("| ${line}") }
@@ -699,7 +699,7 @@ class ClusterFormationTasks {
699699
}
700700

701701
private static File getJpsExecutableByName(Project project, String jpsExecutableName) {
702-
return Paths.get(project.javaHome.toString(), "bin/" + jpsExecutableName).toFile()
702+
return Paths.get(project.runtimeJavaHome.toString(), "bin/" + jpsExecutableName).toFile()
703703
}
704704

705705
/** Adds a task to kill an elasticsearch node with the given pidfile */

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/NodeInfo.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class NodeInfo {
162162
args.add("${esScript}")
163163
}
164164

165-
env = ['JAVA_HOME': project.javaHome]
165+
env = ['JAVA_HOME': project.runtimeJavaHome]
166166
args.addAll("-E", "node.portsfile=true")
167167
String collectedSystemProperties = config.systemProperties.collect { key, value -> "-D${key}=${value}" }.join(" ")
168168
String esJavaOpts = config.jvmArgs.isEmpty() ? collectedSystemProperties : collectedSystemProperties + " " + config.jvmArgs

client/rest-high-level/src/main/java/org/elasticsearch/client/Request.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.elasticsearch.action.bulk.BulkRequest;
3636
import org.elasticsearch.action.delete.DeleteRequest;
3737
import org.elasticsearch.action.get.GetRequest;
38+
import org.elasticsearch.action.get.MultiGetRequest;
3839
import org.elasticsearch.action.index.IndexRequest;
3940
import org.elasticsearch.action.search.ClearScrollRequest;
4041
import org.elasticsearch.action.search.MultiSearchRequest;
@@ -312,6 +313,15 @@ static Request get(GetRequest getRequest) {
312313
return new Request(HttpGet.METHOD_NAME, endpoint, parameters.getParams(), null);
313314
}
314315

316+
static Request multiGet(MultiGetRequest multiGetRequest) throws IOException {
317+
Params parameters = Params.builder();
318+
parameters.withPreference(multiGetRequest.preference());
319+
parameters.withRealtime(multiGetRequest.realtime());
320+
parameters.withRefresh(multiGetRequest.refresh());
321+
HttpEntity entity = createEntity(multiGetRequest, REQUEST_BODY_CONTENT_TYPE);
322+
return new Request(HttpGet.METHOD_NAME, "/_mget", parameters.getParams(), entity);
323+
}
324+
315325
static Request index(IndexRequest indexRequest) {
316326
String method = Strings.hasLength(indexRequest.id()) ? HttpPut.METHOD_NAME : HttpPost.METHOD_NAME;
317327

client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import org.elasticsearch.action.delete.DeleteResponse;
3535
import org.elasticsearch.action.get.GetRequest;
3636
import org.elasticsearch.action.get.GetResponse;
37+
import org.elasticsearch.action.get.MultiGetRequest;
38+
import org.elasticsearch.action.get.MultiGetResponse;
3739
import org.elasticsearch.action.index.IndexRequest;
3840
import org.elasticsearch.action.index.IndexResponse;
3941
import org.elasticsearch.action.main.MainRequest;
@@ -289,6 +291,25 @@ public final void getAsync(GetRequest getRequest, ActionListener<GetResponse> li
289291
performRequestAsyncAndParseEntity(getRequest, Request::get, GetResponse::fromXContent, listener, singleton(404), headers);
290292
}
291293

294+
/**
295+
* Retrieves multiple documents by id using the Multi Get API
296+
*
297+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html">Multi Get API on elastic.co</a>
298+
*/
299+
public final MultiGetResponse multiGet(MultiGetRequest multiGetRequest, Header... headers) throws IOException {
300+
return performRequestAndParseEntity(multiGetRequest, Request::multiGet, MultiGetResponse::fromXContent, singleton(404), headers);
301+
}
302+
303+
/**
304+
* Asynchronously retrieves multiple documents by id using the Multi Get API
305+
*
306+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html">Multi Get API on elastic.co</a>
307+
*/
308+
public void multiGetAsync(MultiGetRequest multiGetRequest, ActionListener<MultiGetResponse> listener, Header... headers) {
309+
performRequestAsyncAndParseEntity(multiGetRequest, Request::multiGet, MultiGetResponse::fromXContent, listener,
310+
singleton(404), headers);
311+
}
312+
292313
/**
293314
* Checks for the existence of a document. Returns true if it exists, false otherwise
294315
*

0 commit comments

Comments
 (0)