diff options
author | Spottedleaf <[email protected]> | 2022-09-26 01:02:51 -0700 |
---|---|---|
committer | GitHub <[email protected]> | 2022-09-26 01:02:51 -0700 |
commit | 01a13871deefa50e186a10b63f71c5e0459e7d30 (patch) | |
tree | caf7056fa3ad155645b2dec6046b13841eb5d4a2 /patches/server/0452-Optimize-NetworkManager-Exception-Handling.patch | |
parent | abe53a7eb477664aba5f32ff22d81f11ed48a44d (diff) | |
download | Paper-01a13871deefa50e186a10b63f71c5e0459e7d30.tar.gz Paper-01a13871deefa50e186a10b63f71c5e0459e7d30.zip |
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.
Diffstat (limited to 'patches/server/0452-Optimize-NetworkManager-Exception-Handling.patch')
-rw-r--r-- | patches/server/0452-Optimize-NetworkManager-Exception-Handling.patch | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/patches/server/0452-Optimize-NetworkManager-Exception-Handling.patch b/patches/server/0452-Optimize-NetworkManager-Exception-Handling.patch new file mode 100644 index 0000000000..cf2905d1ed --- /dev/null +++ b/patches/server/0452-Optimize-NetworkManager-Exception-Handling.patch @@ -0,0 +1,67 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Andrew Steinborn <[email protected]> +Date: Sun, 5 Jul 2020 22:38:18 -0400 +Subject: [PATCH] Optimize NetworkManager Exception Handling + + +diff --git a/src/main/java/net/minecraft/network/ConnectionProtocol.java b/src/main/java/net/minecraft/network/ConnectionProtocol.java +index 672e296cec289abd3bf797d84e16983ca50907be..aec921477e035095d569eab3335175b93a65e672 100644 +--- a/src/main/java/net/minecraft/network/ConnectionProtocol.java ++++ b/src/main/java/net/minecraft/network/ConnectionProtocol.java +@@ -302,6 +302,7 @@ public enum ConnectionProtocol { + + @Nullable + public Packet<?> createPacket(int id, FriendlyByteBuf buf) { ++ if (id < 0 || id >= this.idToDeserializer.size()) return null; // Paper + Function<FriendlyByteBuf, ? extends Packet<T>> function = this.idToDeserializer.get(id); + return function != null ? function.apply(buf) : null; + } +diff --git a/src/main/java/net/minecraft/network/Varint21FrameDecoder.java b/src/main/java/net/minecraft/network/Varint21FrameDecoder.java +index 99b581052f937b0f2d6b5d73de699008c1d51774..ed54479b14dcfc736ac90749106557f0ff537550 100644 +--- a/src/main/java/net/minecraft/network/Varint21FrameDecoder.java ++++ b/src/main/java/net/minecraft/network/Varint21FrameDecoder.java +@@ -8,8 +8,20 @@ import io.netty.handler.codec.CorruptedFrameException; + import java.util.List; + + public class Varint21FrameDecoder extends ByteToMessageDecoder { ++ private final byte[] lenBuf = new byte[3]; // Paper ++ @Override + protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) { ++ // Paper start - if channel is not active just discard the packet ++ if (!channelHandlerContext.channel().isActive()) { ++ byteBuf.skipBytes(byteBuf.readableBytes()); ++ return; ++ } ++ // Paper end + byteBuf.markReaderIndex(); ++ // Paper start - reuse temporary length buffer ++ byte[] abyte = lenBuf; ++ java.util.Arrays.fill(abyte, (byte) 0); ++ // Paper end + byte[] bs = new byte[3]; + + for(int i = 0; i < bs.length; ++i) { +diff --git a/src/main/java/net/minecraft/network/protocol/PacketUtils.java b/src/main/java/net/minecraft/network/protocol/PacketUtils.java +index 049e64c355d5f064009b1107ad15d28c44f999dd..acfa1907bfc9c29d261cfccc00d65bad9ad1a002 100644 +--- a/src/main/java/net/minecraft/network/protocol/PacketUtils.java ++++ b/src/main/java/net/minecraft/network/protocol/PacketUtils.java +@@ -30,11 +30,15 @@ public class PacketUtils { + try (co.aikar.timings.Timing ignored = timing.startTiming()) { // Paper - timings + packet.handle(listener); + } catch (Exception exception) { +- if (listener.shouldPropagateHandlingExceptions()) { +- throw exception; ++ net.minecraft.network.Connection networkmanager = listener.getConnection(); ++ if (networkmanager.getPlayer() != null) { ++ LOGGER.error("Error whilst processing packet {} for {}[{}]", packet, networkmanager.getPlayer().getScoreboardName(), networkmanager.getRemoteAddress(), exception); ++ } else { ++ LOGGER.error("Error whilst processing packet {} for connection from {}", packet, networkmanager.getRemoteAddress(), exception); + } +- +- PacketUtils.LOGGER.error("Failed to handle packet {}, suppressing error", packet, exception); ++ net.minecraft.network.chat.Component error = net.minecraft.network.chat.Component.literal("Packet processing error"); ++ networkmanager.send(new net.minecraft.network.protocol.game.ClientboundDisconnectPacket(error), net.minecraft.network.PacketSendListener.thenRun(() -> networkmanager.disconnect(error))); ++ networkmanager.setReadOnly(); + } + } else { + PacketUtils.LOGGER.debug("Ignoring packet due to disconnection: {}", packet); |