mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-05 10:20:53 +01:00
31699ae9a8
* Updated Upstream (Bukkit/CraftBukkit) Upstream has released updates that appear 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: a6a9d2a4 Remove some old ApiStatus.Experimental annotations be72314c SPIGOT-7300, PR-829: Add new DamageSource API providing enhanced information about entity damage b252cf05 SPIGOT-7576, PR-970: Add methods in MushroomCow to change stew effects b1c689bd PR-902: Add Server#isLoggingIPs to get log-ips configuration 08f86d1c PR-971: Add Player methods for client-side potion effects 2e3024a9 PR-963: Add API for in-world structures a23292a7 SPIGOT-7530, PR-948: Improve Resource Pack API with new 1.20.3 functionality 1851857b SPIGOT-3071, PR-969: Add entity spawn method with spawn reason cde4c52a SPIGOT-5553, PR-964: Add EntityKnockbackEvent CraftBukkit Changes: 38fd4bd50 Fix accidentally renamed internal damage method 80f0ce4be SPIGOT-7300, PR-1180: Add new DamageSource API providing enhanced information about entity damage 7e43f3b16 SPIGOT-7581: Fix typo in BlockMushroom ea14b7d90 SPIGOT-7576, PR-1347: Add methods in MushroomCow to change stew effects 4c687f243 PR-1259: Add Server#isLoggingIPs to get log-ips configuration 22a541a29 Improve support for per-world game rules cb7dccce2 PR-1348: Add Player methods for client-side potion effects b8d6109f0 PR-1335: Add API for in-world structures 4398a1b5b SPIGOT-7577: Make CraftWindCharge#explode discard the entity e74107678 Fix Crafter maximum stack size 0bb0f4f6a SPIGOT-7530, PR-1314: Improve Resource Pack API with new 1.20.3 functionality 4949f556d SPIGOT-3071, PR-1345: Add entity spawn method with spawn reason 20ac73ca2 PR-1353: Fix Structure#place not working as documented with 0 palette 3c1b77871 SPIGOT-6911, PR-1349: Change max book length in CraftMetaBook 333701839 SPIGOT-7572: Bee nests generated without bees f48f4174c SPIGOT-5553, PR-1336: Add EntityKnockbackEvent
127 lines
6.5 KiB
Diff
127 lines
6.5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
|
|
Date: Sat, 11 Jul 2020 05:09:28 -0700
|
|
Subject: [PATCH] Fix GameProfileCache concurrency
|
|
|
|
Separate lookup and state access locks prevent lookups
|
|
from stalling simple state access/write calls
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/players/GameProfileCache.java b/src/main/java/net/minecraft/server/players/GameProfileCache.java
|
|
index 1ec0f3a7148c2f412421772f6e1dff0bb92a51bc..d45fe762941dd6da45c890706bc9e4c0438522c3 100644
|
|
--- a/src/main/java/net/minecraft/server/players/GameProfileCache.java
|
|
+++ b/src/main/java/net/minecraft/server/players/GameProfileCache.java
|
|
@@ -60,6 +60,11 @@ public class GameProfileCache {
|
|
@Nullable
|
|
private Executor executor;
|
|
|
|
+ // Paper start - Fix GameProfileCache concurrency
|
|
+ protected final java.util.concurrent.locks.ReentrantLock stateLock = new java.util.concurrent.locks.ReentrantLock();
|
|
+ protected final java.util.concurrent.locks.ReentrantLock lookupLock = new java.util.concurrent.locks.ReentrantLock();
|
|
+ // Paper end - Fix GameProfileCache concurrency
|
|
+
|
|
public GameProfileCache(GameProfileRepository profileRepository, File cacheFile) {
|
|
this.profileRepository = profileRepository;
|
|
this.file = cacheFile;
|
|
@@ -67,11 +72,13 @@ public class GameProfileCache {
|
|
}
|
|
|
|
private void safeAdd(GameProfileCache.GameProfileInfo entry) {
|
|
+ try { this.stateLock.lock(); // Paper - Fix GameProfileCache concurrency
|
|
GameProfile gameprofile = entry.getProfile();
|
|
|
|
entry.setLastAccess(this.getNextOperation());
|
|
this.profilesByName.put(gameprofile.getName().toLowerCase(Locale.ROOT), entry);
|
|
this.profilesByUUID.put(gameprofile.getId(), entry);
|
|
+ } finally { this.stateLock.unlock(); } // Paper - Fix GameProfileCache concurrency
|
|
}
|
|
|
|
private static Optional<GameProfile> lookupGameProfile(GameProfileRepository repository, String name) {
|
|
@@ -128,17 +135,20 @@ public class GameProfileCache {
|
|
|
|
// Paper start
|
|
public @Nullable GameProfile getProfileIfCached(String name) {
|
|
+ try { this.stateLock.lock(); // Paper - Fix GameProfileCache concurrency
|
|
GameProfileCache.GameProfileInfo entry = this.profilesByName.get(name.toLowerCase(Locale.ROOT));
|
|
if (entry == null) {
|
|
return null;
|
|
}
|
|
entry.setLastAccess(this.getNextOperation());
|
|
return entry.getProfile();
|
|
+ } finally { this.stateLock.unlock(); } // Paper - Fix GameProfileCache concurrency
|
|
}
|
|
// Paper end
|
|
|
|
public Optional<GameProfile> get(String name) {
|
|
String s1 = name.toLowerCase(Locale.ROOT);
|
|
+ boolean stateLocked = true; try { this.stateLock.lock(); // Paper - Fix GameProfileCache concurrency
|
|
GameProfileCache.GameProfileInfo usercache_usercacheentry = (GameProfileCache.GameProfileInfo) this.profilesByName.get(s1);
|
|
boolean flag = false;
|
|
|
|
@@ -154,8 +164,12 @@ public class GameProfileCache {
|
|
if (usercache_usercacheentry != null) {
|
|
usercache_usercacheentry.setLastAccess(this.getNextOperation());
|
|
optional = Optional.of(usercache_usercacheentry.getProfile());
|
|
+ stateLocked = false; this.stateLock.unlock(); // Paper - Fix GameProfileCache concurrency
|
|
} else {
|
|
+ stateLocked = false; this.stateLock.unlock(); // Paper - Fix GameProfileCache concurrency
|
|
+ try { this.lookupLock.lock(); // Paper - Fix GameProfileCache concurrency
|
|
optional = GameProfileCache.lookupGameProfile(this.profileRepository, name); // CraftBukkit - use correct case for offline players
|
|
+ } finally { this.lookupLock.unlock(); } // Paper - Fix GameProfileCache concurrency
|
|
if (optional.isPresent()) {
|
|
this.add((GameProfile) optional.get());
|
|
flag = false;
|
|
@@ -167,6 +181,7 @@ public class GameProfileCache {
|
|
}
|
|
|
|
return optional;
|
|
+ } finally { if (stateLocked) { this.stateLock.unlock(); } } // Paper - Fix GameProfileCache concurrency
|
|
}
|
|
|
|
public CompletableFuture<Optional<GameProfile>> getAsync(String username) {
|
|
@@ -191,6 +206,7 @@ public class GameProfileCache {
|
|
}
|
|
|
|
public Optional<GameProfile> get(UUID uuid) {
|
|
+ try { this.stateLock.lock(); // Paper - Fix GameProfileCache concurrency
|
|
GameProfileCache.GameProfileInfo usercache_usercacheentry = (GameProfileCache.GameProfileInfo) this.profilesByUUID.get(uuid);
|
|
|
|
if (usercache_usercacheentry == null) {
|
|
@@ -199,6 +215,7 @@ public class GameProfileCache {
|
|
usercache_usercacheentry.setLastAccess(this.getNextOperation());
|
|
return Optional.of(usercache_usercacheentry.getProfile());
|
|
}
|
|
+ } finally { this.stateLock.unlock(); } // Paper - Fix GameProfileCache concurrency
|
|
}
|
|
|
|
public void setExecutor(Executor executor) {
|
|
@@ -279,7 +296,7 @@ public class GameProfileCache {
|
|
JsonArray jsonarray = new JsonArray();
|
|
DateFormat dateformat = GameProfileCache.createDateFormat();
|
|
|
|
- this.getTopMRUProfiles(org.spigotmc.SpigotConfig.userCacheCap).forEach((usercache_usercacheentry) -> { // Spigot
|
|
+ this.listTopMRUProfiles(org.spigotmc.SpigotConfig.userCacheCap).forEach((usercache_usercacheentry) -> { // Spigot // Paper - Fix GameProfileCache concurrency
|
|
jsonarray.add(GameProfileCache.writeGameProfile(usercache_usercacheentry, dateformat));
|
|
});
|
|
String s = this.gson.toJson(jsonarray);
|
|
@@ -320,8 +337,19 @@ public class GameProfileCache {
|
|
}
|
|
|
|
private Stream<GameProfileCache.GameProfileInfo> getTopMRUProfiles(int limit) {
|
|
- return ImmutableList.copyOf(this.profilesByUUID.values()).stream().sorted(Comparator.comparing(GameProfileCache.GameProfileInfo::getLastAccess).reversed()).limit((long) limit);
|
|
+ // Paper start - Fix GameProfileCache concurrency
|
|
+ return this.listTopMRUProfiles(limit).stream();
|
|
+ }
|
|
+
|
|
+ private List<GameProfileCache.GameProfileInfo> listTopMRUProfiles(int limit) {
|
|
+ try {
|
|
+ this.stateLock.lock();
|
|
+ return this.profilesByUUID.values().stream().sorted(Comparator.comparing(GameProfileCache.GameProfileInfo::getLastAccess).reversed()).limit(limit).toList();
|
|
+ } finally {
|
|
+ this.stateLock.unlock();
|
|
+ }
|
|
}
|
|
+ // Paper end - Fix GameProfileCache concurrency
|
|
|
|
private static JsonElement writeGameProfile(GameProfileCache.GameProfileInfo entry, DateFormat dateFormat) {
|
|
JsonObject jsonobject = new JsonObject();
|