2016-03-03 07:04:36 +01:00
From d84fad458d80f1cae8913ac4f0356868df9a6344 Mon Sep 17 00:00:00 2001
2014-12-06 04:33:40 +01:00
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
2016-02-29 22:33:06 +01:00
index 47ef0db..277a6ad 100644
2014-12-06 04:33:40 +01:00
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
2016-02-29 22:33:06 +01:00
@@ -875,7 +875,7 @@ public class Chunk {
if (this.s && this.world.getTime() != this.lastSaved || this.r) {
2014-12-06 04:33:40 +01:00
return true;
}
2016-02-29 22:33:06 +01:00
- } else if (this.s && this.world.getTime() >= this.lastSaved + 600L) {
+ } else if (this.s && this.world.getTime() >= this.lastSaved + MinecraftServer.getServer().autosavePeriod * 4) { // Spigot - Only save if we've passed 2 auto save intervals without modification
2014-12-06 04:33:40 +01:00
return true;
}
2015-06-16 11:19:25 +02:00
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
2016-03-03 07:04:36 +01:00
index 780919a..21e7709 100644
2015-06-16 11:19:25 +02:00
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
2016-03-03 07:04:36 +01:00
@@ -258,7 +258,7 @@ public class ChunkProviderServer implements IChunkProvider {
2015-06-16 11:19:25 +02:00
this.saveChunk(chunk);
chunk.f(false);
++i;
- if (i == 24 && !flag) {
2015-06-16 11:24:54 +02:00
+ if (i == 24 && !flag && false) { // Spigot
2015-06-16 11:19:25 +02:00
return false;
}
}
2014-12-06 04:33:40 +01:00
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
2016-03-01 20:39:42 +01:00
index dfe3305..bd2837c 100644
2014-12-06 04:33:40 +01:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2016-03-01 20:39:42 +01:00
@@ -660,7 +660,17 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
2014-12-06 04:33:40 +01:00
SpigotTimings.worldSaveTimer.startTiming(); // Spigot
this.methodProfiler.a("save");
this.v.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
this.methodProfiler.b();
SpigotTimings.worldSaveTimer.stopTiming(); // Spigot
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2016-03-03 07:04:36 +01:00
index 29f6cff..c63f4d5 100644
2014-12-06 04:33:40 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2016-02-29 22:33:06 +01:00
@@ -732,12 +732,17 @@ public class CraftWorld implements World {
2014-12-06 04:33:40 +01:00
}
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) {
--
2016-02-29 22:33:06 +01:00
2.5.0
2014-12-06 04:33:40 +01:00