testserver/Spigot-Server-Patches/0080-Sanitise-RegionFileCac...

51 lines
2.2 KiB
Diff
Raw Normal View History

From b32630a53238ec990917332b269e5e15d870be5a Mon Sep 17 00:00:00 2001
2019-04-27 03:05:36 +00:00
From: Antony Riley <antony@cyberiantiger.org>
Date: Tue, 29 Mar 2016 08:22:55 +0300
Subject: [PATCH] Sanitise RegionFileCache and make configurable.
RegionFileCache prior to this patch would close every single open region
file upon reaching a size of 256.
This patch modifies that behaviour so it closes the the least recently
used RegionFile.
The implementation uses a LinkedHashMap as an LRU cache (modified from HashMap).
The maximum size of the RegionFileCache is also made configurable.
diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
index 6cc99ffe43..0cef1853f5 100644
2019-04-27 03:05:36 +00:00
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
@@ -218,4 +218,9 @@ public class PaperConfig {
2019-04-27 03:05:36 +00:00
private static void loadPermsBeforePlugins() {
loadPermsBeforePlugins = getBoolean("settings.load-permissions-yml-before-plugins", true);
}
+
+ public static int regionFileCacheSize = 256;
+ private static void regionFileCacheSize() {
+ regionFileCacheSize = Math.max(getInt("settings.region-file-cache-size", 256), 4);
2019-04-27 03:05:36 +00:00
+ }
}
diff --git a/src/main/java/net/minecraft/server/RegionFileCache.java b/src/main/java/net/minecraft/server/RegionFileCache.java
2019-05-27 23:01:45 +00:00
index 1ea9e5bb43..21b3b06f53 100644
2019-04-27 03:05:36 +00:00
--- a/src/main/java/net/minecraft/server/RegionFileCache.java
+++ b/src/main/java/net/minecraft/server/RegionFileCache.java
@@ -8,6 +8,7 @@ import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import javax.annotation.Nullable;
+import com.destroystokyo.paper.PaperConfig; // Paper
public abstract class RegionFileCache implements AutoCloseable {
@@ -25,7 +26,7 @@ public abstract class RegionFileCache implements AutoCloseable {
if (regionfile != null) {
return regionfile;
} else {
- if (this.cache.size() >= 256) {
2019-05-27 23:01:45 +00:00
+ if (this.cache.size() >= PaperConfig.regionFileCacheSize) { // Paper - configurable
((RegionFile) this.cache.removeLast()).close();
2019-04-27 03:05:36 +00:00
}
--
2.21.0