2019-01-01 03:15:55 +00:00
From 8d8d26a043ca64b9af562833a593222b20caec71 Mon Sep 17 00:00:00 2001
2016-09-22 02:12:56 +00:00
From: Aikar <aikar@aikar.co>
Date: Mon, 19 Sep 2016 23:16:39 -0400
Subject: [PATCH] Auto Save Improvements
Makes Auto Save Rate setting configurable per-world. If the auto save rate is left -1, the global bukkit.yml value will be used.
Process auto save every tick instead of once per auto tick interval, so that chunk saves will distribute over many ticks instead of all at once.
Re-introduce a cap per tick for auto save (Spigot disabled the vanilla cap) and make it configurable.
2016-12-27 21:11:25 +00:00
Adds incremental player auto saving too
diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
2018-12-13 00:40:29 +00:00
index 51b0dd972..9f8b43d2a 100644
2016-12-27 21:11:25 +00:00
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
2018-10-19 00:44:59 +00:00
@@ -269,4 +269,15 @@ public class PaperConfig {
2016-12-27 21:11:25 +00:00
flyingKickPlayerMessage = getString("messages.kick.flying-player", flyingKickPlayerMessage);
flyingKickVehicleMessage = getString("messages.kick.flying-vehicle", flyingKickVehicleMessage);
}
+
+ public static int playerAutoSaveRate = -1;
2018-03-05 01:20:27 +00:00
+ public static int maxPlayerAutoSavePerTick = 10;
2016-12-27 21:11:25 +00:00
+ private static void playerAutoSaveRate() {
+ playerAutoSaveRate = getInt("settings.player-auto-save-rate", -1);
2018-03-05 01:20:27 +00:00
+ maxPlayerAutoSavePerTick = getInt("settings.max-player-auto-save-per-tick", -1);
+ if (maxPlayerAutoSavePerTick == -1) { // -1 Automatic / "Recommended"
+ // 10 should be safe for everyone unless your mass spamming player auto save
+ maxPlayerAutoSavePerTick = (playerAutoSaveRate == -1 || playerAutoSaveRate > 100) ? 10 : 20;
+ }
2016-12-27 21:11:25 +00:00
+ }
}
2016-09-22 02:12:56 +00:00
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
2018-12-13 00:40:29 +00:00
index d8f258105..47bfb5b62 100644
2016-09-22 02:12:56 +00:00
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -2,6 +2,7 @@ package com.destroystokyo.paper;
import java.util.List;
+import net.minecraft.server.MinecraftServer;
import org.bukkit.configuration.file.YamlConfiguration;
import org.spigotmc.SpigotWorldConfig;
2017-05-14 18:05:01 +00:00
2018-12-13 00:40:29 +00:00
@@ -315,4 +316,19 @@ public class PaperWorldConfig {
2018-07-16 20:08:09 +00:00
private void skipEntityTickingInChunksScheduledForUnload() {
skipEntityTickingInChunksScheduledForUnload = getBoolean("skip-entity-ticking-in-chunks-scheduled-for-unload", skipEntityTickingInChunksScheduledForUnload);
2016-09-22 02:12:56 +00:00
}
+
+ 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 = 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-01-01 03:15:55 +00:00
index ddccdc939..0d70ce797 100644
2016-09-22 02:12:56 +00:00
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
2019-01-01 03:15:55 +00:00
@@ -53,9 +53,9 @@ public class Chunk implements IChunkAccess {
2018-08-26 18:11:49 +00:00
private final TickList<Block> s;
private final TickList<FluidType> t;
private boolean u;
- private boolean v;
+ private boolean v;public boolean hasEntities() { return v; } // Paper - OBFHELPER
2018-07-21 20:03:10 +00:00
private long lastSaved;
2018-08-26 18:11:49 +00:00
- private boolean x;
+ private boolean x; public boolean isModified() { return x; } // Paper - OBFHELPER
private int y;
private long z;
private int A;
2019-01-01 03:15:55 +00:00
@@ -1071,11 +1071,11 @@ public class Chunk implements IChunkAccess {
2018-08-26 18:11:49 +00:00
if (this.v && this.world.getTime() != this.lastSaved || this.x) {
2016-09-22 02:12:56 +00:00
return true;
}
2018-08-26 18:11:49 +00:00
- } else if (this.v && this.world.getTime() >= this.lastSaved + MinecraftServer.getServer().autosavePeriod * 4) { // Spigot - Only save if we've passed 2 auto save intervals without modification
2016-11-04 05:31:49 +00:00
- return true;
2016-09-22 02:12:56 +00:00
}
2016-11-04 05:31:49 +00:00
-
2018-08-26 18:11:49 +00:00
- return this.x;
2018-07-21 20:03:10 +00:00
+ // Paper start - Make world configurable and incremental
+ // This !flag section should say if isModified or hasEntities, then check auto save
+ return ((isModified() || hasEntities()) && this.world.getTime() >= this.lastSaved + world.paperConfig.autoSavePeriod);
+ // Paper end
2016-11-04 05:31:49 +00:00
}
2016-09-22 02:12:56 +00:00
2018-07-16 20:08:09 +00:00
public boolean isEmpty() {
2016-09-22 02:12:56 +00:00
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
2019-01-01 03:15:55 +00:00
index ff6f7596c..91533f8ac 100644
2016-09-22 02:12:56 +00:00
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
2019-01-01 03:15:55 +00:00
@@ -240,7 +240,7 @@ public class ChunkProviderServer implements IChunkProvider {
2018-08-26 18:11:49 +00:00
this.saveChunk(chunk, false); // Spigot
chunk.a(false);
++i;
- if (i == 24 && !flag && false) { // Spigot
+ if (!flag && i >= world.paperConfig.maxAutoSaveChunksPerTick) { // Spigot - // Paper - Incremental Auto Save - cap max
return false;
}
2016-09-22 02:12:56 +00:00
}
2016-12-27 21:11:25 +00:00
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
2019-01-01 03:15:55 +00:00
index 749e41aed..97714be6d 100644
2016-12-27 21:11:25 +00:00
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
2019-01-01 03:15:55 +00:00
@@ -34,6 +34,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
2018-08-26 18:11:49 +00:00
2018-07-16 20:08:09 +00:00
private static final Logger cc = LogManager.getLogger();
public String locale = null; // CraftBukkit - lowercase // Paper - default to null
2016-12-27 21:11:25 +00:00
+ public long lastSave = MinecraftServer.currentTick; // Paper
public PlayerConnection playerConnection;
public final MinecraftServer server;
public final PlayerInteractManager playerInteractManager;
2016-09-22 02:12:56 +00:00
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
2019-01-01 03:15:55 +00:00
index 7710962ce..f09d358e2 100644
2016-09-22 02:12:56 +00:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2019-01-01 03:15:55 +00:00
@@ -143,6 +143,7 @@ public abstract class MinecraftServer implements IAsyncTaskHandler, IMojangStati
2018-07-21 20:03:10 +00:00
public org.bukkit.command.RemoteConsoleCommandSender remoteConsole;
public ConsoleReader reader;
public static int currentTick = 0; // Paper - Further improve tick loop
+ public boolean serverAutoSave = false; // Paper
public final Thread primaryThread;
2016-09-26 05:50:26 +00:00
public java.util.Queue<Runnable> processQueue = new java.util.concurrent.ConcurrentLinkedQueue<Runnable>();
public int autosavePeriod;
2019-01-01 03:15:55 +00:00
@@ -937,22 +938,30 @@ public abstract class MinecraftServer implements IAsyncTaskHandler, IMojangStati
2018-08-26 18:11:49 +00:00
this.m.b().a(agameprofile);
2016-09-22 02:12:56 +00:00
}
- if (autosavePeriod > 0 && this.ticks % autosavePeriod == 0) { // CraftBukkit
2018-12-17 05:18:06 +00:00
this.methodProfiler.enter("save");
- this.playerList.savePlayers();
2016-09-22 02:12:56 +00:00
+
2016-09-26 05:50:26 +00:00
+ serverAutoSave = (autosavePeriod > 0 && this.ticks % autosavePeriod == 0); // Paper
2016-12-27 21:11:25 +00:00
+ int playerSaveInterval = com.destroystokyo.paper.PaperConfig.playerAutoSaveRate;
+ if (playerSaveInterval < 0) {
+ playerSaveInterval = autosavePeriod;
+ }
+ if (playerSaveInterval > 0) { // CraftBukkit // Paper
2018-12-17 05:18:06 +00:00
+ this.playerList.savePlayers(playerSaveInterval);
2016-09-22 02:12:56 +00:00
// Spigot Start
+ } // Paper - Incremental Auto Saving
+
// 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;
2018-08-26 18:11:49 +00:00
for (World world : getWorlds()) {
2016-09-22 02:12:56 +00:00
- world.getWorld().save(false);
+ if (world.paperConfig.autoSavePeriod > 0) world.getWorld().save(false); // Paper - Incremental / Configurable Auto Saving
}
server.playerCommandState = false;
// this.saveChunks(true);
// Spigot End
2018-12-17 05:18:06 +00:00
this.methodProfiler.exit();
2016-09-22 02:12:56 +00:00
- }
+ //} // Paper - Incremental Auto Saving
2018-12-17 05:18:06 +00:00
this.methodProfiler.enter("snooper");
if (getSnooperEnabled() && !this.snooper.d() && this.ticks > 100) { // Spigot
2016-12-27 21:11:25 +00:00
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
2019-01-01 03:15:55 +00:00
index 86aa0c57a..2c3ed3723 100644
2016-12-27 21:11:25 +00:00
--- a/src/main/java/net/minecraft/server/PlayerList.java
+++ b/src/main/java/net/minecraft/server/PlayerList.java
2019-01-01 03:15:55 +00:00
@@ -341,6 +341,7 @@ public abstract class PlayerList {
2016-12-27 21:11:25 +00:00
protected void savePlayerFile(EntityPlayer entityplayer) {
2018-10-03 19:19:35 +00:00
if (!entityplayer.getBukkitEntity().isPersistent()) return; // CraftBukkit
2016-12-27 21:11:25 +00:00
+ entityplayer.lastSave = MinecraftServer.currentTick; // Paper
this.playerFileData.save(entityplayer);
2017-07-17 00:36:27 +00:00
ServerStatisticManager serverstatisticmanager = (ServerStatisticManager) entityplayer.getStatisticManager(); // CraftBukkit
2016-12-27 21:11:25 +00:00
2019-01-01 03:15:55 +00:00
@@ -1207,13 +1208,25 @@ public abstract class PlayerList {
2016-12-27 21:11:25 +00:00
}
+ // Paper start
public void savePlayers() {
+ savePlayers(null);
+ }
+
+ public void savePlayers(Integer interval) {
+ long now = MinecraftServer.currentTick;
MinecraftTimings.savePlayers.startTiming(); // Paper
2018-03-05 01:20:27 +00:00
+ int numSaved = 0; // Paper
2016-12-27 21:11:25 +00:00
for (int i = 0; i < this.players.size(); ++i) {
- this.savePlayerFile((EntityPlayer) this.players.get(i));
+ EntityPlayer entityplayer = this.players.get(i);
+ if (interval == null || now - entityplayer.lastSave >= interval) {
+ this.savePlayerFile(entityplayer);
2018-03-05 01:20:27 +00:00
+ if (interval != null && ++numSaved <= com.destroystokyo.paper.PaperConfig.maxPlayerAutoSavePerTick) { break; } // Paper
2016-12-27 21:11:25 +00:00
+ }
}
MinecraftTimings.savePlayers.stopTiming(); // Paper
}
+ // Paper end
2018-07-16 20:08:09 +00:00
public WhiteList getWhitelist() {
return this.whitelist;
2016-09-22 02:12:56 +00:00
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
2019-01-01 03:15:55 +00:00
index fa7466d64..48d70624c 100644
2016-09-22 02:12:56 +00:00
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
2019-01-01 03:15:55 +00:00
@@ -856,8 +856,9 @@ public class WorldServer extends World implements IAsyncTaskHandler {
2018-12-17 05:18:06 +00:00
ChunkProviderServer chunkproviderserver = this.getChunkProvider();
2016-09-22 02:12:56 +00:00
2018-08-26 18:11:49 +00:00
if (chunkproviderserver.d()) {
2016-09-22 02:12:56 +00:00
- org.bukkit.Bukkit.getPluginManager().callEvent(new org.bukkit.event.world.WorldSaveEvent(getWorld())); // CraftBukkit
+ if (flag) org.bukkit.Bukkit.getPluginManager().callEvent(new org.bukkit.event.world.WorldSaveEvent(getWorld())); // CraftBukkit // Paper - Incremental Auto Saving - Only fire event on full save
2016-10-21 20:42:49 +00:00
timings.worldSave.startTiming(); // Paper
+ if (flag || server.serverAutoSave) { // Paper
2016-09-22 02:12:56 +00:00
if (iprogressupdate != null) {
2018-07-16 20:08:09 +00:00
iprogressupdate.a(new ChatMessage("menu.savingLevel", new Object[0]));
2016-09-22 02:12:56 +00:00
}
2019-01-01 03:15:55 +00:00
@@ -866,6 +867,7 @@ public class WorldServer extends World implements IAsyncTaskHandler {
2016-09-26 05:50:26 +00:00
if (iprogressupdate != null) {
2018-07-16 20:08:09 +00:00
iprogressupdate.c(new ChatMessage("menu.savingChunks", new Object[0]));
2016-09-26 05:50:26 +00:00
}
2016-10-21 20:42:49 +00:00
+ } // Paper
timings.worldSaveChunks.startTiming(); // Paper
chunkproviderserver.a(flag);
2016-09-22 02:12:56 +00:00
--
2019-01-01 03:15:55 +00:00
2.20.1
2016-09-22 02:12:56 +00:00