Only flush to disk on chunk saves if paper.flush-on-save is true (#1942)

The cost of a call to sync() adds up quickly and especially for
HDDs. Playing around generating chunks for a while warranted a
3 min save time on a HDD. This is unacceptable default behaviour
and now the behaviour is hidden behind a flag for server owners
who are OK with taking a hit on saves (although SSDs will not have
this issue remotely as bad, since most of the time was spent seeking).
This commit is contained in:
Spottedleaf 2019-04-06 02:59:42 -07:00
parent 84f63e360a
commit 6719e61704

View file

@ -11,9 +11,9 @@ Now the saving process has been changed to follow this chain of events:
overwrite and corrupt the current data
2. Write the chunk data first (the order of the fields in
the chunk data isn't relevant though)
3. Flush to disk
3. Flush to disk (if the launch flag is used)
4. Write to the region header last
5. Flush to disk
5. Flush to disk (if the launch flag is used)
6. Then we free the previous space allocated
With this chain of events it is impossible for a chunk write to corrupt
@ -27,12 +27,17 @@ Note that when Mojang finally decides to change their region format
to deal with oversized chunks this patch must be changed to deal with
whatever system they decide to impose.
If the paper.flush-on-save startup flag is set to true, then the
steps 3 and 5 will make a call to sync() on the region file's fd,
effectively flushing to disk.
We also make use of two flushes to disk per chunk save (to ensure
ordering and ensure data has gone to disk), so this will negatively
affect save performance.
affect save performance if the startup flag is used (especially on
HDDs).
diff --git a/src/main/java/net/minecraft/server/RegionFile.java b/src/main/java/net/minecraft/server/RegionFile.java
index 82f7af46f..2e2844133 100644
index 82f7af46f..e5659980b 100644
--- a/src/main/java/net/minecraft/server/RegionFile.java
+++ b/src/main/java/net/minecraft/server/RegionFile.java
@@ -0,0 +0,0 @@ public class RegionFile {
@ -149,7 +154,11 @@ index 82f7af46f..2e2844133 100644
}
// Paper start
+ private static final boolean FLUSH_ON_SAVE = Boolean.getBoolean("paper.flush-on-save");
+ private void syncRegionFile() throws IOException {
+ if (!FLUSH_ON_SAVE) {
+ return;
+ }
+ this.getDataFile().getFD().sync(); // rethrow exception as we want to avoid corrupting a regionfile
+ }
+