mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +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.Properties;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
@ -40,6 +43,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
|
||||
private ConnectionPool connectionPool;
|
||||
|
||||
private ReentrantLock massUpdateLock = new ReentrantLock();
|
||||
|
||||
protected SQLDatabaseManager() {
|
||||
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() {
|
||||
massUpdateLock.lock();
|
||||
mcMMO.p.getLogger().info("Purging powerless users...");
|
||||
|
||||
Connection connection = null;
|
||||
@ -113,12 +119,14 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
massUpdateLock.unlock();
|
||||
}
|
||||
|
||||
mcMMO.p.getLogger().info("Purged " + purged + " users from the database.");
|
||||
}
|
||||
|
||||
public void purgeOldUsers() {
|
||||
massUpdateLock.lock();
|
||||
mcMMO.p.getLogger().info("Purging old users...");
|
||||
|
||||
Connection connection = null;
|
||||
@ -156,6 +164,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
massUpdateLock.unlock();
|
||||
}
|
||||
|
||||
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) {
|
||||
List<String> names = new ArrayList<String>();
|
||||
ResultSet resultSet = null;
|
||||
|
||||
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 {
|
||||
connection = connectionPool.getConnection();
|
||||
statement = connection.createStatement();
|
||||
resultSet = statement.executeQuery("SELECT `user` FROM `" + tablePrefix + "users` WHERE `uuid` IS NULL");
|
||||
|
||||
while (resultSet.next()) {
|
||||
names.add(resultSet.getString("user"));
|
||||
}
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
} catch (SQLException ex) {
|
||||
printErrors(ex);
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
if (resultSet != null) {
|
||||
try {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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