Only write to cached header in RegionFile if write potentially succeeds (#2294)

This commit is contained in:
Spottedleaf 2019-07-21 14:36:27 -07:00 committed by Zach
parent ef6823811b
commit 160d1bc9e4
2 changed files with 28 additions and 15 deletions

View File

@ -1,4 +1,4 @@
From 4bcb315529ed74e50b761d1e0a36c70a8b6dfe3b Mon Sep 17 00:00:00 2001
From 9d94490ac2671994c06c081a116d7b11d8ef4f77 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Mon, 1 Apr 2019 18:57:32 -0700
Subject: [PATCH] Make region files more reliable to write to
@ -37,7 +37,7 @@ affect save performance if the startup flag is used (especially on
HDDs).
diff --git a/src/main/java/net/minecraft/server/RegionFile.java b/src/main/java/net/minecraft/server/RegionFile.java
index ed2ccebb23..2e14d84657 100644
index ed2ccebb23..b0ec9edf67 100644
--- a/src/main/java/net/minecraft/server/RegionFile.java
+++ b/src/main/java/net/minecraft/server/RegionFile.java
@@ -29,7 +29,7 @@ public class RegionFile implements AutoCloseable {
@ -101,7 +101,7 @@ index ed2ccebb23..2e14d84657 100644
} else {
this.b.seek(this.b.length());
k = this.e.size();
@@ -259,9 +258,14 @@ public class RegionFile implements AutoCloseable {
@@ -259,22 +258,27 @@ public class RegionFile implements AutoCloseable {
this.e.add(false);
}
@ -117,8 +117,11 @@ index ed2ccebb23..2e14d84657 100644
+ // Paper end
}
this.b(chunkcoordintpair, (int) (SystemUtils.getTimeMillis() / 1000L));
@@ -271,10 +275,10 @@ public class RegionFile implements AutoCloseable {
- this.b(chunkcoordintpair, (int) (SystemUtils.getTimeMillis() / 1000L));
+ // Paper - move this into writeChunkData
} catch (IOException ioexception) {
com.destroystokyo.paper.util.SneakyThrow.sneaky(ioexception); // Paper - we want the upper try/catch to retry this
}
}
@ -131,7 +134,7 @@ index ed2ccebb23..2e14d84657 100644
this.b.write(abyte, 0, j);
}
@@ -286,12 +290,13 @@ public class RegionFile implements AutoCloseable {
@@ -286,24 +290,28 @@ public class RegionFile implements AutoCloseable {
return this.getOffset(chunkcoordintpair) != 0;
}
@ -139,23 +142,32 @@ index ed2ccebb23..2e14d84657 100644
private void a(ChunkCoordIntPair chunkcoordintpair, int i) throws IOException {
int j = this.f(chunkcoordintpair);
this.c[j] = i;
- this.c[j] = i;
+ //this.c[j] = i; // Paper - move this to after the write
this.b.seek((long) (j * 4));
- this.b.writeInt(i);
+ this.writeInt(i); // Paper - Avoid 3 io write calls
+ this.c[j] = i; // Paper - move this to after the write
}
private int f(ChunkCoordIntPair chunkcoordintpair) {
@@ -303,7 +308,7 @@ public class RegionFile implements AutoCloseable {
return chunkcoordintpair.j() + chunkcoordintpair.k() * 32;
}
this.d[j] = i;
+ private final void updateChunkTime(ChunkCoordIntPair chunkPos, final int time) throws IOException { this.b(chunkPos, time); } // Paper - OBFHELPER
private void b(ChunkCoordIntPair chunkcoordintpair, int i) throws IOException {
int j = this.f(chunkcoordintpair);
- this.d[j] = i;
+ //this.d[j] = i; // Paper - move this to after the write
this.b.seek((long) (4096 + j * 4));
- this.b.writeInt(i);
+ this.writeInt(i); // Paper - Avoid 3 io write calls
+ this.d[j] = i; // Paper - move this to after the write
}
public void close() throws IOException {
@@ -311,6 +316,40 @@ public class RegionFile implements AutoCloseable {
@@ -311,6 +319,41 @@ public class RegionFile implements AutoCloseable {
}
// Paper start
@ -189,6 +201,7 @@ index ed2ccebb23..2e14d84657 100644
+ final int chunkOffset, final byte[] chunkData, final int chunkDataLength) throws IOException {
+ this.writeChunkData(chunkOffset, chunkData, chunkDataLength);
+ this.syncRegionFile(); // Sync is required to ensure the previous data is written successfully
+ this.updateChunkTime(chunk, (int)(SystemUtils.getTimeMillis() / 1000L));
+ this.updateChunkHeader(chunk, chunkHeaderData);
+ this.syncRegionFile(); // Ensure header changes go through
+ }

View File

@ -1,4 +1,4 @@
From cc7b001a6a611ee2fe3209292296c8d50dbb173c Mon Sep 17 00:00:00 2001
From 25add0dd2435b00018bd7e90a9ffead534b7ac53 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Sat, 15 Jun 2019 08:54:33 -0700
Subject: [PATCH] Fix World#isChunkGenerated calls
@ -197,7 +197,7 @@ index 0911880c9d..86fb51b90a 100644
boolean isOutsideOfRange(ChunkCoordIntPair chunkcoordintpair) {
// Spigot start
diff --git a/src/main/java/net/minecraft/server/RegionFile.java b/src/main/java/net/minecraft/server/RegionFile.java
index 2e14d84657..66c8b0307f 100644
index b0ec9edf67..41f1e15cb0 100644
--- a/src/main/java/net/minecraft/server/RegionFile.java
+++ b/src/main/java/net/minecraft/server/RegionFile.java
@@ -31,6 +31,30 @@ public class RegionFile implements AutoCloseable {
@ -239,15 +239,15 @@ index 2e14d84657..66c8b0307f 100644
public boolean d(ChunkCoordIntPair chunkcoordintpair) {
return this.getOffset(chunkcoordintpair) != 0;
}
@@ -299,6 +324,7 @@ public class RegionFile implements AutoCloseable {
this.writeInt(i); // Paper - Avoid 3 io write calls
@@ -300,6 +325,7 @@ public class RegionFile implements AutoCloseable {
this.c[j] = i; // Paper - move this to after the write
}
+ private final int getChunkLocation(ChunkCoordIntPair chunkcoordintpair) { return this.f(chunkcoordintpair); } // Paper - OBFHELPER
private int f(ChunkCoordIntPair chunkcoordintpair) {
return chunkcoordintpair.j() + chunkcoordintpair.k() * 32;
}
@@ -312,6 +338,7 @@ public class RegionFile implements AutoCloseable {
@@ -315,6 +341,7 @@ public class RegionFile implements AutoCloseable {
}
public void close() throws IOException {