Skip to content

Commit

Permalink
Fix windows memory locking (#111866) (#111935)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rjernst authored Aug 15, 2024
1 parent 8ab481c commit 5567772
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/changelog/111866.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 111866
summary: Fix windows memory locking
area: Infra/Core
type: bug
issues:
- 111847
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class JdkKernel32Library implements Kernel32Library {
);
private static final MethodHandle SetProcessWorkingSetSize$mh = downcallHandleWithError(
"SetProcessWorkingSetSize",
FunctionDescriptor.of(ADDRESS, JAVA_LONG, JAVA_LONG)
FunctionDescriptor.of(JAVA_BOOLEAN, ADDRESS, JAVA_LONG, JAVA_LONG)
);
private static final MethodHandle GetShortPathNameW$mh = downcallHandleWithError(
"GetShortPathNameW",
Expand Down Expand Up @@ -94,7 +94,7 @@ static class JdkAddress implements Address {

@Override
public Address add(long offset) {
return new JdkAddress(MemorySegment.ofAddress(address.address()));
return new JdkAddress(MemorySegment.ofAddress(address.address() + offset));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.packaging.test;

import org.elasticsearch.packaging.util.ServerUtils;
import org.elasticsearch.packaging.util.docker.DockerRun;

import java.util.Map;

import static org.elasticsearch.packaging.util.docker.Docker.runContainer;
import static org.elasticsearch.packaging.util.docker.DockerRun.builder;

public class MemoryLockingTests extends PackagingTestCase {

public void test10Install() throws Exception {
install();
}

public void test20MemoryLockingEnabled() throws Exception {
configureAndRun(
Map.of(
"bootstrap.memory_lock",
"true",
"xpack.security.enabled",
"false",
"xpack.security.http.ssl.enabled",
"false",
"xpack.security.enrollment.enabled",
"false",
"discovery.type",
"single-node"
)
);
// TODO: very locking worked. logs? check memory of process? at least we know the process started successfully
stopElasticsearch();
}

public void configureAndRun(Map<String, String> settings) throws Exception {
if (distribution().isDocker()) {
DockerRun builder = builder();
settings.forEach(builder::envVar);
runContainer(distribution(), builder);
} else {

for (var setting : settings.entrySet()) {
ServerUtils.addSettingToExistingConfiguration(installation.config, setting.getKey(), setting.getValue());
}
ServerUtils.removeSettingFromExistingConfiguration(installation.config, "cluster.initial_master_nodes");
}

startElasticsearch();
}
}

0 comments on commit 5567772

Please sign in to comment.