-
Notifications
You must be signed in to change notification settings - Fork 25.4k
Use JNA to Speed up Snapshot Cache File Creation #68687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use JNA to Speed up Snapshot Cache File Creation #68687
Conversation
Use JNA to speed up snapshot cache file creation. Do this in `:server` to bypass the security filter and move necessary bits of code to `:server` to enable the logic. Fall back to trying to create the file by writing zeros if anything except for the step determining free disk space fails.
Pinging @elastic/es-distributed (Team:Distributed) |
@@ -260,4 +269,39 @@ static void tryInstallSystemCallFilter(Path tmpFile) { | |||
logger.warn("unable to install syscall filter: ", e); | |||
} | |||
} | |||
|
|||
@SuppressForbidden(reason = "need access to fd on FileOutputStream") | |||
static void fallocateSnapshotCacheFile(Environment environment, long fileSize) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a little unfortunate to leak that much logic into this class, but I figured abstracting things away further to isolate the fallocate
as much as possible wasn't really worth the extra complication (IMO).
server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java
Outdated
Show resolved
Hide resolved
@elasticmachine update branch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Would like to see a review from one more person before merge
server/src/main/java/org/elasticsearch/bootstrap/JNANatives.java
Outdated
Show resolved
Hide resolved
This was caused by elastic#68709 which turned the edge case of a range with start > end into a tripped assertion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
*/ | ||
public static void tryCreateCacheFile(Environment environment, long fileSize) throws IOException { | ||
if (JNA_AVAILABLE == false) { | ||
logger.warn("cannot use fallocate to create cache file because JNA is not available"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I know we are not consistent in starting log messages with uppercase or not but we're using both ways in this PR
server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java
Outdated
Show resolved
Hide resolved
Thanks Yannick + Tanguy! |
Use JNA to speed up snapshot cache file creation. Do this in `:server` to bypass the security filter and move necessary bits of code to `:server` to enable the logic. Fall back to trying to create the file by writing zeros if anything except for the step determining free disk space fails.
Use JNA to speed up snapshot cache file creation. Do this in `:server` to bypass the security filter and move necessary bits of code to `:server` to enable the logic. Fall back to trying to create the file by writing zeros if anything except for the step determining free disk space fails.
Reverted in 4c2e9a6 because it broke local development on a mac. (Sorry!) |
Second go at elastic#68687 now using the proper indirection so that this works on both OSX and Linux. We can't use the same class we use for `mlock` like the original PR did because the method signature differs across OSX and Linux.
Second go at #68687 now using the proper indirection so that this works on both OSX and Linux. We can't use the same class we use for `mlock` like the original PR did because the method signature differs across OSX and Linux.
Second go at elastic#68687 now using the proper indirection so that this works on both OSX and Linux. We can't use the same class we use for `mlock` like the original PR did because the method signature differs across OSX and Linux.
Use JNA to speed up snapshot cache file creation. Do this in
:server
to bypass the security filter and move necessary bits of code to
:server
to enable the logic.
Fall back to trying to create the file by writing zeros if anything except for
the step determining free disk space fails.
Manually verified via
du
that this works as expected and actually allocates hundreds of GB in a fewms
.