Skip to content

Commit 98a94c0

Browse files
Merge branch '9.1' into backport/9.1/pr-137222
2 parents 2d7856e + 31d6234 commit 98a94c0

File tree

23 files changed

+642
-72
lines changed

23 files changed

+642
-72
lines changed

build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/transport/TransportVersionGenerationFuncTest.groovy

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,4 +513,19 @@ class TransportVersionGenerationFuncTest extends AbstractTransportVersionFuncTes
513513
assertGenerateAndValidateSuccess(result)
514514
assertUpperBound("9.2", "existing_92,8123000")
515515
}
516+
517+
def "generation cannot run on release branch"() {
518+
given:
519+
file("myserver/build.gradle") << """
520+
tasks.named('generateTransportVersion') {
521+
currentUpperBoundName = '9.1'
522+
}
523+
"""
524+
525+
when:
526+
def result = runGenerateTask().buildAndFail()
527+
528+
then:
529+
assertGenerateFailure(result, "Transport version generation cannot run on release branches")
530+
}
516531
}

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.Arrays;
4545
import java.util.List;
4646
import java.util.Optional;
47+
import java.util.concurrent.TimeUnit;
4748

4849
import javax.inject.Inject;
4950

@@ -178,7 +179,11 @@ public void execute(BuildFinishedFlowAction.Parameters parameters) throws FileNo
178179
try {
179180
// we are very generious here, as the upload can take
180181
// a long time depending on its size
181-
pb.start().waitFor(30, java.util.concurrent.TimeUnit.MINUTES);
182+
long timeoutSec = calculateUploadWaitTimeoutSeconds(uploadFile);
183+
boolean completedInTime = pb.start().waitFor(timeoutSec, TimeUnit.SECONDS);
184+
if (completedInTime == false) {
185+
System.out.println("Timed out waiting for buildkite artifact upload after " + timeoutSec + " seconds");
186+
}
182187
} catch (InterruptedException e) {
183188
System.out.println("Failed to upload buildkite artifact " + e.getMessage());
184189
}
@@ -278,5 +283,14 @@ private static void createBuildArchiveTar(List<File> files, File projectDir, Fil
278283
private static String calculateArchivePath(Path path, Path projectPath) {
279284
return path.startsWith(projectPath) ? projectPath.relativize(path).toString() : path.getFileName().toString();
280285
}
286+
287+
private static long calculateUploadWaitTimeoutSeconds(File file) {
288+
long fileSizeBytes = file.length();
289+
long fileSizeMB = fileSizeBytes / (1024 * 1024);
290+
291+
// Allocate 4 seconds per MB (assumes ~250 KB/s upload speed)
292+
// with min 10 seconds and max 30 minutes
293+
return Math.max(10, Math.min(1800, fileSizeMB * 4));
294+
}
281295
}
282296
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ public abstract class GenerateTransportVersionDefinitionTask extends DefaultTask
9696
@TaskAction
9797
public void run() throws IOException {
9898
TransportVersionResourcesService resources = getResourceService().get();
99+
List<TransportVersionUpperBound> upstreamUpperBounds = resources.getUpperBoundsFromGitBase();
100+
boolean onReleaseBranch = resources.checkIfDefinitelyOnReleaseBranch(upstreamUpperBounds, getCurrentUpperBoundName().get());
101+
if (onReleaseBranch) {
102+
throw new IllegalArgumentException("Transport version generation cannot run on release branches");
103+
}
104+
99105
Set<String> referencedNames = TransportVersionReference.collectNames(getReferencesFiles());
100106
Set<String> changedDefinitionNames = resources.getChangedReferableDefinitionNames();
101107
String targetDefinitionName = getTargetDefinitionName(resources, referencedNames, changedDefinitionNames);
@@ -109,7 +115,7 @@ public void run() throws IOException {
109115
resetAllUpperBounds(resources, idsByBase);
110116
} else {
111117
getLogger().lifecycle("Generating transport version name: " + targetDefinitionName);
112-
List<TransportVersionUpperBound> upstreamUpperBounds = resources.getUpperBoundsFromGitBase();
118+
113119
Set<String> targetUpperBoundNames = getTargetUpperBoundNames(resources, upstreamUpperBounds, targetDefinitionName);
114120

115121
List<TransportVersionId> ids = updateUpperBounds(

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.nio.file.Files;
2626
import java.nio.file.Path;
2727
import java.util.ArrayList;
28+
import java.util.Collection;
2829
import java.util.Collections;
2930
import java.util.Comparator;
3031
import java.util.HashMap;
@@ -259,6 +260,20 @@ private Path getUpperBoundRelativePath(String name) {
259260
return UPPER_BOUNDS_DIR.resolve(name + ".csv");
260261
}
261262

263+
boolean checkIfDefinitelyOnReleaseBranch(Collection<TransportVersionUpperBound> upperBounds, String currentUpperBoundName) {
264+
// only want to look at definitions <= the current upper bound.
265+
// TODO: we should filter all of the upper bounds/definitions that are validated by this, not just in this method
266+
TransportVersionUpperBound currentUpperBound = upperBounds.stream()
267+
.filter(u -> u.name().equals(currentUpperBoundName))
268+
.findFirst()
269+
.orElse(null);
270+
if (currentUpperBound == null) {
271+
// since there is no current upper bound, we don't know if we are on a release branch
272+
return false;
273+
}
274+
return upperBounds.stream().anyMatch(u -> u.definitionId().complete() > currentUpperBound.definitionId().complete());
275+
}
276+
262277
private String getBaseRefName() {
263278
if (baseRefName.get() == null) {
264279
synchronized (baseRefName) {

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void validateTransportVersions() throws IOException {
8484
Map<Integer, List<IdAndDefinition>> idsByBase = resources.getIdsByBase();
8585
Map<String, TransportVersionUpperBound> upperBounds = resources.getUpperBounds();
8686
TransportVersionUpperBound currentUpperBound = upperBounds.get(getCurrentUpperBoundName().get());
87-
boolean onReleaseBranch = checkIfDefinitelyOnReleaseBranch(upperBounds);
87+
boolean onReleaseBranch = resources.checkIfDefinitelyOnReleaseBranch(upperBounds.values(), getCurrentUpperBoundName().get());
8888
boolean validateModifications = onReleaseBranch == false || getCI().get();
8989

9090
for (var definition : referableDefinitions.values()) {
@@ -330,15 +330,6 @@ private void validatePrimaryIds(
330330
);
331331
}
332332

333-
private boolean checkIfDefinitelyOnReleaseBranch(Map<String, TransportVersionUpperBound> upperBounds) {
334-
// only want to look at definitions <= the current upper bound.
335-
// TODO: we should filter all of the upper bounds/definitions that are validated by this, not just in this method
336-
String currentUpperBoundName = getCurrentUpperBoundName().get();
337-
TransportVersionUpperBound currentUpperBound = upperBounds.get(currentUpperBoundName);
338-
339-
return upperBounds.values().stream().anyMatch(u -> u.definitionId().complete() > currentUpperBound.definitionId().complete());
340-
}
341-
342333
private void throwDefinitionFailure(TransportVersionDefinition definition, String message) {
343334
Path relativePath = getResources().get().getDefinitionPath(definition);
344335
throw new VerificationException("Transport version definition file [" + relativePath + "] " + message);

docs/changelog/137442.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 137442
2+
summary: Handle ._original stored fields with fls
3+
area: "Authorization"
4+
type: bug
5+
issues: []

modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/MatchOnlyTextFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public MatchOnlyTextFieldType(
208208
super(name, true, false, false, tsi, meta);
209209
this.indexAnalyzer = Objects.requireNonNull(indexAnalyzer);
210210
this.textFieldType = new TextFieldType(name, isSyntheticSource, syntheticSourceDelegate);
211-
this.originalName = isSyntheticSource ? name + "._original" : null;
211+
this.originalName = isSyntheticSource ? name + KeywordFieldMapper.FALLBACK_FIELD_NAME_SUFFIX : null;
212212
this.withinMultiField = withinMultiField;
213213
this.storedFieldInBinaryFormat = storedFieldInBinaryFormat;
214214
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.packaging.test;
11+
12+
import org.elasticsearch.packaging.util.Platforms;
13+
import org.elasticsearch.packaging.util.ProcessInfo;
14+
import org.junit.BeforeClass;
15+
16+
import java.util.List;
17+
18+
import static com.carrotsearch.randomizedtesting.RandomizedTest.assumeTrue;
19+
import static org.hamcrest.Matchers.equalTo;
20+
21+
// tests for how the linux distro interacts with the OS
22+
public class LinuxSystemTests extends PackagingTestCase {
23+
24+
@BeforeClass
25+
public static void ensureLinux() {
26+
assumeTrue(Platforms.LINUX);
27+
}
28+
29+
public void test10Install() throws Exception {
30+
install();
31+
}
32+
33+
public void test20CoredumpFilter() throws Exception {
34+
startElasticsearch();
35+
36+
// find the Elasticsearch process
37+
int esPid = -1;
38+
List<ProcessInfo> procs = ProcessInfo.getProcessInfo(sh, "java");
39+
for (ProcessInfo proc : procs) {
40+
if (proc.commandLine().contains("org.elasticsearch.bootstrap.Elasticsearch")) {
41+
esPid = proc.pid();
42+
}
43+
}
44+
if (esPid == -1) {
45+
fail("Could not find Elasticsearch process, existing processes:\n" + procs);
46+
}
47+
48+
// check the coredump filter was set correctly
49+
String coredumpFilter = sh.run("cat /proc/" + esPid + "/coredump_filter").stdout().trim();
50+
assertThat(coredumpFilter, equalTo("00000023"));
51+
}
52+
53+
}

qa/packaging/src/test/java/org/elasticsearch/packaging/util/ProcessInfo.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* works in Linux containers. At the moment that isn't a problem, because we only publish Docker images
2323
* for Linux.
2424
*/
25-
public record ProcessInfo(int pid, int uid, int gid, String username, String group) {
25+
public record ProcessInfo(int pid, int uid, int gid, String username, String group, String commandLine) {
2626

2727
/**
2828
* Fetches process information about <code>command</code>, using <code>sh</code> to execute commands.
@@ -53,7 +53,9 @@ public static List<ProcessInfo> getProcessInfo(Shell sh, String command) {
5353
final String username = sh.run("getent passwd " + uid + " | cut -f1 -d:").stdout().trim();
5454
final String group = sh.run("getent group " + gid + " | cut -f1 -d:").stdout().trim();
5555

56-
infos.add(new ProcessInfo(pid, uid, gid, username, group));
56+
final String commandLine = sh.run("cat /proc/" + pid + "/cmdline").stdout().trim();
57+
58+
infos.add(new ProcessInfo(pid, uid, gid, username, group, commandLine));
5759
}
5860
return Collections.unmodifiableList(infos);
5961
}

server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,10 @@ static void initializeNatives(final Path tmpFile, final boolean mlockAll, final
484484
}
485485
}
486486

487+
if (IOUtils.LINUX) {
488+
setCoredumpFilter();
489+
}
490+
487491
// init lucene random seed. it will use /dev/urandom where available:
488492
StringHelper.randomId();
489493
}
@@ -598,6 +602,20 @@ static Map<String, Set<String>> findPluginsWithNativeAccess(Map<String, Policy>
598602
return pluginsWithNativeAccess;
599603
}
600604

605+
@SuppressForbidden(reason = "access proc filesystem")
606+
private static void setCoredumpFilter() {
607+
// The coredump filter determines which types of memory are added to core dumps. By default, Java
608+
// includes memory mapped files, bits 2 and 3. Here we disable those bits. Note that the VM
609+
// has special options to disable these, but the filter is then inherited from the parent process
610+
// which is the server CLI, which is also a JVM so it has these bits set. Thus, we set it explicitly.
611+
// See https://man7.org/linux/man-pages/man5/core.5.html for more info on the relevant bits of the filter
612+
try {
613+
Files.writeString(Path.of("/proc/self/coredump_filter"), "0x23");
614+
} catch (IOException e) {
615+
throw new RuntimeException("Could not set coredump filter", e);
616+
}
617+
}
618+
601619
// -- instance
602620

603621
private static volatile Elasticsearch INSTANCE;

0 commit comments

Comments
 (0)