Paper/Spigot-Server-Patches/0087-Sanitise-RegionFileCache-and-make-configurable.patch
Shane Freeder 3496f2d7e4
Updated Upstream (Bukkit/CraftBukkit/Spigot)
Developers!: You will need to clean up your work/Minecraft/1.13.2 folder for this

Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
b850a822 SPIGOT-4526: Add conversion time API for Zombie & subclasses

CraftBukkit Changes:
38cf676e SPIGOT-4534: CreatureSpawnEvent not being called for CHUNK_GEN
b446cb5d SPIGOT-4527: Fix sponges with waterlogged blocks
6ec8ea5c SPIGOT-4526: Add conversion time API for Zombie & subclasses
c64fe508 Mappings Update
a3c2ec03 Fix missing ServerListPingEvent call for legacy pings

Spigot Changes:
1dc156ce Rebuild patches
140f654d Mappings Update
2018-12-17 05:19:39 +00:00

80 Zeilen
3.2 KiB
Diff

From f66ef986b6349909793d94ae5f6087a3eb8302c0 Mon Sep 17 00:00:00 2001
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 492df2c8e..0778f53e2 100644
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
@@ -228,4 +228,9 @@ public class PaperConfig {
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
index 5dbd1d517..964996976 100644
--- 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 {
- 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
public static synchronized RegionFile a(File file, int i, int j) {
File file1 = new File(file, "region");
@@ -27,7 +29,7 @@ public class RegionFileCache {
}
if (RegionFileCache.cache.size() >= 256) {
- a();
+ trimCache();
}
RegionFile regionfile1 = new RegionFile(file2);
@@ -60,6 +62,22 @@ public class RegionFileCache {
}
// CraftBukkit end
+ // Paper Start
+ private static synchronized void trimCache() {
+ Iterator<Map.Entry<File, RegionFile>> itr = RegionFileCache.cache.entrySet().iterator();
+ int count = RegionFileCache.cache.size() - PaperConfig.regionFileCacheSize;
+ while (count-- >= 0 && itr.hasNext()) {
+ try {
+ itr.next().getValue().close();
+ } catch (IOException ioexception) {
+ ioexception.printStackTrace();
+ ServerInternalException.reportInternalException(ioexception);
+ }
+ itr.remove();
+ }
+ }
+ // Paper End
+
public static synchronized void a() {
Iterator iterator = RegionFileCache.cache.values().iterator();
--
2.20.0