Fixed a memory leak in MySQL that would cause errors if users were

removed from the DB
This commit is contained in:
nossr50 2019-05-29 10:14:04 -07:00
parent 54eca5b8ba
commit 4795143fca
7 changed files with 43 additions and 5 deletions

View File

@ -1,3 +1,7 @@
Version 2.1.66
Fixed a bug that could happen if a player was removed from the DB when using MySQL/MariaDB when the user was offline
Fixed a minor memory leak for MySQL
Version 2.1.65 Version 2.1.65
Corrected a bug that would cause RetroMode to use Linear formula regardless of setting Corrected a bug that would cause RetroMode to use Linear formula regardless of setting

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.nossr50.mcMMO</groupId> <groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId> <artifactId>mcMMO</artifactId>
<version>2.1.65</version> <version>2.1.66-SNAPSHOT</version>
<name>mcMMO</name> <name>mcMMO</name>
<url>https://github.com/mcMMO-Dev/mcMMO</url> <url>https://github.com/mcMMO-Dev/mcMMO</url>
<scm> <scm>

View File

@ -5,6 +5,7 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor; import org.bukkit.command.TabExecutor;
@ -12,6 +13,7 @@ import org.bukkit.util.StringUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
public class McremoveCommand implements TabExecutor { public class McremoveCommand implements TabExecutor {
@Override @Override
@ -24,7 +26,13 @@ public class McremoveCommand implements TabExecutor {
return true; return true;
} }
if (mcMMO.getDatabaseManager().removeUser(playerName)) { UUID uuid = null;
if(Bukkit.getPlayer(playerName) != null) {
uuid = Bukkit.getPlayer(playerName).getUniqueId();
}
if (mcMMO.getDatabaseManager().removeUser(playerName, uuid)) {
sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", playerName)); sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", playerName));
} }
else { else {

View File

@ -30,9 +30,17 @@ public interface DatabaseManager {
* Remove a user from the database. * Remove a user from the database.
* *
* @param playerName The name of the user to remove * @param playerName The name of the user to remove
* @param uuid player UUID, can be null
* @return true if the user was successfully removed, false otherwise * @return true if the user was successfully removed, false otherwise
*/ */
public boolean removeUser(String playerName); public boolean removeUser(String playerName, UUID uuid);
/**
* Removes any cache used for faster lookups
* Currently only used for SQL
* @param uuid target UUID to cleanup
*/
public void cleanupUser(UUID uuid);
/** /**
* Save a user to the database. * Save a user to the database.

View File

@ -185,7 +185,8 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
mcMMO.p.getLogger().info("Purged " + removedPlayers + " users from the database."); mcMMO.p.getLogger().info("Purged " + removedPlayers + " users from the database.");
} }
public boolean removeUser(String playerName) { public boolean removeUser(String playerName, UUID uuid) {
//NOTE: UUID is unused for FlatFile for this interface implementation
boolean worked = false; boolean worked = false;
BufferedReader in = null; BufferedReader in = null;
@ -240,6 +241,11 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
return worked; return worked;
} }
@Override
public void cleanupUser(UUID uuid) {
//Not used in FlatFile
}
public boolean saveUser(PlayerProfile profile) { public boolean saveUser(PlayerProfile profile) {
String playerName = profile.getPlayerName(); String playerName = profile.getPlayerName();
UUID uuid = profile.getUniqueId(); UUID uuid = profile.getUniqueId();

View File

@ -15,6 +15,7 @@ import com.gmail.nossr50.runnables.database.UUIDUpdateAsyncTask;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import org.apache.tomcat.jdbc.pool.DataSource; import org.apache.tomcat.jdbc.pool.DataSource;
import org.apache.tomcat.jdbc.pool.PoolProperties; import org.apache.tomcat.jdbc.pool.PoolProperties;
import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import java.sql.*; import java.sql.*;
@ -172,7 +173,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
mcMMO.p.getLogger().info("Purged " + purged + " users from the database."); mcMMO.p.getLogger().info("Purged " + purged + " users from the database.");
} }
public boolean removeUser(String playerName) { public boolean removeUser(String playerName, UUID uuid) {
boolean success = false; boolean success = false;
Connection connection = null; Connection connection = null;
PreparedStatement statement = null; PreparedStatement statement = null;
@ -200,12 +201,20 @@ public final class SQLDatabaseManager implements DatabaseManager {
} }
if (success) { if (success) {
if(uuid != null)
cleanupUser(uuid);
Misc.profileCleanup(playerName); Misc.profileCleanup(playerName);
} }
return success; return success;
} }
public void cleanupUser(UUID uuid) {
if(cachedUserIDs.containsKey(uuid))
cachedUserIDs.remove(uuid);
}
public boolean saveUser(PlayerProfile profile) { public boolean saveUser(PlayerProfile profile) {
boolean success = true; boolean success = true;
PreparedStatement statement = null; PreparedStatement statement = null;

View File

@ -1008,5 +1008,8 @@ public class McMMOPlayer {
if (inParty()) { if (inParty()) {
party.removeOnlineMember(thisPlayer); party.removeOnlineMember(thisPlayer);
} }
//Remove user from cache
mcMMO.getDatabaseManager().cleanupUser(thisPlayer.getUniqueId());
} }
} }