testserver/patches/server/0097-Async-GameProfileCache...

87 lines
3.9 KiB
Diff
Raw Normal View History

2021-06-11 12:02:28 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Mon, 16 May 2016 20:47:41 -0400
2022-03-18 03:53:36 +00:00
Subject: [PATCH] Async GameProfileCache saving
2021-06-11 12:02:28 +00:00
2021-06-12 05:20:08 +00:00
2021-06-11 12:02:28 +00:00
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
Rewrite chunk system (#8177) Patch documentation to come Issues with the old system that are fixed now: - World generation does not scale with cpu cores effectively. - Relies on the main thread for scheduling and maintaining chunk state, dropping chunk load/generate rates at lower tps. - Unreliable prioritisation of chunk gen/load calls that block the main thread. - Shutdown logic is utterly unreliable, as it has to wait for all chunks to unload - is it guaranteed that the chunk system is in a state on shutdown that it can reliably do this? Watchdog shutdown also typically failed due to thread checks, which is now resolved. - Saving of data is not unified (i.e can save chunk data without saving entity data, poses problems for desync if shutdown is really abnormal. - Entities are not loaded with chunks. This caused quite a bit of headache for Chunk#getEntities API, but now the new chunk system loads entities with chunks so that they are ready whenever the chunk loads in. Effectively brings the behavior back to 1.16 era, but still storing entities in their own separate regionfiles. The above list is not complete. The patch documentation will complete it. New chunk system hard relies on starlight and dataconverter, and most importantly the new concurrent utilities in ConcurrentUtil. Some of the old async chunk i/o interface (i.e the old file io thread reroutes _some_ calls to the new file io thread) is kept for plugin compat reasons. It will be removed in the next major version of minecraft. The old legacy chunk system patches have been moved to the removed folder in case we need them again.
2022-09-26 08:02:51 +00:00
index 7755d79e0dc01e8464f4ffda46db6dbde033aac4..f1d4a7a9e74adc18e18b2df960794ec8c05ce340 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
Rewrite chunk system (#8177) Patch documentation to come Issues with the old system that are fixed now: - World generation does not scale with cpu cores effectively. - Relies on the main thread for scheduling and maintaining chunk state, dropping chunk load/generate rates at lower tps. - Unreliable prioritisation of chunk gen/load calls that block the main thread. - Shutdown logic is utterly unreliable, as it has to wait for all chunks to unload - is it guaranteed that the chunk system is in a state on shutdown that it can reliably do this? Watchdog shutdown also typically failed due to thread checks, which is now resolved. - Saving of data is not unified (i.e can save chunk data without saving entity data, poses problems for desync if shutdown is really abnormal. - Entities are not loaded with chunks. This caused quite a bit of headache for Chunk#getEntities API, but now the new chunk system loads entities with chunks so that they are ready whenever the chunk loads in. Effectively brings the behavior back to 1.16 era, but still storing entities in their own separate regionfiles. The above list is not complete. The patch documentation will complete it. New chunk system hard relies on starlight and dataconverter, and most importantly the new concurrent utilities in ConcurrentUtil. Some of the old async chunk i/o interface (i.e the old file io thread reroutes _some_ calls to the new file io thread) is kept for plugin compat reasons. It will be removed in the next major version of minecraft. The old legacy chunk system patches have been moved to the removed folder in case we need them again.
2022-09-26 08:02:51 +00:00
@@ -926,7 +926,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2021-06-11 12:02:28 +00:00
} catch (java.lang.InterruptedException ignored) {} // Paper
if (org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) {
2021-06-12 05:20:08 +00:00
MinecraftServer.LOGGER.info("Saving usercache.json");
2021-06-11 12:02:28 +00:00
- this.getProfileCache().save();
2021-06-12 05:20:08 +00:00
+ this.getProfileCache().save(false); // Paper
2021-06-11 12:02:28 +00:00
}
// Spigot end
Rewrite chunk system (#8177) Patch documentation to come Issues with the old system that are fixed now: - World generation does not scale with cpu cores effectively. - Relies on the main thread for scheduling and maintaining chunk state, dropping chunk load/generate rates at lower tps. - Unreliable prioritisation of chunk gen/load calls that block the main thread. - Shutdown logic is utterly unreliable, as it has to wait for all chunks to unload - is it guaranteed that the chunk system is in a state on shutdown that it can reliably do this? Watchdog shutdown also typically failed due to thread checks, which is now resolved. - Saving of data is not unified (i.e can save chunk data without saving entity data, poses problems for desync if shutdown is really abnormal. - Entities are not loaded with chunks. This caused quite a bit of headache for Chunk#getEntities API, but now the new chunk system loads entities with chunks so that they are ready whenever the chunk loads in. Effectively brings the behavior back to 1.16 era, but still storing entities in their own separate regionfiles. The above list is not complete. The patch documentation will complete it. New chunk system hard relies on starlight and dataconverter, and most importantly the new concurrent utilities in ConcurrentUtil. Some of the old async chunk i/o interface (i.e the old file io thread reroutes _some_ calls to the new file io thread) is kept for plugin compat reasons. It will be removed in the next major version of minecraft. The old legacy chunk system patches have been moved to the removed folder in case we need them again.
2022-09-26 08:02:51 +00:00
io.papermc.paper.chunk.system.io.RegionFileIOThread.close(true); // Paper // Paper - rewrite chunk system
2021-06-11 12:02:28 +00:00
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
Rewrite chunk system (#8177) Patch documentation to come Issues with the old system that are fixed now: - World generation does not scale with cpu cores effectively. - Relies on the main thread for scheduling and maintaining chunk state, dropping chunk load/generate rates at lower tps. - Unreliable prioritisation of chunk gen/load calls that block the main thread. - Shutdown logic is utterly unreliable, as it has to wait for all chunks to unload - is it guaranteed that the chunk system is in a state on shutdown that it can reliably do this? Watchdog shutdown also typically failed due to thread checks, which is now resolved. - Saving of data is not unified (i.e can save chunk data without saving entity data, poses problems for desync if shutdown is really abnormal. - Entities are not loaded with chunks. This caused quite a bit of headache for Chunk#getEntities API, but now the new chunk system loads entities with chunks so that they are ready whenever the chunk loads in. Effectively brings the behavior back to 1.16 era, but still storing entities in their own separate regionfiles. The above list is not complete. The patch documentation will complete it. New chunk system hard relies on starlight and dataconverter, and most importantly the new concurrent utilities in ConcurrentUtil. Some of the old async chunk i/o interface (i.e the old file io thread reroutes _some_ calls to the new file io thread) is kept for plugin compat reasons. It will be removed in the next major version of minecraft. The old legacy chunk system patches have been moved to the removed folder in case we need them again.
2022-09-26 08:02:51 +00:00
index 4dc5a5888f0180e1490597e43956e8e80981f8b9..6c856dee201d84285283504aad8cf959e88b1c52 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
2022-06-09 21:43:27 +00:00
@@ -247,7 +247,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
2021-06-11 12:02:28 +00:00
}
if (this.convertOldUsers()) {
- this.getProfileCache().save();
2021-06-12 05:20:08 +00:00
+ this.getProfileCache().save(false); // Paper
2021-06-11 12:02:28 +00:00
}
if (!OldUsersConverter.serverReadyAfterUserconversion(this)) {
diff --git a/src/main/java/net/minecraft/server/players/GameProfileCache.java b/src/main/java/net/minecraft/server/players/GameProfileCache.java
2022-07-27 19:49:24 +00:00
index d246563021c32127e570809f4d849b6a156f4dc6..2249beff3200c5dab1e81bd3d10f2c3bf1e7dbc9 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/server/players/GameProfileCache.java
+++ b/src/main/java/net/minecraft/server/players/GameProfileCache.java
2022-03-18 03:53:36 +00:00
@@ -127,7 +127,7 @@ public class GameProfileCache {
2021-06-12 05:20:08 +00:00
GameProfileCache.GameProfileInfo usercache_usercacheentry = new GameProfileCache.GameProfileInfo(profile, date);
2021-06-11 12:02:28 +00:00
this.safeAdd(usercache_usercacheentry);
- if( !org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly ) this.save(); // Spigot - skip saving if disabled
2021-06-12 05:20:08 +00:00
+ if( !org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly ) this.save(true); // Spigot - skip saving if disabled // Paper - async
2021-06-11 12:02:28 +00:00
}
private long getNextOperation() {
2021-06-12 05:20:08 +00:00
@@ -160,7 +160,7 @@ public class GameProfileCache {
2021-06-11 12:02:28 +00:00
}
if (flag && !org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) { // Spigot - skip saving if disabled
- this.save();
2021-06-12 05:20:08 +00:00
+ this.save(true); // Paper
2021-06-11 12:02:28 +00:00
}
2021-07-07 06:52:40 +00:00
return optional;
2021-11-23 13:22:49 +00:00
@@ -274,7 +274,7 @@ public class GameProfileCache {
2021-06-11 12:02:28 +00:00
return arraylist;
}
- public void save() {
2021-06-12 05:20:08 +00:00
+ public void save(boolean asyncSave) { // Paper
2021-06-11 12:02:28 +00:00
JsonArray jsonarray = new JsonArray();
2021-06-12 05:20:08 +00:00
DateFormat dateformat = GameProfileCache.createDateFormat();
2021-06-11 12:02:28 +00:00
2021-11-23 13:22:49 +00:00
@@ -282,6 +282,7 @@ public class GameProfileCache {
2021-06-12 05:20:08 +00:00
jsonarray.add(GameProfileCache.writeGameProfile(usercache_usercacheentry, dateformat));
2021-06-11 12:02:28 +00:00
});
String s = this.gson.toJson(jsonarray);
+ Runnable save = () -> { // Paper
try {
BufferedWriter bufferedwriter = Files.newWriter(this.file, StandardCharsets.UTF_8);
2022-03-18 03:53:36 +00:00
@@ -306,6 +307,14 @@ public class GameProfileCache {
2021-06-11 12:02:28 +00:00
} catch (IOException ioexception) {
;
}
+ // Paper start
+ };
+ if (asyncSave) {
2021-06-12 05:20:08 +00:00
+ net.minecraft.server.MCUtil.scheduleAsyncTask(save);
2021-06-11 12:02:28 +00:00
+ } else {
+ save.run();
+ }
+ // Paper end
2022-03-18 03:53:36 +00:00
2021-06-11 12:02:28 +00:00
}