2019-12-13 02:18:18 +01:00
From 9dff654d99e1c5c0d31a9974dfe1b2b8314ae3dc Mon Sep 17 00:00:00 2001
2019-06-09 21:22:44 +02:00
From: Shane Freeder <theboyetronic@gmail.com>
Date: Sun, 9 Jun 2019 03:53:22 +0100
Subject: [PATCH] incremental chunk saving
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
2019-12-12 17:20:43 +01:00
index 332f20ce8..f5ed0a698 100644
2019-06-09 21:22:44 +02:00
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
2019-10-27 00:55:58 +02:00
@@ -494,4 +494,19 @@ public class PaperWorldConfig {
2019-06-09 21:22:44 +02:00
keepLoadedRange = (short) (getInt("keep-spawn-loaded-range", Math.min(spigotConfig.viewDistance, 10)) * 16);
log( "Keep Spawn Loaded Range: " + (keepLoadedRange/16));
}
+
+ public int autoSavePeriod = -1;
+ private void autoSavePeriod() {
+ autoSavePeriod = getInt("auto-save-interval", -1);
+ if (autoSavePeriod > 0) {
+ log("Auto Save Interval: " +autoSavePeriod + " (" + (autoSavePeriod / 20) + "s)");
+ } else if (autoSavePeriod < 0) {
+ autoSavePeriod = net.minecraft.server.MinecraftServer.getServer().autosavePeriod;
+ }
+ }
+
+ public int maxAutoSaveChunksPerTick = 24;
+ private void maxAutoSaveChunksPerTick() {
+ maxAutoSaveChunksPerTick = getInt("max-auto-save-chunks-per-tick", 24);
+ }
}
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
2019-12-12 17:20:43 +01:00
index 64c327669..14ec31f0a 100644
2019-06-09 21:22:44 +02:00
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -42,7 +42,7 @@ public class Chunk implements IChunkAccess {
private TickList<Block> o;
private TickList<FluidType> p;
private boolean q;
- private long lastSaved;
+ public long lastSaved; // Paper
private volatile boolean s;
2019-12-12 17:20:43 +01:00
private long inhabitedTime;
2019-06-09 21:22:44 +02:00
@Nullable
2019-07-28 02:38:29 +02:00
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
2019-12-12 17:20:43 +01:00
index 9b2bafdbd..f138b112f 100644
2019-07-28 02:38:29 +02:00
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
@@ -335,6 +335,15 @@ public class ChunkProviderServer extends IChunkProvider {
} // Paper - Timings
}
+ // Paper start - duplicate save, but call incremental
+ public void saveIncrementally() {
+ this.tickDistanceManager();
+ try (co.aikar.timings.Timing timed = world.timings.chunkSaveData.startTiming()) { // Paper - Timings
+ this.playerChunkMap.saveIncrementally();
+ } // Paper - Timings
+ }
+ // Paper end
+
@Override
public void close() throws IOException {
2019-08-05 18:35:40 +02:00
// CraftBukkit start
2019-06-09 21:22:44 +02:00
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
2019-12-12 17:20:43 +01:00
index 0a7648381..8e15aba7f 100644
2019-06-09 21:22:44 +02:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2019-12-12 17:20:43 +01:00
@@ -168,6 +168,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
2019-06-09 21:22:44 +02:00
public static int currentTick = 0; // Paper - Further improve tick loop
public java.util.Queue<Runnable> processQueue = new java.util.concurrent.ConcurrentLinkedQueue<Runnable>();
public int autosavePeriod;
+ public boolean serverAutoSave = false; // Paper
public File bukkitDataPackFolder;
public CommandDispatcher vanillaCommandDispatcher;
private boolean forceTicks;
2019-12-12 17:20:43 +01:00
@@ -1116,14 +1117,28 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
2019-06-09 21:22:44 +02:00
this.serverPing.b().a(agameprofile);
}
- if (autosavePeriod > 0 && this.ticks % autosavePeriod == 0) { // CraftBukkit
2019-09-30 03:14:40 +02:00
- MinecraftServer.LOGGER.debug("Autosave started");
2019-06-09 21:22:44 +02:00
+ //if (autosavePeriod > 0 && this.ticks % autosavePeriod == 0) { // CraftBukkit // Paper - move down
2019-09-30 03:14:40 +02:00
+ //MinecraftServer.LOGGER.debug("Autosave started"); // Paper
2019-06-09 21:22:44 +02:00
+ serverAutoSave = (autosavePeriod > 0 && this.ticks % autosavePeriod == 0); // Paper
this.methodProfiler.enter("save");
+ if (autosavePeriod > 0 && this.ticks % autosavePeriod == 0) { // Paper
this.playerList.savePlayers();
- this.saveChunks(true, false, false);
+ }// Paper
+ // Paper start
2019-06-10 07:39:04 +02:00
+ for (WorldServer world : getWorlds()) {
+ if (world.paperConfig.autoSavePeriod > 0) {
+ try {
2019-07-28 02:38:29 +02:00
+ world.saveIncrementally(serverAutoSave);
2019-06-10 07:39:04 +02:00
+ } catch (ExceptionWorldConflict exceptionWorldConflict) {
+ MinecraftServer.LOGGER.warn(exceptionWorldConflict.getMessage());
+ }
+ }
2019-06-09 21:22:44 +02:00
+ }
+ // Paper end
+
this.methodProfiler.exit();
2019-09-30 03:14:40 +02:00
- MinecraftServer.LOGGER.debug("Autosave finished");
2019-06-09 21:22:44 +02:00
- }
2019-09-30 03:14:40 +02:00
+ //MinecraftServer.LOGGER.debug("Autosave finished"); // Paper
2019-06-09 21:22:44 +02:00
+ //} // Paper
this.methodProfiler.enter("snooper");
if (((DedicatedServer) this).getDedicatedServerProperties().snooperEnabled && !this.snooper.d() && this.ticks > 100) { // Spigot
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
2019-12-12 17:20:43 +01:00
index 827831aab..4379434f6 100644
2019-06-09 21:22:44 +02:00
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
2019-12-12 17:20:43 +01:00
@@ -298,6 +298,36 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
2019-07-28 02:38:29 +02:00
super.close();
}
2019-06-09 21:22:44 +02:00
2019-07-28 02:38:29 +02:00
+ // Paper start - derived from below
+ protected void saveIncrementally() {
+ int savedThisTick = 0;
+ for (PlayerChunk playerchunk : visibleChunks.values()) {
+ if (playerchunk.hasBeenLoaded()) {
+
+ IChunkAccess ichunkaccess = (IChunkAccess) playerchunk.getChunkSave().getNow(null); // CraftBukkit - decompile error
+
+
+ if (ichunkaccess instanceof ProtoChunkExtension || ichunkaccess instanceof Chunk) {
2019-06-09 21:22:44 +02:00
+ boolean shouldSave = true;
2019-06-25 03:47:58 +02:00
+
2019-06-09 21:22:44 +02:00
+ if (ichunkaccess instanceof Chunk) {
+ shouldSave = ((Chunk) ichunkaccess).lastSaved + world.paperConfig.autoSavePeriod <= world.getTime();
+ }
+
2019-06-17 09:47:51 +02:00
+ if (shouldSave && this.saveChunk(ichunkaccess)) {
+ ++savedThisTick;
2019-07-28 02:38:29 +02:00
+ playerchunk.m();
2019-06-09 21:22:44 +02:00
+ }
2019-06-17 09:47:51 +02:00
+ }
2019-07-28 02:38:29 +02:00
+
+ if (savedThisTick >= world.paperConfig.maxAutoSaveChunksPerTick) {
+ return;
+ }
+ }
+ }
+ }
+ // paper end
+
protected void save(boolean flag) {
if (flag) {
List<PlayerChunk> list = (List) this.visibleChunks.values().stream().filter(PlayerChunk::hasBeenLoaded).peek(PlayerChunk::m).collect(Collectors.toList());
2019-06-09 21:22:44 +02:00
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
2019-12-13 02:18:18 +01:00
index c28c0431a..4bfa6ea0e 100644
2019-06-09 21:22:44 +02:00
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
2019-10-20 11:03:39 +02:00
@@ -791,11 +791,44 @@ public class WorldServer extends World {
2019-12-12 17:20:43 +01:00
return this.worldProvider.c();
2019-07-28 02:38:29 +02:00
}
+ // Paper start - derived from below
+ public void saveIncrementally(boolean doFull) throws ExceptionWorldConflict {
+ ChunkProviderServer chunkproviderserver = this.getChunkProvider();
+
+ if (doFull) {
+ org.bukkit.Bukkit.getPluginManager().callEvent(new org.bukkit.event.world.WorldSaveEvent(getWorld()));
+ }
+
+ try (co.aikar.timings.Timing ignored = timings.worldSave.startTiming()) {
+ if (doFull) {
2019-12-13 02:18:18 +01:00
+ this.saveData();
2019-07-28 02:38:29 +02:00
+ }
+
+ timings.worldSaveChunks.startTiming(); // Paper
+ if (!this.isSavingDisabled()) chunkproviderserver.saveIncrementally();
+ timings.worldSaveChunks.stopTiming(); // Paper
+
+
+ // CraftBukkit start - moved from MinecraftServer.saveChunks
+ // PAIL - rename
+ if (doFull) {
+ WorldServer worldserver1 = this;
+ WorldData worlddata = worldserver1.getWorldData();
+
2019-12-13 02:18:18 +01:00
+ worldserver1.getWorldBorder().save(worlddata);
+ worlddata.setCustomBossEvents(this.server.getBossBattleCustomData().save());
+ worldserver1.getDataManager().saveWorldData(worlddata, this.server.getPlayerList().save());
2019-07-28 02:38:29 +02:00
+ // CraftBukkit end
+ }
+ }
+ }
+ // Paper end
+
public void save(@Nullable IProgressUpdate iprogressupdate, boolean flag, boolean flag1) throws ExceptionWorldConflict {
2019-06-10 22:45:17 +02:00
ChunkProviderServer chunkproviderserver = this.getChunkProvider();
2019-06-09 21:22:44 +02:00
if (!flag1) {
2019-06-10 22:45:17 +02:00
- org.bukkit.Bukkit.getPluginManager().callEvent(new org.bukkit.event.world.WorldSaveEvent(getWorld())); // CraftBukkit
2019-07-28 02:38:29 +02:00
+ if (flag) org.bukkit.Bukkit.getPluginManager().callEvent(new org.bukkit.event.world.WorldSaveEvent(getWorld())); // CraftBukkit
2019-06-09 21:22:44 +02:00
try (co.aikar.timings.Timing ignored = timings.worldSave.startTiming()) { // Paper
if (iprogressupdate != null) {
iprogressupdate.a(new ChatMessage("menu.savingLevel", new Object[0]));
2019-12-13 02:18:18 +01:00
@@ -822,6 +855,7 @@ public class WorldServer extends World {
// CraftBukkit end
}
+ protected void saveData() throws ExceptionWorldConflict { this.m_(); } // Paper - OBFHELPER
protected void m_() throws ExceptionWorldConflict {
this.checkSession();
this.worldProvider.i();
2019-06-09 21:22:44 +02:00
--
2019-12-13 02:18:18 +01:00
2.24.0
2019-06-09 21:22:44 +02:00