From 78b19f89a4658892c5ec79d5062f8c5b95ca149b Mon Sep 17 00:00:00 2001 From: Owen <23108066+Owen1212055@users.noreply.github.com> Date: Mon, 8 Aug 2022 07:32:17 -0400 Subject: [PATCH] Separate Command Sending to Separate Thread Pool (#8170) --- .../0297-Async-command-map-building.patch | 45 +++++++++++++------ .../0298-Implement-Brigadier-Mojang-API.patch | 14 +++--- patches/server/0311-Server-Tick-Events.patch | 6 +-- ...isPrimaryThread-and-MinecraftServer-.patch | 4 +- patches/server/0339-Optimize-Hoppers.patch | 4 +- ...-Add-tick-times-API-and-mspt-command.patch | 6 +-- .../0385-Improved-Watchdog-Support.patch | 22 ++++----- .../server/0407-misc-debugging-dumps.patch | 4 +- ...Wait-for-Async-Tasks-during-shutdown.patch | 4 +- ...ld-Difficulty-Remembering-Difficulty.patch | 6 +-- ...-incremental-chunk-and-player-saving.patch | 8 ++-- .../0493-Cache-block-data-strings.patch | 4 +- ...-non-whitelisted-player-when-white-l.patch | 4 +- ...8-Added-ServerResourcesReloadedEvent.patch | 6 +-- ...pty-commands-shall-not-be-dispatched.patch | 4 +- patches/server/0569-Add-PaperRegistry.patch | 6 +-- patches/server/0583-EntityMoveEvent.patch | 4 +- ...pport-for-hex-color-codes-in-console.patch | 4 +- ...telist-use-configurable-kick-message.patch | 4 +- ...mmands-if-tab-completion-is-disabled.patch | 4 +- .../0655-Add-PlayerKickEvent-causes.patch | 6 +-- ...718-Vanilla-command-permission-fixes.patch | 4 +- .../0736-Execute-chunk-tasks-mid-tick.patch | 6 +-- ...y-type-tags-suggestions-in-selectors.patch | 8 ++-- ...sks-fairly-for-worlds-while-waiting-.patch | 6 +-- patches/server/0854-Custom-Potion-Mixes.patch | 4 +- .../0861-Fix-save-problems-on-shutdown.patch | 8 ++-- ...n-on-world-create-while-being-ticked.patch | 6 +-- ...and-message-for-brigadier-syntax-exc.patch | 4 +- 29 files changed, 117 insertions(+), 98 deletions(-) diff --git a/patches/server/0297-Async-command-map-building.patch b/patches/server/0297-Async-command-map-building.patch index bc4fcc419c..0e42b06c04 100644 --- a/patches/server/0297-Async-command-map-building.patch +++ b/patches/server/0297-Async-command-map-building.patch @@ -3,38 +3,45 @@ From: Callahan Date: Wed, 8 Apr 2020 02:42:14 -0500 Subject: [PATCH] Async command map building +This adds a custom pool inorder to make sure that they are closed +without much though, as it doesn't matter if the client is not sent +commands if the server is restarting. Using the default async pool caused issues to arise +due to the shutdown logic generally being much later. diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java -index 2bf67468a6c745bc6243c65210477ba129bfcb07..685e04b1f17938d49cd126bcfe2f488f21afbea2 100644 +index 2bf67468a6c745bc6243c65210477ba129bfcb07..91b32a4856a4c9d6dc12871ed080f7a67311ead0 100644 --- a/src/main/java/net/minecraft/commands/Commands.java +++ b/src/main/java/net/minecraft/commands/Commands.java -@@ -34,6 +34,7 @@ import net.minecraft.network.chat.ComponentUtils; - import net.minecraft.network.chat.HoverEvent; - import net.minecraft.network.chat.MutableComponent; - import net.minecraft.network.protocol.game.ClientboundCommandsPacket; -+import net.minecraft.server.MinecraftServer; - import net.minecraft.server.commands.AdvancementCommands; - import net.minecraft.server.commands.AttributeCommand; - import net.minecraft.server.commands.BanIpCommands; -@@ -360,6 +361,12 @@ public class Commands { +@@ -360,6 +360,23 @@ public class Commands { if ( org.spigotmc.SpigotConfig.tabComplete < 0 ) return; // Spigot // CraftBukkit start // Register Vanilla commands into builtRoot as before + // Paper start - Async command map building -+ net.minecraft.server.MCUtil.scheduleAsyncTask(() -> this.sendAsync(player)); ++ COMMAND_SENDING_POOL.execute(() -> { ++ this.sendAsync(player); ++ }); + } + ++ public static final java.util.concurrent.ThreadPoolExecutor COMMAND_SENDING_POOL = new java.util.concurrent.ThreadPoolExecutor( ++ 0, 2, 60L, java.util.concurrent.TimeUnit.SECONDS, ++ new java.util.concurrent.LinkedBlockingQueue<>(), ++ new com.google.common.util.concurrent.ThreadFactoryBuilder() ++ .setNameFormat("Paper Async Command Builder Thread Pool - %1$d") ++ .setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(net.minecraft.server.MinecraftServer.LOGGER)) ++ .build() ++ ); ++ + private void sendAsync(ServerPlayer player) { + // Paper end - Async command map building Map, CommandNode> map = Maps.newIdentityHashMap(); // Use identity to prevent aliasing issues RootCommandNode vanillaRoot = new RootCommandNode(); -@@ -377,7 +384,14 @@ public class Commands { +@@ -377,7 +394,14 @@ public class Commands { for (CommandNode node : rootcommandnode.getChildren()) { bukkit.add(node.getName()); } + // Paper start - Async command map building -+ MinecraftServer.getServer().execute(() -> { ++ net.minecraft.server.MinecraftServer.getServer().execute(() -> { + runSync(player, bukkit, rootcommandnode); + }); + } @@ -44,3 +51,15 @@ index 2bf67468a6c745bc6243c65210477ba129bfcb07..685e04b1f17938d49cd126bcfe2f488f PlayerCommandSendEvent event = new PlayerCommandSendEvent(player.getBukkitEntity(), new LinkedHashSet<>(bukkit)); event.getPlayer().getServer().getPluginManager().callEvent(event); +diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java +index 89c0c0d0d3458f38a1a0b91617b84f439af667c8..6f6125c3896fb388e0840d3e224b826bfa10eec0 100644 +--- a/src/main/java/net/minecraft/server/MinecraftServer.java ++++ b/src/main/java/net/minecraft/server/MinecraftServer.java +@@ -879,6 +879,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop(player.getBukkitEntity(), (RootCommandNode) rootcommandnode, false).callEvent(); // Paper - MinecraftServer.getServer().execute(() -> { + net.minecraft.server.MinecraftServer.getServer().execute(() -> { runSync(player, bukkit, rootcommandnode); }); -@@ -392,6 +393,7 @@ public class Commands { +@@ -402,6 +403,7 @@ public class Commands { private void runSync(ServerPlayer player, Collection bukkit, RootCommandNode rootcommandnode) { // Paper end - Async command map building @@ -93,7 +93,7 @@ index 685e04b1f17938d49cd126bcfe2f488f21afbea2..d4e3dc8d67006dcff2a64d03c29ffc94 PlayerCommandSendEvent event = new PlayerCommandSendEvent(player.getBukkitEntity(), new LinkedHashSet<>(bukkit)); event.getPlayer().getServer().getPluginManager().callEvent(event); -@@ -410,6 +412,11 @@ public class Commands { +@@ -420,6 +422,11 @@ public class Commands { while (iterator.hasNext()) { CommandNode commandnode2 = (CommandNode) iterator.next(); @@ -106,7 +106,7 @@ index 685e04b1f17938d49cd126bcfe2f488f21afbea2..d4e3dc8d67006dcff2a64d03c29ffc94 if (commandnode2.canUse(source)) { diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java -index c60baac35e4ae333971532ad2da6dd0925efc1a9..4f9adc601ccc84beaee91a6ca9d6cd2740c4416e 100644 +index 19924f3d45af6c4006bd2d921cbeab67a4846059..81c6dd957eb990708fd5f6a1b991a5e8370acf80 100644 --- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java @@ -833,8 +833,12 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic diff --git a/patches/server/0311-Server-Tick-Events.patch b/patches/server/0311-Server-Tick-Events.patch index 82c99a607c..a9e742012a 100644 --- a/patches/server/0311-Server-Tick-Events.patch +++ b/patches/server/0311-Server-Tick-Events.patch @@ -6,10 +6,10 @@ Subject: [PATCH] Server Tick Events Fires event at start and end of a server tick diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index 1a76a4239213c7b8dc40e656164427c1c4f7c2cf..cadf93de666d9db4b08710e36d4420de312c9e2e 100644 +index 6f6125c3896fb388e0840d3e224b826bfa10eec0..8c48544daae0f18a39511df12f7066fc0e383d2c 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java -@@ -1307,6 +1307,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop 0; // Paper diff --git a/patches/server/0373-Add-tick-times-API-and-mspt-command.patch b/patches/server/0373-Add-tick-times-API-and-mspt-command.patch index 6f4253e903..eb51df65e2 100644 --- a/patches/server/0373-Add-tick-times-API-and-mspt-command.patch +++ b/patches/server/0373-Add-tick-times-API-and-mspt-command.patch @@ -125,7 +125,7 @@ index 6a00f3d38da8107825ab1d405f337fd077b09f72..d31b5ed47cffc61c90c926a0cd2005b7 public static void registerCommands(final MinecraftServer server) { diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index e8b826e431229b80fbba2bcdaed2105e6a9bcbdd..7b646a46d561c3cdb03a488d691e811d40684417 100644 +index 181e35da5919ba3b91246b427f2c5773acf1dd12..0612bf8ecc6e1b76d728fea852e850abc1702edf 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -237,6 +237,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop { CompletableFuture completablefuture; diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java -index d67362983816db2b264d30b59423b05843cded16..f5f536549d7daf14ed5f678a55969c540a5dc48d 100644 +index 27dd95242c80d875de8f07e111f06e383eeec0d9..97c670508df6e5ee2a05a4765aafbeb23949b647 100644 --- a/src/main/java/net/minecraft/server/players/PlayerList.java +++ b/src/main/java/net/minecraft/server/players/PlayerList.java @@ -517,7 +517,7 @@ public abstract class PlayerList { @@ -343,7 +343,7 @@ index 4b3a431701fa1e1e1595301291baccd5bafa52f6..b5ed78fa95349974c71ac7113e5f6533 // Paper start diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java -index 9a5373304b445408244fe9850c10526d1df21855..0c76f2e8038bf0bc3edf464295c606acf03a8337 100644 +index 3472114c373d7b884d8ae24906e30daa039d0742..987bc4577190d827718b5144656aaddf22599cab 100644 --- a/src/main/java/org/bukkit/craftbukkit/Main.java +++ b/src/main/java/org/bukkit/craftbukkit/Main.java @@ -12,6 +12,8 @@ import java.util.logging.Level; diff --git a/patches/server/0407-misc-debugging-dumps.patch b/patches/server/0407-misc-debugging-dumps.patch index b9c6fa7fd5..085d0755d1 100644 --- a/patches/server/0407-misc-debugging-dumps.patch +++ b/patches/server/0407-misc-debugging-dumps.patch @@ -29,7 +29,7 @@ index 0000000000000000000000000000000000000000..2d5494d2813b773e60ddba6790b750a9 + } +} diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index 140ff101b8568fa6df0a793e0068f59d48e91e07..d6d398ad64ec923e36155f8617aeb8d0906a9d59 100644 +index 40945909bbefa59da6be784bcf440dfb2075b670..b1f8374253d04d1468f5d57792b30f91a274b97f 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -871,6 +871,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop completablefuture = CompletableFuture.supplyAsync(() -> { Stream stream = dataPacks.stream(); // CraftBukkit - decompile error -@@ -2003,6 +2009,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop(Class apiClass, ResourceKey> resourceKey) { +} diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index 04be281c3862707055b143267186169205720ab2..ea98c98e4449451895c6d91481ace6908c206f45 100644 +index e72af8f8c49dabcbe1d0a80176520ccdb55b1f5b..9484e447959a9c25ac6ef318be1569d236b5915d 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java -@@ -2009,6 +2009,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop 0; // Paper diff --git a/patches/server/0591-Add-support-for-hex-color-codes-in-console.patch b/patches/server/0591-Add-support-for-hex-color-codes-in-console.patch index dfcbb6395d..981d17a7c9 100644 --- a/patches/server/0591-Add-support-for-hex-color-codes-in-console.patch +++ b/patches/server/0591-Add-support-for-hex-color-codes-in-console.patch @@ -282,10 +282,10 @@ index 0000000000000000000000000000000000000000..b4d0b7ecd56ab952319946854168c129 + +} diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index e4f1ceb934917804fc415d3d06ebf9d093a44f7d..1387ed71ff09b834361e415e5fc78786f68dd371 100644 +index 75cd5667eb0f047cdec56b4131dcd1c4f22d4067..af21aa771d90ea47cc23457711a17b69e7b56e9a 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java -@@ -1671,7 +1671,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop modifier = null; private boolean forks; diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java -index edf980cf8992ddfe003ced279fe1324fc2364e5a..e70e5af7e49e4ccf332d9ce44e1a106344b35490 100644 +index 884a7c3a082140d2e1d154851c534ab09f5da4ce..6d480d0332ee9348eacc3269890ee49206623c2a 100644 --- a/src/main/java/net/minecraft/commands/Commands.java +++ b/src/main/java/net/minecraft/commands/Commands.java -@@ -213,7 +213,13 @@ public class Commands { +@@ -212,7 +212,13 @@ public class Commands { if (environment.includeIntegrated) { PublishCommand.register(this.dispatcher); } diff --git a/patches/server/0736-Execute-chunk-tasks-mid-tick.patch b/patches/server/0736-Execute-chunk-tasks-mid-tick.patch index 9602f9b1f5..60e415621c 100644 --- a/patches/server/0736-Execute-chunk-tasks-mid-tick.patch +++ b/patches/server/0736-Execute-chunk-tasks-mid-tick.patch @@ -19,10 +19,10 @@ index 23e564b05ba438924180c91f9b19a60731eedd1b..5ec241d49ff5e3a161a39006f05823a5 private MinecraftTimings() {} diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index 660e1b6955115d67cb37161ef556f90acc53bdfa..621956c024d64bcaa868e0bb01c485fe4ac11df3 100644 +index 4f14a5d9b9b14727021fcb2491c15b9978f17f10..2d94390e3b9fa3afd2471cc691d59de0f470b46c 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java -@@ -1303,6 +1303,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop tree, CommandNode result, CommandSourceStack source, Map, CommandNode> resultNodes) { Iterator iterator = tree.getChildren().iterator(); @@ -46,7 +46,7 @@ index 8380ab300e192064735fcb54c61951522dec8511..e998b01faa9c1d2e5f0fd91f0afdb24d while (iterator.hasNext()) { CommandNode commandnode2 = (CommandNode) iterator.next(); // Paper start -@@ -448,6 +449,12 @@ public class Commands { +@@ -458,6 +459,12 @@ public class Commands { if (requiredargumentbuilder.getSuggestionsProvider() != null) { requiredargumentbuilder.suggests(SuggestionProviders.safelySwap(requiredargumentbuilder.getSuggestionsProvider())); diff --git a/patches/server/0846-Execute-chunk-tasks-fairly-for-worlds-while-waiting-.patch b/patches/server/0846-Execute-chunk-tasks-fairly-for-worlds-while-waiting-.patch index c9b67dcc2d..979e14609b 100644 --- a/patches/server/0846-Execute-chunk-tasks-fairly-for-worlds-while-waiting-.patch +++ b/patches/server/0846-Execute-chunk-tasks-fairly-for-worlds-while-waiting-.patch @@ -9,10 +9,10 @@ This might result in chunks loading far slower in the nether, for example. diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index beaefa13a4635a69d06f652a9ec506072490fd19..ae59d5533a0eb2c427433042512fc560af99940d 100644 +index a4433426efd0823cd8145a50b38127f63e90adc9..1444391ded50ec10e9bfeb073b01c885c429b8bd 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java -@@ -1313,6 +1313,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop { return worldserver1.getChunkSource().chunkMap.hasWork(); })) { -@@ -968,9 +975,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop { return true; }, false); @@ -42,7 +42,7 @@ index 025f033ce7816fd32eb2d7d3f3cba0c8468ffd38..6ff1c5be14332404ae76da1695ce1d49 } this.saveAllChunks(false, true, false); -@@ -1265,6 +1274,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop S spin(Function serverFactory) { AtomicReference atomicreference = new AtomicReference(); -@@ -1526,6 +1527,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop 0; // Paper -@@ -1573,6 +1575,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop= 0) { int j = Math.min(commandsyntaxexception.getInput().length(), commandsyntaxexception.getCursor()); MutableComponent ichatmutablecomponent = Component.empty().withStyle(ChatFormatting.GRAY).withStyle((chatmodifier) -> {