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
parent 6b80069cbe
commit 61b8600730
2 changed files with 21 additions and 8 deletions

View file

@ -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
@@ -0,0 +0,0 @@ public class RegionFile implements AutoCloseable {
@ -240,7 +240,7 @@ index 2e14d84657..66c8b0307f 100644
return this.getOffset(chunkcoordintpair) != 0;
}
@@ -0,0 +0,0 @@ public class RegionFile implements AutoCloseable {
this.writeInt(i); // Paper - Avoid 3 io write calls
this.c[j] = i; // Paper - move this to after the write
}
+ private final int getChunkLocation(ChunkCoordIntPair chunkcoordintpair) { return this.f(chunkcoordintpair); } // Paper - OBFHELPER

View file

@ -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
@@ -0,0 +0,0 @@ public class RegionFile implements AutoCloseable {
@ -117,8 +117,11 @@ index ed2ccebb23..2e14d84657 100644
+ // Paper end
}
this.b(chunkcoordintpair, (int) (SystemUtils.getTimeMillis() / 1000L));
@@ -0,0 +0,0 @@ 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
}
}
@ -139,19 +142,28 @@ 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) {
@@ -0,0 +0,0 @@ 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 {
@ -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
+ }