Paper/patches/server/0238-Add-Debug-Entities-option-to-debug-dupe-uuid-issues.patch

130 lines
7.5 KiB
Diff
Raw Normal View History

2021-06-14 08:41:01 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sat, 21 Jul 2018 08:25:40 -0400
Subject: [PATCH] Add Debug Entities option to debug dupe uuid issues
Add -Ddebug.entities=true to your JVM flags to gain more information
1.17: Needs to be reworked for new entity storage system
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
index 33e20bb8c7addbcf77b38abd837ca096880fc244..8b93af04aca46f59bed826e66ad9ee21cda38199 100644
2021-06-14 08:41:01 +02:00
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -884,6 +884,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-14 08:41:01 +02:00
} else {
ChunkMap.TrackedEntity playerchunkmap_entitytracker = new ChunkMap.TrackedEntity(entity, i, j, entitytypes.trackDeltas());
+ entity.tracker = playerchunkmap_entitytracker; // Paper - Fast access to tracker
this.entityMap.put(entity.getId(), playerchunkmap_entitytracker);
playerchunkmap_entitytracker.updatePlayers(this.level.players());
if (entity instanceof ServerPlayer) {
@@ -926,7 +927,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-14 08:41:01 +02:00
if (playerchunkmap_entitytracker1 != null) {
playerchunkmap_entitytracker1.broadcastRemoved();
}
-
+ entity.tracker = null; // Paper - We're no longer tracked
}
protected void tick() {
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index 65cf330708b4667fd60fdb1094df5a808ae5c2f2..efc2db1b27e9ac4b1094b7e529c198a94d05b164 100644
2021-06-14 08:41:01 +02:00
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
2022-07-27 21:49:24 +02:00
@@ -216,6 +216,9 @@ public class ServerLevel extends Level implements WorldGenLevel {
2021-06-14 08:41:01 +02:00
public final LevelStorageSource.LevelStorageAccess convertable;
public final UUID uuid;
public boolean hasPhysicsEvent = true; // Paper
+ public static Throwable getAddToWorldStackTrace(Entity entity) {
+ return new Throwable(entity + " Added to world at " + new java.util.Date());
+ }
@Override public LevelChunk getChunkIfLoaded(int x, int z) { // Paper - this was added in world too but keeping here for NMS ABI
return this.chunkSource.getChunk(x, z, false);
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 10:02:51 +02:00
@@ -1232,7 +1235,28 @@ public class ServerLevel extends Level implements WorldGenLevel {
2021-06-14 08:41:01 +02:00
// CraftBukkit start
2021-11-23 16:04:41 +01:00
private boolean addEntity(Entity entity, CreatureSpawnEvent.SpawnReason spawnReason) {
2021-06-14 08:41:01 +02:00
org.spigotmc.AsyncCatcher.catchOp("entity add"); // Spigot
+ // Paper start
+ if (entity.valid) {
+ MinecraftServer.LOGGER.error("Attempted Double World add on " + entity, new Throwable());
+
+ if (DEBUG_ENTITIES) {
+ Throwable thr = entity.addedToWorldStack;
+ if (thr == null) {
+ MinecraftServer.LOGGER.error("Double add entity has no add stacktrace");
+ } else {
+ MinecraftServer.LOGGER.error("Double add stacktrace: ", thr);
+ }
+ }
+ return true;
+ }
+ // Paper end
if (entity.isRemoved()) {
+ // Paper start
+ if (DEBUG_ENTITIES) {
+ new Throwable("Tried to add entity " + entity + " but it was marked as removed already").printStackTrace(); // CraftBukkit
+ getAddToWorldStackTrace(entity).printStackTrace();
+ }
+ // Paper end
2021-11-23 16:04:41 +01:00
// WorldServer.LOGGER.warn("Tried to add entity {} but it was marked as removed already", EntityTypes.getKey(entity.getType())); // CraftBukkit
2021-06-14 08:41:01 +02:00
return false;
} else {
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.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 10:02:51 +02:00
index 2e988d59404c52cd9c290b96d21f886573cda0fa..0e632f9eabd0d55a4eaacff54abaf637660528dd 100644
2021-06-14 08:41:01 +02:00
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -235,6 +235,8 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
2021-06-14 08:41:01 +02:00
public com.destroystokyo.paper.loottable.PaperLootableInventoryData lootableData; // Paper
private CraftEntity bukkitEntity;
+ public @org.jetbrains.annotations.Nullable net.minecraft.server.level.ChunkMap.TrackedEntity tracker; // Paper
2022-02-28 23:02:20 +01:00
+ public @Nullable Throwable addedToWorldStack; // Paper - entity debug
2021-06-14 08:41:01 +02:00
public CraftEntity getBukkitEntity() {
if (this.bukkitEntity == null) {
this.bukkitEntity = CraftEntity.getEntity(this.level.getCraftServer(), this);
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.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 10:02:51 +02:00
index f4249ee3259a95b9f079a75c78ccf96a14b99b0d..9ed8117afa4eb1ff9e7403d3ab92a9e6cb0fab73 100644
2021-06-14 08:41:01 +02:00
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
2022-06-07 23:45:11 +02:00
@@ -148,6 +148,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
2021-06-14 08:41:01 +02:00
public boolean pvpMode;
public boolean keepSpawnInMemory = true;
public org.bukkit.generator.ChunkGenerator generator;
+ public static final boolean DEBUG_ENTITIES = Boolean.getBoolean("debug.entities"); // Paper
2021-07-07 08:52:40 +02:00
public boolean preventPoiUpdated = false; // CraftBukkit - SPIGOT-5710
2021-06-14 08:41:01 +02:00
public boolean captureBlockStates = false;
diff --git a/src/main/java/net/minecraft/world/level/entity/EntityLookup.java b/src/main/java/net/minecraft/world/level/entity/EntityLookup.java
index e6b9f812e521abd552e0c7dc0429d5a62f2bfc35..f4731d69946871768ecf16149a47d2ef1cb3e910 100644
2021-06-14 08:41:01 +02:00
--- a/src/main/java/net/minecraft/world/level/entity/EntityLookup.java
+++ b/src/main/java/net/minecraft/world/level/entity/EntityLookup.java
2022-02-28 23:02:20 +01:00
@@ -34,6 +34,26 @@ public class EntityLookup<T extends EntityAccess> {
2021-06-14 08:41:01 +02:00
UUID uUID = entity.getUUID();
if (this.byUuid.containsKey(uUID)) {
LOGGER.warn("Duplicate entity UUID {}: {}", uUID, entity);
+ // Paper start - extra debug info
2022-02-28 23:02:20 +01:00
+ if (entity instanceof net.minecraft.world.entity.Entity entityCast) {
2021-06-14 08:41:01 +02:00
+ if (net.minecraft.server.level.ServerLevel.DEBUG_ENTITIES) {
2022-02-28 23:02:20 +01:00
+ entityCast.addedToWorldStack = net.minecraft.server.level.ServerLevel.getAddToWorldStackTrace(entityCast);
2021-06-14 08:41:01 +02:00
+ }
+
+ T old = this.byUuid.get(entity.getUUID());
2022-02-28 23:02:20 +01:00
+ if (old instanceof net.minecraft.world.entity.Entity oldCast && old != null && oldCast.getId() != entity.getId() && oldCast.valid) {
+ LOGGER.error("Overwrote an existing entity " + oldCast + " with " + entity);
2021-06-14 08:41:01 +02:00
+ if (net.minecraft.server.level.ServerLevel.DEBUG_ENTITIES) {
2022-02-28 23:02:20 +01:00
+ if (oldCast.addedToWorldStack != null) {
+ oldCast.addedToWorldStack.printStackTrace();
2021-06-14 08:41:01 +02:00
+ } else {
2022-02-28 23:02:20 +01:00
+ LOGGER.error("Oddly, the old entity was not added to the world in the normal way. Plugins?");
2021-06-14 08:41:01 +02:00
+ }
2022-02-28 23:02:20 +01:00
+ entityCast.addedToWorldStack.printStackTrace();
2021-06-14 08:41:01 +02:00
+ }
+ }
+ }
+ // Paper end
} else {
this.byUuid.put(uUID, entity);
this.byId.put(entity.getId(), entity);