2019-04-23 06:47:07 +02:00
From a1b78729ad268fc1bb764e0432ff606abb0f7f86 Mon Sep 17 00:00:00 2001
2018-07-15 03:53:17 +02: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
2019-04-23 06:47:07 +02:00
index e4ba7146d1..06c53af2c5 100644
2018-07-15 03:53:17 +02:00
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
2018-10-19 02:44:59 +02:00
@@ -228,4 +228,9 @@ public class PaperConfig {
2018-07-15 03:53:17 +02:00
private static void loadPermsBeforePlugins() {
loadPermsBeforePlugins = getBoolean("settings.load-permissions-yml-before-plugins", true);
}
+
+ public static int regionFileCacheSize = 256;
+ private static void regionFileCacheSize() {
+ regionFileCacheSize = getInt("settings.region-file-cache-size", 256);
+ }
}
diff --git a/src/main/java/net/minecraft/server/RegionFileCache.java b/src/main/java/net/minecraft/server/RegionFileCache.java
2019-04-23 06:47:07 +02:00
index 5dbd1d517a..964996976a 100644
2018-07-15 03:53:17 +02:00
--- a/src/main/java/net/minecraft/server/RegionFileCache.java
+++ b/src/main/java/net/minecraft/server/RegionFileCache.java
@@ -9,10 +9,12 @@ import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import javax.annotation.Nullable;
+import com.destroystokyo.paper.PaperConfig; // Paper
+import java.util.LinkedHashMap; // Paper
public class RegionFileCache {
2018-12-17 06:18:06 +01:00
- public static final Map<File, RegionFile> cache = Maps.newHashMap();
+ public static final Map<File, RegionFile> cache = new LinkedHashMap(PaperConfig.regionFileCacheSize, 0.75f, true); // Paper - HashMap -> LinkedHashMap
2018-07-15 03:53:17 +02:00
public static synchronized RegionFile a(File file, int i, int j) {
File file1 = new File(file, "region");
2018-12-17 06:18:06 +01:00
@@ -27,7 +29,7 @@ public class RegionFileCache {
2018-07-15 03:53:17 +02:00
}
2018-12-17 06:18:06 +01:00
if (RegionFileCache.cache.size() >= 256) {
2018-07-15 03:53:17 +02:00
- a();
2018-12-17 06:18:06 +01:00
+ trimCache();
2018-07-15 03:53:17 +02:00
}
RegionFile regionfile1 = new RegionFile(file2);
2018-08-26 20:11:49 +02:00
@@ -60,6 +62,22 @@ public class RegionFileCache {
2018-07-15 03:53:17 +02:00
}
2018-08-26 20:11:49 +02:00
// CraftBukkit end
2018-07-15 03:53:17 +02:00
+ // Paper Start
+ private static synchronized void trimCache() {
2018-12-17 06:18:06 +01:00
+ Iterator<Map.Entry<File, RegionFile>> itr = RegionFileCache.cache.entrySet().iterator();
+ int count = RegionFileCache.cache.size() - PaperConfig.regionFileCacheSize;
2018-07-15 03:53:17 +02:00
+ while (count-- >= 0 && itr.hasNext()) {
+ try {
2018-12-17 06:18:06 +01:00
+ itr.next().getValue().close();
2018-07-15 03:53:17 +02:00
+ } catch (IOException ioexception) {
+ ioexception.printStackTrace();
+ ServerInternalException.reportInternalException(ioexception);
+ }
+ itr.remove();
+ }
+ }
+ // Paper End
+
public static synchronized void a() {
2018-12-17 06:18:06 +01:00
Iterator iterator = RegionFileCache.cache.values().iterator();
2018-07-15 03:53:17 +02:00
--
2019-04-23 06:47:07 +02:00
2.21.0
2018-07-15 03:53:17 +02:00