mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-26 04:25:26 +01:00
01a13871de
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.
75 lines
3.3 KiB
Diff
75 lines
3.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
|
|
Date: Sat, 5 Mar 2022 17:12:52 -0800
|
|
Subject: [PATCH] Fix save problems on shutdown
|
|
|
|
- Save level.dat first, in case the shutdown is killed later
|
|
- Force run minecraftserver tasks and the chunk source tasks
|
|
while waiting for the chunk system to empty, as there's simply
|
|
too much trash that could prevent them from executing during
|
|
the chunk source tick (i.e "time left in tick" logic).
|
|
- Set forceTicks to true, so that player packets are always
|
|
processed so that the main process queue can be drained
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
index df08b7afcf19ce694a87c25e8589c0c72521c5db..4d920031300a9801debc2eb39a4d3cb9d8fbb330 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -957,6 +957,13 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
}
|
|
}
|
|
|
|
+ // Paper start - let's be a little more intelligent around crashes
|
|
+ // make sure level.dat saves
|
|
+ for (ServerLevel level : this.getAllLevels()) {
|
|
+ level.saveLevelDat();
|
|
+ }
|
|
+ // Paper end - let's be a little more intelligent around crashes
|
|
+
|
|
while (this.levels.values().stream().anyMatch((worldserver1) -> {
|
|
return worldserver1.getChunkSource().chunkMap.hasWork();
|
|
})) {
|
|
@@ -969,9 +976,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
worldserver.getChunkSource().tick(() -> {
|
|
return true;
|
|
}, false);
|
|
+ while (worldserver.getChunkSource().pollTask()); // Paper - drain tasks
|
|
}
|
|
|
|
- this.waitUntilNextTick();
|
|
+ this.forceTicks = true; // Paper
|
|
+ while (this.pollTask()); // Paper - drain tasks
|
|
}
|
|
|
|
this.saveAllChunks(false, true, false);
|
|
@@ -1266,6 +1275,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
}
|
|
|
|
private boolean haveTime() {
|
|
+ // Paper start
|
|
+ if (this.forceTicks) {
|
|
+ return true;
|
|
+ }
|
|
+ // Paper end
|
|
// CraftBukkit start
|
|
if (isOversleep) return canOversleep();// Paper - because of our changes, this logic is broken
|
|
return this.forceTicks || this.runningTask() || Util.getMillis() < (this.mayHaveDelayedTasks ? this.delayedTasksMaxNextTickTime : this.nextTickTime);
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
index e71ae32d9827d8a6fb8543abdba7627897ac9f2e..eceaa1f2ede1c068f9090d13bf9d3b3afaa08cc3 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -1284,7 +1284,13 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
|
}
|
|
|
|
}
|
|
+ // Paper start
|
|
+ this.saveLevelDat();
|
|
+ }
|
|
|
|
+ public void saveLevelDat() {
|
|
+ this.saveLevelData();
|
|
+ // Paper end
|
|
// CraftBukkit start - moved from MinecraftServer.saveChunks
|
|
ServerLevel worldserver1 = this;
|
|
|