2017-04-22 08:16:45 +02:00
From 61c14766f4cf6eb0ac45cfcd60aae9fdcba217e8 Mon Sep 17 00:00:00 2001
2016-03-29 07:27:14 +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
2017-04-22 08:16:45 +02:00
index 6907d4680..c3ff47e00 100644
2016-03-29 07:27:14 +02:00
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
2017-04-22 08:16:45 +02:00
@@ -220,4 +220,9 @@ public class PaperConfig {
2016-06-05 00:26:11 +02:00
private static void healthDeath() {
2016-03-29 07:27:14 +02:00
setHealthBeforeDeathEvent = getBoolean("settings.set-health-before-death-event", false);
}
+
+ 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
2017-03-25 04:18:58 +01:00
index 19fbf9b4a..ad00c39ce 100644
2016-03-29 07:27:14 +02:00
--- a/src/main/java/net/minecraft/server/RegionFileCache.java
+++ b/src/main/java/net/minecraft/server/RegionFileCache.java
@@ -8,10 +8,12 @@ import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
+import com.destroystokyo.paper.PaperConfig; // Paper
+import java.util.LinkedHashMap; // Paper
public class RegionFileCache {
- public static final Map<File, RegionFile> a = Maps.newHashMap(); // Spigot - private -> public
+ public static final Map<File, RegionFile> a = new LinkedHashMap(PaperConfig.regionFileCacheSize, 0.75f, true); // Spigot - private -> public, Paper - HashMap -> LinkedHashMap
// Paper start
public static synchronized RegionFile a(File file, int i, int j) {
@@ -32,8 +34,8 @@ public class RegionFileCache {
file1.mkdirs();
}
- if (RegionFileCache.a.size() >= 256) {
- a();
+ if (RegionFileCache.a.size() >= PaperConfig.regionFileCacheSize) { // Paper
+ trimCache(); // Paper
}
RegionFile regionfile1 = new RegionFile(file2);
2016-11-17 03:23:38 +01:00
@@ -64,6 +66,22 @@ public class RegionFileCache {
2016-03-29 07:27:14 +02:00
}
}
+ // Paper Start
+ private static synchronized void trimCache() {
+ Iterator<Map.Entry<File, RegionFile>> itr = RegionFileCache.a.entrySet().iterator();
+ int count = RegionFileCache.a.size() - PaperConfig.regionFileCacheSize;
+ while (count-- >= 0 && itr.hasNext()) {
+ try {
+ itr.next().getValue().c();
+ } catch (IOException ioexception) {
+ ioexception.printStackTrace();
+ ServerInternalException.reportInternalException(ioexception);
+ }
+ itr.remove();
+ }
+ }
+ // Paper End
+
public static synchronized void a() {
Iterator iterator = RegionFileCache.a.values().iterator();
--
2017-04-22 08:16:45 +02:00
2.12.2
2016-03-29 07:27:14 +02:00