diff --git a/Spigot-Server-Patches/Make-region-files-more-reliable-to-write-to.patch b/Spigot-Server-Patches/Make-region-files-more-reliable-to-write-to.patch index a96a272b27..5cc9febf1c 100644 --- a/Spigot-Server-Patches/Make-region-files-more-reliable-to-write-to.patch +++ b/Spigot-Server-Patches/Make-region-files-more-reliable-to-write-to.patch @@ -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 + } +