mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 23:26:45 +01:00
Prevent user purges and UUID updates from conflicting in mass database operations.
This commit is contained in:
parent
432ff95a98
commit
f4c53aaf8a
@ -13,6 +13,9 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.config.Config;
|
import com.gmail.nossr50.config.Config;
|
||||||
@ -40,6 +43,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
|
|
||||||
private ConnectionPool connectionPool;
|
private ConnectionPool connectionPool;
|
||||||
|
|
||||||
|
private ReentrantLock massUpdateLock = new ReentrantLock();
|
||||||
|
|
||||||
protected SQLDatabaseManager() {
|
protected SQLDatabaseManager() {
|
||||||
String connectionString = "jdbc:mysql://" + Config.getInstance().getMySQLServerName() + ":" + Config.getInstance().getMySQLServerPort() + "/" + Config.getInstance().getMySQLDatabaseName();
|
String connectionString = "jdbc:mysql://" + Config.getInstance().getMySQLServerName() + ":" + Config.getInstance().getMySQLServerPort() + "/" + Config.getInstance().getMySQLDatabaseName();
|
||||||
|
|
||||||
@ -76,6 +81,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void purgePowerlessUsers() {
|
public void purgePowerlessUsers() {
|
||||||
|
massUpdateLock.lock();
|
||||||
mcMMO.p.getLogger().info("Purging powerless users...");
|
mcMMO.p.getLogger().info("Purging powerless users...");
|
||||||
|
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
@ -113,12 +119,14 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
massUpdateLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
mcMMO.p.getLogger().info("Purged " + purged + " users from the database.");
|
mcMMO.p.getLogger().info("Purged " + purged + " users from the database.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void purgeOldUsers() {
|
public void purgeOldUsers() {
|
||||||
|
massUpdateLock.lock();
|
||||||
mcMMO.p.getLogger().info("Purging old users...");
|
mcMMO.p.getLogger().info("Purging old users...");
|
||||||
|
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
@ -156,6 +164,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
massUpdateLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
mcMMO.p.getLogger().info("Purged " + purged + " users from the database.");
|
mcMMO.p.getLogger().info("Purged " + purged + " users from the database.");
|
||||||
@ -1360,7 +1369,6 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkUpgradeAddUUIDs(final Statement statement) {
|
private void checkUpgradeAddUUIDs(final Statement statement) {
|
||||||
List<String> names = new ArrayList<String>();
|
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -1396,29 +1404,57 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new GetUUIDUpdatesRequired().runTaskAsynchronously(mcMMO.p);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class GetUUIDUpdatesRequired extends BukkitRunnable {
|
||||||
|
public void run() {
|
||||||
|
massUpdateLock.lock();
|
||||||
|
List<String> names = new ArrayList<String>();
|
||||||
|
Connection connection = null;
|
||||||
|
Statement statement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
|
try {
|
||||||
|
connection = connectionPool.getConnection();
|
||||||
|
statement = connection.createStatement();
|
||||||
resultSet = statement.executeQuery("SELECT `user` FROM `" + tablePrefix + "users` WHERE `uuid` IS NULL");
|
resultSet = statement.executeQuery("SELECT `user` FROM `" + tablePrefix + "users` WHERE `uuid` IS NULL");
|
||||||
|
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
names.add(resultSet.getString("user"));
|
names.add(resultSet.getString("user"));
|
||||||
}
|
}
|
||||||
}
|
} catch (SQLException ex) {
|
||||||
catch (SQLException ex) {
|
|
||||||
printErrors(ex);
|
printErrors(ex);
|
||||||
}
|
} finally {
|
||||||
finally {
|
|
||||||
if (resultSet != null) {
|
if (resultSet != null) {
|
||||||
try {
|
try {
|
||||||
resultSet.close();
|
resultSet.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
// Ignore
|
||||||
}
|
}
|
||||||
catch (SQLException e) {
|
}
|
||||||
|
if (statement != null) {
|
||||||
|
try {
|
||||||
|
statement.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (connection != null) {
|
||||||
|
try {
|
||||||
|
connection.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!names.isEmpty()) {
|
if (!names.isEmpty()) {
|
||||||
new UUIDUpdateAsyncTask(mcMMO.p, names).runTaskAsynchronously(mcMMO.p);
|
new UUIDUpdateAsyncTask(mcMMO.p, names).run();;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
massUpdateLock.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user