diff --git a/patches/server/0049-Player-saving-async-FileIO.patch b/patches/server/0049-Player-saving-async-FileIO.patch index e2bc4b97..473d9a6e 100644 --- a/patches/server/0049-Player-saving-async-FileIO.patch +++ b/patches/server/0049-Player-saving-async-FileIO.patch @@ -1,14 +1,15 @@ -From 70388f2abf6dfc0588205bfd041d7ab727f869b8 Mon Sep 17 00:00:00 2001 +From b4dc82c91be20d5db78589ed6b66e31572b5616e Mon Sep 17 00:00:00 2001 From: tr7zw Date: Sat, 4 Apr 2020 23:23:04 +0200 Subject: [PATCH] Player saving async FileIO --- .../server/AdvancementDataPlayer.java | 106 ++++++++++-------- - .../java/net/minecraft/server/PlayerList.java | 24 ++++ - .../server/ServerStatisticManager.java | 12 +- - .../net/minecraft/server/WorldNBTStorage.java | 32 ++++-- - 4 files changed, 117 insertions(+), 57 deletions(-) + .../net/minecraft/server/EntityHuman.java | 16 ++- + .../java/net/minecraft/server/PlayerList.java | 28 ++++- + .../server/ServerStatisticManager.java | 20 +++- + .../net/minecraft/server/WorldNBTStorage.java | 33 ++++-- + 5 files changed, 139 insertions(+), 64 deletions(-) diff --git a/src/main/java/net/minecraft/server/AdvancementDataPlayer.java b/src/main/java/net/minecraft/server/AdvancementDataPlayer.java index 79e11eebb7..8d08c91fe6 100644 @@ -143,8 +144,46 @@ index 79e11eebb7..8d08c91fe6 100644 } +diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java +index 09684370f0..9e0cb456bb 100644 +--- a/src/main/java/net/minecraft/server/EntityHuman.java ++++ b/src/main/java/net/minecraft/server/EntityHuman.java +@@ -733,11 +733,23 @@ public abstract class EntityHuman extends EntityLiving { + + } + ++ // YAPFA start ++ private NBTTagList inventorySnapshot = null; ++ private NBTTagList enderchestSnapshot = null; ++ ++ ++ public void takeInventorySnapshot() { ++ inventorySnapshot = this.inventory.a(new NBTTagList()); ++ enderchestSnapshot = this.enderChest.f(); ++ } ++ ++ // YAPFA end ++ + @Override + public void b(NBTTagCompound nbttagcompound) { + super.b(nbttagcompound); + nbttagcompound.setInt("DataVersion", SharedConstants.getGameVersion().getWorldVersion()); +- nbttagcompound.set("Inventory", this.inventory.a(new NBTTagList())); ++ nbttagcompound.set("Inventory", inventorySnapshot); inventorySnapshot = null;// YAPFA + nbttagcompound.setInt("SelectedItemSlot", this.inventory.itemInHandIndex); + nbttagcompound.setShort("SleepTimer", (short) this.sleepTicks); + nbttagcompound.setFloat("XpP", this.exp); +@@ -754,7 +766,7 @@ public abstract class EntityHuman extends EntityLiving { + + this.foodData.b(nbttagcompound); + this.abilities.a(nbttagcompound); +- nbttagcompound.set("EnderItems", this.enderChest.f()); ++ nbttagcompound.set("EnderItems", enderchestSnapshot); enderchestSnapshot = null;// YAPFA + if (!this.getShoulderEntityLeft().isEmpty()) { + nbttagcompound.set("ShoulderEntityLeft", this.getShoulderEntityLeft()); + } diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java -index cf56a821ce..53298c9e3b 100644 +index cf56a821ce..e83d343eaf 100644 --- a/src/main/java/net/minecraft/server/PlayerList.java +++ b/src/main/java/net/minecraft/server/PlayerList.java @@ -16,6 +16,8 @@ import java.util.Map; @@ -185,8 +224,24 @@ index cf56a821ce..53298c9e3b 100644 } // Paper end +@@ -1167,13 +1191,13 @@ public abstract class PlayerList { + File file = new File(this.server.getWorldServer(DimensionManager.OVERWORLD).getDataManager().getDirectory(), "stats"); + File file1 = new File(file, uuid + ".json"); + +- if (!file1.exists()) { ++ /*if (!file1.exists()) { // YAPFA dont check for old stats files with sync File IO + File file2 = new File(file, displayName + ".json"); // CraftBukkit + + if (file2.exists() && file2.isFile()) { + file2.renameTo(file1); + } +- } ++ }*/ + + serverstatisticmanager = new ServerStatisticManager(this.server, file1); + // this.o.put(uuid, serverstatisticmanager); // CraftBukkit diff --git a/src/main/java/net/minecraft/server/ServerStatisticManager.java b/src/main/java/net/minecraft/server/ServerStatisticManager.java -index b3c9a5a845..162b8a27ea 100644 +index b3c9a5a845..edeb8b4fbb 100644 --- a/src/main/java/net/minecraft/server/ServerStatisticManager.java +++ b/src/main/java/net/minecraft/server/ServerStatisticManager.java @@ -20,6 +20,9 @@ import java.util.Map; @@ -207,7 +262,24 @@ index b3c9a5a845..162b8a27ea 100644 public ServerStatisticManager(MinecraftServer minecraftserver, File file) { this.c = minecraftserver; -@@ -55,12 +59,16 @@ public class ServerStatisticManager extends StatisticManager { +@@ -40,7 +44,9 @@ public class ServerStatisticManager extends StatisticManager { + Statistic wrapper = StatisticList.CUSTOM.b( entry.getKey() ); + this.a.put( wrapper, entry.getValue().intValue() ); + } +- // Spigot end ++ // Spigot ends ++ // YAPFA start ++ saveThread.submit(() -> { + if (file.isFile()) { + try { + this.a(minecraftserver.aC(), org.apache.commons.io.FileUtils.readFileToString(file)); +@@ -50,17 +56,21 @@ public class ServerStatisticManager extends StatisticManager { + ServerStatisticManager.LOGGER.error("Couldn't parse statistics file {}", file, jsonparseexception); + } + } +- ++ }); + } public void a() { if ( org.spigotmc.SpigotConfig.disableStatSaving ) return; // Spigot @@ -226,8 +298,17 @@ index b3c9a5a845..162b8a27ea 100644 } @Override +@@ -111,7 +121,7 @@ public class ServerStatisticManager extends StatisticManager { + + if (nbttagcompound2.hasKeyOfType(s2, 99)) { + SystemUtils.a(this.a(statisticwrapper, s2), (statistic) -> { +- this.a.put(statistic, nbttagcompound2.getInt(s2)); ++ this.a.put(statistic, nbttagcompound2.getInt(s2) + this.a.getOrDefault(statistic, 0)); // YAPFA fix async load + }, () -> { + //ServerStatisticManager.LOGGER.warn("Invalid statistic in {}: Don't know what {} is", this.d, s2); // EMC + }); diff --git a/src/main/java/net/minecraft/server/WorldNBTStorage.java b/src/main/java/net/minecraft/server/WorldNBTStorage.java -index 350ac42d6b..39f613fec3 100644 +index 350ac42d6b..c80673770c 100644 --- a/src/main/java/net/minecraft/server/WorldNBTStorage.java +++ b/src/main/java/net/minecraft/server/WorldNBTStorage.java @@ -15,6 +15,9 @@ import org.apache.logging.log4j.Logger; @@ -248,7 +329,7 @@ index 350ac42d6b..39f613fec3 100644 public WorldNBTStorage(File file, String s, @Nullable MinecraftServer minecraftserver, DataFixer datafixer) { this.a = datafixer; -@@ -140,16 +144,24 @@ public class WorldNBTStorage implements IPlayerFileData { +@@ -140,16 +144,25 @@ public class WorldNBTStorage implements IPlayerFileData { public void save(EntityHuman entityhuman) { if(!com.destroystokyo.paper.PaperConfig.savePlayerData) return; // Paper - Make player data saving configurable try { @@ -263,9 +344,10 @@ index 350ac42d6b..39f613fec3 100644 - - file.renameTo(file1); + // YAPFA start -+ NBTTagCompound nbttagcompound = entityhuman.save(new NBTTagCompound()); // Yapfa - save the entity sync to the tag ++ entityhuman.takeInventorySnapshot(); // Take a sync inventory/enderchest snapshot to prevent duping + saveThread.submit(() -> { // Save the tag async + try { ++ NBTTagCompound nbttagcompound = entityhuman.save(new NBTTagCompound()); + File file = new File(this.playerDir, entityhuman.getUniqueIDString() + ".dat.tmp"); + File file1 = new File(this.playerDir, entityhuman.getUniqueIDString() + ".dat"); + diff --git a/patches/server/0051-Akarin-Avoid-double-I-O-operation-on-load-player-fil.patch b/patches/server/0051-Akarin-Avoid-double-I-O-operation-on-load-player-fil.patch index 6c14f19a..1c505934 100644 --- a/patches/server/0051-Akarin-Avoid-double-I-O-operation-on-load-player-fil.patch +++ b/patches/server/0051-Akarin-Avoid-double-I-O-operation-on-load-player-fil.patch @@ -1,4 +1,4 @@ -From 3ac46dfe6fae9451f2ecdbe70a616e499cdb9dcc Mon Sep 17 00:00:00 2001 +From ae3dd18a459c11331e568f3b511002cc88dce8ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=84=97=E3=84=A0=CB=8B=20=E3=84=91=E3=84=A7=CB=8A?= Date: Thu, 2 Apr 2020 11:29:08 +0800 @@ -9,10 +9,10 @@ Subject: [PATCH] Akarin Avoid double I/O operation on load player file 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/minecraft/server/WorldNBTStorage.java b/src/main/java/net/minecraft/server/WorldNBTStorage.java -index 39f613fec3..7faa03aba7 100644 +index c80673770c..65813c84ed 100644 --- a/src/main/java/net/minecraft/server/WorldNBTStorage.java +++ b/src/main/java/net/minecraft/server/WorldNBTStorage.java -@@ -177,7 +177,8 @@ public class WorldNBTStorage implements IPlayerFileData { +@@ -178,7 +178,8 @@ public class WorldNBTStorage implements IPlayerFileData { File file = new File(this.playerDir, entityhuman.getUniqueIDString() + ".dat"); // Spigot Start boolean usingWrongFile = false; @@ -22,7 +22,7 @@ index 39f613fec3..7faa03aba7 100644 { file = new File( this.playerDir, UUID.nameUUIDFromBytes( ( "OfflinePlayer:" + entityhuman.getName() ).getBytes( "UTF-8" ) ).toString() + ".dat"); if ( file.exists() ) -@@ -188,7 +189,7 @@ public class WorldNBTStorage implements IPlayerFileData { +@@ -189,7 +190,7 @@ public class WorldNBTStorage implements IPlayerFileData { } // Spigot End