From a08630ed35f4fd7a561f45ab49b871267430ad5a Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Sun, 19 Dec 2021 09:15:22 -0800 Subject: [PATCH] Only write chunk data to disk if it serializes without throwing This ensures at least a valid version of the chunk exists on disk, even if outdated --- ...-data-to-disk-if-it-serializes-witho.patch | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 patches/server/Only-write-chunk-data-to-disk-if-it-serializes-witho.patch diff --git a/patches/server/Only-write-chunk-data-to-disk-if-it-serializes-witho.patch b/patches/server/Only-write-chunk-data-to-disk-if-it-serializes-witho.patch new file mode 100644 index 0000000000..ffdc576182 --- /dev/null +++ b/patches/server/Only-write-chunk-data-to-disk-if-it-serializes-witho.patch @@ -0,0 +1,38 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Spottedleaf +Date: Sun, 19 Dec 2021 09:13:41 -0800 +Subject: [PATCH] Only write chunk data to disk if it serializes without + throwing + +This ensures at least a valid version of the chunk exists +on disk, even if outdated + +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 +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java ++++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java +@@ -0,0 +0,0 @@ public class RegionFileStorage implements AutoCloseable { + NbtIo.write(nbt, (DataOutput) dataoutputstream); + regionfile.setStatus(pos.x, pos.z, ChunkSerializer.getStatus(nbt)); // Paper - cache status on disk + regionfile.setOversized(pos.x, pos.z, false); // Paper - We don't do this anymore, mojang stores differently, but clear old meta flag if it exists to get rid of our own meta file once last oversized is gone ++ dataoutputstream.close(); // Paper - only write if successful + } catch (Throwable throwable) { + if (dataoutputstream != null) { + try { +- dataoutputstream.close(); ++ //dataoutputstream.close(); // Paper - don't write garbage data to disk if writing serialization fails + } catch (Throwable throwable1) { + throwable.addSuppressed(throwable1); + } +@@ -0,0 +0,0 @@ public class RegionFileStorage implements AutoCloseable { + + throw throwable; + } +- +- if (dataoutputstream != null) { +- dataoutputstream.close(); +- } ++ // Paper - move into try block to only write if successfully serialized + } + + // Paper start