mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-01 18:24:06 +00:00
Pump native chunk tasks while server stop waits for pregen
On Paper only the server thread advances chunk tasks, so a stop that blocks on a running pregen can wait forever. Stop now polls the native chunk queue while joining the pregen worker, and pregen skips eviction and flush scheduling once the server is stopping.
Upstream: 083e68986
This commit is contained in:
1 parent
e87e6d9fae
commit
ae60b14402
8 files changed
+226
-3
No files matched your search
@@ -43,6 +43,7 @@ import art.arcane.iris.util.common.scheduling.J;
|
||||
import java.awt.Color;
|
||||
import java.awt.EventQueue;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -57,6 +58,7 @@ public class PregeneratorJob implements PregenListener, PregenRenderSource {
|
||||
// 60s permit drain + 120s flush + plate reclaim), or a routine drain trips the deadline
|
||||
// and aborts the engine shutdown sequence mid-teardown.
|
||||
private static final long WORLD_SHUTDOWN_TIMEOUT_MILLIS = 200_000L;
|
||||
private static final long PENDING_TASK_POLL_MILLIS = 1L;
|
||||
private static final Color COLOR_EXISTS = parseColor("#4d7d5b");
|
||||
private static final Color COLOR_BLACK = parseColor("#4d7d5b");
|
||||
private static final Color COLOR_MANTLE = parseColor("#3c2773");
|
||||
@@ -203,6 +205,29 @@ public class PregeneratorJob implements PregenListener, PregenRenderSource {
|
||||
return shutdownAndWait(inst, timeoutMs);
|
||||
}
|
||||
|
||||
public static boolean shutdownAndWait(long timeoutMs, Runnable processPendingTasks) {
|
||||
Objects.requireNonNull(processPendingTasks, "processPendingTasks");
|
||||
PregeneratorJob inst = instance.get();
|
||||
if (inst == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
inst.pregenerator.close();
|
||||
inst.worker.interrupt();
|
||||
long started = System.nanoTime();
|
||||
long timeoutNanos = TimeUnit.MILLISECONDS.toNanos(Math.max(1L, timeoutMs));
|
||||
try {
|
||||
while (inst.worker.isAlive() && System.nanoTime() - started < timeoutNanos) {
|
||||
processPendingTasks.run();
|
||||
inst.worker.join(PENDING_TASK_POLL_MILLIS);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IllegalStateException("Interrupted while stopping the Iris pregenerator.", e);
|
||||
}
|
||||
return finishShutdown(inst, timeoutMs);
|
||||
}
|
||||
|
||||
private static boolean shutdownAndWait(PregeneratorJob inst, long timeoutMs) {
|
||||
inst.pregenerator.close();
|
||||
inst.worker.interrupt();
|
||||
@@ -212,6 +237,10 @@ public class PregeneratorJob implements PregenListener, PregenRenderSource {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IllegalStateException("Interrupted while stopping the Iris pregenerator.", e);
|
||||
}
|
||||
return finishShutdown(inst, timeoutMs);
|
||||
}
|
||||
|
||||
private static boolean finishShutdown(PregeneratorJob inst, long timeoutMs) {
|
||||
if (inst.worker.isAlive()) {
|
||||
throw new IllegalStateException("Timed out while stopping the Iris pregenerator after "
|
||||
+ Math.max(1L, timeoutMs) + "ms.");
|
||||
|
||||
@@ -223,6 +223,10 @@ public interface INMSBinding {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean pollChunkTask(World world) {
|
||||
return false;
|
||||
}
|
||||
|
||||
default void flushChunkIO(World world) {
|
||||
}
|
||||
|
||||
|
||||
+27
-1
@@ -70,6 +70,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
private static final long CLOSE_DRAIN_WARNING_SECONDS = 20L;
|
||||
private static final long CLOSE_DRAIN_TIMEOUT_SECONDS = 60L;
|
||||
private static final long FLUSH_TIMEOUT_SECONDS = 120L;
|
||||
private static final long FLUSH_STOP_POLL_MILLIS = 100L;
|
||||
private final World world;
|
||||
private final IrisRuntimeSchedulerMode runtimeSchedulerMode;
|
||||
private final IrisPaperLikeBackendMode paperLikeBackendMode;
|
||||
@@ -349,6 +350,9 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
|
||||
private void evictRegion(long c) {
|
||||
if (IrisToolbelt.isServerStopping()) {
|
||||
return;
|
||||
}
|
||||
if (!evictedRegions.add(c)) {
|
||||
return;
|
||||
}
|
||||
@@ -418,6 +422,9 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
|
||||
private void flushAllRemainingChunks() {
|
||||
if (IrisToolbelt.isServerStopping()) {
|
||||
return;
|
||||
}
|
||||
List<Long> keys = new ArrayList<>(regionChunks.keySet());
|
||||
|
||||
if (foliaRuntime) {
|
||||
@@ -428,6 +435,9 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
|
||||
CompletableFuture<Void> flush = J.sfut(() -> {
|
||||
if (IrisToolbelt.isServerStopping()) {
|
||||
return;
|
||||
}
|
||||
for (Long rk : keys) {
|
||||
if (!evictedRegions.add(rk)) {
|
||||
continue;
|
||||
@@ -451,7 +461,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
});
|
||||
|
||||
try {
|
||||
flush.get(FLUSH_TIMEOUT_SECONDS, TimeUnit.SECONDS);
|
||||
awaitFlushUnlessServerStops(flush);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
IrisLogging.warn("Interrupted while flushing pregen chunks for " + world.getName() + ".");
|
||||
@@ -463,6 +473,22 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
}
|
||||
|
||||
private static void awaitFlushUnlessServerStops(CompletableFuture<Void> flush) throws Exception {
|
||||
long started = System.nanoTime();
|
||||
long timeoutNanos = TimeUnit.SECONDS.toNanos(FLUSH_TIMEOUT_SECONDS);
|
||||
while (!IrisToolbelt.isServerStopping()) {
|
||||
long remainingNanos = timeoutNanos - (System.nanoTime() - started);
|
||||
if (remainingNanos <= 0L) {
|
||||
throw new TimeoutException();
|
||||
}
|
||||
try {
|
||||
flush.get(Math.min(remainingNanos, TimeUnit.MILLISECONDS.toNanos(FLUSH_STOP_POLL_MILLIS)), TimeUnit.NANOSECONDS);
|
||||
return;
|
||||
} catch (TimeoutException pollElapsed) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Chunk onChunkFutureFailure(int x, int z, Throwable throwable) {
|
||||
try {
|
||||
IrisLogging.warn("Failed async pregen chunk load at " + x + "," + z + ". " + metricsSnapshot());
|
||||
|
||||
Reference in new issue
Block a user