Skip to content

Commit

Permalink
More patches
Browse files Browse the repository at this point in the history
  • Loading branch information
AltronMaxX committed Aug 26, 2024
1 parent a651f03 commit fa2b9f1
Show file tree
Hide file tree
Showing 10 changed files with 513 additions and 54 deletions.
10 changes: 5 additions & 5 deletions patches/server/0027-Purpur-Remove-timings.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ index 9a9be6f618c361db39eff0f0397bbc21615da411..cdc46735be4fcb4d992dfb2d7e662a45

}
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index 9741cad817e5bb0d8efc134f7fdb9f6142891425..c5c821344d1fc97642d4445b7825c67b46d51176 100644
index c5a1ad1745cba96dea915b6ecacab0123fe976b7..a0b845df54dc7d6e5232a2d669909244140f5fa4 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -1,6 +1,5 @@
Expand All @@ -1373,7 +1373,7 @@ index 9741cad817e5bb0d8efc134f7fdb9f6142891425..c5c821344d1fc97642d4445b7825c67b
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
@@ -1293,7 +1292,7 @@ public abstract class PlayerList {
@@ -1296,7 +1295,7 @@ public abstract class PlayerList {
public void saveAll(int interval) {
io.papermc.paper.util.MCUtil.ensureMain("Save Players" , () -> { // Paper - Ensure main
final ca.spottedleaf.leafprofiler.RegionizedProfiler.Handle profiler = io.papermc.paper.threadedregions.TickRegionScheduler.getProfiler(); // Folia - profiler
Expand All @@ -1382,7 +1382,7 @@ index 9741cad817e5bb0d8efc134f7fdb9f6142891425..c5c821344d1fc97642d4445b7825c67b
int numSaved = 0;
long now = System.nanoTime(); // Folia - region threading
int max = io.papermc.paper.configuration.GlobalConfiguration.get().playerAutoSave.maxPerTick(); // Folia - region threading
@@ -1315,7 +1314,7 @@ public abstract class PlayerList {
@@ -1318,7 +1317,7 @@ public abstract class PlayerList {
}
// Paper end - Incremental chunk and player saving
}
Expand Down Expand Up @@ -1585,10 +1585,10 @@ index dd02f20e965e6e4aaaf5992ea3c4bb0b7f3cc270..f6d94cde5b20c6a25e73a0f739e564b3
}

diff --git a/src/main/java/net/minecraft/world/level/block/Block.java b/src/main/java/net/minecraft/world/level/block/Block.java
index bf9d00463627c702c639c7cb625c3eb35c2e44aa..70157d581f8cbe60f86f944e7c2b0ce9c722959a 100644
index 64759367cb0dd7401d7a12517a7448d3cbca1a82..b53220534033da5bc8324ebaff4dfa8f229b3fff 100644
--- a/src/main/java/net/minecraft/world/level/block/Block.java
+++ b/src/main/java/net/minecraft/world/level/block/Block.java
@@ -103,13 +103,6 @@ public class Block extends BlockBehaviour implements ItemLike {
@@ -102,13 +102,6 @@ public class Block extends BlockBehaviour implements ItemLike {
this != Blocks.STRUCTURE_BLOCK &&
this != Blocks.JIGSAW;
}
Expand Down
135 changes: 97 additions & 38 deletions patches/server/0038-Add-linear-format-from-LinearPurpur.patch
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ index 3218cbf84f54daf06e84442d5eb1a36d8da6b215..ec9b27177dc526510e86d85f48f167b4
synchronized (cache) {
regionFile = ((ChunkSystemRegionFileStorage)(Object)cache).moonrise$getRegionFileIfLoaded(chunkX, chunkZ);
diff --git a/src/main/java/net/edenor/foldenor/config/FoldenorConfig.java b/src/main/java/net/edenor/foldenor/config/FoldenorConfig.java
index f57a71b1182b3b8e03d3f42ecc6e1b55cb93b788..d4f616a4580e2fc29f9f34b7bbcbf27eecaa27ab 100644
index f57a71b1182b3b8e03d3f42ecc6e1b55cb93b788..db2c92e8fd7d811639f3fb0bb7cff675366b8a10 100644
--- a/src/main/java/net/edenor/foldenor/config/FoldenorConfig.java
+++ b/src/main/java/net/edenor/foldenor/config/FoldenorConfig.java
@@ -2,6 +2,7 @@ package net.edenor.foldenor.config;
Expand Down Expand Up @@ -96,7 +96,7 @@ index f57a71b1182b3b8e03d3f42ecc6e1b55cb93b788..d4f616a4580e2fc29f9f34b7bbcbf27e

public static int version;
static boolean verbose;
@@ -47,6 +52,12 @@ public class FoldenorConfig {
@@ -47,6 +52,13 @@ public class FoldenorConfig {

public static boolean skipMapItemUpdatesIfNoBukkitRender = true;

Expand All @@ -105,11 +105,12 @@ index f57a71b1182b3b8e03d3f42ecc6e1b55cb93b788..d4f616a4580e2fc29f9f34b7bbcbf27e
+ public static boolean throwOnUnknownExtension = false;
+ public static int linearFlushFrequency = 5;
+ public static EnumRegionFileExtension regionFormatType;
+ public static int linearFlushThreads = 1;
+
public static void init(File configFile) {
init(configFile, true);
}
@@ -93,6 +104,8 @@ public class FoldenorConfig {
@@ -93,6 +105,8 @@ public class FoldenorConfig {

readMiscSettings();

Expand All @@ -118,7 +119,7 @@ index f57a71b1182b3b8e03d3f42ecc6e1b55cb93b788..d4f616a4580e2fc29f9f34b7bbcbf27e
try {
readDynamicActivationOfBrains();
} catch (IOException e) {
@@ -123,6 +136,25 @@ public class FoldenorConfig {
@@ -123,6 +137,31 @@ public class FoldenorConfig {
"Use the new Virtual Thread introduced in JDK 21 for CraftAsyncScheduler.");
}

Expand All @@ -127,6 +128,12 @@ index f57a71b1182b3b8e03d3f42ecc6e1b55cb93b788..d4f616a4580e2fc29f9f34b7bbcbf27e
+ throwOnUnknownExtension = getBoolean("region-format.throw-on-unknown-extension", throwOnUnknownExtension);
+ linearCompressionLevel = getInt("region-format.linear.compression-level", linearCompressionLevel);
+ linearFlushFrequency = getInt("region-format.linear.flush-frequency", linearFlushFrequency);
+ linearFlushThreads = getInt("region-format.linear.flush-max-threads", linearFlushThreads);
+
+ if (linearFlushThreads < 0)
+ linearFlushThreads = Math.max(Runtime.getRuntime().availableProcessors() + linearFlushThreads, 1);
+ else
+ linearFlushThreads = Math.max(linearFlushThreads, 1);
+
+ regionFormatType = EnumRegionFileExtension.fromName(regionFormatTypeName);
+ if (regionFormatType == EnumRegionFileExtension.UNKNOWN) {
Expand Down Expand Up @@ -569,10 +576,10 @@ index 0000000000000000000000000000000000000000..087734ea2186c6ee14069b27b09067ce
+}
diff --git a/src/main/java/org/stupidcraft/linearpaper/region/LinearRegionFile.java b/src/main/java/org/stupidcraft/linearpaper/region/LinearRegionFile.java
new file mode 100644
index 0000000000000000000000000000000000000000..b172452cd6664a28cdb38b535018f2f70fe4d99c
index 0000000000000000000000000000000000000000..947eebd163d2679a8572f7d91966ccaa0af12dfd
--- /dev/null
+++ b/src/main/java/org/stupidcraft/linearpaper/region/LinearRegionFile.java
@@ -0,0 +1,310 @@
@@ -0,0 +1,306 @@
+package org.stupidcraft.linearpaper.region;
+
+import com.github.luben.zstd.ZstdInputStream;
Expand All @@ -596,7 +603,7 @@ index 0000000000000000000000000000000000000000..b172452cd6664a28cdb38b535018f2f7
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import javax.annotation.Nullable;
+
+import net.jpountz.lz4.LZ4Compressor;
Expand All @@ -607,21 +614,24 @@ index 0000000000000000000000000000000000000000..b172452cd6664a28cdb38b535018f2f7
+import org.slf4j.Logger;
+
+public class LinearRegionFile implements IRegionFile, AutoCloseable {
+
+ private static final long SUPERBLOCK = -4323716122432332390L;
+ private static final byte VERSION = 2;
+ private static final int HEADER_SIZE = 32;
+ private static final int FOOTER_SIZE = 8;
+ private static final Logger LOGGER = LogUtils.getLogger();
+ private static final List<Byte> SUPPORTED_VERSIONS = Arrays.asList((byte) 1, (byte) 2);
+ private static final LinearRegionFileFlusher linearRegionFileFlusher = new LinearRegionFileFlusher();
+ private final byte[][] buffer = new byte[1024][];
+ private final int[] bufferUncompressedSize = new int[1024];
+ private final int[] chunkTimestamps = new int[1024];
+ private final LZ4Compressor compressor;
+ private final LZ4FastDecompressor decompressor;
+ private final int compressionLevel;
+ private final AtomicBoolean markedToSave = new AtomicBoolean(false);
+ public boolean closed = false;
+ public Path path;
+ private volatile long lastFlushed = System.nanoTime();
+
+
+ public LinearRegionFile(Path file, int compression) throws IOException {
+ this.path = file;
Expand Down Expand Up @@ -699,8 +709,21 @@ index 0000000000000000000000000000000000000000..b172452cd6664a28cdb38b535018f2f7
+ return (int) (System.currentTimeMillis() / 1000L);
+ }
+
+ public Path getPath() {
+ return this.path;
+ }
+
+ public void flush() throws IOException {
+ flushWrapper(); // sync
+ if (isMarkedToSave()) flushWrapper(); // sync
+ }
+
+ private void markToSave() {
+ linearRegionFileFlusher.scheduleSave(this);
+ markedToSave.set(true);
+ }
+
+ public boolean isMarkedToSave() {
+ return markedToSave.getAndSet(false);
+ }
+
+ public void flushWrapper() {
Expand All @@ -711,8 +734,8 @@ index 0000000000000000000000000000000000000000..b172452cd6664a28cdb38b535018f2f7
+ }
+ }
+
+ public boolean doesChunkExist(ChunkPos pos) throws Exception {
+ throw new Exception("doesChunkExist is a stub");
+ public boolean doesChunkExist(ChunkPos pos) {
+ return false;
+ }
+
+ private synchronized void save() throws IOException {
Expand Down Expand Up @@ -767,13 +790,6 @@ index 0000000000000000000000000000000000000000..b172452cd6664a28cdb38b535018f2f7
+ fileStream.getChannel().force(true); // Ensure atomicity on Btrfs
+ }
+ Files.move(tempFile.toPath(), this.path, StandardCopyOption.REPLACE_EXISTING);
+ this.lastFlushed = System.nanoTime();
+ }
+
+ private void checkAndSave() {
+ if ((System.nanoTime() - this.lastFlushed) >= TimeUnit.NANOSECONDS.toSeconds(net.edenor.foldenor.config.FoldenorConfig.linearFlushFrequency)) {
+ this.flushWrapper();
+ }
+ }
+
+ public synchronized void write(ChunkPos pos, ByteBuffer buffer) {
Expand All @@ -794,16 +810,11 @@ index 0000000000000000000000000000000000000000..b172452cd6664a28cdb38b535018f2f7
+ } catch (IOException e) {
+ LOGGER.error("Chunk write IOException {} {}", e, this.path);
+ }
+
+ this.checkAndSave();
+ markToSave();
+ }
+
+ public DataOutputStream getChunkDataOutputStream(ChunkPos pos) {
+ try {
+ return new DataOutputStream(new BufferedOutputStream(new ChunkBuffer(pos)));
+ } finally {
+ this.checkAndSave();
+ }
+ return new DataOutputStream(new BufferedOutputStream(new ChunkBuffer(pos)));
+ }
+
+ private byte[] toByteArray(InputStream in) throws IOException {
Expand All @@ -820,14 +831,10 @@ index 0000000000000000000000000000000000000000..b172452cd6664a28cdb38b535018f2f7
+
+ @Nullable
+ public synchronized DataInputStream getChunkDataInputStream(ChunkPos pos) {
+ try {
+ if (this.bufferUncompressedSize[getChunkIndex(pos.x, pos.z)] != 0) {
+ byte[] content = new byte[bufferUncompressedSize[getChunkIndex(pos.x, pos.z)]];
+ this.decompressor.decompress(this.buffer[getChunkIndex(pos.x, pos.z)], 0, content, 0, bufferUncompressedSize[getChunkIndex(pos.x, pos.z)]);
+ return new DataInputStream(new ByteArrayInputStream(content));
+ }
+ } finally {
+ this.checkAndSave();
+ if (this.bufferUncompressedSize[getChunkIndex(pos.x, pos.z)] != 0) {
+ byte[] content = new byte[bufferUncompressedSize[getChunkIndex(pos.x, pos.z)]];
+ this.decompressor.decompress(this.buffer[getChunkIndex(pos.x, pos.z)], 0, content, 0, bufferUncompressedSize[getChunkIndex(pos.x, pos.z)]);
+ return new DataInputStream(new ByteArrayInputStream(content));
+ }
+ return null;
+ }
Expand All @@ -837,11 +844,7 @@ index 0000000000000000000000000000000000000000..b172452cd6664a28cdb38b535018f2f7
+ this.buffer[i] = null;
+ this.bufferUncompressedSize[i] = 0;
+ this.chunkTimestamps[i] = getTimestamp();
+ this.flushWrapper();
+ }
+
+ public Path getPath() {
+ return this.path;
+ markToSave();
+ }
+
+ public boolean hasChunk(ChunkPos pos) {
Expand Down Expand Up @@ -883,3 +886,59 @@ index 0000000000000000000000000000000000000000..b172452cd6664a28cdb38b535018f2f7
+ }
+ }
+}
diff --git a/src/main/java/org/stupidcraft/linearpaper/region/LinearRegionFileFlusher.java b/src/main/java/org/stupidcraft/linearpaper/region/LinearRegionFileFlusher.java
new file mode 100644
index 0000000000000000000000000000000000000000..b7431e26c27a3af641e0889cbd370e622eba258a
--- /dev/null
+++ b/src/main/java/org/stupidcraft/linearpaper/region/LinearRegionFileFlusher.java
@@ -0,0 +1,50 @@
+package org.stupidcraft.linearpaper.region;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import net.edenor.foldenor.config.FoldenorConfig;
+import org.bukkit.Bukkit;
+
+import java.util.Queue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.LinkedBlockingQueue;
+
+public class LinearRegionFileFlusher {
+ private final Queue<LinearRegionFile> savingQueue = new LinkedBlockingQueue<>();
+ private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(
+ new ThreadFactoryBuilder()
+ .setNameFormat("linear-flush-scheduler")
+ .build()
+ );
+ private final ExecutorService executor = Executors.newFixedThreadPool(
+ FoldenorConfig.linearFlushThreads,
+ new ThreadFactoryBuilder()
+ .setNameFormat("linear-flusher-%d")
+ .build()
+ );
+
+ public LinearRegionFileFlusher() {
+ Bukkit.getLogger().info("Using " + FoldenorConfig.linearFlushThreads + " threads for linear region flushing.");
+ scheduler.scheduleAtFixedRate(this::pollAndFlush, 0L, FoldenorConfig.linearFlushFrequency, TimeUnit.SECONDS);
+ }
+
+ public void scheduleSave(LinearRegionFile regionFile) {
+ if (savingQueue.contains(regionFile)) return;
+ savingQueue.add(regionFile);
+ }
+
+ private void pollAndFlush() {
+ while (!savingQueue.isEmpty()) {
+ LinearRegionFile regionFile = savingQueue.poll();
+ if (!regionFile.closed && regionFile.isMarkedToSave())
+ executor.execute(regionFile::flushWrapper);
+ }
+ }
+
+ public void shutdown() {
+ executor.shutdown();
+ scheduler.shutdown();
+ }
+}
6 changes: 3 additions & 3 deletions patches/server/0040-Pufferfish-Entity-TTL.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subject: [PATCH] Pufferfish Entity TTL


diff --git a/src/main/java/net/edenor/foldenor/config/FoldenorConfig.java b/src/main/java/net/edenor/foldenor/config/FoldenorConfig.java
index d4f616a4580e2fc29f9f34b7bbcbf27eecaa27ab..49c5684edf5f605ba862599b0afcb48d8d0bebaa 100644
index db2c92e8fd7d811639f3fb0bb7cff675366b8a10..448c311508b57978a76713da538580cf4beba9dc 100644
--- a/src/main/java/net/edenor/foldenor/config/FoldenorConfig.java
+++ b/src/main/java/net/edenor/foldenor/config/FoldenorConfig.java
@@ -20,6 +20,7 @@ import java.lang.reflect.Method;
Expand All @@ -16,7 +16,7 @@ index d4f616a4580e2fc29f9f34b7bbcbf27eecaa27ab..49c5684edf5f605ba862599b0afcb48d
import java.util.Map;
import java.util.logging.Level;

@@ -106,6 +107,8 @@ public class FoldenorConfig {
@@ -107,6 +108,8 @@ public class FoldenorConfig {

readRegionFormatSettings();

Expand All @@ -25,7 +25,7 @@ index d4f616a4580e2fc29f9f34b7bbcbf27eecaa27ab..49c5684edf5f605ba862599b0afcb48d
try {
readDynamicActivationOfBrains();
} catch (IOException e) {
@@ -179,6 +182,22 @@ public class FoldenorConfig {
@@ -186,6 +189,22 @@ public class FoldenorConfig {
}, () -> MinecraftServer.LOGGER.warn("Unknown entity \"" + name + "\"")));
}

Expand Down
8 changes: 4 additions & 4 deletions patches/server/0041-Lumina-PCA-sync-protocol.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Lumina PCA-sync-protocol


diff --git a/src/main/java/net/edenor/foldenor/config/FoldenorConfig.java b/src/main/java/net/edenor/foldenor/config/FoldenorConfig.java
index 49c5684edf5f605ba862599b0afcb48d8d0bebaa..e3ef04b52ed1c0dfb9e40cc2daedc0659f761fb7 100644
index 448c311508b57978a76713da538580cf4beba9dc..197954520907e99b7523b3543612bad751d9e969 100644
--- a/src/main/java/net/edenor/foldenor/config/FoldenorConfig.java
+++ b/src/main/java/net/edenor/foldenor/config/FoldenorConfig.java
@@ -109,6 +109,8 @@ public class FoldenorConfig {
@@ -110,6 +110,8 @@ public class FoldenorConfig {

projectileTimeouts();

Expand All @@ -17,7 +17,7 @@ index 49c5684edf5f605ba862599b0afcb48d8d0bebaa..e3ef04b52ed1c0dfb9e40cc2daedc065
try {
readDynamicActivationOfBrains();
} catch (IOException e) {
@@ -198,6 +200,21 @@ public class FoldenorConfig {
@@ -205,6 +207,21 @@ public class FoldenorConfig {
}
}

Expand Down Expand Up @@ -271,7 +271,7 @@ index 431fb6a658c6aac43b6f9dbd1f578b83f261a4e3..75df0fc2eb581b36713001f1f43912ff
protected Component getDefaultName() {
return Component.translatable("container.dispenser");
diff --git a/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java
index 09410e95ebb0fd0089c924f39914287465a453bd..6088e4abdb353328d06852b71089c358abd1398e 100644
index 1035a68aaeb9c50752a03cd72fe65c5eb7e8746c..1aab9e49b8046f926f7c6e0d7d535f2382d711fa 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java
@@ -144,6 +144,16 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ Subject: [PATCH] ShreddedPaper: Optimization:


diff --git a/src/main/java/net/edenor/foldenor/config/FoldenorConfig.java b/src/main/java/net/edenor/foldenor/config/FoldenorConfig.java
index e3ef04b52ed1c0dfb9e40cc2daedc0659f761fb7..418a3e07512b81c1fb6b6f8f2b1478cd033f05ff 100644
index 197954520907e99b7523b3543612bad751d9e969..4d2f828ef93673cf24d038d4645838bba194f887 100644
--- a/src/main/java/net/edenor/foldenor/config/FoldenorConfig.java
+++ b/src/main/java/net/edenor/foldenor/config/FoldenorConfig.java
@@ -59,6 +59,8 @@ public class FoldenorConfig {
public static int linearFlushFrequency = 5;
@@ -60,6 +60,8 @@ public class FoldenorConfig {
public static EnumRegionFileExtension regionFormatType;
public static int linearFlushThreads = 1;

+ public static int entityActivationCheckFrequency = 20;
+
public static void init(File configFile) {
init(configFile, true);
}
@@ -134,6 +136,7 @@ public class FoldenorConfig {
@@ -135,6 +137,7 @@ public class FoldenorConfig {
piglinSpawnChancePersentInPortal = getInt("optimizations.piglin-spawn-chance-persent-in-portal", 100,
"Reduces piglin spawn in portal, by reducing change to spawn");
skipMapItemUpdatesIfNoBukkitRender = getBoolean("optimizations.skip_map_item_updates_if_no_bukkit_render", skipMapItemUpdatesIfNoBukkitRender);
Expand Down
Loading

0 comments on commit fa2b9f1

Please sign in to comment.