mirror of
https://github.com/YatopiaMC/Yatopia.git
synced 2024-11-29 06:05:14 +01:00
61f261ee2a
Upstream/An Sidestream has released updates that appears to apply and compile correctly This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing. Paper Changes: b8020379c Extract Adventure Version into a variable, add reminder to update the linked JD on the homepage (#5422) 809466f2e Fix anchor respawn acting as a bed respawn when using the end portal (#5540) d219fd642 [Auto] Updated Upstream (Bukkit/CraftBukkit) db464b099 Implement methods to convert between Component and Brigadier's Message (#5542) 4047cffca Add PlayerBedFailEnterEvent (#4935) 70d697e6e Update Paperpclip 5ed771591 [CI-SKIP] Remove bad null annotation (#5538) 454a4c78e More World API (#3850) 869e02304 Add PlayerDeepSleepEvent (#5525) fb56fc35e fix non-dummy objectives not updating dc859a61f [CI-SKIP] [Auto] Rebuild Patches 7d1689f1a Add missing checkReachable check for shulker boxes (#5453) ba8eb3d4b Add missing Javadoc for COLORABLE MaterialTag (#5376) db801cbf3 Fix PlayerItemHeldEvent firing twice (#5534) 14de2b795 fix PigZombieAngerEvent cancellation (fixes #5319) (v2) (#5329) 86d684ad1 Add get-set drop chance to EntityEquipment (#5528) 33fb8cf63 Add consumeFuel to FurnaceBurnEvent (#5532) 9957f4630 Fix duplicating /give items on item drop cancel (#5536) d94882043 Fix legacyComposer not using AsyncChatEvent messages (#5509) 053bd82cc Don't print spawn load time when not loading spawn (#5467) a6d78caae Add isDeeplySleeping to HumanEntity (#5470) 711b7a80b Expose more Adventure serializers through PaperComponents (#5443) 3f63bde0c Set Area Effect Cloud Rotation (#5462) 3523f0fda Remove useless check on player interact cancellation (#5448) 6574d1aa8 fix #5526 - use correct type when sending message to clients dbfa833ec don't throw when loading TE with invalid keys a9525a6f7 Do not schedule poi task for each block write on chunk gen Airplane Changes: f5fb024 Temporarily revert patch 3c728a7 Oops, these 2 too 37a93e5 Your daily dose of 1-3% optimization patches bbd689a Remove useless check d8bdbc5 Reduce allocations for fire spreading 41051fd Redo reduction of entity chunk ticking check patch 31272d8 Flare Update 8f32713 Remove criterion patch 0fed2df Various patches that need to be reorganized later f78856b Updated Upstream (Tuinity) f7d6382 Flare Update 71d0799 Update gradle configuration 0f79774 Updated Upstream (Tuinity) Purpur Changes: 3dce975 Updated Upstream (Paper & Airplane) (#298) eb07368 Run GitHub Actions for pull requests e97d062 Updated Upstream (Paper, Tuinity, & Airplane) Empirecraft Changes: 2a021ede Updated Paper e963bb2c Add Paper MojangAPI to pom 6f5bf24e Updated Paper Origami Changes: 73ecdf1 Update Paper 73a3735 Item and exp merge improvements
138 lines
7.1 KiB
Diff
138 lines
7.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Hugo Planque <hookwood01@gmail.com>
|
|
Date: Thu, 21 Jan 2021 17:56:03 +0100
|
|
Subject: [PATCH] New nbt cache
|
|
|
|
The goal of this patch is to reduce I/O operations from the main thread while saving player data and also to avoid too many I/O operations while reading NBT Player file by using a cache (Which start to delete the oldest data when there is too much player compared to the map size)
|
|
|
|
Co-authored-by: ishland <ishlandmc@yeah.net>
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
index 13f9af375011fe6a7e96605105d147445d58d26f..c1fd0149e1c04f33911bef77afa5d1c7938a6048 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -951,7 +951,9 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
|
|
}
|
|
// Spigot start
|
|
MCUtil.asyncExecutor.shutdown(); // Paper
|
|
+ this.worldNBTStorage.executorService.shutdown(); // Yatopia
|
|
try { MCUtil.asyncExecutor.awaitTermination(30, java.util.concurrent.TimeUnit.SECONDS); // Paper
|
|
+ this.worldNBTStorage.executorService.awaitTermination(30, java.util.concurrent.TimeUnit.SECONDS); // Yatopia - New async nbt cache
|
|
} catch (java.lang.InterruptedException ignored) {} // Paper
|
|
if (org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) {
|
|
LOGGER.info("Saving usercache.json");
|
|
diff --git a/src/main/java/net/minecraft/world/level/storage/WorldNBTStorage.java b/src/main/java/net/minecraft/world/level/storage/WorldNBTStorage.java
|
|
index d9c2c7a20953fc3bcdd07d70233ccf6e3748b14b..933b09169b2177f70412722264c0d5f129f3d93f 100644
|
|
--- a/src/main/java/net/minecraft/world/level/storage/WorldNBTStorage.java
|
|
+++ b/src/main/java/net/minecraft/world/level/storage/WorldNBTStorage.java
|
|
@@ -24,6 +24,11 @@ public class WorldNBTStorage {
|
|
private static final Logger LOGGER = LogManager.getLogger();
|
|
private final File playerDir;
|
|
protected final DataFixer a;
|
|
+ // Yatopia start - NBT Cache system
|
|
+ private final org.yatopiamc.yatopia.server.cache.NBTCache dataCache = new org.yatopiamc.yatopia.server.cache.NBTCache();
|
|
+ public final java.util.concurrent.ExecutorService executorService = java.util.concurrent.Executors.newSingleThreadExecutor(
|
|
+ new com.google.common.util.concurrent.ThreadFactoryBuilder().setDaemon(true).setPriority(Thread.NORM_PRIORITY - 1).build());
|
|
+ // Yatopia end
|
|
|
|
public WorldNBTStorage(Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer) {
|
|
this.a = datafixer;
|
|
@@ -37,11 +42,22 @@ public class WorldNBTStorage {
|
|
NBTTagCompound nbttagcompound = entityhuman.save(new NBTTagCompound());
|
|
File file = File.createTempFile(entityhuman.getUniqueIDString() + "-", ".dat", this.playerDir);
|
|
|
|
- NBTCompressedStreamTools.a(nbttagcompound, file);
|
|
+ // NBTCompressedStreamTools.a(nbttagcompound, file); // Yatopia
|
|
+ // Yatopia start - NBT Cache system
|
|
+ Runnable task = () -> { try { NBTCompressedStreamTools.a(nbttagcompound, file);
|
|
File file1 = new File(this.playerDir, entityhuman.getUniqueIDString() + ".dat");
|
|
File file2 = new File(this.playerDir, entityhuman.getUniqueIDString() + ".dat_old");
|
|
|
|
SystemUtils.a(file1, file, file2);
|
|
+ } catch (Exception exception) {
|
|
+ WorldNBTStorage.LOGGER.error("Failed to save player data for {}", entityhuman.getName(), exception); // Paper
|
|
+ }
|
|
+ };
|
|
+ synchronized (this.dataCache){
|
|
+ this.dataCache.put(file, nbttagcompound);
|
|
+ }
|
|
+ this.executorService.execute(task);
|
|
+ // Yatopia end
|
|
} catch (Exception exception) {
|
|
WorldNBTStorage.LOGGER.error("Failed to save player data for {}", entityhuman.getName(), exception); // Paper
|
|
}
|
|
@@ -57,9 +73,18 @@ public class WorldNBTStorage {
|
|
// Spigot Start
|
|
boolean usingWrongFile = false;
|
|
boolean normalFile = file.exists() && file.isFile(); // Akarin - ensures normal file
|
|
- if ( org.bukkit.Bukkit.getOnlineMode() && !normalFile ) // Paper - Check online mode first // Akarin - ensures normal file
|
|
+ // if ( org.bukkit.Bukkit.getOnlineMode() && !normalFile ) // Paper - Check online mode first // Akarin - ensures normal file // Yatopia
|
|
+ // Yatopia start - NBT Cache system
|
|
+ NBTTagCompound playerData;
|
|
+ synchronized (this.dataCache){
|
|
+ playerData = this.dataCache.get(file);
|
|
+ }
|
|
+ if (playerData == null && org.bukkit.Bukkit.getOnlineMode() && !normalFile ) // Paper - Check online mode first // Akarin - ensures normal file
|
|
{
|
|
file = new File( this.playerDir, java.util.UUID.nameUUIDFromBytes( ( "OfflinePlayer:" + entityhuman.getName() ).getBytes( "UTF-8" ) ).toString() + ".dat");
|
|
+ synchronized (this.dataCache){
|
|
+ playerData = this.dataCache.get(file);
|
|
+ }
|
|
if ( file.exists() )
|
|
{
|
|
usingWrongFile = true;
|
|
@@ -67,10 +92,13 @@ public class WorldNBTStorage {
|
|
}
|
|
}
|
|
// Spigot End
|
|
-
|
|
- if (normalFile) { // Akarin - avoid double I/O operation
|
|
+ // if (normalFile) { // Akarin - avoid double I/O operation // Yatopia
|
|
+ if (playerData != null) {
|
|
+ nbttagcompound = playerData;
|
|
+ } else if (normalFile) { // Akarin - avoid double I/O operation
|
|
nbttagcompound = NBTCompressedStreamTools.a(file);
|
|
}
|
|
+ // Yatopia end
|
|
// Spigot Start
|
|
if ( usingWrongFile )
|
|
{
|
|
diff --git a/src/main/java/org/yatopiamc/yatopia/server/cache/NBTCache.java b/src/main/java/org/yatopiamc/yatopia/server/cache/NBTCache.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..d739a71c91b54d156f6e1d8487add372a06d5939
|
|
--- /dev/null
|
|
+++ b/src/main/java/org/yatopiamc/yatopia/server/cache/NBTCache.java
|
|
@@ -0,0 +1,32 @@
|
|
+package org.yatopiamc.yatopia.server.cache;
|
|
+
|
|
+import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenCustomHashMap;
|
|
+import net.minecraft.server.MinecraftServer;
|
|
+import net.minecraft.nbt.NBTTagCompound;
|
|
+
|
|
+import java.io.File;
|
|
+
|
|
+public class NBTCache extends Object2ObjectLinkedOpenCustomHashMap<File, NBTTagCompound> {
|
|
+
|
|
+ public NBTCache() {
|
|
+ super(100, 0.75F, new Strategy<File>() {
|
|
+ @Override
|
|
+ public int hashCode(File k) {
|
|
+ return k.hashCode();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean equals(File k, File k1) {
|
|
+ return k.equals(k1);
|
|
+ }
|
|
+ });
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public NBTTagCompound put(File k, NBTTagCompound v) {
|
|
+ if (this.size() > MinecraftServer.getServer().getPlayerCount()) {
|
|
+ this.removeLast();
|
|
+ }
|
|
+ return super.putAndMoveToFirst(k, v);
|
|
+ }
|
|
+}
|