-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move shared cache pre-allocation and support macOS (#70331)
This commit moves the shared cache pre-allocation code out of bootstrap, and instead to the searchable snapshots code. We go out of our way to only grant permissions to a specific library used for the pre-allocation. Additionally, to ensure our interfaces are sound, we add a macOS implementation based on fcntl and ftruncate. Co-authored-by: Yannick Welsch <yannick@welsch.lu>
- Loading branch information
1 parent
13946ea
commit 77b968c
Showing
26 changed files
with
429 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 0 additions & 57 deletions
57
server/src/main/java/org/elasticsearch/bootstrap/JNAFalloc.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
x-pack/plugin/searchable-snapshots/preallocate/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
apply plugin: 'elasticsearch.build' | ||
|
||
archivesBaseName = 'preallocate' | ||
|
||
dependencies { | ||
compileOnly project(":server") | ||
} | ||
|
||
tasks.named("testingConventions").configure { enabled = false } |
55 changes: 55 additions & 0 deletions
55
.../main/java/org/elasticsearch/xpack/searchablesnapshots/preallocate/LinuxPreallocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.searchablesnapshots.preallocate; | ||
|
||
import com.sun.jna.Native; | ||
import com.sun.jna.Platform; | ||
|
||
import java.security.AccessController; | ||
import java.security.PrivilegedAction; | ||
|
||
final class LinuxPreallocator implements Preallocator { | ||
|
||
@Override | ||
public boolean available() { | ||
return Natives.NATIVES_AVAILABLE; | ||
} | ||
|
||
@Override | ||
public int preallocate(final int fd, final long currentSize, final long fileSize) { | ||
final int rc = Natives.fallocate(fd, 0, currentSize, fileSize - currentSize); | ||
return rc == 0 ? 0 : Native.getLastError(); | ||
} | ||
|
||
@Override | ||
public String error(int errno) { | ||
return Natives.strerror(errno); | ||
} | ||
|
||
private static class Natives { | ||
|
||
public static final boolean NATIVES_AVAILABLE; | ||
|
||
static { | ||
NATIVES_AVAILABLE = AccessController.doPrivileged((PrivilegedAction<Boolean>) () -> { | ||
try { | ||
Native.register(Natives.class, Platform.C_LIBRARY_NAME); | ||
} catch (final UnsatisfiedLinkError e) { | ||
return false; | ||
} | ||
return true; | ||
}); | ||
} | ||
|
||
static native int fallocate(int fd, int mode, long offset, long length); | ||
|
||
static native String strerror(int errno); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.