Fix concurrency issue in light engine (Vanilla bug)

Mojang implemented a cache like chunks have, but this cache
is accessed by multiple threads and is totally not safe.

So just remove it

Fixes #3466

Also missed a pooled nibble release, so slid that in there too.
This commit is contained in:
Aikar 2020-05-28 16:59:38 -04:00
parent db127b6f9c
commit 6bff219f15
2 changed files with 35 additions and 3 deletions

View File

@ -57,7 +57,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
public void a(long i) {
if (this.isVisible) { throw new IllegalStateException("writing to visible data"); } // Paper - avoid copying light data
- this.data.queueUpdate(i, ((NibbleArray) this.data.getUpdating(i)).b()); // Paper - avoid copying light data
+ this.data.queueUpdate(i, new NibbleArray().markPoolSafe(this.data.getUpdating(i).getCloneIfSet())); // Paper - avoid copying light data - pool safe clone
+ NibbleArray updating = this.data.getUpdating(i); // Paper - pool nibbles
+ this.data.queueUpdate(i, new NibbleArray().markPoolSafe(updating.getCloneIfSet())); // Paper - avoid copying light data - pool safe clone
+ if (updating.cleaner != null) updating.cleaner.run(); // Paper
this.c();
}

View File

@ -103,16 +103,36 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
@Nullable
@@ -0,0 +0,0 @@ public abstract class LightEngineStorageArray<M extends LightEngineStorageArray<
public NibbleArray c(long i) {
+ // Paper start - remove cache - not thread safe
+ /*
if (this.d) {
for (int j = 0; j < 2; ++j) {
if (i == this.b[j]) {
return this.c[j];
}
}
}
- }
+ }*/
+ // Paper end
- NibbleArray nibblearray = (NibbleArray) this.a.get(i);
+ NibbleArray nibblearray = (NibbleArray) (this.isVisible ? this.data.getVisibleAsync(i) : this.data.getUpdating(i)); // Paper - avoid copying light data
+ // Paper start - remove cache - not thread safe
+ return nibblearray;
+ /*
if (nibblearray == null) {
return null;
} else {
@@ -0,0 +0,0 @@ public abstract class LightEngineStorageArray<M extends LightEngineStorageArray<
}
return nibblearray;
- }
+ }*/
+ // Paper end
}
@Nullable
public NibbleArray d(long i) {
@ -128,6 +148,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
public void c() {
+ /* // Paper - remove cache
for (int i = 0; i < 2; ++i) {
this.b[i] = Long.MAX_VALUE;
this.c[i] = null;
}
-
+ */
}
public void d() {
diff --git a/src/main/java/net/minecraft/server/LightEngineStorageBlock.java b/src/main/java/net/minecraft/server/LightEngineStorageBlock.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/LightEngineStorageBlock.java