Skip to content

Commit d74a749

Browse files
rjernstcbuescher
authored andcommitted
Fix windows memory locking (elastic#111866)
Memory locking on Windows with the bundled jdk was broken by native access refactoring. This commit fixes the linking issue, as well as adds a packaging test to ensure memory locking is invoked on all supported platforms.
1 parent c72e213 commit d74a749

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

docs/changelog/111866.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 111866
2+
summary: Fix windows memory locking
3+
area: Infra/Core
4+
type: bug
5+
issues:
6+
- 111847

libs/native/src/main21/java/org/elasticsearch/nativeaccess/jdk/JdkKernel32Library.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class JdkKernel32Library implements Kernel32Library {
5656
);
5757
private static final MethodHandle SetProcessWorkingSetSize$mh = downcallHandleWithError(
5858
"SetProcessWorkingSetSize",
59-
FunctionDescriptor.of(ADDRESS, JAVA_LONG, JAVA_LONG)
59+
FunctionDescriptor.of(JAVA_BOOLEAN, ADDRESS, JAVA_LONG, JAVA_LONG)
6060
);
6161
private static final MethodHandle GetCompressedFileSizeW$mh = downcallHandleWithError(
6262
"GetCompressedFileSizeW",
@@ -115,7 +115,7 @@ static class JdkAddress implements Address {
115115

116116
@Override
117117
public Address add(long offset) {
118-
return new JdkAddress(MemorySegment.ofAddress(address.address()));
118+
return new JdkAddress(MemorySegment.ofAddress(address.address() + offset));
119119
}
120120
}
121121

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.packaging.test;
10+
11+
import org.elasticsearch.packaging.util.ServerUtils;
12+
import org.elasticsearch.packaging.util.docker.DockerRun;
13+
14+
import java.util.Map;
15+
16+
import static org.elasticsearch.packaging.util.docker.Docker.runContainer;
17+
import static org.elasticsearch.packaging.util.docker.DockerRun.builder;
18+
19+
public class MemoryLockingTests extends PackagingTestCase {
20+
21+
public void test10Install() throws Exception {
22+
install();
23+
}
24+
25+
public void test20MemoryLockingEnabled() throws Exception {
26+
configureAndRun(
27+
Map.of(
28+
"bootstrap.memory_lock",
29+
"true",
30+
"xpack.security.enabled",
31+
"false",
32+
"xpack.security.http.ssl.enabled",
33+
"false",
34+
"xpack.security.enrollment.enabled",
35+
"false",
36+
"discovery.type",
37+
"single-node"
38+
)
39+
);
40+
// TODO: very locking worked. logs? check memory of process? at least we know the process started successfully
41+
stopElasticsearch();
42+
}
43+
44+
public void configureAndRun(Map<String, String> settings) throws Exception {
45+
if (distribution().isDocker()) {
46+
DockerRun builder = builder();
47+
settings.forEach(builder::envVar);
48+
runContainer(distribution(), builder);
49+
} else {
50+
51+
for (var setting : settings.entrySet()) {
52+
ServerUtils.addSettingToExistingConfiguration(installation.config, setting.getKey(), setting.getValue());
53+
}
54+
ServerUtils.removeSettingFromExistingConfiguration(installation.config, "cluster.initial_master_nodes");
55+
}
56+
57+
startElasticsearch();
58+
}
59+
}

0 commit comments

Comments
 (0)