spigot/CraftBukkit-Patches/0050-Improve-AutoSave-Mechanism.patch

88 lines
4 KiB
Diff
Raw Normal View History

2018-07-22 12:00:00 +10:00
From 3601e4b8cca85b621936b3a6fd09df3a7a5d54f1 Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Sun, 12 Jan 2014 21:07:18 +1100
Subject: [PATCH] Improve AutoSave Mechanism
The problem here is that MinecraftServer.save(..), will attempt to sleep whilst all pending chunks are written to disk.
however due to various and complicated bugs, it will wait for an incorrect amount of chunks, which may cause it to sleep for an overly long amount of time.
Instead we will mimic the save-all command in its behaviour, which is both safe and performant.
Also, only save modified chunks, or chunks with entities after 4 auto save passes
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
2018-07-22 12:00:00 +10:00
index 7f18563e7..d5aaf872a 100644
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
2018-07-15 10:00:00 +10:00
@@ -904,7 +904,7 @@ public class Chunk implements IChunkAccess {
if (this.w && this.world.getTime() != this.lastSaved || this.y) {
return true;
}
2018-07-15 10:00:00 +10:00
- } else if (this.w && this.world.getTime() >= this.lastSaved + 600L) {
+ } else if (this.w && this.world.getTime() >= this.lastSaved + MinecraftServer.getServer().autosavePeriod * 4) { // Spigot - Only save if we've passed 2 auto save intervals without modification
return true;
}
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
2018-07-22 12:00:00 +10:00
index 3e719d5cd..62925a0c7 100644
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
2018-07-15 10:00:00 +10:00
@@ -250,7 +250,7 @@ public class ChunkProviderServer implements IChunkProvider {
this.saveChunk(chunk);
2018-07-15 10:00:00 +10:00
chunk.a(false);
++i;
- if (i == 24 && !flag) {
2015-06-16 10:24:54 +01:00
+ if (i == 24 && !flag && false) { // Spigot
return false;
}
}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
2018-07-22 12:00:00 +10:00
index 0c776692b..7aa788871 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2018-07-22 12:00:00 +10:00
@@ -805,7 +805,17 @@ public abstract class MinecraftServer implements IAsyncTaskHandler, IMojangStati
SpigotTimings.worldSaveTimer.startTiming(); // Spigot
this.methodProfiler.a("save");
2018-07-15 10:00:00 +10:00
this.s.savePlayers();
- this.saveChunks(true);
+ // Spigot Start
+ // We replace this with saving each individual world as this.saveChunks(...) is broken,
+ // and causes the main thread to sleep for random amounts of time depending on chunk activity
+ // Also pass flag to only save modified chunks
+ server.playerCommandState = true;
+ for (World world : worlds) {
+ world.getWorld().save(false);
+ }
+ server.playerCommandState = false;
+ // this.saveChunks(true);
+ // Spigot End
2018-07-15 10:00:00 +10:00
this.methodProfiler.e();
SpigotTimings.worldSaveTimer.stopTiming(); // Spigot
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2018-07-22 12:00:00 +10:00
index c6faa4bfe..1834fae6c 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2018-07-15 10:00:00 +10:00
@@ -727,12 +727,17 @@ public class CraftWorld implements World {
}
public void save() {
+ // Spigot start
+ save(true);
+ }
+ public void save(boolean forceSave) {
+ // Spigot end
this.server.checkSaveState();
try {
boolean oldSave = world.savingDisabled;
world.savingDisabled = false;
- world.save(true, null);
+ world.save(forceSave, null); // Spigot
world.savingDisabled = oldSave;
} catch (ExceptionWorldConflict ex) {
--
2018-07-15 10:00:00 +10:00
2.17.1