2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Mon, 4 Mar 2013 23:46:10 -0500
Subject: [PATCH] Chunk Save Reattempt
We commonly have "Stream Closed" errors on chunk saving, so this code should re-try to save the chunk in the event of failure and hopefully prevent rollbacks.
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
2022-12-07 17:46:46 +01:00
index aa8972fd1a1fade05d60ab69efb8ff24f344508a..ddcc212ba83d9365adb842b3d3ced64e3d7dd155 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
2022-09-01 18:51:59 +02:00
@@ -275,7 +275,7 @@ public class RegionFile implements AutoCloseable {
2021-06-11 14:02:28 +02:00
return true;
}
} catch (IOException ioexception) {
- com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(ioexception); // Paper
+ com.destroystokyo.paper.util.SneakyThrow.sneaky(ioexception); // Paper - we want the upper try/catch to retry this
return false;
}
}
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
2022-09-26 10:02:51 +02:00
index 45cec71b3b2f9444d7be7e5bf9fab166b28ea34d..ece0fd4b51d124be232e24d08f115b9267cb21cb 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
2022-09-26 10:02:51 +02:00
@@ -167,6 +167,7 @@ public class RegionFileStorage implements AutoCloseable {
}
// Paper end - rewrite chunk system
2022-09-01 18:51:59 +02:00
try { // Paper
2021-06-11 14:02:28 +02:00
+ int attempts = 0; Exception laste = null; while (attempts++ < 5) { try { // Paper
2021-06-12 02:57:04 +02:00
if (nbt == null) {
regionfile.clear(pos);
2022-09-26 10:02:51 +02:00
@@ -191,7 +192,18 @@ public class RegionFileStorage implements AutoCloseable {
2022-09-01 18:51:59 +02:00
dataoutputstream.close();
2021-06-12 02:57:04 +02:00
}
2021-06-11 14:02:28 +02:00
}
2022-09-01 18:51:59 +02:00
+ // Paper start
+ return;
2021-06-11 14:02:28 +02:00
+ } catch (Exception ex) {
+ laste = ex;
+ }
+ }
2022-09-01 18:51:59 +02:00
2021-06-11 14:02:28 +02:00
+ if (laste != null) {
+ com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(laste);
2022-09-01 18:51:59 +02:00
+ net.minecraft.server.MinecraftServer.LOGGER.error("Failed to save chunk " + pos, laste);
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
2022-09-01 18:51:59 +02:00
} finally { // Paper start
regionfile.fileLock.unlock();
} // Paper end